Skip to content

Commit e800654

Browse files
stemerkanguy11
authored andcommitted
ice: Use ice_adapter for PTP shared data instead of auxdev
Use struct ice_adapter to hold shared PTP data and control PTP related actions instead of auxbus. This allows significant code simplification and faster access to the container fields used in the PTP support code. Move the PTP port list to the ice_adapter container to simplify the code and avoid race conditions which could occur due to the synchronous nature of the initialization/access and certain memory saving can be achieved by moving PTP data into the ice_adapter itself. Signed-off-by: Sergey Temerkhanov <[email protected]> Reviewed-by: Przemek Kitszel <[email protected]> Reviewed-by: Simon Horman <[email protected]> Tested-by: Pucha Himasekhar Reddy <[email protected]> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <[email protected]>
1 parent fdb7f54 commit e800654

File tree

5 files changed

+105
-43
lines changed

5 files changed

+105
-43
lines changed

drivers/net/ethernet/intel/ice/ice_adapter.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,17 @@ static struct ice_adapter *ice_adapter_new(void)
5050
spin_lock_init(&adapter->ptp_gltsyn_time_lock);
5151
refcount_set(&adapter->refcount, 1);
5252

53+
mutex_init(&adapter->ports.lock);
54+
INIT_LIST_HEAD(&adapter->ports.ports);
55+
5356
return adapter;
5457
}
5558

5659
static void ice_adapter_free(struct ice_adapter *adapter)
5760
{
61+
WARN_ON(!list_empty(&adapter->ports.ports));
62+
mutex_destroy(&adapter->ports.lock);
63+
5864
kfree(adapter);
5965
}
6066

drivers/net/ethernet/intel/ice/ice_adapter.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,42 @@
44
#ifndef _ICE_ADAPTER_H_
55
#define _ICE_ADAPTER_H_
66

7+
#include <linux/types.h>
78
#include <linux/spinlock_types.h>
89
#include <linux/refcount_types.h>
910

1011
struct pci_dev;
1112
struct ice_pf;
1213

14+
/**
15+
* struct ice_port_list - data used to store the list of adapter ports
16+
*
17+
* This structure contains data used to maintain a list of adapter ports
18+
*
19+
* @ports: list of ports
20+
* @lock: protect access to the ports list
21+
*/
22+
struct ice_port_list {
23+
struct list_head ports;
24+
/* To synchronize the ports list operations */
25+
struct mutex lock;
26+
};
27+
1328
/**
1429
* struct ice_adapter - PCI adapter resources shared across PFs
1530
* @ptp_gltsyn_time_lock: Spinlock protecting access to the GLTSYN_TIME
1631
* register of the PTP clock.
1732
* @refcount: Reference count. struct ice_pf objects hold the references.
1833
* @ctrl_pf: Control PF of the adapter
34+
* @ports: Ports list
1935
*/
2036
struct ice_adapter {
2137
refcount_t refcount;
2238
/* For access to the GLTSYN_TIME register */
2339
spinlock_t ptp_gltsyn_time_lock;
2440

2541
struct ice_pf *ctrl_pf;
42+
struct ice_port_list ports;
2643
};
2744

2845
struct ice_adapter *ice_adapter_get(const struct pci_dev *pdev);

drivers/net/ethernet/intel/ice/ice_ptp.c

Lines changed: 74 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -734,16 +734,16 @@ static enum ice_tx_tstamp_work ice_ptp_tx_tstamp_owner(struct ice_pf *pf)
734734
struct ice_ptp_port *port;
735735
unsigned int i;
736736

