Skip to contentSkip to conversation

net: dsa: Allow switch drivers to indicate number of TX queues

PATCH Superseded Florian Fainelli 2 participants 7 messages Sep 2, 2017 – Sep 4, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover net: dsa: Allow switch drivers to indicate number of TX queues

Hi all,

This patch series extracts the parts of the patch set that are likely not to be controversial and actually bringing multi-queue support to DSA-created network devices.

With these patches, we can now use sch_multiq as documented under Documentation/networking/multique.txt and let applications dedice the switch port output queue they want to use. Currently only Broadcom tags utilize that information.

Changes in v2:
- use a proper define for the number of TX queues in bcm_sf2.c (Andrew)

Changes from RFC:

- dropped the ability to configure RX queues since we don't do anything with those just yet
- dropped the patches that dealt with binding the DSA slave network devices queues with their master network devices queues this will be worked on separately.

Florian Fainelli (4):
net: dsa: Allow switch drivers to indicate number of TX queues
net: dsa: tag_brcm: Set output queue from skb queue mapping
net: dsa: bcm_sf2: Advertise number of egress queues
net: dsa: bcm_sf2: Configure IMP port TC2QOS mapping

 drivers/net/dsa/bcm_sf2.c      | 14 +++++++++++++-
 drivers/net/dsa/bcm_sf2_regs.h |  3 +++
 include/net/dsa.h              |  3 +++
 net/dsa/slave.c                |  8 ++++++--
 net/dsa/tag_brcm.c             |  3 ++-
 5 files changed, 27 insertions(+), 4 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 1/4 net: dsa: Allow switch drivers to indicate number of TX queues

Let switch drivers indicate how many TX queues they support. Some switches, such as Broadcom Starfighter 2 are designed with 8 egress queues. Future changes will allow us to leverage the queue mapping and direct the transmission towards a particular queue.

---
 include/net/dsa.h | 3 +++
 net/dsa/slave.c   | 8 ++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
