blob: 03744d1c43fc2f885384fcc4231b81123ad7c3b5 [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
Vivien Didelotf81ec902016-05-09 13:22:58 -04001680static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
Vladimir Oltean89153ed2021-02-13 22:43:19 +02001681 bool vlan_filtering,
1682 struct netlink_ext_ack *extack)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001683{
Vivien Didelot04bed142016-08-31 18:06:13 -04001684 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001685 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1686 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001687 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001688
Vladimir Olteanbae33f22021-01-09 02:01:50 +02001689 if (!mv88e6xxx_max_vid(chip))
1690 return -EOPNOTSUPP;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001691
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001692 mv88e6xxx_reg_lock(chip);
Vivien Didelot385a0992016-11-04 03:23:31 +01001693 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001694 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001695
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001696 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001697}
1698
Vivien Didelot57d32312016-06-20 13:13:58 -04001699static int
1700mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001701 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001702{
Vivien Didelot04bed142016-08-31 18:06:13 -04001703 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001704 int err;
1705
Tobias Waldekranze545f862020-11-10 19:57:20 +01001706 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001707 return -EOPNOTSUPP;
1708
Vivien Didelotda9c3592016-02-12 12:09:40 -05001709 /* If the requested port doesn't belong to the same bridge as the VLAN
1710 * members, do not support it (yet) and fallback to software VLAN.
1711 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001712 mv88e6xxx_reg_lock(chip);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001713 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001714 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001715
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001716 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001717}
1718
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001719static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1720 const unsigned char *addr, u16 vid,
1721 u8 state)
1722{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001723 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001724 struct mv88e6xxx_vtu_entry vlan;
1725 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001726 int err;
1727
1728 /* Null VLAN ID corresponds to the port private database */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001729 if (vid == 0) {
1730 err = mv88e6xxx_port_get_fid(chip, port, &fid);
1731 if (err)
1732 return err;
1733 } else {
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001734 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001735 if (err)
1736 return err;
1737
1738 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001739 if (!vlan.valid)
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001740 return -EOPNOTSUPP;
1741
1742 fid = vlan.fid;
1743 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001744
Vivien Didelotd8291a92019-09-07 16:00:47 -04001745 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001746 ether_addr_copy(entry.mac, addr);
1747 eth_addr_dec(entry.mac);
1748
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001749 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001750 if (err)
1751 return err;
1752
1753 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001754 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001755 memset(&entry, 0, sizeof(entry));
1756 ether_addr_copy(entry.mac, addr);
1757 }
1758
1759 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001760 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001761 entry.portvec &= ~BIT(port);
1762 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001763 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001764 } else {
DENG Qingfangf72f2fb2021-01-30 21:43:34 +08001765 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
1766 entry.portvec = BIT(port);
1767 else
1768 entry.portvec |= BIT(port);
1769
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001770 entry.state = state;
1771 }
1772
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001773 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001774}
1775
Vivien Didelotda7dc872019-09-07 16:00:49 -04001776static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1777 const struct mv88e6xxx_policy *policy)
1778{
1779 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1780 enum mv88e6xxx_policy_action action = policy->action;
1781 const u8 *addr = policy->addr;
1782 u16 vid = policy->vid;
1783 u8 state;
1784 int err;
1785 int id;
1786
1787 if (!chip->info->ops->port_set_policy)
1788 return -EOPNOTSUPP;
1789
1790 switch (mapping) {
1791 case MV88E6XXX_POLICY_MAPPING_DA:
1792 case MV88E6XXX_POLICY_MAPPING_SA:
1793 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1794 state = 0; /* Dissociate the port and address */
1795 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1796 is_multicast_ether_addr(addr))
1797 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1798 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1799 is_unicast_ether_addr(addr))
1800 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1801 else
1802 return -EOPNOTSUPP;
1803
1804 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1805 state);
1806 if (err)
1807 return err;
1808 break;
1809 default:
1810 return -EOPNOTSUPP;
1811 }
1812
1813 /* Skip the port's policy clearing if the mapping is still in use */
1814 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1815 idr_for_each_entry(&chip->policies, policy, id)
1816 if (policy->port == port &&
1817 policy->mapping == mapping &&
1818 policy->action != action)
1819 return 0;
1820
1821 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1822}
1823
1824static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1825 struct ethtool_rx_flow_spec *fs)
1826{
1827 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1828 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1829 enum mv88e6xxx_policy_mapping mapping;
1830 enum mv88e6xxx_policy_action action;
1831 struct mv88e6xxx_policy *policy;
1832 u16 vid = 0;
1833 u8 *addr;
1834 int err;
1835 int id;
1836
1837 if (fs->location != RX_CLS_LOC_ANY)
1838 return -EINVAL;
1839
1840 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1841 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1842 else
1843 return -EOPNOTSUPP;
1844
1845 switch (fs->flow_type & ~FLOW_EXT) {
1846 case ETHER_FLOW:
1847 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1848 is_zero_ether_addr(mac_mask->h_source)) {
1849 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1850 addr = mac_entry->h_dest;
1851 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1852 !is_zero_ether_addr(mac_mask->h_source)) {
1853 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1854 addr = mac_entry->h_source;
1855 } else {
1856 /* Cannot support DA and SA mapping in the same rule */
1857 return -EOPNOTSUPP;
1858 }
1859 break;
1860 default:
1861 return -EOPNOTSUPP;
1862 }
1863
1864 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001865 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001866 return -EOPNOTSUPP;
1867 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1868 }
1869
1870 idr_for_each_entry(&chip->policies, policy, id) {
1871 if (policy->port == port && policy->mapping == mapping &&
1872 policy->action == action && policy->vid == vid &&
1873 ether_addr_equal(policy->addr, addr))
1874 return -EEXIST;
1875 }
1876
1877 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1878 if (!policy)
1879 return -ENOMEM;
1880
1881 fs->location = 0;
1882 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1883 GFP_KERNEL);
1884 if (err) {
1885 devm_kfree(chip->dev, policy);
1886 return err;
1887 }
1888
1889 memcpy(&policy->fs, fs, sizeof(*fs));
1890 ether_addr_copy(policy->addr, addr);
1891 policy->mapping = mapping;
1892 policy->action = action;
1893 policy->port = port;
1894 policy->vid = vid;
1895
1896 err = mv88e6xxx_policy_apply(chip, port, policy);
1897 if (err) {
1898 idr_remove(&chip->policies, fs->location);
1899 devm_kfree(chip->dev, policy);
1900 return err;
1901 }
1902
1903 return 0;
1904}
1905
1906static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1907 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1908{
1909 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1910 struct mv88e6xxx_chip *chip = ds->priv;
1911 struct mv88e6xxx_policy *policy;
1912 int err;
1913 int id;
1914
1915 mv88e6xxx_reg_lock(chip);
1916
1917 switch (rxnfc->cmd) {
1918 case ETHTOOL_GRXCLSRLCNT:
1919 rxnfc->data = 0;
1920 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1921 rxnfc->rule_cnt = 0;
1922 idr_for_each_entry(&chip->policies, policy, id)
1923 if (policy->port == port)
1924 rxnfc->rule_cnt++;
1925 err = 0;
1926 break;
1927 case ETHTOOL_GRXCLSRULE:
1928 err = -ENOENT;
1929 policy = idr_find(&chip->policies, fs->location);
1930 if (policy) {
1931 memcpy(fs, &policy->fs, sizeof(*fs));
1932 err = 0;
1933 }
1934 break;
1935 case ETHTOOL_GRXCLSRLALL:
1936 rxnfc->data = 0;
1937 rxnfc->rule_cnt = 0;
1938 idr_for_each_entry(&chip->policies, policy, id)
1939 if (policy->port == port)
1940 rule_locs[rxnfc->rule_cnt++] = id;
1941 err = 0;
1942 break;
1943 default:
1944 err = -EOPNOTSUPP;
1945 break;
1946 }
1947
1948 mv88e6xxx_reg_unlock(chip);
1949
1950 return err;
1951}
1952
1953static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1954 struct ethtool_rxnfc *rxnfc)
1955{
1956 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1957 struct mv88e6xxx_chip *chip = ds->priv;
1958 struct mv88e6xxx_policy *policy;
1959 int err;
1960
1961 mv88e6xxx_reg_lock(chip);
1962
1963 switch (rxnfc->cmd) {
1964 case ETHTOOL_SRXCLSRLINS:
1965 err = mv88e6xxx_policy_insert(chip, port, fs);
1966 break;
1967 case ETHTOOL_SRXCLSRLDEL:
1968 err = -ENOENT;
1969 policy = idr_remove(&chip->policies, fs->location);
1970 if (policy) {
1971 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
1972 err = mv88e6xxx_policy_apply(chip, port, policy);
1973 devm_kfree(chip->dev, policy);
1974 }
1975 break;
1976 default:
1977 err = -EOPNOTSUPP;
1978 break;
1979 }
1980
1981 mv88e6xxx_reg_unlock(chip);
1982
1983 return err;
1984}
1985
Andrew Lunn87fa8862017-11-09 22:29:56 +01001986static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1987 u16 vid)
1988{
Andrew Lunn87fa8862017-11-09 22:29:56 +01001989 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
Tobias Waldekranz0806dd462021-03-18 20:25:37 +01001990 u8 broadcast[ETH_ALEN];
1991
1992 eth_broadcast_addr(broadcast);
Andrew Lunn87fa8862017-11-09 22:29:56 +01001993
1994 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1995}
1996
1997static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1998{
1999 int port;
2000 int err;
2001
2002 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01002003 struct dsa_port *dp = dsa_to_port(chip->ds, port);
2004 struct net_device *brport;
2005
2006 if (dsa_is_unused_port(chip->ds, port))
2007 continue;
2008
2009 brport = dsa_port_to_bridge_port(dp);
2010 if (brport && !br_port_flag_is_set(brport, BR_BCAST_FLOOD))
2011 /* Skip bridged user ports where broadcast
2012 * flooding is disabled.
2013 */
2014 continue;
2015
Andrew Lunn87fa8862017-11-09 22:29:56 +01002016 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
2017 if (err)
2018 return err;
2019 }
2020
2021 return 0;
2022}
2023
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01002024struct mv88e6xxx_port_broadcast_sync_ctx {
2025 int port;
2026 bool flood;
2027};
2028
2029static int
2030mv88e6xxx_port_broadcast_sync_vlan(struct mv88e6xxx_chip *chip,
2031 const struct mv88e6xxx_vtu_entry *vlan,
2032 void *_ctx)
2033{
2034 struct mv88e6xxx_port_broadcast_sync_ctx *ctx = _ctx;
2035 u8 broadcast[ETH_ALEN];
2036 u8 state;
2037
2038 if (ctx->flood)
2039 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
2040 else
2041 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_UNUSED;
2042
2043 eth_broadcast_addr(broadcast);
2044
2045 return mv88e6xxx_port_db_load_purge(chip, ctx->port, broadcast,
2046 vlan->vid, state);
2047}
2048
2049static int mv88e6xxx_port_broadcast_sync(struct mv88e6xxx_chip *chip, int port,
2050 bool flood)
2051{
2052 struct mv88e6xxx_port_broadcast_sync_ctx ctx = {
2053 .port = port,
2054 .flood = flood,
2055 };
2056 struct mv88e6xxx_vtu_entry vid0 = {
2057 .vid = 0,
2058 };
2059 int err;
2060
2061 /* Update the port's private database... */
2062 err = mv88e6xxx_port_broadcast_sync_vlan(chip, &vid0, &ctx);
2063 if (err)
2064 return err;
2065
2066 /* ...and the database for all VLANs. */
2067 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_broadcast_sync_vlan,
2068 &ctx);
2069}
2070
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002071static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00002072 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002073{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002074 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002075 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002076 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002077
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002078 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002079 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002080 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002081
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002082 if (!vlan.valid) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002083 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002084
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002085 err = mv88e6xxx_atu_new(chip, &vlan.fid);
2086 if (err)
2087 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01002088
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002089 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
2090 if (i == port)
2091 vlan.member[i] = member;
2092 else
2093 vlan.member[i] = non_member;
2094
2095 vlan.vid = vid;
2096 vlan.valid = true;
2097
2098 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2099 if (err)
2100 return err;
2101
2102 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
2103 if (err)
2104 return err;
2105 } else if (vlan.member[port] != member) {
2106 vlan.member[port] = member;
2107
2108 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2109 if (err)
2110 return err;
Russell King933b4422020-02-26 17:14:26 +00002111 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002112 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
2113 port, vid);
2114 }
2115
2116 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002117}
2118
Vladimir Oltean1958d582021-01-09 02:01:53 +02002119static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vladimir Oltean31046a52021-02-13 22:43:18 +02002120 const struct switchdev_obj_port_vlan *vlan,
2121 struct netlink_ext_ack *extack)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002122{
Vivien Didelot04bed142016-08-31 18:06:13 -04002123 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002124 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
2125 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Russell King933b4422020-02-26 17:14:26 +00002126 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002127 u8 member;
Vladimir Oltean1958d582021-01-09 02:01:53 +02002128 int err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002129
Eldar Gasanovb8b79c42021-06-21 11:54:38 +03002130 if (!vlan->vid)
2131 return 0;
2132
Vladimir Oltean1958d582021-01-09 02:01:53 +02002133 err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
2134 if (err)
2135 return err;
Vivien Didelot54d77b52016-05-09 13:22:47 -04002136
Vivien Didelotc91498e2017-06-07 18:12:13 -04002137 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002138 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002139 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002140 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002141 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002142 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002143
Russell King933b4422020-02-26 17:14:26 +00002144 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
2145 * and then the CPU port. Do not warn for duplicates for the CPU port.
2146 */
2147 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
2148
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002149 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002150
Vladimir Oltean1958d582021-01-09 02:01:53 +02002151 err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
2152 if (err) {
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002153 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2154 vlan->vid, untagged ? 'u' : 't');
Vladimir Oltean1958d582021-01-09 02:01:53 +02002155 goto out;
2156 }
Vivien Didelot76e398a2015-11-01 12:33:55 -05002157
Vladimir Oltean1958d582021-01-09 02:01:53 +02002158 if (pvid) {
2159 err = mv88e6xxx_port_set_pvid(chip, port, vlan->vid);
2160 if (err) {
2161 dev_err(ds->dev, "p%d: failed to set PVID %d\n",
2162 port, vlan->vid);
2163 goto out;
2164 }
2165 }
2166out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002167 mv88e6xxx_reg_unlock(chip);
Vladimir Oltean1958d582021-01-09 02:01:53 +02002168
2169 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002170}
2171
Vivien Didelot521098922019-08-01 14:36:36 -04002172static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2173 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002174{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002175 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002176 int i, err;
2177
Vivien Didelot521098922019-08-01 14:36:36 -04002178 if (!vid)
Vladimir Olteanc92c7412021-07-22 16:05:51 +03002179 return 0;
Vivien Didelot521098922019-08-01 14:36:36 -04002180
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002181 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002182 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002183 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002184
Vivien Didelot521098922019-08-01 14:36:36 -04002185 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2186 * tell switchdev that this VLAN is likely handled in software.
2187 */
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002188 if (!vlan.valid ||
Vivien Didelot521098922019-08-01 14:36:36 -04002189 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002190 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002191
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002192 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002193
2194 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002195 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002196 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002197 if (vlan.member[i] !=
2198 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002199 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002200 break;
2201 }
2202 }
2203
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002204 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002205 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002206 return err;
2207
Vivien Didelote606ca32017-03-11 16:12:55 -05002208 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002209}
2210
Vivien Didelotf81ec902016-05-09 13:22:58 -04002211static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2212 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002213{
Vivien Didelot04bed142016-08-31 18:06:13 -04002214 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002215 int err = 0;
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002216 u16 pvid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002217
Tobias Waldekranze545f862020-11-10 19:57:20 +01002218 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04002219 return -EOPNOTSUPP;
2220
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002221 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002222
Vivien Didelot77064f32016-11-04 03:23:30 +01002223 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002224 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002225 goto unlock;
2226
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002227 err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
2228 if (err)
2229 goto unlock;
2230
2231 if (vlan->vid == pvid) {
2232 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002233 if (err)
2234 goto unlock;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002235 }
2236
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002237unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002238 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002239
2240 return err;
2241}
2242
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002243static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2244 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002245{
Vivien Didelot04bed142016-08-31 18:06:13 -04002246 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002247 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002248
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002249 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002250 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2251 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002252 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002253
2254 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002255}
2256
Vivien Didelotf81ec902016-05-09 13:22:58 -04002257static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002258 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002259{
Vivien Didelot04bed142016-08-31 18:06:13 -04002260 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002261 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002262
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002263 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002264 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002265 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002266
Vivien Didelot83dabd12016-08-31 11:50:04 -04002267 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002268}
2269
Vivien Didelot83dabd12016-08-31 11:50:04 -04002270static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2271 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002272 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002273{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002274 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002275 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002276 int err;
2277
Vivien Didelotd8291a92019-09-07 16:00:47 -04002278 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002279 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002280
2281 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002282 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002283 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002284 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002285
Vivien Didelotd8291a92019-09-07 16:00:47 -04002286 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002287 break;
2288
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002289 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002290 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002291
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002292 if (!is_unicast_ether_addr(addr.mac))
2293 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002294
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002295 is_static = (addr.state ==
2296 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2297 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002298 if (err)
2299 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002300 } while (!is_broadcast_ether_addr(addr.mac));
2301
2302 return err;
2303}
2304
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002305struct mv88e6xxx_port_db_dump_vlan_ctx {
2306 int port;
2307 dsa_fdb_dump_cb_t *cb;
2308 void *data;
2309};
2310
2311static int mv88e6xxx_port_db_dump_vlan(struct mv88e6xxx_chip *chip,
2312 const struct mv88e6xxx_vtu_entry *entry,
2313 void *_data)
2314{
2315 struct mv88e6xxx_port_db_dump_vlan_ctx *ctx = _data;
2316
2317 return mv88e6xxx_port_db_dump_fid(chip, entry->fid, entry->vid,
2318 ctx->port, ctx->cb, ctx->data);
2319}
2320
Vivien Didelot83dabd12016-08-31 11:50:04 -04002321static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002322 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002323{
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002324 struct mv88e6xxx_port_db_dump_vlan_ctx ctx = {
2325 .port = port,
2326 .cb = cb,
2327 .data = data,
2328 };
Vivien Didelot83dabd12016-08-31 11:50:04 -04002329 u16 fid;
2330 int err;
2331
2332 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002333 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002334 if (err)
2335 return err;
2336
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002337 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002338 if (err)
2339 return err;
2340
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002341 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_db_dump_vlan, &ctx);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002342}
2343
Vivien Didelotf81ec902016-05-09 13:22:58 -04002344static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002345 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002346{
Vivien Didelot04bed142016-08-31 18:06:13 -04002347 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002348 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002349
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002350 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002351 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002352 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002353
2354 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002355}
2356
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002357static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2358 struct net_device *br)
2359{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002360 struct dsa_switch *ds = chip->ds;
2361 struct dsa_switch_tree *dst = ds->dst;
2362 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002363 int err;
2364
Vivien Didelotef2025e2019-10-21 16:51:27 -04002365 list_for_each_entry(dp, &dst->ports, list) {
2366 if (dp->bridge_dev == br) {
2367 if (dp->ds == ds) {
2368 /* This is a local bridge group member,
2369 * remap its Port VLAN Map.
2370 */
2371 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2372 if (err)
2373 return err;
2374 } else {
2375 /* This is an external bridge group member,
2376 * remap its cross-chip Port VLAN Table entry.
2377 */
2378 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2379 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002380 if (err)
2381 return err;
2382 }
2383 }
2384 }
2385
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002386 return 0;
2387}
2388
Vivien Didelotf81ec902016-05-09 13:22:58 -04002389static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002390 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002391{
Vivien Didelot04bed142016-08-31 18:06:13 -04002392 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002393 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002394
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002395 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002396 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002397 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002398
Vivien Didelot466dfa02016-02-26 13:16:05 -05002399 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002400}
2401
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002402static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2403 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002404{
Vivien Didelot04bed142016-08-31 18:06:13 -04002405 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002406
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002407 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002408 if (mv88e6xxx_bridge_map(chip, br) ||
2409 mv88e6xxx_port_vlan_map(chip, port))
2410 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002411 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002412}
2413
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002414static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2415 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002416 int port, struct net_device *br)
2417{
2418 struct mv88e6xxx_chip *chip = ds->priv;
2419 int err;
2420
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002421 if (tree_index != ds->dst->index)
2422 return 0;
2423
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002424 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002425 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002426 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002427
2428 return err;
2429}
2430
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002431static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2432 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002433 int port, struct net_device *br)
2434{
2435 struct mv88e6xxx_chip *chip = ds->priv;
2436
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002437 if (tree_index != ds->dst->index)
2438 return;
2439
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002440 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002441 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002442 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002443 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002444}
2445
Vladimir Olteance5df682021-07-22 18:55:41 +03002446/* Treat the software bridge as a virtual single-port switch behind the
2447 * CPU and map in the PVT. First dst->last_switch elements are taken by
2448 * physical switches, so start from beyond that range.
2449 */
2450static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
2451 int bridge_num)
2452{
2453 u8 dev = bridge_num + ds->dst->last_switch + 1;
2454 struct mv88e6xxx_chip *chip = ds->priv;
2455 int err;
2456
2457 mv88e6xxx_reg_lock(chip);
2458 err = mv88e6xxx_pvt_map(chip, dev, 0);
2459 mv88e6xxx_reg_unlock(chip);
2460
2461 return err;
2462}
2463
2464static int mv88e6xxx_bridge_tx_fwd_offload(struct dsa_switch *ds, int port,
2465 struct net_device *br,
2466 int bridge_num)
2467{
2468 return mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
2469}
2470
2471static void mv88e6xxx_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port,
2472 struct net_device *br,
2473 int bridge_num)
2474{
2475 int err;
2476
2477 err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
2478 if (err) {
2479 dev_err(ds->dev, "failed to remap cross-chip Port VLAN: %pe\n",
2480 ERR_PTR(err));
2481 }
2482}
2483
Vivien Didelot17e708b2016-12-05 17:30:27 -05002484static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2485{
2486 if (chip->info->ops->reset)
2487 return chip->info->ops->reset(chip);
2488
2489 return 0;
2490}
2491
Vivien Didelot309eca62016-12-05 17:30:26 -05002492static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2493{
2494 struct gpio_desc *gpiod = chip->reset;
2495
2496 /* If there is a GPIO connected to the reset pin, toggle it */
2497 if (gpiod) {
2498 gpiod_set_value_cansleep(gpiod, 1);
2499 usleep_range(10000, 20000);
2500 gpiod_set_value_cansleep(gpiod, 0);
2501 usleep_range(10000, 20000);
Andrew Lunna3dcb3e2020-11-16 08:43:01 -08002502
2503 mv88e6xxx_g1_wait_eeprom_done(chip);
Vivien Didelot309eca62016-12-05 17:30:26 -05002504 }
2505}
2506
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002507static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2508{
2509 int i, err;
2510
2511 /* Set all ports to the Disabled state */
2512 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002513 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002514 if (err)
2515 return err;
2516 }
2517
2518 /* Wait for transmit queues to drain,
2519 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2520 */
2521 usleep_range(2000, 4000);
2522
2523 return 0;
2524}
2525
Vivien Didelotfad09c72016-06-21 12:28:20 -04002526static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002527{
Vivien Didelota935c052016-09-29 12:21:53 -04002528 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002529
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002530 err = mv88e6xxx_disable_ports(chip);
2531 if (err)
2532 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002533
Vivien Didelot309eca62016-12-05 17:30:26 -05002534 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002535
Vivien Didelot17e708b2016-12-05 17:30:27 -05002536 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002537}
2538
Vivien Didelot43145572017-03-11 16:12:59 -05002539static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002540 enum mv88e6xxx_frame_mode frame,
2541 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002542{
2543 int err;
2544
Vivien Didelot43145572017-03-11 16:12:59 -05002545 if (!chip->info->ops->port_set_frame_mode)
2546 return -EOPNOTSUPP;
2547
2548 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002549 if (err)
2550 return err;
2551
Vivien Didelot43145572017-03-11 16:12:59 -05002552 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2553 if (err)
2554 return err;
2555
2556 if (chip->info->ops->port_set_ether_type)
2557 return chip->info->ops->port_set_ether_type(chip, port, etype);
2558
2559 return 0;
2560}
2561
2562static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2563{
2564 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002565 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002566 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002567}
2568
2569static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2570{
2571 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002572 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002573 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002574}
2575
2576static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2577{
2578 return mv88e6xxx_set_port_mode(chip, port,
2579 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002580 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2581 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002582}
2583
2584static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2585{
2586 if (dsa_is_dsa_port(chip->ds, port))
2587 return mv88e6xxx_set_port_mode_dsa(chip, port);
2588
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002589 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002590 return mv88e6xxx_set_port_mode_normal(chip, port);
2591
2592 /* Setup CPU port mode depending on its supported tag format */
Tobias Waldekranz670bb802021-04-20 20:53:07 +02002593 if (chip->tag_protocol == DSA_TAG_PROTO_DSA)
Vivien Didelot43145572017-03-11 16:12:59 -05002594 return mv88e6xxx_set_port_mode_dsa(chip, port);
2595
Tobias Waldekranz670bb802021-04-20 20:53:07 +02002596 if (chip->tag_protocol == DSA_TAG_PROTO_EDSA)
Vivien Didelot43145572017-03-11 16:12:59 -05002597 return mv88e6xxx_set_port_mode_edsa(chip, port);
2598
2599 return -EINVAL;
2600}
2601
Vivien Didelotea698f42017-03-11 16:12:50 -05002602static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2603{
2604 bool message = dsa_is_dsa_port(chip->ds, port);
2605
2606 return mv88e6xxx_port_set_message_port(chip, port, message);
2607}
2608
Vivien Didelot601aeed2017-03-11 16:13:00 -05002609static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2610{
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002611 int err;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002612
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002613 if (chip->info->ops->port_set_ucast_flood) {
Tobias Waldekranz7b9f16f2021-03-18 20:25:38 +01002614 err = chip->info->ops->port_set_ucast_flood(chip, port, true);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002615 if (err)
2616 return err;
2617 }
2618 if (chip->info->ops->port_set_mcast_flood) {
Tobias Waldekranz7b9f16f2021-03-18 20:25:38 +01002619 err = chip->info->ops->port_set_mcast_flood(chip, port, true);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002620 if (err)
2621 return err;
2622 }
Vivien Didelot601aeed2017-03-11 16:13:00 -05002623
David S. Miller407308f2019-06-15 13:35:29 -07002624 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002625}
2626
Vivien Didelot45de77f2019-08-31 16:18:36 -04002627static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2628{
2629 struct mv88e6xxx_port *mvp = dev_id;
2630 struct mv88e6xxx_chip *chip = mvp->chip;
2631 irqreturn_t ret = IRQ_NONE;
2632 int port = mvp->port;
Pavana Sharma193c5b22021-03-17 14:46:40 +01002633 int lane;
Vivien Didelot45de77f2019-08-31 16:18:36 -04002634
2635 mv88e6xxx_reg_lock(chip);
2636 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002637 if (lane >= 0)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002638 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2639 mv88e6xxx_reg_unlock(chip);
2640
2641 return ret;
2642}
2643
2644static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002645 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002646{
2647 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2648 unsigned int irq;
2649 int err;
2650
2651 /* Nothing to request if this SERDES port has no IRQ */
2652 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2653 if (!irq)
2654 return 0;
2655
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002656 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2657 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2658
Vivien Didelot45de77f2019-08-31 16:18:36 -04002659 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2660 mv88e6xxx_reg_unlock(chip);
2661 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002662 IRQF_ONESHOT, dev_id->serdes_irq_name,
2663 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002664 mv88e6xxx_reg_lock(chip);
2665 if (err)
2666 return err;
2667
2668 dev_id->serdes_irq = irq;
2669
2670 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2671}
2672
2673static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002674 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002675{
2676 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2677 unsigned int irq = dev_id->serdes_irq;
2678 int err;
2679
2680 /* Nothing to free if no IRQ has been requested */
2681 if (!irq)
2682 return 0;
2683
2684 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2685
2686 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2687 mv88e6xxx_reg_unlock(chip);
2688 free_irq(irq, dev_id);
2689 mv88e6xxx_reg_lock(chip);
2690
2691 dev_id->serdes_irq = 0;
2692
2693 return err;
2694}
2695
Andrew Lunn6d917822017-05-26 01:03:21 +02002696static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2697 bool on)
2698{
Pavana Sharma193c5b22021-03-17 14:46:40 +01002699 int lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002700 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002701
Vivien Didelotdc272f62019-08-31 16:18:33 -04002702 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002703 if (lane < 0)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002704 return 0;
2705
2706 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002707 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002708 if (err)
2709 return err;
2710
Vivien Didelot45de77f2019-08-31 16:18:36 -04002711 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002712 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002713 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2714 if (err)
2715 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002716
Vivien Didelotdc272f62019-08-31 16:18:33 -04002717 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002718 }
2719
2720 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002721}
2722
Marek Behún2fda45f2021-03-17 14:46:41 +01002723static int mv88e6xxx_set_egress_port(struct mv88e6xxx_chip *chip,
2724 enum mv88e6xxx_egress_direction direction,
2725 int port)
2726{
2727 int err;
2728
2729 if (!chip->info->ops->set_egress_port)
2730 return -EOPNOTSUPP;
2731
2732 err = chip->info->ops->set_egress_port(chip, direction, port);
2733 if (err)
2734 return err;
2735
2736 if (direction == MV88E6XXX_EGRESS_DIR_INGRESS)
2737 chip->ingress_dest_port = port;
2738 else
2739 chip->egress_dest_port = port;
2740
2741 return 0;
2742}
2743
Vivien Didelotfa371c82017-12-05 15:34:10 -05002744static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2745{
2746 struct dsa_switch *ds = chip->ds;
2747 int upstream_port;
2748 int err;
2749
Vivien Didelot07073c72017-12-05 15:34:13 -05002750 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002751 if (chip->info->ops->port_set_upstream_port) {
2752 err = chip->info->ops->port_set_upstream_port(chip, port,
2753 upstream_port);
2754 if (err)
2755 return err;
2756 }
2757
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002758 if (port == upstream_port) {
2759 if (chip->info->ops->set_cpu_port) {
2760 err = chip->info->ops->set_cpu_port(chip,
2761 upstream_port);
2762 if (err)
2763 return err;
2764 }
2765
Marek Behún2fda45f2021-03-17 14:46:41 +01002766 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002767 MV88E6XXX_EGRESS_DIR_INGRESS,
2768 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002769 if (err && err != -EOPNOTSUPP)
2770 return err;
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002771
Marek Behún2fda45f2021-03-17 14:46:41 +01002772 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002773 MV88E6XXX_EGRESS_DIR_EGRESS,
2774 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002775 if (err && err != -EOPNOTSUPP)
2776 return err;
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002777 }
2778
Vivien Didelotfa371c82017-12-05 15:34:10 -05002779 return 0;
2780}
2781
Vivien Didelotfad09c72016-06-21 12:28:20 -04002782static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002783{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002784 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002785 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002786 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002787
Andrew Lunn7b898462018-08-09 15:38:47 +02002788 chip->ports[port].chip = chip;
2789 chip->ports[port].port = port;
2790
Vivien Didelotd78343d2016-11-04 03:23:36 +01002791 /* MAC Forcing register: don't force link, speed, duplex or flow control
2792 * state to any particular values on physical ports, but force the CPU
2793 * port and all DSA ports to their maximum bandwidth and full duplex.
2794 */
2795 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2796 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2797 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002798 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002799 PHY_INTERFACE_MODE_NA);
2800 else
2801 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2802 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002803 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002804 PHY_INTERFACE_MODE_NA);
2805 if (err)
2806 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002807
2808 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2809 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2810 * tunneling, determine priority by looking at 802.1p and IP
2811 * priority fields (IP prio has precedence), and set STP state
2812 * to Forwarding.
2813 *
2814 * If this is the CPU link, use DSA or EDSA tagging depending
2815 * on which tagging mode was configured.
2816 *
2817 * If this is a link to another switch, use DSA tagging mode.
2818 *
2819 * If this is the upstream port for this switch, enable
2820 * forwarding of unknown unicasts and multicasts.
2821 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002822 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2823 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2824 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2825 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002826 if (err)
2827 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002828
Vivien Didelot601aeed2017-03-11 16:13:00 -05002829 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002830 if (err)
2831 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002832
Vivien Didelot601aeed2017-03-11 16:13:00 -05002833 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002834 if (err)
2835 return err;
2836
Andrew Lunnb92ce2f2021-09-26 19:41:25 +02002837 /* Port Control 2: don't force a good FCS, set the MTU size to
2838 * 10222 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002839 * untagged frames on this port, do a destination address lookup on all
2840 * received packets as usual, disable ARP mirroring and don't send a
2841 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002842 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002843 err = mv88e6xxx_port_set_map_da(chip, port);
2844 if (err)
2845 return err;
2846
Vivien Didelotfa371c82017-12-05 15:34:10 -05002847 err = mv88e6xxx_setup_upstream_port(chip, port);
2848 if (err)
2849 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002850
Andrew Lunna23b2962017-02-04 20:15:28 +01002851 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002852 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002853 if (err)
2854 return err;
2855
Vivien Didelotcd782652017-06-08 18:34:13 -04002856 if (chip->info->ops->port_set_jumbo_size) {
Andrew Lunnb92ce2f2021-09-26 19:41:25 +02002857 err = chip->info->ops->port_set_jumbo_size(chip, port, 10218);
Andrew Lunn5f436662016-12-03 04:45:17 +01002858 if (err)
2859 return err;
2860 }
2861
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002862 /* Port Association Vector: disable automatic address learning
2863 * on all user ports since they start out in standalone
2864 * mode. When joining a bridge, learning will be configured to
2865 * match the bridge port settings. Enable learning on all
2866 * DSA/CPU ports. NOTE: FROM_CPU frames always bypass the
2867 * learning process.
2868 *
2869 * Disable HoldAt1, IntOnAgeOut, LockedPort, IgnoreWrongData,
2870 * and RefreshLocked. I.e. setup standard automatic learning.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002871 */
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002872 if (dsa_is_user_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002873 reg = 0;
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002874 else
2875 reg = 1 << port;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002876
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002877 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2878 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002879 if (err)
2880 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002881
2882 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002883 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2884 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002885 if (err)
2886 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002887
Vivien Didelot08984322017-06-08 18:34:12 -04002888 if (chip->info->ops->port_pause_limit) {
2889 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002890 if (err)
2891 return err;
2892 }
2893
Vivien Didelotc8c94892017-03-11 16:13:01 -05002894 if (chip->info->ops->port_disable_learn_limit) {
2895 err = chip->info->ops->port_disable_learn_limit(chip, port);
2896 if (err)
2897 return err;
2898 }
2899
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002900 if (chip->info->ops->port_disable_pri_override) {
2901 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002902 if (err)
2903 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002904 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002905
Andrew Lunnef0a7312016-12-03 04:35:16 +01002906 if (chip->info->ops->port_tag_remap) {
2907 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002908 if (err)
2909 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002910 }
2911
Andrew Lunnef70b112016-12-03 04:45:18 +01002912 if (chip->info->ops->port_egress_rate_limiting) {
2913 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002914 if (err)
2915 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002916 }
2917
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002918 if (chip->info->ops->port_setup_message_port) {
2919 err = chip->info->ops->port_setup_message_port(chip, port);
2920 if (err)
2921 return err;
2922 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002923
Vivien Didelot207afda2016-04-14 14:42:09 -04002924 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002925 * database, and allow bidirectional communication between the
2926 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002927 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002928 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002929 if (err)
2930 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002931
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002932 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002933 if (err)
2934 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002935
2936 /* Default VLAN ID and priority: don't set a default VLAN
2937 * ID, and set the default packet priority to zero.
2938 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002939 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002940}
2941
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002942static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
2943{
2944 struct mv88e6xxx_chip *chip = ds->priv;
2945
2946 if (chip->info->ops->port_set_jumbo_size)
Andrew Lunnb9c587f2021-09-26 19:41:26 +02002947 return 10240 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
Chris Packham1baf0fa2020-07-24 11:21:22 +12002948 else if (chip->info->ops->set_max_frame_size)
Andrew Lunnb9c587f2021-09-26 19:41:26 +02002949 return 1632 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
2950 return 1522 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002951}
2952
2953static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
2954{
2955 struct mv88e6xxx_chip *chip = ds->priv;
2956 int ret = 0;
2957
Andrew Lunnb9c587f2021-09-26 19:41:26 +02002958 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
2959 new_mtu += EDSA_HLEN;
2960
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002961 mv88e6xxx_reg_lock(chip);
2962 if (chip->info->ops->port_set_jumbo_size)
2963 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12002964 else if (chip->info->ops->set_max_frame_size)
2965 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002966 else
2967 if (new_mtu > 1522)
2968 ret = -EINVAL;
2969 mv88e6xxx_reg_unlock(chip);
2970
2971 return ret;
2972}
2973
Andrew Lunn04aca992017-05-26 01:03:24 +02002974static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2975 struct phy_device *phydev)
2976{
2977 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002978 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002979
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002980 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002981 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002982 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002983
2984 return err;
2985}
2986
Andrew Lunn75104db2019-02-24 20:44:43 +01002987static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02002988{
2989 struct mv88e6xxx_chip *chip = ds->priv;
2990
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002991 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002992 if (mv88e6xxx_serdes_power(chip, port, false))
2993 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002994 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002995}
2996
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002997static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2998 unsigned int ageing_time)
2999{
Vivien Didelot04bed142016-08-31 18:06:13 -04003000 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003001 int err;
3002
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003003 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05003004 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003005 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003006
3007 return err;
3008}
3009
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003010static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04003011{
3012 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04003013
Andrew Lunnde2273872016-11-21 23:27:01 +01003014 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003015 if (chip->info->ops->stats_set_histogram) {
3016 err = chip->info->ops->stats_set_histogram(chip);
3017 if (err)
3018 return err;
3019 }
Andrew Lunnde2273872016-11-21 23:27:01 +01003020
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003021 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04003022}
3023
Andrew Lunnea890982019-01-09 00:24:03 +01003024/* Check if the errata has already been applied. */
3025static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
3026{
3027 int port;
3028 int err;
3029 u16 val;
3030
3031 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02003032 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01003033 if (err) {
3034 dev_err(chip->dev,
3035 "Error reading hidden register: %d\n", err);
3036 return false;
3037 }
3038 if (val != 0x01c0)
3039 return false;
3040 }
3041
3042 return true;
3043}
3044
3045/* The 6390 copper ports have an errata which require poking magic
3046 * values into undocumented hidden registers and then performing a
3047 * software reset.
3048 */
3049static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
3050{
3051 int port;
3052 int err;
3053
3054 if (mv88e6390_setup_errata_applied(chip))
3055 return 0;
3056
3057 /* Set the ports into blocking mode */
3058 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
3059 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
3060 if (err)
3061 return err;
3062 }
3063
3064 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02003065 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01003066 if (err)
3067 return err;
3068 }
3069
3070 return mv88e6xxx_software_reset(chip);
3071}
3072
Andrew Lunn23e8b472019-10-25 01:03:52 +02003073static void mv88e6xxx_teardown(struct dsa_switch *ds)
3074{
3075 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003076 dsa_devlink_resources_unregister(ds);
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003077 mv88e6xxx_teardown_devlink_regions_global(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02003078}
3079
Vivien Didelotf81ec902016-05-09 13:22:58 -04003080static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07003081{
Vivien Didelot04bed142016-08-31 18:06:13 -04003082 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003083 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04003084 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04003085 int i;
3086
Vivien Didelotfad09c72016-06-21 12:28:20 -04003087 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003088 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003089
Vladimir Olteance5df682021-07-22 18:55:41 +03003090 /* Since virtual bridges are mapped in the PVT, the number we support
3091 * depends on the physical switch topology. We need to let DSA figure
3092 * that out and therefore we cannot set this at dsa_register_switch()
3093 * time.
3094 */
3095 if (mv88e6xxx_has_pvt(chip))
3096 ds->num_fwd_offloading_bridges = MV88E6XXX_MAX_PVT_SWITCHES -
3097 ds->dst->last_switch - 1;
3098
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003099 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003100
Andrew Lunnea890982019-01-09 00:24:03 +01003101 if (chip->info->ops->setup_errata) {
3102 err = chip->info->ops->setup_errata(chip);
3103 if (err)
3104 goto unlock;
3105 }
3106
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003107 /* Cache the cmode of each port. */
3108 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3109 if (chip->info->ops->port_get_cmode) {
3110 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
3111 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03003112 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003113
3114 chip->ports[i].cmode = cmode;
3115 }
3116 }
3117
Vivien Didelot97299342016-07-18 20:45:30 -04003118 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04003119 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04003120 if (dsa_is_unused_port(ds, i))
3121 continue;
3122
Hubert Feursteinc8574862019-07-31 10:23:48 +02003123 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04003124 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02003125 dev_err(chip->dev, "port %d is invalid\n", i);
3126 err = -EINVAL;
3127 goto unlock;
3128 }
3129
Vivien Didelot97299342016-07-18 20:45:30 -04003130 err = mv88e6xxx_setup_port(chip, i);
3131 if (err)
3132 goto unlock;
3133 }
3134
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003135 err = mv88e6xxx_irl_setup(chip);
3136 if (err)
3137 goto unlock;
3138
Vivien Didelot04a69a12017-10-13 14:18:05 -04003139 err = mv88e6xxx_mac_setup(chip);
3140 if (err)
3141 goto unlock;
3142
Vivien Didelot1b17aed2017-05-26 18:03:05 -04003143 err = mv88e6xxx_phy_setup(chip);
3144 if (err)
3145 goto unlock;
3146
Vivien Didelotb486d7c2017-05-01 14:05:13 -04003147 err = mv88e6xxx_vtu_setup(chip);
3148 if (err)
3149 goto unlock;
3150
Vivien Didelot81228992017-03-30 17:37:08 -04003151 err = mv88e6xxx_pvt_setup(chip);
3152 if (err)
3153 goto unlock;
3154
Vivien Didelota2ac29d2017-03-11 16:12:49 -05003155 err = mv88e6xxx_atu_setup(chip);
3156 if (err)
3157 goto unlock;
3158
Andrew Lunn87fa8862017-11-09 22:29:56 +01003159 err = mv88e6xxx_broadcast_setup(chip, 0);
3160 if (err)
3161 goto unlock;
3162
Vivien Didelot9e907d72017-07-17 13:03:43 -04003163 err = mv88e6xxx_pot_setup(chip);
3164 if (err)
3165 goto unlock;
3166
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003167 err = mv88e6xxx_rmu_setup(chip);
3168 if (err)
3169 goto unlock;
3170
Vivien Didelot51c901a2017-07-17 13:03:41 -04003171 err = mv88e6xxx_rsvd2cpu_setup(chip);
3172 if (err)
3173 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01003174
Vivien Didelotb28f8722018-04-26 21:56:44 -04003175 err = mv88e6xxx_trunk_setup(chip);
3176 if (err)
3177 goto unlock;
3178
Vivien Didelotc7f047b2018-04-26 21:56:45 -04003179 err = mv88e6xxx_devmap_setup(chip);
3180 if (err)
3181 goto unlock;
3182
Vivien Didelot93e18d62018-05-11 17:16:35 -04003183 err = mv88e6xxx_pri_setup(chip);
3184 if (err)
3185 goto unlock;
3186
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003187 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003188 if (chip->info->ptp_support) {
3189 err = mv88e6xxx_ptp_setup(chip);
3190 if (err)
3191 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003192
3193 err = mv88e6xxx_hwtstamp_setup(chip);
3194 if (err)
3195 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003196 }
3197
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003198 err = mv88e6xxx_stats_setup(chip);
3199 if (err)
3200 goto unlock;
3201
Vivien Didelot6b17e862015-08-13 12:52:18 -04003202unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003203 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02003204
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003205 if (err)
3206 return err;
3207
3208 /* Have to be called without holding the register lock, since
3209 * they take the devlink lock, and we later take the locks in
3210 * the reverse order when getting/setting parameters or
3211 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02003212 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003213 err = mv88e6xxx_setup_devlink_resources(ds);
3214 if (err)
3215 return err;
3216
3217 err = mv88e6xxx_setup_devlink_params(ds);
3218 if (err)
Andrew Lunnbfb25542020-09-18 21:11:07 +02003219 goto out_resources;
3220
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003221 err = mv88e6xxx_setup_devlink_regions_global(ds);
Andrew Lunnbfb25542020-09-18 21:11:07 +02003222 if (err)
3223 goto out_params;
3224
3225 return 0;
3226
3227out_params:
3228 mv88e6xxx_teardown_devlink_params(ds);
3229out_resources:
3230 dsa_devlink_resources_unregister(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003231
3232 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003233}
3234
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003235static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
3236{
3237 return mv88e6xxx_setup_devlink_regions_port(ds, port);
3238}
3239
3240static void mv88e6xxx_port_teardown(struct dsa_switch *ds, int port)
3241{
3242 mv88e6xxx_teardown_devlink_regions_port(ds, port);
3243}
3244
Pali Rohár1fe976d2021-04-12 18:57:39 +02003245/* prod_id for switch families which do not have a PHY model number */
3246static const u16 family_prod_id_table[] = {
3247 [MV88E6XXX_FAMILY_6341] = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3248 [MV88E6XXX_FAMILY_6390] = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Marek Behúnc5d015b2021-04-20 09:54:02 +02003249 [MV88E6XXX_FAMILY_6393] = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
Pali Rohár1fe976d2021-04-12 18:57:39 +02003250};
3251
Vivien Didelote57e5e72016-08-15 17:19:00 -04003252static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003253{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003254 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3255 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Pali Rohár1fe976d2021-04-12 18:57:39 +02003256 u16 prod_id;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003257 u16 val;
3258 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003259
Andrew Lunnee26a222017-01-24 14:53:48 +01003260 if (!chip->info->ops->phy_read)
3261 return -EOPNOTSUPP;
3262
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003263 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003264 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003265 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003266
Pali Rohár1fe976d2021-04-12 18:57:39 +02003267 /* Some internal PHYs don't have a model number. */
3268 if (reg == MII_PHYSID2 && !(val & 0x3f0) &&
3269 chip->info->family < ARRAY_SIZE(family_prod_id_table)) {
3270 prod_id = family_prod_id_table[chip->info->family];
3271 if (prod_id)
3272 val |= prod_id >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003273 }
3274
Vivien Didelote57e5e72016-08-15 17:19:00 -04003275 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003276}
3277
Vivien Didelote57e5e72016-08-15 17:19:00 -04003278static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003279{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003280 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3281 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003282 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003283
Andrew Lunnee26a222017-01-24 14:53:48 +01003284 if (!chip->info->ops->phy_write)
3285 return -EOPNOTSUPP;
3286
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003287 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003288 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003289 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003290
3291 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003292}
3293
Vivien Didelotfad09c72016-06-21 12:28:20 -04003294static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003295 struct device_node *np,
3296 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003297{
3298 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003299 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003300 struct mii_bus *bus;
3301 int err;
3302
Andrew Lunn2510bab2018-02-22 01:51:49 +01003303 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003304 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003305 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003306 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003307
3308 if (err)
3309 return err;
3310 }
3311
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003312 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003313 if (!bus)
3314 return -ENOMEM;
3315
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003316 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003317 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003318 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003319 INIT_LIST_HEAD(&mdio_bus->list);
3320 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003321
Andrew Lunnb516d452016-06-04 21:17:06 +02003322 if (np) {
3323 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003324 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003325 } else {
3326 bus->name = "mv88e6xxx SMI";
3327 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3328 }
3329
3330 bus->read = mv88e6xxx_mdio_read;
3331 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003332 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003333
Andrew Lunn6f882842018-03-17 20:32:05 +01003334 if (!external) {
3335 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3336 if (err)
3337 return err;
3338 }
3339
Florian Fainelli00e798c2018-05-15 16:56:19 -07003340 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003341 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003342 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003343 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003344 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003345 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003346
3347 if (external)
3348 list_add_tail(&mdio_bus->list, &chip->mdios);
3349 else
3350 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003351
3352 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003353}
3354
Andrew Lunn3126aee2017-12-07 01:05:57 +01003355static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3356
3357{
3358 struct mv88e6xxx_mdio_bus *mdio_bus;
3359 struct mii_bus *bus;
3360
3361 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3362 bus = mdio_bus->bus;
3363
Andrew Lunn6f882842018-03-17 20:32:05 +01003364 if (!mdio_bus->external)
3365 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3366
Andrew Lunn3126aee2017-12-07 01:05:57 +01003367 mdiobus_unregister(bus);
3368 }
3369}
3370
Andrew Lunna3c53be52017-01-24 14:53:50 +01003371static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3372 struct device_node *np)
3373{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003374 struct device_node *child;
3375 int err;
3376
3377 /* Always register one mdio bus for the internal/default mdio
3378 * bus. This maybe represented in the device tree, but is
3379 * optional.
3380 */
3381 child = of_get_child_by_name(np, "mdio");
3382 err = mv88e6xxx_mdio_register(chip, child, false);
3383 if (err)
3384 return err;
3385
3386 /* Walk the device tree, and see if there are any other nodes
3387 * which say they are compatible with the external mdio
3388 * bus.
3389 */
3390 for_each_available_child_of_node(np, child) {
Andrew Lunnceb96fa2020-09-01 04:32:57 +02003391 if (of_device_is_compatible(
3392 child, "marvell,mv88e6xxx-mdio-external")) {
Andrew Lunna3c53be52017-01-24 14:53:50 +01003393 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003394 if (err) {
3395 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303396 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003397 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003398 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003399 }
3400 }
3401
3402 return 0;
3403}
3404
Vivien Didelot855b1932016-07-20 18:18:35 -04003405static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3406{
Vivien Didelot04bed142016-08-31 18:06:13 -04003407 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003408
3409 return chip->eeprom_len;
3410}
3411
Vivien Didelot855b1932016-07-20 18:18:35 -04003412static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3413 struct ethtool_eeprom *eeprom, u8 *data)
3414{
Vivien Didelot04bed142016-08-31 18:06:13 -04003415 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003416 int err;
3417
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003418 if (!chip->info->ops->get_eeprom)
3419 return -EOPNOTSUPP;
3420
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003421 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003422 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003423 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003424
3425 if (err)
3426 return err;
3427
3428 eeprom->magic = 0xc3ec4951;
3429
3430 return 0;
3431}
3432
Vivien Didelot855b1932016-07-20 18:18:35 -04003433static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3434 struct ethtool_eeprom *eeprom, u8 *data)
3435{
Vivien Didelot04bed142016-08-31 18:06:13 -04003436 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003437 int err;
3438
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003439 if (!chip->info->ops->set_eeprom)
3440 return -EOPNOTSUPP;
3441
Vivien Didelot855b1932016-07-20 18:18:35 -04003442 if (eeprom->magic != 0xc3ec4951)
3443 return -EINVAL;
3444
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003445 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003446 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003447 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003448
3449 return err;
3450}
3451
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003452static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003453 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003454 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3455 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003456 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003457 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003458 .phy_read = mv88e6185_phy_ppu_read,
3459 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003460 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003461 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003462 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003463 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003464 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003465 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3466 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003467 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003468 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003469 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003470 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003471 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003472 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003473 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003474 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003475 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003476 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3477 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003478 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003479 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3480 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003481 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003482 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003483 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003484 .ppu_enable = mv88e6185_g1_ppu_enable,
3485 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003486 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003487 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003488 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003489 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003490 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003491 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003492};
3493
3494static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003495 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003496 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3497 .ip_pri_map = mv88e6085_g1_ip_pri_map,
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 = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003503 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003504 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003505 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3506 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunna23b2962017-02-04 20:15:28 +01003507 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003508 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003509 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003510 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003511 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003512 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3513 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003514 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003515 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003516 .serdes_power = mv88e6185_serdes_power,
3517 .serdes_get_lane = mv88e6185_serdes_get_lane,
3518 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003519 .ppu_enable = mv88e6185_g1_ppu_enable,
3520 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003521 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003522 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003523 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003524 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003525 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003526};
3527
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003528static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003529 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003530 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3531 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003532 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003533 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3534 .phy_read = mv88e6xxx_g2_smi_phy_read,
3535 .phy_write = mv88e6xxx_g2_smi_phy_write,
3536 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003537 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003538 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003539 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003540 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003541 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3542 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003543 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003544 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003545 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003546 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003547 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003548 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003549 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003550 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003551 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003552 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3553 .stats_get_strings = mv88e6095_stats_get_strings,
3554 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003555 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3556 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003557 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003558 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003559 .serdes_power = mv88e6185_serdes_power,
3560 .serdes_get_lane = mv88e6185_serdes_get_lane,
3561 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Chris Packham5c19bc82020-11-24 17:34:39 +13003562 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3563 .serdes_irq_enable = mv88e6097_serdes_irq_enable,
3564 .serdes_irq_status = mv88e6097_serdes_irq_status,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003565 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003566 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003567 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003568 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003569 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003570 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003571 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003572};
3573
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003574static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003575 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003576 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3577 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003578 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003579 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003580 .phy_read = mv88e6xxx_g2_smi_phy_read,
3581 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003582 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003583 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003584 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003585 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003586 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3587 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003588 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003589 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003590 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003591 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003592 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003593 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003594 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3595 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003596 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003597 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3598 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003599 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003600 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003601 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003602 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003603 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3604 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003605 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003606 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003607 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003608 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003609};
3610
3611static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003612 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003613 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3614 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003615 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003616 .phy_read = mv88e6185_phy_ppu_read,
3617 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003618 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003619 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003620 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003621 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003622 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003623 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3624 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003625 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003626 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003627 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003628 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003629 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003630 .port_set_pause = mv88e6185_port_set_pause,
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 Lunna605a0f2016-11-21 23:26:58 +01003633 .stats_snapshot = mv88e6xxx_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 = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003642 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003643 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003644 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003645 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003646 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003647 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003648 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003649};
3650
Vivien Didelot990e27b2017-03-28 13:50:32 -04003651static const struct mv88e6xxx_ops mv88e6141_ops = {
3652 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003653 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3654 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003655 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003656 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3657 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3658 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3659 .phy_read = mv88e6xxx_g2_smi_phy_read,
3660 .phy_write = mv88e6xxx_g2_smi_phy_write,
3661 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003662 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003663 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003664 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003665 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003666 .port_tag_remap = mv88e6095_port_tag_remap,
Marek Behún7da467d2021-07-01 00:22:26 +02003667 .port_set_policy = mv88e6352_port_set_policy,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003668 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003669 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3670 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003671 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003672 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003673 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003674 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003675 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3676 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003677 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003678 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003679 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003680 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Marek Behún11527f32021-07-01 00:22:27 +02003681 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003682 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3683 .stats_get_strings = mv88e6320_stats_get_strings,
3684 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003685 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3686 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003687 .watchdog_ops = &mv88e6390_watchdog_ops,
3688 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003689 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003690 .reset = mv88e6352_g1_reset,
Marek Behún37094882021-07-01 00:22:28 +02003691 .rmu_disable = mv88e6390_g1_rmu_disable,
Marek Behúnc07fff32021-07-01 00:22:29 +02003692 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3693 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003694 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003695 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003696 .serdes_power = mv88e6390_serdes_power,
3697 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003698 /* Check status register pause & lpa register */
3699 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3700 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3701 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3702 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003703 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003704 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003705 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003706 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúna03b98d2021-07-01 00:22:30 +02003707 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
3708 .serdes_get_strings = mv88e6390_serdes_get_strings,
3709 .serdes_get_stats = mv88e6390_serdes_get_stats,
Marek Behún953b0dc2021-07-01 00:22:31 +02003710 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3711 .serdes_get_regs = mv88e6390_serdes_get_regs,
Marek Behúne3af71a2019-02-25 12:39:55 +01003712 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003713};
3714
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003715static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003716 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003717 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3718 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003719 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003720 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003721 .phy_read = mv88e6xxx_g2_smi_phy_read,
3722 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003723 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003724 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003725 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003726 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003727 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003728 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3729 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003730 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003731 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003732 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003733 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003734 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003735 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003736 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003737 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003738 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003739 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3740 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003741 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003742 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3743 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003744 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003745 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003746 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003747 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003748 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3749 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003750 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003751 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003752 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003753 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003754 .phylink_validate = mv88e6185_phylink_validate,
Andrew Lunnfe230362021-09-26 19:41:24 +02003755 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003756};
3757
3758static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003759 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003760 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3761 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003762 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003763 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003764 .phy_read = mv88e6165_phy_read,
3765 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003766 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003767 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003768 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003769 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003770 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003771 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003772 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003773 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003774 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003775 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3776 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003777 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003778 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3779 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003780 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003781 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003782 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003783 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003784 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3785 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003786 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003787 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003788 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003789 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003790 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003791};
3792
3793static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003794 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003795 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3796 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003797 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003798 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003799 .phy_read = mv88e6xxx_g2_smi_phy_read,
3800 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003801 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003802 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003803 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003804 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003805 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003806 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003807 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3808 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003809 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003810 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003811 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003812 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003813 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003814 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003815 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003816 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003817 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003818 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003819 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3820 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003821 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003822 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3823 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003824 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003825 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003826 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003827 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003828 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3829 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003830 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003831 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003832 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003833};
3834
3835static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003836 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003837 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3838 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003839 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003840 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3841 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003842 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003843 .phy_read = mv88e6xxx_g2_smi_phy_read,
3844 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003845 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003846 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003847 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003848 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003849 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003850 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003851 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003852 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3853 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003854 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003855 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003856 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003857 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003858 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003859 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003860 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003861 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003862 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003863 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003864 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3865 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003866 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003867 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3868 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003869 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003870 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003871 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003872 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003873 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003874 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3875 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003876 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003877 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003878 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003879 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3880 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3881 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3882 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003883 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003884 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3885 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003886 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003887 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003888};
3889
3890static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003891 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003892 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3893 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003894 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003895 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003896 .phy_read = mv88e6xxx_g2_smi_phy_read,
3897 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003898 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003899 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003900 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003901 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003902 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003903 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003904 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3905 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003906 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003907 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003908 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003909 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003910 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003911 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003912 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003913 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003914 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003915 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003916 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3917 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003918 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003919 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3920 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003921 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003922 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003923 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003924 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003925 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3926 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003927 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003928 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003929 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003930};
3931
3932static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003933 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003934 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3935 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003936 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003937 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3938 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003939 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003940 .phy_read = mv88e6xxx_g2_smi_phy_read,
3941 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003942 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003943 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003944 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003945 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003946 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003947 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003948 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003949 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3950 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003951 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003952 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003953 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003954 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003955 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003956 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003957 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003958 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003959 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003960 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003961 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3962 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003963 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003964 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3965 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003966 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003967 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003968 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003969 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003970 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003971 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3972 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003973 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003974 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003975 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003976 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3977 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3978 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3979 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003980 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003981 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003982 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003983 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003984 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3985 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003986 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003987 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003988};
3989
3990static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003991 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003992 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3993 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003994 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003995 .phy_read = mv88e6185_phy_ppu_read,
3996 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003997 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003998 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003999 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004000 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004001 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
4002 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunnef70b112016-12-03 04:45:18 +01004003 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01004004 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02004005 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004006 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004007 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004008 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004009 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004010 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4011 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004012 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004013 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4014 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004015 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004016 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13004017 .serdes_power = mv88e6185_serdes_power,
4018 .serdes_get_lane = mv88e6185_serdes_get_lane,
4019 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelot02317e62018-05-09 11:38:49 -04004020 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05004021 .ppu_enable = mv88e6185_g1_ppu_enable,
4022 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004023 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004024 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004025 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004026 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12004027 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004028};
4029
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004030static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004031 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004032 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004033 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004034 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4035 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004036 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4037 .phy_read = mv88e6xxx_g2_smi_phy_read,
4038 .phy_write = mv88e6xxx_g2_smi_phy_write,
4039 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004040 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004041 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004042 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004043 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004044 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004045 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004046 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004047 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4048 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004049 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12004050 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04004051 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004052 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004053 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004054 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004055 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004056 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004057 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004058 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004059 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4060 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004061 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004062 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4063 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004064 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004065 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004066 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004067 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004068 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004069 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4070 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004071 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4072 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004073 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004074 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004075 /* Check status register pause & lpa register */
4076 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4077 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4078 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4079 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004080 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004081 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004082 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004083 .serdes_get_strings = mv88e6390_serdes_get_strings,
4084 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004085 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4086 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004087 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004088 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004089};
4090
4091static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004092 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004093 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004094 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004095 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4096 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004097 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4098 .phy_read = mv88e6xxx_g2_smi_phy_read,
4099 .phy_write = mv88e6xxx_g2_smi_phy_write,
4100 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004101 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004102 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004103 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004104 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004105 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004106 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004107 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004108 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4109 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004110 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12004111 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04004112 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004113 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004114 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004115 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004116 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004117 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004118 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004119 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004120 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4121 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004122 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004123 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4124 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004125 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004126 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004127 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004128 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004129 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004130 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4131 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004132 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4133 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004134 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004135 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004136 /* Check status register pause & lpa register */
4137 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4138 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4139 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4140 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004141 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004142 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004143 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004144 .serdes_get_strings = mv88e6390_serdes_get_strings,
4145 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004146 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4147 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004148 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004149 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004150};
4151
4152static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004153 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004154 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004155 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004156 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4157 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004158 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4159 .phy_read = mv88e6xxx_g2_smi_phy_read,
4160 .phy_write = mv88e6xxx_g2_smi_phy_write,
4161 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004162 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004163 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004164 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004165 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004166 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004167 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004168 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4169 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004170 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004171 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004172 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004173 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004174 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004175 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004176 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004177 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004178 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004179 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4180 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004181 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004182 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4183 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004184 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004185 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004186 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004187 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004188 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004189 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4190 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004191 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4192 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004193 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004194 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004195 /* Check status register pause & lpa register */
4196 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4197 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4198 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4199 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004200 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004201 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004202 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004203 .serdes_get_strings = mv88e6390_serdes_get_strings,
4204 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004205 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4206 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004207 .avb_ops = &mv88e6390_avb_ops,
4208 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004209 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004210};
4211
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004212static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004213 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004214 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4215 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004216 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004217 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4218 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004219 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004220 .phy_read = mv88e6xxx_g2_smi_phy_read,
4221 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004222 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004223 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004224 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004225 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004226 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004227 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004228 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004229 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4230 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004231 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004232 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004233 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004234 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004235 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004236 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004237 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004238 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004239 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004240 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004241 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4242 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004243 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004244 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4245 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004246 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004247 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004248 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004249 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004250 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004251 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4252 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004253 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004254 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004255 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004256 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4257 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4258 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4259 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004260 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004261 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004262 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004263 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004264 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4265 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004266 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004267 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004268 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004269 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004270};
4271
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004272static const struct mv88e6xxx_ops mv88e6250_ops = {
4273 /* MV88E6XXX_FAMILY_6250 */
4274 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4275 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4276 .irl_init_all = mv88e6352_g2_irl_init_all,
4277 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4278 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4279 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4280 .phy_read = mv88e6xxx_g2_smi_phy_read,
4281 .phy_write = mv88e6xxx_g2_smi_phy_write,
4282 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004283 .port_sync_link = mv88e6xxx_port_sync_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004284 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004285 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004286 .port_tag_remap = mv88e6095_port_tag_remap,
4287 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004288 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4289 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004290 .port_set_ether_type = mv88e6351_port_set_ether_type,
4291 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4292 .port_pause_limit = mv88e6097_port_pause_limit,
4293 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004294 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4295 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4296 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4297 .stats_get_strings = mv88e6250_stats_get_strings,
4298 .stats_get_stats = mv88e6250_stats_get_stats,
4299 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4300 .set_egress_port = mv88e6095_g1_set_egress_port,
4301 .watchdog_ops = &mv88e6250_watchdog_ops,
4302 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4303 .pot_clear = mv88e6xxx_g2_pot_clear,
4304 .reset = mv88e6250_g1_reset,
Rasmus Villemoes67c9ed12021-01-25 16:04:48 +01004305 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Rasmus Villemoesb28f3f32021-01-25 16:04:49 +01004306 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004307 .avb_ops = &mv88e6352_avb_ops,
4308 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004309 .phylink_validate = mv88e6065_phylink_validate,
4310};
4311
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004312static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004313 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004314 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004315 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004316 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4317 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004318 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4319 .phy_read = mv88e6xxx_g2_smi_phy_read,
4320 .phy_write = mv88e6xxx_g2_smi_phy_write,
4321 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004322 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004323 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004324 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004325 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004326 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004327 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004328 .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,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004331 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004332 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004333 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004334 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004335 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004336 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004337 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004338 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004339 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004340 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4341 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004342 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004343 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4344 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004345 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004346 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004347 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004348 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004349 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004350 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4351 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004352 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4353 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004354 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004355 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004356 /* Check status register pause & lpa register */
4357 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4358 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4359 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4360 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004361 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004362 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004363 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004364 .serdes_get_strings = mv88e6390_serdes_get_strings,
4365 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004366 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4367 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004368 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004369 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004370 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004371 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004372};
4373
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004374static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004375 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004376 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4377 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004378 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004379 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4380 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004381 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004382 .phy_read = mv88e6xxx_g2_smi_phy_read,
4383 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004384 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004385 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004386 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004387 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004388 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004389 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4390 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004391 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004392 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004393 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004394 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004395 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004396 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004397 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004398 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004399 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004400 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004401 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4402 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004403 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004404 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4405 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004406 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004407 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004408 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004409 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004410 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004411 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004412 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004413 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004414 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004415 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004416};
4417
4418static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004419 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004420 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4421 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004422 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004423 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4424 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004425 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004426 .phy_read = mv88e6xxx_g2_smi_phy_read,
4427 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004428 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004429 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004430 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004431 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004432 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004433 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4434 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004435 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004436 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004437 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004438 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004439 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004440 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004441 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004442 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004443 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004444 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004445 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4446 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004447 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004448 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4449 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004450 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004451 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004452 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004453 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004454 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004455 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004456 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004457 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004458};
4459
Vivien Didelot16e329a2017-03-28 13:50:33 -04004460static const struct mv88e6xxx_ops mv88e6341_ops = {
4461 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004462 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4463 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004464 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004465 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4466 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4467 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4468 .phy_read = mv88e6xxx_g2_smi_phy_read,
4469 .phy_write = mv88e6xxx_g2_smi_phy_write,
4470 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004471 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004472 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004473 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004474 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004475 .port_tag_remap = mv88e6095_port_tag_remap,
Marek Behún7da467d2021-07-01 00:22:26 +02004476 .port_set_policy = mv88e6352_port_set_policy,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004477 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004478 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4479 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004480 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004481 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004482 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004483 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004484 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4485 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004486 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004487 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004488 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004489 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Marek Behún11527f32021-07-01 00:22:27 +02004490 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004491 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4492 .stats_get_strings = mv88e6320_stats_get_strings,
4493 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004494 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4495 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004496 .watchdog_ops = &mv88e6390_watchdog_ops,
4497 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004498 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004499 .reset = mv88e6352_g1_reset,
Marek Behún37094882021-07-01 00:22:28 +02004500 .rmu_disable = mv88e6390_g1_rmu_disable,
Marek Behúnc07fff32021-07-01 00:22:29 +02004501 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4502 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004503 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004504 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004505 .serdes_power = mv88e6390_serdes_power,
4506 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004507 /* Check status register pause & lpa register */
4508 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4509 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4510 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4511 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004512 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004513 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004514 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004515 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004516 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004517 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúna03b98d2021-07-01 00:22:30 +02004518 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4519 .serdes_get_strings = mv88e6390_serdes_get_strings,
4520 .serdes_get_stats = mv88e6390_serdes_get_stats,
Marek Behún953b0dc2021-07-01 00:22:31 +02004521 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4522 .serdes_get_regs = mv88e6390_serdes_get_regs,
Marek Behúne3af71a2019-02-25 12:39:55 +01004523 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004524};
4525
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004526static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004527 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004528 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4529 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004530 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004531 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004532 .phy_read = mv88e6xxx_g2_smi_phy_read,
4533 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004534 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004535 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004536 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004537 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004538 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004539 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004540 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4541 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004542 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004543 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004544 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004545 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004546 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004547 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004548 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004549 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004550 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004551 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004552 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4553 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004554 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004555 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4556 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004557 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004558 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004559 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004560 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004561 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4562 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004563 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004564 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004565 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004566};
4567
4568static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004569 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004570 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4571 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004572 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004573 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004574 .phy_read = mv88e6xxx_g2_smi_phy_read,
4575 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004576 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004577 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004578 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004579 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004580 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004581 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004582 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4583 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004584 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004585 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004586 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004587 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004588 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004589 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004590 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004591 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004592 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004593 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004594 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4595 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004596 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004597 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4598 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004599 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004600 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004601 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004602 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004603 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4604 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004605 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004606 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004607 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004608 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004609 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004610};
4611
4612static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004613 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004614 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4615 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004616 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004617 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4618 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004619 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004620 .phy_read = mv88e6xxx_g2_smi_phy_read,
4621 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004622 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004623 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004624 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004625 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004626 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004627 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004628 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004629 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4630 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004631 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004632 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004633 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004634 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004635 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004636 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004637 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004638 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004639 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004640 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004641 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4642 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004643 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004644 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4645 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004646 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004647 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004648 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004649 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004650 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004651 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4652 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004653 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004654 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004655 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004656 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4657 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4658 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4659 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004660 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004661 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004662 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004663 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004664 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004665 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004666 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004667 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4668 .serdes_get_strings = mv88e6352_serdes_get_strings,
4669 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004670 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4671 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004672 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004673};
4674
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004675static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004676 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004677 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004678 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004679 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4680 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004681 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4682 .phy_read = mv88e6xxx_g2_smi_phy_read,
4683 .phy_write = mv88e6xxx_g2_smi_phy_write,
4684 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004685 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004686 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004687 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004688 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004689 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004690 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004691 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004692 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4693 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004694 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004695 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004696 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004697 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004698 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004699 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004700 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004701 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004702 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004703 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004704 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004705 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4706 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004707 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004708 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4709 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004710 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004711 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004712 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004713 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004714 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004715 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4716 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004717 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4718 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004719 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004720 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004721 /* Check status register pause & lpa register */
4722 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4723 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4724 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4725 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004726 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004727 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004728 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004729 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004730 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004731 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004732 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4733 .serdes_get_strings = mv88e6390_serdes_get_strings,
4734 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004735 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4736 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004737 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004738};
4739
4740static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004741 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004742 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004743 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004744 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4745 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004746 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4747 .phy_read = mv88e6xxx_g2_smi_phy_read,
4748 .phy_write = mv88e6xxx_g2_smi_phy_write,
4749 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004750 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004751 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004752 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004753 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004754 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004755 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004756 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004757 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4758 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004759 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004760 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004761 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004762 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004763 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004764 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004765 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004766 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004767 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004768 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004769 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004770 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4771 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004772 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004773 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4774 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004775 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004776 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004777 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004778 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004779 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004780 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4781 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004782 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4783 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004784 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004785 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004786 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4787 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4788 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4789 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004790 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004791 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004792 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004793 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4794 .serdes_get_strings = mv88e6390_serdes_get_strings,
4795 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004796 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4797 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004798 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004799 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004800 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004801 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004802};
4803
Pavana Sharmade776d02021-03-17 14:46:42 +01004804static const struct mv88e6xxx_ops mv88e6393x_ops = {
4805 /* MV88E6XXX_FAMILY_6393 */
4806 .setup_errata = mv88e6393x_serdes_setup_errata,
4807 .irl_init_all = mv88e6390_g2_irl_init_all,
4808 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4809 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4810 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4811 .phy_read = mv88e6xxx_g2_smi_phy_read,
4812 .phy_write = mv88e6xxx_g2_smi_phy_write,
4813 .port_set_link = mv88e6xxx_port_set_link,
4814 .port_sync_link = mv88e6xxx_port_sync_link,
4815 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4816 .port_set_speed_duplex = mv88e6393x_port_set_speed_duplex,
4817 .port_max_speed_mode = mv88e6393x_port_max_speed_mode,
4818 .port_tag_remap = mv88e6390_port_tag_remap,
Marek Behún6584b262021-03-17 14:46:43 +01004819 .port_set_policy = mv88e6393x_port_set_policy,
Pavana Sharmade776d02021-03-17 14:46:42 +01004820 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4821 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4822 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4823 .port_set_ether_type = mv88e6393x_port_set_ether_type,
4824 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4825 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4826 .port_pause_limit = mv88e6390_port_pause_limit,
4827 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4828 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4829 .port_get_cmode = mv88e6352_port_get_cmode,
4830 .port_set_cmode = mv88e6393x_port_set_cmode,
4831 .port_setup_message_port = mv88e6xxx_setup_message_port,
4832 .port_set_upstream_port = mv88e6393x_port_set_upstream_port,
4833 .stats_snapshot = mv88e6390_g1_stats_snapshot,
4834 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4835 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4836 .stats_get_strings = mv88e6320_stats_get_strings,
4837 .stats_get_stats = mv88e6390_stats_get_stats,
4838 /* .set_cpu_port is missing because this family does not support a global
4839 * CPU port, only per port CPU port which is set via
4840 * .port_set_upstream_port method.
4841 */
4842 .set_egress_port = mv88e6393x_set_egress_port,
4843 .watchdog_ops = &mv88e6390_watchdog_ops,
4844 .mgmt_rsvd2cpu = mv88e6393x_port_mgmt_rsvd2cpu,
4845 .pot_clear = mv88e6xxx_g2_pot_clear,
4846 .reset = mv88e6352_g1_reset,
4847 .rmu_disable = mv88e6390_g1_rmu_disable,
4848 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4849 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4850 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4851 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4852 .serdes_power = mv88e6393x_serdes_power,
4853 .serdes_get_lane = mv88e6393x_serdes_get_lane,
4854 .serdes_pcs_get_state = mv88e6393x_serdes_pcs_get_state,
4855 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4856 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4857 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4858 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4859 .serdes_irq_enable = mv88e6393x_serdes_irq_enable,
4860 .serdes_irq_status = mv88e6393x_serdes_irq_status,
4861 /* TODO: serdes stats */
4862 .gpio_ops = &mv88e6352_gpio_ops,
4863 .avb_ops = &mv88e6390_avb_ops,
4864 .ptp_ops = &mv88e6352_ptp_ops,
4865 .phylink_validate = mv88e6393x_phylink_validate,
4866};
4867
Vivien Didelotf81ec902016-05-09 13:22:58 -04004868static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4869 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004870 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004871 .family = MV88E6XXX_FAMILY_6097,
4872 .name = "Marvell 88E6085",
4873 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004874 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004875 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004876 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004877 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004878 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004879 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004880 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004881 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004882 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004883 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004884 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004885 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004886 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004887 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004888 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004889 },
4890
4891 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004892 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004893 .family = MV88E6XXX_FAMILY_6095,
4894 .name = "Marvell 88E6095/88E6095F",
4895 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004896 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004897 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004898 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004899 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004900 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004901 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004902 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004903 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004904 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004905 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004906 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004907 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004908 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004909 },
4910
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004911 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004912 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004913 .family = MV88E6XXX_FAMILY_6097,
4914 .name = "Marvell 88E6097/88E6097F",
4915 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004916 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004917 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004918 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004919 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004920 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004921 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004922 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004923 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004924 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004925 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004926 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004927 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004928 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004929 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02004930 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004931 .ops = &mv88e6097_ops,
4932 },
4933
Vivien Didelotf81ec902016-05-09 13:22:58 -04004934 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004935 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004936 .family = MV88E6XXX_FAMILY_6165,
4937 .name = "Marvell 88E6123",
4938 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004939 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004940 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004941 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004942 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004943 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004944 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004945 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004946 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004947 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004948 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004949 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004950 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004951 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004952 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02004953 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004954 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004955 },
4956
4957 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004958 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004959 .family = MV88E6XXX_FAMILY_6185,
4960 .name = "Marvell 88E6131",
4961 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004962 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004963 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004964 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004965 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004966 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004967 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004968 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004969 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004970 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004971 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004972 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004973 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004974 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004975 },
4976
Vivien Didelot990e27b2017-03-28 13:50:32 -04004977 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004978 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004979 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01004980 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04004981 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004982 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004983 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004984 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004985 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004986 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004987 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004988 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004989 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004990 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004991 .age_time_coeff = 3750,
4992 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004993 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004994 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004995 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004996 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02004997 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004998 .ops = &mv88e6141_ops,
4999 },
5000
Vivien Didelotf81ec902016-05-09 13:22:58 -04005001 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005002 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005003 .family = MV88E6XXX_FAMILY_6165,
5004 .name = "Marvell 88E6161",
5005 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005006 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005007 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005008 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005009 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005010 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005011 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005012 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005013 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005014 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005015 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005016 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005017 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005018 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005019 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005020 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Andrew Lunndfa54342018-07-18 22:38:22 +02005021 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005022 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005023 },
5024
5025 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005026 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005027 .family = MV88E6XXX_FAMILY_6165,
5028 .name = "Marvell 88E6165",
5029 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005030 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005031 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005032 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005033 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005034 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005035 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005036 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005037 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005038 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005039 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005040 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005041 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005042 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005043 .multi_chip = true,
Andrew Lunndfa54342018-07-18 22:38:22 +02005044 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005045 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005046 },
5047
5048 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005049 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005050 .family = MV88E6XXX_FAMILY_6351,
5051 .name = "Marvell 88E6171",
5052 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005053 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005054 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005055 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005056 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005057 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005058 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005059 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005060 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005061 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005062 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005063 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005064 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005065 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005066 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005067 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005068 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005069 },
5070
5071 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005072 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005073 .family = MV88E6XXX_FAMILY_6352,
5074 .name = "Marvell 88E6172",
5075 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005076 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005077 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005078 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005079 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005080 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005081 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005082 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005083 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005084 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005085 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005086 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005087 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005088 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005089 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005090 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005091 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005092 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005093 },
5094
5095 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005096 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005097 .family = MV88E6XXX_FAMILY_6351,
5098 .name = "Marvell 88E6175",
5099 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005100 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005101 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005102 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005103 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005104 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005105 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005106 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005107 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005108 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005109 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005110 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005111 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005112 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005113 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005114 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005115 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005116 },
5117
5118 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005119 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005120 .family = MV88E6XXX_FAMILY_6352,
5121 .name = "Marvell 88E6176",
5122 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005123 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005124 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005125 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005126 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005127 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005128 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005129 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005130 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005131 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005132 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005133 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005134 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005135 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005136 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005137 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005138 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005139 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005140 },
5141
5142 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005143 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005144 .family = MV88E6XXX_FAMILY_6185,
5145 .name = "Marvell 88E6185",
5146 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005147 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005148 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01005149 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005150 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005151 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005152 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005153 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005154 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005155 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005156 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05005157 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005158 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005159 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005160 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005161 },
5162
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005163 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005164 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005165 .family = MV88E6XXX_FAMILY_6390,
5166 .name = "Marvell 88E6190",
5167 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005168 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005169 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005170 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005171 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005172 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005173 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005174 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005175 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005176 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005177 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005178 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005179 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04005180 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005181 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05005182 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005183 .ops = &mv88e6190_ops,
5184 },
5185
5186 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005187 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005188 .family = MV88E6XXX_FAMILY_6390,
5189 .name = "Marvell 88E6190X",
5190 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005191 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005192 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005193 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005194 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005195 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005196 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005197 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005198 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005199 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005200 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005201 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005202 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005203 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005204 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005205 .multi_chip = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005206 .ops = &mv88e6190x_ops,
5207 },
5208
5209 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005210 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005211 .family = MV88E6XXX_FAMILY_6390,
5212 .name = "Marvell 88E6191",
5213 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005214 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005215 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005216 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04005217 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005218 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005219 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005220 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005221 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005222 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005223 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005224 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005225 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005226 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005227 .multi_chip = true,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005228 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04005229 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005230 },
5231
Pavana Sharmade776d02021-03-17 14:46:42 +01005232 [MV88E6191X] = {
5233 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191X,
5234 .family = MV88E6XXX_FAMILY_6393,
5235 .name = "Marvell 88E6191X",
5236 .num_databases = 4096,
5237 .num_ports = 11, /* 10 + Z80 */
5238 .num_internal_phys = 9,
5239 .max_vid = 8191,
5240 .port_base_addr = 0x0,
5241 .phy_base_addr = 0x0,
5242 .global1_addr = 0x1b,
5243 .global2_addr = 0x1c,
5244 .age_time_coeff = 3750,
5245 .g1_irqs = 10,
5246 .g2_irqs = 14,
5247 .atu_move_port_mask = 0x1f,
5248 .pvt = true,
5249 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005250 .ptp_support = true,
5251 .ops = &mv88e6393x_ops,
5252 },
5253
5254 [MV88E6193X] = {
5255 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6193X,
5256 .family = MV88E6XXX_FAMILY_6393,
5257 .name = "Marvell 88E6193X",
5258 .num_databases = 4096,
5259 .num_ports = 11, /* 10 + Z80 */
5260 .num_internal_phys = 9,
5261 .max_vid = 8191,
5262 .port_base_addr = 0x0,
5263 .phy_base_addr = 0x0,
5264 .global1_addr = 0x1b,
5265 .global2_addr = 0x1c,
5266 .age_time_coeff = 3750,
5267 .g1_irqs = 10,
5268 .g2_irqs = 14,
5269 .atu_move_port_mask = 0x1f,
5270 .pvt = true,
5271 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005272 .ptp_support = true,
5273 .ops = &mv88e6393x_ops,
5274 },
5275
Hubert Feurstein49022642019-07-31 10:23:46 +02005276 [MV88E6220] = {
5277 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
5278 .family = MV88E6XXX_FAMILY_6250,
5279 .name = "Marvell 88E6220",
5280 .num_databases = 64,
5281
5282 /* Ports 2-4 are not routed to pins
5283 * => usable ports 0, 1, 5, 6
5284 */
5285 .num_ports = 7,
5286 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02005287 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02005288 .max_vid = 4095,
5289 .port_base_addr = 0x08,
5290 .phy_base_addr = 0x00,
5291 .global1_addr = 0x0f,
5292 .global2_addr = 0x07,
5293 .age_time_coeff = 15000,
5294 .g1_irqs = 9,
5295 .g2_irqs = 10,
5296 .atu_move_port_mask = 0xf,
5297 .dual_chip = true,
Hubert Feurstein71509612019-07-31 10:23:51 +02005298 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02005299 .ops = &mv88e6250_ops,
5300 },
5301
Vivien Didelotf81ec902016-05-09 13:22:58 -04005302 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005303 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005304 .family = MV88E6XXX_FAMILY_6352,
5305 .name = "Marvell 88E6240",
5306 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005307 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005308 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005309 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005310 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005311 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005312 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005313 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005314 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005315 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005316 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005317 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005318 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005319 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005320 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005321 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005322 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005323 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005324 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005325 },
5326
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005327 [MV88E6250] = {
5328 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
5329 .family = MV88E6XXX_FAMILY_6250,
5330 .name = "Marvell 88E6250",
5331 .num_databases = 64,
5332 .num_ports = 7,
5333 .num_internal_phys = 5,
5334 .max_vid = 4095,
5335 .port_base_addr = 0x08,
5336 .phy_base_addr = 0x00,
5337 .global1_addr = 0x0f,
5338 .global2_addr = 0x07,
5339 .age_time_coeff = 15000,
5340 .g1_irqs = 9,
5341 .g2_irqs = 10,
5342 .atu_move_port_mask = 0xf,
5343 .dual_chip = true,
Hubert Feurstein71509612019-07-31 10:23:51 +02005344 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005345 .ops = &mv88e6250_ops,
5346 },
5347
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005348 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005349 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005350 .family = MV88E6XXX_FAMILY_6390,
5351 .name = "Marvell 88E6290",
5352 .num_databases = 4096,
5353 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005354 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005355 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005356 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005357 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005358 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005359 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005360 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005361 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005362 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005363 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005364 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005365 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005366 .multi_chip = true,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005367 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005368 .ops = &mv88e6290_ops,
5369 },
5370
Vivien Didelotf81ec902016-05-09 13:22:58 -04005371 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005372 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005373 .family = MV88E6XXX_FAMILY_6320,
5374 .name = "Marvell 88E6320",
5375 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005376 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005377 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005378 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005379 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005380 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005381 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005382 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005383 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005384 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005385 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005386 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005387 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005388 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005389 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005390 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005391 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005392 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005393 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005394 },
5395
5396 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005397 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005398 .family = MV88E6XXX_FAMILY_6320,
5399 .name = "Marvell 88E6321",
5400 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005401 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005402 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005403 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005404 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005405 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005406 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005407 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005408 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005409 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005410 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005411 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005412 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005413 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005414 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005415 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005416 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005417 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005418 },
5419
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005420 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005421 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005422 .family = MV88E6XXX_FAMILY_6341,
5423 .name = "Marvell 88E6341",
5424 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005425 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005426 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005427 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005428 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005429 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005430 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005431 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005432 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005433 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005434 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005435 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005436 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005437 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005438 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005439 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005440 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005441 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005442 .ops = &mv88e6341_ops,
5443 },
5444
Vivien Didelotf81ec902016-05-09 13:22:58 -04005445 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005446 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005447 .family = MV88E6XXX_FAMILY_6351,
5448 .name = "Marvell 88E6350",
5449 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005450 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005451 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005452 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005453 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005454 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005455 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005456 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005457 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005458 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005459 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005460 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005461 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005462 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005463 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005464 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005465 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005466 },
5467
5468 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005469 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005470 .family = MV88E6XXX_FAMILY_6351,
5471 .name = "Marvell 88E6351",
5472 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005473 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005474 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005475 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005476 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005477 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005478 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005479 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005480 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005481 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005482 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005483 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005484 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005485 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005486 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005487 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005488 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005489 },
5490
5491 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005492 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005493 .family = MV88E6XXX_FAMILY_6352,
5494 .name = "Marvell 88E6352",
5495 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005496 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005497 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005498 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005499 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005500 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005501 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005502 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005503 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005504 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005505 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005506 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005507 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005508 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005509 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005510 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005511 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005512 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005513 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005514 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005515 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005516 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005517 .family = MV88E6XXX_FAMILY_6390,
5518 .name = "Marvell 88E6390",
5519 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005520 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005521 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005522 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005523 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005524 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005525 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005526 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005527 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005528 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005529 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005530 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005531 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005532 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005533 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005534 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005535 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005536 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005537 .ops = &mv88e6390_ops,
5538 },
5539 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005540 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005541 .family = MV88E6XXX_FAMILY_6390,
5542 .name = "Marvell 88E6390X",
5543 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005544 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005545 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005546 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005547 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005548 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005549 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005550 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005551 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005552 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005553 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005554 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005555 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005556 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005557 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005558 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005559 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005560 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005561 .ops = &mv88e6390x_ops,
5562 },
Pavana Sharmade776d02021-03-17 14:46:42 +01005563
5564 [MV88E6393X] = {
5565 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
5566 .family = MV88E6XXX_FAMILY_6393,
5567 .name = "Marvell 88E6393X",
5568 .num_databases = 4096,
5569 .num_ports = 11, /* 10 + Z80 */
5570 .num_internal_phys = 9,
5571 .max_vid = 8191,
5572 .port_base_addr = 0x0,
5573 .phy_base_addr = 0x0,
5574 .global1_addr = 0x1b,
5575 .global2_addr = 0x1c,
5576 .age_time_coeff = 3750,
5577 .g1_irqs = 10,
5578 .g2_irqs = 14,
5579 .atu_move_port_mask = 0x1f,
5580 .pvt = true,
5581 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005582 .ptp_support = true,
5583 .ops = &mv88e6393x_ops,
5584 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005585};
5586
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005587static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005588{
Vivien Didelota439c062016-04-17 13:23:58 -04005589 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005590
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005591 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5592 if (mv88e6xxx_table[i].prod_num == prod_num)
5593 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005594
Vivien Didelotb9b37712015-10-30 19:39:48 -04005595 return NULL;
5596}
5597
Vivien Didelotfad09c72016-06-21 12:28:20 -04005598static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005599{
5600 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005601 unsigned int prod_num, rev;
5602 u16 id;
5603 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005604
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005605 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005606 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005607 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005608 if (err)
5609 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005610
Vivien Didelot107fcc12017-06-12 12:37:36 -04005611 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5612 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005613
5614 info = mv88e6xxx_lookup_info(prod_num);
5615 if (!info)
5616 return -ENODEV;
5617
Vivien Didelotcaac8542016-06-20 13:14:09 -04005618 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005619 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005620
Vivien Didelotfad09c72016-06-21 12:28:20 -04005621 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5622 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005623
5624 return 0;
5625}
5626
Vivien Didelotfad09c72016-06-21 12:28:20 -04005627static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005628{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005629 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005630
Vivien Didelotfad09c72016-06-21 12:28:20 -04005631 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5632 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005633 return NULL;
5634
Vivien Didelotfad09c72016-06-21 12:28:20 -04005635 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005636
Vivien Didelotfad09c72016-06-21 12:28:20 -04005637 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005638 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005639 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005640
Vivien Didelotfad09c72016-06-21 12:28:20 -04005641 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005642}
5643
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005644static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005645 int port,
5646 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005647{
Vivien Didelot04bed142016-08-31 18:06:13 -04005648 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005649
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005650 return chip->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005651}
5652
Tobias Waldekranz9a99bef2021-04-20 20:53:08 +02005653static int mv88e6xxx_change_tag_protocol(struct dsa_switch *ds, int port,
5654 enum dsa_tag_protocol proto)
5655{
5656 struct mv88e6xxx_chip *chip = ds->priv;
5657 enum dsa_tag_protocol old_protocol;
5658 int err;
5659
5660 switch (proto) {
5661 case DSA_TAG_PROTO_EDSA:
5662 switch (chip->info->edsa_support) {
5663 case MV88E6XXX_EDSA_UNSUPPORTED:
5664 return -EPROTONOSUPPORT;
5665 case MV88E6XXX_EDSA_UNDOCUMENTED:
5666 dev_warn(chip->dev, "Relying on undocumented EDSA tagging behavior\n");
5667 fallthrough;
5668 case MV88E6XXX_EDSA_SUPPORTED:
5669 break;
5670 }
5671 break;
5672 case DSA_TAG_PROTO_DSA:
5673 break;
5674 default:
5675 return -EPROTONOSUPPORT;
5676 }
5677
5678 old_protocol = chip->tag_protocol;
5679 chip->tag_protocol = proto;
5680
5681 mv88e6xxx_reg_lock(chip);
5682 err = mv88e6xxx_setup_port_mode(chip, port);
5683 mv88e6xxx_reg_unlock(chip);
5684
5685 if (err)
5686 chip->tag_protocol = old_protocol;
5687
5688 return err;
5689}
5690
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005691static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
5692 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005693{
Vivien Didelot04bed142016-08-31 18:06:13 -04005694 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005695 int err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005696
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005697 mv88e6xxx_reg_lock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005698 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5699 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005700 mv88e6xxx_reg_unlock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005701
5702 return err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005703}
5704
5705static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5706 const struct switchdev_obj_port_mdb *mdb)
5707{
Vivien Didelot04bed142016-08-31 18:06:13 -04005708 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005709 int err;
5710
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005711 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005712 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005713 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005714
5715 return err;
5716}
5717
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005718static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5719 struct dsa_mall_mirror_tc_entry *mirror,
5720 bool ingress)
5721{
5722 enum mv88e6xxx_egress_direction direction = ingress ?
5723 MV88E6XXX_EGRESS_DIR_INGRESS :
5724 MV88E6XXX_EGRESS_DIR_EGRESS;
5725 struct mv88e6xxx_chip *chip = ds->priv;
5726 bool other_mirrors = false;
5727 int i;
5728 int err;
5729
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005730 mutex_lock(&chip->reg_lock);
5731 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5732 mirror->to_local_port) {
5733 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5734 other_mirrors |= ingress ?
5735 chip->ports[i].mirror_ingress :
5736 chip->ports[i].mirror_egress;
5737
5738 /* Can't change egress port when other mirror is active */
5739 if (other_mirrors) {
5740 err = -EBUSY;
5741 goto out;
5742 }
5743
Marek Behún2fda45f2021-03-17 14:46:41 +01005744 err = mv88e6xxx_set_egress_port(chip, direction,
5745 mirror->to_local_port);
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005746 if (err)
5747 goto out;
5748 }
5749
5750 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5751out:
5752 mutex_unlock(&chip->reg_lock);
5753
5754 return err;
5755}
5756
5757static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5758 struct dsa_mall_mirror_tc_entry *mirror)
5759{
5760 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5761 MV88E6XXX_EGRESS_DIR_INGRESS :
5762 MV88E6XXX_EGRESS_DIR_EGRESS;
5763 struct mv88e6xxx_chip *chip = ds->priv;
5764 bool other_mirrors = false;
5765 int i;
5766
5767 mutex_lock(&chip->reg_lock);
5768 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5769 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5770
5771 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5772 other_mirrors |= mirror->ingress ?
5773 chip->ports[i].mirror_ingress :
5774 chip->ports[i].mirror_egress;
5775
5776 /* Reset egress port when no other mirror is active */
5777 if (!other_mirrors) {
Marek Behún2fda45f2021-03-17 14:46:41 +01005778 if (mv88e6xxx_set_egress_port(chip, direction,
5779 dsa_upstream_port(ds, port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005780 dev_err(ds->dev, "failed to set egress port\n");
5781 }
5782
5783 mutex_unlock(&chip->reg_lock);
5784}
5785
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005786static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port,
5787 struct switchdev_brport_flags flags,
5788 struct netlink_ext_ack *extack)
5789{
5790 struct mv88e6xxx_chip *chip = ds->priv;
5791 const struct mv88e6xxx_ops *ops;
5792
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01005793 if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
5794 BR_BCAST_FLOOD))
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005795 return -EINVAL;
5796
5797 ops = chip->info->ops;
5798
5799 if ((flags.mask & BR_FLOOD) && !ops->port_set_ucast_flood)
5800 return -EINVAL;
5801
5802 if ((flags.mask & BR_MCAST_FLOOD) && !ops->port_set_mcast_flood)
5803 return -EINVAL;
5804
5805 return 0;
5806}
5807
5808static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
5809 struct switchdev_brport_flags flags,
5810 struct netlink_ext_ack *extack)
Russell King4f859012019-02-20 15:35:05 -08005811{
5812 struct mv88e6xxx_chip *chip = ds->priv;
5813 int err = -EOPNOTSUPP;
5814
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005815 mv88e6xxx_reg_lock(chip);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005816
Tobias Waldekranz041bd542021-03-18 20:25:39 +01005817 if (flags.mask & BR_LEARNING) {
5818 bool learning = !!(flags.val & BR_LEARNING);
5819 u16 pav = learning ? (1 << port) : 0;
5820
5821 err = mv88e6xxx_port_set_assoc_vector(chip, port, pav);
5822 if (err)
5823 goto out;
Tobias Waldekranz041bd542021-03-18 20:25:39 +01005824 }
5825
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005826 if (flags.mask & BR_FLOOD) {
5827 bool unicast = !!(flags.val & BR_FLOOD);
5828
5829 err = chip->info->ops->port_set_ucast_flood(chip, port,
5830 unicast);
5831 if (err)
5832 goto out;
5833 }
5834
5835 if (flags.mask & BR_MCAST_FLOOD) {
5836 bool multicast = !!(flags.val & BR_MCAST_FLOOD);
5837
5838 err = chip->info->ops->port_set_mcast_flood(chip, port,
5839 multicast);
5840 if (err)
5841 goto out;
5842 }
5843
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01005844 if (flags.mask & BR_BCAST_FLOOD) {
5845 bool broadcast = !!(flags.val & BR_BCAST_FLOOD);
5846
5847 err = mv88e6xxx_port_broadcast_sync(chip, port, broadcast);
5848 if (err)
5849 goto out;
5850 }
5851
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005852out:
5853 mv88e6xxx_reg_unlock(chip);
5854
5855 return err;
5856}
5857
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005858static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
5859 struct net_device *lag,
5860 struct netdev_lag_upper_info *info)
5861{
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005862 struct mv88e6xxx_chip *chip = ds->priv;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005863 struct dsa_port *dp;
5864 int id, members = 0;
5865
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005866 if (!mv88e6xxx_has_lag(chip))
5867 return false;
5868
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005869 id = dsa_lag_id(ds->dst, lag);
5870 if (id < 0 || id >= ds->num_lag_ids)
5871 return false;
5872
5873 dsa_lag_foreach_port(dp, ds->dst, lag)
5874 /* Includes the port joining the LAG */
5875 members++;
5876
5877 if (members > 8)
5878 return false;
5879
5880 /* We could potentially relax this to include active
5881 * backup in the future.
5882 */
5883 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
5884 return false;
5885
5886 /* Ideally we would also validate that the hash type matches
5887 * the hardware. Alas, this is always set to unknown on team
5888 * interfaces.
5889 */
5890 return true;
5891}
5892
5893static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct net_device *lag)
5894{
5895 struct mv88e6xxx_chip *chip = ds->priv;
5896 struct dsa_port *dp;
5897 u16 map = 0;
5898 int id;
5899
5900 id = dsa_lag_id(ds->dst, lag);
5901
5902 /* Build the map of all ports to distribute flows destined for
5903 * this LAG. This can be either a local user port, or a DSA
5904 * port if the LAG port is on a remote chip.
5905 */
5906 dsa_lag_foreach_port(dp, ds->dst, lag)
5907 map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));
5908
5909 return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
5910}
5911
5912static const u8 mv88e6xxx_lag_mask_table[8][8] = {
5913 /* Row number corresponds to the number of active members in a
5914 * LAG. Each column states which of the eight hash buckets are
5915 * mapped to the column:th port in the LAG.
5916 *
5917 * Example: In a LAG with three active ports, the second port
5918 * ([2][1]) would be selected for traffic mapped to buckets
5919 * 3,4,5 (0x38).
5920 */
5921 { 0xff, 0, 0, 0, 0, 0, 0, 0 },
5922 { 0x0f, 0xf0, 0, 0, 0, 0, 0, 0 },
5923 { 0x07, 0x38, 0xc0, 0, 0, 0, 0, 0 },
5924 { 0x03, 0x0c, 0x30, 0xc0, 0, 0, 0, 0 },
5925 { 0x03, 0x0c, 0x30, 0x40, 0x80, 0, 0, 0 },
5926 { 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80, 0, 0 },
5927 { 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0 },
5928 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
5929};
5930
5931static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
5932 int num_tx, int nth)
5933{
5934 u8 active = 0;
5935 int i;
5936
5937 num_tx = num_tx <= 8 ? num_tx : 8;
5938 if (nth < num_tx)
5939 active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];
5940
5941 for (i = 0; i < 8; i++) {
5942 if (BIT(i) & active)
5943 mask[i] |= BIT(port);
5944 }
5945}
5946
5947static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
5948{
5949 struct mv88e6xxx_chip *chip = ds->priv;
5950 unsigned int id, num_tx;
5951 struct net_device *lag;
5952 struct dsa_port *dp;
5953 int i, err, nth;
5954 u16 mask[8];
5955 u16 ivec;
5956
5957 /* Assume no port is a member of any LAG. */
5958 ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;
5959
5960 /* Disable all masks for ports that _are_ members of a LAG. */
5961 list_for_each_entry(dp, &ds->dst->ports, list) {
5962 if (!dp->lag_dev || dp->ds != ds)
5963 continue;
5964
5965 ivec &= ~BIT(dp->index);
5966 }
5967
5968 for (i = 0; i < 8; i++)
5969 mask[i] = ivec;
5970
5971 /* Enable the correct subset of masks for all LAG ports that
5972 * are in the Tx set.
5973 */
5974 dsa_lags_foreach_id(id, ds->dst) {
5975 lag = dsa_lag_dev(ds->dst, id);
5976 if (!lag)
5977 continue;
5978
5979 num_tx = 0;
5980 dsa_lag_foreach_port(dp, ds->dst, lag) {
5981 if (dp->lag_tx_enabled)
5982 num_tx++;
5983 }
5984
5985 if (!num_tx)
5986 continue;
5987
5988 nth = 0;
5989 dsa_lag_foreach_port(dp, ds->dst, lag) {
5990 if (!dp->lag_tx_enabled)
5991 continue;
5992
5993 if (dp->ds == ds)
5994 mv88e6xxx_lag_set_port_mask(mask, dp->index,
5995 num_tx, nth);
5996
5997 nth++;
5998 }
5999 }
6000
6001 for (i = 0; i < 8; i++) {
6002 err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
6003 if (err)
6004 return err;
6005 }
6006
6007 return 0;
6008}
6009
6010static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
6011 struct net_device *lag)
6012{
6013 int err;
6014
6015 err = mv88e6xxx_lag_sync_masks(ds);
6016
6017 if (!err)
6018 err = mv88e6xxx_lag_sync_map(ds, lag);
6019
6020 return err;
6021}
6022
6023static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port)
6024{
6025 struct mv88e6xxx_chip *chip = ds->priv;
6026 int err;
6027
6028 mv88e6xxx_reg_lock(chip);
6029 err = mv88e6xxx_lag_sync_masks(ds);
6030 mv88e6xxx_reg_unlock(chip);
6031 return err;
6032}
6033
6034static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
6035 struct net_device *lag,
6036 struct netdev_lag_upper_info *info)
6037{
6038 struct mv88e6xxx_chip *chip = ds->priv;
6039 int err, id;
6040
6041 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
6042 return -EOPNOTSUPP;
6043
6044 id = dsa_lag_id(ds->dst, lag);
6045
6046 mv88e6xxx_reg_lock(chip);
6047
6048 err = mv88e6xxx_port_set_trunk(chip, port, true, id);
6049 if (err)
6050 goto err_unlock;
6051
6052 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6053 if (err)
6054 goto err_clear_trunk;
6055
6056 mv88e6xxx_reg_unlock(chip);
6057 return 0;
6058
6059err_clear_trunk:
6060 mv88e6xxx_port_set_trunk(chip, port, false, 0);
6061err_unlock:
6062 mv88e6xxx_reg_unlock(chip);
6063 return err;
6064}
6065
6066static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
6067 struct net_device *lag)
6068{
6069 struct mv88e6xxx_chip *chip = ds->priv;
6070 int err_sync, err_trunk;
6071
6072 mv88e6xxx_reg_lock(chip);
6073 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6074 err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
6075 mv88e6xxx_reg_unlock(chip);
6076 return err_sync ? : err_trunk;
6077}
6078
6079static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
6080 int port)
6081{
6082 struct mv88e6xxx_chip *chip = ds->priv;
6083 int err;
6084
6085 mv88e6xxx_reg_lock(chip);
6086 err = mv88e6xxx_lag_sync_masks(ds);
6087 mv88e6xxx_reg_unlock(chip);
6088 return err;
6089}
6090
6091static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
6092 int port, struct net_device *lag,
6093 struct netdev_lag_upper_info *info)
6094{
6095 struct mv88e6xxx_chip *chip = ds->priv;
6096 int err;
6097
6098 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
6099 return -EOPNOTSUPP;
6100
6101 mv88e6xxx_reg_lock(chip);
6102
6103 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6104 if (err)
6105 goto unlock;
6106
6107 err = mv88e6xxx_pvt_map(chip, sw_index, port);
6108
6109unlock:
6110 mv88e6xxx_reg_unlock(chip);
6111 return err;
6112}
6113
6114static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
6115 int port, struct net_device *lag)
6116{
6117 struct mv88e6xxx_chip *chip = ds->priv;
6118 int err_sync, err_pvt;
6119
6120 mv88e6xxx_reg_lock(chip);
6121 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6122 err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
6123 mv88e6xxx_reg_unlock(chip);
6124 return err_sync ? : err_pvt;
6125}
6126
Florian Fainellia82f67a2017-01-08 14:52:08 -08006127static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02006128 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Tobias Waldekranz9a99bef2021-04-20 20:53:08 +02006129 .change_tag_protocol = mv88e6xxx_change_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006130 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02006131 .teardown = mv88e6xxx_teardown,
Vladimir Olteanfd292c12021-09-17 17:29:16 +03006132 .port_setup = mv88e6xxx_port_setup,
6133 .port_teardown = mv88e6xxx_port_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07006134 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00006135 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07006136 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00006137 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07006138 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
6139 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006140 .get_strings = mv88e6xxx_get_strings,
6141 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
6142 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02006143 .port_enable = mv88e6xxx_port_enable,
6144 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02006145 .port_max_mtu = mv88e6xxx_get_max_mtu,
6146 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04006147 .get_mac_eee = mv88e6xxx_get_mac_eee,
6148 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006149 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006150 .get_eeprom = mv88e6xxx_get_eeprom,
6151 .set_eeprom = mv88e6xxx_set_eeprom,
6152 .get_regs_len = mv88e6xxx_get_regs_len,
6153 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04006154 .get_rxnfc = mv88e6xxx_get_rxnfc,
6155 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04006156 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006157 .port_bridge_join = mv88e6xxx_port_bridge_join,
6158 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02006159 .port_pre_bridge_flags = mv88e6xxx_port_pre_bridge_flags,
6160 .port_bridge_flags = mv88e6xxx_port_bridge_flags,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006161 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04006162 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006163 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006164 .port_vlan_add = mv88e6xxx_port_vlan_add,
6165 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006166 .port_fdb_add = mv88e6xxx_port_fdb_add,
6167 .port_fdb_del = mv88e6xxx_port_fdb_del,
6168 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04006169 .port_mdb_add = mv88e6xxx_port_mdb_add,
6170 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01006171 .port_mirror_add = mv88e6xxx_port_mirror_add,
6172 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04006173 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
6174 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006175 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
6176 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
6177 .port_txtstamp = mv88e6xxx_port_txtstamp,
6178 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
6179 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02006180 .devlink_param_get = mv88e6xxx_devlink_param_get,
6181 .devlink_param_set = mv88e6xxx_devlink_param_set,
Andrew Lunn93157302020-09-18 21:11:09 +02006182 .devlink_info_get = mv88e6xxx_devlink_info_get,
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006183 .port_lag_change = mv88e6xxx_port_lag_change,
6184 .port_lag_join = mv88e6xxx_port_lag_join,
6185 .port_lag_leave = mv88e6xxx_port_lag_leave,
6186 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
6187 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
6188 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
Vladimir Olteance5df682021-07-22 18:55:41 +03006189 .port_bridge_tx_fwd_offload = mv88e6xxx_bridge_tx_fwd_offload,
6190 .port_bridge_tx_fwd_unoffload = mv88e6xxx_bridge_tx_fwd_unoffload,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006191};
6192
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08006193static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006194{
Vivien Didelotfad09c72016-06-21 12:28:20 -04006195 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006196 struct dsa_switch *ds;
6197
Vivien Didelot7e99e342019-10-21 16:51:30 -04006198 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006199 if (!ds)
6200 return -ENOMEM;
6201
Vivien Didelot7e99e342019-10-21 16:51:30 -04006202 ds->dev = dev;
6203 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006204 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006205 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04006206 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04006207 ds->ageing_time_min = chip->info->age_time_coeff;
6208 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006209
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006210 /* Some chips support up to 32, but that requires enabling the
6211 * 5-bit port mode, which we do not support. 640k^W16 ought to
6212 * be enough for anyone.
6213 */
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01006214 ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006215
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006216 dev_set_drvdata(dev, ds);
6217
Vivien Didelot23c9ee42017-05-26 18:12:51 -04006218 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006219}
6220
Vivien Didelotfad09c72016-06-21 12:28:20 -04006221static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006222{
Vivien Didelotfad09c72016-06-21 12:28:20 -04006223 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006224}
6225
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006226static const void *pdata_device_get_match_data(struct device *dev)
6227{
6228 const struct of_device_id *matches = dev->driver->of_match_table;
6229 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
6230
6231 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
6232 matches++) {
6233 if (!strcmp(pdata->compatible, matches->compatible))
6234 return matches->data;
6235 }
6236 return NULL;
6237}
6238
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006239/* There is no suspend to RAM support at DSA level yet, the switch configuration
6240 * would be lost after a power cycle so prevent it to be suspended.
6241 */
6242static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
6243{
6244 return -EOPNOTSUPP;
6245}
6246
6247static int __maybe_unused mv88e6xxx_resume(struct device *dev)
6248{
6249 return 0;
6250}
6251
6252static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
6253
Vivien Didelot57d32312016-06-20 13:13:58 -04006254static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006255{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006256 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04006257 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006258 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006259 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04006260 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006261 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02006262 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006263
Andrew Lunn7bb8c992018-05-31 00:15:42 +02006264 if (!np && !pdata)
6265 return -EINVAL;
6266
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006267 if (np)
6268 compat_info = of_device_get_match_data(dev);
6269
6270 if (pdata) {
6271 compat_info = pdata_device_get_match_data(dev);
6272
6273 if (!pdata->netdev)
6274 return -EINVAL;
6275
6276 for (port = 0; port < DSA_MAX_PORTS; port++) {
6277 if (!(pdata->enabled_ports & (1 << port)))
6278 continue;
6279 if (strcmp(pdata->cd.port_names[port], "cpu"))
6280 continue;
6281 pdata->cd.netdev[port] = &pdata->netdev->dev;
6282 break;
6283 }
6284 }
6285
Vivien Didelotcaac8542016-06-20 13:14:09 -04006286 if (!compat_info)
6287 return -EINVAL;
6288
Vivien Didelotfad09c72016-06-21 12:28:20 -04006289 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006290 if (!chip) {
6291 err = -ENOMEM;
6292 goto out;
6293 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006294
Vivien Didelotfad09c72016-06-21 12:28:20 -04006295 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04006296
Vivien Didelotfad09c72016-06-21 12:28:20 -04006297 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04006298 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006299 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006300
Andrew Lunnb4308f02016-11-21 23:26:55 +01006301 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006302 if (IS_ERR(chip->reset)) {
6303 err = PTR_ERR(chip->reset);
6304 goto out;
6305 }
Baruch Siach7b75e492019-06-27 21:17:39 +03006306 if (chip->reset)
6307 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01006308
Vivien Didelotfad09c72016-06-21 12:28:20 -04006309 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04006310 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006311 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006312
Tobias Waldekranz670bb802021-04-20 20:53:07 +02006313 if (chip->info->edsa_support == MV88E6XXX_EDSA_SUPPORTED)
6314 chip->tag_protocol = DSA_TAG_PROTO_EDSA;
6315 else
6316 chip->tag_protocol = DSA_TAG_PROTO_DSA;
6317
Vivien Didelote57e5e72016-08-15 17:19:00 -04006318 mv88e6xxx_phy_init(chip);
6319
Andrew Lunn00baabe2018-05-19 22:31:35 +02006320 if (chip->info->ops->get_eeprom) {
6321 if (np)
6322 of_property_read_u32(np, "eeprom-length",
6323 &chip->eeprom_len);
6324 else
6325 chip->eeprom_len = pdata->eeprom_len;
6326 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006327
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006328 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006329 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006330 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02006331 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02006332 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02006333
Andrew Lunna27415d2019-05-01 00:10:50 +02006334 if (np) {
6335 chip->irq = of_irq_get(np, 0);
6336 if (chip->irq == -EPROBE_DEFER) {
6337 err = chip->irq;
6338 goto out;
6339 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02006340 }
6341
Andrew Lunna27415d2019-05-01 00:10:50 +02006342 if (pdata)
6343 chip->irq = pdata->irq;
6344
Andrew Lunn294d7112018-02-22 22:58:32 +01006345 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01006346 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01006347 * controllers
6348 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006349 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006350 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006351 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006352 else
6353 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006354 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006355
Andrew Lunn294d7112018-02-22 22:58:32 +01006356 if (err)
6357 goto out;
6358
6359 if (chip->info->g2_irqs > 0) {
6360 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006361 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01006362 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02006363 }
6364
Andrew Lunn294d7112018-02-22 22:58:32 +01006365 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
6366 if (err)
6367 goto out_g2_irq;
6368
6369 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
6370 if (err)
6371 goto out_g1_atu_prob_irq;
6372
Andrew Lunna3c53be52017-01-24 14:53:50 +01006373 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02006374 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01006375 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02006376
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08006377 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006378 if (err)
6379 goto out_mdio;
6380
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006381 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02006382
6383out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01006384 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01006385out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006386 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01006387out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006388 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006389out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006390 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006391 mv88e6xxx_g2_irq_free(chip);
6392out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006393 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006394 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006395 else
6396 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006397out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006398 if (pdata)
6399 dev_put(pdata->netdev);
6400
Andrew Lunndc30c352016-10-16 19:56:49 +02006401 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006402}
6403
6404static void mv88e6xxx_remove(struct mdio_device *mdiodev)
6405{
6406 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006407 struct mv88e6xxx_chip *chip;
6408
6409 if (!ds)
6410 return;
6411
6412 chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006413
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006414 if (chip->info->ptp_support) {
6415 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006416 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006417 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006418
Andrew Lunn930188c2016-08-22 16:01:03 +02006419 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006420 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01006421 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006422
Andrew Lunn76f38f12018-03-17 20:21:09 +01006423 mv88e6xxx_g1_vtu_prob_irq_free(chip);
6424 mv88e6xxx_g1_atu_prob_irq_free(chip);
6425
6426 if (chip->info->g2_irqs > 0)
6427 mv88e6xxx_g2_irq_free(chip);
6428
Andrew Lunn76f38f12018-03-17 20:21:09 +01006429 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006430 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01006431 else
6432 mv88e6xxx_irq_poll_free(chip);
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006433
6434 dev_set_drvdata(&mdiodev->dev, NULL);
6435}
6436
6437static void mv88e6xxx_shutdown(struct mdio_device *mdiodev)
6438{
6439 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
6440
6441 if (!ds)
6442 return;
6443
6444 dsa_switch_shutdown(ds);
6445
6446 dev_set_drvdata(&mdiodev->dev, NULL);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006447}
6448
6449static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04006450 {
6451 .compatible = "marvell,mv88e6085",
6452 .data = &mv88e6xxx_table[MV88E6085],
6453 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01006454 {
6455 .compatible = "marvell,mv88e6190",
6456 .data = &mv88e6xxx_table[MV88E6190],
6457 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00006458 {
6459 .compatible = "marvell,mv88e6250",
6460 .data = &mv88e6xxx_table[MV88E6250],
6461 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006462 { /* sentinel */ },
6463};
6464
6465MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
6466
6467static struct mdio_driver mv88e6xxx_driver = {
6468 .probe = mv88e6xxx_probe,
6469 .remove = mv88e6xxx_remove,
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006470 .shutdown = mv88e6xxx_shutdown,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006471 .mdiodrv.driver = {
6472 .name = "mv88e6085",
6473 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006474 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006475 },
6476};
6477
Andrew Lunn7324d502019-04-27 19:19:10 +02006478mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00006479
6480MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
6481MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
6482MODULE_LICENSE("GPL");