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
12 #define ICE_DPLL_PIN_ESYNC_PULSE_HIGH_PERCENT 25
13 #define ICE_DPLL_PIN_GEN_RCLK_FREQ 1953125
16 * enum ice_dpll_pin_type - enumerate ice pin types:
17 * @ICE_DPLL_PIN_INVALID: invalid pin type
18 * @ICE_DPLL_PIN_TYPE_INPUT: input pin
19 * @ICE_DPLL_PIN_TYPE_OUTPUT: output pin
20 * @ICE_DPLL_PIN_TYPE_RCLK_INPUT: recovery clock input pin
22 enum ice_dpll_pin_type {
24 ICE_DPLL_PIN_TYPE_INPUT,
25 ICE_DPLL_PIN_TYPE_OUTPUT,
26 ICE_DPLL_PIN_TYPE_RCLK_INPUT,
29 static const char * const pin_type_name[] = {
30 [ICE_DPLL_PIN_TYPE_INPUT] = "input",
31 [ICE_DPLL_PIN_TYPE_OUTPUT] = "output",
32 [ICE_DPLL_PIN_TYPE_RCLK_INPUT] = "rclk-input",
35 static const struct dpll_pin_frequency ice_esync_range[] = {
36 DPLL_PIN_FREQUENCY_RANGE(0, DPLL_PIN_FREQUENCY_1_HZ),
40 * ice_dpll_is_reset - check if reset is in progress
41 * @pf: private board structure
42 * @extack: error reporting
44 * If reset is in progress, fill extack with error.
47 * * false - no reset in progress
48 * * true - reset in progress
50 static bool ice_dpll_is_reset(struct ice_pf *pf, struct netlink_ext_ack *extack)
52 if (ice_is_reset_in_progress(pf->state)) {
53 NL_SET_ERR_MSG(extack, "PF reset in progress");
60 * ice_dpll_pin_freq_set - set pin's frequency
61 * @pf: private board structure
62 * @pin: pointer to a pin
63 * @pin_type: type of pin being configured
64 * @freq: frequency to be set
65 * @extack: error reporting
67 * Set requested frequency on a pin.
69 * Context: Called under pf->dplls.lock
72 * * negative - error on AQ or wrong pin type given
75 ice_dpll_pin_freq_set(struct ice_pf *pf, struct ice_dpll_pin *pin,
76 enum ice_dpll_pin_type pin_type, const u32 freq,
77 struct netlink_ext_ack *extack)
83 case ICE_DPLL_PIN_TYPE_INPUT:
84 flags = ICE_AQC_SET_CGU_IN_CFG_FLG1_UPDATE_FREQ;
85 ret = ice_aq_set_input_pin_cfg(&pf->hw, pin->idx, flags,
86 pin->flags[0], freq, 0);
88 case ICE_DPLL_PIN_TYPE_OUTPUT:
89 flags = ICE_AQC_SET_CGU_OUT_CFG_UPDATE_FREQ;
90 ret = ice_aq_set_output_pin_cfg(&pf->hw, pin->idx, flags,
97 NL_SET_ERR_MSG_FMT(extack,
98 "err:%d %s failed to set pin freq:%u on pin:%u\n",
100 ice_aq_str(pf->hw.adminq.sq_last_status),
110 * ice_dpll_frequency_set - wrapper for pin callback for set frequency
111 * @pin: pointer to a pin
112 * @pin_priv: private data pointer passed on pin registration
113 * @dpll: pointer to dpll
114 * @dpll_priv: private data pointer passed on dpll registration
115 * @frequency: frequency to be set
116 * @extack: error reporting
117 * @pin_type: type of pin being configured
119 * Wraps internal set frequency command on a pin.
121 * Context: Acquires pf->dplls.lock
124 * * negative - error pin not found or couldn't set in hw
127 ice_dpll_frequency_set(const struct dpll_pin *pin, void *pin_priv,
128 const struct dpll_device *dpll, void *dpll_priv,
130 struct netlink_ext_ack *extack,
131 enum ice_dpll_pin_type pin_type)
133 struct ice_dpll_pin *p = pin_priv;
134 struct ice_dpll *d = dpll_priv;
135 struct ice_pf *pf = d->pf;
138 if (ice_dpll_is_reset(pf, extack))
141 mutex_lock(&pf->dplls.lock);
142 ret = ice_dpll_pin_freq_set(pf, p, pin_type, frequency, extack);
143 mutex_unlock(&pf->dplls.lock);
149 * ice_dpll_input_frequency_set - input pin callback for set frequency
150 * @pin: pointer to a pin
151 * @pin_priv: private data pointer passed on pin registration
152 * @dpll: pointer to dpll
153 * @dpll_priv: private data pointer passed on dpll registration
154 * @frequency: frequency to be set
155 * @extack: error reporting
157 * Wraps internal set frequency command on a pin.
159 * Context: Calls a function which acquires pf->dplls.lock
162 * * negative - error pin not found or couldn't set in hw
165 ice_dpll_input_frequency_set(const struct dpll_pin *pin, void *pin_priv,
166 const struct dpll_device *dpll, void *dpll_priv,
167 u64 frequency, struct netlink_ext_ack *extack)
169 return ice_dpll_frequency_set(pin, pin_priv, dpll, dpll_priv, frequency,
170 extack, ICE_DPLL_PIN_TYPE_INPUT);
174 * ice_dpll_output_frequency_set - output pin callback for set frequency
175 * @pin: pointer to a pin
176 * @pin_priv: private data pointer passed on pin registration
177 * @dpll: pointer to dpll
178 * @dpll_priv: private data pointer passed on dpll registration
179 * @frequency: frequency to be set
180 * @extack: error reporting
182 * Wraps internal set frequency command on a pin.
184 * Context: Calls a function which acquires pf->dplls.lock
187 * * negative - error pin not found or couldn't set in hw
190 ice_dpll_output_frequency_set(const struct dpll_pin *pin, void *pin_priv,
191 const struct dpll_device *dpll, void *dpll_priv,
192 u64 frequency, struct netlink_ext_ack *extack)
194 return ice_dpll_frequency_set(pin, pin_priv, dpll, dpll_priv, frequency,
195 extack, ICE_DPLL_PIN_TYPE_OUTPUT);
199 * ice_dpll_frequency_get - wrapper for pin callback for get frequency
200 * @pin: pointer to a pin
201 * @pin_priv: private data pointer passed on pin registration
202 * @dpll: pointer to dpll
203 * @dpll_priv: private data pointer passed on dpll registration
204 * @frequency: on success holds pin's frequency
205 * @extack: error reporting
206 * @pin_type: type of pin being configured
208 * Wraps internal get frequency command of a pin.
210 * Context: Acquires pf->dplls.lock
213 * * negative - error pin not found or couldn't get from hw
216 ice_dpll_frequency_get(const struct dpll_pin *pin, void *pin_priv,
217 const struct dpll_device *dpll, void *dpll_priv,
218 u64 *frequency, struct netlink_ext_ack *extack,
219 enum ice_dpll_pin_type pin_type)
221 struct ice_dpll_pin *p = pin_priv;
222 struct ice_dpll *d = dpll_priv;
223 struct ice_pf *pf = d->pf;
225 mutex_lock(&pf->dplls.lock);
226 *frequency = p->freq;
227 mutex_unlock(&pf->dplls.lock);
233 * ice_dpll_input_frequency_get - input pin callback for get frequency
234 * @pin: pointer to a pin
235 * @pin_priv: private data pointer passed on pin registration
236 * @dpll: pointer to dpll
237 * @dpll_priv: private data pointer passed on dpll registration
238 * @frequency: on success holds pin's frequency
239 * @extack: error reporting
241 * Wraps internal get frequency command of a input pin.
243 * Context: Calls a function which acquires pf->dplls.lock
246 * * negative - error pin not found or couldn't get from hw
249 ice_dpll_input_frequency_get(const struct dpll_pin *pin, void *pin_priv,
250 const struct dpll_device *dpll, void *dpll_priv,
251 u64 *frequency, struct netlink_ext_ack *extack)
253 return ice_dpll_frequency_get(pin, pin_priv, dpll, dpll_priv, frequency,
254 extack, ICE_DPLL_PIN_TYPE_INPUT);
258 * ice_dpll_output_frequency_get - output pin callback for get frequency
259 * @pin: pointer to a pin
260 * @pin_priv: private data pointer passed on pin registration
261 * @dpll: pointer to dpll
262 * @dpll_priv: private data pointer passed on dpll registration
263 * @frequency: on success holds pin's frequency
264 * @extack: error reporting
266 * Wraps internal get frequency command of a pin.
268 * Context: Calls a function which acquires pf->dplls.lock
271 * * negative - error pin not found or couldn't get from hw
274 ice_dpll_output_frequency_get(const struct dpll_pin *pin, void *pin_priv,
275 const struct dpll_device *dpll, void *dpll_priv,
276 u64 *frequency, struct netlink_ext_ack *extack)
278 return ice_dpll_frequency_get(pin, pin_priv, dpll, dpll_priv, frequency,
279 extack, ICE_DPLL_PIN_TYPE_OUTPUT);
283 * ice_dpll_pin_enable - enable a pin on dplls
284 * @hw: board private hw structure
285 * @pin: pointer to a pin
286 * @dpll_idx: dpll index to connect to output pin
287 * @pin_type: type of pin being enabled
288 * @extack: error reporting
290 * Enable a pin on both dplls. Store current state in pin->flags.
292 * Context: Called under pf->dplls.lock
298 ice_dpll_pin_enable(struct ice_hw *hw, struct ice_dpll_pin *pin,
299 u8 dpll_idx, enum ice_dpll_pin_type pin_type,
300 struct netlink_ext_ack *extack)
306 case ICE_DPLL_PIN_TYPE_INPUT:
307 if (pin->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN)
308 flags |= ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
309 flags |= ICE_AQC_SET_CGU_IN_CFG_FLG2_INPUT_EN;
310 ret = ice_aq_set_input_pin_cfg(hw, pin->idx, 0, flags, 0, 0);
312 case ICE_DPLL_PIN_TYPE_OUTPUT:
313 flags = ICE_AQC_SET_CGU_OUT_CFG_UPDATE_SRC_SEL;
314 if (pin->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN)
315 flags |= ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
316 flags |= ICE_AQC_SET_CGU_OUT_CFG_OUT_EN;
317 ret = ice_aq_set_output_pin_cfg(hw, pin->idx, flags, dpll_idx,
324 NL_SET_ERR_MSG_FMT(extack,
325 "err:%d %s failed to enable %s pin:%u\n",
326 ret, ice_aq_str(hw->adminq.sq_last_status),
327 pin_type_name[pin_type], pin->idx);
333 * ice_dpll_pin_disable - disable a pin on dplls
334 * @hw: board private hw structure
335 * @pin: pointer to a pin
336 * @pin_type: type of pin being disabled
337 * @extack: error reporting
339 * Disable a pin on both dplls. Store current state in pin->flags.
341 * Context: Called under pf->dplls.lock
347 ice_dpll_pin_disable(struct ice_hw *hw, struct ice_dpll_pin *pin,
348 enum ice_dpll_pin_type pin_type,
349 struct netlink_ext_ack *extack)
355 case ICE_DPLL_PIN_TYPE_INPUT:
356 if (pin->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN)
357 flags |= ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
358 ret = ice_aq_set_input_pin_cfg(hw, pin->idx, 0, flags, 0, 0);
360 case ICE_DPLL_PIN_TYPE_OUTPUT:
361 if (pin->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN)
362 flags |= ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
363 ret = ice_aq_set_output_pin_cfg(hw, pin->idx, flags, 0, 0, 0);
369 NL_SET_ERR_MSG_FMT(extack,
370 "err:%d %s failed to disable %s pin:%u\n",
371 ret, ice_aq_str(hw->adminq.sq_last_status),
372 pin_type_name[pin_type], pin->idx);
378 * ice_dpll_pin_state_update - update pin's state
379 * @pf: private board struct
380 * @pin: structure with pin attributes to be updated
381 * @pin_type: type of pin being updated
382 * @extack: error reporting
384 * Determine pin current state and frequency, then update struct
385 * holding the pin info. For input pin states are separated for each
386 * dpll, for rclk pins states are separated for each parent.
388 * Context: Called under pf->dplls.lock
394 ice_dpll_pin_state_update(struct ice_pf *pf, struct ice_dpll_pin *pin,
395 enum ice_dpll_pin_type pin_type,
396 struct netlink_ext_ack *extack)
398 u8 parent, port_num = ICE_AQC_SET_PHY_REC_CLK_OUT_CURR_PORT;
402 case ICE_DPLL_PIN_TYPE_INPUT:
403 ret = ice_aq_get_input_pin_cfg(&pf->hw, pin->idx, &pin->status,
404 NULL, NULL, &pin->flags[0],
405 &pin->freq, &pin->phase_adjust);
408 if (ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN & pin->flags[0]) {
410 pin->state[pf->dplls.eec.dpll_idx] =
411 pin->pin == pf->dplls.eec.active_input ?
412 DPLL_PIN_STATE_CONNECTED :
413 DPLL_PIN_STATE_SELECTABLE;
414 pin->state[pf->dplls.pps.dpll_idx] =
415 pin->pin == pf->dplls.pps.active_input ?
416 DPLL_PIN_STATE_CONNECTED :
417 DPLL_PIN_STATE_SELECTABLE;
419 pin->state[pf->dplls.eec.dpll_idx] =
420 DPLL_PIN_STATE_SELECTABLE;
421 pin->state[pf->dplls.pps.dpll_idx] =
422 DPLL_PIN_STATE_SELECTABLE;
425 pin->state[pf->dplls.eec.dpll_idx] =
426 DPLL_PIN_STATE_DISCONNECTED;
427 pin->state[pf->dplls.pps.dpll_idx] =
428 DPLL_PIN_STATE_DISCONNECTED;
431 case ICE_DPLL_PIN_TYPE_OUTPUT:
432 ret = ice_aq_get_output_pin_cfg(&pf->hw, pin->idx,
433 &pin->flags[0], &parent,
438 parent &= ICE_AQC_GET_CGU_OUT_CFG_DPLL_SRC_SEL;
439 if (ICE_AQC_GET_CGU_OUT_CFG_OUT_EN & pin->flags[0]) {
440 pin->state[pf->dplls.eec.dpll_idx] =
441 parent == pf->dplls.eec.dpll_idx ?
442 DPLL_PIN_STATE_CONNECTED :
443 DPLL_PIN_STATE_DISCONNECTED;
444 pin->state[pf->dplls.pps.dpll_idx] =
445 parent == pf->dplls.pps.dpll_idx ?
446 DPLL_PIN_STATE_CONNECTED :
447 DPLL_PIN_STATE_DISCONNECTED;
449 pin->state[pf->dplls.eec.dpll_idx] =
450 DPLL_PIN_STATE_DISCONNECTED;
451 pin->state[pf->dplls.pps.dpll_idx] =
452 DPLL_PIN_STATE_DISCONNECTED;
455 case ICE_DPLL_PIN_TYPE_RCLK_INPUT:
456 for (parent = 0; parent < pf->dplls.rclk.num_parents;
460 ret = ice_aq_get_phy_rec_clk_out(&pf->hw, &p,
466 if (ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN &
468 pin->state[parent] = DPLL_PIN_STATE_CONNECTED;
471 DPLL_PIN_STATE_DISCONNECTED;
481 NL_SET_ERR_MSG_FMT(extack,
482 "err:%d %s failed to update %s pin:%u\n",
484 ice_aq_str(pf->hw.adminq.sq_last_status),
485 pin_type_name[pin_type], pin->idx);
487 dev_err_ratelimited(ice_pf_to_dev(pf),
488 "err:%d %s failed to update %s pin:%u\n",
490 ice_aq_str(pf->hw.adminq.sq_last_status),
491 pin_type_name[pin_type], pin->idx);
496 * ice_dpll_hw_input_prio_set - set input priority value in hardware
497 * @pf: board private structure
498 * @dpll: ice dpll pointer
499 * @pin: ice pin pointer
500 * @prio: priority value being set on a dpll
501 * @extack: error reporting
503 * Internal wrapper for setting the priority in the hardware.
505 * Context: Called under pf->dplls.lock
508 * * negative - failure
511 ice_dpll_hw_input_prio_set(struct ice_pf *pf, struct ice_dpll *dpll,
512 struct ice_dpll_pin *pin, const u32 prio,
513 struct netlink_ext_ack *extack)
517 ret = ice_aq_set_cgu_ref_prio(&pf->hw, dpll->dpll_idx, pin->idx,
520 NL_SET_ERR_MSG_FMT(extack,
521 "err:%d %s failed to set pin prio:%u on pin:%u\n",
523 ice_aq_str(pf->hw.adminq.sq_last_status),
526 dpll->input_prio[pin->idx] = prio;
532 * ice_dpll_lock_status_get - get dpll lock status callback
533 * @dpll: registered dpll pointer
534 * @dpll_priv: private data pointer passed on dpll registration
535 * @status: on success holds dpll's lock status
536 * @status_error: status error value
537 * @extack: error reporting
539 * Dpll subsystem callback, provides dpll's lock status.
541 * Context: Acquires pf->dplls.lock
544 * * negative - failure
547 ice_dpll_lock_status_get(const struct dpll_device *dpll, void *dpll_priv,
548 enum dpll_lock_status *status,
549 enum dpll_lock_status_error *status_error,
550 struct netlink_ext_ack *extack)
552 struct ice_dpll *d = dpll_priv;
553 struct ice_pf *pf = d->pf;
555 mutex_lock(&pf->dplls.lock);
556 *status = d->dpll_state;
557 mutex_unlock(&pf->dplls.lock);
563 * ice_dpll_mode_get - get dpll's working mode
564 * @dpll: registered dpll pointer
565 * @dpll_priv: private data pointer passed on dpll registration
566 * @mode: on success holds current working mode of dpll
567 * @extack: error reporting
569 * Dpll subsystem callback. Provides working mode of dpll.
571 * Context: Acquires pf->dplls.lock
574 * * negative - failure
576 static int ice_dpll_mode_get(const struct dpll_device *dpll, void *dpll_priv,
577 enum dpll_mode *mode,
578 struct netlink_ext_ack *extack)
580 struct ice_dpll *d = dpll_priv;
581 struct ice_pf *pf = d->pf;
583 mutex_lock(&pf->dplls.lock);
585 mutex_unlock(&pf->dplls.lock);
591 * ice_dpll_pin_state_set - set pin's state on dpll
592 * @pin: pointer to a pin
593 * @pin_priv: private data pointer passed on pin registration
594 * @dpll: registered dpll pointer
595 * @dpll_priv: private data pointer passed on dpll registration
596 * @enable: if pin shalll be enabled
597 * @extack: error reporting
598 * @pin_type: type of a pin
600 * Set pin state on a pin.
602 * Context: Acquires pf->dplls.lock
604 * * 0 - OK or no change required
608 ice_dpll_pin_state_set(const struct dpll_pin *pin, void *pin_priv,
609 const struct dpll_device *dpll, void *dpll_priv,
610 bool enable, struct netlink_ext_ack *extack,
611 enum ice_dpll_pin_type pin_type)
613 struct ice_dpll_pin *p = pin_priv;
614 struct ice_dpll *d = dpll_priv;
615 struct ice_pf *pf = d->pf;
618 if (ice_dpll_is_reset(pf, extack))
621 mutex_lock(&pf->dplls.lock);
623 ret = ice_dpll_pin_enable(&pf->hw, p, d->dpll_idx, pin_type,
626 ret = ice_dpll_pin_disable(&pf->hw, p, pin_type, extack);
628 ret = ice_dpll_pin_state_update(pf, p, pin_type, extack);
629 mutex_unlock(&pf->dplls.lock);
635 * ice_dpll_output_state_set - enable/disable output pin on dpll device
636 * @pin: pointer to a pin
637 * @pin_priv: private data pointer passed on pin registration
638 * @dpll: dpll being configured
639 * @dpll_priv: private data pointer passed on dpll registration
640 * @state: state of pin to be set
641 * @extack: error reporting
643 * Dpll subsystem callback. Set given state on output type pin.
645 * Context: Calls a function which acquires pf->dplls.lock
647 * * 0 - successfully enabled mode
648 * * negative - failed to enable mode
651 ice_dpll_output_state_set(const struct dpll_pin *pin, void *pin_priv,
652 const struct dpll_device *dpll, void *dpll_priv,
653 enum dpll_pin_state state,
654 struct netlink_ext_ack *extack)
656 bool enable = state == DPLL_PIN_STATE_CONNECTED;
657 struct ice_dpll_pin *p = pin_priv;
658 struct ice_dpll *d = dpll_priv;
660 if (state == DPLL_PIN_STATE_SELECTABLE)
662 if (!enable && p->state[d->dpll_idx] == DPLL_PIN_STATE_DISCONNECTED)
665 return ice_dpll_pin_state_set(pin, pin_priv, dpll, dpll_priv, enable,
666 extack, ICE_DPLL_PIN_TYPE_OUTPUT);
670 * ice_dpll_input_state_set - enable/disable input pin on dpll levice
671 * @pin: pointer to a pin
672 * @pin_priv: private data pointer passed on pin registration
673 * @dpll: dpll being configured
674 * @dpll_priv: private data pointer passed on dpll registration
675 * @state: state of pin to be set
676 * @extack: error reporting
678 * Dpll subsystem callback. Enables given mode on input type pin.
680 * Context: Calls a function which acquires pf->dplls.lock
682 * * 0 - successfully enabled mode
683 * * negative - failed to enable mode
686 ice_dpll_input_state_set(const struct dpll_pin *pin, void *pin_priv,
687 const struct dpll_device *dpll, void *dpll_priv,
688 enum dpll_pin_state state,
689 struct netlink_ext_ack *extack)
691 bool enable = state == DPLL_PIN_STATE_SELECTABLE;
693 return ice_dpll_pin_state_set(pin, pin_priv, dpll, dpll_priv, enable,
694 extack, ICE_DPLL_PIN_TYPE_INPUT);
698 * ice_dpll_pin_state_get - set pin's state on dpll
699 * @pin: pointer to a pin
700 * @pin_priv: private data pointer passed on pin registration
701 * @dpll: registered dpll pointer
702 * @dpll_priv: private data pointer passed on dpll registration
703 * @state: on success holds state of the pin
704 * @extack: error reporting
705 * @pin_type: type of questioned pin
707 * Determine pin state set it on a pin.
709 * Context: Acquires pf->dplls.lock
712 * * negative - failed to get state
715 ice_dpll_pin_state_get(const struct dpll_pin *pin, void *pin_priv,
716 const struct dpll_device *dpll, void *dpll_priv,
717 enum dpll_pin_state *state,
718 struct netlink_ext_ack *extack,
719 enum ice_dpll_pin_type pin_type)
721 struct ice_dpll_pin *p = pin_priv;
722 struct ice_dpll *d = dpll_priv;
723 struct ice_pf *pf = d->pf;
726 if (ice_dpll_is_reset(pf, extack))
729 mutex_lock(&pf->dplls.lock);
730 ret = ice_dpll_pin_state_update(pf, p, pin_type, extack);
733 if (pin_type == ICE_DPLL_PIN_TYPE_INPUT ||
734 pin_type == ICE_DPLL_PIN_TYPE_OUTPUT)
735 *state = p->state[d->dpll_idx];
738 mutex_unlock(&pf->dplls.lock);
744 * ice_dpll_output_state_get - get output pin state on dpll device
745 * @pin: pointer to a pin
746 * @pin_priv: private data pointer passed on pin registration
747 * @dpll: registered dpll pointer
748 * @dpll_priv: private data pointer passed on dpll registration
749 * @state: on success holds state of the pin
750 * @extack: error reporting
752 * Dpll subsystem callback. Check state of a pin.
754 * Context: Calls a function which acquires pf->dplls.lock
757 * * negative - failed to get state
760 ice_dpll_output_state_get(const struct dpll_pin *pin, void *pin_priv,
761 const struct dpll_device *dpll, void *dpll_priv,
762 enum dpll_pin_state *state,
763 struct netlink_ext_ack *extack)
765 return ice_dpll_pin_state_get(pin, pin_priv, dpll, dpll_priv, state,
766 extack, ICE_DPLL_PIN_TYPE_OUTPUT);
770 * ice_dpll_input_state_get - get input pin state on dpll device
771 * @pin: pointer to a pin
772 * @pin_priv: private data pointer passed on pin registration
773 * @dpll: registered dpll pointer
774 * @dpll_priv: private data pointer passed on dpll registration
775 * @state: on success holds state of the pin
776 * @extack: error reporting
778 * Dpll subsystem callback. Check state of a input pin.
780 * Context: Calls a function which acquires pf->dplls.lock
783 * * negative - failed to get state
786 ice_dpll_input_state_get(const struct dpll_pin *pin, void *pin_priv,
787 const struct dpll_device *dpll, void *dpll_priv,
788 enum dpll_pin_state *state,
789 struct netlink_ext_ack *extack)
791 return ice_dpll_pin_state_get(pin, pin_priv, dpll, dpll_priv, state,
792 extack, ICE_DPLL_PIN_TYPE_INPUT);
796 * ice_dpll_input_prio_get - get dpll's input prio
797 * @pin: pointer to a pin
798 * @pin_priv: private data pointer passed on pin registration
799 * @dpll: registered dpll pointer
800 * @dpll_priv: private data pointer passed on dpll registration
801 * @prio: on success - returns input priority on dpll
802 * @extack: error reporting
804 * Dpll subsystem callback. Handler for getting priority of a input pin.
806 * Context: Acquires pf->dplls.lock
809 * * negative - failure
812 ice_dpll_input_prio_get(const struct dpll_pin *pin, void *pin_priv,
813 const struct dpll_device *dpll, void *dpll_priv,
814 u32 *prio, struct netlink_ext_ack *extack)
816 struct ice_dpll_pin *p = pin_priv;
817 struct ice_dpll *d = dpll_priv;
818 struct ice_pf *pf = d->pf;
820 mutex_lock(&pf->dplls.lock);
821 *prio = d->input_prio[p->idx];
822 mutex_unlock(&pf->dplls.lock);
828 * ice_dpll_input_prio_set - set dpll input prio
829 * @pin: pointer to a pin
830 * @pin_priv: private data pointer passed on pin registration
831 * @dpll: registered dpll pointer
832 * @dpll_priv: private data pointer passed on dpll registration
833 * @prio: input priority to be set on dpll
834 * @extack: error reporting
836 * Dpll subsystem callback. Handler for setting priority of a input pin.
838 * Context: Acquires pf->dplls.lock
841 * * negative - failure
844 ice_dpll_input_prio_set(const struct dpll_pin *pin, void *pin_priv,
845 const struct dpll_device *dpll, void *dpll_priv,
846 u32 prio, struct netlink_ext_ack *extack)
848 struct ice_dpll_pin *p = pin_priv;
849 struct ice_dpll *d = dpll_priv;
850 struct ice_pf *pf = d->pf;
853 if (ice_dpll_is_reset(pf, extack))
856 mutex_lock(&pf->dplls.lock);
857 ret = ice_dpll_hw_input_prio_set(pf, d, p, prio, extack);
858 mutex_unlock(&pf->dplls.lock);
864 * ice_dpll_input_direction - callback for get input pin direction
865 * @pin: pointer to a pin
866 * @pin_priv: private data pointer passed on pin registration
867 * @dpll: registered dpll pointer
868 * @dpll_priv: private data pointer passed on dpll registration
869 * @direction: holds input pin direction
870 * @extack: error reporting
872 * Dpll subsystem callback. Handler for getting direction of a input pin.
878 ice_dpll_input_direction(const struct dpll_pin *pin, void *pin_priv,
879 const struct dpll_device *dpll, void *dpll_priv,
880 enum dpll_pin_direction *direction,
881 struct netlink_ext_ack *extack)
883 *direction = DPLL_PIN_DIRECTION_INPUT;
889 * ice_dpll_output_direction - callback for get output pin direction
890 * @pin: pointer to a pin
891 * @pin_priv: private data pointer passed on pin registration
892 * @dpll: registered dpll pointer
893 * @dpll_priv: private data pointer passed on dpll registration
894 * @direction: holds output pin direction
895 * @extack: error reporting
897 * Dpll subsystem callback. Handler for getting direction of an output pin.
903 ice_dpll_output_direction(const struct dpll_pin *pin, void *pin_priv,
904 const struct dpll_device *dpll, void *dpll_priv,
905 enum dpll_pin_direction *direction,
906 struct netlink_ext_ack *extack)
908 *direction = DPLL_PIN_DIRECTION_OUTPUT;
914 * ice_dpll_pin_phase_adjust_get - callback for get 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: on success holds pin phase_adjust value
920 * @extack: error reporting
922 * Dpll subsystem callback. Handler for getting phase adjust value of a pin.
924 * Context: Acquires pf->dplls.lock
930 ice_dpll_pin_phase_adjust_get(const struct dpll_pin *pin, void *pin_priv,
931 const struct dpll_device *dpll, void *dpll_priv,
933 struct netlink_ext_ack *extack)
935 struct ice_dpll_pin *p = pin_priv;
936 struct ice_pf *pf = p->pf;
938 mutex_lock(&pf->dplls.lock);
939 *phase_adjust = p->phase_adjust;
940 mutex_unlock(&pf->dplls.lock);
946 * ice_dpll_pin_phase_adjust_set - helper for setting a pin phase adjust value
947 * @pin: pointer to a pin
948 * @pin_priv: private data pointer passed on pin registration
949 * @dpll: registered dpll pointer
950 * @dpll_priv: private data pointer passed on dpll registration
951 * @phase_adjust: phase_adjust to be set
952 * @extack: error reporting
953 * @type: type of a pin
955 * Helper for dpll subsystem callback. Handler for setting phase adjust value
958 * Context: Acquires pf->dplls.lock
964 ice_dpll_pin_phase_adjust_set(const struct dpll_pin *pin, void *pin_priv,
965 const struct dpll_device *dpll, void *dpll_priv,
967 struct netlink_ext_ack *extack,
968 enum ice_dpll_pin_type type)
970 struct ice_dpll_pin *p = pin_priv;
971 struct ice_dpll *d = dpll_priv;
972 struct ice_pf *pf = d->pf;
973 u8 flag, flags_en = 0;
976 if (ice_dpll_is_reset(pf, extack))
979 mutex_lock(&pf->dplls.lock);
981 case ICE_DPLL_PIN_TYPE_INPUT:
982 flag = ICE_AQC_SET_CGU_IN_CFG_FLG1_UPDATE_DELAY;
983 if (p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN)
984 flags_en |= ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
985 if (p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN)
986 flags_en |= ICE_AQC_SET_CGU_IN_CFG_FLG2_INPUT_EN;
987 ret = ice_aq_set_input_pin_cfg(&pf->hw, p->idx, flag, flags_en,
990 case ICE_DPLL_PIN_TYPE_OUTPUT:
991 flag = ICE_AQC_SET_CGU_OUT_CFG_UPDATE_PHASE;
992 if (p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_OUT_EN)
993 flag |= ICE_AQC_SET_CGU_OUT_CFG_OUT_EN;
994 if (p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN)
995 flag |= ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
996 ret = ice_aq_set_output_pin_cfg(&pf->hw, p->idx, flag, 0, 0,
1003 p->phase_adjust = phase_adjust;
1004 mutex_unlock(&pf->dplls.lock);
1006 NL_SET_ERR_MSG_FMT(extack,
1007 "err:%d %s failed to set pin phase_adjust:%d for pin:%u on dpll:%u\n",
1009 ice_aq_str(pf->hw.adminq.sq_last_status),
1010 phase_adjust, p->idx, d->dpll_idx);
1016 * ice_dpll_input_phase_adjust_set - callback for set input pin phase adjust
1017 * @pin: pointer to a pin
1018 * @pin_priv: private data pointer passed on pin registration
1019 * @dpll: registered dpll pointer
1020 * @dpll_priv: private data pointer passed on dpll registration
1021 * @phase_adjust: phase_adjust to be set
1022 * @extack: error reporting
1024 * Dpll subsystem callback. Wraps a handler for setting phase adjust on input
1027 * Context: Calls a function which acquires pf->dplls.lock
1030 * * negative - error
1033 ice_dpll_input_phase_adjust_set(const struct dpll_pin *pin, void *pin_priv,
1034 const struct dpll_device *dpll, void *dpll_priv,
1036 struct netlink_ext_ack *extack)
1038 return ice_dpll_pin_phase_adjust_set(pin, pin_priv, dpll, dpll_priv,
1039 phase_adjust, extack,
1040 ICE_DPLL_PIN_TYPE_INPUT);
1044 * ice_dpll_output_phase_adjust_set - callback for set output pin phase adjust
1045 * @pin: pointer to a pin
1046 * @pin_priv: private data pointer passed on pin registration
1047 * @dpll: registered dpll pointer
1048 * @dpll_priv: private data pointer passed on dpll registration
1049 * @phase_adjust: phase_adjust to be set
1050 * @extack: error reporting
1052 * Dpll subsystem callback. Wraps a handler for setting phase adjust on output
1055 * Context: Calls a function which acquires pf->dplls.lock
1058 * * negative - error
1061 ice_dpll_output_phase_adjust_set(const struct dpll_pin *pin, void *pin_priv,
1062 const struct dpll_device *dpll, void *dpll_priv,
1064 struct netlink_ext_ack *extack)
1066 return ice_dpll_pin_phase_adjust_set(pin, pin_priv, dpll, dpll_priv,
1067 phase_adjust, extack,
1068 ICE_DPLL_PIN_TYPE_OUTPUT);
1071 #define ICE_DPLL_PHASE_OFFSET_DIVIDER 100
1072 #define ICE_DPLL_PHASE_OFFSET_FACTOR \
1073 (DPLL_PHASE_OFFSET_DIVIDER / ICE_DPLL_PHASE_OFFSET_DIVIDER)
1075 * ice_dpll_phase_offset_get - callback for get dpll phase shift value
1076 * @pin: pointer to a pin
1077 * @pin_priv: private data pointer passed on pin registration
1078 * @dpll: registered dpll pointer
1079 * @dpll_priv: private data pointer passed on dpll registration
1080 * @phase_offset: on success holds pin phase_offset value
1081 * @extack: error reporting
1083 * Dpll subsystem callback. Handler for getting phase shift value between
1084 * dpll's input and output.
1086 * Context: Acquires pf->dplls.lock
1089 * * negative - error
1092 ice_dpll_phase_offset_get(const struct dpll_pin *pin, void *pin_priv,
1093 const struct dpll_device *dpll, void *dpll_priv,
1094 s64 *phase_offset, struct netlink_ext_ack *extack)
1096 struct ice_dpll *d = dpll_priv;
1097 struct ice_pf *pf = d->pf;
1099 mutex_lock(&pf->dplls.lock);
1100 if (d->active_input == pin)
1101 *phase_offset = d->phase_offset * ICE_DPLL_PHASE_OFFSET_FACTOR;
1104 mutex_unlock(&pf->dplls.lock);
1110 * ice_dpll_output_esync_set - callback for setting embedded sync
1111 * @pin: pointer to a pin
1112 * @pin_priv: private data pointer passed on pin registration
1113 * @dpll: registered dpll pointer
1114 * @dpll_priv: private data pointer passed on dpll registration
1115 * @freq: requested embedded sync frequency
1116 * @extack: error reporting
1118 * Dpll subsystem callback. Handler for setting embedded sync frequency value
1121 * Context: Acquires pf->dplls.lock
1124 * * negative - error
1127 ice_dpll_output_esync_set(const struct dpll_pin *pin, void *pin_priv,
1128 const struct dpll_device *dpll, void *dpll_priv,
1129 u64 freq, struct netlink_ext_ack *extack)
1131 struct ice_dpll_pin *p = pin_priv;
1132 struct ice_dpll *d = dpll_priv;
1133 struct ice_pf *pf = d->pf;
1137 if (ice_dpll_is_reset(pf, extack))
1139 mutex_lock(&pf->dplls.lock);
1140 if (p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_OUT_EN)
1141 flags = ICE_AQC_SET_CGU_OUT_CFG_OUT_EN;
1142 if (freq == DPLL_PIN_FREQUENCY_1_HZ) {
1143 if (p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN) {
1146 flags |= ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
1147 ret = ice_aq_set_output_pin_cfg(&pf->hw, p->idx, flags,
1151 if (!(p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN)) {
1154 flags &= ~ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
1155 ret = ice_aq_set_output_pin_cfg(&pf->hw, p->idx, flags,
1159 mutex_unlock(&pf->dplls.lock);
1165 * ice_dpll_output_esync_get - callback for getting embedded sync config
1166 * @pin: pointer to a pin
1167 * @pin_priv: private data pointer passed on pin registration
1168 * @dpll: registered dpll pointer
1169 * @dpll_priv: private data pointer passed on dpll registration
1170 * @esync: on success holds embedded sync pin properties
1171 * @extack: error reporting
1173 * Dpll subsystem callback. Handler for getting embedded sync frequency value
1174 * and capabilities on output pin.
1176 * Context: Acquires pf->dplls.lock
1179 * * negative - error
1182 ice_dpll_output_esync_get(const struct dpll_pin *pin, void *pin_priv,
1183 const struct dpll_device *dpll, void *dpll_priv,
1184 struct dpll_pin_esync *esync,
1185 struct netlink_ext_ack *extack)
1187 struct ice_dpll_pin *p = pin_priv;
1188 struct ice_dpll *d = dpll_priv;
1189 struct ice_pf *pf = d->pf;
1191 if (ice_dpll_is_reset(pf, extack))
1193 mutex_lock(&pf->dplls.lock);
1194 if (!(p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_ABILITY) ||
1195 p->freq != DPLL_PIN_FREQUENCY_10_MHZ) {
1196 mutex_unlock(&pf->dplls.lock);
1199 esync->range = ice_esync_range;
1200 esync->range_num = ARRAY_SIZE(ice_esync_range);
1201 if (p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN) {
1202 esync->freq = DPLL_PIN_FREQUENCY_1_HZ;
1203 esync->pulse = ICE_DPLL_PIN_ESYNC_PULSE_HIGH_PERCENT;
1208 mutex_unlock(&pf->dplls.lock);
1214 * ice_dpll_input_esync_set - callback for setting embedded sync
1215 * @pin: pointer to a pin
1216 * @pin_priv: private data pointer passed on pin registration
1217 * @dpll: registered dpll pointer
1218 * @dpll_priv: private data pointer passed on dpll registration
1219 * @freq: requested embedded sync frequency
1220 * @extack: error reporting
1222 * Dpll subsystem callback. Handler for setting embedded sync frequency value
1225 * Context: Acquires pf->dplls.lock
1228 * * negative - error
1231 ice_dpll_input_esync_set(const struct dpll_pin *pin, void *pin_priv,
1232 const struct dpll_device *dpll, void *dpll_priv,
1233 u64 freq, struct netlink_ext_ack *extack)
1235 struct ice_dpll_pin *p = pin_priv;
1236 struct ice_dpll *d = dpll_priv;
1237 struct ice_pf *pf = d->pf;
1241 if (ice_dpll_is_reset(pf, extack))
1243 mutex_lock(&pf->dplls.lock);
1244 if (p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN)
1245 flags_en = ICE_AQC_SET_CGU_IN_CFG_FLG2_INPUT_EN;
1246 if (freq == DPLL_PIN_FREQUENCY_1_HZ) {
1247 if (p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN) {
1250 flags_en |= ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
1251 ret = ice_aq_set_input_pin_cfg(&pf->hw, p->idx, 0,
1255 if (!(p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN)) {
1258 flags_en &= ~ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
1259 ret = ice_aq_set_input_pin_cfg(&pf->hw, p->idx, 0,
1263 mutex_unlock(&pf->dplls.lock);
1269 * ice_dpll_input_esync_get - callback for getting embedded sync config
1270 * @pin: pointer to a pin
1271 * @pin_priv: private data pointer passed on pin registration
1272 * @dpll: registered dpll pointer
1273 * @dpll_priv: private data pointer passed on dpll registration
1274 * @esync: on success holds embedded sync pin properties
1275 * @extack: error reporting
1277 * Dpll subsystem callback. Handler for getting embedded sync frequency value
1278 * and capabilities on input pin.
1280 * Context: Acquires pf->dplls.lock
1283 * * negative - error
1286 ice_dpll_input_esync_get(const struct dpll_pin *pin, void *pin_priv,
1287 const struct dpll_device *dpll, void *dpll_priv,
1288 struct dpll_pin_esync *esync,
1289 struct netlink_ext_ack *extack)
1291 struct ice_dpll_pin *p = pin_priv;
1292 struct ice_dpll *d = dpll_priv;
1293 struct ice_pf *pf = d->pf;
1295 if (ice_dpll_is_reset(pf, extack))
1297 mutex_lock(&pf->dplls.lock);
1298 if (!(p->status & ICE_AQC_GET_CGU_IN_CFG_STATUS_ESYNC_CAP) ||
1299 p->freq != DPLL_PIN_FREQUENCY_10_MHZ) {
1300 mutex_unlock(&pf->dplls.lock);
1303 esync->range = ice_esync_range;
1304 esync->range_num = ARRAY_SIZE(ice_esync_range);
1305 if (p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN) {
1306 esync->freq = DPLL_PIN_FREQUENCY_1_HZ;
1307 esync->pulse = ICE_DPLL_PIN_ESYNC_PULSE_HIGH_PERCENT;
1312 mutex_unlock(&pf->dplls.lock);
1318 * ice_dpll_rclk_state_on_pin_set - set a state on rclk pin
1319 * @pin: pointer to a pin
1320 * @pin_priv: private data pointer passed on pin registration
1321 * @parent_pin: pin parent pointer
1322 * @parent_pin_priv: parent private data pointer passed on pin registration
1323 * @state: state to be set on pin
1324 * @extack: error reporting
1326 * Dpll subsystem callback, set a state of a rclk pin on a parent pin
1328 * Context: Acquires pf->dplls.lock
1331 * * negative - failure
1334 ice_dpll_rclk_state_on_pin_set(const struct dpll_pin *pin, void *pin_priv,
1335 const struct dpll_pin *parent_pin,
1336 void *parent_pin_priv,
1337 enum dpll_pin_state state,
1338 struct netlink_ext_ack *extack)
1340 struct ice_dpll_pin *p = pin_priv, *parent = parent_pin_priv;
1341 bool enable = state == DPLL_PIN_STATE_CONNECTED;
1342 struct ice_pf *pf = p->pf;
1346 if (ice_dpll_is_reset(pf, extack))
1349 mutex_lock(&pf->dplls.lock);
1350 hw_idx = parent->idx - pf->dplls.base_rclk_idx;
1351 if (hw_idx >= pf->dplls.num_inputs)
1354 if ((enable && p->state[hw_idx] == DPLL_PIN_STATE_CONNECTED) ||
1355 (!enable && p->state[hw_idx] == DPLL_PIN_STATE_DISCONNECTED)) {
1356 NL_SET_ERR_MSG_FMT(extack,
1357 "pin:%u state:%u on parent:%u already set",
1358 p->idx, state, parent->idx);
1361 ret = ice_aq_set_phy_rec_clk_out(&pf->hw, hw_idx, enable,
1364 NL_SET_ERR_MSG_FMT(extack,
1365 "err:%d %s failed to set pin state:%u for pin:%u on parent:%u\n",
1367 ice_aq_str(pf->hw.adminq.sq_last_status),
1368 state, p->idx, parent->idx);
1370 mutex_unlock(&pf->dplls.lock);
1376 * ice_dpll_rclk_state_on_pin_get - get a state of rclk pin
1377 * @pin: pointer to a pin
1378 * @pin_priv: private data pointer passed on pin registration
1379 * @parent_pin: pin parent pointer
1380 * @parent_pin_priv: pin parent priv data pointer passed on pin registration
1381 * @state: on success holds pin state on parent pin
1382 * @extack: error reporting
1384 * dpll subsystem callback, get a state of a recovered clock pin.
1386 * Context: Acquires pf->dplls.lock
1389 * * negative - failure
1392 ice_dpll_rclk_state_on_pin_get(const struct dpll_pin *pin, void *pin_priv,
1393 const struct dpll_pin *parent_pin,
1394 void *parent_pin_priv,
1395 enum dpll_pin_state *state,
1396 struct netlink_ext_ack *extack)
1398 struct ice_dpll_pin *p = pin_priv, *parent = parent_pin_priv;
1399 struct ice_pf *pf = p->pf;
1403 if (ice_dpll_is_reset(pf, extack))
1406 mutex_lock(&pf->dplls.lock);
1407 hw_idx = parent->idx - pf->dplls.base_rclk_idx;
1408 if (hw_idx >= pf->dplls.num_inputs)
1411 ret = ice_dpll_pin_state_update(pf, p, ICE_DPLL_PIN_TYPE_RCLK_INPUT,
1416 *state = p->state[hw_idx];
1419 mutex_unlock(&pf->dplls.lock);
1424 static const struct dpll_pin_ops ice_dpll_rclk_ops = {
1425 .state_on_pin_set = ice_dpll_rclk_state_on_pin_set,
1426 .state_on_pin_get = ice_dpll_rclk_state_on_pin_get,
1427 .direction_get = ice_dpll_input_direction,
1430 static const struct dpll_pin_ops ice_dpll_input_ops = {
1431 .frequency_get = ice_dpll_input_frequency_get,
1432 .frequency_set = ice_dpll_input_frequency_set,
1433 .state_on_dpll_get = ice_dpll_input_state_get,
1434 .state_on_dpll_set = ice_dpll_input_state_set,
1435 .prio_get = ice_dpll_input_prio_get,
1436 .prio_set = ice_dpll_input_prio_set,
1437 .direction_get = ice_dpll_input_direction,
1438 .phase_adjust_get = ice_dpll_pin_phase_adjust_get,
1439 .phase_adjust_set = ice_dpll_input_phase_adjust_set,
1440 .phase_offset_get = ice_dpll_phase_offset_get,
1441 .esync_set = ice_dpll_input_esync_set,
1442 .esync_get = ice_dpll_input_esync_get,
1445 static const struct dpll_pin_ops ice_dpll_output_ops = {
1446 .frequency_get = ice_dpll_output_frequency_get,
1447 .frequency_set = ice_dpll_output_frequency_set,
1448 .state_on_dpll_get = ice_dpll_output_state_get,
1449 .state_on_dpll_set = ice_dpll_output_state_set,
1450 .direction_get = ice_dpll_output_direction,
1451 .phase_adjust_get = ice_dpll_pin_phase_adjust_get,
1452 .phase_adjust_set = ice_dpll_output_phase_adjust_set,
1453 .esync_set = ice_dpll_output_esync_set,
1454 .esync_get = ice_dpll_output_esync_get,
1457 static const struct dpll_device_ops ice_dpll_ops = {
1458 .lock_status_get = ice_dpll_lock_status_get,
1459 .mode_get = ice_dpll_mode_get,
1463 * ice_generate_clock_id - generates unique clock_id for registering dpll.
1464 * @pf: board private structure
1466 * Generates unique (per board) clock_id for allocation and search of dpll
1467 * devices in Linux dpll subsystem.
1469 * Return: generated clock id for the board
1471 static u64 ice_generate_clock_id(struct ice_pf *pf)
1473 return pci_get_dsn(pf->pdev);
1477 * ice_dpll_notify_changes - notify dpll subsystem about changes
1478 * @d: pointer do dpll
1480 * Once change detected appropriate event is submitted to the dpll subsystem.
1482 static void ice_dpll_notify_changes(struct ice_dpll *d)
1484 bool pin_notified = false;
1486 if (d->prev_dpll_state != d->dpll_state) {
1487 d->prev_dpll_state = d->dpll_state;
1488 dpll_device_change_ntf(d->dpll);
1490 if (d->prev_input != d->active_input) {
1492 dpll_pin_change_ntf(d->prev_input);
1493 d->prev_input = d->active_input;
1494 if (d->active_input) {
1495 dpll_pin_change_ntf(d->active_input);
1496 pin_notified = true;
1499 if (d->prev_phase_offset != d->phase_offset) {
1500 d->prev_phase_offset = d->phase_offset;
1501 if (!pin_notified && d->active_input)
1502 dpll_pin_change_ntf(d->active_input);
1507 * ice_dpll_update_state - update dpll state
1508 * @pf: pf private structure
1509 * @d: pointer to queried dpll device
1510 * @init: if function called on initialization of ice dpll
1512 * Poll current state of dpll from hw and update ice_dpll struct.
1514 * Context: Called by kworker under pf->dplls.lock
1517 * * negative - AQ failure
1520 ice_dpll_update_state(struct ice_pf *pf, struct ice_dpll *d, bool init)
1522 struct ice_dpll_pin *p = NULL;
1525 ret = ice_get_cgu_state(&pf->hw, d->dpll_idx, d->prev_dpll_state,
1526 &d->input_idx, &d->ref_state, &d->eec_mode,
1527 &d->phase_offset, &d->dpll_state);
1529 dev_dbg(ice_pf_to_dev(pf),
1530 "update dpll=%d, prev_src_idx:%u, src_idx:%u, state:%d, prev:%d mode:%d\n",
1531 d->dpll_idx, d->prev_input_idx, d->input_idx,
1532 d->dpll_state, d->prev_dpll_state, d->mode);
1534 dev_err(ice_pf_to_dev(pf),
1535 "update dpll=%d state failed, ret=%d %s\n",
1537 ice_aq_str(pf->hw.adminq.sq_last_status));
1541 if (d->dpll_state == DPLL_LOCK_STATUS_LOCKED ||
1542 d->dpll_state == DPLL_LOCK_STATUS_LOCKED_HO_ACQ)
1543 d->active_input = pf->dplls.inputs[d->input_idx].pin;
1544 p = &pf->dplls.inputs[d->input_idx];
1545 return ice_dpll_pin_state_update(pf, p,
1546 ICE_DPLL_PIN_TYPE_INPUT, NULL);
1548 if (d->dpll_state == DPLL_LOCK_STATUS_HOLDOVER ||
1549 d->dpll_state == DPLL_LOCK_STATUS_UNLOCKED) {
1550 d->active_input = NULL;
1551 if (d->input_idx != ICE_DPLL_PIN_IDX_INVALID)
1552 p = &pf->dplls.inputs[d->input_idx];
1553 d->prev_input_idx = ICE_DPLL_PIN_IDX_INVALID;
1554 d->input_idx = ICE_DPLL_PIN_IDX_INVALID;
1557 ret = ice_dpll_pin_state_update(pf, p,
1558 ICE_DPLL_PIN_TYPE_INPUT, NULL);
1559 } else if (d->input_idx != d->prev_input_idx) {
1560 if (d->prev_input_idx != ICE_DPLL_PIN_IDX_INVALID) {
1561 p = &pf->dplls.inputs[d->prev_input_idx];
1562 ice_dpll_pin_state_update(pf, p,
1563 ICE_DPLL_PIN_TYPE_INPUT,
1566 if (d->input_idx != ICE_DPLL_PIN_IDX_INVALID) {
1567 p = &pf->dplls.inputs[d->input_idx];
1568 d->active_input = p->pin;
1569 ice_dpll_pin_state_update(pf, p,
1570 ICE_DPLL_PIN_TYPE_INPUT,
1573 d->prev_input_idx = d->input_idx;
1580 * ice_dpll_periodic_work - DPLLs periodic worker
1581 * @work: pointer to kthread_work structure
1583 * DPLLs periodic worker is responsible for polling state of dpll.
1584 * Context: Holds pf->dplls.lock
1586 static void ice_dpll_periodic_work(struct kthread_work *work)
1588 struct ice_dplls *d = container_of(work, struct ice_dplls, work.work);
1589 struct ice_pf *pf = container_of(d, struct ice_pf, dplls);
1590 struct ice_dpll *de = &pf->dplls.eec;
1591 struct ice_dpll *dp = &pf->dplls.pps;
1594 if (ice_is_reset_in_progress(pf->state))
1596 mutex_lock(&pf->dplls.lock);
1597 ret = ice_dpll_update_state(pf, de, false);
1599 ret = ice_dpll_update_state(pf, dp, false);
1601 d->cgu_state_acq_err_num++;
1602 /* stop rescheduling this worker */
1603 if (d->cgu_state_acq_err_num >
1604 ICE_CGU_STATE_ACQ_ERR_THRESHOLD) {
1605 dev_err(ice_pf_to_dev(pf),
1606 "EEC/PPS DPLLs periodic work disabled\n");
1607 mutex_unlock(&pf->dplls.lock);
1611 mutex_unlock(&pf->dplls.lock);
1612 ice_dpll_notify_changes(de);
1613 ice_dpll_notify_changes(dp);
1616 /* Run twice a second or reschedule if update failed */
1617 kthread_queue_delayed_work(d->kworker, &d->work,
1618 ret ? msecs_to_jiffies(10) :
1619 msecs_to_jiffies(500));
1623 * ice_dpll_release_pins - release pins resources from dpll subsystem
1624 * @pins: pointer to pins array
1625 * @count: number of pins
1627 * Release resources of given pins array in the dpll subsystem.
1629 static void ice_dpll_release_pins(struct ice_dpll_pin *pins, int count)
1633 for (i = 0; i < count; i++)
1634 dpll_pin_put(pins[i].pin);
1638 * ice_dpll_get_pins - get pins from dpll subsystem
1639 * @pf: board private structure
1640 * @pins: pointer to pins array
1641 * @start_idx: get starts from this pin idx value
1642 * @count: number of pins
1643 * @clock_id: clock_id of dpll device
1645 * Get pins - allocate - in dpll subsystem, store them in pin field of given
1650 * * negative - allocation failure reason
1653 ice_dpll_get_pins(struct ice_pf *pf, struct ice_dpll_pin *pins,
1654 int start_idx, int count, u64 clock_id)
1658 for (i = 0; i < count; i++) {
1659 pins[i].pin = dpll_pin_get(clock_id, i + start_idx, THIS_MODULE,
1661 if (IS_ERR(pins[i].pin)) {
1662 ret = PTR_ERR(pins[i].pin);
1671 dpll_pin_put(pins[i].pin);
1676 * ice_dpll_unregister_pins - unregister pins from a dpll
1677 * @dpll: dpll device pointer
1678 * @pins: pointer to pins array
1679 * @ops: callback ops registered with the pins
1680 * @count: number of pins
1682 * Unregister pins of a given array of pins from given dpll device registered in
1686 ice_dpll_unregister_pins(struct dpll_device *dpll, struct ice_dpll_pin *pins,
1687 const struct dpll_pin_ops *ops, int count)
1691 for (i = 0; i < count; i++)
1692 dpll_pin_unregister(dpll, pins[i].pin, ops, &pins[i]);
1696 * ice_dpll_register_pins - register pins with a dpll
1697 * @dpll: dpll pointer to register pins with
1698 * @pins: pointer to pins array
1699 * @ops: callback ops registered with the pins
1700 * @count: number of pins
1702 * Register pins of a given array with given dpll in dpll subsystem.
1706 * * negative - registration failure reason
1709 ice_dpll_register_pins(struct dpll_device *dpll, struct ice_dpll_pin *pins,
1710 const struct dpll_pin_ops *ops, int count)
1714 for (i = 0; i < count; i++) {
1715 ret = dpll_pin_register(dpll, pins[i].pin, ops, &pins[i]);
1717 goto unregister_pins;
1724 dpll_pin_unregister(dpll, pins[i].pin, ops, &pins[i]);
1729 * ice_dpll_deinit_direct_pins - deinitialize direct pins
1730 * @cgu: if cgu is present and controlled by this NIC
1731 * @pins: pointer to pins array
1732 * @count: number of pins
1733 * @ops: callback ops registered with the pins
1734 * @first: dpll device pointer
1735 * @second: dpll device pointer
1737 * If cgu is owned unregister pins from given dplls.
1738 * Release pins resources to the dpll subsystem.
1741 ice_dpll_deinit_direct_pins(bool cgu, struct ice_dpll_pin *pins, int count,
1742 const struct dpll_pin_ops *ops,
1743 struct dpll_device *first,
1744 struct dpll_device *second)
1747 ice_dpll_unregister_pins(first, pins, ops, count);
1748 ice_dpll_unregister_pins(second, pins, ops, count);
1750 ice_dpll_release_pins(pins, count);
1754 * ice_dpll_init_direct_pins - initialize direct pins
1755 * @pf: board private structure
1756 * @cgu: if cgu is present and controlled by this NIC
1757 * @pins: pointer to pins array
1758 * @start_idx: on which index shall allocation start in dpll subsystem
1759 * @count: number of pins
1760 * @ops: callback ops registered with the pins
1761 * @first: dpll device pointer
1762 * @second: dpll device pointer
1764 * Allocate directly connected pins of a given array in dpll subsystem.
1765 * If cgu is owned register allocated pins with given dplls.
1769 * * negative - registration failure reason
1772 ice_dpll_init_direct_pins(struct ice_pf *pf, bool cgu,
1773 struct ice_dpll_pin *pins, int start_idx, int count,
1774 const struct dpll_pin_ops *ops,
1775 struct dpll_device *first, struct dpll_device *second)
1779 ret = ice_dpll_get_pins(pf, pins, start_idx, count, pf->dplls.clock_id);
1783 ret = ice_dpll_register_pins(first, pins, ops, count);
1786 ret = ice_dpll_register_pins(second, pins, ops, count);
1788 goto unregister_first;
1794 ice_dpll_unregister_pins(first, pins, ops, count);
1796 ice_dpll_release_pins(pins, count);
1801 * ice_dpll_deinit_rclk_pin - release rclk pin resources
1802 * @pf: board private structure
1804 * Deregister rclk pin from parent pins and release resources in dpll subsystem.
1806 static void ice_dpll_deinit_rclk_pin(struct ice_pf *pf)
1808 struct ice_dpll_pin *rclk = &pf->dplls.rclk;
1809 struct ice_vsi *vsi = ice_get_main_vsi(pf);
1810 struct dpll_pin *parent;
1813 for (i = 0; i < rclk->num_parents; i++) {
1814 parent = pf->dplls.inputs[rclk->parent_idx[i]].pin;
1817 dpll_pin_on_pin_unregister(parent, rclk->pin,
1818 &ice_dpll_rclk_ops, rclk);
1820 if (WARN_ON_ONCE(!vsi || !vsi->netdev))
1822 dpll_netdev_pin_clear(vsi->netdev);
1823 dpll_pin_put(rclk->pin);
1827 * ice_dpll_init_rclk_pins - initialize recovered clock pin
1828 * @pf: board private structure
1829 * @pin: pin to register
1830 * @start_idx: on which index shall allocation start in dpll subsystem
1831 * @ops: callback ops registered with the pins
1833 * Allocate resource for recovered clock pin in dpll subsystem. Register the
1834 * pin with the parents it has in the info. Register pin with the pf's main vsi
1839 * * negative - registration failure reason
1842 ice_dpll_init_rclk_pins(struct ice_pf *pf, struct ice_dpll_pin *pin,
1843 int start_idx, const struct dpll_pin_ops *ops)
1845 struct ice_vsi *vsi = ice_get_main_vsi(pf);
1846 struct dpll_pin *parent;
1849 if (WARN_ON((!vsi || !vsi->netdev)))
1851 ret = ice_dpll_get_pins(pf, pin, start_idx, ICE_DPLL_RCLK_NUM_PER_PF,
1852 pf->dplls.clock_id);
1855 for (i = 0; i < pf->dplls.rclk.num_parents; i++) {
1856 parent = pf->dplls.inputs[pf->dplls.rclk.parent_idx[i]].pin;
1859 goto unregister_pins;
1861 ret = dpll_pin_on_pin_register(parent, pf->dplls.rclk.pin,
1862 ops, &pf->dplls.rclk);
1864 goto unregister_pins;
1866 dpll_netdev_pin_set(vsi->netdev, pf->dplls.rclk.pin);
1872 parent = pf->dplls.inputs[pf->dplls.rclk.parent_idx[--i]].pin;
1873 dpll_pin_on_pin_unregister(parent, pf->dplls.rclk.pin,
1874 &ice_dpll_rclk_ops, &pf->dplls.rclk);
1876 ice_dpll_release_pins(pin, ICE_DPLL_RCLK_NUM_PER_PF);
1881 * ice_dpll_deinit_pins - deinitialize direct pins
1882 * @pf: board private structure
1883 * @cgu: if cgu is controlled by this pf
1885 * If cgu is owned unregister directly connected pins from the dplls.
1886 * Release resources of directly connected pins from the dpll subsystem.
1888 static void ice_dpll_deinit_pins(struct ice_pf *pf, bool cgu)
1890 struct ice_dpll_pin *outputs = pf->dplls.outputs;
1891 struct ice_dpll_pin *inputs = pf->dplls.inputs;
1892 int num_outputs = pf->dplls.num_outputs;
1893 int num_inputs = pf->dplls.num_inputs;
1894 struct ice_dplls *d = &pf->dplls;
1895 struct ice_dpll *de = &d->eec;
1896 struct ice_dpll *dp = &d->pps;
1898 ice_dpll_deinit_rclk_pin(pf);
1900 ice_dpll_unregister_pins(dp->dpll, inputs, &ice_dpll_input_ops,
1902 ice_dpll_unregister_pins(de->dpll, inputs, &ice_dpll_input_ops,
1905 ice_dpll_release_pins(inputs, num_inputs);
1907 ice_dpll_unregister_pins(dp->dpll, outputs,
1908 &ice_dpll_output_ops, num_outputs);
1909 ice_dpll_unregister_pins(de->dpll, outputs,
1910 &ice_dpll_output_ops, num_outputs);
1911 ice_dpll_release_pins(outputs, num_outputs);
1916 * ice_dpll_init_pins - init pins and register pins with a dplls
1917 * @pf: board private structure
1918 * @cgu: if cgu is present and controlled by this NIC
1920 * Initialize directly connected pf's pins within pf's dplls in a Linux dpll
1925 * * negative - initialization failure reason
1927 static int ice_dpll_init_pins(struct ice_pf *pf, bool cgu)
1932 ret = ice_dpll_init_direct_pins(pf, cgu, pf->dplls.inputs, 0,
1933 pf->dplls.num_inputs,
1934 &ice_dpll_input_ops,
1935 pf->dplls.eec.dpll, pf->dplls.pps.dpll);
1939 ret = ice_dpll_init_direct_pins(pf, cgu, pf->dplls.outputs,
1940 pf->dplls.num_inputs,
1941 pf->dplls.num_outputs,
1942 &ice_dpll_output_ops,
1944 pf->dplls.pps.dpll);
1948 rclk_idx = pf->dplls.num_inputs + pf->dplls.num_outputs + pf->hw.pf_id;
1949 ret = ice_dpll_init_rclk_pins(pf, &pf->dplls.rclk, rclk_idx,
1950 &ice_dpll_rclk_ops);
1952 goto deinit_outputs;
1956 ice_dpll_deinit_direct_pins(cgu, pf->dplls.outputs,
1957 pf->dplls.num_outputs,
1958 &ice_dpll_output_ops, pf->dplls.pps.dpll,
1959 pf->dplls.eec.dpll);
1961 ice_dpll_deinit_direct_pins(cgu, pf->dplls.inputs, pf->dplls.num_inputs,
1962 &ice_dpll_input_ops, pf->dplls.pps.dpll,
1963 pf->dplls.eec.dpll);
1968 * ice_dpll_deinit_dpll - deinitialize dpll device
1969 * @pf: board private structure
1970 * @d: pointer to ice_dpll
1971 * @cgu: if cgu is present and controlled by this NIC
1973 * If cgu is owned unregister the dpll from dpll subsystem.
1974 * Release resources of dpll device from dpll subsystem.
1977 ice_dpll_deinit_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu)
1980 dpll_device_unregister(d->dpll, &ice_dpll_ops, d);
1981 dpll_device_put(d->dpll);
1985 * ice_dpll_init_dpll - initialize dpll device in dpll subsystem
1986 * @pf: board private structure
1987 * @d: dpll to be initialized
1988 * @cgu: if cgu is present and controlled by this NIC
1989 * @type: type of dpll being initialized
1991 * Allocate dpll instance for this board in dpll subsystem, if cgu is controlled
1992 * by this NIC, register dpll with the callback ops.
1996 * * negative - initialization failure reason
1999 ice_dpll_init_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu,
2000 enum dpll_type type)
2002 u64 clock_id = pf->dplls.clock_id;
2005 d->dpll = dpll_device_get(clock_id, d->dpll_idx, THIS_MODULE);
2006 if (IS_ERR(d->dpll)) {
2007 ret = PTR_ERR(d->dpll);
2008 dev_err(ice_pf_to_dev(pf),
2009 "dpll_device_get failed (%p) err=%d\n", d, ret);
2014 ice_dpll_update_state(pf, d, true);
2015 ret = dpll_device_register(d->dpll, type, &ice_dpll_ops, d);
2017 dpll_device_put(d->dpll);
2026 * ice_dpll_deinit_worker - deinitialize dpll kworker
2027 * @pf: board private structure
2029 * Stop dpll's kworker, release it's resources.
2031 static void ice_dpll_deinit_worker(struct ice_pf *pf)
2033 struct ice_dplls *d = &pf->dplls;
2035 kthread_cancel_delayed_work_sync(&d->work);
2036 kthread_destroy_worker(d->kworker);
2040 * ice_dpll_init_worker - Initialize DPLLs periodic worker
2041 * @pf: board private structure
2043 * Create and start DPLLs periodic worker.
2045 * Context: Shall be called after pf->dplls.lock is initialized.
2048 * * negative - create worker failure
2050 static int ice_dpll_init_worker(struct ice_pf *pf)
2052 struct ice_dplls *d = &pf->dplls;
2053 struct kthread_worker *kworker;
2055 kthread_init_delayed_work(&d->work, ice_dpll_periodic_work);
2056 kworker = kthread_create_worker(0, "ice-dplls-%s",
2057 dev_name(ice_pf_to_dev(pf)));
2058 if (IS_ERR(kworker))
2059 return PTR_ERR(kworker);
2060 d->kworker = kworker;
2061 d->cgu_state_acq_err_num = 0;
2062 kthread_queue_delayed_work(d->kworker, &d->work, 0);
2068 * ice_dpll_init_info_pins_generic - initializes generic pins info
2069 * @pf: board private structure
2070 * @input: if input pins initialized
2072 * Init information for generic pins, cache them in PF's pins structures.
2076 * * negative - init failure reason
2078 static int ice_dpll_init_info_pins_generic(struct ice_pf *pf, bool input)
2080 struct ice_dpll *de = &pf->dplls.eec, *dp = &pf->dplls.pps;
2081 static const char labels[][sizeof("99")] = {
2082 "0", "1", "2", "3", "4", "5", "6", "7", "8",
2083 "9", "10", "11", "12", "13", "14", "15" };
2084 u32 cap = DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;
2085 enum ice_dpll_pin_type pin_type;
2086 int i, pin_num, ret = -EINVAL;
2087 struct ice_dpll_pin *pins;
2091 pin_num = pf->dplls.num_inputs;
2092 pins = pf->dplls.inputs;
2093 phase_adj_max = pf->dplls.input_phase_adj_max;
2094 pin_type = ICE_DPLL_PIN_TYPE_INPUT;
2095 cap |= DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE;
2097 pin_num = pf->dplls.num_outputs;
2098 pins = pf->dplls.outputs;
2099 phase_adj_max = pf->dplls.output_phase_adj_max;
2100 pin_type = ICE_DPLL_PIN_TYPE_OUTPUT;
2102 if (pin_num > ARRAY_SIZE(labels))
2105 for (i = 0; i < pin_num; i++) {
2107 pins[i].prop.board_label = labels[i];
2108 pins[i].prop.phase_range.min = phase_adj_max;
2109 pins[i].prop.phase_range.max = -phase_adj_max;
2110 pins[i].prop.capabilities = cap;
2112 ret = ice_dpll_pin_state_update(pf, &pins[i], pin_type, NULL);
2115 if (input && pins[i].freq == ICE_DPLL_PIN_GEN_RCLK_FREQ)
2116 pins[i].prop.type = DPLL_PIN_TYPE_MUX;
2118 pins[i].prop.type = DPLL_PIN_TYPE_EXT;
2121 ret = ice_aq_get_cgu_ref_prio(&pf->hw, de->dpll_idx, i,
2122 &de->input_prio[i]);
2125 ret = ice_aq_get_cgu_ref_prio(&pf->hw, dp->dpll_idx, i,
2126 &dp->input_prio[i]);
2135 * ice_dpll_init_info_direct_pins - initializes direct pins info
2136 * @pf: board private structure
2137 * @pin_type: type of pins being initialized
2139 * Init information for directly connected pins, cache them in pf's pins
2144 * * negative - init failure reason
2147 ice_dpll_init_info_direct_pins(struct ice_pf *pf,
2148 enum ice_dpll_pin_type pin_type)
2150 struct ice_dpll *de = &pf->dplls.eec, *dp = &pf->dplls.pps;
2151 int num_pins, i, ret = -EINVAL;
2152 struct ice_hw *hw = &pf->hw;
2153 struct ice_dpll_pin *pins;
2159 case ICE_DPLL_PIN_TYPE_INPUT:
2160 pins = pf->dplls.inputs;
2161 num_pins = pf->dplls.num_inputs;
2164 case ICE_DPLL_PIN_TYPE_OUTPUT:
2165 pins = pf->dplls.outputs;
2166 num_pins = pf->dplls.num_outputs;
2172 if (num_pins != ice_cgu_get_num_pins(hw, input))
2173 return ice_dpll_init_info_pins_generic(pf, input);
2175 for (i = 0; i < num_pins; i++) {
2178 pins[i].prop.board_label = ice_cgu_get_pin_name(hw, i, input);
2179 pins[i].prop.type = ice_cgu_get_pin_type(hw, i, input);
2181 ret = ice_aq_get_cgu_ref_prio(hw, de->dpll_idx, i,
2182 &de->input_prio[i]);
2185 ret = ice_aq_get_cgu_ref_prio(hw, dp->dpll_idx, i,
2186 &dp->input_prio[i]);
2189 caps |= (DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE |
2190 DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE);
2191 pins[i].prop.phase_range.min =
2192 pf->dplls.input_phase_adj_max;
2193 pins[i].prop.phase_range.max =
2194 -pf->dplls.input_phase_adj_max;
2196 pins[i].prop.phase_range.min =
2197 pf->dplls.output_phase_adj_max;
2198 pins[i].prop.phase_range.max =
2199 -pf->dplls.output_phase_adj_max;
2200 ret = ice_cgu_get_output_pin_state_caps(hw, i, &caps);
2204 pins[i].prop.capabilities = caps;
2205 ret = ice_dpll_pin_state_update(pf, &pins[i], pin_type, NULL);
2208 pins[i].prop.freq_supported =
2209 ice_cgu_get_pin_freq_supp(hw, i, input, &freq_supp_num);
2210 pins[i].prop.freq_supported_num = freq_supp_num;
2218 * ice_dpll_init_info_rclk_pin - initializes rclk pin information
2219 * @pf: board private structure
2221 * Init information for rclk pin, cache them in pf->dplls.rclk.
2225 * * negative - init failure reason
2227 static int ice_dpll_init_info_rclk_pin(struct ice_pf *pf)
2229 struct ice_dpll_pin *pin = &pf->dplls.rclk;
2231 pin->prop.type = DPLL_PIN_TYPE_SYNCE_ETH_PORT;
2232 pin->prop.capabilities |= DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;
2235 return ice_dpll_pin_state_update(pf, pin,
2236 ICE_DPLL_PIN_TYPE_RCLK_INPUT, NULL);
2240 * ice_dpll_init_pins_info - init pins info wrapper
2241 * @pf: board private structure
2242 * @pin_type: type of pins being initialized
2244 * Wraps functions for pin initialization.
2248 * * negative - init failure reason
2251 ice_dpll_init_pins_info(struct ice_pf *pf, enum ice_dpll_pin_type pin_type)
2254 case ICE_DPLL_PIN_TYPE_INPUT:
2255 case ICE_DPLL_PIN_TYPE_OUTPUT:
2256 return ice_dpll_init_info_direct_pins(pf, pin_type);
2257 case ICE_DPLL_PIN_TYPE_RCLK_INPUT:
2258 return ice_dpll_init_info_rclk_pin(pf);
2265 * ice_dpll_deinit_info - release memory allocated for pins info
2266 * @pf: board private structure
2268 * Release memory allocated for pins by ice_dpll_init_info function.
2270 static void ice_dpll_deinit_info(struct ice_pf *pf)
2272 kfree(pf->dplls.inputs);
2273 kfree(pf->dplls.outputs);
2274 kfree(pf->dplls.eec.input_prio);
2275 kfree(pf->dplls.pps.input_prio);
2279 * ice_dpll_init_info - prepare pf's dpll information structure
2280 * @pf: board private structure
2281 * @cgu: if cgu is present and controlled by this NIC
2283 * Acquire (from HW) and set basic dpll information (on pf->dplls struct).
2287 * * negative - init failure reason
2289 static int ice_dpll_init_info(struct ice_pf *pf, bool cgu)
2291 struct ice_aqc_get_cgu_abilities abilities;
2292 struct ice_dpll *de = &pf->dplls.eec;
2293 struct ice_dpll *dp = &pf->dplls.pps;
2294 struct ice_dplls *d = &pf->dplls;
2295 struct ice_hw *hw = &pf->hw;
2296 int ret, alloc_size, i;
2298 d->clock_id = ice_generate_clock_id(pf);
2299 ret = ice_aq_get_cgu_abilities(hw, &abilities);
2301 dev_err(ice_pf_to_dev(pf),
2302 "err:%d %s failed to read cgu abilities\n",
2303 ret, ice_aq_str(hw->adminq.sq_last_status));
2307 de->dpll_idx = abilities.eec_dpll_idx;
2308 dp->dpll_idx = abilities.pps_dpll_idx;
2309 d->num_inputs = abilities.num_inputs;
2310 d->num_outputs = abilities.num_outputs;
2311 d->input_phase_adj_max = le32_to_cpu(abilities.max_in_phase_adj);
2312 d->output_phase_adj_max = le32_to_cpu(abilities.max_out_phase_adj);
2314 alloc_size = sizeof(*d->inputs) * d->num_inputs;
2315 d->inputs = kzalloc(alloc_size, GFP_KERNEL);
2319 alloc_size = sizeof(*de->input_prio) * d->num_inputs;
2320 de->input_prio = kzalloc(alloc_size, GFP_KERNEL);
2321 if (!de->input_prio)
2324 dp->input_prio = kzalloc(alloc_size, GFP_KERNEL);
2325 if (!dp->input_prio)
2328 ret = ice_dpll_init_pins_info(pf, ICE_DPLL_PIN_TYPE_INPUT);
2333 alloc_size = sizeof(*d->outputs) * d->num_outputs;
2334 d->outputs = kzalloc(alloc_size, GFP_KERNEL);
2340 ret = ice_dpll_init_pins_info(pf, ICE_DPLL_PIN_TYPE_OUTPUT);
2345 ret = ice_get_cgu_rclk_pin_info(&pf->hw, &d->base_rclk_idx,
2346 &pf->dplls.rclk.num_parents);
2349 for (i = 0; i < pf->dplls.rclk.num_parents; i++)
2350 pf->dplls.rclk.parent_idx[i] = d->base_rclk_idx + i;
2351 ret = ice_dpll_init_pins_info(pf, ICE_DPLL_PIN_TYPE_RCLK_INPUT);
2354 de->mode = DPLL_MODE_AUTOMATIC;
2355 dp->mode = DPLL_MODE_AUTOMATIC;
2357 dev_dbg(ice_pf_to_dev(pf),
2358 "%s - success, inputs:%u, outputs:%u rclk-parents:%u\n",
2359 __func__, d->num_inputs, d->num_outputs, d->rclk.num_parents);
2364 dev_err(ice_pf_to_dev(pf),
2365 "%s - fail: d->inputs:%p, de->input_prio:%p, dp->input_prio:%p, d->outputs:%p\n",
2366 __func__, d->inputs, de->input_prio,
2367 dp->input_prio, d->outputs);
2368 ice_dpll_deinit_info(pf);
2373 * ice_dpll_deinit - Disable the driver/HW support for dpll subsystem
2375 * @pf: board private structure
2377 * Handles the cleanup work required after dpll initialization, freeing
2378 * resources and unregistering the dpll, pin and all resources used for
2381 * Context: Destroys pf->dplls.lock mutex. Call only if ICE_FLAG_DPLL was set.
2383 void ice_dpll_deinit(struct ice_pf *pf)
2385 bool cgu = ice_is_feature_supported(pf, ICE_F_CGU);
2387 clear_bit(ICE_FLAG_DPLL, pf->flags);
2389 ice_dpll_deinit_worker(pf);
2391 ice_dpll_deinit_pins(pf, cgu);
2392 ice_dpll_deinit_dpll(pf, &pf->dplls.pps, cgu);
2393 ice_dpll_deinit_dpll(pf, &pf->dplls.eec, cgu);
2394 ice_dpll_deinit_info(pf);
2395 mutex_destroy(&pf->dplls.lock);
2399 * ice_dpll_init - initialize support for dpll subsystem
2400 * @pf: board private structure
2402 * Set up the device dplls, register them and pins connected within Linux dpll
2403 * subsystem. Allow userspace to obtain state of DPLL and handling of DPLL
2404 * configuration requests.
2406 * Context: Initializes pf->dplls.lock mutex.
2408 void ice_dpll_init(struct ice_pf *pf)
2410 bool cgu = ice_is_feature_supported(pf, ICE_F_CGU);
2411 struct ice_dplls *d = &pf->dplls;
2414 mutex_init(&d->lock);
2415 err = ice_dpll_init_info(pf, cgu);
2418 err = ice_dpll_init_dpll(pf, &pf->dplls.eec, cgu, DPLL_TYPE_EEC);
2421 err = ice_dpll_init_dpll(pf, &pf->dplls.pps, cgu, DPLL_TYPE_PPS);
2424 err = ice_dpll_init_pins(pf, cgu);
2428 err = ice_dpll_init_worker(pf);
2432 set_bit(ICE_FLAG_DPLL, pf->flags);
2437 ice_dpll_deinit_pins(pf, cgu);
2439 ice_dpll_deinit_dpll(pf, &pf->dplls.pps, cgu);
2441 ice_dpll_deinit_dpll(pf, &pf->dplls.eec, cgu);
2443 ice_dpll_deinit_info(pf);
2445 mutex_destroy(&d->lock);
2446 dev_warn(ice_pf_to_dev(pf), "DPLLs init failure err:%d\n", err);