Skip to content

Commit 67c2404

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: felix: create a template for the DSA tags on xmit
With this patch we try to kill 2 birds with 1 stone. First of all, some switches that use tag_ocelot.c don't have the exact same bitfield layout for the DSA tags. The destination ports field is different for Seville VSC9953 for example. So the choices are to either duplicate tag_ocelot.c into a new tag_seville.c (sub-optimal) or somehow take into account a supposed ocelot->dest_ports_offset when packing this field into the DSA injection header (again not ideal). Secondly, tag_ocelot.c already needs to memset a 128-bit area to zero and call some packing() functions of dubious performance in the fastpath. And most of the values it needs to pack are pretty much constant (BYPASS=1, SRC_PORT=CPU, DEST=port index). So it would be good if we could improve that. The proposed solution is to allocate a memory area per port at probe time, initialize that with the statically defined bits as per chip hardware revision, and just perform a simpler memcpy in the fastpath. Other alternatives have been analyzed, such as: - Create a separate tag_seville.c: too much code duplication for just 1 bit field difference. - Create a separate DSA_TAG_PROTO_SEVILLE under tag_ocelot.c, just like tag_brcm.c, which would have a separate .xmit function. Again, too much code duplication for just 1 bit field difference. - Allocate the template from the init function of the tag_ocelot.c module, instead of from the driver: couldn't figure out a method of accessing the correct port template corresponding to the correct tagger in the .xmit function. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 886e138 commit 67c2404

5 files changed

Lines changed: 44 additions & 13 deletions

File tree

‎drivers/net/dsa/ocelot/felix.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
522522
for (port = 0; port < num_phys_ports; port++) {
523523
struct ocelot_port *ocelot_port;
524524
struct regmap *target;
525+
u8 *template;
525526

526527
ocelot_port = devm_kzalloc(ocelot->dev,
527528
sizeof(struct ocelot_port),
@@ -547,10 +548,22 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
547548
return PTR_ERR(target);
548549
}
549550

551+
template = devm_kzalloc(ocelot->dev, OCELOT_TAG_LEN,
552+
GFP_KERNEL);
553+
if (!template) {
554+
dev_err(ocelot->dev,
555+
"Failed to allocate memory for DSA tag\n");
556+
kfree(port_phy_modes);
557+
return -ENOMEM;
558+
}
559+
550560
ocelot_port->phy_mode = port_phy_modes[port];
551561
ocelot_port->ocelot = ocelot;
552562
ocelot_port->target = target;
563+
ocelot_port->xmit_template = template;
553564
ocelot->ports[port] = ocelot_port;
565+
566+
felix->info->xmit_template_populate(ocelot, port);
554567
}
555568

556569
kfree(port_phy_modes);

‎drivers/net/dsa/ocelot/felix.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct felix_info {
4343
enum tc_setup_type type, void *type_data);
4444
void (*port_sched_speed_set)(struct ocelot *ocelot, int port,
4545
u32 speed);
46+
void (*xmit_template_populate)(struct ocelot *ocelot, int port);
4647
};
4748

4849
extern struct felix_info felix_info_vsc9959;

‎drivers/net/dsa/ocelot/felix_vsc9959.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <soc/mscc/ocelot_ptp.h>
99
#include <soc/mscc/ocelot_sys.h>
1010
#include <soc/mscc/ocelot.h>
11+
#include <linux/packing.h>
1112
#include <net/pkt_sched.h>
1213
#include <linux/iopoll.h>
1314
#include <linux/pci.h>
@@ -1432,6 +1433,24 @@ static int vsc9959_port_setup_tc(struct dsa_switch *ds, int port,
14321433
}
14331434
}
14341435

1436+
static void vsc9959_xmit_template_populate(struct ocelot *ocelot, int port)
1437+
{
1438+
struct ocelot_port *ocelot_port = ocelot->ports[port];
1439+
u8 *template = ocelot_port->xmit_template;
1440+
u64 bypass, dest, src;
1441+
1442+
/* Set the source port as the CPU port module and not the
1443+
* NPI port
1444+
*/
1445+
src = ocelot->num_phys_ports;
1446+
dest = BIT(port);
1447+
bypass = true;
1448+
1449+
packing(template, &bypass, 127, 127, OCELOT_TAG_LEN, PACK, 0);
1450+
packing(template, &dest, 68, 56, OCELOT_TAG_LEN, PACK, 0);
1451+
packing(template, &src, 46, 43, OCELOT_TAG_LEN, PACK, 0);
1452+
}
1453+
14351454
struct felix_info felix_info_vsc9959 = {
14361455
.target_io_res = vsc9959_target_io_res,
14371456
.port_io_res = vsc9959_port_io_res,
@@ -1458,4 +1477,5 @@ struct felix_info felix_info_vsc9959 = {
14581477
.prevalidate_phy_mode = vsc9959_prevalidate_phy_mode,
14591478
.port_setup_tc = vsc9959_port_setup_tc,
14601479
.port_sched_speed_set = vsc9959_sched_speed_set,
1480+
.xmit_template_populate = vsc9959_xmit_template_populate,
14611481
};

‎include/soc/mscc/ocelot.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ struct ocelot_port {
564564
u8 ts_id;
565565

566566
phy_interface_t phy_mode;
567+
568+
u8 *xmit_template;
567569
};
568570

569571
struct ocelot {

‎net/dsa/tag_ocelot.c‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,31 +137,26 @@ static struct sk_buff *ocelot_xmit(struct sk_buff *skb,
137137
struct net_device *netdev)
138138
{
139139
struct dsa_port *dp = dsa_slave_to_port(netdev);
140-
u64 bypass, dest, src, qos_class, rew_op;
141140
struct dsa_switch *ds = dp->ds;
142-
int port = dp->index;
143141
struct ocelot *ocelot = ds->priv;
144-
struct ocelot_port *ocelot_port = ocelot->ports[port];
142+
struct ocelot_port *ocelot_port;
143+
u64 qos_class, rew_op;
145144
u8 *injection;
146145

147146
if (unlikely(skb_cow_head(skb, OCELOT_TAG_LEN) < 0)) {
148147
netdev_err(netdev, "Cannot make room for tag.\n");
149148
return NULL;
150149
}
151150

152-
injection = skb_push(skb, OCELOT_TAG_LEN);
151+
ocelot_port = ocelot->ports[dp->index];
153152

154-
memset(injection, 0, OCELOT_TAG_LEN);
153+
injection = skb_push(skb, OCELOT_TAG_LEN);
155154

156-
/* Set the source port as the CPU port module and not the NPI port */
157-
src = ocelot->num_phys_ports;
158-
dest = BIT(port);
159-
bypass = true;
155+
memcpy(injection, ocelot_port->xmit_template, OCELOT_TAG_LEN);
156+
/* Fix up the fields which are not statically determined
157+
* in the template
158+
*/
160159
qos_class = skb->priority;
161-
162-
packing(injection, &bypass, 127, 127, OCELOT_TAG_LEN, PACK, 0);
163-
packing(injection, &dest, 68, 56, OCELOT_TAG_LEN, PACK, 0);
164-
packing(injection, &src, 46, 43, OCELOT_TAG_LEN, PACK, 0);
165160
packing(injection, &qos_class, 19, 17, OCELOT_TAG_LEN, PACK, 0);
166161

167162
if (ocelot->ptp && (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {

0 commit comments

Comments
 (0)