Skip to content

Commit 8cc4102

Browse files
DanielmachonPaolo Abeni
authored andcommitted
net: sparx5: redefine internal ports and PGID's as offsets
Internal ports and PGID's are both defined relative to the number of front ports on Sparx5. This will not work on lan969x. Instead make them offsets to the number of front ports and add two helpers to retrieve them. Use the helpers throughout. Reviewed-by: Steen Hegelund <[email protected]> Signed-off-by: Daniel Machon <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 4b67bcb commit 8cc4102

File tree

11 files changed

+86
-45
lines changed

11 files changed

+86
-45
lines changed

drivers/net/ethernet/microchip/sparx5/sparx5_calendar.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,22 @@ static enum sparx5_cal_bw sparx5_get_port_cal_speed(struct sparx5 *sparx5,
118118

119119
if (portno >= sparx5->data->consts->n_ports) {
120120
/* Internal ports */
121-
if (portno == SPX5_PORT_CPU_0 || portno == SPX5_PORT_CPU_1) {
121+
if (portno ==
122+
sparx5_get_internal_port(sparx5, SPX5_PORT_CPU_0) ||
123+
portno ==
124+
sparx5_get_internal_port(sparx5, SPX5_PORT_CPU_1)) {
122125
/* Equals 1.25G */
123126
return SPX5_CAL_SPEED_2G5;
124-
} else if (portno == SPX5_PORT_VD0) {
127+
} else if (portno ==
128+
sparx5_get_internal_port(sparx5, SPX5_PORT_VD0)) {
125129
/* IPMC only idle BW */
126130
return SPX5_CAL_SPEED_NONE;
127-
} else if (portno == SPX5_PORT_VD1) {
131+
} else if (portno ==
132+
sparx5_get_internal_port(sparx5, SPX5_PORT_VD1)) {
128133
/* OAM only idle BW */
129134
return SPX5_CAL_SPEED_NONE;
130-
} else if (portno == SPX5_PORT_VD2) {
135+
} else if (portno ==
136+
sparx5_get_internal_port(sparx5, SPX5_PORT_VD2)) {
131137
/* IPinIP gets only idle BW */
132138
return SPX5_CAL_SPEED_NONE;
133139
}

drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ static void sparx5_fdma_injection_mode(struct sparx5 *sparx5)
364364
sparx5, QS_INJ_GRP_CFG(INJ_QUEUE));
365365

366366
/* CPU ports capture setup */
367-
for (portno = SPX5_PORT_CPU_0; portno <= SPX5_PORT_CPU_1; portno++) {
367+
for (portno = sparx5_get_internal_port(sparx5, SPX5_PORT_CPU_0);
368+
portno <= sparx5_get_internal_port(sparx5, SPX5_PORT_CPU_1);
369+
portno++) {
368370
/* ASM CPU port: No preamble, IFH, enable padding */
369371
spx5_wr(ASM_PORT_CFG_PAD_ENA_SET(1) |
370372
ASM_PORT_CFG_NO_PREAMBLE_ENA_SET(1) |

drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ int sparx5_mc_sync(struct net_device *dev, const unsigned char *addr)
129129
struct sparx5_port *port = netdev_priv(dev);
130130
struct sparx5 *sparx5 = port->sparx5;
131131

132-
return sparx5_mact_learn(sparx5, PGID_CPU, addr, port->pvid);
132+
return sparx5_mact_learn(sparx5, sparx5_get_pgid(sparx5, PGID_CPU),
133+
addr, port->pvid);
133134
}
134135

135136
static int sparx5_mact_get(struct sparx5 *sparx5,

drivers/net/ethernet/microchip/sparx5/sparx5_main.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,13 +649,14 @@ static int sparx5_start(struct sparx5 *sparx5)
649649
sparx5_update_fwd(sparx5);
650650

651651
/* CPU copy CPU pgids */
652-
spx5_wr(ANA_AC_PGID_MISC_CFG_PGID_CPU_COPY_ENA_SET(1),
653-
sparx5, ANA_AC_PGID_MISC_CFG(PGID_CPU));
654-
spx5_wr(ANA_AC_PGID_MISC_CFG_PGID_CPU_COPY_ENA_SET(1),
655-
sparx5, ANA_AC_PGID_MISC_CFG(PGID_BCAST));
652+
spx5_wr(ANA_AC_PGID_MISC_CFG_PGID_CPU_COPY_ENA_SET(1), sparx5,
653+
ANA_AC_PGID_MISC_CFG(sparx5_get_pgid(sparx5, PGID_CPU)));
654+
spx5_wr(ANA_AC_PGID_MISC_CFG_PGID_CPU_COPY_ENA_SET(1), sparx5,
655+
ANA_AC_PGID_MISC_CFG(sparx5_get_pgid(sparx5, PGID_BCAST)));
656656

657657
/* Recalc injected frame FCS */
658-
for (idx = SPX5_PORT_CPU_0; idx <= SPX5_PORT_CPU_1; idx++)
658+
for (idx = sparx5_get_internal_port(sparx5, SPX5_PORT_CPU_0);
659+
idx <= sparx5_get_internal_port(sparx5, SPX5_PORT_CPU_1); idx++)
659660
spx5_rmw(ANA_CL_FILTER_CTRL_FORCE_FCS_UPDATE_ENA_SET(1),
660661
ANA_CL_FILTER_CTRL_FORCE_FCS_UPDATE_ENA,
661662
sparx5, ANA_CL_FILTER_CTRL(idx));
@@ -670,7 +671,8 @@ static int sparx5_start(struct sparx5 *sparx5)
670671
sparx5_vlan_init(sparx5);
671672

672673
/* Add host mode BC address (points only to CPU) */
673-
sparx5_mact_learn(sparx5, PGID_CPU, broadcast, NULL_VID);
674+
sparx5_mact_learn(sparx5, sparx5_get_pgid(sparx5, PGID_CPU), broadcast,
675+
NULL_VID);
674676

675677
/* Enable queue limitation watermarks */
676678
sparx5_qlim_set(sparx5);

drivers/net/ethernet/microchip/sparx5/sparx5_main.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,21 @@ enum sparx5_vlan_port_type {
5454
#define SPX5_PORTS 65
5555
#define SPX5_PORTS_ALL 70 /* Total number of ports */
5656

57-
#define SPX5_PORT_CPU (SPX5_PORTS) /* Next port is CPU port */
58-
#define SPX5_PORT_CPU_0 (SPX5_PORT_CPU + 0) /* CPU Port 65 */
59-
#define SPX5_PORT_CPU_1 (SPX5_PORT_CPU + 1) /* CPU Port 66 */
60-
#define SPX5_PORT_VD0 (SPX5_PORT_CPU + 2) /* VD0/Port 67 used for IPMC */
61-
#define SPX5_PORT_VD1 (SPX5_PORT_CPU + 3) /* VD1/Port 68 used for AFI/OAM */
62-
#define SPX5_PORT_VD2 (SPX5_PORT_CPU + 4) /* VD2/Port 69 used for IPinIP*/
63-
64-
#define PGID_BASE SPX5_PORTS /* Starts after port PGIDs */
65-
#define PGID_UC_FLOOD (PGID_BASE + 0)
66-
#define PGID_MC_FLOOD (PGID_BASE + 1)
67-
#define PGID_IPV4_MC_DATA (PGID_BASE + 2)
68-
#define PGID_IPV4_MC_CTRL (PGID_BASE + 3)
69-
#define PGID_IPV6_MC_DATA (PGID_BASE + 4)
70-
#define PGID_IPV6_MC_CTRL (PGID_BASE + 5)
71-
#define PGID_BCAST (PGID_BASE + 6)
72-
#define PGID_CPU (PGID_BASE + 7)
73-
#define PGID_MCAST_START (PGID_BASE + 8)
57+
#define SPX5_PORT_CPU_0 0 /* CPU Port 0 */
58+
#define SPX5_PORT_CPU_1 1 /* CPU Port 1 */
59+
#define SPX5_PORT_VD0 2 /* VD0/Port used for IPMC */
60+
#define SPX5_PORT_VD1 3 /* VD1/Port used for AFI/OAM */
61+
#define SPX5_PORT_VD2 4 /* VD2/Port used for IPinIP*/
62+
63+
#define PGID_UC_FLOOD 0
64+
#define PGID_MC_FLOOD 1
65+
#define PGID_IPV4_MC_DATA 2
66+
#define PGID_IPV4_MC_CTRL 3
67+
#define PGID_IPV6_MC_DATA 4
68+
#define PGID_IPV6_MC_CTRL 5
69+
#define PGID_BCAST 6
70+
#define PGID_CPU 7
71+
#define PGID_MCAST_START 8
7472

7573
#define PGID_TABLE_SIZE 3290
7674

@@ -500,6 +498,7 @@ enum sparx5_pgid_type {
500498
void sparx5_pgid_init(struct sparx5 *spx5);
501499
int sparx5_pgid_alloc_mcast(struct sparx5 *spx5, u16 *idx);
502500
int sparx5_pgid_free(struct sparx5 *spx5, u16 idx);
501+
int sparx5_get_pgid(struct sparx5 *sparx5, int pgid);
503502

504503
/* sparx5_pool.c */
505504
struct sparx5_pool_entry {
@@ -516,6 +515,7 @@ int sparx5_pool_get_with_idx(struct sparx5_pool_entry *pool, int size, u32 idx,
516515
/* sparx5_port.c */
517516
int sparx5_port_mux_set(struct sparx5 *sparx5, struct sparx5_port *port,
518517
struct sparx5_port_config *conf);
518+
int sparx5_get_internal_port(struct sparx5 *sparx5, int port);
519519

520520
/* sparx5_sdlb.c */
521521
#define SPX5_SDLB_PUP_TOKEN_DISABLE 0x1FFF

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ void sparx5_set_port_ifh(struct sparx5 *sparx5, void *ifh_hdr, u16 portno)
6868
/* MISC.PIPELINE_ACT */
6969
ifh_encode_bitfield(ifh_hdr, 1, 42, 3);
7070
/* FWD.SRC_PORT = CPU */
71-
ifh_encode_bitfield(ifh_hdr, SPX5_PORT_CPU, 46, 7);
71+
ifh_encode_bitfield(ifh_hdr, sparx5_get_pgid(sparx5, SPX5_PORT_CPU_0),
72+
46, 7);
7273
/* FWD.SFLOW_ID (disable SFlow sampling) */
7374
ifh_encode_bitfield(ifh_hdr, 124, 57, 7);
7475
/* FWD.UPDATE_FCS = Enable. Enforce update of FCS. */
@@ -190,7 +191,8 @@ static int sparx5_set_mac_address(struct net_device *dev, void *p)
190191
sparx5_mact_forget(sparx5, dev->dev_addr, port->pvid);
191192

192193
/* Add new */
193-
sparx5_mact_learn(sparx5, PGID_CPU, addr->sa_data, port->pvid);
194+
sparx5_mact_learn(sparx5, sparx5_get_pgid(sparx5, PGID_CPU),
195+
addr->sa_data, port->pvid);
194196

195197
/* Record the address */
196198
eth_hw_addr_set(dev, addr->sa_data);

drivers/net/ethernet/microchip/sparx5/sparx5_packet.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ int sparx5_manual_injection_mode(struct sparx5 *sparx5)
317317
sparx5, QS_INJ_GRP_CFG(INJ_QUEUE));
318318

319319
/* CPU ports capture setup */
320-
for (portno = SPX5_PORT_CPU_0; portno <= SPX5_PORT_CPU_1; portno++) {
320+
for (portno = sparx5_get_internal_port(sparx5, SPX5_PORT_CPU_0);
321+
portno <= sparx5_get_internal_port(sparx5, SPX5_PORT_CPU_1);
322+
portno++) {
321323
/* ASM CPU port: No preamble, IFH, enable padding */
322324
spx5_wr(ASM_PORT_CFG_PAD_ENA_SET(1) |
323325
ASM_PORT_CFG_NO_PREAMBLE_ENA_SET(1) |

drivers/net/ethernet/microchip/sparx5/sparx5_pgid.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void sparx5_pgid_init(struct sparx5 *spx5)
1111
/* Reserved for unicast, flood control, broadcast, and CPU.
1212
* These cannot be freed.
1313
*/
14-
for (i = 0; i <= PGID_CPU; i++)
14+
for (i = 0; i <= sparx5_get_pgid(spx5, PGID_CPU); i++)
1515
spx5->pgid_map[i] = SPX5_PGID_RESERVED;
1616
}
1717

@@ -22,7 +22,8 @@ int sparx5_pgid_alloc_mcast(struct sparx5 *spx5, u16 *idx)
2222
/* The multicast area starts at index 65, but the first 7
2323
* are reserved for flood masks and CPU. Start alloc after that.
2424
*/
25-
for (i = PGID_MCAST_START; i < spx5->data->consts->n_pgids; i++) {
25+
for (i = sparx5_get_pgid(spx5, PGID_MCAST_START);
26+
i < spx5->data->consts->n_pgids; i++) {
2627
if (spx5->pgid_map[i] == SPX5_PGID_FREE) {
2728
spx5->pgid_map[i] = SPX5_PGID_MULTICAST;
2829
*idx = i;
@@ -35,7 +36,8 @@ int sparx5_pgid_alloc_mcast(struct sparx5 *spx5, u16 *idx)
3536

3637
int sparx5_pgid_free(struct sparx5 *spx5, u16 idx)
3738
{
38-
if (idx <= PGID_CPU || idx >= spx5->data->consts->n_pgids)
39+
if (idx <= sparx5_get_pgid(spx5, PGID_CPU) ||
40+
idx >= spx5->data->consts->n_pgids)
3941
return -EINVAL;
4042

4143
if (spx5->pgid_map[idx] == SPX5_PGID_FREE)
@@ -44,3 +46,8 @@ int sparx5_pgid_free(struct sparx5 *spx5, u16 idx)
4446
spx5->pgid_map[idx] = SPX5_PGID_FREE;
4547
return 0;
4648
}
49+
50+
int sparx5_get_pgid(struct sparx5 *sparx5, int pgid)
51+
{
52+
return sparx5->data->consts->n_ports + pgid;
53+
}

drivers/net/ethernet/microchip/sparx5/sparx5_port.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,3 +1352,8 @@ int sparx5_port_qos_default_set(const struct sparx5_port *port,
13521352

13531353
return 0;
13541354
}
1355+
1356+
int sparx5_get_internal_port(struct sparx5 *sparx5, int port)
1357+
{
1358+
return sparx5->data->consts->n_ports + port;
1359+
}

drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,34 @@ static int sparx5_port_attr_pre_bridge_flags(struct sparx5_port *port,
3232
static void sparx5_port_update_mcast_ip_flood(struct sparx5_port *port, bool flood_flag)
3333
{
3434
bool should_flood = flood_flag || port->is_mrouter;
35+
struct sparx5 *sparx5 = port->sparx5;
3536
int pgid;
3637

37-
for (pgid = PGID_IPV4_MC_DATA; pgid <= PGID_IPV6_MC_CTRL; pgid++)
38+
for (pgid = sparx5_get_pgid(sparx5, PGID_IPV4_MC_DATA);
39+
pgid <= sparx5_get_pgid(sparx5, PGID_IPV6_MC_CTRL); pgid++)
3840
sparx5_pgid_update_mask(port, pgid, should_flood);
3941
}
4042

4143
static void sparx5_port_attr_bridge_flags(struct sparx5_port *port,
4244
struct switchdev_brport_flags flags)
4345
{
46+
struct sparx5 *sparx5 = port->sparx5;
47+
4448
if (flags.mask & BR_MCAST_FLOOD) {
45-
sparx5_pgid_update_mask(port, PGID_MC_FLOOD, !!(flags.val & BR_MCAST_FLOOD));
49+
sparx5_pgid_update_mask(port,
50+
sparx5_get_pgid(sparx5, PGID_MC_FLOOD),
51+
!!(flags.val & BR_MCAST_FLOOD));
4652
sparx5_port_update_mcast_ip_flood(port, !!(flags.val & BR_MCAST_FLOOD));
4753
}
4854

4955
if (flags.mask & BR_FLOOD)
50-
sparx5_pgid_update_mask(port, PGID_UC_FLOOD, !!(flags.val & BR_FLOOD));
56+
sparx5_pgid_update_mask(port,
57+
sparx5_get_pgid(sparx5, PGID_UC_FLOOD),
58+
!!(flags.val & BR_FLOOD));
5159
if (flags.mask & BR_BCAST_FLOOD)
52-
sparx5_pgid_update_mask(port, PGID_BCAST, !!(flags.val & BR_BCAST_FLOOD));
60+
sparx5_pgid_update_mask(port,
61+
sparx5_get_pgid(sparx5, PGID_BCAST),
62+
!!(flags.val & BR_BCAST_FLOOD));
5363
}
5464

5565
static void sparx5_attr_stp_state_set(struct sparx5_port *port,
@@ -219,7 +229,8 @@ static void sparx5_port_bridge_leave(struct sparx5_port *port,
219229
port->vid = NULL_VID;
220230

221231
/* Forward frames to CPU */
222-
sparx5_mact_learn(sparx5, PGID_CPU, port->ndev->dev_addr, 0);
232+
sparx5_mact_learn(sparx5, sparx5_get_pgid(sparx5, PGID_CPU),
233+
port->ndev->dev_addr, 0);
223234

224235
/* Port enters in host more therefore restore mc list */
225236
__dev_mc_sync(port->ndev, sparx5_mc_sync, sparx5_mc_unsync);
@@ -254,7 +265,8 @@ static int sparx5_port_add_addr(struct net_device *dev, bool up)
254265
u16 vid = port->pvid;
255266

256267
if (up)
257-
sparx5_mact_learn(sparx5, PGID_CPU, port->ndev->dev_addr, vid);
268+
sparx5_mact_learn(sparx5, sparx5_get_pgid(sparx5, PGID_CPU),
269+
port->ndev->dev_addr, vid);
258270
else
259271
sparx5_mact_forget(sparx5, port->ndev->dev_addr, vid);
260272

@@ -330,7 +342,8 @@ static void sparx5_switchdev_bridge_fdb_event_work(struct work_struct *work)
330342
switch (switchdev_work->event) {
331343
case SWITCHDEV_FDB_ADD_TO_DEVICE:
332344
if (host_addr)
333-
sparx5_add_mact_entry(sparx5, dev, PGID_CPU,
345+
sparx5_add_mact_entry(sparx5, dev,
346+
sparx5_get_pgid(sparx5, PGID_CPU),
334347
fdb_info->addr, vid);
335348
else
336349
sparx5_add_mact_entry(sparx5, port->ndev, port->portno,
@@ -418,8 +431,8 @@ static int sparx5_handle_port_vlan_add(struct net_device *dev,
418431
switchdev_blocking_nb);
419432

420433
/* Flood broadcast to CPU */
421-
sparx5_mact_learn(sparx5, PGID_BCAST, dev->broadcast,
422-
v->vid);
434+
sparx5_mact_learn(sparx5, sparx5_get_pgid(sparx5, PGID_BCAST),
435+
dev->broadcast, v->vid);
423436
return 0;
424437
}
425438

drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ void sparx5_update_fwd(struct sparx5 *sparx5)
168168
bitmap_to_arr32(mask, sparx5->bridge_fwd_mask, SPX5_PORTS);
169169

170170
/* Update flood masks */
171-
for (port = PGID_UC_FLOOD; port <= PGID_BCAST; port++) {
171+
for (port = sparx5_get_pgid(sparx5, PGID_UC_FLOOD);
172+
port <= sparx5_get_pgid(sparx5, PGID_BCAST); port++) {
172173
spx5_wr(mask[0], sparx5, ANA_AC_PGID_CFG(port));
173174
if (is_sparx5(sparx5)) {
174175
spx5_wr(mask[1], sparx5, ANA_AC_PGID_CFG1(port));

0 commit comments

Comments
 (0)