@@ -21,7 +21,7 @@ static struct ice_pf *ice_get_ctrl_pf(struct ice_pf *pf)
21
21
return !pf -> adapter ? NULL : pf -> adapter -> ctrl_pf ;
22
22
}
23
23
24
- static __maybe_unused struct ice_ptp * ice_get_ctrl_ptp (struct ice_pf * pf )
24
+ static struct ice_ptp * ice_get_ctrl_ptp (struct ice_pf * pf )
25
25
{
26
26
struct ice_pf * ctrl_pf = ice_get_ctrl_pf (pf );
27
27
@@ -812,16 +812,16 @@ static enum ice_tx_tstamp_work ice_ptp_tx_tstamp_owner(struct ice_pf *pf)
812
812
struct ice_ptp_port * port ;
813
813
unsigned int i ;
814
814
815
- mutex_lock (& pf -> ptp . ports_owner .lock );
816
- list_for_each_entry (port , & pf -> ptp . ports_owner . ports , list_member ) {
815
+ mutex_lock (& pf -> adapter -> ports .lock );
816
+ list_for_each_entry (port , & pf -> adapter -> ports . ports , list_node ) {
817
817
struct ice_ptp_tx * tx = & port -> tx ;
818
818
819
819
if (!tx || !tx -> init )
820
820
continue ;
821
821
822
822
ice_ptp_process_tx_tstamp (tx );
823
823
}
824
- mutex_unlock (& pf -> ptp . ports_owner .lock );
824
+ mutex_unlock (& pf -> adapter -> ports .lock );
825
825
826
826
for (i = 0 ; i < ICE_GET_QUAD_NUM (pf -> hw .ptp .num_lports ); i ++ ) {
827
827
u64 tstamp_ready ;
@@ -986,7 +986,7 @@ ice_ptp_flush_all_tx_tracker(struct ice_pf *pf)
986
986
{
987
987
struct ice_ptp_port * port ;
988
988
989
- list_for_each_entry (port , & pf -> ptp . ports_owner . ports , list_member )
989
+ list_for_each_entry (port , & pf -> adapter -> ports . ports , list_node )
990
990
ice_ptp_flush_tx_tracker (ptp_port_to_pf (port ), & port -> tx );
991
991
}
992
992
@@ -1586,10 +1586,10 @@ static void ice_ptp_restart_all_phy(struct ice_pf *pf)
1586
1586
{
1587
1587
struct list_head * entry ;
1588
1588
1589
- list_for_each (entry , & pf -> ptp . ports_owner .ports ) {
1589
+ list_for_each (entry , & pf -> adapter -> ports .ports ) {
1590
1590
struct ice_ptp_port * port = list_entry (entry ,
1591
1591
struct ice_ptp_port ,
1592
- list_member );
1592
+ list_node );
1593
1593
1594
1594
if (port -> link_up )
1595
1595
ice_ptp_port_phy_restart (port );
@@ -2906,6 +2906,50 @@ void ice_ptp_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
2906
2906
dev_err (ice_pf_to_dev (pf ), "PTP reset failed %d\n" , err );
2907
2907
}
2908
2908
2909
+ static bool ice_is_primary (struct ice_hw * hw )
2910
+ {
2911
+ return ice_is_e825c (hw ) && ice_is_dual (hw ) ?
2912
+ !!(hw -> dev_caps .nac_topo .mode & ICE_NAC_TOPO_PRIMARY_M ) : true;
2913
+ }
2914
+
2915
+ static int ice_ptp_setup_adapter (struct ice_pf * pf )
2916
+ {
2917
+ if (!ice_pf_src_tmr_owned (pf ) || !ice_is_primary (& pf -> hw ))
2918
+ return - EPERM ;
2919
+
2920
+ pf -> adapter -> ctrl_pf = pf ;
2921
+
2922
+ return 0 ;
2923
+ }
2924
+
2925
+ static int ice_ptp_setup_pf (struct ice_pf * pf )
2926
+ {
2927
+ struct ice_ptp * ctrl_ptp = ice_get_ctrl_ptp (pf );
2928
+ struct ice_ptp * ptp = & pf -> ptp ;
2929
+
2930
+ if (WARN_ON (!ctrl_ptp ) || ice_get_phy_model (& pf -> hw ) == ICE_PHY_UNSUP )
2931
+ return - ENODEV ;
2932
+
2933
+ INIT_LIST_HEAD (& ptp -> port .list_node );
2934
+ mutex_lock (& pf -> adapter -> ports .lock );
2935
+
2936
+ list_add (& ptp -> port .list_node ,
2937
+ & pf -> adapter -> ports .ports );
2938
+ mutex_unlock (& pf -> adapter -> ports .lock );
2939
+
2940
+ return 0 ;
2941
+ }
2942
+
2943
+ static void ice_ptp_cleanup_pf (struct ice_pf * pf )
2944
+ {
2945
+ struct ice_ptp * ptp = & pf -> ptp ;
2946
+
2947
+ if (ice_get_phy_model (& pf -> hw ) != ICE_PHY_UNSUP ) {
2948
+ mutex_lock (& pf -> adapter -> ports .lock );
2949
+ list_del (& ptp -> port .list_node );
2950
+ mutex_unlock (& pf -> adapter -> ports .lock );
2951
+ }
2952
+ }
2909
2953
/**
2910
2954
* ice_ptp_aux_dev_to_aux_pf - Get auxiliary PF handle for the auxiliary device
2911
2955
* @aux_dev: auxiliary device to get the auxiliary PF for
@@ -2957,9 +3001,9 @@ static int ice_ptp_auxbus_probe(struct auxiliary_device *aux_dev,
2957
3001
if (WARN_ON (!owner_pf ))
2958
3002
return - ENODEV ;
2959
3003
2960
- INIT_LIST_HEAD (& aux_pf -> ptp .port .list_member );
3004
+ INIT_LIST_HEAD (& aux_pf -> ptp .port .list_node );
2961
3005
mutex_lock (& owner_pf -> ptp .ports_owner .lock );
2962
- list_add (& aux_pf -> ptp .port .list_member ,
3006
+ list_add (& aux_pf -> ptp .port .list_node ,
2963
3007
& owner_pf -> ptp .ports_owner .ports );
2964
3008
mutex_unlock (& owner_pf -> ptp .ports_owner .lock );
2965
3009
@@ -2976,7 +3020,7 @@ static void ice_ptp_auxbus_remove(struct auxiliary_device *aux_dev)
2976
3020
struct ice_pf * aux_pf = ice_ptp_aux_dev_to_aux_pf (aux_dev );
2977
3021
2978
3022
mutex_lock (& owner_pf -> ptp .ports_owner .lock );
2979
- list_del (& aux_pf -> ptp .port .list_member );
3023
+ list_del (& aux_pf -> ptp .port .list_node );
2980
3024
mutex_unlock (& owner_pf -> ptp .ports_owner .lock );
2981
3025
}
2982
3026
@@ -3036,7 +3080,7 @@ ice_ptp_auxbus_create_id_table(struct ice_pf *pf, const char *name)
3036
3080
* ice_ptp_register_auxbus_driver - Register PTP auxiliary bus driver
3037
3081
* @pf: Board private structure
3038
3082
*/
3039
- static int ice_ptp_register_auxbus_driver (struct ice_pf * pf )
3083
+ static int __always_unused ice_ptp_register_auxbus_driver (struct ice_pf * pf )
3040
3084
{
3041
3085
struct auxiliary_driver * aux_driver ;
3042
3086
struct ice_ptp * ptp ;
@@ -3079,7 +3123,7 @@ static int ice_ptp_register_auxbus_driver(struct ice_pf *pf)
3079
3123
* ice_ptp_unregister_auxbus_driver - Unregister PTP auxiliary bus driver
3080
3124
* @pf: Board private structure
3081
3125
*/
3082
- static void ice_ptp_unregister_auxbus_driver (struct ice_pf * pf )
3126
+ static void __always_unused ice_ptp_unregister_auxbus_driver (struct ice_pf * pf )
3083
3127
{
3084
3128
struct auxiliary_driver * aux_driver = & pf -> ptp .ports_owner .aux_driver ;
3085
3129
@@ -3098,15 +3142,12 @@ static void ice_ptp_unregister_auxbus_driver(struct ice_pf *pf)
3098
3142
*/
3099
3143
int ice_ptp_clock_index (struct ice_pf * pf )
3100
3144
{
3101
- struct auxiliary_device * aux_dev ;
3102
- struct ice_pf * owner_pf ;
3145
+ struct ice_ptp * ctrl_ptp = ice_get_ctrl_ptp (pf );
3103
3146
struct ptp_clock * clock ;
3104
3147
3105
- aux_dev = & pf -> ptp .port .aux_dev ;
3106
- owner_pf = ice_ptp_aux_dev_to_owner_pf (aux_dev );
3107
- if (!owner_pf )
3148
+ if (!ctrl_ptp )
3108
3149
return -1 ;
3109
- clock = owner_pf -> ptp . clock ;
3150
+ clock = ctrl_ptp -> clock ;
3110
3151
3111
3152
return clock ? ptp_clock_index (clock ) : -1 ;
3112
3153
}
@@ -3166,15 +3207,7 @@ static int ice_ptp_init_owner(struct ice_pf *pf)
3166
3207
if (err )
3167
3208
goto err_clk ;
3168
3209
3169
- err = ice_ptp_register_auxbus_driver (pf );
3170
- if (err ) {
3171
- dev_err (ice_pf_to_dev (pf ), "Failed to register PTP auxbus driver" );
3172
- goto err_aux ;
3173
- }
3174
-
3175
3210
return 0 ;
3176
- err_aux :
3177
- ptp_clock_unregister (pf -> ptp .clock );
3178
3211
err_clk :
3179
3212
pf -> ptp .clock = NULL ;
3180
3213
err_exit :
@@ -3250,7 +3283,7 @@ static void ice_ptp_release_auxbus_device(struct device *dev)
3250
3283
* ice_ptp_create_auxbus_device - Create PTP auxiliary bus device
3251
3284
* @pf: Board private structure
3252
3285
*/
3253
- static int ice_ptp_create_auxbus_device (struct ice_pf * pf )
3286
+ static __always_unused int ice_ptp_create_auxbus_device (struct ice_pf * pf )
3254
3287
{
3255
3288
struct auxiliary_device * aux_dev ;
3256
3289
struct ice_ptp * ptp ;
@@ -3297,7 +3330,7 @@ static int ice_ptp_create_auxbus_device(struct ice_pf *pf)
3297
3330
* ice_ptp_remove_auxbus_device - Remove PTP auxiliary bus device
3298
3331
* @pf: Board private structure
3299
3332
*/
3300
- static void ice_ptp_remove_auxbus_device (struct ice_pf * pf )
3333
+ static __always_unused void ice_ptp_remove_auxbus_device (struct ice_pf * pf )
3301
3334
{
3302
3335
struct auxiliary_device * aux_dev = & pf -> ptp .port .aux_dev ;
3303
3336
@@ -3361,40 +3394,43 @@ void ice_ptp_init(struct ice_pf *pf)
3361
3394
/* If this function owns the clock hardware, it must allocate and
3362
3395
* configure the PTP clock device to represent it.
3363
3396
*/
3364
- if (ice_pf_src_tmr_owned (pf )) {
3397
+ if (ice_pf_src_tmr_owned (pf ) && ice_is_primary (hw )) {
3398
+ err = ice_ptp_setup_adapter (pf );
3399
+ if (err )
3400
+ goto err_exit ;
3365
3401
err = ice_ptp_init_owner (pf );
3366
3402
if (err )
3367
- goto err ;
3403
+ goto err_exit ;
3368
3404
}
3369
3405
3406
+ err = ice_ptp_setup_pf (pf );
3407
+ if (err )
3408
+ goto err_exit ;
3409
+
3370
3410
ptp -> port .port_num = hw -> pf_id ;
3371
3411
if (ice_is_e825c (hw ) && hw -> ptp .is_2x50g_muxed_topo )
3372
3412
ptp -> port .port_num = hw -> pf_id * 2 ;
3373
3413
3374
3414
err = ice_ptp_init_port (pf , & ptp -> port );
3375
3415
if (err )
3376
- goto err ;
3416
+ goto err_exit ;
3377
3417
3378
3418
/* Start the PHY timestamping block */
3379
3419
ice_ptp_reset_phy_timestamping (pf );
3380
3420
3381
3421
/* Configure initial Tx interrupt settings */
3382
3422
ice_ptp_cfg_tx_interrupt (pf );
3383
3423
3384
- err = ice_ptp_create_auxbus_device (pf );
3385
- if (err )
3386
- goto err ;
3387
-
3388
3424
ptp -> state = ICE_PTP_READY ;
3389
3425
3390
3426
err = ice_ptp_init_work (pf , ptp );
3391
3427
if (err )
3392
- goto err ;
3428
+ goto err_exit ;
3393
3429
3394
3430
dev_info (ice_pf_to_dev (pf ), "PTP init successful\n" );
3395
3431
return ;
3396
3432
3397
- err :
3433
+ err_exit :
3398
3434
/* If we registered a PTP clock, release it */
3399
3435
if (pf -> ptp .clock ) {
3400
3436
ptp_clock_unregister (ptp -> clock );
@@ -3421,7 +3457,7 @@ void ice_ptp_release(struct ice_pf *pf)
3421
3457
/* Disable timestamping for both Tx and Rx */
3422
3458
ice_ptp_disable_timestamp_mode (pf );
3423
3459
3424
- ice_ptp_remove_auxbus_device (pf );
3460
+ ice_ptp_cleanup_pf (pf );
3425
3461
3426
3462
ice_ptp_release_tx_tracker (pf , & pf -> ptp .port .tx );
3427
3463
@@ -3436,9 +3472,6 @@ void ice_ptp_release(struct ice_pf *pf)
3436
3472
pf -> ptp .kworker = NULL ;
3437
3473
}
3438
3474
3439
- if (ice_pf_src_tmr_owned (pf ))
3440
- ice_ptp_unregister_auxbus_driver (pf );
3441
-
3442
3475
if (!pf -> ptp .clock )
3443
3476
return ;
3444
3477
0 commit comments