blob: 14c678a9e41b3501678a74a04b83b2cbb8b36ddb [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{
643 if (port == 0 || port == 9 || port == 10) {
644 phylink_set(mask, 10000baseT_Full);
645 phylink_set(mask, 10000baseKR_Full);
646 phylink_set(mask, 10000baseCR_Full);
647 phylink_set(mask, 10000baseSR_Full);
648 phylink_set(mask, 10000baseLR_Full);
649 phylink_set(mask, 10000baseLRM_Full);
650 phylink_set(mask, 10000baseER_Full);
651 phylink_set(mask, 5000baseT_Full);
652 phylink_set(mask, 2500baseX_Full);
653 phylink_set(mask, 2500baseT_Full);
654 }
655
656 phylink_set(mask, 1000baseT_Full);
657 phylink_set(mask, 1000baseX_Full);
658
659 mv88e6065_phylink_validate(chip, port, mask, state);
660}
661
Russell Kingc9a23562018-05-10 13:17:35 -0700662static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
663 unsigned long *supported,
664 struct phylink_link_state *state)
665{
Russell King6c422e32018-08-09 15:38:39 +0200666 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
667 struct mv88e6xxx_chip *chip = ds->priv;
668
669 /* Allow all the expected bits */
670 phylink_set(mask, Autoneg);
671 phylink_set(mask, Pause);
672 phylink_set_port_modes(mask);
673
674 if (chip->info->ops->phylink_validate)
675 chip->info->ops->phylink_validate(chip, port, mask, state);
676
Sean Anderson49730562021-10-22 18:41:04 -0400677 linkmode_and(supported, supported, mask);
678 linkmode_and(state->advertising, state->advertising, mask);
Russell King6c422e32018-08-09 15:38:39 +0200679
680 /* We can only operate at 2500BaseX or 1000BaseX. If requested
681 * to advertise both, only report advertising at 2500BaseX.
682 */
683 phylink_helper_basex_speed(state);
Russell Kingc9a23562018-05-10 13:17:35 -0700684}
685
Russell Kingc9a23562018-05-10 13:17:35 -0700686static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
687 unsigned int mode,
688 const struct phylink_link_state *state)
689{
690 struct mv88e6xxx_chip *chip = ds->priv;
Russell Kingfad58192020-07-19 12:00:35 +0100691 struct mv88e6xxx_port *p;
Russell King64d47d52020-03-14 10:15:38 +0000692 int err;
Russell Kingc9a23562018-05-10 13:17:35 -0700693
Russell Kingfad58192020-07-19 12:00:35 +0100694 p = &chip->ports[port];
695
Russell King64d47d52020-03-14 10:15:38 +0000696 /* FIXME: is this the correct test? If we're in fixed mode on an
697 * internal port, why should we process this any different from
698 * PHY mode? On the other hand, the port may be automedia between
699 * an internal PHY and the serdes...
700 */
Marek Vasutd700ec42018-09-12 00:15:24 +0200701 if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
Russell Kingc9a23562018-05-10 13:17:35 -0700702 return;
703
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000704 mv88e6xxx_reg_lock(chip);
Russell Kingfad58192020-07-19 12:00:35 +0100705 /* In inband mode, the link may come up at any time while the link
706 * is not forced down. Force the link down while we reconfigure the
707 * interface mode.
Russell King64d47d52020-03-14 10:15:38 +0000708 */
Russell Kingfad58192020-07-19 12:00:35 +0100709 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
710 chip->info->ops->port_set_link)
711 chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
712
Russell King64d47d52020-03-14 10:15:38 +0000713 err = mv88e6xxx_port_config_interface(chip, port, state->interface);
Russell Kinga5a68582020-03-14 10:15:43 +0000714 if (err && err != -EOPNOTSUPP)
715 goto err_unlock;
716
717 err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
718 state->advertising);
719 /* FIXME: we should restart negotiation if something changed - which
720 * is something we get if we convert to using phylinks PCS operations.
721 */
722 if (err > 0)
723 err = 0;
724
Russell Kingfad58192020-07-19 12:00:35 +0100725 /* Undo the forced down state above after completing configuration
726 * irrespective of its state on entry, which allows the link to come up.
727 */
728 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
729 chip->info->ops->port_set_link)
730 chip->info->ops->port_set_link(chip, port, LINK_UNFORCED);
731
732 p->interface = state->interface;
733
Russell Kinga5a68582020-03-14 10:15:43 +0000734err_unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000735 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700736
737 if (err && err != -EOPNOTSUPP)
Russell King64d47d52020-03-14 10:15:38 +0000738 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700739}
740
Russell Kingc9a23562018-05-10 13:17:35 -0700741static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
742 unsigned int mode,
743 phy_interface_t interface)
744{
Russell King30c4a5b2020-02-26 10:23:51 +0000745 struct mv88e6xxx_chip *chip = ds->priv;
746 const struct mv88e6xxx_ops *ops;
747 int err = 0;
748
749 ops = chip->info->ops;
750
Russell King5d5b2312020-03-14 10:16:03 +0000751 mv88e6xxx_reg_lock(chip);
Maarten Zanders4a3e0ae2021-10-11 16:27:20 +0200752 /* Internal PHYs propagate their configuration directly to the MAC.
753 * External PHYs depend on whether the PPU is enabled for this port.
754 */
755 if (((!mv88e6xxx_phy_is_internal(ds, port) &&
756 !mv88e6xxx_port_ppu_updates(chip, port)) ||
Chris Packham4efe76622020-11-24 17:34:37 +1300757 mode == MLO_AN_FIXED) && ops->port_sync_link)
758 err = ops->port_sync_link(chip, port, mode, false);
Russell King5d5b2312020-03-14 10:16:03 +0000759 mv88e6xxx_reg_unlock(chip);
Russell King30c4a5b2020-02-26 10:23:51 +0000760
Russell King5d5b2312020-03-14 10:16:03 +0000761 if (err)
762 dev_err(chip->dev,
763 "p%d: failed to force MAC link down\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700764}
765
766static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
767 unsigned int mode, phy_interface_t interface,
Russell King5b502a72020-02-26 10:23:46 +0000768 struct phy_device *phydev,
769 int speed, int duplex,
770 bool tx_pause, bool rx_pause)
Russell Kingc9a23562018-05-10 13:17:35 -0700771{
Russell King30c4a5b2020-02-26 10:23:51 +0000772 struct mv88e6xxx_chip *chip = ds->priv;
773 const struct mv88e6xxx_ops *ops;
774 int err = 0;
775
776 ops = chip->info->ops;
777
Russell King5d5b2312020-03-14 10:16:03 +0000778 mv88e6xxx_reg_lock(chip);
Maarten Zanders4a3e0ae2021-10-11 16:27:20 +0200779 /* Internal PHYs propagate their configuration directly to the MAC.
780 * External PHYs depend on whether the PPU is enabled for this port.
781 */
782 if ((!mv88e6xxx_phy_is_internal(ds, port) &&
783 !mv88e6xxx_port_ppu_updates(chip, port)) ||
784 mode == MLO_AN_FIXED) {
Russell King30c4a5b2020-02-26 10:23:51 +0000785 /* FIXME: for an automedia port, should we force the link
786 * down here - what if the link comes up due to "other" media
787 * while we're bringing the port up, how is the exclusivity
Russell Kinga5a68582020-03-14 10:15:43 +0000788 * handled in the Marvell hardware? E.g. port 2 on 88E6390
Russell King30c4a5b2020-02-26 10:23:51 +0000789 * shared between internal PHY and Serdes.
790 */
Russell Kinga5a68582020-03-14 10:15:43 +0000791 err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
792 duplex);
793 if (err)
794 goto error;
795
Russell Kingf365c6f2020-03-14 10:15:53 +0000796 if (ops->port_set_speed_duplex) {
797 err = ops->port_set_speed_duplex(chip, port,
798 speed, duplex);
Russell King30c4a5b2020-02-26 10:23:51 +0000799 if (err && err != -EOPNOTSUPP)
800 goto error;
801 }
802
Chris Packham4efe76622020-11-24 17:34:37 +1300803 if (ops->port_sync_link)
804 err = ops->port_sync_link(chip, port, mode, true);
Russell King30c4a5b2020-02-26 10:23:51 +0000805 }
Russell King5d5b2312020-03-14 10:16:03 +0000806error:
807 mv88e6xxx_reg_unlock(chip);
808
809 if (err && err != -EOPNOTSUPP)
810 dev_err(ds->dev,
811 "p%d: failed to configure MAC link up\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700812}
813
Andrew Lunna605a0f2016-11-21 23:26:58 +0100814static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000815{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100816 if (!chip->info->ops->stats_snapshot)
817 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000818
Andrew Lunna605a0f2016-11-21 23:26:58 +0100819 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000820}
821
Andrew Lunne413e7e2015-04-02 04:06:38 +0200822static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100823 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
824 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
825 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
826 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
827 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
828 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
829 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
830 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
831 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
832 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
833 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
834 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
835 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
836 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
837 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
838 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
839 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
840 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
841 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
842 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
843 { "single", 4, 0x14, STATS_TYPE_BANK0, },
844 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
845 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
846 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
847 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
848 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
849 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
850 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
851 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
852 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
853 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
854 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
855 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
856 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
857 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
858 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
859 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
860 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
861 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
862 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
863 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
864 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
865 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
866 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
867 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
868 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
869 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
870 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
871 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
872 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
873 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
874 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
875 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
876 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
877 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
878 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
879 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
880 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
881 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200882};
883
Vivien Didelotfad09c72016-06-21 12:28:20 -0400884static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100885 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100886 int port, u16 bank1_select,
887 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200888{
Andrew Lunn80c46272015-06-20 18:42:30 +0200889 u32 low;
890 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100891 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200892 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200893 u64 value;
894
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100895 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100896 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200897 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
898 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800899 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200900
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200901 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100902 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200903 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
904 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800905 return U64_MAX;
Rasmus Villemoes84b3fd12019-05-29 07:02:11 +0000906 low |= ((u32)reg) << 16;
Andrew Lunn80c46272015-06-20 18:42:30 +0200907 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100908 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100909 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100910 reg = bank1_select;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500911 fallthrough;
Andrew Lunndfafe442016-11-21 23:27:02 +0100912 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100913 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100914 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100915 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100916 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500917 break;
918 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800919 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200920 }
Andrew Lunn6e46e2d2019-02-28 18:14:03 +0100921 value = (((u64)high) << 32) | low;
Andrew Lunn80c46272015-06-20 18:42:30 +0200922 return value;
923}
924
Andrew Lunn436fe172018-03-01 02:02:29 +0100925static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
926 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100927{
928 struct mv88e6xxx_hw_stat *stat;
929 int i, j;
930
931 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
932 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100933 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100934 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
935 ETH_GSTRING_LEN);
936 j++;
937 }
938 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100939
940 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100941}
942
Andrew Lunn436fe172018-03-01 02:02:29 +0100943static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
944 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100945{
Andrew Lunn436fe172018-03-01 02:02:29 +0100946 return mv88e6xxx_stats_get_strings(chip, data,
947 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100948}
949
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000950static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
951 uint8_t *data)
952{
953 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
954}
955
Andrew Lunn436fe172018-03-01 02:02:29 +0100956static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
957 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100958{
Andrew Lunn436fe172018-03-01 02:02:29 +0100959 return mv88e6xxx_stats_get_strings(chip, data,
960 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100961}
962
Andrew Lunn65f60e42018-03-28 23:50:28 +0200963static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
964 "atu_member_violation",
965 "atu_miss_violation",
966 "atu_full_violation",
967 "vtu_member_violation",
968 "vtu_miss_violation",
969};
970
971static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
972{
973 unsigned int i;
974
975 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
976 strlcpy(data + i * ETH_GSTRING_LEN,
977 mv88e6xxx_atu_vtu_stats_strings[i],
978 ETH_GSTRING_LEN);
979}
980
Andrew Lunndfafe442016-11-21 23:27:02 +0100981static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700982 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100983{
Vivien Didelot04bed142016-08-31 18:06:13 -0400984 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100985 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100986
Florian Fainelli89f09042018-04-25 12:12:50 -0700987 if (stringset != ETH_SS_STATS)
988 return;
989
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000990 mv88e6xxx_reg_lock(chip);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100991
Andrew Lunndfafe442016-11-21 23:27:02 +0100992 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100993 count = chip->info->ops->stats_get_strings(chip, data);
994
995 if (chip->info->ops->serdes_get_strings) {
996 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200997 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100998 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100999
Andrew Lunn65f60e42018-03-28 23:50:28 +02001000 data += count * ETH_GSTRING_LEN;
1001 mv88e6xxx_atu_vtu_get_strings(data);
1002
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001003 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001004}
1005
1006static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
1007 int types)
1008{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001009 struct mv88e6xxx_hw_stat *stat;
1010 int i, j;
1011
1012 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1013 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +01001014 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001015 j++;
1016 }
1017 return j;
1018}
1019
Andrew Lunndfafe442016-11-21 23:27:02 +01001020static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1021{
1022 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1023 STATS_TYPE_PORT);
1024}
1025
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001026static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1027{
1028 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
1029}
1030
Andrew Lunndfafe442016-11-21 23:27:02 +01001031static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1032{
1033 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1034 STATS_TYPE_BANK1);
1035}
1036
Florian Fainelli89f09042018-04-25 12:12:50 -07001037static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +01001038{
1039 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +01001040 int serdes_count = 0;
1041 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +01001042
Florian Fainelli89f09042018-04-25 12:12:50 -07001043 if (sset != ETH_SS_STATS)
1044 return 0;
1045
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001046 mv88e6xxx_reg_lock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001047 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +01001048 count = chip->info->ops->stats_get_sset_count(chip);
1049 if (count < 0)
1050 goto out;
1051
1052 if (chip->info->ops->serdes_get_sset_count)
1053 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1054 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +02001055 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +01001056 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001057 goto out;
1058 }
1059 count += serdes_count;
1060 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1061
Andrew Lunn436fe172018-03-01 02:02:29 +01001062out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001063 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001064
Andrew Lunn436fe172018-03-01 02:02:29 +01001065 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +01001066}
1067
Andrew Lunn436fe172018-03-01 02:02:29 +01001068static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1069 uint64_t *data, int types,
1070 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +01001071{
1072 struct mv88e6xxx_hw_stat *stat;
1073 int i, j;
1074
1075 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1076 stat = &mv88e6xxx_hw_stats[i];
1077 if (stat->type & types) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001078 mv88e6xxx_reg_lock(chip);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001079 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1080 bank1_select,
1081 histogram);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001082 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001083
Andrew Lunn052f9472016-11-21 23:27:03 +01001084 j++;
1085 }
1086 }
Andrew Lunn436fe172018-03-01 02:02:29 +01001087 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +01001088}
1089
Andrew Lunn436fe172018-03-01 02:02:29 +01001090static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1091 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001092{
1093 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001094 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001095 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +01001096}
1097
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001098static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1099 uint64_t *data)
1100{
1101 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
1102 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1103}
1104
Andrew Lunn436fe172018-03-01 02:02:29 +01001105static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1106 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001107{
1108 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001109 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001110 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1111 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001112}
1113
Andrew Lunn436fe172018-03-01 02:02:29 +01001114static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1115 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +01001116{
1117 return mv88e6xxx_stats_get_stats(chip, port, data,
1118 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001119 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1120 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001121}
1122
Andrew Lunn65f60e42018-03-28 23:50:28 +02001123static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1124 uint64_t *data)
1125{
1126 *data++ = chip->ports[port].atu_member_violation;
1127 *data++ = chip->ports[port].atu_miss_violation;
1128 *data++ = chip->ports[port].atu_full_violation;
1129 *data++ = chip->ports[port].vtu_member_violation;
1130 *data++ = chip->ports[port].vtu_miss_violation;
1131}
1132
Andrew Lunn052f9472016-11-21 23:27:03 +01001133static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1134 uint64_t *data)
1135{
Andrew Lunn436fe172018-03-01 02:02:29 +01001136 int count = 0;
1137
Andrew Lunn052f9472016-11-21 23:27:03 +01001138 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +01001139 count = chip->info->ops->stats_get_stats(chip, port, data);
1140
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001141 mv88e6xxx_reg_lock(chip);
Andrew Lunn436fe172018-03-01 02:02:29 +01001142 if (chip->info->ops->serdes_get_stats) {
1143 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001144 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +01001145 }
Andrew Lunn65f60e42018-03-28 23:50:28 +02001146 data += count;
1147 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001148 mv88e6xxx_reg_unlock(chip);
Andrew Lunn052f9472016-11-21 23:27:03 +01001149}
1150
Vivien Didelotf81ec902016-05-09 13:22:58 -04001151static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1152 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001153{
Vivien Didelot04bed142016-08-31 18:06:13 -04001154 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001155 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001156
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001157 mv88e6xxx_reg_lock(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001158
Andrew Lunna605a0f2016-11-21 23:26:58 +01001159 ret = mv88e6xxx_stats_snapshot(chip, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001160 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001161
1162 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001163 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001164
1165 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001166
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001167}
Ben Hutchings98e67302011-11-25 14:36:19 +00001168
Vivien Didelotf81ec902016-05-09 13:22:58 -04001169static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001170{
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001171 struct mv88e6xxx_chip *chip = ds->priv;
1172 int len;
1173
1174 len = 32 * sizeof(u16);
1175 if (chip->info->ops->serdes_get_regs_len)
1176 len += chip->info->ops->serdes_get_regs_len(chip, port);
1177
1178 return len;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001179}
1180
Vivien Didelotf81ec902016-05-09 13:22:58 -04001181static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1182 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001183{
Vivien Didelot04bed142016-08-31 18:06:13 -04001184 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001185 int err;
1186 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001187 u16 *p = _p;
1188 int i;
1189
Vivien Didelota5f39322018-12-17 16:05:21 -05001190 regs->version = chip->info->prod_num;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001191
1192 memset(p, 0xff, 32 * sizeof(u16));
1193
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001194 mv88e6xxx_reg_lock(chip);
Vivien Didelot23062512016-05-09 13:22:45 -04001195
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001196 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001197
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001198 err = mv88e6xxx_port_read(chip, port, i, &reg);
1199 if (!err)
1200 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001201 }
Vivien Didelot23062512016-05-09 13:22:45 -04001202
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001203 if (chip->info->ops->serdes_get_regs)
1204 chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1205
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001206 mv88e6xxx_reg_unlock(chip);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001207}
1208
Vivien Didelot08f50062017-08-01 16:32:41 -04001209static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1210 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001211{
Vivien Didelot5480db62017-08-01 16:32:40 -04001212 /* Nothing to do on the port's MAC */
1213 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001214}
1215
Vivien Didelot08f50062017-08-01 16:32:41 -04001216static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1217 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001218{
Vivien Didelot5480db62017-08-01 16:32:40 -04001219 /* Nothing to do on the port's MAC */
1220 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001221}
1222
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001223/* Mask of the local ports allowed to receive frames from a given fabric port */
Vivien Didelote5887a22017-03-30 17:37:11 -04001224static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001225{
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001226 struct dsa_switch *ds = chip->ds;
1227 struct dsa_switch_tree *dst = ds->dst;
Vivien Didelote5887a22017-03-30 17:37:11 -04001228 struct net_device *br;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001229 struct dsa_port *dp;
1230 bool found = false;
Vivien Didelote5887a22017-03-30 17:37:11 -04001231 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001232
Vladimir Olteance5df682021-07-22 18:55:41 +03001233 /* dev is a physical switch */
1234 if (dev <= dst->last_switch) {
1235 list_for_each_entry(dp, &dst->ports, list) {
1236 if (dp->ds->index == dev && dp->index == port) {
1237 /* dp might be a DSA link or a user port, so it
1238 * might or might not have a bridge_dev
1239 * pointer. Use the "found" variable for both
1240 * cases.
1241 */
1242 br = dp->bridge_dev;
1243 found = true;
1244 break;
1245 }
1246 }
1247 /* dev is a virtual bridge */
1248 } else {
1249 list_for_each_entry(dp, &dst->ports, list) {
1250 if (dp->bridge_num < 0)
1251 continue;
1252
1253 if (dp->bridge_num + 1 + dst->last_switch != dev)
1254 continue;
1255
1256 br = dp->bridge_dev;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001257 found = true;
1258 break;
1259 }
1260 }
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001261
Vladimir Olteance5df682021-07-22 18:55:41 +03001262 /* Prevent frames from unknown switch or virtual bridge */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001263 if (!found)
Vivien Didelote5887a22017-03-30 17:37:11 -04001264 return 0;
1265
1266 /* Frames from DSA links and CPU ports can egress any local port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001267 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
Vivien Didelote5887a22017-03-30 17:37:11 -04001268 return mv88e6xxx_port_mask(chip);
1269
Vivien Didelote5887a22017-03-30 17:37:11 -04001270 pvlan = 0;
1271
1272 /* Frames from user ports can egress any local DSA links and CPU ports,
1273 * as well as any local member of their bridge group.
1274 */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001275 list_for_each_entry(dp, &dst->ports, list)
1276 if (dp->ds == ds &&
1277 (dp->type == DSA_PORT_TYPE_CPU ||
1278 dp->type == DSA_PORT_TYPE_DSA ||
1279 (br && dp->bridge_dev == br)))
1280 pvlan |= BIT(dp->index);
Vivien Didelote5887a22017-03-30 17:37:11 -04001281
1282 return pvlan;
1283}
1284
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001285static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001286{
1287 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001288
1289 /* prevent frames from going back out of the port they came in on */
1290 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001291
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001292 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001293}
1294
Vivien Didelotf81ec902016-05-09 13:22:58 -04001295static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1296 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001297{
Vivien Didelot04bed142016-08-31 18:06:13 -04001298 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001299 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001300
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001301 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001302 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001303 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001304
1305 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001306 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001307}
1308
Vivien Didelot93e18d62018-05-11 17:16:35 -04001309static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1310{
1311 int err;
1312
1313 if (chip->info->ops->ieee_pri_map) {
1314 err = chip->info->ops->ieee_pri_map(chip);
1315 if (err)
1316 return err;
1317 }
1318
1319 if (chip->info->ops->ip_pri_map) {
1320 err = chip->info->ops->ip_pri_map(chip);
1321 if (err)
1322 return err;
1323 }
1324
1325 return 0;
1326}
1327
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001328static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1329{
Vivien Didelotc5f51762019-10-30 22:09:13 -04001330 struct dsa_switch *ds = chip->ds;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001331 int target, port;
1332 int err;
1333
1334 if (!chip->info->global2_addr)
1335 return 0;
1336
1337 /* Initialize the routing port to the 32 possible target devices */
1338 for (target = 0; target < 32; target++) {
Vivien Didelotc5f51762019-10-30 22:09:13 -04001339 port = dsa_routing_port(ds, target);
1340 if (port == ds->num_ports)
1341 port = 0x1f;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001342
1343 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1344 if (err)
1345 return err;
1346 }
1347
Vivien Didelot02317e62018-05-09 11:38:49 -04001348 if (chip->info->ops->set_cascade_port) {
1349 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1350 err = chip->info->ops->set_cascade_port(chip, port);
1351 if (err)
1352 return err;
1353 }
1354
Vivien Didelot23c98912018-05-09 11:38:50 -04001355 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1356 if (err)
1357 return err;
1358
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001359 return 0;
1360}
1361
Vivien Didelotb28f8722018-04-26 21:56:44 -04001362static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1363{
1364 /* Clear all trunk masks and mapping */
1365 if (chip->info->global2_addr)
1366 return mv88e6xxx_g2_trunk_clear(chip);
1367
1368 return 0;
1369}
1370
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001371static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1372{
1373 if (chip->info->ops->rmu_disable)
1374 return chip->info->ops->rmu_disable(chip);
1375
1376 return 0;
1377}
1378
Vivien Didelot9e907d72017-07-17 13:03:43 -04001379static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1380{
1381 if (chip->info->ops->pot_clear)
1382 return chip->info->ops->pot_clear(chip);
1383
1384 return 0;
1385}
1386
Vivien Didelot51c901a2017-07-17 13:03:41 -04001387static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1388{
1389 if (chip->info->ops->mgmt_rsvd2cpu)
1390 return chip->info->ops->mgmt_rsvd2cpu(chip);
1391
1392 return 0;
1393}
1394
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001395static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1396{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001397 int err;
1398
Vivien Didelotdaefc942017-03-11 16:12:54 -05001399 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1400 if (err)
1401 return err;
1402
Rasmus Villemoes49506a92020-12-10 12:06:44 +01001403 /* The chips that have a "learn2all" bit in Global1, ATU
1404 * Control are precisely those whose port registers have a
1405 * Message Port bit in Port Control 1 and hence implement
1406 * ->port_setup_message_port.
1407 */
1408 if (chip->info->ops->port_setup_message_port) {
1409 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1410 if (err)
1411 return err;
1412 }
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001413
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001414 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1415}
1416
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001417static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1418{
1419 int port;
1420 int err;
1421
1422 if (!chip->info->ops->irl_init_all)
1423 return 0;
1424
1425 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1426 /* Disable ingress rate limiting by resetting all per port
1427 * ingress rate limit resources to their initial state.
1428 */
1429 err = chip->info->ops->irl_init_all(chip, port);
1430 if (err)
1431 return err;
1432 }
1433
1434 return 0;
1435}
1436
Vivien Didelot04a69a12017-10-13 14:18:05 -04001437static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1438{
1439 if (chip->info->ops->set_switch_mac) {
1440 u8 addr[ETH_ALEN];
1441
1442 eth_random_addr(addr);
1443
1444 return chip->info->ops->set_switch_mac(chip, addr);
1445 }
1446
1447 return 0;
1448}
1449
Vivien Didelot17a15942017-03-30 17:37:09 -04001450static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1451{
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001452 struct dsa_switch_tree *dst = chip->ds->dst;
1453 struct dsa_switch *ds;
1454 struct dsa_port *dp;
Vivien Didelot17a15942017-03-30 17:37:09 -04001455 u16 pvlan = 0;
1456
1457 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001458 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001459
1460 /* Skip the local source device, which uses in-chip port VLAN */
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001461 if (dev != chip->ds->index) {
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001462 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001463
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001464 ds = dsa_switch_find(dst->index, dev);
1465 dp = ds ? dsa_to_port(ds, port) : NULL;
1466 if (dp && dp->lag_dev) {
1467 /* As the PVT is used to limit flooding of
1468 * FORWARD frames, which use the LAG ID as the
1469 * source port, we must translate dev/port to
1470 * the special "LAG device" in the PVT, using
1471 * the LAG ID as the port number.
1472 */
Tobias Waldekranz78e70db2021-04-21 14:04:52 +02001473 dev = MV88E6XXX_G2_PVT_ADDR_DEV_TRUNK;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01001474 port = dsa_lag_id(dst, dp->lag_dev);
1475 }
1476 }
1477
Vivien Didelot17a15942017-03-30 17:37:09 -04001478 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1479}
1480
Vivien Didelot81228992017-03-30 17:37:08 -04001481static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1482{
Vivien Didelot17a15942017-03-30 17:37:09 -04001483 int dev, port;
1484 int err;
1485
Vivien Didelot81228992017-03-30 17:37:08 -04001486 if (!mv88e6xxx_has_pvt(chip))
1487 return 0;
1488
1489 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1490 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1491 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001492 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1493 if (err)
1494 return err;
1495
1496 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1497 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1498 err = mv88e6xxx_pvt_map(chip, dev, port);
1499 if (err)
1500 return err;
1501 }
1502 }
1503
1504 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001505}
1506
Vivien Didelot749efcb2016-09-22 16:49:24 -04001507static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1508{
1509 struct mv88e6xxx_chip *chip = ds->priv;
1510 int err;
1511
Tobias Waldekranzffcec3f2021-03-18 20:25:34 +01001512 if (dsa_to_port(ds, port)->lag_dev)
1513 /* Hardware is incapable of fast-aging a LAG through a
1514 * regular ATU move operation. Until we have something
1515 * more fancy in place this is a no-op.
1516 */
1517 return;
1518
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001519 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001520 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001521 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001522
1523 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001524 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001525}
1526
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001527static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1528{
Tobias Waldekranze545f862020-11-10 19:57:20 +01001529 if (!mv88e6xxx_max_vid(chip))
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001530 return 0;
1531
1532 return mv88e6xxx_g1_vtu_flush(chip);
1533}
1534
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001535static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1536 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotf1394b782017-05-01 14:05:22 -04001537{
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001538 int err;
1539
Vivien Didelotf1394b782017-05-01 14:05:22 -04001540 if (!chip->info->ops->vtu_getnext)
1541 return -EOPNOTSUPP;
1542
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001543 entry->vid = vid ? vid - 1 : mv88e6xxx_max_vid(chip);
1544 entry->valid = false;
1545
1546 err = chip->info->ops->vtu_getnext(chip, entry);
1547
1548 if (entry->vid != vid)
1549 entry->valid = false;
1550
1551 return err;
Vivien Didelotf1394b782017-05-01 14:05:22 -04001552}
1553
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001554static int mv88e6xxx_vtu_walk(struct mv88e6xxx_chip *chip,
1555 int (*cb)(struct mv88e6xxx_chip *chip,
1556 const struct mv88e6xxx_vtu_entry *entry,
1557 void *priv),
1558 void *priv)
1559{
1560 struct mv88e6xxx_vtu_entry entry = {
1561 .vid = mv88e6xxx_max_vid(chip),
1562 .valid = false,
1563 };
1564 int err;
1565
1566 if (!chip->info->ops->vtu_getnext)
1567 return -EOPNOTSUPP;
1568
1569 do {
1570 err = chip->info->ops->vtu_getnext(chip, &entry);
1571 if (err)
1572 return err;
1573
1574 if (!entry.valid)
1575 break;
1576
1577 err = cb(chip, &entry, priv);
1578 if (err)
1579 return err;
1580 } while (entry.vid < mv88e6xxx_max_vid(chip));
1581
1582 return 0;
1583}
1584
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001585static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1586 struct mv88e6xxx_vtu_entry *entry)
1587{
1588 if (!chip->info->ops->vtu_loadpurge)
1589 return -EOPNOTSUPP;
1590
1591 return chip->info->ops->vtu_loadpurge(chip, entry);
1592}
1593
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001594static int mv88e6xxx_fid_map_vlan(struct mv88e6xxx_chip *chip,
1595 const struct mv88e6xxx_vtu_entry *entry,
1596 void *_fid_bitmap)
1597{
1598 unsigned long *fid_bitmap = _fid_bitmap;
1599
1600 set_bit(entry->fid, fid_bitmap);
1601 return 0;
1602}
1603
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001604int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001605{
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001606 int i, err;
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001607 u16 fid;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001608
1609 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1610
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001611 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001612 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001613 err = mv88e6xxx_port_get_fid(chip, i, &fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001614 if (err)
1615 return err;
1616
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001617 set_bit(fid, fid_bitmap);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001618 }
1619
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001620 /* Set every FID bit used by the VLAN entries */
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01001621 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_fid_map_vlan, fid_bitmap);
Andrew Lunn90b6dbd2020-09-18 21:11:06 +02001622}
1623
1624static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
1625{
1626 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1627 int err;
1628
1629 err = mv88e6xxx_fid_map(chip, fid_bitmap);
1630 if (err)
1631 return err;
1632
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001633 /* The reset value 0x000 is used to indicate that multiple address
1634 * databases are not needed. Return the next positive available.
1635 */
1636 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001637 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001638 return -ENOSPC;
1639
1640 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001641 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001642}
1643
Vivien Didelotda9c3592016-02-12 12:09:40 -05001644static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001645 u16 vid)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001646{
Vivien Didelot04bed142016-08-31 18:06:13 -04001647 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001648 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001649 int i, err;
1650
Andrew Lunndb06ae412017-09-25 23:32:20 +02001651 /* DSA and CPU ports have to be members of multiple vlans */
1652 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1653 return 0;
1654
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001655 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001656 if (err)
1657 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001658
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001659 if (!vlan.valid)
1660 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001661
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001662 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1663 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1664 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001665
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001666 if (!dsa_to_port(ds, i)->slave)
1667 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001668
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001669 if (vlan.member[i] ==
1670 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1671 continue;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001672
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001673 if (dsa_to_port(ds, i)->bridge_dev ==
1674 dsa_to_port(ds, port)->bridge_dev)
1675 break; /* same bridge, check next VLAN */
Vivien Didelotda9c3592016-02-12 12:09:40 -05001676
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001677 if (!dsa_to_port(ds, i)->bridge_dev)
1678 continue;
Andrew Lunn66e28092016-12-11 21:07:19 +01001679
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001680 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1681 port, vlan.vid, i,
1682 netdev_name(dsa_to_port(ds, i)->bridge_dev));
1683 return -EOPNOTSUPP;
1684 }
Vivien Didelotda9c3592016-02-12 12:09:40 -05001685
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001686 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001687}
1688
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001689static int mv88e6xxx_port_commit_pvid(struct mv88e6xxx_chip *chip, int port)
1690{
1691 struct dsa_port *dp = dsa_to_port(chip->ds, port);
1692 struct mv88e6xxx_port *p = &chip->ports[port];
Vladimir Oltean5bded822021-10-07 19:47:11 +03001693 u16 pvid = MV88E6XXX_VID_STANDALONE;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001694 bool drop_untagged = false;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001695 int err;
1696
Vladimir Oltean5bded822021-10-07 19:47:11 +03001697 if (dp->bridge_dev) {
1698 if (br_vlan_enabled(dp->bridge_dev)) {
1699 pvid = p->bridge_pvid.vid;
1700 drop_untagged = !p->bridge_pvid.valid;
1701 } else {
1702 pvid = MV88E6XXX_VID_BRIDGED;
1703 }
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001704 }
1705
1706 err = mv88e6xxx_port_set_pvid(chip, port, pvid);
1707 if (err)
1708 return err;
1709
1710 return mv88e6xxx_port_drop_untagged(chip, port, drop_untagged);
1711}
1712
Vivien Didelotf81ec902016-05-09 13:22:58 -04001713static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
Vladimir Oltean89153ed2021-02-13 22:43:19 +02001714 bool vlan_filtering,
1715 struct netlink_ext_ack *extack)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001716{
Vivien Didelot04bed142016-08-31 18:06:13 -04001717 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001718 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1719 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001720 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001721
Vladimir Olteanbae33f22021-01-09 02:01:50 +02001722 if (!mv88e6xxx_max_vid(chip))
1723 return -EOPNOTSUPP;
Vivien Didelot54d77b52016-05-09 13:22:47 -04001724
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001725 mv88e6xxx_reg_lock(chip);
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001726
Vivien Didelot385a0992016-11-04 03:23:31 +01001727 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03001728 if (err)
1729 goto unlock;
1730
1731 err = mv88e6xxx_port_commit_pvid(chip, port);
1732 if (err)
1733 goto unlock;
1734
1735unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001736 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001737
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001738 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001739}
1740
Vivien Didelot57d32312016-06-20 13:13:58 -04001741static int
1742mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001743 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001744{
Vivien Didelot04bed142016-08-31 18:06:13 -04001745 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001746 int err;
1747
Tobias Waldekranze545f862020-11-10 19:57:20 +01001748 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001749 return -EOPNOTSUPP;
1750
Vivien Didelotda9c3592016-02-12 12:09:40 -05001751 /* If the requested port doesn't belong to the same bridge as the VLAN
1752 * members, do not support it (yet) and fallback to software VLAN.
1753 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001754 mv88e6xxx_reg_lock(chip);
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001755 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001756 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001757
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001758 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001759}
1760
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001761static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1762 const unsigned char *addr, u16 vid,
1763 u8 state)
1764{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001765 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001766 struct mv88e6xxx_vtu_entry vlan;
1767 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001768 int err;
1769
Vladimir Oltean5bded822021-10-07 19:47:11 +03001770 /* Ports have two private address databases: one for when the port is
1771 * standalone and one for when the port is under a bridge and the
1772 * 802.1Q mode is disabled. When the port is standalone, DSA wants its
1773 * address database to remain 100% empty, so we never load an ATU entry
1774 * into a standalone port's database. Therefore, translate the null
1775 * VLAN ID into the port's database used for VLAN-unaware bridging.
1776 */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001777 if (vid == 0) {
Vladimir Oltean5bded822021-10-07 19:47:11 +03001778 fid = MV88E6XXX_FID_BRIDGED;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001779 } else {
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001780 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001781 if (err)
1782 return err;
1783
1784 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
Tobias Waldekranz34065c52021-03-18 20:25:36 +01001785 if (!vlan.valid)
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001786 return -EOPNOTSUPP;
1787
1788 fid = vlan.fid;
1789 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001790
Vivien Didelotd8291a92019-09-07 16:00:47 -04001791 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001792 ether_addr_copy(entry.mac, addr);
1793 eth_addr_dec(entry.mac);
1794
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001795 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001796 if (err)
1797 return err;
1798
1799 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001800 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001801 memset(&entry, 0, sizeof(entry));
1802 ether_addr_copy(entry.mac, addr);
1803 }
1804
1805 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001806 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001807 entry.portvec &= ~BIT(port);
1808 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001809 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001810 } else {
DENG Qingfangf72f2fb2021-01-30 21:43:34 +08001811 if (state == MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC)
1812 entry.portvec = BIT(port);
1813 else
1814 entry.portvec |= BIT(port);
1815
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001816 entry.state = state;
1817 }
1818
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001819 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001820}
1821
Vivien Didelotda7dc872019-09-07 16:00:49 -04001822static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1823 const struct mv88e6xxx_policy *policy)
1824{
1825 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1826 enum mv88e6xxx_policy_action action = policy->action;
1827 const u8 *addr = policy->addr;
1828 u16 vid = policy->vid;
1829 u8 state;
1830 int err;
1831 int id;
1832
1833 if (!chip->info->ops->port_set_policy)
1834 return -EOPNOTSUPP;
1835
1836 switch (mapping) {
1837 case MV88E6XXX_POLICY_MAPPING_DA:
1838 case MV88E6XXX_POLICY_MAPPING_SA:
1839 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1840 state = 0; /* Dissociate the port and address */
1841 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1842 is_multicast_ether_addr(addr))
1843 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1844 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1845 is_unicast_ether_addr(addr))
1846 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1847 else
1848 return -EOPNOTSUPP;
1849
1850 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1851 state);
1852 if (err)
1853 return err;
1854 break;
1855 default:
1856 return -EOPNOTSUPP;
1857 }
1858
1859 /* Skip the port's policy clearing if the mapping is still in use */
1860 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1861 idr_for_each_entry(&chip->policies, policy, id)
1862 if (policy->port == port &&
1863 policy->mapping == mapping &&
1864 policy->action != action)
1865 return 0;
1866
1867 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1868}
1869
1870static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1871 struct ethtool_rx_flow_spec *fs)
1872{
1873 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1874 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1875 enum mv88e6xxx_policy_mapping mapping;
1876 enum mv88e6xxx_policy_action action;
1877 struct mv88e6xxx_policy *policy;
1878 u16 vid = 0;
1879 u8 *addr;
1880 int err;
1881 int id;
1882
1883 if (fs->location != RX_CLS_LOC_ANY)
1884 return -EINVAL;
1885
1886 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1887 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1888 else
1889 return -EOPNOTSUPP;
1890
1891 switch (fs->flow_type & ~FLOW_EXT) {
1892 case ETHER_FLOW:
1893 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1894 is_zero_ether_addr(mac_mask->h_source)) {
1895 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1896 addr = mac_entry->h_dest;
1897 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1898 !is_zero_ether_addr(mac_mask->h_source)) {
1899 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1900 addr = mac_entry->h_source;
1901 } else {
1902 /* Cannot support DA and SA mapping in the same rule */
1903 return -EOPNOTSUPP;
1904 }
1905 break;
1906 default:
1907 return -EOPNOTSUPP;
1908 }
1909
1910 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001911 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001912 return -EOPNOTSUPP;
1913 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1914 }
1915
1916 idr_for_each_entry(&chip->policies, policy, id) {
1917 if (policy->port == port && policy->mapping == mapping &&
1918 policy->action == action && policy->vid == vid &&
1919 ether_addr_equal(policy->addr, addr))
1920 return -EEXIST;
1921 }
1922
1923 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1924 if (!policy)
1925 return -ENOMEM;
1926
1927 fs->location = 0;
1928 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1929 GFP_KERNEL);
1930 if (err) {
1931 devm_kfree(chip->dev, policy);
1932 return err;
1933 }
1934
1935 memcpy(&policy->fs, fs, sizeof(*fs));
1936 ether_addr_copy(policy->addr, addr);
1937 policy->mapping = mapping;
1938 policy->action = action;
1939 policy->port = port;
1940 policy->vid = vid;
1941
1942 err = mv88e6xxx_policy_apply(chip, port, policy);
1943 if (err) {
1944 idr_remove(&chip->policies, fs->location);
1945 devm_kfree(chip->dev, policy);
1946 return err;
1947 }
1948
1949 return 0;
1950}
1951
1952static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1953 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1954{
1955 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1956 struct mv88e6xxx_chip *chip = ds->priv;
1957 struct mv88e6xxx_policy *policy;
1958 int err;
1959 int id;
1960
1961 mv88e6xxx_reg_lock(chip);
1962
1963 switch (rxnfc->cmd) {
1964 case ETHTOOL_GRXCLSRLCNT:
1965 rxnfc->data = 0;
1966 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1967 rxnfc->rule_cnt = 0;
1968 idr_for_each_entry(&chip->policies, policy, id)
1969 if (policy->port == port)
1970 rxnfc->rule_cnt++;
1971 err = 0;
1972 break;
1973 case ETHTOOL_GRXCLSRULE:
1974 err = -ENOENT;
1975 policy = idr_find(&chip->policies, fs->location);
1976 if (policy) {
1977 memcpy(fs, &policy->fs, sizeof(*fs));
1978 err = 0;
1979 }
1980 break;
1981 case ETHTOOL_GRXCLSRLALL:
1982 rxnfc->data = 0;
1983 rxnfc->rule_cnt = 0;
1984 idr_for_each_entry(&chip->policies, policy, id)
1985 if (policy->port == port)
1986 rule_locs[rxnfc->rule_cnt++] = id;
1987 err = 0;
1988 break;
1989 default:
1990 err = -EOPNOTSUPP;
1991 break;
1992 }
1993
1994 mv88e6xxx_reg_unlock(chip);
1995
1996 return err;
1997}
1998
1999static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
2000 struct ethtool_rxnfc *rxnfc)
2001{
2002 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
2003 struct mv88e6xxx_chip *chip = ds->priv;
2004 struct mv88e6xxx_policy *policy;
2005 int err;
2006
2007 mv88e6xxx_reg_lock(chip);
2008
2009 switch (rxnfc->cmd) {
2010 case ETHTOOL_SRXCLSRLINS:
2011 err = mv88e6xxx_policy_insert(chip, port, fs);
2012 break;
2013 case ETHTOOL_SRXCLSRLDEL:
2014 err = -ENOENT;
2015 policy = idr_remove(&chip->policies, fs->location);
2016 if (policy) {
2017 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
2018 err = mv88e6xxx_policy_apply(chip, port, policy);
2019 devm_kfree(chip->dev, policy);
2020 }
2021 break;
2022 default:
2023 err = -EOPNOTSUPP;
2024 break;
2025 }
2026
2027 mv88e6xxx_reg_unlock(chip);
2028
2029 return err;
2030}
2031
Andrew Lunn87fa8862017-11-09 22:29:56 +01002032static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
2033 u16 vid)
2034{
Andrew Lunn87fa8862017-11-09 22:29:56 +01002035 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
Tobias Waldekranz0806dd462021-03-18 20:25:37 +01002036 u8 broadcast[ETH_ALEN];
2037
2038 eth_broadcast_addr(broadcast);
Andrew Lunn87fa8862017-11-09 22:29:56 +01002039
2040 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
2041}
2042
2043static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
2044{
2045 int port;
2046 int err;
2047
2048 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01002049 struct dsa_port *dp = dsa_to_port(chip->ds, port);
2050 struct net_device *brport;
2051
2052 if (dsa_is_unused_port(chip->ds, port))
2053 continue;
2054
2055 brport = dsa_port_to_bridge_port(dp);
2056 if (brport && !br_port_flag_is_set(brport, BR_BCAST_FLOOD))
2057 /* Skip bridged user ports where broadcast
2058 * flooding is disabled.
2059 */
2060 continue;
2061
Andrew Lunn87fa8862017-11-09 22:29:56 +01002062 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
2063 if (err)
2064 return err;
2065 }
2066
2067 return 0;
2068}
2069
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01002070struct mv88e6xxx_port_broadcast_sync_ctx {
2071 int port;
2072 bool flood;
2073};
2074
2075static int
2076mv88e6xxx_port_broadcast_sync_vlan(struct mv88e6xxx_chip *chip,
2077 const struct mv88e6xxx_vtu_entry *vlan,
2078 void *_ctx)
2079{
2080 struct mv88e6xxx_port_broadcast_sync_ctx *ctx = _ctx;
2081 u8 broadcast[ETH_ALEN];
2082 u8 state;
2083
2084 if (ctx->flood)
2085 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
2086 else
2087 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_UNUSED;
2088
2089 eth_broadcast_addr(broadcast);
2090
2091 return mv88e6xxx_port_db_load_purge(chip, ctx->port, broadcast,
2092 vlan->vid, state);
2093}
2094
2095static int mv88e6xxx_port_broadcast_sync(struct mv88e6xxx_chip *chip, int port,
2096 bool flood)
2097{
2098 struct mv88e6xxx_port_broadcast_sync_ctx ctx = {
2099 .port = port,
2100 .flood = flood,
2101 };
2102 struct mv88e6xxx_vtu_entry vid0 = {
2103 .vid = 0,
2104 };
2105 int err;
2106
2107 /* Update the port's private database... */
2108 err = mv88e6xxx_port_broadcast_sync_vlan(chip, &vid0, &ctx);
2109 if (err)
2110 return err;
2111
2112 /* ...and the database for all VLANs. */
2113 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_broadcast_sync_vlan,
2114 &ctx);
2115}
2116
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002117static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00002118 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002119{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002120 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002121 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002122 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002123
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002124 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002125 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002126 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002127
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002128 if (!vlan.valid) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002129 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002130
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002131 err = mv88e6xxx_atu_new(chip, &vlan.fid);
2132 if (err)
2133 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01002134
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002135 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
2136 if (i == port)
2137 vlan.member[i] = member;
2138 else
2139 vlan.member[i] = non_member;
2140
2141 vlan.vid = vid;
2142 vlan.valid = true;
2143
2144 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2145 if (err)
2146 return err;
2147
2148 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
2149 if (err)
2150 return err;
2151 } else if (vlan.member[port] != member) {
2152 vlan.member[port] = member;
2153
2154 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
2155 if (err)
2156 return err;
Russell King933b4422020-02-26 17:14:26 +00002157 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04002158 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
2159 port, vid);
2160 }
2161
2162 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002163}
2164
Vladimir Oltean1958d582021-01-09 02:01:53 +02002165static int mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vladimir Oltean31046a52021-02-13 22:43:18 +02002166 const struct switchdev_obj_port_vlan *vlan,
2167 struct netlink_ext_ack *extack)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002168{
Vivien Didelot04bed142016-08-31 18:06:13 -04002169 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002170 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
2171 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002172 struct mv88e6xxx_port *p = &chip->ports[port];
Russell King933b4422020-02-26 17:14:26 +00002173 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002174 u8 member;
Vladimir Oltean1958d582021-01-09 02:01:53 +02002175 int err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002176
Eldar Gasanovb8b79c42021-06-21 11:54:38 +03002177 if (!vlan->vid)
2178 return 0;
2179
Vladimir Oltean1958d582021-01-09 02:01:53 +02002180 err = mv88e6xxx_port_vlan_prepare(ds, port, vlan);
2181 if (err)
2182 return err;
Vivien Didelot54d77b52016-05-09 13:22:47 -04002183
Vivien Didelotc91498e2017-06-07 18:12:13 -04002184 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002185 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002186 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002187 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002188 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002189 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04002190
Russell King933b4422020-02-26 17:14:26 +00002191 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
2192 * and then the CPU port. Do not warn for duplicates for the CPU port.
2193 */
2194 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
2195
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002196 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002197
Vladimir Oltean1958d582021-01-09 02:01:53 +02002198 err = mv88e6xxx_port_vlan_join(chip, port, vlan->vid, member, warn);
2199 if (err) {
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002200 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2201 vlan->vid, untagged ? 'u' : 't');
Vladimir Oltean1958d582021-01-09 02:01:53 +02002202 goto out;
2203 }
Vivien Didelot76e398a2015-11-01 12:33:55 -05002204
Vladimir Oltean1958d582021-01-09 02:01:53 +02002205 if (pvid) {
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002206 p->bridge_pvid.vid = vlan->vid;
2207 p->bridge_pvid.valid = true;
2208
2209 err = mv88e6xxx_port_commit_pvid(chip, port);
2210 if (err)
Vladimir Oltean1958d582021-01-09 02:01:53 +02002211 goto out;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002212 } else if (vlan->vid && p->bridge_pvid.vid == vlan->vid) {
2213 /* The old pvid was reinstalled as a non-pvid VLAN */
2214 p->bridge_pvid.valid = false;
2215
2216 err = mv88e6xxx_port_commit_pvid(chip, port);
2217 if (err)
2218 goto out;
Vladimir Oltean1958d582021-01-09 02:01:53 +02002219 }
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002220
Vladimir Oltean1958d582021-01-09 02:01:53 +02002221out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002222 mv88e6xxx_reg_unlock(chip);
Vladimir Oltean1958d582021-01-09 02:01:53 +02002223
2224 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002225}
2226
Vivien Didelot521098922019-08-01 14:36:36 -04002227static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2228 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002229{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002230 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002231 int i, err;
2232
Vivien Didelot521098922019-08-01 14:36:36 -04002233 if (!vid)
Vladimir Olteanc92c7412021-07-22 16:05:51 +03002234 return 0;
Vivien Didelot521098922019-08-01 14:36:36 -04002235
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002236 err = mv88e6xxx_vtu_get(chip, vid, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002237 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002238 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002239
Vivien Didelot521098922019-08-01 14:36:36 -04002240 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2241 * tell switchdev that this VLAN is likely handled in software.
2242 */
Tobias Waldekranz34065c52021-03-18 20:25:36 +01002243 if (!vlan.valid ||
Vivien Didelot521098922019-08-01 14:36:36 -04002244 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002245 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002246
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002247 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002248
2249 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002250 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002251 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002252 if (vlan.member[i] !=
2253 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002254 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002255 break;
2256 }
2257 }
2258
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002259 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002260 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002261 return err;
2262
Vivien Didelote606ca32017-03-11 16:12:55 -05002263 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002264}
2265
Vivien Didelotf81ec902016-05-09 13:22:58 -04002266static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2267 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002268{
Vivien Didelot04bed142016-08-31 18:06:13 -04002269 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002270 struct mv88e6xxx_port *p = &chip->ports[port];
Vivien Didelot76e398a2015-11-01 12:33:55 -05002271 int err = 0;
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002272 u16 pvid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002273
Tobias Waldekranze545f862020-11-10 19:57:20 +01002274 if (!mv88e6xxx_max_vid(chip))
Vivien Didelot54d77b52016-05-09 13:22:47 -04002275 return -EOPNOTSUPP;
2276
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002277 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002278
Vivien Didelot77064f32016-11-04 03:23:30 +01002279 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002280 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002281 goto unlock;
2282
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02002283 err = mv88e6xxx_port_vlan_leave(chip, port, vlan->vid);
2284 if (err)
2285 goto unlock;
2286
2287 if (vlan->vid == pvid) {
Vladimir Oltean8b6836d2021-10-07 19:47:10 +03002288 p->bridge_pvid.valid = false;
2289
2290 err = mv88e6xxx_port_commit_pvid(chip, port);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002291 if (err)
2292 goto unlock;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002293 }
2294
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002295unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002296 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002297
2298 return err;
2299}
2300
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002301static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2302 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002303{
Vivien Didelot04bed142016-08-31 18:06:13 -04002304 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002305 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002306
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002307 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002308 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2309 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002310 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002311
2312 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002313}
2314
Vivien Didelotf81ec902016-05-09 13:22:58 -04002315static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002316 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002317{
Vivien Didelot04bed142016-08-31 18:06:13 -04002318 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002319 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002320
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002321 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002322 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002323 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002324
Vivien Didelot83dabd12016-08-31 11:50:04 -04002325 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002326}
2327
Vivien Didelot83dabd12016-08-31 11:50:04 -04002328static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2329 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002330 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002331{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002332 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002333 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002334 int err;
2335
Vivien Didelotd8291a92019-09-07 16:00:47 -04002336 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002337 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002338
2339 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002340 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002341 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002342 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002343
Vivien Didelotd8291a92019-09-07 16:00:47 -04002344 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002345 break;
2346
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002347 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002348 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002349
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002350 if (!is_unicast_ether_addr(addr.mac))
2351 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002352
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002353 is_static = (addr.state ==
2354 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2355 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002356 if (err)
2357 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002358 } while (!is_broadcast_ether_addr(addr.mac));
2359
2360 return err;
2361}
2362
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002363struct mv88e6xxx_port_db_dump_vlan_ctx {
2364 int port;
2365 dsa_fdb_dump_cb_t *cb;
2366 void *data;
2367};
2368
2369static int mv88e6xxx_port_db_dump_vlan(struct mv88e6xxx_chip *chip,
2370 const struct mv88e6xxx_vtu_entry *entry,
2371 void *_data)
2372{
2373 struct mv88e6xxx_port_db_dump_vlan_ctx *ctx = _data;
2374
2375 return mv88e6xxx_port_db_dump_fid(chip, entry->fid, entry->vid,
2376 ctx->port, ctx->cb, ctx->data);
2377}
2378
Vivien Didelot83dabd12016-08-31 11:50:04 -04002379static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002380 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002381{
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002382 struct mv88e6xxx_port_db_dump_vlan_ctx ctx = {
2383 .port = port,
2384 .cb = cb,
2385 .data = data,
2386 };
Vivien Didelot83dabd12016-08-31 11:50:04 -04002387 u16 fid;
2388 int err;
2389
2390 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002391 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002392 if (err)
2393 return err;
2394
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002395 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002396 if (err)
2397 return err;
2398
Tobias Waldekranzd89ef4b2021-03-18 20:25:35 +01002399 return mv88e6xxx_vtu_walk(chip, mv88e6xxx_port_db_dump_vlan, &ctx);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002400}
2401
Vivien Didelotf81ec902016-05-09 13:22:58 -04002402static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002403 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002404{
Vivien Didelot04bed142016-08-31 18:06:13 -04002405 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002406 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002407
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002408 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002409 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002410 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002411
2412 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002413}
2414
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002415static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2416 struct net_device *br)
2417{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002418 struct dsa_switch *ds = chip->ds;
2419 struct dsa_switch_tree *dst = ds->dst;
2420 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002421 int err;
2422
Vivien Didelotef2025e2019-10-21 16:51:27 -04002423 list_for_each_entry(dp, &dst->ports, list) {
2424 if (dp->bridge_dev == br) {
2425 if (dp->ds == ds) {
2426 /* This is a local bridge group member,
2427 * remap its Port VLAN Map.
2428 */
2429 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2430 if (err)
2431 return err;
2432 } else {
2433 /* This is an external bridge group member,
2434 * remap its cross-chip Port VLAN Table entry.
2435 */
2436 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2437 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002438 if (err)
2439 return err;
2440 }
2441 }
2442 }
2443
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002444 return 0;
2445}
2446
Vivien Didelotf81ec902016-05-09 13:22:58 -04002447static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002448 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002449{
Vivien Didelot04bed142016-08-31 18:06:13 -04002450 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002451 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002452
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002453 mv88e6xxx_reg_lock(chip);
Vladimir Oltean5bded822021-10-07 19:47:11 +03002454
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002455 err = mv88e6xxx_bridge_map(chip, br);
Vladimir Oltean5bded822021-10-07 19:47:11 +03002456 if (err)
2457 goto unlock;
2458
2459 err = mv88e6xxx_port_commit_pvid(chip, port);
2460 if (err)
2461 goto unlock;
2462
2463unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002464 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002465
Vivien Didelot466dfa02016-02-26 13:16:05 -05002466 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002467}
2468
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002469static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2470 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002471{
Vivien Didelot04bed142016-08-31 18:06:13 -04002472 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Oltean5bded822021-10-07 19:47:11 +03002473 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002474
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002475 mv88e6xxx_reg_lock(chip);
Vladimir Oltean5bded822021-10-07 19:47:11 +03002476
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002477 if (mv88e6xxx_bridge_map(chip, br) ||
2478 mv88e6xxx_port_vlan_map(chip, port))
2479 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vladimir Oltean5bded822021-10-07 19:47:11 +03002480
2481 err = mv88e6xxx_port_commit_pvid(chip, port);
2482 if (err)
2483 dev_err(ds->dev,
2484 "port %d failed to restore standalone pvid: %pe\n",
2485 port, ERR_PTR(err));
2486
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002487 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002488}
2489
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002490static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2491 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002492 int port, struct net_device *br)
2493{
2494 struct mv88e6xxx_chip *chip = ds->priv;
2495 int err;
2496
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002497 if (tree_index != ds->dst->index)
2498 return 0;
2499
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002500 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002501 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002502 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002503
2504 return err;
2505}
2506
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002507static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2508 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002509 int port, struct net_device *br)
2510{
2511 struct mv88e6xxx_chip *chip = ds->priv;
2512
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002513 if (tree_index != ds->dst->index)
2514 return;
2515
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002516 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002517 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002518 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002519 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002520}
2521
Vladimir Olteance5df682021-07-22 18:55:41 +03002522/* Treat the software bridge as a virtual single-port switch behind the
2523 * CPU and map in the PVT. First dst->last_switch elements are taken by
2524 * physical switches, so start from beyond that range.
2525 */
2526static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds,
2527 int bridge_num)
2528{
2529 u8 dev = bridge_num + ds->dst->last_switch + 1;
2530 struct mv88e6xxx_chip *chip = ds->priv;
2531 int err;
2532
2533 mv88e6xxx_reg_lock(chip);
2534 err = mv88e6xxx_pvt_map(chip, dev, 0);
2535 mv88e6xxx_reg_unlock(chip);
2536
2537 return err;
2538}
2539
2540static int mv88e6xxx_bridge_tx_fwd_offload(struct dsa_switch *ds, int port,
2541 struct net_device *br,
2542 int bridge_num)
2543{
2544 return mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
2545}
2546
2547static void mv88e6xxx_bridge_tx_fwd_unoffload(struct dsa_switch *ds, int port,
2548 struct net_device *br,
2549 int bridge_num)
2550{
2551 int err;
2552
2553 err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num);
2554 if (err) {
2555 dev_err(ds->dev, "failed to remap cross-chip Port VLAN: %pe\n",
2556 ERR_PTR(err));
2557 }
2558}
2559
Vivien Didelot17e708b2016-12-05 17:30:27 -05002560static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2561{
2562 if (chip->info->ops->reset)
2563 return chip->info->ops->reset(chip);
2564
2565 return 0;
2566}
2567
Vivien Didelot309eca62016-12-05 17:30:26 -05002568static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2569{
2570 struct gpio_desc *gpiod = chip->reset;
2571
2572 /* If there is a GPIO connected to the reset pin, toggle it */
2573 if (gpiod) {
2574 gpiod_set_value_cansleep(gpiod, 1);
2575 usleep_range(10000, 20000);
2576 gpiod_set_value_cansleep(gpiod, 0);
2577 usleep_range(10000, 20000);
Andrew Lunna3dcb3e2020-11-16 08:43:01 -08002578
2579 mv88e6xxx_g1_wait_eeprom_done(chip);
Vivien Didelot309eca62016-12-05 17:30:26 -05002580 }
2581}
2582
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002583static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2584{
2585 int i, err;
2586
2587 /* Set all ports to the Disabled state */
2588 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002589 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002590 if (err)
2591 return err;
2592 }
2593
2594 /* Wait for transmit queues to drain,
2595 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2596 */
2597 usleep_range(2000, 4000);
2598
2599 return 0;
2600}
2601
Vivien Didelotfad09c72016-06-21 12:28:20 -04002602static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002603{
Vivien Didelota935c052016-09-29 12:21:53 -04002604 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002605
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002606 err = mv88e6xxx_disable_ports(chip);
2607 if (err)
2608 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002609
Vivien Didelot309eca62016-12-05 17:30:26 -05002610 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002611
Vivien Didelot17e708b2016-12-05 17:30:27 -05002612 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002613}
2614
Vivien Didelot43145572017-03-11 16:12:59 -05002615static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002616 enum mv88e6xxx_frame_mode frame,
2617 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002618{
2619 int err;
2620
Vivien Didelot43145572017-03-11 16:12:59 -05002621 if (!chip->info->ops->port_set_frame_mode)
2622 return -EOPNOTSUPP;
2623
2624 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002625 if (err)
2626 return err;
2627
Vivien Didelot43145572017-03-11 16:12:59 -05002628 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2629 if (err)
2630 return err;
2631
2632 if (chip->info->ops->port_set_ether_type)
2633 return chip->info->ops->port_set_ether_type(chip, port, etype);
2634
2635 return 0;
2636}
2637
2638static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2639{
2640 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002641 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002642 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002643}
2644
2645static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2646{
2647 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002648 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002649 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002650}
2651
2652static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2653{
2654 return mv88e6xxx_set_port_mode(chip, port,
2655 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002656 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2657 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002658}
2659
2660static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2661{
2662 if (dsa_is_dsa_port(chip->ds, port))
2663 return mv88e6xxx_set_port_mode_dsa(chip, port);
2664
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002665 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002666 return mv88e6xxx_set_port_mode_normal(chip, port);
2667
2668 /* Setup CPU port mode depending on its supported tag format */
Tobias Waldekranz670bb802021-04-20 20:53:07 +02002669 if (chip->tag_protocol == DSA_TAG_PROTO_DSA)
Vivien Didelot43145572017-03-11 16:12:59 -05002670 return mv88e6xxx_set_port_mode_dsa(chip, port);
2671
Tobias Waldekranz670bb802021-04-20 20:53:07 +02002672 if (chip->tag_protocol == DSA_TAG_PROTO_EDSA)
Vivien Didelot43145572017-03-11 16:12:59 -05002673 return mv88e6xxx_set_port_mode_edsa(chip, port);
2674
2675 return -EINVAL;
2676}
2677
Vivien Didelotea698f42017-03-11 16:12:50 -05002678static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2679{
2680 bool message = dsa_is_dsa_port(chip->ds, port);
2681
2682 return mv88e6xxx_port_set_message_port(chip, port, message);
2683}
2684
Vivien Didelot601aeed2017-03-11 16:13:00 -05002685static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2686{
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002687 int err;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002688
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002689 if (chip->info->ops->port_set_ucast_flood) {
Tobias Waldekranz7b9f16f2021-03-18 20:25:38 +01002690 err = chip->info->ops->port_set_ucast_flood(chip, port, true);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002691 if (err)
2692 return err;
2693 }
2694 if (chip->info->ops->port_set_mcast_flood) {
Tobias Waldekranz7b9f16f2021-03-18 20:25:38 +01002695 err = chip->info->ops->port_set_mcast_flood(chip, port, true);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02002696 if (err)
2697 return err;
2698 }
Vivien Didelot601aeed2017-03-11 16:13:00 -05002699
David S. Miller407308f2019-06-15 13:35:29 -07002700 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002701}
2702
Vivien Didelot45de77f2019-08-31 16:18:36 -04002703static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2704{
2705 struct mv88e6xxx_port *mvp = dev_id;
2706 struct mv88e6xxx_chip *chip = mvp->chip;
2707 irqreturn_t ret = IRQ_NONE;
2708 int port = mvp->port;
Pavana Sharma193c5b22021-03-17 14:46:40 +01002709 int lane;
Vivien Didelot45de77f2019-08-31 16:18:36 -04002710
2711 mv88e6xxx_reg_lock(chip);
2712 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002713 if (lane >= 0)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002714 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2715 mv88e6xxx_reg_unlock(chip);
2716
2717 return ret;
2718}
2719
2720static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002721 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002722{
2723 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2724 unsigned int irq;
2725 int err;
2726
2727 /* Nothing to request if this SERDES port has no IRQ */
2728 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2729 if (!irq)
2730 return 0;
2731
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002732 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2733 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2734
Vivien Didelot45de77f2019-08-31 16:18:36 -04002735 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2736 mv88e6xxx_reg_unlock(chip);
2737 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002738 IRQF_ONESHOT, dev_id->serdes_irq_name,
2739 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002740 mv88e6xxx_reg_lock(chip);
2741 if (err)
2742 return err;
2743
2744 dev_id->serdes_irq = irq;
2745
2746 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2747}
2748
2749static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
Pavana Sharma193c5b22021-03-17 14:46:40 +01002750 int lane)
Vivien Didelot45de77f2019-08-31 16:18:36 -04002751{
2752 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2753 unsigned int irq = dev_id->serdes_irq;
2754 int err;
2755
2756 /* Nothing to free if no IRQ has been requested */
2757 if (!irq)
2758 return 0;
2759
2760 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2761
2762 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2763 mv88e6xxx_reg_unlock(chip);
2764 free_irq(irq, dev_id);
2765 mv88e6xxx_reg_lock(chip);
2766
2767 dev_id->serdes_irq = 0;
2768
2769 return err;
2770}
2771
Andrew Lunn6d917822017-05-26 01:03:21 +02002772static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2773 bool on)
2774{
Pavana Sharma193c5b22021-03-17 14:46:40 +01002775 int lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002776 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002777
Vivien Didelotdc272f62019-08-31 16:18:33 -04002778 lane = mv88e6xxx_serdes_get_lane(chip, port);
Pavana Sharma193c5b22021-03-17 14:46:40 +01002779 if (lane < 0)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002780 return 0;
2781
2782 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002783 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002784 if (err)
2785 return err;
2786
Vivien Didelot45de77f2019-08-31 16:18:36 -04002787 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002788 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002789 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2790 if (err)
2791 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002792
Vivien Didelotdc272f62019-08-31 16:18:33 -04002793 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002794 }
2795
2796 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002797}
2798
Marek Behún2fda45f2021-03-17 14:46:41 +01002799static int mv88e6xxx_set_egress_port(struct mv88e6xxx_chip *chip,
2800 enum mv88e6xxx_egress_direction direction,
2801 int port)
2802{
2803 int err;
2804
2805 if (!chip->info->ops->set_egress_port)
2806 return -EOPNOTSUPP;
2807
2808 err = chip->info->ops->set_egress_port(chip, direction, port);
2809 if (err)
2810 return err;
2811
2812 if (direction == MV88E6XXX_EGRESS_DIR_INGRESS)
2813 chip->ingress_dest_port = port;
2814 else
2815 chip->egress_dest_port = port;
2816
2817 return 0;
2818}
2819
Vivien Didelotfa371c82017-12-05 15:34:10 -05002820static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2821{
2822 struct dsa_switch *ds = chip->ds;
2823 int upstream_port;
2824 int err;
2825
Vivien Didelot07073c72017-12-05 15:34:13 -05002826 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002827 if (chip->info->ops->port_set_upstream_port) {
2828 err = chip->info->ops->port_set_upstream_port(chip, port,
2829 upstream_port);
2830 if (err)
2831 return err;
2832 }
2833
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002834 if (port == upstream_port) {
2835 if (chip->info->ops->set_cpu_port) {
2836 err = chip->info->ops->set_cpu_port(chip,
2837 upstream_port);
2838 if (err)
2839 return err;
2840 }
2841
Marek Behún2fda45f2021-03-17 14:46:41 +01002842 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002843 MV88E6XXX_EGRESS_DIR_INGRESS,
2844 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002845 if (err && err != -EOPNOTSUPP)
2846 return err;
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002847
Marek Behún2fda45f2021-03-17 14:46:41 +01002848 err = mv88e6xxx_set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002849 MV88E6XXX_EGRESS_DIR_EGRESS,
2850 upstream_port);
Marek Behún2fda45f2021-03-17 14:46:41 +01002851 if (err && err != -EOPNOTSUPP)
2852 return err;
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002853 }
2854
Vivien Didelotfa371c82017-12-05 15:34:10 -05002855 return 0;
2856}
2857
Vivien Didelotfad09c72016-06-21 12:28:20 -04002858static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002859{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002860 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002861 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002862 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002863
Andrew Lunn7b898462018-08-09 15:38:47 +02002864 chip->ports[port].chip = chip;
2865 chip->ports[port].port = port;
2866
Vivien Didelotd78343d2016-11-04 03:23:36 +01002867 /* MAC Forcing register: don't force link, speed, duplex or flow control
2868 * state to any particular values on physical ports, but force the CPU
2869 * port and all DSA ports to their maximum bandwidth and full duplex.
2870 */
2871 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2872 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2873 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002874 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002875 PHY_INTERFACE_MODE_NA);
2876 else
2877 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2878 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002879 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002880 PHY_INTERFACE_MODE_NA);
2881 if (err)
2882 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002883
2884 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2885 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2886 * tunneling, determine priority by looking at 802.1p and IP
2887 * priority fields (IP prio has precedence), and set STP state
2888 * to Forwarding.
2889 *
2890 * If this is the CPU link, use DSA or EDSA tagging depending
2891 * on which tagging mode was configured.
2892 *
2893 * If this is a link to another switch, use DSA tagging mode.
2894 *
2895 * If this is the upstream port for this switch, enable
2896 * forwarding of unknown unicasts and multicasts.
2897 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002898 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2899 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2900 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2901 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002902 if (err)
2903 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002904
Vivien Didelot601aeed2017-03-11 16:13:00 -05002905 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002906 if (err)
2907 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002908
Vivien Didelot601aeed2017-03-11 16:13:00 -05002909 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002910 if (err)
2911 return err;
2912
Andrew Lunnb92ce2f2021-09-26 19:41:25 +02002913 /* Port Control 2: don't force a good FCS, set the MTU size to
2914 * 10222 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002915 * untagged frames on this port, do a destination address lookup on all
2916 * received packets as usual, disable ARP mirroring and don't send a
2917 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002918 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002919 err = mv88e6xxx_port_set_map_da(chip, port);
2920 if (err)
2921 return err;
2922
Vivien Didelotfa371c82017-12-05 15:34:10 -05002923 err = mv88e6xxx_setup_upstream_port(chip, port);
2924 if (err)
2925 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002926
Andrew Lunna23b2962017-02-04 20:15:28 +01002927 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002928 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002929 if (err)
2930 return err;
2931
Vladimir Oltean5bded822021-10-07 19:47:11 +03002932 /* Associate MV88E6XXX_VID_BRIDGED with MV88E6XXX_FID_BRIDGED in the
2933 * ATU by virtue of the fact that mv88e6xxx_atu_new() will pick it as
2934 * the first free FID after MV88E6XXX_FID_STANDALONE. This will be used
2935 * as the private PVID on ports under a VLAN-unaware bridge.
2936 * Shared (DSA and CPU) ports must also be members of it, to translate
2937 * the VID from the DSA tag into MV88E6XXX_FID_BRIDGED, instead of
2938 * relying on their port default FID.
2939 */
2940 err = mv88e6xxx_port_vlan_join(chip, port, MV88E6XXX_VID_BRIDGED,
2941 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED,
2942 false);
2943 if (err)
2944 return err;
2945
Vivien Didelotcd782652017-06-08 18:34:13 -04002946 if (chip->info->ops->port_set_jumbo_size) {
Andrew Lunnb92ce2f2021-09-26 19:41:25 +02002947 err = chip->info->ops->port_set_jumbo_size(chip, port, 10218);
Andrew Lunn5f436662016-12-03 04:45:17 +01002948 if (err)
2949 return err;
2950 }
2951
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002952 /* Port Association Vector: disable automatic address learning
2953 * on all user ports since they start out in standalone
2954 * mode. When joining a bridge, learning will be configured to
2955 * match the bridge port settings. Enable learning on all
2956 * DSA/CPU ports. NOTE: FROM_CPU frames always bypass the
2957 * learning process.
2958 *
2959 * Disable HoldAt1, IntOnAgeOut, LockedPort, IgnoreWrongData,
2960 * and RefreshLocked. I.e. setup standard automatic learning.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002961 */
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002962 if (dsa_is_user_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002963 reg = 0;
Tobias Waldekranz041bd542021-03-18 20:25:39 +01002964 else
2965 reg = 1 << port;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002966
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002967 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2968 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002969 if (err)
2970 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002971
2972 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002973 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2974 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002975 if (err)
2976 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002977
Vivien Didelot08984322017-06-08 18:34:12 -04002978 if (chip->info->ops->port_pause_limit) {
2979 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002980 if (err)
2981 return err;
2982 }
2983
Vivien Didelotc8c94892017-03-11 16:13:01 -05002984 if (chip->info->ops->port_disable_learn_limit) {
2985 err = chip->info->ops->port_disable_learn_limit(chip, port);
2986 if (err)
2987 return err;
2988 }
2989
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002990 if (chip->info->ops->port_disable_pri_override) {
2991 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002992 if (err)
2993 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002994 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002995
Andrew Lunnef0a7312016-12-03 04:35:16 +01002996 if (chip->info->ops->port_tag_remap) {
2997 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002998 if (err)
2999 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003000 }
3001
Andrew Lunnef70b112016-12-03 04:45:18 +01003002 if (chip->info->ops->port_egress_rate_limiting) {
3003 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02003004 if (err)
3005 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003006 }
3007
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003008 if (chip->info->ops->port_setup_message_port) {
3009 err = chip->info->ops->port_setup_message_port(chip, port);
3010 if (err)
3011 return err;
3012 }
Guenter Roeckd827e882015-03-26 18:36:29 -07003013
Vivien Didelot207afda2016-04-14 14:42:09 -04003014 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05003015 * database, and allow bidirectional communication between the
3016 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07003017 */
Vladimir Oltean5bded822021-10-07 19:47:11 +03003018 err = mv88e6xxx_port_set_fid(chip, port, MV88E6XXX_FID_STANDALONE);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02003019 if (err)
3020 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05003021
Vivien Didelot240ea3e2017-03-30 17:37:12 -04003022 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02003023 if (err)
3024 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07003025
3026 /* Default VLAN ID and priority: don't set a default VLAN
3027 * ID, and set the default packet priority to zero.
3028 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04003029 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02003030}
3031
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003032static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
3033{
3034 struct mv88e6xxx_chip *chip = ds->priv;
3035
3036 if (chip->info->ops->port_set_jumbo_size)
Andrew Lunnb9c587f2021-09-26 19:41:26 +02003037 return 10240 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
Chris Packham1baf0fa2020-07-24 11:21:22 +12003038 else if (chip->info->ops->set_max_frame_size)
Andrew Lunnb9c587f2021-09-26 19:41:26 +02003039 return 1632 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
3040 return 1522 - VLAN_ETH_HLEN - EDSA_HLEN - ETH_FCS_LEN;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003041}
3042
3043static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
3044{
3045 struct mv88e6xxx_chip *chip = ds->priv;
3046 int ret = 0;
3047
Andrew Lunnb9c587f2021-09-26 19:41:26 +02003048 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
3049 new_mtu += EDSA_HLEN;
3050
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003051 mv88e6xxx_reg_lock(chip);
3052 if (chip->info->ops->port_set_jumbo_size)
3053 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12003054 else if (chip->info->ops->set_max_frame_size)
3055 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02003056 else
3057 if (new_mtu > 1522)
3058 ret = -EINVAL;
3059 mv88e6xxx_reg_unlock(chip);
3060
3061 return ret;
3062}
3063
Andrew Lunn04aca992017-05-26 01:03:24 +02003064static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
3065 struct phy_device *phydev)
3066{
3067 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04003068 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02003069
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003070 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04003071 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003072 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02003073
3074 return err;
3075}
3076
Andrew Lunn75104db2019-02-24 20:44:43 +01003077static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02003078{
3079 struct mv88e6xxx_chip *chip = ds->priv;
3080
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003081 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04003082 if (mv88e6xxx_serdes_power(chip, port, false))
3083 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003084 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02003085}
3086
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003087static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
3088 unsigned int ageing_time)
3089{
Vivien Didelot04bed142016-08-31 18:06:13 -04003090 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003091 int err;
3092
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003093 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05003094 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003095 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003096
3097 return err;
3098}
3099
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003100static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04003101{
3102 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04003103
Andrew Lunnde2273872016-11-21 23:27:01 +01003104 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003105 if (chip->info->ops->stats_set_histogram) {
3106 err = chip->info->ops->stats_set_histogram(chip);
3107 if (err)
3108 return err;
3109 }
Andrew Lunnde2273872016-11-21 23:27:01 +01003110
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003111 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04003112}
3113
Andrew Lunnea890982019-01-09 00:24:03 +01003114/* Check if the errata has already been applied. */
3115static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
3116{
3117 int port;
3118 int err;
3119 u16 val;
3120
3121 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02003122 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01003123 if (err) {
3124 dev_err(chip->dev,
3125 "Error reading hidden register: %d\n", err);
3126 return false;
3127 }
3128 if (val != 0x01c0)
3129 return false;
3130 }
3131
3132 return true;
3133}
3134
3135/* The 6390 copper ports have an errata which require poking magic
3136 * values into undocumented hidden registers and then performing a
3137 * software reset.
3138 */
3139static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
3140{
3141 int port;
3142 int err;
3143
3144 if (mv88e6390_setup_errata_applied(chip))
3145 return 0;
3146
3147 /* Set the ports into blocking mode */
3148 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
3149 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
3150 if (err)
3151 return err;
3152 }
3153
3154 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02003155 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01003156 if (err)
3157 return err;
3158 }
3159
3160 return mv88e6xxx_software_reset(chip);
3161}
3162
Andrew Lunn23e8b472019-10-25 01:03:52 +02003163static void mv88e6xxx_teardown(struct dsa_switch *ds)
3164{
3165 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003166 dsa_devlink_resources_unregister(ds);
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003167 mv88e6xxx_teardown_devlink_regions_global(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02003168}
3169
Vivien Didelotf81ec902016-05-09 13:22:58 -04003170static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07003171{
Vivien Didelot04bed142016-08-31 18:06:13 -04003172 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003173 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04003174 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04003175 int i;
3176
Vivien Didelotfad09c72016-06-21 12:28:20 -04003177 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003178 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003179
Vladimir Olteance5df682021-07-22 18:55:41 +03003180 /* Since virtual bridges are mapped in the PVT, the number we support
3181 * depends on the physical switch topology. We need to let DSA figure
3182 * that out and therefore we cannot set this at dsa_register_switch()
3183 * time.
3184 */
3185 if (mv88e6xxx_has_pvt(chip))
3186 ds->num_fwd_offloading_bridges = MV88E6XXX_MAX_PVT_SWITCHES -
3187 ds->dst->last_switch - 1;
3188
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003189 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003190
Andrew Lunnea890982019-01-09 00:24:03 +01003191 if (chip->info->ops->setup_errata) {
3192 err = chip->info->ops->setup_errata(chip);
3193 if (err)
3194 goto unlock;
3195 }
3196
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003197 /* Cache the cmode of each port. */
3198 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3199 if (chip->info->ops->port_get_cmode) {
3200 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
3201 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03003202 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003203
3204 chip->ports[i].cmode = cmode;
3205 }
3206 }
3207
Vladimir Oltean5bded822021-10-07 19:47:11 +03003208 err = mv88e6xxx_vtu_setup(chip);
3209 if (err)
3210 goto unlock;
3211
Vivien Didelot97299342016-07-18 20:45:30 -04003212 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04003213 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04003214 if (dsa_is_unused_port(ds, i))
3215 continue;
3216
Hubert Feursteinc8574862019-07-31 10:23:48 +02003217 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04003218 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02003219 dev_err(chip->dev, "port %d is invalid\n", i);
3220 err = -EINVAL;
3221 goto unlock;
3222 }
3223
Vivien Didelot97299342016-07-18 20:45:30 -04003224 err = mv88e6xxx_setup_port(chip, i);
3225 if (err)
3226 goto unlock;
3227 }
3228
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003229 err = mv88e6xxx_irl_setup(chip);
3230 if (err)
3231 goto unlock;
3232
Vivien Didelot04a69a12017-10-13 14:18:05 -04003233 err = mv88e6xxx_mac_setup(chip);
3234 if (err)
3235 goto unlock;
3236
Vivien Didelot1b17aed2017-05-26 18:03:05 -04003237 err = mv88e6xxx_phy_setup(chip);
3238 if (err)
3239 goto unlock;
3240
Vivien Didelot81228992017-03-30 17:37:08 -04003241 err = mv88e6xxx_pvt_setup(chip);
3242 if (err)
3243 goto unlock;
3244
Vivien Didelota2ac29d2017-03-11 16:12:49 -05003245 err = mv88e6xxx_atu_setup(chip);
3246 if (err)
3247 goto unlock;
3248
Andrew Lunn87fa8862017-11-09 22:29:56 +01003249 err = mv88e6xxx_broadcast_setup(chip, 0);
3250 if (err)
3251 goto unlock;
3252
Vivien Didelot9e907d72017-07-17 13:03:43 -04003253 err = mv88e6xxx_pot_setup(chip);
3254 if (err)
3255 goto unlock;
3256
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003257 err = mv88e6xxx_rmu_setup(chip);
3258 if (err)
3259 goto unlock;
3260
Vivien Didelot51c901a2017-07-17 13:03:41 -04003261 err = mv88e6xxx_rsvd2cpu_setup(chip);
3262 if (err)
3263 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01003264
Vivien Didelotb28f8722018-04-26 21:56:44 -04003265 err = mv88e6xxx_trunk_setup(chip);
3266 if (err)
3267 goto unlock;
3268
Vivien Didelotc7f047b2018-04-26 21:56:45 -04003269 err = mv88e6xxx_devmap_setup(chip);
3270 if (err)
3271 goto unlock;
3272
Vivien Didelot93e18d62018-05-11 17:16:35 -04003273 err = mv88e6xxx_pri_setup(chip);
3274 if (err)
3275 goto unlock;
3276
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003277 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003278 if (chip->info->ptp_support) {
3279 err = mv88e6xxx_ptp_setup(chip);
3280 if (err)
3281 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003282
3283 err = mv88e6xxx_hwtstamp_setup(chip);
3284 if (err)
3285 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003286 }
3287
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003288 err = mv88e6xxx_stats_setup(chip);
3289 if (err)
3290 goto unlock;
3291
Vivien Didelot6b17e862015-08-13 12:52:18 -04003292unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003293 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02003294
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003295 if (err)
3296 return err;
3297
3298 /* Have to be called without holding the register lock, since
3299 * they take the devlink lock, and we later take the locks in
3300 * the reverse order when getting/setting parameters or
3301 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02003302 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003303 err = mv88e6xxx_setup_devlink_resources(ds);
3304 if (err)
3305 return err;
3306
3307 err = mv88e6xxx_setup_devlink_params(ds);
3308 if (err)
Andrew Lunnbfb25542020-09-18 21:11:07 +02003309 goto out_resources;
3310
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003311 err = mv88e6xxx_setup_devlink_regions_global(ds);
Andrew Lunnbfb25542020-09-18 21:11:07 +02003312 if (err)
3313 goto out_params;
3314
3315 return 0;
3316
3317out_params:
3318 mv88e6xxx_teardown_devlink_params(ds);
3319out_resources:
3320 dsa_devlink_resources_unregister(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003321
3322 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003323}
3324
Vladimir Olteanfd292c12021-09-17 17:29:16 +03003325static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
3326{
3327 return mv88e6xxx_setup_devlink_regions_port(ds, port);
3328}
3329
3330static void mv88e6xxx_port_teardown(struct dsa_switch *ds, int port)
3331{
3332 mv88e6xxx_teardown_devlink_regions_port(ds, port);
3333}
3334
Pali Rohár1fe976d2021-04-12 18:57:39 +02003335/* prod_id for switch families which do not have a PHY model number */
3336static const u16 family_prod_id_table[] = {
3337 [MV88E6XXX_FAMILY_6341] = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
3338 [MV88E6XXX_FAMILY_6390] = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Marek Behúnc5d015b2021-04-20 09:54:02 +02003339 [MV88E6XXX_FAMILY_6393] = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
Pali Rohár1fe976d2021-04-12 18:57:39 +02003340};
3341
Vivien Didelote57e5e72016-08-15 17:19:00 -04003342static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003343{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003344 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3345 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Pali Rohár1fe976d2021-04-12 18:57:39 +02003346 u16 prod_id;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003347 u16 val;
3348 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003349
Andrew Lunnee26a222017-01-24 14:53:48 +01003350 if (!chip->info->ops->phy_read)
3351 return -EOPNOTSUPP;
3352
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003353 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003354 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003355 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003356
Pali Rohár1fe976d2021-04-12 18:57:39 +02003357 /* Some internal PHYs don't have a model number. */
3358 if (reg == MII_PHYSID2 && !(val & 0x3f0) &&
3359 chip->info->family < ARRAY_SIZE(family_prod_id_table)) {
3360 prod_id = family_prod_id_table[chip->info->family];
3361 if (prod_id)
3362 val |= prod_id >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003363 }
3364
Vivien Didelote57e5e72016-08-15 17:19:00 -04003365 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003366}
3367
Vivien Didelote57e5e72016-08-15 17:19:00 -04003368static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003369{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003370 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3371 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003372 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003373
Andrew Lunnee26a222017-01-24 14:53:48 +01003374 if (!chip->info->ops->phy_write)
3375 return -EOPNOTSUPP;
3376
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003377 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003378 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003379 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003380
3381 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003382}
3383
Vivien Didelotfad09c72016-06-21 12:28:20 -04003384static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003385 struct device_node *np,
3386 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003387{
3388 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003389 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003390 struct mii_bus *bus;
3391 int err;
3392
Andrew Lunn2510bab2018-02-22 01:51:49 +01003393 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003394 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003395 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003396 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003397
3398 if (err)
3399 return err;
3400 }
3401
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003402 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003403 if (!bus)
3404 return -ENOMEM;
3405
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003406 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003407 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003408 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003409 INIT_LIST_HEAD(&mdio_bus->list);
3410 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003411
Andrew Lunnb516d452016-06-04 21:17:06 +02003412 if (np) {
3413 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003414 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003415 } else {
3416 bus->name = "mv88e6xxx SMI";
3417 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3418 }
3419
3420 bus->read = mv88e6xxx_mdio_read;
3421 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003422 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003423
Andrew Lunn6f882842018-03-17 20:32:05 +01003424 if (!external) {
3425 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3426 if (err)
3427 return err;
3428 }
3429
Florian Fainelli00e798c2018-05-15 16:56:19 -07003430 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003431 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003432 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003433 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003434 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003435 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003436
3437 if (external)
3438 list_add_tail(&mdio_bus->list, &chip->mdios);
3439 else
3440 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003441
3442 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003443}
3444
Andrew Lunn3126aee2017-12-07 01:05:57 +01003445static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3446
3447{
3448 struct mv88e6xxx_mdio_bus *mdio_bus;
3449 struct mii_bus *bus;
3450
3451 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3452 bus = mdio_bus->bus;
3453
Andrew Lunn6f882842018-03-17 20:32:05 +01003454 if (!mdio_bus->external)
3455 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3456
Andrew Lunn3126aee2017-12-07 01:05:57 +01003457 mdiobus_unregister(bus);
3458 }
3459}
3460
Andrew Lunna3c53be52017-01-24 14:53:50 +01003461static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3462 struct device_node *np)
3463{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003464 struct device_node *child;
3465 int err;
3466
3467 /* Always register one mdio bus for the internal/default mdio
3468 * bus. This maybe represented in the device tree, but is
3469 * optional.
3470 */
3471 child = of_get_child_by_name(np, "mdio");
3472 err = mv88e6xxx_mdio_register(chip, child, false);
3473 if (err)
3474 return err;
3475
3476 /* Walk the device tree, and see if there are any other nodes
3477 * which say they are compatible with the external mdio
3478 * bus.
3479 */
3480 for_each_available_child_of_node(np, child) {
Andrew Lunnceb96fa2020-09-01 04:32:57 +02003481 if (of_device_is_compatible(
3482 child, "marvell,mv88e6xxx-mdio-external")) {
Andrew Lunna3c53be52017-01-24 14:53:50 +01003483 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003484 if (err) {
3485 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303486 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003487 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003488 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003489 }
3490 }
3491
3492 return 0;
3493}
3494
Vivien Didelot855b1932016-07-20 18:18:35 -04003495static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3496{
Vivien Didelot04bed142016-08-31 18:06:13 -04003497 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003498
3499 return chip->eeprom_len;
3500}
3501
Vivien Didelot855b1932016-07-20 18:18:35 -04003502static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3503 struct ethtool_eeprom *eeprom, u8 *data)
3504{
Vivien Didelot04bed142016-08-31 18:06:13 -04003505 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003506 int err;
3507
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003508 if (!chip->info->ops->get_eeprom)
3509 return -EOPNOTSUPP;
3510
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003511 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003512 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003513 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003514
3515 if (err)
3516 return err;
3517
3518 eeprom->magic = 0xc3ec4951;
3519
3520 return 0;
3521}
3522
Vivien Didelot855b1932016-07-20 18:18:35 -04003523static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3524 struct ethtool_eeprom *eeprom, u8 *data)
3525{
Vivien Didelot04bed142016-08-31 18:06:13 -04003526 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003527 int err;
3528
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003529 if (!chip->info->ops->set_eeprom)
3530 return -EOPNOTSUPP;
3531
Vivien Didelot855b1932016-07-20 18:18:35 -04003532 if (eeprom->magic != 0xc3ec4951)
3533 return -EINVAL;
3534
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003535 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003536 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003537 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003538
3539 return err;
3540}
3541
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003542static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003543 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003544 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3545 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003546 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003547 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003548 .phy_read = mv88e6185_phy_ppu_read,
3549 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003550 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003551 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003552 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003553 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003554 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003555 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3556 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003557 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003558 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003559 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003560 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003561 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003562 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003563 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003564 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003565 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003566 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3567 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003568 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003569 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3570 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003571 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003572 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003573 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003574 .ppu_enable = mv88e6185_g1_ppu_enable,
3575 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003576 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003577 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003578 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003579 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003580 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003581 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003582};
3583
3584static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003585 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003586 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3587 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003588 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003589 .phy_read = mv88e6185_phy_ppu_read,
3590 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003591 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003592 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003593 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003594 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003595 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3596 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunna23b2962017-02-04 20:15:28 +01003597 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003598 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003599 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003600 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003601 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003602 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3603 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003604 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003605 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003606 .serdes_power = mv88e6185_serdes_power,
3607 .serdes_get_lane = mv88e6185_serdes_get_lane,
3608 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003609 .ppu_enable = mv88e6185_g1_ppu_enable,
3610 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003611 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003612 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003613 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003614 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003615 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003616};
3617
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003618static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003619 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003620 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3621 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003622 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003623 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3624 .phy_read = mv88e6xxx_g2_smi_phy_read,
3625 .phy_write = mv88e6xxx_g2_smi_phy_write,
3626 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003627 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003628 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003629 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003630 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003631 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3632 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003633 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003634 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003635 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003636 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003637 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003638 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003639 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003640 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003641 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003642 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3643 .stats_get_strings = mv88e6095_stats_get_strings,
3644 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003645 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3646 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003647 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003648 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13003649 .serdes_power = mv88e6185_serdes_power,
3650 .serdes_get_lane = mv88e6185_serdes_get_lane,
3651 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Chris Packham5c19bc82020-11-24 17:34:39 +13003652 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
3653 .serdes_irq_enable = mv88e6097_serdes_irq_enable,
3654 .serdes_irq_status = mv88e6097_serdes_irq_status,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003655 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003656 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003657 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003658 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003659 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003660 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003661 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003662};
3663
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003664static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003665 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003666 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3667 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003668 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003669 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003670 .phy_read = mv88e6xxx_g2_smi_phy_read,
3671 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003672 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003673 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003674 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003675 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003676 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3677 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003678 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003679 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003680 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003681 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003682 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003683 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003684 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3685 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003686 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003687 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3688 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003689 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003690 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003691 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003692 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003693 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3694 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003695 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003696 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003697 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003698 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003699};
3700
3701static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003702 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003703 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3704 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003705 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003706 .phy_read = mv88e6185_phy_ppu_read,
3707 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003708 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003709 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003710 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003711 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003712 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003713 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
3714 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003715 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003716 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003717 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003718 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003719 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003720 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003721 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003722 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003723 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003724 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003725 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3726 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003727 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003728 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3729 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003730 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003731 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003732 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003733 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003734 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003735 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003736 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003737 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003738 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003739};
3740
Vivien Didelot990e27b2017-03-28 13:50:32 -04003741static const struct mv88e6xxx_ops mv88e6141_ops = {
3742 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003743 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3744 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003745 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003746 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3747 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3748 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3749 .phy_read = mv88e6xxx_g2_smi_phy_read,
3750 .phy_write = mv88e6xxx_g2_smi_phy_write,
3751 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003752 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003753 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003754 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003755 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003756 .port_tag_remap = mv88e6095_port_tag_remap,
Marek Behún7da467d2021-07-01 00:22:26 +02003757 .port_set_policy = mv88e6352_port_set_policy,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003758 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003759 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3760 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003761 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003762 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003763 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003764 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003765 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3766 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003767 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003768 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003769 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003770 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Marek Behún11527f32021-07-01 00:22:27 +02003771 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003772 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3773 .stats_get_strings = mv88e6320_stats_get_strings,
3774 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003775 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3776 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003777 .watchdog_ops = &mv88e6390_watchdog_ops,
3778 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003779 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003780 .reset = mv88e6352_g1_reset,
Marek Behún37094882021-07-01 00:22:28 +02003781 .rmu_disable = mv88e6390_g1_rmu_disable,
Marek Behúnc07fff32021-07-01 00:22:29 +02003782 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3783 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003784 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003785 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003786 .serdes_power = mv88e6390_serdes_power,
3787 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003788 /* Check status register pause & lpa register */
3789 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3790 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3791 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3792 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003793 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003794 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003795 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003796 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúna03b98d2021-07-01 00:22:30 +02003797 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
3798 .serdes_get_strings = mv88e6390_serdes_get_strings,
3799 .serdes_get_stats = mv88e6390_serdes_get_stats,
Marek Behún953b0dc2021-07-01 00:22:31 +02003800 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
3801 .serdes_get_regs = mv88e6390_serdes_get_regs,
Marek Behúne3af71a2019-02-25 12:39:55 +01003802 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003803};
3804
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003805static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003806 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003807 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3808 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003809 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003810 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003811 .phy_read = mv88e6xxx_g2_smi_phy_read,
3812 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003813 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003814 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003815 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003816 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003817 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003818 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3819 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003820 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003821 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003822 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003823 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003824 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003825 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003826 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003827 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003828 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003829 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3830 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003831 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003832 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3833 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003834 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003835 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003836 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003837 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003838 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3839 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003840 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003841 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003842 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003843 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003844 .phylink_validate = mv88e6185_phylink_validate,
Andrew Lunnfe230362021-09-26 19:41:24 +02003845 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003846};
3847
3848static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003849 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003850 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3851 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003852 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003853 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003854 .phy_read = mv88e6165_phy_read,
3855 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003856 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003857 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003858 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003859 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003860 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003861 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003862 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003863 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003864 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003865 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3866 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003867 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003868 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3869 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003870 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003871 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003872 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003873 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003874 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3875 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003876 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003877 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003878 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003879 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003880 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003881};
3882
3883static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003884 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003885 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3886 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003887 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003888 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003889 .phy_read = mv88e6xxx_g2_smi_phy_read,
3890 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003891 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003892 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003893 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003894 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003895 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003896 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003897 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3898 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003899 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003900 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003901 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003902 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003903 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003904 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003905 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003906 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003907 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003908 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003909 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3910 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003911 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003912 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3913 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003914 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003915 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003916 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003917 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003918 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3919 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003920 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003921 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003922 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003923};
3924
3925static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003926 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003927 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3928 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003929 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003930 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3931 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003932 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003933 .phy_read = mv88e6xxx_g2_smi_phy_read,
3934 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003935 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003936 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003937 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003938 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003939 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003940 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003941 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003942 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3943 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003944 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003945 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003946 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003947 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003948 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003949 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003950 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003951 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003952 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003953 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003954 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3955 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003956 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003957 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3958 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003959 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003960 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003961 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003962 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003963 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003964 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3965 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003966 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003967 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003968 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003969 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3970 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3971 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3972 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003973 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003974 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3975 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003976 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003977 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003978};
3979
3980static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003981 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003982 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3983 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003984 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003985 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003986 .phy_read = mv88e6xxx_g2_smi_phy_read,
3987 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003988 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13003989 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003990 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003991 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003992 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003993 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02003994 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
3995 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003996 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003997 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003998 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003999 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004000 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004001 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004002 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004003 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004004 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004005 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004006 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4007 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004008 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004009 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4010 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004011 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004012 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004013 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004014 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004015 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4016 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004017 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004018 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004019 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004020};
4021
4022static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004023 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004024 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4025 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004026 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004027 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4028 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004029 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004030 .phy_read = mv88e6xxx_g2_smi_phy_read,
4031 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004032 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004033 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004034 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004035 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004036 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004037 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004038 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004039 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4040 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004041 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004042 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004043 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004044 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004045 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004046 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004047 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004048 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004049 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004050 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004051 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4052 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004053 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004054 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4055 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004056 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004057 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004058 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004059 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004060 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004061 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4062 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004063 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004064 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004065 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004066 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4067 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4068 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4069 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004070 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004071 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004072 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004073 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004074 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4075 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004076 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004077 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004078};
4079
4080static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004081 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004082 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4083 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004084 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04004085 .phy_read = mv88e6185_phy_ppu_read,
4086 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004087 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004088 .port_sync_link = mv88e6185_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004089 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004090 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004091 .port_set_ucast_flood = mv88e6185_port_set_forward_unknown,
4092 .port_set_mcast_flood = mv88e6185_port_set_default_forward,
Andrew Lunnef70b112016-12-03 04:45:18 +01004093 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01004094 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02004095 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004096 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004097 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004098 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004099 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004100 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4101 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004102 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004103 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4104 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004105 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004106 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Chris Packhamf5be1072020-11-24 17:34:38 +13004107 .serdes_power = mv88e6185_serdes_power,
4108 .serdes_get_lane = mv88e6185_serdes_get_lane,
4109 .serdes_pcs_get_state = mv88e6185_serdes_pcs_get_state,
Vivien Didelot02317e62018-05-09 11:38:49 -04004110 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05004111 .ppu_enable = mv88e6185_g1_ppu_enable,
4112 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004113 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004114 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004115 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004116 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12004117 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004118};
4119
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004120static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004121 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004122 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004123 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004124 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4125 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004126 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4127 .phy_read = mv88e6xxx_g2_smi_phy_read,
4128 .phy_write = mv88e6xxx_g2_smi_phy_write,
4129 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004130 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004131 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004132 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004133 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004134 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004135 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004136 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004137 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4138 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004139 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12004140 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04004141 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004142 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004143 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004144 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004145 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004146 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004147 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004148 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004149 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4150 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004151 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004152 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4153 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004154 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004155 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004156 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004157 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004158 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004159 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4160 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004161 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4162 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004163 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004164 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004165 /* Check status register pause & lpa register */
4166 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4167 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4168 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4169 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004170 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004171 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004172 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004173 .serdes_get_strings = mv88e6390_serdes_get_strings,
4174 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004175 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4176 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004177 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004178 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004179};
4180
4181static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004182 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004183 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004184 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004185 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4186 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004187 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4188 .phy_read = mv88e6xxx_g2_smi_phy_read,
4189 .phy_write = mv88e6xxx_g2_smi_phy_write,
4190 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004191 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004192 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004193 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004194 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004195 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004196 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004197 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004198 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4199 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004200 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12004201 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04004202 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004203 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004204 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004205 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004206 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004207 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004208 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004209 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004210 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4211 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004212 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004213 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4214 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004215 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004216 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004217 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004218 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004219 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004220 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4221 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004222 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4223 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004224 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004225 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004226 /* Check status register pause & lpa register */
4227 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4228 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4229 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4230 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004231 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004232 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004233 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004234 .serdes_get_strings = mv88e6390_serdes_get_strings,
4235 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004236 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4237 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004238 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004239 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004240};
4241
4242static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004243 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004244 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004245 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004246 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4247 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004248 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4249 .phy_read = mv88e6xxx_g2_smi_phy_read,
4250 .phy_write = mv88e6xxx_g2_smi_phy_write,
4251 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004252 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004253 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004254 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004255 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004256 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004257 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004258 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4259 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004260 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004261 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004262 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004263 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004264 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004265 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004266 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004267 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004268 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004269 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4270 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004271 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004272 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4273 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004274 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004275 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004276 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004277 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004278 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004279 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4280 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004281 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4282 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004283 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004284 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004285 /* Check status register pause & lpa register */
4286 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4287 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4288 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4289 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004290 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004291 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004292 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004293 .serdes_get_strings = mv88e6390_serdes_get_strings,
4294 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004295 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4296 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004297 .avb_ops = &mv88e6390_avb_ops,
4298 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004299 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004300};
4301
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004302static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004303 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004304 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4305 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004306 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004307 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4308 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004309 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004310 .phy_read = mv88e6xxx_g2_smi_phy_read,
4311 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004312 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004313 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004314 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004315 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004316 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004317 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004318 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004319 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4320 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004321 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004322 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004323 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004324 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004325 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004326 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004327 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004328 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004329 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004330 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004331 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4332 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004333 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004334 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4335 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004336 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004337 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004338 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004339 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004340 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004341 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4342 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004343 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004344 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004345 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004346 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4347 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4348 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4349 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004350 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004351 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004352 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004353 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004354 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4355 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004356 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004357 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004358 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004359 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004360};
4361
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004362static const struct mv88e6xxx_ops mv88e6250_ops = {
4363 /* MV88E6XXX_FAMILY_6250 */
4364 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4365 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4366 .irl_init_all = mv88e6352_g2_irl_init_all,
4367 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4368 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4369 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4370 .phy_read = mv88e6xxx_g2_smi_phy_read,
4371 .phy_write = mv88e6xxx_g2_smi_phy_write,
4372 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004373 .port_sync_link = mv88e6xxx_port_sync_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004374 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004375 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004376 .port_tag_remap = mv88e6095_port_tag_remap,
4377 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004378 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4379 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004380 .port_set_ether_type = mv88e6351_port_set_ether_type,
4381 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4382 .port_pause_limit = mv88e6097_port_pause_limit,
4383 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004384 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4385 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4386 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4387 .stats_get_strings = mv88e6250_stats_get_strings,
4388 .stats_get_stats = mv88e6250_stats_get_stats,
4389 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4390 .set_egress_port = mv88e6095_g1_set_egress_port,
4391 .watchdog_ops = &mv88e6250_watchdog_ops,
4392 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4393 .pot_clear = mv88e6xxx_g2_pot_clear,
4394 .reset = mv88e6250_g1_reset,
Rasmus Villemoes67c9ed12021-01-25 16:04:48 +01004395 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Rasmus Villemoesb28f3f32021-01-25 16:04:49 +01004396 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004397 .avb_ops = &mv88e6352_avb_ops,
4398 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004399 .phylink_validate = mv88e6065_phylink_validate,
4400};
4401
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004402static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004403 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004404 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004405 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004406 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4407 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004408 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4409 .phy_read = mv88e6xxx_g2_smi_phy_read,
4410 .phy_write = mv88e6xxx_g2_smi_phy_write,
4411 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004412 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004413 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004414 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004415 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004416 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004417 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004418 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004419 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4420 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004421 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004422 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004423 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004424 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004425 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004426 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004427 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004428 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004429 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004430 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4431 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004432 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004433 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4434 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004435 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004436 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004437 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004438 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004439 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004440 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4441 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004442 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4443 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004444 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004445 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004446 /* Check status register pause & lpa register */
4447 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4448 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4449 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4450 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004451 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004452 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004453 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004454 .serdes_get_strings = mv88e6390_serdes_get_strings,
4455 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004456 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4457 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004458 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004459 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004460 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004461 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004462};
4463
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004464static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004465 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004466 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4467 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004468 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004469 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4470 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004471 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004472 .phy_read = mv88e6xxx_g2_smi_phy_read,
4473 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004474 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004475 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004476 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004477 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004478 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004479 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4480 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004481 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004482 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004483 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004484 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004485 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004486 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004487 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004488 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004489 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004490 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004491 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4492 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004493 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004494 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4495 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004496 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004497 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004498 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004499 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004500 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004501 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004502 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004503 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004504 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004505 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004506};
4507
4508static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004509 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004510 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4511 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004512 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004513 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4514 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004515 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004516 .phy_read = mv88e6xxx_g2_smi_phy_read,
4517 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004518 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004519 .port_sync_link = mv88e6xxx_port_sync_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004520 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004521 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004522 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004523 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4524 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004525 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004526 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004527 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004528 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004529 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004530 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004531 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004532 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004533 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004534 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004535 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4536 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004537 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004538 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4539 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004540 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004541 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004542 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004543 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004544 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004545 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004546 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004547 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004548};
4549
Vivien Didelot16e329a2017-03-28 13:50:33 -04004550static const struct mv88e6xxx_ops mv88e6341_ops = {
4551 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004552 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4553 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004554 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004555 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4556 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4557 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4558 .phy_read = mv88e6xxx_g2_smi_phy_read,
4559 .phy_write = mv88e6xxx_g2_smi_phy_write,
4560 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004561 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004562 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004563 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004564 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004565 .port_tag_remap = mv88e6095_port_tag_remap,
Marek Behún7da467d2021-07-01 00:22:26 +02004566 .port_set_policy = mv88e6352_port_set_policy,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004567 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004568 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4569 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004570 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004571 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004572 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004573 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004574 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4575 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004576 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004577 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004578 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004579 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Marek Behún11527f32021-07-01 00:22:27 +02004580 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004581 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4582 .stats_get_strings = mv88e6320_stats_get_strings,
4583 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004584 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4585 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004586 .watchdog_ops = &mv88e6390_watchdog_ops,
4587 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004588 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004589 .reset = mv88e6352_g1_reset,
Marek Behún37094882021-07-01 00:22:28 +02004590 .rmu_disable = mv88e6390_g1_rmu_disable,
Marek Behúnc07fff32021-07-01 00:22:29 +02004591 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4592 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004593 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004594 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004595 .serdes_power = mv88e6390_serdes_power,
4596 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004597 /* Check status register pause & lpa register */
4598 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4599 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4600 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4601 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004602 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004603 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004604 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004605 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004606 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004607 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúna03b98d2021-07-01 00:22:30 +02004608 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4609 .serdes_get_strings = mv88e6390_serdes_get_strings,
4610 .serdes_get_stats = mv88e6390_serdes_get_stats,
Marek Behún953b0dc2021-07-01 00:22:31 +02004611 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4612 .serdes_get_regs = mv88e6390_serdes_get_regs,
Marek Behúne3af71a2019-02-25 12:39:55 +01004613 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004614};
4615
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004616static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004617 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004618 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4619 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004620 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004621 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004622 .phy_read = mv88e6xxx_g2_smi_phy_read,
4623 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004624 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004625 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004626 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004627 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004628 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004629 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004630 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4631 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004632 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004633 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004634 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004635 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004636 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004637 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004638 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004639 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004640 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004641 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004642 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4643 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004644 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004645 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4646 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004647 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004648 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004649 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004650 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004651 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4652 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004653 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004654 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004655 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004656};
4657
4658static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004659 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004660 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4661 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004662 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004663 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004664 .phy_read = mv88e6xxx_g2_smi_phy_read,
4665 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004666 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004667 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004668 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004669 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004670 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004671 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004672 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4673 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004674 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004675 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004676 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004677 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004678 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004679 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004680 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004681 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004682 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004683 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004684 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4685 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004686 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004687 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4688 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004689 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004690 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004691 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004692 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004693 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4694 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004695 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004696 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004697 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004698 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004699 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004700};
4701
4702static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004703 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004704 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4705 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004706 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004707 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4708 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004709 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004710 .phy_read = mv88e6xxx_g2_smi_phy_read,
4711 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004712 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004713 .port_sync_link = mv88e6xxx_port_sync_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004714 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004715 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004716 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004717 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004718 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004719 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4720 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004721 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004722 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004723 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004724 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004725 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004726 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004727 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004728 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004729 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004730 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004731 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4732 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004733 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004734 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4735 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004736 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004737 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004738 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004739 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004740 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004741 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4742 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004743 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004744 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004745 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004746 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4747 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4748 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4749 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004750 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004751 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004752 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004753 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004754 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004755 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004756 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004757 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4758 .serdes_get_strings = mv88e6352_serdes_get_strings,
4759 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004760 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4761 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004762 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004763};
4764
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004765static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004766 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004767 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004768 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004769 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4770 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004771 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4772 .phy_read = mv88e6xxx_g2_smi_phy_read,
4773 .phy_write = mv88e6xxx_g2_smi_phy_write,
4774 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004775 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004776 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004777 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004778 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004779 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004780 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004781 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004782 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4783 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004784 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004785 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004786 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004787 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004788 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004789 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004790 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004791 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004792 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004793 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004794 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004795 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4796 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004797 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004798 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4799 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004800 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004801 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004802 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004803 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004804 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004805 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4806 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004807 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4808 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004809 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004810 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004811 /* Check status register pause & lpa register */
4812 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4813 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4814 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4815 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004816 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004817 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004818 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004819 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004820 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004821 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004822 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4823 .serdes_get_strings = mv88e6390_serdes_get_strings,
4824 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004825 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4826 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004827 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004828};
4829
4830static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004831 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004832 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004833 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004834 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4835 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004836 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4837 .phy_read = mv88e6xxx_g2_smi_phy_read,
4838 .phy_write = mv88e6xxx_g2_smi_phy_write,
4839 .port_set_link = mv88e6xxx_port_set_link,
Chris Packham4efe76622020-11-24 17:34:37 +13004840 .port_sync_link = mv88e6xxx_port_sync_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004841 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004842 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004843 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004844 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004845 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004846 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02004847 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4848 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004849 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004850 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004851 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004852 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004853 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004854 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004855 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004856 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004857 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004858 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004859 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004860 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4861 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004862 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004863 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4864 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004865 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004866 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004867 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004868 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004869 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004870 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4871 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004872 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4873 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004874 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004875 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004876 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4877 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4878 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4879 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004880 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004881 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004882 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004883 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4884 .serdes_get_strings = mv88e6390_serdes_get_strings,
4885 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004886 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4887 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004888 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004889 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004890 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004891 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004892};
4893
Pavana Sharmade776d02021-03-17 14:46:42 +01004894static const struct mv88e6xxx_ops mv88e6393x_ops = {
4895 /* MV88E6XXX_FAMILY_6393 */
4896 .setup_errata = mv88e6393x_serdes_setup_errata,
4897 .irl_init_all = mv88e6390_g2_irl_init_all,
4898 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4899 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4900 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4901 .phy_read = mv88e6xxx_g2_smi_phy_read,
4902 .phy_write = mv88e6xxx_g2_smi_phy_write,
4903 .port_set_link = mv88e6xxx_port_set_link,
4904 .port_sync_link = mv88e6xxx_port_sync_link,
4905 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4906 .port_set_speed_duplex = mv88e6393x_port_set_speed_duplex,
4907 .port_max_speed_mode = mv88e6393x_port_max_speed_mode,
4908 .port_tag_remap = mv88e6390_port_tag_remap,
Marek Behún6584b262021-03-17 14:46:43 +01004909 .port_set_policy = mv88e6393x_port_set_policy,
Pavana Sharmade776d02021-03-17 14:46:42 +01004910 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4911 .port_set_ucast_flood = mv88e6352_port_set_ucast_flood,
4912 .port_set_mcast_flood = mv88e6352_port_set_mcast_flood,
4913 .port_set_ether_type = mv88e6393x_port_set_ether_type,
4914 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
4915 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4916 .port_pause_limit = mv88e6390_port_pause_limit,
4917 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4918 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4919 .port_get_cmode = mv88e6352_port_get_cmode,
4920 .port_set_cmode = mv88e6393x_port_set_cmode,
4921 .port_setup_message_port = mv88e6xxx_setup_message_port,
4922 .port_set_upstream_port = mv88e6393x_port_set_upstream_port,
4923 .stats_snapshot = mv88e6390_g1_stats_snapshot,
4924 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
4925 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4926 .stats_get_strings = mv88e6320_stats_get_strings,
4927 .stats_get_stats = mv88e6390_stats_get_stats,
4928 /* .set_cpu_port is missing because this family does not support a global
4929 * CPU port, only per port CPU port which is set via
4930 * .port_set_upstream_port method.
4931 */
4932 .set_egress_port = mv88e6393x_set_egress_port,
4933 .watchdog_ops = &mv88e6390_watchdog_ops,
4934 .mgmt_rsvd2cpu = mv88e6393x_port_mgmt_rsvd2cpu,
4935 .pot_clear = mv88e6xxx_g2_pot_clear,
4936 .reset = mv88e6352_g1_reset,
4937 .rmu_disable = mv88e6390_g1_rmu_disable,
4938 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4939 .atu_set_hash = mv88e6165_g1_atu_set_hash,
4940 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4941 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
4942 .serdes_power = mv88e6393x_serdes_power,
4943 .serdes_get_lane = mv88e6393x_serdes_get_lane,
4944 .serdes_pcs_get_state = mv88e6393x_serdes_pcs_get_state,
4945 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4946 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4947 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
4948 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
4949 .serdes_irq_enable = mv88e6393x_serdes_irq_enable,
4950 .serdes_irq_status = mv88e6393x_serdes_irq_status,
4951 /* TODO: serdes stats */
4952 .gpio_ops = &mv88e6352_gpio_ops,
4953 .avb_ops = &mv88e6390_avb_ops,
4954 .ptp_ops = &mv88e6352_ptp_ops,
4955 .phylink_validate = mv88e6393x_phylink_validate,
4956};
4957
Vivien Didelotf81ec902016-05-09 13:22:58 -04004958static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4959 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004960 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004961 .family = MV88E6XXX_FAMILY_6097,
4962 .name = "Marvell 88E6085",
4963 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004964 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004965 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004966 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004967 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004968 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004969 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004970 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004971 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004972 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004973 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004974 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004975 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004976 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004977 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004978 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004979 },
4980
4981 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004982 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004983 .family = MV88E6XXX_FAMILY_6095,
4984 .name = "Marvell 88E6095/88E6095F",
4985 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004986 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004987 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004988 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004989 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004990 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004991 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004992 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004993 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004994 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004995 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004996 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004997 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004998 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004999 },
5000
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005001 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005002 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005003 .family = MV88E6XXX_FAMILY_6097,
5004 .name = "Marvell 88E6097/88E6097F",
5005 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005006 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005007 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01005008 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005009 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005010 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005011 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005012 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005013 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005014 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01005015 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005016 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005017 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005018 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005019 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005020 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01005021 .ops = &mv88e6097_ops,
5022 },
5023
Vivien Didelotf81ec902016-05-09 13:22:58 -04005024 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005025 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005026 .family = MV88E6XXX_FAMILY_6165,
5027 .name = "Marvell 88E6123",
5028 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005029 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005030 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01005031 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005032 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005033 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005034 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005035 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005036 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005037 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005038 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005039 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005040 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005041 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005042 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005043 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005044 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005045 },
5046
5047 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005048 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005049 .family = MV88E6XXX_FAMILY_6185,
5050 .name = "Marvell 88E6131",
5051 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005052 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005053 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005054 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005055 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005056 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005057 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005058 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005059 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005060 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005061 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05005062 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005063 .multi_chip = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005064 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005065 },
5066
Vivien Didelot990e27b2017-03-28 13:50:32 -04005067 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005068 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005069 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01005070 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04005071 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005072 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005073 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005074 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005075 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005076 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005077 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005078 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005079 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005080 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005081 .age_time_coeff = 3750,
5082 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005083 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005084 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005085 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005086 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005087 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelot990e27b2017-03-28 13:50:32 -04005088 .ops = &mv88e6141_ops,
5089 },
5090
Vivien Didelotf81ec902016-05-09 13:22:58 -04005091 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005092 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005093 .family = MV88E6XXX_FAMILY_6165,
5094 .name = "Marvell 88E6161",
5095 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005096 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005097 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005098 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005099 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005100 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005101 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005102 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005103 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005104 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005105 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005106 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005107 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005108 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005109 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005110 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Andrew Lunndfa54342018-07-18 22:38:22 +02005111 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005112 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005113 },
5114
5115 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005116 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005117 .family = MV88E6XXX_FAMILY_6165,
5118 .name = "Marvell 88E6165",
5119 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005120 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005121 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01005122 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005123 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005124 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005125 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005126 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005127 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005128 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005129 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005130 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005131 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005132 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005133 .multi_chip = true,
Andrew Lunndfa54342018-07-18 22:38:22 +02005134 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005135 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005136 },
5137
5138 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005139 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005140 .family = MV88E6XXX_FAMILY_6351,
5141 .name = "Marvell 88E6171",
5142 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005143 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005144 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005145 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005146 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005147 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005148 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005149 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005150 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005151 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005152 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005153 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005154 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005155 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005156 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005157 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005158 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005159 },
5160
5161 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005162 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005163 .family = MV88E6XXX_FAMILY_6352,
5164 .name = "Marvell 88E6172",
5165 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005166 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005167 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005168 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005169 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005170 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005171 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005172 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005173 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005174 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005175 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005176 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005177 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005178 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005179 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005180 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005181 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005182 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005183 },
5184
5185 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005186 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005187 .family = MV88E6XXX_FAMILY_6351,
5188 .name = "Marvell 88E6175",
5189 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005190 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005191 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005192 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005193 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005194 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005195 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005196 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005197 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005198 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005199 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005200 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005201 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005202 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005203 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005204 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005205 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005206 },
5207
5208 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005209 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005210 .family = MV88E6XXX_FAMILY_6352,
5211 .name = "Marvell 88E6176",
5212 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005213 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005214 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005215 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005216 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005217 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005218 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005219 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005220 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005221 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005222 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005223 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005224 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005225 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005226 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005227 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005228 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005229 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005230 },
5231
5232 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005233 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005234 .family = MV88E6XXX_FAMILY_6185,
5235 .name = "Marvell 88E6185",
5236 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005237 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005238 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01005239 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005240 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005241 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005242 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005243 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005244 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005245 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005246 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05005247 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005248 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005249 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005250 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005251 },
5252
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005253 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005254 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005255 .family = MV88E6XXX_FAMILY_6390,
5256 .name = "Marvell 88E6190",
5257 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005258 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005259 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005260 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005261 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005262 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005263 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005264 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005265 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005266 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005267 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005268 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005269 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04005270 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005271 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05005272 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005273 .ops = &mv88e6190_ops,
5274 },
5275
5276 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005277 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005278 .family = MV88E6XXX_FAMILY_6390,
5279 .name = "Marvell 88E6190X",
5280 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005281 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005282 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005283 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005284 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005285 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005286 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005287 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005288 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005289 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005290 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005291 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005292 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005293 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005294 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005295 .multi_chip = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005296 .ops = &mv88e6190x_ops,
5297 },
5298
5299 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005300 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005301 .family = MV88E6XXX_FAMILY_6390,
5302 .name = "Marvell 88E6191",
5303 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005304 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005305 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005306 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04005307 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005308 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005309 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005310 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005311 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005312 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005313 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005314 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005315 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005316 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005317 .multi_chip = true,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005318 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04005319 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005320 },
5321
Pavana Sharmade776d02021-03-17 14:46:42 +01005322 [MV88E6191X] = {
5323 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191X,
5324 .family = MV88E6XXX_FAMILY_6393,
5325 .name = "Marvell 88E6191X",
5326 .num_databases = 4096,
5327 .num_ports = 11, /* 10 + Z80 */
5328 .num_internal_phys = 9,
5329 .max_vid = 8191,
5330 .port_base_addr = 0x0,
5331 .phy_base_addr = 0x0,
5332 .global1_addr = 0x1b,
5333 .global2_addr = 0x1c,
5334 .age_time_coeff = 3750,
5335 .g1_irqs = 10,
5336 .g2_irqs = 14,
5337 .atu_move_port_mask = 0x1f,
5338 .pvt = true,
5339 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005340 .ptp_support = true,
5341 .ops = &mv88e6393x_ops,
5342 },
5343
5344 [MV88E6193X] = {
5345 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6193X,
5346 .family = MV88E6XXX_FAMILY_6393,
5347 .name = "Marvell 88E6193X",
5348 .num_databases = 4096,
5349 .num_ports = 11, /* 10 + Z80 */
5350 .num_internal_phys = 9,
5351 .max_vid = 8191,
5352 .port_base_addr = 0x0,
5353 .phy_base_addr = 0x0,
5354 .global1_addr = 0x1b,
5355 .global2_addr = 0x1c,
5356 .age_time_coeff = 3750,
5357 .g1_irqs = 10,
5358 .g2_irqs = 14,
5359 .atu_move_port_mask = 0x1f,
5360 .pvt = true,
5361 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005362 .ptp_support = true,
5363 .ops = &mv88e6393x_ops,
5364 },
5365
Hubert Feurstein49022642019-07-31 10:23:46 +02005366 [MV88E6220] = {
5367 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
5368 .family = MV88E6XXX_FAMILY_6250,
5369 .name = "Marvell 88E6220",
5370 .num_databases = 64,
5371
5372 /* Ports 2-4 are not routed to pins
5373 * => usable ports 0, 1, 5, 6
5374 */
5375 .num_ports = 7,
5376 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02005377 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02005378 .max_vid = 4095,
5379 .port_base_addr = 0x08,
5380 .phy_base_addr = 0x00,
5381 .global1_addr = 0x0f,
5382 .global2_addr = 0x07,
5383 .age_time_coeff = 15000,
5384 .g1_irqs = 9,
5385 .g2_irqs = 10,
5386 .atu_move_port_mask = 0xf,
5387 .dual_chip = true,
Hubert Feurstein71509612019-07-31 10:23:51 +02005388 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02005389 .ops = &mv88e6250_ops,
5390 },
5391
Vivien Didelotf81ec902016-05-09 13:22:58 -04005392 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005393 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005394 .family = MV88E6XXX_FAMILY_6352,
5395 .name = "Marvell 88E6240",
5396 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005397 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005398 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005399 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005400 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005401 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005402 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005403 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005404 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005405 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005406 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005407 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005408 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005409 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005410 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005411 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005412 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005413 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005414 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005415 },
5416
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005417 [MV88E6250] = {
5418 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
5419 .family = MV88E6XXX_FAMILY_6250,
5420 .name = "Marvell 88E6250",
5421 .num_databases = 64,
5422 .num_ports = 7,
5423 .num_internal_phys = 5,
5424 .max_vid = 4095,
5425 .port_base_addr = 0x08,
5426 .phy_base_addr = 0x00,
5427 .global1_addr = 0x0f,
5428 .global2_addr = 0x07,
5429 .age_time_coeff = 15000,
5430 .g1_irqs = 9,
5431 .g2_irqs = 10,
5432 .atu_move_port_mask = 0xf,
5433 .dual_chip = true,
Hubert Feurstein71509612019-07-31 10:23:51 +02005434 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005435 .ops = &mv88e6250_ops,
5436 },
5437
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005438 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005439 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005440 .family = MV88E6XXX_FAMILY_6390,
5441 .name = "Marvell 88E6290",
5442 .num_databases = 4096,
5443 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005444 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005445 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005446 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005447 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005448 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005449 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005450 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005451 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005452 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005453 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005454 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005455 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005456 .multi_chip = true,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005457 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005458 .ops = &mv88e6290_ops,
5459 },
5460
Vivien Didelotf81ec902016-05-09 13:22:58 -04005461 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005462 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005463 .family = MV88E6XXX_FAMILY_6320,
5464 .name = "Marvell 88E6320",
5465 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005466 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005467 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005468 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005469 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005470 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005471 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005472 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005473 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005474 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005475 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005476 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005477 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005478 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005479 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005480 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005481 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005482 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005483 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005484 },
5485
5486 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005487 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005488 .family = MV88E6XXX_FAMILY_6320,
5489 .name = "Marvell 88E6321",
5490 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005491 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005492 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005493 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005494 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005495 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005496 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005497 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005498 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005499 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005500 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005501 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005502 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005503 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005504 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005505 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005506 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005507 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005508 },
5509
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005510 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005511 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005512 .family = MV88E6XXX_FAMILY_6341,
5513 .name = "Marvell 88E6341",
5514 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005515 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005516 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005517 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005518 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005519 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005520 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005521 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005522 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005523 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005524 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005525 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005526 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005527 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005528 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005529 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005530 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005531 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005532 .ops = &mv88e6341_ops,
5533 },
5534
Vivien Didelotf81ec902016-05-09 13:22:58 -04005535 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005536 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005537 .family = MV88E6XXX_FAMILY_6351,
5538 .name = "Marvell 88E6350",
5539 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005540 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005541 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005542 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005543 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005544 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005545 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005546 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005547 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005548 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005549 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005550 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005551 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005552 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005553 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005554 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005555 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005556 },
5557
5558 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005559 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005560 .family = MV88E6XXX_FAMILY_6351,
5561 .name = "Marvell 88E6351",
5562 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005563 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005564 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005565 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005566 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005567 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005568 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005569 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005570 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005571 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005572 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005573 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005574 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005575 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005576 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005577 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005578 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005579 },
5580
5581 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005582 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005583 .family = MV88E6XXX_FAMILY_6352,
5584 .name = "Marvell 88E6352",
5585 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005586 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005587 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005588 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005589 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005590 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005591 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005592 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005593 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005594 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005595 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005596 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005597 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005598 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005599 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005600 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005601 .edsa_support = MV88E6XXX_EDSA_SUPPORTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005602 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005603 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005604 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005605 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005606 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005607 .family = MV88E6XXX_FAMILY_6390,
5608 .name = "Marvell 88E6390",
5609 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005610 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005611 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005612 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005613 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005614 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005615 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005616 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005617 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005618 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005619 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005620 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005621 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005622 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005623 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005624 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005625 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005626 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005627 .ops = &mv88e6390_ops,
5628 },
5629 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005630 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005631 .family = MV88E6XXX_FAMILY_6390,
5632 .name = "Marvell 88E6390X",
5633 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005634 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005635 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005636 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005637 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005638 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005639 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005640 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005641 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005642 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005643 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005644 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005645 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005646 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005647 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005648 .multi_chip = true,
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005649 .edsa_support = MV88E6XXX_EDSA_UNDOCUMENTED,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005650 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005651 .ops = &mv88e6390x_ops,
5652 },
Pavana Sharmade776d02021-03-17 14:46:42 +01005653
5654 [MV88E6393X] = {
5655 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6393X,
5656 .family = MV88E6XXX_FAMILY_6393,
5657 .name = "Marvell 88E6393X",
5658 .num_databases = 4096,
5659 .num_ports = 11, /* 10 + Z80 */
5660 .num_internal_phys = 9,
5661 .max_vid = 8191,
5662 .port_base_addr = 0x0,
5663 .phy_base_addr = 0x0,
5664 .global1_addr = 0x1b,
5665 .global2_addr = 0x1c,
5666 .age_time_coeff = 3750,
5667 .g1_irqs = 10,
5668 .g2_irqs = 14,
5669 .atu_move_port_mask = 0x1f,
5670 .pvt = true,
5671 .multi_chip = true,
Pavana Sharmade776d02021-03-17 14:46:42 +01005672 .ptp_support = true,
5673 .ops = &mv88e6393x_ops,
5674 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005675};
5676
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005677static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005678{
Vivien Didelota439c062016-04-17 13:23:58 -04005679 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005680
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005681 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5682 if (mv88e6xxx_table[i].prod_num == prod_num)
5683 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005684
Vivien Didelotb9b37712015-10-30 19:39:48 -04005685 return NULL;
5686}
5687
Vivien Didelotfad09c72016-06-21 12:28:20 -04005688static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005689{
5690 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005691 unsigned int prod_num, rev;
5692 u16 id;
5693 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005694
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005695 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005696 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005697 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005698 if (err)
5699 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005700
Vivien Didelot107fcc12017-06-12 12:37:36 -04005701 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5702 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005703
5704 info = mv88e6xxx_lookup_info(prod_num);
5705 if (!info)
5706 return -ENODEV;
5707
Vivien Didelotcaac8542016-06-20 13:14:09 -04005708 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005709 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005710
Vivien Didelotfad09c72016-06-21 12:28:20 -04005711 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5712 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005713
5714 return 0;
5715}
5716
Vivien Didelotfad09c72016-06-21 12:28:20 -04005717static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005718{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005719 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005720
Vivien Didelotfad09c72016-06-21 12:28:20 -04005721 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5722 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005723 return NULL;
5724
Vivien Didelotfad09c72016-06-21 12:28:20 -04005725 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005726
Vivien Didelotfad09c72016-06-21 12:28:20 -04005727 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005728 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005729 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005730
Vivien Didelotfad09c72016-06-21 12:28:20 -04005731 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005732}
5733
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005734static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005735 int port,
5736 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005737{
Vivien Didelot04bed142016-08-31 18:06:13 -04005738 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005739
Tobias Waldekranz670bb802021-04-20 20:53:07 +02005740 return chip->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005741}
5742
Tobias Waldekranz9a99bef2021-04-20 20:53:08 +02005743static int mv88e6xxx_change_tag_protocol(struct dsa_switch *ds, int port,
5744 enum dsa_tag_protocol proto)
5745{
5746 struct mv88e6xxx_chip *chip = ds->priv;
5747 enum dsa_tag_protocol old_protocol;
5748 int err;
5749
5750 switch (proto) {
5751 case DSA_TAG_PROTO_EDSA:
5752 switch (chip->info->edsa_support) {
5753 case MV88E6XXX_EDSA_UNSUPPORTED:
5754 return -EPROTONOSUPPORT;
5755 case MV88E6XXX_EDSA_UNDOCUMENTED:
5756 dev_warn(chip->dev, "Relying on undocumented EDSA tagging behavior\n");
5757 fallthrough;
5758 case MV88E6XXX_EDSA_SUPPORTED:
5759 break;
5760 }
5761 break;
5762 case DSA_TAG_PROTO_DSA:
5763 break;
5764 default:
5765 return -EPROTONOSUPPORT;
5766 }
5767
5768 old_protocol = chip->tag_protocol;
5769 chip->tag_protocol = proto;
5770
5771 mv88e6xxx_reg_lock(chip);
5772 err = mv88e6xxx_setup_port_mode(chip, port);
5773 mv88e6xxx_reg_unlock(chip);
5774
5775 if (err)
5776 chip->tag_protocol = old_protocol;
5777
5778 return err;
5779}
5780
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005781static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
5782 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005783{
Vivien Didelot04bed142016-08-31 18:06:13 -04005784 struct mv88e6xxx_chip *chip = ds->priv;
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005785 int err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005786
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005787 mv88e6xxx_reg_lock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005788 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
5789 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005790 mv88e6xxx_reg_unlock(chip);
Vladimir Olteana52b2da2021-01-09 02:01:52 +02005791
5792 return err;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005793}
5794
5795static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5796 const struct switchdev_obj_port_mdb *mdb)
5797{
Vivien Didelot04bed142016-08-31 18:06:13 -04005798 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005799 int err;
5800
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005801 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005802 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005803 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005804
5805 return err;
5806}
5807
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005808static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5809 struct dsa_mall_mirror_tc_entry *mirror,
5810 bool ingress)
5811{
5812 enum mv88e6xxx_egress_direction direction = ingress ?
5813 MV88E6XXX_EGRESS_DIR_INGRESS :
5814 MV88E6XXX_EGRESS_DIR_EGRESS;
5815 struct mv88e6xxx_chip *chip = ds->priv;
5816 bool other_mirrors = false;
5817 int i;
5818 int err;
5819
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005820 mutex_lock(&chip->reg_lock);
5821 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5822 mirror->to_local_port) {
5823 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5824 other_mirrors |= ingress ?
5825 chip->ports[i].mirror_ingress :
5826 chip->ports[i].mirror_egress;
5827
5828 /* Can't change egress port when other mirror is active */
5829 if (other_mirrors) {
5830 err = -EBUSY;
5831 goto out;
5832 }
5833
Marek Behún2fda45f2021-03-17 14:46:41 +01005834 err = mv88e6xxx_set_egress_port(chip, direction,
5835 mirror->to_local_port);
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005836 if (err)
5837 goto out;
5838 }
5839
5840 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5841out:
5842 mutex_unlock(&chip->reg_lock);
5843
5844 return err;
5845}
5846
5847static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5848 struct dsa_mall_mirror_tc_entry *mirror)
5849{
5850 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5851 MV88E6XXX_EGRESS_DIR_INGRESS :
5852 MV88E6XXX_EGRESS_DIR_EGRESS;
5853 struct mv88e6xxx_chip *chip = ds->priv;
5854 bool other_mirrors = false;
5855 int i;
5856
5857 mutex_lock(&chip->reg_lock);
5858 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5859 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5860
5861 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5862 other_mirrors |= mirror->ingress ?
5863 chip->ports[i].mirror_ingress :
5864 chip->ports[i].mirror_egress;
5865
5866 /* Reset egress port when no other mirror is active */
5867 if (!other_mirrors) {
Marek Behún2fda45f2021-03-17 14:46:41 +01005868 if (mv88e6xxx_set_egress_port(chip, direction,
5869 dsa_upstream_port(ds, port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005870 dev_err(ds->dev, "failed to set egress port\n");
5871 }
5872
5873 mutex_unlock(&chip->reg_lock);
5874}
5875
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005876static int mv88e6xxx_port_pre_bridge_flags(struct dsa_switch *ds, int port,
5877 struct switchdev_brport_flags flags,
5878 struct netlink_ext_ack *extack)
5879{
5880 struct mv88e6xxx_chip *chip = ds->priv;
5881 const struct mv88e6xxx_ops *ops;
5882
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01005883 if (flags.mask & ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD |
5884 BR_BCAST_FLOOD))
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005885 return -EINVAL;
5886
5887 ops = chip->info->ops;
5888
5889 if ((flags.mask & BR_FLOOD) && !ops->port_set_ucast_flood)
5890 return -EINVAL;
5891
5892 if ((flags.mask & BR_MCAST_FLOOD) && !ops->port_set_mcast_flood)
5893 return -EINVAL;
5894
5895 return 0;
5896}
5897
5898static int mv88e6xxx_port_bridge_flags(struct dsa_switch *ds, int port,
5899 struct switchdev_brport_flags flags,
5900 struct netlink_ext_ack *extack)
Russell King4f859012019-02-20 15:35:05 -08005901{
5902 struct mv88e6xxx_chip *chip = ds->priv;
5903 int err = -EOPNOTSUPP;
5904
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005905 mv88e6xxx_reg_lock(chip);
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005906
Tobias Waldekranz041bd542021-03-18 20:25:39 +01005907 if (flags.mask & BR_LEARNING) {
5908 bool learning = !!(flags.val & BR_LEARNING);
5909 u16 pav = learning ? (1 << port) : 0;
5910
5911 err = mv88e6xxx_port_set_assoc_vector(chip, port, pav);
5912 if (err)
5913 goto out;
Tobias Waldekranz041bd542021-03-18 20:25:39 +01005914 }
5915
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005916 if (flags.mask & BR_FLOOD) {
5917 bool unicast = !!(flags.val & BR_FLOOD);
5918
5919 err = chip->info->ops->port_set_ucast_flood(chip, port,
5920 unicast);
5921 if (err)
5922 goto out;
5923 }
5924
5925 if (flags.mask & BR_MCAST_FLOOD) {
5926 bool multicast = !!(flags.val & BR_MCAST_FLOOD);
5927
5928 err = chip->info->ops->port_set_mcast_flood(chip, port,
5929 multicast);
5930 if (err)
5931 goto out;
5932 }
5933
Tobias Waldekranz8d1d8292021-03-18 20:25:40 +01005934 if (flags.mask & BR_BCAST_FLOOD) {
5935 bool broadcast = !!(flags.val & BR_BCAST_FLOOD);
5936
5937 err = mv88e6xxx_port_broadcast_sync(chip, port, broadcast);
5938 if (err)
5939 goto out;
5940 }
5941
Vladimir Olteana8b659e2021-02-12 17:15:56 +02005942out:
5943 mv88e6xxx_reg_unlock(chip);
5944
5945 return err;
5946}
5947
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005948static bool mv88e6xxx_lag_can_offload(struct dsa_switch *ds,
5949 struct net_device *lag,
5950 struct netdev_lag_upper_info *info)
5951{
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005952 struct mv88e6xxx_chip *chip = ds->priv;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005953 struct dsa_port *dp;
5954 int id, members = 0;
5955
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01005956 if (!mv88e6xxx_has_lag(chip))
5957 return false;
5958
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01005959 id = dsa_lag_id(ds->dst, lag);
5960 if (id < 0 || id >= ds->num_lag_ids)
5961 return false;
5962
5963 dsa_lag_foreach_port(dp, ds->dst, lag)
5964 /* Includes the port joining the LAG */
5965 members++;
5966
5967 if (members > 8)
5968 return false;
5969
5970 /* We could potentially relax this to include active
5971 * backup in the future.
5972 */
5973 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
5974 return false;
5975
5976 /* Ideally we would also validate that the hash type matches
5977 * the hardware. Alas, this is always set to unknown on team
5978 * interfaces.
5979 */
5980 return true;
5981}
5982
5983static int mv88e6xxx_lag_sync_map(struct dsa_switch *ds, struct net_device *lag)
5984{
5985 struct mv88e6xxx_chip *chip = ds->priv;
5986 struct dsa_port *dp;
5987 u16 map = 0;
5988 int id;
5989
5990 id = dsa_lag_id(ds->dst, lag);
5991
5992 /* Build the map of all ports to distribute flows destined for
5993 * this LAG. This can be either a local user port, or a DSA
5994 * port if the LAG port is on a remote chip.
5995 */
5996 dsa_lag_foreach_port(dp, ds->dst, lag)
5997 map |= BIT(dsa_towards_port(ds, dp->ds->index, dp->index));
5998
5999 return mv88e6xxx_g2_trunk_mapping_write(chip, id, map);
6000}
6001
6002static const u8 mv88e6xxx_lag_mask_table[8][8] = {
6003 /* Row number corresponds to the number of active members in a
6004 * LAG. Each column states which of the eight hash buckets are
6005 * mapped to the column:th port in the LAG.
6006 *
6007 * Example: In a LAG with three active ports, the second port
6008 * ([2][1]) would be selected for traffic mapped to buckets
6009 * 3,4,5 (0x38).
6010 */
6011 { 0xff, 0, 0, 0, 0, 0, 0, 0 },
6012 { 0x0f, 0xf0, 0, 0, 0, 0, 0, 0 },
6013 { 0x07, 0x38, 0xc0, 0, 0, 0, 0, 0 },
6014 { 0x03, 0x0c, 0x30, 0xc0, 0, 0, 0, 0 },
6015 { 0x03, 0x0c, 0x30, 0x40, 0x80, 0, 0, 0 },
6016 { 0x03, 0x0c, 0x10, 0x20, 0x40, 0x80, 0, 0 },
6017 { 0x03, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0 },
6018 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 },
6019};
6020
6021static void mv88e6xxx_lag_set_port_mask(u16 *mask, int port,
6022 int num_tx, int nth)
6023{
6024 u8 active = 0;
6025 int i;
6026
6027 num_tx = num_tx <= 8 ? num_tx : 8;
6028 if (nth < num_tx)
6029 active = mv88e6xxx_lag_mask_table[num_tx - 1][nth];
6030
6031 for (i = 0; i < 8; i++) {
6032 if (BIT(i) & active)
6033 mask[i] |= BIT(port);
6034 }
6035}
6036
6037static int mv88e6xxx_lag_sync_masks(struct dsa_switch *ds)
6038{
6039 struct mv88e6xxx_chip *chip = ds->priv;
6040 unsigned int id, num_tx;
6041 struct net_device *lag;
6042 struct dsa_port *dp;
6043 int i, err, nth;
6044 u16 mask[8];
6045 u16 ivec;
6046
6047 /* Assume no port is a member of any LAG. */
6048 ivec = BIT(mv88e6xxx_num_ports(chip)) - 1;
6049
6050 /* Disable all masks for ports that _are_ members of a LAG. */
6051 list_for_each_entry(dp, &ds->dst->ports, list) {
6052 if (!dp->lag_dev || dp->ds != ds)
6053 continue;
6054
6055 ivec &= ~BIT(dp->index);
6056 }
6057
6058 for (i = 0; i < 8; i++)
6059 mask[i] = ivec;
6060
6061 /* Enable the correct subset of masks for all LAG ports that
6062 * are in the Tx set.
6063 */
6064 dsa_lags_foreach_id(id, ds->dst) {
6065 lag = dsa_lag_dev(ds->dst, id);
6066 if (!lag)
6067 continue;
6068
6069 num_tx = 0;
6070 dsa_lag_foreach_port(dp, ds->dst, lag) {
6071 if (dp->lag_tx_enabled)
6072 num_tx++;
6073 }
6074
6075 if (!num_tx)
6076 continue;
6077
6078 nth = 0;
6079 dsa_lag_foreach_port(dp, ds->dst, lag) {
6080 if (!dp->lag_tx_enabled)
6081 continue;
6082
6083 if (dp->ds == ds)
6084 mv88e6xxx_lag_set_port_mask(mask, dp->index,
6085 num_tx, nth);
6086
6087 nth++;
6088 }
6089 }
6090
6091 for (i = 0; i < 8; i++) {
6092 err = mv88e6xxx_g2_trunk_mask_write(chip, i, true, mask[i]);
6093 if (err)
6094 return err;
6095 }
6096
6097 return 0;
6098}
6099
6100static int mv88e6xxx_lag_sync_masks_map(struct dsa_switch *ds,
6101 struct net_device *lag)
6102{
6103 int err;
6104
6105 err = mv88e6xxx_lag_sync_masks(ds);
6106
6107 if (!err)
6108 err = mv88e6xxx_lag_sync_map(ds, lag);
6109
6110 return err;
6111}
6112
6113static int mv88e6xxx_port_lag_change(struct dsa_switch *ds, int port)
6114{
6115 struct mv88e6xxx_chip *chip = ds->priv;
6116 int err;
6117
6118 mv88e6xxx_reg_lock(chip);
6119 err = mv88e6xxx_lag_sync_masks(ds);
6120 mv88e6xxx_reg_unlock(chip);
6121 return err;
6122}
6123
6124static int mv88e6xxx_port_lag_join(struct dsa_switch *ds, int port,
6125 struct net_device *lag,
6126 struct netdev_lag_upper_info *info)
6127{
6128 struct mv88e6xxx_chip *chip = ds->priv;
6129 int err, id;
6130
6131 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
6132 return -EOPNOTSUPP;
6133
6134 id = dsa_lag_id(ds->dst, lag);
6135
6136 mv88e6xxx_reg_lock(chip);
6137
6138 err = mv88e6xxx_port_set_trunk(chip, port, true, id);
6139 if (err)
6140 goto err_unlock;
6141
6142 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6143 if (err)
6144 goto err_clear_trunk;
6145
6146 mv88e6xxx_reg_unlock(chip);
6147 return 0;
6148
6149err_clear_trunk:
6150 mv88e6xxx_port_set_trunk(chip, port, false, 0);
6151err_unlock:
6152 mv88e6xxx_reg_unlock(chip);
6153 return err;
6154}
6155
6156static int mv88e6xxx_port_lag_leave(struct dsa_switch *ds, int port,
6157 struct net_device *lag)
6158{
6159 struct mv88e6xxx_chip *chip = ds->priv;
6160 int err_sync, err_trunk;
6161
6162 mv88e6xxx_reg_lock(chip);
6163 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6164 err_trunk = mv88e6xxx_port_set_trunk(chip, port, false, 0);
6165 mv88e6xxx_reg_unlock(chip);
6166 return err_sync ? : err_trunk;
6167}
6168
6169static int mv88e6xxx_crosschip_lag_change(struct dsa_switch *ds, int sw_index,
6170 int port)
6171{
6172 struct mv88e6xxx_chip *chip = ds->priv;
6173 int err;
6174
6175 mv88e6xxx_reg_lock(chip);
6176 err = mv88e6xxx_lag_sync_masks(ds);
6177 mv88e6xxx_reg_unlock(chip);
6178 return err;
6179}
6180
6181static int mv88e6xxx_crosschip_lag_join(struct dsa_switch *ds, int sw_index,
6182 int port, struct net_device *lag,
6183 struct netdev_lag_upper_info *info)
6184{
6185 struct mv88e6xxx_chip *chip = ds->priv;
6186 int err;
6187
6188 if (!mv88e6xxx_lag_can_offload(ds, lag, info))
6189 return -EOPNOTSUPP;
6190
6191 mv88e6xxx_reg_lock(chip);
6192
6193 err = mv88e6xxx_lag_sync_masks_map(ds, lag);
6194 if (err)
6195 goto unlock;
6196
6197 err = mv88e6xxx_pvt_map(chip, sw_index, port);
6198
6199unlock:
6200 mv88e6xxx_reg_unlock(chip);
6201 return err;
6202}
6203
6204static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
6205 int port, struct net_device *lag)
6206{
6207 struct mv88e6xxx_chip *chip = ds->priv;
6208 int err_sync, err_pvt;
6209
6210 mv88e6xxx_reg_lock(chip);
6211 err_sync = mv88e6xxx_lag_sync_masks_map(ds, lag);
6212 err_pvt = mv88e6xxx_pvt_map(chip, sw_index, port);
6213 mv88e6xxx_reg_unlock(chip);
6214 return err_sync ? : err_pvt;
6215}
6216
Florian Fainellia82f67a2017-01-08 14:52:08 -08006217static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02006218 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Tobias Waldekranz9a99bef2021-04-20 20:53:08 +02006219 .change_tag_protocol = mv88e6xxx_change_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006220 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02006221 .teardown = mv88e6xxx_teardown,
Vladimir Olteanfd292c12021-09-17 17:29:16 +03006222 .port_setup = mv88e6xxx_port_setup,
6223 .port_teardown = mv88e6xxx_port_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07006224 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00006225 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07006226 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00006227 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07006228 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
6229 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006230 .get_strings = mv88e6xxx_get_strings,
6231 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
6232 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02006233 .port_enable = mv88e6xxx_port_enable,
6234 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02006235 .port_max_mtu = mv88e6xxx_get_max_mtu,
6236 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04006237 .get_mac_eee = mv88e6xxx_get_mac_eee,
6238 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006239 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006240 .get_eeprom = mv88e6xxx_get_eeprom,
6241 .set_eeprom = mv88e6xxx_set_eeprom,
6242 .get_regs_len = mv88e6xxx_get_regs_len,
6243 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04006244 .get_rxnfc = mv88e6xxx_get_rxnfc,
6245 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04006246 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006247 .port_bridge_join = mv88e6xxx_port_bridge_join,
6248 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Vladimir Olteana8b659e2021-02-12 17:15:56 +02006249 .port_pre_bridge_flags = mv88e6xxx_port_pre_bridge_flags,
6250 .port_bridge_flags = mv88e6xxx_port_bridge_flags,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006251 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04006252 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006253 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006254 .port_vlan_add = mv88e6xxx_port_vlan_add,
6255 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006256 .port_fdb_add = mv88e6xxx_port_fdb_add,
6257 .port_fdb_del = mv88e6xxx_port_fdb_del,
6258 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04006259 .port_mdb_add = mv88e6xxx_port_mdb_add,
6260 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01006261 .port_mirror_add = mv88e6xxx_port_mirror_add,
6262 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04006263 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
6264 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006265 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
6266 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
6267 .port_txtstamp = mv88e6xxx_port_txtstamp,
6268 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
6269 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02006270 .devlink_param_get = mv88e6xxx_devlink_param_get,
6271 .devlink_param_set = mv88e6xxx_devlink_param_set,
Andrew Lunn93157302020-09-18 21:11:09 +02006272 .devlink_info_get = mv88e6xxx_devlink_info_get,
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006273 .port_lag_change = mv88e6xxx_port_lag_change,
6274 .port_lag_join = mv88e6xxx_port_lag_join,
6275 .port_lag_leave = mv88e6xxx_port_lag_leave,
6276 .crosschip_lag_change = mv88e6xxx_crosschip_lag_change,
6277 .crosschip_lag_join = mv88e6xxx_crosschip_lag_join,
6278 .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave,
Vladimir Olteance5df682021-07-22 18:55:41 +03006279 .port_bridge_tx_fwd_offload = mv88e6xxx_bridge_tx_fwd_offload,
6280 .port_bridge_tx_fwd_unoffload = mv88e6xxx_bridge_tx_fwd_unoffload,
Vivien Didelotf81ec902016-05-09 13:22:58 -04006281};
6282
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08006283static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006284{
Vivien Didelotfad09c72016-06-21 12:28:20 -04006285 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006286 struct dsa_switch *ds;
6287
Vivien Didelot7e99e342019-10-21 16:51:30 -04006288 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006289 if (!ds)
6290 return -ENOMEM;
6291
Vivien Didelot7e99e342019-10-21 16:51:30 -04006292 ds->dev = dev;
6293 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006294 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006295 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04006296 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04006297 ds->ageing_time_min = chip->info->age_time_coeff;
6298 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006299
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006300 /* Some chips support up to 32, but that requires enabling the
6301 * 5-bit port mode, which we do not support. 640k^W16 ought to
6302 * be enough for anyone.
6303 */
Tobias Waldekranzb80dc512021-01-15 13:52:59 +01006304 ds->num_lag_ids = mv88e6xxx_has_lag(chip) ? 16 : 0;
Tobias Waldekranz57e661a2021-01-13 09:42:54 +01006305
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006306 dev_set_drvdata(dev, ds);
6307
Vivien Didelot23c9ee42017-05-26 18:12:51 -04006308 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006309}
6310
Vivien Didelotfad09c72016-06-21 12:28:20 -04006311static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006312{
Vivien Didelotfad09c72016-06-21 12:28:20 -04006313 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04006314}
6315
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006316static const void *pdata_device_get_match_data(struct device *dev)
6317{
6318 const struct of_device_id *matches = dev->driver->of_match_table;
6319 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
6320
6321 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
6322 matches++) {
6323 if (!strcmp(pdata->compatible, matches->compatible))
6324 return matches->data;
6325 }
6326 return NULL;
6327}
6328
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006329/* There is no suspend to RAM support at DSA level yet, the switch configuration
6330 * would be lost after a power cycle so prevent it to be suspended.
6331 */
6332static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
6333{
6334 return -EOPNOTSUPP;
6335}
6336
6337static int __maybe_unused mv88e6xxx_resume(struct device *dev)
6338{
6339 return 0;
6340}
6341
6342static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
6343
Vivien Didelot57d32312016-06-20 13:13:58 -04006344static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006345{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006346 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04006347 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006348 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006349 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04006350 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006351 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02006352 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006353
Andrew Lunn7bb8c992018-05-31 00:15:42 +02006354 if (!np && !pdata)
6355 return -EINVAL;
6356
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006357 if (np)
6358 compat_info = of_device_get_match_data(dev);
6359
6360 if (pdata) {
6361 compat_info = pdata_device_get_match_data(dev);
6362
6363 if (!pdata->netdev)
6364 return -EINVAL;
6365
6366 for (port = 0; port < DSA_MAX_PORTS; port++) {
6367 if (!(pdata->enabled_ports & (1 << port)))
6368 continue;
6369 if (strcmp(pdata->cd.port_names[port], "cpu"))
6370 continue;
6371 pdata->cd.netdev[port] = &pdata->netdev->dev;
6372 break;
6373 }
6374 }
6375
Vivien Didelotcaac8542016-06-20 13:14:09 -04006376 if (!compat_info)
6377 return -EINVAL;
6378
Vivien Didelotfad09c72016-06-21 12:28:20 -04006379 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006380 if (!chip) {
6381 err = -ENOMEM;
6382 goto out;
6383 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006384
Vivien Didelotfad09c72016-06-21 12:28:20 -04006385 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04006386
Vivien Didelotfad09c72016-06-21 12:28:20 -04006387 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04006388 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006389 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006390
Andrew Lunnb4308f02016-11-21 23:26:55 +01006391 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006392 if (IS_ERR(chip->reset)) {
6393 err = PTR_ERR(chip->reset);
6394 goto out;
6395 }
Baruch Siach7b75e492019-06-27 21:17:39 +03006396 if (chip->reset)
6397 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01006398
Vivien Didelotfad09c72016-06-21 12:28:20 -04006399 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04006400 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006401 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006402
Tobias Waldekranz670bb802021-04-20 20:53:07 +02006403 if (chip->info->edsa_support == MV88E6XXX_EDSA_SUPPORTED)
6404 chip->tag_protocol = DSA_TAG_PROTO_EDSA;
6405 else
6406 chip->tag_protocol = DSA_TAG_PROTO_DSA;
6407
Vivien Didelote57e5e72016-08-15 17:19:00 -04006408 mv88e6xxx_phy_init(chip);
6409
Andrew Lunn00baabe2018-05-19 22:31:35 +02006410 if (chip->info->ops->get_eeprom) {
6411 if (np)
6412 of_property_read_u32(np, "eeprom-length",
6413 &chip->eeprom_len);
6414 else
6415 chip->eeprom_len = pdata->eeprom_len;
6416 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02006417
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006418 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006419 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006420 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02006421 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02006422 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02006423
Andrew Lunna27415d2019-05-01 00:10:50 +02006424 if (np) {
6425 chip->irq = of_irq_get(np, 0);
6426 if (chip->irq == -EPROBE_DEFER) {
6427 err = chip->irq;
6428 goto out;
6429 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02006430 }
6431
Andrew Lunna27415d2019-05-01 00:10:50 +02006432 if (pdata)
6433 chip->irq = pdata->irq;
6434
Andrew Lunn294d7112018-02-22 22:58:32 +01006435 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01006436 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01006437 * controllers
6438 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006439 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006440 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006441 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006442 else
6443 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00006444 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006445
Andrew Lunn294d7112018-02-22 22:58:32 +01006446 if (err)
6447 goto out;
6448
6449 if (chip->info->g2_irqs > 0) {
6450 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006451 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01006452 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02006453 }
6454
Andrew Lunn294d7112018-02-22 22:58:32 +01006455 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
6456 if (err)
6457 goto out_g2_irq;
6458
6459 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
6460 if (err)
6461 goto out_g1_atu_prob_irq;
6462
Andrew Lunna3c53be52017-01-24 14:53:50 +01006463 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02006464 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01006465 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02006466
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08006467 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006468 if (err)
6469 goto out_mdio;
6470
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006471 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02006472
6473out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01006474 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01006475out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006476 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01006477out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006478 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006479out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006480 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02006481 mv88e6xxx_g2_irq_free(chip);
6482out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01006483 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006484 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01006485 else
6486 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006487out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02006488 if (pdata)
6489 dev_put(pdata->netdev);
6490
Andrew Lunndc30c352016-10-16 19:56:49 +02006491 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006492}
6493
6494static void mv88e6xxx_remove(struct mdio_device *mdiodev)
6495{
6496 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006497 struct mv88e6xxx_chip *chip;
6498
6499 if (!ds)
6500 return;
6501
6502 chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006503
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006504 if (chip->info->ptp_support) {
6505 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006506 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01006507 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01006508
Andrew Lunn930188c2016-08-22 16:01:03 +02006509 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04006510 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01006511 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02006512
Andrew Lunn76f38f12018-03-17 20:21:09 +01006513 mv88e6xxx_g1_vtu_prob_irq_free(chip);
6514 mv88e6xxx_g1_atu_prob_irq_free(chip);
6515
6516 if (chip->info->g2_irqs > 0)
6517 mv88e6xxx_g2_irq_free(chip);
6518
Andrew Lunn76f38f12018-03-17 20:21:09 +01006519 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01006520 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01006521 else
6522 mv88e6xxx_irq_poll_free(chip);
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006523
6524 dev_set_drvdata(&mdiodev->dev, NULL);
6525}
6526
6527static void mv88e6xxx_shutdown(struct mdio_device *mdiodev)
6528{
6529 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
6530
6531 if (!ds)
6532 return;
6533
6534 dsa_switch_shutdown(ds);
6535
6536 dev_set_drvdata(&mdiodev->dev, NULL);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006537}
6538
6539static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04006540 {
6541 .compatible = "marvell,mv88e6085",
6542 .data = &mv88e6xxx_table[MV88E6085],
6543 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01006544 {
6545 .compatible = "marvell,mv88e6190",
6546 .data = &mv88e6xxx_table[MV88E6190],
6547 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00006548 {
6549 .compatible = "marvell,mv88e6250",
6550 .data = &mv88e6xxx_table[MV88E6250],
6551 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006552 { /* sentinel */ },
6553};
6554
6555MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
6556
6557static struct mdio_driver mv88e6xxx_driver = {
6558 .probe = mv88e6xxx_probe,
6559 .remove = mv88e6xxx_remove,
Vladimir Oltean0650bf52021-09-17 16:34:33 +03006560 .shutdown = mv88e6xxx_shutdown,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006561 .mdiodrv.driver = {
6562 .name = "mv88e6085",
6563 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01006564 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02006565 },
6566};
6567
Andrew Lunn7324d502019-04-27 19:19:10 +02006568mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00006569
6570MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
6571MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
6572MODULE_LICENSE("GPL");