blob: 51436494794423867415b894c92236cee9835a8a [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00002/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04003 * Marvell 88e6xxx Ethernet switch single-chip support
4 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00005 * Copyright (c) 2008 Marvell Semiconductor
6 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02007 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
8 *
Vivien Didelot4333d612017-03-28 15:10:36 -04009 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
10 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 */
12
Vivien Didelot19fb7f62019-08-09 18:47:55 -040013#include <linux/bitfield.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000014#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070015#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020016#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070017#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020018#include <linux/interrupt.h>
19#include <linux/irq.h>
20#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000021#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000022#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020023#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000024#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040025#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020026#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020027#include <linux/of_mdio.h>
Andrew Lunn877b7cb2018-05-19 22:31:34 +020028#include <linux/platform_data/mv88e6xxx.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000029#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010030#include <linux/gpio/consumer.h>
Russell Kingc9a23562018-05-10 13:17:35 -070031#include <linux/phylink.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000032#include <net/dsa.h>
Vivien Didelotec561272016-09-02 14:45:33 -040033
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -040034#include "chip.h"
Andrew Lunn9dd43aa2020-09-18 21:11:05 +020035#include "devlink.h"
Vivien Didelota935c052016-09-29 12:21:53 -040036#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040037#include "global2.h"
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +010038#include "hwtstamp.h"
Andrew Lunn10fa5bf2017-05-26 01:03:20 +020039#include "phy.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010040#include "port.h"
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +010041#include "ptp.h"
Andrew Lunn6d917822017-05-26 01:03:21 +020042#include "serdes.h"
Vivien Didelote7ba0fa2019-05-03 19:28:22 -040043#include "smi.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000044
Vivien Didelotfad09c72016-06-21 12:28:20 -040045static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040046{
Vivien Didelotfad09c72016-06-21 12:28:20 -040047 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
48 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040049 dump_stack();
50 }
51}
52
Vivien Didelotec561272016-09-02 14:45:33 -040053int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -040054{
55 int err;
56
Vivien Didelotfad09c72016-06-21 12:28:20 -040057 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -040058
Vivien Didelotfad09c72016-06-21 12:28:20 -040059 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040060 if (err)
61 return err;
62
Vivien Didelotfad09c72016-06-21 12:28:20 -040063 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -040064 addr, reg, *val);
65
66 return 0;
67}
68
Vivien Didelotec561272016-09-02 14:45:33 -040069int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -040070{
71 int err;
72
Vivien Didelotfad09c72016-06-21 12:28:20 -040073 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -040074
Vivien Didelotfad09c72016-06-21 12:28:20 -040075 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040076 if (err)
77 return err;
78
Vivien Didelotfad09c72016-06-21 12:28:20 -040079 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -040080 addr, reg, val);
81
82 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000083}
84
Vivien Didelot683f2242019-08-09 18:47:54 -040085int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg,
86 u16 mask, u16 val)
87{
88 u16 data;
89 int err;
90 int i;
91
92 /* There's no bus specific operation to wait for a mask */
93 for (i = 0; i < 16; i++) {
94 err = mv88e6xxx_read(chip, addr, reg, &data);
95 if (err)
96 return err;
97
98 if ((data & mask) == val)
99 return 0;
100
101 usleep_range(1000, 2000);
102 }
103
104 dev_err(chip->dev, "Timeout while waiting for switch\n");
105 return -ETIMEDOUT;
106}
107
Vivien Didelot19fb7f62019-08-09 18:47:55 -0400108int mv88e6xxx_wait_bit(struct mv88e6xxx_chip *chip, int addr, int reg,
109 int bit, int val)
110{
111 return mv88e6xxx_wait_mask(chip, addr, reg, BIT(bit),
112 val ? BIT(bit) : 0x0000);
113}
114
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200115struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
Andrew Lunna3c53be52017-01-24 14:53:50 +0100116{
117 struct mv88e6xxx_mdio_bus *mdio_bus;
118
119 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
120 list);
121 if (!mdio_bus)
122 return NULL;
123
124 return mdio_bus->bus;
125}
126
Andrew Lunndc30c352016-10-16 19:56:49 +0200127static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
128{
129 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
130 unsigned int n = d->hwirq;
131
132 chip->g1_irq.masked |= (1 << n);
133}
134
135static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
136{
137 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
138 unsigned int n = d->hwirq;
139
140 chip->g1_irq.masked &= ~(1 << n);
141}
142
Andrew Lunn294d7112018-02-22 22:58:32 +0100143static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200144{
Andrew Lunndc30c352016-10-16 19:56:49 +0200145 unsigned int nhandled = 0;
146 unsigned int sub_irq;
147 unsigned int n;
148 u16 reg;
John David Anglin7c0db242019-02-11 13:40:21 -0500149 u16 ctl1;
Andrew Lunndc30c352016-10-16 19:56:49 +0200150 int err;
151
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000152 mv88e6xxx_reg_lock(chip);
Vivien Didelot82466922017-06-15 12:13:59 -0400153 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000154 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200155
156 if (err)
157 goto out;
158
John David Anglin7c0db242019-02-11 13:40:21 -0500159 do {
160 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
161 if (reg & (1 << n)) {
162 sub_irq = irq_find_mapping(chip->g1_irq.domain,
163 n);
164 handle_nested_irq(sub_irq);
165 ++nhandled;
166 }
Andrew Lunndc30c352016-10-16 19:56:49 +0200167 }
John David Anglin7c0db242019-02-11 13:40:21 -0500168
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000169 mv88e6xxx_reg_lock(chip);
John David Anglin7c0db242019-02-11 13:40:21 -0500170 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1);
171 if (err)
172 goto unlock;
173 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
174unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000175 mv88e6xxx_reg_unlock(chip);
John David Anglin7c0db242019-02-11 13:40:21 -0500176 if (err)
177 goto out;
178 ctl1 &= GENMASK(chip->g1_irq.nirqs, 0);
179 } while (reg & ctl1);
180
Andrew Lunndc30c352016-10-16 19:56:49 +0200181out:
182 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
183}
184
Andrew Lunn294d7112018-02-22 22:58:32 +0100185static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
186{
187 struct mv88e6xxx_chip *chip = dev_id;
188
189 return mv88e6xxx_g1_irq_thread_work(chip);
190}
191
Andrew Lunndc30c352016-10-16 19:56:49 +0200192static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
193{
194 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
195
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000196 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200197}
198
199static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
200{
201 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
202 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
203 u16 reg;
204 int err;
205
Vivien Didelotd77f4322017-06-15 12:14:03 -0400206 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200207 if (err)
208 goto out;
209
210 reg &= ~mask;
211 reg |= (~chip->g1_irq.masked & mask);
212
Vivien Didelotd77f4322017-06-15 12:14:03 -0400213 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200214 if (err)
215 goto out;
216
217out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000218 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200219}
220
Bhumika Goyal6eb15e22017-08-19 16:25:52 +0530221static const struct irq_chip mv88e6xxx_g1_irq_chip = {
Andrew Lunndc30c352016-10-16 19:56:49 +0200222 .name = "mv88e6xxx-g1",
223 .irq_mask = mv88e6xxx_g1_irq_mask,
224 .irq_unmask = mv88e6xxx_g1_irq_unmask,
225 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
226 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
227};
228
229static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
230 unsigned int irq,
231 irq_hw_number_t hwirq)
232{
233 struct mv88e6xxx_chip *chip = d->host_data;
234
235 irq_set_chip_data(irq, d->host_data);
236 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
237 irq_set_noprobe(irq);
238
239 return 0;
240}
241
242static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
243 .map = mv88e6xxx_g1_irq_domain_map,
244 .xlate = irq_domain_xlate_twocell,
245};
246
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200247/* To be called with reg_lock held */
Andrew Lunn294d7112018-02-22 22:58:32 +0100248static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200249{
250 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100251 u16 mask;
252
Vivien Didelotd77f4322017-06-15 12:14:03 -0400253 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100254 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400255 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100256
Andreas Färber5edef2f2016-11-27 23:26:28 +0100257 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100258 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200259 irq_dispose_mapping(virq);
260 }
261
Andrew Lunna3db3d32016-11-20 20:14:14 +0100262 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200263}
264
Andrew Lunn294d7112018-02-22 22:58:32 +0100265static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
266{
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200267 /*
268 * free_irq must be called without reg_lock taken because the irq
269 * handler takes this lock, too.
270 */
Andrew Lunn294d7112018-02-22 22:58:32 +0100271 free_irq(chip->irq, chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200272
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000273 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200274 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000275 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100276}
277
278static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200279{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100280 int err, irq, virq;
281 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200282
283 chip->g1_irq.nirqs = chip->info->g1_irqs;
284 chip->g1_irq.domain = irq_domain_add_simple(
285 NULL, chip->g1_irq.nirqs, 0,
286 &mv88e6xxx_g1_irq_domain_ops, chip);
287 if (!chip->g1_irq.domain)
288 return -ENOMEM;
289
290 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
291 irq_create_mapping(chip->g1_irq.domain, irq);
292
293 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
294 chip->g1_irq.masked = ~0;
295
Vivien Didelotd77f4322017-06-15 12:14:03 -0400296 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200297 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100298 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200299
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100300 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200301
Vivien Didelotd77f4322017-06-15 12:14:03 -0400302 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200303 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100304 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200305
306 /* Reading the interrupt status clears (most of) them */
Vivien Didelot82466922017-06-15 12:13:59 -0400307 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200308 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100309 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200310
Andrew Lunndc30c352016-10-16 19:56:49 +0200311 return 0;
312
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100313out_disable:
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100314 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400315 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100316
317out_mapping:
318 for (irq = 0; irq < 16; irq++) {
319 virq = irq_find_mapping(chip->g1_irq.domain, irq);
320 irq_dispose_mapping(virq);
321 }
322
323 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200324
325 return err;
326}
327
Andrew Lunn294d7112018-02-22 22:58:32 +0100328static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
329{
Andrew Lunnf6d97582019-02-23 17:43:56 +0100330 static struct lock_class_key lock_key;
331 static struct lock_class_key request_key;
Andrew Lunn294d7112018-02-22 22:58:32 +0100332 int err;
333
334 err = mv88e6xxx_g1_irq_setup_common(chip);
335 if (err)
336 return err;
337
Andrew Lunnf6d97582019-02-23 17:43:56 +0100338 /* These lock classes tells lockdep that global 1 irqs are in
339 * a different category than their parent GPIO, so it won't
340 * report false recursion.
341 */
342 irq_set_lockdep_class(chip->irq, &lock_key, &request_key);
343
Andrew Lunn30953832020-01-06 17:13:48 +0100344 snprintf(chip->irq_name, sizeof(chip->irq_name),
345 "mv88e6xxx-%s", dev_name(chip->dev));
346
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000347 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100348 err = request_threaded_irq(chip->irq, NULL,
349 mv88e6xxx_g1_irq_thread_fn,
Marek Behún03403762018-08-30 02:13:50 +0200350 IRQF_ONESHOT | IRQF_SHARED,
Andrew Lunn30953832020-01-06 17:13:48 +0100351 chip->irq_name, chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000352 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100353 if (err)
354 mv88e6xxx_g1_irq_free_common(chip);
355
356 return err;
357}
358
359static void mv88e6xxx_irq_poll(struct kthread_work *work)
360{
361 struct mv88e6xxx_chip *chip = container_of(work,
362 struct mv88e6xxx_chip,
363 irq_poll_work.work);
364 mv88e6xxx_g1_irq_thread_work(chip);
365
366 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
367 msecs_to_jiffies(100));
368}
369
370static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
371{
372 int err;
373
374 err = mv88e6xxx_g1_irq_setup_common(chip);
375 if (err)
376 return err;
377
378 kthread_init_delayed_work(&chip->irq_poll_work,
379 mv88e6xxx_irq_poll);
380
Florian Fainelli3f8b8692019-02-21 20:09:27 -0800381 chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
Andrew Lunn294d7112018-02-22 22:58:32 +0100382 if (IS_ERR(chip->kworker))
383 return PTR_ERR(chip->kworker);
384
385 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
386 msecs_to_jiffies(100));
387
388 return 0;
389}
390
391static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
392{
393 kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
394 kthread_destroy_worker(chip->kworker);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200395
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000396 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200397 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000398 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100399}
400
Russell King64d47d52020-03-14 10:15:38 +0000401static int mv88e6xxx_port_config_interface(struct mv88e6xxx_chip *chip,
402 int port, phy_interface_t interface)
403{
404 int err;
405
406 if (chip->info->ops->port_set_rgmii_delay) {
407 err = chip->info->ops->port_set_rgmii_delay(chip, port,
408 interface);
409 if (err && err != -EOPNOTSUPP)
410 return err;
411 }
412
413 if (chip->info->ops->port_set_cmode) {
414 err = chip->info->ops->port_set_cmode(chip, port,
415 interface);
416 if (err && err != -EOPNOTSUPP)
417 return err;
418 }
419
420 return 0;
421}
422
Russell Kinga5a68582020-03-14 10:15:43 +0000423static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
424 int link, int speed, int duplex, int pause,
425 phy_interface_t mode)
Vivien Didelotd78343d2016-11-04 03:23:36 +0100426{
427 int err;
428
429 if (!chip->info->ops->port_set_link)
430 return 0;
431
432 /* Port's MAC control must not be changed unless the link is down */
Hubert Feurstein43c8e0a2019-07-30 12:11:42 +0200433 err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100434 if (err)
435 return err;
436
Russell Kingf365c6f2020-03-14 10:15:53 +0000437 if (chip->info->ops->port_set_speed_duplex) {
438 err = chip->info->ops->port_set_speed_duplex(chip, port,
439 speed, duplex);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100440 if (err && err != -EOPNOTSUPP)
441 goto restore_link;
442 }
443
Andrew Lunn7cbbee02019-03-08 01:21:27 +0100444 if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
445 mode = chip->info->ops->port_max_speed_mode(port);
446
Andrew Lunn54186b92018-08-09 15:38:37 +0200447 if (chip->info->ops->port_set_pause) {
448 err = chip->info->ops->port_set_pause(chip, port, pause);
449 if (err)
450 goto restore_link;
451 }
452
Russell King64d47d52020-03-14 10:15:38 +0000453 err = mv88e6xxx_port_config_interface(chip, port, mode);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100454restore_link:
455 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400456 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100457
458 return err;
459}
460
Marek Vasutd700ec42018-09-12 00:15:24 +0200461static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
462{
463 struct mv88e6xxx_chip *chip = ds->priv;
464
465 return port < chip->info->num_internal_phys;
466}
467
Russell King5d5b2312020-03-14 10:16:03 +0000468static int mv88e6xxx_port_ppu_updates(struct mv88e6xxx_chip *chip, int port)
469{
470 u16 reg;
471 int err;
472
473 err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
474 if (err) {
475 dev_err(chip->dev,
476 "p%d: %s: failed to read port status\n",
477 port, __func__);
478 return err;
479 }
480
481 return !!(reg & MV88E6XXX_PORT_STS_PHY_DETECT);
482}
483
Russell Kinga5a68582020-03-14 10:15:43 +0000484static int mv88e6xxx_serdes_pcs_get_state(struct dsa_switch *ds, int port,
485 struct phylink_link_state *state)
486{
487 struct mv88e6xxx_chip *chip = ds->priv;
488 u8 lane;
489 int err;
490
491 mv88e6xxx_reg_lock(chip);
492 lane = mv88e6xxx_serdes_get_lane(chip, port);
493 if (lane && chip->info->ops->serdes_pcs_get_state)
494 err = chip->info->ops->serdes_pcs_get_state(chip, port, lane,
495 state);
496 else
497 err = -EOPNOTSUPP;
498 mv88e6xxx_reg_unlock(chip);
499
500 return err;
501}
502
503static int mv88e6xxx_serdes_pcs_config(struct mv88e6xxx_chip *chip, int port,
504 unsigned int mode,
505 phy_interface_t interface,
506 const unsigned long *advertise)
507{
508 const struct mv88e6xxx_ops *ops = chip->info->ops;
509 u8 lane;
510
511 if (ops->serdes_pcs_config) {
512 lane = mv88e6xxx_serdes_get_lane(chip, port);
513 if (lane)
514 return ops->serdes_pcs_config(chip, port, lane, mode,
515 interface, advertise);
516 }
517
518 return 0;
519}
520
521static void mv88e6xxx_serdes_pcs_an_restart(struct dsa_switch *ds, int port)
522{
523 struct mv88e6xxx_chip *chip = ds->priv;
524 const struct mv88e6xxx_ops *ops;
525 int err = 0;
526 u8 lane;
527
528 ops = chip->info->ops;
529
530 if (ops->serdes_pcs_an_restart) {
531 mv88e6xxx_reg_lock(chip);
532 lane = mv88e6xxx_serdes_get_lane(chip, port);
533 if (lane)
534 err = ops->serdes_pcs_an_restart(chip, port, lane);
535 mv88e6xxx_reg_unlock(chip);
536
537 if (err)
538 dev_err(ds->dev, "p%d: failed to restart AN\n", port);
539 }
540}
541
542static int mv88e6xxx_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port,
543 unsigned int mode,
544 int speed, int duplex)
545{
546 const struct mv88e6xxx_ops *ops = chip->info->ops;
547 u8 lane;
548
549 if (!phylink_autoneg_inband(mode) && ops->serdes_pcs_link_up) {
550 lane = mv88e6xxx_serdes_get_lane(chip, port);
551 if (lane)
552 return ops->serdes_pcs_link_up(chip, port, lane,
553 speed, duplex);
554 }
555
556 return 0;
557}
558
Russell King6c422e32018-08-09 15:38:39 +0200559static void mv88e6065_phylink_validate(struct mv88e6xxx_chip *chip, int port,
560 unsigned long *mask,
561 struct phylink_link_state *state)
562{
563 if (!phy_interface_mode_is_8023z(state->interface)) {
564 /* 10M and 100M are only supported in non-802.3z mode */
565 phylink_set(mask, 10baseT_Half);
566 phylink_set(mask, 10baseT_Full);
567 phylink_set(mask, 100baseT_Half);
568 phylink_set(mask, 100baseT_Full);
569 }
570}
571
572static void mv88e6185_phylink_validate(struct mv88e6xxx_chip *chip, int port,
573 unsigned long *mask,
574 struct phylink_link_state *state)
575{
576 /* FIXME: if the port is in 1000Base-X mode, then it only supports
577 * 1000M FD speeds. In this case, CMODE will indicate 5.
578 */
579 phylink_set(mask, 1000baseT_Full);
580 phylink_set(mask, 1000baseX_Full);
581
582 mv88e6065_phylink_validate(chip, port, mask, state);
583}
584
Marek Behúne3af71a2019-02-25 12:39:55 +0100585static void mv88e6341_phylink_validate(struct mv88e6xxx_chip *chip, int port,
586 unsigned long *mask,
587 struct phylink_link_state *state)
588{
589 if (port >= 5)
590 phylink_set(mask, 2500baseX_Full);
591
592 /* No ethtool bits for 200Mbps */
593 phylink_set(mask, 1000baseT_Full);
594 phylink_set(mask, 1000baseX_Full);
595
596 mv88e6065_phylink_validate(chip, port, mask, state);
597}
598
Russell King6c422e32018-08-09 15:38:39 +0200599static void mv88e6352_phylink_validate(struct mv88e6xxx_chip *chip, int port,
600 unsigned long *mask,
601 struct phylink_link_state *state)
602{
603 /* No ethtool bits for 200Mbps */
604 phylink_set(mask, 1000baseT_Full);
605 phylink_set(mask, 1000baseX_Full);
606
607 mv88e6065_phylink_validate(chip, port, mask, state);
608}
609
610static void mv88e6390_phylink_validate(struct mv88e6xxx_chip *chip, int port,
611 unsigned long *mask,
612 struct phylink_link_state *state)
613{
Andrew Lunnec260162019-02-08 22:25:44 +0100614 if (port >= 9) {
Russell King6c422e32018-08-09 15:38:39 +0200615 phylink_set(mask, 2500baseX_Full);
Andrew Lunnec260162019-02-08 22:25:44 +0100616 phylink_set(mask, 2500baseT_Full);
617 }
Russell King6c422e32018-08-09 15:38:39 +0200618
619 /* No ethtool bits for 200Mbps */
620 phylink_set(mask, 1000baseT_Full);
621 phylink_set(mask, 1000baseX_Full);
622
623 mv88e6065_phylink_validate(chip, port, mask, state);
624}
625
626static void mv88e6390x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
627 unsigned long *mask,
628 struct phylink_link_state *state)
629{
630 if (port >= 9) {
631 phylink_set(mask, 10000baseT_Full);
632 phylink_set(mask, 10000baseKR_Full);
633 }
634
635 mv88e6390_phylink_validate(chip, port, mask, state);
636}
637
Russell Kingc9a23562018-05-10 13:17:35 -0700638static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
639 unsigned long *supported,
640 struct phylink_link_state *state)
641{
Russell King6c422e32018-08-09 15:38:39 +0200642 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
643 struct mv88e6xxx_chip *chip = ds->priv;
644
645 /* Allow all the expected bits */
646 phylink_set(mask, Autoneg);
647 phylink_set(mask, Pause);
648 phylink_set_port_modes(mask);
649
650 if (chip->info->ops->phylink_validate)
651 chip->info->ops->phylink_validate(chip, port, mask, state);
652
653 bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
654 bitmap_and(state->advertising, state->advertising, mask,
655 __ETHTOOL_LINK_MODE_MASK_NBITS);
656
657 /* We can only operate at 2500BaseX or 1000BaseX. If requested
658 * to advertise both, only report advertising at 2500BaseX.
659 */
660 phylink_helper_basex_speed(state);
Russell Kingc9a23562018-05-10 13:17:35 -0700661}
662
Russell Kingc9a23562018-05-10 13:17:35 -0700663static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
664 unsigned int mode,
665 const struct phylink_link_state *state)
666{
667 struct mv88e6xxx_chip *chip = ds->priv;
Russell Kingfad58192020-07-19 12:00:35 +0100668 struct mv88e6xxx_port *p;
Russell King64d47d52020-03-14 10:15:38 +0000669 int err;
Russell Kingc9a23562018-05-10 13:17:35 -0700670
Russell Kingfad58192020-07-19 12:00:35 +0100671 p = &chip->ports[port];
672
Russell King64d47d52020-03-14 10:15:38 +0000673 /* FIXME: is this the correct test? If we're in fixed mode on an
674 * internal port, why should we process this any different from
675 * PHY mode? On the other hand, the port may be automedia between
676 * an internal PHY and the serdes...
677 */
Marek Vasutd700ec42018-09-12 00:15:24 +0200678 if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
Russell Kingc9a23562018-05-10 13:17:35 -0700679 return;
680
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000681 mv88e6xxx_reg_lock(chip);
Russell Kingfad58192020-07-19 12:00:35 +0100682 /* In inband mode, the link may come up at any time while the link
683 * is not forced down. Force the link down while we reconfigure the
684 * interface mode.
Russell King64d47d52020-03-14 10:15:38 +0000685 */
Russell Kingfad58192020-07-19 12:00:35 +0100686 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
687 chip->info->ops->port_set_link)
688 chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
689
Russell King64d47d52020-03-14 10:15:38 +0000690 err = mv88e6xxx_port_config_interface(chip, port, state->interface);
Russell Kinga5a68582020-03-14 10:15:43 +0000691 if (err && err != -EOPNOTSUPP)
692 goto err_unlock;
693
694 err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
695 state->advertising);
696 /* FIXME: we should restart negotiation if something changed - which
697 * is something we get if we convert to using phylinks PCS operations.
698 */
699 if (err > 0)
700 err = 0;
701
Russell Kingfad58192020-07-19 12:00:35 +0100702 /* Undo the forced down state above after completing configuration
703 * irrespective of its state on entry, which allows the link to come up.
704 */
705 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
706 chip->info->ops->port_set_link)
707 chip->info->ops->port_set_link(chip, port, LINK_UNFORCED);
708
709 p->interface = state->interface;
710
Russell Kinga5a68582020-03-14 10:15:43 +0000711err_unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000712 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700713
714 if (err && err != -EOPNOTSUPP)
Russell King64d47d52020-03-14 10:15:38 +0000715 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700716}
717
Russell Kingc9a23562018-05-10 13:17:35 -0700718static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
719 unsigned int mode,
720 phy_interface_t interface)
721{
Russell King30c4a5b2020-02-26 10:23:51 +0000722 struct mv88e6xxx_chip *chip = ds->priv;
723 const struct mv88e6xxx_ops *ops;
724 int err = 0;
725
726 ops = chip->info->ops;
727
Russell King5d5b2312020-03-14 10:16:03 +0000728 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200729 if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
Chris Packham4efe76622020-11-24 17:34:37 +1300730 mode == MLO_AN_FIXED) && ops->port_sync_link)
731 err = ops->port_sync_link(chip, port, mode, false);
Russell King5d5b2312020-03-14 10:16:03 +0000732 mv88e6xxx_reg_unlock(chip);
Russell King30c4a5b2020-02-26 10:23:51 +0000733
Russell King5d5b2312020-03-14 10:16:03 +0000734 if (err)
735 dev_err(chip->dev,
736 "p%d: failed to force MAC link down\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700737}
738
739static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
740 unsigned int mode, phy_interface_t interface,
Russell King5b502a72020-02-26 10:23:46 +0000741 struct phy_device *phydev,
742 int speed, int duplex,
743 bool tx_pause, bool rx_pause)
Russell Kingc9a23562018-05-10 13:17:35 -0700744{
Russell King30c4a5b2020-02-26 10:23:51 +0000745 struct mv88e6xxx_chip *chip = ds->priv;
746 const struct mv88e6xxx_ops *ops;
747 int err = 0;
748
749 ops = chip->info->ops;
750
Russell King5d5b2312020-03-14 10:16:03 +0000751 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200752 if (!mv88e6xxx_port_ppu_updates(chip, port) || mode == MLO_AN_FIXED) {
Russell King30c4a5b2020-02-26 10:23:51 +0000753 /* FIXME: for an automedia port, should we force the link
754 * down here - what if the link comes up due to "other" media
755 * while we're bringing the port up, how is the exclusivity
Russell Kinga5a68582020-03-14 10:15:43 +0000756 * handled in the Marvell hardware? E.g. port 2 on 88E6390
Russell King30c4a5b2020-02-26 10:23:51 +0000757 * shared between internal PHY and Serdes.
758 */
Russell Kinga5a68582020-03-14 10:15:43 +0000759 err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
760 duplex);
761 if (err)
762 goto error;
763
Russell Kingf365c6f2020-03-14 10:15:53 +0000764 if (ops->port_set_speed_duplex) {
765 err = ops->port_set_speed_duplex(chip, port,
766 speed, duplex);
Russell King30c4a5b2020-02-26 10:23:51 +0000767 if (err && err != -EOPNOTSUPP)
768 goto error;
769 }
770
Chris Packham4efe76622020-11-24 17:34:37 +1300771 if (ops->port_sync_link)
772 err = ops->port_sync_link(chip, port, mode, true);
Russell King30c4a5b2020-02-26 10:23:51 +0000773 }
Russell King5d5b2312020-03-14 10:16:03 +0000774error:
775 mv88e6xxx_reg_unlock(chip);
776
777 if (err && err != -EOPNOTSUPP)
778 dev_err(ds->dev,
779 "p%d: failed to configure MAC link up\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700780}
781
Andrew Lunna605a0f2016-11-21 23:26:58 +0100782static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000783{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100784 if (!chip->info->ops->stats_snapshot)
785 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000786
Andrew Lunna605a0f2016-11-21 23:26:58 +0100787 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000788}
789
Andrew Lunne413e7e2015-04-02 04:06:38 +0200790static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100791 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
792 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
793 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
794 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
795 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
796 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
797 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
798 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
799 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
800 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
801 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
802 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
803 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
804 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
805 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
806 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
807 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
808 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
809 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
810 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
811 { "single", 4, 0x14, STATS_TYPE_BANK0, },
812 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
813 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
814 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
815 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
816 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
817 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
818 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
819 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
820 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
821 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
822 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
823 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
824 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
825 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
826 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
827 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
828 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
829 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
830 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
831 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
832 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
833 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
834 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
835 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
836 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
837 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
838 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
839 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
840 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
841 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
842 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
843 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
844 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
845 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
846 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
847 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
848 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
849 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200850};
851
Vivien Didelotfad09c72016-06-21 12:28:20 -0400852static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100853 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100854 int port, u16 bank1_select,
855 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200856{
Andrew Lunn80c46272015-06-20 18:42:30 +0200857 u32 low;
858 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100859 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200860 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200861 u64 value;
862
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100863 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100864 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200865 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
866 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800867 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200868
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200869 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100870 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200871 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
872 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800873 return U64_MAX;
Rasmus Villemoes84b3fd12019-05-29 07:02:11 +0000874 low |= ((u32)reg) << 16;
Andrew Lunn80c46272015-06-20 18:42:30 +0200875 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100876 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100877 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100878 reg = bank1_select;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500879 fallthrough;
Andrew Lunndfafe442016-11-21 23:27:02 +0100880 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100881 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100882 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100883 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100884 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500885 break;
886 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800887 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200888 }
Andrew Lunn6e46e2d2019-02-28 18:14:03 +0100889 value = (((u64)high) << 32) | low;
Andrew Lunn80c46272015-06-20 18:42:30 +0200890 return value;
891}
892
Andrew Lunn436fe172018-03-01 02:02:29 +0100893static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
894 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100895{
896 struct mv88e6xxx_hw_stat *stat;
897 int i, j;
898
899 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
900 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100901 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100902 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
903 ETH_GSTRING_LEN);
904 j++;
905 }
906 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100907
908 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100909}
910
Andrew Lunn436fe172018-03-01 02:02:29 +0100911static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
912 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100913{
Andrew Lunn436fe172018-03-01 02:02:29 +0100914 return mv88e6xxx_stats_get_strings(chip, data,
915 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100916}
917
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000918static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
919 uint8_t *data)
920{
921 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
922}
923
Andrew Lunn436fe172018-03-01 02:02:29 +0100924static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
925 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100926{
Andrew Lunn436fe172018-03-01 02:02:29 +0100927 return mv88e6xxx_stats_get_strings(chip, data,
928 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100929}
930
Andrew Lunn65f60e42018-03-28 23:50:28 +0200931static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
932 "atu_member_violation",
933 "atu_miss_violation",
934 "atu_full_violation",
935 "vtu_member_violation",
936 "vtu_miss_violation",
937};
938
939static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
940{
941 unsigned int i;
942
943 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
944 strlcpy(data + i * ETH_GSTRING_LEN,
945 mv88e6xxx_atu_vtu_stats_strings[i],
946 ETH_GSTRING_LEN);
947}
948
Andrew Lunndfafe442016-11-21 23:27:02 +0100949static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700950 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100951{
Vivien Didelot04bed142016-08-31 18:06:13 -0400952 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100953 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100954
Florian Fainelli89f09042018-04-25 12:12:50 -0700955 if (stringset != ETH_SS_STATS)
956 return;
957
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000958 mv88e6xxx_reg_lock(chip);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100959
Andrew Lunndfafe442016-11-21 23:27:02 +0100960 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100961 count = chip->info->ops->stats_get_strings(chip, data);
962
963 if (chip->info->ops->serdes_get_strings) {
964 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200965 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100966 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100967
Andrew Lunn65f60e42018-03-28 23:50:28 +0200968 data += count * ETH_GSTRING_LEN;
969 mv88e6xxx_atu_vtu_get_strings(data);
970
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000971 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100972}
973
974static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
975 int types)
976{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100977 struct mv88e6xxx_hw_stat *stat;
978 int i, j;
979
980 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
981 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100982 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100983 j++;
984 }
985 return j;
986}
987
Andrew Lunndfafe442016-11-21 23:27:02 +0100988static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
989{
990 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
991 STATS_TYPE_PORT);
992}
993
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000994static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
995{
996 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
997}
998
Andrew Lunndfafe442016-11-21 23:27:02 +0100999static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1000{
1001 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1002 STATS_TYPE_BANK1);
1003}
1004
Florian Fainelli89f09042018-04-25 12:12:50 -07001005static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +01001006{
1007 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +01001008 int serdes_count = 0;
1009 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +01001010
Florian Fainelli89f09042018-04-25 12:12:50 -07001011 if (sset != ETH_SS_STATS)
1012 return 0;
1013
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001014 mv88e6xxx_reg_lock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001015 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +01001016 count = chip->info->ops->stats_get_sset_count(chip);
1017 if (count < 0)
1018 goto out;
1019
1020 if (chip->info->ops->serdes_get_sset_count)
1021 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1022 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +02001023 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +01001024 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001025 goto out;
1026 }
1027 count += serdes_count;
1028 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1029
Andrew Lunn436fe172018-03-01 02:02:29 +01001030out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001031 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001032
Andrew Lunn436fe172018-03-01 02:02:29 +01001033 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +01001034}
1035
Andrew Lunn436fe172018-03-01 02:02:29 +01001036static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1037 uint64_t *data, int types,
1038 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +01001039{
1040 struct mv88e6xxx_hw_stat *stat;
1041 int i, j;
1042
1043 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1044 stat = &mv88e6xxx_hw_stats[i];
1045 if (stat->type & types) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001046 mv88e6xxx_reg_lock(chip);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001047 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1048 bank1_select,
1049 histogram);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001050 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001051
Andrew Lunn052f9472016-11-21 23:27:03 +01001052 j++;
1053 }
1054 }
Andrew Lunn436fe172018-03-01 02:02:29 +01001055 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +01001056}
1057
Andrew Lunn436fe172018-03-01 02:02:29 +01001058static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1059 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001060{
1061 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001062 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001063 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +01001064}
1065
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001066static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1067 uint64_t *data)
1068{
1069 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
1070 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1071}
1072
Andrew Lunn436fe172018-03-01 02:02:29 +01001073static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1074 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001075{
1076 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001077 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001078 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1079 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001080}
1081
Andrew Lunn436fe172018-03-01 02:02:29 +01001082static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1083 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +01001084{
1085 return mv88e6xxx_stats_get_stats(chip, port, data,
1086 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001087 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1088 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001089}
1090
Andrew Lunn65f60e42018-03-28 23:50:28 +02001091static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1092 uint64_t *data)
1093{
1094 *data++ = chip->ports[port].atu_member_violation;
1095 *data++ = chip->ports[port].atu_miss_violation;
1096 *data++ = chip->ports[port].atu_full_violation;
1097 *data++ = chip->ports[port].vtu_member_violation;
1098 *data++ = chip->ports[port].vtu_miss_violation;
1099}
1100
Andrew Lunn052f9472016-11-21 23:27:03 +01001101static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1102 uint64_t *data)
1103{
Andrew Lunn436fe172018-03-01 02:02:29 +01001104 int count = 0;
1105
Andrew Lunn052f9472016-11-21 23:27:03 +01001106 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +01001107 count = chip->info->ops->stats_get_stats(chip, port, data);
1108
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001109 mv88e6xxx_reg_lock(chip);
Andrew Lunn436fe172018-03-01 02:02:29 +01001110 if (chip->info->ops->serdes_get_stats) {
1111 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001112 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +01001113 }
Andrew Lunn65f60e42018-03-28 23:50:28 +02001114 data += count;
1115 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001116 mv88e6xxx_reg_unlock(chip);
Andrew Lunn052f9472016-11-21 23:27:03 +01001117}
1118
Vivien Didelotf81ec902016-05-09 13:22:58 -04001119static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1120 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001121{
Vivien Didelot04bed142016-08-31 18:06:13 -04001122 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001123 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001124
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001125 mv88e6xxx_reg_lock(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001126
Andrew Lunna605a0f2016-11-21 23:26:58 +01001127 ret = mv88e6xxx_stats_snapshot(chip, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001128 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001129
1130 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001131 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001132
1133 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001134
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001135}
Ben Hutchings98e67302011-11-25 14:36:19 +00001136
Vivien Didelotf81ec902016-05-09 13:22:58 -04001137static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001138{
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001139 struct mv88e6xxx_chip *chip = ds->priv;
1140 int len;
1141
1142 len = 32 * sizeof(u16);
1143 if (chip->info->ops->serdes_get_regs_len)
1144 len += chip->info->ops->serdes_get_regs_len(chip, port);
1145
1146 return len;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001147}
1148
Vivien Didelotf81ec902016-05-09 13:22:58 -04001149static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1150 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001151{
Vivien Didelot04bed142016-08-31 18:06:13 -04001152 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001153 int err;
1154 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001155 u16 *p = _p;
1156 int i;
1157
Vivien Didelota5f39322018-12-17 16:05:21 -05001158 regs->version = chip->info->prod_num;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001159
1160 memset(p, 0xff, 32 * sizeof(u16));
1161
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001162 mv88e6xxx_reg_lock(chip);
Vivien Didelot23062512016-05-09 13:22:45 -04001163
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001164 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001165
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001166 err = mv88e6xxx_port_read(chip, port, i, &reg);
1167 if (!err)
1168 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001169 }
Vivien Didelot23062512016-05-09 13:22:45 -04001170
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001171 if (chip->info->ops->serdes_get_regs)
1172 chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1173
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001174 mv88e6xxx_reg_unlock(chip);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001175}
1176
Vivien Didelot08f50062017-08-01 16:32:41 -04001177static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1178 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001179{
Vivien Didelot5480db62017-08-01 16:32:40 -04001180 /* Nothing to do on the port's MAC */
1181 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001182}
1183
Vivien Didelot08f50062017-08-01 16:32:41 -04001184static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1185 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001186{
Vivien Didelot5480db62017-08-01 16:32:40 -04001187 /* Nothing to do on the port's MAC */
1188 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001189}
1190
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001191/* Mask of the local ports allowed to receive frames from a given fabric port */
Vivien Didelote5887a22017-03-30 17:37:11 -04001192static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001193{
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001194 struct dsa_switch *ds = chip->ds;
1195 struct dsa_switch_tree *dst = ds->dst;
Vivien Didelote5887a22017-03-30 17:37:11 -04001196 struct net_device *br;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001197 struct dsa_port *dp;
1198 bool found = false;
Vivien Didelote5887a22017-03-30 17:37:11 -04001199 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001200
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001201 list_for_each_entry(dp, &dst->ports, list) {
1202 if (dp->ds->index == dev && dp->index == port) {
1203 found = true;
1204 break;
1205 }
1206 }
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001207
Vivien Didelote5887a22017-03-30 17:37:11 -04001208 /* Prevent frames from unknown switch or port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001209 if (!found)
Vivien Didelote5887a22017-03-30 17:37:11 -04001210 return 0;
1211
1212 /* Frames from DSA links and CPU ports can egress any local port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001213 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
Vivien Didelote5887a22017-03-30 17:37:11 -04001214 return mv88e6xxx_port_mask(chip);
1215
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001216 br = dp->bridge_dev;
Vivien Didelote5887a22017-03-30 17:37:11 -04001217 pvlan = 0;
1218
1219 /* Frames from user ports can egress any local DSA links and CPU ports,
1220 * as well as any local member of their bridge group.
1221 */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001222 list_for_each_entry(dp, &dst->ports, list)
1223 if (dp->ds == ds &&
1224 (dp->type == DSA_PORT_TYPE_CPU ||
1225 dp->type == DSA_PORT_TYPE_DSA ||
1226 (br && dp->bridge_dev == br)))
1227 pvlan |= BIT(dp->index);
Vivien Didelote5887a22017-03-30 17:37:11 -04001228
1229 return pvlan;
1230}
1231
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001232static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001233{
1234 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001235
1236 /* prevent frames from going back out of the port they came in on */
1237 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001238
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001239 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001240}
1241
Vivien Didelotf81ec902016-05-09 13:22:58 -04001242static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1243 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001244{
Vivien Didelot04bed142016-08-31 18:06:13 -04001245 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001246 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001247
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001248 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001249 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001250 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001251
1252 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001253 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001254}
1255
Vivien Didelot93e18d62018-05-11 17:16:35 -04001256static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1257{
1258 int err;
1259
1260 if (chip->info->ops->ieee_pri_map) {
1261 err = chip->info->ops->ieee_pri_map(chip);
1262 if (err)
1263 return err;
1264 }
1265
1266 if (chip->info->ops->ip_pri_map) {
1267 err = chip->info->ops->ip_pri_map(chip);
1268 if (err)
1269 return err;
1270 }
1271
1272 return 0;
1273}
1274
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001275static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1276{
Vivien Didelotc5f51762019-10-30 22:09:13 -04001277 struct dsa_switch *ds = chip->ds;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001278 int target, port;
1279 int err;
1280
1281 if (!chip->info->global2_addr)
1282 return 0;
1283
1284 /* Initialize the routing port to the 32 possible target devices */
1285 for (target = 0; target < 32; target++) {
Vivien Didelotc5f51762019-10-30 22:09:13 -04001286 port = dsa_routing_port(ds, target);
1287 if (port == ds->num_ports)
1288 port = 0x1f;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001289
1290 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1291 if (err)
1292 return err;
1293 }
1294
Vivien Didelot02317e62018-05-09 11:38:49 -04001295 if (chip->info->ops->set_cascade_port) {
1296 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1297 err = chip->info->ops->set_cascade_port(chip, port);
1298 if (err)
1299 return err;
1300 }
1301
Vivien Didelot23c98912018-05-09 11:38:50 -04001302 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1303 if (err)
1304 return err;
1305
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001306 return 0;
1307}
1308
Vivien Didelotb28f8722018-04-26 21:56:44 -04001309static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1310{
1311 /* Clear all trunk masks and mapping */
1312 if (chip->info->global2_addr)
1313 return mv88e6xxx_g2_trunk_clear(chip);
1314
1315 return 0;
1316}
1317
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001318static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1319{
1320 if (chip->info->ops->rmu_disable)
1321 return chip->info->ops->rmu_disable(chip);
1322
1323 return 0;
1324}
1325
Vivien Didelot9e907d72017-07-17 13:03:43 -04001326static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1327{
1328 if (chip->info->ops->pot_clear)
1329 return chip->info->ops->pot_clear(chip);
1330
1331 return 0;
1332}
1333
Vivien Didelot51c901a2017-07-17 13:03:41 -04001334static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1335{
1336 if (chip->info->ops->mgmt_rsvd2cpu)
1337 return chip->info->ops->mgmt_rsvd2cpu(chip);
1338
1339 return 0;
1340}
1341
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001342static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1343{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001344 int err;
1345
Vivien Didelotdaefc942017-03-11 16:12:54 -05001346 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1347 if (err)
1348 return err;
1349
Rasmus Villemoes49506a92020-12-10 12:06:44 +01001350 /* The chips that have a "learn2all" bit in Global1, ATU
1351 * Control are precisely those whose port registers have a
1352 * Message Port bit in Port Control 1 and hence implement
1353 * ->port_setup_message_port.
1354 */
1355 if (chip->info->ops->port_setup_message_port) {
1356 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1357 if (err)
1358 return err;
1359 }
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001360
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001361 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1362}
1363
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001364static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1365{
1366 int port;
1367 int err;
1368
1369 if (!chip->info->ops->irl_init_all)
1370 return 0;
1371
1372 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1373 /* Disable ingress rate limiting by resetting all per port
1374 * ingress rate limit resources to their initial state.
1375 */
1376 err = chip->info->ops->irl_init_all(chip, port);
1377 if (err)
1378 return err;
1379 }
1380
1381 return 0;
1382}
1383
Vivien Didelot04a69a12017-10-13 14:18:05 -04001384static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1385{
1386 if (chip->info->ops->set_switch_mac) {
1387 u8 addr[ETH_ALEN];
1388
1389 eth_random_addr(addr);
1390
1391 return chip->info->ops->set_switch_mac(chip, addr);
1392 }
1393
1394 return 0;
1395}
1396
Vivien Didelot17a15942017-03-30 17:37:09 -04001397static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1398{
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001399 struct dsa_switch_tree *dst = chip->ds->dst;
1400 struct dsa_switch *ds;
1401 struct dsa_port *dp;
Vivien Didelot17a15942017-03-30 17:37:09 -04001402 u16 pvlan = 0;
1403
1404 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001405 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001406
1407 /* Skip the local source device, which uses in-chip port VLAN */
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001408 if (dev != chip->ds->index) {
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001409 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001410
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001411 ds = dsa_switch_find(dst->index, dev);
1412 dp = ds ? dsa_to_port(ds, port) : NULL;
1413 if (dp && dp->lag_dev) {
1414 /* As the PVT is used to limit flooding of
1415 * FORWARD frames, which use the LAG ID as the
1416 * source port, we must translate dev/port to
1417 * the special "LAG device" in the PVT, using
1418 * the LAG ID as the port number.
1419 */
1420 dev = MV88E6XXX_G2_PVT_ADRR_DEV_TRUNK;
1421 port = dsa_lag_id(dst, dp->lag_dev);
1422 }
1423 }
1424
Vivien Didelot17a15942017-03-30 17:37:09 -04001425 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1426}
1427
Vivien Didelot81228992017-03-30 17:37:08 -04001428static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1429{
Vivien Didelot17a15942017-03-30 17:37:09 -04001430 int dev, port;
1431 int err;
1432
Vivien Didelot81228992017-03-30 17:37:08 -04001433 if (!mv88e6xxx_has_pvt(chip))
1434 return 0;
1435
1436 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1437 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1438 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001439 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1440 if (err)
1441 return err;
1442
1443 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1444 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1445 err = mv88e6xxx_pvt_map(chip, dev, port);
1446 if (err)
1447 return err;
1448 }
1449 }
1450
1451 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001452}
1453
Vivien Didelot749efcb2016-09-22 16:49:24 -04001454static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1455{
1456 struct mv88e6xxx_chip *chip = ds->priv;
1457 int err;
1458
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001459 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001460 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001461 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001462
1463 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001464 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001465}
1466
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001467static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1468{
Tobias Waldekranze545f862020-11-10 19:57:20 +01001469 if (!mv88e6xxx_max_vid(chip))
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001470 return 0;
1471
1472 return mv88e6xxx_g1_vtu_flush(chip);
1473}
1474
Vivien Didelotf1394b782017-05-01 14:05:22 -04001475static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1476 struct mv88e6xxx_vtu_entry *entry)
1477{
1478 if (!chip->info->ops->vtu_getnext)
1479 return -EOPNOTSUPP;
1480
1481 return chip->info->ops->vtu_getnext(chip, entry);
1482}
1483
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001484static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1485 struct mv88e6xxx_vtu_entry *entry)
1486{
1487 if (!chip->info->ops->vtu_loadpurge)
1488 return -EOPNOTSUPP;
1489
1490 return chip->info->ops->vtu_loadpurge(chip, entry);
1491}
1492
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001493int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001494{
Vivien Didelot425d2d32019-08-01 14:36:34 -04001495 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001496 int i, err;
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001497 u16 fid;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001498
1499 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1500
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001501 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001502 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001503 err = mv88e6xxx_port_get_fid(chip, i, &fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001504 if (err)
1505 return err;
1506
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001507 set_bit(fid, fid_bitmap);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001508 }
1509
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001510 /* Set every FID bit used by the VLAN entries */
Tobias Waldekranze545f862020-11-10 19:57:20 +01001511 vlan.vid = mv88e6xxx_max_vid(chip);
Vivien Didelot425d2d32019-08-01 14:36:34 -04001512 vlan.valid = false;
1513
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001514 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001515 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001516 if (err)
1517 return err;
1518
1519 if (!vlan.valid)
1520 break;
1521
1522 set_bit(vlan.fid, fid_bitmap);
Tobias Waldekranze545f862020-11-10 19:57:20 +01001523 } while (vlan.vid < mv88e6xxx_max_vid(chip));
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001524
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001525 return 0;
1526}
1527
1528static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1529{
1530 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1531 int err;
1532
1533 err = mv88e6xxx_fid_map(chip, fid_bitmap);
1534 if (err)
1535 return err;
1536
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001537 /* The reset value 0x000 is used to indicate that multiple address
1538 * databases are not needed. Return the next positive available.
1539 */
1540 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001541 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001542 return -ENOSPC;
1543
1544 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001545 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001546}
1547
Vivien Didelotda9c3592016-02-12 12:09:40 -05001548static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001549 u16 vid)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001550{
Vivien Didelot04bed142016-08-31 18:06:13 -04001551 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001552 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001553 int i, err;
1554
Vladimir Oltean3e85f582021-01-09 02:01:47 +02001555 if (!vid)
1556 return -EOPNOTSUPP;
1557
Andrew Lunndb06ae412017-09-25 23:32:20 +02001558 /* DSA and CPU ports have to be members of multiple vlans */
1559 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1560 return 0;
1561
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001562 vlan.vid = vid - 1;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001563 vlan.valid = false;
1564
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001565 err = mv88e6xxx_vtu_getnext(chip, &vlan);
1566 if (err)
1567 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001568
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001569 if (!vlan.valid)
1570 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001571
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001572 if (vlan.vid != vid)
1573 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001574
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001575 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1576 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1577 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001578
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001579 if (!dsa_to_port(ds, i)->slave)
1580 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001581
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001582 if (vlan.member[i] ==
1583 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1584 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001585
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001586 if (dsa_to_port(ds, i)->bridge_dev ==
1587 dsa_to_port(ds, port)->bridge_dev)
1588 break; /* same bridge, check next VLAN */
Vivien Didelotda9c3592016-02-12 12:09:40 -05001589
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001590 if (!dsa_to_port(ds, i)->bridge_dev)
1591 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001592
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001593 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1594 port, vlan.vid, i,
1595 netdev_name(dsa_to_port(ds, i)->bridge_dev));
1596 return -EOPNOTSUPP;
1597 }
Vivien Didelotda9c3592016-02-12 12:09:40 -05001598
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001599 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001600}
1601
Vivien Didelotf81ec902016-05-09 13:22:58 -04001602static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
Vladimir Olteanbae33f22021-01-09 02:01:50 +02001603 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001604{
Vivien Didelot04bed142016-08-31 18:06:13 -04001605 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001606 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1607 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001608 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001609
Vladimir Olteanbae33f22021-01-09 02:01:50 +02001610 if (!mv88e6xxx_max_vid(chip))
1611 return -EOPNOTSUPP;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001612
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001613 mv88e6xxx_reg_lock(chip);
Vivien Didelot385a0992016-11-04 03:23:31 +01001614 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001615 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001616
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001617 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001618}
1619
Vivien Didelot57d32312016-06-20 13:13:58 -04001620static int
1621mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001622 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001623{
Vivien Didelot04bed142016-08-31 18:06:13 -04001624 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001625 int err;
1626
Tobias Waldekranze545f862020-11-10 19:57:20 +01001627 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001628 return -EOPNOTSUPP;
1629
Vivien Didelotda9c3592016-02-12 12:09:40 -05001630 /* If the requested port doesn't belong to the same bridge as the VLAN
1631 * members, do not support it (yet) and fallback to software VLAN.
1632 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001633 mv88e6xxx_reg_lock(chip);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001634 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001635 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001636
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001637 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001638}
1639
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001640static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1641 const unsigned char *addr, u16 vid,
1642 u8 state)
1643{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001644 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001645 struct mv88e6xxx_vtu_entry vlan;
1646 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001647 int err;
1648
1649 /* Null VLAN ID corresponds to the port private database */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001650 if (vid == 0) {
1651 err = mv88e6xxx_port_get_fid(chip, port, &fid);
1652 if (err)
1653 return err;
1654 } else {
1655 vlan.vid = vid - 1;
1656 vlan.valid = false;
1657
1658 err = mv88e6xxx_vtu_getnext(chip, &vlan);
1659 if (err)
1660 return err;
1661
1662 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1663 if (vlan.vid != vid || !vlan.valid)
1664 return -EOPNOTSUPP;
1665
1666 fid = vlan.fid;
1667 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001668
Vivien Didelotd8291a92019-09-07 16:00:47 -04001669 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001670 ether_addr_copy(entry.mac, addr);
1671 eth_addr_dec(entry.mac);
1672
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001673 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001674 if (err)
1675 return err;
1676
1677 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001678 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001679 memset(&entry, 0, sizeof(entry));
1680 ether_addr_copy(entry.mac, addr);
1681 }
1682
1683 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001684 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001685 entry.portvec &= ~BIT(port);
1686 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001687 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001688 } else {
1689 entry.portvec |= BIT(port);
1690 entry.state = state;
1691 }
1692
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001693 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001694}
1695
Vivien Didelotda7dc872019-09-07 16:00:49 -04001696static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1697 const struct mv88e6xxx_policy *policy)
1698{
1699 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1700 enum mv88e6xxx_policy_action action = policy->action;
1701 const u8 *addr = policy->addr;
1702 u16 vid = policy->vid;
1703 u8 state;
1704 int err;
1705 int id;
1706
1707 if (!chip->info->ops->port_set_policy)
1708 return -EOPNOTSUPP;
1709
1710 switch (mapping) {
1711 case MV88E6XXX_POLICY_MAPPING_DA:
1712 case MV88E6XXX_POLICY_MAPPING_SA:
1713 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1714 state = 0; /* Dissociate the port and address */
1715 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1716 is_multicast_ether_addr(addr))
1717 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1718 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1719 is_unicast_ether_addr(addr))
1720 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1721 else
1722 return -EOPNOTSUPP;
1723
1724 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1725 state);
1726 if (err)
1727 return err;
1728 break;
1729 default:
1730 return -EOPNOTSUPP;
1731 }
1732
1733 /* Skip the port's policy clearing if the mapping is still in use */
1734 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1735 idr_for_each_entry(&chip->policies, policy, id)
1736 if (policy->port == port &&
1737 policy->mapping == mapping &&
1738 policy->action != action)
1739 return 0;
1740
1741 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1742}
1743
1744static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1745 struct ethtool_rx_flow_spec *fs)
1746{
1747 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1748 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1749 enum mv88e6xxx_policy_mapping mapping;
1750 enum mv88e6xxx_policy_action action;
1751 struct mv88e6xxx_policy *policy;
1752 u16 vid = 0;
1753 u8 *addr;
1754 int err;
1755 int id;
1756
1757 if (fs->location != RX_CLS_LOC_ANY)
1758 return -EINVAL;
1759
1760 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1761 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1762 else
1763 return -EOPNOTSUPP;
1764
1765 switch (fs->flow_type & ~FLOW_EXT) {
1766 case ETHER_FLOW:
1767 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1768 is_zero_ether_addr(mac_mask->h_source)) {
1769 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1770 addr = mac_entry->h_dest;
1771 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1772 !is_zero_ether_addr(mac_mask->h_source)) {
1773 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1774 addr = mac_entry->h_source;
1775 } else {
1776 /* Cannot support DA and SA mapping in the same rule */
1777 return -EOPNOTSUPP;
1778 }
1779 break;
1780 default:
1781 return -EOPNOTSUPP;
1782 }
1783
1784 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001785 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001786 return -EOPNOTSUPP;
1787 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1788 }
1789
1790 idr_for_each_entry(&chip->policies, policy, id) {
1791 if (policy->port == port && policy->mapping == mapping &&
1792 policy->action == action && policy->vid == vid &&
1793 ether_addr_equal(policy->addr, addr))
1794 return -EEXIST;
1795 }
1796
1797 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1798 if (!policy)
1799 return -ENOMEM;
1800
1801 fs->location = 0;
1802 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1803 GFP_KERNEL);
1804 if (err) {
1805 devm_kfree(chip->dev, policy);
1806 return err;
1807 }
1808
1809 memcpy(&policy->fs, fs, sizeof(*fs));
1810 ether_addr_copy(policy->addr, addr);
1811 policy->mapping = mapping;
1812 policy->action = action;
1813 policy->port = port;
1814 policy->vid = vid;
1815
1816 err = mv88e6xxx_policy_apply(chip, port, policy);
1817 if (err) {
1818 idr_remove(&chip->policies, fs->location);
1819 devm_kfree(chip->dev, policy);
1820 return err;
1821 }
1822
1823 return 0;
1824}
1825
1826static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1827 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1828{
1829 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1830 struct mv88e6xxx_chip *chip = ds->priv;
1831 struct mv88e6xxx_policy *policy;
1832 int err;
1833 int id;
1834
1835 mv88e6xxx_reg_lock(chip);
1836
1837 switch (rxnfc->cmd) {
1838 case ETHTOOL_GRXCLSRLCNT:
1839 rxnfc->data = 0;
1840 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1841 rxnfc->rule_cnt = 0;
1842 idr_for_each_entry(&chip->policies, policy, id)
1843 if (policy->port == port)
1844 rxnfc->rule_cnt++;
1845 err = 0;
1846 break;
1847 case ETHTOOL_GRXCLSRULE:
1848 err = -ENOENT;
1849 policy = idr_find(&chip->policies, fs->location);
1850 if (policy) {
1851 memcpy(fs, &policy->fs, sizeof(*fs));
1852 err = 0;
1853 }
1854 break;
1855 case ETHTOOL_GRXCLSRLALL:
1856 rxnfc->data = 0;
1857 rxnfc->rule_cnt = 0;
1858 idr_for_each_entry(&chip->policies, policy, id)
1859 if (policy->port == port)
1860 rule_locs[rxnfc->rule_cnt++] = id;
1861 err = 0;
1862 break;
1863 default:
1864 err = -EOPNOTSUPP;
1865 break;
1866 }
1867
1868 mv88e6xxx_reg_unlock(chip);
1869
1870 return err;
1871}
1872
1873static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1874 struct ethtool_rxnfc *rxnfc)
1875{
1876 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1877 struct mv88e6xxx_chip *chip = ds->priv;
1878 struct mv88e6xxx_policy *policy;
1879 int err;
1880
1881 mv88e6xxx_reg_lock(chip);
1882
1883 switch (rxnfc->cmd) {
1884 case ETHTOOL_SRXCLSRLINS:
1885 err = mv88e6xxx_policy_insert(chip, port, fs);
1886 break;
1887 case ETHTOOL_SRXCLSRLDEL:
1888 err = -ENOENT;
1889 policy = idr_remove(&chip->policies, fs->location);
1890 if (policy) {
1891 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
1892 err = mv88e6xxx_policy_apply(chip, port, policy);
1893 devm_kfree(chip->dev, policy);
1894 }
1895 break;
1896 default:
1897 err = -EOPNOTSUPP;
1898 break;
1899 }
1900
1901 mv88e6xxx_reg_unlock(chip);
1902
1903 return err;
1904}
1905
Andrew Lunn87fa8862017-11-09 22:29:56 +01001906static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1907 u16 vid)
1908{
1909 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1910 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1911
1912 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1913}
1914
1915static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1916{
1917 int port;
1918 int err;
1919
1920 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1921 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1922 if (err)
1923 return err;
1924 }
1925
1926 return 0;
1927}
1928
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001929static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00001930 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001931{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001932 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001933 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001934 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001935
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001936 vlan.vid = vid - 1;
1937 vlan.valid = false;
1938
1939 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001940 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001941 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001942
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001943 if (vlan.vid != vid || !vlan.valid) {
1944 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001945
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001946 err = mv88e6xxx_atu_new(chip, &vlan.fid);
1947 if (err)
1948 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01001949
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001950 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1951 if (i == port)
1952 vlan.member[i] = member;
1953 else
1954 vlan.member[i] = non_member;
1955
1956 vlan.vid = vid;
1957 vlan.valid = true;
1958
1959 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1960 if (err)
1961 return err;
1962
1963 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
1964 if (err)
1965 return err;
1966 } else if (vlan.member[port] != member) {
1967 vlan.member[port] = member;
1968
1969 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1970 if (err)
1971 return err;
Russell King933b4422020-02-26 17:14:26 +00001972 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001973 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
1974 port, vid);
1975 }
1976
1977 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001978}
1979
Vladimir Oltean1958d582021-01-09 02:01:53 +02001980static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1981 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001982{
Vivien Didelot04bed142016-08-31 18:06:13 -04001983 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001984 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1985 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Russell King933b4422020-02-26 17:14:26 +00001986 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001987 u8 member;
Vladimir Oltean1958d582021-01-09 02:01:53 +02001988 int err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001989
Vladimir Oltean1958d582021-01-09 02:01:53 +02001990 err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
1991 if (err)
1992 return err;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001993
Vivien Didelotc91498e2017-06-07 18:12:13 -04001994 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001995 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001996 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001997 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001998 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001999 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002000
Russell King933b4422020-02-26 17:14:26 +00002001 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
2002 * and then the CPU port. Do not warn for duplicates for the CPU port.
2003 */
2004 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
2005
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002006 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002007
Vladimir Oltean1958d582021-01-09 02:01:53 +02002008 err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
2009 if (err) {
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002010 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2011 vlan->vid, untagged ? 'u' : 't');
Vladimir Oltean1958d582021-01-09 02:01:53 +02002012 goto out;
2013 }
Vivien Didelot76e398a2015-11-01 12:33:55 -05002014
Vladimir Oltean1958d582021-01-09 02:01:53 +02002015 if (pvid) {
2016 err = mv88e6xxx_port_set_pvid(chip, port, vlan->vid);
2017 if (err) {
2018 dev_err(ds->dev, "p%d: failed to set PVID %d\n",
2019 port, vlan->vid);
2020 goto out;
2021 }
2022 }
2023out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002024 mv88e6xxx_reg_unlock(chip);
Vladimir Oltean1958d582021-01-09 02:01:53 +02002025
2026 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002027}
2028
Vivien Didelot521098922019-08-01 14:36:36 -04002029static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2030 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002031{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002032 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002033 int i, err;
2034
Vivien Didelot521098922019-08-01 14:36:36 -04002035 if (!vid)
2036 return -EOPNOTSUPP;
2037
2038 vlan.vid = vid - 1;
2039 vlan.valid = false;
2040
2041 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002042 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002043 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002044
Vivien Didelot521098922019-08-01 14:36:36 -04002045 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2046 * tell switchdev that this VLAN is likely handled in software.
2047 */
2048 if (vlan.vid != vid || !vlan.valid ||
2049 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002050 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002051
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002052 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002053
2054 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002055 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002056 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002057 if (vlan.member[i] !=
2058 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002059 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002060 break;
2061 }
2062 }
2063
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002064 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002065 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002066 return err;
2067
Vivien Didelote606ca32017-03-11 16:12:55 -05002068 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002069}
2070
Vivien Didelotf81ec902016-05-09 13:22:58 -04002071static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2072 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002073{
Vivien Didelot04bed142016-08-31 18:06:13 -04002074 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002075 int err = 0;
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002076 u16 pvid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002077
Tobias Waldekranze545f862020-11-10 19:57:20 +01002078 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04002079 return -EOPNOTSUPP;
2080
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002081 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002082
Vivien Didelot77064f32016-11-04 03:23:30 +01002083 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002084 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002085 goto unlock;
2086
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002087 err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
2088 if (err)
2089 goto unlock;
2090
2091 if (vlan->vid == pvid) {
2092 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002093 if (err)
2094 goto unlock;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002095 }
2096
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002097unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002098 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002099
2100 return err;
2101}
2102
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002103static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2104 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002105{
Vivien Didelot04bed142016-08-31 18:06:13 -04002106 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002107 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002108
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002109 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002110 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2111 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002112 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002113
2114 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002115}
2116
Vivien Didelotf81ec902016-05-09 13:22:58 -04002117static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002118 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002119{
Vivien Didelot04bed142016-08-31 18:06:13 -04002120 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002121 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002122
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002123 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002124 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002125 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002126
Vivien Didelot83dabd12016-08-31 11:50:04 -04002127 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002128}
2129
Vivien Didelot83dabd12016-08-31 11:50:04 -04002130static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2131 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002132 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002133{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002134 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002135 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002136 int err;
2137
Vivien Didelotd8291a92019-09-07 16:00:47 -04002138 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002139 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002140
2141 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002142 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002143 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002144 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002145
Vivien Didelotd8291a92019-09-07 16:00:47 -04002146 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002147 break;
2148
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002149 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002150 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002151
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002152 if (!is_unicast_ether_addr(addr.mac))
2153 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002154
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002155 is_static = (addr.state ==
2156 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2157 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002158 if (err)
2159 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002160 } while (!is_broadcast_ether_addr(addr.mac));
2161
2162 return err;
2163}
2164
Vivien Didelot83dabd12016-08-31 11:50:04 -04002165static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002166 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002167{
Vivien Didelot425d2d32019-08-01 14:36:34 -04002168 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002169 u16 fid;
2170 int err;
2171
2172 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002173 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002174 if (err)
2175 return err;
2176
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002177 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002178 if (err)
2179 return err;
2180
2181 /* Dump VLANs' Filtering Information Databases */
Tobias Waldekranze545f862020-11-10 19:57:20 +01002182 vlan.vid = mv88e6xxx_max_vid(chip);
Vivien Didelot425d2d32019-08-01 14:36:34 -04002183 vlan.valid = false;
2184
Vivien Didelot83dabd12016-08-31 11:50:04 -04002185 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04002186 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002187 if (err)
2188 return err;
2189
2190 if (!vlan.valid)
2191 break;
2192
2193 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002194 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002195 if (err)
2196 return err;
Tobias Waldekranze545f862020-11-10 19:57:20 +01002197 } while (vlan.vid < mv88e6xxx_max_vid(chip));
Vivien Didelot83dabd12016-08-31 11:50:04 -04002198
2199 return err;
2200}
2201
Vivien Didelotf81ec902016-05-09 13:22:58 -04002202static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002203 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002204{
Vivien Didelot04bed142016-08-31 18:06:13 -04002205 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002206 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002207
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002208 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002209 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002210 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002211
2212 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002213}
2214
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002215static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2216 struct net_device *br)
2217{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002218 struct dsa_switch *ds = chip->ds;
2219 struct dsa_switch_tree *dst = ds->dst;
2220 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002221 int err;
2222
Vivien Didelotef2025e2019-10-21 16:51:27 -04002223 list_for_each_entry(dp, &dst->ports, list) {
2224 if (dp->bridge_dev == br) {
2225 if (dp->ds == ds) {
2226 /* This is a local bridge group member,
2227 * remap its Port VLAN Map.
2228 */
2229 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2230 if (err)
2231 return err;
2232 } else {
2233 /* This is an external bridge group member,
2234 * remap its cross-chip Port VLAN Table entry.
2235 */
2236 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2237 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002238 if (err)
2239 return err;
2240 }
2241 }
2242 }
2243
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002244 return 0;
2245}
2246
Vivien Didelotf81ec902016-05-09 13:22:58 -04002247static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002248 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002249{
Vivien Didelot04bed142016-08-31 18:06:13 -04002250 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002251 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002252
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002253 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002254 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002255 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002256
Vivien Didelot466dfa02016-02-26 13:16:05 -05002257 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002258}
2259
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002260static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2261 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002262{
Vivien Didelot04bed142016-08-31 18:06:13 -04002263 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002264
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002265 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002266 if (mv88e6xxx_bridge_map(chip, br) ||
2267 mv88e6xxx_port_vlan_map(chip, port))
2268 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002269 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002270}
2271
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002272static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2273 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002274 int port, struct net_device *br)
2275{
2276 struct mv88e6xxx_chip *chip = ds->priv;
2277 int err;
2278
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002279 if (tree_index != ds->dst->index)
2280 return 0;
2281
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002282 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002283 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002284 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002285
2286 return err;
2287}
2288
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002289static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2290 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002291 int port, struct net_device *br)
2292{
2293 struct mv88e6xxx_chip *chip = ds->priv;
2294
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002295 if (tree_index != ds->dst->index)
2296 return;
2297
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002298 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002299 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002300 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002301 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002302}
2303
Vivien Didelot17e708b2016-12-05 17:30:27 -05002304static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2305{
2306 if (chip->info->ops->reset)
2307 return chip->info->ops->reset(chip);
2308
2309 return 0;
2310}
2311
Vivien Didelot309eca62016-12-05 17:30:26 -05002312static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2313{
2314 struct gpio_desc *gpiod = chip->reset;
2315
2316 /* If there is a GPIO connected to the reset pin, toggle it */
2317 if (gpiod) {
2318 gpiod_set_value_cansleep(gpiod, 1);
2319 usleep_range(10000, 20000);
2320 gpiod_set_value_cansleep(gpiod, 0);
2321 usleep_range(10000, 20000);
Andrew Lunna3dcb3e2020-11-16 08:43:01 -08002322
2323 mv88e6xxx_g1_wait_eeprom_done(chip);
Vivien Didelot309eca62016-12-05 17:30:26 -05002324 }
2325}
2326
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002327static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2328{
2329 int i, err;
2330
2331 /* Set all ports to the Disabled state */
2332 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002333 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002334 if (err)
2335 return err;
2336 }
2337
2338 /* Wait for transmit queues to drain,
2339 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2340 */
2341 usleep_range(2000, 4000);
2342
2343 return 0;
2344}
2345
Vivien Didelotfad09c72016-06-21 12:28:20 -04002346static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002347{
Vivien Didelota935c052016-09-29 12:21:53 -04002348 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002349
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002350 err = mv88e6xxx_disable_ports(chip);
2351 if (err)
2352 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002353
Vivien Didelot309eca62016-12-05 17:30:26 -05002354 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002355
Vivien Didelot17e708b2016-12-05 17:30:27 -05002356 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002357}
2358
Vivien Didelot43145572017-03-11 16:12:59 -05002359static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002360 enum mv88e6xxx_frame_mode frame,
2361 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002362{
2363 int err;
2364
Vivien Didelot43145572017-03-11 16:12:59 -05002365 if (!chip->info->ops->port_set_frame_mode)
2366 return -EOPNOTSUPP;
2367
2368 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002369 if (err)
2370 return err;
2371
Vivien Didelot43145572017-03-11 16:12:59 -05002372 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2373 if (err)
2374 return err;
2375
2376 if (chip->info->ops->port_set_ether_type)
2377 return chip->info->ops->port_set_ether_type(chip, port, etype);
2378
2379 return 0;
2380}
2381
2382static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2383{
2384 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002385 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002386 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002387}
2388
2389static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2390{
2391 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002392 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002393 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002394}
2395
2396static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2397{
2398 return mv88e6xxx_set_port_mode(chip, port,
2399 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002400 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2401 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002402}
2403
2404static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2405{
2406 if (dsa_is_dsa_port(chip->ds, port))
2407 return mv88e6xxx_set_port_mode_dsa(chip, port);
2408
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002409 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002410 return mv88e6xxx_set_port_mode_normal(chip, port);
2411
2412 /* Setup CPU port mode depending on its supported tag format */
2413 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2414 return mv88e6xxx_set_port_mode_dsa(chip, port);
2415
2416 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2417 return mv88e6xxx_set_port_mode_edsa(chip, port);
2418
2419 return -EINVAL;
2420}
2421
Vivien Didelotea698f42017-03-11 16:12:50 -05002422static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2423{
2424 bool message = dsa_is_dsa_port(chip->ds, port);
2425
2426 return mv88e6xxx_port_set_message_port(chip, port, message);
2427}
2428
Vivien Didelot601aeed2017-03-11 16:13:00 -05002429static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2430{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002431 struct dsa_switch *ds = chip->ds;
David S. Miller407308f2019-06-15 13:35:29 -07002432 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002433
David S. Miller407308f2019-06-15 13:35:29 -07002434 /* Upstream ports flood frames with unknown unicast or multicast DA */
2435 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2436 if (chip->info->ops->port_set_egress_floods)
2437 return chip->info->ops->port_set_egress_floods(chip, port,
2438 flood, flood);
Vivien Didelot601aeed2017-03-11 16:13:00 -05002439
David S. Miller407308f2019-06-15 13:35:29 -07002440 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002441}
2442
Vivien Didelot45de77f2019-08-31 16:18:36 -04002443static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2444{
2445 struct mv88e6xxx_port *mvp = dev_id;
2446 struct mv88e6xxx_chip *chip = mvp->chip;
2447 irqreturn_t ret = IRQ_NONE;
2448 int port = mvp->port;
2449 u8 lane;
2450
2451 mv88e6xxx_reg_lock(chip);
2452 lane = mv88e6xxx_serdes_get_lane(chip, port);
2453 if (lane)
2454 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2455 mv88e6xxx_reg_unlock(chip);
2456
2457 return ret;
2458}
2459
2460static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
2461 u8 lane)
2462{
2463 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2464 unsigned int irq;
2465 int err;
2466
2467 /* Nothing to request if this SERDES port has no IRQ */
2468 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2469 if (!irq)
2470 return 0;
2471
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002472 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2473 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2474
Vivien Didelot45de77f2019-08-31 16:18:36 -04002475 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2476 mv88e6xxx_reg_unlock(chip);
2477 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002478 IRQF_ONESHOT, dev_id->serdes_irq_name,
2479 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002480 mv88e6xxx_reg_lock(chip);
2481 if (err)
2482 return err;
2483
2484 dev_id->serdes_irq = irq;
2485
2486 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2487}
2488
2489static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
2490 u8 lane)
2491{
2492 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2493 unsigned int irq = dev_id->serdes_irq;
2494 int err;
2495
2496 /* Nothing to free if no IRQ has been requested */
2497 if (!irq)
2498 return 0;
2499
2500 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2501
2502 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2503 mv88e6xxx_reg_unlock(chip);
2504 free_irq(irq, dev_id);
2505 mv88e6xxx_reg_lock(chip);
2506
2507 dev_id->serdes_irq = 0;
2508
2509 return err;
2510}
2511
Andrew Lunn6d917822017-05-26 01:03:21 +02002512static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2513 bool on)
2514{
Vivien Didelotdc272f62019-08-31 16:18:33 -04002515 u8 lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002516 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002517
Vivien Didelotdc272f62019-08-31 16:18:33 -04002518 lane = mv88e6xxx_serdes_get_lane(chip, port);
2519 if (!lane)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002520 return 0;
2521
2522 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002523 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002524 if (err)
2525 return err;
2526
Vivien Didelot45de77f2019-08-31 16:18:36 -04002527 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002528 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002529 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2530 if (err)
2531 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002532
Vivien Didelotdc272f62019-08-31 16:18:33 -04002533 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002534 }
2535
2536 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002537}
2538
Vivien Didelotfa371c82017-12-05 15:34:10 -05002539static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2540{
2541 struct dsa_switch *ds = chip->ds;
2542 int upstream_port;
2543 int err;
2544
Vivien Didelot07073c72017-12-05 15:34:13 -05002545 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002546 if (chip->info->ops->port_set_upstream_port) {
2547 err = chip->info->ops->port_set_upstream_port(chip, port,
2548 upstream_port);
2549 if (err)
2550 return err;
2551 }
2552
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002553 if (port == upstream_port) {
2554 if (chip->info->ops->set_cpu_port) {
2555 err = chip->info->ops->set_cpu_port(chip,
2556 upstream_port);
2557 if (err)
2558 return err;
2559 }
2560
2561 if (chip->info->ops->set_egress_port) {
2562 err = chip->info->ops->set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002563 MV88E6XXX_EGRESS_DIR_INGRESS,
2564 upstream_port);
2565 if (err)
2566 return err;
2567
2568 err = chip->info->ops->set_egress_port(chip,
2569 MV88E6XXX_EGRESS_DIR_EGRESS,
2570 upstream_port);
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002571 if (err)
2572 return err;
2573 }
2574 }
2575
Vivien Didelotfa371c82017-12-05 15:34:10 -05002576 return 0;
2577}
2578
Vivien Didelotfad09c72016-06-21 12:28:20 -04002579static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002580{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002581 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002582 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002583 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002584
Andrew Lunn7b898462018-08-09 15:38:47 +02002585 chip->ports[port].chip = chip;
2586 chip->ports[port].port = port;
2587
Vivien Didelotd78343d2016-11-04 03:23:36 +01002588 /* MAC Forcing register: don't force link, speed, duplex or flow control
2589 * state to any particular values on physical ports, but force the CPU
2590 * port and all DSA ports to their maximum bandwidth and full duplex.
2591 */
2592 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2593 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2594 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002595 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002596 PHY_INTERFACE_MODE_NA);
2597 else
2598 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2599 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002600 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002601 PHY_INTERFACE_MODE_NA);
2602 if (err)
2603 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002604
2605 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2606 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2607 * tunneling, determine priority by looking at 802.1p and IP
2608 * priority fields (IP prio has precedence), and set STP state
2609 * to Forwarding.
2610 *
2611 * If this is the CPU link, use DSA or EDSA tagging depending
2612 * on which tagging mode was configured.
2613 *
2614 * If this is a link to another switch, use DSA tagging mode.
2615 *
2616 * If this is the upstream port for this switch, enable
2617 * forwarding of unknown unicasts and multicasts.
2618 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002619 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2620 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2621 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2622 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002623 if (err)
2624 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002625
Vivien Didelot601aeed2017-03-11 16:13:00 -05002626 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002627 if (err)
2628 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002629
Vivien Didelot601aeed2017-03-11 16:13:00 -05002630 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002631 if (err)
2632 return err;
2633
Vivien Didelot8efdda42015-08-13 12:52:23 -04002634 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002635 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002636 * untagged frames on this port, do a destination address lookup on all
2637 * received packets as usual, disable ARP mirroring and don't send a
2638 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002639 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002640 err = mv88e6xxx_port_set_map_da(chip, port);
2641 if (err)
2642 return err;
2643
Vivien Didelotfa371c82017-12-05 15:34:10 -05002644 err = mv88e6xxx_setup_upstream_port(chip, port);
2645 if (err)
2646 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002647
Andrew Lunna23b2962017-02-04 20:15:28 +01002648 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002649 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002650 if (err)
2651 return err;
2652
Vivien Didelotcd782652017-06-08 18:34:13 -04002653 if (chip->info->ops->port_set_jumbo_size) {
2654 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002655 if (err)
2656 return err;
2657 }
2658
Andrew Lunn54d792f2015-05-06 01:09:47 +02002659 /* Port Association Vector: when learning source addresses
2660 * of packets, add the address to the address database using
2661 * a port bitmap that has only the bit for this port set and
2662 * the other bits clear.
2663 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002664 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002665 /* Disable learning for CPU port */
2666 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002667 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002668
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002669 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2670 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002671 if (err)
2672 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002673
2674 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002675 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2676 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002677 if (err)
2678 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002679
Vivien Didelot08984322017-06-08 18:34:12 -04002680 if (chip->info->ops->port_pause_limit) {
2681 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002682 if (err)
2683 return err;
2684 }
2685
Vivien Didelotc8c94892017-03-11 16:13:01 -05002686 if (chip->info->ops->port_disable_learn_limit) {
2687 err = chip->info->ops->port_disable_learn_limit(chip, port);
2688 if (err)
2689 return err;
2690 }
2691
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002692 if (chip->info->ops->port_disable_pri_override) {
2693 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002694 if (err)
2695 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002696 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002697
Andrew Lunnef0a7312016-12-03 04:35:16 +01002698 if (chip->info->ops->port_tag_remap) {
2699 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002700 if (err)
2701 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002702 }
2703
Andrew Lunnef70b112016-12-03 04:45:18 +01002704 if (chip->info->ops->port_egress_rate_limiting) {
2705 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002706 if (err)
2707 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002708 }
2709
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002710 if (chip->info->ops->port_setup_message_port) {
2711 err = chip->info->ops->port_setup_message_port(chip, port);
2712 if (err)
2713 return err;
2714 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002715
Vivien Didelot207afda2016-04-14 14:42:09 -04002716 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002717 * database, and allow bidirectional communication between the
2718 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002719 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002720 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002721 if (err)
2722 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002723
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002724 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002725 if (err)
2726 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002727
2728 /* Default VLAN ID and priority: don't set a default VLAN
2729 * ID, and set the default packet priority to zero.
2730 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002731 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002732}
2733
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002734static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
2735{
2736 struct mv88e6xxx_chip *chip = ds->priv;
2737
2738 if (chip->info->ops->port_set_jumbo_size)
2739 return 10240;
Chris Packham1baf0fa2020-07-24 11:21:22 +12002740 else if (chip->info->ops->set_max_frame_size)
2741 return 1632;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002742 return 1522;
2743}
2744
2745static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
2746{
2747 struct mv88e6xxx_chip *chip = ds->priv;
2748 int ret = 0;
2749
2750 mv88e6xxx_reg_lock(chip);
2751 if (chip->info->ops->port_set_jumbo_size)
2752 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12002753 else if (chip->info->ops->set_max_frame_size)
2754 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002755 else
2756 if (new_mtu > 1522)
2757 ret = -EINVAL;
2758 mv88e6xxx_reg_unlock(chip);
2759
2760 return ret;
2761}
2762
Andrew Lunn04aca992017-05-26 01:03:24 +02002763static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2764 struct phy_device *phydev)
2765{
2766 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002767 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002768
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002769 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002770 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002771 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002772
2773 return err;
2774}
2775
Andrew Lunn75104db2019-02-24 20:44:43 +01002776static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02002777{
2778 struct mv88e6xxx_chip *chip = ds->priv;
2779
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002780 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002781 if (mv88e6xxx_serdes_power(chip, port, false))
2782 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002783 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002784}
2785
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002786static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2787 unsigned int ageing_time)
2788{
Vivien Didelot04bed142016-08-31 18:06:13 -04002789 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002790 int err;
2791
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002792 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05002793 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002794 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002795
2796 return err;
2797}
2798
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002799static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002800{
2801 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002802
Andrew Lunnde2273872016-11-21 23:27:01 +01002803 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002804 if (chip->info->ops->stats_set_histogram) {
2805 err = chip->info->ops->stats_set_histogram(chip);
2806 if (err)
2807 return err;
2808 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002809
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002810 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002811}
2812
Andrew Lunnea890982019-01-09 00:24:03 +01002813/* Check if the errata has already been applied. */
2814static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
2815{
2816 int port;
2817 int err;
2818 u16 val;
2819
2820 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002821 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01002822 if (err) {
2823 dev_err(chip->dev,
2824 "Error reading hidden register: %d\n", err);
2825 return false;
2826 }
2827 if (val != 0x01c0)
2828 return false;
2829 }
2830
2831 return true;
2832}
2833
2834/* The 6390 copper ports have an errata which require poking magic
2835 * values into undocumented hidden registers and then performing a
2836 * software reset.
2837 */
2838static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
2839{
2840 int port;
2841 int err;
2842
2843 if (mv88e6390_setup_errata_applied(chip))
2844 return 0;
2845
2846 /* Set the ports into blocking mode */
2847 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2848 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
2849 if (err)
2850 return err;
2851 }
2852
2853 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002854 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01002855 if (err)
2856 return err;
2857 }
2858
2859 return mv88e6xxx_software_reset(chip);
2860}
2861
Andrew Lunn23e8b472019-10-25 01:03:52 +02002862static void mv88e6xxx_teardown(struct dsa_switch *ds)
2863{
2864 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002865 dsa_devlink_resources_unregister(ds);
Andrew Lunnbfb25542020-09-18 21:11:07 +02002866 mv88e6xxx_teardown_devlink_regions(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02002867}
2868
Vivien Didelotf81ec902016-05-09 13:22:58 -04002869static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002870{
Vivien Didelot04bed142016-08-31 18:06:13 -04002871 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002872 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04002873 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002874 int i;
2875
Vivien Didelotfad09c72016-06-21 12:28:20 -04002876 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002877 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002878
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002879 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002880
Andrew Lunnea890982019-01-09 00:24:03 +01002881 if (chip->info->ops->setup_errata) {
2882 err = chip->info->ops->setup_errata(chip);
2883 if (err)
2884 goto unlock;
2885 }
2886
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002887 /* Cache the cmode of each port. */
2888 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2889 if (chip->info->ops->port_get_cmode) {
2890 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
2891 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03002892 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002893
2894 chip->ports[i].cmode = cmode;
2895 }
2896 }
2897
Vivien Didelot97299342016-07-18 20:45:30 -04002898 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002899 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04002900 if (dsa_is_unused_port(ds, i))
2901 continue;
2902
Hubert Feursteinc8574862019-07-31 10:23:48 +02002903 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04002904 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02002905 dev_err(chip->dev, "port %d is invalid\n", i);
2906 err = -EINVAL;
2907 goto unlock;
2908 }
2909
Vivien Didelot97299342016-07-18 20:45:30 -04002910 err = mv88e6xxx_setup_port(chip, i);
2911 if (err)
2912 goto unlock;
2913 }
2914
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002915 err = mv88e6xxx_irl_setup(chip);
2916 if (err)
2917 goto unlock;
2918
Vivien Didelot04a69a12017-10-13 14:18:05 -04002919 err = mv88e6xxx_mac_setup(chip);
2920 if (err)
2921 goto unlock;
2922
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002923 err = mv88e6xxx_phy_setup(chip);
2924 if (err)
2925 goto unlock;
2926
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002927 err = mv88e6xxx_vtu_setup(chip);
2928 if (err)
2929 goto unlock;
2930
Vivien Didelot81228992017-03-30 17:37:08 -04002931 err = mv88e6xxx_pvt_setup(chip);
2932 if (err)
2933 goto unlock;
2934
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002935 err = mv88e6xxx_atu_setup(chip);
2936 if (err)
2937 goto unlock;
2938
Andrew Lunn87fa8862017-11-09 22:29:56 +01002939 err = mv88e6xxx_broadcast_setup(chip, 0);
2940 if (err)
2941 goto unlock;
2942
Vivien Didelot9e907d72017-07-17 13:03:43 -04002943 err = mv88e6xxx_pot_setup(chip);
2944 if (err)
2945 goto unlock;
2946
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002947 err = mv88e6xxx_rmu_setup(chip);
2948 if (err)
2949 goto unlock;
2950
Vivien Didelot51c901a2017-07-17 13:03:41 -04002951 err = mv88e6xxx_rsvd2cpu_setup(chip);
2952 if (err)
2953 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002954
Vivien Didelotb28f8722018-04-26 21:56:44 -04002955 err = mv88e6xxx_trunk_setup(chip);
2956 if (err)
2957 goto unlock;
2958
Vivien Didelotc7f047b2018-04-26 21:56:45 -04002959 err = mv88e6xxx_devmap_setup(chip);
2960 if (err)
2961 goto unlock;
2962
Vivien Didelot93e18d62018-05-11 17:16:35 -04002963 err = mv88e6xxx_pri_setup(chip);
2964 if (err)
2965 goto unlock;
2966
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002967 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002968 if (chip->info->ptp_support) {
2969 err = mv88e6xxx_ptp_setup(chip);
2970 if (err)
2971 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002972
2973 err = mv88e6xxx_hwtstamp_setup(chip);
2974 if (err)
2975 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002976 }
2977
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002978 err = mv88e6xxx_stats_setup(chip);
2979 if (err)
2980 goto unlock;
2981
Vivien Didelot6b17e862015-08-13 12:52:18 -04002982unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002983 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02002984
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002985 if (err)
2986 return err;
2987
2988 /* Have to be called without holding the register lock, since
2989 * they take the devlink lock, and we later take the locks in
2990 * the reverse order when getting/setting parameters or
2991 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02002992 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002993 err = mv88e6xxx_setup_devlink_resources(ds);
2994 if (err)
2995 return err;
2996
2997 err = mv88e6xxx_setup_devlink_params(ds);
2998 if (err)
Andrew Lunnbfb25542020-09-18 21:11:07 +02002999 goto out_resources;
3000
3001 err = mv88e6xxx_setup_devlink_regions(ds);
3002 if (err)
3003 goto out_params;
3004
3005 return 0;
3006
3007out_params:
3008 mv88e6xxx_teardown_devlink_params(ds);
3009out_resources:
3010 dsa_devlink_resources_unregister(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003011
3012 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003013}
3014
Vivien Didelote57e5e72016-08-15 17:19:00 -04003015static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003016{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003017 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3018 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003019 u16 val;
3020 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003021
Andrew Lunnee26a222017-01-24 14:53:48 +01003022 if (!chip->info->ops->phy_read)
3023 return -EOPNOTSUPP;
3024
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003025 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003026 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003027 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003028
Andrew Lunnda9f3302017-02-01 03:40:05 +01003029 if (reg == MII_PHYSID2) {
Andrew Lunnddc49ac2018-11-12 18:51:01 +01003030 /* Some internal PHYs don't have a model number. */
3031 if (chip->info->family != MV88E6XXX_FAMILY_6165)
3032 /* Then there is the 6165 family. It gets is
3033 * PHYs correct. But it can also have two
3034 * SERDES interfaces in the PHY address
3035 * space. And these don't have a model
3036 * number. But they are not PHYs, so we don't
3037 * want to give them something a PHY driver
3038 * will recognise.
3039 *
3040 * Use the mv88e6390 family model number
3041 * instead, for anything which really could be
3042 * a PHY,
3043 */
3044 if (!(val & 0x3f0))
3045 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003046 }
3047
Vivien Didelote57e5e72016-08-15 17:19:00 -04003048 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003049}
3050
Vivien Didelote57e5e72016-08-15 17:19:00 -04003051static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003052{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003053 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3054 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003055 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003056
Andrew Lunnee26a222017-01-24 14:53:48 +01003057 if (!chip->info->ops->phy_write)
3058 return -EOPNOTSUPP;
3059
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003060 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003061 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003062 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003063
3064 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003065}
3066
Vivien Didelotfad09c72016-06-21 12:28:20 -04003067static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003068 struct device_node *np,
3069 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003070{
3071 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003072 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003073 struct mii_bus *bus;
3074 int err;
3075
Andrew Lunn2510bab2018-02-22 01:51:49 +01003076 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003077 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003078 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003079 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003080
3081 if (err)
3082 return err;
3083 }
3084
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003085 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003086 if (!bus)
3087 return -ENOMEM;
3088
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003089 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003090 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003091 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003092 INIT_LIST_HEAD(&mdio_bus->list);
3093 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003094
Andrew Lunnb516d452016-06-04 21:17:06 +02003095 if (np) {
3096 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003097 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003098 } else {
3099 bus->name = "mv88e6xxx SMI";
3100 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3101 }
3102
3103 bus->read = mv88e6xxx_mdio_read;
3104 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003105 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003106
Andrew Lunn6f882842018-03-17 20:32:05 +01003107 if (!external) {
3108 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3109 if (err)
3110 return err;
3111 }
3112
Florian Fainelli00e798c2018-05-15 16:56:19 -07003113 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003114 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003115 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003116 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003117 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003118 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003119
3120 if (external)
3121 list_add_tail(&mdio_bus->list, &chip->mdios);
3122 else
3123 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003124
3125 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003126}
3127
Andrew Lunn3126aee2017-12-07 01:05:57 +01003128static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3129
3130{
3131 struct mv88e6xxx_mdio_bus *mdio_bus;
3132 struct mii_bus *bus;
3133
3134 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3135 bus = mdio_bus->bus;
3136
Andrew Lunn6f882842018-03-17 20:32:05 +01003137 if (!mdio_bus->external)
3138 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3139
Andrew Lunn3126aee2017-12-07 01:05:57 +01003140 mdiobus_unregister(bus);
3141 }
3142}
3143
Andrew Lunna3c53be52017-01-24 14:53:50 +01003144static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3145 struct device_node *np)
3146{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003147 struct device_node *child;
3148 int err;
3149
3150 /* Always register one mdio bus for the internal/default mdio
3151 * bus. This maybe represented in the device tree, but is
3152 * optional.
3153 */
3154 child = of_get_child_by_name(np, "mdio");
3155 err = mv88e6xxx_mdio_register(chip, child, false);
3156 if (err)
3157 return err;
3158
3159 /* Walk the device tree, and see if there are any other nodes
3160 * which say they are compatible with the external mdio
3161 * bus.
3162 */
3163 for_each_available_child_of_node(np, child) {
Andrew Lunnceb96fa2020-09-01 04:32:57 +02003164 if (of_device_is_compatible(
3165 child, "marvell,mv88e6xxx-mdio-external")) {
Andrew Lunna3c53be52017-01-24 14:53:50 +01003166 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003167 if (err) {
3168 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303169 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003170 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003171 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003172 }
3173 }
3174
3175 return 0;
3176}
3177
Vivien Didelot855b1932016-07-20 18:18:35 -04003178static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3179{
Vivien Didelot04bed142016-08-31 18:06:13 -04003180 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003181
3182 return chip->eeprom_len;
3183}
3184
Vivien Didelot855b1932016-07-20 18:18:35 -04003185static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3186 struct ethtool_eeprom *eeprom, u8 *data)
3187{
Vivien Didelot04bed142016-08-31 18:06:13 -04003188 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003189 int err;
3190
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003191 if (!chip->info->ops->get_eeprom)
3192 return -EOPNOTSUPP;
3193
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003194 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003195 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003196 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003197
3198 if (err)
3199 return err;
3200
3201 eeprom->magic = 0xc3ec4951;
3202
3203 return 0;
3204}
3205
Vivien Didelot855b1932016-07-20 18:18:35 -04003206static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3207 struct ethtool_eeprom *eeprom, u8 *data)
3208{
Vivien Didelot04bed142016-08-31 18:06:13 -04003209 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003210 int err;
3211
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003212 if (!chip->info->ops->set_eeprom)
3213 return -EOPNOTSUPP;
3214
Vivien Didelot855b1932016-07-20 18:18:35 -04003215 if (eeprom->magic != 0xc3ec4951)
3216 return -EINVAL;
3217
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003218 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003219 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003220 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003221
3222 return err;
3223}
3224
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003225static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003226 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003227 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3228 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003229 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003230 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003231 .phy_read = mv88e6185_phy_ppu_read,
3232 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003233 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003234 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003235 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003236 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003237 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003238 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003239 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003240 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003241 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003242 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003243 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003244 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003245 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003246 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003247 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003248 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3249 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003250 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003251 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3252 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003253 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003254 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003255 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003256 .ppu_enable = mv88e6185_g1_ppu_enable,
3257 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003258 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003259 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003260 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003261 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003262 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003263 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003264};
3265
3266static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003267 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003268 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3269 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003270 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003271 .phy_read = mv88e6185_phy_ppu_read,
3272 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003273 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003274 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003275 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003276 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003277 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01003278 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003279 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003280 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003281 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003282 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003283 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3284 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003285 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003286 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003287 .serdes_power = mv88e6185_serdes_power,
3288 .serdes_get_lane = mv88e6185_serdes_get_lane,
3289 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003290 .ppu_enable = mv88e6185_g1_ppu_enable,
3291 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003292 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003293 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003294 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003295 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003296 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003297};
3298
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003299static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003300 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003301 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3302 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003303 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003304 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3305 .phy_read = mv88e6xxx_g2_smi_phy_read,
3306 .phy_write = mv88e6xxx_g2_smi_phy_write,
3307 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003308 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003309 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003310 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003311 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003312 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003313 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003314 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003315 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003316 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003317 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003318 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003319 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003320 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003321 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003322 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3323 .stats_get_strings = mv88e6095_stats_get_strings,
3324 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003325 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3326 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003327 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003328 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003329 .serdes_power = mv88e6185_serdes_power,
3330 .serdes_get_lane = mv88e6185_serdes_get_lane,
3331 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Chris Packham5c19bc82020-11-24 17:34:39 +13003332 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3333 .serdes_irq_enable = mv88e6097_serdes_irq_enable,
3334 .serdes_irq_status = mv88e6097_serdes_irq_status,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003335 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003336 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003337 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003338 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003339 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003340 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003341 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003342};
3343
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003344static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003345 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003346 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3347 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003348 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003349 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003350 .phy_read = mv88e6xxx_g2_smi_phy_read,
3351 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003352 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003353 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003354 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003355 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003356 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003357 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003358 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003359 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003360 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003361 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003362 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003363 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3364 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003365 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003366 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3367 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003368 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003369 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003370 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003371 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003372 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3373 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003374 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003375 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003376 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003377 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003378};
3379
3380static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003381 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003382 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3383 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003384 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003385 .phy_read = mv88e6185_phy_ppu_read,
3386 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003387 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003388 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003389 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003390 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003391 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003392 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003393 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003394 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003395 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003396 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003397 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003398 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003399 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003400 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003401 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003402 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003403 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3404 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003405 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003406 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3407 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003408 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003409 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003410 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003411 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003412 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003413 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003414 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003415 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003416 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003417};
3418
Vivien Didelot990e27b2017-03-28 13:50:32 -04003419static const struct mv88e6xxx_ops mv88e6141_ops = {
3420 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003421 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3422 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003423 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003424 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3425 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3426 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3427 .phy_read = mv88e6xxx_g2_smi_phy_read,
3428 .phy_write = mv88e6xxx_g2_smi_phy_write,
3429 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003430 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003431 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003432 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003433 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003434 .port_tag_remap = mv88e6095_port_tag_remap,
3435 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3436 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3437 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003438 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003439 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003440 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003441 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3442 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003443 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003444 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003445 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003446 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003447 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003448 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3449 .stats_get_strings = mv88e6320_stats_get_strings,
3450 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003451 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3452 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003453 .watchdog_ops = &mv88e6390_watchdog_ops,
3454 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003455 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003456 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003457 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003458 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003459 .serdes_power = mv88e6390_serdes_power,
3460 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003461 /* Check status register pause & lpa register */
3462 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3463 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3464 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3465 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003466 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003467 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003468 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003469 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003470 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003471};
3472
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003473static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003474 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003475 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3476 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003477 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003478 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003479 .phy_read = mv88e6xxx_g2_smi_phy_read,
3480 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003481 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003482 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003483 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003484 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003485 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003486 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003487 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003488 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003489 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003490 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003491 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003492 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003493 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003494 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003495 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003496 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003497 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3498 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003499 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003500 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3501 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003502 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003503 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003504 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003505 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003506 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3507 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003508 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003509 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003510 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003511 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003512 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003513};
3514
3515static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003516 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003517 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3518 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003519 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003520 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003521 .phy_read = mv88e6165_phy_read,
3522 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003523 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003524 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003525 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003526 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003527 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003528 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003529 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003530 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003531 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003532 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3533 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003534 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003535 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3536 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003537 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003538 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003539 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003540 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003541 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3542 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003543 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003544 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003545 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003546 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003547 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003548};
3549
3550static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003551 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003552 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3553 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003554 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003555 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003556 .phy_read = mv88e6xxx_g2_smi_phy_read,
3557 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003558 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003559 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003560 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003561 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003562 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003563 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003564 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003565 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003566 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003567 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003568 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003569 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003570 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003571 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003572 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003573 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003574 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003575 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3576 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003577 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003578 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3579 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003580 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003581 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003582 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003583 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003584 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3585 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003586 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003587 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003588 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003589};
3590
3591static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003592 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003593 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3594 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003595 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003596 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3597 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003598 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003599 .phy_read = mv88e6xxx_g2_smi_phy_read,
3600 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003601 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003602 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003603 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003604 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003605 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003606 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003607 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003608 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003609 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003610 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003611 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003612 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003613 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003614 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003615 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003616 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003617 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003618 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003619 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3620 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003621 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003622 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3623 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003624 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003625 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003626 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003627 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003628 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003629 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3630 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003631 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003632 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003633 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003634 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3635 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3636 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3637 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003638 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003639 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3640 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003641 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003642 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003643};
3644
3645static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003646 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003647 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3648 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003649 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003650 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003651 .phy_read = mv88e6xxx_g2_smi_phy_read,
3652 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003653 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003654 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003655 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003656 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003657 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003658 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003659 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003660 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003661 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003662 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003663 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003664 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003665 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003666 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003667 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003668 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003669 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003670 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3671 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003672 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003673 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3674 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003675 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003676 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003677 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003678 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003679 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3680 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003681 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003682 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003683 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003684};
3685
3686static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003687 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003688 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3689 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003690 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003691 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3692 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003693 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003694 .phy_read = mv88e6xxx_g2_smi_phy_read,
3695 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003696 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003697 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003698 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003699 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003700 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003701 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003702 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003703 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003704 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003705 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003706 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003707 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003708 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003709 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003710 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003711 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003712 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003713 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003714 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3715 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003716 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003717 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3718 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003719 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003720 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003721 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003722 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003723 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003724 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3725 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003726 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003727 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003728 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003729 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3730 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3731 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3732 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003733 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003734 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003735 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003736 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003737 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3738 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003739 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003740 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003741};
3742
3743static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003744 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003745 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3746 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003747 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003748 .phy_read = mv88e6185_phy_ppu_read,
3749 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003750 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003751 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003752 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003753 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003754 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003755 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003756 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02003757 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003758 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003759 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003760 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003761 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003762 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3763 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003764 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003765 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3766 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003767 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003768 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003769 .serdes_power = mv88e6185_serdes_power,
3770 .serdes_get_lane = mv88e6185_serdes_get_lane,
3771 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelot02317e62018-05-09 11:38:49 -04003772 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003773 .ppu_enable = mv88e6185_g1_ppu_enable,
3774 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003775 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003776 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003777 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003778 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003779 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003780};
3781
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003782static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003783 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003784 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003785 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003786 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3787 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003788 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3789 .phy_read = mv88e6xxx_g2_smi_phy_read,
3790 .phy_write = mv88e6xxx_g2_smi_phy_write,
3791 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003792 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003793 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003794 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003795 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003796 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003797 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003798 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003799 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003800 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003801 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003802 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003803 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003804 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003805 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003806 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003807 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003808 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003809 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003810 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3811 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003812 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003813 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3814 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003815 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003816 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003817 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003818 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003819 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003820 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3821 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003822 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3823 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003824 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003825 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003826 /* Check status register pause & lpa register */
3827 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3828 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3829 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3830 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003831 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003832 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003833 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003834 .serdes_get_strings = mv88e6390_serdes_get_strings,
3835 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003836 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3837 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003838 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003839 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003840};
3841
3842static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003843 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003844 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003845 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003846 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3847 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003848 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3849 .phy_read = mv88e6xxx_g2_smi_phy_read,
3850 .phy_write = mv88e6xxx_g2_smi_phy_write,
3851 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003852 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003853 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003854 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003855 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003856 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003857 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003858 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003859 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003860 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003861 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003862 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003863 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003864 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003865 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003866 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003867 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003868 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003869 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003870 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3871 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003872 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003873 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3874 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003875 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003876 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003877 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003878 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003879 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003880 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3881 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003882 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3883 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003884 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003885 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003886 /* Check status register pause & lpa register */
3887 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3888 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3889 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3890 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003891 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003892 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003893 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003894 .serdes_get_strings = mv88e6390_serdes_get_strings,
3895 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003896 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3897 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003898 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003899 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003900};
3901
3902static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003903 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003904 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003905 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003906 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3907 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003908 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3909 .phy_read = mv88e6xxx_g2_smi_phy_read,
3910 .phy_write = mv88e6xxx_g2_smi_phy_write,
3911 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003912 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003913 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003914 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003915 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003916 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003917 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003918 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003919 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003920 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003921 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003922 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003923 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003924 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003925 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003926 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003927 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003928 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3929 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003930 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003931 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3932 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003933 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003934 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003935 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003936 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003937 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003938 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3939 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003940 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3941 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003942 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003943 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003944 /* Check status register pause & lpa register */
3945 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3946 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3947 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3948 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003949 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003950 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003951 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01003952 .serdes_get_strings = mv88e6390_serdes_get_strings,
3953 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01003954 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3955 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003956 .avb_ops = &mv88e6390_avb_ops,
3957 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003958 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003959};
3960
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003961static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003962 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003963 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3964 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003965 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003966 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3967 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003968 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003969 .phy_read = mv88e6xxx_g2_smi_phy_read,
3970 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003971 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003972 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003973 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003974 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003975 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003976 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003977 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003978 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003979 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003980 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003981 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003982 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003983 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003984 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003985 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003986 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003987 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003988 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003989 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3990 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003991 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003992 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3993 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003994 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003995 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003996 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003997 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003998 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003999 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4000 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004001 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004002 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004003 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004004 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4005 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4006 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4007 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004008 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004009 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004010 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004011 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004012 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4013 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004014 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004015 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004016 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004017 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004018};
4019
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004020static const struct mv88e6xxx_ops mv88e6250_ops = {
4021 /* MV88E6XXX_FAMILY_6250 */
4022 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4023 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4024 .irl_init_all = mv88e6352_g2_irl_init_all,
4025 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4026 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4027 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4028 .phy_read = mv88e6xxx_g2_smi_phy_read,
4029 .phy_write = mv88e6xxx_g2_smi_phy_write,
4030 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004031 .port_sync_link = mv88e6xxx_port_sync_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004032 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004033 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004034 .port_tag_remap = mv88e6095_port_tag_remap,
4035 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4036 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
4037 .port_set_ether_type = mv88e6351_port_set_ether_type,
4038 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4039 .port_pause_limit = mv88e6097_port_pause_limit,
4040 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004041 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4042 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4043 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4044 .stats_get_strings = mv88e6250_stats_get_strings,
4045 .stats_get_stats = mv88e6250_stats_get_stats,
4046 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4047 .set_egress_port = mv88e6095_g1_set_egress_port,
4048 .watchdog_ops = &mv88e6250_watchdog_ops,
4049 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4050 .pot_clear = mv88e6xxx_g2_pot_clear,
4051 .reset = mv88e6250_g1_reset,
Rasmus Villemoes67c9ed12021-01-25 16:04:48 +01004052 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Rasmus Villemoesb28f3f32021-01-25 16:04:49 +01004053 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004054 .avb_ops = &mv88e6352_avb_ops,
4055 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004056 .phylink_validate = mv88e6065_phylink_validate,
4057};
4058
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004059static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004060 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004061 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004062 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004063 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4064 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004065 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4066 .phy_read = mv88e6xxx_g2_smi_phy_read,
4067 .phy_write = mv88e6xxx_g2_smi_phy_write,
4068 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004069 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004070 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004071 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004072 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004073 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004074 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004075 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004076 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004077 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004078 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004079 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004080 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004081 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004082 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004083 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004084 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004085 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004086 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4087 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004088 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004089 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4090 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004091 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004092 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004093 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004094 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004095 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004096 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4097 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004098 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4099 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004100 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004101 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004102 /* Check status register pause & lpa register */
4103 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4104 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4105 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4106 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004107 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004108 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004109 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004110 .serdes_get_strings = mv88e6390_serdes_get_strings,
4111 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004112 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4113 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004114 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004115 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004116 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004117 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004118};
4119
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004120static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004121 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004122 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4123 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004124 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004125 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4126 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004127 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004128 .phy_read = mv88e6xxx_g2_smi_phy_read,
4129 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004130 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004131 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004132 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004133 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004134 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004135 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004136 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004137 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004138 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004139 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004140 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004141 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004142 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004143 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004144 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004145 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004146 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4147 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004148 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004149 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4150 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004151 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004152 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004153 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004154 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004155 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004156 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004157 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004158 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004159 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004160 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004161};
4162
4163static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004164 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004165 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4166 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004167 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004168 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4169 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004170 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004171 .phy_read = mv88e6xxx_g2_smi_phy_read,
4172 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004173 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004174 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004175 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004176 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004177 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004178 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004179 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004180 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004181 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004182 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004183 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004184 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004185 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004186 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004187 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004188 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004189 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4190 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004191 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004192 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4193 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004194 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004195 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004196 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004197 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004198 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004199 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004200 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004201 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004202};
4203
Vivien Didelot16e329a2017-03-28 13:50:33 -04004204static const struct mv88e6xxx_ops mv88e6341_ops = {
4205 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004206 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4207 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004208 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004209 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4210 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4211 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4212 .phy_read = mv88e6xxx_g2_smi_phy_read,
4213 .phy_write = mv88e6xxx_g2_smi_phy_write,
4214 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004215 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004216 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004217 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004218 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004219 .port_tag_remap = mv88e6095_port_tag_remap,
4220 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4221 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
4222 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004223 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004224 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004225 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004226 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4227 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004228 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004229 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004230 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004231 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004232 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004233 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4234 .stats_get_strings = mv88e6320_stats_get_strings,
4235 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004236 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4237 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004238 .watchdog_ops = &mv88e6390_watchdog_ops,
4239 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004240 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004241 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004242 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004243 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004244 .serdes_power = mv88e6390_serdes_power,
4245 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004246 /* Check status register pause & lpa register */
4247 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4248 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4249 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4250 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004251 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004252 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004253 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004254 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004255 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004256 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01004257 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004258};
4259
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004260static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004261 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004262 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4263 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004264 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004265 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004266 .phy_read = mv88e6xxx_g2_smi_phy_read,
4267 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004268 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004269 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004270 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004271 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004272 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004273 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004274 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004275 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004276 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004277 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004278 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004279 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004280 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004281 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004282 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004283 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004284 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004285 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4286 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004287 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004288 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4289 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004290 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004291 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004292 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004293 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004294 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4295 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004296 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004297 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004298 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004299};
4300
4301static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004302 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004303 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4304 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004305 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004306 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004307 .phy_read = mv88e6xxx_g2_smi_phy_read,
4308 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004309 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004310 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004311 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004312 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004313 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004314 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004315 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004316 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004317 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004318 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004319 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004320 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004321 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004322 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004323 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004324 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004325 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004326 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4327 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004328 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004329 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4330 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004331 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004332 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004333 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004334 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004335 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4336 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004337 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004338 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004339 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004340 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004341 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004342};
4343
4344static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004345 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004346 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4347 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004348 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004349 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4350 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004351 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004352 .phy_read = mv88e6xxx_g2_smi_phy_read,
4353 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004354 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004355 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004356 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004357 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004358 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004359 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004360 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004361 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004362 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004363 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004364 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004365 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004366 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004367 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004368 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004369 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004370 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004371 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004372 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4373 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004374 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004375 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4376 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004377 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004378 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004379 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004380 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004381 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004382 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4383 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004384 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004385 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004386 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004387 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4388 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4389 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4390 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004391 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004392 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004393 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004394 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004395 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004396 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004397 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004398 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4399 .serdes_get_strings = mv88e6352_serdes_get_strings,
4400 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004401 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4402 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004403 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004404};
4405
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004406static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004407 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004408 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004409 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004410 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4411 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004412 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4413 .phy_read = mv88e6xxx_g2_smi_phy_read,
4414 .phy_write = mv88e6xxx_g2_smi_phy_write,
4415 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004416 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004417 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004418 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004419 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004420 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004421 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004422 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004423 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004424 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004425 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004426 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004427 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004428 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004429 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004430 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004431 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004432 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004433 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004434 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004435 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4436 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004437 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004438 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4439 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004440 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004441 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004442 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004443 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004444 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004445 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4446 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004447 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4448 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004449 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004450 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004451 /* Check status register pause & lpa register */
4452 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4453 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4454 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4455 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004456 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004457 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004458 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004459 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004460 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004461 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004462 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4463 .serdes_get_strings = mv88e6390_serdes_get_strings,
4464 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004465 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4466 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004467 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004468};
4469
4470static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004471 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004472 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004473 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004474 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4475 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004476 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4477 .phy_read = mv88e6xxx_g2_smi_phy_read,
4478 .phy_write = mv88e6xxx_g2_smi_phy_write,
4479 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004480 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004481 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004482 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004483 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004484 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004485 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004486 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004487 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004488 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004489 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004490 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004491 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004492 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004493 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004494 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004495 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004496 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004497 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004498 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004499 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4500 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004501 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004502 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4503 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004504 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004505 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004506 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004507 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004508 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004509 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4510 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004511 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4512 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004513 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004514 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004515 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4516 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4517 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4518 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004519 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004520 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004521 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004522 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4523 .serdes_get_strings = mv88e6390_serdes_get_strings,
4524 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004525 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4526 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004527 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004528 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004529 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004530 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004531};
4532
Vivien Didelotf81ec902016-05-09 13:22:58 -04004533static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4534 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004535 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004536 .family = MV88E6XXX_FAMILY_6097,
4537 .name = "Marvell 88E6085",
4538 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004539 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004540 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004541 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004542 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004543 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004544 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004545 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004546 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004547 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004548 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004549 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004550 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004551 .pvt = true,
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 = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004555 },
4556
4557 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004558 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004559 .family = MV88E6XXX_FAMILY_6095,
4560 .name = "Marvell 88E6095/88E6095F",
4561 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004562 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004563 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004564 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004565 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004566 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004567 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004568 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004569 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004570 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004571 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004572 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004573 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004574 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004575 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004576 },
4577
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004578 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004579 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004580 .family = MV88E6XXX_FAMILY_6097,
4581 .name = "Marvell 88E6097/88E6097F",
4582 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004583 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004584 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004585 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004586 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004587 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004588 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004589 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004590 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004591 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004592 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004593 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004594 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004595 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004596 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01004597 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004598 .ops = &mv88e6097_ops,
4599 },
4600
Vivien Didelotf81ec902016-05-09 13:22:58 -04004601 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004602 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004603 .family = MV88E6XXX_FAMILY_6165,
4604 .name = "Marvell 88E6123",
4605 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004606 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004607 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004608 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004609 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004610 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004611 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004612 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004613 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004614 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004615 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004616 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004617 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004618 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004619 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004620 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004621 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004622 },
4623
4624 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004625 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004626 .family = MV88E6XXX_FAMILY_6185,
4627 .name = "Marvell 88E6131",
4628 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004629 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004630 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004631 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004632 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004633 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004634 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004635 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004636 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004637 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004638 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004639 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004640 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004641 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004642 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004643 },
4644
Vivien Didelot990e27b2017-03-28 13:50:32 -04004645 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004646 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004647 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01004648 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04004649 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004650 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004651 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004652 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004653 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004654 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004655 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004656 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004657 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004658 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004659 .age_time_coeff = 3750,
4660 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004661 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004662 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004663 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004664 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004665 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004666 .ops = &mv88e6141_ops,
4667 },
4668
Vivien Didelotf81ec902016-05-09 13:22:58 -04004669 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004670 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004671 .family = MV88E6XXX_FAMILY_6165,
4672 .name = "Marvell 88E6161",
4673 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004674 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004675 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004676 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004677 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004678 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004679 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004680 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004681 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004682 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004683 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004684 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004685 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004686 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004687 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004688 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004689 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004690 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004691 },
4692
4693 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004694 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004695 .family = MV88E6XXX_FAMILY_6165,
4696 .name = "Marvell 88E6165",
4697 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004698 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004699 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004700 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004701 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004702 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004703 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004704 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004705 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004706 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004707 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004708 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004709 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004710 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004711 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004712 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004713 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004714 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004715 },
4716
4717 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004718 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004719 .family = MV88E6XXX_FAMILY_6351,
4720 .name = "Marvell 88E6171",
4721 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004722 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004723 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004724 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004725 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004726 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004727 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004728 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004729 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004730 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004731 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004732 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004733 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004734 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004735 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004736 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004737 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004738 },
4739
4740 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004741 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004742 .family = MV88E6XXX_FAMILY_6352,
4743 .name = "Marvell 88E6172",
4744 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004745 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004746 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004747 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004748 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004749 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004750 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004751 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004752 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004753 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004754 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004755 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004756 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004757 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004758 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004759 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004760 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004761 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004762 },
4763
4764 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004765 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004766 .family = MV88E6XXX_FAMILY_6351,
4767 .name = "Marvell 88E6175",
4768 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004769 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004770 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004771 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004772 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004773 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004774 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004775 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004776 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004777 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004778 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004779 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004780 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004781 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004782 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004783 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004784 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004785 },
4786
4787 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004788 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004789 .family = MV88E6XXX_FAMILY_6352,
4790 .name = "Marvell 88E6176",
4791 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004792 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004793 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004794 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004795 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004796 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004797 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004798 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004799 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004800 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004801 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004802 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004803 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004804 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004805 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004806 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004807 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004808 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004809 },
4810
4811 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004812 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004813 .family = MV88E6XXX_FAMILY_6185,
4814 .name = "Marvell 88E6185",
4815 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004816 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004817 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004818 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004819 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004820 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004821 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004822 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004823 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004824 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004825 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004826 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004827 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004828 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004829 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004830 },
4831
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004832 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004833 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004834 .family = MV88E6XXX_FAMILY_6390,
4835 .name = "Marvell 88E6190",
4836 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004837 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004838 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004839 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004840 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004841 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004842 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004843 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004844 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004845 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004846 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004847 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004848 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004849 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04004850 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004851 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05004852 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004853 .ops = &mv88e6190_ops,
4854 },
4855
4856 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004857 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004858 .family = MV88E6XXX_FAMILY_6390,
4859 .name = "Marvell 88E6190X",
4860 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004861 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004862 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004863 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004864 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004865 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004866 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004867 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004868 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004869 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004870 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004871 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004872 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004873 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004874 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004875 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004876 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004877 .ops = &mv88e6190x_ops,
4878 },
4879
4880 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004881 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004882 .family = MV88E6XXX_FAMILY_6390,
4883 .name = "Marvell 88E6191",
4884 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004885 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004886 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004887 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04004888 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004889 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004890 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004891 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004892 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004893 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004894 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004895 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004896 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004897 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004898 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004899 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004900 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04004901 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004902 },
4903
Hubert Feurstein49022642019-07-31 10:23:46 +02004904 [MV88E6220] = {
4905 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
4906 .family = MV88E6XXX_FAMILY_6250,
4907 .name = "Marvell 88E6220",
4908 .num_databases = 64,
4909
4910 /* Ports 2-4 are not routed to pins
4911 * => usable ports 0, 1, 5, 6
4912 */
4913 .num_ports = 7,
4914 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02004915 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02004916 .max_vid = 4095,
4917 .port_base_addr = 0x08,
4918 .phy_base_addr = 0x00,
4919 .global1_addr = 0x0f,
4920 .global2_addr = 0x07,
4921 .age_time_coeff = 15000,
4922 .g1_irqs = 9,
4923 .g2_irqs = 10,
4924 .atu_move_port_mask = 0xf,
4925 .dual_chip = true,
4926 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02004927 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02004928 .ops = &mv88e6250_ops,
4929 },
4930
Vivien Didelotf81ec902016-05-09 13:22:58 -04004931 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004932 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004933 .family = MV88E6XXX_FAMILY_6352,
4934 .name = "Marvell 88E6240",
4935 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004936 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004937 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004938 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004939 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004940 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004941 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004942 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004943 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004944 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004945 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004946 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004947 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004948 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004949 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004950 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004951 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004952 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004953 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004954 },
4955
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004956 [MV88E6250] = {
4957 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
4958 .family = MV88E6XXX_FAMILY_6250,
4959 .name = "Marvell 88E6250",
4960 .num_databases = 64,
4961 .num_ports = 7,
4962 .num_internal_phys = 5,
4963 .max_vid = 4095,
4964 .port_base_addr = 0x08,
4965 .phy_base_addr = 0x00,
4966 .global1_addr = 0x0f,
4967 .global2_addr = 0x07,
4968 .age_time_coeff = 15000,
4969 .g1_irqs = 9,
4970 .g2_irqs = 10,
4971 .atu_move_port_mask = 0xf,
4972 .dual_chip = true,
4973 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02004974 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004975 .ops = &mv88e6250_ops,
4976 },
4977
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004978 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004979 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004980 .family = MV88E6XXX_FAMILY_6390,
4981 .name = "Marvell 88E6290",
4982 .num_databases = 4096,
4983 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004984 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004985 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004986 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004987 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004988 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004989 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004990 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004991 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004992 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004993 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004994 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004995 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004996 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004997 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004998 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004999 .ops = &mv88e6290_ops,
5000 },
5001
Vivien Didelotf81ec902016-05-09 13:22:58 -04005002 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005003 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005004 .family = MV88E6XXX_FAMILY_6320,
5005 .name = "Marvell 88E6320",
5006 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005007 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005008 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005009 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005010 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005011 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005012 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005013 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005014 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005015 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005016 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005017 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005018 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005019 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005020 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005021 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005022 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005023 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005024 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005025 },
5026
5027 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005028 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005029 .family = MV88E6XXX_FAMILY_6320,
5030 .name = "Marvell 88E6321",
5031 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005032 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005033 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005034 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005035 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005036 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005037 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005038 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005039 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005040 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005041 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005042 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005043 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005044 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005045 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005046 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005047 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005048 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005049 },
5050
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005051 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005052 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005053 .family = MV88E6XXX_FAMILY_6341,
5054 .name = "Marvell 88E6341",
5055 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005056 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005057 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005058 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005059 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005060 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005061 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005062 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005063 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005064 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005065 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005066 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005067 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005068 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005069 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005070 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005071 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005072 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005073 .ops = &mv88e6341_ops,
5074 },
5075
Vivien Didelotf81ec902016-05-09 13:22:58 -04005076 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005077 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005078 .family = MV88E6XXX_FAMILY_6351,
5079 .name = "Marvell 88E6350",
5080 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005081 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005082 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005083 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005084 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005085 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005086 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005087 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005088 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005089 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005090 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005091 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005092 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005093 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005094 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005095 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005096 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005097 },
5098
5099 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005100 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005101 .family = MV88E6XXX_FAMILY_6351,
5102 .name = "Marvell 88E6351",
5103 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005104 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005105 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005106 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005107 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005108 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005109 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005110 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005111 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005112 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005113 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005114 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005115 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005116 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005117 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005118 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005119 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005120 },
5121
5122 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005123 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005124 .family = MV88E6XXX_FAMILY_6352,
5125 .name = "Marvell 88E6352",
5126 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005127 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005128 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005129 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005130 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005131 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005132 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005133 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005134 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005135 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005136 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005137 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005138 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005139 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005140 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005141 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005142 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005143 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005144 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005145 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005146 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005147 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005148 .family = MV88E6XXX_FAMILY_6390,
5149 .name = "Marvell 88E6390",
5150 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005151 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005152 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005153 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005154 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005155 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005156 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005157 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005158 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005159 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005160 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005161 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005162 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005163 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005164 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005165 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005166 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005167 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005168 .ops = &mv88e6390_ops,
5169 },
5170 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005171 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005172 .family = MV88E6XXX_FAMILY_6390,
5173 .name = "Marvell 88E6390X",
5174 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005175 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005176 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005177 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005178 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005179 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005180 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005181 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005182 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005183 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005184 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005185 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005186 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005187 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005188 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005189 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005190 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005191 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005192 .ops = &mv88e6390x_ops,
5193 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005194};
5195
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005196static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005197{
Vivien Didelota439c062016-04-17 13:23:58 -04005198 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005199
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005200 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5201 if (mv88e6xxx_table[i].prod_num == prod_num)
5202 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005203
Vivien Didelotb9b37712015-10-30 19:39:48 -04005204 return NULL;
5205}
5206
Vivien Didelotfad09c72016-06-21 12:28:20 -04005207static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005208{
5209 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005210 unsigned int prod_num, rev;
5211 u16 id;
5212 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005213
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005214 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005215 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005216 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005217 if (err)
5218 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005219
Vivien Didelot107fcc12017-06-12 12:37:36 -04005220 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5221 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005222
5223 info = mv88e6xxx_lookup_info(prod_num);
5224 if (!info)
5225 return -ENODEV;
5226
Vivien Didelotcaac8542016-06-20 13:14:09 -04005227 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005228 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005229
Vivien Didelotca070c12016-09-02 14:45:34 -04005230 err = mv88e6xxx_g2_require(chip);
5231 if (err)
5232 return err;
5233
Vivien Didelotfad09c72016-06-21 12:28:20 -04005234 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5235 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005236
5237 return 0;
5238}
5239
Vivien Didelotfad09c72016-06-21 12:28:20 -04005240static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005241{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005242 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005243
Vivien Didelotfad09c72016-06-21 12:28:20 -04005244 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5245 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005246 return NULL;
5247
Vivien Didelotfad09c72016-06-21 12:28:20 -04005248 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005249
Vivien Didelotfad09c72016-06-21 12:28:20 -04005250 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005251 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005252 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005253
Vivien Didelotfad09c72016-06-21 12:28:20 -04005254 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005255}
5256
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005257static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005258 int port,
5259 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005260{
Vivien Didelot04bed142016-08-31 18:06:13 -04005261 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005262
Andrew Lunn443d5a12016-12-03 04:35:18 +01005263 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005264}
5265
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005266static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
5267 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005268{
Vivien Didelot04bed142016-08-31 18:06:13 -04005269 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005270 int err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005271
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005272 mv88e6xxx_reg_lock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005273 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5274 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005275 mv88e6xxx_reg_unlock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005276
5277 return err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005278}
5279
5280static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5281 const struct switchdev_obj_port_mdb *mdb)
5282{
Vivien Didelot04bed142016-08-31 18:06:13 -04005283 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005284 int err;
5285
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005286 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005287 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005288 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005289
5290 return err;
5291}
5292
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005293static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5294 struct dsa_mall_mirror_tc_entry *mirror,
5295 bool ingress)
5296{
5297 enum mv88e6xxx_egress_direction direction = ingress ?
5298 MV88E6XXX_EGRESS_DIR_INGRESS :
5299 MV88E6XXX_EGRESS_DIR_EGRESS;
5300 struct mv88e6xxx_chip *chip = ds->priv;
5301 bool other_mirrors = false;
5302 int i;
5303 int err;
5304
5305 if (!chip->info->ops->set_egress_port)
5306 return -EOPNOTSUPP;
5307
5308 mutex_lock(&chip->reg_lock);
5309 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5310 mirror->to_local_port) {
5311 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5312 other_mirrors |= ingress ?
5313 chip->ports[i].mirror_ingress :
5314 chip->ports[i].mirror_egress;
5315
5316 /* Can't change egress port when other mirror is active */
5317 if (other_mirrors) {
5318 err = -EBUSY;
5319 goto out;
5320 }
5321
5322 err = chip->info->ops->set_egress_port(chip,
5323 direction,
5324 mirror->to_local_port);
5325 if (err)
5326 goto out;
5327 }
5328
5329 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5330out:
5331 mutex_unlock(&chip->reg_lock);
5332
5333 return err;
5334}
5335
5336static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5337 struct dsa_mall_mirror_tc_entry *mirror)
5338{
5339 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5340 MV88E6XXX_EGRESS_DIR_INGRESS :
5341 MV88E6XXX_EGRESS_DIR_EGRESS;
5342 struct mv88e6xxx_chip *chip = ds->priv;
5343 bool other_mirrors = false;
5344 int i;
5345
5346 mutex_lock(&chip->reg_lock);
5347 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5348 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5349
5350 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5351 other_mirrors |= mirror->ingress ?
5352 chip->ports[i].mirror_ingress :
5353 chip->ports[i].mirror_egress;
5354
5355 /* Reset egress port when no other mirror is active */
5356 if (!other_mirrors) {
5357 if (chip->info->ops->set_egress_port(chip,
5358 direction,
5359 dsa_upstream_port(ds,
Colin Ian King4e4637b2019-11-12 13:05:23 +00005360 port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005361 dev_err(ds->dev, "failed to set egress port\n");
5362 }
5363
5364 mutex_unlock(&chip->reg_lock);
5365}
5366
Russell King4f859012019-02-20 15:35:05 -08005367static int mv88e6xxx_port_egress_floods(struct dsa_switch *ds, int port,
5368 bool unicast, bool multicast)
5369{
5370 struct mv88e6xxx_chip *chip = ds->priv;
5371 int err = -EOPNOTSUPP;
5372
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005373 mv88e6xxx_reg_lock(chip);
Russell King4f859012019-02-20 15:35:05 -08005374 if (chip->info->ops->port_set_egress_floods)
5375 err = chip->info->ops->port_set_egress_floods(chip, port,
5376 unicast,
5377 multicast);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005378 mv88e6xxx_reg_unlock(chip);
Russell King4f859012019-02-20 15:35:05 -08005379
5380 return err;
5381}
5382
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005383static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
5384 struct net_device *lag,
5385 struct netdev_lag_upper_info *info)
5386{
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005387 struct mv88e6xxx_chip *chip = ds->priv;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005388 struct dsa_port *dp;
5389 int id, members = 0;
5390
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005391 if (!mv88e6xxx_has_lag(chip))
5392 return false;
5393
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005394 id = dsa_lag_id(ds->dst, lag);
5395 if (id < 0 || id >= ds->num_lag_ids)
5396 return false;
5397
5398 dsa_lag_foreach_port(dp, ds->dst, lag)
5399 /* Includes the port joining the LAG */
5400 members++;
5401
5402 if (members > 8)
5403 return false;
5404
5405 /* We could potentially relax this to include active
5406 * backup in the future.
5407 */
5408 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
5409 return false;
5410
5411 /* Ideally we would also validate that the hash type matches
5412 * the hardware. Alas, this is always set to unknown on team
5413 * interfaces.
5414 */
5415 return true;
5416}
5417
5418static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct net_device *lag)
5419{
5420 struct mv88e6xxx_chip *chip = ds->priv;
5421 struct dsa_port *dp;
5422 u16 map = 0;
5423 int id;
5424
5425 id = dsa_lag_id(ds->dst, lag);
5426
5427 /* Build the map of all ports to distribute flows destined for
5428 * this LAG. This can be either a local user port, or a DSA
5429 * port if the LAG port is on a remote chip.
5430 */
5431 dsa_lag_foreach_port(dp, ds->dst, lag)
5432 map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));
5433
5434 return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
5435}
5436
5437static const u8 mv88e6xxx_lag_mask_table[8][8] = {
5438 /* Row number corresponds to the number of active members in a
5439 * LAG. Each column states which of the eight hash buckets are
5440 * mapped to the column:th port in the LAG.
5441 *
5442 * Example: In a LAG with three active ports, the second port
5443 * ([2][1]) would be selected for traffic mapped to buckets
5444 * 3,4,5 (0x38).
5445 */
5446 { 0xff, 0, 0, 0, 0, 0, 0, 0 },
5447 { 0x0f, 0xf0, 0, 0, 0, 0, 0, 0 },
5448 { 0x07, 0x38, 0xc0, 0, 0, 0, 0, 0 },
5449 { 0x03, 0x0c, 0x30, 0xc0, 0, 0, 0, 0 },
5450 { 0x03, 0x0c, 0x30, 0x40, 0x80, 0, 0, 0 },
5451 { 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80, 0, 0 },
5452 { 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0 },
5453 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
5454};
5455
5456static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
5457 int num_tx, int nth)
5458{
5459 u8 active = 0;
5460 int i;
5461
5462 num_tx = num_tx <= 8 ? num_tx : 8;
5463 if (nth < num_tx)
5464 active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];
5465
5466 for (i = 0; i < 8; i++) {
5467 if (BIT(i) & active)
5468 mask[i] |= BIT(port);
5469 }
5470}
5471
5472static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
5473{
5474 struct mv88e6xxx_chip *chip = ds->priv;
5475 unsigned int id, num_tx;
5476 struct net_device *lag;
5477 struct dsa_port *dp;
5478 int i, err, nth;
5479 u16 mask[8];
5480 u16 ivec;
5481
5482 /* Assume no port is a member of any LAG. */
5483 ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;
5484
5485 /* Disable all masks for ports that _are_ members of a LAG. */
5486 list_for_each_entry(dp, &ds->dst->ports, list) {
5487 if (!dp->lag_dev || dp->ds != ds)
5488 continue;
5489
5490 ivec &= ~BIT(dp->index);
5491 }
5492
5493 for (i = 0; i < 8; i++)
5494 mask[i] = ivec;
5495
5496 /* Enable the correct subset of masks for all LAG ports that
5497 * are in the Tx set.
5498 */
5499 dsa_lags_foreach_id(id, ds->dst) {
5500 lag = dsa_lag_dev(ds->dst, id);
5501 if (!lag)
5502 continue;
5503
5504 num_tx = 0;
5505 dsa_lag_foreach_port(dp, ds->dst, lag) {
5506 if (dp->lag_tx_enabled)
5507 num_tx++;
5508 }
5509
5510 if (!num_tx)
5511 continue;
5512
5513 nth = 0;
5514 dsa_lag_foreach_port(dp, ds->dst, lag) {
5515 if (!dp->lag_tx_enabled)
5516 continue;
5517
5518 if (dp->ds == ds)
5519 mv88e6xxx_lag_set_port_mask(mask, dp->index,
5520 num_tx, nth);
5521
5522 nth++;
5523 }
5524 }
5525
5526 for (i = 0; i < 8; i++) {
5527 err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
5528 if (err)
5529 return err;
5530 }
5531
5532 return 0;
5533}
5534
5535static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
5536 struct net_device *lag)
5537{
5538 int err;
5539
5540 err = mv88e6xxx_lag_sync_masks(ds);
5541
5542 if (!err)
5543 err = mv88e6xxx_lag_sync_map(ds, lag);
5544
5545 return err;
5546}
5547
5548static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port)
5549{
5550 struct mv88e6xxx_chip *chip = ds->priv;
5551 int err;
5552
5553 mv88e6xxx_reg_lock(chip);
5554 err = mv88e6xxx_lag_sync_masks(ds);
5555 mv88e6xxx_reg_unlock(chip);
5556 return err;
5557}
5558
5559static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
5560 struct net_device *lag,
5561 struct netdev_lag_upper_info *info)
5562{
5563 struct mv88e6xxx_chip *chip = ds->priv;
5564 int err, id;
5565
5566 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
5567 return -EOPNOTSUPP;
5568
5569 id = dsa_lag_id(ds->dst, lag);
5570
5571 mv88e6xxx_reg_lock(chip);
5572
5573 err = mv88e6xxx_port_set_trunk(chip, port, true, id);
5574 if (err)
5575 goto err_unlock;
5576
5577 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
5578 if (err)
5579 goto err_clear_trunk;
5580
5581 mv88e6xxx_reg_unlock(chip);
5582 return 0;
5583
5584err_clear_trunk:
5585 mv88e6xxx_port_set_trunk(chip, port, false, 0);
5586err_unlock:
5587 mv88e6xxx_reg_unlock(chip);
5588 return err;
5589}
5590
5591static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
5592 struct net_device *lag)
5593{
5594 struct mv88e6xxx_chip *chip = ds->priv;
5595 int err_sync, err_trunk;
5596
5597 mv88e6xxx_reg_lock(chip);
5598 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
5599 err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
5600 mv88e6xxx_reg_unlock(chip);
5601 return err_sync ? : err_trunk;
5602}
5603
5604static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
5605 int port)
5606{
5607 struct mv88e6xxx_chip *chip = ds->priv;
5608 int err;
5609
5610 mv88e6xxx_reg_lock(chip);
5611 err = mv88e6xxx_lag_sync_masks(ds);
5612 mv88e6xxx_reg_unlock(chip);
5613 return err;
5614}
5615
5616static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
5617 int port, struct net_device *lag,
5618 struct netdev_lag_upper_info *info)
5619{
5620 struct mv88e6xxx_chip *chip = ds->priv;
5621 int err;
5622
5623 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
5624 return -EOPNOTSUPP;
5625
5626 mv88e6xxx_reg_lock(chip);
5627
5628 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
5629 if (err)
5630 goto unlock;
5631
5632 err = mv88e6xxx_pvt_map(chip, sw_index, port);
5633
5634unlock:
5635 mv88e6xxx_reg_unlock(chip);
5636 return err;
5637}
5638
5639static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
5640 int port, struct net_device *lag)
5641{
5642 struct mv88e6xxx_chip *chip = ds->priv;
5643 int err_sync, err_pvt;
5644
5645 mv88e6xxx_reg_lock(chip);
5646 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
5647 err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
5648 mv88e6xxx_reg_unlock(chip);
5649 return err_sync ? : err_pvt;
5650}
5651
Florian Fainellia82f67a2017-01-08 14:52:08 -08005652static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02005653 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005654 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005655 .teardown = mv88e6xxx_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07005656 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00005657 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07005658 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00005659 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07005660 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
5661 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005662 .get_strings = mv88e6xxx_get_strings,
5663 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
5664 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02005665 .port_enable = mv88e6xxx_port_enable,
5666 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02005667 .port_max_mtu = mv88e6xxx_get_max_mtu,
5668 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04005669 .get_mac_eee = mv88e6xxx_get_mac_eee,
5670 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005671 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005672 .get_eeprom = mv88e6xxx_get_eeprom,
5673 .set_eeprom = mv88e6xxx_set_eeprom,
5674 .get_regs_len = mv88e6xxx_get_regs_len,
5675 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04005676 .get_rxnfc = mv88e6xxx_get_rxnfc,
5677 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04005678 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005679 .port_bridge_join = mv88e6xxx_port_bridge_join,
5680 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Russell King4f859012019-02-20 15:35:05 -08005681 .port_egress_floods = mv88e6xxx_port_egress_floods,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005682 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04005683 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005684 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005685 .port_vlan_add = mv88e6xxx_port_vlan_add,
5686 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005687 .port_fdb_add = mv88e6xxx_port_fdb_add,
5688 .port_fdb_del = mv88e6xxx_port_fdb_del,
5689 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005690 .port_mdb_add = mv88e6xxx_port_mdb_add,
5691 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005692 .port_mirror_add = mv88e6xxx_port_mirror_add,
5693 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04005694 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
5695 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005696 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
5697 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
5698 .port_txtstamp = mv88e6xxx_port_txtstamp,
5699 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
5700 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005701 .devlink_param_get = mv88e6xxx_devlink_param_get,
5702 .devlink_param_set = mv88e6xxx_devlink_param_set,
Andrew Lunn93157302020-09-18 21:11:09 +02005703 .devlink_info_get = mv88e6xxx_devlink_info_get,
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005704 .port_lag_change = mv88e6xxx_port_lag_change,
5705 .port_lag_join = mv88e6xxx_port_lag_join,
5706 .port_lag_leave = mv88e6xxx_port_lag_leave,
5707 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
5708 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
5709 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005710};
5711
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005712static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005713{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005714 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005715 struct dsa_switch *ds;
5716
Vivien Didelot7e99e342019-10-21 16:51:30 -04005717 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005718 if (!ds)
5719 return -ENOMEM;
5720
Vivien Didelot7e99e342019-10-21 16:51:30 -04005721 ds->dev = dev;
5722 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005723 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005724 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04005725 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04005726 ds->ageing_time_min = chip->info->age_time_coeff;
5727 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005728
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005729 /* Some chips support up to 32, but that requires enabling the
5730 * 5-bit port mode, which we do not support. 640k^W16 ought to
5731 * be enough for anyone.
5732 */
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005733 ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005734
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005735 dev_set_drvdata(dev, ds);
5736
Vivien Didelot23c9ee42017-05-26 18:12:51 -04005737 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005738}
5739
Vivien Didelotfad09c72016-06-21 12:28:20 -04005740static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005741{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005742 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005743}
5744
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005745static const void *pdata_device_get_match_data(struct device *dev)
5746{
5747 const struct of_device_id *matches = dev->driver->of_match_table;
5748 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
5749
5750 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
5751 matches++) {
5752 if (!strcmp(pdata->compatible, matches->compatible))
5753 return matches->data;
5754 }
5755 return NULL;
5756}
5757
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005758/* There is no suspend to RAM support at DSA level yet, the switch configuration
5759 * would be lost after a power cycle so prevent it to be suspended.
5760 */
5761static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
5762{
5763 return -EOPNOTSUPP;
5764}
5765
5766static int __maybe_unused mv88e6xxx_resume(struct device *dev)
5767{
5768 return 0;
5769}
5770
5771static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
5772
Vivien Didelot57d32312016-06-20 13:13:58 -04005773static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005774{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005775 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04005776 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005777 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005778 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04005779 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005780 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02005781 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005782
Andrew Lunn7bb8c992018-05-31 00:15:42 +02005783 if (!np && !pdata)
5784 return -EINVAL;
5785
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005786 if (np)
5787 compat_info = of_device_get_match_data(dev);
5788
5789 if (pdata) {
5790 compat_info = pdata_device_get_match_data(dev);
5791
5792 if (!pdata->netdev)
5793 return -EINVAL;
5794
5795 for (port = 0; port < DSA_MAX_PORTS; port++) {
5796 if (!(pdata->enabled_ports & (1 << port)))
5797 continue;
5798 if (strcmp(pdata->cd.port_names[port], "cpu"))
5799 continue;
5800 pdata->cd.netdev[port] = &pdata->netdev->dev;
5801 break;
5802 }
5803 }
5804
Vivien Didelotcaac8542016-06-20 13:14:09 -04005805 if (!compat_info)
5806 return -EINVAL;
5807
Vivien Didelotfad09c72016-06-21 12:28:20 -04005808 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005809 if (!chip) {
5810 err = -ENOMEM;
5811 goto out;
5812 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005813
Vivien Didelotfad09c72016-06-21 12:28:20 -04005814 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04005815
Vivien Didelotfad09c72016-06-21 12:28:20 -04005816 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04005817 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005818 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005819
Andrew Lunnb4308f02016-11-21 23:26:55 +01005820 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005821 if (IS_ERR(chip->reset)) {
5822 err = PTR_ERR(chip->reset);
5823 goto out;
5824 }
Baruch Siach7b75e492019-06-27 21:17:39 +03005825 if (chip->reset)
5826 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01005827
Vivien Didelotfad09c72016-06-21 12:28:20 -04005828 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005829 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005830 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005831
Vivien Didelote57e5e72016-08-15 17:19:00 -04005832 mv88e6xxx_phy_init(chip);
5833
Andrew Lunn00baabe2018-05-19 22:31:35 +02005834 if (chip->info->ops->get_eeprom) {
5835 if (np)
5836 of_property_read_u32(np, "eeprom-length",
5837 &chip->eeprom_len);
5838 else
5839 chip->eeprom_len = pdata->eeprom_len;
5840 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005841
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005842 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005843 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005844 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02005845 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02005846 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02005847
Andrew Lunna27415d2019-05-01 00:10:50 +02005848 if (np) {
5849 chip->irq = of_irq_get(np, 0);
5850 if (chip->irq == -EPROBE_DEFER) {
5851 err = chip->irq;
5852 goto out;
5853 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02005854 }
5855
Andrew Lunna27415d2019-05-01 00:10:50 +02005856 if (pdata)
5857 chip->irq = pdata->irq;
5858
Andrew Lunn294d7112018-02-22 22:58:32 +01005859 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01005860 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01005861 * controllers
5862 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005863 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005864 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005865 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005866 else
5867 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005868 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005869
Andrew Lunn294d7112018-02-22 22:58:32 +01005870 if (err)
5871 goto out;
5872
5873 if (chip->info->g2_irqs > 0) {
5874 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005875 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01005876 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005877 }
5878
Andrew Lunn294d7112018-02-22 22:58:32 +01005879 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
5880 if (err)
5881 goto out_g2_irq;
5882
5883 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
5884 if (err)
5885 goto out_g1_atu_prob_irq;
5886
Andrew Lunna3c53be52017-01-24 14:53:50 +01005887 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02005888 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01005889 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005890
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005891 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005892 if (err)
5893 goto out_mdio;
5894
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005895 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02005896
5897out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01005898 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01005899out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005900 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01005901out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005902 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005903out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005904 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005905 mv88e6xxx_g2_irq_free(chip);
5906out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005907 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005908 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005909 else
5910 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005911out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005912 if (pdata)
5913 dev_put(pdata->netdev);
5914
Andrew Lunndc30c352016-10-16 19:56:49 +02005915 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005916}
5917
5918static void mv88e6xxx_remove(struct mdio_device *mdiodev)
5919{
5920 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04005921 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005922
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005923 if (chip->info->ptp_support) {
5924 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005925 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005926 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005927
Andrew Lunn930188c2016-08-22 16:01:03 +02005928 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005929 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005930 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005931
Andrew Lunn76f38f12018-03-17 20:21:09 +01005932 mv88e6xxx_g1_vtu_prob_irq_free(chip);
5933 mv88e6xxx_g1_atu_prob_irq_free(chip);
5934
5935 if (chip->info->g2_irqs > 0)
5936 mv88e6xxx_g2_irq_free(chip);
5937
Andrew Lunn76f38f12018-03-17 20:21:09 +01005938 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005939 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01005940 else
5941 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005942}
5943
5944static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04005945 {
5946 .compatible = "marvell,mv88e6085",
5947 .data = &mv88e6xxx_table[MV88E6085],
5948 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005949 {
5950 .compatible = "marvell,mv88e6190",
5951 .data = &mv88e6xxx_table[MV88E6190],
5952 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005953 {
5954 .compatible = "marvell,mv88e6250",
5955 .data = &mv88e6xxx_table[MV88E6250],
5956 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005957 { /* sentinel */ },
5958};
5959
5960MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
5961
5962static struct mdio_driver mv88e6xxx_driver = {
5963 .probe = mv88e6xxx_probe,
5964 .remove = mv88e6xxx_remove,
5965 .mdiodrv.driver = {
5966 .name = "mv88e6085",
5967 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005968 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005969 },
5970};
5971
Andrew Lunn7324d502019-04-27 19:19:10 +02005972mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00005973
5974MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
5975MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
5976MODULE_LICENSE("GPL");