blob: 895d7b6dba2d85d347f1cbdd5533b1d49f7382d4 [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
Andrew Lunn30953832020-01-06 17:13:48 +0100343 snprintf(chip->irq_name, sizeof(chip->irq_name),
344 "mv88e6xxx-%s", dev_name(chip->dev));
345
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000346 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100347 err = request_threaded_irq(chip->irq, NULL,
348 mv88e6xxx_g1_irq_thread_fn,
Marek Behún03403762018-08-30 02:13:50 +0200349 IRQF_ONESHOT | IRQF_SHARED,
Andrew Lunn30953832020-01-06 17:13:48 +0100350 chip->irq_name, chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000351 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100352 if (err)
353 mv88e6xxx_g1_irq_free_common(chip);
354
355 return err;
356}
357
358static void mv88e6xxx_irq_poll(struct kthread_work *work)
359{
360 struct mv88e6xxx_chip *chip = container_of(work,
361 struct mv88e6xxx_chip,
362 irq_poll_work.work);
363 mv88e6xxx_g1_irq_thread_work(chip);
364
365 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
366 msecs_to_jiffies(100));
367}
368
369static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)
370{
371 int err;
372
373 err = mv88e6xxx_g1_irq_setup_common(chip);
374 if (err)
375 return err;
376
377 kthread_init_delayed_work(&chip->irq_poll_work,
378 mv88e6xxx_irq_poll);
379
Florian Fainelli3f8b8692019-02-21 20:09:27 -0800380 chip->kworker = kthread_create_worker(0, "%s", dev_name(chip->dev));
Andrew Lunn294d7112018-02-22 22:58:32 +0100381 if (IS_ERR(chip->kworker))
382 return PTR_ERR(chip->kworker);
383
384 kthread_queue_delayed_work(chip->kworker, &chip->irq_poll_work,
385 msecs_to_jiffies(100));
386
387 return 0;
388}
389
390static void mv88e6xxx_irq_poll_free(struct mv88e6xxx_chip *chip)
391{
392 kthread_cancel_delayed_work_sync(&chip->irq_poll_work);
393 kthread_destroy_worker(chip->kworker);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200394
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000395 mv88e6xxx_reg_lock(chip);
Uwe Kleine-König3d824752018-07-20 11:53:15 +0200396 mv88e6xxx_g1_irq_free_common(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000397 mv88e6xxx_reg_unlock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +0100398}
399
Russell King64d47d52020-03-14 10:15:38 +0000400static int mv88e6xxx_port_config_interface(struct mv88e6xxx_chip *chip,
401 int port, phy_interface_t interface)
402{
403 int err;
404
405 if (chip->info->ops->port_set_rgmii_delay) {
406 err = chip->info->ops->port_set_rgmii_delay(chip, port,
407 interface);
408 if (err && err != -EOPNOTSUPP)
409 return err;
410 }
411
412 if (chip->info->ops->port_set_cmode) {
413 err = chip->info->ops->port_set_cmode(chip, port,
414 interface);
415 if (err && err != -EOPNOTSUPP)
416 return err;
417 }
418
419 return 0;
420}
421
Russell Kinga5a68582020-03-14 10:15:43 +0000422static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
423 int link, int speed, int duplex, int pause,
424 phy_interface_t mode)
Vivien Didelotd78343d2016-11-04 03:23:36 +0100425{
426 int err;
427
428 if (!chip->info->ops->port_set_link)
429 return 0;
430
431 /* Port's MAC control must not be changed unless the link is down */
Hubert Feurstein43c8e0a2019-07-30 12:11:42 +0200432 err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100433 if (err)
434 return err;
435
Russell Kingf365c6f2020-03-14 10:15:53 +0000436 if (chip->info->ops->port_set_speed_duplex) {
437 err = chip->info->ops->port_set_speed_duplex(chip, port,
438 speed, duplex);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100439 if (err && err != -EOPNOTSUPP)
440 goto restore_link;
441 }
442
Andrew Lunn7cbbee02019-03-08 01:21:27 +0100443 if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
444 mode = chip->info->ops->port_max_speed_mode(port);
445
Andrew Lunn54186b92018-08-09 15:38:37 +0200446 if (chip->info->ops->port_set_pause) {
447 err = chip->info->ops->port_set_pause(chip, port, pause);
448 if (err)
449 goto restore_link;
450 }
451
Russell King64d47d52020-03-14 10:15:38 +0000452 err = mv88e6xxx_port_config_interface(chip, port, mode);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100453restore_link:
454 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400455 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100456
457 return err;
458}
459
Marek Vasutd700ec42018-09-12 00:15:24 +0200460static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
461{
462 struct mv88e6xxx_chip *chip = ds->priv;
463
464 return port < chip->info->num_internal_phys;
465}
466
Russell King5d5b2312020-03-14 10:16:03 +0000467static int mv88e6xxx_port_ppu_updates(struct mv88e6xxx_chip *chip, int port)
468{
469 u16 reg;
470 int err;
471
472 err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_STS, &reg);
473 if (err) {
474 dev_err(chip->dev,
475 "p%d: %s: failed to read port status\n",
476 port, __func__);
477 return err;
478 }
479
480 return !!(reg & MV88E6XXX_PORT_STS_PHY_DETECT);
481}
482
Russell Kinga5a68582020-03-14 10:15:43 +0000483static int mv88e6xxx_serdes_pcs_get_state(struct dsa_switch *ds, int port,
484 struct phylink_link_state *state)
485{
486 struct mv88e6xxx_chip *chip = ds->priv;
487 u8 lane;
488 int err;
489
490 mv88e6xxx_reg_lock(chip);
491 lane = mv88e6xxx_serdes_get_lane(chip, port);
492 if (lane && chip->info->ops->serdes_pcs_get_state)
493 err = chip->info->ops->serdes_pcs_get_state(chip, port, lane,
494 state);
495 else
496 err = -EOPNOTSUPP;
497 mv88e6xxx_reg_unlock(chip);
498
499 return err;
500}
501
502static int mv88e6xxx_serdes_pcs_config(struct mv88e6xxx_chip *chip, int port,
503 unsigned int mode,
504 phy_interface_t interface,
505 const unsigned long *advertise)
506{
507 const struct mv88e6xxx_ops *ops = chip->info->ops;
508 u8 lane;
509
510 if (ops->serdes_pcs_config) {
511 lane = mv88e6xxx_serdes_get_lane(chip, port);
512 if (lane)
513 return ops->serdes_pcs_config(chip, port, lane, mode,
514 interface, advertise);
515 }
516
517 return 0;
518}
519
520static void mv88e6xxx_serdes_pcs_an_restart(struct dsa_switch *ds, int port)
521{
522 struct mv88e6xxx_chip *chip = ds->priv;
523 const struct mv88e6xxx_ops *ops;
524 int err = 0;
525 u8 lane;
526
527 ops = chip->info->ops;
528
529 if (ops->serdes_pcs_an_restart) {
530 mv88e6xxx_reg_lock(chip);
531 lane = mv88e6xxx_serdes_get_lane(chip, port);
532 if (lane)
533 err = ops->serdes_pcs_an_restart(chip, port, lane);
534 mv88e6xxx_reg_unlock(chip);
535
536 if (err)
537 dev_err(ds->dev, "p%d: failed to restart AN\n", port);
538 }
539}
540
541static int mv88e6xxx_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port,
542 unsigned int mode,
543 int speed, int duplex)
544{
545 const struct mv88e6xxx_ops *ops = chip->info->ops;
546 u8 lane;
547
548 if (!phylink_autoneg_inband(mode) && ops->serdes_pcs_link_up) {
549 lane = mv88e6xxx_serdes_get_lane(chip, port);
550 if (lane)
551 return ops->serdes_pcs_link_up(chip, port, lane,
552 speed, duplex);
553 }
554
555 return 0;
556}
557
Russell King6c422e32018-08-09 15:38:39 +0200558static void mv88e6065_phylink_validate(struct mv88e6xxx_chip *chip, int port,
559 unsigned long *mask,
560 struct phylink_link_state *state)
561{
562 if (!phy_interface_mode_is_8023z(state->interface)) {
563 /* 10M and 100M are only supported in non-802.3z mode */
564 phylink_set(mask, 10baseT_Half);
565 phylink_set(mask, 10baseT_Full);
566 phylink_set(mask, 100baseT_Half);
567 phylink_set(mask, 100baseT_Full);
568 }
569}
570
571static void mv88e6185_phylink_validate(struct mv88e6xxx_chip *chip, int port,
572 unsigned long *mask,
573 struct phylink_link_state *state)
574{
575 /* FIXME: if the port is in 1000Base-X mode, then it only supports
576 * 1000M FD speeds. In this case, CMODE will indicate 5.
577 */
578 phylink_set(mask, 1000baseT_Full);
579 phylink_set(mask, 1000baseX_Full);
580
581 mv88e6065_phylink_validate(chip, port, mask, state);
582}
583
Marek Behúne3af71a2019-02-25 12:39:55 +0100584static void mv88e6341_phylink_validate(struct mv88e6xxx_chip *chip, int port,
585 unsigned long *mask,
586 struct phylink_link_state *state)
587{
588 if (port >= 5)
589 phylink_set(mask, 2500baseX_Full);
590
591 /* No ethtool bits for 200Mbps */
592 phylink_set(mask, 1000baseT_Full);
593 phylink_set(mask, 1000baseX_Full);
594
595 mv88e6065_phylink_validate(chip, port, mask, state);
596}
597
Russell King6c422e32018-08-09 15:38:39 +0200598static void mv88e6352_phylink_validate(struct mv88e6xxx_chip *chip, int port,
599 unsigned long *mask,
600 struct phylink_link_state *state)
601{
602 /* No ethtool bits for 200Mbps */
603 phylink_set(mask, 1000baseT_Full);
604 phylink_set(mask, 1000baseX_Full);
605
606 mv88e6065_phylink_validate(chip, port, mask, state);
607}
608
609static void mv88e6390_phylink_validate(struct mv88e6xxx_chip *chip, int port,
610 unsigned long *mask,
611 struct phylink_link_state *state)
612{
Andrew Lunnec260162019-02-08 22:25:44 +0100613 if (port >= 9) {
Russell King6c422e32018-08-09 15:38:39 +0200614 phylink_set(mask, 2500baseX_Full);
Andrew Lunnec260162019-02-08 22:25:44 +0100615 phylink_set(mask, 2500baseT_Full);
616 }
Russell King6c422e32018-08-09 15:38:39 +0200617
618 /* No ethtool bits for 200Mbps */
619 phylink_set(mask, 1000baseT_Full);
620 phylink_set(mask, 1000baseX_Full);
621
622 mv88e6065_phylink_validate(chip, port, mask, state);
623}
624
625static void mv88e6390x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
626 unsigned long *mask,
627 struct phylink_link_state *state)
628{
629 if (port >= 9) {
630 phylink_set(mask, 10000baseT_Full);
631 phylink_set(mask, 10000baseKR_Full);
632 }
633
634 mv88e6390_phylink_validate(chip, port, mask, state);
635}
636
Russell Kingc9a23562018-05-10 13:17:35 -0700637static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
638 unsigned long *supported,
639 struct phylink_link_state *state)
640{
Russell King6c422e32018-08-09 15:38:39 +0200641 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
642 struct mv88e6xxx_chip *chip = ds->priv;
643
644 /* Allow all the expected bits */
645 phylink_set(mask, Autoneg);
646 phylink_set(mask, Pause);
647 phylink_set_port_modes(mask);
648
649 if (chip->info->ops->phylink_validate)
650 chip->info->ops->phylink_validate(chip, port, mask, state);
651
652 bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
653 bitmap_and(state->advertising, state->advertising, mask,
654 __ETHTOOL_LINK_MODE_MASK_NBITS);
655
656 /* We can only operate at 2500BaseX or 1000BaseX. If requested
657 * to advertise both, only report advertising at 2500BaseX.
658 */
659 phylink_helper_basex_speed(state);
Russell Kingc9a23562018-05-10 13:17:35 -0700660}
661
Russell Kingc9a23562018-05-10 13:17:35 -0700662static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
663 unsigned int mode,
664 const struct phylink_link_state *state)
665{
666 struct mv88e6xxx_chip *chip = ds->priv;
Russell Kingfad58192020-07-19 12:00:35 +0100667 struct mv88e6xxx_port *p;
Russell King64d47d52020-03-14 10:15:38 +0000668 int err;
Russell Kingc9a23562018-05-10 13:17:35 -0700669
Russell Kingfad58192020-07-19 12:00:35 +0100670 p = &chip->ports[port];
671
Russell King64d47d52020-03-14 10:15:38 +0000672 /* FIXME: is this the correct test? If we're in fixed mode on an
673 * internal port, why should we process this any different from
674 * PHY mode? On the other hand, the port may be automedia between
675 * an internal PHY and the serdes...
676 */
Marek Vasutd700ec42018-09-12 00:15:24 +0200677 if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
Russell Kingc9a23562018-05-10 13:17:35 -0700678 return;
679
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000680 mv88e6xxx_reg_lock(chip);
Russell Kingfad58192020-07-19 12:00:35 +0100681 /* In inband mode, the link may come up at any time while the link
682 * is not forced down. Force the link down while we reconfigure the
683 * interface mode.
Russell King64d47d52020-03-14 10:15:38 +0000684 */
Russell Kingfad58192020-07-19 12:00:35 +0100685 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
686 chip->info->ops->port_set_link)
687 chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
688
Russell King64d47d52020-03-14 10:15:38 +0000689 err = mv88e6xxx_port_config_interface(chip, port, state->interface);
Russell Kinga5a68582020-03-14 10:15:43 +0000690 if (err && err != -EOPNOTSUPP)
691 goto err_unlock;
692
693 err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
694 state->advertising);
695 /* FIXME: we should restart negotiation if something changed - which
696 * is something we get if we convert to using phylinks PCS operations.
697 */
698 if (err > 0)
699 err = 0;
700
Russell Kingfad58192020-07-19 12:00:35 +0100701 /* Undo the forced down state above after completing configuration
702 * irrespective of its state on entry, which allows the link to come up.
703 */
704 if (mode == MLO_AN_INBAND && p->interface != state->interface &&
705 chip->info->ops->port_set_link)
706 chip->info->ops->port_set_link(chip, port, LINK_UNFORCED);
707
708 p->interface = state->interface;
709
Russell Kinga5a68582020-03-14 10:15:43 +0000710err_unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000711 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700712
713 if (err && err != -EOPNOTSUPP)
Russell King64d47d52020-03-14 10:15:38 +0000714 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700715}
716
Russell Kingc9a23562018-05-10 13:17:35 -0700717static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
718 unsigned int mode,
719 phy_interface_t interface)
720{
Russell King30c4a5b2020-02-26 10:23:51 +0000721 struct mv88e6xxx_chip *chip = ds->priv;
722 const struct mv88e6xxx_ops *ops;
723 int err = 0;
724
725 ops = chip->info->ops;
726
Russell King5d5b2312020-03-14 10:16:03 +0000727 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200728 if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
729 mode == MLO_AN_FIXED) && ops->port_set_link)
Russell King30c4a5b2020-02-26 10:23:51 +0000730 err = ops->port_set_link(chip, port, LINK_FORCED_DOWN);
Russell King5d5b2312020-03-14 10:16:03 +0000731 mv88e6xxx_reg_unlock(chip);
Russell King30c4a5b2020-02-26 10:23:51 +0000732
Russell King5d5b2312020-03-14 10:16:03 +0000733 if (err)
734 dev_err(chip->dev,
735 "p%d: failed to force MAC link down\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700736}
737
738static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
739 unsigned int mode, phy_interface_t interface,
Russell King5b502a72020-02-26 10:23:46 +0000740 struct phy_device *phydev,
741 int speed, int duplex,
742 bool tx_pause, bool rx_pause)
Russell Kingc9a23562018-05-10 13:17:35 -0700743{
Russell King30c4a5b2020-02-26 10:23:51 +0000744 struct mv88e6xxx_chip *chip = ds->priv;
745 const struct mv88e6xxx_ops *ops;
746 int err = 0;
747
748 ops = chip->info->ops;
749
Russell King5d5b2312020-03-14 10:16:03 +0000750 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200751 if (!mv88e6xxx_port_ppu_updates(chip, port) || mode == MLO_AN_FIXED) {
Russell King30c4a5b2020-02-26 10:23:51 +0000752 /* FIXME: for an automedia port, should we force the link
753 * down here - what if the link comes up due to "other" media
754 * while we're bringing the port up, how is the exclusivity
Russell Kinga5a68582020-03-14 10:15:43 +0000755 * handled in the Marvell hardware? E.g. port 2 on 88E6390
Russell King30c4a5b2020-02-26 10:23:51 +0000756 * shared between internal PHY and Serdes.
757 */
Russell Kinga5a68582020-03-14 10:15:43 +0000758 err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
759 duplex);
760 if (err)
761 goto error;
762
Russell Kingf365c6f2020-03-14 10:15:53 +0000763 if (ops->port_set_speed_duplex) {
764 err = ops->port_set_speed_duplex(chip, port,
765 speed, duplex);
Russell King30c4a5b2020-02-26 10:23:51 +0000766 if (err && err != -EOPNOTSUPP)
767 goto error;
768 }
769
770 if (ops->port_set_link)
771 err = ops->port_set_link(chip, port, LINK_FORCED_UP);
Russell King30c4a5b2020-02-26 10:23:51 +0000772 }
Russell King5d5b2312020-03-14 10:16:03 +0000773error:
774 mv88e6xxx_reg_unlock(chip);
775
776 if (err && err != -EOPNOTSUPP)
777 dev_err(ds->dev,
778 "p%d: failed to configure MAC link up\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700779}
780
Andrew Lunna605a0f2016-11-21 23:26:58 +0100781static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000782{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100783 if (!chip->info->ops->stats_snapshot)
784 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000785
Andrew Lunna605a0f2016-11-21 23:26:58 +0100786 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000787}
788
Andrew Lunne413e7e2015-04-02 04:06:38 +0200789static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100790 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
791 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
792 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
793 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
794 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
795 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
796 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
797 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
798 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
799 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
800 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
801 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
802 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
803 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
804 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
805 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
806 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
807 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
808 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
809 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
810 { "single", 4, 0x14, STATS_TYPE_BANK0, },
811 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
812 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
813 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
814 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
815 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
816 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
817 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
818 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
819 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
820 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
821 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
822 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
823 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
824 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
825 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
826 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
827 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
828 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
829 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
830 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
831 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
832 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
833 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
834 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
835 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
836 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
837 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
838 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
839 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
840 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
841 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
842 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
843 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
844 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
845 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
846 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
847 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
848 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200849};
850
Vivien Didelotfad09c72016-06-21 12:28:20 -0400851static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100852 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100853 int port, u16 bank1_select,
854 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200855{
Andrew Lunn80c46272015-06-20 18:42:30 +0200856 u32 low;
857 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100858 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200859 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200860 u64 value;
861
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100862 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100863 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200864 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
865 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800866 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200867
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200868 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100869 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200870 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
871 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800872 return U64_MAX;
Rasmus Villemoes84b3fd12019-05-29 07:02:11 +0000873 low |= ((u32)reg) << 16;
Andrew Lunn80c46272015-06-20 18:42:30 +0200874 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100875 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100876 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100877 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100878 /* fall through */
879 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100880 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100881 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100882 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100883 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500884 break;
885 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800886 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200887 }
Andrew Lunn6e46e2d2019-02-28 18:14:03 +0100888 value = (((u64)high) << 32) | low;
Andrew Lunn80c46272015-06-20 18:42:30 +0200889 return value;
890}
891
Andrew Lunn436fe172018-03-01 02:02:29 +0100892static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
893 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100894{
895 struct mv88e6xxx_hw_stat *stat;
896 int i, j;
897
898 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
899 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100900 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100901 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
902 ETH_GSTRING_LEN);
903 j++;
904 }
905 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100906
907 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100908}
909
Andrew Lunn436fe172018-03-01 02:02:29 +0100910static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
911 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100912{
Andrew Lunn436fe172018-03-01 02:02:29 +0100913 return mv88e6xxx_stats_get_strings(chip, data,
914 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100915}
916
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000917static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
918 uint8_t *data)
919{
920 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
921}
922
Andrew Lunn436fe172018-03-01 02:02:29 +0100923static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
924 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100925{
Andrew Lunn436fe172018-03-01 02:02:29 +0100926 return mv88e6xxx_stats_get_strings(chip, data,
927 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100928}
929
Andrew Lunn65f60e42018-03-28 23:50:28 +0200930static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
931 "atu_member_violation",
932 "atu_miss_violation",
933 "atu_full_violation",
934 "vtu_member_violation",
935 "vtu_miss_violation",
936};
937
938static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
939{
940 unsigned int i;
941
942 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
943 strlcpy(data + i * ETH_GSTRING_LEN,
944 mv88e6xxx_atu_vtu_stats_strings[i],
945 ETH_GSTRING_LEN);
946}
947
Andrew Lunndfafe442016-11-21 23:27:02 +0100948static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700949 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100950{
Vivien Didelot04bed142016-08-31 18:06:13 -0400951 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100952 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100953
Florian Fainelli89f09042018-04-25 12:12:50 -0700954 if (stringset != ETH_SS_STATS)
955 return;
956
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000957 mv88e6xxx_reg_lock(chip);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100958
Andrew Lunndfafe442016-11-21 23:27:02 +0100959 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100960 count = chip->info->ops->stats_get_strings(chip, data);
961
962 if (chip->info->ops->serdes_get_strings) {
963 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200964 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100965 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100966
Andrew Lunn65f60e42018-03-28 23:50:28 +0200967 data += count * ETH_GSTRING_LEN;
968 mv88e6xxx_atu_vtu_get_strings(data);
969
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000970 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100971}
972
973static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
974 int types)
975{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100976 struct mv88e6xxx_hw_stat *stat;
977 int i, j;
978
979 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
980 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100981 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100982 j++;
983 }
984 return j;
985}
986
Andrew Lunndfafe442016-11-21 23:27:02 +0100987static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
988{
989 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
990 STATS_TYPE_PORT);
991}
992
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000993static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
994{
995 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
996}
997
Andrew Lunndfafe442016-11-21 23:27:02 +0100998static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
999{
1000 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1001 STATS_TYPE_BANK1);
1002}
1003
Florian Fainelli89f09042018-04-25 12:12:50 -07001004static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +01001005{
1006 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +01001007 int serdes_count = 0;
1008 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +01001009
Florian Fainelli89f09042018-04-25 12:12:50 -07001010 if (sset != ETH_SS_STATS)
1011 return 0;
1012
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001013 mv88e6xxx_reg_lock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001014 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +01001015 count = chip->info->ops->stats_get_sset_count(chip);
1016 if (count < 0)
1017 goto out;
1018
1019 if (chip->info->ops->serdes_get_sset_count)
1020 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1021 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +02001022 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +01001023 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001024 goto out;
1025 }
1026 count += serdes_count;
1027 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1028
Andrew Lunn436fe172018-03-01 02:02:29 +01001029out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001030 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001031
Andrew Lunn436fe172018-03-01 02:02:29 +01001032 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +01001033}
1034
Andrew Lunn436fe172018-03-01 02:02:29 +01001035static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1036 uint64_t *data, int types,
1037 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +01001038{
1039 struct mv88e6xxx_hw_stat *stat;
1040 int i, j;
1041
1042 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1043 stat = &mv88e6xxx_hw_stats[i];
1044 if (stat->type & types) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001045 mv88e6xxx_reg_lock(chip);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001046 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1047 bank1_select,
1048 histogram);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001049 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001050
Andrew Lunn052f9472016-11-21 23:27:03 +01001051 j++;
1052 }
1053 }
Andrew Lunn436fe172018-03-01 02:02:29 +01001054 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +01001055}
1056
Andrew Lunn436fe172018-03-01 02:02:29 +01001057static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1058 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001059{
1060 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001061 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001062 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +01001063}
1064
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001065static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1066 uint64_t *data)
1067{
1068 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
1069 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1070}
1071
Andrew Lunn436fe172018-03-01 02:02:29 +01001072static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1073 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001074{
1075 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001076 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001077 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1078 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001079}
1080
Andrew Lunn436fe172018-03-01 02:02:29 +01001081static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1082 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +01001083{
1084 return mv88e6xxx_stats_get_stats(chip, port, data,
1085 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001086 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1087 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001088}
1089
Andrew Lunn65f60e42018-03-28 23:50:28 +02001090static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1091 uint64_t *data)
1092{
1093 *data++ = chip->ports[port].atu_member_violation;
1094 *data++ = chip->ports[port].atu_miss_violation;
1095 *data++ = chip->ports[port].atu_full_violation;
1096 *data++ = chip->ports[port].vtu_member_violation;
1097 *data++ = chip->ports[port].vtu_miss_violation;
1098}
1099
Andrew Lunn052f9472016-11-21 23:27:03 +01001100static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1101 uint64_t *data)
1102{
Andrew Lunn436fe172018-03-01 02:02:29 +01001103 int count = 0;
1104
Andrew Lunn052f9472016-11-21 23:27:03 +01001105 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +01001106 count = chip->info->ops->stats_get_stats(chip, port, data);
1107
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001108 mv88e6xxx_reg_lock(chip);
Andrew Lunn436fe172018-03-01 02:02:29 +01001109 if (chip->info->ops->serdes_get_stats) {
1110 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001111 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +01001112 }
Andrew Lunn65f60e42018-03-28 23:50:28 +02001113 data += count;
1114 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001115 mv88e6xxx_reg_unlock(chip);
Andrew Lunn052f9472016-11-21 23:27:03 +01001116}
1117
Vivien Didelotf81ec902016-05-09 13:22:58 -04001118static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1119 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001120{
Vivien Didelot04bed142016-08-31 18:06:13 -04001121 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001122 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001123
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001124 mv88e6xxx_reg_lock(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001125
Andrew Lunna605a0f2016-11-21 23:26:58 +01001126 ret = mv88e6xxx_stats_snapshot(chip, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001127 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001128
1129 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001130 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001131
1132 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001133
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001134}
Ben Hutchings98e67302011-11-25 14:36:19 +00001135
Vivien Didelotf81ec902016-05-09 13:22:58 -04001136static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001137{
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001138 struct mv88e6xxx_chip *chip = ds->priv;
1139 int len;
1140
1141 len = 32 * sizeof(u16);
1142 if (chip->info->ops->serdes_get_regs_len)
1143 len += chip->info->ops->serdes_get_regs_len(chip, port);
1144
1145 return len;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001146}
1147
Vivien Didelotf81ec902016-05-09 13:22:58 -04001148static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1149 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001150{
Vivien Didelot04bed142016-08-31 18:06:13 -04001151 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001152 int err;
1153 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001154 u16 *p = _p;
1155 int i;
1156
Vivien Didelota5f39322018-12-17 16:05:21 -05001157 regs->version = chip->info->prod_num;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001158
1159 memset(p, 0xff, 32 * sizeof(u16));
1160
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001161 mv88e6xxx_reg_lock(chip);
Vivien Didelot23062512016-05-09 13:22:45 -04001162
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001163 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001164
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001165 err = mv88e6xxx_port_read(chip, port, i, &reg);
1166 if (!err)
1167 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001168 }
Vivien Didelot23062512016-05-09 13:22:45 -04001169
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001170 if (chip->info->ops->serdes_get_regs)
1171 chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1172
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001173 mv88e6xxx_reg_unlock(chip);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001174}
1175
Vivien Didelot08f50062017-08-01 16:32:41 -04001176static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1177 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001178{
Vivien Didelot5480db62017-08-01 16:32:40 -04001179 /* Nothing to do on the port's MAC */
1180 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001181}
1182
Vivien Didelot08f50062017-08-01 16:32:41 -04001183static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1184 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001185{
Vivien Didelot5480db62017-08-01 16:32:40 -04001186 /* Nothing to do on the port's MAC */
1187 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001188}
1189
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001190/* Mask of the local ports allowed to receive frames from a given fabric port */
Vivien Didelote5887a22017-03-30 17:37:11 -04001191static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001192{
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001193 struct dsa_switch *ds = chip->ds;
1194 struct dsa_switch_tree *dst = ds->dst;
Vivien Didelote5887a22017-03-30 17:37:11 -04001195 struct net_device *br;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001196 struct dsa_port *dp;
1197 bool found = false;
Vivien Didelote5887a22017-03-30 17:37:11 -04001198 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001199
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001200 list_for_each_entry(dp, &dst->ports, list) {
1201 if (dp->ds->index == dev && dp->index == port) {
1202 found = true;
1203 break;
1204 }
1205 }
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001206
Vivien Didelote5887a22017-03-30 17:37:11 -04001207 /* Prevent frames from unknown switch or port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001208 if (!found)
Vivien Didelote5887a22017-03-30 17:37:11 -04001209 return 0;
1210
1211 /* Frames from DSA links and CPU ports can egress any local port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001212 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
Vivien Didelote5887a22017-03-30 17:37:11 -04001213 return mv88e6xxx_port_mask(chip);
1214
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001215 br = dp->bridge_dev;
Vivien Didelote5887a22017-03-30 17:37:11 -04001216 pvlan = 0;
1217
1218 /* Frames from user ports can egress any local DSA links and CPU ports,
1219 * as well as any local member of their bridge group.
1220 */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001221 list_for_each_entry(dp, &dst->ports, list)
1222 if (dp->ds == ds &&
1223 (dp->type == DSA_PORT_TYPE_CPU ||
1224 dp->type == DSA_PORT_TYPE_DSA ||
1225 (br && dp->bridge_dev == br)))
1226 pvlan |= BIT(dp->index);
Vivien Didelote5887a22017-03-30 17:37:11 -04001227
1228 return pvlan;
1229}
1230
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001231static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001232{
1233 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001234
1235 /* prevent frames from going back out of the port they came in on */
1236 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001237
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001238 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001239}
1240
Vivien Didelotf81ec902016-05-09 13:22:58 -04001241static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1242 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001243{
Vivien Didelot04bed142016-08-31 18:06:13 -04001244 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001245 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001246
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001247 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001248 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001249 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001250
1251 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001252 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001253}
1254
Vivien Didelot93e18d62018-05-11 17:16:35 -04001255static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1256{
1257 int err;
1258
1259 if (chip->info->ops->ieee_pri_map) {
1260 err = chip->info->ops->ieee_pri_map(chip);
1261 if (err)
1262 return err;
1263 }
1264
1265 if (chip->info->ops->ip_pri_map) {
1266 err = chip->info->ops->ip_pri_map(chip);
1267 if (err)
1268 return err;
1269 }
1270
1271 return 0;
1272}
1273
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001274static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1275{
Vivien Didelotc5f51762019-10-30 22:09:13 -04001276 struct dsa_switch *ds = chip->ds;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001277 int target, port;
1278 int err;
1279
1280 if (!chip->info->global2_addr)
1281 return 0;
1282
1283 /* Initialize the routing port to the 32 possible target devices */
1284 for (target = 0; target < 32; target++) {
Vivien Didelotc5f51762019-10-30 22:09:13 -04001285 port = dsa_routing_port(ds, target);
1286 if (port == ds->num_ports)
1287 port = 0x1f;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001288
1289 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1290 if (err)
1291 return err;
1292 }
1293
Vivien Didelot02317e62018-05-09 11:38:49 -04001294 if (chip->info->ops->set_cascade_port) {
1295 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1296 err = chip->info->ops->set_cascade_port(chip, port);
1297 if (err)
1298 return err;
1299 }
1300
Vivien Didelot23c98912018-05-09 11:38:50 -04001301 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1302 if (err)
1303 return err;
1304
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001305 return 0;
1306}
1307
Vivien Didelotb28f8722018-04-26 21:56:44 -04001308static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1309{
1310 /* Clear all trunk masks and mapping */
1311 if (chip->info->global2_addr)
1312 return mv88e6xxx_g2_trunk_clear(chip);
1313
1314 return 0;
1315}
1316
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001317static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1318{
1319 if (chip->info->ops->rmu_disable)
1320 return chip->info->ops->rmu_disable(chip);
1321
1322 return 0;
1323}
1324
Vivien Didelot9e907d72017-07-17 13:03:43 -04001325static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1326{
1327 if (chip->info->ops->pot_clear)
1328 return chip->info->ops->pot_clear(chip);
1329
1330 return 0;
1331}
1332
Vivien Didelot51c901a2017-07-17 13:03:41 -04001333static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1334{
1335 if (chip->info->ops->mgmt_rsvd2cpu)
1336 return chip->info->ops->mgmt_rsvd2cpu(chip);
1337
1338 return 0;
1339}
1340
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001341static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1342{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001343 int err;
1344
Vivien Didelotdaefc942017-03-11 16:12:54 -05001345 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1346 if (err)
1347 return err;
1348
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001349 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1350 if (err)
1351 return err;
1352
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001353 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1354}
1355
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001356static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1357{
1358 int port;
1359 int err;
1360
1361 if (!chip->info->ops->irl_init_all)
1362 return 0;
1363
1364 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1365 /* Disable ingress rate limiting by resetting all per port
1366 * ingress rate limit resources to their initial state.
1367 */
1368 err = chip->info->ops->irl_init_all(chip, port);
1369 if (err)
1370 return err;
1371 }
1372
1373 return 0;
1374}
1375
Vivien Didelot04a69a12017-10-13 14:18:05 -04001376static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1377{
1378 if (chip->info->ops->set_switch_mac) {
1379 u8 addr[ETH_ALEN];
1380
1381 eth_random_addr(addr);
1382
1383 return chip->info->ops->set_switch_mac(chip, addr);
1384 }
1385
1386 return 0;
1387}
1388
Vivien Didelot17a15942017-03-30 17:37:09 -04001389static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1390{
1391 u16 pvlan = 0;
1392
1393 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001394 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001395
1396 /* Skip the local source device, which uses in-chip port VLAN */
1397 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001398 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001399
1400 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1401}
1402
Vivien Didelot81228992017-03-30 17:37:08 -04001403static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1404{
Vivien Didelot17a15942017-03-30 17:37:09 -04001405 int dev, port;
1406 int err;
1407
Vivien Didelot81228992017-03-30 17:37:08 -04001408 if (!mv88e6xxx_has_pvt(chip))
1409 return 0;
1410
1411 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1412 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1413 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001414 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1415 if (err)
1416 return err;
1417
1418 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1419 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1420 err = mv88e6xxx_pvt_map(chip, dev, port);
1421 if (err)
1422 return err;
1423 }
1424 }
1425
1426 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001427}
1428
Vivien Didelot749efcb2016-09-22 16:49:24 -04001429static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1430{
1431 struct mv88e6xxx_chip *chip = ds->priv;
1432 int err;
1433
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001434 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001435 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001436 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001437
1438 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001439 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001440}
1441
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001442static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1443{
1444 if (!chip->info->max_vid)
1445 return 0;
1446
1447 return mv88e6xxx_g1_vtu_flush(chip);
1448}
1449
Vivien Didelotf1394b782017-05-01 14:05:22 -04001450static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1451 struct mv88e6xxx_vtu_entry *entry)
1452{
1453 if (!chip->info->ops->vtu_getnext)
1454 return -EOPNOTSUPP;
1455
1456 return chip->info->ops->vtu_getnext(chip, entry);
1457}
1458
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001459static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1460 struct mv88e6xxx_vtu_entry *entry)
1461{
1462 if (!chip->info->ops->vtu_loadpurge)
1463 return -EOPNOTSUPP;
1464
1465 return chip->info->ops->vtu_loadpurge(chip, entry);
1466}
1467
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001468static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001469{
1470 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot425d2d32019-08-01 14:36:34 -04001471 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001472 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001473
1474 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1475
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001476 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001477 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001478 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001479 if (err)
1480 return err;
1481
1482 set_bit(*fid, fid_bitmap);
1483 }
1484
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001485 /* Set every FID bit used by the VLAN entries */
Vivien Didelot425d2d32019-08-01 14:36:34 -04001486 vlan.vid = chip->info->max_vid;
1487 vlan.valid = false;
1488
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001489 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001490 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001491 if (err)
1492 return err;
1493
1494 if (!vlan.valid)
1495 break;
1496
1497 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001498 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001499
1500 /* The reset value 0x000 is used to indicate that multiple address
1501 * databases are not needed. Return the next positive available.
1502 */
1503 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001504 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001505 return -ENOSPC;
1506
1507 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001508 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001509}
1510
Andrew Lunn23e8b472019-10-25 01:03:52 +02001511static int mv88e6xxx_atu_get_hash(struct mv88e6xxx_chip *chip, u8 *hash)
1512{
1513 if (chip->info->ops->atu_get_hash)
1514 return chip->info->ops->atu_get_hash(chip, hash);
1515
1516 return -EOPNOTSUPP;
1517}
1518
1519static int mv88e6xxx_atu_set_hash(struct mv88e6xxx_chip *chip, u8 hash)
1520{
1521 if (chip->info->ops->atu_set_hash)
1522 return chip->info->ops->atu_set_hash(chip, hash);
1523
1524 return -EOPNOTSUPP;
1525}
1526
Vivien Didelotda9c3592016-02-12 12:09:40 -05001527static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1528 u16 vid_begin, u16 vid_end)
1529{
Vivien Didelot04bed142016-08-31 18:06:13 -04001530 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001531 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001532 int i, err;
1533
Andrew Lunndb06ae412017-09-25 23:32:20 +02001534 /* DSA and CPU ports have to be members of multiple vlans */
1535 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1536 return 0;
1537
Vivien Didelotda9c3592016-02-12 12:09:40 -05001538 if (!vid_begin)
1539 return -EOPNOTSUPP;
1540
Vivien Didelot425d2d32019-08-01 14:36:34 -04001541 vlan.vid = vid_begin - 1;
1542 vlan.valid = false;
1543
Vivien Didelotda9c3592016-02-12 12:09:40 -05001544 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001545 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001546 if (err)
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001547 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001548
1549 if (!vlan.valid)
1550 break;
1551
1552 if (vlan.vid > vid_end)
1553 break;
1554
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001555 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001556 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1557 continue;
1558
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001559 if (!dsa_to_port(ds, i)->slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001560 continue;
1561
Vivien Didelotbd00e052017-05-01 14:05:11 -04001562 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001563 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001564 continue;
1565
Vivien Didelotc8652c82017-10-16 11:12:19 -04001566 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001567 dsa_to_port(ds, port)->bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001568 break; /* same bridge, check next VLAN */
1569
Vivien Didelotc8652c82017-10-16 11:12:19 -04001570 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001571 continue;
1572
Andrew Lunn743fcc22017-11-09 22:29:54 +01001573 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1574 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001575 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001576 return -EOPNOTSUPP;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001577 }
1578 } while (vlan.vid < vid_end);
1579
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001580 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001581}
1582
Vivien Didelotf81ec902016-05-09 13:22:58 -04001583static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1584 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001585{
Vivien Didelot04bed142016-08-31 18:06:13 -04001586 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001587 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1588 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001589 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001590
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001591 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001592 return -EOPNOTSUPP;
1593
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001594 mv88e6xxx_reg_lock(chip);
Vivien Didelot385a0992016-11-04 03:23:31 +01001595 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001596 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001597
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001598 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001599}
1600
Vivien Didelot57d32312016-06-20 13:13:58 -04001601static int
1602mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001603 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001604{
Vivien Didelot04bed142016-08-31 18:06:13 -04001605 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001606 int err;
1607
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001608 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001609 return -EOPNOTSUPP;
1610
Vivien Didelotda9c3592016-02-12 12:09:40 -05001611 /* If the requested port doesn't belong to the same bridge as the VLAN
1612 * members, do not support it (yet) and fallback to software VLAN.
1613 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001614 mv88e6xxx_reg_lock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001615 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1616 vlan->vid_end);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001617 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001618
Vivien Didelot76e398a2015-11-01 12:33:55 -05001619 /* We don't need any dynamic resource from the kernel (yet),
1620 * so skip the prepare phase.
1621 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001622 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001623}
1624
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001625static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1626 const unsigned char *addr, u16 vid,
1627 u8 state)
1628{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001629 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001630 struct mv88e6xxx_vtu_entry vlan;
1631 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001632 int err;
1633
1634 /* Null VLAN ID corresponds to the port private database */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001635 if (vid == 0) {
1636 err = mv88e6xxx_port_get_fid(chip, port, &fid);
1637 if (err)
1638 return err;
1639 } else {
1640 vlan.vid = vid - 1;
1641 vlan.valid = false;
1642
1643 err = mv88e6xxx_vtu_getnext(chip, &vlan);
1644 if (err)
1645 return err;
1646
1647 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1648 if (vlan.vid != vid || !vlan.valid)
1649 return -EOPNOTSUPP;
1650
1651 fid = vlan.fid;
1652 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001653
Vivien Didelotd8291a92019-09-07 16:00:47 -04001654 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001655 ether_addr_copy(entry.mac, addr);
1656 eth_addr_dec(entry.mac);
1657
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001658 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001659 if (err)
1660 return err;
1661
1662 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001663 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001664 memset(&entry, 0, sizeof(entry));
1665 ether_addr_copy(entry.mac, addr);
1666 }
1667
1668 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001669 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001670 entry.portvec &= ~BIT(port);
1671 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001672 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001673 } else {
1674 entry.portvec |= BIT(port);
1675 entry.state = state;
1676 }
1677
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001678 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001679}
1680
Vivien Didelotda7dc872019-09-07 16:00:49 -04001681static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1682 const struct mv88e6xxx_policy *policy)
1683{
1684 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1685 enum mv88e6xxx_policy_action action = policy->action;
1686 const u8 *addr = policy->addr;
1687 u16 vid = policy->vid;
1688 u8 state;
1689 int err;
1690 int id;
1691
1692 if (!chip->info->ops->port_set_policy)
1693 return -EOPNOTSUPP;
1694
1695 switch (mapping) {
1696 case MV88E6XXX_POLICY_MAPPING_DA:
1697 case MV88E6XXX_POLICY_MAPPING_SA:
1698 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1699 state = 0; /* Dissociate the port and address */
1700 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1701 is_multicast_ether_addr(addr))
1702 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1703 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1704 is_unicast_ether_addr(addr))
1705 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1706 else
1707 return -EOPNOTSUPP;
1708
1709 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1710 state);
1711 if (err)
1712 return err;
1713 break;
1714 default:
1715 return -EOPNOTSUPP;
1716 }
1717
1718 /* Skip the port's policy clearing if the mapping is still in use */
1719 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1720 idr_for_each_entry(&chip->policies, policy, id)
1721 if (policy->port == port &&
1722 policy->mapping == mapping &&
1723 policy->action != action)
1724 return 0;
1725
1726 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1727}
1728
1729static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1730 struct ethtool_rx_flow_spec *fs)
1731{
1732 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1733 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1734 enum mv88e6xxx_policy_mapping mapping;
1735 enum mv88e6xxx_policy_action action;
1736 struct mv88e6xxx_policy *policy;
1737 u16 vid = 0;
1738 u8 *addr;
1739 int err;
1740 int id;
1741
1742 if (fs->location != RX_CLS_LOC_ANY)
1743 return -EINVAL;
1744
1745 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1746 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1747 else
1748 return -EOPNOTSUPP;
1749
1750 switch (fs->flow_type & ~FLOW_EXT) {
1751 case ETHER_FLOW:
1752 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1753 is_zero_ether_addr(mac_mask->h_source)) {
1754 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1755 addr = mac_entry->h_dest;
1756 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1757 !is_zero_ether_addr(mac_mask->h_source)) {
1758 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1759 addr = mac_entry->h_source;
1760 } else {
1761 /* Cannot support DA and SA mapping in the same rule */
1762 return -EOPNOTSUPP;
1763 }
1764 break;
1765 default:
1766 return -EOPNOTSUPP;
1767 }
1768
1769 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001770 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001771 return -EOPNOTSUPP;
1772 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1773 }
1774
1775 idr_for_each_entry(&chip->policies, policy, id) {
1776 if (policy->port == port && policy->mapping == mapping &&
1777 policy->action == action && policy->vid == vid &&
1778 ether_addr_equal(policy->addr, addr))
1779 return -EEXIST;
1780 }
1781
1782 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1783 if (!policy)
1784 return -ENOMEM;
1785
1786 fs->location = 0;
1787 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1788 GFP_KERNEL);
1789 if (err) {
1790 devm_kfree(chip->dev, policy);
1791 return err;
1792 }
1793
1794 memcpy(&policy->fs, fs, sizeof(*fs));
1795 ether_addr_copy(policy->addr, addr);
1796 policy->mapping = mapping;
1797 policy->action = action;
1798 policy->port = port;
1799 policy->vid = vid;
1800
1801 err = mv88e6xxx_policy_apply(chip, port, policy);
1802 if (err) {
1803 idr_remove(&chip->policies, fs->location);
1804 devm_kfree(chip->dev, policy);
1805 return err;
1806 }
1807
1808 return 0;
1809}
1810
1811static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1812 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1813{
1814 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1815 struct mv88e6xxx_chip *chip = ds->priv;
1816 struct mv88e6xxx_policy *policy;
1817 int err;
1818 int id;
1819
1820 mv88e6xxx_reg_lock(chip);
1821
1822 switch (rxnfc->cmd) {
1823 case ETHTOOL_GRXCLSRLCNT:
1824 rxnfc->data = 0;
1825 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1826 rxnfc->rule_cnt = 0;
1827 idr_for_each_entry(&chip->policies, policy, id)
1828 if (policy->port == port)
1829 rxnfc->rule_cnt++;
1830 err = 0;
1831 break;
1832 case ETHTOOL_GRXCLSRULE:
1833 err = -ENOENT;
1834 policy = idr_find(&chip->policies, fs->location);
1835 if (policy) {
1836 memcpy(fs, &policy->fs, sizeof(*fs));
1837 err = 0;
1838 }
1839 break;
1840 case ETHTOOL_GRXCLSRLALL:
1841 rxnfc->data = 0;
1842 rxnfc->rule_cnt = 0;
1843 idr_for_each_entry(&chip->policies, policy, id)
1844 if (policy->port == port)
1845 rule_locs[rxnfc->rule_cnt++] = id;
1846 err = 0;
1847 break;
1848 default:
1849 err = -EOPNOTSUPP;
1850 break;
1851 }
1852
1853 mv88e6xxx_reg_unlock(chip);
1854
1855 return err;
1856}
1857
1858static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1859 struct ethtool_rxnfc *rxnfc)
1860{
1861 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1862 struct mv88e6xxx_chip *chip = ds->priv;
1863 struct mv88e6xxx_policy *policy;
1864 int err;
1865
1866 mv88e6xxx_reg_lock(chip);
1867
1868 switch (rxnfc->cmd) {
1869 case ETHTOOL_SRXCLSRLINS:
1870 err = mv88e6xxx_policy_insert(chip, port, fs);
1871 break;
1872 case ETHTOOL_SRXCLSRLDEL:
1873 err = -ENOENT;
1874 policy = idr_remove(&chip->policies, fs->location);
1875 if (policy) {
1876 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
1877 err = mv88e6xxx_policy_apply(chip, port, policy);
1878 devm_kfree(chip->dev, policy);
1879 }
1880 break;
1881 default:
1882 err = -EOPNOTSUPP;
1883 break;
1884 }
1885
1886 mv88e6xxx_reg_unlock(chip);
1887
1888 return err;
1889}
1890
Andrew Lunn87fa8862017-11-09 22:29:56 +01001891static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1892 u16 vid)
1893{
1894 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1895 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1896
1897 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1898}
1899
1900static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1901{
1902 int port;
1903 int err;
1904
1905 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1906 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1907 if (err)
1908 return err;
1909 }
1910
1911 return 0;
1912}
1913
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001914static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00001915 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001916{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001917 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001918 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001919 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001920
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001921 if (!vid)
1922 return -EOPNOTSUPP;
1923
1924 vlan.vid = vid - 1;
1925 vlan.valid = false;
1926
1927 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001928 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001929 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001930
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001931 if (vlan.vid != vid || !vlan.valid) {
1932 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001933
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001934 err = mv88e6xxx_atu_new(chip, &vlan.fid);
1935 if (err)
1936 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01001937
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001938 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1939 if (i == port)
1940 vlan.member[i] = member;
1941 else
1942 vlan.member[i] = non_member;
1943
1944 vlan.vid = vid;
1945 vlan.valid = true;
1946
1947 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1948 if (err)
1949 return err;
1950
1951 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
1952 if (err)
1953 return err;
1954 } else if (vlan.member[port] != member) {
1955 vlan.member[port] = member;
1956
1957 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1958 if (err)
1959 return err;
Russell King933b4422020-02-26 17:14:26 +00001960 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001961 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
1962 port, vid);
1963 }
1964
1965 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001966}
1967
Vivien Didelotf81ec902016-05-09 13:22:58 -04001968static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001969 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001970{
Vivien Didelot04bed142016-08-31 18:06:13 -04001971 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001972 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1973 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Russell King933b4422020-02-26 17:14:26 +00001974 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001975 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001976 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001977
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001978 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001979 return;
1980
Vivien Didelotc91498e2017-06-07 18:12:13 -04001981 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001982 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001983 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001984 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001985 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001986 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001987
Russell King933b4422020-02-26 17:14:26 +00001988 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
1989 * and then the CPU port. Do not warn for duplicates for the CPU port.
1990 */
1991 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
1992
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001993 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001994
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001995 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Russell King933b4422020-02-26 17:14:26 +00001996 if (mv88e6xxx_port_vlan_join(chip, port, vid, member, warn))
Vivien Didelot774439e52017-06-08 18:34:08 -04001997 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1998 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001999
Vivien Didelot77064f32016-11-04 03:23:30 +01002000 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04002001 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
2002 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04002003
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002004 mv88e6xxx_reg_unlock(chip);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002005}
2006
Vivien Didelot521098922019-08-01 14:36:36 -04002007static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2008 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002009{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002010 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002011 int i, err;
2012
Vivien Didelot521098922019-08-01 14:36:36 -04002013 if (!vid)
2014 return -EOPNOTSUPP;
2015
2016 vlan.vid = vid - 1;
2017 vlan.valid = false;
2018
2019 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002020 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002021 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002022
Vivien Didelot521098922019-08-01 14:36:36 -04002023 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2024 * tell switchdev that this VLAN is likely handled in software.
2025 */
2026 if (vlan.vid != vid || !vlan.valid ||
2027 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002028 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002029
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002030 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002031
2032 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002033 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002034 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002035 if (vlan.member[i] !=
2036 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002037 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002038 break;
2039 }
2040 }
2041
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002042 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002043 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002044 return err;
2045
Vivien Didelote606ca32017-03-11 16:12:55 -05002046 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002047}
2048
Vivien Didelotf81ec902016-05-09 13:22:58 -04002049static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2050 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002051{
Vivien Didelot04bed142016-08-31 18:06:13 -04002052 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002053 u16 pvid, vid;
2054 int err = 0;
2055
Vivien Didelot3cf3c842017-05-01 14:05:10 -04002056 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04002057 return -EOPNOTSUPP;
2058
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002059 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002060
Vivien Didelot77064f32016-11-04 03:23:30 +01002061 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002062 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002063 goto unlock;
2064
Vivien Didelot76e398a2015-11-01 12:33:55 -05002065 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelot521098922019-08-01 14:36:36 -04002066 err = mv88e6xxx_port_vlan_leave(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002067 if (err)
2068 goto unlock;
2069
2070 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01002071 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002072 if (err)
2073 goto unlock;
2074 }
2075 }
2076
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002077unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002078 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002079
2080 return err;
2081}
2082
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002083static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2084 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002085{
Vivien Didelot04bed142016-08-31 18:06:13 -04002086 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002087 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002088
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002089 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002090 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2091 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002092 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002093
2094 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002095}
2096
Vivien Didelotf81ec902016-05-09 13:22:58 -04002097static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002098 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002099{
Vivien Didelot04bed142016-08-31 18:06:13 -04002100 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002101 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002102
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002103 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002104 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002105 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002106
Vivien Didelot83dabd12016-08-31 11:50:04 -04002107 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002108}
2109
Vivien Didelot83dabd12016-08-31 11:50:04 -04002110static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2111 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002112 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002113{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002114 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002115 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002116 int err;
2117
Vivien Didelotd8291a92019-09-07 16:00:47 -04002118 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002119 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002120
2121 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002122 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002123 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002124 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002125
Vivien Didelotd8291a92019-09-07 16:00:47 -04002126 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002127 break;
2128
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002129 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002130 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002131
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002132 if (!is_unicast_ether_addr(addr.mac))
2133 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002134
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002135 is_static = (addr.state ==
2136 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2137 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002138 if (err)
2139 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002140 } while (!is_broadcast_ether_addr(addr.mac));
2141
2142 return err;
2143}
2144
Vivien Didelot83dabd12016-08-31 11:50:04 -04002145static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002146 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002147{
Vivien Didelot425d2d32019-08-01 14:36:34 -04002148 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002149 u16 fid;
2150 int err;
2151
2152 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002153 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002154 if (err)
2155 return err;
2156
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002157 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002158 if (err)
2159 return err;
2160
2161 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot425d2d32019-08-01 14:36:34 -04002162 vlan.vid = chip->info->max_vid;
2163 vlan.valid = false;
2164
Vivien Didelot83dabd12016-08-31 11:50:04 -04002165 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04002166 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002167 if (err)
2168 return err;
2169
2170 if (!vlan.valid)
2171 break;
2172
2173 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002174 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002175 if (err)
2176 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04002177 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002178
2179 return err;
2180}
2181
Vivien Didelotf81ec902016-05-09 13:22:58 -04002182static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002183 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002184{
Vivien Didelot04bed142016-08-31 18:06:13 -04002185 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002186 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002187
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002188 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002189 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002190 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002191
2192 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002193}
2194
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002195static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2196 struct net_device *br)
2197{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002198 struct dsa_switch *ds = chip->ds;
2199 struct dsa_switch_tree *dst = ds->dst;
2200 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002201 int err;
2202
Vivien Didelotef2025e2019-10-21 16:51:27 -04002203 list_for_each_entry(dp, &dst->ports, list) {
2204 if (dp->bridge_dev == br) {
2205 if (dp->ds == ds) {
2206 /* This is a local bridge group member,
2207 * remap its Port VLAN Map.
2208 */
2209 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2210 if (err)
2211 return err;
2212 } else {
2213 /* This is an external bridge group member,
2214 * remap its cross-chip Port VLAN Table entry.
2215 */
2216 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2217 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002218 if (err)
2219 return err;
2220 }
2221 }
2222 }
2223
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002224 return 0;
2225}
2226
Vivien Didelotf81ec902016-05-09 13:22:58 -04002227static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002228 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002229{
Vivien Didelot04bed142016-08-31 18:06:13 -04002230 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002231 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002232
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002233 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002234 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002235 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002236
Vivien Didelot466dfa02016-02-26 13:16:05 -05002237 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002238}
2239
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002240static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2241 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002242{
Vivien Didelot04bed142016-08-31 18:06:13 -04002243 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002244
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002245 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002246 if (mv88e6xxx_bridge_map(chip, br) ||
2247 mv88e6xxx_port_vlan_map(chip, port))
2248 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002249 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002250}
2251
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002252static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2253 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002254 int port, struct net_device *br)
2255{
2256 struct mv88e6xxx_chip *chip = ds->priv;
2257 int err;
2258
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002259 if (tree_index != ds->dst->index)
2260 return 0;
2261
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002262 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002263 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002264 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002265
2266 return err;
2267}
2268
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002269static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2270 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002271 int port, struct net_device *br)
2272{
2273 struct mv88e6xxx_chip *chip = ds->priv;
2274
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002275 if (tree_index != ds->dst->index)
2276 return;
2277
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002278 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002279 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002280 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002281 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002282}
2283
Vivien Didelot17e708b2016-12-05 17:30:27 -05002284static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2285{
2286 if (chip->info->ops->reset)
2287 return chip->info->ops->reset(chip);
2288
2289 return 0;
2290}
2291
Vivien Didelot309eca62016-12-05 17:30:26 -05002292static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2293{
2294 struct gpio_desc *gpiod = chip->reset;
2295
2296 /* If there is a GPIO connected to the reset pin, toggle it */
2297 if (gpiod) {
2298 gpiod_set_value_cansleep(gpiod, 1);
2299 usleep_range(10000, 20000);
2300 gpiod_set_value_cansleep(gpiod, 0);
2301 usleep_range(10000, 20000);
2302 }
2303}
2304
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002305static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2306{
2307 int i, err;
2308
2309 /* Set all ports to the Disabled state */
2310 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002311 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002312 if (err)
2313 return err;
2314 }
2315
2316 /* Wait for transmit queues to drain,
2317 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2318 */
2319 usleep_range(2000, 4000);
2320
2321 return 0;
2322}
2323
Vivien Didelotfad09c72016-06-21 12:28:20 -04002324static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002325{
Vivien Didelota935c052016-09-29 12:21:53 -04002326 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002327
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002328 err = mv88e6xxx_disable_ports(chip);
2329 if (err)
2330 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002331
Vivien Didelot309eca62016-12-05 17:30:26 -05002332 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002333
Vivien Didelot17e708b2016-12-05 17:30:27 -05002334 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002335}
2336
Vivien Didelot43145572017-03-11 16:12:59 -05002337static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002338 enum mv88e6xxx_frame_mode frame,
2339 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002340{
2341 int err;
2342
Vivien Didelot43145572017-03-11 16:12:59 -05002343 if (!chip->info->ops->port_set_frame_mode)
2344 return -EOPNOTSUPP;
2345
2346 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002347 if (err)
2348 return err;
2349
Vivien Didelot43145572017-03-11 16:12:59 -05002350 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2351 if (err)
2352 return err;
2353
2354 if (chip->info->ops->port_set_ether_type)
2355 return chip->info->ops->port_set_ether_type(chip, port, etype);
2356
2357 return 0;
2358}
2359
2360static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2361{
2362 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002363 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002364 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002365}
2366
2367static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2368{
2369 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002370 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002371 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002372}
2373
2374static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2375{
2376 return mv88e6xxx_set_port_mode(chip, port,
2377 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002378 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2379 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002380}
2381
2382static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2383{
2384 if (dsa_is_dsa_port(chip->ds, port))
2385 return mv88e6xxx_set_port_mode_dsa(chip, port);
2386
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002387 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002388 return mv88e6xxx_set_port_mode_normal(chip, port);
2389
2390 /* Setup CPU port mode depending on its supported tag format */
2391 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2392 return mv88e6xxx_set_port_mode_dsa(chip, port);
2393
2394 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2395 return mv88e6xxx_set_port_mode_edsa(chip, port);
2396
2397 return -EINVAL;
2398}
2399
Vivien Didelotea698f42017-03-11 16:12:50 -05002400static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2401{
2402 bool message = dsa_is_dsa_port(chip->ds, port);
2403
2404 return mv88e6xxx_port_set_message_port(chip, port, message);
2405}
2406
Vivien Didelot601aeed2017-03-11 16:13:00 -05002407static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2408{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002409 struct dsa_switch *ds = chip->ds;
David S. Miller407308f2019-06-15 13:35:29 -07002410 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002411
David S. Miller407308f2019-06-15 13:35:29 -07002412 /* Upstream ports flood frames with unknown unicast or multicast DA */
2413 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2414 if (chip->info->ops->port_set_egress_floods)
2415 return chip->info->ops->port_set_egress_floods(chip, port,
2416 flood, flood);
Vivien Didelot601aeed2017-03-11 16:13:00 -05002417
David S. Miller407308f2019-06-15 13:35:29 -07002418 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002419}
2420
Vivien Didelot45de77f2019-08-31 16:18:36 -04002421static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2422{
2423 struct mv88e6xxx_port *mvp = dev_id;
2424 struct mv88e6xxx_chip *chip = mvp->chip;
2425 irqreturn_t ret = IRQ_NONE;
2426 int port = mvp->port;
2427 u8 lane;
2428
2429 mv88e6xxx_reg_lock(chip);
2430 lane = mv88e6xxx_serdes_get_lane(chip, port);
2431 if (lane)
2432 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2433 mv88e6xxx_reg_unlock(chip);
2434
2435 return ret;
2436}
2437
2438static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
2439 u8 lane)
2440{
2441 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2442 unsigned int irq;
2443 int err;
2444
2445 /* Nothing to request if this SERDES port has no IRQ */
2446 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2447 if (!irq)
2448 return 0;
2449
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002450 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2451 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2452
Vivien Didelot45de77f2019-08-31 16:18:36 -04002453 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2454 mv88e6xxx_reg_unlock(chip);
2455 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002456 IRQF_ONESHOT, dev_id->serdes_irq_name,
2457 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002458 mv88e6xxx_reg_lock(chip);
2459 if (err)
2460 return err;
2461
2462 dev_id->serdes_irq = irq;
2463
2464 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2465}
2466
2467static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
2468 u8 lane)
2469{
2470 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2471 unsigned int irq = dev_id->serdes_irq;
2472 int err;
2473
2474 /* Nothing to free if no IRQ has been requested */
2475 if (!irq)
2476 return 0;
2477
2478 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2479
2480 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2481 mv88e6xxx_reg_unlock(chip);
2482 free_irq(irq, dev_id);
2483 mv88e6xxx_reg_lock(chip);
2484
2485 dev_id->serdes_irq = 0;
2486
2487 return err;
2488}
2489
Andrew Lunn6d917822017-05-26 01:03:21 +02002490static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2491 bool on)
2492{
Vivien Didelotdc272f62019-08-31 16:18:33 -04002493 u8 lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002494 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002495
Vivien Didelotdc272f62019-08-31 16:18:33 -04002496 lane = mv88e6xxx_serdes_get_lane(chip, port);
2497 if (!lane)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002498 return 0;
2499
2500 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002501 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002502 if (err)
2503 return err;
2504
Vivien Didelot45de77f2019-08-31 16:18:36 -04002505 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002506 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002507 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2508 if (err)
2509 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002510
Vivien Didelotdc272f62019-08-31 16:18:33 -04002511 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002512 }
2513
2514 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002515}
2516
Vivien Didelotfa371c82017-12-05 15:34:10 -05002517static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2518{
2519 struct dsa_switch *ds = chip->ds;
2520 int upstream_port;
2521 int err;
2522
Vivien Didelot07073c72017-12-05 15:34:13 -05002523 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002524 if (chip->info->ops->port_set_upstream_port) {
2525 err = chip->info->ops->port_set_upstream_port(chip, port,
2526 upstream_port);
2527 if (err)
2528 return err;
2529 }
2530
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002531 if (port == upstream_port) {
2532 if (chip->info->ops->set_cpu_port) {
2533 err = chip->info->ops->set_cpu_port(chip,
2534 upstream_port);
2535 if (err)
2536 return err;
2537 }
2538
2539 if (chip->info->ops->set_egress_port) {
2540 err = chip->info->ops->set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002541 MV88E6XXX_EGRESS_DIR_INGRESS,
2542 upstream_port);
2543 if (err)
2544 return err;
2545
2546 err = chip->info->ops->set_egress_port(chip,
2547 MV88E6XXX_EGRESS_DIR_EGRESS,
2548 upstream_port);
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002549 if (err)
2550 return err;
2551 }
2552 }
2553
Vivien Didelotfa371c82017-12-05 15:34:10 -05002554 return 0;
2555}
2556
Vivien Didelotfad09c72016-06-21 12:28:20 -04002557static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002558{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002559 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002560 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002561 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002562
Andrew Lunn7b898462018-08-09 15:38:47 +02002563 chip->ports[port].chip = chip;
2564 chip->ports[port].port = port;
2565
Vivien Didelotd78343d2016-11-04 03:23:36 +01002566 /* MAC Forcing register: don't force link, speed, duplex or flow control
2567 * state to any particular values on physical ports, but force the CPU
2568 * port and all DSA ports to their maximum bandwidth and full duplex.
2569 */
2570 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2571 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2572 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002573 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002574 PHY_INTERFACE_MODE_NA);
2575 else
2576 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2577 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002578 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002579 PHY_INTERFACE_MODE_NA);
2580 if (err)
2581 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002582
2583 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2584 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2585 * tunneling, determine priority by looking at 802.1p and IP
2586 * priority fields (IP prio has precedence), and set STP state
2587 * to Forwarding.
2588 *
2589 * If this is the CPU link, use DSA or EDSA tagging depending
2590 * on which tagging mode was configured.
2591 *
2592 * If this is a link to another switch, use DSA tagging mode.
2593 *
2594 * If this is the upstream port for this switch, enable
2595 * forwarding of unknown unicasts and multicasts.
2596 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002597 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2598 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2599 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2600 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002601 if (err)
2602 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002603
Vivien Didelot601aeed2017-03-11 16:13:00 -05002604 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002605 if (err)
2606 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002607
Vivien Didelot601aeed2017-03-11 16:13:00 -05002608 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002609 if (err)
2610 return err;
2611
Vivien Didelot8efdda42015-08-13 12:52:23 -04002612 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002613 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002614 * untagged frames on this port, do a destination address lookup on all
2615 * received packets as usual, disable ARP mirroring and don't send a
2616 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002617 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002618 err = mv88e6xxx_port_set_map_da(chip, port);
2619 if (err)
2620 return err;
2621
Vivien Didelotfa371c82017-12-05 15:34:10 -05002622 err = mv88e6xxx_setup_upstream_port(chip, port);
2623 if (err)
2624 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002625
Andrew Lunna23b2962017-02-04 20:15:28 +01002626 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002627 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002628 if (err)
2629 return err;
2630
Vivien Didelotcd782652017-06-08 18:34:13 -04002631 if (chip->info->ops->port_set_jumbo_size) {
2632 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002633 if (err)
2634 return err;
2635 }
2636
Andrew Lunn54d792f2015-05-06 01:09:47 +02002637 /* Port Association Vector: when learning source addresses
2638 * of packets, add the address to the address database using
2639 * a port bitmap that has only the bit for this port set and
2640 * the other bits clear.
2641 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002642 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002643 /* Disable learning for CPU port */
2644 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002645 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002646
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002647 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2648 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002649 if (err)
2650 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002651
2652 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002653 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2654 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002655 if (err)
2656 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002657
Vivien Didelot08984322017-06-08 18:34:12 -04002658 if (chip->info->ops->port_pause_limit) {
2659 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002660 if (err)
2661 return err;
2662 }
2663
Vivien Didelotc8c94892017-03-11 16:13:01 -05002664 if (chip->info->ops->port_disable_learn_limit) {
2665 err = chip->info->ops->port_disable_learn_limit(chip, port);
2666 if (err)
2667 return err;
2668 }
2669
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002670 if (chip->info->ops->port_disable_pri_override) {
2671 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002672 if (err)
2673 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002674 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002675
Andrew Lunnef0a7312016-12-03 04:35:16 +01002676 if (chip->info->ops->port_tag_remap) {
2677 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002678 if (err)
2679 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002680 }
2681
Andrew Lunnef70b112016-12-03 04:45:18 +01002682 if (chip->info->ops->port_egress_rate_limiting) {
2683 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002684 if (err)
2685 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002686 }
2687
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002688 if (chip->info->ops->port_setup_message_port) {
2689 err = chip->info->ops->port_setup_message_port(chip, port);
2690 if (err)
2691 return err;
2692 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002693
Vivien Didelot207afda2016-04-14 14:42:09 -04002694 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002695 * database, and allow bidirectional communication between the
2696 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002697 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002698 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002699 if (err)
2700 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002701
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002702 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002703 if (err)
2704 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002705
2706 /* Default VLAN ID and priority: don't set a default VLAN
2707 * ID, and set the default packet priority to zero.
2708 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002709 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002710}
2711
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002712static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
2713{
2714 struct mv88e6xxx_chip *chip = ds->priv;
2715
2716 if (chip->info->ops->port_set_jumbo_size)
2717 return 10240;
Chris Packham1baf0fa2020-07-24 11:21:22 +12002718 else if (chip->info->ops->set_max_frame_size)
2719 return 1632;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002720 return 1522;
2721}
2722
2723static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
2724{
2725 struct mv88e6xxx_chip *chip = ds->priv;
2726 int ret = 0;
2727
2728 mv88e6xxx_reg_lock(chip);
2729 if (chip->info->ops->port_set_jumbo_size)
2730 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12002731 else if (chip->info->ops->set_max_frame_size)
2732 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002733 else
2734 if (new_mtu > 1522)
2735 ret = -EINVAL;
2736 mv88e6xxx_reg_unlock(chip);
2737
2738 return ret;
2739}
2740
Andrew Lunn04aca992017-05-26 01:03:24 +02002741static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2742 struct phy_device *phydev)
2743{
2744 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002745 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002746
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002747 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002748 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002749 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002750
2751 return err;
2752}
2753
Andrew Lunn75104db2019-02-24 20:44:43 +01002754static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02002755{
2756 struct mv88e6xxx_chip *chip = ds->priv;
2757
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002758 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002759 if (mv88e6xxx_serdes_power(chip, port, false))
2760 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002761 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002762}
2763
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002764static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2765 unsigned int ageing_time)
2766{
Vivien Didelot04bed142016-08-31 18:06:13 -04002767 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002768 int err;
2769
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002770 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05002771 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002772 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002773
2774 return err;
2775}
2776
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002777static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002778{
2779 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002780
Andrew Lunnde2273872016-11-21 23:27:01 +01002781 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002782 if (chip->info->ops->stats_set_histogram) {
2783 err = chip->info->ops->stats_set_histogram(chip);
2784 if (err)
2785 return err;
2786 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002787
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002788 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002789}
2790
Andrew Lunnea890982019-01-09 00:24:03 +01002791/* Check if the errata has already been applied. */
2792static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
2793{
2794 int port;
2795 int err;
2796 u16 val;
2797
2798 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002799 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01002800 if (err) {
2801 dev_err(chip->dev,
2802 "Error reading hidden register: %d\n", err);
2803 return false;
2804 }
2805 if (val != 0x01c0)
2806 return false;
2807 }
2808
2809 return true;
2810}
2811
2812/* The 6390 copper ports have an errata which require poking magic
2813 * values into undocumented hidden registers and then performing a
2814 * software reset.
2815 */
2816static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
2817{
2818 int port;
2819 int err;
2820
2821 if (mv88e6390_setup_errata_applied(chip))
2822 return 0;
2823
2824 /* Set the ports into blocking mode */
2825 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2826 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
2827 if (err)
2828 return err;
2829 }
2830
2831 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002832 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01002833 if (err)
2834 return err;
2835 }
2836
2837 return mv88e6xxx_software_reset(chip);
2838}
2839
Andrew Lunn23e8b472019-10-25 01:03:52 +02002840enum mv88e6xxx_devlink_param_id {
2841 MV88E6XXX_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
2842 MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH,
2843};
2844
2845static int mv88e6xxx_devlink_param_get(struct dsa_switch *ds, u32 id,
2846 struct devlink_param_gset_ctx *ctx)
2847{
2848 struct mv88e6xxx_chip *chip = ds->priv;
2849 int err;
2850
2851 mv88e6xxx_reg_lock(chip);
2852
2853 switch (id) {
2854 case MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH:
2855 err = mv88e6xxx_atu_get_hash(chip, &ctx->val.vu8);
2856 break;
2857 default:
2858 err = -EOPNOTSUPP;
2859 break;
2860 }
2861
2862 mv88e6xxx_reg_unlock(chip);
2863
2864 return err;
2865}
2866
2867static int mv88e6xxx_devlink_param_set(struct dsa_switch *ds, u32 id,
2868 struct devlink_param_gset_ctx *ctx)
2869{
2870 struct mv88e6xxx_chip *chip = ds->priv;
2871 int err;
2872
2873 mv88e6xxx_reg_lock(chip);
2874
2875 switch (id) {
2876 case MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH:
2877 err = mv88e6xxx_atu_set_hash(chip, ctx->val.vu8);
2878 break;
2879 default:
2880 err = -EOPNOTSUPP;
2881 break;
2882 }
2883
2884 mv88e6xxx_reg_unlock(chip);
2885
2886 return err;
2887}
2888
2889static const struct devlink_param mv88e6xxx_devlink_params[] = {
2890 DSA_DEVLINK_PARAM_DRIVER(MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH,
2891 "ATU_hash", DEVLINK_PARAM_TYPE_U8,
2892 BIT(DEVLINK_PARAM_CMODE_RUNTIME)),
2893};
2894
2895static int mv88e6xxx_setup_devlink_params(struct dsa_switch *ds)
2896{
2897 return dsa_devlink_params_register(ds, mv88e6xxx_devlink_params,
2898 ARRAY_SIZE(mv88e6xxx_devlink_params));
2899}
2900
2901static void mv88e6xxx_teardown_devlink_params(struct dsa_switch *ds)
2902{
2903 dsa_devlink_params_unregister(ds, mv88e6xxx_devlink_params,
2904 ARRAY_SIZE(mv88e6xxx_devlink_params));
2905}
2906
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002907enum mv88e6xxx_devlink_resource_id {
2908 MV88E6XXX_RESOURCE_ID_ATU,
2909 MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
2910 MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
2911 MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
2912 MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
2913};
2914
2915static u64 mv88e6xxx_devlink_atu_bin_get(struct mv88e6xxx_chip *chip,
2916 u16 bin)
2917{
2918 u16 occupancy = 0;
2919 int err;
2920
2921 mv88e6xxx_reg_lock(chip);
2922
2923 err = mv88e6xxx_g2_atu_stats_set(chip, MV88E6XXX_G2_ATU_STATS_MODE_ALL,
2924 bin);
2925 if (err) {
2926 dev_err(chip->dev, "failed to set ATU stats kind/bin\n");
2927 goto unlock;
2928 }
2929
2930 err = mv88e6xxx_g1_atu_get_next(chip, 0);
2931 if (err) {
2932 dev_err(chip->dev, "failed to perform ATU get next\n");
2933 goto unlock;
2934 }
2935
2936 err = mv88e6xxx_g2_atu_stats_get(chip, &occupancy);
2937 if (err) {
2938 dev_err(chip->dev, "failed to get ATU stats\n");
2939 goto unlock;
2940 }
2941
Andrew Lunn012fc742020-03-11 21:02:31 +01002942 occupancy &= MV88E6XXX_G2_ATU_STATS_MASK;
2943
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002944unlock:
2945 mv88e6xxx_reg_unlock(chip);
2946
2947 return occupancy;
2948}
2949
2950static u64 mv88e6xxx_devlink_atu_bin_0_get(void *priv)
2951{
2952 struct mv88e6xxx_chip *chip = priv;
2953
2954 return mv88e6xxx_devlink_atu_bin_get(chip,
2955 MV88E6XXX_G2_ATU_STATS_BIN_0);
2956}
2957
2958static u64 mv88e6xxx_devlink_atu_bin_1_get(void *priv)
2959{
2960 struct mv88e6xxx_chip *chip = priv;
2961
2962 return mv88e6xxx_devlink_atu_bin_get(chip,
2963 MV88E6XXX_G2_ATU_STATS_BIN_1);
2964}
2965
2966static u64 mv88e6xxx_devlink_atu_bin_2_get(void *priv)
2967{
2968 struct mv88e6xxx_chip *chip = priv;
2969
2970 return mv88e6xxx_devlink_atu_bin_get(chip,
2971 MV88E6XXX_G2_ATU_STATS_BIN_2);
2972}
2973
2974static u64 mv88e6xxx_devlink_atu_bin_3_get(void *priv)
2975{
2976 struct mv88e6xxx_chip *chip = priv;
2977
2978 return mv88e6xxx_devlink_atu_bin_get(chip,
2979 MV88E6XXX_G2_ATU_STATS_BIN_3);
2980}
2981
2982static u64 mv88e6xxx_devlink_atu_get(void *priv)
2983{
2984 return mv88e6xxx_devlink_atu_bin_0_get(priv) +
2985 mv88e6xxx_devlink_atu_bin_1_get(priv) +
2986 mv88e6xxx_devlink_atu_bin_2_get(priv) +
2987 mv88e6xxx_devlink_atu_bin_3_get(priv);
2988}
2989
2990static int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
2991{
2992 struct devlink_resource_size_params size_params;
2993 struct mv88e6xxx_chip *chip = ds->priv;
2994 int err;
2995
2996 devlink_resource_size_params_init(&size_params,
2997 mv88e6xxx_num_macs(chip),
2998 mv88e6xxx_num_macs(chip),
2999 1, DEVLINK_RESOURCE_UNIT_ENTRY);
3000
3001 err = dsa_devlink_resource_register(ds, "ATU",
3002 mv88e6xxx_num_macs(chip),
3003 MV88E6XXX_RESOURCE_ID_ATU,
3004 DEVLINK_RESOURCE_ID_PARENT_TOP,
3005 &size_params);
3006 if (err)
3007 goto out;
3008
3009 devlink_resource_size_params_init(&size_params,
3010 mv88e6xxx_num_macs(chip) / 4,
3011 mv88e6xxx_num_macs(chip) / 4,
3012 1, DEVLINK_RESOURCE_UNIT_ENTRY);
3013
3014 err = dsa_devlink_resource_register(ds, "ATU_bin_0",
3015 mv88e6xxx_num_macs(chip) / 4,
3016 MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
3017 MV88E6XXX_RESOURCE_ID_ATU,
3018 &size_params);
3019 if (err)
3020 goto out;
3021
3022 err = dsa_devlink_resource_register(ds, "ATU_bin_1",
3023 mv88e6xxx_num_macs(chip) / 4,
3024 MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
3025 MV88E6XXX_RESOURCE_ID_ATU,
3026 &size_params);
3027 if (err)
3028 goto out;
3029
3030 err = dsa_devlink_resource_register(ds, "ATU_bin_2",
3031 mv88e6xxx_num_macs(chip) / 4,
3032 MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
3033 MV88E6XXX_RESOURCE_ID_ATU,
3034 &size_params);
3035 if (err)
3036 goto out;
3037
3038 err = dsa_devlink_resource_register(ds, "ATU_bin_3",
3039 mv88e6xxx_num_macs(chip) / 4,
3040 MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
3041 MV88E6XXX_RESOURCE_ID_ATU,
3042 &size_params);
3043 if (err)
3044 goto out;
3045
3046 dsa_devlink_resource_occ_get_register(ds,
3047 MV88E6XXX_RESOURCE_ID_ATU,
3048 mv88e6xxx_devlink_atu_get,
3049 chip);
3050
3051 dsa_devlink_resource_occ_get_register(ds,
3052 MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
3053 mv88e6xxx_devlink_atu_bin_0_get,
3054 chip);
3055
3056 dsa_devlink_resource_occ_get_register(ds,
3057 MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
3058 mv88e6xxx_devlink_atu_bin_1_get,
3059 chip);
3060
3061 dsa_devlink_resource_occ_get_register(ds,
3062 MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
3063 mv88e6xxx_devlink_atu_bin_2_get,
3064 chip);
3065
3066 dsa_devlink_resource_occ_get_register(ds,
3067 MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
3068 mv88e6xxx_devlink_atu_bin_3_get,
3069 chip);
3070
3071 return 0;
3072
3073out:
3074 dsa_devlink_resources_unregister(ds);
3075 return err;
3076}
3077
Andrew Lunn23e8b472019-10-25 01:03:52 +02003078static void mv88e6xxx_teardown(struct dsa_switch *ds)
3079{
3080 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003081 dsa_devlink_resources_unregister(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02003082}
3083
Vivien Didelotf81ec902016-05-09 13:22:58 -04003084static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07003085{
Vivien Didelot04bed142016-08-31 18:06:13 -04003086 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003087 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04003088 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04003089 int i;
3090
Vivien Didelotfad09c72016-06-21 12:28:20 -04003091 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003092 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003093
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003094 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003095
Andrew Lunnea890982019-01-09 00:24:03 +01003096 if (chip->info->ops->setup_errata) {
3097 err = chip->info->ops->setup_errata(chip);
3098 if (err)
3099 goto unlock;
3100 }
3101
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003102 /* Cache the cmode of each port. */
3103 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3104 if (chip->info->ops->port_get_cmode) {
3105 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
3106 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03003107 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003108
3109 chip->ports[i].cmode = cmode;
3110 }
3111 }
3112
Vivien Didelot97299342016-07-18 20:45:30 -04003113 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04003114 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04003115 if (dsa_is_unused_port(ds, i))
3116 continue;
3117
Hubert Feursteinc8574862019-07-31 10:23:48 +02003118 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04003119 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02003120 dev_err(chip->dev, "port %d is invalid\n", i);
3121 err = -EINVAL;
3122 goto unlock;
3123 }
3124
Vivien Didelot97299342016-07-18 20:45:30 -04003125 err = mv88e6xxx_setup_port(chip, i);
3126 if (err)
3127 goto unlock;
3128 }
3129
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003130 err = mv88e6xxx_irl_setup(chip);
3131 if (err)
3132 goto unlock;
3133
Vivien Didelot04a69a12017-10-13 14:18:05 -04003134 err = mv88e6xxx_mac_setup(chip);
3135 if (err)
3136 goto unlock;
3137
Vivien Didelot1b17aed2017-05-26 18:03:05 -04003138 err = mv88e6xxx_phy_setup(chip);
3139 if (err)
3140 goto unlock;
3141
Vivien Didelotb486d7c2017-05-01 14:05:13 -04003142 err = mv88e6xxx_vtu_setup(chip);
3143 if (err)
3144 goto unlock;
3145
Vivien Didelot81228992017-03-30 17:37:08 -04003146 err = mv88e6xxx_pvt_setup(chip);
3147 if (err)
3148 goto unlock;
3149
Vivien Didelota2ac29d2017-03-11 16:12:49 -05003150 err = mv88e6xxx_atu_setup(chip);
3151 if (err)
3152 goto unlock;
3153
Andrew Lunn87fa8862017-11-09 22:29:56 +01003154 err = mv88e6xxx_broadcast_setup(chip, 0);
3155 if (err)
3156 goto unlock;
3157
Vivien Didelot9e907d72017-07-17 13:03:43 -04003158 err = mv88e6xxx_pot_setup(chip);
3159 if (err)
3160 goto unlock;
3161
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003162 err = mv88e6xxx_rmu_setup(chip);
3163 if (err)
3164 goto unlock;
3165
Vivien Didelot51c901a2017-07-17 13:03:41 -04003166 err = mv88e6xxx_rsvd2cpu_setup(chip);
3167 if (err)
3168 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01003169
Vivien Didelotb28f8722018-04-26 21:56:44 -04003170 err = mv88e6xxx_trunk_setup(chip);
3171 if (err)
3172 goto unlock;
3173
Vivien Didelotc7f047b2018-04-26 21:56:45 -04003174 err = mv88e6xxx_devmap_setup(chip);
3175 if (err)
3176 goto unlock;
3177
Vivien Didelot93e18d62018-05-11 17:16:35 -04003178 err = mv88e6xxx_pri_setup(chip);
3179 if (err)
3180 goto unlock;
3181
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003182 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003183 if (chip->info->ptp_support) {
3184 err = mv88e6xxx_ptp_setup(chip);
3185 if (err)
3186 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003187
3188 err = mv88e6xxx_hwtstamp_setup(chip);
3189 if (err)
3190 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003191 }
3192
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003193 err = mv88e6xxx_stats_setup(chip);
3194 if (err)
3195 goto unlock;
3196
Vivien Didelot6b17e862015-08-13 12:52:18 -04003197unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003198 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02003199
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003200 if (err)
3201 return err;
3202
3203 /* Have to be called without holding the register lock, since
3204 * they take the devlink lock, and we later take the locks in
3205 * the reverse order when getting/setting parameters or
3206 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02003207 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003208 err = mv88e6xxx_setup_devlink_resources(ds);
3209 if (err)
3210 return err;
3211
3212 err = mv88e6xxx_setup_devlink_params(ds);
3213 if (err)
3214 dsa_devlink_resources_unregister(ds);
3215
3216 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003217}
3218
Vivien Didelote57e5e72016-08-15 17:19:00 -04003219static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003220{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003221 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3222 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003223 u16 val;
3224 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003225
Andrew Lunnee26a222017-01-24 14:53:48 +01003226 if (!chip->info->ops->phy_read)
3227 return -EOPNOTSUPP;
3228
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003229 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003230 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003231 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003232
Andrew Lunnda9f3302017-02-01 03:40:05 +01003233 if (reg == MII_PHYSID2) {
Andrew Lunnddc49ac2018-11-12 18:51:01 +01003234 /* Some internal PHYs don't have a model number. */
3235 if (chip->info->family != MV88E6XXX_FAMILY_6165)
3236 /* Then there is the 6165 family. It gets is
3237 * PHYs correct. But it can also have two
3238 * SERDES interfaces in the PHY address
3239 * space. And these don't have a model
3240 * number. But they are not PHYs, so we don't
3241 * want to give them something a PHY driver
3242 * will recognise.
3243 *
3244 * Use the mv88e6390 family model number
3245 * instead, for anything which really could be
3246 * a PHY,
3247 */
3248 if (!(val & 0x3f0))
3249 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003250 }
3251
Vivien Didelote57e5e72016-08-15 17:19:00 -04003252 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003253}
3254
Vivien Didelote57e5e72016-08-15 17:19:00 -04003255static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003256{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003257 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3258 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003259 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003260
Andrew Lunnee26a222017-01-24 14:53:48 +01003261 if (!chip->info->ops->phy_write)
3262 return -EOPNOTSUPP;
3263
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003264 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003265 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003266 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003267
3268 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003269}
3270
Vivien Didelotfad09c72016-06-21 12:28:20 -04003271static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003272 struct device_node *np,
3273 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003274{
3275 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003276 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003277 struct mii_bus *bus;
3278 int err;
3279
Andrew Lunn2510bab2018-02-22 01:51:49 +01003280 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003281 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003282 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003283 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003284
3285 if (err)
3286 return err;
3287 }
3288
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003289 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003290 if (!bus)
3291 return -ENOMEM;
3292
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003293 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003294 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003295 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003296 INIT_LIST_HEAD(&mdio_bus->list);
3297 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003298
Andrew Lunnb516d452016-06-04 21:17:06 +02003299 if (np) {
3300 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003301 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003302 } else {
3303 bus->name = "mv88e6xxx SMI";
3304 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3305 }
3306
3307 bus->read = mv88e6xxx_mdio_read;
3308 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003309 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003310
Andrew Lunn6f882842018-03-17 20:32:05 +01003311 if (!external) {
3312 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3313 if (err)
3314 return err;
3315 }
3316
Florian Fainelli00e798c2018-05-15 16:56:19 -07003317 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003318 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003319 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003320 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003321 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003322 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003323
3324 if (external)
3325 list_add_tail(&mdio_bus->list, &chip->mdios);
3326 else
3327 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003328
3329 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003330}
3331
Andrew Lunn3126aee2017-12-07 01:05:57 +01003332static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3333
3334{
3335 struct mv88e6xxx_mdio_bus *mdio_bus;
3336 struct mii_bus *bus;
3337
3338 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3339 bus = mdio_bus->bus;
3340
Andrew Lunn6f882842018-03-17 20:32:05 +01003341 if (!mdio_bus->external)
3342 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3343
Andrew Lunn3126aee2017-12-07 01:05:57 +01003344 mdiobus_unregister(bus);
3345 }
3346}
3347
Andrew Lunna3c53be52017-01-24 14:53:50 +01003348static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3349 struct device_node *np)
3350{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003351 struct device_node *child;
3352 int err;
3353
3354 /* Always register one mdio bus for the internal/default mdio
3355 * bus. This maybe represented in the device tree, but is
3356 * optional.
3357 */
3358 child = of_get_child_by_name(np, "mdio");
3359 err = mv88e6xxx_mdio_register(chip, child, false);
3360 if (err)
3361 return err;
3362
3363 /* Walk the device tree, and see if there are any other nodes
3364 * which say they are compatible with the external mdio
3365 * bus.
3366 */
3367 for_each_available_child_of_node(np, child) {
Andrew Lunnceb96fa2020-09-01 04:32:57 +02003368 if (of_device_is_compatible(
3369 child, "marvell,mv88e6xxx-mdio-external")) {
Andrew Lunna3c53be52017-01-24 14:53:50 +01003370 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003371 if (err) {
3372 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303373 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003374 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003375 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003376 }
3377 }
3378
3379 return 0;
3380}
3381
Vivien Didelot855b1932016-07-20 18:18:35 -04003382static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3383{
Vivien Didelot04bed142016-08-31 18:06:13 -04003384 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003385
3386 return chip->eeprom_len;
3387}
3388
Vivien Didelot855b1932016-07-20 18:18:35 -04003389static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3390 struct ethtool_eeprom *eeprom, u8 *data)
3391{
Vivien Didelot04bed142016-08-31 18:06:13 -04003392 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003393 int err;
3394
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003395 if (!chip->info->ops->get_eeprom)
3396 return -EOPNOTSUPP;
3397
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003398 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003399 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003400 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003401
3402 if (err)
3403 return err;
3404
3405 eeprom->magic = 0xc3ec4951;
3406
3407 return 0;
3408}
3409
Vivien Didelot855b1932016-07-20 18:18:35 -04003410static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3411 struct ethtool_eeprom *eeprom, u8 *data)
3412{
Vivien Didelot04bed142016-08-31 18:06:13 -04003413 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003414 int err;
3415
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003416 if (!chip->info->ops->set_eeprom)
3417 return -EOPNOTSUPP;
3418
Vivien Didelot855b1932016-07-20 18:18:35 -04003419 if (eeprom->magic != 0xc3ec4951)
3420 return -EINVAL;
3421
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003422 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003423 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003424 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003425
3426 return err;
3427}
3428
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003429static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003430 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003431 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3432 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003433 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003434 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003435 .phy_read = mv88e6185_phy_ppu_read,
3436 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003437 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003438 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003439 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003440 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003441 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003442 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003443 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003444 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003445 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003446 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003447 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003448 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003449 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003450 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003451 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3452 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003453 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003454 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3455 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003456 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003457 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003458 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003459 .ppu_enable = mv88e6185_g1_ppu_enable,
3460 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003461 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003462 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003463 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003464 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003465 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003466 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003467};
3468
3469static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003470 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003471 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3472 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003473 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003474 .phy_read = mv88e6185_phy_ppu_read,
3475 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003476 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003477 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003478 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003479 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01003480 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003481 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003482 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003483 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003484 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003485 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3486 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003487 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003488 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003489 .ppu_enable = mv88e6185_g1_ppu_enable,
3490 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003491 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003492 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003493 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003494 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003495 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003496};
3497
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003498static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003499 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003500 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3501 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003502 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003503 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3504 .phy_read = mv88e6xxx_g2_smi_phy_read,
3505 .phy_write = mv88e6xxx_g2_smi_phy_write,
3506 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003507 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003508 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003509 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003510 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003511 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003512 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003513 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003514 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003515 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003516 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003517 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003518 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003519 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003520 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3521 .stats_get_strings = mv88e6095_stats_get_strings,
3522 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003523 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3524 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003525 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003526 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003527 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003528 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003529 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003530 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003531 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003532 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003533 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003534};
3535
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003536static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003537 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003538 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3539 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003540 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003541 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003542 .phy_read = mv88e6xxx_g2_smi_phy_read,
3543 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003544 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003545 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003546 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003547 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003548 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003549 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003550 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003551 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003552 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003553 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003554 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3555 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003556 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003557 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3558 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003559 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003560 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003561 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003562 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003563 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3564 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003565 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003566 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003567 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003568 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003569};
3570
3571static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003572 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003573 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3574 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003575 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003576 .phy_read = mv88e6185_phy_ppu_read,
3577 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003578 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003579 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003580 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003581 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003582 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003583 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003584 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003585 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003586 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003587 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003588 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003589 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003590 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003591 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003592 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003593 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3594 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003595 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003596 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3597 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003598 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003599 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003600 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003601 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003602 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003603 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003604 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003605 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003606 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003607};
3608
Vivien Didelot990e27b2017-03-28 13:50:32 -04003609static const struct mv88e6xxx_ops mv88e6141_ops = {
3610 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003611 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3612 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003613 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003614 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3615 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3616 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3617 .phy_read = mv88e6xxx_g2_smi_phy_read,
3618 .phy_write = mv88e6xxx_g2_smi_phy_write,
3619 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003620 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003621 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003622 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003623 .port_tag_remap = mv88e6095_port_tag_remap,
3624 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3625 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3626 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003627 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003628 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003629 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003630 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3631 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003632 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003633 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003634 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003635 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003636 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003637 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3638 .stats_get_strings = mv88e6320_stats_get_strings,
3639 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003640 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3641 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003642 .watchdog_ops = &mv88e6390_watchdog_ops,
3643 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003644 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003645 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003646 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003647 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003648 .serdes_power = mv88e6390_serdes_power,
3649 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003650 /* Check status register pause & lpa register */
3651 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3652 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3653 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3654 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003655 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003656 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003657 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003658 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003659 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003660};
3661
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003662static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003663 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003664 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3665 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003666 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003667 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003668 .phy_read = mv88e6xxx_g2_smi_phy_read,
3669 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003670 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003671 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003672 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003673 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003674 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003675 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003676 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003677 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003678 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003679 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003680 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003681 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003682 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003683 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003684 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003685 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3686 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003687 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003688 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3689 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003690 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003691 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003692 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003693 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003694 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3695 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003696 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003697 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003698 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003699 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003700 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003701};
3702
3703static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003704 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003705 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3706 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003707 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003708 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003709 .phy_read = mv88e6165_phy_read,
3710 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003711 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003712 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003713 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003714 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003715 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003716 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003717 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003718 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003719 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3720 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003721 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003722 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3723 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003724 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003725 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003726 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003727 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003728 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3729 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003730 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003731 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003732 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003733 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003734 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003735};
3736
3737static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003738 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003739 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3740 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003741 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003742 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003743 .phy_read = mv88e6xxx_g2_smi_phy_read,
3744 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003745 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003746 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003747 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003748 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003749 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003750 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003751 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003752 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003753 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003754 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003755 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003756 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003757 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003758 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003759 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003760 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003761 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3762 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003763 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003764 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3765 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003766 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003767 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003768 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003769 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003770 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3771 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003772 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003773 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003774 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003775};
3776
3777static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003778 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003779 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3780 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003781 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003782 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3783 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003784 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003785 .phy_read = mv88e6xxx_g2_smi_phy_read,
3786 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003787 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003788 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003789 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003790 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003791 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003792 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003793 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003794 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003795 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003796 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003797 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003798 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003799 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003800 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003801 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003802 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003803 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003804 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3805 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003806 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003807 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3808 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003809 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003810 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003811 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003812 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003813 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003814 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3815 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003816 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003817 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003818 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003819 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3820 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3821 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3822 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003823 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003824 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3825 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003826 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003827 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003828};
3829
3830static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003831 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003832 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3833 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003834 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003835 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003836 .phy_read = mv88e6xxx_g2_smi_phy_read,
3837 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003838 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003839 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003840 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003841 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003842 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003843 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003844 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003845 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003846 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003847 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003848 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003849 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003850 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003851 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003852 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003853 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003854 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3855 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003856 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003857 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3858 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003859 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003860 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003861 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003862 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003863 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3864 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003865 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003866 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003867 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003868};
3869
3870static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003871 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003872 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3873 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003874 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003875 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3876 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003877 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003878 .phy_read = mv88e6xxx_g2_smi_phy_read,
3879 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003880 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003881 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003882 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003883 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003884 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003885 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003886 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003887 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003888 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003889 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003890 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003891 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003892 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003893 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003894 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003895 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003896 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003897 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3898 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003899 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003900 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3901 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003902 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003903 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003904 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003905 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003906 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003907 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3908 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003909 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003910 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003911 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003912 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3913 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3914 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3915 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003916 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003917 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003918 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003919 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003920 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3921 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003922 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003923 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003924};
3925
3926static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003927 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003928 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3929 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003930 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003931 .phy_read = mv88e6185_phy_ppu_read,
3932 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003933 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003934 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003935 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003936 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003937 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003938 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02003939 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003940 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003941 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003942 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003943 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003944 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3945 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003946 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003947 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3948 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003949 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003950 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelot02317e62018-05-09 11:38:49 -04003951 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003952 .ppu_enable = mv88e6185_g1_ppu_enable,
3953 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003954 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003955 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003956 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003957 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003958 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003959};
3960
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003961static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003962 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003963 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003964 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003965 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3966 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003967 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3968 .phy_read = mv88e6xxx_g2_smi_phy_read,
3969 .phy_write = mv88e6xxx_g2_smi_phy_write,
3970 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003971 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003972 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003973 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003974 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003975 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003976 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003977 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003978 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003979 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003980 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003981 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003982 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003983 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003984 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003985 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003986 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003987 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003988 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3989 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003990 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003991 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3992 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003993 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003994 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003995 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003996 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003997 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003998 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3999 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004000 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4001 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004002 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004003 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004004 /* Check status register pause & lpa register */
4005 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4006 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4007 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4008 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004009 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004010 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004011 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004012 .serdes_get_strings = mv88e6390_serdes_get_strings,
4013 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004014 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4015 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004016 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004017 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004018};
4019
4020static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004021 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004022 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004023 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004024 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4025 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004026 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4027 .phy_read = mv88e6xxx_g2_smi_phy_read,
4028 .phy_write = mv88e6xxx_g2_smi_phy_write,
4029 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004030 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004031 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004032 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004033 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004034 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004035 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004036 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004037 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12004038 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04004039 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004040 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004041 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004042 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004043 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004044 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004045 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004046 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004047 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4048 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004049 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004050 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4051 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004052 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004053 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004054 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004055 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004056 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004057 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4058 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004059 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4060 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004061 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004062 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004063 /* Check status register pause & lpa register */
4064 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4065 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4066 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4067 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004068 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004069 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004070 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004071 .serdes_get_strings = mv88e6390_serdes_get_strings,
4072 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004073 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4074 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004075 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004076 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004077};
4078
4079static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004080 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004081 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004082 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004083 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4084 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004085 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4086 .phy_read = mv88e6xxx_g2_smi_phy_read,
4087 .phy_write = mv88e6xxx_g2_smi_phy_write,
4088 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004089 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004090 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004091 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004092 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004093 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004094 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004095 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004096 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004097 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004098 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004099 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004100 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004101 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004102 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004103 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004104 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4105 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004106 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004107 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4108 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004109 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004110 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004111 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004112 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004113 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004114 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4115 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004116 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4117 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004118 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004119 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004120 /* Check status register pause & lpa register */
4121 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4122 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4123 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4124 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004125 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004126 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004127 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004128 .serdes_get_strings = mv88e6390_serdes_get_strings,
4129 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004130 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4131 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004132 .avb_ops = &mv88e6390_avb_ops,
4133 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004134 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004135};
4136
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004137static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004138 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004139 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4140 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004141 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004142 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4143 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004144 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004145 .phy_read = mv88e6xxx_g2_smi_phy_read,
4146 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004147 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004148 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004149 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004150 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004151 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004152 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004153 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004154 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004155 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004156 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004157 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004158 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004159 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004160 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004161 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004162 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004163 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004164 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4165 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004166 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004167 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4168 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004169 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004170 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004171 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004172 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004173 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004174 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4175 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004176 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004177 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004178 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004179 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4180 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4181 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4182 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004183 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004184 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004185 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004186 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004187 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4188 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004189 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004190 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004191 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004192 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004193};
4194
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004195static const struct mv88e6xxx_ops mv88e6250_ops = {
4196 /* MV88E6XXX_FAMILY_6250 */
4197 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4198 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4199 .irl_init_all = mv88e6352_g2_irl_init_all,
4200 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4201 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4202 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4203 .phy_read = mv88e6xxx_g2_smi_phy_read,
4204 .phy_write = mv88e6xxx_g2_smi_phy_write,
4205 .port_set_link = mv88e6xxx_port_set_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004206 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004207 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004208 .port_tag_remap = mv88e6095_port_tag_remap,
4209 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4210 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
4211 .port_set_ether_type = mv88e6351_port_set_ether_type,
4212 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4213 .port_pause_limit = mv88e6097_port_pause_limit,
4214 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004215 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4216 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4217 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4218 .stats_get_strings = mv88e6250_stats_get_strings,
4219 .stats_get_stats = mv88e6250_stats_get_stats,
4220 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4221 .set_egress_port = mv88e6095_g1_set_egress_port,
4222 .watchdog_ops = &mv88e6250_watchdog_ops,
4223 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4224 .pot_clear = mv88e6xxx_g2_pot_clear,
4225 .reset = mv88e6250_g1_reset,
4226 .vtu_getnext = mv88e6250_g1_vtu_getnext,
4227 .vtu_loadpurge = mv88e6250_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004228 .avb_ops = &mv88e6352_avb_ops,
4229 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004230 .phylink_validate = mv88e6065_phylink_validate,
4231};
4232
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004233static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004234 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004235 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004236 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004237 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4238 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004239 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4240 .phy_read = mv88e6xxx_g2_smi_phy_read,
4241 .phy_write = mv88e6xxx_g2_smi_phy_write,
4242 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004243 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004244 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004245 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004246 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004247 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004248 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004249 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004250 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004251 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004252 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004253 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004254 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004255 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004256 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004257 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004258 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004259 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4260 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004261 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004262 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4263 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004264 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004265 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004266 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004267 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004268 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004269 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4270 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004271 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4272 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004273 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004274 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004275 /* Check status register pause & lpa register */
4276 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4277 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4278 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4279 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004280 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004281 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004282 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004283 .serdes_get_strings = mv88e6390_serdes_get_strings,
4284 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004285 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4286 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004287 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004288 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004289 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004290 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004291};
4292
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004293static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004294 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004295 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4296 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004297 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004298 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4299 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004300 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004301 .phy_read = mv88e6xxx_g2_smi_phy_read,
4302 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004303 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004304 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004305 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004306 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004307 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004308 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004309 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004310 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004311 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004312 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004313 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004314 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004315 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004316 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004317 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004318 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4319 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004320 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004321 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4322 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004323 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004324 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004325 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004326 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004327 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004328 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004329 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004330 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004331 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004332 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004333};
4334
4335static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004336 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004337 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4338 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004339 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004340 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4341 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004342 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004343 .phy_read = mv88e6xxx_g2_smi_phy_read,
4344 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004345 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004346 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004347 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004348 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004349 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004350 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004351 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004352 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004353 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004354 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004355 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004356 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004357 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004358 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004359 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004360 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4361 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004362 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004363 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4364 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004365 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004366 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004367 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004368 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004369 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004370 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004371 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004372 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004373};
4374
Vivien Didelot16e329a2017-03-28 13:50:33 -04004375static const struct mv88e6xxx_ops mv88e6341_ops = {
4376 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004377 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4378 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004379 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004380 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4381 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4382 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4383 .phy_read = mv88e6xxx_g2_smi_phy_read,
4384 .phy_write = mv88e6xxx_g2_smi_phy_write,
4385 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004386 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004387 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004388 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004389 .port_tag_remap = mv88e6095_port_tag_remap,
4390 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4391 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
4392 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004393 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004394 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004395 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004396 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4397 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004398 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004399 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004400 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004401 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004402 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004403 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4404 .stats_get_strings = mv88e6320_stats_get_strings,
4405 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004406 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4407 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004408 .watchdog_ops = &mv88e6390_watchdog_ops,
4409 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004410 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004411 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004412 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004413 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004414 .serdes_power = mv88e6390_serdes_power,
4415 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004416 /* Check status register pause & lpa register */
4417 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4418 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4419 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4420 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004421 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004422 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004423 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004424 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004425 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004426 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01004427 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004428};
4429
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004430static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004431 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004432 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4433 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004434 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004435 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004436 .phy_read = mv88e6xxx_g2_smi_phy_read,
4437 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004438 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004439 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004440 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004441 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004442 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004443 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004444 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004445 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004446 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004447 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004448 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004449 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004450 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004451 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004452 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004453 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004454 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4455 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004456 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004457 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4458 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004459 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004460 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004461 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004462 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004463 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4464 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004465 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004466 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004467 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004468};
4469
4470static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004471 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004472 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4473 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004474 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004475 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004476 .phy_read = mv88e6xxx_g2_smi_phy_read,
4477 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004478 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004479 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004480 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004481 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004482 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004483 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004484 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004485 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004486 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004487 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004488 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004489 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004490 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004491 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004492 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004493 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004494 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4495 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004496 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004497 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4498 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004499 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004500 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004501 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004502 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004503 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4504 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004505 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004506 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004507 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004508 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004509 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004510};
4511
4512static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004513 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004514 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4515 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004516 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004517 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4518 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004519 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004520 .phy_read = mv88e6xxx_g2_smi_phy_read,
4521 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004522 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004523 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004524 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004525 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004526 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004527 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004528 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004529 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004530 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004531 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004532 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004533 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004534 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004535 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004536 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004537 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004538 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004539 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4540 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004541 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004542 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4543 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004544 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004545 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004546 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004547 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004548 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004549 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4550 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004551 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004552 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004553 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004554 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4555 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4556 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4557 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004558 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004559 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004560 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004561 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004562 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004563 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004564 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004565 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4566 .serdes_get_strings = mv88e6352_serdes_get_strings,
4567 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004568 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4569 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004570 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004571};
4572
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004573static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004574 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004575 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004576 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004577 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4578 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004579 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4580 .phy_read = mv88e6xxx_g2_smi_phy_read,
4581 .phy_write = mv88e6xxx_g2_smi_phy_write,
4582 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004583 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004584 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004585 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004586 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004587 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004588 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004589 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004590 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004591 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004592 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004593 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004594 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004595 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004596 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004597 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004598 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004599 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004600 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004601 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4602 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004603 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004604 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4605 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004606 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004607 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004608 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004609 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004610 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004611 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4612 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004613 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4614 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004615 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004616 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004617 /* Check status register pause & lpa register */
4618 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4619 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4620 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4621 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004622 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004623 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004624 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004625 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004626 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004627 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004628 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4629 .serdes_get_strings = mv88e6390_serdes_get_strings,
4630 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004631 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4632 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004633 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004634};
4635
4636static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004637 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004638 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004639 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004640 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4641 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004642 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4643 .phy_read = mv88e6xxx_g2_smi_phy_read,
4644 .phy_write = mv88e6xxx_g2_smi_phy_write,
4645 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004646 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004647 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004648 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004649 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004650 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004651 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004652 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004653 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004654 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004655 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004656 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004657 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004658 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004659 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004660 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004661 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004662 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004663 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004664 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4665 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004666 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004667 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4668 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004669 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004670 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004671 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004672 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004673 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004674 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4675 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004676 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4677 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004678 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004679 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004680 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4681 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4682 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4683 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004684 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004685 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004686 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004687 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4688 .serdes_get_strings = mv88e6390_serdes_get_strings,
4689 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004690 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4691 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004692 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004693 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004694 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004695 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004696};
4697
Vivien Didelotf81ec902016-05-09 13:22:58 -04004698static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4699 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004700 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004701 .family = MV88E6XXX_FAMILY_6097,
4702 .name = "Marvell 88E6085",
4703 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004704 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004705 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004706 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004707 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004708 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004709 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004710 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004711 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004712 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004713 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004714 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004715 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004716 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004717 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004718 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004719 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004720 },
4721
4722 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004723 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004724 .family = MV88E6XXX_FAMILY_6095,
4725 .name = "Marvell 88E6095/88E6095F",
4726 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004727 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004728 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004729 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004730 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004731 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004732 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004733 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004734 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004735 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004736 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004737 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004738 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004739 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004740 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004741 },
4742
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004743 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004744 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004745 .family = MV88E6XXX_FAMILY_6097,
4746 .name = "Marvell 88E6097/88E6097F",
4747 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004748 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004749 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004750 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004751 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004752 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004753 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004754 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004755 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004756 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004757 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004758 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004759 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004760 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004761 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01004762 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004763 .ops = &mv88e6097_ops,
4764 },
4765
Vivien Didelotf81ec902016-05-09 13:22:58 -04004766 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004767 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004768 .family = MV88E6XXX_FAMILY_6165,
4769 .name = "Marvell 88E6123",
4770 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004771 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004772 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004773 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004774 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004775 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004776 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004777 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004778 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004779 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004780 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004781 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004782 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004783 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004784 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004785 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004786 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004787 },
4788
4789 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004790 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004791 .family = MV88E6XXX_FAMILY_6185,
4792 .name = "Marvell 88E6131",
4793 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004794 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004795 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004796 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004797 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004798 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004799 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004800 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004801 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004802 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004803 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004804 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004805 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004806 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004807 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004808 },
4809
Vivien Didelot990e27b2017-03-28 13:50:32 -04004810 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004811 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004812 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01004813 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04004814 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004815 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004816 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004817 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004818 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004819 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004820 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004821 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004822 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004823 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004824 .age_time_coeff = 3750,
4825 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004826 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004827 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004828 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004829 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004830 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004831 .ops = &mv88e6141_ops,
4832 },
4833
Vivien Didelotf81ec902016-05-09 13:22:58 -04004834 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004835 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004836 .family = MV88E6XXX_FAMILY_6165,
4837 .name = "Marvell 88E6161",
4838 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004839 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004840 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004841 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004842 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004843 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004844 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004845 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004846 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004847 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004848 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004849 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004850 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004851 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004852 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004853 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004854 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004855 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004856 },
4857
4858 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004859 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004860 .family = MV88E6XXX_FAMILY_6165,
4861 .name = "Marvell 88E6165",
4862 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004863 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004864 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004865 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004866 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004867 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004868 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004869 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004870 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004871 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004872 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004873 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004874 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004875 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004876 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004877 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004878 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004879 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004880 },
4881
4882 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004883 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004884 .family = MV88E6XXX_FAMILY_6351,
4885 .name = "Marvell 88E6171",
4886 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004887 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004888 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004889 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004890 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004891 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004892 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004893 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004894 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004895 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004896 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004897 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004898 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004899 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004900 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004901 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004902 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004903 },
4904
4905 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004906 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004907 .family = MV88E6XXX_FAMILY_6352,
4908 .name = "Marvell 88E6172",
4909 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004910 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004911 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004912 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004913 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004914 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004915 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004916 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004917 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004918 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004919 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004920 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004921 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004922 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004923 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004924 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004925 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004926 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004927 },
4928
4929 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004930 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004931 .family = MV88E6XXX_FAMILY_6351,
4932 .name = "Marvell 88E6175",
4933 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004934 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004935 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004936 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004937 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004938 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004939 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004940 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004941 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004942 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004943 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004944 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004945 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004946 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004947 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004948 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004949 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004950 },
4951
4952 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004953 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004954 .family = MV88E6XXX_FAMILY_6352,
4955 .name = "Marvell 88E6176",
4956 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004957 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004958 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004959 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004960 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004961 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004962 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004963 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004964 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004965 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004966 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004967 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004968 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004969 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004970 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004971 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004972 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004973 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004974 },
4975
4976 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004977 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004978 .family = MV88E6XXX_FAMILY_6185,
4979 .name = "Marvell 88E6185",
4980 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004981 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004982 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004983 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004984 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004985 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004986 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004987 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004988 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004989 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004990 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004991 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004992 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004993 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004994 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004995 },
4996
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004997 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004998 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004999 .family = MV88E6XXX_FAMILY_6390,
5000 .name = "Marvell 88E6190",
5001 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005002 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005003 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005004 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005005 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005006 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005007 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005008 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005009 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005010 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005011 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005012 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005013 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005014 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04005015 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005016 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05005017 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005018 .ops = &mv88e6190_ops,
5019 },
5020
5021 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005022 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005023 .family = MV88E6XXX_FAMILY_6390,
5024 .name = "Marvell 88E6190X",
5025 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005026 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005027 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005028 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005029 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005030 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005031 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005032 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005033 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005034 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005035 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005036 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005037 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005038 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005039 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005040 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005041 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005042 .ops = &mv88e6190x_ops,
5043 },
5044
5045 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005046 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005047 .family = MV88E6XXX_FAMILY_6390,
5048 .name = "Marvell 88E6191",
5049 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005050 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005051 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005052 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04005053 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005054 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005055 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005056 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005057 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005058 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005059 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005060 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005061 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005062 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005063 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005064 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005065 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04005066 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005067 },
5068
Hubert Feurstein49022642019-07-31 10:23:46 +02005069 [MV88E6220] = {
5070 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
5071 .family = MV88E6XXX_FAMILY_6250,
5072 .name = "Marvell 88E6220",
5073 .num_databases = 64,
5074
5075 /* Ports 2-4 are not routed to pins
5076 * => usable ports 0, 1, 5, 6
5077 */
5078 .num_ports = 7,
5079 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02005080 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02005081 .max_vid = 4095,
5082 .port_base_addr = 0x08,
5083 .phy_base_addr = 0x00,
5084 .global1_addr = 0x0f,
5085 .global2_addr = 0x07,
5086 .age_time_coeff = 15000,
5087 .g1_irqs = 9,
5088 .g2_irqs = 10,
5089 .atu_move_port_mask = 0xf,
5090 .dual_chip = true,
5091 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02005092 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02005093 .ops = &mv88e6250_ops,
5094 },
5095
Vivien Didelotf81ec902016-05-09 13:22:58 -04005096 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005097 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005098 .family = MV88E6XXX_FAMILY_6352,
5099 .name = "Marvell 88E6240",
5100 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005101 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005102 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005103 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005104 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005105 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005106 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005107 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005108 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005109 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005110 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005111 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005112 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005113 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005114 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005115 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005116 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005117 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005118 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005119 },
5120
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005121 [MV88E6250] = {
5122 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
5123 .family = MV88E6XXX_FAMILY_6250,
5124 .name = "Marvell 88E6250",
5125 .num_databases = 64,
5126 .num_ports = 7,
5127 .num_internal_phys = 5,
5128 .max_vid = 4095,
5129 .port_base_addr = 0x08,
5130 .phy_base_addr = 0x00,
5131 .global1_addr = 0x0f,
5132 .global2_addr = 0x07,
5133 .age_time_coeff = 15000,
5134 .g1_irqs = 9,
5135 .g2_irqs = 10,
5136 .atu_move_port_mask = 0xf,
5137 .dual_chip = true,
5138 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02005139 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005140 .ops = &mv88e6250_ops,
5141 },
5142
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005143 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005144 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005145 .family = MV88E6XXX_FAMILY_6390,
5146 .name = "Marvell 88E6290",
5147 .num_databases = 4096,
5148 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005149 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005150 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005151 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005152 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005153 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005154 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005155 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005156 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005157 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005158 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005159 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005160 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005161 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005162 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005163 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005164 .ops = &mv88e6290_ops,
5165 },
5166
Vivien Didelotf81ec902016-05-09 13:22:58 -04005167 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005168 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005169 .family = MV88E6XXX_FAMILY_6320,
5170 .name = "Marvell 88E6320",
5171 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005172 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005173 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005174 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005175 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005176 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005177 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005178 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005179 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005180 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005181 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005182 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005183 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005184 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005185 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005186 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005187 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005188 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005189 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005190 },
5191
5192 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005193 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005194 .family = MV88E6XXX_FAMILY_6320,
5195 .name = "Marvell 88E6321",
5196 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005197 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005198 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005199 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005200 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005201 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005202 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005203 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005204 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005205 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005206 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005207 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005208 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005209 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005210 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005211 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005212 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005213 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005214 },
5215
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005216 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005217 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005218 .family = MV88E6XXX_FAMILY_6341,
5219 .name = "Marvell 88E6341",
5220 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005221 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005222 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005223 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005224 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005225 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005226 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005227 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005228 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005229 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005230 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005231 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005232 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005233 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005234 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005235 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005236 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005237 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005238 .ops = &mv88e6341_ops,
5239 },
5240
Vivien Didelotf81ec902016-05-09 13:22:58 -04005241 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005242 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005243 .family = MV88E6XXX_FAMILY_6351,
5244 .name = "Marvell 88E6350",
5245 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005246 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005247 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005248 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005249 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005250 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005251 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005252 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005253 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005254 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005255 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005256 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005257 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005258 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005259 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005260 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005261 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005262 },
5263
5264 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005265 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005266 .family = MV88E6XXX_FAMILY_6351,
5267 .name = "Marvell 88E6351",
5268 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005269 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005270 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005271 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005272 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005273 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005274 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005275 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005276 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005277 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005278 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005279 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005280 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005281 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005282 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005283 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005284 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005285 },
5286
5287 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005288 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005289 .family = MV88E6XXX_FAMILY_6352,
5290 .name = "Marvell 88E6352",
5291 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005292 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005293 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005294 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005295 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005296 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005297 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005298 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005299 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005300 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005301 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005302 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005303 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005304 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005305 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005306 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005307 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005308 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005309 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005310 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005311 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005312 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005313 .family = MV88E6XXX_FAMILY_6390,
5314 .name = "Marvell 88E6390",
5315 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005316 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005317 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005318 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005319 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005320 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005321 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005322 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005323 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005324 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005325 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005326 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005327 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005328 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005329 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005330 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005331 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005332 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005333 .ops = &mv88e6390_ops,
5334 },
5335 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005336 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005337 .family = MV88E6XXX_FAMILY_6390,
5338 .name = "Marvell 88E6390X",
5339 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005340 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005341 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005342 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005343 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005344 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005345 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005346 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005347 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005348 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005349 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005350 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005351 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005352 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005353 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005354 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005355 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005356 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005357 .ops = &mv88e6390x_ops,
5358 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005359};
5360
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005361static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005362{
Vivien Didelota439c062016-04-17 13:23:58 -04005363 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005364
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005365 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5366 if (mv88e6xxx_table[i].prod_num == prod_num)
5367 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005368
Vivien Didelotb9b37712015-10-30 19:39:48 -04005369 return NULL;
5370}
5371
Vivien Didelotfad09c72016-06-21 12:28:20 -04005372static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005373{
5374 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005375 unsigned int prod_num, rev;
5376 u16 id;
5377 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005378
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005379 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005380 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005381 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005382 if (err)
5383 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005384
Vivien Didelot107fcc12017-06-12 12:37:36 -04005385 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5386 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005387
5388 info = mv88e6xxx_lookup_info(prod_num);
5389 if (!info)
5390 return -ENODEV;
5391
Vivien Didelotcaac8542016-06-20 13:14:09 -04005392 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005393 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005394
Vivien Didelotca070c12016-09-02 14:45:34 -04005395 err = mv88e6xxx_g2_require(chip);
5396 if (err)
5397 return err;
5398
Vivien Didelotfad09c72016-06-21 12:28:20 -04005399 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5400 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005401
5402 return 0;
5403}
5404
Vivien Didelotfad09c72016-06-21 12:28:20 -04005405static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005406{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005407 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005408
Vivien Didelotfad09c72016-06-21 12:28:20 -04005409 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5410 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005411 return NULL;
5412
Vivien Didelotfad09c72016-06-21 12:28:20 -04005413 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005414
Vivien Didelotfad09c72016-06-21 12:28:20 -04005415 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005416 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005417 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005418
Vivien Didelotfad09c72016-06-21 12:28:20 -04005419 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005420}
5421
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005422static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005423 int port,
5424 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005425{
Vivien Didelot04bed142016-08-31 18:06:13 -04005426 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005427
Andrew Lunn443d5a12016-12-03 04:35:18 +01005428 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005429}
5430
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005431static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05005432 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005433{
5434 /* We don't need any dynamic resource from the kernel (yet),
5435 * so skip the prepare phase.
5436 */
5437
5438 return 0;
5439}
5440
5441static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05005442 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005443{
Vivien Didelot04bed142016-08-31 18:06:13 -04005444 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005445
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005446 mv88e6xxx_reg_lock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005447 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04005448 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04005449 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
5450 port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005451 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005452}
5453
5454static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5455 const struct switchdev_obj_port_mdb *mdb)
5456{
Vivien Didelot04bed142016-08-31 18:06:13 -04005457 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005458 int err;
5459
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005460 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005461 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005462 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005463
5464 return err;
5465}
5466
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005467static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5468 struct dsa_mall_mirror_tc_entry *mirror,
5469 bool ingress)
5470{
5471 enum mv88e6xxx_egress_direction direction = ingress ?
5472 MV88E6XXX_EGRESS_DIR_INGRESS :
5473 MV88E6XXX_EGRESS_DIR_EGRESS;
5474 struct mv88e6xxx_chip *chip = ds->priv;
5475 bool other_mirrors = false;
5476 int i;
5477 int err;
5478
5479 if (!chip->info->ops->set_egress_port)
5480 return -EOPNOTSUPP;
5481
5482 mutex_lock(&chip->reg_lock);
5483 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5484 mirror->to_local_port) {
5485 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5486 other_mirrors |= ingress ?
5487 chip->ports[i].mirror_ingress :
5488 chip->ports[i].mirror_egress;
5489
5490 /* Can't change egress port when other mirror is active */
5491 if (other_mirrors) {
5492 err = -EBUSY;
5493 goto out;
5494 }
5495
5496 err = chip->info->ops->set_egress_port(chip,
5497 direction,
5498 mirror->to_local_port);
5499 if (err)
5500 goto out;
5501 }
5502
5503 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5504out:
5505 mutex_unlock(&chip->reg_lock);
5506
5507 return err;
5508}
5509
5510static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5511 struct dsa_mall_mirror_tc_entry *mirror)
5512{
5513 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5514 MV88E6XXX_EGRESS_DIR_INGRESS :
5515 MV88E6XXX_EGRESS_DIR_EGRESS;
5516 struct mv88e6xxx_chip *chip = ds->priv;
5517 bool other_mirrors = false;
5518 int i;
5519
5520 mutex_lock(&chip->reg_lock);
5521 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5522 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5523
5524 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5525 other_mirrors |= mirror->ingress ?
5526 chip->ports[i].mirror_ingress :
5527 chip->ports[i].mirror_egress;
5528
5529 /* Reset egress port when no other mirror is active */
5530 if (!other_mirrors) {
5531 if (chip->info->ops->set_egress_port(chip,
5532 direction,
5533 dsa_upstream_port(ds,
Colin Ian King4e4637b2019-11-12 13:05:23 +00005534 port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005535 dev_err(ds->dev, "failed to set egress port\n");
5536 }
5537
5538 mutex_unlock(&chip->reg_lock);
5539}
5540
Russell King4f859012019-02-20 15:35:05 -08005541static int mv88e6xxx_port_egress_floods(struct dsa_switch *ds, int port,
5542 bool unicast, bool multicast)
5543{
5544 struct mv88e6xxx_chip *chip = ds->priv;
5545 int err = -EOPNOTSUPP;
5546
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005547 mv88e6xxx_reg_lock(chip);
Russell King4f859012019-02-20 15:35:05 -08005548 if (chip->info->ops->port_set_egress_floods)
5549 err = chip->info->ops->port_set_egress_floods(chip, port,
5550 unicast,
5551 multicast);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005552 mv88e6xxx_reg_unlock(chip);
Russell King4f859012019-02-20 15:35:05 -08005553
5554 return err;
5555}
5556
Florian Fainellia82f67a2017-01-08 14:52:08 -08005557static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02005558 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005559 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005560 .teardown = mv88e6xxx_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07005561 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00005562 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07005563 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00005564 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07005565 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
5566 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005567 .get_strings = mv88e6xxx_get_strings,
5568 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
5569 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02005570 .port_enable = mv88e6xxx_port_enable,
5571 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02005572 .port_max_mtu = mv88e6xxx_get_max_mtu,
5573 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04005574 .get_mac_eee = mv88e6xxx_get_mac_eee,
5575 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005576 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005577 .get_eeprom = mv88e6xxx_get_eeprom,
5578 .set_eeprom = mv88e6xxx_set_eeprom,
5579 .get_regs_len = mv88e6xxx_get_regs_len,
5580 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04005581 .get_rxnfc = mv88e6xxx_get_rxnfc,
5582 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04005583 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005584 .port_bridge_join = mv88e6xxx_port_bridge_join,
5585 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Russell King4f859012019-02-20 15:35:05 -08005586 .port_egress_floods = mv88e6xxx_port_egress_floods,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005587 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04005588 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005589 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
5590 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
5591 .port_vlan_add = mv88e6xxx_port_vlan_add,
5592 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005593 .port_fdb_add = mv88e6xxx_port_fdb_add,
5594 .port_fdb_del = mv88e6xxx_port_fdb_del,
5595 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005596 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
5597 .port_mdb_add = mv88e6xxx_port_mdb_add,
5598 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005599 .port_mirror_add = mv88e6xxx_port_mirror_add,
5600 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04005601 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
5602 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005603 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
5604 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
5605 .port_txtstamp = mv88e6xxx_port_txtstamp,
5606 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
5607 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005608 .devlink_param_get = mv88e6xxx_devlink_param_get,
5609 .devlink_param_set = mv88e6xxx_devlink_param_set,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005610};
5611
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005612static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005613{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005614 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005615 struct dsa_switch *ds;
5616
Vivien Didelot7e99e342019-10-21 16:51:30 -04005617 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005618 if (!ds)
5619 return -ENOMEM;
5620
Vivien Didelot7e99e342019-10-21 16:51:30 -04005621 ds->dev = dev;
5622 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005623 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005624 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04005625 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04005626 ds->ageing_time_min = chip->info->age_time_coeff;
5627 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005628
5629 dev_set_drvdata(dev, ds);
5630
Vivien Didelot23c9ee42017-05-26 18:12:51 -04005631 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005632}
5633
Vivien Didelotfad09c72016-06-21 12:28:20 -04005634static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005635{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005636 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005637}
5638
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005639static const void *pdata_device_get_match_data(struct device *dev)
5640{
5641 const struct of_device_id *matches = dev->driver->of_match_table;
5642 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
5643
5644 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
5645 matches++) {
5646 if (!strcmp(pdata->compatible, matches->compatible))
5647 return matches->data;
5648 }
5649 return NULL;
5650}
5651
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005652/* There is no suspend to RAM support at DSA level yet, the switch configuration
5653 * would be lost after a power cycle so prevent it to be suspended.
5654 */
5655static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
5656{
5657 return -EOPNOTSUPP;
5658}
5659
5660static int __maybe_unused mv88e6xxx_resume(struct device *dev)
5661{
5662 return 0;
5663}
5664
5665static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
5666
Vivien Didelot57d32312016-06-20 13:13:58 -04005667static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005668{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005669 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04005670 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005671 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005672 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04005673 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005674 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02005675 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005676
Andrew Lunn7bb8c992018-05-31 00:15:42 +02005677 if (!np && !pdata)
5678 return -EINVAL;
5679
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005680 if (np)
5681 compat_info = of_device_get_match_data(dev);
5682
5683 if (pdata) {
5684 compat_info = pdata_device_get_match_data(dev);
5685
5686 if (!pdata->netdev)
5687 return -EINVAL;
5688
5689 for (port = 0; port < DSA_MAX_PORTS; port++) {
5690 if (!(pdata->enabled_ports & (1 << port)))
5691 continue;
5692 if (strcmp(pdata->cd.port_names[port], "cpu"))
5693 continue;
5694 pdata->cd.netdev[port] = &pdata->netdev->dev;
5695 break;
5696 }
5697 }
5698
Vivien Didelotcaac8542016-06-20 13:14:09 -04005699 if (!compat_info)
5700 return -EINVAL;
5701
Vivien Didelotfad09c72016-06-21 12:28:20 -04005702 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005703 if (!chip) {
5704 err = -ENOMEM;
5705 goto out;
5706 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005707
Vivien Didelotfad09c72016-06-21 12:28:20 -04005708 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04005709
Vivien Didelotfad09c72016-06-21 12:28:20 -04005710 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04005711 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005712 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005713
Andrew Lunnb4308f02016-11-21 23:26:55 +01005714 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005715 if (IS_ERR(chip->reset)) {
5716 err = PTR_ERR(chip->reset);
5717 goto out;
5718 }
Baruch Siach7b75e492019-06-27 21:17:39 +03005719 if (chip->reset)
5720 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01005721
Vivien Didelotfad09c72016-06-21 12:28:20 -04005722 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005723 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005724 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005725
Vivien Didelote57e5e72016-08-15 17:19:00 -04005726 mv88e6xxx_phy_init(chip);
5727
Andrew Lunn00baabe2018-05-19 22:31:35 +02005728 if (chip->info->ops->get_eeprom) {
5729 if (np)
5730 of_property_read_u32(np, "eeprom-length",
5731 &chip->eeprom_len);
5732 else
5733 chip->eeprom_len = pdata->eeprom_len;
5734 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005735
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005736 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005737 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005738 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02005739 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02005740 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02005741
Andrew Lunna27415d2019-05-01 00:10:50 +02005742 if (np) {
5743 chip->irq = of_irq_get(np, 0);
5744 if (chip->irq == -EPROBE_DEFER) {
5745 err = chip->irq;
5746 goto out;
5747 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02005748 }
5749
Andrew Lunna27415d2019-05-01 00:10:50 +02005750 if (pdata)
5751 chip->irq = pdata->irq;
5752
Andrew Lunn294d7112018-02-22 22:58:32 +01005753 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01005754 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01005755 * controllers
5756 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005757 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005758 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005759 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005760 else
5761 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005762 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005763
Andrew Lunn294d7112018-02-22 22:58:32 +01005764 if (err)
5765 goto out;
5766
5767 if (chip->info->g2_irqs > 0) {
5768 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005769 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01005770 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005771 }
5772
Andrew Lunn294d7112018-02-22 22:58:32 +01005773 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
5774 if (err)
5775 goto out_g2_irq;
5776
5777 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
5778 if (err)
5779 goto out_g1_atu_prob_irq;
5780
Andrew Lunna3c53be52017-01-24 14:53:50 +01005781 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02005782 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01005783 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005784
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005785 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005786 if (err)
5787 goto out_mdio;
5788
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005789 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02005790
5791out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01005792 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01005793out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005794 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01005795out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005796 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005797out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005798 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005799 mv88e6xxx_g2_irq_free(chip);
5800out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005801 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005802 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005803 else
5804 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005805out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005806 if (pdata)
5807 dev_put(pdata->netdev);
5808
Andrew Lunndc30c352016-10-16 19:56:49 +02005809 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005810}
5811
5812static void mv88e6xxx_remove(struct mdio_device *mdiodev)
5813{
5814 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04005815 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005816
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005817 if (chip->info->ptp_support) {
5818 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005819 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005820 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005821
Andrew Lunn930188c2016-08-22 16:01:03 +02005822 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005823 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005824 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005825
Andrew Lunn76f38f12018-03-17 20:21:09 +01005826 mv88e6xxx_g1_vtu_prob_irq_free(chip);
5827 mv88e6xxx_g1_atu_prob_irq_free(chip);
5828
5829 if (chip->info->g2_irqs > 0)
5830 mv88e6xxx_g2_irq_free(chip);
5831
Andrew Lunn76f38f12018-03-17 20:21:09 +01005832 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005833 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01005834 else
5835 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005836}
5837
5838static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04005839 {
5840 .compatible = "marvell,mv88e6085",
5841 .data = &mv88e6xxx_table[MV88E6085],
5842 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005843 {
5844 .compatible = "marvell,mv88e6190",
5845 .data = &mv88e6xxx_table[MV88E6190],
5846 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005847 {
5848 .compatible = "marvell,mv88e6250",
5849 .data = &mv88e6xxx_table[MV88E6250],
5850 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005851 { /* sentinel */ },
5852};
5853
5854MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
5855
5856static struct mdio_driver mv88e6xxx_driver = {
5857 .probe = mv88e6xxx_probe,
5858 .remove = mv88e6xxx_remove,
5859 .mdiodrv.driver = {
5860 .name = "mv88e6085",
5861 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005862 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005863 },
5864};
5865
Andrew Lunn7324d502019-04-27 19:19:10 +02005866mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00005867
5868MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
5869MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
5870MODULE_LICENSE("GPL");