blob: d46f0c096c9713bc2bbc105ff320d9bebc99403c [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;
488 u8 lane;
489 int err;
490
491 mv88e6xxx_reg_lock(chip);
492 lane = mv88e6xxx_serdes_get_lane(chip, port);
493 if (lane && chip->info->ops->serdes_pcs_get_state)
494 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;
509 u8 lane;
510
511 if (ops->serdes_pcs_config) {
512 lane = mv88e6xxx_serdes_get_lane(chip, port);
513 if (lane)
514 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;
526 u8 lane;
527
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);
533 if (lane)
534 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;
547 u8 lane;
548
549 if (!phylink_autoneg_inband(mode) && ops->serdes_pcs_link_up) {
550 lane = mv88e6xxx_serdes_get_lane(chip, port);
551 if (lane)
552 return ops->serdes_pcs_link_up(chip, port, lane,
553 speed, duplex);
554 }
555
556 return 0;
557}
558
Russell King6c422e32018-08-09 15:38:39 +0200559static void mv88e6065_phylink_validate(struct mv88e6xxx_chip *chip, int port,
560 unsigned long *mask,
561 struct phylink_link_state *state)
562{
563 if (!phy_interface_mode_is_8023z(state->interface)) {
564 /* 10M and 100M are only supported in non-802.3z mode */
565 phylink_set(mask, 10baseT_Half);
566 phylink_set(mask, 10baseT_Full);
567 phylink_set(mask, 100baseT_Half);
568 phylink_set(mask, 100baseT_Full);
569 }
570}
571
572static void mv88e6185_phylink_validate(struct mv88e6xxx_chip *chip, int port,
573 unsigned long *mask,
574 struct phylink_link_state *state)
575{
576 /* FIXME: if the port is in 1000Base-X mode, then it only supports
577 * 1000M FD speeds. In this case, CMODE will indicate 5.
578 */
579 phylink_set(mask, 1000baseT_Full);
580 phylink_set(mask, 1000baseX_Full);
581
582 mv88e6065_phylink_validate(chip, port, mask, state);
583}
584
Marek Behúne3af71a2019-02-25 12:39:55 +0100585static void mv88e6341_phylink_validate(struct mv88e6xxx_chip *chip, int port,
586 unsigned long *mask,
587 struct phylink_link_state *state)
588{
589 if (port >= 5)
590 phylink_set(mask, 2500baseX_Full);
591
592 /* No ethtool bits for 200Mbps */
593 phylink_set(mask, 1000baseT_Full);
594 phylink_set(mask, 1000baseX_Full);
595
596 mv88e6065_phylink_validate(chip, port, mask, state);
597}
598
Russell King6c422e32018-08-09 15:38:39 +0200599static void mv88e6352_phylink_validate(struct mv88e6xxx_chip *chip, int port,
600 unsigned long *mask,
601 struct phylink_link_state *state)
602{
603 /* No ethtool bits for 200Mbps */
604 phylink_set(mask, 1000baseT_Full);
605 phylink_set(mask, 1000baseX_Full);
606
607 mv88e6065_phylink_validate(chip, port, mask, state);
608}
609
610static void mv88e6390_phylink_validate(struct mv88e6xxx_chip *chip, int port,
611 unsigned long *mask,
612 struct phylink_link_state *state)
613{
Andrew Lunnec260162019-02-08 22:25:44 +0100614 if (port >= 9) {
Russell King6c422e32018-08-09 15:38:39 +0200615 phylink_set(mask, 2500baseX_Full);
Andrew Lunnec260162019-02-08 22:25:44 +0100616 phylink_set(mask, 2500baseT_Full);
617 }
Russell King6c422e32018-08-09 15:38:39 +0200618
619 /* No ethtool bits for 200Mbps */
620 phylink_set(mask, 1000baseT_Full);
621 phylink_set(mask, 1000baseX_Full);
622
623 mv88e6065_phylink_validate(chip, port, mask, state);
624}
625
626static void mv88e6390x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
627 unsigned long *mask,
628 struct phylink_link_state *state)
629{
630 if (port >= 9) {
631 phylink_set(mask, 10000baseT_Full);
632 phylink_set(mask, 10000baseKR_Full);
633 }
634
635 mv88e6390_phylink_validate(chip, port, mask, state);
636}
637
Russell Kingc9a23562018-05-10 13:17:35 -0700638static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
639 unsigned long *supported,
640 struct phylink_link_state *state)
641{
Russell King6c422e32018-08-09 15:38:39 +0200642 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
643 struct mv88e6xxx_chip *chip = ds->priv;
644
645 /* Allow all the expected bits */
646 phylink_set(mask, Autoneg);
647 phylink_set(mask, Pause);
648 phylink_set_port_modes(mask);
649
650 if (chip->info->ops->phylink_validate)
651 chip->info->ops->phylink_validate(chip, port, mask, state);
652
653 bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
654 bitmap_and(state->advertising, state->advertising, mask,
655 __ETHTOOL_LINK_MODE_MASK_NBITS);
656
657 /* We can only operate at 2500BaseX or 1000BaseX. If requested
658 * to advertise both, only report advertising at 2500BaseX.
659 */
660 phylink_helper_basex_speed(state);
Russell Kingc9a23562018-05-10 13:17:35 -0700661}
662
Russell Kingc9a23562018-05-10 13:17:35 -0700663static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
664 unsigned int mode,
665 const struct phylink_link_state *state)
666{
667 struct mv88e6xxx_chip *chip = ds->priv;
Russell Kingfad58192020-07-19 12:00:35 +0100668 struct mv88e6xxx_port *p;
Russell King64d47d52020-03-14 10:15:38 +0000669 int err;
Russell Kingc9a23562018-05-10 13:17:35 -0700670
Russell Kingfad58192020-07-19 12:00:35 +0100671 p = &chip->ports[port];
672
Russell King64d47d52020-03-14 10:15:38 +0000673 /* FIXME: is this the correct test? If we're in fixed mode on an
674 * internal port, why should we process this any different from
675 * PHY mode? On the other hand, the port may be automedia between
676 * an internal PHY and the serdes...
677 */
Marek Vasutd700ec42018-09-12 00:15:24 +0200678 if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
Russell Kingc9a23562018-05-10 13:17:35 -0700679 return;
680
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000681 mv88e6xxx_reg_lock(chip);
Russell Kingfad58192020-07-19 12:00:35 +0100682 /* In inband mode, the link may come up at any time while the link
683 * is not forced down. Force the link down while we reconfigure the
684 * interface mode.
Russell King64d47d52020-03-14 10:15:38 +0000685 */
Russell Kingfad58192020-07-19 12:00:35 +0100686 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
687 chip->info->ops->port_set_link)
688 chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
689
Russell King64d47d52020-03-14 10:15:38 +0000690 err = mv88e6xxx_port_config_interface(chip, port, state->interface);
Russell Kinga5a68582020-03-14 10:15:43 +0000691 if (err && err != -EOPNOTSUPP)
692 goto err_unlock;
693
694 err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
695 state->advertising);
696 /* FIXME: we should restart negotiation if something changed - which
697 * is something we get if we convert to using phylinks PCS operations.
698 */
699 if (err > 0)
700 err = 0;
701
Russell Kingfad58192020-07-19 12:00:35 +0100702 /* Undo the forced down state above after completing configuration
703 * irrespective of its state on entry, which allows the link to come up.
704 */
705 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
706 chip->info->ops->port_set_link)
707 chip->info->ops->port_set_link(chip, port, LINK_UNFORCED);
708
709 p->interface = state->interface;
710
Russell Kinga5a68582020-03-14 10:15:43 +0000711err_unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000712 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700713
714 if (err && err != -EOPNOTSUPP)
Russell King64d47d52020-03-14 10:15:38 +0000715 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700716}
717
Russell Kingc9a23562018-05-10 13:17:35 -0700718static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
719 unsigned int mode,
720 phy_interface_t interface)
721{
Russell King30c4a5b2020-02-26 10:23:51 +0000722 struct mv88e6xxx_chip *chip = ds->priv;
723 const struct mv88e6xxx_ops *ops;
724 int err = 0;
725
726 ops = chip->info->ops;
727
Russell King5d5b2312020-03-14 10:16:03 +0000728 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200729 if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
Chris Packham4efe76622020-11-24 17:34:37 +1300730 mode == MLO_AN_FIXED) && ops->port_sync_link)
731 err = ops->port_sync_link(chip, port, mode, false);
Russell King5d5b2312020-03-14 10:16:03 +0000732 mv88e6xxx_reg_unlock(chip);
Russell King30c4a5b2020-02-26 10:23:51 +0000733
Russell King5d5b2312020-03-14 10:16:03 +0000734 if (err)
735 dev_err(chip->dev,
736 "p%d: failed to force MAC link down\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700737}
738
739static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
740 unsigned int mode, phy_interface_t interface,
Russell King5b502a72020-02-26 10:23:46 +0000741 struct phy_device *phydev,
742 int speed, int duplex,
743 bool tx_pause, bool rx_pause)
Russell Kingc9a23562018-05-10 13:17:35 -0700744{
Russell King30c4a5b2020-02-26 10:23:51 +0000745 struct mv88e6xxx_chip *chip = ds->priv;
746 const struct mv88e6xxx_ops *ops;
747 int err = 0;
748
749 ops = chip->info->ops;
750
Russell King5d5b2312020-03-14 10:16:03 +0000751 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200752 if (!mv88e6xxx_port_ppu_updates(chip, port) || mode == MLO_AN_FIXED) {
Russell King30c4a5b2020-02-26 10:23:51 +0000753 /* FIXME: for an automedia port, should we force the link
754 * down here - what if the link comes up due to "other" media
755 * while we're bringing the port up, how is the exclusivity
Russell Kinga5a68582020-03-14 10:15:43 +0000756 * handled in the Marvell hardware? E.g. port 2 on 88E6390
Russell King30c4a5b2020-02-26 10:23:51 +0000757 * shared between internal PHY and Serdes.
758 */
Russell Kinga5a68582020-03-14 10:15:43 +0000759 err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
760 duplex);
761 if (err)
762 goto error;
763
Russell Kingf365c6f2020-03-14 10:15:53 +0000764 if (ops->port_set_speed_duplex) {
765 err = ops->port_set_speed_duplex(chip, port,
766 speed, duplex);
Russell King30c4a5b2020-02-26 10:23:51 +0000767 if (err && err != -EOPNOTSUPP)
768 goto error;
769 }
770
Chris Packham4efe76622020-11-24 17:34:37 +1300771 if (ops->port_sync_link)
772 err = ops->port_sync_link(chip, port, mode, true);
Russell King30c4a5b2020-02-26 10:23:51 +0000773 }
Russell King5d5b2312020-03-14 10:16:03 +0000774error:
775 mv88e6xxx_reg_unlock(chip);
776
777 if (err && err != -EOPNOTSUPP)
778 dev_err(ds->dev,
779 "p%d: failed to configure MAC link up\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700780}
781
Andrew Lunna605a0f2016-11-21 23:26:58 +0100782static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000783{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100784 if (!chip->info->ops->stats_snapshot)
785 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000786
Andrew Lunna605a0f2016-11-21 23:26:58 +0100787 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000788}
789
Andrew Lunne413e7e2015-04-02 04:06:38 +0200790static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100791 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
792 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
793 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
794 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
795 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
796 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
797 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
798 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
799 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
800 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
801 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
802 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
803 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
804 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
805 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
806 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
807 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
808 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
809 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
810 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
811 { "single", 4, 0x14, STATS_TYPE_BANK0, },
812 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
813 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
814 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
815 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
816 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
817 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
818 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
819 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
820 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
821 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
822 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
823 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
824 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
825 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
826 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
827 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
828 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
829 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
830 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
831 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
832 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
833 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
834 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
835 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
836 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
837 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
838 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
839 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
840 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
841 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
842 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
843 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
844 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
845 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
846 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
847 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
848 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
849 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200850};
851
Vivien Didelotfad09c72016-06-21 12:28:20 -0400852static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100853 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100854 int port, u16 bank1_select,
855 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200856{
Andrew Lunn80c46272015-06-20 18:42:30 +0200857 u32 low;
858 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100859 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200860 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200861 u64 value;
862
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100863 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100864 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200865 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
866 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800867 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200868
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200869 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100870 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200871 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
872 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800873 return U64_MAX;
Rasmus Villemoes84b3fd12019-05-29 07:02:11 +0000874 low |= ((u32)reg) << 16;
Andrew Lunn80c46272015-06-20 18:42:30 +0200875 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100876 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100877 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100878 reg = bank1_select;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500879 fallthrough;
Andrew Lunndfafe442016-11-21 23:27:02 +0100880 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100881 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100882 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100883 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100884 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500885 break;
886 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800887 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200888 }
Andrew Lunn6e46e2d2019-02-28 18:14:03 +0100889 value = (((u64)high) << 32) | low;
Andrew Lunn80c46272015-06-20 18:42:30 +0200890 return value;
891}
892
Andrew Lunn436fe172018-03-01 02:02:29 +0100893static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
894 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100895{
896 struct mv88e6xxx_hw_stat *stat;
897 int i, j;
898
899 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
900 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100901 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100902 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
903 ETH_GSTRING_LEN);
904 j++;
905 }
906 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100907
908 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100909}
910
Andrew Lunn436fe172018-03-01 02:02:29 +0100911static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
912 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100913{
Andrew Lunn436fe172018-03-01 02:02:29 +0100914 return mv88e6xxx_stats_get_strings(chip, data,
915 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100916}
917
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000918static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
919 uint8_t *data)
920{
921 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
922}
923
Andrew Lunn436fe172018-03-01 02:02:29 +0100924static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
925 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100926{
Andrew Lunn436fe172018-03-01 02:02:29 +0100927 return mv88e6xxx_stats_get_strings(chip, data,
928 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100929}
930
Andrew Lunn65f60e42018-03-28 23:50:28 +0200931static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
932 "atu_member_violation",
933 "atu_miss_violation",
934 "atu_full_violation",
935 "vtu_member_violation",
936 "vtu_miss_violation",
937};
938
939static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
940{
941 unsigned int i;
942
943 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
944 strlcpy(data + i * ETH_GSTRING_LEN,
945 mv88e6xxx_atu_vtu_stats_strings[i],
946 ETH_GSTRING_LEN);
947}
948
Andrew Lunndfafe442016-11-21 23:27:02 +0100949static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700950 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100951{
Vivien Didelot04bed142016-08-31 18:06:13 -0400952 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100953 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100954
Florian Fainelli89f09042018-04-25 12:12:50 -0700955 if (stringset != ETH_SS_STATS)
956 return;
957
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000958 mv88e6xxx_reg_lock(chip);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100959
Andrew Lunndfafe442016-11-21 23:27:02 +0100960 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100961 count = chip->info->ops->stats_get_strings(chip, data);
962
963 if (chip->info->ops->serdes_get_strings) {
964 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200965 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100966 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100967
Andrew Lunn65f60e42018-03-28 23:50:28 +0200968 data += count * ETH_GSTRING_LEN;
969 mv88e6xxx_atu_vtu_get_strings(data);
970
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000971 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100972}
973
974static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
975 int types)
976{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100977 struct mv88e6xxx_hw_stat *stat;
978 int i, j;
979
980 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
981 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100982 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100983 j++;
984 }
985 return j;
986}
987
Andrew Lunndfafe442016-11-21 23:27:02 +0100988static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
989{
990 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
991 STATS_TYPE_PORT);
992}
993
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000994static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
995{
996 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
997}
998
Andrew Lunndfafe442016-11-21 23:27:02 +0100999static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1000{
1001 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1002 STATS_TYPE_BANK1);
1003}
1004
Florian Fainelli89f09042018-04-25 12:12:50 -07001005static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +01001006{
1007 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +01001008 int serdes_count = 0;
1009 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +01001010
Florian Fainelli89f09042018-04-25 12:12:50 -07001011 if (sset != ETH_SS_STATS)
1012 return 0;
1013
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001014 mv88e6xxx_reg_lock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001015 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +01001016 count = chip->info->ops->stats_get_sset_count(chip);
1017 if (count < 0)
1018 goto out;
1019
1020 if (chip->info->ops->serdes_get_sset_count)
1021 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1022 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +02001023 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +01001024 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001025 goto out;
1026 }
1027 count += serdes_count;
1028 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1029
Andrew Lunn436fe172018-03-01 02:02:29 +01001030out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001031 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001032
Andrew Lunn436fe172018-03-01 02:02:29 +01001033 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +01001034}
1035
Andrew Lunn436fe172018-03-01 02:02:29 +01001036static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1037 uint64_t *data, int types,
1038 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +01001039{
1040 struct mv88e6xxx_hw_stat *stat;
1041 int i, j;
1042
1043 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1044 stat = &mv88e6xxx_hw_stats[i];
1045 if (stat->type & types) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001046 mv88e6xxx_reg_lock(chip);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001047 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1048 bank1_select,
1049 histogram);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001050 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001051
Andrew Lunn052f9472016-11-21 23:27:03 +01001052 j++;
1053 }
1054 }
Andrew Lunn436fe172018-03-01 02:02:29 +01001055 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +01001056}
1057
Andrew Lunn436fe172018-03-01 02:02:29 +01001058static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1059 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001060{
1061 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001062 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001063 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +01001064}
1065
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001066static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1067 uint64_t *data)
1068{
1069 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
1070 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1071}
1072
Andrew Lunn436fe172018-03-01 02:02:29 +01001073static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1074 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001075{
1076 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001077 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001078 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1079 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001080}
1081
Andrew Lunn436fe172018-03-01 02:02:29 +01001082static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1083 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +01001084{
1085 return mv88e6xxx_stats_get_stats(chip, port, data,
1086 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001087 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1088 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001089}
1090
Andrew Lunn65f60e42018-03-28 23:50:28 +02001091static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1092 uint64_t *data)
1093{
1094 *data++ = chip->ports[port].atu_member_violation;
1095 *data++ = chip->ports[port].atu_miss_violation;
1096 *data++ = chip->ports[port].atu_full_violation;
1097 *data++ = chip->ports[port].vtu_member_violation;
1098 *data++ = chip->ports[port].vtu_miss_violation;
1099}
1100
Andrew Lunn052f9472016-11-21 23:27:03 +01001101static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1102 uint64_t *data)
1103{
Andrew Lunn436fe172018-03-01 02:02:29 +01001104 int count = 0;
1105
Andrew Lunn052f9472016-11-21 23:27:03 +01001106 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +01001107 count = chip->info->ops->stats_get_stats(chip, port, data);
1108
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001109 mv88e6xxx_reg_lock(chip);
Andrew Lunn436fe172018-03-01 02:02:29 +01001110 if (chip->info->ops->serdes_get_stats) {
1111 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001112 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +01001113 }
Andrew Lunn65f60e42018-03-28 23:50:28 +02001114 data += count;
1115 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001116 mv88e6xxx_reg_unlock(chip);
Andrew Lunn052f9472016-11-21 23:27:03 +01001117}
1118
Vivien Didelotf81ec902016-05-09 13:22:58 -04001119static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1120 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001121{
Vivien Didelot04bed142016-08-31 18:06:13 -04001122 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001123 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001124
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001125 mv88e6xxx_reg_lock(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001126
Andrew Lunna605a0f2016-11-21 23:26:58 +01001127 ret = mv88e6xxx_stats_snapshot(chip, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001128 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001129
1130 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001131 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001132
1133 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001134
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001135}
Ben Hutchings98e67302011-11-25 14:36:19 +00001136
Vivien Didelotf81ec902016-05-09 13:22:58 -04001137static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001138{
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001139 struct mv88e6xxx_chip *chip = ds->priv;
1140 int len;
1141
1142 len = 32 * sizeof(u16);
1143 if (chip->info->ops->serdes_get_regs_len)
1144 len += chip->info->ops->serdes_get_regs_len(chip, port);
1145
1146 return len;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001147}
1148
Vivien Didelotf81ec902016-05-09 13:22:58 -04001149static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1150 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001151{
Vivien Didelot04bed142016-08-31 18:06:13 -04001152 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001153 int err;
1154 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001155 u16 *p = _p;
1156 int i;
1157
Vivien Didelota5f39322018-12-17 16:05:21 -05001158 regs->version = chip->info->prod_num;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001159
1160 memset(p, 0xff, 32 * sizeof(u16));
1161
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001162 mv88e6xxx_reg_lock(chip);
Vivien Didelot23062512016-05-09 13:22:45 -04001163
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001164 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001165
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001166 err = mv88e6xxx_port_read(chip, port, i, &reg);
1167 if (!err)
1168 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001169 }
Vivien Didelot23062512016-05-09 13:22:45 -04001170
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001171 if (chip->info->ops->serdes_get_regs)
1172 chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1173
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001174 mv88e6xxx_reg_unlock(chip);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001175}
1176
Vivien Didelot08f50062017-08-01 16:32:41 -04001177static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1178 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001179{
Vivien Didelot5480db62017-08-01 16:32:40 -04001180 /* Nothing to do on the port's MAC */
1181 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001182}
1183
Vivien Didelot08f50062017-08-01 16:32:41 -04001184static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1185 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001186{
Vivien Didelot5480db62017-08-01 16:32:40 -04001187 /* Nothing to do on the port's MAC */
1188 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001189}
1190
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001191/* Mask of the local ports allowed to receive frames from a given fabric port */
Vivien Didelote5887a22017-03-30 17:37:11 -04001192static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001193{
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001194 struct dsa_switch *ds = chip->ds;
1195 struct dsa_switch_tree *dst = ds->dst;
Vivien Didelote5887a22017-03-30 17:37:11 -04001196 struct net_device *br;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001197 struct dsa_port *dp;
1198 bool found = false;
Vivien Didelote5887a22017-03-30 17:37:11 -04001199 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001200
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001201 list_for_each_entry(dp, &dst->ports, list) {
1202 if (dp->ds->index == dev && dp->index == port) {
1203 found = true;
1204 break;
1205 }
1206 }
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001207
Vivien Didelote5887a22017-03-30 17:37:11 -04001208 /* Prevent frames from unknown switch or port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001209 if (!found)
Vivien Didelote5887a22017-03-30 17:37:11 -04001210 return 0;
1211
1212 /* Frames from DSA links and CPU ports can egress any local port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001213 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
Vivien Didelote5887a22017-03-30 17:37:11 -04001214 return mv88e6xxx_port_mask(chip);
1215
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001216 br = dp->bridge_dev;
Vivien Didelote5887a22017-03-30 17:37:11 -04001217 pvlan = 0;
1218
1219 /* Frames from user ports can egress any local DSA links and CPU ports,
1220 * as well as any local member of their bridge group.
1221 */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001222 list_for_each_entry(dp, &dst->ports, list)
1223 if (dp->ds == ds &&
1224 (dp->type == DSA_PORT_TYPE_CPU ||
1225 dp->type == DSA_PORT_TYPE_DSA ||
1226 (br && dp->bridge_dev == br)))
1227 pvlan |= BIT(dp->index);
Vivien Didelote5887a22017-03-30 17:37:11 -04001228
1229 return pvlan;
1230}
1231
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001232static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001233{
1234 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001235
1236 /* prevent frames from going back out of the port they came in on */
1237 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001238
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001239 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001240}
1241
Vivien Didelotf81ec902016-05-09 13:22:58 -04001242static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1243 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001244{
Vivien Didelot04bed142016-08-31 18:06:13 -04001245 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001246 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001247
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001248 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001249 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001250 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001251
1252 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001253 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001254}
1255
Vivien Didelot93e18d62018-05-11 17:16:35 -04001256static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1257{
1258 int err;
1259
1260 if (chip->info->ops->ieee_pri_map) {
1261 err = chip->info->ops->ieee_pri_map(chip);
1262 if (err)
1263 return err;
1264 }
1265
1266 if (chip->info->ops->ip_pri_map) {
1267 err = chip->info->ops->ip_pri_map(chip);
1268 if (err)
1269 return err;
1270 }
1271
1272 return 0;
1273}
1274
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001275static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1276{
Vivien Didelotc5f51762019-10-30 22:09:13 -04001277 struct dsa_switch *ds = chip->ds;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001278 int target, port;
1279 int err;
1280
1281 if (!chip->info->global2_addr)
1282 return 0;
1283
1284 /* Initialize the routing port to the 32 possible target devices */
1285 for (target = 0; target < 32; target++) {
Vivien Didelotc5f51762019-10-30 22:09:13 -04001286 port = dsa_routing_port(ds, target);
1287 if (port == ds->num_ports)
1288 port = 0x1f;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001289
1290 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1291 if (err)
1292 return err;
1293 }
1294
Vivien Didelot02317e62018-05-09 11:38:49 -04001295 if (chip->info->ops->set_cascade_port) {
1296 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1297 err = chip->info->ops->set_cascade_port(chip, port);
1298 if (err)
1299 return err;
1300 }
1301
Vivien Didelot23c98912018-05-09 11:38:50 -04001302 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1303 if (err)
1304 return err;
1305
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001306 return 0;
1307}
1308
Vivien Didelotb28f8722018-04-26 21:56:44 -04001309static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1310{
1311 /* Clear all trunk masks and mapping */
1312 if (chip->info->global2_addr)
1313 return mv88e6xxx_g2_trunk_clear(chip);
1314
1315 return 0;
1316}
1317
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001318static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1319{
1320 if (chip->info->ops->rmu_disable)
1321 return chip->info->ops->rmu_disable(chip);
1322
1323 return 0;
1324}
1325
Vivien Didelot9e907d72017-07-17 13:03:43 -04001326static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1327{
1328 if (chip->info->ops->pot_clear)
1329 return chip->info->ops->pot_clear(chip);
1330
1331 return 0;
1332}
1333
Vivien Didelot51c901a2017-07-17 13:03:41 -04001334static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1335{
1336 if (chip->info->ops->mgmt_rsvd2cpu)
1337 return chip->info->ops->mgmt_rsvd2cpu(chip);
1338
1339 return 0;
1340}
1341
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001342static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1343{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001344 int err;
1345
Vivien Didelotdaefc942017-03-11 16:12:54 -05001346 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1347 if (err)
1348 return err;
1349
Rasmus Villemoes49506a92020-12-10 12:06:44 +01001350 /* The chips that have a "learn2all" bit in Global1, ATU
1351 * Control are precisely those whose port registers have a
1352 * Message Port bit in Port Control 1 and hence implement
1353 * ->port_setup_message_port.
1354 */
1355 if (chip->info->ops->port_setup_message_port) {
1356 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1357 if (err)
1358 return err;
1359 }
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001360
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001361 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1362}
1363
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001364static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1365{
1366 int port;
1367 int err;
1368
1369 if (!chip->info->ops->irl_init_all)
1370 return 0;
1371
1372 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1373 /* Disable ingress rate limiting by resetting all per port
1374 * ingress rate limit resources to their initial state.
1375 */
1376 err = chip->info->ops->irl_init_all(chip, port);
1377 if (err)
1378 return err;
1379 }
1380
1381 return 0;
1382}
1383
Vivien Didelot04a69a12017-10-13 14:18:05 -04001384static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1385{
1386 if (chip->info->ops->set_switch_mac) {
1387 u8 addr[ETH_ALEN];
1388
1389 eth_random_addr(addr);
1390
1391 return chip->info->ops->set_switch_mac(chip, addr);
1392 }
1393
1394 return 0;
1395}
1396
Vivien Didelot17a15942017-03-30 17:37:09 -04001397static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1398{
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001399 struct dsa_switch_tree *dst = chip->ds->dst;
1400 struct dsa_switch *ds;
1401 struct dsa_port *dp;
Vivien Didelot17a15942017-03-30 17:37:09 -04001402 u16 pvlan = 0;
1403
1404 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001405 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001406
1407 /* Skip the local source device, which uses in-chip port VLAN */
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001408 if (dev != chip->ds->index) {
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001409 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001410
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001411 ds = dsa_switch_find(dst->index, dev);
1412 dp = ds ? dsa_to_port(ds, port) : NULL;
1413 if (dp && dp->lag_dev) {
1414 /* As the PVT is used to limit flooding of
1415 * FORWARD frames, which use the LAG ID as the
1416 * source port, we must translate dev/port to
1417 * the special "LAG device" in the PVT, using
1418 * the LAG ID as the port number.
1419 */
1420 dev = MV88E6XXX_G2_PVT_ADRR_DEV_TRUNK;
1421 port = dsa_lag_id(dst, dp->lag_dev);
1422 }
1423 }
1424
Vivien Didelot17a15942017-03-30 17:37:09 -04001425 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1426}
1427
Vivien Didelot81228992017-03-30 17:37:08 -04001428static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1429{
Vivien Didelot17a15942017-03-30 17:37:09 -04001430 int dev, port;
1431 int err;
1432
Vivien Didelot81228992017-03-30 17:37:08 -04001433 if (!mv88e6xxx_has_pvt(chip))
1434 return 0;
1435
1436 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1437 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1438 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001439 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1440 if (err)
1441 return err;
1442
1443 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1444 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1445 err = mv88e6xxx_pvt_map(chip, dev, port);
1446 if (err)
1447 return err;
1448 }
1449 }
1450
1451 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001452}
1453
Vivien Didelot749efcb2016-09-22 16:49:24 -04001454static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1455{
1456 struct mv88e6xxx_chip *chip = ds->priv;
1457 int err;
1458
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001459 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001460 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001461 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001462
1463 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001464 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001465}
1466
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001467static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1468{
Tobias Waldekranze545f862020-11-10 19:57:20 +01001469 if (!mv88e6xxx_max_vid(chip))
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001470 return 0;
1471
1472 return mv88e6xxx_g1_vtu_flush(chip);
1473}
1474
Vivien Didelotf1394b782017-05-01 14:05:22 -04001475static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1476 struct mv88e6xxx_vtu_entry *entry)
1477{
1478 if (!chip->info->ops->vtu_getnext)
1479 return -EOPNOTSUPP;
1480
1481 return chip->info->ops->vtu_getnext(chip, entry);
1482}
1483
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001484static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1485 struct mv88e6xxx_vtu_entry *entry)
1486{
1487 if (!chip->info->ops->vtu_loadpurge)
1488 return -EOPNOTSUPP;
1489
1490 return chip->info->ops->vtu_loadpurge(chip, entry);
1491}
1492
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001493int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001494{
Vivien Didelot425d2d32019-08-01 14:36:34 -04001495 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001496 int i, err;
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001497 u16 fid;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001498
1499 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1500
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001501 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001502 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001503 err = mv88e6xxx_port_get_fid(chip, i, &fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001504 if (err)
1505 return err;
1506
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001507 set_bit(fid, fid_bitmap);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001508 }
1509
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001510 /* Set every FID bit used by the VLAN entries */
Tobias Waldekranze545f862020-11-10 19:57:20 +01001511 vlan.vid = mv88e6xxx_max_vid(chip);
Vivien Didelot425d2d32019-08-01 14:36:34 -04001512 vlan.valid = false;
1513
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001514 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001515 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001516 if (err)
1517 return err;
1518
1519 if (!vlan.valid)
1520 break;
1521
1522 set_bit(vlan.fid, fid_bitmap);
Tobias Waldekranze545f862020-11-10 19:57:20 +01001523 } while (vlan.vid < mv88e6xxx_max_vid(chip));
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001524
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001525 return 0;
1526}
1527
1528static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1529{
1530 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1531 int err;
1532
1533 err = mv88e6xxx_fid_map(chip, fid_bitmap);
1534 if (err)
1535 return err;
1536
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001537 /* The reset value 0x000 is used to indicate that multiple address
1538 * databases are not needed. Return the next positive available.
1539 */
1540 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001541 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001542 return -ENOSPC;
1543
1544 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001545 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001546}
1547
Vivien Didelotda9c3592016-02-12 12:09:40 -05001548static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001549 u16 vid)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001550{
Vivien Didelot04bed142016-08-31 18:06:13 -04001551 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001552 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001553 int i, err;
1554
Vladimir Oltean3e85f582021-01-09 02:01:47 +02001555 if (!vid)
1556 return -EOPNOTSUPP;
1557
Andrew Lunndb06ae412017-09-25 23:32:20 +02001558 /* DSA and CPU ports have to be members of multiple vlans */
1559 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1560 return 0;
1561
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001562 vlan.vid = vid - 1;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001563 vlan.valid = false;
1564
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001565 err = mv88e6xxx_vtu_getnext(chip, &vlan);
1566 if (err)
1567 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001568
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001569 if (!vlan.valid)
1570 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001571
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001572 if (vlan.vid != vid)
1573 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001574
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001575 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1576 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1577 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001578
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001579 if (!dsa_to_port(ds, i)->slave)
1580 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001581
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001582 if (vlan.member[i] ==
1583 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1584 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001585
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001586 if (dsa_to_port(ds, i)->bridge_dev ==
1587 dsa_to_port(ds, port)->bridge_dev)
1588 break; /* same bridge, check next VLAN */
Vivien Didelotda9c3592016-02-12 12:09:40 -05001589
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001590 if (!dsa_to_port(ds, i)->bridge_dev)
1591 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001592
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001593 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1594 port, vlan.vid, i,
1595 netdev_name(dsa_to_port(ds, i)->bridge_dev));
1596 return -EOPNOTSUPP;
1597 }
Vivien Didelotda9c3592016-02-12 12:09:40 -05001598
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001599 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001600}
1601
Vivien Didelotf81ec902016-05-09 13:22:58 -04001602static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
Vladimir Olteanbae33f22021-01-09 02:01:50 +02001603 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001604{
Vivien Didelot04bed142016-08-31 18:06:13 -04001605 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001606 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1607 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001608 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001609
Vladimir Olteanbae33f22021-01-09 02:01:50 +02001610 if (!mv88e6xxx_max_vid(chip))
1611 return -EOPNOTSUPP;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001612
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001613 mv88e6xxx_reg_lock(chip);
Vivien Didelot385a0992016-11-04 03:23:31 +01001614 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001615 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001616
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001617 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001618}
1619
Vivien Didelot57d32312016-06-20 13:13:58 -04001620static int
1621mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001622 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001623{
Vivien Didelot04bed142016-08-31 18:06:13 -04001624 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001625 int err;
1626
Tobias Waldekranze545f862020-11-10 19:57:20 +01001627 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001628 return -EOPNOTSUPP;
1629
Vivien Didelotda9c3592016-02-12 12:09:40 -05001630 /* If the requested port doesn't belong to the same bridge as the VLAN
1631 * members, do not support it (yet) and fallback to software VLAN.
1632 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001633 mv88e6xxx_reg_lock(chip);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001634 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001635 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001636
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001637 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001638}
1639
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001640static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1641 const unsigned char *addr, u16 vid,
1642 u8 state)
1643{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001644 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001645 struct mv88e6xxx_vtu_entry vlan;
1646 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001647 int err;
1648
1649 /* Null VLAN ID corresponds to the port private database */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001650 if (vid == 0) {
1651 err = mv88e6xxx_port_get_fid(chip, port, &fid);
1652 if (err)
1653 return err;
1654 } else {
1655 vlan.vid = vid - 1;
1656 vlan.valid = false;
1657
1658 err = mv88e6xxx_vtu_getnext(chip, &vlan);
1659 if (err)
1660 return err;
1661
1662 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1663 if (vlan.vid != vid || !vlan.valid)
1664 return -EOPNOTSUPP;
1665
1666 fid = vlan.fid;
1667 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001668
Vivien Didelotd8291a92019-09-07 16:00:47 -04001669 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001670 ether_addr_copy(entry.mac, addr);
1671 eth_addr_dec(entry.mac);
1672
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001673 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001674 if (err)
1675 return err;
1676
1677 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001678 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001679 memset(&entry, 0, sizeof(entry));
1680 ether_addr_copy(entry.mac, addr);
1681 }
1682
1683 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001684 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001685 entry.portvec &= ~BIT(port);
1686 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001687 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001688 } else {
DENG Qingfangf72f2fb2021-01-30 21:43:34 +08001689 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
1690 entry.portvec = BIT(port);
1691 else
1692 entry.portvec |= BIT(port);
1693
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001694 entry.state = state;
1695 }
1696
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001697 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001698}
1699
Vivien Didelotda7dc872019-09-07 16:00:49 -04001700static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1701 const struct mv88e6xxx_policy *policy)
1702{
1703 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1704 enum mv88e6xxx_policy_action action = policy->action;
1705 const u8 *addr = policy->addr;
1706 u16 vid = policy->vid;
1707 u8 state;
1708 int err;
1709 int id;
1710
1711 if (!chip->info->ops->port_set_policy)
1712 return -EOPNOTSUPP;
1713
1714 switch (mapping) {
1715 case MV88E6XXX_POLICY_MAPPING_DA:
1716 case MV88E6XXX_POLICY_MAPPING_SA:
1717 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1718 state = 0; /* Dissociate the port and address */
1719 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1720 is_multicast_ether_addr(addr))
1721 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1722 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1723 is_unicast_ether_addr(addr))
1724 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1725 else
1726 return -EOPNOTSUPP;
1727
1728 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1729 state);
1730 if (err)
1731 return err;
1732 break;
1733 default:
1734 return -EOPNOTSUPP;
1735 }
1736
1737 /* Skip the port's policy clearing if the mapping is still in use */
1738 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1739 idr_for_each_entry(&chip->policies, policy, id)
1740 if (policy->port == port &&
1741 policy->mapping == mapping &&
1742 policy->action != action)
1743 return 0;
1744
1745 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1746}
1747
1748static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1749 struct ethtool_rx_flow_spec *fs)
1750{
1751 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1752 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1753 enum mv88e6xxx_policy_mapping mapping;
1754 enum mv88e6xxx_policy_action action;
1755 struct mv88e6xxx_policy *policy;
1756 u16 vid = 0;
1757 u8 *addr;
1758 int err;
1759 int id;
1760
1761 if (fs->location != RX_CLS_LOC_ANY)
1762 return -EINVAL;
1763
1764 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1765 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1766 else
1767 return -EOPNOTSUPP;
1768
1769 switch (fs->flow_type & ~FLOW_EXT) {
1770 case ETHER_FLOW:
1771 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1772 is_zero_ether_addr(mac_mask->h_source)) {
1773 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1774 addr = mac_entry->h_dest;
1775 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1776 !is_zero_ether_addr(mac_mask->h_source)) {
1777 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1778 addr = mac_entry->h_source;
1779 } else {
1780 /* Cannot support DA and SA mapping in the same rule */
1781 return -EOPNOTSUPP;
1782 }
1783 break;
1784 default:
1785 return -EOPNOTSUPP;
1786 }
1787
1788 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001789 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001790 return -EOPNOTSUPP;
1791 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1792 }
1793
1794 idr_for_each_entry(&chip->policies, policy, id) {
1795 if (policy->port == port && policy->mapping == mapping &&
1796 policy->action == action && policy->vid == vid &&
1797 ether_addr_equal(policy->addr, addr))
1798 return -EEXIST;
1799 }
1800
1801 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1802 if (!policy)
1803 return -ENOMEM;
1804
1805 fs->location = 0;
1806 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1807 GFP_KERNEL);
1808 if (err) {
1809 devm_kfree(chip->dev, policy);
1810 return err;
1811 }
1812
1813 memcpy(&policy->fs, fs, sizeof(*fs));
1814 ether_addr_copy(policy->addr, addr);
1815 policy->mapping = mapping;
1816 policy->action = action;
1817 policy->port = port;
1818 policy->vid = vid;
1819
1820 err = mv88e6xxx_policy_apply(chip, port, policy);
1821 if (err) {
1822 idr_remove(&chip->policies, fs->location);
1823 devm_kfree(chip->dev, policy);
1824 return err;
1825 }
1826
1827 return 0;
1828}
1829
1830static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1831 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1832{
1833 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1834 struct mv88e6xxx_chip *chip = ds->priv;
1835 struct mv88e6xxx_policy *policy;
1836 int err;
1837 int id;
1838
1839 mv88e6xxx_reg_lock(chip);
1840
1841 switch (rxnfc->cmd) {
1842 case ETHTOOL_GRXCLSRLCNT:
1843 rxnfc->data = 0;
1844 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1845 rxnfc->rule_cnt = 0;
1846 idr_for_each_entry(&chip->policies, policy, id)
1847 if (policy->port == port)
1848 rxnfc->rule_cnt++;
1849 err = 0;
1850 break;
1851 case ETHTOOL_GRXCLSRULE:
1852 err = -ENOENT;
1853 policy = idr_find(&chip->policies, fs->location);
1854 if (policy) {
1855 memcpy(fs, &policy->fs, sizeof(*fs));
1856 err = 0;
1857 }
1858 break;
1859 case ETHTOOL_GRXCLSRLALL:
1860 rxnfc->data = 0;
1861 rxnfc->rule_cnt = 0;
1862 idr_for_each_entry(&chip->policies, policy, id)
1863 if (policy->port == port)
1864 rule_locs[rxnfc->rule_cnt++] = id;
1865 err = 0;
1866 break;
1867 default:
1868 err = -EOPNOTSUPP;
1869 break;
1870 }
1871
1872 mv88e6xxx_reg_unlock(chip);
1873
1874 return err;
1875}
1876
1877static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1878 struct ethtool_rxnfc *rxnfc)
1879{
1880 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1881 struct mv88e6xxx_chip *chip = ds->priv;
1882 struct mv88e6xxx_policy *policy;
1883 int err;
1884
1885 mv88e6xxx_reg_lock(chip);
1886
1887 switch (rxnfc->cmd) {
1888 case ETHTOOL_SRXCLSRLINS:
1889 err = mv88e6xxx_policy_insert(chip, port, fs);
1890 break;
1891 case ETHTOOL_SRXCLSRLDEL:
1892 err = -ENOENT;
1893 policy = idr_remove(&chip->policies, fs->location);
1894 if (policy) {
1895 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
1896 err = mv88e6xxx_policy_apply(chip, port, policy);
1897 devm_kfree(chip->dev, policy);
1898 }
1899 break;
1900 default:
1901 err = -EOPNOTSUPP;
1902 break;
1903 }
1904
1905 mv88e6xxx_reg_unlock(chip);
1906
1907 return err;
1908}
1909
Andrew Lunn87fa8862017-11-09 22:29:56 +01001910static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1911 u16 vid)
1912{
1913 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1914 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1915
1916 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1917}
1918
1919static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1920{
1921 int port;
1922 int err;
1923
1924 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1925 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1926 if (err)
1927 return err;
1928 }
1929
1930 return 0;
1931}
1932
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001933static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00001934 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001935{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001936 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001937 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001938 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001939
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001940 vlan.vid = vid - 1;
1941 vlan.valid = false;
1942
1943 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001944 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001945 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001946
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001947 if (vlan.vid != vid || !vlan.valid) {
1948 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001949
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001950 err = mv88e6xxx_atu_new(chip, &vlan.fid);
1951 if (err)
1952 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01001953
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001954 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1955 if (i == port)
1956 vlan.member[i] = member;
1957 else
1958 vlan.member[i] = non_member;
1959
1960 vlan.vid = vid;
1961 vlan.valid = true;
1962
1963 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1964 if (err)
1965 return err;
1966
1967 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
1968 if (err)
1969 return err;
1970 } else if (vlan.member[port] != member) {
1971 vlan.member[port] = member;
1972
1973 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1974 if (err)
1975 return err;
Russell King933b4422020-02-26 17:14:26 +00001976 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001977 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
1978 port, vid);
1979 }
1980
1981 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001982}
1983
Vladimir Oltean1958d582021-01-09 02:01:53 +02001984static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vladimir Oltean31046a52021-02-13 22:43:18 +02001985 const struct switchdev_obj_port_vlan *vlan,
1986 struct netlink_ext_ack *extack)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001987{
Vivien Didelot04bed142016-08-31 18:06:13 -04001988 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001989 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1990 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Russell King933b4422020-02-26 17:14:26 +00001991 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001992 u8 member;
Vladimir Oltean1958d582021-01-09 02:01:53 +02001993 int err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001994
Vladimir Oltean1958d582021-01-09 02:01:53 +02001995 err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
1996 if (err)
1997 return err;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001998
Vivien Didelotc91498e2017-06-07 18:12:13 -04001999 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002000 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002001 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002002 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002003 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002004 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002005
Russell King933b4422020-02-26 17:14:26 +00002006 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
2007 * and then the CPU port. Do not warn for duplicates for the CPU port.
2008 */
2009 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
2010
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002011 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002012
Vladimir Oltean1958d582021-01-09 02:01:53 +02002013 err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
2014 if (err) {
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002015 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2016 vlan->vid, untagged ? 'u' : 't');
Vladimir Oltean1958d582021-01-09 02:01:53 +02002017 goto out;
2018 }
Vivien Didelot76e398a2015-11-01 12:33:55 -05002019
Vladimir Oltean1958d582021-01-09 02:01:53 +02002020 if (pvid) {
2021 err = mv88e6xxx_port_set_pvid(chip, port, vlan->vid);
2022 if (err) {
2023 dev_err(ds->dev, "p%d: failed to set PVID %d\n",
2024 port, vlan->vid);
2025 goto out;
2026 }
2027 }
2028out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002029 mv88e6xxx_reg_unlock(chip);
Vladimir Oltean1958d582021-01-09 02:01:53 +02002030
2031 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002032}
2033
Vivien Didelot521098922019-08-01 14:36:36 -04002034static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2035 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002036{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002037 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002038 int i, err;
2039
Vivien Didelot521098922019-08-01 14:36:36 -04002040 if (!vid)
2041 return -EOPNOTSUPP;
2042
2043 vlan.vid = vid - 1;
2044 vlan.valid = false;
2045
2046 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002047 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002048 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002049
Vivien Didelot521098922019-08-01 14:36:36 -04002050 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2051 * tell switchdev that this VLAN is likely handled in software.
2052 */
2053 if (vlan.vid != vid || !vlan.valid ||
2054 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002055 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002056
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002057 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002058
2059 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002060 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002061 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002062 if (vlan.member[i] !=
2063 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002064 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002065 break;
2066 }
2067 }
2068
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002069 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002070 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002071 return err;
2072
Vivien Didelote606ca32017-03-11 16:12:55 -05002073 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002074}
2075
Vivien Didelotf81ec902016-05-09 13:22:58 -04002076static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2077 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002078{
Vivien Didelot04bed142016-08-31 18:06:13 -04002079 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002080 int err = 0;
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002081 u16 pvid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002082
Tobias Waldekranze545f862020-11-10 19:57:20 +01002083 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04002084 return -EOPNOTSUPP;
2085
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002086 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002087
Vivien Didelot77064f32016-11-04 03:23:30 +01002088 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002089 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002090 goto unlock;
2091
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002092 err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
2093 if (err)
2094 goto unlock;
2095
2096 if (vlan->vid == pvid) {
2097 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002098 if (err)
2099 goto unlock;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002100 }
2101
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002102unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002103 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002104
2105 return err;
2106}
2107
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002108static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2109 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002110{
Vivien Didelot04bed142016-08-31 18:06:13 -04002111 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002112 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002113
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002114 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002115 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2116 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002117 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002118
2119 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002120}
2121
Vivien Didelotf81ec902016-05-09 13:22:58 -04002122static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002123 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002124{
Vivien Didelot04bed142016-08-31 18:06:13 -04002125 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002126 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002127
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002128 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002129 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002130 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002131
Vivien Didelot83dabd12016-08-31 11:50:04 -04002132 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002133}
2134
Vivien Didelot83dabd12016-08-31 11:50:04 -04002135static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2136 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002137 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002138{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002139 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002140 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002141 int err;
2142
Vivien Didelotd8291a92019-09-07 16:00:47 -04002143 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002144 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002145
2146 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002147 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002148 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002149 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002150
Vivien Didelotd8291a92019-09-07 16:00:47 -04002151 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002152 break;
2153
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002154 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002155 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002156
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002157 if (!is_unicast_ether_addr(addr.mac))
2158 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002159
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002160 is_static = (addr.state ==
2161 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2162 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002163 if (err)
2164 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002165 } while (!is_broadcast_ether_addr(addr.mac));
2166
2167 return err;
2168}
2169
Vivien Didelot83dabd12016-08-31 11:50:04 -04002170static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002171 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002172{
Vivien Didelot425d2d32019-08-01 14:36:34 -04002173 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002174 u16 fid;
2175 int err;
2176
2177 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002178 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002179 if (err)
2180 return err;
2181
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002182 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002183 if (err)
2184 return err;
2185
2186 /* Dump VLANs' Filtering Information Databases */
Tobias Waldekranze545f862020-11-10 19:57:20 +01002187 vlan.vid = mv88e6xxx_max_vid(chip);
Vivien Didelot425d2d32019-08-01 14:36:34 -04002188 vlan.valid = false;
2189
Vivien Didelot83dabd12016-08-31 11:50:04 -04002190 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04002191 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002192 if (err)
2193 return err;
2194
2195 if (!vlan.valid)
2196 break;
2197
2198 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002199 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002200 if (err)
2201 return err;
Tobias Waldekranze545f862020-11-10 19:57:20 +01002202 } while (vlan.vid < mv88e6xxx_max_vid(chip));
Vivien Didelot83dabd12016-08-31 11:50:04 -04002203
2204 return err;
2205}
2206
Vivien Didelotf81ec902016-05-09 13:22:58 -04002207static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002208 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002209{
Vivien Didelot04bed142016-08-31 18:06:13 -04002210 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002211 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002212
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002213 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002214 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002215 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002216
2217 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002218}
2219
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002220static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2221 struct net_device *br)
2222{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002223 struct dsa_switch *ds = chip->ds;
2224 struct dsa_switch_tree *dst = ds->dst;
2225 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002226 int err;
2227
Vivien Didelotef2025e2019-10-21 16:51:27 -04002228 list_for_each_entry(dp, &dst->ports, list) {
2229 if (dp->bridge_dev == br) {
2230 if (dp->ds == ds) {
2231 /* This is a local bridge group member,
2232 * remap its Port VLAN Map.
2233 */
2234 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2235 if (err)
2236 return err;
2237 } else {
2238 /* This is an external bridge group member,
2239 * remap its cross-chip Port VLAN Table entry.
2240 */
2241 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2242 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002243 if (err)
2244 return err;
2245 }
2246 }
2247 }
2248
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002249 return 0;
2250}
2251
Vivien Didelotf81ec902016-05-09 13:22:58 -04002252static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002253 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002254{
Vivien Didelot04bed142016-08-31 18:06:13 -04002255 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002256 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002257
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002258 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002259 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002260 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002261
Vivien Didelot466dfa02016-02-26 13:16:05 -05002262 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002263}
2264
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002265static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2266 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002267{
Vivien Didelot04bed142016-08-31 18:06:13 -04002268 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002269
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002270 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002271 if (mv88e6xxx_bridge_map(chip, br) ||
2272 mv88e6xxx_port_vlan_map(chip, port))
2273 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002274 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002275}
2276
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002277static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2278 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002279 int port, struct net_device *br)
2280{
2281 struct mv88e6xxx_chip *chip = ds->priv;
2282 int err;
2283
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002284 if (tree_index != ds->dst->index)
2285 return 0;
2286
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002287 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002288 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002289 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002290
2291 return err;
2292}
2293
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002294static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2295 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002296 int port, struct net_device *br)
2297{
2298 struct mv88e6xxx_chip *chip = ds->priv;
2299
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002300 if (tree_index != ds->dst->index)
2301 return;
2302
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002303 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002304 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002305 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002306 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002307}
2308
Vivien Didelot17e708b2016-12-05 17:30:27 -05002309static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2310{
2311 if (chip->info->ops->reset)
2312 return chip->info->ops->reset(chip);
2313
2314 return 0;
2315}
2316
Vivien Didelot309eca62016-12-05 17:30:26 -05002317static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2318{
2319 struct gpio_desc *gpiod = chip->reset;
2320
2321 /* If there is a GPIO connected to the reset pin, toggle it */
2322 if (gpiod) {
2323 gpiod_set_value_cansleep(gpiod, 1);
2324 usleep_range(10000, 20000);
2325 gpiod_set_value_cansleep(gpiod, 0);
2326 usleep_range(10000, 20000);
Andrew Lunna3dcb3e2020-11-16 08:43:01 -08002327
2328 mv88e6xxx_g1_wait_eeprom_done(chip);
Vivien Didelot309eca62016-12-05 17:30:26 -05002329 }
2330}
2331
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002332static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2333{
2334 int i, err;
2335
2336 /* Set all ports to the Disabled state */
2337 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002338 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002339 if (err)
2340 return err;
2341 }
2342
2343 /* Wait for transmit queues to drain,
2344 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2345 */
2346 usleep_range(2000, 4000);
2347
2348 return 0;
2349}
2350
Vivien Didelotfad09c72016-06-21 12:28:20 -04002351static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002352{
Vivien Didelota935c052016-09-29 12:21:53 -04002353 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002354
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002355 err = mv88e6xxx_disable_ports(chip);
2356 if (err)
2357 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002358
Vivien Didelot309eca62016-12-05 17:30:26 -05002359 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002360
Vivien Didelot17e708b2016-12-05 17:30:27 -05002361 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002362}
2363
Vivien Didelot43145572017-03-11 16:12:59 -05002364static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002365 enum mv88e6xxx_frame_mode frame,
2366 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002367{
2368 int err;
2369
Vivien Didelot43145572017-03-11 16:12:59 -05002370 if (!chip->info->ops->port_set_frame_mode)
2371 return -EOPNOTSUPP;
2372
2373 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002374 if (err)
2375 return err;
2376
Vivien Didelot43145572017-03-11 16:12:59 -05002377 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2378 if (err)
2379 return err;
2380
2381 if (chip->info->ops->port_set_ether_type)
2382 return chip->info->ops->port_set_ether_type(chip, port, etype);
2383
2384 return 0;
2385}
2386
2387static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2388{
2389 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002390 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002391 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002392}
2393
2394static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2395{
2396 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002397 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002398 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002399}
2400
2401static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2402{
2403 return mv88e6xxx_set_port_mode(chip, port,
2404 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002405 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2406 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002407}
2408
2409static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2410{
2411 if (dsa_is_dsa_port(chip->ds, port))
2412 return mv88e6xxx_set_port_mode_dsa(chip, port);
2413
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002414 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002415 return mv88e6xxx_set_port_mode_normal(chip, port);
2416
2417 /* Setup CPU port mode depending on its supported tag format */
2418 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2419 return mv88e6xxx_set_port_mode_dsa(chip, port);
2420
2421 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2422 return mv88e6xxx_set_port_mode_edsa(chip, port);
2423
2424 return -EINVAL;
2425}
2426
Vivien Didelotea698f42017-03-11 16:12:50 -05002427static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2428{
2429 bool message = dsa_is_dsa_port(chip->ds, port);
2430
2431 return mv88e6xxx_port_set_message_port(chip, port, message);
2432}
2433
Vivien Didelot601aeed2017-03-11 16:13:00 -05002434static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2435{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002436 struct dsa_switch *ds = chip->ds;
David S. Miller407308f2019-06-15 13:35:29 -07002437 bool flood;
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002438 int err;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002439
David S. Miller407308f2019-06-15 13:35:29 -07002440 /* Upstream ports flood frames with unknown unicast or multicast DA */
2441 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002442 if (chip->info->ops->port_set_ucast_flood) {
2443 err = chip->info->ops->port_set_ucast_flood(chip, port, flood);
2444 if (err)
2445 return err;
2446 }
2447 if (chip->info->ops->port_set_mcast_flood) {
2448 err = chip->info->ops->port_set_mcast_flood(chip, port, flood);
2449 if (err)
2450 return err;
2451 }
Vivien Didelot601aeed2017-03-11 16:13:00 -05002452
David S. Miller407308f2019-06-15 13:35:29 -07002453 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002454}
2455
Vivien Didelot45de77f2019-08-31 16:18:36 -04002456static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2457{
2458 struct mv88e6xxx_port *mvp = dev_id;
2459 struct mv88e6xxx_chip *chip = mvp->chip;
2460 irqreturn_t ret = IRQ_NONE;
2461 int port = mvp->port;
2462 u8 lane;
2463
2464 mv88e6xxx_reg_lock(chip);
2465 lane = mv88e6xxx_serdes_get_lane(chip, port);
2466 if (lane)
2467 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2468 mv88e6xxx_reg_unlock(chip);
2469
2470 return ret;
2471}
2472
2473static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
2474 u8 lane)
2475{
2476 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2477 unsigned int irq;
2478 int err;
2479
2480 /* Nothing to request if this SERDES port has no IRQ */
2481 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2482 if (!irq)
2483 return 0;
2484
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002485 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2486 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2487
Vivien Didelot45de77f2019-08-31 16:18:36 -04002488 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2489 mv88e6xxx_reg_unlock(chip);
2490 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002491 IRQF_ONESHOT, dev_id->serdes_irq_name,
2492 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002493 mv88e6xxx_reg_lock(chip);
2494 if (err)
2495 return err;
2496
2497 dev_id->serdes_irq = irq;
2498
2499 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2500}
2501
2502static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
2503 u8 lane)
2504{
2505 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2506 unsigned int irq = dev_id->serdes_irq;
2507 int err;
2508
2509 /* Nothing to free if no IRQ has been requested */
2510 if (!irq)
2511 return 0;
2512
2513 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2514
2515 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2516 mv88e6xxx_reg_unlock(chip);
2517 free_irq(irq, dev_id);
2518 mv88e6xxx_reg_lock(chip);
2519
2520 dev_id->serdes_irq = 0;
2521
2522 return err;
2523}
2524
Andrew Lunn6d917822017-05-26 01:03:21 +02002525static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2526 bool on)
2527{
Vivien Didelotdc272f62019-08-31 16:18:33 -04002528 u8 lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002529 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002530
Vivien Didelotdc272f62019-08-31 16:18:33 -04002531 lane = mv88e6xxx_serdes_get_lane(chip, port);
2532 if (!lane)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002533 return 0;
2534
2535 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002536 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002537 if (err)
2538 return err;
2539
Vivien Didelot45de77f2019-08-31 16:18:36 -04002540 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002541 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002542 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2543 if (err)
2544 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002545
Vivien Didelotdc272f62019-08-31 16:18:33 -04002546 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002547 }
2548
2549 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002550}
2551
Vivien Didelotfa371c82017-12-05 15:34:10 -05002552static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2553{
2554 struct dsa_switch *ds = chip->ds;
2555 int upstream_port;
2556 int err;
2557
Vivien Didelot07073c72017-12-05 15:34:13 -05002558 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002559 if (chip->info->ops->port_set_upstream_port) {
2560 err = chip->info->ops->port_set_upstream_port(chip, port,
2561 upstream_port);
2562 if (err)
2563 return err;
2564 }
2565
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002566 if (port == upstream_port) {
2567 if (chip->info->ops->set_cpu_port) {
2568 err = chip->info->ops->set_cpu_port(chip,
2569 upstream_port);
2570 if (err)
2571 return err;
2572 }
2573
2574 if (chip->info->ops->set_egress_port) {
2575 err = chip->info->ops->set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002576 MV88E6XXX_EGRESS_DIR_INGRESS,
2577 upstream_port);
2578 if (err)
2579 return err;
2580
2581 err = chip->info->ops->set_egress_port(chip,
2582 MV88E6XXX_EGRESS_DIR_EGRESS,
2583 upstream_port);
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002584 if (err)
2585 return err;
2586 }
2587 }
2588
Vivien Didelotfa371c82017-12-05 15:34:10 -05002589 return 0;
2590}
2591
Vivien Didelotfad09c72016-06-21 12:28:20 -04002592static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002593{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002594 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002595 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002596 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002597
Andrew Lunn7b898462018-08-09 15:38:47 +02002598 chip->ports[port].chip = chip;
2599 chip->ports[port].port = port;
2600
Vivien Didelotd78343d2016-11-04 03:23:36 +01002601 /* MAC Forcing register: don't force link, speed, duplex or flow control
2602 * state to any particular values on physical ports, but force the CPU
2603 * port and all DSA ports to their maximum bandwidth and full duplex.
2604 */
2605 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2606 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2607 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002608 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002609 PHY_INTERFACE_MODE_NA);
2610 else
2611 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2612 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002613 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002614 PHY_INTERFACE_MODE_NA);
2615 if (err)
2616 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002617
2618 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2619 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2620 * tunneling, determine priority by looking at 802.1p and IP
2621 * priority fields (IP prio has precedence), and set STP state
2622 * to Forwarding.
2623 *
2624 * If this is the CPU link, use DSA or EDSA tagging depending
2625 * on which tagging mode was configured.
2626 *
2627 * If this is a link to another switch, use DSA tagging mode.
2628 *
2629 * If this is the upstream port for this switch, enable
2630 * forwarding of unknown unicasts and multicasts.
2631 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002632 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2633 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2634 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2635 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002636 if (err)
2637 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002638
Vivien Didelot601aeed2017-03-11 16:13:00 -05002639 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002640 if (err)
2641 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002642
Vivien Didelot601aeed2017-03-11 16:13:00 -05002643 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002644 if (err)
2645 return err;
2646
Vivien Didelot8efdda42015-08-13 12:52:23 -04002647 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002648 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002649 * untagged frames on this port, do a destination address lookup on all
2650 * received packets as usual, disable ARP mirroring and don't send a
2651 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002652 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002653 err = mv88e6xxx_port_set_map_da(chip, port);
2654 if (err)
2655 return err;
2656
Vivien Didelotfa371c82017-12-05 15:34:10 -05002657 err = mv88e6xxx_setup_upstream_port(chip, port);
2658 if (err)
2659 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002660
Andrew Lunna23b2962017-02-04 20:15:28 +01002661 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002662 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002663 if (err)
2664 return err;
2665
Vivien Didelotcd782652017-06-08 18:34:13 -04002666 if (chip->info->ops->port_set_jumbo_size) {
2667 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002668 if (err)
2669 return err;
2670 }
2671
Andrew Lunn54d792f2015-05-06 01:09:47 +02002672 /* Port Association Vector: when learning source addresses
2673 * of packets, add the address to the address database using
2674 * a port bitmap that has only the bit for this port set and
2675 * the other bits clear.
2676 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002677 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002678 /* Disable learning for CPU port */
2679 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002680 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002681
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002682 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2683 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002684 if (err)
2685 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002686
2687 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002688 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2689 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002690 if (err)
2691 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002692
Vivien Didelot08984322017-06-08 18:34:12 -04002693 if (chip->info->ops->port_pause_limit) {
2694 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002695 if (err)
2696 return err;
2697 }
2698
Vivien Didelotc8c94892017-03-11 16:13:01 -05002699 if (chip->info->ops->port_disable_learn_limit) {
2700 err = chip->info->ops->port_disable_learn_limit(chip, port);
2701 if (err)
2702 return err;
2703 }
2704
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002705 if (chip->info->ops->port_disable_pri_override) {
2706 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002707 if (err)
2708 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002709 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002710
Andrew Lunnef0a7312016-12-03 04:35:16 +01002711 if (chip->info->ops->port_tag_remap) {
2712 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002713 if (err)
2714 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002715 }
2716
Andrew Lunnef70b112016-12-03 04:45:18 +01002717 if (chip->info->ops->port_egress_rate_limiting) {
2718 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002719 if (err)
2720 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002721 }
2722
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002723 if (chip->info->ops->port_setup_message_port) {
2724 err = chip->info->ops->port_setup_message_port(chip, port);
2725 if (err)
2726 return err;
2727 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002728
Vivien Didelot207afda2016-04-14 14:42:09 -04002729 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002730 * database, and allow bidirectional communication between the
2731 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002732 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002733 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002734 if (err)
2735 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002736
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002737 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002738 if (err)
2739 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002740
2741 /* Default VLAN ID and priority: don't set a default VLAN
2742 * ID, and set the default packet priority to zero.
2743 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002744 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002745}
2746
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002747static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
2748{
2749 struct mv88e6xxx_chip *chip = ds->priv;
2750
2751 if (chip->info->ops->port_set_jumbo_size)
2752 return 10240;
Chris Packham1baf0fa2020-07-24 11:21:22 +12002753 else if (chip->info->ops->set_max_frame_size)
2754 return 1632;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002755 return 1522;
2756}
2757
2758static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
2759{
2760 struct mv88e6xxx_chip *chip = ds->priv;
2761 int ret = 0;
2762
2763 mv88e6xxx_reg_lock(chip);
2764 if (chip->info->ops->port_set_jumbo_size)
2765 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12002766 else if (chip->info->ops->set_max_frame_size)
2767 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002768 else
2769 if (new_mtu > 1522)
2770 ret = -EINVAL;
2771 mv88e6xxx_reg_unlock(chip);
2772
2773 return ret;
2774}
2775
Andrew Lunn04aca992017-05-26 01:03:24 +02002776static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2777 struct phy_device *phydev)
2778{
2779 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002780 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002781
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002782 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002783 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002784 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002785
2786 return err;
2787}
2788
Andrew Lunn75104db2019-02-24 20:44:43 +01002789static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02002790{
2791 struct mv88e6xxx_chip *chip = ds->priv;
2792
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002793 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002794 if (mv88e6xxx_serdes_power(chip, port, false))
2795 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002796 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002797}
2798
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002799static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2800 unsigned int ageing_time)
2801{
Vivien Didelot04bed142016-08-31 18:06:13 -04002802 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002803 int err;
2804
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002805 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05002806 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002807 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002808
2809 return err;
2810}
2811
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002812static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002813{
2814 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002815
Andrew Lunnde2273872016-11-21 23:27:01 +01002816 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002817 if (chip->info->ops->stats_set_histogram) {
2818 err = chip->info->ops->stats_set_histogram(chip);
2819 if (err)
2820 return err;
2821 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002822
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002823 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002824}
2825
Andrew Lunnea890982019-01-09 00:24:03 +01002826/* Check if the errata has already been applied. */
2827static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
2828{
2829 int port;
2830 int err;
2831 u16 val;
2832
2833 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002834 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01002835 if (err) {
2836 dev_err(chip->dev,
2837 "Error reading hidden register: %d\n", err);
2838 return false;
2839 }
2840 if (val != 0x01c0)
2841 return false;
2842 }
2843
2844 return true;
2845}
2846
2847/* The 6390 copper ports have an errata which require poking magic
2848 * values into undocumented hidden registers and then performing a
2849 * software reset.
2850 */
2851static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
2852{
2853 int port;
2854 int err;
2855
2856 if (mv88e6390_setup_errata_applied(chip))
2857 return 0;
2858
2859 /* Set the ports into blocking mode */
2860 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2861 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
2862 if (err)
2863 return err;
2864 }
2865
2866 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002867 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01002868 if (err)
2869 return err;
2870 }
2871
2872 return mv88e6xxx_software_reset(chip);
2873}
2874
Andrew Lunn23e8b472019-10-25 01:03:52 +02002875static void mv88e6xxx_teardown(struct dsa_switch *ds)
2876{
2877 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002878 dsa_devlink_resources_unregister(ds);
Andrew Lunnbfb25542020-09-18 21:11:07 +02002879 mv88e6xxx_teardown_devlink_regions(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02002880}
2881
Vivien Didelotf81ec902016-05-09 13:22:58 -04002882static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002883{
Vivien Didelot04bed142016-08-31 18:06:13 -04002884 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002885 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04002886 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002887 int i;
2888
Vivien Didelotfad09c72016-06-21 12:28:20 -04002889 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002890 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002891
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002892 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002893
Andrew Lunnea890982019-01-09 00:24:03 +01002894 if (chip->info->ops->setup_errata) {
2895 err = chip->info->ops->setup_errata(chip);
2896 if (err)
2897 goto unlock;
2898 }
2899
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002900 /* Cache the cmode of each port. */
2901 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2902 if (chip->info->ops->port_get_cmode) {
2903 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
2904 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03002905 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002906
2907 chip->ports[i].cmode = cmode;
2908 }
2909 }
2910
Vivien Didelot97299342016-07-18 20:45:30 -04002911 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002912 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04002913 if (dsa_is_unused_port(ds, i))
2914 continue;
2915
Hubert Feursteinc8574862019-07-31 10:23:48 +02002916 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04002917 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02002918 dev_err(chip->dev, "port %d is invalid\n", i);
2919 err = -EINVAL;
2920 goto unlock;
2921 }
2922
Vivien Didelot97299342016-07-18 20:45:30 -04002923 err = mv88e6xxx_setup_port(chip, i);
2924 if (err)
2925 goto unlock;
2926 }
2927
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002928 err = mv88e6xxx_irl_setup(chip);
2929 if (err)
2930 goto unlock;
2931
Vivien Didelot04a69a12017-10-13 14:18:05 -04002932 err = mv88e6xxx_mac_setup(chip);
2933 if (err)
2934 goto unlock;
2935
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002936 err = mv88e6xxx_phy_setup(chip);
2937 if (err)
2938 goto unlock;
2939
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002940 err = mv88e6xxx_vtu_setup(chip);
2941 if (err)
2942 goto unlock;
2943
Vivien Didelot81228992017-03-30 17:37:08 -04002944 err = mv88e6xxx_pvt_setup(chip);
2945 if (err)
2946 goto unlock;
2947
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002948 err = mv88e6xxx_atu_setup(chip);
2949 if (err)
2950 goto unlock;
2951
Andrew Lunn87fa8862017-11-09 22:29:56 +01002952 err = mv88e6xxx_broadcast_setup(chip, 0);
2953 if (err)
2954 goto unlock;
2955
Vivien Didelot9e907d72017-07-17 13:03:43 -04002956 err = mv88e6xxx_pot_setup(chip);
2957 if (err)
2958 goto unlock;
2959
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002960 err = mv88e6xxx_rmu_setup(chip);
2961 if (err)
2962 goto unlock;
2963
Vivien Didelot51c901a2017-07-17 13:03:41 -04002964 err = mv88e6xxx_rsvd2cpu_setup(chip);
2965 if (err)
2966 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002967
Vivien Didelotb28f8722018-04-26 21:56:44 -04002968 err = mv88e6xxx_trunk_setup(chip);
2969 if (err)
2970 goto unlock;
2971
Vivien Didelotc7f047b2018-04-26 21:56:45 -04002972 err = mv88e6xxx_devmap_setup(chip);
2973 if (err)
2974 goto unlock;
2975
Vivien Didelot93e18d62018-05-11 17:16:35 -04002976 err = mv88e6xxx_pri_setup(chip);
2977 if (err)
2978 goto unlock;
2979
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002980 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002981 if (chip->info->ptp_support) {
2982 err = mv88e6xxx_ptp_setup(chip);
2983 if (err)
2984 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002985
2986 err = mv88e6xxx_hwtstamp_setup(chip);
2987 if (err)
2988 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002989 }
2990
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002991 err = mv88e6xxx_stats_setup(chip);
2992 if (err)
2993 goto unlock;
2994
Vivien Didelot6b17e862015-08-13 12:52:18 -04002995unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002996 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02002997
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002998 if (err)
2999 return err;
3000
3001 /* Have to be called without holding the register lock, since
3002 * they take the devlink lock, and we later take the locks in
3003 * the reverse order when getting/setting parameters or
3004 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02003005 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003006 err = mv88e6xxx_setup_devlink_resources(ds);
3007 if (err)
3008 return err;
3009
3010 err = mv88e6xxx_setup_devlink_params(ds);
3011 if (err)
Andrew Lunnbfb25542020-09-18 21:11:07 +02003012 goto out_resources;
3013
3014 err = mv88e6xxx_setup_devlink_regions(ds);
3015 if (err)
3016 goto out_params;
3017
3018 return 0;
3019
3020out_params:
3021 mv88e6xxx_teardown_devlink_params(ds);
3022out_resources:
3023 dsa_devlink_resources_unregister(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003024
3025 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003026}
3027
Vivien Didelote57e5e72016-08-15 17:19:00 -04003028static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003029{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003030 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3031 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003032 u16 val;
3033 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003034
Andrew Lunnee26a222017-01-24 14:53:48 +01003035 if (!chip->info->ops->phy_read)
3036 return -EOPNOTSUPP;
3037
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003038 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003039 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003040 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003041
Andrew Lunnda9f3302017-02-01 03:40:05 +01003042 if (reg == MII_PHYSID2) {
Andrew Lunnddc49ac2018-11-12 18:51:01 +01003043 /* Some internal PHYs don't have a model number. */
3044 if (chip->info->family != MV88E6XXX_FAMILY_6165)
3045 /* Then there is the 6165 family. It gets is
3046 * PHYs correct. But it can also have two
3047 * SERDES interfaces in the PHY address
3048 * space. And these don't have a model
3049 * number. But they are not PHYs, so we don't
3050 * want to give them something a PHY driver
3051 * will recognise.
3052 *
3053 * Use the mv88e6390 family model number
3054 * instead, for anything which really could be
3055 * a PHY,
3056 */
3057 if (!(val & 0x3f0))
3058 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003059 }
3060
Vivien Didelote57e5e72016-08-15 17:19:00 -04003061 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003062}
3063
Vivien Didelote57e5e72016-08-15 17:19:00 -04003064static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003065{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003066 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3067 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003068 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003069
Andrew Lunnee26a222017-01-24 14:53:48 +01003070 if (!chip->info->ops->phy_write)
3071 return -EOPNOTSUPP;
3072
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003073 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003074 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003075 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003076
3077 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003078}
3079
Vivien Didelotfad09c72016-06-21 12:28:20 -04003080static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003081 struct device_node *np,
3082 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003083{
3084 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003085 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003086 struct mii_bus *bus;
3087 int err;
3088
Andrew Lunn2510bab2018-02-22 01:51:49 +01003089 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003090 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003091 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003092 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003093
3094 if (err)
3095 return err;
3096 }
3097
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003098 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003099 if (!bus)
3100 return -ENOMEM;
3101
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003102 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003103 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003104 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003105 INIT_LIST_HEAD(&mdio_bus->list);
3106 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003107
Andrew Lunnb516d452016-06-04 21:17:06 +02003108 if (np) {
3109 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003110 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003111 } else {
3112 bus->name = "mv88e6xxx SMI";
3113 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3114 }
3115
3116 bus->read = mv88e6xxx_mdio_read;
3117 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003118 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003119
Andrew Lunn6f882842018-03-17 20:32:05 +01003120 if (!external) {
3121 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3122 if (err)
3123 return err;
3124 }
3125
Florian Fainelli00e798c2018-05-15 16:56:19 -07003126 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003127 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003128 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003129 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003130 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003131 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003132
3133 if (external)
3134 list_add_tail(&mdio_bus->list, &chip->mdios);
3135 else
3136 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003137
3138 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003139}
3140
Andrew Lunn3126aee2017-12-07 01:05:57 +01003141static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3142
3143{
3144 struct mv88e6xxx_mdio_bus *mdio_bus;
3145 struct mii_bus *bus;
3146
3147 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3148 bus = mdio_bus->bus;
3149
Andrew Lunn6f882842018-03-17 20:32:05 +01003150 if (!mdio_bus->external)
3151 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3152
Andrew Lunn3126aee2017-12-07 01:05:57 +01003153 mdiobus_unregister(bus);
3154 }
3155}
3156
Andrew Lunna3c53be52017-01-24 14:53:50 +01003157static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3158 struct device_node *np)
3159{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003160 struct device_node *child;
3161 int err;
3162
3163 /* Always register one mdio bus for the internal/default mdio
3164 * bus. This maybe represented in the device tree, but is
3165 * optional.
3166 */
3167 child = of_get_child_by_name(np, "mdio");
3168 err = mv88e6xxx_mdio_register(chip, child, false);
3169 if (err)
3170 return err;
3171
3172 /* Walk the device tree, and see if there are any other nodes
3173 * which say they are compatible with the external mdio
3174 * bus.
3175 */
3176 for_each_available_child_of_node(np, child) {
Andrew Lunnceb96fa2020-09-01 04:32:57 +02003177 if (of_device_is_compatible(
3178 child, "marvell,mv88e6xxx-mdio-external")) {
Andrew Lunna3c53be52017-01-24 14:53:50 +01003179 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003180 if (err) {
3181 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303182 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003183 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003184 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003185 }
3186 }
3187
3188 return 0;
3189}
3190
Vivien Didelot855b1932016-07-20 18:18:35 -04003191static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3192{
Vivien Didelot04bed142016-08-31 18:06:13 -04003193 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003194
3195 return chip->eeprom_len;
3196}
3197
Vivien Didelot855b1932016-07-20 18:18:35 -04003198static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3199 struct ethtool_eeprom *eeprom, u8 *data)
3200{
Vivien Didelot04bed142016-08-31 18:06:13 -04003201 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003202 int err;
3203
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003204 if (!chip->info->ops->get_eeprom)
3205 return -EOPNOTSUPP;
3206
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003207 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003208 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003209 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003210
3211 if (err)
3212 return err;
3213
3214 eeprom->magic = 0xc3ec4951;
3215
3216 return 0;
3217}
3218
Vivien Didelot855b1932016-07-20 18:18:35 -04003219static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3220 struct ethtool_eeprom *eeprom, u8 *data)
3221{
Vivien Didelot04bed142016-08-31 18:06:13 -04003222 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003223 int err;
3224
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003225 if (!chip->info->ops->set_eeprom)
3226 return -EOPNOTSUPP;
3227
Vivien Didelot855b1932016-07-20 18:18:35 -04003228 if (eeprom->magic != 0xc3ec4951)
3229 return -EINVAL;
3230
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003231 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003232 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003233 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003234
3235 return err;
3236}
3237
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003238static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003239 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003240 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3241 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003242 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003243 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003244 .phy_read = mv88e6185_phy_ppu_read,
3245 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003246 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003247 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003248 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003249 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003250 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003251 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3252 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003253 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003254 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003255 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003256 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003257 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003258 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003259 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003260 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003261 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003262 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3263 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003264 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003265 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3266 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003267 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003268 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003269 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003270 .ppu_enable = mv88e6185_g1_ppu_enable,
3271 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003272 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003273 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003274 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003275 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003276 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003277 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003278};
3279
3280static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003281 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003282 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3283 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003284 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003285 .phy_read = mv88e6185_phy_ppu_read,
3286 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003287 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003288 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003289 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003290 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003291 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3292 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunna23b2962017-02-04 20:15:28 +01003293 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003294 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003295 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003296 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003297 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003298 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3299 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003300 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003301 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003302 .serdes_power = mv88e6185_serdes_power,
3303 .serdes_get_lane = mv88e6185_serdes_get_lane,
3304 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003305 .ppu_enable = mv88e6185_g1_ppu_enable,
3306 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003307 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003308 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003309 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003310 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003311 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003312};
3313
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003314static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003315 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003316 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3317 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003318 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003319 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3320 .phy_read = mv88e6xxx_g2_smi_phy_read,
3321 .phy_write = mv88e6xxx_g2_smi_phy_write,
3322 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003323 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003324 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003325 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003326 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003327 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3328 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003329 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003330 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003331 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003332 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003333 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003334 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003335 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003336 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003337 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003338 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3339 .stats_get_strings = mv88e6095_stats_get_strings,
3340 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003341 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3342 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003343 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003344 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003345 .serdes_power = mv88e6185_serdes_power,
3346 .serdes_get_lane = mv88e6185_serdes_get_lane,
3347 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Chris Packham5c19bc82020-11-24 17:34:39 +13003348 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3349 .serdes_irq_enable = mv88e6097_serdes_irq_enable,
3350 .serdes_irq_status = mv88e6097_serdes_irq_status,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003351 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003352 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003353 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003354 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003355 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003356 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003357 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003358};
3359
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003360static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003361 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003362 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3363 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003364 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003365 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003366 .phy_read = mv88e6xxx_g2_smi_phy_read,
3367 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003368 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003369 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003370 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003371 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003372 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3373 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003374 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003375 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003376 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003377 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003378 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003379 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003380 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3381 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003382 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003383 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3384 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003385 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003386 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003387 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003388 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003389 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3390 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003391 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003392 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003393 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003394 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003395};
3396
3397static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003398 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003399 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3400 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003401 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003402 .phy_read = mv88e6185_phy_ppu_read,
3403 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003404 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003405 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003406 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003407 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003408 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003409 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3410 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003411 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003412 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003413 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003414 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003415 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003416 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003417 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003418 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003419 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003420 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003421 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3422 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003423 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003424 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3425 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003426 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003427 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003428 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003429 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003430 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003431 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003432 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003433 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003434 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003435};
3436
Vivien Didelot990e27b2017-03-28 13:50:32 -04003437static const struct mv88e6xxx_ops mv88e6141_ops = {
3438 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003439 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3440 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003441 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003442 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3443 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3444 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3445 .phy_read = mv88e6xxx_g2_smi_phy_read,
3446 .phy_write = mv88e6xxx_g2_smi_phy_write,
3447 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003448 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003449 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003450 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003451 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003452 .port_tag_remap = mv88e6095_port_tag_remap,
3453 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003454 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3455 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003456 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003457 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003458 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003459 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003460 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3461 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003462 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003463 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003464 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003465 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003466 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003467 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3468 .stats_get_strings = mv88e6320_stats_get_strings,
3469 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003470 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3471 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003472 .watchdog_ops = &mv88e6390_watchdog_ops,
3473 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003474 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003475 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003476 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003477 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003478 .serdes_power = mv88e6390_serdes_power,
3479 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003480 /* Check status register pause & lpa register */
3481 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3482 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3483 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3484 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003485 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003486 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003487 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003488 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003489 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003490};
3491
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003492static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003493 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003494 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3495 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003496 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003497 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003498 .phy_read = mv88e6xxx_g2_smi_phy_read,
3499 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003500 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003501 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003502 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003503 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003504 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003505 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3506 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003507 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003508 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003509 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003510 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003511 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003512 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003513 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003514 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003515 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003516 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003517 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3518 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003519 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003520 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3521 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003522 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003523 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003524 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003525 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003526 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3527 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003528 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003529 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003530 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003531 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003532 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003533};
3534
3535static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003536 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003537 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3538 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003539 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003540 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003541 .phy_read = mv88e6165_phy_read,
3542 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003543 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003544 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003545 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
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,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003550 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003551 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003552 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3553 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003554 .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,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003557 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003558 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003559 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003560 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003561 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3562 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003563 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003564 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003565 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003566 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003567 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003568};
3569
3570static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003571 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003572 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3573 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003574 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003575 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003576 .phy_read = mv88e6xxx_g2_smi_phy_read,
3577 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003578 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003579 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003580 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003581 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003582 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003583 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003584 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3585 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003586 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003587 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003588 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003589 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003590 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003591 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003592 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003593 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003594 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003595 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003596 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3597 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003598 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003599 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3600 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003601 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003602 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003603 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003604 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003605 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3606 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003607 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003608 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003609 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003610};
3611
3612static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003613 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003614 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3615 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003616 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003617 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3618 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003619 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003620 .phy_read = mv88e6xxx_g2_smi_phy_read,
3621 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003622 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003623 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003624 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003625 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003626 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003627 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003628 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003629 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3630 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003631 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003632 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003633 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003634 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003635 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003636 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003637 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003638 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003639 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003640 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003641 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3642 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003643 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003644 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3645 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003646 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003647 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003648 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003649 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003650 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003651 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3652 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003653 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003654 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003655 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003656 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3657 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3658 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3659 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003660 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003661 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3662 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003663 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003664 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003665};
3666
3667static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003668 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003669 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3670 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003671 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003672 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003673 .phy_read = mv88e6xxx_g2_smi_phy_read,
3674 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003675 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003676 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003677 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003678 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003679 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003680 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003681 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3682 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003683 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003684 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003685 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003686 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003687 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003688 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003689 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003690 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003691 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003692 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003693 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3694 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003695 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003696 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3697 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003698 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003699 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003700 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003701 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003702 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3703 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003704 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003705 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003706 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003707};
3708
3709static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003710 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003711 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3712 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003713 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003714 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3715 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003716 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003717 .phy_read = mv88e6xxx_g2_smi_phy_read,
3718 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003719 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003720 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003721 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003722 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003723 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003724 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003725 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003726 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3727 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003728 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003729 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003730 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003731 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003732 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003733 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003734 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003735 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003736 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003737 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003738 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3739 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003740 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003741 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3742 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003743 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003744 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003745 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003746 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003747 .rmu_disable = mv88e6352_g1_rmu_disable,
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,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003752 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003753 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3754 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3755 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3756 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003757 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003758 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003759 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003760 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003761 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3762 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003763 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003764 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003765};
3766
3767static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003768 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003769 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3770 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003771 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003772 .phy_read = mv88e6185_phy_ppu_read,
3773 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003774 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003775 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003776 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003777 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003778 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3779 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunnef70b112016-12-03 04:45:18 +01003780 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003781 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02003782 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003783 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003784 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003785 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003786 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003787 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3788 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003789 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003790 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3791 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003792 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003793 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003794 .serdes_power = mv88e6185_serdes_power,
3795 .serdes_get_lane = mv88e6185_serdes_get_lane,
3796 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelot02317e62018-05-09 11:38:49 -04003797 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003798 .ppu_enable = mv88e6185_g1_ppu_enable,
3799 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003800 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003801 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003802 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003803 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003804 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003805};
3806
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003807static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003808 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003809 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003810 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003811 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3812 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003813 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3814 .phy_read = mv88e6xxx_g2_smi_phy_read,
3815 .phy_write = mv88e6xxx_g2_smi_phy_write,
3816 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003817 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003818 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003819 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003820 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003821 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003822 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003823 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003824 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3825 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003826 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003827 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003828 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003829 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003830 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003831 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003832 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003833 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003834 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003835 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003836 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3837 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003838 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003839 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3840 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003841 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003842 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003843 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003844 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003845 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003846 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3847 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003848 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3849 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003850 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003851 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003852 /* Check status register pause & lpa register */
3853 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3854 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3855 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3856 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003857 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003858 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003859 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003860 .serdes_get_strings = mv88e6390_serdes_get_strings,
3861 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003862 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3863 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003864 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003865 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003866};
3867
3868static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003869 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003870 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003871 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003872 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3873 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003874 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3875 .phy_read = mv88e6xxx_g2_smi_phy_read,
3876 .phy_write = mv88e6xxx_g2_smi_phy_write,
3877 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003878 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003879 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003880 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003881 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003882 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003883 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003884 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003885 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3886 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003887 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003888 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003889 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003890 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003891 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003892 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003893 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003894 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003895 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003896 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003897 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3898 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003899 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003900 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3901 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003902 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003903 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003904 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003905 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003906 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003907 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3908 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003909 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3910 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003911 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003912 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003913 /* Check status register pause & lpa register */
3914 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3915 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3916 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3917 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003918 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003919 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003920 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003921 .serdes_get_strings = mv88e6390_serdes_get_strings,
3922 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003923 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3924 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003925 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003926 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003927};
3928
3929static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003930 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003931 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003932 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003933 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3934 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003935 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3936 .phy_read = mv88e6xxx_g2_smi_phy_read,
3937 .phy_write = mv88e6xxx_g2_smi_phy_write,
3938 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003939 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003940 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003941 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003942 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003943 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003944 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003945 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3946 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003947 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003948 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003949 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003950 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003951 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003952 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003953 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003954 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003955 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003956 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3957 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003958 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003959 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3960 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003961 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003962 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003963 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003964 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003965 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003966 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3967 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003968 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3969 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003970 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003971 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003972 /* Check status register pause & lpa register */
3973 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3974 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3975 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3976 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003977 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003978 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003979 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003980 .serdes_get_strings = mv88e6390_serdes_get_strings,
3981 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003982 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3983 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003984 .avb_ops = &mv88e6390_avb_ops,
3985 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003986 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003987};
3988
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003989static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003990 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003991 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3992 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003993 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003994 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3995 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003996 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003997 .phy_read = mv88e6xxx_g2_smi_phy_read,
3998 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003999 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004000 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004001 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004002 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004003 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004004 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004005 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004006 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4007 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004008 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004009 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004010 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004011 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004012 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004013 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004014 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004015 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004016 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004017 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004018 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4019 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004020 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004021 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4022 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004023 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004024 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004025 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004026 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004027 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004028 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4029 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004030 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004031 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004032 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004033 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4034 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4035 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4036 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004037 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004038 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004039 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004040 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004041 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4042 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004043 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004044 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004045 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004046 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004047};
4048
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004049static const struct mv88e6xxx_ops mv88e6250_ops = {
4050 /* MV88E6XXX_FAMILY_6250 */
4051 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4052 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4053 .irl_init_all = mv88e6352_g2_irl_init_all,
4054 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4055 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4056 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4057 .phy_read = mv88e6xxx_g2_smi_phy_read,
4058 .phy_write = mv88e6xxx_g2_smi_phy_write,
4059 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004060 .port_sync_link = mv88e6xxx_port_sync_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004061 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004062 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004063 .port_tag_remap = mv88e6095_port_tag_remap,
4064 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004065 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4066 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004067 .port_set_ether_type = mv88e6351_port_set_ether_type,
4068 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4069 .port_pause_limit = mv88e6097_port_pause_limit,
4070 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004071 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4072 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4073 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4074 .stats_get_strings = mv88e6250_stats_get_strings,
4075 .stats_get_stats = mv88e6250_stats_get_stats,
4076 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4077 .set_egress_port = mv88e6095_g1_set_egress_port,
4078 .watchdog_ops = &mv88e6250_watchdog_ops,
4079 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4080 .pot_clear = mv88e6xxx_g2_pot_clear,
4081 .reset = mv88e6250_g1_reset,
Rasmus Villemoes67c9ed12021-01-25 16:04:48 +01004082 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Rasmus Villemoesb28f3f32021-01-25 16:04:49 +01004083 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004084 .avb_ops = &mv88e6352_avb_ops,
4085 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004086 .phylink_validate = mv88e6065_phylink_validate,
4087};
4088
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004089static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004090 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004091 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004092 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004093 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4094 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004095 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4096 .phy_read = mv88e6xxx_g2_smi_phy_read,
4097 .phy_write = mv88e6xxx_g2_smi_phy_write,
4098 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004099 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004100 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004101 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004102 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004103 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004104 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004105 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004106 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4107 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004108 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004109 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004110 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004111 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004112 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004113 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004114 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004115 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004116 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004117 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4118 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004119 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004120 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4121 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004122 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004123 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004124 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004125 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004126 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004127 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4128 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004129 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4130 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004131 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004132 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004133 /* Check status register pause & lpa register */
4134 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4135 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4136 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4137 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004138 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004139 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004140 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004141 .serdes_get_strings = mv88e6390_serdes_get_strings,
4142 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004143 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4144 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004145 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004146 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004147 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004148 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004149};
4150
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004151static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004152 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004153 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4154 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004155 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004156 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4157 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004158 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004159 .phy_read = mv88e6xxx_g2_smi_phy_read,
4160 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004161 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004162 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004163 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004164 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004165 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004166 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4167 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004168 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004169 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004170 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004171 .port_pause_limit = mv88e6097_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,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004175 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004176 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004177 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004178 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4179 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004180 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004181 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4182 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004183 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004184 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004185 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004186 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004187 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004188 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004189 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004190 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004191 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004192 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004193};
4194
4195static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004196 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004197 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4198 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004199 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004200 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4201 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004202 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004203 .phy_read = mv88e6xxx_g2_smi_phy_read,
4204 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004205 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004206 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004207 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004208 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004209 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004210 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4211 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004212 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004213 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004214 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004215 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004216 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004217 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004218 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004219 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004220 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004221 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004222 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4223 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004224 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004225 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4226 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004227 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004228 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004229 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004230 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004231 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004232 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004233 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004234 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004235};
4236
Vivien Didelot16e329a2017-03-28 13:50:33 -04004237static const struct mv88e6xxx_ops mv88e6341_ops = {
4238 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004239 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4240 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004241 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004242 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4243 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4244 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4245 .phy_read = mv88e6xxx_g2_smi_phy_read,
4246 .phy_write = mv88e6xxx_g2_smi_phy_write,
4247 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004248 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004249 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004250 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004251 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004252 .port_tag_remap = mv88e6095_port_tag_remap,
4253 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004254 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4255 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004256 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004257 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004258 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004259 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004260 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4261 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004262 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004263 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004264 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004265 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004266 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004267 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4268 .stats_get_strings = mv88e6320_stats_get_strings,
4269 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004270 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4271 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004272 .watchdog_ops = &mv88e6390_watchdog_ops,
4273 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004274 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004275 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004276 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004277 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004278 .serdes_power = mv88e6390_serdes_power,
4279 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004280 /* Check status register pause & lpa register */
4281 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4282 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4283 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4284 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004285 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004286 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004287 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004288 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004289 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004290 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01004291 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004292};
4293
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004294static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004295 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004296 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4297 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004298 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004299 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004300 .phy_read = mv88e6xxx_g2_smi_phy_read,
4301 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004302 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004303 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004304 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004305 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004306 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004307 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004308 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4309 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004310 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004311 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004312 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004313 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004314 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004315 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004316 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004317 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004318 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004319 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004320 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4321 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004322 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004323 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4324 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004325 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004326 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004327 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004328 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004329 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4330 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004331 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004332 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004333 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004334};
4335
4336static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004337 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004338 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4339 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004340 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004341 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004342 .phy_read = mv88e6xxx_g2_smi_phy_read,
4343 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004344 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004345 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004346 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004347 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004348 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004349 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004350 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4351 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004352 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004353 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004354 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004355 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004356 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004357 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004358 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004359 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004360 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004361 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004362 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4363 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004364 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004365 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4366 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004367 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004368 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004369 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004370 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004371 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4372 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004373 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004374 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004375 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004376 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004377 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004378};
4379
4380static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004381 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004382 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4383 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004384 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004385 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4386 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004387 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004388 .phy_read = mv88e6xxx_g2_smi_phy_read,
4389 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004390 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004391 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004392 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004393 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004394 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004395 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004396 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004397 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4398 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004399 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004400 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004401 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004402 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004403 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004404 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004405 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004406 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004407 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004408 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004409 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4410 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004411 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004412 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4413 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004414 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004415 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004416 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004417 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004418 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004419 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4420 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004421 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004422 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004423 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004424 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4425 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4426 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4427 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004428 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004429 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004430 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004431 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004432 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004433 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004434 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004435 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4436 .serdes_get_strings = mv88e6352_serdes_get_strings,
4437 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004438 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4439 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004440 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004441};
4442
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004443static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004444 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004445 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004446 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004447 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4448 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004449 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4450 .phy_read = mv88e6xxx_g2_smi_phy_read,
4451 .phy_write = mv88e6xxx_g2_smi_phy_write,
4452 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004453 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004454 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004455 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004456 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004457 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004458 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004459 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004460 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4461 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004462 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004463 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004464 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004465 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004466 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004467 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004468 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004469 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004470 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004471 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004472 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004473 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4474 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004475 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004476 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4477 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004478 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004479 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004480 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004481 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004482 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004483 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4484 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004485 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4486 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004487 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004488 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004489 /* Check status register pause & lpa register */
4490 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4491 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4492 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4493 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004494 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004495 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004496 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004497 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004498 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004499 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004500 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4501 .serdes_get_strings = mv88e6390_serdes_get_strings,
4502 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004503 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4504 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004505 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004506};
4507
4508static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004509 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004510 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004511 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004512 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4513 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004514 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4515 .phy_read = mv88e6xxx_g2_smi_phy_read,
4516 .phy_write = mv88e6xxx_g2_smi_phy_write,
4517 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004518 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004519 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004520 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004521 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004522 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004523 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004524 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004525 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4526 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004527 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004528 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004529 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004530 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004531 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004532 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004533 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004534 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004535 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004536 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004537 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004538 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4539 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004540 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004541 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4542 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004543 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004544 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004545 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004546 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004547 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004548 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4549 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004550 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4551 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004552 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004553 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004554 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4555 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4556 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4557 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004558 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004559 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004560 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004561 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4562 .serdes_get_strings = mv88e6390_serdes_get_strings,
4563 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004564 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4565 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004566 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004567 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004568 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004569 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004570};
4571
Vivien Didelotf81ec902016-05-09 13:22:58 -04004572static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4573 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004574 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004575 .family = MV88E6XXX_FAMILY_6097,
4576 .name = "Marvell 88E6085",
4577 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004578 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004579 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004580 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004581 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004582 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004583 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004584 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004585 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004586 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004587 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004588 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004589 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004590 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004591 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004592 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004593 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004594 },
4595
4596 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004597 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004598 .family = MV88E6XXX_FAMILY_6095,
4599 .name = "Marvell 88E6095/88E6095F",
4600 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004601 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004602 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004603 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004604 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004605 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004606 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004607 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004608 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004609 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004610 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004611 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004612 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004613 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004614 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004615 },
4616
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004617 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004618 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004619 .family = MV88E6XXX_FAMILY_6097,
4620 .name = "Marvell 88E6097/88E6097F",
4621 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004622 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004623 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004624 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004625 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004626 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004627 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004628 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004629 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004630 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004631 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004632 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004633 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004634 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004635 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01004636 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004637 .ops = &mv88e6097_ops,
4638 },
4639
Vivien Didelotf81ec902016-05-09 13:22:58 -04004640 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004641 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004642 .family = MV88E6XXX_FAMILY_6165,
4643 .name = "Marvell 88E6123",
4644 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004645 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004646 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004647 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004648 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004649 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004650 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004651 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004652 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004653 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004654 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004655 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004656 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004657 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004658 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004659 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004660 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004661 },
4662
4663 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004664 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004665 .family = MV88E6XXX_FAMILY_6185,
4666 .name = "Marvell 88E6131",
4667 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004668 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004669 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004670 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004671 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004672 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004673 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004674 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004675 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004676 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004677 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004678 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004679 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004680 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004681 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004682 },
4683
Vivien Didelot990e27b2017-03-28 13:50:32 -04004684 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004685 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004686 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01004687 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04004688 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004689 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004690 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004691 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004692 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004693 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004694 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004695 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004696 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004697 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004698 .age_time_coeff = 3750,
4699 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004700 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004701 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004702 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004703 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004704 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004705 .ops = &mv88e6141_ops,
4706 },
4707
Vivien Didelotf81ec902016-05-09 13:22:58 -04004708 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004709 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004710 .family = MV88E6XXX_FAMILY_6165,
4711 .name = "Marvell 88E6161",
4712 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004713 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004714 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004715 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004716 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004717 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004718 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004719 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004720 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004721 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004722 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004723 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004724 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004725 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004726 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004727 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004728 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004729 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004730 },
4731
4732 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004733 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004734 .family = MV88E6XXX_FAMILY_6165,
4735 .name = "Marvell 88E6165",
4736 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004737 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004738 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004739 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004740 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004741 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004742 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004743 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004744 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004745 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004746 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004747 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004748 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004749 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004750 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004751 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004752 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004753 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004754 },
4755
4756 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004757 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004758 .family = MV88E6XXX_FAMILY_6351,
4759 .name = "Marvell 88E6171",
4760 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004761 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004762 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004763 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004764 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004765 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004766 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004767 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004768 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004769 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004770 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004771 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004772 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004773 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004774 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004775 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004776 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004777 },
4778
4779 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004780 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004781 .family = MV88E6XXX_FAMILY_6352,
4782 .name = "Marvell 88E6172",
4783 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004784 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004785 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004786 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004787 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004788 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004789 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004790 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004791 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004792 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004793 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004794 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004795 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004796 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004797 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004798 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004799 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004800 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004801 },
4802
4803 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004804 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004805 .family = MV88E6XXX_FAMILY_6351,
4806 .name = "Marvell 88E6175",
4807 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004808 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004809 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004810 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004811 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004812 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004813 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004814 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004815 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004816 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004817 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004818 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004819 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004820 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004821 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004822 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004823 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004824 },
4825
4826 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004827 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004828 .family = MV88E6XXX_FAMILY_6352,
4829 .name = "Marvell 88E6176",
4830 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004831 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004832 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004833 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004834 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004835 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004836 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004837 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004838 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004839 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004840 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004841 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004842 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004843 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004844 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004845 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004846 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004847 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004848 },
4849
4850 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004851 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004852 .family = MV88E6XXX_FAMILY_6185,
4853 .name = "Marvell 88E6185",
4854 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004855 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004856 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004857 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004858 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004859 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004860 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004861 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004862 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004863 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004864 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004865 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004866 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004867 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004868 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004869 },
4870
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004871 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004872 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004873 .family = MV88E6XXX_FAMILY_6390,
4874 .name = "Marvell 88E6190",
4875 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004876 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004877 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004878 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004879 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004880 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004881 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004882 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004883 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004884 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004885 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004886 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004887 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004888 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04004889 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004890 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05004891 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004892 .ops = &mv88e6190_ops,
4893 },
4894
4895 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004896 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004897 .family = MV88E6XXX_FAMILY_6390,
4898 .name = "Marvell 88E6190X",
4899 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004900 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004901 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004902 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004903 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004904 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004905 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004906 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004907 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004908 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004909 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004910 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004911 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004912 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004913 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004914 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004915 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004916 .ops = &mv88e6190x_ops,
4917 },
4918
4919 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004920 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004921 .family = MV88E6XXX_FAMILY_6390,
4922 .name = "Marvell 88E6191",
4923 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004924 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004925 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004926 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04004927 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004928 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004929 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004930 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004931 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004932 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004933 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004934 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004935 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004936 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004937 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004938 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004939 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04004940 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004941 },
4942
Hubert Feurstein49022642019-07-31 10:23:46 +02004943 [MV88E6220] = {
4944 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
4945 .family = MV88E6XXX_FAMILY_6250,
4946 .name = "Marvell 88E6220",
4947 .num_databases = 64,
4948
4949 /* Ports 2-4 are not routed to pins
4950 * => usable ports 0, 1, 5, 6
4951 */
4952 .num_ports = 7,
4953 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02004954 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02004955 .max_vid = 4095,
4956 .port_base_addr = 0x08,
4957 .phy_base_addr = 0x00,
4958 .global1_addr = 0x0f,
4959 .global2_addr = 0x07,
4960 .age_time_coeff = 15000,
4961 .g1_irqs = 9,
4962 .g2_irqs = 10,
4963 .atu_move_port_mask = 0xf,
4964 .dual_chip = true,
4965 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02004966 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02004967 .ops = &mv88e6250_ops,
4968 },
4969
Vivien Didelotf81ec902016-05-09 13:22:58 -04004970 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004971 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004972 .family = MV88E6XXX_FAMILY_6352,
4973 .name = "Marvell 88E6240",
4974 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004975 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004976 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004977 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004978 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004979 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004980 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004981 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004982 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004983 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004984 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004985 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004986 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004987 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004988 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004989 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004990 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004991 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004992 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004993 },
4994
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004995 [MV88E6250] = {
4996 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
4997 .family = MV88E6XXX_FAMILY_6250,
4998 .name = "Marvell 88E6250",
4999 .num_databases = 64,
5000 .num_ports = 7,
5001 .num_internal_phys = 5,
5002 .max_vid = 4095,
5003 .port_base_addr = 0x08,
5004 .phy_base_addr = 0x00,
5005 .global1_addr = 0x0f,
5006 .global2_addr = 0x07,
5007 .age_time_coeff = 15000,
5008 .g1_irqs = 9,
5009 .g2_irqs = 10,
5010 .atu_move_port_mask = 0xf,
5011 .dual_chip = true,
5012 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02005013 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005014 .ops = &mv88e6250_ops,
5015 },
5016
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005017 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005018 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005019 .family = MV88E6XXX_FAMILY_6390,
5020 .name = "Marvell 88E6290",
5021 .num_databases = 4096,
5022 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005023 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005024 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005025 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005026 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005027 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005028 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005029 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005030 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005031 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005032 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005033 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005034 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005035 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005036 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005037 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005038 .ops = &mv88e6290_ops,
5039 },
5040
Vivien Didelotf81ec902016-05-09 13:22:58 -04005041 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005042 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005043 .family = MV88E6XXX_FAMILY_6320,
5044 .name = "Marvell 88E6320",
5045 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005046 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005047 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005048 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005049 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005050 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005051 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005052 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005053 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005054 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005055 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005056 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005057 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005058 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005059 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005060 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005061 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005062 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005063 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005064 },
5065
5066 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005067 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005068 .family = MV88E6XXX_FAMILY_6320,
5069 .name = "Marvell 88E6321",
5070 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005071 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005072 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005073 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005074 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005075 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005076 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005077 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005078 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005079 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005080 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005081 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005082 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005083 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005084 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005085 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005086 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005087 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005088 },
5089
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005090 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005091 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005092 .family = MV88E6XXX_FAMILY_6341,
5093 .name = "Marvell 88E6341",
5094 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005095 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005096 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005097 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005098 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005099 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005100 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005101 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005102 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005103 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005104 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005105 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005106 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005107 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005108 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005109 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005110 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005111 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005112 .ops = &mv88e6341_ops,
5113 },
5114
Vivien Didelotf81ec902016-05-09 13:22:58 -04005115 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005116 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005117 .family = MV88E6XXX_FAMILY_6351,
5118 .name = "Marvell 88E6350",
5119 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005120 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005121 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005122 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005123 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005124 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005125 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005126 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005127 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005128 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005129 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005130 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005131 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005132 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005133 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005134 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005135 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005136 },
5137
5138 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005139 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005140 .family = MV88E6XXX_FAMILY_6351,
5141 .name = "Marvell 88E6351",
5142 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005143 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005144 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005145 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005146 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005147 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005148 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005149 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005150 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005151 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005152 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005153 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005154 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005155 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005156 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005157 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005158 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005159 },
5160
5161 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005162 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005163 .family = MV88E6XXX_FAMILY_6352,
5164 .name = "Marvell 88E6352",
5165 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005166 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005167 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005168 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005169 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005170 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005171 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005172 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005173 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005174 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005175 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005176 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005177 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005178 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005179 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005180 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005181 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005182 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005183 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005184 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005185 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005186 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005187 .family = MV88E6XXX_FAMILY_6390,
5188 .name = "Marvell 88E6390",
5189 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005190 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005191 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005192 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005193 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005194 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005195 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005196 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005197 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005198 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005199 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005200 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005201 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005202 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005203 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005204 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005205 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005206 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005207 .ops = &mv88e6390_ops,
5208 },
5209 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005210 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005211 .family = MV88E6XXX_FAMILY_6390,
5212 .name = "Marvell 88E6390X",
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,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005217 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005218 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005219 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005220 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005221 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005222 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005223 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005224 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005225 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005226 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005227 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005228 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005229 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005230 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005231 .ops = &mv88e6390x_ops,
5232 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005233};
5234
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005235static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005236{
Vivien Didelota439c062016-04-17 13:23:58 -04005237 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005238
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005239 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5240 if (mv88e6xxx_table[i].prod_num == prod_num)
5241 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005242
Vivien Didelotb9b37712015-10-30 19:39:48 -04005243 return NULL;
5244}
5245
Vivien Didelotfad09c72016-06-21 12:28:20 -04005246static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005247{
5248 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005249 unsigned int prod_num, rev;
5250 u16 id;
5251 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005252
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005253 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005254 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005255 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005256 if (err)
5257 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005258
Vivien Didelot107fcc12017-06-12 12:37:36 -04005259 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5260 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005261
5262 info = mv88e6xxx_lookup_info(prod_num);
5263 if (!info)
5264 return -ENODEV;
5265
Vivien Didelotcaac8542016-06-20 13:14:09 -04005266 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005267 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005268
Vivien Didelotfad09c72016-06-21 12:28:20 -04005269 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5270 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005271
5272 return 0;
5273}
5274
Vivien Didelotfad09c72016-06-21 12:28:20 -04005275static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005276{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005277 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005278
Vivien Didelotfad09c72016-06-21 12:28:20 -04005279 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5280 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005281 return NULL;
5282
Vivien Didelotfad09c72016-06-21 12:28:20 -04005283 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005284
Vivien Didelotfad09c72016-06-21 12:28:20 -04005285 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005286 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005287 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005288
Vivien Didelotfad09c72016-06-21 12:28:20 -04005289 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005290}
5291
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005292static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005293 int port,
5294 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005295{
Vivien Didelot04bed142016-08-31 18:06:13 -04005296 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005297
Andrew Lunn443d5a12016-12-03 04:35:18 +01005298 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005299}
5300
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005301static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
5302 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005303{
Vivien Didelot04bed142016-08-31 18:06:13 -04005304 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005305 int err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005306
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005307 mv88e6xxx_reg_lock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005308 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5309 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005310 mv88e6xxx_reg_unlock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005311
5312 return err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005313}
5314
5315static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5316 const struct switchdev_obj_port_mdb *mdb)
5317{
Vivien Didelot04bed142016-08-31 18:06:13 -04005318 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005319 int err;
5320
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005321 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005322 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005323 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005324
5325 return err;
5326}
5327
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005328static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5329 struct dsa_mall_mirror_tc_entry *mirror,
5330 bool ingress)
5331{
5332 enum mv88e6xxx_egress_direction direction = ingress ?
5333 MV88E6XXX_EGRESS_DIR_INGRESS :
5334 MV88E6XXX_EGRESS_DIR_EGRESS;
5335 struct mv88e6xxx_chip *chip = ds->priv;
5336 bool other_mirrors = false;
5337 int i;
5338 int err;
5339
5340 if (!chip->info->ops->set_egress_port)
5341 return -EOPNOTSUPP;
5342
5343 mutex_lock(&chip->reg_lock);
5344 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5345 mirror->to_local_port) {
5346 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5347 other_mirrors |= ingress ?
5348 chip->ports[i].mirror_ingress :
5349 chip->ports[i].mirror_egress;
5350
5351 /* Can't change egress port when other mirror is active */
5352 if (other_mirrors) {
5353 err = -EBUSY;
5354 goto out;
5355 }
5356
5357 err = chip->info->ops->set_egress_port(chip,
5358 direction,
5359 mirror->to_local_port);
5360 if (err)
5361 goto out;
5362 }
5363
5364 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5365out:
5366 mutex_unlock(&chip->reg_lock);
5367
5368 return err;
5369}
5370
5371static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5372 struct dsa_mall_mirror_tc_entry *mirror)
5373{
5374 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5375 MV88E6XXX_EGRESS_DIR_INGRESS :
5376 MV88E6XXX_EGRESS_DIR_EGRESS;
5377 struct mv88e6xxx_chip *chip = ds->priv;
5378 bool other_mirrors = false;
5379 int i;
5380
5381 mutex_lock(&chip->reg_lock);
5382 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5383 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5384
5385 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5386 other_mirrors |= mirror->ingress ?
5387 chip->ports[i].mirror_ingress :
5388 chip->ports[i].mirror_egress;
5389
5390 /* Reset egress port when no other mirror is active */
5391 if (!other_mirrors) {
5392 if (chip->info->ops->set_egress_port(chip,
5393 direction,
5394 dsa_upstream_port(ds,
Colin Ian King4e4637b2019-11-12 13:05:23 +00005395 port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005396 dev_err(ds->dev, "failed to set egress port\n");
5397 }
5398
5399 mutex_unlock(&chip->reg_lock);
5400}
5401
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005402static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port,
5403 struct switchdev_brport_flags flags,
5404 struct netlink_ext_ack *extack)
5405{
5406 struct mv88e6xxx_chip *chip = ds->priv;
5407 const struct mv88e6xxx_ops *ops;
5408
5409 if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD))
5410 return -EINVAL;
5411
5412 ops = chip->info->ops;
5413
5414 if ((flags.mask & BR_FLOOD) && !ops->port_set_ucast_flood)
5415 return -EINVAL;
5416
5417 if ((flags.mask & BR_MCAST_FLOOD) && !ops->port_set_mcast_flood)
5418 return -EINVAL;
5419
5420 return 0;
5421}
5422
5423static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
5424 struct switchdev_brport_flags flags,
5425 struct netlink_ext_ack *extack)
Russell King4f859012019-02-20 15:35:05 -08005426{
5427 struct mv88e6xxx_chip *chip = ds->priv;
5428 int err = -EOPNOTSUPP;
5429
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005430 mv88e6xxx_reg_lock(chip);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005431
5432 if (flags.mask & BR_FLOOD) {
5433 bool unicast = !!(flags.val & BR_FLOOD);
5434
5435 err = chip->info->ops->port_set_ucast_flood(chip, port,
5436 unicast);
5437 if (err)
5438 goto out;
5439 }
5440
5441 if (flags.mask & BR_MCAST_FLOOD) {
5442 bool multicast = !!(flags.val & BR_MCAST_FLOOD);
5443
5444 err = chip->info->ops->port_set_mcast_flood(chip, port,
5445 multicast);
5446 if (err)
5447 goto out;
5448 }
5449
5450out:
5451 mv88e6xxx_reg_unlock(chip);
5452
5453 return err;
5454}
5455
5456static int mv88e6xxx_port_set_mrouter(struct dsa_switch *ds, int port,
5457 bool mrouter,
5458 struct netlink_ext_ack *extack)
5459{
5460 struct mv88e6xxx_chip *chip = ds->priv;
5461 int err;
5462
5463 if (!chip->info->ops->port_set_mcast_flood)
5464 return -EOPNOTSUPP;
5465
5466 mv88e6xxx_reg_lock(chip);
5467 err = chip->info->ops->port_set_mcast_flood(chip, port, mrouter);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005468 mv88e6xxx_reg_unlock(chip);
Russell King4f859012019-02-20 15:35:05 -08005469
5470 return err;
5471}
5472
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005473static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
5474 struct net_device *lag,
5475 struct netdev_lag_upper_info *info)
5476{
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005477 struct mv88e6xxx_chip *chip = ds->priv;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005478 struct dsa_port *dp;
5479 int id, members = 0;
5480
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005481 if (!mv88e6xxx_has_lag(chip))
5482 return false;
5483
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005484 id = dsa_lag_id(ds->dst, lag);
5485 if (id < 0 || id >= ds->num_lag_ids)
5486 return false;
5487
5488 dsa_lag_foreach_port(dp, ds->dst, lag)
5489 /* Includes the port joining the LAG */
5490 members++;
5491
5492 if (members > 8)
5493 return false;
5494
5495 /* We could potentially relax this to include active
5496 * backup in the future.
5497 */
5498 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
5499 return false;
5500
5501 /* Ideally we would also validate that the hash type matches
5502 * the hardware. Alas, this is always set to unknown on team
5503 * interfaces.
5504 */
5505 return true;
5506}
5507
5508static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct net_device *lag)
5509{
5510 struct mv88e6xxx_chip *chip = ds->priv;
5511 struct dsa_port *dp;
5512 u16 map = 0;
5513 int id;
5514
5515 id = dsa_lag_id(ds->dst, lag);
5516
5517 /* Build the map of all ports to distribute flows destined for
5518 * this LAG. This can be either a local user port, or a DSA
5519 * port if the LAG port is on a remote chip.
5520 */
5521 dsa_lag_foreach_port(dp, ds->dst, lag)
5522 map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));
5523
5524 return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
5525}
5526
5527static const u8 mv88e6xxx_lag_mask_table[8][8] = {
5528 /* Row number corresponds to the number of active members in a
5529 * LAG. Each column states which of the eight hash buckets are
5530 * mapped to the column:th port in the LAG.
5531 *
5532 * Example: In a LAG with three active ports, the second port
5533 * ([2][1]) would be selected for traffic mapped to buckets
5534 * 3,4,5 (0x38).
5535 */
5536 { 0xff, 0, 0, 0, 0, 0, 0, 0 },
5537 { 0x0f, 0xf0, 0, 0, 0, 0, 0, 0 },
5538 { 0x07, 0x38, 0xc0, 0, 0, 0, 0, 0 },
5539 { 0x03, 0x0c, 0x30, 0xc0, 0, 0, 0, 0 },
5540 { 0x03, 0x0c, 0x30, 0x40, 0x80, 0, 0, 0 },
5541 { 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80, 0, 0 },
5542 { 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0 },
5543 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
5544};
5545
5546static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
5547 int num_tx, int nth)
5548{
5549 u8 active = 0;
5550 int i;
5551
5552 num_tx = num_tx <= 8 ? num_tx : 8;
5553 if (nth < num_tx)
5554 active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];
5555
5556 for (i = 0; i < 8; i++) {
5557 if (BIT(i) & active)
5558 mask[i] |= BIT(port);
5559 }
5560}
5561
5562static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
5563{
5564 struct mv88e6xxx_chip *chip = ds->priv;
5565 unsigned int id, num_tx;
5566 struct net_device *lag;
5567 struct dsa_port *dp;
5568 int i, err, nth;
5569 u16 mask[8];
5570 u16 ivec;
5571
5572 /* Assume no port is a member of any LAG. */
5573 ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;
5574
5575 /* Disable all masks for ports that _are_ members of a LAG. */
5576 list_for_each_entry(dp, &ds->dst->ports, list) {
5577 if (!dp->lag_dev || dp->ds != ds)
5578 continue;
5579
5580 ivec &= ~BIT(dp->index);
5581 }
5582
5583 for (i = 0; i < 8; i++)
5584 mask[i] = ivec;
5585
5586 /* Enable the correct subset of masks for all LAG ports that
5587 * are in the Tx set.
5588 */
5589 dsa_lags_foreach_id(id, ds->dst) {
5590 lag = dsa_lag_dev(ds->dst, id);
5591 if (!lag)
5592 continue;
5593
5594 num_tx = 0;
5595 dsa_lag_foreach_port(dp, ds->dst, lag) {
5596 if (dp->lag_tx_enabled)
5597 num_tx++;
5598 }
5599
5600 if (!num_tx)
5601 continue;
5602
5603 nth = 0;
5604 dsa_lag_foreach_port(dp, ds->dst, lag) {
5605 if (!dp->lag_tx_enabled)
5606 continue;
5607
5608 if (dp->ds == ds)
5609 mv88e6xxx_lag_set_port_mask(mask, dp->index,
5610 num_tx, nth);
5611
5612 nth++;
5613 }
5614 }
5615
5616 for (i = 0; i < 8; i++) {
5617 err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
5618 if (err)
5619 return err;
5620 }
5621
5622 return 0;
5623}
5624
5625static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
5626 struct net_device *lag)
5627{
5628 int err;
5629
5630 err = mv88e6xxx_lag_sync_masks(ds);
5631
5632 if (!err)
5633 err = mv88e6xxx_lag_sync_map(ds, lag);
5634
5635 return err;
5636}
5637
5638static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port)
5639{
5640 struct mv88e6xxx_chip *chip = ds->priv;
5641 int err;
5642
5643 mv88e6xxx_reg_lock(chip);
5644 err = mv88e6xxx_lag_sync_masks(ds);
5645 mv88e6xxx_reg_unlock(chip);
5646 return err;
5647}
5648
5649static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
5650 struct net_device *lag,
5651 struct netdev_lag_upper_info *info)
5652{
5653 struct mv88e6xxx_chip *chip = ds->priv;
5654 int err, id;
5655
5656 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
5657 return -EOPNOTSUPP;
5658
5659 id = dsa_lag_id(ds->dst, lag);
5660
5661 mv88e6xxx_reg_lock(chip);
5662
5663 err = mv88e6xxx_port_set_trunk(chip, port, true, id);
5664 if (err)
5665 goto err_unlock;
5666
5667 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
5668 if (err)
5669 goto err_clear_trunk;
5670
5671 mv88e6xxx_reg_unlock(chip);
5672 return 0;
5673
5674err_clear_trunk:
5675 mv88e6xxx_port_set_trunk(chip, port, false, 0);
5676err_unlock:
5677 mv88e6xxx_reg_unlock(chip);
5678 return err;
5679}
5680
5681static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
5682 struct net_device *lag)
5683{
5684 struct mv88e6xxx_chip *chip = ds->priv;
5685 int err_sync, err_trunk;
5686
5687 mv88e6xxx_reg_lock(chip);
5688 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
5689 err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
5690 mv88e6xxx_reg_unlock(chip);
5691 return err_sync ? : err_trunk;
5692}
5693
5694static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
5695 int port)
5696{
5697 struct mv88e6xxx_chip *chip = ds->priv;
5698 int err;
5699
5700 mv88e6xxx_reg_lock(chip);
5701 err = mv88e6xxx_lag_sync_masks(ds);
5702 mv88e6xxx_reg_unlock(chip);
5703 return err;
5704}
5705
5706static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
5707 int port, struct net_device *lag,
5708 struct netdev_lag_upper_info *info)
5709{
5710 struct mv88e6xxx_chip *chip = ds->priv;
5711 int err;
5712
5713 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
5714 return -EOPNOTSUPP;
5715
5716 mv88e6xxx_reg_lock(chip);
5717
5718 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
5719 if (err)
5720 goto unlock;
5721
5722 err = mv88e6xxx_pvt_map(chip, sw_index, port);
5723
5724unlock:
5725 mv88e6xxx_reg_unlock(chip);
5726 return err;
5727}
5728
5729static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
5730 int port, struct net_device *lag)
5731{
5732 struct mv88e6xxx_chip *chip = ds->priv;
5733 int err_sync, err_pvt;
5734
5735 mv88e6xxx_reg_lock(chip);
5736 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
5737 err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
5738 mv88e6xxx_reg_unlock(chip);
5739 return err_sync ? : err_pvt;
5740}
5741
Florian Fainellia82f67a2017-01-08 14:52:08 -08005742static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02005743 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005744 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005745 .teardown = mv88e6xxx_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07005746 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00005747 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07005748 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00005749 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07005750 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
5751 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005752 .get_strings = mv88e6xxx_get_strings,
5753 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
5754 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02005755 .port_enable = mv88e6xxx_port_enable,
5756 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02005757 .port_max_mtu = mv88e6xxx_get_max_mtu,
5758 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04005759 .get_mac_eee = mv88e6xxx_get_mac_eee,
5760 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005761 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005762 .get_eeprom = mv88e6xxx_get_eeprom,
5763 .set_eeprom = mv88e6xxx_set_eeprom,
5764 .get_regs_len = mv88e6xxx_get_regs_len,
5765 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04005766 .get_rxnfc = mv88e6xxx_get_rxnfc,
5767 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04005768 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005769 .port_bridge_join = mv88e6xxx_port_bridge_join,
5770 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005771 .port_pre_bridge_flags = mv88e6xxx_port_pre_bridge_flags,
5772 .port_bridge_flags = mv88e6xxx_port_bridge_flags,
5773 .port_set_mrouter = mv88e6xxx_port_set_mrouter,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005774 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04005775 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005776 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005777 .port_vlan_add = mv88e6xxx_port_vlan_add,
5778 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005779 .port_fdb_add = mv88e6xxx_port_fdb_add,
5780 .port_fdb_del = mv88e6xxx_port_fdb_del,
5781 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005782 .port_mdb_add = mv88e6xxx_port_mdb_add,
5783 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005784 .port_mirror_add = mv88e6xxx_port_mirror_add,
5785 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04005786 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
5787 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005788 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
5789 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
5790 .port_txtstamp = mv88e6xxx_port_txtstamp,
5791 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
5792 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005793 .devlink_param_get = mv88e6xxx_devlink_param_get,
5794 .devlink_param_set = mv88e6xxx_devlink_param_set,
Andrew Lunn93157302020-09-18 21:11:09 +02005795 .devlink_info_get = mv88e6xxx_devlink_info_get,
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005796 .port_lag_change = mv88e6xxx_port_lag_change,
5797 .port_lag_join = mv88e6xxx_port_lag_join,
5798 .port_lag_leave = mv88e6xxx_port_lag_leave,
5799 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
5800 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
5801 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005802};
5803
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005804static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005805{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005806 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005807 struct dsa_switch *ds;
5808
Vivien Didelot7e99e342019-10-21 16:51:30 -04005809 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005810 if (!ds)
5811 return -ENOMEM;
5812
Vivien Didelot7e99e342019-10-21 16:51:30 -04005813 ds->dev = dev;
5814 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005815 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005816 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04005817 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04005818 ds->ageing_time_min = chip->info->age_time_coeff;
5819 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005820
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005821 /* Some chips support up to 32, but that requires enabling the
5822 * 5-bit port mode, which we do not support. 640k^W16 ought to
5823 * be enough for anyone.
5824 */
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005825 ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005826
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005827 dev_set_drvdata(dev, ds);
5828
Vivien Didelot23c9ee42017-05-26 18:12:51 -04005829 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005830}
5831
Vivien Didelotfad09c72016-06-21 12:28:20 -04005832static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005833{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005834 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005835}
5836
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005837static const void *pdata_device_get_match_data(struct device *dev)
5838{
5839 const struct of_device_id *matches = dev->driver->of_match_table;
5840 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
5841
5842 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
5843 matches++) {
5844 if (!strcmp(pdata->compatible, matches->compatible))
5845 return matches->data;
5846 }
5847 return NULL;
5848}
5849
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005850/* There is no suspend to RAM support at DSA level yet, the switch configuration
5851 * would be lost after a power cycle so prevent it to be suspended.
5852 */
5853static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
5854{
5855 return -EOPNOTSUPP;
5856}
5857
5858static int __maybe_unused mv88e6xxx_resume(struct device *dev)
5859{
5860 return 0;
5861}
5862
5863static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
5864
Vivien Didelot57d32312016-06-20 13:13:58 -04005865static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005866{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005867 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04005868 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005869 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005870 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04005871 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005872 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02005873 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005874
Andrew Lunn7bb8c992018-05-31 00:15:42 +02005875 if (!np && !pdata)
5876 return -EINVAL;
5877
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005878 if (np)
5879 compat_info = of_device_get_match_data(dev);
5880
5881 if (pdata) {
5882 compat_info = pdata_device_get_match_data(dev);
5883
5884 if (!pdata->netdev)
5885 return -EINVAL;
5886
5887 for (port = 0; port < DSA_MAX_PORTS; port++) {
5888 if (!(pdata->enabled_ports & (1 << port)))
5889 continue;
5890 if (strcmp(pdata->cd.port_names[port], "cpu"))
5891 continue;
5892 pdata->cd.netdev[port] = &pdata->netdev->dev;
5893 break;
5894 }
5895 }
5896
Vivien Didelotcaac8542016-06-20 13:14:09 -04005897 if (!compat_info)
5898 return -EINVAL;
5899
Vivien Didelotfad09c72016-06-21 12:28:20 -04005900 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005901 if (!chip) {
5902 err = -ENOMEM;
5903 goto out;
5904 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005905
Vivien Didelotfad09c72016-06-21 12:28:20 -04005906 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04005907
Vivien Didelotfad09c72016-06-21 12:28:20 -04005908 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04005909 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005910 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005911
Andrew Lunnb4308f02016-11-21 23:26:55 +01005912 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005913 if (IS_ERR(chip->reset)) {
5914 err = PTR_ERR(chip->reset);
5915 goto out;
5916 }
Baruch Siach7b75e492019-06-27 21:17:39 +03005917 if (chip->reset)
5918 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01005919
Vivien Didelotfad09c72016-06-21 12:28:20 -04005920 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005921 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005922 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005923
Vivien Didelote57e5e72016-08-15 17:19:00 -04005924 mv88e6xxx_phy_init(chip);
5925
Andrew Lunn00baabe2018-05-19 22:31:35 +02005926 if (chip->info->ops->get_eeprom) {
5927 if (np)
5928 of_property_read_u32(np, "eeprom-length",
5929 &chip->eeprom_len);
5930 else
5931 chip->eeprom_len = pdata->eeprom_len;
5932 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005933
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005934 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005935 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005936 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02005937 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02005938 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02005939
Andrew Lunna27415d2019-05-01 00:10:50 +02005940 if (np) {
5941 chip->irq = of_irq_get(np, 0);
5942 if (chip->irq == -EPROBE_DEFER) {
5943 err = chip->irq;
5944 goto out;
5945 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02005946 }
5947
Andrew Lunna27415d2019-05-01 00:10:50 +02005948 if (pdata)
5949 chip->irq = pdata->irq;
5950
Andrew Lunn294d7112018-02-22 22:58:32 +01005951 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01005952 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01005953 * controllers
5954 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005955 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005956 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005957 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005958 else
5959 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005960 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005961
Andrew Lunn294d7112018-02-22 22:58:32 +01005962 if (err)
5963 goto out;
5964
5965 if (chip->info->g2_irqs > 0) {
5966 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005967 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01005968 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005969 }
5970
Andrew Lunn294d7112018-02-22 22:58:32 +01005971 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
5972 if (err)
5973 goto out_g2_irq;
5974
5975 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
5976 if (err)
5977 goto out_g1_atu_prob_irq;
5978
Andrew Lunna3c53be52017-01-24 14:53:50 +01005979 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02005980 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01005981 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005982
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005983 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005984 if (err)
5985 goto out_mdio;
5986
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005987 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02005988
5989out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01005990 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01005991out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005992 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01005993out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005994 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005995out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005996 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005997 mv88e6xxx_g2_irq_free(chip);
5998out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005999 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006000 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006001 else
6002 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006003out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006004 if (pdata)
6005 dev_put(pdata->netdev);
6006
Andrew Lunndc30c352016-10-16 19:56:49 +02006007 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006008}
6009
6010static void mv88e6xxx_remove(struct mdio_device *mdiodev)
6011{
6012 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04006013 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006014
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006015 if (chip->info->ptp_support) {
6016 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006017 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006018 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006019
Andrew Lunn930188c2016-08-22 16:01:03 +02006020 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006021 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01006022 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006023
Andrew Lunn76f38f12018-03-17 20:21:09 +01006024 mv88e6xxx_g1_vtu_prob_irq_free(chip);
6025 mv88e6xxx_g1_atu_prob_irq_free(chip);
6026
6027 if (chip->info->g2_irqs > 0)
6028 mv88e6xxx_g2_irq_free(chip);
6029
Andrew Lunn76f38f12018-03-17 20:21:09 +01006030 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006031 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01006032 else
6033 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006034}
6035
6036static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04006037 {
6038 .compatible = "marvell,mv88e6085",
6039 .data = &mv88e6xxx_table[MV88E6085],
6040 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01006041 {
6042 .compatible = "marvell,mv88e6190",
6043 .data = &mv88e6xxx_table[MV88E6190],
6044 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00006045 {
6046 .compatible = "marvell,mv88e6250",
6047 .data = &mv88e6xxx_table[MV88E6250],
6048 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006049 { /* sentinel */ },
6050};
6051
6052MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
6053
6054static struct mdio_driver mv88e6xxx_driver = {
6055 .probe = mv88e6xxx_probe,
6056 .remove = mv88e6xxx_remove,
6057 .mdiodrv.driver = {
6058 .name = "mv88e6085",
6059 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006060 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006061 },
6062};
6063
Andrew Lunn7324d502019-04-27 19:19:10 +02006064mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00006065
6066MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
6067MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
6068MODULE_LICENSE("GPL");