Skip to content

Commit e8e0827

Browse files
Amit Cohenkuba-moo
authored andcommitted
mlxsw: Initialize txhdr_info according to PTP operations
A next patch will construct Tx header as part of pci.c. The switch driver (mlxsw_spectrum.ko) should encapsulate all the differences between the different ASICs and the bus driver (mlxsw_pci.ko) should remain unaware. As preparation, add the relevant info as part of mlxsw_txhdr_info structure, so later bus driver will merely construct the Tx header based on information passed from the switch driver. Most of the packets are transmitted as control packets, but PTP packets in Spectrum-2 and Spectrum-3 should be handled differently. The driver transmits them as data packets, and the default VLAN tag (4095) is added if the packet is not already tagged. Extend PTP operations to store a boolean which indicates whether packets should be transmitted as data packets. Set it for Spectrum-2 and Spectrum-3 only. Extend mlxsw_txhdr_info to store fields which will be used later to construct Tx header. Initialize such fields according to the new boolean which is stored in PTP operations. Note that for now, mlxsw_txhdr_info structure is initialized, but not used, a next patch will use it. Signed-off-by: Amit Cohen <amcohen@nvidia.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com> Link: https://patch.msgid.link/efcaacd4bedef524e840a0c29f96cebf2c4bc0e0.1737044384.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3498566 commit e8e0827

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

drivers/net/ethernet/mellanox/mlxsw/core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ struct mlxsw_tx_info {
7474

7575
struct mlxsw_txhdr_info {
7676
struct mlxsw_tx_info tx_info;
77+
bool data;
78+
u16 max_fid; /* Used for PTP packets which are sent as data. */
7779
};
7880

7981
struct mlxsw_rx_md_info {

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,33 @@ static bool mlxsw_sp_skb_requires_ts(struct sk_buff *skb)
299299
return !!ptp_parse_header(skb, type);
300300
}
301301

302+
static void mlxsw_sp_txhdr_info_data_init(struct mlxsw_core *mlxsw_core,
303+
struct sk_buff *skb,
304+
struct mlxsw_txhdr_info *txhdr_info)
305+
{
306+
/* Resource validation was done as part of PTP init. */
307+
u16 max_fid = MLXSW_CORE_RES_GET(mlxsw_core, FID);
308+
309+
txhdr_info->data = true;
310+
txhdr_info->max_fid = max_fid;
311+
}
312+
313+
static void
314+
mlxsw_sp_txhdr_preparations(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
315+
struct mlxsw_txhdr_info *txhdr_info)
316+
{
317+
if (likely(!mlxsw_sp_skb_requires_ts(skb)))
318+
return;
319+
320+
if (!mlxsw_sp->ptp_ops->tx_as_data)
321+
return;
322+
323+
/* Special handling for PTP events that require a time stamp and cannot
324+
* be transmitted as regular control packets.
325+
*/
326+
mlxsw_sp_txhdr_info_data_init(mlxsw_sp->core, skb, txhdr_info);
327+
}
328+
302329
static int mlxsw_sp_txhdr_handle(struct mlxsw_core *mlxsw_core,
303330
struct mlxsw_sp_port *mlxsw_sp_port,
304331
struct sk_buff *skb,
@@ -721,7 +748,7 @@ static netdev_tx_t mlxsw_sp_port_xmit(struct sk_buff *skb,
721748
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
722749
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
723750
struct mlxsw_sp_port_pcpu_stats *pcpu_stats;
724-
const struct mlxsw_txhdr_info txhdr_info = {
751+
struct mlxsw_txhdr_info txhdr_info = {
725752
.tx_info.local_port = mlxsw_sp_port->local_port,
726753
.tx_info.is_emad = false,
727754
};
@@ -738,6 +765,8 @@ static netdev_tx_t mlxsw_sp_port_xmit(struct sk_buff *skb,
738765
return NETDEV_TX_OK;
739766
}
740767

768+
mlxsw_sp_txhdr_preparations(mlxsw_sp, skb, &txhdr_info);
769+
741770
err = mlxsw_sp_txhdr_handle(mlxsw_sp->core, mlxsw_sp_port, skb,
742771
&txhdr_info.tx_info);
743772
if (err)
@@ -2812,6 +2841,7 @@ static const struct mlxsw_sp_ptp_ops mlxsw_sp2_ptp_ops = {
28122841
.get_stats_strings = mlxsw_sp2_get_stats_strings,
28132842
.get_stats = mlxsw_sp2_get_stats,
28142843
.txhdr_construct = mlxsw_sp2_ptp_txhdr_construct,
2844+
.tx_as_data = true,
28152845
};
28162846

28172847
static const struct mlxsw_sp_ptp_ops mlxsw_sp4_ptp_ops = {

drivers/net/ethernet/mellanox/mlxsw/spectrum.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ struct mlxsw_sp_ptp_ops {
247247
struct mlxsw_sp_port *mlxsw_sp_port,
248248
struct sk_buff *skb,
249249
const struct mlxsw_tx_info *tx_info);
250+
bool tx_as_data;
250251
};
251252

252253
struct mlxsw_sp_fid_core_ops {

drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,10 @@ struct mlxsw_sp_ptp_state *mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
13531353
struct mlxsw_sp2_ptp_state *ptp_state;
13541354
int err;
13551355

1356+
/* Max FID will be used in data path, check validity as part of init. */
1357+
if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, FID))
1358+
return ERR_PTR(-EIO);
1359+
13561360
ptp_state = kzalloc(sizeof(*ptp_state), GFP_KERNEL);
13571361
if (!ptp_state)
13581362
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)