blob: 91286d7b12c75b0c065d2811021b16cbc5d0907a [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 {
1689 entry.portvec |= BIT(port);
1690 entry.state = state;
1691 }
1692
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001693 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001694}
1695
Vivien Didelotda7dc872019-09-07 16:00:49 -04001696static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1697 const struct mv88e6xxx_policy *policy)
1698{
1699 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1700 enum mv88e6xxx_policy_action action = policy->action;
1701 const u8 *addr = policy->addr;
1702 u16 vid = policy->vid;
1703 u8 state;
1704 int err;
1705 int id;
1706
1707 if (!chip->info->ops->port_set_policy)
1708 return -EOPNOTSUPP;
1709
1710 switch (mapping) {
1711 case MV88E6XXX_POLICY_MAPPING_DA:
1712 case MV88E6XXX_POLICY_MAPPING_SA:
1713 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1714 state = 0; /* Dissociate the port and address */
1715 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1716 is_multicast_ether_addr(addr))
1717 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1718 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1719 is_unicast_ether_addr(addr))
1720 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1721 else
1722 return -EOPNOTSUPP;
1723
1724 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1725 state);
1726 if (err)
1727 return err;
1728 break;
1729 default:
1730 return -EOPNOTSUPP;
1731 }
1732
1733 /* Skip the port's policy clearing if the mapping is still in use */
1734 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1735 idr_for_each_entry(&chip->policies, policy, id)
1736 if (policy->port == port &&
1737 policy->mapping == mapping &&
1738 policy->action != action)
1739 return 0;
1740
1741 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1742}
1743
1744static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1745 struct ethtool_rx_flow_spec *fs)
1746{
1747 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1748 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1749 enum mv88e6xxx_policy_mapping mapping;
1750 enum mv88e6xxx_policy_action action;
1751 struct mv88e6xxx_policy *policy;
1752 u16 vid = 0;
1753 u8 *addr;
1754 int err;
1755 int id;
1756
1757 if (fs->location != RX_CLS_LOC_ANY)
1758 return -EINVAL;
1759
1760 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1761 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1762 else
1763 return -EOPNOTSUPP;
1764
1765 switch (fs->flow_type & ~FLOW_EXT) {
1766 case ETHER_FLOW:
1767 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1768 is_zero_ether_addr(mac_mask->h_source)) {
1769 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1770 addr = mac_entry->h_dest;
1771 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1772 !is_zero_ether_addr(mac_mask->h_source)) {
1773 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1774 addr = mac_entry->h_source;
1775 } else {
1776 /* Cannot support DA and SA mapping in the same rule */
1777 return -EOPNOTSUPP;
1778 }
1779 break;
1780 default:
1781 return -EOPNOTSUPP;
1782 }
1783
1784 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001785 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001786 return -EOPNOTSUPP;
1787 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1788 }
1789
1790 idr_for_each_entry(&chip->policies, policy, id) {
1791 if (policy->port == port && policy->mapping == mapping &&
1792 policy->action == action && policy->vid == vid &&
1793 ether_addr_equal(policy->addr, addr))
1794 return -EEXIST;
1795 }
1796
1797 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1798 if (!policy)
1799 return -ENOMEM;
1800
1801 fs->location = 0;
1802 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1803 GFP_KERNEL);
1804 if (err) {
1805 devm_kfree(chip->dev, policy);
1806 return err;
1807 }
1808
1809 memcpy(&policy->fs, fs, sizeof(*fs));
1810 ether_addr_copy(policy->addr, addr);
1811 policy->mapping = mapping;
1812 policy->action = action;
1813 policy->port = port;
1814 policy->vid = vid;
1815
1816 err = mv88e6xxx_policy_apply(chip, port, policy);
1817 if (err) {
1818 idr_remove(&chip->policies, fs->location);
1819 devm_kfree(chip->dev, policy);
1820 return err;
1821 }
1822
1823 return 0;
1824}
1825
1826static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1827 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1828{
1829 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1830 struct mv88e6xxx_chip *chip = ds->priv;
1831 struct mv88e6xxx_policy *policy;
1832 int err;
1833 int id;
1834
1835 mv88e6xxx_reg_lock(chip);
1836
1837 switch (rxnfc->cmd) {
1838 case ETHTOOL_GRXCLSRLCNT:
1839 rxnfc->data = 0;
1840 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1841 rxnfc->rule_cnt = 0;
1842 idr_for_each_entry(&chip->policies, policy, id)
1843 if (policy->port == port)
1844 rxnfc->rule_cnt++;
1845 err = 0;
1846 break;
1847 case ETHTOOL_GRXCLSRULE:
1848 err = -ENOENT;
1849 policy = idr_find(&chip->policies, fs->location);
1850 if (policy) {
1851 memcpy(fs, &policy->fs, sizeof(*fs));
1852 err = 0;
1853 }
1854 break;
1855 case ETHTOOL_GRXCLSRLALL:
1856 rxnfc->data = 0;
1857 rxnfc->rule_cnt = 0;
1858 idr_for_each_entry(&chip->policies, policy, id)
1859 if (policy->port == port)
1860 rule_locs[rxnfc->rule_cnt++] = id;
1861 err = 0;
1862 break;
1863 default:
1864 err = -EOPNOTSUPP;
1865 break;
1866 }
1867
1868 mv88e6xxx_reg_unlock(chip);
1869
1870 return err;
1871}
1872
1873static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1874 struct ethtool_rxnfc *rxnfc)
1875{
1876 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1877 struct mv88e6xxx_chip *chip = ds->priv;
1878 struct mv88e6xxx_policy *policy;
1879 int err;
1880
1881 mv88e6xxx_reg_lock(chip);
1882
1883 switch (rxnfc->cmd) {
1884 case ETHTOOL_SRXCLSRLINS:
1885 err = mv88e6xxx_policy_insert(chip, port, fs);
1886 break;
1887 case ETHTOOL_SRXCLSRLDEL:
1888 err = -ENOENT;
1889 policy = idr_remove(&chip->policies, fs->location);
1890 if (policy) {
1891 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
1892 err = mv88e6xxx_policy_apply(chip, port, policy);
1893 devm_kfree(chip->dev, policy);
1894 }
1895 break;
1896 default:
1897 err = -EOPNOTSUPP;
1898 break;
1899 }
1900
1901 mv88e6xxx_reg_unlock(chip);
1902
1903 return err;
1904}
1905
Andrew Lunn87fa8862017-11-09 22:29:56 +01001906static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1907 u16 vid)
1908{
1909 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1910 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1911
1912 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1913}
1914
1915static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1916{
1917 int port;
1918 int err;
1919
1920 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1921 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1922 if (err)
1923 return err;
1924 }
1925
1926 return 0;
1927}
1928
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001929static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00001930 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001931{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001932 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001933 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001934 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001935
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001936 vlan.vid = vid - 1;
1937 vlan.valid = false;
1938
1939 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001940 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001941 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001942
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001943 if (vlan.vid != vid || !vlan.valid) {
1944 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001945
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001946 err = mv88e6xxx_atu_new(chip, &vlan.fid);
1947 if (err)
1948 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01001949
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001950 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1951 if (i == port)
1952 vlan.member[i] = member;
1953 else
1954 vlan.member[i] = non_member;
1955
1956 vlan.vid = vid;
1957 vlan.valid = true;
1958
1959 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1960 if (err)
1961 return err;
1962
1963 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
1964 if (err)
1965 return err;
1966 } else if (vlan.member[port] != member) {
1967 vlan.member[port] = member;
1968
1969 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1970 if (err)
1971 return err;
Russell King933b4422020-02-26 17:14:26 +00001972 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001973 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
1974 port, vid);
1975 }
1976
1977 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001978}
1979
Vladimir Oltean1958d582021-01-09 02:01:53 +02001980static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1981 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001982{
Vivien Didelot04bed142016-08-31 18:06:13 -04001983 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001984 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1985 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Russell King933b4422020-02-26 17:14:26 +00001986 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001987 u8 member;
Vladimir Oltean1958d582021-01-09 02:01:53 +02001988 int err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001989
Vladimir Oltean1958d582021-01-09 02:01:53 +02001990 err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
1991 if (err)
1992 return err;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001993
Vivien Didelotc91498e2017-06-07 18:12:13 -04001994 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001995 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001996 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001997 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001998 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001999 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002000
Russell King933b4422020-02-26 17:14:26 +00002001 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
2002 * and then the CPU port. Do not warn for duplicates for the CPU port.
2003 */
2004 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
2005
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002006 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002007
Vladimir Oltean1958d582021-01-09 02:01:53 +02002008 err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
2009 if (err) {
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002010 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2011 vlan->vid, untagged ? 'u' : 't');
Vladimir Oltean1958d582021-01-09 02:01:53 +02002012 goto out;
2013 }
Vivien Didelot76e398a2015-11-01 12:33:55 -05002014
Vladimir Oltean1958d582021-01-09 02:01:53 +02002015 if (pvid) {
2016 err = mv88e6xxx_port_set_pvid(chip, port, vlan->vid);
2017 if (err) {
2018 dev_err(ds->dev, "p%d: failed to set PVID %d\n",
2019 port, vlan->vid);
2020 goto out;
2021 }
2022 }
2023out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002024 mv88e6xxx_reg_unlock(chip);
Vladimir Oltean1958d582021-01-09 02:01:53 +02002025
2026 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002027}
2028
Vivien Didelot521098922019-08-01 14:36:36 -04002029static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2030 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002031{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002032 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002033 int i, err;
2034
Vivien Didelot521098922019-08-01 14:36:36 -04002035 if (!vid)
2036 return -EOPNOTSUPP;
2037
2038 vlan.vid = vid - 1;
2039 vlan.valid = false;
2040
2041 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002042 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002043 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002044
Vivien Didelot521098922019-08-01 14:36:36 -04002045 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2046 * tell switchdev that this VLAN is likely handled in software.
2047 */
2048 if (vlan.vid != vid || !vlan.valid ||
2049 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002050 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002051
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002052 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002053
2054 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002055 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002056 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002057 if (vlan.member[i] !=
2058 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002059 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002060 break;
2061 }
2062 }
2063
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002064 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002065 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002066 return err;
2067
Vivien Didelote606ca32017-03-11 16:12:55 -05002068 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002069}
2070
Vivien Didelotf81ec902016-05-09 13:22:58 -04002071static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2072 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002073{
Vivien Didelot04bed142016-08-31 18:06:13 -04002074 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002075 int err = 0;
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002076 u16 pvid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002077
Tobias Waldekranze545f862020-11-10 19:57:20 +01002078 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04002079 return -EOPNOTSUPP;
2080
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002081 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002082
Vivien Didelot77064f32016-11-04 03:23:30 +01002083 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002084 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002085 goto unlock;
2086
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002087 err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
2088 if (err)
2089 goto unlock;
2090
2091 if (vlan->vid == pvid) {
2092 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002093 if (err)
2094 goto unlock;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002095 }
2096
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002097unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002098 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002099
2100 return err;
2101}
2102
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002103static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2104 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002105{
Vivien Didelot04bed142016-08-31 18:06:13 -04002106 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002107 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002108
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002109 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002110 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2111 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002112 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002113
2114 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002115}
2116
Vivien Didelotf81ec902016-05-09 13:22:58 -04002117static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002118 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002119{
Vivien Didelot04bed142016-08-31 18:06:13 -04002120 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002121 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002122
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002123 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002124 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002125 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002126
Vivien Didelot83dabd12016-08-31 11:50:04 -04002127 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002128}
2129
Vivien Didelot83dabd12016-08-31 11:50:04 -04002130static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2131 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002132 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002133{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002134 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002135 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002136 int err;
2137
Vivien Didelotd8291a92019-09-07 16:00:47 -04002138 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002139 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002140
2141 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002142 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002143 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002144 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002145
Vivien Didelotd8291a92019-09-07 16:00:47 -04002146 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002147 break;
2148
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002149 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002150 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002151
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002152 if (!is_unicast_ether_addr(addr.mac))
2153 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002154
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002155 is_static = (addr.state ==
2156 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2157 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002158 if (err)
2159 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002160 } while (!is_broadcast_ether_addr(addr.mac));
2161
2162 return err;
2163}
2164
Vivien Didelot83dabd12016-08-31 11:50:04 -04002165static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002166 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002167{
Vivien Didelot425d2d32019-08-01 14:36:34 -04002168 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002169 u16 fid;
2170 int err;
2171
2172 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002173 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002174 if (err)
2175 return err;
2176
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002177 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002178 if (err)
2179 return err;
2180
2181 /* Dump VLANs' Filtering Information Databases */
Tobias Waldekranze545f862020-11-10 19:57:20 +01002182 vlan.vid = mv88e6xxx_max_vid(chip);
Vivien Didelot425d2d32019-08-01 14:36:34 -04002183 vlan.valid = false;
2184
Vivien Didelot83dabd12016-08-31 11:50:04 -04002185 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04002186 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002187 if (err)
2188 return err;
2189
2190 if (!vlan.valid)
2191 break;
2192
2193 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002194 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002195 if (err)
2196 return err;
Tobias Waldekranze545f862020-11-10 19:57:20 +01002197 } while (vlan.vid < mv88e6xxx_max_vid(chip));
Vivien Didelot83dabd12016-08-31 11:50:04 -04002198
2199 return err;
2200}
2201
Vivien Didelotf81ec902016-05-09 13:22:58 -04002202static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002203 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002204{
Vivien Didelot04bed142016-08-31 18:06:13 -04002205 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002206 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002207
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002208 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002209 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002210 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002211
2212 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002213}
2214
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002215static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2216 struct net_device *br)
2217{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002218 struct dsa_switch *ds = chip->ds;
2219 struct dsa_switch_tree *dst = ds->dst;
2220 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002221 int err;
2222
Vivien Didelotef2025e2019-10-21 16:51:27 -04002223 list_for_each_entry(dp, &dst->ports, list) {
2224 if (dp->bridge_dev == br) {
2225 if (dp->ds == ds) {
2226 /* This is a local bridge group member,
2227 * remap its Port VLAN Map.
2228 */
2229 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2230 if (err)
2231 return err;
2232 } else {
2233 /* This is an external bridge group member,
2234 * remap its cross-chip Port VLAN Table entry.
2235 */
2236 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2237 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002238 if (err)
2239 return err;
2240 }
2241 }
2242 }
2243
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002244 return 0;
2245}
2246
Vivien Didelotf81ec902016-05-09 13:22:58 -04002247static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002248 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002249{
Vivien Didelot04bed142016-08-31 18:06:13 -04002250 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002251 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002252
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002253 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002254 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002255 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002256
Vivien Didelot466dfa02016-02-26 13:16:05 -05002257 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002258}
2259
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002260static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2261 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002262{
Vivien Didelot04bed142016-08-31 18:06:13 -04002263 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002264
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002265 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002266 if (mv88e6xxx_bridge_map(chip, br) ||
2267 mv88e6xxx_port_vlan_map(chip, port))
2268 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002269 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002270}
2271
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002272static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2273 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002274 int port, struct net_device *br)
2275{
2276 struct mv88e6xxx_chip *chip = ds->priv;
2277 int err;
2278
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002279 if (tree_index != ds->dst->index)
2280 return 0;
2281
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002282 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002283 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002284 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002285
2286 return err;
2287}
2288
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002289static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2290 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002291 int port, struct net_device *br)
2292{
2293 struct mv88e6xxx_chip *chip = ds->priv;
2294
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002295 if (tree_index != ds->dst->index)
2296 return;
2297
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002298 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002299 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002300 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002301 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002302}
2303
Vivien Didelot17e708b2016-12-05 17:30:27 -05002304static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2305{
2306 if (chip->info->ops->reset)
2307 return chip->info->ops->reset(chip);
2308
2309 return 0;
2310}
2311
Vivien Didelot309eca62016-12-05 17:30:26 -05002312static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2313{
2314 struct gpio_desc *gpiod = chip->reset;
2315
2316 /* If there is a GPIO connected to the reset pin, toggle it */
2317 if (gpiod) {
2318 gpiod_set_value_cansleep(gpiod, 1);
2319 usleep_range(10000, 20000);
2320 gpiod_set_value_cansleep(gpiod, 0);
2321 usleep_range(10000, 20000);
Andrew Lunna3dcb3e2020-11-16 08:43:01 -08002322
2323 mv88e6xxx_g1_wait_eeprom_done(chip);
Vivien Didelot309eca62016-12-05 17:30:26 -05002324 }
2325}
2326
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002327static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2328{
2329 int i, err;
2330
2331 /* Set all ports to the Disabled state */
2332 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002333 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002334 if (err)
2335 return err;
2336 }
2337
2338 /* Wait for transmit queues to drain,
2339 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2340 */
2341 usleep_range(2000, 4000);
2342
2343 return 0;
2344}
2345
Vivien Didelotfad09c72016-06-21 12:28:20 -04002346static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002347{
Vivien Didelota935c052016-09-29 12:21:53 -04002348 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002349
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002350 err = mv88e6xxx_disable_ports(chip);
2351 if (err)
2352 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002353
Vivien Didelot309eca62016-12-05 17:30:26 -05002354 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002355
Vivien Didelot17e708b2016-12-05 17:30:27 -05002356 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002357}
2358
Vivien Didelot43145572017-03-11 16:12:59 -05002359static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002360 enum mv88e6xxx_frame_mode frame,
2361 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002362{
2363 int err;
2364
Vivien Didelot43145572017-03-11 16:12:59 -05002365 if (!chip->info->ops->port_set_frame_mode)
2366 return -EOPNOTSUPP;
2367
2368 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002369 if (err)
2370 return err;
2371
Vivien Didelot43145572017-03-11 16:12:59 -05002372 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2373 if (err)
2374 return err;
2375
2376 if (chip->info->ops->port_set_ether_type)
2377 return chip->info->ops->port_set_ether_type(chip, port, etype);
2378
2379 return 0;
2380}
2381
2382static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2383{
2384 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002385 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002386 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002387}
2388
2389static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2390{
2391 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002392 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002393 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002394}
2395
2396static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2397{
2398 return mv88e6xxx_set_port_mode(chip, port,
2399 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002400 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2401 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002402}
2403
2404static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2405{
2406 if (dsa_is_dsa_port(chip->ds, port))
2407 return mv88e6xxx_set_port_mode_dsa(chip, port);
2408
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002409 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002410 return mv88e6xxx_set_port_mode_normal(chip, port);
2411
2412 /* Setup CPU port mode depending on its supported tag format */
2413 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2414 return mv88e6xxx_set_port_mode_dsa(chip, port);
2415
2416 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2417 return mv88e6xxx_set_port_mode_edsa(chip, port);
2418
2419 return -EINVAL;
2420}
2421
Vivien Didelotea698f42017-03-11 16:12:50 -05002422static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2423{
2424 bool message = dsa_is_dsa_port(chip->ds, port);
2425
2426 return mv88e6xxx_port_set_message_port(chip, port, message);
2427}
2428
Vivien Didelot601aeed2017-03-11 16:13:00 -05002429static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2430{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002431 struct dsa_switch *ds = chip->ds;
David S. Miller407308f2019-06-15 13:35:29 -07002432 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002433
David S. Miller407308f2019-06-15 13:35:29 -07002434 /* Upstream ports flood frames with unknown unicast or multicast DA */
2435 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2436 if (chip->info->ops->port_set_egress_floods)
2437 return chip->info->ops->port_set_egress_floods(chip, port,
2438 flood, flood);
Vivien Didelot601aeed2017-03-11 16:13:00 -05002439
David S. Miller407308f2019-06-15 13:35:29 -07002440 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002441}
2442
Vivien Didelot45de77f2019-08-31 16:18:36 -04002443static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2444{
2445 struct mv88e6xxx_port *mvp = dev_id;
2446 struct mv88e6xxx_chip *chip = mvp->chip;
2447 irqreturn_t ret = IRQ_NONE;
2448 int port = mvp->port;
2449 u8 lane;
2450
2451 mv88e6xxx_reg_lock(chip);
2452 lane = mv88e6xxx_serdes_get_lane(chip, port);
2453 if (lane)
2454 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2455 mv88e6xxx_reg_unlock(chip);
2456
2457 return ret;
2458}
2459
2460static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
2461 u8 lane)
2462{
2463 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2464 unsigned int irq;
2465 int err;
2466
2467 /* Nothing to request if this SERDES port has no IRQ */
2468 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2469 if (!irq)
2470 return 0;
2471
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002472 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2473 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2474
Vivien Didelot45de77f2019-08-31 16:18:36 -04002475 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2476 mv88e6xxx_reg_unlock(chip);
2477 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002478 IRQF_ONESHOT, dev_id->serdes_irq_name,
2479 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002480 mv88e6xxx_reg_lock(chip);
2481 if (err)
2482 return err;
2483
2484 dev_id->serdes_irq = irq;
2485
2486 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2487}
2488
2489static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
2490 u8 lane)
2491{
2492 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2493 unsigned int irq = dev_id->serdes_irq;
2494 int err;
2495
2496 /* Nothing to free if no IRQ has been requested */
2497 if (!irq)
2498 return 0;
2499
2500 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2501
2502 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2503 mv88e6xxx_reg_unlock(chip);
2504 free_irq(irq, dev_id);
2505 mv88e6xxx_reg_lock(chip);
2506
2507 dev_id->serdes_irq = 0;
2508
2509 return err;
2510}
2511
Andrew Lunn6d917822017-05-26 01:03:21 +02002512static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2513 bool on)
2514{
Vivien Didelotdc272f62019-08-31 16:18:33 -04002515 u8 lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002516 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002517
Vivien Didelotdc272f62019-08-31 16:18:33 -04002518 lane = mv88e6xxx_serdes_get_lane(chip, port);
2519 if (!lane)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002520 return 0;
2521
2522 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002523 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002524 if (err)
2525 return err;
2526
Vivien Didelot45de77f2019-08-31 16:18:36 -04002527 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002528 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002529 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2530 if (err)
2531 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002532
Vivien Didelotdc272f62019-08-31 16:18:33 -04002533 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002534 }
2535
2536 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002537}
2538
Vivien Didelotfa371c82017-12-05 15:34:10 -05002539static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2540{
2541 struct dsa_switch *ds = chip->ds;
2542 int upstream_port;
2543 int err;
2544
Vivien Didelot07073c72017-12-05 15:34:13 -05002545 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002546 if (chip->info->ops->port_set_upstream_port) {
2547 err = chip->info->ops->port_set_upstream_port(chip, port,
2548 upstream_port);
2549 if (err)
2550 return err;
2551 }
2552
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002553 if (port == upstream_port) {
2554 if (chip->info->ops->set_cpu_port) {
2555 err = chip->info->ops->set_cpu_port(chip,
2556 upstream_port);
2557 if (err)
2558 return err;
2559 }
2560
2561 if (chip->info->ops->set_egress_port) {
2562 err = chip->info->ops->set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002563 MV88E6XXX_EGRESS_DIR_INGRESS,
2564 upstream_port);
2565 if (err)
2566 return err;
2567
2568 err = chip->info->ops->set_egress_port(chip,
2569 MV88E6XXX_EGRESS_DIR_EGRESS,
2570 upstream_port);
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002571 if (err)
2572 return err;
2573 }
2574 }
2575
Vivien Didelotfa371c82017-12-05 15:34:10 -05002576 return 0;
2577}
2578
Vivien Didelotfad09c72016-06-21 12:28:20 -04002579static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002580{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002581 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002582 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002583 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002584
Andrew Lunn7b898462018-08-09 15:38:47 +02002585 chip->ports[port].chip = chip;
2586 chip->ports[port].port = port;
2587
Vivien Didelotd78343d2016-11-04 03:23:36 +01002588 /* MAC Forcing register: don't force link, speed, duplex or flow control
2589 * state to any particular values on physical ports, but force the CPU
2590 * port and all DSA ports to their maximum bandwidth and full duplex.
2591 */
2592 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2593 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2594 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002595 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002596 PHY_INTERFACE_MODE_NA);
2597 else
2598 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2599 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002600 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002601 PHY_INTERFACE_MODE_NA);
2602 if (err)
2603 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002604
2605 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2606 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2607 * tunneling, determine priority by looking at 802.1p and IP
2608 * priority fields (IP prio has precedence), and set STP state
2609 * to Forwarding.
2610 *
2611 * If this is the CPU link, use DSA or EDSA tagging depending
2612 * on which tagging mode was configured.
2613 *
2614 * If this is a link to another switch, use DSA tagging mode.
2615 *
2616 * If this is the upstream port for this switch, enable
2617 * forwarding of unknown unicasts and multicasts.
2618 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002619 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2620 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2621 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2622 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002623 if (err)
2624 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002625
Vivien Didelot601aeed2017-03-11 16:13:00 -05002626 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002627 if (err)
2628 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002629
Vivien Didelot601aeed2017-03-11 16:13:00 -05002630 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002631 if (err)
2632 return err;
2633
Vivien Didelot8efdda42015-08-13 12:52:23 -04002634 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002635 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002636 * untagged frames on this port, do a destination address lookup on all
2637 * received packets as usual, disable ARP mirroring and don't send a
2638 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002639 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002640 err = mv88e6xxx_port_set_map_da(chip, port);
2641 if (err)
2642 return err;
2643
Vivien Didelotfa371c82017-12-05 15:34:10 -05002644 err = mv88e6xxx_setup_upstream_port(chip, port);
2645 if (err)
2646 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002647
Andrew Lunna23b2962017-02-04 20:15:28 +01002648 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002649 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002650 if (err)
2651 return err;
2652
Vivien Didelotcd782652017-06-08 18:34:13 -04002653 if (chip->info->ops->port_set_jumbo_size) {
2654 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002655 if (err)
2656 return err;
2657 }
2658
Andrew Lunn54d792f2015-05-06 01:09:47 +02002659 /* Port Association Vector: when learning source addresses
2660 * of packets, add the address to the address database using
2661 * a port bitmap that has only the bit for this port set and
2662 * the other bits clear.
2663 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002664 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002665 /* Disable learning for CPU port */
2666 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002667 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002668
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002669 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2670 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002671 if (err)
2672 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002673
2674 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002675 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2676 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002677 if (err)
2678 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002679
Vivien Didelot08984322017-06-08 18:34:12 -04002680 if (chip->info->ops->port_pause_limit) {
2681 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002682 if (err)
2683 return err;
2684 }
2685
Vivien Didelotc8c94892017-03-11 16:13:01 -05002686 if (chip->info->ops->port_disable_learn_limit) {
2687 err = chip->info->ops->port_disable_learn_limit(chip, port);
2688 if (err)
2689 return err;
2690 }
2691
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002692 if (chip->info->ops->port_disable_pri_override) {
2693 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002694 if (err)
2695 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002696 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002697
Andrew Lunnef0a7312016-12-03 04:35:16 +01002698 if (chip->info->ops->port_tag_remap) {
2699 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002700 if (err)
2701 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002702 }
2703
Andrew Lunnef70b112016-12-03 04:45:18 +01002704 if (chip->info->ops->port_egress_rate_limiting) {
2705 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002706 if (err)
2707 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002708 }
2709
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002710 if (chip->info->ops->port_setup_message_port) {
2711 err = chip->info->ops->port_setup_message_port(chip, port);
2712 if (err)
2713 return err;
2714 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002715
Vivien Didelot207afda2016-04-14 14:42:09 -04002716 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002717 * database, and allow bidirectional communication between the
2718 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002719 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002720 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002721 if (err)
2722 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002723
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002724 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002725 if (err)
2726 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002727
2728 /* Default VLAN ID and priority: don't set a default VLAN
2729 * ID, and set the default packet priority to zero.
2730 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002731 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002732}
2733
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002734static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
2735{
2736 struct mv88e6xxx_chip *chip = ds->priv;
2737
2738 if (chip->info->ops->port_set_jumbo_size)
2739 return 10240;
Chris Packham1baf0fa2020-07-24 11:21:22 +12002740 else if (chip->info->ops->set_max_frame_size)
2741 return 1632;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002742 return 1522;
2743}
2744
2745static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
2746{
2747 struct mv88e6xxx_chip *chip = ds->priv;
2748 int ret = 0;
2749
2750 mv88e6xxx_reg_lock(chip);
2751 if (chip->info->ops->port_set_jumbo_size)
2752 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12002753 else if (chip->info->ops->set_max_frame_size)
2754 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002755 else
2756 if (new_mtu > 1522)
2757 ret = -EINVAL;
2758 mv88e6xxx_reg_unlock(chip);
2759
2760 return ret;
2761}
2762
Andrew Lunn04aca992017-05-26 01:03:24 +02002763static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2764 struct phy_device *phydev)
2765{
2766 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002767 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002768
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002769 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002770 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002771 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002772
2773 return err;
2774}
2775
Andrew Lunn75104db2019-02-24 20:44:43 +01002776static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02002777{
2778 struct mv88e6xxx_chip *chip = ds->priv;
2779
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002780 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002781 if (mv88e6xxx_serdes_power(chip, port, false))
2782 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002783 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002784}
2785
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002786static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2787 unsigned int ageing_time)
2788{
Vivien Didelot04bed142016-08-31 18:06:13 -04002789 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002790 int err;
2791
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002792 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05002793 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002794 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002795
2796 return err;
2797}
2798
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002799static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002800{
2801 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002802
Andrew Lunnde2273872016-11-21 23:27:01 +01002803 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002804 if (chip->info->ops->stats_set_histogram) {
2805 err = chip->info->ops->stats_set_histogram(chip);
2806 if (err)
2807 return err;
2808 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002809
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002810 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002811}
2812
Andrew Lunnea890982019-01-09 00:24:03 +01002813/* Check if the errata has already been applied. */
2814static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
2815{
2816 int port;
2817 int err;
2818 u16 val;
2819
2820 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002821 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01002822 if (err) {
2823 dev_err(chip->dev,
2824 "Error reading hidden register: %d\n", err);
2825 return false;
2826 }
2827 if (val != 0x01c0)
2828 return false;
2829 }
2830
2831 return true;
2832}
2833
2834/* The 6390 copper ports have an errata which require poking magic
2835 * values into undocumented hidden registers and then performing a
2836 * software reset.
2837 */
2838static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
2839{
2840 int port;
2841 int err;
2842
2843 if (mv88e6390_setup_errata_applied(chip))
2844 return 0;
2845
2846 /* Set the ports into blocking mode */
2847 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2848 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
2849 if (err)
2850 return err;
2851 }
2852
2853 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002854 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01002855 if (err)
2856 return err;
2857 }
2858
2859 return mv88e6xxx_software_reset(chip);
2860}
2861
Andrew Lunn23e8b472019-10-25 01:03:52 +02002862static void mv88e6xxx_teardown(struct dsa_switch *ds)
2863{
2864 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002865 dsa_devlink_resources_unregister(ds);
Andrew Lunnbfb25542020-09-18 21:11:07 +02002866 mv88e6xxx_teardown_devlink_regions(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02002867}
2868
Vivien Didelotf81ec902016-05-09 13:22:58 -04002869static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002870{
Vivien Didelot04bed142016-08-31 18:06:13 -04002871 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002872 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04002873 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002874 int i;
2875
Vivien Didelotfad09c72016-06-21 12:28:20 -04002876 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002877 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Russell King1fb74192020-10-29 16:09:03 +00002878 ds->configure_vlan_while_not_filtering = true;
Vivien Didelot552238b2016-05-09 13:22:49 -04002879
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002880 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002881
Andrew Lunnea890982019-01-09 00:24:03 +01002882 if (chip->info->ops->setup_errata) {
2883 err = chip->info->ops->setup_errata(chip);
2884 if (err)
2885 goto unlock;
2886 }
2887
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002888 /* Cache the cmode of each port. */
2889 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2890 if (chip->info->ops->port_get_cmode) {
2891 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
2892 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03002893 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002894
2895 chip->ports[i].cmode = cmode;
2896 }
2897 }
2898
Vivien Didelot97299342016-07-18 20:45:30 -04002899 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002900 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04002901 if (dsa_is_unused_port(ds, i))
2902 continue;
2903
Hubert Feursteinc8574862019-07-31 10:23:48 +02002904 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04002905 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02002906 dev_err(chip->dev, "port %d is invalid\n", i);
2907 err = -EINVAL;
2908 goto unlock;
2909 }
2910
Vivien Didelot97299342016-07-18 20:45:30 -04002911 err = mv88e6xxx_setup_port(chip, i);
2912 if (err)
2913 goto unlock;
2914 }
2915
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002916 err = mv88e6xxx_irl_setup(chip);
2917 if (err)
2918 goto unlock;
2919
Vivien Didelot04a69a12017-10-13 14:18:05 -04002920 err = mv88e6xxx_mac_setup(chip);
2921 if (err)
2922 goto unlock;
2923
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002924 err = mv88e6xxx_phy_setup(chip);
2925 if (err)
2926 goto unlock;
2927
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002928 err = mv88e6xxx_vtu_setup(chip);
2929 if (err)
2930 goto unlock;
2931
Vivien Didelot81228992017-03-30 17:37:08 -04002932 err = mv88e6xxx_pvt_setup(chip);
2933 if (err)
2934 goto unlock;
2935
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002936 err = mv88e6xxx_atu_setup(chip);
2937 if (err)
2938 goto unlock;
2939
Andrew Lunn87fa8862017-11-09 22:29:56 +01002940 err = mv88e6xxx_broadcast_setup(chip, 0);
2941 if (err)
2942 goto unlock;
2943
Vivien Didelot9e907d72017-07-17 13:03:43 -04002944 err = mv88e6xxx_pot_setup(chip);
2945 if (err)
2946 goto unlock;
2947
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002948 err = mv88e6xxx_rmu_setup(chip);
2949 if (err)
2950 goto unlock;
2951
Vivien Didelot51c901a2017-07-17 13:03:41 -04002952 err = mv88e6xxx_rsvd2cpu_setup(chip);
2953 if (err)
2954 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002955
Vivien Didelotb28f8722018-04-26 21:56:44 -04002956 err = mv88e6xxx_trunk_setup(chip);
2957 if (err)
2958 goto unlock;
2959
Vivien Didelotc7f047b2018-04-26 21:56:45 -04002960 err = mv88e6xxx_devmap_setup(chip);
2961 if (err)
2962 goto unlock;
2963
Vivien Didelot93e18d62018-05-11 17:16:35 -04002964 err = mv88e6xxx_pri_setup(chip);
2965 if (err)
2966 goto unlock;
2967
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002968 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002969 if (chip->info->ptp_support) {
2970 err = mv88e6xxx_ptp_setup(chip);
2971 if (err)
2972 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002973
2974 err = mv88e6xxx_hwtstamp_setup(chip);
2975 if (err)
2976 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002977 }
2978
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002979 err = mv88e6xxx_stats_setup(chip);
2980 if (err)
2981 goto unlock;
2982
Vivien Didelot6b17e862015-08-13 12:52:18 -04002983unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002984 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02002985
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002986 if (err)
2987 return err;
2988
2989 /* Have to be called without holding the register lock, since
2990 * they take the devlink lock, and we later take the locks in
2991 * the reverse order when getting/setting parameters or
2992 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02002993 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002994 err = mv88e6xxx_setup_devlink_resources(ds);
2995 if (err)
2996 return err;
2997
2998 err = mv88e6xxx_setup_devlink_params(ds);
2999 if (err)
Andrew Lunnbfb25542020-09-18 21:11:07 +02003000 goto out_resources;
3001
3002 err = mv88e6xxx_setup_devlink_regions(ds);
3003 if (err)
3004 goto out_params;
3005
3006 return 0;
3007
3008out_params:
3009 mv88e6xxx_teardown_devlink_params(ds);
3010out_resources:
3011 dsa_devlink_resources_unregister(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003012
3013 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003014}
3015
Vivien Didelote57e5e72016-08-15 17:19:00 -04003016static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003017{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003018 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3019 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003020 u16 val;
3021 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003022
Andrew Lunnee26a222017-01-24 14:53:48 +01003023 if (!chip->info->ops->phy_read)
3024 return -EOPNOTSUPP;
3025
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003026 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003027 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003028 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003029
Andrew Lunnda9f3302017-02-01 03:40:05 +01003030 if (reg == MII_PHYSID2) {
Andrew Lunnddc49ac2018-11-12 18:51:01 +01003031 /* Some internal PHYs don't have a model number. */
3032 if (chip->info->family != MV88E6XXX_FAMILY_6165)
3033 /* Then there is the 6165 family. It gets is
3034 * PHYs correct. But it can also have two
3035 * SERDES interfaces in the PHY address
3036 * space. And these don't have a model
3037 * number. But they are not PHYs, so we don't
3038 * want to give them something a PHY driver
3039 * will recognise.
3040 *
3041 * Use the mv88e6390 family model number
3042 * instead, for anything which really could be
3043 * a PHY,
3044 */
3045 if (!(val & 0x3f0))
3046 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003047 }
3048
Vivien Didelote57e5e72016-08-15 17:19:00 -04003049 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003050}
3051
Vivien Didelote57e5e72016-08-15 17:19:00 -04003052static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003053{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003054 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3055 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003056 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003057
Andrew Lunnee26a222017-01-24 14:53:48 +01003058 if (!chip->info->ops->phy_write)
3059 return -EOPNOTSUPP;
3060
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003061 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003062 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003063 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003064
3065 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003066}
3067
Vivien Didelotfad09c72016-06-21 12:28:20 -04003068static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003069 struct device_node *np,
3070 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003071{
3072 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003073 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003074 struct mii_bus *bus;
3075 int err;
3076
Andrew Lunn2510bab2018-02-22 01:51:49 +01003077 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003078 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003079 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003080 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003081
3082 if (err)
3083 return err;
3084 }
3085
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003086 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003087 if (!bus)
3088 return -ENOMEM;
3089
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003090 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003091 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003092 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003093 INIT_LIST_HEAD(&mdio_bus->list);
3094 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003095
Andrew Lunnb516d452016-06-04 21:17:06 +02003096 if (np) {
3097 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003098 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003099 } else {
3100 bus->name = "mv88e6xxx SMI";
3101 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3102 }
3103
3104 bus->read = mv88e6xxx_mdio_read;
3105 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003106 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003107
Andrew Lunn6f882842018-03-17 20:32:05 +01003108 if (!external) {
3109 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3110 if (err)
3111 return err;
3112 }
3113
Florian Fainelli00e798c2018-05-15 16:56:19 -07003114 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003115 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003116 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003117 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003118 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003119 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003120
3121 if (external)
3122 list_add_tail(&mdio_bus->list, &chip->mdios);
3123 else
3124 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003125
3126 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003127}
3128
Andrew Lunn3126aee2017-12-07 01:05:57 +01003129static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3130
3131{
3132 struct mv88e6xxx_mdio_bus *mdio_bus;
3133 struct mii_bus *bus;
3134
3135 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3136 bus = mdio_bus->bus;
3137
Andrew Lunn6f882842018-03-17 20:32:05 +01003138 if (!mdio_bus->external)
3139 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3140
Andrew Lunn3126aee2017-12-07 01:05:57 +01003141 mdiobus_unregister(bus);
3142 }
3143}
3144
Andrew Lunna3c53be52017-01-24 14:53:50 +01003145static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3146 struct device_node *np)
3147{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003148 struct device_node *child;
3149 int err;
3150
3151 /* Always register one mdio bus for the internal/default mdio
3152 * bus. This maybe represented in the device tree, but is
3153 * optional.
3154 */
3155 child = of_get_child_by_name(np, "mdio");
3156 err = mv88e6xxx_mdio_register(chip, child, false);
3157 if (err)
3158 return err;
3159
3160 /* Walk the device tree, and see if there are any other nodes
3161 * which say they are compatible with the external mdio
3162 * bus.
3163 */
3164 for_each_available_child_of_node(np, child) {
Andrew Lunnceb96fa2020-09-01 04:32:57 +02003165 if (of_device_is_compatible(
3166 child, "marvell,mv88e6xxx-mdio-external")) {
Andrew Lunna3c53be52017-01-24 14:53:50 +01003167 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003168 if (err) {
3169 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303170 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003171 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003172 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003173 }
3174 }
3175
3176 return 0;
3177}
3178
Vivien Didelot855b1932016-07-20 18:18:35 -04003179static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3180{
Vivien Didelot04bed142016-08-31 18:06:13 -04003181 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003182
3183 return chip->eeprom_len;
3184}
3185
Vivien Didelot855b1932016-07-20 18:18:35 -04003186static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3187 struct ethtool_eeprom *eeprom, u8 *data)
3188{
Vivien Didelot04bed142016-08-31 18:06:13 -04003189 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003190 int err;
3191
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003192 if (!chip->info->ops->get_eeprom)
3193 return -EOPNOTSUPP;
3194
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003195 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003196 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003197 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003198
3199 if (err)
3200 return err;
3201
3202 eeprom->magic = 0xc3ec4951;
3203
3204 return 0;
3205}
3206
Vivien Didelot855b1932016-07-20 18:18:35 -04003207static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3208 struct ethtool_eeprom *eeprom, u8 *data)
3209{
Vivien Didelot04bed142016-08-31 18:06:13 -04003210 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003211 int err;
3212
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003213 if (!chip->info->ops->set_eeprom)
3214 return -EOPNOTSUPP;
3215
Vivien Didelot855b1932016-07-20 18:18:35 -04003216 if (eeprom->magic != 0xc3ec4951)
3217 return -EINVAL;
3218
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003219 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003220 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003221 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003222
3223 return err;
3224}
3225
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003226static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003227 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003228 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3229 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003230 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003231 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003232 .phy_read = mv88e6185_phy_ppu_read,
3233 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003234 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003235 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003236 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003237 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003238 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003239 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003240 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003241 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003242 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003243 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003244 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003245 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003246 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003247 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003248 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003249 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3250 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003251 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003252 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3253 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003254 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003255 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003256 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003257 .ppu_enable = mv88e6185_g1_ppu_enable,
3258 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003259 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003260 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003261 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003262 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003263 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003264 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003265};
3266
3267static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003268 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003269 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3270 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003271 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003272 .phy_read = mv88e6185_phy_ppu_read,
3273 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003274 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003275 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003276 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003277 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003278 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01003279 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003280 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003281 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003282 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003283 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003284 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3285 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003286 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003287 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003288 .serdes_power = mv88e6185_serdes_power,
3289 .serdes_get_lane = mv88e6185_serdes_get_lane,
3290 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003291 .ppu_enable = mv88e6185_g1_ppu_enable,
3292 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003293 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003294 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003295 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003296 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003297 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003298};
3299
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003300static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003301 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003302 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3303 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003304 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003305 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3306 .phy_read = mv88e6xxx_g2_smi_phy_read,
3307 .phy_write = mv88e6xxx_g2_smi_phy_write,
3308 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003309 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003310 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003311 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003312 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003313 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003314 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003315 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003316 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003317 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003318 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003319 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003320 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003321 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003322 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003323 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3324 .stats_get_strings = mv88e6095_stats_get_strings,
3325 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003326 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3327 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003328 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003329 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003330 .serdes_power = mv88e6185_serdes_power,
3331 .serdes_get_lane = mv88e6185_serdes_get_lane,
3332 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Chris Packham5c19bc82020-11-24 17:34:39 +13003333 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3334 .serdes_irq_enable = mv88e6097_serdes_irq_enable,
3335 .serdes_irq_status = mv88e6097_serdes_irq_status,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003336 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003337 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003338 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003339 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003340 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003341 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003342 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003343};
3344
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003345static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003346 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003347 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3348 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003349 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003350 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003351 .phy_read = mv88e6xxx_g2_smi_phy_read,
3352 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003353 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003354 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003355 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003356 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003357 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003358 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003359 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003360 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003361 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003362 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003363 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003364 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3365 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003366 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003367 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3368 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003369 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003370 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003371 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003372 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003373 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3374 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003375 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003376 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003377 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003378 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003379};
3380
3381static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003382 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003383 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3384 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003385 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003386 .phy_read = mv88e6185_phy_ppu_read,
3387 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003388 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003389 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003390 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003391 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003392 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003393 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003394 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003395 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003396 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003397 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003398 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003399 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003400 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003401 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003402 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003403 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003404 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3405 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003406 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003407 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3408 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003409 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003410 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003411 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003412 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003413 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003414 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003415 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003416 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003417 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003418};
3419
Vivien Didelot990e27b2017-03-28 13:50:32 -04003420static const struct mv88e6xxx_ops mv88e6141_ops = {
3421 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003422 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3423 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003424 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003425 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3426 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3427 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3428 .phy_read = mv88e6xxx_g2_smi_phy_read,
3429 .phy_write = mv88e6xxx_g2_smi_phy_write,
3430 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003431 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003432 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003433 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003434 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003435 .port_tag_remap = mv88e6095_port_tag_remap,
3436 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3437 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3438 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003439 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003440 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003441 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003442 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3443 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003444 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003445 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003446 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003447 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003448 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003449 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3450 .stats_get_strings = mv88e6320_stats_get_strings,
3451 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003452 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3453 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003454 .watchdog_ops = &mv88e6390_watchdog_ops,
3455 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003456 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003457 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003458 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003459 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003460 .serdes_power = mv88e6390_serdes_power,
3461 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003462 /* Check status register pause & lpa register */
3463 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3464 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3465 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3466 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003467 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003468 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003469 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003470 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003471 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003472};
3473
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003474static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003475 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003476 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3477 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003478 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003479 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003480 .phy_read = mv88e6xxx_g2_smi_phy_read,
3481 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003482 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003483 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003484 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003485 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003486 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003487 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003488 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003489 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003490 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003491 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003492 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003493 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003494 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003495 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003496 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003497 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003498 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3499 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003500 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003501 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3502 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003503 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003504 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003505 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003506 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003507 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3508 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003509 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003510 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003511 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003512 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003513 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003514};
3515
3516static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003517 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003518 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3519 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003520 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003521 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003522 .phy_read = mv88e6165_phy_read,
3523 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003524 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003525 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003526 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003527 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003528 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003529 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003530 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003531 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003532 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003533 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3534 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003535 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003536 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3537 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003538 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003539 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003540 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003541 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003542 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3543 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003544 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003545 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003546 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003547 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003548 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003549};
3550
3551static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003552 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003553 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3554 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003555 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003556 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003557 .phy_read = mv88e6xxx_g2_smi_phy_read,
3558 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003559 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003560 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003561 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003562 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003563 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003564 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003565 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003566 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003567 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003568 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003569 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003570 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003571 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003572 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003573 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003574 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003575 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003576 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3577 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003578 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003579 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3580 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003581 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003582 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003583 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003584 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003585 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3586 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003587 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003588 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003589 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003590};
3591
3592static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003593 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003594 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3595 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003596 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003597 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3598 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003599 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003600 .phy_read = mv88e6xxx_g2_smi_phy_read,
3601 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003602 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003603 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003604 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003605 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003606 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003607 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003608 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003609 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003610 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003611 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003612 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003613 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003614 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003615 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003616 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003617 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003618 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003619 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003620 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3621 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003622 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003623 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3624 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003625 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003626 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003627 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003628 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003629 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003630 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3631 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003632 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003633 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003634 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003635 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3636 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3637 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3638 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003639 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003640 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3641 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003642 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003643 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003644};
3645
3646static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003647 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003648 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3649 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003650 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003651 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003652 .phy_read = mv88e6xxx_g2_smi_phy_read,
3653 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003654 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003655 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003656 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003657 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003658 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003659 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003660 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003661 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003662 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003663 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003664 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003665 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003666 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003667 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003668 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003669 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003670 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003671 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3672 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003673 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003674 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3675 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003676 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003677 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003678 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003679 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003680 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3681 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003682 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003683 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003684 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003685};
3686
3687static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003688 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003689 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3690 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003691 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003692 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3693 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003694 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003695 .phy_read = mv88e6xxx_g2_smi_phy_read,
3696 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003697 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003698 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003699 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003700 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003701 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003702 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003703 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003704 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003705 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003706 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003707 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003708 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003709 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003710 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003711 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003712 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003713 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003714 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003715 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3716 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003717 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003718 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3719 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003720 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003721 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003722 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003723 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003724 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003725 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3726 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003727 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003728 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003729 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003730 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3731 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3732 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3733 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003734 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003735 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003736 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003737 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003738 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3739 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003740 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003741 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003742};
3743
3744static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003745 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003746 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3747 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003748 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003749 .phy_read = mv88e6185_phy_ppu_read,
3750 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003751 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003752 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003753 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003754 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003755 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003756 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003757 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02003758 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003759 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003760 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003761 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003762 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003763 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3764 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003765 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003766 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3767 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003768 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003769 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003770 .serdes_power = mv88e6185_serdes_power,
3771 .serdes_get_lane = mv88e6185_serdes_get_lane,
3772 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelot02317e62018-05-09 11:38:49 -04003773 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003774 .ppu_enable = mv88e6185_g1_ppu_enable,
3775 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003776 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003777 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003778 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003779 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003780 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003781};
3782
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003783static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003784 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003785 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003786 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003787 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3788 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003789 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3790 .phy_read = mv88e6xxx_g2_smi_phy_read,
3791 .phy_write = mv88e6xxx_g2_smi_phy_write,
3792 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003793 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003794 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003795 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003796 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003797 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003798 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003799 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003800 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003801 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003802 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003803 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003804 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003805 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003806 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003807 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003808 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003809 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003810 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003811 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3812 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003813 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003814 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3815 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003816 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003817 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003818 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003819 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003820 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003821 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3822 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003823 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3824 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003825 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003826 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003827 /* Check status register pause & lpa register */
3828 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3829 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3830 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3831 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003832 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003833 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003834 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003835 .serdes_get_strings = mv88e6390_serdes_get_strings,
3836 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003837 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3838 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003839 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003840 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003841};
3842
3843static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003844 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003845 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003846 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003847 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3848 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003849 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3850 .phy_read = mv88e6xxx_g2_smi_phy_read,
3851 .phy_write = mv88e6xxx_g2_smi_phy_write,
3852 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003853 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003854 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003855 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003856 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003857 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003858 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003859 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003860 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003861 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003862 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003863 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003864 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003865 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003866 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003867 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003868 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003869 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003870 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003871 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3872 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003873 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003874 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3875 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003876 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003877 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003878 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003879 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003880 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003881 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3882 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003883 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3884 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003885 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003886 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003887 /* Check status register pause & lpa register */
3888 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3889 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3890 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3891 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003892 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003893 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003894 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003895 .serdes_get_strings = mv88e6390_serdes_get_strings,
3896 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003897 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3898 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003899 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003900 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003901};
3902
3903static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003904 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003905 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003906 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003907 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3908 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003909 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3910 .phy_read = mv88e6xxx_g2_smi_phy_read,
3911 .phy_write = mv88e6xxx_g2_smi_phy_write,
3912 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003913 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003914 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003915 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003916 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003917 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003918 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003919 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003920 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003921 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003922 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003923 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003924 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003925 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003926 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003927 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003928 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003929 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3930 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003931 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003932 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3933 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003934 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003935 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003936 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003937 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003938 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003939 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3940 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003941 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3942 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003943 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003944 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003945 /* Check status register pause & lpa register */
3946 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3947 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3948 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3949 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003950 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003951 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003952 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003953 .serdes_get_strings = mv88e6390_serdes_get_strings,
3954 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003955 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3956 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003957 .avb_ops = &mv88e6390_avb_ops,
3958 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003959 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003960};
3961
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003962static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003963 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003964 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3965 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003966 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003967 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3968 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003969 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003970 .phy_read = mv88e6xxx_g2_smi_phy_read,
3971 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003972 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003973 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003974 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003975 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003976 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003977 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003978 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003979 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003980 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003981 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003982 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003983 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003984 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003985 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003986 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003987 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003988 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003989 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003990 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3991 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003992 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003993 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3994 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003995 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003996 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003997 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003998 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003999 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004000 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4001 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004002 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004003 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004004 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004005 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4006 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4007 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4008 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004009 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004010 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004011 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004012 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004013 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4014 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004015 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004016 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004017 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004018 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004019};
4020
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004021static const struct mv88e6xxx_ops mv88e6250_ops = {
4022 /* MV88E6XXX_FAMILY_6250 */
4023 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4024 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4025 .irl_init_all = mv88e6352_g2_irl_init_all,
4026 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4027 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4028 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4029 .phy_read = mv88e6xxx_g2_smi_phy_read,
4030 .phy_write = mv88e6xxx_g2_smi_phy_write,
4031 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004032 .port_sync_link = mv88e6xxx_port_sync_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004033 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004034 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004035 .port_tag_remap = mv88e6095_port_tag_remap,
4036 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4037 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
4038 .port_set_ether_type = mv88e6351_port_set_ether_type,
4039 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4040 .port_pause_limit = mv88e6097_port_pause_limit,
4041 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004042 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4043 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4044 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4045 .stats_get_strings = mv88e6250_stats_get_strings,
4046 .stats_get_stats = mv88e6250_stats_get_stats,
4047 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4048 .set_egress_port = mv88e6095_g1_set_egress_port,
4049 .watchdog_ops = &mv88e6250_watchdog_ops,
4050 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4051 .pot_clear = mv88e6xxx_g2_pot_clear,
4052 .reset = mv88e6250_g1_reset,
4053 .vtu_getnext = mv88e6250_g1_vtu_getnext,
4054 .vtu_loadpurge = mv88e6250_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004055 .avb_ops = &mv88e6352_avb_ops,
4056 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004057 .phylink_validate = mv88e6065_phylink_validate,
4058};
4059
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004060static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004061 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004062 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004063 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004064 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4065 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004066 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4067 .phy_read = mv88e6xxx_g2_smi_phy_read,
4068 .phy_write = mv88e6xxx_g2_smi_phy_write,
4069 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004070 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004071 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004072 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004073 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004074 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004075 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004076 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004077 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004078 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004079 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004080 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004081 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004082 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004083 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004084 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004085 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004086 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004087 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4088 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004089 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004090 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4091 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004092 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004093 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004094 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004095 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004096 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004097 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4098 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004099 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4100 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004101 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004102 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004103 /* Check status register pause & lpa register */
4104 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4105 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4106 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4107 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004108 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004109 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004110 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004111 .serdes_get_strings = mv88e6390_serdes_get_strings,
4112 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004113 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4114 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004115 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004116 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004117 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004118 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004119};
4120
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004121static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004122 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004123 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4124 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004125 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004126 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4127 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004128 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004129 .phy_read = mv88e6xxx_g2_smi_phy_read,
4130 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004131 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004132 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004133 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004134 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004135 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004136 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004137 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004138 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004139 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004140 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004141 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004142 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004143 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004144 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004145 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004146 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004147 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4148 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004149 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004150 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4151 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004152 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004153 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004154 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004155 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004156 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004157 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004158 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004159 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004160 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004161 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004162};
4163
4164static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004165 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004166 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4167 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004168 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004169 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4170 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004171 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004172 .phy_read = mv88e6xxx_g2_smi_phy_read,
4173 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004174 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004175 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004176 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004177 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004178 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004179 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004180 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004181 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004182 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004183 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004184 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004185 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004186 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004187 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004188 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004189 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004190 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4191 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004192 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004193 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4194 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004195 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004196 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004197 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004198 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004199 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004200 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004201 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004202 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004203};
4204
Vivien Didelot16e329a2017-03-28 13:50:33 -04004205static const struct mv88e6xxx_ops mv88e6341_ops = {
4206 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004207 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4208 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004209 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004210 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4211 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4212 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4213 .phy_read = mv88e6xxx_g2_smi_phy_read,
4214 .phy_write = mv88e6xxx_g2_smi_phy_write,
4215 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004216 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004217 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004218 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004219 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004220 .port_tag_remap = mv88e6095_port_tag_remap,
4221 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4222 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
4223 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004224 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004225 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004226 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004227 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4228 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004229 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004230 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004231 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004232 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004233 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004234 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4235 .stats_get_strings = mv88e6320_stats_get_strings,
4236 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004237 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4238 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004239 .watchdog_ops = &mv88e6390_watchdog_ops,
4240 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004241 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004242 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004243 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004244 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004245 .serdes_power = mv88e6390_serdes_power,
4246 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004247 /* Check status register pause & lpa register */
4248 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4249 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4250 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4251 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004252 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004253 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004254 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004255 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004256 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004257 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01004258 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004259};
4260
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004261static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004262 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004263 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4264 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004265 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004266 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004267 .phy_read = mv88e6xxx_g2_smi_phy_read,
4268 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004269 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004270 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004271 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004272 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004273 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004274 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004275 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004276 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004277 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004278 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004279 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004280 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004281 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004282 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004283 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004284 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004285 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004286 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4287 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004288 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004289 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4290 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004291 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004292 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004293 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004294 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004295 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4296 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004297 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004298 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004299 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004300};
4301
4302static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004303 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004304 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4305 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004306 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004307 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004308 .phy_read = mv88e6xxx_g2_smi_phy_read,
4309 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004310 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004311 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004312 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004313 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004314 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004315 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004316 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004317 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004318 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004319 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004320 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004321 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004322 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004323 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004324 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004325 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004326 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004327 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4328 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004329 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004330 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4331 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004332 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004333 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004334 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004335 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004336 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4337 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004338 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004339 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004340 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004341 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004342 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004343};
4344
4345static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004346 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004347 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4348 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004349 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004350 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4351 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004352 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004353 .phy_read = mv88e6xxx_g2_smi_phy_read,
4354 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004355 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004356 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004357 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004358 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004359 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004360 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004361 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004362 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004363 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004364 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004365 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004366 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004367 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004368 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004369 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004370 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004371 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004372 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004373 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4374 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004375 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004376 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4377 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004378 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004379 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004380 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004381 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004382 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004383 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4384 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004385 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004386 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004387 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004388 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4389 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4390 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4391 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004392 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004393 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004394 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004395 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004396 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004397 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004398 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004399 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4400 .serdes_get_strings = mv88e6352_serdes_get_strings,
4401 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004402 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4403 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004404 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004405};
4406
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004407static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004408 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004409 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004410 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004411 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4412 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004413 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4414 .phy_read = mv88e6xxx_g2_smi_phy_read,
4415 .phy_write = mv88e6xxx_g2_smi_phy_write,
4416 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004417 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004418 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004419 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004420 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004421 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004422 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004423 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004424 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004425 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004426 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004427 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004428 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004429 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004430 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004431 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004432 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004433 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004434 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004435 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004436 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4437 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004438 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004439 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4440 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004441 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004442 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004443 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004444 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004445 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004446 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4447 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004448 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4449 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004450 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004451 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004452 /* Check status register pause & lpa register */
4453 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4454 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4455 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4456 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004457 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004458 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004459 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004460 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004461 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004462 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004463 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4464 .serdes_get_strings = mv88e6390_serdes_get_strings,
4465 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004466 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4467 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004468 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004469};
4470
4471static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004472 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004473 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004474 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004475 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4476 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004477 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4478 .phy_read = mv88e6xxx_g2_smi_phy_read,
4479 .phy_write = mv88e6xxx_g2_smi_phy_write,
4480 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004481 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004482 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004483 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004484 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004485 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004486 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004487 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004488 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004489 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004490 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004491 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004492 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004493 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004494 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004495 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004496 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004497 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004498 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004499 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004500 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4501 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004502 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004503 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4504 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004505 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004506 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004507 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004508 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004509 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004510 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4511 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004512 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4513 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004514 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004515 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004516 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4517 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4518 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4519 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004520 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004521 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004522 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004523 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4524 .serdes_get_strings = mv88e6390_serdes_get_strings,
4525 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004526 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4527 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004528 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004529 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004530 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004531 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004532};
4533
Vivien Didelotf81ec902016-05-09 13:22:58 -04004534static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4535 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004536 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004537 .family = MV88E6XXX_FAMILY_6097,
4538 .name = "Marvell 88E6085",
4539 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004540 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004541 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004542 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004543 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004544 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004545 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004546 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004547 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004548 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004549 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004550 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004551 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004552 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004553 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004554 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004555 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004556 },
4557
4558 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004559 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004560 .family = MV88E6XXX_FAMILY_6095,
4561 .name = "Marvell 88E6095/88E6095F",
4562 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004563 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004564 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004565 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004566 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004567 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004568 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004569 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004570 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004571 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004572 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004573 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004574 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004575 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004576 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004577 },
4578
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004579 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004580 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004581 .family = MV88E6XXX_FAMILY_6097,
4582 .name = "Marvell 88E6097/88E6097F",
4583 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004584 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004585 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004586 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004587 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004588 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004589 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004590 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004591 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004592 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004593 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004594 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004595 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004596 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004597 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01004598 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004599 .ops = &mv88e6097_ops,
4600 },
4601
Vivien Didelotf81ec902016-05-09 13:22:58 -04004602 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004603 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004604 .family = MV88E6XXX_FAMILY_6165,
4605 .name = "Marvell 88E6123",
4606 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004607 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004608 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004609 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004610 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004611 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004612 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004613 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004614 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004615 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004616 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004617 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004618 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004619 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004620 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004621 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004622 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004623 },
4624
4625 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004626 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004627 .family = MV88E6XXX_FAMILY_6185,
4628 .name = "Marvell 88E6131",
4629 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004630 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004631 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004632 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004633 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004634 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004635 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004636 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004637 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004638 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004639 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004640 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004641 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004642 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004643 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004644 },
4645
Vivien Didelot990e27b2017-03-28 13:50:32 -04004646 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004647 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004648 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01004649 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04004650 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004651 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004652 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004653 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004654 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004655 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004656 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004657 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004658 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004659 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004660 .age_time_coeff = 3750,
4661 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004662 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004663 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004664 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004665 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004666 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004667 .ops = &mv88e6141_ops,
4668 },
4669
Vivien Didelotf81ec902016-05-09 13:22:58 -04004670 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004671 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004672 .family = MV88E6XXX_FAMILY_6165,
4673 .name = "Marvell 88E6161",
4674 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004675 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004676 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004677 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004678 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004679 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004680 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004681 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004682 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004683 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004684 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004685 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004686 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004687 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004688 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004689 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004690 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004691 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004692 },
4693
4694 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004695 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004696 .family = MV88E6XXX_FAMILY_6165,
4697 .name = "Marvell 88E6165",
4698 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004699 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004700 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004701 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004702 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004703 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004704 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004705 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004706 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004707 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004708 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004709 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004710 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004711 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004712 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004713 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004714 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004715 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004716 },
4717
4718 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004719 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004720 .family = MV88E6XXX_FAMILY_6351,
4721 .name = "Marvell 88E6171",
4722 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004723 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004724 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004725 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004726 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004727 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004728 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004729 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004730 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004731 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004732 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004733 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004734 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004735 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004736 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004737 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004738 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004739 },
4740
4741 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004742 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004743 .family = MV88E6XXX_FAMILY_6352,
4744 .name = "Marvell 88E6172",
4745 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004746 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004747 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004748 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004749 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004750 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004751 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004752 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004753 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004754 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004755 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004756 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004757 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004758 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004759 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004760 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004761 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004762 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004763 },
4764
4765 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004766 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004767 .family = MV88E6XXX_FAMILY_6351,
4768 .name = "Marvell 88E6175",
4769 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004770 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004771 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004772 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004773 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004774 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004775 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004776 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004777 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004778 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004779 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004780 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004781 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004782 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004783 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004784 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004785 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004786 },
4787
4788 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004789 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004790 .family = MV88E6XXX_FAMILY_6352,
4791 .name = "Marvell 88E6176",
4792 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004793 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004794 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004795 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004796 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004797 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004798 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004799 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004800 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004801 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004802 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004803 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004804 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004805 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004806 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004807 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004808 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004809 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004810 },
4811
4812 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004813 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004814 .family = MV88E6XXX_FAMILY_6185,
4815 .name = "Marvell 88E6185",
4816 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004817 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004818 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004819 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004820 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004821 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004822 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004823 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004824 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004825 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004826 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004827 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004828 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004829 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004830 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004831 },
4832
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004833 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004834 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004835 .family = MV88E6XXX_FAMILY_6390,
4836 .name = "Marvell 88E6190",
4837 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004838 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004839 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004840 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004841 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004842 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004843 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004844 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004845 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004846 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004847 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004848 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004849 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004850 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04004851 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004852 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05004853 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004854 .ops = &mv88e6190_ops,
4855 },
4856
4857 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004858 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004859 .family = MV88E6XXX_FAMILY_6390,
4860 .name = "Marvell 88E6190X",
4861 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004862 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004863 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004864 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004865 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004866 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004867 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004868 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004869 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004870 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004871 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004872 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004873 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004874 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004875 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004876 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004877 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004878 .ops = &mv88e6190x_ops,
4879 },
4880
4881 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004882 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004883 .family = MV88E6XXX_FAMILY_6390,
4884 .name = "Marvell 88E6191",
4885 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004886 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004887 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004888 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04004889 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004890 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004891 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004892 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004893 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004894 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004895 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004896 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004897 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004898 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004899 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004900 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004901 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04004902 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004903 },
4904
Hubert Feurstein49022642019-07-31 10:23:46 +02004905 [MV88E6220] = {
4906 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
4907 .family = MV88E6XXX_FAMILY_6250,
4908 .name = "Marvell 88E6220",
4909 .num_databases = 64,
4910
4911 /* Ports 2-4 are not routed to pins
4912 * => usable ports 0, 1, 5, 6
4913 */
4914 .num_ports = 7,
4915 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02004916 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02004917 .max_vid = 4095,
4918 .port_base_addr = 0x08,
4919 .phy_base_addr = 0x00,
4920 .global1_addr = 0x0f,
4921 .global2_addr = 0x07,
4922 .age_time_coeff = 15000,
4923 .g1_irqs = 9,
4924 .g2_irqs = 10,
4925 .atu_move_port_mask = 0xf,
4926 .dual_chip = true,
4927 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02004928 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02004929 .ops = &mv88e6250_ops,
4930 },
4931
Vivien Didelotf81ec902016-05-09 13:22:58 -04004932 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004933 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004934 .family = MV88E6XXX_FAMILY_6352,
4935 .name = "Marvell 88E6240",
4936 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004937 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004938 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004939 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004940 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004941 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004942 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004943 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004944 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004945 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004946 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004947 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004948 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004949 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004950 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004951 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004952 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004953 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004954 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004955 },
4956
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004957 [MV88E6250] = {
4958 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
4959 .family = MV88E6XXX_FAMILY_6250,
4960 .name = "Marvell 88E6250",
4961 .num_databases = 64,
4962 .num_ports = 7,
4963 .num_internal_phys = 5,
4964 .max_vid = 4095,
4965 .port_base_addr = 0x08,
4966 .phy_base_addr = 0x00,
4967 .global1_addr = 0x0f,
4968 .global2_addr = 0x07,
4969 .age_time_coeff = 15000,
4970 .g1_irqs = 9,
4971 .g2_irqs = 10,
4972 .atu_move_port_mask = 0xf,
4973 .dual_chip = true,
4974 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02004975 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004976 .ops = &mv88e6250_ops,
4977 },
4978
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004979 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004980 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004981 .family = MV88E6XXX_FAMILY_6390,
4982 .name = "Marvell 88E6290",
4983 .num_databases = 4096,
4984 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004985 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004986 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004987 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004988 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004989 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004990 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004991 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004992 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004993 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004994 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004995 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004996 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004997 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004998 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004999 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005000 .ops = &mv88e6290_ops,
5001 },
5002
Vivien Didelotf81ec902016-05-09 13:22:58 -04005003 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005004 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005005 .family = MV88E6XXX_FAMILY_6320,
5006 .name = "Marvell 88E6320",
5007 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005008 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005009 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005010 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005011 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005012 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005013 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005014 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005015 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005016 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005017 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005018 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005019 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005020 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005021 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005022 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005023 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005024 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005025 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005026 },
5027
5028 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005029 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005030 .family = MV88E6XXX_FAMILY_6320,
5031 .name = "Marvell 88E6321",
5032 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005033 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005034 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005035 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005036 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005037 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005038 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005039 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005040 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005041 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005042 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005043 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005044 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005045 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005046 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005047 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005048 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005049 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005050 },
5051
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005052 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005053 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005054 .family = MV88E6XXX_FAMILY_6341,
5055 .name = "Marvell 88E6341",
5056 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005057 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005058 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005059 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005060 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005061 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005062 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005063 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005064 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005065 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005066 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005067 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005068 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005069 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005070 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005071 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005072 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005073 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005074 .ops = &mv88e6341_ops,
5075 },
5076
Vivien Didelotf81ec902016-05-09 13:22:58 -04005077 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005078 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005079 .family = MV88E6XXX_FAMILY_6351,
5080 .name = "Marvell 88E6350",
5081 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005082 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005083 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005084 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005085 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005086 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005087 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005088 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005089 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005090 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005091 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005092 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005093 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005094 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005095 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005096 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005097 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005098 },
5099
5100 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005101 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005102 .family = MV88E6XXX_FAMILY_6351,
5103 .name = "Marvell 88E6351",
5104 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005105 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005106 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005107 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005108 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005109 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005110 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005111 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005112 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005113 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005114 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005115 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005116 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005117 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005118 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005119 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005120 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005121 },
5122
5123 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005124 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005125 .family = MV88E6XXX_FAMILY_6352,
5126 .name = "Marvell 88E6352",
5127 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005128 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005129 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005130 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005131 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005132 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005133 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005134 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005135 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005136 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005137 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005138 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005139 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005140 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005141 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005142 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005143 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005144 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005145 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005146 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005147 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005148 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005149 .family = MV88E6XXX_FAMILY_6390,
5150 .name = "Marvell 88E6390",
5151 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005152 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005153 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005154 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005155 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005156 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005157 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005158 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005159 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005160 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005161 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005162 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005163 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005164 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005165 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005166 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005167 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005168 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005169 .ops = &mv88e6390_ops,
5170 },
5171 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005172 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005173 .family = MV88E6XXX_FAMILY_6390,
5174 .name = "Marvell 88E6390X",
5175 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005176 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005177 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005178 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005179 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005180 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005181 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005182 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005183 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005184 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005185 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005186 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005187 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005188 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005189 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005190 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005191 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005192 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005193 .ops = &mv88e6390x_ops,
5194 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005195};
5196
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005197static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005198{
Vivien Didelota439c062016-04-17 13:23:58 -04005199 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005200
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005201 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5202 if (mv88e6xxx_table[i].prod_num == prod_num)
5203 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005204
Vivien Didelotb9b37712015-10-30 19:39:48 -04005205 return NULL;
5206}
5207
Vivien Didelotfad09c72016-06-21 12:28:20 -04005208static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005209{
5210 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005211 unsigned int prod_num, rev;
5212 u16 id;
5213 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005214
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005215 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005216 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005217 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005218 if (err)
5219 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005220
Vivien Didelot107fcc12017-06-12 12:37:36 -04005221 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5222 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005223
5224 info = mv88e6xxx_lookup_info(prod_num);
5225 if (!info)
5226 return -ENODEV;
5227
Vivien Didelotcaac8542016-06-20 13:14:09 -04005228 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005229 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005230
Vivien Didelotca070c12016-09-02 14:45:34 -04005231 err = mv88e6xxx_g2_require(chip);
5232 if (err)
5233 return err;
5234
Vivien Didelotfad09c72016-06-21 12:28:20 -04005235 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5236 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005237
5238 return 0;
5239}
5240
Vivien Didelotfad09c72016-06-21 12:28:20 -04005241static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005242{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005243 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005244
Vivien Didelotfad09c72016-06-21 12:28:20 -04005245 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5246 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005247 return NULL;
5248
Vivien Didelotfad09c72016-06-21 12:28:20 -04005249 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005250
Vivien Didelotfad09c72016-06-21 12:28:20 -04005251 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005252 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005253 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005254
Vivien Didelotfad09c72016-06-21 12:28:20 -04005255 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005256}
5257
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005258static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005259 int port,
5260 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005261{
Vivien Didelot04bed142016-08-31 18:06:13 -04005262 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005263
Andrew Lunn443d5a12016-12-03 04:35:18 +01005264 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005265}
5266
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005267static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
5268 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005269{
Vivien Didelot04bed142016-08-31 18:06:13 -04005270 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005271 int err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005272
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005273 mv88e6xxx_reg_lock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005274 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5275 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005276 mv88e6xxx_reg_unlock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005277
5278 return err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005279}
5280
5281static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5282 const struct switchdev_obj_port_mdb *mdb)
5283{
Vivien Didelot04bed142016-08-31 18:06:13 -04005284 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005285 int err;
5286
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005287 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005288 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005289 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005290
5291 return err;
5292}
5293
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005294static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5295 struct dsa_mall_mirror_tc_entry *mirror,
5296 bool ingress)
5297{
5298 enum mv88e6xxx_egress_direction direction = ingress ?
5299 MV88E6XXX_EGRESS_DIR_INGRESS :
5300 MV88E6XXX_EGRESS_DIR_EGRESS;
5301 struct mv88e6xxx_chip *chip = ds->priv;
5302 bool other_mirrors = false;
5303 int i;
5304 int err;
5305
5306 if (!chip->info->ops->set_egress_port)
5307 return -EOPNOTSUPP;
5308
5309 mutex_lock(&chip->reg_lock);
5310 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5311 mirror->to_local_port) {
5312 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5313 other_mirrors |= ingress ?
5314 chip->ports[i].mirror_ingress :
5315 chip->ports[i].mirror_egress;
5316
5317 /* Can't change egress port when other mirror is active */
5318 if (other_mirrors) {
5319 err = -EBUSY;
5320 goto out;
5321 }
5322
5323 err = chip->info->ops->set_egress_port(chip,
5324 direction,
5325 mirror->to_local_port);
5326 if (err)
5327 goto out;
5328 }
5329
5330 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5331out:
5332 mutex_unlock(&chip->reg_lock);
5333
5334 return err;
5335}
5336
5337static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5338 struct dsa_mall_mirror_tc_entry *mirror)
5339{
5340 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5341 MV88E6XXX_EGRESS_DIR_INGRESS :
5342 MV88E6XXX_EGRESS_DIR_EGRESS;
5343 struct mv88e6xxx_chip *chip = ds->priv;
5344 bool other_mirrors = false;
5345 int i;
5346
5347 mutex_lock(&chip->reg_lock);
5348 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5349 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5350
5351 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5352 other_mirrors |= mirror->ingress ?
5353 chip->ports[i].mirror_ingress :
5354 chip->ports[i].mirror_egress;
5355
5356 /* Reset egress port when no other mirror is active */
5357 if (!other_mirrors) {
5358 if (chip->info->ops->set_egress_port(chip,
5359 direction,
5360 dsa_upstream_port(ds,
Colin Ian King4e4637b2019-11-12 13:05:23 +00005361 port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005362 dev_err(ds->dev, "failed to set egress port\n");
5363 }
5364
5365 mutex_unlock(&chip->reg_lock);
5366}
5367
Russell King4f859012019-02-20 15:35:05 -08005368static int mv88e6xxx_port_egress_floods(struct dsa_switch *ds, int port,
5369 bool unicast, bool multicast)
5370{
5371 struct mv88e6xxx_chip *chip = ds->priv;
5372 int err = -EOPNOTSUPP;
5373
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005374 mv88e6xxx_reg_lock(chip);
Russell King4f859012019-02-20 15:35:05 -08005375 if (chip->info->ops->port_set_egress_floods)
5376 err = chip->info->ops->port_set_egress_floods(chip, port,
5377 unicast,
5378 multicast);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005379 mv88e6xxx_reg_unlock(chip);
Russell King4f859012019-02-20 15:35:05 -08005380
5381 return err;
5382}
5383
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005384static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
5385 struct net_device *lag,
5386 struct netdev_lag_upper_info *info)
5387{
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005388 struct mv88e6xxx_chip *chip = ds->priv;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005389 struct dsa_port *dp;
5390 int id, members = 0;
5391
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005392 if (!mv88e6xxx_has_lag(chip))
5393 return false;
5394
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005395 id = dsa_lag_id(ds->dst, lag);
5396 if (id < 0 || id >= ds->num_lag_ids)
5397 return false;
5398
5399 dsa_lag_foreach_port(dp, ds->dst, lag)
5400 /* Includes the port joining the LAG */
5401 members++;
5402
5403 if (members > 8)
5404 return false;
5405
5406 /* We could potentially relax this to include active
5407 * backup in the future.
5408 */
5409 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
5410 return false;
5411
5412 /* Ideally we would also validate that the hash type matches
5413 * the hardware. Alas, this is always set to unknown on team
5414 * interfaces.
5415 */
5416 return true;
5417}
5418
5419static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct net_device *lag)
5420{
5421 struct mv88e6xxx_chip *chip = ds->priv;
5422 struct dsa_port *dp;
5423 u16 map = 0;
5424 int id;
5425
5426 id = dsa_lag_id(ds->dst, lag);
5427
5428 /* Build the map of all ports to distribute flows destined for
5429 * this LAG. This can be either a local user port, or a DSA
5430 * port if the LAG port is on a remote chip.
5431 */
5432 dsa_lag_foreach_port(dp, ds->dst, lag)
5433 map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));
5434
5435 return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
5436}
5437
5438static const u8 mv88e6xxx_lag_mask_table[8][8] = {
5439 /* Row number corresponds to the number of active members in a
5440 * LAG. Each column states which of the eight hash buckets are
5441 * mapped to the column:th port in the LAG.
5442 *
5443 * Example: In a LAG with three active ports, the second port
5444 * ([2][1]) would be selected for traffic mapped to buckets
5445 * 3,4,5 (0x38).
5446 */
5447 { 0xff, 0, 0, 0, 0, 0, 0, 0 },
5448 { 0x0f, 0xf0, 0, 0, 0, 0, 0, 0 },
5449 { 0x07, 0x38, 0xc0, 0, 0, 0, 0, 0 },
5450 { 0x03, 0x0c, 0x30, 0xc0, 0, 0, 0, 0 },
5451 { 0x03, 0x0c, 0x30, 0x40, 0x80, 0, 0, 0 },
5452 { 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80, 0, 0 },
5453 { 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0 },
5454 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
5455};
5456
5457static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
5458 int num_tx, int nth)
5459{
5460 u8 active = 0;
5461 int i;
5462
5463 num_tx = num_tx <= 8 ? num_tx : 8;
5464 if (nth < num_tx)
5465 active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];
5466
5467 for (i = 0; i < 8; i++) {
5468 if (BIT(i) & active)
5469 mask[i] |= BIT(port);
5470 }
5471}
5472
5473static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
5474{
5475 struct mv88e6xxx_chip *chip = ds->priv;
5476 unsigned int id, num_tx;
5477 struct net_device *lag;
5478 struct dsa_port *dp;
5479 int i, err, nth;
5480 u16 mask[8];
5481 u16 ivec;
5482
5483 /* Assume no port is a member of any LAG. */
5484 ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;
5485
5486 /* Disable all masks for ports that _are_ members of a LAG. */
5487 list_for_each_entry(dp, &ds->dst->ports, list) {
5488 if (!dp->lag_dev || dp->ds != ds)
5489 continue;
5490
5491 ivec &= ~BIT(dp->index);
5492 }
5493
5494 for (i = 0; i < 8; i++)
5495 mask[i] = ivec;
5496
5497 /* Enable the correct subset of masks for all LAG ports that
5498 * are in the Tx set.
5499 */
5500 dsa_lags_foreach_id(id, ds->dst) {
5501 lag = dsa_lag_dev(ds->dst, id);
5502 if (!lag)
5503 continue;
5504
5505 num_tx = 0;
5506 dsa_lag_foreach_port(dp, ds->dst, lag) {
5507 if (dp->lag_tx_enabled)
5508 num_tx++;
5509 }
5510
5511 if (!num_tx)
5512 continue;
5513
5514 nth = 0;
5515 dsa_lag_foreach_port(dp, ds->dst, lag) {
5516 if (!dp->lag_tx_enabled)
5517 continue;
5518
5519 if (dp->ds == ds)
5520 mv88e6xxx_lag_set_port_mask(mask, dp->index,
5521 num_tx, nth);
5522
5523 nth++;
5524 }
5525 }
5526
5527 for (i = 0; i < 8; i++) {
5528 err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
5529 if (err)
5530 return err;
5531 }
5532
5533 return 0;
5534}
5535
5536static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
5537 struct net_device *lag)
5538{
5539 int err;
5540
5541 err = mv88e6xxx_lag_sync_masks(ds);
5542
5543 if (!err)
5544 err = mv88e6xxx_lag_sync_map(ds, lag);
5545
5546 return err;
5547}
5548
5549static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port)
5550{
5551 struct mv88e6xxx_chip *chip = ds->priv;
5552 int err;
5553
5554 mv88e6xxx_reg_lock(chip);
5555 err = mv88e6xxx_lag_sync_masks(ds);
5556 mv88e6xxx_reg_unlock(chip);
5557 return err;
5558}
5559
5560static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
5561 struct net_device *lag,
5562 struct netdev_lag_upper_info *info)
5563{
5564 struct mv88e6xxx_chip *chip = ds->priv;
5565 int err, id;
5566
5567 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
5568 return -EOPNOTSUPP;
5569
5570 id = dsa_lag_id(ds->dst, lag);
5571
5572 mv88e6xxx_reg_lock(chip);
5573
5574 err = mv88e6xxx_port_set_trunk(chip, port, true, id);
5575 if (err)
5576 goto err_unlock;
5577
5578 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
5579 if (err)
5580 goto err_clear_trunk;
5581
5582 mv88e6xxx_reg_unlock(chip);
5583 return 0;
5584
5585err_clear_trunk:
5586 mv88e6xxx_port_set_trunk(chip, port, false, 0);
5587err_unlock:
5588 mv88e6xxx_reg_unlock(chip);
5589 return err;
5590}
5591
5592static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
5593 struct net_device *lag)
5594{
5595 struct mv88e6xxx_chip *chip = ds->priv;
5596 int err_sync, err_trunk;
5597
5598 mv88e6xxx_reg_lock(chip);
5599 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
5600 err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
5601 mv88e6xxx_reg_unlock(chip);
5602 return err_sync ? : err_trunk;
5603}
5604
5605static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
5606 int port)
5607{
5608 struct mv88e6xxx_chip *chip = ds->priv;
5609 int err;
5610
5611 mv88e6xxx_reg_lock(chip);
5612 err = mv88e6xxx_lag_sync_masks(ds);
5613 mv88e6xxx_reg_unlock(chip);
5614 return err;
5615}
5616
5617static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
5618 int port, struct net_device *lag,
5619 struct netdev_lag_upper_info *info)
5620{
5621 struct mv88e6xxx_chip *chip = ds->priv;
5622 int err;
5623
5624 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
5625 return -EOPNOTSUPP;
5626
5627 mv88e6xxx_reg_lock(chip);
5628
5629 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
5630 if (err)
5631 goto unlock;
5632
5633 err = mv88e6xxx_pvt_map(chip, sw_index, port);
5634
5635unlock:
5636 mv88e6xxx_reg_unlock(chip);
5637 return err;
5638}
5639
5640static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
5641 int port, struct net_device *lag)
5642{
5643 struct mv88e6xxx_chip *chip = ds->priv;
5644 int err_sync, err_pvt;
5645
5646 mv88e6xxx_reg_lock(chip);
5647 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
5648 err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
5649 mv88e6xxx_reg_unlock(chip);
5650 return err_sync ? : err_pvt;
5651}
5652
Florian Fainellia82f67a2017-01-08 14:52:08 -08005653static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02005654 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005655 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005656 .teardown = mv88e6xxx_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07005657 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00005658 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07005659 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00005660 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07005661 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
5662 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005663 .get_strings = mv88e6xxx_get_strings,
5664 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
5665 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02005666 .port_enable = mv88e6xxx_port_enable,
5667 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02005668 .port_max_mtu = mv88e6xxx_get_max_mtu,
5669 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04005670 .get_mac_eee = mv88e6xxx_get_mac_eee,
5671 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005672 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005673 .get_eeprom = mv88e6xxx_get_eeprom,
5674 .set_eeprom = mv88e6xxx_set_eeprom,
5675 .get_regs_len = mv88e6xxx_get_regs_len,
5676 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04005677 .get_rxnfc = mv88e6xxx_get_rxnfc,
5678 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04005679 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005680 .port_bridge_join = mv88e6xxx_port_bridge_join,
5681 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Russell King4f859012019-02-20 15:35:05 -08005682 .port_egress_floods = mv88e6xxx_port_egress_floods,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005683 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04005684 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005685 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005686 .port_vlan_add = mv88e6xxx_port_vlan_add,
5687 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005688 .port_fdb_add = mv88e6xxx_port_fdb_add,
5689 .port_fdb_del = mv88e6xxx_port_fdb_del,
5690 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005691 .port_mdb_add = mv88e6xxx_port_mdb_add,
5692 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005693 .port_mirror_add = mv88e6xxx_port_mirror_add,
5694 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04005695 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
5696 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005697 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
5698 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
5699 .port_txtstamp = mv88e6xxx_port_txtstamp,
5700 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
5701 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005702 .devlink_param_get = mv88e6xxx_devlink_param_get,
5703 .devlink_param_set = mv88e6xxx_devlink_param_set,
Andrew Lunn93157302020-09-18 21:11:09 +02005704 .devlink_info_get = mv88e6xxx_devlink_info_get,
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005705 .port_lag_change = mv88e6xxx_port_lag_change,
5706 .port_lag_join = mv88e6xxx_port_lag_join,
5707 .port_lag_leave = mv88e6xxx_port_lag_leave,
5708 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
5709 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
5710 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005711};
5712
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005713static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005714{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005715 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005716 struct dsa_switch *ds;
5717
Vivien Didelot7e99e342019-10-21 16:51:30 -04005718 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005719 if (!ds)
5720 return -ENOMEM;
5721
Vivien Didelot7e99e342019-10-21 16:51:30 -04005722 ds->dev = dev;
5723 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005724 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005725 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04005726 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04005727 ds->ageing_time_min = chip->info->age_time_coeff;
5728 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005729
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005730 /* Some chips support up to 32, but that requires enabling the
5731 * 5-bit port mode, which we do not support. 640k^W16 ought to
5732 * be enough for anyone.
5733 */
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005734 ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005735
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005736 dev_set_drvdata(dev, ds);
5737
Vivien Didelot23c9ee42017-05-26 18:12:51 -04005738 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005739}
5740
Vivien Didelotfad09c72016-06-21 12:28:20 -04005741static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005742{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005743 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005744}
5745
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005746static const void *pdata_device_get_match_data(struct device *dev)
5747{
5748 const struct of_device_id *matches = dev->driver->of_match_table;
5749 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
5750
5751 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
5752 matches++) {
5753 if (!strcmp(pdata->compatible, matches->compatible))
5754 return matches->data;
5755 }
5756 return NULL;
5757}
5758
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005759/* There is no suspend to RAM support at DSA level yet, the switch configuration
5760 * would be lost after a power cycle so prevent it to be suspended.
5761 */
5762static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
5763{
5764 return -EOPNOTSUPP;
5765}
5766
5767static int __maybe_unused mv88e6xxx_resume(struct device *dev)
5768{
5769 return 0;
5770}
5771
5772static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
5773
Vivien Didelot57d32312016-06-20 13:13:58 -04005774static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005775{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005776 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04005777 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005778 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005779 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04005780 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005781 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02005782 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005783
Andrew Lunn7bb8c992018-05-31 00:15:42 +02005784 if (!np && !pdata)
5785 return -EINVAL;
5786
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005787 if (np)
5788 compat_info = of_device_get_match_data(dev);
5789
5790 if (pdata) {
5791 compat_info = pdata_device_get_match_data(dev);
5792
5793 if (!pdata->netdev)
5794 return -EINVAL;
5795
5796 for (port = 0; port < DSA_MAX_PORTS; port++) {
5797 if (!(pdata->enabled_ports & (1 << port)))
5798 continue;
5799 if (strcmp(pdata->cd.port_names[port], "cpu"))
5800 continue;
5801 pdata->cd.netdev[port] = &pdata->netdev->dev;
5802 break;
5803 }
5804 }
5805
Vivien Didelotcaac8542016-06-20 13:14:09 -04005806 if (!compat_info)
5807 return -EINVAL;
5808
Vivien Didelotfad09c72016-06-21 12:28:20 -04005809 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005810 if (!chip) {
5811 err = -ENOMEM;
5812 goto out;
5813 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005814
Vivien Didelotfad09c72016-06-21 12:28:20 -04005815 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04005816
Vivien Didelotfad09c72016-06-21 12:28:20 -04005817 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04005818 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005819 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005820
Andrew Lunnb4308f02016-11-21 23:26:55 +01005821 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005822 if (IS_ERR(chip->reset)) {
5823 err = PTR_ERR(chip->reset);
5824 goto out;
5825 }
Baruch Siach7b75e492019-06-27 21:17:39 +03005826 if (chip->reset)
5827 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01005828
Vivien Didelotfad09c72016-06-21 12:28:20 -04005829 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005830 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005831 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005832
Vivien Didelote57e5e72016-08-15 17:19:00 -04005833 mv88e6xxx_phy_init(chip);
5834
Andrew Lunn00baabe2018-05-19 22:31:35 +02005835 if (chip->info->ops->get_eeprom) {
5836 if (np)
5837 of_property_read_u32(np, "eeprom-length",
5838 &chip->eeprom_len);
5839 else
5840 chip->eeprom_len = pdata->eeprom_len;
5841 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005842
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005843 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005844 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005845 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02005846 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02005847 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02005848
Andrew Lunna27415d2019-05-01 00:10:50 +02005849 if (np) {
5850 chip->irq = of_irq_get(np, 0);
5851 if (chip->irq == -EPROBE_DEFER) {
5852 err = chip->irq;
5853 goto out;
5854 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02005855 }
5856
Andrew Lunna27415d2019-05-01 00:10:50 +02005857 if (pdata)
5858 chip->irq = pdata->irq;
5859
Andrew Lunn294d7112018-02-22 22:58:32 +01005860 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01005861 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01005862 * controllers
5863 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005864 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005865 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005866 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005867 else
5868 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005869 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005870
Andrew Lunn294d7112018-02-22 22:58:32 +01005871 if (err)
5872 goto out;
5873
5874 if (chip->info->g2_irqs > 0) {
5875 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005876 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01005877 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005878 }
5879
Andrew Lunn294d7112018-02-22 22:58:32 +01005880 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
5881 if (err)
5882 goto out_g2_irq;
5883
5884 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
5885 if (err)
5886 goto out_g1_atu_prob_irq;
5887
Andrew Lunna3c53be52017-01-24 14:53:50 +01005888 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02005889 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01005890 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005891
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005892 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005893 if (err)
5894 goto out_mdio;
5895
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005896 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02005897
5898out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01005899 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01005900out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005901 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01005902out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005903 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005904out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005905 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005906 mv88e6xxx_g2_irq_free(chip);
5907out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005908 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005909 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005910 else
5911 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005912out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005913 if (pdata)
5914 dev_put(pdata->netdev);
5915
Andrew Lunndc30c352016-10-16 19:56:49 +02005916 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005917}
5918
5919static void mv88e6xxx_remove(struct mdio_device *mdiodev)
5920{
5921 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04005922 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005923
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005924 if (chip->info->ptp_support) {
5925 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005926 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005927 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005928
Andrew Lunn930188c2016-08-22 16:01:03 +02005929 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005930 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005931 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005932
Andrew Lunn76f38f12018-03-17 20:21:09 +01005933 mv88e6xxx_g1_vtu_prob_irq_free(chip);
5934 mv88e6xxx_g1_atu_prob_irq_free(chip);
5935
5936 if (chip->info->g2_irqs > 0)
5937 mv88e6xxx_g2_irq_free(chip);
5938
Andrew Lunn76f38f12018-03-17 20:21:09 +01005939 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005940 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01005941 else
5942 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005943}
5944
5945static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04005946 {
5947 .compatible = "marvell,mv88e6085",
5948 .data = &mv88e6xxx_table[MV88E6085],
5949 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005950 {
5951 .compatible = "marvell,mv88e6190",
5952 .data = &mv88e6xxx_table[MV88E6190],
5953 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005954 {
5955 .compatible = "marvell,mv88e6250",
5956 .data = &mv88e6xxx_table[MV88E6250],
5957 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005958 { /* sentinel */ },
5959};
5960
5961MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
5962
5963static struct mdio_driver mv88e6xxx_driver = {
5964 .probe = mv88e6xxx_probe,
5965 .remove = mv88e6xxx_remove,
5966 .mdiodrv.driver = {
5967 .name = "mv88e6085",
5968 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005969 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005970 },
5971};
5972
Andrew Lunn7324d502019-04-27 19:19:10 +02005973mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00005974
5975MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
5976MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
5977MODULE_LICENSE("GPL");