Skip to content

Commit 9f8a7c6

Browse files
committed
ice: Use ice_adapter for PTP shared data instead of auxdev
JIRA: https://issues.redhat.com/browse/RHEL-29207 Conflicts: - adjusted context conflict in ice_ptp_hw.h due to already applied 258f5f9 ("ice: Add correct PHY lane assignment") Upstream commit(s): commit e800654 Author: Sergey Temerkhanov <[email protected]> Date: Wed Aug 21 15:09:56 2024 +0200 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]> Signed-off-by: Petr Oros <[email protected]>
1 parent 1228b09 commit 9f8a7c6

File tree

5 files changed

+106
-44
lines changed

5 files changed

+106
-44
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.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: 75 additions & 42 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

@@ -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
*/
31503194
int 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);
32293262
err_clk:
32303263
pf->ptp.clock = NULL;
32313264
err_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

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)