blob: 17578f77468388f717b725d9b63ddc20fa3364d6 [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>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070015#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020016#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070017#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020018#include <linux/interrupt.h>
19#include <linux/irq.h>
20#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000021#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000022#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020023#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000024#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040025#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020026#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020027#include <linux/of_mdio.h>
Andrew Lunn877b7cb2018-05-19 22:31:34 +020028#include <linux/platform_data/mv88e6xxx.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000029#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010030#include <linux/gpio/consumer.h>
Russell Kingc9a23562018-05-10 13:17:35 -070031#include <linux/phylink.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000032#include <net/dsa.h>
Vivien Didelotec561272016-09-02 14:45:33 -040033
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -040034#include "chip.h"
Andrew Lunn9dd43aa2020-09-18 21:11:05 +020035#include "devlink.h"
Vivien Didelota935c052016-09-29 12:21:53 -040036#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040037#include "global2.h"
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +010038#include "hwtstamp.h"
Andrew Lunn10fa5bf2017-05-26 01:03:20 +020039#include "phy.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010040#include "port.h"
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +010041#include "ptp.h"
Andrew Lunn6d917822017-05-26 01:03:21 +020042#include "serdes.h"
Vivien Didelote7ba0fa2019-05-03 19:28:22 -040043#include "smi.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000044
Vivien Didelotfad09c72016-06-21 12:28:20 -040045static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040046{
Vivien Didelotfad09c72016-06-21 12:28:20 -040047 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
48 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040049 dump_stack();
50 }
51}
52
Vivien Didelotec561272016-09-02 14:45:33 -040053int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -040054{
55 int err;
56
Vivien Didelotfad09c72016-06-21 12:28:20 -040057 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -040058
Vivien Didelotfad09c72016-06-21 12:28:20 -040059 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040060 if (err)
61 return err;
62
Vivien Didelotfad09c72016-06-21 12:28:20 -040063 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -040064 addr, reg, *val);
65
66 return 0;
67}
68
Vivien Didelotec561272016-09-02 14:45:33 -040069int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -040070{
71 int err;
72
Vivien Didelotfad09c72016-06-21 12:28:20 -040073 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -040074
Vivien Didelotfad09c72016-06-21 12:28:20 -040075 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040076 if (err)
77 return err;
78
Vivien Didelotfad09c72016-06-21 12:28:20 -040079 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -040080 addr, reg, val);
81
82 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000083}
84
Vivien Didelot683f2242019-08-09 18:47:54 -040085int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg,
86 u16 mask, u16 val)
87{
88 u16 data;
89 int err;
90 int i;
91
92 /* There's no bus specific operation to wait for a mask */
93 for (i = 0; i < 16; i++) {
94 err = mv88e6xxx_read(chip, addr, reg, &data);
95 if (err)
96 return err;
97
98 if ((data & mask) == val)
99 return 0;
100
101 usleep_range(1000, 2000);
102 }
103
104 dev_err(chip->dev, "Timeout while waiting for switch\n");
105 return -ETIMEDOUT;
106}
107
Vivien Didelot19fb7f62019-08-09 18:47:55 -0400108int mv88e6xxx_wait_bit(struct mv88e6xxx_chip *chip, int addr, int reg,
109 int bit, int val)
110{
111 return mv88e6xxx_wait_mask(chip, addr, reg, BIT(bit),
112 val ? BIT(bit) : 0x0000);
113}
114
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200115struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
Andrew Lunna3c53be52017-01-24 14:53:50 +0100116{
117 struct mv88e6xxx_mdio_bus *mdio_bus;
118
119 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
120 list);
121 if (!mdio_bus)
122 return NULL;
123
124 return mdio_bus->bus;
125}
126
Andrew Lunndc30c352016-10-16 19:56:49 +0200127static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
128{
129 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
130 unsigned int n = d->hwirq;
131
132 chip->g1_irq.masked |= (1 << n);
133}
134
135static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
136{
137 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
138 unsigned int n = d->hwirq;
139
140 chip->g1_irq.masked &= ~(1 << n);
141}
142
Andrew Lunn294d7112018-02-22 22:58:32 +0100143static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200144{
Andrew Lunndc30c352016-10-16 19:56:49 +0200145 unsigned int nhandled = 0;
146 unsigned int sub_irq;
147 unsigned int n;
148 u16 reg;
John David Anglin7c0db242019-02-11 13:40:21 -0500149 u16 ctl1;
Andrew Lunndc30c352016-10-16 19:56:49 +0200150 int err;
151
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000152 mv88e6xxx_reg_lock(chip);
Vivien Didelot82466922017-06-15 12:13:59 -0400153 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000154 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200155
156 if (err)
157 goto out;
158
John David Anglin7c0db242019-02-11 13:40:21 -0500159 do {
160 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
161 if (reg & (1 << n)) {
162 sub_irq = irq_find_mapping(chip->g1_irq.domain,
163 n);
164 handle_nested_irq(sub_irq);
165 ++nhandled;
166 }
Andrew Lunndc30c352016-10-16 19:56:49 +0200167 }
John David Anglin7c0db242019-02-11 13:40:21 -0500168
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000169 mv88e6xxx_reg_lock(chip);
John David Anglin7c0db242019-02-11 13:40:21 -0500170 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1);
171 if (err)
172 goto unlock;
173 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
174unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000175 mv88e6xxx_reg_unlock(chip);
John David Anglin7c0db242019-02-11 13:40:21 -0500176 if (err)
177 goto out;
178 ctl1 &= GENMASK(chip->g1_irq.nirqs, 0);
179 } while (reg & ctl1);
180
Andrew Lunndc30c352016-10-16 19:56:49 +0200181out:
182 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
183}
184
Andrew Lunn294d7112018-02-22 22:58:32 +0100185static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
186{
187 struct mv88e6xxx_chip *chip = dev_id;
188
189 return mv88e6xxx_g1_irq_thread_work(chip);
190}
191
Andrew Lunndc30c352016-10-16 19:56:49 +0200192static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
193{
194 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
195
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000196 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200197}
198
199static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
200{
201 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
202 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
203 u16 reg;
204 int err;
205
Vivien Didelotd77f4322017-06-15 12:14:03 -0400206 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200207 if (err)
208 goto out;
209
210 reg &= ~mask;
211 reg |= (~chip->g1_irq.masked & mask);
212
Vivien Didelotd77f4322017-06-15 12:14:03 -0400213 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200214 if (err)
215 goto out;
216
217out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000218 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200219}
220
Bhumika Goyal6eb15e22017-08-19 16:25:52 +0530221static const struct irq_chip mv88e6xxx_g1_irq_chip = {
Andrew Lunndc30c352016-10-16 19:56:49 +0200222 .name = "mv88e6xxx-g1",
223 .irq_mask = mv88e6xxx_g1_irq_mask,
224 .irq_unmask = mv88e6xxx_g1_irq_unmask,
225 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
226 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
227};
228
229static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
230 unsigned int irq,
231 irq_hw_number_t hwirq)
232{
233 struct mv88e6xxx_chip *chip = d->host_data;
234
235 irq_set_chip_data(irq, d->host_data);
236 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
237 irq_set_noprobe(irq);
238
239 return 0;
240}
241
242static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
243 .map = mv88e6xxx_g1_irq_domain_map,
244 .xlate = irq_domain_xlate_twocell,
245};
246
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200247/* To be called with reg_lock held */
Andrew Lunn294d7112018-02-22 22:58:32 +0100248static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200249{
250 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100251 u16 mask;
252
Vivien Didelotd77f4322017-06-15 12:14:03 -0400253 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100254 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400255 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100256
Andreas Färber5edef2f2016-11-27 23:26:28 +0100257 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100258 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200259 irq_dispose_mapping(virq);
260 }
261
Andrew Lunna3db3d32016-11-20 20:14:14 +0100262 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200263}
264
Andrew Lunn294d7112018-02-22 22:58:32 +0100265static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
266{
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200267 /*
268 * free_irq must be called without reg_lock taken because the irq
269 * handler takes this lock, too.
270 */
Andrew Lunn294d7112018-02-22 22:58:32 +0100271 free_irq(chip->irq, chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200272
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000273 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200274 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000275 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100276}
277
278static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200279{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100280 int err, irq, virq;
281 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200282
283 chip->g1_irq.nirqs = chip->info->g1_irqs;
284 chip->g1_irq.domain = irq_domain_add_simple(
285 NULL, chip->g1_irq.nirqs, 0,
286 &mv88e6xxx_g1_irq_domain_ops, chip);
287 if (!chip->g1_irq.domain)
288 return -ENOMEM;
289
290 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
291 irq_create_mapping(chip->g1_irq.domain, irq);
292
293 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
294 chip->g1_irq.masked = ~0;
295
Vivien Didelotd77f4322017-06-15 12:14:03 -0400296 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200297 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100298 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200299
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100300 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200301
Vivien Didelotd77f4322017-06-15 12:14:03 -0400302 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200303 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100304 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200305
306 /* Reading the interrupt status clears (most of) them */
Vivien Didelot82466922017-06-15 12:13:59 -0400307 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200308 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100309 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200310
Andrew Lunndc30c352016-10-16 19:56:49 +0200311 return 0;
312
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100313out_disable:
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100314 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400315 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100316
317out_mapping:
318 for (irq = 0; irq < 16; irq++) {
319 virq = irq_find_mapping(chip->g1_irq.domain, irq);
320 irq_dispose_mapping(virq);
321 }
322
323 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200324
325 return err;
326}
327
Andrew Lunn294d7112018-02-22 22:58:32 +0100328static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
329{
Andrew Lunnf6d97582019-02-23 17:43:56 +0100330 static struct lock_class_key lock_key;
331 static struct lock_class_key request_key;
Andrew Lunn294d7112018-02-22 22:58:32 +0100332 int err;
333
334 err = mv88e6xxx_g1_irq_setup_common(chip);
335 if (err)
336 return err;
337
Andrew Lunnf6d97582019-02-23 17:43:56 +0100338 /* These lock classes tells lockdep that global 1 irqs are in
339 * a different category than their parent GPIO, so it won't
340 * report false recursion.
341 */
342 irq_set_lockdep_class(chip->irq, &lock_key, &request_key);
343
Andrew Lunn30953832020-01-06 17:13:48 +0100344 snprintf(chip->irq_name, sizeof(chip->irq_name),
345 "mv88e6xxx-%s", dev_name(chip->dev));
346
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000347 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100348 err = request_threaded_irq(chip->irq, NULL,
349 mv88e6xxx_g1_irq_thread_fn,
Marek Behún03403762018-08-30 02:13:50 +0200350 IRQF_ONESHOT | IRQF_SHARED,
Andrew Lunn30953832020-01-06 17:13:48 +0100351 chip->irq_name, chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000352 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100353 if (err)
354 mv88e6xxx_g1_irq_free_common(chip);
355
356 return err;
357}
358
359static void mv88e6xxx_irq_poll(struct kthread_work *work)
360{
361 struct mv88e6xxx_chip *chip = container_of(work,
362 struct mv88e6xxx_chip,
363 irq_poll_work.work);
364 mv88e6xxx_g1_irq_thread_work(chip);
365
366 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
367 msecs_to_jiffies(100));
368}
369
370static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
371{
372 int err;
373
374 err = mv88e6xxx_g1_irq_setup_common(chip);
375 if (err)
376 return err;
377
378 kthread_init_delayed_work(&chip->irq_poll_work,
379 mv88e6xxx_irq_poll);
380
Florian Fainelli3f8b8692019-02-21 20:09:27 -0800381 chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
Andrew Lunn294d7112018-02-22 22:58:32 +0100382 if (IS_ERR(chip->kworker))
383 return PTR_ERR(chip->kworker);
384
385 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
386 msecs_to_jiffies(100));
387
388 return 0;
389}
390
391static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
392{
393 kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
394 kthread_destroy_worker(chip->kworker);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200395
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000396 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200397 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000398 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100399}
400
Russell King64d47d52020-03-14 10:15:38 +0000401static int mv88e6xxx_port_config_interface(struct mv88e6xxx_chip *chip,
402 int port, phy_interface_t interface)
403{
404 int err;
405
406 if (chip->info->ops->port_set_rgmii_delay) {
407 err = chip->info->ops->port_set_rgmii_delay(chip, port,
408 interface);
409 if (err && err != -EOPNOTSUPP)
410 return err;
411 }
412
413 if (chip->info->ops->port_set_cmode) {
414 err = chip->info->ops->port_set_cmode(chip, port,
415 interface);
416 if (err && err != -EOPNOTSUPP)
417 return err;
418 }
419
420 return 0;
421}
422
Russell Kinga5a68582020-03-14 10:15:43 +0000423static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
424 int link, int speed, int duplex, int pause,
425 phy_interface_t mode)
Vivien Didelotd78343d2016-11-04 03:23:36 +0100426{
427 int err;
428
429 if (!chip->info->ops->port_set_link)
430 return 0;
431
432 /* Port's MAC control must not be changed unless the link is down */
Hubert Feurstein43c8e0a2019-07-30 12:11:42 +0200433 err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100434 if (err)
435 return err;
436
Russell Kingf365c6f2020-03-14 10:15:53 +0000437 if (chip->info->ops->port_set_speed_duplex) {
438 err = chip->info->ops->port_set_speed_duplex(chip, port,
439 speed, duplex);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100440 if (err && err != -EOPNOTSUPP)
441 goto restore_link;
442 }
443
Andrew Lunn7cbbee02019-03-08 01:21:27 +0100444 if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
445 mode = chip->info->ops->port_max_speed_mode(port);
446
Andrew Lunn54186b92018-08-09 15:38:37 +0200447 if (chip->info->ops->port_set_pause) {
448 err = chip->info->ops->port_set_pause(chip, port, pause);
449 if (err)
450 goto restore_link;
451 }
452
Russell King64d47d52020-03-14 10:15:38 +0000453 err = mv88e6xxx_port_config_interface(chip, port, mode);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100454restore_link:
455 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400456 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100457
458 return err;
459}
460
Marek Vasutd700ec42018-09-12 00:15:24 +0200461static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
462{
463 struct mv88e6xxx_chip *chip = ds->priv;
464
465 return port < chip->info->num_internal_phys;
466}
467
Russell King5d5b2312020-03-14 10:16:03 +0000468static int mv88e6xxx_port_ppu_updates(struct mv88e6xxx_chip *chip, int port)
469{
470 u16 reg;
471 int err;
472
473 err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
474 if (err) {
475 dev_err(chip->dev,
476 "p%d: %s: failed to read port status\n",
477 port, __func__);
478 return err;
479 }
480
481 return !!(reg & MV88E6XXX_PORT_STS_PHY_DETECT);
482}
483
Russell Kinga5a68582020-03-14 10:15:43 +0000484static int mv88e6xxx_serdes_pcs_get_state(struct dsa_switch *ds, int port,
485 struct phylink_link_state *state)
486{
487 struct mv88e6xxx_chip *chip = ds->priv;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100488 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000489 int err;
490
491 mv88e6xxx_reg_lock(chip);
492 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100493 if (lane >= 0 && chip->info->ops->serdes_pcs_get_state)
Russell Kinga5a68582020-03-14 10:15:43 +0000494 err = chip->info->ops->serdes_pcs_get_state(chip, port, lane,
495 state);
496 else
497 err = -EOPNOTSUPP;
498 mv88e6xxx_reg_unlock(chip);
499
500 return err;
501}
502
503static int mv88e6xxx_serdes_pcs_config(struct mv88e6xxx_chip *chip, int port,
504 unsigned int mode,
505 phy_interface_t interface,
506 const unsigned long *advertise)
507{
508 const struct mv88e6xxx_ops *ops = chip->info->ops;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100509 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000510
511 if (ops->serdes_pcs_config) {
512 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100513 if (lane >= 0)
Russell Kinga5a68582020-03-14 10:15:43 +0000514 return ops->serdes_pcs_config(chip, port, lane, mode,
515 interface, advertise);
516 }
517
518 return 0;
519}
520
521static void mv88e6xxx_serdes_pcs_an_restart(struct dsa_switch *ds, int port)
522{
523 struct mv88e6xxx_chip *chip = ds->priv;
524 const struct mv88e6xxx_ops *ops;
525 int err = 0;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100526 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000527
528 ops = chip->info->ops;
529
530 if (ops->serdes_pcs_an_restart) {
531 mv88e6xxx_reg_lock(chip);
532 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100533 if (lane >= 0)
Russell Kinga5a68582020-03-14 10:15:43 +0000534 err = ops->serdes_pcs_an_restart(chip, port, lane);
535 mv88e6xxx_reg_unlock(chip);
536
537 if (err)
538 dev_err(ds->dev, "p%d: failed to restart AN\n", port);
539 }
540}
541
542static int mv88e6xxx_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port,
543 unsigned int mode,
544 int speed, int duplex)
545{
546 const struct mv88e6xxx_ops *ops = chip->info->ops;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100547 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000548
549 if (!phylink_autoneg_inband(mode) && ops->serdes_pcs_link_up) {
550 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100551 if (lane >= 0)
Russell Kinga5a68582020-03-14 10:15:43 +0000552 return ops->serdes_pcs_link_up(chip, port, lane,
553 speed, duplex);
554 }
555
556 return 0;
557}
558
Russell King6c422e32018-08-09 15:38:39 +0200559static void mv88e6065_phylink_validate(struct mv88e6xxx_chip *chip, int port,
560 unsigned long *mask,
561 struct phylink_link_state *state)
562{
563 if (!phy_interface_mode_is_8023z(state->interface)) {
564 /* 10M and 100M are only supported in non-802.3z mode */
565 phylink_set(mask, 10baseT_Half);
566 phylink_set(mask, 10baseT_Full);
567 phylink_set(mask, 100baseT_Half);
568 phylink_set(mask, 100baseT_Full);
569 }
570}
571
572static void mv88e6185_phylink_validate(struct mv88e6xxx_chip *chip, int port,
573 unsigned long *mask,
574 struct phylink_link_state *state)
575{
576 /* FIXME: if the port is in 1000Base-X mode, then it only supports
577 * 1000M FD speeds. In this case, CMODE will indicate 5.
578 */
579 phylink_set(mask, 1000baseT_Full);
580 phylink_set(mask, 1000baseX_Full);
581
582 mv88e6065_phylink_validate(chip, port, mask, state);
583}
584
Marek Behúne3af71a2019-02-25 12:39:55 +0100585static void mv88e6341_phylink_validate(struct mv88e6xxx_chip *chip, int port,
586 unsigned long *mask,
587 struct phylink_link_state *state)
588{
589 if (port >= 5)
590 phylink_set(mask, 2500baseX_Full);
591
592 /* No ethtool bits for 200Mbps */
593 phylink_set(mask, 1000baseT_Full);
594 phylink_set(mask, 1000baseX_Full);
595
596 mv88e6065_phylink_validate(chip, port, mask, state);
597}
598
Russell King6c422e32018-08-09 15:38:39 +0200599static void mv88e6352_phylink_validate(struct mv88e6xxx_chip *chip, int port,
600 unsigned long *mask,
601 struct phylink_link_state *state)
602{
603 /* No ethtool bits for 200Mbps */
604 phylink_set(mask, 1000baseT_Full);
605 phylink_set(mask, 1000baseX_Full);
606
607 mv88e6065_phylink_validate(chip, port, mask, state);
608}
609
610static void mv88e6390_phylink_validate(struct mv88e6xxx_chip *chip, int port,
611 unsigned long *mask,
612 struct phylink_link_state *state)
613{
Andrew Lunnec260162019-02-08 22:25:44 +0100614 if (port >= 9) {
Russell King6c422e32018-08-09 15:38:39 +0200615 phylink_set(mask, 2500baseX_Full);
Andrew Lunnec260162019-02-08 22:25:44 +0100616 phylink_set(mask, 2500baseT_Full);
617 }
Russell King6c422e32018-08-09 15:38:39 +0200618
619 /* No ethtool bits for 200Mbps */
620 phylink_set(mask, 1000baseT_Full);
621 phylink_set(mask, 1000baseX_Full);
622
623 mv88e6065_phylink_validate(chip, port, mask, state);
624}
625
626static void mv88e6390x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
627 unsigned long *mask,
628 struct phylink_link_state *state)
629{
630 if (port >= 9) {
631 phylink_set(mask, 10000baseT_Full);
632 phylink_set(mask, 10000baseKR_Full);
633 }
634
635 mv88e6390_phylink_validate(chip, port, mask, state);
636}
637
Pavana Sharmade776d02021-03-17 14:46:42 +0100638static void mv88e6393x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
639 unsigned long *mask,
640 struct phylink_link_state *state)
641{
642 if (port == 0 || port == 9 || port == 10) {
643 phylink_set(mask, 10000baseT_Full);
644 phylink_set(mask, 10000baseKR_Full);
645 phylink_set(mask, 10000baseCR_Full);
646 phylink_set(mask, 10000baseSR_Full);
647 phylink_set(mask, 10000baseLR_Full);
648 phylink_set(mask, 10000baseLRM_Full);
649 phylink_set(mask, 10000baseER_Full);
650 phylink_set(mask, 5000baseT_Full);
651 phylink_set(mask, 2500baseX_Full);
652 phylink_set(mask, 2500baseT_Full);
653 }
654
655 phylink_set(mask, 1000baseT_Full);
656 phylink_set(mask, 1000baseX_Full);
657
658 mv88e6065_phylink_validate(chip, port, mask, state);
659}
660
Russell Kingc9a23562018-05-10 13:17:35 -0700661static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
662 unsigned long *supported,
663 struct phylink_link_state *state)
664{
Russell King6c422e32018-08-09 15:38:39 +0200665 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
666 struct mv88e6xxx_chip *chip = ds->priv;
667
668 /* Allow all the expected bits */
669 phylink_set(mask, Autoneg);
670 phylink_set(mask, Pause);
671 phylink_set_port_modes(mask);
672
673 if (chip->info->ops->phylink_validate)
674 chip->info->ops->phylink_validate(chip, port, mask, state);
675
676 bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
677 bitmap_and(state->advertising, state->advertising, mask,
678 __ETHTOOL_LINK_MODE_MASK_NBITS);
679
680 /* We can only operate at 2500BaseX or 1000BaseX. If requested
681 * to advertise both, only report advertising at 2500BaseX.
682 */
683 phylink_helper_basex_speed(state);
Russell Kingc9a23562018-05-10 13:17:35 -0700684}
685
Russell Kingc9a23562018-05-10 13:17:35 -0700686static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
687 unsigned int mode,
688 const struct phylink_link_state *state)
689{
690 struct mv88e6xxx_chip *chip = ds->priv;
Russell Kingfad58192020-07-19 12:00:35 +0100691 struct mv88e6xxx_port *p;
Russell King64d47d52020-03-14 10:15:38 +0000692 int err;
Russell Kingc9a23562018-05-10 13:17:35 -0700693
Russell Kingfad58192020-07-19 12:00:35 +0100694 p = &chip->ports[port];
695
Russell King64d47d52020-03-14 10:15:38 +0000696 /* FIXME: is this the correct test? If we're in fixed mode on an
697 * internal port, why should we process this any different from
698 * PHY mode? On the other hand, the port may be automedia between
699 * an internal PHY and the serdes...
700 */
Marek Vasutd700ec42018-09-12 00:15:24 +0200701 if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
Russell Kingc9a23562018-05-10 13:17:35 -0700702 return;
703
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000704 mv88e6xxx_reg_lock(chip);
Russell Kingfad58192020-07-19 12:00:35 +0100705 /* In inband mode, the link may come up at any time while the link
706 * is not forced down. Force the link down while we reconfigure the
707 * interface mode.
Russell King64d47d52020-03-14 10:15:38 +0000708 */
Russell Kingfad58192020-07-19 12:00:35 +0100709 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
710 chip->info->ops->port_set_link)
711 chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
712
Russell King64d47d52020-03-14 10:15:38 +0000713 err = mv88e6xxx_port_config_interface(chip, port, state->interface);
Russell Kinga5a68582020-03-14 10:15:43 +0000714 if (err && err != -EOPNOTSUPP)
715 goto err_unlock;
716
717 err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
718 state->advertising);
719 /* FIXME: we should restart negotiation if something changed - which
720 * is something we get if we convert to using phylinks PCS operations.
721 */
722 if (err > 0)
723 err = 0;
724
Russell Kingfad58192020-07-19 12:00:35 +0100725 /* Undo the forced down state above after completing configuration
726 * irrespective of its state on entry, which allows the link to come up.
727 */
728 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
729 chip->info->ops->port_set_link)
730 chip->info->ops->port_set_link(chip, port, LINK_UNFORCED);
731
732 p->interface = state->interface;
733
Russell Kinga5a68582020-03-14 10:15:43 +0000734err_unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000735 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700736
737 if (err && err != -EOPNOTSUPP)
Russell King64d47d52020-03-14 10:15:38 +0000738 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700739}
740
Russell Kingc9a23562018-05-10 13:17:35 -0700741static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
742 unsigned int mode,
743 phy_interface_t interface)
744{
Russell King30c4a5b2020-02-26 10:23:51 +0000745 struct mv88e6xxx_chip *chip = ds->priv;
746 const struct mv88e6xxx_ops *ops;
747 int err = 0;
748
749 ops = chip->info->ops;
750
Russell King5d5b2312020-03-14 10:16:03 +0000751 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200752 if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
Chris Packham4efe76622020-11-24 17:34:37 +1300753 mode == MLO_AN_FIXED) && ops->port_sync_link)
754 err = ops->port_sync_link(chip, port, mode, false);
Russell King5d5b2312020-03-14 10:16:03 +0000755 mv88e6xxx_reg_unlock(chip);
Russell King30c4a5b2020-02-26 10:23:51 +0000756
Russell King5d5b2312020-03-14 10:16:03 +0000757 if (err)
758 dev_err(chip->dev,
759 "p%d: failed to force MAC link down\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700760}
761
762static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
763 unsigned int mode, phy_interface_t interface,
Russell King5b502a72020-02-26 10:23:46 +0000764 struct phy_device *phydev,
765 int speed, int duplex,
766 bool tx_pause, bool rx_pause)
Russell Kingc9a23562018-05-10 13:17:35 -0700767{
Russell King30c4a5b2020-02-26 10:23:51 +0000768 struct mv88e6xxx_chip *chip = ds->priv;
769 const struct mv88e6xxx_ops *ops;
770 int err = 0;
771
772 ops = chip->info->ops;
773
Russell King5d5b2312020-03-14 10:16:03 +0000774 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200775 if (!mv88e6xxx_port_ppu_updates(chip, port) || mode == MLO_AN_FIXED) {
Russell King30c4a5b2020-02-26 10:23:51 +0000776 /* FIXME: for an automedia port, should we force the link
777 * down here - what if the link comes up due to "other" media
778 * while we're bringing the port up, how is the exclusivity
Russell Kinga5a68582020-03-14 10:15:43 +0000779 * handled in the Marvell hardware? E.g. port 2 on 88E6390
Russell King30c4a5b2020-02-26 10:23:51 +0000780 * shared between internal PHY and Serdes.
781 */
Russell Kinga5a68582020-03-14 10:15:43 +0000782 err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
783 duplex);
784 if (err)
785 goto error;
786
Russell Kingf365c6f2020-03-14 10:15:53 +0000787 if (ops->port_set_speed_duplex) {
788 err = ops->port_set_speed_duplex(chip, port,
789 speed, duplex);
Russell King30c4a5b2020-02-26 10:23:51 +0000790 if (err && err != -EOPNOTSUPP)
791 goto error;
792 }
793
Chris Packham4efe76622020-11-24 17:34:37 +1300794 if (ops->port_sync_link)
795 err = ops->port_sync_link(chip, port, mode, true);
Russell King30c4a5b2020-02-26 10:23:51 +0000796 }
Russell King5d5b2312020-03-14 10:16:03 +0000797error:
798 mv88e6xxx_reg_unlock(chip);
799
800 if (err && err != -EOPNOTSUPP)
801 dev_err(ds->dev,
802 "p%d: failed to configure MAC link up\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700803}
804
Andrew Lunna605a0f2016-11-21 23:26:58 +0100805static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000806{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100807 if (!chip->info->ops->stats_snapshot)
808 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000809
Andrew Lunna605a0f2016-11-21 23:26:58 +0100810 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000811}
812
Andrew Lunne413e7e2015-04-02 04:06:38 +0200813static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100814 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
815 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
816 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
817 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
818 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
819 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
820 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
821 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
822 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
823 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
824 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
825 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
826 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
827 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
828 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
829 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
830 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
831 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
832 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
833 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
834 { "single", 4, 0x14, STATS_TYPE_BANK0, },
835 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
836 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
837 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
838 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
839 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
840 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
841 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
842 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
843 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
844 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
845 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
846 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
847 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
848 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
849 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
850 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
851 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
852 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
853 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
854 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
855 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
856 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
857 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
858 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
859 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
860 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
861 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
862 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
863 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
864 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
865 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
866 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
867 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
868 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
869 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
870 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
871 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
872 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200873};
874
Vivien Didelotfad09c72016-06-21 12:28:20 -0400875static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100876 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100877 int port, u16 bank1_select,
878 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200879{
Andrew Lunn80c46272015-06-20 18:42:30 +0200880 u32 low;
881 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100882 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200883 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200884 u64 value;
885
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100886 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100887 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200888 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
889 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800890 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200891
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200892 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100893 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200894 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
895 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800896 return U64_MAX;
Rasmus Villemoes84b3fd12019-05-29 07:02:11 +0000897 low |= ((u32)reg) << 16;
Andrew Lunn80c46272015-06-20 18:42:30 +0200898 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100899 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100900 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100901 reg = bank1_select;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500902 fallthrough;
Andrew Lunndfafe442016-11-21 23:27:02 +0100903 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100904 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100905 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100906 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100907 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500908 break;
909 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800910 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200911 }
Andrew Lunn6e46e2d2019-02-28 18:14:03 +0100912 value = (((u64)high) << 32) | low;
Andrew Lunn80c46272015-06-20 18:42:30 +0200913 return value;
914}
915
Andrew Lunn436fe172018-03-01 02:02:29 +0100916static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
917 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100918{
919 struct mv88e6xxx_hw_stat *stat;
920 int i, j;
921
922 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
923 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100924 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100925 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
926 ETH_GSTRING_LEN);
927 j++;
928 }
929 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100930
931 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100932}
933
Andrew Lunn436fe172018-03-01 02:02:29 +0100934static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
935 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100936{
Andrew Lunn436fe172018-03-01 02:02:29 +0100937 return mv88e6xxx_stats_get_strings(chip, data,
938 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100939}
940
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000941static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
942 uint8_t *data)
943{
944 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
945}
946
Andrew Lunn436fe172018-03-01 02:02:29 +0100947static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
948 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100949{
Andrew Lunn436fe172018-03-01 02:02:29 +0100950 return mv88e6xxx_stats_get_strings(chip, data,
951 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100952}
953
Andrew Lunn65f60e42018-03-28 23:50:28 +0200954static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
955 "atu_member_violation",
956 "atu_miss_violation",
957 "atu_full_violation",
958 "vtu_member_violation",
959 "vtu_miss_violation",
960};
961
962static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
963{
964 unsigned int i;
965
966 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
967 strlcpy(data + i * ETH_GSTRING_LEN,
968 mv88e6xxx_atu_vtu_stats_strings[i],
969 ETH_GSTRING_LEN);
970}
971
Andrew Lunndfafe442016-11-21 23:27:02 +0100972static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700973 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100974{
Vivien Didelot04bed142016-08-31 18:06:13 -0400975 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100976 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100977
Florian Fainelli89f09042018-04-25 12:12:50 -0700978 if (stringset != ETH_SS_STATS)
979 return;
980
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000981 mv88e6xxx_reg_lock(chip);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100982
Andrew Lunndfafe442016-11-21 23:27:02 +0100983 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100984 count = chip->info->ops->stats_get_strings(chip, data);
985
986 if (chip->info->ops->serdes_get_strings) {
987 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200988 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100989 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100990
Andrew Lunn65f60e42018-03-28 23:50:28 +0200991 data += count * ETH_GSTRING_LEN;
992 mv88e6xxx_atu_vtu_get_strings(data);
993
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000994 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100995}
996
997static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
998 int types)
999{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001000 struct mv88e6xxx_hw_stat *stat;
1001 int i, j;
1002
1003 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1004 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +01001005 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001006 j++;
1007 }
1008 return j;
1009}
1010
Andrew Lunndfafe442016-11-21 23:27:02 +01001011static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1012{
1013 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1014 STATS_TYPE_PORT);
1015}
1016
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001017static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1018{
1019 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
1020}
1021
Andrew Lunndfafe442016-11-21 23:27:02 +01001022static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1023{
1024 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1025 STATS_TYPE_BANK1);
1026}
1027
Florian Fainelli89f09042018-04-25 12:12:50 -07001028static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +01001029{
1030 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +01001031 int serdes_count = 0;
1032 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +01001033
Florian Fainelli89f09042018-04-25 12:12:50 -07001034 if (sset != ETH_SS_STATS)
1035 return 0;
1036
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001037 mv88e6xxx_reg_lock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001038 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +01001039 count = chip->info->ops->stats_get_sset_count(chip);
1040 if (count < 0)
1041 goto out;
1042
1043 if (chip->info->ops->serdes_get_sset_count)
1044 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1045 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +02001046 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +01001047 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001048 goto out;
1049 }
1050 count += serdes_count;
1051 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1052
Andrew Lunn436fe172018-03-01 02:02:29 +01001053out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001054 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001055
Andrew Lunn436fe172018-03-01 02:02:29 +01001056 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +01001057}
1058
Andrew Lunn436fe172018-03-01 02:02:29 +01001059static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1060 uint64_t *data, int types,
1061 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +01001062{
1063 struct mv88e6xxx_hw_stat *stat;
1064 int i, j;
1065
1066 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1067 stat = &mv88e6xxx_hw_stats[i];
1068 if (stat->type & types) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001069 mv88e6xxx_reg_lock(chip);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001070 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1071 bank1_select,
1072 histogram);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001073 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001074
Andrew Lunn052f9472016-11-21 23:27:03 +01001075 j++;
1076 }
1077 }
Andrew Lunn436fe172018-03-01 02:02:29 +01001078 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +01001079}
1080
Andrew Lunn436fe172018-03-01 02:02:29 +01001081static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1082 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001083{
1084 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001085 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001086 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +01001087}
1088
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001089static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1090 uint64_t *data)
1091{
1092 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
1093 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1094}
1095
Andrew Lunn436fe172018-03-01 02:02:29 +01001096static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1097 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001098{
1099 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001100 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001101 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1102 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001103}
1104
Andrew Lunn436fe172018-03-01 02:02:29 +01001105static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1106 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +01001107{
1108 return mv88e6xxx_stats_get_stats(chip, port, data,
1109 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001110 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1111 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001112}
1113
Andrew Lunn65f60e42018-03-28 23:50:28 +02001114static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1115 uint64_t *data)
1116{
1117 *data++ = chip->ports[port].atu_member_violation;
1118 *data++ = chip->ports[port].atu_miss_violation;
1119 *data++ = chip->ports[port].atu_full_violation;
1120 *data++ = chip->ports[port].vtu_member_violation;
1121 *data++ = chip->ports[port].vtu_miss_violation;
1122}
1123
Andrew Lunn052f9472016-11-21 23:27:03 +01001124static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1125 uint64_t *data)
1126{
Andrew Lunn436fe172018-03-01 02:02:29 +01001127 int count = 0;
1128
Andrew Lunn052f9472016-11-21 23:27:03 +01001129 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +01001130 count = chip->info->ops->stats_get_stats(chip, port, data);
1131
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001132 mv88e6xxx_reg_lock(chip);
Andrew Lunn436fe172018-03-01 02:02:29 +01001133 if (chip->info->ops->serdes_get_stats) {
1134 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001135 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +01001136 }
Andrew Lunn65f60e42018-03-28 23:50:28 +02001137 data += count;
1138 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001139 mv88e6xxx_reg_unlock(chip);
Andrew Lunn052f9472016-11-21 23:27:03 +01001140}
1141
Vivien Didelotf81ec902016-05-09 13:22:58 -04001142static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1143 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001144{
Vivien Didelot04bed142016-08-31 18:06:13 -04001145 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001146 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001147
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001148 mv88e6xxx_reg_lock(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001149
Andrew Lunna605a0f2016-11-21 23:26:58 +01001150 ret = mv88e6xxx_stats_snapshot(chip, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001151 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001152
1153 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001154 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001155
1156 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001157
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001158}
Ben Hutchings98e67302011-11-25 14:36:19 +00001159
Vivien Didelotf81ec902016-05-09 13:22:58 -04001160static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001161{
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001162 struct mv88e6xxx_chip *chip = ds->priv;
1163 int len;
1164
1165 len = 32 * sizeof(u16);
1166 if (chip->info->ops->serdes_get_regs_len)
1167 len += chip->info->ops->serdes_get_regs_len(chip, port);
1168
1169 return len;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001170}
1171
Vivien Didelotf81ec902016-05-09 13:22:58 -04001172static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1173 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001174{
Vivien Didelot04bed142016-08-31 18:06:13 -04001175 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001176 int err;
1177 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001178 u16 *p = _p;
1179 int i;
1180
Vivien Didelota5f39322018-12-17 16:05:21 -05001181 regs->version = chip->info->prod_num;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001182
1183 memset(p, 0xff, 32 * sizeof(u16));
1184
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001185 mv88e6xxx_reg_lock(chip);
Vivien Didelot23062512016-05-09 13:22:45 -04001186
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001187 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001188
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001189 err = mv88e6xxx_port_read(chip, port, i, &reg);
1190 if (!err)
1191 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001192 }
Vivien Didelot23062512016-05-09 13:22:45 -04001193
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001194 if (chip->info->ops->serdes_get_regs)
1195 chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1196
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001197 mv88e6xxx_reg_unlock(chip);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001198}
1199
Vivien Didelot08f50062017-08-01 16:32:41 -04001200static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1201 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001202{
Vivien Didelot5480db62017-08-01 16:32:40 -04001203 /* Nothing to do on the port's MAC */
1204 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001205}
1206
Vivien Didelot08f50062017-08-01 16:32:41 -04001207static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1208 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001209{
Vivien Didelot5480db62017-08-01 16:32:40 -04001210 /* Nothing to do on the port's MAC */
1211 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001212}
1213
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001214/* Mask of the local ports allowed to receive frames from a given fabric port */
Vivien Didelote5887a22017-03-30 17:37:11 -04001215static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001216{
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001217 struct dsa_switch *ds = chip->ds;
1218 struct dsa_switch_tree *dst = ds->dst;
Vivien Didelote5887a22017-03-30 17:37:11 -04001219 struct net_device *br;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001220 struct dsa_port *dp;
1221 bool found = false;
Vivien Didelote5887a22017-03-30 17:37:11 -04001222 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001223
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001224 list_for_each_entry(dp, &dst->ports, list) {
1225 if (dp->ds->index == dev && dp->index == port) {
1226 found = true;
1227 break;
1228 }
1229 }
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001230
Vivien Didelote5887a22017-03-30 17:37:11 -04001231 /* Prevent frames from unknown switch or port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001232 if (!found)
Vivien Didelote5887a22017-03-30 17:37:11 -04001233 return 0;
1234
1235 /* Frames from DSA links and CPU ports can egress any local port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001236 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
Vivien Didelote5887a22017-03-30 17:37:11 -04001237 return mv88e6xxx_port_mask(chip);
1238
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001239 br = dp->bridge_dev;
Vivien Didelote5887a22017-03-30 17:37:11 -04001240 pvlan = 0;
1241
1242 /* Frames from user ports can egress any local DSA links and CPU ports,
1243 * as well as any local member of their bridge group.
1244 */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001245 list_for_each_entry(dp, &dst->ports, list)
1246 if (dp->ds == ds &&
1247 (dp->type == DSA_PORT_TYPE_CPU ||
1248 dp->type == DSA_PORT_TYPE_DSA ||
1249 (br && dp->bridge_dev == br)))
1250 pvlan |= BIT(dp->index);
Vivien Didelote5887a22017-03-30 17:37:11 -04001251
1252 return pvlan;
1253}
1254
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001255static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001256{
1257 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001258
1259 /* prevent frames from going back out of the port they came in on */
1260 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001261
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001262 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001263}
1264
Vivien Didelotf81ec902016-05-09 13:22:58 -04001265static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1266 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001267{
Vivien Didelot04bed142016-08-31 18:06:13 -04001268 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001269 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001270
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001271 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001272 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001273 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001274
1275 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001276 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001277}
1278
Vivien Didelot93e18d62018-05-11 17:16:35 -04001279static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1280{
1281 int err;
1282
1283 if (chip->info->ops->ieee_pri_map) {
1284 err = chip->info->ops->ieee_pri_map(chip);
1285 if (err)
1286 return err;
1287 }
1288
1289 if (chip->info->ops->ip_pri_map) {
1290 err = chip->info->ops->ip_pri_map(chip);
1291 if (err)
1292 return err;
1293 }
1294
1295 return 0;
1296}
1297
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001298static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1299{
Vivien Didelotc5f51762019-10-30 22:09:13 -04001300 struct dsa_switch *ds = chip->ds;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001301 int target, port;
1302 int err;
1303
1304 if (!chip->info->global2_addr)
1305 return 0;
1306
1307 /* Initialize the routing port to the 32 possible target devices */
1308 for (target = 0; target < 32; target++) {
Vivien Didelotc5f51762019-10-30 22:09:13 -04001309 port = dsa_routing_port(ds, target);
1310 if (port == ds->num_ports)
1311 port = 0x1f;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001312
1313 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1314 if (err)
1315 return err;
1316 }
1317
Vivien Didelot02317e62018-05-09 11:38:49 -04001318 if (chip->info->ops->set_cascade_port) {
1319 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1320 err = chip->info->ops->set_cascade_port(chip, port);
1321 if (err)
1322 return err;
1323 }
1324
Vivien Didelot23c98912018-05-09 11:38:50 -04001325 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1326 if (err)
1327 return err;
1328
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001329 return 0;
1330}
1331
Vivien Didelotb28f8722018-04-26 21:56:44 -04001332static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1333{
1334 /* Clear all trunk masks and mapping */
1335 if (chip->info->global2_addr)
1336 return mv88e6xxx_g2_trunk_clear(chip);
1337
1338 return 0;
1339}
1340
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001341static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1342{
1343 if (chip->info->ops->rmu_disable)
1344 return chip->info->ops->rmu_disable(chip);
1345
1346 return 0;
1347}
1348
Vivien Didelot9e907d72017-07-17 13:03:43 -04001349static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1350{
1351 if (chip->info->ops->pot_clear)
1352 return chip->info->ops->pot_clear(chip);
1353
1354 return 0;
1355}
1356
Vivien Didelot51c901a2017-07-17 13:03:41 -04001357static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1358{
1359 if (chip->info->ops->mgmt_rsvd2cpu)
1360 return chip->info->ops->mgmt_rsvd2cpu(chip);
1361
1362 return 0;
1363}
1364
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001365static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1366{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001367 int err;
1368
Vivien Didelotdaefc942017-03-11 16:12:54 -05001369 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1370 if (err)
1371 return err;
1372
Rasmus Villemoes49506a92020-12-10 12:06:44 +01001373 /* The chips that have a "learn2all" bit in Global1, ATU
1374 * Control are precisely those whose port registers have a
1375 * Message Port bit in Port Control 1 and hence implement
1376 * ->port_setup_message_port.
1377 */
1378 if (chip->info->ops->port_setup_message_port) {
1379 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1380 if (err)
1381 return err;
1382 }
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001383
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001384 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1385}
1386
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001387static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1388{
1389 int port;
1390 int err;
1391
1392 if (!chip->info->ops->irl_init_all)
1393 return 0;
1394
1395 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1396 /* Disable ingress rate limiting by resetting all per port
1397 * ingress rate limit resources to their initial state.
1398 */
1399 err = chip->info->ops->irl_init_all(chip, port);
1400 if (err)
1401 return err;
1402 }
1403
1404 return 0;
1405}
1406
Vivien Didelot04a69a12017-10-13 14:18:05 -04001407static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1408{
1409 if (chip->info->ops->set_switch_mac) {
1410 u8 addr[ETH_ALEN];
1411
1412 eth_random_addr(addr);
1413
1414 return chip->info->ops->set_switch_mac(chip, addr);
1415 }
1416
1417 return 0;
1418}
1419
Vivien Didelot17a15942017-03-30 17:37:09 -04001420static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1421{
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001422 struct dsa_switch_tree *dst = chip->ds->dst;
1423 struct dsa_switch *ds;
1424 struct dsa_port *dp;
Vivien Didelot17a15942017-03-30 17:37:09 -04001425 u16 pvlan = 0;
1426
1427 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001428 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001429
1430 /* Skip the local source device, which uses in-chip port VLAN */
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001431 if (dev != chip->ds->index) {
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001432 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001433
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001434 ds = dsa_switch_find(dst->index, dev);
1435 dp = ds ? dsa_to_port(ds, port) : NULL;
1436 if (dp && dp->lag_dev) {
1437 /* As the PVT is used to limit flooding of
1438 * FORWARD frames, which use the LAG ID as the
1439 * source port, we must translate dev/port to
1440 * the special "LAG device" in the PVT, using
1441 * the LAG ID as the port number.
1442 */
1443 dev = MV88E6XXX_G2_PVT_ADRR_DEV_TRUNK;
1444 port = dsa_lag_id(dst, dp->lag_dev);
1445 }
1446 }
1447
Vivien Didelot17a15942017-03-30 17:37:09 -04001448 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1449}
1450
Vivien Didelot81228992017-03-30 17:37:08 -04001451static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1452{
Vivien Didelot17a15942017-03-30 17:37:09 -04001453 int dev, port;
1454 int err;
1455
Vivien Didelot81228992017-03-30 17:37:08 -04001456 if (!mv88e6xxx_has_pvt(chip))
1457 return 0;
1458
1459 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1460 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1461 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001462 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1463 if (err)
1464 return err;
1465
1466 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1467 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1468 err = mv88e6xxx_pvt_map(chip, dev, port);
1469 if (err)
1470 return err;
1471 }
1472 }
1473
1474 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001475}
1476
Vivien Didelot749efcb2016-09-22 16:49:24 -04001477static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1478{
1479 struct mv88e6xxx_chip *chip = ds->priv;
1480 int err;
1481
Tobias Waldekranzffcec3f2021-03-18 20:25:34 +01001482 if (dsa_to_port(ds, port)->lag_dev)
1483 /* Hardware is incapable of fast-aging a LAG through a
1484 * regular ATU move operation. Until we have something
1485 * more fancy in place this is a no-op.
1486 */
1487 return;
1488
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001489 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001490 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001491 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001492
1493 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001494 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001495}
1496
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001497static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1498{
Tobias Waldekranze545f862020-11-10 19:57:20 +01001499 if (!mv88e6xxx_max_vid(chip))
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001500 return 0;
1501
1502 return mv88e6xxx_g1_vtu_flush(chip);
1503}
1504
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001505static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1506 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotf1394b782017-05-01 14:05:22 -04001507{
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001508 int err;
1509
Vivien Didelotf1394b782017-05-01 14:05:22 -04001510 if (!chip->info->ops->vtu_getnext)
1511 return -EOPNOTSUPP;
1512
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001513 entry->vid = vid ? vid - 1 : mv88e6xxx_max_vid(chip);
1514 entry->valid = false;
1515
1516 err = chip->info->ops->vtu_getnext(chip, entry);
1517
1518 if (entry->vid != vid)
1519 entry->valid = false;
1520
1521 return err;
Vivien Didelotf1394b782017-05-01 14:05:22 -04001522}
1523
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001524static int mv88e6xxx_vtu_walk(struct mv88e6xxx_chip *chip,
1525 int (*cb)(struct mv88e6xxx_chip *chip,
1526 const struct mv88e6xxx_vtu_entry *entry,
1527 void *priv),
1528 void *priv)
1529{
1530 struct mv88e6xxx_vtu_entry entry = {
1531 .vid = mv88e6xxx_max_vid(chip),
1532 .valid = false,
1533 };
1534 int err;
1535
1536 if (!chip->info->ops->vtu_getnext)
1537 return -EOPNOTSUPP;
1538
1539 do {
1540 err = chip->info->ops->vtu_getnext(chip, &entry);
1541 if (err)
1542 return err;
1543
1544 if (!entry.valid)
1545 break;
1546
1547 err = cb(chip, &entry, priv);
1548 if (err)
1549 return err;
1550 } while (entry.vid < mv88e6xxx_max_vid(chip));
1551
1552 return 0;
1553}
1554
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001555static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1556 struct mv88e6xxx_vtu_entry *entry)
1557{
1558 if (!chip->info->ops->vtu_loadpurge)
1559 return -EOPNOTSUPP;
1560
1561 return chip->info->ops->vtu_loadpurge(chip, entry);
1562}
1563
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001564static int mv88e6xxx_fid_map_vlan(struct mv88e6xxx_chip *chip,
1565 const struct mv88e6xxx_vtu_entry *entry,
1566 void *_fid_bitmap)
1567{
1568 unsigned long *fid_bitmap = _fid_bitmap;
1569
1570 set_bit(entry->fid, fid_bitmap);
1571 return 0;
1572}
1573
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001574int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001575{
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001576 int i, err;
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001577 u16 fid;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001578
1579 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1580
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001581 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001582 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001583 err = mv88e6xxx_port_get_fid(chip, i, &fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001584 if (err)
1585 return err;
1586
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001587 set_bit(fid, fid_bitmap);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001588 }
1589
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001590 /* Set every FID bit used by the VLAN entries */
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001591 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_fid_map_vlan, fid_bitmap);
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001592}
1593
1594static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1595{
1596 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1597 int err;
1598
1599 err = mv88e6xxx_fid_map(chip, fid_bitmap);
1600 if (err)
1601 return err;
1602
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001603 /* The reset value 0x000 is used to indicate that multiple address
1604 * databases are not needed. Return the next positive available.
1605 */
1606 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001607 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001608 return -ENOSPC;
1609
1610 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001611 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001612}
1613
Vivien Didelotda9c3592016-02-12 12:09:40 -05001614static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001615 u16 vid)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001616{
Vivien Didelot04bed142016-08-31 18:06:13 -04001617 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001618 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001619 int i, err;
1620
Vladimir Oltean3e85f582021-01-09 02:01:47 +02001621 if (!vid)
1622 return -EOPNOTSUPP;
1623
Andrew Lunndb06ae412017-09-25 23:32:20 +02001624 /* DSA and CPU ports have to be members of multiple vlans */
1625 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1626 return 0;
1627
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001628 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001629 if (err)
1630 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001631
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001632 if (!vlan.valid)
1633 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001634
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001635 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1636 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1637 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001638
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001639 if (!dsa_to_port(ds, i)->slave)
1640 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001641
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001642 if (vlan.member[i] ==
1643 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1644 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001645
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001646 if (dsa_to_port(ds, i)->bridge_dev ==
1647 dsa_to_port(ds, port)->bridge_dev)
1648 break; /* same bridge, check next VLAN */
Vivien Didelotda9c3592016-02-12 12:09:40 -05001649
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001650 if (!dsa_to_port(ds, i)->bridge_dev)
1651 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001652
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001653 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1654 port, vlan.vid, i,
1655 netdev_name(dsa_to_port(ds, i)->bridge_dev));
1656 return -EOPNOTSUPP;
1657 }
Vivien Didelotda9c3592016-02-12 12:09:40 -05001658
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001659 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001660}
1661
Vivien Didelotf81ec902016-05-09 13:22:58 -04001662static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
Vladimir Oltean89153ed2021-02-13 22:43:19 +02001663 bool vlan_filtering,
1664 struct netlink_ext_ack *extack)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001665{
Vivien Didelot04bed142016-08-31 18:06:13 -04001666 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001667 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1668 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001669 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001670
Vladimir Olteanbae33f22021-01-09 02:01:50 +02001671 if (!mv88e6xxx_max_vid(chip))
1672 return -EOPNOTSUPP;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001673
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001674 mv88e6xxx_reg_lock(chip);
Vivien Didelot385a0992016-11-04 03:23:31 +01001675 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001676 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001677
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001678 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001679}
1680
Vivien Didelot57d32312016-06-20 13:13:58 -04001681static int
1682mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001683 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001684{
Vivien Didelot04bed142016-08-31 18:06:13 -04001685 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001686 int err;
1687
Tobias Waldekranze545f862020-11-10 19:57:20 +01001688 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001689 return -EOPNOTSUPP;
1690
Vivien Didelotda9c3592016-02-12 12:09:40 -05001691 /* If the requested port doesn't belong to the same bridge as the VLAN
1692 * members, do not support it (yet) and fallback to software VLAN.
1693 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001694 mv88e6xxx_reg_lock(chip);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001695 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001696 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001697
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001698 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001699}
1700
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001701static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1702 const unsigned char *addr, u16 vid,
1703 u8 state)
1704{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001705 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001706 struct mv88e6xxx_vtu_entry vlan;
1707 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001708 int err;
1709
1710 /* Null VLAN ID corresponds to the port private database */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001711 if (vid == 0) {
1712 err = mv88e6xxx_port_get_fid(chip, port, &fid);
1713 if (err)
1714 return err;
1715 } else {
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001716 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001717 if (err)
1718 return err;
1719
1720 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001721 if (!vlan.valid)
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001722 return -EOPNOTSUPP;
1723
1724 fid = vlan.fid;
1725 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001726
Vivien Didelotd8291a92019-09-07 16:00:47 -04001727 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001728 ether_addr_copy(entry.mac, addr);
1729 eth_addr_dec(entry.mac);
1730
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001731 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001732 if (err)
1733 return err;
1734
1735 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001736 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001737 memset(&entry, 0, sizeof(entry));
1738 ether_addr_copy(entry.mac, addr);
1739 }
1740
1741 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001742 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001743 entry.portvec &= ~BIT(port);
1744 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001745 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001746 } else {
DENG Qingfangf72f2fb2021-01-30 21:43:34 +08001747 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
1748 entry.portvec = BIT(port);
1749 else
1750 entry.portvec |= BIT(port);
1751
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001752 entry.state = state;
1753 }
1754
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001755 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001756}
1757
Vivien Didelotda7dc872019-09-07 16:00:49 -04001758static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1759 const struct mv88e6xxx_policy *policy)
1760{
1761 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1762 enum mv88e6xxx_policy_action action = policy->action;
1763 const u8 *addr = policy->addr;
1764 u16 vid = policy->vid;
1765 u8 state;
1766 int err;
1767 int id;
1768
1769 if (!chip->info->ops->port_set_policy)
1770 return -EOPNOTSUPP;
1771
1772 switch (mapping) {
1773 case MV88E6XXX_POLICY_MAPPING_DA:
1774 case MV88E6XXX_POLICY_MAPPING_SA:
1775 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1776 state = 0; /* Dissociate the port and address */
1777 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1778 is_multicast_ether_addr(addr))
1779 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1780 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1781 is_unicast_ether_addr(addr))
1782 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1783 else
1784 return -EOPNOTSUPP;
1785
1786 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1787 state);
1788 if (err)
1789 return err;
1790 break;
1791 default:
1792 return -EOPNOTSUPP;
1793 }
1794
1795 /* Skip the port's policy clearing if the mapping is still in use */
1796 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1797 idr_for_each_entry(&chip->policies, policy, id)
1798 if (policy->port == port &&
1799 policy->mapping == mapping &&
1800 policy->action != action)
1801 return 0;
1802
1803 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1804}
1805
1806static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1807 struct ethtool_rx_flow_spec *fs)
1808{
1809 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1810 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1811 enum mv88e6xxx_policy_mapping mapping;
1812 enum mv88e6xxx_policy_action action;
1813 struct mv88e6xxx_policy *policy;
1814 u16 vid = 0;
1815 u8 *addr;
1816 int err;
1817 int id;
1818
1819 if (fs->location != RX_CLS_LOC_ANY)
1820 return -EINVAL;
1821
1822 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1823 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1824 else
1825 return -EOPNOTSUPP;
1826
1827 switch (fs->flow_type & ~FLOW_EXT) {
1828 case ETHER_FLOW:
1829 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1830 is_zero_ether_addr(mac_mask->h_source)) {
1831 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1832 addr = mac_entry->h_dest;
1833 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1834 !is_zero_ether_addr(mac_mask->h_source)) {
1835 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1836 addr = mac_entry->h_source;
1837 } else {
1838 /* Cannot support DA and SA mapping in the same rule */
1839 return -EOPNOTSUPP;
1840 }
1841 break;
1842 default:
1843 return -EOPNOTSUPP;
1844 }
1845
1846 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001847 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001848 return -EOPNOTSUPP;
1849 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1850 }
1851
1852 idr_for_each_entry(&chip->policies, policy, id) {
1853 if (policy->port == port && policy->mapping == mapping &&
1854 policy->action == action && policy->vid == vid &&
1855 ether_addr_equal(policy->addr, addr))
1856 return -EEXIST;
1857 }
1858
1859 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1860 if (!policy)
1861 return -ENOMEM;
1862
1863 fs->location = 0;
1864 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1865 GFP_KERNEL);
1866 if (err) {
1867 devm_kfree(chip->dev, policy);
1868 return err;
1869 }
1870
1871 memcpy(&policy->fs, fs, sizeof(*fs));
1872 ether_addr_copy(policy->addr, addr);
1873 policy->mapping = mapping;
1874 policy->action = action;
1875 policy->port = port;
1876 policy->vid = vid;
1877
1878 err = mv88e6xxx_policy_apply(chip, port, policy);
1879 if (err) {
1880 idr_remove(&chip->policies, fs->location);
1881 devm_kfree(chip->dev, policy);
1882 return err;
1883 }
1884
1885 return 0;
1886}
1887
1888static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1889 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1890{
1891 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1892 struct mv88e6xxx_chip *chip = ds->priv;
1893 struct mv88e6xxx_policy *policy;
1894 int err;
1895 int id;
1896
1897 mv88e6xxx_reg_lock(chip);
1898
1899 switch (rxnfc->cmd) {
1900 case ETHTOOL_GRXCLSRLCNT:
1901 rxnfc->data = 0;
1902 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1903 rxnfc->rule_cnt = 0;
1904 idr_for_each_entry(&chip->policies, policy, id)
1905 if (policy->port == port)
1906 rxnfc->rule_cnt++;
1907 err = 0;
1908 break;
1909 case ETHTOOL_GRXCLSRULE:
1910 err = -ENOENT;
1911 policy = idr_find(&chip->policies, fs->location);
1912 if (policy) {
1913 memcpy(fs, &policy->fs, sizeof(*fs));
1914 err = 0;
1915 }
1916 break;
1917 case ETHTOOL_GRXCLSRLALL:
1918 rxnfc->data = 0;
1919 rxnfc->rule_cnt = 0;
1920 idr_for_each_entry(&chip->policies, policy, id)
1921 if (policy->port == port)
1922 rule_locs[rxnfc->rule_cnt++] = id;
1923 err = 0;
1924 break;
1925 default:
1926 err = -EOPNOTSUPP;
1927 break;
1928 }
1929
1930 mv88e6xxx_reg_unlock(chip);
1931
1932 return err;
1933}
1934
1935static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1936 struct ethtool_rxnfc *rxnfc)
1937{
1938 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1939 struct mv88e6xxx_chip *chip = ds->priv;
1940 struct mv88e6xxx_policy *policy;
1941 int err;
1942
1943 mv88e6xxx_reg_lock(chip);
1944
1945 switch (rxnfc->cmd) {
1946 case ETHTOOL_SRXCLSRLINS:
1947 err = mv88e6xxx_policy_insert(chip, port, fs);
1948 break;
1949 case ETHTOOL_SRXCLSRLDEL:
1950 err = -ENOENT;
1951 policy = idr_remove(&chip->policies, fs->location);
1952 if (policy) {
1953 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
1954 err = mv88e6xxx_policy_apply(chip, port, policy);
1955 devm_kfree(chip->dev, policy);
1956 }
1957 break;
1958 default:
1959 err = -EOPNOTSUPP;
1960 break;
1961 }
1962
1963 mv88e6xxx_reg_unlock(chip);
1964
1965 return err;
1966}
1967
Andrew Lunn87fa8862017-11-09 22:29:56 +01001968static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1969 u16 vid)
1970{
Andrew Lunn87fa8862017-11-09 22:29:56 +01001971 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
Tobias Waldekranz0806dd462021-03-18 20:25:37 +01001972 u8 broadcast[ETH_ALEN];
1973
1974 eth_broadcast_addr(broadcast);
Andrew Lunn87fa8862017-11-09 22:29:56 +01001975
1976 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1977}
1978
1979static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1980{
1981 int port;
1982 int err;
1983
1984 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1985 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1986 if (err)
1987 return err;
1988 }
1989
1990 return 0;
1991}
1992
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001993static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00001994 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001995{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001996 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001997 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001998 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001999
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002000 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002001 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002002 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002003
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002004 if (!vlan.valid) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002005 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002006
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002007 err = mv88e6xxx_atu_new(chip, &vlan.fid);
2008 if (err)
2009 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01002010
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002011 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
2012 if (i == port)
2013 vlan.member[i] = member;
2014 else
2015 vlan.member[i] = non_member;
2016
2017 vlan.vid = vid;
2018 vlan.valid = true;
2019
2020 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2021 if (err)
2022 return err;
2023
2024 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
2025 if (err)
2026 return err;
2027 } else if (vlan.member[port] != member) {
2028 vlan.member[port] = member;
2029
2030 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2031 if (err)
2032 return err;
Russell King933b4422020-02-26 17:14:26 +00002033 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002034 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
2035 port, vid);
2036 }
2037
2038 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002039}
2040
Vladimir Oltean1958d582021-01-09 02:01:53 +02002041static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vladimir Oltean31046a52021-02-13 22:43:18 +02002042 const struct switchdev_obj_port_vlan *vlan,
2043 struct netlink_ext_ack *extack)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002044{
Vivien Didelot04bed142016-08-31 18:06:13 -04002045 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002046 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
2047 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Russell King933b4422020-02-26 17:14:26 +00002048 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002049 u8 member;
Vladimir Oltean1958d582021-01-09 02:01:53 +02002050 int err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002051
Vladimir Oltean1958d582021-01-09 02:01:53 +02002052 err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
2053 if (err)
2054 return err;
Vivien Didelot54d77b52016-05-09 13:22:47 -04002055
Vivien Didelotc91498e2017-06-07 18:12:13 -04002056 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002057 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002058 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002059 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002060 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002061 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002062
Russell King933b4422020-02-26 17:14:26 +00002063 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
2064 * and then the CPU port. Do not warn for duplicates for the CPU port.
2065 */
2066 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
2067
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002068 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002069
Vladimir Oltean1958d582021-01-09 02:01:53 +02002070 err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
2071 if (err) {
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002072 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2073 vlan->vid, untagged ? 'u' : 't');
Vladimir Oltean1958d582021-01-09 02:01:53 +02002074 goto out;
2075 }
Vivien Didelot76e398a2015-11-01 12:33:55 -05002076
Vladimir Oltean1958d582021-01-09 02:01:53 +02002077 if (pvid) {
2078 err = mv88e6xxx_port_set_pvid(chip, port, vlan->vid);
2079 if (err) {
2080 dev_err(ds->dev, "p%d: failed to set PVID %d\n",
2081 port, vlan->vid);
2082 goto out;
2083 }
2084 }
2085out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002086 mv88e6xxx_reg_unlock(chip);
Vladimir Oltean1958d582021-01-09 02:01:53 +02002087
2088 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002089}
2090
Vivien Didelot521098922019-08-01 14:36:36 -04002091static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2092 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002093{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002094 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002095 int i, err;
2096
Vivien Didelot521098922019-08-01 14:36:36 -04002097 if (!vid)
2098 return -EOPNOTSUPP;
2099
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002100 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002101 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002102 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002103
Vivien Didelot521098922019-08-01 14:36:36 -04002104 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2105 * tell switchdev that this VLAN is likely handled in software.
2106 */
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002107 if (!vlan.valid ||
Vivien Didelot521098922019-08-01 14:36:36 -04002108 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002109 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002110
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002111 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002112
2113 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002114 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002115 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002116 if (vlan.member[i] !=
2117 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002118 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002119 break;
2120 }
2121 }
2122
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002123 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002124 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002125 return err;
2126
Vivien Didelote606ca32017-03-11 16:12:55 -05002127 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002128}
2129
Vivien Didelotf81ec902016-05-09 13:22:58 -04002130static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2131 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002132{
Vivien Didelot04bed142016-08-31 18:06:13 -04002133 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002134 int err = 0;
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002135 u16 pvid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002136
Tobias Waldekranze545f862020-11-10 19:57:20 +01002137 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04002138 return -EOPNOTSUPP;
2139
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002140 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002141
Vivien Didelot77064f32016-11-04 03:23:30 +01002142 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002143 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002144 goto unlock;
2145
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002146 err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
2147 if (err)
2148 goto unlock;
2149
2150 if (vlan->vid == pvid) {
2151 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002152 if (err)
2153 goto unlock;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002154 }
2155
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002156unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002157 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002158
2159 return err;
2160}
2161
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002162static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2163 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002164{
Vivien Didelot04bed142016-08-31 18:06:13 -04002165 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002166 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002167
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002168 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002169 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2170 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002171 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002172
2173 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002174}
2175
Vivien Didelotf81ec902016-05-09 13:22:58 -04002176static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002177 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002178{
Vivien Didelot04bed142016-08-31 18:06:13 -04002179 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002180 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002181
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002182 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002183 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002184 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002185
Vivien Didelot83dabd12016-08-31 11:50:04 -04002186 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002187}
2188
Vivien Didelot83dabd12016-08-31 11:50:04 -04002189static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2190 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002191 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002192{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002193 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002194 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002195 int err;
2196
Vivien Didelotd8291a92019-09-07 16:00:47 -04002197 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002198 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002199
2200 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002201 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002202 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002203 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002204
Vivien Didelotd8291a92019-09-07 16:00:47 -04002205 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002206 break;
2207
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002208 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002209 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002210
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002211 if (!is_unicast_ether_addr(addr.mac))
2212 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002213
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002214 is_static = (addr.state ==
2215 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2216 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002217 if (err)
2218 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002219 } while (!is_broadcast_ether_addr(addr.mac));
2220
2221 return err;
2222}
2223
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002224struct mv88e6xxx_port_db_dump_vlan_ctx {
2225 int port;
2226 dsa_fdb_dump_cb_t *cb;
2227 void *data;
2228};
2229
2230static int mv88e6xxx_port_db_dump_vlan(struct mv88e6xxx_chip *chip,
2231 const struct mv88e6xxx_vtu_entry *entry,
2232 void *_data)
2233{
2234 struct mv88e6xxx_port_db_dump_vlan_ctx *ctx = _data;
2235
2236 return mv88e6xxx_port_db_dump_fid(chip, entry->fid, entry->vid,
2237 ctx->port, ctx->cb, ctx->data);
2238}
2239
Vivien Didelot83dabd12016-08-31 11:50:04 -04002240static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002241 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002242{
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002243 struct mv88e6xxx_port_db_dump_vlan_ctx ctx = {
2244 .port = port,
2245 .cb = cb,
2246 .data = data,
2247 };
Vivien Didelot83dabd12016-08-31 11:50:04 -04002248 u16 fid;
2249 int err;
2250
2251 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002252 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002253 if (err)
2254 return err;
2255
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002256 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002257 if (err)
2258 return err;
2259
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002260 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_db_dump_vlan, &ctx);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002261}
2262
Vivien Didelotf81ec902016-05-09 13:22:58 -04002263static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002264 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002265{
Vivien Didelot04bed142016-08-31 18:06:13 -04002266 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002267 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002268
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002269 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002270 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002271 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002272
2273 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002274}
2275
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002276static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2277 struct net_device *br)
2278{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002279 struct dsa_switch *ds = chip->ds;
2280 struct dsa_switch_tree *dst = ds->dst;
2281 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002282 int err;
2283
Vivien Didelotef2025e2019-10-21 16:51:27 -04002284 list_for_each_entry(dp, &dst->ports, list) {
2285 if (dp->bridge_dev == br) {
2286 if (dp->ds == ds) {
2287 /* This is a local bridge group member,
2288 * remap its Port VLAN Map.
2289 */
2290 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2291 if (err)
2292 return err;
2293 } else {
2294 /* This is an external bridge group member,
2295 * remap its cross-chip Port VLAN Table entry.
2296 */
2297 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2298 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002299 if (err)
2300 return err;
2301 }
2302 }
2303 }
2304
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002305 return 0;
2306}
2307
Vivien Didelotf81ec902016-05-09 13:22:58 -04002308static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002309 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002310{
Vivien Didelot04bed142016-08-31 18:06:13 -04002311 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002312 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002313
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002314 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002315 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002316 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002317
Vivien Didelot466dfa02016-02-26 13:16:05 -05002318 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002319}
2320
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002321static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2322 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002323{
Vivien Didelot04bed142016-08-31 18:06:13 -04002324 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002325
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002326 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002327 if (mv88e6xxx_bridge_map(chip, br) ||
2328 mv88e6xxx_port_vlan_map(chip, port))
2329 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002330 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002331}
2332
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002333static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2334 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002335 int port, struct net_device *br)
2336{
2337 struct mv88e6xxx_chip *chip = ds->priv;
2338 int err;
2339
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002340 if (tree_index != ds->dst->index)
2341 return 0;
2342
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002343 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002344 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002345 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002346
2347 return err;
2348}
2349
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002350static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2351 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002352 int port, struct net_device *br)
2353{
2354 struct mv88e6xxx_chip *chip = ds->priv;
2355
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002356 if (tree_index != ds->dst->index)
2357 return;
2358
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002359 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002360 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002361 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002362 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002363}
2364
Vivien Didelot17e708b2016-12-05 17:30:27 -05002365static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2366{
2367 if (chip->info->ops->reset)
2368 return chip->info->ops->reset(chip);
2369
2370 return 0;
2371}
2372
Vivien Didelot309eca62016-12-05 17:30:26 -05002373static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2374{
2375 struct gpio_desc *gpiod = chip->reset;
2376
2377 /* If there is a GPIO connected to the reset pin, toggle it */
2378 if (gpiod) {
2379 gpiod_set_value_cansleep(gpiod, 1);
2380 usleep_range(10000, 20000);
2381 gpiod_set_value_cansleep(gpiod, 0);
2382 usleep_range(10000, 20000);
Andrew Lunna3dcb3e2020-11-16 08:43:01 -08002383
2384 mv88e6xxx_g1_wait_eeprom_done(chip);
Vivien Didelot309eca62016-12-05 17:30:26 -05002385 }
2386}
2387
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002388static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2389{
2390 int i, err;
2391
2392 /* Set all ports to the Disabled state */
2393 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002394 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002395 if (err)
2396 return err;
2397 }
2398
2399 /* Wait for transmit queues to drain,
2400 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2401 */
2402 usleep_range(2000, 4000);
2403
2404 return 0;
2405}
2406
Vivien Didelotfad09c72016-06-21 12:28:20 -04002407static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002408{
Vivien Didelota935c052016-09-29 12:21:53 -04002409 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002410
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002411 err = mv88e6xxx_disable_ports(chip);
2412 if (err)
2413 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002414
Vivien Didelot309eca62016-12-05 17:30:26 -05002415 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002416
Vivien Didelot17e708b2016-12-05 17:30:27 -05002417 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002418}
2419
Vivien Didelot43145572017-03-11 16:12:59 -05002420static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002421 enum mv88e6xxx_frame_mode frame,
2422 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002423{
2424 int err;
2425
Vivien Didelot43145572017-03-11 16:12:59 -05002426 if (!chip->info->ops->port_set_frame_mode)
2427 return -EOPNOTSUPP;
2428
2429 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002430 if (err)
2431 return err;
2432
Vivien Didelot43145572017-03-11 16:12:59 -05002433 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2434 if (err)
2435 return err;
2436
2437 if (chip->info->ops->port_set_ether_type)
2438 return chip->info->ops->port_set_ether_type(chip, port, etype);
2439
2440 return 0;
2441}
2442
2443static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2444{
2445 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002446 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002447 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002448}
2449
2450static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2451{
2452 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002453 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002454 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002455}
2456
2457static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2458{
2459 return mv88e6xxx_set_port_mode(chip, port,
2460 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002461 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2462 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002463}
2464
2465static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2466{
2467 if (dsa_is_dsa_port(chip->ds, port))
2468 return mv88e6xxx_set_port_mode_dsa(chip, port);
2469
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002470 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002471 return mv88e6xxx_set_port_mode_normal(chip, port);
2472
2473 /* Setup CPU port mode depending on its supported tag format */
2474 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2475 return mv88e6xxx_set_port_mode_dsa(chip, port);
2476
2477 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2478 return mv88e6xxx_set_port_mode_edsa(chip, port);
2479
2480 return -EINVAL;
2481}
2482
Vivien Didelotea698f42017-03-11 16:12:50 -05002483static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2484{
2485 bool message = dsa_is_dsa_port(chip->ds, port);
2486
2487 return mv88e6xxx_port_set_message_port(chip, port, message);
2488}
2489
Vivien Didelot601aeed2017-03-11 16:13:00 -05002490static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2491{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002492 struct dsa_switch *ds = chip->ds;
David S. Miller407308f2019-06-15 13:35:29 -07002493 bool flood;
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002494 int err;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002495
David S. Miller407308f2019-06-15 13:35:29 -07002496 /* Upstream ports flood frames with unknown unicast or multicast DA */
2497 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002498 if (chip->info->ops->port_set_ucast_flood) {
2499 err = chip->info->ops->port_set_ucast_flood(chip, port, flood);
2500 if (err)
2501 return err;
2502 }
2503 if (chip->info->ops->port_set_mcast_flood) {
2504 err = chip->info->ops->port_set_mcast_flood(chip, port, flood);
2505 if (err)
2506 return err;
2507 }
Vivien Didelot601aeed2017-03-11 16:13:00 -05002508
David S. Miller407308f2019-06-15 13:35:29 -07002509 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002510}
2511
Vivien Didelot45de77f2019-08-31 16:18:36 -04002512static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2513{
2514 struct mv88e6xxx_port *mvp = dev_id;
2515 struct mv88e6xxx_chip *chip = mvp->chip;
2516 irqreturn_t ret = IRQ_NONE;
2517 int port = mvp->port;
Pavana Sharma193c5b22021-03-17 14:46:40 +01002518 int lane;
Vivien Didelot45de77f2019-08-31 16:18:36 -04002519
2520 mv88e6xxx_reg_lock(chip);
2521 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002522 if (lane >= 0)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002523 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2524 mv88e6xxx_reg_unlock(chip);
2525
2526 return ret;
2527}
2528
2529static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002530 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002531{
2532 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2533 unsigned int irq;
2534 int err;
2535
2536 /* Nothing to request if this SERDES port has no IRQ */
2537 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2538 if (!irq)
2539 return 0;
2540
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002541 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2542 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2543
Vivien Didelot45de77f2019-08-31 16:18:36 -04002544 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2545 mv88e6xxx_reg_unlock(chip);
2546 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002547 IRQF_ONESHOT, dev_id->serdes_irq_name,
2548 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002549 mv88e6xxx_reg_lock(chip);
2550 if (err)
2551 return err;
2552
2553 dev_id->serdes_irq = irq;
2554
2555 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2556}
2557
2558static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002559 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002560{
2561 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2562 unsigned int irq = dev_id->serdes_irq;
2563 int err;
2564
2565 /* Nothing to free if no IRQ has been requested */
2566 if (!irq)
2567 return 0;
2568
2569 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2570
2571 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2572 mv88e6xxx_reg_unlock(chip);
2573 free_irq(irq, dev_id);
2574 mv88e6xxx_reg_lock(chip);
2575
2576 dev_id->serdes_irq = 0;
2577
2578 return err;
2579}
2580
Andrew Lunn6d917822017-05-26 01:03:21 +02002581static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2582 bool on)
2583{
Pavana Sharma193c5b22021-03-17 14:46:40 +01002584 int lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002585 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002586
Vivien Didelotdc272f62019-08-31 16:18:33 -04002587 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002588 if (lane < 0)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002589 return 0;
2590
2591 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002592 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002593 if (err)
2594 return err;
2595
Vivien Didelot45de77f2019-08-31 16:18:36 -04002596 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002597 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002598 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2599 if (err)
2600 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002601
Vivien Didelotdc272f62019-08-31 16:18:33 -04002602 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002603 }
2604
2605 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002606}
2607
Marek Behún2fda45f2021-03-17 14:46:41 +01002608static int mv88e6xxx_set_egress_port(struct mv88e6xxx_chip *chip,
2609 enum mv88e6xxx_egress_direction direction,
2610 int port)
2611{
2612 int err;
2613
2614 if (!chip->info->ops->set_egress_port)
2615 return -EOPNOTSUPP;
2616
2617 err = chip->info->ops->set_egress_port(chip, direction, port);
2618 if (err)
2619 return err;
2620
2621 if (direction == MV88E6XXX_EGRESS_DIR_INGRESS)
2622 chip->ingress_dest_port = port;
2623 else
2624 chip->egress_dest_port = port;
2625
2626 return 0;
2627}
2628
Vivien Didelotfa371c82017-12-05 15:34:10 -05002629static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2630{
2631 struct dsa_switch *ds = chip->ds;
2632 int upstream_port;
2633 int err;
2634
Vivien Didelot07073c72017-12-05 15:34:13 -05002635 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002636 if (chip->info->ops->port_set_upstream_port) {
2637 err = chip->info->ops->port_set_upstream_port(chip, port,
2638 upstream_port);
2639 if (err)
2640 return err;
2641 }
2642
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002643 if (port == upstream_port) {
2644 if (chip->info->ops->set_cpu_port) {
2645 err = chip->info->ops->set_cpu_port(chip,
2646 upstream_port);
2647 if (err)
2648 return err;
2649 }
2650
Marek Behún2fda45f2021-03-17 14:46:41 +01002651 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002652 MV88E6XXX_EGRESS_DIR_INGRESS,
2653 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002654 if (err && err != -EOPNOTSUPP)
2655 return err;
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002656
Marek Behún2fda45f2021-03-17 14:46:41 +01002657 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002658 MV88E6XXX_EGRESS_DIR_EGRESS,
2659 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002660 if (err && err != -EOPNOTSUPP)
2661 return err;
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002662 }
2663
Vivien Didelotfa371c82017-12-05 15:34:10 -05002664 return 0;
2665}
2666
Vivien Didelotfad09c72016-06-21 12:28:20 -04002667static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002668{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002669 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002670 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002671 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002672
Andrew Lunn7b898462018-08-09 15:38:47 +02002673 chip->ports[port].chip = chip;
2674 chip->ports[port].port = port;
2675
Vivien Didelotd78343d2016-11-04 03:23:36 +01002676 /* MAC Forcing register: don't force link, speed, duplex or flow control
2677 * state to any particular values on physical ports, but force the CPU
2678 * port and all DSA ports to their maximum bandwidth and full duplex.
2679 */
2680 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2681 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2682 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002683 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002684 PHY_INTERFACE_MODE_NA);
2685 else
2686 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2687 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002688 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002689 PHY_INTERFACE_MODE_NA);
2690 if (err)
2691 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002692
2693 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2694 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2695 * tunneling, determine priority by looking at 802.1p and IP
2696 * priority fields (IP prio has precedence), and set STP state
2697 * to Forwarding.
2698 *
2699 * If this is the CPU link, use DSA or EDSA tagging depending
2700 * on which tagging mode was configured.
2701 *
2702 * If this is a link to another switch, use DSA tagging mode.
2703 *
2704 * If this is the upstream port for this switch, enable
2705 * forwarding of unknown unicasts and multicasts.
2706 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002707 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2708 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2709 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2710 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002711 if (err)
2712 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002713
Vivien Didelot601aeed2017-03-11 16:13:00 -05002714 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002715 if (err)
2716 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002717
Vivien Didelot601aeed2017-03-11 16:13:00 -05002718 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002719 if (err)
2720 return err;
2721
Vivien Didelot8efdda42015-08-13 12:52:23 -04002722 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002723 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002724 * untagged frames on this port, do a destination address lookup on all
2725 * received packets as usual, disable ARP mirroring and don't send a
2726 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002727 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002728 err = mv88e6xxx_port_set_map_da(chip, port);
2729 if (err)
2730 return err;
2731
Vivien Didelotfa371c82017-12-05 15:34:10 -05002732 err = mv88e6xxx_setup_upstream_port(chip, port);
2733 if (err)
2734 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002735
Andrew Lunna23b2962017-02-04 20:15:28 +01002736 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002737 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002738 if (err)
2739 return err;
2740
Vivien Didelotcd782652017-06-08 18:34:13 -04002741 if (chip->info->ops->port_set_jumbo_size) {
2742 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002743 if (err)
2744 return err;
2745 }
2746
Andrew Lunn54d792f2015-05-06 01:09:47 +02002747 /* Port Association Vector: when learning source addresses
2748 * of packets, add the address to the address database using
2749 * a port bitmap that has only the bit for this port set and
2750 * the other bits clear.
2751 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002752 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002753 /* Disable learning for CPU port */
2754 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002755 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002756
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002757 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2758 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002759 if (err)
2760 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002761
2762 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002763 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2764 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002765 if (err)
2766 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002767
Vivien Didelot08984322017-06-08 18:34:12 -04002768 if (chip->info->ops->port_pause_limit) {
2769 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002770 if (err)
2771 return err;
2772 }
2773
Vivien Didelotc8c94892017-03-11 16:13:01 -05002774 if (chip->info->ops->port_disable_learn_limit) {
2775 err = chip->info->ops->port_disable_learn_limit(chip, port);
2776 if (err)
2777 return err;
2778 }
2779
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002780 if (chip->info->ops->port_disable_pri_override) {
2781 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002782 if (err)
2783 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002784 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002785
Andrew Lunnef0a7312016-12-03 04:35:16 +01002786 if (chip->info->ops->port_tag_remap) {
2787 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002788 if (err)
2789 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002790 }
2791
Andrew Lunnef70b112016-12-03 04:45:18 +01002792 if (chip->info->ops->port_egress_rate_limiting) {
2793 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002794 if (err)
2795 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002796 }
2797
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002798 if (chip->info->ops->port_setup_message_port) {
2799 err = chip->info->ops->port_setup_message_port(chip, port);
2800 if (err)
2801 return err;
2802 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002803
Vivien Didelot207afda2016-04-14 14:42:09 -04002804 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002805 * database, and allow bidirectional communication between the
2806 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002807 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002808 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002809 if (err)
2810 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002811
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002812 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002813 if (err)
2814 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002815
2816 /* Default VLAN ID and priority: don't set a default VLAN
2817 * ID, and set the default packet priority to zero.
2818 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002819 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002820}
2821
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002822static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
2823{
2824 struct mv88e6xxx_chip *chip = ds->priv;
2825
2826 if (chip->info->ops->port_set_jumbo_size)
2827 return 10240;
Chris Packham1baf0fa2020-07-24 11:21:22 +12002828 else if (chip->info->ops->set_max_frame_size)
2829 return 1632;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002830 return 1522;
2831}
2832
2833static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
2834{
2835 struct mv88e6xxx_chip *chip = ds->priv;
2836 int ret = 0;
2837
2838 mv88e6xxx_reg_lock(chip);
2839 if (chip->info->ops->port_set_jumbo_size)
2840 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12002841 else if (chip->info->ops->set_max_frame_size)
2842 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002843 else
2844 if (new_mtu > 1522)
2845 ret = -EINVAL;
2846 mv88e6xxx_reg_unlock(chip);
2847
2848 return ret;
2849}
2850
Andrew Lunn04aca992017-05-26 01:03:24 +02002851static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2852 struct phy_device *phydev)
2853{
2854 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002855 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002856
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002857 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002858 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002859 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002860
2861 return err;
2862}
2863
Andrew Lunn75104db2019-02-24 20:44:43 +01002864static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02002865{
2866 struct mv88e6xxx_chip *chip = ds->priv;
2867
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002868 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002869 if (mv88e6xxx_serdes_power(chip, port, false))
2870 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002871 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002872}
2873
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002874static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2875 unsigned int ageing_time)
2876{
Vivien Didelot04bed142016-08-31 18:06:13 -04002877 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002878 int err;
2879
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002880 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05002881 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002882 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002883
2884 return err;
2885}
2886
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002887static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002888{
2889 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002890
Andrew Lunnde2273872016-11-21 23:27:01 +01002891 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002892 if (chip->info->ops->stats_set_histogram) {
2893 err = chip->info->ops->stats_set_histogram(chip);
2894 if (err)
2895 return err;
2896 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002897
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002898 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002899}
2900
Andrew Lunnea890982019-01-09 00:24:03 +01002901/* Check if the errata has already been applied. */
2902static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
2903{
2904 int port;
2905 int err;
2906 u16 val;
2907
2908 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002909 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01002910 if (err) {
2911 dev_err(chip->dev,
2912 "Error reading hidden register: %d\n", err);
2913 return false;
2914 }
2915 if (val != 0x01c0)
2916 return false;
2917 }
2918
2919 return true;
2920}
2921
2922/* The 6390 copper ports have an errata which require poking magic
2923 * values into undocumented hidden registers and then performing a
2924 * software reset.
2925 */
2926static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
2927{
2928 int port;
2929 int err;
2930
2931 if (mv88e6390_setup_errata_applied(chip))
2932 return 0;
2933
2934 /* Set the ports into blocking mode */
2935 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2936 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
2937 if (err)
2938 return err;
2939 }
2940
2941 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002942 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01002943 if (err)
2944 return err;
2945 }
2946
2947 return mv88e6xxx_software_reset(chip);
2948}
2949
Andrew Lunn23e8b472019-10-25 01:03:52 +02002950static void mv88e6xxx_teardown(struct dsa_switch *ds)
2951{
2952 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002953 dsa_devlink_resources_unregister(ds);
Andrew Lunnbfb25542020-09-18 21:11:07 +02002954 mv88e6xxx_teardown_devlink_regions(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02002955}
2956
Vivien Didelotf81ec902016-05-09 13:22:58 -04002957static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002958{
Vivien Didelot04bed142016-08-31 18:06:13 -04002959 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002960 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04002961 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002962 int i;
2963
Vivien Didelotfad09c72016-06-21 12:28:20 -04002964 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002965 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002966
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002967 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002968
Andrew Lunnea890982019-01-09 00:24:03 +01002969 if (chip->info->ops->setup_errata) {
2970 err = chip->info->ops->setup_errata(chip);
2971 if (err)
2972 goto unlock;
2973 }
2974
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002975 /* Cache the cmode of each port. */
2976 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2977 if (chip->info->ops->port_get_cmode) {
2978 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
2979 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03002980 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002981
2982 chip->ports[i].cmode = cmode;
2983 }
2984 }
2985
Vivien Didelot97299342016-07-18 20:45:30 -04002986 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002987 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04002988 if (dsa_is_unused_port(ds, i))
2989 continue;
2990
Hubert Feursteinc8574862019-07-31 10:23:48 +02002991 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04002992 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02002993 dev_err(chip->dev, "port %d is invalid\n", i);
2994 err = -EINVAL;
2995 goto unlock;
2996 }
2997
Vivien Didelot97299342016-07-18 20:45:30 -04002998 err = mv88e6xxx_setup_port(chip, i);
2999 if (err)
3000 goto unlock;
3001 }
3002
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003003 err = mv88e6xxx_irl_setup(chip);
3004 if (err)
3005 goto unlock;
3006
Vivien Didelot04a69a12017-10-13 14:18:05 -04003007 err = mv88e6xxx_mac_setup(chip);
3008 if (err)
3009 goto unlock;
3010
Vivien Didelot1b17aed2017-05-26 18:03:05 -04003011 err = mv88e6xxx_phy_setup(chip);
3012 if (err)
3013 goto unlock;
3014
Vivien Didelotb486d7c2017-05-01 14:05:13 -04003015 err = mv88e6xxx_vtu_setup(chip);
3016 if (err)
3017 goto unlock;
3018
Vivien Didelot81228992017-03-30 17:37:08 -04003019 err = mv88e6xxx_pvt_setup(chip);
3020 if (err)
3021 goto unlock;
3022
Vivien Didelota2ac29d2017-03-11 16:12:49 -05003023 err = mv88e6xxx_atu_setup(chip);
3024 if (err)
3025 goto unlock;
3026
Andrew Lunn87fa8862017-11-09 22:29:56 +01003027 err = mv88e6xxx_broadcast_setup(chip, 0);
3028 if (err)
3029 goto unlock;
3030
Vivien Didelot9e907d72017-07-17 13:03:43 -04003031 err = mv88e6xxx_pot_setup(chip);
3032 if (err)
3033 goto unlock;
3034
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003035 err = mv88e6xxx_rmu_setup(chip);
3036 if (err)
3037 goto unlock;
3038
Vivien Didelot51c901a2017-07-17 13:03:41 -04003039 err = mv88e6xxx_rsvd2cpu_setup(chip);
3040 if (err)
3041 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01003042
Vivien Didelotb28f8722018-04-26 21:56:44 -04003043 err = mv88e6xxx_trunk_setup(chip);
3044 if (err)
3045 goto unlock;
3046
Vivien Didelotc7f047b2018-04-26 21:56:45 -04003047 err = mv88e6xxx_devmap_setup(chip);
3048 if (err)
3049 goto unlock;
3050
Vivien Didelot93e18d62018-05-11 17:16:35 -04003051 err = mv88e6xxx_pri_setup(chip);
3052 if (err)
3053 goto unlock;
3054
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003055 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003056 if (chip->info->ptp_support) {
3057 err = mv88e6xxx_ptp_setup(chip);
3058 if (err)
3059 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003060
3061 err = mv88e6xxx_hwtstamp_setup(chip);
3062 if (err)
3063 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003064 }
3065
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003066 err = mv88e6xxx_stats_setup(chip);
3067 if (err)
3068 goto unlock;
3069
Vivien Didelot6b17e862015-08-13 12:52:18 -04003070unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003071 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02003072
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003073 if (err)
3074 return err;
3075
3076 /* Have to be called without holding the register lock, since
3077 * they take the devlink lock, and we later take the locks in
3078 * the reverse order when getting/setting parameters or
3079 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02003080 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003081 err = mv88e6xxx_setup_devlink_resources(ds);
3082 if (err)
3083 return err;
3084
3085 err = mv88e6xxx_setup_devlink_params(ds);
3086 if (err)
Andrew Lunnbfb25542020-09-18 21:11:07 +02003087 goto out_resources;
3088
3089 err = mv88e6xxx_setup_devlink_regions(ds);
3090 if (err)
3091 goto out_params;
3092
3093 return 0;
3094
3095out_params:
3096 mv88e6xxx_teardown_devlink_params(ds);
3097out_resources:
3098 dsa_devlink_resources_unregister(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003099
3100 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003101}
3102
Vivien Didelote57e5e72016-08-15 17:19:00 -04003103static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003104{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003105 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3106 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003107 u16 val;
3108 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003109
Andrew Lunnee26a222017-01-24 14:53:48 +01003110 if (!chip->info->ops->phy_read)
3111 return -EOPNOTSUPP;
3112
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003113 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003114 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003115 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003116
Andrew Lunnda9f3302017-02-01 03:40:05 +01003117 if (reg == MII_PHYSID2) {
Andrew Lunnddc49ac2018-11-12 18:51:01 +01003118 /* Some internal PHYs don't have a model number. */
3119 if (chip->info->family != MV88E6XXX_FAMILY_6165)
3120 /* Then there is the 6165 family. It gets is
3121 * PHYs correct. But it can also have two
3122 * SERDES interfaces in the PHY address
3123 * space. And these don't have a model
3124 * number. But they are not PHYs, so we don't
3125 * want to give them something a PHY driver
3126 * will recognise.
3127 *
3128 * Use the mv88e6390 family model number
3129 * instead, for anything which really could be
3130 * a PHY,
3131 */
3132 if (!(val & 0x3f0))
3133 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003134 }
3135
Vivien Didelote57e5e72016-08-15 17:19:00 -04003136 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003137}
3138
Vivien Didelote57e5e72016-08-15 17:19:00 -04003139static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003140{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003141 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3142 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003143 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003144
Andrew Lunnee26a222017-01-24 14:53:48 +01003145 if (!chip->info->ops->phy_write)
3146 return -EOPNOTSUPP;
3147
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003148 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003149 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003150 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003151
3152 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003153}
3154
Vivien Didelotfad09c72016-06-21 12:28:20 -04003155static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003156 struct device_node *np,
3157 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003158{
3159 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003160 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003161 struct mii_bus *bus;
3162 int err;
3163
Andrew Lunn2510bab2018-02-22 01:51:49 +01003164 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003165 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003166 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003167 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003168
3169 if (err)
3170 return err;
3171 }
3172
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003173 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003174 if (!bus)
3175 return -ENOMEM;
3176
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003177 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003178 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003179 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003180 INIT_LIST_HEAD(&mdio_bus->list);
3181 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003182
Andrew Lunnb516d452016-06-04 21:17:06 +02003183 if (np) {
3184 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003185 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003186 } else {
3187 bus->name = "mv88e6xxx SMI";
3188 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3189 }
3190
3191 bus->read = mv88e6xxx_mdio_read;
3192 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003193 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003194
Andrew Lunn6f882842018-03-17 20:32:05 +01003195 if (!external) {
3196 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3197 if (err)
3198 return err;
3199 }
3200
Florian Fainelli00e798c2018-05-15 16:56:19 -07003201 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003202 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003203 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003204 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003205 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003206 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003207
3208 if (external)
3209 list_add_tail(&mdio_bus->list, &chip->mdios);
3210 else
3211 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003212
3213 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003214}
3215
Andrew Lunn3126aee2017-12-07 01:05:57 +01003216static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3217
3218{
3219 struct mv88e6xxx_mdio_bus *mdio_bus;
3220 struct mii_bus *bus;
3221
3222 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3223 bus = mdio_bus->bus;
3224
Andrew Lunn6f882842018-03-17 20:32:05 +01003225 if (!mdio_bus->external)
3226 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3227
Andrew Lunn3126aee2017-12-07 01:05:57 +01003228 mdiobus_unregister(bus);
3229 }
3230}
3231
Andrew Lunna3c53be52017-01-24 14:53:50 +01003232static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3233 struct device_node *np)
3234{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003235 struct device_node *child;
3236 int err;
3237
3238 /* Always register one mdio bus for the internal/default mdio
3239 * bus. This maybe represented in the device tree, but is
3240 * optional.
3241 */
3242 child = of_get_child_by_name(np, "mdio");
3243 err = mv88e6xxx_mdio_register(chip, child, false);
3244 if (err)
3245 return err;
3246
3247 /* Walk the device tree, and see if there are any other nodes
3248 * which say they are compatible with the external mdio
3249 * bus.
3250 */
3251 for_each_available_child_of_node(np, child) {
Andrew Lunnceb96fa2020-09-01 04:32:57 +02003252 if (of_device_is_compatible(
3253 child, "marvell,mv88e6xxx-mdio-external")) {
Andrew Lunna3c53be52017-01-24 14:53:50 +01003254 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003255 if (err) {
3256 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303257 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003258 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003259 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003260 }
3261 }
3262
3263 return 0;
3264}
3265
Vivien Didelot855b1932016-07-20 18:18:35 -04003266static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3267{
Vivien Didelot04bed142016-08-31 18:06:13 -04003268 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003269
3270 return chip->eeprom_len;
3271}
3272
Vivien Didelot855b1932016-07-20 18:18:35 -04003273static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3274 struct ethtool_eeprom *eeprom, u8 *data)
3275{
Vivien Didelot04bed142016-08-31 18:06:13 -04003276 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003277 int err;
3278
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003279 if (!chip->info->ops->get_eeprom)
3280 return -EOPNOTSUPP;
3281
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003282 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003283 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003284 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003285
3286 if (err)
3287 return err;
3288
3289 eeprom->magic = 0xc3ec4951;
3290
3291 return 0;
3292}
3293
Vivien Didelot855b1932016-07-20 18:18:35 -04003294static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3295 struct ethtool_eeprom *eeprom, u8 *data)
3296{
Vivien Didelot04bed142016-08-31 18:06:13 -04003297 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003298 int err;
3299
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003300 if (!chip->info->ops->set_eeprom)
3301 return -EOPNOTSUPP;
3302
Vivien Didelot855b1932016-07-20 18:18:35 -04003303 if (eeprom->magic != 0xc3ec4951)
3304 return -EINVAL;
3305
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003306 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003307 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003308 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003309
3310 return err;
3311}
3312
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003313static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003314 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003315 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3316 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003317 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003318 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003319 .phy_read = mv88e6185_phy_ppu_read,
3320 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003321 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003322 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003323 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003324 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003325 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003326 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3327 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003328 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003329 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003330 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003331 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003332 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003333 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003334 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003335 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003336 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003337 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3338 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003339 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003340 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3341 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003342 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003343 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003344 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003345 .ppu_enable = mv88e6185_g1_ppu_enable,
3346 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003347 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003348 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003349 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003350 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003351 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003352 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003353};
3354
3355static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003356 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003357 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3358 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003359 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003360 .phy_read = mv88e6185_phy_ppu_read,
3361 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003362 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003363 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003364 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003365 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003366 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3367 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunna23b2962017-02-04 20:15:28 +01003368 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003369 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003370 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003371 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003372 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003373 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3374 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003375 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003376 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003377 .serdes_power = mv88e6185_serdes_power,
3378 .serdes_get_lane = mv88e6185_serdes_get_lane,
3379 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003380 .ppu_enable = mv88e6185_g1_ppu_enable,
3381 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003382 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003383 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003384 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003385 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003386 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003387};
3388
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003389static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003390 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003391 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3392 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003393 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003394 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3395 .phy_read = mv88e6xxx_g2_smi_phy_read,
3396 .phy_write = mv88e6xxx_g2_smi_phy_write,
3397 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003398 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003399 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003400 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003401 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003402 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3403 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003404 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003405 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003406 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003407 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003408 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003409 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003410 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003411 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003412 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003413 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3414 .stats_get_strings = mv88e6095_stats_get_strings,
3415 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003416 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3417 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003418 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003419 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003420 .serdes_power = mv88e6185_serdes_power,
3421 .serdes_get_lane = mv88e6185_serdes_get_lane,
3422 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Chris Packham5c19bc82020-11-24 17:34:39 +13003423 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3424 .serdes_irq_enable = mv88e6097_serdes_irq_enable,
3425 .serdes_irq_status = mv88e6097_serdes_irq_status,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003426 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003427 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003428 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003429 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003430 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003431 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003432 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003433};
3434
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003435static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003436 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003437 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3438 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003439 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003440 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003441 .phy_read = mv88e6xxx_g2_smi_phy_read,
3442 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003443 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003444 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003445 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003446 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003447 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3448 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003449 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003450 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003451 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003452 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003453 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003454 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003455 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3456 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003457 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003458 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3459 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003460 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003461 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003462 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003463 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003464 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3465 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003466 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003467 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003468 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003469 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003470};
3471
3472static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003473 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003474 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3475 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003476 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003477 .phy_read = mv88e6185_phy_ppu_read,
3478 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003479 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003480 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003481 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003482 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003483 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003484 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3485 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003486 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003487 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003488 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003489 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003490 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003491 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003492 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003493 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003494 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003495 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003496 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3497 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003498 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003499 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3500 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003501 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003502 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003503 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003504 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003505 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003506 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003507 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003508 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003509 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003510};
3511
Vivien Didelot990e27b2017-03-28 13:50:32 -04003512static const struct mv88e6xxx_ops mv88e6141_ops = {
3513 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003514 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3515 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003516 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003517 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3518 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3519 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3520 .phy_read = mv88e6xxx_g2_smi_phy_read,
3521 .phy_write = mv88e6xxx_g2_smi_phy_write,
3522 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003523 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003524 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003525 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003526 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003527 .port_tag_remap = mv88e6095_port_tag_remap,
3528 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003529 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3530 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003531 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003532 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003533 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003534 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003535 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3536 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003537 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003538 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003539 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003540 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003541 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003542 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3543 .stats_get_strings = mv88e6320_stats_get_strings,
3544 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003545 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3546 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003547 .watchdog_ops = &mv88e6390_watchdog_ops,
3548 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003549 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003550 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003551 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003552 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003553 .serdes_power = mv88e6390_serdes_power,
3554 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003555 /* Check status register pause & lpa register */
3556 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3557 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3558 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3559 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003560 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003561 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003562 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003563 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003564 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003565};
3566
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003567static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003568 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003569 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3570 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003571 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003572 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003573 .phy_read = mv88e6xxx_g2_smi_phy_read,
3574 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003575 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003576 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003577 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003578 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003579 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003580 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3581 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003582 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003583 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003584 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003585 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003586 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003587 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003588 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003589 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003590 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003591 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003592 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3593 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003594 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003595 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3596 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003597 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003598 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003599 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003600 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003601 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3602 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003603 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003604 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003605 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003606 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003607 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003608};
3609
3610static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003611 /* MV88E6XXX_FAMILY_6165 */
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,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003615 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003616 .phy_read = mv88e6165_phy_read,
3617 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003618 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003619 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003620 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003621 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003622 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003623 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003624 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003625 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003626 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003627 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3628 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003629 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003630 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3631 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003632 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003633 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003634 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003635 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003636 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3637 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003638 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003639 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003640 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003641 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003642 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003643};
3644
3645static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003646 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003647 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3648 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003649 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003650 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003651 .phy_read = mv88e6xxx_g2_smi_phy_read,
3652 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003653 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003654 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003655 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003656 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003657 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003658 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003659 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3660 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003661 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003662 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003663 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003664 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003665 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003666 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003667 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003668 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003669 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003670 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003671 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3672 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003673 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003674 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3675 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003676 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003677 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003678 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003679 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003680 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3681 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003682 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003683 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003684 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003685};
3686
3687static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003688 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003689 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3690 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003691 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003692 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3693 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003694 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003695 .phy_read = mv88e6xxx_g2_smi_phy_read,
3696 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003697 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003698 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003699 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003700 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003701 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003702 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003703 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003704 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3705 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003706 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003707 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003708 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003709 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003710 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003711 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003712 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003713 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003714 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003715 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003716 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3717 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003718 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003719 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3720 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003721 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003722 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003723 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003724 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003725 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003726 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3727 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003728 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003729 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003730 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003731 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3732 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3733 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3734 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003735 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003736 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3737 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003738 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003739 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003740};
3741
3742static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003743 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003744 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3745 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003746 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003747 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003748 .phy_read = mv88e6xxx_g2_smi_phy_read,
3749 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003750 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003751 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003752 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003753 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003754 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003755 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003756 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3757 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003758 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003759 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003760 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003761 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003762 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003763 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003764 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003765 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003766 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003767 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003768 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3769 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003770 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003771 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3772 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003773 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003774 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003775 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003776 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003777 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3778 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003779 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003780 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003781 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003782};
3783
3784static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003785 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003786 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3787 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003788 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003789 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3790 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003791 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003792 .phy_read = mv88e6xxx_g2_smi_phy_read,
3793 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003794 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003795 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003796 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003797 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003798 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003799 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003800 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003801 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3802 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003803 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003804 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003805 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003806 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003807 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003808 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003809 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003810 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003811 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003812 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003813 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3814 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003815 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003816 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3817 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003818 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003819 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003820 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003821 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003822 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003823 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3824 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003825 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003826 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003827 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003828 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3829 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3830 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3831 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003832 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003833 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003834 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003835 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003836 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3837 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003838 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003839 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003840};
3841
3842static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003843 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003844 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3845 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003846 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003847 .phy_read = mv88e6185_phy_ppu_read,
3848 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003849 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003850 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003851 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003852 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003853 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3854 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunnef70b112016-12-03 04:45:18 +01003855 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003856 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02003857 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003858 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003859 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003860 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003861 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003862 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3863 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003864 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003865 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3866 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003867 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003868 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003869 .serdes_power = mv88e6185_serdes_power,
3870 .serdes_get_lane = mv88e6185_serdes_get_lane,
3871 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelot02317e62018-05-09 11:38:49 -04003872 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003873 .ppu_enable = mv88e6185_g1_ppu_enable,
3874 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003875 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003876 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003877 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003878 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003879 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003880};
3881
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003882static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003883 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003884 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003885 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003886 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3887 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003888 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3889 .phy_read = mv88e6xxx_g2_smi_phy_read,
3890 .phy_write = mv88e6xxx_g2_smi_phy_write,
3891 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003892 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003893 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003894 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003895 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003896 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003897 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003898 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003899 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3900 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003901 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003902 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003903 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003904 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003905 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003906 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003907 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003908 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003909 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003910 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003911 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3912 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003913 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003914 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3915 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003916 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003917 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003918 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003919 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003920 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003921 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3922 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003923 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3924 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003925 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003926 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003927 /* Check status register pause & lpa register */
3928 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3929 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3930 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3931 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003932 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003933 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003934 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003935 .serdes_get_strings = mv88e6390_serdes_get_strings,
3936 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003937 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3938 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003939 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003940 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003941};
3942
3943static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003944 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003945 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003946 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003947 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3948 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003949 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3950 .phy_read = mv88e6xxx_g2_smi_phy_read,
3951 .phy_write = mv88e6xxx_g2_smi_phy_write,
3952 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003953 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003954 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003955 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003956 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003957 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003958 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003959 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003960 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3961 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003962 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003963 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003964 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003965 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003966 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003967 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003968 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003969 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003970 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003971 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003972 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3973 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003974 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003975 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3976 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003977 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003978 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003979 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003980 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003981 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003982 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3983 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003984 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3985 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003986 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003987 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003988 /* Check status register pause & lpa register */
3989 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3990 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3991 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3992 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003993 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003994 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003995 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003996 .serdes_get_strings = mv88e6390_serdes_get_strings,
3997 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003998 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3999 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004000 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004001 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004002};
4003
4004static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004005 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004006 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004007 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004008 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4009 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004010 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4011 .phy_read = mv88e6xxx_g2_smi_phy_read,
4012 .phy_write = mv88e6xxx_g2_smi_phy_write,
4013 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004014 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004015 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004016 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004017 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004018 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004019 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004020 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4021 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004022 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004023 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004024 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004025 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004026 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004027 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004028 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004029 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004030 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004031 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4032 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004033 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004034 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4035 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004036 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004037 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004038 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004039 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004040 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004041 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4042 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004043 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4044 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004045 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004046 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004047 /* Check status register pause & lpa register */
4048 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4049 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4050 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4051 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004052 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004053 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004054 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004055 .serdes_get_strings = mv88e6390_serdes_get_strings,
4056 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004057 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4058 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004059 .avb_ops = &mv88e6390_avb_ops,
4060 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004061 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004062};
4063
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004064static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004065 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004066 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4067 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004068 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004069 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4070 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004071 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004072 .phy_read = mv88e6xxx_g2_smi_phy_read,
4073 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004074 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004075 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004076 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004077 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004078 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004079 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004080 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004081 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4082 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004083 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004084 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004085 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004086 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004087 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004088 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004089 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004090 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004091 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004092 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004093 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4094 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004095 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004096 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4097 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004098 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004099 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004100 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004101 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004102 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004103 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4104 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004105 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004106 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004107 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004108 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4109 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4110 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4111 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004112 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004113 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004114 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004115 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004116 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4117 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004118 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004119 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004120 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004121 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004122};
4123
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004124static const struct mv88e6xxx_ops mv88e6250_ops = {
4125 /* MV88E6XXX_FAMILY_6250 */
4126 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4127 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4128 .irl_init_all = mv88e6352_g2_irl_init_all,
4129 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4130 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4131 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4132 .phy_read = mv88e6xxx_g2_smi_phy_read,
4133 .phy_write = mv88e6xxx_g2_smi_phy_write,
4134 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004135 .port_sync_link = mv88e6xxx_port_sync_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004136 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004137 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004138 .port_tag_remap = mv88e6095_port_tag_remap,
4139 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004140 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4141 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004142 .port_set_ether_type = mv88e6351_port_set_ether_type,
4143 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4144 .port_pause_limit = mv88e6097_port_pause_limit,
4145 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004146 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4147 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4148 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4149 .stats_get_strings = mv88e6250_stats_get_strings,
4150 .stats_get_stats = mv88e6250_stats_get_stats,
4151 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4152 .set_egress_port = mv88e6095_g1_set_egress_port,
4153 .watchdog_ops = &mv88e6250_watchdog_ops,
4154 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4155 .pot_clear = mv88e6xxx_g2_pot_clear,
4156 .reset = mv88e6250_g1_reset,
Rasmus Villemoes67c9ed12021-01-25 16:04:48 +01004157 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Rasmus Villemoesb28f3f32021-01-25 16:04:49 +01004158 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004159 .avb_ops = &mv88e6352_avb_ops,
4160 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004161 .phylink_validate = mv88e6065_phylink_validate,
4162};
4163
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004164static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004165 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004166 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004167 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004168 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4169 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004170 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4171 .phy_read = mv88e6xxx_g2_smi_phy_read,
4172 .phy_write = mv88e6xxx_g2_smi_phy_write,
4173 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004174 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004175 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004176 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004177 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004178 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004179 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004180 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004181 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4182 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004183 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004184 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004185 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004186 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004187 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004188 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004189 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004190 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004191 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004192 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4193 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004194 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004195 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4196 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004197 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004198 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004199 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004200 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004201 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004202 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4203 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004204 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4205 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004206 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004207 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004208 /* Check status register pause & lpa register */
4209 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4210 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4211 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4212 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004213 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004214 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004215 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004216 .serdes_get_strings = mv88e6390_serdes_get_strings,
4217 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004218 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4219 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004220 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004221 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004222 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004223 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004224};
4225
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004226static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004227 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004228 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4229 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004230 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004231 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4232 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004233 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004234 .phy_read = mv88e6xxx_g2_smi_phy_read,
4235 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004236 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004237 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004238 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004239 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004240 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004241 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4242 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004243 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004244 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004245 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004246 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004247 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004248 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004249 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004250 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004251 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004252 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004253 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4254 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004255 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004256 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4257 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004258 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004259 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004260 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004261 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004262 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004263 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004264 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004265 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004266 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004267 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004268};
4269
4270static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004271 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004272 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4273 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004274 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004275 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4276 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004277 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004278 .phy_read = mv88e6xxx_g2_smi_phy_read,
4279 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004280 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004281 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004282 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004283 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004284 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004285 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4286 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004287 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004288 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004289 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004290 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004291 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004292 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004293 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004294 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004295 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004296 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004297 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4298 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004299 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004300 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4301 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004302 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004303 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004304 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004305 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004306 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004307 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004308 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004309 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004310};
4311
Vivien Didelot16e329a2017-03-28 13:50:33 -04004312static const struct mv88e6xxx_ops mv88e6341_ops = {
4313 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004314 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4315 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004316 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004317 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4318 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4319 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4320 .phy_read = mv88e6xxx_g2_smi_phy_read,
4321 .phy_write = mv88e6xxx_g2_smi_phy_write,
4322 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004323 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004324 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004325 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004326 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004327 .port_tag_remap = mv88e6095_port_tag_remap,
4328 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004329 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4330 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004331 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004332 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004333 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004334 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004335 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4336 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004337 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004338 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004339 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004340 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004341 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004342 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4343 .stats_get_strings = mv88e6320_stats_get_strings,
4344 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004345 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4346 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004347 .watchdog_ops = &mv88e6390_watchdog_ops,
4348 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004349 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004350 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004351 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004352 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004353 .serdes_power = mv88e6390_serdes_power,
4354 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004355 /* Check status register pause & lpa register */
4356 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4357 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4358 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4359 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004360 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004361 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004362 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004363 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004364 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004365 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01004366 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004367};
4368
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004369static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004370 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004371 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4372 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004373 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004374 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004375 .phy_read = mv88e6xxx_g2_smi_phy_read,
4376 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004377 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004378 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004379 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004380 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004381 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004382 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004383 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4384 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004385 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004386 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004387 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004388 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004389 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004390 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004391 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004392 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004393 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004394 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004395 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4396 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004397 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004398 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4399 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004400 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004401 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004402 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004403 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004404 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4405 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004406 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004407 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004408 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004409};
4410
4411static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004412 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004413 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4414 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004415 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004416 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004417 .phy_read = mv88e6xxx_g2_smi_phy_read,
4418 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004419 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004420 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004421 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004422 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004423 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004424 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004425 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4426 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004427 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004428 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004429 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004430 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004431 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004432 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004433 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004434 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004435 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004436 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004437 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4438 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004439 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004440 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4441 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004442 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004443 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004444 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004445 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004446 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4447 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004448 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004449 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004450 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004451 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004452 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004453};
4454
4455static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004456 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004457 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4458 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004459 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004460 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4461 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004462 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004463 .phy_read = mv88e6xxx_g2_smi_phy_read,
4464 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004465 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004466 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004467 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004468 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004469 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004470 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004471 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004472 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4473 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004474 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004475 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004476 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004477 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004478 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004479 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004480 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004481 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004482 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004483 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004484 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4485 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004486 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004487 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4488 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004489 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004490 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004491 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004492 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004493 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004494 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4495 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004496 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004497 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004498 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004499 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4500 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4501 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4502 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004503 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004504 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004505 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004506 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004507 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004508 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004509 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004510 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4511 .serdes_get_strings = mv88e6352_serdes_get_strings,
4512 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004513 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4514 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004515 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004516};
4517
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004518static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004519 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004520 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004521 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004522 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4523 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004524 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4525 .phy_read = mv88e6xxx_g2_smi_phy_read,
4526 .phy_write = mv88e6xxx_g2_smi_phy_write,
4527 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004528 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004529 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004530 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004531 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004532 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004533 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004534 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004535 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4536 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004537 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004538 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004539 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004540 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004541 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004542 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004543 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004544 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004545 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004546 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004547 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004548 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4549 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004550 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004551 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4552 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004553 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004554 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004555 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004556 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004557 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004558 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4559 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004560 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4561 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004562 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004563 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004564 /* Check status register pause & lpa register */
4565 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4566 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4567 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4568 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004569 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004570 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004571 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004572 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004573 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004574 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004575 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4576 .serdes_get_strings = mv88e6390_serdes_get_strings,
4577 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004578 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4579 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004580 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004581};
4582
4583static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004584 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004585 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004586 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004587 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4588 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004589 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4590 .phy_read = mv88e6xxx_g2_smi_phy_read,
4591 .phy_write = mv88e6xxx_g2_smi_phy_write,
4592 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004593 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004594 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004595 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004596 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004597 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004598 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004599 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004600 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4601 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004602 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004603 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004604 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004605 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004606 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004607 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004608 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004609 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004610 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004611 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004612 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004613 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4614 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004615 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004616 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4617 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004618 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004619 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004620 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004621 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004622 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004623 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4624 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004625 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4626 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004627 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004628 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004629 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4630 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4631 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4632 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004633 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004634 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004635 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004636 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4637 .serdes_get_strings = mv88e6390_serdes_get_strings,
4638 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004639 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4640 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004641 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004642 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004643 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004644 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004645};
4646
Pavana Sharmade776d02021-03-17 14:46:42 +01004647static const struct mv88e6xxx_ops mv88e6393x_ops = {
4648 /* MV88E6XXX_FAMILY_6393 */
4649 .setup_errata = mv88e6393x_serdes_setup_errata,
4650 .irl_init_all = mv88e6390_g2_irl_init_all,
4651 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4652 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4653 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4654 .phy_read = mv88e6xxx_g2_smi_phy_read,
4655 .phy_write = mv88e6xxx_g2_smi_phy_write,
4656 .port_set_link = mv88e6xxx_port_set_link,
4657 .port_sync_link = mv88e6xxx_port_sync_link,
4658 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4659 .port_set_speed_duplex = mv88e6393x_port_set_speed_duplex,
4660 .port_max_speed_mode = mv88e6393x_port_max_speed_mode,
4661 .port_tag_remap = mv88e6390_port_tag_remap,
Marek Behún6584b262021-03-17 14:46:43 +01004662 .port_set_policy = mv88e6393x_port_set_policy,
Pavana Sharmade776d02021-03-17 14:46:42 +01004663 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4664 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4665 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4666 .port_set_ether_type = mv88e6393x_port_set_ether_type,
4667 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4668 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4669 .port_pause_limit = mv88e6390_port_pause_limit,
4670 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4671 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4672 .port_get_cmode = mv88e6352_port_get_cmode,
4673 .port_set_cmode = mv88e6393x_port_set_cmode,
4674 .port_setup_message_port = mv88e6xxx_setup_message_port,
4675 .port_set_upstream_port = mv88e6393x_port_set_upstream_port,
4676 .stats_snapshot = mv88e6390_g1_stats_snapshot,
4677 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4678 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4679 .stats_get_strings = mv88e6320_stats_get_strings,
4680 .stats_get_stats = mv88e6390_stats_get_stats,
4681 /* .set_cpu_port is missing because this family does not support a global
4682 * CPU port, only per port CPU port which is set via
4683 * .port_set_upstream_port method.
4684 */
4685 .set_egress_port = mv88e6393x_set_egress_port,
4686 .watchdog_ops = &mv88e6390_watchdog_ops,
4687 .mgmt_rsvd2cpu = mv88e6393x_port_mgmt_rsvd2cpu,
4688 .pot_clear = mv88e6xxx_g2_pot_clear,
4689 .reset = mv88e6352_g1_reset,
4690 .rmu_disable = mv88e6390_g1_rmu_disable,
4691 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4692 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4693 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4694 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4695 .serdes_power = mv88e6393x_serdes_power,
4696 .serdes_get_lane = mv88e6393x_serdes_get_lane,
4697 .serdes_pcs_get_state = mv88e6393x_serdes_pcs_get_state,
4698 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4699 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4700 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4701 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4702 .serdes_irq_enable = mv88e6393x_serdes_irq_enable,
4703 .serdes_irq_status = mv88e6393x_serdes_irq_status,
4704 /* TODO: serdes stats */
4705 .gpio_ops = &mv88e6352_gpio_ops,
4706 .avb_ops = &mv88e6390_avb_ops,
4707 .ptp_ops = &mv88e6352_ptp_ops,
4708 .phylink_validate = mv88e6393x_phylink_validate,
4709};
4710
Vivien Didelotf81ec902016-05-09 13:22:58 -04004711static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4712 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004713 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004714 .family = MV88E6XXX_FAMILY_6097,
4715 .name = "Marvell 88E6085",
4716 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004717 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004718 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004719 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004720 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004721 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004722 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004723 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004724 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004725 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004726 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004727 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004728 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004729 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004730 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004731 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004732 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004733 },
4734
4735 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004736 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004737 .family = MV88E6XXX_FAMILY_6095,
4738 .name = "Marvell 88E6095/88E6095F",
4739 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004740 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004741 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004742 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004743 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004744 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004745 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004746 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004747 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004748 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004749 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004750 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004751 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004752 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004753 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004754 },
4755
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004756 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004757 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004758 .family = MV88E6XXX_FAMILY_6097,
4759 .name = "Marvell 88E6097/88E6097F",
4760 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004761 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004762 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004763 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004764 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004765 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004766 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004767 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004768 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004769 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004770 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004771 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004772 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004773 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004774 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01004775 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004776 .ops = &mv88e6097_ops,
4777 },
4778
Vivien Didelotf81ec902016-05-09 13:22:58 -04004779 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004780 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004781 .family = MV88E6XXX_FAMILY_6165,
4782 .name = "Marvell 88E6123",
4783 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004784 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004785 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004786 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004787 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004788 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004789 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004790 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004791 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004792 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004793 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004794 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004795 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004796 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004797 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004798 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004799 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004800 },
4801
4802 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004803 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004804 .family = MV88E6XXX_FAMILY_6185,
4805 .name = "Marvell 88E6131",
4806 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004807 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004808 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004809 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004810 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004811 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004812 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004813 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004814 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004815 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004816 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004817 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004818 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004819 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004820 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004821 },
4822
Vivien Didelot990e27b2017-03-28 13:50:32 -04004823 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004824 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004825 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01004826 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04004827 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004828 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004829 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004830 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004831 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004832 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004833 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004834 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004835 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004836 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004837 .age_time_coeff = 3750,
4838 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004839 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004840 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004841 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004842 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004843 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004844 .ops = &mv88e6141_ops,
4845 },
4846
Vivien Didelotf81ec902016-05-09 13:22:58 -04004847 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004848 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004849 .family = MV88E6XXX_FAMILY_6165,
4850 .name = "Marvell 88E6161",
4851 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004852 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004853 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004854 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004855 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004856 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004857 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004858 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004859 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004860 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004861 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004862 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004863 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004864 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004865 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004866 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004867 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004868 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004869 },
4870
4871 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004872 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004873 .family = MV88E6XXX_FAMILY_6165,
4874 .name = "Marvell 88E6165",
4875 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004876 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004877 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004878 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004879 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004880 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004881 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004882 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004883 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004884 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004885 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004886 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004887 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004888 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004889 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004890 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004891 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004892 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004893 },
4894
4895 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004896 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004897 .family = MV88E6XXX_FAMILY_6351,
4898 .name = "Marvell 88E6171",
4899 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004900 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004901 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004902 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004903 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004904 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004905 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004906 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004907 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004908 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004909 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004910 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004911 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004912 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004913 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004914 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004915 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004916 },
4917
4918 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004919 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004920 .family = MV88E6XXX_FAMILY_6352,
4921 .name = "Marvell 88E6172",
4922 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004923 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004924 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004925 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004926 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004927 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004928 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004929 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004930 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004931 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004932 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004933 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004934 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004935 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004936 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004937 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004938 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004939 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004940 },
4941
4942 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004943 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004944 .family = MV88E6XXX_FAMILY_6351,
4945 .name = "Marvell 88E6175",
4946 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004947 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004948 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004949 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004950 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004951 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004952 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004953 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004954 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004955 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004956 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004957 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004958 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004959 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004960 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004961 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004962 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004963 },
4964
4965 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004966 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004967 .family = MV88E6XXX_FAMILY_6352,
4968 .name = "Marvell 88E6176",
4969 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004970 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004971 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004972 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004973 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004974 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004975 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004976 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004977 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004978 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004979 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004980 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004981 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004982 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004983 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004984 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004985 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004986 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004987 },
4988
4989 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004990 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004991 .family = MV88E6XXX_FAMILY_6185,
4992 .name = "Marvell 88E6185",
4993 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004994 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004995 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004996 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004997 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004998 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004999 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005000 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005001 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005002 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005003 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05005004 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005005 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005006 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005007 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005008 },
5009
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005010 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005011 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005012 .family = MV88E6XXX_FAMILY_6390,
5013 .name = "Marvell 88E6190",
5014 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005015 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005016 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005017 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005018 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005019 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005020 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005021 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005022 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005023 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005024 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005025 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005026 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005027 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04005028 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005029 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05005030 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005031 .ops = &mv88e6190_ops,
5032 },
5033
5034 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005035 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005036 .family = MV88E6XXX_FAMILY_6390,
5037 .name = "Marvell 88E6190X",
5038 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005039 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005040 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005041 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005042 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005043 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005044 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005045 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005046 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005047 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005048 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005049 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005050 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005051 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005052 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005053 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005054 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005055 .ops = &mv88e6190x_ops,
5056 },
5057
5058 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005059 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005060 .family = MV88E6XXX_FAMILY_6390,
5061 .name = "Marvell 88E6191",
5062 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005063 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005064 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005065 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04005066 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005067 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005068 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005069 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005070 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005071 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005072 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005073 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005074 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005075 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005076 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005077 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005078 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04005079 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005080 },
5081
Pavana Sharmade776d02021-03-17 14:46:42 +01005082 [MV88E6191X] = {
5083 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191X,
5084 .family = MV88E6XXX_FAMILY_6393,
5085 .name = "Marvell 88E6191X",
5086 .num_databases = 4096,
5087 .num_ports = 11, /* 10 + Z80 */
5088 .num_internal_phys = 9,
5089 .max_vid = 8191,
5090 .port_base_addr = 0x0,
5091 .phy_base_addr = 0x0,
5092 .global1_addr = 0x1b,
5093 .global2_addr = 0x1c,
5094 .age_time_coeff = 3750,
5095 .g1_irqs = 10,
5096 .g2_irqs = 14,
5097 .atu_move_port_mask = 0x1f,
5098 .pvt = true,
5099 .multi_chip = true,
5100 .tag_protocol = DSA_TAG_PROTO_DSA,
5101 .ptp_support = true,
5102 .ops = &mv88e6393x_ops,
5103 },
5104
5105 [MV88E6193X] = {
5106 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6193X,
5107 .family = MV88E6XXX_FAMILY_6393,
5108 .name = "Marvell 88E6193X",
5109 .num_databases = 4096,
5110 .num_ports = 11, /* 10 + Z80 */
5111 .num_internal_phys = 9,
5112 .max_vid = 8191,
5113 .port_base_addr = 0x0,
5114 .phy_base_addr = 0x0,
5115 .global1_addr = 0x1b,
5116 .global2_addr = 0x1c,
5117 .age_time_coeff = 3750,
5118 .g1_irqs = 10,
5119 .g2_irqs = 14,
5120 .atu_move_port_mask = 0x1f,
5121 .pvt = true,
5122 .multi_chip = true,
5123 .tag_protocol = DSA_TAG_PROTO_DSA,
5124 .ptp_support = true,
5125 .ops = &mv88e6393x_ops,
5126 },
5127
Hubert Feurstein49022642019-07-31 10:23:46 +02005128 [MV88E6220] = {
5129 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
5130 .family = MV88E6XXX_FAMILY_6250,
5131 .name = "Marvell 88E6220",
5132 .num_databases = 64,
5133
5134 /* Ports 2-4 are not routed to pins
5135 * => usable ports 0, 1, 5, 6
5136 */
5137 .num_ports = 7,
5138 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02005139 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02005140 .max_vid = 4095,
5141 .port_base_addr = 0x08,
5142 .phy_base_addr = 0x00,
5143 .global1_addr = 0x0f,
5144 .global2_addr = 0x07,
5145 .age_time_coeff = 15000,
5146 .g1_irqs = 9,
5147 .g2_irqs = 10,
5148 .atu_move_port_mask = 0xf,
5149 .dual_chip = true,
5150 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02005151 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02005152 .ops = &mv88e6250_ops,
5153 },
5154
Vivien Didelotf81ec902016-05-09 13:22:58 -04005155 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005156 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005157 .family = MV88E6XXX_FAMILY_6352,
5158 .name = "Marvell 88E6240",
5159 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005160 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005161 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005162 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005163 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005164 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005165 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005166 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005167 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005168 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005169 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005170 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005171 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005172 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005173 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005174 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005175 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005176 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005177 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005178 },
5179
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005180 [MV88E6250] = {
5181 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
5182 .family = MV88E6XXX_FAMILY_6250,
5183 .name = "Marvell 88E6250",
5184 .num_databases = 64,
5185 .num_ports = 7,
5186 .num_internal_phys = 5,
5187 .max_vid = 4095,
5188 .port_base_addr = 0x08,
5189 .phy_base_addr = 0x00,
5190 .global1_addr = 0x0f,
5191 .global2_addr = 0x07,
5192 .age_time_coeff = 15000,
5193 .g1_irqs = 9,
5194 .g2_irqs = 10,
5195 .atu_move_port_mask = 0xf,
5196 .dual_chip = true,
5197 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02005198 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005199 .ops = &mv88e6250_ops,
5200 },
5201
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005202 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005203 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005204 .family = MV88E6XXX_FAMILY_6390,
5205 .name = "Marvell 88E6290",
5206 .num_databases = 4096,
5207 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005208 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005209 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005210 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005211 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005212 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005213 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005214 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005215 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005216 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005217 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005218 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005219 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005220 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005221 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005222 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005223 .ops = &mv88e6290_ops,
5224 },
5225
Vivien Didelotf81ec902016-05-09 13:22:58 -04005226 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005227 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005228 .family = MV88E6XXX_FAMILY_6320,
5229 .name = "Marvell 88E6320",
5230 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005231 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005232 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005233 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005234 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005235 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005236 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005237 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005238 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005239 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005240 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005241 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005242 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005243 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005244 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005245 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005246 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005247 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005248 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005249 },
5250
5251 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005252 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005253 .family = MV88E6XXX_FAMILY_6320,
5254 .name = "Marvell 88E6321",
5255 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005256 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005257 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005258 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005259 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005260 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005261 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005262 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005263 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005264 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005265 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005266 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005267 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005268 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005269 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005270 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005271 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005272 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005273 },
5274
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005275 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005276 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005277 .family = MV88E6XXX_FAMILY_6341,
5278 .name = "Marvell 88E6341",
5279 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005280 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005281 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005282 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005283 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005284 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005285 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005286 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005287 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005288 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005289 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005290 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005291 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005292 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005293 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005294 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005295 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005296 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005297 .ops = &mv88e6341_ops,
5298 },
5299
Vivien Didelotf81ec902016-05-09 13:22:58 -04005300 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005301 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005302 .family = MV88E6XXX_FAMILY_6351,
5303 .name = "Marvell 88E6350",
5304 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005305 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005306 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005307 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005308 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005309 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005310 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005311 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005312 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005313 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005314 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005315 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005316 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005317 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005318 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005319 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005320 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005321 },
5322
5323 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005324 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005325 .family = MV88E6XXX_FAMILY_6351,
5326 .name = "Marvell 88E6351",
5327 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005328 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005329 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005330 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005331 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005332 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005333 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005334 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005335 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005336 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005337 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005338 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005339 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005340 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005341 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005342 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005343 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005344 },
5345
5346 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005347 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005348 .family = MV88E6XXX_FAMILY_6352,
5349 .name = "Marvell 88E6352",
5350 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005351 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005352 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005353 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005354 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005355 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005356 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005357 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005358 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005359 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005360 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005361 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005362 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005363 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005364 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005365 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005366 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005367 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005368 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005369 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005370 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005371 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005372 .family = MV88E6XXX_FAMILY_6390,
5373 .name = "Marvell 88E6390",
5374 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005375 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005376 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005377 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005378 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005379 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005380 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005381 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005382 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005383 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005384 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005385 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005386 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005387 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005388 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005389 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005390 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005391 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005392 .ops = &mv88e6390_ops,
5393 },
5394 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005395 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005396 .family = MV88E6XXX_FAMILY_6390,
5397 .name = "Marvell 88E6390X",
5398 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005399 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005400 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005401 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005402 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005403 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005404 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005405 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005406 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005407 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005408 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005409 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005410 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005411 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005412 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005413 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005414 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005415 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005416 .ops = &mv88e6390x_ops,
5417 },
Pavana Sharmade776d02021-03-17 14:46:42 +01005418
5419 [MV88E6393X] = {
5420 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
5421 .family = MV88E6XXX_FAMILY_6393,
5422 .name = "Marvell 88E6393X",
5423 .num_databases = 4096,
5424 .num_ports = 11, /* 10 + Z80 */
5425 .num_internal_phys = 9,
5426 .max_vid = 8191,
5427 .port_base_addr = 0x0,
5428 .phy_base_addr = 0x0,
5429 .global1_addr = 0x1b,
5430 .global2_addr = 0x1c,
5431 .age_time_coeff = 3750,
5432 .g1_irqs = 10,
5433 .g2_irqs = 14,
5434 .atu_move_port_mask = 0x1f,
5435 .pvt = true,
5436 .multi_chip = true,
5437 .tag_protocol = DSA_TAG_PROTO_DSA,
5438 .ptp_support = true,
5439 .ops = &mv88e6393x_ops,
5440 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005441};
5442
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005443static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005444{
Vivien Didelota439c062016-04-17 13:23:58 -04005445 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005446
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005447 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5448 if (mv88e6xxx_table[i].prod_num == prod_num)
5449 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005450
Vivien Didelotb9b37712015-10-30 19:39:48 -04005451 return NULL;
5452}
5453
Vivien Didelotfad09c72016-06-21 12:28:20 -04005454static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005455{
5456 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005457 unsigned int prod_num, rev;
5458 u16 id;
5459 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005460
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005461 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005462 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005463 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005464 if (err)
5465 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005466
Vivien Didelot107fcc12017-06-12 12:37:36 -04005467 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5468 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005469
5470 info = mv88e6xxx_lookup_info(prod_num);
5471 if (!info)
5472 return -ENODEV;
5473
Vivien Didelotcaac8542016-06-20 13:14:09 -04005474 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005475 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005476
Vivien Didelotfad09c72016-06-21 12:28:20 -04005477 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5478 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005479
5480 return 0;
5481}
5482
Vivien Didelotfad09c72016-06-21 12:28:20 -04005483static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005484{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005485 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005486
Vivien Didelotfad09c72016-06-21 12:28:20 -04005487 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5488 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005489 return NULL;
5490
Vivien Didelotfad09c72016-06-21 12:28:20 -04005491 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005492
Vivien Didelotfad09c72016-06-21 12:28:20 -04005493 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005494 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005495 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005496
Vivien Didelotfad09c72016-06-21 12:28:20 -04005497 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005498}
5499
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005500static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005501 int port,
5502 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005503{
Vivien Didelot04bed142016-08-31 18:06:13 -04005504 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005505
Andrew Lunn443d5a12016-12-03 04:35:18 +01005506 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005507}
5508
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005509static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
5510 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005511{
Vivien Didelot04bed142016-08-31 18:06:13 -04005512 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005513 int err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005514
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005515 mv88e6xxx_reg_lock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005516 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5517 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005518 mv88e6xxx_reg_unlock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005519
5520 return err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005521}
5522
5523static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5524 const struct switchdev_obj_port_mdb *mdb)
5525{
Vivien Didelot04bed142016-08-31 18:06:13 -04005526 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005527 int err;
5528
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005529 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005530 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005531 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005532
5533 return err;
5534}
5535
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005536static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5537 struct dsa_mall_mirror_tc_entry *mirror,
5538 bool ingress)
5539{
5540 enum mv88e6xxx_egress_direction direction = ingress ?
5541 MV88E6XXX_EGRESS_DIR_INGRESS :
5542 MV88E6XXX_EGRESS_DIR_EGRESS;
5543 struct mv88e6xxx_chip *chip = ds->priv;
5544 bool other_mirrors = false;
5545 int i;
5546 int err;
5547
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005548 mutex_lock(&chip->reg_lock);
5549 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5550 mirror->to_local_port) {
5551 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5552 other_mirrors |= ingress ?
5553 chip->ports[i].mirror_ingress :
5554 chip->ports[i].mirror_egress;
5555
5556 /* Can't change egress port when other mirror is active */
5557 if (other_mirrors) {
5558 err = -EBUSY;
5559 goto out;
5560 }
5561
Marek Behún2fda45f2021-03-17 14:46:41 +01005562 err = mv88e6xxx_set_egress_port(chip, direction,
5563 mirror->to_local_port);
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005564 if (err)
5565 goto out;
5566 }
5567
5568 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5569out:
5570 mutex_unlock(&chip->reg_lock);
5571
5572 return err;
5573}
5574
5575static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5576 struct dsa_mall_mirror_tc_entry *mirror)
5577{
5578 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5579 MV88E6XXX_EGRESS_DIR_INGRESS :
5580 MV88E6XXX_EGRESS_DIR_EGRESS;
5581 struct mv88e6xxx_chip *chip = ds->priv;
5582 bool other_mirrors = false;
5583 int i;
5584
5585 mutex_lock(&chip->reg_lock);
5586 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5587 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5588
5589 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5590 other_mirrors |= mirror->ingress ?
5591 chip->ports[i].mirror_ingress :
5592 chip->ports[i].mirror_egress;
5593
5594 /* Reset egress port when no other mirror is active */
5595 if (!other_mirrors) {
Marek Behún2fda45f2021-03-17 14:46:41 +01005596 if (mv88e6xxx_set_egress_port(chip, direction,
5597 dsa_upstream_port(ds, port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005598 dev_err(ds->dev, "failed to set egress port\n");
5599 }
5600
5601 mutex_unlock(&chip->reg_lock);
5602}
5603
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005604static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port,
5605 struct switchdev_brport_flags flags,
5606 struct netlink_ext_ack *extack)
5607{
5608 struct mv88e6xxx_chip *chip = ds->priv;
5609 const struct mv88e6xxx_ops *ops;
5610
5611 if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD))
5612 return -EINVAL;
5613
5614 ops = chip->info->ops;
5615
5616 if ((flags.mask & BR_FLOOD) && !ops->port_set_ucast_flood)
5617 return -EINVAL;
5618
5619 if ((flags.mask & BR_MCAST_FLOOD) && !ops->port_set_mcast_flood)
5620 return -EINVAL;
5621
5622 return 0;
5623}
5624
5625static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
5626 struct switchdev_brport_flags flags,
5627 struct netlink_ext_ack *extack)
Russell King4f859012019-02-20 15:35:05 -08005628{
5629 struct mv88e6xxx_chip *chip = ds->priv;
5630 int err = -EOPNOTSUPP;
5631
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005632 mv88e6xxx_reg_lock(chip);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005633
5634 if (flags.mask & BR_FLOOD) {
5635 bool unicast = !!(flags.val & BR_FLOOD);
5636
5637 err = chip->info->ops->port_set_ucast_flood(chip, port,
5638 unicast);
5639 if (err)
5640 goto out;
5641 }
5642
5643 if (flags.mask & BR_MCAST_FLOOD) {
5644 bool multicast = !!(flags.val & BR_MCAST_FLOOD);
5645
5646 err = chip->info->ops->port_set_mcast_flood(chip, port,
5647 multicast);
5648 if (err)
5649 goto out;
5650 }
5651
5652out:
5653 mv88e6xxx_reg_unlock(chip);
5654
5655 return err;
5656}
5657
5658static int mv88e6xxx_port_set_mrouter(struct dsa_switch *ds, int port,
5659 bool mrouter,
5660 struct netlink_ext_ack *extack)
5661{
5662 struct mv88e6xxx_chip *chip = ds->priv;
5663 int err;
5664
5665 if (!chip->info->ops->port_set_mcast_flood)
5666 return -EOPNOTSUPP;
5667
5668 mv88e6xxx_reg_lock(chip);
5669 err = chip->info->ops->port_set_mcast_flood(chip, port, mrouter);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005670 mv88e6xxx_reg_unlock(chip);
Russell King4f859012019-02-20 15:35:05 -08005671
5672 return err;
5673}
5674
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005675static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
5676 struct net_device *lag,
5677 struct netdev_lag_upper_info *info)
5678{
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005679 struct mv88e6xxx_chip *chip = ds->priv;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005680 struct dsa_port *dp;
5681 int id, members = 0;
5682
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005683 if (!mv88e6xxx_has_lag(chip))
5684 return false;
5685
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005686 id = dsa_lag_id(ds->dst, lag);
5687 if (id < 0 || id >= ds->num_lag_ids)
5688 return false;
5689
5690 dsa_lag_foreach_port(dp, ds->dst, lag)
5691 /* Includes the port joining the LAG */
5692 members++;
5693
5694 if (members > 8)
5695 return false;
5696
5697 /* We could potentially relax this to include active
5698 * backup in the future.
5699 */
5700 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
5701 return false;
5702
5703 /* Ideally we would also validate that the hash type matches
5704 * the hardware. Alas, this is always set to unknown on team
5705 * interfaces.
5706 */
5707 return true;
5708}
5709
5710static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct net_device *lag)
5711{
5712 struct mv88e6xxx_chip *chip = ds->priv;
5713 struct dsa_port *dp;
5714 u16 map = 0;
5715 int id;
5716
5717 id = dsa_lag_id(ds->dst, lag);
5718
5719 /* Build the map of all ports to distribute flows destined for
5720 * this LAG. This can be either a local user port, or a DSA
5721 * port if the LAG port is on a remote chip.
5722 */
5723 dsa_lag_foreach_port(dp, ds->dst, lag)
5724 map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));
5725
5726 return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
5727}
5728
5729static const u8 mv88e6xxx_lag_mask_table[8][8] = {
5730 /* Row number corresponds to the number of active members in a
5731 * LAG. Each column states which of the eight hash buckets are
5732 * mapped to the column:th port in the LAG.
5733 *
5734 * Example: In a LAG with three active ports, the second port
5735 * ([2][1]) would be selected for traffic mapped to buckets
5736 * 3,4,5 (0x38).
5737 */
5738 { 0xff, 0, 0, 0, 0, 0, 0, 0 },
5739 { 0x0f, 0xf0, 0, 0, 0, 0, 0, 0 },
5740 { 0x07, 0x38, 0xc0, 0, 0, 0, 0, 0 },
5741 { 0x03, 0x0c, 0x30, 0xc0, 0, 0, 0, 0 },
5742 { 0x03, 0x0c, 0x30, 0x40, 0x80, 0, 0, 0 },
5743 { 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80, 0, 0 },
5744 { 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0 },
5745 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
5746};
5747
5748static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
5749 int num_tx, int nth)
5750{
5751 u8 active = 0;
5752 int i;
5753
5754 num_tx = num_tx <= 8 ? num_tx : 8;
5755 if (nth < num_tx)
5756 active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];
5757
5758 for (i = 0; i < 8; i++) {
5759 if (BIT(i) & active)
5760 mask[i] |= BIT(port);
5761 }
5762}
5763
5764static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
5765{
5766 struct mv88e6xxx_chip *chip = ds->priv;
5767 unsigned int id, num_tx;
5768 struct net_device *lag;
5769 struct dsa_port *dp;
5770 int i, err, nth;
5771 u16 mask[8];
5772 u16 ivec;
5773
5774 /* Assume no port is a member of any LAG. */
5775 ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;
5776
5777 /* Disable all masks for ports that _are_ members of a LAG. */
5778 list_for_each_entry(dp, &ds->dst->ports, list) {
5779 if (!dp->lag_dev || dp->ds != ds)
5780 continue;
5781
5782 ivec &= ~BIT(dp->index);
5783 }
5784
5785 for (i = 0; i < 8; i++)
5786 mask[i] = ivec;
5787
5788 /* Enable the correct subset of masks for all LAG ports that
5789 * are in the Tx set.
5790 */
5791 dsa_lags_foreach_id(id, ds->dst) {
5792 lag = dsa_lag_dev(ds->dst, id);
5793 if (!lag)
5794 continue;
5795
5796 num_tx = 0;
5797 dsa_lag_foreach_port(dp, ds->dst, lag) {
5798 if (dp->lag_tx_enabled)
5799 num_tx++;
5800 }
5801
5802 if (!num_tx)
5803 continue;
5804
5805 nth = 0;
5806 dsa_lag_foreach_port(dp, ds->dst, lag) {
5807 if (!dp->lag_tx_enabled)
5808 continue;
5809
5810 if (dp->ds == ds)
5811 mv88e6xxx_lag_set_port_mask(mask, dp->index,
5812 num_tx, nth);
5813
5814 nth++;
5815 }
5816 }
5817
5818 for (i = 0; i < 8; i++) {
5819 err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
5820 if (err)
5821 return err;
5822 }
5823
5824 return 0;
5825}
5826
5827static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
5828 struct net_device *lag)
5829{
5830 int err;
5831
5832 err = mv88e6xxx_lag_sync_masks(ds);
5833
5834 if (!err)
5835 err = mv88e6xxx_lag_sync_map(ds, lag);
5836
5837 return err;
5838}
5839
5840static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port)
5841{
5842 struct mv88e6xxx_chip *chip = ds->priv;
5843 int err;
5844
5845 mv88e6xxx_reg_lock(chip);
5846 err = mv88e6xxx_lag_sync_masks(ds);
5847 mv88e6xxx_reg_unlock(chip);
5848 return err;
5849}
5850
5851static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
5852 struct net_device *lag,
5853 struct netdev_lag_upper_info *info)
5854{
5855 struct mv88e6xxx_chip *chip = ds->priv;
5856 int err, id;
5857
5858 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
5859 return -EOPNOTSUPP;
5860
5861 id = dsa_lag_id(ds->dst, lag);
5862
5863 mv88e6xxx_reg_lock(chip);
5864
5865 err = mv88e6xxx_port_set_trunk(chip, port, true, id);
5866 if (err)
5867 goto err_unlock;
5868
5869 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
5870 if (err)
5871 goto err_clear_trunk;
5872
5873 mv88e6xxx_reg_unlock(chip);
5874 return 0;
5875
5876err_clear_trunk:
5877 mv88e6xxx_port_set_trunk(chip, port, false, 0);
5878err_unlock:
5879 mv88e6xxx_reg_unlock(chip);
5880 return err;
5881}
5882
5883static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
5884 struct net_device *lag)
5885{
5886 struct mv88e6xxx_chip *chip = ds->priv;
5887 int err_sync, err_trunk;
5888
5889 mv88e6xxx_reg_lock(chip);
5890 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
5891 err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
5892 mv88e6xxx_reg_unlock(chip);
5893 return err_sync ? : err_trunk;
5894}
5895
5896static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
5897 int port)
5898{
5899 struct mv88e6xxx_chip *chip = ds->priv;
5900 int err;
5901
5902 mv88e6xxx_reg_lock(chip);
5903 err = mv88e6xxx_lag_sync_masks(ds);
5904 mv88e6xxx_reg_unlock(chip);
5905 return err;
5906}
5907
5908static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
5909 int port, struct net_device *lag,
5910 struct netdev_lag_upper_info *info)
5911{
5912 struct mv88e6xxx_chip *chip = ds->priv;
5913 int err;
5914
5915 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
5916 return -EOPNOTSUPP;
5917
5918 mv88e6xxx_reg_lock(chip);
5919
5920 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
5921 if (err)
5922 goto unlock;
5923
5924 err = mv88e6xxx_pvt_map(chip, sw_index, port);
5925
5926unlock:
5927 mv88e6xxx_reg_unlock(chip);
5928 return err;
5929}
5930
5931static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
5932 int port, struct net_device *lag)
5933{
5934 struct mv88e6xxx_chip *chip = ds->priv;
5935 int err_sync, err_pvt;
5936
5937 mv88e6xxx_reg_lock(chip);
5938 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
5939 err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
5940 mv88e6xxx_reg_unlock(chip);
5941 return err_sync ? : err_pvt;
5942}
5943
Florian Fainellia82f67a2017-01-08 14:52:08 -08005944static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02005945 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005946 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005947 .teardown = mv88e6xxx_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07005948 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00005949 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07005950 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00005951 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07005952 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
5953 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005954 .get_strings = mv88e6xxx_get_strings,
5955 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
5956 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02005957 .port_enable = mv88e6xxx_port_enable,
5958 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02005959 .port_max_mtu = mv88e6xxx_get_max_mtu,
5960 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04005961 .get_mac_eee = mv88e6xxx_get_mac_eee,
5962 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005963 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005964 .get_eeprom = mv88e6xxx_get_eeprom,
5965 .set_eeprom = mv88e6xxx_set_eeprom,
5966 .get_regs_len = mv88e6xxx_get_regs_len,
5967 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04005968 .get_rxnfc = mv88e6xxx_get_rxnfc,
5969 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04005970 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005971 .port_bridge_join = mv88e6xxx_port_bridge_join,
5972 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005973 .port_pre_bridge_flags = mv88e6xxx_port_pre_bridge_flags,
5974 .port_bridge_flags = mv88e6xxx_port_bridge_flags,
5975 .port_set_mrouter = mv88e6xxx_port_set_mrouter,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005976 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04005977 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005978 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005979 .port_vlan_add = mv88e6xxx_port_vlan_add,
5980 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005981 .port_fdb_add = mv88e6xxx_port_fdb_add,
5982 .port_fdb_del = mv88e6xxx_port_fdb_del,
5983 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005984 .port_mdb_add = mv88e6xxx_port_mdb_add,
5985 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005986 .port_mirror_add = mv88e6xxx_port_mirror_add,
5987 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04005988 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
5989 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005990 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
5991 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
5992 .port_txtstamp = mv88e6xxx_port_txtstamp,
5993 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
5994 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005995 .devlink_param_get = mv88e6xxx_devlink_param_get,
5996 .devlink_param_set = mv88e6xxx_devlink_param_set,
Andrew Lunn93157302020-09-18 21:11:09 +02005997 .devlink_info_get = mv88e6xxx_devlink_info_get,
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005998 .port_lag_change = mv88e6xxx_port_lag_change,
5999 .port_lag_join = mv88e6xxx_port_lag_join,
6000 .port_lag_leave = mv88e6xxx_port_lag_leave,
6001 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
6002 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
6003 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006004};
6005
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08006006static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006007{
Vivien Didelotfad09c72016-06-21 12:28:20 -04006008 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006009 struct dsa_switch *ds;
6010
Vivien Didelot7e99e342019-10-21 16:51:30 -04006011 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006012 if (!ds)
6013 return -ENOMEM;
6014
Vivien Didelot7e99e342019-10-21 16:51:30 -04006015 ds->dev = dev;
6016 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006017 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006018 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04006019 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04006020 ds->ageing_time_min = chip->info->age_time_coeff;
6021 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006022
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006023 /* Some chips support up to 32, but that requires enabling the
6024 * 5-bit port mode, which we do not support. 640k^W16 ought to
6025 * be enough for anyone.
6026 */
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01006027 ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006028
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006029 dev_set_drvdata(dev, ds);
6030
Vivien Didelot23c9ee42017-05-26 18:12:51 -04006031 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006032}
6033
Vivien Didelotfad09c72016-06-21 12:28:20 -04006034static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006035{
Vivien Didelotfad09c72016-06-21 12:28:20 -04006036 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006037}
6038
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006039static const void *pdata_device_get_match_data(struct device *dev)
6040{
6041 const struct of_device_id *matches = dev->driver->of_match_table;
6042 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
6043
6044 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
6045 matches++) {
6046 if (!strcmp(pdata->compatible, matches->compatible))
6047 return matches->data;
6048 }
6049 return NULL;
6050}
6051
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006052/* There is no suspend to RAM support at DSA level yet, the switch configuration
6053 * would be lost after a power cycle so prevent it to be suspended.
6054 */
6055static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
6056{
6057 return -EOPNOTSUPP;
6058}
6059
6060static int __maybe_unused mv88e6xxx_resume(struct device *dev)
6061{
6062 return 0;
6063}
6064
6065static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
6066
Vivien Didelot57d32312016-06-20 13:13:58 -04006067static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006068{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006069 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04006070 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006071 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006072 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04006073 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006074 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02006075 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006076
Andrew Lunn7bb8c992018-05-31 00:15:42 +02006077 if (!np && !pdata)
6078 return -EINVAL;
6079
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006080 if (np)
6081 compat_info = of_device_get_match_data(dev);
6082
6083 if (pdata) {
6084 compat_info = pdata_device_get_match_data(dev);
6085
6086 if (!pdata->netdev)
6087 return -EINVAL;
6088
6089 for (port = 0; port < DSA_MAX_PORTS; port++) {
6090 if (!(pdata->enabled_ports & (1 << port)))
6091 continue;
6092 if (strcmp(pdata->cd.port_names[port], "cpu"))
6093 continue;
6094 pdata->cd.netdev[port] = &pdata->netdev->dev;
6095 break;
6096 }
6097 }
6098
Vivien Didelotcaac8542016-06-20 13:14:09 -04006099 if (!compat_info)
6100 return -EINVAL;
6101
Vivien Didelotfad09c72016-06-21 12:28:20 -04006102 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006103 if (!chip) {
6104 err = -ENOMEM;
6105 goto out;
6106 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006107
Vivien Didelotfad09c72016-06-21 12:28:20 -04006108 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04006109
Vivien Didelotfad09c72016-06-21 12:28:20 -04006110 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04006111 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006112 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006113
Andrew Lunnb4308f02016-11-21 23:26:55 +01006114 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006115 if (IS_ERR(chip->reset)) {
6116 err = PTR_ERR(chip->reset);
6117 goto out;
6118 }
Baruch Siach7b75e492019-06-27 21:17:39 +03006119 if (chip->reset)
6120 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01006121
Vivien Didelotfad09c72016-06-21 12:28:20 -04006122 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04006123 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006124 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006125
Vivien Didelote57e5e72016-08-15 17:19:00 -04006126 mv88e6xxx_phy_init(chip);
6127
Andrew Lunn00baabe2018-05-19 22:31:35 +02006128 if (chip->info->ops->get_eeprom) {
6129 if (np)
6130 of_property_read_u32(np, "eeprom-length",
6131 &chip->eeprom_len);
6132 else
6133 chip->eeprom_len = pdata->eeprom_len;
6134 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006135
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006136 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006137 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006138 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02006139 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02006140 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02006141
Andrew Lunna27415d2019-05-01 00:10:50 +02006142 if (np) {
6143 chip->irq = of_irq_get(np, 0);
6144 if (chip->irq == -EPROBE_DEFER) {
6145 err = chip->irq;
6146 goto out;
6147 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02006148 }
6149
Andrew Lunna27415d2019-05-01 00:10:50 +02006150 if (pdata)
6151 chip->irq = pdata->irq;
6152
Andrew Lunn294d7112018-02-22 22:58:32 +01006153 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01006154 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01006155 * controllers
6156 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006157 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006158 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006159 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006160 else
6161 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006162 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006163
Andrew Lunn294d7112018-02-22 22:58:32 +01006164 if (err)
6165 goto out;
6166
6167 if (chip->info->g2_irqs > 0) {
6168 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006169 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01006170 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02006171 }
6172
Andrew Lunn294d7112018-02-22 22:58:32 +01006173 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
6174 if (err)
6175 goto out_g2_irq;
6176
6177 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
6178 if (err)
6179 goto out_g1_atu_prob_irq;
6180
Andrew Lunna3c53be52017-01-24 14:53:50 +01006181 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02006182 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01006183 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02006184
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08006185 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006186 if (err)
6187 goto out_mdio;
6188
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006189 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02006190
6191out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01006192 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01006193out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006194 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01006195out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006196 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006197out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006198 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006199 mv88e6xxx_g2_irq_free(chip);
6200out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006201 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006202 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006203 else
6204 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006205out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006206 if (pdata)
6207 dev_put(pdata->netdev);
6208
Andrew Lunndc30c352016-10-16 19:56:49 +02006209 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006210}
6211
6212static void mv88e6xxx_remove(struct mdio_device *mdiodev)
6213{
6214 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04006215 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006216
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006217 if (chip->info->ptp_support) {
6218 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006219 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006220 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006221
Andrew Lunn930188c2016-08-22 16:01:03 +02006222 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006223 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01006224 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006225
Andrew Lunn76f38f12018-03-17 20:21:09 +01006226 mv88e6xxx_g1_vtu_prob_irq_free(chip);
6227 mv88e6xxx_g1_atu_prob_irq_free(chip);
6228
6229 if (chip->info->g2_irqs > 0)
6230 mv88e6xxx_g2_irq_free(chip);
6231
Andrew Lunn76f38f12018-03-17 20:21:09 +01006232 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006233 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01006234 else
6235 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006236}
6237
6238static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04006239 {
6240 .compatible = "marvell,mv88e6085",
6241 .data = &mv88e6xxx_table[MV88E6085],
6242 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01006243 {
6244 .compatible = "marvell,mv88e6190",
6245 .data = &mv88e6xxx_table[MV88E6190],
6246 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00006247 {
6248 .compatible = "marvell,mv88e6250",
6249 .data = &mv88e6xxx_table[MV88E6250],
6250 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006251 { /* sentinel */ },
6252};
6253
6254MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
6255
6256static struct mdio_driver mv88e6xxx_driver = {
6257 .probe = mv88e6xxx_probe,
6258 .remove = mv88e6xxx_remove,
6259 .mdiodrv.driver = {
6260 .name = "mv88e6085",
6261 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006262 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006263 },
6264};
6265
Andrew Lunn7324d502019-04-27 19:19:10 +02006266mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00006267
6268MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
6269MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
6270MODULE_LICENSE("GPL");