blob: fc9d3875f0995178dd27fae98a4963c4de236509 [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
Russell Kingc9a23562018-05-10 13:17:35 -0700638static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
639 unsigned long *supported,
640 struct phylink_link_state *state)
641{
Russell King6c422e32018-08-09 15:38:39 +0200642 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
643 struct mv88e6xxx_chip *chip = ds->priv;
644
645 /* Allow all the expected bits */
646 phylink_set(mask, Autoneg);
647 phylink_set(mask, Pause);
648 phylink_set_port_modes(mask);
649
650 if (chip->info->ops->phylink_validate)
651 chip->info->ops->phylink_validate(chip, port, mask, state);
652
653 bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
654 bitmap_and(state->advertising, state->advertising, mask,
655 __ETHTOOL_LINK_MODE_MASK_NBITS);
656
657 /* We can only operate at 2500BaseX or 1000BaseX. If requested
658 * to advertise both, only report advertising at 2500BaseX.
659 */
660 phylink_helper_basex_speed(state);
Russell Kingc9a23562018-05-10 13:17:35 -0700661}
662
Russell Kingc9a23562018-05-10 13:17:35 -0700663static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
664 unsigned int mode,
665 const struct phylink_link_state *state)
666{
667 struct mv88e6xxx_chip *chip = ds->priv;
Russell Kingfad58192020-07-19 12:00:35 +0100668 struct mv88e6xxx_port *p;
Russell King64d47d52020-03-14 10:15:38 +0000669 int err;
Russell Kingc9a23562018-05-10 13:17:35 -0700670
Russell Kingfad58192020-07-19 12:00:35 +0100671 p = &chip->ports[port];
672
Russell King64d47d52020-03-14 10:15:38 +0000673 /* FIXME: is this the correct test? If we're in fixed mode on an
674 * internal port, why should we process this any different from
675 * PHY mode? On the other hand, the port may be automedia between
676 * an internal PHY and the serdes...
677 */
Marek Vasutd700ec42018-09-12 00:15:24 +0200678 if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
Russell Kingc9a23562018-05-10 13:17:35 -0700679 return;
680
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000681 mv88e6xxx_reg_lock(chip);
Russell Kingfad58192020-07-19 12:00:35 +0100682 /* In inband mode, the link may come up at any time while the link
683 * is not forced down. Force the link down while we reconfigure the
684 * interface mode.
Russell King64d47d52020-03-14 10:15:38 +0000685 */
Russell Kingfad58192020-07-19 12:00:35 +0100686 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
687 chip->info->ops->port_set_link)
688 chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
689
Russell King64d47d52020-03-14 10:15:38 +0000690 err = mv88e6xxx_port_config_interface(chip, port, state->interface);
Russell Kinga5a68582020-03-14 10:15:43 +0000691 if (err && err != -EOPNOTSUPP)
692 goto err_unlock;
693
694 err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
695 state->advertising);
696 /* FIXME: we should restart negotiation if something changed - which
697 * is something we get if we convert to using phylinks PCS operations.
698 */
699 if (err > 0)
700 err = 0;
701
Russell Kingfad58192020-07-19 12:00:35 +0100702 /* Undo the forced down state above after completing configuration
703 * irrespective of its state on entry, which allows the link to come up.
704 */
705 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
706 chip->info->ops->port_set_link)
707 chip->info->ops->port_set_link(chip, port, LINK_UNFORCED);
708
709 p->interface = state->interface;
710
Russell Kinga5a68582020-03-14 10:15:43 +0000711err_unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000712 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700713
714 if (err && err != -EOPNOTSUPP)
Russell King64d47d52020-03-14 10:15:38 +0000715 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700716}
717
Russell Kingc9a23562018-05-10 13:17:35 -0700718static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
719 unsigned int mode,
720 phy_interface_t interface)
721{
Russell King30c4a5b2020-02-26 10:23:51 +0000722 struct mv88e6xxx_chip *chip = ds->priv;
723 const struct mv88e6xxx_ops *ops;
724 int err = 0;
725
726 ops = chip->info->ops;
727
Russell King5d5b2312020-03-14 10:16:03 +0000728 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200729 if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
Chris Packham4efe76622020-11-24 17:34:37 +1300730 mode == MLO_AN_FIXED) && ops->port_sync_link)
731 err = ops->port_sync_link(chip, port, mode, false);
Russell King5d5b2312020-03-14 10:16:03 +0000732 mv88e6xxx_reg_unlock(chip);
Russell King30c4a5b2020-02-26 10:23:51 +0000733
Russell King5d5b2312020-03-14 10:16:03 +0000734 if (err)
735 dev_err(chip->dev,
736 "p%d: failed to force MAC link down\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700737}
738
739static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
740 unsigned int mode, phy_interface_t interface,
Russell King5b502a72020-02-26 10:23:46 +0000741 struct phy_device *phydev,
742 int speed, int duplex,
743 bool tx_pause, bool rx_pause)
Russell Kingc9a23562018-05-10 13:17:35 -0700744{
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) || mode == MLO_AN_FIXED) {
Russell King30c4a5b2020-02-26 10:23:51 +0000753 /* FIXME: for an automedia port, should we force the link
754 * down here - what if the link comes up due to "other" media
755 * while we're bringing the port up, how is the exclusivity
Russell Kinga5a68582020-03-14 10:15:43 +0000756 * handled in the Marvell hardware? E.g. port 2 on 88E6390
Russell King30c4a5b2020-02-26 10:23:51 +0000757 * shared between internal PHY and Serdes.
758 */
Russell Kinga5a68582020-03-14 10:15:43 +0000759 err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
760 duplex);
761 if (err)
762 goto error;
763
Russell Kingf365c6f2020-03-14 10:15:53 +0000764 if (ops->port_set_speed_duplex) {
765 err = ops->port_set_speed_duplex(chip, port,
766 speed, duplex);
Russell King30c4a5b2020-02-26 10:23:51 +0000767 if (err && err != -EOPNOTSUPP)
768 goto error;
769 }
770
Chris Packham4efe76622020-11-24 17:34:37 +1300771 if (ops->port_sync_link)
772 err = ops->port_sync_link(chip, port, mode, true);
Russell King30c4a5b2020-02-26 10:23:51 +0000773 }
Russell King5d5b2312020-03-14 10:16:03 +0000774error:
775 mv88e6xxx_reg_unlock(chip);
776
777 if (err && err != -EOPNOTSUPP)
778 dev_err(ds->dev,
779 "p%d: failed to configure MAC link up\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700780}
781
Andrew Lunna605a0f2016-11-21 23:26:58 +0100782static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000783{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100784 if (!chip->info->ops->stats_snapshot)
785 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000786
Andrew Lunna605a0f2016-11-21 23:26:58 +0100787 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000788}
789
Andrew Lunne413e7e2015-04-02 04:06:38 +0200790static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100791 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
792 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
793 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
794 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
795 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
796 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
797 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
798 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
799 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
800 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
801 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
802 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
803 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
804 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
805 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
806 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
807 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
808 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
809 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
810 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
811 { "single", 4, 0x14, STATS_TYPE_BANK0, },
812 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
813 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
814 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
815 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
816 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
817 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
818 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
819 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
820 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
821 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
822 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
823 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
824 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
825 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
826 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
827 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
828 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
829 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
830 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
831 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
832 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
833 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
834 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
835 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
836 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
837 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
838 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
839 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
840 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
841 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
842 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
843 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
844 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
845 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
846 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
847 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
848 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
849 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200850};
851
Vivien Didelotfad09c72016-06-21 12:28:20 -0400852static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100853 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100854 int port, u16 bank1_select,
855 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200856{
Andrew Lunn80c46272015-06-20 18:42:30 +0200857 u32 low;
858 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100859 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200860 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200861 u64 value;
862
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100863 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100864 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200865 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
866 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800867 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200868
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200869 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100870 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200871 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
872 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800873 return U64_MAX;
Rasmus Villemoes84b3fd12019-05-29 07:02:11 +0000874 low |= ((u32)reg) << 16;
Andrew Lunn80c46272015-06-20 18:42:30 +0200875 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100876 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100877 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100878 reg = bank1_select;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500879 fallthrough;
Andrew Lunndfafe442016-11-21 23:27:02 +0100880 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100881 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100882 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100883 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100884 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500885 break;
886 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800887 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200888 }
Andrew Lunn6e46e2d2019-02-28 18:14:03 +0100889 value = (((u64)high) << 32) | low;
Andrew Lunn80c46272015-06-20 18:42:30 +0200890 return value;
891}
892
Andrew Lunn436fe172018-03-01 02:02:29 +0100893static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
894 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100895{
896 struct mv88e6xxx_hw_stat *stat;
897 int i, j;
898
899 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
900 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100901 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100902 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
903 ETH_GSTRING_LEN);
904 j++;
905 }
906 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100907
908 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100909}
910
Andrew Lunn436fe172018-03-01 02:02:29 +0100911static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
912 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100913{
Andrew Lunn436fe172018-03-01 02:02:29 +0100914 return mv88e6xxx_stats_get_strings(chip, data,
915 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100916}
917
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000918static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
919 uint8_t *data)
920{
921 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
922}
923
Andrew Lunn436fe172018-03-01 02:02:29 +0100924static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
925 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100926{
Andrew Lunn436fe172018-03-01 02:02:29 +0100927 return mv88e6xxx_stats_get_strings(chip, data,
928 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100929}
930
Andrew Lunn65f60e42018-03-28 23:50:28 +0200931static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
932 "atu_member_violation",
933 "atu_miss_violation",
934 "atu_full_violation",
935 "vtu_member_violation",
936 "vtu_miss_violation",
937};
938
939static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
940{
941 unsigned int i;
942
943 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
944 strlcpy(data + i * ETH_GSTRING_LEN,
945 mv88e6xxx_atu_vtu_stats_strings[i],
946 ETH_GSTRING_LEN);
947}
948
Andrew Lunndfafe442016-11-21 23:27:02 +0100949static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700950 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100951{
Vivien Didelot04bed142016-08-31 18:06:13 -0400952 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100953 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100954
Florian Fainelli89f09042018-04-25 12:12:50 -0700955 if (stringset != ETH_SS_STATS)
956 return;
957
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000958 mv88e6xxx_reg_lock(chip);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100959
Andrew Lunndfafe442016-11-21 23:27:02 +0100960 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100961 count = chip->info->ops->stats_get_strings(chip, data);
962
963 if (chip->info->ops->serdes_get_strings) {
964 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200965 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100966 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100967
Andrew Lunn65f60e42018-03-28 23:50:28 +0200968 data += count * ETH_GSTRING_LEN;
969 mv88e6xxx_atu_vtu_get_strings(data);
970
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000971 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100972}
973
974static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
975 int types)
976{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100977 struct mv88e6xxx_hw_stat *stat;
978 int i, j;
979
980 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
981 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100982 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100983 j++;
984 }
985 return j;
986}
987
Andrew Lunndfafe442016-11-21 23:27:02 +0100988static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
989{
990 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
991 STATS_TYPE_PORT);
992}
993
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000994static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
995{
996 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
997}
998
Andrew Lunndfafe442016-11-21 23:27:02 +0100999static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1000{
1001 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1002 STATS_TYPE_BANK1);
1003}
1004
Florian Fainelli89f09042018-04-25 12:12:50 -07001005static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +01001006{
1007 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +01001008 int serdes_count = 0;
1009 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +01001010
Florian Fainelli89f09042018-04-25 12:12:50 -07001011 if (sset != ETH_SS_STATS)
1012 return 0;
1013
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001014 mv88e6xxx_reg_lock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001015 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +01001016 count = chip->info->ops->stats_get_sset_count(chip);
1017 if (count < 0)
1018 goto out;
1019
1020 if (chip->info->ops->serdes_get_sset_count)
1021 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1022 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +02001023 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +01001024 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001025 goto out;
1026 }
1027 count += serdes_count;
1028 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1029
Andrew Lunn436fe172018-03-01 02:02:29 +01001030out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001031 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001032
Andrew Lunn436fe172018-03-01 02:02:29 +01001033 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +01001034}
1035
Andrew Lunn436fe172018-03-01 02:02:29 +01001036static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1037 uint64_t *data, int types,
1038 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +01001039{
1040 struct mv88e6xxx_hw_stat *stat;
1041 int i, j;
1042
1043 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1044 stat = &mv88e6xxx_hw_stats[i];
1045 if (stat->type & types) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001046 mv88e6xxx_reg_lock(chip);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001047 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1048 bank1_select,
1049 histogram);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001050 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001051
Andrew Lunn052f9472016-11-21 23:27:03 +01001052 j++;
1053 }
1054 }
Andrew Lunn436fe172018-03-01 02:02:29 +01001055 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +01001056}
1057
Andrew Lunn436fe172018-03-01 02:02:29 +01001058static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1059 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001060{
1061 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001062 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001063 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +01001064}
1065
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001066static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1067 uint64_t *data)
1068{
1069 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
1070 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1071}
1072
Andrew Lunn436fe172018-03-01 02:02:29 +01001073static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1074 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001075{
1076 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001077 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001078 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1079 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001080}
1081
Andrew Lunn436fe172018-03-01 02:02:29 +01001082static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1083 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +01001084{
1085 return mv88e6xxx_stats_get_stats(chip, port, data,
1086 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001087 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1088 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001089}
1090
Andrew Lunn65f60e42018-03-28 23:50:28 +02001091static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1092 uint64_t *data)
1093{
1094 *data++ = chip->ports[port].atu_member_violation;
1095 *data++ = chip->ports[port].atu_miss_violation;
1096 *data++ = chip->ports[port].atu_full_violation;
1097 *data++ = chip->ports[port].vtu_member_violation;
1098 *data++ = chip->ports[port].vtu_miss_violation;
1099}
1100
Andrew Lunn052f9472016-11-21 23:27:03 +01001101static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1102 uint64_t *data)
1103{
Andrew Lunn436fe172018-03-01 02:02:29 +01001104 int count = 0;
1105
Andrew Lunn052f9472016-11-21 23:27:03 +01001106 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +01001107 count = chip->info->ops->stats_get_stats(chip, port, data);
1108
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001109 mv88e6xxx_reg_lock(chip);
Andrew Lunn436fe172018-03-01 02:02:29 +01001110 if (chip->info->ops->serdes_get_stats) {
1111 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001112 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +01001113 }
Andrew Lunn65f60e42018-03-28 23:50:28 +02001114 data += count;
1115 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001116 mv88e6xxx_reg_unlock(chip);
Andrew Lunn052f9472016-11-21 23:27:03 +01001117}
1118
Vivien Didelotf81ec902016-05-09 13:22:58 -04001119static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1120 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001121{
Vivien Didelot04bed142016-08-31 18:06:13 -04001122 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001123 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001124
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001125 mv88e6xxx_reg_lock(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001126
Andrew Lunna605a0f2016-11-21 23:26:58 +01001127 ret = mv88e6xxx_stats_snapshot(chip, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001128 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001129
1130 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001131 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001132
1133 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001134
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001135}
Ben Hutchings98e67302011-11-25 14:36:19 +00001136
Vivien Didelotf81ec902016-05-09 13:22:58 -04001137static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001138{
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001139 struct mv88e6xxx_chip *chip = ds->priv;
1140 int len;
1141
1142 len = 32 * sizeof(u16);
1143 if (chip->info->ops->serdes_get_regs_len)
1144 len += chip->info->ops->serdes_get_regs_len(chip, port);
1145
1146 return len;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001147}
1148
Vivien Didelotf81ec902016-05-09 13:22:58 -04001149static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1150 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001151{
Vivien Didelot04bed142016-08-31 18:06:13 -04001152 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001153 int err;
1154 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001155 u16 *p = _p;
1156 int i;
1157
Vivien Didelota5f39322018-12-17 16:05:21 -05001158 regs->version = chip->info->prod_num;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001159
1160 memset(p, 0xff, 32 * sizeof(u16));
1161
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001162 mv88e6xxx_reg_lock(chip);
Vivien Didelot23062512016-05-09 13:22:45 -04001163
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001164 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001165
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001166 err = mv88e6xxx_port_read(chip, port, i, &reg);
1167 if (!err)
1168 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001169 }
Vivien Didelot23062512016-05-09 13:22:45 -04001170
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001171 if (chip->info->ops->serdes_get_regs)
1172 chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1173
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001174 mv88e6xxx_reg_unlock(chip);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001175}
1176
Vivien Didelot08f50062017-08-01 16:32:41 -04001177static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1178 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001179{
Vivien Didelot5480db62017-08-01 16:32:40 -04001180 /* Nothing to do on the port's MAC */
1181 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001182}
1183
Vivien Didelot08f50062017-08-01 16:32:41 -04001184static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1185 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001186{
Vivien Didelot5480db62017-08-01 16:32:40 -04001187 /* Nothing to do on the port's MAC */
1188 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001189}
1190
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001191/* Mask of the local ports allowed to receive frames from a given fabric port */
Vivien Didelote5887a22017-03-30 17:37:11 -04001192static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001193{
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001194 struct dsa_switch *ds = chip->ds;
1195 struct dsa_switch_tree *dst = ds->dst;
Vivien Didelote5887a22017-03-30 17:37:11 -04001196 struct net_device *br;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001197 struct dsa_port *dp;
1198 bool found = false;
Vivien Didelote5887a22017-03-30 17:37:11 -04001199 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001200
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001201 list_for_each_entry(dp, &dst->ports, list) {
1202 if (dp->ds->index == dev && dp->index == port) {
1203 found = true;
1204 break;
1205 }
1206 }
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001207
Vivien Didelote5887a22017-03-30 17:37:11 -04001208 /* Prevent frames from unknown switch or port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001209 if (!found)
Vivien Didelote5887a22017-03-30 17:37:11 -04001210 return 0;
1211
1212 /* Frames from DSA links and CPU ports can egress any local port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001213 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
Vivien Didelote5887a22017-03-30 17:37:11 -04001214 return mv88e6xxx_port_mask(chip);
1215
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001216 br = dp->bridge_dev;
Vivien Didelote5887a22017-03-30 17:37:11 -04001217 pvlan = 0;
1218
1219 /* Frames from user ports can egress any local DSA links and CPU ports,
1220 * as well as any local member of their bridge group.
1221 */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001222 list_for_each_entry(dp, &dst->ports, list)
1223 if (dp->ds == ds &&
1224 (dp->type == DSA_PORT_TYPE_CPU ||
1225 dp->type == DSA_PORT_TYPE_DSA ||
1226 (br && dp->bridge_dev == br)))
1227 pvlan |= BIT(dp->index);
Vivien Didelote5887a22017-03-30 17:37:11 -04001228
1229 return pvlan;
1230}
1231
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001232static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001233{
1234 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001235
1236 /* prevent frames from going back out of the port they came in on */
1237 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001238
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001239 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001240}
1241
Vivien Didelotf81ec902016-05-09 13:22:58 -04001242static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1243 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001244{
Vivien Didelot04bed142016-08-31 18:06:13 -04001245 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001246 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001247
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001248 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001249 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001250 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001251
1252 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001253 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001254}
1255
Vivien Didelot93e18d62018-05-11 17:16:35 -04001256static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1257{
1258 int err;
1259
1260 if (chip->info->ops->ieee_pri_map) {
1261 err = chip->info->ops->ieee_pri_map(chip);
1262 if (err)
1263 return err;
1264 }
1265
1266 if (chip->info->ops->ip_pri_map) {
1267 err = chip->info->ops->ip_pri_map(chip);
1268 if (err)
1269 return err;
1270 }
1271
1272 return 0;
1273}
1274
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001275static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1276{
Vivien Didelotc5f51762019-10-30 22:09:13 -04001277 struct dsa_switch *ds = chip->ds;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001278 int target, port;
1279 int err;
1280
1281 if (!chip->info->global2_addr)
1282 return 0;
1283
1284 /* Initialize the routing port to the 32 possible target devices */
1285 for (target = 0; target < 32; target++) {
Vivien Didelotc5f51762019-10-30 22:09:13 -04001286 port = dsa_routing_port(ds, target);
1287 if (port == ds->num_ports)
1288 port = 0x1f;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001289
1290 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1291 if (err)
1292 return err;
1293 }
1294
Vivien Didelot02317e62018-05-09 11:38:49 -04001295 if (chip->info->ops->set_cascade_port) {
1296 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1297 err = chip->info->ops->set_cascade_port(chip, port);
1298 if (err)
1299 return err;
1300 }
1301
Vivien Didelot23c98912018-05-09 11:38:50 -04001302 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1303 if (err)
1304 return err;
1305
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001306 return 0;
1307}
1308
Vivien Didelotb28f8722018-04-26 21:56:44 -04001309static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1310{
1311 /* Clear all trunk masks and mapping */
1312 if (chip->info->global2_addr)
1313 return mv88e6xxx_g2_trunk_clear(chip);
1314
1315 return 0;
1316}
1317
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001318static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1319{
1320 if (chip->info->ops->rmu_disable)
1321 return chip->info->ops->rmu_disable(chip);
1322
1323 return 0;
1324}
1325
Vivien Didelot9e907d72017-07-17 13:03:43 -04001326static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1327{
1328 if (chip->info->ops->pot_clear)
1329 return chip->info->ops->pot_clear(chip);
1330
1331 return 0;
1332}
1333
Vivien Didelot51c901a2017-07-17 13:03:41 -04001334static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1335{
1336 if (chip->info->ops->mgmt_rsvd2cpu)
1337 return chip->info->ops->mgmt_rsvd2cpu(chip);
1338
1339 return 0;
1340}
1341
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001342static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1343{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001344 int err;
1345
Vivien Didelotdaefc942017-03-11 16:12:54 -05001346 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1347 if (err)
1348 return err;
1349
Rasmus Villemoes49506a92020-12-10 12:06:44 +01001350 /* The chips that have a "learn2all" bit in Global1, ATU
1351 * Control are precisely those whose port registers have a
1352 * Message Port bit in Port Control 1 and hence implement
1353 * ->port_setup_message_port.
1354 */
1355 if (chip->info->ops->port_setup_message_port) {
1356 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1357 if (err)
1358 return err;
1359 }
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001360
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001361 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1362}
1363
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001364static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1365{
1366 int port;
1367 int err;
1368
1369 if (!chip->info->ops->irl_init_all)
1370 return 0;
1371
1372 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1373 /* Disable ingress rate limiting by resetting all per port
1374 * ingress rate limit resources to their initial state.
1375 */
1376 err = chip->info->ops->irl_init_all(chip, port);
1377 if (err)
1378 return err;
1379 }
1380
1381 return 0;
1382}
1383
Vivien Didelot04a69a12017-10-13 14:18:05 -04001384static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1385{
1386 if (chip->info->ops->set_switch_mac) {
1387 u8 addr[ETH_ALEN];
1388
1389 eth_random_addr(addr);
1390
1391 return chip->info->ops->set_switch_mac(chip, addr);
1392 }
1393
1394 return 0;
1395}
1396
Vivien Didelot17a15942017-03-30 17:37:09 -04001397static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1398{
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001399 struct dsa_switch_tree *dst = chip->ds->dst;
1400 struct dsa_switch *ds;
1401 struct dsa_port *dp;
Vivien Didelot17a15942017-03-30 17:37:09 -04001402 u16 pvlan = 0;
1403
1404 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001405 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001406
1407 /* Skip the local source device, which uses in-chip port VLAN */
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001408 if (dev != chip->ds->index) {
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001409 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001410
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001411 ds = dsa_switch_find(dst->index, dev);
1412 dp = ds ? dsa_to_port(ds, port) : NULL;
1413 if (dp && dp->lag_dev) {
1414 /* As the PVT is used to limit flooding of
1415 * FORWARD frames, which use the LAG ID as the
1416 * source port, we must translate dev/port to
1417 * the special "LAG device" in the PVT, using
1418 * the LAG ID as the port number.
1419 */
1420 dev = MV88E6XXX_G2_PVT_ADRR_DEV_TRUNK;
1421 port = dsa_lag_id(dst, dp->lag_dev);
1422 }
1423 }
1424
Vivien Didelot17a15942017-03-30 17:37:09 -04001425 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1426}
1427
Vivien Didelot81228992017-03-30 17:37:08 -04001428static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1429{
Vivien Didelot17a15942017-03-30 17:37:09 -04001430 int dev, port;
1431 int err;
1432
Vivien Didelot81228992017-03-30 17:37:08 -04001433 if (!mv88e6xxx_has_pvt(chip))
1434 return 0;
1435
1436 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1437 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1438 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001439 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1440 if (err)
1441 return err;
1442
1443 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1444 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1445 err = mv88e6xxx_pvt_map(chip, dev, port);
1446 if (err)
1447 return err;
1448 }
1449 }
1450
1451 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001452}
1453
Vivien Didelot749efcb2016-09-22 16:49:24 -04001454static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1455{
1456 struct mv88e6xxx_chip *chip = ds->priv;
1457 int err;
1458
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001459 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001460 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001461 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001462
1463 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001464 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001465}
1466
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001467static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1468{
Tobias Waldekranze545f862020-11-10 19:57:20 +01001469 if (!mv88e6xxx_max_vid(chip))
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001470 return 0;
1471
1472 return mv88e6xxx_g1_vtu_flush(chip);
1473}
1474
Vivien Didelotf1394b782017-05-01 14:05:22 -04001475static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1476 struct mv88e6xxx_vtu_entry *entry)
1477{
1478 if (!chip->info->ops->vtu_getnext)
1479 return -EOPNOTSUPP;
1480
1481 return chip->info->ops->vtu_getnext(chip, entry);
1482}
1483
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001484static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1485 struct mv88e6xxx_vtu_entry *entry)
1486{
1487 if (!chip->info->ops->vtu_loadpurge)
1488 return -EOPNOTSUPP;
1489
1490 return chip->info->ops->vtu_loadpurge(chip, entry);
1491}
1492
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001493int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001494{
Vivien Didelot425d2d32019-08-01 14:36:34 -04001495 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001496 int i, err;
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001497 u16 fid;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001498
1499 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1500
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001501 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001502 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001503 err = mv88e6xxx_port_get_fid(chip, i, &fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001504 if (err)
1505 return err;
1506
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001507 set_bit(fid, fid_bitmap);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001508 }
1509
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001510 /* Set every FID bit used by the VLAN entries */
Tobias Waldekranze545f862020-11-10 19:57:20 +01001511 vlan.vid = mv88e6xxx_max_vid(chip);
Vivien Didelot425d2d32019-08-01 14:36:34 -04001512 vlan.valid = false;
1513
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001514 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001515 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001516 if (err)
1517 return err;
1518
1519 if (!vlan.valid)
1520 break;
1521
1522 set_bit(vlan.fid, fid_bitmap);
Tobias Waldekranze545f862020-11-10 19:57:20 +01001523 } while (vlan.vid < mv88e6xxx_max_vid(chip));
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001524
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001525 return 0;
1526}
1527
1528static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1529{
1530 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1531 int err;
1532
1533 err = mv88e6xxx_fid_map(chip, fid_bitmap);
1534 if (err)
1535 return err;
1536
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001537 /* The reset value 0x000 is used to indicate that multiple address
1538 * databases are not needed. Return the next positive available.
1539 */
1540 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001541 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001542 return -ENOSPC;
1543
1544 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001545 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001546}
1547
Vivien Didelotda9c3592016-02-12 12:09:40 -05001548static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001549 u16 vid)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001550{
Vivien Didelot04bed142016-08-31 18:06:13 -04001551 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001552 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001553 int i, err;
1554
Vladimir Oltean3e85f582021-01-09 02:01:47 +02001555 if (!vid)
1556 return -EOPNOTSUPP;
1557
Andrew Lunndb06ae412017-09-25 23:32:20 +02001558 /* DSA and CPU ports have to be members of multiple vlans */
1559 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1560 return 0;
1561
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001562 vlan.vid = vid - 1;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001563 vlan.valid = false;
1564
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001565 err = mv88e6xxx_vtu_getnext(chip, &vlan);
1566 if (err)
1567 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001568
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001569 if (!vlan.valid)
1570 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001571
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001572 if (vlan.vid != vid)
1573 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001574
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001575 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1576 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1577 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001578
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001579 if (!dsa_to_port(ds, i)->slave)
1580 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001581
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001582 if (vlan.member[i] ==
1583 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1584 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001585
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001586 if (dsa_to_port(ds, i)->bridge_dev ==
1587 dsa_to_port(ds, port)->bridge_dev)
1588 break; /* same bridge, check next VLAN */
Vivien Didelotda9c3592016-02-12 12:09:40 -05001589
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001590 if (!dsa_to_port(ds, i)->bridge_dev)
1591 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001592
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001593 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1594 port, vlan.vid, i,
1595 netdev_name(dsa_to_port(ds, i)->bridge_dev));
1596 return -EOPNOTSUPP;
1597 }
Vivien Didelotda9c3592016-02-12 12:09:40 -05001598
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001599 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001600}
1601
Vivien Didelotf81ec902016-05-09 13:22:58 -04001602static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
Vladimir Oltean89153ed2021-02-13 22:43:19 +02001603 bool vlan_filtering,
1604 struct netlink_ext_ack *extack)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001605{
Vivien Didelot04bed142016-08-31 18:06:13 -04001606 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001607 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1608 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001609 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001610
Vladimir Olteanbae33f22021-01-09 02:01:50 +02001611 if (!mv88e6xxx_max_vid(chip))
1612 return -EOPNOTSUPP;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001613
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001614 mv88e6xxx_reg_lock(chip);
Vivien Didelot385a0992016-11-04 03:23:31 +01001615 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001616 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001617
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001618 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001619}
1620
Vivien Didelot57d32312016-06-20 13:13:58 -04001621static int
1622mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001623 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001624{
Vivien Didelot04bed142016-08-31 18:06:13 -04001625 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001626 int err;
1627
Tobias Waldekranze545f862020-11-10 19:57:20 +01001628 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001629 return -EOPNOTSUPP;
1630
Vivien Didelotda9c3592016-02-12 12:09:40 -05001631 /* If the requested port doesn't belong to the same bridge as the VLAN
1632 * members, do not support it (yet) and fallback to software VLAN.
1633 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001634 mv88e6xxx_reg_lock(chip);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001635 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001636 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001637
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001638 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001639}
1640
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001641static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1642 const unsigned char *addr, u16 vid,
1643 u8 state)
1644{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001645 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001646 struct mv88e6xxx_vtu_entry vlan;
1647 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001648 int err;
1649
1650 /* Null VLAN ID corresponds to the port private database */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001651 if (vid == 0) {
1652 err = mv88e6xxx_port_get_fid(chip, port, &fid);
1653 if (err)
1654 return err;
1655 } else {
1656 vlan.vid = vid - 1;
1657 vlan.valid = false;
1658
1659 err = mv88e6xxx_vtu_getnext(chip, &vlan);
1660 if (err)
1661 return err;
1662
1663 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1664 if (vlan.vid != vid || !vlan.valid)
1665 return -EOPNOTSUPP;
1666
1667 fid = vlan.fid;
1668 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001669
Vivien Didelotd8291a92019-09-07 16:00:47 -04001670 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001671 ether_addr_copy(entry.mac, addr);
1672 eth_addr_dec(entry.mac);
1673
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001674 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001675 if (err)
1676 return err;
1677
1678 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001679 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001680 memset(&entry, 0, sizeof(entry));
1681 ether_addr_copy(entry.mac, addr);
1682 }
1683
1684 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001685 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001686 entry.portvec &= ~BIT(port);
1687 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001688 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001689 } else {
DENG Qingfangf72f2fb2021-01-30 21:43:34 +08001690 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
1691 entry.portvec = BIT(port);
1692 else
1693 entry.portvec |= BIT(port);
1694
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001695 entry.state = state;
1696 }
1697
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001698 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001699}
1700
Vivien Didelotda7dc872019-09-07 16:00:49 -04001701static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1702 const struct mv88e6xxx_policy *policy)
1703{
1704 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1705 enum mv88e6xxx_policy_action action = policy->action;
1706 const u8 *addr = policy->addr;
1707 u16 vid = policy->vid;
1708 u8 state;
1709 int err;
1710 int id;
1711
1712 if (!chip->info->ops->port_set_policy)
1713 return -EOPNOTSUPP;
1714
1715 switch (mapping) {
1716 case MV88E6XXX_POLICY_MAPPING_DA:
1717 case MV88E6XXX_POLICY_MAPPING_SA:
1718 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1719 state = 0; /* Dissociate the port and address */
1720 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1721 is_multicast_ether_addr(addr))
1722 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1723 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1724 is_unicast_ether_addr(addr))
1725 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1726 else
1727 return -EOPNOTSUPP;
1728
1729 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1730 state);
1731 if (err)
1732 return err;
1733 break;
1734 default:
1735 return -EOPNOTSUPP;
1736 }
1737
1738 /* Skip the port's policy clearing if the mapping is still in use */
1739 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1740 idr_for_each_entry(&chip->policies, policy, id)
1741 if (policy->port == port &&
1742 policy->mapping == mapping &&
1743 policy->action != action)
1744 return 0;
1745
1746 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1747}
1748
1749static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1750 struct ethtool_rx_flow_spec *fs)
1751{
1752 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1753 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1754 enum mv88e6xxx_policy_mapping mapping;
1755 enum mv88e6xxx_policy_action action;
1756 struct mv88e6xxx_policy *policy;
1757 u16 vid = 0;
1758 u8 *addr;
1759 int err;
1760 int id;
1761
1762 if (fs->location != RX_CLS_LOC_ANY)
1763 return -EINVAL;
1764
1765 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1766 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1767 else
1768 return -EOPNOTSUPP;
1769
1770 switch (fs->flow_type & ~FLOW_EXT) {
1771 case ETHER_FLOW:
1772 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1773 is_zero_ether_addr(mac_mask->h_source)) {
1774 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1775 addr = mac_entry->h_dest;
1776 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1777 !is_zero_ether_addr(mac_mask->h_source)) {
1778 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1779 addr = mac_entry->h_source;
1780 } else {
1781 /* Cannot support DA and SA mapping in the same rule */
1782 return -EOPNOTSUPP;
1783 }
1784 break;
1785 default:
1786 return -EOPNOTSUPP;
1787 }
1788
1789 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001790 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001791 return -EOPNOTSUPP;
1792 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1793 }
1794
1795 idr_for_each_entry(&chip->policies, policy, id) {
1796 if (policy->port == port && policy->mapping == mapping &&
1797 policy->action == action && policy->vid == vid &&
1798 ether_addr_equal(policy->addr, addr))
1799 return -EEXIST;
1800 }
1801
1802 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1803 if (!policy)
1804 return -ENOMEM;
1805
1806 fs->location = 0;
1807 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1808 GFP_KERNEL);
1809 if (err) {
1810 devm_kfree(chip->dev, policy);
1811 return err;
1812 }
1813
1814 memcpy(&policy->fs, fs, sizeof(*fs));
1815 ether_addr_copy(policy->addr, addr);
1816 policy->mapping = mapping;
1817 policy->action = action;
1818 policy->port = port;
1819 policy->vid = vid;
1820
1821 err = mv88e6xxx_policy_apply(chip, port, policy);
1822 if (err) {
1823 idr_remove(&chip->policies, fs->location);
1824 devm_kfree(chip->dev, policy);
1825 return err;
1826 }
1827
1828 return 0;
1829}
1830
1831static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1832 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1833{
1834 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1835 struct mv88e6xxx_chip *chip = ds->priv;
1836 struct mv88e6xxx_policy *policy;
1837 int err;
1838 int id;
1839
1840 mv88e6xxx_reg_lock(chip);
1841
1842 switch (rxnfc->cmd) {
1843 case ETHTOOL_GRXCLSRLCNT:
1844 rxnfc->data = 0;
1845 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1846 rxnfc->rule_cnt = 0;
1847 idr_for_each_entry(&chip->policies, policy, id)
1848 if (policy->port == port)
1849 rxnfc->rule_cnt++;
1850 err = 0;
1851 break;
1852 case ETHTOOL_GRXCLSRULE:
1853 err = -ENOENT;
1854 policy = idr_find(&chip->policies, fs->location);
1855 if (policy) {
1856 memcpy(fs, &policy->fs, sizeof(*fs));
1857 err = 0;
1858 }
1859 break;
1860 case ETHTOOL_GRXCLSRLALL:
1861 rxnfc->data = 0;
1862 rxnfc->rule_cnt = 0;
1863 idr_for_each_entry(&chip->policies, policy, id)
1864 if (policy->port == port)
1865 rule_locs[rxnfc->rule_cnt++] = id;
1866 err = 0;
1867 break;
1868 default:
1869 err = -EOPNOTSUPP;
1870 break;
1871 }
1872
1873 mv88e6xxx_reg_unlock(chip);
1874
1875 return err;
1876}
1877
1878static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1879 struct ethtool_rxnfc *rxnfc)
1880{
1881 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1882 struct mv88e6xxx_chip *chip = ds->priv;
1883 struct mv88e6xxx_policy *policy;
1884 int err;
1885
1886 mv88e6xxx_reg_lock(chip);
1887
1888 switch (rxnfc->cmd) {
1889 case ETHTOOL_SRXCLSRLINS:
1890 err = mv88e6xxx_policy_insert(chip, port, fs);
1891 break;
1892 case ETHTOOL_SRXCLSRLDEL:
1893 err = -ENOENT;
1894 policy = idr_remove(&chip->policies, fs->location);
1895 if (policy) {
1896 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
1897 err = mv88e6xxx_policy_apply(chip, port, policy);
1898 devm_kfree(chip->dev, policy);
1899 }
1900 break;
1901 default:
1902 err = -EOPNOTSUPP;
1903 break;
1904 }
1905
1906 mv88e6xxx_reg_unlock(chip);
1907
1908 return err;
1909}
1910
Andrew Lunn87fa8862017-11-09 22:29:56 +01001911static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1912 u16 vid)
1913{
1914 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1915 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1916
1917 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1918}
1919
1920static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1921{
1922 int port;
1923 int err;
1924
1925 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1926 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1927 if (err)
1928 return err;
1929 }
1930
1931 return 0;
1932}
1933
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001934static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00001935 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001936{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001937 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001938 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001939 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001940
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001941 vlan.vid = vid - 1;
1942 vlan.valid = false;
1943
1944 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001945 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001946 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001947
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001948 if (vlan.vid != vid || !vlan.valid) {
1949 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001950
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001951 err = mv88e6xxx_atu_new(chip, &vlan.fid);
1952 if (err)
1953 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01001954
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001955 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1956 if (i == port)
1957 vlan.member[i] = member;
1958 else
1959 vlan.member[i] = non_member;
1960
1961 vlan.vid = vid;
1962 vlan.valid = true;
1963
1964 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1965 if (err)
1966 return err;
1967
1968 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
1969 if (err)
1970 return err;
1971 } else if (vlan.member[port] != member) {
1972 vlan.member[port] = member;
1973
1974 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1975 if (err)
1976 return err;
Russell King933b4422020-02-26 17:14:26 +00001977 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001978 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
1979 port, vid);
1980 }
1981
1982 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001983}
1984
Vladimir Oltean1958d582021-01-09 02:01:53 +02001985static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vladimir Oltean31046a52021-02-13 22:43:18 +02001986 const struct switchdev_obj_port_vlan *vlan,
1987 struct netlink_ext_ack *extack)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001988{
Vivien Didelot04bed142016-08-31 18:06:13 -04001989 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001990 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1991 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Russell King933b4422020-02-26 17:14:26 +00001992 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001993 u8 member;
Vladimir Oltean1958d582021-01-09 02:01:53 +02001994 int err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001995
Vladimir Oltean1958d582021-01-09 02:01:53 +02001996 err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
1997 if (err)
1998 return err;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001999
Vivien Didelotc91498e2017-06-07 18:12:13 -04002000 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002001 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002002 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002003 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002004 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002005 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002006
Russell King933b4422020-02-26 17:14:26 +00002007 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
2008 * and then the CPU port. Do not warn for duplicates for the CPU port.
2009 */
2010 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
2011
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002012 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002013
Vladimir Oltean1958d582021-01-09 02:01:53 +02002014 err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
2015 if (err) {
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002016 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2017 vlan->vid, untagged ? 'u' : 't');
Vladimir Oltean1958d582021-01-09 02:01:53 +02002018 goto out;
2019 }
Vivien Didelot76e398a2015-11-01 12:33:55 -05002020
Vladimir Oltean1958d582021-01-09 02:01:53 +02002021 if (pvid) {
2022 err = mv88e6xxx_port_set_pvid(chip, port, vlan->vid);
2023 if (err) {
2024 dev_err(ds->dev, "p%d: failed to set PVID %d\n",
2025 port, vlan->vid);
2026 goto out;
2027 }
2028 }
2029out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002030 mv88e6xxx_reg_unlock(chip);
Vladimir Oltean1958d582021-01-09 02:01:53 +02002031
2032 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002033}
2034
Vivien Didelot521098922019-08-01 14:36:36 -04002035static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2036 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002037{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002038 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002039 int i, err;
2040
Vivien Didelot521098922019-08-01 14:36:36 -04002041 if (!vid)
2042 return -EOPNOTSUPP;
2043
2044 vlan.vid = vid - 1;
2045 vlan.valid = false;
2046
2047 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002048 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002049 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002050
Vivien Didelot521098922019-08-01 14:36:36 -04002051 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2052 * tell switchdev that this VLAN is likely handled in software.
2053 */
2054 if (vlan.vid != vid || !vlan.valid ||
2055 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002056 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002057
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002058 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002059
2060 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002061 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002062 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002063 if (vlan.member[i] !=
2064 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002065 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002066 break;
2067 }
2068 }
2069
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002070 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002071 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002072 return err;
2073
Vivien Didelote606ca32017-03-11 16:12:55 -05002074 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002075}
2076
Vivien Didelotf81ec902016-05-09 13:22:58 -04002077static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2078 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002079{
Vivien Didelot04bed142016-08-31 18:06:13 -04002080 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002081 int err = 0;
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002082 u16 pvid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002083
Tobias Waldekranze545f862020-11-10 19:57:20 +01002084 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04002085 return -EOPNOTSUPP;
2086
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002087 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002088
Vivien Didelot77064f32016-11-04 03:23:30 +01002089 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002090 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002091 goto unlock;
2092
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002093 err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
2094 if (err)
2095 goto unlock;
2096
2097 if (vlan->vid == pvid) {
2098 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002099 if (err)
2100 goto unlock;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002101 }
2102
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002103unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002104 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002105
2106 return err;
2107}
2108
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002109static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2110 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002111{
Vivien Didelot04bed142016-08-31 18:06:13 -04002112 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002113 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002114
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002115 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002116 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2117 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002118 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002119
2120 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002121}
2122
Vivien Didelotf81ec902016-05-09 13:22:58 -04002123static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002124 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002125{
Vivien Didelot04bed142016-08-31 18:06:13 -04002126 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002127 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002128
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002129 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002130 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002131 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002132
Vivien Didelot83dabd12016-08-31 11:50:04 -04002133 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002134}
2135
Vivien Didelot83dabd12016-08-31 11:50:04 -04002136static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2137 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002138 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002139{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002140 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002141 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002142 int err;
2143
Vivien Didelotd8291a92019-09-07 16:00:47 -04002144 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002145 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002146
2147 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002148 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002149 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002150 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002151
Vivien Didelotd8291a92019-09-07 16:00:47 -04002152 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002153 break;
2154
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002155 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002156 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002157
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002158 if (!is_unicast_ether_addr(addr.mac))
2159 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002160
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002161 is_static = (addr.state ==
2162 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2163 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002164 if (err)
2165 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002166 } while (!is_broadcast_ether_addr(addr.mac));
2167
2168 return err;
2169}
2170
Vivien Didelot83dabd12016-08-31 11:50:04 -04002171static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002172 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002173{
Vivien Didelot425d2d32019-08-01 14:36:34 -04002174 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002175 u16 fid;
2176 int err;
2177
2178 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002179 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002180 if (err)
2181 return err;
2182
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002183 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002184 if (err)
2185 return err;
2186
2187 /* Dump VLANs' Filtering Information Databases */
Tobias Waldekranze545f862020-11-10 19:57:20 +01002188 vlan.vid = mv88e6xxx_max_vid(chip);
Vivien Didelot425d2d32019-08-01 14:36:34 -04002189 vlan.valid = false;
2190
Vivien Didelot83dabd12016-08-31 11:50:04 -04002191 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04002192 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002193 if (err)
2194 return err;
2195
2196 if (!vlan.valid)
2197 break;
2198
2199 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002200 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002201 if (err)
2202 return err;
Tobias Waldekranze545f862020-11-10 19:57:20 +01002203 } while (vlan.vid < mv88e6xxx_max_vid(chip));
Vivien Didelot83dabd12016-08-31 11:50:04 -04002204
2205 return err;
2206}
2207
Vivien Didelotf81ec902016-05-09 13:22:58 -04002208static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002209 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002210{
Vivien Didelot04bed142016-08-31 18:06:13 -04002211 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002212 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002213
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002214 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002215 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002216 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002217
2218 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002219}
2220
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002221static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2222 struct net_device *br)
2223{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002224 struct dsa_switch *ds = chip->ds;
2225 struct dsa_switch_tree *dst = ds->dst;
2226 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002227 int err;
2228
Vivien Didelotef2025e2019-10-21 16:51:27 -04002229 list_for_each_entry(dp, &dst->ports, list) {
2230 if (dp->bridge_dev == br) {
2231 if (dp->ds == ds) {
2232 /* This is a local bridge group member,
2233 * remap its Port VLAN Map.
2234 */
2235 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2236 if (err)
2237 return err;
2238 } else {
2239 /* This is an external bridge group member,
2240 * remap its cross-chip Port VLAN Table entry.
2241 */
2242 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2243 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002244 if (err)
2245 return err;
2246 }
2247 }
2248 }
2249
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002250 return 0;
2251}
2252
Vivien Didelotf81ec902016-05-09 13:22:58 -04002253static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002254 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002255{
Vivien Didelot04bed142016-08-31 18:06:13 -04002256 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002257 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002258
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002259 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002260 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002261 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002262
Vivien Didelot466dfa02016-02-26 13:16:05 -05002263 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002264}
2265
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002266static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2267 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002268{
Vivien Didelot04bed142016-08-31 18:06:13 -04002269 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002270
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002271 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002272 if (mv88e6xxx_bridge_map(chip, br) ||
2273 mv88e6xxx_port_vlan_map(chip, port))
2274 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002275 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002276}
2277
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002278static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2279 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002280 int port, struct net_device *br)
2281{
2282 struct mv88e6xxx_chip *chip = ds->priv;
2283 int err;
2284
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002285 if (tree_index != ds->dst->index)
2286 return 0;
2287
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002288 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002289 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002290 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002291
2292 return err;
2293}
2294
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002295static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2296 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002297 int port, struct net_device *br)
2298{
2299 struct mv88e6xxx_chip *chip = ds->priv;
2300
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002301 if (tree_index != ds->dst->index)
2302 return;
2303
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002304 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002305 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002306 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002307 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002308}
2309
Vivien Didelot17e708b2016-12-05 17:30:27 -05002310static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2311{
2312 if (chip->info->ops->reset)
2313 return chip->info->ops->reset(chip);
2314
2315 return 0;
2316}
2317
Vivien Didelot309eca62016-12-05 17:30:26 -05002318static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2319{
2320 struct gpio_desc *gpiod = chip->reset;
2321
2322 /* If there is a GPIO connected to the reset pin, toggle it */
2323 if (gpiod) {
2324 gpiod_set_value_cansleep(gpiod, 1);
2325 usleep_range(10000, 20000);
2326 gpiod_set_value_cansleep(gpiod, 0);
2327 usleep_range(10000, 20000);
Andrew Lunna3dcb3e2020-11-16 08:43:01 -08002328
2329 mv88e6xxx_g1_wait_eeprom_done(chip);
Vivien Didelot309eca62016-12-05 17:30:26 -05002330 }
2331}
2332
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002333static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2334{
2335 int i, err;
2336
2337 /* Set all ports to the Disabled state */
2338 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002339 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002340 if (err)
2341 return err;
2342 }
2343
2344 /* Wait for transmit queues to drain,
2345 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2346 */
2347 usleep_range(2000, 4000);
2348
2349 return 0;
2350}
2351
Vivien Didelotfad09c72016-06-21 12:28:20 -04002352static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002353{
Vivien Didelota935c052016-09-29 12:21:53 -04002354 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002355
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002356 err = mv88e6xxx_disable_ports(chip);
2357 if (err)
2358 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002359
Vivien Didelot309eca62016-12-05 17:30:26 -05002360 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002361
Vivien Didelot17e708b2016-12-05 17:30:27 -05002362 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002363}
2364
Vivien Didelot43145572017-03-11 16:12:59 -05002365static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002366 enum mv88e6xxx_frame_mode frame,
2367 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002368{
2369 int err;
2370
Vivien Didelot43145572017-03-11 16:12:59 -05002371 if (!chip->info->ops->port_set_frame_mode)
2372 return -EOPNOTSUPP;
2373
2374 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002375 if (err)
2376 return err;
2377
Vivien Didelot43145572017-03-11 16:12:59 -05002378 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2379 if (err)
2380 return err;
2381
2382 if (chip->info->ops->port_set_ether_type)
2383 return chip->info->ops->port_set_ether_type(chip, port, etype);
2384
2385 return 0;
2386}
2387
2388static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2389{
2390 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002391 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002392 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002393}
2394
2395static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2396{
2397 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002398 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002399 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002400}
2401
2402static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2403{
2404 return mv88e6xxx_set_port_mode(chip, port,
2405 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002406 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2407 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002408}
2409
2410static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2411{
2412 if (dsa_is_dsa_port(chip->ds, port))
2413 return mv88e6xxx_set_port_mode_dsa(chip, port);
2414
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002415 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002416 return mv88e6xxx_set_port_mode_normal(chip, port);
2417
2418 /* Setup CPU port mode depending on its supported tag format */
2419 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2420 return mv88e6xxx_set_port_mode_dsa(chip, port);
2421
2422 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2423 return mv88e6xxx_set_port_mode_edsa(chip, port);
2424
2425 return -EINVAL;
2426}
2427
Vivien Didelotea698f42017-03-11 16:12:50 -05002428static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2429{
2430 bool message = dsa_is_dsa_port(chip->ds, port);
2431
2432 return mv88e6xxx_port_set_message_port(chip, port, message);
2433}
2434
Vivien Didelot601aeed2017-03-11 16:13:00 -05002435static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2436{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002437 struct dsa_switch *ds = chip->ds;
David S. Miller407308f2019-06-15 13:35:29 -07002438 bool flood;
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002439 int err;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002440
David S. Miller407308f2019-06-15 13:35:29 -07002441 /* Upstream ports flood frames with unknown unicast or multicast DA */
2442 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002443 if (chip->info->ops->port_set_ucast_flood) {
2444 err = chip->info->ops->port_set_ucast_flood(chip, port, flood);
2445 if (err)
2446 return err;
2447 }
2448 if (chip->info->ops->port_set_mcast_flood) {
2449 err = chip->info->ops->port_set_mcast_flood(chip, port, flood);
2450 if (err)
2451 return err;
2452 }
Vivien Didelot601aeed2017-03-11 16:13:00 -05002453
David S. Miller407308f2019-06-15 13:35:29 -07002454 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002455}
2456
Vivien Didelot45de77f2019-08-31 16:18:36 -04002457static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2458{
2459 struct mv88e6xxx_port *mvp = dev_id;
2460 struct mv88e6xxx_chip *chip = mvp->chip;
2461 irqreturn_t ret = IRQ_NONE;
2462 int port = mvp->port;
Pavana Sharma193c5b22021-03-17 14:46:40 +01002463 int lane;
Vivien Didelot45de77f2019-08-31 16:18:36 -04002464
2465 mv88e6xxx_reg_lock(chip);
2466 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002467 if (lane >= 0)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002468 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2469 mv88e6xxx_reg_unlock(chip);
2470
2471 return ret;
2472}
2473
2474static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002475 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002476{
2477 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2478 unsigned int irq;
2479 int err;
2480
2481 /* Nothing to request if this SERDES port has no IRQ */
2482 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2483 if (!irq)
2484 return 0;
2485
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002486 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2487 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2488
Vivien Didelot45de77f2019-08-31 16:18:36 -04002489 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2490 mv88e6xxx_reg_unlock(chip);
2491 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002492 IRQF_ONESHOT, dev_id->serdes_irq_name,
2493 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002494 mv88e6xxx_reg_lock(chip);
2495 if (err)
2496 return err;
2497
2498 dev_id->serdes_irq = irq;
2499
2500 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2501}
2502
2503static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002504 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002505{
2506 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2507 unsigned int irq = dev_id->serdes_irq;
2508 int err;
2509
2510 /* Nothing to free if no IRQ has been requested */
2511 if (!irq)
2512 return 0;
2513
2514 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2515
2516 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2517 mv88e6xxx_reg_unlock(chip);
2518 free_irq(irq, dev_id);
2519 mv88e6xxx_reg_lock(chip);
2520
2521 dev_id->serdes_irq = 0;
2522
2523 return err;
2524}
2525
Andrew Lunn6d917822017-05-26 01:03:21 +02002526static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2527 bool on)
2528{
Pavana Sharma193c5b22021-03-17 14:46:40 +01002529 int lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002530 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002531
Vivien Didelotdc272f62019-08-31 16:18:33 -04002532 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002533 if (lane < 0)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002534 return 0;
2535
2536 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002537 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002538 if (err)
2539 return err;
2540
Vivien Didelot45de77f2019-08-31 16:18:36 -04002541 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002542 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002543 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2544 if (err)
2545 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002546
Vivien Didelotdc272f62019-08-31 16:18:33 -04002547 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002548 }
2549
2550 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002551}
2552
Marek Behún2fda45f2021-03-17 14:46:41 +01002553static int mv88e6xxx_set_egress_port(struct mv88e6xxx_chip *chip,
2554 enum mv88e6xxx_egress_direction direction,
2555 int port)
2556{
2557 int err;
2558
2559 if (!chip->info->ops->set_egress_port)
2560 return -EOPNOTSUPP;
2561
2562 err = chip->info->ops->set_egress_port(chip, direction, port);
2563 if (err)
2564 return err;
2565
2566 if (direction == MV88E6XXX_EGRESS_DIR_INGRESS)
2567 chip->ingress_dest_port = port;
2568 else
2569 chip->egress_dest_port = port;
2570
2571 return 0;
2572}
2573
Vivien Didelotfa371c82017-12-05 15:34:10 -05002574static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2575{
2576 struct dsa_switch *ds = chip->ds;
2577 int upstream_port;
2578 int err;
2579
Vivien Didelot07073c72017-12-05 15:34:13 -05002580 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002581 if (chip->info->ops->port_set_upstream_port) {
2582 err = chip->info->ops->port_set_upstream_port(chip, port,
2583 upstream_port);
2584 if (err)
2585 return err;
2586 }
2587
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002588 if (port == upstream_port) {
2589 if (chip->info->ops->set_cpu_port) {
2590 err = chip->info->ops->set_cpu_port(chip,
2591 upstream_port);
2592 if (err)
2593 return err;
2594 }
2595
Marek Behún2fda45f2021-03-17 14:46:41 +01002596 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002597 MV88E6XXX_EGRESS_DIR_INGRESS,
2598 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002599 if (err && err != -EOPNOTSUPP)
2600 return err;
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002601
Marek Behún2fda45f2021-03-17 14:46:41 +01002602 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002603 MV88E6XXX_EGRESS_DIR_EGRESS,
2604 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002605 if (err && err != -EOPNOTSUPP)
2606 return err;
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002607 }
2608
Vivien Didelotfa371c82017-12-05 15:34:10 -05002609 return 0;
2610}
2611
Vivien Didelotfad09c72016-06-21 12:28:20 -04002612static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002613{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002614 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002615 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002616 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002617
Andrew Lunn7b898462018-08-09 15:38:47 +02002618 chip->ports[port].chip = chip;
2619 chip->ports[port].port = port;
2620
Vivien Didelotd78343d2016-11-04 03:23:36 +01002621 /* MAC Forcing register: don't force link, speed, duplex or flow control
2622 * state to any particular values on physical ports, but force the CPU
2623 * port and all DSA ports to their maximum bandwidth and full duplex.
2624 */
2625 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2626 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2627 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002628 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002629 PHY_INTERFACE_MODE_NA);
2630 else
2631 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2632 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002633 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002634 PHY_INTERFACE_MODE_NA);
2635 if (err)
2636 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002637
2638 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2639 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2640 * tunneling, determine priority by looking at 802.1p and IP
2641 * priority fields (IP prio has precedence), and set STP state
2642 * to Forwarding.
2643 *
2644 * If this is the CPU link, use DSA or EDSA tagging depending
2645 * on which tagging mode was configured.
2646 *
2647 * If this is a link to another switch, use DSA tagging mode.
2648 *
2649 * If this is the upstream port for this switch, enable
2650 * forwarding of unknown unicasts and multicasts.
2651 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002652 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2653 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2654 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2655 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002656 if (err)
2657 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002658
Vivien Didelot601aeed2017-03-11 16:13:00 -05002659 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002660 if (err)
2661 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002662
Vivien Didelot601aeed2017-03-11 16:13:00 -05002663 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002664 if (err)
2665 return err;
2666
Vivien Didelot8efdda42015-08-13 12:52:23 -04002667 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002668 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002669 * untagged frames on this port, do a destination address lookup on all
2670 * received packets as usual, disable ARP mirroring and don't send a
2671 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002672 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002673 err = mv88e6xxx_port_set_map_da(chip, port);
2674 if (err)
2675 return err;
2676
Vivien Didelotfa371c82017-12-05 15:34:10 -05002677 err = mv88e6xxx_setup_upstream_port(chip, port);
2678 if (err)
2679 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002680
Andrew Lunna23b2962017-02-04 20:15:28 +01002681 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002682 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002683 if (err)
2684 return err;
2685
Vivien Didelotcd782652017-06-08 18:34:13 -04002686 if (chip->info->ops->port_set_jumbo_size) {
2687 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002688 if (err)
2689 return err;
2690 }
2691
Andrew Lunn54d792f2015-05-06 01:09:47 +02002692 /* Port Association Vector: when learning source addresses
2693 * of packets, add the address to the address database using
2694 * a port bitmap that has only the bit for this port set and
2695 * the other bits clear.
2696 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002697 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002698 /* Disable learning for CPU port */
2699 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002700 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002701
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002702 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2703 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002704 if (err)
2705 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002706
2707 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002708 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2709 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002710 if (err)
2711 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002712
Vivien Didelot08984322017-06-08 18:34:12 -04002713 if (chip->info->ops->port_pause_limit) {
2714 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002715 if (err)
2716 return err;
2717 }
2718
Vivien Didelotc8c94892017-03-11 16:13:01 -05002719 if (chip->info->ops->port_disable_learn_limit) {
2720 err = chip->info->ops->port_disable_learn_limit(chip, port);
2721 if (err)
2722 return err;
2723 }
2724
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002725 if (chip->info->ops->port_disable_pri_override) {
2726 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002727 if (err)
2728 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002729 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002730
Andrew Lunnef0a7312016-12-03 04:35:16 +01002731 if (chip->info->ops->port_tag_remap) {
2732 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002733 if (err)
2734 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002735 }
2736
Andrew Lunnef70b112016-12-03 04:45:18 +01002737 if (chip->info->ops->port_egress_rate_limiting) {
2738 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002739 if (err)
2740 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002741 }
2742
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002743 if (chip->info->ops->port_setup_message_port) {
2744 err = chip->info->ops->port_setup_message_port(chip, port);
2745 if (err)
2746 return err;
2747 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002748
Vivien Didelot207afda2016-04-14 14:42:09 -04002749 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002750 * database, and allow bidirectional communication between the
2751 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002752 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002753 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002754 if (err)
2755 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002756
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002757 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002758 if (err)
2759 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002760
2761 /* Default VLAN ID and priority: don't set a default VLAN
2762 * ID, and set the default packet priority to zero.
2763 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002764 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002765}
2766
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002767static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
2768{
2769 struct mv88e6xxx_chip *chip = ds->priv;
2770
2771 if (chip->info->ops->port_set_jumbo_size)
2772 return 10240;
Chris Packham1baf0fa2020-07-24 11:21:22 +12002773 else if (chip->info->ops->set_max_frame_size)
2774 return 1632;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002775 return 1522;
2776}
2777
2778static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
2779{
2780 struct mv88e6xxx_chip *chip = ds->priv;
2781 int ret = 0;
2782
2783 mv88e6xxx_reg_lock(chip);
2784 if (chip->info->ops->port_set_jumbo_size)
2785 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12002786 else if (chip->info->ops->set_max_frame_size)
2787 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002788 else
2789 if (new_mtu > 1522)
2790 ret = -EINVAL;
2791 mv88e6xxx_reg_unlock(chip);
2792
2793 return ret;
2794}
2795
Andrew Lunn04aca992017-05-26 01:03:24 +02002796static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2797 struct phy_device *phydev)
2798{
2799 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002800 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002801
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002802 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002803 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002804 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002805
2806 return err;
2807}
2808
Andrew Lunn75104db2019-02-24 20:44:43 +01002809static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02002810{
2811 struct mv88e6xxx_chip *chip = ds->priv;
2812
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002813 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002814 if (mv88e6xxx_serdes_power(chip, port, false))
2815 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002816 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002817}
2818
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002819static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2820 unsigned int ageing_time)
2821{
Vivien Didelot04bed142016-08-31 18:06:13 -04002822 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002823 int err;
2824
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002825 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05002826 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002827 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002828
2829 return err;
2830}
2831
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002832static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002833{
2834 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002835
Andrew Lunnde2273872016-11-21 23:27:01 +01002836 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002837 if (chip->info->ops->stats_set_histogram) {
2838 err = chip->info->ops->stats_set_histogram(chip);
2839 if (err)
2840 return err;
2841 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002842
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002843 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002844}
2845
Andrew Lunnea890982019-01-09 00:24:03 +01002846/* Check if the errata has already been applied. */
2847static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
2848{
2849 int port;
2850 int err;
2851 u16 val;
2852
2853 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002854 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01002855 if (err) {
2856 dev_err(chip->dev,
2857 "Error reading hidden register: %d\n", err);
2858 return false;
2859 }
2860 if (val != 0x01c0)
2861 return false;
2862 }
2863
2864 return true;
2865}
2866
2867/* The 6390 copper ports have an errata which require poking magic
2868 * values into undocumented hidden registers and then performing a
2869 * software reset.
2870 */
2871static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
2872{
2873 int port;
2874 int err;
2875
2876 if (mv88e6390_setup_errata_applied(chip))
2877 return 0;
2878
2879 /* Set the ports into blocking mode */
2880 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2881 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
2882 if (err)
2883 return err;
2884 }
2885
2886 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002887 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01002888 if (err)
2889 return err;
2890 }
2891
2892 return mv88e6xxx_software_reset(chip);
2893}
2894
Andrew Lunn23e8b472019-10-25 01:03:52 +02002895static void mv88e6xxx_teardown(struct dsa_switch *ds)
2896{
2897 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002898 dsa_devlink_resources_unregister(ds);
Andrew Lunnbfb25542020-09-18 21:11:07 +02002899 mv88e6xxx_teardown_devlink_regions(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02002900}
2901
Vivien Didelotf81ec902016-05-09 13:22:58 -04002902static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002903{
Vivien Didelot04bed142016-08-31 18:06:13 -04002904 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002905 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04002906 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002907 int i;
2908
Vivien Didelotfad09c72016-06-21 12:28:20 -04002909 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002910 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002911
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002912 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002913
Andrew Lunnea890982019-01-09 00:24:03 +01002914 if (chip->info->ops->setup_errata) {
2915 err = chip->info->ops->setup_errata(chip);
2916 if (err)
2917 goto unlock;
2918 }
2919
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002920 /* Cache the cmode of each port. */
2921 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2922 if (chip->info->ops->port_get_cmode) {
2923 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
2924 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03002925 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002926
2927 chip->ports[i].cmode = cmode;
2928 }
2929 }
2930
Vivien Didelot97299342016-07-18 20:45:30 -04002931 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002932 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04002933 if (dsa_is_unused_port(ds, i))
2934 continue;
2935
Hubert Feursteinc8574862019-07-31 10:23:48 +02002936 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04002937 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02002938 dev_err(chip->dev, "port %d is invalid\n", i);
2939 err = -EINVAL;
2940 goto unlock;
2941 }
2942
Vivien Didelot97299342016-07-18 20:45:30 -04002943 err = mv88e6xxx_setup_port(chip, i);
2944 if (err)
2945 goto unlock;
2946 }
2947
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002948 err = mv88e6xxx_irl_setup(chip);
2949 if (err)
2950 goto unlock;
2951
Vivien Didelot04a69a12017-10-13 14:18:05 -04002952 err = mv88e6xxx_mac_setup(chip);
2953 if (err)
2954 goto unlock;
2955
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002956 err = mv88e6xxx_phy_setup(chip);
2957 if (err)
2958 goto unlock;
2959
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002960 err = mv88e6xxx_vtu_setup(chip);
2961 if (err)
2962 goto unlock;
2963
Vivien Didelot81228992017-03-30 17:37:08 -04002964 err = mv88e6xxx_pvt_setup(chip);
2965 if (err)
2966 goto unlock;
2967
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002968 err = mv88e6xxx_atu_setup(chip);
2969 if (err)
2970 goto unlock;
2971
Andrew Lunn87fa8862017-11-09 22:29:56 +01002972 err = mv88e6xxx_broadcast_setup(chip, 0);
2973 if (err)
2974 goto unlock;
2975
Vivien Didelot9e907d72017-07-17 13:03:43 -04002976 err = mv88e6xxx_pot_setup(chip);
2977 if (err)
2978 goto unlock;
2979
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002980 err = mv88e6xxx_rmu_setup(chip);
2981 if (err)
2982 goto unlock;
2983
Vivien Didelot51c901a2017-07-17 13:03:41 -04002984 err = mv88e6xxx_rsvd2cpu_setup(chip);
2985 if (err)
2986 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002987
Vivien Didelotb28f8722018-04-26 21:56:44 -04002988 err = mv88e6xxx_trunk_setup(chip);
2989 if (err)
2990 goto unlock;
2991
Vivien Didelotc7f047b2018-04-26 21:56:45 -04002992 err = mv88e6xxx_devmap_setup(chip);
2993 if (err)
2994 goto unlock;
2995
Vivien Didelot93e18d62018-05-11 17:16:35 -04002996 err = mv88e6xxx_pri_setup(chip);
2997 if (err)
2998 goto unlock;
2999
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003000 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003001 if (chip->info->ptp_support) {
3002 err = mv88e6xxx_ptp_setup(chip);
3003 if (err)
3004 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003005
3006 err = mv88e6xxx_hwtstamp_setup(chip);
3007 if (err)
3008 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003009 }
3010
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003011 err = mv88e6xxx_stats_setup(chip);
3012 if (err)
3013 goto unlock;
3014
Vivien Didelot6b17e862015-08-13 12:52:18 -04003015unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003016 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02003017
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003018 if (err)
3019 return err;
3020
3021 /* Have to be called without holding the register lock, since
3022 * they take the devlink lock, and we later take the locks in
3023 * the reverse order when getting/setting parameters or
3024 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02003025 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003026 err = mv88e6xxx_setup_devlink_resources(ds);
3027 if (err)
3028 return err;
3029
3030 err = mv88e6xxx_setup_devlink_params(ds);
3031 if (err)
Andrew Lunnbfb25542020-09-18 21:11:07 +02003032 goto out_resources;
3033
3034 err = mv88e6xxx_setup_devlink_regions(ds);
3035 if (err)
3036 goto out_params;
3037
3038 return 0;
3039
3040out_params:
3041 mv88e6xxx_teardown_devlink_params(ds);
3042out_resources:
3043 dsa_devlink_resources_unregister(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003044
3045 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003046}
3047
Vivien Didelote57e5e72016-08-15 17:19:00 -04003048static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003049{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003050 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3051 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003052 u16 val;
3053 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003054
Andrew Lunnee26a222017-01-24 14:53:48 +01003055 if (!chip->info->ops->phy_read)
3056 return -EOPNOTSUPP;
3057
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003058 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003059 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003060 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003061
Andrew Lunnda9f3302017-02-01 03:40:05 +01003062 if (reg == MII_PHYSID2) {
Andrew Lunnddc49ac2018-11-12 18:51:01 +01003063 /* Some internal PHYs don't have a model number. */
3064 if (chip->info->family != MV88E6XXX_FAMILY_6165)
3065 /* Then there is the 6165 family. It gets is
3066 * PHYs correct. But it can also have two
3067 * SERDES interfaces in the PHY address
3068 * space. And these don't have a model
3069 * number. But they are not PHYs, so we don't
3070 * want to give them something a PHY driver
3071 * will recognise.
3072 *
3073 * Use the mv88e6390 family model number
3074 * instead, for anything which really could be
3075 * a PHY,
3076 */
3077 if (!(val & 0x3f0))
3078 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003079 }
3080
Vivien Didelote57e5e72016-08-15 17:19:00 -04003081 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003082}
3083
Vivien Didelote57e5e72016-08-15 17:19:00 -04003084static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003085{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003086 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3087 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003088 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003089
Andrew Lunnee26a222017-01-24 14:53:48 +01003090 if (!chip->info->ops->phy_write)
3091 return -EOPNOTSUPP;
3092
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003093 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003094 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003095 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003096
3097 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003098}
3099
Vivien Didelotfad09c72016-06-21 12:28:20 -04003100static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003101 struct device_node *np,
3102 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003103{
3104 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003105 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003106 struct mii_bus *bus;
3107 int err;
3108
Andrew Lunn2510bab2018-02-22 01:51:49 +01003109 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003110 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003111 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003112 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003113
3114 if (err)
3115 return err;
3116 }
3117
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003118 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003119 if (!bus)
3120 return -ENOMEM;
3121
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003122 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003123 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003124 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003125 INIT_LIST_HEAD(&mdio_bus->list);
3126 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003127
Andrew Lunnb516d452016-06-04 21:17:06 +02003128 if (np) {
3129 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003130 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003131 } else {
3132 bus->name = "mv88e6xxx SMI";
3133 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3134 }
3135
3136 bus->read = mv88e6xxx_mdio_read;
3137 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003138 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003139
Andrew Lunn6f882842018-03-17 20:32:05 +01003140 if (!external) {
3141 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3142 if (err)
3143 return err;
3144 }
3145
Florian Fainelli00e798c2018-05-15 16:56:19 -07003146 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003147 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003148 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003149 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003150 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003151 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003152
3153 if (external)
3154 list_add_tail(&mdio_bus->list, &chip->mdios);
3155 else
3156 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003157
3158 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003159}
3160
Andrew Lunn3126aee2017-12-07 01:05:57 +01003161static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3162
3163{
3164 struct mv88e6xxx_mdio_bus *mdio_bus;
3165 struct mii_bus *bus;
3166
3167 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3168 bus = mdio_bus->bus;
3169
Andrew Lunn6f882842018-03-17 20:32:05 +01003170 if (!mdio_bus->external)
3171 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3172
Andrew Lunn3126aee2017-12-07 01:05:57 +01003173 mdiobus_unregister(bus);
3174 }
3175}
3176
Andrew Lunna3c53be52017-01-24 14:53:50 +01003177static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3178 struct device_node *np)
3179{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003180 struct device_node *child;
3181 int err;
3182
3183 /* Always register one mdio bus for the internal/default mdio
3184 * bus. This maybe represented in the device tree, but is
3185 * optional.
3186 */
3187 child = of_get_child_by_name(np, "mdio");
3188 err = mv88e6xxx_mdio_register(chip, child, false);
3189 if (err)
3190 return err;
3191
3192 /* Walk the device tree, and see if there are any other nodes
3193 * which say they are compatible with the external mdio
3194 * bus.
3195 */
3196 for_each_available_child_of_node(np, child) {
Andrew Lunnceb96fa2020-09-01 04:32:57 +02003197 if (of_device_is_compatible(
3198 child, "marvell,mv88e6xxx-mdio-external")) {
Andrew Lunna3c53be52017-01-24 14:53:50 +01003199 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003200 if (err) {
3201 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303202 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003203 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003204 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003205 }
3206 }
3207
3208 return 0;
3209}
3210
Vivien Didelot855b1932016-07-20 18:18:35 -04003211static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3212{
Vivien Didelot04bed142016-08-31 18:06:13 -04003213 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003214
3215 return chip->eeprom_len;
3216}
3217
Vivien Didelot855b1932016-07-20 18:18:35 -04003218static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3219 struct ethtool_eeprom *eeprom, u8 *data)
3220{
Vivien Didelot04bed142016-08-31 18:06:13 -04003221 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003222 int err;
3223
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003224 if (!chip->info->ops->get_eeprom)
3225 return -EOPNOTSUPP;
3226
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003227 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003228 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003229 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003230
3231 if (err)
3232 return err;
3233
3234 eeprom->magic = 0xc3ec4951;
3235
3236 return 0;
3237}
3238
Vivien Didelot855b1932016-07-20 18:18:35 -04003239static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3240 struct ethtool_eeprom *eeprom, u8 *data)
3241{
Vivien Didelot04bed142016-08-31 18:06:13 -04003242 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003243 int err;
3244
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003245 if (!chip->info->ops->set_eeprom)
3246 return -EOPNOTSUPP;
3247
Vivien Didelot855b1932016-07-20 18:18:35 -04003248 if (eeprom->magic != 0xc3ec4951)
3249 return -EINVAL;
3250
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003251 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003252 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003253 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003254
3255 return err;
3256}
3257
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003258static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003259 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003260 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3261 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003262 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003263 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003264 .phy_read = mv88e6185_phy_ppu_read,
3265 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003266 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003267 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003268 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003269 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003270 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003271 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3272 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003273 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003274 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003275 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003276 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003277 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003278 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003279 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003280 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003281 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003282 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3283 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003284 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003285 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3286 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003287 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003288 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003289 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003290 .ppu_enable = mv88e6185_g1_ppu_enable,
3291 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003292 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003293 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003294 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003295 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003296 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003297 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003298};
3299
3300static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003301 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003302 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3303 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003304 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003305 .phy_read = mv88e6185_phy_ppu_read,
3306 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003307 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003308 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003309 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003310 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003311 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3312 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunna23b2962017-02-04 20:15:28 +01003313 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003314 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003315 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003316 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003317 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003318 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3319 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003320 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003321 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003322 .serdes_power = mv88e6185_serdes_power,
3323 .serdes_get_lane = mv88e6185_serdes_get_lane,
3324 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003325 .ppu_enable = mv88e6185_g1_ppu_enable,
3326 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003327 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003328 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003329 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003330 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003331 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003332};
3333
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003334static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003335 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003336 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3337 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003338 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003339 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3340 .phy_read = mv88e6xxx_g2_smi_phy_read,
3341 .phy_write = mv88e6xxx_g2_smi_phy_write,
3342 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003343 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003344 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003345 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003346 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003347 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3348 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003349 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003350 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003351 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003352 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003353 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003354 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003355 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003356 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003357 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003358 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3359 .stats_get_strings = mv88e6095_stats_get_strings,
3360 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003361 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3362 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003363 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003364 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003365 .serdes_power = mv88e6185_serdes_power,
3366 .serdes_get_lane = mv88e6185_serdes_get_lane,
3367 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Chris Packham5c19bc82020-11-24 17:34:39 +13003368 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3369 .serdes_irq_enable = mv88e6097_serdes_irq_enable,
3370 .serdes_irq_status = mv88e6097_serdes_irq_status,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003371 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003372 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003373 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003374 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003375 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003376 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003377 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003378};
3379
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003380static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003381 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003382 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3383 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003384 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003385 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003386 .phy_read = mv88e6xxx_g2_smi_phy_read,
3387 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003388 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003389 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003390 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003391 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003392 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3393 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003394 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003395 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003396 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003397 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003398 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003399 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003400 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3401 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003402 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003403 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3404 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003405 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003406 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003407 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003408 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003409 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3410 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003411 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003412 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003413 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003414 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003415};
3416
3417static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003418 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003419 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3420 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003421 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003422 .phy_read = mv88e6185_phy_ppu_read,
3423 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003424 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003425 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003426 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003427 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003428 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003429 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3430 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003431 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003432 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003433 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003434 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003435 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003436 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003437 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003438 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003439 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003440 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003441 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3442 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003443 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003444 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3445 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003446 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003447 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003448 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003449 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003450 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003451 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003452 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003453 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003454 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003455};
3456
Vivien Didelot990e27b2017-03-28 13:50:32 -04003457static const struct mv88e6xxx_ops mv88e6141_ops = {
3458 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003459 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3460 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003461 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003462 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3463 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3464 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3465 .phy_read = mv88e6xxx_g2_smi_phy_read,
3466 .phy_write = mv88e6xxx_g2_smi_phy_write,
3467 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003468 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003469 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003470 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003471 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003472 .port_tag_remap = mv88e6095_port_tag_remap,
3473 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003474 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3475 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003476 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003477 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003478 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003479 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003480 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3481 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003482 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003483 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003484 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003485 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003486 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003487 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3488 .stats_get_strings = mv88e6320_stats_get_strings,
3489 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003490 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3491 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003492 .watchdog_ops = &mv88e6390_watchdog_ops,
3493 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003494 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003495 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003496 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003497 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003498 .serdes_power = mv88e6390_serdes_power,
3499 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003500 /* Check status register pause & lpa register */
3501 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3502 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3503 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3504 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003505 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003506 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003507 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003508 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003509 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003510};
3511
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003512static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003513 /* MV88E6XXX_FAMILY_6165 */
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 Didelotb073d4e2016-09-29 12:22:01 -04003517 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003518 .phy_read = mv88e6xxx_g2_smi_phy_read,
3519 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003520 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003521 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003522 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003523 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003524 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003525 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3526 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003527 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003528 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003529 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003530 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003531 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003532 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003533 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003534 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003535 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003536 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003537 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3538 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003539 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003540 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3541 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003542 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003543 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003544 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003545 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003546 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3547 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003548 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003549 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003550 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003551 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003552 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003553};
3554
3555static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003556 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003557 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3558 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003559 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003560 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003561 .phy_read = mv88e6165_phy_read,
3562 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003563 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003564 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003565 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003566 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003567 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003568 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003569 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003570 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003571 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003572 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3573 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003574 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003575 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3576 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003577 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003578 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003579 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003580 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003581 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3582 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003583 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003584 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003585 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003586 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003587 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003588};
3589
3590static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003591 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003592 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3593 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003594 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003595 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003596 .phy_read = mv88e6xxx_g2_smi_phy_read,
3597 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003598 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003599 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003600 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003601 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003602 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003603 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003604 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3605 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003606 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003607 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003608 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003609 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003610 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003611 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003612 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003613 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003614 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003615 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003616 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3617 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003618 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003619 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3620 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003621 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003622 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003623 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003624 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003625 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3626 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003627 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003628 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003629 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003630};
3631
3632static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003633 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003634 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3635 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003636 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003637 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3638 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003639 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003640 .phy_read = mv88e6xxx_g2_smi_phy_read,
3641 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003642 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003643 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003644 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003645 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003646 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003647 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003648 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003649 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3650 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003651 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003652 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003653 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003654 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003655 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003656 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003657 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003658 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003659 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003660 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003661 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3662 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003663 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003664 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3665 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003666 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003667 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003668 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003669 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003670 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003671 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3672 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003673 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003674 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003675 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003676 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3677 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3678 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3679 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003680 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003681 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3682 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003683 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003684 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003685};
3686
3687static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003688 /* MV88E6XXX_FAMILY_6351 */
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 Didelotb073d4e2016-09-29 12:22:01 -04003692 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003693 .phy_read = mv88e6xxx_g2_smi_phy_read,
3694 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003695 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003696 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003697 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003698 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003699 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003700 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003701 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3702 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003703 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003704 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003705 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003706 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003707 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003708 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003709 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003710 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003711 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003712 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003713 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3714 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003715 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003716 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3717 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003718 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003719 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003720 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003721 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003722 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3723 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003724 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003725 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003726 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003727};
3728
3729static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003730 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003731 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3732 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003733 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003734 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3735 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003736 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003737 .phy_read = mv88e6xxx_g2_smi_phy_read,
3738 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003739 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003740 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003741 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003742 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003743 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003744 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003745 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003746 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3747 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003748 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003749 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003750 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003751 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003752 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003753 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003754 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003755 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003756 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003757 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003758 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3759 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003760 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003761 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3762 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003763 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003764 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003765 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003766 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003767 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003768 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3769 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003770 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003771 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003772 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003773 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3774 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3775 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3776 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003777 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003778 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003779 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003780 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003781 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3782 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003783 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003784 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003785};
3786
3787static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003788 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003789 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3790 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003791 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003792 .phy_read = mv88e6185_phy_ppu_read,
3793 .phy_write = mv88e6185_phy_ppu_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 = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003796 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003797 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003798 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3799 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunnef70b112016-12-03 04:45:18 +01003800 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003801 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02003802 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003803 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003804 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003805 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003806 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003807 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3808 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003809 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003810 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3811 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003812 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003813 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003814 .serdes_power = mv88e6185_serdes_power,
3815 .serdes_get_lane = mv88e6185_serdes_get_lane,
3816 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelot02317e62018-05-09 11:38:49 -04003817 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003818 .ppu_enable = mv88e6185_g1_ppu_enable,
3819 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003820 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003821 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003822 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003823 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003824 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003825};
3826
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003827static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003828 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003829 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003830 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003831 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3832 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003833 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3834 .phy_read = mv88e6xxx_g2_smi_phy_read,
3835 .phy_write = mv88e6xxx_g2_smi_phy_write,
3836 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003837 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003838 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003839 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003840 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003841 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003842 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003843 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003844 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3845 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003846 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003847 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003848 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003849 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003850 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003851 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003852 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003853 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003854 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003855 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003856 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3857 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003858 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003859 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3860 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003861 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003862 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003863 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003864 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003865 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003866 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3867 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003868 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3869 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003870 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003871 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003872 /* Check status register pause & lpa register */
3873 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3874 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3875 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3876 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003877 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003878 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003879 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003880 .serdes_get_strings = mv88e6390_serdes_get_strings,
3881 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003882 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3883 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003884 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003885 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003886};
3887
3888static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003889 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003890 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003891 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003892 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3893 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003894 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3895 .phy_read = mv88e6xxx_g2_smi_phy_read,
3896 .phy_write = mv88e6xxx_g2_smi_phy_write,
3897 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003898 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003899 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003900 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003901 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003902 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003903 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003904 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003905 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3906 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003907 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003908 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003909 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003910 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003911 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003912 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003913 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003914 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003915 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003916 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003917 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3918 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003919 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003920 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3921 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003922 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003923 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003924 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003925 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003926 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003927 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3928 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003929 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3930 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003931 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003932 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003933 /* Check status register pause & lpa register */
3934 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3935 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3936 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3937 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003938 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003939 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003940 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003941 .serdes_get_strings = mv88e6390_serdes_get_strings,
3942 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003943 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3944 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003945 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003946 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003947};
3948
3949static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003950 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003951 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003952 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003953 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3954 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003955 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3956 .phy_read = mv88e6xxx_g2_smi_phy_read,
3957 .phy_write = mv88e6xxx_g2_smi_phy_write,
3958 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003959 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003960 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003961 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003962 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003963 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003964 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003965 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3966 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003967 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003968 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003969 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003970 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003971 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003972 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003973 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003974 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003975 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003976 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3977 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003978 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003979 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3980 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003981 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003982 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003983 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003984 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003985 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003986 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3987 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003988 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3989 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003990 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003991 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003992 /* Check status register pause & lpa register */
3993 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3994 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3995 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3996 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003997 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003998 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003999 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004000 .serdes_get_strings = mv88e6390_serdes_get_strings,
4001 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004002 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4003 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004004 .avb_ops = &mv88e6390_avb_ops,
4005 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004006 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004007};
4008
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004009static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004010 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004011 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4012 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004013 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004014 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4015 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004016 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004017 .phy_read = mv88e6xxx_g2_smi_phy_read,
4018 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004019 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004020 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004021 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004022 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004023 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004024 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004025 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004026 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4027 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004028 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004029 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004030 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004031 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004032 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004033 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004034 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004035 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004036 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004037 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004038 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4039 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004040 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004041 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4042 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004043 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004044 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004045 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004046 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004047 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004048 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4049 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004050 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004051 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004052 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004053 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4054 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4055 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4056 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004057 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004058 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004059 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004060 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004061 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4062 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004063 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004064 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004065 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004066 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004067};
4068
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004069static const struct mv88e6xxx_ops mv88e6250_ops = {
4070 /* MV88E6XXX_FAMILY_6250 */
4071 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4072 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4073 .irl_init_all = mv88e6352_g2_irl_init_all,
4074 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4075 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4076 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4077 .phy_read = mv88e6xxx_g2_smi_phy_read,
4078 .phy_write = mv88e6xxx_g2_smi_phy_write,
4079 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004080 .port_sync_link = mv88e6xxx_port_sync_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004081 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004082 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004083 .port_tag_remap = mv88e6095_port_tag_remap,
4084 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004085 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4086 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004087 .port_set_ether_type = mv88e6351_port_set_ether_type,
4088 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4089 .port_pause_limit = mv88e6097_port_pause_limit,
4090 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004091 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4092 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4093 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4094 .stats_get_strings = mv88e6250_stats_get_strings,
4095 .stats_get_stats = mv88e6250_stats_get_stats,
4096 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4097 .set_egress_port = mv88e6095_g1_set_egress_port,
4098 .watchdog_ops = &mv88e6250_watchdog_ops,
4099 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4100 .pot_clear = mv88e6xxx_g2_pot_clear,
4101 .reset = mv88e6250_g1_reset,
Rasmus Villemoes67c9ed12021-01-25 16:04:48 +01004102 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Rasmus Villemoesb28f3f32021-01-25 16:04:49 +01004103 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004104 .avb_ops = &mv88e6352_avb_ops,
4105 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004106 .phylink_validate = mv88e6065_phylink_validate,
4107};
4108
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004109static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004110 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004111 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004112 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004113 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4114 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004115 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4116 .phy_read = mv88e6xxx_g2_smi_phy_read,
4117 .phy_write = mv88e6xxx_g2_smi_phy_write,
4118 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004119 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004120 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004121 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004122 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004123 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004124 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004125 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004126 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4127 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004128 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004129 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004130 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004131 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004132 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004133 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004134 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004135 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004136 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004137 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4138 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004139 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004140 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4141 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004142 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004143 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004144 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004145 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004146 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004147 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4148 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004149 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4150 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004151 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004152 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004153 /* Check status register pause & lpa register */
4154 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4155 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4156 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4157 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004158 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004159 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004160 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004161 .serdes_get_strings = mv88e6390_serdes_get_strings,
4162 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004163 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4164 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004165 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004166 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004167 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004168 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004169};
4170
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004171static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004172 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004173 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4174 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004175 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004176 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4177 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004178 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004179 .phy_read = mv88e6xxx_g2_smi_phy_read,
4180 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004181 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004182 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004183 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004184 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004185 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004186 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4187 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004188 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004189 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004190 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004191 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004192 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004193 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004194 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004195 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004196 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004197 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004198 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4199 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004200 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004201 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4202 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004203 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004204 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004205 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004206 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004207 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004208 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004209 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004210 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004211 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004212 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004213};
4214
4215static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004216 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004217 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4218 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004219 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004220 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4221 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004222 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004223 .phy_read = mv88e6xxx_g2_smi_phy_read,
4224 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004225 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004226 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004227 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004228 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004229 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004230 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4231 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004232 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004233 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004234 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004235 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004236 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004237 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004238 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004239 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004240 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004241 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004242 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4243 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004244 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004245 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4246 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004247 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004248 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004249 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004250 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004251 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004252 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004253 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004254 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004255};
4256
Vivien Didelot16e329a2017-03-28 13:50:33 -04004257static const struct mv88e6xxx_ops mv88e6341_ops = {
4258 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004259 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4260 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004261 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004262 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4263 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4264 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4265 .phy_read = mv88e6xxx_g2_smi_phy_read,
4266 .phy_write = mv88e6xxx_g2_smi_phy_write,
4267 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004268 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004269 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004270 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004271 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004272 .port_tag_remap = mv88e6095_port_tag_remap,
4273 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004274 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4275 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004276 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004277 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004278 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004279 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004280 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4281 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004282 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004283 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004284 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004285 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004286 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004287 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4288 .stats_get_strings = mv88e6320_stats_get_strings,
4289 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004290 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4291 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004292 .watchdog_ops = &mv88e6390_watchdog_ops,
4293 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004294 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004295 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004296 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004297 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004298 .serdes_power = mv88e6390_serdes_power,
4299 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004300 /* Check status register pause & lpa register */
4301 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4302 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4303 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4304 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004305 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004306 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004307 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004308 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004309 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004310 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01004311 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004312};
4313
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004314static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004315 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004316 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4317 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004318 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004319 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004320 .phy_read = mv88e6xxx_g2_smi_phy_read,
4321 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004322 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004323 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004324 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004325 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004326 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004327 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004328 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4329 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004330 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004331 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004332 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004333 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004334 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004335 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004336 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004337 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004338 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004339 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004340 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4341 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004342 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004343 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4344 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004345 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004346 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004347 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004348 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004349 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4350 .atu_set_hash = mv88e6165_g1_atu_set_hash,
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,
Russell King6c422e32018-08-09 15:38:39 +02004353 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004354};
4355
4356static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004357 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004358 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4359 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004360 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004361 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004362 .phy_read = mv88e6xxx_g2_smi_phy_read,
4363 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004364 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004365 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004366 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004367 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004368 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004369 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004370 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4371 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004372 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004373 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004374 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004375 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004376 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004377 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004378 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004379 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004380 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004381 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004382 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4383 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004384 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004385 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4386 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004387 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004388 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004389 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004390 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004391 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4392 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004393 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004394 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004395 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004396 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004397 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004398};
4399
4400static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004401 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004402 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4403 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004404 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004405 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4406 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004407 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004408 .phy_read = mv88e6xxx_g2_smi_phy_read,
4409 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004410 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004411 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004412 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004413 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004414 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004415 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004416 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004417 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4418 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004419 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004420 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004421 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004422 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004423 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004424 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004425 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004426 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004427 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004428 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004429 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4430 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004431 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004432 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4433 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004434 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004435 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004436 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004437 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004438 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004439 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4440 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004441 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004442 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004443 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004444 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4445 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4446 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4447 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004448 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004449 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004450 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004451 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004452 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004453 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004454 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004455 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4456 .serdes_get_strings = mv88e6352_serdes_get_strings,
4457 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004458 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4459 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004460 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004461};
4462
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004463static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004464 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004465 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004466 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004467 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4468 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004469 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4470 .phy_read = mv88e6xxx_g2_smi_phy_read,
4471 .phy_write = mv88e6xxx_g2_smi_phy_write,
4472 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004473 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004474 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004475 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004476 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004477 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004478 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004479 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004480 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4481 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004482 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004483 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004484 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004485 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004486 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004487 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004488 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004489 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004490 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004491 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004492 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004493 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4494 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004495 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004496 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4497 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004498 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004499 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004500 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004501 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004502 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004503 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4504 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004505 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4506 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004507 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004508 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004509 /* Check status register pause & lpa register */
4510 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4511 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4512 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4513 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004514 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004515 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004516 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004517 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004518 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004519 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004520 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4521 .serdes_get_strings = mv88e6390_serdes_get_strings,
4522 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004523 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4524 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004525 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004526};
4527
4528static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004529 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004530 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004531 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004532 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4533 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004534 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4535 .phy_read = mv88e6xxx_g2_smi_phy_read,
4536 .phy_write = mv88e6xxx_g2_smi_phy_write,
4537 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004538 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004539 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004540 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004541 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004542 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004543 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004544 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004545 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4546 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004547 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004548 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004549 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004550 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004551 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004552 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004553 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004554 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004555 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004556 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004557 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004558 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4559 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004560 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004561 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4562 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004563 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004564 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004565 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004566 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004567 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004568 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4569 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004570 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4571 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004572 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004573 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004574 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4575 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4576 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4577 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004578 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004579 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004580 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004581 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4582 .serdes_get_strings = mv88e6390_serdes_get_strings,
4583 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004584 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4585 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004586 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004587 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004588 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004589 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004590};
4591
Vivien Didelotf81ec902016-05-09 13:22:58 -04004592static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4593 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004594 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004595 .family = MV88E6XXX_FAMILY_6097,
4596 .name = "Marvell 88E6085",
4597 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004598 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004599 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004600 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004601 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004602 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004603 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004604 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004605 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004606 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004607 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004608 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004609 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004610 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004611 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004612 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004613 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004614 },
4615
4616 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004617 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004618 .family = MV88E6XXX_FAMILY_6095,
4619 .name = "Marvell 88E6095/88E6095F",
4620 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004621 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004622 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004623 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004624 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004625 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004626 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004627 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004628 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004629 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004630 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004631 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004632 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004633 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004634 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004635 },
4636
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004637 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004638 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004639 .family = MV88E6XXX_FAMILY_6097,
4640 .name = "Marvell 88E6097/88E6097F",
4641 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004642 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004643 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004644 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004645 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004646 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004647 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004648 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004649 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004650 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004651 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004652 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004653 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004654 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004655 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01004656 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004657 .ops = &mv88e6097_ops,
4658 },
4659
Vivien Didelotf81ec902016-05-09 13:22:58 -04004660 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004661 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004662 .family = MV88E6XXX_FAMILY_6165,
4663 .name = "Marvell 88E6123",
4664 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004665 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004666 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004667 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004668 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004669 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004670 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004671 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004672 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004673 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004674 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004675 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004676 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004677 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004678 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004679 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004680 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004681 },
4682
4683 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004684 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004685 .family = MV88E6XXX_FAMILY_6185,
4686 .name = "Marvell 88E6131",
4687 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004688 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004689 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004690 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004691 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004692 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004693 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004694 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004695 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004696 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004697 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004698 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004699 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004700 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004701 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004702 },
4703
Vivien Didelot990e27b2017-03-28 13:50:32 -04004704 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004705 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004706 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01004707 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04004708 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004709 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004710 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004711 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004712 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004713 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004714 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004715 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004716 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004717 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004718 .age_time_coeff = 3750,
4719 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004720 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004721 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004722 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004723 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004724 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004725 .ops = &mv88e6141_ops,
4726 },
4727
Vivien Didelotf81ec902016-05-09 13:22:58 -04004728 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004729 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004730 .family = MV88E6XXX_FAMILY_6165,
4731 .name = "Marvell 88E6161",
4732 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004733 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004734 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004735 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004736 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004737 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004738 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004739 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004740 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004741 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004742 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004743 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004744 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004745 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004746 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004747 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004748 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004749 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004750 },
4751
4752 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004753 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004754 .family = MV88E6XXX_FAMILY_6165,
4755 .name = "Marvell 88E6165",
4756 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004757 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004758 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004759 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004760 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004761 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004762 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004763 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004764 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004765 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004766 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004767 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004768 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004769 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004770 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004771 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004772 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004773 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004774 },
4775
4776 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004777 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004778 .family = MV88E6XXX_FAMILY_6351,
4779 .name = "Marvell 88E6171",
4780 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004781 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004782 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004783 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004784 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004785 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004786 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004787 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004788 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004789 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004790 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004791 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004792 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004793 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004794 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004795 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004796 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004797 },
4798
4799 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004800 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004801 .family = MV88E6XXX_FAMILY_6352,
4802 .name = "Marvell 88E6172",
4803 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004804 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004805 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004806 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004807 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004808 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004809 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004810 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004811 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004812 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004813 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004814 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004815 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004816 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004817 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004818 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004819 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004820 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004821 },
4822
4823 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004824 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004825 .family = MV88E6XXX_FAMILY_6351,
4826 .name = "Marvell 88E6175",
4827 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004828 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004829 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004830 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004831 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004832 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004833 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004834 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004835 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004836 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004837 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004838 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004839 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004840 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004841 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004842 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004843 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004844 },
4845
4846 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004847 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004848 .family = MV88E6XXX_FAMILY_6352,
4849 .name = "Marvell 88E6176",
4850 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004851 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004852 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004853 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004854 .num_gpio = 15,
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 Lunn443d5a12016-12-03 04:35:18 +01004866 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004867 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004868 },
4869
4870 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004871 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004872 .family = MV88E6XXX_FAMILY_6185,
4873 .name = "Marvell 88E6185",
4874 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004875 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004876 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004877 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004878 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004879 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004880 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004881 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004882 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004883 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004884 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004885 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004886 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004887 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004888 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004889 },
4890
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004891 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004892 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004893 .family = MV88E6XXX_FAMILY_6390,
4894 .name = "Marvell 88E6190",
4895 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004896 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004897 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004898 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004899 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004900 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004901 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004902 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004903 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004904 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004905 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004906 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004907 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004908 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04004909 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004910 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05004911 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004912 .ops = &mv88e6190_ops,
4913 },
4914
4915 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004916 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004917 .family = MV88E6XXX_FAMILY_6390,
4918 .name = "Marvell 88E6190X",
4919 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004920 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004921 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004922 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004923 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004924 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004925 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004926 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004927 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004928 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004929 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004930 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004931 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004932 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004933 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004934 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004935 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004936 .ops = &mv88e6190x_ops,
4937 },
4938
4939 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004940 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004941 .family = MV88E6XXX_FAMILY_6390,
4942 .name = "Marvell 88E6191",
4943 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004944 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004945 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004946 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04004947 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004948 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004949 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004950 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004951 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004952 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004953 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004954 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004955 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004956 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004957 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004958 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004959 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04004960 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004961 },
4962
Hubert Feurstein49022642019-07-31 10:23:46 +02004963 [MV88E6220] = {
4964 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
4965 .family = MV88E6XXX_FAMILY_6250,
4966 .name = "Marvell 88E6220",
4967 .num_databases = 64,
4968
4969 /* Ports 2-4 are not routed to pins
4970 * => usable ports 0, 1, 5, 6
4971 */
4972 .num_ports = 7,
4973 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02004974 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02004975 .max_vid = 4095,
4976 .port_base_addr = 0x08,
4977 .phy_base_addr = 0x00,
4978 .global1_addr = 0x0f,
4979 .global2_addr = 0x07,
4980 .age_time_coeff = 15000,
4981 .g1_irqs = 9,
4982 .g2_irqs = 10,
4983 .atu_move_port_mask = 0xf,
4984 .dual_chip = true,
4985 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02004986 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02004987 .ops = &mv88e6250_ops,
4988 },
4989
Vivien Didelotf81ec902016-05-09 13:22:58 -04004990 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004991 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004992 .family = MV88E6XXX_FAMILY_6352,
4993 .name = "Marvell 88E6240",
4994 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004995 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004996 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004997 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004998 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004999 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005000 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005001 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005002 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005003 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005004 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005005 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005006 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005007 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005008 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005009 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005010 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005011 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005012 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005013 },
5014
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005015 [MV88E6250] = {
5016 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
5017 .family = MV88E6XXX_FAMILY_6250,
5018 .name = "Marvell 88E6250",
5019 .num_databases = 64,
5020 .num_ports = 7,
5021 .num_internal_phys = 5,
5022 .max_vid = 4095,
5023 .port_base_addr = 0x08,
5024 .phy_base_addr = 0x00,
5025 .global1_addr = 0x0f,
5026 .global2_addr = 0x07,
5027 .age_time_coeff = 15000,
5028 .g1_irqs = 9,
5029 .g2_irqs = 10,
5030 .atu_move_port_mask = 0xf,
5031 .dual_chip = true,
5032 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02005033 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005034 .ops = &mv88e6250_ops,
5035 },
5036
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005037 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005038 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005039 .family = MV88E6XXX_FAMILY_6390,
5040 .name = "Marvell 88E6290",
5041 .num_databases = 4096,
5042 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005043 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005044 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005045 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005046 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005047 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005048 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005049 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005050 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005051 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005052 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005053 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005054 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005055 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005056 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005057 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005058 .ops = &mv88e6290_ops,
5059 },
5060
Vivien Didelotf81ec902016-05-09 13:22:58 -04005061 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005062 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005063 .family = MV88E6XXX_FAMILY_6320,
5064 .name = "Marvell 88E6320",
5065 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005066 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005067 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005068 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005069 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005070 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005071 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005072 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005073 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005074 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005075 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005076 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005077 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005078 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005079 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005080 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005081 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005082 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005083 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005084 },
5085
5086 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005087 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005088 .family = MV88E6XXX_FAMILY_6320,
5089 .name = "Marvell 88E6321",
5090 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005091 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005092 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005093 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005094 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005095 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005096 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005097 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005098 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005099 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005100 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005101 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005102 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005103 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005104 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005105 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005106 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005107 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005108 },
5109
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005110 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005111 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005112 .family = MV88E6XXX_FAMILY_6341,
5113 .name = "Marvell 88E6341",
5114 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005115 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005116 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005117 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005118 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005119 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005120 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005121 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005122 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005123 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005124 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005125 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005126 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005127 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005128 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005129 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005130 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005131 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005132 .ops = &mv88e6341_ops,
5133 },
5134
Vivien Didelotf81ec902016-05-09 13:22:58 -04005135 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005136 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005137 .family = MV88E6XXX_FAMILY_6351,
5138 .name = "Marvell 88E6350",
5139 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005140 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005141 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005142 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005143 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005144 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005145 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005146 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005147 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005148 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005149 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005150 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005151 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005152 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005153 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005154 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005155 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005156 },
5157
5158 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005159 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005160 .family = MV88E6XXX_FAMILY_6351,
5161 .name = "Marvell 88E6351",
5162 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005163 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005164 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005165 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005166 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005167 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005168 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005169 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005170 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005171 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005172 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005173 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005174 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005175 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005176 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005177 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005178 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005179 },
5180
5181 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005182 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005183 .family = MV88E6XXX_FAMILY_6352,
5184 .name = "Marvell 88E6352",
5185 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005186 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005187 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005188 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005189 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005190 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005191 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005192 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005193 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005194 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005195 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005196 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005197 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005198 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005199 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005200 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005201 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005202 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005203 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005204 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005205 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005206 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005207 .family = MV88E6XXX_FAMILY_6390,
5208 .name = "Marvell 88E6390",
5209 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005210 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005211 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005212 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005213 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005214 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005215 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005216 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005217 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005218 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005219 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005220 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005221 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005222 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005223 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005224 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005225 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005226 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005227 .ops = &mv88e6390_ops,
5228 },
5229 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005230 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005231 .family = MV88E6XXX_FAMILY_6390,
5232 .name = "Marvell 88E6390X",
5233 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005234 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005235 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005236 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005237 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005238 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005239 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005240 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005241 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005242 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005243 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005244 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005245 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005246 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005247 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005248 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005249 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005250 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005251 .ops = &mv88e6390x_ops,
5252 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005253};
5254
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005255static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005256{
Vivien Didelota439c062016-04-17 13:23:58 -04005257 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005258
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005259 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5260 if (mv88e6xxx_table[i].prod_num == prod_num)
5261 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005262
Vivien Didelotb9b37712015-10-30 19:39:48 -04005263 return NULL;
5264}
5265
Vivien Didelotfad09c72016-06-21 12:28:20 -04005266static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005267{
5268 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005269 unsigned int prod_num, rev;
5270 u16 id;
5271 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005272
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005273 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005274 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005275 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005276 if (err)
5277 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005278
Vivien Didelot107fcc12017-06-12 12:37:36 -04005279 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5280 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005281
5282 info = mv88e6xxx_lookup_info(prod_num);
5283 if (!info)
5284 return -ENODEV;
5285
Vivien Didelotcaac8542016-06-20 13:14:09 -04005286 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005287 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005288
Vivien Didelotfad09c72016-06-21 12:28:20 -04005289 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5290 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005291
5292 return 0;
5293}
5294
Vivien Didelotfad09c72016-06-21 12:28:20 -04005295static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005296{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005297 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005298
Vivien Didelotfad09c72016-06-21 12:28:20 -04005299 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5300 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005301 return NULL;
5302
Vivien Didelotfad09c72016-06-21 12:28:20 -04005303 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005304
Vivien Didelotfad09c72016-06-21 12:28:20 -04005305 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005306 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005307 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005308
Vivien Didelotfad09c72016-06-21 12:28:20 -04005309 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005310}
5311
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005312static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005313 int port,
5314 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005315{
Vivien Didelot04bed142016-08-31 18:06:13 -04005316 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005317
Andrew Lunn443d5a12016-12-03 04:35:18 +01005318 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005319}
5320
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005321static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
5322 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005323{
Vivien Didelot04bed142016-08-31 18:06:13 -04005324 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005325 int err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005326
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005327 mv88e6xxx_reg_lock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005328 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5329 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005330 mv88e6xxx_reg_unlock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005331
5332 return err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005333}
5334
5335static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5336 const struct switchdev_obj_port_mdb *mdb)
5337{
Vivien Didelot04bed142016-08-31 18:06:13 -04005338 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005339 int err;
5340
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005341 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005342 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005343 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005344
5345 return err;
5346}
5347
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005348static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5349 struct dsa_mall_mirror_tc_entry *mirror,
5350 bool ingress)
5351{
5352 enum mv88e6xxx_egress_direction direction = ingress ?
5353 MV88E6XXX_EGRESS_DIR_INGRESS :
5354 MV88E6XXX_EGRESS_DIR_EGRESS;
5355 struct mv88e6xxx_chip *chip = ds->priv;
5356 bool other_mirrors = false;
5357 int i;
5358 int err;
5359
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005360 mutex_lock(&chip->reg_lock);
5361 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5362 mirror->to_local_port) {
5363 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5364 other_mirrors |= ingress ?
5365 chip->ports[i].mirror_ingress :
5366 chip->ports[i].mirror_egress;
5367
5368 /* Can't change egress port when other mirror is active */
5369 if (other_mirrors) {
5370 err = -EBUSY;
5371 goto out;
5372 }
5373
Marek Behún2fda45f2021-03-17 14:46:41 +01005374 err = mv88e6xxx_set_egress_port(chip, direction,
5375 mirror->to_local_port);
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005376 if (err)
5377 goto out;
5378 }
5379
5380 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5381out:
5382 mutex_unlock(&chip->reg_lock);
5383
5384 return err;
5385}
5386
5387static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5388 struct dsa_mall_mirror_tc_entry *mirror)
5389{
5390 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5391 MV88E6XXX_EGRESS_DIR_INGRESS :
5392 MV88E6XXX_EGRESS_DIR_EGRESS;
5393 struct mv88e6xxx_chip *chip = ds->priv;
5394 bool other_mirrors = false;
5395 int i;
5396
5397 mutex_lock(&chip->reg_lock);
5398 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5399 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5400
5401 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5402 other_mirrors |= mirror->ingress ?
5403 chip->ports[i].mirror_ingress :
5404 chip->ports[i].mirror_egress;
5405
5406 /* Reset egress port when no other mirror is active */
5407 if (!other_mirrors) {
Marek Behún2fda45f2021-03-17 14:46:41 +01005408 if (mv88e6xxx_set_egress_port(chip, direction,
5409 dsa_upstream_port(ds, port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005410 dev_err(ds->dev, "failed to set egress port\n");
5411 }
5412
5413 mutex_unlock(&chip->reg_lock);
5414}
5415
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005416static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port,
5417 struct switchdev_brport_flags flags,
5418 struct netlink_ext_ack *extack)
5419{
5420 struct mv88e6xxx_chip *chip = ds->priv;
5421 const struct mv88e6xxx_ops *ops;
5422
5423 if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD))
5424 return -EINVAL;
5425
5426 ops = chip->info->ops;
5427
5428 if ((flags.mask & BR_FLOOD) && !ops->port_set_ucast_flood)
5429 return -EINVAL;
5430
5431 if ((flags.mask & BR_MCAST_FLOOD) && !ops->port_set_mcast_flood)
5432 return -EINVAL;
5433
5434 return 0;
5435}
5436
5437static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
5438 struct switchdev_brport_flags flags,
5439 struct netlink_ext_ack *extack)
Russell King4f859012019-02-20 15:35:05 -08005440{
5441 struct mv88e6xxx_chip *chip = ds->priv;
5442 int err = -EOPNOTSUPP;
5443
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005444 mv88e6xxx_reg_lock(chip);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005445
5446 if (flags.mask & BR_FLOOD) {
5447 bool unicast = !!(flags.val & BR_FLOOD);
5448
5449 err = chip->info->ops->port_set_ucast_flood(chip, port,
5450 unicast);
5451 if (err)
5452 goto out;
5453 }
5454
5455 if (flags.mask & BR_MCAST_FLOOD) {
5456 bool multicast = !!(flags.val & BR_MCAST_FLOOD);
5457
5458 err = chip->info->ops->port_set_mcast_flood(chip, port,
5459 multicast);
5460 if (err)
5461 goto out;
5462 }
5463
5464out:
5465 mv88e6xxx_reg_unlock(chip);
5466
5467 return err;
5468}
5469
5470static int mv88e6xxx_port_set_mrouter(struct dsa_switch *ds, int port,
5471 bool mrouter,
5472 struct netlink_ext_ack *extack)
5473{
5474 struct mv88e6xxx_chip *chip = ds->priv;
5475 int err;
5476
5477 if (!chip->info->ops->port_set_mcast_flood)
5478 return -EOPNOTSUPP;
5479
5480 mv88e6xxx_reg_lock(chip);
5481 err = chip->info->ops->port_set_mcast_flood(chip, port, mrouter);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005482 mv88e6xxx_reg_unlock(chip);
Russell King4f859012019-02-20 15:35:05 -08005483
5484 return err;
5485}
5486
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005487static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
5488 struct net_device *lag,
5489 struct netdev_lag_upper_info *info)
5490{
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005491 struct mv88e6xxx_chip *chip = ds->priv;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005492 struct dsa_port *dp;
5493 int id, members = 0;
5494
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005495 if (!mv88e6xxx_has_lag(chip))
5496 return false;
5497
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005498 id = dsa_lag_id(ds->dst, lag);
5499 if (id < 0 || id >= ds->num_lag_ids)
5500 return false;
5501
5502 dsa_lag_foreach_port(dp, ds->dst, lag)
5503 /* Includes the port joining the LAG */
5504 members++;
5505
5506 if (members > 8)
5507 return false;
5508
5509 /* We could potentially relax this to include active
5510 * backup in the future.
5511 */
5512 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
5513 return false;
5514
5515 /* Ideally we would also validate that the hash type matches
5516 * the hardware. Alas, this is always set to unknown on team
5517 * interfaces.
5518 */
5519 return true;
5520}
5521
5522static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct net_device *lag)
5523{
5524 struct mv88e6xxx_chip *chip = ds->priv;
5525 struct dsa_port *dp;
5526 u16 map = 0;
5527 int id;
5528
5529 id = dsa_lag_id(ds->dst, lag);
5530
5531 /* Build the map of all ports to distribute flows destined for
5532 * this LAG. This can be either a local user port, or a DSA
5533 * port if the LAG port is on a remote chip.
5534 */
5535 dsa_lag_foreach_port(dp, ds->dst, lag)
5536 map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));
5537
5538 return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
5539}
5540
5541static const u8 mv88e6xxx_lag_mask_table[8][8] = {
5542 /* Row number corresponds to the number of active members in a
5543 * LAG. Each column states which of the eight hash buckets are
5544 * mapped to the column:th port in the LAG.
5545 *
5546 * Example: In a LAG with three active ports, the second port
5547 * ([2][1]) would be selected for traffic mapped to buckets
5548 * 3,4,5 (0x38).
5549 */
5550 { 0xff, 0, 0, 0, 0, 0, 0, 0 },
5551 { 0x0f, 0xf0, 0, 0, 0, 0, 0, 0 },
5552 { 0x07, 0x38, 0xc0, 0, 0, 0, 0, 0 },
5553 { 0x03, 0x0c, 0x30, 0xc0, 0, 0, 0, 0 },
5554 { 0x03, 0x0c, 0x30, 0x40, 0x80, 0, 0, 0 },
5555 { 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80, 0, 0 },
5556 { 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0 },
5557 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
5558};
5559
5560static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
5561 int num_tx, int nth)
5562{
5563 u8 active = 0;
5564 int i;
5565
5566 num_tx = num_tx <= 8 ? num_tx : 8;
5567 if (nth < num_tx)
5568 active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];
5569
5570 for (i = 0; i < 8; i++) {
5571 if (BIT(i) & active)
5572 mask[i] |= BIT(port);
5573 }
5574}
5575
5576static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
5577{
5578 struct mv88e6xxx_chip *chip = ds->priv;
5579 unsigned int id, num_tx;
5580 struct net_device *lag;
5581 struct dsa_port *dp;
5582 int i, err, nth;
5583 u16 mask[8];
5584 u16 ivec;
5585
5586 /* Assume no port is a member of any LAG. */
5587 ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;
5588
5589 /* Disable all masks for ports that _are_ members of a LAG. */
5590 list_for_each_entry(dp, &ds->dst->ports, list) {
5591 if (!dp->lag_dev || dp->ds != ds)
5592 continue;
5593
5594 ivec &= ~BIT(dp->index);
5595 }
5596
5597 for (i = 0; i < 8; i++)
5598 mask[i] = ivec;
5599
5600 /* Enable the correct subset of masks for all LAG ports that
5601 * are in the Tx set.
5602 */
5603 dsa_lags_foreach_id(id, ds->dst) {
5604 lag = dsa_lag_dev(ds->dst, id);
5605 if (!lag)
5606 continue;
5607
5608 num_tx = 0;
5609 dsa_lag_foreach_port(dp, ds->dst, lag) {
5610 if (dp->lag_tx_enabled)
5611 num_tx++;
5612 }
5613
5614 if (!num_tx)
5615 continue;
5616
5617 nth = 0;
5618 dsa_lag_foreach_port(dp, ds->dst, lag) {
5619 if (!dp->lag_tx_enabled)
5620 continue;
5621
5622 if (dp->ds == ds)
5623 mv88e6xxx_lag_set_port_mask(mask, dp->index,
5624 num_tx, nth);
5625
5626 nth++;
5627 }
5628 }
5629
5630 for (i = 0; i < 8; i++) {
5631 err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
5632 if (err)
5633 return err;
5634 }
5635
5636 return 0;
5637}
5638
5639static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
5640 struct net_device *lag)
5641{
5642 int err;
5643
5644 err = mv88e6xxx_lag_sync_masks(ds);
5645
5646 if (!err)
5647 err = mv88e6xxx_lag_sync_map(ds, lag);
5648
5649 return err;
5650}
5651
5652static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port)
5653{
5654 struct mv88e6xxx_chip *chip = ds->priv;
5655 int err;
5656
5657 mv88e6xxx_reg_lock(chip);
5658 err = mv88e6xxx_lag_sync_masks(ds);
5659 mv88e6xxx_reg_unlock(chip);
5660 return err;
5661}
5662
5663static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
5664 struct net_device *lag,
5665 struct netdev_lag_upper_info *info)
5666{
5667 struct mv88e6xxx_chip *chip = ds->priv;
5668 int err, id;
5669
5670 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
5671 return -EOPNOTSUPP;
5672
5673 id = dsa_lag_id(ds->dst, lag);
5674
5675 mv88e6xxx_reg_lock(chip);
5676
5677 err = mv88e6xxx_port_set_trunk(chip, port, true, id);
5678 if (err)
5679 goto err_unlock;
5680
5681 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
5682 if (err)
5683 goto err_clear_trunk;
5684
5685 mv88e6xxx_reg_unlock(chip);
5686 return 0;
5687
5688err_clear_trunk:
5689 mv88e6xxx_port_set_trunk(chip, port, false, 0);
5690err_unlock:
5691 mv88e6xxx_reg_unlock(chip);
5692 return err;
5693}
5694
5695static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
5696 struct net_device *lag)
5697{
5698 struct mv88e6xxx_chip *chip = ds->priv;
5699 int err_sync, err_trunk;
5700
5701 mv88e6xxx_reg_lock(chip);
5702 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
5703 err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
5704 mv88e6xxx_reg_unlock(chip);
5705 return err_sync ? : err_trunk;
5706}
5707
5708static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
5709 int port)
5710{
5711 struct mv88e6xxx_chip *chip = ds->priv;
5712 int err;
5713
5714 mv88e6xxx_reg_lock(chip);
5715 err = mv88e6xxx_lag_sync_masks(ds);
5716 mv88e6xxx_reg_unlock(chip);
5717 return err;
5718}
5719
5720static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
5721 int port, struct net_device *lag,
5722 struct netdev_lag_upper_info *info)
5723{
5724 struct mv88e6xxx_chip *chip = ds->priv;
5725 int err;
5726
5727 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
5728 return -EOPNOTSUPP;
5729
5730 mv88e6xxx_reg_lock(chip);
5731
5732 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
5733 if (err)
5734 goto unlock;
5735
5736 err = mv88e6xxx_pvt_map(chip, sw_index, port);
5737
5738unlock:
5739 mv88e6xxx_reg_unlock(chip);
5740 return err;
5741}
5742
5743static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
5744 int port, struct net_device *lag)
5745{
5746 struct mv88e6xxx_chip *chip = ds->priv;
5747 int err_sync, err_pvt;
5748
5749 mv88e6xxx_reg_lock(chip);
5750 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
5751 err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
5752 mv88e6xxx_reg_unlock(chip);
5753 return err_sync ? : err_pvt;
5754}
5755
Florian Fainellia82f67a2017-01-08 14:52:08 -08005756static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02005757 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005758 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005759 .teardown = mv88e6xxx_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07005760 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00005761 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07005762 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00005763 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07005764 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
5765 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005766 .get_strings = mv88e6xxx_get_strings,
5767 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
5768 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02005769 .port_enable = mv88e6xxx_port_enable,
5770 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02005771 .port_max_mtu = mv88e6xxx_get_max_mtu,
5772 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04005773 .get_mac_eee = mv88e6xxx_get_mac_eee,
5774 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005775 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005776 .get_eeprom = mv88e6xxx_get_eeprom,
5777 .set_eeprom = mv88e6xxx_set_eeprom,
5778 .get_regs_len = mv88e6xxx_get_regs_len,
5779 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04005780 .get_rxnfc = mv88e6xxx_get_rxnfc,
5781 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04005782 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005783 .port_bridge_join = mv88e6xxx_port_bridge_join,
5784 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005785 .port_pre_bridge_flags = mv88e6xxx_port_pre_bridge_flags,
5786 .port_bridge_flags = mv88e6xxx_port_bridge_flags,
5787 .port_set_mrouter = mv88e6xxx_port_set_mrouter,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005788 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04005789 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005790 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005791 .port_vlan_add = mv88e6xxx_port_vlan_add,
5792 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005793 .port_fdb_add = mv88e6xxx_port_fdb_add,
5794 .port_fdb_del = mv88e6xxx_port_fdb_del,
5795 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005796 .port_mdb_add = mv88e6xxx_port_mdb_add,
5797 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005798 .port_mirror_add = mv88e6xxx_port_mirror_add,
5799 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04005800 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
5801 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005802 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
5803 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
5804 .port_txtstamp = mv88e6xxx_port_txtstamp,
5805 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
5806 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005807 .devlink_param_get = mv88e6xxx_devlink_param_get,
5808 .devlink_param_set = mv88e6xxx_devlink_param_set,
Andrew Lunn93157302020-09-18 21:11:09 +02005809 .devlink_info_get = mv88e6xxx_devlink_info_get,
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005810 .port_lag_change = mv88e6xxx_port_lag_change,
5811 .port_lag_join = mv88e6xxx_port_lag_join,
5812 .port_lag_leave = mv88e6xxx_port_lag_leave,
5813 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
5814 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
5815 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005816};
5817
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005818static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005819{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005820 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005821 struct dsa_switch *ds;
5822
Vivien Didelot7e99e342019-10-21 16:51:30 -04005823 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005824 if (!ds)
5825 return -ENOMEM;
5826
Vivien Didelot7e99e342019-10-21 16:51:30 -04005827 ds->dev = dev;
5828 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005829 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005830 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04005831 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04005832 ds->ageing_time_min = chip->info->age_time_coeff;
5833 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005834
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005835 /* Some chips support up to 32, but that requires enabling the
5836 * 5-bit port mode, which we do not support. 640k^W16 ought to
5837 * be enough for anyone.
5838 */
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005839 ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005840
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005841 dev_set_drvdata(dev, ds);
5842
Vivien Didelot23c9ee42017-05-26 18:12:51 -04005843 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005844}
5845
Vivien Didelotfad09c72016-06-21 12:28:20 -04005846static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005847{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005848 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005849}
5850
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005851static const void *pdata_device_get_match_data(struct device *dev)
5852{
5853 const struct of_device_id *matches = dev->driver->of_match_table;
5854 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
5855
5856 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
5857 matches++) {
5858 if (!strcmp(pdata->compatible, matches->compatible))
5859 return matches->data;
5860 }
5861 return NULL;
5862}
5863
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005864/* There is no suspend to RAM support at DSA level yet, the switch configuration
5865 * would be lost after a power cycle so prevent it to be suspended.
5866 */
5867static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
5868{
5869 return -EOPNOTSUPP;
5870}
5871
5872static int __maybe_unused mv88e6xxx_resume(struct device *dev)
5873{
5874 return 0;
5875}
5876
5877static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
5878
Vivien Didelot57d32312016-06-20 13:13:58 -04005879static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005880{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005881 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04005882 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005883 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005884 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04005885 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005886 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02005887 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005888
Andrew Lunn7bb8c992018-05-31 00:15:42 +02005889 if (!np && !pdata)
5890 return -EINVAL;
5891
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005892 if (np)
5893 compat_info = of_device_get_match_data(dev);
5894
5895 if (pdata) {
5896 compat_info = pdata_device_get_match_data(dev);
5897
5898 if (!pdata->netdev)
5899 return -EINVAL;
5900
5901 for (port = 0; port < DSA_MAX_PORTS; port++) {
5902 if (!(pdata->enabled_ports & (1 << port)))
5903 continue;
5904 if (strcmp(pdata->cd.port_names[port], "cpu"))
5905 continue;
5906 pdata->cd.netdev[port] = &pdata->netdev->dev;
5907 break;
5908 }
5909 }
5910
Vivien Didelotcaac8542016-06-20 13:14:09 -04005911 if (!compat_info)
5912 return -EINVAL;
5913
Vivien Didelotfad09c72016-06-21 12:28:20 -04005914 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005915 if (!chip) {
5916 err = -ENOMEM;
5917 goto out;
5918 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005919
Vivien Didelotfad09c72016-06-21 12:28:20 -04005920 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04005921
Vivien Didelotfad09c72016-06-21 12:28:20 -04005922 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04005923 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005924 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005925
Andrew Lunnb4308f02016-11-21 23:26:55 +01005926 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005927 if (IS_ERR(chip->reset)) {
5928 err = PTR_ERR(chip->reset);
5929 goto out;
5930 }
Baruch Siach7b75e492019-06-27 21:17:39 +03005931 if (chip->reset)
5932 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01005933
Vivien Didelotfad09c72016-06-21 12:28:20 -04005934 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005935 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005936 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005937
Vivien Didelote57e5e72016-08-15 17:19:00 -04005938 mv88e6xxx_phy_init(chip);
5939
Andrew Lunn00baabe2018-05-19 22:31:35 +02005940 if (chip->info->ops->get_eeprom) {
5941 if (np)
5942 of_property_read_u32(np, "eeprom-length",
5943 &chip->eeprom_len);
5944 else
5945 chip->eeprom_len = pdata->eeprom_len;
5946 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005947
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005948 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005949 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005950 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02005951 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02005952 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02005953
Andrew Lunna27415d2019-05-01 00:10:50 +02005954 if (np) {
5955 chip->irq = of_irq_get(np, 0);
5956 if (chip->irq == -EPROBE_DEFER) {
5957 err = chip->irq;
5958 goto out;
5959 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02005960 }
5961
Andrew Lunna27415d2019-05-01 00:10:50 +02005962 if (pdata)
5963 chip->irq = pdata->irq;
5964
Andrew Lunn294d7112018-02-22 22:58:32 +01005965 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01005966 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01005967 * controllers
5968 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005969 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005970 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005971 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005972 else
5973 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005974 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005975
Andrew Lunn294d7112018-02-22 22:58:32 +01005976 if (err)
5977 goto out;
5978
5979 if (chip->info->g2_irqs > 0) {
5980 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005981 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01005982 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005983 }
5984
Andrew Lunn294d7112018-02-22 22:58:32 +01005985 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
5986 if (err)
5987 goto out_g2_irq;
5988
5989 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
5990 if (err)
5991 goto out_g1_atu_prob_irq;
5992
Andrew Lunna3c53be52017-01-24 14:53:50 +01005993 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02005994 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01005995 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005996
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005997 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005998 if (err)
5999 goto out_mdio;
6000
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006001 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02006002
6003out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01006004 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01006005out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006006 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01006007out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006008 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006009out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006010 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006011 mv88e6xxx_g2_irq_free(chip);
6012out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006013 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006014 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006015 else
6016 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006017out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006018 if (pdata)
6019 dev_put(pdata->netdev);
6020
Andrew Lunndc30c352016-10-16 19:56:49 +02006021 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006022}
6023
6024static void mv88e6xxx_remove(struct mdio_device *mdiodev)
6025{
6026 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04006027 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006028
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006029 if (chip->info->ptp_support) {
6030 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006031 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006032 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006033
Andrew Lunn930188c2016-08-22 16:01:03 +02006034 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006035 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01006036 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006037
Andrew Lunn76f38f12018-03-17 20:21:09 +01006038 mv88e6xxx_g1_vtu_prob_irq_free(chip);
6039 mv88e6xxx_g1_atu_prob_irq_free(chip);
6040
6041 if (chip->info->g2_irqs > 0)
6042 mv88e6xxx_g2_irq_free(chip);
6043
Andrew Lunn76f38f12018-03-17 20:21:09 +01006044 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006045 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01006046 else
6047 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006048}
6049
6050static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04006051 {
6052 .compatible = "marvell,mv88e6085",
6053 .data = &mv88e6xxx_table[MV88E6085],
6054 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01006055 {
6056 .compatible = "marvell,mv88e6190",
6057 .data = &mv88e6xxx_table[MV88E6190],
6058 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00006059 {
6060 .compatible = "marvell,mv88e6250",
6061 .data = &mv88e6xxx_table[MV88E6250],
6062 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006063 { /* sentinel */ },
6064};
6065
6066MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
6067
6068static struct mdio_driver mv88e6xxx_driver = {
6069 .probe = mv88e6xxx_probe,
6070 .remove = mv88e6xxx_remove,
6071 .mdiodrv.driver = {
6072 .name = "mv88e6085",
6073 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006074 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006075 },
6076};
6077
Andrew Lunn7324d502019-04-27 19:19:10 +02006078mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00006079
6080MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
6081MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
6082MODULE_LICENSE("GPL");