737-
mutex_lock(&pf->ptp.ports_owner.lock);
738-
list_for_each_entry(port, &pf->ptp.ports_owner.ports, list_member) {
737+
mutex_lock(&pf->adapter->ports.lock);
738+
list_for_each_entry(port, &pf->adapter->ports.ports, list_node) {
739739
struct ice_ptp_tx *tx = &port->tx;
740740

741741
if (!tx || !tx->init)
742742
continue;
743743

744744
ice_ptp_process_tx_tstamp(tx);
745745
}
746-
mutex_unlock(&pf->ptp.ports_owner.lock);
746+
mutex_unlock(&pf->adapter->ports.lock);
747747

748748
for (i = 0; i < ICE_GET_QUAD_NUM(pf->hw.ptp.num_lports); i++) {
749749
u64 tstamp_ready;
@@ -908,7 +908,7 @@ ice_ptp_flush_all_tx_tracker(struct ice_pf *pf)
908908
{
909909
struct ice_ptp_port *port;
910910

911-
list_for_each_entry(port, &pf->ptp.ports_owner.ports, list_member)
911+
list_for_each_entry(port, &pf->adapter->ports.ports, list_node)
912912
ice_ptp_flush_tx_tracker(ptp_port_to_pf(port), &port->tx);
913913
}
914914

@@ -1508,10 +1508,10 @@ static void ice_ptp_restart_all_phy(struct ice_pf *pf)
15081508
{
15091509
struct list_head *entry;
15101510

1511-
list_for_each(entry, &pf->ptp.ports_owner.ports) {
1511+
list_for_each(entry, &pf->adapter->ports.ports) {
15121512
struct ice_ptp_port *port = list_entry(entry,
15131513
struct ice_ptp_port,
1514-
list_member);
1514+
list_node);
15151515

15161516
if (port->link_up)
15171517
ice_ptp_port_phy_restart(port);
@@ -2939,6 +2939,50 @@ void ice_ptp_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
29392939
dev_err(ice_pf_to_dev(pf), "PTP reset failed %d\n", err);
29402940
}
29412941

2942+
static bool ice_is_primary(struct ice_hw *hw)
2943+
{
2944+
return ice_is_e825c(hw) && ice_is_dual(hw) ?
2945+
!!(hw->dev_caps.nac_topo.mode & ICE_NAC_TOPO_PRIMARY_M) : true;
2946+
}
2947+
2948+
static int ice_ptp_setup_adapter(struct ice_pf *pf)
2949+
{
2950+
if (!ice_pf_src_tmr_owned(pf) || !ice_is_primary(&pf->hw))
2951+
return -EPERM;
2952+
2953+
pf->adapter->ctrl_pf = pf;
2954+
2955+
return 0;
2956+
}
2957+
2958+
static int ice_ptp_setup_pf(struct ice_pf *pf)
2959+
{
2960+
struct ice_ptp *ctrl_ptp = ice_get_ctrl_ptp(pf);
2961+
struct ice_ptp *ptp = &pf->ptp;
2962+
2963+
if (WARN_ON(!ctrl_ptp) || ice_get_phy_model(&pf->hw) == ICE_PHY_UNSUP)
2964+
return -ENODEV;
2965+
2966+
INIT_LIST_HEAD(&ptp->port.list_node);
2967+
mutex_lock(&pf->adapter->ports.lock);
2968+
2969+
list_add(&ptp->port.list_node,
2970+
&pf->adapter->ports.ports);
2971+
mutex_unlock(&pf->adapter->ports.lock);
2972+
2973+
return 0;
2974+
}
2975+
2976+
static void ice_ptp_cleanup_pf(struct ice_pf *pf)
2977+
{
2978+
struct ice_ptp *ptp = &pf->ptp;
2979+
2980+
if (ice_get_phy_model(&pf->hw) != ICE_PHY_UNSUP) {
2981+
mutex_lock(&pf->adapter->ports.lock);
2982+
list_del(&ptp->port.list_node);
2983+
mutex_unlock(&pf->adapter->ports.lock);
2984+
}
2985+
}
29422986
/**
29432987
* ice_ptp_aux_dev_to_aux_pf - Get auxiliary PF handle for the auxiliary device
29442988
* @aux_dev: auxiliary device to get the auxiliary PF for
@@ -2990,9 +3034,9 @@ static int ice_ptp_auxbus_probe(struct auxiliary_device *aux_dev,
29903034
if (WARN_ON(!owner_pf))
29913035
return -ENODEV;
29923036

2993-
INIT_LIST_HEAD(&aux_pf->ptp.port.list_member);
3037+
INIT_LIST_HEAD(&aux_pf->ptp.port.list_node);
29943038
mutex_lock(&owner_pf->ptp.ports_owner.lock);
2995-
list_add(&aux_pf->ptp.port.list_member,
3039+
list_add(&aux_pf->ptp.port.list_node,
29963040
&owner_pf->ptp.ports_owner.ports);
29973041
mutex_unlock(&owner_pf->ptp.ports_owner.lock);
29983042

@@ -3009,7 +3053,7 @@ static void ice_ptp_auxbus_remove(struct auxiliary_device *aux_dev)
30093053
struct ice_pf *aux_pf = ice_ptp_aux_dev_to_aux_pf(aux_dev);
30103054

30113055
mutex_lock(&owner_pf->ptp.ports_owner.lock);
3012-
list_del(&aux_pf->ptp.port.list_member);
3056+
list_del(&aux_pf->ptp.port.list_node);
30133057
mutex_unlock(&owner_pf->ptp.ports_owner.lock);
30143058
}
30153059

@@ -3069,7 +3113,7 @@ ice_ptp_auxbus_create_id_table(struct ice_pf *pf, const char *name)
30693113
* ice_ptp_register_auxbus_driver - Register PTP auxiliary bus driver
30703114
* @pf: Board private structure
30713115
*/
3072-
static int ice_ptp_register_auxbus_driver(struct ice_pf *pf)
3116+
static int __always_unused ice_ptp_register_auxbus_driver(struct ice_pf *pf)
30733117
{
30743118
struct auxiliary_driver *aux_driver;
30753119
struct ice_ptp *ptp;
@@ -3112,7 +3156,7 @@ static int ice_ptp_register_auxbus_driver(struct ice_pf *pf)
31123156
* ice_ptp_unregister_auxbus_driver - Unregister PTP auxiliary bus driver
31133157
* @pf: Board private structure
31143158
*/
3115-
static void ice_ptp_unregister_auxbus_driver(struct ice_pf *pf)
3159+
static void __always_unused ice_ptp_unregister_auxbus_driver(struct ice_pf *pf)
31163160
{
31173161
struct auxiliary_driver *aux_driver = &pf->ptp.ports_owner.aux_driver;
31183162

@@ -3131,15 +3175,12 @@ static void ice_ptp_unregister_auxbus_driver(struct ice_pf *pf)
31313175
*/
31323176
int ice_ptp_clock_index(struct ice_pf *pf)
31333177
{
3134-
struct auxiliary_device *aux_dev;
3135-
struct ice_pf *owner_pf;
3178+
struct ice_ptp *ctrl_ptp = ice_get_ctrl_ptp(pf);
31363179
struct ptp_clock *clock;
31373180

3138-
aux_dev = &pf->ptp.port.aux_dev;
3139-
owner_pf = ice_ptp_aux_dev_to_owner_pf(aux_dev);
3140-
if (!owner_pf)
3181+
if (!ctrl_ptp)
31413182
return -1;
3142-
clock = owner_pf->ptp.clock;
3183+
clock = ctrl_ptp->clock;
31433184

31443185
return clock ? ptp_clock_index(clock) : -1;
31453186
}
@@ -3199,15 +3240,7 @@ static int ice_ptp_init_owner(struct ice_pf *pf)
31993240
if (err)
32003241
goto err_clk;
32013242

3202-
err = ice_ptp_register_auxbus_driver(pf);
3203-
if (err) {
3204-
dev_err(ice_pf_to_dev(pf), "Failed to register PTP auxbus driver");
3205-
goto err_aux;
3206-
}
3207-
32083243
return 0;
3209-
err_aux:
3210-
ptp_clock_unregister(pf->ptp.clock);
32113244
err_clk:
32123245
pf->ptp.clock = NULL;
32133246
err_exit:
@@ -3283,7 +3316,7 @@ static void ice_ptp_release_auxbus_device(struct device *dev)
32833316
* ice_ptp_create_auxbus_device - Create PTP auxiliary bus device
32843317
* @pf: Board private structure
32853318
*/
3286-
static int ice_ptp_create_auxbus_device(struct ice_pf *pf)
3319+
static __always_unused int ice_ptp_create_auxbus_device(struct ice_pf *pf)
32873320
{
32883321
struct auxiliary_device *aux_dev;
32893322
struct ice_ptp *ptp;
@@ -3330,7 +3363,7 @@ static int ice_ptp_create_auxbus_device(struct ice_pf *pf)
33303363
* ice_ptp_remove_auxbus_device - Remove PTP auxiliary bus device
33313364
* @pf: Board private structure
33323365
*/
3333-
static void ice_ptp_remove_auxbus_device(struct ice_pf *pf)
3366+
static __always_unused void ice_ptp_remove_auxbus_device(struct ice_pf *pf)
33343367
{
33353368
struct auxiliary_device *aux_dev = &pf->ptp.port.aux_dev;
33363369

@@ -3394,40 +3427,43 @@ void ice_ptp_init(struct ice_pf *pf)
33943427
/* If this function owns the clock hardware, it must allocate and
33953428
* configure the PTP clock device to represent it.
33963429
*/
3397-
if (ice_pf_src_tmr_owned(pf)) {
3430+
if (ice_pf_src_tmr_owned(pf) && ice_is_primary(hw)) {
3431+
err = ice_ptp_setup_adapter(pf);
3432+
if (err)
3433+
goto err_exit;
33983434
err = ice_ptp_init_owner(pf);
33993435
if (err)
3400-
goto err;
3436+
goto err_exit;
34013437
}
34023438

3439+
err = ice_ptp_setup_pf(pf);
3440+
if (err)
3441+
goto err_exit;
3442+
34033443
ptp->port.port_num = hw->pf_id;
34043444
if (ice_is_e825c(hw) && hw->ptp.is_2x50g_muxed_topo)
34053445
ptp->port.port_num = hw->pf_id * 2;
34063446

34073447
err = ice_ptp_init_port(pf, &ptp->port);
34083448
if (err)
3409-
goto err;
3449+
goto err_exit;
34103450

34113451
/* Start the PHY timestamping block */
34123452
ice_ptp_reset_phy_timestamping(pf);
34133453

34143454
/* Configure initial Tx interrupt settings */
34153455
ice_ptp_cfg_tx_interrupt(pf);
34163456

3417-
err = ice_ptp_create_auxbus_device(pf);
3418-
if (err)
3419-
goto err;
3420-
34213457
ptp->state = ICE_PTP_READY;
34223458

34233459
err = ice_ptp_init_work(pf, ptp);
34243460
if (err)
3425-
goto err;
3461+
goto err_exit;
34263462

34273463
dev_info(ice_pf_to_dev(pf), "PTP init successful\n");
34283464
return;
34293465

3430-
err:
3466+
err_exit:
34313467
/* If we registered a PTP clock, release it */
34323468
if (pf->ptp.clock) {
34333469
ptp_clock_unregister(ptp->clock);
@@ -3454,7 +3490,7 @@ void ice_ptp_release(struct ice_pf *pf)
34543490
/* Disable timestamping for both Tx and Rx */
34553491
ice_ptp_disable_timestamp_mode(pf);
34563492

3457-
ice_ptp_remove_auxbus_device(pf);
3493+
ice_ptp_cleanup_pf(pf);
34583494

34593495
ice_ptp_release_tx_tracker(pf, &pf->ptp.port.tx);
34603496

@@ -3469,9 +3505,6 @@ void ice_ptp_release(struct ice_pf *pf)
34693505
pf->ptp.kworker = NULL;
34703506
}
34713507

3472-
if (ice_pf_src_tmr_owned(pf))
3473-
ice_ptp_unregister_auxbus_driver(pf);
3474-
34753508
if (!pf->ptp.clock)
34763509
return;
34773510

drivers/net/ethernet/intel/ice/ice_ptp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ struct ice_ptp_tx {
138138
* ready for PTP functionality. It is used to track the port initialization
139139
* and determine when the port's PHY offset is valid.
140140
*
141-
* @list_member: list member structure of auxiliary device
141+
* @list_node: list member structure
142142
* @tx: Tx timestamp tracking for this port
143143
* @aux_dev: auxiliary device associated with this port
144144
* @ov_work: delayed work task for tracking when PHY offset is valid
@@ -148,7 +148,7 @@ struct ice_ptp_tx {
148148
* @port_num: the port number this structure represents
149149
*/
150150
struct ice_ptp_port {
151-
struct list_head list_member;
151+
struct list_head list_node;
152152
struct ice_ptp_tx tx;
153153
struct auxiliary_device aux_dev;
154154
struct kthread_delayed_work ov_work;
@@ -174,6 +174,7 @@ enum ice_ptp_tx_interrupt {
174174
* @ports: list of porst handled by this port owner
175175
* @lock: protect access to ports list
176176
*/
177+
177178
struct ice_ptp_port_owner {
178179
struct auxiliary_driver aux_driver;
179180
struct list_head ports;

drivers/net/ethernet/intel/ice/ice_ptp_hw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,11 @@ static inline u64 ice_get_base_incval(struct ice_hw *hw)
468468
}
469469
}
470470

471+
static inline bool ice_is_dual(struct ice_hw *hw)
472+
{
473+
return !!(hw->dev_caps.nac_topo.mode & ICE_NAC_TOPO_DUAL_M);
474+
}
475+
471476
#define PFTSYN_SEM_BYTES 4
472477

473478
#define ICE_PTP_CLOCK_INDEX_0 0x00

0 commit comments

Comments
 (0)