Skip to content

Commit 3bcb896

Browse files
oleremdavem330
authored andcommitted
net: dsa: microchip: init predictable IPV to queue mapping for all non KSZ8xxx variants
Init priority to queue mapping in the way as it shown in IEEE 802.1Q mapping example. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Acked-by: Arun Ramadoss <arun.ramadoss@microchip.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c631250 commit 3bcb896

1 file changed

Lines changed: 33 additions & 24 deletions

File tree

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/of_net.h>
2525
#include <linux/micrel_phy.h>
2626
#include <net/dsa.h>
27+
#include <net/ieee8021q.h>
2728
#include <net/pkt_cls.h>
2829
#include <net/switchdev.h>
2930

@@ -2720,16 +2721,46 @@ static int ksz_port_mdb_del(struct dsa_switch *ds, int port,
27202721
return dev->dev_ops->mdb_del(dev, port, mdb, db);
27212722
}
27222723

2724+
static int ksz9477_set_default_prio_queue_mapping(struct ksz_device *dev,
2725+
int port)
2726+
{
2727+
u32 queue_map = 0;
2728+
int ipv;
2729+
2730+
for (ipv = 0; ipv < dev->info->num_ipvs; ipv++) {
2731+
int queue;
2732+
2733+
/* Traffic Type (TT) is corresponding to the Internal Priority
2734+
* Value (IPV) in the switch. Traffic Class (TC) is
2735+
* corresponding to the queue in the switch.
2736+
*/
2737+
queue = ieee8021q_tt_to_tc(ipv, dev->info->num_tx_queues);
2738+
if (queue < 0)
2739+
return queue;
2740+
2741+
queue_map |= queue << (ipv * KSZ9477_PORT_TC_MAP_S);
2742+
}
2743+
2744+
return ksz_pwrite32(dev, port, KSZ9477_PORT_MRI_TC_MAP__4, queue_map);
2745+
}
2746+
27232747
static int ksz_port_setup(struct dsa_switch *ds, int port)
27242748
{
27252749
struct ksz_device *dev = ds->priv;
2750+
int ret;
27262751

27272752
if (!dsa_is_user_port(ds, port))
27282753
return 0;
27292754

27302755
/* setup user port */
27312756
dev->dev_ops->port_setup(dev, port, false);
27322757

2758+
if (!is_ksz8(dev)) {
2759+
ret = ksz9477_set_default_prio_queue_mapping(dev, port);
2760+
if (ret)
2761+
return ret;
2762+
}
2763+
27332764
/* port_stp_state_set() will be called after to enable the port so
27342765
* there is no need to do anything.
27352766
*/
@@ -3589,8 +3620,7 @@ static int ksz_tc_ets_add(struct ksz_device *dev, int port,
35893620

35903621
static int ksz_tc_ets_del(struct ksz_device *dev, int port)
35913622
{
3592-
int ret, queue, tc_prio, s;
3593-
u32 queue_map = 0;
3623+
int ret, queue;
35943624

35953625
/* To restore the default chip configuration, set all queues to use the
35963626
* WRR scheduler with a weight of 1.
@@ -3602,31 +3632,10 @@ static int ksz_tc_ets_del(struct ksz_device *dev, int port)
36023632
return ret;
36033633
}
36043634

3605-
switch (dev->info->num_tx_queues) {
3606-
case 2:
3607-
s = 2;
3608-
break;
3609-
case 4:
3610-
s = 1;
3611-
break;
3612-
case 8:
3613-
s = 0;
3614-
break;
3615-
default:
3616-
return -EINVAL;
3617-
}
3618-
36193635
/* Revert the queue mapping for TC-priority to its default setting on
36203636
* the chip.
36213637
*/
3622-
for (tc_prio = 0; tc_prio < dev->info->num_ipvs; tc_prio++) {
3623-
int queue;
3624-
3625-
queue = tc_prio >> s;
3626-
queue_map |= queue << (tc_prio * KSZ9477_PORT_TC_MAP_S);
3627-
}
3628-
3629-
return ksz_pwrite32(dev, port, KSZ9477_PORT_MRI_TC_MAP__4, queue_map);
3638+
return ksz9477_set_default_prio_queue_mapping(dev, port);
36303639
}
36313640

36323641
static int ksz_tc_ets_validate(struct ksz_device *dev, int port,

0 commit comments

Comments
 (0)