blob: 510ccdc2d03ccbdabff237bfb6ea29795658f941 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00002/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04003 * Marvell 88e6xxx Ethernet switch single-chip support
4 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00005 * Copyright (c) 2008 Marvell Semiconductor
6 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02007 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
8 *
Vivien Didelot4333d612017-03-28 15:10:36 -04009 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
10 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 */
12
Vivien Didelot19fb7f62019-08-09 18:47:55 -040013#include <linux/bitfield.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000014#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070015#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020016#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070017#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020018#include <linux/interrupt.h>
19#include <linux/irq.h>
20#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000021#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000022#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020023#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000024#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040025#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020026#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020027#include <linux/of_mdio.h>
Andrew Lunn877b7cb2018-05-19 22:31:34 +020028#include <linux/platform_data/mv88e6xxx.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000029#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010030#include <linux/gpio/consumer.h>
Russell Kingc9a23562018-05-10 13:17:35 -070031#include <linux/phylink.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000032#include <net/dsa.h>
Vivien Didelotec561272016-09-02 14:45:33 -040033
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -040034#include "chip.h"
Vivien Didelota935c052016-09-29 12:21:53 -040035#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040036#include "global2.h"
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +010037#include "hwtstamp.h"
Andrew Lunn10fa5bf2017-05-26 01:03:20 +020038#include "phy.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010039#include "port.h"
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +010040#include "ptp.h"
Andrew Lunn6d917822017-05-26 01:03:21 +020041#include "serdes.h"
Vivien Didelote7ba0fa2019-05-03 19:28:22 -040042#include "smi.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000043
Vivien Didelotfad09c72016-06-21 12:28:20 -040044static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040045{
Vivien Didelotfad09c72016-06-21 12:28:20 -040046 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
47 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040048 dump_stack();
49 }
50}
51
Vivien Didelotec561272016-09-02 14:45:33 -040052int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -040053{
54 int err;
55
Vivien Didelotfad09c72016-06-21 12:28:20 -040056 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -040057
Vivien Didelotfad09c72016-06-21 12:28:20 -040058 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040059 if (err)
60 return err;
61
Vivien Didelotfad09c72016-06-21 12:28:20 -040062 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -040063 addr, reg, *val);
64
65 return 0;
66}
67
Vivien Didelotec561272016-09-02 14:45:33 -040068int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -040069{
70 int err;
71
Vivien Didelotfad09c72016-06-21 12:28:20 -040072 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -040073
Vivien Didelotfad09c72016-06-21 12:28:20 -040074 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040075 if (err)
76 return err;
77
Vivien Didelotfad09c72016-06-21 12:28:20 -040078 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -040079 addr, reg, val);
80
81 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000082}
83
Vivien Didelot683f2242019-08-09 18:47:54 -040084int mv88e6xxx_wait_mask(struct mv88e6xxx_chip *chip, int addr, int reg,
85 u16 mask, u16 val)
86{
87 u16 data;
88 int err;
89 int i;
90
91 /* There's no bus specific operation to wait for a mask */
92 for (i = 0; i < 16; i++) {
93 err = mv88e6xxx_read(chip, addr, reg, &data);
94 if (err)
95 return err;
96
97 if ((data & mask) == val)
98 return 0;
99
100 usleep_range(1000, 2000);
101 }
102
103 dev_err(chip->dev, "Timeout while waiting for switch\n");
104 return -ETIMEDOUT;
105}
106
Vivien Didelot19fb7f62019-08-09 18:47:55 -0400107int mv88e6xxx_wait_bit(struct mv88e6xxx_chip *chip, int addr, int reg,
108 int bit, int val)
109{
110 return mv88e6xxx_wait_mask(chip, addr, reg, BIT(bit),
111 val ? BIT(bit) : 0x0000);
112}
113
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200114struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
Andrew Lunna3c53be52017-01-24 14:53:50 +0100115{
116 struct mv88e6xxx_mdio_bus *mdio_bus;
117
118 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
119 list);
120 if (!mdio_bus)
121 return NULL;
122
123 return mdio_bus->bus;
124}
125
Andrew Lunndc30c352016-10-16 19:56:49 +0200126static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
127{
128 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
129 unsigned int n = d->hwirq;
130
131 chip->g1_irq.masked |= (1 << n);
132}
133
134static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
135{
136 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
137 unsigned int n = d->hwirq;
138
139 chip->g1_irq.masked &= ~(1 << n);
140}
141
Andrew Lunn294d7112018-02-22 22:58:32 +0100142static irqreturn_t mv88e6xxx_g1_irq_thread_work(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200143{
Andrew Lunndc30c352016-10-16 19:56:49 +0200144 unsigned int nhandled = 0;
145 unsigned int sub_irq;
146 unsigned int n;
147 u16 reg;
John David Anglin7c0db242019-02-11 13:40:21 -0500148 u16 ctl1;
Andrew Lunndc30c352016-10-16 19:56:49 +0200149 int err;
150
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000151 mv88e6xxx_reg_lock(chip);
Vivien Didelot82466922017-06-15 12:13:59 -0400152 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000153 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200154
155 if (err)
156 goto out;
157
John David Anglin7c0db242019-02-11 13:40:21 -0500158 do {
159 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
160 if (reg & (1 << n)) {
161 sub_irq = irq_find_mapping(chip->g1_irq.domain,
162 n);
163 handle_nested_irq(sub_irq);
164 ++nhandled;
165 }
Andrew Lunndc30c352016-10-16 19:56:49 +0200166 }
John David Anglin7c0db242019-02-11 13:40:21 -0500167
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000168 mv88e6xxx_reg_lock(chip);
John David Anglin7c0db242019-02-11 13:40:21 -0500169 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &ctl1);
170 if (err)
171 goto unlock;
172 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
173unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000174 mv88e6xxx_reg_unlock(chip);
John David Anglin7c0db242019-02-11 13:40:21 -0500175 if (err)
176 goto out;
177 ctl1 &= GENMASK(chip->g1_irq.nirqs, 0);
178 } while (reg & ctl1);
179
Andrew Lunndc30c352016-10-16 19:56:49 +0200180out:
181 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
182}
183
Andrew Lunn294d7112018-02-22 22:58:32 +0100184static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
185{
186 struct mv88e6xxx_chip *chip = dev_id;
187
188 return mv88e6xxx_g1_irq_thread_work(chip);
189}
190
Andrew Lunndc30c352016-10-16 19:56:49 +0200191static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
192{
193 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
194
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000195 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200196}
197
198static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
199{
200 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
201 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
202 u16 reg;
203 int err;
204
Vivien Didelotd77f4322017-06-15 12:14:03 -0400205 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200206 if (err)
207 goto out;
208
209 reg &= ~mask;
210 reg |= (~chip->g1_irq.masked & mask);
211
Vivien Didelotd77f4322017-06-15 12:14:03 -0400212 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200213 if (err)
214 goto out;
215
216out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000217 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200218}
219
Bhumika Goyal6eb15e22017-08-19 16:25:52 +0530220static const struct irq_chip mv88e6xxx_g1_irq_chip = {
Andrew Lunndc30c352016-10-16 19:56:49 +0200221 .name = "mv88e6xxx-g1",
222 .irq_mask = mv88e6xxx_g1_irq_mask,
223 .irq_unmask = mv88e6xxx_g1_irq_unmask,
224 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
225 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
226};
227
228static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
229 unsigned int irq,
230 irq_hw_number_t hwirq)
231{
232 struct mv88e6xxx_chip *chip = d->host_data;
233
234 irq_set_chip_data(irq, d->host_data);
235 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
236 irq_set_noprobe(irq);
237
238 return 0;
239}
240
241static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
242 .map = mv88e6xxx_g1_irq_domain_map,
243 .xlate = irq_domain_xlate_twocell,
244};
245
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200246/* To be called with reg_lock held */
Andrew Lunn294d7112018-02-22 22:58:32 +0100247static void mv88e6xxx_g1_irq_free_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200248{
249 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100250 u16 mask;
251
Vivien Didelotd77f4322017-06-15 12:14:03 -0400252 mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100253 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400254 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3460a572016-11-20 20:14:16 +0100255
Andreas Färber5edef2f2016-11-27 23:26:28 +0100256 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100257 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200258 irq_dispose_mapping(virq);
259 }
260
Andrew Lunna3db3d32016-11-20 20:14:14 +0100261 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200262}
263
Andrew Lunn294d7112018-02-22 22:58:32 +0100264static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
265{
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200266 /*
267 * free_irq must be called without reg_lock taken because the irq
268 * handler takes this lock, too.
269 */
Andrew Lunn294d7112018-02-22 22:58:32 +0100270 free_irq(chip->irq, chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200271
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000272 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200273 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000274 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100275}
276
277static int mv88e6xxx_g1_irq_setup_common(struct mv88e6xxx_chip *chip)
Andrew Lunndc30c352016-10-16 19:56:49 +0200278{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100279 int err, irq, virq;
280 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200281
282 chip->g1_irq.nirqs = chip->info->g1_irqs;
283 chip->g1_irq.domain = irq_domain_add_simple(
284 NULL, chip->g1_irq.nirqs, 0,
285 &mv88e6xxx_g1_irq_domain_ops, chip);
286 if (!chip->g1_irq.domain)
287 return -ENOMEM;
288
289 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
290 irq_create_mapping(chip->g1_irq.domain, irq);
291
292 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
293 chip->g1_irq.masked = ~0;
294
Vivien Didelotd77f4322017-06-15 12:14:03 -0400295 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_CTL1, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200296 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100297 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200298
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100299 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200300
Vivien Didelotd77f4322017-06-15 12:14:03 -0400301 err = mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200302 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100303 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200304
305 /* Reading the interrupt status clears (most of) them */
Vivien Didelot82466922017-06-15 12:13:59 -0400306 err = mv88e6xxx_g1_read(chip, MV88E6XXX_G1_STS, &reg);
Andrew Lunndc30c352016-10-16 19:56:49 +0200307 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100308 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200309
Andrew Lunndc30c352016-10-16 19:56:49 +0200310 return 0;
311
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100312out_disable:
Andrew Lunn3d5fdba2017-12-07 01:05:56 +0100313 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Vivien Didelotd77f4322017-06-15 12:14:03 -0400314 mv88e6xxx_g1_write(chip, MV88E6XXX_G1_CTL1, mask);
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100315
316out_mapping:
317 for (irq = 0; irq < 16; irq++) {
318 virq = irq_find_mapping(chip->g1_irq.domain, irq);
319 irq_dispose_mapping(virq);
320 }
321
322 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200323
324 return err;
325}
326
Andrew Lunn294d7112018-02-22 22:58:32 +0100327static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
328{
Andrew Lunnf6d97582019-02-23 17:43:56 +0100329 static struct lock_class_key lock_key;
330 static struct lock_class_key request_key;
Andrew Lunn294d7112018-02-22 22:58:32 +0100331 int err;
332
333 err = mv88e6xxx_g1_irq_setup_common(chip);
334 if (err)
335 return err;
336
Andrew Lunnf6d97582019-02-23 17:43:56 +0100337 /* These lock classes tells lockdep that global 1 irqs are in
338 * a different category than their parent GPIO, so it won't
339 * report false recursion.
340 */
341 irq_set_lockdep_class(chip->irq, &lock_key, &request_key);
342
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000343 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100344 err = request_threaded_irq(chip->irq, NULL,
345 mv88e6xxx_g1_irq_thread_fn,
Marek Behún03403762018-08-30 02:13:50 +0200346 IRQF_ONESHOT | IRQF_SHARED,
Andrew Lunn294d7112018-02-22 22:58:32 +0100347 dev_name(chip->dev), chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000348 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100349 if (err)
350 mv88e6xxx_g1_irq_free_common(chip);
351
352 return err;
353}
354
355static void mv88e6xxx_irq_poll(struct kthread_work *work)
356{
357 struct mv88e6xxx_chip *chip = container_of(work,
358 struct mv88e6xxx_chip,
359 irq_poll_work.work);
360 mv88e6xxx_g1_irq_thread_work(chip);
361
362 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
363 msecs_to_jiffies(100));
364}
365
366static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
367{
368 int err;
369
370 err = mv88e6xxx_g1_irq_setup_common(chip);
371 if (err)
372 return err;
373
374 kthread_init_delayed_work(&chip->irq_poll_work,
375 mv88e6xxx_irq_poll);
376
Florian Fainelli3f8b8692019-02-21 20:09:27 -0800377 chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
Andrew Lunn294d7112018-02-22 22:58:32 +0100378 if (IS_ERR(chip->kworker))
379 return PTR_ERR(chip->kworker);
380
381 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
382 msecs_to_jiffies(100));
383
384 return 0;
385}
386
387static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
388{
389 kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
390 kthread_destroy_worker(chip->kworker);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200391
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000392 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200393 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000394 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100395}
396
Heiner Kallweit72d8b4f2019-03-01 20:41:00 +0100397int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port, int link,
398 int speed, int duplex, int pause,
399 phy_interface_t mode)
Vivien Didelotd78343d2016-11-04 03:23:36 +0100400{
Andrew Lunna26deec2019-04-18 03:11:39 +0200401 struct phylink_link_state state;
Vivien Didelotd78343d2016-11-04 03:23:36 +0100402 int err;
403
404 if (!chip->info->ops->port_set_link)
405 return 0;
406
Andrew Lunna26deec2019-04-18 03:11:39 +0200407 if (!chip->info->ops->port_link_state)
408 return 0;
409
410 err = chip->info->ops->port_link_state(chip, port, &state);
411 if (err)
412 return err;
413
414 /* Has anything actually changed? We don't expect the
415 * interface mode to change without one of the other
416 * parameters also changing
417 */
418 if (state.link == link &&
419 state.speed == speed &&
Marek Behún927441a2019-08-14 16:40:24 +0200420 state.duplex == duplex &&
421 (state.interface == mode ||
422 state.interface == PHY_INTERFACE_MODE_NA))
Andrew Lunna26deec2019-04-18 03:11:39 +0200423 return 0;
424
Vivien Didelotd78343d2016-11-04 03:23:36 +0100425 /* Port's MAC control must not be changed unless the link is down */
Hubert Feurstein43c8e0a2019-07-30 12:11:42 +0200426 err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100427 if (err)
428 return err;
429
430 if (chip->info->ops->port_set_speed) {
431 err = chip->info->ops->port_set_speed(chip, port, speed);
432 if (err && err != -EOPNOTSUPP)
433 goto restore_link;
434 }
435
Andrew Lunn7cbbee02019-03-08 01:21:27 +0100436 if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
437 mode = chip->info->ops->port_max_speed_mode(port);
438
Andrew Lunn54186b92018-08-09 15:38:37 +0200439 if (chip->info->ops->port_set_pause) {
440 err = chip->info->ops->port_set_pause(chip, port, pause);
441 if (err)
442 goto restore_link;
443 }
444
Vivien Didelotd78343d2016-11-04 03:23:36 +0100445 if (chip->info->ops->port_set_duplex) {
446 err = chip->info->ops->port_set_duplex(chip, port, duplex);
447 if (err && err != -EOPNOTSUPP)
448 goto restore_link;
449 }
450
451 if (chip->info->ops->port_set_rgmii_delay) {
452 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
453 if (err && err != -EOPNOTSUPP)
454 goto restore_link;
455 }
456
Andrew Lunnf39908d2017-02-04 20:02:50 +0100457 if (chip->info->ops->port_set_cmode) {
458 err = chip->info->ops->port_set_cmode(chip, port, mode);
459 if (err && err != -EOPNOTSUPP)
460 goto restore_link;
461 }
462
Vivien Didelotd78343d2016-11-04 03:23:36 +0100463 err = 0;
464restore_link:
465 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400466 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100467
468 return err;
469}
470
Marek Vasutd700ec42018-09-12 00:15:24 +0200471static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
472{
473 struct mv88e6xxx_chip *chip = ds->priv;
474
475 return port < chip->info->num_internal_phys;
476}
477
Russell King6c422e32018-08-09 15:38:39 +0200478static void mv88e6065_phylink_validate(struct mv88e6xxx_chip *chip, int port,
479 unsigned long *mask,
480 struct phylink_link_state *state)
481{
482 if (!phy_interface_mode_is_8023z(state->interface)) {
483 /* 10M and 100M are only supported in non-802.3z mode */
484 phylink_set(mask, 10baseT_Half);
485 phylink_set(mask, 10baseT_Full);
486 phylink_set(mask, 100baseT_Half);
487 phylink_set(mask, 100baseT_Full);
488 }
489}
490
491static void mv88e6185_phylink_validate(struct mv88e6xxx_chip *chip, int port,
492 unsigned long *mask,
493 struct phylink_link_state *state)
494{
495 /* FIXME: if the port is in 1000Base-X mode, then it only supports
496 * 1000M FD speeds. In this case, CMODE will indicate 5.
497 */
498 phylink_set(mask, 1000baseT_Full);
499 phylink_set(mask, 1000baseX_Full);
500
501 mv88e6065_phylink_validate(chip, port, mask, state);
502}
503
Marek Behúne3af71a2019-02-25 12:39:55 +0100504static void mv88e6341_phylink_validate(struct mv88e6xxx_chip *chip, int port,
505 unsigned long *mask,
506 struct phylink_link_state *state)
507{
508 if (port >= 5)
509 phylink_set(mask, 2500baseX_Full);
510
511 /* No ethtool bits for 200Mbps */
512 phylink_set(mask, 1000baseT_Full);
513 phylink_set(mask, 1000baseX_Full);
514
515 mv88e6065_phylink_validate(chip, port, mask, state);
516}
517
Russell King6c422e32018-08-09 15:38:39 +0200518static void mv88e6352_phylink_validate(struct mv88e6xxx_chip *chip, int port,
519 unsigned long *mask,
520 struct phylink_link_state *state)
521{
522 /* No ethtool bits for 200Mbps */
523 phylink_set(mask, 1000baseT_Full);
524 phylink_set(mask, 1000baseX_Full);
525
526 mv88e6065_phylink_validate(chip, port, mask, state);
527}
528
529static void mv88e6390_phylink_validate(struct mv88e6xxx_chip *chip, int port,
530 unsigned long *mask,
531 struct phylink_link_state *state)
532{
Andrew Lunnec260162019-02-08 22:25:44 +0100533 if (port >= 9) {
Russell King6c422e32018-08-09 15:38:39 +0200534 phylink_set(mask, 2500baseX_Full);
Andrew Lunnec260162019-02-08 22:25:44 +0100535 phylink_set(mask, 2500baseT_Full);
536 }
Russell King6c422e32018-08-09 15:38:39 +0200537
538 /* No ethtool bits for 200Mbps */
539 phylink_set(mask, 1000baseT_Full);
540 phylink_set(mask, 1000baseX_Full);
541
542 mv88e6065_phylink_validate(chip, port, mask, state);
543}
544
545static void mv88e6390x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
546 unsigned long *mask,
547 struct phylink_link_state *state)
548{
549 if (port >= 9) {
550 phylink_set(mask, 10000baseT_Full);
551 phylink_set(mask, 10000baseKR_Full);
552 }
553
554 mv88e6390_phylink_validate(chip, port, mask, state);
555}
556
Russell Kingc9a23562018-05-10 13:17:35 -0700557static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
558 unsigned long *supported,
559 struct phylink_link_state *state)
560{
Russell King6c422e32018-08-09 15:38:39 +0200561 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
562 struct mv88e6xxx_chip *chip = ds->priv;
563
564 /* Allow all the expected bits */
565 phylink_set(mask, Autoneg);
566 phylink_set(mask, Pause);
567 phylink_set_port_modes(mask);
568
569 if (chip->info->ops->phylink_validate)
570 chip->info->ops->phylink_validate(chip, port, mask, state);
571
572 bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
573 bitmap_and(state->advertising, state->advertising, mask,
574 __ETHTOOL_LINK_MODE_MASK_NBITS);
575
576 /* We can only operate at 2500BaseX or 1000BaseX. If requested
577 * to advertise both, only report advertising at 2500BaseX.
578 */
579 phylink_helper_basex_speed(state);
Russell Kingc9a23562018-05-10 13:17:35 -0700580}
581
582static int mv88e6xxx_link_state(struct dsa_switch *ds, int port,
583 struct phylink_link_state *state)
584{
585 struct mv88e6xxx_chip *chip = ds->priv;
586 int err;
587
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000588 mv88e6xxx_reg_lock(chip);
Russell King6c422e32018-08-09 15:38:39 +0200589 if (chip->info->ops->port_link_state)
590 err = chip->info->ops->port_link_state(chip, port, state);
591 else
592 err = -EOPNOTSUPP;
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000593 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700594
595 return err;
596}
597
598static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
599 unsigned int mode,
600 const struct phylink_link_state *state)
601{
602 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn54186b92018-08-09 15:38:37 +0200603 int speed, duplex, link, pause, err;
Russell Kingc9a23562018-05-10 13:17:35 -0700604
Marek Vasutd700ec42018-09-12 00:15:24 +0200605 if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
Russell Kingc9a23562018-05-10 13:17:35 -0700606 return;
607
608 if (mode == MLO_AN_FIXED) {
609 link = LINK_FORCED_UP;
610 speed = state->speed;
611 duplex = state->duplex;
Marek Vasutd700ec42018-09-12 00:15:24 +0200612 } else if (!mv88e6xxx_phy_is_internal(ds, port)) {
613 link = state->link;
614 speed = state->speed;
615 duplex = state->duplex;
Russell Kingc9a23562018-05-10 13:17:35 -0700616 } else {
617 speed = SPEED_UNFORCED;
618 duplex = DUPLEX_UNFORCED;
619 link = LINK_UNFORCED;
620 }
Andrew Lunn54186b92018-08-09 15:38:37 +0200621 pause = !!phylink_test(state->advertising, Pause);
Russell Kingc9a23562018-05-10 13:17:35 -0700622
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000623 mv88e6xxx_reg_lock(chip);
Andrew Lunn54186b92018-08-09 15:38:37 +0200624 err = mv88e6xxx_port_setup_mac(chip, port, link, speed, duplex, pause,
Russell Kingc9a23562018-05-10 13:17:35 -0700625 state->interface);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000626 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700627
628 if (err && err != -EOPNOTSUPP)
629 dev_err(ds->dev, "p%d: failed to configure MAC\n", port);
630}
631
632static void mv88e6xxx_mac_link_force(struct dsa_switch *ds, int port, int link)
633{
634 struct mv88e6xxx_chip *chip = ds->priv;
635 int err;
636
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000637 mv88e6xxx_reg_lock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700638 err = chip->info->ops->port_set_link(chip, port, link);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000639 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700640
641 if (err)
642 dev_err(chip->dev, "p%d: failed to force MAC link\n", port);
643}
644
645static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
646 unsigned int mode,
647 phy_interface_t interface)
648{
649 if (mode == MLO_AN_FIXED)
650 mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_DOWN);
651}
652
653static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
654 unsigned int mode, phy_interface_t interface,
655 struct phy_device *phydev)
656{
657 if (mode == MLO_AN_FIXED)
658 mv88e6xxx_mac_link_force(ds, port, LINK_FORCED_UP);
659}
660
Andrew Lunna605a0f2016-11-21 23:26:58 +0100661static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000662{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100663 if (!chip->info->ops->stats_snapshot)
664 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000665
Andrew Lunna605a0f2016-11-21 23:26:58 +0100666 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000667}
668
Andrew Lunne413e7e2015-04-02 04:06:38 +0200669static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100670 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
671 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
672 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
673 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
674 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
675 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
676 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
677 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
678 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
679 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
680 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
681 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
682 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
683 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
684 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
685 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
686 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
687 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
688 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
689 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
690 { "single", 4, 0x14, STATS_TYPE_BANK0, },
691 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
692 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
693 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
694 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
695 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
696 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
697 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
698 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
699 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
700 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
701 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
702 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
703 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
704 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
705 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
706 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
707 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
708 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
709 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
710 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
711 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
712 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
713 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
714 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
715 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
716 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
717 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
718 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
719 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
720 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
721 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
722 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
723 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
724 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
725 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
726 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
727 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
728 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200729};
730
Vivien Didelotfad09c72016-06-21 12:28:20 -0400731static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100732 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100733 int port, u16 bank1_select,
734 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200735{
Andrew Lunn80c46272015-06-20 18:42:30 +0200736 u32 low;
737 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100738 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200739 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200740 u64 value;
741
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100742 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100743 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200744 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
745 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800746 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200747
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200748 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100749 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200750 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
751 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800752 return U64_MAX;
Rasmus Villemoes84b3fd12019-05-29 07:02:11 +0000753 low |= ((u32)reg) << 16;
Andrew Lunn80c46272015-06-20 18:42:30 +0200754 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100755 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100756 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100757 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100758 /* fall through */
759 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100760 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100761 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100762 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100763 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500764 break;
765 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800766 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200767 }
Andrew Lunn6e46e2d2019-02-28 18:14:03 +0100768 value = (((u64)high) << 32) | low;
Andrew Lunn80c46272015-06-20 18:42:30 +0200769 return value;
770}
771
Andrew Lunn436fe172018-03-01 02:02:29 +0100772static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
773 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100774{
775 struct mv88e6xxx_hw_stat *stat;
776 int i, j;
777
778 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
779 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100780 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100781 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
782 ETH_GSTRING_LEN);
783 j++;
784 }
785 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100786
787 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100788}
789
Andrew Lunn436fe172018-03-01 02:02:29 +0100790static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
791 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100792{
Andrew Lunn436fe172018-03-01 02:02:29 +0100793 return mv88e6xxx_stats_get_strings(chip, data,
794 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100795}
796
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000797static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
798 uint8_t *data)
799{
800 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
801}
802
Andrew Lunn436fe172018-03-01 02:02:29 +0100803static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
804 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100805{
Andrew Lunn436fe172018-03-01 02:02:29 +0100806 return mv88e6xxx_stats_get_strings(chip, data,
807 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100808}
809
Andrew Lunn65f60e42018-03-28 23:50:28 +0200810static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
811 "atu_member_violation",
812 "atu_miss_violation",
813 "atu_full_violation",
814 "vtu_member_violation",
815 "vtu_miss_violation",
816};
817
818static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
819{
820 unsigned int i;
821
822 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
823 strlcpy(data + i * ETH_GSTRING_LEN,
824 mv88e6xxx_atu_vtu_stats_strings[i],
825 ETH_GSTRING_LEN);
826}
827
Andrew Lunndfafe442016-11-21 23:27:02 +0100828static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700829 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100830{
Vivien Didelot04bed142016-08-31 18:06:13 -0400831 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100832 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100833
Florian Fainelli89f09042018-04-25 12:12:50 -0700834 if (stringset != ETH_SS_STATS)
835 return;
836
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000837 mv88e6xxx_reg_lock(chip);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100838
Andrew Lunndfafe442016-11-21 23:27:02 +0100839 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100840 count = chip->info->ops->stats_get_strings(chip, data);
841
842 if (chip->info->ops->serdes_get_strings) {
843 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200844 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100845 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100846
Andrew Lunn65f60e42018-03-28 23:50:28 +0200847 data += count * ETH_GSTRING_LEN;
848 mv88e6xxx_atu_vtu_get_strings(data);
849
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000850 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100851}
852
853static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
854 int types)
855{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100856 struct mv88e6xxx_hw_stat *stat;
857 int i, j;
858
859 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
860 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100861 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100862 j++;
863 }
864 return j;
865}
866
Andrew Lunndfafe442016-11-21 23:27:02 +0100867static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
868{
869 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
870 STATS_TYPE_PORT);
871}
872
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000873static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
874{
875 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
876}
877
Andrew Lunndfafe442016-11-21 23:27:02 +0100878static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
879{
880 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
881 STATS_TYPE_BANK1);
882}
883
Florian Fainelli89f09042018-04-25 12:12:50 -0700884static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +0100885{
886 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100887 int serdes_count = 0;
888 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100889
Florian Fainelli89f09042018-04-25 12:12:50 -0700890 if (sset != ETH_SS_STATS)
891 return 0;
892
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000893 mv88e6xxx_reg_lock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100894 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +0100895 count = chip->info->ops->stats_get_sset_count(chip);
896 if (count < 0)
897 goto out;
898
899 if (chip->info->ops->serdes_get_sset_count)
900 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
901 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +0200902 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +0100903 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200904 goto out;
905 }
906 count += serdes_count;
907 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
908
Andrew Lunn436fe172018-03-01 02:02:29 +0100909out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000910 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100911
Andrew Lunn436fe172018-03-01 02:02:29 +0100912 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +0100913}
914
Andrew Lunn436fe172018-03-01 02:02:29 +0100915static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
916 uint64_t *data, int types,
917 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100918{
919 struct mv88e6xxx_hw_stat *stat;
920 int i, j;
921
922 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
923 stat = &mv88e6xxx_hw_stats[i];
924 if (stat->type & types) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000925 mv88e6xxx_reg_lock(chip);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100926 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
927 bank1_select,
928 histogram);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000929 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +0100930
Andrew Lunn052f9472016-11-21 23:27:03 +0100931 j++;
932 }
933 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100934 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +0100935}
936
Andrew Lunn436fe172018-03-01 02:02:29 +0100937static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
938 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100939{
940 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100941 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400942 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100943}
944
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000945static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
946 uint64_t *data)
947{
948 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
949 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
950}
951
Andrew Lunn436fe172018-03-01 02:02:29 +0100952static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
953 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +0100954{
955 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100956 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400957 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
958 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +0100959}
960
Andrew Lunn436fe172018-03-01 02:02:29 +0100961static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
962 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +0100963{
964 return mv88e6xxx_stats_get_stats(chip, port, data,
965 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -0400966 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
967 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100968}
969
Andrew Lunn65f60e42018-03-28 23:50:28 +0200970static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
971 uint64_t *data)
972{
973 *data++ = chip->ports[port].atu_member_violation;
974 *data++ = chip->ports[port].atu_miss_violation;
975 *data++ = chip->ports[port].atu_full_violation;
976 *data++ = chip->ports[port].vtu_member_violation;
977 *data++ = chip->ports[port].vtu_miss_violation;
978}
979
Andrew Lunn052f9472016-11-21 23:27:03 +0100980static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
981 uint64_t *data)
982{
Andrew Lunn436fe172018-03-01 02:02:29 +0100983 int count = 0;
984
Andrew Lunn052f9472016-11-21 23:27:03 +0100985 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +0100986 count = chip->info->ops->stats_get_stats(chip, port, data);
987
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000988 mv88e6xxx_reg_lock(chip);
Andrew Lunn436fe172018-03-01 02:02:29 +0100989 if (chip->info->ops->serdes_get_stats) {
990 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200991 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100992 }
Andrew Lunn65f60e42018-03-28 23:50:28 +0200993 data += count;
994 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000995 mv88e6xxx_reg_unlock(chip);
Andrew Lunn052f9472016-11-21 23:27:03 +0100996}
997
Vivien Didelotf81ec902016-05-09 13:22:58 -0400998static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
999 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001000{
Vivien Didelot04bed142016-08-31 18:06:13 -04001001 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001002 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001003
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001004 mv88e6xxx_reg_lock(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001005
Andrew Lunna605a0f2016-11-21 23:26:58 +01001006 ret = mv88e6xxx_stats_snapshot(chip, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001007 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001008
1009 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001010 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001011
1012 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001013
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001014}
Ben Hutchings98e67302011-11-25 14:36:19 +00001015
Vivien Didelotf81ec902016-05-09 13:22:58 -04001016static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001017{
1018 return 32 * sizeof(u16);
1019}
1020
Vivien Didelotf81ec902016-05-09 13:22:58 -04001021static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1022 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001023{
Vivien Didelot04bed142016-08-31 18:06:13 -04001024 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001025 int err;
1026 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001027 u16 *p = _p;
1028 int i;
1029
Vivien Didelota5f39322018-12-17 16:05:21 -05001030 regs->version = chip->info->prod_num;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001031
1032 memset(p, 0xff, 32 * sizeof(u16));
1033
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001034 mv88e6xxx_reg_lock(chip);
Vivien Didelot23062512016-05-09 13:22:45 -04001035
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001036 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001037
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001038 err = mv88e6xxx_port_read(chip, port, i, &reg);
1039 if (!err)
1040 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001041 }
Vivien Didelot23062512016-05-09 13:22:45 -04001042
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001043 mv88e6xxx_reg_unlock(chip);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001044}
1045
Vivien Didelot08f50062017-08-01 16:32:41 -04001046static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1047 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001048{
Vivien Didelot5480db62017-08-01 16:32:40 -04001049 /* Nothing to do on the port's MAC */
1050 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001051}
1052
Vivien Didelot08f50062017-08-01 16:32:41 -04001053static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1054 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001055{
Vivien Didelot5480db62017-08-01 16:32:40 -04001056 /* Nothing to do on the port's MAC */
1057 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001058}
1059
Vivien Didelote5887a22017-03-30 17:37:11 -04001060static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001061{
Vivien Didelote5887a22017-03-30 17:37:11 -04001062 struct dsa_switch *ds = NULL;
1063 struct net_device *br;
1064 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001065 int i;
1066
Vivien Didelote5887a22017-03-30 17:37:11 -04001067 if (dev < DSA_MAX_SWITCHES)
1068 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001069
Vivien Didelote5887a22017-03-30 17:37:11 -04001070 /* Prevent frames from unknown switch or port */
1071 if (!ds || port >= ds->num_ports)
1072 return 0;
1073
1074 /* Frames from DSA links and CPU ports can egress any local port */
1075 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1076 return mv88e6xxx_port_mask(chip);
1077
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001078 br = dsa_to_port(ds, port)->bridge_dev;
Vivien Didelote5887a22017-03-30 17:37:11 -04001079 pvlan = 0;
1080
1081 /* Frames from user ports can egress any local DSA links and CPU ports,
1082 * as well as any local member of their bridge group.
1083 */
1084 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1085 if (dsa_is_cpu_port(chip->ds, i) ||
1086 dsa_is_dsa_port(chip->ds, i) ||
Vivien Didelotc8652c82017-10-16 11:12:19 -04001087 (br && dsa_to_port(chip->ds, i)->bridge_dev == br))
Vivien Didelote5887a22017-03-30 17:37:11 -04001088 pvlan |= BIT(i);
1089
1090 return pvlan;
1091}
1092
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001093static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001094{
1095 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001096
1097 /* prevent frames from going back out of the port they came in on */
1098 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001099
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001100 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001101}
1102
Vivien Didelotf81ec902016-05-09 13:22:58 -04001103static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1104 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001105{
Vivien Didelot04bed142016-08-31 18:06:13 -04001106 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001107 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001108
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001109 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001110 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001111 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001112
1113 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001114 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001115}
1116
Vivien Didelot93e18d62018-05-11 17:16:35 -04001117static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1118{
1119 int err;
1120
1121 if (chip->info->ops->ieee_pri_map) {
1122 err = chip->info->ops->ieee_pri_map(chip);
1123 if (err)
1124 return err;
1125 }
1126
1127 if (chip->info->ops->ip_pri_map) {
1128 err = chip->info->ops->ip_pri_map(chip);
1129 if (err)
1130 return err;
1131 }
1132
1133 return 0;
1134}
1135
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001136static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1137{
1138 int target, port;
1139 int err;
1140
1141 if (!chip->info->global2_addr)
1142 return 0;
1143
1144 /* Initialize the routing port to the 32 possible target devices */
1145 for (target = 0; target < 32; target++) {
1146 port = 0x1f;
1147 if (target < DSA_MAX_SWITCHES)
1148 if (chip->ds->rtable[target] != DSA_RTABLE_NONE)
1149 port = chip->ds->rtable[target];
1150
1151 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1152 if (err)
1153 return err;
1154 }
1155
Vivien Didelot02317e62018-05-09 11:38:49 -04001156 if (chip->info->ops->set_cascade_port) {
1157 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1158 err = chip->info->ops->set_cascade_port(chip, port);
1159 if (err)
1160 return err;
1161 }
1162
Vivien Didelot23c98912018-05-09 11:38:50 -04001163 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1164 if (err)
1165 return err;
1166
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001167 return 0;
1168}
1169
Vivien Didelotb28f8722018-04-26 21:56:44 -04001170static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1171{
1172 /* Clear all trunk masks and mapping */
1173 if (chip->info->global2_addr)
1174 return mv88e6xxx_g2_trunk_clear(chip);
1175
1176 return 0;
1177}
1178
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001179static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1180{
1181 if (chip->info->ops->rmu_disable)
1182 return chip->info->ops->rmu_disable(chip);
1183
1184 return 0;
1185}
1186
Vivien Didelot9e907d72017-07-17 13:03:43 -04001187static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1188{
1189 if (chip->info->ops->pot_clear)
1190 return chip->info->ops->pot_clear(chip);
1191
1192 return 0;
1193}
1194
Vivien Didelot51c901a2017-07-17 13:03:41 -04001195static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1196{
1197 if (chip->info->ops->mgmt_rsvd2cpu)
1198 return chip->info->ops->mgmt_rsvd2cpu(chip);
1199
1200 return 0;
1201}
1202
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001203static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1204{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001205 int err;
1206
Vivien Didelotdaefc942017-03-11 16:12:54 -05001207 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1208 if (err)
1209 return err;
1210
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001211 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1212 if (err)
1213 return err;
1214
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001215 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1216}
1217
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001218static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1219{
1220 int port;
1221 int err;
1222
1223 if (!chip->info->ops->irl_init_all)
1224 return 0;
1225
1226 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1227 /* Disable ingress rate limiting by resetting all per port
1228 * ingress rate limit resources to their initial state.
1229 */
1230 err = chip->info->ops->irl_init_all(chip, port);
1231 if (err)
1232 return err;
1233 }
1234
1235 return 0;
1236}
1237
Vivien Didelot04a69a12017-10-13 14:18:05 -04001238static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1239{
1240 if (chip->info->ops->set_switch_mac) {
1241 u8 addr[ETH_ALEN];
1242
1243 eth_random_addr(addr);
1244
1245 return chip->info->ops->set_switch_mac(chip, addr);
1246 }
1247
1248 return 0;
1249}
1250
Vivien Didelot17a15942017-03-30 17:37:09 -04001251static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1252{
1253 u16 pvlan = 0;
1254
1255 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001256 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001257
1258 /* Skip the local source device, which uses in-chip port VLAN */
1259 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001260 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001261
1262 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1263}
1264
Vivien Didelot81228992017-03-30 17:37:08 -04001265static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1266{
Vivien Didelot17a15942017-03-30 17:37:09 -04001267 int dev, port;
1268 int err;
1269
Vivien Didelot81228992017-03-30 17:37:08 -04001270 if (!mv88e6xxx_has_pvt(chip))
1271 return 0;
1272
1273 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1274 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1275 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001276 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1277 if (err)
1278 return err;
1279
1280 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1281 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1282 err = mv88e6xxx_pvt_map(chip, dev, port);
1283 if (err)
1284 return err;
1285 }
1286 }
1287
1288 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001289}
1290
Vivien Didelot749efcb2016-09-22 16:49:24 -04001291static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1292{
1293 struct mv88e6xxx_chip *chip = ds->priv;
1294 int err;
1295
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001296 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001297 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001298 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001299
1300 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001301 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001302}
1303
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001304static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1305{
1306 if (!chip->info->max_vid)
1307 return 0;
1308
1309 return mv88e6xxx_g1_vtu_flush(chip);
1310}
1311
Vivien Didelotf1394b782017-05-01 14:05:22 -04001312static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1313 struct mv88e6xxx_vtu_entry *entry)
1314{
1315 if (!chip->info->ops->vtu_getnext)
1316 return -EOPNOTSUPP;
1317
1318 return chip->info->ops->vtu_getnext(chip, entry);
1319}
1320
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001321static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1322 struct mv88e6xxx_vtu_entry *entry)
1323{
1324 if (!chip->info->ops->vtu_loadpurge)
1325 return -EOPNOTSUPP;
1326
1327 return chip->info->ops->vtu_loadpurge(chip, entry);
1328}
1329
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001330static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001331{
1332 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot425d2d32019-08-01 14:36:34 -04001333 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001334 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001335
1336 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1337
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001338 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001339 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001340 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001341 if (err)
1342 return err;
1343
1344 set_bit(*fid, fid_bitmap);
1345 }
1346
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001347 /* Set every FID bit used by the VLAN entries */
Vivien Didelot425d2d32019-08-01 14:36:34 -04001348 vlan.vid = chip->info->max_vid;
1349 vlan.valid = false;
1350
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001351 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001352 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001353 if (err)
1354 return err;
1355
1356 if (!vlan.valid)
1357 break;
1358
1359 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001360 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001361
1362 /* The reset value 0x000 is used to indicate that multiple address
1363 * databases are not needed. Return the next positive available.
1364 */
1365 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001366 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001367 return -ENOSPC;
1368
1369 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001370 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001371}
1372
Vivien Didelotda9c3592016-02-12 12:09:40 -05001373static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1374 u16 vid_begin, u16 vid_end)
1375{
Vivien Didelot04bed142016-08-31 18:06:13 -04001376 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001377 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001378 int i, err;
1379
Andrew Lunndb06ae412017-09-25 23:32:20 +02001380 /* DSA and CPU ports have to be members of multiple vlans */
1381 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1382 return 0;
1383
Vivien Didelotda9c3592016-02-12 12:09:40 -05001384 if (!vid_begin)
1385 return -EOPNOTSUPP;
1386
Vivien Didelot425d2d32019-08-01 14:36:34 -04001387 vlan.vid = vid_begin - 1;
1388 vlan.valid = false;
1389
Vivien Didelotda9c3592016-02-12 12:09:40 -05001390 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001391 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001392 if (err)
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001393 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001394
1395 if (!vlan.valid)
1396 break;
1397
1398 if (vlan.vid > vid_end)
1399 break;
1400
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001401 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001402 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1403 continue;
1404
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001405 if (!dsa_to_port(ds, i)->slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001406 continue;
1407
Vivien Didelotbd00e052017-05-01 14:05:11 -04001408 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001409 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001410 continue;
1411
Vivien Didelotc8652c82017-10-16 11:12:19 -04001412 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001413 dsa_to_port(ds, port)->bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001414 break; /* same bridge, check next VLAN */
1415
Vivien Didelotc8652c82017-10-16 11:12:19 -04001416 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001417 continue;
1418
Andrew Lunn743fcc22017-11-09 22:29:54 +01001419 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1420 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001421 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001422 return -EOPNOTSUPP;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001423 }
1424 } while (vlan.vid < vid_end);
1425
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001426 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001427}
1428
Vivien Didelotf81ec902016-05-09 13:22:58 -04001429static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1430 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001431{
Vivien Didelot04bed142016-08-31 18:06:13 -04001432 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001433 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1434 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001435 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001436
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001437 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001438 return -EOPNOTSUPP;
1439
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001440 mv88e6xxx_reg_lock(chip);
Vivien Didelot385a0992016-11-04 03:23:31 +01001441 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001442 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001443
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001444 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001445}
1446
Vivien Didelot57d32312016-06-20 13:13:58 -04001447static int
1448mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001449 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001450{
Vivien Didelot04bed142016-08-31 18:06:13 -04001451 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001452 int err;
1453
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001454 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001455 return -EOPNOTSUPP;
1456
Vivien Didelotda9c3592016-02-12 12:09:40 -05001457 /* If the requested port doesn't belong to the same bridge as the VLAN
1458 * members, do not support it (yet) and fallback to software VLAN.
1459 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001460 mv88e6xxx_reg_lock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001461 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1462 vlan->vid_end);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001463 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001464
Vivien Didelot76e398a2015-11-01 12:33:55 -05001465 /* We don't need any dynamic resource from the kernel (yet),
1466 * so skip the prepare phase.
1467 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001468 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001469}
1470
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001471static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1472 const unsigned char *addr, u16 vid,
1473 u8 state)
1474{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001475 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001476 struct mv88e6xxx_vtu_entry vlan;
1477 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001478 int err;
1479
1480 /* Null VLAN ID corresponds to the port private database */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001481 if (vid == 0) {
1482 err = mv88e6xxx_port_get_fid(chip, port, &fid);
1483 if (err)
1484 return err;
1485 } else {
1486 vlan.vid = vid - 1;
1487 vlan.valid = false;
1488
1489 err = mv88e6xxx_vtu_getnext(chip, &vlan);
1490 if (err)
1491 return err;
1492
1493 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1494 if (vlan.vid != vid || !vlan.valid)
1495 return -EOPNOTSUPP;
1496
1497 fid = vlan.fid;
1498 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001499
Vivien Didelotd8291a92019-09-07 16:00:47 -04001500 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001501 ether_addr_copy(entry.mac, addr);
1502 eth_addr_dec(entry.mac);
1503
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001504 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001505 if (err)
1506 return err;
1507
1508 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001509 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001510 memset(&entry, 0, sizeof(entry));
1511 ether_addr_copy(entry.mac, addr);
1512 }
1513
1514 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001515 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001516 entry.portvec &= ~BIT(port);
1517 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001518 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001519 } else {
1520 entry.portvec |= BIT(port);
1521 entry.state = state;
1522 }
1523
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001524 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001525}
1526
Vivien Didelotda7dc872019-09-07 16:00:49 -04001527static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1528 const struct mv88e6xxx_policy *policy)
1529{
1530 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1531 enum mv88e6xxx_policy_action action = policy->action;
1532 const u8 *addr = policy->addr;
1533 u16 vid = policy->vid;
1534 u8 state;
1535 int err;
1536 int id;
1537
1538 if (!chip->info->ops->port_set_policy)
1539 return -EOPNOTSUPP;
1540
1541 switch (mapping) {
1542 case MV88E6XXX_POLICY_MAPPING_DA:
1543 case MV88E6XXX_POLICY_MAPPING_SA:
1544 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1545 state = 0; /* Dissociate the port and address */
1546 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1547 is_multicast_ether_addr(addr))
1548 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1549 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1550 is_unicast_ether_addr(addr))
1551 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1552 else
1553 return -EOPNOTSUPP;
1554
1555 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1556 state);
1557 if (err)
1558 return err;
1559 break;
1560 default:
1561 return -EOPNOTSUPP;
1562 }
1563
1564 /* Skip the port's policy clearing if the mapping is still in use */
1565 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1566 idr_for_each_entry(&chip->policies, policy, id)
1567 if (policy->port == port &&
1568 policy->mapping == mapping &&
1569 policy->action != action)
1570 return 0;
1571
1572 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1573}
1574
1575static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1576 struct ethtool_rx_flow_spec *fs)
1577{
1578 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1579 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1580 enum mv88e6xxx_policy_mapping mapping;
1581 enum mv88e6xxx_policy_action action;
1582 struct mv88e6xxx_policy *policy;
1583 u16 vid = 0;
1584 u8 *addr;
1585 int err;
1586 int id;
1587
1588 if (fs->location != RX_CLS_LOC_ANY)
1589 return -EINVAL;
1590
1591 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1592 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1593 else
1594 return -EOPNOTSUPP;
1595
1596 switch (fs->flow_type & ~FLOW_EXT) {
1597 case ETHER_FLOW:
1598 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1599 is_zero_ether_addr(mac_mask->h_source)) {
1600 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1601 addr = mac_entry->h_dest;
1602 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1603 !is_zero_ether_addr(mac_mask->h_source)) {
1604 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1605 addr = mac_entry->h_source;
1606 } else {
1607 /* Cannot support DA and SA mapping in the same rule */
1608 return -EOPNOTSUPP;
1609 }
1610 break;
1611 default:
1612 return -EOPNOTSUPP;
1613 }
1614
1615 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
1616 if (fs->m_ext.vlan_tci != 0xffff)
1617 return -EOPNOTSUPP;
1618 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1619 }
1620
1621 idr_for_each_entry(&chip->policies, policy, id) {
1622 if (policy->port == port && policy->mapping == mapping &&
1623 policy->action == action && policy->vid == vid &&
1624 ether_addr_equal(policy->addr, addr))
1625 return -EEXIST;
1626 }
1627
1628 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1629 if (!policy)
1630 return -ENOMEM;
1631
1632 fs->location = 0;
1633 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1634 GFP_KERNEL);
1635 if (err) {
1636 devm_kfree(chip->dev, policy);
1637 return err;
1638 }
1639
1640 memcpy(&policy->fs, fs, sizeof(*fs));
1641 ether_addr_copy(policy->addr, addr);
1642 policy->mapping = mapping;
1643 policy->action = action;
1644 policy->port = port;
1645 policy->vid = vid;
1646
1647 err = mv88e6xxx_policy_apply(chip, port, policy);
1648 if (err) {
1649 idr_remove(&chip->policies, fs->location);
1650 devm_kfree(chip->dev, policy);
1651 return err;
1652 }
1653
1654 return 0;
1655}
1656
1657static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1658 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1659{
1660 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1661 struct mv88e6xxx_chip *chip = ds->priv;
1662 struct mv88e6xxx_policy *policy;
1663 int err;
1664 int id;
1665
1666 mv88e6xxx_reg_lock(chip);
1667
1668 switch (rxnfc->cmd) {
1669 case ETHTOOL_GRXCLSRLCNT:
1670 rxnfc->data = 0;
1671 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1672 rxnfc->rule_cnt = 0;
1673 idr_for_each_entry(&chip->policies, policy, id)
1674 if (policy->port == port)
1675 rxnfc->rule_cnt++;
1676 err = 0;
1677 break;
1678 case ETHTOOL_GRXCLSRULE:
1679 err = -ENOENT;
1680 policy = idr_find(&chip->policies, fs->location);
1681 if (policy) {
1682 memcpy(fs, &policy->fs, sizeof(*fs));
1683 err = 0;
1684 }
1685 break;
1686 case ETHTOOL_GRXCLSRLALL:
1687 rxnfc->data = 0;
1688 rxnfc->rule_cnt = 0;
1689 idr_for_each_entry(&chip->policies, policy, id)
1690 if (policy->port == port)
1691 rule_locs[rxnfc->rule_cnt++] = id;
1692 err = 0;
1693 break;
1694 default:
1695 err = -EOPNOTSUPP;
1696 break;
1697 }
1698
1699 mv88e6xxx_reg_unlock(chip);
1700
1701 return err;
1702}
1703
1704static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1705 struct ethtool_rxnfc *rxnfc)
1706{
1707 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1708 struct mv88e6xxx_chip *chip = ds->priv;
1709 struct mv88e6xxx_policy *policy;
1710 int err;
1711
1712 mv88e6xxx_reg_lock(chip);
1713
1714 switch (rxnfc->cmd) {
1715 case ETHTOOL_SRXCLSRLINS:
1716 err = mv88e6xxx_policy_insert(chip, port, fs);
1717 break;
1718 case ETHTOOL_SRXCLSRLDEL:
1719 err = -ENOENT;
1720 policy = idr_remove(&chip->policies, fs->location);
1721 if (policy) {
1722 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
1723 err = mv88e6xxx_policy_apply(chip, port, policy);
1724 devm_kfree(chip->dev, policy);
1725 }
1726 break;
1727 default:
1728 err = -EOPNOTSUPP;
1729 break;
1730 }
1731
1732 mv88e6xxx_reg_unlock(chip);
1733
1734 return err;
1735}
1736
Andrew Lunn87fa8862017-11-09 22:29:56 +01001737static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1738 u16 vid)
1739{
1740 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1741 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1742
1743 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1744}
1745
1746static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1747{
1748 int port;
1749 int err;
1750
1751 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1752 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1753 if (err)
1754 return err;
1755 }
1756
1757 return 0;
1758}
1759
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001760static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001761 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001762{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001763 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001764 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001765 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001766
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001767 if (!vid)
1768 return -EOPNOTSUPP;
1769
1770 vlan.vid = vid - 1;
1771 vlan.valid = false;
1772
1773 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001774 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001775 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001776
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001777 if (vlan.vid != vid || !vlan.valid) {
1778 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001779
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001780 err = mv88e6xxx_atu_new(chip, &vlan.fid);
1781 if (err)
1782 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01001783
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001784 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1785 if (i == port)
1786 vlan.member[i] = member;
1787 else
1788 vlan.member[i] = non_member;
1789
1790 vlan.vid = vid;
1791 vlan.valid = true;
1792
1793 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1794 if (err)
1795 return err;
1796
1797 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
1798 if (err)
1799 return err;
1800 } else if (vlan.member[port] != member) {
1801 vlan.member[port] = member;
1802
1803 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1804 if (err)
1805 return err;
1806 } else {
1807 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
1808 port, vid);
1809 }
1810
1811 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001812}
1813
Vivien Didelotf81ec902016-05-09 13:22:58 -04001814static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001815 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001816{
Vivien Didelot04bed142016-08-31 18:06:13 -04001817 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001818 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1819 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001820 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001821 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001822
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001823 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001824 return;
1825
Vivien Didelotc91498e2017-06-07 18:12:13 -04001826 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001827 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001828 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001829 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001830 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001831 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001832
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001833 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001834
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001835 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001836 if (mv88e6xxx_port_vlan_join(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001837 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1838 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001839
Vivien Didelot77064f32016-11-04 03:23:30 +01001840 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001841 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1842 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001843
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001844 mv88e6xxx_reg_unlock(chip);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001845}
1846
Vivien Didelot521098922019-08-01 14:36:36 -04001847static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
1848 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001849{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001850 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001851 int i, err;
1852
Vivien Didelot521098922019-08-01 14:36:36 -04001853 if (!vid)
1854 return -EOPNOTSUPP;
1855
1856 vlan.vid = vid - 1;
1857 vlan.valid = false;
1858
1859 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001860 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001861 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001862
Vivien Didelot521098922019-08-01 14:36:36 -04001863 /* If the VLAN doesn't exist in hardware or the port isn't a member,
1864 * tell switchdev that this VLAN is likely handled in software.
1865 */
1866 if (vlan.vid != vid || !vlan.valid ||
1867 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001868 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001869
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001870 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001871
1872 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001873 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001874 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001875 if (vlan.member[i] !=
1876 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001877 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001878 break;
1879 }
1880 }
1881
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001882 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001883 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001884 return err;
1885
Vivien Didelote606ca32017-03-11 16:12:55 -05001886 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001887}
1888
Vivien Didelotf81ec902016-05-09 13:22:58 -04001889static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1890 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001891{
Vivien Didelot04bed142016-08-31 18:06:13 -04001892 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001893 u16 pvid, vid;
1894 int err = 0;
1895
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001896 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001897 return -EOPNOTSUPP;
1898
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001899 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001900
Vivien Didelot77064f32016-11-04 03:23:30 +01001901 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001902 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001903 goto unlock;
1904
Vivien Didelot76e398a2015-11-01 12:33:55 -05001905 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelot521098922019-08-01 14:36:36 -04001906 err = mv88e6xxx_port_vlan_leave(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001907 if (err)
1908 goto unlock;
1909
1910 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001911 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001912 if (err)
1913 goto unlock;
1914 }
1915 }
1916
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001917unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001918 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001919
1920 return err;
1921}
1922
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001923static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1924 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001925{
Vivien Didelot04bed142016-08-31 18:06:13 -04001926 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001927 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04001928
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001929 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001930 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1931 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001932 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001933
1934 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001935}
1936
Vivien Didelotf81ec902016-05-09 13:22:58 -04001937static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001938 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07001939{
Vivien Didelot04bed142016-08-31 18:06:13 -04001940 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001941 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001942
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001943 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04001944 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001945 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07001946
Vivien Didelot83dabd12016-08-31 11:50:04 -04001947 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001948}
1949
Vivien Didelot83dabd12016-08-31 11:50:04 -04001950static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1951 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001952 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001953{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001954 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001955 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001956 int err;
1957
Vivien Didelotd8291a92019-09-07 16:00:47 -04001958 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001959 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001960
1961 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001962 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001963 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001964 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001965
Vivien Didelotd8291a92019-09-07 16:00:47 -04001966 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001967 break;
1968
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001969 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001970 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001971
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001972 if (!is_unicast_ether_addr(addr.mac))
1973 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001974
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001975 is_static = (addr.state ==
1976 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1977 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001978 if (err)
1979 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001980 } while (!is_broadcast_ether_addr(addr.mac));
1981
1982 return err;
1983}
1984
Vivien Didelot83dabd12016-08-31 11:50:04 -04001985static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001986 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001987{
Vivien Didelot425d2d32019-08-01 14:36:34 -04001988 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001989 u16 fid;
1990 int err;
1991
1992 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001993 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001994 if (err)
1995 return err;
1996
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001997 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001998 if (err)
1999 return err;
2000
2001 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot425d2d32019-08-01 14:36:34 -04002002 vlan.vid = chip->info->max_vid;
2003 vlan.valid = false;
2004
Vivien Didelot83dabd12016-08-31 11:50:04 -04002005 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04002006 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002007 if (err)
2008 return err;
2009
2010 if (!vlan.valid)
2011 break;
2012
2013 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002014 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002015 if (err)
2016 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04002017 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002018
2019 return err;
2020}
2021
Vivien Didelotf81ec902016-05-09 13:22:58 -04002022static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002023 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002024{
Vivien Didelot04bed142016-08-31 18:06:13 -04002025 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002026 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002027
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002028 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002029 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002030 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002031
2032 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002033}
2034
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002035static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2036 struct net_device *br)
2037{
Vivien Didelote96a6e02017-03-30 17:37:13 -04002038 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002039 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04002040 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002041 int err;
2042
2043 /* Remap the Port VLAN of each local bridge group member */
2044 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04002045 if (dsa_to_port(chip->ds, port)->bridge_dev == br) {
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002046 err = mv88e6xxx_port_vlan_map(chip, port);
2047 if (err)
2048 return err;
2049 }
2050 }
2051
Vivien Didelote96a6e02017-03-30 17:37:13 -04002052 /* Remap the Port VLAN of each cross-chip bridge group member */
2053 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
2054 ds = chip->ds->dst->ds[dev];
2055 if (!ds)
2056 break;
2057
2058 for (port = 0; port < ds->num_ports; ++port) {
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04002059 if (dsa_to_port(ds, port)->bridge_dev == br) {
Vivien Didelote96a6e02017-03-30 17:37:13 -04002060 err = mv88e6xxx_pvt_map(chip, dev, port);
2061 if (err)
2062 return err;
2063 }
2064 }
2065 }
2066
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002067 return 0;
2068}
2069
Vivien Didelotf81ec902016-05-09 13:22:58 -04002070static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002071 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002072{
Vivien Didelot04bed142016-08-31 18:06:13 -04002073 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002074 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002075
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002076 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002077 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002078 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002079
Vivien Didelot466dfa02016-02-26 13:16:05 -05002080 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002081}
2082
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002083static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2084 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002085{
Vivien Didelot04bed142016-08-31 18:06:13 -04002086 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002087
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002088 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002089 if (mv88e6xxx_bridge_map(chip, br) ||
2090 mv88e6xxx_port_vlan_map(chip, port))
2091 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002092 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002093}
2094
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002095static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
2096 int port, struct net_device *br)
2097{
2098 struct mv88e6xxx_chip *chip = ds->priv;
2099 int err;
2100
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002101 mv88e6xxx_reg_lock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002102 err = mv88e6xxx_pvt_map(chip, dev, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002103 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002104
2105 return err;
2106}
2107
2108static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
2109 int port, struct net_device *br)
2110{
2111 struct mv88e6xxx_chip *chip = ds->priv;
2112
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002113 mv88e6xxx_reg_lock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002114 if (mv88e6xxx_pvt_map(chip, dev, port))
2115 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002116 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002117}
2118
Vivien Didelot17e708b2016-12-05 17:30:27 -05002119static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2120{
2121 if (chip->info->ops->reset)
2122 return chip->info->ops->reset(chip);
2123
2124 return 0;
2125}
2126
Vivien Didelot309eca62016-12-05 17:30:26 -05002127static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2128{
2129 struct gpio_desc *gpiod = chip->reset;
2130
2131 /* If there is a GPIO connected to the reset pin, toggle it */
2132 if (gpiod) {
2133 gpiod_set_value_cansleep(gpiod, 1);
2134 usleep_range(10000, 20000);
2135 gpiod_set_value_cansleep(gpiod, 0);
2136 usleep_range(10000, 20000);
2137 }
2138}
2139
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002140static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2141{
2142 int i, err;
2143
2144 /* Set all ports to the Disabled state */
2145 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002146 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002147 if (err)
2148 return err;
2149 }
2150
2151 /* Wait for transmit queues to drain,
2152 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2153 */
2154 usleep_range(2000, 4000);
2155
2156 return 0;
2157}
2158
Vivien Didelotfad09c72016-06-21 12:28:20 -04002159static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002160{
Vivien Didelota935c052016-09-29 12:21:53 -04002161 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002162
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002163 err = mv88e6xxx_disable_ports(chip);
2164 if (err)
2165 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002166
Vivien Didelot309eca62016-12-05 17:30:26 -05002167 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002168
Vivien Didelot17e708b2016-12-05 17:30:27 -05002169 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002170}
2171
Vivien Didelot43145572017-03-11 16:12:59 -05002172static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002173 enum mv88e6xxx_frame_mode frame,
2174 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002175{
2176 int err;
2177
Vivien Didelot43145572017-03-11 16:12:59 -05002178 if (!chip->info->ops->port_set_frame_mode)
2179 return -EOPNOTSUPP;
2180
2181 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002182 if (err)
2183 return err;
2184
Vivien Didelot43145572017-03-11 16:12:59 -05002185 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2186 if (err)
2187 return err;
2188
2189 if (chip->info->ops->port_set_ether_type)
2190 return chip->info->ops->port_set_ether_type(chip, port, etype);
2191
2192 return 0;
2193}
2194
2195static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2196{
2197 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002198 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002199 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002200}
2201
2202static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2203{
2204 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002205 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002206 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002207}
2208
2209static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2210{
2211 return mv88e6xxx_set_port_mode(chip, port,
2212 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002213 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2214 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002215}
2216
2217static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2218{
2219 if (dsa_is_dsa_port(chip->ds, port))
2220 return mv88e6xxx_set_port_mode_dsa(chip, port);
2221
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002222 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002223 return mv88e6xxx_set_port_mode_normal(chip, port);
2224
2225 /* Setup CPU port mode depending on its supported tag format */
2226 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2227 return mv88e6xxx_set_port_mode_dsa(chip, port);
2228
2229 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2230 return mv88e6xxx_set_port_mode_edsa(chip, port);
2231
2232 return -EINVAL;
2233}
2234
Vivien Didelotea698f42017-03-11 16:12:50 -05002235static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2236{
2237 bool message = dsa_is_dsa_port(chip->ds, port);
2238
2239 return mv88e6xxx_port_set_message_port(chip, port, message);
2240}
2241
Vivien Didelot601aeed2017-03-11 16:13:00 -05002242static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2243{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002244 struct dsa_switch *ds = chip->ds;
David S. Miller407308f2019-06-15 13:35:29 -07002245 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002246
David S. Miller407308f2019-06-15 13:35:29 -07002247 /* Upstream ports flood frames with unknown unicast or multicast DA */
2248 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2249 if (chip->info->ops->port_set_egress_floods)
2250 return chip->info->ops->port_set_egress_floods(chip, port,
2251 flood, flood);
Vivien Didelot601aeed2017-03-11 16:13:00 -05002252
David S. Miller407308f2019-06-15 13:35:29 -07002253 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002254}
2255
Vivien Didelot45de77f2019-08-31 16:18:36 -04002256static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2257{
2258 struct mv88e6xxx_port *mvp = dev_id;
2259 struct mv88e6xxx_chip *chip = mvp->chip;
2260 irqreturn_t ret = IRQ_NONE;
2261 int port = mvp->port;
2262 u8 lane;
2263
2264 mv88e6xxx_reg_lock(chip);
2265 lane = mv88e6xxx_serdes_get_lane(chip, port);
2266 if (lane)
2267 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2268 mv88e6xxx_reg_unlock(chip);
2269
2270 return ret;
2271}
2272
2273static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
2274 u8 lane)
2275{
2276 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2277 unsigned int irq;
2278 int err;
2279
2280 /* Nothing to request if this SERDES port has no IRQ */
2281 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2282 if (!irq)
2283 return 0;
2284
2285 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2286 mv88e6xxx_reg_unlock(chip);
2287 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
2288 IRQF_ONESHOT, "mv88e6xxx-serdes", dev_id);
2289 mv88e6xxx_reg_lock(chip);
2290 if (err)
2291 return err;
2292
2293 dev_id->serdes_irq = irq;
2294
2295 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2296}
2297
2298static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
2299 u8 lane)
2300{
2301 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2302 unsigned int irq = dev_id->serdes_irq;
2303 int err;
2304
2305 /* Nothing to free if no IRQ has been requested */
2306 if (!irq)
2307 return 0;
2308
2309 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2310
2311 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2312 mv88e6xxx_reg_unlock(chip);
2313 free_irq(irq, dev_id);
2314 mv88e6xxx_reg_lock(chip);
2315
2316 dev_id->serdes_irq = 0;
2317
2318 return err;
2319}
2320
Andrew Lunn6d917822017-05-26 01:03:21 +02002321static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2322 bool on)
2323{
Vivien Didelotdc272f62019-08-31 16:18:33 -04002324 u8 lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002325 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002326
Vivien Didelotdc272f62019-08-31 16:18:33 -04002327 lane = mv88e6xxx_serdes_get_lane(chip, port);
2328 if (!lane)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002329 return 0;
2330
2331 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002332 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002333 if (err)
2334 return err;
2335
Vivien Didelot45de77f2019-08-31 16:18:36 -04002336 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002337 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002338 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2339 if (err)
2340 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002341
Vivien Didelotdc272f62019-08-31 16:18:33 -04002342 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002343 }
2344
2345 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002346}
2347
Vivien Didelotfa371c82017-12-05 15:34:10 -05002348static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2349{
2350 struct dsa_switch *ds = chip->ds;
2351 int upstream_port;
2352 int err;
2353
Vivien Didelot07073c72017-12-05 15:34:13 -05002354 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002355 if (chip->info->ops->port_set_upstream_port) {
2356 err = chip->info->ops->port_set_upstream_port(chip, port,
2357 upstream_port);
2358 if (err)
2359 return err;
2360 }
2361
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002362 if (port == upstream_port) {
2363 if (chip->info->ops->set_cpu_port) {
2364 err = chip->info->ops->set_cpu_port(chip,
2365 upstream_port);
2366 if (err)
2367 return err;
2368 }
2369
2370 if (chip->info->ops->set_egress_port) {
2371 err = chip->info->ops->set_egress_port(chip,
2372 upstream_port);
2373 if (err)
2374 return err;
2375 }
2376 }
2377
Vivien Didelotfa371c82017-12-05 15:34:10 -05002378 return 0;
2379}
2380
Vivien Didelotfad09c72016-06-21 12:28:20 -04002381static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002382{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002383 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002384 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002385 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002386
Andrew Lunn7b898462018-08-09 15:38:47 +02002387 chip->ports[port].chip = chip;
2388 chip->ports[port].port = port;
2389
Vivien Didelotd78343d2016-11-04 03:23:36 +01002390 /* MAC Forcing register: don't force link, speed, duplex or flow control
2391 * state to any particular values on physical ports, but force the CPU
2392 * port and all DSA ports to their maximum bandwidth and full duplex.
2393 */
2394 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2395 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2396 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002397 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002398 PHY_INTERFACE_MODE_NA);
2399 else
2400 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2401 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002402 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002403 PHY_INTERFACE_MODE_NA);
2404 if (err)
2405 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002406
2407 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2408 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2409 * tunneling, determine priority by looking at 802.1p and IP
2410 * priority fields (IP prio has precedence), and set STP state
2411 * to Forwarding.
2412 *
2413 * If this is the CPU link, use DSA or EDSA tagging depending
2414 * on which tagging mode was configured.
2415 *
2416 * If this is a link to another switch, use DSA tagging mode.
2417 *
2418 * If this is the upstream port for this switch, enable
2419 * forwarding of unknown unicasts and multicasts.
2420 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002421 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2422 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2423 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2424 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002425 if (err)
2426 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002427
Vivien Didelot601aeed2017-03-11 16:13:00 -05002428 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002429 if (err)
2430 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002431
Vivien Didelot601aeed2017-03-11 16:13:00 -05002432 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002433 if (err)
2434 return err;
2435
Vivien Didelot8efdda42015-08-13 12:52:23 -04002436 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002437 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002438 * untagged frames on this port, do a destination address lookup on all
2439 * received packets as usual, disable ARP mirroring and don't send a
2440 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002441 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002442 err = mv88e6xxx_port_set_map_da(chip, port);
2443 if (err)
2444 return err;
2445
Vivien Didelotfa371c82017-12-05 15:34:10 -05002446 err = mv88e6xxx_setup_upstream_port(chip, port);
2447 if (err)
2448 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002449
Andrew Lunna23b2962017-02-04 20:15:28 +01002450 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002451 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002452 if (err)
2453 return err;
2454
Vivien Didelotcd782652017-06-08 18:34:13 -04002455 if (chip->info->ops->port_set_jumbo_size) {
2456 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002457 if (err)
2458 return err;
2459 }
2460
Andrew Lunn54d792f2015-05-06 01:09:47 +02002461 /* Port Association Vector: when learning source addresses
2462 * of packets, add the address to the address database using
2463 * a port bitmap that has only the bit for this port set and
2464 * the other bits clear.
2465 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002466 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002467 /* Disable learning for CPU port */
2468 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002469 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002470
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002471 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2472 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002473 if (err)
2474 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002475
2476 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002477 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2478 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002479 if (err)
2480 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002481
Vivien Didelot08984322017-06-08 18:34:12 -04002482 if (chip->info->ops->port_pause_limit) {
2483 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002484 if (err)
2485 return err;
2486 }
2487
Vivien Didelotc8c94892017-03-11 16:13:01 -05002488 if (chip->info->ops->port_disable_learn_limit) {
2489 err = chip->info->ops->port_disable_learn_limit(chip, port);
2490 if (err)
2491 return err;
2492 }
2493
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002494 if (chip->info->ops->port_disable_pri_override) {
2495 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002496 if (err)
2497 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002498 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002499
Andrew Lunnef0a7312016-12-03 04:35:16 +01002500 if (chip->info->ops->port_tag_remap) {
2501 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002502 if (err)
2503 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002504 }
2505
Andrew Lunnef70b112016-12-03 04:45:18 +01002506 if (chip->info->ops->port_egress_rate_limiting) {
2507 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002508 if (err)
2509 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002510 }
2511
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002512 if (chip->info->ops->port_setup_message_port) {
2513 err = chip->info->ops->port_setup_message_port(chip, port);
2514 if (err)
2515 return err;
2516 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002517
Vivien Didelot207afda2016-04-14 14:42:09 -04002518 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002519 * database, and allow bidirectional communication between the
2520 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002521 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002522 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002523 if (err)
2524 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002525
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002526 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002527 if (err)
2528 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002529
2530 /* Default VLAN ID and priority: don't set a default VLAN
2531 * ID, and set the default packet priority to zero.
2532 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002533 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002534}
2535
Andrew Lunn04aca992017-05-26 01:03:24 +02002536static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2537 struct phy_device *phydev)
2538{
2539 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002540 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002541
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002542 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002543 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002544 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002545
2546 return err;
2547}
2548
Andrew Lunn75104db2019-02-24 20:44:43 +01002549static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02002550{
2551 struct mv88e6xxx_chip *chip = ds->priv;
2552
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002553 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002554 if (mv88e6xxx_serdes_power(chip, port, false))
2555 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002556 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002557}
2558
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002559static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2560 unsigned int ageing_time)
2561{
Vivien Didelot04bed142016-08-31 18:06:13 -04002562 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002563 int err;
2564
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002565 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05002566 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002567 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002568
2569 return err;
2570}
2571
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002572static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002573{
2574 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002575
Andrew Lunnde2273872016-11-21 23:27:01 +01002576 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002577 if (chip->info->ops->stats_set_histogram) {
2578 err = chip->info->ops->stats_set_histogram(chip);
2579 if (err)
2580 return err;
2581 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002582
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002583 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002584}
2585
Andrew Lunnea890982019-01-09 00:24:03 +01002586/* Check if the errata has already been applied. */
2587static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
2588{
2589 int port;
2590 int err;
2591 u16 val;
2592
2593 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002594 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01002595 if (err) {
2596 dev_err(chip->dev,
2597 "Error reading hidden register: %d\n", err);
2598 return false;
2599 }
2600 if (val != 0x01c0)
2601 return false;
2602 }
2603
2604 return true;
2605}
2606
2607/* The 6390 copper ports have an errata which require poking magic
2608 * values into undocumented hidden registers and then performing a
2609 * software reset.
2610 */
2611static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
2612{
2613 int port;
2614 int err;
2615
2616 if (mv88e6390_setup_errata_applied(chip))
2617 return 0;
2618
2619 /* Set the ports into blocking mode */
2620 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2621 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
2622 if (err)
2623 return err;
2624 }
2625
2626 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002627 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01002628 if (err)
2629 return err;
2630 }
2631
2632 return mv88e6xxx_software_reset(chip);
2633}
2634
Vivien Didelotf81ec902016-05-09 13:22:58 -04002635static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002636{
Vivien Didelot04bed142016-08-31 18:06:13 -04002637 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002638 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04002639 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002640 int i;
2641
Vivien Didelotfad09c72016-06-21 12:28:20 -04002642 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002643 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002644
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002645 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002646
Andrew Lunnea890982019-01-09 00:24:03 +01002647 if (chip->info->ops->setup_errata) {
2648 err = chip->info->ops->setup_errata(chip);
2649 if (err)
2650 goto unlock;
2651 }
2652
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002653 /* Cache the cmode of each port. */
2654 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2655 if (chip->info->ops->port_get_cmode) {
2656 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
2657 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03002658 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002659
2660 chip->ports[i].cmode = cmode;
2661 }
2662 }
2663
Vivien Didelot97299342016-07-18 20:45:30 -04002664 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002665 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04002666 if (dsa_is_unused_port(ds, i))
2667 continue;
2668
Hubert Feursteinc8574862019-07-31 10:23:48 +02002669 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04002670 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02002671 dev_err(chip->dev, "port %d is invalid\n", i);
2672 err = -EINVAL;
2673 goto unlock;
2674 }
2675
Vivien Didelot97299342016-07-18 20:45:30 -04002676 err = mv88e6xxx_setup_port(chip, i);
2677 if (err)
2678 goto unlock;
2679 }
2680
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002681 err = mv88e6xxx_irl_setup(chip);
2682 if (err)
2683 goto unlock;
2684
Vivien Didelot04a69a12017-10-13 14:18:05 -04002685 err = mv88e6xxx_mac_setup(chip);
2686 if (err)
2687 goto unlock;
2688
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002689 err = mv88e6xxx_phy_setup(chip);
2690 if (err)
2691 goto unlock;
2692
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002693 err = mv88e6xxx_vtu_setup(chip);
2694 if (err)
2695 goto unlock;
2696
Vivien Didelot81228992017-03-30 17:37:08 -04002697 err = mv88e6xxx_pvt_setup(chip);
2698 if (err)
2699 goto unlock;
2700
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002701 err = mv88e6xxx_atu_setup(chip);
2702 if (err)
2703 goto unlock;
2704
Andrew Lunn87fa8862017-11-09 22:29:56 +01002705 err = mv88e6xxx_broadcast_setup(chip, 0);
2706 if (err)
2707 goto unlock;
2708
Vivien Didelot9e907d72017-07-17 13:03:43 -04002709 err = mv88e6xxx_pot_setup(chip);
2710 if (err)
2711 goto unlock;
2712
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002713 err = mv88e6xxx_rmu_setup(chip);
2714 if (err)
2715 goto unlock;
2716
Vivien Didelot51c901a2017-07-17 13:03:41 -04002717 err = mv88e6xxx_rsvd2cpu_setup(chip);
2718 if (err)
2719 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002720
Vivien Didelotb28f8722018-04-26 21:56:44 -04002721 err = mv88e6xxx_trunk_setup(chip);
2722 if (err)
2723 goto unlock;
2724
Vivien Didelotc7f047b2018-04-26 21:56:45 -04002725 err = mv88e6xxx_devmap_setup(chip);
2726 if (err)
2727 goto unlock;
2728
Vivien Didelot93e18d62018-05-11 17:16:35 -04002729 err = mv88e6xxx_pri_setup(chip);
2730 if (err)
2731 goto unlock;
2732
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002733 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002734 if (chip->info->ptp_support) {
2735 err = mv88e6xxx_ptp_setup(chip);
2736 if (err)
2737 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002738
2739 err = mv88e6xxx_hwtstamp_setup(chip);
2740 if (err)
2741 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002742 }
2743
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002744 err = mv88e6xxx_stats_setup(chip);
2745 if (err)
2746 goto unlock;
2747
Vivien Didelot6b17e862015-08-13 12:52:18 -04002748unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002749 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02002750
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002751 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002752}
2753
Vivien Didelote57e5e72016-08-15 17:19:00 -04002754static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002755{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002756 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2757 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002758 u16 val;
2759 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002760
Andrew Lunnee26a222017-01-24 14:53:48 +01002761 if (!chip->info->ops->phy_read)
2762 return -EOPNOTSUPP;
2763
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002764 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01002765 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002766 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002767
Andrew Lunnda9f3302017-02-01 03:40:05 +01002768 if (reg == MII_PHYSID2) {
Andrew Lunnddc49ac2018-11-12 18:51:01 +01002769 /* Some internal PHYs don't have a model number. */
2770 if (chip->info->family != MV88E6XXX_FAMILY_6165)
2771 /* Then there is the 6165 family. It gets is
2772 * PHYs correct. But it can also have two
2773 * SERDES interfaces in the PHY address
2774 * space. And these don't have a model
2775 * number. But they are not PHYs, so we don't
2776 * want to give them something a PHY driver
2777 * will recognise.
2778 *
2779 * Use the mv88e6390 family model number
2780 * instead, for anything which really could be
2781 * a PHY,
2782 */
2783 if (!(val & 0x3f0))
2784 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002785 }
2786
Vivien Didelote57e5e72016-08-15 17:19:00 -04002787 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002788}
2789
Vivien Didelote57e5e72016-08-15 17:19:00 -04002790static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002791{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002792 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2793 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002794 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002795
Andrew Lunnee26a222017-01-24 14:53:48 +01002796 if (!chip->info->ops->phy_write)
2797 return -EOPNOTSUPP;
2798
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002799 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01002800 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002801 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002802
2803 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002804}
2805
Vivien Didelotfad09c72016-06-21 12:28:20 -04002806static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002807 struct device_node *np,
2808 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002809{
2810 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002811 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002812 struct mii_bus *bus;
2813 int err;
2814
Andrew Lunn2510bab2018-02-22 01:51:49 +01002815 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002816 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01002817 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002818 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01002819
2820 if (err)
2821 return err;
2822 }
2823
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002824 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002825 if (!bus)
2826 return -ENOMEM;
2827
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002828 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002829 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002830 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002831 INIT_LIST_HEAD(&mdio_bus->list);
2832 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002833
Andrew Lunnb516d452016-06-04 21:17:06 +02002834 if (np) {
2835 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05002836 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002837 } else {
2838 bus->name = "mv88e6xxx SMI";
2839 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2840 }
2841
2842 bus->read = mv88e6xxx_mdio_read;
2843 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002844 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002845
Andrew Lunn6f882842018-03-17 20:32:05 +01002846 if (!external) {
2847 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
2848 if (err)
2849 return err;
2850 }
2851
Florian Fainelli00e798c2018-05-15 16:56:19 -07002852 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002853 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002854 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01002855 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002856 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002857 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002858
2859 if (external)
2860 list_add_tail(&mdio_bus->list, &chip->mdios);
2861 else
2862 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002863
2864 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002865}
2866
Andrew Lunna3c53be52017-01-24 14:53:50 +01002867static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2868 { .compatible = "marvell,mv88e6xxx-mdio-external",
2869 .data = (void *)true },
2870 { },
2871};
2872
Andrew Lunn3126aee2017-12-07 01:05:57 +01002873static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
2874
2875{
2876 struct mv88e6xxx_mdio_bus *mdio_bus;
2877 struct mii_bus *bus;
2878
2879 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2880 bus = mdio_bus->bus;
2881
Andrew Lunn6f882842018-03-17 20:32:05 +01002882 if (!mdio_bus->external)
2883 mv88e6xxx_g2_irq_mdio_free(chip, bus);
2884
Andrew Lunn3126aee2017-12-07 01:05:57 +01002885 mdiobus_unregister(bus);
2886 }
2887}
2888
Andrew Lunna3c53be52017-01-24 14:53:50 +01002889static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2890 struct device_node *np)
2891{
2892 const struct of_device_id *match;
2893 struct device_node *child;
2894 int err;
2895
2896 /* Always register one mdio bus for the internal/default mdio
2897 * bus. This maybe represented in the device tree, but is
2898 * optional.
2899 */
2900 child = of_get_child_by_name(np, "mdio");
2901 err = mv88e6xxx_mdio_register(chip, child, false);
2902 if (err)
2903 return err;
2904
2905 /* Walk the device tree, and see if there are any other nodes
2906 * which say they are compatible with the external mdio
2907 * bus.
2908 */
2909 for_each_available_child_of_node(np, child) {
2910 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2911 if (match) {
2912 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01002913 if (err) {
2914 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05302915 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002916 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01002917 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002918 }
2919 }
2920
2921 return 0;
2922}
2923
Vivien Didelot855b1932016-07-20 18:18:35 -04002924static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2925{
Vivien Didelot04bed142016-08-31 18:06:13 -04002926 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002927
2928 return chip->eeprom_len;
2929}
2930
Vivien Didelot855b1932016-07-20 18:18:35 -04002931static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2932 struct ethtool_eeprom *eeprom, u8 *data)
2933{
Vivien Didelot04bed142016-08-31 18:06:13 -04002934 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002935 int err;
2936
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002937 if (!chip->info->ops->get_eeprom)
2938 return -EOPNOTSUPP;
2939
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002940 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002941 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002942 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04002943
2944 if (err)
2945 return err;
2946
2947 eeprom->magic = 0xc3ec4951;
2948
2949 return 0;
2950}
2951
Vivien Didelot855b1932016-07-20 18:18:35 -04002952static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2953 struct ethtool_eeprom *eeprom, u8 *data)
2954{
Vivien Didelot04bed142016-08-31 18:06:13 -04002955 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002956 int err;
2957
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002958 if (!chip->info->ops->set_eeprom)
2959 return -EOPNOTSUPP;
2960
Vivien Didelot855b1932016-07-20 18:18:35 -04002961 if (eeprom->magic != 0xc3ec4951)
2962 return -EINVAL;
2963
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002964 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002965 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002966 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04002967
2968 return err;
2969}
2970
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002971static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002972 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002973 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2974 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002975 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002976 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002977 .phy_read = mv88e6185_phy_ppu_read,
2978 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002979 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002980 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002981 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002982 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002983 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002984 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002985 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002986 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002987 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002988 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002989 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02002990 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002991 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002992 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002993 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002994 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01002995 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2996 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002997 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04002998 .set_cpu_port = mv88e6095_g1_set_cpu_port,
2999 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003000 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003001 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003002 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003003 .ppu_enable = mv88e6185_g1_ppu_enable,
3004 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003005 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003006 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003007 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003008 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003009 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003010};
3011
3012static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003013 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003014 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3015 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003016 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003017 .phy_read = mv88e6185_phy_ppu_read,
3018 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003019 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003020 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003021 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003022 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003023 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01003024 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Russell King6c422e32018-08-09 15:38:39 +02003025 .port_link_state = mv88e6185_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003026 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003027 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003028 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003029 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003030 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3031 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003032 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003033 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003034 .ppu_enable = mv88e6185_g1_ppu_enable,
3035 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003036 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003037 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003038 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003039 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003040};
3041
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003042static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003043 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003044 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3045 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003046 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003047 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3048 .phy_read = mv88e6xxx_g2_smi_phy_read,
3049 .phy_write = mv88e6xxx_g2_smi_phy_write,
3050 .port_set_link = mv88e6xxx_port_set_link,
3051 .port_set_duplex = mv88e6xxx_port_set_duplex,
3052 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003053 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003054 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003055 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003056 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003057 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003058 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003059 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003060 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003061 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003062 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003063 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003064 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003065 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003066 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003067 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3068 .stats_get_strings = mv88e6095_stats_get_strings,
3069 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003070 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3071 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003072 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003073 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003074 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003075 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003076 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003077 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003078 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003079 .phylink_validate = mv88e6185_phylink_validate,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003080};
3081
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003082static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003083 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003084 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3085 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003086 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003087 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003088 .phy_read = mv88e6xxx_g2_smi_phy_read,
3089 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003090 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003091 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003092 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003093 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003094 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003095 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003096 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003097 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003098 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003099 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003100 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003101 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003102 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3103 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003104 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003105 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3106 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003107 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003108 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003109 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003110 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003111 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003112 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003113 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003114};
3115
3116static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003117 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003118 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3119 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003120 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003121 .phy_read = mv88e6185_phy_ppu_read,
3122 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003123 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003124 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003125 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003126 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003127 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003128 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003129 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003130 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003131 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003132 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003133 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003134 .port_set_pause = mv88e6185_port_set_pause,
Russell King6c422e32018-08-09 15:38:39 +02003135 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003136 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003137 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003138 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003139 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003140 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3141 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003142 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003143 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3144 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003145 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003146 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003147 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003148 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003149 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003150 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003151 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003152 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003153 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003154};
3155
Vivien Didelot990e27b2017-03-28 13:50:32 -04003156static const struct mv88e6xxx_ops mv88e6141_ops = {
3157 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003158 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3159 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003160 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003161 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3162 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3163 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3164 .phy_read = mv88e6xxx_g2_smi_phy_read,
3165 .phy_write = mv88e6xxx_g2_smi_phy_write,
3166 .port_set_link = mv88e6xxx_port_set_link,
3167 .port_set_duplex = mv88e6xxx_port_set_duplex,
3168 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Marek Behún26422342018-10-13 14:40:31 +02003169 .port_set_speed = mv88e6341_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003170 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003171 .port_tag_remap = mv88e6095_port_tag_remap,
3172 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3173 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3174 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003175 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003176 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003177 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003178 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3179 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003180 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003181 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003182 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003183 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003184 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003185 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003186 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3187 .stats_get_strings = mv88e6320_stats_get_strings,
3188 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003189 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3190 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003191 .watchdog_ops = &mv88e6390_watchdog_ops,
3192 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003193 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003194 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003195 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003196 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003197 .serdes_power = mv88e6390_serdes_power,
3198 .serdes_get_lane = mv88e6341_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003199 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003200 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003201 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003202 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003203 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003204};
3205
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003206static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003207 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003208 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3209 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003210 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003211 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003212 .phy_read = mv88e6xxx_g2_smi_phy_read,
3213 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003214 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003215 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003216 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003217 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003218 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003219 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003220 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003221 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003222 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003223 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003224 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003225 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003226 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003227 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003228 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003229 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003230 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003231 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3232 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003233 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003234 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3235 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003236 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003237 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003238 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003239 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003240 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003241 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003242 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003243 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003244 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003245};
3246
3247static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003248 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003249 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3250 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003251 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003252 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003253 .phy_read = mv88e6165_phy_read,
3254 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003255 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003256 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003257 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003258 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003259 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003260 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003261 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003262 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003263 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003264 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003265 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3266 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003267 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003268 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3269 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003270 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003271 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003272 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003273 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003274 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003275 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003276 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003277 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003278 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003279};
3280
3281static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003282 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003283 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3284 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003285 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003286 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003287 .phy_read = mv88e6xxx_g2_smi_phy_read,
3288 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003289 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003290 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003291 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003292 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003293 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003294 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003295 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003296 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003297 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003298 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003299 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003300 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003301 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003302 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003303 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003304 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003305 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003306 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003307 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3308 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003309 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003310 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3311 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003312 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003313 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003314 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003315 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003316 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003317 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003318 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003319};
3320
3321static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003322 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003323 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3324 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003325 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003326 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3327 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003328 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003329 .phy_read = mv88e6xxx_g2_smi_phy_read,
3330 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003331 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003332 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003333 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003334 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003335 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003336 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003337 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003338 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003339 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003340 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003341 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003342 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003343 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003344 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003345 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003346 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003347 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003348 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003349 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003350 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3351 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003352 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003353 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3354 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003355 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003356 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003357 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003358 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003359 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003360 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003361 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003362 .serdes_get_lane = mv88e6352_serdes_get_lane,
Andrew Lunn6d917822017-05-26 01:03:21 +02003363 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003364 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003365 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003366};
3367
3368static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003369 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003370 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3371 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003372 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003373 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003374 .phy_read = mv88e6xxx_g2_smi_phy_read,
3375 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003376 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003377 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003378 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003379 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003380 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003381 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003382 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003383 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003384 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003385 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003386 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003387 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003388 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003389 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003390 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003391 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003392 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003393 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003394 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3395 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003396 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003397 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3398 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003399 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003400 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003401 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003402 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003403 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003404 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003405 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003406};
3407
3408static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003409 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003410 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3411 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003412 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003413 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3414 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003415 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003416 .phy_read = mv88e6xxx_g2_smi_phy_read,
3417 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003418 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003419 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003420 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003421 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003422 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003423 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003424 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003425 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003426 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003427 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003428 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003429 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003430 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003431 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003432 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003433 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003434 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003435 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003436 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003437 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3438 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003439 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003440 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3441 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003442 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003443 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003444 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003445 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003446 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003447 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003448 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003449 .serdes_get_lane = mv88e6352_serdes_get_lane,
Andrew Lunn6d917822017-05-26 01:03:21 +02003450 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003451 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003452 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003453 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003454 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003455 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003456};
3457
3458static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003459 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003460 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3461 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003462 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003463 .phy_read = mv88e6185_phy_ppu_read,
3464 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003465 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003466 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003467 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003468 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003469 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003470 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003471 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02003472 .port_set_pause = mv88e6185_port_set_pause,
Russell King6c422e32018-08-09 15:38:39 +02003473 .port_link_state = mv88e6185_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003474 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003475 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003476 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003477 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003478 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3479 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003480 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003481 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3482 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003483 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003484 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelot02317e62018-05-09 11:38:49 -04003485 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003486 .ppu_enable = mv88e6185_g1_ppu_enable,
3487 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003488 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003489 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003490 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003491 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003492};
3493
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003494static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003495 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003496 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003497 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003498 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3499 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003500 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3501 .phy_read = mv88e6xxx_g2_smi_phy_read,
3502 .phy_write = mv88e6xxx_g2_smi_phy_write,
3503 .port_set_link = mv88e6xxx_port_set_link,
3504 .port_set_duplex = mv88e6xxx_port_set_duplex,
3505 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3506 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003507 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003508 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003509 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003510 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003511 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003512 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003513 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003514 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003515 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003516 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003517 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003518 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003519 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003520 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003521 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003522 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3523 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003524 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003525 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3526 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003527 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003528 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003529 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003530 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003531 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003532 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3533 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003534 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003535 .serdes_get_lane = mv88e6390_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003536 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003537 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003538 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003539 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003540 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003541};
3542
3543static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003544 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003545 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003546 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003547 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3548 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003549 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3550 .phy_read = mv88e6xxx_g2_smi_phy_read,
3551 .phy_write = mv88e6xxx_g2_smi_phy_write,
3552 .port_set_link = mv88e6xxx_port_set_link,
3553 .port_set_duplex = mv88e6xxx_port_set_duplex,
3554 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3555 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003556 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003557 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003558 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003559 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003560 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003561 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003562 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003563 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003564 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003565 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003566 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003567 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003568 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003569 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003570 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003571 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3572 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003573 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003574 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3575 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003576 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003577 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003578 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003579 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003580 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003581 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3582 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003583 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003584 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003585 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003586 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003587 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003588 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003589 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003590};
3591
3592static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003593 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003594 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003595 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003596 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3597 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003598 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3599 .phy_read = mv88e6xxx_g2_smi_phy_read,
3600 .phy_write = mv88e6xxx_g2_smi_phy_write,
3601 .port_set_link = mv88e6xxx_port_set_link,
3602 .port_set_duplex = mv88e6xxx_port_set_duplex,
3603 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3604 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003605 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003606 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003607 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003608 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003609 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003610 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003611 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003612 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003613 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003614 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003615 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003616 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003617 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003618 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003619 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3620 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003621 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003622 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3623 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003624 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003625 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003626 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003627 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003628 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003629 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3630 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003631 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003632 .serdes_get_lane = mv88e6390_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003633 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003634 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003635 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003636 .avb_ops = &mv88e6390_avb_ops,
3637 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003638 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003639};
3640
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003641static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003642 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003643 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3644 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003645 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003646 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3647 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003648 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003649 .phy_read = mv88e6xxx_g2_smi_phy_read,
3650 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003651 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003652 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003653 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003654 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003655 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003656 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003657 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003658 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003659 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003660 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003661 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003662 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003663 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003664 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003665 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003666 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003667 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003668 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003669 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003670 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3671 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003672 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003673 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3674 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003675 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003676 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003677 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003678 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003679 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003680 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003681 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003682 .serdes_get_lane = mv88e6352_serdes_get_lane,
Andrew Lunn6d917822017-05-26 01:03:21 +02003683 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003684 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003685 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003686 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003687 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003688 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003689 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003690 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003691};
3692
Rasmus Villemoes1f718362019-06-04 07:34:32 +00003693static const struct mv88e6xxx_ops mv88e6250_ops = {
3694 /* MV88E6XXX_FAMILY_6250 */
3695 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
3696 .ip_pri_map = mv88e6085_g1_ip_pri_map,
3697 .irl_init_all = mv88e6352_g2_irl_init_all,
3698 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3699 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
3700 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3701 .phy_read = mv88e6xxx_g2_smi_phy_read,
3702 .phy_write = mv88e6xxx_g2_smi_phy_write,
3703 .port_set_link = mv88e6xxx_port_set_link,
3704 .port_set_duplex = mv88e6xxx_port_set_duplex,
3705 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3706 .port_set_speed = mv88e6250_port_set_speed,
3707 .port_tag_remap = mv88e6095_port_tag_remap,
3708 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3709 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3710 .port_set_ether_type = mv88e6351_port_set_ether_type,
3711 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3712 .port_pause_limit = mv88e6097_port_pause_limit,
3713 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3714 .port_link_state = mv88e6250_port_link_state,
3715 .stats_snapshot = mv88e6320_g1_stats_snapshot,
3716 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3717 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
3718 .stats_get_strings = mv88e6250_stats_get_strings,
3719 .stats_get_stats = mv88e6250_stats_get_stats,
3720 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3721 .set_egress_port = mv88e6095_g1_set_egress_port,
3722 .watchdog_ops = &mv88e6250_watchdog_ops,
3723 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3724 .pot_clear = mv88e6xxx_g2_pot_clear,
3725 .reset = mv88e6250_g1_reset,
3726 .vtu_getnext = mv88e6250_g1_vtu_getnext,
3727 .vtu_loadpurge = mv88e6250_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02003728 .avb_ops = &mv88e6352_avb_ops,
3729 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00003730 .phylink_validate = mv88e6065_phylink_validate,
3731};
3732
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003733static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003734 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003735 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003736 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003737 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3738 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003739 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3740 .phy_read = mv88e6xxx_g2_smi_phy_read,
3741 .phy_write = mv88e6xxx_g2_smi_phy_write,
3742 .port_set_link = mv88e6xxx_port_set_link,
3743 .port_set_duplex = mv88e6xxx_port_set_duplex,
3744 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3745 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003746 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003747 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003748 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003749 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003750 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003751 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003752 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003753 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003754 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003755 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003756 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003757 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003758 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003759 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003760 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003761 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3762 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003763 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003764 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3765 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003766 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003767 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003768 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003769 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003770 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003771 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3772 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003773 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003774 .serdes_get_lane = mv88e6390_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003775 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003776 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003777 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003778 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003779 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003780 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003781 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003782};
3783
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003784static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003785 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003786 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3787 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003788 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003789 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3790 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003791 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003792 .phy_read = mv88e6xxx_g2_smi_phy_read,
3793 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003794 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003795 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003796 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003797 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003798 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003799 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003800 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003801 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003802 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003803 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003804 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003805 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003806 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003807 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003808 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003809 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003810 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003811 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3812 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003813 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003814 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3815 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01003816 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003817 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003818 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003819 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003820 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003821 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003822 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003823 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003824 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003825 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003826};
3827
3828static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04003829 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003830 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3831 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003832 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003833 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3834 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003835 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003836 .phy_read = mv88e6xxx_g2_smi_phy_read,
3837 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003838 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003839 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003840 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003841 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003842 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003843 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003844 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003845 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003846 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003847 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003848 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003849 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003850 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003851 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003852 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003853 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003854 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003855 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3856 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003857 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003858 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3859 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01003860 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003861 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003862 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003863 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003864 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003865 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003866 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003867 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003868};
3869
Vivien Didelot16e329a2017-03-28 13:50:33 -04003870static const struct mv88e6xxx_ops mv88e6341_ops = {
3871 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003872 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3873 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003874 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003875 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3876 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3877 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3878 .phy_read = mv88e6xxx_g2_smi_phy_read,
3879 .phy_write = mv88e6xxx_g2_smi_phy_write,
3880 .port_set_link = mv88e6xxx_port_set_link,
3881 .port_set_duplex = mv88e6xxx_port_set_duplex,
3882 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Marek Behún26422342018-10-13 14:40:31 +02003883 .port_set_speed = mv88e6341_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003884 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003885 .port_tag_remap = mv88e6095_port_tag_remap,
3886 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3887 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3888 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003889 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003890 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003891 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003892 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3893 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003894 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003895 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003896 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003897 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003898 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003899 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003900 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3901 .stats_get_strings = mv88e6320_stats_get_strings,
3902 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003903 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3904 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003905 .watchdog_ops = &mv88e6390_watchdog_ops,
3906 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003907 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003908 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003909 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003910 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003911 .serdes_power = mv88e6390_serdes_power,
3912 .serdes_get_lane = mv88e6341_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003913 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003914 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003915 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003916 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003917 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003918 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003919 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003920};
3921
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003922static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003923 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003924 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3925 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003926 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003927 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003928 .phy_read = mv88e6xxx_g2_smi_phy_read,
3929 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003930 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003931 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003932 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003933 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003934 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003935 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003936 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003937 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003938 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003939 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003940 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003941 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003942 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003943 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003944 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003945 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003946 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003947 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003948 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3949 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003950 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003951 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3952 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003953 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003954 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003955 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003956 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003957 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003958 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003959 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003960};
3961
3962static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003963 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003964 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3965 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003966 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003967 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003968 .phy_read = mv88e6xxx_g2_smi_phy_read,
3969 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003970 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003971 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003972 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003973 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003974 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003975 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003976 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003977 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003978 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003979 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003980 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003981 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003982 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003983 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003984 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003985 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003986 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003987 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003988 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3989 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003990 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003991 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3992 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003993 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003994 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003995 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003996 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003997 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003998 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003999 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004000 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004001 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004002};
4003
4004static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004005 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004006 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4007 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004008 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004009 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4010 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004011 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004012 .phy_read = mv88e6xxx_g2_smi_phy_read,
4013 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004014 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01004015 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004016 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01004017 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004018 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004019 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004020 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004021 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004022 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004023 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004024 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004025 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004026 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004027 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004028 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004029 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004030 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004031 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004032 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004033 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4034 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004035 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004036 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4037 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004038 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004039 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004040 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004041 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004042 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004043 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004044 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004045 .serdes_get_lane = mv88e6352_serdes_get_lane,
Andrew Lunn6d917822017-05-26 01:03:21 +02004046 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004047 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004048 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004049 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004050 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004051 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004052 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004053 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4054 .serdes_get_strings = mv88e6352_serdes_get_strings,
4055 .serdes_get_stats = mv88e6352_serdes_get_stats,
Russell King6c422e32018-08-09 15:38:39 +02004056 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004057};
4058
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004059static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004060 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004061 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004062 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004063 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4064 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004065 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4066 .phy_read = mv88e6xxx_g2_smi_phy_read,
4067 .phy_write = mv88e6xxx_g2_smi_phy_write,
4068 .port_set_link = mv88e6xxx_port_set_link,
4069 .port_set_duplex = mv88e6xxx_port_set_duplex,
4070 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4071 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004072 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004073 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004074 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004075 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004076 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004077 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004078 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004079 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004080 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004081 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004082 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004083 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004084 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004085 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004086 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004087 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004088 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004089 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4090 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004091 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004092 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4093 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004094 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004095 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004096 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004097 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004098 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04004099 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4100 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004101 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004102 .serdes_get_lane = mv88e6390_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004103 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004104 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004105 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004106 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004107 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004108 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004109 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004110};
4111
4112static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004113 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004114 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004115 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004116 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4117 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004118 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4119 .phy_read = mv88e6xxx_g2_smi_phy_read,
4120 .phy_write = mv88e6xxx_g2_smi_phy_write,
4121 .port_set_link = mv88e6xxx_port_set_link,
4122 .port_set_duplex = mv88e6xxx_port_set_duplex,
4123 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4124 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004125 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004126 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004127 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004128 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004129 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004130 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004131 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004132 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004133 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004134 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004135 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004136 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004137 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004138 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004139 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004140 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004141 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004142 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4143 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004144 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004145 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4146 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004147 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004148 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004149 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004150 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004151 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04004152 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4153 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004154 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004155 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004156 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004157 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004158 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004159 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004160 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004161 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004162 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004163};
4164
Vivien Didelotf81ec902016-05-09 13:22:58 -04004165static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4166 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004167 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004168 .family = MV88E6XXX_FAMILY_6097,
4169 .name = "Marvell 88E6085",
4170 .num_databases = 4096,
4171 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004172 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004173 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004174 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004175 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004176 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004177 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004178 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004179 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004180 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004181 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004182 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004183 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004184 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004185 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004186 },
4187
4188 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004189 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004190 .family = MV88E6XXX_FAMILY_6095,
4191 .name = "Marvell 88E6095/88E6095F",
4192 .num_databases = 256,
4193 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004194 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004195 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004196 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004197 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004198 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004199 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004200 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004201 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004202 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004203 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004204 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004205 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004206 },
4207
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004208 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004209 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004210 .family = MV88E6XXX_FAMILY_6097,
4211 .name = "Marvell 88E6097/88E6097F",
4212 .num_databases = 4096,
4213 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004214 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004215 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004216 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004217 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004218 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004219 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004220 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004221 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004222 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004223 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004224 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004225 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01004226 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004227 .ops = &mv88e6097_ops,
4228 },
4229
Vivien Didelotf81ec902016-05-09 13:22:58 -04004230 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004231 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004232 .family = MV88E6XXX_FAMILY_6165,
4233 .name = "Marvell 88E6123",
4234 .num_databases = 4096,
4235 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004236 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004237 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004238 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004239 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004240 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004241 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004242 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004243 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004244 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004245 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004246 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004247 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004248 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004249 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004250 },
4251
4252 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004253 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004254 .family = MV88E6XXX_FAMILY_6185,
4255 .name = "Marvell 88E6131",
4256 .num_databases = 256,
4257 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004258 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004259 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004260 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004261 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004262 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004263 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004264 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004265 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004266 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004267 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004268 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004269 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004270 },
4271
Vivien Didelot990e27b2017-03-28 13:50:32 -04004272 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004273 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004274 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01004275 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04004276 .num_databases = 4096,
4277 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004278 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004279 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004280 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004281 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004282 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004283 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004284 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004285 .age_time_coeff = 3750,
4286 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004287 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004288 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004289 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004290 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004291 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004292 .ops = &mv88e6141_ops,
4293 },
4294
Vivien Didelotf81ec902016-05-09 13:22:58 -04004295 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004296 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004297 .family = MV88E6XXX_FAMILY_6165,
4298 .name = "Marvell 88E6161",
4299 .num_databases = 4096,
4300 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004301 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004302 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004303 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004304 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004305 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004306 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004307 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004308 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004309 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004310 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004311 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004312 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004313 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004314 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004315 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004316 },
4317
4318 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004319 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004320 .family = MV88E6XXX_FAMILY_6165,
4321 .name = "Marvell 88E6165",
4322 .num_databases = 4096,
4323 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004324 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004325 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004326 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004327 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004328 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004329 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004330 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004331 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004332 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004333 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004334 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004335 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004336 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004337 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004338 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004339 },
4340
4341 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004342 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004343 .family = MV88E6XXX_FAMILY_6351,
4344 .name = "Marvell 88E6171",
4345 .num_databases = 4096,
4346 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004347 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004348 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004349 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004350 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004351 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004352 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004353 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004354 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004355 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004356 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004357 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004358 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004359 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004360 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004361 },
4362
4363 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004364 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004365 .family = MV88E6XXX_FAMILY_6352,
4366 .name = "Marvell 88E6172",
4367 .num_databases = 4096,
4368 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004369 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004370 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004371 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004372 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004373 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004374 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004375 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004376 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004377 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004378 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004379 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004380 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004381 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004382 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004383 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004384 },
4385
4386 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004387 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004388 .family = MV88E6XXX_FAMILY_6351,
4389 .name = "Marvell 88E6175",
4390 .num_databases = 4096,
4391 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004392 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004393 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004394 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004395 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004396 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004397 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004398 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004399 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004400 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004401 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004402 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004403 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004404 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004405 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004406 },
4407
4408 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004409 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004410 .family = MV88E6XXX_FAMILY_6352,
4411 .name = "Marvell 88E6176",
4412 .num_databases = 4096,
4413 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004414 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004415 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004416 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004417 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004418 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004419 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004420 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004421 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004422 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004423 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004424 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004425 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004426 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004427 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004428 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004429 },
4430
4431 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004432 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004433 .family = MV88E6XXX_FAMILY_6185,
4434 .name = "Marvell 88E6185",
4435 .num_databases = 256,
4436 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004437 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004438 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004439 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004440 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004441 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004442 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004443 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004444 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004445 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004446 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004447 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004448 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004449 },
4450
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004451 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004452 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004453 .family = MV88E6XXX_FAMILY_6390,
4454 .name = "Marvell 88E6190",
4455 .num_databases = 4096,
4456 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004457 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004458 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004459 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004460 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004461 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004462 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004463 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004464 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004465 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004466 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004467 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04004468 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004469 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05004470 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004471 .ops = &mv88e6190_ops,
4472 },
4473
4474 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004475 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004476 .family = MV88E6XXX_FAMILY_6390,
4477 .name = "Marvell 88E6190X",
4478 .num_databases = 4096,
4479 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004480 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004481 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004482 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004483 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004484 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004485 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004486 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004487 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004488 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004489 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004490 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004491 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004492 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004493 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004494 .ops = &mv88e6190x_ops,
4495 },
4496
4497 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004498 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004499 .family = MV88E6XXX_FAMILY_6390,
4500 .name = "Marvell 88E6191",
4501 .num_databases = 4096,
4502 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004503 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04004504 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004505 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004506 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004507 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004508 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004509 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004510 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004511 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004512 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004513 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004514 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004515 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004516 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04004517 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004518 },
4519
Hubert Feurstein49022642019-07-31 10:23:46 +02004520 [MV88E6220] = {
4521 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
4522 .family = MV88E6XXX_FAMILY_6250,
4523 .name = "Marvell 88E6220",
4524 .num_databases = 64,
4525
4526 /* Ports 2-4 are not routed to pins
4527 * => usable ports 0, 1, 5, 6
4528 */
4529 .num_ports = 7,
4530 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02004531 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02004532 .max_vid = 4095,
4533 .port_base_addr = 0x08,
4534 .phy_base_addr = 0x00,
4535 .global1_addr = 0x0f,
4536 .global2_addr = 0x07,
4537 .age_time_coeff = 15000,
4538 .g1_irqs = 9,
4539 .g2_irqs = 10,
4540 .atu_move_port_mask = 0xf,
4541 .dual_chip = true,
4542 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02004543 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02004544 .ops = &mv88e6250_ops,
4545 },
4546
Vivien Didelotf81ec902016-05-09 13:22:58 -04004547 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004548 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004549 .family = MV88E6XXX_FAMILY_6352,
4550 .name = "Marvell 88E6240",
4551 .num_databases = 4096,
4552 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004553 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004554 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004555 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004556 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004557 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004558 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004559 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004560 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004561 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004562 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004563 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004564 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004565 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004566 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004567 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004568 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004569 },
4570
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004571 [MV88E6250] = {
4572 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
4573 .family = MV88E6XXX_FAMILY_6250,
4574 .name = "Marvell 88E6250",
4575 .num_databases = 64,
4576 .num_ports = 7,
4577 .num_internal_phys = 5,
4578 .max_vid = 4095,
4579 .port_base_addr = 0x08,
4580 .phy_base_addr = 0x00,
4581 .global1_addr = 0x0f,
4582 .global2_addr = 0x07,
4583 .age_time_coeff = 15000,
4584 .g1_irqs = 9,
4585 .g2_irqs = 10,
4586 .atu_move_port_mask = 0xf,
4587 .dual_chip = true,
4588 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02004589 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004590 .ops = &mv88e6250_ops,
4591 },
4592
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004593 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004594 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004595 .family = MV88E6XXX_FAMILY_6390,
4596 .name = "Marvell 88E6290",
4597 .num_databases = 4096,
4598 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004599 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004600 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004601 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004602 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004603 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004604 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004605 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004606 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004607 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004608 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004609 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004610 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004611 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004612 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004613 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004614 .ops = &mv88e6290_ops,
4615 },
4616
Vivien Didelotf81ec902016-05-09 13:22:58 -04004617 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004618 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004619 .family = MV88E6XXX_FAMILY_6320,
4620 .name = "Marvell 88E6320",
4621 .num_databases = 4096,
4622 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004623 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004624 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004625 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004626 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004627 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004628 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004629 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004630 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004631 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004632 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004633 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004634 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004635 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004636 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004637 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004638 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004639 },
4640
4641 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004642 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004643 .family = MV88E6XXX_FAMILY_6320,
4644 .name = "Marvell 88E6321",
4645 .num_databases = 4096,
4646 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004647 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004648 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004649 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004650 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004651 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004652 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004653 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004654 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004655 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004656 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004657 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004658 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004659 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004660 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004661 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004662 },
4663
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004664 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004665 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004666 .family = MV88E6XXX_FAMILY_6341,
4667 .name = "Marvell 88E6341",
4668 .num_databases = 4096,
Andrew Lunnbc393152018-03-17 20:32:04 +01004669 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004670 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004671 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004672 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004673 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004674 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004675 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004676 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004677 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05004678 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004679 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004680 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004681 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004682 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004683 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004684 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004685 .ops = &mv88e6341_ops,
4686 },
4687
Vivien Didelotf81ec902016-05-09 13:22:58 -04004688 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004689 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004690 .family = MV88E6XXX_FAMILY_6351,
4691 .name = "Marvell 88E6350",
4692 .num_databases = 4096,
4693 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004694 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004695 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004696 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004697 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004698 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004699 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004700 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004701 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004702 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004703 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004704 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004705 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004706 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004707 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004708 },
4709
4710 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004711 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004712 .family = MV88E6XXX_FAMILY_6351,
4713 .name = "Marvell 88E6351",
4714 .num_databases = 4096,
4715 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004716 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004717 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004718 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004719 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004720 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004721 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004722 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004723 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004724 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004725 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004726 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004727 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004728 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004729 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004730 },
4731
4732 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004733 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004734 .family = MV88E6XXX_FAMILY_6352,
4735 .name = "Marvell 88E6352",
4736 .num_databases = 4096,
4737 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004738 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004739 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004740 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004741 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004742 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004743 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004744 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004745 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004746 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004747 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004748 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004749 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004750 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004751 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004752 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004753 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004754 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004755 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004756 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004757 .family = MV88E6XXX_FAMILY_6390,
4758 .name = "Marvell 88E6390",
4759 .num_databases = 4096,
4760 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004761 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004762 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004763 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004764 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004765 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004766 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004767 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004768 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004769 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004770 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004771 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004772 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004773 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004774 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004775 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004776 .ops = &mv88e6390_ops,
4777 },
4778 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004779 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004780 .family = MV88E6XXX_FAMILY_6390,
4781 .name = "Marvell 88E6390X",
4782 .num_databases = 4096,
4783 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004784 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004785 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004786 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004787 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004788 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004789 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004790 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004791 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004792 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004793 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004794 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004795 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004796 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004797 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004798 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004799 .ops = &mv88e6390x_ops,
4800 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004801};
4802
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004803static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004804{
Vivien Didelota439c062016-04-17 13:23:58 -04004805 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004806
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004807 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4808 if (mv88e6xxx_table[i].prod_num == prod_num)
4809 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004810
Vivien Didelotb9b37712015-10-30 19:39:48 -04004811 return NULL;
4812}
4813
Vivien Didelotfad09c72016-06-21 12:28:20 -04004814static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004815{
4816 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004817 unsigned int prod_num, rev;
4818 u16 id;
4819 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004820
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004821 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04004822 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004823 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004824 if (err)
4825 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004826
Vivien Didelot107fcc12017-06-12 12:37:36 -04004827 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
4828 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004829
4830 info = mv88e6xxx_lookup_info(prod_num);
4831 if (!info)
4832 return -ENODEV;
4833
Vivien Didelotcaac8542016-06-20 13:14:09 -04004834 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004835 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004836
Vivien Didelotca070c12016-09-02 14:45:34 -04004837 err = mv88e6xxx_g2_require(chip);
4838 if (err)
4839 return err;
4840
Vivien Didelotfad09c72016-06-21 12:28:20 -04004841 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4842 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004843
4844 return 0;
4845}
4846
Vivien Didelotfad09c72016-06-21 12:28:20 -04004847static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004848{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004849 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004850
Vivien Didelotfad09c72016-06-21 12:28:20 -04004851 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4852 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004853 return NULL;
4854
Vivien Didelotfad09c72016-06-21 12:28:20 -04004855 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004856
Vivien Didelotfad09c72016-06-21 12:28:20 -04004857 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004858 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04004859 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04004860
Vivien Didelotfad09c72016-06-21 12:28:20 -04004861 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004862}
4863
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08004864static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
4865 int port)
Andrew Lunn7b314362016-08-22 16:01:01 +02004866{
Vivien Didelot04bed142016-08-31 18:06:13 -04004867 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004868
Andrew Lunn443d5a12016-12-03 04:35:18 +01004869 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004870}
4871
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004872static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004873 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004874{
4875 /* We don't need any dynamic resource from the kernel (yet),
4876 * so skip the prepare phase.
4877 */
4878
4879 return 0;
4880}
4881
4882static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004883 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004884{
Vivien Didelot04bed142016-08-31 18:06:13 -04004885 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004886
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004887 mv88e6xxx_reg_lock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004888 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004889 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04004890 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
4891 port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004892 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004893}
4894
4895static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4896 const struct switchdev_obj_port_mdb *mdb)
4897{
Vivien Didelot04bed142016-08-31 18:06:13 -04004898 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004899 int err;
4900
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004901 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04004902 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004903 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004904
4905 return err;
4906}
4907
Russell King4f859012019-02-20 15:35:05 -08004908static int mv88e6xxx_port_egress_floods(struct dsa_switch *ds, int port,
4909 bool unicast, bool multicast)
4910{
4911 struct mv88e6xxx_chip *chip = ds->priv;
4912 int err = -EOPNOTSUPP;
4913
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004914 mv88e6xxx_reg_lock(chip);
Russell King4f859012019-02-20 15:35:05 -08004915 if (chip->info->ops->port_set_egress_floods)
4916 err = chip->info->ops->port_set_egress_floods(chip, port,
4917 unicast,
4918 multicast);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004919 mv88e6xxx_reg_unlock(chip);
Russell King4f859012019-02-20 15:35:05 -08004920
4921 return err;
4922}
4923
Florian Fainellia82f67a2017-01-08 14:52:08 -08004924static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02004925 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004926 .setup = mv88e6xxx_setup,
Russell Kingc9a23562018-05-10 13:17:35 -07004927 .phylink_validate = mv88e6xxx_validate,
4928 .phylink_mac_link_state = mv88e6xxx_link_state,
4929 .phylink_mac_config = mv88e6xxx_mac_config,
4930 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
4931 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004932 .get_strings = mv88e6xxx_get_strings,
4933 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4934 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02004935 .port_enable = mv88e6xxx_port_enable,
4936 .port_disable = mv88e6xxx_port_disable,
Vivien Didelot08f50062017-08-01 16:32:41 -04004937 .get_mac_eee = mv88e6xxx_get_mac_eee,
4938 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004939 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004940 .get_eeprom = mv88e6xxx_get_eeprom,
4941 .set_eeprom = mv88e6xxx_set_eeprom,
4942 .get_regs_len = mv88e6xxx_get_regs_len,
4943 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04004944 .get_rxnfc = mv88e6xxx_get_rxnfc,
4945 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004946 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004947 .port_bridge_join = mv88e6xxx_port_bridge_join,
4948 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Russell King4f859012019-02-20 15:35:05 -08004949 .port_egress_floods = mv88e6xxx_port_egress_floods,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004950 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004951 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004952 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4953 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4954 .port_vlan_add = mv88e6xxx_port_vlan_add,
4955 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004956 .port_fdb_add = mv88e6xxx_port_fdb_add,
4957 .port_fdb_del = mv88e6xxx_port_fdb_del,
4958 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004959 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4960 .port_mdb_add = mv88e6xxx_port_mdb_add,
4961 .port_mdb_del = mv88e6xxx_port_mdb_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04004962 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
4963 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004964 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
4965 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
4966 .port_txtstamp = mv88e6xxx_port_txtstamp,
4967 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
4968 .get_ts_info = mv88e6xxx_get_ts_info,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004969};
4970
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004971static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004972{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004973 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004974 struct dsa_switch *ds;
4975
Vivien Didelot73b12042017-03-30 17:37:10 -04004976 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004977 if (!ds)
4978 return -ENOMEM;
4979
Vivien Didelotfad09c72016-06-21 12:28:20 -04004980 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004981 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004982 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004983 ds->ageing_time_min = chip->info->age_time_coeff;
4984 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004985
4986 dev_set_drvdata(dev, ds);
4987
Vivien Didelot23c9ee42017-05-26 18:12:51 -04004988 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004989}
4990
Vivien Didelotfad09c72016-06-21 12:28:20 -04004991static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004992{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004993 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004994}
4995
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004996static const void *pdata_device_get_match_data(struct device *dev)
4997{
4998 const struct of_device_id *matches = dev->driver->of_match_table;
4999 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
5000
5001 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
5002 matches++) {
5003 if (!strcmp(pdata->compatible, matches->compatible))
5004 return matches->data;
5005 }
5006 return NULL;
5007}
5008
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005009/* There is no suspend to RAM support at DSA level yet, the switch configuration
5010 * would be lost after a power cycle so prevent it to be suspended.
5011 */
5012static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
5013{
5014 return -EOPNOTSUPP;
5015}
5016
5017static int __maybe_unused mv88e6xxx_resume(struct device *dev)
5018{
5019 return 0;
5020}
5021
5022static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
5023
Vivien Didelot57d32312016-06-20 13:13:58 -04005024static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005025{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005026 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04005027 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005028 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005029 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04005030 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005031 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02005032 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005033
Andrew Lunn7bb8c992018-05-31 00:15:42 +02005034 if (!np && !pdata)
5035 return -EINVAL;
5036
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005037 if (np)
5038 compat_info = of_device_get_match_data(dev);
5039
5040 if (pdata) {
5041 compat_info = pdata_device_get_match_data(dev);
5042
5043 if (!pdata->netdev)
5044 return -EINVAL;
5045
5046 for (port = 0; port < DSA_MAX_PORTS; port++) {
5047 if (!(pdata->enabled_ports & (1 << port)))
5048 continue;
5049 if (strcmp(pdata->cd.port_names[port], "cpu"))
5050 continue;
5051 pdata->cd.netdev[port] = &pdata->netdev->dev;
5052 break;
5053 }
5054 }
5055
Vivien Didelotcaac8542016-06-20 13:14:09 -04005056 if (!compat_info)
5057 return -EINVAL;
5058
Vivien Didelotfad09c72016-06-21 12:28:20 -04005059 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005060 if (!chip) {
5061 err = -ENOMEM;
5062 goto out;
5063 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005064
Vivien Didelotfad09c72016-06-21 12:28:20 -04005065 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04005066
Vivien Didelotfad09c72016-06-21 12:28:20 -04005067 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04005068 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005069 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005070
Andrew Lunnb4308f02016-11-21 23:26:55 +01005071 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005072 if (IS_ERR(chip->reset)) {
5073 err = PTR_ERR(chip->reset);
5074 goto out;
5075 }
Baruch Siach7b75e492019-06-27 21:17:39 +03005076 if (chip->reset)
5077 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01005078
Vivien Didelotfad09c72016-06-21 12:28:20 -04005079 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005080 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005081 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005082
Vivien Didelote57e5e72016-08-15 17:19:00 -04005083 mv88e6xxx_phy_init(chip);
5084
Andrew Lunn00baabe2018-05-19 22:31:35 +02005085 if (chip->info->ops->get_eeprom) {
5086 if (np)
5087 of_property_read_u32(np, "eeprom-length",
5088 &chip->eeprom_len);
5089 else
5090 chip->eeprom_len = pdata->eeprom_len;
5091 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005092
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005093 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005094 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005095 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02005096 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02005097 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02005098
Andrew Lunna27415d2019-05-01 00:10:50 +02005099 if (np) {
5100 chip->irq = of_irq_get(np, 0);
5101 if (chip->irq == -EPROBE_DEFER) {
5102 err = chip->irq;
5103 goto out;
5104 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02005105 }
5106
Andrew Lunna27415d2019-05-01 00:10:50 +02005107 if (pdata)
5108 chip->irq = pdata->irq;
5109
Andrew Lunn294d7112018-02-22 22:58:32 +01005110 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01005111 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01005112 * controllers
5113 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005114 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005115 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005116 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005117 else
5118 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005119 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005120
Andrew Lunn294d7112018-02-22 22:58:32 +01005121 if (err)
5122 goto out;
5123
5124 if (chip->info->g2_irqs > 0) {
5125 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005126 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01005127 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005128 }
5129
Andrew Lunn294d7112018-02-22 22:58:32 +01005130 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
5131 if (err)
5132 goto out_g2_irq;
5133
5134 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
5135 if (err)
5136 goto out_g1_atu_prob_irq;
5137
Andrew Lunna3c53be52017-01-24 14:53:50 +01005138 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02005139 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01005140 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005141
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005142 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005143 if (err)
5144 goto out_mdio;
5145
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005146 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02005147
5148out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01005149 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01005150out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005151 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01005152out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005153 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005154out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005155 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005156 mv88e6xxx_g2_irq_free(chip);
5157out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005158 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005159 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005160 else
5161 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005162out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005163 if (pdata)
5164 dev_put(pdata->netdev);
5165
Andrew Lunndc30c352016-10-16 19:56:49 +02005166 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005167}
5168
5169static void mv88e6xxx_remove(struct mdio_device *mdiodev)
5170{
5171 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04005172 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005173
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005174 if (chip->info->ptp_support) {
5175 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005176 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005177 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005178
Andrew Lunn930188c2016-08-22 16:01:03 +02005179 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005180 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005181 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005182
Andrew Lunn76f38f12018-03-17 20:21:09 +01005183 mv88e6xxx_g1_vtu_prob_irq_free(chip);
5184 mv88e6xxx_g1_atu_prob_irq_free(chip);
5185
5186 if (chip->info->g2_irqs > 0)
5187 mv88e6xxx_g2_irq_free(chip);
5188
Andrew Lunn76f38f12018-03-17 20:21:09 +01005189 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005190 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01005191 else
5192 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005193}
5194
5195static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04005196 {
5197 .compatible = "marvell,mv88e6085",
5198 .data = &mv88e6xxx_table[MV88E6085],
5199 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005200 {
5201 .compatible = "marvell,mv88e6190",
5202 .data = &mv88e6xxx_table[MV88E6190],
5203 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005204 {
5205 .compatible = "marvell,mv88e6250",
5206 .data = &mv88e6xxx_table[MV88E6250],
5207 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005208 { /* sentinel */ },
5209};
5210
5211MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
5212
5213static struct mdio_driver mv88e6xxx_driver = {
5214 .probe = mv88e6xxx_probe,
5215 .remove = mv88e6xxx_remove,
5216 .mdiodrv.driver = {
5217 .name = "mv88e6085",
5218 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005219 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005220 },
5221};
5222
Andrew Lunn7324d502019-04-27 19:19:10 +02005223mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00005224
5225MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
5226MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
5227MODULE_LICENSE("GPL");