xref: /linux/drivers/net/ethernet/intel/ice/ice_dpll.c (revision 55d0969c451159cff86949b38c39171cab962069)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2022, Intel Corporation. */
3 
4 #include "ice.h"
5 #include "ice_lib.h"
6 #include "ice_trace.h"
7 #include <linux/dpll.h>
8 
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 
14 /**
15  * enum ice_dpll_pin_type - enumerate ice pin types:
16  * @ICE_DPLL_PIN_INVALID: invalid pin type
17  * @ICE_DPLL_PIN_TYPE_INPUT: input pin
18  * @ICE_DPLL_PIN_TYPE_OUTPUT: output pin
19  * @ICE_DPLL_PIN_TYPE_RCLK_INPUT: recovery clock input pin
20  */
21 enum ice_dpll_pin_type {
22 	ICE_DPLL_PIN_INVALID,
23 	ICE_DPLL_PIN_TYPE_INPUT,
24 	ICE_DPLL_PIN_TYPE_OUTPUT,
25 	ICE_DPLL_PIN_TYPE_RCLK_INPUT,
26 };
27 
28 static const char * const pin_type_name[] = {
29 	[ICE_DPLL_PIN_TYPE_INPUT] = "input",
30 	[ICE_DPLL_PIN_TYPE_OUTPUT] = "output",
31 	[ICE_DPLL_PIN_TYPE_RCLK_INPUT] = "rclk-input",
32 };
33 
34 static const struct dpll_pin_frequency ice_esync_range[] = {
35 	DPLL_PIN_FREQUENCY_RANGE(0, DPLL_PIN_FREQUENCY_1_HZ),
36 };
37 
38 /**
39  * ice_dpll_is_reset - check if reset is in progress
40  * @pf: private board structure
41  * @extack: error reporting
42  *
43  * If reset is in progress, fill extack with error.
44  *
45  * Return:
46  * * false - no reset in progress
47  * * true - reset in progress
48  */
49 static bool ice_dpll_is_reset(struct ice_pf *pf, struct netlink_ext_ack *extack)
50 {
51 	if (ice_is_reset_in_progress(pf->state)) {
52 		NL_SET_ERR_MSG(extack, "PF reset in progress");
53 		return true;
54 	}
55 	return false;
56 }
57 
58 /**
59  * ice_dpll_pin_freq_set - set pin's frequency
60  * @pf: private board structure
61  * @pin: pointer to a pin
62  * @pin_type: type of pin being configured
63  * @freq: frequency to be set
64  * @extack: error reporting
65  *
66  * Set requested frequency on a pin.
67  *
68  * Context: Called under pf->dplls.lock
69  * Return:
70  * * 0 - success
71  * * negative - error on AQ or wrong pin type given
72  */
73 static int
74 ice_dpll_pin_freq_set(struct ice_pf *pf, struct ice_dpll_pin *pin,
75 		      enum ice_dpll_pin_type pin_type, const u32 freq,
76 		      struct netlink_ext_ack *extack)
77 {
78 	u8 flags;
79 	int ret;
80 
81 	switch (pin_type) {
82 	case ICE_DPLL_PIN_TYPE_INPUT:
83 		flags = ICE_AQC_SET_CGU_IN_CFG_FLG1_UPDATE_FREQ;
84 		ret = ice_aq_set_input_pin_cfg(&pf->hw, pin->idx, flags,
85 					       pin->flags[0], freq, 0);
86 		break;
87 	case ICE_DPLL_PIN_TYPE_OUTPUT:
88 		flags = ICE_AQC_SET_CGU_OUT_CFG_UPDATE_FREQ;
89 		ret = ice_aq_set_output_pin_cfg(&pf->hw, pin->idx, flags,
90 						0, freq, 0);
91 		break;
92 	default:
93 		return -EINVAL;
94 	}
95 	if (ret) {
96 		NL_SET_ERR_MSG_FMT(extack,
97 				   "err:%d %s failed to set pin freq:%u on pin:%u\n",
98 				   ret,
99 				   ice_aq_str(pf->hw.adminq.sq_last_status),
100 				   freq, pin->idx);
101 		return ret;
102 	}
103 	pin->freq = freq;
104 
105 	return 0;
106 }
107 
108 /**
109  * ice_dpll_frequency_set - wrapper for pin callback for set frequency
110  * @pin: pointer to a pin
111  * @pin_priv: private data pointer passed on pin registration
112  * @dpll: pointer to dpll
113  * @dpll_priv: private data pointer passed on dpll registration
114  * @frequency: frequency to be set
115  * @extack: error reporting
116  * @pin_type: type of pin being configured
117  *
118  * Wraps internal set frequency command on a pin.
119  *
120  * Context: Acquires pf->dplls.lock
121  * Return:
122  * * 0 - success
123  * * negative - error pin not found or couldn't set in hw
124  */
125 static int
126 ice_dpll_frequency_set(const struct dpll_pin *pin, void *pin_priv,
127 		       const struct dpll_device *dpll, void *dpll_priv,
128 		       const u32 frequency,
129 		       struct netlink_ext_ack *extack,
130 		       enum ice_dpll_pin_type pin_type)
131 {
132 	struct ice_dpll_pin *p = pin_priv;
133 	struct ice_dpll *d = dpll_priv;
134 	struct ice_pf *pf = d->pf;
135 	int ret;
136 
137 	if (ice_dpll_is_reset(pf, extack))
138 		return -EBUSY;
139 
140 	mutex_lock(&pf->dplls.lock);
141 	ret = ice_dpll_pin_freq_set(pf, p, pin_type, frequency, extack);
142 	mutex_unlock(&pf->dplls.lock);
143 
144 	return ret;
145 }
146 
147 /**
148  * ice_dpll_input_frequency_set - input pin callback for set frequency
149  * @pin: pointer to a pin
150  * @pin_priv: private data pointer passed on pin registration
151  * @dpll: pointer to dpll
152  * @dpll_priv: private data pointer passed on dpll registration
153  * @frequency: frequency to be set
154  * @extack: error reporting
155  *
156  * Wraps internal set frequency command on a pin.
157  *
158  * Context: Calls a function which acquires pf->dplls.lock
159  * Return:
160  * * 0 - success
161  * * negative - error pin not found or couldn't set in hw
162  */
163 static int
164 ice_dpll_input_frequency_set(const struct dpll_pin *pin, void *pin_priv,
165 			     const struct dpll_device *dpll, void *dpll_priv,
166 			     u64 frequency, struct netlink_ext_ack *extack)
167 {
168 	return ice_dpll_frequency_set(pin, pin_priv, dpll, dpll_priv, frequency,
169 				      extack, ICE_DPLL_PIN_TYPE_INPUT);
170 }
171 
172 /**
173  * ice_dpll_output_frequency_set - output pin callback for set frequency
174  * @pin: pointer to a pin
175  * @pin_priv: private data pointer passed on pin registration
176  * @dpll: pointer to dpll
177  * @dpll_priv: private data pointer passed on dpll registration
178  * @frequency: frequency to be set
179  * @extack: error reporting
180  *
181  * Wraps internal set frequency command on a pin.
182  *
183  * Context: Calls a function which acquires pf->dplls.lock
184  * Return:
185  * * 0 - success
186  * * negative - error pin not found or couldn't set in hw
187  */
188 static int
189 ice_dpll_output_frequency_set(const struct dpll_pin *pin, void *pin_priv,
190 			      const struct dpll_device *dpll, void *dpll_priv,
191 			      u64 frequency, struct netlink_ext_ack *extack)
192 {
193 	return ice_dpll_frequency_set(pin, pin_priv, dpll, dpll_priv, frequency,
194 				      extack, ICE_DPLL_PIN_TYPE_OUTPUT);
195 }
196 
197 /**
198  * ice_dpll_frequency_get - wrapper for pin callback for get frequency
199  * @pin: pointer to a pin
200  * @pin_priv: private data pointer passed on pin registration
201  * @dpll: pointer to dpll
202  * @dpll_priv: private data pointer passed on dpll registration
203  * @frequency: on success holds pin's frequency
204  * @extack: error reporting
205  * @pin_type: type of pin being configured
206  *
207  * Wraps internal get frequency command of a pin.
208  *
209  * Context: Acquires pf->dplls.lock
210  * Return:
211  * * 0 - success
212  * * negative - error pin not found or couldn't get from hw
213  */
214 static int
215 ice_dpll_frequency_get(const struct dpll_pin *pin, void *pin_priv,
216 		       const struct dpll_device *dpll, void *dpll_priv,
217 		       u64 *frequency, struct netlink_ext_ack *extack,
218 		       enum ice_dpll_pin_type pin_type)
219 {
220 	struct ice_dpll_pin *p = pin_priv;
221 	struct ice_dpll *d = dpll_priv;
222 	struct ice_pf *pf = d->pf;
223 
224 	mutex_lock(&pf->dplls.lock);
225 	*frequency = p->freq;
226 	mutex_unlock(&pf->dplls.lock);
227 
228 	return 0;
229 }
230 
231 /**
232  * ice_dpll_input_frequency_get - input pin callback for get frequency
233  * @pin: pointer to a pin
234  * @pin_priv: private data pointer passed on pin registration
235  * @dpll: pointer to dpll
236  * @dpll_priv: private data pointer passed on dpll registration
237  * @frequency: on success holds pin's frequency
238  * @extack: error reporting
239  *
240  * Wraps internal get frequency command of a input pin.
241  *
242  * Context: Calls a function which acquires pf->dplls.lock
243  * Return:
244  * * 0 - success
245  * * negative - error pin not found or couldn't get from hw
246  */
247 static int
248 ice_dpll_input_frequency_get(const struct dpll_pin *pin, void *pin_priv,
249 			     const struct dpll_device *dpll, void *dpll_priv,
250 			     u64 *frequency, struct netlink_ext_ack *extack)
251 {
252 	return ice_dpll_frequency_get(pin, pin_priv, dpll, dpll_priv, frequency,
253 				      extack, ICE_DPLL_PIN_TYPE_INPUT);
254 }
255 
256 /**
257  * ice_dpll_output_frequency_get - output pin callback for get frequency
258  * @pin: pointer to a pin
259  * @pin_priv: private data pointer passed on pin registration
260  * @dpll: pointer to dpll
261  * @dpll_priv: private data pointer passed on dpll registration
262  * @frequency: on success holds pin's frequency
263  * @extack: error reporting
264  *
265  * Wraps internal get frequency command of a pin.
266  *
267  * Context: Calls a function which acquires pf->dplls.lock
268  * Return:
269  * * 0 - success
270  * * negative - error pin not found or couldn't get from hw
271  */
272 static int
273 ice_dpll_output_frequency_get(const struct dpll_pin *pin, void *pin_priv,
274 			      const struct dpll_device *dpll, void *dpll_priv,
275 			      u64 *frequency, struct netlink_ext_ack *extack)
276 {
277 	return ice_dpll_frequency_get(pin, pin_priv, dpll, dpll_priv, frequency,
278 				      extack, ICE_DPLL_PIN_TYPE_OUTPUT);
279 }
280 
281 /**
282  * ice_dpll_pin_enable - enable a pin on dplls
283  * @hw: board private hw structure
284  * @pin: pointer to a pin
285  * @dpll_idx: dpll index to connect to output pin
286  * @pin_type: type of pin being enabled
287  * @extack: error reporting
288  *
289  * Enable a pin on both dplls. Store current state in pin->flags.
290  *
291  * Context: Called under pf->dplls.lock
292  * Return:
293  * * 0 - OK
294  * * negative - error
295  */
296 static int
297 ice_dpll_pin_enable(struct ice_hw *hw, struct ice_dpll_pin *pin,
298 		    u8 dpll_idx, enum ice_dpll_pin_type pin_type,
299 		    struct netlink_ext_ack *extack)
300 {
301 	u8 flags = 0;
302 	int ret;
303 
304 	switch (pin_type) {
305 	case ICE_DPLL_PIN_TYPE_INPUT:
306 		if (pin->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN)
307 			flags |= ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
308 		flags |= ICE_AQC_SET_CGU_IN_CFG_FLG2_INPUT_EN;
309 		ret = ice_aq_set_input_pin_cfg(hw, pin->idx, 0, flags, 0, 0);
310 		break;
311 	case ICE_DPLL_PIN_TYPE_OUTPUT:
312 		flags = ICE_AQC_SET_CGU_OUT_CFG_UPDATE_SRC_SEL;
313 		if (pin->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN)
314 			flags |= ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
315 		flags |= ICE_AQC_SET_CGU_OUT_CFG_OUT_EN;
316 		ret = ice_aq_set_output_pin_cfg(hw, pin->idx, flags, dpll_idx,
317 						0, 0);
318 		break;
319 	default:
320 		return -EINVAL;
321 	}
322 	if (ret)
323 		NL_SET_ERR_MSG_FMT(extack,
324 				   "err:%d %s failed to enable %s pin:%u\n",
325 				   ret, ice_aq_str(hw->adminq.sq_last_status),
326 				   pin_type_name[pin_type], pin->idx);
327 
328 	return ret;
329 }
330 
331 /**
332  * ice_dpll_pin_disable - disable a pin on dplls
333  * @hw: board private hw structure
334  * @pin: pointer to a pin
335  * @pin_type: type of pin being disabled
336  * @extack: error reporting
337  *
338  * Disable a pin on both dplls. Store current state in pin->flags.
339  *
340  * Context: Called under pf->dplls.lock
341  * Return:
342  * * 0 - OK
343  * * negative - error
344  */
345 static int
346 ice_dpll_pin_disable(struct ice_hw *hw, struct ice_dpll_pin *pin,
347 		     enum ice_dpll_pin_type pin_type,
348 		     struct netlink_ext_ack *extack)
349 {
350 	u8 flags = 0;
351 	int ret;
352 
353 	switch (pin_type) {
354 	case ICE_DPLL_PIN_TYPE_INPUT:
355 		if (pin->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN)
356 			flags |= ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
357 		ret = ice_aq_set_input_pin_cfg(hw, pin->idx, 0, flags, 0, 0);
358 		break;
359 	case ICE_DPLL_PIN_TYPE_OUTPUT:
360 		if (pin->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN)
361 			flags |= ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
362 		ret = ice_aq_set_output_pin_cfg(hw, pin->idx, flags, 0, 0, 0);
363 		break;
364 	default:
365 		return -EINVAL;
366 	}
367 	if (ret)
368 		NL_SET_ERR_MSG_FMT(extack,
369 				   "err:%d %s failed to disable %s pin:%u\n",
370 				   ret, ice_aq_str(hw->adminq.sq_last_status),
371 				   pin_type_name[pin_type], pin->idx);
372 
373 	return ret;
374 }
375 
376 /**
377  * ice_dpll_pin_state_update - update pin's state
378  * @pf: private board struct
379  * @pin: structure with pin attributes to be updated
380  * @pin_type: type of pin being updated
381  * @extack: error reporting
382  *
383  * Determine pin current state and frequency, then update struct
384  * holding the pin info. For input pin states are separated for each
385  * dpll, for rclk pins states are separated for each parent.
386  *
387  * Context: Called under pf->dplls.lock
388  * Return:
389  * * 0 - OK
390  * * negative - error
391  */
392 static int
393 ice_dpll_pin_state_update(struct ice_pf *pf, struct ice_dpll_pin *pin,
394 			  enum ice_dpll_pin_type pin_type,
395 			  struct netlink_ext_ack *extack)
396 {
397 	u8 parent, port_num = ICE_AQC_SET_PHY_REC_CLK_OUT_CURR_PORT;
398 	int ret;
399 
400 	switch (pin_type) {
401 	case ICE_DPLL_PIN_TYPE_INPUT:
402 		ret = ice_aq_get_input_pin_cfg(&pf->hw, pin->idx, &pin->status,
403 					       NULL, NULL, &pin->flags[0],
404 					       &pin->freq, &pin->phase_adjust);
405 		if (ret)
406 			goto err;
407 		if (ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN & pin->flags[0]) {
408 			if (pin->pin) {
409 				pin->state[pf->dplls.eec.dpll_idx] =
410 					pin->pin == pf->dplls.eec.active_input ?
411 					DPLL_PIN_STATE_CONNECTED :
412 					DPLL_PIN_STATE_SELECTABLE;
413 				pin->state[pf->dplls.pps.dpll_idx] =
414 					pin->pin == pf->dplls.pps.active_input ?
415 					DPLL_PIN_STATE_CONNECTED :
416 					DPLL_PIN_STATE_SELECTABLE;
417 			} else {
418 				pin->state[pf->dplls.eec.dpll_idx] =
419 					DPLL_PIN_STATE_SELECTABLE;
420 				pin->state[pf->dplls.pps.dpll_idx] =
421 					DPLL_PIN_STATE_SELECTABLE;
422 			}
423 		} else {
424 			pin->state[pf->dplls.eec.dpll_idx] =
425 				DPLL_PIN_STATE_DISCONNECTED;
426 			pin->state[pf->dplls.pps.dpll_idx] =
427 				DPLL_PIN_STATE_DISCONNECTED;
428 		}
429 		break;
430 	case ICE_DPLL_PIN_TYPE_OUTPUT:
431 		ret = ice_aq_get_output_pin_cfg(&pf->hw, pin->idx,
432 						&pin->flags[0], &parent,
433 						&pin->freq, NULL);
434 		if (ret)
435 			goto err;
436 
437 		parent &= ICE_AQC_GET_CGU_OUT_CFG_DPLL_SRC_SEL;
438 		if (ICE_AQC_GET_CGU_OUT_CFG_OUT_EN & pin->flags[0]) {
439 			pin->state[pf->dplls.eec.dpll_idx] =
440 				parent == pf->dplls.eec.dpll_idx ?
441 				DPLL_PIN_STATE_CONNECTED :
442 				DPLL_PIN_STATE_DISCONNECTED;
443 			pin->state[pf->dplls.pps.dpll_idx] =
444 				parent == pf->dplls.pps.dpll_idx ?
445 				DPLL_PIN_STATE_CONNECTED :
446 				DPLL_PIN_STATE_DISCONNECTED;
447 		} else {
448 			pin->state[pf->dplls.eec.dpll_idx] =
449 				DPLL_PIN_STATE_DISCONNECTED;
450 			pin->state[pf->dplls.pps.dpll_idx] =
451 				DPLL_PIN_STATE_DISCONNECTED;
452 		}
453 		break;
454 	case ICE_DPLL_PIN_TYPE_RCLK_INPUT:
455 		for (parent = 0; parent < pf->dplls.rclk.num_parents;
456 		     parent++) {
457 			u8 p = parent;
458 
459 			ret = ice_aq_get_phy_rec_clk_out(&pf->hw, &p,
460 							 &port_num,
461 							 &pin->flags[parent],
462 							 NULL);
463 			if (ret)
464 				goto err;
465 			if (ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN &
466 			    pin->flags[parent])
467 				pin->state[parent] = DPLL_PIN_STATE_CONNECTED;
468 			else
469 				pin->state[parent] =
470 					DPLL_PIN_STATE_DISCONNECTED;
471 		}
472 		break;
473 	default:
474 		return -EINVAL;
475 	}
476 
477 	return 0;
478 err:
479 	if (extack)
480 		NL_SET_ERR_MSG_FMT(extack,
481 				   "err:%d %s failed to update %s pin:%u\n",
482 				   ret,
483 				   ice_aq_str(pf->hw.adminq.sq_last_status),
484 				   pin_type_name[pin_type], pin->idx);
485 	else
486 		dev_err_ratelimited(ice_pf_to_dev(pf),
487 				    "err:%d %s failed to update %s pin:%u\n",
488 				    ret,
489 				    ice_aq_str(pf->hw.adminq.sq_last_status),
490 				    pin_type_name[pin_type], pin->idx);
491 	return ret;
492 }
493 
494 /**
495  * ice_dpll_hw_input_prio_set - set input priority value in hardware
496  * @pf: board private structure
497  * @dpll: ice dpll pointer
498  * @pin: ice pin pointer
499  * @prio: priority value being set on a dpll
500  * @extack: error reporting
501  *
502  * Internal wrapper for setting the priority in the hardware.
503  *
504  * Context: Called under pf->dplls.lock
505  * Return:
506  * * 0 - success
507  * * negative - failure
508  */
509 static int
510 ice_dpll_hw_input_prio_set(struct ice_pf *pf, struct ice_dpll *dpll,
511 			   struct ice_dpll_pin *pin, const u32 prio,
512 			   struct netlink_ext_ack *extack)
513 {
514 	int ret;
515 
516 	ret = ice_aq_set_cgu_ref_prio(&pf->hw, dpll->dpll_idx, pin->idx,
517 				      (u8)prio);
518 	if (ret)
519 		NL_SET_ERR_MSG_FMT(extack,
520 				   "err:%d %s failed to set pin prio:%u on pin:%u\n",
521 				   ret,
522 				   ice_aq_str(pf->hw.adminq.sq_last_status),
523 				   prio, pin->idx);
524 	else
525 		dpll->input_prio[pin->idx] = prio;
526 
527 	return ret;
528 }
529 
530 /**
531  * ice_dpll_lock_status_get - get dpll lock status callback
532  * @dpll: registered dpll pointer
533  * @dpll_priv: private data pointer passed on dpll registration
534  * @status: on success holds dpll's lock status
535  * @status_error: status error value
536  * @extack: error reporting
537  *
538  * Dpll subsystem callback, provides dpll's lock status.
539  *
540  * Context: Acquires pf->dplls.lock
541  * Return:
542  * * 0 - success
543  * * negative - failure
544  */
545 static int
546 ice_dpll_lock_status_get(const struct dpll_device *dpll, void *dpll_priv,
547 			 enum dpll_lock_status *status,
548 			 enum dpll_lock_status_error *status_error,
549 			 struct netlink_ext_ack *extack)
550 {
551 	struct ice_dpll *d = dpll_priv;
552 	struct ice_pf *pf = d->pf;
553 
554 	mutex_lock(&pf->dplls.lock);
555 	*status = d->dpll_state;
556 	mutex_unlock(&pf->dplls.lock);
557 
558 	return 0;
559 }
560 
561 /**
562  * ice_dpll_mode_get - get dpll's working mode
563  * @dpll: registered dpll pointer
564  * @dpll_priv: private data pointer passed on dpll registration
565  * @mode: on success holds current working mode of dpll
566  * @extack: error reporting
567  *
568  * Dpll subsystem callback. Provides working mode of dpll.
569  *
570  * Context: Acquires pf->dplls.lock
571  * Return:
572  * * 0 - success
573  * * negative - failure
574  */
575 static int ice_dpll_mode_get(const struct dpll_device *dpll, void *dpll_priv,
576 			     enum dpll_mode *mode,
577 			     struct netlink_ext_ack *extack)
578 {
579 	struct ice_dpll *d = dpll_priv;
580 	struct ice_pf *pf = d->pf;
581 
582 	mutex_lock(&pf->dplls.lock);
583 	*mode = d->mode;
584 	mutex_unlock(&pf->dplls.lock);
585 
586 	return 0;
587 }
588 
589 /**
590  * ice_dpll_pin_state_set - set pin's state on dpll
591  * @pin: pointer to a pin
592  * @pin_priv: private data pointer passed on pin registration
593  * @dpll: registered dpll pointer
594  * @dpll_priv: private data pointer passed on dpll registration
595  * @enable: if pin shalll be enabled
596  * @extack: error reporting
597  * @pin_type: type of a pin
598  *
599  * Set pin state on a pin.
600  *
601  * Context: Acquires pf->dplls.lock
602  * Return:
603  * * 0 - OK or no change required
604  * * negative - error
605  */
606 static int
607 ice_dpll_pin_state_set(const struct dpll_pin *pin, void *pin_priv,
608 		       const struct dpll_device *dpll, void *dpll_priv,
609 		       bool enable, struct netlink_ext_ack *extack,
610 		       enum ice_dpll_pin_type pin_type)
611 {
612 	struct ice_dpll_pin *p = pin_priv;
613 	struct ice_dpll *d = dpll_priv;
614 	struct ice_pf *pf = d->pf;
615 	int ret;
616 
617 	if (ice_dpll_is_reset(pf, extack))
618 		return -EBUSY;
619 
620 	mutex_lock(&pf->dplls.lock);
621 	if (enable)
622 		ret = ice_dpll_pin_enable(&pf->hw, p, d->dpll_idx, pin_type,
623 					  extack);
624 	else
625 		ret = ice_dpll_pin_disable(&pf->hw, p, pin_type, extack);
626 	if (!ret)
627 		ret = ice_dpll_pin_state_update(pf, p, pin_type, extack);
628 	mutex_unlock(&pf->dplls.lock);
629 
630 	return ret;
631 }
632 
633 /**
634  * ice_dpll_output_state_set - enable/disable output pin on dpll device
635  * @pin: pointer to a pin
636  * @pin_priv: private data pointer passed on pin registration
637  * @dpll: dpll being configured
638  * @dpll_priv: private data pointer passed on dpll registration
639  * @state: state of pin to be set
640  * @extack: error reporting
641  *
642  * Dpll subsystem callback. Set given state on output type pin.
643  *
644  * Context: Calls a function which acquires pf->dplls.lock
645  * Return:
646  * * 0 - successfully enabled mode
647  * * negative - failed to enable mode
648  */
649 static int
650 ice_dpll_output_state_set(const struct dpll_pin *pin, void *pin_priv,
651 			  const struct dpll_device *dpll, void *dpll_priv,
652 			  enum dpll_pin_state state,
653 			  struct netlink_ext_ack *extack)
654 {
655 	bool enable = state == DPLL_PIN_STATE_CONNECTED;
656 	struct ice_dpll_pin *p = pin_priv;
657 	struct ice_dpll *d = dpll_priv;
658 
659 	if (state == DPLL_PIN_STATE_SELECTABLE)
660 		return -EINVAL;
661 	if (!enable && p->state[d->dpll_idx] == DPLL_PIN_STATE_DISCONNECTED)
662 		return 0;
663 
664 	return ice_dpll_pin_state_set(pin, pin_priv, dpll, dpll_priv, enable,
665 				      extack, ICE_DPLL_PIN_TYPE_OUTPUT);
666 }
667 
668 /**
669  * ice_dpll_input_state_set - enable/disable input pin on dpll levice
670  * @pin: pointer to a pin
671  * @pin_priv: private data pointer passed on pin registration
672  * @dpll: dpll being configured
673  * @dpll_priv: private data pointer passed on dpll registration
674  * @state: state of pin to be set
675  * @extack: error reporting
676  *
677  * Dpll subsystem callback. Enables given mode on input type pin.
678  *
679  * Context: Calls a function which acquires pf->dplls.lock
680  * Return:
681  * * 0 - successfully enabled mode
682  * * negative - failed to enable mode
683  */
684 static int
685 ice_dpll_input_state_set(const struct dpll_pin *pin, void *pin_priv,
686 			 const struct dpll_device *dpll, void *dpll_priv,
687 			 enum dpll_pin_state state,
688 			 struct netlink_ext_ack *extack)
689 {
690 	bool enable = state == DPLL_PIN_STATE_SELECTABLE;
691 
692 	return ice_dpll_pin_state_set(pin, pin_priv, dpll, dpll_priv, enable,
693 				      extack, ICE_DPLL_PIN_TYPE_INPUT);
694 }
695 
696 /**
697  * ice_dpll_pin_state_get - set pin's state on dpll
698  * @pin: pointer to a pin
699  * @pin_priv: private data pointer passed on pin registration
700  * @dpll: registered dpll pointer
701  * @dpll_priv: private data pointer passed on dpll registration
702  * @state: on success holds state of the pin
703  * @extack: error reporting
704  * @pin_type: type of questioned pin
705  *
706  * Determine pin state set it on a pin.
707  *
708  * Context: Acquires pf->dplls.lock
709  * Return:
710  * * 0 - success
711  * * negative - failed to get state
712  */
713 static int
714 ice_dpll_pin_state_get(const struct dpll_pin *pin, void *pin_priv,
715 		       const struct dpll_device *dpll, void *dpll_priv,
716 		       enum dpll_pin_state *state,
717 		       struct netlink_ext_ack *extack,
718 		       enum ice_dpll_pin_type pin_type)
719 {
720 	struct ice_dpll_pin *p = pin_priv;
721 	struct ice_dpll *d = dpll_priv;
722 	struct ice_pf *pf = d->pf;
723 	int ret;
724 
725 	if (ice_dpll_is_reset(pf, extack))
726 		return -EBUSY;
727 
728 	mutex_lock(&pf->dplls.lock);
729 	ret = ice_dpll_pin_state_update(pf, p, pin_type, extack);
730 	if (ret)
731 		goto unlock;
732 	if (pin_type == ICE_DPLL_PIN_TYPE_INPUT ||
733 	    pin_type == ICE_DPLL_PIN_TYPE_OUTPUT)
734 		*state = p->state[d->dpll_idx];
735 	ret = 0;
736 unlock:
737 	mutex_unlock(&pf->dplls.lock);
738 
739 	return ret;
740 }
741 
742 /**
743  * ice_dpll_output_state_get - get output pin state on dpll device
744  * @pin: pointer to a pin
745  * @pin_priv: private data pointer passed on pin registration
746  * @dpll: registered dpll pointer
747  * @dpll_priv: private data pointer passed on dpll registration
748  * @state: on success holds state of the pin
749  * @extack: error reporting
750  *
751  * Dpll subsystem callback. Check state of a pin.
752  *
753  * Context: Calls a function which acquires pf->dplls.lock
754  * Return:
755  * * 0 - success
756  * * negative - failed to get state
757  */
758 static int
759 ice_dpll_output_state_get(const struct dpll_pin *pin, void *pin_priv,
760 			  const struct dpll_device *dpll, void *dpll_priv,
761 			  enum dpll_pin_state *state,
762 			  struct netlink_ext_ack *extack)
763 {
764 	return ice_dpll_pin_state_get(pin, pin_priv, dpll, dpll_priv, state,
765 				      extack, ICE_DPLL_PIN_TYPE_OUTPUT);
766 }
767 
768 /**
769  * ice_dpll_input_state_get - get input pin state on dpll device
770  * @pin: pointer to a pin
771  * @pin_priv: private data pointer passed on pin registration
772  * @dpll: registered dpll pointer
773  * @dpll_priv: private data pointer passed on dpll registration
774  * @state: on success holds state of the pin
775  * @extack: error reporting
776  *
777  * Dpll subsystem callback. Check state of a input pin.
778  *
779  * Context: Calls a function which acquires pf->dplls.lock
780  * Return:
781  * * 0 - success
782  * * negative - failed to get state
783  */
784 static int
785 ice_dpll_input_state_get(const struct dpll_pin *pin, void *pin_priv,
786 			 const struct dpll_device *dpll, void *dpll_priv,
787 			 enum dpll_pin_state *state,
788 			 struct netlink_ext_ack *extack)
789 {
790 	return ice_dpll_pin_state_get(pin, pin_priv, dpll, dpll_priv, state,
791 				      extack, ICE_DPLL_PIN_TYPE_INPUT);
792 }
793 
794 /**
795  * ice_dpll_input_prio_get - get dpll's input prio
796  * @pin: pointer to a pin
797  * @pin_priv: private data pointer passed on pin registration
798  * @dpll: registered dpll pointer
799  * @dpll_priv: private data pointer passed on dpll registration
800  * @prio: on success - returns input priority on dpll
801  * @extack: error reporting
802  *
803  * Dpll subsystem callback. Handler for getting priority of a input pin.
804  *
805  * Context: Acquires pf->dplls.lock
806  * Return:
807  * * 0 - success
808  * * negative - failure
809  */
810 static int
811 ice_dpll_input_prio_get(const struct dpll_pin *pin, void *pin_priv,
812 			const struct dpll_device *dpll, void *dpll_priv,
813 			u32 *prio, struct netlink_ext_ack *extack)
814 {
815 	struct ice_dpll_pin *p = pin_priv;
816 	struct ice_dpll *d = dpll_priv;
817 	struct ice_pf *pf = d->pf;
818 
819 	mutex_lock(&pf->dplls.lock);
820 	*prio = d->input_prio[p->idx];
821 	mutex_unlock(&pf->dplls.lock);
822 
823 	return 0;
824 }
825 
826 /**
827  * ice_dpll_input_prio_set - set dpll input prio
828  * @pin: pointer to a pin
829  * @pin_priv: private data pointer passed on pin registration
830  * @dpll: registered dpll pointer
831  * @dpll_priv: private data pointer passed on dpll registration
832  * @prio: input priority to be set on dpll
833  * @extack: error reporting
834  *
835  * Dpll subsystem callback. Handler for setting priority of a input pin.
836  *
837  * Context: Acquires pf->dplls.lock
838  * Return:
839  * * 0 - success
840  * * negative - failure
841  */
842 static int
843 ice_dpll_input_prio_set(const struct dpll_pin *pin, void *pin_priv,
844 			const struct dpll_device *dpll, void *dpll_priv,
845 			u32 prio, struct netlink_ext_ack *extack)
846 {
847 	struct ice_dpll_pin *p = pin_priv;
848 	struct ice_dpll *d = dpll_priv;
849 	struct ice_pf *pf = d->pf;
850 	int ret;
851 
852 	if (ice_dpll_is_reset(pf, extack))
853 		return -EBUSY;
854 
855 	mutex_lock(&pf->dplls.lock);
856 	ret = ice_dpll_hw_input_prio_set(pf, d, p, prio, extack);
857 	mutex_unlock(&pf->dplls.lock);
858 
859 	return ret;
860 }
861 
862 /**
863  * ice_dpll_input_direction - callback for get input pin direction
864  * @pin: pointer to a pin
865  * @pin_priv: private data pointer passed on pin registration
866  * @dpll: registered dpll pointer
867  * @dpll_priv: private data pointer passed on dpll registration
868  * @direction: holds input pin direction
869  * @extack: error reporting
870  *
871  * Dpll subsystem callback. Handler for getting direction of a input pin.
872  *
873  * Return:
874  * * 0 - success
875  */
876 static int
877 ice_dpll_input_direction(const struct dpll_pin *pin, void *pin_priv,
878 			 const struct dpll_device *dpll, void *dpll_priv,
879 			 enum dpll_pin_direction *direction,
880 			 struct netlink_ext_ack *extack)
881 {
882 	*direction = DPLL_PIN_DIRECTION_INPUT;
883 
884 	return 0;
885 }
886 
887 /**
888  * ice_dpll_output_direction - callback for get output pin direction
889  * @pin: pointer to a pin
890  * @pin_priv: private data pointer passed on pin registration
891  * @dpll: registered dpll pointer
892  * @dpll_priv: private data pointer passed on dpll registration
893  * @direction: holds output pin direction
894  * @extack: error reporting
895  *
896  * Dpll subsystem callback. Handler for getting direction of an output pin.
897  *
898  * Return:
899  * * 0 - success
900  */
901 static int
902 ice_dpll_output_direction(const struct dpll_pin *pin, void *pin_priv,
903 			  const struct dpll_device *dpll, void *dpll_priv,
904 			  enum dpll_pin_direction *direction,
905 			  struct netlink_ext_ack *extack)
906 {
907 	*direction = DPLL_PIN_DIRECTION_OUTPUT;
908 
909 	return 0;
910 }
911 
912 /**
913  * ice_dpll_pin_phase_adjust_get - callback for get pin phase adjust value
914  * @pin: pointer to a pin
915  * @pin_priv: private data pointer passed on pin registration
916  * @dpll: registered dpll pointer
917  * @dpll_priv: private data pointer passed on dpll registration
918  * @phase_adjust: on success holds pin phase_adjust value
919  * @extack: error reporting
920  *
921  * Dpll subsystem callback. Handler for getting phase adjust value of a pin.
922  *
923  * Context: Acquires pf->dplls.lock
924  * Return:
925  * * 0 - success
926  * * negative - error
927  */
928 static int
929 ice_dpll_pin_phase_adjust_get(const struct dpll_pin *pin, void *pin_priv,
930 			      const struct dpll_device *dpll, void *dpll_priv,
931 			      s32 *phase_adjust,
932 			      struct netlink_ext_ack *extack)
933 {
934 	struct ice_dpll_pin *p = pin_priv;
935 	struct ice_pf *pf = p->pf;
936 
937 	mutex_lock(&pf->dplls.lock);
938 	*phase_adjust = p->phase_adjust;
939 	mutex_unlock(&pf->dplls.lock);
940 
941 	return 0;
942 }
943 
944 /**
945  * ice_dpll_pin_phase_adjust_set - helper for setting a pin phase adjust value
946  * @pin: pointer to a pin
947  * @pin_priv: private data pointer passed on pin registration
948  * @dpll: registered dpll pointer
949  * @dpll_priv: private data pointer passed on dpll registration
950  * @phase_adjust: phase_adjust to be set
951  * @extack: error reporting
952  * @type: type of a pin
953  *
954  * Helper for dpll subsystem callback. Handler for setting phase adjust value
955  * of a pin.
956  *
957  * Context: Acquires pf->dplls.lock
958  * Return:
959  * * 0 - success
960  * * negative - error
961  */
962 static int
963 ice_dpll_pin_phase_adjust_set(const struct dpll_pin *pin, void *pin_priv,
964 			      const struct dpll_device *dpll, void *dpll_priv,
965 			      s32 phase_adjust,
966 			      struct netlink_ext_ack *extack,
967 			      enum ice_dpll_pin_type type)
968 {
969 	struct ice_dpll_pin *p = pin_priv;
970 	struct ice_dpll *d = dpll_priv;
971 	struct ice_pf *pf = d->pf;
972 	u8 flag, flags_en = 0;
973 	int ret;
974 
975 	if (ice_dpll_is_reset(pf, extack))
976 		return -EBUSY;
977 
978 	mutex_lock(&pf->dplls.lock);
979 	switch (type) {
980 	case ICE_DPLL_PIN_TYPE_INPUT:
981 		flag = ICE_AQC_SET_CGU_IN_CFG_FLG1_UPDATE_DELAY;
982 		if (p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN)
983 			flags_en |= ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
984 		if (p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN)
985 			flags_en |= ICE_AQC_SET_CGU_IN_CFG_FLG2_INPUT_EN;
986 		ret = ice_aq_set_input_pin_cfg(&pf->hw, p->idx, flag, flags_en,
987 					       0, phase_adjust);
988 		break;
989 	case ICE_DPLL_PIN_TYPE_OUTPUT:
990 		flag = ICE_AQC_SET_CGU_OUT_CFG_UPDATE_PHASE;
991 		if (p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_OUT_EN)
992 			flag |= ICE_AQC_SET_CGU_OUT_CFG_OUT_EN;
993 		if (p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN)
994 			flag |= ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
995 		ret = ice_aq_set_output_pin_cfg(&pf->hw, p->idx, flag, 0, 0,
996 						phase_adjust);
997 		break;
998 	default:
999 		ret = -EINVAL;
1000 	}
1001 	if (!ret)
1002 		p->phase_adjust = phase_adjust;
1003 	mutex_unlock(&pf->dplls.lock);
1004 	if (ret)
1005 		NL_SET_ERR_MSG_FMT(extack,
1006 				   "err:%d %s failed to set pin phase_adjust:%d for pin:%u on dpll:%u\n",
1007 				   ret,
1008 				   ice_aq_str(pf->hw.adminq.sq_last_status),
1009 				   phase_adjust, p->idx, d->dpll_idx);
1010 
1011 	return ret;
1012 }
1013 
1014 /**
1015  * ice_dpll_input_phase_adjust_set - callback for set input pin phase adjust
1016  * @pin: pointer to a pin
1017  * @pin_priv: private data pointer passed on pin registration
1018  * @dpll: registered dpll pointer
1019  * @dpll_priv: private data pointer passed on dpll registration
1020  * @phase_adjust: phase_adjust to be set
1021  * @extack: error reporting
1022  *
1023  * Dpll subsystem callback. Wraps a handler for setting phase adjust on input
1024  * pin.
1025  *
1026  * Context: Calls a function which acquires pf->dplls.lock
1027  * Return:
1028  * * 0 - success
1029  * * negative - error
1030  */
1031 static int
1032 ice_dpll_input_phase_adjust_set(const struct dpll_pin *pin, void *pin_priv,
1033 				const struct dpll_device *dpll, void *dpll_priv,
1034 				s32 phase_adjust,
1035 				struct netlink_ext_ack *extack)
1036 {
1037 	return ice_dpll_pin_phase_adjust_set(pin, pin_priv, dpll, dpll_priv,
1038 					     phase_adjust, extack,
1039 					     ICE_DPLL_PIN_TYPE_INPUT);
1040 }
1041 
1042 /**
1043  * ice_dpll_output_phase_adjust_set - callback for set output pin phase adjust
1044  * @pin: pointer to a pin
1045  * @pin_priv: private data pointer passed on pin registration
1046  * @dpll: registered dpll pointer
1047  * @dpll_priv: private data pointer passed on dpll registration
1048  * @phase_adjust: phase_adjust to be set
1049  * @extack: error reporting
1050  *
1051  * Dpll subsystem callback. Wraps a handler for setting phase adjust on output
1052  * pin.
1053  *
1054  * Context: Calls a function which acquires pf->dplls.lock
1055  * Return:
1056  * * 0 - success
1057  * * negative - error
1058  */
1059 static int
1060 ice_dpll_output_phase_adjust_set(const struct dpll_pin *pin, void *pin_priv,
1061 				 const struct dpll_device *dpll, void *dpll_priv,
1062 				 s32 phase_adjust,
1063 				 struct netlink_ext_ack *extack)
1064 {
1065 	return ice_dpll_pin_phase_adjust_set(pin, pin_priv, dpll, dpll_priv,
1066 					     phase_adjust, extack,
1067 					     ICE_DPLL_PIN_TYPE_OUTPUT);
1068 }
1069 
1070 #define ICE_DPLL_PHASE_OFFSET_DIVIDER	100
1071 #define ICE_DPLL_PHASE_OFFSET_FACTOR		\
1072 	(DPLL_PHASE_OFFSET_DIVIDER / ICE_DPLL_PHASE_OFFSET_DIVIDER)
1073 /**
1074  * ice_dpll_phase_offset_get - callback for get dpll phase shift value
1075  * @pin: pointer to a pin
1076  * @pin_priv: private data pointer passed on pin registration
1077  * @dpll: registered dpll pointer
1078  * @dpll_priv: private data pointer passed on dpll registration
1079  * @phase_offset: on success holds pin phase_offset value
1080  * @extack: error reporting
1081  *
1082  * Dpll subsystem callback. Handler for getting phase shift value between
1083  * dpll's input and output.
1084  *
1085  * Context: Acquires pf->dplls.lock
1086  * Return:
1087  * * 0 - success
1088  * * negative - error
1089  */
1090 static int
1091 ice_dpll_phase_offset_get(const struct dpll_pin *pin, void *pin_priv,
1092 			  const struct dpll_device *dpll, void *dpll_priv,
1093 			  s64 *phase_offset, struct netlink_ext_ack *extack)
1094 {
1095 	struct ice_dpll *d = dpll_priv;
1096 	struct ice_pf *pf = d->pf;
1097 
1098 	mutex_lock(&pf->dplls.lock);
1099 	if (d->active_input == pin)
1100 		*phase_offset = d->phase_offset * ICE_DPLL_PHASE_OFFSET_FACTOR;
1101 	else
1102 		*phase_offset = 0;
1103 	mutex_unlock(&pf->dplls.lock);
1104 
1105 	return 0;
1106 }
1107 
1108 /**
1109  * ice_dpll_output_esync_set - callback for setting embedded sync
1110  * @pin: pointer to a pin
1111  * @pin_priv: private data pointer passed on pin registration
1112  * @dpll: registered dpll pointer
1113  * @dpll_priv: private data pointer passed on dpll registration
1114  * @freq: requested embedded sync frequency
1115  * @extack: error reporting
1116  *
1117  * Dpll subsystem callback. Handler for setting embedded sync frequency value
1118  * on output pin.
1119  *
1120  * Context: Acquires pf->dplls.lock
1121  * Return:
1122  * * 0 - success
1123  * * negative - error
1124  */
1125 static int
1126 ice_dpll_output_esync_set(const struct dpll_pin *pin, void *pin_priv,
1127 			  const struct dpll_device *dpll, void *dpll_priv,
1128 			  u64 freq, struct netlink_ext_ack *extack)
1129 {
1130 	struct ice_dpll_pin *p = pin_priv;
1131 	struct ice_dpll *d = dpll_priv;
1132 	struct ice_pf *pf = d->pf;
1133 	u8 flags = 0;
1134 	int ret;
1135 
1136 	if (ice_dpll_is_reset(pf, extack))
1137 		return -EBUSY;
1138 	mutex_lock(&pf->dplls.lock);
1139 	if (p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_OUT_EN)
1140 		flags = ICE_AQC_SET_CGU_OUT_CFG_OUT_EN;
1141 	if (freq == DPLL_PIN_FREQUENCY_1_HZ) {
1142 		if (p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN) {
1143 			ret = 0;
1144 		} else {
1145 			flags |= ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
1146 			ret = ice_aq_set_output_pin_cfg(&pf->hw, p->idx, flags,
1147 							0, 0, 0);
1148 		}
1149 	} else {
1150 		if (!(p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN)) {
1151 			ret = 0;
1152 		} else {
1153 			flags &= ~ICE_AQC_SET_CGU_OUT_CFG_ESYNC_EN;
1154 			ret = ice_aq_set_output_pin_cfg(&pf->hw, p->idx, flags,
1155 							0, 0, 0);
1156 		}
1157 	}
1158 	mutex_unlock(&pf->dplls.lock);
1159 
1160 	return ret;
1161 }
1162 
1163 /**
1164  * ice_dpll_output_esync_get - callback for getting embedded sync config
1165  * @pin: pointer to a pin
1166  * @pin_priv: private data pointer passed on pin registration
1167  * @dpll: registered dpll pointer
1168  * @dpll_priv: private data pointer passed on dpll registration
1169  * @esync: on success holds embedded sync pin properties
1170  * @extack: error reporting
1171  *
1172  * Dpll subsystem callback. Handler for getting embedded sync frequency value
1173  * and capabilities on output pin.
1174  *
1175  * Context: Acquires pf->dplls.lock
1176  * Return:
1177  * * 0 - success
1178  * * negative - error
1179  */
1180 static int
1181 ice_dpll_output_esync_get(const struct dpll_pin *pin, void *pin_priv,
1182 			  const struct dpll_device *dpll, void *dpll_priv,
1183 			  struct dpll_pin_esync *esync,
1184 			  struct netlink_ext_ack *extack)
1185 {
1186 	struct ice_dpll_pin *p = pin_priv;
1187 	struct ice_dpll *d = dpll_priv;
1188 	struct ice_pf *pf = d->pf;
1189 
1190 	if (ice_dpll_is_reset(pf, extack))
1191 		return -EBUSY;
1192 	mutex_lock(&pf->dplls.lock);
1193 	if (!(p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_ABILITY) ||
1194 	    p->freq != DPLL_PIN_FREQUENCY_10_MHZ) {
1195 		mutex_unlock(&pf->dplls.lock);
1196 		return -EOPNOTSUPP;
1197 	}
1198 	esync->range = ice_esync_range;
1199 	esync->range_num = ARRAY_SIZE(ice_esync_range);
1200 	if (p->flags[0] & ICE_AQC_GET_CGU_OUT_CFG_ESYNC_EN) {
1201 		esync->freq = DPLL_PIN_FREQUENCY_1_HZ;
1202 		esync->pulse = ICE_DPLL_PIN_ESYNC_PULSE_HIGH_PERCENT;
1203 	} else {
1204 		esync->freq = 0;
1205 		esync->pulse = 0;
1206 	}
1207 	mutex_unlock(&pf->dplls.lock);
1208 
1209 	return 0;
1210 }
1211 
1212 /**
1213  * ice_dpll_input_esync_set - callback for setting embedded sync
1214  * @pin: pointer to a pin
1215  * @pin_priv: private data pointer passed on pin registration
1216  * @dpll: registered dpll pointer
1217  * @dpll_priv: private data pointer passed on dpll registration
1218  * @freq: requested embedded sync frequency
1219  * @extack: error reporting
1220  *
1221  * Dpll subsystem callback. Handler for setting embedded sync frequency value
1222  * on input pin.
1223  *
1224  * Context: Acquires pf->dplls.lock
1225  * Return:
1226  * * 0 - success
1227  * * negative - error
1228  */
1229 static int
1230 ice_dpll_input_esync_set(const struct dpll_pin *pin, void *pin_priv,
1231 			 const struct dpll_device *dpll, void *dpll_priv,
1232 			 u64 freq, struct netlink_ext_ack *extack)
1233 {
1234 	struct ice_dpll_pin *p = pin_priv;
1235 	struct ice_dpll *d = dpll_priv;
1236 	struct ice_pf *pf = d->pf;
1237 	u8 flags_en = 0;
1238 	int ret;
1239 
1240 	if (ice_dpll_is_reset(pf, extack))
1241 		return -EBUSY;
1242 	mutex_lock(&pf->dplls.lock);
1243 	if (p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN)
1244 		flags_en = ICE_AQC_SET_CGU_IN_CFG_FLG2_INPUT_EN;
1245 	if (freq == DPLL_PIN_FREQUENCY_1_HZ) {
1246 		if (p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN) {
1247 			ret = 0;
1248 		} else {
1249 			flags_en |= ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
1250 			ret = ice_aq_set_input_pin_cfg(&pf->hw, p->idx, 0,
1251 						       flags_en, 0, 0);
1252 		}
1253 	} else {
1254 		if (!(p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN)) {
1255 			ret = 0;
1256 		} else {
1257 			flags_en &= ~ICE_AQC_SET_CGU_IN_CFG_FLG2_ESYNC_EN;
1258 			ret = ice_aq_set_input_pin_cfg(&pf->hw, p->idx, 0,
1259 						       flags_en, 0, 0);
1260 		}
1261 	}
1262 	mutex_unlock(&pf->dplls.lock);
1263 
1264 	return ret;
1265 }
1266 
1267 /**
1268  * ice_dpll_input_esync_get - callback for getting embedded sync config
1269  * @pin: pointer to a pin
1270  * @pin_priv: private data pointer passed on pin registration
1271  * @dpll: registered dpll pointer
1272  * @dpll_priv: private data pointer passed on dpll registration
1273  * @esync: on success holds embedded sync pin properties
1274  * @extack: error reporting
1275  *
1276  * Dpll subsystem callback. Handler for getting embedded sync frequency value
1277  * and capabilities on input pin.
1278  *
1279  * Context: Acquires pf->dplls.lock
1280  * Return:
1281  * * 0 - success
1282  * * negative - error
1283  */
1284 static int
1285 ice_dpll_input_esync_get(const struct dpll_pin *pin, void *pin_priv,
1286 			 const struct dpll_device *dpll, void *dpll_priv,
1287 			 struct dpll_pin_esync *esync,
1288 			 struct netlink_ext_ack *extack)
1289 {
1290 	struct ice_dpll_pin *p = pin_priv;
1291 	struct ice_dpll *d = dpll_priv;
1292 	struct ice_pf *pf = d->pf;
1293 
1294 	if (ice_dpll_is_reset(pf, extack))
1295 		return -EBUSY;
1296 	mutex_lock(&pf->dplls.lock);
1297 	if (!(p->status & ICE_AQC_GET_CGU_IN_CFG_STATUS_ESYNC_CAP) ||
1298 	    p->freq != DPLL_PIN_FREQUENCY_10_MHZ) {
1299 		mutex_unlock(&pf->dplls.lock);
1300 		return -EOPNOTSUPP;
1301 	}
1302 	esync->range = ice_esync_range;
1303 	esync->range_num = ARRAY_SIZE(ice_esync_range);
1304 	if (p->flags[0] & ICE_AQC_GET_CGU_IN_CFG_FLG2_ESYNC_EN) {
1305 		esync->freq = DPLL_PIN_FREQUENCY_1_HZ;
1306 		esync->pulse = ICE_DPLL_PIN_ESYNC_PULSE_HIGH_PERCENT;
1307 	} else {
1308 		esync->freq = 0;
1309 		esync->pulse = 0;
1310 	}
1311 	mutex_unlock(&pf->dplls.lock);
1312 
1313 	return 0;
1314 }
1315 
1316 /**
1317  * ice_dpll_rclk_state_on_pin_set - set a state on rclk pin
1318  * @pin: pointer to a pin
1319  * @pin_priv: private data pointer passed on pin registration
1320  * @parent_pin: pin parent pointer
1321  * @parent_pin_priv: parent private data pointer passed on pin registration
1322  * @state: state to be set on pin
1323  * @extack: error reporting
1324  *
1325  * Dpll subsystem callback, set a state of a rclk pin on a parent pin
1326  *
1327  * Context: Acquires pf->dplls.lock
1328  * Return:
1329  * * 0 - success
1330  * * negative - failure
1331  */
1332 static int
1333 ice_dpll_rclk_state_on_pin_set(const struct dpll_pin *pin, void *pin_priv,
1334 			       const struct dpll_pin *parent_pin,
1335 			       void *parent_pin_priv,
1336 			       enum dpll_pin_state state,
1337 			       struct netlink_ext_ack *extack)
1338 {
1339 	struct ice_dpll_pin *p = pin_priv, *parent = parent_pin_priv;
1340 	bool enable = state == DPLL_PIN_STATE_CONNECTED;
1341 	struct ice_pf *pf = p->pf;
1342 	int ret = -EINVAL;
1343 	u32 hw_idx;
1344 
1345 	if (ice_dpll_is_reset(pf, extack))
1346 		return -EBUSY;
1347 
1348 	mutex_lock(&pf->dplls.lock);
1349 	hw_idx = parent->idx - pf->dplls.base_rclk_idx;
1350 	if (hw_idx >= pf->dplls.num_inputs)
1351 		goto unlock;
1352 
1353 	if ((enable && p->state[hw_idx] == DPLL_PIN_STATE_CONNECTED) ||
1354 	    (!enable && p->state[hw_idx] == DPLL_PIN_STATE_DISCONNECTED)) {
1355 		NL_SET_ERR_MSG_FMT(extack,
1356 				   "pin:%u state:%u on parent:%u already set",
1357 				   p->idx, state, parent->idx);
1358 		goto unlock;
1359 	}
1360 	ret = ice_aq_set_phy_rec_clk_out(&pf->hw, hw_idx, enable,
1361 					 &p->freq);
1362 	if (ret)
1363 		NL_SET_ERR_MSG_FMT(extack,
1364 				   "err:%d %s failed to set pin state:%u for pin:%u on parent:%u\n",
1365 				   ret,
1366 				   ice_aq_str(pf->hw.adminq.sq_last_status),
1367 				   state, p->idx, parent->idx);
1368 unlock:
1369 	mutex_unlock(&pf->dplls.lock);
1370 
1371 	return ret;
1372 }
1373 
1374 /**
1375  * ice_dpll_rclk_state_on_pin_get - get a state of rclk pin
1376  * @pin: pointer to a pin
1377  * @pin_priv: private data pointer passed on pin registration
1378  * @parent_pin: pin parent pointer
1379  * @parent_pin_priv: pin parent priv data pointer passed on pin registration
1380  * @state: on success holds pin state on parent pin
1381  * @extack: error reporting
1382  *
1383  * dpll subsystem callback, get a state of a recovered clock pin.
1384  *
1385  * Context: Acquires pf->dplls.lock
1386  * Return:
1387  * * 0 - success
1388  * * negative - failure
1389  */
1390 static int
1391 ice_dpll_rclk_state_on_pin_get(const struct dpll_pin *pin, void *pin_priv,
1392 			       const struct dpll_pin *parent_pin,
1393 			       void *parent_pin_priv,
1394 			       enum dpll_pin_state *state,
1395 			       struct netlink_ext_ack *extack)
1396 {
1397 	struct ice_dpll_pin *p = pin_priv, *parent = parent_pin_priv;
1398 	struct ice_pf *pf = p->pf;
1399 	int ret = -EINVAL;
1400 	u32 hw_idx;
1401 
1402 	if (ice_dpll_is_reset(pf, extack))
1403 		return -EBUSY;
1404 
1405 	mutex_lock(&pf->dplls.lock);
1406 	hw_idx = parent->idx - pf->dplls.base_rclk_idx;
1407 	if (hw_idx >= pf->dplls.num_inputs)
1408 		goto unlock;
1409 
1410 	ret = ice_dpll_pin_state_update(pf, p, ICE_DPLL_PIN_TYPE_RCLK_INPUT,
1411 					extack);
1412 	if (ret)
1413 		goto unlock;
1414 
1415 	*state = p->state[hw_idx];
1416 	ret = 0;
1417 unlock:
1418 	mutex_unlock(&pf->dplls.lock);
1419 
1420 	return ret;
1421 }
1422 
1423 static const struct dpll_pin_ops ice_dpll_rclk_ops = {
1424 	.state_on_pin_set = ice_dpll_rclk_state_on_pin_set,
1425 	.state_on_pin_get = ice_dpll_rclk_state_on_pin_get,
1426 	.direction_get = ice_dpll_input_direction,
1427 };
1428 
1429 static const struct dpll_pin_ops ice_dpll_input_ops = {
1430 	.frequency_get = ice_dpll_input_frequency_get,
1431 	.frequency_set = ice_dpll_input_frequency_set,
1432 	.state_on_dpll_get = ice_dpll_input_state_get,
1433 	.state_on_dpll_set = ice_dpll_input_state_set,
1434 	.prio_get = ice_dpll_input_prio_get,
1435 	.prio_set = ice_dpll_input_prio_set,
1436 	.direction_get = ice_dpll_input_direction,
1437 	.phase_adjust_get = ice_dpll_pin_phase_adjust_get,
1438 	.phase_adjust_set = ice_dpll_input_phase_adjust_set,
1439 	.phase_offset_get = ice_dpll_phase_offset_get,
1440 	.esync_set = ice_dpll_input_esync_set,
1441 	.esync_get = ice_dpll_input_esync_get,
1442 };
1443 
1444 static const struct dpll_pin_ops ice_dpll_output_ops = {
1445 	.frequency_get = ice_dpll_output_frequency_get,
1446 	.frequency_set = ice_dpll_output_frequency_set,
1447 	.state_on_dpll_get = ice_dpll_output_state_get,
1448 	.state_on_dpll_set = ice_dpll_output_state_set,
1449 	.direction_get = ice_dpll_output_direction,
1450 	.phase_adjust_get = ice_dpll_pin_phase_adjust_get,
1451 	.phase_adjust_set = ice_dpll_output_phase_adjust_set,
1452 	.esync_set = ice_dpll_output_esync_set,
1453 	.esync_get = ice_dpll_output_esync_get,
1454 };
1455 
1456 static const struct dpll_device_ops ice_dpll_ops = {
1457 	.lock_status_get = ice_dpll_lock_status_get,
1458 	.mode_get = ice_dpll_mode_get,
1459 };
1460 
1461 /**
1462  * ice_generate_clock_id - generates unique clock_id for registering dpll.
1463  * @pf: board private structure
1464  *
1465  * Generates unique (per board) clock_id for allocation and search of dpll
1466  * devices in Linux dpll subsystem.
1467  *
1468  * Return: generated clock id for the board
1469  */
1470 static u64 ice_generate_clock_id(struct ice_pf *pf)
1471 {
1472 	return pci_get_dsn(pf->pdev);
1473 }
1474 
1475 /**
1476  * ice_dpll_notify_changes - notify dpll subsystem about changes
1477  * @d: pointer do dpll
1478  *
1479  * Once change detected appropriate event is submitted to the dpll subsystem.
1480  */
1481 static void ice_dpll_notify_changes(struct ice_dpll *d)
1482 {
1483 	bool pin_notified = false;
1484 
1485 	if (d->prev_dpll_state != d->dpll_state) {
1486 		d->prev_dpll_state = d->dpll_state;
1487 		dpll_device_change_ntf(d->dpll);
1488 	}
1489 	if (d->prev_input != d->active_input) {
1490 		if (d->prev_input)
1491 			dpll_pin_change_ntf(d->prev_input);
1492 		d->prev_input = d->active_input;
1493 		if (d->active_input) {
1494 			dpll_pin_change_ntf(d->active_input);
1495 			pin_notified = true;
1496 		}
1497 	}
1498 	if (d->prev_phase_offset != d->phase_offset) {
1499 		d->prev_phase_offset = d->phase_offset;
1500 		if (!pin_notified && d->active_input)
1501 			dpll_pin_change_ntf(d->active_input);
1502 	}
1503 }
1504 
1505 /**
1506  * ice_dpll_update_state - update dpll state
1507  * @pf: pf private structure
1508  * @d: pointer to queried dpll device
1509  * @init: if function called on initialization of ice dpll
1510  *
1511  * Poll current state of dpll from hw and update ice_dpll struct.
1512  *
1513  * Context: Called by kworker under pf->dplls.lock
1514  * Return:
1515  * * 0 - success
1516  * * negative - AQ failure
1517  */
1518 static int
1519 ice_dpll_update_state(struct ice_pf *pf, struct ice_dpll *d, bool init)
1520 {
1521 	struct ice_dpll_pin *p = NULL;
1522 	int ret;
1523 
1524 	ret = ice_get_cgu_state(&pf->hw, d->dpll_idx, d->prev_dpll_state,
1525 				&d->input_idx, &d->ref_state, &d->eec_mode,
1526 				&d->phase_offset, &d->dpll_state);
1527 
1528 	dev_dbg(ice_pf_to_dev(pf),
1529 		"update dpll=%d, prev_src_idx:%u, src_idx:%u, state:%d, prev:%d mode:%d\n",
1530 		d->dpll_idx, d->prev_input_idx, d->input_idx,
1531 		d->dpll_state, d->prev_dpll_state, d->mode);
1532 	if (ret) {
1533 		dev_err(ice_pf_to_dev(pf),
1534 			"update dpll=%d state failed, ret=%d %s\n",
1535 			d->dpll_idx, ret,
1536 			ice_aq_str(pf->hw.adminq.sq_last_status));
1537 		return ret;
1538 	}
1539 	if (init) {
1540 		if (d->dpll_state == DPLL_LOCK_STATUS_LOCKED ||
1541 		    d->dpll_state == DPLL_LOCK_STATUS_LOCKED_HO_ACQ)
1542 			d->active_input = pf->dplls.inputs[d->input_idx].pin;
1543 		p = &pf->dplls.inputs[d->input_idx];
1544 		return ice_dpll_pin_state_update(pf, p,
1545 						 ICE_DPLL_PIN_TYPE_INPUT, NULL);
1546 	}
1547 	if (d->dpll_state == DPLL_LOCK_STATUS_HOLDOVER ||
1548 	    d->dpll_state == DPLL_LOCK_STATUS_UNLOCKED) {
1549 		d->active_input = NULL;
1550 		if (d->input_idx != ICE_DPLL_PIN_IDX_INVALID)
1551 			p = &pf->dplls.inputs[d->input_idx];
1552 		d->prev_input_idx = ICE_DPLL_PIN_IDX_INVALID;
1553 		d->input_idx = ICE_DPLL_PIN_IDX_INVALID;
1554 		if (!p)
1555 			return 0;
1556 		ret = ice_dpll_pin_state_update(pf, p,
1557 						ICE_DPLL_PIN_TYPE_INPUT, NULL);
1558 	} else if (d->input_idx != d->prev_input_idx) {
1559 		if (d->prev_input_idx != ICE_DPLL_PIN_IDX_INVALID) {
1560 			p = &pf->dplls.inputs[d->prev_input_idx];
1561 			ice_dpll_pin_state_update(pf, p,
1562 						  ICE_DPLL_PIN_TYPE_INPUT,
1563 						  NULL);
1564 		}
1565 		if (d->input_idx != ICE_DPLL_PIN_IDX_INVALID) {
1566 			p = &pf->dplls.inputs[d->input_idx];
1567 			d->active_input = p->pin;
1568 			ice_dpll_pin_state_update(pf, p,
1569 						  ICE_DPLL_PIN_TYPE_INPUT,
1570 						  NULL);
1571 		}
1572 		d->prev_input_idx = d->input_idx;
1573 	}
1574 
1575 	return ret;
1576 }
1577 
1578 /**
1579  * ice_dpll_periodic_work - DPLLs periodic worker
1580  * @work: pointer to kthread_work structure
1581  *
1582  * DPLLs periodic worker is responsible for polling state of dpll.
1583  * Context: Holds pf->dplls.lock
1584  */
1585 static void ice_dpll_periodic_work(struct kthread_work *work)
1586 {
1587 	struct ice_dplls *d = container_of(work, struct ice_dplls, work.work);
1588 	struct ice_pf *pf = container_of(d, struct ice_pf, dplls);
1589 	struct ice_dpll *de = &pf->dplls.eec;
1590 	struct ice_dpll *dp = &pf->dplls.pps;
1591 	int ret = 0;
1592 
1593 	if (ice_is_reset_in_progress(pf->state))
1594 		goto resched;
1595 	mutex_lock(&pf->dplls.lock);
1596 	ret = ice_dpll_update_state(pf, de, false);
1597 	if (!ret)
1598 		ret = ice_dpll_update_state(pf, dp, false);
1599 	if (ret) {
1600 		d->cgu_state_acq_err_num++;
1601 		/* stop rescheduling this worker */
1602 		if (d->cgu_state_acq_err_num >
1603 		    ICE_CGU_STATE_ACQ_ERR_THRESHOLD) {
1604 			dev_err(ice_pf_to_dev(pf),
1605 				"EEC/PPS DPLLs periodic work disabled\n");
1606 			mutex_unlock(&pf->dplls.lock);
1607 			return;
1608 		}
1609 	}
1610 	mutex_unlock(&pf->dplls.lock);
1611 	ice_dpll_notify_changes(de);
1612 	ice_dpll_notify_changes(dp);
1613 
1614 resched:
1615 	/* Run twice a second or reschedule if update failed */
1616 	kthread_queue_delayed_work(d->kworker, &d->work,
1617 				   ret ? msecs_to_jiffies(10) :
1618 				   msecs_to_jiffies(500));
1619 }
1620 
1621 /**
1622  * ice_dpll_release_pins - release pins resources from dpll subsystem
1623  * @pins: pointer to pins array
1624  * @count: number of pins
1625  *
1626  * Release resources of given pins array in the dpll subsystem.
1627  */
1628 static void ice_dpll_release_pins(struct ice_dpll_pin *pins, int count)
1629 {
1630 	int i;
1631 
1632 	for (i = 0; i < count; i++)
1633 		dpll_pin_put(pins[i].pin);
1634 }
1635 
1636 /**
1637  * ice_dpll_get_pins - get pins from dpll subsystem
1638  * @pf: board private structure
1639  * @pins: pointer to pins array
1640  * @start_idx: get starts from this pin idx value
1641  * @count: number of pins
1642  * @clock_id: clock_id of dpll device
1643  *
1644  * Get pins - allocate - in dpll subsystem, store them in pin field of given
1645  * pins array.
1646  *
1647  * Return:
1648  * * 0 - success
1649  * * negative - allocation failure reason
1650  */
1651 static int
1652 ice_dpll_get_pins(struct ice_pf *pf, struct ice_dpll_pin *pins,
1653 		  int start_idx, int count, u64 clock_id)
1654 {
1655 	int i, ret;
1656 
1657 	for (i = 0; i < count; i++) {
1658 		pins[i].pin = dpll_pin_get(clock_id, i + start_idx, THIS_MODULE,
1659 					   &pins[i].prop);
1660 		if (IS_ERR(pins[i].pin)) {
1661 			ret = PTR_ERR(pins[i].pin);
1662 			goto release_pins;
1663 		}
1664 	}
1665 
1666 	return 0;
1667 
1668 release_pins:
1669 	while (--i >= 0)
1670 		dpll_pin_put(pins[i].pin);
1671 	return ret;
1672 }
1673 
1674 /**
1675  * ice_dpll_unregister_pins - unregister pins from a dpll
1676  * @dpll: dpll device pointer
1677  * @pins: pointer to pins array
1678  * @ops: callback ops registered with the pins
1679  * @count: number of pins
1680  *
1681  * Unregister pins of a given array of pins from given dpll device registered in
1682  * dpll subsystem.
1683  */
1684 static void
1685 ice_dpll_unregister_pins(struct dpll_device *dpll, struct ice_dpll_pin *pins,
1686 			 const struct dpll_pin_ops *ops, int count)
1687 {
1688 	int i;
1689 
1690 	for (i = 0; i < count; i++)
1691 		dpll_pin_unregister(dpll, pins[i].pin, ops, &pins[i]);
1692 }
1693 
1694 /**
1695  * ice_dpll_register_pins - register pins with a dpll
1696  * @dpll: dpll pointer to register pins with
1697  * @pins: pointer to pins array
1698  * @ops: callback ops registered with the pins
1699  * @count: number of pins
1700  *
1701  * Register pins of a given array with given dpll in dpll subsystem.
1702  *
1703  * Return:
1704  * * 0 - success
1705  * * negative - registration failure reason
1706  */
1707 static int
1708 ice_dpll_register_pins(struct dpll_device *dpll, struct ice_dpll_pin *pins,
1709 		       const struct dpll_pin_ops *ops, int count)
1710 {
1711 	int ret, i;
1712 
1713 	for (i = 0; i < count; i++) {
1714 		ret = dpll_pin_register(dpll, pins[i].pin, ops, &pins[i]);
1715 		if (ret)
1716 			goto unregister_pins;
1717 	}
1718 
1719 	return 0;
1720 
1721 unregister_pins:
1722 	while (--i >= 0)
1723 		dpll_pin_unregister(dpll, pins[i].pin, ops, &pins[i]);
1724 	return ret;
1725 }
1726 
1727 /**
1728  * ice_dpll_deinit_direct_pins - deinitialize direct pins
1729  * @cgu: if cgu is present and controlled by this NIC
1730  * @pins: pointer to pins array
1731  * @count: number of pins
1732  * @ops: callback ops registered with the pins
1733  * @first: dpll device pointer
1734  * @second: dpll device pointer
1735  *
1736  * If cgu is owned unregister pins from given dplls.
1737  * Release pins resources to the dpll subsystem.
1738  */
1739 static void
1740 ice_dpll_deinit_direct_pins(bool cgu, struct ice_dpll_pin *pins, int count,
1741 			    const struct dpll_pin_ops *ops,
1742 			    struct dpll_device *first,
1743 			    struct dpll_device *second)
1744 {
1745 	if (cgu) {
1746 		ice_dpll_unregister_pins(first, pins, ops, count);
1747 		ice_dpll_unregister_pins(second, pins, ops, count);
1748 	}
1749 	ice_dpll_release_pins(pins, count);
1750 }
1751 
1752 /**
1753  * ice_dpll_init_direct_pins - initialize direct pins
1754  * @pf: board private structure
1755  * @cgu: if cgu is present and controlled by this NIC
1756  * @pins: pointer to pins array
1757  * @start_idx: on which index shall allocation start in dpll subsystem
1758  * @count: number of pins
1759  * @ops: callback ops registered with the pins
1760  * @first: dpll device pointer
1761  * @second: dpll device pointer
1762  *
1763  * Allocate directly connected pins of a given array in dpll subsystem.
1764  * If cgu is owned register allocated pins with given dplls.
1765  *
1766  * Return:
1767  * * 0 - success
1768  * * negative - registration failure reason
1769  */
1770 static int
1771 ice_dpll_init_direct_pins(struct ice_pf *pf, bool cgu,
1772 			  struct ice_dpll_pin *pins, int start_idx, int count,
1773 			  const struct dpll_pin_ops *ops,
1774 			  struct dpll_device *first, struct dpll_device *second)
1775 {
1776 	int ret;
1777 
1778 	ret = ice_dpll_get_pins(pf, pins, start_idx, count, pf->dplls.clock_id);
1779 	if (ret)
1780 		return ret;
1781 	if (cgu) {
1782 		ret = ice_dpll_register_pins(first, pins, ops, count);
1783 		if (ret)
1784 			goto release_pins;
1785 		ret = ice_dpll_register_pins(second, pins, ops, count);
1786 		if (ret)
1787 			goto unregister_first;
1788 	}
1789 
1790 	return 0;
1791 
1792 unregister_first:
1793 	ice_dpll_unregister_pins(first, pins, ops, count);
1794 release_pins:
1795 	ice_dpll_release_pins(pins, count);
1796 	return ret;
1797 }
1798 
1799 /**
1800  * ice_dpll_deinit_rclk_pin - release rclk pin resources
1801  * @pf: board private structure
1802  *
1803  * Deregister rclk pin from parent pins and release resources in dpll subsystem.
1804  */
1805 static void ice_dpll_deinit_rclk_pin(struct ice_pf *pf)
1806 {
1807 	struct ice_dpll_pin *rclk = &pf->dplls.rclk;
1808 	struct ice_vsi *vsi = ice_get_main_vsi(pf);
1809 	struct dpll_pin *parent;
1810 	int i;
1811 
1812 	for (i = 0; i < rclk->num_parents; i++) {
1813 		parent = pf->dplls.inputs[rclk->parent_idx[i]].pin;
1814 		if (!parent)
1815 			continue;
1816 		dpll_pin_on_pin_unregister(parent, rclk->pin,
1817 					   &ice_dpll_rclk_ops, rclk);
1818 	}
1819 	if (WARN_ON_ONCE(!vsi || !vsi->netdev))
1820 		return;
1821 	dpll_netdev_pin_clear(vsi->netdev);
1822 	dpll_pin_put(rclk->pin);
1823 }
1824 
1825 /**
1826  * ice_dpll_init_rclk_pins - initialize recovered clock pin
1827  * @pf: board private structure
1828  * @pin: pin to register
1829  * @start_idx: on which index shall allocation start in dpll subsystem
1830  * @ops: callback ops registered with the pins
1831  *
1832  * Allocate resource for recovered clock pin in dpll subsystem. Register the
1833  * pin with the parents it has in the info. Register pin with the pf's main vsi
1834  * netdev.
1835  *
1836  * Return:
1837  * * 0 - success
1838  * * negative - registration failure reason
1839  */
1840 static int
1841 ice_dpll_init_rclk_pins(struct ice_pf *pf, struct ice_dpll_pin *pin,
1842 			int start_idx, const struct dpll_pin_ops *ops)
1843 {
1844 	struct ice_vsi *vsi = ice_get_main_vsi(pf);
1845 	struct dpll_pin *parent;
1846 	int ret, i;
1847 
1848 	if (WARN_ON((!vsi || !vsi->netdev)))
1849 		return -EINVAL;
1850 	ret = ice_dpll_get_pins(pf, pin, start_idx, ICE_DPLL_RCLK_NUM_PER_PF,
1851 				pf->dplls.clock_id);
1852 	if (ret)
1853 		return ret;
1854 	for (i = 0; i < pf->dplls.rclk.num_parents; i++) {
1855 		parent = pf->dplls.inputs[pf->dplls.rclk.parent_idx[i]].pin;
1856 		if (!parent) {
1857 			ret = -ENODEV;
1858 			goto unregister_pins;
1859 		}
1860 		ret = dpll_pin_on_pin_register(parent, pf->dplls.rclk.pin,
1861 					       ops, &pf->dplls.rclk);
1862 		if (ret)
1863 			goto unregister_pins;
1864 	}
1865 	dpll_netdev_pin_set(vsi->netdev, pf->dplls.rclk.pin);
1866 
1867 	return 0;
1868 
1869 unregister_pins:
1870 	while (i) {
1871 		parent = pf->dplls.inputs[pf->dplls.rclk.parent_idx[--i]].pin;
1872 		dpll_pin_on_pin_unregister(parent, pf->dplls.rclk.pin,
1873 					   &ice_dpll_rclk_ops, &pf->dplls.rclk);
1874 	}
1875 	ice_dpll_release_pins(pin, ICE_DPLL_RCLK_NUM_PER_PF);
1876 	return ret;
1877 }
1878 
1879 /**
1880  * ice_dpll_deinit_pins - deinitialize direct pins
1881  * @pf: board private structure
1882  * @cgu: if cgu is controlled by this pf
1883  *
1884  * If cgu is owned unregister directly connected pins from the dplls.
1885  * Release resources of directly connected pins from the dpll subsystem.
1886  */
1887 static void ice_dpll_deinit_pins(struct ice_pf *pf, bool cgu)
1888 {
1889 	struct ice_dpll_pin *outputs = pf->dplls.outputs;
1890 	struct ice_dpll_pin *inputs = pf->dplls.inputs;
1891 	int num_outputs = pf->dplls.num_outputs;
1892 	int num_inputs = pf->dplls.num_inputs;
1893 	struct ice_dplls *d = &pf->dplls;
1894 	struct ice_dpll *de = &d->eec;
1895 	struct ice_dpll *dp = &d->pps;
1896 
1897 	ice_dpll_deinit_rclk_pin(pf);
1898 	if (cgu) {
1899 		ice_dpll_unregister_pins(dp->dpll, inputs, &ice_dpll_input_ops,
1900 					 num_inputs);
1901 		ice_dpll_unregister_pins(de->dpll, inputs, &ice_dpll_input_ops,
1902 					 num_inputs);
1903 	}
1904 	ice_dpll_release_pins(inputs, num_inputs);
1905 	if (cgu) {
1906 		ice_dpll_unregister_pins(dp->dpll, outputs,
1907 					 &ice_dpll_output_ops, num_outputs);
1908 		ice_dpll_unregister_pins(de->dpll, outputs,
1909 					 &ice_dpll_output_ops, num_outputs);
1910 		ice_dpll_release_pins(outputs, num_outputs);
1911 	}
1912 }
1913 
1914 /**
1915  * ice_dpll_init_pins - init pins and register pins with a dplls
1916  * @pf: board private structure
1917  * @cgu: if cgu is present and controlled by this NIC
1918  *
1919  * Initialize directly connected pf's pins within pf's dplls in a Linux dpll
1920  * subsystem.
1921  *
1922  * Return:
1923  * * 0 - success
1924  * * negative - initialization failure reason
1925  */
1926 static int ice_dpll_init_pins(struct ice_pf *pf, bool cgu)
1927 {
1928 	u32 rclk_idx;
1929 	int ret;
1930 
1931 	ret = ice_dpll_init_direct_pins(pf, cgu, pf->dplls.inputs, 0,
1932 					pf->dplls.num_inputs,
1933 					&ice_dpll_input_ops,
1934 					pf->dplls.eec.dpll, pf->dplls.pps.dpll);
1935 	if (ret)
1936 		return ret;
1937 	if (cgu) {
1938 		ret = ice_dpll_init_direct_pins(pf, cgu, pf->dplls.outputs,
1939 						pf->dplls.num_inputs,
1940 						pf->dplls.num_outputs,
1941 						&ice_dpll_output_ops,
1942 						pf->dplls.eec.dpll,
1943 						pf->dplls.pps.dpll);
1944 		if (ret)
1945 			goto deinit_inputs;
1946 	}
1947 	rclk_idx = pf->dplls.num_inputs + pf->dplls.num_outputs + pf->hw.pf_id;
1948 	ret = ice_dpll_init_rclk_pins(pf, &pf->dplls.rclk, rclk_idx,
1949 				      &ice_dpll_rclk_ops);
1950 	if (ret)
1951 		goto deinit_outputs;
1952 
1953 	return 0;
1954 deinit_outputs:
1955 	ice_dpll_deinit_direct_pins(cgu, pf->dplls.outputs,
1956 				    pf->dplls.num_outputs,
1957 				    &ice_dpll_output_ops, pf->dplls.pps.dpll,
1958 				    pf->dplls.eec.dpll);
1959 deinit_inputs:
1960 	ice_dpll_deinit_direct_pins(cgu, pf->dplls.inputs, pf->dplls.num_inputs,
1961 				    &ice_dpll_input_ops, pf->dplls.pps.dpll,
1962 				    pf->dplls.eec.dpll);
1963 	return ret;
1964 }
1965 
1966 /**
1967  * ice_dpll_deinit_dpll - deinitialize dpll device
1968  * @pf: board private structure
1969  * @d: pointer to ice_dpll
1970  * @cgu: if cgu is present and controlled by this NIC
1971  *
1972  * If cgu is owned unregister the dpll from dpll subsystem.
1973  * Release resources of dpll device from dpll subsystem.
1974  */
1975 static void
1976 ice_dpll_deinit_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu)
1977 {
1978 	if (cgu)
1979 		dpll_device_unregister(d->dpll, &ice_dpll_ops, d);
1980 	dpll_device_put(d->dpll);
1981 }
1982 
1983 /**
1984  * ice_dpll_init_dpll - initialize dpll device in dpll subsystem
1985  * @pf: board private structure
1986  * @d: dpll to be initialized
1987  * @cgu: if cgu is present and controlled by this NIC
1988  * @type: type of dpll being initialized
1989  *
1990  * Allocate dpll instance for this board in dpll subsystem, if cgu is controlled
1991  * by this NIC, register dpll with the callback ops.
1992  *
1993  * Return:
1994  * * 0 - success
1995  * * negative - initialization failure reason
1996  */
1997 static int
1998 ice_dpll_init_dpll(struct ice_pf *pf, struct ice_dpll *d, bool cgu,
1999 		   enum dpll_type type)
2000 {
2001 	u64 clock_id = pf->dplls.clock_id;
2002 	int ret;
2003 
2004 	d->dpll = dpll_device_get(clock_id, d->dpll_idx, THIS_MODULE);
2005 	if (IS_ERR(d->dpll)) {
2006 		ret = PTR_ERR(d->dpll);
2007 		dev_err(ice_pf_to_dev(pf),
2008 			"dpll_device_get failed (%p) err=%d\n", d, ret);
2009 		return ret;
2010 	}
2011 	d->pf = pf;
2012 	if (cgu) {
2013 		ice_dpll_update_state(pf, d, true);
2014 		ret = dpll_device_register(d->dpll, type, &ice_dpll_ops, d);
2015 		if (ret) {
2016 			dpll_device_put(d->dpll);
2017 			return ret;
2018 		}
2019 	}
2020 
2021 	return 0;
2022 }
2023 
2024 /**
2025  * ice_dpll_deinit_worker - deinitialize dpll kworker
2026  * @pf: board private structure
2027  *
2028  * Stop dpll's kworker, release it's resources.
2029  */
2030 static void ice_dpll_deinit_worker(struct ice_pf *pf)
2031 {
2032 	struct ice_dplls *d = &pf->dplls;
2033 
2034 	kthread_cancel_delayed_work_sync(&d->work);
2035 	kthread_destroy_worker(d->kworker);
2036 }
2037 
2038 /**
2039  * ice_dpll_init_worker - Initialize DPLLs periodic worker
2040  * @pf: board private structure
2041  *
2042  * Create and start DPLLs periodic worker.
2043  *
2044  * Context: Shall be called after pf->dplls.lock is initialized.
2045  * Return:
2046  * * 0 - success
2047  * * negative - create worker failure
2048  */
2049 static int ice_dpll_init_worker(struct ice_pf *pf)
2050 {
2051 	struct ice_dplls *d = &pf->dplls;
2052 	struct kthread_worker *kworker;
2053 
2054 	kthread_init_delayed_work(&d->work, ice_dpll_periodic_work);
2055 	kworker = kthread_create_worker(0, "ice-dplls-%s",
2056 					dev_name(ice_pf_to_dev(pf)));
2057 	if (IS_ERR(kworker))
2058 		return PTR_ERR(kworker);
2059 	d->kworker = kworker;
2060 	d->cgu_state_acq_err_num = 0;
2061 	kthread_queue_delayed_work(d->kworker, &d->work, 0);
2062 
2063 	return 0;
2064 }
2065 
2066 /**
2067  * ice_dpll_init_info_direct_pins - initializes direct pins info
2068  * @pf: board private structure
2069  * @pin_type: type of pins being initialized
2070  *
2071  * Init information for directly connected pins, cache them in pf's pins
2072  * structures.
2073  *
2074  * Return:
2075  * * 0 - success
2076  * * negative - init failure reason
2077  */
2078 static int
2079 ice_dpll_init_info_direct_pins(struct ice_pf *pf,
2080 			       enum ice_dpll_pin_type pin_type)
2081 {
2082 	struct ice_dpll *de = &pf->dplls.eec, *dp = &pf->dplls.pps;
2083 	int num_pins, i, ret = -EINVAL;
2084 	struct ice_hw *hw = &pf->hw;
2085 	struct ice_dpll_pin *pins;
2086 	unsigned long caps;
2087 	u8 freq_supp_num;
2088 	bool input;
2089 
2090 	switch (pin_type) {
2091 	case ICE_DPLL_PIN_TYPE_INPUT:
2092 		pins = pf->dplls.inputs;
2093 		num_pins = pf->dplls.num_inputs;
2094 		input = true;
2095 		break;
2096 	case ICE_DPLL_PIN_TYPE_OUTPUT:
2097 		pins = pf->dplls.outputs;
2098 		num_pins = pf->dplls.num_outputs;
2099 		input = false;
2100 		break;
2101 	default:
2102 		return -EINVAL;
2103 	}
2104 
2105 	for (i = 0; i < num_pins; i++) {
2106 		caps = 0;
2107 		pins[i].idx = i;
2108 		pins[i].prop.board_label = ice_cgu_get_pin_name(hw, i, input);
2109 		pins[i].prop.type = ice_cgu_get_pin_type(hw, i, input);
2110 		if (input) {
2111 			ret = ice_aq_get_cgu_ref_prio(hw, de->dpll_idx, i,
2112 						      &de->input_prio[i]);
2113 			if (ret)
2114 				return ret;
2115 			ret = ice_aq_get_cgu_ref_prio(hw, dp->dpll_idx, i,
2116 						      &dp->input_prio[i]);
2117 			if (ret)
2118 				return ret;
2119 			caps |= (DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE |
2120 				 DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE);
2121 			pins[i].prop.phase_range.min =
2122 				pf->dplls.input_phase_adj_max;
2123 			pins[i].prop.phase_range.max =
2124 				-pf->dplls.input_phase_adj_max;
2125 		} else {
2126 			pins[i].prop.phase_range.min =
2127 				pf->dplls.output_phase_adj_max;
2128 			pins[i].prop.phase_range.max =
2129 				-pf->dplls.output_phase_adj_max;
2130 			ret = ice_cgu_get_output_pin_state_caps(hw, i, &caps);
2131 			if (ret)
2132 				return ret;
2133 		}
2134 		pins[i].prop.capabilities = caps;
2135 		ret = ice_dpll_pin_state_update(pf, &pins[i], pin_type, NULL);
2136 		if (ret)
2137 			return ret;
2138 		pins[i].prop.freq_supported =
2139 			ice_cgu_get_pin_freq_supp(hw, i, input, &freq_supp_num);
2140 		pins[i].prop.freq_supported_num = freq_supp_num;
2141 		pins[i].pf = pf;
2142 	}
2143 
2144 	return ret;
2145 }
2146 
2147 /**
2148  * ice_dpll_init_info_rclk_pin - initializes rclk pin information
2149  * @pf: board private structure
2150  *
2151  * Init information for rclk pin, cache them in pf->dplls.rclk.
2152  *
2153  * Return:
2154  * * 0 - success
2155  * * negative - init failure reason
2156  */
2157 static int ice_dpll_init_info_rclk_pin(struct ice_pf *pf)
2158 {
2159 	struct ice_dpll_pin *pin = &pf->dplls.rclk;
2160 
2161 	pin->prop.type = DPLL_PIN_TYPE_SYNCE_ETH_PORT;
2162 	pin->prop.capabilities |= DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;
2163 	pin->pf = pf;
2164 
2165 	return ice_dpll_pin_state_update(pf, pin,
2166 					 ICE_DPLL_PIN_TYPE_RCLK_INPUT, NULL);
2167 }
2168 
2169 /**
2170  * ice_dpll_init_pins_info - init pins info wrapper
2171  * @pf: board private structure
2172  * @pin_type: type of pins being initialized
2173  *
2174  * Wraps functions for pin initialization.
2175  *
2176  * Return:
2177  * * 0 - success
2178  * * negative - init failure reason
2179  */
2180 static int
2181 ice_dpll_init_pins_info(struct ice_pf *pf, enum ice_dpll_pin_type pin_type)
2182 {
2183 	switch (pin_type) {
2184 	case ICE_DPLL_PIN_TYPE_INPUT:
2185 	case ICE_DPLL_PIN_TYPE_OUTPUT:
2186 		return ice_dpll_init_info_direct_pins(pf, pin_type);
2187 	case ICE_DPLL_PIN_TYPE_RCLK_INPUT:
2188 		return ice_dpll_init_info_rclk_pin(pf);
2189 	default:
2190 		return -EINVAL;
2191 	}
2192 }
2193 
2194 /**
2195  * ice_dpll_deinit_info - release memory allocated for pins info
2196  * @pf: board private structure
2197  *
2198  * Release memory allocated for pins by ice_dpll_init_info function.
2199  */
2200 static void ice_dpll_deinit_info(struct ice_pf *pf)
2201 {
2202 	kfree(pf->dplls.inputs);
2203 	kfree(pf->dplls.outputs);
2204 	kfree(pf->dplls.eec.input_prio);
2205 	kfree(pf->dplls.pps.input_prio);
2206 }
2207 
2208 /**
2209  * ice_dpll_init_info - prepare pf's dpll information structure
2210  * @pf: board private structure
2211  * @cgu: if cgu is present and controlled by this NIC
2212  *
2213  * Acquire (from HW) and set basic dpll information (on pf->dplls struct).
2214  *
2215  * Return:
2216  * * 0 - success
2217  * * negative - init failure reason
2218  */
2219 static int ice_dpll_init_info(struct ice_pf *pf, bool cgu)
2220 {
2221 	struct ice_aqc_get_cgu_abilities abilities;
2222 	struct ice_dpll *de = &pf->dplls.eec;
2223 	struct ice_dpll *dp = &pf->dplls.pps;
2224 	struct ice_dplls *d = &pf->dplls;
2225 	struct ice_hw *hw = &pf->hw;
2226 	int ret, alloc_size, i;
2227 
2228 	d->clock_id = ice_generate_clock_id(pf);
2229 	ret = ice_aq_get_cgu_abilities(hw, &abilities);
2230 	if (ret) {
2231 		dev_err(ice_pf_to_dev(pf),
2232 			"err:%d %s failed to read cgu abilities\n",
2233 			ret, ice_aq_str(hw->adminq.sq_last_status));
2234 		return ret;
2235 	}
2236 
2237 	de->dpll_idx = abilities.eec_dpll_idx;
2238 	dp->dpll_idx = abilities.pps_dpll_idx;
2239 	d->num_inputs = abilities.num_inputs;
2240 	d->num_outputs = abilities.num_outputs;
2241 	d->input_phase_adj_max = le32_to_cpu(abilities.max_in_phase_adj);
2242 	d->output_phase_adj_max = le32_to_cpu(abilities.max_out_phase_adj);
2243 
2244 	alloc_size = sizeof(*d->inputs) * d->num_inputs;
2245 	d->inputs = kzalloc(alloc_size, GFP_KERNEL);
2246 	if (!d->inputs)
2247 		return -ENOMEM;
2248 
2249 	alloc_size = sizeof(*de->input_prio) * d->num_inputs;
2250 	de->input_prio = kzalloc(alloc_size, GFP_KERNEL);
2251 	if (!de->input_prio)
2252 		return -ENOMEM;
2253 
2254 	dp->input_prio = kzalloc(alloc_size, GFP_KERNEL);
2255 	if (!dp->input_prio)
2256 		return -ENOMEM;
2257 
2258 	ret = ice_dpll_init_pins_info(pf, ICE_DPLL_PIN_TYPE_INPUT);
2259 	if (ret)
2260 		goto deinit_info;
2261 
2262 	if (cgu) {
2263 		alloc_size = sizeof(*d->outputs) * d->num_outputs;
2264 		d->outputs = kzalloc(alloc_size, GFP_KERNEL);
2265 		if (!d->outputs) {
2266 			ret = -ENOMEM;
2267 			goto deinit_info;
2268 		}
2269 
2270 		ret = ice_dpll_init_pins_info(pf, ICE_DPLL_PIN_TYPE_OUTPUT);
2271 		if (ret)
2272 			goto deinit_info;
2273 	}
2274 
2275 	ret = ice_get_cgu_rclk_pin_info(&pf->hw, &d->base_rclk_idx,
2276 					&pf->dplls.rclk.num_parents);
2277 	if (ret)
2278 		return ret;
2279 	for (i = 0; i < pf->dplls.rclk.num_parents; i++)
2280 		pf->dplls.rclk.parent_idx[i] = d->base_rclk_idx + i;
2281 	ret = ice_dpll_init_pins_info(pf, ICE_DPLL_PIN_TYPE_RCLK_INPUT);
2282 	if (ret)
2283 		return ret;
2284 	de->mode = DPLL_MODE_AUTOMATIC;
2285 	dp->mode = DPLL_MODE_AUTOMATIC;
2286 
2287 	dev_dbg(ice_pf_to_dev(pf),
2288 		"%s - success, inputs:%u, outputs:%u rclk-parents:%u\n",
2289 		__func__, d->num_inputs, d->num_outputs, d->rclk.num_parents);
2290 
2291 	return 0;
2292 
2293 deinit_info:
2294 	dev_err(ice_pf_to_dev(pf),
2295 		"%s - fail: d->inputs:%p, de->input_prio:%p, dp->input_prio:%p, d->outputs:%p\n",
2296 		__func__, d->inputs, de->input_prio,
2297 		dp->input_prio, d->outputs);
2298 	ice_dpll_deinit_info(pf);
2299 	return ret;
2300 }
2301 
2302 /**
2303  * ice_dpll_deinit - Disable the driver/HW support for dpll subsystem
2304  * the dpll device.
2305  * @pf: board private structure
2306  *
2307  * Handles the cleanup work required after dpll initialization, freeing
2308  * resources and unregistering the dpll, pin and all resources used for
2309  * handling them.
2310  *
2311  * Context: Destroys pf->dplls.lock mutex. Call only if ICE_FLAG_DPLL was set.
2312  */
2313 void ice_dpll_deinit(struct ice_pf *pf)
2314 {
2315 	bool cgu = ice_is_feature_supported(pf, ICE_F_CGU);
2316 
2317 	clear_bit(ICE_FLAG_DPLL, pf->flags);
2318 	if (cgu)
2319 		ice_dpll_deinit_worker(pf);
2320 
2321 	ice_dpll_deinit_pins(pf, cgu);
2322 	ice_dpll_deinit_dpll(pf, &pf->dplls.pps, cgu);
2323 	ice_dpll_deinit_dpll(pf, &pf->dplls.eec, cgu);
2324 	ice_dpll_deinit_info(pf);
2325 	mutex_destroy(&pf->dplls.lock);
2326 }
2327 
2328 /**
2329  * ice_dpll_init - initialize support for dpll subsystem
2330  * @pf: board private structure
2331  *
2332  * Set up the device dplls, register them and pins connected within Linux dpll
2333  * subsystem. Allow userspace to obtain state of DPLL and handling of DPLL
2334  * configuration requests.
2335  *
2336  * Context: Initializes pf->dplls.lock mutex.
2337  */
2338 void ice_dpll_init(struct ice_pf *pf)
2339 {
2340 	bool cgu = ice_is_feature_supported(pf, ICE_F_CGU);
2341 	struct ice_dplls *d = &pf->dplls;
2342 	int err = 0;
2343 
2344 	mutex_init(&d->lock);
2345 	err = ice_dpll_init_info(pf, cgu);
2346 	if (err)
2347 		goto err_exit;
2348 	err = ice_dpll_init_dpll(pf, &pf->dplls.eec, cgu, DPLL_TYPE_EEC);
2349 	if (err)
2350 		goto deinit_info;
2351 	err = ice_dpll_init_dpll(pf, &pf->dplls.pps, cgu, DPLL_TYPE_PPS);
2352 	if (err)
2353 		goto deinit_eec;
2354 	err = ice_dpll_init_pins(pf, cgu);
2355 	if (err)
2356 		goto deinit_pps;
2357 	if (cgu) {
2358 		err = ice_dpll_init_worker(pf);
2359 		if (err)
2360 			goto deinit_pins;
2361 	}
2362 	set_bit(ICE_FLAG_DPLL, pf->flags);
2363 
2364 	return;
2365 
2366 deinit_pins:
2367 	ice_dpll_deinit_pins(pf, cgu);
2368 deinit_pps:
2369 	ice_dpll_deinit_dpll(pf, &pf->dplls.pps, cgu);
2370 deinit_eec:
2371 	ice_dpll_deinit_dpll(pf, &pf->dplls.eec, cgu);
2372 deinit_info:
2373 	ice_dpll_deinit_info(pf);
2374 err_exit:
2375 	mutex_destroy(&d->lock);
2376 	dev_warn(ice_pf_to_dev(pf), "DPLLs init failure err:%d\n", err);
2377 }
2378