blob: b8a3e8c88c07bfea8ed56048b216be6758c55452 [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 King64d47d52020-03-14 10:15:38 +0000667 int err;
Russell Kingc9a23562018-05-10 13:17:35 -0700668
Russell King64d47d52020-03-14 10:15:38 +0000669 /* FIXME: is this the correct test? If we're in fixed mode on an
670 * internal port, why should we process this any different from
671 * PHY mode? On the other hand, the port may be automedia between
672 * an internal PHY and the serdes...
673 */
Marek Vasutd700ec42018-09-12 00:15:24 +0200674 if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
Russell Kingc9a23562018-05-10 13:17:35 -0700675 return;
676
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000677 mv88e6xxx_reg_lock(chip);
Russell King64d47d52020-03-14 10:15:38 +0000678 /* FIXME: should we force the link down here - but if we do, how
679 * do we restore the link force/unforce state? The driver layering
680 * gets in the way.
681 */
682 err = mv88e6xxx_port_config_interface(chip, port, state->interface);
Russell Kinga5a68582020-03-14 10:15:43 +0000683 if (err && err != -EOPNOTSUPP)
684 goto err_unlock;
685
686 err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
687 state->advertising);
688 /* FIXME: we should restart negotiation if something changed - which
689 * is something we get if we convert to using phylinks PCS operations.
690 */
691 if (err > 0)
692 err = 0;
693
694err_unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000695 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700696
697 if (err && err != -EOPNOTSUPP)
Russell King64d47d52020-03-14 10:15:38 +0000698 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700699}
700
Russell Kingc9a23562018-05-10 13:17:35 -0700701static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
702 unsigned int mode,
703 phy_interface_t interface)
704{
Russell King30c4a5b2020-02-26 10:23:51 +0000705 struct mv88e6xxx_chip *chip = ds->priv;
706 const struct mv88e6xxx_ops *ops;
707 int err = 0;
708
709 ops = chip->info->ops;
710
Russell King5d5b2312020-03-14 10:16:03 +0000711 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200712 if ((!mv88e6xxx_port_ppu_updates(chip, port) ||
713 mode == MLO_AN_FIXED) && ops->port_set_link)
Russell King30c4a5b2020-02-26 10:23:51 +0000714 err = ops->port_set_link(chip, port, LINK_FORCED_DOWN);
Russell King5d5b2312020-03-14 10:16:03 +0000715 mv88e6xxx_reg_unlock(chip);
Russell King30c4a5b2020-02-26 10:23:51 +0000716
Russell King5d5b2312020-03-14 10:16:03 +0000717 if (err)
718 dev_err(chip->dev,
719 "p%d: failed to force MAC link down\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700720}
721
722static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
723 unsigned int mode, phy_interface_t interface,
Russell King5b502a72020-02-26 10:23:46 +0000724 struct phy_device *phydev,
725 int speed, int duplex,
726 bool tx_pause, bool rx_pause)
Russell Kingc9a23562018-05-10 13:17:35 -0700727{
Russell King30c4a5b2020-02-26 10:23:51 +0000728 struct mv88e6xxx_chip *chip = ds->priv;
729 const struct mv88e6xxx_ops *ops;
730 int err = 0;
731
732 ops = chip->info->ops;
733
Russell King5d5b2312020-03-14 10:16:03 +0000734 mv88e6xxx_reg_lock(chip);
Andrew Lunn34b5e6a2020-04-14 02:34:38 +0200735 if (!mv88e6xxx_port_ppu_updates(chip, port) || mode == MLO_AN_FIXED) {
Russell King30c4a5b2020-02-26 10:23:51 +0000736 /* FIXME: for an automedia port, should we force the link
737 * down here - what if the link comes up due to "other" media
738 * while we're bringing the port up, how is the exclusivity
Russell Kinga5a68582020-03-14 10:15:43 +0000739 * handled in the Marvell hardware? E.g. port 2 on 88E6390
Russell King30c4a5b2020-02-26 10:23:51 +0000740 * shared between internal PHY and Serdes.
741 */
Russell Kinga5a68582020-03-14 10:15:43 +0000742 err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
743 duplex);
744 if (err)
745 goto error;
746
Russell Kingf365c6f2020-03-14 10:15:53 +0000747 if (ops->port_set_speed_duplex) {
748 err = ops->port_set_speed_duplex(chip, port,
749 speed, duplex);
Russell King30c4a5b2020-02-26 10:23:51 +0000750 if (err && err != -EOPNOTSUPP)
751 goto error;
752 }
753
754 if (ops->port_set_link)
755 err = ops->port_set_link(chip, port, LINK_FORCED_UP);
Russell King30c4a5b2020-02-26 10:23:51 +0000756 }
Russell King5d5b2312020-03-14 10:16:03 +0000757error:
758 mv88e6xxx_reg_unlock(chip);
759
760 if (err && err != -EOPNOTSUPP)
761 dev_err(ds->dev,
762 "p%d: failed to configure MAC link up\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700763}
764
Andrew Lunna605a0f2016-11-21 23:26:58 +0100765static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000766{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100767 if (!chip->info->ops->stats_snapshot)
768 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000769
Andrew Lunna605a0f2016-11-21 23:26:58 +0100770 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000771}
772
Andrew Lunne413e7e2015-04-02 04:06:38 +0200773static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100774 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
775 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
776 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
777 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
778 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
779 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
780 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
781 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
782 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
783 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
784 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
785 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
786 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
787 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
788 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
789 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
790 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
791 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
792 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
793 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
794 { "single", 4, 0x14, STATS_TYPE_BANK0, },
795 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
796 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
797 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
798 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
799 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
800 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
801 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
802 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
803 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
804 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
805 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
806 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
807 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
808 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
809 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
810 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
811 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
812 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
813 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
814 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
815 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
816 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
817 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
818 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
819 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
820 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
821 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
822 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
823 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
824 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
825 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
826 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
827 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
828 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
829 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
830 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
831 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
832 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200833};
834
Vivien Didelotfad09c72016-06-21 12:28:20 -0400835static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100836 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100837 int port, u16 bank1_select,
838 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200839{
Andrew Lunn80c46272015-06-20 18:42:30 +0200840 u32 low;
841 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100842 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200843 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200844 u64 value;
845
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100846 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100847 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200848 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
849 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800850 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200851
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200852 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100853 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200854 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
855 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800856 return U64_MAX;
Rasmus Villemoes84b3fd12019-05-29 07:02:11 +0000857 low |= ((u32)reg) << 16;
Andrew Lunn80c46272015-06-20 18:42:30 +0200858 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100859 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100860 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100861 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100862 /* fall through */
863 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100864 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100865 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100866 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100867 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500868 break;
869 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800870 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200871 }
Andrew Lunn6e46e2d2019-02-28 18:14:03 +0100872 value = (((u64)high) << 32) | low;
Andrew Lunn80c46272015-06-20 18:42:30 +0200873 return value;
874}
875
Andrew Lunn436fe172018-03-01 02:02:29 +0100876static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
877 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100878{
879 struct mv88e6xxx_hw_stat *stat;
880 int i, j;
881
882 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
883 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100884 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100885 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
886 ETH_GSTRING_LEN);
887 j++;
888 }
889 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100890
891 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100892}
893
Andrew Lunn436fe172018-03-01 02:02:29 +0100894static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
895 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100896{
Andrew Lunn436fe172018-03-01 02:02:29 +0100897 return mv88e6xxx_stats_get_strings(chip, data,
898 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100899}
900
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000901static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
902 uint8_t *data)
903{
904 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
905}
906
Andrew Lunn436fe172018-03-01 02:02:29 +0100907static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
908 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100909{
Andrew Lunn436fe172018-03-01 02:02:29 +0100910 return mv88e6xxx_stats_get_strings(chip, data,
911 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100912}
913
Andrew Lunn65f60e42018-03-28 23:50:28 +0200914static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
915 "atu_member_violation",
916 "atu_miss_violation",
917 "atu_full_violation",
918 "vtu_member_violation",
919 "vtu_miss_violation",
920};
921
922static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
923{
924 unsigned int i;
925
926 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
927 strlcpy(data + i * ETH_GSTRING_LEN,
928 mv88e6xxx_atu_vtu_stats_strings[i],
929 ETH_GSTRING_LEN);
930}
931
Andrew Lunndfafe442016-11-21 23:27:02 +0100932static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700933 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100934{
Vivien Didelot04bed142016-08-31 18:06:13 -0400935 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100936 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100937
Florian Fainelli89f09042018-04-25 12:12:50 -0700938 if (stringset != ETH_SS_STATS)
939 return;
940
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000941 mv88e6xxx_reg_lock(chip);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100942
Andrew Lunndfafe442016-11-21 23:27:02 +0100943 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100944 count = chip->info->ops->stats_get_strings(chip, data);
945
946 if (chip->info->ops->serdes_get_strings) {
947 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200948 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100949 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100950
Andrew Lunn65f60e42018-03-28 23:50:28 +0200951 data += count * ETH_GSTRING_LEN;
952 mv88e6xxx_atu_vtu_get_strings(data);
953
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000954 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100955}
956
957static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
958 int types)
959{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100960 struct mv88e6xxx_hw_stat *stat;
961 int i, j;
962
963 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
964 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100965 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100966 j++;
967 }
968 return j;
969}
970
Andrew Lunndfafe442016-11-21 23:27:02 +0100971static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
972{
973 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
974 STATS_TYPE_PORT);
975}
976
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000977static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
978{
979 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
980}
981
Andrew Lunndfafe442016-11-21 23:27:02 +0100982static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
983{
984 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
985 STATS_TYPE_BANK1);
986}
987
Florian Fainelli89f09042018-04-25 12:12:50 -0700988static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +0100989{
990 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100991 int serdes_count = 0;
992 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100993
Florian Fainelli89f09042018-04-25 12:12:50 -0700994 if (sset != ETH_SS_STATS)
995 return 0;
996
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000997 mv88e6xxx_reg_lock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100998 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +0100999 count = chip->info->ops->stats_get_sset_count(chip);
1000 if (count < 0)
1001 goto out;
1002
1003 if (chip->info->ops->serdes_get_sset_count)
1004 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1005 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +02001006 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +01001007 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001008 goto out;
1009 }
1010 count += serdes_count;
1011 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1012
Andrew Lunn436fe172018-03-01 02:02:29 +01001013out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001014 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001015
Andrew Lunn436fe172018-03-01 02:02:29 +01001016 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +01001017}
1018
Andrew Lunn436fe172018-03-01 02:02:29 +01001019static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1020 uint64_t *data, int types,
1021 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +01001022{
1023 struct mv88e6xxx_hw_stat *stat;
1024 int i, j;
1025
1026 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1027 stat = &mv88e6xxx_hw_stats[i];
1028 if (stat->type & types) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001029 mv88e6xxx_reg_lock(chip);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001030 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1031 bank1_select,
1032 histogram);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001033 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001034
Andrew Lunn052f9472016-11-21 23:27:03 +01001035 j++;
1036 }
1037 }
Andrew Lunn436fe172018-03-01 02:02:29 +01001038 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +01001039}
1040
Andrew Lunn436fe172018-03-01 02:02:29 +01001041static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1042 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001043{
1044 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001045 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001046 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +01001047}
1048
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001049static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1050 uint64_t *data)
1051{
1052 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
1053 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1054}
1055
Andrew Lunn436fe172018-03-01 02:02:29 +01001056static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1057 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001058{
1059 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001060 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001061 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1062 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001063}
1064
Andrew Lunn436fe172018-03-01 02:02:29 +01001065static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1066 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +01001067{
1068 return mv88e6xxx_stats_get_stats(chip, port, data,
1069 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001070 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1071 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001072}
1073
Andrew Lunn65f60e42018-03-28 23:50:28 +02001074static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1075 uint64_t *data)
1076{
1077 *data++ = chip->ports[port].atu_member_violation;
1078 *data++ = chip->ports[port].atu_miss_violation;
1079 *data++ = chip->ports[port].atu_full_violation;
1080 *data++ = chip->ports[port].vtu_member_violation;
1081 *data++ = chip->ports[port].vtu_miss_violation;
1082}
1083
Andrew Lunn052f9472016-11-21 23:27:03 +01001084static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1085 uint64_t *data)
1086{
Andrew Lunn436fe172018-03-01 02:02:29 +01001087 int count = 0;
1088
Andrew Lunn052f9472016-11-21 23:27:03 +01001089 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +01001090 count = chip->info->ops->stats_get_stats(chip, port, data);
1091
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001092 mv88e6xxx_reg_lock(chip);
Andrew Lunn436fe172018-03-01 02:02:29 +01001093 if (chip->info->ops->serdes_get_stats) {
1094 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001095 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +01001096 }
Andrew Lunn65f60e42018-03-28 23:50:28 +02001097 data += count;
1098 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001099 mv88e6xxx_reg_unlock(chip);
Andrew Lunn052f9472016-11-21 23:27:03 +01001100}
1101
Vivien Didelotf81ec902016-05-09 13:22:58 -04001102static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1103 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001104{
Vivien Didelot04bed142016-08-31 18:06:13 -04001105 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001106 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001107
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001108 mv88e6xxx_reg_lock(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001109
Andrew Lunna605a0f2016-11-21 23:26:58 +01001110 ret = mv88e6xxx_stats_snapshot(chip, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001111 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001112
1113 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001114 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001115
1116 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001117
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001118}
Ben Hutchings98e67302011-11-25 14:36:19 +00001119
Vivien Didelotf81ec902016-05-09 13:22:58 -04001120static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001121{
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001122 struct mv88e6xxx_chip *chip = ds->priv;
1123 int len;
1124
1125 len = 32 * sizeof(u16);
1126 if (chip->info->ops->serdes_get_regs_len)
1127 len += chip->info->ops->serdes_get_regs_len(chip, port);
1128
1129 return len;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001130}
1131
Vivien Didelotf81ec902016-05-09 13:22:58 -04001132static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1133 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001134{
Vivien Didelot04bed142016-08-31 18:06:13 -04001135 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001136 int err;
1137 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001138 u16 *p = _p;
1139 int i;
1140
Vivien Didelota5f39322018-12-17 16:05:21 -05001141 regs->version = chip->info->prod_num;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001142
1143 memset(p, 0xff, 32 * sizeof(u16));
1144
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001145 mv88e6xxx_reg_lock(chip);
Vivien Didelot23062512016-05-09 13:22:45 -04001146
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001147 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001148
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001149 err = mv88e6xxx_port_read(chip, port, i, &reg);
1150 if (!err)
1151 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001152 }
Vivien Didelot23062512016-05-09 13:22:45 -04001153
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001154 if (chip->info->ops->serdes_get_regs)
1155 chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1156
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001157 mv88e6xxx_reg_unlock(chip);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001158}
1159
Vivien Didelot08f50062017-08-01 16:32:41 -04001160static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1161 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001162{
Vivien Didelot5480db62017-08-01 16:32:40 -04001163 /* Nothing to do on the port's MAC */
1164 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001165}
1166
Vivien Didelot08f50062017-08-01 16:32:41 -04001167static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1168 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001169{
Vivien Didelot5480db62017-08-01 16:32:40 -04001170 /* Nothing to do on the port's MAC */
1171 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001172}
1173
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001174/* Mask of the local ports allowed to receive frames from a given fabric port */
Vivien Didelote5887a22017-03-30 17:37:11 -04001175static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001176{
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001177 struct dsa_switch *ds = chip->ds;
1178 struct dsa_switch_tree *dst = ds->dst;
Vivien Didelote5887a22017-03-30 17:37:11 -04001179 struct net_device *br;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001180 struct dsa_port *dp;
1181 bool found = false;
Vivien Didelote5887a22017-03-30 17:37:11 -04001182 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001183
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001184 list_for_each_entry(dp, &dst->ports, list) {
1185 if (dp->ds->index == dev && dp->index == port) {
1186 found = true;
1187 break;
1188 }
1189 }
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001190
Vivien Didelote5887a22017-03-30 17:37:11 -04001191 /* Prevent frames from unknown switch or port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001192 if (!found)
Vivien Didelote5887a22017-03-30 17:37:11 -04001193 return 0;
1194
1195 /* Frames from DSA links and CPU ports can egress any local port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001196 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
Vivien Didelote5887a22017-03-30 17:37:11 -04001197 return mv88e6xxx_port_mask(chip);
1198
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001199 br = dp->bridge_dev;
Vivien Didelote5887a22017-03-30 17:37:11 -04001200 pvlan = 0;
1201
1202 /* Frames from user ports can egress any local DSA links and CPU ports,
1203 * as well as any local member of their bridge group.
1204 */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001205 list_for_each_entry(dp, &dst->ports, list)
1206 if (dp->ds == ds &&
1207 (dp->type == DSA_PORT_TYPE_CPU ||
1208 dp->type == DSA_PORT_TYPE_DSA ||
1209 (br && dp->bridge_dev == br)))
1210 pvlan |= BIT(dp->index);
Vivien Didelote5887a22017-03-30 17:37:11 -04001211
1212 return pvlan;
1213}
1214
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001215static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001216{
1217 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001218
1219 /* prevent frames from going back out of the port they came in on */
1220 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001221
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001222 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001223}
1224
Vivien Didelotf81ec902016-05-09 13:22:58 -04001225static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1226 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001227{
Vivien Didelot04bed142016-08-31 18:06:13 -04001228 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001229 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001230
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001231 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001232 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001233 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001234
1235 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001236 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001237}
1238
Vivien Didelot93e18d62018-05-11 17:16:35 -04001239static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1240{
1241 int err;
1242
1243 if (chip->info->ops->ieee_pri_map) {
1244 err = chip->info->ops->ieee_pri_map(chip);
1245 if (err)
1246 return err;
1247 }
1248
1249 if (chip->info->ops->ip_pri_map) {
1250 err = chip->info->ops->ip_pri_map(chip);
1251 if (err)
1252 return err;
1253 }
1254
1255 return 0;
1256}
1257
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001258static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1259{
Vivien Didelotc5f51762019-10-30 22:09:13 -04001260 struct dsa_switch *ds = chip->ds;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001261 int target, port;
1262 int err;
1263
1264 if (!chip->info->global2_addr)
1265 return 0;
1266
1267 /* Initialize the routing port to the 32 possible target devices */
1268 for (target = 0; target < 32; target++) {
Vivien Didelotc5f51762019-10-30 22:09:13 -04001269 port = dsa_routing_port(ds, target);
1270 if (port == ds->num_ports)
1271 port = 0x1f;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001272
1273 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1274 if (err)
1275 return err;
1276 }
1277
Vivien Didelot02317e62018-05-09 11:38:49 -04001278 if (chip->info->ops->set_cascade_port) {
1279 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1280 err = chip->info->ops->set_cascade_port(chip, port);
1281 if (err)
1282 return err;
1283 }
1284
Vivien Didelot23c98912018-05-09 11:38:50 -04001285 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1286 if (err)
1287 return err;
1288
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001289 return 0;
1290}
1291
Vivien Didelotb28f8722018-04-26 21:56:44 -04001292static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1293{
1294 /* Clear all trunk masks and mapping */
1295 if (chip->info->global2_addr)
1296 return mv88e6xxx_g2_trunk_clear(chip);
1297
1298 return 0;
1299}
1300
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001301static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1302{
1303 if (chip->info->ops->rmu_disable)
1304 return chip->info->ops->rmu_disable(chip);
1305
1306 return 0;
1307}
1308
Vivien Didelot9e907d72017-07-17 13:03:43 -04001309static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1310{
1311 if (chip->info->ops->pot_clear)
1312 return chip->info->ops->pot_clear(chip);
1313
1314 return 0;
1315}
1316
Vivien Didelot51c901a2017-07-17 13:03:41 -04001317static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1318{
1319 if (chip->info->ops->mgmt_rsvd2cpu)
1320 return chip->info->ops->mgmt_rsvd2cpu(chip);
1321
1322 return 0;
1323}
1324
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001325static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1326{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001327 int err;
1328
Vivien Didelotdaefc942017-03-11 16:12:54 -05001329 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1330 if (err)
1331 return err;
1332
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001333 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1334 if (err)
1335 return err;
1336
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001337 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1338}
1339
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001340static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1341{
1342 int port;
1343 int err;
1344
1345 if (!chip->info->ops->irl_init_all)
1346 return 0;
1347
1348 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1349 /* Disable ingress rate limiting by resetting all per port
1350 * ingress rate limit resources to their initial state.
1351 */
1352 err = chip->info->ops->irl_init_all(chip, port);
1353 if (err)
1354 return err;
1355 }
1356
1357 return 0;
1358}
1359
Vivien Didelot04a69a12017-10-13 14:18:05 -04001360static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1361{
1362 if (chip->info->ops->set_switch_mac) {
1363 u8 addr[ETH_ALEN];
1364
1365 eth_random_addr(addr);
1366
1367 return chip->info->ops->set_switch_mac(chip, addr);
1368 }
1369
1370 return 0;
1371}
1372
Vivien Didelot17a15942017-03-30 17:37:09 -04001373static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1374{
1375 u16 pvlan = 0;
1376
1377 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001378 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001379
1380 /* Skip the local source device, which uses in-chip port VLAN */
1381 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001382 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001383
1384 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1385}
1386
Vivien Didelot81228992017-03-30 17:37:08 -04001387static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1388{
Vivien Didelot17a15942017-03-30 17:37:09 -04001389 int dev, port;
1390 int err;
1391
Vivien Didelot81228992017-03-30 17:37:08 -04001392 if (!mv88e6xxx_has_pvt(chip))
1393 return 0;
1394
1395 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1396 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1397 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001398 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1399 if (err)
1400 return err;
1401
1402 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1403 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1404 err = mv88e6xxx_pvt_map(chip, dev, port);
1405 if (err)
1406 return err;
1407 }
1408 }
1409
1410 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001411}
1412
Vivien Didelot749efcb2016-09-22 16:49:24 -04001413static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1414{
1415 struct mv88e6xxx_chip *chip = ds->priv;
1416 int err;
1417
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001418 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001419 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001420 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001421
1422 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001423 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001424}
1425
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001426static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1427{
1428 if (!chip->info->max_vid)
1429 return 0;
1430
1431 return mv88e6xxx_g1_vtu_flush(chip);
1432}
1433
Vivien Didelotf1394b782017-05-01 14:05:22 -04001434static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1435 struct mv88e6xxx_vtu_entry *entry)
1436{
1437 if (!chip->info->ops->vtu_getnext)
1438 return -EOPNOTSUPP;
1439
1440 return chip->info->ops->vtu_getnext(chip, entry);
1441}
1442
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001443static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1444 struct mv88e6xxx_vtu_entry *entry)
1445{
1446 if (!chip->info->ops->vtu_loadpurge)
1447 return -EOPNOTSUPP;
1448
1449 return chip->info->ops->vtu_loadpurge(chip, entry);
1450}
1451
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001452static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001453{
1454 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot425d2d32019-08-01 14:36:34 -04001455 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001456 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001457
1458 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1459
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001460 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001461 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001462 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001463 if (err)
1464 return err;
1465
1466 set_bit(*fid, fid_bitmap);
1467 }
1468
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001469 /* Set every FID bit used by the VLAN entries */
Vivien Didelot425d2d32019-08-01 14:36:34 -04001470 vlan.vid = chip->info->max_vid;
1471 vlan.valid = false;
1472
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001473 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001474 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001475 if (err)
1476 return err;
1477
1478 if (!vlan.valid)
1479 break;
1480
1481 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001482 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001483
1484 /* The reset value 0x000 is used to indicate that multiple address
1485 * databases are not needed. Return the next positive available.
1486 */
1487 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001488 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001489 return -ENOSPC;
1490
1491 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001492 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001493}
1494
Andrew Lunn23e8b472019-10-25 01:03:52 +02001495static int mv88e6xxx_atu_get_hash(struct mv88e6xxx_chip *chip, u8 *hash)
1496{
1497 if (chip->info->ops->atu_get_hash)
1498 return chip->info->ops->atu_get_hash(chip, hash);
1499
1500 return -EOPNOTSUPP;
1501}
1502
1503static int mv88e6xxx_atu_set_hash(struct mv88e6xxx_chip *chip, u8 hash)
1504{
1505 if (chip->info->ops->atu_set_hash)
1506 return chip->info->ops->atu_set_hash(chip, hash);
1507
1508 return -EOPNOTSUPP;
1509}
1510
Vivien Didelotda9c3592016-02-12 12:09:40 -05001511static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1512 u16 vid_begin, u16 vid_end)
1513{
Vivien Didelot04bed142016-08-31 18:06:13 -04001514 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001515 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001516 int i, err;
1517
Andrew Lunndb06ae412017-09-25 23:32:20 +02001518 /* DSA and CPU ports have to be members of multiple vlans */
1519 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1520 return 0;
1521
Vivien Didelotda9c3592016-02-12 12:09:40 -05001522 if (!vid_begin)
1523 return -EOPNOTSUPP;
1524
Vivien Didelot425d2d32019-08-01 14:36:34 -04001525 vlan.vid = vid_begin - 1;
1526 vlan.valid = false;
1527
Vivien Didelotda9c3592016-02-12 12:09:40 -05001528 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001529 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001530 if (err)
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001531 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001532
1533 if (!vlan.valid)
1534 break;
1535
1536 if (vlan.vid > vid_end)
1537 break;
1538
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001539 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001540 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1541 continue;
1542
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001543 if (!dsa_to_port(ds, i)->slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001544 continue;
1545
Vivien Didelotbd00e052017-05-01 14:05:11 -04001546 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001547 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001548 continue;
1549
Vivien Didelotc8652c82017-10-16 11:12:19 -04001550 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001551 dsa_to_port(ds, port)->bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001552 break; /* same bridge, check next VLAN */
1553
Vivien Didelotc8652c82017-10-16 11:12:19 -04001554 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001555 continue;
1556
Andrew Lunn743fcc22017-11-09 22:29:54 +01001557 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1558 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001559 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001560 return -EOPNOTSUPP;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001561 }
1562 } while (vlan.vid < vid_end);
1563
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001564 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001565}
1566
Vivien Didelotf81ec902016-05-09 13:22:58 -04001567static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1568 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001569{
Vivien Didelot04bed142016-08-31 18:06:13 -04001570 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001571 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1572 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001573 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001574
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001575 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001576 return -EOPNOTSUPP;
1577
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001578 mv88e6xxx_reg_lock(chip);
Vivien Didelot385a0992016-11-04 03:23:31 +01001579 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001580 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001581
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001582 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001583}
1584
Vivien Didelot57d32312016-06-20 13:13:58 -04001585static int
1586mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001587 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001588{
Vivien Didelot04bed142016-08-31 18:06:13 -04001589 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001590 int err;
1591
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001592 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001593 return -EOPNOTSUPP;
1594
Vivien Didelotda9c3592016-02-12 12:09:40 -05001595 /* If the requested port doesn't belong to the same bridge as the VLAN
1596 * members, do not support it (yet) and fallback to software VLAN.
1597 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001598 mv88e6xxx_reg_lock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001599 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1600 vlan->vid_end);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001601 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001602
Vivien Didelot76e398a2015-11-01 12:33:55 -05001603 /* We don't need any dynamic resource from the kernel (yet),
1604 * so skip the prepare phase.
1605 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001606 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001607}
1608
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001609static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1610 const unsigned char *addr, u16 vid,
1611 u8 state)
1612{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001613 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001614 struct mv88e6xxx_vtu_entry vlan;
1615 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001616 int err;
1617
1618 /* Null VLAN ID corresponds to the port private database */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001619 if (vid == 0) {
1620 err = mv88e6xxx_port_get_fid(chip, port, &fid);
1621 if (err)
1622 return err;
1623 } else {
1624 vlan.vid = vid - 1;
1625 vlan.valid = false;
1626
1627 err = mv88e6xxx_vtu_getnext(chip, &vlan);
1628 if (err)
1629 return err;
1630
1631 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1632 if (vlan.vid != vid || !vlan.valid)
1633 return -EOPNOTSUPP;
1634
1635 fid = vlan.fid;
1636 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001637
Vivien Didelotd8291a92019-09-07 16:00:47 -04001638 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001639 ether_addr_copy(entry.mac, addr);
1640 eth_addr_dec(entry.mac);
1641
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001642 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001643 if (err)
1644 return err;
1645
1646 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001647 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001648 memset(&entry, 0, sizeof(entry));
1649 ether_addr_copy(entry.mac, addr);
1650 }
1651
1652 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001653 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001654 entry.portvec &= ~BIT(port);
1655 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001656 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001657 } else {
1658 entry.portvec |= BIT(port);
1659 entry.state = state;
1660 }
1661
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001662 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001663}
1664
Vivien Didelotda7dc872019-09-07 16:00:49 -04001665static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1666 const struct mv88e6xxx_policy *policy)
1667{
1668 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1669 enum mv88e6xxx_policy_action action = policy->action;
1670 const u8 *addr = policy->addr;
1671 u16 vid = policy->vid;
1672 u8 state;
1673 int err;
1674 int id;
1675
1676 if (!chip->info->ops->port_set_policy)
1677 return -EOPNOTSUPP;
1678
1679 switch (mapping) {
1680 case MV88E6XXX_POLICY_MAPPING_DA:
1681 case MV88E6XXX_POLICY_MAPPING_SA:
1682 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1683 state = 0; /* Dissociate the port and address */
1684 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1685 is_multicast_ether_addr(addr))
1686 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1687 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1688 is_unicast_ether_addr(addr))
1689 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1690 else
1691 return -EOPNOTSUPP;
1692
1693 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1694 state);
1695 if (err)
1696 return err;
1697 break;
1698 default:
1699 return -EOPNOTSUPP;
1700 }
1701
1702 /* Skip the port's policy clearing if the mapping is still in use */
1703 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1704 idr_for_each_entry(&chip->policies, policy, id)
1705 if (policy->port == port &&
1706 policy->mapping == mapping &&
1707 policy->action != action)
1708 return 0;
1709
1710 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1711}
1712
1713static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1714 struct ethtool_rx_flow_spec *fs)
1715{
1716 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1717 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1718 enum mv88e6xxx_policy_mapping mapping;
1719 enum mv88e6xxx_policy_action action;
1720 struct mv88e6xxx_policy *policy;
1721 u16 vid = 0;
1722 u8 *addr;
1723 int err;
1724 int id;
1725
1726 if (fs->location != RX_CLS_LOC_ANY)
1727 return -EINVAL;
1728
1729 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1730 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1731 else
1732 return -EOPNOTSUPP;
1733
1734 switch (fs->flow_type & ~FLOW_EXT) {
1735 case ETHER_FLOW:
1736 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1737 is_zero_ether_addr(mac_mask->h_source)) {
1738 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1739 addr = mac_entry->h_dest;
1740 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1741 !is_zero_ether_addr(mac_mask->h_source)) {
1742 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1743 addr = mac_entry->h_source;
1744 } else {
1745 /* Cannot support DA and SA mapping in the same rule */
1746 return -EOPNOTSUPP;
1747 }
1748 break;
1749 default:
1750 return -EOPNOTSUPP;
1751 }
1752
1753 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
Andrew Lunn04844282020-07-05 21:38:08 +02001754 if (fs->m_ext.vlan_tci != htons(0xffff))
Vivien Didelotda7dc872019-09-07 16:00:49 -04001755 return -EOPNOTSUPP;
1756 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1757 }
1758
1759 idr_for_each_entry(&chip->policies, policy, id) {
1760 if (policy->port == port && policy->mapping == mapping &&
1761 policy->action == action && policy->vid == vid &&
1762 ether_addr_equal(policy->addr, addr))
1763 return -EEXIST;
1764 }
1765
1766 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1767 if (!policy)
1768 return -ENOMEM;
1769
1770 fs->location = 0;
1771 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1772 GFP_KERNEL);
1773 if (err) {
1774 devm_kfree(chip->dev, policy);
1775 return err;
1776 }
1777
1778 memcpy(&policy->fs, fs, sizeof(*fs));
1779 ether_addr_copy(policy->addr, addr);
1780 policy->mapping = mapping;
1781 policy->action = action;
1782 policy->port = port;
1783 policy->vid = vid;
1784
1785 err = mv88e6xxx_policy_apply(chip, port, policy);
1786 if (err) {
1787 idr_remove(&chip->policies, fs->location);
1788 devm_kfree(chip->dev, policy);
1789 return err;
1790 }
1791
1792 return 0;
1793}
1794
1795static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1796 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1797{
1798 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1799 struct mv88e6xxx_chip *chip = ds->priv;
1800 struct mv88e6xxx_policy *policy;
1801 int err;
1802 int id;
1803
1804 mv88e6xxx_reg_lock(chip);
1805
1806 switch (rxnfc->cmd) {
1807 case ETHTOOL_GRXCLSRLCNT:
1808 rxnfc->data = 0;
1809 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1810 rxnfc->rule_cnt = 0;
1811 idr_for_each_entry(&chip->policies, policy, id)
1812 if (policy->port == port)
1813 rxnfc->rule_cnt++;
1814 err = 0;
1815 break;
1816 case ETHTOOL_GRXCLSRULE:
1817 err = -ENOENT;
1818 policy = idr_find(&chip->policies, fs->location);
1819 if (policy) {
1820 memcpy(fs, &policy->fs, sizeof(*fs));
1821 err = 0;
1822 }
1823 break;
1824 case ETHTOOL_GRXCLSRLALL:
1825 rxnfc->data = 0;
1826 rxnfc->rule_cnt = 0;
1827 idr_for_each_entry(&chip->policies, policy, id)
1828 if (policy->port == port)
1829 rule_locs[rxnfc->rule_cnt++] = id;
1830 err = 0;
1831 break;
1832 default:
1833 err = -EOPNOTSUPP;
1834 break;
1835 }
1836
1837 mv88e6xxx_reg_unlock(chip);
1838
1839 return err;
1840}
1841
1842static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1843 struct ethtool_rxnfc *rxnfc)
1844{
1845 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1846 struct mv88e6xxx_chip *chip = ds->priv;
1847 struct mv88e6xxx_policy *policy;
1848 int err;
1849
1850 mv88e6xxx_reg_lock(chip);
1851
1852 switch (rxnfc->cmd) {
1853 case ETHTOOL_SRXCLSRLINS:
1854 err = mv88e6xxx_policy_insert(chip, port, fs);
1855 break;
1856 case ETHTOOL_SRXCLSRLDEL:
1857 err = -ENOENT;
1858 policy = idr_remove(&chip->policies, fs->location);
1859 if (policy) {
1860 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
1861 err = mv88e6xxx_policy_apply(chip, port, policy);
1862 devm_kfree(chip->dev, policy);
1863 }
1864 break;
1865 default:
1866 err = -EOPNOTSUPP;
1867 break;
1868 }
1869
1870 mv88e6xxx_reg_unlock(chip);
1871
1872 return err;
1873}
1874
Andrew Lunn87fa8862017-11-09 22:29:56 +01001875static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1876 u16 vid)
1877{
1878 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1879 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1880
1881 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1882}
1883
1884static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1885{
1886 int port;
1887 int err;
1888
1889 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1890 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1891 if (err)
1892 return err;
1893 }
1894
1895 return 0;
1896}
1897
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001898static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00001899 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001900{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001901 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001902 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001903 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001904
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001905 if (!vid)
1906 return -EOPNOTSUPP;
1907
1908 vlan.vid = vid - 1;
1909 vlan.valid = false;
1910
1911 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001912 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001913 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001914
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001915 if (vlan.vid != vid || !vlan.valid) {
1916 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001917
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001918 err = mv88e6xxx_atu_new(chip, &vlan.fid);
1919 if (err)
1920 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01001921
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001922 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1923 if (i == port)
1924 vlan.member[i] = member;
1925 else
1926 vlan.member[i] = non_member;
1927
1928 vlan.vid = vid;
1929 vlan.valid = true;
1930
1931 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1932 if (err)
1933 return err;
1934
1935 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
1936 if (err)
1937 return err;
1938 } else if (vlan.member[port] != member) {
1939 vlan.member[port] = member;
1940
1941 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1942 if (err)
1943 return err;
Russell King933b4422020-02-26 17:14:26 +00001944 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001945 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
1946 port, vid);
1947 }
1948
1949 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001950}
1951
Vivien Didelotf81ec902016-05-09 13:22:58 -04001952static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001953 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001954{
Vivien Didelot04bed142016-08-31 18:06:13 -04001955 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001956 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1957 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Russell King933b4422020-02-26 17:14:26 +00001958 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001959 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001960 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001961
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001962 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001963 return;
1964
Vivien Didelotc91498e2017-06-07 18:12:13 -04001965 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001966 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001967 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001968 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001969 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001970 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001971
Russell King933b4422020-02-26 17:14:26 +00001972 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
1973 * and then the CPU port. Do not warn for duplicates for the CPU port.
1974 */
1975 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
1976
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001977 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001978
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001979 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Russell King933b4422020-02-26 17:14:26 +00001980 if (mv88e6xxx_port_vlan_join(chip, port, vid, member, warn))
Vivien Didelot774439e52017-06-08 18:34:08 -04001981 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
1982 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001983
Vivien Didelot77064f32016-11-04 03:23:30 +01001984 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04001985 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
1986 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001987
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001988 mv88e6xxx_reg_unlock(chip);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001989}
1990
Vivien Didelot521098922019-08-01 14:36:36 -04001991static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
1992 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001993{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001994 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001995 int i, err;
1996
Vivien Didelot521098922019-08-01 14:36:36 -04001997 if (!vid)
1998 return -EOPNOTSUPP;
1999
2000 vlan.vid = vid - 1;
2001 vlan.valid = false;
2002
2003 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002004 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002005 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002006
Vivien Didelot521098922019-08-01 14:36:36 -04002007 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2008 * tell switchdev that this VLAN is likely handled in software.
2009 */
2010 if (vlan.vid != vid || !vlan.valid ||
2011 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002012 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002013
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002014 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002015
2016 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002017 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002018 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002019 if (vlan.member[i] !=
2020 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002021 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002022 break;
2023 }
2024 }
2025
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002026 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002027 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002028 return err;
2029
Vivien Didelote606ca32017-03-11 16:12:55 -05002030 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002031}
2032
Vivien Didelotf81ec902016-05-09 13:22:58 -04002033static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2034 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002035{
Vivien Didelot04bed142016-08-31 18:06:13 -04002036 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002037 u16 pvid, vid;
2038 int err = 0;
2039
Vivien Didelot3cf3c842017-05-01 14:05:10 -04002040 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04002041 return -EOPNOTSUPP;
2042
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002043 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002044
Vivien Didelot77064f32016-11-04 03:23:30 +01002045 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002046 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002047 goto unlock;
2048
Vivien Didelot76e398a2015-11-01 12:33:55 -05002049 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelot521098922019-08-01 14:36:36 -04002050 err = mv88e6xxx_port_vlan_leave(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002051 if (err)
2052 goto unlock;
2053
2054 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01002055 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002056 if (err)
2057 goto unlock;
2058 }
2059 }
2060
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002061unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002062 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002063
2064 return err;
2065}
2066
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002067static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2068 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002069{
Vivien Didelot04bed142016-08-31 18:06:13 -04002070 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002071 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002072
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002073 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002074 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2075 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002076 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002077
2078 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002079}
2080
Vivien Didelotf81ec902016-05-09 13:22:58 -04002081static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002082 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002083{
Vivien Didelot04bed142016-08-31 18:06:13 -04002084 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002085 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002086
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002087 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002088 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002089 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002090
Vivien Didelot83dabd12016-08-31 11:50:04 -04002091 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002092}
2093
Vivien Didelot83dabd12016-08-31 11:50:04 -04002094static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2095 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002096 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002097{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002098 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002099 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002100 int err;
2101
Vivien Didelotd8291a92019-09-07 16:00:47 -04002102 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002103 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002104
2105 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002106 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002107 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002108 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002109
Vivien Didelotd8291a92019-09-07 16:00:47 -04002110 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002111 break;
2112
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002113 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002114 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002115
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002116 if (!is_unicast_ether_addr(addr.mac))
2117 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002118
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002119 is_static = (addr.state ==
2120 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2121 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002122 if (err)
2123 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002124 } while (!is_broadcast_ether_addr(addr.mac));
2125
2126 return err;
2127}
2128
Vivien Didelot83dabd12016-08-31 11:50:04 -04002129static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002130 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002131{
Vivien Didelot425d2d32019-08-01 14:36:34 -04002132 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002133 u16 fid;
2134 int err;
2135
2136 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002137 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002138 if (err)
2139 return err;
2140
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002141 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002142 if (err)
2143 return err;
2144
2145 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot425d2d32019-08-01 14:36:34 -04002146 vlan.vid = chip->info->max_vid;
2147 vlan.valid = false;
2148
Vivien Didelot83dabd12016-08-31 11:50:04 -04002149 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04002150 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002151 if (err)
2152 return err;
2153
2154 if (!vlan.valid)
2155 break;
2156
2157 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002158 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002159 if (err)
2160 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04002161 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002162
2163 return err;
2164}
2165
Vivien Didelotf81ec902016-05-09 13:22:58 -04002166static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002167 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002168{
Vivien Didelot04bed142016-08-31 18:06:13 -04002169 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002170 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002171
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002172 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002173 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002174 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002175
2176 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002177}
2178
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002179static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2180 struct net_device *br)
2181{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002182 struct dsa_switch *ds = chip->ds;
2183 struct dsa_switch_tree *dst = ds->dst;
2184 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002185 int err;
2186
Vivien Didelotef2025e2019-10-21 16:51:27 -04002187 list_for_each_entry(dp, &dst->ports, list) {
2188 if (dp->bridge_dev == br) {
2189 if (dp->ds == ds) {
2190 /* This is a local bridge group member,
2191 * remap its Port VLAN Map.
2192 */
2193 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2194 if (err)
2195 return err;
2196 } else {
2197 /* This is an external bridge group member,
2198 * remap its cross-chip Port VLAN Table entry.
2199 */
2200 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2201 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002202 if (err)
2203 return err;
2204 }
2205 }
2206 }
2207
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002208 return 0;
2209}
2210
Vivien Didelotf81ec902016-05-09 13:22:58 -04002211static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002212 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002213{
Vivien Didelot04bed142016-08-31 18:06:13 -04002214 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002215 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002216
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002217 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002218 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002219 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002220
Vivien Didelot466dfa02016-02-26 13:16:05 -05002221 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002222}
2223
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002224static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2225 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002226{
Vivien Didelot04bed142016-08-31 18:06:13 -04002227 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002228
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002229 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002230 if (mv88e6xxx_bridge_map(chip, br) ||
2231 mv88e6xxx_port_vlan_map(chip, port))
2232 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002233 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002234}
2235
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002236static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds,
2237 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002238 int port, struct net_device *br)
2239{
2240 struct mv88e6xxx_chip *chip = ds->priv;
2241 int err;
2242
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002243 if (tree_index != ds->dst->index)
2244 return 0;
2245
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002246 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002247 err = mv88e6xxx_pvt_map(chip, sw_index, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002248 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002249
2250 return err;
2251}
2252
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002253static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds,
2254 int tree_index, int sw_index,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002255 int port, struct net_device *br)
2256{
2257 struct mv88e6xxx_chip *chip = ds->priv;
2258
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002259 if (tree_index != ds->dst->index)
2260 return;
2261
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002262 mv88e6xxx_reg_lock(chip);
Vladimir Olteanf66a6a62020-05-10 19:37:41 +03002263 if (mv88e6xxx_pvt_map(chip, sw_index, port))
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002264 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002265 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002266}
2267
Vivien Didelot17e708b2016-12-05 17:30:27 -05002268static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2269{
2270 if (chip->info->ops->reset)
2271 return chip->info->ops->reset(chip);
2272
2273 return 0;
2274}
2275
Vivien Didelot309eca62016-12-05 17:30:26 -05002276static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2277{
2278 struct gpio_desc *gpiod = chip->reset;
2279
2280 /* If there is a GPIO connected to the reset pin, toggle it */
2281 if (gpiod) {
2282 gpiod_set_value_cansleep(gpiod, 1);
2283 usleep_range(10000, 20000);
2284 gpiod_set_value_cansleep(gpiod, 0);
2285 usleep_range(10000, 20000);
2286 }
2287}
2288
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002289static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2290{
2291 int i, err;
2292
2293 /* Set all ports to the Disabled state */
2294 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002295 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002296 if (err)
2297 return err;
2298 }
2299
2300 /* Wait for transmit queues to drain,
2301 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2302 */
2303 usleep_range(2000, 4000);
2304
2305 return 0;
2306}
2307
Vivien Didelotfad09c72016-06-21 12:28:20 -04002308static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002309{
Vivien Didelota935c052016-09-29 12:21:53 -04002310 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002311
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002312 err = mv88e6xxx_disable_ports(chip);
2313 if (err)
2314 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002315
Vivien Didelot309eca62016-12-05 17:30:26 -05002316 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002317
Vivien Didelot17e708b2016-12-05 17:30:27 -05002318 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002319}
2320
Vivien Didelot43145572017-03-11 16:12:59 -05002321static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002322 enum mv88e6xxx_frame_mode frame,
2323 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002324{
2325 int err;
2326
Vivien Didelot43145572017-03-11 16:12:59 -05002327 if (!chip->info->ops->port_set_frame_mode)
2328 return -EOPNOTSUPP;
2329
2330 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002331 if (err)
2332 return err;
2333
Vivien Didelot43145572017-03-11 16:12:59 -05002334 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2335 if (err)
2336 return err;
2337
2338 if (chip->info->ops->port_set_ether_type)
2339 return chip->info->ops->port_set_ether_type(chip, port, etype);
2340
2341 return 0;
2342}
2343
2344static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2345{
2346 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002347 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002348 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002349}
2350
2351static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2352{
2353 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002354 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002355 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002356}
2357
2358static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2359{
2360 return mv88e6xxx_set_port_mode(chip, port,
2361 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002362 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2363 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002364}
2365
2366static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2367{
2368 if (dsa_is_dsa_port(chip->ds, port))
2369 return mv88e6xxx_set_port_mode_dsa(chip, port);
2370
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002371 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002372 return mv88e6xxx_set_port_mode_normal(chip, port);
2373
2374 /* Setup CPU port mode depending on its supported tag format */
2375 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2376 return mv88e6xxx_set_port_mode_dsa(chip, port);
2377
2378 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2379 return mv88e6xxx_set_port_mode_edsa(chip, port);
2380
2381 return -EINVAL;
2382}
2383
Vivien Didelotea698f42017-03-11 16:12:50 -05002384static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2385{
2386 bool message = dsa_is_dsa_port(chip->ds, port);
2387
2388 return mv88e6xxx_port_set_message_port(chip, port, message);
2389}
2390
Vivien Didelot601aeed2017-03-11 16:13:00 -05002391static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2392{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002393 struct dsa_switch *ds = chip->ds;
David S. Miller407308f2019-06-15 13:35:29 -07002394 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002395
David S. Miller407308f2019-06-15 13:35:29 -07002396 /* Upstream ports flood frames with unknown unicast or multicast DA */
2397 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2398 if (chip->info->ops->port_set_egress_floods)
2399 return chip->info->ops->port_set_egress_floods(chip, port,
2400 flood, flood);
Vivien Didelot601aeed2017-03-11 16:13:00 -05002401
David S. Miller407308f2019-06-15 13:35:29 -07002402 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002403}
2404
Vivien Didelot45de77f2019-08-31 16:18:36 -04002405static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2406{
2407 struct mv88e6xxx_port *mvp = dev_id;
2408 struct mv88e6xxx_chip *chip = mvp->chip;
2409 irqreturn_t ret = IRQ_NONE;
2410 int port = mvp->port;
2411 u8 lane;
2412
2413 mv88e6xxx_reg_lock(chip);
2414 lane = mv88e6xxx_serdes_get_lane(chip, port);
2415 if (lane)
2416 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2417 mv88e6xxx_reg_unlock(chip);
2418
2419 return ret;
2420}
2421
2422static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
2423 u8 lane)
2424{
2425 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2426 unsigned int irq;
2427 int err;
2428
2429 /* Nothing to request if this SERDES port has no IRQ */
2430 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2431 if (!irq)
2432 return 0;
2433
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002434 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2435 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2436
Vivien Didelot45de77f2019-08-31 16:18:36 -04002437 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2438 mv88e6xxx_reg_unlock(chip);
2439 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002440 IRQF_ONESHOT, dev_id->serdes_irq_name,
2441 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002442 mv88e6xxx_reg_lock(chip);
2443 if (err)
2444 return err;
2445
2446 dev_id->serdes_irq = irq;
2447
2448 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2449}
2450
2451static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
2452 u8 lane)
2453{
2454 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2455 unsigned int irq = dev_id->serdes_irq;
2456 int err;
2457
2458 /* Nothing to free if no IRQ has been requested */
2459 if (!irq)
2460 return 0;
2461
2462 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2463
2464 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2465 mv88e6xxx_reg_unlock(chip);
2466 free_irq(irq, dev_id);
2467 mv88e6xxx_reg_lock(chip);
2468
2469 dev_id->serdes_irq = 0;
2470
2471 return err;
2472}
2473
Andrew Lunn6d917822017-05-26 01:03:21 +02002474static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2475 bool on)
2476{
Vivien Didelotdc272f62019-08-31 16:18:33 -04002477 u8 lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002478 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002479
Vivien Didelotdc272f62019-08-31 16:18:33 -04002480 lane = mv88e6xxx_serdes_get_lane(chip, port);
2481 if (!lane)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002482 return 0;
2483
2484 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002485 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002486 if (err)
2487 return err;
2488
Vivien Didelot45de77f2019-08-31 16:18:36 -04002489 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002490 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002491 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2492 if (err)
2493 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002494
Vivien Didelotdc272f62019-08-31 16:18:33 -04002495 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002496 }
2497
2498 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002499}
2500
Vivien Didelotfa371c82017-12-05 15:34:10 -05002501static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2502{
2503 struct dsa_switch *ds = chip->ds;
2504 int upstream_port;
2505 int err;
2506
Vivien Didelot07073c72017-12-05 15:34:13 -05002507 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002508 if (chip->info->ops->port_set_upstream_port) {
2509 err = chip->info->ops->port_set_upstream_port(chip, port,
2510 upstream_port);
2511 if (err)
2512 return err;
2513 }
2514
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002515 if (port == upstream_port) {
2516 if (chip->info->ops->set_cpu_port) {
2517 err = chip->info->ops->set_cpu_port(chip,
2518 upstream_port);
2519 if (err)
2520 return err;
2521 }
2522
2523 if (chip->info->ops->set_egress_port) {
2524 err = chip->info->ops->set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002525 MV88E6XXX_EGRESS_DIR_INGRESS,
2526 upstream_port);
2527 if (err)
2528 return err;
2529
2530 err = chip->info->ops->set_egress_port(chip,
2531 MV88E6XXX_EGRESS_DIR_EGRESS,
2532 upstream_port);
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002533 if (err)
2534 return err;
2535 }
2536 }
2537
Vivien Didelotfa371c82017-12-05 15:34:10 -05002538 return 0;
2539}
2540
Vivien Didelotfad09c72016-06-21 12:28:20 -04002541static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002542{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002543 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002544 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002545 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002546
Andrew Lunn7b898462018-08-09 15:38:47 +02002547 chip->ports[port].chip = chip;
2548 chip->ports[port].port = port;
2549
Vivien Didelotd78343d2016-11-04 03:23:36 +01002550 /* MAC Forcing register: don't force link, speed, duplex or flow control
2551 * state to any particular values on physical ports, but force the CPU
2552 * port and all DSA ports to their maximum bandwidth and full duplex.
2553 */
2554 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2555 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2556 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002557 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002558 PHY_INTERFACE_MODE_NA);
2559 else
2560 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2561 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002562 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002563 PHY_INTERFACE_MODE_NA);
2564 if (err)
2565 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002566
2567 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2568 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2569 * tunneling, determine priority by looking at 802.1p and IP
2570 * priority fields (IP prio has precedence), and set STP state
2571 * to Forwarding.
2572 *
2573 * If this is the CPU link, use DSA or EDSA tagging depending
2574 * on which tagging mode was configured.
2575 *
2576 * If this is a link to another switch, use DSA tagging mode.
2577 *
2578 * If this is the upstream port for this switch, enable
2579 * forwarding of unknown unicasts and multicasts.
2580 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002581 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2582 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2583 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2584 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002585 if (err)
2586 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002587
Vivien Didelot601aeed2017-03-11 16:13:00 -05002588 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002589 if (err)
2590 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002591
Vivien Didelot601aeed2017-03-11 16:13:00 -05002592 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002593 if (err)
2594 return err;
2595
Vivien Didelot8efdda42015-08-13 12:52:23 -04002596 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002597 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002598 * untagged frames on this port, do a destination address lookup on all
2599 * received packets as usual, disable ARP mirroring and don't send a
2600 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002601 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002602 err = mv88e6xxx_port_set_map_da(chip, port);
2603 if (err)
2604 return err;
2605
Vivien Didelotfa371c82017-12-05 15:34:10 -05002606 err = mv88e6xxx_setup_upstream_port(chip, port);
2607 if (err)
2608 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002609
Andrew Lunna23b2962017-02-04 20:15:28 +01002610 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002611 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002612 if (err)
2613 return err;
2614
Vivien Didelotcd782652017-06-08 18:34:13 -04002615 if (chip->info->ops->port_set_jumbo_size) {
2616 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002617 if (err)
2618 return err;
2619 }
2620
Andrew Lunn54d792f2015-05-06 01:09:47 +02002621 /* Port Association Vector: when learning source addresses
2622 * of packets, add the address to the address database using
2623 * a port bitmap that has only the bit for this port set and
2624 * the other bits clear.
2625 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002626 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002627 /* Disable learning for CPU port */
2628 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002629 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002630
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002631 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2632 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002633 if (err)
2634 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002635
2636 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002637 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2638 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002639 if (err)
2640 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002641
Vivien Didelot08984322017-06-08 18:34:12 -04002642 if (chip->info->ops->port_pause_limit) {
2643 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002644 if (err)
2645 return err;
2646 }
2647
Vivien Didelotc8c94892017-03-11 16:13:01 -05002648 if (chip->info->ops->port_disable_learn_limit) {
2649 err = chip->info->ops->port_disable_learn_limit(chip, port);
2650 if (err)
2651 return err;
2652 }
2653
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002654 if (chip->info->ops->port_disable_pri_override) {
2655 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002656 if (err)
2657 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002658 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002659
Andrew Lunnef0a7312016-12-03 04:35:16 +01002660 if (chip->info->ops->port_tag_remap) {
2661 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002662 if (err)
2663 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002664 }
2665
Andrew Lunnef70b112016-12-03 04:45:18 +01002666 if (chip->info->ops->port_egress_rate_limiting) {
2667 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002668 if (err)
2669 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002670 }
2671
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002672 if (chip->info->ops->port_setup_message_port) {
2673 err = chip->info->ops->port_setup_message_port(chip, port);
2674 if (err)
2675 return err;
2676 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002677
Vivien Didelot207afda2016-04-14 14:42:09 -04002678 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002679 * database, and allow bidirectional communication between the
2680 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002681 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002682 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002683 if (err)
2684 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002685
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002686 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002687 if (err)
2688 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002689
2690 /* Default VLAN ID and priority: don't set a default VLAN
2691 * ID, and set the default packet priority to zero.
2692 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002693 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002694}
2695
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002696static int mv88e6xxx_get_max_mtu(struct dsa_switch *ds, int port)
2697{
2698 struct mv88e6xxx_chip *chip = ds->priv;
2699
2700 if (chip->info->ops->port_set_jumbo_size)
2701 return 10240;
Chris Packham1baf0fa2020-07-24 11:21:22 +12002702 else if (chip->info->ops->set_max_frame_size)
2703 return 1632;
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002704 return 1522;
2705}
2706
2707static int mv88e6xxx_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
2708{
2709 struct mv88e6xxx_chip *chip = ds->priv;
2710 int ret = 0;
2711
2712 mv88e6xxx_reg_lock(chip);
2713 if (chip->info->ops->port_set_jumbo_size)
2714 ret = chip->info->ops->port_set_jumbo_size(chip, port, new_mtu);
Chris Packham1baf0fa2020-07-24 11:21:22 +12002715 else if (chip->info->ops->set_max_frame_size)
2716 ret = chip->info->ops->set_max_frame_size(chip, new_mtu);
Andrew Lunn2a550ae2020-07-11 22:32:05 +02002717 else
2718 if (new_mtu > 1522)
2719 ret = -EINVAL;
2720 mv88e6xxx_reg_unlock(chip);
2721
2722 return ret;
2723}
2724
Andrew Lunn04aca992017-05-26 01:03:24 +02002725static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2726 struct phy_device *phydev)
2727{
2728 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002729 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002730
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002731 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002732 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002733 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002734
2735 return err;
2736}
2737
Andrew Lunn75104db2019-02-24 20:44:43 +01002738static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02002739{
2740 struct mv88e6xxx_chip *chip = ds->priv;
2741
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002742 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002743 if (mv88e6xxx_serdes_power(chip, port, false))
2744 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002745 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002746}
2747
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002748static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2749 unsigned int ageing_time)
2750{
Vivien Didelot04bed142016-08-31 18:06:13 -04002751 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002752 int err;
2753
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002754 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05002755 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002756 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002757
2758 return err;
2759}
2760
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002761static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002762{
2763 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002764
Andrew Lunnde2273872016-11-21 23:27:01 +01002765 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002766 if (chip->info->ops->stats_set_histogram) {
2767 err = chip->info->ops->stats_set_histogram(chip);
2768 if (err)
2769 return err;
2770 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002771
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002772 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002773}
2774
Andrew Lunnea890982019-01-09 00:24:03 +01002775/* Check if the errata has already been applied. */
2776static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
2777{
2778 int port;
2779 int err;
2780 u16 val;
2781
2782 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002783 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01002784 if (err) {
2785 dev_err(chip->dev,
2786 "Error reading hidden register: %d\n", err);
2787 return false;
2788 }
2789 if (val != 0x01c0)
2790 return false;
2791 }
2792
2793 return true;
2794}
2795
2796/* The 6390 copper ports have an errata which require poking magic
2797 * values into undocumented hidden registers and then performing a
2798 * software reset.
2799 */
2800static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
2801{
2802 int port;
2803 int err;
2804
2805 if (mv88e6390_setup_errata_applied(chip))
2806 return 0;
2807
2808 /* Set the ports into blocking mode */
2809 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2810 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
2811 if (err)
2812 return err;
2813 }
2814
2815 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002816 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01002817 if (err)
2818 return err;
2819 }
2820
2821 return mv88e6xxx_software_reset(chip);
2822}
2823
Andrew Lunn23e8b472019-10-25 01:03:52 +02002824enum mv88e6xxx_devlink_param_id {
2825 MV88E6XXX_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
2826 MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH,
2827};
2828
2829static int mv88e6xxx_devlink_param_get(struct dsa_switch *ds, u32 id,
2830 struct devlink_param_gset_ctx *ctx)
2831{
2832 struct mv88e6xxx_chip *chip = ds->priv;
2833 int err;
2834
2835 mv88e6xxx_reg_lock(chip);
2836
2837 switch (id) {
2838 case MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH:
2839 err = mv88e6xxx_atu_get_hash(chip, &ctx->val.vu8);
2840 break;
2841 default:
2842 err = -EOPNOTSUPP;
2843 break;
2844 }
2845
2846 mv88e6xxx_reg_unlock(chip);
2847
2848 return err;
2849}
2850
2851static int mv88e6xxx_devlink_param_set(struct dsa_switch *ds, u32 id,
2852 struct devlink_param_gset_ctx *ctx)
2853{
2854 struct mv88e6xxx_chip *chip = ds->priv;
2855 int err;
2856
2857 mv88e6xxx_reg_lock(chip);
2858
2859 switch (id) {
2860 case MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH:
2861 err = mv88e6xxx_atu_set_hash(chip, ctx->val.vu8);
2862 break;
2863 default:
2864 err = -EOPNOTSUPP;
2865 break;
2866 }
2867
2868 mv88e6xxx_reg_unlock(chip);
2869
2870 return err;
2871}
2872
2873static const struct devlink_param mv88e6xxx_devlink_params[] = {
2874 DSA_DEVLINK_PARAM_DRIVER(MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH,
2875 "ATU_hash", DEVLINK_PARAM_TYPE_U8,
2876 BIT(DEVLINK_PARAM_CMODE_RUNTIME)),
2877};
2878
2879static int mv88e6xxx_setup_devlink_params(struct dsa_switch *ds)
2880{
2881 return dsa_devlink_params_register(ds, mv88e6xxx_devlink_params,
2882 ARRAY_SIZE(mv88e6xxx_devlink_params));
2883}
2884
2885static void mv88e6xxx_teardown_devlink_params(struct dsa_switch *ds)
2886{
2887 dsa_devlink_params_unregister(ds, mv88e6xxx_devlink_params,
2888 ARRAY_SIZE(mv88e6xxx_devlink_params));
2889}
2890
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002891enum mv88e6xxx_devlink_resource_id {
2892 MV88E6XXX_RESOURCE_ID_ATU,
2893 MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
2894 MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
2895 MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
2896 MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
2897};
2898
2899static u64 mv88e6xxx_devlink_atu_bin_get(struct mv88e6xxx_chip *chip,
2900 u16 bin)
2901{
2902 u16 occupancy = 0;
2903 int err;
2904
2905 mv88e6xxx_reg_lock(chip);
2906
2907 err = mv88e6xxx_g2_atu_stats_set(chip, MV88E6XXX_G2_ATU_STATS_MODE_ALL,
2908 bin);
2909 if (err) {
2910 dev_err(chip->dev, "failed to set ATU stats kind/bin\n");
2911 goto unlock;
2912 }
2913
2914 err = mv88e6xxx_g1_atu_get_next(chip, 0);
2915 if (err) {
2916 dev_err(chip->dev, "failed to perform ATU get next\n");
2917 goto unlock;
2918 }
2919
2920 err = mv88e6xxx_g2_atu_stats_get(chip, &occupancy);
2921 if (err) {
2922 dev_err(chip->dev, "failed to get ATU stats\n");
2923 goto unlock;
2924 }
2925
Andrew Lunn012fc742020-03-11 21:02:31 +01002926 occupancy &= MV88E6XXX_G2_ATU_STATS_MASK;
2927
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002928unlock:
2929 mv88e6xxx_reg_unlock(chip);
2930
2931 return occupancy;
2932}
2933
2934static u64 mv88e6xxx_devlink_atu_bin_0_get(void *priv)
2935{
2936 struct mv88e6xxx_chip *chip = priv;
2937
2938 return mv88e6xxx_devlink_atu_bin_get(chip,
2939 MV88E6XXX_G2_ATU_STATS_BIN_0);
2940}
2941
2942static u64 mv88e6xxx_devlink_atu_bin_1_get(void *priv)
2943{
2944 struct mv88e6xxx_chip *chip = priv;
2945
2946 return mv88e6xxx_devlink_atu_bin_get(chip,
2947 MV88E6XXX_G2_ATU_STATS_BIN_1);
2948}
2949
2950static u64 mv88e6xxx_devlink_atu_bin_2_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_2);
2956}
2957
2958static u64 mv88e6xxx_devlink_atu_bin_3_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_3);
2964}
2965
2966static u64 mv88e6xxx_devlink_atu_get(void *priv)
2967{
2968 return mv88e6xxx_devlink_atu_bin_0_get(priv) +
2969 mv88e6xxx_devlink_atu_bin_1_get(priv) +
2970 mv88e6xxx_devlink_atu_bin_2_get(priv) +
2971 mv88e6xxx_devlink_atu_bin_3_get(priv);
2972}
2973
2974static int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
2975{
2976 struct devlink_resource_size_params size_params;
2977 struct mv88e6xxx_chip *chip = ds->priv;
2978 int err;
2979
2980 devlink_resource_size_params_init(&size_params,
2981 mv88e6xxx_num_macs(chip),
2982 mv88e6xxx_num_macs(chip),
2983 1, DEVLINK_RESOURCE_UNIT_ENTRY);
2984
2985 err = dsa_devlink_resource_register(ds, "ATU",
2986 mv88e6xxx_num_macs(chip),
2987 MV88E6XXX_RESOURCE_ID_ATU,
2988 DEVLINK_RESOURCE_ID_PARENT_TOP,
2989 &size_params);
2990 if (err)
2991 goto out;
2992
2993 devlink_resource_size_params_init(&size_params,
2994 mv88e6xxx_num_macs(chip) / 4,
2995 mv88e6xxx_num_macs(chip) / 4,
2996 1, DEVLINK_RESOURCE_UNIT_ENTRY);
2997
2998 err = dsa_devlink_resource_register(ds, "ATU_bin_0",
2999 mv88e6xxx_num_macs(chip) / 4,
3000 MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
3001 MV88E6XXX_RESOURCE_ID_ATU,
3002 &size_params);
3003 if (err)
3004 goto out;
3005
3006 err = dsa_devlink_resource_register(ds, "ATU_bin_1",
3007 mv88e6xxx_num_macs(chip) / 4,
3008 MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
3009 MV88E6XXX_RESOURCE_ID_ATU,
3010 &size_params);
3011 if (err)
3012 goto out;
3013
3014 err = dsa_devlink_resource_register(ds, "ATU_bin_2",
3015 mv88e6xxx_num_macs(chip) / 4,
3016 MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
3017 MV88E6XXX_RESOURCE_ID_ATU,
3018 &size_params);
3019 if (err)
3020 goto out;
3021
3022 err = dsa_devlink_resource_register(ds, "ATU_bin_3",
3023 mv88e6xxx_num_macs(chip) / 4,
3024 MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
3025 MV88E6XXX_RESOURCE_ID_ATU,
3026 &size_params);
3027 if (err)
3028 goto out;
3029
3030 dsa_devlink_resource_occ_get_register(ds,
3031 MV88E6XXX_RESOURCE_ID_ATU,
3032 mv88e6xxx_devlink_atu_get,
3033 chip);
3034
3035 dsa_devlink_resource_occ_get_register(ds,
3036 MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
3037 mv88e6xxx_devlink_atu_bin_0_get,
3038 chip);
3039
3040 dsa_devlink_resource_occ_get_register(ds,
3041 MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
3042 mv88e6xxx_devlink_atu_bin_1_get,
3043 chip);
3044
3045 dsa_devlink_resource_occ_get_register(ds,
3046 MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
3047 mv88e6xxx_devlink_atu_bin_2_get,
3048 chip);
3049
3050 dsa_devlink_resource_occ_get_register(ds,
3051 MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
3052 mv88e6xxx_devlink_atu_bin_3_get,
3053 chip);
3054
3055 return 0;
3056
3057out:
3058 dsa_devlink_resources_unregister(ds);
3059 return err;
3060}
3061
Andrew Lunn23e8b472019-10-25 01:03:52 +02003062static void mv88e6xxx_teardown(struct dsa_switch *ds)
3063{
3064 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003065 dsa_devlink_resources_unregister(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02003066}
3067
Vivien Didelotf81ec902016-05-09 13:22:58 -04003068static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07003069{
Vivien Didelot04bed142016-08-31 18:06:13 -04003070 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003071 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04003072 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04003073 int i;
3074
Vivien Didelotfad09c72016-06-21 12:28:20 -04003075 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003076 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003077
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003078 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003079
Andrew Lunnea890982019-01-09 00:24:03 +01003080 if (chip->info->ops->setup_errata) {
3081 err = chip->info->ops->setup_errata(chip);
3082 if (err)
3083 goto unlock;
3084 }
3085
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003086 /* Cache the cmode of each port. */
3087 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3088 if (chip->info->ops->port_get_cmode) {
3089 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
3090 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03003091 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003092
3093 chip->ports[i].cmode = cmode;
3094 }
3095 }
3096
Vivien Didelot97299342016-07-18 20:45:30 -04003097 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04003098 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04003099 if (dsa_is_unused_port(ds, i))
3100 continue;
3101
Hubert Feursteinc8574862019-07-31 10:23:48 +02003102 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04003103 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02003104 dev_err(chip->dev, "port %d is invalid\n", i);
3105 err = -EINVAL;
3106 goto unlock;
3107 }
3108
Vivien Didelot97299342016-07-18 20:45:30 -04003109 err = mv88e6xxx_setup_port(chip, i);
3110 if (err)
3111 goto unlock;
3112 }
3113
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003114 err = mv88e6xxx_irl_setup(chip);
3115 if (err)
3116 goto unlock;
3117
Vivien Didelot04a69a12017-10-13 14:18:05 -04003118 err = mv88e6xxx_mac_setup(chip);
3119 if (err)
3120 goto unlock;
3121
Vivien Didelot1b17aed2017-05-26 18:03:05 -04003122 err = mv88e6xxx_phy_setup(chip);
3123 if (err)
3124 goto unlock;
3125
Vivien Didelotb486d7c2017-05-01 14:05:13 -04003126 err = mv88e6xxx_vtu_setup(chip);
3127 if (err)
3128 goto unlock;
3129
Vivien Didelot81228992017-03-30 17:37:08 -04003130 err = mv88e6xxx_pvt_setup(chip);
3131 if (err)
3132 goto unlock;
3133
Vivien Didelota2ac29d2017-03-11 16:12:49 -05003134 err = mv88e6xxx_atu_setup(chip);
3135 if (err)
3136 goto unlock;
3137
Andrew Lunn87fa8862017-11-09 22:29:56 +01003138 err = mv88e6xxx_broadcast_setup(chip, 0);
3139 if (err)
3140 goto unlock;
3141
Vivien Didelot9e907d72017-07-17 13:03:43 -04003142 err = mv88e6xxx_pot_setup(chip);
3143 if (err)
3144 goto unlock;
3145
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003146 err = mv88e6xxx_rmu_setup(chip);
3147 if (err)
3148 goto unlock;
3149
Vivien Didelot51c901a2017-07-17 13:03:41 -04003150 err = mv88e6xxx_rsvd2cpu_setup(chip);
3151 if (err)
3152 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01003153
Vivien Didelotb28f8722018-04-26 21:56:44 -04003154 err = mv88e6xxx_trunk_setup(chip);
3155 if (err)
3156 goto unlock;
3157
Vivien Didelotc7f047b2018-04-26 21:56:45 -04003158 err = mv88e6xxx_devmap_setup(chip);
3159 if (err)
3160 goto unlock;
3161
Vivien Didelot93e18d62018-05-11 17:16:35 -04003162 err = mv88e6xxx_pri_setup(chip);
3163 if (err)
3164 goto unlock;
3165
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003166 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003167 if (chip->info->ptp_support) {
3168 err = mv88e6xxx_ptp_setup(chip);
3169 if (err)
3170 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003171
3172 err = mv88e6xxx_hwtstamp_setup(chip);
3173 if (err)
3174 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003175 }
3176
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003177 err = mv88e6xxx_stats_setup(chip);
3178 if (err)
3179 goto unlock;
3180
Vivien Didelot6b17e862015-08-13 12:52:18 -04003181unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003182 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02003183
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003184 if (err)
3185 return err;
3186
3187 /* Have to be called without holding the register lock, since
3188 * they take the devlink lock, and we later take the locks in
3189 * the reverse order when getting/setting parameters or
3190 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02003191 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003192 err = mv88e6xxx_setup_devlink_resources(ds);
3193 if (err)
3194 return err;
3195
3196 err = mv88e6xxx_setup_devlink_params(ds);
3197 if (err)
3198 dsa_devlink_resources_unregister(ds);
3199
3200 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003201}
3202
Vivien Didelote57e5e72016-08-15 17:19:00 -04003203static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003204{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003205 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3206 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003207 u16 val;
3208 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003209
Andrew Lunnee26a222017-01-24 14:53:48 +01003210 if (!chip->info->ops->phy_read)
3211 return -EOPNOTSUPP;
3212
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003213 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003214 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003215 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003216
Andrew Lunnda9f3302017-02-01 03:40:05 +01003217 if (reg == MII_PHYSID2) {
Andrew Lunnddc49ac2018-11-12 18:51:01 +01003218 /* Some internal PHYs don't have a model number. */
3219 if (chip->info->family != MV88E6XXX_FAMILY_6165)
3220 /* Then there is the 6165 family. It gets is
3221 * PHYs correct. But it can also have two
3222 * SERDES interfaces in the PHY address
3223 * space. And these don't have a model
3224 * number. But they are not PHYs, so we don't
3225 * want to give them something a PHY driver
3226 * will recognise.
3227 *
3228 * Use the mv88e6390 family model number
3229 * instead, for anything which really could be
3230 * a PHY,
3231 */
3232 if (!(val & 0x3f0))
3233 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003234 }
3235
Vivien Didelote57e5e72016-08-15 17:19:00 -04003236 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003237}
3238
Vivien Didelote57e5e72016-08-15 17:19:00 -04003239static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003240{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003241 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3242 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003243 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003244
Andrew Lunnee26a222017-01-24 14:53:48 +01003245 if (!chip->info->ops->phy_write)
3246 return -EOPNOTSUPP;
3247
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003248 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003249 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003250 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003251
3252 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003253}
3254
Vivien Didelotfad09c72016-06-21 12:28:20 -04003255static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003256 struct device_node *np,
3257 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003258{
3259 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003260 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003261 struct mii_bus *bus;
3262 int err;
3263
Andrew Lunn2510bab2018-02-22 01:51:49 +01003264 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003265 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003266 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003267 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003268
3269 if (err)
3270 return err;
3271 }
3272
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003273 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003274 if (!bus)
3275 return -ENOMEM;
3276
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003277 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003278 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003279 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003280 INIT_LIST_HEAD(&mdio_bus->list);
3281 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003282
Andrew Lunnb516d452016-06-04 21:17:06 +02003283 if (np) {
3284 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003285 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003286 } else {
3287 bus->name = "mv88e6xxx SMI";
3288 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3289 }
3290
3291 bus->read = mv88e6xxx_mdio_read;
3292 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003293 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003294
Andrew Lunn6f882842018-03-17 20:32:05 +01003295 if (!external) {
3296 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3297 if (err)
3298 return err;
3299 }
3300
Florian Fainelli00e798c2018-05-15 16:56:19 -07003301 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003302 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003303 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003304 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003305 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003306 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003307
3308 if (external)
3309 list_add_tail(&mdio_bus->list, &chip->mdios);
3310 else
3311 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003312
3313 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003314}
3315
Andrew Lunna3c53be52017-01-24 14:53:50 +01003316static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
3317 { .compatible = "marvell,mv88e6xxx-mdio-external",
3318 .data = (void *)true },
3319 { },
3320};
3321
Andrew Lunn3126aee2017-12-07 01:05:57 +01003322static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3323
3324{
3325 struct mv88e6xxx_mdio_bus *mdio_bus;
3326 struct mii_bus *bus;
3327
3328 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3329 bus = mdio_bus->bus;
3330
Andrew Lunn6f882842018-03-17 20:32:05 +01003331 if (!mdio_bus->external)
3332 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3333
Andrew Lunn3126aee2017-12-07 01:05:57 +01003334 mdiobus_unregister(bus);
3335 }
3336}
3337
Andrew Lunna3c53be52017-01-24 14:53:50 +01003338static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3339 struct device_node *np)
3340{
3341 const struct of_device_id *match;
3342 struct device_node *child;
3343 int err;
3344
3345 /* Always register one mdio bus for the internal/default mdio
3346 * bus. This maybe represented in the device tree, but is
3347 * optional.
3348 */
3349 child = of_get_child_by_name(np, "mdio");
3350 err = mv88e6xxx_mdio_register(chip, child, false);
3351 if (err)
3352 return err;
3353
3354 /* Walk the device tree, and see if there are any other nodes
3355 * which say they are compatible with the external mdio
3356 * bus.
3357 */
3358 for_each_available_child_of_node(np, child) {
3359 match = of_match_node(mv88e6xxx_mdio_external_match, child);
3360 if (match) {
3361 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003362 if (err) {
3363 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303364 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003365 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003366 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003367 }
3368 }
3369
3370 return 0;
3371}
3372
Vivien Didelot855b1932016-07-20 18:18:35 -04003373static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3374{
Vivien Didelot04bed142016-08-31 18:06:13 -04003375 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003376
3377 return chip->eeprom_len;
3378}
3379
Vivien Didelot855b1932016-07-20 18:18:35 -04003380static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3381 struct ethtool_eeprom *eeprom, u8 *data)
3382{
Vivien Didelot04bed142016-08-31 18:06:13 -04003383 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003384 int err;
3385
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003386 if (!chip->info->ops->get_eeprom)
3387 return -EOPNOTSUPP;
3388
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003389 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003390 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003391 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003392
3393 if (err)
3394 return err;
3395
3396 eeprom->magic = 0xc3ec4951;
3397
3398 return 0;
3399}
3400
Vivien Didelot855b1932016-07-20 18:18:35 -04003401static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3402 struct ethtool_eeprom *eeprom, u8 *data)
3403{
Vivien Didelot04bed142016-08-31 18:06:13 -04003404 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003405 int err;
3406
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003407 if (!chip->info->ops->set_eeprom)
3408 return -EOPNOTSUPP;
3409
Vivien Didelot855b1932016-07-20 18:18:35 -04003410 if (eeprom->magic != 0xc3ec4951)
3411 return -EINVAL;
3412
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003413 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003414 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003415 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003416
3417 return err;
3418}
3419
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003420static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003421 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003422 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3423 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003424 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003425 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003426 .phy_read = mv88e6185_phy_ppu_read,
3427 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003428 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003429 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003430 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003431 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003432 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003433 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003434 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003435 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003436 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003437 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003438 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003439 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003440 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003441 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003442 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3443 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003444 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003445 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3446 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003447 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003448 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003449 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003450 .ppu_enable = mv88e6185_g1_ppu_enable,
3451 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003452 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003453 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003454 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003455 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003456 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003457 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003458};
3459
3460static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003461 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003462 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3463 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003464 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003465 .phy_read = mv88e6185_phy_ppu_read,
3466 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003467 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003468 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003469 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003470 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01003471 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003472 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003473 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003474 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003475 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003476 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3477 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003478 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003479 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003480 .ppu_enable = mv88e6185_g1_ppu_enable,
3481 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003482 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003483 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003484 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003485 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003486 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003487};
3488
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003489static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003490 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003491 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3492 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003493 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003494 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3495 .phy_read = mv88e6xxx_g2_smi_phy_read,
3496 .phy_write = mv88e6xxx_g2_smi_phy_write,
3497 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003498 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003499 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003500 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003501 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003502 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003503 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003504 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003505 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003506 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003507 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003508 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003509 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003510 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003511 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3512 .stats_get_strings = mv88e6095_stats_get_strings,
3513 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003514 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3515 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003516 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003517 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003518 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003519 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003520 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003521 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003522 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003523 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003524 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003525};
3526
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003527static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003528 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003529 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3530 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003531 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003532 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003533 .phy_read = mv88e6xxx_g2_smi_phy_read,
3534 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003535 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003536 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003537 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003538 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003539 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003540 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003541 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003542 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003543 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003544 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003545 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3546 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003547 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003548 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3549 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003550 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003551 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003552 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003553 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003554 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3555 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003556 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003557 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003558 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003559 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003560};
3561
3562static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003563 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003564 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3565 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003566 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003567 .phy_read = mv88e6185_phy_ppu_read,
3568 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003569 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003570 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003571 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003572 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003573 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003574 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003575 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003576 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003577 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003578 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003579 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003580 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003581 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003582 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003583 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003584 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3585 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003586 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003587 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3588 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003589 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003590 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003591 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003592 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003593 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003594 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003595 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003596 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003597 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003598};
3599
Vivien Didelot990e27b2017-03-28 13:50:32 -04003600static const struct mv88e6xxx_ops mv88e6141_ops = {
3601 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003602 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3603 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003604 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003605 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3606 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3607 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3608 .phy_read = mv88e6xxx_g2_smi_phy_read,
3609 .phy_write = mv88e6xxx_g2_smi_phy_write,
3610 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003611 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003612 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003613 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003614 .port_tag_remap = mv88e6095_port_tag_remap,
3615 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3616 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3617 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003618 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003619 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003620 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003621 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3622 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003623 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003624 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003625 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003626 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003627 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003628 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3629 .stats_get_strings = mv88e6320_stats_get_strings,
3630 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003631 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3632 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003633 .watchdog_ops = &mv88e6390_watchdog_ops,
3634 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003635 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003636 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003637 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003638 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003639 .serdes_power = mv88e6390_serdes_power,
3640 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003641 /* Check status register pause & lpa register */
3642 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3643 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3644 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3645 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003646 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003647 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003648 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003649 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003650 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003651};
3652
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003653static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003654 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003655 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3656 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003657 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003658 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003659 .phy_read = mv88e6xxx_g2_smi_phy_read,
3660 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003661 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003662 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003663 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003664 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003665 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003666 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003667 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003668 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003669 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003670 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003671 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003672 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003673 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003674 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003675 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003676 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3677 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003678 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003679 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3680 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003681 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003682 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003683 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003684 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003685 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3686 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003687 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003688 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003689 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003690 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003691 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003692};
3693
3694static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003695 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003696 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3697 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003698 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003699 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003700 .phy_read = mv88e6165_phy_read,
3701 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003702 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003703 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003704 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003705 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003706 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003707 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003708 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003709 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003710 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3711 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003712 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003713 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3714 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003715 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003716 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003717 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003718 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003719 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3720 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003721 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003722 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003723 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003724 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003725 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003726};
3727
3728static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003729 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003730 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3731 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003732 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003733 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003734 .phy_read = mv88e6xxx_g2_smi_phy_read,
3735 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003736 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003737 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003738 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003739 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003740 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003741 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003742 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003743 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003744 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003745 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003746 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003747 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003748 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003749 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003750 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003751 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003752 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3753 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003754 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003755 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3756 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003757 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003758 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003759 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003760 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003761 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3762 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003763 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003764 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003765 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003766};
3767
3768static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003769 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003770 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3771 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003772 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003773 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3774 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003775 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003776 .phy_read = mv88e6xxx_g2_smi_phy_read,
3777 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003778 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003779 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003780 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003781 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003782 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003783 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003784 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003785 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003786 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003787 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003788 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003789 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003790 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003791 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003792 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003793 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003794 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003795 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3796 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003797 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003798 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3799 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003800 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003801 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003802 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003803 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003804 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003805 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3806 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003807 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003808 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003809 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003810 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3811 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3812 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3813 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003814 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003815 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3816 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003817 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003818 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003819};
3820
3821static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003822 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003823 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3824 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003825 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003826 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003827 .phy_read = mv88e6xxx_g2_smi_phy_read,
3828 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003829 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003830 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003831 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003832 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003833 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003834 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003835 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003836 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003837 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003838 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003839 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003840 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003841 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003842 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003843 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003844 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003845 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3846 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003847 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003848 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3849 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003850 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003851 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003852 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003853 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003854 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3855 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003856 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003857 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003858 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003859};
3860
3861static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003862 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003863 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3864 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003865 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003866 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3867 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003868 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003869 .phy_read = mv88e6xxx_g2_smi_phy_read,
3870 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003871 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003872 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003873 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003874 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003875 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003876 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003877 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003878 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003879 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003880 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003881 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003882 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003883 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003884 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003885 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003886 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003887 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003888 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3889 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003890 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003891 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3892 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003893 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003894 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003895 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003896 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003897 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003898 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3899 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003900 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003901 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003902 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003903 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3904 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3905 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3906 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003907 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003908 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003909 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003910 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003911 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3912 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003913 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003914 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003915};
3916
3917static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003918 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003919 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3920 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003921 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003922 .phy_read = mv88e6185_phy_ppu_read,
3923 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003924 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00003925 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003926 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003927 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003928 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003929 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02003930 .port_set_pause = mv88e6185_port_set_pause,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003931 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003932 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003933 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003934 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003935 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3936 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003937 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003938 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3939 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003940 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003941 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelot02317e62018-05-09 11:38:49 -04003942 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003943 .ppu_enable = mv88e6185_g1_ppu_enable,
3944 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003945 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003946 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003947 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003948 .phylink_validate = mv88e6185_phylink_validate,
Chris Packham1baf0fa2020-07-24 11:21:22 +12003949 .set_max_frame_size = mv88e6185_g1_set_max_frame_size,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003950};
3951
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003952static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003953 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003954 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003955 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003956 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3957 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003958 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3959 .phy_read = mv88e6xxx_g2_smi_phy_read,
3960 .phy_write = mv88e6xxx_g2_smi_phy_write,
3961 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003962 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00003963 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003964 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003965 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003966 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003967 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003968 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003969 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12003970 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04003971 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003972 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003973 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003974 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003975 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003976 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003977 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003978 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003979 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3980 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003981 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003982 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3983 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003984 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003985 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003986 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003987 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003988 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003989 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3990 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04003991 .vtu_getnext = mv88e6390_g1_vtu_getnext,
3992 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02003993 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02003994 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003995 /* Check status register pause & lpa register */
3996 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3997 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3998 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3999 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004000 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004001 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004002 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004003 .serdes_get_strings = mv88e6390_serdes_get_strings,
4004 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004005 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4006 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004007 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004008 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004009};
4010
4011static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004012 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004013 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004014 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004015 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4016 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004017 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4018 .phy_read = mv88e6xxx_g2_smi_phy_read,
4019 .phy_write = mv88e6xxx_g2_smi_phy_write,
4020 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004021 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004022 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004023 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004024 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004025 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004026 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004027 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004028 .port_set_ether_type = mv88e6351_port_set_ether_type,
Chris Packhame8b34c62020-07-24 11:21:21 +12004029 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot08984322017-06-08 18:34:12 -04004030 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004031 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004032 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004033 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004034 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004035 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004036 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004037 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004038 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4039 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004040 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004041 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4042 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004043 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004044 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004045 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004046 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004047 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004048 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4049 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004050 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4051 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004052 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004053 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004054 /* Check status register pause & lpa register */
4055 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4056 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4057 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4058 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004059 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004060 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004061 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004062 .serdes_get_strings = mv88e6390_serdes_get_strings,
4063 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004064 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4065 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004066 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004067 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004068};
4069
4070static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004071 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004072 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004073 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004074 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4075 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004076 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4077 .phy_read = mv88e6xxx_g2_smi_phy_read,
4078 .phy_write = mv88e6xxx_g2_smi_phy_write,
4079 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004080 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004081 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004082 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004083 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004084 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004085 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004086 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004087 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004088 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004089 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004090 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004091 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004092 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004093 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004094 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004095 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4096 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004097 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004098 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4099 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004100 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004101 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004102 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004103 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004104 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004105 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4106 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004107 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4108 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004109 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004110 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004111 /* Check status register pause & lpa register */
4112 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4113 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4114 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4115 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004116 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004117 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004118 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004119 .serdes_get_strings = mv88e6390_serdes_get_strings,
4120 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004121 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4122 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004123 .avb_ops = &mv88e6390_avb_ops,
4124 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004125 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004126};
4127
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004128static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004129 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004130 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4131 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004132 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004133 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4134 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004135 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004136 .phy_read = mv88e6xxx_g2_smi_phy_read,
4137 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004138 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004139 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004140 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004141 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004142 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004143 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004144 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004145 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004146 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004147 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004148 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004149 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004150 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004151 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004152 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004153 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004154 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004155 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4156 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004157 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004158 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4159 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004160 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004161 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004162 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004163 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004164 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004165 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4166 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004167 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004168 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004169 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004170 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4171 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4172 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4173 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004174 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004175 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004176 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004177 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004178 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4179 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004180 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004181 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004182 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004183 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004184};
4185
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004186static const struct mv88e6xxx_ops mv88e6250_ops = {
4187 /* MV88E6XXX_FAMILY_6250 */
4188 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4189 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4190 .irl_init_all = mv88e6352_g2_irl_init_all,
4191 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4192 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4193 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4194 .phy_read = mv88e6xxx_g2_smi_phy_read,
4195 .phy_write = mv88e6xxx_g2_smi_phy_write,
4196 .port_set_link = mv88e6xxx_port_set_link,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004197 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004198 .port_set_speed_duplex = mv88e6250_port_set_speed_duplex,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004199 .port_tag_remap = mv88e6095_port_tag_remap,
4200 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4201 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
4202 .port_set_ether_type = mv88e6351_port_set_ether_type,
4203 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4204 .port_pause_limit = mv88e6097_port_pause_limit,
4205 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004206 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4207 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4208 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4209 .stats_get_strings = mv88e6250_stats_get_strings,
4210 .stats_get_stats = mv88e6250_stats_get_stats,
4211 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4212 .set_egress_port = mv88e6095_g1_set_egress_port,
4213 .watchdog_ops = &mv88e6250_watchdog_ops,
4214 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4215 .pot_clear = mv88e6xxx_g2_pot_clear,
4216 .reset = mv88e6250_g1_reset,
4217 .vtu_getnext = mv88e6250_g1_vtu_getnext,
4218 .vtu_loadpurge = mv88e6250_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004219 .avb_ops = &mv88e6352_avb_ops,
4220 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004221 .phylink_validate = mv88e6065_phylink_validate,
4222};
4223
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004224static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004225 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004226 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004227 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004228 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4229 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004230 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4231 .phy_read = mv88e6xxx_g2_smi_phy_read,
4232 .phy_write = mv88e6xxx_g2_smi_phy_write,
4233 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004234 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004235 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004236 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004237 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004238 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004239 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004240 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004241 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004242 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004243 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004244 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004245 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004246 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004247 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004248 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004249 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004250 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4251 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004252 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004253 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4254 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004255 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004256 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004257 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004258 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004259 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004260 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4261 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004262 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4263 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004264 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004265 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004266 /* Check status register pause & lpa register */
4267 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4268 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4269 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4270 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004271 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004272 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004273 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004274 .serdes_get_strings = mv88e6390_serdes_get_strings,
4275 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004276 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4277 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004278 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004279 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004280 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004281 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004282};
4283
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004284static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004285 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004286 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4287 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004288 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004289 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4290 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004291 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004292 .phy_read = mv88e6xxx_g2_smi_phy_read,
4293 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004294 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004295 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004296 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004297 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004298 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004299 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004300 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004301 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004302 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004303 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004304 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004305 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004306 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004307 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004308 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004309 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4310 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004311 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004312 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4313 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004314 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004315 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004316 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004317 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004318 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004319 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004320 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004321 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004322 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004323 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004324};
4325
4326static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004327 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004328 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4329 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004330 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004331 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4332 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004333 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004334 .phy_read = mv88e6xxx_g2_smi_phy_read,
4335 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004336 .port_set_link = mv88e6xxx_port_set_link,
Russell Kingf365c6f2020-03-14 10:15:53 +00004337 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004338 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004339 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004340 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004341 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004342 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004343 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004344 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004345 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004346 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004347 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004348 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004349 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004350 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004351 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4352 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004353 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004354 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4355 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004356 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004357 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004358 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004359 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004360 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004361 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004362 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004363 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004364};
4365
Vivien Didelot16e329a2017-03-28 13:50:33 -04004366static const struct mv88e6xxx_ops mv88e6341_ops = {
4367 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004368 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4369 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004370 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004371 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4372 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4373 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4374 .phy_read = mv88e6xxx_g2_smi_phy_read,
4375 .phy_write = mv88e6xxx_g2_smi_phy_write,
4376 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004377 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004378 .port_set_speed_duplex = mv88e6341_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004379 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004380 .port_tag_remap = mv88e6095_port_tag_remap,
4381 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4382 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
4383 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004384 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004385 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004386 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004387 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4388 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004389 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004390 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004391 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004392 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004393 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004394 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4395 .stats_get_strings = mv88e6320_stats_get_strings,
4396 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004397 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4398 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004399 .watchdog_ops = &mv88e6390_watchdog_ops,
4400 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004401 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004402 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004403 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004404 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004405 .serdes_power = mv88e6390_serdes_power,
4406 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004407 /* Check status register pause & lpa register */
4408 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4409 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4410 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4411 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004412 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004413 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004414 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004415 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004416 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004417 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01004418 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004419};
4420
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004421static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004422 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004423 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4424 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004425 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004426 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004427 .phy_read = mv88e6xxx_g2_smi_phy_read,
4428 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004429 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004430 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004431 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004432 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004433 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004434 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004435 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004436 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004437 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004438 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004439 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004440 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004441 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004442 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004443 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004444 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004445 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4446 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004447 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004448 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4449 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004450 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004451 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004452 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004453 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004454 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4455 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004456 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004457 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004458 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004459};
4460
4461static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004462 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004463 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4464 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004465 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004466 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004467 .phy_read = mv88e6xxx_g2_smi_phy_read,
4468 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004469 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004470 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004471 .port_set_speed_duplex = mv88e6185_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004472 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004473 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004474 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004475 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004476 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004477 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004478 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004479 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004480 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004481 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004482 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004483 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004484 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004485 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4486 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004487 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004488 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4489 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004490 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004491 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004492 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004493 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004494 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4495 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004496 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004497 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004498 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004499 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004500 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004501};
4502
4503static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004504 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004505 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4506 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004507 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004508 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4509 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004510 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004511 .phy_read = mv88e6xxx_g2_smi_phy_read,
4512 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004513 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004514 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004515 .port_set_speed_duplex = mv88e6352_port_set_speed_duplex,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004516 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004517 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004518 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004519 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004520 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004521 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004522 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004523 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004524 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004525 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004526 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004527 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004528 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004529 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004530 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4531 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004532 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004533 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4534 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004535 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004536 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004537 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004538 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004539 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004540 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4541 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004542 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004543 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004544 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004545 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4546 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4547 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4548 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004549 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004550 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004551 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004552 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004553 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004554 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004555 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004556 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4557 .serdes_get_strings = mv88e6352_serdes_get_strings,
4558 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004559 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4560 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004561 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004562};
4563
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004564static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004565 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004566 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004567 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004568 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4569 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004570 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4571 .phy_read = mv88e6xxx_g2_smi_phy_read,
4572 .phy_write = mv88e6xxx_g2_smi_phy_write,
4573 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004574 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004575 .port_set_speed_duplex = mv88e6390_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004576 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004577 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004578 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004579 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004580 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004581 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004582 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004583 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004584 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004585 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004586 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004587 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004588 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004589 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004590 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004591 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004592 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4593 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004594 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004595 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4596 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004597 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004598 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004599 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004600 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004601 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004602 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4603 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004604 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4605 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004606 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004607 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004608 /* Check status register pause & lpa register */
4609 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4610 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4611 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4612 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004613 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004614 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004615 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004616 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004617 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004618 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004619 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4620 .serdes_get_strings = mv88e6390_serdes_get_strings,
4621 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004622 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4623 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004624 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004625};
4626
4627static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004628 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004629 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004630 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004631 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4632 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004633 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4634 .phy_read = mv88e6xxx_g2_smi_phy_read,
4635 .phy_write = mv88e6xxx_g2_smi_phy_write,
4636 .port_set_link = mv88e6xxx_port_set_link,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004637 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Russell Kingf365c6f2020-03-14 10:15:53 +00004638 .port_set_speed_duplex = mv88e6390x_port_set_speed_duplex,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004639 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004640 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004641 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004642 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004643 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004644 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004645 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004646 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004647 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004648 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004649 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004650 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004651 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004652 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004653 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004654 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004655 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4656 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004657 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004658 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4659 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004660 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004661 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004662 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004663 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004664 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004665 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4666 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004667 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4668 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004669 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004670 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004671 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4672 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4673 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4674 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004675 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004676 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004677 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004678 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4679 .serdes_get_strings = mv88e6390_serdes_get_strings,
4680 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004681 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4682 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004683 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004684 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004685 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004686 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004687};
4688
Vivien Didelotf81ec902016-05-09 13:22:58 -04004689static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4690 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004691 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004692 .family = MV88E6XXX_FAMILY_6097,
4693 .name = "Marvell 88E6085",
4694 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004695 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004696 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004697 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004698 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004699 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004700 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004701 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004702 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004703 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004704 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004705 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004706 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004707 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004708 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004709 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004710 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004711 },
4712
4713 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004714 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004715 .family = MV88E6XXX_FAMILY_6095,
4716 .name = "Marvell 88E6095/88E6095F",
4717 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004718 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004719 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004720 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004721 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004722 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004723 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004724 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004725 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004726 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004727 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004728 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004729 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004730 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004731 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004732 },
4733
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004734 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004735 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004736 .family = MV88E6XXX_FAMILY_6097,
4737 .name = "Marvell 88E6097/88E6097F",
4738 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004739 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004740 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004741 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004742 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004743 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004744 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004745 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004746 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004747 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004748 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004749 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004750 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004751 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004752 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01004753 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004754 .ops = &mv88e6097_ops,
4755 },
4756
Vivien Didelotf81ec902016-05-09 13:22:58 -04004757 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004758 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004759 .family = MV88E6XXX_FAMILY_6165,
4760 .name = "Marvell 88E6123",
4761 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004762 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004763 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004764 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004765 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004766 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004767 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004768 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004769 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004770 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004771 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004772 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004773 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004774 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004775 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004776 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004777 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004778 },
4779
4780 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004781 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004782 .family = MV88E6XXX_FAMILY_6185,
4783 .name = "Marvell 88E6131",
4784 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004785 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004786 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004787 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004788 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004789 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004790 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004791 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004792 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004793 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004794 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004795 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004796 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004797 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004798 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004799 },
4800
Vivien Didelot990e27b2017-03-28 13:50:32 -04004801 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004802 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004803 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01004804 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04004805 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004806 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004807 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004808 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004809 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004810 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004811 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004812 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004813 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004814 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004815 .age_time_coeff = 3750,
4816 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004817 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004818 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004819 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004820 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004821 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004822 .ops = &mv88e6141_ops,
4823 },
4824
Vivien Didelotf81ec902016-05-09 13:22:58 -04004825 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004826 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004827 .family = MV88E6XXX_FAMILY_6165,
4828 .name = "Marvell 88E6161",
4829 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004830 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004831 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004832 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004833 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004834 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004835 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004836 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004837 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004838 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004839 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004840 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004841 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004842 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004843 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004844 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004845 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004846 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004847 },
4848
4849 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004850 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004851 .family = MV88E6XXX_FAMILY_6165,
4852 .name = "Marvell 88E6165",
4853 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004854 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004855 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004856 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004857 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004858 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004859 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004860 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004861 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004862 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004863 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004864 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004865 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004866 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004867 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004868 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004869 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004870 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004871 },
4872
4873 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004874 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004875 .family = MV88E6XXX_FAMILY_6351,
4876 .name = "Marvell 88E6171",
4877 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004878 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004879 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004880 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004881 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004882 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004883 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004884 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004885 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004886 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004887 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004888 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004889 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004890 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004891 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004892 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004893 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004894 },
4895
4896 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004897 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004898 .family = MV88E6XXX_FAMILY_6352,
4899 .name = "Marvell 88E6172",
4900 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004901 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004902 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004903 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004904 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004905 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004906 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004907 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004908 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004909 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004910 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004911 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004912 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004913 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004914 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004915 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004916 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004917 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004918 },
4919
4920 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004921 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004922 .family = MV88E6XXX_FAMILY_6351,
4923 .name = "Marvell 88E6175",
4924 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004925 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004926 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004927 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004928 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004929 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004930 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004931 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004932 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004933 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004934 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004935 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004936 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004937 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004938 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004939 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004940 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004941 },
4942
4943 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004944 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004945 .family = MV88E6XXX_FAMILY_6352,
4946 .name = "Marvell 88E6176",
4947 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004948 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004949 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004950 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004951 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004952 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004953 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004954 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004955 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004956 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004957 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004958 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004959 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004960 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004961 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004962 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004963 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004964 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004965 },
4966
4967 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004968 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004969 .family = MV88E6XXX_FAMILY_6185,
4970 .name = "Marvell 88E6185",
4971 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004972 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004973 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004974 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004975 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004976 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004977 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004978 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004979 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004980 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004981 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004982 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004983 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004984 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004985 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004986 },
4987
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004988 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004989 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004990 .family = MV88E6XXX_FAMILY_6390,
4991 .name = "Marvell 88E6190",
4992 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004993 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004994 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01004995 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004996 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04004997 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004998 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004999 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005000 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005001 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005002 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005003 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005004 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005005 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04005006 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005007 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05005008 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005009 .ops = &mv88e6190_ops,
5010 },
5011
5012 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005013 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005014 .family = MV88E6XXX_FAMILY_6390,
5015 .name = "Marvell 88E6190X",
5016 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005017 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005018 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005019 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005020 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005021 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005022 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005023 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005024 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005025 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005026 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005027 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005028 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005029 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005030 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005031 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005032 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005033 .ops = &mv88e6190x_ops,
5034 },
5035
5036 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005037 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005038 .family = MV88E6XXX_FAMILY_6390,
5039 .name = "Marvell 88E6191",
5040 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005041 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005042 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005043 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04005044 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005045 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005046 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005047 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005048 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005049 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005050 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005051 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005052 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005053 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005054 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005055 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005056 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04005057 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005058 },
5059
Hubert Feurstein49022642019-07-31 10:23:46 +02005060 [MV88E6220] = {
5061 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
5062 .family = MV88E6XXX_FAMILY_6250,
5063 .name = "Marvell 88E6220",
5064 .num_databases = 64,
5065
5066 /* Ports 2-4 are not routed to pins
5067 * => usable ports 0, 1, 5, 6
5068 */
5069 .num_ports = 7,
5070 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02005071 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02005072 .max_vid = 4095,
5073 .port_base_addr = 0x08,
5074 .phy_base_addr = 0x00,
5075 .global1_addr = 0x0f,
5076 .global2_addr = 0x07,
5077 .age_time_coeff = 15000,
5078 .g1_irqs = 9,
5079 .g2_irqs = 10,
5080 .atu_move_port_mask = 0xf,
5081 .dual_chip = true,
5082 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02005083 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02005084 .ops = &mv88e6250_ops,
5085 },
5086
Vivien Didelotf81ec902016-05-09 13:22:58 -04005087 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005088 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005089 .family = MV88E6XXX_FAMILY_6352,
5090 .name = "Marvell 88E6240",
5091 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005092 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005093 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005094 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005095 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005096 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005097 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005098 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005099 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005100 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005101 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005102 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005103 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005104 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005105 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005106 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005107 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005108 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005109 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005110 },
5111
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005112 [MV88E6250] = {
5113 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
5114 .family = MV88E6XXX_FAMILY_6250,
5115 .name = "Marvell 88E6250",
5116 .num_databases = 64,
5117 .num_ports = 7,
5118 .num_internal_phys = 5,
5119 .max_vid = 4095,
5120 .port_base_addr = 0x08,
5121 .phy_base_addr = 0x00,
5122 .global1_addr = 0x0f,
5123 .global2_addr = 0x07,
5124 .age_time_coeff = 15000,
5125 .g1_irqs = 9,
5126 .g2_irqs = 10,
5127 .atu_move_port_mask = 0xf,
5128 .dual_chip = true,
5129 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02005130 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005131 .ops = &mv88e6250_ops,
5132 },
5133
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005134 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005135 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005136 .family = MV88E6XXX_FAMILY_6390,
5137 .name = "Marvell 88E6290",
5138 .num_databases = 4096,
5139 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005140 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005141 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005142 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005143 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005144 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005145 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005146 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005147 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005148 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005149 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005150 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005151 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005152 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005153 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005154 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005155 .ops = &mv88e6290_ops,
5156 },
5157
Vivien Didelotf81ec902016-05-09 13:22:58 -04005158 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005159 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005160 .family = MV88E6XXX_FAMILY_6320,
5161 .name = "Marvell 88E6320",
5162 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005163 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005164 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005165 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005166 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005167 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005168 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005169 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005170 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005171 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005172 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005173 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005174 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005175 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005176 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005177 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005178 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005179 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005180 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005181 },
5182
5183 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005184 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005185 .family = MV88E6XXX_FAMILY_6320,
5186 .name = "Marvell 88E6321",
5187 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005188 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005189 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005190 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005191 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005192 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005193 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005194 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005195 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005196 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005197 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005198 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005199 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005200 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005201 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005202 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005203 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005204 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005205 },
5206
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005207 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005208 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005209 .family = MV88E6XXX_FAMILY_6341,
5210 .name = "Marvell 88E6341",
5211 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005212 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005213 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005214 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005215 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005216 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005217 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005218 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005219 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005220 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005221 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005222 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005223 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005224 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005225 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005226 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005227 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005228 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005229 .ops = &mv88e6341_ops,
5230 },
5231
Vivien Didelotf81ec902016-05-09 13:22:58 -04005232 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005233 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005234 .family = MV88E6XXX_FAMILY_6351,
5235 .name = "Marvell 88E6350",
5236 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005237 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005238 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005239 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005240 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005241 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005242 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005243 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005244 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005245 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005246 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005247 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005248 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005249 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005250 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005251 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005252 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005253 },
5254
5255 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005256 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005257 .family = MV88E6XXX_FAMILY_6351,
5258 .name = "Marvell 88E6351",
5259 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005260 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005261 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005262 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005263 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005264 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005265 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005266 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005267 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005268 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005269 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005270 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005271 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005272 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005273 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005274 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005275 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005276 },
5277
5278 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005279 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005280 .family = MV88E6XXX_FAMILY_6352,
5281 .name = "Marvell 88E6352",
5282 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005283 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005284 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005285 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005286 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005287 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005288 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005289 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005290 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005291 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005292 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005293 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005294 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005295 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005296 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005297 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005298 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005299 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005300 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005301 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005302 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005303 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005304 .family = MV88E6XXX_FAMILY_6390,
5305 .name = "Marvell 88E6390",
5306 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005307 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005308 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005309 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005310 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005311 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005312 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005313 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005314 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005315 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005316 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005317 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005318 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005319 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005320 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005321 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005322 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005323 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005324 .ops = &mv88e6390_ops,
5325 },
5326 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005327 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005328 .family = MV88E6XXX_FAMILY_6390,
5329 .name = "Marvell 88E6390X",
5330 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005331 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005332 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005333 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005334 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005335 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005336 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005337 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005338 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005339 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005340 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005341 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005342 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005343 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005344 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005345 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005346 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005347 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005348 .ops = &mv88e6390x_ops,
5349 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005350};
5351
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005352static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005353{
Vivien Didelota439c062016-04-17 13:23:58 -04005354 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005355
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005356 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5357 if (mv88e6xxx_table[i].prod_num == prod_num)
5358 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005359
Vivien Didelotb9b37712015-10-30 19:39:48 -04005360 return NULL;
5361}
5362
Vivien Didelotfad09c72016-06-21 12:28:20 -04005363static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005364{
5365 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005366 unsigned int prod_num, rev;
5367 u16 id;
5368 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005369
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005370 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005371 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005372 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005373 if (err)
5374 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005375
Vivien Didelot107fcc12017-06-12 12:37:36 -04005376 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5377 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005378
5379 info = mv88e6xxx_lookup_info(prod_num);
5380 if (!info)
5381 return -ENODEV;
5382
Vivien Didelotcaac8542016-06-20 13:14:09 -04005383 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005384 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005385
Vivien Didelotca070c12016-09-02 14:45:34 -04005386 err = mv88e6xxx_g2_require(chip);
5387 if (err)
5388 return err;
5389
Vivien Didelotfad09c72016-06-21 12:28:20 -04005390 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5391 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005392
5393 return 0;
5394}
5395
Vivien Didelotfad09c72016-06-21 12:28:20 -04005396static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005397{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005398 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005399
Vivien Didelotfad09c72016-06-21 12:28:20 -04005400 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5401 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005402 return NULL;
5403
Vivien Didelotfad09c72016-06-21 12:28:20 -04005404 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005405
Vivien Didelotfad09c72016-06-21 12:28:20 -04005406 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005407 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005408 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005409
Vivien Didelotfad09c72016-06-21 12:28:20 -04005410 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005411}
5412
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005413static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005414 int port,
5415 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005416{
Vivien Didelot04bed142016-08-31 18:06:13 -04005417 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005418
Andrew Lunn443d5a12016-12-03 04:35:18 +01005419 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005420}
5421
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005422static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05005423 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005424{
5425 /* We don't need any dynamic resource from the kernel (yet),
5426 * so skip the prepare phase.
5427 */
5428
5429 return 0;
5430}
5431
5432static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05005433 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005434{
Vivien Didelot04bed142016-08-31 18:06:13 -04005435 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005436
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005437 mv88e6xxx_reg_lock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005438 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04005439 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04005440 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
5441 port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005442 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005443}
5444
5445static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5446 const struct switchdev_obj_port_mdb *mdb)
5447{
Vivien Didelot04bed142016-08-31 18:06:13 -04005448 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005449 int err;
5450
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005451 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005452 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005453 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005454
5455 return err;
5456}
5457
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005458static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5459 struct dsa_mall_mirror_tc_entry *mirror,
5460 bool ingress)
5461{
5462 enum mv88e6xxx_egress_direction direction = ingress ?
5463 MV88E6XXX_EGRESS_DIR_INGRESS :
5464 MV88E6XXX_EGRESS_DIR_EGRESS;
5465 struct mv88e6xxx_chip *chip = ds->priv;
5466 bool other_mirrors = false;
5467 int i;
5468 int err;
5469
5470 if (!chip->info->ops->set_egress_port)
5471 return -EOPNOTSUPP;
5472
5473 mutex_lock(&chip->reg_lock);
5474 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5475 mirror->to_local_port) {
5476 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5477 other_mirrors |= ingress ?
5478 chip->ports[i].mirror_ingress :
5479 chip->ports[i].mirror_egress;
5480
5481 /* Can't change egress port when other mirror is active */
5482 if (other_mirrors) {
5483 err = -EBUSY;
5484 goto out;
5485 }
5486
5487 err = chip->info->ops->set_egress_port(chip,
5488 direction,
5489 mirror->to_local_port);
5490 if (err)
5491 goto out;
5492 }
5493
5494 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5495out:
5496 mutex_unlock(&chip->reg_lock);
5497
5498 return err;
5499}
5500
5501static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5502 struct dsa_mall_mirror_tc_entry *mirror)
5503{
5504 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5505 MV88E6XXX_EGRESS_DIR_INGRESS :
5506 MV88E6XXX_EGRESS_DIR_EGRESS;
5507 struct mv88e6xxx_chip *chip = ds->priv;
5508 bool other_mirrors = false;
5509 int i;
5510
5511 mutex_lock(&chip->reg_lock);
5512 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5513 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5514
5515 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5516 other_mirrors |= mirror->ingress ?
5517 chip->ports[i].mirror_ingress :
5518 chip->ports[i].mirror_egress;
5519
5520 /* Reset egress port when no other mirror is active */
5521 if (!other_mirrors) {
5522 if (chip->info->ops->set_egress_port(chip,
5523 direction,
5524 dsa_upstream_port(ds,
Colin Ian King4e4637b2019-11-12 13:05:23 +00005525 port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005526 dev_err(ds->dev, "failed to set egress port\n");
5527 }
5528
5529 mutex_unlock(&chip->reg_lock);
5530}
5531
Russell King4f859012019-02-20 15:35:05 -08005532static int mv88e6xxx_port_egress_floods(struct dsa_switch *ds, int port,
5533 bool unicast, bool multicast)
5534{
5535 struct mv88e6xxx_chip *chip = ds->priv;
5536 int err = -EOPNOTSUPP;
5537
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005538 mv88e6xxx_reg_lock(chip);
Russell King4f859012019-02-20 15:35:05 -08005539 if (chip->info->ops->port_set_egress_floods)
5540 err = chip->info->ops->port_set_egress_floods(chip, port,
5541 unicast,
5542 multicast);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005543 mv88e6xxx_reg_unlock(chip);
Russell King4f859012019-02-20 15:35:05 -08005544
5545 return err;
5546}
5547
Florian Fainellia82f67a2017-01-08 14:52:08 -08005548static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02005549 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005550 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005551 .teardown = mv88e6xxx_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07005552 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00005553 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07005554 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00005555 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07005556 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
5557 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005558 .get_strings = mv88e6xxx_get_strings,
5559 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
5560 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02005561 .port_enable = mv88e6xxx_port_enable,
5562 .port_disable = mv88e6xxx_port_disable,
Andrew Lunn2a550ae2020-07-11 22:32:05 +02005563 .port_max_mtu = mv88e6xxx_get_max_mtu,
5564 .port_change_mtu = mv88e6xxx_change_mtu,
Vivien Didelot08f50062017-08-01 16:32:41 -04005565 .get_mac_eee = mv88e6xxx_get_mac_eee,
5566 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005567 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005568 .get_eeprom = mv88e6xxx_get_eeprom,
5569 .set_eeprom = mv88e6xxx_set_eeprom,
5570 .get_regs_len = mv88e6xxx_get_regs_len,
5571 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04005572 .get_rxnfc = mv88e6xxx_get_rxnfc,
5573 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04005574 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005575 .port_bridge_join = mv88e6xxx_port_bridge_join,
5576 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Russell King4f859012019-02-20 15:35:05 -08005577 .port_egress_floods = mv88e6xxx_port_egress_floods,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005578 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04005579 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005580 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
5581 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
5582 .port_vlan_add = mv88e6xxx_port_vlan_add,
5583 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005584 .port_fdb_add = mv88e6xxx_port_fdb_add,
5585 .port_fdb_del = mv88e6xxx_port_fdb_del,
5586 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005587 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
5588 .port_mdb_add = mv88e6xxx_port_mdb_add,
5589 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005590 .port_mirror_add = mv88e6xxx_port_mirror_add,
5591 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04005592 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
5593 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005594 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
5595 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
5596 .port_txtstamp = mv88e6xxx_port_txtstamp,
5597 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
5598 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005599 .devlink_param_get = mv88e6xxx_devlink_param_get,
5600 .devlink_param_set = mv88e6xxx_devlink_param_set,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005601};
5602
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005603static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005604{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005605 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005606 struct dsa_switch *ds;
5607
Vivien Didelot7e99e342019-10-21 16:51:30 -04005608 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005609 if (!ds)
5610 return -ENOMEM;
5611
Vivien Didelot7e99e342019-10-21 16:51:30 -04005612 ds->dev = dev;
5613 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005614 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005615 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04005616 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04005617 ds->ageing_time_min = chip->info->age_time_coeff;
5618 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005619
5620 dev_set_drvdata(dev, ds);
5621
Vivien Didelot23c9ee42017-05-26 18:12:51 -04005622 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005623}
5624
Vivien Didelotfad09c72016-06-21 12:28:20 -04005625static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005626{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005627 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005628}
5629
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005630static const void *pdata_device_get_match_data(struct device *dev)
5631{
5632 const struct of_device_id *matches = dev->driver->of_match_table;
5633 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
5634
5635 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
5636 matches++) {
5637 if (!strcmp(pdata->compatible, matches->compatible))
5638 return matches->data;
5639 }
5640 return NULL;
5641}
5642
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005643/* There is no suspend to RAM support at DSA level yet, the switch configuration
5644 * would be lost after a power cycle so prevent it to be suspended.
5645 */
5646static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
5647{
5648 return -EOPNOTSUPP;
5649}
5650
5651static int __maybe_unused mv88e6xxx_resume(struct device *dev)
5652{
5653 return 0;
5654}
5655
5656static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
5657
Vivien Didelot57d32312016-06-20 13:13:58 -04005658static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005659{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005660 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04005661 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005662 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005663 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04005664 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005665 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02005666 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005667
Andrew Lunn7bb8c992018-05-31 00:15:42 +02005668 if (!np && !pdata)
5669 return -EINVAL;
5670
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005671 if (np)
5672 compat_info = of_device_get_match_data(dev);
5673
5674 if (pdata) {
5675 compat_info = pdata_device_get_match_data(dev);
5676
5677 if (!pdata->netdev)
5678 return -EINVAL;
5679
5680 for (port = 0; port < DSA_MAX_PORTS; port++) {
5681 if (!(pdata->enabled_ports & (1 << port)))
5682 continue;
5683 if (strcmp(pdata->cd.port_names[port], "cpu"))
5684 continue;
5685 pdata->cd.netdev[port] = &pdata->netdev->dev;
5686 break;
5687 }
5688 }
5689
Vivien Didelotcaac8542016-06-20 13:14:09 -04005690 if (!compat_info)
5691 return -EINVAL;
5692
Vivien Didelotfad09c72016-06-21 12:28:20 -04005693 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005694 if (!chip) {
5695 err = -ENOMEM;
5696 goto out;
5697 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005698
Vivien Didelotfad09c72016-06-21 12:28:20 -04005699 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04005700
Vivien Didelotfad09c72016-06-21 12:28:20 -04005701 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04005702 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005703 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005704
Andrew Lunnb4308f02016-11-21 23:26:55 +01005705 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005706 if (IS_ERR(chip->reset)) {
5707 err = PTR_ERR(chip->reset);
5708 goto out;
5709 }
Baruch Siach7b75e492019-06-27 21:17:39 +03005710 if (chip->reset)
5711 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01005712
Vivien Didelotfad09c72016-06-21 12:28:20 -04005713 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005714 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005715 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005716
Vivien Didelote57e5e72016-08-15 17:19:00 -04005717 mv88e6xxx_phy_init(chip);
5718
Andrew Lunn00baabe2018-05-19 22:31:35 +02005719 if (chip->info->ops->get_eeprom) {
5720 if (np)
5721 of_property_read_u32(np, "eeprom-length",
5722 &chip->eeprom_len);
5723 else
5724 chip->eeprom_len = pdata->eeprom_len;
5725 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005726
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005727 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005728 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005729 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02005730 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02005731 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02005732
Andrew Lunna27415d2019-05-01 00:10:50 +02005733 if (np) {
5734 chip->irq = of_irq_get(np, 0);
5735 if (chip->irq == -EPROBE_DEFER) {
5736 err = chip->irq;
5737 goto out;
5738 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02005739 }
5740
Andrew Lunna27415d2019-05-01 00:10:50 +02005741 if (pdata)
5742 chip->irq = pdata->irq;
5743
Andrew Lunn294d7112018-02-22 22:58:32 +01005744 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01005745 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01005746 * controllers
5747 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005748 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005749 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005750 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005751 else
5752 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005753 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005754
Andrew Lunn294d7112018-02-22 22:58:32 +01005755 if (err)
5756 goto out;
5757
5758 if (chip->info->g2_irqs > 0) {
5759 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005760 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01005761 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005762 }
5763
Andrew Lunn294d7112018-02-22 22:58:32 +01005764 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
5765 if (err)
5766 goto out_g2_irq;
5767
5768 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
5769 if (err)
5770 goto out_g1_atu_prob_irq;
5771
Andrew Lunna3c53be52017-01-24 14:53:50 +01005772 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02005773 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01005774 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005775
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005776 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005777 if (err)
5778 goto out_mdio;
5779
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005780 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02005781
5782out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01005783 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01005784out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005785 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01005786out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005787 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005788out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005789 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005790 mv88e6xxx_g2_irq_free(chip);
5791out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005792 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005793 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005794 else
5795 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005796out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005797 if (pdata)
5798 dev_put(pdata->netdev);
5799
Andrew Lunndc30c352016-10-16 19:56:49 +02005800 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005801}
5802
5803static void mv88e6xxx_remove(struct mdio_device *mdiodev)
5804{
5805 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04005806 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005807
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005808 if (chip->info->ptp_support) {
5809 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005810 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005811 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005812
Andrew Lunn930188c2016-08-22 16:01:03 +02005813 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005814 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005815 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005816
Andrew Lunn76f38f12018-03-17 20:21:09 +01005817 mv88e6xxx_g1_vtu_prob_irq_free(chip);
5818 mv88e6xxx_g1_atu_prob_irq_free(chip);
5819
5820 if (chip->info->g2_irqs > 0)
5821 mv88e6xxx_g2_irq_free(chip);
5822
Andrew Lunn76f38f12018-03-17 20:21:09 +01005823 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005824 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01005825 else
5826 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005827}
5828
5829static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04005830 {
5831 .compatible = "marvell,mv88e6085",
5832 .data = &mv88e6xxx_table[MV88E6085],
5833 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005834 {
5835 .compatible = "marvell,mv88e6190",
5836 .data = &mv88e6xxx_table[MV88E6190],
5837 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005838 {
5839 .compatible = "marvell,mv88e6250",
5840 .data = &mv88e6xxx_table[MV88E6250],
5841 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005842 { /* sentinel */ },
5843};
5844
5845MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
5846
5847static struct mdio_driver mv88e6xxx_driver = {
5848 .probe = mv88e6xxx_probe,
5849 .remove = mv88e6xxx_remove,
5850 .mdiodrv.driver = {
5851 .name = "mv88e6085",
5852 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005853 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005854 },
5855};
5856
Andrew Lunn7324d502019-04-27 19:19:10 +02005857mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00005858
5859MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
5860MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
5861MODULE_LICENSE("GPL");