1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2022, Intel Corporation. */
7 #include <linux/dpll.h>
9 #define ICE_CGU_STATE_ACQ_ERR_THRESHOLD 50
10 #define ICE_DPLL_PIN_IDX_INVALID 0xff
11 #define ICE_DPLL_RCLK_NUM_PER_PF 1
14 * enum ice_dpll_pin_type - enumerate ice pin types:
15 * @ICE_DPLL_PIN_INVALID: invalid pin type
16 * @ICE_DPLL_PIN_TYPE_INPUT: input pin
17 * @ICE_DPLL_PIN_TYPE_OUTPUT: output pin
18 * @ICE_DPLL_PIN_TYPE_RCLK_INPUT: recovery clock input pin
20 enum ice_dpll_pin_type {
22 ICE_DPLL_PIN_TYPE_INPUT,
23 ICE_DPLL_PIN_TYPE_OUTPUT,
24 ICE_DPLL_PIN_TYPE_RCLK_INPUT,
27 static const char * const pin_type_name[] = {
28 [ICE_DPLL_PIN_TYPE_INPUT] = "input",
29 [ICE_DPLL_PIN_TYPE_OUTPUT] = "output",
30 [ICE_DPLL_PIN_TYPE_RCLK_INPUT] = "rclk-input",
34 * ice_dpll_pin_freq_set - set pin's frequency
35 * @pf: private board structure
36 * @pin: pointer to a pin
37 * @pin_type: type of pin being configured
38 * @freq: frequency to be set
39 * @extack: error reporting
41 * Set requested frequency on a pin.
43 * Context: Called under pf->dplls.lock
46 * * negative - error on AQ or wrong pin type given
49 ice_dpll_pin_freq_set(struct ice_pf *pf, struct ice_dpll_pin *pin,
50 enum ice_dpll_pin_type pin_type, const u32 freq,
51 struct netlink_ext_ack *extack)
57 case ICE_DPLL_PIN_TYPE_INPUT:
58 flags = ICE_AQC_SET_CGU_IN_CFG_FLG1_UPDATE_FREQ;
59 ret = ice_aq_set_input_pin_cfg(&pf->hw, pin->idx, flags,
60 pin->flags[0], freq, 0);
62 case ICE_DPLL_PIN_TYPE_OUTPUT:
63 flags = ICE_AQC_SET_CGU_OUT_CFG_UPDATE_FREQ;
64 ret = ice_aq_set_output_pin_cfg(&pf->hw, pin->idx, flags,
71 NL_SET_ERR_MSG_FMT(extack,
72 "err:%d %s failed to set pin freq:%u on pin:%u\n",
74 ice_aq_str(pf->hw.adminq.sq_last_status),
84 * ice_dpll_frequency_set - wrapper for pin callback for set frequency
85 * @pin: pointer to a pin
86 * @pin_priv: private data pointer passed on pin registration
87 * @dpll: pointer to dpll
88 * @dpll_priv: private data pointer passed on dpll registration
89 * @frequency: frequency to be set
90 * @extack: error reporting
91 * @pin_type: type of pin being configured
93 * Wraps internal set frequency command on a pin.
95 * Context: Acquires pf->dplls.lock
98 * * negative - error pin not found or couldn't set in hw
101 ice_dpll_frequency_set(const struct dpll_pin *pin, void *pin_priv,
102 const struct dpll_device *dpll, void *dpll_priv,
104 struct netlink_ext_ack *extack,
105 enum ice_dpll_pin_type pin_type)
107 struct ice_dpll_pin *p = pin_priv;
108 struct ice_dpll *d = dpll_priv;
109 struct ice_pf *pf = d->pf;
112 mutex_lock(&pf->dplls.lock);
113 ret = ice_dpll_pin_freq_set(pf, p, pin_type, frequency, extack);
114 mutex_unlock(&pf->dplls.lock);
120 * ice_dpll_input_frequency_set - input pin callback for set frequency
121 * @pin: pointer to a pin
122 * @pin_priv: private data pointer passed on pin registration
123 * @dpll: pointer to dpll
124 * @dpll_priv: private data pointer passed on dpll registration
125 * @frequency: frequency to be set
126 * @extack: error reporting
128 * Wraps internal set frequency command on a pin.
130 * Context: Calls a function which acquires pf->dplls.lock
133 * * negative - error pin not found or couldn't set in hw
136 ice_dpll_input_frequency_set(const struct dpll_pin *pin, void *pin_priv,
137 const struct dpll_device *dpll, void *dpll_priv,
138 u64 frequency, struct netlink_ext_ack *extack)
140 return ice_dpll_frequency_set(pin, pin_priv, dpll, dpll_priv, frequency,
141 extack, ICE_DPLL_PIN_TYPE_INPUT);
145 * ice_dpll_output_frequency_set - output pin callback for set frequency
146 * @pin: pointer to a pin
147 * @pin_priv: private data pointer passed on pin registration
148 * @dpll: pointer to dpll
149 * @dpll_priv: private data pointer passed on dpll registration
150 * @frequency: frequency to be set
151 * @extack: error reporting
153 * Wraps internal set frequency command on a pin.
155 * Context: Calls a function which acquires pf->dplls.lock
158 * * negative - error pin not found or couldn't set in hw
161 ice_dpll_output_frequency_set(const struct dpll_pin *pin, void *pin_priv,
162 const struct dpll_device *dpll, void *dpll_priv,
163 u64 frequency, struct netlink_ext_ack *extack)
165 return ice_dpll_frequency_set(pin, pin_priv, dpll, dpll_priv, frequency,
166 extack, ICE_DPLL_PIN_TYPE_OUTPUT);
170 * ice_dpll_frequency_get - wrapper for pin callback for get frequency
171 * @pin: pointer to a pin
172 * @pin_priv: private data pointer passed on pin registration
173 * @dpll: pointer to dpll
174 * @dpll_priv: private data pointer passed on dpll registration
175 * @frequency: on success holds pin's frequency
176 * @extack: error reporting
177 * @pin_type: type of pin being configured
179 * Wraps internal get frequency command of a pin.
181 * Context: Acquires pf->dplls.lock
184 * * negative - error pin not found or couldn't get from hw
187 ice_dpll_frequency_get(const struct dpll_pin *pin, void *pin_priv,
188 const struct dpll_device *dpll, void *dpll_priv,
189 u64 *frequency, struct netlink_ext_ack *extack,
190 enum ice_dpll_pin_type pin_type)
192 struct ice_dpll_pin *p = pin_priv;
193 struct ice_dpll *d = dpll_priv;
194 struct ice_pf *pf = d->pf;
196 mutex_lock(&pf->dplls.lock);
197 *frequency = p->freq;
198 mutex_unlock(&pf->dplls.lock);
204 * ice_dpll_input_frequency_get - input pin callback for get frequency
205 * @pin: pointer to a pin
206 * @pin_priv: private data pointer passed on pin registration
207 * @dpll: pointer to dpll
208 * @dpll_priv: private data pointer passed on dpll registration
209 * @frequency: on success holds pin's frequency
210 * @extack: error reporting
212 * Wraps internal get frequency command of a input pin.
214 * Context: Calls a function which acquires pf->dplls.lock
217 * * negative - error pin not found or couldn't get from hw
220 ice_dpll_input_frequency_get(const struct dpll_pin *pin, void *pin_priv,
221 const struct dpll_device *dpll, void *dpll_priv,
222 u64 *frequency, struct netlink_ext_ack *extack)
224 return ice_dpll_frequency_get(pin, pin_priv, dpll, dpll_priv, frequency,
225 extack, ICE_DPLL_PIN_TYPE_INPUT);
229 * ice_dpll_output_frequency_get - output pin callback for get frequency
230 * @pin: pointer to a pin
231 * @pin_priv: private data pointer passed on pin registration
232 * @dpll: pointer to dpll
233 * @dpll_priv: private data pointer passed on dpll registration
234 * @frequency: on success holds pin's frequency
235 * @extack: error reporting
237 * Wraps internal get frequency command of a pin.
239 * Context: Calls a function which acquires pf->dplls.lock
242 * * negative - error pin not found or couldn't get from hw
245 ice_dpll_output_frequency_get(const struct dpll_pin *pin, void *pin_priv,
246 const struct dpll_device *dpll, void *dpll_priv,
247 u64 *frequency, struct netlink_ext_ack *extack)
249 return ice_dpll_frequency_get(pin, pin_priv, dpll, dpll_priv, frequency,
250 extack, ICE_DPLL_PIN_TYPE_OUTPUT);
254 * ice_dpll_pin_enable - enable a pin on dplls
255 * @hw: board private hw structure
256 * @pin: pointer to a pin
257 * @pin_type: type of pin being enabled
258 * @extack: error reporting
260 * Enable a pin on both dplls. Store current state in pin->flags.
262 * Context: Called under pf->dplls.lock
268 ice_dpll_pin_enable(struct ice_hw *hw, struct ice_dpll_pin *pin,
269 enum ice_dpll_pin_type pin_type,
270 struct netlink_ext_ack *extack)
276 case ICE_DPLL_PIN_TYPE_INPUT:
277 if (pin->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN)
278 flags |= ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
279 flags |= ICE_AQC_SET_CGU_IN_CFG_FLG2_INPUT_EN;
280 ret = ice_aq_set_input_pin_cfg(hw, pin->idx, 0, flags, 0, 0);
282 case ICE_DPLL_PIN_TYPE_OUTPUT:
283 if (pin->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN)
284 flags |= ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
285 flags |= ICE_AQC_SET_CGU_OUT_CFG_OUT_EN;
286 ret = ice_aq_set_output_pin_cfg(hw, pin->idx, flags, 0, 0, 0);
292 NL_SET_ERR_MSG_FMT(extack,
293 "err:%d %s failed to enable %s pin:%u\n",
294 ret, ice_aq_str(hw->adminq.sq_last_status),
295 pin_type_name[pin_type], pin->idx);
301 * ice_dpll_pin_disable - disable a pin on dplls
302 * @hw: board private hw structure
303 * @pin: pointer to a pin
304 * @pin_type: type of pin being disabled
305 * @extack: error reporting
307 * Disable a pin on both dplls. Store current state in pin->flags.
309 * Context: Called under pf->dplls.lock
315 ice_dpll_pin_disable(struct ice_hw *hw, struct ice_dpll_pin *pin,
316 enum ice_dpll_pin_type pin_type,
317 struct netlink_ext_ack *extack)
323 case ICE_DPLL_PIN_TYPE_INPUT:
324 if (pin->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN)
325 flags |= ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
326 ret = ice_aq_set_input_pin_cfg(hw, pin->idx, 0, flags, 0, 0);
328 case ICE_DPLL_PIN_TYPE_OUTPUT:
329 if (pin->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN)
330 flags |= ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
331 ret = ice_aq_set_output_pin_cfg(hw, pin->idx, flags, 0, 0, 0);
337 NL_SET_ERR_MSG_FMT(extack,
338 "err:%d %s failed to disable %s pin:%u\n",
339 ret, ice_aq_str(hw->adminq.sq_last_status),
340 pin_type_name[pin_type], pin->idx);
346 * ice_dpll_pin_state_update - update pin's state
347 * @pf: private board struct
348 * @pin: structure with pin attributes to be updated
349 * @pin_type: type of pin being updated
350 * @extack: error reporting
352 * Determine pin current state and frequency, then update struct
353 * holding the pin info. For input pin states are separated for each
354 * dpll, for rclk pins states are separated for each parent.
356 * Context: Called under pf->dplls.lock
362 ice_dpll_pin_state_update(struct ice_pf *pf, struct ice_dpll_pin *pin,
363 enum ice_dpll_pin_type pin_type,
364 struct netlink_ext_ack *extack)
366 u8 parent, port_num = ICE_AQC_SET_PHY_REC_CLK_OUT_CURR_PORT;
370 case ICE_DPLL_PIN_TYPE_INPUT:
371 ret = ice_aq_get_input_pin_cfg(&pf->hw, pin->idx, NULL, NULL,
372 NULL, &pin->flags[0],
376 if (ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN & pin->flags[0]) {
378 pin->state[pf->dplls.eec.dpll_idx] =
379 pin->pin == pf->dplls.eec.active_input ?
380 DPLL_PIN_STATE_CONNECTED :
381 DPLL_PIN_STATE_SELECTABLE;
382 pin->state[pf->dplls.pps.dpll_idx] =
383 pin->pin == pf->dplls.pps.active_input ?
384 DPLL_PIN_STATE_CONNECTED :
385 DPLL_PIN_STATE_SELECTABLE;
387 pin->state[pf->dplls.eec.dpll_idx] =
388 DPLL_PIN_STATE_SELECTABLE;
389 pin->state[pf->dplls.pps.dpll_idx] =
390 DPLL_PIN_STATE_SELECTABLE;
393 pin->state[pf->dplls.eec.dpll_idx] =
394 DPLL_PIN_STATE_DISCONNECTED;
395 pin->state[pf->dplls.pps.dpll_idx] =
396 DPLL_PIN_STATE_DISCONNECTED;
399 case ICE_DPLL_PIN_TYPE_OUTPUT:
400 ret = ice_aq_get_output_pin_cfg(&pf->hw, pin->idx,
401 &pin->flags[0], NULL,
405 if (ICE_AQC_SET_CGU_OUT_CFG_OUT_EN & pin->flags[0])
406 pin->state[0] = DPLL_PIN_STATE_CONNECTED;
408 pin->state[0] = DPLL_PIN_STATE_DISCONNECTED;
410 case ICE_DPLL_PIN_TYPE_RCLK_INPUT:
411 for (parent = 0; parent < pf->dplls.rclk.num_parents;
415 ret = ice_aq_get_phy_rec_clk_out(&pf->hw, &p,
421 if (ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN &
423 pin->state[parent] = DPLL_PIN_STATE_CONNECTED;
426 DPLL_PIN_STATE_DISCONNECTED;
436 NL_SET_ERR_MSG_FMT(extack,
437 "err:%d %s failed to update %s pin:%u\n",
439 ice_aq_str(pf->hw.adminq.sq_last_status),
440 pin_type_name[pin_type], pin->idx);
442 dev_err_ratelimited(ice_pf_to_dev(pf),
443 "err:%d %s failed to update %s pin:%u\n",
445 ice_aq_str(pf->hw.adminq.sq_last_status),
446 pin_type_name[pin_type], pin->idx);
451 * ice_dpll_hw_input_prio_set - set input priority value in hardware
452 * @pf: board private structure
453 * @dpll: ice dpll pointer
454 * @pin: ice pin pointer
455 * @prio: priority value being set on a dpll
456 * @extack: error reporting
458 * Internal wrapper for setting the priority in the hardware.
460 * Context: Called under pf->dplls.lock
463 * * negative - failure
466 ice_dpll_hw_input_prio_set(struct ice_pf *pf, struct ice_dpll *dpll,
467 struct ice_dpll_pin *pin, const u32 prio,
468 struct netlink_ext_ack *extack)
472 ret = ice_aq_set_cgu_ref_prio(&pf->hw, dpll->dpll_idx, pin->idx,
475 NL_SET_ERR_MSG_FMT(extack,
476 "err:%d %s failed to set pin prio:%u on pin:%u\n",
478 ice_aq_str(pf->hw.adminq.sq_last_status),
481 dpll->input_prio[pin->idx] = prio;
487 * ice_dpll_lock_status_get - get dpll lock status callback
488 * @dpll: registered dpll pointer
489 * @dpll_priv: private data pointer passed on dpll registration
490 * @status: on success holds dpll's lock status
491 * @extack: error reporting
493 * Dpll subsystem callback, provides dpll's lock status.
495 * Context: Acquires pf->dplls.lock
498 * * negative - failure
501 ice_dpll_lock_status_get(const struct dpll_device *dpll, void *dpll_priv,
502 enum dpll_lock_status *status,
503 struct netlink_ext_ack *extack)
505 struct ice_dpll *d = dpll_priv;
506 struct ice_pf *pf = d->pf;
508 mutex_lock(&pf->dplls.lock);
509 *status = d->dpll_state;
510 mutex_unlock(&pf->dplls.lock);
516 * ice_dpll_mode_supported - check if dpll's working mode is supported
517 * @dpll: registered dpll pointer
518 * @dpll_priv: private data pointer passed on dpll registration
519 * @mode: mode to be checked for support
520 * @extack: error reporting
522 * Dpll subsystem callback. Provides information if working mode is supported
526 * * true - mode is supported
527 * * false - mode is not supported
529 static bool ice_dpll_mode_supported(const struct dpll_device *dpll,
532 struct netlink_ext_ack *extack)
534 if (mode == DPLL_MODE_AUTOMATIC)
541 * ice_dpll_mode_get - get dpll's working mode
542 * @dpll: registered dpll pointer
543 * @dpll_priv: private data pointer passed on dpll registration
544 * @mode: on success holds current working mode of dpll
545 * @extack: error reporting
547 * Dpll subsystem callback. Provides working mode of dpll.
549 * Context: Acquires pf->dplls.lock
552 * * negative - failure
554 static int ice_dpll_mode_get(const struct dpll_device *dpll, void *dpll_priv,
555 enum dpll_mode *mode,
556 struct netlink_ext_ack *extack)
558 struct ice_dpll *d = dpll_priv;
559 struct ice_pf *pf = d->pf;
561 mutex_lock(&pf->dplls.lock);
563 mutex_unlock(&pf->dplls.lock);
569 * ice_dpll_pin_state_set - set pin's state on dpll
570 * @pin: pointer to a pin
571 * @pin_priv: private data pointer passed on pin registration
572 * @dpll: registered dpll pointer
573 * @dpll_priv: private data pointer passed on dpll registration
574 * @enable: if pin shalll be enabled
575 * @extack: error reporting
576 * @pin_type: type of a pin
578 * Set pin state on a pin.
580 * Context: Acquires pf->dplls.lock
582 * * 0 - OK or no change required
586 ice_dpll_pin_state_set(const struct dpll_pin *pin, void *pin_priv,
587 const struct dpll_device *dpll, void *dpll_priv,
588 bool enable, struct netlink_ext_ack *extack,
589 enum ice_dpll_pin_type pin_type)
591 struct ice_dpll_pin *p = pin_priv;
592 struct ice_dpll *d = dpll_priv;
593 struct ice_pf *pf = d->pf;
596 mutex_lock(&pf->dplls.lock);
598 ret = ice_dpll_pin_enable(&pf->hw, p, pin_type, extack);
600 ret = ice_dpll_pin_disable(&pf->hw, p, pin_type, extack);
602 ret = ice_dpll_pin_state_update(pf, p, pin_type, extack);
603 mutex_unlock(&pf->dplls.lock);
609 * ice_dpll_output_state_set - enable/disable output pin on dpll device
610 * @pin: pointer to a pin
611 * @pin_priv: private data pointer passed on pin registration
612 * @dpll: dpll being configured
613 * @dpll_priv: private data pointer passed on dpll registration
614 * @state: state of pin to be set
615 * @extack: error reporting
617 * Dpll subsystem callback. Set given state on output type pin.
619 * Context: Calls a function which acquires pf->dplls.lock
621 * * 0 - successfully enabled mode
622 * * negative - failed to enable mode
625 ice_dpll_output_state_set(const struct dpll_pin *pin, void *pin_priv,
626 const struct dpll_device *dpll, void *dpll_priv,
627 enum dpll_pin_state state,
628 struct netlink_ext_ack *extack)
630 bool enable = state == DPLL_PIN_STATE_CONNECTED;
632 return ice_dpll_pin_state_set(pin, pin_priv, dpll, dpll_priv, enable,
633 extack, ICE_DPLL_PIN_TYPE_OUTPUT);
637 * ice_dpll_input_state_set - enable/disable input pin on dpll levice
638 * @pin: pointer to a pin
639 * @pin_priv: private data pointer passed on pin registration
640 * @dpll: dpll being configured
641 * @dpll_priv: private data pointer passed on dpll registration
642 * @state: state of pin to be set
643 * @extack: error reporting
645 * Dpll subsystem callback. Enables given mode on input type pin.
647 * Context: Calls a function which acquires pf->dplls.lock
649 * * 0 - successfully enabled mode
650 * * negative - failed to enable mode
653 ice_dpll_input_state_set(const struct dpll_pin *pin, void *pin_priv,
654 const struct dpll_device *dpll, void *dpll_priv,
655 enum dpll_pin_state state,
656 struct netlink_ext_ack *extack)
658 bool enable = state == DPLL_PIN_STATE_SELECTABLE;
660 return ice_dpll_pin_state_set(pin, pin_priv, dpll, dpll_priv, enable,
661 extack, ICE_DPLL_PIN_TYPE_INPUT);
665 * ice_dpll_pin_state_get - set pin's state on dpll
666 * @pin: pointer to a pin
667 * @pin_priv: private data pointer passed on pin registration
668 * @dpll: registered dpll pointer
669 * @dpll_priv: private data pointer passed on dpll registration
670 * @state: on success holds state of the pin
671 * @extack: error reporting
672 * @pin_type: type of questioned pin
674 * Determine pin state set it on a pin.
676 * Context: Acquires pf->dplls.lock
679 * * negative - failed to get state
682 ice_dpll_pin_state_get(const struct dpll_pin *pin, void *pin_priv,
683 const struct dpll_device *dpll, void *dpll_priv,
684 enum dpll_pin_state *state,
685 struct netlink_ext_ack *extack,
686 enum ice_dpll_pin_type pin_type)
688 struct ice_dpll_pin *p = pin_priv;
689 struct ice_dpll *d = dpll_priv;
690 struct ice_pf *pf = d->pf;
693 mutex_lock(&pf->dplls.lock);
694 ret = ice_dpll_pin_state_update(pf, p, pin_type, extack);
697 if (pin_type == ICE_DPLL_PIN_TYPE_INPUT)
698 *state = p->state[d->dpll_idx];
699 else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT)
700 *state = p->state[0];
703 mutex_unlock(&pf->dplls.lock);
709 * ice_dpll_output_state_get - get output pin state on dpll device
710 * @pin: pointer to a pin
711 * @pin_priv: private data pointer passed on pin registration
712 * @dpll: registered dpll pointer
713 * @dpll_priv: private data pointer passed on dpll registration
714 * @state: on success holds state of the pin
715 * @extack: error reporting
717 * Dpll subsystem callback. Check state of a pin.
719 * Context: Calls a function which acquires pf->dplls.lock
722 * * negative - failed to get state
725 ice_dpll_output_state_get(const struct dpll_pin *pin, void *pin_priv,
726 const struct dpll_device *dpll, void *dpll_priv,
727 enum dpll_pin_state *state,
728 struct netlink_ext_ack *extack)
730 return ice_dpll_pin_state_get(pin, pin_priv, dpll, dpll_priv, state,
731 extack, ICE_DPLL_PIN_TYPE_OUTPUT);
735 * ice_dpll_input_state_get - get input pin state on dpll device
736 * @pin: pointer to a pin
737 * @pin_priv: private data pointer passed on pin registration
738 * @dpll: registered dpll pointer
739 * @dpll_priv: private data pointer passed on dpll registration
740 * @state: on success holds state of the pin
741 * @extack: error reporting
743 * Dpll subsystem callback. Check state of a input pin.
745 * Context: Calls a function which acquires pf->dplls.lock
748 * * negative - failed to get state
751 ice_dpll_input_state_get(const struct dpll_pin *pin, void *pin_priv,
752 const struct dpll_device *dpll, void *dpll_priv,
753 enum dpll_pin_state *state,
754 struct netlink_ext_ack *extack)
756 return ice_dpll_pin_state_get(pin, pin_priv, dpll, dpll_priv, state,
757 extack, ICE_DPLL_PIN_TYPE_INPUT);
761 * ice_dpll_input_prio_get - get dpll's input prio
762 * @pin: pointer to a pin
763 * @pin_priv: private data pointer passed on pin registration
764 * @dpll: registered dpll pointer
765 * @dpll_priv: private data pointer passed on dpll registration
766 * @prio: on success - returns input priority on dpll
767 * @extack: error reporting
769 * Dpll subsystem callback. Handler for getting priority of a input pin.
771 * Context: Acquires pf->dplls.lock
774 * * negative - failure
777 ice_dpll_input_prio_get(const struct dpll_pin *pin, void *pin_priv,
778 const struct dpll_device *dpll, void *dpll_priv,
779 u32 *prio, struct netlink_ext_ack *extack)
781 struct ice_dpll_pin *p = pin_priv;
782 struct ice_dpll *d = dpll_priv;
783 struct ice_pf *pf = d->pf;
785 mutex_lock(&pf->dplls.lock);
786 *prio = d->input_prio[p->idx];
787 mutex_unlock(&pf->dplls.lock);
793 * ice_dpll_input_prio_set - set dpll input prio
794 * @pin: pointer to a pin
795 * @pin_priv: private data pointer passed on pin registration
796 * @dpll: registered dpll pointer
797 * @dpll_priv: private data pointer passed on dpll registration
798 * @prio: input priority to be set on dpll
799 * @extack: error reporting
801 * Dpll subsystem callback. Handler for setting priority of a input pin.
803 * Context: Acquires pf->dplls.lock
806 * * negative - failure
809 ice_dpll_input_prio_set(const struct dpll_pin *pin, void *pin_priv,
810 const struct dpll_device *dpll, void *dpll_priv,
811 u32 prio, struct netlink_ext_ack *extack)
813 struct ice_dpll_pin *p = pin_priv;
814 struct ice_dpll *d = dpll_priv;
815 struct ice_pf *pf = d->pf;
818 if (prio > ICE_DPLL_PRIO_MAX) {
819 NL_SET_ERR_MSG_FMT(extack, "prio out of supported range 0-%d",
824 mutex_lock(&pf->dplls.lock);
825 ret = ice_dpll_hw_input_prio_set(pf, d, p, prio, extack);
826 mutex_unlock(&pf->dplls.lock);
832 * ice_dpll_input_direction - callback for get input pin direction
833 * @pin: pointer to a pin
834 * @pin_priv: private data pointer passed on pin registration
835 * @dpll: registered dpll pointer
836 * @dpll_priv: private data pointer passed on dpll registration
837 * @direction: holds input pin direction
838 * @extack: error reporting
840 * Dpll subsystem callback. Handler for getting direction of a input pin.
846 ice_dpll_input_direction(const struct dpll_pin *pin, void *pin_priv,
847 const struct dpll_device *dpll, void *dpll_priv,
848 enum dpll_pin_direction *direction,
849 struct netlink_ext_ack *extack)
851 *direction = DPLL_PIN_DIRECTION_INPUT;
857 * ice_dpll_output_direction - callback for get output pin direction
858 * @pin: pointer to a pin
859 * @pin_priv: private data pointer passed on pin registration
860 * @dpll: registered dpll pointer
861 * @dpll_priv: private data pointer passed on dpll registration
862 * @direction: holds output pin direction
863 * @extack: error reporting
865 * Dpll subsystem callback. Handler for getting direction of an output pin.
871 ice_dpll_output_direction(const struct dpll_pin *pin, void *pin_priv,
872 const struct dpll_device *dpll, void *dpll_priv,
873 enum dpll_pin_direction *direction,
874 struct netlink_ext_ack *extack)
876 *direction = DPLL_PIN_DIRECTION_OUTPUT;
882 * ice_dpll_pin_phase_adjust_get - callback for get pin phase adjust value
883 * @pin: pointer to a pin
884 * @pin_priv: private data pointer passed on pin registration
885 * @dpll: registered dpll pointer
886 * @dpll_priv: private data pointer passed on dpll registration
887 * @phase_adjust: on success holds pin phase_adjust value
888 * @extack: error reporting
890 * Dpll subsystem callback. Handler for getting phase adjust value of a pin.
892 * Context: Acquires pf->dplls.lock
898 ice_dpll_pin_phase_adjust_get(const struct dpll_pin *pin, void *pin_priv,
899 const struct dpll_device *dpll, void *dpll_priv,
901 struct netlink_ext_ack *extack)
903 struct ice_dpll_pin *p = pin_priv;
904 struct ice_pf *pf = p->pf;
906 mutex_lock(&pf->dplls.lock);
907 *phase_adjust = p->phase_adjust;
908 mutex_unlock(&pf->dplls.lock);
914 * ice_dpll_pin_phase_adjust_set - helper for setting a pin phase adjust value
915 * @pin: pointer to a pin
916 * @pin_priv: private data pointer passed on pin registration
917 * @dpll: registered dpll pointer
918 * @dpll_priv: private data pointer passed on dpll registration
919 * @phase_adjust: phase_adjust to be set
920 * @extack: error reporting
921 * @type: type of a pin
923 * Helper for dpll subsystem callback. Handler for setting phase adjust value
926 * Context: Acquires pf->dplls.lock
932 ice_dpll_pin_phase_adjust_set(const struct dpll_pin *pin, void *pin_priv,
933 const struct dpll_device *dpll, void *dpll_priv,
935 struct netlink_ext_ack *extack,
936 enum ice_dpll_pin_type type)
938 struct ice_dpll_pin *p = pin_priv;
939 struct ice_dpll *d = dpll_priv;
940 struct ice_pf *pf = d->pf;
941 u8 flag, flags_en = 0;
944 mutex_lock(&pf->dplls.lock);
946 case ICE_DPLL_PIN_TYPE_INPUT:
947 flag = ICE_AQC_SET_CGU_IN_CFG_FLG1_UPDATE_DELAY;
948 if (p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN)
949 flags_en |= ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
950 if (p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN)
951 flags_en |= ICE_AQC_SET_CGU_IN_CFG_FLG2_INPUT_EN;
952 ret = ice_aq_set_input_pin_cfg(&pf->hw, p->idx, flag, flags_en,
955 case ICE_DPLL_PIN_TYPE_OUTPUT:
956 flag = ICE_AQC_SET_CGU_OUT_CFG_UPDATE_PHASE;
957 if (p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_OUT_EN)
958 flag |= ICE_AQC_SET_CGU_OUT_CFG_OUT_EN;
959 if (p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN)
960 flag |= ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
961 ret = ice_aq_set_output_pin_cfg(&pf->hw, p->idx, flag, 0, 0,
968 p->phase_adjust = phase_adjust;
969 mutex_unlock(&pf->dplls.lock);
971 NL_SET_ERR_MSG_FMT(extack,
972 "err:%d %s failed to set pin phase_adjust:%d for pin:%u on dpll:%u\n",
974 ice_aq_str(pf->hw.adminq.sq_last_status),
975 phase_adjust, p->idx, d->dpll_idx);
981 * ice_dpll_input_phase_adjust_set - callback for set input pin phase adjust
982 * @pin: pointer to a pin
983 * @pin_priv: private data pointer passed on pin registration
984 * @dpll: registered dpll pointer
985 * @dpll_priv: private data pointer passed on dpll registration
986 * @phase_adjust: phase_adjust to be set
987 * @extack: error reporting
989 * Dpll subsystem callback. Wraps a handler for setting phase adjust on input
992 * Context: Calls a function which acquires pf->dplls.lock
998 ice_dpll_input_phase_adjust_set(const struct dpll_pin *pin, void *pin_priv,
999 const struct dpll_device *dpll, void *dpll_priv,
1001 struct netlink_ext_ack *extack)
1003 return ice_dpll_pin_phase_adjust_set(pin, pin_priv, dpll, dpll_priv,
1004 phase_adjust, extack,
1005 ICE_DPLL_PIN_TYPE_INPUT);
1009 * ice_dpll_output_phase_adjust_set - callback for set output pin phase adjust
1010 * @pin: pointer to a pin
1011 * @pin_priv: private data pointer passed on pin registration
1012 * @dpll: registered dpll pointer
1013 * @dpll_priv: private data pointer passed on dpll registration
1014 * @phase_adjust: phase_adjust to be set
1015 * @extack: error reporting
1017 * Dpll subsystem callback. Wraps a handler for setting phase adjust on output
1020 * Context: Calls a function which acquires pf->dplls.lock
1023 * * negative - error
1026 ice_dpll_output_phase_adjust_set(const struct dpll_pin *pin, void *pin_priv,
1027 const struct dpll_device *dpll, void *dpll_priv,
1029 struct netlink_ext_ack *extack)
1031 return ice_dpll_pin_phase_adjust_set(pin, pin_priv, dpll, dpll_priv,
1032 phase_adjust, extack,
1033 ICE_DPLL_PIN_TYPE_OUTPUT);
1036 #define ICE_DPLL_PHASE_OFFSET_DIVIDER 100
1037 #define ICE_DPLL_PHASE_OFFSET_FACTOR \
1038 (DPLL_PHASE_OFFSET_DIVIDER / ICE_DPLL_PHASE_OFFSET_DIVIDER)
1040 * ice_dpll_phase_offset_get - callback for get dpll phase shift value
1041 * @pin: pointer to a pin
1042 * @pin_priv: private data pointer passed on pin registration
1043 * @dpll: registered dpll pointer
1044 * @dpll_priv: private data pointer passed on dpll registration
1045 * @phase_offset: on success holds pin phase_offset value
1046 * @extack: error reporting
1048 * Dpll subsystem callback. Handler for getting phase shift value between
1049 * dpll's input and output.
1051 * Context: Acquires pf->dplls.lock
1054 * * negative - error
1057 ice_dpll_phase_offset_get(const struct dpll_pin *pin, void *pin_priv,
1058 const struct dpll_device *dpll, void *dpll_priv,
1059 s64 *phase_offset, struct netlink_ext_ack *extack)
1061 struct ice_dpll *d = dpll_priv;
1062 struct ice_pf *pf = d->pf;
1064 mutex_lock(&pf->dplls.lock);
1065 if (d->active_input == pin)
1066 *phase_offset = d->phase_offset * ICE_DPLL_PHASE_OFFSET_FACTOR;
1069 mutex_unlock(&pf->dplls.lock);
1075 * ice_dpll_rclk_state_on_pin_set - set a state on rclk pin
1076 * @pin: pointer to a pin
1077 * @pin_priv: private data pointer passed on pin registration
1078 * @parent_pin: pin parent pointer
1079 * @parent_pin_priv: parent private data pointer passed on pin registration
1080 * @state: state to be set on pin
1081 * @extack: error reporting
1083 * Dpll subsystem callback, set a state of a rclk pin on a parent pin
1085 * Context: Acquires pf->dplls.lock
1088 * * negative - failure
1091 ice_dpll_rclk_state_on_pin_set(const struct dpll_pin *pin, void *pin_priv,
1092 const struct dpll_pin *parent_pin,
1093 void *parent_pin_priv,
1094 enum dpll_pin_state state,
1095 struct netlink_ext_ack *extack)
1097 struct ice_dpll_pin *p = pin_priv, *parent = parent_pin_priv;
1098 bool enable = state == DPLL_PIN_STATE_CONNECTED;
1099 struct ice_pf *pf = p->pf;
1103 mutex_lock(&pf->dplls.lock);
1104 hw_idx = parent->idx - pf->dplls.base_rclk_idx;
1105 if (hw_idx >= pf->dplls.num_inputs)
1108 if ((enable && p->state[hw_idx] == DPLL_PIN_STATE_CONNECTED) ||
1109 (!enable && p->state[hw_idx] == DPLL_PIN_STATE_DISCONNECTED)) {
1110 NL_SET_ERR_MSG_FMT(extack,
1111 "pin:%u state:%u on parent:%u already set",
1112 p->idx, state, parent->idx);
1115 ret = ice_aq_set_phy_rec_clk_out(&pf->hw, hw_idx, enable,
1118 NL_SET_ERR_MSG_FMT(extack,
1119 "err:%d %s failed to set pin state:%u for pin:%u on parent:%u\n",
1121 ice_aq_str(pf->hw.adminq.sq_last_status),
1122 state, p->idx, parent->idx);
1124 mutex_unlock(&pf->dplls.lock);
1130 * ice_dpll_rclk_state_on_pin_get - get a state of rclk pin
1131 * @pin: pointer to a pin
1132 * @pin_priv: private data pointer passed on pin registration
1133 * @parent_pin: pin parent pointer
1134 * @parent_pin_priv: pin parent priv data pointer passed on pin registration
1135 * @state: on success holds pin state on parent pin
1136 * @extack: error reporting
1138 * dpll subsystem callback, get a state of a recovered clock pin.
1140 * Context: Acquires pf->dplls.lock
1143 * * negative - failure
1146 ice_dpll_rclk_state_on_pin_get(const struct dpll_pin *pin, void *pin_priv,
1147 const struct dpll_pin *parent_pin,
1148 void *parent_pin_priv,
1149 enum dpll_pin_state *state,
1150 struct netlink_ext_ack *extack)
1152 struct ice_dpll_pin *p = pin_priv, *parent = parent_pin_priv;
1153 struct ice_pf *pf = p->pf;
1157 mutex_lock(&pf->dplls.lock);
1158 hw_idx = parent->idx - pf->dplls.base_rclk_idx;
1159 if (hw_idx >= pf->dplls.num_inputs)
1162 ret = ice_dpll_pin_state_update(pf, p, ICE_DPLL_PIN_TYPE_RCLK_INPUT,
1167 *state = p->state[hw_idx];
1170 mutex_unlock(&pf->dplls.lock);
1175 static const struct dpll_pin_ops ice_dpll_rclk_ops = {
1176 .state_on_pin_set = ice_dpll_rclk_state_on_pin_set,
1177 .state_on_pin_get = ice_dpll_rclk_state_on_pin_get,
1178 .direction_get = ice_dpll_input_direction,
1181 static const struct dpll_pin_ops ice_dpll_input_ops = {
1182 .frequency_get = ice_dpll_input_frequency_get,
1183 .frequency_set = ice_dpll_input_frequency_set,
1184 .state_on_dpll_get = ice_dpll_input_state_get,
1185 .state_on_dpll_set = ice_dpll_input_state_set,
1186 .prio_get = ice_dpll_input_prio_get,
1187 .prio_set = ice_dpll_input_prio_set,
1188 .direction_get = ice_dpll_input_direction,
1189 .phase_adjust_get = ice_dpll_pin_phase_adjust_get,
1190 .phase_adjust_set = ice_dpll_input_phase_adjust_set,
1191 .phase_offset_get = ice_dpll_phase_offset_get,
1194 static const struct dpll_pin_ops ice_dpll_output_ops = {
1195 .frequency_get = ice_dpll_output_frequency_get,
1196 .frequency_set = ice_dpll_output_frequency_set,
1197 .state_on_dpll_get = ice_dpll_output_state_get,
1198 .state_on_dpll_set = ice_dpll_output_state_set,
1199 .direction_get = ice_dpll_output_direction,
1200 .phase_adjust_get = ice_dpll_pin_phase_adjust_get,
1201 .phase_adjust_set = ice_dpll_output_phase_adjust_set,
1204 static const struct dpll_device_ops ice_dpll_ops = {
1205 .lock_status_get = ice_dpll_lock_status_get,
1206 .mode_supported = ice_dpll_mode_supported,
1207 .mode_get = ice_dpll_mode_get,
1211 * ice_generate_clock_id - generates unique clock_id for registering dpll.
1212 * @pf: board private structure
1214 * Generates unique (per board) clock_id for allocation and search of dpll
1215 * devices in Linux dpll subsystem.
1217 * Return: generated clock id for the board
1219 static u64 ice_generate_clock_id(struct ice_pf *pf)
1221 return pci_get_dsn(pf->pdev);
1225 * ice_dpll_notify_changes - notify dpll subsystem about changes
1226 * @d: pointer do dpll
1228 * Once change detected appropriate event is submitted to the dpll subsystem.
1230 static void ice_dpll_notify_changes(struct ice_dpll *d)
1232 bool pin_notified = false;
1234 if (d->prev_dpll_state != d->dpll_state) {
1235 d->prev_dpll_state = d->dpll_state;
1236 dpll_device_change_ntf(d->dpll);
1238 if (d->prev_input != d->active_input) {
1240 dpll_pin_change_ntf(d->prev_input);
1241 d->prev_input = d->active_input;
1242 if (d->active_input) {
1243 dpll_pin_change_ntf(d->active_input);
1244 pin_notified = true;
1247 if (d->prev_phase_offset != d->phase_offset) {
1248 d->prev_phase_offset = d->phase_offset;
1249 if (!pin_notified && d->active_input)
1250 dpll_pin_change_ntf(d->active_input);
1255 * ice_dpll_update_state - update dpll state
1256 * @pf: pf private structure
1257 * @d: pointer to queried dpll device
1258 * @init: if function called on initialization of ice dpll
1260 * Poll current state of dpll from hw and update ice_dpll struct.
1262 * Context: Called by kworker under pf->dplls.lock
1265 * * negative - AQ failure
1268 ice_dpll_update_state(struct ice_pf *pf, struct ice_dpll *d, bool init)
1270 struct ice_dpll_pin *p = NULL;
1273 ret = ice_get_cgu_state(&pf->hw, d->dpll_idx, d->prev_dpll_state,
1274 &d->input_idx, &d->ref_state, &d->eec_mode,
1275 &d->phase_offset, &d->dpll_state);
1277 dev_dbg(ice_pf_to_dev(pf),
1278 "update dpll=%d, prev_src_idx:%u, src_idx:%u, state:%d, prev:%d mode:%d\n",
1279 d->dpll_idx, d->prev_input_idx, d->input_idx,
1280 d->dpll_state, d->prev_dpll_state, d->mode);
1282 dev_err(ice_pf_to_dev(pf),
1283 "update dpll=%d state failed, ret=%d %s\n",
1285 ice_aq_str(pf->hw.adminq.sq_last_status));
1289 if (d->dpll_state == DPLL_LOCK_STATUS_LOCKED ||
1290 d->dpll_state == DPLL_LOCK_STATUS_LOCKED_HO_ACQ)
1291 d->active_input = pf->dplls.inputs[d->input_idx].pin;
1292 p = &pf->dplls.inputs[d->input_idx];
1293 return ice_dpll_pin_state_update(pf, p,
1294 ICE_DPLL_PIN_TYPE_INPUT, NULL);
1296 if (d->dpll_state == DPLL_LOCK_STATUS_HOLDOVER ||
1297 d->dpll_state == DPLL_LOCK_STATUS_UNLOCKED) {
1298 d->active_input = NULL;
1299 if (d->input_idx != ICE_DPLL_PIN_IDX_INVALID)
1300 p = &pf->dplls.inputs[d->input_idx];
1301 d->prev_input_idx = ICE_DPLL_PIN_IDX_INVALID;
1302 d->input_idx = ICE_DPLL_PIN_IDX_INVALID;
1305 ret = ice_dpll_pin_state_update(pf, p,
1306 ICE_DPLL_PIN_TYPE_INPUT, NULL);
1307 } else if (d->input_idx != d->prev_input_idx) {
1308 if (d->prev_input_idx != ICE_DPLL_PIN_IDX_INVALID) {
1309 p = &pf->dplls.inputs[d->prev_input_idx];
1310 ice_dpll_pin_state_update(pf, p,
1311 ICE_DPLL_PIN_TYPE_INPUT,
1314 if (d->input_idx != ICE_DPLL_PIN_IDX_INVALID) {
1315 p = &pf->dplls.inputs[d->input_idx];
1316 d->active_input = p->pin;
1317 ice_dpll_pin_state_update(pf, p,
1318 ICE_DPLL_PIN_TYPE_INPUT,
1321 d->prev_input_idx = d->input_idx;
1328 * ice_dpll_periodic_work - DPLLs periodic worker
1329 * @work: pointer to kthread_work structure
1331 * DPLLs periodic worker is responsible for polling state of dpll.
1332 * Context: Holds pf->dplls.lock
1334 static void ice_dpll_periodic_work(struct kthread_work *work)
1336 struct ice_dplls *d = container_of(work, struct ice_dplls, work.work);
1337 struct ice_pf *pf = container_of(d, struct ice_pf, dplls);
1338 struct ice_dpll *de = &pf->dplls.eec;
1339 struct ice_dpll *dp = &pf->dplls.pps;
1342 mutex_lock(&pf->dplls.lock);
1343 ret = ice_dpll_update_state(pf, de, false);
1345 ret = ice_dpll_update_state(pf, dp, false);
1347 d->cgu_state_acq_err_num++;
1348 /* stop rescheduling this worker */
1349 if (d->cgu_state_acq_err_num >
1350 ICE_CGU_STATE_ACQ_ERR_THRESHOLD) {
1351 dev_err(ice_pf_to_dev(pf),
1352 "EEC/PPS DPLLs periodic work disabled\n");
1353 mutex_unlock(&pf->dplls.lock);
1357 mutex_unlock(&pf->dplls.lock);
1358 ice_dpll_notify_changes(de);
1359 ice_dpll_notify_changes(dp);
1361 /* Run twice a second or reschedule if update failed */
1362 kthread_queue_delayed_work(d->kworker, &d->work,
1363 ret ? msecs_to_jiffies(10) :
1364 msecs_to_jiffies(500));
1368 * ice_dpll_release_pins - release pins resources from dpll subsystem
1369 * @pins: pointer to pins array
1370 * @count: number of pins
1372 * Release resources of given pins array in the dpll subsystem.
1374 static void ice_dpll_release_pins(struct ice_dpll_pin *pins, int count)
1378 for (i = 0; i < count; i++)
1379 dpll_pin_put(pins[i].pin);
1383 * ice_dpll_get_pins - get pins from dpll subsystem
1384 * @pf: board private structure
1385 * @pins: pointer to pins array
1386 * @start_idx: get starts from this pin idx value
1387 * @count: number of pins
1388 * @clock_id: clock_id of dpll device
1390 * Get pins - allocate - in dpll subsystem, store them in pin field of given
1395 * * negative - allocation failure reason
1398 ice_dpll_get_pins(struct ice_pf *pf, struct ice_dpll_pin *pins,
1399 int start_idx, int count, u64 clock_id)
1403 for (i = 0; i < count; i++) {
1404 pins[i].pin = dpll_pin_get(clock_id, i + start_idx, THIS_MODULE,
1406 if (IS_ERR(pins[i].pin)) {
1407 ret = PTR_ERR(pins[i].pin);
1416 dpll_pin_put(pins[i].pin);
1421 * ice_dpll_unregister_pins - unregister pins from a dpll
1422 * @dpll: dpll device pointer
1423 * @pins: pointer to pins array
1424 * @ops: callback ops registered with the pins
1425 * @count: number of pins
1427 * Unregister pins of a given array of pins from given dpll device registered in
1431 ice_dpll_unregister_pins(struct dpll_device *dpll, struct ice_dpll_pin *pins,
1432 const struct dpll_pin_ops *ops, int count)
1436 for (i = 0; i < count; i++)
1437 dpll_pin_unregister(dpll, pins[i].pin, ops, &pins[i]);
1441 * ice_dpll_register_pins - register pins with a dpll
1442 * @dpll: dpll pointer to register pins with
1443 * @pins: pointer to pins array
1444 * @ops: callback ops registered with the pins
1445 * @count: number of pins
1447 * Register pins of a given array with given dpll in dpll subsystem.
1451 * * negative - registration failure reason
1454 ice_dpll_register_pins(struct dpll_device *dpll, struct ice_dpll_pin *pins,
1455 const struct dpll_pin_ops *ops, int count)
1459 for (i = 0; i < count; i++) {
1460 ret = dpll_pin_register(dpll, pins[i].pin, ops, &pins[i]);
1462 goto unregister_pins;
1469 dpll_pin_unregister(dpll, pins[i].pin, ops, &pins[i]);
1474 * ice_dpll_deinit_direct_pins - deinitialize direct pins
1475 * @cgu: if cgu is present and controlled by this NIC
1476 * @pins: pointer to pins array
1477 * @count: number of pins
1478 * @ops: callback ops registered with the pins
1479 * @first: dpll device pointer
1480 * @second: dpll device pointer
1482 * If cgu is owned unregister pins from given dplls.
1483 * Release pins resources to the dpll subsystem.
1486 ice_dpll_deinit_direct_pins(bool cgu, struct ice_dpll_pin *pins, int count,
1487 const struct dpll_pin_ops *ops,
1488 struct dpll_device *first,
1489 struct dpll_device *second)
1492 ice_dpll_unregister_pins(first, pins, ops, count);
1493 ice_dpll_unregister_pins(second, pins, ops, count);
1495 ice_dpll_release_pins(pins, count);
1499 * ice_dpll_init_direct_pins - initialize direct pins
1500 * @pf: board private structure
1501 * @cgu: if cgu is present and controlled by this NIC
1502 * @pins: pointer to pins array
1503 * @start_idx: on which index shall allocation start in dpll subsystem
1504 * @count: number of pins
1505 * @ops: callback ops registered with the pins
1506 * @first: dpll device pointer
1507 * @second: dpll device pointer
1509 * Allocate directly connected pins of a given array in dpll subsystem.
1510 * If cgu is owned register allocated pins with given dplls.
1514 * * negative - registration failure reason
1517 ice_dpll_init_direct_pins(struct ice_pf *pf, bool cgu,
1518 struct ice_dpll_pin *pins, int start_idx, int count,
1519 const struct dpll_pin_ops *ops,
1520 struct dpll_device *first, struct dpll_device *second)
1524 ret = ice_dpll_get_pins(pf, pins, start_idx, count, pf->dplls.clock_id);
1528 ret = ice_dpll_register_pins(first, pins, ops, count);
1531 ret = ice_dpll_register_pins(second, pins, ops, count);
1533 goto unregister_first;
1539 ice_dpll_unregister_pins(first, pins, ops, count);
1541 ice_dpll_release_pins(pins, count);
1546 * ice_dpll_deinit_rclk_pin - release rclk pin resources
1547 * @pf: board private structure
1549 * Deregister rclk pin from parent pins and release resources in dpll subsystem.
1551 static void ice_dpll_deinit_rclk_pin(struct ice_pf *pf)
1553 struct ice_dpll_pin *rclk = &pf->dplls.rclk;
1554 struct ice_vsi *vsi = ice_get_main_vsi(pf);
1555 struct dpll_pin *parent;
1558 for (i = 0; i < rclk->num_parents; i++) {
1559 parent = pf->dplls.inputs[rclk->parent_idx[i]].pin;
1562 dpll_pin_on_pin_unregister(parent, rclk->pin,
1563 &ice_dpll_rclk_ops, rclk);
1565 if (WARN_ON_ONCE(!vsi || !vsi->netdev))
1567 netdev_dpll_pin_clear(vsi->netdev);
1568 dpll_pin_put(rclk->pin);
1572 * ice_dpll_init_rclk_pins - initialize recovered clock pin
1573 * @pf: board private structure
1574 * @pin: pin to register
1575 * @start_idx: on which index shall allocation start in dpll subsystem
1576 * @ops: callback ops registered with the pins
1578 * Allocate resource for recovered clock pin in dpll subsystem. Register the
1579 * pin with the parents it has in the info. Register pin with the pf's main vsi
1584 * * negative - registration failure reason
1587 ice_dpll_init_rclk_pins(struct ice_pf *pf, struct ice_dpll_pin *pin,
1588 int start_idx, const struct dpll_pin_ops *ops)
1590 struct ice_vsi *vsi = ice_get_main_vsi(pf);
1591 struct dpll_pin *parent;
1594 ret = ice_dpll_get_pins(pf, pin, start_idx, ICE_DPLL_RCLK_NUM_PER_PF,
1595 pf->dplls.clock_id);
1598 for (i = 0; i < pf->dplls.rclk.num_parents; i++) {
1599 parent = pf->dplls.inputs[pf->dplls.rclk.parent_idx[i]].pin;
1602 goto unregister_pins;
1604 ret = dpll_pin_on_pin_register(parent, pf->dplls.rclk.pin,
1605 ops, &pf->dplls.rclk);
1607 goto unregister_pins;
1609 if (WARN_ON((!vsi || !vsi->netdev)))
1611 netdev_dpll_pin_set(vsi->netdev, pf->dplls.rclk.pin);
1617 parent = pf->dplls.inputs[pf->dplls.rclk.parent_idx[--i]].pin;
1618 dpll_pin_on_pin_unregister(parent, pf->dplls.rclk.pin,
1619 &ice_dpll_rclk_ops, &pf->dplls.rclk);
1621 ice_dpll_release_pins(pin, ICE_DPLL_RCLK_NUM_PER_PF);
1626 * ice_dpll_deinit_pins - deinitialize direct pins
1627 * @pf: board private structure
1628 * @cgu: if cgu is controlled by this pf
1630 * If cgu is owned unregister directly connected pins from the dplls.
1631 * Release resources of directly connected pins from the dpll subsystem.
1633 static void ice_dpll_deinit_pins(struct ice_pf *pf, bool cgu)
1635 struct ice_dpll_pin *outputs = pf->dplls.outputs;
1636 struct ice_dpll_pin *inputs = pf->dplls.inputs;
1637 int num_outputs = pf->dplls.num_outputs;
1638 int num_inputs = pf->dplls.num_inputs;
1639 struct ice_dplls *d = &pf->dplls;
1640 struct ice_dpll *de = &d->eec;
1641 struct ice_dpll *dp = &d->pps;
1643 ice_dpll_deinit_rclk_pin(pf);
1645 ice_dpll_unregister_pins(dp->dpll, inputs, &ice_dpll_input_ops,
1647 ice_dpll_unregister_pins(de->dpll, inputs, &ice_dpll_input_ops,
1650 ice_dpll_release_pins(inputs, num_inputs);
1652 ice_dpll_unregister_pins(dp->dpll, outputs,
1653 &ice_dpll_output_ops, num_outputs);
1654 ice_dpll_unregister_pins(de->dpll, outputs,
1655 &ice_dpll_output_ops, num_outputs);
1656 ice_dpll_release_pins(outputs, num_outputs);
1661 * ice_dpll_init_pins - init pins and register pins with a dplls
1662 * @pf: board private structure
1663 * @cgu: if cgu is present and controlled by this NIC
1665 * Initialize directly connected pf's pins within pf's dplls in a Linux dpll
1670 * * negative - initialization failure reason
1672 static int ice_dpll_init_pins(struct ice_pf *pf, bool cgu)
1677 ret = ice_dpll_init_direct_pins(pf, cgu, pf->dplls.inputs, 0,
1678 pf->dplls.num_inputs,
1679 &ice_dpll_input_ops,
1680 pf->dplls.eec.dpll, pf->dplls.pps.dpll);
1684 ret = ice_dpll_init_direct_pins(pf, cgu, pf->dplls.outputs,
1685 pf->dplls.num_inputs,
1686 pf->dplls.num_outputs,
1687 &ice_dpll_output_ops,
1689 pf->dplls.pps.dpll);
1693 rclk_idx = pf->dplls.num_inputs + pf->dplls.num_outputs + pf->hw.pf_id;
1694 ret = ice_dpll_init_rclk_pins(pf, &pf->dplls.rclk, rclk_idx,
1695 &ice_dpll_rclk_ops);
1697 goto deinit_outputs;
1701 ice_dpll_deinit_direct_pins(cgu, pf->dplls.outputs,
1702 pf->dplls.num_outputs,
1703 &ice_dpll_output_ops, pf->dplls.pps.dpll,
1704 pf->dplls.eec.dpll);
1706 ice_dpll_deinit_direct_pins(cgu, pf->dplls.inputs, pf->dplls.num_inputs,
1707 &ice_dpll_input_ops, pf->dplls.pps.dpll,
1708 pf->dplls.eec.dpll);
1713 * ice_dpll_deinit_dpll - deinitialize dpll device
1714 * @pf: board private structure
1715 * @d: pointer to ice_dpll
1716 * @cgu: if cgu is present and controlled by this NIC
1718 * If cgu is owned unregister the dpll from dpll subsystem.
1719 * Release resources of dpll device from dpll subsystem.
1722 ice_dpll_deinit_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu)
1725 dpll_device_unregister(d->dpll, &ice_dpll_ops, d);
1726 dpll_device_put(d->dpll);
1730 * ice_dpll_init_dpll - initialize dpll device in dpll subsystem
1731 * @pf: board private structure
1732 * @d: dpll to be initialized
1733 * @cgu: if cgu is present and controlled by this NIC
1734 * @type: type of dpll being initialized
1736 * Allocate dpll instance for this board in dpll subsystem, if cgu is controlled
1737 * by this NIC, register dpll with the callback ops.
1741 * * negative - initialization failure reason
1744 ice_dpll_init_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu,
1745 enum dpll_type type)
1747 u64 clock_id = pf->dplls.clock_id;
1750 d->dpll = dpll_device_get(clock_id, d->dpll_idx, THIS_MODULE);
1751 if (IS_ERR(d->dpll)) {
1752 ret = PTR_ERR(d->dpll);
1753 dev_err(ice_pf_to_dev(pf),
1754 "dpll_device_get failed (%p) err=%d\n", d, ret);
1759 ret = dpll_device_register(d->dpll, type, &ice_dpll_ops, d);
1761 dpll_device_put(d->dpll);
1770 * ice_dpll_deinit_worker - deinitialize dpll kworker
1771 * @pf: board private structure
1773 * Stop dpll's kworker, release it's resources.
1775 static void ice_dpll_deinit_worker(struct ice_pf *pf)
1777 struct ice_dplls *d = &pf->dplls;
1779 kthread_cancel_delayed_work_sync(&d->work);
1780 kthread_destroy_worker(d->kworker);
1784 * ice_dpll_init_worker - Initialize DPLLs periodic worker
1785 * @pf: board private structure
1787 * Create and start DPLLs periodic worker.
1789 * Context: Shall be called after pf->dplls.lock is initialized.
1792 * * negative - create worker failure
1794 static int ice_dpll_init_worker(struct ice_pf *pf)
1796 struct ice_dplls *d = &pf->dplls;
1797 struct kthread_worker *kworker;
1799 ice_dpll_update_state(pf, &d->eec, true);
1800 ice_dpll_update_state(pf, &d->pps, true);
1801 kthread_init_delayed_work(&d->work, ice_dpll_periodic_work);
1802 kworker = kthread_create_worker(0, "ice-dplls-%s",
1803 dev_name(ice_pf_to_dev(pf)));
1804 if (IS_ERR(kworker))
1805 return PTR_ERR(kworker);
1806 d->kworker = kworker;
1807 d->cgu_state_acq_err_num = 0;
1808 kthread_queue_delayed_work(d->kworker, &d->work, 0);
1814 * ice_dpll_init_info_direct_pins - initializes direct pins info
1815 * @pf: board private structure
1816 * @pin_type: type of pins being initialized
1818 * Init information for directly connected pins, cache them in pf's pins
1823 * * negative - init failure reason
1826 ice_dpll_init_info_direct_pins(struct ice_pf *pf,
1827 enum ice_dpll_pin_type pin_type)
1829 struct ice_dpll *de = &pf->dplls.eec, *dp = &pf->dplls.pps;
1830 int num_pins, i, ret = -EINVAL;
1831 struct ice_hw *hw = &pf->hw;
1832 struct ice_dpll_pin *pins;
1837 case ICE_DPLL_PIN_TYPE_INPUT:
1838 pins = pf->dplls.inputs;
1839 num_pins = pf->dplls.num_inputs;
1842 case ICE_DPLL_PIN_TYPE_OUTPUT:
1843 pins = pf->dplls.outputs;
1844 num_pins = pf->dplls.num_outputs;
1851 for (i = 0; i < num_pins; i++) {
1853 pins[i].prop.board_label = ice_cgu_get_pin_name(hw, i, input);
1854 pins[i].prop.type = ice_cgu_get_pin_type(hw, i, input);
1856 ret = ice_aq_get_cgu_ref_prio(hw, de->dpll_idx, i,
1857 &de->input_prio[i]);
1860 ret = ice_aq_get_cgu_ref_prio(hw, dp->dpll_idx, i,
1861 &dp->input_prio[i]);
1864 pins[i].prop.capabilities |=
1865 DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE;
1866 pins[i].prop.phase_range.min =
1867 pf->dplls.input_phase_adj_max;
1868 pins[i].prop.phase_range.max =
1869 -pf->dplls.input_phase_adj_max;
1871 pins[i].prop.phase_range.min =
1872 pf->dplls.output_phase_adj_max;
1873 pins[i].prop.phase_range.max =
1874 -pf->dplls.output_phase_adj_max;
1876 pins[i].prop.capabilities |=
1877 DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;
1878 ret = ice_dpll_pin_state_update(pf, &pins[i], pin_type, NULL);
1881 pins[i].prop.freq_supported =
1882 ice_cgu_get_pin_freq_supp(hw, i, input, &freq_supp_num);
1883 pins[i].prop.freq_supported_num = freq_supp_num;
1891 * ice_dpll_init_info_rclk_pin - initializes rclk pin information
1892 * @pf: board private structure
1894 * Init information for rclk pin, cache them in pf->dplls.rclk.
1898 * * negative - init failure reason
1900 static int ice_dpll_init_info_rclk_pin(struct ice_pf *pf)
1902 struct ice_dpll_pin *pin = &pf->dplls.rclk;
1904 pin->prop.type = DPLL_PIN_TYPE_SYNCE_ETH_PORT;
1905 pin->prop.capabilities |= DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;
1908 return ice_dpll_pin_state_update(pf, pin,
1909 ICE_DPLL_PIN_TYPE_RCLK_INPUT, NULL);
1913 * ice_dpll_init_pins_info - init pins info wrapper
1914 * @pf: board private structure
1915 * @pin_type: type of pins being initialized
1917 * Wraps functions for pin initialization.
1921 * * negative - init failure reason
1924 ice_dpll_init_pins_info(struct ice_pf *pf, enum ice_dpll_pin_type pin_type)
1927 case ICE_DPLL_PIN_TYPE_INPUT:
1928 case ICE_DPLL_PIN_TYPE_OUTPUT:
1929 return ice_dpll_init_info_direct_pins(pf, pin_type);
1930 case ICE_DPLL_PIN_TYPE_RCLK_INPUT:
1931 return ice_dpll_init_info_rclk_pin(pf);
1938 * ice_dpll_deinit_info - release memory allocated for pins info
1939 * @pf: board private structure
1941 * Release memory allocated for pins by ice_dpll_init_info function.
1943 static void ice_dpll_deinit_info(struct ice_pf *pf)
1945 kfree(pf->dplls.inputs);
1946 kfree(pf->dplls.outputs);
1947 kfree(pf->dplls.eec.input_prio);
1948 kfree(pf->dplls.pps.input_prio);
1952 * ice_dpll_init_info - prepare pf's dpll information structure
1953 * @pf: board private structure
1954 * @cgu: if cgu is present and controlled by this NIC
1956 * Acquire (from HW) and set basic dpll information (on pf->dplls struct).
1960 * * negative - init failure reason
1962 static int ice_dpll_init_info(struct ice_pf *pf, bool cgu)
1964 struct ice_aqc_get_cgu_abilities abilities;
1965 struct ice_dpll *de = &pf->dplls.eec;
1966 struct ice_dpll *dp = &pf->dplls.pps;
1967 struct ice_dplls *d = &pf->dplls;
1968 struct ice_hw *hw = &pf->hw;
1969 int ret, alloc_size, i;
1971 d->clock_id = ice_generate_clock_id(pf);
1972 ret = ice_aq_get_cgu_abilities(hw, &abilities);
1974 dev_err(ice_pf_to_dev(pf),
1975 "err:%d %s failed to read cgu abilities\n",
1976 ret, ice_aq_str(hw->adminq.sq_last_status));
1980 de->dpll_idx = abilities.eec_dpll_idx;
1981 dp->dpll_idx = abilities.pps_dpll_idx;
1982 d->num_inputs = abilities.num_inputs;
1983 d->num_outputs = abilities.num_outputs;
1984 d->input_phase_adj_max = le32_to_cpu(abilities.max_in_phase_adj);
1985 d->output_phase_adj_max = le32_to_cpu(abilities.max_out_phase_adj);
1987 alloc_size = sizeof(*d->inputs) * d->num_inputs;
1988 d->inputs = kzalloc(alloc_size, GFP_KERNEL);
1992 alloc_size = sizeof(*de->input_prio) * d->num_inputs;
1993 de->input_prio = kzalloc(alloc_size, GFP_KERNEL);
1994 if (!de->input_prio)
1997 dp->input_prio = kzalloc(alloc_size, GFP_KERNEL);
1998 if (!dp->input_prio)
2001 ret = ice_dpll_init_pins_info(pf, ICE_DPLL_PIN_TYPE_INPUT);
2006 alloc_size = sizeof(*d->outputs) * d->num_outputs;
2007 d->outputs = kzalloc(alloc_size, GFP_KERNEL);
2013 ret = ice_dpll_init_pins_info(pf, ICE_DPLL_PIN_TYPE_OUTPUT);
2018 ret = ice_get_cgu_rclk_pin_info(&pf->hw, &d->base_rclk_idx,
2019 &pf->dplls.rclk.num_parents);
2022 for (i = 0; i < pf->dplls.rclk.num_parents; i++)
2023 pf->dplls.rclk.parent_idx[i] = d->base_rclk_idx + i;
2024 ret = ice_dpll_init_pins_info(pf, ICE_DPLL_PIN_TYPE_RCLK_INPUT);
2027 de->mode = DPLL_MODE_AUTOMATIC;
2028 dp->mode = DPLL_MODE_AUTOMATIC;
2030 dev_dbg(ice_pf_to_dev(pf),
2031 "%s - success, inputs:%u, outputs:%u rclk-parents:%u\n",
2032 __func__, d->num_inputs, d->num_outputs, d->rclk.num_parents);
2037 dev_err(ice_pf_to_dev(pf),
2038 "%s - fail: d->inputs:%p, de->input_prio:%p, dp->input_prio:%p, d->outputs:%p\n",
2039 __func__, d->inputs, de->input_prio,
2040 dp->input_prio, d->outputs);
2041 ice_dpll_deinit_info(pf);
2046 * ice_dpll_deinit - Disable the driver/HW support for dpll subsystem
2048 * @pf: board private structure
2050 * Handles the cleanup work required after dpll initialization, freeing
2051 * resources and unregistering the dpll, pin and all resources used for
2054 * Context: Destroys pf->dplls.lock mutex. Call only if ICE_FLAG_DPLL was set.
2056 void ice_dpll_deinit(struct ice_pf *pf)
2058 bool cgu = ice_is_feature_supported(pf, ICE_F_CGU);
2060 clear_bit(ICE_FLAG_DPLL, pf->flags);
2062 ice_dpll_deinit_worker(pf);
2064 ice_dpll_deinit_pins(pf, cgu);
2065 ice_dpll_deinit_dpll(pf, &pf->dplls.pps, cgu);
2066 ice_dpll_deinit_dpll(pf, &pf->dplls.eec, cgu);
2067 ice_dpll_deinit_info(pf);
2068 mutex_destroy(&pf->dplls.lock);
2072 * ice_dpll_init - initialize support for dpll subsystem
2073 * @pf: board private structure
2075 * Set up the device dplls, register them and pins connected within Linux dpll
2076 * subsystem. Allow userspace to obtain state of DPLL and handling of DPLL
2077 * configuration requests.
2079 * Context: Initializes pf->dplls.lock mutex.
2081 void ice_dpll_init(struct ice_pf *pf)
2083 bool cgu = ice_is_feature_supported(pf, ICE_F_CGU);
2084 struct ice_dplls *d = &pf->dplls;
2087 err = ice_dpll_init_info(pf, cgu);
2090 err = ice_dpll_init_dpll(pf, &pf->dplls.eec, cgu, DPLL_TYPE_EEC);
2093 err = ice_dpll_init_dpll(pf, &pf->dplls.pps, cgu, DPLL_TYPE_PPS);
2096 err = ice_dpll_init_pins(pf, cgu);
2099 mutex_init(&d->lock);
2101 err = ice_dpll_init_worker(pf);
2105 set_bit(ICE_FLAG_DPLL, pf->flags);
2110 ice_dpll_deinit_pins(pf, cgu);
2112 ice_dpll_deinit_dpll(pf, &pf->dplls.pps, cgu);
2114 ice_dpll_deinit_dpll(pf, &pf->dplls.eec, cgu);
2116 ice_dpll_deinit_info(pf);
2118 mutex_destroy(&d->lock);
2119 dev_warn(ice_pf_to_dev(pf), "DPLLs init failure err:%d\n", err);