@@ -62,7 +62,7 @@ static struct ice_pf *ice_get_ctrl_pf(struct ice_pf *pf)
62
62
return !pf -> adapter ? NULL : pf -> adapter -> ctrl_pf ;
63
63
}
64
64
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 )
66
66
{
67
67
struct ice_pf * ctrl_pf = ice_get_ctrl_pf (pf );
68
68
@@ -760,16 +760,16 @@ static enum ice_tx_tstamp_work ice_ptp_tx_tstamp_owner(struct ice_pf *pf)
760
760
struct ice_ptp_port * port ;
761
761
unsigned int i ;
762
762
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 ) {
765
765
struct ice_ptp_tx * tx = & port -> tx ;
766
766
767
767
if (!tx || !tx -> init )
768
768
continue ;
769
769
770
770
ice_ptp_process_tx_tstamp (tx );
771
771
}
772
- mutex_unlock (& pf -> ptp . ports_owner .lock );
772
+ mutex_unlock (& pf -> adapter -> ports .lock );
773
773
774
774
for (i = 0 ; i < ICE_GET_QUAD_NUM (pf -> hw .ptp .num_lports ); i ++ ) {
775
775
u64 tstamp_ready ;
@@ -934,7 +934,7 @@ ice_ptp_flush_all_tx_tracker(struct ice_pf *pf)
934
934
{
935
935
struct ice_ptp_port * port ;
936
936
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 )
938
938
ice_ptp_flush_tx_tracker (ptp_port_to_pf (port ), & port -> tx );
939
939
}
940
940
@@ -1526,10 +1526,10 @@ static void ice_ptp_restart_all_phy(struct ice_pf *pf)
1526
1526
{
1527
1527
struct list_head * entry ;
1528
1528
1529
- list_for_each (entry , & pf -> ptp . ports_owner .ports ) {
1529
+ list_for_each (entry , & pf -> adapter -> ports .ports ) {
1530
1530
struct ice_ptp_port * port = list_entry (entry ,
1531
1531
struct ice_ptp_port ,
1532
- list_member );
1532
+ list_node );
1533
1533
1534
1534
if (port -> link_up )
1535
1535
ice_ptp_port_phy_restart (port );
@@ -2957,6 +2957,50 @@ void ice_ptp_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
2957
2957
dev_err (ice_pf_to_dev (pf ), "PTP reset failed %d\n" , err );
2958
2958
}
2959
2959
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
+ }
2960
3004
/**
2961
3005
* ice_ptp_aux_dev_to_aux_pf - Get auxiliary PF handle for the auxiliary device
2962
3006
* @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,
3008
3052
if (WARN_ON (!owner_pf ))
3009
3053
return - ENODEV ;
3010
3054
3011
- INIT_LIST_HEAD (& aux_pf -> ptp .port .list_member );
3055
+ INIT_LIST_HEAD (& aux_pf -> ptp .port .list_node );
3012
3056
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 ,
3014
3058
& owner_pf -> ptp .ports_owner .ports );
3015
3059
mutex_unlock (& owner_pf -> ptp .ports_owner .lock );
3016
3060
@@ -3027,7 +3071,7 @@ static void ice_ptp_auxbus_remove(struct auxiliary_device *aux_dev)
3027
3071
struct ice_pf * aux_pf = ice_ptp_aux_dev_to_aux_pf (aux_dev );
3028
3072
3029
3073
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 );
3031
3075
mutex_unlock (& owner_pf -> ptp .ports_owner .lock );
3032
3076
}
3033
3077
@@ -3087,7 +3131,7 @@ ice_ptp_auxbus_create_id_table(struct ice_pf *pf, const char *name)
3087
3131
* ice_ptp_register_auxbus_driver - Register PTP auxiliary bus driver
3088
3132
* @pf: Board private structure
3089
3133
*/
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 )
3091
3135
{
3092
3136
struct auxiliary_driver * aux_driver ;
3093
3137
struct ice_ptp * ptp ;
@@ -3130,7 +3174,7 @@ static int ice_ptp_register_auxbus_driver(struct ice_pf *pf)
3130
3174
* ice_ptp_unregister_auxbus_driver - Unregister PTP auxiliary bus driver
3131
3175
* @pf: Board private structure
3132
3176
*/
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 )
3134
3178
{
3135
3179
struct auxiliary_driver * aux_driver = & pf -> ptp .ports_owner .aux_driver ;
3136
3180
@@ -3149,15 +3193,12 @@ static void ice_ptp_unregister_auxbus_driver(struct ice_pf *pf)
3149
3193
*/
3150
3194
int ice_ptp_clock_index (struct ice_pf * pf )
3151
3195
{
3152
- struct auxiliary_device * aux_dev ;
3153
- struct ice_pf * owner_pf ;
3196
+ struct ice_ptp * ctrl_ptp = ice_get_ctrl_ptp (pf );
3154
3197
struct ptp_clock * clock ;
3155
3198
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 )
3159
3200
return -1 ;
3160
- clock = owner_pf -> ptp . clock ;
3201
+ clock = ctrl_ptp -> clock ;
3161
3202
3162
3203
return clock ? ptp_clock_index (clock ) : -1 ;
3163
3204
}
@@ -3217,15 +3258,7 @@ static int ice_ptp_init_owner(struct ice_pf *pf)
3217
3258
if (err )
3218
3259
goto err_clk ;
3219
3260
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
-
3226
3261
return 0 ;
3227
- err_aux :
3228
- ptp_clock_unregister (pf -> ptp .clock );
3229
3262
err_clk :
3230
3263
pf -> ptp .clock = NULL ;
3231
3264
err_exit :
@@ -3301,7 +3334,7 @@ static void ice_ptp_release_auxbus_device(struct device *dev)
3301
3334
* ice_ptp_create_auxbus_device - Create PTP auxiliary bus device
3302
3335
* @pf: Board private structure
3303
3336
*/
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 )
3305
3338
{
3306
3339
struct auxiliary_device * aux_dev ;
3307
3340
struct ice_ptp * ptp ;
@@ -3348,7 +3381,7 @@ static int ice_ptp_create_auxbus_device(struct ice_pf *pf)
3348
3381
* ice_ptp_remove_auxbus_device - Remove PTP auxiliary bus device
3349
3382
* @pf: Board private structure
3350
3383
*/
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 )
3352
3385
{
3353
3386
struct auxiliary_device * aux_dev = & pf -> ptp .port .aux_dev ;
3354
3387
@@ -3408,7 +3441,7 @@ void ice_ptp_init(struct ice_pf *pf)
3408
3441
lane_num = ice_get_phy_lane_number (hw );
3409
3442
if (lane_num < 0 ) {
3410
3443
err = lane_num ;
3411
- goto err ;
3444
+ goto err_exit ;
3412
3445
}
3413
3446
3414
3447
ptp -> port .port_num = (u8 )lane_num ;
@@ -3419,36 +3452,39 @@ void ice_ptp_init(struct ice_pf *pf)
3419
3452
/* If this function owns the clock hardware, it must allocate and
3420
3453
* configure the PTP clock device to represent it.
3421
3454
*/
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 ;
3423
3459
err = ice_ptp_init_owner (pf );
3424
3460
if (err )
3425
- goto err ;
3461
+ goto err_exit ;
3426
3462
}
3427
3463
3464
+ err = ice_ptp_setup_pf (pf );
3465
+ if (err )
3466
+ goto err_exit ;
3467
+
3428
3468
err = ice_ptp_init_port (pf , & ptp -> port );
3429
3469
if (err )
3430
- goto err ;
3470
+ goto err_exit ;
3431
3471
3432
3472
/* Start the PHY timestamping block */
3433
3473
ice_ptp_reset_phy_timestamping (pf );
3434
3474
3435
3475
/* Configure initial Tx interrupt settings */
3436
3476
ice_ptp_cfg_tx_interrupt (pf );
3437
3477
3438
- err = ice_ptp_create_auxbus_device (pf );
3439
- if (err )
3440
- goto err ;
3441
-
3442
3478
ptp -> state = ICE_PTP_READY ;
3443
3479
3444
3480
err = ice_ptp_init_work (pf , ptp );
3445
3481
if (err )
3446
- goto err ;
3482
+ goto err_exit ;
3447
3483
3448
3484
dev_info (ice_pf_to_dev (pf ), "PTP init successful\n" );
3449
3485
return ;
3450
3486
3451
- err :
3487
+ err_exit :
3452
3488
/* If we registered a PTP clock, release it */
3453
3489
if (pf -> ptp .clock ) {
3454
3490
ptp_clock_unregister (ptp -> clock );
@@ -3475,7 +3511,7 @@ void ice_ptp_release(struct ice_pf *pf)
3475
3511
/* Disable timestamping for both Tx and Rx */
3476
3512
ice_ptp_disable_timestamp_mode (pf );
3477
3513
3478
- ice_ptp_remove_auxbus_device (pf );
3514
+ ice_ptp_cleanup_pf (pf );
3479
3515
3480
3516
ice_ptp_release_tx_tracker (pf , & pf -> ptp .port .tx );
3481
3517
@@ -3490,9 +3526,6 @@ void ice_ptp_release(struct ice_pf *pf)
3490
3526
pf -> ptp .kworker = NULL ;
3491
3527
}
3492
3528
3493
- if (ice_pf_src_tmr_owned (pf ))
3494
- ice_ptp_unregister_auxbus_driver (pf );
3495
-
3496
3529
if (!pf -> ptp .clock )
3497
3530
return ;
3498
3531
0 commit comments