Skip to content

Commit 99949a7

Browse files
committed
Merge branch 'dsa-next'
Andrew Lunn says: ==================== DSA Mavell drivers refactoring and cleanup v1->v2: * Add missing signed-of-by: For patches authored by Guenter Roeck. * Add Reviewed by from Guenter Roack to patch #5. This is a collection of patches again net-next from today containing refactoring and consolidate of code, cleanups and using #define's to replace register numbers. Patch #1 Swaps the 6131 driver to use the consolidated setup code. Patch #2 Moves the Switch IDs used during probe into a central location. We need these later so that we can differentiate the different features the devices have. Patch #3 Makes the 6131 driver set the number of ports in the private state structure. It then uses this, rather than hard coded maximum number of ports. Patch #4 Similar to Patch #3, but for the 6123_61_65 driver. Patch #5 Similar to Patch #3, and #4, but for all the remaining drivers. This greatly increases the similarity of the code between drivers, allow further patches to consolidate the duplicated code. Patch #6 Consolidate the switch reset code, which has two minor variants. Removes around 35 lines per driver. Patch #7 Moves phy page access functions out of the 6352 driver into the shared code. Currently only the 6352 driver uses this, but it is likely other devices will come along wanting this functionality. Patch #8 Consolidates the code used to access phy registers. Removes around 40 lines of code per driver. Patch #9 Fixes missing mutex locking in the EEE code, and refactors the code a bit to make it more understandable with respect to locks. Patch #10 Consolidates reading statistics. This is very similar code for all devices, but the number of available statistics differ, which can be determined from the product ID. Removes around 65 lines per driver. Patch #11 Add #defines for registers, and bits within the registers. For the moment, this is limited to the shared code. The individual drivers will be converted once the remaining duplicated code is consolidated Patch #12 Fix broken statistic counters on the 6172. The 6352 family requires the port number is poked into a different set of bits in the register compared to other devices. Many thanks to Guenter Roeck for repeatedly reviewing the patches and testing them on his hardware. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 05e8bb8 + f3a8b6b commit 99949a7

File tree

6 files changed

+728
-764
lines changed

6 files changed

+728
-764
lines changed

drivers/net/dsa/mv88e6123_61_65.c

Lines changed: 30 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -25,66 +25,33 @@ static char *mv88e6123_61_65_probe(struct device *host_dev, int sw_addr)
2525
if (bus == NULL)
2626
return NULL;
2727

28-
ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), 0x03);
28+
ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), PORT_SWITCH_ID);
2929
if (ret >= 0) {
30-
if (ret == 0x1212)
30+
if (ret == PORT_SWITCH_ID_6123_A1)
3131
return "Marvell 88E6123 (A1)";
32-
if (ret == 0x1213)
32+
if (ret == PORT_SWITCH_ID_6123_A2)
3333
return "Marvell 88E6123 (A2)";
34-
if ((ret & 0xfff0) == 0x1210)
34+
if ((ret & 0xfff0) == PORT_SWITCH_ID_6123)
3535
return "Marvell 88E6123";
3636

37-
if (ret == 0x1612)
37+
if (ret == PORT_SWITCH_ID_6161_A1)
3838
return "Marvell 88E6161 (A1)";
39-
if (ret == 0x1613)
39+
if (ret == PORT_SWITCH_ID_6161_A2)
4040
return "Marvell 88E6161 (A2)";
41-
if ((ret & 0xfff0) == 0x1610)
41+
if ((ret & 0xfff0) == PORT_SWITCH_ID_6161)
4242
return "Marvell 88E6161";
4343

44-
if (ret == 0x1652)
44+
if (ret == PORT_SWITCH_ID_6165_A1)
4545
return "Marvell 88E6165 (A1)";
46-
if (ret == 0x1653)
46+
if (ret == PORT_SWITCH_ID_6165_A2)
4747
return "Marvell 88e6165 (A2)";
48-
if ((ret & 0xfff0) == 0x1650)
48+
if ((ret & 0xfff0) == PORT_SWITCH_ID_6165)
4949
return "Marvell 88E6165";
5050
}
5151

