blob: 984bdcaff1eae5f696813dbfaa72075530335712 [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) ||
730 mode == MLO_AN_FIXED) && ops->port_set_link)
Russell King30c4a5b2020-02-26 10:23:51 +0000731 err = ops->port_set_link(chip, port, LINK_FORCED_DOWN);
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
771 if (ops->port_set_link)
772 err = ops->port_set_link(chip, port, LINK_FORCED_UP);
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
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001350 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1351 if (err)
1352 return err;
1353
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001354 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1355}
1356
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001357static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1358{
1359 int port;
1360 int err;
1361
1362 if (!chip->info->ops->irl_init_all)
1363 return 0;
1364
1365 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1366 /* Disable ingress rate limiting by resetting all per port
1367 * ingress rate limit resources to their initial state.
1368 */
1369 err = chip->info->ops->irl_init_all(chip, port);
1370 if (err)
1371 return err;
1372 }
1373
1374 return 0;
1375}
1376
Vivien Didelot04a69a12017-10-13 14:18:05 -04001377static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1378{
1379 if (chip->info->ops->set_switch_mac) {
1380 u8 addr[ETH_ALEN];
1381
1382 eth_random_addr(addr);
1383
1384 return chip->info->ops->set_switch_mac(chip, addr);
1385 }
1386
1387 return 0;
1388}
1389
Vivien Didelot17a15942017-03-30 17:37:09 -04001390static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1391{
1392 u16 pvlan = 0;
1393
1394 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001395 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001396
1397 /* Skip the local source device, which uses in-chip port VLAN */
1398 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001399 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001400
1401 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1402}
1403
Vivien Didelot81228992017-03-30 17:37:08 -04001404static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1405{
Vivien Didelot17a15942017-03-30 17:37:09 -04001406 int dev, port;
1407 int err;
1408
Vivien Didelot81228992017-03-30 17:37:08 -04001409 if (!mv88e6xxx_has_pvt(chip))
1410 return 0;
1411
1412 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1413 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1414 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001415 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1416 if (err)
1417 return err;
1418
1419 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1420 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1421 err = mv88e6xxx_pvt_map(chip, dev, port);
1422 if (err)
1423 return err;
1424 }
1425 }
1426
1427 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001428}
1429
Vivien Didelot749efcb2016-09-22 16:49:24 -04001430static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1431{
1432 struct mv88e6xxx_chip *chip = ds->priv;
1433 int err;
1434
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001435 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001436 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001437 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001438
1439 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001440 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001441}
1442
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001443static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1444{
1445 if (!chip->info->max_vid)
1446 return 0;
1447
1448 return mv88e6xxx_g1_vtu_flush(chip);
1449}
1450
Vivien Didelotf1394b782017-05-01 14:05:22 -04001451static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1452 struct mv88e6xxx_vtu_entry *entry)
1453{
1454 if (!chip->info->ops->vtu_getnext)
1455 return -EOPNOTSUPP;
1456
1457 return chip->info->ops->vtu_getnext(chip, entry);
1458}
1459
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001460static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1461 struct mv88e6xxx_vtu_entry *entry)
1462{
1463 if (!chip->info->ops->vtu_loadpurge)
1464 return -EOPNOTSUPP;
1465
1466 return chip->info->ops->vtu_loadpurge(chip, entry);
1467}
1468
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001469static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001470{
1471 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot425d2d32019-08-01 14:36:34 -04001472 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001473 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001474
1475 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1476
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001477 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001478 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001479 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001480 if (err)
1481 return err;
1482
1483 set_bit(*fid, fid_bitmap);
1484 }
1485
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001486 /* Set every FID bit used by the VLAN entries */
Vivien Didelot425d2d32019-08-01 14:36:34 -04001487 vlan.vid = chip->info->max_vid;
1488 vlan.valid = false;
1489
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001490 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001491 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001492 if (err)
1493 return err;
1494
1495 if (!vlan.valid)
1496 break;
1497
1498 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001499 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001500
1501 /* The reset value 0x000 is used to indicate that multiple address
1502 * databases are not needed. Return the next positive available.
1503 */
1504 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001505 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001506 return -ENOSPC;
1507
1508 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001509 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001510}
1511
Vivien Didelotda9c3592016-02-12 12:09:40 -05001512static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1513 u16 vid_begin, u16 vid_end)
1514{
Vivien Didelot04bed142016-08-31 18:06:13 -04001515 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001516 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001517 int i, err;
1518
Andrew Lunndb06ae412017-09-25 23:32:20 +02001519 /* DSA and CPU ports have to be members of multiple vlans */
1520 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1521 return 0;
1522
Vivien Didelotda9c3592016-02-12 12:09:40 -05001523 if (!vid_begin)
1524 return -EOPNOTSUPP;
1525
Vivien Didelot425d2d32019-08-01 14:36:34 -04001526 vlan.vid = vid_begin - 1;
1527 vlan.valid = false;
1528
Vivien Didelotda9c3592016-02-12 12:09:40 -05001529 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001530 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001531 if (err)
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001532 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001533
1534 if (!vlan.valid)
1535 break;
1536
1537 if (vlan.vid > vid_end)
1538 break;
1539
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001540 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001541 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1542 continue;
1543
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001544 if (!dsa_to_port(ds, i)->slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001545 continue;
1546
Vivien Didelotbd00e052017-05-01 14:05:11 -04001547 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001548 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001549 continue;
1550
Vivien Didelotc8652c82017-10-16 11:12:19 -04001551 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001552 dsa_to_port(ds, port)->bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001553 break; /* same bridge, check next VLAN */
1554
Vivien Didelotc8652c82017-10-16 11:12:19 -04001555 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001556 continue;
1557
Andrew Lunn743fcc22017-11-09 22:29:54 +01001558 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1559 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001560 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001561 return -EOPNOTSUPP;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001562 }
1563 } while (vlan.vid < vid_end);
1564
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001565 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001566}
1567
Vivien Didelotf81ec902016-05-09 13:22:58 -04001568static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1569 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001570{
Vivien Didelot04bed142016-08-31 18:06:13 -04001571 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001572 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1573 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001574 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001575
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001576 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001577 return -EOPNOTSUPP;
1578
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001579 mv88e6xxx_reg_lock(chip);
Vivien Didelot385a0992016-11-04 03:23:31 +01001580 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001581 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001582
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001583 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001584}
1585
Vivien Didelot57d32312016-06-20 13:13:58 -04001586static int
1587mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001588 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001589{
Vivien Didelot04bed142016-08-31 18:06:13 -04001590 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001591 int err;
1592
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001593 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001594 return -EOPNOTSUPP;
1595
Vivien Didelotda9c3592016-02-12 12:09:40 -05001596 /* If the requested port doesn't belong to the same bridge as the VLAN
1597 * members, do not support it (yet) and fallback to software VLAN.
1598 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001599 mv88e6xxx_reg_lock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001600 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1601 vlan->vid_end);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001602 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001603
Vivien Didelot76e398a2015-11-01 12:33:55 -05001604 /* We don't need any dynamic resource from the kernel (yet),
1605 * so skip the prepare phase.
1606 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001607 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001608}
1609
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001610static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1611 const unsigned char *addr, u16 vid,
1612 u8 state)
1613{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001614 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001615 struct mv88e6xxx_vtu_entry vlan;
1616 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001617 int err;
1618
1619 /* Null VLAN ID corresponds to the port private database */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001620 if (vid == 0) {
1621 err = mv88e6xxx_port_get_fid(chip, port, &fid);
1622 if (err)
1623 return err;
1624 } else {
1625 vlan.vid = vid - 1;
1626 vlan.valid = false;
1627
1628 err = mv88e6xxx_vtu_getnext(chip, &vlan);
1629 if (err)
1630 return err;
1631
1632 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1633 if (vlan.vid != vid || !vlan.valid)
1634 return -EOPNOTSUPP;
1635
1636 fid = vlan.fid;
1637 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001638
Vivien Didelotd8291a92019-09-07 16:00:47 -04001639 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001640 ether_addr_copy(entry.mac, addr);
1641 eth_addr_dec(entry.mac);
1642
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001643 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001644 if (err)
1645 return err;
1646
1647 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001648 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001649 memset(&entry, 0, sizeof(entry));
1650 ether_addr_copy(entry.mac, addr);
1651 }
1652
1653 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001654 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001655 entry.portvec &= ~BIT(port);
1656 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001657 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001658 } else {
1659 entry.portvec |= BIT(port);
1660 entry.state = state;
1661 }
1662
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001663 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001664}
1665
Vivien Didelotda7dc872019-09-07 16:00:49 -04001666static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1667 const struct mv88e6xxx_policy *policy)
1668{
1669 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1670 enum mv88e6xxx_policy_action action = policy->action;
1671 const u8 *addr = policy->addr;
1672 u16 vid = policy->vid;
1673 u8 state;
1674 int err;
1675 int id;
1676
1677 if (!chip->info->ops->port_set_policy)
1678 return -EOPNOTSUPP;
1679
1680 switch (mapping) {
1681 case MV88E6XXX_POLICY_MAPPING_DA:
1682 case MV88E6XXX_POLICY_MAPPING_SA:
1683 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1684 state = 0; /* Dissociate the port and address */
1685 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1686 is_multicast_ether_addr(addr))
1687 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1688 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1689 is_unicast_ether_addr(addr))
1690 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1691 else
1692 return -EOPNOTSUPP;
1693
1694 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1695 state);
1696 if (err)
1697 return err;
1698 break;
1699 default:
1700 return -EOPNOTSUPP;
1701 }
1702
1703 /* Skip the port's policy clearing if the mapping is still in use */
1704 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1705 idr_for_each_entry(&chip->policies, policy, id)
1706 if (policy->port == port &&
1707 policy->mapping == mapping &&
1708 policy->action != action)
1709 return 0;
1710
1711 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1712}
1713
1714static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1715 struct ethtool_rx_flow_spec *fs)
1716{
1717 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1718 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1719 enum mv88e6xxx_policy_mapping mapping;
1720 enum mv88e6xxx_policy_action action;
1721 struct mv88e6xxx_policy *policy;
1722 u16 vid = 0;
1723 u8 *addr;
1724 int err;
1725 int id;
1726
1727 if (fs->location != RX_CLS_LOC_ANY)
1728 return -EINVAL;
1729
1730 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1731 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1732 else
1733 return -EOPNOTSUPP;
1734
1735 switch (fs->flow_type & ~FLOW_EXT) {
1736 case ETHER_FLOW:
1737 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1738 is_zero_ether_addr(mac_mask->h_source)) {
1739 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1740 addr = mac_entry->h_dest;
1741 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1742 !is_zero_ether_addr(mac_mask->h_source)) {
1743 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1744 addr = mac_entry->h_source;
1745 } else {
1746 /* Cannot support DA and SA mapping in the same rule */
1747 return -EOPNOTSUPP;
1748 }
1749 break;
1750 default:
1751 return -EOPNOTSUPP;
1752 }
1753
1754 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001755 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001756 return -EOPNOTSUPP;
1757 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1758 }
1759
1760 idr_for_each_entry(&chip->policies, policy, id) {
1761 if (policy->port == port && policy->mapping == mapping &&
1762 policy->action == action && policy->vid == vid &&
1763 ether_addr_equal(policy->addr, addr))
1764 return -EEXIST;
1765 }
1766
1767 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1768 if (!policy)
1769 return -ENOMEM;
1770
1771 fs->location = 0;
1772 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1773 GFP_KERNEL);
1774 if (err) {
1775 devm_kfree(chip->dev, policy);
1776 return err;
1777 }
1778
1779 memcpy(&policy->fs, fs, sizeof(*fs));
1780 ether_addr_copy(policy->addr, addr);
1781 policy->mapping = mapping;
1782 policy->action = action;
1783 policy->port = port;
1784 policy->vid = vid;
1785
1786 err = mv88e6xxx_policy_apply(chip, port, policy);
1787 if (err) {
1788 idr_remove(&chip->policies, fs->location);
1789 devm_kfree(chip->dev, policy);
1790 return err;
1791 }
1792
1793 return 0;
1794}
1795
1796static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1797 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1798{
1799 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1800 struct mv88e6xxx_chip *chip = ds->priv;
1801 struct mv88e6xxx_policy *policy;
1802 int err;
1803 int id;
1804
1805 mv88e6xxx_reg_lock(chip);
1806
1807 switch (rxnfc->cmd) {
1808 case ETHTOOL_GRXCLSRLCNT:
1809 rxnfc->data = 0;
1810 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1811 rxnfc->rule_cnt = 0;
1812 idr_for_each_entry(&chip->policies, policy, id)
1813 if (policy->port == port)
1814 rxnfc->rule_cnt++;
1815 err = 0;
1816 break;
1817 case ETHTOOL_GRXCLSRULE:
1818 err = -ENOENT;
1819 policy = idr_find(&chip->policies, fs->location);
1820 if (policy) {
1821 memcpy(fs, &policy->fs, sizeof(*fs));
1822 err = 0;
1823 }
1824 break;
1825 case ETHTOOL_GRXCLSRLALL:
1826 rxnfc->data = 0;
1827 rxnfc->rule_cnt = 0;
1828 idr_for_each_entry(&chip->policies, policy, id)
1829 if (policy->port == port)
1830 rule_locs[rxnfc->rule_cnt++] = id;
1831 err = 0;
1832 break;
1833 default:
1834 err = -EOPNOTSUPP;
1835 break;
1836 }
1837
1838 mv88e6xxx_reg_unlock(chip);
1839
1840 return err;
1841}
1842
1843static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1844 struct ethtool_rxnfc *rxnfc)
1845{
1846 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1847 struct mv88e6xxx_chip *chip = ds->priv;
1848 struct mv88e6xxx_policy *policy;
1849 int err;
1850
1851 mv88e6xxx_reg_lock(chip);
1852
1853 switch (rxnfc->cmd) {
1854 case ETHTOOL_SRXCLSRLINS:
1855 err = mv88e6xxx_policy_insert(chip, port, fs);
1856 break;
1857 case ETHTOOL_SRXCLSRLDEL:
1858 err = -ENOENT;
1859 policy = idr_remove(&chip->policies, fs->location);
1860 if (policy) {
1861 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
1862 err = mv88e6xxx_policy_apply(chip, port, policy);
1863 devm_kfree(chip->dev, policy);
1864 }
1865 break;
1866 default:
1867 err = -EOPNOTSUPP;
1868 break;
1869 }
1870
1871 mv88e6xxx_reg_unlock(chip);
1872
1873 return err;
1874}
1875
Andrew Lunn87fa8862017-11-09 22:29:56 +01001876static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1877 u16 vid)
1878{
1879 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1880 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1881
1882 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1883}
1884
1885static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1886{
1887 int port;
1888 int err;
1889
1890 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1891 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1892 if (err)
1893 return err;
1894 }
1895
1896 return 0;
1897}
1898
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001899static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00001900 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001901{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001902 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001903 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001904 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001905
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001906 if (!vid)
1907 return -EOPNOTSUPP;
1908
1909 vlan.vid = vid - 1;
1910 vlan.valid = false;
1911
1912 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001913 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001914 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001915
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001916 if (vlan.vid != vid || !vlan.valid) {
1917 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001918
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001919 err = mv88e6xxx_atu_new(chip, &vlan.fid);
1920 if (err)
1921 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01001922
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001923 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1924 if (i == port)
1925 vlan.member[i] = member;
1926 else
1927 vlan.member[i] = non_member;
1928
1929 vlan.vid = vid;
1930 vlan.valid = true;
1931
1932 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1933 if (err)
1934 return err;
1935
1936 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
1937 if (err)
1938 return err;
1939 } else if (vlan.member[port] != member) {
1940 vlan.member[port] = member;
1941
1942 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1943 if (err)
1944 return err;
Russell King933b4422020-02-26 17:14:26 +00001945 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001946 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
1947 port, vid);
1948 }
1949
1950 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001951}
1952
Vivien Didelotf81ec902016-05-09 13:22:58 -04001953static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001954 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001955{
Vivien Didelot04bed142016-08-31 18:06:13 -04001956 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001957 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1958 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Russell King933b4422020-02-26 17:14:26 +00001959 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001960 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001961 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001962
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001963 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001964 return;
1965
Vivien Didelotc91498e2017-06-07 18:12:13 -04001966 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001967 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001968 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001969 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001970 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001971 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001972
Russell King933b4422020-02-26 17:14:26 +00001973 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
1974 * and then the CPU port. Do not warn for duplicates for the CPU port.
1975 */
1976 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
1977
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001978 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001979
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001980 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Russell King933b4422020-02-26 17:14:26 +00001981 if (mv88e6xxx_port_vlan_join(chip, port, vid, member, warn))
Vivien Didelot774439e52017-06-08 18:34:08 -04001982 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1983 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001984
Vivien Didelot77064f32016-11-04 03:23:30 +01001985 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001986 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1987 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001988
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001989 mv88e6xxx_reg_unlock(chip);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001990}
1991
Vivien Didelot521098922019-08-01 14:36:36 -04001992static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
1993 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001994{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001995 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001996 int i, err;
1997
Vivien Didelot521098922019-08-01 14:36:36 -04001998 if (!vid)
1999 return -EOPNOTSUPP;
2000
2001 vlan.vid = vid - 1;
2002 vlan.valid = false;
2003
2004 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002005 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002006 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002007
Vivien Didelot521098922019-08-01 14:36:36 -04002008 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2009 * tell switchdev that this VLAN is likely handled in software.
2010 */
2011 if (vlan.vid != vid || !vlan.valid ||
2012 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002013 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002014
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002015 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002016
2017 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002018 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002019 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002020 if (vlan.member[i] !=
2021 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002022 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002023 break;
2024 }
2025 }
2026
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002027 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002028 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002029 return err;
2030
Vivien Didelote606ca32017-03-11 16:12:55 -05002031 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002032}
2033
Vivien Didelotf81ec902016-05-09 13:22:58 -04002034static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2035 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002036{
Vivien Didelot04bed142016-08-31 18:06:13 -04002037 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002038 u16 pvid, vid;
2039 int err = 0;
2040
Vivien Didelot3cf3c842017-05-01 14:05:10 -04002041 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04002042 return -EOPNOTSUPP;
2043
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002044 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002045
Vivien Didelot77064f32016-11-04 03:23:30 +01002046 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002047 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002048 goto unlock;
2049
Vivien Didelot76e398a2015-11-01 12:33:55 -05002050 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelot521098922019-08-01 14:36:36 -04002051 err = mv88e6xxx_port_vlan_leave(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002052 if (err)
2053 goto unlock;
2054
2055 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01002056 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002057 if (err)
2058 goto unlock;
2059 }
2060 }
2061
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002062unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002063 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002064
2065 return err;
2066}
2067
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002068static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2069 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002070{
Vivien Didelot04bed142016-08-31 18:06:13 -04002071 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002072 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002073
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002074 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002075 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2076 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002077 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002078
2079 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002080}
2081
Vivien Didelotf81ec902016-05-09 13:22:58 -04002082static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002083 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002084{
Vivien Didelot04bed142016-08-31 18:06:13 -04002085 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002086 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002087
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002088 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002089 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002090 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002091
Vivien Didelot83dabd12016-08-31 11:50:04 -04002092 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002093}
2094
Vivien Didelot83dabd12016-08-31 11:50:04 -04002095static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2096 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002097 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002098{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002099 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002100 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002101 int err;
2102
Vivien Didelotd8291a92019-09-07 16:00:47 -04002103 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002104 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002105
2106 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002107 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002108 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002109 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002110
Vivien Didelotd8291a92019-09-07 16:00:47 -04002111 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002112 break;
2113
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002114 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002115 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002116
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002117 if (!is_unicast_ether_addr(addr.mac))
2118 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002119
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002120 is_static = (addr.state ==
2121 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2122 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002123 if (err)
2124 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002125 } while (!is_broadcast_ether_addr(addr.mac));
2126
2127 return err;
2128}
2129
Vivien Didelot83dabd12016-08-31 11:50:04 -04002130static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002131 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002132{
Vivien Didelot425d2d32019-08-01 14:36:34 -04002133 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002134 u16 fid;
2135 int err;
2136
2137 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002138 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002139 if (err)
2140 return err;
2141
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002142 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002143 if (err)
2144 return err;
2145
2146 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot425d2d32019-08-01 14:36:34 -04002147 vlan.vid = chip->info->max_vid;
2148 vlan.valid = false;
2149
Vivien Didelot83dabd12016-08-31 11:50:04 -04002150 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04002151 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002152 if (err)
2153 return err;
2154
2155 if (!vlan.valid)
2156 break;
2157
2158 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002159 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002160 if (err)
2161 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04002162 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002163
2164 return err;
2165}
2166
Vivien Didelotf81ec902016-05-09 13:22:58 -04002167static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002168 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002169{
Vivien Didelot04bed142016-08-31 18:06:13 -04002170 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002171 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002172
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002173 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002174 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002175 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002176
2177 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002178}
2179
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002180static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2181 struct net_device *br)
2182{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002183 struct dsa_switch *ds = chip->ds;
2184 struct dsa_switch_tree *dst = ds->dst;
2185 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002186 int err;
2187
Vivien Didelotef2025e2019-10-21 16:51:27 -04002188 list_for_each_entry(dp, &dst->ports, list) {
2189 if (dp->bridge_dev == br) {
2190 if (dp->ds == ds) {
2191 /* This is a local bridge group member,
2192 * remap its Port VLAN Map.
2193 */
2194 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2195 if (err)
2196 return err;
2197 } else {
2198 /* This is an external bridge group member,
2199 * remap its cross-chip Port VLAN Table entry.
2200 */
2201 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2202 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002203 if (err)
2204 return err;
2205 }
2206 }
2207 }
2208
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002209 return 0;
2210}
2211
Vivien Didelotf81ec902016-05-09 13:22:58 -04002212static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002213 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002214{
Vivien Didelot04bed142016-08-31 18:06:13 -04002215 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002216 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002217
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002218 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002219 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002220 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002221
Vivien Didelot466dfa02016-02-26 13:16:05 -05002222 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002223}
2224
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002225static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2226 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002227{
Vivien Didelot04bed142016-08-31 18:06:13 -04002228 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002229
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002230 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002231 if (mv88e6xxx_bridge_map(chip, br) ||
2232 mv88e6xxx_port_vlan_map(chip, port))
2233 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002234 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002235}
2236
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002237static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2238 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002239 int port, struct net_device *br)
2240{
2241 struct mv88e6xxx_chip *chip = ds->priv;
2242 int err;
2243
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002244 if (tree_index != ds->dst->index)
2245 return 0;
2246
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002247 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002248 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002249 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002250
2251 return err;
2252}
2253
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002254static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2255 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002256 int port, struct net_device *br)
2257{
2258 struct mv88e6xxx_chip *chip = ds->priv;
2259
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002260 if (tree_index != ds->dst->index)
2261 return;
2262
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002263 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002264 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002265 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002266 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002267}
2268
Vivien Didelot17e708b2016-12-05 17:30:27 -05002269static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2270{
2271 if (chip->info->ops->reset)
2272 return chip->info->ops->reset(chip);
2273
2274 return 0;
2275}
2276
Vivien Didelot309eca62016-12-05 17:30:26 -05002277static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2278{
2279 struct gpio_desc *gpiod = chip->reset;
2280
2281 /* If there is a GPIO connected to the reset pin, toggle it */
2282 if (gpiod) {
2283 gpiod_set_value_cansleep(gpiod, 1);
2284 usleep_range(10000, 20000);
2285 gpiod_set_value_cansleep(gpiod, 0);
2286 usleep_range(10000, 20000);
2287 }
2288}
2289
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002290static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2291{
2292 int i, err;
2293
2294 /* Set all ports to the Disabled state */
2295 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002296 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002297 if (err)
2298 return err;
2299 }
2300
2301 /* Wait for transmit queues to drain,
2302 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2303 */
2304 usleep_range(2000, 4000);
2305
2306 return 0;
2307}
2308
Vivien Didelotfad09c72016-06-21 12:28:20 -04002309static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002310{
Vivien Didelota935c052016-09-29 12:21:53 -04002311 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002312
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002313 err = mv88e6xxx_disable_ports(chip);
2314 if (err)
2315 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002316
Vivien Didelot309eca62016-12-05 17:30:26 -05002317 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002318
Vivien Didelot17e708b2016-12-05 17:30:27 -05002319 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002320}
2321
Vivien Didelot43145572017-03-11 16:12:59 -05002322static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002323 enum mv88e6xxx_frame_mode frame,
2324 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002325{
2326 int err;
2327
Vivien Didelot43145572017-03-11 16:12:59 -05002328 if (!chip->info->ops->port_set_frame_mode)
2329 return -EOPNOTSUPP;
2330
2331 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002332 if (err)
2333 return err;
2334
Vivien Didelot43145572017-03-11 16:12:59 -05002335 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2336 if (err)
2337 return err;
2338
2339 if (chip->info->ops->port_set_ether_type)
2340 return chip->info->ops->port_set_ether_type(chip, port, etype);
2341
2342 return 0;
2343}
2344
2345static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2346{
2347 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002348 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002349 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002350}
2351
2352static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2353{
2354 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002355 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002356 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002357}
2358
2359static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2360{
2361 return mv88e6xxx_set_port_mode(chip, port,
2362 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002363 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2364 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002365}
2366
2367static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2368{
2369 if (dsa_is_dsa_port(chip->ds, port))
2370 return mv88e6xxx_set_port_mode_dsa(chip, port);
2371
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002372 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002373 return mv88e6xxx_set_port_mode_normal(chip, port);
2374
2375 /* Setup CPU port mode depending on its supported tag format */
2376 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2377 return mv88e6xxx_set_port_mode_dsa(chip, port);
2378
2379 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2380 return mv88e6xxx_set_port_mode_edsa(chip, port);
2381
2382 return -EINVAL;
2383}
2384
Vivien Didelotea698f42017-03-11 16:12:50 -05002385static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2386{
2387 bool message = dsa_is_dsa_port(chip->ds, port);
2388
2389 return mv88e6xxx_port_set_message_port(chip, port, message);
2390}
2391
Vivien Didelot601aeed2017-03-11 16:13:00 -05002392static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2393{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002394 struct dsa_switch *ds = chip->ds;
David S. Miller407308f2019-06-15 13:35:29 -07002395 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002396
David S. Miller407308f2019-06-15 13:35:29 -07002397 /* Upstream ports flood frames with unknown unicast or multicast DA */
2398 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2399 if (chip->info->ops->port_set_egress_floods)
2400 return chip->info->ops->port_set_egress_floods(chip, port,
2401 flood, flood);
Vivien Didelot601aeed2017-03-11 16:13:00 -05002402
David S. Miller407308f2019-06-15 13:35:29 -07002403 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002404}
2405
Vivien Didelot45de77f2019-08-31 16:18:36 -04002406static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2407{
2408 struct mv88e6xxx_port *mvp = dev_id;
2409 struct mv88e6xxx_chip *chip = mvp->chip;
2410 irqreturn_t ret = IRQ_NONE;
2411 int port = mvp->port;
2412 u8 lane;
2413
2414 mv88e6xxx_reg_lock(chip);
2415 lane = mv88e6xxx_serdes_get_lane(chip, port);
2416 if (lane)
2417 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2418 mv88e6xxx_reg_unlock(chip);
2419
2420 return ret;
2421}
2422
2423static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
2424 u8 lane)
2425{
2426 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2427 unsigned int irq;
2428 int err;
2429
2430 /* Nothing to request if this SERDES port has no IRQ */
2431 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2432 if (!irq)
2433 return 0;
2434
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002435 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2436 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2437
Vivien Didelot45de77f2019-08-31 16:18:36 -04002438 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2439 mv88e6xxx_reg_unlock(chip);
2440 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002441 IRQF_ONESHOT, dev_id->serdes_irq_name,
2442 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002443 mv88e6xxx_reg_lock(chip);
2444 if (err)
2445 return err;
2446
2447 dev_id->serdes_irq = irq;
2448
2449 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2450}
2451
2452static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
2453 u8 lane)
2454{
2455 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2456 unsigned int irq = dev_id->serdes_irq;
2457 int err;
2458
2459 /* Nothing to free if no IRQ has been requested */
2460 if (!irq)
2461 return 0;
2462
2463 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2464
2465 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2466 mv88e6xxx_reg_unlock(chip);
2467 free_irq(irq, dev_id);
2468 mv88e6xxx_reg_lock(chip);
2469
2470 dev_id->serdes_irq = 0;
2471
2472 return err;
2473}
2474
Andrew Lunn6d917822017-05-26 01:03:21 +02002475static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2476 bool on)
2477{
Vivien Didelotdc272f62019-08-31 16:18:33 -04002478 u8 lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002479 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002480
Vivien Didelotdc272f62019-08-31 16:18:33 -04002481 lane = mv88e6xxx_serdes_get_lane(chip, port);
2482 if (!lane)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002483 return 0;
2484
2485 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002486 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002487 if (err)
2488 return err;
2489
Vivien Didelot45de77f2019-08-31 16:18:36 -04002490 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002491 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002492 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2493 if (err)
2494 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002495
Vivien Didelotdc272f62019-08-31 16:18:33 -04002496 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002497 }
2498
2499 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002500}
2501
Vivien Didelotfa371c82017-12-05 15:34:10 -05002502static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2503{
2504 struct dsa_switch *ds = chip->ds;
2505 int upstream_port;
2506 int err;
2507
Vivien Didelot07073c72017-12-05 15:34:13 -05002508 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002509 if (chip->info->ops->port_set_upstream_port) {
2510 err = chip->info->ops->port_set_upstream_port(chip, port,
2511 upstream_port);
2512 if (err)
2513 return err;
2514 }
2515
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002516 if (port == upstream_port) {
2517 if (chip->info->ops->set_cpu_port) {
2518 err = chip->info->ops->set_cpu_port(chip,
2519 upstream_port);
2520 if (err)
2521 return err;
2522 }
2523
2524 if (chip->info->ops->set_egress_port) {
2525 err = chip->info->ops->set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002526 MV88E6XXX_EGRESS_DIR_INGRESS,
2527 upstream_port);
2528 if (err)
2529 return err;
2530
2531 err = chip->info->ops->set_egress_port(chip,
2532 MV88E6XXX_EGRESS_DIR_EGRESS,
2533 upstream_port);
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002534 if (err)
2535 return err;
2536 }
2537 }
2538
Vivien Didelotfa371c82017-12-05 15:34:10 -05002539 return 0;
2540}
2541
Vivien Didelotfad09c72016-06-21 12:28:20 -04002542static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002543{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002544 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002545 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002546 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002547
Andrew Lunn7b898462018-08-09 15:38:47 +02002548 chip->ports[port].chip = chip;
2549 chip->ports[port].port = port;
2550
Vivien Didelotd78343d2016-11-04 03:23:36 +01002551 /* MAC Forcing register: don't force link, speed, duplex or flow control
2552 * state to any particular values on physical ports, but force the CPU
2553 * port and all DSA ports to their maximum bandwidth and full duplex.
2554 */
2555 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2556 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2557 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002558 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002559 PHY_INTERFACE_MODE_NA);
2560 else
2561 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2562 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002563 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002564 PHY_INTERFACE_MODE_NA);
2565 if (err)
2566 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002567
2568 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2569 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2570 * tunneling, determine priority by looking at 802.1p and IP
2571 * priority fields (IP prio has precedence), and set STP state
2572 * to Forwarding.
2573 *
2574 * If this is the CPU link, use DSA or EDSA tagging depending
2575 * on which tagging mode was configured.
2576 *
2577 * If this is a link to another switch, use DSA tagging mode.
2578 *
2579 * If this is the upstream port for this switch, enable
2580 * forwarding of unknown unicasts and multicasts.
2581 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002582 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2583 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2584 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2585 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002586 if (err)
2587 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002588
Vivien Didelot601aeed2017-03-11 16:13:00 -05002589 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002590 if (err)
2591 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002592
Vivien Didelot601aeed2017-03-11 16:13:00 -05002593 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002594 if (err)
2595 return err;
2596
Vivien Didelot8efdda42015-08-13 12:52:23 -04002597 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002598 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002599 * untagged frames on this port, do a destination address lookup on all
2600 * received packets as usual, disable ARP mirroring and don't send a
2601 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002602 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002603 err = mv88e6xxx_port_set_map_da(chip, port);
2604 if (err)
2605 return err;
2606
Vivien Didelotfa371c82017-12-05 15:34:10 -05002607 err = mv88e6xxx_setup_upstream_port(chip, port);
2608 if (err)
2609 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002610
Andrew Lunna23b2962017-02-04 20:15:28 +01002611 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002612 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002613 if (err)
2614 return err;
2615
Vivien Didelotcd782652017-06-08 18:34:13 -04002616 if (chip->info->ops->port_set_jumbo_size) {
2617 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002618 if (err)
2619 return err;
2620 }
2621
Andrew Lunn54d792f2015-05-06 01:09:47 +02002622 /* Port Association Vector: when learning source addresses
2623 * of packets, add the address to the address database using
2624 * a port bitmap that has only the bit for this port set and
2625 * the other bits clear.
2626 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002627 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002628 /* Disable learning for CPU port */
2629 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002630 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002631
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002632 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2633 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002634 if (err)
2635 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002636
2637 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002638 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2639 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002640 if (err)
2641 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002642
Vivien Didelot08984322017-06-08 18:34:12 -04002643 if (chip->info->ops->port_pause_limit) {
2644 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002645 if (err)
2646 return err;
2647 }
2648
Vivien Didelotc8c94892017-03-11 16:13:01 -05002649 if (chip->info->ops->port_disable_learn_limit) {
2650 err = chip->info->ops->port_disable_learn_limit(chip, port);
2651 if (err)
2652 return err;
2653 }
2654
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002655 if (chip->info->ops->port_disable_pri_override) {
2656 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002657 if (err)
2658 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002659 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002660
Andrew Lunnef0a7312016-12-03 04:35:16 +01002661 if (chip->info->ops->port_tag_remap) {
2662 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002663 if (err)
2664 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002665 }
2666
Andrew Lunnef70b112016-12-03 04:45:18 +01002667 if (chip->info->ops->port_egress_rate_limiting) {
2668 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002669 if (err)
2670 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002671 }
2672
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002673 if (chip->info->ops->port_setup_message_port) {
2674 err = chip->info->ops->port_setup_message_port(chip, port);
2675 if (err)
2676 return err;
2677 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002678
Vivien Didelot207afda2016-04-14 14:42:09 -04002679 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002680 * database, and allow bidirectional communication between the
2681 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002682 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002683 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002684 if (err)
2685 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002686
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002687 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002688 if (err)
2689 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002690
2691 /* Default VLAN ID and priority: don't set a default VLAN
2692 * ID, and set the default packet priority to zero.
2693 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002694 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002695}
2696
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002697static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
2698{
2699 struct mv88e6xxx_chip *chip = ds->priv;
2700
2701 if (chip->info->ops->port_set_jumbo_size)
2702 return 10240;
Chris Packham1baf0fa2020-07-24 11:21:22 +12002703 else if (chip->info->ops->set_max_frame_size)
2704 return 1632;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002705 return 1522;
2706}
2707
2708static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
2709{
2710 struct mv88e6xxx_chip *chip = ds->priv;
2711 int ret = 0;
2712
2713 mv88e6xxx_reg_lock(chip);
2714 if (chip->info->ops->port_set_jumbo_size)
2715 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12002716 else if (chip->info->ops->set_max_frame_size)
2717 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002718 else
2719 if (new_mtu > 1522)
2720 ret = -EINVAL;
2721 mv88e6xxx_reg_unlock(chip);
2722
2723 return ret;
2724}
2725
Andrew Lunn04aca992017-05-26 01:03:24 +02002726static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2727 struct phy_device *phydev)
2728{
2729 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002730 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002731
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002732 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002733 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002734 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002735
2736 return err;
2737}
2738
Andrew Lunn75104db2019-02-24 20:44:43 +01002739static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02002740{
2741 struct mv88e6xxx_chip *chip = ds->priv;
2742
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002743 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002744 if (mv88e6xxx_serdes_power(chip, port, false))
2745 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002746 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002747}
2748
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002749static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2750 unsigned int ageing_time)
2751{
Vivien Didelot04bed142016-08-31 18:06:13 -04002752 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002753 int err;
2754
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002755 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05002756 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002757 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002758
2759 return err;
2760}
2761
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002762static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002763{
2764 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002765
Andrew Lunnde2273872016-11-21 23:27:01 +01002766 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002767 if (chip->info->ops->stats_set_histogram) {
2768 err = chip->info->ops->stats_set_histogram(chip);
2769 if (err)
2770 return err;
2771 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002772
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002773 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002774}
2775
Andrew Lunnea890982019-01-09 00:24:03 +01002776/* Check if the errata has already been applied. */
2777static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
2778{
2779 int port;
2780 int err;
2781 u16 val;
2782
2783 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002784 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01002785 if (err) {
2786 dev_err(chip->dev,
2787 "Error reading hidden register: %d\n", err);
2788 return false;
2789 }
2790 if (val != 0x01c0)
2791 return false;
2792 }
2793
2794 return true;
2795}
2796
2797/* The 6390 copper ports have an errata which require poking magic
2798 * values into undocumented hidden registers and then performing a
2799 * software reset.
2800 */
2801static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
2802{
2803 int port;
2804 int err;
2805
2806 if (mv88e6390_setup_errata_applied(chip))
2807 return 0;
2808
2809 /* Set the ports into blocking mode */
2810 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2811 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
2812 if (err)
2813 return err;
2814 }
2815
2816 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002817 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01002818 if (err)
2819 return err;
2820 }
2821
2822 return mv88e6xxx_software_reset(chip);
2823}
2824
Andrew Lunn23e8b472019-10-25 01:03:52 +02002825static void mv88e6xxx_teardown(struct dsa_switch *ds)
2826{
2827 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002828 dsa_devlink_resources_unregister(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02002829}
2830
Vivien Didelotf81ec902016-05-09 13:22:58 -04002831static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002832{
Vivien Didelot04bed142016-08-31 18:06:13 -04002833 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002834 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04002835 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002836 int i;
2837
Vivien Didelotfad09c72016-06-21 12:28:20 -04002838 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002839 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002840
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002841 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002842
Andrew Lunnea890982019-01-09 00:24:03 +01002843 if (chip->info->ops->setup_errata) {
2844 err = chip->info->ops->setup_errata(chip);
2845 if (err)
2846 goto unlock;
2847 }
2848
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002849 /* Cache the cmode of each port. */
2850 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2851 if (chip->info->ops->port_get_cmode) {
2852 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
2853 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03002854 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002855
2856 chip->ports[i].cmode = cmode;
2857 }
2858 }
2859
Vivien Didelot97299342016-07-18 20:45:30 -04002860 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002861 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04002862 if (dsa_is_unused_port(ds, i))
2863 continue;
2864
Hubert Feursteinc8574862019-07-31 10:23:48 +02002865 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04002866 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02002867 dev_err(chip->dev, "port %d is invalid\n", i);
2868 err = -EINVAL;
2869 goto unlock;
2870 }
2871
Vivien Didelot97299342016-07-18 20:45:30 -04002872 err = mv88e6xxx_setup_port(chip, i);
2873 if (err)
2874 goto unlock;
2875 }
2876
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002877 err = mv88e6xxx_irl_setup(chip);
2878 if (err)
2879 goto unlock;
2880
Vivien Didelot04a69a12017-10-13 14:18:05 -04002881 err = mv88e6xxx_mac_setup(chip);
2882 if (err)
2883 goto unlock;
2884
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002885 err = mv88e6xxx_phy_setup(chip);
2886 if (err)
2887 goto unlock;
2888
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002889 err = mv88e6xxx_vtu_setup(chip);
2890 if (err)
2891 goto unlock;
2892
Vivien Didelot81228992017-03-30 17:37:08 -04002893 err = mv88e6xxx_pvt_setup(chip);
2894 if (err)
2895 goto unlock;
2896
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002897 err = mv88e6xxx_atu_setup(chip);
2898 if (err)
2899 goto unlock;
2900
Andrew Lunn87fa8862017-11-09 22:29:56 +01002901 err = mv88e6xxx_broadcast_setup(chip, 0);
2902 if (err)
2903 goto unlock;
2904
Vivien Didelot9e907d72017-07-17 13:03:43 -04002905 err = mv88e6xxx_pot_setup(chip);
2906 if (err)
2907 goto unlock;
2908
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002909 err = mv88e6xxx_rmu_setup(chip);
2910 if (err)
2911 goto unlock;
2912
Vivien Didelot51c901a2017-07-17 13:03:41 -04002913 err = mv88e6xxx_rsvd2cpu_setup(chip);
2914 if (err)
2915 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002916
Vivien Didelotb28f8722018-04-26 21:56:44 -04002917 err = mv88e6xxx_trunk_setup(chip);
2918 if (err)
2919 goto unlock;
2920
Vivien Didelotc7f047b2018-04-26 21:56:45 -04002921 err = mv88e6xxx_devmap_setup(chip);
2922 if (err)
2923 goto unlock;
2924
Vivien Didelot93e18d62018-05-11 17:16:35 -04002925 err = mv88e6xxx_pri_setup(chip);
2926 if (err)
2927 goto unlock;
2928
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002929 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002930 if (chip->info->ptp_support) {
2931 err = mv88e6xxx_ptp_setup(chip);
2932 if (err)
2933 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002934
2935 err = mv88e6xxx_hwtstamp_setup(chip);
2936 if (err)
2937 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002938 }
2939
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002940 err = mv88e6xxx_stats_setup(chip);
2941 if (err)
2942 goto unlock;
2943
Vivien Didelot6b17e862015-08-13 12:52:18 -04002944unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002945 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02002946
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002947 if (err)
2948 return err;
2949
2950 /* Have to be called without holding the register lock, since
2951 * they take the devlink lock, and we later take the locks in
2952 * the reverse order when getting/setting parameters or
2953 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02002954 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002955 err = mv88e6xxx_setup_devlink_resources(ds);
2956 if (err)
2957 return err;
2958
2959 err = mv88e6xxx_setup_devlink_params(ds);
2960 if (err)
2961 dsa_devlink_resources_unregister(ds);
2962
2963 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002964}
2965
Vivien Didelote57e5e72016-08-15 17:19:00 -04002966static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002967{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002968 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2969 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002970 u16 val;
2971 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002972
Andrew Lunnee26a222017-01-24 14:53:48 +01002973 if (!chip->info->ops->phy_read)
2974 return -EOPNOTSUPP;
2975
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002976 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01002977 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002978 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002979
Andrew Lunnda9f3302017-02-01 03:40:05 +01002980 if (reg == MII_PHYSID2) {
Andrew Lunnddc49ac2018-11-12 18:51:01 +01002981 /* Some internal PHYs don't have a model number. */
2982 if (chip->info->family != MV88E6XXX_FAMILY_6165)
2983 /* Then there is the 6165 family. It gets is
2984 * PHYs correct. But it can also have two
2985 * SERDES interfaces in the PHY address
2986 * space. And these don't have a model
2987 * number. But they are not PHYs, so we don't
2988 * want to give them something a PHY driver
2989 * will recognise.
2990 *
2991 * Use the mv88e6390 family model number
2992 * instead, for anything which really could be
2993 * a PHY,
2994 */
2995 if (!(val & 0x3f0))
2996 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002997 }
2998
Vivien Didelote57e5e72016-08-15 17:19:00 -04002999 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003000}
3001
Vivien Didelote57e5e72016-08-15 17:19:00 -04003002static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003003{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003004 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3005 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003006 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003007
Andrew Lunnee26a222017-01-24 14:53:48 +01003008 if (!chip->info->ops->phy_write)
3009 return -EOPNOTSUPP;
3010
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003011 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003012 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003013 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003014
3015 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003016}
3017
Vivien Didelotfad09c72016-06-21 12:28:20 -04003018static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003019 struct device_node *np,
3020 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003021{
3022 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003023 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003024 struct mii_bus *bus;
3025 int err;
3026
Andrew Lunn2510bab2018-02-22 01:51:49 +01003027 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003028 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003029 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003030 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003031
3032 if (err)
3033 return err;
3034 }
3035
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003036 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003037 if (!bus)
3038 return -ENOMEM;
3039
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003040 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003041 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003042 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003043 INIT_LIST_HEAD(&mdio_bus->list);
3044 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003045
Andrew Lunnb516d452016-06-04 21:17:06 +02003046 if (np) {
3047 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003048 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003049 } else {
3050 bus->name = "mv88e6xxx SMI";
3051 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3052 }
3053
3054 bus->read = mv88e6xxx_mdio_read;
3055 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003056 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003057
Andrew Lunn6f882842018-03-17 20:32:05 +01003058 if (!external) {
3059 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3060 if (err)
3061 return err;
3062 }
3063
Florian Fainelli00e798c2018-05-15 16:56:19 -07003064 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003065 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003066 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003067 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003068 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003069 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003070
3071 if (external)
3072 list_add_tail(&mdio_bus->list, &chip->mdios);
3073 else
3074 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003075
3076 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003077}
3078
Andrew Lunn3126aee2017-12-07 01:05:57 +01003079static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3080
3081{
3082 struct mv88e6xxx_mdio_bus *mdio_bus;
3083 struct mii_bus *bus;
3084
3085 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3086 bus = mdio_bus->bus;
3087
Andrew Lunn6f882842018-03-17 20:32:05 +01003088 if (!mdio_bus->external)
3089 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3090
Andrew Lunn3126aee2017-12-07 01:05:57 +01003091 mdiobus_unregister(bus);
3092 }
3093}
3094
Andrew Lunna3c53be52017-01-24 14:53:50 +01003095static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3096 struct device_node *np)
3097{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003098 struct device_node *child;
3099 int err;
3100
3101 /* Always register one mdio bus for the internal/default mdio
3102 * bus. This maybe represented in the device tree, but is
3103 * optional.
3104 */
3105 child = of_get_child_by_name(np, "mdio");
3106 err = mv88e6xxx_mdio_register(chip, child, false);
3107 if (err)
3108 return err;
3109
3110 /* Walk the device tree, and see if there are any other nodes
3111 * which say they are compatible with the external mdio
3112 * bus.
3113 */
3114 for_each_available_child_of_node(np, child) {
Andrew Lunnceb96fa2020-09-01 04:32:57 +02003115 if (of_device_is_compatible(
3116 child, "marvell,mv88e6xxx-mdio-external")) {
Andrew Lunna3c53be52017-01-24 14:53:50 +01003117 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003118 if (err) {
3119 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303120 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003121 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003122 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003123 }
3124 }
3125
3126 return 0;
3127}
3128
Vivien Didelot855b1932016-07-20 18:18:35 -04003129static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3130{
Vivien Didelot04bed142016-08-31 18:06:13 -04003131 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003132
3133 return chip->eeprom_len;
3134}
3135
Vivien Didelot855b1932016-07-20 18:18:35 -04003136static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3137 struct ethtool_eeprom *eeprom, u8 *data)
3138{
Vivien Didelot04bed142016-08-31 18:06:13 -04003139 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003140 int err;
3141
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003142 if (!chip->info->ops->get_eeprom)
3143 return -EOPNOTSUPP;
3144
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003145 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003146 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003147 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003148
3149 if (err)
3150 return err;
3151
3152 eeprom->magic = 0xc3ec4951;
3153
3154 return 0;
3155}
3156
Vivien Didelot855b1932016-07-20 18:18:35 -04003157static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3158 struct ethtool_eeprom *eeprom, u8 *data)
3159{
Vivien Didelot04bed142016-08-31 18:06:13 -04003160 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003161 int err;
3162
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003163 if (!chip->info->ops->set_eeprom)
3164 return -EOPNOTSUPP;
3165
Vivien Didelot855b1932016-07-20 18:18:35 -04003166 if (eeprom->magic != 0xc3ec4951)
3167 return -EINVAL;
3168
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003169 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003170 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003171 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003172
3173 return err;
3174}
3175
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003176static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003177 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003178 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3179 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003180 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003181 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003182 .phy_read = mv88e6185_phy_ppu_read,
3183 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003184 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003185 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003186 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003187 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003188 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003189 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003190 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003191 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003192 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003193 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003194 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003195 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003196 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003197 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003198 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3199 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003200 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003201 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3202 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003203 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003204 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003205 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003206 .ppu_enable = mv88e6185_g1_ppu_enable,
3207 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003208 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003209 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003210 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003211 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003212 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003213 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003214};
3215
3216static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003217 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003218 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3219 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003220 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003221 .phy_read = mv88e6185_phy_ppu_read,
3222 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003223 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003224 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003225 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003226 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01003227 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003228 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003229 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003230 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003231 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003232 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3233 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003234 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003235 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003236 .ppu_enable = mv88e6185_g1_ppu_enable,
3237 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003238 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003239 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003240 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003241 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003242 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003243};
3244
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003245static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003246 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003247 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3248 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003249 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003250 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3251 .phy_read = mv88e6xxx_g2_smi_phy_read,
3252 .phy_write = mv88e6xxx_g2_smi_phy_write,
3253 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003254 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003255 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003256 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003257 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003258 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003259 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003260 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003261 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003262 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003263 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003264 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003265 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003266 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003267 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3268 .stats_get_strings = mv88e6095_stats_get_strings,
3269 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003270 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3271 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003272 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003273 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003274 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003275 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003276 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003277 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003278 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003279 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003280 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003281};
3282
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003283static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003284 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003285 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3286 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003287 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003288 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003289 .phy_read = mv88e6xxx_g2_smi_phy_read,
3290 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003291 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003292 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003293 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003294 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003295 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003296 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003297 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003298 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003299 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003300 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003301 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3302 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003303 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003304 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3305 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003306 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003307 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003308 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003309 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003310 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3311 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003312 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003313 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003314 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003315 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003316};
3317
3318static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003319 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003320 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3321 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003322 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003323 .phy_read = mv88e6185_phy_ppu_read,
3324 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003325 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003326 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003327 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003328 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003329 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003330 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003331 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003332 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003333 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003334 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003335 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003336 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003337 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003338 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003339 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003340 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3341 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003342 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003343 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3344 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003345 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003346 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003347 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003348 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003349 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003350 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003351 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003352 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003353 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003354};
3355
Vivien Didelot990e27b2017-03-28 13:50:32 -04003356static const struct mv88e6xxx_ops mv88e6141_ops = {
3357 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003358 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3359 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003360 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003361 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3362 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3363 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3364 .phy_read = mv88e6xxx_g2_smi_phy_read,
3365 .phy_write = mv88e6xxx_g2_smi_phy_write,
3366 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003367 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003368 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003369 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003370 .port_tag_remap = mv88e6095_port_tag_remap,
3371 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3372 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3373 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003374 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003375 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003376 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003377 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3378 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003379 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003380 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003381 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003382 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003383 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003384 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3385 .stats_get_strings = mv88e6320_stats_get_strings,
3386 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003387 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3388 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003389 .watchdog_ops = &mv88e6390_watchdog_ops,
3390 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003391 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003392 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003393 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003394 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003395 .serdes_power = mv88e6390_serdes_power,
3396 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003397 /* Check status register pause & lpa register */
3398 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3399 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3400 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3401 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003402 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003403 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003404 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003405 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003406 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003407};
3408
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003409static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003410 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003411 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3412 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003413 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003414 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003415 .phy_read = mv88e6xxx_g2_smi_phy_read,
3416 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003417 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003418 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003419 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003420 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003421 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003422 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003423 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003424 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003425 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003426 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003427 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003428 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003429 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003430 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003431 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003432 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3433 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003434 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003435 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3436 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003437 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003438 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003439 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003440 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003441 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3442 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003443 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003444 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003445 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003446 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003447 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003448};
3449
3450static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003451 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003452 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3453 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003454 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003455 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003456 .phy_read = mv88e6165_phy_read,
3457 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003458 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003459 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003460 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003461 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003462 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003463 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003464 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003465 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003466 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3467 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003468 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003469 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3470 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003471 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003472 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003473 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003474 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003475 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3476 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003477 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003478 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003479 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003480 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003481 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003482};
3483
3484static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003485 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003486 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3487 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003488 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003489 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003490 .phy_read = mv88e6xxx_g2_smi_phy_read,
3491 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003492 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003493 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003494 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003495 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003496 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003497 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003498 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003499 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003500 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003501 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003502 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003503 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003504 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003505 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003506 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003507 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003508 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3509 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003510 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003511 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3512 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003513 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003514 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003515 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003516 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003517 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3518 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003519 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003520 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003521 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003522};
3523
3524static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003525 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003526 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3527 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003528 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003529 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3530 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003531 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003532 .phy_read = mv88e6xxx_g2_smi_phy_read,
3533 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003534 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003535 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003536 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003537 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003538 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003539 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003540 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003541 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003542 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003543 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003544 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003545 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003546 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003547 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003548 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003549 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003550 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003551 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3552 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003553 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003554 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3555 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003556 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003557 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003558 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003559 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003560 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003561 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3562 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003563 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003564 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003565 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003566 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3567 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3568 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3569 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003570 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003571 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3572 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003573 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003574 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003575};
3576
3577static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003578 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003579 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3580 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003581 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003582 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003583 .phy_read = mv88e6xxx_g2_smi_phy_read,
3584 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003585 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003586 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003587 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003588 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003589 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003590 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003591 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003592 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003593 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003594 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003595 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003596 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003597 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003598 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003599 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003600 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003601 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3602 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003603 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003604 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3605 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003606 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003607 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003608 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003609 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003610 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3611 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003612 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003613 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003614 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003615};
3616
3617static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003618 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003619 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3620 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003621 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003622 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3623 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003624 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003625 .phy_read = mv88e6xxx_g2_smi_phy_read,
3626 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003627 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003628 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003629 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003630 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003631 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003632 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003633 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003634 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003635 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003636 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003637 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003638 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003639 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003640 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003641 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003642 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003643 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003644 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3645 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003646 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003647 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3648 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003649 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003650 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003651 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003652 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003653 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003654 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3655 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003656 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003657 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003658 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003659 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3660 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3661 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3662 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003663 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003664 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003665 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003666 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003667 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3668 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003669 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003670 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003671};
3672
3673static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003674 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003675 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3676 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003677 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003678 .phy_read = mv88e6185_phy_ppu_read,
3679 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003680 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003681 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003682 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003683 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003684 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003685 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02003686 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003687 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003688 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003689 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003690 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003691 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3692 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003693 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003694 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3695 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003696 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003697 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelot02317e62018-05-09 11:38:49 -04003698 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003699 .ppu_enable = mv88e6185_g1_ppu_enable,
3700 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003701 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003702 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003703 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003704 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003705 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003706};
3707
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003708static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003709 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003710 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003711 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003712 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3713 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003714 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3715 .phy_read = mv88e6xxx_g2_smi_phy_read,
3716 .phy_write = mv88e6xxx_g2_smi_phy_write,
3717 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003718 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003719 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003720 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003721 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003722 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003723 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003724 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003725 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003726 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003727 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003728 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003729 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003730 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003731 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003732 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003733 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003734 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003735 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3736 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003737 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003738 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3739 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003740 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003741 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003742 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003743 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003744 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003745 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3746 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003747 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3748 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003749 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003750 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003751 /* Check status register pause & lpa register */
3752 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3753 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3754 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3755 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003756 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003757 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003758 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003759 .serdes_get_strings = mv88e6390_serdes_get_strings,
3760 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003761 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3762 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003763 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003764 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003765};
3766
3767static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003768 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003769 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003770 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003771 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3772 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003773 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3774 .phy_read = mv88e6xxx_g2_smi_phy_read,
3775 .phy_write = mv88e6xxx_g2_smi_phy_write,
3776 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003777 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003778 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003779 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003780 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003781 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003782 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003783 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003784 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003785 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003786 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003787 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003788 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003789 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003790 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003791 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003792 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003793 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003794 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3795 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003796 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003797 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3798 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003799 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003800 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003801 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003802 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003803 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003804 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3805 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003806 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3807 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003808 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003809 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003810 /* Check status register pause & lpa register */
3811 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3812 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3813 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3814 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003815 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003816 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003817 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003818 .serdes_get_strings = mv88e6390_serdes_get_strings,
3819 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003820 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3821 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003822 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003823 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003824};
3825
3826static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003827 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003828 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003829 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003830 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3831 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003832 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3833 .phy_read = mv88e6xxx_g2_smi_phy_read,
3834 .phy_write = mv88e6xxx_g2_smi_phy_write,
3835 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003836 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003837 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003838 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003839 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003840 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003841 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003842 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003843 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003844 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003845 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003846 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003847 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003848 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003849 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003850 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003851 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3852 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003853 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003854 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3855 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003856 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003857 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003858 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003859 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003860 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003861 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3862 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003863 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3864 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003865 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003866 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003867 /* Check status register pause & lpa register */
3868 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3869 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3870 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3871 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003872 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003873 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003874 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003875 .serdes_get_strings = mv88e6390_serdes_get_strings,
3876 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003877 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3878 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003879 .avb_ops = &mv88e6390_avb_ops,
3880 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003881 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003882};
3883
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003884static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003885 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003886 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3887 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003888 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003889 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3890 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003891 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003892 .phy_read = mv88e6xxx_g2_smi_phy_read,
3893 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003894 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003895 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003896 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003897 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003898 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003899 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003900 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003901 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003902 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003903 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003904 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003905 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003906 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003907 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003908 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003909 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003910 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003911 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3912 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003913 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003914 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3915 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003916 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003917 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003918 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003919 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003920 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003921 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3922 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003923 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003924 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003925 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003926 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3927 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3928 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3929 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003930 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003931 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003932 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003933 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003934 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3935 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003936 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003937 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003938 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003939 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003940};
3941
Rasmus Villemoes1f718362019-06-04 07:34:32 +00003942static const struct mv88e6xxx_ops mv88e6250_ops = {
3943 /* MV88E6XXX_FAMILY_6250 */
3944 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
3945 .ip_pri_map = mv88e6085_g1_ip_pri_map,
3946 .irl_init_all = mv88e6352_g2_irl_init_all,
3947 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3948 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
3949 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3950 .phy_read = mv88e6xxx_g2_smi_phy_read,
3951 .phy_write = mv88e6xxx_g2_smi_phy_write,
3952 .port_set_link = mv88e6xxx_port_set_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00003953 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003954 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00003955 .port_tag_remap = mv88e6095_port_tag_remap,
3956 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3957 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3958 .port_set_ether_type = mv88e6351_port_set_ether_type,
3959 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3960 .port_pause_limit = mv88e6097_port_pause_limit,
3961 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00003962 .stats_snapshot = mv88e6320_g1_stats_snapshot,
3963 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3964 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
3965 .stats_get_strings = mv88e6250_stats_get_strings,
3966 .stats_get_stats = mv88e6250_stats_get_stats,
3967 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3968 .set_egress_port = mv88e6095_g1_set_egress_port,
3969 .watchdog_ops = &mv88e6250_watchdog_ops,
3970 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3971 .pot_clear = mv88e6xxx_g2_pot_clear,
3972 .reset = mv88e6250_g1_reset,
3973 .vtu_getnext = mv88e6250_g1_vtu_getnext,
3974 .vtu_loadpurge = mv88e6250_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02003975 .avb_ops = &mv88e6352_avb_ops,
3976 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00003977 .phylink_validate = mv88e6065_phylink_validate,
3978};
3979
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003980static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003981 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003982 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003983 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003984 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3985 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003986 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3987 .phy_read = mv88e6xxx_g2_smi_phy_read,
3988 .phy_write = mv88e6xxx_g2_smi_phy_write,
3989 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003990 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003991 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003992 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003993 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003994 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003995 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003996 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003997 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003998 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003999 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004000 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004001 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004002 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004003 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004004 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004005 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004006 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4007 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004008 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004009 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4010 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004011 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004012 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004013 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004014 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004015 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004016 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4017 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004018 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4019 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004020 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004021 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004022 /* Check status register pause & lpa register */
4023 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4024 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4025 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4026 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004027 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004028 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004029 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004030 .serdes_get_strings = mv88e6390_serdes_get_strings,
4031 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004032 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4033 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004034 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004035 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004036 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004037 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004038};
4039
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004040static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004041 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004042 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4043 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004044 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004045 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4046 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004047 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004048 .phy_read = mv88e6xxx_g2_smi_phy_read,
4049 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004050 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004051 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004052 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004053 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004054 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004055 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004056 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004057 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004058 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004059 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004060 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004061 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004062 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004063 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004064 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004065 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4066 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004067 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004068 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4069 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004070 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004071 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004072 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004073 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004074 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004075 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004076 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004077 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004078 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004079 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004080};
4081
4082static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004083 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004084 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4085 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004086 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004087 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4088 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004089 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004090 .phy_read = mv88e6xxx_g2_smi_phy_read,
4091 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004092 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004093 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004094 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004095 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004096 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004097 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004098 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004099 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004100 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004101 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004102 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004103 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004104 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004105 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004106 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004107 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4108 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004109 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004110 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4111 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004112 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004113 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004114 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004115 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004116 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004117 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004118 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004119 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004120};
4121
Vivien Didelot16e329a2017-03-28 13:50:33 -04004122static const struct mv88e6xxx_ops mv88e6341_ops = {
4123 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004124 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4125 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004126 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004127 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4128 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4129 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4130 .phy_read = mv88e6xxx_g2_smi_phy_read,
4131 .phy_write = mv88e6xxx_g2_smi_phy_write,
4132 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004133 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004134 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004135 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004136 .port_tag_remap = mv88e6095_port_tag_remap,
4137 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4138 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
4139 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004140 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004141 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004142 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004143 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4144 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004145 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004146 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004147 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004148 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004149 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004150 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4151 .stats_get_strings = mv88e6320_stats_get_strings,
4152 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004153 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4154 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004155 .watchdog_ops = &mv88e6390_watchdog_ops,
4156 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004157 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004158 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004159 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004160 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004161 .serdes_power = mv88e6390_serdes_power,
4162 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004163 /* Check status register pause & lpa register */
4164 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4165 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4166 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4167 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004168 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004169 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004170 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004171 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004172 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004173 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01004174 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004175};
4176
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004177static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004178 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004179 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4180 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004181 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004182 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004183 .phy_read = mv88e6xxx_g2_smi_phy_read,
4184 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004185 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004186 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004187 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004188 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004189 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004190 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004191 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004192 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004193 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004194 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004195 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004196 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004197 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004198 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004199 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004200 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004201 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4202 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004203 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004204 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4205 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004206 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004207 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004208 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004209 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004210 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4211 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004212 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004213 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004214 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004215};
4216
4217static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004218 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004219 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4220 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004221 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004222 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004223 .phy_read = mv88e6xxx_g2_smi_phy_read,
4224 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004225 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004226 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004227 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004228 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004229 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004230 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004231 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004232 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004233 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004234 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004235 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004236 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004237 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004238 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004239 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004240 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004241 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4242 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004243 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004244 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4245 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004246 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004247 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004248 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004249 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004250 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4251 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004252 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004253 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004254 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004255 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004256 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004257};
4258
4259static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004260 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004261 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4262 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004263 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004264 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4265 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
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,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004270 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004271 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004272 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004273 .port_set_policy = mv88e6352_port_set_policy,
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,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004295 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004296 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4297 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004298 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004299 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004300 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004301 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4302 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4303 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4304 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004305 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004306 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004307 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004308 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004309 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004310 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004311 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004312 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4313 .serdes_get_strings = mv88e6352_serdes_get_strings,
4314 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004315 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4316 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004317 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004318};
4319
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004320static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004321 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004322 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004323 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004324 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4325 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004326 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4327 .phy_read = mv88e6xxx_g2_smi_phy_read,
4328 .phy_write = mv88e6xxx_g2_smi_phy_write,
4329 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004330 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004331 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004332 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004333 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004334 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004335 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004336 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004337 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004338 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004339 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004340 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004341 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004342 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004343 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004344 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004345 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004346 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004347 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004348 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4349 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004350 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004351 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4352 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004353 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004354 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004355 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004356 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004357 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004358 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4359 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004360 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4361 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004362 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004363 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004364 /* Check status register pause & lpa register */
4365 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4366 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4367 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4368 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004369 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004370 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004371 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004372 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004373 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004374 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004375 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4376 .serdes_get_strings = mv88e6390_serdes_get_strings,
4377 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004378 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4379 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004380 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004381};
4382
4383static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004384 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004385 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004386 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004387 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4388 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004389 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4390 .phy_read = mv88e6xxx_g2_smi_phy_read,
4391 .phy_write = mv88e6xxx_g2_smi_phy_write,
4392 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004393 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004394 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004395 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004396 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004397 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004398 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004399 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004400 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004401 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004402 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004403 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004404 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004405 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004406 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004407 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004408 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004409 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004410 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004411 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4412 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004413 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004414 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4415 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004416 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004417 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004418 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004419 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004420 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004421 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4422 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004423 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4424 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004425 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004426 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004427 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4428 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4429 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4430 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004431 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004432 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004433 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004434 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4435 .serdes_get_strings = mv88e6390_serdes_get_strings,
4436 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004437 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4438 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004439 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004440 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004441 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004442 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004443};
4444
Vivien Didelotf81ec902016-05-09 13:22:58 -04004445static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4446 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004447 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004448 .family = MV88E6XXX_FAMILY_6097,
4449 .name = "Marvell 88E6085",
4450 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004451 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004452 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004453 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004454 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004455 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004456 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004457 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004458 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004459 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004460 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004461 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004462 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004463 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004464 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004465 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004466 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004467 },
4468
4469 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004470 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004471 .family = MV88E6XXX_FAMILY_6095,
4472 .name = "Marvell 88E6095/88E6095F",
4473 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004474 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004475 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004476 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004477 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004478 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004479 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004480 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004481 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004482 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004483 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004484 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004485 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004486 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004487 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004488 },
4489
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004490 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004491 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004492 .family = MV88E6XXX_FAMILY_6097,
4493 .name = "Marvell 88E6097/88E6097F",
4494 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004495 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004496 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004497 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004498 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004499 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004500 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004501 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004502 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004503 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004504 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004505 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004506 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004507 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004508 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01004509 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004510 .ops = &mv88e6097_ops,
4511 },
4512
Vivien Didelotf81ec902016-05-09 13:22:58 -04004513 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004514 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004515 .family = MV88E6XXX_FAMILY_6165,
4516 .name = "Marvell 88E6123",
4517 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004518 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004519 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004520 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004521 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004522 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004523 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004524 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004525 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004526 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004527 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004528 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004529 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004530 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004531 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004532 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004533 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004534 },
4535
4536 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004537 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004538 .family = MV88E6XXX_FAMILY_6185,
4539 .name = "Marvell 88E6131",
4540 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004541 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004542 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004543 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004544 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004545 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004546 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004547 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004548 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004549 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004550 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004551 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004552 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004553 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004554 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004555 },
4556
Vivien Didelot990e27b2017-03-28 13:50:32 -04004557 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004558 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004559 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01004560 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04004561 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004562 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004563 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004564 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004565 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004566 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004567 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004568 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004569 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004570 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004571 .age_time_coeff = 3750,
4572 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004573 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004574 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004575 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004576 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004577 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004578 .ops = &mv88e6141_ops,
4579 },
4580
Vivien Didelotf81ec902016-05-09 13:22:58 -04004581 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004582 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004583 .family = MV88E6XXX_FAMILY_6165,
4584 .name = "Marvell 88E6161",
4585 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004586 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004587 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004588 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004589 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004590 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004591 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004592 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004593 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004594 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004595 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004596 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004597 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004598 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004599 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004600 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004601 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004602 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004603 },
4604
4605 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004606 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004607 .family = MV88E6XXX_FAMILY_6165,
4608 .name = "Marvell 88E6165",
4609 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004610 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004611 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004612 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004613 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004614 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004615 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004616 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004617 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004618 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004619 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004620 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004621 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004622 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004623 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004624 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004625 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004626 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004627 },
4628
4629 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004630 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004631 .family = MV88E6XXX_FAMILY_6351,
4632 .name = "Marvell 88E6171",
4633 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004634 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004635 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004636 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004637 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004638 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004639 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004640 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004641 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004642 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004643 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004644 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004645 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004646 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004647 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004648 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004649 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004650 },
4651
4652 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004653 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004654 .family = MV88E6XXX_FAMILY_6352,
4655 .name = "Marvell 88E6172",
4656 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004657 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004658 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004659 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004660 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004661 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004662 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004663 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004664 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004665 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004666 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004667 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004668 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004669 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004670 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004671 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004672 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004673 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004674 },
4675
4676 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004677 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004678 .family = MV88E6XXX_FAMILY_6351,
4679 .name = "Marvell 88E6175",
4680 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004681 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004682 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004683 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004684 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004685 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004686 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004687 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004688 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004689 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004690 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004691 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004692 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004693 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004694 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004695 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004696 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004697 },
4698
4699 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004700 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004701 .family = MV88E6XXX_FAMILY_6352,
4702 .name = "Marvell 88E6176",
4703 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004704 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004705 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004706 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004707 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004708 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004709 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004710 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004711 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004712 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004713 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004714 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004715 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004716 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004717 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004718 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004719 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004720 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004721 },
4722
4723 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004724 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004725 .family = MV88E6XXX_FAMILY_6185,
4726 .name = "Marvell 88E6185",
4727 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004728 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004729 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004730 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004731 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004732 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004733 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004734 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004735 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004736 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004737 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004738 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004739 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004740 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004741 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004742 },
4743
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004744 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004745 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004746 .family = MV88E6XXX_FAMILY_6390,
4747 .name = "Marvell 88E6190",
4748 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004749 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004750 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004751 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004752 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004753 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004754 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004755 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004756 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004757 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004758 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004759 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004760 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004761 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04004762 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004763 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05004764 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004765 .ops = &mv88e6190_ops,
4766 },
4767
4768 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004769 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004770 .family = MV88E6XXX_FAMILY_6390,
4771 .name = "Marvell 88E6190X",
4772 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004773 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004774 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004775 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004776 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004777 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004778 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004779 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004780 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004781 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004782 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004783 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004784 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004785 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004786 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004787 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004788 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004789 .ops = &mv88e6190x_ops,
4790 },
4791
4792 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004793 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004794 .family = MV88E6XXX_FAMILY_6390,
4795 .name = "Marvell 88E6191",
4796 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004797 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004798 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004799 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04004800 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004801 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004802 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004803 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004804 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004805 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004806 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004807 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004808 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004809 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004810 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004811 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004812 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04004813 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004814 },
4815
Hubert Feurstein49022642019-07-31 10:23:46 +02004816 [MV88E6220] = {
4817 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
4818 .family = MV88E6XXX_FAMILY_6250,
4819 .name = "Marvell 88E6220",
4820 .num_databases = 64,
4821
4822 /* Ports 2-4 are not routed to pins
4823 * => usable ports 0, 1, 5, 6
4824 */
4825 .num_ports = 7,
4826 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02004827 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02004828 .max_vid = 4095,
4829 .port_base_addr = 0x08,
4830 .phy_base_addr = 0x00,
4831 .global1_addr = 0x0f,
4832 .global2_addr = 0x07,
4833 .age_time_coeff = 15000,
4834 .g1_irqs = 9,
4835 .g2_irqs = 10,
4836 .atu_move_port_mask = 0xf,
4837 .dual_chip = true,
4838 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02004839 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02004840 .ops = &mv88e6250_ops,
4841 },
4842
Vivien Didelotf81ec902016-05-09 13:22:58 -04004843 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004844 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004845 .family = MV88E6XXX_FAMILY_6352,
4846 .name = "Marvell 88E6240",
4847 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004848 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004849 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004850 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004851 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004852 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004853 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004854 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004855 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004856 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004857 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004858 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004859 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004860 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004861 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004862 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004863 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004864 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004865 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004866 },
4867
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004868 [MV88E6250] = {
4869 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
4870 .family = MV88E6XXX_FAMILY_6250,
4871 .name = "Marvell 88E6250",
4872 .num_databases = 64,
4873 .num_ports = 7,
4874 .num_internal_phys = 5,
4875 .max_vid = 4095,
4876 .port_base_addr = 0x08,
4877 .phy_base_addr = 0x00,
4878 .global1_addr = 0x0f,
4879 .global2_addr = 0x07,
4880 .age_time_coeff = 15000,
4881 .g1_irqs = 9,
4882 .g2_irqs = 10,
4883 .atu_move_port_mask = 0xf,
4884 .dual_chip = true,
4885 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02004886 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004887 .ops = &mv88e6250_ops,
4888 },
4889
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004890 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004891 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004892 .family = MV88E6XXX_FAMILY_6390,
4893 .name = "Marvell 88E6290",
4894 .num_databases = 4096,
4895 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004896 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004897 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004898 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004899 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004900 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004901 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004902 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004903 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004904 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004905 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004906 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004907 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004908 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004909 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004910 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004911 .ops = &mv88e6290_ops,
4912 },
4913
Vivien Didelotf81ec902016-05-09 13:22:58 -04004914 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004915 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004916 .family = MV88E6XXX_FAMILY_6320,
4917 .name = "Marvell 88E6320",
4918 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004919 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004920 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004921 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004922 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004923 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004924 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004925 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004926 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004927 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004928 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004929 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004930 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004931 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004932 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004933 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004934 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004935 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004936 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004937 },
4938
4939 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004940 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004941 .family = MV88E6XXX_FAMILY_6320,
4942 .name = "Marvell 88E6321",
4943 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004944 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004945 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004946 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004947 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004948 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004949 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004950 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004951 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004952 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004953 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004954 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004955 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004956 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004957 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004958 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004959 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004960 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004961 },
4962
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004963 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004964 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004965 .family = MV88E6XXX_FAMILY_6341,
4966 .name = "Marvell 88E6341",
4967 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004968 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01004969 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004970 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004971 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004972 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004973 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004974 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004975 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004976 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004977 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05004978 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004979 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004980 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004981 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004982 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004983 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004984 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004985 .ops = &mv88e6341_ops,
4986 },
4987
Vivien Didelotf81ec902016-05-09 13:22:58 -04004988 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004989 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004990 .family = MV88E6XXX_FAMILY_6351,
4991 .name = "Marvell 88E6350",
4992 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004993 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004994 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004995 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004996 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004997 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004998 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004999 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005000 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005001 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005002 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005003 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005004 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005005 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005006 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005007 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005008 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005009 },
5010
5011 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005012 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005013 .family = MV88E6XXX_FAMILY_6351,
5014 .name = "Marvell 88E6351",
5015 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005016 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005017 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005018 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005019 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005020 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005021 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005022 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005023 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005024 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005025 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005026 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005027 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005028 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005029 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005030 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005031 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005032 },
5033
5034 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005035 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005036 .family = MV88E6XXX_FAMILY_6352,
5037 .name = "Marvell 88E6352",
5038 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005039 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005040 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005041 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005042 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005043 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005044 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005045 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005046 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005047 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005048 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005049 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005050 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005051 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005052 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005053 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005054 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005055 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005056 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005057 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005058 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005059 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005060 .family = MV88E6XXX_FAMILY_6390,
5061 .name = "Marvell 88E6390",
5062 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005063 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005064 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005065 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005066 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005067 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005068 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005069 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005070 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005071 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005072 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005073 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005074 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005075 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005076 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005077 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005078 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005079 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005080 .ops = &mv88e6390_ops,
5081 },
5082 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005083 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005084 .family = MV88E6XXX_FAMILY_6390,
5085 .name = "Marvell 88E6390X",
5086 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005087 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005088 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005089 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005090 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005091 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005092 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005093 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005094 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005095 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005096 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005097 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005098 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005099 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005100 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005101 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005102 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005103 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005104 .ops = &mv88e6390x_ops,
5105 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005106};
5107
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005108static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005109{
Vivien Didelota439c062016-04-17 13:23:58 -04005110 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005111
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005112 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5113 if (mv88e6xxx_table[i].prod_num == prod_num)
5114 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005115
Vivien Didelotb9b37712015-10-30 19:39:48 -04005116 return NULL;
5117}
5118
Vivien Didelotfad09c72016-06-21 12:28:20 -04005119static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005120{
5121 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005122 unsigned int prod_num, rev;
5123 u16 id;
5124 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005125
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005126 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005127 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005128 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005129 if (err)
5130 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005131
Vivien Didelot107fcc12017-06-12 12:37:36 -04005132 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5133 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005134
5135 info = mv88e6xxx_lookup_info(prod_num);
5136 if (!info)
5137 return -ENODEV;
5138
Vivien Didelotcaac8542016-06-20 13:14:09 -04005139 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005140 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005141
Vivien Didelotca070c12016-09-02 14:45:34 -04005142 err = mv88e6xxx_g2_require(chip);
5143 if (err)
5144 return err;
5145
Vivien Didelotfad09c72016-06-21 12:28:20 -04005146 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5147 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005148
5149 return 0;
5150}
5151
Vivien Didelotfad09c72016-06-21 12:28:20 -04005152static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005153{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005154 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005155
Vivien Didelotfad09c72016-06-21 12:28:20 -04005156 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5157 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005158 return NULL;
5159
Vivien Didelotfad09c72016-06-21 12:28:20 -04005160 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005161
Vivien Didelotfad09c72016-06-21 12:28:20 -04005162 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005163 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005164 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005165
Vivien Didelotfad09c72016-06-21 12:28:20 -04005166 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005167}
5168
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005169static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005170 int port,
5171 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005172{
Vivien Didelot04bed142016-08-31 18:06:13 -04005173 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005174
Andrew Lunn443d5a12016-12-03 04:35:18 +01005175 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005176}
5177
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005178static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05005179 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005180{
5181 /* We don't need any dynamic resource from the kernel (yet),
5182 * so skip the prepare phase.
5183 */
5184
5185 return 0;
5186}
5187
5188static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05005189 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005190{
Vivien Didelot04bed142016-08-31 18:06:13 -04005191 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005192
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005193 mv88e6xxx_reg_lock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005194 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04005195 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04005196 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
5197 port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005198 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005199}
5200
5201static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5202 const struct switchdev_obj_port_mdb *mdb)
5203{
Vivien Didelot04bed142016-08-31 18:06:13 -04005204 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005205 int err;
5206
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005207 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005208 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005209 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005210
5211 return err;
5212}
5213
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005214static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5215 struct dsa_mall_mirror_tc_entry *mirror,
5216 bool ingress)
5217{
5218 enum mv88e6xxx_egress_direction direction = ingress ?
5219 MV88E6XXX_EGRESS_DIR_INGRESS :
5220 MV88E6XXX_EGRESS_DIR_EGRESS;
5221 struct mv88e6xxx_chip *chip = ds->priv;
5222 bool other_mirrors = false;
5223 int i;
5224 int err;
5225
5226 if (!chip->info->ops->set_egress_port)
5227 return -EOPNOTSUPP;
5228
5229 mutex_lock(&chip->reg_lock);
5230 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5231 mirror->to_local_port) {
5232 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5233 other_mirrors |= ingress ?
5234 chip->ports[i].mirror_ingress :
5235 chip->ports[i].mirror_egress;
5236
5237 /* Can't change egress port when other mirror is active */
5238 if (other_mirrors) {
5239 err = -EBUSY;
5240 goto out;
5241 }
5242
5243 err = chip->info->ops->set_egress_port(chip,
5244 direction,
5245 mirror->to_local_port);
5246 if (err)
5247 goto out;
5248 }
5249
5250 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5251out:
5252 mutex_unlock(&chip->reg_lock);
5253
5254 return err;
5255}
5256
5257static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5258 struct dsa_mall_mirror_tc_entry *mirror)
5259{
5260 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5261 MV88E6XXX_EGRESS_DIR_INGRESS :
5262 MV88E6XXX_EGRESS_DIR_EGRESS;
5263 struct mv88e6xxx_chip *chip = ds->priv;
5264 bool other_mirrors = false;
5265 int i;
5266
5267 mutex_lock(&chip->reg_lock);
5268 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5269 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5270
5271 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5272 other_mirrors |= mirror->ingress ?
5273 chip->ports[i].mirror_ingress :
5274 chip->ports[i].mirror_egress;
5275
5276 /* Reset egress port when no other mirror is active */
5277 if (!other_mirrors) {
5278 if (chip->info->ops->set_egress_port(chip,
5279 direction,
5280 dsa_upstream_port(ds,
Colin Ian King4e4637b2019-11-12 13:05:23 +00005281 port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005282 dev_err(ds->dev, "failed to set egress port\n");
5283 }
5284
5285 mutex_unlock(&chip->reg_lock);
5286}
5287
Russell King4f859012019-02-20 15:35:05 -08005288static int mv88e6xxx_port_egress_floods(struct dsa_switch *ds, int port,
5289 bool unicast, bool multicast)
5290{
5291 struct mv88e6xxx_chip *chip = ds->priv;
5292 int err = -EOPNOTSUPP;
5293
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005294 mv88e6xxx_reg_lock(chip);
Russell King4f859012019-02-20 15:35:05 -08005295 if (chip->info->ops->port_set_egress_floods)
5296 err = chip->info->ops->port_set_egress_floods(chip, port,
5297 unicast,
5298 multicast);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005299 mv88e6xxx_reg_unlock(chip);
Russell King4f859012019-02-20 15:35:05 -08005300
5301 return err;
5302}
5303
Florian Fainellia82f67a2017-01-08 14:52:08 -08005304static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02005305 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005306 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005307 .teardown = mv88e6xxx_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07005308 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00005309 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07005310 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00005311 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07005312 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
5313 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005314 .get_strings = mv88e6xxx_get_strings,
5315 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
5316 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02005317 .port_enable = mv88e6xxx_port_enable,
5318 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02005319 .port_max_mtu = mv88e6xxx_get_max_mtu,
5320 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04005321 .get_mac_eee = mv88e6xxx_get_mac_eee,
5322 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005323 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005324 .get_eeprom = mv88e6xxx_get_eeprom,
5325 .set_eeprom = mv88e6xxx_set_eeprom,
5326 .get_regs_len = mv88e6xxx_get_regs_len,
5327 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04005328 .get_rxnfc = mv88e6xxx_get_rxnfc,
5329 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04005330 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005331 .port_bridge_join = mv88e6xxx_port_bridge_join,
5332 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Russell King4f859012019-02-20 15:35:05 -08005333 .port_egress_floods = mv88e6xxx_port_egress_floods,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005334 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04005335 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005336 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
5337 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
5338 .port_vlan_add = mv88e6xxx_port_vlan_add,
5339 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005340 .port_fdb_add = mv88e6xxx_port_fdb_add,
5341 .port_fdb_del = mv88e6xxx_port_fdb_del,
5342 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005343 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
5344 .port_mdb_add = mv88e6xxx_port_mdb_add,
5345 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005346 .port_mirror_add = mv88e6xxx_port_mirror_add,
5347 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04005348 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
5349 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005350 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
5351 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
5352 .port_txtstamp = mv88e6xxx_port_txtstamp,
5353 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
5354 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005355 .devlink_param_get = mv88e6xxx_devlink_param_get,
5356 .devlink_param_set = mv88e6xxx_devlink_param_set,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005357};
5358
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005359static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005360{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005361 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005362 struct dsa_switch *ds;
5363
Vivien Didelot7e99e342019-10-21 16:51:30 -04005364 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005365 if (!ds)
5366 return -ENOMEM;
5367
Vivien Didelot7e99e342019-10-21 16:51:30 -04005368 ds->dev = dev;
5369 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005370 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005371 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04005372 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04005373 ds->ageing_time_min = chip->info->age_time_coeff;
5374 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005375
5376 dev_set_drvdata(dev, ds);
5377
Vivien Didelot23c9ee42017-05-26 18:12:51 -04005378 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005379}
5380
Vivien Didelotfad09c72016-06-21 12:28:20 -04005381static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005382{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005383 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005384}
5385
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005386static const void *pdata_device_get_match_data(struct device *dev)
5387{
5388 const struct of_device_id *matches = dev->driver->of_match_table;
5389 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
5390
5391 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
5392 matches++) {
5393 if (!strcmp(pdata->compatible, matches->compatible))
5394 return matches->data;
5395 }
5396 return NULL;
5397}
5398
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005399/* There is no suspend to RAM support at DSA level yet, the switch configuration
5400 * would be lost after a power cycle so prevent it to be suspended.
5401 */
5402static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
5403{
5404 return -EOPNOTSUPP;
5405}
5406
5407static int __maybe_unused mv88e6xxx_resume(struct device *dev)
5408{
5409 return 0;
5410}
5411
5412static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
5413
Vivien Didelot57d32312016-06-20 13:13:58 -04005414static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005415{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005416 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04005417 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005418 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005419 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04005420 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005421 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02005422 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005423
Andrew Lunn7bb8c992018-05-31 00:15:42 +02005424 if (!np && !pdata)
5425 return -EINVAL;
5426
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005427 if (np)
5428 compat_info = of_device_get_match_data(dev);
5429
5430 if (pdata) {
5431 compat_info = pdata_device_get_match_data(dev);
5432
5433 if (!pdata->netdev)
5434 return -EINVAL;
5435
5436 for (port = 0; port < DSA_MAX_PORTS; port++) {
5437 if (!(pdata->enabled_ports & (1 << port)))
5438 continue;
5439 if (strcmp(pdata->cd.port_names[port], "cpu"))
5440 continue;
5441 pdata->cd.netdev[port] = &pdata->netdev->dev;
5442 break;
5443 }
5444 }
5445
Vivien Didelotcaac8542016-06-20 13:14:09 -04005446 if (!compat_info)
5447 return -EINVAL;
5448
Vivien Didelotfad09c72016-06-21 12:28:20 -04005449 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005450 if (!chip) {
5451 err = -ENOMEM;
5452 goto out;
5453 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005454
Vivien Didelotfad09c72016-06-21 12:28:20 -04005455 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04005456
Vivien Didelotfad09c72016-06-21 12:28:20 -04005457 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04005458 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005459 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005460
Andrew Lunnb4308f02016-11-21 23:26:55 +01005461 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005462 if (IS_ERR(chip->reset)) {
5463 err = PTR_ERR(chip->reset);
5464 goto out;
5465 }
Baruch Siach7b75e492019-06-27 21:17:39 +03005466 if (chip->reset)
5467 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01005468
Vivien Didelotfad09c72016-06-21 12:28:20 -04005469 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005470 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005471 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005472
Vivien Didelote57e5e72016-08-15 17:19:00 -04005473 mv88e6xxx_phy_init(chip);
5474
Andrew Lunn00baabe2018-05-19 22:31:35 +02005475 if (chip->info->ops->get_eeprom) {
5476 if (np)
5477 of_property_read_u32(np, "eeprom-length",
5478 &chip->eeprom_len);
5479 else
5480 chip->eeprom_len = pdata->eeprom_len;
5481 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005482
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005483 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005484 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005485 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02005486 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02005487 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02005488
Andrew Lunna27415d2019-05-01 00:10:50 +02005489 if (np) {
5490 chip->irq = of_irq_get(np, 0);
5491 if (chip->irq == -EPROBE_DEFER) {
5492 err = chip->irq;
5493 goto out;
5494 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02005495 }
5496
Andrew Lunna27415d2019-05-01 00:10:50 +02005497 if (pdata)
5498 chip->irq = pdata->irq;
5499
Andrew Lunn294d7112018-02-22 22:58:32 +01005500 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01005501 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01005502 * controllers
5503 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005504 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005505 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005506 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005507 else
5508 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005509 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005510
Andrew Lunn294d7112018-02-22 22:58:32 +01005511 if (err)
5512 goto out;
5513
5514 if (chip->info->g2_irqs > 0) {
5515 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005516 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01005517 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005518 }
5519
Andrew Lunn294d7112018-02-22 22:58:32 +01005520 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
5521 if (err)
5522 goto out_g2_irq;
5523
5524 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
5525 if (err)
5526 goto out_g1_atu_prob_irq;
5527
Andrew Lunna3c53be52017-01-24 14:53:50 +01005528 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02005529 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01005530 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005531
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005532 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005533 if (err)
5534 goto out_mdio;
5535
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005536 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02005537
5538out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01005539 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01005540out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005541 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01005542out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005543 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005544out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005545 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005546 mv88e6xxx_g2_irq_free(chip);
5547out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005548 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005549 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005550 else
5551 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005552out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005553 if (pdata)
5554 dev_put(pdata->netdev);
5555
Andrew Lunndc30c352016-10-16 19:56:49 +02005556 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005557}
5558
5559static void mv88e6xxx_remove(struct mdio_device *mdiodev)
5560{
5561 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04005562 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005563
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005564 if (chip->info->ptp_support) {
5565 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005566 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005567 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005568
Andrew Lunn930188c2016-08-22 16:01:03 +02005569 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005570 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005571 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005572
Andrew Lunn76f38f12018-03-17 20:21:09 +01005573 mv88e6xxx_g1_vtu_prob_irq_free(chip);
5574 mv88e6xxx_g1_atu_prob_irq_free(chip);
5575
5576 if (chip->info->g2_irqs > 0)
5577 mv88e6xxx_g2_irq_free(chip);
5578
Andrew Lunn76f38f12018-03-17 20:21:09 +01005579 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005580 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01005581 else
5582 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005583}
5584
5585static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04005586 {
5587 .compatible = "marvell,mv88e6085",
5588 .data = &mv88e6xxx_table[MV88E6085],
5589 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005590 {
5591 .compatible = "marvell,mv88e6190",
5592 .data = &mv88e6xxx_table[MV88E6190],
5593 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005594 {
5595 .compatible = "marvell,mv88e6250",
5596 .data = &mv88e6xxx_table[MV88E6250],
5597 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005598 { /* sentinel */ },
5599};
5600
5601MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
5602
5603static struct mdio_driver mv88e6xxx_driver = {
5604 .probe = mv88e6xxx_probe,
5605 .remove = mv88e6xxx_remove,
5606 .mdiodrv.driver = {
5607 .name = "mv88e6085",
5608 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005609 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005610 },
5611};
5612
Andrew Lunn7324d502019-04-27 19:19:10 +02005613mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00005614
5615MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
5616MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
5617MODULE_LICENSE("GPL");