Skip to content

Commit 19e1e17

Browse files
committed
Merge branch 'mlxsw-move-tx-header-handling-to-pci-driver'
Petr Machata says: ==================== mlxsw: Move Tx header handling to PCI driver Amit Cohen writes: Tx header should be added to all packets transmitted from the CPU to Spectrum ASICs. Historically, handling this header was added as a driver function, as Tx header is different between Spectrum and Switch-X. From May 2021, there is no support for SwitchX-2 ASIC, and all the relevant code was removed. For now, there is no justification to handle Tx header as part of spectrum.c, we can handle this as part of PCI, in skb_transmit(). This change will also be useful when XDP support will be added to mlxsw, as for XDP_TX and XDP_REDIRECT actions, Tx header should be added before transmitting the packet. Patch set overview: Patches Rust-for-Linux#1-Rust-for-Linux#2 add structure to store Tx header info and initialize it Patch Rust-for-Linux#3 moves definitions of Tx header fields to txheader.h Patch Rust-for-Linux#4 moves Tx header handling to PCI driver Patch Rust-for-Linux#5 removes unnecessary attribute ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 41c5d10 + 448269f commit 19e1e17

File tree

9 files changed

+176
-259
lines changed

9 files changed

+176
-259
lines changed

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

+10-11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "reg.h"
3636
#include "resources.h"
3737
#include "../mlxfw/mlxfw.h"
38+
#include "txheader.h"
3839

