Skip to content

Commit 7929a66

Browse files
ikhorndavem330
authored andcommitted
net: ethernet: ti: cpsw: add MQPRIO Qdisc offload
That's possible to offload vlan to tc priority mapping with assumption sk_prio == L2 prio. Example: $ ethtool -L eth0 rx 1 tx 4 $ qdisc replace dev eth0 handle 100: parent root mqprio num_tc 3 \ map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 queues 1@0 1@1 2@2 hw 1 $ tc -g class show dev eth0 +---(100:ffe2) mqprio |    +---(100:3) mqprio |    +---(100:4) mqprio |     +---(100:ffe1) mqprio |    +---(100:2) mqprio |     +---(100:ffe0) mqprio     +---(100:1) mqprio Here, 100:1 is txq0, 100:2 is txq1, 100:3 is txq2, 100:4 is txq3 txq0 belongs to tc0, txq1 to tc1, txq2 and txq3 to tc2 The offload part only maps L2 prio to classes of traffic, but not to transmit queues, so to direct traffic to traffic class vlan has to be created with appropriate egress map. Reviewed-by: Ilias Apalodimas <[email protected]> Reviewed-by: Grygorii Strashko <[email protected]> Signed-off-by: Ivan Khoronzhuk <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4bb6c35 commit 7929a66

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

drivers/net/ethernet/ti/cpsw.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <linux/sys_soc.h>
4040

4141
#include <linux/pinctrl/consumer.h>
42+
#include <net/pkt_cls.h>
4243

4344
#include "cpsw.h"
4445
#include "cpsw_ale.h"
@@ -153,6 +154,8 @@ do { \
153154
#define IRQ_NUM 2
154155
#define CPSW_MAX_QUEUES 8
155156
#define CPSW_CPDMA_DESCS_POOL_SIZE_DEFAULT 256
157+
#define CPSW_TC_NUM 4
158+
#define CPSW_FIFO_SHAPERS_NUM (CPSW_TC_NUM - 1)
156159

157160
#define CPSW_RX_VLAN_ENCAP_HDR_PRIO_SHIFT 29
158161
#define CPSW_RX_VLAN_ENCAP_HDR_PRIO_MSK GENMASK(2, 0)
@@ -454,6 +457,7 @@ struct cpsw_priv {
454457
u8 mac_addr[ETH_ALEN];
455458
bool rx_pause;
456459
bool tx_pause;
460+
bool mqprio_hw;
457461
u32 emac_port;
458462
struct cpsw_common *cpsw;
459463
};
@@ -1578,6 +1582,14 @@ static void cpsw_slave_stop(struct cpsw_slave *slave, struct cpsw_common *cpsw)
15781582
soft_reset_slave(slave);
15791583
}
15801584

1585+
static int cpsw_tc_to_fifo(int tc, int num_tc)
1586+
{
1587+
if (tc == num_tc - 1)
1588+
return 0;
1589+
1590+
return CPSW_FIFO_SHAPERS_NUM - tc;
1591+
}
1592+
15811593
static int cpsw_ndo_open(struct net_device *ndev)
15821594
{
15831595
struct cpsw_priv *priv = netdev_priv(ndev);
@@ -2191,6 +2203,75 @@ static int cpsw_ndo_set_tx_maxrate(struct net_device *ndev, int queue, u32 rate)
21912203
return ret;
21922204
}
21932205

2206+
static int cpsw_set_mqprio(struct net_device *ndev, void *type_data)
2207+
{
2208+
struct tc_mqprio_qopt_offload *mqprio = type_data;
2209+
struct cpsw_priv *priv = netdev_priv(ndev);
2210+
struct cpsw_common *cpsw = priv->cpsw;
2211+
int fifo, num_tc, count, offset;
2212+
struct cpsw_slave *slave;
2213+
u32 tx_prio_map = 0;
2214+
int i, tc, ret;
2215+
2216+
num_tc = mqprio->qopt.num_tc;
2217+
if (num_tc > CPSW_TC_NUM)
2218+
return -EINVAL;
2219+
2220+
if (mqprio->mode != TC_MQPRIO_MODE_DCB)
2221+
return -EINVAL;
2222+
2223+
ret = pm_runtime_get_sync(cpsw->dev);
2224+
if (ret < 0) {
2225+
pm_runtime_put_noidle(cpsw->dev);
2226+
return ret;
2227+
}
2228+
2229+
if (num_tc) {
2230+
for (i = 0; i < 8; i++) {
2231+
tc = mqprio->qopt.prio_tc_map[i];
2232+
fifo = cpsw_tc_to_fifo(tc, num_tc);
2233+
tx_prio_map |= fifo << (4 * i);
2234+
}
2235+
2236+
netdev_set_num_tc(ndev, num_tc);
2237+
for (i = 0; i < num_tc; i++) {
2238+
count = mqprio->qopt.count[i];
2239+
offset = mqprio->qopt.offset[i];
2240+
netdev_set_tc_queue(ndev, i, count, offset);
2241+
}
2242+
}
2243+
2244+
if (!mqprio->qopt.hw) {
2245+
/* restore default configuration */
2246+
netdev_reset_tc(ndev);
2247+
tx_prio_map = TX_PRIORITY_MAPPING;
2248+
}
2249+
2250+
priv->mqprio_hw = mqprio->qopt.hw;
2251+
2252+
offset = cpsw->version == CPSW_VERSION_1 ?
2253+
CPSW1_TX_PRI_MAP : CPSW2_TX_PRI_MAP;
2254+
2255+
slave = &cpsw->slaves[cpsw_slave_index(cpsw, priv)];
2256+
slave_write(slave, tx_prio_map, offset);
2257+
2258+
pm_runtime_put_sync(cpsw->dev);
2259+
2260+
return 0;
2261+
}
2262+
2263+
static int cpsw_ndo_setup_tc(struct net_device *ndev, enum tc_setup_type type,
2264+
void *type_data)
2265+
{
2266+
switch (type) {
2267+
case TC_SETUP_QDISC_MQPRIO:
2268+
return cpsw_set_mqprio(ndev, type_data);
2269+
2270+
default:
2271+
return -EOPNOTSUPP;
2272+
}
2273+
}
2274+
21942275
static const struct net_device_ops cpsw_netdev_ops = {
21952276
.ndo_open = cpsw_ndo_open,
21962277
.ndo_stop = cpsw_ndo_stop,
@@ -2206,6 +2287,7 @@ static const struct net_device_ops cpsw_netdev_ops = {
22062287
#endif
22072288
.ndo_vlan_rx_add_vid = cpsw_ndo_vlan_rx_add_vid,
22082289
.ndo_vlan_rx_kill_vid = cpsw_ndo_vlan_rx_kill_vid,
2290+
.ndo_setup_tc = cpsw_ndo_setup_tc,
22092291
};
22102292

22112293
static int cpsw_get_regs_len(struct net_device *ndev)

0 commit comments

Comments
 (0)