Skip to content

Commit 09d2229

Browse files
stemerkjfvogel
authored andcommitted
ice: Use ice_adapter for PTP shared data instead of auxdev
[ Upstream commit e800654 ] 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]> Stable-dep-of: 258f5f9 ("ice: Add correct PHY lane assignment") Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 2f59743be4d9568cad2d9cf697d1b897975421ed) Signed-off-by: Jack Vogel <[email protected]>
1 parent 8f80a5c commit 09d2229

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
@@ -40,11 +40,17 @@ static struct ice_adapter *ice_adapter_new(void)
4040
spin_lock_init(&adapter->ptp_gltsyn_time_lock);
4141
refcount_set(&adapter->refcount, 1);
4242

43+
mutex_init(&adapter->ports.lock);
44+
INIT_LIST_HEAD(&adapter->ports.ports);
45+
4346
return adapter;
4447
}
4548

4649
static void ice_adapter_free(struct ice_adapter *adapter)
4750
{
51+
WARN_ON(!list_empty(&adapter->ports.ports));
52+
mutex_destroy(&adapter->ports.lock);
53+
4854
kfree(adapter);
4955
}
5056

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
@@ -21,7 +21,7 @@ static struct ice_pf *ice_get_ctrl_pf(struct ice_pf *pf)
2121
return !pf->adapter ? NULL : pf->adapter->ctrl_pf;
2222
}
2323

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)
2525
{
2626
struct ice_pf *ctrl_pf = ice_get_ctrl_pf(pf);
2727

@@ -812,16 +812,16 @@ static enum ice_tx_tstamp_work ice_ptp_tx_tstamp_owner(struct ice_pf *pf)
812812
struct ice_ptp_port *port;
813813
unsigned int i;
814814

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) {
817817
struct ice_ptp_tx *tx = &port->tx;
818818

819819
if (!tx || !tx->init)
820820
continue;
821821

822822
ice_ptp_process_tx_tstamp(tx);
823823
}
824-
mutex_unlock(&pf->ptp.ports_owner.lock);
824+
mutex_unlock(&pf->adapter->ports.lock);
825825

826826
for (i = 0; i < ICE_GET_QUAD_NUM(pf->hw.ptp.num_lports); i++) {
827827
u64 tstamp_ready;
@@ -986,7 +986,7 @@ ice_ptp_flush_all_tx_tracker(struct ice_pf *pf)
986986
{
987987
struct ice_ptp_port *port;
988988

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)
990990
ice_ptp_flush_tx_tracker(ptp_port_to_pf(port), &port->tx);
991991
}
992992

@@ -1586,10 +1586,10 @@ static void ice_ptp_restart_all_phy(struct ice_pf *pf)
15861586
{
15871587
struct list_head *entry;
15881588

1589-
list_for_each(entry, &pf->ptp.ports_owner.ports) {
1589+
list_for_each(entry, &pf->adapter->ports.ports) {
15901590
struct ice_ptp_port *port = list_entry(entry,
15911591
struct ice_ptp_port,
1592-
list_member);
1592+
list_node);
15931593

15941594
if (port->link_up)
15951595
ice_ptp_port_phy_restart(port);
@@ -2906,6 +2906,50 @@ void ice_ptp_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
29062906
dev_err(ice_pf_to_dev(pf), "PTP reset failed %d\n", err);
29072907
}
29082908

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+
}
29092953
/**
29102954
* ice_ptp_aux_dev_to_aux_pf - Get auxiliary PF handle for the auxiliary device
29112955
* @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,
29573001
if (WARN_ON(!owner_pf))
29583002
return -ENODEV;
29593003

2960-
INIT_LIST_HEAD(&aux_pf->ptp.port.list_member);
3004+
INIT_LIST_HEAD(&aux_pf->ptp.port.list_node);
29613005
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,
29633007
&owner_pf->ptp.ports_owner.ports);
29643008
mutex_unlock(&owner_pf->ptp.ports_owner.lock);
29653009

@@ -2976,7 +3020,7 @@ static void ice_ptp_auxbus_remove(struct auxiliary_device *aux_dev)
29763020
struct ice_pf *aux_pf = ice_ptp_aux_dev_to_aux_pf(aux_dev);
29773021

29783022
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);
29803024
mutex_unlock(&owner_pf->ptp.ports_owner.lock);
29813025
}
29823026

@@ -3036,7 +3080,7 @@ ice_ptp_auxbus_create_id_table(struct ice_pf *pf, const char *name)
30363080
* ice_ptp_register_auxbus_driver - Register PTP auxiliary bus driver
30373081
* @pf: Board private structure
30383082
*/
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)
30403084
{
30413085
struct auxiliary_driver *aux_driver;
30423086
struct ice_ptp *ptp;
@@ -3079,7 +3123,7 @@ static int ice_ptp_register_auxbus_driver(struct ice_pf *pf)
30793123
* ice_ptp_unregister_auxbus_driver - Unregister PTP auxiliary bus driver
30803124
* @pf: Board private structure
30813125
*/
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)
30833127
{
30843128
struct auxiliary_driver *aux_driver = &pf->ptp.ports_owner.aux_driver;
30853129

@@ -3098,15 +3142,12 @@ static void ice_ptp_unregister_auxbus_driver(struct ice_pf *pf)
30983142
*/
30993143
int ice_ptp_clock_index(struct ice_pf *pf)
31003144
{
3101-
struct auxiliary_device *aux_dev;
3102-
struct ice_pf *owner_pf;
3145+
struct ice_ptp *ctrl_ptp = ice_get_ctrl_ptp(pf);
31033146
struct ptp_clock *clock;
31043147

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)
31083149
return -1;
3109-
clock = owner_pf->ptp.clock;
3150+
clock = ctrl_ptp->clock;
31103151

31113152
return clock ? ptp_clock_index(clock) : -1;
31123153
}
@@ -3166,15 +3207,7 @@ static int ice_ptp_init_owner(struct ice_pf *pf)
31663207
if (err)
31673208
goto err_clk;
31683209

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-
31753210
return 0;
3176-
err_aux:
3177-
ptp_clock_unregister(pf->ptp.clock);
31783211
err_clk:
31793212
pf->ptp.clock = NULL;
31803213
err_exit:
@@ -3250,7 +3283,7 @@ static void ice_ptp_release_auxbus_device(struct device *dev)
32503283
* ice_ptp_create_auxbus_device - Create PTP auxiliary bus device
32513284
* @pf: Board private structure
32523285
*/
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)
32543287
{
32553288
struct auxiliary_device *aux_dev;
32563289
struct ice_ptp *ptp;
@@ -3297,7 +3330,7 @@ static int ice_ptp_create_auxbus_device(struct ice_pf *pf)
32973330
* ice_ptp_remove_auxbus_device - Remove PTP auxiliary bus device
32983331
* @pf: Board private structure
32993332
*/
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)
33013334
{
33023335
struct auxiliary_device *aux_dev = &pf->ptp.port.aux_dev;
33033336

@@ -3361,40 +3394,43 @@ void ice_ptp_init(struct ice_pf *pf)
33613394
/* If this function owns the clock hardware, it must allocate and
33623395
* configure the PTP clock device to represent it.
33633396
*/
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;
33653401
err = ice_ptp_init_owner(pf);
33663402
if (err)
3367-
goto err;
3403+
goto err_exit;
33683404
}
33693405

