Skip to content

Commit d976a52

Browse files
Joao Pintodavem330
authored andcommitted
net: stmmac: multiple queues dt configuration
This patch adds the multiple queues configuration in the Device Tree. It was also created a set of structures to keep the RX and TX queues configurations to be used in the driver. Signed-off-by: Joao Pinto <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 429a372 commit d976a52

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

Documentation/devicetree/bindings/net/stmmac.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ Optional properties:
7272
- snps,mb: mixed-burst
7373
- snps,rb: rebuild INCRx Burst
7474
- mdio: with compatible = "snps,dwmac-mdio", create and register mdio bus.
75+
- Multiple RX Queues parameters: below the list of all the parameters to
76+
configure the multiple RX queues:
77+
- snps,rx-queues-to-use: number of RX queues to be used in the driver
78+
- Choose one of these RX scheduling algorithms:
79+
- snps,rx-sched-sp: Strict priority
80+
- snps,rx-sched-wsp: Weighted Strict priority
81+
- For each RX queue
82+
- Choose one of these modes:
83+
- snps,dcb-algorithm: Queue to be enabled as DCB
84+
- snps,avb-algorithm: Queue to be enabled as AVB
85+
- snps,map-to-dma-channel: Channel to map
86+
- Multiple TX Queues parameters: below the list of all the parameters to
87+
configure the multiple TX queues:
88+
- snps,tx-queues-to-use: number of TX queues to be used in the driver
89+
- Choose one of these TX scheduling algorithms:
90+
- snps,tx-sched-wrr: Weighted Round Robin
91+
- snps,tx-sched-wfq: Weighted Fair Queuing
92+
- snps,tx-sched-dwrr: Deficit Weighted Round Robin
93+
- snps,tx-sched-sp: Strict priority
94+
- For each TX queue
95+
- snps,weight: TX queue weight (if using a weighted algorithm)
7596

7697
Examples:
7798

@@ -81,6 +102,23 @@ Examples:
81102
snps,blen = <256 128 64 32 0 0 0>;
82103
};
83104

105+
mtl_rx_setup: rx-queues-config {
106+
snps,rx-queues-to-use = <1>;
107+
snps,rx-sched-sp;
108+
queue0 {
109+
snps,dcb-algorithm;
110+
snps,map-to-dma-channel = <0x0>;
111+
};
112+
};
113+
114+
mtl_tx_setup: tx-queues-config {
115+
snps,tx-queues-to-use = <1>;
116+
snps,tx-sched-wrr;
117+
queue0 {
118+
snps,weight = <0x10>;
119+
};
120+
};
121+
84122
gmac0: ethernet@e0800000 {
85123
compatible = "st,spear600-gmac";
86124
reg = <0xe0800000 0x8000>;
@@ -104,4 +142,6 @@ Examples:
104142
phy1: ethernet-phy@0 {
105143
};
106144
};
145+
snps,mtl-rx-config = <&mtl_rx_setup>;
146+
snps,mtl-tx-config = <&mtl_tx_setup>;
107147
};

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,95 @@ static struct stmmac_axi *stmmac_axi_setup(struct platform_device *pdev)
131131
return axi;
132132
}
133133

