@@ -62,7 +62,7 @@ static struct ice_pf *ice_get_ctrl_pf(struct ice_pf *pf)
6262 return !pf -> adapter ? NULL : pf -> adapter -> ctrl_pf ;
6363}
6464
65- static __maybe_unused struct ice_ptp * ice_get_ctrl_ptp (struct ice_pf * pf )
65+ static struct ice_ptp * ice_get_ctrl_ptp (struct ice_pf * pf )
6666{
6767 struct ice_pf * ctrl_pf = ice_get_ctrl_pf (pf );
6868
@@ -760,16 +760,16 @@ static enum ice_tx_tstamp_work ice_ptp_tx_tstamp_owner(struct ice_pf *pf)
760760 struct ice_ptp_port * port ;
761761 unsigned int i ;
762762
763- mutex_lock (& pf -> ptp . ports_owner .lock );
764- list_for_each_entry (port , & pf -> ptp . ports_owner . ports , list_member ) {
763+ mutex_lock (& pf -> adapter -> ports .lock );
764+ list_for_each_entry (port , & pf -> adapter -> ports . ports , list_node ) {
765765 struct ice_ptp_tx * tx = & port -> tx ;
766766
767767 if (!tx || !tx -> init )
768768 continue ;
769769
770770 ice_ptp_process_tx_tstamp (tx );
771771 }
772- mutex_unlock (& pf -> ptp . ports_owner .lock );
772+ mutex_unlock (& pf -> adapter -> ports .lock );
773773
774774 for (i = 0 ; i < ICE_GET_QUAD_NUM (pf -> hw .ptp .num_lports ); i ++ ) {
775775 u64 tstamp_ready ;
@@ -934,7 +934,7 @@ ice_ptp_flush_all_tx_tracker(struct ice_pf *pf)
934934{
935935 struct ice_ptp_port * port ;
936936
937- list_for_each_entry (port , & pf -> ptp . ports_owner . ports , list_member )
937+ list_for_each_entry (port , & pf -> adapter -> ports . ports , list_node )
938938 ice_ptp_flush_tx_tracker (ptp_port_to_pf (port ), & port -> tx );
939939}
940940
@@ -1526,10 +1526,10 @@ static void ice_ptp_restart_all_phy(struct ice_pf *pf)
15261526{
15271527 struct list_head * entry ;
15281528
1529- list_for_each (entry , & pf -> ptp . ports_owner .ports ) {
1529+ list_for_each (entry , & pf -> adapter -> ports .ports ) {
15301530 struct ice_ptp_port * port = list_entry (entry ,
15311531 struct ice_ptp_port ,
1532- list_member );
1532+ list_node );
15331533
15341534 if (port -> link_up )
15351535 ice_ptp_port_phy_restart (port );
@@ -2957,6 +2957,50 @@ void ice_ptp_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
29572957 dev_err (ice_pf_to_dev (pf ), "PTP reset failed %d\n" , err );
29582958}
29592959
2960+ static bool ice_is_primary (struct ice_hw * hw )
2961+ {
2962+ return ice_is_e825c (hw ) && ice_is_dual (hw ) ?
2963+ !!(hw -> dev_caps .nac_topo .mode & ICE_NAC_TOPO_PRIMARY_M ) : true;
2964+ }
2965+
2966+ static int ice_ptp_setup_adapter (struct ice_pf * pf )
2967+ {
2968+ if (!ice_pf_src_tmr_owned (pf ) || !ice_is_primary (& pf -> hw ))
2969+ return - EPERM ;
2970+
2971+ pf -> adapter -> ctrl_pf = pf ;
2972+
2973+ return 0 ;
2974+ }
2975+
2976+ static int ice_ptp_setup_pf (struct ice_pf * pf )
2977+ {
2978+ struct ice_ptp * ctrl_ptp = ice_get_ctrl_ptp (pf );
2979+ struct ice_ptp * ptp = & pf -> ptp ;
2980+
2981+ if (WARN_ON (!ctrl_ptp ) || ice_get_phy_model (& pf -> hw ) == ICE_PHY_UNSUP )
2982+ return - ENODEV ;
2983+
2984+ INIT_LIST_HEAD (& ptp -> port .list_node );
2985+ mutex_lock (& pf -> adapter -> ports .lock );
2986+
2987+ list_add (& ptp -> port .list_node ,
2988+ & pf -> adapter -> ports .ports );
2989+ mutex_unlock (& pf -> adapter -> ports .lock );
2990+
2991+ return 0 ;
2992+ }
2993+
2994+ static void ice_ptp_cleanup_pf (struct ice_pf * pf )
2995+ {
2996+ struct ice_ptp * ptp = & pf -> ptp ;
2997+
2998+ if (ice_get_phy_model (& pf -> hw ) != ICE_PHY_UNSUP ) {
2999+ mutex_lock (& pf -> adapter -> ports .lock );
3000+ list_del (& ptp -> port .list_node );
3001+ mutex_unlock (& pf -> adapter -> ports .lock );
3002+ }
3003+ }
29603004/**
29613005 * ice_ptp_aux_dev_to_aux_pf - Get auxiliary PF handle for the auxiliary device
29623006 * @aux_dev: auxiliary device to get the auxiliary PF for
@@ -3008,9 +3052,9 @@ static int ice_ptp_auxbus_probe(struct auxiliary_device *aux_dev,
30083052 if (WARN_ON (!owner_pf ))
30093053 return - ENODEV ;
30103054
3011- INIT_LIST_HEAD (& aux_pf -> ptp .port .list_member );
3055+ INIT_LIST_HEAD (& aux_pf -> ptp .port .list_node );
30123056 mutex_lock (& owner_pf -> ptp .ports_owner .lock );
3013- list_add (& aux_pf -> ptp .port .list_member ,
3057+ list_add (& aux_pf -> ptp .port .list_node ,
30143058 & owner_pf -> ptp .ports_owner .ports );
30153059 mutex_unlock (& owner_pf -> ptp .ports_owner .lock );
30163060
@@ -3027,7 +3071,7 @@ static void ice_ptp_auxbus_remove(struct auxiliary_device *aux_dev)
30273071 struct ice_pf * aux_pf = ice_ptp_aux_dev_to_aux_pf (aux_dev );
30283072
30293073 mutex_lock (& owner_pf -> ptp .ports_owner .lock );
3030- list_del (& aux_pf -> ptp .port .list_member );
3074+ list_del (& aux_pf -> ptp .port .list_node );
30313075 mutex_unlock (& owner_pf -> ptp .ports_owner .lock );
30323076}
30333077
@@ -3087,7 +3131,7 @@ ice_ptp_auxbus_create_id_table(struct ice_pf *pf, const char *name)
30873131 * ice_ptp_register_auxbus_driver - Register PTP auxiliary bus driver
30883132 * @pf: Board private structure
30893133 */
3090- static int ice_ptp_register_auxbus_driver (struct ice_pf * pf )
3134+ static int __always_unused ice_ptp_register_auxbus_driver (struct ice_pf * pf )
30913135{
30923136 struct auxiliary_driver * aux_driver ;
30933137 struct ice_ptp * ptp ;
@@ -3130,7 +3174,7 @@ static int ice_ptp_register_auxbus_driver(struct ice_pf *pf)
31303174 * ice_ptp_unregister_auxbus_driver - Unregister PTP auxiliary bus driver
31313175 * @pf: Board private structure
31323176 */
3133- static void ice_ptp_unregister_auxbus_driver (struct ice_pf * pf )
3177+ static void __always_unused ice_ptp_unregister_auxbus_driver (struct ice_pf * pf )
31343178{
31353179 struct auxiliary_driver * aux_driver = & pf -> ptp .ports_owner .aux_driver ;
31363180
@@ -3149,15 +3193,12 @@ static void ice_ptp_unregister_auxbus_driver(struct ice_pf *pf)
31493193 */
31503194int ice_ptp_clock_index (struct ice_pf * pf )
31513195{
3152- struct auxiliary_device * aux_dev ;
3153- struct ice_pf * owner_pf ;
3196+ struct ice_ptp * ctrl_ptp = ice_get_ctrl_ptp (pf );
31543197 struct ptp_clock * clock ;
31553198
3156- aux_dev = & pf -> ptp .port .aux_dev ;
3157- owner_pf = ice_ptp_aux_dev_to_owner_pf (aux_dev );
3158- if (!owner_pf )
3199+ if (!ctrl_ptp )
31593200 return -1 ;
3160- clock = owner_pf -> ptp . clock ;
3201+ clock = ctrl_ptp -> clock ;
31613202
31623203 return clock ? ptp_clock_index (clock ) : -1 ;
31633204}
@@ -3217,15 +3258,7 @@ static int ice_ptp_init_owner(struct ice_pf *pf)
32173258 if (err )
32183259 goto err_clk ;
32193260
3220- err = ice_ptp_register_auxbus_driver (pf );
3221- if (err ) {
3222- dev_err (ice_pf_to_dev (pf ), "Failed to register PTP auxbus driver" );
3223- goto err_aux ;
3224- }
3225-
32263261 return 0 ;
3227- err_aux :
3228- ptp_clock_unregister (pf -> ptp .clock );
32293262err_clk :
32303263 pf -> ptp .clock = NULL ;
32313264err_exit :
@@ -3301,7 +3334,7 @@ static void ice_ptp_release_auxbus_device(struct device *dev)
33013334 * ice_ptp_create_auxbus_device - Create PTP auxiliary bus device
33023335 * @pf: Board private structure
33033336 */
3304- static int ice_ptp_create_auxbus_device (struct ice_pf * pf )
3337+ static __always_unused int ice_ptp_create_auxbus_device (struct ice_pf * pf )
33053338{
33063339 struct auxiliary_device * aux_dev ;
33073340 struct ice_ptp * ptp ;
@@ -3348,7 +3381,7 @@ static int ice_ptp_create_auxbus_device(struct ice_pf *pf)
33483381 * ice_ptp_remove_auxbus_device - Remove PTP auxiliary bus device
33493382 * @pf: Board private structure
33503383 */
3351- static void ice_ptp_remove_auxbus_device (struct ice_pf * pf )
3384+ static __always_unused void ice_ptp_remove_auxbus_device (struct ice_pf * pf )
33523385{
33533386 struct auxiliary_device * aux_dev = & pf -> ptp .port .aux_dev ;
33543387
@@ -3408,7 +3441,7 @@ void ice_ptp_init(struct ice_pf *pf)
34083441 lane_num = ice_get_phy_lane_number (hw );
34093442 if (lane_num < 0 ) {
34103443 err = lane_num ;
3411- goto err ;
3444+ goto err_exit ;
34123445 }
34133446
34143447 ptp -> port .port_num = (u8 )lane_num ;
@@ -3419,36 +3452,39 @@ void ice_ptp_init(struct ice_pf *pf)
34193452 /* If this function owns the clock hardware, it must allocate and
34203453 * configure the PTP clock device to represent it.
34213454 */
3422- if (ice_pf_src_tmr_owned (pf )) {
3455+ if (ice_pf_src_tmr_owned (pf ) && ice_is_primary (hw )) {
3456+ err = ice_ptp_setup_adapter (pf );
3457+ if (err )
3458+ goto err_exit ;
34233459 err = ice_ptp_init_owner (pf );
34243460 if (err )
3425- goto err ;
3461+ goto err_exit ;
34263462 }
34273463
3464+ err = ice_ptp_setup_pf (pf );
3465+ if (err )
3466+ goto err_exit ;
3467+
34283468 err = ice_ptp_init_port (pf , & ptp -> port );
34293469 if (err )
3430- goto err ;
3470+ goto err_exit ;
34313471
34323472 /* Start the PHY timestamping block */
34333473 ice_ptp_reset_phy_timestamping (pf );
34343474
34353475 /* Configure initial Tx interrupt settings */
34363476 ice_ptp_cfg_tx_interrupt (pf );
34373477
3438- err = ice_ptp_create_auxbus_device (pf );
3439- if (err )
3440- goto err ;
3441-
34423478 ptp -> state = ICE_PTP_READY ;
34433479
34443480 err = ice_ptp_init_work (pf , ptp );
34453481 if (err )
3446- goto err ;
3482+ goto err_exit ;
34473483
34483484 dev_info (ice_pf_to_dev (pf ), "PTP init successful\n" );
34493485 return ;
34503486
3451- err :
3487+ err_exit :
34523488 /* If we registered a PTP clock, release it */
34533489 if (pf -> ptp .clock ) {
34543490 ptp_clock_unregister (ptp -> clock );
@@ -3475,7 +3511,7 @@ void ice_ptp_release(struct ice_pf *pf)
34753511 /* Disable timestamping for both Tx and Rx */
34763512 ice_ptp_disable_timestamp_mode (pf );
34773513
3478- ice_ptp_remove_auxbus_device (pf );
3514+ ice_ptp_cleanup_pf (pf );
34793515
34803516 ice_ptp_release_tx_tracker (pf , & pf -> ptp .port .tx );
34813517
@@ -3490,9 +3526,6 @@ void ice_ptp_release(struct ice_pf *pf)
34903526 pf -> ptp .kworker = NULL ;
34913527 }
34923528
3493- if (ice_pf_src_tmr_owned (pf ))
3494- ice_ptp_unregister_auxbus_driver (pf );
3495-
34963529 if (!pf -> ptp .clock )
34973530 return ;
34983531
0 commit comments