1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Marvell 88e6xxx Ethernet switch single-chip support
4 *
5 * Copyright (c) 2008 Marvell Semiconductor
6 *
7 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
8 *
9 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
10 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
11 */
12
13 #include <linux/bitfield.h>
14 #include <linux/delay.h>
15 #include <linux/dsa/mv88e6xxx.h>
16 #include <linux/etherdevice.h>
17 #include <linux/ethtool.h>
18 #include <linux/if_bridge.h>
19 #include <linux/interrupt.h>
20 #include <linux/irq.h>
21 #include <linux/irqdomain.h>
22 #include <linux/jiffies.h>
23 #include <linux/list.h>
24 #include <linux/mdio.h>
25 #include <linux/module.h>
26 #include <linux/of_device.h>
27 #include <linux/of_irq.h>
28 #include <linux/of_mdio.h>
29 #include <linux/platform_data/mv88e6xxx.h>
30 #include <linux/netdevice.h>
31 #include <linux/gpio/consumer.h>
32 #include <linux/phylink.h>
33 #include <net/dsa.h>
34
35 #include "chip.h"
36 #include "devlink.h"
37 #include "global1.h"
38 #include "global2.h"
39 #include "hwtstamp.h"
40 #include "phy.h"
41 #include "port.h"
42 #include "ptp.h"
43 #include "serdes.h"
44 #include "smi.h"
45
assert_reg_lock(struct mv88e6xxx_chip * chip)46 static void assert_reg_lock(struct mv88e6xxx_chip *chip)
47 {
48 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
49 dev_err(chip->dev, "Switch registers lock not held!\n");
50 dump_stack();
51 }
52 }
53
mv88e6xxx_read(struct mv88e6xxx_chip * chip,int addr,int reg,u16 * val)54 int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
55 {
56 int err;
57
58 assert_reg_lock(chip);
59
60 err = mv88e6xxx_smi_read(chip, addr, reg, val);
61 if (err)
62 return err;
63
64 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
65 addr, reg, *val);
66
67 return 0;
68 }
69
mv88e6xxx_write(struct mv88e6xxx_chip * chip,int addr,int reg,u16 val)70 int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
71 {
72 int err;
73
74 assert_reg_lock(chip);
75
76 err = mv88e6xxx_smi_write(chip, addr, reg, val);
77 if (err)
78 return err;
79
80 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
81 addr, reg, val);
82
83 return 0;
84 }
85
mv88e6xxx_wait_mask(struct mv88e6xxx_chip * chip,int addr,int reg,u16 mask,u16 val)86 int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg,
87 u16 mask, u16 val)
88 {
89 const unsigned long timeout = jiffies + msecs_to_jiffies(50);
90 u16 data;
91 int err;
92 int i;
93
94 /* There's no bus specific operation to wait for a mask. Even
95 * if the initial poll takes longer than 50ms, always do at
96 * least one more attempt.
97 */
98 for (i = 0; time_before(jiffies, timeout) || (i < 2); i++) {
99 err = mv88e6xxx_read(chip, addr, reg, &data);
100 if (err)
101 return err;
102
103 if ((data & mask) == val)
104 return 0;
105
106 if (i < 2)
107 cpu_relax();
108 else
109 usleep_range(1000, 2000);
110 }
111
112 dev_err(chip->dev, "Timeout while waiting for switch\n");
113 return -ETIMEDOUT;
114 }
115
mv88e6xxx_wait_bit(struct mv88e6xxx_chip * chip,int addr,int reg,int bit,int val)116 int mv88e6xxx_wait_bit(struct mv88e6xxx_chip *chip, int addr, int reg,
117 int bit, int val)
118 {
119 return mv88e6xxx_wait_mask(chip, addr, reg, BIT(bit),
120 val ? BIT(bit) : 0x0000);
121 }
122
mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip * chip)123 struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
124 {
125 struct mv88e6xxx_mdio_bus *mdio_bus;
126
127 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
128 list);
129 if (!mdio_bus)
130 return NULL;
131
132 return mdio_bus->bus;
133 }
134
mv88e6xxx_g1_irq_mask(struct irq_data * d)135 static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
136 {
137 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
138 unsigned int n = d->hwirq;
139
140 chip->g1_irq.masked |= (1 << n);
141 }
142
mv88e6xxx_g1_irq_unmask(struct irq_data * d)143 static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
144 {
145 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
146 unsigned int n = d->hwirq;
147
148 chip->g1_irq.masked &= ~(1 << n);
149 }
150
mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip * chip)151 static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
152 {
153 unsigned int nhandled = 0;
154 unsigned int sub_irq;
155 unsigned int n;
156 u16 reg;
157 u16 ctl1;
158 int err;
159
160 mv88e6xxx_reg_lock(chip);
161 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, ®);
162 mv88e6xxx_reg_unlock(chip);
163
164 if (err)
165 goto out;
166
167 do {
168 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
169 if (reg & (1 << n)) {
170 sub_irq = irq_find_mapping(chip->g1_irq.domain,
171 n);
172 handle_nested_irq(sub_irq);
173 ++nhandled;
174 }
175 }
176
177 mv88e6xxx_reg_lock(chip);
178 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1);
179 if (err)
180 goto unlock;
181 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, ®);
182 unlock:
183 mv88e6xxx_reg_unlock(chip);
184 if (err)
185 goto out;
186 ctl1 &= GENMASK(chip->g1_irq.nirqs, 0);
187 } while (reg & ctl1);
188
189 out:
190 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
191 }
192
mv88e6xxx_g1_irq_thread_fn(int irq,void * dev_id)193 static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
194 {
195 struct mv88e6xxx_chip *chip = dev_id;
196
197 return mv88e6xxx_g1_irq_thread_work(chip);
198 }
199
mv88e6xxx_g1_irq_bus_lock(struct irq_data * d)200 static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
201 {
202 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
203
204 mv88e6xxx_reg_lock(chip);
205 }
206
mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data * d)207 static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
208 {
209 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
210 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
211 u16 reg;
212 int err;
213
214 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, ®);
215 if (err)
216 goto out;
217
218 reg &= ~mask;
219 reg |= (~chip->g1_irq.masked & mask);
220
221 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
222 if (err)
223 goto out;
224
225 out:
226 mv88e6xxx_reg_unlock(chip);
227 }
228
229 static const struct irq_chip mv88e6xxx_g1_irq_chip = {
230 .name = "mv88e6xxx-g1",
231 .irq_mask = mv88e6xxx_g1_irq_mask,
232 .irq_unmask = mv88e6xxx_g1_irq_unmask,
233 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
234 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
235 };
236
mv88e6xxx_g1_irq_domain_map(struct irq_domain * d,unsigned int irq,irq_hw_number_t hwirq)237 static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
238 unsigned int irq,
239 irq_hw_number_t hwirq)
240 {
241 struct mv88e6xxx_chip *chip = d->host_data;
242
243 irq_set_chip_data(irq, d->host_data);
244 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
245 irq_set_noprobe(irq);
246
247 return 0;
248 }
249
250 static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
251 .map = mv88e6xxx_g1_irq_domain_map,
252 .xlate = irq_domain_xlate_twocell,
253 };
254
255 /* To be called with reg_lock held */
mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip * chip)256 static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
257 {
258 int irq, virq;
259 u16 mask;
260
261 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
262 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
263 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
264
265 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
266 virq = irq_find_mapping(chip->g1_irq.domain, irq);
267 irq_dispose_mapping(virq);
268 }
269
270 irq_domain_remove(chip->g1_irq.domain);
271 }
272
mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip * chip)273 static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
274 {
275 /*
276 * free_irq must be called without reg_lock taken because the irq
277 * handler takes this lock, too.
278 */
279 free_irq(chip->irq, chip);
280
281 mv88e6xxx_reg_lock(chip);
282 mv88e6xxx_g1_irq_free_common(chip);
283 mv88e6xxx_reg_unlock(chip);
284 }
285
mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip * chip)286 static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
287 {
288 int err, irq, virq;
289 u16 reg, mask;
290
291 chip->g1_irq.nirqs = chip->info->g1_irqs;
292 chip->g1_irq.domain = irq_domain_add_simple(
293 NULL, chip->g1_irq.nirqs, 0,
294 &mv88e6xxx_g1_irq_domain_ops, chip);
295 if (!chip->g1_irq.domain)
296 return -ENOMEM;
297
298 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
299 irq_create_mapping(chip->g1_irq.domain, irq);
300
301 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
302 chip->g1_irq.masked = ~0;
303
304 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
305 if (err)
306 goto out_mapping;
307
308 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
309
310 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
311 if (err)
312 goto out_disable;
313
314 /* Reading the interrupt status clears (most of) them */
315 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, ®);
316 if (err)
317 goto out_disable;
318
319 return 0;
320
321 out_disable:
322 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
323 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
324
325 out_mapping:
326 for (irq = 0; irq < 16; irq++) {
327 virq = irq_find_mapping(chip->g1_irq.domain, irq);
328 irq_dispose_mapping(virq);
329 }
330
331 irq_domain_remove(chip->g1_irq.domain);
332
333 return err;
334 }
335
mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip * chip)336 static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
337 {
338 static struct lock_class_key lock_key;
339 static struct lock_class_key request_key;
340 int err;
341
342 err = mv88e6xxx_g1_irq_setup_common(chip);
343 if (err)
344 return err;
345
346 /* These lock classes tells lockdep that global 1 irqs are in
347 * a different category than their parent GPIO, so it won't
348 * report false recursion.
349 */
350 irq_set_lockdep_class(chip->irq, &lock_key, &request_key);
351
352 snprintf(chip->irq_name, sizeof(chip->irq_name),
353 "mv88e6xxx-%s", dev_name(chip->dev));
354
355 mv88e6xxx_reg_unlock(chip);
356 err = request_threaded_irq(chip->irq, NULL,
357 mv88e6xxx_g1_irq_thread_fn,
358 IRQF_ONESHOT | IRQF_SHARED,
359 chip->irq_name, chip);
360 mv88e6xxx_reg_lock(chip);
361 if (err)
362 mv88e6xxx_g1_irq_free_common(chip);
363
364 return err;
365 }
366
mv88e6xxx_irq_poll(struct kthread_work * work)367 static void mv88e6xxx_irq_poll(struct kthread_work *work)
368 {
369 struct mv88e6xxx_chip *chip = container_of(work,
370 struct mv88e6xxx_chip,
371 irq_poll_work.work);
372 mv88e6xxx_g1_irq_thread_work(chip);
373
374 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
375 msecs_to_jiffies(100));
376 }
377
mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip * chip)378 static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
379 {
380 int err;
381
382 err = mv88e6xxx_g1_irq_setup_common(chip);
383 if (err)
384 return err;
385
386 kthread_init_delayed_work(&chip->irq_poll_work,
387 mv88e6xxx_irq_poll);
388
389 chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
390 if (IS_ERR(chip->kworker))
391 return PTR_ERR(chip->kworker);
392
393 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
394 msecs_to_jiffies(100));
395
396 return 0;
397 }
398
mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip * chip)399 static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
400 {
401 kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
402 kthread_destroy_worker(chip->kworker);
403
404 mv88e6xxx_reg_lock(chip);
405 mv88e6xxx_g1_irq_free_common(chip);
406 mv88e6xxx_reg_unlock(chip);
407 }
408
mv88e6xxx_port_config_interface(struct mv88e6xxx_chip * chip,int port,phy_interface_t interface)409 static int mv88e6xxx_port_config_interface(struct mv88e6xxx_chip *chip,
410 int port, phy_interface_t interface)
411 {
412 int err;
413
414 if (chip->info->ops->port_set_rgmii_delay) {
415 err = chip->info->ops->port_set_rgmii_delay(chip, port,
416 interface);
417 if (err && err != -EOPNOTSUPP)
418 return err;
419 }
420
421 if (chip->info->ops->port_set_cmode) {
422 err = chip->info->ops->port_set_cmode(chip, port,
423 interface);
424 if (err && err != -EOPNOTSUPP)
425 return err;
426 }
427
428 return 0;
429 }
430
mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip * chip,int port,int link,int speed,int duplex,int pause,phy_interface_t mode)431 static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
432 int link, int speed, int duplex, int pause,
433 phy_interface_t mode)
434 {
435 int err;
436
437 if (!chip->info->ops->port_set_link)
438 return 0;
439
440 /* Port's MAC control must not be changed unless the link is down */
441 err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
442 if (err)
443 return err;
444
445 if (chip->info->ops->port_set_speed_duplex) {
446 err = chip->info->ops->port_set_speed_duplex(chip, port,
447 speed, duplex);
448 if (err && err != -EOPNOTSUPP)
449 goto restore_link;
450 }
451
452 if (chip->info->ops->port_set_pause) {
453 err = chip->info->ops->port_set_pause(chip, port, pause);
454 if (err)
455 goto restore_link;
456 }
457
458 err = mv88e6xxx_port_config_interface(chip, port, mode);
459 restore_link:
460 if (chip->info->ops->port_set_link(chip, port, link))
461 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
462
463 return err;
464 }
465
mv88e6xxx_phy_is_internal(struct dsa_switch * ds,int port)466 static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
467 {
468 struct mv88e6xxx_chip *chip = ds->priv;
469
470 return port < chip->info->num_internal_phys;
471 }
472
mv88e6xxx_port_ppu_updates(struct mv88e6xxx_chip * chip,int port)473 static int mv88e6xxx_port_ppu_updates(struct mv88e6xxx_chip *chip, int port)
474 {
475 u16 reg;
476 int err;
477
478 /* The 88e6250 family does not have the PHY detect bit. Instead,
479 * report whether the port is internal.
480 */
481 if (chip->info->family == MV88E6XXX_FAMILY_6250)
482 return port < chip->info->num_internal_phys;
483
484 err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, ®);
485 if (err) {
486 dev_err(chip->dev,
487 "p%d: %s: failed to read port status\n",
488 port, __func__);
489 return err;
490 }
491
492 return !!(reg & MV88E6XXX_PORT_STS_PHY_DETECT);
493 }
494
mv88e6xxx_serdes_pcs_get_state(struct dsa_switch * ds,int port,struct phylink_link_state * state)495 static int mv88e6xxx_serdes_pcs_get_state(struct dsa_switch *ds, int port,
496 struct phylink_link_state *state)
497 {
498 struct mv88e6xxx_chip *chip = ds->priv;
499 int lane;
500 int err;
501
502 mv88e6xxx_reg_lock(chip);
503 lane = mv88e6xxx_serdes_get_lane(chip, port);
504 if (lane >= 0 && chip->info->ops->serdes_pcs_get_state)
505 err = chip->info->ops->serdes_pcs_get_state(chip, port, lane,
506 state);
507 else
508 err = -EOPNOTSUPP;
509 mv88e6xxx_reg_unlock(chip);
510
511 return err;
512 }
513
mv88e6xxx_serdes_pcs_config(struct mv88e6xxx_chip * chip,int port,unsigned int mode,phy_interface_t interface,const unsigned long * advertise)514 static int mv88e6xxx_serdes_pcs_config(struct mv88e6xxx_chip *chip, int port,
515 unsigned int mode,
516 phy_interface_t interface,
517 const unsigned long *advertise)
518 {
519 const struct mv88e6xxx_ops *ops = chip->info->ops;
520 int lane;
521
522 if (ops->serdes_pcs_config) {
523 lane = mv88e6xxx_serdes_get_lane(chip, port);
524 if (lane >= 0)
525 return ops->serdes_pcs_config(chip, port, lane, mode,
526 interface, advertise);
527 }
528
529 return 0;
530 }
531
mv88e6xxx_serdes_pcs_an_restart(struct dsa_switch * ds,int port)532 static void mv88e6xxx_serdes_pcs_an_restart(struct dsa_switch *ds, int port)
533 {
534 struct mv88e6xxx_chip *chip = ds->priv;
535 const struct mv88e6xxx_ops *ops;
536 int err = 0;
537 int lane;
538
539 ops = chip->info->ops;
540
541 if (ops->serdes_pcs_an_restart) {
542 mv88e6xxx_reg_lock(chip);
543 lane = mv88e6xxx_serdes_get_lane(chip, port);
544 if (lane >= 0)
545 err = ops->serdes_pcs_an_restart(chip, port, lane);
546 mv88e6xxx_reg_unlock(chip);
547
548 if (err)
549 dev_err(ds->dev, "p%d: failed to restart AN\n", port);
550 }
551 }
552
mv88e6xxx_serdes_pcs_link_up(struct mv88e6xxx_chip * chip,int port,unsigned int mode,int speed,int duplex)553 static int mv88e6xxx_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port,
554 unsigned int mode,
555 int speed, int duplex)
556 {
557 const struct mv88e6xxx_ops *ops = chip->info->ops;
558 int lane;
559
560 if (!phylink_autoneg_inband(mode) && ops->serdes_pcs_link_up) {
561 lane = mv88e6xxx_serdes_get_lane(chip, port);
562 if (lane >= 0)
563 return ops->serdes_pcs_link_up(chip, port, lane,
564 speed, duplex);
565 }
566
567 return 0;
568 }
569
570 static const u8 mv88e6185_phy_interface_modes[] = {
571 [MV88E6185_PORT_STS_CMODE_GMII_FD] = PHY_INTERFACE_MODE_GMII,
572 [MV88E6185_PORT_STS_CMODE_MII_100_FD_PS] = PHY_INTERFACE_MODE_MII,
573 [MV88E6185_PORT_STS_CMODE_MII_100] = PHY_INTERFACE_MODE_MII,
574 [MV88E6185_PORT_STS_CMODE_MII_10] = PHY_INTERFACE_MODE_MII,
575 [MV88E6185_PORT_STS_CMODE_SERDES] = PHY_INTERFACE_MODE_1000BASEX,
576 [MV88E6185_PORT_STS_CMODE_1000BASE_X] = PHY_INTERFACE_MODE_1000BASEX,
577 [MV88E6185_PORT_STS_CMODE_PHY] = PHY_INTERFACE_MODE_SGMII,
578 };
579
mv88e6095_phylink_get_caps(struct mv88e6xxx_chip * chip,int port,struct phylink_config * config)580 static void mv88e6095_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
581 struct phylink_config *config)
582 {
583 u8 cmode = chip->ports[port].cmode;
584
585 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100;
586
587 if (mv88e6xxx_phy_is_internal(chip->ds, port)) {
588 __set_bit(PHY_INTERFACE_MODE_MII, config->supported_interfaces);
589 } else {
590 if (cmode < ARRAY_SIZE(mv88e6185_phy_interface_modes) &&
591 mv88e6185_phy_interface_modes[cmode])
592 __set_bit(mv88e6185_phy_interface_modes[cmode],
593 config->supported_interfaces);
594
595 config->mac_capabilities |= MAC_1000FD;
596 }
597 }
598
mv88e6185_phylink_get_caps(struct mv88e6xxx_chip * chip,int port,struct phylink_config * config)599 static void mv88e6185_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
600 struct phylink_config *config)
601 {
602 u8 cmode = chip->ports[port].cmode;
603
604 if (cmode < ARRAY_SIZE(mv88e6185_phy_interface_modes) &&
605 mv88e6185_phy_interface_modes[cmode])
606 __set_bit(mv88e6185_phy_interface_modes[cmode],
607 config->supported_interfaces);
608
609 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 |
610 MAC_1000FD;
611 }
612
613 static const u8 mv88e6xxx_phy_interface_modes[] = {
614 [MV88E6XXX_PORT_STS_CMODE_MII_PHY] = PHY_INTERFACE_MODE_MII,
615 [MV88E6XXX_PORT_STS_CMODE_MII] = PHY_INTERFACE_MODE_MII,
616 [MV88E6XXX_PORT_STS_CMODE_GMII] = PHY_INTERFACE_MODE_GMII,
617 [MV88E6XXX_PORT_STS_CMODE_RMII_PHY] = PHY_INTERFACE_MODE_RMII,
618 [MV88E6XXX_PORT_STS_CMODE_RMII] = PHY_INTERFACE_MODE_RMII,
619 [MV88E6XXX_PORT_STS_CMODE_100BASEX] = PHY_INTERFACE_MODE_100BASEX,
620 [MV88E6XXX_PORT_STS_CMODE_1000BASEX] = PHY_INTERFACE_MODE_1000BASEX,
621 [MV88E6XXX_PORT_STS_CMODE_SGMII] = PHY_INTERFACE_MODE_SGMII,
622 /* higher interface modes are not needed here, since ports supporting
623 * them are writable, and so the supported interfaces are filled in the
624 * corresponding .phylink_set_interfaces() implementation below
625 */
626 };
627
mv88e6xxx_translate_cmode(u8 cmode,unsigned long * supported)628 static void mv88e6xxx_translate_cmode(u8 cmode, unsigned long *supported)
629 {
630 if (cmode < ARRAY_SIZE(mv88e6xxx_phy_interface_modes) &&
631 mv88e6xxx_phy_interface_modes[cmode])
632 __set_bit(mv88e6xxx_phy_interface_modes[cmode], supported);
633 else if (cmode == MV88E6XXX_PORT_STS_CMODE_RGMII)
634 phy_interface_set_rgmii(supported);
635 }
636
mv88e6250_phylink_get_caps(struct mv88e6xxx_chip * chip,int port,struct phylink_config * config)637 static void mv88e6250_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
638 struct phylink_config *config)
639 {
640 unsigned long *supported = config->supported_interfaces;
641
642 /* Translate the default cmode */
643 mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported);
644
645 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100;
646 }
647
mv88e6352_get_port4_serdes_cmode(struct mv88e6xxx_chip * chip)648 static int mv88e6352_get_port4_serdes_cmode(struct mv88e6xxx_chip *chip)
649 {
650 u16 reg, val;
651 int err;
652
653 err = mv88e6xxx_port_read(chip, 4, MV88E6XXX_PORT_STS, ®);
654 if (err)
655 return err;
656
657 /* If PHY_DETECT is zero, then we are not in auto-media mode */
658 if (!(reg & MV88E6XXX_PORT_STS_PHY_DETECT))
659 return 0xf;
660
661 val = reg & ~MV88E6XXX_PORT_STS_PHY_DETECT;
662 err = mv88e6xxx_port_write(chip, 4, MV88E6XXX_PORT_STS, val);
663 if (err)
664 return err;
665
666 err = mv88e6xxx_port_read(chip, 4, MV88E6XXX_PORT_STS, &val);
667 if (err)
668 return err;
669
670 /* Restore PHY_DETECT value */
671 err = mv88e6xxx_port_write(chip, 4, MV88E6XXX_PORT_STS, reg);
672 if (err)
673 return err;
674
675 return val & MV88E6XXX_PORT_STS_CMODE_MASK;
676 }
677
mv88e6352_phylink_get_caps(struct mv88e6xxx_chip * chip,int port,struct phylink_config * config)678 static void mv88e6352_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
679 struct phylink_config *config)
680 {
681 unsigned long *supported = config->supported_interfaces;
682 int err, cmode;
683
684 /* Translate the default cmode */
685 mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported);
686
687 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 |
688 MAC_1000FD;
689
690 /* Port 4 supports automedia if the serdes is associated with it. */
691 if (port == 4) {
692 err = mv88e6352_g2_scratch_port_has_serdes(chip, port);
693 if (err < 0)
694 dev_err(chip->dev, "p%d: failed to read scratch\n",
695 port);
696 if (err <= 0)
697 return;
698
699 cmode = mv88e6352_get_port4_serdes_cmode(chip);
700 if (cmode < 0)
701 dev_err(chip->dev, "p%d: failed to read serdes cmode\n",
702 port);
703 else
704 mv88e6xxx_translate_cmode(cmode, supported);
705 }
706 }
707
mv88e6341_phylink_get_caps(struct mv88e6xxx_chip * chip,int port,struct phylink_config * config)708 static void mv88e6341_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
709 struct phylink_config *config)
710 {
711 unsigned long *supported = config->supported_interfaces;
712
713 /* Translate the default cmode */
714 mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported);
715
716 /* No ethtool bits for 200Mbps */
717 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 |
718 MAC_1000FD;
719
720 /* The C_Mode field is programmable on port 5 */
721 if (port == 5) {
722 __set_bit(PHY_INTERFACE_MODE_SGMII, supported);
723 __set_bit(PHY_INTERFACE_MODE_1000BASEX, supported);
724 __set_bit(PHY_INTERFACE_MODE_2500BASEX, supported);
725
726 config->mac_capabilities |= MAC_2500FD;
727 }
728 }
729
mv88e6390_phylink_get_caps(struct mv88e6xxx_chip * chip,int port,struct phylink_config * config)730 static void mv88e6390_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
731 struct phylink_config *config)
732 {
733 unsigned long *supported = config->supported_interfaces;
734
735 /* Translate the default cmode */
736 mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported);
737
738 /* No ethtool bits for 200Mbps */
739 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 |
740 MAC_1000FD;
741
742 /* The C_Mode field is programmable on ports 9 and 10 */
743 if (port == 9 || port == 10) {
744 __set_bit(PHY_INTERFACE_MODE_SGMII, supported);
745 __set_bit(PHY_INTERFACE_MODE_1000BASEX, supported);
746 __set_bit(PHY_INTERFACE_MODE_2500BASEX, supported);
747
748 config->mac_capabilities |= MAC_2500FD;
749 }
750 }
751
mv88e6390x_phylink_get_caps(struct mv88e6xxx_chip * chip,int port,struct phylink_config * config)752 static void mv88e6390x_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
753 struct phylink_config *config)
754 {
755 unsigned long *supported = config->supported_interfaces;
756
757 mv88e6390_phylink_get_caps(chip, port, config);
758
759 /* For the 6x90X, ports 2-7 can be in automedia mode.
760 * (Note that 6x90 doesn't support RXAUI nor XAUI).
761 *
762 * Port 2 can also support 1000BASE-X in automedia mode if port 9 is
763 * configured for 1000BASE-X, SGMII or 2500BASE-X.
764 * Port 3-4 can also support 1000BASE-X in automedia mode if port 9 is
765 * configured for RXAUI, 1000BASE-X, SGMII or 2500BASE-X.
766 *
767 * Port 5 can also support 1000BASE-X in automedia mode if port 10 is
768 * configured for 1000BASE-X, SGMII or 2500BASE-X.
769 * Port 6-7 can also support 1000BASE-X in automedia mode if port 10 is
770 * configured for RXAUI, 1000BASE-X, SGMII or 2500BASE-X.
771 *
772 * For now, be permissive (as the old code was) and allow 1000BASE-X
773 * on ports 2..7.
774 */
775 if (port >= 2 && port <= 7)
776 __set_bit(PHY_INTERFACE_MODE_1000BASEX, supported);
777
778 /* The C_Mode field can also be programmed for 10G speeds */
779 if (port == 9 || port == 10) {
780 __set_bit(PHY_INTERFACE_MODE_XAUI, supported);
781 __set_bit(PHY_INTERFACE_MODE_RXAUI, supported);
782
783 config->mac_capabilities |= MAC_10000FD;
784 }
785 }
786
mv88e6393x_phylink_get_caps(struct mv88e6xxx_chip * chip,int port,struct phylink_config * config)787 static void mv88e6393x_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
788 struct phylink_config *config)
789 {
790 unsigned long *supported = config->supported_interfaces;
791 bool is_6191x =
792 chip->info->prod_num == MV88E6XXX_PORT_SWITCH_ID_PROD_6191X;
793
794 mv88e6xxx_translate_cmode(chip->ports[port].cmode, supported);
795
796 config->mac_capabilities = MAC_SYM_PAUSE | MAC_10 | MAC_100 |
797 MAC_1000FD;
798
799 /* The C_Mode field can be programmed for ports 0, 9 and 10 */
800 if (port == 0 || port == 9 || port == 10) {
801 __set_bit(PHY_INTERFACE_MODE_SGMII, supported);
802 __set_bit(PHY_INTERFACE_MODE_1000BASEX, supported);
803
804 /* 6191X supports >1G modes only on port 10 */
805 if (!is_6191x || port == 10) {
806 __set_bit(PHY_INTERFACE_MODE_2500BASEX, supported);
807 __set_bit(PHY_INTERFACE_MODE_5GBASER, supported);
808 __set_bit(PHY_INTERFACE_MODE_10GBASER, supported);
809 /* FIXME: USXGMII is not supported yet */
810 /* __set_bit(PHY_INTERFACE_MODE_USXGMII, supported); */
811
812 config->mac_capabilities |= MAC_2500FD | MAC_5000FD |
813 MAC_10000FD;
814 }
815 }
816
817 if (port == 0) {
818 __set_bit(PHY_INTERFACE_MODE_RMII, supported);
819 __set_bit(PHY_INTERFACE_MODE_RGMII, supported);
820 __set_bit(PHY_INTERFACE_MODE_RGMII_ID, supported);
821 __set_bit(PHY_INTERFACE_MODE_RGMII_RXID, supported);
822 __set_bit(PHY_INTERFACE_MODE_RGMII_TXID, supported);
823 }
824 }
825
mv88e6xxx_get_caps(struct dsa_switch * ds,int port,struct phylink_config * config)826 static void mv88e6xxx_get_caps(struct dsa_switch *ds, int port,
827 struct phylink_config *config)
828 {
829 struct mv88e6xxx_chip *chip = ds->priv;
830
831 mv88e6xxx_reg_lock(chip);
832 chip->info->ops->phylink_get_caps(chip, port, config);
833 mv88e6xxx_reg_unlock(chip);
834
835 if (mv88e6xxx_phy_is_internal(ds, port)) {
836 __set_bit(PHY_INTERFACE_MODE_INTERNAL,
837 config->supported_interfaces);
838 /* Internal ports with no phy-mode need GMII for PHYLIB */
839 __set_bit(PHY_INTERFACE_MODE_GMII,
840 config->supported_interfaces);
841 }
842 }
843
mv88e6xxx_mac_config(struct dsa_switch * ds,int port,unsigned int mode,const struct phylink_link_state * state)844 static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
845 unsigned int mode,
846 const struct phylink_link_state *state)
847 {
848 struct mv88e6xxx_chip *chip = ds->priv;
849 struct mv88e6xxx_port *p;
850 int err = 0;
851
852 p = &chip->ports[port];
853
854 mv88e6xxx_reg_lock(chip);
855
856 if (mode != MLO_AN_PHY || !mv88e6xxx_phy_is_internal(ds, port)) {
857 /* In inband mode, the link may come up at any time while the
858 * link is not forced down. Force the link down while we
859 * reconfigure the interface mode.
860 */
861 if (mode == MLO_AN_INBAND &&
862 p->interface != state->interface &&
863 chip->info->ops->port_set_link)
864 chip->info->ops->port_set_link(chip, port,
865 LINK_FORCED_DOWN);
866
867 err = mv88e6xxx_port_config_interface(chip, port,
868 state->interface);
869 if (err && err != -EOPNOTSUPP)
870 goto err_unlock;
871
872 err = mv88e6xxx_serdes_pcs_config(chip, port, mode,
873 state->interface,
874 state->advertising);
875 /* FIXME: we should restart negotiation if something changed -
876 * which is something we get if we convert to using phylinks
877 * PCS operations.
878 */
879 if (err > 0)
880 err = 0;
881 }
882
883 /* Undo the forced down state above after completing configuration
884 * irrespective of its state on entry, which allows the link to come
885 * up in the in-band case where there is no separate SERDES. Also
886 * ensure that the link can come up if the PPU is in use and we are
887 * in PHY mode (we treat the PPU as an effective in-band mechanism.)
888 */
889 if (chip->info->ops->port_set_link &&
890 ((mode == MLO_AN_INBAND && p->interface != state->interface) ||
891 (mode == MLO_AN_PHY && mv88e6xxx_port_ppu_updates(chip, port))))
892 chip->info->ops->port_set_link(chip, port, LINK_UNFORCED);
893
894 p->interface = state->interface;
895
896 err_unlock:
897 mv88e6xxx_reg_unlock(chip);
898
899 if (err && err != -EOPNOTSUPP)
900 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
901 }
902
mv88e6xxx_mac_link_down(struct dsa_switch * ds,int port,unsigned int mode,phy_interface_t interface)903 static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
904 unsigned int mode,
905 phy_interface_t interface)
906 {
907 struct mv88e6xxx_chip *chip = ds->priv;
908 const struct mv88e6xxx_ops *ops;
909 int err = 0;
910
911 ops = chip->info->ops;
912
913 mv88e6xxx_reg_lock(chip);
914 /* Force the link down if we know the port may not be automatically
915 * updated by the switch or if we are using fixed-link mode.
916 */
917 if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
918 mode == MLO_AN_FIXED) && ops->port_sync_link)
919 err = ops->port_sync_link(chip, port, mode, false);
920
921 if (!err && ops->port_set_speed_duplex)
922 err = ops->port_set_speed_duplex(chip, port, SPEED_UNFORCED,
923 DUPLEX_UNFORCED);
924 mv88e6xxx_reg_unlock(chip);
925
926 if (err)
927 dev_err(chip->dev,
928 "p%d: failed to force MAC link down\n", port);
929 }
930
mv88e6xxx_mac_link_up(struct dsa_switch * ds,int port,unsigned int mode,phy_interface_t interface,struct phy_device * phydev,int speed,int duplex,bool tx_pause,bool rx_pause)931 static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
932 unsigned int mode, phy_interface_t interface,
933 struct phy_device *phydev,
934 int speed, int duplex,
935 bool tx_pause, bool rx_pause)
936 {
937 struct mv88e6xxx_chip *chip = ds->priv;
938 const struct mv88e6xxx_ops *ops;
939 int err = 0;
940
941 ops = chip->info->ops;
942
943 mv88e6xxx_reg_lock(chip);
944 /* Configure and force the link up if we know that the port may not
945 * automatically updated by the switch or if we are using fixed-link
946 * mode.
947 */
948 if (!mv88e6xxx_port_ppu_updates(chip, port) ||
949 mode == MLO_AN_FIXED) {
950 /* FIXME: for an automedia port, should we force the link
951 * down here - what if the link comes up due to "other" media
952 * while we're bringing the port up, how is the exclusivity
953 * handled in the Marvell hardware? E.g. port 2 on 88E6390
954 * shared between internal PHY and Serdes.
955 */
956 err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
957 duplex);
958 if (err)
959 goto error;
960
961 if (ops->port_set_speed_duplex) {
962 err = ops->port_set_speed_duplex(chip, port,
963 speed, duplex);
964 if (err && err != -EOPNOTSUPP)
965 goto error;
966 }
967
968 if (ops->port_sync_link)
969 err = ops->port_sync_link(chip, port, mode, true);
970 }
971 error:
972 mv88e6xxx_reg_unlock(chip);
973
974 if (err && err != -EOPNOTSUPP)
975 dev_err(ds->dev,
976 "p%d: failed to configure MAC link up\n", port);
977 }
978
mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip * chip,int port)979 static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
980 {
981 if (!chip->info->ops->stats_snapshot)
982 return -EOPNOTSUPP;
983
984 return chip->info->ops->stats_snapshot(chip, port);
985 }
986
987 static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
988 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
989 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
990 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
991 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
992 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
993 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
994 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
995 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
996 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
997 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
998 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
999 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
1000 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
1001 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
1002 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
1003 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
1004 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
1005 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
1006 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
1007 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
1008 { "single", 4, 0x14, STATS_TYPE_BANK0, },
1009 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
1010 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
1011 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
1012 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
1013 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
1014 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
1015 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
1016 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
1017 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
1018 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
1019 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
1020 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
1021 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
1022 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
1023 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
1024 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
1025 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
1026 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
1027 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
1028 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
1029 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
1030 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
1031 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
1032 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
1033 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
1034 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
1035 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
1036 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
1037 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
1038 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
1039 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
1040 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
1041 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
1042 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
1043 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
1044 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
1045 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
1046 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
1047 };
1048
_mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip * chip,struct mv88e6xxx_hw_stat * s,int port,u16 bank1_select,u16 histogram)1049 static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
1050 struct mv88e6xxx_hw_stat *s,
1051 int port, u16 bank1_select,
1052 u16 histogram)
1053 {
1054 u32 low;
1055 u32 high = 0;
1056 u16 reg = 0;
1057 int err;
1058 u64 value;
1059
1060 switch (s->type) {
1061 case STATS_TYPE_PORT:
1062 err = mv88e6xxx_port_read(chip, port, s->reg, ®);
1063 if (err)
1064 return U64_MAX;
1065
1066 low = reg;
1067 if (s->size == 4) {
1068 err = mv88e6xxx_port_read(chip, port, s->reg + 1, ®);
1069 if (err)
1070 return U64_MAX;
1071 low |= ((u32)reg) << 16;
1072 }
1073 break;
1074 case STATS_TYPE_BANK1:
1075 reg = bank1_select;
1076 fallthrough;
1077 case STATS_TYPE_BANK0:
1078 reg |= s->reg | histogram;
1079 mv88e6xxx_g1_stats_read(chip, reg, &low);
1080 if (s->size == 8)
1081 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
1082 break;
1083 default:
1084 return U64_MAX;
1085 }
1086 value = (((u64)high) << 32) | low;
1087 return value;
1088 }
1089
mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip * chip,uint8_t * data,int types)1090 static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
1091 uint8_t *data, int types)
1092 {
1093 struct mv88e6xxx_hw_stat *stat;
1094 int i, j;
1095
1096 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1097 stat = &mv88e6xxx_hw_stats[i];
1098 if (stat->type & types) {
1099 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
1100 ETH_GSTRING_LEN);
1101 j++;
1102 }
1103 }
1104
1105 return j;
1106 }
1107
mv88e6095_stats_get_strings(struct mv88e6xxx_chip * chip,uint8_t * data)1108 static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
1109 uint8_t *data)
1110 {
1111 return mv88e6xxx_stats_get_strings(chip, data,
1112 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
1113 }
1114
mv88e6250_stats_get_strings(struct mv88e6xxx_chip * chip,uint8_t * data)1115 static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
1116 uint8_t *data)
1117 {
1118 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
1119 }
1120
mv88e6320_stats_get_strings(struct mv88e6xxx_chip * chip,uint8_t * data)1121 static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
1122 uint8_t *data)
1123 {
1124 return mv88e6xxx_stats_get_strings(chip, data,
1125 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
1126 }
1127
1128 static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
1129 "atu_member_violation",
1130 "atu_miss_violation",
1131 "atu_full_violation",
1132 "vtu_member_violation",
1133 "vtu_miss_violation",
1134 };
1135
mv88e6xxx_atu_vtu_get_strings(uint8_t * data)1136 static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
1137 {
1138 unsigned int i;
1139
1140 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
1141 strscpy(data + i * ETH_GSTRING_LEN,
1142 mv88e6xxx_atu_vtu_stats_strings[i],
1143 ETH_GSTRING_LEN);
1144 }
1145
mv88e6xxx_get_strings(struct dsa_switch * ds,int port,u32 stringset,uint8_t * data)1146 static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
1147 u32 stringset, uint8_t *data)
1148 {
1149 struct mv88e6xxx_chip *chip = ds->priv;
1150 int count = 0;
1151
1152 if (stringset != ETH_SS_STATS)
1153 return;
1154
1155 mv88e6xxx_reg_lock(chip);
1156
1157 if (chip->info->ops->stats_get_strings)
1158 count = chip->info->ops->stats_get_strings(chip, data);
1159
1160 if (chip->info->ops->serdes_get_strings) {
1161 data += count * ETH_GSTRING_LEN;
1162 count = chip->info->ops->serdes_get_strings(chip, port, data);
1163 }
1164
1165 data += count * ETH_GSTRING_LEN;
1166 mv88e6xxx_atu_vtu_get_strings(data);
1167
1168 mv88e6xxx_reg_unlock(chip);
1169 }
1170
mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip * chip,int types)1171 static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
1172 int types)
1173 {
1174 struct mv88e6xxx_hw_stat *stat;
1175 int i, j;
1176
1177 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1178 stat = &mv88e6xxx_hw_stats[i];
1179 if (stat->type & types)
1180 j++;
1181 }
1182 return j;
1183 }
1184
mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip * chip)1185 static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1186 {
1187 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1188 STATS_TYPE_PORT);
1189 }
1190
mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip * chip)1191 static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1192 {
1193 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
1194 }
1195
mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip * chip)1196 static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1197 {
1198 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1199 STATS_TYPE_BANK1);
1200 }
1201
mv88e6xxx_get_sset_count(struct dsa_switch * ds,int port,int sset)1202 static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
1203 {
1204 struct mv88e6xxx_chip *chip = ds->priv;
1205 int serdes_count = 0;
1206 int count = 0;
1207
1208 if (sset != ETH_SS_STATS)
1209 return 0;
1210
1211 mv88e6xxx_reg_lock(chip);
1212 if (chip->info->ops->stats_get_sset_count)
1213 count = chip->info->ops->stats_get_sset_count(chip);
1214 if (count < 0)
1215 goto out;
1216
1217 if (chip->info->ops->serdes_get_sset_count)
1218 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1219 port);
1220 if (serdes_count < 0) {
1221 count = serdes_count;
1222 goto out;
1223 }
1224 count += serdes_count;
1225 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1226
1227 out:
1228 mv88e6xxx_reg_unlock(chip);
1229
1230 return count;
1231 }
1232
mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip * chip,int port,uint64_t * data,int types,u16 bank1_select,u16 histogram)1233 static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1234 uint64_t *data, int types,
1235 u16 bank1_select, u16 histogram)
1236 {
1237 struct mv88e6xxx_hw_stat *stat;
1238 int i, j;
1239
1240 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1241 stat = &mv88e6xxx_hw_stats[i];
1242 if (stat->type & types) {
1243 mv88e6xxx_reg_lock(chip);
1244 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1245 bank1_select,
1246 histogram);
1247 mv88e6xxx_reg_unlock(chip);
1248
1249 j++;
1250 }
1251 }
1252 return j;
1253 }
1254
mv88e6095_stats_get_stats(struct mv88e6xxx_chip * chip,int port,uint64_t * data)1255 static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1256 uint64_t *data)
1257 {
1258 return mv88e6xxx_stats_get_stats(chip, port, data,
1259 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
1260 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1261 }
1262
mv88e6250_stats_get_stats(struct mv88e6xxx_chip * chip,int port,uint64_t * data)1263 static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1264 uint64_t *data)
1265 {
1266 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
1267 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1268 }
1269
mv88e6320_stats_get_stats(struct mv88e6xxx_chip * chip,int port,uint64_t * data)1270 static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1271 uint64_t *data)
1272 {
1273 return mv88e6xxx_stats_get_stats(chip, port, data,
1274 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1275 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1276 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1277 }
1278
mv88e6390_stats_get_stats(struct mv88e6xxx_chip * chip,int port,uint64_t * data)1279 static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1280 uint64_t *data)
1281 {
1282 return mv88e6xxx_stats_get_stats(chip, port, data,
1283 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1284 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1285 0);
1286 }
1287
mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip * chip,int port,uint64_t * data)1288 static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1289 uint64_t *data)
1290 {
1291 *data++ = chip->ports[port].atu_member_violation;
1292 *data++ = chip->ports[port].atu_miss_violation;
1293 *data++ = chip->ports[port].atu_full_violation;
1294 *data++ = chip->ports[port].vtu_member_violation;
1295 *data++ = chip->ports[port].vtu_miss_violation;
1296 }
1297
mv88e6xxx_get_stats(struct mv88e6xxx_chip * chip,int port,uint64_t * data)1298 static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1299 uint64_t *data)
1300 {
1301 int count = 0;
1302
1303 if (chip->info->ops->stats_get_stats)
1304 count = chip->info->ops->stats_get_stats(chip, port, data);
1305
1306 mv88e6xxx_reg_lock(chip);
1307 if (chip->info->ops->serdes_get_stats) {
1308 data += count;
1309 count = chip->info->ops->serdes_get_stats(chip, port, data);
1310 }
1311 data += count;
1312 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
1313 mv88e6xxx_reg_unlock(chip);
1314 }
1315
mv88e6xxx_get_ethtool_stats(struct dsa_switch * ds,int port,uint64_t * data)1316 static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1317 uint64_t *data)
1318 {
1319 struct mv88e6xxx_chip *chip = ds->priv;
1320 int ret;
1321
1322 mv88e6xxx_reg_lock(chip);
1323
1324 ret = mv88e6xxx_stats_snapshot(chip, port);
1325 mv88e6xxx_reg_unlock(chip);
1326
1327 if (ret < 0)
1328 return;
1329
1330 mv88e6xxx_get_stats(chip, port, data);
1331
1332 }
1333
mv88e6xxx_get_regs_len(struct dsa_switch * ds,int port)1334 static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1335 {
1336 struct mv88e6xxx_chip *chip = ds->priv;
1337 int len;
1338
1339 len = 32 * sizeof(u16);
1340 if (chip->info->ops->serdes_get_regs_len)
1341 len += chip->info->ops->serdes_get_regs_len(chip, port);
1342
1343 return len;
1344 }
1345
mv88e6xxx_get_regs(struct dsa_switch * ds,int port,struct ethtool_regs * regs,void * _p)1346 static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1347 struct ethtool_regs *regs, void *_p)
1348 {
1349 struct mv88e6xxx_chip *chip = ds->priv;
1350 int err;
1351 u16 reg;
1352 u16 *p = _p;
1353 int i;
1354
1355 regs->version = chip->info->prod_num;
1356
1357 memset(p, 0xff, 32 * sizeof(u16));
1358
1359 mv88e6xxx_reg_lock(chip);
1360
1361 for (i = 0; i < 32; i++) {
1362
1363 err = mv88e6xxx_port_read(chip, port, i, ®);
1364 if (!err)
1365 p[i] = reg;
1366 }
1367
1368 if (chip->info->ops->serdes_get_regs)
1369 chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1370
1371 mv88e6xxx_reg_unlock(chip);
1372 }
1373
mv88e6xxx_get_mac_eee(struct dsa_switch * ds,int port,struct ethtool_eee * e)1374 static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1375 struct ethtool_eee *e)
1376 {
1377 /* Nothing to do on the port's MAC */
1378 return 0;
1379 }
1380
mv88e6xxx_set_mac_eee(struct dsa_switch * ds,int port,struct ethtool_eee * e)1381 static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1382 struct ethtool_eee *e)
1383 {
1384 /* Nothing to do on the port's MAC */
1385 return 0;
1386 }
1387
1388 /* Mask of the local ports allowed to receive frames from a given fabric port */
mv88e6xxx_port_vlan(struct mv88e6xxx_chip * chip,int dev,int port)1389 static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
1390 {
1391 struct dsa_switch *ds = chip->ds;
1392 struct dsa_switch_tree *dst = ds->dst;
1393 struct dsa_port *dp, *other_dp;
1394 bool found = false;
1395 u16 pvlan;
1396
1397 /* dev is a physical switch */
1398 if (dev <= dst->last_switch) {
1399 list_for_each_entry(dp, &dst->ports, list) {
1400 if (dp->ds->index == dev && dp->index == port) {
1401 /* dp might be a DSA link or a user port, so it
1402 * might or might not have a bridge.
1403 * Use the "found" variable for both cases.
1404 */
1405 found = true;
1406 break;
1407 }
1408 }
1409 /* dev is a virtual bridge */
1410 } else {
1411 list_for_each_entry(dp, &dst->ports, list) {
1412 unsigned int bridge_num = dsa_port_bridge_num_get(dp);
1413
1414 if (!bridge_num)
1415 continue;
1416
1417 if (bridge_num + dst->last_switch != dev)
1418 continue;
1419
1420 found = true;
1421 break;
1422 }
1423 }
1424
1425 /* Prevent frames from unknown switch or virtual bridge */
1426 if (!found)
1427 return 0;
1428
1429 /* Frames from DSA links and CPU ports can egress any local port */
1430 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
1431 return mv88e6xxx_port_mask(chip);
1432
1433 pvlan = 0;
1434
1435 /* Frames from standalone user ports can only egress on the
1436 * upstream port.
1437 */
1438 if (!dsa_port_bridge_dev_get(dp))
1439 return BIT(dsa_switch_upstream_port(ds));
1440
1441 /* Frames from bridged user ports can egress any local DSA
1442 * links and CPU ports, as well as any local member of their
1443 * bridge group.
1444 */
1445 dsa_switch_for_each_port(other_dp, ds)
1446 if (other_dp->type == DSA_PORT_TYPE_CPU ||
1447 other_dp->type == DSA_PORT_TYPE_DSA ||
1448 dsa_port_bridge_same(dp, other_dp))
1449 pvlan |= BIT(other_dp->index);
1450
1451 return pvlan;
1452 }
1453
mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip * chip,int port)1454 static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
1455 {
1456 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
1457
1458 /* prevent frames from going back out of the port they came in on */
1459 output_ports &= ~BIT(port);
1460
1461 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1462 }
1463
mv88e6xxx_port_stp_state_set(struct dsa_switch * ds,int port,u8 state)1464 static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1465 u8 state)
1466 {
1467 struct mv88e6xxx_chip *chip = ds->priv;
1468 int err;
1469
1470 mv88e6xxx_reg_lock(chip);
1471 err = mv88e6xxx_port_set_state(chip, port, state);
1472 mv88e6xxx_reg_unlock(chip);
1473
1474 if (err)
1475 dev_err(ds->dev, "p%d: failed to update state\n", port);
1476 }
1477
mv88e6xxx_pri_setup(struct mv88e6xxx_chip * chip)1478 static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1479 {
1480 int err;
1481
1482 if (chip->info->ops->ieee_pri_map) {
1483 err = chip->info->ops->ieee_pri_map(chip);
1484 if (err)
1485 return err;
1486 }
1487
1488 if (chip->info->ops->ip_pri_map) {
1489 err = chip->info->ops->ip_pri_map(chip);
1490 if (err)
1491 return err;
1492 }
1493
1494 return 0;
1495 }
1496
mv88e6xxx_devmap_setup(struct mv88e6xxx_chip * chip)1497 static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1498 {
1499 struct dsa_switch *ds = chip->ds;
1500 int target, port;
1501 int err;
1502
1503 if (!chip->info->global2_addr)
1504 return 0;
1505
1506 /* Initialize the routing port to the 32 possible target devices */
1507 for (target = 0; target < 32; target++) {
1508 port = dsa_routing_port(ds, target);
1509 if (port == ds->num_ports)
1510 port = 0x1f;
1511
1512 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1513 if (err)
1514 return err;
1515 }
1516
1517 if (chip->info->ops->set_cascade_port) {
1518 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1519 err = chip->info->ops->set_cascade_port(chip, port);
1520 if (err)
1521 return err;
1522 }
1523
1524 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1525 if (err)
1526 return err;
1527
1528 return 0;
1529 }
1530
mv88e6xxx_trunk_setup(struct mv88e6xxx_chip * chip)1531 static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1532 {
1533 /* Clear all trunk masks and mapping */
1534 if (chip->info->global2_addr)
1535 return mv88e6xxx_g2_trunk_clear(chip);
1536
1537 return 0;
1538 }
1539
mv88e6xxx_rmu_setup(struct mv88e6xxx_chip * chip)1540 static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1541 {
1542 if (chip->info->ops->rmu_disable)
1543 return chip->info->ops->rmu_disable(chip);
1544
1545 return 0;
1546 }
1547
mv88e6xxx_pot_setup(struct mv88e6xxx_chip * chip)1548 static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1549 {
1550 if (chip->info->ops->pot_clear)
1551 return chip->info->ops->pot_clear(chip);
1552
1553 return 0;
1554 }
1555
mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip * chip)1556 static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1557 {
1558 if (chip->info->ops->mgmt_rsvd2cpu)
1559 return chip->info->ops->mgmt_rsvd2cpu(chip);
1560
1561 return 0;
1562 }
1563
mv88e6xxx_atu_setup(struct mv88e6xxx_chip * chip)1564 static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1565 {
1566 int err;
1567
1568 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1569 if (err)
1570 return err;
1571
1572 /* The chips that have a "learn2all" bit in Global1, ATU
1573 * Control are precisely those whose port registers have a
1574 * Message Port bit in Port Control 1 and hence implement
1575 * ->port_setup_message_port.
1576 */
1577 if (chip->info->ops->port_setup_message_port) {
1578 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1579 if (err)
1580 return err;
1581 }
1582
1583 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1584 }
1585
mv88e6xxx_irl_setup(struct mv88e6xxx_chip * chip)1586 static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1587 {
1588 int port;
1589 int err;
1590
1591 if (!chip->info->ops->irl_init_all)
1592 return 0;
1593
1594 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1595 /* Disable ingress rate limiting by resetting all per port
1596 * ingress rate limit resources to their initial state.
1597 */
1598 err = chip->info->ops->irl_init_all(chip, port);
1599 if (err)
1600 return err;
1601 }
1602
1603 return 0;
1604 }
1605
mv88e6xxx_mac_setup(struct mv88e6xxx_chip * chip)1606 static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1607 {
1608 if (chip->info->ops->set_switch_mac) {
1609 u8 addr[ETH_ALEN];
1610
1611 eth_random_addr(addr);
1612
1613 return chip->info->ops->set_switch_mac(chip, addr);
1614 }
1615
1616 return 0;
1617 }
1618
mv88e6xxx_pvt_map(struct mv88e6xxx_chip * chip,int dev,int port)1619 static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1620 {
1621 struct dsa_switch_tree *dst = chip->ds->dst;
1622 struct dsa_switch *ds;
1623 struct dsa_port *dp;
1624 u16 pvlan = 0;
1625
1626 if (!mv88e6xxx_has_pvt(chip))
1627 return 0;
1628
1629 /* Skip the local source device, which uses in-chip port VLAN */
1630 if (dev != chip->ds->index) {
1631 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
1632
1633 ds = dsa_switch_find(dst->index, dev);
1634 dp = ds ? dsa_to_port(ds, port) : NULL;
1635 if (dp && dp->lag) {
1636 /* As the PVT is used to limit flooding of
1637 * FORWARD frames, which use the LAG ID as the
1638 * source port, we must translate dev/port to
1639 * the special "LAG device" in the PVT, using
1640 * the LAG ID (one-based) as the port number
1641 * (zero-based).
1642 */
1643 dev = MV88E6XXX_G2_PVT_ADDR_DEV_TRUNK;
1644 port = dsa_port_lag_id_get(dp) - 1;
1645 }
1646 }
1647
1648 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1649 }
1650
mv88e6xxx_pvt_setup(struct mv88e6xxx_chip * chip)1651 static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1652 {
1653 int dev, port;
1654 int err;
1655
1656 if (!mv88e6xxx_has_pvt(chip))
1657 return 0;
1658
1659 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1660 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1661 */
1662 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1663 if (err)
1664 return err;
1665
1666 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1667 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1668 err = mv88e6xxx_pvt_map(chip, dev, port);
1669 if (err)
1670 return err;
1671 }
1672 }
1673
1674 return 0;
1675 }
1676
mv88e6xxx_port_fast_age_fid(struct mv88e6xxx_chip * chip,int port,u16 fid)1677 static int mv88e6xxx_port_fast_age_fid(struct mv88e6xxx_chip *chip, int port,
1678 u16 fid)
1679 {
1680 if (dsa_to_port(chip->ds, port)->lag)
1681 /* Hardware is incapable of fast-aging a LAG through a
1682 * regular ATU move operation. Until we have something
1683 * more fancy in place this is a no-op.
1684 */
1685 return -EOPNOTSUPP;
1686
1687 return mv88e6xxx_g1_atu_remove(chip, fid, port, false);
1688 }
1689
mv88e6xxx_port_fast_age(struct dsa_switch * ds,int port)1690 static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1691 {
1692 struct mv88e6xxx_chip *chip = ds->priv;
1693 int err;
1694
1695 mv88e6xxx_reg_lock(chip);
1696 err = mv88e6xxx_port_fast_age_fid(chip, port, 0);
1697 mv88e6xxx_reg_unlock(chip);
1698
1699 if (err)
1700 dev_err(chip->ds->dev, "p%d: failed to flush ATU: %d\n",
1701 port, err);
1702 }
1703
mv88e6xxx_vtu_setup(struct mv88e6xxx_chip * chip)1704 static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1705 {
1706 if (!mv88e6xxx_max_vid(chip))
1707 return 0;
1708
1709 return mv88e6xxx_g1_vtu_flush(chip);
1710 }
1711
mv88e6xxx_vtu_get(struct mv88e6xxx_chip * chip,u16 vid,struct mv88e6xxx_vtu_entry * entry)1712 static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1713 struct mv88e6xxx_vtu_entry *entry)
1714 {
1715 int err;
1716
1717 if (!chip->info->ops->vtu_getnext)
1718 return -EOPNOTSUPP;
1719
1720 entry->vid = vid ? vid - 1 : mv88e6xxx_max_vid(chip);
1721 entry->valid = false;
1722
1723 err = chip->info->ops->vtu_getnext(chip, entry);
1724
1725 if (entry->vid != vid)
1726 entry->valid = false;
1727
1728 return err;
1729 }
1730
mv88e6xxx_vtu_walk(struct mv88e6xxx_chip * chip,int (* cb)(struct mv88e6xxx_chip * chip,const struct mv88e6xxx_vtu_entry * entry,void * priv),void * priv)1731 static int mv88e6xxx_vtu_walk(struct mv88e6xxx_chip *chip,
1732 int (*cb)(struct mv88e6xxx_chip *chip,
1733 const struct mv88e6xxx_vtu_entry *entry,
1734 void *priv),
1735 void *priv)
1736 {
1737 struct mv88e6xxx_vtu_entry entry = {
1738 .vid = mv88e6xxx_max_vid(chip),
1739 .valid = false,
1740 };
1741 int err;
1742
1743 if (!chip->info->ops->vtu_getnext)
1744 return -EOPNOTSUPP;
1745
1746 do {
1747 err = chip->info->ops->vtu_getnext(chip, &entry);
1748 if (err)
1749 return err;
1750
1751 if (!entry.valid)
1752 break;
1753
1754 err = cb(chip, &entry, priv);
1755 if (err)
1756 return err;
1757 } while (entry.vid < mv88e6xxx_max_vid(chip));
1758
1759 return 0;
1760 }
1761
mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip * chip,struct mv88e6xxx_vtu_entry * entry)1762 static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1763 struct mv88e6xxx_vtu_entry *entry)
1764 {
1765 if (!chip->info->ops->vtu_loadpurge)
1766 return -EOPNOTSUPP;
1767
1768 return chip->info->ops->vtu_loadpurge(chip, entry);
1769 }
1770
mv88e6xxx_fid_map_vlan(struct mv88e6xxx_chip * chip,const struct mv88e6xxx_vtu_entry * entry,void * _fid_bitmap)1771 static int mv88e6xxx_fid_map_vlan(struct mv88e6xxx_chip *chip,
1772 const struct mv88e6xxx_vtu_entry *entry,
1773 void *_fid_bitmap)
1774 {
1775 unsigned long *fid_bitmap = _fid_bitmap;
1776
1777 set_bit(entry->fid, fid_bitmap);
1778 return 0;
1779 }
1780
mv88e6xxx_fid_map(struct mv88e6xxx_chip * chip,unsigned long * fid_bitmap)1781 int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
1782 {
1783 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1784
1785 /* Every FID has an associated VID, so walking the VTU
1786 * will discover the full set of FIDs in use.
1787 */
1788 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_fid_map_vlan, fid_bitmap);
1789 }
1790
mv88e6xxx_atu_new(struct mv88e6xxx_chip * chip,u16 * fid)1791 static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1792 {
1793 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1794 int err;
1795
1796 err = mv88e6xxx_fid_map(chip, fid_bitmap);
1797 if (err)
1798 return err;
1799
1800 *fid = find_first_zero_bit(fid_bitmap, MV88E6XXX_N_FID);
1801 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1802 return -ENOSPC;
1803
1804 /* Clear the database */
1805 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
1806 }
1807
mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip * chip,struct mv88e6xxx_stu_entry * entry)1808 static int mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
1809 struct mv88e6xxx_stu_entry *entry)
1810 {
1811 if (!chip->info->ops->stu_loadpurge)
1812 return -EOPNOTSUPP;
1813
1814 return chip->info->ops->stu_loadpurge(chip, entry);
1815 }
1816
mv88e6xxx_stu_setup(struct mv88e6xxx_chip * chip)1817 static int mv88e6xxx_stu_setup(struct mv88e6xxx_chip *chip)
1818 {
1819 struct mv88e6xxx_stu_entry stu = {
1820 .valid = true,
1821 .sid = 0
1822 };
1823
1824 if (!mv88e6xxx_has_stu(chip))
1825 return 0;
1826
1827 /* Make sure that SID 0 is always valid. This is used by VTU
1828 * entries that do not make use of the STU, e.g. when creating
1829 * a VLAN upper on a port that is also part of a VLAN
1830 * filtering bridge.
1831 */
1832 return mv88e6xxx_stu_loadpurge(chip, &stu);
1833 }
1834
mv88e6xxx_sid_get(struct mv88e6xxx_chip * chip,u8 * sid)1835 static int mv88e6xxx_sid_get(struct mv88e6xxx_chip *chip, u8 *sid)
1836 {
1837 DECLARE_BITMAP(busy, MV88E6XXX_N_SID) = { 0 };
1838 struct mv88e6xxx_mst *mst;
1839
1840 __set_bit(0, busy);
1841
1842 list_for_each_entry(mst, &chip->msts, node)
1843 __set_bit(mst->stu.sid, busy);
1844
1845 *sid = find_first_zero_bit(busy, MV88E6XXX_N_SID);
1846
1847 return (*sid >= mv88e6xxx_max_sid(chip)) ? -ENOSPC : 0;
1848 }
1849
mv88e6xxx_mst_put(struct mv88e6xxx_chip * chip,u8 sid)1850 static int mv88e6xxx_mst_put(struct mv88e6xxx_chip *chip, u8 sid)
1851 {
1852 struct mv88e6xxx_mst *mst, *tmp;
1853 int err;
1854
1855 if (!sid)
1856 return 0;
1857
1858 list_for_each_entry_safe(mst, tmp, &chip->msts, node) {
1859 if (mst->stu.sid != sid)
1860 continue;
1861
1862 if (!refcount_dec_and_test(&mst->refcnt))
1863 return 0;
1864
1865 mst->stu.valid = false;
1866 err = mv88e6xxx_stu_loadpurge(chip, &mst->stu);
1867 if (err) {
1868 refcount_set(&mst->refcnt, 1);
1869 return err;
1870 }
1871
1872 list_del(&mst->node);
1873 kfree(mst);
1874 return 0;
1875 }
1876
1877 return -ENOENT;
1878 }
1879
mv88e6xxx_mst_get(struct mv88e6xxx_chip * chip,struct net_device * br,u16 msti,u8 * sid)1880 static int mv88e6xxx_mst_get(struct mv88e6xxx_chip *chip, struct net_device *br,
1881 u16 msti, u8 *sid)
1882 {
1883 struct mv88e6xxx_mst *mst;
1884 int err, i;
1885
1886 if (!mv88e6xxx_has_stu(chip)) {
1887 err = -EOPNOTSUPP;
1888 goto err;
1889 }
1890
1891 if (!msti) {
1892 *sid = 0;
1893 return 0;
1894 }
1895
1896 list_for_each_entry(mst, &chip->msts, node) {
1897 if (mst->br == br && mst->msti == msti) {
1898 refcount_inc(&mst->refcnt);
1899 *sid = mst->stu.sid;
1900 return 0;
1901 }
1902 }
1903
1904 err = mv88e6xxx_sid_get(chip, sid);
1905 if (err)
1906 goto err;
1907
1908 mst = kzalloc(sizeof(*mst), GFP_KERNEL);
1909 if (!mst) {
1910 err = -ENOMEM;
1911 goto err;
1912 }
1913
1914 INIT_LIST_HEAD(&mst->node);
1915 refcount_set(&mst->refcnt, 1);
1916 mst->br = br;
1917 mst->msti = msti;
1918 mst->stu.valid = true;
1919 mst->stu.sid = *sid;
1920
1921 /* The bridge starts out all ports in the disabled state. But
1922 * a STU state of disabled means to go by the port-global
1923 * state. So we set all user port's initial state to blocking,
1924 * to match the bridge's behavior.
1925 */
1926 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
1927 mst->stu.state[i] = dsa_is_user_port(chip->ds, i) ?
1928 MV88E6XXX_PORT_CTL0_STATE_BLOCKING :
1929 MV88E6XXX_PORT_CTL0_STATE_DISABLED;
1930
1931 err = mv88e6xxx_stu_loadpurge(chip, &mst->stu);
1932 if (err)
1933 goto err_free;
1934
1935 list_add_tail(&mst->node, &chip->msts);
1936 return 0;
1937
1938 err_free:
1939 kfree(mst);
1940 err:
1941 return err;
1942 }
1943
mv88e6xxx_port_mst_state_set(struct dsa_switch * ds,int port,const struct switchdev_mst_state * st)1944 static int mv88e6xxx_port_mst_state_set(struct dsa_switch *ds, int port,
1945 const struct switchdev_mst_state *st)
1946 {
1947 struct dsa_port *dp = dsa_to_port(ds, port);
1948 struct mv88e6xxx_chip *chip = ds->priv;
1949 struct mv88e6xxx_mst *mst;
1950 u8 state;
1951 int err;
1952
1953 if (!mv88e6xxx_has_stu(chip))
1954 return -EOPNOTSUPP;
1955
1956 switch (st->state) {
1957 case BR_STATE_DISABLED:
1958 case BR_STATE_BLOCKING:
1959 case BR_STATE_LISTENING:
1960 state = MV88E6XXX_PORT_CTL0_STATE_BLOCKING;
1961 break;
1962 case BR_STATE_LEARNING:
1963 state = MV88E6XXX_PORT_CTL0_STATE_LEARNING;
1964 break;
1965 case BR_STATE_FORWARDING:
1966 state = MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
1967 break;
1968 default:
1969 return -EINVAL;
1970 }
1971
1972 list_for_each_entry(mst, &chip->msts, node) {
1973 if (mst->br == dsa_port_bridge_dev_get(dp) &&
1974 mst->msti == st->msti) {
1975 if (mst->stu.state[port] == state)
1976 return 0;
1977
1978 mst->stu.state[port] = state;
1979 mv88e6xxx_reg_lock(chip);
1980 err = mv88e6xxx_stu_loadpurge(chip, &mst->stu);
1981 mv88e6xxx_reg_unlock(chip);
1982 return err;
1983 }
1984 }
1985
1986 return -ENOENT;
1987 }
1988
mv88e6xxx_port_check_hw_vlan(struct dsa_switch * ds,int port,u16 vid)1989 static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1990 u16 vid)
1991 {
1992 struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
1993 struct mv88e6xxx_chip *chip = ds->priv;
1994 struct mv88e6xxx_vtu_entry vlan;
1995 int err;
1996
1997 /* DSA and CPU ports have to be members of multiple vlans */
1998 if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp))
1999 return 0;
2000
2001 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
2002 if (err)
2003 return err;
2004
2005 if (!vlan.valid)
2006 return 0;
2007
2008 dsa_switch_for_each_user_port(other_dp, ds) {
2009 struct net_device *other_br;
2010
2011 if (vlan.member[other_dp->index] ==
2012 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
2013 continue;
2014
2015 if (dsa_port_bridge_same(dp, other_dp))
2016 break; /* same bridge, check next VLAN */
2017
2018 other_br = dsa_port_bridge_dev_get(other_dp);
2019 if (!other_br)
2020 continue;
2021
2022 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
2023 port, vlan.vid, other_dp->index, netdev_name(other_br));
2024 return -EOPNOTSUPP;
2025 }
2026
2027 return 0;
2028 }
2029
mv88e6xxx_port_commit_pvid(struct mv88e6xxx_chip * chip,int port)2030 static int mv88e6xxx_port_commit_pvid(struct mv88e6xxx_chip *chip, int port)
2031 {
2032 struct dsa_port *dp = dsa_to_port(chip->ds, port);
2033 struct net_device *br = dsa_port_bridge_dev_get(dp);
2034 struct mv88e6xxx_port *p = &chip->ports[port];
2035 u16 pvid = MV88E6XXX_VID_STANDALONE;
2036 bool drop_untagged = false;
2037 int err;
2038
2039 if (br) {
2040 if (br_vlan_enabled(br)) {
2041 pvid = p->bridge_pvid.vid;
2042 drop_untagged = !p->bridge_pvid.valid;
2043 } else {
2044 pvid = MV88E6XXX_VID_BRIDGED;
2045 }
2046 }
2047
2048 err = mv88e6xxx_port_set_pvid(chip, port, pvid);
2049 if (err)
2050 return err;
2051
2052 return mv88e6xxx_port_drop_untagged(chip, port, drop_untagged);
2053 }
2054
mv88e6xxx_port_vlan_filtering(struct dsa_switch * ds,int port,bool vlan_filtering,struct netlink_ext_ack * extack)2055 static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
2056 bool vlan_filtering,
2057 struct netlink_ext_ack *extack)
2058 {
2059 struct mv88e6xxx_chip *chip = ds->priv;
2060 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
2061 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
2062 int err;
2063
2064 if (!mv88e6xxx_max_vid(chip))
2065 return -EOPNOTSUPP;
2066
2067 mv88e6xxx_reg_lock(chip);
2068
2069 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
2070 if (err)
2071 goto unlock;
2072
2073 err = mv88e6xxx_port_commit_pvid(chip, port);
2074 if (err)
2075 goto unlock;
2076
2077 unlock:
2078 mv88e6xxx_reg_unlock(chip);
2079
2080 return err;
2081 }
2082
2083 static int
mv88e6xxx_port_vlan_prepare(struct dsa_switch * ds,int port,const struct switchdev_obj_port_vlan * vlan)2084 mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
2085 const struct switchdev_obj_port_vlan *vlan)
2086 {
2087 struct mv88e6xxx_chip *chip = ds->priv;
2088 int err;
2089
2090 if (!mv88e6xxx_max_vid(chip))
2091 return -EOPNOTSUPP;
2092
2093 /* If the requested port doesn't belong to the same bridge as the VLAN
2094 * members, do not support it (yet) and fallback to software VLAN.
2095 */
2096 mv88e6xxx_reg_lock(chip);
2097 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid);
2098 mv88e6xxx_reg_unlock(chip);
2099
2100 return err;
2101 }
2102
mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip * chip,int port,const unsigned char * addr,u16 vid,u8 state)2103 static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2104 const unsigned char *addr, u16 vid,
2105 u8 state)
2106 {
2107 struct mv88e6xxx_atu_entry entry;
2108 struct mv88e6xxx_vtu_entry vlan;
2109 u16 fid;
2110 int err;
2111
2112 /* Ports have two private address databases: one for when the port is
2113 * standalone and one for when the port is under a bridge and the
2114 * 802.1Q mode is disabled. When the port is standalone, DSA wants its
2115 * address database to remain 100% empty, so we never load an ATU entry
2116 * into a standalone port's database. Therefore, translate the null
2117 * VLAN ID into the port's database used for VLAN-unaware bridging.
2118 */
2119 if (vid == 0) {
2120 fid = MV88E6XXX_FID_BRIDGED;
2121 } else {
2122 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
2123 if (err)
2124 return err;
2125
2126 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
2127 if (!vlan.valid)
2128 return -EOPNOTSUPP;
2129
2130 fid = vlan.fid;
2131 }
2132
2133 entry.state = 0;
2134 ether_addr_copy(entry.mac, addr);
2135 eth_addr_dec(entry.mac);
2136
2137 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
2138 if (err)
2139 return err;
2140
2141 /* Initialize a fresh ATU entry if it isn't found */
2142 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
2143 memset(&entry, 0, sizeof(entry));
2144 ether_addr_copy(entry.mac, addr);
2145 }
2146
2147 /* Purge the ATU entry only if no port is using it anymore */
2148 if (!state) {
2149 entry.portvec &= ~BIT(port);
2150 if (!entry.portvec)
2151 entry.state = 0;
2152 } else {
2153 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
2154 entry.portvec = BIT(port);
2155 else
2156 entry.portvec |= BIT(port);
2157
2158 entry.state = state;
2159 }
2160
2161 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
2162 }
2163
mv88e6xxx_policy_apply(struct mv88e6xxx_chip * chip,int port,const struct mv88e6xxx_policy * policy)2164 static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
2165 const struct mv88e6xxx_policy *policy)
2166 {
2167 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
2168 enum mv88e6xxx_policy_action action = policy->action;
2169 const u8 *addr = policy->addr;
2170 u16 vid = policy->vid;
2171 u8 state;
2172 int err;
2173 int id;
2174
2175 if (!chip->info->ops->port_set_policy)
2176 return -EOPNOTSUPP;
2177
2178 switch (mapping) {
2179 case MV88E6XXX_POLICY_MAPPING_DA:
2180 case MV88E6XXX_POLICY_MAPPING_SA:
2181 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
2182 state = 0; /* Dissociate the port and address */
2183 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
2184 is_multicast_ether_addr(addr))
2185 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
2186 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
2187 is_unicast_ether_addr(addr))
2188 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
2189 else
2190 return -EOPNOTSUPP;
2191
2192 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2193 state);
2194 if (err)
2195 return err;
2196 break;
2197 default:
2198 return -EOPNOTSUPP;
2199 }
2200
2201 /* Skip the port's policy clearing if the mapping is still in use */
2202 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
2203 idr_for_each_entry(&chip->policies, policy, id)
2204 if (policy->port == port &&
2205 policy->mapping == mapping &&
2206 policy->action != action)
2207 return 0;
2208
2209 return chip->info->ops->port_set_policy(chip, port, mapping, action);
2210 }
2211
mv88e6xxx_policy_insert(struct mv88e6xxx_chip * chip,int port,struct ethtool_rx_flow_spec * fs)2212 static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
2213 struct ethtool_rx_flow_spec *fs)
2214 {
2215 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
2216 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
2217 enum mv88e6xxx_policy_mapping mapping;
2218 enum mv88e6xxx_policy_action action;
2219 struct mv88e6xxx_policy *policy;
2220 u16 vid = 0;
2221 u8 *addr;
2222 int err;
2223 int id;
2224
2225 if (fs->location != RX_CLS_LOC_ANY)
2226 return -EINVAL;
2227
2228 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
2229 action = MV88E6XXX_POLICY_ACTION_DISCARD;
2230 else
2231 return -EOPNOTSUPP;
2232
2233 switch (fs->flow_type & ~FLOW_EXT) {
2234 case ETHER_FLOW:
2235 if (!is_zero_ether_addr(mac_mask->h_dest) &&
2236 is_zero_ether_addr(mac_mask->h_source)) {
2237 mapping = MV88E6XXX_POLICY_MAPPING_DA;
2238 addr = mac_entry->h_dest;
2239 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
2240 !is_zero_ether_addr(mac_mask->h_source)) {
2241 mapping = MV88E6XXX_POLICY_MAPPING_SA;
2242 addr = mac_entry->h_source;
2243 } else {
2244 /* Cannot support DA and SA mapping in the same rule */
2245 return -EOPNOTSUPP;
2246 }
2247 break;
2248 default:
2249 return -EOPNOTSUPP;
2250 }
2251
2252 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
2253 if (fs->m_ext.vlan_tci != htons(0xffff))
2254 return -EOPNOTSUPP;
2255 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
2256 }
2257
2258 idr_for_each_entry(&chip->policies, policy, id) {
2259 if (policy->port == port && policy->mapping == mapping &&
2260 policy->action == action && policy->vid == vid &&
2261 ether_addr_equal(policy->addr, addr))
2262 return -EEXIST;
2263 }
2264
2265 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
2266 if (!policy)
2267 return -ENOMEM;
2268
2269 fs->location = 0;
2270 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
2271 GFP_KERNEL);
2272 if (err) {
2273 devm_kfree(chip->dev, policy);
2274 return err;
2275 }
2276
2277 memcpy(&policy->fs, fs, sizeof(*fs));
2278 ether_addr_copy(policy->addr, addr);
2279 policy->mapping = mapping;
2280 policy->action = action;
2281 policy->port = port;
2282 policy->vid = vid;
2283
2284 err = mv88e6xxx_policy_apply(chip, port, policy);
2285 if (err) {
2286 idr_remove(&chip->policies, fs->location);
2287 devm_kfree(chip->dev, policy);
2288 return err;
2289 }
2290
2291 return 0;
2292 }
2293
mv88e6xxx_get_rxnfc(struct dsa_switch * ds,int port,struct ethtool_rxnfc * rxnfc,u32 * rule_locs)2294 static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
2295 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
2296 {
2297 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
2298 struct mv88e6xxx_chip *chip = ds->priv;
2299 struct mv88e6xxx_policy *policy;
2300 int err;
2301 int id;
2302
2303 mv88e6xxx_reg_lock(chip);
2304
2305 switch (rxnfc->cmd) {
2306 case ETHTOOL_GRXCLSRLCNT:
2307 rxnfc->data = 0;
2308 rxnfc->data |= RX_CLS_LOC_SPECIAL;
2309 rxnfc->rule_cnt = 0;
2310 idr_for_each_entry(&chip->policies, policy, id)
2311 if (policy->port == port)
2312 rxnfc->rule_cnt++;
2313 err = 0;
2314 break;
2315 case ETHTOOL_GRXCLSRULE:
2316 err = -ENOENT;
2317 policy = idr_find(&chip->policies, fs->location);
2318 if (policy) {
2319 memcpy(fs, &policy->fs, sizeof(*fs));
2320 err = 0;
2321 }
2322 break;
2323 case ETHTOOL_GRXCLSRLALL:
2324 rxnfc->data = 0;
2325 rxnfc->rule_cnt = 0;
2326 idr_for_each_entry(&chip->policies, policy, id)
2327 if (policy->port == port)
2328 rule_locs[rxnfc->rule_cnt++] = id;
2329 err = 0;
2330 break;
2331 default:
2332 err = -EOPNOTSUPP;
2333 break;
2334 }
2335
2336 mv88e6xxx_reg_unlock(chip);
2337
2338 return err;
2339 }
2340
mv88e6xxx_set_rxnfc(struct dsa_switch * ds,int port,struct ethtool_rxnfc * rxnfc)2341 static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
2342 struct ethtool_rxnfc *rxnfc)
2343 {
2344 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
2345 struct mv88e6xxx_chip *chip = ds->priv;
2346 struct mv88e6xxx_policy *policy;
2347 int err;
2348
2349 mv88e6xxx_reg_lock(chip);
2350
2351 switch (rxnfc->cmd) {
2352 case ETHTOOL_SRXCLSRLINS:
2353 err = mv88e6xxx_policy_insert(chip, port, fs);
2354 break;
2355 case ETHTOOL_SRXCLSRLDEL:
2356 err = -ENOENT;
2357 policy = idr_remove(&chip->policies, fs->location);
2358 if (policy) {
2359 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
2360 err = mv88e6xxx_policy_apply(chip, port, policy);
2361 devm_kfree(chip->dev, policy);
2362 }
2363 break;
2364 default:
2365 err = -EOPNOTSUPP;
2366 break;
2367 }
2368
2369 mv88e6xxx_reg_unlock(chip);
2370
2371 return err;
2372 }
2373
mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip * chip,int port,u16 vid)2374 static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
2375 u16 vid)
2376 {
2377 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
2378 u8 broadcast[ETH_ALEN];
2379
2380 eth_broadcast_addr(broadcast);
2381
2382 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
2383 }
2384
mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip * chip,u16 vid)2385 static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
2386 {
2387 int port;
2388 int err;
2389
2390 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2391 struct dsa_port *dp = dsa_to_port(chip->ds, port);
2392 struct net_device *brport;
2393
2394 if (dsa_is_unused_port(chip->ds, port))
2395 continue;
2396
2397 brport = dsa_port_to_bridge_port(dp);
2398 if (brport && !br_port_flag_is_set(brport, BR_BCAST_FLOOD))
2399 /* Skip bridged user ports where broadcast
2400 * flooding is disabled.
2401 */
2402 continue;
2403
2404 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
2405 if (err)
2406 return err;
2407 }
2408
2409 return 0;
2410 }
2411
2412 struct mv88e6xxx_port_broadcast_sync_ctx {
2413 int port;
2414 bool flood;
2415 };
2416
2417 static int
mv88e6xxx_port_broadcast_sync_vlan(struct mv88e6xxx_chip * chip,const struct mv88e6xxx_vtu_entry * vlan,void * _ctx)2418 mv88e6xxx_port_broadcast_sync_vlan(struct mv88e6xxx_chip *chip,
2419 const struct mv88e6xxx_vtu_entry *vlan,
2420 void *_ctx)
2421 {
2422 struct mv88e6xxx_port_broadcast_sync_ctx *ctx = _ctx;
2423 u8 broadcast[ETH_ALEN];
2424 u8 state;
2425
2426 if (ctx->flood)
2427 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
2428 else
2429 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_UNUSED;
2430
2431 eth_broadcast_addr(broadcast);
2432
2433 return mv88e6xxx_port_db_load_purge(chip, ctx->port, broadcast,
2434 vlan->vid, state);
2435 }
2436
mv88e6xxx_port_broadcast_sync(struct mv88e6xxx_chip * chip,int port,bool flood)2437 static int mv88e6xxx_port_broadcast_sync(struct mv88e6xxx_chip *chip, int port,
2438 bool flood)
2439 {
2440 struct mv88e6xxx_port_broadcast_sync_ctx ctx = {
2441 .port = port,
2442 .flood = flood,
2443 };
2444 struct mv88e6xxx_vtu_entry vid0 = {
2445 .vid = 0,
2446 };
2447 int err;
2448
2449 /* Update the port's private database... */
2450 err = mv88e6xxx_port_broadcast_sync_vlan(chip, &vid0, &ctx);
2451 if (err)
2452 return err;
2453
2454 /* ...and the database for all VLANs. */
2455 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_broadcast_sync_vlan,
2456 &ctx);
2457 }
2458
mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip * chip,int port,u16 vid,u8 member,bool warn)2459 static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
2460 u16 vid, u8 member, bool warn)
2461 {
2462 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
2463 struct mv88e6xxx_vtu_entry vlan;
2464 int i, err;
2465
2466 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
2467 if (err)
2468 return err;
2469
2470 if (!vlan.valid) {
2471 memset(&vlan, 0, sizeof(vlan));
2472
2473 if (vid == MV88E6XXX_VID_STANDALONE)
2474 vlan.policy = true;
2475
2476 err = mv88e6xxx_atu_new(chip, &vlan.fid);
2477 if (err)
2478 return err;
2479
2480 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
2481 if (i == port)
2482 vlan.member[i] = member;
2483 else
2484 vlan.member[i] = non_member;
2485
2486 vlan.vid = vid;
2487 vlan.valid = true;
2488
2489 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2490 if (err)
2491 return err;
2492
2493 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
2494 if (err)
2495 return err;
2496 } else if (vlan.member[port] != member) {
2497 vlan.member[port] = member;
2498
2499 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2500 if (err)
2501 return err;
2502 } else if (warn) {
2503 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
2504 port, vid);
2505 }
2506
2507 return 0;
2508 }
2509
mv88e6xxx_port_vlan_add(struct dsa_switch * ds,int port,const struct switchdev_obj_port_vlan * vlan,struct netlink_ext_ack * extack)2510 static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
2511 const struct switchdev_obj_port_vlan *vlan,
2512 struct netlink_ext_ack *extack)
2513 {
2514 struct mv88e6xxx_chip *chip = ds->priv;
2515 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
2516 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
2517 struct mv88e6xxx_port *p = &chip->ports[port];
2518 bool warn;
2519 u8 member;
2520 int err;
2521
2522 if (!vlan->vid)
2523 return 0;
2524
2525 err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
2526 if (err)
2527 return err;
2528
2529 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
2530 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
2531 else if (untagged)
2532 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
2533 else
2534 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
2535
2536 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
2537 * and then the CPU port. Do not warn for duplicates for the CPU port.
2538 */
2539 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
2540
2541 mv88e6xxx_reg_lock(chip);
2542
2543 err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
2544 if (err) {
2545 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2546 vlan->vid, untagged ? 'u' : 't');
2547 goto out;
2548 }
2549
2550 if (pvid) {
2551 p->bridge_pvid.vid = vlan->vid;
2552 p->bridge_pvid.valid = true;
2553
2554 err = mv88e6xxx_port_commit_pvid(chip, port);
2555 if (err)
2556 goto out;
2557 } else if (vlan->vid && p->bridge_pvid.vid == vlan->vid) {
2558 /* The old pvid was reinstalled as a non-pvid VLAN */
2559 p->bridge_pvid.valid = false;
2560
2561 err = mv88e6xxx_port_commit_pvid(chip, port);
2562 if (err)
2563 goto out;
2564 }
2565
2566 out:
2567 mv88e6xxx_reg_unlock(chip);
2568
2569 return err;
2570 }
2571
mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip * chip,int port,u16 vid)2572 static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2573 int port, u16 vid)
2574 {
2575 struct mv88e6xxx_vtu_entry vlan;
2576 int i, err;
2577
2578 if (!vid)
2579 return 0;
2580
2581 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
2582 if (err)
2583 return err;
2584
2585 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2586 * tell switchdev that this VLAN is likely handled in software.
2587 */
2588 if (!vlan.valid ||
2589 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
2590 return -EOPNOTSUPP;
2591
2592 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
2593
2594 /* keep the VLAN unless all ports are excluded */
2595 vlan.valid = false;
2596 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
2597 if (vlan.member[i] !=
2598 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
2599 vlan.valid = true;
2600 break;
2601 }
2602 }
2603
2604 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2605 if (err)
2606 return err;
2607
2608 if (!vlan.valid) {
2609 err = mv88e6xxx_mst_put(chip, vlan.sid);
2610 if (err)
2611 return err;
2612 }
2613
2614 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
2615 }
2616
mv88e6xxx_port_vlan_del(struct dsa_switch * ds,int port,const struct switchdev_obj_port_vlan * vlan)2617 static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2618 const struct switchdev_obj_port_vlan *vlan)
2619 {
2620 struct mv88e6xxx_chip *chip = ds->priv;
2621 struct mv88e6xxx_port *p = &chip->ports[port];
2622 int err = 0;
2623 u16 pvid;
2624
2625 if (!mv88e6xxx_max_vid(chip))
2626 return -EOPNOTSUPP;
2627
2628 /* The ATU removal procedure needs the FID to be mapped in the VTU,
2629 * but FDB deletion runs concurrently with VLAN deletion. Flush the DSA
2630 * switchdev workqueue to ensure that all FDB entries are deleted
2631 * before we remove the VLAN.
2632 */
2633 dsa_flush_workqueue();
2634
2635 mv88e6xxx_reg_lock(chip);
2636
2637 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
2638 if (err)
2639 goto unlock;
2640
2641 err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
2642 if (err)
2643 goto unlock;
2644
2645 if (vlan->vid == pvid) {
2646 p->bridge_pvid.valid = false;
2647
2648 err = mv88e6xxx_port_commit_pvid(chip, port);
2649 if (err)
2650 goto unlock;
2651 }
2652
2653 unlock:
2654 mv88e6xxx_reg_unlock(chip);
2655
2656 return err;
2657 }
2658
mv88e6xxx_port_vlan_fast_age(struct dsa_switch * ds,int port,u16 vid)2659 static int mv88e6xxx_port_vlan_fast_age(struct dsa_switch *ds, int port, u16 vid)
2660 {
2661 struct mv88e6xxx_chip *chip = ds->priv;
2662 struct mv88e6xxx_vtu_entry vlan;
2663 int err;
2664
2665 mv88e6xxx_reg_lock(chip);
2666
2667 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
2668 if (err)
2669 goto unlock;
2670
2671 err = mv88e6xxx_port_fast_age_fid(chip, port, vlan.fid);
2672
2673 unlock:
2674 mv88e6xxx_reg_unlock(chip);
2675
2676 return err;
2677 }
2678
mv88e6xxx_vlan_msti_set(struct dsa_switch * ds,struct dsa_bridge bridge,const struct switchdev_vlan_msti * msti)2679 static int mv88e6xxx_vlan_msti_set(struct dsa_switch *ds,
2680 struct dsa_bridge bridge,
2681 const struct switchdev_vlan_msti *msti)
2682 {
2683 struct mv88e6xxx_chip *chip = ds->priv;
2684 struct mv88e6xxx_vtu_entry vlan;
2685 u8 old_sid, new_sid;
2686 int err;
2687
2688 if (!mv88e6xxx_has_stu(chip))
2689 return -EOPNOTSUPP;
2690
2691 mv88e6xxx_reg_lock(chip);
2692
2693 err = mv88e6xxx_vtu_get(chip, msti->vid, &vlan);
2694 if (err)
2695 goto unlock;
2696
2697 if (!vlan.valid) {
2698 err = -EINVAL;
2699 goto unlock;
2700 }
2701
2702 old_sid = vlan.sid;
2703
2704 err = mv88e6xxx_mst_get(chip, bridge.dev, msti->msti, &new_sid);
2705 if (err)
2706 goto unlock;
2707
2708 if (new_sid != old_sid) {
2709 vlan.sid = new_sid;
2710
2711 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2712 if (err) {
2713 mv88e6xxx_mst_put(chip, new_sid);
2714 goto unlock;
2715 }
2716 }
2717
2718 err = mv88e6xxx_mst_put(chip, old_sid);
2719
2720 unlock:
2721 mv88e6xxx_reg_unlock(chip);
2722 return err;
2723 }
2724
mv88e6xxx_port_fdb_add(struct dsa_switch * ds,int port,const unsigned char * addr,u16 vid,struct dsa_db db)2725 static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2726 const unsigned char *addr, u16 vid,
2727 struct dsa_db db)
2728 {
2729 struct mv88e6xxx_chip *chip = ds->priv;
2730 int err;
2731
2732 mv88e6xxx_reg_lock(chip);
2733 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2734 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2735 mv88e6xxx_reg_unlock(chip);
2736
2737 return err;
2738 }
2739
mv88e6xxx_port_fdb_del(struct dsa_switch * ds,int port,const unsigned char * addr,u16 vid,struct dsa_db db)2740 static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2741 const unsigned char *addr, u16 vid,
2742 struct dsa_db db)
2743 {
2744 struct mv88e6xxx_chip *chip = ds->priv;
2745 int err;
2746
2747 mv88e6xxx_reg_lock(chip);
2748 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
2749 mv88e6xxx_reg_unlock(chip);
2750
2751 return err;
2752 }
2753
mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip * chip,u16 fid,u16 vid,int port,dsa_fdb_dump_cb_t * cb,void * data)2754 static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2755 u16 fid, u16 vid, int port,
2756 dsa_fdb_dump_cb_t *cb, void *data)
2757 {
2758 struct mv88e6xxx_atu_entry addr;
2759 bool is_static;
2760 int err;
2761
2762 addr.state = 0;
2763 eth_broadcast_addr(addr.mac);
2764
2765 do {
2766 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
2767 if (err)
2768 return err;
2769
2770 if (!addr.state)
2771 break;
2772
2773 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
2774 continue;
2775
2776 if (!is_unicast_ether_addr(addr.mac))
2777 continue;
2778
2779 is_static = (addr.state ==
2780 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2781 err = cb(addr.mac, vid, is_static, data);
2782 if (err)
2783 return err;
2784 } while (!is_broadcast_ether_addr(addr.mac));
2785
2786 return err;
2787 }
2788
2789 struct mv88e6xxx_port_db_dump_vlan_ctx {
2790 int port;
2791 dsa_fdb_dump_cb_t *cb;
2792 void *data;
2793 };
2794
mv88e6xxx_port_db_dump_vlan(struct mv88e6xxx_chip * chip,const struct mv88e6xxx_vtu_entry * entry,void * _data)2795 static int mv88e6xxx_port_db_dump_vlan(struct mv88e6xxx_chip *chip,
2796 const struct mv88e6xxx_vtu_entry *entry,
2797 void *_data)
2798 {
2799 struct mv88e6xxx_port_db_dump_vlan_ctx *ctx = _data;
2800
2801 return mv88e6xxx_port_db_dump_fid(chip, entry->fid, entry->vid,
2802 ctx->port, ctx->cb, ctx->data);
2803 }
2804
mv88e6xxx_port_db_dump(struct mv88e6xxx_chip * chip,int port,dsa_fdb_dump_cb_t * cb,void * data)2805 static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2806 dsa_fdb_dump_cb_t *cb, void *data)
2807 {
2808 struct mv88e6xxx_port_db_dump_vlan_ctx ctx = {
2809 .port = port,
2810 .cb = cb,
2811 .data = data,
2812 };
2813 u16 fid;
2814 int err;
2815
2816 /* Dump port's default Filtering Information Database (VLAN ID 0) */
2817 err = mv88e6xxx_port_get_fid(chip, port, &fid);
2818 if (err)
2819 return err;
2820
2821 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
2822 if (err)
2823 return err;
2824
2825 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_db_dump_vlan, &ctx);
2826 }
2827
mv88e6xxx_port_fdb_dump(struct dsa_switch * ds,int port,dsa_fdb_dump_cb_t * cb,void * data)2828 static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2829 dsa_fdb_dump_cb_t *cb, void *data)
2830 {
2831 struct mv88e6xxx_chip *chip = ds->priv;
2832 int err;
2833
2834 mv88e6xxx_reg_lock(chip);
2835 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
2836 mv88e6xxx_reg_unlock(chip);
2837
2838 return err;
2839 }
2840
mv88e6xxx_bridge_map(struct mv88e6xxx_chip * chip,struct dsa_bridge bridge)2841 static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2842 struct dsa_bridge bridge)
2843 {
2844 struct dsa_switch *ds = chip->ds;
2845 struct dsa_switch_tree *dst = ds->dst;
2846 struct dsa_port *dp;
2847 int err;
2848
2849 list_for_each_entry(dp, &dst->ports, list) {
2850 if (dsa_port_offloads_bridge(dp, &bridge)) {
2851 if (dp->ds == ds) {
2852 /* This is a local bridge group member,
2853 * remap its Port VLAN Map.
2854 */
2855 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2856 if (err)
2857 return err;
2858 } else {
2859 /* This is an external bridge group member,
2860 * remap its cross-chip Port VLAN Table entry.
2861 */
2862 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2863 dp->index);
2864 if (err)
2865 return err;
2866 }
2867 }
2868 }
2869
2870 return 0;
2871 }
2872
2873 /* Treat the software bridge as a virtual single-port switch behind the
2874 * CPU and map in the PVT. First dst->last_switch elements are taken by
2875 * physical switches, so start from beyond that range.
2876 */
mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch * ds,unsigned int bridge_num)2877 static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
2878 unsigned int bridge_num)
2879 {
2880 u8 dev = bridge_num + ds->dst->last_switch;
2881 struct mv88e6xxx_chip *chip = ds->priv;
2882
2883 return mv88e6xxx_pvt_map(chip, dev, 0);
2884 }
2885
mv88e6xxx_port_bridge_join(struct dsa_switch * ds,int port,struct dsa_bridge bridge,bool * tx_fwd_offload,struct netlink_ext_ack * extack)2886 static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
2887 struct dsa_bridge bridge,
2888 bool *tx_fwd_offload,
2889 struct netlink_ext_ack *extack)
2890 {
2891 struct mv88e6xxx_chip *chip = ds->priv;
2892 int err;
2893
2894 mv88e6xxx_reg_lock(chip);
2895
2896 err = mv88e6xxx_bridge_map(chip, bridge);
2897 if (err)
2898 goto unlock;
2899
2900 err = mv88e6xxx_port_set_map_da(chip, port, true);
2901 if (err)
2902 goto unlock;
2903
2904 err = mv88e6xxx_port_commit_pvid(chip, port);
2905 if (err)
2906 goto unlock;
2907
2908 if (mv88e6xxx_has_pvt(chip)) {
2909 err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num);
2910 if (err)
2911 goto unlock;
2912
2913 *tx_fwd_offload = true;
2914 }
2915
2916 unlock:
2917 mv88e6xxx_reg_unlock(chip);
2918
2919 return err;
2920 }
2921
mv88e6xxx_port_bridge_leave(struct dsa_switch * ds,int port,struct dsa_bridge bridge)2922 static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2923 struct dsa_bridge bridge)
2924 {
2925 struct mv88e6xxx_chip *chip = ds->priv;
2926 int err;
2927
2928 mv88e6xxx_reg_lock(chip);
2929
2930 if (bridge.tx_fwd_offload &&
2931 mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num))
2932 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
2933
2934 if (mv88e6xxx_bridge_map(chip, bridge) ||
2935 mv88e6xxx_port_vlan_map(chip, port))
2936 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
2937
2938 err = mv88e6xxx_port_set_map_da(chip, port, false);
2939 if (err)
2940 dev_err(ds->dev,
2941 "port %d failed to restore map-DA: %pe\n",
2942 port, ERR_PTR(err));
2943
2944 err = mv88e6xxx_port_commit_pvid(chip, port);
2945 if (err)
2946 dev_err(ds->dev,
2947 "port %d failed to restore standalone pvid: %pe\n",
2948 port, ERR_PTR(err));
2949
2950 mv88e6xxx_reg_unlock(chip);
2951 }
2952
mv88e6xxx_crosschip_bridge_join(struct dsa_switch * ds,int tree_index,int sw_index,int port,struct dsa_bridge bridge,struct netlink_ext_ack * extack)2953 static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2954 int tree_index, int sw_index,
2955 int port, struct dsa_bridge bridge,
2956 struct netlink_ext_ack *extack)
2957 {
2958 struct mv88e6xxx_chip *chip = ds->priv;
2959 int err;
2960
2961 if (tree_index != ds->dst->index)
2962 return 0;
2963
2964 mv88e6xxx_reg_lock(chip);
2965 err = mv88e6xxx_pvt_map(chip, sw_index, port);
2966 err = err ? : mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num);
2967 mv88e6xxx_reg_unlock(chip);
2968
2969 return err;
2970 }
2971
mv88e6xxx_crosschip_bridge_leave(struct dsa_switch * ds,int tree_index,int sw_index,int port,struct dsa_bridge bridge)2972 static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2973 int tree_index, int sw_index,
2974 int port, struct dsa_bridge bridge)
2975 {
2976 struct mv88e6xxx_chip *chip = ds->priv;
2977
2978 if (tree_index != ds->dst->index)
2979 return;
2980
2981 mv88e6xxx_reg_lock(chip);
2982 if (mv88e6xxx_pvt_map(chip, sw_index, port) ||
2983 mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge.num))
2984 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
2985 mv88e6xxx_reg_unlock(chip);
2986 }
2987
mv88e6xxx_software_reset(struct mv88e6xxx_chip * chip)2988 static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2989 {
2990 if (chip->info->ops->reset)
2991 return chip->info->ops->reset(chip);
2992
2993 return 0;
2994 }
2995
mv88e6xxx_hardware_reset(struct mv88e6xxx_chip * chip)2996 static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2997 {
2998 struct gpio_desc *gpiod = chip->reset;
2999
3000 /* If there is a GPIO connected to the reset pin, toggle it */
3001 if (gpiod) {
3002 gpiod_set_value_cansleep(gpiod, 1);
3003 usleep_range(10000, 20000);
3004 gpiod_set_value_cansleep(gpiod, 0);
3005 usleep_range(10000, 20000);
3006
3007 mv88e6xxx_g1_wait_eeprom_done(chip);
3008 }
3009 }
3010
mv88e6xxx_disable_ports(struct mv88e6xxx_chip * chip)3011 static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
3012 {
3013 int i, err;
3014
3015 /* Set all ports to the Disabled state */
3016 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3017 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
3018 if (err)
3019 return err;
3020 }
3021
3022 /* Wait for transmit queues to drain,
3023 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
3024 */
3025 usleep_range(2000, 4000);
3026
3027 return 0;
3028 }
3029
mv88e6xxx_switch_reset(struct mv88e6xxx_chip * chip)3030 static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
3031 {
3032 int err;
3033
3034 err = mv88e6xxx_disable_ports(chip);
3035 if (err)
3036 return err;
3037
3038 mv88e6xxx_hardware_reset(chip);
3039
3040 return mv88e6xxx_software_reset(chip);
3041 }
3042
mv88e6xxx_set_port_mode(struct mv88e6xxx_chip * chip,int port,enum mv88e6xxx_frame_mode frame,enum mv88e6xxx_egress_mode egress,u16 etype)3043 static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
3044 enum mv88e6xxx_frame_mode frame,
3045 enum mv88e6xxx_egress_mode egress, u16 etype)
3046 {
3047 int err;
3048
3049 if (!chip->info->ops->port_set_frame_mode)
3050 return -EOPNOTSUPP;
3051
3052 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
3053 if (err)
3054 return err;
3055
3056 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
3057 if (err)
3058 return err;
3059
3060 if (chip->info->ops->port_set_ether_type)
3061 return chip->info->ops->port_set_ether_type(chip, port, etype);
3062
3063 return 0;
3064 }
3065
mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip * chip,int port)3066 static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
3067 {
3068 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
3069 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
3070 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
3071 }
3072
mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip * chip,int port)3073 static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
3074 {
3075 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
3076 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
3077 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
3078 }
3079
mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip * chip,int port)3080 static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
3081 {
3082 return mv88e6xxx_set_port_mode(chip, port,
3083 MV88E6XXX_FRAME_MODE_ETHERTYPE,
3084 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
3085 ETH_P_EDSA);
3086 }
3087
mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip * chip,int port)3088 static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
3089 {
3090 if (dsa_is_dsa_port(chip->ds, port))
3091 return mv88e6xxx_set_port_mode_dsa(chip, port);
3092
3093 if (dsa_is_user_port(chip->ds, port))
3094 return mv88e6xxx_set_port_mode_normal(chip, port);
3095
3096 /* Setup CPU port mode depending on its supported tag format */
3097 if (chip->tag_protocol == DSA_TAG_PROTO_DSA)
3098 return mv88e6xxx_set_port_mode_dsa(chip, port);
3099
3100 if (chip->tag_protocol == DSA_TAG_PROTO_EDSA)
3101 return mv88e6xxx_set_port_mode_edsa(chip, port);
3102
3103 return -EINVAL;
3104 }
3105
mv88e6xxx_setup_message_port(struct mv88e6xxx_chip * chip,int port)3106 static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
3107 {
3108 bool message = dsa_is_dsa_port(chip->ds, port);
3109
3110 return mv88e6xxx_port_set_message_port(chip, port, message);
3111 }
3112
mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip * chip,int port)3113 static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
3114 {
3115 int err;
3116
3117 if (chip->info->ops->port_set_ucast_flood) {
3118 err = chip->info->ops->port_set_ucast_flood(chip, port, true);
3119 if (err)
3120 return err;
3121 }
3122 if (chip->info->ops->port_set_mcast_flood) {
3123 err = chip->info->ops->port_set_mcast_flood(chip, port, true);
3124 if (err)
3125 return err;
3126 }
3127
3128 return 0;
3129 }
3130
mv88e6xxx_serdes_irq_thread_fn(int irq,void * dev_id)3131 static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
3132 {
3133 struct mv88e6xxx_port *mvp = dev_id;
3134 struct mv88e6xxx_chip *chip = mvp->chip;
3135 irqreturn_t ret = IRQ_NONE;
3136 int port = mvp->port;
3137 int lane;
3138
3139 mv88e6xxx_reg_lock(chip);
3140 lane = mv88e6xxx_serdes_get_lane(chip, port);
3141 if (lane >= 0)
3142 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
3143 mv88e6xxx_reg_unlock(chip);
3144
3145 return ret;
3146 }
3147
mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip * chip,int port,int lane)3148 static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
3149 int lane)
3150 {
3151 struct mv88e6xxx_port *dev_id = &chip->ports[port];
3152 unsigned int irq;
3153 int err;
3154
3155 /* Nothing to request if this SERDES port has no IRQ */
3156 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
3157 if (!irq)
3158 return 0;
3159
3160 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
3161 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
3162
3163 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
3164 mv88e6xxx_reg_unlock(chip);
3165 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
3166 IRQF_ONESHOT, dev_id->serdes_irq_name,
3167 dev_id);
3168 mv88e6xxx_reg_lock(chip);
3169 if (err)
3170 return err;
3171
3172 dev_id->serdes_irq = irq;
3173
3174 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
3175 }
3176
mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip * chip,int port,int lane)3177 static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
3178 int lane)
3179 {
3180 struct mv88e6xxx_port *dev_id = &chip->ports[port];
3181 unsigned int irq = dev_id->serdes_irq;
3182 int err;
3183
3184 /* Nothing to free if no IRQ has been requested */
3185 if (!irq)
3186 return 0;
3187
3188 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
3189
3190 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
3191 mv88e6xxx_reg_unlock(chip);
3192 free_irq(irq, dev_id);
3193 mv88e6xxx_reg_lock(chip);
3194
3195 dev_id->serdes_irq = 0;
3196
3197 return err;
3198 }
3199
mv88e6xxx_serdes_power(struct mv88e6xxx_chip * chip,int port,bool on)3200 static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
3201 bool on)
3202 {
3203 int lane;
3204 int err;
3205
3206 lane = mv88e6xxx_serdes_get_lane(chip, port);
3207 if (lane < 0)
3208 return 0;
3209
3210 if (on) {
3211 err = mv88e6xxx_serdes_power_up(chip, port, lane);
3212 if (err)
3213 return err;
3214
3215 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
3216 } else {
3217 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
3218 if (err)
3219 return err;
3220
3221 err = mv88e6xxx_serdes_power_down(chip, port, lane);
3222 }
3223
3224 return err;
3225 }
3226
mv88e6xxx_set_egress_port(struct mv88e6xxx_chip * chip,enum mv88e6xxx_egress_direction direction,int port)3227 static int mv88e6xxx_set_egress_port(struct mv88e6xxx_chip *chip,
3228 enum mv88e6xxx_egress_direction direction,
3229 int port)
3230 {
3231 int err;
3232
3233 if (!chip->info->ops->set_egress_port)
3234 return -EOPNOTSUPP;
3235
3236 err = chip->info->ops->set_egress_port(chip, direction, port);
3237 if (err)
3238 return err;
3239
3240 if (direction == MV88E6XXX_EGRESS_DIR_INGRESS)
3241 chip->ingress_dest_port = port;
3242 else
3243 chip->egress_dest_port = port;
3244
3245 return 0;
3246 }
3247
mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip * chip,int port)3248 static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
3249 {
3250 struct dsa_switch *ds = chip->ds;
3251 int upstream_port;
3252 int err;
3253
3254 upstream_port = dsa_upstream_port(ds, port);
3255 if (chip->info->ops->port_set_upstream_port) {
3256 err = chip->info->ops->port_set_upstream_port(chip, port,
3257 upstream_port);
3258 if (err)
3259 return err;
3260 }
3261
3262 if (port == upstream_port) {
3263 if (chip->info->ops->set_cpu_port) {
3264 err = chip->info->ops->set_cpu_port(chip,
3265 upstream_port);
3266 if (err)
3267 return err;
3268 }
3269
3270 err = mv88e6xxx_set_egress_port(chip,
3271 MV88E6XXX_EGRESS_DIR_INGRESS,
3272 upstream_port);
3273 if (err && err != -EOPNOTSUPP)
3274 return err;
3275
3276 err = mv88e6xxx_set_egress_port(chip,
3277 MV88E6XXX_EGRESS_DIR_EGRESS,
3278 upstream_port);
3279 if (err && err != -EOPNOTSUPP)
3280 return err;
3281 }
3282
3283 return 0;
3284 }
3285
mv88e6xxx_setup_port(struct mv88e6xxx_chip * chip,int port)3286 static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
3287 {
3288 struct device_node *phy_handle = NULL;
3289 struct dsa_switch *ds = chip->ds;
3290 phy_interface_t mode;
3291 struct dsa_port *dp;
3292 int tx_amp, speed;
3293 int err;
3294 u16 reg;
3295
3296 chip->ports[port].chip = chip;
3297 chip->ports[port].port = port;
3298
3299 dp = dsa_to_port(ds, port);
3300
3301 /* MAC Forcing register: don't force link, speed, duplex or flow control
3302 * state to any particular values on physical ports, but force the CPU
3303 * port and all DSA ports to their maximum bandwidth and full duplex.
3304 */
3305 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
3306 struct phylink_config pl_config = {};
3307 unsigned long caps;
3308
3309 chip->info->ops->phylink_get_caps(chip, port, &pl_config);
3310
3311 caps = pl_config.mac_capabilities;
3312
3313 if (chip->info->ops->port_max_speed_mode)
3314 mode = chip->info->ops->port_max_speed_mode(port);
3315 else
3316 mode = PHY_INTERFACE_MODE_NA;
3317
3318 if (caps & MAC_10000FD)
3319 speed = SPEED_10000;
3320 else if (caps & MAC_5000FD)
3321 speed = SPEED_5000;
3322 else if (caps & MAC_2500FD)
3323 speed = SPEED_2500;
3324 else if (caps & MAC_1000)
3325 speed = SPEED_1000;
3326 else if (caps & MAC_100)
3327 speed = SPEED_100;
3328 else
3329 speed = SPEED_10;
3330
3331 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
3332 speed, DUPLEX_FULL,
3333 PAUSE_OFF, mode);
3334 } else {
3335 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
3336 SPEED_UNFORCED, DUPLEX_UNFORCED,
3337 PAUSE_ON,
3338 PHY_INTERFACE_MODE_NA);
3339 }
3340 if (err)
3341 return err;
3342
3343 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
3344 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
3345 * tunneling, determine priority by looking at 802.1p and IP
3346 * priority fields (IP prio has precedence), and set STP state
3347 * to Forwarding.
3348 *
3349 * If this is the CPU link, use DSA or EDSA tagging depending
3350 * on which tagging mode was configured.
3351 *
3352 * If this is a link to another switch, use DSA tagging mode.
3353 *
3354 * If this is the upstream port for this switch, enable
3355 * forwarding of unknown unicasts and multicasts.
3356 */
3357 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
3358 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
3359 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
3360 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
3361 if (err)
3362 return err;
3363
3364 err = mv88e6xxx_setup_port_mode(chip, port);
3365 if (err)
3366 return err;
3367
3368 err = mv88e6xxx_setup_egress_floods(chip, port);
3369 if (err)
3370 return err;
3371
3372 /* Port Control 2: don't force a good FCS, set the MTU size to
3373 * 10222 bytes, disable 802.1q tags checking, don't discard
3374 * tagged or untagged frames on this port, skip destination
3375 * address lookup on user ports, disable ARP mirroring and don't
3376 * send a copy of all transmitted/received frames on this port
3377 * to the CPU.
3378 */
3379 err = mv88e6xxx_port_set_map_da(chip, port, !dsa_is_user_port(ds, port));
3380 if (err)
3381 return err;
3382
3383 err = mv88e6xxx_setup_upstream_port(chip, port);
3384 if (err)
3385 return err;
3386
3387 /* On chips that support it, set all downstream DSA ports'
3388 * VLAN policy to TRAP. In combination with loading
3389 * MV88E6XXX_VID_STANDALONE as a policy entry in the VTU, this
3390 * provides a better isolation barrier between standalone
3391 * ports, as the ATU is bypassed on any intermediate switches
3392 * between the incoming port and the CPU.
3393 */
3394 if (dsa_is_downstream_port(ds, port) &&
3395 chip->info->ops->port_set_policy) {
3396 err = chip->info->ops->port_set_policy(chip, port,
3397 MV88E6XXX_POLICY_MAPPING_VTU,
3398 MV88E6XXX_POLICY_ACTION_TRAP);
3399 if (err)
3400 return err;
3401 }
3402
3403 /* User ports start out in standalone mode and 802.1Q is
3404 * therefore disabled. On DSA ports, all valid VIDs are always
3405 * loaded in the VTU - therefore, enable 802.1Q in order to take
3406 * advantage of VLAN policy on chips that supports it.
3407 */
3408 err = mv88e6xxx_port_set_8021q_mode(chip, port,
3409 dsa_is_user_port(ds, port) ?
3410 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED :
3411 MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE);
3412 if (err)
3413 return err;
3414
3415 /* Bind MV88E6XXX_VID_STANDALONE to MV88E6XXX_FID_STANDALONE by
3416 * virtue of the fact that mv88e6xxx_atu_new() will pick it as
3417 * the first free FID. This will be used as the private PVID for
3418 * unbridged ports. Shared (DSA and CPU) ports must also be
3419 * members of this VID, in order to trap all frames assigned to
3420 * it to the CPU.
3421 */
3422 err = mv88e6xxx_port_vlan_join(chip, port, MV88E6XXX_VID_STANDALONE,
3423 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED,
3424 false);
3425 if (err)
3426 return err;
3427
3428 /* Associate MV88E6XXX_VID_BRIDGED with MV88E6XXX_FID_BRIDGED in the
3429 * ATU by virtue of the fact that mv88e6xxx_atu_new() will pick it as
3430 * the first free FID after MV88E6XXX_FID_STANDALONE. This will be used
3431 * as the private PVID on ports under a VLAN-unaware bridge.
3432 * Shared (DSA and CPU) ports must also be members of it, to translate
3433 * the VID from the DSA tag into MV88E6XXX_FID_BRIDGED, instead of
3434 * relying on their port default FID.
3435 */
3436 err = mv88e6xxx_port_vlan_join(chip, port, MV88E6XXX_VID_BRIDGED,
3437 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED,
3438 false);
3439 if (err)
3440 return err;
3441
3442 if (chip->info->ops->port_set_jumbo_size) {
3443 err = chip->info->ops->port_set_jumbo_size(chip, port, 10218);
3444 if (err)
3445 return err;
3446 }
3447
3448 /* Port Association Vector: disable automatic address learning
3449 * on all user ports since they start out in standalone
3450 * mode. When joining a bridge, learning will be configured to
3451 * match the bridge port settings. Enable learning on all
3452 * DSA/CPU ports. NOTE: FROM_CPU frames always bypass the
3453 * learning process.
3454 *
3455 * Disable HoldAt1, IntOnAgeOut, LockedPort, IgnoreWrongData,
3456 * and RefreshLocked. I.e. setup standard automatic learning.
3457 */
3458 if (dsa_is_user_port(ds, port))
3459 reg = 0;
3460 else
3461 reg = 1 << port;
3462
3463 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
3464 reg);
3465 if (err)
3466 return err;
3467
3468 /* Egress rate control 2: disable egress rate control. */
3469 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
3470 0x0000);
3471 if (err)
3472 return err;
3473
3474 if (chip->info->ops->port_pause_limit) {
3475 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
3476 if (err)
3477 return err;
3478 }
3479
3480 if (chip->info->ops->port_disable_learn_limit) {
3481 err = chip->info->ops->port_disable_learn_limit(chip, port);
3482 if (err)
3483 return err;
3484 }
3485
3486 if (chip->info->ops->port_disable_pri_override) {
3487 err = chip->info->ops->port_disable_pri_override(chip, port);
3488 if (err)
3489 return err;
3490 }
3491
3492 if (chip->info->ops->port_tag_remap) {
3493 err = chip->info->ops->port_tag_remap(chip, port);
3494 if (err)
3495 return err;
3496 }
3497
3498 if (chip->info->ops->port_egress_rate_limiting) {
3499 err = chip->info->ops->port_egress_rate_limiting(chip, port);
3500 if (err)
3501 return err;
3502 }
3503
3504 if (chip->info->ops->port_setup_message_port) {
3505 err = chip->info->ops->port_setup_message_port(chip, port);
3506 if (err)
3507 return err;
3508 }
3509
3510 if (chip->info->ops->serdes_set_tx_amplitude) {
3511 if (dp)
3512 phy_handle = of_parse_phandle(dp->dn, "phy-handle", 0);
3513
3514 if (phy_handle && !of_property_read_u32(phy_handle,
3515 "tx-p2p-microvolt",
3516 &tx_amp))
3517 err = chip->info->ops->serdes_set_tx_amplitude(chip,
3518 port, tx_amp);
3519 if (phy_handle) {
3520 of_node_put(phy_handle);
3521 if (err)
3522 return err;
3523 }
3524 }
3525
3526 /* Port based VLAN map: give each port the same default address
3527 * database, and allow bidirectional communication between the
3528 * CPU and DSA port(s), and the other ports.
3529 */
3530 err = mv88e6xxx_port_set_fid(chip, port, MV88E6XXX_FID_STANDALONE);
3531 if (err)
3532 return err;
3533
3534 err = mv88e6xxx_port_vlan_map(chip, port);
3535 if (err)
3536 return err;
3537
3538 /* Default VLAN ID and priority: don't set a default VLAN
3539 * ID, and set the default packet priority to zero.
3540 */
3541 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
3542 }
3543
mv88e6xxx_get_max_mtu(struct dsa_switch * ds,int port)3544 static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
3545 {
3546 struct mv88e6xxx_chip *chip = ds->priv;
3547
3548 if (chip->info->ops->port_set_jumbo_size)
3549 return 10240 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
3550 else if (chip->info->ops->set_max_frame_size)
3551 return 1632 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
3552 return 1522 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
3553 }
3554
mv88e6xxx_change_mtu(struct dsa_switch * ds,int port,int new_mtu)3555 static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
3556 {
3557 struct mv88e6xxx_chip *chip = ds->priv;
3558 int ret = 0;
3559
3560 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
3561 new_mtu += EDSA_HLEN;
3562
3563 mv88e6xxx_reg_lock(chip);
3564 if (chip->info->ops->port_set_jumbo_size)
3565 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
3566 else if (chip->info->ops->set_max_frame_size)
3567 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
3568 else
3569 if (new_mtu > 1522)
3570 ret = -EINVAL;
3571 mv88e6xxx_reg_unlock(chip);
3572
3573 return ret;
3574 }
3575
mv88e6xxx_port_enable(struct dsa_switch * ds,int port,struct phy_device * phydev)3576 static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
3577 struct phy_device *phydev)
3578 {
3579 struct mv88e6xxx_chip *chip = ds->priv;
3580 int err;
3581
3582 mv88e6xxx_reg_lock(chip);
3583 err = mv88e6xxx_serdes_power(chip, port, true);
3584 mv88e6xxx_reg_unlock(chip);
3585
3586 return err;
3587 }
3588
mv88e6xxx_port_disable(struct dsa_switch * ds,int port)3589 static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
3590 {
3591 struct mv88e6xxx_chip *chip = ds->priv;
3592
3593 mv88e6xxx_reg_lock(chip);
3594 if (mv88e6xxx_serdes_power(chip, port, false))
3595 dev_err(chip->dev, "failed to power off SERDES\n");
3596 mv88e6xxx_reg_unlock(chip);
3597 }
3598
mv88e6xxx_set_ageing_time(struct dsa_switch * ds,unsigned int ageing_time)3599 static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
3600 unsigned int ageing_time)
3601 {
3602 struct mv88e6xxx_chip *chip = ds->priv;
3603 int err;
3604
3605 mv88e6xxx_reg_lock(chip);
3606 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
3607 mv88e6xxx_reg_unlock(chip);
3608
3609 return err;
3610 }
3611
mv88e6xxx_stats_setup(struct mv88e6xxx_chip * chip)3612 static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
3613 {
3614 int err;
3615
3616 /* Initialize the statistics unit */
3617 if (chip->info->ops->stats_set_histogram) {
3618 err = chip->info->ops->stats_set_histogram(chip);
3619 if (err)
3620 return err;
3621 }
3622
3623 return mv88e6xxx_g1_stats_clear(chip);
3624 }
3625
3626 /* Check if the errata has already been applied. */
mv88e6390_setup_errata_applied(struct mv88e6xxx_chip * chip)3627 static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
3628 {
3629 int port;
3630 int err;
3631 u16 val;
3632
3633 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
3634 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
3635 if (err) {
3636 dev_err(chip->dev,
3637 "Error reading hidden register: %d\n", err);
3638 return false;
3639 }
3640 if (val != 0x01c0)
3641 return false;
3642 }
3643
3644 return true;
3645 }
3646
3647 /* The 6390 copper ports have an errata which require poking magic
3648 * values into undocumented hidden registers and then performing a
3649 * software reset.
3650 */
mv88e6390_setup_errata(struct mv88e6xxx_chip * chip)3651 static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
3652 {
3653 int port;
3654 int err;
3655
3656 if (mv88e6390_setup_errata_applied(chip))
3657 return 0;
3658
3659 /* Set the ports into blocking mode */
3660 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
3661 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
3662 if (err)
3663 return err;
3664 }
3665
3666 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
3667 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
3668 if (err)
3669 return err;
3670 }
3671
3672 return mv88e6xxx_software_reset(chip);
3673 }
3674
mv88e6xxx_teardown(struct dsa_switch * ds)3675 static void mv88e6xxx_teardown(struct dsa_switch *ds)
3676 {
3677 mv88e6xxx_teardown_devlink_params(ds);
3678 dsa_devlink_resources_unregister(ds);
3679 mv88e6xxx_teardown_devlink_regions_global(ds);
3680 }
3681
mv88e6xxx_setup(struct dsa_switch * ds)3682 static int mv88e6xxx_setup(struct dsa_switch *ds)
3683 {
3684 struct mv88e6xxx_chip *chip = ds->priv;
3685 u8 cmode;
3686 int err;
3687 int i;
3688
3689 chip->ds = ds;
3690 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
3691
3692 /* Since virtual bridges are mapped in the PVT, the number we support
3693 * depends on the physical switch topology. We need to let DSA figure
3694 * that out and therefore we cannot set this at dsa_register_switch()
3695 * time.
3696 */
3697 if (mv88e6xxx_has_pvt(chip))
3698 ds->max_num_bridges = MV88E6XXX_MAX_PVT_SWITCHES -
3699 ds->dst->last_switch - 1;
3700
3701 mv88e6xxx_reg_lock(chip);
3702
3703 if (chip->info->ops->setup_errata) {
3704 err = chip->info->ops->setup_errata(chip);
3705 if (err)
3706 goto unlock;
3707 }
3708
3709 /* Cache the cmode of each port. */
3710 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3711 if (chip->info->ops->port_get_cmode) {
3712 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
3713 if (err)
3714 goto unlock;
3715
3716 chip->ports[i].cmode = cmode;
3717 }
3718 }
3719
3720 err = mv88e6xxx_vtu_setup(chip);
3721 if (err)
3722 goto unlock;
3723
3724 /* Must be called after mv88e6xxx_vtu_setup (which flushes the
3725 * VTU, thereby also flushing the STU).
3726 */
3727 err = mv88e6xxx_stu_setup(chip);
3728 if (err)
3729 goto unlock;
3730
3731 /* Setup Switch Port Registers */
3732 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3733 if (dsa_is_unused_port(ds, i))
3734 continue;
3735
3736 /* Prevent the use of an invalid port. */
3737 if (mv88e6xxx_is_invalid_port(chip, i)) {
3738 dev_err(chip->dev, "port %d is invalid\n", i);
3739 err = -EINVAL;
3740 goto unlock;
3741 }
3742
3743 err = mv88e6xxx_setup_port(chip, i);
3744 if (err)
3745 goto unlock;
3746 }
3747
3748 err = mv88e6xxx_irl_setup(chip);
3749 if (err)
3750 goto unlock;
3751
3752 err = mv88e6xxx_mac_setup(chip);
3753 if (err)
3754 goto unlock;
3755
3756 err = mv88e6xxx_phy_setup(chip);
3757 if (err)
3758 goto unlock;
3759
3760 err = mv88e6xxx_pvt_setup(chip);
3761 if (err)
3762 goto unlock;
3763
3764 err = mv88e6xxx_atu_setup(chip);
3765 if (err)
3766 goto unlock;
3767
3768 err = mv88e6xxx_broadcast_setup(chip, 0);
3769 if (err)
3770 goto unlock;
3771
3772 err = mv88e6xxx_pot_setup(chip);
3773 if (err)
3774 goto unlock;
3775
3776 err = mv88e6xxx_rmu_setup(chip);
3777 if (err)
3778 goto unlock;
3779
3780 err = mv88e6xxx_rsvd2cpu_setup(chip);
3781 if (err)
3782 goto unlock;
3783
3784 err = mv88e6xxx_trunk_setup(chip);
3785 if (err)
3786 goto unlock;
3787
3788 err = mv88e6xxx_devmap_setup(chip);
3789 if (err)
3790 goto unlock;
3791
3792 err = mv88e6xxx_pri_setup(chip);
3793 if (err)
3794 goto unlock;
3795
3796 /* Setup PTP Hardware Clock and timestamping */
3797 if (chip->info->ptp_support) {
3798 err = mv88e6xxx_ptp_setup(chip);
3799 if (err)
3800 goto unlock;
3801
3802 err = mv88e6xxx_hwtstamp_setup(chip);
3803 if (err)
3804 goto unlock;
3805 }
3806
3807 err = mv88e6xxx_stats_setup(chip);
3808 if (err)
3809 goto unlock;
3810
3811 unlock:
3812 mv88e6xxx_reg_unlock(chip);
3813
3814 if (err)
3815 return err;
3816
3817 /* Have to be called without holding the register lock, since
3818 * they take the devlink lock, and we later take the locks in
3819 * the reverse order when getting/setting parameters or
3820 * resource occupancy.
3821 */
3822 err = mv88e6xxx_setup_devlink_resources(ds);
3823 if (err)
3824 return err;
3825
3826 err = mv88e6xxx_setup_devlink_params(ds);
3827 if (err)
3828 goto out_resources;
3829
3830 err = mv88e6xxx_setup_devlink_regions_global(ds);
3831 if (err)
3832 goto out_params;
3833
3834 return 0;
3835
3836 out_params:
3837 mv88e6xxx_teardown_devlink_params(ds);
3838 out_resources:
3839 dsa_devlink_resources_unregister(ds);
3840
3841 return err;
3842 }
3843
mv88e6xxx_port_setup(struct dsa_switch * ds,int port)3844 static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
3845 {
3846 return mv88e6xxx_setup_devlink_regions_port(ds, port);
3847 }
3848
mv88e6xxx_port_teardown(struct dsa_switch * ds,int port)3849 static void mv88e6xxx_port_teardown(struct dsa_switch *ds, int port)
3850 {
3851 mv88e6xxx_teardown_devlink_regions_port(ds, port);
3852 }
3853
3854 /* prod_id for switch families which do not have a PHY model number */
3855 static const u16 family_prod_id_table[] = {
3856 [MV88E6XXX_FAMILY_6341] = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3857 [MV88E6XXX_FAMILY_6390] = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
3858 [MV88E6XXX_FAMILY_6393] = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
3859 };
3860
mv88e6xxx_mdio_read(struct mii_bus * bus,int phy,int reg)3861 static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
3862 {
3863 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3864 struct mv88e6xxx_chip *chip = mdio_bus->chip;
3865 u16 prod_id;
3866 u16 val;
3867 int err;
3868
3869 if (!chip->info->ops->phy_read)
3870 return -EOPNOTSUPP;
3871
3872 mv88e6xxx_reg_lock(chip);
3873 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
3874 mv88e6xxx_reg_unlock(chip);
3875
3876 /* Some internal PHYs don't have a model number. */
3877 if (reg == MII_PHYSID2 && !(val & 0x3f0) &&
3878 chip->info->family < ARRAY_SIZE(family_prod_id_table)) {
3879 prod_id = family_prod_id_table[chip->info->family];
3880 if (prod_id)
3881 val |= prod_id >> 4;
3882 }
3883
3884 return err ? err : val;
3885 }
3886
mv88e6xxx_mdio_write(struct mii_bus * bus,int phy,int reg,u16 val)3887 static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
3888 {
3889 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3890 struct mv88e6xxx_chip *chip = mdio_bus->chip;
3891 int err;
3892
3893 if (!chip->info->ops->phy_write)
3894 return -EOPNOTSUPP;
3895
3896 mv88e6xxx_reg_lock(chip);
3897 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
3898 mv88e6xxx_reg_unlock(chip);
3899
3900 return err;
3901 }
3902
mv88e6xxx_mdio_register(struct mv88e6xxx_chip * chip,struct device_node * np,bool external)3903 static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
3904 struct device_node *np,
3905 bool external)
3906 {
3907 static int index;
3908 struct mv88e6xxx_mdio_bus *mdio_bus;
3909 struct mii_bus *bus;
3910 int err;
3911
3912 if (external) {
3913 mv88e6xxx_reg_lock(chip);
3914 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
3915 mv88e6xxx_reg_unlock(chip);
3916
3917 if (err)
3918 return err;
3919 }
3920
3921 bus = mdiobus_alloc_size(sizeof(*mdio_bus));
3922 if (!bus)
3923 return -ENOMEM;
3924
3925 mdio_bus = bus->priv;
3926 mdio_bus->bus = bus;
3927 mdio_bus->chip = chip;
3928 INIT_LIST_HEAD(&mdio_bus->list);
3929 mdio_bus->external = external;
3930
3931 if (np) {
3932 bus->name = np->full_name;
3933 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
3934 } else {
3935 bus->name = "mv88e6xxx SMI";
3936 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3937 }
3938
3939 bus->read = mv88e6xxx_mdio_read;
3940 bus->write = mv88e6xxx_mdio_write;
3941 bus->parent = chip->dev;
3942
3943 if (!external) {
3944 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3945 if (err)
3946 goto out;
3947 }
3948
3949 err = of_mdiobus_register(bus, np);
3950 if (err) {
3951 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
3952 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3953 goto out;
3954 }
3955
3956 if (external)
3957 list_add_tail(&mdio_bus->list, &chip->mdios);
3958 else
3959 list_add(&mdio_bus->list, &chip->mdios);
3960
3961 return 0;
3962
3963 out:
3964 mdiobus_free(bus);
3965 return err;
3966 }
3967
mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip * chip)3968 static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3969
3970 {
3971 struct mv88e6xxx_mdio_bus *mdio_bus, *p;
3972 struct mii_bus *bus;
3973
3974 list_for_each_entry_safe(mdio_bus, p, &chip->mdios, list) {
3975 bus = mdio_bus->bus;
3976
3977 if (!mdio_bus->external)
3978 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3979
3980 mdiobus_unregister(bus);
3981 mdiobus_free(bus);
3982 }
3983 }
3984
mv88e6xxx_mdios_register(struct mv88e6xxx_chip * chip,struct device_node * np)3985 static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3986 struct device_node *np)
3987 {
3988 struct device_node *child;
3989 int err;
3990
3991 /* Always register one mdio bus for the internal/default mdio
3992 * bus. This maybe represented in the device tree, but is
3993 * optional.
3994 */
3995 child = of_get_child_by_name(np, "mdio");
3996 err = mv88e6xxx_mdio_register(chip, child, false);
3997 of_node_put(child);
3998 if (err)
3999 return err;
4000
4001 /* Walk the device tree, and see if there are any other nodes
4002 * which say they are compatible with the external mdio
4003 * bus.
4004 */
4005 for_each_available_child_of_node(np, child) {
4006 if (of_device_is_compatible(
4007 child, "marvell,mv88e6xxx-mdio-external")) {
4008 err = mv88e6xxx_mdio_register(chip, child, true);
4009 if (err) {
4010 mv88e6xxx_mdios_unregister(chip);
4011 of_node_put(child);
4012 return err;
4013 }
4014 }
4015 }
4016
4017 return 0;
4018 }
4019
mv88e6xxx_get_eeprom_len(struct dsa_switch * ds)4020 static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
4021 {
4022 struct mv88e6xxx_chip *chip = ds->priv;
4023
4024 return chip->eeprom_len;
4025 }
4026
mv88e6xxx_get_eeprom(struct dsa_switch * ds,struct ethtool_eeprom * eeprom,u8 * data)4027 static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
4028 struct ethtool_eeprom *eeprom, u8 *data)
4029 {
4030 struct mv88e6xxx_chip *chip = ds->priv;
4031 int err;
4032
4033 if (!chip->info->ops->get_eeprom)
4034 return -EOPNOTSUPP;
4035
4036 mv88e6xxx_reg_lock(chip);
4037 err = chip->info->ops->get_eeprom(chip, eeprom, data);
4038 mv88e6xxx_reg_unlock(chip);
4039
4040 if (err)
4041 return err;
4042
4043 eeprom->magic = 0xc3ec4951;
4044
4045 return 0;
4046 }
4047
mv88e6xxx_set_eeprom(struct dsa_switch * ds,struct ethtool_eeprom * eeprom,u8 * data)4048 static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
4049 struct ethtool_eeprom *eeprom, u8 *data)
4050 {
4051 struct mv88e6xxx_chip *chip = ds->priv;
4052 int err;
4053
4054 if (!chip->info->ops->set_eeprom)
4055 return -EOPNOTSUPP;
4056
4057 if (eeprom->magic != 0xc3ec4951)
4058 return -EINVAL;
4059
4060 mv88e6xxx_reg_lock(chip);
4061 err = chip->info->ops->set_eeprom(chip, eeprom, data);
4062 mv88e6xxx_reg_unlock(chip);
4063
4064 return err;
4065 }
4066
4067 static const struct mv88e6xxx_ops mv88e6085_ops = {
4068 /* MV88E6XXX_FAMILY_6097 */
4069 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4070 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4071 .irl_init_all = mv88e6352_g2_irl_init_all,
4072 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
4073 .phy_read = mv88e6185_phy_ppu_read,
4074 .phy_write = mv88e6185_phy_ppu_write,
4075 .port_set_link = mv88e6xxx_port_set_link,
4076 .port_sync_link = mv88e6xxx_port_sync_link,
4077 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4078 .port_tag_remap = mv88e6095_port_tag_remap,
4079 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4080 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4081 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4082 .port_set_ether_type = mv88e6351_port_set_ether_type,
4083 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4084 .port_pause_limit = mv88e6097_port_pause_limit,
4085 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4086 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4087 .port_get_cmode = mv88e6185_port_get_cmode,
4088 .port_setup_message_port = mv88e6xxx_setup_message_port,
4089 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4090 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4091 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4092 .stats_get_strings = mv88e6095_stats_get_strings,
4093 .stats_get_stats = mv88e6095_stats_get_stats,
4094 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4095 .set_egress_port = mv88e6095_g1_set_egress_port,
4096 .watchdog_ops = &mv88e6097_watchdog_ops,
4097 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4098 .pot_clear = mv88e6xxx_g2_pot_clear,
4099 .ppu_enable = mv88e6185_g1_ppu_enable,
4100 .ppu_disable = mv88e6185_g1_ppu_disable,
4101 .reset = mv88e6185_g1_reset,
4102 .rmu_disable = mv88e6085_g1_rmu_disable,
4103 .vtu_getnext = mv88e6352_g1_vtu_getnext,
4104 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4105 .stu_getnext = mv88e6352_g1_stu_getnext,
4106 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4107 .phylink_get_caps = mv88e6185_phylink_get_caps,
4108 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4109 };
4110
4111 static const struct mv88e6xxx_ops mv88e6095_ops = {
4112 /* MV88E6XXX_FAMILY_6095 */
4113 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4114 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4115 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
4116 .phy_read = mv88e6185_phy_ppu_read,
4117 .phy_write = mv88e6185_phy_ppu_write,
4118 .port_set_link = mv88e6xxx_port_set_link,
4119 .port_sync_link = mv88e6185_port_sync_link,
4120 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4121 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
4122 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
4123 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
4124 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
4125 .port_get_cmode = mv88e6185_port_get_cmode,
4126 .port_setup_message_port = mv88e6xxx_setup_message_port,
4127 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4128 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4129 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4130 .stats_get_strings = mv88e6095_stats_get_strings,
4131 .stats_get_stats = mv88e6095_stats_get_stats,
4132 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
4133 .serdes_power = mv88e6185_serdes_power,
4134 .serdes_get_lane = mv88e6185_serdes_get_lane,
4135 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
4136 .ppu_enable = mv88e6185_g1_ppu_enable,
4137 .ppu_disable = mv88e6185_g1_ppu_disable,
4138 .reset = mv88e6185_g1_reset,
4139 .vtu_getnext = mv88e6185_g1_vtu_getnext,
4140 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4141 .phylink_get_caps = mv88e6095_phylink_get_caps,
4142 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4143 };
4144
4145 static const struct mv88e6xxx_ops mv88e6097_ops = {
4146 /* MV88E6XXX_FAMILY_6097 */
4147 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4148 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4149 .irl_init_all = mv88e6352_g2_irl_init_all,
4150 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4151 .phy_read = mv88e6xxx_g2_smi_phy_read,
4152 .phy_write = mv88e6xxx_g2_smi_phy_write,
4153 .port_set_link = mv88e6xxx_port_set_link,
4154 .port_sync_link = mv88e6185_port_sync_link,
4155 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4156 .port_tag_remap = mv88e6095_port_tag_remap,
4157 .port_set_policy = mv88e6352_port_set_policy,
4158 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4159 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4160 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4161 .port_set_ether_type = mv88e6351_port_set_ether_type,
4162 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
4163 .port_pause_limit = mv88e6097_port_pause_limit,
4164 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4165 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4166 .port_get_cmode = mv88e6185_port_get_cmode,
4167 .port_setup_message_port = mv88e6xxx_setup_message_port,
4168 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4169 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4170 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4171 .stats_get_strings = mv88e6095_stats_get_strings,
4172 .stats_get_stats = mv88e6095_stats_get_stats,
4173 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4174 .set_egress_port = mv88e6095_g1_set_egress_port,
4175 .watchdog_ops = &mv88e6097_watchdog_ops,
4176 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4177 .serdes_power = mv88e6185_serdes_power,
4178 .serdes_get_lane = mv88e6185_serdes_get_lane,
4179 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
4180 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4181 .serdes_irq_enable = mv88e6097_serdes_irq_enable,
4182 .serdes_irq_status = mv88e6097_serdes_irq_status,
4183 .pot_clear = mv88e6xxx_g2_pot_clear,
4184 .reset = mv88e6352_g1_reset,
4185 .rmu_disable = mv88e6085_g1_rmu_disable,
4186 .vtu_getnext = mv88e6352_g1_vtu_getnext,
4187 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4188 .phylink_get_caps = mv88e6095_phylink_get_caps,
4189 .stu_getnext = mv88e6352_g1_stu_getnext,
4190 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4191 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4192 };
4193
4194 static const struct mv88e6xxx_ops mv88e6123_ops = {
4195 /* MV88E6XXX_FAMILY_6165 */
4196 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4197 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4198 .irl_init_all = mv88e6352_g2_irl_init_all,
4199 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4200 .phy_read = mv88e6xxx_g2_smi_phy_read,
4201 .phy_write = mv88e6xxx_g2_smi_phy_write,
4202 .port_set_link = mv88e6xxx_port_set_link,
4203 .port_sync_link = mv88e6xxx_port_sync_link,
4204 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4205 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
4206 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4207 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4208 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4209 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4210 .port_get_cmode = mv88e6185_port_get_cmode,
4211 .port_setup_message_port = mv88e6xxx_setup_message_port,
4212 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4213 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4214 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4215 .stats_get_strings = mv88e6095_stats_get_strings,
4216 .stats_get_stats = mv88e6095_stats_get_stats,
4217 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4218 .set_egress_port = mv88e6095_g1_set_egress_port,
4219 .watchdog_ops = &mv88e6097_watchdog_ops,
4220 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4221 .pot_clear = mv88e6xxx_g2_pot_clear,
4222 .reset = mv88e6352_g1_reset,
4223 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4224 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4225 .vtu_getnext = mv88e6352_g1_vtu_getnext,
4226 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4227 .stu_getnext = mv88e6352_g1_stu_getnext,
4228 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4229 .phylink_get_caps = mv88e6185_phylink_get_caps,
4230 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4231 };
4232
4233 static const struct mv88e6xxx_ops mv88e6131_ops = {
4234 /* MV88E6XXX_FAMILY_6185 */
4235 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4236 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4237 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
4238 .phy_read = mv88e6185_phy_ppu_read,
4239 .phy_write = mv88e6185_phy_ppu_write,
4240 .port_set_link = mv88e6xxx_port_set_link,
4241 .port_sync_link = mv88e6xxx_port_sync_link,
4242 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4243 .port_tag_remap = mv88e6095_port_tag_remap,
4244 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4245 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
4246 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
4247 .port_set_ether_type = mv88e6351_port_set_ether_type,
4248 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
4249 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4250 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4251 .port_pause_limit = mv88e6097_port_pause_limit,
4252 .port_set_pause = mv88e6185_port_set_pause,
4253 .port_get_cmode = mv88e6185_port_get_cmode,
4254 .port_setup_message_port = mv88e6xxx_setup_message_port,
4255 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4256 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4257 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4258 .stats_get_strings = mv88e6095_stats_get_strings,
4259 .stats_get_stats = mv88e6095_stats_get_stats,
4260 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4261 .set_egress_port = mv88e6095_g1_set_egress_port,
4262 .watchdog_ops = &mv88e6097_watchdog_ops,
4263 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
4264 .ppu_enable = mv88e6185_g1_ppu_enable,
4265 .set_cascade_port = mv88e6185_g1_set_cascade_port,
4266 .ppu_disable = mv88e6185_g1_ppu_disable,
4267 .reset = mv88e6185_g1_reset,
4268 .vtu_getnext = mv88e6185_g1_vtu_getnext,
4269 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4270 .phylink_get_caps = mv88e6185_phylink_get_caps,
4271 };
4272
4273 static const struct mv88e6xxx_ops mv88e6141_ops = {
4274 /* MV88E6XXX_FAMILY_6341 */
4275 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4276 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4277 .irl_init_all = mv88e6352_g2_irl_init_all,
4278 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4279 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4280 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4281 .phy_read = mv88e6xxx_g2_smi_phy_read,
4282 .phy_write = mv88e6xxx_g2_smi_phy_write,
4283 .port_set_link = mv88e6xxx_port_set_link,
4284 .port_sync_link = mv88e6xxx_port_sync_link,
4285 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4286 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
4287 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
4288 .port_tag_remap = mv88e6095_port_tag_remap,
4289 .port_set_policy = mv88e6352_port_set_policy,
4290 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4291 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4292 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4293 .port_set_ether_type = mv88e6351_port_set_ether_type,
4294 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4295 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4296 .port_pause_limit = mv88e6097_port_pause_limit,
4297 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4298 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4299 .port_get_cmode = mv88e6352_port_get_cmode,
4300 .port_set_cmode = mv88e6341_port_set_cmode,
4301 .port_setup_message_port = mv88e6xxx_setup_message_port,
4302 .stats_snapshot = mv88e6390_g1_stats_snapshot,
4303 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4304 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4305 .stats_get_strings = mv88e6320_stats_get_strings,
4306 .stats_get_stats = mv88e6390_stats_get_stats,
4307 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4308 .set_egress_port = mv88e6390_g1_set_egress_port,
4309 .watchdog_ops = &mv88e6390_watchdog_ops,
4310 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4311 .pot_clear = mv88e6xxx_g2_pot_clear,
4312 .reset = mv88e6352_g1_reset,
4313 .rmu_disable = mv88e6390_g1_rmu_disable,
4314 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4315 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4316 .vtu_getnext = mv88e6352_g1_vtu_getnext,
4317 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4318 .stu_getnext = mv88e6352_g1_stu_getnext,
4319 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4320 .serdes_power = mv88e6390_serdes_power,
4321 .serdes_get_lane = mv88e6341_serdes_get_lane,
4322 /* Check status register pause & lpa register */
4323 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4324 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4325 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4326 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4327 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4328 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
4329 .serdes_irq_status = mv88e6390_serdes_irq_status,
4330 .gpio_ops = &mv88e6352_gpio_ops,
4331 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4332 .serdes_get_strings = mv88e6390_serdes_get_strings,
4333 .serdes_get_stats = mv88e6390_serdes_get_stats,
4334 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4335 .serdes_get_regs = mv88e6390_serdes_get_regs,
4336 .phylink_get_caps = mv88e6341_phylink_get_caps,
4337 };
4338
4339 static const struct mv88e6xxx_ops mv88e6161_ops = {
4340 /* MV88E6XXX_FAMILY_6165 */
4341 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4342 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4343 .irl_init_all = mv88e6352_g2_irl_init_all,
4344 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4345 .phy_read = mv88e6xxx_g2_smi_phy_read,
4346 .phy_write = mv88e6xxx_g2_smi_phy_write,
4347 .port_set_link = mv88e6xxx_port_set_link,
4348 .port_sync_link = mv88e6xxx_port_sync_link,
4349 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4350 .port_tag_remap = mv88e6095_port_tag_remap,
4351 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4352 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4353 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4354 .port_set_ether_type = mv88e6351_port_set_ether_type,
4355 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4356 .port_pause_limit = mv88e6097_port_pause_limit,
4357 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4358 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4359 .port_get_cmode = mv88e6185_port_get_cmode,
4360 .port_setup_message_port = mv88e6xxx_setup_message_port,
4361 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4362 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4363 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4364 .stats_get_strings = mv88e6095_stats_get_strings,
4365 .stats_get_stats = mv88e6095_stats_get_stats,
4366 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4367 .set_egress_port = mv88e6095_g1_set_egress_port,
4368 .watchdog_ops = &mv88e6097_watchdog_ops,
4369 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4370 .pot_clear = mv88e6xxx_g2_pot_clear,
4371 .reset = mv88e6352_g1_reset,
4372 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4373 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4374 .vtu_getnext = mv88e6352_g1_vtu_getnext,
4375 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4376 .stu_getnext = mv88e6352_g1_stu_getnext,
4377 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4378 .avb_ops = &mv88e6165_avb_ops,
4379 .ptp_ops = &mv88e6165_ptp_ops,
4380 .phylink_get_caps = mv88e6185_phylink_get_caps,
4381 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4382 };
4383
4384 static const struct mv88e6xxx_ops mv88e6165_ops = {
4385 /* MV88E6XXX_FAMILY_6165 */
4386 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4387 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4388 .irl_init_all = mv88e6352_g2_irl_init_all,
4389 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4390 .phy_read = mv88e6165_phy_read,
4391 .phy_write = mv88e6165_phy_write,
4392 .port_set_link = mv88e6xxx_port_set_link,
4393 .port_sync_link = mv88e6xxx_port_sync_link,
4394 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4395 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4396 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4397 .port_get_cmode = mv88e6185_port_get_cmode,
4398 .port_setup_message_port = mv88e6xxx_setup_message_port,
4399 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4400 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4401 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4402 .stats_get_strings = mv88e6095_stats_get_strings,
4403 .stats_get_stats = mv88e6095_stats_get_stats,
4404 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4405 .set_egress_port = mv88e6095_g1_set_egress_port,
4406 .watchdog_ops = &mv88e6097_watchdog_ops,
4407 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4408 .pot_clear = mv88e6xxx_g2_pot_clear,
4409 .reset = mv88e6352_g1_reset,
4410 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4411 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4412 .vtu_getnext = mv88e6352_g1_vtu_getnext,
4413 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4414 .stu_getnext = mv88e6352_g1_stu_getnext,
4415 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4416 .avb_ops = &mv88e6165_avb_ops,
4417 .ptp_ops = &mv88e6165_ptp_ops,
4418 .phylink_get_caps = mv88e6185_phylink_get_caps,
4419 };
4420
4421 static const struct mv88e6xxx_ops mv88e6171_ops = {
4422 /* MV88E6XXX_FAMILY_6351 */
4423 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4424 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4425 .irl_init_all = mv88e6352_g2_irl_init_all,
4426 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4427 .phy_read = mv88e6xxx_g2_smi_phy_read,
4428 .phy_write = mv88e6xxx_g2_smi_phy_write,
4429 .port_set_link = mv88e6xxx_port_set_link,
4430 .port_sync_link = mv88e6xxx_port_sync_link,
4431 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4432 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4433 .port_tag_remap = mv88e6095_port_tag_remap,
4434 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4435 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4436 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4437 .port_set_ether_type = mv88e6351_port_set_ether_type,
4438 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4439 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4440 .port_pause_limit = mv88e6097_port_pause_limit,
4441 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4442 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4443 .port_get_cmode = mv88e6352_port_get_cmode,
4444 .port_setup_message_port = mv88e6xxx_setup_message_port,
4445 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4446 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4447 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4448 .stats_get_strings = mv88e6095_stats_get_strings,
4449 .stats_get_stats = mv88e6095_stats_get_stats,
4450 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4451 .set_egress_port = mv88e6095_g1_set_egress_port,
4452 .watchdog_ops = &mv88e6097_watchdog_ops,
4453 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4454 .pot_clear = mv88e6xxx_g2_pot_clear,
4455 .reset = mv88e6352_g1_reset,
4456 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4457 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4458 .vtu_getnext = mv88e6352_g1_vtu_getnext,
4459 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4460 .stu_getnext = mv88e6352_g1_stu_getnext,
4461 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4462 .phylink_get_caps = mv88e6185_phylink_get_caps,
4463 };
4464
4465 static const struct mv88e6xxx_ops mv88e6172_ops = {
4466 /* MV88E6XXX_FAMILY_6352 */
4467 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4468 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4469 .irl_init_all = mv88e6352_g2_irl_init_all,
4470 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4471 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4472 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4473 .phy_read = mv88e6xxx_g2_smi_phy_read,
4474 .phy_write = mv88e6xxx_g2_smi_phy_write,
4475 .port_set_link = mv88e6xxx_port_set_link,
4476 .port_sync_link = mv88e6xxx_port_sync_link,
4477 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4478 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4479 .port_tag_remap = mv88e6095_port_tag_remap,
4480 .port_set_policy = mv88e6352_port_set_policy,
4481 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4482 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4483 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4484 .port_set_ether_type = mv88e6351_port_set_ether_type,
4485 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4486 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4487 .port_pause_limit = mv88e6097_port_pause_limit,
4488 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4489 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4490 .port_get_cmode = mv88e6352_port_get_cmode,
4491 .port_setup_message_port = mv88e6xxx_setup_message_port,
4492 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4493 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4494 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4495 .stats_get_strings = mv88e6095_stats_get_strings,
4496 .stats_get_stats = mv88e6095_stats_get_stats,
4497 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4498 .set_egress_port = mv88e6095_g1_set_egress_port,
4499 .watchdog_ops = &mv88e6097_watchdog_ops,
4500 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4501 .pot_clear = mv88e6xxx_g2_pot_clear,
4502 .reset = mv88e6352_g1_reset,
4503 .rmu_disable = mv88e6352_g1_rmu_disable,
4504 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4505 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4506 .vtu_getnext = mv88e6352_g1_vtu_getnext,
4507 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4508 .stu_getnext = mv88e6352_g1_stu_getnext,
4509 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4510 .serdes_get_lane = mv88e6352_serdes_get_lane,
4511 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4512 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4513 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4514 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
4515 .serdes_power = mv88e6352_serdes_power,
4516 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4517 .serdes_get_regs = mv88e6352_serdes_get_regs,
4518 .gpio_ops = &mv88e6352_gpio_ops,
4519 .phylink_get_caps = mv88e6352_phylink_get_caps,
4520 };
4521
4522 static const struct mv88e6xxx_ops mv88e6175_ops = {
4523 /* MV88E6XXX_FAMILY_6351 */
4524 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4525 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4526 .irl_init_all = mv88e6352_g2_irl_init_all,
4527 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4528 .phy_read = mv88e6xxx_g2_smi_phy_read,
4529 .phy_write = mv88e6xxx_g2_smi_phy_write,
4530 .port_set_link = mv88e6xxx_port_set_link,
4531 .port_sync_link = mv88e6xxx_port_sync_link,
4532 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4533 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4534 .port_tag_remap = mv88e6095_port_tag_remap,
4535 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4536 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4537 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4538 .port_set_ether_type = mv88e6351_port_set_ether_type,
4539 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4540 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4541 .port_pause_limit = mv88e6097_port_pause_limit,
4542 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4543 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4544 .port_get_cmode = mv88e6352_port_get_cmode,
4545 .port_setup_message_port = mv88e6xxx_setup_message_port,
4546 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4547 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4548 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4549 .stats_get_strings = mv88e6095_stats_get_strings,
4550 .stats_get_stats = mv88e6095_stats_get_stats,
4551 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4552 .set_egress_port = mv88e6095_g1_set_egress_port,
4553 .watchdog_ops = &mv88e6097_watchdog_ops,
4554 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4555 .pot_clear = mv88e6xxx_g2_pot_clear,
4556 .reset = mv88e6352_g1_reset,
4557 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4558 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4559 .vtu_getnext = mv88e6352_g1_vtu_getnext,
4560 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4561 .stu_getnext = mv88e6352_g1_stu_getnext,
4562 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4563 .phylink_get_caps = mv88e6185_phylink_get_caps,
4564 };
4565
4566 static const struct mv88e6xxx_ops mv88e6176_ops = {
4567 /* MV88E6XXX_FAMILY_6352 */
4568 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4569 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4570 .irl_init_all = mv88e6352_g2_irl_init_all,
4571 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4572 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4573 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4574 .phy_read = mv88e6xxx_g2_smi_phy_read,
4575 .phy_write = mv88e6xxx_g2_smi_phy_write,
4576 .port_set_link = mv88e6xxx_port_set_link,
4577 .port_sync_link = mv88e6xxx_port_sync_link,
4578 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4579 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4580 .port_tag_remap = mv88e6095_port_tag_remap,
4581 .port_set_policy = mv88e6352_port_set_policy,
4582 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4583 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4584 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4585 .port_set_ether_type = mv88e6351_port_set_ether_type,
4586 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4587 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4588 .port_pause_limit = mv88e6097_port_pause_limit,
4589 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4590 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4591 .port_get_cmode = mv88e6352_port_get_cmode,
4592 .port_setup_message_port = mv88e6xxx_setup_message_port,
4593 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4594 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4595 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4596 .stats_get_strings = mv88e6095_stats_get_strings,
4597 .stats_get_stats = mv88e6095_stats_get_stats,
4598 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4599 .set_egress_port = mv88e6095_g1_set_egress_port,
4600 .watchdog_ops = &mv88e6097_watchdog_ops,
4601 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4602 .pot_clear = mv88e6xxx_g2_pot_clear,
4603 .reset = mv88e6352_g1_reset,
4604 .rmu_disable = mv88e6352_g1_rmu_disable,
4605 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4606 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4607 .vtu_getnext = mv88e6352_g1_vtu_getnext,
4608 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4609 .stu_getnext = mv88e6352_g1_stu_getnext,
4610 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4611 .serdes_get_lane = mv88e6352_serdes_get_lane,
4612 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4613 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4614 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4615 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
4616 .serdes_power = mv88e6352_serdes_power,
4617 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4618 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
4619 .serdes_irq_status = mv88e6352_serdes_irq_status,
4620 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4621 .serdes_get_regs = mv88e6352_serdes_get_regs,
4622 .serdes_set_tx_amplitude = mv88e6352_serdes_set_tx_amplitude,
4623 .gpio_ops = &mv88e6352_gpio_ops,
4624 .phylink_get_caps = mv88e6352_phylink_get_caps,
4625 };
4626
4627 static const struct mv88e6xxx_ops mv88e6185_ops = {
4628 /* MV88E6XXX_FAMILY_6185 */
4629 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4630 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4631 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
4632 .phy_read = mv88e6185_phy_ppu_read,
4633 .phy_write = mv88e6185_phy_ppu_write,
4634 .port_set_link = mv88e6xxx_port_set_link,
4635 .port_sync_link = mv88e6185_port_sync_link,
4636 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
4637 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
4638 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
4639 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
4640 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
4641 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
4642 .port_set_pause = mv88e6185_port_set_pause,
4643 .port_get_cmode = mv88e6185_port_get_cmode,
4644 .port_setup_message_port = mv88e6xxx_setup_message_port,
4645 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
4646 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4647 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4648 .stats_get_strings = mv88e6095_stats_get_strings,
4649 .stats_get_stats = mv88e6095_stats_get_stats,
4650 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4651 .set_egress_port = mv88e6095_g1_set_egress_port,
4652 .watchdog_ops = &mv88e6097_watchdog_ops,
4653 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
4654 .serdes_power = mv88e6185_serdes_power,
4655 .serdes_get_lane = mv88e6185_serdes_get_lane,
4656 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
4657 .set_cascade_port = mv88e6185_g1_set_cascade_port,
4658 .ppu_enable = mv88e6185_g1_ppu_enable,
4659 .ppu_disable = mv88e6185_g1_ppu_disable,
4660 .reset = mv88e6185_g1_reset,
4661 .vtu_getnext = mv88e6185_g1_vtu_getnext,
4662 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4663 .phylink_get_caps = mv88e6185_phylink_get_caps,
4664 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
4665 };
4666
4667 static const struct mv88e6xxx_ops mv88e6190_ops = {
4668 /* MV88E6XXX_FAMILY_6390 */
4669 .setup_errata = mv88e6390_setup_errata,
4670 .irl_init_all = mv88e6390_g2_irl_init_all,
4671 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4672 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4673 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4674 .phy_read = mv88e6xxx_g2_smi_phy_read,
4675 .phy_write = mv88e6xxx_g2_smi_phy_write,
4676 .port_set_link = mv88e6xxx_port_set_link,
4677 .port_sync_link = mv88e6xxx_port_sync_link,
4678 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4679 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4680 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
4681 .port_tag_remap = mv88e6390_port_tag_remap,
4682 .port_set_policy = mv88e6352_port_set_policy,
4683 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4684 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4685 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4686 .port_set_ether_type = mv88e6351_port_set_ether_type,
4687 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4688 .port_pause_limit = mv88e6390_port_pause_limit,
4689 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4690 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4691 .port_get_cmode = mv88e6352_port_get_cmode,
4692 .port_set_cmode = mv88e6390_port_set_cmode,
4693 .port_setup_message_port = mv88e6xxx_setup_message_port,
4694 .stats_snapshot = mv88e6390_g1_stats_snapshot,
4695 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4696 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4697 .stats_get_strings = mv88e6320_stats_get_strings,
4698 .stats_get_stats = mv88e6390_stats_get_stats,
4699 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4700 .set_egress_port = mv88e6390_g1_set_egress_port,
4701 .watchdog_ops = &mv88e6390_watchdog_ops,
4702 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4703 .pot_clear = mv88e6xxx_g2_pot_clear,
4704 .reset = mv88e6352_g1_reset,
4705 .rmu_disable = mv88e6390_g1_rmu_disable,
4706 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4707 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4708 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4709 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4710 .stu_getnext = mv88e6390_g1_stu_getnext,
4711 .stu_loadpurge = mv88e6390_g1_stu_loadpurge,
4712 .serdes_power = mv88e6390_serdes_power,
4713 .serdes_get_lane = mv88e6390_serdes_get_lane,
4714 /* Check status register pause & lpa register */
4715 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4716 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4717 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4718 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4719 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4720 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
4721 .serdes_irq_status = mv88e6390_serdes_irq_status,
4722 .serdes_get_strings = mv88e6390_serdes_get_strings,
4723 .serdes_get_stats = mv88e6390_serdes_get_stats,
4724 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4725 .serdes_get_regs = mv88e6390_serdes_get_regs,
4726 .gpio_ops = &mv88e6352_gpio_ops,
4727 .phylink_get_caps = mv88e6390_phylink_get_caps,
4728 };
4729
4730 static const struct mv88e6xxx_ops mv88e6190x_ops = {
4731 /* MV88E6XXX_FAMILY_6390 */
4732 .setup_errata = mv88e6390_setup_errata,
4733 .irl_init_all = mv88e6390_g2_irl_init_all,
4734 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4735 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4736 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4737 .phy_read = mv88e6xxx_g2_smi_phy_read,
4738 .phy_write = mv88e6xxx_g2_smi_phy_write,
4739 .port_set_link = mv88e6xxx_port_set_link,
4740 .port_sync_link = mv88e6xxx_port_sync_link,
4741 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4742 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
4743 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
4744 .port_tag_remap = mv88e6390_port_tag_remap,
4745 .port_set_policy = mv88e6352_port_set_policy,
4746 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4747 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4748 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4749 .port_set_ether_type = mv88e6351_port_set_ether_type,
4750 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4751 .port_pause_limit = mv88e6390_port_pause_limit,
4752 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4753 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4754 .port_get_cmode = mv88e6352_port_get_cmode,
4755 .port_set_cmode = mv88e6390x_port_set_cmode,
4756 .port_setup_message_port = mv88e6xxx_setup_message_port,
4757 .stats_snapshot = mv88e6390_g1_stats_snapshot,
4758 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4759 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4760 .stats_get_strings = mv88e6320_stats_get_strings,
4761 .stats_get_stats = mv88e6390_stats_get_stats,
4762 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4763 .set_egress_port = mv88e6390_g1_set_egress_port,
4764 .watchdog_ops = &mv88e6390_watchdog_ops,
4765 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4766 .pot_clear = mv88e6xxx_g2_pot_clear,
4767 .reset = mv88e6352_g1_reset,
4768 .rmu_disable = mv88e6390_g1_rmu_disable,
4769 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4770 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4771 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4772 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4773 .stu_getnext = mv88e6390_g1_stu_getnext,
4774 .stu_loadpurge = mv88e6390_g1_stu_loadpurge,
4775 .serdes_power = mv88e6390_serdes_power,
4776 .serdes_get_lane = mv88e6390x_serdes_get_lane,
4777 /* Check status register pause & lpa register */
4778 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4779 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4780 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4781 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4782 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4783 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
4784 .serdes_irq_status = mv88e6390_serdes_irq_status,
4785 .serdes_get_strings = mv88e6390_serdes_get_strings,
4786 .serdes_get_stats = mv88e6390_serdes_get_stats,
4787 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4788 .serdes_get_regs = mv88e6390_serdes_get_regs,
4789 .gpio_ops = &mv88e6352_gpio_ops,
4790 .phylink_get_caps = mv88e6390x_phylink_get_caps,
4791 };
4792
4793 static const struct mv88e6xxx_ops mv88e6191_ops = {
4794 /* MV88E6XXX_FAMILY_6390 */
4795 .setup_errata = mv88e6390_setup_errata,
4796 .irl_init_all = mv88e6390_g2_irl_init_all,
4797 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4798 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4799 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4800 .phy_read = mv88e6xxx_g2_smi_phy_read,
4801 .phy_write = mv88e6xxx_g2_smi_phy_write,
4802 .port_set_link = mv88e6xxx_port_set_link,
4803 .port_sync_link = mv88e6xxx_port_sync_link,
4804 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4805 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4806 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
4807 .port_tag_remap = mv88e6390_port_tag_remap,
4808 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4809 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4810 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4811 .port_set_ether_type = mv88e6351_port_set_ether_type,
4812 .port_pause_limit = mv88e6390_port_pause_limit,
4813 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4814 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4815 .port_get_cmode = mv88e6352_port_get_cmode,
4816 .port_set_cmode = mv88e6390_port_set_cmode,
4817 .port_setup_message_port = mv88e6xxx_setup_message_port,
4818 .stats_snapshot = mv88e6390_g1_stats_snapshot,
4819 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4820 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4821 .stats_get_strings = mv88e6320_stats_get_strings,
4822 .stats_get_stats = mv88e6390_stats_get_stats,
4823 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4824 .set_egress_port = mv88e6390_g1_set_egress_port,
4825 .watchdog_ops = &mv88e6390_watchdog_ops,
4826 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4827 .pot_clear = mv88e6xxx_g2_pot_clear,
4828 .reset = mv88e6352_g1_reset,
4829 .rmu_disable = mv88e6390_g1_rmu_disable,
4830 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4831 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4832 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4833 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4834 .stu_getnext = mv88e6390_g1_stu_getnext,
4835 .stu_loadpurge = mv88e6390_g1_stu_loadpurge,
4836 .serdes_power = mv88e6390_serdes_power,
4837 .serdes_get_lane = mv88e6390_serdes_get_lane,
4838 /* Check status register pause & lpa register */
4839 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4840 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4841 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4842 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4843 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4844 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
4845 .serdes_irq_status = mv88e6390_serdes_irq_status,
4846 .serdes_get_strings = mv88e6390_serdes_get_strings,
4847 .serdes_get_stats = mv88e6390_serdes_get_stats,
4848 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4849 .serdes_get_regs = mv88e6390_serdes_get_regs,
4850 .avb_ops = &mv88e6390_avb_ops,
4851 .ptp_ops = &mv88e6352_ptp_ops,
4852 .phylink_get_caps = mv88e6390_phylink_get_caps,
4853 };
4854
4855 static const struct mv88e6xxx_ops mv88e6240_ops = {
4856 /* MV88E6XXX_FAMILY_6352 */
4857 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4858 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4859 .irl_init_all = mv88e6352_g2_irl_init_all,
4860 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4861 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4862 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4863 .phy_read = mv88e6xxx_g2_smi_phy_read,
4864 .phy_write = mv88e6xxx_g2_smi_phy_write,
4865 .port_set_link = mv88e6xxx_port_set_link,
4866 .port_sync_link = mv88e6xxx_port_sync_link,
4867 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4868 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
4869 .port_tag_remap = mv88e6095_port_tag_remap,
4870 .port_set_policy = mv88e6352_port_set_policy,
4871 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4872 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4873 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4874 .port_set_ether_type = mv88e6351_port_set_ether_type,
4875 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4876 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4877 .port_pause_limit = mv88e6097_port_pause_limit,
4878 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4879 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4880 .port_get_cmode = mv88e6352_port_get_cmode,
4881 .port_setup_message_port = mv88e6xxx_setup_message_port,
4882 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4883 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4884 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4885 .stats_get_strings = mv88e6095_stats_get_strings,
4886 .stats_get_stats = mv88e6095_stats_get_stats,
4887 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4888 .set_egress_port = mv88e6095_g1_set_egress_port,
4889 .watchdog_ops = &mv88e6097_watchdog_ops,
4890 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4891 .pot_clear = mv88e6xxx_g2_pot_clear,
4892 .reset = mv88e6352_g1_reset,
4893 .rmu_disable = mv88e6352_g1_rmu_disable,
4894 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4895 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4896 .vtu_getnext = mv88e6352_g1_vtu_getnext,
4897 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
4898 .stu_getnext = mv88e6352_g1_stu_getnext,
4899 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
4900 .serdes_get_lane = mv88e6352_serdes_get_lane,
4901 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4902 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4903 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4904 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
4905 .serdes_power = mv88e6352_serdes_power,
4906 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
4907 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
4908 .serdes_irq_status = mv88e6352_serdes_irq_status,
4909 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4910 .serdes_get_regs = mv88e6352_serdes_get_regs,
4911 .serdes_set_tx_amplitude = mv88e6352_serdes_set_tx_amplitude,
4912 .gpio_ops = &mv88e6352_gpio_ops,
4913 .avb_ops = &mv88e6352_avb_ops,
4914 .ptp_ops = &mv88e6352_ptp_ops,
4915 .phylink_get_caps = mv88e6352_phylink_get_caps,
4916 };
4917
4918 static const struct mv88e6xxx_ops mv88e6250_ops = {
4919 /* MV88E6XXX_FAMILY_6250 */
4920 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4921 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4922 .irl_init_all = mv88e6352_g2_irl_init_all,
4923 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4924 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4925 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4926 .phy_read = mv88e6xxx_g2_smi_phy_read,
4927 .phy_write = mv88e6xxx_g2_smi_phy_write,
4928 .port_set_link = mv88e6xxx_port_set_link,
4929 .port_sync_link = mv88e6xxx_port_sync_link,
4930 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4931 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
4932 .port_tag_remap = mv88e6095_port_tag_remap,
4933 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4934 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4935 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4936 .port_set_ether_type = mv88e6351_port_set_ether_type,
4937 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4938 .port_pause_limit = mv88e6097_port_pause_limit,
4939 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4940 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4941 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4942 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4943 .stats_get_strings = mv88e6250_stats_get_strings,
4944 .stats_get_stats = mv88e6250_stats_get_stats,
4945 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4946 .set_egress_port = mv88e6095_g1_set_egress_port,
4947 .watchdog_ops = &mv88e6250_watchdog_ops,
4948 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4949 .pot_clear = mv88e6xxx_g2_pot_clear,
4950 .reset = mv88e6250_g1_reset,
4951 .vtu_getnext = mv88e6185_g1_vtu_getnext,
4952 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
4953 .avb_ops = &mv88e6352_avb_ops,
4954 .ptp_ops = &mv88e6250_ptp_ops,
4955 .phylink_get_caps = mv88e6250_phylink_get_caps,
4956 };
4957
4958 static const struct mv88e6xxx_ops mv88e6290_ops = {
4959 /* MV88E6XXX_FAMILY_6390 */
4960 .setup_errata = mv88e6390_setup_errata,
4961 .irl_init_all = mv88e6390_g2_irl_init_all,
4962 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4963 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4964 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4965 .phy_read = mv88e6xxx_g2_smi_phy_read,
4966 .phy_write = mv88e6xxx_g2_smi_phy_write,
4967 .port_set_link = mv88e6xxx_port_set_link,
4968 .port_sync_link = mv88e6xxx_port_sync_link,
4969 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4970 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
4971 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
4972 .port_tag_remap = mv88e6390_port_tag_remap,
4973 .port_set_policy = mv88e6352_port_set_policy,
4974 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4975 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4976 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4977 .port_set_ether_type = mv88e6351_port_set_ether_type,
4978 .port_pause_limit = mv88e6390_port_pause_limit,
4979 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4980 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4981 .port_get_cmode = mv88e6352_port_get_cmode,
4982 .port_set_cmode = mv88e6390_port_set_cmode,
4983 .port_setup_message_port = mv88e6xxx_setup_message_port,
4984 .stats_snapshot = mv88e6390_g1_stats_snapshot,
4985 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4986 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4987 .stats_get_strings = mv88e6320_stats_get_strings,
4988 .stats_get_stats = mv88e6390_stats_get_stats,
4989 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4990 .set_egress_port = mv88e6390_g1_set_egress_port,
4991 .watchdog_ops = &mv88e6390_watchdog_ops,
4992 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
4993 .pot_clear = mv88e6xxx_g2_pot_clear,
4994 .reset = mv88e6352_g1_reset,
4995 .rmu_disable = mv88e6390_g1_rmu_disable,
4996 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4997 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4998 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4999 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
5000 .stu_getnext = mv88e6390_g1_stu_getnext,
5001 .stu_loadpurge = mv88e6390_g1_stu_loadpurge,
5002 .serdes_power = mv88e6390_serdes_power,
5003 .serdes_get_lane = mv88e6390_serdes_get_lane,
5004 /* Check status register pause & lpa register */
5005 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
5006 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
5007 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
5008 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
5009 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
5010 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
5011 .serdes_irq_status = mv88e6390_serdes_irq_status,
5012 .serdes_get_strings = mv88e6390_serdes_get_strings,
5013 .serdes_get_stats = mv88e6390_serdes_get_stats,
5014 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
5015 .serdes_get_regs = mv88e6390_serdes_get_regs,
5016 .gpio_ops = &mv88e6352_gpio_ops,
5017 .avb_ops = &mv88e6390_avb_ops,
5018 .ptp_ops = &mv88e6352_ptp_ops,
5019 .phylink_get_caps = mv88e6390_phylink_get_caps,
5020 };
5021
5022 static const struct mv88e6xxx_ops mv88e6320_ops = {
5023 /* MV88E6XXX_FAMILY_6320 */
5024 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
5025 .ip_pri_map = mv88e6085_g1_ip_pri_map,
5026 .irl_init_all = mv88e6352_g2_irl_init_all,
5027 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
5028 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
5029 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5030 .phy_read = mv88e6xxx_g2_smi_phy_read,
5031 .phy_write = mv88e6xxx_g2_smi_phy_write,
5032 .port_set_link = mv88e6xxx_port_set_link,
5033 .port_sync_link = mv88e6xxx_port_sync_link,
5034 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
5035 .port_tag_remap = mv88e6095_port_tag_remap,
5036 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
5037 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5038 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5039 .port_set_ether_type = mv88e6351_port_set_ether_type,
5040 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5041 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5042 .port_pause_limit = mv88e6097_port_pause_limit,
5043 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5044 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5045 .port_get_cmode = mv88e6352_port_get_cmode,
5046 .port_setup_message_port = mv88e6xxx_setup_message_port,
5047 .stats_snapshot = mv88e6320_g1_stats_snapshot,
5048 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
5049 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
5050 .stats_get_strings = mv88e6320_stats_get_strings,
5051 .stats_get_stats = mv88e6320_stats_get_stats,
5052 .set_cpu_port = mv88e6095_g1_set_cpu_port,
5053 .set_egress_port = mv88e6095_g1_set_egress_port,
5054 .watchdog_ops = &mv88e6390_watchdog_ops,
5055 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
5056 .pot_clear = mv88e6xxx_g2_pot_clear,
5057 .reset = mv88e6352_g1_reset,
5058 .vtu_getnext = mv88e6185_g1_vtu_getnext,
5059 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
5060 .gpio_ops = &mv88e6352_gpio_ops,
5061 .avb_ops = &mv88e6352_avb_ops,
5062 .ptp_ops = &mv88e6352_ptp_ops,
5063 .phylink_get_caps = mv88e6185_phylink_get_caps,
5064 };
5065
5066 static const struct mv88e6xxx_ops mv88e6321_ops = {
5067 /* MV88E6XXX_FAMILY_6320 */
5068 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
5069 .ip_pri_map = mv88e6085_g1_ip_pri_map,
5070 .irl_init_all = mv88e6352_g2_irl_init_all,
5071 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
5072 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
5073 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5074 .phy_read = mv88e6xxx_g2_smi_phy_read,
5075 .phy_write = mv88e6xxx_g2_smi_phy_write,
5076 .port_set_link = mv88e6xxx_port_set_link,
5077 .port_sync_link = mv88e6xxx_port_sync_link,
5078 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
5079 .port_tag_remap = mv88e6095_port_tag_remap,
5080 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
5081 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5082 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5083 .port_set_ether_type = mv88e6351_port_set_ether_type,
5084 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5085 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5086 .port_pause_limit = mv88e6097_port_pause_limit,
5087 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5088 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5089 .port_get_cmode = mv88e6352_port_get_cmode,
5090 .port_setup_message_port = mv88e6xxx_setup_message_port,
5091 .stats_snapshot = mv88e6320_g1_stats_snapshot,
5092 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
5093 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
5094 .stats_get_strings = mv88e6320_stats_get_strings,
5095 .stats_get_stats = mv88e6320_stats_get_stats,
5096 .set_cpu_port = mv88e6095_g1_set_cpu_port,
5097 .set_egress_port = mv88e6095_g1_set_egress_port,
5098 .watchdog_ops = &mv88e6390_watchdog_ops,
5099 .reset = mv88e6352_g1_reset,
5100 .vtu_getnext = mv88e6185_g1_vtu_getnext,
5101 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
5102 .gpio_ops = &mv88e6352_gpio_ops,
5103 .avb_ops = &mv88e6352_avb_ops,
5104 .ptp_ops = &mv88e6352_ptp_ops,
5105 .phylink_get_caps = mv88e6185_phylink_get_caps,
5106 };
5107
5108 static const struct mv88e6xxx_ops mv88e6341_ops = {
5109 /* MV88E6XXX_FAMILY_6341 */
5110 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
5111 .ip_pri_map = mv88e6085_g1_ip_pri_map,
5112 .irl_init_all = mv88e6352_g2_irl_init_all,
5113 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
5114 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
5115 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5116 .phy_read = mv88e6xxx_g2_smi_phy_read,
5117 .phy_write = mv88e6xxx_g2_smi_phy_write,
5118 .port_set_link = mv88e6xxx_port_set_link,
5119 .port_sync_link = mv88e6xxx_port_sync_link,
5120 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
5121 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
5122 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
5123 .port_tag_remap = mv88e6095_port_tag_remap,
5124 .port_set_policy = mv88e6352_port_set_policy,
5125 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
5126 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5127 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5128 .port_set_ether_type = mv88e6351_port_set_ether_type,
5129 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5130 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5131 .port_pause_limit = mv88e6097_port_pause_limit,
5132 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5133 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5134 .port_get_cmode = mv88e6352_port_get_cmode,
5135 .port_set_cmode = mv88e6341_port_set_cmode,
5136 .port_setup_message_port = mv88e6xxx_setup_message_port,
5137 .stats_snapshot = mv88e6390_g1_stats_snapshot,
5138 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
5139 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
5140 .stats_get_strings = mv88e6320_stats_get_strings,
5141 .stats_get_stats = mv88e6390_stats_get_stats,
5142 .set_cpu_port = mv88e6390_g1_set_cpu_port,
5143 .set_egress_port = mv88e6390_g1_set_egress_port,
5144 .watchdog_ops = &mv88e6390_watchdog_ops,
5145 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
5146 .pot_clear = mv88e6xxx_g2_pot_clear,
5147 .reset = mv88e6352_g1_reset,
5148 .rmu_disable = mv88e6390_g1_rmu_disable,
5149 .atu_get_hash = mv88e6165_g1_atu_get_hash,
5150 .atu_set_hash = mv88e6165_g1_atu_set_hash,
5151 .vtu_getnext = mv88e6352_g1_vtu_getnext,
5152 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
5153 .stu_getnext = mv88e6352_g1_stu_getnext,
5154 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
5155 .serdes_power = mv88e6390_serdes_power,
5156 .serdes_get_lane = mv88e6341_serdes_get_lane,
5157 /* Check status register pause & lpa register */
5158 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
5159 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
5160 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
5161 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
5162 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
5163 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
5164 .serdes_irq_status = mv88e6390_serdes_irq_status,
5165 .gpio_ops = &mv88e6352_gpio_ops,
5166 .avb_ops = &mv88e6390_avb_ops,
5167 .ptp_ops = &mv88e6352_ptp_ops,
5168 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
5169 .serdes_get_strings = mv88e6390_serdes_get_strings,
5170 .serdes_get_stats = mv88e6390_serdes_get_stats,
5171 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
5172 .serdes_get_regs = mv88e6390_serdes_get_regs,
5173 .phylink_get_caps = mv88e6341_phylink_get_caps,
5174 };
5175
5176 static const struct mv88e6xxx_ops mv88e6350_ops = {
5177 /* MV88E6XXX_FAMILY_6351 */
5178 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
5179 .ip_pri_map = mv88e6085_g1_ip_pri_map,
5180 .irl_init_all = mv88e6352_g2_irl_init_all,
5181 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5182 .phy_read = mv88e6xxx_g2_smi_phy_read,
5183 .phy_write = mv88e6xxx_g2_smi_phy_write,
5184 .port_set_link = mv88e6xxx_port_set_link,
5185 .port_sync_link = mv88e6xxx_port_sync_link,
5186 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
5187 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
5188 .port_tag_remap = mv88e6095_port_tag_remap,
5189 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
5190 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5191 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5192 .port_set_ether_type = mv88e6351_port_set_ether_type,
5193 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5194 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5195 .port_pause_limit = mv88e6097_port_pause_limit,
5196 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5197 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5198 .port_get_cmode = mv88e6352_port_get_cmode,
5199 .port_setup_message_port = mv88e6xxx_setup_message_port,
5200 .stats_snapshot = mv88e6320_g1_stats_snapshot,
5201 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
5202 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
5203 .stats_get_strings = mv88e6095_stats_get_strings,
5204 .stats_get_stats = mv88e6095_stats_get_stats,
5205 .set_cpu_port = mv88e6095_g1_set_cpu_port,
5206 .set_egress_port = mv88e6095_g1_set_egress_port,
5207 .watchdog_ops = &mv88e6097_watchdog_ops,
5208 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
5209 .pot_clear = mv88e6xxx_g2_pot_clear,
5210 .reset = mv88e6352_g1_reset,
5211 .atu_get_hash = mv88e6165_g1_atu_get_hash,
5212 .atu_set_hash = mv88e6165_g1_atu_set_hash,
5213 .vtu_getnext = mv88e6352_g1_vtu_getnext,
5214 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
5215 .stu_getnext = mv88e6352_g1_stu_getnext,
5216 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
5217 .phylink_get_caps = mv88e6185_phylink_get_caps,
5218 };
5219
5220 static const struct mv88e6xxx_ops mv88e6351_ops = {
5221 /* MV88E6XXX_FAMILY_6351 */
5222 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
5223 .ip_pri_map = mv88e6085_g1_ip_pri_map,
5224 .irl_init_all = mv88e6352_g2_irl_init_all,
5225 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5226 .phy_read = mv88e6xxx_g2_smi_phy_read,
5227 .phy_write = mv88e6xxx_g2_smi_phy_write,
5228 .port_set_link = mv88e6xxx_port_set_link,
5229 .port_sync_link = mv88e6xxx_port_sync_link,
5230 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
5231 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
5232 .port_tag_remap = mv88e6095_port_tag_remap,
5233 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
5234 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5235 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5236 .port_set_ether_type = mv88e6351_port_set_ether_type,
5237 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5238 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5239 .port_pause_limit = mv88e6097_port_pause_limit,
5240 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5241 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5242 .port_get_cmode = mv88e6352_port_get_cmode,
5243 .port_setup_message_port = mv88e6xxx_setup_message_port,
5244 .stats_snapshot = mv88e6320_g1_stats_snapshot,
5245 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
5246 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
5247 .stats_get_strings = mv88e6095_stats_get_strings,
5248 .stats_get_stats = mv88e6095_stats_get_stats,
5249 .set_cpu_port = mv88e6095_g1_set_cpu_port,
5250 .set_egress_port = mv88e6095_g1_set_egress_port,
5251 .watchdog_ops = &mv88e6097_watchdog_ops,
5252 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
5253 .pot_clear = mv88e6xxx_g2_pot_clear,
5254 .reset = mv88e6352_g1_reset,
5255 .atu_get_hash = mv88e6165_g1_atu_get_hash,
5256 .atu_set_hash = mv88e6165_g1_atu_set_hash,
5257 .vtu_getnext = mv88e6352_g1_vtu_getnext,
5258 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
5259 .stu_getnext = mv88e6352_g1_stu_getnext,
5260 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
5261 .avb_ops = &mv88e6352_avb_ops,
5262 .ptp_ops = &mv88e6352_ptp_ops,
5263 .phylink_get_caps = mv88e6185_phylink_get_caps,
5264 };
5265
5266 static const struct mv88e6xxx_ops mv88e6352_ops = {
5267 /* MV88E6XXX_FAMILY_6352 */
5268 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
5269 .ip_pri_map = mv88e6085_g1_ip_pri_map,
5270 .irl_init_all = mv88e6352_g2_irl_init_all,
5271 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
5272 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
5273 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5274 .phy_read = mv88e6xxx_g2_smi_phy_read,
5275 .phy_write = mv88e6xxx_g2_smi_phy_write,
5276 .port_set_link = mv88e6xxx_port_set_link,
5277 .port_sync_link = mv88e6xxx_port_sync_link,
5278 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
5279 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
5280 .port_tag_remap = mv88e6095_port_tag_remap,
5281 .port_set_policy = mv88e6352_port_set_policy,
5282 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
5283 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5284 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5285 .port_set_ether_type = mv88e6351_port_set_ether_type,
5286 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5287 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5288 .port_pause_limit = mv88e6097_port_pause_limit,
5289 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5290 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5291 .port_get_cmode = mv88e6352_port_get_cmode,
5292 .port_setup_message_port = mv88e6xxx_setup_message_port,
5293 .stats_snapshot = mv88e6320_g1_stats_snapshot,
5294 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
5295 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
5296 .stats_get_strings = mv88e6095_stats_get_strings,
5297 .stats_get_stats = mv88e6095_stats_get_stats,
5298 .set_cpu_port = mv88e6095_g1_set_cpu_port,
5299 .set_egress_port = mv88e6095_g1_set_egress_port,
5300 .watchdog_ops = &mv88e6097_watchdog_ops,
5301 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
5302 .pot_clear = mv88e6xxx_g2_pot_clear,
5303 .reset = mv88e6352_g1_reset,
5304 .rmu_disable = mv88e6352_g1_rmu_disable,
5305 .atu_get_hash = mv88e6165_g1_atu_get_hash,
5306 .atu_set_hash = mv88e6165_g1_atu_set_hash,
5307 .vtu_getnext = mv88e6352_g1_vtu_getnext,
5308 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
5309 .stu_getnext = mv88e6352_g1_stu_getnext,
5310 .stu_loadpurge = mv88e6352_g1_stu_loadpurge,
5311 .serdes_get_lane = mv88e6352_serdes_get_lane,
5312 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
5313 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
5314 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
5315 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
5316 .serdes_power = mv88e6352_serdes_power,
5317 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
5318 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
5319 .serdes_irq_status = mv88e6352_serdes_irq_status,
5320 .gpio_ops = &mv88e6352_gpio_ops,
5321 .avb_ops = &mv88e6352_avb_ops,
5322 .ptp_ops = &mv88e6352_ptp_ops,
5323 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
5324 .serdes_get_strings = mv88e6352_serdes_get_strings,
5325 .serdes_get_stats = mv88e6352_serdes_get_stats,
5326 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
5327 .serdes_get_regs = mv88e6352_serdes_get_regs,
5328 .serdes_set_tx_amplitude = mv88e6352_serdes_set_tx_amplitude,
5329 .phylink_get_caps = mv88e6352_phylink_get_caps,
5330 };
5331
5332 static const struct mv88e6xxx_ops mv88e6390_ops = {
5333 /* MV88E6XXX_FAMILY_6390 */
5334 .setup_errata = mv88e6390_setup_errata,
5335 .irl_init_all = mv88e6390_g2_irl_init_all,
5336 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
5337 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
5338 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5339 .phy_read = mv88e6xxx_g2_smi_phy_read,
5340 .phy_write = mv88e6xxx_g2_smi_phy_write,
5341 .port_set_link = mv88e6xxx_port_set_link,
5342 .port_sync_link = mv88e6xxx_port_sync_link,
5343 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
5344 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
5345 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
5346 .port_tag_remap = mv88e6390_port_tag_remap,
5347 .port_set_policy = mv88e6352_port_set_policy,
5348 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
5349 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5350 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5351 .port_set_ether_type = mv88e6351_port_set_ether_type,
5352 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5353 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5354 .port_pause_limit = mv88e6390_port_pause_limit,
5355 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5356 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5357 .port_get_cmode = mv88e6352_port_get_cmode,
5358 .port_set_cmode = mv88e6390_port_set_cmode,
5359 .port_setup_message_port = mv88e6xxx_setup_message_port,
5360 .stats_snapshot = mv88e6390_g1_stats_snapshot,
5361 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
5362 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
5363 .stats_get_strings = mv88e6320_stats_get_strings,
5364 .stats_get_stats = mv88e6390_stats_get_stats,
5365 .set_cpu_port = mv88e6390_g1_set_cpu_port,
5366 .set_egress_port = mv88e6390_g1_set_egress_port,
5367 .watchdog_ops = &mv88e6390_watchdog_ops,
5368 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
5369 .pot_clear = mv88e6xxx_g2_pot_clear,
5370 .reset = mv88e6352_g1_reset,
5371 .rmu_disable = mv88e6390_g1_rmu_disable,
5372 .atu_get_hash = mv88e6165_g1_atu_get_hash,
5373 .atu_set_hash = mv88e6165_g1_atu_set_hash,
5374 .vtu_getnext = mv88e6390_g1_vtu_getnext,
5375 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
5376 .stu_getnext = mv88e6390_g1_stu_getnext,
5377 .stu_loadpurge = mv88e6390_g1_stu_loadpurge,
5378 .serdes_power = mv88e6390_serdes_power,
5379 .serdes_get_lane = mv88e6390_serdes_get_lane,
5380 /* Check status register pause & lpa register */
5381 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
5382 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
5383 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
5384 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
5385 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
5386 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
5387 .serdes_irq_status = mv88e6390_serdes_irq_status,
5388 .gpio_ops = &mv88e6352_gpio_ops,
5389 .avb_ops = &mv88e6390_avb_ops,
5390 .ptp_ops = &mv88e6352_ptp_ops,
5391 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
5392 .serdes_get_strings = mv88e6390_serdes_get_strings,
5393 .serdes_get_stats = mv88e6390_serdes_get_stats,
5394 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
5395 .serdes_get_regs = mv88e6390_serdes_get_regs,
5396 .phylink_get_caps = mv88e6390_phylink_get_caps,
5397 };
5398
5399 static const struct mv88e6xxx_ops mv88e6390x_ops = {
5400 /* MV88E6XXX_FAMILY_6390 */
5401 .setup_errata = mv88e6390_setup_errata,
5402 .irl_init_all = mv88e6390_g2_irl_init_all,
5403 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
5404 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
5405 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5406 .phy_read = mv88e6xxx_g2_smi_phy_read,
5407 .phy_write = mv88e6xxx_g2_smi_phy_write,
5408 .port_set_link = mv88e6xxx_port_set_link,
5409 .port_sync_link = mv88e6xxx_port_sync_link,
5410 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
5411 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
5412 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
5413 .port_tag_remap = mv88e6390_port_tag_remap,
5414 .port_set_policy = mv88e6352_port_set_policy,
5415 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
5416 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5417 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5418 .port_set_ether_type = mv88e6351_port_set_ether_type,
5419 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5420 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5421 .port_pause_limit = mv88e6390_port_pause_limit,
5422 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5423 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5424 .port_get_cmode = mv88e6352_port_get_cmode,
5425 .port_set_cmode = mv88e6390x_port_set_cmode,
5426 .port_setup_message_port = mv88e6xxx_setup_message_port,
5427 .stats_snapshot = mv88e6390_g1_stats_snapshot,
5428 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
5429 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
5430 .stats_get_strings = mv88e6320_stats_get_strings,
5431 .stats_get_stats = mv88e6390_stats_get_stats,
5432 .set_cpu_port = mv88e6390_g1_set_cpu_port,
5433 .set_egress_port = mv88e6390_g1_set_egress_port,
5434 .watchdog_ops = &mv88e6390_watchdog_ops,
5435 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
5436 .pot_clear = mv88e6xxx_g2_pot_clear,
5437 .reset = mv88e6352_g1_reset,
5438 .rmu_disable = mv88e6390_g1_rmu_disable,
5439 .atu_get_hash = mv88e6165_g1_atu_get_hash,
5440 .atu_set_hash = mv88e6165_g1_atu_set_hash,
5441 .vtu_getnext = mv88e6390_g1_vtu_getnext,
5442 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
5443 .stu_getnext = mv88e6390_g1_stu_getnext,
5444 .stu_loadpurge = mv88e6390_g1_stu_loadpurge,
5445 .serdes_power = mv88e6390_serdes_power,
5446 .serdes_get_lane = mv88e6390x_serdes_get_lane,
5447 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
5448 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
5449 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
5450 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
5451 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
5452 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
5453 .serdes_irq_status = mv88e6390_serdes_irq_status,
5454 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
5455 .serdes_get_strings = mv88e6390_serdes_get_strings,
5456 .serdes_get_stats = mv88e6390_serdes_get_stats,
5457 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
5458 .serdes_get_regs = mv88e6390_serdes_get_regs,
5459 .gpio_ops = &mv88e6352_gpio_ops,
5460 .avb_ops = &mv88e6390_avb_ops,
5461 .ptp_ops = &mv88e6352_ptp_ops,
5462 .phylink_get_caps = mv88e6390x_phylink_get_caps,
5463 };
5464
5465 static const struct mv88e6xxx_ops mv88e6393x_ops = {
5466 /* MV88E6XXX_FAMILY_6393 */
5467 .setup_errata = mv88e6393x_serdes_setup_errata,
5468 .irl_init_all = mv88e6390_g2_irl_init_all,
5469 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
5470 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
5471 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
5472 .phy_read = mv88e6xxx_g2_smi_phy_read,
5473 .phy_write = mv88e6xxx_g2_smi_phy_write,
5474 .port_set_link = mv88e6xxx_port_set_link,
5475 .port_sync_link = mv88e6xxx_port_sync_link,
5476 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
5477 .port_set_speed_duplex = mv88e6393x_port_set_speed_duplex,
5478 .port_max_speed_mode = mv88e6393x_port_max_speed_mode,
5479 .port_tag_remap = mv88e6390_port_tag_remap,
5480 .port_set_policy = mv88e6393x_port_set_policy,
5481 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
5482 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
5483 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
5484 .port_set_ether_type = mv88e6393x_port_set_ether_type,
5485 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
5486 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
5487 .port_pause_limit = mv88e6390_port_pause_limit,
5488 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
5489 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
5490 .port_get_cmode = mv88e6352_port_get_cmode,
5491 .port_set_cmode = mv88e6393x_port_set_cmode,
5492 .port_setup_message_port = mv88e6xxx_setup_message_port,
5493 .port_set_upstream_port = mv88e6393x_port_set_upstream_port,
5494 .stats_snapshot = mv88e6390_g1_stats_snapshot,
5495 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
5496 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
5497 .stats_get_strings = mv88e6320_stats_get_strings,
5498 .stats_get_stats = mv88e6390_stats_get_stats,
5499 /* .set_cpu_port is missing because this family does not support a global
5500 * CPU port, only per port CPU port which is set via
5501 * .port_set_upstream_port method.
5502 */
5503 .set_egress_port = mv88e6393x_set_egress_port,
5504 .watchdog_ops = &mv88e6390_watchdog_ops,
5505 .mgmt_rsvd2cpu = mv88e6393x_port_mgmt_rsvd2cpu,
5506 .pot_clear = mv88e6xxx_g2_pot_clear,
5507 .reset = mv88e6352_g1_reset,
5508 .rmu_disable = mv88e6390_g1_rmu_disable,
5509 .atu_get_hash = mv88e6165_g1_atu_get_hash,
5510 .atu_set_hash = mv88e6165_g1_atu_set_hash,
5511 .vtu_getnext = mv88e6390_g1_vtu_getnext,
5512 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
5513 .stu_getnext = mv88e6390_g1_stu_getnext,
5514 .stu_loadpurge = mv88e6390_g1_stu_loadpurge,
5515 .serdes_power = mv88e6393x_serdes_power,
5516 .serdes_get_lane = mv88e6393x_serdes_get_lane,
5517 .serdes_pcs_get_state = mv88e6393x_serdes_pcs_get_state,
5518 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
5519 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
5520 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
5521 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
5522 .serdes_irq_enable = mv88e6393x_serdes_irq_enable,
5523 .serdes_irq_status = mv88e6393x_serdes_irq_status,
5524 /* TODO: serdes stats */
5525 .gpio_ops = &mv88e6352_gpio_ops,
5526 .avb_ops = &mv88e6390_avb_ops,
5527 .ptp_ops = &mv88e6352_ptp_ops,
5528 .phylink_get_caps = mv88e6393x_phylink_get_caps,
5529 };
5530
5531 static const struct mv88e6xxx_info mv88e6xxx_table[] = {
5532 [MV88E6085] = {
5533 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
5534 .family = MV88E6XXX_FAMILY_6097,
5535 .name = "Marvell 88E6085",
5536 .num_databases = 4096,
5537 .num_macs = 8192,
5538 .num_ports = 10,
5539 .num_internal_phys = 5,
5540 .max_vid = 4095,
5541 .max_sid = 63,
5542 .port_base_addr = 0x10,
5543 .phy_base_addr = 0x0,
5544 .global1_addr = 0x1b,
5545 .global2_addr = 0x1c,
5546 .age_time_coeff = 15000,
5547 .g1_irqs = 8,
5548 .g2_irqs = 10,
5549 .atu_move_port_mask = 0xf,
5550 .pvt = true,
5551 .multi_chip = true,
5552 .ops = &mv88e6085_ops,
5553 },
5554
5555 [MV88E6095] = {
5556 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
5557 .family = MV88E6XXX_FAMILY_6095,
5558 .name = "Marvell 88E6095/88E6095F",
5559 .num_databases = 256,
5560 .num_macs = 8192,
5561 .num_ports = 11,
5562 .num_internal_phys = 0,
5563 .max_vid = 4095,
5564 .port_base_addr = 0x10,
5565 .phy_base_addr = 0x0,
5566 .global1_addr = 0x1b,
5567 .global2_addr = 0x1c,
5568 .age_time_coeff = 15000,
5569 .g1_irqs = 8,
5570 .atu_move_port_mask = 0xf,
5571 .multi_chip = true,
5572 .ops = &mv88e6095_ops,
5573 },
5574
5575 [MV88E6097] = {
5576 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
5577 .family = MV88E6XXX_FAMILY_6097,
5578 .name = "Marvell 88E6097/88E6097F",
5579 .num_databases = 4096,
5580 .num_macs = 8192,
5581 .num_ports = 11,
5582 .num_internal_phys = 8,
5583 .max_vid = 4095,
5584 .max_sid = 63,
5585 .port_base_addr = 0x10,
5586 .phy_base_addr = 0x0,
5587 .global1_addr = 0x1b,
5588 .global2_addr = 0x1c,
5589 .age_time_coeff = 15000,
5590 .g1_irqs = 8,
5591 .g2_irqs = 10,
5592 .atu_move_port_mask = 0xf,
5593 .pvt = true,
5594 .multi_chip = true,
5595 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5596 .ops = &mv88e6097_ops,
5597 },
5598
5599 [MV88E6123] = {
5600 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
5601 .family = MV88E6XXX_FAMILY_6165,
5602 .name = "Marvell 88E6123",
5603 .num_databases = 4096,
5604 .num_macs = 1024,
5605 .num_ports = 3,
5606 .num_internal_phys = 5,
5607 .max_vid = 4095,
5608 .max_sid = 63,
5609 .port_base_addr = 0x10,
5610 .phy_base_addr = 0x0,
5611 .global1_addr = 0x1b,
5612 .global2_addr = 0x1c,
5613 .age_time_coeff = 15000,
5614 .g1_irqs = 9,
5615 .g2_irqs = 10,
5616 .atu_move_port_mask = 0xf,
5617 .pvt = true,
5618 .multi_chip = true,
5619 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5620 .ops = &mv88e6123_ops,
5621 },
5622
5623 [MV88E6131] = {
5624 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
5625 .family = MV88E6XXX_FAMILY_6185,
5626 .name = "Marvell 88E6131",
5627 .num_databases = 256,
5628 .num_macs = 8192,
5629 .num_ports = 8,
5630 .num_internal_phys = 0,
5631 .max_vid = 4095,
5632 .port_base_addr = 0x10,
5633 .phy_base_addr = 0x0,
5634 .global1_addr = 0x1b,
5635 .global2_addr = 0x1c,
5636 .age_time_coeff = 15000,
5637 .g1_irqs = 9,
5638 .atu_move_port_mask = 0xf,
5639 .multi_chip = true,
5640 .ops = &mv88e6131_ops,
5641 },
5642
5643 [MV88E6141] = {
5644 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
5645 .family = MV88E6XXX_FAMILY_6341,
5646 .name = "Marvell 88E6141",
5647 .num_databases = 4096,
5648 .num_macs = 2048,
5649 .num_ports = 6,
5650 .num_internal_phys = 5,
5651 .num_gpio = 11,
5652 .max_vid = 4095,
5653 .max_sid = 63,
5654 .port_base_addr = 0x10,
5655 .phy_base_addr = 0x10,
5656 .global1_addr = 0x1b,
5657 .global2_addr = 0x1c,
5658 .age_time_coeff = 3750,
5659 .atu_move_port_mask = 0x1f,
5660 .g1_irqs = 9,
5661 .g2_irqs = 10,
5662 .pvt = true,
5663 .multi_chip = true,
5664 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5665 .ops = &mv88e6141_ops,
5666 },
5667
5668 [MV88E6161] = {
5669 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
5670 .family = MV88E6XXX_FAMILY_6165,
5671 .name = "Marvell 88E6161",
5672 .num_databases = 4096,
5673 .num_macs = 1024,
5674 .num_ports = 6,
5675 .num_internal_phys = 5,
5676 .max_vid = 4095,
5677 .max_sid = 63,
5678 .port_base_addr = 0x10,
5679 .phy_base_addr = 0x0,
5680 .global1_addr = 0x1b,
5681 .global2_addr = 0x1c,
5682 .age_time_coeff = 15000,
5683 .g1_irqs = 9,
5684 .g2_irqs = 10,
5685 .atu_move_port_mask = 0xf,
5686 .pvt = true,
5687 .multi_chip = true,
5688 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5689 .ptp_support = true,
5690 .ops = &mv88e6161_ops,
5691 },
5692
5693 [MV88E6165] = {
5694 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
5695 .family = MV88E6XXX_FAMILY_6165,
5696 .name = "Marvell 88E6165",
5697 .num_databases = 4096,
5698 .num_macs = 8192,
5699 .num_ports = 6,
5700 .num_internal_phys = 0,
5701 .max_vid = 4095,
5702 .max_sid = 63,
5703 .port_base_addr = 0x10,
5704 .phy_base_addr = 0x0,
5705 .global1_addr = 0x1b,
5706 .global2_addr = 0x1c,
5707 .age_time_coeff = 15000,
5708 .g1_irqs = 9,
5709 .g2_irqs = 10,
5710 .atu_move_port_mask = 0xf,
5711 .pvt = true,
5712 .multi_chip = true,
5713 .ptp_support = true,
5714 .ops = &mv88e6165_ops,
5715 },
5716
5717 [MV88E6171] = {
5718 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
5719 .family = MV88E6XXX_FAMILY_6351,
5720 .name = "Marvell 88E6171",
5721 .num_databases = 4096,
5722 .num_macs = 8192,
5723 .num_ports = 7,
5724 .num_internal_phys = 5,
5725 .max_vid = 4095,
5726 .max_sid = 63,
5727 .port_base_addr = 0x10,
5728 .phy_base_addr = 0x0,
5729 .global1_addr = 0x1b,
5730 .global2_addr = 0x1c,
5731 .age_time_coeff = 15000,
5732 .g1_irqs = 9,
5733 .g2_irqs = 10,
5734 .atu_move_port_mask = 0xf,
5735 .pvt = true,
5736 .multi_chip = true,
5737 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5738 .ops = &mv88e6171_ops,
5739 },
5740
5741 [MV88E6172] = {
5742 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
5743 .family = MV88E6XXX_FAMILY_6352,
5744 .name = "Marvell 88E6172",
5745 .num_databases = 4096,
5746 .num_macs = 8192,
5747 .num_ports = 7,
5748 .num_internal_phys = 5,
5749 .num_gpio = 15,
5750 .max_vid = 4095,
5751 .max_sid = 63,
5752 .port_base_addr = 0x10,
5753 .phy_base_addr = 0x0,
5754 .global1_addr = 0x1b,
5755 .global2_addr = 0x1c,
5756 .age_time_coeff = 15000,
5757 .g1_irqs = 9,
5758 .g2_irqs = 10,
5759 .atu_move_port_mask = 0xf,
5760 .pvt = true,
5761 .multi_chip = true,
5762 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5763 .ops = &mv88e6172_ops,
5764 },
5765
5766 [MV88E6175] = {
5767 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
5768 .family = MV88E6XXX_FAMILY_6351,
5769 .name = "Marvell 88E6175",
5770 .num_databases = 4096,
5771 .num_macs = 8192,
5772 .num_ports = 7,
5773 .num_internal_phys = 5,
5774 .max_vid = 4095,
5775 .max_sid = 63,
5776 .port_base_addr = 0x10,
5777 .phy_base_addr = 0x0,
5778 .global1_addr = 0x1b,
5779 .global2_addr = 0x1c,
5780 .age_time_coeff = 15000,
5781 .g1_irqs = 9,
5782 .g2_irqs = 10,
5783 .atu_move_port_mask = 0xf,
5784 .pvt = true,
5785 .multi_chip = true,
5786 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5787 .ops = &mv88e6175_ops,
5788 },
5789
5790 [MV88E6176] = {
5791 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
5792 .family = MV88E6XXX_FAMILY_6352,
5793 .name = "Marvell 88E6176",
5794 .num_databases = 4096,
5795 .num_macs = 8192,
5796 .num_ports = 7,
5797 .num_internal_phys = 5,
5798 .num_gpio = 15,
5799 .max_vid = 4095,
5800 .max_sid = 63,
5801 .port_base_addr = 0x10,
5802 .phy_base_addr = 0x0,
5803 .global1_addr = 0x1b,
5804 .global2_addr = 0x1c,
5805 .age_time_coeff = 15000,
5806 .g1_irqs = 9,
5807 .g2_irqs = 10,
5808 .atu_move_port_mask = 0xf,
5809 .pvt = true,
5810 .multi_chip = true,
5811 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5812 .ops = &mv88e6176_ops,
5813 },
5814
5815 [MV88E6185] = {
5816 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
5817 .family = MV88E6XXX_FAMILY_6185,
5818 .name = "Marvell 88E6185",
5819 .num_databases = 256,
5820 .num_macs = 8192,
5821 .num_ports = 10,
5822 .num_internal_phys = 0,
5823 .max_vid = 4095,
5824 .port_base_addr = 0x10,
5825 .phy_base_addr = 0x0,
5826 .global1_addr = 0x1b,
5827 .global2_addr = 0x1c,
5828 .age_time_coeff = 15000,
5829 .g1_irqs = 8,
5830 .atu_move_port_mask = 0xf,
5831 .multi_chip = true,
5832 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
5833 .ops = &mv88e6185_ops,
5834 },
5835
5836 [MV88E6190] = {
5837 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
5838 .family = MV88E6XXX_FAMILY_6390,
5839 .name = "Marvell 88E6190",
5840 .num_databases = 4096,
5841 .num_macs = 16384,
5842 .num_ports = 11, /* 10 + Z80 */
5843 .num_internal_phys = 9,
5844 .num_gpio = 16,
5845 .max_vid = 8191,
5846 .max_sid = 63,
5847 .port_base_addr = 0x0,
5848 .phy_base_addr = 0x0,
5849 .global1_addr = 0x1b,
5850 .global2_addr = 0x1c,
5851 .age_time_coeff = 3750,
5852 .g1_irqs = 9,
5853 .g2_irqs = 14,
5854 .pvt = true,
5855 .multi_chip = true,
5856 .atu_move_port_mask = 0x1f,
5857 .ops = &mv88e6190_ops,
5858 },
5859
5860 [MV88E6190X] = {
5861 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
5862 .family = MV88E6XXX_FAMILY_6390,
5863 .name = "Marvell 88E6190X",
5864 .num_databases = 4096,
5865 .num_macs = 16384,
5866 .num_ports = 11, /* 10 + Z80 */
5867 .num_internal_phys = 9,
5868 .num_gpio = 16,
5869 .max_vid = 8191,
5870 .max_sid = 63,
5871 .port_base_addr = 0x0,
5872 .phy_base_addr = 0x0,
5873 .global1_addr = 0x1b,
5874 .global2_addr = 0x1c,
5875 .age_time_coeff = 3750,
5876 .g1_irqs = 9,
5877 .g2_irqs = 14,
5878 .atu_move_port_mask = 0x1f,
5879 .pvt = true,
5880 .multi_chip = true,
5881 .ops = &mv88e6190x_ops,
5882 },
5883
5884 [MV88E6191] = {
5885 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
5886 .family = MV88E6XXX_FAMILY_6390,
5887 .name = "Marvell 88E6191",
5888 .num_databases = 4096,
5889 .num_macs = 16384,
5890 .num_ports = 11, /* 10 + Z80 */
5891 .num_internal_phys = 9,
5892 .max_vid = 8191,
5893 .max_sid = 63,
5894 .port_base_addr = 0x0,
5895 .phy_base_addr = 0x0,
5896 .global1_addr = 0x1b,
5897 .global2_addr = 0x1c,
5898 .age_time_coeff = 3750,
5899 .g1_irqs = 9,
5900 .g2_irqs = 14,
5901 .atu_move_port_mask = 0x1f,
5902 .pvt = true,
5903 .multi_chip = true,
5904 .ptp_support = true,
5905 .ops = &mv88e6191_ops,
5906 },
5907
5908 [MV88E6191X] = {
5909 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191X,
5910 .family = MV88E6XXX_FAMILY_6393,
5911 .name = "Marvell 88E6191X",
5912 .num_databases = 4096,
5913 .num_ports = 11, /* 10 + Z80 */
5914 .num_internal_phys = 9,
5915 .max_vid = 8191,
5916 .max_sid = 63,
5917 .port_base_addr = 0x0,
5918 .phy_base_addr = 0x0,
5919 .global1_addr = 0x1b,
5920 .global2_addr = 0x1c,
5921 .age_time_coeff = 3750,
5922 .g1_irqs = 10,
5923 .g2_irqs = 14,
5924 .atu_move_port_mask = 0x1f,
5925 .pvt = true,
5926 .multi_chip = true,
5927 .ptp_support = true,
5928 .ops = &mv88e6393x_ops,
5929 },
5930
5931 [MV88E6193X] = {
5932 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6193X,
5933 .family = MV88E6XXX_FAMILY_6393,
5934 .name = "Marvell 88E6193X",
5935 .num_databases = 4096,
5936 .num_ports = 11, /* 10 + Z80 */
5937 .num_internal_phys = 9,
5938 .max_vid = 8191,
5939 .max_sid = 63,
5940 .port_base_addr = 0x0,
5941 .phy_base_addr = 0x0,
5942 .global1_addr = 0x1b,
5943 .global2_addr = 0x1c,
5944 .age_time_coeff = 3750,
5945 .g1_irqs = 10,
5946 .g2_irqs = 14,
5947 .atu_move_port_mask = 0x1f,
5948 .pvt = true,
5949 .multi_chip = true,
5950 .ptp_support = true,
5951 .ops = &mv88e6393x_ops,
5952 },
5953
5954 [MV88E6220] = {
5955 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
5956 .family = MV88E6XXX_FAMILY_6250,
5957 .name = "Marvell 88E6220",
5958 .num_databases = 64,
5959
5960 /* Ports 2-4 are not routed to pins
5961 * => usable ports 0, 1, 5, 6
5962 */
5963 .num_ports = 7,
5964 .num_internal_phys = 2,
5965 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
5966 .max_vid = 4095,
5967 .port_base_addr = 0x08,
5968 .phy_base_addr = 0x00,
5969 .global1_addr = 0x0f,
5970 .global2_addr = 0x07,
5971 .age_time_coeff = 15000,
5972 .g1_irqs = 9,
5973 .g2_irqs = 10,
5974 .atu_move_port_mask = 0xf,
5975 .dual_chip = true,
5976 .ptp_support = true,
5977 .ops = &mv88e6250_ops,
5978 },
5979
5980 [MV88E6240] = {
5981 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
5982 .family = MV88E6XXX_FAMILY_6352,
5983 .name = "Marvell 88E6240",
5984 .num_databases = 4096,
5985 .num_macs = 8192,
5986 .num_ports = 7,
5987 .num_internal_phys = 5,
5988 .num_gpio = 15,
5989 .max_vid = 4095,
5990 .max_sid = 63,
5991 .port_base_addr = 0x10,
5992 .phy_base_addr = 0x0,
5993 .global1_addr = 0x1b,
5994 .global2_addr = 0x1c,
5995 .age_time_coeff = 15000,
5996 .g1_irqs = 9,
5997 .g2_irqs = 10,
5998 .atu_move_port_mask = 0xf,
5999 .pvt = true,
6000 .multi_chip = true,
6001 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6002 .ptp_support = true,
6003 .ops = &mv88e6240_ops,
6004 },
6005
6006 [MV88E6250] = {
6007 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
6008 .family = MV88E6XXX_FAMILY_6250,
6009 .name = "Marvell 88E6250",
6010 .num_databases = 64,
6011 .num_ports = 7,
6012 .num_internal_phys = 5,
6013 .max_vid = 4095,
6014 .port_base_addr = 0x08,
6015 .phy_base_addr = 0x00,
6016 .global1_addr = 0x0f,
6017 .global2_addr = 0x07,
6018 .age_time_coeff = 15000,
6019 .g1_irqs = 9,
6020 .g2_irqs = 10,
6021 .atu_move_port_mask = 0xf,
6022 .dual_chip = true,
6023 .ptp_support = true,
6024 .ops = &mv88e6250_ops,
6025 },
6026
6027 [MV88E6290] = {
6028 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
6029 .family = MV88E6XXX_FAMILY_6390,
6030 .name = "Marvell 88E6290",
6031 .num_databases = 4096,
6032 .num_ports = 11, /* 10 + Z80 */
6033 .num_internal_phys = 9,
6034 .num_gpio = 16,
6035 .max_vid = 8191,
6036 .max_sid = 63,
6037 .port_base_addr = 0x0,
6038 .phy_base_addr = 0x0,
6039 .global1_addr = 0x1b,
6040 .global2_addr = 0x1c,
6041 .age_time_coeff = 3750,
6042 .g1_irqs = 9,
6043 .g2_irqs = 14,
6044 .atu_move_port_mask = 0x1f,
6045 .pvt = true,
6046 .multi_chip = true,
6047 .ptp_support = true,
6048 .ops = &mv88e6290_ops,
6049 },
6050
6051 [MV88E6320] = {
6052 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
6053 .family = MV88E6XXX_FAMILY_6320,
6054 .name = "Marvell 88E6320",
6055 .num_databases = 4096,
6056 .num_macs = 8192,
6057 .num_ports = 7,
6058 .num_internal_phys = 5,
6059 .num_gpio = 15,
6060 .max_vid = 4095,
6061 .port_base_addr = 0x10,
6062 .phy_base_addr = 0x0,
6063 .global1_addr = 0x1b,
6064 .global2_addr = 0x1c,
6065 .age_time_coeff = 15000,
6066 .g1_irqs = 8,
6067 .g2_irqs = 10,
6068 .atu_move_port_mask = 0xf,
6069 .pvt = true,
6070 .multi_chip = true,
6071 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6072 .ptp_support = true,
6073 .ops = &mv88e6320_ops,
6074 },
6075
6076 [MV88E6321] = {
6077 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
6078 .family = MV88E6XXX_FAMILY_6320,
6079 .name = "Marvell 88E6321",
6080 .num_databases = 4096,
6081 .num_macs = 8192,
6082 .num_ports = 7,
6083 .num_internal_phys = 5,
6084 .num_gpio = 15,
6085 .max_vid = 4095,
6086 .port_base_addr = 0x10,
6087 .phy_base_addr = 0x0,
6088 .global1_addr = 0x1b,
6089 .global2_addr = 0x1c,
6090 .age_time_coeff = 15000,
6091 .g1_irqs = 8,
6092 .g2_irqs = 10,
6093 .atu_move_port_mask = 0xf,
6094 .multi_chip = true,
6095 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6096 .ptp_support = true,
6097 .ops = &mv88e6321_ops,
6098 },
6099
6100 [MV88E6341] = {
6101 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
6102 .family = MV88E6XXX_FAMILY_6341,
6103 .name = "Marvell 88E6341",
6104 .num_databases = 4096,
6105 .num_macs = 2048,
6106 .num_internal_phys = 5,
6107 .num_ports = 6,
6108 .num_gpio = 11,
6109 .max_vid = 4095,
6110 .max_sid = 63,
6111 .port_base_addr = 0x10,
6112 .phy_base_addr = 0x10,
6113 .global1_addr = 0x1b,
6114 .global2_addr = 0x1c,
6115 .age_time_coeff = 3750,
6116 .atu_move_port_mask = 0x1f,
6117 .g1_irqs = 9,
6118 .g2_irqs = 10,
6119 .pvt = true,
6120 .multi_chip = true,
6121 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6122 .ptp_support = true,
6123 .ops = &mv88e6341_ops,
6124 },
6125
6126 [MV88E6350] = {
6127 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
6128 .family = MV88E6XXX_FAMILY_6351,
6129 .name = "Marvell 88E6350",
6130 .num_databases = 4096,
6131 .num_macs = 8192,
6132 .num_ports = 7,
6133 .num_internal_phys = 5,
6134 .max_vid = 4095,
6135 .max_sid = 63,
6136 .port_base_addr = 0x10,
6137 .phy_base_addr = 0x0,
6138 .global1_addr = 0x1b,
6139 .global2_addr = 0x1c,
6140 .age_time_coeff = 15000,
6141 .g1_irqs = 9,
6142 .g2_irqs = 10,
6143 .atu_move_port_mask = 0xf,
6144 .pvt = true,
6145 .multi_chip = true,
6146 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6147 .ops = &mv88e6350_ops,
6148 },
6149
6150 [MV88E6351] = {
6151 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
6152 .family = MV88E6XXX_FAMILY_6351,
6153 .name = "Marvell 88E6351",
6154 .num_databases = 4096,
6155 .num_macs = 8192,
6156 .num_ports = 7,
6157 .num_internal_phys = 5,
6158 .max_vid = 4095,
6159 .max_sid = 63,
6160 .port_base_addr = 0x10,
6161 .phy_base_addr = 0x0,
6162 .global1_addr = 0x1b,
6163 .global2_addr = 0x1c,
6164 .age_time_coeff = 15000,
6165 .g1_irqs = 9,
6166 .g2_irqs = 10,
6167 .atu_move_port_mask = 0xf,
6168 .pvt = true,
6169 .multi_chip = true,
6170 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6171 .ops = &mv88e6351_ops,
6172 },
6173
6174 [MV88E6352] = {
6175 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
6176 .family = MV88E6XXX_FAMILY_6352,
6177 .name = "Marvell 88E6352",
6178 .num_databases = 4096,
6179 .num_macs = 8192,
6180 .num_ports = 7,
6181 .num_internal_phys = 5,
6182 .num_gpio = 15,
6183 .max_vid = 4095,
6184 .max_sid = 63,
6185 .port_base_addr = 0x10,
6186 .phy_base_addr = 0x0,
6187 .global1_addr = 0x1b,
6188 .global2_addr = 0x1c,
6189 .age_time_coeff = 15000,
6190 .g1_irqs = 9,
6191 .g2_irqs = 10,
6192 .atu_move_port_mask = 0xf,
6193 .pvt = true,
6194 .multi_chip = true,
6195 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
6196 .ptp_support = true,
6197 .ops = &mv88e6352_ops,
6198 },
6199 [MV88E6390] = {
6200 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
6201 .family = MV88E6XXX_FAMILY_6390,
6202 .name = "Marvell 88E6390",
6203 .num_databases = 4096,
6204 .num_macs = 16384,
6205 .num_ports = 11, /* 10 + Z80 */
6206 .num_internal_phys = 9,
6207 .num_gpio = 16,
6208 .max_vid = 8191,
6209 .max_sid = 63,
6210 .port_base_addr = 0x0,
6211 .phy_base_addr = 0x0,
6212 .global1_addr = 0x1b,
6213 .global2_addr = 0x1c,
6214 .age_time_coeff = 3750,
6215 .g1_irqs = 9,
6216 .g2_irqs = 14,
6217 .atu_move_port_mask = 0x1f,
6218 .pvt = true,
6219 .multi_chip = true,
6220 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
6221 .ptp_support = true,
6222 .ops = &mv88e6390_ops,
6223 },
6224 [MV88E6390X] = {
6225 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
6226 .family = MV88E6XXX_FAMILY_6390,
6227 .name = "Marvell 88E6390X",
6228 .num_databases = 4096,
6229 .num_macs = 16384,
6230 .num_ports = 11, /* 10 + Z80 */
6231 .num_internal_phys = 9,
6232 .num_gpio = 16,
6233 .max_vid = 8191,
6234 .max_sid = 63,
6235 .port_base_addr = 0x0,
6236 .phy_base_addr = 0x0,
6237 .global1_addr = 0x1b,
6238 .global2_addr = 0x1c,
6239 .age_time_coeff = 3750,
6240 .g1_irqs = 9,
6241 .g2_irqs = 14,
6242 .atu_move_port_mask = 0x1f,
6243 .pvt = true,
6244 .multi_chip = true,
6245 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
6246 .ptp_support = true,
6247 .ops = &mv88e6390x_ops,
6248 },
6249
6250 [MV88E6393X] = {
6251 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
6252 .family = MV88E6XXX_FAMILY_6393,
6253 .name = "Marvell 88E6393X",
6254 .num_databases = 4096,
6255 .num_ports = 11, /* 10 + Z80 */
6256 .num_internal_phys = 9,
6257 .max_vid = 8191,
6258 .max_sid = 63,
6259 .port_base_addr = 0x0,
6260 .phy_base_addr = 0x0,
6261 .global1_addr = 0x1b,
6262 .global2_addr = 0x1c,
6263 .age_time_coeff = 3750,
6264 .g1_irqs = 10,
6265 .g2_irqs = 14,
6266 .atu_move_port_mask = 0x1f,
6267 .pvt = true,
6268 .multi_chip = true,
6269 .ptp_support = true,
6270 .ops = &mv88e6393x_ops,
6271 },
6272 };
6273
mv88e6xxx_lookup_info(unsigned int prod_num)6274 static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
6275 {
6276 int i;
6277
6278 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
6279 if (mv88e6xxx_table[i].prod_num == prod_num)
6280 return &mv88e6xxx_table[i];
6281
6282 return NULL;
6283 }
6284
mv88e6xxx_detect(struct mv88e6xxx_chip * chip)6285 static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
6286 {
6287 const struct mv88e6xxx_info *info;
6288 unsigned int prod_num, rev;
6289 u16 id;
6290 int err;
6291
6292 mv88e6xxx_reg_lock(chip);
6293 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
6294 mv88e6xxx_reg_unlock(chip);
6295 if (err)
6296 return err;
6297
6298 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
6299 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
6300
6301 info = mv88e6xxx_lookup_info(prod_num);
6302 if (!info)
6303 return -ENODEV;
6304
6305 /* Update the compatible info with the probed one */
6306 chip->info = info;
6307
6308 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
6309 chip->info->prod_num, chip->info->name, rev);
6310
6311 return 0;
6312 }
6313
mv88e6xxx_single_chip_detect(struct mv88e6xxx_chip * chip,struct mdio_device * mdiodev)6314 static int mv88e6xxx_single_chip_detect(struct mv88e6xxx_chip *chip,
6315 struct mdio_device *mdiodev)
6316 {
6317 int err;
6318
6319 /* dual_chip takes precedence over single/multi-chip modes */
6320 if (chip->info->dual_chip)
6321 return -EINVAL;
6322
6323 /* If the mdio addr is 16 indicating the first port address of a switch
6324 * (e.g. mv88e6*41) in single chip addressing mode the device may be
6325 * configured in single chip addressing mode. Setup the smi access as
6326 * single chip addressing mode and attempt to detect the model of the
6327 * switch, if this fails the device is not configured in single chip
6328 * addressing mode.
6329 */
6330 if (mdiodev->addr != 16)
6331 return -EINVAL;
6332
6333 err = mv88e6xxx_smi_init(chip, mdiodev->bus, 0);
6334 if (err)
6335 return err;
6336
6337 return mv88e6xxx_detect(chip);
6338 }
6339
mv88e6xxx_alloc_chip(struct device * dev)6340 static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
6341 {
6342 struct mv88e6xxx_chip *chip;
6343
6344 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
6345 if (!chip)
6346 return NULL;
6347
6348 chip->dev = dev;
6349
6350 mutex_init(&chip->reg_lock);
6351 INIT_LIST_HEAD(&chip->mdios);
6352 idr_init(&chip->policies);
6353 INIT_LIST_HEAD(&chip->msts);
6354
6355 return chip;
6356 }
6357
mv88e6xxx_get_tag_protocol(struct dsa_switch * ds,int port,enum dsa_tag_protocol m)6358 static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
6359 int port,
6360 enum dsa_tag_protocol m)
6361 {
6362 struct mv88e6xxx_chip *chip = ds->priv;
6363
6364 return chip->tag_protocol;
6365 }
6366
mv88e6xxx_change_tag_protocol(struct dsa_switch * ds,enum dsa_tag_protocol proto)6367 static int mv88e6xxx_change_tag_protocol(struct dsa_switch *ds,
6368 enum dsa_tag_protocol proto)
6369 {
6370 struct mv88e6xxx_chip *chip = ds->priv;
6371 enum dsa_tag_protocol old_protocol;
6372 struct dsa_port *cpu_dp;
6373 int err;
6374
6375 switch (proto) {
6376 case DSA_TAG_PROTO_EDSA:
6377 switch (chip->info->edsa_support) {
6378 case MV88E6XXX_EDSA_UNSUPPORTED:
6379 return -EPROTONOSUPPORT;
6380 case MV88E6XXX_EDSA_UNDOCUMENTED:
6381 dev_warn(chip->dev, "Relying on undocumented EDSA tagging behavior\n");
6382 fallthrough;
6383 case MV88E6XXX_EDSA_SUPPORTED:
6384 break;
6385 }
6386 break;
6387 case DSA_TAG_PROTO_DSA:
6388 break;
6389 default:
6390 return -EPROTONOSUPPORT;
6391 }
6392
6393 old_protocol = chip->tag_protocol;
6394 chip->tag_protocol = proto;
6395
6396 mv88e6xxx_reg_lock(chip);
6397 dsa_switch_for_each_cpu_port(cpu_dp, ds) {
6398 err = mv88e6xxx_setup_port_mode(chip, cpu_dp->index);
6399 if (err) {
6400 mv88e6xxx_reg_unlock(chip);
6401 goto unwind;
6402 }
6403 }
6404 mv88e6xxx_reg_unlock(chip);
6405
6406 return 0;
6407
6408 unwind:
6409 chip->tag_protocol = old_protocol;
6410
6411 mv88e6xxx_reg_lock(chip);
6412 dsa_switch_for_each_cpu_port_continue_reverse(cpu_dp, ds)
6413 mv88e6xxx_setup_port_mode(chip, cpu_dp->index);
6414 mv88e6xxx_reg_unlock(chip);
6415
6416 return err;
6417 }
6418
mv88e6xxx_port_mdb_add(struct dsa_switch * ds,int port,const struct switchdev_obj_port_mdb * mdb,struct dsa_db db)6419 static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
6420 const struct switchdev_obj_port_mdb *mdb,
6421 struct dsa_db db)
6422 {
6423 struct mv88e6xxx_chip *chip = ds->priv;
6424 int err;
6425
6426 mv88e6xxx_reg_lock(chip);
6427 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
6428 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
6429 mv88e6xxx_reg_unlock(chip);
6430
6431 return err;
6432 }
6433
mv88e6xxx_port_mdb_del(struct dsa_switch * ds,int port,const struct switchdev_obj_port_mdb * mdb,struct dsa_db db)6434 static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
6435 const struct switchdev_obj_port_mdb *mdb,
6436 struct dsa_db db)
6437 {
6438 struct mv88e6xxx_chip *chip = ds->priv;
6439 int err;
6440
6441 mv88e6xxx_reg_lock(chip);
6442 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
6443 mv88e6xxx_reg_unlock(chip);
6444
6445 return err;
6446 }
6447
mv88e6xxx_port_mirror_add(struct dsa_switch * ds,int port,struct dsa_mall_mirror_tc_entry * mirror,bool ingress,struct netlink_ext_ack * extack)6448 static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
6449 struct dsa_mall_mirror_tc_entry *mirror,
6450 bool ingress,
6451 struct netlink_ext_ack *extack)
6452 {
6453 enum mv88e6xxx_egress_direction direction = ingress ?
6454 MV88E6XXX_EGRESS_DIR_INGRESS :
6455 MV88E6XXX_EGRESS_DIR_EGRESS;
6456 struct mv88e6xxx_chip *chip = ds->priv;
6457 bool other_mirrors = false;
6458 int i;
6459 int err;
6460
6461 mutex_lock(&chip->reg_lock);
6462 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
6463 mirror->to_local_port) {
6464 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
6465 other_mirrors |= ingress ?
6466 chip->ports[i].mirror_ingress :
6467 chip->ports[i].mirror_egress;
6468
6469 /* Can't change egress port when other mirror is active */
6470 if (other_mirrors) {
6471 err = -EBUSY;
6472 goto out;
6473 }
6474
6475 err = mv88e6xxx_set_egress_port(chip, direction,
6476 mirror->to_local_port);
6477 if (err)
6478 goto out;
6479 }
6480
6481 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
6482 out:
6483 mutex_unlock(&chip->reg_lock);
6484
6485 return err;
6486 }
6487
mv88e6xxx_port_mirror_del(struct dsa_switch * ds,int port,struct dsa_mall_mirror_tc_entry * mirror)6488 static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
6489 struct dsa_mall_mirror_tc_entry *mirror)
6490 {
6491 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
6492 MV88E6XXX_EGRESS_DIR_INGRESS :
6493 MV88E6XXX_EGRESS_DIR_EGRESS;
6494 struct mv88e6xxx_chip *chip = ds->priv;
6495 bool other_mirrors = false;
6496 int i;
6497
6498 mutex_lock(&chip->reg_lock);
6499 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
6500 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
6501
6502 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
6503 other_mirrors |= mirror->ingress ?
6504 chip->ports[i].mirror_ingress :
6505 chip->ports[i].mirror_egress;
6506
6507 /* Reset egress port when no other mirror is active */
6508 if (!other_mirrors) {
6509 if (mv88e6xxx_set_egress_port(chip, direction,
6510 dsa_upstream_port(ds, port)))
6511 dev_err(ds->dev, "failed to set egress port\n");
6512 }
6513
6514 mutex_unlock(&chip->reg_lock);
6515 }
6516
mv88e6xxx_port_pre_bridge_flags(struct dsa_switch * ds,int port,struct switchdev_brport_flags flags,struct netlink_ext_ack * extack)6517 static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port,
6518 struct switchdev_brport_flags flags,
6519 struct netlink_ext_ack *extack)
6520 {
6521 struct mv88e6xxx_chip *chip = ds->priv;
6522 const struct mv88e6xxx_ops *ops;
6523
6524 if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
6525 BR_BCAST_FLOOD | BR_PORT_LOCKED))
6526 return -EINVAL;
6527
6528 ops = chip->info->ops;
6529
6530 if ((flags.mask & BR_FLOOD) && !ops->port_set_ucast_flood)
6531 return -EINVAL;
6532
6533 if ((flags.mask & BR_MCAST_FLOOD) && !ops->port_set_mcast_flood)
6534 return -EINVAL;
6535
6536 return 0;
6537 }
6538
mv88e6xxx_port_bridge_flags(struct dsa_switch * ds,int port,struct switchdev_brport_flags flags,struct netlink_ext_ack * extack)6539 static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
6540 struct switchdev_brport_flags flags,
6541 struct netlink_ext_ack *extack)
6542 {
6543 struct mv88e6xxx_chip *chip = ds->priv;
6544 int err = -EOPNOTSUPP;
6545
6546 mv88e6xxx_reg_lock(chip);
6547
6548 if (flags.mask & BR_LEARNING) {
6549 bool learning = !!(flags.val & BR_LEARNING);
6550 u16 pav = learning ? (1 << port) : 0;
6551
6552 err = mv88e6xxx_port_set_assoc_vector(chip, port, pav);
6553 if (err)
6554 goto out;
6555 }
6556
6557 if (flags.mask & BR_FLOOD) {
6558 bool unicast = !!(flags.val & BR_FLOOD);
6559
6560 err = chip->info->ops->port_set_ucast_flood(chip, port,
6561 unicast);
6562 if (err)
6563 goto out;
6564 }
6565
6566 if (flags.mask & BR_MCAST_FLOOD) {
6567 bool multicast = !!(flags.val & BR_MCAST_FLOOD);
6568
6569 err = chip->info->ops->port_set_mcast_flood(chip, port,
6570 multicast);
6571 if (err)
6572 goto out;
6573 }
6574
6575 if (flags.mask & BR_BCAST_FLOOD) {
6576 bool broadcast = !!(flags.val & BR_BCAST_FLOOD);
6577
6578 err = mv88e6xxx_port_broadcast_sync(chip, port, broadcast);
6579 if (err)
6580 goto out;
6581 }
6582
6583 if (flags.mask & BR_PORT_LOCKED) {
6584 bool locked = !!(flags.val & BR_PORT_LOCKED);
6585
6586 err = mv88e6xxx_port_set_lock(chip, port, locked);
6587 if (err)
6588 goto out;
6589 }
6590 out:
6591 mv88e6xxx_reg_unlock(chip);
6592
6593 return err;
6594 }
6595
mv88e6xxx_lag_can_offload(struct dsa_switch * ds,struct dsa_lag lag,struct netdev_lag_upper_info * info,struct netlink_ext_ack * extack)6596 static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
6597 struct dsa_lag lag,
6598 struct netdev_lag_upper_info *info,
6599 struct netlink_ext_ack *extack)
6600 {
6601 struct mv88e6xxx_chip *chip = ds->priv;
6602 struct dsa_port *dp;
6603 int members = 0;
6604
6605 if (!mv88e6xxx_has_lag(chip)) {
6606 NL_SET_ERR_MSG_MOD(extack, "Chip does not support LAG offload");
6607 return false;
6608 }
6609
6610 if (!lag.id)
6611 return false;
6612
6613 dsa_lag_foreach_port(dp, ds->dst, &lag)
6614 /* Includes the port joining the LAG */
6615 members++;
6616
6617 if (members > 8) {
6618 NL_SET_ERR_MSG_MOD(extack,
6619 "Cannot offload more than 8 LAG ports");
6620 return false;
6621 }
6622
6623 /* We could potentially relax this to include active
6624 * backup in the future.
6625 */
6626 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) {
6627 NL_SET_ERR_MSG_MOD(extack,
6628 "Can only offload LAG using hash TX type");
6629 return false;
6630 }
6631
6632 /* Ideally we would also validate that the hash type matches
6633 * the hardware. Alas, this is always set to unknown on team
6634 * interfaces.
6635 */
6636 return true;
6637 }
6638
mv88e6xxx_lag_sync_map(struct dsa_switch * ds,struct dsa_lag lag)6639 static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct dsa_lag lag)
6640 {
6641 struct mv88e6xxx_chip *chip = ds->priv;
6642 struct dsa_port *dp;
6643 u16 map = 0;
6644 int id;
6645
6646 /* DSA LAG IDs are one-based, hardware is zero-based */
6647 id = lag.id - 1;
6648
6649 /* Build the map of all ports to distribute flows destined for
6650 * this LAG. This can be either a local user port, or a DSA
6651 * port if the LAG port is on a remote chip.
6652 */
6653 dsa_lag_foreach_port(dp, ds->dst, &lag)
6654 map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));
6655
6656 return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
6657 }
6658
6659 static const u8 mv88e6xxx_lag_mask_table[8][8] = {
6660 /* Row number corresponds to the number of active members in a
6661 * LAG. Each column states which of the eight hash buckets are
6662 * mapped to the column:th port in the LAG.
6663 *
6664 * Example: In a LAG with three active ports, the second port
6665 * ([2][1]) would be selected for traffic mapped to buckets
6666 * 3,4,5 (0x38).
6667 */
6668 { 0xff, 0, 0, 0, 0, 0, 0, 0 },
6669 { 0x0f, 0xf0, 0, 0, 0, 0, 0, 0 },
6670 { 0x07, 0x38, 0xc0, 0, 0, 0, 0, 0 },
6671 { 0x03, 0x0c, 0x30, 0xc0, 0, 0, 0, 0 },
6672 { 0x03, 0x0c, 0x30, 0x40, 0x80, 0, 0, 0 },
6673 { 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80, 0, 0 },
6674 { 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0 },
6675 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
6676 };
6677
mv88e6xxx_lag_set_port_mask(u16 * mask,int port,int num_tx,int nth)6678 static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
6679 int num_tx, int nth)
6680 {
6681 u8 active = 0;
6682 int i;
6683
6684 num_tx = num_tx <= 8 ? num_tx : 8;
6685 if (nth < num_tx)
6686 active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];
6687
6688 for (i = 0; i < 8; i++) {
6689 if (BIT(i) & active)
6690 mask[i] |= BIT(port);
6691 }
6692 }
6693
mv88e6xxx_lag_sync_masks(struct dsa_switch * ds)6694 static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
6695 {
6696 struct mv88e6xxx_chip *chip = ds->priv;
6697 unsigned int id, num_tx;
6698 struct dsa_port *dp;
6699 struct dsa_lag *lag;
6700 int i, err, nth;
6701 u16 mask[8];
6702 u16 ivec;
6703
6704 /* Assume no port is a member of any LAG. */
6705 ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;
6706
6707 /* Disable all masks for ports that _are_ members of a LAG. */
6708 dsa_switch_for_each_port(dp, ds) {
6709 if (!dp->lag)
6710 continue;
6711
6712 ivec &= ~BIT(dp->index);
6713 }
6714
6715 for (i = 0; i < 8; i++)
6716 mask[i] = ivec;
6717
6718 /* Enable the correct subset of masks for all LAG ports that
6719 * are in the Tx set.
6720 */
6721 dsa_lags_foreach_id(id, ds->dst) {
6722 lag = dsa_lag_by_id(ds->dst, id);
6723 if (!lag)
6724 continue;
6725
6726 num_tx = 0;
6727 dsa_lag_foreach_port(dp, ds->dst, lag) {
6728 if (dp->lag_tx_enabled)
6729 num_tx++;
6730 }
6731
6732 if (!num_tx)
6733 continue;
6734
6735 nth = 0;
6736 dsa_lag_foreach_port(dp, ds->dst, lag) {
6737 if (!dp->lag_tx_enabled)
6738 continue;
6739
6740 if (dp->ds == ds)
6741 mv88e6xxx_lag_set_port_mask(mask, dp->index,
6742 num_tx, nth);
6743
6744 nth++;
6745 }
6746 }
6747
6748 for (i = 0; i < 8; i++) {
6749 err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
6750 if (err)
6751 return err;
6752 }
6753
6754 return 0;
6755 }
6756
mv88e6xxx_lag_sync_masks_map(struct dsa_switch * ds,struct dsa_lag lag)6757 static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
6758 struct dsa_lag lag)
6759 {
6760 int err;
6761
6762 err = mv88e6xxx_lag_sync_masks(ds);
6763
6764 if (!err)
6765 err = mv88e6xxx_lag_sync_map(ds, lag);
6766
6767 return err;
6768 }
6769
mv88e6xxx_port_lag_change(struct dsa_switch * ds,int port)6770 static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port)
6771 {
6772 struct mv88e6xxx_chip *chip = ds->priv;
6773 int err;
6774
6775 mv88e6xxx_reg_lock(chip);
6776 err = mv88e6xxx_lag_sync_masks(ds);
6777 mv88e6xxx_reg_unlock(chip);
6778 return err;
6779 }
6780
mv88e6xxx_port_lag_join(struct dsa_switch * ds,int port,struct dsa_lag lag,struct netdev_lag_upper_info * info,struct netlink_ext_ack * extack)6781 static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
6782 struct dsa_lag lag,
6783 struct netdev_lag_upper_info *info,
6784 struct netlink_ext_ack *extack)
6785 {
6786 struct mv88e6xxx_chip *chip = ds->priv;
6787 int err, id;
6788
6789 if (!mv88e6xxx_lag_can_offload(ds, lag, info, extack))
6790 return -EOPNOTSUPP;
6791
6792 /* DSA LAG IDs are one-based */
6793 id = lag.id - 1;
6794
6795 mv88e6xxx_reg_lock(chip);
6796
6797 err = mv88e6xxx_port_set_trunk(chip, port, true, id);
6798 if (err)
6799 goto err_unlock;
6800
6801 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6802 if (err)
6803 goto err_clear_trunk;
6804
6805 mv88e6xxx_reg_unlock(chip);
6806 return 0;
6807
6808 err_clear_trunk:
6809 mv88e6xxx_port_set_trunk(chip, port, false, 0);
6810 err_unlock:
6811 mv88e6xxx_reg_unlock(chip);
6812 return err;
6813 }
6814
mv88e6xxx_port_lag_leave(struct dsa_switch * ds,int port,struct dsa_lag lag)6815 static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
6816 struct dsa_lag lag)
6817 {
6818 struct mv88e6xxx_chip *chip = ds->priv;
6819 int err_sync, err_trunk;
6820
6821 mv88e6xxx_reg_lock(chip);
6822 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6823 err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
6824 mv88e6xxx_reg_unlock(chip);
6825 return err_sync ? : err_trunk;
6826 }
6827
mv88e6xxx_crosschip_lag_change(struct dsa_switch * ds,int sw_index,int port)6828 static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
6829 int port)
6830 {
6831 struct mv88e6xxx_chip *chip = ds->priv;
6832 int err;
6833
6834 mv88e6xxx_reg_lock(chip);
6835 err = mv88e6xxx_lag_sync_masks(ds);
6836 mv88e6xxx_reg_unlock(chip);
6837 return err;
6838 }
6839
mv88e6xxx_crosschip_lag_join(struct dsa_switch * ds,int sw_index,int port,struct dsa_lag lag,struct netdev_lag_upper_info * info,struct netlink_ext_ack * extack)6840 static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
6841 int port, struct dsa_lag lag,
6842 struct netdev_lag_upper_info *info,
6843 struct netlink_ext_ack *extack)
6844 {
6845 struct mv88e6xxx_chip *chip = ds->priv;
6846 int err;
6847
6848 if (!mv88e6xxx_lag_can_offload(ds, lag, info, extack))
6849 return -EOPNOTSUPP;
6850
6851 mv88e6xxx_reg_lock(chip);
6852
6853 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6854 if (err)
6855 goto unlock;
6856
6857 err = mv88e6xxx_pvt_map(chip, sw_index, port);
6858
6859 unlock:
6860 mv88e6xxx_reg_unlock(chip);
6861 return err;
6862 }
6863
mv88e6xxx_crosschip_lag_leave(struct dsa_switch * ds,int sw_index,int port,struct dsa_lag lag)6864 static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
6865 int port, struct dsa_lag lag)
6866 {
6867 struct mv88e6xxx_chip *chip = ds->priv;
6868 int err_sync, err_pvt;
6869
6870 mv88e6xxx_reg_lock(chip);
6871 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6872 err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
6873 mv88e6xxx_reg_unlock(chip);
6874 return err_sync ? : err_pvt;
6875 }
6876
6877 static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
6878 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
6879 .change_tag_protocol = mv88e6xxx_change_tag_protocol,
6880 .setup = mv88e6xxx_setup,
6881 .teardown = mv88e6xxx_teardown,
6882 .port_setup = mv88e6xxx_port_setup,
6883 .port_teardown = mv88e6xxx_port_teardown,
6884 .phylink_get_caps = mv88e6xxx_get_caps,
6885 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
6886 .phylink_mac_config = mv88e6xxx_mac_config,
6887 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
6888 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
6889 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
6890 .get_strings = mv88e6xxx_get_strings,
6891 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
6892 .get_sset_count = mv88e6xxx_get_sset_count,
6893 .port_enable = mv88e6xxx_port_enable,
6894 .port_disable = mv88e6xxx_port_disable,
6895 .port_max_mtu = mv88e6xxx_get_max_mtu,
6896 .port_change_mtu = mv88e6xxx_change_mtu,
6897 .get_mac_eee = mv88e6xxx_get_mac_eee,
6898 .set_mac_eee = mv88e6xxx_set_mac_eee,
6899 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
6900 .get_eeprom = mv88e6xxx_get_eeprom,
6901 .set_eeprom = mv88e6xxx_set_eeprom,
6902 .get_regs_len = mv88e6xxx_get_regs_len,
6903 .get_regs = mv88e6xxx_get_regs,
6904 .get_rxnfc = mv88e6xxx_get_rxnfc,
6905 .set_rxnfc = mv88e6xxx_set_rxnfc,
6906 .set_ageing_time = mv88e6xxx_set_ageing_time,
6907 .port_bridge_join = mv88e6xxx_port_bridge_join,
6908 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
6909 .port_pre_bridge_flags = mv88e6xxx_port_pre_bridge_flags,
6910 .port_bridge_flags = mv88e6xxx_port_bridge_flags,
6911 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
6912 .port_mst_state_set = mv88e6xxx_port_mst_state_set,
6913 .port_fast_age = mv88e6xxx_port_fast_age,
6914 .port_vlan_fast_age = mv88e6xxx_port_vlan_fast_age,
6915 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
6916 .port_vlan_add = mv88e6xxx_port_vlan_add,
6917 .port_vlan_del = mv88e6xxx_port_vlan_del,
6918 .vlan_msti_set = mv88e6xxx_vlan_msti_set,
6919 .port_fdb_add = mv88e6xxx_port_fdb_add,
6920 .port_fdb_del = mv88e6xxx_port_fdb_del,
6921 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
6922 .port_mdb_add = mv88e6xxx_port_mdb_add,
6923 .port_mdb_del = mv88e6xxx_port_mdb_del,
6924 .port_mirror_add = mv88e6xxx_port_mirror_add,
6925 .port_mirror_del = mv88e6xxx_port_mirror_del,
6926 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
6927 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
6928 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
6929 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
6930 .port_txtstamp = mv88e6xxx_port_txtstamp,
6931 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
6932 .get_ts_info = mv88e6xxx_get_ts_info,
6933 .devlink_param_get = mv88e6xxx_devlink_param_get,
6934 .devlink_param_set = mv88e6xxx_devlink_param_set,
6935 .devlink_info_get = mv88e6xxx_devlink_info_get,
6936 .port_lag_change = mv88e6xxx_port_lag_change,
6937 .port_lag_join = mv88e6xxx_port_lag_join,
6938 .port_lag_leave = mv88e6xxx_port_lag_leave,
6939 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
6940 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
6941 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
6942 };
6943
mv88e6xxx_register_switch(struct mv88e6xxx_chip * chip)6944 static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
6945 {
6946 struct device *dev = chip->dev;
6947 struct dsa_switch *ds;
6948
6949 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
6950 if (!ds)
6951 return -ENOMEM;
6952
6953 ds->dev = dev;
6954 ds->num_ports = mv88e6xxx_num_ports(chip);
6955 ds->priv = chip;
6956 ds->dev = dev;
6957 ds->ops = &mv88e6xxx_switch_ops;
6958 ds->ageing_time_min = chip->info->age_time_coeff;
6959 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
6960
6961 /* Some chips support up to 32, but that requires enabling the
6962 * 5-bit port mode, which we do not support. 640k^W16 ought to
6963 * be enough for anyone.
6964 */
6965 ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
6966
6967 dev_set_drvdata(dev, ds);
6968
6969 return dsa_register_switch(ds);
6970 }
6971
mv88e6xxx_unregister_switch(struct mv88e6xxx_chip * chip)6972 static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
6973 {
6974 dsa_unregister_switch(chip->ds);
6975 }
6976
pdata_device_get_match_data(struct device * dev)6977 static const void *pdata_device_get_match_data(struct device *dev)
6978 {
6979 const struct of_device_id *matches = dev->driver->of_match_table;
6980 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
6981
6982 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
6983 matches++) {
6984 if (!strcmp(pdata->compatible, matches->compatible))
6985 return matches->data;
6986 }
6987 return NULL;
6988 }
6989
6990 /* There is no suspend to RAM support at DSA level yet, the switch configuration
6991 * would be lost after a power cycle so prevent it to be suspended.
6992 */
mv88e6xxx_suspend(struct device * dev)6993 static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
6994 {
6995 return -EOPNOTSUPP;
6996 }
6997
mv88e6xxx_resume(struct device * dev)6998 static int __maybe_unused mv88e6xxx_resume(struct device *dev)
6999 {
7000 return 0;
7001 }
7002
7003 static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
7004
mv88e6xxx_probe(struct mdio_device * mdiodev)7005 static int mv88e6xxx_probe(struct mdio_device *mdiodev)
7006 {
7007 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
7008 const struct mv88e6xxx_info *compat_info = NULL;
7009 struct device *dev = &mdiodev->dev;
7010 struct device_node *np = dev->of_node;
7011 struct mv88e6xxx_chip *chip;
7012 int port;
7013 int err;
7014
7015 if (!np && !pdata)
7016 return -EINVAL;
7017
7018 if (np)
7019 compat_info = of_device_get_match_data(dev);
7020
7021 if (pdata) {
7022 compat_info = pdata_device_get_match_data(dev);
7023
7024 if (!pdata->netdev)
7025 return -EINVAL;
7026
7027 for (port = 0; port < DSA_MAX_PORTS; port++) {
7028 if (!(pdata->enabled_ports & (1 << port)))
7029 continue;
7030 if (strcmp(pdata->cd.port_names[port], "cpu"))
7031 continue;
7032 pdata->cd.netdev[port] = &pdata->netdev->dev;
7033 break;
7034 }
7035 }
7036
7037 if (!compat_info)
7038 return -EINVAL;
7039
7040 chip = mv88e6xxx_alloc_chip(dev);
7041 if (!chip) {
7042 err = -ENOMEM;
7043 goto out;
7044 }
7045
7046 chip->info = compat_info;
7047
7048 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
7049 if (IS_ERR(chip->reset)) {
7050 err = PTR_ERR(chip->reset);
7051 goto out;
7052 }
7053 if (chip->reset)
7054 usleep_range(1000, 2000);
7055
7056 /* Detect if the device is configured in single chip addressing mode,
7057 * otherwise continue with address specific smi init/detection.
7058 */
7059 err = mv88e6xxx_single_chip_detect(chip, mdiodev);
7060 if (err) {
7061 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
7062 if (err)
7063 goto out;
7064
7065 err = mv88e6xxx_detect(chip);
7066 if (err)
7067 goto out;
7068 }
7069
7070 if (chip->info->edsa_support == MV88E6XXX_EDSA_SUPPORTED)
7071 chip->tag_protocol = DSA_TAG_PROTO_EDSA;
7072 else
7073 chip->tag_protocol = DSA_TAG_PROTO_DSA;
7074
7075 mv88e6xxx_phy_init(chip);
7076
7077 if (chip->info->ops->get_eeprom) {
7078 if (np)
7079 of_property_read_u32(np, "eeprom-length",
7080 &chip->eeprom_len);
7081 else
7082 chip->eeprom_len = pdata->eeprom_len;
7083 }
7084
7085 mv88e6xxx_reg_lock(chip);
7086 err = mv88e6xxx_switch_reset(chip);
7087 mv88e6xxx_reg_unlock(chip);
7088 if (err)
7089 goto out;
7090
7091 if (np) {
7092 chip->irq = of_irq_get(np, 0);
7093 if (chip->irq == -EPROBE_DEFER) {
7094 err = chip->irq;
7095 goto out;
7096 }
7097 }
7098
7099 if (pdata)
7100 chip->irq = pdata->irq;
7101
7102 /* Has to be performed before the MDIO bus is created, because
7103 * the PHYs will link their interrupts to these interrupt
7104 * controllers
7105 */
7106 mv88e6xxx_reg_lock(chip);
7107 if (chip->irq > 0)
7108 err = mv88e6xxx_g1_irq_setup(chip);
7109 else
7110 err = mv88e6xxx_irq_poll_setup(chip);
7111 mv88e6xxx_reg_unlock(chip);
7112
7113 if (err)
7114 goto out;
7115
7116 if (chip->info->g2_irqs > 0) {
7117 err = mv88e6xxx_g2_irq_setup(chip);
7118 if (err)
7119 goto out_g1_irq;
7120 }
7121
7122 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
7123 if (err)
7124 goto out_g2_irq;
7125
7126 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
7127 if (err)
7128 goto out_g1_atu_prob_irq;
7129
7130 err = mv88e6xxx_mdios_register(chip, np);
7131 if (err)
7132 goto out_g1_vtu_prob_irq;
7133
7134 err = mv88e6xxx_register_switch(chip);
7135 if (err)
7136 goto out_mdio;
7137
7138 return 0;
7139
7140 out_mdio:
7141 mv88e6xxx_mdios_unregister(chip);
7142 out_g1_vtu_prob_irq:
7143 mv88e6xxx_g1_vtu_prob_irq_free(chip);
7144 out_g1_atu_prob_irq:
7145 mv88e6xxx_g1_atu_prob_irq_free(chip);
7146 out_g2_irq:
7147 if (chip->info->g2_irqs > 0)
7148 mv88e6xxx_g2_irq_free(chip);
7149 out_g1_irq:
7150 if (chip->irq > 0)
7151 mv88e6xxx_g1_irq_free(chip);
7152 else
7153 mv88e6xxx_irq_poll_free(chip);
7154 out:
7155 if (pdata)
7156 dev_put(pdata->netdev);
7157
7158 return err;
7159 }
7160
mv88e6xxx_remove(struct mdio_device * mdiodev)7161 static void mv88e6xxx_remove(struct mdio_device *mdiodev)
7162 {
7163 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
7164 struct mv88e6xxx_chip *chip;
7165
7166 if (!ds)
7167 return;
7168
7169 chip = ds->priv;
7170
7171 if (chip->info->ptp_support) {
7172 mv88e6xxx_hwtstamp_free(chip);
7173 mv88e6xxx_ptp_free(chip);
7174 }
7175
7176 mv88e6xxx_phy_destroy(chip);
7177 mv88e6xxx_unregister_switch(chip);
7178 mv88e6xxx_mdios_unregister(chip);
7179
7180 mv88e6xxx_g1_vtu_prob_irq_free(chip);
7181 mv88e6xxx_g1_atu_prob_irq_free(chip);
7182
7183 if (chip->info->g2_irqs > 0)
7184 mv88e6xxx_g2_irq_free(chip);
7185
7186 if (chip->irq > 0)
7187 mv88e6xxx_g1_irq_free(chip);
7188 else
7189 mv88e6xxx_irq_poll_free(chip);
7190 }
7191
mv88e6xxx_shutdown(struct mdio_device * mdiodev)7192 static void mv88e6xxx_shutdown(struct mdio_device *mdiodev)
7193 {
7194 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
7195
7196 if (!ds)
7197 return;
7198
7199 dsa_switch_shutdown(ds);
7200
7201 dev_set_drvdata(&mdiodev->dev, NULL);
7202 }
7203
7204 static const struct of_device_id mv88e6xxx_of_match[] = {
7205 {
7206 .compatible = "marvell,mv88e6085",
7207 .data = &mv88e6xxx_table[MV88E6085],
7208 },
7209 {
7210 .compatible = "marvell,mv88e6190",
7211 .data = &mv88e6xxx_table[MV88E6190],
7212 },
7213 {
7214 .compatible = "marvell,mv88e6250",
7215 .data = &mv88e6xxx_table[MV88E6250],
7216 },
7217 { /* sentinel */ },
7218 };
7219
7220 MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
7221
7222 static struct mdio_driver mv88e6xxx_driver = {
7223 .probe = mv88e6xxx_probe,
7224 .remove = mv88e6xxx_remove,
7225 .shutdown = mv88e6xxx_shutdown,
7226 .mdiodrv.driver = {
7227 .name = "mv88e6085",
7228 .of_match_table = mv88e6xxx_of_match,
7229 .pm = &mv88e6xxx_pm_ops,
7230 },
7231 };
7232
7233 mdio_module_driver(mv88e6xxx_driver);
7234
7235 MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
7236 MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
7237 MODULE_LICENSE("GPL");
7238