blob: d7b29792732b70267f156ecee1a903dd1fec7394 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00002/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04003 * Marvell 88e6xxx Ethernet switch single-chip support
4 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00005 * Copyright (c) 2008 Marvell Semiconductor
6 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02007 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
8 *
Vivien Didelot4333d612017-03-28 15:10:36 -04009 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
10 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 */
12
Vivien Didelot19fb7f62019-08-09 18:47:55 -040013#include <linux/bitfield.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000014#include <linux/delay.h>
Vladimir Oltean5bded822021-10-07 19:47:11 +030015#include <linux/dsa/mv88e6xxx.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070016#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020017#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070018#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020019#include <linux/interrupt.h>
20#include <linux/irq.h>
21#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000022#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000023#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020024#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000025#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040026#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020027#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020028#include <linux/of_mdio.h>
Andrew Lunn877b7cb2018-05-19 22:31:34 +020029#include <linux/platform_data/mv88e6xxx.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000030#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010031#include <linux/gpio/consumer.h>
Russell Kingc9a23562018-05-10 13:17:35 -070032#include <linux/phylink.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000033#include <net/dsa.h>
Vivien Didelotec561272016-09-02 14:45:33 -040034
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -040035#include "chip.h"
Andrew Lunn9dd43aa2020-09-18 21:11:05 +020036#include "devlink.h"
Vivien Didelota935c052016-09-29 12:21:53 -040037#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040038#include "global2.h"
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +010039#include "hwtstamp.h"
Andrew Lunn10fa5bf2017-05-26 01:03:20 +020040#include "phy.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010041#include "port.h"
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +010042#include "ptp.h"
Andrew Lunn6d917822017-05-26 01:03:21 +020043#include "serdes.h"
Vivien Didelote7ba0fa2019-05-03 19:28:22 -040044#include "smi.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000045
Vivien Didelotfad09c72016-06-21 12:28:20 -040046static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040047{
Vivien Didelotfad09c72016-06-21 12:28:20 -040048 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
49 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040050 dump_stack();
51 }
52}
53
Vivien Didelotec561272016-09-02 14:45:33 -040054int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -040055{
56 int err;
57
Vivien Didelotfad09c72016-06-21 12:28:20 -040058 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -040059
Vivien Didelotfad09c72016-06-21 12:28:20 -040060 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040061 if (err)
62 return err;
63
Vivien Didelotfad09c72016-06-21 12:28:20 -040064 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -040065 addr, reg, *val);
66
67 return 0;
68}
69
Vivien Didelotec561272016-09-02 14:45:33 -040070int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -040071{
72 int err;
73
Vivien Didelotfad09c72016-06-21 12:28:20 -040074 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -040075
Vivien Didelotfad09c72016-06-21 12:28:20 -040076 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040077 if (err)
78 return err;
79
Vivien Didelotfad09c72016-06-21 12:28:20 -040080 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -040081 addr, reg, val);
82
83 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000084}
85
Vivien Didelot683f2242019-08-09 18:47:54 -040086int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg,
87 u16 mask, u16 val)
88{
89 u16 data;
90 int err;
91 int i;
92
93 /* There's no bus specific operation to wait for a mask */
94 for (i = 0; i < 16; i++) {
95 err = mv88e6xxx_read(chip, addr, reg, &data);
96 if (err)
97 return err;
98
99 if ((data & mask) == val)
100 return 0;
101
102 usleep_range(1000, 2000);
103 }
104
105 dev_err(chip->dev, "Timeout while waiting for switch\n");
106 return -ETIMEDOUT;
107}
108
Vivien Didelot19fb7f62019-08-09 18:47:55 -0400109int mv88e6xxx_wait_bit(struct mv88e6xxx_chip *chip, int addr, int reg,
110 int bit, int val)
111{
112 return mv88e6xxx_wait_mask(chip, addr, reg, BIT(bit),
113 val ? BIT(bit) : 0x0000);
114}
115
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200116struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
Andrew Lunna3c53be52017-01-24 14:53:50 +0100117{
118 struct mv88e6xxx_mdio_bus *mdio_bus;
119
120 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
121 list);
122 if (!mdio_bus)
123 return NULL;
124
125 return mdio_bus->bus;
126}
127
Andrew Lunndc30c352016-10-16 19:56:49 +0200128static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
129{
130 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
131 unsigned int n = d->hwirq;
132
133 chip->g1_irq.masked |= (1 << n);
134}
135
136static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
137{
138 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
139 unsigned int n = d->hwirq;
140
141 chip->g1_irq.masked &= ~(1 << n);
142}
143
Andrew Lunn294d7112018-02-22 22:58:32 +0100144static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200145{
Andrew Lunndc30c352016-10-16 19:56:49 +0200146 unsigned int nhandled = 0;
147 unsigned int sub_irq;
148 unsigned int n;
149 u16 reg;
John David Anglin7c0db242019-02-11 13:40:21 -0500150 u16 ctl1;
Andrew Lunndc30c352016-10-16 19:56:49 +0200151 int err;
152
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000153 mv88e6xxx_reg_lock(chip);
Vivien Didelot82466922017-06-15 12:13:59 -0400154 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000155 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200156
157 if (err)
158 goto out;
159
John David Anglin7c0db242019-02-11 13:40:21 -0500160 do {
161 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
162 if (reg & (1 << n)) {
163 sub_irq = irq_find_mapping(chip->g1_irq.domain,
164 n);
165 handle_nested_irq(sub_irq);
166 ++nhandled;
167 }
Andrew Lunndc30c352016-10-16 19:56:49 +0200168 }
John David Anglin7c0db242019-02-11 13:40:21 -0500169
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000170 mv88e6xxx_reg_lock(chip);
John David Anglin7c0db242019-02-11 13:40:21 -0500171 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1);
172 if (err)
173 goto unlock;
174 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
175unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000176 mv88e6xxx_reg_unlock(chip);
John David Anglin7c0db242019-02-11 13:40:21 -0500177 if (err)
178 goto out;
179 ctl1 &= GENMASK(chip->g1_irq.nirqs, 0);
180 } while (reg & ctl1);
181
Andrew Lunndc30c352016-10-16 19:56:49 +0200182out:
183 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
184}
185
Andrew Lunn294d7112018-02-22 22:58:32 +0100186static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
187{
188 struct mv88e6xxx_chip *chip = dev_id;
189
190 return mv88e6xxx_g1_irq_thread_work(chip);
191}
192
Andrew Lunndc30c352016-10-16 19:56:49 +0200193static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
194{
195 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
196
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000197 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200198}
199
200static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
201{
202 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
203 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
204 u16 reg;
205 int err;
206
Vivien Didelotd77f4322017-06-15 12:14:03 -0400207 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200208 if (err)
209 goto out;
210
211 reg &= ~mask;
212 reg |= (~chip->g1_irq.masked & mask);
213
Vivien Didelotd77f4322017-06-15 12:14:03 -0400214 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200215 if (err)
216 goto out;
217
218out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000219 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200220}
221
Bhumika Goyal6eb15e22017-08-19 16:25:52 +0530222static const struct irq_chip mv88e6xxx_g1_irq_chip = {
Andrew Lunndc30c352016-10-16 19:56:49 +0200223 .name = "mv88e6xxx-g1",
224 .irq_mask = mv88e6xxx_g1_irq_mask,
225 .irq_unmask = mv88e6xxx_g1_irq_unmask,
226 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
227 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
228};
229
230static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
231 unsigned int irq,
232 irq_hw_number_t hwirq)
233{
234 struct mv88e6xxx_chip *chip = d->host_data;
235
236 irq_set_chip_data(irq, d->host_data);
237 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
238 irq_set_noprobe(irq);
239
240 return 0;
241}
242
243static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
244 .map = mv88e6xxx_g1_irq_domain_map,
245 .xlate = irq_domain_xlate_twocell,
246};
247
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200248/* To be called with reg_lock held */
Andrew Lunn294d7112018-02-22 22:58:32 +0100249static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200250{
251 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100252 u16 mask;
253
Vivien Didelotd77f4322017-06-15 12:14:03 -0400254 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100255 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400256 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100257
Andreas Färber5edef2f2016-11-27 23:26:28 +0100258 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100259 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200260 irq_dispose_mapping(virq);
261 }
262
Andrew Lunna3db3d32016-11-20 20:14:14 +0100263 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200264}
265
Andrew Lunn294d7112018-02-22 22:58:32 +0100266static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
267{
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200268 /*
269 * free_irq must be called without reg_lock taken because the irq
270 * handler takes this lock, too.
271 */
Andrew Lunn294d7112018-02-22 22:58:32 +0100272 free_irq(chip->irq, chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200273
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000274 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200275 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000276 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100277}
278
279static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200280{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100281 int err, irq, virq;
282 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200283
284 chip->g1_irq.nirqs = chip->info->g1_irqs;
285 chip->g1_irq.domain = irq_domain_add_simple(
286 NULL, chip->g1_irq.nirqs, 0,
287 &mv88e6xxx_g1_irq_domain_ops, chip);
288 if (!chip->g1_irq.domain)
289 return -ENOMEM;
290
291 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
292 irq_create_mapping(chip->g1_irq.domain, irq);
293
294 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
295 chip->g1_irq.masked = ~0;
296
Vivien Didelotd77f4322017-06-15 12:14:03 -0400297 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200298 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100299 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200300
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100301 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200302
Vivien Didelotd77f4322017-06-15 12:14:03 -0400303 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200304 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100305 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200306
307 /* Reading the interrupt status clears (most of) them */
Vivien Didelot82466922017-06-15 12:13:59 -0400308 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200309 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100310 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200311
Andrew Lunndc30c352016-10-16 19:56:49 +0200312 return 0;
313
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100314out_disable:
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100315 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400316 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100317
318out_mapping:
319 for (irq = 0; irq < 16; irq++) {
320 virq = irq_find_mapping(chip->g1_irq.domain, irq);
321 irq_dispose_mapping(virq);
322 }
323
324 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200325
326 return err;
327}
328
Andrew Lunn294d7112018-02-22 22:58:32 +0100329static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
330{
Andrew Lunnf6d97582019-02-23 17:43:56 +0100331 static struct lock_class_key lock_key;
332 static struct lock_class_key request_key;
Andrew Lunn294d7112018-02-22 22:58:32 +0100333 int err;
334
335 err = mv88e6xxx_g1_irq_setup_common(chip);
336 if (err)
337 return err;
338
Andrew Lunnf6d97582019-02-23 17:43:56 +0100339 /* These lock classes tells lockdep that global 1 irqs are in
340 * a different category than their parent GPIO, so it won't
341 * report false recursion.
342 */
343 irq_set_lockdep_class(chip->irq, &lock_key, &request_key);
344
Andrew Lunn30953832020-01-06 17:13:48 +0100345 snprintf(chip->irq_name, sizeof(chip->irq_name),
346 "mv88e6xxx-%s", dev_name(chip->dev));
347
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000348 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100349 err = request_threaded_irq(chip->irq, NULL,
350 mv88e6xxx_g1_irq_thread_fn,
Marek Behún03403762018-08-30 02:13:50 +0200351 IRQF_ONESHOT | IRQF_SHARED,
Andrew Lunn30953832020-01-06 17:13:48 +0100352 chip->irq_name, chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000353 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100354 if (err)
355 mv88e6xxx_g1_irq_free_common(chip);
356
357 return err;
358}
359
360static void mv88e6xxx_irq_poll(struct kthread_work *work)
361{
362 struct mv88e6xxx_chip *chip = container_of(work,
363 struct mv88e6xxx_chip,
364 irq_poll_work.work);
365 mv88e6xxx_g1_irq_thread_work(chip);
366
367 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
368 msecs_to_jiffies(100));
369}
370
371static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
372{
373 int err;
374
375 err = mv88e6xxx_g1_irq_setup_common(chip);
376 if (err)
377 return err;
378
379 kthread_init_delayed_work(&chip->irq_poll_work,
380 mv88e6xxx_irq_poll);
381
Florian Fainelli3f8b8692019-02-21 20:09:27 -0800382 chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
Andrew Lunn294d7112018-02-22 22:58:32 +0100383 if (IS_ERR(chip->kworker))
384 return PTR_ERR(chip->kworker);
385
386 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
387 msecs_to_jiffies(100));
388
389 return 0;
390}
391
392static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
393{
394 kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
395 kthread_destroy_worker(chip->kworker);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200396
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000397 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200398 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000399 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100400}
401
Russell King64d47d52020-03-14 10:15:38 +0000402static int mv88e6xxx_port_config_interface(struct mv88e6xxx_chip *chip,
403 int port, phy_interface_t interface)
404{
405 int err;
406
407 if (chip->info->ops->port_set_rgmii_delay) {
408 err = chip->info->ops->port_set_rgmii_delay(chip, port,
409 interface);
410 if (err && err != -EOPNOTSUPP)
411 return err;
412 }
413
414 if (chip->info->ops->port_set_cmode) {
415 err = chip->info->ops->port_set_cmode(chip, port,
416 interface);
417 if (err && err != -EOPNOTSUPP)
418 return err;
419 }
420
421 return 0;
422}
423
Russell Kinga5a68582020-03-14 10:15:43 +0000424static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
425 int link, int speed, int duplex, int pause,
426 phy_interface_t mode)
Vivien Didelotd78343d2016-11-04 03:23:36 +0100427{
428 int err;
429
430 if (!chip->info->ops->port_set_link)
431 return 0;
432
433 /* Port's MAC control must not be changed unless the link is down */
Hubert Feurstein43c8e0a2019-07-30 12:11:42 +0200434 err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100435 if (err)
436 return err;
437
Russell Kingf365c6f2020-03-14 10:15:53 +0000438 if (chip->info->ops->port_set_speed_duplex) {
439 err = chip->info->ops->port_set_speed_duplex(chip, port,
440 speed, duplex);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100441 if (err && err != -EOPNOTSUPP)
442 goto restore_link;
443 }
444
Andrew Lunn7cbbee02019-03-08 01:21:27 +0100445 if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
446 mode = chip->info->ops->port_max_speed_mode(port);
447
Andrew Lunn54186b92018-08-09 15:38:37 +0200448 if (chip->info->ops->port_set_pause) {
449 err = chip->info->ops->port_set_pause(chip, port, pause);
450 if (err)
451 goto restore_link;
452 }
453
Russell King64d47d52020-03-14 10:15:38 +0000454 err = mv88e6xxx_port_config_interface(chip, port, mode);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100455restore_link:
456 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400457 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100458
459 return err;
460}
461
Marek Vasutd700ec42018-09-12 00:15:24 +0200462static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
463{
464 struct mv88e6xxx_chip *chip = ds->priv;
465
466 return port < chip->info->num_internal_phys;
467}
468
Russell King5d5b2312020-03-14 10:16:03 +0000469static int mv88e6xxx_port_ppu_updates(struct mv88e6xxx_chip *chip, int port)
470{
471 u16 reg;
472 int err;
473
474 err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
475 if (err) {
476 dev_err(chip->dev,
477 "p%d: %s: failed to read port status\n",
478 port, __func__);
479 return err;
480 }
481
482 return !!(reg & MV88E6XXX_PORT_STS_PHY_DETECT);
483}
484
Russell Kinga5a68582020-03-14 10:15:43 +0000485static int mv88e6xxx_serdes_pcs_get_state(struct dsa_switch *ds, int port,
486 struct phylink_link_state *state)
487{
488 struct mv88e6xxx_chip *chip = ds->priv;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100489 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000490 int err;
491
492 mv88e6xxx_reg_lock(chip);
493 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100494 if (lane >= 0 && chip->info->ops->serdes_pcs_get_state)
Russell Kinga5a68582020-03-14 10:15:43 +0000495 err = chip->info->ops->serdes_pcs_get_state(chip, port, lane,
496 state);
497 else
498 err = -EOPNOTSUPP;
499 mv88e6xxx_reg_unlock(chip);
500
501 return err;
502}
503
504static int mv88e6xxx_serdes_pcs_config(struct mv88e6xxx_chip *chip, int port,
505 unsigned int mode,
506 phy_interface_t interface,
507 const unsigned long *advertise)
508{
509 const struct mv88e6xxx_ops *ops = chip->info->ops;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100510 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000511
512 if (ops->serdes_pcs_config) {
513 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100514 if (lane >= 0)
Russell Kinga5a68582020-03-14 10:15:43 +0000515 return ops->serdes_pcs_config(chip, port, lane, mode,
516 interface, advertise);
517 }
518
519 return 0;
520}
521
522static void mv88e6xxx_serdes_pcs_an_restart(struct dsa_switch *ds, int port)
523{
524 struct mv88e6xxx_chip *chip = ds->priv;
525 const struct mv88e6xxx_ops *ops;
526 int err = 0;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100527 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000528
529 ops = chip->info->ops;
530
531 if (ops->serdes_pcs_an_restart) {
532 mv88e6xxx_reg_lock(chip);
533 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100534 if (lane >= 0)
Russell Kinga5a68582020-03-14 10:15:43 +0000535 err = ops->serdes_pcs_an_restart(chip, port, lane);
536 mv88e6xxx_reg_unlock(chip);
537
538 if (err)
539 dev_err(ds->dev, "p%d: failed to restart AN\n", port);
540 }
541}
542
543static int mv88e6xxx_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port,
544 unsigned int mode,
545 int speed, int duplex)
546{
547 const struct mv88e6xxx_ops *ops = chip->info->ops;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100548 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000549
550 if (!phylink_autoneg_inband(mode) && ops->serdes_pcs_link_up) {
551 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100552 if (lane >= 0)
Russell Kinga5a68582020-03-14 10:15:43 +0000553 return ops->serdes_pcs_link_up(chip, port, lane,
554 speed, duplex);
555 }
556
557 return 0;
558}
559
Russell King6c422e32018-08-09 15:38:39 +0200560static void mv88e6065_phylink_validate(struct mv88e6xxx_chip *chip, int port,
561 unsigned long *mask,
562 struct phylink_link_state *state)
563{
564 if (!phy_interface_mode_is_8023z(state->interface)) {
565 /* 10M and 100M are only supported in non-802.3z mode */
566 phylink_set(mask, 10baseT_Half);
567 phylink_set(mask, 10baseT_Full);
568 phylink_set(mask, 100baseT_Half);
569 phylink_set(mask, 100baseT_Full);
570 }
571}
572
573static void mv88e6185_phylink_validate(struct mv88e6xxx_chip *chip, int port,
574 unsigned long *mask,
575 struct phylink_link_state *state)
576{
577 /* FIXME: if the port is in 1000Base-X mode, then it only supports
578 * 1000M FD speeds. In this case, CMODE will indicate 5.
579 */
580 phylink_set(mask, 1000baseT_Full);
581 phylink_set(mask, 1000baseX_Full);
582
583 mv88e6065_phylink_validate(chip, port, mask, state);
584}
585
Marek Behúne3af71a2019-02-25 12:39:55 +0100586static void mv88e6341_phylink_validate(struct mv88e6xxx_chip *chip, int port,
587 unsigned long *mask,
588 struct phylink_link_state *state)
589{
590 if (port >= 5)
591 phylink_set(mask, 2500baseX_Full);
592
593 /* No ethtool bits for 200Mbps */
594 phylink_set(mask, 1000baseT_Full);
595 phylink_set(mask, 1000baseX_Full);
596
597 mv88e6065_phylink_validate(chip, port, mask, state);
598}
599
Russell King6c422e32018-08-09 15:38:39 +0200600static void mv88e6352_phylink_validate(struct mv88e6xxx_chip *chip, int port,
601 unsigned long *mask,
602 struct phylink_link_state *state)
603{
604 /* No ethtool bits for 200Mbps */
605 phylink_set(mask, 1000baseT_Full);
606 phylink_set(mask, 1000baseX_Full);
607
608 mv88e6065_phylink_validate(chip, port, mask, state);
609}
610
611static void mv88e6390_phylink_validate(struct mv88e6xxx_chip *chip, int port,
612 unsigned long *mask,
613 struct phylink_link_state *state)
614{
Andrew Lunnec260162019-02-08 22:25:44 +0100615 if (port >= 9) {
Russell King6c422e32018-08-09 15:38:39 +0200616 phylink_set(mask, 2500baseX_Full);
Andrew Lunnec260162019-02-08 22:25:44 +0100617 phylink_set(mask, 2500baseT_Full);
618 }
Russell King6c422e32018-08-09 15:38:39 +0200619
620 /* No ethtool bits for 200Mbps */
621 phylink_set(mask, 1000baseT_Full);
622 phylink_set(mask, 1000baseX_Full);
623
624 mv88e6065_phylink_validate(chip, port, mask, state);
625}
626
627static void mv88e6390x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
628 unsigned long *mask,
629 struct phylink_link_state *state)
630{
631 if (port >= 9) {
632 phylink_set(mask, 10000baseT_Full);
633 phylink_set(mask, 10000baseKR_Full);
634 }
635
636 mv88e6390_phylink_validate(chip, port, mask, state);
637}
638
Pavana Sharmade776d02021-03-17 14:46:42 +0100639static void mv88e6393x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
640 unsigned long *mask,
641 struct phylink_link_state *state)
642{
643 if (port == 0 || port == 9 || port == 10) {
644 phylink_set(mask, 10000baseT_Full);
645 phylink_set(mask, 10000baseKR_Full);
646 phylink_set(mask, 10000baseCR_Full);
647 phylink_set(mask, 10000baseSR_Full);
648 phylink_set(mask, 10000baseLR_Full);
649 phylink_set(mask, 10000baseLRM_Full);
650 phylink_set(mask, 10000baseER_Full);
651 phylink_set(mask, 5000baseT_Full);
652 phylink_set(mask, 2500baseX_Full);
653 phylink_set(mask, 2500baseT_Full);
654 }
655
656 phylink_set(mask, 1000baseT_Full);
657 phylink_set(mask, 1000baseX_Full);
658
659 mv88e6065_phylink_validate(chip, port, mask, state);
660}
661
Russell Kingc9a23562018-05-10 13:17:35 -0700662static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
663 unsigned long *supported,
664 struct phylink_link_state *state)
665{
Russell King6c422e32018-08-09 15:38:39 +0200666 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
667 struct mv88e6xxx_chip *chip = ds->priv;
668
669 /* Allow all the expected bits */
670 phylink_set(mask, Autoneg);
671 phylink_set(mask, Pause);
672 phylink_set_port_modes(mask);
673
674 if (chip->info->ops->phylink_validate)
675 chip->info->ops->phylink_validate(chip, port, mask, state);
676
677 bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
678 bitmap_and(state->advertising, state->advertising, mask,
679 __ETHTOOL_LINK_MODE_MASK_NBITS);
680
681 /* We can only operate at 2500BaseX or 1000BaseX. If requested
682 * to advertise both, only report advertising at 2500BaseX.
683 */
684 phylink_helper_basex_speed(state);
Russell Kingc9a23562018-05-10 13:17:35 -0700685}
686
Russell Kingc9a23562018-05-10 13:17:35 -0700687static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
688 unsigned int mode,
689 const struct phylink_link_state *state)
690{
691 struct mv88e6xxx_chip *chip = ds->priv;
Russell Kingfad58192020-07-19 12:00:35 +0100692 struct mv88e6xxx_port *p;
Russell King64d47d52020-03-14 10:15:38 +0000693 int err;
Russell Kingc9a23562018-05-10 13:17:35 -0700694
Russell Kingfad58192020-07-19 12:00:35 +0100695 p = &chip->ports[port];
696
Russell King64d47d52020-03-14 10:15:38 +0000697 /* FIXME: is this the correct test? If we're in fixed mode on an
698 * internal port, why should we process this any different from
699 * PHY mode? On the other hand, the port may be automedia between
700 * an internal PHY and the serdes...
701 */
Marek Vasutd700ec42018-09-12 00:15:24 +0200702 if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
Russell Kingc9a23562018-05-10 13:17:35 -0700703 return;
704
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000705 mv88e6xxx_reg_lock(chip);
Russell Kingfad58192020-07-19 12:00:35 +0100706 /* In inband mode, the link may come up at any time while the link
707 * is not forced down. Force the link down while we reconfigure the
708 * interface mode.
Russell King64d47d52020-03-14 10:15:38 +0000709 */
Russell Kingfad58192020-07-19 12:00:35 +0100710 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
711 chip->info->ops->port_set_link)
712 chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
713
Russell King64d47d52020-03-14 10:15:38 +0000714 err = mv88e6xxx_port_config_interface(chip, port, state->interface);
Russell Kinga5a68582020-03-14 10:15:43 +0000715 if (err && err != -EOPNOTSUPP)
716 goto err_unlock;
717
718 err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
719 state->advertising);
720 /* FIXME: we should restart negotiation if something changed - which
721 * is something we get if we convert to using phylinks PCS operations.
722 */
723 if (err > 0)
724 err = 0;
725
Russell Kingfad58192020-07-19 12:00:35 +0100726 /* Undo the forced down state above after completing configuration
727 * irrespective of its state on entry, which allows the link to come up.
728 */
729 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
730 chip->info->ops->port_set_link)
731 chip->info->ops->port_set_link(chip, port, LINK_UNFORCED);
732
733 p->interface = state->interface;
734
Russell Kinga5a68582020-03-14 10:15:43 +0000735err_unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000736 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700737
738 if (err && err != -EOPNOTSUPP)
Russell King64d47d52020-03-14 10:15:38 +0000739 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700740}
741
Russell Kingc9a23562018-05-10 13:17:35 -0700742static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
743 unsigned int mode,
744 phy_interface_t interface)
745{
Russell King30c4a5b2020-02-26 10:23:51 +0000746 struct mv88e6xxx_chip *chip = ds->priv;
747 const struct mv88e6xxx_ops *ops;
748 int err = 0;
749
750 ops = chip->info->ops;
751
Russell King5d5b2312020-03-14 10:16:03 +0000752 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200753 if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
Chris Packham4efe76622020-11-24 17:34:37 +1300754 mode == MLO_AN_FIXED) && ops->port_sync_link)
755 err = ops->port_sync_link(chip, port, mode, false);
Russell King5d5b2312020-03-14 10:16:03 +0000756 mv88e6xxx_reg_unlock(chip);
Russell King30c4a5b2020-02-26 10:23:51 +0000757
Russell King5d5b2312020-03-14 10:16:03 +0000758 if (err)
759 dev_err(chip->dev,
760 "p%d: failed to force MAC link down\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700761}
762
763static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
764 unsigned int mode, phy_interface_t interface,
Russell King5b502a72020-02-26 10:23:46 +0000765 struct phy_device *phydev,
766 int speed, int duplex,
767 bool tx_pause, bool rx_pause)
Russell Kingc9a23562018-05-10 13:17:35 -0700768{
Russell King30c4a5b2020-02-26 10:23:51 +0000769 struct mv88e6xxx_chip *chip = ds->priv;
770 const struct mv88e6xxx_ops *ops;
771 int err = 0;
772
773 ops = chip->info->ops;
774
Russell King5d5b2312020-03-14 10:16:03 +0000775 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200776 if (!mv88e6xxx_port_ppu_updates(chip, port) || mode == MLO_AN_FIXED) {
Russell King30c4a5b2020-02-26 10:23:51 +0000777 /* FIXME: for an automedia port, should we force the link
778 * down here - what if the link comes up due to "other" media
779 * while we're bringing the port up, how is the exclusivity
Russell Kinga5a68582020-03-14 10:15:43 +0000780 * handled in the Marvell hardware? E.g. port 2 on 88E6390
Russell King30c4a5b2020-02-26 10:23:51 +0000781 * shared between internal PHY and Serdes.
782 */
Russell Kinga5a68582020-03-14 10:15:43 +0000783 err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
784 duplex);
785 if (err)
786 goto error;
787
Russell Kingf365c6f2020-03-14 10:15:53 +0000788 if (ops->port_set_speed_duplex) {
789 err = ops->port_set_speed_duplex(chip, port,
790 speed, duplex);
Russell King30c4a5b2020-02-26 10:23:51 +0000791 if (err && err != -EOPNOTSUPP)
792 goto error;
793 }
794
Chris Packham4efe76622020-11-24 17:34:37 +1300795 if (ops->port_sync_link)
796 err = ops->port_sync_link(chip, port, mode, true);
Russell King30c4a5b2020-02-26 10:23:51 +0000797 }
Russell King5d5b2312020-03-14 10:16:03 +0000798error:
799 mv88e6xxx_reg_unlock(chip);
800
801 if (err && err != -EOPNOTSUPP)
802 dev_err(ds->dev,
803 "p%d: failed to configure MAC link up\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700804}
805
Andrew Lunna605a0f2016-11-21 23:26:58 +0100806static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000807{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100808 if (!chip->info->ops->stats_snapshot)
809 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000810
Andrew Lunna605a0f2016-11-21 23:26:58 +0100811 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000812}
813
Andrew Lunne413e7e2015-04-02 04:06:38 +0200814static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100815 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
816 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
817 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
818 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
819 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
820 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
821 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
822 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
823 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
824 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
825 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
826 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
827 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
828 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
829 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
830 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
831 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
832 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
833 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
834 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
835 { "single", 4, 0x14, STATS_TYPE_BANK0, },
836 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
837 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
838 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
839 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
840 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
841 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
842 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
843 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
844 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
845 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
846 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
847 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
848 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
849 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
850 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
851 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
852 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
853 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
854 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
855 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
856 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
857 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
858 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
859 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
860 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
861 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
862 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
863 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
864 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
865 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
866 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
867 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
868 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
869 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
870 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
871 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
872 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
873 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200874};
875
Vivien Didelotfad09c72016-06-21 12:28:20 -0400876static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100877 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100878 int port, u16 bank1_select,
879 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200880{
Andrew Lunn80c46272015-06-20 18:42:30 +0200881 u32 low;
882 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100883 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200884 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200885 u64 value;
886
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100887 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100888 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200889 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
890 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800891 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200892
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200893 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100894 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200895 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
896 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800897 return U64_MAX;
Rasmus Villemoes84b3fd12019-05-29 07:02:11 +0000898 low |= ((u32)reg) << 16;
Andrew Lunn80c46272015-06-20 18:42:30 +0200899 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100900 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100901 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100902 reg = bank1_select;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500903 fallthrough;
Andrew Lunndfafe442016-11-21 23:27:02 +0100904 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100905 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100906 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100907 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100908 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500909 break;
910 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800911 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200912 }
Andrew Lunn6e46e2d2019-02-28 18:14:03 +0100913 value = (((u64)high) << 32) | low;
Andrew Lunn80c46272015-06-20 18:42:30 +0200914 return value;
915}
916
Andrew Lunn436fe172018-03-01 02:02:29 +0100917static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
918 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100919{
920 struct mv88e6xxx_hw_stat *stat;
921 int i, j;
922
923 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
924 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100925 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100926 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
927 ETH_GSTRING_LEN);
928 j++;
929 }
930 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100931
932 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100933}
934
Andrew Lunn436fe172018-03-01 02:02:29 +0100935static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
936 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100937{
Andrew Lunn436fe172018-03-01 02:02:29 +0100938 return mv88e6xxx_stats_get_strings(chip, data,
939 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100940}
941
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000942static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
943 uint8_t *data)
944{
945 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
946}
947
Andrew Lunn436fe172018-03-01 02:02:29 +0100948static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
949 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100950{
Andrew Lunn436fe172018-03-01 02:02:29 +0100951 return mv88e6xxx_stats_get_strings(chip, data,
952 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100953}
954
Andrew Lunn65f60e42018-03-28 23:50:28 +0200955static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
956 "atu_member_violation",
957 "atu_miss_violation",
958 "atu_full_violation",
959 "vtu_member_violation",
960 "vtu_miss_violation",
961};
962
963static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
964{
965 unsigned int i;
966
967 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
968 strlcpy(data + i * ETH_GSTRING_LEN,
969 mv88e6xxx_atu_vtu_stats_strings[i],
970 ETH_GSTRING_LEN);
971}
972
Andrew Lunndfafe442016-11-21 23:27:02 +0100973static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700974 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100975{
Vivien Didelot04bed142016-08-31 18:06:13 -0400976 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100977 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100978
Florian Fainelli89f09042018-04-25 12:12:50 -0700979 if (stringset != ETH_SS_STATS)
980 return;
981
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000982 mv88e6xxx_reg_lock(chip);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100983
Andrew Lunndfafe442016-11-21 23:27:02 +0100984 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100985 count = chip->info->ops->stats_get_strings(chip, data);
986
987 if (chip->info->ops->serdes_get_strings) {
988 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200989 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100990 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100991
Andrew Lunn65f60e42018-03-28 23:50:28 +0200992 data += count * ETH_GSTRING_LEN;
993 mv88e6xxx_atu_vtu_get_strings(data);
994
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000995 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100996}
997
998static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
999 int types)
1000{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001001 struct mv88e6xxx_hw_stat *stat;
1002 int i, j;
1003
1004 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1005 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +01001006 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001007 j++;
1008 }
1009 return j;
1010}
1011
Andrew Lunndfafe442016-11-21 23:27:02 +01001012static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1013{
1014 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1015 STATS_TYPE_PORT);
1016}
1017
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001018static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1019{
1020 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
1021}
1022
Andrew Lunndfafe442016-11-21 23:27:02 +01001023static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1024{
1025 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1026 STATS_TYPE_BANK1);
1027}
1028
Florian Fainelli89f09042018-04-25 12:12:50 -07001029static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +01001030{
1031 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +01001032 int serdes_count = 0;
1033 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +01001034
Florian Fainelli89f09042018-04-25 12:12:50 -07001035 if (sset != ETH_SS_STATS)
1036 return 0;
1037
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001038 mv88e6xxx_reg_lock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001039 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +01001040 count = chip->info->ops->stats_get_sset_count(chip);
1041 if (count < 0)
1042 goto out;
1043
1044 if (chip->info->ops->serdes_get_sset_count)
1045 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1046 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +02001047 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +01001048 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001049 goto out;
1050 }
1051 count += serdes_count;
1052 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1053
Andrew Lunn436fe172018-03-01 02:02:29 +01001054out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001055 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001056
Andrew Lunn436fe172018-03-01 02:02:29 +01001057 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +01001058}
1059
Andrew Lunn436fe172018-03-01 02:02:29 +01001060static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1061 uint64_t *data, int types,
1062 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +01001063{
1064 struct mv88e6xxx_hw_stat *stat;
1065 int i, j;
1066
1067 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1068 stat = &mv88e6xxx_hw_stats[i];
1069 if (stat->type & types) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001070 mv88e6xxx_reg_lock(chip);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001071 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1072 bank1_select,
1073 histogram);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001074 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001075
Andrew Lunn052f9472016-11-21 23:27:03 +01001076 j++;
1077 }
1078 }
Andrew Lunn436fe172018-03-01 02:02:29 +01001079 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +01001080}
1081
Andrew Lunn436fe172018-03-01 02:02:29 +01001082static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1083 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001084{
1085 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001086 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001087 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +01001088}
1089
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001090static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1091 uint64_t *data)
1092{
1093 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
1094 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1095}
1096
Andrew Lunn436fe172018-03-01 02:02:29 +01001097static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1098 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001099{
1100 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001101 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001102 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1103 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001104}
1105
Andrew Lunn436fe172018-03-01 02:02:29 +01001106static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1107 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +01001108{
1109 return mv88e6xxx_stats_get_stats(chip, port, data,
1110 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001111 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1112 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001113}
1114
Andrew Lunn65f60e42018-03-28 23:50:28 +02001115static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1116 uint64_t *data)
1117{
1118 *data++ = chip->ports[port].atu_member_violation;
1119 *data++ = chip->ports[port].atu_miss_violation;
1120 *data++ = chip->ports[port].atu_full_violation;
1121 *data++ = chip->ports[port].vtu_member_violation;
1122 *data++ = chip->ports[port].vtu_miss_violation;
1123}
1124
Andrew Lunn052f9472016-11-21 23:27:03 +01001125static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1126 uint64_t *data)
1127{
Andrew Lunn436fe172018-03-01 02:02:29 +01001128 int count = 0;
1129
Andrew Lunn052f9472016-11-21 23:27:03 +01001130 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +01001131 count = chip->info->ops->stats_get_stats(chip, port, data);
1132
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001133 mv88e6xxx_reg_lock(chip);
Andrew Lunn436fe172018-03-01 02:02:29 +01001134 if (chip->info->ops->serdes_get_stats) {
1135 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001136 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +01001137 }
Andrew Lunn65f60e42018-03-28 23:50:28 +02001138 data += count;
1139 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001140 mv88e6xxx_reg_unlock(chip);
Andrew Lunn052f9472016-11-21 23:27:03 +01001141}
1142
Vivien Didelotf81ec902016-05-09 13:22:58 -04001143static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1144 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001145{
Vivien Didelot04bed142016-08-31 18:06:13 -04001146 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001147 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001148
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001149 mv88e6xxx_reg_lock(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001150
Andrew Lunna605a0f2016-11-21 23:26:58 +01001151 ret = mv88e6xxx_stats_snapshot(chip, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001152 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001153
1154 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001155 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001156
1157 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001158
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001159}
Ben Hutchings98e67302011-11-25 14:36:19 +00001160
Vivien Didelotf81ec902016-05-09 13:22:58 -04001161static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001162{
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001163 struct mv88e6xxx_chip *chip = ds->priv;
1164 int len;
1165
1166 len = 32 * sizeof(u16);
1167 if (chip->info->ops->serdes_get_regs_len)
1168 len += chip->info->ops->serdes_get_regs_len(chip, port);
1169
1170 return len;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001171}
1172
Vivien Didelotf81ec902016-05-09 13:22:58 -04001173static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1174 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001175{
Vivien Didelot04bed142016-08-31 18:06:13 -04001176 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001177 int err;
1178 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001179 u16 *p = _p;
1180 int i;
1181
Vivien Didelota5f39322018-12-17 16:05:21 -05001182 regs->version = chip->info->prod_num;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001183
1184 memset(p, 0xff, 32 * sizeof(u16));
1185
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001186 mv88e6xxx_reg_lock(chip);
Vivien Didelot23062512016-05-09 13:22:45 -04001187
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001188 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001189
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001190 err = mv88e6xxx_port_read(chip, port, i, &reg);
1191 if (!err)
1192 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001193 }
Vivien Didelot23062512016-05-09 13:22:45 -04001194
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001195 if (chip->info->ops->serdes_get_regs)
1196 chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1197
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001198 mv88e6xxx_reg_unlock(chip);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001199}
1200
Vivien Didelot08f50062017-08-01 16:32:41 -04001201static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1202 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001203{
Vivien Didelot5480db62017-08-01 16:32:40 -04001204 /* Nothing to do on the port's MAC */
1205 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001206}
1207
Vivien Didelot08f50062017-08-01 16:32:41 -04001208static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1209 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001210{
Vivien Didelot5480db62017-08-01 16:32:40 -04001211 /* Nothing to do on the port's MAC */
1212 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001213}
1214
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001215/* Mask of the local ports allowed to receive frames from a given fabric port */
Vivien Didelote5887a22017-03-30 17:37:11 -04001216static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001217{
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001218 struct dsa_switch *ds = chip->ds;
1219 struct dsa_switch_tree *dst = ds->dst;
Vivien Didelote5887a22017-03-30 17:37:11 -04001220 struct net_device *br;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001221 struct dsa_port *dp;
1222 bool found = false;
Vivien Didelote5887a22017-03-30 17:37:11 -04001223 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001224
Vladimir Olteance5df682021-07-22 18:55:41 +03001225 /* dev is a physical switch */
1226 if (dev <= dst->last_switch) {
1227 list_for_each_entry(dp, &dst->ports, list) {
1228 if (dp->ds->index == dev && dp->index == port) {
1229 /* dp might be a DSA link or a user port, so it
1230 * might or might not have a bridge_dev
1231 * pointer. Use the "found" variable for both
1232 * cases.
1233 */
1234 br = dp->bridge_dev;
1235 found = true;
1236 break;
1237 }
1238 }
1239 /* dev is a virtual bridge */
1240 } else {
1241 list_for_each_entry(dp, &dst->ports, list) {
1242 if (dp->bridge_num < 0)
1243 continue;
1244
1245 if (dp->bridge_num + 1 + dst->last_switch != dev)
1246 continue;
1247
1248 br = dp->bridge_dev;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001249 found = true;
1250 break;
1251 }
1252 }
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001253
Vladimir Olteance5df682021-07-22 18:55:41 +03001254 /* Prevent frames from unknown switch or virtual bridge */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001255 if (!found)
Vivien Didelote5887a22017-03-30 17:37:11 -04001256 return 0;
1257
1258 /* Frames from DSA links and CPU ports can egress any local port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001259 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
Vivien Didelote5887a22017-03-30 17:37:11 -04001260 return mv88e6xxx_port_mask(chip);
1261
Vivien Didelote5887a22017-03-30 17:37:11 -04001262 pvlan = 0;
1263
1264 /* Frames from user ports can egress any local DSA links and CPU ports,
1265 * as well as any local member of their bridge group.
1266 */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001267 list_for_each_entry(dp, &dst->ports, list)
1268 if (dp->ds == ds &&
1269 (dp->type == DSA_PORT_TYPE_CPU ||
1270 dp->type == DSA_PORT_TYPE_DSA ||
1271 (br && dp->bridge_dev == br)))
1272 pvlan |= BIT(dp->index);
Vivien Didelote5887a22017-03-30 17:37:11 -04001273
1274 return pvlan;
1275}
1276
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001277static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001278{
1279 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001280
1281 /* prevent frames from going back out of the port they came in on */
1282 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001283
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001284 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001285}
1286
Vivien Didelotf81ec902016-05-09 13:22:58 -04001287static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1288 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001289{
Vivien Didelot04bed142016-08-31 18:06:13 -04001290 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001291 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001292
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001293 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001294 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001295 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001296
1297 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001298 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001299}
1300
Vivien Didelot93e18d62018-05-11 17:16:35 -04001301static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1302{
1303 int err;
1304
1305 if (chip->info->ops->ieee_pri_map) {
1306 err = chip->info->ops->ieee_pri_map(chip);
1307 if (err)
1308 return err;
1309 }
1310
1311 if (chip->info->ops->ip_pri_map) {
1312 err = chip->info->ops->ip_pri_map(chip);
1313 if (err)
1314 return err;
1315 }
1316
1317 return 0;
1318}
1319
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001320static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1321{
Vivien Didelotc5f51762019-10-30 22:09:13 -04001322 struct dsa_switch *ds = chip->ds;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001323 int target, port;
1324 int err;
1325
1326 if (!chip->info->global2_addr)
1327 return 0;
1328
1329 /* Initialize the routing port to the 32 possible target devices */
1330 for (target = 0; target < 32; target++) {
Vivien Didelotc5f51762019-10-30 22:09:13 -04001331 port = dsa_routing_port(ds, target);
1332 if (port == ds->num_ports)
1333 port = 0x1f;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001334
1335 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1336 if (err)
1337 return err;
1338 }
1339
Vivien Didelot02317e62018-05-09 11:38:49 -04001340 if (chip->info->ops->set_cascade_port) {
1341 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1342 err = chip->info->ops->set_cascade_port(chip, port);
1343 if (err)
1344 return err;
1345 }
1346
Vivien Didelot23c98912018-05-09 11:38:50 -04001347 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1348 if (err)
1349 return err;
1350
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001351 return 0;
1352}
1353
Vivien Didelotb28f8722018-04-26 21:56:44 -04001354static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1355{
1356 /* Clear all trunk masks and mapping */
1357 if (chip->info->global2_addr)
1358 return mv88e6xxx_g2_trunk_clear(chip);
1359
1360 return 0;
1361}
1362
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001363static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1364{
1365 if (chip->info->ops->rmu_disable)
1366 return chip->info->ops->rmu_disable(chip);
1367
1368 return 0;
1369}
1370
Vivien Didelot9e907d72017-07-17 13:03:43 -04001371static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1372{
1373 if (chip->info->ops->pot_clear)
1374 return chip->info->ops->pot_clear(chip);
1375
1376 return 0;
1377}
1378
Vivien Didelot51c901a2017-07-17 13:03:41 -04001379static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1380{
1381 if (chip->info->ops->mgmt_rsvd2cpu)
1382 return chip->info->ops->mgmt_rsvd2cpu(chip);
1383
1384 return 0;
1385}
1386
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001387static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1388{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001389 int err;
1390
Vivien Didelotdaefc942017-03-11 16:12:54 -05001391 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1392 if (err)
1393 return err;
1394
Rasmus Villemoes49506a92020-12-10 12:06:44 +01001395 /* The chips that have a "learn2all" bit in Global1, ATU
1396 * Control are precisely those whose port registers have a
1397 * Message Port bit in Port Control 1 and hence implement
1398 * ->port_setup_message_port.
1399 */
1400 if (chip->info->ops->port_setup_message_port) {
1401 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1402 if (err)
1403 return err;
1404 }
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001405
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001406 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1407}
1408
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001409static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1410{
1411 int port;
1412 int err;
1413
1414 if (!chip->info->ops->irl_init_all)
1415 return 0;
1416
1417 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1418 /* Disable ingress rate limiting by resetting all per port
1419 * ingress rate limit resources to their initial state.
1420 */
1421 err = chip->info->ops->irl_init_all(chip, port);
1422 if (err)
1423 return err;
1424 }
1425
1426 return 0;
1427}
1428
Vivien Didelot04a69a12017-10-13 14:18:05 -04001429static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1430{
1431 if (chip->info->ops->set_switch_mac) {
1432 u8 addr[ETH_ALEN];
1433
1434 eth_random_addr(addr);
1435
1436 return chip->info->ops->set_switch_mac(chip, addr);
1437 }
1438
1439 return 0;
1440}
1441
Vivien Didelot17a15942017-03-30 17:37:09 -04001442static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1443{
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001444 struct dsa_switch_tree *dst = chip->ds->dst;
1445 struct dsa_switch *ds;
1446 struct dsa_port *dp;
Vivien Didelot17a15942017-03-30 17:37:09 -04001447 u16 pvlan = 0;
1448
1449 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001450 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001451
1452 /* Skip the local source device, which uses in-chip port VLAN */
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001453 if (dev != chip->ds->index) {
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001454 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001455
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001456 ds = dsa_switch_find(dst->index, dev);
1457 dp = ds ? dsa_to_port(ds, port) : NULL;
1458 if (dp && dp->lag_dev) {
1459 /* As the PVT is used to limit flooding of
1460 * FORWARD frames, which use the LAG ID as the
1461 * source port, we must translate dev/port to
1462 * the special "LAG device" in the PVT, using
1463 * the LAG ID as the port number.
1464 */
Tobias Waldekranz78e70db2021-04-21 14:04:52 +02001465 dev = MV88E6XXX_G2_PVT_ADDR_DEV_TRUNK;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001466 port = dsa_lag_id(dst, dp->lag_dev);
1467 }
1468 }
1469
Vivien Didelot17a15942017-03-30 17:37:09 -04001470 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1471}
1472
Vivien Didelot81228992017-03-30 17:37:08 -04001473static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1474{
Vivien Didelot17a15942017-03-30 17:37:09 -04001475 int dev, port;
1476 int err;
1477
Vivien Didelot81228992017-03-30 17:37:08 -04001478 if (!mv88e6xxx_has_pvt(chip))
1479 return 0;
1480
1481 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1482 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1483 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001484 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1485 if (err)
1486 return err;
1487
1488 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1489 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1490 err = mv88e6xxx_pvt_map(chip, dev, port);
1491 if (err)
1492 return err;
1493 }
1494 }
1495
1496 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001497}
1498
Vivien Didelot749efcb2016-09-22 16:49:24 -04001499static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1500{
1501 struct mv88e6xxx_chip *chip = ds->priv;
1502 int err;
1503
Tobias Waldekranzffcec3f2021-03-18 20:25:34 +01001504 if (dsa_to_port(ds, port)->lag_dev)
1505 /* Hardware is incapable of fast-aging a LAG through a
1506 * regular ATU move operation. Until we have something
1507 * more fancy in place this is a no-op.
1508 */
1509 return;
1510
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001511 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001512 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001513 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001514
1515 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001516 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001517}
1518
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001519static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1520{
Tobias Waldekranze545f862020-11-10 19:57:20 +01001521 if (!mv88e6xxx_max_vid(chip))
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001522 return 0;
1523
1524 return mv88e6xxx_g1_vtu_flush(chip);
1525}
1526
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001527static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1528 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotf1394b782017-05-01 14:05:22 -04001529{
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001530 int err;
1531
Vivien Didelotf1394b782017-05-01 14:05:22 -04001532 if (!chip->info->ops->vtu_getnext)
1533 return -EOPNOTSUPP;
1534
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001535 entry->vid = vid ? vid - 1 : mv88e6xxx_max_vid(chip);
1536 entry->valid = false;
1537
1538 err = chip->info->ops->vtu_getnext(chip, entry);
1539
1540 if (entry->vid != vid)
1541 entry->valid = false;
1542
1543 return err;
Vivien Didelotf1394b782017-05-01 14:05:22 -04001544}
1545
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001546static int mv88e6xxx_vtu_walk(struct mv88e6xxx_chip *chip,
1547 int (*cb)(struct mv88e6xxx_chip *chip,
1548 const struct mv88e6xxx_vtu_entry *entry,
1549 void *priv),
1550 void *priv)
1551{
1552 struct mv88e6xxx_vtu_entry entry = {
1553 .vid = mv88e6xxx_max_vid(chip),
1554 .valid = false,
1555 };
1556 int err;
1557
1558 if (!chip->info->ops->vtu_getnext)
1559 return -EOPNOTSUPP;
1560
1561 do {
1562 err = chip->info->ops->vtu_getnext(chip, &entry);
1563 if (err)
1564 return err;
1565
1566 if (!entry.valid)
1567 break;
1568
1569 err = cb(chip, &entry, priv);
1570 if (err)
1571 return err;
1572 } while (entry.vid < mv88e6xxx_max_vid(chip));
1573
1574 return 0;
1575}
1576
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001577static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1578 struct mv88e6xxx_vtu_entry *entry)
1579{
1580 if (!chip->info->ops->vtu_loadpurge)
1581 return -EOPNOTSUPP;
1582
1583 return chip->info->ops->vtu_loadpurge(chip, entry);
1584}
1585
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001586static int mv88e6xxx_fid_map_vlan(struct mv88e6xxx_chip *chip,
1587 const struct mv88e6xxx_vtu_entry *entry,
1588 void *_fid_bitmap)
1589{
1590 unsigned long *fid_bitmap = _fid_bitmap;
1591
1592 set_bit(entry->fid, fid_bitmap);
1593 return 0;
1594}
1595
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001596int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001597{
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001598 int i, err;
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001599 u16 fid;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001600
1601 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1602
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001603 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001604 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001605 err = mv88e6xxx_port_get_fid(chip, i, &fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001606 if (err)
1607 return err;
1608
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001609 set_bit(fid, fid_bitmap);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001610 }
1611
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001612 /* Set every FID bit used by the VLAN entries */
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001613 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_fid_map_vlan, fid_bitmap);
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001614}
1615
1616static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1617{
1618 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1619 int err;
1620
1621 err = mv88e6xxx_fid_map(chip, fid_bitmap);
1622 if (err)
1623 return err;
1624
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001625 /* The reset value 0x000 is used to indicate that multiple address
1626 * databases are not needed. Return the next positive available.
1627 */
1628 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001629 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001630 return -ENOSPC;
1631
1632 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001633 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001634}
1635
Vivien Didelotda9c3592016-02-12 12:09:40 -05001636static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001637 u16 vid)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001638{
Vivien Didelot04bed142016-08-31 18:06:13 -04001639 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001640 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001641 int i, err;
1642
Andrew Lunndb06ae412017-09-25 23:32:20 +02001643 /* DSA and CPU ports have to be members of multiple vlans */
1644 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1645 return 0;
1646
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001647 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001648 if (err)
1649 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001650
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001651 if (!vlan.valid)
1652 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001653
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001654 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1655 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1656 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001657
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001658 if (!dsa_to_port(ds, i)->slave)
1659 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001660
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001661 if (vlan.member[i] ==
1662 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1663 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001664
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001665 if (dsa_to_port(ds, i)->bridge_dev ==
1666 dsa_to_port(ds, port)->bridge_dev)
1667 break; /* same bridge, check next VLAN */
Vivien Didelotda9c3592016-02-12 12:09:40 -05001668
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001669 if (!dsa_to_port(ds, i)->bridge_dev)
1670 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001671
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001672 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1673 port, vlan.vid, i,
1674 netdev_name(dsa_to_port(ds, i)->bridge_dev));
1675 return -EOPNOTSUPP;
1676 }
Vivien Didelotda9c3592016-02-12 12:09:40 -05001677
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001678 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001679}
1680
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001681static int mv88e6xxx_port_commit_pvid(struct mv88e6xxx_chip *chip, int port)
1682{
1683 struct dsa_port *dp = dsa_to_port(chip->ds, port);
1684 struct mv88e6xxx_port *p = &chip->ports[port];
Vladimir Oltean5bded822021-10-07 19:47:11 +03001685 u16 pvid = MV88E6XXX_VID_STANDALONE;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001686 bool drop_untagged = false;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001687 int err;
1688
Vladimir Oltean5bded822021-10-07 19:47:11 +03001689 if (dp->bridge_dev) {
1690 if (br_vlan_enabled(dp->bridge_dev)) {
1691 pvid = p->bridge_pvid.vid;
1692 drop_untagged = !p->bridge_pvid.valid;
1693 } else {
1694 pvid = MV88E6XXX_VID_BRIDGED;
1695 }
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001696 }
1697
1698 err = mv88e6xxx_port_set_pvid(chip, port, pvid);
1699 if (err)
1700 return err;
1701
1702 return mv88e6xxx_port_drop_untagged(chip, port, drop_untagged);
1703}
1704
Vivien Didelotf81ec902016-05-09 13:22:58 -04001705static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
Vladimir Oltean89153ed2021-02-13 22:43:19 +02001706 bool vlan_filtering,
1707 struct netlink_ext_ack *extack)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001708{
Vivien Didelot04bed142016-08-31 18:06:13 -04001709 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001710 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1711 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001712 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001713
Vladimir Olteanbae33f22021-01-09 02:01:50 +02001714 if (!mv88e6xxx_max_vid(chip))
1715 return -EOPNOTSUPP;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001716
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001717 mv88e6xxx_reg_lock(chip);
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001718
Vivien Didelot385a0992016-11-04 03:23:31 +01001719 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001720 if (err)
1721 goto unlock;
1722
1723 err = mv88e6xxx_port_commit_pvid(chip, port);
1724 if (err)
1725 goto unlock;
1726
1727unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001728 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001729
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001730 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001731}
1732
Vivien Didelot57d32312016-06-20 13:13:58 -04001733static int
1734mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001735 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001736{
Vivien Didelot04bed142016-08-31 18:06:13 -04001737 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001738 int err;
1739
Tobias Waldekranze545f862020-11-10 19:57:20 +01001740 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001741 return -EOPNOTSUPP;
1742
Vivien Didelotda9c3592016-02-12 12:09:40 -05001743 /* If the requested port doesn't belong to the same bridge as the VLAN
1744 * members, do not support it (yet) and fallback to software VLAN.
1745 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001746 mv88e6xxx_reg_lock(chip);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001747 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001748 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001749
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001750 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001751}
1752
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001753static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1754 const unsigned char *addr, u16 vid,
1755 u8 state)
1756{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001757 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001758 struct mv88e6xxx_vtu_entry vlan;
1759 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001760 int err;
1761
Vladimir Oltean5bded822021-10-07 19:47:11 +03001762 /* Ports have two private address databases: one for when the port is
1763 * standalone and one for when the port is under a bridge and the
1764 * 802.1Q mode is disabled. When the port is standalone, DSA wants its
1765 * address database to remain 100% empty, so we never load an ATU entry
1766 * into a standalone port's database. Therefore, translate the null
1767 * VLAN ID into the port's database used for VLAN-unaware bridging.
1768 */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001769 if (vid == 0) {
Vladimir Oltean5bded822021-10-07 19:47:11 +03001770 fid = MV88E6XXX_FID_BRIDGED;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001771 } else {
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001772 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001773 if (err)
1774 return err;
1775
1776 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001777 if (!vlan.valid)
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001778 return -EOPNOTSUPP;
1779
1780 fid = vlan.fid;
1781 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001782
Vivien Didelotd8291a92019-09-07 16:00:47 -04001783 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001784 ether_addr_copy(entry.mac, addr);
1785 eth_addr_dec(entry.mac);
1786
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001787 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001788 if (err)
1789 return err;
1790
1791 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001792 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001793 memset(&entry, 0, sizeof(entry));
1794 ether_addr_copy(entry.mac, addr);
1795 }
1796
1797 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001798 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001799 entry.portvec &= ~BIT(port);
1800 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001801 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001802 } else {
DENG Qingfangf72f2fb2021-01-30 21:43:34 +08001803 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
1804 entry.portvec = BIT(port);
1805 else
1806 entry.portvec |= BIT(port);
1807
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001808 entry.state = state;
1809 }
1810
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001811 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001812}
1813
Vivien Didelotda7dc872019-09-07 16:00:49 -04001814static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1815 const struct mv88e6xxx_policy *policy)
1816{
1817 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1818 enum mv88e6xxx_policy_action action = policy->action;
1819 const u8 *addr = policy->addr;
1820 u16 vid = policy->vid;
1821 u8 state;
1822 int err;
1823 int id;
1824
1825 if (!chip->info->ops->port_set_policy)
1826 return -EOPNOTSUPP;
1827
1828 switch (mapping) {
1829 case MV88E6XXX_POLICY_MAPPING_DA:
1830 case MV88E6XXX_POLICY_MAPPING_SA:
1831 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1832 state = 0; /* Dissociate the port and address */
1833 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1834 is_multicast_ether_addr(addr))
1835 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1836 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1837 is_unicast_ether_addr(addr))
1838 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1839 else
1840 return -EOPNOTSUPP;
1841
1842 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1843 state);
1844 if (err)
1845 return err;
1846 break;
1847 default:
1848 return -EOPNOTSUPP;
1849 }
1850
1851 /* Skip the port's policy clearing if the mapping is still in use */
1852 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1853 idr_for_each_entry(&chip->policies, policy, id)
1854 if (policy->port == port &&
1855 policy->mapping == mapping &&
1856 policy->action != action)
1857 return 0;
1858
1859 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1860}
1861
1862static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1863 struct ethtool_rx_flow_spec *fs)
1864{
1865 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1866 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1867 enum mv88e6xxx_policy_mapping mapping;
1868 enum mv88e6xxx_policy_action action;
1869 struct mv88e6xxx_policy *policy;
1870 u16 vid = 0;
1871 u8 *addr;
1872 int err;
1873 int id;
1874
1875 if (fs->location != RX_CLS_LOC_ANY)
1876 return -EINVAL;
1877
1878 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1879 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1880 else
1881 return -EOPNOTSUPP;
1882
1883 switch (fs->flow_type & ~FLOW_EXT) {
1884 case ETHER_FLOW:
1885 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1886 is_zero_ether_addr(mac_mask->h_source)) {
1887 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1888 addr = mac_entry->h_dest;
1889 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1890 !is_zero_ether_addr(mac_mask->h_source)) {
1891 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1892 addr = mac_entry->h_source;
1893 } else {
1894 /* Cannot support DA and SA mapping in the same rule */
1895 return -EOPNOTSUPP;
1896 }
1897 break;
1898 default:
1899 return -EOPNOTSUPP;
1900 }
1901
1902 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001903 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001904 return -EOPNOTSUPP;
1905 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1906 }
1907
1908 idr_for_each_entry(&chip->policies, policy, id) {
1909 if (policy->port == port && policy->mapping == mapping &&
1910 policy->action == action && policy->vid == vid &&
1911 ether_addr_equal(policy->addr, addr))
1912 return -EEXIST;
1913 }
1914
1915 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1916 if (!policy)
1917 return -ENOMEM;
1918
1919 fs->location = 0;
1920 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1921 GFP_KERNEL);
1922 if (err) {
1923 devm_kfree(chip->dev, policy);
1924 return err;
1925 }
1926
1927 memcpy(&policy->fs, fs, sizeof(*fs));
1928 ether_addr_copy(policy->addr, addr);
1929 policy->mapping = mapping;
1930 policy->action = action;
1931 policy->port = port;
1932 policy->vid = vid;
1933
1934 err = mv88e6xxx_policy_apply(chip, port, policy);
1935 if (err) {
1936 idr_remove(&chip->policies, fs->location);
1937 devm_kfree(chip->dev, policy);
1938 return err;
1939 }
1940
1941 return 0;
1942}
1943
1944static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1945 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1946{
1947 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1948 struct mv88e6xxx_chip *chip = ds->priv;
1949 struct mv88e6xxx_policy *policy;
1950 int err;
1951 int id;
1952
1953 mv88e6xxx_reg_lock(chip);
1954
1955 switch (rxnfc->cmd) {
1956 case ETHTOOL_GRXCLSRLCNT:
1957 rxnfc->data = 0;
1958 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1959 rxnfc->rule_cnt = 0;
1960 idr_for_each_entry(&chip->policies, policy, id)
1961 if (policy->port == port)
1962 rxnfc->rule_cnt++;
1963 err = 0;
1964 break;
1965 case ETHTOOL_GRXCLSRULE:
1966 err = -ENOENT;
1967 policy = idr_find(&chip->policies, fs->location);
1968 if (policy) {
1969 memcpy(fs, &policy->fs, sizeof(*fs));
1970 err = 0;
1971 }
1972 break;
1973 case ETHTOOL_GRXCLSRLALL:
1974 rxnfc->data = 0;
1975 rxnfc->rule_cnt = 0;
1976 idr_for_each_entry(&chip->policies, policy, id)
1977 if (policy->port == port)
1978 rule_locs[rxnfc->rule_cnt++] = id;
1979 err = 0;
1980 break;
1981 default:
1982 err = -EOPNOTSUPP;
1983 break;
1984 }
1985
1986 mv88e6xxx_reg_unlock(chip);
1987
1988 return err;
1989}
1990
1991static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1992 struct ethtool_rxnfc *rxnfc)
1993{
1994 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1995 struct mv88e6xxx_chip *chip = ds->priv;
1996 struct mv88e6xxx_policy *policy;
1997 int err;
1998
1999 mv88e6xxx_reg_lock(chip);
2000
2001 switch (rxnfc->cmd) {
2002 case ETHTOOL_SRXCLSRLINS:
2003 err = mv88e6xxx_policy_insert(chip, port, fs);
2004 break;
2005 case ETHTOOL_SRXCLSRLDEL:
2006 err = -ENOENT;
2007 policy = idr_remove(&chip->policies, fs->location);
2008 if (policy) {
2009 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
2010 err = mv88e6xxx_policy_apply(chip, port, policy);
2011 devm_kfree(chip->dev, policy);
2012 }
2013 break;
2014 default:
2015 err = -EOPNOTSUPP;
2016 break;
2017 }
2018
2019 mv88e6xxx_reg_unlock(chip);
2020
2021 return err;
2022}
2023
Andrew Lunn87fa8862017-11-09 22:29:56 +01002024static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
2025 u16 vid)
2026{
Andrew Lunn87fa8862017-11-09 22:29:56 +01002027 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
Tobias Waldekranz0806dd462021-03-18 20:25:37 +01002028 u8 broadcast[ETH_ALEN];
2029
2030 eth_broadcast_addr(broadcast);
Andrew Lunn87fa8862017-11-09 22:29:56 +01002031
2032 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
2033}
2034
2035static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
2036{
2037 int port;
2038 int err;
2039
2040 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01002041 struct dsa_port *dp = dsa_to_port(chip->ds, port);
2042 struct net_device *brport;
2043
2044 if (dsa_is_unused_port(chip->ds, port))
2045 continue;
2046
2047 brport = dsa_port_to_bridge_port(dp);
2048 if (brport && !br_port_flag_is_set(brport, BR_BCAST_FLOOD))
2049 /* Skip bridged user ports where broadcast
2050 * flooding is disabled.
2051 */
2052 continue;
2053
Andrew Lunn87fa8862017-11-09 22:29:56 +01002054 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
2055 if (err)
2056 return err;
2057 }
2058
2059 return 0;
2060}
2061
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01002062struct mv88e6xxx_port_broadcast_sync_ctx {
2063 int port;
2064 bool flood;
2065};
2066
2067static int
2068mv88e6xxx_port_broadcast_sync_vlan(struct mv88e6xxx_chip *chip,
2069 const struct mv88e6xxx_vtu_entry *vlan,
2070 void *_ctx)
2071{
2072 struct mv88e6xxx_port_broadcast_sync_ctx *ctx = _ctx;
2073 u8 broadcast[ETH_ALEN];
2074 u8 state;
2075
2076 if (ctx->flood)
2077 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
2078 else
2079 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_UNUSED;
2080
2081 eth_broadcast_addr(broadcast);
2082
2083 return mv88e6xxx_port_db_load_purge(chip, ctx->port, broadcast,
2084 vlan->vid, state);
2085}
2086
2087static int mv88e6xxx_port_broadcast_sync(struct mv88e6xxx_chip *chip, int port,
2088 bool flood)
2089{
2090 struct mv88e6xxx_port_broadcast_sync_ctx ctx = {
2091 .port = port,
2092 .flood = flood,
2093 };
2094 struct mv88e6xxx_vtu_entry vid0 = {
2095 .vid = 0,
2096 };
2097 int err;
2098
2099 /* Update the port's private database... */
2100 err = mv88e6xxx_port_broadcast_sync_vlan(chip, &vid0, &ctx);
2101 if (err)
2102 return err;
2103
2104 /* ...and the database for all VLANs. */
2105 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_broadcast_sync_vlan,
2106 &ctx);
2107}
2108
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002109static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00002110 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002111{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002112 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002113 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002114 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002115
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002116 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002117 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002118 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002119
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002120 if (!vlan.valid) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002121 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002122
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002123 err = mv88e6xxx_atu_new(chip, &vlan.fid);
2124 if (err)
2125 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01002126
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002127 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
2128 if (i == port)
2129 vlan.member[i] = member;
2130 else
2131 vlan.member[i] = non_member;
2132
2133 vlan.vid = vid;
2134 vlan.valid = true;
2135
2136 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2137 if (err)
2138 return err;
2139
2140 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
2141 if (err)
2142 return err;
2143 } else if (vlan.member[port] != member) {
2144 vlan.member[port] = member;
2145
2146 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2147 if (err)
2148 return err;
Russell King933b4422020-02-26 17:14:26 +00002149 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002150 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
2151 port, vid);
2152 }
2153
2154 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002155}
2156
Vladimir Oltean1958d582021-01-09 02:01:53 +02002157static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vladimir Oltean31046a52021-02-13 22:43:18 +02002158 const struct switchdev_obj_port_vlan *vlan,
2159 struct netlink_ext_ack *extack)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002160{
Vivien Didelot04bed142016-08-31 18:06:13 -04002161 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002162 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
2163 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002164 struct mv88e6xxx_port *p = &chip->ports[port];
Russell King933b4422020-02-26 17:14:26 +00002165 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002166 u8 member;
Vladimir Oltean1958d582021-01-09 02:01:53 +02002167 int err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002168
Eldar Gasanovb8b79c42021-06-21 11:54:38 +03002169 if (!vlan->vid)
2170 return 0;
2171
Vladimir Oltean1958d582021-01-09 02:01:53 +02002172 err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
2173 if (err)
2174 return err;
Vivien Didelot54d77b52016-05-09 13:22:47 -04002175
Vivien Didelotc91498e2017-06-07 18:12:13 -04002176 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002177 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002178 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002179 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002180 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002181 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002182
Russell King933b4422020-02-26 17:14:26 +00002183 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
2184 * and then the CPU port. Do not warn for duplicates for the CPU port.
2185 */
2186 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
2187
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002188 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002189
Vladimir Oltean1958d582021-01-09 02:01:53 +02002190 err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
2191 if (err) {
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002192 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2193 vlan->vid, untagged ? 'u' : 't');
Vladimir Oltean1958d582021-01-09 02:01:53 +02002194 goto out;
2195 }
Vivien Didelot76e398a2015-11-01 12:33:55 -05002196
Vladimir Oltean1958d582021-01-09 02:01:53 +02002197 if (pvid) {
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002198 p->bridge_pvid.vid = vlan->vid;
2199 p->bridge_pvid.valid = true;
2200
2201 err = mv88e6xxx_port_commit_pvid(chip, port);
2202 if (err)
Vladimir Oltean1958d582021-01-09 02:01:53 +02002203 goto out;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002204 } else if (vlan->vid && p->bridge_pvid.vid == vlan->vid) {
2205 /* The old pvid was reinstalled as a non-pvid VLAN */
2206 p->bridge_pvid.valid = false;
2207
2208 err = mv88e6xxx_port_commit_pvid(chip, port);
2209 if (err)
2210 goto out;
Vladimir Oltean1958d582021-01-09 02:01:53 +02002211 }
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002212
Vladimir Oltean1958d582021-01-09 02:01:53 +02002213out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002214 mv88e6xxx_reg_unlock(chip);
Vladimir Oltean1958d582021-01-09 02:01:53 +02002215
2216 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002217}
2218
Vivien Didelot521098922019-08-01 14:36:36 -04002219static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2220 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002221{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002222 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002223 int i, err;
2224
Vivien Didelot521098922019-08-01 14:36:36 -04002225 if (!vid)
Vladimir Olteanc92c7412021-07-22 16:05:51 +03002226 return 0;
Vivien Didelot521098922019-08-01 14:36:36 -04002227
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002228 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002229 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002230 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002231
Vivien Didelot521098922019-08-01 14:36:36 -04002232 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2233 * tell switchdev that this VLAN is likely handled in software.
2234 */
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002235 if (!vlan.valid ||
Vivien Didelot521098922019-08-01 14:36:36 -04002236 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002237 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002238
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002239 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002240
2241 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002242 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002243 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002244 if (vlan.member[i] !=
2245 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002246 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002247 break;
2248 }
2249 }
2250
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002251 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002252 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002253 return err;
2254
Vivien Didelote606ca32017-03-11 16:12:55 -05002255 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002256}
2257
Vivien Didelotf81ec902016-05-09 13:22:58 -04002258static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2259 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002260{
Vivien Didelot04bed142016-08-31 18:06:13 -04002261 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002262 struct mv88e6xxx_port *p = &chip->ports[port];
Vivien Didelot76e398a2015-11-01 12:33:55 -05002263 int err = 0;
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002264 u16 pvid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002265
Tobias Waldekranze545f862020-11-10 19:57:20 +01002266 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04002267 return -EOPNOTSUPP;
2268
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002269 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002270
Vivien Didelot77064f32016-11-04 03:23:30 +01002271 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002272 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002273 goto unlock;
2274
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002275 err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
2276 if (err)
2277 goto unlock;
2278
2279 if (vlan->vid == pvid) {
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002280 p->bridge_pvid.valid = false;
2281
2282 err = mv88e6xxx_port_commit_pvid(chip, port);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002283 if (err)
2284 goto unlock;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002285 }
2286
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002287unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002288 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002289
2290 return err;
2291}
2292
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002293static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2294 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002295{
Vivien Didelot04bed142016-08-31 18:06:13 -04002296 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002297 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002298
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002299 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002300 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2301 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002302 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002303
2304 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002305}
2306
Vivien Didelotf81ec902016-05-09 13:22:58 -04002307static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002308 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002309{
Vivien Didelot04bed142016-08-31 18:06:13 -04002310 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002311 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002312
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002313 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002314 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002315 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002316
Vivien Didelot83dabd12016-08-31 11:50:04 -04002317 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002318}
2319
Vivien Didelot83dabd12016-08-31 11:50:04 -04002320static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2321 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002322 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002323{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002324 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002325 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002326 int err;
2327
Vivien Didelotd8291a92019-09-07 16:00:47 -04002328 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002329 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002330
2331 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002332 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002333 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002334 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002335
Vivien Didelotd8291a92019-09-07 16:00:47 -04002336 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002337 break;
2338
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002339 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002340 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002341
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002342 if (!is_unicast_ether_addr(addr.mac))
2343 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002344
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002345 is_static = (addr.state ==
2346 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2347 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002348 if (err)
2349 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002350 } while (!is_broadcast_ether_addr(addr.mac));
2351
2352 return err;
2353}
2354
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002355struct mv88e6xxx_port_db_dump_vlan_ctx {
2356 int port;
2357 dsa_fdb_dump_cb_t *cb;
2358 void *data;
2359};
2360
2361static int mv88e6xxx_port_db_dump_vlan(struct mv88e6xxx_chip *chip,
2362 const struct mv88e6xxx_vtu_entry *entry,
2363 void *_data)
2364{
2365 struct mv88e6xxx_port_db_dump_vlan_ctx *ctx = _data;
2366
2367 return mv88e6xxx_port_db_dump_fid(chip, entry->fid, entry->vid,
2368 ctx->port, ctx->cb, ctx->data);
2369}
2370
Vivien Didelot83dabd12016-08-31 11:50:04 -04002371static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002372 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002373{
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002374 struct mv88e6xxx_port_db_dump_vlan_ctx ctx = {
2375 .port = port,
2376 .cb = cb,
2377 .data = data,
2378 };
Vivien Didelot83dabd12016-08-31 11:50:04 -04002379 u16 fid;
2380 int err;
2381
2382 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002383 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002384 if (err)
2385 return err;
2386
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002387 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002388 if (err)
2389 return err;
2390
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002391 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_db_dump_vlan, &ctx);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002392}
2393
Vivien Didelotf81ec902016-05-09 13:22:58 -04002394static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002395 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002396{
Vivien Didelot04bed142016-08-31 18:06:13 -04002397 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002398 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002399
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002400 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002401 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002402 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002403
2404 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002405}
2406
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002407static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2408 struct net_device *br)
2409{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002410 struct dsa_switch *ds = chip->ds;
2411 struct dsa_switch_tree *dst = ds->dst;
2412 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002413 int err;
2414
Vivien Didelotef2025e2019-10-21 16:51:27 -04002415 list_for_each_entry(dp, &dst->ports, list) {
2416 if (dp->bridge_dev == br) {
2417 if (dp->ds == ds) {
2418 /* This is a local bridge group member,
2419 * remap its Port VLAN Map.
2420 */
2421 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2422 if (err)
2423 return err;
2424 } else {
2425 /* This is an external bridge group member,
2426 * remap its cross-chip Port VLAN Table entry.
2427 */
2428 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2429 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002430 if (err)
2431 return err;
2432 }
2433 }
2434 }
2435
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002436 return 0;
2437}
2438
Vivien Didelotf81ec902016-05-09 13:22:58 -04002439static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002440 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002441{
Vivien Didelot04bed142016-08-31 18:06:13 -04002442 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002443 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002444
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002445 mv88e6xxx_reg_lock(chip);
Vladimir Oltean5bded822021-10-07 19:47:11 +03002446
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002447 err = mv88e6xxx_bridge_map(chip, br);
Vladimir Oltean5bded822021-10-07 19:47:11 +03002448 if (err)
2449 goto unlock;
2450
2451 err = mv88e6xxx_port_commit_pvid(chip, port);
2452 if (err)
2453 goto unlock;
2454
2455unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002456 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002457
Vivien Didelot466dfa02016-02-26 13:16:05 -05002458 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002459}
2460
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002461static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2462 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002463{
Vivien Didelot04bed142016-08-31 18:06:13 -04002464 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Oltean5bded822021-10-07 19:47:11 +03002465 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002466
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002467 mv88e6xxx_reg_lock(chip);
Vladimir Oltean5bded822021-10-07 19:47:11 +03002468
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002469 if (mv88e6xxx_bridge_map(chip, br) ||
2470 mv88e6xxx_port_vlan_map(chip, port))
2471 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vladimir Oltean5bded822021-10-07 19:47:11 +03002472
2473 err = mv88e6xxx_port_commit_pvid(chip, port);
2474 if (err)
2475 dev_err(ds->dev,
2476 "port %d failed to restore standalone pvid: %pe\n",
2477 port, ERR_PTR(err));
2478
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002479 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002480}
2481
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002482static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2483 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002484 int port, struct net_device *br)
2485{
2486 struct mv88e6xxx_chip *chip = ds->priv;
2487 int err;
2488
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002489 if (tree_index != ds->dst->index)
2490 return 0;
2491
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002492 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002493 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002494 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002495
2496 return err;
2497}
2498
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002499static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2500 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002501 int port, struct net_device *br)
2502{
2503 struct mv88e6xxx_chip *chip = ds->priv;
2504
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002505 if (tree_index != ds->dst->index)
2506 return;
2507
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002508 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002509 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002510 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002511 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002512}
2513
Vladimir Olteance5df682021-07-22 18:55:41 +03002514/* Treat the software bridge as a virtual single-port switch behind the
2515 * CPU and map in the PVT. First dst->last_switch elements are taken by
2516 * physical switches, so start from beyond that range.
2517 */
2518static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
2519 int bridge_num)
2520{
2521 u8 dev = bridge_num + ds->dst->last_switch + 1;
2522 struct mv88e6xxx_chip *chip = ds->priv;
2523 int err;
2524
2525 mv88e6xxx_reg_lock(chip);
2526 err = mv88e6xxx_pvt_map(chip, dev, 0);
2527 mv88e6xxx_reg_unlock(chip);
2528
2529 return err;
2530}
2531
2532static int mv88e6xxx_bridge_tx_fwd_offload(struct dsa_switch *ds, int port,
2533 struct net_device *br,
2534 int bridge_num)
2535{
2536 return mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
2537}
2538
2539static void mv88e6xxx_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port,
2540 struct net_device *br,
2541 int bridge_num)
2542{
2543 int err;
2544
2545 err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
2546 if (err) {
2547 dev_err(ds->dev, "failed to remap cross-chip Port VLAN: %pe\n",
2548 ERR_PTR(err));
2549 }
2550}
2551
Vivien Didelot17e708b2016-12-05 17:30:27 -05002552static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2553{
2554 if (chip->info->ops->reset)
2555 return chip->info->ops->reset(chip);
2556
2557 return 0;
2558}
2559
Vivien Didelot309eca62016-12-05 17:30:26 -05002560static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2561{
2562 struct gpio_desc *gpiod = chip->reset;
2563
2564 /* If there is a GPIO connected to the reset pin, toggle it */
2565 if (gpiod) {
2566 gpiod_set_value_cansleep(gpiod, 1);
2567 usleep_range(10000, 20000);
2568 gpiod_set_value_cansleep(gpiod, 0);
2569 usleep_range(10000, 20000);
Andrew Lunna3dcb3e2020-11-16 08:43:01 -08002570
2571 mv88e6xxx_g1_wait_eeprom_done(chip);
Vivien Didelot309eca62016-12-05 17:30:26 -05002572 }
2573}
2574
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002575static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2576{
2577 int i, err;
2578
2579 /* Set all ports to the Disabled state */
2580 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002581 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002582 if (err)
2583 return err;
2584 }
2585
2586 /* Wait for transmit queues to drain,
2587 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2588 */
2589 usleep_range(2000, 4000);
2590
2591 return 0;
2592}
2593
Vivien Didelotfad09c72016-06-21 12:28:20 -04002594static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002595{
Vivien Didelota935c052016-09-29 12:21:53 -04002596 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002597
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002598 err = mv88e6xxx_disable_ports(chip);
2599 if (err)
2600 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002601
Vivien Didelot309eca62016-12-05 17:30:26 -05002602 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002603
Vivien Didelot17e708b2016-12-05 17:30:27 -05002604 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002605}
2606
Vivien Didelot43145572017-03-11 16:12:59 -05002607static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002608 enum mv88e6xxx_frame_mode frame,
2609 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002610{
2611 int err;
2612
Vivien Didelot43145572017-03-11 16:12:59 -05002613 if (!chip->info->ops->port_set_frame_mode)
2614 return -EOPNOTSUPP;
2615
2616 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002617 if (err)
2618 return err;
2619
Vivien Didelot43145572017-03-11 16:12:59 -05002620 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2621 if (err)
2622 return err;
2623
2624 if (chip->info->ops->port_set_ether_type)
2625 return chip->info->ops->port_set_ether_type(chip, port, etype);
2626
2627 return 0;
2628}
2629
2630static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2631{
2632 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002633 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002634 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002635}
2636
2637static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2638{
2639 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002640 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002641 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002642}
2643
2644static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2645{
2646 return mv88e6xxx_set_port_mode(chip, port,
2647 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002648 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2649 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002650}
2651
2652static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2653{
2654 if (dsa_is_dsa_port(chip->ds, port))
2655 return mv88e6xxx_set_port_mode_dsa(chip, port);
2656
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002657 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002658 return mv88e6xxx_set_port_mode_normal(chip, port);
2659
2660 /* Setup CPU port mode depending on its supported tag format */
Tobias Waldekranz670bb802021-04-20 20:53:07 +02002661 if (chip->tag_protocol == DSA_TAG_PROTO_DSA)
Vivien Didelot43145572017-03-11 16:12:59 -05002662 return mv88e6xxx_set_port_mode_dsa(chip, port);
2663
Tobias Waldekranz670bb802021-04-20 20:53:07 +02002664 if (chip->tag_protocol == DSA_TAG_PROTO_EDSA)
Vivien Didelot43145572017-03-11 16:12:59 -05002665 return mv88e6xxx_set_port_mode_edsa(chip, port);
2666
2667 return -EINVAL;
2668}
2669
Vivien Didelotea698f42017-03-11 16:12:50 -05002670static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2671{
2672 bool message = dsa_is_dsa_port(chip->ds, port);
2673
2674 return mv88e6xxx_port_set_message_port(chip, port, message);
2675}
2676
Vivien Didelot601aeed2017-03-11 16:13:00 -05002677static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2678{
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002679 int err;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002680
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002681 if (chip->info->ops->port_set_ucast_flood) {
Tobias Waldekranz7b9f16f2021-03-18 20:25:38 +01002682 err = chip->info->ops->port_set_ucast_flood(chip, port, true);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002683 if (err)
2684 return err;
2685 }
2686 if (chip->info->ops->port_set_mcast_flood) {
Tobias Waldekranz7b9f16f2021-03-18 20:25:38 +01002687 err = chip->info->ops->port_set_mcast_flood(chip, port, true);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002688 if (err)
2689 return err;
2690 }
Vivien Didelot601aeed2017-03-11 16:13:00 -05002691
David S. Miller407308f2019-06-15 13:35:29 -07002692 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002693}
2694
Vivien Didelot45de77f2019-08-31 16:18:36 -04002695static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2696{
2697 struct mv88e6xxx_port *mvp = dev_id;
2698 struct mv88e6xxx_chip *chip = mvp->chip;
2699 irqreturn_t ret = IRQ_NONE;
2700 int port = mvp->port;
Pavana Sharma193c5b22021-03-17 14:46:40 +01002701 int lane;
Vivien Didelot45de77f2019-08-31 16:18:36 -04002702
2703 mv88e6xxx_reg_lock(chip);
2704 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002705 if (lane >= 0)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002706 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2707 mv88e6xxx_reg_unlock(chip);
2708
2709 return ret;
2710}
2711
2712static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002713 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002714{
2715 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2716 unsigned int irq;
2717 int err;
2718
2719 /* Nothing to request if this SERDES port has no IRQ */
2720 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2721 if (!irq)
2722 return 0;
2723
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002724 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2725 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2726
Vivien Didelot45de77f2019-08-31 16:18:36 -04002727 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2728 mv88e6xxx_reg_unlock(chip);
2729 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002730 IRQF_ONESHOT, dev_id->serdes_irq_name,
2731 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002732 mv88e6xxx_reg_lock(chip);
2733 if (err)
2734 return err;
2735
2736 dev_id->serdes_irq = irq;
2737
2738 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2739}
2740
2741static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002742 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002743{
2744 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2745 unsigned int irq = dev_id->serdes_irq;
2746 int err;
2747
2748 /* Nothing to free if no IRQ has been requested */
2749 if (!irq)
2750 return 0;
2751
2752 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2753
2754 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2755 mv88e6xxx_reg_unlock(chip);
2756 free_irq(irq, dev_id);
2757 mv88e6xxx_reg_lock(chip);
2758
2759 dev_id->serdes_irq = 0;
2760
2761 return err;
2762}
2763
Andrew Lunn6d917822017-05-26 01:03:21 +02002764static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2765 bool on)
2766{
Pavana Sharma193c5b22021-03-17 14:46:40 +01002767 int lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002768 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002769
Vivien Didelotdc272f62019-08-31 16:18:33 -04002770 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002771 if (lane < 0)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002772 return 0;
2773
2774 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002775 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002776 if (err)
2777 return err;
2778
Vivien Didelot45de77f2019-08-31 16:18:36 -04002779 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002780 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002781 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2782 if (err)
2783 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002784
Vivien Didelotdc272f62019-08-31 16:18:33 -04002785 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002786 }
2787
2788 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002789}
2790
Marek Behún2fda45f2021-03-17 14:46:41 +01002791static int mv88e6xxx_set_egress_port(struct mv88e6xxx_chip *chip,
2792 enum mv88e6xxx_egress_direction direction,
2793 int port)
2794{
2795 int err;
2796
2797 if (!chip->info->ops->set_egress_port)
2798 return -EOPNOTSUPP;
2799
2800 err = chip->info->ops->set_egress_port(chip, direction, port);
2801 if (err)
2802 return err;
2803
2804 if (direction == MV88E6XXX_EGRESS_DIR_INGRESS)
2805 chip->ingress_dest_port = port;
2806 else
2807 chip->egress_dest_port = port;
2808
2809 return 0;
2810}
2811
Vivien Didelotfa371c82017-12-05 15:34:10 -05002812static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2813{
2814 struct dsa_switch *ds = chip->ds;
2815 int upstream_port;
2816 int err;
2817
Vivien Didelot07073c72017-12-05 15:34:13 -05002818 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002819 if (chip->info->ops->port_set_upstream_port) {
2820 err = chip->info->ops->port_set_upstream_port(chip, port,
2821 upstream_port);
2822 if (err)
2823 return err;
2824 }
2825
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002826 if (port == upstream_port) {
2827 if (chip->info->ops->set_cpu_port) {
2828 err = chip->info->ops->set_cpu_port(chip,
2829 upstream_port);
2830 if (err)
2831 return err;
2832 }
2833
Marek Behún2fda45f2021-03-17 14:46:41 +01002834 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002835 MV88E6XXX_EGRESS_DIR_INGRESS,
2836 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002837 if (err && err != -EOPNOTSUPP)
2838 return err;
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002839
Marek Behún2fda45f2021-03-17 14:46:41 +01002840 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002841 MV88E6XXX_EGRESS_DIR_EGRESS,
2842 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002843 if (err && err != -EOPNOTSUPP)
2844 return err;
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002845 }
2846
Vivien Didelotfa371c82017-12-05 15:34:10 -05002847 return 0;
2848}
2849
Vivien Didelotfad09c72016-06-21 12:28:20 -04002850static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002851{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002852 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002853 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002854 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002855
Andrew Lunn7b898462018-08-09 15:38:47 +02002856 chip->ports[port].chip = chip;
2857 chip->ports[port].port = port;
2858
Vivien Didelotd78343d2016-11-04 03:23:36 +01002859 /* MAC Forcing register: don't force link, speed, duplex or flow control
2860 * state to any particular values on physical ports, but force the CPU
2861 * port and all DSA ports to their maximum bandwidth and full duplex.
2862 */
2863 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2864 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2865 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002866 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002867 PHY_INTERFACE_MODE_NA);
2868 else
2869 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2870 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002871 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002872 PHY_INTERFACE_MODE_NA);
2873 if (err)
2874 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002875
2876 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2877 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2878 * tunneling, determine priority by looking at 802.1p and IP
2879 * priority fields (IP prio has precedence), and set STP state
2880 * to Forwarding.
2881 *
2882 * If this is the CPU link, use DSA or EDSA tagging depending
2883 * on which tagging mode was configured.
2884 *
2885 * If this is a link to another switch, use DSA tagging mode.
2886 *
2887 * If this is the upstream port for this switch, enable
2888 * forwarding of unknown unicasts and multicasts.
2889 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002890 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2891 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2892 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2893 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002894 if (err)
2895 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002896
Vivien Didelot601aeed2017-03-11 16:13:00 -05002897 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002898 if (err)
2899 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002900
Vivien Didelot601aeed2017-03-11 16:13:00 -05002901 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002902 if (err)
2903 return err;
2904
Andrew Lunnb92ce2f2021-09-26 19:41:25 +02002905 /* Port Control 2: don't force a good FCS, set the MTU size to
2906 * 10222 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002907 * untagged frames on this port, do a destination address lookup on all
2908 * received packets as usual, disable ARP mirroring and don't send a
2909 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002910 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002911 err = mv88e6xxx_port_set_map_da(chip, port);
2912 if (err)
2913 return err;
2914
Vivien Didelotfa371c82017-12-05 15:34:10 -05002915 err = mv88e6xxx_setup_upstream_port(chip, port);
2916 if (err)
2917 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002918
Andrew Lunna23b2962017-02-04 20:15:28 +01002919 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002920 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002921 if (err)
2922 return err;
2923
Vladimir Oltean5bded822021-10-07 19:47:11 +03002924 /* Associate MV88E6XXX_VID_BRIDGED with MV88E6XXX_FID_BRIDGED in the
2925 * ATU by virtue of the fact that mv88e6xxx_atu_new() will pick it as
2926 * the first free FID after MV88E6XXX_FID_STANDALONE. This will be used
2927 * as the private PVID on ports under a VLAN-unaware bridge.
2928 * Shared (DSA and CPU) ports must also be members of it, to translate
2929 * the VID from the DSA tag into MV88E6XXX_FID_BRIDGED, instead of
2930 * relying on their port default FID.
2931 */
2932 err = mv88e6xxx_port_vlan_join(chip, port, MV88E6XXX_VID_BRIDGED,
2933 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED,
2934 false);
2935 if (err)
2936 return err;
2937
Vivien Didelotcd782652017-06-08 18:34:13 -04002938 if (chip->info->ops->port_set_jumbo_size) {
Andrew Lunnb92ce2f2021-09-26 19:41:25 +02002939 err = chip->info->ops->port_set_jumbo_size(chip, port, 10218);
Andrew Lunn5f436662016-12-03 04:45:17 +01002940 if (err)
2941 return err;
2942 }
2943
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002944 /* Port Association Vector: disable automatic address learning
2945 * on all user ports since they start out in standalone
2946 * mode. When joining a bridge, learning will be configured to
2947 * match the bridge port settings. Enable learning on all
2948 * DSA/CPU ports. NOTE: FROM_CPU frames always bypass the
2949 * learning process.
2950 *
2951 * Disable HoldAt1, IntOnAgeOut, LockedPort, IgnoreWrongData,
2952 * and RefreshLocked. I.e. setup standard automatic learning.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002953 */
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002954 if (dsa_is_user_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002955 reg = 0;
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002956 else
2957 reg = 1 << port;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002958
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002959 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2960 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002961 if (err)
2962 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002963
2964 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002965 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2966 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002967 if (err)
2968 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002969
Vivien Didelot08984322017-06-08 18:34:12 -04002970 if (chip->info->ops->port_pause_limit) {
2971 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002972 if (err)
2973 return err;
2974 }
2975
Vivien Didelotc8c94892017-03-11 16:13:01 -05002976 if (chip->info->ops->port_disable_learn_limit) {
2977 err = chip->info->ops->port_disable_learn_limit(chip, port);
2978 if (err)
2979 return err;
2980 }
2981
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002982 if (chip->info->ops->port_disable_pri_override) {
2983 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002984 if (err)
2985 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002986 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002987
Andrew Lunnef0a7312016-12-03 04:35:16 +01002988 if (chip->info->ops->port_tag_remap) {
2989 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002990 if (err)
2991 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002992 }
2993
Andrew Lunnef70b112016-12-03 04:45:18 +01002994 if (chip->info->ops->port_egress_rate_limiting) {
2995 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002996 if (err)
2997 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002998 }
2999
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003000 if (chip->info->ops->port_setup_message_port) {
3001 err = chip->info->ops->port_setup_message_port(chip, port);
3002 if (err)
3003 return err;
3004 }
Guenter Roeckd827e882015-03-26 18:36:29 -07003005
Vivien Didelot207afda2016-04-14 14:42:09 -04003006 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05003007 * database, and allow bidirectional communication between the
3008 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07003009 */
Vladimir Oltean5bded822021-10-07 19:47:11 +03003010 err = mv88e6xxx_port_set_fid(chip, port, MV88E6XXX_FID_STANDALONE);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02003011 if (err)
3012 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05003013
Vivien Didelot240ea3e2017-03-30 17:37:12 -04003014 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02003015 if (err)
3016 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07003017
3018 /* Default VLAN ID and priority: don't set a default VLAN
3019 * ID, and set the default packet priority to zero.
3020 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04003021 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02003022}
3023
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003024static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
3025{
3026 struct mv88e6xxx_chip *chip = ds->priv;
3027
3028 if (chip->info->ops->port_set_jumbo_size)
Andrew Lunnb9c587f2021-09-26 19:41:26 +02003029 return 10240 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
Chris Packham1baf0fa2020-07-24 11:21:22 +12003030 else if (chip->info->ops->set_max_frame_size)
Andrew Lunnb9c587f2021-09-26 19:41:26 +02003031 return 1632 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
3032 return 1522 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003033}
3034
3035static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
3036{
3037 struct mv88e6xxx_chip *chip = ds->priv;
3038 int ret = 0;
3039
Andrew Lunnb9c587f2021-09-26 19:41:26 +02003040 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
3041 new_mtu += EDSA_HLEN;
3042
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003043 mv88e6xxx_reg_lock(chip);
3044 if (chip->info->ops->port_set_jumbo_size)
3045 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12003046 else if (chip->info->ops->set_max_frame_size)
3047 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003048 else
3049 if (new_mtu > 1522)
3050 ret = -EINVAL;
3051 mv88e6xxx_reg_unlock(chip);
3052
3053 return ret;
3054}
3055
Andrew Lunn04aca992017-05-26 01:03:24 +02003056static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
3057 struct phy_device *phydev)
3058{
3059 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04003060 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02003061
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003062 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04003063 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003064 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02003065
3066 return err;
3067}
3068
Andrew Lunn75104db2019-02-24 20:44:43 +01003069static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02003070{
3071 struct mv88e6xxx_chip *chip = ds->priv;
3072
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003073 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04003074 if (mv88e6xxx_serdes_power(chip, port, false))
3075 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003076 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02003077}
3078
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003079static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
3080 unsigned int ageing_time)
3081{
Vivien Didelot04bed142016-08-31 18:06:13 -04003082 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003083 int err;
3084
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003085 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05003086 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003087 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003088
3089 return err;
3090}
3091
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003092static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04003093{
3094 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04003095
Andrew Lunnde2273872016-11-21 23:27:01 +01003096 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003097 if (chip->info->ops->stats_set_histogram) {
3098 err = chip->info->ops->stats_set_histogram(chip);
3099 if (err)
3100 return err;
3101 }
Andrew Lunnde2273872016-11-21 23:27:01 +01003102
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003103 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04003104}
3105
Andrew Lunnea890982019-01-09 00:24:03 +01003106/* Check if the errata has already been applied. */
3107static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
3108{
3109 int port;
3110 int err;
3111 u16 val;
3112
3113 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02003114 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01003115 if (err) {
3116 dev_err(chip->dev,
3117 "Error reading hidden register: %d\n", err);
3118 return false;
3119 }
3120 if (val != 0x01c0)
3121 return false;
3122 }
3123
3124 return true;
3125}
3126
3127/* The 6390 copper ports have an errata which require poking magic
3128 * values into undocumented hidden registers and then performing a
3129 * software reset.
3130 */
3131static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
3132{
3133 int port;
3134 int err;
3135
3136 if (mv88e6390_setup_errata_applied(chip))
3137 return 0;
3138
3139 /* Set the ports into blocking mode */
3140 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
3141 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
3142 if (err)
3143 return err;
3144 }
3145
3146 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02003147 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01003148 if (err)
3149 return err;
3150 }
3151
3152 return mv88e6xxx_software_reset(chip);
3153}
3154
Andrew Lunn23e8b472019-10-25 01:03:52 +02003155static void mv88e6xxx_teardown(struct dsa_switch *ds)
3156{
3157 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003158 dsa_devlink_resources_unregister(ds);
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003159 mv88e6xxx_teardown_devlink_regions_global(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02003160}
3161
Vivien Didelotf81ec902016-05-09 13:22:58 -04003162static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07003163{
Vivien Didelot04bed142016-08-31 18:06:13 -04003164 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003165 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04003166 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04003167 int i;
3168
Vivien Didelotfad09c72016-06-21 12:28:20 -04003169 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003170 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003171
Vladimir Olteance5df682021-07-22 18:55:41 +03003172 /* Since virtual bridges are mapped in the PVT, the number we support
3173 * depends on the physical switch topology. We need to let DSA figure
3174 * that out and therefore we cannot set this at dsa_register_switch()
3175 * time.
3176 */
3177 if (mv88e6xxx_has_pvt(chip))
3178 ds->num_fwd_offloading_bridges = MV88E6XXX_MAX_PVT_SWITCHES -
3179 ds->dst->last_switch - 1;
3180
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003181 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003182
Andrew Lunnea890982019-01-09 00:24:03 +01003183 if (chip->info->ops->setup_errata) {
3184 err = chip->info->ops->setup_errata(chip);
3185 if (err)
3186 goto unlock;
3187 }
3188
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003189 /* Cache the cmode of each port. */
3190 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3191 if (chip->info->ops->port_get_cmode) {
3192 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
3193 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03003194 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003195
3196 chip->ports[i].cmode = cmode;
3197 }
3198 }
3199
Vladimir Oltean5bded822021-10-07 19:47:11 +03003200 err = mv88e6xxx_vtu_setup(chip);
3201 if (err)
3202 goto unlock;
3203
Vivien Didelot97299342016-07-18 20:45:30 -04003204 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04003205 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04003206 if (dsa_is_unused_port(ds, i))
3207 continue;
3208
Hubert Feursteinc8574862019-07-31 10:23:48 +02003209 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04003210 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02003211 dev_err(chip->dev, "port %d is invalid\n", i);
3212 err = -EINVAL;
3213 goto unlock;
3214 }
3215
Vivien Didelot97299342016-07-18 20:45:30 -04003216 err = mv88e6xxx_setup_port(chip, i);
3217 if (err)
3218 goto unlock;
3219 }
3220
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003221 err = mv88e6xxx_irl_setup(chip);
3222 if (err)
3223 goto unlock;
3224
Vivien Didelot04a69a12017-10-13 14:18:05 -04003225 err = mv88e6xxx_mac_setup(chip);
3226 if (err)
3227 goto unlock;
3228
Vivien Didelot1b17aed2017-05-26 18:03:05 -04003229 err = mv88e6xxx_phy_setup(chip);
3230 if (err)
3231 goto unlock;
3232
Vivien Didelot81228992017-03-30 17:37:08 -04003233 err = mv88e6xxx_pvt_setup(chip);
3234 if (err)
3235 goto unlock;
3236
Vivien Didelota2ac29d2017-03-11 16:12:49 -05003237 err = mv88e6xxx_atu_setup(chip);
3238 if (err)
3239 goto unlock;
3240
Andrew Lunn87fa8862017-11-09 22:29:56 +01003241 err = mv88e6xxx_broadcast_setup(chip, 0);
3242 if (err)
3243 goto unlock;
3244
Vivien Didelot9e907d72017-07-17 13:03:43 -04003245 err = mv88e6xxx_pot_setup(chip);
3246 if (err)
3247 goto unlock;
3248
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003249 err = mv88e6xxx_rmu_setup(chip);
3250 if (err)
3251 goto unlock;
3252
Vivien Didelot51c901a2017-07-17 13:03:41 -04003253 err = mv88e6xxx_rsvd2cpu_setup(chip);
3254 if (err)
3255 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01003256
Vivien Didelotb28f8722018-04-26 21:56:44 -04003257 err = mv88e6xxx_trunk_setup(chip);
3258 if (err)
3259 goto unlock;
3260
Vivien Didelotc7f047b2018-04-26 21:56:45 -04003261 err = mv88e6xxx_devmap_setup(chip);
3262 if (err)
3263 goto unlock;
3264
Vivien Didelot93e18d62018-05-11 17:16:35 -04003265 err = mv88e6xxx_pri_setup(chip);
3266 if (err)
3267 goto unlock;
3268
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003269 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003270 if (chip->info->ptp_support) {
3271 err = mv88e6xxx_ptp_setup(chip);
3272 if (err)
3273 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003274
3275 err = mv88e6xxx_hwtstamp_setup(chip);
3276 if (err)
3277 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003278 }
3279
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003280 err = mv88e6xxx_stats_setup(chip);
3281 if (err)
3282 goto unlock;
3283
Vivien Didelot6b17e862015-08-13 12:52:18 -04003284unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003285 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02003286
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003287 if (err)
3288 return err;
3289
3290 /* Have to be called without holding the register lock, since
3291 * they take the devlink lock, and we later take the locks in
3292 * the reverse order when getting/setting parameters or
3293 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02003294 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003295 err = mv88e6xxx_setup_devlink_resources(ds);
3296 if (err)
3297 return err;
3298
3299 err = mv88e6xxx_setup_devlink_params(ds);
3300 if (err)
Andrew Lunnbfb25542020-09-18 21:11:07 +02003301 goto out_resources;
3302
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003303 err = mv88e6xxx_setup_devlink_regions_global(ds);
Andrew Lunnbfb25542020-09-18 21:11:07 +02003304 if (err)
3305 goto out_params;
3306
3307 return 0;
3308
3309out_params:
3310 mv88e6xxx_teardown_devlink_params(ds);
3311out_resources:
3312 dsa_devlink_resources_unregister(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003313
3314 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003315}
3316
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003317static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
3318{
3319 return mv88e6xxx_setup_devlink_regions_port(ds, port);
3320}
3321
3322static void mv88e6xxx_port_teardown(struct dsa_switch *ds, int port)
3323{
3324 mv88e6xxx_teardown_devlink_regions_port(ds, port);
3325}
3326
Pali Rohár1fe976d2021-04-12 18:57:39 +02003327/* prod_id for switch families which do not have a PHY model number */
3328static const u16 family_prod_id_table[] = {
3329 [MV88E6XXX_FAMILY_6341] = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3330 [MV88E6XXX_FAMILY_6390] = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Marek Behúnc5d015b2021-04-20 09:54:02 +02003331 [MV88E6XXX_FAMILY_6393] = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
Pali Rohár1fe976d2021-04-12 18:57:39 +02003332};
3333
Vivien Didelote57e5e72016-08-15 17:19:00 -04003334static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003335{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003336 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3337 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Pali Rohár1fe976d2021-04-12 18:57:39 +02003338 u16 prod_id;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003339 u16 val;
3340 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003341
Andrew Lunnee26a222017-01-24 14:53:48 +01003342 if (!chip->info->ops->phy_read)
3343 return -EOPNOTSUPP;
3344
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003345 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003346 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003347 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003348
Pali Rohár1fe976d2021-04-12 18:57:39 +02003349 /* Some internal PHYs don't have a model number. */
3350 if (reg == MII_PHYSID2 && !(val & 0x3f0) &&
3351 chip->info->family < ARRAY_SIZE(family_prod_id_table)) {
3352 prod_id = family_prod_id_table[chip->info->family];
3353 if (prod_id)
3354 val |= prod_id >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003355 }
3356
Vivien Didelote57e5e72016-08-15 17:19:00 -04003357 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003358}
3359
Vivien Didelote57e5e72016-08-15 17:19:00 -04003360static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003361{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003362 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3363 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003364 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003365
Andrew Lunnee26a222017-01-24 14:53:48 +01003366 if (!chip->info->ops->phy_write)
3367 return -EOPNOTSUPP;
3368
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003369 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003370 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003371 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003372
3373 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003374}
3375
Vivien Didelotfad09c72016-06-21 12:28:20 -04003376static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003377 struct device_node *np,
3378 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003379{
3380 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003381 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003382 struct mii_bus *bus;
3383 int err;
3384
Andrew Lunn2510bab2018-02-22 01:51:49 +01003385 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003386 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003387 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003388 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003389
3390 if (err)
3391 return err;
3392 }
3393
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003394 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003395 if (!bus)
3396 return -ENOMEM;
3397
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003398 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003399 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003400 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003401 INIT_LIST_HEAD(&mdio_bus->list);
3402 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003403
Andrew Lunnb516d452016-06-04 21:17:06 +02003404 if (np) {
3405 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003406 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003407 } else {
3408 bus->name = "mv88e6xxx SMI";
3409 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3410 }
3411
3412 bus->read = mv88e6xxx_mdio_read;
3413 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003414 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003415
Andrew Lunn6f882842018-03-17 20:32:05 +01003416 if (!external) {
3417 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3418 if (err)
3419 return err;
3420 }
3421
Florian Fainelli00e798c2018-05-15 16:56:19 -07003422 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003423 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003424 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003425 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003426 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003427 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003428
3429 if (external)
3430 list_add_tail(&mdio_bus->list, &chip->mdios);
3431 else
3432 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003433
3434 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003435}
3436
Andrew Lunn3126aee2017-12-07 01:05:57 +01003437static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3438
3439{
3440 struct mv88e6xxx_mdio_bus *mdio_bus;
3441 struct mii_bus *bus;
3442
3443 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3444 bus = mdio_bus->bus;
3445
Andrew Lunn6f882842018-03-17 20:32:05 +01003446 if (!mdio_bus->external)
3447 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3448
Andrew Lunn3126aee2017-12-07 01:05:57 +01003449 mdiobus_unregister(bus);
3450 }
3451}
3452
Andrew Lunna3c53be52017-01-24 14:53:50 +01003453static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3454 struct device_node *np)
3455{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003456 struct device_node *child;
3457 int err;
3458
3459 /* Always register one mdio bus for the internal/default mdio
3460 * bus. This maybe represented in the device tree, but is
3461 * optional.
3462 */
3463 child = of_get_child_by_name(np, "mdio");
3464 err = mv88e6xxx_mdio_register(chip, child, false);
3465 if (err)
3466 return err;
3467
3468 /* Walk the device tree, and see if there are any other nodes
3469 * which say they are compatible with the external mdio
3470 * bus.
3471 */
3472 for_each_available_child_of_node(np, child) {
Andrew Lunnceb96fa2020-09-01 04:32:57 +02003473 if (of_device_is_compatible(
3474 child, "marvell,mv88e6xxx-mdio-external")) {
Andrew Lunna3c53be52017-01-24 14:53:50 +01003475 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003476 if (err) {
3477 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303478 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003479 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003480 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003481 }
3482 }
3483
3484 return 0;
3485}
3486
Vivien Didelot855b1932016-07-20 18:18:35 -04003487static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3488{
Vivien Didelot04bed142016-08-31 18:06:13 -04003489 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003490
3491 return chip->eeprom_len;
3492}
3493
Vivien Didelot855b1932016-07-20 18:18:35 -04003494static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3495 struct ethtool_eeprom *eeprom, u8 *data)
3496{
Vivien Didelot04bed142016-08-31 18:06:13 -04003497 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003498 int err;
3499
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003500 if (!chip->info->ops->get_eeprom)
3501 return -EOPNOTSUPP;
3502
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003503 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003504 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003505 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003506
3507 if (err)
3508 return err;
3509
3510 eeprom->magic = 0xc3ec4951;
3511
3512 return 0;
3513}
3514
Vivien Didelot855b1932016-07-20 18:18:35 -04003515static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3516 struct ethtool_eeprom *eeprom, u8 *data)
3517{
Vivien Didelot04bed142016-08-31 18:06:13 -04003518 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003519 int err;
3520
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003521 if (!chip->info->ops->set_eeprom)
3522 return -EOPNOTSUPP;
3523
Vivien Didelot855b1932016-07-20 18:18:35 -04003524 if (eeprom->magic != 0xc3ec4951)
3525 return -EINVAL;
3526
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003527 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003528 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003529 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003530
3531 return err;
3532}
3533
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003534static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003535 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003536 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3537 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003538 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003539 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003540 .phy_read = mv88e6185_phy_ppu_read,
3541 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003542 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003543 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003544 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003545 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003546 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003547 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3548 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003549 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003550 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003551 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003552 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003553 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003554 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003555 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003556 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003557 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003558 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3559 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003560 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003561 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3562 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003563 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003564 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003565 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003566 .ppu_enable = mv88e6185_g1_ppu_enable,
3567 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003568 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003569 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003570 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003571 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003572 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003573 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003574};
3575
3576static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003577 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003578 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3579 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003580 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003581 .phy_read = mv88e6185_phy_ppu_read,
3582 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003583 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003584 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003585 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003586 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003587 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3588 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunna23b2962017-02-04 20:15:28 +01003589 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003590 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003591 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003592 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003593 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003594 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3595 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003596 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003597 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003598 .serdes_power = mv88e6185_serdes_power,
3599 .serdes_get_lane = mv88e6185_serdes_get_lane,
3600 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003601 .ppu_enable = mv88e6185_g1_ppu_enable,
3602 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003603 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003604 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003605 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003606 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003607 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003608};
3609
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003610static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003611 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003612 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3613 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003614 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003615 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3616 .phy_read = mv88e6xxx_g2_smi_phy_read,
3617 .phy_write = mv88e6xxx_g2_smi_phy_write,
3618 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003619 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003620 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003621 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003622 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003623 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3624 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003625 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003626 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003627 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003628 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003629 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003630 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003631 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003632 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003633 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003634 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3635 .stats_get_strings = mv88e6095_stats_get_strings,
3636 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003637 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3638 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003639 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003640 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003641 .serdes_power = mv88e6185_serdes_power,
3642 .serdes_get_lane = mv88e6185_serdes_get_lane,
3643 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Chris Packham5c19bc82020-11-24 17:34:39 +13003644 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3645 .serdes_irq_enable = mv88e6097_serdes_irq_enable,
3646 .serdes_irq_status = mv88e6097_serdes_irq_status,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003647 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003648 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003649 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003650 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003651 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003652 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003653 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003654};
3655
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003656static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003657 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003658 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3659 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003660 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003661 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003662 .phy_read = mv88e6xxx_g2_smi_phy_read,
3663 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003664 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003665 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003666 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003667 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003668 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3669 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003670 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003671 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003672 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003673 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003674 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003675 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003676 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3677 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003678 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003679 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3680 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003681 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003682 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003683 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003684 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003685 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3686 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003687 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003688 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003689 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003690 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003691};
3692
3693static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003694 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003695 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3696 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003697 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003698 .phy_read = mv88e6185_phy_ppu_read,
3699 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003700 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003701 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003702 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003703 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003704 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003705 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3706 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003707 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003708 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003709 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003710 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003711 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003712 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003713 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003714 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003715 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003716 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003717 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3718 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003719 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003720 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3721 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003722 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003723 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003724 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003725 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003726 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003727 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003728 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003729 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003730 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003731};
3732
Vivien Didelot990e27b2017-03-28 13:50:32 -04003733static const struct mv88e6xxx_ops mv88e6141_ops = {
3734 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003735 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3736 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003737 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003738 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3739 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3740 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3741 .phy_read = mv88e6xxx_g2_smi_phy_read,
3742 .phy_write = mv88e6xxx_g2_smi_phy_write,
3743 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003744 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003745 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003746 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003747 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003748 .port_tag_remap = mv88e6095_port_tag_remap,
Marek Behún7da467d2021-07-01 00:22:26 +02003749 .port_set_policy = mv88e6352_port_set_policy,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003750 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003751 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3752 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003753 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003754 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003755 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003756 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003757 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3758 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003759 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003760 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003761 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003762 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Marek Behún11527f32021-07-01 00:22:27 +02003763 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003764 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3765 .stats_get_strings = mv88e6320_stats_get_strings,
3766 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003767 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3768 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003769 .watchdog_ops = &mv88e6390_watchdog_ops,
3770 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003771 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003772 .reset = mv88e6352_g1_reset,
Marek Behún37094882021-07-01 00:22:28 +02003773 .rmu_disable = mv88e6390_g1_rmu_disable,
Marek Behúnc07fff32021-07-01 00:22:29 +02003774 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3775 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003776 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003777 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003778 .serdes_power = mv88e6390_serdes_power,
3779 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003780 /* Check status register pause & lpa register */
3781 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3782 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3783 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3784 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003785 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003786 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003787 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003788 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúna03b98d2021-07-01 00:22:30 +02003789 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
3790 .serdes_get_strings = mv88e6390_serdes_get_strings,
3791 .serdes_get_stats = mv88e6390_serdes_get_stats,
Marek Behún953b0dc2021-07-01 00:22:31 +02003792 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3793 .serdes_get_regs = mv88e6390_serdes_get_regs,
Marek Behúne3af71a2019-02-25 12:39:55 +01003794 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003795};
3796
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003797static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003798 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003799 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3800 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003801 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003802 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003803 .phy_read = mv88e6xxx_g2_smi_phy_read,
3804 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003805 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003806 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003807 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003808 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003809 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003810 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3811 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003812 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003813 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003814 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003815 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003816 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003817 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003818 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003819 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003820 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003821 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3822 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003823 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003824 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3825 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003826 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003827 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003828 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003829 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003830 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3831 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003832 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003833 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003834 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003835 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003836 .phylink_validate = mv88e6185_phylink_validate,
Andrew Lunnfe230362021-09-26 19:41:24 +02003837 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003838};
3839
3840static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003841 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003842 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3843 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003844 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003845 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003846 .phy_read = mv88e6165_phy_read,
3847 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003848 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003849 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003850 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003851 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003852 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003853 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003854 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003855 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003856 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003857 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3858 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003859 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003860 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3861 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003862 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003863 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003864 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003865 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003866 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3867 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003868 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003869 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003870 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003871 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003872 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003873};
3874
3875static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003876 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003877 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3878 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003879 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003880 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003881 .phy_read = mv88e6xxx_g2_smi_phy_read,
3882 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003883 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003884 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003885 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003886 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003887 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003888 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003889 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3890 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003891 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003892 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003893 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003894 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003895 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003896 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003897 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003898 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003899 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003900 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003901 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3902 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003903 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003904 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3905 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003906 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003907 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003908 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003909 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003910 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3911 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003912 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003913 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003914 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003915};
3916
3917static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003918 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003919 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3920 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003921 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003922 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3923 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003924 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003925 .phy_read = mv88e6xxx_g2_smi_phy_read,
3926 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003927 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003928 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003929 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003930 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003931 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003932 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003933 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003934 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3935 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003936 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003937 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003938 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003939 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003940 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003941 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003942 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003943 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003944 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003945 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003946 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3947 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003948 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003949 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3950 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003951 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003952 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003953 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003954 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003955 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003956 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3957 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003958 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003959 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003960 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003961 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3962 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3963 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3964 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003965 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003966 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3967 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003968 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003969 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003970};
3971
3972static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003973 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003974 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3975 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003976 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003977 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003978 .phy_read = mv88e6xxx_g2_smi_phy_read,
3979 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003980 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003981 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003982 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003983 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003984 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003985 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003986 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3987 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003988 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003989 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003990 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003991 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003992 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003993 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003994 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003995 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003996 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003997 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003998 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3999 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004000 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004001 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4002 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004003 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004004 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004005 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004006 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004007 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4008 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004009 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004010 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004011 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004012};
4013
4014static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004015 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004016 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4017 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004018 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004019 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4020 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004021 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004022 .phy_read = mv88e6xxx_g2_smi_phy_read,
4023 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004024 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004025 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004026 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004027 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004028 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004029 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004030 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004031 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4032 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004033 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004034 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004035 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004036 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004037 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004038 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004039 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004040 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004041 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004042 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004043 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4044 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004045 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004046 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4047 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004048 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004049 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004050 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004051 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004052 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004053 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4054 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004055 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004056 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004057 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004058 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4059 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4060 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4061 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004062 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004063 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004064 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004065 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004066 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4067 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004068 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004069 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004070};
4071
4072static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004073 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004074 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4075 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004076 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04004077 .phy_read = mv88e6185_phy_ppu_read,
4078 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004079 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004080 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004081 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004082 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004083 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
4084 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunnef70b112016-12-03 04:45:18 +01004085 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01004086 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02004087 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004088 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004089 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004090 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004091 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004092 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4093 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004094 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004095 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4096 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004097 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004098 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13004099 .serdes_power = mv88e6185_serdes_power,
4100 .serdes_get_lane = mv88e6185_serdes_get_lane,
4101 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelot02317e62018-05-09 11:38:49 -04004102 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05004103 .ppu_enable = mv88e6185_g1_ppu_enable,
4104 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004105 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004106 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004107 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004108 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12004109 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004110};
4111
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004112static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004113 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004114 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004115 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004116 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4117 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004118 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4119 .phy_read = mv88e6xxx_g2_smi_phy_read,
4120 .phy_write = mv88e6xxx_g2_smi_phy_write,
4121 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004122 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004123 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004124 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004125 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004126 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004127 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004128 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004129 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4130 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004131 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12004132 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04004133 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004134 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004135 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004136 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004137 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004138 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004139 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004140 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004141 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4142 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004143 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004144 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4145 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004146 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004147 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004148 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004149 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004150 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004151 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4152 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004153 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4154 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004155 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004156 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004157 /* Check status register pause & lpa register */
4158 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4159 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4160 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4161 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004162 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004163 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004164 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004165 .serdes_get_strings = mv88e6390_serdes_get_strings,
4166 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004167 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4168 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004169 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004170 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004171};
4172
4173static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004174 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004175 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004176 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004177 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4178 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004179 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4180 .phy_read = mv88e6xxx_g2_smi_phy_read,
4181 .phy_write = mv88e6xxx_g2_smi_phy_write,
4182 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004183 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004184 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004185 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004186 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004187 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004188 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004189 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004190 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4191 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004192 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12004193 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04004194 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004195 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004196 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004197 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004198 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004199 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004200 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004201 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004202 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4203 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004204 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004205 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4206 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004207 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004208 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004209 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004210 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004211 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004212 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4213 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004214 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4215 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004216 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004217 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004218 /* Check status register pause & lpa register */
4219 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4220 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4221 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4222 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004223 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004224 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004225 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004226 .serdes_get_strings = mv88e6390_serdes_get_strings,
4227 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004228 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4229 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004230 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004231 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004232};
4233
4234static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004235 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004236 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004237 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004238 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4239 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004240 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4241 .phy_read = mv88e6xxx_g2_smi_phy_read,
4242 .phy_write = mv88e6xxx_g2_smi_phy_write,
4243 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004244 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004245 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004246 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004247 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004248 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004249 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004250 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4251 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004252 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004253 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004254 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004255 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004256 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004257 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004258 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004259 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004260 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004261 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4262 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004263 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004264 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4265 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004266 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004267 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004268 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004269 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004270 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004271 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4272 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004273 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4274 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004275 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004276 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004277 /* Check status register pause & lpa register */
4278 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4279 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4280 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4281 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004282 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004283 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004284 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004285 .serdes_get_strings = mv88e6390_serdes_get_strings,
4286 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004287 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4288 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004289 .avb_ops = &mv88e6390_avb_ops,
4290 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004291 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004292};
4293
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004294static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004295 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004296 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4297 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004298 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004299 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4300 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004301 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004302 .phy_read = mv88e6xxx_g2_smi_phy_read,
4303 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004304 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004305 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004306 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004307 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004308 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004309 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004310 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004311 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4312 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004313 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004314 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004315 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004316 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004317 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004318 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004319 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004320 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004321 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004322 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004323 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4324 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004325 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004326 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4327 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004328 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004329 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004330 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004331 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004332 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004333 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4334 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004335 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004336 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004337 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004338 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4339 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4340 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4341 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004342 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004343 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004344 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004345 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004346 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4347 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004348 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004349 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004350 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004351 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004352};
4353
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004354static const struct mv88e6xxx_ops mv88e6250_ops = {
4355 /* MV88E6XXX_FAMILY_6250 */
4356 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4357 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4358 .irl_init_all = mv88e6352_g2_irl_init_all,
4359 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4360 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4361 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4362 .phy_read = mv88e6xxx_g2_smi_phy_read,
4363 .phy_write = mv88e6xxx_g2_smi_phy_write,
4364 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004365 .port_sync_link = mv88e6xxx_port_sync_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004366 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004367 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004368 .port_tag_remap = mv88e6095_port_tag_remap,
4369 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004370 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4371 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004372 .port_set_ether_type = mv88e6351_port_set_ether_type,
4373 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4374 .port_pause_limit = mv88e6097_port_pause_limit,
4375 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004376 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4377 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4378 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4379 .stats_get_strings = mv88e6250_stats_get_strings,
4380 .stats_get_stats = mv88e6250_stats_get_stats,
4381 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4382 .set_egress_port = mv88e6095_g1_set_egress_port,
4383 .watchdog_ops = &mv88e6250_watchdog_ops,
4384 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4385 .pot_clear = mv88e6xxx_g2_pot_clear,
4386 .reset = mv88e6250_g1_reset,
Rasmus Villemoes67c9ed12021-01-25 16:04:48 +01004387 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Rasmus Villemoesb28f3f32021-01-25 16:04:49 +01004388 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004389 .avb_ops = &mv88e6352_avb_ops,
4390 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004391 .phylink_validate = mv88e6065_phylink_validate,
4392};
4393
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004394static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004395 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004396 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004397 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004398 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4399 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004400 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4401 .phy_read = mv88e6xxx_g2_smi_phy_read,
4402 .phy_write = mv88e6xxx_g2_smi_phy_write,
4403 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004404 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004405 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004406 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004407 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004408 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004409 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004410 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004411 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4412 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004413 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004414 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004415 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004416 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004417 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004418 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004419 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004420 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004421 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004422 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4423 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004424 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004425 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4426 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004427 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004428 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004429 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004430 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004431 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004432 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4433 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004434 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4435 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004436 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004437 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004438 /* Check status register pause & lpa register */
4439 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4440 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4441 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4442 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004443 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004444 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004445 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004446 .serdes_get_strings = mv88e6390_serdes_get_strings,
4447 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004448 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4449 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004450 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004451 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004452 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004453 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004454};
4455
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004456static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004457 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004458 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4459 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004460 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004461 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4462 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004463 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004464 .phy_read = mv88e6xxx_g2_smi_phy_read,
4465 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004466 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004467 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004468 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004469 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004470 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004471 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4472 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004473 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004474 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004475 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004476 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004477 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004478 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004479 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004480 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004481 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004482 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004483 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4484 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004485 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004486 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4487 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004488 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004489 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004490 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004491 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004492 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004493 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004494 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004495 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004496 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004497 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004498};
4499
4500static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004501 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004502 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4503 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004504 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004505 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4506 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004507 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004508 .phy_read = mv88e6xxx_g2_smi_phy_read,
4509 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004510 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004511 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004512 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004513 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004514 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004515 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4516 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004517 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004518 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004519 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004520 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004521 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004522 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004523 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004524 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004525 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004526 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004527 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4528 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004529 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004530 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4531 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004532 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004533 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004534 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004535 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004536 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004537 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004538 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004539 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004540};
4541
Vivien Didelot16e329a2017-03-28 13:50:33 -04004542static const struct mv88e6xxx_ops mv88e6341_ops = {
4543 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004544 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4545 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004546 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004547 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4548 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4549 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4550 .phy_read = mv88e6xxx_g2_smi_phy_read,
4551 .phy_write = mv88e6xxx_g2_smi_phy_write,
4552 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004553 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004554 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004555 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004556 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004557 .port_tag_remap = mv88e6095_port_tag_remap,
Marek Behún7da467d2021-07-01 00:22:26 +02004558 .port_set_policy = mv88e6352_port_set_policy,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004559 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004560 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4561 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004562 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004563 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004564 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004565 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004566 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4567 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004568 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004569 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004570 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004571 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Marek Behún11527f32021-07-01 00:22:27 +02004572 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004573 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4574 .stats_get_strings = mv88e6320_stats_get_strings,
4575 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004576 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4577 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004578 .watchdog_ops = &mv88e6390_watchdog_ops,
4579 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004580 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004581 .reset = mv88e6352_g1_reset,
Marek Behún37094882021-07-01 00:22:28 +02004582 .rmu_disable = mv88e6390_g1_rmu_disable,
Marek Behúnc07fff32021-07-01 00:22:29 +02004583 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4584 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004585 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004586 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004587 .serdes_power = mv88e6390_serdes_power,
4588 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004589 /* Check status register pause & lpa register */
4590 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4591 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4592 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4593 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004594 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004595 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004596 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004597 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004598 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004599 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúna03b98d2021-07-01 00:22:30 +02004600 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4601 .serdes_get_strings = mv88e6390_serdes_get_strings,
4602 .serdes_get_stats = mv88e6390_serdes_get_stats,
Marek Behún953b0dc2021-07-01 00:22:31 +02004603 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4604 .serdes_get_regs = mv88e6390_serdes_get_regs,
Marek Behúne3af71a2019-02-25 12:39:55 +01004605 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004606};
4607
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004608static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004609 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004610 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4611 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004612 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004613 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004614 .phy_read = mv88e6xxx_g2_smi_phy_read,
4615 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004616 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004617 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004618 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004619 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004620 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004621 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004622 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4623 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004624 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004625 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004626 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004627 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004628 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004629 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004630 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004631 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004632 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004633 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004634 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4635 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004636 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004637 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4638 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004639 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004640 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004641 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004642 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004643 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4644 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004645 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004646 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004647 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004648};
4649
4650static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004651 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004652 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4653 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004654 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004655 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004656 .phy_read = mv88e6xxx_g2_smi_phy_read,
4657 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004658 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004659 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004660 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004661 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004662 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004663 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004664 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4665 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004666 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004667 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004668 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004669 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004670 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004671 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004672 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004673 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004674 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004675 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004676 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4677 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004678 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004679 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4680 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004681 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004682 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004683 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004684 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004685 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4686 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004687 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004688 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004689 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004690 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004691 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004692};
4693
4694static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004695 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004696 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4697 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004698 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004699 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4700 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004701 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004702 .phy_read = mv88e6xxx_g2_smi_phy_read,
4703 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004704 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004705 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004706 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004707 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004708 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004709 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004710 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004711 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4712 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004713 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004714 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004715 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004716 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004717 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004718 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004719 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004720 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004721 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004722 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004723 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4724 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004725 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004726 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4727 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004728 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004729 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004730 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004731 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004732 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004733 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4734 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004735 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004736 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004737 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004738 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4739 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4740 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4741 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004742 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004743 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004744 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004745 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004746 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004747 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004748 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004749 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4750 .serdes_get_strings = mv88e6352_serdes_get_strings,
4751 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004752 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4753 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004754 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004755};
4756
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004757static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004758 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004759 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004760 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004761 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4762 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004763 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4764 .phy_read = mv88e6xxx_g2_smi_phy_read,
4765 .phy_write = mv88e6xxx_g2_smi_phy_write,
4766 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004767 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004768 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004769 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004770 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004771 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004772 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004773 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004774 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4775 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004776 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004777 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004778 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004779 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004780 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004781 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004782 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004783 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004784 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004785 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004786 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004787 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4788 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004789 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004790 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4791 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004792 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004793 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004794 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004795 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004796 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004797 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4798 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004799 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4800 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004801 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004802 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004803 /* Check status register pause & lpa register */
4804 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4805 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4806 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4807 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004808 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004809 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004810 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004811 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004812 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004813 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004814 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4815 .serdes_get_strings = mv88e6390_serdes_get_strings,
4816 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004817 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4818 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004819 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004820};
4821
4822static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004823 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004824 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004825 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004826 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4827 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004828 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4829 .phy_read = mv88e6xxx_g2_smi_phy_read,
4830 .phy_write = mv88e6xxx_g2_smi_phy_write,
4831 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004832 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004833 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004834 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004835 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004836 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004837 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004838 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004839 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4840 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004841 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004842 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004843 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004844 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004845 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004846 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004847 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004848 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004849 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004850 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004851 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004852 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4853 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004854 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004855 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4856 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004857 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004858 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004859 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004860 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004861 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004862 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4863 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004864 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4865 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004866 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004867 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004868 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4869 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4870 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4871 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004872 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004873 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004874 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004875 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4876 .serdes_get_strings = mv88e6390_serdes_get_strings,
4877 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004878 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4879 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004880 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004881 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004882 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004883 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004884};
4885
Pavana Sharmade776d02021-03-17 14:46:42 +01004886static const struct mv88e6xxx_ops mv88e6393x_ops = {
4887 /* MV88E6XXX_FAMILY_6393 */
4888 .setup_errata = mv88e6393x_serdes_setup_errata,
4889 .irl_init_all = mv88e6390_g2_irl_init_all,
4890 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4891 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4892 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4893 .phy_read = mv88e6xxx_g2_smi_phy_read,
4894 .phy_write = mv88e6xxx_g2_smi_phy_write,
4895 .port_set_link = mv88e6xxx_port_set_link,
4896 .port_sync_link = mv88e6xxx_port_sync_link,
4897 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4898 .port_set_speed_duplex = mv88e6393x_port_set_speed_duplex,
4899 .port_max_speed_mode = mv88e6393x_port_max_speed_mode,
4900 .port_tag_remap = mv88e6390_port_tag_remap,
Marek Behún6584b262021-03-17 14:46:43 +01004901 .port_set_policy = mv88e6393x_port_set_policy,
Pavana Sharmade776d02021-03-17 14:46:42 +01004902 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4903 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4904 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4905 .port_set_ether_type = mv88e6393x_port_set_ether_type,
4906 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4907 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4908 .port_pause_limit = mv88e6390_port_pause_limit,
4909 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4910 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4911 .port_get_cmode = mv88e6352_port_get_cmode,
4912 .port_set_cmode = mv88e6393x_port_set_cmode,
4913 .port_setup_message_port = mv88e6xxx_setup_message_port,
4914 .port_set_upstream_port = mv88e6393x_port_set_upstream_port,
4915 .stats_snapshot = mv88e6390_g1_stats_snapshot,
4916 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4917 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4918 .stats_get_strings = mv88e6320_stats_get_strings,
4919 .stats_get_stats = mv88e6390_stats_get_stats,
4920 /* .set_cpu_port is missing because this family does not support a global
4921 * CPU port, only per port CPU port which is set via
4922 * .port_set_upstream_port method.
4923 */
4924 .set_egress_port = mv88e6393x_set_egress_port,
4925 .watchdog_ops = &mv88e6390_watchdog_ops,
4926 .mgmt_rsvd2cpu = mv88e6393x_port_mgmt_rsvd2cpu,
4927 .pot_clear = mv88e6xxx_g2_pot_clear,
4928 .reset = mv88e6352_g1_reset,
4929 .rmu_disable = mv88e6390_g1_rmu_disable,
4930 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4931 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4932 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4933 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4934 .serdes_power = mv88e6393x_serdes_power,
4935 .serdes_get_lane = mv88e6393x_serdes_get_lane,
4936 .serdes_pcs_get_state = mv88e6393x_serdes_pcs_get_state,
4937 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4938 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4939 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4940 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4941 .serdes_irq_enable = mv88e6393x_serdes_irq_enable,
4942 .serdes_irq_status = mv88e6393x_serdes_irq_status,
4943 /* TODO: serdes stats */
4944 .gpio_ops = &mv88e6352_gpio_ops,
4945 .avb_ops = &mv88e6390_avb_ops,
4946 .ptp_ops = &mv88e6352_ptp_ops,
4947 .phylink_validate = mv88e6393x_phylink_validate,
4948};
4949
Vivien Didelotf81ec902016-05-09 13:22:58 -04004950static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4951 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004952 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004953 .family = MV88E6XXX_FAMILY_6097,
4954 .name = "Marvell 88E6085",
4955 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004956 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004957 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004958 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004959 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004960 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004961 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004962 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004963 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004964 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004965 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004966 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004967 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004968 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004969 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004970 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004971 },
4972
4973 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004974 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004975 .family = MV88E6XXX_FAMILY_6095,
4976 .name = "Marvell 88E6095/88E6095F",
4977 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004978 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004979 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004980 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004981 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004982 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004983 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004984 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004985 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004986 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004987 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004988 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004989 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004990 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004991 },
4992
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004993 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004994 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004995 .family = MV88E6XXX_FAMILY_6097,
4996 .name = "Marvell 88E6097/88E6097F",
4997 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004998 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004999 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01005000 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005001 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005002 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005003 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005004 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005005 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005006 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01005007 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005008 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005009 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005010 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005011 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005012 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005013 .ops = &mv88e6097_ops,
5014 },
5015
Vivien Didelotf81ec902016-05-09 13:22:58 -04005016 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005017 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005018 .family = MV88E6XXX_FAMILY_6165,
5019 .name = "Marvell 88E6123",
5020 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005021 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005022 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01005023 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005024 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005025 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005026 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005027 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005028 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005029 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005030 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005031 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005032 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005033 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005034 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005035 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005036 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005037 },
5038
5039 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005040 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005041 .family = MV88E6XXX_FAMILY_6185,
5042 .name = "Marvell 88E6131",
5043 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005044 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005045 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005046 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005047 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005048 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005049 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005050 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005051 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005052 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005053 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05005054 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005055 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005056 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005057 },
5058
Vivien Didelot990e27b2017-03-28 13:50:32 -04005059 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005060 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005061 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01005062 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04005063 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005064 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005065 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005066 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005067 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005068 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005069 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005070 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005071 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005072 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005073 .age_time_coeff = 3750,
5074 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005075 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005076 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005077 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005078 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005079 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005080 .ops = &mv88e6141_ops,
5081 },
5082
Vivien Didelotf81ec902016-05-09 13:22:58 -04005083 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005084 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005085 .family = MV88E6XXX_FAMILY_6165,
5086 .name = "Marvell 88E6161",
5087 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005088 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005089 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005090 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005091 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005092 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005093 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005094 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005095 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005096 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005097 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005098 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005099 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005100 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005101 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005102 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Andrew Lunndfa54342018-07-18 22:38:22 +02005103 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005104 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005105 },
5106
5107 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005108 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005109 .family = MV88E6XXX_FAMILY_6165,
5110 .name = "Marvell 88E6165",
5111 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005112 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005113 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005114 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005115 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005116 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005117 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005118 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005119 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005120 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005121 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005122 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005123 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005124 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005125 .multi_chip = true,
Andrew Lunndfa54342018-07-18 22:38:22 +02005126 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005127 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005128 },
5129
5130 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005131 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005132 .family = MV88E6XXX_FAMILY_6351,
5133 .name = "Marvell 88E6171",
5134 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005135 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005136 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005137 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005138 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005139 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005140 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005141 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005142 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005143 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005144 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005145 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005146 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005147 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005148 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005149 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005150 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005151 },
5152
5153 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005154 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005155 .family = MV88E6XXX_FAMILY_6352,
5156 .name = "Marvell 88E6172",
5157 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005158 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005159 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005160 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005161 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005162 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005163 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005164 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005165 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005166 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005167 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005168 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005169 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005170 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005171 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005172 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005173 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005174 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005175 },
5176
5177 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005178 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005179 .family = MV88E6XXX_FAMILY_6351,
5180 .name = "Marvell 88E6175",
5181 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005182 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005183 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005184 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005185 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005186 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005187 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005188 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005189 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005190 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005191 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005192 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005193 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005194 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005195 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005196 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005197 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005198 },
5199
5200 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005201 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005202 .family = MV88E6XXX_FAMILY_6352,
5203 .name = "Marvell 88E6176",
5204 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005205 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005206 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005207 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005208 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005209 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005210 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005211 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005212 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005213 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005214 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005215 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005216 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005217 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005218 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005219 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005220 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005221 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005222 },
5223
5224 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005225 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005226 .family = MV88E6XXX_FAMILY_6185,
5227 .name = "Marvell 88E6185",
5228 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005229 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005230 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01005231 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005232 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005233 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005234 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005235 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005236 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005237 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005238 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05005239 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005240 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005241 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005242 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005243 },
5244
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005245 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005246 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005247 .family = MV88E6XXX_FAMILY_6390,
5248 .name = "Marvell 88E6190",
5249 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005250 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005251 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005252 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005253 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005254 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005255 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005256 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005257 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005258 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005259 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005260 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005261 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04005262 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005263 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05005264 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005265 .ops = &mv88e6190_ops,
5266 },
5267
5268 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005269 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005270 .family = MV88E6XXX_FAMILY_6390,
5271 .name = "Marvell 88E6190X",
5272 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005273 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005274 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005275 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005276 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005277 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005278 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005279 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005280 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005281 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005282 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005283 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005284 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005285 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005286 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005287 .multi_chip = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005288 .ops = &mv88e6190x_ops,
5289 },
5290
5291 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005292 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005293 .family = MV88E6XXX_FAMILY_6390,
5294 .name = "Marvell 88E6191",
5295 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005296 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005297 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005298 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04005299 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005300 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005301 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005302 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005303 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005304 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005305 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005306 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005307 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005308 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005309 .multi_chip = true,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005310 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04005311 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005312 },
5313
Pavana Sharmade776d02021-03-17 14:46:42 +01005314 [MV88E6191X] = {
5315 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191X,
5316 .family = MV88E6XXX_FAMILY_6393,
5317 .name = "Marvell 88E6191X",
5318 .num_databases = 4096,
5319 .num_ports = 11, /* 10 + Z80 */
5320 .num_internal_phys = 9,
5321 .max_vid = 8191,
5322 .port_base_addr = 0x0,
5323 .phy_base_addr = 0x0,
5324 .global1_addr = 0x1b,
5325 .global2_addr = 0x1c,
5326 .age_time_coeff = 3750,
5327 .g1_irqs = 10,
5328 .g2_irqs = 14,
5329 .atu_move_port_mask = 0x1f,
5330 .pvt = true,
5331 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005332 .ptp_support = true,
5333 .ops = &mv88e6393x_ops,
5334 },
5335
5336 [MV88E6193X] = {
5337 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6193X,
5338 .family = MV88E6XXX_FAMILY_6393,
5339 .name = "Marvell 88E6193X",
5340 .num_databases = 4096,
5341 .num_ports = 11, /* 10 + Z80 */
5342 .num_internal_phys = 9,
5343 .max_vid = 8191,
5344 .port_base_addr = 0x0,
5345 .phy_base_addr = 0x0,
5346 .global1_addr = 0x1b,
5347 .global2_addr = 0x1c,
5348 .age_time_coeff = 3750,
5349 .g1_irqs = 10,
5350 .g2_irqs = 14,
5351 .atu_move_port_mask = 0x1f,
5352 .pvt = true,
5353 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005354 .ptp_support = true,
5355 .ops = &mv88e6393x_ops,
5356 },
5357
Hubert Feurstein49022642019-07-31 10:23:46 +02005358 [MV88E6220] = {
5359 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
5360 .family = MV88E6XXX_FAMILY_6250,
5361 .name = "Marvell 88E6220",
5362 .num_databases = 64,
5363
5364 /* Ports 2-4 are not routed to pins
5365 * => usable ports 0, 1, 5, 6
5366 */
5367 .num_ports = 7,
5368 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02005369 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02005370 .max_vid = 4095,
5371 .port_base_addr = 0x08,
5372 .phy_base_addr = 0x00,
5373 .global1_addr = 0x0f,
5374 .global2_addr = 0x07,
5375 .age_time_coeff = 15000,
5376 .g1_irqs = 9,
5377 .g2_irqs = 10,
5378 .atu_move_port_mask = 0xf,
5379 .dual_chip = true,
Hubert Feurstein71509612019-07-31 10:23:51 +02005380 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02005381 .ops = &mv88e6250_ops,
5382 },
5383
Vivien Didelotf81ec902016-05-09 13:22:58 -04005384 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005385 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005386 .family = MV88E6XXX_FAMILY_6352,
5387 .name = "Marvell 88E6240",
5388 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005389 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005390 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005391 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005392 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005393 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005394 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005395 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005396 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005397 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005398 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005399 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005400 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005401 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005402 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005403 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005404 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005405 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005406 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005407 },
5408
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005409 [MV88E6250] = {
5410 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
5411 .family = MV88E6XXX_FAMILY_6250,
5412 .name = "Marvell 88E6250",
5413 .num_databases = 64,
5414 .num_ports = 7,
5415 .num_internal_phys = 5,
5416 .max_vid = 4095,
5417 .port_base_addr = 0x08,
5418 .phy_base_addr = 0x00,
5419 .global1_addr = 0x0f,
5420 .global2_addr = 0x07,
5421 .age_time_coeff = 15000,
5422 .g1_irqs = 9,
5423 .g2_irqs = 10,
5424 .atu_move_port_mask = 0xf,
5425 .dual_chip = true,
Hubert Feurstein71509612019-07-31 10:23:51 +02005426 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005427 .ops = &mv88e6250_ops,
5428 },
5429
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005430 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005431 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005432 .family = MV88E6XXX_FAMILY_6390,
5433 .name = "Marvell 88E6290",
5434 .num_databases = 4096,
5435 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005436 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005437 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005438 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005439 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005440 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005441 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005442 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005443 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005444 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005445 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005446 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005447 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005448 .multi_chip = true,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005449 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005450 .ops = &mv88e6290_ops,
5451 },
5452
Vivien Didelotf81ec902016-05-09 13:22:58 -04005453 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005454 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005455 .family = MV88E6XXX_FAMILY_6320,
5456 .name = "Marvell 88E6320",
5457 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005458 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005459 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005460 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005461 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005462 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005463 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005464 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005465 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005466 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005467 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005468 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005469 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005470 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005471 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005472 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005473 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005474 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005475 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005476 },
5477
5478 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005479 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005480 .family = MV88E6XXX_FAMILY_6320,
5481 .name = "Marvell 88E6321",
5482 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005483 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005484 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005485 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005486 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005487 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005488 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005489 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005490 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005491 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005492 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005493 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005494 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005495 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005496 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005497 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005498 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005499 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005500 },
5501
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005502 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005503 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005504 .family = MV88E6XXX_FAMILY_6341,
5505 .name = "Marvell 88E6341",
5506 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005507 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005508 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005509 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005510 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005511 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005512 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005513 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005514 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005515 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005516 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005517 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005518 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005519 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005520 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005521 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005522 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005523 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005524 .ops = &mv88e6341_ops,
5525 },
5526
Vivien Didelotf81ec902016-05-09 13:22:58 -04005527 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005528 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005529 .family = MV88E6XXX_FAMILY_6351,
5530 .name = "Marvell 88E6350",
5531 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005532 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005533 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005534 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005535 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005536 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005537 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005538 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005539 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005540 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005541 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005542 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005543 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005544 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005545 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005546 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005547 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005548 },
5549
5550 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005551 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005552 .family = MV88E6XXX_FAMILY_6351,
5553 .name = "Marvell 88E6351",
5554 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005555 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005556 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005557 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005558 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005559 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005560 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005561 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005562 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005563 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005564 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005565 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005566 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005567 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005568 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005569 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005570 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005571 },
5572
5573 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005574 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005575 .family = MV88E6XXX_FAMILY_6352,
5576 .name = "Marvell 88E6352",
5577 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005578 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005579 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005580 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005581 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005582 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005583 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005584 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005585 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005586 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005587 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005588 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005589 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005590 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005591 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005592 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005593 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005594 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005595 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005596 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005597 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005598 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005599 .family = MV88E6XXX_FAMILY_6390,
5600 .name = "Marvell 88E6390",
5601 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005602 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005603 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005604 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005605 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005606 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005607 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005608 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005609 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005610 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005611 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005612 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005613 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005614 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005615 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005616 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005617 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005618 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005619 .ops = &mv88e6390_ops,
5620 },
5621 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005622 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005623 .family = MV88E6XXX_FAMILY_6390,
5624 .name = "Marvell 88E6390X",
5625 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005626 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005627 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005628 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005629 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005630 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005631 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005632 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005633 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005634 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005635 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005636 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005637 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005638 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005639 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005640 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005641 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005642 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005643 .ops = &mv88e6390x_ops,
5644 },
Pavana Sharmade776d02021-03-17 14:46:42 +01005645
5646 [MV88E6393X] = {
5647 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
5648 .family = MV88E6XXX_FAMILY_6393,
5649 .name = "Marvell 88E6393X",
5650 .num_databases = 4096,
5651 .num_ports = 11, /* 10 + Z80 */
5652 .num_internal_phys = 9,
5653 .max_vid = 8191,
5654 .port_base_addr = 0x0,
5655 .phy_base_addr = 0x0,
5656 .global1_addr = 0x1b,
5657 .global2_addr = 0x1c,
5658 .age_time_coeff = 3750,
5659 .g1_irqs = 10,
5660 .g2_irqs = 14,
5661 .atu_move_port_mask = 0x1f,
5662 .pvt = true,
5663 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005664 .ptp_support = true,
5665 .ops = &mv88e6393x_ops,
5666 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005667};
5668
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005669static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005670{
Vivien Didelota439c062016-04-17 13:23:58 -04005671 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005672
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005673 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5674 if (mv88e6xxx_table[i].prod_num == prod_num)
5675 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005676
Vivien Didelotb9b37712015-10-30 19:39:48 -04005677 return NULL;
5678}
5679
Vivien Didelotfad09c72016-06-21 12:28:20 -04005680static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005681{
5682 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005683 unsigned int prod_num, rev;
5684 u16 id;
5685 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005686
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005687 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005688 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005689 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005690 if (err)
5691 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005692
Vivien Didelot107fcc12017-06-12 12:37:36 -04005693 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5694 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005695
5696 info = mv88e6xxx_lookup_info(prod_num);
5697 if (!info)
5698 return -ENODEV;
5699
Vivien Didelotcaac8542016-06-20 13:14:09 -04005700 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005701 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005702
Vivien Didelotfad09c72016-06-21 12:28:20 -04005703 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5704 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005705
5706 return 0;
5707}
5708
Vivien Didelotfad09c72016-06-21 12:28:20 -04005709static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005710{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005711 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005712
Vivien Didelotfad09c72016-06-21 12:28:20 -04005713 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5714 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005715 return NULL;
5716
Vivien Didelotfad09c72016-06-21 12:28:20 -04005717 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005718
Vivien Didelotfad09c72016-06-21 12:28:20 -04005719 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005720 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005721 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005722
Vivien Didelotfad09c72016-06-21 12:28:20 -04005723 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005724}
5725
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005726static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005727 int port,
5728 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005729{
Vivien Didelot04bed142016-08-31 18:06:13 -04005730 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005731
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005732 return chip->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005733}
5734
Tobias Waldekranz9a99bef2021-04-20 20:53:08 +02005735static int mv88e6xxx_change_tag_protocol(struct dsa_switch *ds, int port,
5736 enum dsa_tag_protocol proto)
5737{
5738 struct mv88e6xxx_chip *chip = ds->priv;
5739 enum dsa_tag_protocol old_protocol;
5740 int err;
5741
5742 switch (proto) {
5743 case DSA_TAG_PROTO_EDSA:
5744 switch (chip->info->edsa_support) {
5745 case MV88E6XXX_EDSA_UNSUPPORTED:
5746 return -EPROTONOSUPPORT;
5747 case MV88E6XXX_EDSA_UNDOCUMENTED:
5748 dev_warn(chip->dev, "Relying on undocumented EDSA tagging behavior\n");
5749 fallthrough;
5750 case MV88E6XXX_EDSA_SUPPORTED:
5751 break;
5752 }
5753 break;
5754 case DSA_TAG_PROTO_DSA:
5755 break;
5756 default:
5757 return -EPROTONOSUPPORT;
5758 }
5759
5760 old_protocol = chip->tag_protocol;
5761 chip->tag_protocol = proto;
5762
5763 mv88e6xxx_reg_lock(chip);
5764 err = mv88e6xxx_setup_port_mode(chip, port);
5765 mv88e6xxx_reg_unlock(chip);
5766
5767 if (err)
5768 chip->tag_protocol = old_protocol;
5769
5770 return err;
5771}
5772
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005773static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
5774 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005775{
Vivien Didelot04bed142016-08-31 18:06:13 -04005776 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005777 int err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005778
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005779 mv88e6xxx_reg_lock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005780 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5781 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005782 mv88e6xxx_reg_unlock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005783
5784 return err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005785}
5786
5787static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5788 const struct switchdev_obj_port_mdb *mdb)
5789{
Vivien Didelot04bed142016-08-31 18:06:13 -04005790 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005791 int err;
5792
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005793 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005794 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005795 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005796
5797 return err;
5798}
5799
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005800static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5801 struct dsa_mall_mirror_tc_entry *mirror,
5802 bool ingress)
5803{
5804 enum mv88e6xxx_egress_direction direction = ingress ?
5805 MV88E6XXX_EGRESS_DIR_INGRESS :
5806 MV88E6XXX_EGRESS_DIR_EGRESS;
5807 struct mv88e6xxx_chip *chip = ds->priv;
5808 bool other_mirrors = false;
5809 int i;
5810 int err;
5811
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005812 mutex_lock(&chip->reg_lock);
5813 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5814 mirror->to_local_port) {
5815 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5816 other_mirrors |= ingress ?
5817 chip->ports[i].mirror_ingress :
5818 chip->ports[i].mirror_egress;
5819
5820 /* Can't change egress port when other mirror is active */
5821 if (other_mirrors) {
5822 err = -EBUSY;
5823 goto out;
5824 }
5825
Marek Behún2fda45f2021-03-17 14:46:41 +01005826 err = mv88e6xxx_set_egress_port(chip, direction,
5827 mirror->to_local_port);
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005828 if (err)
5829 goto out;
5830 }
5831
5832 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5833out:
5834 mutex_unlock(&chip->reg_lock);
5835
5836 return err;
5837}
5838
5839static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5840 struct dsa_mall_mirror_tc_entry *mirror)
5841{
5842 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5843 MV88E6XXX_EGRESS_DIR_INGRESS :
5844 MV88E6XXX_EGRESS_DIR_EGRESS;
5845 struct mv88e6xxx_chip *chip = ds->priv;
5846 bool other_mirrors = false;
5847 int i;
5848
5849 mutex_lock(&chip->reg_lock);
5850 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5851 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5852
5853 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5854 other_mirrors |= mirror->ingress ?
5855 chip->ports[i].mirror_ingress :
5856 chip->ports[i].mirror_egress;
5857
5858 /* Reset egress port when no other mirror is active */
5859 if (!other_mirrors) {
Marek Behún2fda45f2021-03-17 14:46:41 +01005860 if (mv88e6xxx_set_egress_port(chip, direction,
5861 dsa_upstream_port(ds, port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005862 dev_err(ds->dev, "failed to set egress port\n");
5863 }
5864
5865 mutex_unlock(&chip->reg_lock);
5866}
5867
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005868static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port,
5869 struct switchdev_brport_flags flags,
5870 struct netlink_ext_ack *extack)
5871{
5872 struct mv88e6xxx_chip *chip = ds->priv;
5873 const struct mv88e6xxx_ops *ops;
5874
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01005875 if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
5876 BR_BCAST_FLOOD))
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005877 return -EINVAL;
5878
5879 ops = chip->info->ops;
5880
5881 if ((flags.mask & BR_FLOOD) && !ops->port_set_ucast_flood)
5882 return -EINVAL;
5883
5884 if ((flags.mask & BR_MCAST_FLOOD) && !ops->port_set_mcast_flood)
5885 return -EINVAL;
5886
5887 return 0;
5888}
5889
5890static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
5891 struct switchdev_brport_flags flags,
5892 struct netlink_ext_ack *extack)
Russell King4f859012019-02-20 15:35:05 -08005893{
5894 struct mv88e6xxx_chip *chip = ds->priv;
5895 int err = -EOPNOTSUPP;
5896
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005897 mv88e6xxx_reg_lock(chip);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005898
Tobias Waldekranz041bd542021-03-18 20:25:39 +01005899 if (flags.mask & BR_LEARNING) {
5900 bool learning = !!(flags.val & BR_LEARNING);
5901 u16 pav = learning ? (1 << port) : 0;
5902
5903 err = mv88e6xxx_port_set_assoc_vector(chip, port, pav);
5904 if (err)
5905 goto out;
Tobias Waldekranz041bd542021-03-18 20:25:39 +01005906 }
5907
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005908 if (flags.mask & BR_FLOOD) {
5909 bool unicast = !!(flags.val & BR_FLOOD);
5910
5911 err = chip->info->ops->port_set_ucast_flood(chip, port,
5912 unicast);
5913 if (err)
5914 goto out;
5915 }
5916
5917 if (flags.mask & BR_MCAST_FLOOD) {
5918 bool multicast = !!(flags.val & BR_MCAST_FLOOD);
5919
5920 err = chip->info->ops->port_set_mcast_flood(chip, port,
5921 multicast);
5922 if (err)
5923 goto out;
5924 }
5925
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01005926 if (flags.mask & BR_BCAST_FLOOD) {
5927 bool broadcast = !!(flags.val & BR_BCAST_FLOOD);
5928
5929 err = mv88e6xxx_port_broadcast_sync(chip, port, broadcast);
5930 if (err)
5931 goto out;
5932 }
5933
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005934out:
5935 mv88e6xxx_reg_unlock(chip);
5936
5937 return err;
5938}
5939
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005940static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
5941 struct net_device *lag,
5942 struct netdev_lag_upper_info *info)
5943{
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005944 struct mv88e6xxx_chip *chip = ds->priv;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005945 struct dsa_port *dp;
5946 int id, members = 0;
5947
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005948 if (!mv88e6xxx_has_lag(chip))
5949 return false;
5950
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005951 id = dsa_lag_id(ds->dst, lag);
5952 if (id < 0 || id >= ds->num_lag_ids)
5953 return false;
5954
5955 dsa_lag_foreach_port(dp, ds->dst, lag)
5956 /* Includes the port joining the LAG */
5957 members++;
5958
5959 if (members > 8)
5960 return false;
5961
5962 /* We could potentially relax this to include active
5963 * backup in the future.
5964 */
5965 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
5966 return false;
5967
5968 /* Ideally we would also validate that the hash type matches
5969 * the hardware. Alas, this is always set to unknown on team
5970 * interfaces.
5971 */
5972 return true;
5973}
5974
5975static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct net_device *lag)
5976{
5977 struct mv88e6xxx_chip *chip = ds->priv;
5978 struct dsa_port *dp;
5979 u16 map = 0;
5980 int id;
5981
5982 id = dsa_lag_id(ds->dst, lag);
5983
5984 /* Build the map of all ports to distribute flows destined for
5985 * this LAG. This can be either a local user port, or a DSA
5986 * port if the LAG port is on a remote chip.
5987 */
5988 dsa_lag_foreach_port(dp, ds->dst, lag)
5989 map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));
5990
5991 return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
5992}
5993
5994static const u8 mv88e6xxx_lag_mask_table[8][8] = {
5995 /* Row number corresponds to the number of active members in a
5996 * LAG. Each column states which of the eight hash buckets are
5997 * mapped to the column:th port in the LAG.
5998 *
5999 * Example: In a LAG with three active ports, the second port
6000 * ([2][1]) would be selected for traffic mapped to buckets
6001 * 3,4,5 (0x38).
6002 */
6003 { 0xff, 0, 0, 0, 0, 0, 0, 0 },
6004 { 0x0f, 0xf0, 0, 0, 0, 0, 0, 0 },
6005 { 0x07, 0x38, 0xc0, 0, 0, 0, 0, 0 },
6006 { 0x03, 0x0c, 0x30, 0xc0, 0, 0, 0, 0 },
6007 { 0x03, 0x0c, 0x30, 0x40, 0x80, 0, 0, 0 },
6008 { 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80, 0, 0 },
6009 { 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0 },
6010 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
6011};
6012
6013static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
6014 int num_tx, int nth)
6015{
6016 u8 active = 0;
6017 int i;
6018
6019 num_tx = num_tx <= 8 ? num_tx : 8;
6020 if (nth < num_tx)
6021 active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];
6022
6023 for (i = 0; i < 8; i++) {
6024 if (BIT(i) & active)
6025 mask[i] |= BIT(port);
6026 }
6027}
6028
6029static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
6030{
6031 struct mv88e6xxx_chip *chip = ds->priv;
6032 unsigned int id, num_tx;
6033 struct net_device *lag;
6034 struct dsa_port *dp;
6035 int i, err, nth;
6036 u16 mask[8];
6037 u16 ivec;
6038
6039 /* Assume no port is a member of any LAG. */
6040 ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;
6041
6042 /* Disable all masks for ports that _are_ members of a LAG. */
6043 list_for_each_entry(dp, &ds->dst->ports, list) {
6044 if (!dp->lag_dev || dp->ds != ds)
6045 continue;
6046
6047 ivec &= ~BIT(dp->index);
6048 }
6049
6050 for (i = 0; i < 8; i++)
6051 mask[i] = ivec;
6052
6053 /* Enable the correct subset of masks for all LAG ports that
6054 * are in the Tx set.
6055 */
6056 dsa_lags_foreach_id(id, ds->dst) {
6057 lag = dsa_lag_dev(ds->dst, id);
6058 if (!lag)
6059 continue;
6060
6061 num_tx = 0;
6062 dsa_lag_foreach_port(dp, ds->dst, lag) {
6063 if (dp->lag_tx_enabled)
6064 num_tx++;
6065 }
6066
6067 if (!num_tx)
6068 continue;
6069
6070 nth = 0;
6071 dsa_lag_foreach_port(dp, ds->dst, lag) {
6072 if (!dp->lag_tx_enabled)
6073 continue;
6074
6075 if (dp->ds == ds)
6076 mv88e6xxx_lag_set_port_mask(mask, dp->index,
6077 num_tx, nth);
6078
6079 nth++;
6080 }
6081 }
6082
6083 for (i = 0; i < 8; i++) {
6084 err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
6085 if (err)
6086 return err;
6087 }
6088
6089 return 0;
6090}
6091
6092static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
6093 struct net_device *lag)
6094{
6095 int err;
6096
6097 err = mv88e6xxx_lag_sync_masks(ds);
6098
6099 if (!err)
6100 err = mv88e6xxx_lag_sync_map(ds, lag);
6101
6102 return err;
6103}
6104
6105static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port)
6106{
6107 struct mv88e6xxx_chip *chip = ds->priv;
6108 int err;
6109
6110 mv88e6xxx_reg_lock(chip);
6111 err = mv88e6xxx_lag_sync_masks(ds);
6112 mv88e6xxx_reg_unlock(chip);
6113 return err;
6114}
6115
6116static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
6117 struct net_device *lag,
6118 struct netdev_lag_upper_info *info)
6119{
6120 struct mv88e6xxx_chip *chip = ds->priv;
6121 int err, id;
6122
6123 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
6124 return -EOPNOTSUPP;
6125
6126 id = dsa_lag_id(ds->dst, lag);
6127
6128 mv88e6xxx_reg_lock(chip);
6129
6130 err = mv88e6xxx_port_set_trunk(chip, port, true, id);
6131 if (err)
6132 goto err_unlock;
6133
6134 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6135 if (err)
6136 goto err_clear_trunk;
6137
6138 mv88e6xxx_reg_unlock(chip);
6139 return 0;
6140
6141err_clear_trunk:
6142 mv88e6xxx_port_set_trunk(chip, port, false, 0);
6143err_unlock:
6144 mv88e6xxx_reg_unlock(chip);
6145 return err;
6146}
6147
6148static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
6149 struct net_device *lag)
6150{
6151 struct mv88e6xxx_chip *chip = ds->priv;
6152 int err_sync, err_trunk;
6153
6154 mv88e6xxx_reg_lock(chip);
6155 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6156 err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
6157 mv88e6xxx_reg_unlock(chip);
6158 return err_sync ? : err_trunk;
6159}
6160
6161static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
6162 int port)
6163{
6164 struct mv88e6xxx_chip *chip = ds->priv;
6165 int err;
6166
6167 mv88e6xxx_reg_lock(chip);
6168 err = mv88e6xxx_lag_sync_masks(ds);
6169 mv88e6xxx_reg_unlock(chip);
6170 return err;
6171}
6172
6173static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
6174 int port, struct net_device *lag,
6175 struct netdev_lag_upper_info *info)
6176{
6177 struct mv88e6xxx_chip *chip = ds->priv;
6178 int err;
6179
6180 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
6181 return -EOPNOTSUPP;
6182
6183 mv88e6xxx_reg_lock(chip);
6184
6185 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6186 if (err)
6187 goto unlock;
6188
6189 err = mv88e6xxx_pvt_map(chip, sw_index, port);
6190
6191unlock:
6192 mv88e6xxx_reg_unlock(chip);
6193 return err;
6194}
6195
6196static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
6197 int port, struct net_device *lag)
6198{
6199 struct mv88e6xxx_chip *chip = ds->priv;
6200 int err_sync, err_pvt;
6201
6202 mv88e6xxx_reg_lock(chip);
6203 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6204 err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
6205 mv88e6xxx_reg_unlock(chip);
6206 return err_sync ? : err_pvt;
6207}
6208
Florian Fainellia82f67a2017-01-08 14:52:08 -08006209static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02006210 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Tobias Waldekranz9a99bef2021-04-20 20:53:08 +02006211 .change_tag_protocol = mv88e6xxx_change_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006212 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02006213 .teardown = mv88e6xxx_teardown,
Vladimir Olteanfd292c12021-09-17 17:29:16 +03006214 .port_setup = mv88e6xxx_port_setup,
6215 .port_teardown = mv88e6xxx_port_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07006216 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00006217 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07006218 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00006219 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07006220 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
6221 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006222 .get_strings = mv88e6xxx_get_strings,
6223 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
6224 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02006225 .port_enable = mv88e6xxx_port_enable,
6226 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02006227 .port_max_mtu = mv88e6xxx_get_max_mtu,
6228 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04006229 .get_mac_eee = mv88e6xxx_get_mac_eee,
6230 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006231 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006232 .get_eeprom = mv88e6xxx_get_eeprom,
6233 .set_eeprom = mv88e6xxx_set_eeprom,
6234 .get_regs_len = mv88e6xxx_get_regs_len,
6235 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04006236 .get_rxnfc = mv88e6xxx_get_rxnfc,
6237 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04006238 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006239 .port_bridge_join = mv88e6xxx_port_bridge_join,
6240 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02006241 .port_pre_bridge_flags = mv88e6xxx_port_pre_bridge_flags,
6242 .port_bridge_flags = mv88e6xxx_port_bridge_flags,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006243 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04006244 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006245 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006246 .port_vlan_add = mv88e6xxx_port_vlan_add,
6247 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006248 .port_fdb_add = mv88e6xxx_port_fdb_add,
6249 .port_fdb_del = mv88e6xxx_port_fdb_del,
6250 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04006251 .port_mdb_add = mv88e6xxx_port_mdb_add,
6252 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01006253 .port_mirror_add = mv88e6xxx_port_mirror_add,
6254 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04006255 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
6256 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006257 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
6258 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
6259 .port_txtstamp = mv88e6xxx_port_txtstamp,
6260 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
6261 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02006262 .devlink_param_get = mv88e6xxx_devlink_param_get,
6263 .devlink_param_set = mv88e6xxx_devlink_param_set,
Andrew Lunn93157302020-09-18 21:11:09 +02006264 .devlink_info_get = mv88e6xxx_devlink_info_get,
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006265 .port_lag_change = mv88e6xxx_port_lag_change,
6266 .port_lag_join = mv88e6xxx_port_lag_join,
6267 .port_lag_leave = mv88e6xxx_port_lag_leave,
6268 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
6269 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
6270 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
Vladimir Olteance5df682021-07-22 18:55:41 +03006271 .port_bridge_tx_fwd_offload = mv88e6xxx_bridge_tx_fwd_offload,
6272 .port_bridge_tx_fwd_unoffload = mv88e6xxx_bridge_tx_fwd_unoffload,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006273};
6274
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08006275static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006276{
Vivien Didelotfad09c72016-06-21 12:28:20 -04006277 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006278 struct dsa_switch *ds;
6279
Vivien Didelot7e99e342019-10-21 16:51:30 -04006280 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006281 if (!ds)
6282 return -ENOMEM;
6283
Vivien Didelot7e99e342019-10-21 16:51:30 -04006284 ds->dev = dev;
6285 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006286 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006287 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04006288 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04006289 ds->ageing_time_min = chip->info->age_time_coeff;
6290 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006291
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006292 /* Some chips support up to 32, but that requires enabling the
6293 * 5-bit port mode, which we do not support. 640k^W16 ought to
6294 * be enough for anyone.
6295 */
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01006296 ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006297
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006298 dev_set_drvdata(dev, ds);
6299
Vivien Didelot23c9ee42017-05-26 18:12:51 -04006300 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006301}
6302
Vivien Didelotfad09c72016-06-21 12:28:20 -04006303static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006304{
Vivien Didelotfad09c72016-06-21 12:28:20 -04006305 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006306}
6307
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006308static const void *pdata_device_get_match_data(struct device *dev)
6309{
6310 const struct of_device_id *matches = dev->driver->of_match_table;
6311 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
6312
6313 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
6314 matches++) {
6315 if (!strcmp(pdata->compatible, matches->compatible))
6316 return matches->data;
6317 }
6318 return NULL;
6319}
6320
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006321/* There is no suspend to RAM support at DSA level yet, the switch configuration
6322 * would be lost after a power cycle so prevent it to be suspended.
6323 */
6324static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
6325{
6326 return -EOPNOTSUPP;
6327}
6328
6329static int __maybe_unused mv88e6xxx_resume(struct device *dev)
6330{
6331 return 0;
6332}
6333
6334static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
6335
Vivien Didelot57d32312016-06-20 13:13:58 -04006336static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006337{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006338 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04006339 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006340 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006341 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04006342 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006343 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02006344 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006345
Andrew Lunn7bb8c992018-05-31 00:15:42 +02006346 if (!np && !pdata)
6347 return -EINVAL;
6348
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006349 if (np)
6350 compat_info = of_device_get_match_data(dev);
6351
6352 if (pdata) {
6353 compat_info = pdata_device_get_match_data(dev);
6354
6355 if (!pdata->netdev)
6356 return -EINVAL;
6357
6358 for (port = 0; port < DSA_MAX_PORTS; port++) {
6359 if (!(pdata->enabled_ports & (1 << port)))
6360 continue;
6361 if (strcmp(pdata->cd.port_names[port], "cpu"))
6362 continue;
6363 pdata->cd.netdev[port] = &pdata->netdev->dev;
6364 break;
6365 }
6366 }
6367
Vivien Didelotcaac8542016-06-20 13:14:09 -04006368 if (!compat_info)
6369 return -EINVAL;
6370
Vivien Didelotfad09c72016-06-21 12:28:20 -04006371 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006372 if (!chip) {
6373 err = -ENOMEM;
6374 goto out;
6375 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006376
Vivien Didelotfad09c72016-06-21 12:28:20 -04006377 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04006378
Vivien Didelotfad09c72016-06-21 12:28:20 -04006379 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04006380 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006381 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006382
Andrew Lunnb4308f02016-11-21 23:26:55 +01006383 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006384 if (IS_ERR(chip->reset)) {
6385 err = PTR_ERR(chip->reset);
6386 goto out;
6387 }
Baruch Siach7b75e492019-06-27 21:17:39 +03006388 if (chip->reset)
6389 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01006390
Vivien Didelotfad09c72016-06-21 12:28:20 -04006391 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04006392 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006393 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006394
Tobias Waldekranz670bb802021-04-20 20:53:07 +02006395 if (chip->info->edsa_support == MV88E6XXX_EDSA_SUPPORTED)
6396 chip->tag_protocol = DSA_TAG_PROTO_EDSA;
6397 else
6398 chip->tag_protocol = DSA_TAG_PROTO_DSA;
6399
Vivien Didelote57e5e72016-08-15 17:19:00 -04006400 mv88e6xxx_phy_init(chip);
6401
Andrew Lunn00baabe2018-05-19 22:31:35 +02006402 if (chip->info->ops->get_eeprom) {
6403 if (np)
6404 of_property_read_u32(np, "eeprom-length",
6405 &chip->eeprom_len);
6406 else
6407 chip->eeprom_len = pdata->eeprom_len;
6408 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006409
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006410 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006411 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006412 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02006413 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02006414 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02006415
Andrew Lunna27415d2019-05-01 00:10:50 +02006416 if (np) {
6417 chip->irq = of_irq_get(np, 0);
6418 if (chip->irq == -EPROBE_DEFER) {
6419 err = chip->irq;
6420 goto out;
6421 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02006422 }
6423
Andrew Lunna27415d2019-05-01 00:10:50 +02006424 if (pdata)
6425 chip->irq = pdata->irq;
6426
Andrew Lunn294d7112018-02-22 22:58:32 +01006427 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01006428 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01006429 * controllers
6430 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006431 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006432 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006433 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006434 else
6435 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006436 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006437
Andrew Lunn294d7112018-02-22 22:58:32 +01006438 if (err)
6439 goto out;
6440
6441 if (chip->info->g2_irqs > 0) {
6442 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006443 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01006444 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02006445 }
6446
Andrew Lunn294d7112018-02-22 22:58:32 +01006447 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
6448 if (err)
6449 goto out_g2_irq;
6450
6451 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
6452 if (err)
6453 goto out_g1_atu_prob_irq;
6454
Andrew Lunna3c53be52017-01-24 14:53:50 +01006455 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02006456 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01006457 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02006458
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08006459 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006460 if (err)
6461 goto out_mdio;
6462
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006463 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02006464
6465out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01006466 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01006467out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006468 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01006469out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006470 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006471out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006472 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006473 mv88e6xxx_g2_irq_free(chip);
6474out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006475 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006476 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006477 else
6478 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006479out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006480 if (pdata)
6481 dev_put(pdata->netdev);
6482
Andrew Lunndc30c352016-10-16 19:56:49 +02006483 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006484}
6485
6486static void mv88e6xxx_remove(struct mdio_device *mdiodev)
6487{
6488 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006489 struct mv88e6xxx_chip *chip;
6490
6491 if (!ds)
6492 return;
6493
6494 chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006495
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006496 if (chip->info->ptp_support) {
6497 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006498 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006499 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006500
Andrew Lunn930188c2016-08-22 16:01:03 +02006501 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006502 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01006503 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006504
Andrew Lunn76f38f12018-03-17 20:21:09 +01006505 mv88e6xxx_g1_vtu_prob_irq_free(chip);
6506 mv88e6xxx_g1_atu_prob_irq_free(chip);
6507
6508 if (chip->info->g2_irqs > 0)
6509 mv88e6xxx_g2_irq_free(chip);
6510
Andrew Lunn76f38f12018-03-17 20:21:09 +01006511 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006512 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01006513 else
6514 mv88e6xxx_irq_poll_free(chip);
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006515
6516 dev_set_drvdata(&mdiodev->dev, NULL);
6517}
6518
6519static void mv88e6xxx_shutdown(struct mdio_device *mdiodev)
6520{
6521 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
6522
6523 if (!ds)
6524 return;
6525
6526 dsa_switch_shutdown(ds);
6527
6528 dev_set_drvdata(&mdiodev->dev, NULL);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006529}
6530
6531static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04006532 {
6533 .compatible = "marvell,mv88e6085",
6534 .data = &mv88e6xxx_table[MV88E6085],
6535 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01006536 {
6537 .compatible = "marvell,mv88e6190",
6538 .data = &mv88e6xxx_table[MV88E6190],
6539 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00006540 {
6541 .compatible = "marvell,mv88e6250",
6542 .data = &mv88e6xxx_table[MV88E6250],
6543 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006544 { /* sentinel */ },
6545};
6546
6547MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
6548
6549static struct mdio_driver mv88e6xxx_driver = {
6550 .probe = mv88e6xxx_probe,
6551 .remove = mv88e6xxx_remove,
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006552 .shutdown = mv88e6xxx_shutdown,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006553 .mdiodrv.driver = {
6554 .name = "mv88e6085",
6555 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006556 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006557 },
6558};
6559
Andrew Lunn7324d502019-04-27 19:19:10 +02006560mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00006561
6562MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
6563MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
6564MODULE_LICENSE("GPL");