5252
return NULL;
5353
}
5454

55-
static int mv88e6123_61_65_switch_reset(struct dsa_switch *ds)
56-
{
57-
int i;
58-
int ret;
59-
unsigned long timeout;
60-
61-
/* Set all ports to the disabled state. */
62-
for (i = 0; i < 8; i++) {
63-
ret = REG_READ(REG_PORT(i), 0x04);
64-
REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
65-
}
66-
67-
/* Wait for transmit queues to drain. */
68-
usleep_range(2000, 4000);
69-
70-
/* Reset the switch. */
71-
REG_WRITE(REG_GLOBAL, 0x04, 0xc400);
72-
73-
/* Wait up to one second for reset to complete. */
74-
timeout = jiffies + 1 * HZ;
75-
while (time_before(jiffies, timeout)) {
76-
ret = REG_READ(REG_GLOBAL, 0x00);
77-
if ((ret & 0xc800) == 0xc800)
78-
break;
79-
80-
usleep_range(1000, 2000);
81-
}
82-
if (time_after(jiffies, timeout))
83-
return -ETIMEDOUT;
84-
85-
return 0;
86-
}
87-
8855
static int mv88e6123_61_65_setup_global(struct dsa_switch *ds)
8956
{
9057
int ret;
@@ -271,14 +238,27 @@ static int mv88e6123_61_65_setup_port(struct dsa_switch *ds, int p)
271238

272239
static int mv88e6123_61_65_setup(struct dsa_switch *ds)
273240
{
241+
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
274242
int i;
275243
int ret;
276244

277245
ret = mv88e6xxx_setup_common(ds);
278246
if (ret < 0)
279247
return ret;
280248

281-
ret = mv88e6123_61_65_switch_reset(ds);
249+
switch (ps->id) {
250+
case PORT_SWITCH_ID_6123:
251+
ps->num_ports = 3;
252+
break;
253+
case PORT_SWITCH_ID_6161:
254+
case PORT_SWITCH_ID_6165:
255+
ps->num_ports = 6;
256+
break;
257+
default:
258+
return -ENODEV;
259+
}
260+
261+
ret = mv88e6xxx_switch_reset(ds, false);
282262
if (ret < 0)
283263
return ret;
284264

@@ -288,7 +268,7 @@ static int mv88e6123_61_65_setup(struct dsa_switch *ds)
288268
if (ret < 0)
289269
return ret;
290270

291-
for (i = 0; i < 6; i++) {
271+
for (i = 0; i < ps->num_ports; i++) {
292272
ret = mv88e6123_61_65_setup_port(ds, i);
293273
if (ret < 0)
294274
return ret;
@@ -297,108 +277,18 @@ static int mv88e6123_61_65_setup(struct dsa_switch *ds)
297277
return 0;
298278
}
299279

300-
static int mv88e6123_61_65_port_to_phy_addr(int port)
301-
{
302-
if (port >= 0 && port <= 4)
303-
return port;
304-
return -1;
305-
}
306-
307-
static int
308-
mv88e6123_61_65_phy_read(struct dsa_switch *ds, int port, int regnum)
309-
{
310-
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
311-
int addr = mv88e6123_61_65_port_to_phy_addr(port);
312-
int ret;
313-
314-
mutex_lock(&ps->phy_mutex);
315-
ret = mv88e6xxx_phy_read(ds, addr, regnum);
316-
mutex_unlock(&ps->phy_mutex);
317-
return ret;
318-
}
319-
320-
static int
321-
mv88e6123_61_65_phy_write(struct dsa_switch *ds,
322-
int port, int regnum, u16 val)
323-
{
324-
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
325-
int addr = mv88e6123_61_65_port_to_phy_addr(port);
326-
int ret;
327-
328-
mutex_lock(&ps->phy_mutex);
329-
ret = mv88e6xxx_phy_write(ds, addr, regnum, val);
330-
mutex_unlock(&ps->phy_mutex);
331-
return ret;
332-
}
333-
334-
static struct mv88e6xxx_hw_stat mv88e6123_61_65_hw_stats[] = {
335-
{ "in_good_octets", 8, 0x00, },
336-
{ "in_bad_octets", 4, 0x02, },
337-
{ "in_unicast", 4, 0x04, },
338-
{ "in_broadcasts", 4, 0x06, },
339-
{ "in_multicasts", 4, 0x07, },
340-
{ "in_pause", 4, 0x16, },
341-
{ "in_undersize", 4, 0x18, },
342-
{ "in_fragments", 4, 0x19, },
343-
{ "in_oversize", 4, 0x1a, },
344-
{ "in_jabber", 4, 0x1b, },
345-
{ "in_rx_error", 4, 0x1c, },
346-
{ "in_fcs_error", 4, 0x1d, },
347-
{ "out_octets", 8, 0x0e, },
348-
{ "out_unicast", 4, 0x10, },
349-
{ "out_broadcasts", 4, 0x13, },
350-
{ "out_multicasts", 4, 0x12, },
351-
{ "out_pause", 4, 0x15, },
352-
{ "excessive", 4, 0x11, },
353-
{ "collisions", 4, 0x1e, },
354-
{ "deferred", 4, 0x05, },
355-
{ "single", 4, 0x14, },
356-
{ "multiple", 4, 0x17, },
357-
{ "out_fcs_error", 4, 0x03, },
358-
{ "late", 4, 0x1f, },
359-
{ "hist_64bytes", 4, 0x08, },
360-
{ "hist_65_127bytes", 4, 0x09, },
361-
{ "hist_128_255bytes", 4, 0x0a, },
362-
{ "hist_256_511bytes", 4, 0x0b, },
363-
{ "hist_512_1023bytes", 4, 0x0c, },
364-
{ "hist_1024_max_bytes", 4, 0x0d, },
365-
{ "sw_in_discards", 4, 0x110, },
366-
{ "sw_in_filtered", 2, 0x112, },
367-
{ "sw_out_filtered", 2, 0x113, },
368-
};
369-
370-
static void
371-
mv88e6123_61_65_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
372-
{
373-
mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6123_61_65_hw_stats),
374-
mv88e6123_61_65_hw_stats, port, data);
375-
}
376-
377-
static void
378-
mv88e6123_61_65_get_ethtool_stats(struct dsa_switch *ds,
379-
int port, uint64_t *data)
380-
{
381-
mv88e6xxx_get_ethtool_stats(ds, ARRAY_SIZE(mv88e6123_61_65_hw_stats),
382-
mv88e6123_61_65_hw_stats, port, data);
383-
}
384-
385-
static int mv88e6123_61_65_get_sset_count(struct dsa_switch *ds)
386-
{
387-
return ARRAY_SIZE(mv88e6123_61_65_hw_stats);
388-
}
389-
390280
struct dsa_switch_driver mv88e6123_61_65_switch_driver = {
391281
.tag_protocol = DSA_TAG_PROTO_EDSA,
392282
.priv_size = sizeof(struct mv88e6xxx_priv_state),
393283
.probe = mv88e6123_61_65_probe,
394284
.setup = mv88e6123_61_65_setup,
395285
.set_addr = mv88e6xxx_set_addr_indirect,
396-
.phy_read = mv88e6123_61_65_phy_read,
397-
.phy_write = mv88e6123_61_65_phy_write,
286+
.phy_read = mv88e6xxx_phy_read,
287+
.phy_write = mv88e6xxx_phy_write,
398288
.poll_link = mv88e6xxx_poll_link,
399-
.get_strings = mv88e6123_61_65_get_strings,
400-
.get_ethtool_stats = mv88e6123_61_65_get_ethtool_stats,
401-
.get_sset_count = mv88e6123_61_65_get_sset_count,
289+
.get_strings = mv88e6xxx_get_strings,
290+
.get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
291+
.get_sset_count = mv88e6xxx_get_sset_count,
402292
#ifdef CONFIG_NET_DSA_HWMON
403293
.get_temp = mv88e6xxx_get_temp,
404294
#endif

0 commit comments

Comments
 (0)