History

Merge branch 'net-dsa-microchip-make-ksz8795-driver-more-versatile'

Michael Grzeschik says: ==================== net: dsa: microchip: make ksz8795 driver more versatile This series changes the ksz8795 driver to use more dynamic variables instead of static defines. The purpose is to prepare the driver to be used with other microchip switches with a similar layout. ====================

Jakub Kicinski committed 5 years ago

Commit 6ec1dfb2 parents 9693e08 02ffbb05 files · +40 −61Browse files

Unified · Split

5 files
  1. drivers/net/dsa/microchip/ksz8795.c +33 −38
  2. drivers/net/dsa/microchip/ksz8795_reg.h +0 −10
  3. drivers/net/dsa/microchip/ksz9477.c +5 −9
  4. drivers/net/dsa/microchip/ksz_common.c +2 −2
  5. drivers/net/dsa/microchip/ksz_common.h +0 −2
drivers/net/dsa/microchip/ksz8795.c+33−38
@@ -23,7 +23,7 @@ · 22 unmodified lines
2323
2424 static const struct {
2525 char string[ETH_GSTRING_LEN];
26−} mib_names[TOTAL_SWITCH_COUNTER_NUM] = {
26+} mib_names[] = {
2727 { "rx_hi" },
2828 { "rx_undersize" },
2929 { "rx_fragments" },
@@ -125,7 +125,7 @@ static void ksz8795_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, · 95 unmodified lines
125125 u8 check;
126126 int loop;
127127
128− ctrl_addr = addr + SWITCH_COUNTER_NUM * port;
128+ ctrl_addr = addr + dev->reg_mib_cnt * port;
129129 ctrl_addr |= IND_ACC_TABLE(TABLE_MIB | TABLE_READ);
130130
131131 mutex_lock(&dev->alu_mutex);
@@ -156,7 +156,7 @@ static void ksz8795_r_mib_pkt(struct ksz_device *dev, int port, u16 addr, · 24 unmodified lines
156156 u8 check;
157157 int loop;
158158
159− addr -= SWITCH_COUNTER_NUM;
159+ addr -= dev->reg_mib_cnt;
160160 ctrl_addr = (KS_MIB_TOTAL_RX_1 - KS_MIB_TOTAL_RX_0) * port;
161161 ctrl_addr += addr + KS_MIB_TOTAL_RX_0;
162162 ctrl_addr |= IND_ACC_TABLE(TABLE_MIB | TABLE_READ);
@@ -418,8 +418,8 @@ static void ksz8795_r_vlan_entries(struct ksz_device *dev, u16 addr) · 255 unmodified lines
418418 int i;
419419
420420 ksz8795_r_table(dev, TABLE_VLAN, addr, &data);
421− addr *= 4;
422− for (i = 0; i < 4; i++) {
421+ addr *= dev->phy_port_cnt;
422+ for (i = 0; i < dev->phy_port_cnt; i++) {
423423 dev->vlan_cache[addr + i].table[0] = (u16)data;
424424 data >>= VLAN_TABLE_S;
425425 }
@@ -433,7 +433,7 @@ static void ksz8795_r_vlan_table(struct ksz_device *dev, u16 vid, u16 *vlan) · 7 unmodified lines
433433 u64 buf;
434434
435435 data = (u16 *)&buf;
436− addr = vid / 4;
436+ addr = vid / dev->phy_port_cnt;
437437 index = vid & 3;
438438 ksz8795_r_table(dev, TABLE_VLAN, addr, &buf);
439439 *vlan = data[index];
@@ -447,7 +447,7 @@ static void ksz8795_w_vlan_table(struct ksz_device *dev, u16 vid, u16 vlan) · 7 unmodified lines
447447 u64 buf;
448448
449449 data = (u16 *)&buf;
450− addr = vid / 4;
450+ addr = vid / dev->phy_port_cnt;
451451 index = vid & 3;
452452 ksz8795_r_table(dev, TABLE_VLAN, addr, &buf);
453453 data[index] = vlan;
@@ -654,9 +654,10 @@ static enum dsa_tag_protocol ksz8795_get_tag_protocol(struct dsa_switch *ds, · 200 unmodified lines
654654 static void ksz8795_get_strings(struct dsa_switch *ds, int port,
655655 u32 stringset, uint8_t *buf)
656656 {
657+ struct ksz_device *dev = ds->priv;
657658 int i;
658659
659− for (i = 0; i < TOTAL_SWITCH_COUNTER_NUM; i++) {
660+ for (i = 0; i < dev->mib_cnt; i++) {
660661 memcpy(buf + i * ETH_GSTRING_LEN, mib_names[i].string,
661662 ETH_GSTRING_LEN);
662663 }
@@ -691,12 +692,12 @@ static void ksz8795_port_stp_state_set(struct dsa_switch *ds, int port, · 28 unmodified lines
691692 switch (state) {
692693 case BR_STATE_DISABLED:
693694 data |= PORT_LEARN_DISABLE;
694− if (port < SWITCH_PORT_NUM)
695+ if (port < dev->phy_port_cnt)
695696 member = 0;
696697 break;
697698 case BR_STATE_LISTENING:
698699 data |= (PORT_RX_ENABLE | PORT_LEARN_DISABLE);
699− if (port < SWITCH_PORT_NUM &&
700+ if (port < dev->phy_port_cnt &&
700701 p->stp_state == BR_STATE_DISABLED)
701702 member = dev->host_mask | p->vid_member;
702703 break;
@@ -720,7 +721,7 @@ static void ksz8795_port_stp_state_set(struct dsa_switch *ds, int port, · 17 unmodified lines
720721 break;
721722 case BR_STATE_BLOCKING:
722723 data |= PORT_LEARN_DISABLE;
723− if (port < SWITCH_PORT_NUM &&
724+ if (port < dev->phy_port_cnt &&
724725 p->stp_state == BR_STATE_DISABLED)
725726 member = dev->host_mask | p->vid_member;
726727 break;
@@ -750,17 +751,17 @@ static void ksz8795_port_stp_state_set(struct dsa_switch *ds, int port, · 23 unmodified lines
750751
751752 static void ksz8795_flush_dyn_mac_table(struct ksz_device *dev, int port)
752753 {
753− u8 learn[TOTAL_PORT_NUM];
754+ u8 learn[DSA_MAX_PORTS];
754755 int first, index, cnt;
755756 struct ksz_port *p;
756757
757− if ((uint)port < TOTAL_PORT_NUM) {
758+ if ((uint)port < dev->port_cnt) {
758759 first = port;
759760 cnt = port + 1;
760761 } else {
761762 /* Flush all ports. */
762763 first = 0;
763− cnt = dev->mib_port_cnt;
764+ cnt = dev->port_cnt;
764765 }
765766 for (index = first; index < cnt; index++) {
766767 p = &dev->ports[index];
@@ -992,8 +993,6 @@ static void ksz8795_config_cpu_port(struct dsa_switch *ds) · 225 unmodified lines
992993 u8 remote;
993994 int i;
994995
995− ds->num_ports = dev->port_cnt + 1;
996−
997996 /* Switch marks the maximum frame with extra byte as oversize. */
998997 ksz_cfg(dev, REG_SW_CTRL_2, SW_LEGAL_PACKET_DISABLE, true);
999998 ksz_cfg(dev, S_TAIL_TAG_CTRL, SW_TAIL_TAG_ENABLE, true);
@@ -1005,7 +1004,7 @@ static void ksz8795_config_cpu_port(struct dsa_switch *ds) · 5 unmodified lines
10051004 ksz8795_port_setup(dev, dev->cpu_port, true);
10061005 dev->member = dev->host_mask;
10071006
1008− for (i = 0; i < SWITCH_PORT_NUM; i++) {
1007+ for (i = 0; i < dev->phy_port_cnt; i++) {
10091008 p = &dev->ports[i];
10101009
10111010 /* Initialize to non-zero so that ksz_cfg_port_member() will
@@ -1016,7 +1015,7 @@ static void ksz8795_config_cpu_port(struct dsa_switch *ds) · 4 unmodified lines
10161015 ksz8795_port_stp_state_set(ds, i, BR_STATE_DISABLED);
10171016
10181017 /* Last port may be disabled. */
1019− if (i == dev->port_cnt)
1018+ if (i == dev->phy_port_cnt)
10201019 break;
10211020 p->on = 1;
10221021 p->phy = 1;
@@ -1085,7 +1084,7 @@ static int ksz8795_setup(struct dsa_switch *ds) · 62 unmodified lines
10851084 (BROADCAST_STORM_VALUE *
10861085 BROADCAST_STORM_PROT_RATE) / 100);
10871086
1088− for (i = 0; i < VLAN_TABLE_ENTRIES; i++)
1087+ for (i = 0; i < (dev->num_vlans / 4); i++)
10891088 ksz8795_r_vlan_entries(dev, i);
10901089
10911090 /* Setup STP address for STP operation. */
@@ -1150,10 +1149,6 @@ static int ksz8795_switch_detect(struct ksz_device *dev) · 58 unmodified lines
11501149 (id2 != CHIP_ID_94 && id2 != CHIP_ID_95))
11511150 return -ENODEV;
11521151
1153− dev->mib_port_cnt = TOTAL_PORT_NUM;
1154− dev->phy_port_cnt = SWITCH_PORT_NUM;
1155− dev->port_cnt = SWITCH_PORT_NUM;
1156−
11571152 if (id2 == CHIP_ID_95) {
11581153 u8 val;
11591154
@@ -1162,17 +1157,12 @@ static int ksz8795_switch_detect(struct ksz_device *dev) · 2 unmodified lines
11621157 if (val & PORT_FIBER_MODE)
11631158 id2 = 0x65;
11641159 } else if (id2 == CHIP_ID_94) {
1165− dev->port_cnt--;
1166− dev->last_port = dev->port_cnt;
11671160 id2 = 0x94;
11681161 }
11691162 id16 &= ~0xff;
11701163 id16 |= id2;
11711164 dev->chip_id = id16;
11721165
1173− dev->cpu_port = dev->mib_port_cnt - 1;
1174− dev->host_mask = BIT(dev->cpu_port);
1175−
11761166 return 0;
11771167 }
11781168
@@ -1194,7 +1184,7 @@ static const struct ksz_chip_data ksz8795_switch_chips[] = { · 15 unmodified lines
11941184 .num_alus = 0,
11951185 .num_statics = 8,
11961186 .cpu_ports = 0x10, /* can be configured as cpu port */
1197− .port_cnt = 4, /* total physical port count */
1187+ .port_cnt = 5, /* total cpu and user ports */
11981188 },
11991189 {
12001190 .chip_id = 0x8794,
@@ -1203,7 +1193,7 @@ static const struct ksz_chip_data ksz8795_switch_chips[] = { · 2 unmodified lines
12031193 .num_alus = 0,
12041194 .num_statics = 8,
12051195 .cpu_ports = 0x10, /* can be configured as cpu port */
1206− .port_cnt = 3, /* total physical port count */
1196+ .port_cnt = 4, /* total cpu and user ports */
12071197 },
12081198 {
12091199 .chip_id = 0x8765,
@@ -1212,7 +1202,7 @@ static const struct ksz_chip_data ksz8795_switch_chips[] = { · 2 unmodified lines
12121202 .num_alus = 0,
12131203 .num_statics = 8,
12141204 .cpu_ports = 0x10, /* can be configured as cpu port */
1215− .port_cnt = 4, /* total physical port count */
1205+ .port_cnt = 5, /* total cpu and user ports */
12161206 },
12171207 };
12181208
@@ -1244,27 +1234,32 @@ static int ksz8795_switch_init(struct ksz_device *dev) · 25 unmodified lines
12441234 dev->port_mask = BIT(dev->port_cnt) - 1;
12451235 dev->port_mask |= dev->host_mask;
12461236
1247− dev->reg_mib_cnt = SWITCH_COUNTER_NUM;
1248− dev->mib_cnt = TOTAL_SWITCH_COUNTER_NUM;
1237+ dev->reg_mib_cnt = KSZ8795_COUNTER_NUM;
1238+ dev->mib_cnt = ARRAY_SIZE(mib_names);
1239+
1240+ dev->phy_port_cnt = dev->port_cnt - 1;
1241+
1242+ dev->cpu_port = dev->port_cnt - 1;
1243+ dev->host_mask = BIT(dev->cpu_port);
12491244
1250− i = dev->mib_port_cnt;
1251− dev->ports = devm_kzalloc(dev->dev, sizeof(struct ksz_port) * i,
1245+ dev->ports = devm_kzalloc(dev->dev,
1246+ dev->port_cnt * sizeof(struct ksz_port),
12521247 GFP_KERNEL);
12531248 if (!dev->ports)
12541249 return -ENOMEM;
1255− for (i = 0; i < dev->mib_port_cnt; i++) {
1250+ for (i = 0; i < dev->port_cnt; i++) {
12561251 mutex_init(&dev->ports[i].mib.cnt_mutex);
12571252 dev->ports[i].mib.counters =
12581253 devm_kzalloc(dev->dev,
12591254 sizeof(u64) *
1260− (TOTAL_SWITCH_COUNTER_NUM + 1),
1255+ (dev->mib_cnt + 1),
12611256 GFP_KERNEL);
12621257 if (!dev->ports[i].mib.counters)
12631258 return -ENOMEM;
12641259 }
12651260
12661261 /* set the real number of ports */
1267− dev->ds->num_ports = dev->port_cnt + 1;
1262+ dev->ds->num_ports = dev->port_cnt;
12681263
12691264 return 0;
12701265 }
drivers/net/dsa/microchip/ksz8795_reg.h+0−10
@@ -846,16 +846,7 @@ · 845 unmodified lines
846846
847847 #define KS_PRIO_IN_REG 4
848848
849−#define TOTAL_PORT_NUM 5
850−
851−/* Host port can only be last of them. */
852−#define SWITCH_PORT_NUM (TOTAL_PORT_NUM - 1)
853−
854849 #define KSZ8795_COUNTER_NUM 0x20
855−#define TOTAL_KSZ8795_COUNTER_NUM (KSZ8795_COUNTER_NUM + 4)
856−
857−#define SWITCH_COUNTER_NUM KSZ8795_COUNTER_NUM
858−#define TOTAL_SWITCH_COUNTER_NUM TOTAL_KSZ8795_COUNTER_NUM
859850
860851 /* Common names used by other drivers */
861852
@@ -998,7 +989,6 @@ · 136 unmodified lines
998989 #define TAIL_TAG_OVERRIDE BIT(6)
999990 #define TAIL_TAG_LOOKUP BIT(7)
1000991
1001−#define VLAN_TABLE_ENTRIES (4096 / 4)
1002992 #define FID_ENTRIES 128
1003993
1004994 #endif
drivers/net/dsa/microchip/ksz9477.c+5−9
@@ -478,7 +478,7 @@ static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port) · 477 unmodified lines
478478 SW_FLUSH_OPTION_M << SW_FLUSH_OPTION_S,
479479 SW_FLUSH_OPTION_DYN_MAC << SW_FLUSH_OPTION_S);
480480
481− if (port < dev->mib_port_cnt) {
481+ if (port < dev->port_cnt) {
482482 /* flush individual port */
483483 ksz_pread8(dev, port, P_STP_CTRL, &data);
484484 if (!(data & PORT_LEARN_DISABLE))
@@ -1267,8 +1267,6 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds) · 782 unmodified lines
12671267 struct ksz_port *p;
12681268 int i;
12691269
1270− ds->num_ports = dev->port_cnt;
1271−
12721270 for (i = 0; i < dev->port_cnt; i++) {
12731271 if (dsa_is_cpu_port(ds, i) && (dev->cpu_ports & (1 << i))) {
12741272 phy_interface_t interface;
@@ -1319,7 +1317,7 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds) · 44 unmodified lines
13191317
13201318 dev->member = dev->host_mask;
13211319
1322− for (i = 0; i < dev->mib_port_cnt; i++) {
1320+ for (i = 0; i < dev->port_cnt; i++) {
13231321 if (i == dev->cpu_port)
13241322 continue;
13251323 p = &dev->ports[i];
@@ -1446,7 +1444,6 @@ static int ksz9477_switch_detect(struct ksz_device *dev) · 120 unmodified lines
14461444 return ret;
14471445
14481446 /* Number of ports can be reduced depending on chip. */
1449− dev->mib_port_cnt = TOTAL_PORT_NUM;
14501447 dev->phy_port_cnt = 5;
14511448
14521449 /* Default capability is gigabit capable. */
@@ -1463,7 +1460,6 @@ static int ksz9477_switch_detect(struct ksz_device *dev) · 10 unmodified lines
14631460 /* Chip does not support gigabit. */
14641461 if (data8 & SW_QW_ABLE)
14651462 dev->features &= ~GBIT_SUPPORT;
1466− dev->mib_port_cnt = 3;
14671463 dev->phy_port_cnt = 2;
14681464 } else {
14691465 dev_info(dev->dev, "Found KSZ9477 or compatible\n");
@@ -1566,12 +1562,12 @@ static int ksz9477_switch_init(struct ksz_device *dev) · 96 unmodified lines
15661562 dev->reg_mib_cnt = SWITCH_COUNTER_NUM;
15671563 dev->mib_cnt = TOTAL_SWITCH_COUNTER_NUM;
15681564
1569− i = dev->mib_port_cnt;
1570− dev->ports = devm_kzalloc(dev->dev, sizeof(struct ksz_port) * i,
1565+ dev->ports = devm_kzalloc(dev->dev,
1566+ dev->port_cnt * sizeof(struct ksz_port),
15711567 GFP_KERNEL);
15721568 if (!dev->ports)
15731569 return -ENOMEM;
1574− for (i = 0; i < dev->mib_port_cnt; i++) {
1570+ for (i = 0; i < dev->port_cnt; i++) {
15751571 mutex_init(&dev->ports[i].mib.cnt_mutex);
15761572 dev->ports[i].mib.counters =
15771573 devm_kzalloc(dev->dev,
drivers/net/dsa/microchip/ksz_common.c+2−2
@@ -72,7 +72,7 @@ static void ksz_mib_read_work(struct work_struct *work) · 71 unmodified lines
7272 struct ksz_port *p;
7373 int i;
7474
75− for (i = 0; i < dev->mib_port_cnt; i++) {
75+ for (i = 0; i < dev->port_cnt; i++) {
7676 if (dsa_is_unused_port(dev->ds, i))
7777 continue;
7878
@@ -103,7 +103,7 @@ void ksz_init_mib_timer(struct ksz_device *dev) · 24 unmodified lines
103103
104104 INIT_DELAYED_WORK(&dev->mib_read, ksz_mib_read_work);
105105
106− for (i = 0; i < dev->mib_port_cnt; i++)
106+ for (i = 0; i < dev->port_cnt; i++)
107107 dev->dev_ops->port_init_cnt(dev, i);
108108 }
109109 EXPORT_SYMBOL_GPL(ksz_init_mib_timer);
drivers/net/dsa/microchip/ksz_common.h+0−2
@@ -71,8 +71,6 @@ struct ksz_device { · 70 unmodified lines
7171 int port_cnt;
7272 int reg_mib_cnt;
7373 int mib_cnt;
74− int mib_port_cnt;
75− int last_port; /* ports after that not used */
7674 phy_interface_t compat_interface;
7775 u32 regs_size;
7876 bool phy_errata_9477;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t