3406+
err = ice_ptp_setup_pf(pf);
3407+
if (err)
3408+
goto err_exit;
3409+
33703410
ptp->port.port_num = hw->pf_id;
33713411
if (ice_is_e825c(hw) && hw->ptp.is_2x50g_muxed_topo)
33723412
ptp->port.port_num = hw->pf_id * 2;
33733413

33743414
err = ice_ptp_init_port(pf, &ptp->port);
33753415
if (err)
3376-
goto err;
3416+
goto err_exit;
33773417

33783418
/* Start the PHY timestamping block */
33793419
ice_ptp_reset_phy_timestamping(pf);
33803420

33813421
/* Configure initial Tx interrupt settings */
33823422
ice_ptp_cfg_tx_interrupt(pf);
33833423

3384-
err = ice_ptp_create_auxbus_device(pf);
3385-
if (err)
3386-
goto err;
3387-
33883424
ptp->state = ICE_PTP_READY;
33893425

33903426
err = ice_ptp_init_work(pf, ptp);
33913427
if (err)
3392-
goto err;
3428+
goto err_exit;
33933429

33943430
dev_info(ice_pf_to_dev(pf), "PTP init successful\n");
33953431
return;
33963432

3397-
err:
3433+
err_exit:
33983434
/* If we registered a PTP clock, release it */
33993435
if (pf->ptp.clock) {
34003436
ptp_clock_unregister(ptp->clock);
@@ -3421,7 +3457,7 @@ void ice_ptp_release(struct ice_pf *pf)
34213457
/* Disable timestamping for both Tx and Rx */
34223458
ice_ptp_disable_timestamp_mode(pf);
34233459

3424-
ice_ptp_remove_auxbus_device(pf);
3460+
ice_ptp_cleanup_pf(pf);
34253461

34263462
ice_ptp_release_tx_tracker(pf, &pf->ptp.port.tx);
34273463

@@ -3436,9 +3472,6 @@ void ice_ptp_release(struct ice_pf *pf)
34363472
pf->ptp.kworker = NULL;
34373473
}
34383474

3439-
if (ice_pf_src_tmr_owned(pf))
3440-
ice_ptp_unregister_auxbus_driver(pf);
3441-
34423475
if (!pf->ptp.clock)
34433476
return;
34443477

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct ice_ptp_tx {
169169
* ready for PTP functionality. It is used to track the port initialization
170170
* and determine when the port's PHY offset is valid.
171171
*
172-
* @list_member: list member structure of auxiliary device
172+
* @list_node: list member structure
173173
* @tx: Tx timestamp tracking for this port
174174
* @aux_dev: auxiliary device associated with this port
175175
* @ov_work: delayed work task for tracking when PHY offset is valid
@@ -179,7 +179,7 @@ struct ice_ptp_tx {
179179
* @port_num: the port number this structure represents
180180
*/
181181
struct ice_ptp_port {
182-
struct list_head list_member;
182+
struct list_head list_node;
183183
struct ice_ptp_tx tx;
184184
struct auxiliary_device aux_dev;
185185
struct kthread_delayed_work ov_work;
@@ -205,6 +205,7 @@ enum ice_ptp_tx_interrupt {
205205
* @ports: list of porst handled by this port owner
206206
* @lock: protect access to ports list
207207
*/
208+
208209
struct ice_ptp_port_owner {
209210
struct auxiliary_driver aux_driver;
210211
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
@@ -452,6 +452,11 @@ static inline u64 ice_get_base_incval(struct ice_hw *hw)
452452
}
453453
}
454454

455+
static inline bool ice_is_dual(struct ice_hw *hw)
456+
{
457+
return !!(hw->dev_caps.nac_topo.mode & ICE_NAC_TOPO_DUAL_M);
458+
}
459+
455460
#define PFTSYN_SEM_BYTES 4
456461

457462
#define ICE_PTP_CLOCK_INDEX_0 0x00

0 commit comments

Comments
 (0)