blob: af89431420532735bdf36f44e6f344abcf769211 [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 Didelot9dc8b132019-10-21 16:51:26 -04001060/* Mask of the local ports allowed to receive frames from a given fabric port */
Vivien Didelote5887a22017-03-30 17:37:11 -04001061static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001062{
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001063 struct dsa_switch *ds = chip->ds;
1064 struct dsa_switch_tree *dst = ds->dst;
Vivien Didelote5887a22017-03-30 17:37:11 -04001065 struct net_device *br;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001066 struct dsa_port *dp;
1067 bool found = false;
Vivien Didelote5887a22017-03-30 17:37:11 -04001068 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001069
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001070 list_for_each_entry(dp, &dst->ports, list) {
1071 if (dp->ds->index == dev && dp->index == port) {
1072 found = true;
1073 break;
1074 }
1075 }
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001076
Vivien Didelote5887a22017-03-30 17:37:11 -04001077 /* Prevent frames from unknown switch or port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001078 if (!found)
Vivien Didelote5887a22017-03-30 17:37:11 -04001079 return 0;
1080
1081 /* Frames from DSA links and CPU ports can egress any local port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001082 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
Vivien Didelote5887a22017-03-30 17:37:11 -04001083 return mv88e6xxx_port_mask(chip);
1084
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001085 br = dp->bridge_dev;
Vivien Didelote5887a22017-03-30 17:37:11 -04001086 pvlan = 0;
1087
1088 /* Frames from user ports can egress any local DSA links and CPU ports,
1089 * as well as any local member of their bridge group.
1090 */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001091 list_for_each_entry(dp, &dst->ports, list)
1092 if (dp->ds == ds &&
1093 (dp->type == DSA_PORT_TYPE_CPU ||
1094 dp->type == DSA_PORT_TYPE_DSA ||
1095 (br && dp->bridge_dev == br)))
1096 pvlan |= BIT(dp->index);
Vivien Didelote5887a22017-03-30 17:37:11 -04001097
1098 return pvlan;
1099}
1100
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001101static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001102{
1103 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001104
1105 /* prevent frames from going back out of the port they came in on */
1106 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001107
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001108 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001109}
1110
Vivien Didelotf81ec902016-05-09 13:22:58 -04001111static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1112 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001113{
Vivien Didelot04bed142016-08-31 18:06:13 -04001114 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001115 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001116
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001117 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001118 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001119 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001120
1121 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001122 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001123}
1124
Vivien Didelot93e18d62018-05-11 17:16:35 -04001125static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1126{
1127 int err;
1128
1129 if (chip->info->ops->ieee_pri_map) {
1130 err = chip->info->ops->ieee_pri_map(chip);
1131 if (err)
1132 return err;
1133 }
1134
1135 if (chip->info->ops->ip_pri_map) {
1136 err = chip->info->ops->ip_pri_map(chip);
1137 if (err)
1138 return err;
1139 }
1140
1141 return 0;
1142}
1143
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001144static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1145{
1146 int target, port;
1147 int err;
1148
1149 if (!chip->info->global2_addr)
1150 return 0;
1151
1152 /* Initialize the routing port to the 32 possible target devices */
1153 for (target = 0; target < 32; target++) {
1154 port = 0x1f;
1155 if (target < DSA_MAX_SWITCHES)
1156 if (chip->ds->rtable[target] != DSA_RTABLE_NONE)
1157 port = chip->ds->rtable[target];
1158
1159 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1160 if (err)
1161 return err;
1162 }
1163
Vivien Didelot02317e62018-05-09 11:38:49 -04001164 if (chip->info->ops->set_cascade_port) {
1165 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1166 err = chip->info->ops->set_cascade_port(chip, port);
1167 if (err)
1168 return err;
1169 }
1170
Vivien Didelot23c98912018-05-09 11:38:50 -04001171 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1172 if (err)
1173 return err;
1174
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001175 return 0;
1176}
1177
Vivien Didelotb28f8722018-04-26 21:56:44 -04001178static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1179{
1180 /* Clear all trunk masks and mapping */
1181 if (chip->info->global2_addr)
1182 return mv88e6xxx_g2_trunk_clear(chip);
1183
1184 return 0;
1185}
1186
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001187static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1188{
1189 if (chip->info->ops->rmu_disable)
1190 return chip->info->ops->rmu_disable(chip);
1191
1192 return 0;
1193}
1194
Vivien Didelot9e907d72017-07-17 13:03:43 -04001195static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1196{
1197 if (chip->info->ops->pot_clear)
1198 return chip->info->ops->pot_clear(chip);
1199
1200 return 0;
1201}
1202
Vivien Didelot51c901a2017-07-17 13:03:41 -04001203static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1204{
1205 if (chip->info->ops->mgmt_rsvd2cpu)
1206 return chip->info->ops->mgmt_rsvd2cpu(chip);
1207
1208 return 0;
1209}
1210
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001211static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1212{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001213 int err;
1214
Vivien Didelotdaefc942017-03-11 16:12:54 -05001215 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1216 if (err)
1217 return err;
1218
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001219 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1220 if (err)
1221 return err;
1222
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001223 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1224}
1225
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001226static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1227{
1228 int port;
1229 int err;
1230
1231 if (!chip->info->ops->irl_init_all)
1232 return 0;
1233
1234 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1235 /* Disable ingress rate limiting by resetting all per port
1236 * ingress rate limit resources to their initial state.
1237 */
1238 err = chip->info->ops->irl_init_all(chip, port);
1239 if (err)
1240 return err;
1241 }
1242
1243 return 0;
1244}
1245
Vivien Didelot04a69a12017-10-13 14:18:05 -04001246static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1247{
1248 if (chip->info->ops->set_switch_mac) {
1249 u8 addr[ETH_ALEN];
1250
1251 eth_random_addr(addr);
1252
1253 return chip->info->ops->set_switch_mac(chip, addr);
1254 }
1255
1256 return 0;
1257}
1258
Vivien Didelot17a15942017-03-30 17:37:09 -04001259static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1260{
1261 u16 pvlan = 0;
1262
1263 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001264 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001265
1266 /* Skip the local source device, which uses in-chip port VLAN */
1267 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001268 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001269
1270 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1271}
1272
Vivien Didelot81228992017-03-30 17:37:08 -04001273static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1274{
Vivien Didelot17a15942017-03-30 17:37:09 -04001275 int dev, port;
1276 int err;
1277
Vivien Didelot81228992017-03-30 17:37:08 -04001278 if (!mv88e6xxx_has_pvt(chip))
1279 return 0;
1280
1281 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1282 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1283 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001284 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1285 if (err)
1286 return err;
1287
1288 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1289 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1290 err = mv88e6xxx_pvt_map(chip, dev, port);
1291 if (err)
1292 return err;
1293 }
1294 }
1295
1296 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001297}
1298
Vivien Didelot749efcb2016-09-22 16:49:24 -04001299static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1300{
1301 struct mv88e6xxx_chip *chip = ds->priv;
1302 int err;
1303
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001304 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001305 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001306 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001307
1308 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001309 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001310}
1311
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001312static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1313{
1314 if (!chip->info->max_vid)
1315 return 0;
1316
1317 return mv88e6xxx_g1_vtu_flush(chip);
1318}
1319
Vivien Didelotf1394b782017-05-01 14:05:22 -04001320static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1321 struct mv88e6xxx_vtu_entry *entry)
1322{
1323 if (!chip->info->ops->vtu_getnext)
1324 return -EOPNOTSUPP;
1325
1326 return chip->info->ops->vtu_getnext(chip, entry);
1327}
1328
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001329static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1330 struct mv88e6xxx_vtu_entry *entry)
1331{
1332 if (!chip->info->ops->vtu_loadpurge)
1333 return -EOPNOTSUPP;
1334
1335 return chip->info->ops->vtu_loadpurge(chip, entry);
1336}
1337
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001338static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001339{
1340 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot425d2d32019-08-01 14:36:34 -04001341 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001342 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001343
1344 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1345
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001346 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001347 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001348 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001349 if (err)
1350 return err;
1351
1352 set_bit(*fid, fid_bitmap);
1353 }
1354
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001355 /* Set every FID bit used by the VLAN entries */
Vivien Didelot425d2d32019-08-01 14:36:34 -04001356 vlan.vid = chip->info->max_vid;
1357 vlan.valid = false;
1358
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001359 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001360 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001361 if (err)
1362 return err;
1363
1364 if (!vlan.valid)
1365 break;
1366
1367 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001368 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001369
1370 /* The reset value 0x000 is used to indicate that multiple address
1371 * databases are not needed. Return the next positive available.
1372 */
1373 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001374 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001375 return -ENOSPC;
1376
1377 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001378 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001379}
1380
Vivien Didelotda9c3592016-02-12 12:09:40 -05001381static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1382 u16 vid_begin, u16 vid_end)
1383{
Vivien Didelot04bed142016-08-31 18:06:13 -04001384 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001385 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001386 int i, err;
1387
Andrew Lunndb06ae412017-09-25 23:32:20 +02001388 /* DSA and CPU ports have to be members of multiple vlans */
1389 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1390 return 0;
1391
Vivien Didelotda9c3592016-02-12 12:09:40 -05001392 if (!vid_begin)
1393 return -EOPNOTSUPP;
1394
Vivien Didelot425d2d32019-08-01 14:36:34 -04001395 vlan.vid = vid_begin - 1;
1396 vlan.valid = false;
1397
Vivien Didelotda9c3592016-02-12 12:09:40 -05001398 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001399 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001400 if (err)
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001401 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001402
1403 if (!vlan.valid)
1404 break;
1405
1406 if (vlan.vid > vid_end)
1407 break;
1408
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001409 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001410 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1411 continue;
1412
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001413 if (!dsa_to_port(ds, i)->slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001414 continue;
1415
Vivien Didelotbd00e052017-05-01 14:05:11 -04001416 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001417 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001418 continue;
1419
Vivien Didelotc8652c82017-10-16 11:12:19 -04001420 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001421 dsa_to_port(ds, port)->bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001422 break; /* same bridge, check next VLAN */
1423
Vivien Didelotc8652c82017-10-16 11:12:19 -04001424 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001425 continue;
1426
Andrew Lunn743fcc22017-11-09 22:29:54 +01001427 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1428 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001429 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001430 return -EOPNOTSUPP;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001431 }
1432 } while (vlan.vid < vid_end);
1433
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001434 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001435}
1436
Vivien Didelotf81ec902016-05-09 13:22:58 -04001437static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1438 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001439{
Vivien Didelot04bed142016-08-31 18:06:13 -04001440 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001441 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1442 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001443 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001444
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001445 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001446 return -EOPNOTSUPP;
1447
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001448 mv88e6xxx_reg_lock(chip);
Vivien Didelot385a0992016-11-04 03:23:31 +01001449 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001450 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001451
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001452 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001453}
1454
Vivien Didelot57d32312016-06-20 13:13:58 -04001455static int
1456mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001457 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001458{
Vivien Didelot04bed142016-08-31 18:06:13 -04001459 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001460 int err;
1461
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001462 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001463 return -EOPNOTSUPP;
1464
Vivien Didelotda9c3592016-02-12 12:09:40 -05001465 /* If the requested port doesn't belong to the same bridge as the VLAN
1466 * members, do not support it (yet) and fallback to software VLAN.
1467 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001468 mv88e6xxx_reg_lock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001469 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1470 vlan->vid_end);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001471 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001472
Vivien Didelot76e398a2015-11-01 12:33:55 -05001473 /* We don't need any dynamic resource from the kernel (yet),
1474 * so skip the prepare phase.
1475 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001476 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001477}
1478
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001479static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1480 const unsigned char *addr, u16 vid,
1481 u8 state)
1482{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001483 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001484 struct mv88e6xxx_vtu_entry vlan;
1485 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001486 int err;
1487
1488 /* Null VLAN ID corresponds to the port private database */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001489 if (vid == 0) {
1490 err = mv88e6xxx_port_get_fid(chip, port, &fid);
1491 if (err)
1492 return err;
1493 } else {
1494 vlan.vid = vid - 1;
1495 vlan.valid = false;
1496
1497 err = mv88e6xxx_vtu_getnext(chip, &vlan);
1498 if (err)
1499 return err;
1500
1501 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1502 if (vlan.vid != vid || !vlan.valid)
1503 return -EOPNOTSUPP;
1504
1505 fid = vlan.fid;
1506 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001507
Vivien Didelotd8291a92019-09-07 16:00:47 -04001508 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001509 ether_addr_copy(entry.mac, addr);
1510 eth_addr_dec(entry.mac);
1511
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001512 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001513 if (err)
1514 return err;
1515
1516 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001517 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001518 memset(&entry, 0, sizeof(entry));
1519 ether_addr_copy(entry.mac, addr);
1520 }
1521
1522 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001523 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001524 entry.portvec &= ~BIT(port);
1525 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001526 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001527 } else {
1528 entry.portvec |= BIT(port);
1529 entry.state = state;
1530 }
1531
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001532 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001533}
1534
Vivien Didelotda7dc872019-09-07 16:00:49 -04001535static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1536 const struct mv88e6xxx_policy *policy)
1537{
1538 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1539 enum mv88e6xxx_policy_action action = policy->action;
1540 const u8 *addr = policy->addr;
1541 u16 vid = policy->vid;
1542 u8 state;
1543 int err;
1544 int id;
1545
1546 if (!chip->info->ops->port_set_policy)
1547 return -EOPNOTSUPP;
1548
1549 switch (mapping) {
1550 case MV88E6XXX_POLICY_MAPPING_DA:
1551 case MV88E6XXX_POLICY_MAPPING_SA:
1552 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1553 state = 0; /* Dissociate the port and address */
1554 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1555 is_multicast_ether_addr(addr))
1556 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1557 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1558 is_unicast_ether_addr(addr))
1559 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1560 else
1561 return -EOPNOTSUPP;
1562
1563 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1564 state);
1565 if (err)
1566 return err;
1567 break;
1568 default:
1569 return -EOPNOTSUPP;
1570 }
1571
1572 /* Skip the port's policy clearing if the mapping is still in use */
1573 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1574 idr_for_each_entry(&chip->policies, policy, id)
1575 if (policy->port == port &&
1576 policy->mapping == mapping &&
1577 policy->action != action)
1578 return 0;
1579
1580 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1581}
1582
1583static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1584 struct ethtool_rx_flow_spec *fs)
1585{
1586 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1587 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1588 enum mv88e6xxx_policy_mapping mapping;
1589 enum mv88e6xxx_policy_action action;
1590 struct mv88e6xxx_policy *policy;
1591 u16 vid = 0;
1592 u8 *addr;
1593 int err;
1594 int id;
1595
1596 if (fs->location != RX_CLS_LOC_ANY)
1597 return -EINVAL;
1598
1599 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1600 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1601 else
1602 return -EOPNOTSUPP;
1603
1604 switch (fs->flow_type & ~FLOW_EXT) {
1605 case ETHER_FLOW:
1606 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1607 is_zero_ether_addr(mac_mask->h_source)) {
1608 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1609 addr = mac_entry->h_dest;
1610 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1611 !is_zero_ether_addr(mac_mask->h_source)) {
1612 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1613 addr = mac_entry->h_source;
1614 } else {
1615 /* Cannot support DA and SA mapping in the same rule */
1616 return -EOPNOTSUPP;
1617 }
1618 break;
1619 default:
1620 return -EOPNOTSUPP;
1621 }
1622
1623 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
1624 if (fs->m_ext.vlan_tci != 0xffff)
1625 return -EOPNOTSUPP;
1626 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1627 }
1628
1629 idr_for_each_entry(&chip->policies, policy, id) {
1630 if (policy->port == port && policy->mapping == mapping &&
1631 policy->action == action && policy->vid == vid &&
1632 ether_addr_equal(policy->addr, addr))
1633 return -EEXIST;
1634 }
1635
1636 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1637 if (!policy)
1638 return -ENOMEM;
1639
1640 fs->location = 0;
1641 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1642 GFP_KERNEL);
1643 if (err) {
1644 devm_kfree(chip->dev, policy);
1645 return err;
1646 }
1647
1648 memcpy(&policy->fs, fs, sizeof(*fs));
1649 ether_addr_copy(policy->addr, addr);
1650 policy->mapping = mapping;
1651 policy->action = action;
1652 policy->port = port;
1653 policy->vid = vid;
1654
1655 err = mv88e6xxx_policy_apply(chip, port, policy);
1656 if (err) {
1657 idr_remove(&chip->policies, fs->location);
1658 devm_kfree(chip->dev, policy);
1659 return err;
1660 }
1661
1662 return 0;
1663}
1664
1665static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1666 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1667{
1668 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1669 struct mv88e6xxx_chip *chip = ds->priv;
1670 struct mv88e6xxx_policy *policy;
1671 int err;
1672 int id;
1673
1674 mv88e6xxx_reg_lock(chip);
1675
1676 switch (rxnfc->cmd) {
1677 case ETHTOOL_GRXCLSRLCNT:
1678 rxnfc->data = 0;
1679 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1680 rxnfc->rule_cnt = 0;
1681 idr_for_each_entry(&chip->policies, policy, id)
1682 if (policy->port == port)
1683 rxnfc->rule_cnt++;
1684 err = 0;
1685 break;
1686 case ETHTOOL_GRXCLSRULE:
1687 err = -ENOENT;
1688 policy = idr_find(&chip->policies, fs->location);
1689 if (policy) {
1690 memcpy(fs, &policy->fs, sizeof(*fs));
1691 err = 0;
1692 }
1693 break;
1694 case ETHTOOL_GRXCLSRLALL:
1695 rxnfc->data = 0;
1696 rxnfc->rule_cnt = 0;
1697 idr_for_each_entry(&chip->policies, policy, id)
1698 if (policy->port == port)
1699 rule_locs[rxnfc->rule_cnt++] = id;
1700 err = 0;
1701 break;
1702 default:
1703 err = -EOPNOTSUPP;
1704 break;
1705 }
1706
1707 mv88e6xxx_reg_unlock(chip);
1708
1709 return err;
1710}
1711
1712static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1713 struct ethtool_rxnfc *rxnfc)
1714{
1715 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1716 struct mv88e6xxx_chip *chip = ds->priv;
1717 struct mv88e6xxx_policy *policy;
1718 int err;
1719
1720 mv88e6xxx_reg_lock(chip);
1721
1722 switch (rxnfc->cmd) {
1723 case ETHTOOL_SRXCLSRLINS:
1724 err = mv88e6xxx_policy_insert(chip, port, fs);
1725 break;
1726 case ETHTOOL_SRXCLSRLDEL:
1727 err = -ENOENT;
1728 policy = idr_remove(&chip->policies, fs->location);
1729 if (policy) {
1730 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
1731 err = mv88e6xxx_policy_apply(chip, port, policy);
1732 devm_kfree(chip->dev, policy);
1733 }
1734 break;
1735 default:
1736 err = -EOPNOTSUPP;
1737 break;
1738 }
1739
1740 mv88e6xxx_reg_unlock(chip);
1741
1742 return err;
1743}
1744
Andrew Lunn87fa8862017-11-09 22:29:56 +01001745static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1746 u16 vid)
1747{
1748 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1749 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1750
1751 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1752}
1753
1754static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1755{
1756 int port;
1757 int err;
1758
1759 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1760 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1761 if (err)
1762 return err;
1763 }
1764
1765 return 0;
1766}
1767
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001768static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Vivien Didelotc91498e2017-06-07 18:12:13 -04001769 u16 vid, u8 member)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001770{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001771 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001772 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001773 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001774
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001775 if (!vid)
1776 return -EOPNOTSUPP;
1777
1778 vlan.vid = vid - 1;
1779 vlan.valid = false;
1780
1781 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001782 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001783 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001784
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001785 if (vlan.vid != vid || !vlan.valid) {
1786 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001787
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001788 err = mv88e6xxx_atu_new(chip, &vlan.fid);
1789 if (err)
1790 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01001791
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001792 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1793 if (i == port)
1794 vlan.member[i] = member;
1795 else
1796 vlan.member[i] = non_member;
1797
1798 vlan.vid = vid;
1799 vlan.valid = true;
1800
1801 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1802 if (err)
1803 return err;
1804
1805 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
1806 if (err)
1807 return err;
1808 } else if (vlan.member[port] != member) {
1809 vlan.member[port] = member;
1810
1811 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1812 if (err)
1813 return err;
1814 } else {
1815 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
1816 port, vid);
1817 }
1818
1819 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001820}
1821
Vivien Didelotf81ec902016-05-09 13:22:58 -04001822static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001823 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001824{
Vivien Didelot04bed142016-08-31 18:06:13 -04001825 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001826 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1827 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001828 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001829 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001830
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001831 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001832 return;
1833
Vivien Didelotc91498e2017-06-07 18:12:13 -04001834 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001835 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001836 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001837 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001838 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001839 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001840
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001841 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001842
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001843 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001844 if (mv88e6xxx_port_vlan_join(chip, port, vid, member))
Vivien Didelot774439e52017-06-08 18:34:08 -04001845 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1846 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001847
Vivien Didelot77064f32016-11-04 03:23:30 +01001848 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001849 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1850 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001851
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001852 mv88e6xxx_reg_unlock(chip);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001853}
1854
Vivien Didelot521098922019-08-01 14:36:36 -04001855static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
1856 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001857{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001858 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001859 int i, err;
1860
Vivien Didelot521098922019-08-01 14:36:36 -04001861 if (!vid)
1862 return -EOPNOTSUPP;
1863
1864 vlan.vid = vid - 1;
1865 vlan.valid = false;
1866
1867 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001868 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001869 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001870
Vivien Didelot521098922019-08-01 14:36:36 -04001871 /* If the VLAN doesn't exist in hardware or the port isn't a member,
1872 * tell switchdev that this VLAN is likely handled in software.
1873 */
1874 if (vlan.vid != vid || !vlan.valid ||
1875 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001876 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001877
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001878 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001879
1880 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001881 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001882 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001883 if (vlan.member[i] !=
1884 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001885 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001886 break;
1887 }
1888 }
1889
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001890 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001891 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001892 return err;
1893
Vivien Didelote606ca32017-03-11 16:12:55 -05001894 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001895}
1896
Vivien Didelotf81ec902016-05-09 13:22:58 -04001897static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1898 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001899{
Vivien Didelot04bed142016-08-31 18:06:13 -04001900 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001901 u16 pvid, vid;
1902 int err = 0;
1903
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001904 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001905 return -EOPNOTSUPP;
1906
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001907 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001908
Vivien Didelot77064f32016-11-04 03:23:30 +01001909 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001910 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001911 goto unlock;
1912
Vivien Didelot76e398a2015-11-01 12:33:55 -05001913 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelot521098922019-08-01 14:36:36 -04001914 err = mv88e6xxx_port_vlan_leave(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001915 if (err)
1916 goto unlock;
1917
1918 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001919 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001920 if (err)
1921 goto unlock;
1922 }
1923 }
1924
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001925unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001926 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001927
1928 return err;
1929}
1930
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001931static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1932 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001933{
Vivien Didelot04bed142016-08-31 18:06:13 -04001934 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001935 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04001936
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001937 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001938 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1939 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001940 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03001941
1942 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001943}
1944
Vivien Didelotf81ec902016-05-09 13:22:58 -04001945static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03001946 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07001947{
Vivien Didelot04bed142016-08-31 18:06:13 -04001948 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001949 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001950
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001951 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04001952 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001953 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07001954
Vivien Didelot83dabd12016-08-31 11:50:04 -04001955 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001956}
1957
Vivien Didelot83dabd12016-08-31 11:50:04 -04001958static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1959 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001960 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001961{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001962 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001963 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001964 int err;
1965
Vivien Didelotd8291a92019-09-07 16:00:47 -04001966 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001967 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001968
1969 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001970 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001971 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001972 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001973
Vivien Didelotd8291a92019-09-07 16:00:47 -04001974 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001975 break;
1976
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001977 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001978 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001979
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001980 if (!is_unicast_ether_addr(addr.mac))
1981 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001982
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001983 is_static = (addr.state ==
1984 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
1985 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001986 if (err)
1987 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001988 } while (!is_broadcast_ether_addr(addr.mac));
1989
1990 return err;
1991}
1992
Vivien Didelot83dabd12016-08-31 11:50:04 -04001993static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03001994 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001995{
Vivien Didelot425d2d32019-08-01 14:36:34 -04001996 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001997 u16 fid;
1998 int err;
1999
2000 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002001 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002002 if (err)
2003 return err;
2004
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002005 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002006 if (err)
2007 return err;
2008
2009 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot425d2d32019-08-01 14:36:34 -04002010 vlan.vid = chip->info->max_vid;
2011 vlan.valid = false;
2012
Vivien Didelot83dabd12016-08-31 11:50:04 -04002013 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04002014 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002015 if (err)
2016 return err;
2017
2018 if (!vlan.valid)
2019 break;
2020
2021 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002022 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002023 if (err)
2024 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04002025 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002026
2027 return err;
2028}
2029
Vivien Didelotf81ec902016-05-09 13:22:58 -04002030static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002031 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002032{
Vivien Didelot04bed142016-08-31 18:06:13 -04002033 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002034 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002035
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002036 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002037 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002038 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002039
2040 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002041}
2042
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002043static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2044 struct net_device *br)
2045{
Vivien Didelote96a6e02017-03-30 17:37:13 -04002046 struct dsa_switch *ds;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002047 int port;
Vivien Didelote96a6e02017-03-30 17:37:13 -04002048 int dev;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002049 int err;
2050
2051 /* Remap the Port VLAN of each local bridge group member */
2052 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04002053 if (dsa_to_port(chip->ds, port)->bridge_dev == br) {
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002054 err = mv88e6xxx_port_vlan_map(chip, port);
2055 if (err)
2056 return err;
2057 }
2058 }
2059
Vivien Didelote96a6e02017-03-30 17:37:13 -04002060 /* Remap the Port VLAN of each cross-chip bridge group member */
2061 for (dev = 0; dev < DSA_MAX_SWITCHES; ++dev) {
2062 ds = chip->ds->dst->ds[dev];
2063 if (!ds)
2064 break;
2065
2066 for (port = 0; port < ds->num_ports; ++port) {
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04002067 if (dsa_to_port(ds, port)->bridge_dev == br) {
Vivien Didelote96a6e02017-03-30 17:37:13 -04002068 err = mv88e6xxx_pvt_map(chip, dev, port);
2069 if (err)
2070 return err;
2071 }
2072 }
2073 }
2074
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002075 return 0;
2076}
2077
Vivien Didelotf81ec902016-05-09 13:22:58 -04002078static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002079 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002080{
Vivien Didelot04bed142016-08-31 18:06:13 -04002081 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002082 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002083
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002084 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002085 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002086 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002087
Vivien Didelot466dfa02016-02-26 13:16:05 -05002088 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002089}
2090
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002091static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2092 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002093{
Vivien Didelot04bed142016-08-31 18:06:13 -04002094 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002095
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002096 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002097 if (mv88e6xxx_bridge_map(chip, br) ||
2098 mv88e6xxx_port_vlan_map(chip, port))
2099 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002100 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002101}
2102
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002103static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
2104 int port, struct net_device *br)
2105{
2106 struct mv88e6xxx_chip *chip = ds->priv;
2107 int err;
2108
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002109 mv88e6xxx_reg_lock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002110 err = mv88e6xxx_pvt_map(chip, dev, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002111 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002112
2113 return err;
2114}
2115
2116static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
2117 int port, struct net_device *br)
2118{
2119 struct mv88e6xxx_chip *chip = ds->priv;
2120
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002121 mv88e6xxx_reg_lock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002122 if (mv88e6xxx_pvt_map(chip, dev, port))
2123 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002124 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002125}
2126
Vivien Didelot17e708b2016-12-05 17:30:27 -05002127static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2128{
2129 if (chip->info->ops->reset)
2130 return chip->info->ops->reset(chip);
2131
2132 return 0;
2133}
2134
Vivien Didelot309eca62016-12-05 17:30:26 -05002135static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2136{
2137 struct gpio_desc *gpiod = chip->reset;
2138
2139 /* If there is a GPIO connected to the reset pin, toggle it */
2140 if (gpiod) {
2141 gpiod_set_value_cansleep(gpiod, 1);
2142 usleep_range(10000, 20000);
2143 gpiod_set_value_cansleep(gpiod, 0);
2144 usleep_range(10000, 20000);
2145 }
2146}
2147
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002148static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2149{
2150 int i, err;
2151
2152 /* Set all ports to the Disabled state */
2153 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002154 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002155 if (err)
2156 return err;
2157 }
2158
2159 /* Wait for transmit queues to drain,
2160 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2161 */
2162 usleep_range(2000, 4000);
2163
2164 return 0;
2165}
2166
Vivien Didelotfad09c72016-06-21 12:28:20 -04002167static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002168{
Vivien Didelota935c052016-09-29 12:21:53 -04002169 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002170
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002171 err = mv88e6xxx_disable_ports(chip);
2172 if (err)
2173 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002174
Vivien Didelot309eca62016-12-05 17:30:26 -05002175 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002176
Vivien Didelot17e708b2016-12-05 17:30:27 -05002177 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002178}
2179
Vivien Didelot43145572017-03-11 16:12:59 -05002180static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002181 enum mv88e6xxx_frame_mode frame,
2182 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002183{
2184 int err;
2185
Vivien Didelot43145572017-03-11 16:12:59 -05002186 if (!chip->info->ops->port_set_frame_mode)
2187 return -EOPNOTSUPP;
2188
2189 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002190 if (err)
2191 return err;
2192
Vivien Didelot43145572017-03-11 16:12:59 -05002193 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2194 if (err)
2195 return err;
2196
2197 if (chip->info->ops->port_set_ether_type)
2198 return chip->info->ops->port_set_ether_type(chip, port, etype);
2199
2200 return 0;
2201}
2202
2203static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2204{
2205 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002206 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002207 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002208}
2209
2210static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2211{
2212 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002213 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002214 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002215}
2216
2217static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2218{
2219 return mv88e6xxx_set_port_mode(chip, port,
2220 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002221 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2222 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002223}
2224
2225static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2226{
2227 if (dsa_is_dsa_port(chip->ds, port))
2228 return mv88e6xxx_set_port_mode_dsa(chip, port);
2229
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002230 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002231 return mv88e6xxx_set_port_mode_normal(chip, port);
2232
2233 /* Setup CPU port mode depending on its supported tag format */
2234 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2235 return mv88e6xxx_set_port_mode_dsa(chip, port);
2236
2237 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2238 return mv88e6xxx_set_port_mode_edsa(chip, port);
2239
2240 return -EINVAL;
2241}
2242
Vivien Didelotea698f42017-03-11 16:12:50 -05002243static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2244{
2245 bool message = dsa_is_dsa_port(chip->ds, port);
2246
2247 return mv88e6xxx_port_set_message_port(chip, port, message);
2248}
2249
Vivien Didelot601aeed2017-03-11 16:13:00 -05002250static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2251{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002252 struct dsa_switch *ds = chip->ds;
David S. Miller407308f2019-06-15 13:35:29 -07002253 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002254
David S. Miller407308f2019-06-15 13:35:29 -07002255 /* Upstream ports flood frames with unknown unicast or multicast DA */
2256 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2257 if (chip->info->ops->port_set_egress_floods)
2258 return chip->info->ops->port_set_egress_floods(chip, port,
2259 flood, flood);
Vivien Didelot601aeed2017-03-11 16:13:00 -05002260
David S. Miller407308f2019-06-15 13:35:29 -07002261 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002262}
2263
Vivien Didelot45de77f2019-08-31 16:18:36 -04002264static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2265{
2266 struct mv88e6xxx_port *mvp = dev_id;
2267 struct mv88e6xxx_chip *chip = mvp->chip;
2268 irqreturn_t ret = IRQ_NONE;
2269 int port = mvp->port;
2270 u8 lane;
2271
2272 mv88e6xxx_reg_lock(chip);
2273 lane = mv88e6xxx_serdes_get_lane(chip, port);
2274 if (lane)
2275 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2276 mv88e6xxx_reg_unlock(chip);
2277
2278 return ret;
2279}
2280
2281static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
2282 u8 lane)
2283{
2284 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2285 unsigned int irq;
2286 int err;
2287
2288 /* Nothing to request if this SERDES port has no IRQ */
2289 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2290 if (!irq)
2291 return 0;
2292
2293 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2294 mv88e6xxx_reg_unlock(chip);
2295 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
2296 IRQF_ONESHOT, "mv88e6xxx-serdes", dev_id);
2297 mv88e6xxx_reg_lock(chip);
2298 if (err)
2299 return err;
2300
2301 dev_id->serdes_irq = irq;
2302
2303 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2304}
2305
2306static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
2307 u8 lane)
2308{
2309 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2310 unsigned int irq = dev_id->serdes_irq;
2311 int err;
2312
2313 /* Nothing to free if no IRQ has been requested */
2314 if (!irq)
2315 return 0;
2316
2317 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2318
2319 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2320 mv88e6xxx_reg_unlock(chip);
2321 free_irq(irq, dev_id);
2322 mv88e6xxx_reg_lock(chip);
2323
2324 dev_id->serdes_irq = 0;
2325
2326 return err;
2327}
2328
Andrew Lunn6d917822017-05-26 01:03:21 +02002329static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2330 bool on)
2331{
Vivien Didelotdc272f62019-08-31 16:18:33 -04002332 u8 lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002333 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002334
Vivien Didelotdc272f62019-08-31 16:18:33 -04002335 lane = mv88e6xxx_serdes_get_lane(chip, port);
2336 if (!lane)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002337 return 0;
2338
2339 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002340 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002341 if (err)
2342 return err;
2343
Vivien Didelot45de77f2019-08-31 16:18:36 -04002344 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002345 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002346 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2347 if (err)
2348 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002349
Vivien Didelotdc272f62019-08-31 16:18:33 -04002350 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002351 }
2352
2353 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002354}
2355
Vivien Didelotfa371c82017-12-05 15:34:10 -05002356static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2357{
2358 struct dsa_switch *ds = chip->ds;
2359 int upstream_port;
2360 int err;
2361
Vivien Didelot07073c72017-12-05 15:34:13 -05002362 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002363 if (chip->info->ops->port_set_upstream_port) {
2364 err = chip->info->ops->port_set_upstream_port(chip, port,
2365 upstream_port);
2366 if (err)
2367 return err;
2368 }
2369
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002370 if (port == upstream_port) {
2371 if (chip->info->ops->set_cpu_port) {
2372 err = chip->info->ops->set_cpu_port(chip,
2373 upstream_port);
2374 if (err)
2375 return err;
2376 }
2377
2378 if (chip->info->ops->set_egress_port) {
2379 err = chip->info->ops->set_egress_port(chip,
2380 upstream_port);
2381 if (err)
2382 return err;
2383 }
2384 }
2385
Vivien Didelotfa371c82017-12-05 15:34:10 -05002386 return 0;
2387}
2388
Vivien Didelotfad09c72016-06-21 12:28:20 -04002389static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002390{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002391 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002392 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002393 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002394
Andrew Lunn7b898462018-08-09 15:38:47 +02002395 chip->ports[port].chip = chip;
2396 chip->ports[port].port = port;
2397
Vivien Didelotd78343d2016-11-04 03:23:36 +01002398 /* MAC Forcing register: don't force link, speed, duplex or flow control
2399 * state to any particular values on physical ports, but force the CPU
2400 * port and all DSA ports to their maximum bandwidth and full duplex.
2401 */
2402 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2403 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2404 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002405 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002406 PHY_INTERFACE_MODE_NA);
2407 else
2408 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2409 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002410 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002411 PHY_INTERFACE_MODE_NA);
2412 if (err)
2413 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002414
2415 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2416 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2417 * tunneling, determine priority by looking at 802.1p and IP
2418 * priority fields (IP prio has precedence), and set STP state
2419 * to Forwarding.
2420 *
2421 * If this is the CPU link, use DSA or EDSA tagging depending
2422 * on which tagging mode was configured.
2423 *
2424 * If this is a link to another switch, use DSA tagging mode.
2425 *
2426 * If this is the upstream port for this switch, enable
2427 * forwarding of unknown unicasts and multicasts.
2428 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002429 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2430 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2431 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2432 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002433 if (err)
2434 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002435
Vivien Didelot601aeed2017-03-11 16:13:00 -05002436 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002437 if (err)
2438 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002439
Vivien Didelot601aeed2017-03-11 16:13:00 -05002440 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002441 if (err)
2442 return err;
2443
Vivien Didelot8efdda42015-08-13 12:52:23 -04002444 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002445 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002446 * untagged frames on this port, do a destination address lookup on all
2447 * received packets as usual, disable ARP mirroring and don't send a
2448 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002449 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002450 err = mv88e6xxx_port_set_map_da(chip, port);
2451 if (err)
2452 return err;
2453
Vivien Didelotfa371c82017-12-05 15:34:10 -05002454 err = mv88e6xxx_setup_upstream_port(chip, port);
2455 if (err)
2456 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002457
Andrew Lunna23b2962017-02-04 20:15:28 +01002458 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002459 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002460 if (err)
2461 return err;
2462
Vivien Didelotcd782652017-06-08 18:34:13 -04002463 if (chip->info->ops->port_set_jumbo_size) {
2464 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002465 if (err)
2466 return err;
2467 }
2468
Andrew Lunn54d792f2015-05-06 01:09:47 +02002469 /* Port Association Vector: when learning source addresses
2470 * of packets, add the address to the address database using
2471 * a port bitmap that has only the bit for this port set and
2472 * the other bits clear.
2473 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002474 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002475 /* Disable learning for CPU port */
2476 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002477 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002478
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002479 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2480 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002481 if (err)
2482 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002483
2484 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002485 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2486 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002487 if (err)
2488 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002489
Vivien Didelot08984322017-06-08 18:34:12 -04002490 if (chip->info->ops->port_pause_limit) {
2491 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002492 if (err)
2493 return err;
2494 }
2495
Vivien Didelotc8c94892017-03-11 16:13:01 -05002496 if (chip->info->ops->port_disable_learn_limit) {
2497 err = chip->info->ops->port_disable_learn_limit(chip, port);
2498 if (err)
2499 return err;
2500 }
2501
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002502 if (chip->info->ops->port_disable_pri_override) {
2503 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002504 if (err)
2505 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002506 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002507
Andrew Lunnef0a7312016-12-03 04:35:16 +01002508 if (chip->info->ops->port_tag_remap) {
2509 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002510 if (err)
2511 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002512 }
2513
Andrew Lunnef70b112016-12-03 04:45:18 +01002514 if (chip->info->ops->port_egress_rate_limiting) {
2515 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002516 if (err)
2517 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002518 }
2519
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002520 if (chip->info->ops->port_setup_message_port) {
2521 err = chip->info->ops->port_setup_message_port(chip, port);
2522 if (err)
2523 return err;
2524 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002525
Vivien Didelot207afda2016-04-14 14:42:09 -04002526 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002527 * database, and allow bidirectional communication between the
2528 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002529 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002530 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002531 if (err)
2532 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002533
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002534 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002535 if (err)
2536 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002537
2538 /* Default VLAN ID and priority: don't set a default VLAN
2539 * ID, and set the default packet priority to zero.
2540 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002541 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002542}
2543
Andrew Lunn04aca992017-05-26 01:03:24 +02002544static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2545 struct phy_device *phydev)
2546{
2547 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002548 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002549
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002550 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002551 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002552 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002553
2554 return err;
2555}
2556
Andrew Lunn75104db2019-02-24 20:44:43 +01002557static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02002558{
2559 struct mv88e6xxx_chip *chip = ds->priv;
2560
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002561 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002562 if (mv88e6xxx_serdes_power(chip, port, false))
2563 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002564 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002565}
2566
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002567static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2568 unsigned int ageing_time)
2569{
Vivien Didelot04bed142016-08-31 18:06:13 -04002570 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002571 int err;
2572
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002573 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05002574 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002575 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002576
2577 return err;
2578}
2579
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002580static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002581{
2582 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002583
Andrew Lunnde2273872016-11-21 23:27:01 +01002584 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002585 if (chip->info->ops->stats_set_histogram) {
2586 err = chip->info->ops->stats_set_histogram(chip);
2587 if (err)
2588 return err;
2589 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002590
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002591 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002592}
2593
Andrew Lunnea890982019-01-09 00:24:03 +01002594/* Check if the errata has already been applied. */
2595static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
2596{
2597 int port;
2598 int err;
2599 u16 val;
2600
2601 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002602 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01002603 if (err) {
2604 dev_err(chip->dev,
2605 "Error reading hidden register: %d\n", err);
2606 return false;
2607 }
2608 if (val != 0x01c0)
2609 return false;
2610 }
2611
2612 return true;
2613}
2614
2615/* The 6390 copper ports have an errata which require poking magic
2616 * values into undocumented hidden registers and then performing a
2617 * software reset.
2618 */
2619static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
2620{
2621 int port;
2622 int err;
2623
2624 if (mv88e6390_setup_errata_applied(chip))
2625 return 0;
2626
2627 /* Set the ports into blocking mode */
2628 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2629 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
2630 if (err)
2631 return err;
2632 }
2633
2634 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002635 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01002636 if (err)
2637 return err;
2638 }
2639
2640 return mv88e6xxx_software_reset(chip);
2641}
2642
Vivien Didelotf81ec902016-05-09 13:22:58 -04002643static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002644{
Vivien Didelot04bed142016-08-31 18:06:13 -04002645 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002646 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04002647 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002648 int i;
2649
Vivien Didelotfad09c72016-06-21 12:28:20 -04002650 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002651 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002652
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002653 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002654
Andrew Lunnea890982019-01-09 00:24:03 +01002655 if (chip->info->ops->setup_errata) {
2656 err = chip->info->ops->setup_errata(chip);
2657 if (err)
2658 goto unlock;
2659 }
2660
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002661 /* Cache the cmode of each port. */
2662 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2663 if (chip->info->ops->port_get_cmode) {
2664 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
2665 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03002666 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002667
2668 chip->ports[i].cmode = cmode;
2669 }
2670 }
2671
Vivien Didelot97299342016-07-18 20:45:30 -04002672 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002673 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04002674 if (dsa_is_unused_port(ds, i))
2675 continue;
2676
Hubert Feursteinc8574862019-07-31 10:23:48 +02002677 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04002678 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02002679 dev_err(chip->dev, "port %d is invalid\n", i);
2680 err = -EINVAL;
2681 goto unlock;
2682 }
2683
Vivien Didelot97299342016-07-18 20:45:30 -04002684 err = mv88e6xxx_setup_port(chip, i);
2685 if (err)
2686 goto unlock;
2687 }
2688
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002689 err = mv88e6xxx_irl_setup(chip);
2690 if (err)
2691 goto unlock;
2692
Vivien Didelot04a69a12017-10-13 14:18:05 -04002693 err = mv88e6xxx_mac_setup(chip);
2694 if (err)
2695 goto unlock;
2696
Vivien Didelot1b17aed2017-05-26 18:03:05 -04002697 err = mv88e6xxx_phy_setup(chip);
2698 if (err)
2699 goto unlock;
2700
Vivien Didelotb486d7c2017-05-01 14:05:13 -04002701 err = mv88e6xxx_vtu_setup(chip);
2702 if (err)
2703 goto unlock;
2704
Vivien Didelot81228992017-03-30 17:37:08 -04002705 err = mv88e6xxx_pvt_setup(chip);
2706 if (err)
2707 goto unlock;
2708
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002709 err = mv88e6xxx_atu_setup(chip);
2710 if (err)
2711 goto unlock;
2712
Andrew Lunn87fa8862017-11-09 22:29:56 +01002713 err = mv88e6xxx_broadcast_setup(chip, 0);
2714 if (err)
2715 goto unlock;
2716
Vivien Didelot9e907d72017-07-17 13:03:43 -04002717 err = mv88e6xxx_pot_setup(chip);
2718 if (err)
2719 goto unlock;
2720
Vivien Didelot9e5baf92018-05-09 11:38:51 -04002721 err = mv88e6xxx_rmu_setup(chip);
2722 if (err)
2723 goto unlock;
2724
Vivien Didelot51c901a2017-07-17 13:03:41 -04002725 err = mv88e6xxx_rsvd2cpu_setup(chip);
2726 if (err)
2727 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01002728
Vivien Didelotb28f8722018-04-26 21:56:44 -04002729 err = mv88e6xxx_trunk_setup(chip);
2730 if (err)
2731 goto unlock;
2732
Vivien Didelotc7f047b2018-04-26 21:56:45 -04002733 err = mv88e6xxx_devmap_setup(chip);
2734 if (err)
2735 goto unlock;
2736
Vivien Didelot93e18d62018-05-11 17:16:35 -04002737 err = mv88e6xxx_pri_setup(chip);
2738 if (err)
2739 goto unlock;
2740
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002741 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002742 if (chip->info->ptp_support) {
2743 err = mv88e6xxx_ptp_setup(chip);
2744 if (err)
2745 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01002746
2747 err = mv88e6xxx_hwtstamp_setup(chip);
2748 if (err)
2749 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01002750 }
2751
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002752 err = mv88e6xxx_stats_setup(chip);
2753 if (err)
2754 goto unlock;
2755
Vivien Didelot6b17e862015-08-13 12:52:18 -04002756unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002757 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02002758
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002759 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002760}
2761
Vivien Didelote57e5e72016-08-15 17:19:00 -04002762static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002763{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002764 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2765 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002766 u16 val;
2767 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002768
Andrew Lunnee26a222017-01-24 14:53:48 +01002769 if (!chip->info->ops->phy_read)
2770 return -EOPNOTSUPP;
2771
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002772 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01002773 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002774 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002775
Andrew Lunnda9f3302017-02-01 03:40:05 +01002776 if (reg == MII_PHYSID2) {
Andrew Lunnddc49ac2018-11-12 18:51:01 +01002777 /* Some internal PHYs don't have a model number. */
2778 if (chip->info->family != MV88E6XXX_FAMILY_6165)
2779 /* Then there is the 6165 family. It gets is
2780 * PHYs correct. But it can also have two
2781 * SERDES interfaces in the PHY address
2782 * space. And these don't have a model
2783 * number. But they are not PHYs, so we don't
2784 * want to give them something a PHY driver
2785 * will recognise.
2786 *
2787 * Use the mv88e6390 family model number
2788 * instead, for anything which really could be
2789 * a PHY,
2790 */
2791 if (!(val & 0x3f0))
2792 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01002793 }
2794
Vivien Didelote57e5e72016-08-15 17:19:00 -04002795 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002796}
2797
Vivien Didelote57e5e72016-08-15 17:19:00 -04002798static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002799{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002800 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2801 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002802 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002803
Andrew Lunnee26a222017-01-24 14:53:48 +01002804 if (!chip->info->ops->phy_write)
2805 return -EOPNOTSUPP;
2806
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002807 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01002808 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002809 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002810
2811 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002812}
2813
Vivien Didelotfad09c72016-06-21 12:28:20 -04002814static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002815 struct device_node *np,
2816 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002817{
2818 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002819 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002820 struct mii_bus *bus;
2821 int err;
2822
Andrew Lunn2510bab2018-02-22 01:51:49 +01002823 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002824 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01002825 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002826 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01002827
2828 if (err)
2829 return err;
2830 }
2831
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002832 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002833 if (!bus)
2834 return -ENOMEM;
2835
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002836 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002837 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002838 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002839 INIT_LIST_HEAD(&mdio_bus->list);
2840 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002841
Andrew Lunnb516d452016-06-04 21:17:06 +02002842 if (np) {
2843 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05002844 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002845 } else {
2846 bus->name = "mv88e6xxx SMI";
2847 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2848 }
2849
2850 bus->read = mv88e6xxx_mdio_read;
2851 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002852 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002853
Andrew Lunn6f882842018-03-17 20:32:05 +01002854 if (!external) {
2855 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
2856 if (err)
2857 return err;
2858 }
2859
Florian Fainelli00e798c2018-05-15 16:56:19 -07002860 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002861 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002862 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01002863 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002864 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002865 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002866
2867 if (external)
2868 list_add_tail(&mdio_bus->list, &chip->mdios);
2869 else
2870 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002871
2872 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002873}
2874
Andrew Lunna3c53be52017-01-24 14:53:50 +01002875static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2876 { .compatible = "marvell,mv88e6xxx-mdio-external",
2877 .data = (void *)true },
2878 { },
2879};
2880
Andrew Lunn3126aee2017-12-07 01:05:57 +01002881static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
2882
2883{
2884 struct mv88e6xxx_mdio_bus *mdio_bus;
2885 struct mii_bus *bus;
2886
2887 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2888 bus = mdio_bus->bus;
2889
Andrew Lunn6f882842018-03-17 20:32:05 +01002890 if (!mdio_bus->external)
2891 mv88e6xxx_g2_irq_mdio_free(chip, bus);
2892
Andrew Lunn3126aee2017-12-07 01:05:57 +01002893 mdiobus_unregister(bus);
2894 }
2895}
2896
Andrew Lunna3c53be52017-01-24 14:53:50 +01002897static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2898 struct device_node *np)
2899{
2900 const struct of_device_id *match;
2901 struct device_node *child;
2902 int err;
2903
2904 /* Always register one mdio bus for the internal/default mdio
2905 * bus. This maybe represented in the device tree, but is
2906 * optional.
2907 */
2908 child = of_get_child_by_name(np, "mdio");
2909 err = mv88e6xxx_mdio_register(chip, child, false);
2910 if (err)
2911 return err;
2912
2913 /* Walk the device tree, and see if there are any other nodes
2914 * which say they are compatible with the external mdio
2915 * bus.
2916 */
2917 for_each_available_child_of_node(np, child) {
2918 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2919 if (match) {
2920 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01002921 if (err) {
2922 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05302923 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002924 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01002925 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002926 }
2927 }
2928
2929 return 0;
2930}
2931
Vivien Didelot855b1932016-07-20 18:18:35 -04002932static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2933{
Vivien Didelot04bed142016-08-31 18:06:13 -04002934 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002935
2936 return chip->eeprom_len;
2937}
2938
Vivien Didelot855b1932016-07-20 18:18:35 -04002939static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2940 struct ethtool_eeprom *eeprom, u8 *data)
2941{
Vivien Didelot04bed142016-08-31 18:06:13 -04002942 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002943 int err;
2944
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002945 if (!chip->info->ops->get_eeprom)
2946 return -EOPNOTSUPP;
2947
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002948 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002949 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002950 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04002951
2952 if (err)
2953 return err;
2954
2955 eeprom->magic = 0xc3ec4951;
2956
2957 return 0;
2958}
2959
Vivien Didelot855b1932016-07-20 18:18:35 -04002960static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2961 struct ethtool_eeprom *eeprom, u8 *data)
2962{
Vivien Didelot04bed142016-08-31 18:06:13 -04002963 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002964 int err;
2965
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002966 if (!chip->info->ops->set_eeprom)
2967 return -EOPNOTSUPP;
2968
Vivien Didelot855b1932016-07-20 18:18:35 -04002969 if (eeprom->magic != 0xc3ec4951)
2970 return -EINVAL;
2971
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002972 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002973 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002974 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04002975
2976 return err;
2977}
2978
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002979static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002980 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04002981 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
2982 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04002983 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002984 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04002985 .phy_read = mv88e6185_phy_ppu_read,
2986 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002987 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002988 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002989 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002990 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002991 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002992 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002993 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002994 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04002995 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002996 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002997 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02002998 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02002999 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003000 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003001 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003002 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003003 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3004 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003005 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003006 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3007 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003008 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003009 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003010 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003011 .ppu_enable = mv88e6185_g1_ppu_enable,
3012 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003013 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003014 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003015 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003016 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003017 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003018};
3019
3020static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003021 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003022 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3023 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003024 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003025 .phy_read = mv88e6185_phy_ppu_read,
3026 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003027 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003028 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003029 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003030 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003031 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01003032 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Russell King6c422e32018-08-09 15:38:39 +02003033 .port_link_state = mv88e6185_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003034 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003035 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003036 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003037 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003038 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3039 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003040 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003041 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003042 .ppu_enable = mv88e6185_g1_ppu_enable,
3043 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003044 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003045 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003046 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003047 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003048};
3049
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003050static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003051 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003052 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3053 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003054 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003055 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3056 .phy_read = mv88e6xxx_g2_smi_phy_read,
3057 .phy_write = mv88e6xxx_g2_smi_phy_write,
3058 .port_set_link = mv88e6xxx_port_set_link,
3059 .port_set_duplex = mv88e6xxx_port_set_duplex,
3060 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003061 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003062 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003063 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003064 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003065 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003066 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003067 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003068 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003069 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003070 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003071 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003072 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003073 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003074 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003075 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3076 .stats_get_strings = mv88e6095_stats_get_strings,
3077 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003078 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3079 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003080 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003081 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003082 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003083 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003084 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003085 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003086 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003087 .phylink_validate = mv88e6185_phylink_validate,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003088};
3089
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003090static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003091 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003092 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3093 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003094 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003095 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003096 .phy_read = mv88e6xxx_g2_smi_phy_read,
3097 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003098 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003099 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003100 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003101 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003102 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003103 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003104 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003105 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003106 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003107 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003108 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003109 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003110 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3111 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003112 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003113 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3114 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003115 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003116 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003117 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003118 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003119 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003120 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003121 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003122};
3123
3124static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003125 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003126 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3127 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003128 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003129 .phy_read = mv88e6185_phy_ppu_read,
3130 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003131 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003132 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003133 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003134 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003135 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003136 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003137 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003138 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003139 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003140 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003141 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003142 .port_set_pause = mv88e6185_port_set_pause,
Russell King6c422e32018-08-09 15:38:39 +02003143 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003144 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003145 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003146 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003147 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003148 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3149 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003150 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003151 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3152 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003153 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003154 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003155 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003156 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003157 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003158 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003159 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003160 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003161 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003162};
3163
Vivien Didelot990e27b2017-03-28 13:50:32 -04003164static const struct mv88e6xxx_ops mv88e6141_ops = {
3165 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003166 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3167 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003168 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003169 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3170 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3171 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3172 .phy_read = mv88e6xxx_g2_smi_phy_read,
3173 .phy_write = mv88e6xxx_g2_smi_phy_write,
3174 .port_set_link = mv88e6xxx_port_set_link,
3175 .port_set_duplex = mv88e6xxx_port_set_duplex,
3176 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Marek Behún26422342018-10-13 14:40:31 +02003177 .port_set_speed = mv88e6341_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003178 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003179 .port_tag_remap = mv88e6095_port_tag_remap,
3180 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3181 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3182 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003183 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003184 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003185 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003186 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3187 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003188 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003189 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003190 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003191 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003192 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003193 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003194 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3195 .stats_get_strings = mv88e6320_stats_get_strings,
3196 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003197 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3198 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003199 .watchdog_ops = &mv88e6390_watchdog_ops,
3200 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003201 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003202 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003203 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003204 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003205 .serdes_power = mv88e6390_serdes_power,
3206 .serdes_get_lane = mv88e6341_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003207 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003208 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003209 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003210 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003211 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003212};
3213
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003214static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003215 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003216 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3217 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003218 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003219 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003220 .phy_read = mv88e6xxx_g2_smi_phy_read,
3221 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003222 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003223 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003224 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003225 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003226 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003227 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003228 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003229 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003230 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003231 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003232 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003233 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003234 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003235 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003236 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003237 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003238 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003239 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3240 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003241 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003242 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3243 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003244 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003245 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003246 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003247 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003248 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003249 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003250 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003251 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003252 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003253};
3254
3255static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003256 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003257 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3258 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003259 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003260 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003261 .phy_read = mv88e6165_phy_read,
3262 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003263 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003264 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003265 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003266 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003267 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003268 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003269 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003270 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003271 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003272 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003273 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3274 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003275 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003276 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3277 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003278 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003279 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003280 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003281 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003282 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003283 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003284 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003285 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003286 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003287};
3288
3289static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003290 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003291 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3292 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003293 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003294 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003295 .phy_read = mv88e6xxx_g2_smi_phy_read,
3296 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003297 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003298 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003299 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003300 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003301 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003302 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003303 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003304 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003305 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003306 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003307 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003308 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003309 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003310 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003311 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003312 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003313 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003314 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003315 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3316 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003317 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003318 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3319 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003320 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003321 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003322 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003323 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003324 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003325 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003326 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003327};
3328
3329static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003330 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003331 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3332 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003333 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003334 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3335 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003336 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003337 .phy_read = mv88e6xxx_g2_smi_phy_read,
3338 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003339 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003340 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003341 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003342 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003343 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003344 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003345 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003346 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003347 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003348 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003349 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003350 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003351 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003352 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003353 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003354 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003355 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003356 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003357 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003358 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3359 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003360 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003361 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3362 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003363 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003364 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003365 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003366 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003367 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003368 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003369 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003370 .serdes_get_lane = mv88e6352_serdes_get_lane,
Andrew Lunn6d917822017-05-26 01:03:21 +02003371 .serdes_power = mv88e6352_serdes_power,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003372 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003373 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003374};
3375
3376static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003377 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003378 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3379 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003380 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003381 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003382 .phy_read = mv88e6xxx_g2_smi_phy_read,
3383 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003384 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003385 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003386 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003387 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003388 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003389 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003390 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003391 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003392 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003393 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003394 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003395 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003396 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003397 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003398 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003399 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003400 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003401 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003402 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3403 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003404 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003405 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3406 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003407 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003408 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003409 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003410 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003411 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003412 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003413 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003414};
3415
3416static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003417 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003418 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3419 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003420 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003421 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3422 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003423 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003424 .phy_read = mv88e6xxx_g2_smi_phy_read,
3425 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003426 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003427 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003428 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003429 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003430 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003431 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003432 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003433 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003434 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003435 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003436 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003437 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003438 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003439 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003440 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003441 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003442 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003443 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003444 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003445 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3446 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003447 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003448 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3449 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003450 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003451 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003452 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003453 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003454 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003455 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003456 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003457 .serdes_get_lane = mv88e6352_serdes_get_lane,
Andrew Lunn6d917822017-05-26 01:03:21 +02003458 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003459 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003460 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003461 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003462 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003463 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003464};
3465
3466static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003467 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003468 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3469 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003470 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003471 .phy_read = mv88e6185_phy_ppu_read,
3472 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003473 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003474 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003475 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003476 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003477 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003478 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003479 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02003480 .port_set_pause = mv88e6185_port_set_pause,
Russell King6c422e32018-08-09 15:38:39 +02003481 .port_link_state = mv88e6185_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003482 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003483 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003484 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003485 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003486 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3487 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003488 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003489 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3490 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003491 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003492 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelot02317e62018-05-09 11:38:49 -04003493 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003494 .ppu_enable = mv88e6185_g1_ppu_enable,
3495 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003496 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003497 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003498 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003499 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003500};
3501
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003502static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003503 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003504 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003505 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003506 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3507 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003508 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3509 .phy_read = mv88e6xxx_g2_smi_phy_read,
3510 .phy_write = mv88e6xxx_g2_smi_phy_write,
3511 .port_set_link = mv88e6xxx_port_set_link,
3512 .port_set_duplex = mv88e6xxx_port_set_duplex,
3513 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3514 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003515 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003516 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003517 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003518 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003519 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003520 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003521 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003522 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003523 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003524 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003525 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003526 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003527 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003528 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003529 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003530 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3531 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003532 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003533 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3534 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003535 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003536 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003537 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003538 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003539 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003540 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3541 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003542 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003543 .serdes_get_lane = mv88e6390_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003544 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003545 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003546 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003547 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003548 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003549};
3550
3551static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003552 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003553 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003554 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003555 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3556 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003557 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3558 .phy_read = mv88e6xxx_g2_smi_phy_read,
3559 .phy_write = mv88e6xxx_g2_smi_phy_write,
3560 .port_set_link = mv88e6xxx_port_set_link,
3561 .port_set_duplex = mv88e6xxx_port_set_duplex,
3562 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3563 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003564 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003565 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003566 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003567 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003568 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003569 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003570 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003571 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003572 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003573 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003574 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003575 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003576 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003577 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003578 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003579 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3580 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003581 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003582 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3583 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003584 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003585 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003586 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003587 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003588 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003589 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3590 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003591 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003592 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003593 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003594 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003595 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003596 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003597 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003598};
3599
3600static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003601 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003602 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003603 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003604 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3605 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003606 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3607 .phy_read = mv88e6xxx_g2_smi_phy_read,
3608 .phy_write = mv88e6xxx_g2_smi_phy_write,
3609 .port_set_link = mv88e6xxx_port_set_link,
3610 .port_set_duplex = mv88e6xxx_port_set_duplex,
3611 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3612 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003613 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003614 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003615 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003616 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003617 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003618 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003619 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003620 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003621 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003622 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003623 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003624 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003625 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003626 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003627 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3628 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003629 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003630 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3631 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003632 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003633 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003634 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003635 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003636 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003637 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3638 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003639 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003640 .serdes_get_lane = mv88e6390_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003641 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003642 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003643 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003644 .avb_ops = &mv88e6390_avb_ops,
3645 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003646 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003647};
3648
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003649static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003650 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003651 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3652 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003653 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003654 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3655 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003656 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003657 .phy_read = mv88e6xxx_g2_smi_phy_read,
3658 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003659 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003660 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003661 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003662 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003663 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003664 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003665 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003666 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003667 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003668 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003669 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003670 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003671 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003672 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003673 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003674 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003675 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003676 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003677 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003678 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3679 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003680 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003681 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3682 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003683 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003684 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003685 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003686 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003687 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003688 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003689 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003690 .serdes_get_lane = mv88e6352_serdes_get_lane,
Andrew Lunn6d917822017-05-26 01:03:21 +02003691 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003692 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003693 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003694 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003695 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003696 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003697 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003698 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003699};
3700
Rasmus Villemoes1f718362019-06-04 07:34:32 +00003701static const struct mv88e6xxx_ops mv88e6250_ops = {
3702 /* MV88E6XXX_FAMILY_6250 */
3703 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
3704 .ip_pri_map = mv88e6085_g1_ip_pri_map,
3705 .irl_init_all = mv88e6352_g2_irl_init_all,
3706 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3707 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
3708 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3709 .phy_read = mv88e6xxx_g2_smi_phy_read,
3710 .phy_write = mv88e6xxx_g2_smi_phy_write,
3711 .port_set_link = mv88e6xxx_port_set_link,
3712 .port_set_duplex = mv88e6xxx_port_set_duplex,
3713 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3714 .port_set_speed = mv88e6250_port_set_speed,
3715 .port_tag_remap = mv88e6095_port_tag_remap,
3716 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3717 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3718 .port_set_ether_type = mv88e6351_port_set_ether_type,
3719 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3720 .port_pause_limit = mv88e6097_port_pause_limit,
3721 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3722 .port_link_state = mv88e6250_port_link_state,
3723 .stats_snapshot = mv88e6320_g1_stats_snapshot,
3724 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
3725 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
3726 .stats_get_strings = mv88e6250_stats_get_strings,
3727 .stats_get_stats = mv88e6250_stats_get_stats,
3728 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3729 .set_egress_port = mv88e6095_g1_set_egress_port,
3730 .watchdog_ops = &mv88e6250_watchdog_ops,
3731 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
3732 .pot_clear = mv88e6xxx_g2_pot_clear,
3733 .reset = mv88e6250_g1_reset,
3734 .vtu_getnext = mv88e6250_g1_vtu_getnext,
3735 .vtu_loadpurge = mv88e6250_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02003736 .avb_ops = &mv88e6352_avb_ops,
3737 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00003738 .phylink_validate = mv88e6065_phylink_validate,
3739};
3740
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003741static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003742 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003743 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003744 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003745 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3746 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003747 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3748 .phy_read = mv88e6xxx_g2_smi_phy_read,
3749 .phy_write = mv88e6xxx_g2_smi_phy_write,
3750 .port_set_link = mv88e6xxx_port_set_link,
3751 .port_set_duplex = mv88e6xxx_port_set_duplex,
3752 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3753 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003754 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003755 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003756 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003757 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003758 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003759 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003760 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003761 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003762 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003763 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003764 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003765 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003766 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003767 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003768 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003769 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3770 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003771 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003772 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3773 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003774 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003775 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003776 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003777 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003778 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04003779 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3780 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003781 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003782 .serdes_get_lane = mv88e6390_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003783 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003784 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003785 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003786 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003787 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003788 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003789 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003790};
3791
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003792static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003793 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003794 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3795 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003796 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003797 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3798 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003799 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003800 .phy_read = mv88e6xxx_g2_smi_phy_read,
3801 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003802 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003803 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003804 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003805 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003806 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003807 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003808 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003809 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003810 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003811 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003812 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003813 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003814 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003815 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003816 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003817 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003818 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003819 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3820 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003821 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003822 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3823 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01003824 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003825 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003826 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003827 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003828 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003829 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003830 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003831 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003832 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003833 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003834};
3835
3836static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04003837 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003838 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3839 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003840 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003841 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3842 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003843 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003844 .phy_read = mv88e6xxx_g2_smi_phy_read,
3845 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003846 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003847 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003848 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003849 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003850 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003851 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003852 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003853 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003854 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003855 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003856 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003857 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003858 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003859 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003860 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003861 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003862 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003863 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3864 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003865 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003866 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3867 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01003868 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003869 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003870 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003871 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003872 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003873 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003874 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003875 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003876};
3877
Vivien Didelot16e329a2017-03-28 13:50:33 -04003878static const struct mv88e6xxx_ops mv88e6341_ops = {
3879 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003880 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3881 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003882 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003883 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3884 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3885 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3886 .phy_read = mv88e6xxx_g2_smi_phy_read,
3887 .phy_write = mv88e6xxx_g2_smi_phy_write,
3888 .port_set_link = mv88e6xxx_port_set_link,
3889 .port_set_duplex = mv88e6xxx_port_set_duplex,
3890 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Marek Behún26422342018-10-13 14:40:31 +02003891 .port_set_speed = mv88e6341_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003892 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003893 .port_tag_remap = mv88e6095_port_tag_remap,
3894 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3895 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3896 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003897 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003898 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003899 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003900 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3901 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003902 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003903 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003904 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003905 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003906 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003907 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003908 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3909 .stats_get_strings = mv88e6320_stats_get_strings,
3910 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003911 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3912 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003913 .watchdog_ops = &mv88e6390_watchdog_ops,
3914 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003915 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003916 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003917 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003918 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003919 .serdes_power = mv88e6390_serdes_power,
3920 .serdes_get_lane = mv88e6341_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003921 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003922 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003923 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003924 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01003925 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02003926 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003927 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04003928};
3929
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003930static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003931 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003932 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3933 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003934 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003935 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003936 .phy_read = mv88e6xxx_g2_smi_phy_read,
3937 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003938 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003939 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003940 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003941 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003942 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003943 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003944 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003945 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003946 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003947 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003948 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003949 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003950 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003951 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003952 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003953 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003954 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003955 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003956 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3957 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003958 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003959 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3960 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003961 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003962 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003963 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003964 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003965 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003966 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003967 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003968};
3969
3970static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003971 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003972 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3973 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003974 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003975 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003976 .phy_read = mv88e6xxx_g2_smi_phy_read,
3977 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003978 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003979 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003980 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003981 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003982 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003983 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003984 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003985 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003986 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003987 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003988 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003989 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003990 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003991 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003992 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003993 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003994 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003995 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003996 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3997 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003998 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003999 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4000 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004001 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004002 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004003 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004004 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004005 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004006 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004007 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004008 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004009 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004010};
4011
4012static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004013 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004014 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4015 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004016 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004017 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4018 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004019 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004020 .phy_read = mv88e6xxx_g2_smi_phy_read,
4021 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004022 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01004023 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004024 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01004025 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004026 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004027 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004028 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004029 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004030 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004031 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004032 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004033 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004034 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004035 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004036 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004037 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004038 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004039 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004040 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004041 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4042 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004043 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004044 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4045 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004046 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004047 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004048 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004049 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004050 .rmu_disable = mv88e6352_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004051 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004052 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004053 .serdes_get_lane = mv88e6352_serdes_get_lane,
Andrew Lunn6d917822017-05-26 01:03:21 +02004054 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004055 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004056 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004057 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004058 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004059 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004060 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004061 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4062 .serdes_get_strings = mv88e6352_serdes_get_strings,
4063 .serdes_get_stats = mv88e6352_serdes_get_stats,
Russell King6c422e32018-08-09 15:38:39 +02004064 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004065};
4066
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004067static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004068 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004069 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004070 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004071 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4072 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004073 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4074 .phy_read = mv88e6xxx_g2_smi_phy_read,
4075 .phy_write = mv88e6xxx_g2_smi_phy_write,
4076 .port_set_link = mv88e6xxx_port_set_link,
4077 .port_set_duplex = mv88e6xxx_port_set_duplex,
4078 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4079 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004080 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004081 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004082 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004083 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004084 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004085 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004086 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004087 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004088 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004089 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004090 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004091 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004092 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004093 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004094 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004095 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004096 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004097 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4098 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004099 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004100 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4101 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004102 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004103 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004104 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004105 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004106 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04004107 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4108 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004109 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004110 .serdes_get_lane = mv88e6390_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004111 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004112 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004113 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004114 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004115 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004116 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004117 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004118};
4119
4120static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004121 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004122 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004123 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004124 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4125 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004126 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4127 .phy_read = mv88e6xxx_g2_smi_phy_read,
4128 .phy_write = mv88e6xxx_g2_smi_phy_write,
4129 .port_set_link = mv88e6xxx_port_set_link,
4130 .port_set_duplex = mv88e6xxx_port_set_duplex,
4131 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4132 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004133 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004134 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004135 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004136 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004137 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004138 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004139 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004140 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004141 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004142 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004143 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004144 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004145 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004146 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004147 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004148 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004149 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004150 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4151 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004152 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004153 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4154 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004155 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004156 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004157 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004158 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004159 .rmu_disable = mv88e6390_g1_rmu_disable,
Vivien Didelot931d1822017-05-01 14:05:27 -04004160 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4161 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004162 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004163 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004164 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004165 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004166 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004167 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004168 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004169 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004170 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004171};
4172
Vivien Didelotf81ec902016-05-09 13:22:58 -04004173static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4174 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004175 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004176 .family = MV88E6XXX_FAMILY_6097,
4177 .name = "Marvell 88E6085",
4178 .num_databases = 4096,
4179 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004180 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004181 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004182 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004183 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004184 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004185 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004186 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004187 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004188 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004189 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004190 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004191 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004192 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004193 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004194 },
4195
4196 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004197 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004198 .family = MV88E6XXX_FAMILY_6095,
4199 .name = "Marvell 88E6095/88E6095F",
4200 .num_databases = 256,
4201 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004202 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004203 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004204 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004205 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004206 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004207 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004208 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004209 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004210 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004211 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004212 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004213 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004214 },
4215
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004216 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004217 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004218 .family = MV88E6XXX_FAMILY_6097,
4219 .name = "Marvell 88E6097/88E6097F",
4220 .num_databases = 4096,
4221 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004222 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004223 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004224 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004225 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004226 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004227 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004228 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004229 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004230 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004231 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004232 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004233 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01004234 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004235 .ops = &mv88e6097_ops,
4236 },
4237
Vivien Didelotf81ec902016-05-09 13:22:58 -04004238 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004239 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004240 .family = MV88E6XXX_FAMILY_6165,
4241 .name = "Marvell 88E6123",
4242 .num_databases = 4096,
4243 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004244 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004245 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004246 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004247 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004248 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004249 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004250 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004251 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004252 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004253 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004254 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004255 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004256 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004257 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004258 },
4259
4260 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004261 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004262 .family = MV88E6XXX_FAMILY_6185,
4263 .name = "Marvell 88E6131",
4264 .num_databases = 256,
4265 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004266 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004267 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004268 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004269 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004270 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004271 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004272 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004273 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004274 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004275 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004276 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004277 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004278 },
4279
Vivien Didelot990e27b2017-03-28 13:50:32 -04004280 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004281 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004282 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01004283 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04004284 .num_databases = 4096,
4285 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004286 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004287 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004288 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004289 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004290 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004291 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004292 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004293 .age_time_coeff = 3750,
4294 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004295 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004296 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004297 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004298 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004299 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004300 .ops = &mv88e6141_ops,
4301 },
4302
Vivien Didelotf81ec902016-05-09 13:22:58 -04004303 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004304 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004305 .family = MV88E6XXX_FAMILY_6165,
4306 .name = "Marvell 88E6161",
4307 .num_databases = 4096,
4308 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004309 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004310 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004311 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004312 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004313 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004314 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004315 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004316 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004317 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004318 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004319 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004320 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004321 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004322 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004323 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004324 },
4325
4326 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004327 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004328 .family = MV88E6XXX_FAMILY_6165,
4329 .name = "Marvell 88E6165",
4330 .num_databases = 4096,
4331 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004332 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004333 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004334 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004335 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004336 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004337 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004338 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004339 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004340 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004341 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004342 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004343 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004344 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004345 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004346 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004347 },
4348
4349 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004350 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004351 .family = MV88E6XXX_FAMILY_6351,
4352 .name = "Marvell 88E6171",
4353 .num_databases = 4096,
4354 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004355 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004356 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004357 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004358 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004359 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004360 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004361 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004362 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004363 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004364 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004365 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004366 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004367 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004368 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004369 },
4370
4371 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004372 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004373 .family = MV88E6XXX_FAMILY_6352,
4374 .name = "Marvell 88E6172",
4375 .num_databases = 4096,
4376 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004377 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004378 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004379 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004380 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004381 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004382 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004383 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004384 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004385 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004386 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004387 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004388 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004389 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004390 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004391 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004392 },
4393
4394 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004395 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004396 .family = MV88E6XXX_FAMILY_6351,
4397 .name = "Marvell 88E6175",
4398 .num_databases = 4096,
4399 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004400 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004401 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004402 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004403 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004404 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004405 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004406 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004407 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004408 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004409 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004410 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004411 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004412 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004413 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004414 },
4415
4416 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004417 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004418 .family = MV88E6XXX_FAMILY_6352,
4419 .name = "Marvell 88E6176",
4420 .num_databases = 4096,
4421 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004422 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004423 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004424 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004425 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004426 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004427 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004428 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004429 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004430 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004431 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004432 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004433 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004434 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004435 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004436 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004437 },
4438
4439 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004440 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004441 .family = MV88E6XXX_FAMILY_6185,
4442 .name = "Marvell 88E6185",
4443 .num_databases = 256,
4444 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004445 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004446 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004447 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004448 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004449 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004450 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004451 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004452 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004453 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004454 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004455 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004456 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004457 },
4458
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004459 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004460 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004461 .family = MV88E6XXX_FAMILY_6390,
4462 .name = "Marvell 88E6190",
4463 .num_databases = 4096,
4464 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004465 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004466 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004467 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004468 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004469 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004470 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004471 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004472 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004473 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004474 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004475 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04004476 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004477 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05004478 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004479 .ops = &mv88e6190_ops,
4480 },
4481
4482 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004483 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004484 .family = MV88E6XXX_FAMILY_6390,
4485 .name = "Marvell 88E6190X",
4486 .num_databases = 4096,
4487 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004488 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004489 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004490 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004491 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004492 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004493 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004494 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004495 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004496 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004497 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004498 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004499 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004500 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004501 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004502 .ops = &mv88e6190x_ops,
4503 },
4504
4505 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004506 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004507 .family = MV88E6XXX_FAMILY_6390,
4508 .name = "Marvell 88E6191",
4509 .num_databases = 4096,
4510 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004511 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04004512 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004513 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004514 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004515 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004516 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004517 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004518 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004519 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004520 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004521 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004522 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004523 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004524 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04004525 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004526 },
4527
Hubert Feurstein49022642019-07-31 10:23:46 +02004528 [MV88E6220] = {
4529 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
4530 .family = MV88E6XXX_FAMILY_6250,
4531 .name = "Marvell 88E6220",
4532 .num_databases = 64,
4533
4534 /* Ports 2-4 are not routed to pins
4535 * => usable ports 0, 1, 5, 6
4536 */
4537 .num_ports = 7,
4538 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02004539 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02004540 .max_vid = 4095,
4541 .port_base_addr = 0x08,
4542 .phy_base_addr = 0x00,
4543 .global1_addr = 0x0f,
4544 .global2_addr = 0x07,
4545 .age_time_coeff = 15000,
4546 .g1_irqs = 9,
4547 .g2_irqs = 10,
4548 .atu_move_port_mask = 0xf,
4549 .dual_chip = true,
4550 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02004551 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02004552 .ops = &mv88e6250_ops,
4553 },
4554
Vivien Didelotf81ec902016-05-09 13:22:58 -04004555 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004556 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004557 .family = MV88E6XXX_FAMILY_6352,
4558 .name = "Marvell 88E6240",
4559 .num_databases = 4096,
4560 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004561 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004562 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004563 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004564 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004565 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004566 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004567 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004568 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004569 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004570 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004571 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004572 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004573 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004574 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004575 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004576 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004577 },
4578
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004579 [MV88E6250] = {
4580 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
4581 .family = MV88E6XXX_FAMILY_6250,
4582 .name = "Marvell 88E6250",
4583 .num_databases = 64,
4584 .num_ports = 7,
4585 .num_internal_phys = 5,
4586 .max_vid = 4095,
4587 .port_base_addr = 0x08,
4588 .phy_base_addr = 0x00,
4589 .global1_addr = 0x0f,
4590 .global2_addr = 0x07,
4591 .age_time_coeff = 15000,
4592 .g1_irqs = 9,
4593 .g2_irqs = 10,
4594 .atu_move_port_mask = 0xf,
4595 .dual_chip = true,
4596 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02004597 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004598 .ops = &mv88e6250_ops,
4599 },
4600
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004601 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004602 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004603 .family = MV88E6XXX_FAMILY_6390,
4604 .name = "Marvell 88E6290",
4605 .num_databases = 4096,
4606 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004607 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004608 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004609 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004610 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004611 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004612 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004613 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004614 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004615 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004616 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004617 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004618 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004619 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004620 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004621 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004622 .ops = &mv88e6290_ops,
4623 },
4624
Vivien Didelotf81ec902016-05-09 13:22:58 -04004625 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004626 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004627 .family = MV88E6XXX_FAMILY_6320,
4628 .name = "Marvell 88E6320",
4629 .num_databases = 4096,
4630 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004631 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004632 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004633 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004634 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004635 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004636 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004637 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004638 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004639 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004640 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004641 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004642 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004643 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004644 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004645 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004646 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004647 },
4648
4649 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004650 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004651 .family = MV88E6XXX_FAMILY_6320,
4652 .name = "Marvell 88E6321",
4653 .num_databases = 4096,
4654 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004655 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004656 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004657 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004658 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004659 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004660 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004661 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004662 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004663 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004664 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004665 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004666 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004667 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004668 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004669 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004670 },
4671
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004672 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004673 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004674 .family = MV88E6XXX_FAMILY_6341,
4675 .name = "Marvell 88E6341",
4676 .num_databases = 4096,
Andrew Lunnbc393152018-03-17 20:32:04 +01004677 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004678 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004679 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004680 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004681 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004682 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004683 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004684 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004685 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05004686 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004687 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004688 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004689 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004690 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004691 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004692 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004693 .ops = &mv88e6341_ops,
4694 },
4695
Vivien Didelotf81ec902016-05-09 13:22:58 -04004696 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004697 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004698 .family = MV88E6XXX_FAMILY_6351,
4699 .name = "Marvell 88E6350",
4700 .num_databases = 4096,
4701 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004702 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004703 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004704 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004705 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004706 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004707 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004708 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004709 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004710 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004711 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004712 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004713 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004714 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004715 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004716 },
4717
4718 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004719 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004720 .family = MV88E6XXX_FAMILY_6351,
4721 .name = "Marvell 88E6351",
4722 .num_databases = 4096,
4723 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004724 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004725 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004726 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004727 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004728 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004729 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004730 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004731 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004732 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004733 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004734 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004735 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004736 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004737 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004738 },
4739
4740 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004741 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004742 .family = MV88E6XXX_FAMILY_6352,
4743 .name = "Marvell 88E6352",
4744 .num_databases = 4096,
4745 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004746 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004747 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004748 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004749 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004750 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004751 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004752 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004753 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004754 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004755 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004756 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004757 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004758 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004759 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004760 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004761 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004762 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004763 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004764 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004765 .family = MV88E6XXX_FAMILY_6390,
4766 .name = "Marvell 88E6390",
4767 .num_databases = 4096,
4768 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004769 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004770 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004771 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004772 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004773 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004774 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004775 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004776 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004777 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004778 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004779 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004780 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004781 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004782 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004783 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004784 .ops = &mv88e6390_ops,
4785 },
4786 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004787 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004788 .family = MV88E6XXX_FAMILY_6390,
4789 .name = "Marvell 88E6390X",
4790 .num_databases = 4096,
4791 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004792 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004793 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004794 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004795 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004796 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004797 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004798 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004799 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004800 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004801 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05004802 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004803 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004804 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004805 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01004806 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004807 .ops = &mv88e6390x_ops,
4808 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004809};
4810
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004811static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004812{
Vivien Didelota439c062016-04-17 13:23:58 -04004813 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004814
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004815 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4816 if (mv88e6xxx_table[i].prod_num == prod_num)
4817 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004818
Vivien Didelotb9b37712015-10-30 19:39:48 -04004819 return NULL;
4820}
4821
Vivien Didelotfad09c72016-06-21 12:28:20 -04004822static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004823{
4824 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004825 unsigned int prod_num, rev;
4826 u16 id;
4827 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004828
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004829 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04004830 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004831 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004832 if (err)
4833 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004834
Vivien Didelot107fcc12017-06-12 12:37:36 -04004835 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
4836 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004837
4838 info = mv88e6xxx_lookup_info(prod_num);
4839 if (!info)
4840 return -ENODEV;
4841
Vivien Didelotcaac8542016-06-20 13:14:09 -04004842 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004843 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004844
Vivien Didelotca070c12016-09-02 14:45:34 -04004845 err = mv88e6xxx_g2_require(chip);
4846 if (err)
4847 return err;
4848
Vivien Didelotfad09c72016-06-21 12:28:20 -04004849 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4850 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004851
4852 return 0;
4853}
4854
Vivien Didelotfad09c72016-06-21 12:28:20 -04004855static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004856{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004857 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004858
Vivien Didelotfad09c72016-06-21 12:28:20 -04004859 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4860 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004861 return NULL;
4862
Vivien Didelotfad09c72016-06-21 12:28:20 -04004863 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004864
Vivien Didelotfad09c72016-06-21 12:28:20 -04004865 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004866 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04004867 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04004868
Vivien Didelotfad09c72016-06-21 12:28:20 -04004869 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004870}
4871
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08004872static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
4873 int port)
Andrew Lunn7b314362016-08-22 16:01:01 +02004874{
Vivien Didelot04bed142016-08-31 18:06:13 -04004875 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004876
Andrew Lunn443d5a12016-12-03 04:35:18 +01004877 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004878}
4879
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004880static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004881 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004882{
4883 /* We don't need any dynamic resource from the kernel (yet),
4884 * so skip the prepare phase.
4885 */
4886
4887 return 0;
4888}
4889
4890static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05004891 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004892{
Vivien Didelot04bed142016-08-31 18:06:13 -04004893 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004894
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004895 mv88e6xxx_reg_lock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004896 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04004897 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04004898 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
4899 port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004900 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004901}
4902
4903static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4904 const struct switchdev_obj_port_mdb *mdb)
4905{
Vivien Didelot04bed142016-08-31 18:06:13 -04004906 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004907 int err;
4908
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004909 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04004910 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004911 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004912
4913 return err;
4914}
4915
Russell King4f859012019-02-20 15:35:05 -08004916static int mv88e6xxx_port_egress_floods(struct dsa_switch *ds, int port,
4917 bool unicast, bool multicast)
4918{
4919 struct mv88e6xxx_chip *chip = ds->priv;
4920 int err = -EOPNOTSUPP;
4921
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004922 mv88e6xxx_reg_lock(chip);
Russell King4f859012019-02-20 15:35:05 -08004923 if (chip->info->ops->port_set_egress_floods)
4924 err = chip->info->ops->port_set_egress_floods(chip, port,
4925 unicast,
4926 multicast);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00004927 mv88e6xxx_reg_unlock(chip);
Russell King4f859012019-02-20 15:35:05 -08004928
4929 return err;
4930}
4931
Florian Fainellia82f67a2017-01-08 14:52:08 -08004932static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02004933 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004934 .setup = mv88e6xxx_setup,
Russell Kingc9a23562018-05-10 13:17:35 -07004935 .phylink_validate = mv88e6xxx_validate,
4936 .phylink_mac_link_state = mv88e6xxx_link_state,
4937 .phylink_mac_config = mv88e6xxx_mac_config,
4938 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
4939 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004940 .get_strings = mv88e6xxx_get_strings,
4941 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4942 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02004943 .port_enable = mv88e6xxx_port_enable,
4944 .port_disable = mv88e6xxx_port_disable,
Vivien Didelot08f50062017-08-01 16:32:41 -04004945 .get_mac_eee = mv88e6xxx_get_mac_eee,
4946 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004947 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004948 .get_eeprom = mv88e6xxx_get_eeprom,
4949 .set_eeprom = mv88e6xxx_set_eeprom,
4950 .get_regs_len = mv88e6xxx_get_regs_len,
4951 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04004952 .get_rxnfc = mv88e6xxx_get_rxnfc,
4953 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004954 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004955 .port_bridge_join = mv88e6xxx_port_bridge_join,
4956 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Russell King4f859012019-02-20 15:35:05 -08004957 .port_egress_floods = mv88e6xxx_port_egress_floods,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004958 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004959 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004960 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4961 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4962 .port_vlan_add = mv88e6xxx_port_vlan_add,
4963 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004964 .port_fdb_add = mv88e6xxx_port_fdb_add,
4965 .port_fdb_del = mv88e6xxx_port_fdb_del,
4966 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004967 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4968 .port_mdb_add = mv88e6xxx_port_mdb_add,
4969 .port_mdb_del = mv88e6xxx_port_mdb_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04004970 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
4971 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01004972 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
4973 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
4974 .port_txtstamp = mv88e6xxx_port_txtstamp,
4975 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
4976 .get_ts_info = mv88e6xxx_get_ts_info,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004977};
4978
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004979static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004980{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004981 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004982 struct dsa_switch *ds;
4983
Vivien Didelot73b12042017-03-30 17:37:10 -04004984 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004985 if (!ds)
4986 return -ENOMEM;
4987
Vivien Didelotfad09c72016-06-21 12:28:20 -04004988 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02004989 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004990 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004991 ds->ageing_time_min = chip->info->age_time_coeff;
4992 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004993
4994 dev_set_drvdata(dev, ds);
4995
Vivien Didelot23c9ee42017-05-26 18:12:51 -04004996 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004997}
4998
Vivien Didelotfad09c72016-06-21 12:28:20 -04004999static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005000{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005001 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005002}
5003
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005004static const void *pdata_device_get_match_data(struct device *dev)
5005{
5006 const struct of_device_id *matches = dev->driver->of_match_table;
5007 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
5008
5009 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
5010 matches++) {
5011 if (!strcmp(pdata->compatible, matches->compatible))
5012 return matches->data;
5013 }
5014 return NULL;
5015}
5016
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005017/* There is no suspend to RAM support at DSA level yet, the switch configuration
5018 * would be lost after a power cycle so prevent it to be suspended.
5019 */
5020static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
5021{
5022 return -EOPNOTSUPP;
5023}
5024
5025static int __maybe_unused mv88e6xxx_resume(struct device *dev)
5026{
5027 return 0;
5028}
5029
5030static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
5031
Vivien Didelot57d32312016-06-20 13:13:58 -04005032static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005033{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005034 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04005035 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005036 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005037 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04005038 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005039 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02005040 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005041
Andrew Lunn7bb8c992018-05-31 00:15:42 +02005042 if (!np && !pdata)
5043 return -EINVAL;
5044
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005045 if (np)
5046 compat_info = of_device_get_match_data(dev);
5047
5048 if (pdata) {
5049 compat_info = pdata_device_get_match_data(dev);
5050
5051 if (!pdata->netdev)
5052 return -EINVAL;
5053
5054 for (port = 0; port < DSA_MAX_PORTS; port++) {
5055 if (!(pdata->enabled_ports & (1 << port)))
5056 continue;
5057 if (strcmp(pdata->cd.port_names[port], "cpu"))
5058 continue;
5059 pdata->cd.netdev[port] = &pdata->netdev->dev;
5060 break;
5061 }
5062 }
5063
Vivien Didelotcaac8542016-06-20 13:14:09 -04005064 if (!compat_info)
5065 return -EINVAL;
5066
Vivien Didelotfad09c72016-06-21 12:28:20 -04005067 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005068 if (!chip) {
5069 err = -ENOMEM;
5070 goto out;
5071 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005072
Vivien Didelotfad09c72016-06-21 12:28:20 -04005073 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04005074
Vivien Didelotfad09c72016-06-21 12:28:20 -04005075 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04005076 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005077 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005078
Andrew Lunnb4308f02016-11-21 23:26:55 +01005079 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005080 if (IS_ERR(chip->reset)) {
5081 err = PTR_ERR(chip->reset);
5082 goto out;
5083 }
Baruch Siach7b75e492019-06-27 21:17:39 +03005084 if (chip->reset)
5085 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01005086
Vivien Didelotfad09c72016-06-21 12:28:20 -04005087 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005088 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005089 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005090
Vivien Didelote57e5e72016-08-15 17:19:00 -04005091 mv88e6xxx_phy_init(chip);
5092
Andrew Lunn00baabe2018-05-19 22:31:35 +02005093 if (chip->info->ops->get_eeprom) {
5094 if (np)
5095 of_property_read_u32(np, "eeprom-length",
5096 &chip->eeprom_len);
5097 else
5098 chip->eeprom_len = pdata->eeprom_len;
5099 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005100
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005101 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005102 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005103 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02005104 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02005105 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02005106
Andrew Lunna27415d2019-05-01 00:10:50 +02005107 if (np) {
5108 chip->irq = of_irq_get(np, 0);
5109 if (chip->irq == -EPROBE_DEFER) {
5110 err = chip->irq;
5111 goto out;
5112 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02005113 }
5114
Andrew Lunna27415d2019-05-01 00:10:50 +02005115 if (pdata)
5116 chip->irq = pdata->irq;
5117
Andrew Lunn294d7112018-02-22 22:58:32 +01005118 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01005119 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01005120 * controllers
5121 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005122 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005123 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005124 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005125 else
5126 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005127 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005128
Andrew Lunn294d7112018-02-22 22:58:32 +01005129 if (err)
5130 goto out;
5131
5132 if (chip->info->g2_irqs > 0) {
5133 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005134 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01005135 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005136 }
5137
Andrew Lunn294d7112018-02-22 22:58:32 +01005138 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
5139 if (err)
5140 goto out_g2_irq;
5141
5142 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
5143 if (err)
5144 goto out_g1_atu_prob_irq;
5145
Andrew Lunna3c53be52017-01-24 14:53:50 +01005146 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02005147 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01005148 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005149
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005150 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005151 if (err)
5152 goto out_mdio;
5153
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005154 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02005155
5156out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01005157 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01005158out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005159 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01005160out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005161 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005162out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005163 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005164 mv88e6xxx_g2_irq_free(chip);
5165out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005166 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005167 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005168 else
5169 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005170out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005171 if (pdata)
5172 dev_put(pdata->netdev);
5173
Andrew Lunndc30c352016-10-16 19:56:49 +02005174 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005175}
5176
5177static void mv88e6xxx_remove(struct mdio_device *mdiodev)
5178{
5179 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04005180 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005181
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005182 if (chip->info->ptp_support) {
5183 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005184 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005185 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005186
Andrew Lunn930188c2016-08-22 16:01:03 +02005187 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005188 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005189 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005190
Andrew Lunn76f38f12018-03-17 20:21:09 +01005191 mv88e6xxx_g1_vtu_prob_irq_free(chip);
5192 mv88e6xxx_g1_atu_prob_irq_free(chip);
5193
5194 if (chip->info->g2_irqs > 0)
5195 mv88e6xxx_g2_irq_free(chip);
5196
Andrew Lunn76f38f12018-03-17 20:21:09 +01005197 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005198 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01005199 else
5200 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005201}
5202
5203static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04005204 {
5205 .compatible = "marvell,mv88e6085",
5206 .data = &mv88e6xxx_table[MV88E6085],
5207 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005208 {
5209 .compatible = "marvell,mv88e6190",
5210 .data = &mv88e6xxx_table[MV88E6190],
5211 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005212 {
5213 .compatible = "marvell,mv88e6250",
5214 .data = &mv88e6xxx_table[MV88E6250],
5215 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005216 { /* sentinel */ },
5217};
5218
5219MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
5220
5221static struct mdio_driver mv88e6xxx_driver = {
5222 .probe = mv88e6xxx_probe,
5223 .remove = mv88e6xxx_remove,
5224 .mdiodrv.driver = {
5225 .name = "mv88e6085",
5226 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005227 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005228 },
5229};
5230
Andrew Lunn7324d502019-04-27 19:19:10 +02005231mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00005232
5233MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
5234MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
5235MODULE_LICENSE("GPL");