blob: f00cbf5753b914040be2dc3b31f2a15cb4274976 [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>
Vladimir Oltean5bded822021-10-07 19:47:11 +030015#include <linux/dsa/mv88e6xxx.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070016#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020017#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070018#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020019#include <linux/interrupt.h>
20#include <linux/irq.h>
21#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000022#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000023#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020024#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000025#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040026#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020027#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020028#include <linux/of_mdio.h>
Andrew Lunn877b7cb2018-05-19 22:31:34 +020029#include <linux/platform_data/mv88e6xxx.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000030#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010031#include <linux/gpio/consumer.h>
Russell Kingc9a23562018-05-10 13:17:35 -070032#include <linux/phylink.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000033#include <net/dsa.h>
Vivien Didelotec561272016-09-02 14:45:33 -040034
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -040035#include "chip.h"
Andrew Lunn9dd43aa2020-09-18 21:11:05 +020036#include "devlink.h"
Vivien Didelota935c052016-09-29 12:21:53 -040037#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040038#include "global2.h"
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +010039#include "hwtstamp.h"
Andrew Lunn10fa5bf2017-05-26 01:03:20 +020040#include "phy.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010041#include "port.h"
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +010042#include "ptp.h"
Andrew Lunn6d917822017-05-26 01:03:21 +020043#include "serdes.h"
Vivien Didelote7ba0fa2019-05-03 19:28:22 -040044#include "smi.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000045
Vivien Didelotfad09c72016-06-21 12:28:20 -040046static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040047{
Vivien Didelotfad09c72016-06-21 12:28:20 -040048 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
49 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040050 dump_stack();
51 }
52}
53
Vivien Didelotec561272016-09-02 14:45:33 -040054int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -040055{
56 int err;
57
Vivien Didelotfad09c72016-06-21 12:28:20 -040058 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -040059
Vivien Didelotfad09c72016-06-21 12:28:20 -040060 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040061 if (err)
62 return err;
63
Vivien Didelotfad09c72016-06-21 12:28:20 -040064 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -040065 addr, reg, *val);
66
67 return 0;
68}
69
Vivien Didelotec561272016-09-02 14:45:33 -040070int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -040071{
72 int err;
73
Vivien Didelotfad09c72016-06-21 12:28:20 -040074 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -040075
Vivien Didelotfad09c72016-06-21 12:28:20 -040076 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040077 if (err)
78 return err;
79
Vivien Didelotfad09c72016-06-21 12:28:20 -040080 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -040081 addr, reg, val);
82
83 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000084}
85
Vivien Didelot683f2242019-08-09 18:47:54 -040086int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg,
87 u16 mask, u16 val)
88{
89 u16 data;
90 int err;
91 int i;
92
93 /* There's no bus specific operation to wait for a mask */
94 for (i = 0; i < 16; i++) {
95 err = mv88e6xxx_read(chip, addr, reg, &data);
96 if (err)
97 return err;
98
99 if ((data & mask) == val)
100 return 0;
101
102 usleep_range(1000, 2000);
103 }
104
105 dev_err(chip->dev, "Timeout while waiting for switch\n");
106 return -ETIMEDOUT;
107}
108
Vivien Didelot19fb7f62019-08-09 18:47:55 -0400109int mv88e6xxx_wait_bit(struct mv88e6xxx_chip *chip, int addr, int reg,
110 int bit, int val)
111{
112 return mv88e6xxx_wait_mask(chip, addr, reg, BIT(bit),
113 val ? BIT(bit) : 0x0000);
114}
115
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200116struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
Andrew Lunna3c53be52017-01-24 14:53:50 +0100117{
118 struct mv88e6xxx_mdio_bus *mdio_bus;
119
120 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
121 list);
122 if (!mdio_bus)
123 return NULL;
124
125 return mdio_bus->bus;
126}
127
Andrew Lunndc30c352016-10-16 19:56:49 +0200128static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
129{
130 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
131 unsigned int n = d->hwirq;
132
133 chip->g1_irq.masked |= (1 << n);
134}
135
136static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
137{
138 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
139 unsigned int n = d->hwirq;
140
141 chip->g1_irq.masked &= ~(1 << n);
142}
143
Andrew Lunn294d7112018-02-22 22:58:32 +0100144static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200145{
Andrew Lunndc30c352016-10-16 19:56:49 +0200146 unsigned int nhandled = 0;
147 unsigned int sub_irq;
148 unsigned int n;
149 u16 reg;
John David Anglin7c0db242019-02-11 13:40:21 -0500150 u16 ctl1;
Andrew Lunndc30c352016-10-16 19:56:49 +0200151 int err;
152
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000153 mv88e6xxx_reg_lock(chip);
Vivien Didelot82466922017-06-15 12:13:59 -0400154 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000155 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200156
157 if (err)
158 goto out;
159
John David Anglin7c0db242019-02-11 13:40:21 -0500160 do {
161 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
162 if (reg & (1 << n)) {
163 sub_irq = irq_find_mapping(chip->g1_irq.domain,
164 n);
165 handle_nested_irq(sub_irq);
166 ++nhandled;
167 }
Andrew Lunndc30c352016-10-16 19:56:49 +0200168 }
John David Anglin7c0db242019-02-11 13:40:21 -0500169
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000170 mv88e6xxx_reg_lock(chip);
John David Anglin7c0db242019-02-11 13:40:21 -0500171 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1);
172 if (err)
173 goto unlock;
174 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
175unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000176 mv88e6xxx_reg_unlock(chip);
John David Anglin7c0db242019-02-11 13:40:21 -0500177 if (err)
178 goto out;
179 ctl1 &= GENMASK(chip->g1_irq.nirqs, 0);
180 } while (reg & ctl1);
181
Andrew Lunndc30c352016-10-16 19:56:49 +0200182out:
183 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
184}
185
Andrew Lunn294d7112018-02-22 22:58:32 +0100186static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
187{
188 struct mv88e6xxx_chip *chip = dev_id;
189
190 return mv88e6xxx_g1_irq_thread_work(chip);
191}
192
Andrew Lunndc30c352016-10-16 19:56:49 +0200193static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
194{
195 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
196
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000197 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200198}
199
200static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
201{
202 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
203 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
204 u16 reg;
205 int err;
206
Vivien Didelotd77f4322017-06-15 12:14:03 -0400207 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200208 if (err)
209 goto out;
210
211 reg &= ~mask;
212 reg |= (~chip->g1_irq.masked & mask);
213
Vivien Didelotd77f4322017-06-15 12:14:03 -0400214 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200215 if (err)
216 goto out;
217
218out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000219 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200220}
221
Bhumika Goyal6eb15e22017-08-19 16:25:52 +0530222static const struct irq_chip mv88e6xxx_g1_irq_chip = {
Andrew Lunndc30c352016-10-16 19:56:49 +0200223 .name = "mv88e6xxx-g1",
224 .irq_mask = mv88e6xxx_g1_irq_mask,
225 .irq_unmask = mv88e6xxx_g1_irq_unmask,
226 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
227 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
228};
229
230static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
231 unsigned int irq,
232 irq_hw_number_t hwirq)
233{
234 struct mv88e6xxx_chip *chip = d->host_data;
235
236 irq_set_chip_data(irq, d->host_data);
237 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
238 irq_set_noprobe(irq);
239
240 return 0;
241}
242
243static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
244 .map = mv88e6xxx_g1_irq_domain_map,
245 .xlate = irq_domain_xlate_twocell,
246};
247
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200248/* To be called with reg_lock held */
Andrew Lunn294d7112018-02-22 22:58:32 +0100249static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200250{
251 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100252 u16 mask;
253
Vivien Didelotd77f4322017-06-15 12:14:03 -0400254 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100255 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400256 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100257
Andreas Färber5edef2f2016-11-27 23:26:28 +0100258 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100259 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200260 irq_dispose_mapping(virq);
261 }
262
Andrew Lunna3db3d32016-11-20 20:14:14 +0100263 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200264}
265
Andrew Lunn294d7112018-02-22 22:58:32 +0100266static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
267{
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200268 /*
269 * free_irq must be called without reg_lock taken because the irq
270 * handler takes this lock, too.
271 */
Andrew Lunn294d7112018-02-22 22:58:32 +0100272 free_irq(chip->irq, chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200273
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000274 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200275 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000276 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100277}
278
279static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200280{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100281 int err, irq, virq;
282 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200283
284 chip->g1_irq.nirqs = chip->info->g1_irqs;
285 chip->g1_irq.domain = irq_domain_add_simple(
286 NULL, chip->g1_irq.nirqs, 0,
287 &mv88e6xxx_g1_irq_domain_ops, chip);
288 if (!chip->g1_irq.domain)
289 return -ENOMEM;
290
291 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
292 irq_create_mapping(chip->g1_irq.domain, irq);
293
294 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
295 chip->g1_irq.masked = ~0;
296
Vivien Didelotd77f4322017-06-15 12:14:03 -0400297 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200298 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100299 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200300
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100301 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200302
Vivien Didelotd77f4322017-06-15 12:14:03 -0400303 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200304 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100305 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200306
307 /* Reading the interrupt status clears (most of) them */
Vivien Didelot82466922017-06-15 12:13:59 -0400308 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200309 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100310 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200311
Andrew Lunndc30c352016-10-16 19:56:49 +0200312 return 0;
313
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100314out_disable:
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100315 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400316 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100317
318out_mapping:
319 for (irq = 0; irq < 16; irq++) {
320 virq = irq_find_mapping(chip->g1_irq.domain, irq);
321 irq_dispose_mapping(virq);
322 }
323
324 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200325
326 return err;
327}
328
Andrew Lunn294d7112018-02-22 22:58:32 +0100329static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
330{
Andrew Lunnf6d97582019-02-23 17:43:56 +0100331 static struct lock_class_key lock_key;
332 static struct lock_class_key request_key;
Andrew Lunn294d7112018-02-22 22:58:32 +0100333 int err;
334
335 err = mv88e6xxx_g1_irq_setup_common(chip);
336 if (err)
337 return err;
338
Andrew Lunnf6d97582019-02-23 17:43:56 +0100339 /* These lock classes tells lockdep that global 1 irqs are in
340 * a different category than their parent GPIO, so it won't
341 * report false recursion.
342 */
343 irq_set_lockdep_class(chip->irq, &lock_key, &request_key);
344
Andrew Lunn30953832020-01-06 17:13:48 +0100345 snprintf(chip->irq_name, sizeof(chip->irq_name),
346 "mv88e6xxx-%s", dev_name(chip->dev));
347
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000348 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100349 err = request_threaded_irq(chip->irq, NULL,
350 mv88e6xxx_g1_irq_thread_fn,
Marek Behún03403762018-08-30 02:13:50 +0200351 IRQF_ONESHOT | IRQF_SHARED,
Andrew Lunn30953832020-01-06 17:13:48 +0100352 chip->irq_name, chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000353 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100354 if (err)
355 mv88e6xxx_g1_irq_free_common(chip);
356
357 return err;
358}
359
360static void mv88e6xxx_irq_poll(struct kthread_work *work)
361{
362 struct mv88e6xxx_chip *chip = container_of(work,
363 struct mv88e6xxx_chip,
364 irq_poll_work.work);
365 mv88e6xxx_g1_irq_thread_work(chip);
366
367 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
368 msecs_to_jiffies(100));
369}
370
371static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
372{
373 int err;
374
375 err = mv88e6xxx_g1_irq_setup_common(chip);
376 if (err)
377 return err;
378
379 kthread_init_delayed_work(&chip->irq_poll_work,
380 mv88e6xxx_irq_poll);
381
Florian Fainelli3f8b8692019-02-21 20:09:27 -0800382 chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
Andrew Lunn294d7112018-02-22 22:58:32 +0100383 if (IS_ERR(chip->kworker))
384 return PTR_ERR(chip->kworker);
385
386 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
387 msecs_to_jiffies(100));
388
389 return 0;
390}
391
392static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
393{
394 kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
395 kthread_destroy_worker(chip->kworker);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200396
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000397 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200398 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000399 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100400}
401
Russell King64d47d52020-03-14 10:15:38 +0000402static int mv88e6xxx_port_config_interface(struct mv88e6xxx_chip *chip,
403 int port, phy_interface_t interface)
404{
405 int err;
406
407 if (chip->info->ops->port_set_rgmii_delay) {
408 err = chip->info->ops->port_set_rgmii_delay(chip, port,
409 interface);
410 if (err && err != -EOPNOTSUPP)
411 return err;
412 }
413
414 if (chip->info->ops->port_set_cmode) {
415 err = chip->info->ops->port_set_cmode(chip, port,
416 interface);
417 if (err && err != -EOPNOTSUPP)
418 return err;
419 }
420
421 return 0;
422}
423
Russell Kinga5a68582020-03-14 10:15:43 +0000424static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
425 int link, int speed, int duplex, int pause,
426 phy_interface_t mode)
Vivien Didelotd78343d2016-11-04 03:23:36 +0100427{
428 int err;
429
430 if (!chip->info->ops->port_set_link)
431 return 0;
432
433 /* Port's MAC control must not be changed unless the link is down */
Hubert Feurstein43c8e0a2019-07-30 12:11:42 +0200434 err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100435 if (err)
436 return err;
437
Russell Kingf365c6f2020-03-14 10:15:53 +0000438 if (chip->info->ops->port_set_speed_duplex) {
439 err = chip->info->ops->port_set_speed_duplex(chip, port,
440 speed, duplex);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100441 if (err && err != -EOPNOTSUPP)
442 goto restore_link;
443 }
444
Andrew Lunn7cbbee02019-03-08 01:21:27 +0100445 if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
446 mode = chip->info->ops->port_max_speed_mode(port);
447
Andrew Lunn54186b92018-08-09 15:38:37 +0200448 if (chip->info->ops->port_set_pause) {
449 err = chip->info->ops->port_set_pause(chip, port, pause);
450 if (err)
451 goto restore_link;
452 }
453
Russell King64d47d52020-03-14 10:15:38 +0000454 err = mv88e6xxx_port_config_interface(chip, port, mode);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100455restore_link:
456 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400457 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100458
459 return err;
460}
461
Marek Vasutd700ec42018-09-12 00:15:24 +0200462static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
463{
464 struct mv88e6xxx_chip *chip = ds->priv;
465
466 return port < chip->info->num_internal_phys;
467}
468
Russell King5d5b2312020-03-14 10:16:03 +0000469static int mv88e6xxx_port_ppu_updates(struct mv88e6xxx_chip *chip, int port)
470{
471 u16 reg;
472 int err;
473
474 err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
475 if (err) {
476 dev_err(chip->dev,
477 "p%d: %s: failed to read port status\n",
478 port, __func__);
479 return err;
480 }
481
482 return !!(reg & MV88E6XXX_PORT_STS_PHY_DETECT);
483}
484
Russell Kinga5a68582020-03-14 10:15:43 +0000485static int mv88e6xxx_serdes_pcs_get_state(struct dsa_switch *ds, int port,
486 struct phylink_link_state *state)
487{
488 struct mv88e6xxx_chip *chip = ds->priv;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100489 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000490 int err;
491
492 mv88e6xxx_reg_lock(chip);
493 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100494 if (lane >= 0 && chip->info->ops->serdes_pcs_get_state)
Russell Kinga5a68582020-03-14 10:15:43 +0000495 err = chip->info->ops->serdes_pcs_get_state(chip, port, lane,
496 state);
497 else
498 err = -EOPNOTSUPP;
499 mv88e6xxx_reg_unlock(chip);
500
501 return err;
502}
503
504static int mv88e6xxx_serdes_pcs_config(struct mv88e6xxx_chip *chip, int port,
505 unsigned int mode,
506 phy_interface_t interface,
507 const unsigned long *advertise)
508{
509 const struct mv88e6xxx_ops *ops = chip->info->ops;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100510 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000511
512 if (ops->serdes_pcs_config) {
513 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100514 if (lane >= 0)
Russell Kinga5a68582020-03-14 10:15:43 +0000515 return ops->serdes_pcs_config(chip, port, lane, mode,
516 interface, advertise);
517 }
518
519 return 0;
520}
521
522static void mv88e6xxx_serdes_pcs_an_restart(struct dsa_switch *ds, int port)
523{
524 struct mv88e6xxx_chip *chip = ds->priv;
525 const struct mv88e6xxx_ops *ops;
526 int err = 0;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100527 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000528
529 ops = chip->info->ops;
530
531 if (ops->serdes_pcs_an_restart) {
532 mv88e6xxx_reg_lock(chip);
533 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100534 if (lane >= 0)
Russell Kinga5a68582020-03-14 10:15:43 +0000535 err = ops->serdes_pcs_an_restart(chip, port, lane);
536 mv88e6xxx_reg_unlock(chip);
537
538 if (err)
539 dev_err(ds->dev, "p%d: failed to restart AN\n", port);
540 }
541}
542
543static int mv88e6xxx_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port,
544 unsigned int mode,
545 int speed, int duplex)
546{
547 const struct mv88e6xxx_ops *ops = chip->info->ops;
Pavana Sharma193c5b22021-03-17 14:46:40 +0100548 int lane;
Russell Kinga5a68582020-03-14 10:15:43 +0000549
550 if (!phylink_autoneg_inband(mode) && ops->serdes_pcs_link_up) {
551 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +0100552 if (lane >= 0)
Russell Kinga5a68582020-03-14 10:15:43 +0000553 return ops->serdes_pcs_link_up(chip, port, lane,
554 speed, duplex);
555 }
556
557 return 0;
558}
559
Russell King6c422e32018-08-09 15:38:39 +0200560static void mv88e6065_phylink_validate(struct mv88e6xxx_chip *chip, int port,
561 unsigned long *mask,
562 struct phylink_link_state *state)
563{
564 if (!phy_interface_mode_is_8023z(state->interface)) {
565 /* 10M and 100M are only supported in non-802.3z mode */
566 phylink_set(mask, 10baseT_Half);
567 phylink_set(mask, 10baseT_Full);
568 phylink_set(mask, 100baseT_Half);
569 phylink_set(mask, 100baseT_Full);
570 }
571}
572
573static void mv88e6185_phylink_validate(struct mv88e6xxx_chip *chip, int port,
574 unsigned long *mask,
575 struct phylink_link_state *state)
576{
577 /* FIXME: if the port is in 1000Base-X mode, then it only supports
578 * 1000M FD speeds. In this case, CMODE will indicate 5.
579 */
580 phylink_set(mask, 1000baseT_Full);
581 phylink_set(mask, 1000baseX_Full);
582
583 mv88e6065_phylink_validate(chip, port, mask, state);
584}
585
Marek Behúne3af71a2019-02-25 12:39:55 +0100586static void mv88e6341_phylink_validate(struct mv88e6xxx_chip *chip, int port,
587 unsigned long *mask,
588 struct phylink_link_state *state)
589{
590 if (port >= 5)
591 phylink_set(mask, 2500baseX_Full);
592
593 /* No ethtool bits for 200Mbps */
594 phylink_set(mask, 1000baseT_Full);
595 phylink_set(mask, 1000baseX_Full);
596
597 mv88e6065_phylink_validate(chip, port, mask, state);
598}
599
Russell King6c422e32018-08-09 15:38:39 +0200600static void mv88e6352_phylink_validate(struct mv88e6xxx_chip *chip, int port,
601 unsigned long *mask,
602 struct phylink_link_state *state)
603{
604 /* No ethtool bits for 200Mbps */
605 phylink_set(mask, 1000baseT_Full);
606 phylink_set(mask, 1000baseX_Full);
607
608 mv88e6065_phylink_validate(chip, port, mask, state);
609}
610
611static void mv88e6390_phylink_validate(struct mv88e6xxx_chip *chip, int port,
612 unsigned long *mask,
613 struct phylink_link_state *state)
614{
Andrew Lunnec260162019-02-08 22:25:44 +0100615 if (port >= 9) {
Russell King6c422e32018-08-09 15:38:39 +0200616 phylink_set(mask, 2500baseX_Full);
Andrew Lunnec260162019-02-08 22:25:44 +0100617 phylink_set(mask, 2500baseT_Full);
618 }
Russell King6c422e32018-08-09 15:38:39 +0200619
620 /* No ethtool bits for 200Mbps */
621 phylink_set(mask, 1000baseT_Full);
622 phylink_set(mask, 1000baseX_Full);
623
624 mv88e6065_phylink_validate(chip, port, mask, state);
625}
626
627static void mv88e6390x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
628 unsigned long *mask,
629 struct phylink_link_state *state)
630{
631 if (port >= 9) {
632 phylink_set(mask, 10000baseT_Full);
633 phylink_set(mask, 10000baseKR_Full);
634 }
635
636 mv88e6390_phylink_validate(chip, port, mask, state);
637}
638
Pavana Sharmade776d02021-03-17 14:46:42 +0100639static void mv88e6393x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
640 unsigned long *mask,
641 struct phylink_link_state *state)
642{
Marek Behúndc2fc9f2021-11-04 18:17:47 +0100643 bool is_6191x =
644 chip->info->prod_num == MV88E6XXX_PORT_SWITCH_ID_PROD_6191X;
645
646 if (((port == 0 || port == 9) && !is_6191x) || port == 10) {
Pavana Sharmade776d02021-03-17 14:46:42 +0100647 phylink_set(mask, 10000baseT_Full);
648 phylink_set(mask, 10000baseKR_Full);
649 phylink_set(mask, 10000baseCR_Full);
650 phylink_set(mask, 10000baseSR_Full);
651 phylink_set(mask, 10000baseLR_Full);
652 phylink_set(mask, 10000baseLRM_Full);
653 phylink_set(mask, 10000baseER_Full);
654 phylink_set(mask, 5000baseT_Full);
655 phylink_set(mask, 2500baseX_Full);
656 phylink_set(mask, 2500baseT_Full);
657 }
658
659 phylink_set(mask, 1000baseT_Full);
660 phylink_set(mask, 1000baseX_Full);
661
662 mv88e6065_phylink_validate(chip, port, mask, state);
663}
664
Russell Kingc9a23562018-05-10 13:17:35 -0700665static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
666 unsigned long *supported,
667 struct phylink_link_state *state)
668{
Russell King6c422e32018-08-09 15:38:39 +0200669 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
670 struct mv88e6xxx_chip *chip = ds->priv;
671
672 /* Allow all the expected bits */
673 phylink_set(mask, Autoneg);
674 phylink_set(mask, Pause);
675 phylink_set_port_modes(mask);
676
677 if (chip->info->ops->phylink_validate)
678 chip->info->ops->phylink_validate(chip, port, mask, state);
679
Sean Anderson49730562021-10-22 18:41:04 -0400680 linkmode_and(supported, supported, mask);
681 linkmode_and(state->advertising, state->advertising, mask);
Russell King6c422e32018-08-09 15:38:39 +0200682
683 /* We can only operate at 2500BaseX or 1000BaseX. If requested
684 * to advertise both, only report advertising at 2500BaseX.
685 */
686 phylink_helper_basex_speed(state);
Russell Kingc9a23562018-05-10 13:17:35 -0700687}
688
Russell Kingc9a23562018-05-10 13:17:35 -0700689static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
690 unsigned int mode,
691 const struct phylink_link_state *state)
692{
693 struct mv88e6xxx_chip *chip = ds->priv;
Russell Kingfad58192020-07-19 12:00:35 +0100694 struct mv88e6xxx_port *p;
Russell King64d47d52020-03-14 10:15:38 +0000695 int err;
Russell Kingc9a23562018-05-10 13:17:35 -0700696
Russell Kingfad58192020-07-19 12:00:35 +0100697 p = &chip->ports[port];
698
Russell King64d47d52020-03-14 10:15:38 +0000699 /* FIXME: is this the correct test? If we're in fixed mode on an
700 * internal port, why should we process this any different from
701 * PHY mode? On the other hand, the port may be automedia between
702 * an internal PHY and the serdes...
703 */
Marek Vasutd700ec42018-09-12 00:15:24 +0200704 if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
Russell Kingc9a23562018-05-10 13:17:35 -0700705 return;
706
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000707 mv88e6xxx_reg_lock(chip);
Russell Kingfad58192020-07-19 12:00:35 +0100708 /* In inband mode, the link may come up at any time while the link
709 * is not forced down. Force the link down while we reconfigure the
710 * interface mode.
Russell King64d47d52020-03-14 10:15:38 +0000711 */
Russell Kingfad58192020-07-19 12:00:35 +0100712 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
713 chip->info->ops->port_set_link)
714 chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
715
Russell King64d47d52020-03-14 10:15:38 +0000716 err = mv88e6xxx_port_config_interface(chip, port, state->interface);
Russell Kinga5a68582020-03-14 10:15:43 +0000717 if (err && err != -EOPNOTSUPP)
718 goto err_unlock;
719
720 err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
721 state->advertising);
722 /* FIXME: we should restart negotiation if something changed - which
723 * is something we get if we convert to using phylinks PCS operations.
724 */
725 if (err > 0)
726 err = 0;
727
Russell Kingfad58192020-07-19 12:00:35 +0100728 /* Undo the forced down state above after completing configuration
729 * irrespective of its state on entry, which allows the link to come up.
730 */
731 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
732 chip->info->ops->port_set_link)
733 chip->info->ops->port_set_link(chip, port, LINK_UNFORCED);
734
735 p->interface = state->interface;
736
Russell Kinga5a68582020-03-14 10:15:43 +0000737err_unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000738 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700739
740 if (err && err != -EOPNOTSUPP)
Russell King64d47d52020-03-14 10:15:38 +0000741 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700742}
743
Russell Kingc9a23562018-05-10 13:17:35 -0700744static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
745 unsigned int mode,
746 phy_interface_t interface)
747{
Russell King30c4a5b2020-02-26 10:23:51 +0000748 struct mv88e6xxx_chip *chip = ds->priv;
749 const struct mv88e6xxx_ops *ops;
750 int err = 0;
751
752 ops = chip->info->ops;
753
Russell King5d5b2312020-03-14 10:16:03 +0000754 mv88e6xxx_reg_lock(chip);
Maarten Zanders4a3e0ae2021-10-11 16:27:20 +0200755 /* Internal PHYs propagate their configuration directly to the MAC.
756 * External PHYs depend on whether the PPU is enabled for this port.
757 */
758 if (((!mv88e6xxx_phy_is_internal(ds, port) &&
759 !mv88e6xxx_port_ppu_updates(chip, port)) ||
Chris Packham4efe76622020-11-24 17:34:37 +1300760 mode == MLO_AN_FIXED) && ops->port_sync_link)
761 err = ops->port_sync_link(chip, port, mode, false);
Russell King5d5b2312020-03-14 10:16:03 +0000762 mv88e6xxx_reg_unlock(chip);
Russell King30c4a5b2020-02-26 10:23:51 +0000763
Russell King5d5b2312020-03-14 10:16:03 +0000764 if (err)
765 dev_err(chip->dev,
766 "p%d: failed to force MAC link down\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700767}
768
769static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
770 unsigned int mode, phy_interface_t interface,
Russell King5b502a72020-02-26 10:23:46 +0000771 struct phy_device *phydev,
772 int speed, int duplex,
773 bool tx_pause, bool rx_pause)
Russell Kingc9a23562018-05-10 13:17:35 -0700774{
Russell King30c4a5b2020-02-26 10:23:51 +0000775 struct mv88e6xxx_chip *chip = ds->priv;
776 const struct mv88e6xxx_ops *ops;
777 int err = 0;
778
779 ops = chip->info->ops;
780
Russell King5d5b2312020-03-14 10:16:03 +0000781 mv88e6xxx_reg_lock(chip);
Maarten Zanders4a3e0ae2021-10-11 16:27:20 +0200782 /* Internal PHYs propagate their configuration directly to the MAC.
783 * External PHYs depend on whether the PPU is enabled for this port.
784 */
785 if ((!mv88e6xxx_phy_is_internal(ds, port) &&
786 !mv88e6xxx_port_ppu_updates(chip, port)) ||
787 mode == MLO_AN_FIXED) {
Russell King30c4a5b2020-02-26 10:23:51 +0000788 /* FIXME: for an automedia port, should we force the link
789 * down here - what if the link comes up due to "other" media
790 * while we're bringing the port up, how is the exclusivity
Russell Kinga5a68582020-03-14 10:15:43 +0000791 * handled in the Marvell hardware? E.g. port 2 on 88E6390
Russell King30c4a5b2020-02-26 10:23:51 +0000792 * shared between internal PHY and Serdes.
793 */
Russell Kinga5a68582020-03-14 10:15:43 +0000794 err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
795 duplex);
796 if (err)
797 goto error;
798
Russell Kingf365c6f2020-03-14 10:15:53 +0000799 if (ops->port_set_speed_duplex) {
800 err = ops->port_set_speed_duplex(chip, port,
801 speed, duplex);
Russell King30c4a5b2020-02-26 10:23:51 +0000802 if (err && err != -EOPNOTSUPP)
803 goto error;
804 }
805
Chris Packham4efe76622020-11-24 17:34:37 +1300806 if (ops->port_sync_link)
807 err = ops->port_sync_link(chip, port, mode, true);
Russell King30c4a5b2020-02-26 10:23:51 +0000808 }
Russell King5d5b2312020-03-14 10:16:03 +0000809error:
810 mv88e6xxx_reg_unlock(chip);
811
812 if (err && err != -EOPNOTSUPP)
813 dev_err(ds->dev,
814 "p%d: failed to configure MAC link up\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700815}
816
Andrew Lunna605a0f2016-11-21 23:26:58 +0100817static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000818{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100819 if (!chip->info->ops->stats_snapshot)
820 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000821
Andrew Lunna605a0f2016-11-21 23:26:58 +0100822 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000823}
824
Andrew Lunne413e7e2015-04-02 04:06:38 +0200825static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100826 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
827 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
828 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
829 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
830 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
831 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
832 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
833 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
834 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
835 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
836 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
837 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
838 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
839 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
840 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
841 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
842 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
843 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
844 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
845 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
846 { "single", 4, 0x14, STATS_TYPE_BANK0, },
847 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
848 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
849 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
850 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
851 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
852 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
853 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
854 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
855 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
856 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
857 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
858 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
859 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
860 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
861 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
862 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
863 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
864 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
865 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
866 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
867 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
868 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
869 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
870 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
871 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
872 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
873 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
874 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
875 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
876 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
877 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
878 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
879 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
880 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
881 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
882 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
883 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
884 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200885};
886
Vivien Didelotfad09c72016-06-21 12:28:20 -0400887static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100888 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100889 int port, u16 bank1_select,
890 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200891{
Andrew Lunn80c46272015-06-20 18:42:30 +0200892 u32 low;
893 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100894 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200895 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200896 u64 value;
897
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100898 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100899 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200900 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
901 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800902 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200903
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200904 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100905 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200906 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
907 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800908 return U64_MAX;
Rasmus Villemoes84b3fd12019-05-29 07:02:11 +0000909 low |= ((u32)reg) << 16;
Andrew Lunn80c46272015-06-20 18:42:30 +0200910 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100911 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100912 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100913 reg = bank1_select;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500914 fallthrough;
Andrew Lunndfafe442016-11-21 23:27:02 +0100915 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100916 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100917 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100918 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100919 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500920 break;
921 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800922 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200923 }
Andrew Lunn6e46e2d2019-02-28 18:14:03 +0100924 value = (((u64)high) << 32) | low;
Andrew Lunn80c46272015-06-20 18:42:30 +0200925 return value;
926}
927
Andrew Lunn436fe172018-03-01 02:02:29 +0100928static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
929 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100930{
931 struct mv88e6xxx_hw_stat *stat;
932 int i, j;
933
934 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
935 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100936 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100937 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
938 ETH_GSTRING_LEN);
939 j++;
940 }
941 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100942
943 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100944}
945
Andrew Lunn436fe172018-03-01 02:02:29 +0100946static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
947 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100948{
Andrew Lunn436fe172018-03-01 02:02:29 +0100949 return mv88e6xxx_stats_get_strings(chip, data,
950 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100951}
952
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000953static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
954 uint8_t *data)
955{
956 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
957}
958
Andrew Lunn436fe172018-03-01 02:02:29 +0100959static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
960 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100961{
Andrew Lunn436fe172018-03-01 02:02:29 +0100962 return mv88e6xxx_stats_get_strings(chip, data,
963 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100964}
965
Andrew Lunn65f60e42018-03-28 23:50:28 +0200966static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
967 "atu_member_violation",
968 "atu_miss_violation",
969 "atu_full_violation",
970 "vtu_member_violation",
971 "vtu_miss_violation",
972};
973
974static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
975{
976 unsigned int i;
977
978 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
979 strlcpy(data + i * ETH_GSTRING_LEN,
980 mv88e6xxx_atu_vtu_stats_strings[i],
981 ETH_GSTRING_LEN);
982}
983
Andrew Lunndfafe442016-11-21 23:27:02 +0100984static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700985 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100986{
Vivien Didelot04bed142016-08-31 18:06:13 -0400987 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100988 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100989
Florian Fainelli89f09042018-04-25 12:12:50 -0700990 if (stringset != ETH_SS_STATS)
991 return;
992
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000993 mv88e6xxx_reg_lock(chip);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100994
Andrew Lunndfafe442016-11-21 23:27:02 +0100995 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100996 count = chip->info->ops->stats_get_strings(chip, data);
997
998 if (chip->info->ops->serdes_get_strings) {
999 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001000 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +01001001 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +01001002
Andrew Lunn65f60e42018-03-28 23:50:28 +02001003 data += count * ETH_GSTRING_LEN;
1004 mv88e6xxx_atu_vtu_get_strings(data);
1005
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001006 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001007}
1008
1009static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
1010 int types)
1011{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001012 struct mv88e6xxx_hw_stat *stat;
1013 int i, j;
1014
1015 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1016 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +01001017 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001018 j++;
1019 }
1020 return j;
1021}
1022
Andrew Lunndfafe442016-11-21 23:27:02 +01001023static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1024{
1025 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1026 STATS_TYPE_PORT);
1027}
1028
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001029static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1030{
1031 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
1032}
1033
Andrew Lunndfafe442016-11-21 23:27:02 +01001034static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1035{
1036 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1037 STATS_TYPE_BANK1);
1038}
1039
Florian Fainelli89f09042018-04-25 12:12:50 -07001040static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +01001041{
1042 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +01001043 int serdes_count = 0;
1044 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +01001045
Florian Fainelli89f09042018-04-25 12:12:50 -07001046 if (sset != ETH_SS_STATS)
1047 return 0;
1048
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001049 mv88e6xxx_reg_lock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001050 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +01001051 count = chip->info->ops->stats_get_sset_count(chip);
1052 if (count < 0)
1053 goto out;
1054
1055 if (chip->info->ops->serdes_get_sset_count)
1056 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1057 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +02001058 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +01001059 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001060 goto out;
1061 }
1062 count += serdes_count;
1063 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1064
Andrew Lunn436fe172018-03-01 02:02:29 +01001065out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001066 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001067
Andrew Lunn436fe172018-03-01 02:02:29 +01001068 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +01001069}
1070
Andrew Lunn436fe172018-03-01 02:02:29 +01001071static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1072 uint64_t *data, int types,
1073 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +01001074{
1075 struct mv88e6xxx_hw_stat *stat;
1076 int i, j;
1077
1078 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1079 stat = &mv88e6xxx_hw_stats[i];
1080 if (stat->type & types) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001081 mv88e6xxx_reg_lock(chip);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001082 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1083 bank1_select,
1084 histogram);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001085 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001086
Andrew Lunn052f9472016-11-21 23:27:03 +01001087 j++;
1088 }
1089 }
Andrew Lunn436fe172018-03-01 02:02:29 +01001090 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +01001091}
1092
Andrew Lunn436fe172018-03-01 02:02:29 +01001093static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1094 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001095{
1096 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001097 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001098 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +01001099}
1100
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001101static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1102 uint64_t *data)
1103{
1104 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
1105 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1106}
1107
Andrew Lunn436fe172018-03-01 02:02:29 +01001108static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1109 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001110{
1111 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001112 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001113 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1114 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001115}
1116
Andrew Lunn436fe172018-03-01 02:02:29 +01001117static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1118 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +01001119{
1120 return mv88e6xxx_stats_get_stats(chip, port, data,
1121 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001122 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1123 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001124}
1125
Andrew Lunn65f60e42018-03-28 23:50:28 +02001126static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1127 uint64_t *data)
1128{
1129 *data++ = chip->ports[port].atu_member_violation;
1130 *data++ = chip->ports[port].atu_miss_violation;
1131 *data++ = chip->ports[port].atu_full_violation;
1132 *data++ = chip->ports[port].vtu_member_violation;
1133 *data++ = chip->ports[port].vtu_miss_violation;
1134}
1135
Andrew Lunn052f9472016-11-21 23:27:03 +01001136static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1137 uint64_t *data)
1138{
Andrew Lunn436fe172018-03-01 02:02:29 +01001139 int count = 0;
1140
Andrew Lunn052f9472016-11-21 23:27:03 +01001141 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +01001142 count = chip->info->ops->stats_get_stats(chip, port, data);
1143
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001144 mv88e6xxx_reg_lock(chip);
Andrew Lunn436fe172018-03-01 02:02:29 +01001145 if (chip->info->ops->serdes_get_stats) {
1146 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001147 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +01001148 }
Andrew Lunn65f60e42018-03-28 23:50:28 +02001149 data += count;
1150 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001151 mv88e6xxx_reg_unlock(chip);
Andrew Lunn052f9472016-11-21 23:27:03 +01001152}
1153
Vivien Didelotf81ec902016-05-09 13:22:58 -04001154static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1155 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001156{
Vivien Didelot04bed142016-08-31 18:06:13 -04001157 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001158 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001159
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001160 mv88e6xxx_reg_lock(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001161
Andrew Lunna605a0f2016-11-21 23:26:58 +01001162 ret = mv88e6xxx_stats_snapshot(chip, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001163 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001164
1165 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001166 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001167
1168 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001169
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001170}
Ben Hutchings98e67302011-11-25 14:36:19 +00001171
Vivien Didelotf81ec902016-05-09 13:22:58 -04001172static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001173{
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001174 struct mv88e6xxx_chip *chip = ds->priv;
1175 int len;
1176
1177 len = 32 * sizeof(u16);
1178 if (chip->info->ops->serdes_get_regs_len)
1179 len += chip->info->ops->serdes_get_regs_len(chip, port);
1180
1181 return len;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001182}
1183
Vivien Didelotf81ec902016-05-09 13:22:58 -04001184static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1185 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001186{
Vivien Didelot04bed142016-08-31 18:06:13 -04001187 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001188 int err;
1189 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001190 u16 *p = _p;
1191 int i;
1192
Vivien Didelota5f39322018-12-17 16:05:21 -05001193 regs->version = chip->info->prod_num;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001194
1195 memset(p, 0xff, 32 * sizeof(u16));
1196
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001197 mv88e6xxx_reg_lock(chip);
Vivien Didelot23062512016-05-09 13:22:45 -04001198
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001199 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001200
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001201 err = mv88e6xxx_port_read(chip, port, i, &reg);
1202 if (!err)
1203 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001204 }
Vivien Didelot23062512016-05-09 13:22:45 -04001205
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001206 if (chip->info->ops->serdes_get_regs)
1207 chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1208
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001209 mv88e6xxx_reg_unlock(chip);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001210}
1211
Vivien Didelot08f50062017-08-01 16:32:41 -04001212static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1213 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001214{
Vivien Didelot5480db62017-08-01 16:32:40 -04001215 /* Nothing to do on the port's MAC */
1216 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001217}
1218
Vivien Didelot08f50062017-08-01 16:32:41 -04001219static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1220 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001221{
Vivien Didelot5480db62017-08-01 16:32:40 -04001222 /* Nothing to do on the port's MAC */
1223 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001224}
1225
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001226/* Mask of the local ports allowed to receive frames from a given fabric port */
Vivien Didelote5887a22017-03-30 17:37:11 -04001227static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001228{
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001229 struct dsa_switch *ds = chip->ds;
1230 struct dsa_switch_tree *dst = ds->dst;
Vivien Didelote5887a22017-03-30 17:37:11 -04001231 struct net_device *br;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001232 struct dsa_port *dp;
1233 bool found = false;
Vivien Didelote5887a22017-03-30 17:37:11 -04001234 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001235
Vladimir Olteance5df682021-07-22 18:55:41 +03001236 /* dev is a physical switch */
1237 if (dev <= dst->last_switch) {
1238 list_for_each_entry(dp, &dst->ports, list) {
1239 if (dp->ds->index == dev && dp->index == port) {
1240 /* dp might be a DSA link or a user port, so it
1241 * might or might not have a bridge_dev
1242 * pointer. Use the "found" variable for both
1243 * cases.
1244 */
1245 br = dp->bridge_dev;
1246 found = true;
1247 break;
1248 }
1249 }
1250 /* dev is a virtual bridge */
1251 } else {
1252 list_for_each_entry(dp, &dst->ports, list) {
1253 if (dp->bridge_num < 0)
1254 continue;
1255
1256 if (dp->bridge_num + 1 + dst->last_switch != dev)
1257 continue;
1258
1259 br = dp->bridge_dev;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001260 found = true;
1261 break;
1262 }
1263 }
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001264
Vladimir Olteance5df682021-07-22 18:55:41 +03001265 /* Prevent frames from unknown switch or virtual bridge */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001266 if (!found)
Vivien Didelote5887a22017-03-30 17:37:11 -04001267 return 0;
1268
1269 /* Frames from DSA links and CPU ports can egress any local port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001270 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
Vivien Didelote5887a22017-03-30 17:37:11 -04001271 return mv88e6xxx_port_mask(chip);
1272
Vivien Didelote5887a22017-03-30 17:37:11 -04001273 pvlan = 0;
1274
1275 /* Frames from user ports can egress any local DSA links and CPU ports,
1276 * as well as any local member of their bridge group.
1277 */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001278 list_for_each_entry(dp, &dst->ports, list)
1279 if (dp->ds == ds &&
1280 (dp->type == DSA_PORT_TYPE_CPU ||
1281 dp->type == DSA_PORT_TYPE_DSA ||
1282 (br && dp->bridge_dev == br)))
1283 pvlan |= BIT(dp->index);
Vivien Didelote5887a22017-03-30 17:37:11 -04001284
1285 return pvlan;
1286}
1287
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001288static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001289{
1290 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001291
1292 /* prevent frames from going back out of the port they came in on */
1293 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001294
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001295 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001296}
1297
Vivien Didelotf81ec902016-05-09 13:22:58 -04001298static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1299 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001300{
Vivien Didelot04bed142016-08-31 18:06:13 -04001301 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001302 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001303
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001304 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001305 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001306 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001307
1308 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001309 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001310}
1311
Vivien Didelot93e18d62018-05-11 17:16:35 -04001312static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1313{
1314 int err;
1315
1316 if (chip->info->ops->ieee_pri_map) {
1317 err = chip->info->ops->ieee_pri_map(chip);
1318 if (err)
1319 return err;
1320 }
1321
1322 if (chip->info->ops->ip_pri_map) {
1323 err = chip->info->ops->ip_pri_map(chip);
1324 if (err)
1325 return err;
1326 }
1327
1328 return 0;
1329}
1330
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001331static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1332{
Vivien Didelotc5f51762019-10-30 22:09:13 -04001333 struct dsa_switch *ds = chip->ds;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001334 int target, port;
1335 int err;
1336
1337 if (!chip->info->global2_addr)
1338 return 0;
1339
1340 /* Initialize the routing port to the 32 possible target devices */
1341 for (target = 0; target < 32; target++) {
Vivien Didelotc5f51762019-10-30 22:09:13 -04001342 port = dsa_routing_port(ds, target);
1343 if (port == ds->num_ports)
1344 port = 0x1f;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001345
1346 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1347 if (err)
1348 return err;
1349 }
1350
Vivien Didelot02317e62018-05-09 11:38:49 -04001351 if (chip->info->ops->set_cascade_port) {
1352 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1353 err = chip->info->ops->set_cascade_port(chip, port);
1354 if (err)
1355 return err;
1356 }
1357
Vivien Didelot23c98912018-05-09 11:38:50 -04001358 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1359 if (err)
1360 return err;
1361
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001362 return 0;
1363}
1364
Vivien Didelotb28f8722018-04-26 21:56:44 -04001365static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1366{
1367 /* Clear all trunk masks and mapping */
1368 if (chip->info->global2_addr)
1369 return mv88e6xxx_g2_trunk_clear(chip);
1370
1371 return 0;
1372}
1373
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001374static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1375{
1376 if (chip->info->ops->rmu_disable)
1377 return chip->info->ops->rmu_disable(chip);
1378
1379 return 0;
1380}
1381
Vivien Didelot9e907d72017-07-17 13:03:43 -04001382static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1383{
1384 if (chip->info->ops->pot_clear)
1385 return chip->info->ops->pot_clear(chip);
1386
1387 return 0;
1388}
1389
Vivien Didelot51c901a2017-07-17 13:03:41 -04001390static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1391{
1392 if (chip->info->ops->mgmt_rsvd2cpu)
1393 return chip->info->ops->mgmt_rsvd2cpu(chip);
1394
1395 return 0;
1396}
1397
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001398static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1399{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001400 int err;
1401
Vivien Didelotdaefc942017-03-11 16:12:54 -05001402 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1403 if (err)
1404 return err;
1405
Rasmus Villemoes49506a92020-12-10 12:06:44 +01001406 /* The chips that have a "learn2all" bit in Global1, ATU
1407 * Control are precisely those whose port registers have a
1408 * Message Port bit in Port Control 1 and hence implement
1409 * ->port_setup_message_port.
1410 */
1411 if (chip->info->ops->port_setup_message_port) {
1412 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1413 if (err)
1414 return err;
1415 }
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001416
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001417 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1418}
1419
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001420static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1421{
1422 int port;
1423 int err;
1424
1425 if (!chip->info->ops->irl_init_all)
1426 return 0;
1427
1428 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1429 /* Disable ingress rate limiting by resetting all per port
1430 * ingress rate limit resources to their initial state.
1431 */
1432 err = chip->info->ops->irl_init_all(chip, port);
1433 if (err)
1434 return err;
1435 }
1436
1437 return 0;
1438}
1439
Vivien Didelot04a69a12017-10-13 14:18:05 -04001440static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1441{
1442 if (chip->info->ops->set_switch_mac) {
1443 u8 addr[ETH_ALEN];
1444
1445 eth_random_addr(addr);
1446
1447 return chip->info->ops->set_switch_mac(chip, addr);
1448 }
1449
1450 return 0;
1451}
1452
Vivien Didelot17a15942017-03-30 17:37:09 -04001453static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1454{
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001455 struct dsa_switch_tree *dst = chip->ds->dst;
1456 struct dsa_switch *ds;
1457 struct dsa_port *dp;
Vivien Didelot17a15942017-03-30 17:37:09 -04001458 u16 pvlan = 0;
1459
1460 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001461 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001462
1463 /* Skip the local source device, which uses in-chip port VLAN */
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001464 if (dev != chip->ds->index) {
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001465 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001466
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001467 ds = dsa_switch_find(dst->index, dev);
1468 dp = ds ? dsa_to_port(ds, port) : NULL;
1469 if (dp && dp->lag_dev) {
1470 /* As the PVT is used to limit flooding of
1471 * FORWARD frames, which use the LAG ID as the
1472 * source port, we must translate dev/port to
1473 * the special "LAG device" in the PVT, using
1474 * the LAG ID as the port number.
1475 */
Tobias Waldekranz78e70db2021-04-21 14:04:52 +02001476 dev = MV88E6XXX_G2_PVT_ADDR_DEV_TRUNK;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001477 port = dsa_lag_id(dst, dp->lag_dev);
1478 }
1479 }
1480
Vivien Didelot17a15942017-03-30 17:37:09 -04001481 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1482}
1483
Vivien Didelot81228992017-03-30 17:37:08 -04001484static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1485{
Vivien Didelot17a15942017-03-30 17:37:09 -04001486 int dev, port;
1487 int err;
1488
Vivien Didelot81228992017-03-30 17:37:08 -04001489 if (!mv88e6xxx_has_pvt(chip))
1490 return 0;
1491
1492 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1493 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1494 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001495 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1496 if (err)
1497 return err;
1498
1499 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1500 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1501 err = mv88e6xxx_pvt_map(chip, dev, port);
1502 if (err)
1503 return err;
1504 }
1505 }
1506
1507 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001508}
1509
Vivien Didelot749efcb2016-09-22 16:49:24 -04001510static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1511{
1512 struct mv88e6xxx_chip *chip = ds->priv;
1513 int err;
1514
Tobias Waldekranzffcec3f2021-03-18 20:25:34 +01001515 if (dsa_to_port(ds, port)->lag_dev)
1516 /* Hardware is incapable of fast-aging a LAG through a
1517 * regular ATU move operation. Until we have something
1518 * more fancy in place this is a no-op.
1519 */
1520 return;
1521
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001522 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001523 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001524 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001525
1526 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001527 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001528}
1529
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001530static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1531{
Tobias Waldekranze545f862020-11-10 19:57:20 +01001532 if (!mv88e6xxx_max_vid(chip))
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001533 return 0;
1534
1535 return mv88e6xxx_g1_vtu_flush(chip);
1536}
1537
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001538static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1539 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotf1394b782017-05-01 14:05:22 -04001540{
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001541 int err;
1542
Vivien Didelotf1394b782017-05-01 14:05:22 -04001543 if (!chip->info->ops->vtu_getnext)
1544 return -EOPNOTSUPP;
1545
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001546 entry->vid = vid ? vid - 1 : mv88e6xxx_max_vid(chip);
1547 entry->valid = false;
1548
1549 err = chip->info->ops->vtu_getnext(chip, entry);
1550
1551 if (entry->vid != vid)
1552 entry->valid = false;
1553
1554 return err;
Vivien Didelotf1394b782017-05-01 14:05:22 -04001555}
1556
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001557static int mv88e6xxx_vtu_walk(struct mv88e6xxx_chip *chip,
1558 int (*cb)(struct mv88e6xxx_chip *chip,
1559 const struct mv88e6xxx_vtu_entry *entry,
1560 void *priv),
1561 void *priv)
1562{
1563 struct mv88e6xxx_vtu_entry entry = {
1564 .vid = mv88e6xxx_max_vid(chip),
1565 .valid = false,
1566 };
1567 int err;
1568
1569 if (!chip->info->ops->vtu_getnext)
1570 return -EOPNOTSUPP;
1571
1572 do {
1573 err = chip->info->ops->vtu_getnext(chip, &entry);
1574 if (err)
1575 return err;
1576
1577 if (!entry.valid)
1578 break;
1579
1580 err = cb(chip, &entry, priv);
1581 if (err)
1582 return err;
1583 } while (entry.vid < mv88e6xxx_max_vid(chip));
1584
1585 return 0;
1586}
1587
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001588static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1589 struct mv88e6xxx_vtu_entry *entry)
1590{
1591 if (!chip->info->ops->vtu_loadpurge)
1592 return -EOPNOTSUPP;
1593
1594 return chip->info->ops->vtu_loadpurge(chip, entry);
1595}
1596
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001597static int mv88e6xxx_fid_map_vlan(struct mv88e6xxx_chip *chip,
1598 const struct mv88e6xxx_vtu_entry *entry,
1599 void *_fid_bitmap)
1600{
1601 unsigned long *fid_bitmap = _fid_bitmap;
1602
1603 set_bit(entry->fid, fid_bitmap);
1604 return 0;
1605}
1606
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001607int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001608{
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001609 int i, err;
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001610 u16 fid;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001611
1612 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1613
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001614 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001615 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001616 err = mv88e6xxx_port_get_fid(chip, i, &fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001617 if (err)
1618 return err;
1619
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001620 set_bit(fid, fid_bitmap);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001621 }
1622
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001623 /* Set every FID bit used by the VLAN entries */
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001624 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_fid_map_vlan, fid_bitmap);
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001625}
1626
1627static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1628{
1629 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1630 int err;
1631
1632 err = mv88e6xxx_fid_map(chip, fid_bitmap);
1633 if (err)
1634 return err;
1635
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001636 /* The reset value 0x000 is used to indicate that multiple address
1637 * databases are not needed. Return the next positive available.
1638 */
1639 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001640 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001641 return -ENOSPC;
1642
1643 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001644 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001645}
1646
Vivien Didelotda9c3592016-02-12 12:09:40 -05001647static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001648 u16 vid)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001649{
Vivien Didelot04bed142016-08-31 18:06:13 -04001650 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001651 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001652 int i, err;
1653
Andrew Lunndb06ae412017-09-25 23:32:20 +02001654 /* DSA and CPU ports have to be members of multiple vlans */
1655 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1656 return 0;
1657
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001658 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001659 if (err)
1660 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001661
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001662 if (!vlan.valid)
1663 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001664
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001665 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1666 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1667 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001668
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001669 if (!dsa_to_port(ds, i)->slave)
1670 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001671
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001672 if (vlan.member[i] ==
1673 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1674 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001675
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001676 if (dsa_to_port(ds, i)->bridge_dev ==
1677 dsa_to_port(ds, port)->bridge_dev)
1678 break; /* same bridge, check next VLAN */
Vivien Didelotda9c3592016-02-12 12:09:40 -05001679
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001680 if (!dsa_to_port(ds, i)->bridge_dev)
1681 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001682
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001683 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1684 port, vlan.vid, i,
1685 netdev_name(dsa_to_port(ds, i)->bridge_dev));
1686 return -EOPNOTSUPP;
1687 }
Vivien Didelotda9c3592016-02-12 12:09:40 -05001688
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001689 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001690}
1691
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001692static int mv88e6xxx_port_commit_pvid(struct mv88e6xxx_chip *chip, int port)
1693{
1694 struct dsa_port *dp = dsa_to_port(chip->ds, port);
1695 struct mv88e6xxx_port *p = &chip->ports[port];
Vladimir Oltean5bded822021-10-07 19:47:11 +03001696 u16 pvid = MV88E6XXX_VID_STANDALONE;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001697 bool drop_untagged = false;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001698 int err;
1699
Vladimir Oltean5bded822021-10-07 19:47:11 +03001700 if (dp->bridge_dev) {
1701 if (br_vlan_enabled(dp->bridge_dev)) {
1702 pvid = p->bridge_pvid.vid;
1703 drop_untagged = !p->bridge_pvid.valid;
1704 } else {
1705 pvid = MV88E6XXX_VID_BRIDGED;
1706 }
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001707 }
1708
1709 err = mv88e6xxx_port_set_pvid(chip, port, pvid);
1710 if (err)
1711 return err;
1712
1713 return mv88e6xxx_port_drop_untagged(chip, port, drop_untagged);
1714}
1715
Vivien Didelotf81ec902016-05-09 13:22:58 -04001716static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
Vladimir Oltean89153ed2021-02-13 22:43:19 +02001717 bool vlan_filtering,
1718 struct netlink_ext_ack *extack)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001719{
Vivien Didelot04bed142016-08-31 18:06:13 -04001720 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001721 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1722 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001723 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001724
Vladimir Olteanbae33f22021-01-09 02:01:50 +02001725 if (!mv88e6xxx_max_vid(chip))
1726 return -EOPNOTSUPP;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001727
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001728 mv88e6xxx_reg_lock(chip);
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001729
Vivien Didelot385a0992016-11-04 03:23:31 +01001730 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001731 if (err)
1732 goto unlock;
1733
1734 err = mv88e6xxx_port_commit_pvid(chip, port);
1735 if (err)
1736 goto unlock;
1737
1738unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001739 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001740
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001741 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001742}
1743
Vivien Didelot57d32312016-06-20 13:13:58 -04001744static int
1745mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001746 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001747{
Vivien Didelot04bed142016-08-31 18:06:13 -04001748 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001749 int err;
1750
Tobias Waldekranze545f862020-11-10 19:57:20 +01001751 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001752 return -EOPNOTSUPP;
1753
Vivien Didelotda9c3592016-02-12 12:09:40 -05001754 /* If the requested port doesn't belong to the same bridge as the VLAN
1755 * members, do not support it (yet) and fallback to software VLAN.
1756 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001757 mv88e6xxx_reg_lock(chip);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001758 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001759 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001760
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001761 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001762}
1763
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001764static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1765 const unsigned char *addr, u16 vid,
1766 u8 state)
1767{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001768 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001769 struct mv88e6xxx_vtu_entry vlan;
1770 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001771 int err;
1772
Vladimir Oltean5bded822021-10-07 19:47:11 +03001773 /* Ports have two private address databases: one for when the port is
1774 * standalone and one for when the port is under a bridge and the
1775 * 802.1Q mode is disabled. When the port is standalone, DSA wants its
1776 * address database to remain 100% empty, so we never load an ATU entry
1777 * into a standalone port's database. Therefore, translate the null
1778 * VLAN ID into the port's database used for VLAN-unaware bridging.
1779 */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001780 if (vid == 0) {
Vladimir Oltean5bded822021-10-07 19:47:11 +03001781 fid = MV88E6XXX_FID_BRIDGED;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001782 } else {
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001783 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001784 if (err)
1785 return err;
1786
1787 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001788 if (!vlan.valid)
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001789 return -EOPNOTSUPP;
1790
1791 fid = vlan.fid;
1792 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001793
Vivien Didelotd8291a92019-09-07 16:00:47 -04001794 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001795 ether_addr_copy(entry.mac, addr);
1796 eth_addr_dec(entry.mac);
1797
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001798 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001799 if (err)
1800 return err;
1801
1802 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001803 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001804 memset(&entry, 0, sizeof(entry));
1805 ether_addr_copy(entry.mac, addr);
1806 }
1807
1808 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001809 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001810 entry.portvec &= ~BIT(port);
1811 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001812 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001813 } else {
DENG Qingfangf72f2fb2021-01-30 21:43:34 +08001814 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
1815 entry.portvec = BIT(port);
1816 else
1817 entry.portvec |= BIT(port);
1818
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001819 entry.state = state;
1820 }
1821
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001822 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001823}
1824
Vivien Didelotda7dc872019-09-07 16:00:49 -04001825static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1826 const struct mv88e6xxx_policy *policy)
1827{
1828 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1829 enum mv88e6xxx_policy_action action = policy->action;
1830 const u8 *addr = policy->addr;
1831 u16 vid = policy->vid;
1832 u8 state;
1833 int err;
1834 int id;
1835
1836 if (!chip->info->ops->port_set_policy)
1837 return -EOPNOTSUPP;
1838
1839 switch (mapping) {
1840 case MV88E6XXX_POLICY_MAPPING_DA:
1841 case MV88E6XXX_POLICY_MAPPING_SA:
1842 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1843 state = 0; /* Dissociate the port and address */
1844 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1845 is_multicast_ether_addr(addr))
1846 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1847 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1848 is_unicast_ether_addr(addr))
1849 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1850 else
1851 return -EOPNOTSUPP;
1852
1853 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1854 state);
1855 if (err)
1856 return err;
1857 break;
1858 default:
1859 return -EOPNOTSUPP;
1860 }
1861
1862 /* Skip the port's policy clearing if the mapping is still in use */
1863 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1864 idr_for_each_entry(&chip->policies, policy, id)
1865 if (policy->port == port &&
1866 policy->mapping == mapping &&
1867 policy->action != action)
1868 return 0;
1869
1870 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1871}
1872
1873static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1874 struct ethtool_rx_flow_spec *fs)
1875{
1876 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1877 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1878 enum mv88e6xxx_policy_mapping mapping;
1879 enum mv88e6xxx_policy_action action;
1880 struct mv88e6xxx_policy *policy;
1881 u16 vid = 0;
1882 u8 *addr;
1883 int err;
1884 int id;
1885
1886 if (fs->location != RX_CLS_LOC_ANY)
1887 return -EINVAL;
1888
1889 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1890 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1891 else
1892 return -EOPNOTSUPP;
1893
1894 switch (fs->flow_type & ~FLOW_EXT) {
1895 case ETHER_FLOW:
1896 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1897 is_zero_ether_addr(mac_mask->h_source)) {
1898 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1899 addr = mac_entry->h_dest;
1900 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1901 !is_zero_ether_addr(mac_mask->h_source)) {
1902 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1903 addr = mac_entry->h_source;
1904 } else {
1905 /* Cannot support DA and SA mapping in the same rule */
1906 return -EOPNOTSUPP;
1907 }
1908 break;
1909 default:
1910 return -EOPNOTSUPP;
1911 }
1912
1913 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001914 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001915 return -EOPNOTSUPP;
1916 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1917 }
1918
1919 idr_for_each_entry(&chip->policies, policy, id) {
1920 if (policy->port == port && policy->mapping == mapping &&
1921 policy->action == action && policy->vid == vid &&
1922 ether_addr_equal(policy->addr, addr))
1923 return -EEXIST;
1924 }
1925
1926 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1927 if (!policy)
1928 return -ENOMEM;
1929
1930 fs->location = 0;
1931 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1932 GFP_KERNEL);
1933 if (err) {
1934 devm_kfree(chip->dev, policy);
1935 return err;
1936 }
1937
1938 memcpy(&policy->fs, fs, sizeof(*fs));
1939 ether_addr_copy(policy->addr, addr);
1940 policy->mapping = mapping;
1941 policy->action = action;
1942 policy->port = port;
1943 policy->vid = vid;
1944
1945 err = mv88e6xxx_policy_apply(chip, port, policy);
1946 if (err) {
1947 idr_remove(&chip->policies, fs->location);
1948 devm_kfree(chip->dev, policy);
1949 return err;
1950 }
1951
1952 return 0;
1953}
1954
1955static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1956 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1957{
1958 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1959 struct mv88e6xxx_chip *chip = ds->priv;
1960 struct mv88e6xxx_policy *policy;
1961 int err;
1962 int id;
1963
1964 mv88e6xxx_reg_lock(chip);
1965
1966 switch (rxnfc->cmd) {
1967 case ETHTOOL_GRXCLSRLCNT:
1968 rxnfc->data = 0;
1969 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1970 rxnfc->rule_cnt = 0;
1971 idr_for_each_entry(&chip->policies, policy, id)
1972 if (policy->port == port)
1973 rxnfc->rule_cnt++;
1974 err = 0;
1975 break;
1976 case ETHTOOL_GRXCLSRULE:
1977 err = -ENOENT;
1978 policy = idr_find(&chip->policies, fs->location);
1979 if (policy) {
1980 memcpy(fs, &policy->fs, sizeof(*fs));
1981 err = 0;
1982 }
1983 break;
1984 case ETHTOOL_GRXCLSRLALL:
1985 rxnfc->data = 0;
1986 rxnfc->rule_cnt = 0;
1987 idr_for_each_entry(&chip->policies, policy, id)
1988 if (policy->port == port)
1989 rule_locs[rxnfc->rule_cnt++] = id;
1990 err = 0;
1991 break;
1992 default:
1993 err = -EOPNOTSUPP;
1994 break;
1995 }
1996
1997 mv88e6xxx_reg_unlock(chip);
1998
1999 return err;
2000}
2001
2002static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
2003 struct ethtool_rxnfc *rxnfc)
2004{
2005 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
2006 struct mv88e6xxx_chip *chip = ds->priv;
2007 struct mv88e6xxx_policy *policy;
2008 int err;
2009
2010 mv88e6xxx_reg_lock(chip);
2011
2012 switch (rxnfc->cmd) {
2013 case ETHTOOL_SRXCLSRLINS:
2014 err = mv88e6xxx_policy_insert(chip, port, fs);
2015 break;
2016 case ETHTOOL_SRXCLSRLDEL:
2017 err = -ENOENT;
2018 policy = idr_remove(&chip->policies, fs->location);
2019 if (policy) {
2020 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
2021 err = mv88e6xxx_policy_apply(chip, port, policy);
2022 devm_kfree(chip->dev, policy);
2023 }
2024 break;
2025 default:
2026 err = -EOPNOTSUPP;
2027 break;
2028 }
2029
2030 mv88e6xxx_reg_unlock(chip);
2031
2032 return err;
2033}
2034
Andrew Lunn87fa8862017-11-09 22:29:56 +01002035static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
2036 u16 vid)
2037{
Andrew Lunn87fa8862017-11-09 22:29:56 +01002038 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
Tobias Waldekranz0806dd462021-03-18 20:25:37 +01002039 u8 broadcast[ETH_ALEN];
2040
2041 eth_broadcast_addr(broadcast);
Andrew Lunn87fa8862017-11-09 22:29:56 +01002042
2043 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
2044}
2045
2046static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
2047{
2048 int port;
2049 int err;
2050
2051 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01002052 struct dsa_port *dp = dsa_to_port(chip->ds, port);
2053 struct net_device *brport;
2054
2055 if (dsa_is_unused_port(chip->ds, port))
2056 continue;
2057
2058 brport = dsa_port_to_bridge_port(dp);
2059 if (brport && !br_port_flag_is_set(brport, BR_BCAST_FLOOD))
2060 /* Skip bridged user ports where broadcast
2061 * flooding is disabled.
2062 */
2063 continue;
2064
Andrew Lunn87fa8862017-11-09 22:29:56 +01002065 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
2066 if (err)
2067 return err;
2068 }
2069
2070 return 0;
2071}
2072
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01002073struct mv88e6xxx_port_broadcast_sync_ctx {
2074 int port;
2075 bool flood;
2076};
2077
2078static int
2079mv88e6xxx_port_broadcast_sync_vlan(struct mv88e6xxx_chip *chip,
2080 const struct mv88e6xxx_vtu_entry *vlan,
2081 void *_ctx)
2082{
2083 struct mv88e6xxx_port_broadcast_sync_ctx *ctx = _ctx;
2084 u8 broadcast[ETH_ALEN];
2085 u8 state;
2086
2087 if (ctx->flood)
2088 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
2089 else
2090 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_UNUSED;
2091
2092 eth_broadcast_addr(broadcast);
2093
2094 return mv88e6xxx_port_db_load_purge(chip, ctx->port, broadcast,
2095 vlan->vid, state);
2096}
2097
2098static int mv88e6xxx_port_broadcast_sync(struct mv88e6xxx_chip *chip, int port,
2099 bool flood)
2100{
2101 struct mv88e6xxx_port_broadcast_sync_ctx ctx = {
2102 .port = port,
2103 .flood = flood,
2104 };
2105 struct mv88e6xxx_vtu_entry vid0 = {
2106 .vid = 0,
2107 };
2108 int err;
2109
2110 /* Update the port's private database... */
2111 err = mv88e6xxx_port_broadcast_sync_vlan(chip, &vid0, &ctx);
2112 if (err)
2113 return err;
2114
2115 /* ...and the database for all VLANs. */
2116 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_broadcast_sync_vlan,
2117 &ctx);
2118}
2119
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002120static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00002121 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002122{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002123 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002124 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002125 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002126
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002127 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002128 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002129 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002130
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002131 if (!vlan.valid) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002132 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002133
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002134 err = mv88e6xxx_atu_new(chip, &vlan.fid);
2135 if (err)
2136 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01002137
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002138 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
2139 if (i == port)
2140 vlan.member[i] = member;
2141 else
2142 vlan.member[i] = non_member;
2143
2144 vlan.vid = vid;
2145 vlan.valid = true;
2146
2147 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2148 if (err)
2149 return err;
2150
2151 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
2152 if (err)
2153 return err;
2154 } else if (vlan.member[port] != member) {
2155 vlan.member[port] = member;
2156
2157 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2158 if (err)
2159 return err;
Russell King933b4422020-02-26 17:14:26 +00002160 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002161 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
2162 port, vid);
2163 }
2164
2165 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002166}
2167
Vladimir Oltean1958d582021-01-09 02:01:53 +02002168static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vladimir Oltean31046a52021-02-13 22:43:18 +02002169 const struct switchdev_obj_port_vlan *vlan,
2170 struct netlink_ext_ack *extack)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002171{
Vivien Didelot04bed142016-08-31 18:06:13 -04002172 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002173 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
2174 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002175 struct mv88e6xxx_port *p = &chip->ports[port];
Russell King933b4422020-02-26 17:14:26 +00002176 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002177 u8 member;
Vladimir Oltean1958d582021-01-09 02:01:53 +02002178 int err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002179
Eldar Gasanovb8b79c42021-06-21 11:54:38 +03002180 if (!vlan->vid)
2181 return 0;
2182
Vladimir Oltean1958d582021-01-09 02:01:53 +02002183 err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
2184 if (err)
2185 return err;
Vivien Didelot54d77b52016-05-09 13:22:47 -04002186
Vivien Didelotc91498e2017-06-07 18:12:13 -04002187 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002188 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002189 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002190 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002191 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002192 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002193
Russell King933b4422020-02-26 17:14:26 +00002194 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
2195 * and then the CPU port. Do not warn for duplicates for the CPU port.
2196 */
2197 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
2198
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002199 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002200
Vladimir Oltean1958d582021-01-09 02:01:53 +02002201 err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
2202 if (err) {
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002203 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2204 vlan->vid, untagged ? 'u' : 't');
Vladimir Oltean1958d582021-01-09 02:01:53 +02002205 goto out;
2206 }
Vivien Didelot76e398a2015-11-01 12:33:55 -05002207
Vladimir Oltean1958d582021-01-09 02:01:53 +02002208 if (pvid) {
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002209 p->bridge_pvid.vid = vlan->vid;
2210 p->bridge_pvid.valid = true;
2211
2212 err = mv88e6xxx_port_commit_pvid(chip, port);
2213 if (err)
Vladimir Oltean1958d582021-01-09 02:01:53 +02002214 goto out;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002215 } else if (vlan->vid && p->bridge_pvid.vid == vlan->vid) {
2216 /* The old pvid was reinstalled as a non-pvid VLAN */
2217 p->bridge_pvid.valid = false;
2218
2219 err = mv88e6xxx_port_commit_pvid(chip, port);
2220 if (err)
2221 goto out;
Vladimir Oltean1958d582021-01-09 02:01:53 +02002222 }
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002223
Vladimir Oltean1958d582021-01-09 02:01:53 +02002224out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002225 mv88e6xxx_reg_unlock(chip);
Vladimir Oltean1958d582021-01-09 02:01:53 +02002226
2227 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002228}
2229
Vivien Didelot521098922019-08-01 14:36:36 -04002230static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2231 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002232{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002233 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002234 int i, err;
2235
Vivien Didelot521098922019-08-01 14:36:36 -04002236 if (!vid)
Vladimir Olteanc92c7412021-07-22 16:05:51 +03002237 return 0;
Vivien Didelot521098922019-08-01 14:36:36 -04002238
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002239 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002240 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002241 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002242
Vivien Didelot521098922019-08-01 14:36:36 -04002243 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2244 * tell switchdev that this VLAN is likely handled in software.
2245 */
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002246 if (!vlan.valid ||
Vivien Didelot521098922019-08-01 14:36:36 -04002247 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002248 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002249
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002250 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002251
2252 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002253 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002254 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002255 if (vlan.member[i] !=
2256 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002257 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002258 break;
2259 }
2260 }
2261
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002262 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002263 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002264 return err;
2265
Vivien Didelote606ca32017-03-11 16:12:55 -05002266 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002267}
2268
Vivien Didelotf81ec902016-05-09 13:22:58 -04002269static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2270 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002271{
Vivien Didelot04bed142016-08-31 18:06:13 -04002272 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002273 struct mv88e6xxx_port *p = &chip->ports[port];
Vivien Didelot76e398a2015-11-01 12:33:55 -05002274 int err = 0;
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002275 u16 pvid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002276
Tobias Waldekranze545f862020-11-10 19:57:20 +01002277 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04002278 return -EOPNOTSUPP;
2279
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002280 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002281
Vivien Didelot77064f32016-11-04 03:23:30 +01002282 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002283 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002284 goto unlock;
2285
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002286 err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
2287 if (err)
2288 goto unlock;
2289
2290 if (vlan->vid == pvid) {
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002291 p->bridge_pvid.valid = false;
2292
2293 err = mv88e6xxx_port_commit_pvid(chip, port);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002294 if (err)
2295 goto unlock;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002296 }
2297
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002298unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002299 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002300
2301 return err;
2302}
2303
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002304static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2305 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002306{
Vivien Didelot04bed142016-08-31 18:06:13 -04002307 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002308 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002309
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002310 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002311 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2312 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002313 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002314
2315 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002316}
2317
Vivien Didelotf81ec902016-05-09 13:22:58 -04002318static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002319 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002320{
Vivien Didelot04bed142016-08-31 18:06:13 -04002321 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002322 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002323
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002324 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002325 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002326 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002327
Vivien Didelot83dabd12016-08-31 11:50:04 -04002328 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002329}
2330
Vivien Didelot83dabd12016-08-31 11:50:04 -04002331static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2332 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002333 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002334{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002335 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002336 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002337 int err;
2338
Vivien Didelotd8291a92019-09-07 16:00:47 -04002339 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002340 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002341
2342 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002343 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002344 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002345 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002346
Vivien Didelotd8291a92019-09-07 16:00:47 -04002347 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002348 break;
2349
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002350 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002351 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002352
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002353 if (!is_unicast_ether_addr(addr.mac))
2354 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002355
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002356 is_static = (addr.state ==
2357 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2358 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002359 if (err)
2360 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002361 } while (!is_broadcast_ether_addr(addr.mac));
2362
2363 return err;
2364}
2365
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002366struct mv88e6xxx_port_db_dump_vlan_ctx {
2367 int port;
2368 dsa_fdb_dump_cb_t *cb;
2369 void *data;
2370};
2371
2372static int mv88e6xxx_port_db_dump_vlan(struct mv88e6xxx_chip *chip,
2373 const struct mv88e6xxx_vtu_entry *entry,
2374 void *_data)
2375{
2376 struct mv88e6xxx_port_db_dump_vlan_ctx *ctx = _data;
2377
2378 return mv88e6xxx_port_db_dump_fid(chip, entry->fid, entry->vid,
2379 ctx->port, ctx->cb, ctx->data);
2380}
2381
Vivien Didelot83dabd12016-08-31 11:50:04 -04002382static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002383 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002384{
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002385 struct mv88e6xxx_port_db_dump_vlan_ctx ctx = {
2386 .port = port,
2387 .cb = cb,
2388 .data = data,
2389 };
Vivien Didelot83dabd12016-08-31 11:50:04 -04002390 u16 fid;
2391 int err;
2392
2393 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002394 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002395 if (err)
2396 return err;
2397
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002398 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002399 if (err)
2400 return err;
2401
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002402 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_db_dump_vlan, &ctx);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002403}
2404
Vivien Didelotf81ec902016-05-09 13:22:58 -04002405static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002406 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002407{
Vivien Didelot04bed142016-08-31 18:06:13 -04002408 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002409 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002410
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002411 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002412 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002413 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002414
2415 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002416}
2417
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002418static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2419 struct net_device *br)
2420{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002421 struct dsa_switch *ds = chip->ds;
2422 struct dsa_switch_tree *dst = ds->dst;
2423 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002424 int err;
2425
Vivien Didelotef2025e2019-10-21 16:51:27 -04002426 list_for_each_entry(dp, &dst->ports, list) {
2427 if (dp->bridge_dev == br) {
2428 if (dp->ds == ds) {
2429 /* This is a local bridge group member,
2430 * remap its Port VLAN Map.
2431 */
2432 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2433 if (err)
2434 return err;
2435 } else {
2436 /* This is an external bridge group member,
2437 * remap its cross-chip Port VLAN Table entry.
2438 */
2439 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2440 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002441 if (err)
2442 return err;
2443 }
2444 }
2445 }
2446
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002447 return 0;
2448}
2449
Vivien Didelotf81ec902016-05-09 13:22:58 -04002450static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002451 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002452{
Vivien Didelot04bed142016-08-31 18:06:13 -04002453 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002454 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002455
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002456 mv88e6xxx_reg_lock(chip);
Vladimir Oltean5bded822021-10-07 19:47:11 +03002457
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002458 err = mv88e6xxx_bridge_map(chip, br);
Vladimir Oltean5bded822021-10-07 19:47:11 +03002459 if (err)
2460 goto unlock;
2461
2462 err = mv88e6xxx_port_commit_pvid(chip, port);
2463 if (err)
2464 goto unlock;
2465
2466unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002467 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002468
Vivien Didelot466dfa02016-02-26 13:16:05 -05002469 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002470}
2471
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002472static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2473 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002474{
Vivien Didelot04bed142016-08-31 18:06:13 -04002475 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Oltean5bded822021-10-07 19:47:11 +03002476 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002477
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002478 mv88e6xxx_reg_lock(chip);
Vladimir Oltean5bded822021-10-07 19:47:11 +03002479
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002480 if (mv88e6xxx_bridge_map(chip, br) ||
2481 mv88e6xxx_port_vlan_map(chip, port))
2482 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vladimir Oltean5bded822021-10-07 19:47:11 +03002483
2484 err = mv88e6xxx_port_commit_pvid(chip, port);
2485 if (err)
2486 dev_err(ds->dev,
2487 "port %d failed to restore standalone pvid: %pe\n",
2488 port, ERR_PTR(err));
2489
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002490 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002491}
2492
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002493static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2494 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002495 int port, struct net_device *br)
2496{
2497 struct mv88e6xxx_chip *chip = ds->priv;
2498 int err;
2499
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002500 if (tree_index != ds->dst->index)
2501 return 0;
2502
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002503 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002504 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002505 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002506
2507 return err;
2508}
2509
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002510static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2511 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002512 int port, struct net_device *br)
2513{
2514 struct mv88e6xxx_chip *chip = ds->priv;
2515
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002516 if (tree_index != ds->dst->index)
2517 return;
2518
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002519 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002520 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002521 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002522 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002523}
2524
Vladimir Olteance5df682021-07-22 18:55:41 +03002525/* Treat the software bridge as a virtual single-port switch behind the
2526 * CPU and map in the PVT. First dst->last_switch elements are taken by
2527 * physical switches, so start from beyond that range.
2528 */
2529static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
2530 int bridge_num)
2531{
2532 u8 dev = bridge_num + ds->dst->last_switch + 1;
2533 struct mv88e6xxx_chip *chip = ds->priv;
2534 int err;
2535
2536 mv88e6xxx_reg_lock(chip);
2537 err = mv88e6xxx_pvt_map(chip, dev, 0);
2538 mv88e6xxx_reg_unlock(chip);
2539
2540 return err;
2541}
2542
2543static int mv88e6xxx_bridge_tx_fwd_offload(struct dsa_switch *ds, int port,
2544 struct net_device *br,
2545 int bridge_num)
2546{
2547 return mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
2548}
2549
2550static void mv88e6xxx_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port,
2551 struct net_device *br,
2552 int bridge_num)
2553{
2554 int err;
2555
2556 err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
2557 if (err) {
2558 dev_err(ds->dev, "failed to remap cross-chip Port VLAN: %pe\n",
2559 ERR_PTR(err));
2560 }
2561}
2562
Vivien Didelot17e708b2016-12-05 17:30:27 -05002563static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2564{
2565 if (chip->info->ops->reset)
2566 return chip->info->ops->reset(chip);
2567
2568 return 0;
2569}
2570
Vivien Didelot309eca62016-12-05 17:30:26 -05002571static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2572{
2573 struct gpio_desc *gpiod = chip->reset;
2574
2575 /* If there is a GPIO connected to the reset pin, toggle it */
2576 if (gpiod) {
2577 gpiod_set_value_cansleep(gpiod, 1);
2578 usleep_range(10000, 20000);
2579 gpiod_set_value_cansleep(gpiod, 0);
2580 usleep_range(10000, 20000);
Andrew Lunna3dcb3e2020-11-16 08:43:01 -08002581
2582 mv88e6xxx_g1_wait_eeprom_done(chip);
Vivien Didelot309eca62016-12-05 17:30:26 -05002583 }
2584}
2585
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002586static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2587{
2588 int i, err;
2589
2590 /* Set all ports to the Disabled state */
2591 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002592 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002593 if (err)
2594 return err;
2595 }
2596
2597 /* Wait for transmit queues to drain,
2598 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2599 */
2600 usleep_range(2000, 4000);
2601
2602 return 0;
2603}
2604
Vivien Didelotfad09c72016-06-21 12:28:20 -04002605static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002606{
Vivien Didelota935c052016-09-29 12:21:53 -04002607 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002608
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002609 err = mv88e6xxx_disable_ports(chip);
2610 if (err)
2611 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002612
Vivien Didelot309eca62016-12-05 17:30:26 -05002613 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002614
Vivien Didelot17e708b2016-12-05 17:30:27 -05002615 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002616}
2617
Vivien Didelot43145572017-03-11 16:12:59 -05002618static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002619 enum mv88e6xxx_frame_mode frame,
2620 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002621{
2622 int err;
2623
Vivien Didelot43145572017-03-11 16:12:59 -05002624 if (!chip->info->ops->port_set_frame_mode)
2625 return -EOPNOTSUPP;
2626
2627 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002628 if (err)
2629 return err;
2630
Vivien Didelot43145572017-03-11 16:12:59 -05002631 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2632 if (err)
2633 return err;
2634
2635 if (chip->info->ops->port_set_ether_type)
2636 return chip->info->ops->port_set_ether_type(chip, port, etype);
2637
2638 return 0;
2639}
2640
2641static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2642{
2643 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002644 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002645 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002646}
2647
2648static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2649{
2650 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002651 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002652 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002653}
2654
2655static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2656{
2657 return mv88e6xxx_set_port_mode(chip, port,
2658 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002659 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2660 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002661}
2662
2663static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2664{
2665 if (dsa_is_dsa_port(chip->ds, port))
2666 return mv88e6xxx_set_port_mode_dsa(chip, port);
2667
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002668 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002669 return mv88e6xxx_set_port_mode_normal(chip, port);
2670
2671 /* Setup CPU port mode depending on its supported tag format */
Tobias Waldekranz670bb802021-04-20 20:53:07 +02002672 if (chip->tag_protocol == DSA_TAG_PROTO_DSA)
Vivien Didelot43145572017-03-11 16:12:59 -05002673 return mv88e6xxx_set_port_mode_dsa(chip, port);
2674
Tobias Waldekranz670bb802021-04-20 20:53:07 +02002675 if (chip->tag_protocol == DSA_TAG_PROTO_EDSA)
Vivien Didelot43145572017-03-11 16:12:59 -05002676 return mv88e6xxx_set_port_mode_edsa(chip, port);
2677
2678 return -EINVAL;
2679}
2680
Vivien Didelotea698f42017-03-11 16:12:50 -05002681static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2682{
2683 bool message = dsa_is_dsa_port(chip->ds, port);
2684
2685 return mv88e6xxx_port_set_message_port(chip, port, message);
2686}
2687
Vivien Didelot601aeed2017-03-11 16:13:00 -05002688static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2689{
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002690 int err;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002691
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002692 if (chip->info->ops->port_set_ucast_flood) {
Tobias Waldekranz7b9f16f2021-03-18 20:25:38 +01002693 err = chip->info->ops->port_set_ucast_flood(chip, port, true);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002694 if (err)
2695 return err;
2696 }
2697 if (chip->info->ops->port_set_mcast_flood) {
Tobias Waldekranz7b9f16f2021-03-18 20:25:38 +01002698 err = chip->info->ops->port_set_mcast_flood(chip, port, true);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002699 if (err)
2700 return err;
2701 }
Vivien Didelot601aeed2017-03-11 16:13:00 -05002702
David S. Miller407308f2019-06-15 13:35:29 -07002703 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002704}
2705
Vivien Didelot45de77f2019-08-31 16:18:36 -04002706static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2707{
2708 struct mv88e6xxx_port *mvp = dev_id;
2709 struct mv88e6xxx_chip *chip = mvp->chip;
2710 irqreturn_t ret = IRQ_NONE;
2711 int port = mvp->port;
Pavana Sharma193c5b22021-03-17 14:46:40 +01002712 int lane;
Vivien Didelot45de77f2019-08-31 16:18:36 -04002713
2714 mv88e6xxx_reg_lock(chip);
2715 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002716 if (lane >= 0)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002717 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2718 mv88e6xxx_reg_unlock(chip);
2719
2720 return ret;
2721}
2722
2723static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002724 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002725{
2726 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2727 unsigned int irq;
2728 int err;
2729
2730 /* Nothing to request if this SERDES port has no IRQ */
2731 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2732 if (!irq)
2733 return 0;
2734
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002735 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2736 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2737
Vivien Didelot45de77f2019-08-31 16:18:36 -04002738 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2739 mv88e6xxx_reg_unlock(chip);
2740 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002741 IRQF_ONESHOT, dev_id->serdes_irq_name,
2742 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002743 mv88e6xxx_reg_lock(chip);
2744 if (err)
2745 return err;
2746
2747 dev_id->serdes_irq = irq;
2748
2749 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2750}
2751
2752static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002753 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002754{
2755 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2756 unsigned int irq = dev_id->serdes_irq;
2757 int err;
2758
2759 /* Nothing to free if no IRQ has been requested */
2760 if (!irq)
2761 return 0;
2762
2763 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2764
2765 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2766 mv88e6xxx_reg_unlock(chip);
2767 free_irq(irq, dev_id);
2768 mv88e6xxx_reg_lock(chip);
2769
2770 dev_id->serdes_irq = 0;
2771
2772 return err;
2773}
2774
Andrew Lunn6d917822017-05-26 01:03:21 +02002775static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2776 bool on)
2777{
Pavana Sharma193c5b22021-03-17 14:46:40 +01002778 int lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002779 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002780
Vivien Didelotdc272f62019-08-31 16:18:33 -04002781 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002782 if (lane < 0)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002783 return 0;
2784
2785 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002786 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002787 if (err)
2788 return err;
2789
Vivien Didelot45de77f2019-08-31 16:18:36 -04002790 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002791 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002792 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2793 if (err)
2794 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002795
Vivien Didelotdc272f62019-08-31 16:18:33 -04002796 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002797 }
2798
2799 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002800}
2801
Marek Behún2fda45f2021-03-17 14:46:41 +01002802static int mv88e6xxx_set_egress_port(struct mv88e6xxx_chip *chip,
2803 enum mv88e6xxx_egress_direction direction,
2804 int port)
2805{
2806 int err;
2807
2808 if (!chip->info->ops->set_egress_port)
2809 return -EOPNOTSUPP;
2810
2811 err = chip->info->ops->set_egress_port(chip, direction, port);
2812 if (err)
2813 return err;
2814
2815 if (direction == MV88E6XXX_EGRESS_DIR_INGRESS)
2816 chip->ingress_dest_port = port;
2817 else
2818 chip->egress_dest_port = port;
2819
2820 return 0;
2821}
2822
Vivien Didelotfa371c82017-12-05 15:34:10 -05002823static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2824{
2825 struct dsa_switch *ds = chip->ds;
2826 int upstream_port;
2827 int err;
2828
Vivien Didelot07073c72017-12-05 15:34:13 -05002829 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002830 if (chip->info->ops->port_set_upstream_port) {
2831 err = chip->info->ops->port_set_upstream_port(chip, port,
2832 upstream_port);
2833 if (err)
2834 return err;
2835 }
2836
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002837 if (port == upstream_port) {
2838 if (chip->info->ops->set_cpu_port) {
2839 err = chip->info->ops->set_cpu_port(chip,
2840 upstream_port);
2841 if (err)
2842 return err;
2843 }
2844
Marek Behún2fda45f2021-03-17 14:46:41 +01002845 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002846 MV88E6XXX_EGRESS_DIR_INGRESS,
2847 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002848 if (err && err != -EOPNOTSUPP)
2849 return err;
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002850
Marek Behún2fda45f2021-03-17 14:46:41 +01002851 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002852 MV88E6XXX_EGRESS_DIR_EGRESS,
2853 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002854 if (err && err != -EOPNOTSUPP)
2855 return err;
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002856 }
2857
Vivien Didelotfa371c82017-12-05 15:34:10 -05002858 return 0;
2859}
2860
Vivien Didelotfad09c72016-06-21 12:28:20 -04002861static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002862{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002863 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002864 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002865 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002866
Andrew Lunn7b898462018-08-09 15:38:47 +02002867 chip->ports[port].chip = chip;
2868 chip->ports[port].port = port;
2869
Vivien Didelotd78343d2016-11-04 03:23:36 +01002870 /* MAC Forcing register: don't force link, speed, duplex or flow control
2871 * state to any particular values on physical ports, but force the CPU
2872 * port and all DSA ports to their maximum bandwidth and full duplex.
2873 */
2874 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2875 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2876 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002877 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002878 PHY_INTERFACE_MODE_NA);
2879 else
2880 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2881 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002882 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002883 PHY_INTERFACE_MODE_NA);
2884 if (err)
2885 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002886
2887 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2888 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2889 * tunneling, determine priority by looking at 802.1p and IP
2890 * priority fields (IP prio has precedence), and set STP state
2891 * to Forwarding.
2892 *
2893 * If this is the CPU link, use DSA or EDSA tagging depending
2894 * on which tagging mode was configured.
2895 *
2896 * If this is a link to another switch, use DSA tagging mode.
2897 *
2898 * If this is the upstream port for this switch, enable
2899 * forwarding of unknown unicasts and multicasts.
2900 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002901 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2902 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2903 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2904 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002905 if (err)
2906 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002907
Vivien Didelot601aeed2017-03-11 16:13:00 -05002908 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002909 if (err)
2910 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002911
Vivien Didelot601aeed2017-03-11 16:13:00 -05002912 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002913 if (err)
2914 return err;
2915
Andrew Lunnb92ce2f2021-09-26 19:41:25 +02002916 /* Port Control 2: don't force a good FCS, set the MTU size to
2917 * 10222 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002918 * untagged frames on this port, do a destination address lookup on all
2919 * received packets as usual, disable ARP mirroring and don't send a
2920 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002921 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002922 err = mv88e6xxx_port_set_map_da(chip, port);
2923 if (err)
2924 return err;
2925
Vivien Didelotfa371c82017-12-05 15:34:10 -05002926 err = mv88e6xxx_setup_upstream_port(chip, port);
2927 if (err)
2928 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002929
Andrew Lunna23b2962017-02-04 20:15:28 +01002930 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002931 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002932 if (err)
2933 return err;
2934
Vladimir Oltean5bded822021-10-07 19:47:11 +03002935 /* Associate MV88E6XXX_VID_BRIDGED with MV88E6XXX_FID_BRIDGED in the
2936 * ATU by virtue of the fact that mv88e6xxx_atu_new() will pick it as
2937 * the first free FID after MV88E6XXX_FID_STANDALONE. This will be used
2938 * as the private PVID on ports under a VLAN-unaware bridge.
2939 * Shared (DSA and CPU) ports must also be members of it, to translate
2940 * the VID from the DSA tag into MV88E6XXX_FID_BRIDGED, instead of
2941 * relying on their port default FID.
2942 */
2943 err = mv88e6xxx_port_vlan_join(chip, port, MV88E6XXX_VID_BRIDGED,
2944 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED,
2945 false);
2946 if (err)
2947 return err;
2948
Vivien Didelotcd782652017-06-08 18:34:13 -04002949 if (chip->info->ops->port_set_jumbo_size) {
Andrew Lunnb92ce2f2021-09-26 19:41:25 +02002950 err = chip->info->ops->port_set_jumbo_size(chip, port, 10218);
Andrew Lunn5f436662016-12-03 04:45:17 +01002951 if (err)
2952 return err;
2953 }
2954
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002955 /* Port Association Vector: disable automatic address learning
2956 * on all user ports since they start out in standalone
2957 * mode. When joining a bridge, learning will be configured to
2958 * match the bridge port settings. Enable learning on all
2959 * DSA/CPU ports. NOTE: FROM_CPU frames always bypass the
2960 * learning process.
2961 *
2962 * Disable HoldAt1, IntOnAgeOut, LockedPort, IgnoreWrongData,
2963 * and RefreshLocked. I.e. setup standard automatic learning.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002964 */
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002965 if (dsa_is_user_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002966 reg = 0;
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002967 else
2968 reg = 1 << port;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002969
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002970 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2971 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002972 if (err)
2973 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002974
2975 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002976 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2977 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002978 if (err)
2979 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002980
Vivien Didelot08984322017-06-08 18:34:12 -04002981 if (chip->info->ops->port_pause_limit) {
2982 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002983 if (err)
2984 return err;
2985 }
2986
Vivien Didelotc8c94892017-03-11 16:13:01 -05002987 if (chip->info->ops->port_disable_learn_limit) {
2988 err = chip->info->ops->port_disable_learn_limit(chip, port);
2989 if (err)
2990 return err;
2991 }
2992
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002993 if (chip->info->ops->port_disable_pri_override) {
2994 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002995 if (err)
2996 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002997 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002998
Andrew Lunnef0a7312016-12-03 04:35:16 +01002999 if (chip->info->ops->port_tag_remap) {
3000 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02003001 if (err)
3002 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003003 }
3004
Andrew Lunnef70b112016-12-03 04:45:18 +01003005 if (chip->info->ops->port_egress_rate_limiting) {
3006 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02003007 if (err)
3008 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003009 }
3010
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003011 if (chip->info->ops->port_setup_message_port) {
3012 err = chip->info->ops->port_setup_message_port(chip, port);
3013 if (err)
3014 return err;
3015 }
Guenter Roeckd827e882015-03-26 18:36:29 -07003016
Vivien Didelot207afda2016-04-14 14:42:09 -04003017 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05003018 * database, and allow bidirectional communication between the
3019 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07003020 */
Vladimir Oltean5bded822021-10-07 19:47:11 +03003021 err = mv88e6xxx_port_set_fid(chip, port, MV88E6XXX_FID_STANDALONE);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02003022 if (err)
3023 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05003024
Vivien Didelot240ea3e2017-03-30 17:37:12 -04003025 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02003026 if (err)
3027 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07003028
3029 /* Default VLAN ID and priority: don't set a default VLAN
3030 * ID, and set the default packet priority to zero.
3031 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04003032 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02003033}
3034
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003035static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
3036{
3037 struct mv88e6xxx_chip *chip = ds->priv;
3038
3039 if (chip->info->ops->port_set_jumbo_size)
Andrew Lunnb9c587f2021-09-26 19:41:26 +02003040 return 10240 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
Chris Packham1baf0fa2020-07-24 11:21:22 +12003041 else if (chip->info->ops->set_max_frame_size)
Andrew Lunnb9c587f2021-09-26 19:41:26 +02003042 return 1632 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
3043 return 1522 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003044}
3045
3046static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
3047{
3048 struct mv88e6xxx_chip *chip = ds->priv;
3049 int ret = 0;
3050
Andrew Lunnb9c587f2021-09-26 19:41:26 +02003051 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
3052 new_mtu += EDSA_HLEN;
3053
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003054 mv88e6xxx_reg_lock(chip);
3055 if (chip->info->ops->port_set_jumbo_size)
3056 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12003057 else if (chip->info->ops->set_max_frame_size)
3058 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003059 else
3060 if (new_mtu > 1522)
3061 ret = -EINVAL;
3062 mv88e6xxx_reg_unlock(chip);
3063
3064 return ret;
3065}
3066
Andrew Lunn04aca992017-05-26 01:03:24 +02003067static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
3068 struct phy_device *phydev)
3069{
3070 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04003071 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02003072
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003073 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04003074 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003075 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02003076
3077 return err;
3078}
3079
Andrew Lunn75104db2019-02-24 20:44:43 +01003080static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02003081{
3082 struct mv88e6xxx_chip *chip = ds->priv;
3083
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003084 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04003085 if (mv88e6xxx_serdes_power(chip, port, false))
3086 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003087 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02003088}
3089
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003090static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
3091 unsigned int ageing_time)
3092{
Vivien Didelot04bed142016-08-31 18:06:13 -04003093 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003094 int err;
3095
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003096 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05003097 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003098 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003099
3100 return err;
3101}
3102
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003103static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04003104{
3105 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04003106
Andrew Lunnde2273872016-11-21 23:27:01 +01003107 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003108 if (chip->info->ops->stats_set_histogram) {
3109 err = chip->info->ops->stats_set_histogram(chip);
3110 if (err)
3111 return err;
3112 }
Andrew Lunnde2273872016-11-21 23:27:01 +01003113
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003114 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04003115}
3116
Andrew Lunnea890982019-01-09 00:24:03 +01003117/* Check if the errata has already been applied. */
3118static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
3119{
3120 int port;
3121 int err;
3122 u16 val;
3123
3124 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02003125 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01003126 if (err) {
3127 dev_err(chip->dev,
3128 "Error reading hidden register: %d\n", err);
3129 return false;
3130 }
3131 if (val != 0x01c0)
3132 return false;
3133 }
3134
3135 return true;
3136}
3137
3138/* The 6390 copper ports have an errata which require poking magic
3139 * values into undocumented hidden registers and then performing a
3140 * software reset.
3141 */
3142static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
3143{
3144 int port;
3145 int err;
3146
3147 if (mv88e6390_setup_errata_applied(chip))
3148 return 0;
3149
3150 /* Set the ports into blocking mode */
3151 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
3152 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
3153 if (err)
3154 return err;
3155 }
3156
3157 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02003158 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01003159 if (err)
3160 return err;
3161 }
3162
3163 return mv88e6xxx_software_reset(chip);
3164}
3165
Andrew Lunn23e8b472019-10-25 01:03:52 +02003166static void mv88e6xxx_teardown(struct dsa_switch *ds)
3167{
3168 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003169 dsa_devlink_resources_unregister(ds);
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003170 mv88e6xxx_teardown_devlink_regions_global(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02003171}
3172
Vivien Didelotf81ec902016-05-09 13:22:58 -04003173static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07003174{
Vivien Didelot04bed142016-08-31 18:06:13 -04003175 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003176 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04003177 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04003178 int i;
3179
Vivien Didelotfad09c72016-06-21 12:28:20 -04003180 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003181 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003182
Vladimir Olteance5df682021-07-22 18:55:41 +03003183 /* Since virtual bridges are mapped in the PVT, the number we support
3184 * depends on the physical switch topology. We need to let DSA figure
3185 * that out and therefore we cannot set this at dsa_register_switch()
3186 * time.
3187 */
3188 if (mv88e6xxx_has_pvt(chip))
3189 ds->num_fwd_offloading_bridges = MV88E6XXX_MAX_PVT_SWITCHES -
3190 ds->dst->last_switch - 1;
3191
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003192 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003193
Andrew Lunnea890982019-01-09 00:24:03 +01003194 if (chip->info->ops->setup_errata) {
3195 err = chip->info->ops->setup_errata(chip);
3196 if (err)
3197 goto unlock;
3198 }
3199
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003200 /* Cache the cmode of each port. */
3201 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3202 if (chip->info->ops->port_get_cmode) {
3203 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
3204 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03003205 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003206
3207 chip->ports[i].cmode = cmode;
3208 }
3209 }
3210
Vladimir Oltean5bded822021-10-07 19:47:11 +03003211 err = mv88e6xxx_vtu_setup(chip);
3212 if (err)
3213 goto unlock;
3214
Vivien Didelot97299342016-07-18 20:45:30 -04003215 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04003216 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04003217 if (dsa_is_unused_port(ds, i))
3218 continue;
3219
Hubert Feursteinc8574862019-07-31 10:23:48 +02003220 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04003221 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02003222 dev_err(chip->dev, "port %d is invalid\n", i);
3223 err = -EINVAL;
3224 goto unlock;
3225 }
3226
Vivien Didelot97299342016-07-18 20:45:30 -04003227 err = mv88e6xxx_setup_port(chip, i);
3228 if (err)
3229 goto unlock;
3230 }
3231
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003232 err = mv88e6xxx_irl_setup(chip);
3233 if (err)
3234 goto unlock;
3235
Vivien Didelot04a69a12017-10-13 14:18:05 -04003236 err = mv88e6xxx_mac_setup(chip);
3237 if (err)
3238 goto unlock;
3239
Vivien Didelot1b17aed2017-05-26 18:03:05 -04003240 err = mv88e6xxx_phy_setup(chip);
3241 if (err)
3242 goto unlock;
3243
Vivien Didelot81228992017-03-30 17:37:08 -04003244 err = mv88e6xxx_pvt_setup(chip);
3245 if (err)
3246 goto unlock;
3247
Vivien Didelota2ac29d2017-03-11 16:12:49 -05003248 err = mv88e6xxx_atu_setup(chip);
3249 if (err)
3250 goto unlock;
3251
Andrew Lunn87fa8862017-11-09 22:29:56 +01003252 err = mv88e6xxx_broadcast_setup(chip, 0);
3253 if (err)
3254 goto unlock;
3255
Vivien Didelot9e907d72017-07-17 13:03:43 -04003256 err = mv88e6xxx_pot_setup(chip);
3257 if (err)
3258 goto unlock;
3259
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003260 err = mv88e6xxx_rmu_setup(chip);
3261 if (err)
3262 goto unlock;
3263
Vivien Didelot51c901a2017-07-17 13:03:41 -04003264 err = mv88e6xxx_rsvd2cpu_setup(chip);
3265 if (err)
3266 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01003267
Vivien Didelotb28f8722018-04-26 21:56:44 -04003268 err = mv88e6xxx_trunk_setup(chip);
3269 if (err)
3270 goto unlock;
3271
Vivien Didelotc7f047b2018-04-26 21:56:45 -04003272 err = mv88e6xxx_devmap_setup(chip);
3273 if (err)
3274 goto unlock;
3275
Vivien Didelot93e18d62018-05-11 17:16:35 -04003276 err = mv88e6xxx_pri_setup(chip);
3277 if (err)
3278 goto unlock;
3279
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003280 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003281 if (chip->info->ptp_support) {
3282 err = mv88e6xxx_ptp_setup(chip);
3283 if (err)
3284 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003285
3286 err = mv88e6xxx_hwtstamp_setup(chip);
3287 if (err)
3288 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003289 }
3290
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003291 err = mv88e6xxx_stats_setup(chip);
3292 if (err)
3293 goto unlock;
3294
Vivien Didelot6b17e862015-08-13 12:52:18 -04003295unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003296 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02003297
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003298 if (err)
3299 return err;
3300
3301 /* Have to be called without holding the register lock, since
3302 * they take the devlink lock, and we later take the locks in
3303 * the reverse order when getting/setting parameters or
3304 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02003305 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003306 err = mv88e6xxx_setup_devlink_resources(ds);
3307 if (err)
3308 return err;
3309
3310 err = mv88e6xxx_setup_devlink_params(ds);
3311 if (err)
Andrew Lunnbfb25542020-09-18 21:11:07 +02003312 goto out_resources;
3313
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003314 err = mv88e6xxx_setup_devlink_regions_global(ds);
Andrew Lunnbfb25542020-09-18 21:11:07 +02003315 if (err)
3316 goto out_params;
3317
3318 return 0;
3319
3320out_params:
3321 mv88e6xxx_teardown_devlink_params(ds);
3322out_resources:
3323 dsa_devlink_resources_unregister(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003324
3325 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003326}
3327
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003328static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
3329{
3330 return mv88e6xxx_setup_devlink_regions_port(ds, port);
3331}
3332
3333static void mv88e6xxx_port_teardown(struct dsa_switch *ds, int port)
3334{
3335 mv88e6xxx_teardown_devlink_regions_port(ds, port);
3336}
3337
Pali Rohár1fe976d2021-04-12 18:57:39 +02003338/* prod_id for switch families which do not have a PHY model number */
3339static const u16 family_prod_id_table[] = {
3340 [MV88E6XXX_FAMILY_6341] = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3341 [MV88E6XXX_FAMILY_6390] = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Marek Behúnc5d015b2021-04-20 09:54:02 +02003342 [MV88E6XXX_FAMILY_6393] = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
Pali Rohár1fe976d2021-04-12 18:57:39 +02003343};
3344
Vivien Didelote57e5e72016-08-15 17:19:00 -04003345static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003346{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003347 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3348 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Pali Rohár1fe976d2021-04-12 18:57:39 +02003349 u16 prod_id;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003350 u16 val;
3351 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003352
Andrew Lunnee26a222017-01-24 14:53:48 +01003353 if (!chip->info->ops->phy_read)
3354 return -EOPNOTSUPP;
3355
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003356 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003357 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003358 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003359
Pali Rohár1fe976d2021-04-12 18:57:39 +02003360 /* Some internal PHYs don't have a model number. */
3361 if (reg == MII_PHYSID2 && !(val & 0x3f0) &&
3362 chip->info->family < ARRAY_SIZE(family_prod_id_table)) {
3363 prod_id = family_prod_id_table[chip->info->family];
3364 if (prod_id)
3365 val |= prod_id >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003366 }
3367
Vivien Didelote57e5e72016-08-15 17:19:00 -04003368 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003369}
3370
Vivien Didelote57e5e72016-08-15 17:19:00 -04003371static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003372{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003373 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3374 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003375 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003376
Andrew Lunnee26a222017-01-24 14:53:48 +01003377 if (!chip->info->ops->phy_write)
3378 return -EOPNOTSUPP;
3379
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003380 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003381 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003382 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003383
3384 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003385}
3386
Vivien Didelotfad09c72016-06-21 12:28:20 -04003387static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003388 struct device_node *np,
3389 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003390{
3391 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003392 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003393 struct mii_bus *bus;
3394 int err;
3395
Andrew Lunn2510bab2018-02-22 01:51:49 +01003396 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003397 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003398 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003399 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003400
3401 if (err)
3402 return err;
3403 }
3404
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003405 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003406 if (!bus)
3407 return -ENOMEM;
3408
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003409 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003410 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003411 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003412 INIT_LIST_HEAD(&mdio_bus->list);
3413 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003414
Andrew Lunnb516d452016-06-04 21:17:06 +02003415 if (np) {
3416 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003417 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003418 } else {
3419 bus->name = "mv88e6xxx SMI";
3420 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3421 }
3422
3423 bus->read = mv88e6xxx_mdio_read;
3424 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003425 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003426
Andrew Lunn6f882842018-03-17 20:32:05 +01003427 if (!external) {
3428 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3429 if (err)
3430 return err;
3431 }
3432
Florian Fainelli00e798c2018-05-15 16:56:19 -07003433 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003434 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003435 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003436 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003437 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003438 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003439
3440 if (external)
3441 list_add_tail(&mdio_bus->list, &chip->mdios);
3442 else
3443 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003444
3445 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003446}
3447
Andrew Lunn3126aee2017-12-07 01:05:57 +01003448static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3449
3450{
3451 struct mv88e6xxx_mdio_bus *mdio_bus;
3452 struct mii_bus *bus;
3453
3454 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3455 bus = mdio_bus->bus;
3456
Andrew Lunn6f882842018-03-17 20:32:05 +01003457 if (!mdio_bus->external)
3458 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3459
Andrew Lunn3126aee2017-12-07 01:05:57 +01003460 mdiobus_unregister(bus);
3461 }
3462}
3463
Andrew Lunna3c53be52017-01-24 14:53:50 +01003464static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3465 struct device_node *np)
3466{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003467 struct device_node *child;
3468 int err;
3469
3470 /* Always register one mdio bus for the internal/default mdio
3471 * bus. This maybe represented in the device tree, but is
3472 * optional.
3473 */
3474 child = of_get_child_by_name(np, "mdio");
3475 err = mv88e6xxx_mdio_register(chip, child, false);
3476 if (err)
3477 return err;
3478
3479 /* Walk the device tree, and see if there are any other nodes
3480 * which say they are compatible with the external mdio
3481 * bus.
3482 */
3483 for_each_available_child_of_node(np, child) {
Andrew Lunnceb96fa2020-09-01 04:32:57 +02003484 if (of_device_is_compatible(
3485 child, "marvell,mv88e6xxx-mdio-external")) {
Andrew Lunna3c53be52017-01-24 14:53:50 +01003486 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003487 if (err) {
3488 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303489 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003490 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003491 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003492 }
3493 }
3494
3495 return 0;
3496}
3497
Vivien Didelot855b1932016-07-20 18:18:35 -04003498static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3499{
Vivien Didelot04bed142016-08-31 18:06:13 -04003500 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003501
3502 return chip->eeprom_len;
3503}
3504
Vivien Didelot855b1932016-07-20 18:18:35 -04003505static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3506 struct ethtool_eeprom *eeprom, u8 *data)
3507{
Vivien Didelot04bed142016-08-31 18:06:13 -04003508 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003509 int err;
3510
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003511 if (!chip->info->ops->get_eeprom)
3512 return -EOPNOTSUPP;
3513
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003514 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003515 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003516 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003517
3518 if (err)
3519 return err;
3520
3521 eeprom->magic = 0xc3ec4951;
3522
3523 return 0;
3524}
3525
Vivien Didelot855b1932016-07-20 18:18:35 -04003526static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3527 struct ethtool_eeprom *eeprom, u8 *data)
3528{
Vivien Didelot04bed142016-08-31 18:06:13 -04003529 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003530 int err;
3531
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003532 if (!chip->info->ops->set_eeprom)
3533 return -EOPNOTSUPP;
3534
Vivien Didelot855b1932016-07-20 18:18:35 -04003535 if (eeprom->magic != 0xc3ec4951)
3536 return -EINVAL;
3537
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003538 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003539 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003540 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003541
3542 return err;
3543}
3544
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003545static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003546 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003547 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3548 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003549 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003550 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003551 .phy_read = mv88e6185_phy_ppu_read,
3552 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003553 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003554 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003555 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003556 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003557 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003558 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3559 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003560 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003561 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003562 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003563 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003564 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003565 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003566 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003567 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003568 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003569 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3570 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003571 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003572 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3573 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003574 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003575 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003576 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003577 .ppu_enable = mv88e6185_g1_ppu_enable,
3578 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003579 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003580 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003581 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003582 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003583 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003584 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003585};
3586
3587static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003588 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003589 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3590 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003591 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003592 .phy_read = mv88e6185_phy_ppu_read,
3593 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003594 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003595 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003596 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003597 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003598 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3599 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunna23b2962017-02-04 20:15:28 +01003600 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003601 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003602 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003603 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003604 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003605 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3606 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003607 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003608 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003609 .serdes_power = mv88e6185_serdes_power,
3610 .serdes_get_lane = mv88e6185_serdes_get_lane,
3611 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003612 .ppu_enable = mv88e6185_g1_ppu_enable,
3613 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003614 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003615 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003616 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003617 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003618 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003619};
3620
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003621static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003622 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003623 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3624 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003625 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003626 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3627 .phy_read = mv88e6xxx_g2_smi_phy_read,
3628 .phy_write = mv88e6xxx_g2_smi_phy_write,
3629 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003630 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003631 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003632 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003633 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003634 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3635 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003636 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003637 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003638 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003639 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003640 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003641 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003642 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003643 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003644 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003645 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3646 .stats_get_strings = mv88e6095_stats_get_strings,
3647 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003648 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3649 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003650 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003651 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003652 .serdes_power = mv88e6185_serdes_power,
3653 .serdes_get_lane = mv88e6185_serdes_get_lane,
3654 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Chris Packham5c19bc82020-11-24 17:34:39 +13003655 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3656 .serdes_irq_enable = mv88e6097_serdes_irq_enable,
3657 .serdes_irq_status = mv88e6097_serdes_irq_status,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003658 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003659 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003660 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003661 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003662 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003663 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003664 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003665};
3666
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003667static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003668 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003669 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3670 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003671 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003672 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003673 .phy_read = mv88e6xxx_g2_smi_phy_read,
3674 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003675 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003676 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003677 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003678 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003679 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3680 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003681 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003682 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003683 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003684 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003685 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003686 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003687 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3688 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003689 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003690 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3691 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003692 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003693 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003694 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003695 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003696 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3697 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003698 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003699 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003700 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003701 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003702};
3703
3704static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003705 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003706 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3707 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003708 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003709 .phy_read = mv88e6185_phy_ppu_read,
3710 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003711 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003712 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003713 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003714 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003715 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003716 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3717 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003718 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003719 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003720 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003721 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003722 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003723 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003724 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003725 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003726 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003727 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003728 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3729 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003730 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003731 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3732 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003733 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003734 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003735 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003736 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003737 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003738 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003739 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003740 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003741 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003742};
3743
Vivien Didelot990e27b2017-03-28 13:50:32 -04003744static const struct mv88e6xxx_ops mv88e6141_ops = {
3745 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003746 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3747 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003748 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003749 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3750 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3751 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3752 .phy_read = mv88e6xxx_g2_smi_phy_read,
3753 .phy_write = mv88e6xxx_g2_smi_phy_write,
3754 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003755 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003756 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003757 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003758 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003759 .port_tag_remap = mv88e6095_port_tag_remap,
Marek Behún7da467d2021-07-01 00:22:26 +02003760 .port_set_policy = mv88e6352_port_set_policy,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003761 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003762 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3763 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003764 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003765 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003766 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003767 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003768 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3769 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003770 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003771 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003772 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003773 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Marek Behún11527f32021-07-01 00:22:27 +02003774 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003775 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3776 .stats_get_strings = mv88e6320_stats_get_strings,
3777 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003778 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3779 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003780 .watchdog_ops = &mv88e6390_watchdog_ops,
3781 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003782 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003783 .reset = mv88e6352_g1_reset,
Marek Behún37094882021-07-01 00:22:28 +02003784 .rmu_disable = mv88e6390_g1_rmu_disable,
Marek Behúnc07fff32021-07-01 00:22:29 +02003785 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3786 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003787 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003788 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003789 .serdes_power = mv88e6390_serdes_power,
3790 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003791 /* Check status register pause & lpa register */
3792 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3793 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3794 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3795 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003796 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003797 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003798 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003799 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúna03b98d2021-07-01 00:22:30 +02003800 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
3801 .serdes_get_strings = mv88e6390_serdes_get_strings,
3802 .serdes_get_stats = mv88e6390_serdes_get_stats,
Marek Behún953b0dc2021-07-01 00:22:31 +02003803 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3804 .serdes_get_regs = mv88e6390_serdes_get_regs,
Marek Behúne3af71a2019-02-25 12:39:55 +01003805 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003806};
3807
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003808static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003809 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003810 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3811 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003812 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003813 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003814 .phy_read = mv88e6xxx_g2_smi_phy_read,
3815 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003816 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003817 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003818 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003819 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003820 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003821 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3822 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003823 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003824 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003825 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003826 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003827 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003828 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003829 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003830 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003831 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003832 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3833 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003834 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003835 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3836 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003837 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003838 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003839 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003840 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003841 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3842 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003843 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003844 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003845 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003846 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003847 .phylink_validate = mv88e6185_phylink_validate,
Andrew Lunnfe230362021-09-26 19:41:24 +02003848 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003849};
3850
3851static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003852 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003853 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3854 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003855 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003856 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003857 .phy_read = mv88e6165_phy_read,
3858 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003859 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003860 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003861 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003862 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003863 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003864 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003865 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003866 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003867 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003868 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3869 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003870 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003871 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3872 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003873 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003874 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003875 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003876 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003877 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3878 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003879 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003880 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003881 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003882 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003883 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003884};
3885
3886static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003887 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003888 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3889 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003890 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003891 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003892 .phy_read = mv88e6xxx_g2_smi_phy_read,
3893 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003894 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003895 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003896 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003897 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003898 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003899 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003900 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3901 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003902 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003903 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003904 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003905 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003906 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003907 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003908 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003909 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003910 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003911 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003912 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3913 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003914 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003915 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3916 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003917 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003918 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003919 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003920 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003921 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3922 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003923 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003924 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003925 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003926};
3927
3928static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003929 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003930 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3931 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003932 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003933 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3934 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003935 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003936 .phy_read = mv88e6xxx_g2_smi_phy_read,
3937 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003938 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003939 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003940 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003941 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003942 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003943 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003944 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003945 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3946 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003947 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003948 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003949 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003950 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003951 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003952 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003953 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003954 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003955 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003956 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003957 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3958 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003959 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003960 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3961 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003962 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003963 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003964 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003965 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003966 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003967 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3968 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003969 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003970 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003971 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003972 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3973 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3974 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3975 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003976 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003977 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3978 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003979 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003980 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003981};
3982
3983static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003984 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003985 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3986 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003987 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003988 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003989 .phy_read = mv88e6xxx_g2_smi_phy_read,
3990 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003991 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003992 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003993 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003994 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003995 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003996 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003997 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3998 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003999 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004000 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004001 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004002 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004003 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004004 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004005 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004006 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004007 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004008 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004009 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4010 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004011 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004012 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4013 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004014 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004015 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004016 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004017 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004018 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4019 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004020 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004021 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004022 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004023};
4024
4025static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004026 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004027 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4028 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004029 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004030 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4031 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004032 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004033 .phy_read = mv88e6xxx_g2_smi_phy_read,
4034 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004035 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004036 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004037 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004038 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004039 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004040 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004041 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004042 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4043 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004044 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004045 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004046 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004047 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004048 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004049 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004050 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004051 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004052 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004053 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004054 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4055 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004056 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004057 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4058 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004059 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004060 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004061 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004062 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004063 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004064 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4065 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004066 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004067 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004068 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004069 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4070 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4071 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4072 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004073 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004074 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004075 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004076 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004077 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4078 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004079 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004080 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004081};
4082
4083static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004084 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004085 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4086 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004087 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04004088 .phy_read = mv88e6185_phy_ppu_read,
4089 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004090 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004091 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004092 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004093 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004094 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
4095 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunnef70b112016-12-03 04:45:18 +01004096 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01004097 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02004098 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004099 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004100 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004101 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004102 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004103 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4104 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004105 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004106 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4107 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004108 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004109 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13004110 .serdes_power = mv88e6185_serdes_power,
4111 .serdes_get_lane = mv88e6185_serdes_get_lane,
4112 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelot02317e62018-05-09 11:38:49 -04004113 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05004114 .ppu_enable = mv88e6185_g1_ppu_enable,
4115 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004116 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004117 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004118 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004119 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12004120 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004121};
4122
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004123static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004124 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004125 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004126 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004127 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4128 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004129 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4130 .phy_read = mv88e6xxx_g2_smi_phy_read,
4131 .phy_write = mv88e6xxx_g2_smi_phy_write,
4132 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004133 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004134 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004135 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004136 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004137 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004138 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004139 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004140 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4141 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004142 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12004143 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04004144 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004145 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004146 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004147 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004148 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004149 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004150 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004151 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004152 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4153 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004154 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004155 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4156 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004157 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004158 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004159 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004160 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004161 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004162 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4163 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004164 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4165 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004166 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004167 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004168 /* Check status register pause & lpa register */
4169 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4170 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4171 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4172 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004173 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004174 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004175 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004176 .serdes_get_strings = mv88e6390_serdes_get_strings,
4177 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004178 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4179 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004180 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004181 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004182};
4183
4184static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004185 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004186 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004187 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004188 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4189 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004190 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4191 .phy_read = mv88e6xxx_g2_smi_phy_read,
4192 .phy_write = mv88e6xxx_g2_smi_phy_write,
4193 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004194 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004195 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004196 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004197 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004198 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004199 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004200 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004201 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4202 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004203 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12004204 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04004205 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004206 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004207 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004208 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004209 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004210 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004211 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004212 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004213 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4214 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004215 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004216 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4217 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004218 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004219 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004220 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004221 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004222 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004223 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4224 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004225 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4226 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004227 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004228 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004229 /* Check status register pause & lpa register */
4230 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4231 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4232 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4233 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004234 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004235 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004236 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004237 .serdes_get_strings = mv88e6390_serdes_get_strings,
4238 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004239 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4240 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004241 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004242 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004243};
4244
4245static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004246 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004247 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004248 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004249 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4250 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004251 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4252 .phy_read = mv88e6xxx_g2_smi_phy_read,
4253 .phy_write = mv88e6xxx_g2_smi_phy_write,
4254 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004255 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004256 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004257 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004258 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004259 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004260 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004261 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4262 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004263 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004264 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004265 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004266 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004267 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004268 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004269 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004270 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004271 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004272 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4273 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004274 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004275 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4276 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004277 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004278 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004279 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004280 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004281 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004282 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4283 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004284 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4285 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004286 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004287 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004288 /* Check status register pause & lpa register */
4289 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4290 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4291 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4292 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004293 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004294 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004295 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004296 .serdes_get_strings = mv88e6390_serdes_get_strings,
4297 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004298 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4299 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004300 .avb_ops = &mv88e6390_avb_ops,
4301 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004302 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004303};
4304
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004305static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004306 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004307 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4308 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004309 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004310 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4311 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004312 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004313 .phy_read = mv88e6xxx_g2_smi_phy_read,
4314 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004315 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004316 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004317 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004318 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004319 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004320 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004321 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004322 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4323 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004324 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004325 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004326 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004327 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004328 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004329 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004330 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004331 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004332 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004333 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004334 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4335 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004336 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004337 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4338 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004339 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004340 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004341 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004342 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004343 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004344 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4345 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004346 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004347 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004348 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004349 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4350 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4351 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4352 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004353 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004354 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004355 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004356 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004357 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4358 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004359 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004360 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004361 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004362 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004363};
4364
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004365static const struct mv88e6xxx_ops mv88e6250_ops = {
4366 /* MV88E6XXX_FAMILY_6250 */
4367 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4368 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4369 .irl_init_all = mv88e6352_g2_irl_init_all,
4370 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4371 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4372 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4373 .phy_read = mv88e6xxx_g2_smi_phy_read,
4374 .phy_write = mv88e6xxx_g2_smi_phy_write,
4375 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004376 .port_sync_link = mv88e6xxx_port_sync_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004377 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004378 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004379 .port_tag_remap = mv88e6095_port_tag_remap,
4380 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004381 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4382 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004383 .port_set_ether_type = mv88e6351_port_set_ether_type,
4384 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4385 .port_pause_limit = mv88e6097_port_pause_limit,
4386 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004387 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4388 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4389 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4390 .stats_get_strings = mv88e6250_stats_get_strings,
4391 .stats_get_stats = mv88e6250_stats_get_stats,
4392 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4393 .set_egress_port = mv88e6095_g1_set_egress_port,
4394 .watchdog_ops = &mv88e6250_watchdog_ops,
4395 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4396 .pot_clear = mv88e6xxx_g2_pot_clear,
4397 .reset = mv88e6250_g1_reset,
Rasmus Villemoes67c9ed12021-01-25 16:04:48 +01004398 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Rasmus Villemoesb28f3f32021-01-25 16:04:49 +01004399 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004400 .avb_ops = &mv88e6352_avb_ops,
4401 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004402 .phylink_validate = mv88e6065_phylink_validate,
4403};
4404
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004405static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004406 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004407 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004408 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004409 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4410 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004411 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4412 .phy_read = mv88e6xxx_g2_smi_phy_read,
4413 .phy_write = mv88e6xxx_g2_smi_phy_write,
4414 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004415 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004416 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004417 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004418 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004419 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004420 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004421 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004422 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4423 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004424 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004425 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004426 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004427 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004428 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004429 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004430 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004431 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004432 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004433 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4434 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004435 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004436 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4437 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004438 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004439 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004440 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004441 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004442 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004443 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4444 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004445 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4446 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004447 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004448 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004449 /* Check status register pause & lpa register */
4450 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4451 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4452 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4453 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004454 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004455 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004456 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004457 .serdes_get_strings = mv88e6390_serdes_get_strings,
4458 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004459 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4460 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004461 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004462 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004463 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004464 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004465};
4466
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004467static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004468 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004469 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4470 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004471 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004472 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4473 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004474 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004475 .phy_read = mv88e6xxx_g2_smi_phy_read,
4476 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004477 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004478 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004479 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004480 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004481 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004482 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4483 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004484 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004485 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004486 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004487 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004488 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004489 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004490 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004491 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004492 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004493 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004494 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4495 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004496 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004497 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4498 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004499 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004500 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004501 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004502 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004503 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004504 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004505 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004506 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004507 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004508 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004509};
4510
4511static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004512 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004513 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4514 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004515 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004516 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4517 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004518 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004519 .phy_read = mv88e6xxx_g2_smi_phy_read,
4520 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004521 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004522 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004523 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004524 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004525 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004526 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4527 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004528 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004529 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004530 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004531 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004532 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004533 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004534 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004535 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004536 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004537 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004538 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4539 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004540 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004541 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4542 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004543 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004544 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004545 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004546 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004547 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004548 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004549 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004550 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004551};
4552
Vivien Didelot16e329a2017-03-28 13:50:33 -04004553static const struct mv88e6xxx_ops mv88e6341_ops = {
4554 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004555 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4556 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004557 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004558 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4559 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4560 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4561 .phy_read = mv88e6xxx_g2_smi_phy_read,
4562 .phy_write = mv88e6xxx_g2_smi_phy_write,
4563 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004564 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004565 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004566 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004567 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004568 .port_tag_remap = mv88e6095_port_tag_remap,
Marek Behún7da467d2021-07-01 00:22:26 +02004569 .port_set_policy = mv88e6352_port_set_policy,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004570 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004571 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4572 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004573 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004574 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004575 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004576 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004577 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4578 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004579 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004580 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004581 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004582 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Marek Behún11527f32021-07-01 00:22:27 +02004583 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004584 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4585 .stats_get_strings = mv88e6320_stats_get_strings,
4586 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004587 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4588 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004589 .watchdog_ops = &mv88e6390_watchdog_ops,
4590 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004591 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004592 .reset = mv88e6352_g1_reset,
Marek Behún37094882021-07-01 00:22:28 +02004593 .rmu_disable = mv88e6390_g1_rmu_disable,
Marek Behúnc07fff32021-07-01 00:22:29 +02004594 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4595 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004596 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004597 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004598 .serdes_power = mv88e6390_serdes_power,
4599 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004600 /* Check status register pause & lpa register */
4601 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4602 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4603 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4604 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004605 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004606 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004607 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004608 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004609 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004610 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúna03b98d2021-07-01 00:22:30 +02004611 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4612 .serdes_get_strings = mv88e6390_serdes_get_strings,
4613 .serdes_get_stats = mv88e6390_serdes_get_stats,
Marek Behún953b0dc2021-07-01 00:22:31 +02004614 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4615 .serdes_get_regs = mv88e6390_serdes_get_regs,
Marek Behúne3af71a2019-02-25 12:39:55 +01004616 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004617};
4618
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004619static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004620 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004621 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4622 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004623 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004624 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004625 .phy_read = mv88e6xxx_g2_smi_phy_read,
4626 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004627 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004628 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004629 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004630 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004631 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004632 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004633 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4634 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004635 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004636 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004637 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004638 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004639 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004640 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004641 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004642 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004643 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004644 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004645 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4646 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004647 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004648 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4649 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004650 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004651 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004652 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004653 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004654 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4655 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004656 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004657 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004658 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004659};
4660
4661static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004662 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004663 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4664 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004665 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004666 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004667 .phy_read = mv88e6xxx_g2_smi_phy_read,
4668 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004669 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004670 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004671 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004672 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004673 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004674 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004675 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4676 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004677 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004678 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004679 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004680 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004681 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004682 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004683 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004684 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004685 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004686 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004687 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4688 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004689 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004690 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4691 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004692 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004693 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004694 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004695 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004696 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4697 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004698 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004699 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004700 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004701 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004702 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004703};
4704
4705static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004706 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004707 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4708 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004709 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004710 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4711 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004712 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004713 .phy_read = mv88e6xxx_g2_smi_phy_read,
4714 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004715 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004716 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004717 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004718 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004719 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004720 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004721 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004722 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4723 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004724 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004725 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004726 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004727 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004728 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004729 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004730 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004731 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004732 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004733 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004734 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4735 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004736 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004737 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4738 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004739 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004740 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004741 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004742 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004743 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004744 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4745 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004746 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004747 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004748 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004749 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4750 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4751 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4752 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004753 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004754 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004755 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004756 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004757 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004758 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004759 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004760 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4761 .serdes_get_strings = mv88e6352_serdes_get_strings,
4762 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004763 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4764 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004765 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004766};
4767
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004768static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004769 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004770 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004771 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004772 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4773 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004774 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4775 .phy_read = mv88e6xxx_g2_smi_phy_read,
4776 .phy_write = mv88e6xxx_g2_smi_phy_write,
4777 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004778 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004779 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004780 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004781 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004782 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004783 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004784 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004785 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4786 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004787 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004788 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004789 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004790 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004791 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004792 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004793 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004794 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004795 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004796 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004797 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004798 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4799 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004800 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004801 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4802 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004803 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004804 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004805 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004806 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004807 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004808 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4809 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004810 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4811 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004812 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004813 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004814 /* Check status register pause & lpa register */
4815 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4816 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4817 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4818 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004819 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004820 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004821 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004822 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004823 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004824 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004825 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4826 .serdes_get_strings = mv88e6390_serdes_get_strings,
4827 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004828 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4829 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004830 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004831};
4832
4833static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004834 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004835 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004836 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004837 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4838 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004839 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4840 .phy_read = mv88e6xxx_g2_smi_phy_read,
4841 .phy_write = mv88e6xxx_g2_smi_phy_write,
4842 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004843 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004844 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004845 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004846 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004847 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004848 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004849 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004850 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4851 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004852 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004853 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004854 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004855 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004856 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004857 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004858 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004859 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004860 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004861 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004862 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004863 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4864 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004865 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004866 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4867 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004868 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004869 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004870 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004871 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004872 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004873 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4874 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004875 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4876 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004877 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004878 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004879 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4880 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4881 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4882 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004883 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004884 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004885 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004886 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4887 .serdes_get_strings = mv88e6390_serdes_get_strings,
4888 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004889 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4890 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004891 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004892 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004893 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004894 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004895};
4896
Pavana Sharmade776d02021-03-17 14:46:42 +01004897static const struct mv88e6xxx_ops mv88e6393x_ops = {
4898 /* MV88E6XXX_FAMILY_6393 */
4899 .setup_errata = mv88e6393x_serdes_setup_errata,
4900 .irl_init_all = mv88e6390_g2_irl_init_all,
4901 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4902 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4903 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4904 .phy_read = mv88e6xxx_g2_smi_phy_read,
4905 .phy_write = mv88e6xxx_g2_smi_phy_write,
4906 .port_set_link = mv88e6xxx_port_set_link,
4907 .port_sync_link = mv88e6xxx_port_sync_link,
4908 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4909 .port_set_speed_duplex = mv88e6393x_port_set_speed_duplex,
4910 .port_max_speed_mode = mv88e6393x_port_max_speed_mode,
4911 .port_tag_remap = mv88e6390_port_tag_remap,
Marek Behún6584b262021-03-17 14:46:43 +01004912 .port_set_policy = mv88e6393x_port_set_policy,
Pavana Sharmade776d02021-03-17 14:46:42 +01004913 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4914 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4915 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4916 .port_set_ether_type = mv88e6393x_port_set_ether_type,
4917 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4918 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4919 .port_pause_limit = mv88e6390_port_pause_limit,
4920 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4921 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4922 .port_get_cmode = mv88e6352_port_get_cmode,
4923 .port_set_cmode = mv88e6393x_port_set_cmode,
4924 .port_setup_message_port = mv88e6xxx_setup_message_port,
4925 .port_set_upstream_port = mv88e6393x_port_set_upstream_port,
4926 .stats_snapshot = mv88e6390_g1_stats_snapshot,
4927 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4928 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4929 .stats_get_strings = mv88e6320_stats_get_strings,
4930 .stats_get_stats = mv88e6390_stats_get_stats,
4931 /* .set_cpu_port is missing because this family does not support a global
4932 * CPU port, only per port CPU port which is set via
4933 * .port_set_upstream_port method.
4934 */
4935 .set_egress_port = mv88e6393x_set_egress_port,
4936 .watchdog_ops = &mv88e6390_watchdog_ops,
4937 .mgmt_rsvd2cpu = mv88e6393x_port_mgmt_rsvd2cpu,
4938 .pot_clear = mv88e6xxx_g2_pot_clear,
4939 .reset = mv88e6352_g1_reset,
4940 .rmu_disable = mv88e6390_g1_rmu_disable,
4941 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4942 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4943 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4944 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4945 .serdes_power = mv88e6393x_serdes_power,
4946 .serdes_get_lane = mv88e6393x_serdes_get_lane,
4947 .serdes_pcs_get_state = mv88e6393x_serdes_pcs_get_state,
4948 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4949 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4950 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4951 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4952 .serdes_irq_enable = mv88e6393x_serdes_irq_enable,
4953 .serdes_irq_status = mv88e6393x_serdes_irq_status,
4954 /* TODO: serdes stats */
4955 .gpio_ops = &mv88e6352_gpio_ops,
4956 .avb_ops = &mv88e6390_avb_ops,
4957 .ptp_ops = &mv88e6352_ptp_ops,
4958 .phylink_validate = mv88e6393x_phylink_validate,
4959};
4960
Vivien Didelotf81ec902016-05-09 13:22:58 -04004961static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4962 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004963 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004964 .family = MV88E6XXX_FAMILY_6097,
4965 .name = "Marvell 88E6085",
4966 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004967 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004968 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004969 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004970 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004971 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004972 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004973 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004974 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004975 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004976 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004977 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004978 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004979 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004980 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004981 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004982 },
4983
4984 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004985 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004986 .family = MV88E6XXX_FAMILY_6095,
4987 .name = "Marvell 88E6095/88E6095F",
4988 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004989 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004990 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004991 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004992 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004993 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004994 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004995 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004996 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004997 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004998 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004999 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005000 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005001 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005002 },
5003
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005004 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005005 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005006 .family = MV88E6XXX_FAMILY_6097,
5007 .name = "Marvell 88E6097/88E6097F",
5008 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005009 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005010 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01005011 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005012 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005013 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005014 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005015 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005016 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005017 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01005018 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005019 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005020 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005021 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005022 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005023 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005024 .ops = &mv88e6097_ops,
5025 },
5026
Vivien Didelotf81ec902016-05-09 13:22:58 -04005027 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005028 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005029 .family = MV88E6XXX_FAMILY_6165,
5030 .name = "Marvell 88E6123",
5031 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005032 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005033 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01005034 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005035 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005036 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005037 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005038 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005039 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005040 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005041 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005042 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005043 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005044 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005045 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005046 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005047 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005048 },
5049
5050 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005051 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005052 .family = MV88E6XXX_FAMILY_6185,
5053 .name = "Marvell 88E6131",
5054 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005055 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005056 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005057 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005058 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005059 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005060 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005061 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005062 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005063 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005064 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05005065 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005066 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005067 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005068 },
5069
Vivien Didelot990e27b2017-03-28 13:50:32 -04005070 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005071 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005072 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01005073 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04005074 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005075 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005076 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005077 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005078 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005079 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005080 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005081 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005082 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005083 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005084 .age_time_coeff = 3750,
5085 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005086 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005087 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005088 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005089 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005090 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005091 .ops = &mv88e6141_ops,
5092 },
5093
Vivien Didelotf81ec902016-05-09 13:22:58 -04005094 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005095 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005096 .family = MV88E6XXX_FAMILY_6165,
5097 .name = "Marvell 88E6161",
5098 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005099 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005100 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005101 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005102 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005103 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005104 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005105 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005106 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005107 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005108 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005109 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005110 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005111 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005112 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005113 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Andrew Lunndfa54342018-07-18 22:38:22 +02005114 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005115 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005116 },
5117
5118 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005119 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005120 .family = MV88E6XXX_FAMILY_6165,
5121 .name = "Marvell 88E6165",
5122 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005123 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005124 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005125 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005126 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005127 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005128 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005129 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005130 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005131 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005132 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005133 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005134 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005135 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005136 .multi_chip = true,
Andrew Lunndfa54342018-07-18 22:38:22 +02005137 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005138 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005139 },
5140
5141 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005142 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005143 .family = MV88E6XXX_FAMILY_6351,
5144 .name = "Marvell 88E6171",
5145 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005146 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005147 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005148 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005149 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005150 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005151 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005152 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005153 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005154 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005155 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005156 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005157 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005158 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005159 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005160 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005161 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005162 },
5163
5164 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005165 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005166 .family = MV88E6XXX_FAMILY_6352,
5167 .name = "Marvell 88E6172",
5168 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005169 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005170 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005171 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005172 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005173 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005174 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005175 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005176 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005177 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005178 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005179 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005180 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005181 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005182 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005183 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005184 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005185 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005186 },
5187
5188 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005189 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005190 .family = MV88E6XXX_FAMILY_6351,
5191 .name = "Marvell 88E6175",
5192 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005193 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005194 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005195 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005196 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005197 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005198 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005199 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005200 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005201 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005202 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005203 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005204 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005205 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005206 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005207 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005208 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005209 },
5210
5211 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005212 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005213 .family = MV88E6XXX_FAMILY_6352,
5214 .name = "Marvell 88E6176",
5215 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005216 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005217 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005218 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005219 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005220 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005221 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005222 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005223 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005224 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005225 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005226 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005227 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005228 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005229 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005230 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005231 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005232 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005233 },
5234
5235 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005236 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005237 .family = MV88E6XXX_FAMILY_6185,
5238 .name = "Marvell 88E6185",
5239 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005240 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005241 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01005242 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005243 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005244 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005245 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005246 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005247 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005248 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005249 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05005250 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005251 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005252 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005253 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005254 },
5255
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005256 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005257 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005258 .family = MV88E6XXX_FAMILY_6390,
5259 .name = "Marvell 88E6190",
5260 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005261 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005262 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005263 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005264 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005265 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005266 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005267 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005268 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005269 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005270 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005271 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005272 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04005273 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005274 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05005275 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005276 .ops = &mv88e6190_ops,
5277 },
5278
5279 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005280 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005281 .family = MV88E6XXX_FAMILY_6390,
5282 .name = "Marvell 88E6190X",
5283 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005284 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005285 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005286 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005287 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005288 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005289 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005290 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005291 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005292 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005293 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005294 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005295 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005296 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005297 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005298 .multi_chip = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005299 .ops = &mv88e6190x_ops,
5300 },
5301
5302 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005303 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005304 .family = MV88E6XXX_FAMILY_6390,
5305 .name = "Marvell 88E6191",
5306 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005307 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005308 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005309 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04005310 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005311 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005312 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005313 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005314 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005315 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005316 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005317 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005318 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005319 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005320 .multi_chip = true,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005321 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04005322 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005323 },
5324
Pavana Sharmade776d02021-03-17 14:46:42 +01005325 [MV88E6191X] = {
5326 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191X,
5327 .family = MV88E6XXX_FAMILY_6393,
5328 .name = "Marvell 88E6191X",
5329 .num_databases = 4096,
5330 .num_ports = 11, /* 10 + Z80 */
5331 .num_internal_phys = 9,
5332 .max_vid = 8191,
5333 .port_base_addr = 0x0,
5334 .phy_base_addr = 0x0,
5335 .global1_addr = 0x1b,
5336 .global2_addr = 0x1c,
5337 .age_time_coeff = 3750,
5338 .g1_irqs = 10,
5339 .g2_irqs = 14,
5340 .atu_move_port_mask = 0x1f,
5341 .pvt = true,
5342 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005343 .ptp_support = true,
5344 .ops = &mv88e6393x_ops,
5345 },
5346
5347 [MV88E6193X] = {
5348 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6193X,
5349 .family = MV88E6XXX_FAMILY_6393,
5350 .name = "Marvell 88E6193X",
5351 .num_databases = 4096,
5352 .num_ports = 11, /* 10 + Z80 */
5353 .num_internal_phys = 9,
5354 .max_vid = 8191,
5355 .port_base_addr = 0x0,
5356 .phy_base_addr = 0x0,
5357 .global1_addr = 0x1b,
5358 .global2_addr = 0x1c,
5359 .age_time_coeff = 3750,
5360 .g1_irqs = 10,
5361 .g2_irqs = 14,
5362 .atu_move_port_mask = 0x1f,
5363 .pvt = true,
5364 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005365 .ptp_support = true,
5366 .ops = &mv88e6393x_ops,
5367 },
5368
Hubert Feurstein49022642019-07-31 10:23:46 +02005369 [MV88E6220] = {
5370 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
5371 .family = MV88E6XXX_FAMILY_6250,
5372 .name = "Marvell 88E6220",
5373 .num_databases = 64,
5374
5375 /* Ports 2-4 are not routed to pins
5376 * => usable ports 0, 1, 5, 6
5377 */
5378 .num_ports = 7,
5379 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02005380 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02005381 .max_vid = 4095,
5382 .port_base_addr = 0x08,
5383 .phy_base_addr = 0x00,
5384 .global1_addr = 0x0f,
5385 .global2_addr = 0x07,
5386 .age_time_coeff = 15000,
5387 .g1_irqs = 9,
5388 .g2_irqs = 10,
5389 .atu_move_port_mask = 0xf,
5390 .dual_chip = true,
Hubert Feurstein71509612019-07-31 10:23:51 +02005391 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02005392 .ops = &mv88e6250_ops,
5393 },
5394
Vivien Didelotf81ec902016-05-09 13:22:58 -04005395 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005396 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005397 .family = MV88E6XXX_FAMILY_6352,
5398 .name = "Marvell 88E6240",
5399 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005400 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005401 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005402 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005403 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005404 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005405 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005406 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005407 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005408 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005409 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005410 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005411 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005412 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005413 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005414 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005415 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005416 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005417 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005418 },
5419
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005420 [MV88E6250] = {
5421 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
5422 .family = MV88E6XXX_FAMILY_6250,
5423 .name = "Marvell 88E6250",
5424 .num_databases = 64,
5425 .num_ports = 7,
5426 .num_internal_phys = 5,
5427 .max_vid = 4095,
5428 .port_base_addr = 0x08,
5429 .phy_base_addr = 0x00,
5430 .global1_addr = 0x0f,
5431 .global2_addr = 0x07,
5432 .age_time_coeff = 15000,
5433 .g1_irqs = 9,
5434 .g2_irqs = 10,
5435 .atu_move_port_mask = 0xf,
5436 .dual_chip = true,
Hubert Feurstein71509612019-07-31 10:23:51 +02005437 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005438 .ops = &mv88e6250_ops,
5439 },
5440
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005441 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005442 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005443 .family = MV88E6XXX_FAMILY_6390,
5444 .name = "Marvell 88E6290",
5445 .num_databases = 4096,
5446 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005447 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005448 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005449 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005450 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005451 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005452 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005453 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005454 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005455 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005456 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005457 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005458 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005459 .multi_chip = true,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005460 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005461 .ops = &mv88e6290_ops,
5462 },
5463
Vivien Didelotf81ec902016-05-09 13:22:58 -04005464 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005465 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005466 .family = MV88E6XXX_FAMILY_6320,
5467 .name = "Marvell 88E6320",
5468 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005469 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005470 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005471 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005472 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005473 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005474 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005475 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005476 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005477 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005478 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005479 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005480 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005481 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005482 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005483 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005484 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005485 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005486 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005487 },
5488
5489 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005490 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005491 .family = MV88E6XXX_FAMILY_6320,
5492 .name = "Marvell 88E6321",
5493 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005494 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005495 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005496 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005497 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005498 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005499 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005500 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005501 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005502 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005503 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005504 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005505 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005506 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005507 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005508 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005509 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005510 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005511 },
5512
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005513 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005514 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005515 .family = MV88E6XXX_FAMILY_6341,
5516 .name = "Marvell 88E6341",
5517 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005518 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005519 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005520 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005521 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005522 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005523 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005524 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005525 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005526 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005527 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005528 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005529 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005530 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005531 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005532 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005533 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005534 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005535 .ops = &mv88e6341_ops,
5536 },
5537
Vivien Didelotf81ec902016-05-09 13:22:58 -04005538 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005539 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005540 .family = MV88E6XXX_FAMILY_6351,
5541 .name = "Marvell 88E6350",
5542 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005543 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005544 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005545 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005546 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005547 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005548 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005549 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005550 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005551 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005552 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005553 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005554 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005555 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005556 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005557 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005558 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005559 },
5560
5561 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005562 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005563 .family = MV88E6XXX_FAMILY_6351,
5564 .name = "Marvell 88E6351",
5565 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005566 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005567 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005568 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005569 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005570 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005571 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005572 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005573 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005574 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005575 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005576 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005577 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005578 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005579 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005580 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005581 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005582 },
5583
5584 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005585 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005586 .family = MV88E6XXX_FAMILY_6352,
5587 .name = "Marvell 88E6352",
5588 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005589 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005590 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005591 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005592 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005593 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005594 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005595 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005596 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005597 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005598 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005599 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005600 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005601 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005602 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005603 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005604 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005605 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005606 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005607 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005608 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005609 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005610 .family = MV88E6XXX_FAMILY_6390,
5611 .name = "Marvell 88E6390",
5612 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005613 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005614 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005615 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005616 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005617 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005618 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005619 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005620 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005621 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005622 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005623 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005624 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005625 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005626 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005627 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005628 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005629 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005630 .ops = &mv88e6390_ops,
5631 },
5632 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005633 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005634 .family = MV88E6XXX_FAMILY_6390,
5635 .name = "Marvell 88E6390X",
5636 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005637 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005638 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005639 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005640 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005641 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005642 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005643 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005644 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005645 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005646 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005647 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005648 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005649 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005650 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005651 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005652 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005653 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005654 .ops = &mv88e6390x_ops,
5655 },
Pavana Sharmade776d02021-03-17 14:46:42 +01005656
5657 [MV88E6393X] = {
5658 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
5659 .family = MV88E6XXX_FAMILY_6393,
5660 .name = "Marvell 88E6393X",
5661 .num_databases = 4096,
5662 .num_ports = 11, /* 10 + Z80 */
5663 .num_internal_phys = 9,
5664 .max_vid = 8191,
5665 .port_base_addr = 0x0,
5666 .phy_base_addr = 0x0,
5667 .global1_addr = 0x1b,
5668 .global2_addr = 0x1c,
5669 .age_time_coeff = 3750,
5670 .g1_irqs = 10,
5671 .g2_irqs = 14,
5672 .atu_move_port_mask = 0x1f,
5673 .pvt = true,
5674 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005675 .ptp_support = true,
5676 .ops = &mv88e6393x_ops,
5677 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005678};
5679
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005680static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005681{
Vivien Didelota439c062016-04-17 13:23:58 -04005682 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005683
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005684 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5685 if (mv88e6xxx_table[i].prod_num == prod_num)
5686 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005687
Vivien Didelotb9b37712015-10-30 19:39:48 -04005688 return NULL;
5689}
5690
Vivien Didelotfad09c72016-06-21 12:28:20 -04005691static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005692{
5693 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005694 unsigned int prod_num, rev;
5695 u16 id;
5696 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005697
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005698 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005699 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005700 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005701 if (err)
5702 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005703
Vivien Didelot107fcc12017-06-12 12:37:36 -04005704 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5705 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005706
5707 info = mv88e6xxx_lookup_info(prod_num);
5708 if (!info)
5709 return -ENODEV;
5710
Vivien Didelotcaac8542016-06-20 13:14:09 -04005711 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005712 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005713
Vivien Didelotfad09c72016-06-21 12:28:20 -04005714 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5715 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005716
5717 return 0;
5718}
5719
Vivien Didelotfad09c72016-06-21 12:28:20 -04005720static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005721{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005722 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005723
Vivien Didelotfad09c72016-06-21 12:28:20 -04005724 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5725 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005726 return NULL;
5727
Vivien Didelotfad09c72016-06-21 12:28:20 -04005728 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005729
Vivien Didelotfad09c72016-06-21 12:28:20 -04005730 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005731 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005732 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005733
Vivien Didelotfad09c72016-06-21 12:28:20 -04005734 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005735}
5736
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005737static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005738 int port,
5739 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005740{
Vivien Didelot04bed142016-08-31 18:06:13 -04005741 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005742
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005743 return chip->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005744}
5745
Tobias Waldekranz9a99bef2021-04-20 20:53:08 +02005746static int mv88e6xxx_change_tag_protocol(struct dsa_switch *ds, int port,
5747 enum dsa_tag_protocol proto)
5748{
5749 struct mv88e6xxx_chip *chip = ds->priv;
5750 enum dsa_tag_protocol old_protocol;
5751 int err;
5752
5753 switch (proto) {
5754 case DSA_TAG_PROTO_EDSA:
5755 switch (chip->info->edsa_support) {
5756 case MV88E6XXX_EDSA_UNSUPPORTED:
5757 return -EPROTONOSUPPORT;
5758 case MV88E6XXX_EDSA_UNDOCUMENTED:
5759 dev_warn(chip->dev, "Relying on undocumented EDSA tagging behavior\n");
5760 fallthrough;
5761 case MV88E6XXX_EDSA_SUPPORTED:
5762 break;
5763 }
5764 break;
5765 case DSA_TAG_PROTO_DSA:
5766 break;
5767 default:
5768 return -EPROTONOSUPPORT;
5769 }
5770
5771 old_protocol = chip->tag_protocol;
5772 chip->tag_protocol = proto;
5773
5774 mv88e6xxx_reg_lock(chip);
5775 err = mv88e6xxx_setup_port_mode(chip, port);
5776 mv88e6xxx_reg_unlock(chip);
5777
5778 if (err)
5779 chip->tag_protocol = old_protocol;
5780
5781 return err;
5782}
5783
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005784static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
5785 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005786{
Vivien Didelot04bed142016-08-31 18:06:13 -04005787 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005788 int err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005789
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005790 mv88e6xxx_reg_lock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005791 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5792 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005793 mv88e6xxx_reg_unlock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005794
5795 return err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005796}
5797
5798static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5799 const struct switchdev_obj_port_mdb *mdb)
5800{
Vivien Didelot04bed142016-08-31 18:06:13 -04005801 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005802 int err;
5803
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005804 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005805 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005806 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005807
5808 return err;
5809}
5810
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005811static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5812 struct dsa_mall_mirror_tc_entry *mirror,
5813 bool ingress)
5814{
5815 enum mv88e6xxx_egress_direction direction = ingress ?
5816 MV88E6XXX_EGRESS_DIR_INGRESS :
5817 MV88E6XXX_EGRESS_DIR_EGRESS;
5818 struct mv88e6xxx_chip *chip = ds->priv;
5819 bool other_mirrors = false;
5820 int i;
5821 int err;
5822
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005823 mutex_lock(&chip->reg_lock);
5824 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5825 mirror->to_local_port) {
5826 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5827 other_mirrors |= ingress ?
5828 chip->ports[i].mirror_ingress :
5829 chip->ports[i].mirror_egress;
5830
5831 /* Can't change egress port when other mirror is active */
5832 if (other_mirrors) {
5833 err = -EBUSY;
5834 goto out;
5835 }
5836
Marek Behún2fda45f2021-03-17 14:46:41 +01005837 err = mv88e6xxx_set_egress_port(chip, direction,
5838 mirror->to_local_port);
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005839 if (err)
5840 goto out;
5841 }
5842
5843 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5844out:
5845 mutex_unlock(&chip->reg_lock);
5846
5847 return err;
5848}
5849
5850static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5851 struct dsa_mall_mirror_tc_entry *mirror)
5852{
5853 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5854 MV88E6XXX_EGRESS_DIR_INGRESS :
5855 MV88E6XXX_EGRESS_DIR_EGRESS;
5856 struct mv88e6xxx_chip *chip = ds->priv;
5857 bool other_mirrors = false;
5858 int i;
5859
5860 mutex_lock(&chip->reg_lock);
5861 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5862 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5863
5864 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5865 other_mirrors |= mirror->ingress ?
5866 chip->ports[i].mirror_ingress :
5867 chip->ports[i].mirror_egress;
5868
5869 /* Reset egress port when no other mirror is active */
5870 if (!other_mirrors) {
Marek Behún2fda45f2021-03-17 14:46:41 +01005871 if (mv88e6xxx_set_egress_port(chip, direction,
5872 dsa_upstream_port(ds, port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005873 dev_err(ds->dev, "failed to set egress port\n");
5874 }
5875
5876 mutex_unlock(&chip->reg_lock);
5877}
5878
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005879static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port,
5880 struct switchdev_brport_flags flags,
5881 struct netlink_ext_ack *extack)
5882{
5883 struct mv88e6xxx_chip *chip = ds->priv;
5884 const struct mv88e6xxx_ops *ops;
5885
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01005886 if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
5887 BR_BCAST_FLOOD))
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005888 return -EINVAL;
5889
5890 ops = chip->info->ops;
5891
5892 if ((flags.mask & BR_FLOOD) && !ops->port_set_ucast_flood)
5893 return -EINVAL;
5894
5895 if ((flags.mask & BR_MCAST_FLOOD) && !ops->port_set_mcast_flood)
5896 return -EINVAL;
5897
5898 return 0;
5899}
5900
5901static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
5902 struct switchdev_brport_flags flags,
5903 struct netlink_ext_ack *extack)
Russell King4f859012019-02-20 15:35:05 -08005904{
5905 struct mv88e6xxx_chip *chip = ds->priv;
5906 int err = -EOPNOTSUPP;
5907
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005908 mv88e6xxx_reg_lock(chip);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005909
Tobias Waldekranz041bd542021-03-18 20:25:39 +01005910 if (flags.mask & BR_LEARNING) {
5911 bool learning = !!(flags.val & BR_LEARNING);
5912 u16 pav = learning ? (1 << port) : 0;
5913
5914 err = mv88e6xxx_port_set_assoc_vector(chip, port, pav);
5915 if (err)
5916 goto out;
Tobias Waldekranz041bd542021-03-18 20:25:39 +01005917 }
5918
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005919 if (flags.mask & BR_FLOOD) {
5920 bool unicast = !!(flags.val & BR_FLOOD);
5921
5922 err = chip->info->ops->port_set_ucast_flood(chip, port,
5923 unicast);
5924 if (err)
5925 goto out;
5926 }
5927
5928 if (flags.mask & BR_MCAST_FLOOD) {
5929 bool multicast = !!(flags.val & BR_MCAST_FLOOD);
5930
5931 err = chip->info->ops->port_set_mcast_flood(chip, port,
5932 multicast);
5933 if (err)
5934 goto out;
5935 }
5936
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01005937 if (flags.mask & BR_BCAST_FLOOD) {
5938 bool broadcast = !!(flags.val & BR_BCAST_FLOOD);
5939
5940 err = mv88e6xxx_port_broadcast_sync(chip, port, broadcast);
5941 if (err)
5942 goto out;
5943 }
5944
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005945out:
5946 mv88e6xxx_reg_unlock(chip);
5947
5948 return err;
5949}
5950
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005951static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
5952 struct net_device *lag,
5953 struct netdev_lag_upper_info *info)
5954{
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005955 struct mv88e6xxx_chip *chip = ds->priv;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005956 struct dsa_port *dp;
5957 int id, members = 0;
5958
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005959 if (!mv88e6xxx_has_lag(chip))
5960 return false;
5961
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005962 id = dsa_lag_id(ds->dst, lag);
5963 if (id < 0 || id >= ds->num_lag_ids)
5964 return false;
5965
5966 dsa_lag_foreach_port(dp, ds->dst, lag)
5967 /* Includes the port joining the LAG */
5968 members++;
5969
5970 if (members > 8)
5971 return false;
5972
5973 /* We could potentially relax this to include active
5974 * backup in the future.
5975 */
5976 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
5977 return false;
5978
5979 /* Ideally we would also validate that the hash type matches
5980 * the hardware. Alas, this is always set to unknown on team
5981 * interfaces.
5982 */
5983 return true;
5984}
5985
5986static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct net_device *lag)
5987{
5988 struct mv88e6xxx_chip *chip = ds->priv;
5989 struct dsa_port *dp;
5990 u16 map = 0;
5991 int id;
5992
5993 id = dsa_lag_id(ds->dst, lag);
5994
5995 /* Build the map of all ports to distribute flows destined for
5996 * this LAG. This can be either a local user port, or a DSA
5997 * port if the LAG port is on a remote chip.
5998 */
5999 dsa_lag_foreach_port(dp, ds->dst, lag)
6000 map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));
6001
6002 return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
6003}
6004
6005static const u8 mv88e6xxx_lag_mask_table[8][8] = {
6006 /* Row number corresponds to the number of active members in a
6007 * LAG. Each column states which of the eight hash buckets are
6008 * mapped to the column:th port in the LAG.
6009 *
6010 * Example: In a LAG with three active ports, the second port
6011 * ([2][1]) would be selected for traffic mapped to buckets
6012 * 3,4,5 (0x38).
6013 */
6014 { 0xff, 0, 0, 0, 0, 0, 0, 0 },
6015 { 0x0f, 0xf0, 0, 0, 0, 0, 0, 0 },
6016 { 0x07, 0x38, 0xc0, 0, 0, 0, 0, 0 },
6017 { 0x03, 0x0c, 0x30, 0xc0, 0, 0, 0, 0 },
6018 { 0x03, 0x0c, 0x30, 0x40, 0x80, 0, 0, 0 },
6019 { 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80, 0, 0 },
6020 { 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0 },
6021 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
6022};
6023
6024static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
6025 int num_tx, int nth)
6026{
6027 u8 active = 0;
6028 int i;
6029
6030 num_tx = num_tx <= 8 ? num_tx : 8;
6031 if (nth < num_tx)
6032 active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];
6033
6034 for (i = 0; i < 8; i++) {
6035 if (BIT(i) & active)
6036 mask[i] |= BIT(port);
6037 }
6038}
6039
6040static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
6041{
6042 struct mv88e6xxx_chip *chip = ds->priv;
6043 unsigned int id, num_tx;
6044 struct net_device *lag;
6045 struct dsa_port *dp;
6046 int i, err, nth;
6047 u16 mask[8];
6048 u16 ivec;
6049
6050 /* Assume no port is a member of any LAG. */
6051 ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;
6052
6053 /* Disable all masks for ports that _are_ members of a LAG. */
6054 list_for_each_entry(dp, &ds->dst->ports, list) {
6055 if (!dp->lag_dev || dp->ds != ds)
6056 continue;
6057
6058 ivec &= ~BIT(dp->index);
6059 }
6060
6061 for (i = 0; i < 8; i++)
6062 mask[i] = ivec;
6063
6064 /* Enable the correct subset of masks for all LAG ports that
6065 * are in the Tx set.
6066 */
6067 dsa_lags_foreach_id(id, ds->dst) {
6068 lag = dsa_lag_dev(ds->dst, id);
6069 if (!lag)
6070 continue;
6071
6072 num_tx = 0;
6073 dsa_lag_foreach_port(dp, ds->dst, lag) {
6074 if (dp->lag_tx_enabled)
6075 num_tx++;
6076 }
6077
6078 if (!num_tx)
6079 continue;
6080
6081 nth = 0;
6082 dsa_lag_foreach_port(dp, ds->dst, lag) {
6083 if (!dp->lag_tx_enabled)
6084 continue;
6085
6086 if (dp->ds == ds)
6087 mv88e6xxx_lag_set_port_mask(mask, dp->index,
6088 num_tx, nth);
6089
6090 nth++;
6091 }
6092 }
6093
6094 for (i = 0; i < 8; i++) {
6095 err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
6096 if (err)
6097 return err;
6098 }
6099
6100 return 0;
6101}
6102
6103static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
6104 struct net_device *lag)
6105{
6106 int err;
6107
6108 err = mv88e6xxx_lag_sync_masks(ds);
6109
6110 if (!err)
6111 err = mv88e6xxx_lag_sync_map(ds, lag);
6112
6113 return err;
6114}
6115
6116static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port)
6117{
6118 struct mv88e6xxx_chip *chip = ds->priv;
6119 int err;
6120
6121 mv88e6xxx_reg_lock(chip);
6122 err = mv88e6xxx_lag_sync_masks(ds);
6123 mv88e6xxx_reg_unlock(chip);
6124 return err;
6125}
6126
6127static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
6128 struct net_device *lag,
6129 struct netdev_lag_upper_info *info)
6130{
6131 struct mv88e6xxx_chip *chip = ds->priv;
6132 int err, id;
6133
6134 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
6135 return -EOPNOTSUPP;
6136
6137 id = dsa_lag_id(ds->dst, lag);
6138
6139 mv88e6xxx_reg_lock(chip);
6140
6141 err = mv88e6xxx_port_set_trunk(chip, port, true, id);
6142 if (err)
6143 goto err_unlock;
6144
6145 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6146 if (err)
6147 goto err_clear_trunk;
6148
6149 mv88e6xxx_reg_unlock(chip);
6150 return 0;
6151
6152err_clear_trunk:
6153 mv88e6xxx_port_set_trunk(chip, port, false, 0);
6154err_unlock:
6155 mv88e6xxx_reg_unlock(chip);
6156 return err;
6157}
6158
6159static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
6160 struct net_device *lag)
6161{
6162 struct mv88e6xxx_chip *chip = ds->priv;
6163 int err_sync, err_trunk;
6164
6165 mv88e6xxx_reg_lock(chip);
6166 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6167 err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
6168 mv88e6xxx_reg_unlock(chip);
6169 return err_sync ? : err_trunk;
6170}
6171
6172static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
6173 int port)
6174{
6175 struct mv88e6xxx_chip *chip = ds->priv;
6176 int err;
6177
6178 mv88e6xxx_reg_lock(chip);
6179 err = mv88e6xxx_lag_sync_masks(ds);
6180 mv88e6xxx_reg_unlock(chip);
6181 return err;
6182}
6183
6184static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
6185 int port, struct net_device *lag,
6186 struct netdev_lag_upper_info *info)
6187{
6188 struct mv88e6xxx_chip *chip = ds->priv;
6189 int err;
6190
6191 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
6192 return -EOPNOTSUPP;
6193
6194 mv88e6xxx_reg_lock(chip);
6195
6196 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6197 if (err)
6198 goto unlock;
6199
6200 err = mv88e6xxx_pvt_map(chip, sw_index, port);
6201
6202unlock:
6203 mv88e6xxx_reg_unlock(chip);
6204 return err;
6205}
6206
6207static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
6208 int port, struct net_device *lag)
6209{
6210 struct mv88e6xxx_chip *chip = ds->priv;
6211 int err_sync, err_pvt;
6212
6213 mv88e6xxx_reg_lock(chip);
6214 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6215 err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
6216 mv88e6xxx_reg_unlock(chip);
6217 return err_sync ? : err_pvt;
6218}
6219
Florian Fainellia82f67a2017-01-08 14:52:08 -08006220static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02006221 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Tobias Waldekranz9a99bef2021-04-20 20:53:08 +02006222 .change_tag_protocol = mv88e6xxx_change_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006223 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02006224 .teardown = mv88e6xxx_teardown,
Vladimir Olteanfd292c12021-09-17 17:29:16 +03006225 .port_setup = mv88e6xxx_port_setup,
6226 .port_teardown = mv88e6xxx_port_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07006227 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00006228 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07006229 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00006230 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07006231 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
6232 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006233 .get_strings = mv88e6xxx_get_strings,
6234 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
6235 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02006236 .port_enable = mv88e6xxx_port_enable,
6237 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02006238 .port_max_mtu = mv88e6xxx_get_max_mtu,
6239 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04006240 .get_mac_eee = mv88e6xxx_get_mac_eee,
6241 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006242 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006243 .get_eeprom = mv88e6xxx_get_eeprom,
6244 .set_eeprom = mv88e6xxx_set_eeprom,
6245 .get_regs_len = mv88e6xxx_get_regs_len,
6246 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04006247 .get_rxnfc = mv88e6xxx_get_rxnfc,
6248 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04006249 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006250 .port_bridge_join = mv88e6xxx_port_bridge_join,
6251 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02006252 .port_pre_bridge_flags = mv88e6xxx_port_pre_bridge_flags,
6253 .port_bridge_flags = mv88e6xxx_port_bridge_flags,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006254 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04006255 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006256 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006257 .port_vlan_add = mv88e6xxx_port_vlan_add,
6258 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006259 .port_fdb_add = mv88e6xxx_port_fdb_add,
6260 .port_fdb_del = mv88e6xxx_port_fdb_del,
6261 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04006262 .port_mdb_add = mv88e6xxx_port_mdb_add,
6263 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01006264 .port_mirror_add = mv88e6xxx_port_mirror_add,
6265 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04006266 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
6267 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006268 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
6269 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
6270 .port_txtstamp = mv88e6xxx_port_txtstamp,
6271 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
6272 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02006273 .devlink_param_get = mv88e6xxx_devlink_param_get,
6274 .devlink_param_set = mv88e6xxx_devlink_param_set,
Andrew Lunn93157302020-09-18 21:11:09 +02006275 .devlink_info_get = mv88e6xxx_devlink_info_get,
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006276 .port_lag_change = mv88e6xxx_port_lag_change,
6277 .port_lag_join = mv88e6xxx_port_lag_join,
6278 .port_lag_leave = mv88e6xxx_port_lag_leave,
6279 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
6280 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
6281 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
Vladimir Olteance5df682021-07-22 18:55:41 +03006282 .port_bridge_tx_fwd_offload = mv88e6xxx_bridge_tx_fwd_offload,
6283 .port_bridge_tx_fwd_unoffload = mv88e6xxx_bridge_tx_fwd_unoffload,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006284};
6285
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08006286static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006287{
Vivien Didelotfad09c72016-06-21 12:28:20 -04006288 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006289 struct dsa_switch *ds;
6290
Vivien Didelot7e99e342019-10-21 16:51:30 -04006291 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006292 if (!ds)
6293 return -ENOMEM;
6294
Vivien Didelot7e99e342019-10-21 16:51:30 -04006295 ds->dev = dev;
6296 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006297 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006298 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04006299 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04006300 ds->ageing_time_min = chip->info->age_time_coeff;
6301 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006302
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006303 /* Some chips support up to 32, but that requires enabling the
6304 * 5-bit port mode, which we do not support. 640k^W16 ought to
6305 * be enough for anyone.
6306 */
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01006307 ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006308
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006309 dev_set_drvdata(dev, ds);
6310
Vivien Didelot23c9ee42017-05-26 18:12:51 -04006311 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006312}
6313
Vivien Didelotfad09c72016-06-21 12:28:20 -04006314static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006315{
Vivien Didelotfad09c72016-06-21 12:28:20 -04006316 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006317}
6318
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006319static const void *pdata_device_get_match_data(struct device *dev)
6320{
6321 const struct of_device_id *matches = dev->driver->of_match_table;
6322 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
6323
6324 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
6325 matches++) {
6326 if (!strcmp(pdata->compatible, matches->compatible))
6327 return matches->data;
6328 }
6329 return NULL;
6330}
6331
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006332/* There is no suspend to RAM support at DSA level yet, the switch configuration
6333 * would be lost after a power cycle so prevent it to be suspended.
6334 */
6335static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
6336{
6337 return -EOPNOTSUPP;
6338}
6339
6340static int __maybe_unused mv88e6xxx_resume(struct device *dev)
6341{
6342 return 0;
6343}
6344
6345static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
6346
Vivien Didelot57d32312016-06-20 13:13:58 -04006347static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006348{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006349 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04006350 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006351 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006352 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04006353 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006354 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02006355 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006356
Andrew Lunn7bb8c992018-05-31 00:15:42 +02006357 if (!np && !pdata)
6358 return -EINVAL;
6359
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006360 if (np)
6361 compat_info = of_device_get_match_data(dev);
6362
6363 if (pdata) {
6364 compat_info = pdata_device_get_match_data(dev);
6365
6366 if (!pdata->netdev)
6367 return -EINVAL;
6368
6369 for (port = 0; port < DSA_MAX_PORTS; port++) {
6370 if (!(pdata->enabled_ports & (1 << port)))
6371 continue;
6372 if (strcmp(pdata->cd.port_names[port], "cpu"))
6373 continue;
6374 pdata->cd.netdev[port] = &pdata->netdev->dev;
6375 break;
6376 }
6377 }
6378
Vivien Didelotcaac8542016-06-20 13:14:09 -04006379 if (!compat_info)
6380 return -EINVAL;
6381
Vivien Didelotfad09c72016-06-21 12:28:20 -04006382 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006383 if (!chip) {
6384 err = -ENOMEM;
6385 goto out;
6386 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006387
Vivien Didelotfad09c72016-06-21 12:28:20 -04006388 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04006389
Vivien Didelotfad09c72016-06-21 12:28:20 -04006390 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04006391 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006392 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006393
Andrew Lunnb4308f02016-11-21 23:26:55 +01006394 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006395 if (IS_ERR(chip->reset)) {
6396 err = PTR_ERR(chip->reset);
6397 goto out;
6398 }
Baruch Siach7b75e492019-06-27 21:17:39 +03006399 if (chip->reset)
6400 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01006401
Vivien Didelotfad09c72016-06-21 12:28:20 -04006402 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04006403 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006404 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006405
Tobias Waldekranz670bb802021-04-20 20:53:07 +02006406 if (chip->info->edsa_support == MV88E6XXX_EDSA_SUPPORTED)
6407 chip->tag_protocol = DSA_TAG_PROTO_EDSA;
6408 else
6409 chip->tag_protocol = DSA_TAG_PROTO_DSA;
6410
Vivien Didelote57e5e72016-08-15 17:19:00 -04006411 mv88e6xxx_phy_init(chip);
6412
Andrew Lunn00baabe2018-05-19 22:31:35 +02006413 if (chip->info->ops->get_eeprom) {
6414 if (np)
6415 of_property_read_u32(np, "eeprom-length",
6416 &chip->eeprom_len);
6417 else
6418 chip->eeprom_len = pdata->eeprom_len;
6419 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006420
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006421 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006422 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006423 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02006424 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02006425 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02006426
Andrew Lunna27415d2019-05-01 00:10:50 +02006427 if (np) {
6428 chip->irq = of_irq_get(np, 0);
6429 if (chip->irq == -EPROBE_DEFER) {
6430 err = chip->irq;
6431 goto out;
6432 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02006433 }
6434
Andrew Lunna27415d2019-05-01 00:10:50 +02006435 if (pdata)
6436 chip->irq = pdata->irq;
6437
Andrew Lunn294d7112018-02-22 22:58:32 +01006438 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01006439 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01006440 * controllers
6441 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006442 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006443 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006444 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006445 else
6446 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006447 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006448
Andrew Lunn294d7112018-02-22 22:58:32 +01006449 if (err)
6450 goto out;
6451
6452 if (chip->info->g2_irqs > 0) {
6453 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006454 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01006455 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02006456 }
6457
Andrew Lunn294d7112018-02-22 22:58:32 +01006458 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
6459 if (err)
6460 goto out_g2_irq;
6461
6462 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
6463 if (err)
6464 goto out_g1_atu_prob_irq;
6465
Andrew Lunna3c53be52017-01-24 14:53:50 +01006466 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02006467 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01006468 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02006469
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08006470 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006471 if (err)
6472 goto out_mdio;
6473
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006474 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02006475
6476out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01006477 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01006478out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006479 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01006480out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006481 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006482out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006483 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006484 mv88e6xxx_g2_irq_free(chip);
6485out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006486 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006487 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006488 else
6489 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006490out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006491 if (pdata)
6492 dev_put(pdata->netdev);
6493
Andrew Lunndc30c352016-10-16 19:56:49 +02006494 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006495}
6496
6497static void mv88e6xxx_remove(struct mdio_device *mdiodev)
6498{
6499 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006500 struct mv88e6xxx_chip *chip;
6501
6502 if (!ds)
6503 return;
6504
6505 chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006506
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006507 if (chip->info->ptp_support) {
6508 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006509 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006510 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006511
Andrew Lunn930188c2016-08-22 16:01:03 +02006512 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006513 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01006514 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006515
Andrew Lunn76f38f12018-03-17 20:21:09 +01006516 mv88e6xxx_g1_vtu_prob_irq_free(chip);
6517 mv88e6xxx_g1_atu_prob_irq_free(chip);
6518
6519 if (chip->info->g2_irqs > 0)
6520 mv88e6xxx_g2_irq_free(chip);
6521
Andrew Lunn76f38f12018-03-17 20:21:09 +01006522 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006523 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01006524 else
6525 mv88e6xxx_irq_poll_free(chip);
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006526
6527 dev_set_drvdata(&mdiodev->dev, NULL);
6528}
6529
6530static void mv88e6xxx_shutdown(struct mdio_device *mdiodev)
6531{
6532 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
6533
6534 if (!ds)
6535 return;
6536
6537 dsa_switch_shutdown(ds);
6538
6539 dev_set_drvdata(&mdiodev->dev, NULL);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006540}
6541
6542static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04006543 {
6544 .compatible = "marvell,mv88e6085",
6545 .data = &mv88e6xxx_table[MV88E6085],
6546 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01006547 {
6548 .compatible = "marvell,mv88e6190",
6549 .data = &mv88e6xxx_table[MV88E6190],
6550 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00006551 {
6552 .compatible = "marvell,mv88e6250",
6553 .data = &mv88e6xxx_table[MV88E6250],
6554 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006555 { /* sentinel */ },
6556};
6557
6558MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
6559
6560static struct mdio_driver mv88e6xxx_driver = {
6561 .probe = mv88e6xxx_probe,
6562 .remove = mv88e6xxx_remove,
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006563 .shutdown = mv88e6xxx_shutdown,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006564 .mdiodrv.driver = {
6565 .name = "mv88e6085",
6566 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006567 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006568 },
6569};
6570
Andrew Lunn7324d502019-04-27 19:19:10 +02006571mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00006572
6573MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
6574MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
6575MODULE_LICENSE("GPL");