include/net/dsa.h +3 -0
index 398ca8d70ccd..dd44d6ce1097 100644
@@ -243,6 +243,9 @@ struct dsa_switch {
 	/* devlink used to represent this switch device */
 	struct devlink		*devlink;
 
+	/* Number of switch port queues */
+	unsigned int		num_tx_queues;
+
 	/* Dynamically allocated ports, keep last */
 	size_t num_ports;
 	struct dsa_port ports[];
net/dsa/slave.c +6 -2
index 78e78a6e6833..2afa99506f8b 100644
@@ -1259,8 +1259,12 @@ int dsa_slave_create(struct dsa_port *port, const char *name)
 	cpu_dp = ds->dst->cpu_dp;
 	master = cpu_dp->netdev;
 
-	slave_dev = alloc_netdev(sizeof(struct dsa_slave_priv), name,
-				 NET_NAME_UNKNOWN, ether_setup);
+	if (!ds->num_tx_queues)
+		ds->num_tx_queues = 1;
+
+	slave_dev = alloc_netdev_mqs(sizeof(struct dsa_slave_priv), name,
+				     NET_NAME_UNKNOWN, ether_setup,
+				     ds->num_tx_queues, 1);
 	if (slave_dev == NULL)
 		return -ENOMEM;
 
Signature · 1 line
2.11.0
#2 lore raw

PATCH v2 2/4 net: dsa: tag_brcm: Set output queue from skb queue mapping

In reply to Florian Fainelli

We originally used skb->priority but that was not quite correct as this bitfield needs to contain the egress switch queue we intend to send this SKB to.

---
 net/dsa/tag_brcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/dsa/tag_brcm.c +2 -1
index de74c3f77818..dbb016434ace 100644
@@ -62,6 +62,7 @@
 static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct dsa_slave_priv *p = netdev_priv(dev);
+	u16 queue = skb_get_queue_mapping(skb);
 	u8 *brcm_tag;
 
 	if (skb_cow_head(skb, BRCM_TAG_LEN) < 0)
@@ -78,7 +79,7 @@ static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev
 	 * deprecated
 	 */
 	brcm_tag[0] = (1 << BRCM_OPCODE_SHIFT) |
-			((skb->priority << BRCM_IG_TC_SHIFT) & BRCM_IG_TC_MASK);
+		       ((queue & BRCM_IG_TC_MASK) << BRCM_IG_TC_SHIFT);
 	brcm_tag[1] = 0;
 	brcm_tag[2] = 0;
 	if (p->dp->index == 8)
Signature · 1 line
2.11.0
#3 lore raw

PATCH v2 3/4 net: dsa: bcm_sf2: Advertise number of egress queues

In reply to Florian Fainelli

The switch supports 8 egress queues per port, so indicate that such that net/dsa/slave.c::dsa_slave_create can allocate the right number of TX queues. While at it use SF2_NUM_EGRESS_QUEUE as a define for the number of queues we support.

---
 drivers/net/dsa/bcm_sf2.c      | 5 ++++-
 drivers/net/dsa/bcm_sf2_regs.h | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/net/dsa/bcm_sf2.c +4 -1
index 554fe2df9365..6b184bafa235 100644
@@ -244,7 +244,7 @@ static int bcm_sf2_port_setup(struct dsa_switch *ds, int port,
 	 * to a different queue number
 	 */
 	reg = core_readl(priv, CORE_PORT_TC2_QOS_MAP_PORT(port));
-	for (i = 0; i < 8; i++)
+	for (i = 0; i < SF2_NUM_EGRESS_QUEUES; i++)
 		reg |= i << (PRT_TO_QID_SHIFT * i);
 	core_writel(priv, reg, CORE_PORT_TC2_QOS_MAP_PORT(port));
 
@@ -1151,6 +1151,9 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev)
 	ds = dev->ds;
 	ds->ops = &bcm_sf2_ops;
 
+	/* Advertise the 8 egress queues */
+	ds->num_tx_queues = SF2_NUM_EGRESS_QUEUES;
+
 	dev_set_drvdata(&pdev->dev, priv);
 
 	spin_lock_init(&priv->indir_lock);
drivers/net/dsa/bcm_sf2_regs.h +3 -0
index 26052450091e..49695fcc2ea8 100644
@@ -401,4 +401,7 @@ enum bcm_sf2_reg_offs {
 
 #define CFP_NUM_RULES			256
 
+/* Number of egress queues per port */
+#define SF2_NUM_EGRESS_QUEUES		8
+
 #endif /* __BCM_SF2_REGS_H */
Signature · 1 line
2.11.0
#4 lore raw

PATCH v2 4/4 net: dsa: bcm_sf2: Configure IMP port TC2QOS mapping

In reply to Florian Fainelli

Even though TC2QOS mapping is for switch egress queues, we need to configure it correclty in order for the Broadcom tag ingress (CPU -> switch) queue selection to work correctly since there is a 1:1 mapping between switch egress queues and ingress queues.

---
 drivers/net/dsa/bcm_sf2.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/net/dsa/bcm_sf2.c +9 -0
index 6b184bafa235..d7b53d53c116 100644
@@ -103,6 +103,7 @@ static void bcm_sf2_brcm_hdr_setup(struct bcm_sf2_priv *priv, int port)
 static void bcm_sf2_imp_setup(struct dsa_switch *ds, int port)
 {
 	struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
+	unsigned int i;
 	u32 reg, offset;
 
 	if (priv->type == BCM7445_DEVICE_ID)
@@ -129,6 +130,14 @@ static void bcm_sf2_imp_setup(struct dsa_switch *ds, int port)
 	reg |= MII_DUMB_FWDG_EN;
 	core_writel(priv, reg, CORE_SWITCH_CTRL);
 
+	/* Configure Traffic Class to QoS mapping, allow each priority to map
+	 * to a different queue number
+	 */
+	reg = core_readl(priv, CORE_PORT_TC2_QOS_MAP_PORT(port));
+	for (i = 0; i < SF2_NUM_EGRESS_QUEUES; i++)
+		reg |= i << (PRT_TO_QID_SHIFT * i);
+	core_writel(priv, reg, CORE_PORT_TC2_QOS_MAP_PORT(port));
+
 	bcm_sf2_brcm_hdr_setup(priv, port);
 
 	/* Force link status for IMP port */
Signature · 1 line
2.11.0
maintainer
#5 lore raw
In reply to Florian Fainelli

From: Florian Fainelli <[email protected]>
Date: Sat, 2 Sep 2017 11:06:05 -0700

Quoted 11 lines

This patch series extracts the parts of the patch set that are likely not to be controversial and actually bringing multi-queue support to DSA-created network devices.

With these patches, we can now use sch_multiq as documented under Documentation/networking/multique.txt and let applications dedice the switch port output queue they want to use. Currently only Broadcom tags utilize that information.

Changes in v2:
- use a proper define for the number of TX queues in bcm_sf2.c (Andrew)

Hello Florian.

For some reason this series didn't make it completely into patchwork, I only see patch #1 there.

Can you try submitting again? If it doesn't work this time I'll just apply it by hand from my inbox.

Thanks.

#6 lore raw
Quoted 15 lines · David Miller

From: Florian Fainelli <[email protected]>
Date: Sat, 2 Sep 2017 11:06:05 -0700

Quoted 11 lines

This patch series extracts the parts of the patch set that are likely not to be controversial and actually bringing multi-queue support to DSA-created network devices.

With these patches, we can now use sch_multiq as documented under Documentation/networking/multique.txt and let applications dedice the switch port output queue they want to use. Currently only Broadcom tags utilize that information.

Changes in v2:
- use a proper define for the number of TX queues in bcm_sf2.c (Andrew)

Quoted 7 lines

Hello Florian.

For some reason this series didn't make it completely into patchwork, I only see patch #1 there.

Can you try submitting again? If it doesn't work this time I'll just apply it by hand from my inbox.

No problem, I just resent this patch series, thanks for the heads-up.

Signature · 1 line
Florian