blob: d672112afffd225da17f1297ef9ba3c82f9ee48a [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00002/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04003 * Marvell 88e6xxx Ethernet switch single-chip support
4 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00005 * Copyright (c) 2008 Marvell Semiconductor
6 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02007 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
8 *
Vivien Didelot4333d612017-03-28 15:10:36 -04009 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
10 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 */
12
Vivien Didelot19fb7f62019-08-09 18:47:55 -040013#include <linux/bitfield.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000014#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070015#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020016#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070017#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020018#include <linux/interrupt.h>
19#include <linux/irq.h>
20#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000021#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000022#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020023#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000024#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040025#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020026#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020027#include <linux/of_mdio.h>
Andrew Lunn877b7cb2018-05-19 22:31:34 +020028#include <linux/platform_data/mv88e6xxx.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000029#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010030#include <linux/gpio/consumer.h>
Russell Kingc9a23562018-05-10 13:17:35 -070031#include <linux/phylink.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000032#include <net/dsa.h>
Vivien Didelotec561272016-09-02 14:45:33 -040033
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -040034#include "chip.h"
Andrew Lunn9dd43aa2020-09-18 21:11:05 +020035#include "devlink.h"
Vivien Didelota935c052016-09-29 12:21:53 -040036#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040037#include "global2.h"
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +010038#include "hwtstamp.h"
Andrew Lunn10fa5bf2017-05-26 01:03:20 +020039#include "phy.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010040#include "port.h"
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +010041#include "ptp.h"
Andrew Lunn6d917822017-05-26 01:03:21 +020042#include "serdes.h"
Vivien Didelote7ba0fa2019-05-03 19:28:22 -040043#include "smi.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000044
Vivien Didelotfad09c72016-06-21 12:28:20 -040045static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040046{
Vivien Didelotfad09c72016-06-21 12:28:20 -040047 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
48 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040049 dump_stack();
50 }
51}
52
Vivien Didelotec561272016-09-02 14:45:33 -040053int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -040054{
55 int err;
56
Vivien Didelotfad09c72016-06-21 12:28:20 -040057 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -040058
Vivien Didelotfad09c72016-06-21 12:28:20 -040059 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040060 if (err)
61 return err;
62
Vivien Didelotfad09c72016-06-21 12:28:20 -040063 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -040064 addr, reg, *val);
65
66 return 0;
67}
68
Vivien Didelotec561272016-09-02 14:45:33 -040069int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -040070{
71 int err;
72
Vivien Didelotfad09c72016-06-21 12:28:20 -040073 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -040074
Vivien Didelotfad09c72016-06-21 12:28:20 -040075 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040076 if (err)
77 return err;
78
Vivien Didelotfad09c72016-06-21 12:28:20 -040079 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -040080 addr, reg, val);
81
82 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000083}
84
Vivien Didelot683f2242019-08-09 18:47:54 -040085int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg,
86 u16 mask, u16 val)
87{
88 u16 data;
89 int err;
90 int i;
91
92 /* There's no bus specific operation to wait for a mask */
93 for (i = 0; i < 16; i++) {
94 err = mv88e6xxx_read(chip, addr, reg, &data);
95 if (err)
96 return err;
97
98 if ((data & mask) == val)
99 return 0;
100
101 usleep_range(1000, 2000);
102 }
103
104 dev_err(chip->dev, "Timeout while waiting for switch\n");
105 return -ETIMEDOUT;
106}
107
Vivien Didelot19fb7f62019-08-09 18:47:55 -0400108int mv88e6xxx_wait_bit(struct mv88e6xxx_chip *chip, int addr, int reg,
109 int bit, int val)
110{
111 return mv88e6xxx_wait_mask(chip, addr, reg, BIT(bit),
112 val ? BIT(bit) : 0x0000);
113}
114
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200115struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
Andrew Lunna3c53be52017-01-24 14:53:50 +0100116{
117 struct mv88e6xxx_mdio_bus *mdio_bus;
118
119 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
120 list);
121 if (!mdio_bus)
122 return NULL;
123
124 return mdio_bus->bus;
125}
126
Andrew Lunndc30c352016-10-16 19:56:49 +0200127static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
128{
129 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
130 unsigned int n = d->hwirq;
131
132 chip->g1_irq.masked |= (1 << n);
133}
134
135static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
136{
137 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
138 unsigned int n = d->hwirq;
139
140 chip->g1_irq.masked &= ~(1 << n);
141}
142
Andrew Lunn294d7112018-02-22 22:58:32 +0100143static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200144{
Andrew Lunndc30c352016-10-16 19:56:49 +0200145 unsigned int nhandled = 0;
146 unsigned int sub_irq;
147 unsigned int n;
148 u16 reg;
John David Anglin7c0db242019-02-11 13:40:21 -0500149 u16 ctl1;
Andrew Lunndc30c352016-10-16 19:56:49 +0200150 int err;
151
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000152 mv88e6xxx_reg_lock(chip);
Vivien Didelot82466922017-06-15 12:13:59 -0400153 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000154 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200155
156 if (err)
157 goto out;
158
John David Anglin7c0db242019-02-11 13:40:21 -0500159 do {
160 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
161 if (reg & (1 << n)) {
162 sub_irq = irq_find_mapping(chip->g1_irq.domain,
163 n);
164 handle_nested_irq(sub_irq);
165 ++nhandled;
166 }
Andrew Lunndc30c352016-10-16 19:56:49 +0200167 }
John David Anglin7c0db242019-02-11 13:40:21 -0500168
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000169 mv88e6xxx_reg_lock(chip);
John David Anglin7c0db242019-02-11 13:40:21 -0500170 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1);
171 if (err)
172 goto unlock;
173 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
174unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000175 mv88e6xxx_reg_unlock(chip);
John David Anglin7c0db242019-02-11 13:40:21 -0500176 if (err)
177 goto out;
178 ctl1 &= GENMASK(chip->g1_irq.nirqs, 0);
179 } while (reg & ctl1);
180
Andrew Lunndc30c352016-10-16 19:56:49 +0200181out:
182 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
183}
184
Andrew Lunn294d7112018-02-22 22:58:32 +0100185static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
186{
187 struct mv88e6xxx_chip *chip = dev_id;
188
189 return mv88e6xxx_g1_irq_thread_work(chip);
190}
191
Andrew Lunndc30c352016-10-16 19:56:49 +0200192static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
193{
194 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
195
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000196 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200197}
198
199static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
200{
201 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
202 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
203 u16 reg;
204 int err;
205
Vivien Didelotd77f4322017-06-15 12:14:03 -0400206 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200207 if (err)
208 goto out;
209
210 reg &= ~mask;
211 reg |= (~chip->g1_irq.masked & mask);
212
Vivien Didelotd77f4322017-06-15 12:14:03 -0400213 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200214 if (err)
215 goto out;
216
217out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000218 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200219}
220
Bhumika Goyal6eb15e22017-08-19 16:25:52 +0530221static const struct irq_chip mv88e6xxx_g1_irq_chip = {
Andrew Lunndc30c352016-10-16 19:56:49 +0200222 .name = "mv88e6xxx-g1",
223 .irq_mask = mv88e6xxx_g1_irq_mask,
224 .irq_unmask = mv88e6xxx_g1_irq_unmask,
225 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
226 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
227};
228
229static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
230 unsigned int irq,
231 irq_hw_number_t hwirq)
232{
233 struct mv88e6xxx_chip *chip = d->host_data;
234
235 irq_set_chip_data(irq, d->host_data);
236 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
237 irq_set_noprobe(irq);
238
239 return 0;
240}
241
242static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
243 .map = mv88e6xxx_g1_irq_domain_map,
244 .xlate = irq_domain_xlate_twocell,
245};
246
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200247/* To be called with reg_lock held */
Andrew Lunn294d7112018-02-22 22:58:32 +0100248static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200249{
250 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100251 u16 mask;
252
Vivien Didelotd77f4322017-06-15 12:14:03 -0400253 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100254 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400255 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100256
Andreas Färber5edef2f2016-11-27 23:26:28 +0100257 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100258 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200259 irq_dispose_mapping(virq);
260 }
261
Andrew Lunna3db3d32016-11-20 20:14:14 +0100262 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200263}
264
Andrew Lunn294d7112018-02-22 22:58:32 +0100265static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
266{
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200267 /*
268 * free_irq must be called without reg_lock taken because the irq
269 * handler takes this lock, too.
270 */
Andrew Lunn294d7112018-02-22 22:58:32 +0100271 free_irq(chip->irq, chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200272
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000273 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200274 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000275 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100276}
277
278static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200279{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100280 int err, irq, virq;
281 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200282
283 chip->g1_irq.nirqs = chip->info->g1_irqs;
284 chip->g1_irq.domain = irq_domain_add_simple(
285 NULL, chip->g1_irq.nirqs, 0,
286 &mv88e6xxx_g1_irq_domain_ops, chip);
287 if (!chip->g1_irq.domain)
288 return -ENOMEM;
289
290 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
291 irq_create_mapping(chip->g1_irq.domain, irq);
292
293 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
294 chip->g1_irq.masked = ~0;
295
Vivien Didelotd77f4322017-06-15 12:14:03 -0400296 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200297 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100298 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200299
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100300 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200301
Vivien Didelotd77f4322017-06-15 12:14:03 -0400302 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200303 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100304 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200305
306 /* Reading the interrupt status clears (most of) them */
Vivien Didelot82466922017-06-15 12:13:59 -0400307 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200308 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100309 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200310
Andrew Lunndc30c352016-10-16 19:56:49 +0200311 return 0;
312
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100313out_disable:
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100314 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400315 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100316
317out_mapping:
318 for (irq = 0; irq < 16; irq++) {
319 virq = irq_find_mapping(chip->g1_irq.domain, irq);
320 irq_dispose_mapping(virq);
321 }
322
323 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200324
325 return err;
326}
327
Andrew Lunn294d7112018-02-22 22:58:32 +0100328static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
329{
Andrew Lunnf6d97582019-02-23 17:43:56 +0100330 static struct lock_class_key lock_key;
331 static struct lock_class_key request_key;
Andrew Lunn294d7112018-02-22 22:58:32 +0100332 int err;
333
334 err = mv88e6xxx_g1_irq_setup_common(chip);
335 if (err)
336 return err;
337
Andrew Lunnf6d97582019-02-23 17:43:56 +0100338 /* These lock classes tells lockdep that global 1 irqs are in
339 * a different category than their parent GPIO, so it won't
340 * report false recursion.
341 */
342 irq_set_lockdep_class(chip->irq, &lock_key, &request_key);
343
Andrew Lunn30953832020-01-06 17:13:48 +0100344 snprintf(chip->irq_name, sizeof(chip->irq_name),
345 "mv88e6xxx-%s", dev_name(chip->dev));
346
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000347 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100348 err = request_threaded_irq(chip->irq, NULL,
349 mv88e6xxx_g1_irq_thread_fn,
Marek Behún03403762018-08-30 02:13:50 +0200350 IRQF_ONESHOT | IRQF_SHARED,
Andrew Lunn30953832020-01-06 17:13:48 +0100351 chip->irq_name, chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000352 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100353 if (err)
354 mv88e6xxx_g1_irq_free_common(chip);
355
356 return err;
357}
358
359static void mv88e6xxx_irq_poll(struct kthread_work *work)
360{
361 struct mv88e6xxx_chip *chip = container_of(work,
362 struct mv88e6xxx_chip,
363 irq_poll_work.work);
364 mv88e6xxx_g1_irq_thread_work(chip);
365
366 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
367 msecs_to_jiffies(100));
368}
369
370static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
371{
372 int err;
373
374 err = mv88e6xxx_g1_irq_setup_common(chip);
375 if (err)
376 return err;
377
378 kthread_init_delayed_work(&chip->irq_poll_work,
379 mv88e6xxx_irq_poll);
380
Florian Fainelli3f8b8692019-02-21 20:09:27 -0800381 chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
Andrew Lunn294d7112018-02-22 22:58:32 +0100382 if (IS_ERR(chip->kworker))
383 return PTR_ERR(chip->kworker);
384
385 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
386 msecs_to_jiffies(100));
387
388 return 0;
389}
390
391static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
392{
393 kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
394 kthread_destroy_worker(chip->kworker);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200395
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000396 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200397 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000398 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100399}
400
Russell King64d47d52020-03-14 10:15:38 +0000401static int mv88e6xxx_port_config_interface(struct mv88e6xxx_chip *chip,
402 int port, phy_interface_t interface)
403{
404 int err;
405
406 if (chip->info->ops->port_set_rgmii_delay) {
407 err = chip->info->ops->port_set_rgmii_delay(chip, port,
408 interface);
409 if (err && err != -EOPNOTSUPP)
410 return err;
411 }
412
413 if (chip->info->ops->port_set_cmode) {
414 err = chip->info->ops->port_set_cmode(chip, port,
415 interface);
416 if (err && err != -EOPNOTSUPP)
417 return err;
418 }
419
420 return 0;
421}
422
Russell Kinga5a68582020-03-14 10:15:43 +0000423static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
424 int link, int speed, int duplex, int pause,
425 phy_interface_t mode)
Vivien Didelotd78343d2016-11-04 03:23:36 +0100426{
427 int err;
428
429 if (!chip->info->ops->port_set_link)
430 return 0;
431
432 /* Port's MAC control must not be changed unless the link is down */
Hubert Feurstein43c8e0a2019-07-30 12:11:42 +0200433 err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100434 if (err)
435 return err;
436
Russell Kingf365c6f2020-03-14 10:15:53 +0000437 if (chip->info->ops->port_set_speed_duplex) {
438 err = chip->info->ops->port_set_speed_duplex(chip, port,
439 speed, duplex);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100440 if (err && err != -EOPNOTSUPP)
441 goto restore_link;
442 }
443
Andrew Lunn7cbbee02019-03-08 01:21:27 +0100444 if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
445 mode = chip->info->ops->port_max_speed_mode(port);
446
Andrew Lunn54186b92018-08-09 15:38:37 +0200447 if (chip->info->ops->port_set_pause) {
448 err = chip->info->ops->port_set_pause(chip, port, pause);
449 if (err)
450 goto restore_link;
451 }
452
Russell King64d47d52020-03-14 10:15:38 +0000453 err = mv88e6xxx_port_config_interface(chip, port, mode);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100454restore_link:
455 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400456 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100457
458 return err;
459}
460
Marek Vasutd700ec42018-09-12 00:15:24 +0200461static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
462{
463 struct mv88e6xxx_chip *chip = ds->priv;
464
465 return port < chip->info->num_internal_phys;
466}
467
Russell King5d5b2312020-03-14 10:16:03 +0000468static int mv88e6xxx_port_ppu_updates(struct mv88e6xxx_chip *chip, int port)
469{
470 u16 reg;
471 int err;
472
473 err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
474 if (err) {
475 dev_err(chip->dev,
476 "p%d: %s: failed to read port status\n",
477 port, __func__);
478 return err;
479 }
480
481 return !!(reg & MV88E6XXX_PORT_STS_PHY_DETECT);
482}
483
Russell Kinga5a68582020-03-14 10:15:43 +0000484static int mv88e6xxx_serdes_pcs_get_state(struct dsa_switch *ds, int port,
485 struct phylink_link_state *state)
486{
487 struct mv88e6xxx_chip *chip = ds->priv;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100488 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000489 int err;
490
491 mv88e6xxx_reg_lock(chip);
492 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100493 if (lane >= 0 && chip->info->ops->serdes_pcs_get_state)
Russell Kinga5a68582020-03-14 10:15:43 +0000494 err = chip->info->ops->serdes_pcs_get_state(chip, port, lane,
495 state);
496 else
497 err = -EOPNOTSUPP;
498 mv88e6xxx_reg_unlock(chip);
499
500 return err;
501}
502
503static int mv88e6xxx_serdes_pcs_config(struct mv88e6xxx_chip *chip, int port,
504 unsigned int mode,
505 phy_interface_t interface,
506 const unsigned long *advertise)
507{
508 const struct mv88e6xxx_ops *ops = chip->info->ops;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100509 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000510
511 if (ops->serdes_pcs_config) {
512 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100513 if (lane >= 0)
Russell Kinga5a68582020-03-14 10:15:43 +0000514 return ops->serdes_pcs_config(chip, port, lane, mode,
515 interface, advertise);
516 }
517
518 return 0;
519}
520
521static void mv88e6xxx_serdes_pcs_an_restart(struct dsa_switch *ds, int port)
522{
523 struct mv88e6xxx_chip *chip = ds->priv;
524 const struct mv88e6xxx_ops *ops;
525 int err = 0;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100526 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000527
528 ops = chip->info->ops;
529
530 if (ops->serdes_pcs_an_restart) {
531 mv88e6xxx_reg_lock(chip);
532 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100533 if (lane >= 0)
Russell Kinga5a68582020-03-14 10:15:43 +0000534 err = ops->serdes_pcs_an_restart(chip, port, lane);
535 mv88e6xxx_reg_unlock(chip);
536
537 if (err)
538 dev_err(ds->dev, "p%d: failed to restart AN\n", port);
539 }
540}
541
542static int mv88e6xxx_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port,
543 unsigned int mode,
544 int speed, int duplex)
545{
546 const struct mv88e6xxx_ops *ops = chip->info->ops;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100547 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000548
549 if (!phylink_autoneg_inband(mode) && ops->serdes_pcs_link_up) {
550 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100551 if (lane >= 0)
Russell Kinga5a68582020-03-14 10:15:43 +0000552 return ops->serdes_pcs_link_up(chip, port, lane,
553 speed, duplex);
554 }
555
556 return 0;
557}
558
Russell King6c422e32018-08-09 15:38:39 +0200559static void mv88e6065_phylink_validate(struct mv88e6xxx_chip *chip, int port,
560 unsigned long *mask,
561 struct phylink_link_state *state)
562{
563 if (!phy_interface_mode_is_8023z(state->interface)) {
564 /* 10M and 100M are only supported in non-802.3z mode */
565 phylink_set(mask, 10baseT_Half);
566 phylink_set(mask, 10baseT_Full);
567 phylink_set(mask, 100baseT_Half);
568 phylink_set(mask, 100baseT_Full);
569 }
570}
571
572static void mv88e6185_phylink_validate(struct mv88e6xxx_chip *chip, int port,
573 unsigned long *mask,
574 struct phylink_link_state *state)
575{
576 /* FIXME: if the port is in 1000Base-X mode, then it only supports
577 * 1000M FD speeds. In this case, CMODE will indicate 5.
578 */
579 phylink_set(mask, 1000baseT_Full);
580 phylink_set(mask, 1000baseX_Full);
581
582 mv88e6065_phylink_validate(chip, port, mask, state);
583}
584
Marek Behúne3af71a2019-02-25 12:39:55 +0100585static void mv88e6341_phylink_validate(struct mv88e6xxx_chip *chip, int port,
586 unsigned long *mask,
587 struct phylink_link_state *state)
588{
589 if (port >= 5)
590 phylink_set(mask, 2500baseX_Full);
591
592 /* No ethtool bits for 200Mbps */
593 phylink_set(mask, 1000baseT_Full);
594 phylink_set(mask, 1000baseX_Full);
595
596 mv88e6065_phylink_validate(chip, port, mask, state);
597}
598
Russell King6c422e32018-08-09 15:38:39 +0200599static void mv88e6352_phylink_validate(struct mv88e6xxx_chip *chip, int port,
600 unsigned long *mask,
601 struct phylink_link_state *state)
602{
603 /* No ethtool bits for 200Mbps */
604 phylink_set(mask, 1000baseT_Full);
605 phylink_set(mask, 1000baseX_Full);
606
607 mv88e6065_phylink_validate(chip, port, mask, state);
608}
609
610static void mv88e6390_phylink_validate(struct mv88e6xxx_chip *chip, int port,
611 unsigned long *mask,
612 struct phylink_link_state *state)
613{
Andrew Lunnec260162019-02-08 22:25:44 +0100614 if (port >= 9) {
Russell King6c422e32018-08-09 15:38:39 +0200615 phylink_set(mask, 2500baseX_Full);
Andrew Lunnec260162019-02-08 22:25:44 +0100616 phylink_set(mask, 2500baseT_Full);
617 }
Russell King6c422e32018-08-09 15:38:39 +0200618
619 /* No ethtool bits for 200Mbps */
620 phylink_set(mask, 1000baseT_Full);
621 phylink_set(mask, 1000baseX_Full);
622
623 mv88e6065_phylink_validate(chip, port, mask, state);
624}
625
626static void mv88e6390x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
627 unsigned long *mask,
628 struct phylink_link_state *state)
629{
630 if (port >= 9) {
631 phylink_set(mask, 10000baseT_Full);
632 phylink_set(mask, 10000baseKR_Full);
633 }
634
635 mv88e6390_phylink_validate(chip, port, mask, state);
636}
637
Pavana Sharmade776d02021-03-17 14:46:42 +0100638static void mv88e6393x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
639 unsigned long *mask,
640 struct phylink_link_state *state)
641{
642 if (port == 0 || port == 9 || port == 10) {
643 phylink_set(mask, 10000baseT_Full);
644 phylink_set(mask, 10000baseKR_Full);
645 phylink_set(mask, 10000baseCR_Full);
646 phylink_set(mask, 10000baseSR_Full);
647 phylink_set(mask, 10000baseLR_Full);
648 phylink_set(mask, 10000baseLRM_Full);
649 phylink_set(mask, 10000baseER_Full);
650 phylink_set(mask, 5000baseT_Full);
651 phylink_set(mask, 2500baseX_Full);
652 phylink_set(mask, 2500baseT_Full);
653 }
654
655 phylink_set(mask, 1000baseT_Full);
656 phylink_set(mask, 1000baseX_Full);
657
658 mv88e6065_phylink_validate(chip, port, mask, state);
659}
660
Russell Kingc9a23562018-05-10 13:17:35 -0700661static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
662 unsigned long *supported,
663 struct phylink_link_state *state)
664{
Russell King6c422e32018-08-09 15:38:39 +0200665 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
666 struct mv88e6xxx_chip *chip = ds->priv;
667
668 /* Allow all the expected bits */
669 phylink_set(mask, Autoneg);
670 phylink_set(mask, Pause);
671 phylink_set_port_modes(mask);
672
673 if (chip->info->ops->phylink_validate)
674 chip->info->ops->phylink_validate(chip, port, mask, state);
675
676 bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
677 bitmap_and(state->advertising, state->advertising, mask,
678 __ETHTOOL_LINK_MODE_MASK_NBITS);
679
680 /* We can only operate at 2500BaseX or 1000BaseX. If requested
681 * to advertise both, only report advertising at 2500BaseX.
682 */
683 phylink_helper_basex_speed(state);
Russell Kingc9a23562018-05-10 13:17:35 -0700684}
685
Russell Kingc9a23562018-05-10 13:17:35 -0700686static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
687 unsigned int mode,
688 const struct phylink_link_state *state)
689{
690 struct mv88e6xxx_chip *chip = ds->priv;
Russell Kingfad58192020-07-19 12:00:35 +0100691 struct mv88e6xxx_port *p;
Russell King64d47d52020-03-14 10:15:38 +0000692 int err;
Russell Kingc9a23562018-05-10 13:17:35 -0700693
Russell Kingfad58192020-07-19 12:00:35 +0100694 p = &chip->ports[port];
695
Russell King64d47d52020-03-14 10:15:38 +0000696 /* FIXME: is this the correct test? If we're in fixed mode on an
697 * internal port, why should we process this any different from
698 * PHY mode? On the other hand, the port may be automedia between
699 * an internal PHY and the serdes...
700 */
Marek Vasutd700ec42018-09-12 00:15:24 +0200701 if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
Russell Kingc9a23562018-05-10 13:17:35 -0700702 return;
703
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000704 mv88e6xxx_reg_lock(chip);
Russell Kingfad58192020-07-19 12:00:35 +0100705 /* In inband mode, the link may come up at any time while the link
706 * is not forced down. Force the link down while we reconfigure the
707 * interface mode.
Russell King64d47d52020-03-14 10:15:38 +0000708 */
Russell Kingfad58192020-07-19 12:00:35 +0100709 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
710 chip->info->ops->port_set_link)
711 chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
712
Russell King64d47d52020-03-14 10:15:38 +0000713 err = mv88e6xxx_port_config_interface(chip, port, state->interface);
Russell Kinga5a68582020-03-14 10:15:43 +0000714 if (err && err != -EOPNOTSUPP)
715 goto err_unlock;
716
717 err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
718 state->advertising);
719 /* FIXME: we should restart negotiation if something changed - which
720 * is something we get if we convert to using phylinks PCS operations.
721 */
722 if (err > 0)
723 err = 0;
724
Russell Kingfad58192020-07-19 12:00:35 +0100725 /* Undo the forced down state above after completing configuration
726 * irrespective of its state on entry, which allows the link to come up.
727 */
728 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
729 chip->info->ops->port_set_link)
730 chip->info->ops->port_set_link(chip, port, LINK_UNFORCED);
731
732 p->interface = state->interface;
733
Russell Kinga5a68582020-03-14 10:15:43 +0000734err_unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000735 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700736
737 if (err && err != -EOPNOTSUPP)
Russell King64d47d52020-03-14 10:15:38 +0000738 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700739}
740
Russell Kingc9a23562018-05-10 13:17:35 -0700741static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
742 unsigned int mode,
743 phy_interface_t interface)
744{
Russell King30c4a5b2020-02-26 10:23:51 +0000745 struct mv88e6xxx_chip *chip = ds->priv;
746 const struct mv88e6xxx_ops *ops;
747 int err = 0;
748
749 ops = chip->info->ops;
750
Russell King5d5b2312020-03-14 10:16:03 +0000751 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200752 if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
Chris Packham4efe76622020-11-24 17:34:37 +1300753 mode == MLO_AN_FIXED) && ops->port_sync_link)
754 err = ops->port_sync_link(chip, port, mode, false);
Russell King5d5b2312020-03-14 10:16:03 +0000755 mv88e6xxx_reg_unlock(chip);
Russell King30c4a5b2020-02-26 10:23:51 +0000756
Russell King5d5b2312020-03-14 10:16:03 +0000757 if (err)
758 dev_err(chip->dev,
759 "p%d: failed to force MAC link down\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700760}
761
762static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
763 unsigned int mode, phy_interface_t interface,
Russell King5b502a72020-02-26 10:23:46 +0000764 struct phy_device *phydev,
765 int speed, int duplex,
766 bool tx_pause, bool rx_pause)
Russell Kingc9a23562018-05-10 13:17:35 -0700767{
Russell King30c4a5b2020-02-26 10:23:51 +0000768 struct mv88e6xxx_chip *chip = ds->priv;
769 const struct mv88e6xxx_ops *ops;
770 int err = 0;
771
772 ops = chip->info->ops;
773
Russell King5d5b2312020-03-14 10:16:03 +0000774 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200775 if (!mv88e6xxx_port_ppu_updates(chip, port) || mode == MLO_AN_FIXED) {
Russell King30c4a5b2020-02-26 10:23:51 +0000776 /* FIXME: for an automedia port, should we force the link
777 * down here - what if the link comes up due to "other" media
778 * while we're bringing the port up, how is the exclusivity
Russell Kinga5a68582020-03-14 10:15:43 +0000779 * handled in the Marvell hardware? E.g. port 2 on 88E6390
Russell King30c4a5b2020-02-26 10:23:51 +0000780 * shared between internal PHY and Serdes.
781 */
Russell Kinga5a68582020-03-14 10:15:43 +0000782 err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
783 duplex);
784 if (err)
785 goto error;
786
Russell Kingf365c6f2020-03-14 10:15:53 +0000787 if (ops->port_set_speed_duplex) {
788 err = ops->port_set_speed_duplex(chip, port,
789 speed, duplex);
Russell King30c4a5b2020-02-26 10:23:51 +0000790 if (err && err != -EOPNOTSUPP)
791 goto error;
792 }
793
Chris Packham4efe76622020-11-24 17:34:37 +1300794 if (ops->port_sync_link)
795 err = ops->port_sync_link(chip, port, mode, true);
Russell King30c4a5b2020-02-26 10:23:51 +0000796 }
Russell King5d5b2312020-03-14 10:16:03 +0000797error:
798 mv88e6xxx_reg_unlock(chip);
799
800 if (err && err != -EOPNOTSUPP)
801 dev_err(ds->dev,
802 "p%d: failed to configure MAC link up\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700803}
804
Andrew Lunna605a0f2016-11-21 23:26:58 +0100805static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000806{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100807 if (!chip->info->ops->stats_snapshot)
808 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000809
Andrew Lunna605a0f2016-11-21 23:26:58 +0100810 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000811}
812
Andrew Lunne413e7e2015-04-02 04:06:38 +0200813static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100814 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
815 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
816 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
817 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
818 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
819 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
820 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
821 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
822 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
823 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
824 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
825 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
826 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
827 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
828 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
829 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
830 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
831 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
832 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
833 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
834 { "single", 4, 0x14, STATS_TYPE_BANK0, },
835 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
836 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
837 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
838 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
839 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
840 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
841 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
842 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
843 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
844 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
845 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
846 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
847 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
848 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
849 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
850 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
851 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
852 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
853 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
854 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
855 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
856 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
857 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
858 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
859 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
860 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
861 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
862 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
863 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
864 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
865 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
866 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
867 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
868 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
869 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
870 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
871 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
872 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200873};
874
Vivien Didelotfad09c72016-06-21 12:28:20 -0400875static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100876 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100877 int port, u16 bank1_select,
878 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200879{
Andrew Lunn80c46272015-06-20 18:42:30 +0200880 u32 low;
881 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100882 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200883 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200884 u64 value;
885
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100886 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100887 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200888 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
889 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800890 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200891
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200892 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100893 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200894 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
895 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800896 return U64_MAX;
Rasmus Villemoes84b3fd12019-05-29 07:02:11 +0000897 low |= ((u32)reg) << 16;
Andrew Lunn80c46272015-06-20 18:42:30 +0200898 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100899 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100900 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100901 reg = bank1_select;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500902 fallthrough;
Andrew Lunndfafe442016-11-21 23:27:02 +0100903 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100904 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100905 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100906 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100907 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500908 break;
909 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800910 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200911 }
Andrew Lunn6e46e2d2019-02-28 18:14:03 +0100912 value = (((u64)high) << 32) | low;
Andrew Lunn80c46272015-06-20 18:42:30 +0200913 return value;
914}
915
Andrew Lunn436fe172018-03-01 02:02:29 +0100916static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
917 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100918{
919 struct mv88e6xxx_hw_stat *stat;
920 int i, j;
921
922 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
923 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100924 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100925 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
926 ETH_GSTRING_LEN);
927 j++;
928 }
929 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100930
931 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100932}
933
Andrew Lunn436fe172018-03-01 02:02:29 +0100934static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
935 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100936{
Andrew Lunn436fe172018-03-01 02:02:29 +0100937 return mv88e6xxx_stats_get_strings(chip, data,
938 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100939}
940
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000941static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
942 uint8_t *data)
943{
944 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
945}
946
Andrew Lunn436fe172018-03-01 02:02:29 +0100947static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
948 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100949{
Andrew Lunn436fe172018-03-01 02:02:29 +0100950 return mv88e6xxx_stats_get_strings(chip, data,
951 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100952}
953
Andrew Lunn65f60e42018-03-28 23:50:28 +0200954static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
955 "atu_member_violation",
956 "atu_miss_violation",
957 "atu_full_violation",
958 "vtu_member_violation",
959 "vtu_miss_violation",
960};
961
962static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
963{
964 unsigned int i;
965
966 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
967 strlcpy(data + i * ETH_GSTRING_LEN,
968 mv88e6xxx_atu_vtu_stats_strings[i],
969 ETH_GSTRING_LEN);
970}
971
Andrew Lunndfafe442016-11-21 23:27:02 +0100972static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700973 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100974{
Vivien Didelot04bed142016-08-31 18:06:13 -0400975 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100976 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100977
Florian Fainelli89f09042018-04-25 12:12:50 -0700978 if (stringset != ETH_SS_STATS)
979 return;
980
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000981 mv88e6xxx_reg_lock(chip);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100982
Andrew Lunndfafe442016-11-21 23:27:02 +0100983 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100984 count = chip->info->ops->stats_get_strings(chip, data);
985
986 if (chip->info->ops->serdes_get_strings) {
987 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200988 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100989 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100990
Andrew Lunn65f60e42018-03-28 23:50:28 +0200991 data += count * ETH_GSTRING_LEN;
992 mv88e6xxx_atu_vtu_get_strings(data);
993
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000994 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100995}
996
997static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
998 int types)
999{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001000 struct mv88e6xxx_hw_stat *stat;
1001 int i, j;
1002
1003 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1004 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +01001005 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001006 j++;
1007 }
1008 return j;
1009}
1010
Andrew Lunndfafe442016-11-21 23:27:02 +01001011static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1012{
1013 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1014 STATS_TYPE_PORT);
1015}
1016
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001017static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1018{
1019 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
1020}
1021
Andrew Lunndfafe442016-11-21 23:27:02 +01001022static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1023{
1024 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1025 STATS_TYPE_BANK1);
1026}
1027
Florian Fainelli89f09042018-04-25 12:12:50 -07001028static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +01001029{
1030 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +01001031 int serdes_count = 0;
1032 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +01001033
Florian Fainelli89f09042018-04-25 12:12:50 -07001034 if (sset != ETH_SS_STATS)
1035 return 0;
1036
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001037 mv88e6xxx_reg_lock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001038 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +01001039 count = chip->info->ops->stats_get_sset_count(chip);
1040 if (count < 0)
1041 goto out;
1042
1043 if (chip->info->ops->serdes_get_sset_count)
1044 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1045 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +02001046 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +01001047 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001048 goto out;
1049 }
1050 count += serdes_count;
1051 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1052
Andrew Lunn436fe172018-03-01 02:02:29 +01001053out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001054 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001055
Andrew Lunn436fe172018-03-01 02:02:29 +01001056 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +01001057}
1058
Andrew Lunn436fe172018-03-01 02:02:29 +01001059static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1060 uint64_t *data, int types,
1061 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +01001062{
1063 struct mv88e6xxx_hw_stat *stat;
1064 int i, j;
1065
1066 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1067 stat = &mv88e6xxx_hw_stats[i];
1068 if (stat->type & types) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001069 mv88e6xxx_reg_lock(chip);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001070 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1071 bank1_select,
1072 histogram);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001073 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001074
Andrew Lunn052f9472016-11-21 23:27:03 +01001075 j++;
1076 }
1077 }
Andrew Lunn436fe172018-03-01 02:02:29 +01001078 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +01001079}
1080
Andrew Lunn436fe172018-03-01 02:02:29 +01001081static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1082 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001083{
1084 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001085 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001086 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +01001087}
1088
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001089static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1090 uint64_t *data)
1091{
1092 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
1093 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1094}
1095
Andrew Lunn436fe172018-03-01 02:02:29 +01001096static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1097 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001098{
1099 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001100 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001101 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1102 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001103}
1104
Andrew Lunn436fe172018-03-01 02:02:29 +01001105static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1106 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +01001107{
1108 return mv88e6xxx_stats_get_stats(chip, port, data,
1109 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001110 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1111 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001112}
1113
Andrew Lunn65f60e42018-03-28 23:50:28 +02001114static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1115 uint64_t *data)
1116{
1117 *data++ = chip->ports[port].atu_member_violation;
1118 *data++ = chip->ports[port].atu_miss_violation;
1119 *data++ = chip->ports[port].atu_full_violation;
1120 *data++ = chip->ports[port].vtu_member_violation;
1121 *data++ = chip->ports[port].vtu_miss_violation;
1122}
1123
Andrew Lunn052f9472016-11-21 23:27:03 +01001124static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1125 uint64_t *data)
1126{
Andrew Lunn436fe172018-03-01 02:02:29 +01001127 int count = 0;
1128
Andrew Lunn052f9472016-11-21 23:27:03 +01001129 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +01001130 count = chip->info->ops->stats_get_stats(chip, port, data);
1131
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001132 mv88e6xxx_reg_lock(chip);
Andrew Lunn436fe172018-03-01 02:02:29 +01001133 if (chip->info->ops->serdes_get_stats) {
1134 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001135 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +01001136 }
Andrew Lunn65f60e42018-03-28 23:50:28 +02001137 data += count;
1138 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001139 mv88e6xxx_reg_unlock(chip);
Andrew Lunn052f9472016-11-21 23:27:03 +01001140}
1141
Vivien Didelotf81ec902016-05-09 13:22:58 -04001142static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1143 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001144{
Vivien Didelot04bed142016-08-31 18:06:13 -04001145 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001146 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001147
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001148 mv88e6xxx_reg_lock(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001149
Andrew Lunna605a0f2016-11-21 23:26:58 +01001150 ret = mv88e6xxx_stats_snapshot(chip, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001151 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001152
1153 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001154 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001155
1156 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001157
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001158}
Ben Hutchings98e67302011-11-25 14:36:19 +00001159
Vivien Didelotf81ec902016-05-09 13:22:58 -04001160static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001161{
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001162 struct mv88e6xxx_chip *chip = ds->priv;
1163 int len;
1164
1165 len = 32 * sizeof(u16);
1166 if (chip->info->ops->serdes_get_regs_len)
1167 len += chip->info->ops->serdes_get_regs_len(chip, port);
1168
1169 return len;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001170}
1171
Vivien Didelotf81ec902016-05-09 13:22:58 -04001172static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1173 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001174{
Vivien Didelot04bed142016-08-31 18:06:13 -04001175 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001176 int err;
1177 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001178 u16 *p = _p;
1179 int i;
1180
Vivien Didelota5f39322018-12-17 16:05:21 -05001181 regs->version = chip->info->prod_num;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001182
1183 memset(p, 0xff, 32 * sizeof(u16));
1184
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001185 mv88e6xxx_reg_lock(chip);
Vivien Didelot23062512016-05-09 13:22:45 -04001186
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001187 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001188
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001189 err = mv88e6xxx_port_read(chip, port, i, &reg);
1190 if (!err)
1191 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001192 }
Vivien Didelot23062512016-05-09 13:22:45 -04001193
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001194 if (chip->info->ops->serdes_get_regs)
1195 chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1196
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001197 mv88e6xxx_reg_unlock(chip);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001198}
1199
Vivien Didelot08f50062017-08-01 16:32:41 -04001200static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1201 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001202{
Vivien Didelot5480db62017-08-01 16:32:40 -04001203 /* Nothing to do on the port's MAC */
1204 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001205}
1206
Vivien Didelot08f50062017-08-01 16:32:41 -04001207static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1208 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001209{
Vivien Didelot5480db62017-08-01 16:32:40 -04001210 /* Nothing to do on the port's MAC */
1211 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001212}
1213
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001214/* Mask of the local ports allowed to receive frames from a given fabric port */
Vivien Didelote5887a22017-03-30 17:37:11 -04001215static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001216{
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001217 struct dsa_switch *ds = chip->ds;
1218 struct dsa_switch_tree *dst = ds->dst;
Vivien Didelote5887a22017-03-30 17:37:11 -04001219 struct net_device *br;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001220 struct dsa_port *dp;
1221 bool found = false;
Vivien Didelote5887a22017-03-30 17:37:11 -04001222 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001223
Vladimir Olteance5df682021-07-22 18:55:41 +03001224 /* dev is a physical switch */
1225 if (dev <= dst->last_switch) {
1226 list_for_each_entry(dp, &dst->ports, list) {
1227 if (dp->ds->index == dev && dp->index == port) {
1228 /* dp might be a DSA link or a user port, so it
1229 * might or might not have a bridge_dev
1230 * pointer. Use the "found" variable for both
1231 * cases.
1232 */
1233 br = dp->bridge_dev;
1234 found = true;
1235 break;
1236 }
1237 }
1238 /* dev is a virtual bridge */
1239 } else {
1240 list_for_each_entry(dp, &dst->ports, list) {
1241 if (dp->bridge_num < 0)
1242 continue;
1243
1244 if (dp->bridge_num + 1 + dst->last_switch != dev)
1245 continue;
1246
1247 br = dp->bridge_dev;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001248 found = true;
1249 break;
1250 }
1251 }
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001252
Vladimir Olteance5df682021-07-22 18:55:41 +03001253 /* Prevent frames from unknown switch or virtual bridge */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001254 if (!found)
Vivien Didelote5887a22017-03-30 17:37:11 -04001255 return 0;
1256
1257 /* Frames from DSA links and CPU ports can egress any local port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001258 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
Vivien Didelote5887a22017-03-30 17:37:11 -04001259 return mv88e6xxx_port_mask(chip);
1260
Vivien Didelote5887a22017-03-30 17:37:11 -04001261 pvlan = 0;
1262
1263 /* Frames from user ports can egress any local DSA links and CPU ports,
1264 * as well as any local member of their bridge group.
1265 */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001266 list_for_each_entry(dp, &dst->ports, list)
1267 if (dp->ds == ds &&
1268 (dp->type == DSA_PORT_TYPE_CPU ||
1269 dp->type == DSA_PORT_TYPE_DSA ||
1270 (br && dp->bridge_dev == br)))
1271 pvlan |= BIT(dp->index);
Vivien Didelote5887a22017-03-30 17:37:11 -04001272
1273 return pvlan;
1274}
1275
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001276static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001277{
1278 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001279
1280 /* prevent frames from going back out of the port they came in on */
1281 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001282
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001283 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001284}
1285
Vivien Didelotf81ec902016-05-09 13:22:58 -04001286static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1287 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001288{
Vivien Didelot04bed142016-08-31 18:06:13 -04001289 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001290 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001291
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001292 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001293 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001294 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001295
1296 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001297 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001298}
1299
Vivien Didelot93e18d62018-05-11 17:16:35 -04001300static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1301{
1302 int err;
1303
1304 if (chip->info->ops->ieee_pri_map) {
1305 err = chip->info->ops->ieee_pri_map(chip);
1306 if (err)
1307 return err;
1308 }
1309
1310 if (chip->info->ops->ip_pri_map) {
1311 err = chip->info->ops->ip_pri_map(chip);
1312 if (err)
1313 return err;
1314 }
1315
1316 return 0;
1317}
1318
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001319static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1320{
Vivien Didelotc5f51762019-10-30 22:09:13 -04001321 struct dsa_switch *ds = chip->ds;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001322 int target, port;
1323 int err;
1324
1325 if (!chip->info->global2_addr)
1326 return 0;
1327
1328 /* Initialize the routing port to the 32 possible target devices */
1329 for (target = 0; target < 32; target++) {
Vivien Didelotc5f51762019-10-30 22:09:13 -04001330 port = dsa_routing_port(ds, target);
1331 if (port == ds->num_ports)
1332 port = 0x1f;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001333
1334 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1335 if (err)
1336 return err;
1337 }
1338
Vivien Didelot02317e62018-05-09 11:38:49 -04001339 if (chip->info->ops->set_cascade_port) {
1340 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1341 err = chip->info->ops->set_cascade_port(chip, port);
1342 if (err)
1343 return err;
1344 }
1345
Vivien Didelot23c98912018-05-09 11:38:50 -04001346 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1347 if (err)
1348 return err;
1349
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001350 return 0;
1351}
1352
Vivien Didelotb28f8722018-04-26 21:56:44 -04001353static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1354{
1355 /* Clear all trunk masks and mapping */
1356 if (chip->info->global2_addr)
1357 return mv88e6xxx_g2_trunk_clear(chip);
1358
1359 return 0;
1360}
1361
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001362static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1363{
1364 if (chip->info->ops->rmu_disable)
1365 return chip->info->ops->rmu_disable(chip);
1366
1367 return 0;
1368}
1369
Vivien Didelot9e907d72017-07-17 13:03:43 -04001370static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1371{
1372 if (chip->info->ops->pot_clear)
1373 return chip->info->ops->pot_clear(chip);
1374
1375 return 0;
1376}
1377
Vivien Didelot51c901a2017-07-17 13:03:41 -04001378static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1379{
1380 if (chip->info->ops->mgmt_rsvd2cpu)
1381 return chip->info->ops->mgmt_rsvd2cpu(chip);
1382
1383 return 0;
1384}
1385
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001386static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1387{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001388 int err;
1389
Vivien Didelotdaefc942017-03-11 16:12:54 -05001390 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1391 if (err)
1392 return err;
1393
Rasmus Villemoes49506a92020-12-10 12:06:44 +01001394 /* The chips that have a "learn2all" bit in Global1, ATU
1395 * Control are precisely those whose port registers have a
1396 * Message Port bit in Port Control 1 and hence implement
1397 * ->port_setup_message_port.
1398 */
1399 if (chip->info->ops->port_setup_message_port) {
1400 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1401 if (err)
1402 return err;
1403 }
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001404
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001405 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1406}
1407
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001408static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1409{
1410 int port;
1411 int err;
1412
1413 if (!chip->info->ops->irl_init_all)
1414 return 0;
1415
1416 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1417 /* Disable ingress rate limiting by resetting all per port
1418 * ingress rate limit resources to their initial state.
1419 */
1420 err = chip->info->ops->irl_init_all(chip, port);
1421 if (err)
1422 return err;
1423 }
1424
1425 return 0;
1426}
1427
Vivien Didelot04a69a12017-10-13 14:18:05 -04001428static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1429{
1430 if (chip->info->ops->set_switch_mac) {
1431 u8 addr[ETH_ALEN];
1432
1433 eth_random_addr(addr);
1434
1435 return chip->info->ops->set_switch_mac(chip, addr);
1436 }
1437
1438 return 0;
1439}
1440
Vivien Didelot17a15942017-03-30 17:37:09 -04001441static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1442{
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001443 struct dsa_switch_tree *dst = chip->ds->dst;
1444 struct dsa_switch *ds;
1445 struct dsa_port *dp;
Vivien Didelot17a15942017-03-30 17:37:09 -04001446 u16 pvlan = 0;
1447
1448 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001449 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001450
1451 /* Skip the local source device, which uses in-chip port VLAN */
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001452 if (dev != chip->ds->index) {
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001453 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001454
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001455 ds = dsa_switch_find(dst->index, dev);
1456 dp = ds ? dsa_to_port(ds, port) : NULL;
1457 if (dp && dp->lag_dev) {
1458 /* As the PVT is used to limit flooding of
1459 * FORWARD frames, which use the LAG ID as the
1460 * source port, we must translate dev/port to
1461 * the special "LAG device" in the PVT, using
1462 * the LAG ID as the port number.
1463 */
Tobias Waldekranz78e70db2021-04-21 14:04:52 +02001464 dev = MV88E6XXX_G2_PVT_ADDR_DEV_TRUNK;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001465 port = dsa_lag_id(dst, dp->lag_dev);
1466 }
1467 }
1468
Vivien Didelot17a15942017-03-30 17:37:09 -04001469 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1470}
1471
Vivien Didelot81228992017-03-30 17:37:08 -04001472static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1473{
Vivien Didelot17a15942017-03-30 17:37:09 -04001474 int dev, port;
1475 int err;
1476
Vivien Didelot81228992017-03-30 17:37:08 -04001477 if (!mv88e6xxx_has_pvt(chip))
1478 return 0;
1479
1480 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1481 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1482 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001483 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1484 if (err)
1485 return err;
1486
1487 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1488 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1489 err = mv88e6xxx_pvt_map(chip, dev, port);
1490 if (err)
1491 return err;
1492 }
1493 }
1494
1495 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001496}
1497
Vivien Didelot749efcb2016-09-22 16:49:24 -04001498static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1499{
1500 struct mv88e6xxx_chip *chip = ds->priv;
1501 int err;
1502
Tobias Waldekranzffcec3f2021-03-18 20:25:34 +01001503 if (dsa_to_port(ds, port)->lag_dev)
1504 /* Hardware is incapable of fast-aging a LAG through a
1505 * regular ATU move operation. Until we have something
1506 * more fancy in place this is a no-op.
1507 */
1508 return;
1509
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001510 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001511 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001512 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001513
1514 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001515 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001516}
1517
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001518static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1519{
Tobias Waldekranze545f862020-11-10 19:57:20 +01001520 if (!mv88e6xxx_max_vid(chip))
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001521 return 0;
1522
1523 return mv88e6xxx_g1_vtu_flush(chip);
1524}
1525
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001526static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1527 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotf1394b782017-05-01 14:05:22 -04001528{
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001529 int err;
1530
Vivien Didelotf1394b782017-05-01 14:05:22 -04001531 if (!chip->info->ops->vtu_getnext)
1532 return -EOPNOTSUPP;
1533
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001534 entry->vid = vid ? vid - 1 : mv88e6xxx_max_vid(chip);
1535 entry->valid = false;
1536
1537 err = chip->info->ops->vtu_getnext(chip, entry);
1538
1539 if (entry->vid != vid)
1540 entry->valid = false;
1541
1542 return err;
Vivien Didelotf1394b782017-05-01 14:05:22 -04001543}
1544
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001545static int mv88e6xxx_vtu_walk(struct mv88e6xxx_chip *chip,
1546 int (*cb)(struct mv88e6xxx_chip *chip,
1547 const struct mv88e6xxx_vtu_entry *entry,
1548 void *priv),
1549 void *priv)
1550{
1551 struct mv88e6xxx_vtu_entry entry = {
1552 .vid = mv88e6xxx_max_vid(chip),
1553 .valid = false,
1554 };
1555 int err;
1556
1557 if (!chip->info->ops->vtu_getnext)
1558 return -EOPNOTSUPP;
1559
1560 do {
1561 err = chip->info->ops->vtu_getnext(chip, &entry);
1562 if (err)
1563 return err;
1564
1565 if (!entry.valid)
1566 break;
1567
1568 err = cb(chip, &entry, priv);
1569 if (err)
1570 return err;
1571 } while (entry.vid < mv88e6xxx_max_vid(chip));
1572
1573 return 0;
1574}
1575
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001576static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1577 struct mv88e6xxx_vtu_entry *entry)
1578{
1579 if (!chip->info->ops->vtu_loadpurge)
1580 return -EOPNOTSUPP;
1581
1582 return chip->info->ops->vtu_loadpurge(chip, entry);
1583}
1584
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001585static int mv88e6xxx_fid_map_vlan(struct mv88e6xxx_chip *chip,
1586 const struct mv88e6xxx_vtu_entry *entry,
1587 void *_fid_bitmap)
1588{
1589 unsigned long *fid_bitmap = _fid_bitmap;
1590
1591 set_bit(entry->fid, fid_bitmap);
1592 return 0;
1593}
1594
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001595int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001596{
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001597 int i, err;
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001598 u16 fid;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001599
1600 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1601
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001602 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001603 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001604 err = mv88e6xxx_port_get_fid(chip, i, &fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001605 if (err)
1606 return err;
1607
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001608 set_bit(fid, fid_bitmap);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001609 }
1610
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001611 /* Set every FID bit used by the VLAN entries */
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001612 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_fid_map_vlan, fid_bitmap);
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001613}
1614
1615static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1616{
1617 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1618 int err;
1619
1620 err = mv88e6xxx_fid_map(chip, fid_bitmap);
1621 if (err)
1622 return err;
1623
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001624 /* The reset value 0x000 is used to indicate that multiple address
1625 * databases are not needed. Return the next positive available.
1626 */
1627 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001628 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001629 return -ENOSPC;
1630
1631 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001632 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001633}
1634
Vivien Didelotda9c3592016-02-12 12:09:40 -05001635static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001636 u16 vid)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001637{
Vivien Didelot04bed142016-08-31 18:06:13 -04001638 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001639 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001640 int i, err;
1641
Andrew Lunndb06ae412017-09-25 23:32:20 +02001642 /* DSA and CPU ports have to be members of multiple vlans */
1643 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1644 return 0;
1645
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001646 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001647 if (err)
1648 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001649
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001650 if (!vlan.valid)
1651 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001652
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001653 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1654 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1655 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001656
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001657 if (!dsa_to_port(ds, i)->slave)
1658 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001659
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001660 if (vlan.member[i] ==
1661 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1662 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001663
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001664 if (dsa_to_port(ds, i)->bridge_dev ==
1665 dsa_to_port(ds, port)->bridge_dev)
1666 break; /* same bridge, check next VLAN */
Vivien Didelotda9c3592016-02-12 12:09:40 -05001667
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001668 if (!dsa_to_port(ds, i)->bridge_dev)
1669 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001670
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001671 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1672 port, vlan.vid, i,
1673 netdev_name(dsa_to_port(ds, i)->bridge_dev));
1674 return -EOPNOTSUPP;
1675 }
Vivien Didelotda9c3592016-02-12 12:09:40 -05001676
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001677 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001678}
1679
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001680static int mv88e6xxx_port_commit_pvid(struct mv88e6xxx_chip *chip, int port)
1681{
1682 struct dsa_port *dp = dsa_to_port(chip->ds, port);
1683 struct mv88e6xxx_port *p = &chip->ports[port];
1684 bool drop_untagged = false;
1685 u16 pvid = 0;
1686 int err;
1687
1688 if (dp->bridge_dev && br_vlan_enabled(dp->bridge_dev)) {
1689 pvid = p->bridge_pvid.vid;
1690 drop_untagged = !p->bridge_pvid.valid;
1691 }
1692
1693 err = mv88e6xxx_port_set_pvid(chip, port, pvid);
1694 if (err)
1695 return err;
1696
1697 return mv88e6xxx_port_drop_untagged(chip, port, drop_untagged);
1698}
1699
Vivien Didelotf81ec902016-05-09 13:22:58 -04001700static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
Vladimir Oltean89153ed2021-02-13 22:43:19 +02001701 bool vlan_filtering,
1702 struct netlink_ext_ack *extack)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001703{
Vivien Didelot04bed142016-08-31 18:06:13 -04001704 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001705 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1706 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001707 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001708
Vladimir Olteanbae33f22021-01-09 02:01:50 +02001709 if (!mv88e6xxx_max_vid(chip))
1710 return -EOPNOTSUPP;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001711
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001712 mv88e6xxx_reg_lock(chip);
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001713
Vivien Didelot385a0992016-11-04 03:23:31 +01001714 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001715 if (err)
1716 goto unlock;
1717
1718 err = mv88e6xxx_port_commit_pvid(chip, port);
1719 if (err)
1720 goto unlock;
1721
1722unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001723 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001724
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001725 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001726}
1727
Vivien Didelot57d32312016-06-20 13:13:58 -04001728static int
1729mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001730 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001731{
Vivien Didelot04bed142016-08-31 18:06:13 -04001732 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001733 int err;
1734
Tobias Waldekranze545f862020-11-10 19:57:20 +01001735 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001736 return -EOPNOTSUPP;
1737
Vivien Didelotda9c3592016-02-12 12:09:40 -05001738 /* If the requested port doesn't belong to the same bridge as the VLAN
1739 * members, do not support it (yet) and fallback to software VLAN.
1740 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001741 mv88e6xxx_reg_lock(chip);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001742 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001743 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001744
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001745 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001746}
1747
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001748static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1749 const unsigned char *addr, u16 vid,
1750 u8 state)
1751{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001752 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001753 struct mv88e6xxx_vtu_entry vlan;
1754 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001755 int err;
1756
1757 /* Null VLAN ID corresponds to the port private database */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001758 if (vid == 0) {
1759 err = mv88e6xxx_port_get_fid(chip, port, &fid);
1760 if (err)
1761 return err;
1762 } else {
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001763 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001764 if (err)
1765 return err;
1766
1767 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001768 if (!vlan.valid)
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001769 return -EOPNOTSUPP;
1770
1771 fid = vlan.fid;
1772 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001773
Vivien Didelotd8291a92019-09-07 16:00:47 -04001774 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001775 ether_addr_copy(entry.mac, addr);
1776 eth_addr_dec(entry.mac);
1777
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001778 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001779 if (err)
1780 return err;
1781
1782 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001783 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001784 memset(&entry, 0, sizeof(entry));
1785 ether_addr_copy(entry.mac, addr);
1786 }
1787
1788 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001789 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001790 entry.portvec &= ~BIT(port);
1791 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001792 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001793 } else {
DENG Qingfangf72f2fb2021-01-30 21:43:34 +08001794 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
1795 entry.portvec = BIT(port);
1796 else
1797 entry.portvec |= BIT(port);
1798
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001799 entry.state = state;
1800 }
1801
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001802 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001803}
1804
Vivien Didelotda7dc872019-09-07 16:00:49 -04001805static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1806 const struct mv88e6xxx_policy *policy)
1807{
1808 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1809 enum mv88e6xxx_policy_action action = policy->action;
1810 const u8 *addr = policy->addr;
1811 u16 vid = policy->vid;
1812 u8 state;
1813 int err;
1814 int id;
1815
1816 if (!chip->info->ops->port_set_policy)
1817 return -EOPNOTSUPP;
1818
1819 switch (mapping) {
1820 case MV88E6XXX_POLICY_MAPPING_DA:
1821 case MV88E6XXX_POLICY_MAPPING_SA:
1822 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1823 state = 0; /* Dissociate the port and address */
1824 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1825 is_multicast_ether_addr(addr))
1826 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1827 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1828 is_unicast_ether_addr(addr))
1829 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1830 else
1831 return -EOPNOTSUPP;
1832
1833 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1834 state);
1835 if (err)
1836 return err;
1837 break;
1838 default:
1839 return -EOPNOTSUPP;
1840 }
1841
1842 /* Skip the port's policy clearing if the mapping is still in use */
1843 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1844 idr_for_each_entry(&chip->policies, policy, id)
1845 if (policy->port == port &&
1846 policy->mapping == mapping &&
1847 policy->action != action)
1848 return 0;
1849
1850 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1851}
1852
1853static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1854 struct ethtool_rx_flow_spec *fs)
1855{
1856 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1857 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1858 enum mv88e6xxx_policy_mapping mapping;
1859 enum mv88e6xxx_policy_action action;
1860 struct mv88e6xxx_policy *policy;
1861 u16 vid = 0;
1862 u8 *addr;
1863 int err;
1864 int id;
1865
1866 if (fs->location != RX_CLS_LOC_ANY)
1867 return -EINVAL;
1868
1869 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1870 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1871 else
1872 return -EOPNOTSUPP;
1873
1874 switch (fs->flow_type & ~FLOW_EXT) {
1875 case ETHER_FLOW:
1876 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1877 is_zero_ether_addr(mac_mask->h_source)) {
1878 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1879 addr = mac_entry->h_dest;
1880 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1881 !is_zero_ether_addr(mac_mask->h_source)) {
1882 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1883 addr = mac_entry->h_source;
1884 } else {
1885 /* Cannot support DA and SA mapping in the same rule */
1886 return -EOPNOTSUPP;
1887 }
1888 break;
1889 default:
1890 return -EOPNOTSUPP;
1891 }
1892
1893 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001894 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001895 return -EOPNOTSUPP;
1896 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1897 }
1898
1899 idr_for_each_entry(&chip->policies, policy, id) {
1900 if (policy->port == port && policy->mapping == mapping &&
1901 policy->action == action && policy->vid == vid &&
1902 ether_addr_equal(policy->addr, addr))
1903 return -EEXIST;
1904 }
1905
1906 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1907 if (!policy)
1908 return -ENOMEM;
1909
1910 fs->location = 0;
1911 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1912 GFP_KERNEL);
1913 if (err) {
1914 devm_kfree(chip->dev, policy);
1915 return err;
1916 }
1917
1918 memcpy(&policy->fs, fs, sizeof(*fs));
1919 ether_addr_copy(policy->addr, addr);
1920 policy->mapping = mapping;
1921 policy->action = action;
1922 policy->port = port;
1923 policy->vid = vid;
1924
1925 err = mv88e6xxx_policy_apply(chip, port, policy);
1926 if (err) {
1927 idr_remove(&chip->policies, fs->location);
1928 devm_kfree(chip->dev, policy);
1929 return err;
1930 }
1931
1932 return 0;
1933}
1934
1935static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1936 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1937{
1938 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1939 struct mv88e6xxx_chip *chip = ds->priv;
1940 struct mv88e6xxx_policy *policy;
1941 int err;
1942 int id;
1943
1944 mv88e6xxx_reg_lock(chip);
1945
1946 switch (rxnfc->cmd) {
1947 case ETHTOOL_GRXCLSRLCNT:
1948 rxnfc->data = 0;
1949 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1950 rxnfc->rule_cnt = 0;
1951 idr_for_each_entry(&chip->policies, policy, id)
1952 if (policy->port == port)
1953 rxnfc->rule_cnt++;
1954 err = 0;
1955 break;
1956 case ETHTOOL_GRXCLSRULE:
1957 err = -ENOENT;
1958 policy = idr_find(&chip->policies, fs->location);
1959 if (policy) {
1960 memcpy(fs, &policy->fs, sizeof(*fs));
1961 err = 0;
1962 }
1963 break;
1964 case ETHTOOL_GRXCLSRLALL:
1965 rxnfc->data = 0;
1966 rxnfc->rule_cnt = 0;
1967 idr_for_each_entry(&chip->policies, policy, id)
1968 if (policy->port == port)
1969 rule_locs[rxnfc->rule_cnt++] = id;
1970 err = 0;
1971 break;
1972 default:
1973 err = -EOPNOTSUPP;
1974 break;
1975 }
1976
1977 mv88e6xxx_reg_unlock(chip);
1978
1979 return err;
1980}
1981
1982static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1983 struct ethtool_rxnfc *rxnfc)
1984{
1985 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1986 struct mv88e6xxx_chip *chip = ds->priv;
1987 struct mv88e6xxx_policy *policy;
1988 int err;
1989
1990 mv88e6xxx_reg_lock(chip);
1991
1992 switch (rxnfc->cmd) {
1993 case ETHTOOL_SRXCLSRLINS:
1994 err = mv88e6xxx_policy_insert(chip, port, fs);
1995 break;
1996 case ETHTOOL_SRXCLSRLDEL:
1997 err = -ENOENT;
1998 policy = idr_remove(&chip->policies, fs->location);
1999 if (policy) {
2000 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
2001 err = mv88e6xxx_policy_apply(chip, port, policy);
2002 devm_kfree(chip->dev, policy);
2003 }
2004 break;
2005 default:
2006 err = -EOPNOTSUPP;
2007 break;
2008 }
2009
2010 mv88e6xxx_reg_unlock(chip);
2011
2012 return err;
2013}
2014
Andrew Lunn87fa8862017-11-09 22:29:56 +01002015static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
2016 u16 vid)
2017{
Andrew Lunn87fa8862017-11-09 22:29:56 +01002018 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
Tobias Waldekranz0806dd462021-03-18 20:25:37 +01002019 u8 broadcast[ETH_ALEN];
2020
2021 eth_broadcast_addr(broadcast);
Andrew Lunn87fa8862017-11-09 22:29:56 +01002022
2023 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
2024}
2025
2026static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
2027{
2028 int port;
2029 int err;
2030
2031 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01002032 struct dsa_port *dp = dsa_to_port(chip->ds, port);
2033 struct net_device *brport;
2034
2035 if (dsa_is_unused_port(chip->ds, port))
2036 continue;
2037
2038 brport = dsa_port_to_bridge_port(dp);
2039 if (brport && !br_port_flag_is_set(brport, BR_BCAST_FLOOD))
2040 /* Skip bridged user ports where broadcast
2041 * flooding is disabled.
2042 */
2043 continue;
2044
Andrew Lunn87fa8862017-11-09 22:29:56 +01002045 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
2046 if (err)
2047 return err;
2048 }
2049
2050 return 0;
2051}
2052
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01002053struct mv88e6xxx_port_broadcast_sync_ctx {
2054 int port;
2055 bool flood;
2056};
2057
2058static int
2059mv88e6xxx_port_broadcast_sync_vlan(struct mv88e6xxx_chip *chip,
2060 const struct mv88e6xxx_vtu_entry *vlan,
2061 void *_ctx)
2062{
2063 struct mv88e6xxx_port_broadcast_sync_ctx *ctx = _ctx;
2064 u8 broadcast[ETH_ALEN];
2065 u8 state;
2066
2067 if (ctx->flood)
2068 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
2069 else
2070 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_UNUSED;
2071
2072 eth_broadcast_addr(broadcast);
2073
2074 return mv88e6xxx_port_db_load_purge(chip, ctx->port, broadcast,
2075 vlan->vid, state);
2076}
2077
2078static int mv88e6xxx_port_broadcast_sync(struct mv88e6xxx_chip *chip, int port,
2079 bool flood)
2080{
2081 struct mv88e6xxx_port_broadcast_sync_ctx ctx = {
2082 .port = port,
2083 .flood = flood,
2084 };
2085 struct mv88e6xxx_vtu_entry vid0 = {
2086 .vid = 0,
2087 };
2088 int err;
2089
2090 /* Update the port's private database... */
2091 err = mv88e6xxx_port_broadcast_sync_vlan(chip, &vid0, &ctx);
2092 if (err)
2093 return err;
2094
2095 /* ...and the database for all VLANs. */
2096 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_broadcast_sync_vlan,
2097 &ctx);
2098}
2099
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002100static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00002101 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002102{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002103 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002104 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002105 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002106
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002107 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002108 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002109 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002110
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002111 if (!vlan.valid) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002112 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002113
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002114 err = mv88e6xxx_atu_new(chip, &vlan.fid);
2115 if (err)
2116 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01002117
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002118 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
2119 if (i == port)
2120 vlan.member[i] = member;
2121 else
2122 vlan.member[i] = non_member;
2123
2124 vlan.vid = vid;
2125 vlan.valid = true;
2126
2127 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2128 if (err)
2129 return err;
2130
2131 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
2132 if (err)
2133 return err;
2134 } else if (vlan.member[port] != member) {
2135 vlan.member[port] = member;
2136
2137 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2138 if (err)
2139 return err;
Russell King933b4422020-02-26 17:14:26 +00002140 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002141 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
2142 port, vid);
2143 }
2144
2145 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002146}
2147
Vladimir Oltean1958d582021-01-09 02:01:53 +02002148static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vladimir Oltean31046a52021-02-13 22:43:18 +02002149 const struct switchdev_obj_port_vlan *vlan,
2150 struct netlink_ext_ack *extack)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002151{
Vivien Didelot04bed142016-08-31 18:06:13 -04002152 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002153 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
2154 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002155 struct mv88e6xxx_port *p = &chip->ports[port];
Russell King933b4422020-02-26 17:14:26 +00002156 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002157 u8 member;
Vladimir Oltean1958d582021-01-09 02:01:53 +02002158 int err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002159
Eldar Gasanovb8b79c42021-06-21 11:54:38 +03002160 if (!vlan->vid)
2161 return 0;
2162
Vladimir Oltean1958d582021-01-09 02:01:53 +02002163 err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
2164 if (err)
2165 return err;
Vivien Didelot54d77b52016-05-09 13:22:47 -04002166
Vivien Didelotc91498e2017-06-07 18:12:13 -04002167 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002168 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002169 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002170 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002171 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002172 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002173
Russell King933b4422020-02-26 17:14:26 +00002174 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
2175 * and then the CPU port. Do not warn for duplicates for the CPU port.
2176 */
2177 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
2178
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002179 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002180
Vladimir Oltean1958d582021-01-09 02:01:53 +02002181 err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
2182 if (err) {
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002183 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2184 vlan->vid, untagged ? 'u' : 't');
Vladimir Oltean1958d582021-01-09 02:01:53 +02002185 goto out;
2186 }
Vivien Didelot76e398a2015-11-01 12:33:55 -05002187
Vladimir Oltean1958d582021-01-09 02:01:53 +02002188 if (pvid) {
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002189 p->bridge_pvid.vid = vlan->vid;
2190 p->bridge_pvid.valid = true;
2191
2192 err = mv88e6xxx_port_commit_pvid(chip, port);
2193 if (err)
Vladimir Oltean1958d582021-01-09 02:01:53 +02002194 goto out;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002195 } else if (vlan->vid && p->bridge_pvid.vid == vlan->vid) {
2196 /* The old pvid was reinstalled as a non-pvid VLAN */
2197 p->bridge_pvid.valid = false;
2198
2199 err = mv88e6xxx_port_commit_pvid(chip, port);
2200 if (err)
2201 goto out;
Vladimir Oltean1958d582021-01-09 02:01:53 +02002202 }
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002203
Vladimir Oltean1958d582021-01-09 02:01:53 +02002204out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002205 mv88e6xxx_reg_unlock(chip);
Vladimir Oltean1958d582021-01-09 02:01:53 +02002206
2207 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002208}
2209
Vivien Didelot521098922019-08-01 14:36:36 -04002210static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2211 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002212{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002213 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002214 int i, err;
2215
Vivien Didelot521098922019-08-01 14:36:36 -04002216 if (!vid)
Vladimir Olteanc92c7412021-07-22 16:05:51 +03002217 return 0;
Vivien Didelot521098922019-08-01 14:36:36 -04002218
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002219 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002220 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002221 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002222
Vivien Didelot521098922019-08-01 14:36:36 -04002223 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2224 * tell switchdev that this VLAN is likely handled in software.
2225 */
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002226 if (!vlan.valid ||
Vivien Didelot521098922019-08-01 14:36:36 -04002227 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002228 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002229
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002230 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002231
2232 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002233 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002234 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002235 if (vlan.member[i] !=
2236 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002237 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002238 break;
2239 }
2240 }
2241
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002242 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002243 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002244 return err;
2245
Vivien Didelote606ca32017-03-11 16:12:55 -05002246 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002247}
2248
Vivien Didelotf81ec902016-05-09 13:22:58 -04002249static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2250 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002251{
Vivien Didelot04bed142016-08-31 18:06:13 -04002252 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002253 struct mv88e6xxx_port *p = &chip->ports[port];
Vivien Didelot76e398a2015-11-01 12:33:55 -05002254 int err = 0;
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002255 u16 pvid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002256
Tobias Waldekranze545f862020-11-10 19:57:20 +01002257 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04002258 return -EOPNOTSUPP;
2259
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002260 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002261
Vivien Didelot77064f32016-11-04 03:23:30 +01002262 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002263 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002264 goto unlock;
2265
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002266 err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
2267 if (err)
2268 goto unlock;
2269
2270 if (vlan->vid == pvid) {
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002271 p->bridge_pvid.valid = false;
2272
2273 err = mv88e6xxx_port_commit_pvid(chip, port);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002274 if (err)
2275 goto unlock;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002276 }
2277
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002278unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002279 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002280
2281 return err;
2282}
2283
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002284static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2285 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002286{
Vivien Didelot04bed142016-08-31 18:06:13 -04002287 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002288 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002289
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002290 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002291 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2292 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002293 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002294
2295 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002296}
2297
Vivien Didelotf81ec902016-05-09 13:22:58 -04002298static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002299 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002300{
Vivien Didelot04bed142016-08-31 18:06:13 -04002301 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002302 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002303
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002304 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002305 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002306 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002307
Vivien Didelot83dabd12016-08-31 11:50:04 -04002308 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002309}
2310
Vivien Didelot83dabd12016-08-31 11:50:04 -04002311static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2312 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002313 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002314{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002315 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002316 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002317 int err;
2318
Vivien Didelotd8291a92019-09-07 16:00:47 -04002319 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002320 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002321
2322 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002323 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002324 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002325 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002326
Vivien Didelotd8291a92019-09-07 16:00:47 -04002327 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002328 break;
2329
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002330 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002331 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002332
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002333 if (!is_unicast_ether_addr(addr.mac))
2334 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002335
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002336 is_static = (addr.state ==
2337 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2338 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002339 if (err)
2340 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002341 } while (!is_broadcast_ether_addr(addr.mac));
2342
2343 return err;
2344}
2345
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002346struct mv88e6xxx_port_db_dump_vlan_ctx {
2347 int port;
2348 dsa_fdb_dump_cb_t *cb;
2349 void *data;
2350};
2351
2352static int mv88e6xxx_port_db_dump_vlan(struct mv88e6xxx_chip *chip,
2353 const struct mv88e6xxx_vtu_entry *entry,
2354 void *_data)
2355{
2356 struct mv88e6xxx_port_db_dump_vlan_ctx *ctx = _data;
2357
2358 return mv88e6xxx_port_db_dump_fid(chip, entry->fid, entry->vid,
2359 ctx->port, ctx->cb, ctx->data);
2360}
2361
Vivien Didelot83dabd12016-08-31 11:50:04 -04002362static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002363 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002364{
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002365 struct mv88e6xxx_port_db_dump_vlan_ctx ctx = {
2366 .port = port,
2367 .cb = cb,
2368 .data = data,
2369 };
Vivien Didelot83dabd12016-08-31 11:50:04 -04002370 u16 fid;
2371 int err;
2372
2373 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002374 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002375 if (err)
2376 return err;
2377
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002378 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002379 if (err)
2380 return err;
2381
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002382 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_db_dump_vlan, &ctx);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002383}
2384
Vivien Didelotf81ec902016-05-09 13:22:58 -04002385static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002386 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002387{
Vivien Didelot04bed142016-08-31 18:06:13 -04002388 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002389 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002390
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002391 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002392 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002393 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002394
2395 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002396}
2397
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002398static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2399 struct net_device *br)
2400{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002401 struct dsa_switch *ds = chip->ds;
2402 struct dsa_switch_tree *dst = ds->dst;
2403 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002404 int err;
2405
Vivien Didelotef2025e2019-10-21 16:51:27 -04002406 list_for_each_entry(dp, &dst->ports, list) {
2407 if (dp->bridge_dev == br) {
2408 if (dp->ds == ds) {
2409 /* This is a local bridge group member,
2410 * remap its Port VLAN Map.
2411 */
2412 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2413 if (err)
2414 return err;
2415 } else {
2416 /* This is an external bridge group member,
2417 * remap its cross-chip Port VLAN Table entry.
2418 */
2419 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2420 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002421 if (err)
2422 return err;
2423 }
2424 }
2425 }
2426
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002427 return 0;
2428}
2429
Vivien Didelotf81ec902016-05-09 13:22:58 -04002430static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002431 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002432{
Vivien Didelot04bed142016-08-31 18:06:13 -04002433 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002434 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002435
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002436 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002437 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002438 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002439
Vivien Didelot466dfa02016-02-26 13:16:05 -05002440 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002441}
2442
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002443static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2444 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002445{
Vivien Didelot04bed142016-08-31 18:06:13 -04002446 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002447
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002448 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002449 if (mv88e6xxx_bridge_map(chip, br) ||
2450 mv88e6xxx_port_vlan_map(chip, port))
2451 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002452 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002453}
2454
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002455static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2456 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002457 int port, struct net_device *br)
2458{
2459 struct mv88e6xxx_chip *chip = ds->priv;
2460 int err;
2461
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002462 if (tree_index != ds->dst->index)
2463 return 0;
2464
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002465 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002466 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002467 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002468
2469 return err;
2470}
2471
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002472static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2473 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002474 int port, struct net_device *br)
2475{
2476 struct mv88e6xxx_chip *chip = ds->priv;
2477
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002478 if (tree_index != ds->dst->index)
2479 return;
2480
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002481 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002482 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002483 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002484 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002485}
2486
Vladimir Olteance5df682021-07-22 18:55:41 +03002487/* Treat the software bridge as a virtual single-port switch behind the
2488 * CPU and map in the PVT. First dst->last_switch elements are taken by
2489 * physical switches, so start from beyond that range.
2490 */
2491static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
2492 int bridge_num)
2493{
2494 u8 dev = bridge_num + ds->dst->last_switch + 1;
2495 struct mv88e6xxx_chip *chip = ds->priv;
2496 int err;
2497
2498 mv88e6xxx_reg_lock(chip);
2499 err = mv88e6xxx_pvt_map(chip, dev, 0);
2500 mv88e6xxx_reg_unlock(chip);
2501
2502 return err;
2503}
2504
2505static int mv88e6xxx_bridge_tx_fwd_offload(struct dsa_switch *ds, int port,
2506 struct net_device *br,
2507 int bridge_num)
2508{
2509 return mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
2510}
2511
2512static void mv88e6xxx_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port,
2513 struct net_device *br,
2514 int bridge_num)
2515{
2516 int err;
2517
2518 err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
2519 if (err) {
2520 dev_err(ds->dev, "failed to remap cross-chip Port VLAN: %pe\n",
2521 ERR_PTR(err));
2522 }
2523}
2524
Vivien Didelot17e708b2016-12-05 17:30:27 -05002525static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2526{
2527 if (chip->info->ops->reset)
2528 return chip->info->ops->reset(chip);
2529
2530 return 0;
2531}
2532
Vivien Didelot309eca62016-12-05 17:30:26 -05002533static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2534{
2535 struct gpio_desc *gpiod = chip->reset;
2536
2537 /* If there is a GPIO connected to the reset pin, toggle it */
2538 if (gpiod) {
2539 gpiod_set_value_cansleep(gpiod, 1);
2540 usleep_range(10000, 20000);
2541 gpiod_set_value_cansleep(gpiod, 0);
2542 usleep_range(10000, 20000);
Andrew Lunna3dcb3e2020-11-16 08:43:01 -08002543
2544 mv88e6xxx_g1_wait_eeprom_done(chip);
Vivien Didelot309eca62016-12-05 17:30:26 -05002545 }
2546}
2547
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002548static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2549{
2550 int i, err;
2551
2552 /* Set all ports to the Disabled state */
2553 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002554 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002555 if (err)
2556 return err;
2557 }
2558
2559 /* Wait for transmit queues to drain,
2560 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2561 */
2562 usleep_range(2000, 4000);
2563
2564 return 0;
2565}
2566
Vivien Didelotfad09c72016-06-21 12:28:20 -04002567static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002568{
Vivien Didelota935c052016-09-29 12:21:53 -04002569 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002570
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002571 err = mv88e6xxx_disable_ports(chip);
2572 if (err)
2573 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002574
Vivien Didelot309eca62016-12-05 17:30:26 -05002575 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002576
Vivien Didelot17e708b2016-12-05 17:30:27 -05002577 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002578}
2579
Vivien Didelot43145572017-03-11 16:12:59 -05002580static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002581 enum mv88e6xxx_frame_mode frame,
2582 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002583{
2584 int err;
2585
Vivien Didelot43145572017-03-11 16:12:59 -05002586 if (!chip->info->ops->port_set_frame_mode)
2587 return -EOPNOTSUPP;
2588
2589 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002590 if (err)
2591 return err;
2592
Vivien Didelot43145572017-03-11 16:12:59 -05002593 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2594 if (err)
2595 return err;
2596
2597 if (chip->info->ops->port_set_ether_type)
2598 return chip->info->ops->port_set_ether_type(chip, port, etype);
2599
2600 return 0;
2601}
2602
2603static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2604{
2605 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002606 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002607 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002608}
2609
2610static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2611{
2612 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002613 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002614 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002615}
2616
2617static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2618{
2619 return mv88e6xxx_set_port_mode(chip, port,
2620 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002621 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2622 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002623}
2624
2625static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2626{
2627 if (dsa_is_dsa_port(chip->ds, port))
2628 return mv88e6xxx_set_port_mode_dsa(chip, port);
2629
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002630 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002631 return mv88e6xxx_set_port_mode_normal(chip, port);
2632
2633 /* Setup CPU port mode depending on its supported tag format */
Tobias Waldekranz670bb802021-04-20 20:53:07 +02002634 if (chip->tag_protocol == DSA_TAG_PROTO_DSA)
Vivien Didelot43145572017-03-11 16:12:59 -05002635 return mv88e6xxx_set_port_mode_dsa(chip, port);
2636
Tobias Waldekranz670bb802021-04-20 20:53:07 +02002637 if (chip->tag_protocol == DSA_TAG_PROTO_EDSA)
Vivien Didelot43145572017-03-11 16:12:59 -05002638 return mv88e6xxx_set_port_mode_edsa(chip, port);
2639
2640 return -EINVAL;
2641}
2642
Vivien Didelotea698f42017-03-11 16:12:50 -05002643static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2644{
2645 bool message = dsa_is_dsa_port(chip->ds, port);
2646
2647 return mv88e6xxx_port_set_message_port(chip, port, message);
2648}
2649
Vivien Didelot601aeed2017-03-11 16:13:00 -05002650static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2651{
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002652 int err;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002653
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002654 if (chip->info->ops->port_set_ucast_flood) {
Tobias Waldekranz7b9f16f2021-03-18 20:25:38 +01002655 err = chip->info->ops->port_set_ucast_flood(chip, port, true);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002656 if (err)
2657 return err;
2658 }
2659 if (chip->info->ops->port_set_mcast_flood) {
Tobias Waldekranz7b9f16f2021-03-18 20:25:38 +01002660 err = chip->info->ops->port_set_mcast_flood(chip, port, true);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002661 if (err)
2662 return err;
2663 }
Vivien Didelot601aeed2017-03-11 16:13:00 -05002664
David S. Miller407308f2019-06-15 13:35:29 -07002665 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002666}
2667
Vivien Didelot45de77f2019-08-31 16:18:36 -04002668static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2669{
2670 struct mv88e6xxx_port *mvp = dev_id;
2671 struct mv88e6xxx_chip *chip = mvp->chip;
2672 irqreturn_t ret = IRQ_NONE;
2673 int port = mvp->port;
Pavana Sharma193c5b22021-03-17 14:46:40 +01002674 int lane;
Vivien Didelot45de77f2019-08-31 16:18:36 -04002675
2676 mv88e6xxx_reg_lock(chip);
2677 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002678 if (lane >= 0)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002679 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2680 mv88e6xxx_reg_unlock(chip);
2681
2682 return ret;
2683}
2684
2685static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002686 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002687{
2688 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2689 unsigned int irq;
2690 int err;
2691
2692 /* Nothing to request if this SERDES port has no IRQ */
2693 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2694 if (!irq)
2695 return 0;
2696
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002697 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2698 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2699
Vivien Didelot45de77f2019-08-31 16:18:36 -04002700 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2701 mv88e6xxx_reg_unlock(chip);
2702 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002703 IRQF_ONESHOT, dev_id->serdes_irq_name,
2704 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002705 mv88e6xxx_reg_lock(chip);
2706 if (err)
2707 return err;
2708
2709 dev_id->serdes_irq = irq;
2710
2711 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2712}
2713
2714static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002715 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002716{
2717 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2718 unsigned int irq = dev_id->serdes_irq;
2719 int err;
2720
2721 /* Nothing to free if no IRQ has been requested */
2722 if (!irq)
2723 return 0;
2724
2725 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2726
2727 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2728 mv88e6xxx_reg_unlock(chip);
2729 free_irq(irq, dev_id);
2730 mv88e6xxx_reg_lock(chip);
2731
2732 dev_id->serdes_irq = 0;
2733
2734 return err;
2735}
2736
Andrew Lunn6d917822017-05-26 01:03:21 +02002737static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2738 bool on)
2739{
Pavana Sharma193c5b22021-03-17 14:46:40 +01002740 int lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002741 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002742
Vivien Didelotdc272f62019-08-31 16:18:33 -04002743 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002744 if (lane < 0)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002745 return 0;
2746
2747 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002748 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002749 if (err)
2750 return err;
2751
Vivien Didelot45de77f2019-08-31 16:18:36 -04002752 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002753 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002754 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2755 if (err)
2756 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002757
Vivien Didelotdc272f62019-08-31 16:18:33 -04002758 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002759 }
2760
2761 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002762}
2763
Marek Behún2fda45f2021-03-17 14:46:41 +01002764static int mv88e6xxx_set_egress_port(struct mv88e6xxx_chip *chip,
2765 enum mv88e6xxx_egress_direction direction,
2766 int port)
2767{
2768 int err;
2769
2770 if (!chip->info->ops->set_egress_port)
2771 return -EOPNOTSUPP;
2772
2773 err = chip->info->ops->set_egress_port(chip, direction, port);
2774 if (err)
2775 return err;
2776
2777 if (direction == MV88E6XXX_EGRESS_DIR_INGRESS)
2778 chip->ingress_dest_port = port;
2779 else
2780 chip->egress_dest_port = port;
2781
2782 return 0;
2783}
2784
Vivien Didelotfa371c82017-12-05 15:34:10 -05002785static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2786{
2787 struct dsa_switch *ds = chip->ds;
2788 int upstream_port;
2789 int err;
2790
Vivien Didelot07073c72017-12-05 15:34:13 -05002791 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002792 if (chip->info->ops->port_set_upstream_port) {
2793 err = chip->info->ops->port_set_upstream_port(chip, port,
2794 upstream_port);
2795 if (err)
2796 return err;
2797 }
2798
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002799 if (port == upstream_port) {
2800 if (chip->info->ops->set_cpu_port) {
2801 err = chip->info->ops->set_cpu_port(chip,
2802 upstream_port);
2803 if (err)
2804 return err;
2805 }
2806
Marek Behún2fda45f2021-03-17 14:46:41 +01002807 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002808 MV88E6XXX_EGRESS_DIR_INGRESS,
2809 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002810 if (err && err != -EOPNOTSUPP)
2811 return err;
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002812
Marek Behún2fda45f2021-03-17 14:46:41 +01002813 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002814 MV88E6XXX_EGRESS_DIR_EGRESS,
2815 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002816 if (err && err != -EOPNOTSUPP)
2817 return err;
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002818 }
2819
Vivien Didelotfa371c82017-12-05 15:34:10 -05002820 return 0;
2821}
2822
Vivien Didelotfad09c72016-06-21 12:28:20 -04002823static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002824{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002825 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002826 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002827 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002828
Andrew Lunn7b898462018-08-09 15:38:47 +02002829 chip->ports[port].chip = chip;
2830 chip->ports[port].port = port;
2831
Vivien Didelotd78343d2016-11-04 03:23:36 +01002832 /* MAC Forcing register: don't force link, speed, duplex or flow control
2833 * state to any particular values on physical ports, but force the CPU
2834 * port and all DSA ports to their maximum bandwidth and full duplex.
2835 */
2836 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2837 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2838 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002839 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002840 PHY_INTERFACE_MODE_NA);
2841 else
2842 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2843 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002844 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002845 PHY_INTERFACE_MODE_NA);
2846 if (err)
2847 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002848
2849 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2850 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2851 * tunneling, determine priority by looking at 802.1p and IP
2852 * priority fields (IP prio has precedence), and set STP state
2853 * to Forwarding.
2854 *
2855 * If this is the CPU link, use DSA or EDSA tagging depending
2856 * on which tagging mode was configured.
2857 *
2858 * If this is a link to another switch, use DSA tagging mode.
2859 *
2860 * If this is the upstream port for this switch, enable
2861 * forwarding of unknown unicasts and multicasts.
2862 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002863 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2864 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2865 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2866 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002867 if (err)
2868 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002869
Vivien Didelot601aeed2017-03-11 16:13:00 -05002870 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002871 if (err)
2872 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002873
Vivien Didelot601aeed2017-03-11 16:13:00 -05002874 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002875 if (err)
2876 return err;
2877
Andrew Lunnb92ce2f2021-09-26 19:41:25 +02002878 /* Port Control 2: don't force a good FCS, set the MTU size to
2879 * 10222 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002880 * untagged frames on this port, do a destination address lookup on all
2881 * received packets as usual, disable ARP mirroring and don't send a
2882 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002883 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002884 err = mv88e6xxx_port_set_map_da(chip, port);
2885 if (err)
2886 return err;
2887
Vivien Didelotfa371c82017-12-05 15:34:10 -05002888 err = mv88e6xxx_setup_upstream_port(chip, port);
2889 if (err)
2890 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002891
Andrew Lunna23b2962017-02-04 20:15:28 +01002892 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002893 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002894 if (err)
2895 return err;
2896
Vivien Didelotcd782652017-06-08 18:34:13 -04002897 if (chip->info->ops->port_set_jumbo_size) {
Andrew Lunnb92ce2f2021-09-26 19:41:25 +02002898 err = chip->info->ops->port_set_jumbo_size(chip, port, 10218);
Andrew Lunn5f436662016-12-03 04:45:17 +01002899 if (err)
2900 return err;
2901 }
2902
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002903 /* Port Association Vector: disable automatic address learning
2904 * on all user ports since they start out in standalone
2905 * mode. When joining a bridge, learning will be configured to
2906 * match the bridge port settings. Enable learning on all
2907 * DSA/CPU ports. NOTE: FROM_CPU frames always bypass the
2908 * learning process.
2909 *
2910 * Disable HoldAt1, IntOnAgeOut, LockedPort, IgnoreWrongData,
2911 * and RefreshLocked. I.e. setup standard automatic learning.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002912 */
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002913 if (dsa_is_user_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002914 reg = 0;
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002915 else
2916 reg = 1 << port;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002917
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002918 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2919 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002920 if (err)
2921 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002922
2923 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002924 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2925 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002926 if (err)
2927 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002928
Vivien Didelot08984322017-06-08 18:34:12 -04002929 if (chip->info->ops->port_pause_limit) {
2930 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002931 if (err)
2932 return err;
2933 }
2934
Vivien Didelotc8c94892017-03-11 16:13:01 -05002935 if (chip->info->ops->port_disable_learn_limit) {
2936 err = chip->info->ops->port_disable_learn_limit(chip, port);
2937 if (err)
2938 return err;
2939 }
2940
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002941 if (chip->info->ops->port_disable_pri_override) {
2942 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002943 if (err)
2944 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002945 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002946
Andrew Lunnef0a7312016-12-03 04:35:16 +01002947 if (chip->info->ops->port_tag_remap) {
2948 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002949 if (err)
2950 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002951 }
2952
Andrew Lunnef70b112016-12-03 04:45:18 +01002953 if (chip->info->ops->port_egress_rate_limiting) {
2954 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002955 if (err)
2956 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002957 }
2958
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002959 if (chip->info->ops->port_setup_message_port) {
2960 err = chip->info->ops->port_setup_message_port(chip, port);
2961 if (err)
2962 return err;
2963 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002964
Vivien Didelot207afda2016-04-14 14:42:09 -04002965 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002966 * database, and allow bidirectional communication between the
2967 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002968 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002969 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002970 if (err)
2971 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002972
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002973 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002974 if (err)
2975 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002976
2977 /* Default VLAN ID and priority: don't set a default VLAN
2978 * ID, and set the default packet priority to zero.
2979 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002980 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002981}
2982
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002983static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
2984{
2985 struct mv88e6xxx_chip *chip = ds->priv;
2986
2987 if (chip->info->ops->port_set_jumbo_size)
Andrew Lunnb9c587f2021-09-26 19:41:26 +02002988 return 10240 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
Chris Packham1baf0fa2020-07-24 11:21:22 +12002989 else if (chip->info->ops->set_max_frame_size)
Andrew Lunnb9c587f2021-09-26 19:41:26 +02002990 return 1632 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
2991 return 1522 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002992}
2993
2994static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
2995{
2996 struct mv88e6xxx_chip *chip = ds->priv;
2997 int ret = 0;
2998
Andrew Lunnb9c587f2021-09-26 19:41:26 +02002999 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
3000 new_mtu += EDSA_HLEN;
3001
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003002 mv88e6xxx_reg_lock(chip);
3003 if (chip->info->ops->port_set_jumbo_size)
3004 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12003005 else if (chip->info->ops->set_max_frame_size)
3006 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003007 else
3008 if (new_mtu > 1522)
3009 ret = -EINVAL;
3010 mv88e6xxx_reg_unlock(chip);
3011
3012 return ret;
3013}
3014
Andrew Lunn04aca992017-05-26 01:03:24 +02003015static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
3016 struct phy_device *phydev)
3017{
3018 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04003019 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02003020
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003021 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04003022 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003023 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02003024
3025 return err;
3026}
3027
Andrew Lunn75104db2019-02-24 20:44:43 +01003028static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02003029{
3030 struct mv88e6xxx_chip *chip = ds->priv;
3031
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003032 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04003033 if (mv88e6xxx_serdes_power(chip, port, false))
3034 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003035 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02003036}
3037
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003038static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
3039 unsigned int ageing_time)
3040{
Vivien Didelot04bed142016-08-31 18:06:13 -04003041 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003042 int err;
3043
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003044 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05003045 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003046 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003047
3048 return err;
3049}
3050
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003051static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04003052{
3053 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04003054
Andrew Lunnde2273872016-11-21 23:27:01 +01003055 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003056 if (chip->info->ops->stats_set_histogram) {
3057 err = chip->info->ops->stats_set_histogram(chip);
3058 if (err)
3059 return err;
3060 }
Andrew Lunnde2273872016-11-21 23:27:01 +01003061
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003062 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04003063}
3064
Andrew Lunnea890982019-01-09 00:24:03 +01003065/* Check if the errata has already been applied. */
3066static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
3067{
3068 int port;
3069 int err;
3070 u16 val;
3071
3072 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02003073 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01003074 if (err) {
3075 dev_err(chip->dev,
3076 "Error reading hidden register: %d\n", err);
3077 return false;
3078 }
3079 if (val != 0x01c0)
3080 return false;
3081 }
3082
3083 return true;
3084}
3085
3086/* The 6390 copper ports have an errata which require poking magic
3087 * values into undocumented hidden registers and then performing a
3088 * software reset.
3089 */
3090static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
3091{
3092 int port;
3093 int err;
3094
3095 if (mv88e6390_setup_errata_applied(chip))
3096 return 0;
3097
3098 /* Set the ports into blocking mode */
3099 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
3100 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
3101 if (err)
3102 return err;
3103 }
3104
3105 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02003106 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01003107 if (err)
3108 return err;
3109 }
3110
3111 return mv88e6xxx_software_reset(chip);
3112}
3113
Andrew Lunn23e8b472019-10-25 01:03:52 +02003114static void mv88e6xxx_teardown(struct dsa_switch *ds)
3115{
3116 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003117 dsa_devlink_resources_unregister(ds);
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003118 mv88e6xxx_teardown_devlink_regions_global(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02003119}
3120
Vivien Didelotf81ec902016-05-09 13:22:58 -04003121static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07003122{
Vivien Didelot04bed142016-08-31 18:06:13 -04003123 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003124 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04003125 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04003126 int i;
3127
Vivien Didelotfad09c72016-06-21 12:28:20 -04003128 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003129 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003130
Vladimir Olteance5df682021-07-22 18:55:41 +03003131 /* Since virtual bridges are mapped in the PVT, the number we support
3132 * depends on the physical switch topology. We need to let DSA figure
3133 * that out and therefore we cannot set this at dsa_register_switch()
3134 * time.
3135 */
3136 if (mv88e6xxx_has_pvt(chip))
3137 ds->num_fwd_offloading_bridges = MV88E6XXX_MAX_PVT_SWITCHES -
3138 ds->dst->last_switch - 1;
3139
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003140 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003141
Andrew Lunnea890982019-01-09 00:24:03 +01003142 if (chip->info->ops->setup_errata) {
3143 err = chip->info->ops->setup_errata(chip);
3144 if (err)
3145 goto unlock;
3146 }
3147
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003148 /* Cache the cmode of each port. */
3149 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3150 if (chip->info->ops->port_get_cmode) {
3151 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
3152 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03003153 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003154
3155 chip->ports[i].cmode = cmode;
3156 }
3157 }
3158
Vivien Didelot97299342016-07-18 20:45:30 -04003159 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04003160 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04003161 if (dsa_is_unused_port(ds, i))
3162 continue;
3163
Hubert Feursteinc8574862019-07-31 10:23:48 +02003164 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04003165 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02003166 dev_err(chip->dev, "port %d is invalid\n", i);
3167 err = -EINVAL;
3168 goto unlock;
3169 }
3170
Vivien Didelot97299342016-07-18 20:45:30 -04003171 err = mv88e6xxx_setup_port(chip, i);
3172 if (err)
3173 goto unlock;
3174 }
3175
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003176 err = mv88e6xxx_irl_setup(chip);
3177 if (err)
3178 goto unlock;
3179
Vivien Didelot04a69a12017-10-13 14:18:05 -04003180 err = mv88e6xxx_mac_setup(chip);
3181 if (err)
3182 goto unlock;
3183
Vivien Didelot1b17aed2017-05-26 18:03:05 -04003184 err = mv88e6xxx_phy_setup(chip);
3185 if (err)
3186 goto unlock;
3187
Vivien Didelotb486d7c2017-05-01 14:05:13 -04003188 err = mv88e6xxx_vtu_setup(chip);
3189 if (err)
3190 goto unlock;
3191
Vivien Didelot81228992017-03-30 17:37:08 -04003192 err = mv88e6xxx_pvt_setup(chip);
3193 if (err)
3194 goto unlock;
3195
Vivien Didelota2ac29d2017-03-11 16:12:49 -05003196 err = mv88e6xxx_atu_setup(chip);
3197 if (err)
3198 goto unlock;
3199
Andrew Lunn87fa8862017-11-09 22:29:56 +01003200 err = mv88e6xxx_broadcast_setup(chip, 0);
3201 if (err)
3202 goto unlock;
3203
Vivien Didelot9e907d72017-07-17 13:03:43 -04003204 err = mv88e6xxx_pot_setup(chip);
3205 if (err)
3206 goto unlock;
3207
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003208 err = mv88e6xxx_rmu_setup(chip);
3209 if (err)
3210 goto unlock;
3211
Vivien Didelot51c901a2017-07-17 13:03:41 -04003212 err = mv88e6xxx_rsvd2cpu_setup(chip);
3213 if (err)
3214 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01003215
Vivien Didelotb28f8722018-04-26 21:56:44 -04003216 err = mv88e6xxx_trunk_setup(chip);
3217 if (err)
3218 goto unlock;
3219
Vivien Didelotc7f047b2018-04-26 21:56:45 -04003220 err = mv88e6xxx_devmap_setup(chip);
3221 if (err)
3222 goto unlock;
3223
Vivien Didelot93e18d62018-05-11 17:16:35 -04003224 err = mv88e6xxx_pri_setup(chip);
3225 if (err)
3226 goto unlock;
3227
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003228 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003229 if (chip->info->ptp_support) {
3230 err = mv88e6xxx_ptp_setup(chip);
3231 if (err)
3232 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003233
3234 err = mv88e6xxx_hwtstamp_setup(chip);
3235 if (err)
3236 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003237 }
3238
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003239 err = mv88e6xxx_stats_setup(chip);
3240 if (err)
3241 goto unlock;
3242
Vivien Didelot6b17e862015-08-13 12:52:18 -04003243unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003244 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02003245
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003246 if (err)
3247 return err;
3248
3249 /* Have to be called without holding the register lock, since
3250 * they take the devlink lock, and we later take the locks in
3251 * the reverse order when getting/setting parameters or
3252 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02003253 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003254 err = mv88e6xxx_setup_devlink_resources(ds);
3255 if (err)
3256 return err;
3257
3258 err = mv88e6xxx_setup_devlink_params(ds);
3259 if (err)
Andrew Lunnbfb25542020-09-18 21:11:07 +02003260 goto out_resources;
3261
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003262 err = mv88e6xxx_setup_devlink_regions_global(ds);
Andrew Lunnbfb25542020-09-18 21:11:07 +02003263 if (err)
3264 goto out_params;
3265
3266 return 0;
3267
3268out_params:
3269 mv88e6xxx_teardown_devlink_params(ds);
3270out_resources:
3271 dsa_devlink_resources_unregister(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003272
3273 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003274}
3275
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003276static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
3277{
3278 return mv88e6xxx_setup_devlink_regions_port(ds, port);
3279}
3280
3281static void mv88e6xxx_port_teardown(struct dsa_switch *ds, int port)
3282{
3283 mv88e6xxx_teardown_devlink_regions_port(ds, port);
3284}
3285
Pali Rohár1fe976d2021-04-12 18:57:39 +02003286/* prod_id for switch families which do not have a PHY model number */
3287static const u16 family_prod_id_table[] = {
3288 [MV88E6XXX_FAMILY_6341] = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3289 [MV88E6XXX_FAMILY_6390] = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Marek Behúnc5d015b2021-04-20 09:54:02 +02003290 [MV88E6XXX_FAMILY_6393] = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
Pali Rohár1fe976d2021-04-12 18:57:39 +02003291};
3292
Vivien Didelote57e5e72016-08-15 17:19:00 -04003293static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003294{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003295 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3296 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Pali Rohár1fe976d2021-04-12 18:57:39 +02003297 u16 prod_id;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003298 u16 val;
3299 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003300
Andrew Lunnee26a222017-01-24 14:53:48 +01003301 if (!chip->info->ops->phy_read)
3302 return -EOPNOTSUPP;
3303
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003304 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003305 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003306 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003307
Pali Rohár1fe976d2021-04-12 18:57:39 +02003308 /* Some internal PHYs don't have a model number. */
3309 if (reg == MII_PHYSID2 && !(val & 0x3f0) &&
3310 chip->info->family < ARRAY_SIZE(family_prod_id_table)) {
3311 prod_id = family_prod_id_table[chip->info->family];
3312 if (prod_id)
3313 val |= prod_id >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003314 }
3315
Vivien Didelote57e5e72016-08-15 17:19:00 -04003316 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003317}
3318
Vivien Didelote57e5e72016-08-15 17:19:00 -04003319static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003320{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003321 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3322 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003323 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003324
Andrew Lunnee26a222017-01-24 14:53:48 +01003325 if (!chip->info->ops->phy_write)
3326 return -EOPNOTSUPP;
3327
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003328 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003329 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003330 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003331
3332 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003333}
3334
Vivien Didelotfad09c72016-06-21 12:28:20 -04003335static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003336 struct device_node *np,
3337 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003338{
3339 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003340 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003341 struct mii_bus *bus;
3342 int err;
3343
Andrew Lunn2510bab2018-02-22 01:51:49 +01003344 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003345 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003346 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003347 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003348
3349 if (err)
3350 return err;
3351 }
3352
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003353 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003354 if (!bus)
3355 return -ENOMEM;
3356
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003357 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003358 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003359 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003360 INIT_LIST_HEAD(&mdio_bus->list);
3361 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003362
Andrew Lunnb516d452016-06-04 21:17:06 +02003363 if (np) {
3364 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003365 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003366 } else {
3367 bus->name = "mv88e6xxx SMI";
3368 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3369 }
3370
3371 bus->read = mv88e6xxx_mdio_read;
3372 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003373 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003374
Andrew Lunn6f882842018-03-17 20:32:05 +01003375 if (!external) {
3376 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3377 if (err)
3378 return err;
3379 }
3380
Florian Fainelli00e798c2018-05-15 16:56:19 -07003381 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003382 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003383 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003384 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003385 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003386 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003387
3388 if (external)
3389 list_add_tail(&mdio_bus->list, &chip->mdios);
3390 else
3391 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003392
3393 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003394}
3395
Andrew Lunn3126aee2017-12-07 01:05:57 +01003396static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3397
3398{
3399 struct mv88e6xxx_mdio_bus *mdio_bus;
3400 struct mii_bus *bus;
3401
3402 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3403 bus = mdio_bus->bus;
3404
Andrew Lunn6f882842018-03-17 20:32:05 +01003405 if (!mdio_bus->external)
3406 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3407
Andrew Lunn3126aee2017-12-07 01:05:57 +01003408 mdiobus_unregister(bus);
3409 }
3410}
3411
Andrew Lunna3c53be52017-01-24 14:53:50 +01003412static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3413 struct device_node *np)
3414{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003415 struct device_node *child;
3416 int err;
3417
3418 /* Always register one mdio bus for the internal/default mdio
3419 * bus. This maybe represented in the device tree, but is
3420 * optional.
3421 */
3422 child = of_get_child_by_name(np, "mdio");
3423 err = mv88e6xxx_mdio_register(chip, child, false);
3424 if (err)
3425 return err;
3426
3427 /* Walk the device tree, and see if there are any other nodes
3428 * which say they are compatible with the external mdio
3429 * bus.
3430 */
3431 for_each_available_child_of_node(np, child) {
Andrew Lunnceb96fa2020-09-01 04:32:57 +02003432 if (of_device_is_compatible(
3433 child, "marvell,mv88e6xxx-mdio-external")) {
Andrew Lunna3c53be52017-01-24 14:53:50 +01003434 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003435 if (err) {
3436 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303437 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003438 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003439 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003440 }
3441 }
3442
3443 return 0;
3444}
3445
Vivien Didelot855b1932016-07-20 18:18:35 -04003446static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3447{
Vivien Didelot04bed142016-08-31 18:06:13 -04003448 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003449
3450 return chip->eeprom_len;
3451}
3452
Vivien Didelot855b1932016-07-20 18:18:35 -04003453static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3454 struct ethtool_eeprom *eeprom, u8 *data)
3455{
Vivien Didelot04bed142016-08-31 18:06:13 -04003456 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003457 int err;
3458
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003459 if (!chip->info->ops->get_eeprom)
3460 return -EOPNOTSUPP;
3461
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003462 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003463 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003464 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003465
3466 if (err)
3467 return err;
3468
3469 eeprom->magic = 0xc3ec4951;
3470
3471 return 0;
3472}
3473
Vivien Didelot855b1932016-07-20 18:18:35 -04003474static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3475 struct ethtool_eeprom *eeprom, u8 *data)
3476{
Vivien Didelot04bed142016-08-31 18:06:13 -04003477 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003478 int err;
3479
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003480 if (!chip->info->ops->set_eeprom)
3481 return -EOPNOTSUPP;
3482
Vivien Didelot855b1932016-07-20 18:18:35 -04003483 if (eeprom->magic != 0xc3ec4951)
3484 return -EINVAL;
3485
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003486 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003487 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003488 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003489
3490 return err;
3491}
3492
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003493static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003494 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003495 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3496 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003497 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003498 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003499 .phy_read = mv88e6185_phy_ppu_read,
3500 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003501 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003502 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003503 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003504 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003505 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003506 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3507 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003508 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003509 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003510 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003511 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003512 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003513 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003514 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003515 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003516 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003517 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3518 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003519 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003520 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3521 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003522 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003523 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003524 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003525 .ppu_enable = mv88e6185_g1_ppu_enable,
3526 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003527 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003528 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003529 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003530 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003531 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003532 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003533};
3534
3535static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003536 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003537 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3538 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003539 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003540 .phy_read = mv88e6185_phy_ppu_read,
3541 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003542 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003543 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003544 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003545 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003546 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3547 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunna23b2962017-02-04 20:15:28 +01003548 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003549 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003550 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003551 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003552 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003553 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3554 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003555 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003556 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003557 .serdes_power = mv88e6185_serdes_power,
3558 .serdes_get_lane = mv88e6185_serdes_get_lane,
3559 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003560 .ppu_enable = mv88e6185_g1_ppu_enable,
3561 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003562 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003563 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003564 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003565 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003566 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003567};
3568
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003569static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003570 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003571 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3572 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003573 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003574 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3575 .phy_read = mv88e6xxx_g2_smi_phy_read,
3576 .phy_write = mv88e6xxx_g2_smi_phy_write,
3577 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003578 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003579 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003580 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003581 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003582 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3583 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003584 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003585 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003586 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003587 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003588 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003589 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003590 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003591 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003592 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003593 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3594 .stats_get_strings = mv88e6095_stats_get_strings,
3595 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003596 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3597 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003598 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003599 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003600 .serdes_power = mv88e6185_serdes_power,
3601 .serdes_get_lane = mv88e6185_serdes_get_lane,
3602 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Chris Packham5c19bc82020-11-24 17:34:39 +13003603 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3604 .serdes_irq_enable = mv88e6097_serdes_irq_enable,
3605 .serdes_irq_status = mv88e6097_serdes_irq_status,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003606 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003607 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003608 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003609 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003610 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003611 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003612 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003613};
3614
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003615static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003616 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003617 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3618 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003619 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003620 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003621 .phy_read = mv88e6xxx_g2_smi_phy_read,
3622 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003623 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003624 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003625 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003626 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003627 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3628 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003629 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003630 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003631 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003632 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003633 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003634 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003635 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3636 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003637 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003638 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3639 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003640 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003641 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003642 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003643 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003644 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3645 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003646 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003647 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003648 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003649 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003650};
3651
3652static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003653 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003654 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3655 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003656 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003657 .phy_read = mv88e6185_phy_ppu_read,
3658 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003659 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003660 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003661 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003662 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003663 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003664 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3665 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003666 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003667 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003668 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003669 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003670 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003671 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003672 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003673 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003674 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003675 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003676 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3677 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003678 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003679 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3680 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003681 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003682 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003683 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003684 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003685 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003686 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003687 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003688 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003689 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003690};
3691
Vivien Didelot990e27b2017-03-28 13:50:32 -04003692static const struct mv88e6xxx_ops mv88e6141_ops = {
3693 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003694 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3695 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003696 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003697 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3698 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3699 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3700 .phy_read = mv88e6xxx_g2_smi_phy_read,
3701 .phy_write = mv88e6xxx_g2_smi_phy_write,
3702 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003703 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003704 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003705 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003706 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003707 .port_tag_remap = mv88e6095_port_tag_remap,
Marek Behún7da467d2021-07-01 00:22:26 +02003708 .port_set_policy = mv88e6352_port_set_policy,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003709 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003710 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3711 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003712 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003713 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003714 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003715 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003716 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3717 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003718 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003719 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003720 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003721 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Marek Behún11527f32021-07-01 00:22:27 +02003722 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003723 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3724 .stats_get_strings = mv88e6320_stats_get_strings,
3725 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003726 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3727 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003728 .watchdog_ops = &mv88e6390_watchdog_ops,
3729 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003730 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003731 .reset = mv88e6352_g1_reset,
Marek Behún37094882021-07-01 00:22:28 +02003732 .rmu_disable = mv88e6390_g1_rmu_disable,
Marek Behúnc07fff32021-07-01 00:22:29 +02003733 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3734 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003735 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003736 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003737 .serdes_power = mv88e6390_serdes_power,
3738 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003739 /* Check status register pause & lpa register */
3740 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3741 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3742 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3743 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003744 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003745 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003746 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003747 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúna03b98d2021-07-01 00:22:30 +02003748 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
3749 .serdes_get_strings = mv88e6390_serdes_get_strings,
3750 .serdes_get_stats = mv88e6390_serdes_get_stats,
Marek Behún953b0dc2021-07-01 00:22:31 +02003751 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3752 .serdes_get_regs = mv88e6390_serdes_get_regs,
Marek Behúne3af71a2019-02-25 12:39:55 +01003753 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003754};
3755
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003756static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003757 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003758 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3759 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003760 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003761 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003762 .phy_read = mv88e6xxx_g2_smi_phy_read,
3763 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003764 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003765 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003766 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003767 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003768 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003769 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3770 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003771 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003772 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003773 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003774 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003775 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003776 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003777 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003778 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003779 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003780 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3781 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003782 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003783 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3784 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003785 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003786 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003787 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003788 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003789 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3790 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003791 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003792 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003793 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003794 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003795 .phylink_validate = mv88e6185_phylink_validate,
Andrew Lunnfe230362021-09-26 19:41:24 +02003796 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003797};
3798
3799static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003800 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003801 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3802 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003803 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003804 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003805 .phy_read = mv88e6165_phy_read,
3806 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003807 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003808 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003809 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003810 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003811 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003812 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003813 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003814 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003815 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003816 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3817 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003818 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003819 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3820 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003821 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003822 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003823 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003824 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003825 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3826 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003827 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003828 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003829 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003830 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003831 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003832};
3833
3834static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003835 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003836 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3837 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003838 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003839 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003840 .phy_read = mv88e6xxx_g2_smi_phy_read,
3841 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003842 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003843 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003844 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003845 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003846 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003847 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003848 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3849 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003850 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003851 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003852 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003853 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003854 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003855 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003856 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003857 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003858 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003859 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003860 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3861 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003862 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003863 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3864 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003865 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003866 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003867 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003868 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003869 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3870 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003871 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003872 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003873 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003874};
3875
3876static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003877 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003878 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3879 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003880 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003881 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3882 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003883 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003884 .phy_read = mv88e6xxx_g2_smi_phy_read,
3885 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003886 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003887 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003888 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003889 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003890 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003891 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003892 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003893 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3894 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003895 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003896 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003897 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003898 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003899 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003900 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003901 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003902 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003903 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003904 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003905 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3906 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003907 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003908 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3909 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003910 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003911 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003912 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003913 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003914 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003915 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3916 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003917 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003918 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003919 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003920 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3921 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3922 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3923 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003924 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003925 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3926 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003927 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003928 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003929};
3930
3931static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003932 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003933 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3934 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003935 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003936 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003937 .phy_read = mv88e6xxx_g2_smi_phy_read,
3938 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003939 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003940 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003941 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003942 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003943 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003944 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003945 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3946 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003947 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003948 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003949 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003950 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003951 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003952 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003953 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003954 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003955 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003956 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003957 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3958 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003959 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003960 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3961 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003962 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003963 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003964 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003965 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003966 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3967 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003968 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003969 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003970 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003971};
3972
3973static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003974 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003975 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3976 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003977 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003978 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3979 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003980 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003981 .phy_read = mv88e6xxx_g2_smi_phy_read,
3982 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003983 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003984 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003985 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003986 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003987 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003988 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003989 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003990 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3991 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003992 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003993 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003994 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003995 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003996 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003997 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003998 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003999 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004000 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004001 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004002 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4003 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004004 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004005 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4006 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004007 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004008 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004009 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004010 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004011 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004012 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4013 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004014 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004015 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004016 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004017 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4018 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4019 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4020 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004021 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004022 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004023 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004024 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004025 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4026 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004027 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004028 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004029};
4030
4031static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004032 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004033 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4034 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004035 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04004036 .phy_read = mv88e6185_phy_ppu_read,
4037 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004038 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004039 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004040 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004041 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004042 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
4043 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunnef70b112016-12-03 04:45:18 +01004044 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01004045 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02004046 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004047 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004048 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004049 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004050 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004051 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4052 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004053 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004054 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4055 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004056 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004057 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13004058 .serdes_power = mv88e6185_serdes_power,
4059 .serdes_get_lane = mv88e6185_serdes_get_lane,
4060 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelot02317e62018-05-09 11:38:49 -04004061 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05004062 .ppu_enable = mv88e6185_g1_ppu_enable,
4063 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004064 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004065 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004066 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004067 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12004068 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004069};
4070
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004071static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004072 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004073 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004074 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004075 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4076 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004077 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4078 .phy_read = mv88e6xxx_g2_smi_phy_read,
4079 .phy_write = mv88e6xxx_g2_smi_phy_write,
4080 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004081 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004082 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004083 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004084 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004085 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004086 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004087 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004088 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4089 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004090 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12004091 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04004092 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004093 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004094 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004095 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004096 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004097 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004098 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004099 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004100 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4101 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004102 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004103 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4104 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004105 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004106 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004107 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004108 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004109 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004110 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4111 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004112 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4113 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004114 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004115 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004116 /* Check status register pause & lpa register */
4117 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4118 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4119 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4120 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004121 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004122 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004123 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004124 .serdes_get_strings = mv88e6390_serdes_get_strings,
4125 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004126 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4127 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004128 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004129 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004130};
4131
4132static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004133 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004134 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004135 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004136 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4137 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004138 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4139 .phy_read = mv88e6xxx_g2_smi_phy_read,
4140 .phy_write = mv88e6xxx_g2_smi_phy_write,
4141 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004142 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004143 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004144 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004145 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004146 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004147 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004148 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004149 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4150 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004151 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12004152 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04004153 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004154 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004155 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004156 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004157 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004158 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004159 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004160 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004161 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4162 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004163 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004164 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4165 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004166 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004167 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004168 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004169 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004170 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004171 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4172 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004173 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4174 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004175 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004176 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004177 /* Check status register pause & lpa register */
4178 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4179 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4180 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4181 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004182 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004183 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004184 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004185 .serdes_get_strings = mv88e6390_serdes_get_strings,
4186 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004187 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4188 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004189 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004190 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004191};
4192
4193static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004194 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004195 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004196 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004197 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4198 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004199 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4200 .phy_read = mv88e6xxx_g2_smi_phy_read,
4201 .phy_write = mv88e6xxx_g2_smi_phy_write,
4202 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004203 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004204 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004205 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004206 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004207 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004208 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004209 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4210 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004211 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004212 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004213 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004214 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004215 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004216 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004217 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004218 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004219 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004220 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4221 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004222 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004223 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4224 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004225 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004226 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004227 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004228 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004229 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004230 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4231 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004232 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4233 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004234 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004235 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004236 /* Check status register pause & lpa register */
4237 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4238 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4239 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4240 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004241 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004242 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004243 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004244 .serdes_get_strings = mv88e6390_serdes_get_strings,
4245 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004246 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4247 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004248 .avb_ops = &mv88e6390_avb_ops,
4249 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004250 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004251};
4252
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004253static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004254 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004255 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4256 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004257 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004258 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4259 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004260 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004261 .phy_read = mv88e6xxx_g2_smi_phy_read,
4262 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004263 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004264 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004265 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004266 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004267 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004268 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004269 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004270 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4271 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004272 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004273 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004274 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004275 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004276 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004277 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004278 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004279 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004280 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004281 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004282 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4283 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004284 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004285 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4286 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004287 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004288 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004289 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004290 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004291 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004292 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4293 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004294 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004295 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004296 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004297 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4298 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4299 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4300 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004301 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004302 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004303 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004304 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004305 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4306 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004307 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004308 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004309 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004310 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004311};
4312
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004313static const struct mv88e6xxx_ops mv88e6250_ops = {
4314 /* MV88E6XXX_FAMILY_6250 */
4315 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4316 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4317 .irl_init_all = mv88e6352_g2_irl_init_all,
4318 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4319 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4320 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4321 .phy_read = mv88e6xxx_g2_smi_phy_read,
4322 .phy_write = mv88e6xxx_g2_smi_phy_write,
4323 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004324 .port_sync_link = mv88e6xxx_port_sync_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004325 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004326 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004327 .port_tag_remap = mv88e6095_port_tag_remap,
4328 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004329 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4330 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004331 .port_set_ether_type = mv88e6351_port_set_ether_type,
4332 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4333 .port_pause_limit = mv88e6097_port_pause_limit,
4334 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004335 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4336 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4337 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4338 .stats_get_strings = mv88e6250_stats_get_strings,
4339 .stats_get_stats = mv88e6250_stats_get_stats,
4340 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4341 .set_egress_port = mv88e6095_g1_set_egress_port,
4342 .watchdog_ops = &mv88e6250_watchdog_ops,
4343 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4344 .pot_clear = mv88e6xxx_g2_pot_clear,
4345 .reset = mv88e6250_g1_reset,
Rasmus Villemoes67c9ed12021-01-25 16:04:48 +01004346 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Rasmus Villemoesb28f3f32021-01-25 16:04:49 +01004347 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004348 .avb_ops = &mv88e6352_avb_ops,
4349 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004350 .phylink_validate = mv88e6065_phylink_validate,
4351};
4352
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004353static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004354 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004355 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004356 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004357 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4358 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004359 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4360 .phy_read = mv88e6xxx_g2_smi_phy_read,
4361 .phy_write = mv88e6xxx_g2_smi_phy_write,
4362 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004363 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004364 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004365 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004366 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004367 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004368 .port_set_policy = mv88e6352_port_set_policy,
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 Didelot08984322017-06-08 18:34:12 -04004373 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004374 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004375 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004376 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004377 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004378 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004379 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004380 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004381 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4382 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004383 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004384 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4385 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004386 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004387 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004388 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004389 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004390 .rmu_disable = mv88e6390_g1_rmu_disable,
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 Didelot931d1822017-05-01 14:05:27 -04004393 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4394 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004395 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004396 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004397 /* Check status register pause & lpa register */
4398 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4399 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4400 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4401 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004402 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004403 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004404 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004405 .serdes_get_strings = mv88e6390_serdes_get_strings,
4406 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004407 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4408 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004409 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004410 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004411 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004412 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004413};
4414
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004415static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004416 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004417 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4418 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004419 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004420 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4421 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004422 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004423 .phy_read = mv88e6xxx_g2_smi_phy_read,
4424 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004425 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004426 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004427 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004428 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004429 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004430 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4431 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004432 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004433 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004434 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004435 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004436 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004437 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004438 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004439 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004440 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004441 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004442 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4443 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004444 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004445 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4446 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004447 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004448 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004449 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004450 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004451 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004452 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004453 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004454 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004455 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004456 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004457};
4458
4459static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004460 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004461 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4462 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004463 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004464 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4465 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004466 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004467 .phy_read = mv88e6xxx_g2_smi_phy_read,
4468 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004469 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004470 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004471 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004472 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004473 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004474 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4475 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004476 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004477 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004478 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004479 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004480 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004481 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004482 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004483 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004484 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004485 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004486 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4487 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004488 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004489 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4490 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004491 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004492 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004493 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004494 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004495 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004496 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004497 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004498 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004499};
4500
Vivien Didelot16e329a2017-03-28 13:50:33 -04004501static const struct mv88e6xxx_ops mv88e6341_ops = {
4502 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004503 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4504 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004505 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004506 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4507 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4508 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4509 .phy_read = mv88e6xxx_g2_smi_phy_read,
4510 .phy_write = mv88e6xxx_g2_smi_phy_write,
4511 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004512 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004513 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004514 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004515 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004516 .port_tag_remap = mv88e6095_port_tag_remap,
Marek Behún7da467d2021-07-01 00:22:26 +02004517 .port_set_policy = mv88e6352_port_set_policy,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004518 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004519 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4520 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004521 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004522 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004523 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004524 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004525 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4526 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004527 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004528 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004529 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004530 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Marek Behún11527f32021-07-01 00:22:27 +02004531 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004532 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4533 .stats_get_strings = mv88e6320_stats_get_strings,
4534 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004535 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4536 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004537 .watchdog_ops = &mv88e6390_watchdog_ops,
4538 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004539 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004540 .reset = mv88e6352_g1_reset,
Marek Behún37094882021-07-01 00:22:28 +02004541 .rmu_disable = mv88e6390_g1_rmu_disable,
Marek Behúnc07fff32021-07-01 00:22:29 +02004542 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4543 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004544 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004545 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004546 .serdes_power = mv88e6390_serdes_power,
4547 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004548 /* Check status register pause & lpa register */
4549 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4550 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4551 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4552 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004553 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004554 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004555 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004556 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004557 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004558 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúna03b98d2021-07-01 00:22:30 +02004559 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4560 .serdes_get_strings = mv88e6390_serdes_get_strings,
4561 .serdes_get_stats = mv88e6390_serdes_get_stats,
Marek Behún953b0dc2021-07-01 00:22:31 +02004562 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4563 .serdes_get_regs = mv88e6390_serdes_get_regs,
Marek Behúne3af71a2019-02-25 12:39:55 +01004564 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004565};
4566
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004567static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004568 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004569 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4570 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004571 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004572 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004573 .phy_read = mv88e6xxx_g2_smi_phy_read,
4574 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004575 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004576 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004577 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004578 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004579 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004580 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004581 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4582 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004583 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004584 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004585 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004586 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004587 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004588 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004589 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004590 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004591 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004592 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004593 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4594 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004595 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004596 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4597 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004598 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004599 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004600 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004601 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004602 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4603 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004604 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004605 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004606 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004607};
4608
4609static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004610 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004611 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4612 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004613 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004614 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004615 .phy_read = mv88e6xxx_g2_smi_phy_read,
4616 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004617 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004618 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004619 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004620 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004621 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004622 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004623 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4624 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004625 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004626 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004627 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004628 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004629 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004630 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004631 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004632 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004633 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004634 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004635 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4636 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004637 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004638 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4639 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004640 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004641 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004642 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004643 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004644 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4645 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004646 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004647 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004648 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004649 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004650 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004651};
4652
4653static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004654 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004655 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4656 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004657 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004658 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4659 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004660 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004661 .phy_read = mv88e6xxx_g2_smi_phy_read,
4662 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004663 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004664 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004665 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004666 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004667 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004668 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004669 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004670 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4671 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004672 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004673 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004674 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004675 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004676 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004677 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004678 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004679 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004680 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004681 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004682 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4683 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004684 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004685 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4686 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004687 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004688 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004689 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004690 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004691 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004692 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4693 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004694 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004695 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004696 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004697 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4698 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4699 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4700 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004701 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004702 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004703 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004704 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004705 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004706 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004707 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004708 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4709 .serdes_get_strings = mv88e6352_serdes_get_strings,
4710 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004711 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4712 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004713 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004714};
4715
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004716static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004717 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004718 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004719 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004720 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4721 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004722 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4723 .phy_read = mv88e6xxx_g2_smi_phy_read,
4724 .phy_write = mv88e6xxx_g2_smi_phy_write,
4725 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004726 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004727 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004728 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004729 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004730 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004731 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004732 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004733 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4734 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004735 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004736 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004737 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004738 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004739 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004740 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004741 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004742 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004743 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004744 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004745 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004746 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4747 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004748 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004749 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4750 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004751 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004752 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004753 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004754 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004755 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004756 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4757 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004758 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4759 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004760 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004761 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004762 /* Check status register pause & lpa register */
4763 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4764 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4765 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4766 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004767 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004768 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004769 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004770 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004771 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004772 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004773 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4774 .serdes_get_strings = mv88e6390_serdes_get_strings,
4775 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004776 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4777 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004778 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004779};
4780
4781static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004782 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004783 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004784 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004785 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4786 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004787 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4788 .phy_read = mv88e6xxx_g2_smi_phy_read,
4789 .phy_write = mv88e6xxx_g2_smi_phy_write,
4790 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004791 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004792 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004793 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004794 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004795 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004796 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004797 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004798 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4799 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004800 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004801 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004802 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004803 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004804 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004805 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004806 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004807 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004808 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004809 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004810 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004811 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4812 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004813 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004814 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4815 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004816 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004817 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004818 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004819 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004820 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004821 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4822 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004823 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4824 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004825 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004826 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004827 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4828 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4829 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4830 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004831 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004832 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004833 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004834 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4835 .serdes_get_strings = mv88e6390_serdes_get_strings,
4836 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004837 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4838 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004839 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004840 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004841 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004842 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004843};
4844
Pavana Sharmade776d02021-03-17 14:46:42 +01004845static const struct mv88e6xxx_ops mv88e6393x_ops = {
4846 /* MV88E6XXX_FAMILY_6393 */
4847 .setup_errata = mv88e6393x_serdes_setup_errata,
4848 .irl_init_all = mv88e6390_g2_irl_init_all,
4849 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4850 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4851 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4852 .phy_read = mv88e6xxx_g2_smi_phy_read,
4853 .phy_write = mv88e6xxx_g2_smi_phy_write,
4854 .port_set_link = mv88e6xxx_port_set_link,
4855 .port_sync_link = mv88e6xxx_port_sync_link,
4856 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4857 .port_set_speed_duplex = mv88e6393x_port_set_speed_duplex,
4858 .port_max_speed_mode = mv88e6393x_port_max_speed_mode,
4859 .port_tag_remap = mv88e6390_port_tag_remap,
Marek Behún6584b262021-03-17 14:46:43 +01004860 .port_set_policy = mv88e6393x_port_set_policy,
Pavana Sharmade776d02021-03-17 14:46:42 +01004861 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4862 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4863 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4864 .port_set_ether_type = mv88e6393x_port_set_ether_type,
4865 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4866 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4867 .port_pause_limit = mv88e6390_port_pause_limit,
4868 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4869 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4870 .port_get_cmode = mv88e6352_port_get_cmode,
4871 .port_set_cmode = mv88e6393x_port_set_cmode,
4872 .port_setup_message_port = mv88e6xxx_setup_message_port,
4873 .port_set_upstream_port = mv88e6393x_port_set_upstream_port,
4874 .stats_snapshot = mv88e6390_g1_stats_snapshot,
4875 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4876 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4877 .stats_get_strings = mv88e6320_stats_get_strings,
4878 .stats_get_stats = mv88e6390_stats_get_stats,
4879 /* .set_cpu_port is missing because this family does not support a global
4880 * CPU port, only per port CPU port which is set via
4881 * .port_set_upstream_port method.
4882 */
4883 .set_egress_port = mv88e6393x_set_egress_port,
4884 .watchdog_ops = &mv88e6390_watchdog_ops,
4885 .mgmt_rsvd2cpu = mv88e6393x_port_mgmt_rsvd2cpu,
4886 .pot_clear = mv88e6xxx_g2_pot_clear,
4887 .reset = mv88e6352_g1_reset,
4888 .rmu_disable = mv88e6390_g1_rmu_disable,
4889 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4890 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4891 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4892 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4893 .serdes_power = mv88e6393x_serdes_power,
4894 .serdes_get_lane = mv88e6393x_serdes_get_lane,
4895 .serdes_pcs_get_state = mv88e6393x_serdes_pcs_get_state,
4896 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4897 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4898 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4899 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4900 .serdes_irq_enable = mv88e6393x_serdes_irq_enable,
4901 .serdes_irq_status = mv88e6393x_serdes_irq_status,
4902 /* TODO: serdes stats */
4903 .gpio_ops = &mv88e6352_gpio_ops,
4904 .avb_ops = &mv88e6390_avb_ops,
4905 .ptp_ops = &mv88e6352_ptp_ops,
4906 .phylink_validate = mv88e6393x_phylink_validate,
4907};
4908
Vivien Didelotf81ec902016-05-09 13:22:58 -04004909static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4910 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004911 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004912 .family = MV88E6XXX_FAMILY_6097,
4913 .name = "Marvell 88E6085",
4914 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004915 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004916 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004917 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004918 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004919 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004920 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004921 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004922 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004923 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004924 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004925 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004926 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004927 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004928 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004929 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004930 },
4931
4932 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004933 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004934 .family = MV88E6XXX_FAMILY_6095,
4935 .name = "Marvell 88E6095/88E6095F",
4936 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004937 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004938 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004939 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004940 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004941 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004942 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004943 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004944 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004945 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004946 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004947 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004948 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004949 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004950 },
4951
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004952 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004953 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004954 .family = MV88E6XXX_FAMILY_6097,
4955 .name = "Marvell 88E6097/88E6097F",
4956 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004957 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004958 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004959 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004960 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004961 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004962 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004963 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004964 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004965 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004966 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004967 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004968 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004969 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004970 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02004971 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004972 .ops = &mv88e6097_ops,
4973 },
4974
Vivien Didelotf81ec902016-05-09 13:22:58 -04004975 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004976 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004977 .family = MV88E6XXX_FAMILY_6165,
4978 .name = "Marvell 88E6123",
4979 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004980 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004981 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004982 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004983 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004984 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004985 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004986 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004987 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004988 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004989 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004990 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004991 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004992 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004993 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02004994 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004995 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004996 },
4997
4998 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004999 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005000 .family = MV88E6XXX_FAMILY_6185,
5001 .name = "Marvell 88E6131",
5002 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005003 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005004 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005005 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005006 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005007 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005008 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005009 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005010 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005011 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005012 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05005013 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005014 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005015 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005016 },
5017
Vivien Didelot990e27b2017-03-28 13:50:32 -04005018 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005019 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005020 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01005021 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04005022 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005023 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005024 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005025 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005026 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005027 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005028 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005029 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005030 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005031 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005032 .age_time_coeff = 3750,
5033 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005034 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005035 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005036 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005037 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005038 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005039 .ops = &mv88e6141_ops,
5040 },
5041
Vivien Didelotf81ec902016-05-09 13:22:58 -04005042 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005043 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005044 .family = MV88E6XXX_FAMILY_6165,
5045 .name = "Marvell 88E6161",
5046 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005047 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005048 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005049 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005050 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005051 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005052 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005053 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005054 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005055 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005056 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005057 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005058 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005059 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005060 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005061 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Andrew Lunndfa54342018-07-18 22:38:22 +02005062 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005063 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005064 },
5065
5066 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005067 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005068 .family = MV88E6XXX_FAMILY_6165,
5069 .name = "Marvell 88E6165",
5070 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005071 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005072 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005073 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005074 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005075 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005076 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005077 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005078 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005079 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005080 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005081 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005082 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005083 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005084 .multi_chip = true,
Andrew Lunndfa54342018-07-18 22:38:22 +02005085 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005086 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005087 },
5088
5089 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005090 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005091 .family = MV88E6XXX_FAMILY_6351,
5092 .name = "Marvell 88E6171",
5093 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005094 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005095 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005096 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005097 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005098 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005099 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005100 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005101 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005102 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005103 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005104 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005105 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005106 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005107 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005108 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005109 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005110 },
5111
5112 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005113 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005114 .family = MV88E6XXX_FAMILY_6352,
5115 .name = "Marvell 88E6172",
5116 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005117 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005118 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005119 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005120 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005121 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005122 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005123 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005124 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005125 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005126 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005127 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005128 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005129 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005130 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005131 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005132 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005133 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005134 },
5135
5136 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005137 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005138 .family = MV88E6XXX_FAMILY_6351,
5139 .name = "Marvell 88E6175",
5140 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005141 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005142 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005143 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005144 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005145 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005146 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005147 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005148 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005149 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005150 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005151 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005152 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005153 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005154 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005155 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005156 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005157 },
5158
5159 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005160 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005161 .family = MV88E6XXX_FAMILY_6352,
5162 .name = "Marvell 88E6176",
5163 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005164 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005165 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005166 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005167 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005168 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005169 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005170 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005171 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005172 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005173 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005174 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005175 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005176 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005177 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005178 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005179 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005180 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005181 },
5182
5183 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005184 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005185 .family = MV88E6XXX_FAMILY_6185,
5186 .name = "Marvell 88E6185",
5187 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005188 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005189 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01005190 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005191 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005192 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005193 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005194 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005195 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005196 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005197 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05005198 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005199 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005200 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005201 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005202 },
5203
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005204 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005205 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005206 .family = MV88E6XXX_FAMILY_6390,
5207 .name = "Marvell 88E6190",
5208 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005209 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005210 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005211 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005212 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005213 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005214 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005215 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005216 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005217 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005218 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005219 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005220 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04005221 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005222 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05005223 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005224 .ops = &mv88e6190_ops,
5225 },
5226
5227 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005228 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005229 .family = MV88E6XXX_FAMILY_6390,
5230 .name = "Marvell 88E6190X",
5231 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005232 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005233 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005234 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005235 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005236 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005237 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005238 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005239 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005240 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005241 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005242 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005243 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005244 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005245 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005246 .multi_chip = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005247 .ops = &mv88e6190x_ops,
5248 },
5249
5250 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005251 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005252 .family = MV88E6XXX_FAMILY_6390,
5253 .name = "Marvell 88E6191",
5254 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005255 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005256 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005257 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04005258 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005259 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005260 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005261 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005262 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005263 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005264 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005265 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005266 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005267 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005268 .multi_chip = true,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005269 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04005270 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005271 },
5272
Pavana Sharmade776d02021-03-17 14:46:42 +01005273 [MV88E6191X] = {
5274 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191X,
5275 .family = MV88E6XXX_FAMILY_6393,
5276 .name = "Marvell 88E6191X",
5277 .num_databases = 4096,
5278 .num_ports = 11, /* 10 + Z80 */
5279 .num_internal_phys = 9,
5280 .max_vid = 8191,
5281 .port_base_addr = 0x0,
5282 .phy_base_addr = 0x0,
5283 .global1_addr = 0x1b,
5284 .global2_addr = 0x1c,
5285 .age_time_coeff = 3750,
5286 .g1_irqs = 10,
5287 .g2_irqs = 14,
5288 .atu_move_port_mask = 0x1f,
5289 .pvt = true,
5290 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005291 .ptp_support = true,
5292 .ops = &mv88e6393x_ops,
5293 },
5294
5295 [MV88E6193X] = {
5296 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6193X,
5297 .family = MV88E6XXX_FAMILY_6393,
5298 .name = "Marvell 88E6193X",
5299 .num_databases = 4096,
5300 .num_ports = 11, /* 10 + Z80 */
5301 .num_internal_phys = 9,
5302 .max_vid = 8191,
5303 .port_base_addr = 0x0,
5304 .phy_base_addr = 0x0,
5305 .global1_addr = 0x1b,
5306 .global2_addr = 0x1c,
5307 .age_time_coeff = 3750,
5308 .g1_irqs = 10,
5309 .g2_irqs = 14,
5310 .atu_move_port_mask = 0x1f,
5311 .pvt = true,
5312 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005313 .ptp_support = true,
5314 .ops = &mv88e6393x_ops,
5315 },
5316
Hubert Feurstein49022642019-07-31 10:23:46 +02005317 [MV88E6220] = {
5318 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
5319 .family = MV88E6XXX_FAMILY_6250,
5320 .name = "Marvell 88E6220",
5321 .num_databases = 64,
5322
5323 /* Ports 2-4 are not routed to pins
5324 * => usable ports 0, 1, 5, 6
5325 */
5326 .num_ports = 7,
5327 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02005328 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02005329 .max_vid = 4095,
5330 .port_base_addr = 0x08,
5331 .phy_base_addr = 0x00,
5332 .global1_addr = 0x0f,
5333 .global2_addr = 0x07,
5334 .age_time_coeff = 15000,
5335 .g1_irqs = 9,
5336 .g2_irqs = 10,
5337 .atu_move_port_mask = 0xf,
5338 .dual_chip = true,
Hubert Feurstein71509612019-07-31 10:23:51 +02005339 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02005340 .ops = &mv88e6250_ops,
5341 },
5342
Vivien Didelotf81ec902016-05-09 13:22:58 -04005343 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005344 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005345 .family = MV88E6XXX_FAMILY_6352,
5346 .name = "Marvell 88E6240",
5347 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005348 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005349 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005350 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005351 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005352 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005353 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005354 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005355 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005356 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005357 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005358 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005359 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005360 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005361 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005362 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005363 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005364 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005365 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005366 },
5367
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005368 [MV88E6250] = {
5369 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
5370 .family = MV88E6XXX_FAMILY_6250,
5371 .name = "Marvell 88E6250",
5372 .num_databases = 64,
5373 .num_ports = 7,
5374 .num_internal_phys = 5,
5375 .max_vid = 4095,
5376 .port_base_addr = 0x08,
5377 .phy_base_addr = 0x00,
5378 .global1_addr = 0x0f,
5379 .global2_addr = 0x07,
5380 .age_time_coeff = 15000,
5381 .g1_irqs = 9,
5382 .g2_irqs = 10,
5383 .atu_move_port_mask = 0xf,
5384 .dual_chip = true,
Hubert Feurstein71509612019-07-31 10:23:51 +02005385 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005386 .ops = &mv88e6250_ops,
5387 },
5388
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005389 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005390 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005391 .family = MV88E6XXX_FAMILY_6390,
5392 .name = "Marvell 88E6290",
5393 .num_databases = 4096,
5394 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005395 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005396 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005397 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005398 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005399 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005400 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005401 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005402 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005403 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005404 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005405 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005406 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005407 .multi_chip = true,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005408 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005409 .ops = &mv88e6290_ops,
5410 },
5411
Vivien Didelotf81ec902016-05-09 13:22:58 -04005412 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005413 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005414 .family = MV88E6XXX_FAMILY_6320,
5415 .name = "Marvell 88E6320",
5416 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005417 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005418 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005419 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005420 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005421 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005422 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005423 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005424 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005425 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005426 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005427 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005428 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005429 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005430 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005431 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005432 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005433 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005434 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005435 },
5436
5437 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005438 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005439 .family = MV88E6XXX_FAMILY_6320,
5440 .name = "Marvell 88E6321",
5441 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005442 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005443 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005444 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005445 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005446 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005447 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005448 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005449 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005450 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005451 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005452 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005453 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005454 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005455 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005456 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005457 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005458 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005459 },
5460
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005461 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005462 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005463 .family = MV88E6XXX_FAMILY_6341,
5464 .name = "Marvell 88E6341",
5465 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005466 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005467 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005468 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005469 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005470 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005471 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005472 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005473 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005474 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005475 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005476 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005477 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005478 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005479 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005480 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005481 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005482 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005483 .ops = &mv88e6341_ops,
5484 },
5485
Vivien Didelotf81ec902016-05-09 13:22:58 -04005486 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005487 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005488 .family = MV88E6XXX_FAMILY_6351,
5489 .name = "Marvell 88E6350",
5490 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005491 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005492 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005493 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005494 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005495 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005496 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005497 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005498 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005499 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005500 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005501 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005502 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005503 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005504 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005505 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005506 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005507 },
5508
5509 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005510 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005511 .family = MV88E6XXX_FAMILY_6351,
5512 .name = "Marvell 88E6351",
5513 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005514 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005515 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005516 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005517 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005518 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005519 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005520 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005521 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005522 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005523 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005524 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005525 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005526 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005527 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005528 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005529 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005530 },
5531
5532 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005533 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005534 .family = MV88E6XXX_FAMILY_6352,
5535 .name = "Marvell 88E6352",
5536 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005537 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005538 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005539 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005540 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005541 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005542 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005543 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005544 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005545 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005546 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005547 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005548 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005549 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005550 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005551 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005552 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005553 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005554 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005555 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005556 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005557 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005558 .family = MV88E6XXX_FAMILY_6390,
5559 .name = "Marvell 88E6390",
5560 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005561 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005562 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005563 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005564 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005565 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005566 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005567 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005568 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005569 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005570 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005571 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005572 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005573 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005574 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005575 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005576 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005577 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005578 .ops = &mv88e6390_ops,
5579 },
5580 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005581 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005582 .family = MV88E6XXX_FAMILY_6390,
5583 .name = "Marvell 88E6390X",
5584 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005585 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005586 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005587 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005588 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005589 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005590 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005591 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005592 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005593 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005594 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005595 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005596 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005597 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005598 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005599 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005600 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005601 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005602 .ops = &mv88e6390x_ops,
5603 },
Pavana Sharmade776d02021-03-17 14:46:42 +01005604
5605 [MV88E6393X] = {
5606 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
5607 .family = MV88E6XXX_FAMILY_6393,
5608 .name = "Marvell 88E6393X",
5609 .num_databases = 4096,
5610 .num_ports = 11, /* 10 + Z80 */
5611 .num_internal_phys = 9,
5612 .max_vid = 8191,
5613 .port_base_addr = 0x0,
5614 .phy_base_addr = 0x0,
5615 .global1_addr = 0x1b,
5616 .global2_addr = 0x1c,
5617 .age_time_coeff = 3750,
5618 .g1_irqs = 10,
5619 .g2_irqs = 14,
5620 .atu_move_port_mask = 0x1f,
5621 .pvt = true,
5622 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005623 .ptp_support = true,
5624 .ops = &mv88e6393x_ops,
5625 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005626};
5627
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005628static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005629{
Vivien Didelota439c062016-04-17 13:23:58 -04005630 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005631
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005632 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5633 if (mv88e6xxx_table[i].prod_num == prod_num)
5634 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005635
Vivien Didelotb9b37712015-10-30 19:39:48 -04005636 return NULL;
5637}
5638
Vivien Didelotfad09c72016-06-21 12:28:20 -04005639static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005640{
5641 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005642 unsigned int prod_num, rev;
5643 u16 id;
5644 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005645
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005646 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005647 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005648 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005649 if (err)
5650 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005651
Vivien Didelot107fcc12017-06-12 12:37:36 -04005652 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5653 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005654
5655 info = mv88e6xxx_lookup_info(prod_num);
5656 if (!info)
5657 return -ENODEV;
5658
Vivien Didelotcaac8542016-06-20 13:14:09 -04005659 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005660 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005661
Vivien Didelotfad09c72016-06-21 12:28:20 -04005662 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5663 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005664
5665 return 0;
5666}
5667
Vivien Didelotfad09c72016-06-21 12:28:20 -04005668static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005669{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005670 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005671
Vivien Didelotfad09c72016-06-21 12:28:20 -04005672 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5673 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005674 return NULL;
5675
Vivien Didelotfad09c72016-06-21 12:28:20 -04005676 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005677
Vivien Didelotfad09c72016-06-21 12:28:20 -04005678 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005679 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005680 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005681
Vivien Didelotfad09c72016-06-21 12:28:20 -04005682 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005683}
5684
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005685static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005686 int port,
5687 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005688{
Vivien Didelot04bed142016-08-31 18:06:13 -04005689 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005690
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005691 return chip->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005692}
5693
Tobias Waldekranz9a99bef2021-04-20 20:53:08 +02005694static int mv88e6xxx_change_tag_protocol(struct dsa_switch *ds, int port,
5695 enum dsa_tag_protocol proto)
5696{
5697 struct mv88e6xxx_chip *chip = ds->priv;
5698 enum dsa_tag_protocol old_protocol;
5699 int err;
5700
5701 switch (proto) {
5702 case DSA_TAG_PROTO_EDSA:
5703 switch (chip->info->edsa_support) {
5704 case MV88E6XXX_EDSA_UNSUPPORTED:
5705 return -EPROTONOSUPPORT;
5706 case MV88E6XXX_EDSA_UNDOCUMENTED:
5707 dev_warn(chip->dev, "Relying on undocumented EDSA tagging behavior\n");
5708 fallthrough;
5709 case MV88E6XXX_EDSA_SUPPORTED:
5710 break;
5711 }
5712 break;
5713 case DSA_TAG_PROTO_DSA:
5714 break;
5715 default:
5716 return -EPROTONOSUPPORT;
5717 }
5718
5719 old_protocol = chip->tag_protocol;
5720 chip->tag_protocol = proto;
5721
5722 mv88e6xxx_reg_lock(chip);
5723 err = mv88e6xxx_setup_port_mode(chip, port);
5724 mv88e6xxx_reg_unlock(chip);
5725
5726 if (err)
5727 chip->tag_protocol = old_protocol;
5728
5729 return err;
5730}
5731
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005732static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
5733 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005734{
Vivien Didelot04bed142016-08-31 18:06:13 -04005735 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005736 int err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005737
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005738 mv88e6xxx_reg_lock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005739 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5740 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005741 mv88e6xxx_reg_unlock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005742
5743 return err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005744}
5745
5746static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5747 const struct switchdev_obj_port_mdb *mdb)
5748{
Vivien Didelot04bed142016-08-31 18:06:13 -04005749 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005750 int err;
5751
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005752 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005753 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005754 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005755
5756 return err;
5757}
5758
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005759static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5760 struct dsa_mall_mirror_tc_entry *mirror,
5761 bool ingress)
5762{
5763 enum mv88e6xxx_egress_direction direction = ingress ?
5764 MV88E6XXX_EGRESS_DIR_INGRESS :
5765 MV88E6XXX_EGRESS_DIR_EGRESS;
5766 struct mv88e6xxx_chip *chip = ds->priv;
5767 bool other_mirrors = false;
5768 int i;
5769 int err;
5770
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005771 mutex_lock(&chip->reg_lock);
5772 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5773 mirror->to_local_port) {
5774 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5775 other_mirrors |= ingress ?
5776 chip->ports[i].mirror_ingress :
5777 chip->ports[i].mirror_egress;
5778
5779 /* Can't change egress port when other mirror is active */
5780 if (other_mirrors) {
5781 err = -EBUSY;
5782 goto out;
5783 }
5784
Marek Behún2fda45f2021-03-17 14:46:41 +01005785 err = mv88e6xxx_set_egress_port(chip, direction,
5786 mirror->to_local_port);
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005787 if (err)
5788 goto out;
5789 }
5790
5791 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5792out:
5793 mutex_unlock(&chip->reg_lock);
5794
5795 return err;
5796}
5797
5798static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5799 struct dsa_mall_mirror_tc_entry *mirror)
5800{
5801 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5802 MV88E6XXX_EGRESS_DIR_INGRESS :
5803 MV88E6XXX_EGRESS_DIR_EGRESS;
5804 struct mv88e6xxx_chip *chip = ds->priv;
5805 bool other_mirrors = false;
5806 int i;
5807
5808 mutex_lock(&chip->reg_lock);
5809 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5810 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5811
5812 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5813 other_mirrors |= mirror->ingress ?
5814 chip->ports[i].mirror_ingress :
5815 chip->ports[i].mirror_egress;
5816
5817 /* Reset egress port when no other mirror is active */
5818 if (!other_mirrors) {
Marek Behún2fda45f2021-03-17 14:46:41 +01005819 if (mv88e6xxx_set_egress_port(chip, direction,
5820 dsa_upstream_port(ds, port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005821 dev_err(ds->dev, "failed to set egress port\n");
5822 }
5823
5824 mutex_unlock(&chip->reg_lock);
5825}
5826
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005827static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port,
5828 struct switchdev_brport_flags flags,
5829 struct netlink_ext_ack *extack)
5830{
5831 struct mv88e6xxx_chip *chip = ds->priv;
5832 const struct mv88e6xxx_ops *ops;
5833
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01005834 if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
5835 BR_BCAST_FLOOD))
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005836 return -EINVAL;
5837
5838 ops = chip->info->ops;
5839
5840 if ((flags.mask & BR_FLOOD) && !ops->port_set_ucast_flood)
5841 return -EINVAL;
5842
5843 if ((flags.mask & BR_MCAST_FLOOD) && !ops->port_set_mcast_flood)
5844 return -EINVAL;
5845
5846 return 0;
5847}
5848
5849static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
5850 struct switchdev_brport_flags flags,
5851 struct netlink_ext_ack *extack)
Russell King4f859012019-02-20 15:35:05 -08005852{
5853 struct mv88e6xxx_chip *chip = ds->priv;
5854 int err = -EOPNOTSUPP;
5855
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005856 mv88e6xxx_reg_lock(chip);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005857
Tobias Waldekranz041bd542021-03-18 20:25:39 +01005858 if (flags.mask & BR_LEARNING) {
5859 bool learning = !!(flags.val & BR_LEARNING);
5860 u16 pav = learning ? (1 << port) : 0;
5861
5862 err = mv88e6xxx_port_set_assoc_vector(chip, port, pav);
5863 if (err)
5864 goto out;
Tobias Waldekranz041bd542021-03-18 20:25:39 +01005865 }
5866
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005867 if (flags.mask & BR_FLOOD) {
5868 bool unicast = !!(flags.val & BR_FLOOD);
5869
5870 err = chip->info->ops->port_set_ucast_flood(chip, port,
5871 unicast);
5872 if (err)
5873 goto out;
5874 }
5875
5876 if (flags.mask & BR_MCAST_FLOOD) {
5877 bool multicast = !!(flags.val & BR_MCAST_FLOOD);
5878
5879 err = chip->info->ops->port_set_mcast_flood(chip, port,
5880 multicast);
5881 if (err)
5882 goto out;
5883 }
5884
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01005885 if (flags.mask & BR_BCAST_FLOOD) {
5886 bool broadcast = !!(flags.val & BR_BCAST_FLOOD);
5887
5888 err = mv88e6xxx_port_broadcast_sync(chip, port, broadcast);
5889 if (err)
5890 goto out;
5891 }
5892
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005893out:
5894 mv88e6xxx_reg_unlock(chip);
5895
5896 return err;
5897}
5898
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005899static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
5900 struct net_device *lag,
5901 struct netdev_lag_upper_info *info)
5902{
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005903 struct mv88e6xxx_chip *chip = ds->priv;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005904 struct dsa_port *dp;
5905 int id, members = 0;
5906
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005907 if (!mv88e6xxx_has_lag(chip))
5908 return false;
5909
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005910 id = dsa_lag_id(ds->dst, lag);
5911 if (id < 0 || id >= ds->num_lag_ids)
5912 return false;
5913
5914 dsa_lag_foreach_port(dp, ds->dst, lag)
5915 /* Includes the port joining the LAG */
5916 members++;
5917
5918 if (members > 8)
5919 return false;
5920
5921 /* We could potentially relax this to include active
5922 * backup in the future.
5923 */
5924 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
5925 return false;
5926
5927 /* Ideally we would also validate that the hash type matches
5928 * the hardware. Alas, this is always set to unknown on team
5929 * interfaces.
5930 */
5931 return true;
5932}
5933
5934static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct net_device *lag)
5935{
5936 struct mv88e6xxx_chip *chip = ds->priv;
5937 struct dsa_port *dp;
5938 u16 map = 0;
5939 int id;
5940
5941 id = dsa_lag_id(ds->dst, lag);
5942
5943 /* Build the map of all ports to distribute flows destined for
5944 * this LAG. This can be either a local user port, or a DSA
5945 * port if the LAG port is on a remote chip.
5946 */
5947 dsa_lag_foreach_port(dp, ds->dst, lag)
5948 map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));
5949
5950 return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
5951}
5952
5953static const u8 mv88e6xxx_lag_mask_table[8][8] = {
5954 /* Row number corresponds to the number of active members in a
5955 * LAG. Each column states which of the eight hash buckets are
5956 * mapped to the column:th port in the LAG.
5957 *
5958 * Example: In a LAG with three active ports, the second port
5959 * ([2][1]) would be selected for traffic mapped to buckets
5960 * 3,4,5 (0x38).
5961 */
5962 { 0xff, 0, 0, 0, 0, 0, 0, 0 },
5963 { 0x0f, 0xf0, 0, 0, 0, 0, 0, 0 },
5964 { 0x07, 0x38, 0xc0, 0, 0, 0, 0, 0 },
5965 { 0x03, 0x0c, 0x30, 0xc0, 0, 0, 0, 0 },
5966 { 0x03, 0x0c, 0x30, 0x40, 0x80, 0, 0, 0 },
5967 { 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80, 0, 0 },
5968 { 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0 },
5969 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
5970};
5971
5972static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
5973 int num_tx, int nth)
5974{
5975 u8 active = 0;
5976 int i;
5977
5978 num_tx = num_tx <= 8 ? num_tx : 8;
5979 if (nth < num_tx)
5980 active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];
5981
5982 for (i = 0; i < 8; i++) {
5983 if (BIT(i) & active)
5984 mask[i] |= BIT(port);
5985 }
5986}
5987
5988static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
5989{
5990 struct mv88e6xxx_chip *chip = ds->priv;
5991 unsigned int id, num_tx;
5992 struct net_device *lag;
5993 struct dsa_port *dp;
5994 int i, err, nth;
5995 u16 mask[8];
5996 u16 ivec;
5997
5998 /* Assume no port is a member of any LAG. */
5999 ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;
6000
6001 /* Disable all masks for ports that _are_ members of a LAG. */
6002 list_for_each_entry(dp, &ds->dst->ports, list) {
6003 if (!dp->lag_dev || dp->ds != ds)
6004 continue;
6005
6006 ivec &= ~BIT(dp->index);
6007 }
6008
6009 for (i = 0; i < 8; i++)
6010 mask[i] = ivec;
6011
6012 /* Enable the correct subset of masks for all LAG ports that
6013 * are in the Tx set.
6014 */
6015 dsa_lags_foreach_id(id, ds->dst) {
6016 lag = dsa_lag_dev(ds->dst, id);
6017 if (!lag)
6018 continue;
6019
6020 num_tx = 0;
6021 dsa_lag_foreach_port(dp, ds->dst, lag) {
6022 if (dp->lag_tx_enabled)
6023 num_tx++;
6024 }
6025
6026 if (!num_tx)
6027 continue;
6028
6029 nth = 0;
6030 dsa_lag_foreach_port(dp, ds->dst, lag) {
6031 if (!dp->lag_tx_enabled)
6032 continue;
6033
6034 if (dp->ds == ds)
6035 mv88e6xxx_lag_set_port_mask(mask, dp->index,
6036 num_tx, nth);
6037
6038 nth++;
6039 }
6040 }
6041
6042 for (i = 0; i < 8; i++) {
6043 err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
6044 if (err)
6045 return err;
6046 }
6047
6048 return 0;
6049}
6050
6051static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
6052 struct net_device *lag)
6053{
6054 int err;
6055
6056 err = mv88e6xxx_lag_sync_masks(ds);
6057
6058 if (!err)
6059 err = mv88e6xxx_lag_sync_map(ds, lag);
6060
6061 return err;
6062}
6063
6064static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port)
6065{
6066 struct mv88e6xxx_chip *chip = ds->priv;
6067 int err;
6068
6069 mv88e6xxx_reg_lock(chip);
6070 err = mv88e6xxx_lag_sync_masks(ds);
6071 mv88e6xxx_reg_unlock(chip);
6072 return err;
6073}
6074
6075static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
6076 struct net_device *lag,
6077 struct netdev_lag_upper_info *info)
6078{
6079 struct mv88e6xxx_chip *chip = ds->priv;
6080 int err, id;
6081
6082 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
6083 return -EOPNOTSUPP;
6084
6085 id = dsa_lag_id(ds->dst, lag);
6086
6087 mv88e6xxx_reg_lock(chip);
6088
6089 err = mv88e6xxx_port_set_trunk(chip, port, true, id);
6090 if (err)
6091 goto err_unlock;
6092
6093 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6094 if (err)
6095 goto err_clear_trunk;
6096
6097 mv88e6xxx_reg_unlock(chip);
6098 return 0;
6099
6100err_clear_trunk:
6101 mv88e6xxx_port_set_trunk(chip, port, false, 0);
6102err_unlock:
6103 mv88e6xxx_reg_unlock(chip);
6104 return err;
6105}
6106
6107static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
6108 struct net_device *lag)
6109{
6110 struct mv88e6xxx_chip *chip = ds->priv;
6111 int err_sync, err_trunk;
6112
6113 mv88e6xxx_reg_lock(chip);
6114 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6115 err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
6116 mv88e6xxx_reg_unlock(chip);
6117 return err_sync ? : err_trunk;
6118}
6119
6120static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
6121 int port)
6122{
6123 struct mv88e6xxx_chip *chip = ds->priv;
6124 int err;
6125
6126 mv88e6xxx_reg_lock(chip);
6127 err = mv88e6xxx_lag_sync_masks(ds);
6128 mv88e6xxx_reg_unlock(chip);
6129 return err;
6130}
6131
6132static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
6133 int port, struct net_device *lag,
6134 struct netdev_lag_upper_info *info)
6135{
6136 struct mv88e6xxx_chip *chip = ds->priv;
6137 int err;
6138
6139 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
6140 return -EOPNOTSUPP;
6141
6142 mv88e6xxx_reg_lock(chip);
6143
6144 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6145 if (err)
6146 goto unlock;
6147
6148 err = mv88e6xxx_pvt_map(chip, sw_index, port);
6149
6150unlock:
6151 mv88e6xxx_reg_unlock(chip);
6152 return err;
6153}
6154
6155static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
6156 int port, struct net_device *lag)
6157{
6158 struct mv88e6xxx_chip *chip = ds->priv;
6159 int err_sync, err_pvt;
6160
6161 mv88e6xxx_reg_lock(chip);
6162 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6163 err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
6164 mv88e6xxx_reg_unlock(chip);
6165 return err_sync ? : err_pvt;
6166}
6167
Florian Fainellia82f67a2017-01-08 14:52:08 -08006168static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02006169 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Tobias Waldekranz9a99bef2021-04-20 20:53:08 +02006170 .change_tag_protocol = mv88e6xxx_change_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006171 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02006172 .teardown = mv88e6xxx_teardown,
Vladimir Olteanfd292c12021-09-17 17:29:16 +03006173 .port_setup = mv88e6xxx_port_setup,
6174 .port_teardown = mv88e6xxx_port_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07006175 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00006176 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07006177 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00006178 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07006179 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
6180 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006181 .get_strings = mv88e6xxx_get_strings,
6182 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
6183 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02006184 .port_enable = mv88e6xxx_port_enable,
6185 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02006186 .port_max_mtu = mv88e6xxx_get_max_mtu,
6187 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04006188 .get_mac_eee = mv88e6xxx_get_mac_eee,
6189 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006190 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006191 .get_eeprom = mv88e6xxx_get_eeprom,
6192 .set_eeprom = mv88e6xxx_set_eeprom,
6193 .get_regs_len = mv88e6xxx_get_regs_len,
6194 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04006195 .get_rxnfc = mv88e6xxx_get_rxnfc,
6196 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04006197 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006198 .port_bridge_join = mv88e6xxx_port_bridge_join,
6199 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02006200 .port_pre_bridge_flags = mv88e6xxx_port_pre_bridge_flags,
6201 .port_bridge_flags = mv88e6xxx_port_bridge_flags,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006202 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04006203 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006204 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006205 .port_vlan_add = mv88e6xxx_port_vlan_add,
6206 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006207 .port_fdb_add = mv88e6xxx_port_fdb_add,
6208 .port_fdb_del = mv88e6xxx_port_fdb_del,
6209 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04006210 .port_mdb_add = mv88e6xxx_port_mdb_add,
6211 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01006212 .port_mirror_add = mv88e6xxx_port_mirror_add,
6213 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04006214 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
6215 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006216 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
6217 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
6218 .port_txtstamp = mv88e6xxx_port_txtstamp,
6219 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
6220 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02006221 .devlink_param_get = mv88e6xxx_devlink_param_get,
6222 .devlink_param_set = mv88e6xxx_devlink_param_set,
Andrew Lunn93157302020-09-18 21:11:09 +02006223 .devlink_info_get = mv88e6xxx_devlink_info_get,
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006224 .port_lag_change = mv88e6xxx_port_lag_change,
6225 .port_lag_join = mv88e6xxx_port_lag_join,
6226 .port_lag_leave = mv88e6xxx_port_lag_leave,
6227 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
6228 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
6229 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
Vladimir Olteance5df682021-07-22 18:55:41 +03006230 .port_bridge_tx_fwd_offload = mv88e6xxx_bridge_tx_fwd_offload,
6231 .port_bridge_tx_fwd_unoffload = mv88e6xxx_bridge_tx_fwd_unoffload,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006232};
6233
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08006234static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006235{
Vivien Didelotfad09c72016-06-21 12:28:20 -04006236 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006237 struct dsa_switch *ds;
6238
Vivien Didelot7e99e342019-10-21 16:51:30 -04006239 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006240 if (!ds)
6241 return -ENOMEM;
6242
Vivien Didelot7e99e342019-10-21 16:51:30 -04006243 ds->dev = dev;
6244 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006245 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006246 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04006247 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04006248 ds->ageing_time_min = chip->info->age_time_coeff;
6249 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006250
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006251 /* Some chips support up to 32, but that requires enabling the
6252 * 5-bit port mode, which we do not support. 640k^W16 ought to
6253 * be enough for anyone.
6254 */
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01006255 ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006256
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006257 dev_set_drvdata(dev, ds);
6258
Vivien Didelot23c9ee42017-05-26 18:12:51 -04006259 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006260}
6261
Vivien Didelotfad09c72016-06-21 12:28:20 -04006262static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006263{
Vivien Didelotfad09c72016-06-21 12:28:20 -04006264 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006265}
6266
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006267static const void *pdata_device_get_match_data(struct device *dev)
6268{
6269 const struct of_device_id *matches = dev->driver->of_match_table;
6270 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
6271
6272 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
6273 matches++) {
6274 if (!strcmp(pdata->compatible, matches->compatible))
6275 return matches->data;
6276 }
6277 return NULL;
6278}
6279
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006280/* There is no suspend to RAM support at DSA level yet, the switch configuration
6281 * would be lost after a power cycle so prevent it to be suspended.
6282 */
6283static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
6284{
6285 return -EOPNOTSUPP;
6286}
6287
6288static int __maybe_unused mv88e6xxx_resume(struct device *dev)
6289{
6290 return 0;
6291}
6292
6293static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
6294
Vivien Didelot57d32312016-06-20 13:13:58 -04006295static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006296{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006297 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04006298 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006299 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006300 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04006301 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006302 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02006303 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006304
Andrew Lunn7bb8c992018-05-31 00:15:42 +02006305 if (!np && !pdata)
6306 return -EINVAL;
6307
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006308 if (np)
6309 compat_info = of_device_get_match_data(dev);
6310
6311 if (pdata) {
6312 compat_info = pdata_device_get_match_data(dev);
6313
6314 if (!pdata->netdev)
6315 return -EINVAL;
6316
6317 for (port = 0; port < DSA_MAX_PORTS; port++) {
6318 if (!(pdata->enabled_ports & (1 << port)))
6319 continue;
6320 if (strcmp(pdata->cd.port_names[port], "cpu"))
6321 continue;
6322 pdata->cd.netdev[port] = &pdata->netdev->dev;
6323 break;
6324 }
6325 }
6326
Vivien Didelotcaac8542016-06-20 13:14:09 -04006327 if (!compat_info)
6328 return -EINVAL;
6329
Vivien Didelotfad09c72016-06-21 12:28:20 -04006330 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006331 if (!chip) {
6332 err = -ENOMEM;
6333 goto out;
6334 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006335
Vivien Didelotfad09c72016-06-21 12:28:20 -04006336 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04006337
Vivien Didelotfad09c72016-06-21 12:28:20 -04006338 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04006339 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006340 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006341
Andrew Lunnb4308f02016-11-21 23:26:55 +01006342 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006343 if (IS_ERR(chip->reset)) {
6344 err = PTR_ERR(chip->reset);
6345 goto out;
6346 }
Baruch Siach7b75e492019-06-27 21:17:39 +03006347 if (chip->reset)
6348 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01006349
Vivien Didelotfad09c72016-06-21 12:28:20 -04006350 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04006351 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006352 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006353
Tobias Waldekranz670bb802021-04-20 20:53:07 +02006354 if (chip->info->edsa_support == MV88E6XXX_EDSA_SUPPORTED)
6355 chip->tag_protocol = DSA_TAG_PROTO_EDSA;
6356 else
6357 chip->tag_protocol = DSA_TAG_PROTO_DSA;
6358
Vivien Didelote57e5e72016-08-15 17:19:00 -04006359 mv88e6xxx_phy_init(chip);
6360
Andrew Lunn00baabe2018-05-19 22:31:35 +02006361 if (chip->info->ops->get_eeprom) {
6362 if (np)
6363 of_property_read_u32(np, "eeprom-length",
6364 &chip->eeprom_len);
6365 else
6366 chip->eeprom_len = pdata->eeprom_len;
6367 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006368
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006369 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006370 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006371 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02006372 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02006373 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02006374
Andrew Lunna27415d2019-05-01 00:10:50 +02006375 if (np) {
6376 chip->irq = of_irq_get(np, 0);
6377 if (chip->irq == -EPROBE_DEFER) {
6378 err = chip->irq;
6379 goto out;
6380 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02006381 }
6382
Andrew Lunna27415d2019-05-01 00:10:50 +02006383 if (pdata)
6384 chip->irq = pdata->irq;
6385
Andrew Lunn294d7112018-02-22 22:58:32 +01006386 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01006387 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01006388 * controllers
6389 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006390 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006391 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006392 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006393 else
6394 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006395 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006396
Andrew Lunn294d7112018-02-22 22:58:32 +01006397 if (err)
6398 goto out;
6399
6400 if (chip->info->g2_irqs > 0) {
6401 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006402 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01006403 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02006404 }
6405
Andrew Lunn294d7112018-02-22 22:58:32 +01006406 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
6407 if (err)
6408 goto out_g2_irq;
6409
6410 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
6411 if (err)
6412 goto out_g1_atu_prob_irq;
6413
Andrew Lunna3c53be52017-01-24 14:53:50 +01006414 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02006415 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01006416 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02006417
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08006418 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006419 if (err)
6420 goto out_mdio;
6421
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006422 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02006423
6424out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01006425 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01006426out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006427 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01006428out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006429 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006430out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006431 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006432 mv88e6xxx_g2_irq_free(chip);
6433out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006434 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006435 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006436 else
6437 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006438out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006439 if (pdata)
6440 dev_put(pdata->netdev);
6441
Andrew Lunndc30c352016-10-16 19:56:49 +02006442 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006443}
6444
6445static void mv88e6xxx_remove(struct mdio_device *mdiodev)
6446{
6447 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006448 struct mv88e6xxx_chip *chip;
6449
6450 if (!ds)
6451 return;
6452
6453 chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006454
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006455 if (chip->info->ptp_support) {
6456 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006457 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006458 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006459
Andrew Lunn930188c2016-08-22 16:01:03 +02006460 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006461 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01006462 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006463
Andrew Lunn76f38f12018-03-17 20:21:09 +01006464 mv88e6xxx_g1_vtu_prob_irq_free(chip);
6465 mv88e6xxx_g1_atu_prob_irq_free(chip);
6466
6467 if (chip->info->g2_irqs > 0)
6468 mv88e6xxx_g2_irq_free(chip);
6469
Andrew Lunn76f38f12018-03-17 20:21:09 +01006470 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006471 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01006472 else
6473 mv88e6xxx_irq_poll_free(chip);
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006474
6475 dev_set_drvdata(&mdiodev->dev, NULL);
6476}
6477
6478static void mv88e6xxx_shutdown(struct mdio_device *mdiodev)
6479{
6480 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
6481
6482 if (!ds)
6483 return;
6484
6485 dsa_switch_shutdown(ds);
6486
6487 dev_set_drvdata(&mdiodev->dev, NULL);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006488}
6489
6490static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04006491 {
6492 .compatible = "marvell,mv88e6085",
6493 .data = &mv88e6xxx_table[MV88E6085],
6494 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01006495 {
6496 .compatible = "marvell,mv88e6190",
6497 .data = &mv88e6xxx_table[MV88E6190],
6498 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00006499 {
6500 .compatible = "marvell,mv88e6250",
6501 .data = &mv88e6xxx_table[MV88E6250],
6502 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006503 { /* sentinel */ },
6504};
6505
6506MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
6507
6508static struct mdio_driver mv88e6xxx_driver = {
6509 .probe = mv88e6xxx_probe,
6510 .remove = mv88e6xxx_remove,
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006511 .shutdown = mv88e6xxx_shutdown,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006512 .mdiodrv.driver = {
6513 .name = "mv88e6085",
6514 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006515 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006516 },
6517};
6518
Andrew Lunn7324d502019-04-27 19:19:10 +02006519mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00006520
6521MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
6522MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
6523MODULE_LICENSE("GPL");