3940
static LIST_HEAD(mlxsw_core_driver_list);
4041
static DEFINE_SPINLOCK(mlxsw_core_driver_list_lock);
@@ -677,7 +678,7 @@ struct mlxsw_reg_trans {
677678
struct list_head bulk_list;
678679
struct mlxsw_core *core;
679680
struct sk_buff *tx_skb;
680-
struct mlxsw_tx_info tx_info;
681+
struct mlxsw_txhdr_info txhdr_info;
681682
struct delayed_work timeout_dw;
682683
unsigned int retries;
683684
u64 tid;
@@ -737,12 +738,11 @@ static int mlxsw_emad_transmit(struct mlxsw_core *mlxsw_core,
737738
if (!skb)
738739
return -ENOMEM;
739740

740-
trace_devlink_hwmsg(priv_to_devlink(mlxsw_core), false, 0,
741-
skb->data + mlxsw_core->driver->txhdr_len,
742-
skb->len - mlxsw_core->driver->txhdr_len);
741+
trace_devlink_hwmsg(priv_to_devlink(mlxsw_core), false, 0, skb->data,
742+
skb->len);
743743

744744
atomic_set(&trans->active, 1);
745-
err = mlxsw_core_skb_transmit(mlxsw_core, skb, &trans->tx_info);
745+
err = mlxsw_core_skb_transmit(mlxsw_core, skb, &trans->txhdr_info);
746746
if (err) {
747747
dev_kfree_skb(skb);
748748
return err;
@@ -944,7 +944,7 @@ static struct sk_buff *mlxsw_emad_alloc(const struct mlxsw_core *mlxsw_core,
944944

945945
emad_len = (reg_len + sizeof(u32) + MLXSW_EMAD_ETH_HDR_LEN +
946946
(MLXSW_EMAD_OP_TLV_LEN + MLXSW_EMAD_END_TLV_LEN) *
947-
sizeof(u32) + mlxsw_core->driver->txhdr_len);
947+
sizeof(u32) + MLXSW_TXHDR_LEN);
948948
if (mlxsw_core->emad.enable_string_tlv)
949949
emad_len += MLXSW_EMAD_STRING_TLV_LEN * sizeof(u32);
950950
if (mlxsw_core->emad.enable_latency_tlv)
@@ -984,8 +984,8 @@ static int mlxsw_emad_reg_access(struct mlxsw_core *mlxsw_core,
984984
list_add_tail(&trans->bulk_list, bulk_list);
985985
trans->core = mlxsw_core;
986986
trans->tx_skb = skb;
987-
trans->tx_info.local_port = MLXSW_PORT_CPU_PORT;
988-
trans->tx_info.is_emad = true;
987+
trans->txhdr_info.tx_info.local_port = MLXSW_PORT_CPU_PORT;
988+
trans->txhdr_info.tx_info.is_emad = true;
989989
INIT_DELAYED_WORK(&trans->timeout_dw, mlxsw_emad_trans_timeout_work);
990990
trans->tid = tid;
991991
init_completion(&trans->completion);
@@ -995,7 +995,6 @@ static int mlxsw_emad_reg_access(struct mlxsw_core *mlxsw_core,
995995
trans->type = type;
996996

997997
mlxsw_emad_construct(mlxsw_core, skb, reg, payload, type, trans->tid);
998-
mlxsw_core->driver->txhdr_construct(skb, &trans->tx_info);
999998

1000999
spin_lock_bh(&mlxsw_core->emad.trans_list_lock);
10011000
list_add_tail_rcu(&trans->list, &mlxsw_core->emad.trans_list);
@@ -2330,10 +2329,10 @@ bool mlxsw_core_skb_transmit_busy(struct mlxsw_core *mlxsw_core,
23302329
EXPORT_SYMBOL(mlxsw_core_skb_transmit_busy);
23312330

23322331
int mlxsw_core_skb_transmit(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
2333-
const struct mlxsw_tx_info *tx_info)
2332+
const struct mlxsw_txhdr_info *txhdr_info)
23342333
{
23352334
return mlxsw_core->bus->skb_transmit(mlxsw_core->bus_priv, skb,
2336-
tx_info);
2335+
txhdr_info);
23372336
}
23382337
EXPORT_SYMBOL(mlxsw_core_skb_transmit);
23392338

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ struct mlxsw_tx_info {
7272
bool is_emad;
7373
};
7474

75+
struct mlxsw_txhdr_info {
76+
struct mlxsw_tx_info tx_info;
77+
bool data;
78+
u16 max_fid; /* Used for PTP packets which are sent as data. */
79+
};
80+
7581
struct mlxsw_rx_md_info {
7682
struct napi_struct *napi;
7783
u32 cookie_index;
@@ -95,7 +101,7 @@ struct mlxsw_rx_md_info {
95101
bool mlxsw_core_skb_transmit_busy(struct mlxsw_core *mlxsw_core,
96102
const struct mlxsw_tx_info *tx_info);
97103
int mlxsw_core_skb_transmit(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
98-
const struct mlxsw_tx_info *tx_info);
104+
const struct mlxsw_txhdr_info *txhdr_info);
99105
void mlxsw_core_ptp_transmitted(struct mlxsw_core *mlxsw_core,
100106
struct sk_buff *skb, u16 local_port);
101107

@@ -426,8 +432,6 @@ struct mlxsw_driver {
426432
int (*trap_policer_counter_get)(struct mlxsw_core *mlxsw_core,
427433
const struct devlink_trap_policer *policer,
428434
u64 *p_drops);
429-
void (*txhdr_construct)(struct sk_buff *skb,
430-
const struct mlxsw_tx_info *tx_info);
431435
int (*resources_register)(struct mlxsw_core *mlxsw_core);
432436
int (*kvd_sizes_get)(struct mlxsw_core *mlxsw_core,
433437
const struct mlxsw_config_profile *profile,
@@ -440,7 +444,6 @@ struct mlxsw_driver {
440444
void (*ptp_transmitted)(struct mlxsw_core *mlxsw_core,
441445
struct sk_buff *skb, u16 local_port);
442446

443-
u8 txhdr_len;
444447
const struct mlxsw_config_profile *profile;
445448
bool sdq_supports_cqe_v2;
446449
};
@@ -487,7 +490,7 @@ struct mlxsw_bus {
487490
bool (*skb_transmit_busy)(void *bus_priv,
488491
const struct mlxsw_tx_info *tx_info);
489492
int (*skb_transmit)(void *bus_priv, struct sk_buff *skb,
490-
const struct mlxsw_tx_info *tx_info);
493+
const struct mlxsw_txhdr_info *txhdr_info);
491494
int (*cmd_exec)(void *bus_priv, u16 opcode, u8 opcode_mod,
492495
u32 in_mod, bool out_mbox_direct,
493496
char *in_mbox, size_t in_mbox_size,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ static bool mlxsw_i2c_skb_transmit_busy(void *bus_priv,
516516
}
517517

518518
static int mlxsw_i2c_skb_transmit(void *bus_priv, struct sk_buff *skb,
519-
const struct mlxsw_tx_info *tx_info)
519+
const struct mlxsw_txhdr_info *txhdr_info)
520520
{
521521
return 0;
522522
}

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

+41-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "cmd.h"
2222
#include "port.h"
2323
#include "resources.h"
24+
#include "txheader.h"
2425

2526
#define mlxsw_pci_write32(mlxsw_pci, reg, val) \
2627
iowrite32be(val, (mlxsw_pci)->hw_addr + (MLXSW_PCI_ ## reg))
@@ -2095,6 +2096,39 @@ static void mlxsw_pci_fini(void *bus_priv)
20952096
mlxsw_pci_free_irq_vectors(mlxsw_pci);
20962097
}
20972098

2099+
static int mlxsw_pci_txhdr_construct(struct sk_buff *skb,
2100+
const struct mlxsw_txhdr_info *txhdr_info)
2101+
{
2102+
const struct mlxsw_tx_info tx_info = txhdr_info->tx_info;
2103+
char *txhdr;
2104+
2105+
if (skb_cow_head(skb, MLXSW_TXHDR_LEN))
2106+
return -ENOMEM;
2107+
2108+
txhdr = skb_push(skb, MLXSW_TXHDR_LEN);
2109+
memset(txhdr, 0, MLXSW_TXHDR_LEN);
2110+
2111+
mlxsw_tx_hdr_version_set(txhdr, MLXSW_TXHDR_VERSION_1);
2112+
mlxsw_tx_hdr_proto_set(txhdr, MLXSW_TXHDR_PROTO_ETH);
2113+
mlxsw_tx_hdr_swid_set(txhdr, 0);
2114+
2115+
if (unlikely(txhdr_info->data)) {
2116+
u16 fid = txhdr_info->max_fid + tx_info.local_port - 1;
2117+
2118+
mlxsw_tx_hdr_rx_is_router_set(txhdr, true);
2119+
mlxsw_tx_hdr_fid_valid_set(txhdr, true);
2120+
mlxsw_tx_hdr_fid_set(txhdr, fid);
2121+
mlxsw_tx_hdr_type_set(txhdr, MLXSW_TXHDR_TYPE_DATA);
2122+
} else {
2123+
mlxsw_tx_hdr_ctl_set(txhdr, MLXSW_TXHDR_ETH_CTL);
2124+
mlxsw_tx_hdr_control_tclass_set(txhdr, 1);
2125+
mlxsw_tx_hdr_port_mid_set(txhdr, tx_info.local_port);
2126+
mlxsw_tx_hdr_type_set(txhdr, MLXSW_TXHDR_TYPE_CONTROL);
2127+
}
2128+
2129+
return 0;
2130+
}
2131+
20982132
static struct mlxsw_pci_queue *
20992133
mlxsw_pci_sdq_pick(struct mlxsw_pci *mlxsw_pci,
21002134
const struct mlxsw_tx_info *tx_info)
@@ -2122,7 +2156,7 @@ static bool mlxsw_pci_skb_transmit_busy(void *bus_priv,
21222156
}
21232157

21242158
static int mlxsw_pci_skb_transmit(void *bus_priv, struct sk_buff *skb,
2125-
const struct mlxsw_tx_info *tx_info)
2159+
const struct mlxsw_txhdr_info *txhdr_info)
21262160
{
21272161
struct mlxsw_pci *mlxsw_pci = bus_priv;
21282162
struct mlxsw_pci_queue *q;
@@ -2131,21 +2165,25 @@ static int mlxsw_pci_skb_transmit(void *bus_priv, struct sk_buff *skb,
21312165
int i;
21322166
int err;
21332167

2168+
err = mlxsw_pci_txhdr_construct(skb, txhdr_info);
2169+
if (err)
2170+
return err;
2171+
21342172
if (skb_shinfo(skb)->nr_frags > MLXSW_PCI_WQE_SG_ENTRIES - 1) {
21352173
err = skb_linearize(skb);
21362174
if (err)
21372175
return err;
21382176
}
21392177

2140-
q = mlxsw_pci_sdq_pick(mlxsw_pci, tx_info);
2178+
q = mlxsw_pci_sdq_pick(mlxsw_pci, &txhdr_info->tx_info);
21412179
spin_lock_bh(&q->lock);
21422180
elem_info = mlxsw_pci_queue_elem_info_producer_get(q);
21432181
if (!elem_info) {
21442182
/* queue is full */
21452183
err = -EAGAIN;
21462184
goto unlock;
21472185
}
2148-
mlxsw_skb_cb(skb)->tx_info = *tx_info;
2186+
mlxsw_skb_cb(skb)->tx_info = txhdr_info->tx_info;
21492187
elem_info->sdq.skb = skb;
21502188

21512189
wqe = elem_info->elem;

0 commit comments

Comments
 (0)