134+
/**
135+
* stmmac_mtl_setup - parse DT parameters for multiple queues configuration
136+
* @pdev: platform device
137+
*/
138+
static void stmmac_mtl_setup(struct platform_device *pdev,
139+
struct plat_stmmacenet_data *plat)
140+
{
141+
struct device_node *q_node;
142+
struct device_node *rx_node;
143+
struct device_node *tx_node;
144+
u8 queue = 0;
145+
146+
rx_node = of_parse_phandle(pdev->dev.of_node, "snps,mtl-rx-config", 0);
147+
if (!rx_node)
148+
return;
149+
150+
tx_node = of_parse_phandle(pdev->dev.of_node, "snps,mtl-tx-config", 0);
151+
if (!tx_node) {
152+
of_node_put(rx_node);
153+
return;
154+
}
155+
156+
/* Processing RX queues common config */
157+
if (of_property_read_u8(rx_node, "snps,rx-queues-to-use",
158+
&plat->rx_queues_to_use))
159+
plat->rx_queues_to_use = 1;
160+
161+
if (of_property_read_bool(rx_node, "snps,rx-sched-sp"))
162+
plat->rx_sched_algorithm = MTL_RX_ALGORITHM_SP;
163+
else if (of_property_read_bool(rx_node, "snps,rx-sched-wsp"))
164+
plat->rx_sched_algorithm = MTL_RX_ALGORITHM_WSP;
165+
else
166+
plat->rx_sched_algorithm = MTL_RX_ALGORITHM_SP;
167+
168+
/* Processing individual RX queue config */
169+
for_each_child_of_node(rx_node, q_node) {
170+
if (queue >= plat->rx_queues_to_use)
171+
break;
172+
173+
if (of_property_read_bool(q_node, "snps,dcb-algorithm"))
174+
plat->rx_queues_cfg[queue].mode_to_use = MTL_RX_DCB;
175+
else if (of_property_read_bool(q_node, "snps,avb-algorithm"))
176+
plat->rx_queues_cfg[queue].mode_to_use = MTL_RX_AVB;
177+
else
178+
plat->rx_queues_cfg[queue].mode_to_use = MTL_RX_DCB;
179+
180+
if (of_property_read_u8(q_node, "snps,map-to-dma-channel",
181+
&plat->rx_queues_cfg[queue].chan))
182+
plat->rx_queues_cfg[queue].chan = queue;
183+
/* TODO: Dynamic mapping to be included in the future */
184+
185+
queue++;
186+
}
187+
188+
/* Processing TX queues common config */
189+
if (of_property_read_u8(tx_node, "snps,tx-queues-to-use",
190+
&plat->tx_queues_to_use))
191+
plat->tx_queues_to_use = 1;
192+
193+
if (of_property_read_bool(tx_node, "snps,tx-sched-wrr"))
194+
plat->tx_sched_algorithm = MTL_TX_ALGORITHM_WRR;
195+
else if (of_property_read_bool(tx_node, "snps,tx-sched-wfq"))
196+
plat->tx_sched_algorithm = MTL_TX_ALGORITHM_WFQ;
197+
else if (of_property_read_bool(tx_node, "snps,tx-sched-dwrr"))
198+
plat->tx_sched_algorithm = MTL_TX_ALGORITHM_DWRR;
199+
else if (of_property_read_bool(tx_node, "snps,tx-sched-sp"))
200+
plat->tx_sched_algorithm = MTL_TX_ALGORITHM_SP;
201+
else
202+
plat->tx_sched_algorithm = MTL_TX_ALGORITHM_SP;
203+
204+
queue = 0;
205+
206+
/* Processing individual TX queue config */
207+
for_each_child_of_node(tx_node, q_node) {
208+
if (queue >= plat->tx_queues_to_use)
209+
break;
210+
211+
if (of_property_read_u8(q_node, "snps,weight",
212+
&plat->tx_queues_cfg[queue].weight))
213+
plat->tx_queues_cfg[queue].weight = 0x10 + queue;
214+
215+
queue++;
216+
}
217+
218+
of_node_put(rx_node);
219+
of_node_put(tx_node);
220+
of_node_put(q_node);
221+
}
222+
134223
/**
135224
* stmmac_dt_phy - parse device-tree driver parameters to allocate PHY resources
136225
* @plat: driver data platform structure
@@ -340,6 +429,8 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
340429

341430
plat->axi = stmmac_axi_setup(pdev);
342431

432+
stmmac_mtl_setup(pdev, plat);
433+
343434
/* clock setup */
344435
plat->stmmac_clk = devm_clk_get(&pdev->dev,
345436
STMMAC_RESOURCE_NAME);

include/linux/stmmac.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
#include <linux/platform_device.h>
3030

31+
#define MTL_MAX_RX_QUEUES 8
32+
#define MTL_MAX_TX_QUEUES 8
33+
3134
#define STMMAC_RX_COE_NONE 0
3235
#define STMMAC_RX_COE_TYPE1 1
3336
#define STMMAC_RX_COE_TYPE2 2
@@ -44,6 +47,18 @@
4447
#define STMMAC_CSR_150_250M 0x4 /* MDC = clk_scr_i/102 */
4548
#define STMMAC_CSR_250_300M 0x5 /* MDC = clk_scr_i/122 */
4649

50+
/* MTL algorithms identifiers */
51+
#define MTL_TX_ALGORITHM_WRR 0x0
52+
#define MTL_TX_ALGORITHM_WFQ 0x1
53+
#define MTL_TX_ALGORITHM_DWRR 0x2
54+
#define MTL_TX_ALGORITHM_SP 0x3
55+
#define MTL_RX_ALGORITHM_SP 0x4
56+
#define MTL_RX_ALGORITHM_WSP 0x5
57+
58+
/* RX Queue Mode */
59+
#define MTL_RX_DCB 0x0
60+
#define MTL_RX_AVB 0x1
61+
4762
/* The MDC clock could be set higher than the IEEE 802.3
4863
* specified frequency limit 0f 2.5 MHz, by programming a clock divider
4964
* of value different than the above defined values. The resultant MDIO
@@ -109,6 +124,15 @@ struct stmmac_axi {
109124
bool axi_rb;
110125
};
111126

127+
struct stmmac_rxq_cfg {
128+
u8 mode_to_use;
129+
u8 chan;
130+
};
131+
132+
struct stmmac_txq_cfg {
133+
u8 weight;
134+
};
135+
112136
struct plat_stmmacenet_data {
113137
int bus_id;
114138
int phy_addr;
@@ -133,6 +157,12 @@ struct plat_stmmacenet_data {
133157
int unicast_filter_entries;
134158
int tx_fifo_size;
135159
int rx_fifo_size;
160+
u8 rx_queues_to_use;
161+
u8 tx_queues_to_use;
162+
u8 rx_sched_algorithm;
163+
u8 tx_sched_algorithm;
164+
struct stmmac_rxq_cfg rx_queues_cfg[MTL_MAX_RX_QUEUES];
165+
struct stmmac_txq_cfg tx_queues_cfg[MTL_MAX_TX_QUEUES];
136166
void (*fix_mac_speed)(void *priv, unsigned int speed);
137167
int (*init)(struct platform_device *pdev, void *priv);
138168
void (*exit)(struct platform_device *pdev, void *priv);

0 commit comments

Comments
 (0)