blob: 548a0c3edfacebd38b9e21d83c47e31affbd1c43 [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{
Andrew Lunna26deec2019-04-18 03:11:39 +0200426 struct phylink_link_state state;
Vivien Didelotd78343d2016-11-04 03:23:36 +0100427 int err;
428
429 if (!chip->info->ops->port_set_link)
430 return 0;
431
Andrew Lunna26deec2019-04-18 03:11:39 +0200432 if (!chip->info->ops->port_link_state)
433 return 0;
434
435 err = chip->info->ops->port_link_state(chip, port, &state);
436 if (err)
437 return err;
438
439 /* Has anything actually changed? We don't expect the
440 * interface mode to change without one of the other
441 * parameters also changing
442 */
443 if (state.link == link &&
444 state.speed == speed &&
Marek Behún927441a2019-08-14 16:40:24 +0200445 state.duplex == duplex &&
446 (state.interface == mode ||
447 state.interface == PHY_INTERFACE_MODE_NA))
Andrew Lunna26deec2019-04-18 03:11:39 +0200448 return 0;
449
Vivien Didelotd78343d2016-11-04 03:23:36 +0100450 /* Port's MAC control must not be changed unless the link is down */
Hubert Feurstein43c8e0a2019-07-30 12:11:42 +0200451 err = chip->info->ops->port_set_link(chip, port, LINK_FORCED_DOWN);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100452 if (err)
453 return err;
454
455 if (chip->info->ops->port_set_speed) {
456 err = chip->info->ops->port_set_speed(chip, port, speed);
457 if (err && err != -EOPNOTSUPP)
458 goto restore_link;
459 }
460
Andrew Lunn7cbbee02019-03-08 01:21:27 +0100461 if (speed == SPEED_MAX && chip->info->ops->port_max_speed_mode)
462 mode = chip->info->ops->port_max_speed_mode(port);
463
Andrew Lunn54186b92018-08-09 15:38:37 +0200464 if (chip->info->ops->port_set_pause) {
465 err = chip->info->ops->port_set_pause(chip, port, pause);
466 if (err)
467 goto restore_link;
468 }
469
Vivien Didelotd78343d2016-11-04 03:23:36 +0100470 if (chip->info->ops->port_set_duplex) {
471 err = chip->info->ops->port_set_duplex(chip, port, duplex);
472 if (err && err != -EOPNOTSUPP)
473 goto restore_link;
474 }
475
Russell King64d47d52020-03-14 10:15:38 +0000476 err = mv88e6xxx_port_config_interface(chip, port, mode);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100477restore_link:
478 if (chip->info->ops->port_set_link(chip, port, link))
Vivien Didelot774439e52017-06-08 18:34:08 -0400479 dev_err(chip->dev, "p%d: failed to restore MAC's link\n", port);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100480
481 return err;
482}
483
Marek Vasutd700ec42018-09-12 00:15:24 +0200484static int mv88e6xxx_phy_is_internal(struct dsa_switch *ds, int port)
485{
486 struct mv88e6xxx_chip *chip = ds->priv;
487
488 return port < chip->info->num_internal_phys;
489}
490
Russell Kinga5a68582020-03-14 10:15:43 +0000491static int mv88e6xxx_serdes_pcs_get_state(struct dsa_switch *ds, int port,
492 struct phylink_link_state *state)
493{
494 struct mv88e6xxx_chip *chip = ds->priv;
495 u8 lane;
496 int err;
497
498 mv88e6xxx_reg_lock(chip);
499 lane = mv88e6xxx_serdes_get_lane(chip, port);
500 if (lane && chip->info->ops->serdes_pcs_get_state)
501 err = chip->info->ops->serdes_pcs_get_state(chip, port, lane,
502 state);
503 else
504 err = -EOPNOTSUPP;
505 mv88e6xxx_reg_unlock(chip);
506
507 return err;
508}
509
510static int mv88e6xxx_serdes_pcs_config(struct mv88e6xxx_chip *chip, int port,
511 unsigned int mode,
512 phy_interface_t interface,
513 const unsigned long *advertise)
514{
515 const struct mv88e6xxx_ops *ops = chip->info->ops;
516 u8 lane;
517
518 if (ops->serdes_pcs_config) {
519 lane = mv88e6xxx_serdes_get_lane(chip, port);
520 if (lane)
521 return ops->serdes_pcs_config(chip, port, lane, mode,
522 interface, advertise);
523 }
524
525 return 0;
526}
527
528static void mv88e6xxx_serdes_pcs_an_restart(struct dsa_switch *ds, int port)
529{
530 struct mv88e6xxx_chip *chip = ds->priv;
531 const struct mv88e6xxx_ops *ops;
532 int err = 0;
533 u8 lane;
534
535 ops = chip->info->ops;
536
537 if (ops->serdes_pcs_an_restart) {
538 mv88e6xxx_reg_lock(chip);
539 lane = mv88e6xxx_serdes_get_lane(chip, port);
540 if (lane)
541 err = ops->serdes_pcs_an_restart(chip, port, lane);
542 mv88e6xxx_reg_unlock(chip);
543
544 if (err)
545 dev_err(ds->dev, "p%d: failed to restart AN\n", port);
546 }
547}
548
549static int mv88e6xxx_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port,
550 unsigned int mode,
551 int speed, int duplex)
552{
553 const struct mv88e6xxx_ops *ops = chip->info->ops;
554 u8 lane;
555
556 if (!phylink_autoneg_inband(mode) && ops->serdes_pcs_link_up) {
557 lane = mv88e6xxx_serdes_get_lane(chip, port);
558 if (lane)
559 return ops->serdes_pcs_link_up(chip, port, lane,
560 speed, duplex);
561 }
562
563 return 0;
564}
565
Russell King6c422e32018-08-09 15:38:39 +0200566static void mv88e6065_phylink_validate(struct mv88e6xxx_chip *chip, int port,
567 unsigned long *mask,
568 struct phylink_link_state *state)
569{
570 if (!phy_interface_mode_is_8023z(state->interface)) {
571 /* 10M and 100M are only supported in non-802.3z mode */
572 phylink_set(mask, 10baseT_Half);
573 phylink_set(mask, 10baseT_Full);
574 phylink_set(mask, 100baseT_Half);
575 phylink_set(mask, 100baseT_Full);
576 }
577}
578
579static void mv88e6185_phylink_validate(struct mv88e6xxx_chip *chip, int port,
580 unsigned long *mask,
581 struct phylink_link_state *state)
582{
583 /* FIXME: if the port is in 1000Base-X mode, then it only supports
584 * 1000M FD speeds. In this case, CMODE will indicate 5.
585 */
586 phylink_set(mask, 1000baseT_Full);
587 phylink_set(mask, 1000baseX_Full);
588
589 mv88e6065_phylink_validate(chip, port, mask, state);
590}
591
Marek Behúne3af71a2019-02-25 12:39:55 +0100592static void mv88e6341_phylink_validate(struct mv88e6xxx_chip *chip, int port,
593 unsigned long *mask,
594 struct phylink_link_state *state)
595{
596 if (port >= 5)
597 phylink_set(mask, 2500baseX_Full);
598
599 /* No ethtool bits for 200Mbps */
600 phylink_set(mask, 1000baseT_Full);
601 phylink_set(mask, 1000baseX_Full);
602
603 mv88e6065_phylink_validate(chip, port, mask, state);
604}
605
Russell King6c422e32018-08-09 15:38:39 +0200606static void mv88e6352_phylink_validate(struct mv88e6xxx_chip *chip, int port,
607 unsigned long *mask,
608 struct phylink_link_state *state)
609{
610 /* No ethtool bits for 200Mbps */
611 phylink_set(mask, 1000baseT_Full);
612 phylink_set(mask, 1000baseX_Full);
613
614 mv88e6065_phylink_validate(chip, port, mask, state);
615}
616
617static void mv88e6390_phylink_validate(struct mv88e6xxx_chip *chip, int port,
618 unsigned long *mask,
619 struct phylink_link_state *state)
620{
Andrew Lunnec260162019-02-08 22:25:44 +0100621 if (port >= 9) {
Russell King6c422e32018-08-09 15:38:39 +0200622 phylink_set(mask, 2500baseX_Full);
Andrew Lunnec260162019-02-08 22:25:44 +0100623 phylink_set(mask, 2500baseT_Full);
624 }
Russell King6c422e32018-08-09 15:38:39 +0200625
626 /* No ethtool bits for 200Mbps */
627 phylink_set(mask, 1000baseT_Full);
628 phylink_set(mask, 1000baseX_Full);
629
630 mv88e6065_phylink_validate(chip, port, mask, state);
631}
632
633static void mv88e6390x_phylink_validate(struct mv88e6xxx_chip *chip, int port,
634 unsigned long *mask,
635 struct phylink_link_state *state)
636{
637 if (port >= 9) {
638 phylink_set(mask, 10000baseT_Full);
639 phylink_set(mask, 10000baseKR_Full);
640 }
641
642 mv88e6390_phylink_validate(chip, port, mask, state);
643}
644
Russell Kingc9a23562018-05-10 13:17:35 -0700645static void mv88e6xxx_validate(struct dsa_switch *ds, int port,
646 unsigned long *supported,
647 struct phylink_link_state *state)
648{
Russell King6c422e32018-08-09 15:38:39 +0200649 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
650 struct mv88e6xxx_chip *chip = ds->priv;
651
652 /* Allow all the expected bits */
653 phylink_set(mask, Autoneg);
654 phylink_set(mask, Pause);
655 phylink_set_port_modes(mask);
656
657 if (chip->info->ops->phylink_validate)
658 chip->info->ops->phylink_validate(chip, port, mask, state);
659
660 bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
661 bitmap_and(state->advertising, state->advertising, mask,
662 __ETHTOOL_LINK_MODE_MASK_NBITS);
663
664 /* We can only operate at 2500BaseX or 1000BaseX. If requested
665 * to advertise both, only report advertising at 2500BaseX.
666 */
667 phylink_helper_basex_speed(state);
Russell Kingc9a23562018-05-10 13:17:35 -0700668}
669
Russell Kingc9a23562018-05-10 13:17:35 -0700670static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
671 unsigned int mode,
672 const struct phylink_link_state *state)
673{
674 struct mv88e6xxx_chip *chip = ds->priv;
Russell King64d47d52020-03-14 10:15:38 +0000675 int err;
Russell Kingc9a23562018-05-10 13:17:35 -0700676
Russell King64d47d52020-03-14 10:15:38 +0000677 /* FIXME: is this the correct test? If we're in fixed mode on an
678 * internal port, why should we process this any different from
679 * PHY mode? On the other hand, the port may be automedia between
680 * an internal PHY and the serdes...
681 */
Marek Vasutd700ec42018-09-12 00:15:24 +0200682 if ((mode == MLO_AN_PHY) && mv88e6xxx_phy_is_internal(ds, port))
Russell Kingc9a23562018-05-10 13:17:35 -0700683 return;
684
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000685 mv88e6xxx_reg_lock(chip);
Russell King64d47d52020-03-14 10:15:38 +0000686 /* FIXME: should we force the link down here - but if we do, how
687 * do we restore the link force/unforce state? The driver layering
688 * gets in the way.
689 */
690 err = mv88e6xxx_port_config_interface(chip, port, state->interface);
Russell Kinga5a68582020-03-14 10:15:43 +0000691 if (err && err != -EOPNOTSUPP)
692 goto err_unlock;
693
694 err = mv88e6xxx_serdes_pcs_config(chip, port, mode, state->interface,
695 state->advertising);
696 /* FIXME: we should restart negotiation if something changed - which
697 * is something we get if we convert to using phylinks PCS operations.
698 */
699 if (err > 0)
700 err = 0;
701
702err_unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000703 mv88e6xxx_reg_unlock(chip);
Russell Kingc9a23562018-05-10 13:17:35 -0700704
705 if (err && err != -EOPNOTSUPP)
Russell King64d47d52020-03-14 10:15:38 +0000706 dev_err(ds->dev, "p%d: failed to configure MAC/PCS\n", port);
Russell Kingc9a23562018-05-10 13:17:35 -0700707}
708
Russell Kingc9a23562018-05-10 13:17:35 -0700709static void mv88e6xxx_mac_link_down(struct dsa_switch *ds, int port,
710 unsigned int mode,
711 phy_interface_t interface)
712{
Russell King30c4a5b2020-02-26 10:23:51 +0000713 struct mv88e6xxx_chip *chip = ds->priv;
714 const struct mv88e6xxx_ops *ops;
715 int err = 0;
716
717 ops = chip->info->ops;
718
719 /* Internal PHYs propagate their configuration directly to the MAC.
720 * External PHYs depend on whether the PPU is enabled for this port.
721 * FIXME: we should be using the PPU enable state here. What about
722 * an automedia port?
723 */
724 if (!mv88e6xxx_phy_is_internal(ds, port) && ops->port_set_link) {
725 mv88e6xxx_reg_lock(chip);
726 err = ops->port_set_link(chip, port, LINK_FORCED_DOWN);
727 mv88e6xxx_reg_unlock(chip);
728
729 if (err)
730 dev_err(chip->dev,
731 "p%d: failed to force MAC link down\n", port);
732 }
Russell Kingc9a23562018-05-10 13:17:35 -0700733}
734
735static void mv88e6xxx_mac_link_up(struct dsa_switch *ds, int port,
736 unsigned int mode, phy_interface_t interface,
Russell King5b502a72020-02-26 10:23:46 +0000737 struct phy_device *phydev,
738 int speed, int duplex,
739 bool tx_pause, bool rx_pause)
Russell Kingc9a23562018-05-10 13:17:35 -0700740{
Russell King30c4a5b2020-02-26 10:23:51 +0000741 struct mv88e6xxx_chip *chip = ds->priv;
742 const struct mv88e6xxx_ops *ops;
743 int err = 0;
744
745 ops = chip->info->ops;
746
747 /* Internal PHYs propagate their configuration directly to the MAC.
748 * External PHYs depend on whether the PPU is enabled for this port.
749 * FIXME: we should be using the PPU enable state here. What about
750 * an automedia port?
751 */
752 if (!mv88e6xxx_phy_is_internal(ds, port)) {
753 mv88e6xxx_reg_lock(chip);
754 /* FIXME: for an automedia port, should we force the link
755 * down here - what if the link comes up due to "other" media
756 * while we're bringing the port up, how is the exclusivity
Russell Kinga5a68582020-03-14 10:15:43 +0000757 * handled in the Marvell hardware? E.g. port 2 on 88E6390
Russell King30c4a5b2020-02-26 10:23:51 +0000758 * shared between internal PHY and Serdes.
759 */
Russell Kinga5a68582020-03-14 10:15:43 +0000760 err = mv88e6xxx_serdes_pcs_link_up(chip, port, mode, speed,
761 duplex);
762 if (err)
763 goto error;
764
Russell King30c4a5b2020-02-26 10:23:51 +0000765 if (ops->port_set_speed) {
766 err = ops->port_set_speed(chip, port, speed);
767 if (err && err != -EOPNOTSUPP)
768 goto error;
769 }
770
771 if (ops->port_set_duplex) {
772 err = ops->port_set_duplex(chip, port, duplex);
773 if (err && err != -EOPNOTSUPP)
774 goto error;
775 }
776
777 if (ops->port_set_link)
778 err = ops->port_set_link(chip, port, LINK_FORCED_UP);
779error:
780 mv88e6xxx_reg_unlock(chip);
781
782 if (err && err != -EOPNOTSUPP)
783 dev_err(ds->dev,
784 "p%d: failed to configure MAC link up\n", port);
785 }
Russell Kingc9a23562018-05-10 13:17:35 -0700786}
787
Andrew Lunna605a0f2016-11-21 23:26:58 +0100788static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000789{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100790 if (!chip->info->ops->stats_snapshot)
791 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000792
Andrew Lunna605a0f2016-11-21 23:26:58 +0100793 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000794}
795
Andrew Lunne413e7e2015-04-02 04:06:38 +0200796static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100797 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
798 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
799 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
800 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
801 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
802 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
803 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
804 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
805 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
806 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
807 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
808 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
809 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
810 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
811 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
812 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
813 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
814 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
815 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
816 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
817 { "single", 4, 0x14, STATS_TYPE_BANK0, },
818 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
819 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
820 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
821 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
822 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
823 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
824 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
825 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
826 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
827 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
828 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
829 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
830 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
831 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
832 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
833 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
834 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
835 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
836 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
837 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
838 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
839 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
840 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
841 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
842 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
843 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
844 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
845 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
846 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
847 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
848 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
849 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
850 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
851 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
852 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
853 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
854 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
855 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200856};
857
Vivien Didelotfad09c72016-06-21 12:28:20 -0400858static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100859 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100860 int port, u16 bank1_select,
861 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200862{
Andrew Lunn80c46272015-06-20 18:42:30 +0200863 u32 low;
864 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100865 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200866 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200867 u64 value;
868
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100869 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100870 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200871 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
872 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800873 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200874
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200875 low = reg;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100876 if (s->size == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200877 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
878 if (err)
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800879 return U64_MAX;
Rasmus Villemoes84b3fd12019-05-29 07:02:11 +0000880 low |= ((u32)reg) << 16;
Andrew Lunn80c46272015-06-20 18:42:30 +0200881 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100882 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100883 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100884 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100885 /* fall through */
886 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100887 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100888 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100889 if (s->size == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100890 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Gustavo A. R. Silva9fc3e4d2017-05-11 22:11:29 -0500891 break;
892 default:
Jisheng Zhang6c3442f2018-04-27 16:18:58 +0800893 return U64_MAX;
Andrew Lunn80c46272015-06-20 18:42:30 +0200894 }
Andrew Lunn6e46e2d2019-02-28 18:14:03 +0100895 value = (((u64)high) << 32) | low;
Andrew Lunn80c46272015-06-20 18:42:30 +0200896 return value;
897}
898
Andrew Lunn436fe172018-03-01 02:02:29 +0100899static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
900 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100901{
902 struct mv88e6xxx_hw_stat *stat;
903 int i, j;
904
905 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
906 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100907 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100908 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
909 ETH_GSTRING_LEN);
910 j++;
911 }
912 }
Andrew Lunn436fe172018-03-01 02:02:29 +0100913
914 return j;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100915}
916
Andrew Lunn436fe172018-03-01 02:02:29 +0100917static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
918 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100919{
Andrew Lunn436fe172018-03-01 02:02:29 +0100920 return mv88e6xxx_stats_get_strings(chip, data,
921 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
Andrew Lunndfafe442016-11-21 23:27:02 +0100922}
923
Rasmus Villemoes1f718362019-06-04 07:34:32 +0000924static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
925 uint8_t *data)
926{
927 return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
928}
929
Andrew Lunn436fe172018-03-01 02:02:29 +0100930static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
931 uint8_t *data)
Andrew Lunndfafe442016-11-21 23:27:02 +0100932{
Andrew Lunn436fe172018-03-01 02:02:29 +0100933 return mv88e6xxx_stats_get_strings(chip, data,
934 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
Andrew Lunndfafe442016-11-21 23:27:02 +0100935}
936
Andrew Lunn65f60e42018-03-28 23:50:28 +0200937static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
938 "atu_member_violation",
939 "atu_miss_violation",
940 "atu_full_violation",
941 "vtu_member_violation",
942 "vtu_miss_violation",
943};
944
945static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data)
946{
947 unsigned int i;
948
949 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
950 strlcpy(data + i * ETH_GSTRING_LEN,
951 mv88e6xxx_atu_vtu_stats_strings[i],
952 ETH_GSTRING_LEN);
953}
954
Andrew Lunndfafe442016-11-21 23:27:02 +0100955static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
Florian Fainelli89f09042018-04-25 12:12:50 -0700956 u32 stringset, uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100957{
Vivien Didelot04bed142016-08-31 18:06:13 -0400958 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +0100959 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100960
Florian Fainelli89f09042018-04-25 12:12:50 -0700961 if (stringset != ETH_SS_STATS)
962 return;
963
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000964 mv88e6xxx_reg_lock(chip);
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100965
Andrew Lunndfafe442016-11-21 23:27:02 +0100966 if (chip->info->ops->stats_get_strings)
Andrew Lunn436fe172018-03-01 02:02:29 +0100967 count = chip->info->ops->stats_get_strings(chip, data);
968
969 if (chip->info->ops->serdes_get_strings) {
970 data += count * ETH_GSTRING_LEN;
Andrew Lunn65f60e42018-03-28 23:50:28 +0200971 count = chip->info->ops->serdes_get_strings(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100972 }
Andrew Lunnc6c8cd52018-03-01 02:02:28 +0100973
Andrew Lunn65f60e42018-03-28 23:50:28 +0200974 data += count * ETH_GSTRING_LEN;
975 mv88e6xxx_atu_vtu_get_strings(data);
976
Rasmus Villemoesc9acece2019-06-20 13:50:42 +0000977 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100978}
979
980static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
981 int types)
982{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100983 struct mv88e6xxx_hw_stat *stat;
984 int i, j;
985
986 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
987 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100988 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100989 j++;
990 }
991 return j;
992}
993
Andrew Lunndfafe442016-11-21 23:27:02 +0100994static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
995{
996 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
997 STATS_TYPE_PORT);
998}
999
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001000static int mv88e6250_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1001{
1002 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0);
1003}
1004
Andrew Lunndfafe442016-11-21 23:27:02 +01001005static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1006{
1007 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1008 STATS_TYPE_BANK1);
1009}
1010
Florian Fainelli89f09042018-04-25 12:12:50 -07001011static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset)
Andrew Lunndfafe442016-11-21 23:27:02 +01001012{
1013 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn436fe172018-03-01 02:02:29 +01001014 int serdes_count = 0;
1015 int count = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +01001016
Florian Fainelli89f09042018-04-25 12:12:50 -07001017 if (sset != ETH_SS_STATS)
1018 return 0;
1019
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001020 mv88e6xxx_reg_lock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001021 if (chip->info->ops->stats_get_sset_count)
Andrew Lunn436fe172018-03-01 02:02:29 +01001022 count = chip->info->ops->stats_get_sset_count(chip);
1023 if (count < 0)
1024 goto out;
1025
1026 if (chip->info->ops->serdes_get_sset_count)
1027 serdes_count = chip->info->ops->serdes_get_sset_count(chip,
1028 port);
Andrew Lunn65f60e42018-03-28 23:50:28 +02001029 if (serdes_count < 0) {
Andrew Lunn436fe172018-03-01 02:02:29 +01001030 count = serdes_count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001031 goto out;
1032 }
1033 count += serdes_count;
1034 count += ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings);
1035
Andrew Lunn436fe172018-03-01 02:02:29 +01001036out:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001037 mv88e6xxx_reg_unlock(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +01001038
Andrew Lunn436fe172018-03-01 02:02:29 +01001039 return count;
Andrew Lunndfafe442016-11-21 23:27:02 +01001040}
1041
Andrew Lunn436fe172018-03-01 02:02:29 +01001042static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1043 uint64_t *data, int types,
1044 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +01001045{
1046 struct mv88e6xxx_hw_stat *stat;
1047 int i, j;
1048
1049 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1050 stat = &mv88e6xxx_hw_stats[i];
1051 if (stat->type & types) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001052 mv88e6xxx_reg_lock(chip);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001053 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
1054 bank1_select,
1055 histogram);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001056 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001057
Andrew Lunn052f9472016-11-21 23:27:03 +01001058 j++;
1059 }
1060 }
Andrew Lunn436fe172018-03-01 02:02:29 +01001061 return j;
Andrew Lunn052f9472016-11-21 23:27:03 +01001062}
1063
Andrew Lunn436fe172018-03-01 02:02:29 +01001064static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1065 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001066{
1067 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001068 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001069 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +01001070}
1071
Rasmus Villemoes1f718362019-06-04 07:34:32 +00001072static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1073 uint64_t *data)
1074{
1075 return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0,
1076 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
1077}
1078
Andrew Lunn436fe172018-03-01 02:02:29 +01001079static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1080 uint64_t *data)
Andrew Lunn052f9472016-11-21 23:27:03 +01001081{
1082 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001083 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001084 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9,
1085 MV88E6XXX_G1_STATS_OP_HIST_RX_TX);
Andrew Lunne0d8b612016-11-21 23:27:04 +01001086}
1087
Andrew Lunn436fe172018-03-01 02:02:29 +01001088static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1089 uint64_t *data)
Andrew Lunne0d8b612016-11-21 23:27:04 +01001090{
1091 return mv88e6xxx_stats_get_stats(chip, port, data,
1092 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
Vivien Didelot57d1ef32017-06-15 12:14:05 -04001093 MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10,
1094 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001095}
1096
Andrew Lunn65f60e42018-03-28 23:50:28 +02001097static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port,
1098 uint64_t *data)
1099{
1100 *data++ = chip->ports[port].atu_member_violation;
1101 *data++ = chip->ports[port].atu_miss_violation;
1102 *data++ = chip->ports[port].atu_full_violation;
1103 *data++ = chip->ports[port].vtu_member_violation;
1104 *data++ = chip->ports[port].vtu_miss_violation;
1105}
1106
Andrew Lunn052f9472016-11-21 23:27:03 +01001107static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1108 uint64_t *data)
1109{
Andrew Lunn436fe172018-03-01 02:02:29 +01001110 int count = 0;
1111
Andrew Lunn052f9472016-11-21 23:27:03 +01001112 if (chip->info->ops->stats_get_stats)
Andrew Lunn436fe172018-03-01 02:02:29 +01001113 count = chip->info->ops->stats_get_stats(chip, port, data);
1114
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001115 mv88e6xxx_reg_lock(chip);
Andrew Lunn436fe172018-03-01 02:02:29 +01001116 if (chip->info->ops->serdes_get_stats) {
1117 data += count;
Andrew Lunn65f60e42018-03-28 23:50:28 +02001118 count = chip->info->ops->serdes_get_stats(chip, port, data);
Andrew Lunn436fe172018-03-01 02:02:29 +01001119 }
Andrew Lunn65f60e42018-03-28 23:50:28 +02001120 data += count;
1121 mv88e6xxx_atu_vtu_get_stats(chip, port, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001122 mv88e6xxx_reg_unlock(chip);
Andrew Lunn052f9472016-11-21 23:27:03 +01001123}
1124
Vivien Didelotf81ec902016-05-09 13:22:58 -04001125static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1126 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001127{
Vivien Didelot04bed142016-08-31 18:06:13 -04001128 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001129 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001130
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001131 mv88e6xxx_reg_lock(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001132
Andrew Lunna605a0f2016-11-21 23:26:58 +01001133 ret = mv88e6xxx_stats_snapshot(chip, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001134 mv88e6xxx_reg_unlock(chip);
Andrew Lunn377cda12018-02-15 14:38:34 +01001135
1136 if (ret < 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001137 return;
Andrew Lunn052f9472016-11-21 23:27:03 +01001138
1139 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001140
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001141}
Ben Hutchings98e67302011-11-25 14:36:19 +00001142
Vivien Didelotf81ec902016-05-09 13:22:58 -04001143static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001144{
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001145 struct mv88e6xxx_chip *chip = ds->priv;
1146 int len;
1147
1148 len = 32 * sizeof(u16);
1149 if (chip->info->ops->serdes_get_regs_len)
1150 len += chip->info->ops->serdes_get_regs_len(chip, port);
1151
1152 return len;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001153}
1154
Vivien Didelotf81ec902016-05-09 13:22:58 -04001155static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1156 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001157{
Vivien Didelot04bed142016-08-31 18:06:13 -04001158 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001159 int err;
1160 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001161 u16 *p = _p;
1162 int i;
1163
Vivien Didelota5f39322018-12-17 16:05:21 -05001164 regs->version = chip->info->prod_num;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001165
1166 memset(p, 0xff, 32 * sizeof(u16));
1167
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001168 mv88e6xxx_reg_lock(chip);
Vivien Didelot23062512016-05-09 13:22:45 -04001169
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001170 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001171
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001172 err = mv88e6xxx_port_read(chip, port, i, &reg);
1173 if (!err)
1174 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001175 }
Vivien Didelot23062512016-05-09 13:22:45 -04001176
Andrew Lunn0d30bbd2020-02-16 18:54:13 +01001177 if (chip->info->ops->serdes_get_regs)
1178 chip->info->ops->serdes_get_regs(chip, port, &p[i]);
1179
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001180 mv88e6xxx_reg_unlock(chip);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001181}
1182
Vivien Didelot08f50062017-08-01 16:32:41 -04001183static int mv88e6xxx_get_mac_eee(struct dsa_switch *ds, int port,
1184 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001185{
Vivien Didelot5480db62017-08-01 16:32:40 -04001186 /* Nothing to do on the port's MAC */
1187 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001188}
1189
Vivien Didelot08f50062017-08-01 16:32:41 -04001190static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port,
1191 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001192{
Vivien Didelot5480db62017-08-01 16:32:40 -04001193 /* Nothing to do on the port's MAC */
1194 return 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001195}
1196
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001197/* Mask of the local ports allowed to receive frames from a given fabric port */
Vivien Didelote5887a22017-03-30 17:37:11 -04001198static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001199{
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001200 struct dsa_switch *ds = chip->ds;
1201 struct dsa_switch_tree *dst = ds->dst;
Vivien Didelote5887a22017-03-30 17:37:11 -04001202 struct net_device *br;
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001203 struct dsa_port *dp;
1204 bool found = false;
Vivien Didelote5887a22017-03-30 17:37:11 -04001205 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001206
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001207 list_for_each_entry(dp, &dst->ports, list) {
1208 if (dp->ds->index == dev && dp->index == port) {
1209 found = true;
1210 break;
1211 }
1212 }
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001213
Vivien Didelote5887a22017-03-30 17:37:11 -04001214 /* Prevent frames from unknown switch or port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001215 if (!found)
Vivien Didelote5887a22017-03-30 17:37:11 -04001216 return 0;
1217
1218 /* Frames from DSA links and CPU ports can egress any local port */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001219 if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA)
Vivien Didelote5887a22017-03-30 17:37:11 -04001220 return mv88e6xxx_port_mask(chip);
1221
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001222 br = dp->bridge_dev;
Vivien Didelote5887a22017-03-30 17:37:11 -04001223 pvlan = 0;
1224
1225 /* Frames from user ports can egress any local DSA links and CPU ports,
1226 * as well as any local member of their bridge group.
1227 */
Vivien Didelot9dc8b132019-10-21 16:51:26 -04001228 list_for_each_entry(dp, &dst->ports, list)
1229 if (dp->ds == ds &&
1230 (dp->type == DSA_PORT_TYPE_CPU ||
1231 dp->type == DSA_PORT_TYPE_DSA ||
1232 (br && dp->bridge_dev == br)))
1233 pvlan |= BIT(dp->index);
Vivien Didelote5887a22017-03-30 17:37:11 -04001234
1235 return pvlan;
1236}
1237
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001238static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001239{
1240 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001241
1242 /* prevent frames from going back out of the port they came in on */
1243 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001244
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001245 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001246}
1247
Vivien Didelotf81ec902016-05-09 13:22:58 -04001248static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1249 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001250{
Vivien Didelot04bed142016-08-31 18:06:13 -04001251 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot553eb542016-05-13 20:38:23 -04001252 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001253
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001254 mv88e6xxx_reg_lock(chip);
Vivien Didelotf894c292017-06-08 18:34:10 -04001255 err = mv88e6xxx_port_set_state(chip, port, state);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001256 mv88e6xxx_reg_unlock(chip);
Vivien Didelot553eb542016-05-13 20:38:23 -04001257
1258 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001259 dev_err(ds->dev, "p%d: failed to update state\n", port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001260}
1261
Vivien Didelot93e18d62018-05-11 17:16:35 -04001262static int mv88e6xxx_pri_setup(struct mv88e6xxx_chip *chip)
1263{
1264 int err;
1265
1266 if (chip->info->ops->ieee_pri_map) {
1267 err = chip->info->ops->ieee_pri_map(chip);
1268 if (err)
1269 return err;
1270 }
1271
1272 if (chip->info->ops->ip_pri_map) {
1273 err = chip->info->ops->ip_pri_map(chip);
1274 if (err)
1275 return err;
1276 }
1277
1278 return 0;
1279}
1280
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001281static int mv88e6xxx_devmap_setup(struct mv88e6xxx_chip *chip)
1282{
Vivien Didelotc5f51762019-10-30 22:09:13 -04001283 struct dsa_switch *ds = chip->ds;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001284 int target, port;
1285 int err;
1286
1287 if (!chip->info->global2_addr)
1288 return 0;
1289
1290 /* Initialize the routing port to the 32 possible target devices */
1291 for (target = 0; target < 32; target++) {
Vivien Didelotc5f51762019-10-30 22:09:13 -04001292 port = dsa_routing_port(ds, target);
1293 if (port == ds->num_ports)
1294 port = 0x1f;
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001295
1296 err = mv88e6xxx_g2_device_mapping_write(chip, target, port);
1297 if (err)
1298 return err;
1299 }
1300
Vivien Didelot02317e62018-05-09 11:38:49 -04001301 if (chip->info->ops->set_cascade_port) {
1302 port = MV88E6XXX_CASCADE_PORT_MULTIPLE;
1303 err = chip->info->ops->set_cascade_port(chip, port);
1304 if (err)
1305 return err;
1306 }
1307
Vivien Didelot23c98912018-05-09 11:38:50 -04001308 err = mv88e6xxx_g1_set_device_number(chip, chip->ds->index);
1309 if (err)
1310 return err;
1311
Vivien Didelotc7f047b2018-04-26 21:56:45 -04001312 return 0;
1313}
1314
Vivien Didelotb28f8722018-04-26 21:56:44 -04001315static int mv88e6xxx_trunk_setup(struct mv88e6xxx_chip *chip)
1316{
1317 /* Clear all trunk masks and mapping */
1318 if (chip->info->global2_addr)
1319 return mv88e6xxx_g2_trunk_clear(chip);
1320
1321 return 0;
1322}
1323
Vivien Didelot9e5baf92018-05-09 11:38:51 -04001324static int mv88e6xxx_rmu_setup(struct mv88e6xxx_chip *chip)
1325{
1326 if (chip->info->ops->rmu_disable)
1327 return chip->info->ops->rmu_disable(chip);
1328
1329 return 0;
1330}
1331
Vivien Didelot9e907d72017-07-17 13:03:43 -04001332static int mv88e6xxx_pot_setup(struct mv88e6xxx_chip *chip)
1333{
1334 if (chip->info->ops->pot_clear)
1335 return chip->info->ops->pot_clear(chip);
1336
1337 return 0;
1338}
1339
Vivien Didelot51c901a2017-07-17 13:03:41 -04001340static int mv88e6xxx_rsvd2cpu_setup(struct mv88e6xxx_chip *chip)
1341{
1342 if (chip->info->ops->mgmt_rsvd2cpu)
1343 return chip->info->ops->mgmt_rsvd2cpu(chip);
1344
1345 return 0;
1346}
1347
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001348static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1349{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001350 int err;
1351
Vivien Didelotdaefc942017-03-11 16:12:54 -05001352 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1353 if (err)
1354 return err;
1355
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001356 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1357 if (err)
1358 return err;
1359
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001360 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1361}
1362
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04001363static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
1364{
1365 int port;
1366 int err;
1367
1368 if (!chip->info->ops->irl_init_all)
1369 return 0;
1370
1371 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1372 /* Disable ingress rate limiting by resetting all per port
1373 * ingress rate limit resources to their initial state.
1374 */
1375 err = chip->info->ops->irl_init_all(chip, port);
1376 if (err)
1377 return err;
1378 }
1379
1380 return 0;
1381}
1382
Vivien Didelot04a69a12017-10-13 14:18:05 -04001383static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
1384{
1385 if (chip->info->ops->set_switch_mac) {
1386 u8 addr[ETH_ALEN];
1387
1388 eth_random_addr(addr);
1389
1390 return chip->info->ops->set_switch_mac(chip, addr);
1391 }
1392
1393 return 0;
1394}
1395
Vivien Didelot17a15942017-03-30 17:37:09 -04001396static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1397{
1398 u16 pvlan = 0;
1399
1400 if (!mv88e6xxx_has_pvt(chip))
Vivien Didelotd14939b2019-10-21 16:51:25 -04001401 return 0;
Vivien Didelot17a15942017-03-30 17:37:09 -04001402
1403 /* Skip the local source device, which uses in-chip port VLAN */
1404 if (dev != chip->ds->index)
Vivien Didelotaec5ac82017-03-30 17:37:15 -04001405 pvlan = mv88e6xxx_port_vlan(chip, dev, port);
Vivien Didelot17a15942017-03-30 17:37:09 -04001406
1407 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1408}
1409
Vivien Didelot81228992017-03-30 17:37:08 -04001410static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1411{
Vivien Didelot17a15942017-03-30 17:37:09 -04001412 int dev, port;
1413 int err;
1414
Vivien Didelot81228992017-03-30 17:37:08 -04001415 if (!mv88e6xxx_has_pvt(chip))
1416 return 0;
1417
1418 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1419 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1420 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001421 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1422 if (err)
1423 return err;
1424
1425 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1426 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1427 err = mv88e6xxx_pvt_map(chip, dev, port);
1428 if (err)
1429 return err;
1430 }
1431 }
1432
1433 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001434}
1435
Vivien Didelot749efcb2016-09-22 16:49:24 -04001436static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1437{
1438 struct mv88e6xxx_chip *chip = ds->priv;
1439 int err;
1440
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001441 mv88e6xxx_reg_lock(chip);
Vivien Didelote606ca32017-03-11 16:12:55 -05001442 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001443 mv88e6xxx_reg_unlock(chip);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001444
1445 if (err)
Vivien Didelot774439e52017-06-08 18:34:08 -04001446 dev_err(ds->dev, "p%d: failed to flush ATU\n", port);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001447}
1448
Vivien Didelotb486d7c2017-05-01 14:05:13 -04001449static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
1450{
1451 if (!chip->info->max_vid)
1452 return 0;
1453
1454 return mv88e6xxx_g1_vtu_flush(chip);
1455}
1456
Vivien Didelotf1394b782017-05-01 14:05:22 -04001457static int mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1458 struct mv88e6xxx_vtu_entry *entry)
1459{
1460 if (!chip->info->ops->vtu_getnext)
1461 return -EOPNOTSUPP;
1462
1463 return chip->info->ops->vtu_getnext(chip, entry);
1464}
1465
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04001466static int mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1467 struct mv88e6xxx_vtu_entry *entry)
1468{
1469 if (!chip->info->ops->vtu_loadpurge)
1470 return -EOPNOTSUPP;
1471
1472 return chip->info->ops->vtu_loadpurge(chip, entry);
1473}
1474
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001475static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001476{
1477 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelot425d2d32019-08-01 14:36:34 -04001478 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001479 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001480
1481 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1482
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001483 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001484 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001485 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001486 if (err)
1487 return err;
1488
1489 set_bit(*fid, fid_bitmap);
1490 }
1491
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001492 /* Set every FID bit used by the VLAN entries */
Vivien Didelot425d2d32019-08-01 14:36:34 -04001493 vlan.vid = chip->info->max_vid;
1494 vlan.valid = false;
1495
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001496 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001497 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001498 if (err)
1499 return err;
1500
1501 if (!vlan.valid)
1502 break;
1503
1504 set_bit(vlan.fid, fid_bitmap);
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001505 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001506
1507 /* The reset value 0x000 is used to indicate that multiple address
1508 * databases are not needed. Return the next positive available.
1509 */
1510 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001511 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001512 return -ENOSPC;
1513
1514 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001515 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001516}
1517
Andrew Lunn23e8b472019-10-25 01:03:52 +02001518static int mv88e6xxx_atu_get_hash(struct mv88e6xxx_chip *chip, u8 *hash)
1519{
1520 if (chip->info->ops->atu_get_hash)
1521 return chip->info->ops->atu_get_hash(chip, hash);
1522
1523 return -EOPNOTSUPP;
1524}
1525
1526static int mv88e6xxx_atu_set_hash(struct mv88e6xxx_chip *chip, u8 hash)
1527{
1528 if (chip->info->ops->atu_set_hash)
1529 return chip->info->ops->atu_set_hash(chip, hash);
1530
1531 return -EOPNOTSUPP;
1532}
1533
Vivien Didelotda9c3592016-02-12 12:09:40 -05001534static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1535 u16 vid_begin, u16 vid_end)
1536{
Vivien Didelot04bed142016-08-31 18:06:13 -04001537 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot425d2d32019-08-01 14:36:34 -04001538 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001539 int i, err;
1540
Andrew Lunndb06ae412017-09-25 23:32:20 +02001541 /* DSA and CPU ports have to be members of multiple vlans */
1542 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
1543 return 0;
1544
Vivien Didelotda9c3592016-02-12 12:09:40 -05001545 if (!vid_begin)
1546 return -EOPNOTSUPP;
1547
Vivien Didelot425d2d32019-08-01 14:36:34 -04001548 vlan.vid = vid_begin - 1;
1549 vlan.valid = false;
1550
Vivien Didelotda9c3592016-02-12 12:09:40 -05001551 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04001552 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001553 if (err)
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001554 return err;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001555
1556 if (!vlan.valid)
1557 break;
1558
1559 if (vlan.vid > vid_end)
1560 break;
1561
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001562 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001563 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1564 continue;
1565
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001566 if (!dsa_to_port(ds, i)->slave)
Andrew Lunn66e28092016-12-11 21:07:19 +01001567 continue;
1568
Vivien Didelotbd00e052017-05-01 14:05:11 -04001569 if (vlan.member[i] ==
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001570 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001571 continue;
1572
Vivien Didelotc8652c82017-10-16 11:12:19 -04001573 if (dsa_to_port(ds, i)->bridge_dev ==
Vivien Didelot68bb8ea2019-10-21 16:51:15 -04001574 dsa_to_port(ds, port)->bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001575 break; /* same bridge, check next VLAN */
1576
Vivien Didelotc8652c82017-10-16 11:12:19 -04001577 if (!dsa_to_port(ds, i)->bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001578 continue;
1579
Andrew Lunn743fcc22017-11-09 22:29:54 +01001580 dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n",
1581 port, vlan.vid, i,
Vivien Didelotc8652c82017-10-16 11:12:19 -04001582 netdev_name(dsa_to_port(ds, i)->bridge_dev));
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001583 return -EOPNOTSUPP;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001584 }
1585 } while (vlan.vid < vid_end);
1586
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001587 return 0;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001588}
1589
Vivien Didelotf81ec902016-05-09 13:22:58 -04001590static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1591 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001592{
Vivien Didelot04bed142016-08-31 18:06:13 -04001593 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot81c6edb2017-06-12 12:37:41 -04001594 u16 mode = vlan_filtering ? MV88E6XXX_PORT_CTL2_8021Q_MODE_SECURE :
1595 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001596 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001597
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001598 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001599 return -EOPNOTSUPP;
1600
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001601 mv88e6xxx_reg_lock(chip);
Vivien Didelot385a0992016-11-04 03:23:31 +01001602 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00001603 mv88e6xxx_reg_unlock(chip);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001604
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001605 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001606}
1607
Vivien Didelot57d32312016-06-20 13:13:58 -04001608static int
1609mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001610 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001611{
Vivien Didelot04bed142016-08-31 18:06:13 -04001612 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001613 int err;
1614
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001615 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001616 return -EOPNOTSUPP;
1617
Vivien Didelotda9c3592016-02-12 12:09:40 -05001618 /* If the requested port doesn't belong to the same bridge as the VLAN
1619 * members, do not support it (yet) and fallback to software VLAN.
1620 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001621 mv88e6xxx_reg_lock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001622 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1623 vlan->vid_end);
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001624 mv88e6xxx_reg_unlock(chip);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001625
Vivien Didelot76e398a2015-11-01 12:33:55 -05001626 /* We don't need any dynamic resource from the kernel (yet),
1627 * so skip the prepare phase.
1628 */
Vivien Didelot7095a4c2019-08-01 14:36:33 -04001629 return err;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001630}
1631
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001632static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1633 const unsigned char *addr, u16 vid,
1634 u8 state)
1635{
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001636 struct mv88e6xxx_atu_entry entry;
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001637 struct mv88e6xxx_vtu_entry vlan;
1638 u16 fid;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001639 int err;
1640
1641 /* Null VLAN ID corresponds to the port private database */
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001642 if (vid == 0) {
1643 err = mv88e6xxx_port_get_fid(chip, port, &fid);
1644 if (err)
1645 return err;
1646 } else {
1647 vlan.vid = vid - 1;
1648 vlan.valid = false;
1649
1650 err = mv88e6xxx_vtu_getnext(chip, &vlan);
1651 if (err)
1652 return err;
1653
1654 /* switchdev expects -EOPNOTSUPP to honor software VLANs */
1655 if (vlan.vid != vid || !vlan.valid)
1656 return -EOPNOTSUPP;
1657
1658 fid = vlan.fid;
1659 }
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001660
Vivien Didelotd8291a92019-09-07 16:00:47 -04001661 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001662 ether_addr_copy(entry.mac, addr);
1663 eth_addr_dec(entry.mac);
1664
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001665 err = mv88e6xxx_g1_atu_getnext(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001666 if (err)
1667 return err;
1668
1669 /* Initialize a fresh ATU entry if it isn't found */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001670 if (!entry.state || !ether_addr_equal(entry.mac, addr)) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001671 memset(&entry, 0, sizeof(entry));
1672 ether_addr_copy(entry.mac, addr);
1673 }
1674
1675 /* Purge the ATU entry only if no port is using it anymore */
Vivien Didelotd8291a92019-09-07 16:00:47 -04001676 if (!state) {
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001677 entry.portvec &= ~BIT(port);
1678 if (!entry.portvec)
Vivien Didelotd8291a92019-09-07 16:00:47 -04001679 entry.state = 0;
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001680 } else {
1681 entry.portvec |= BIT(port);
1682 entry.state = state;
1683 }
1684
Vivien Didelot5ef8d242019-08-01 14:36:35 -04001685 return mv88e6xxx_g1_atu_loadpurge(chip, fid, &entry);
Andrew Lunna4c93ae2017-11-09 22:29:55 +01001686}
1687
Vivien Didelotda7dc872019-09-07 16:00:49 -04001688static int mv88e6xxx_policy_apply(struct mv88e6xxx_chip *chip, int port,
1689 const struct mv88e6xxx_policy *policy)
1690{
1691 enum mv88e6xxx_policy_mapping mapping = policy->mapping;
1692 enum mv88e6xxx_policy_action action = policy->action;
1693 const u8 *addr = policy->addr;
1694 u16 vid = policy->vid;
1695 u8 state;
1696 int err;
1697 int id;
1698
1699 if (!chip->info->ops->port_set_policy)
1700 return -EOPNOTSUPP;
1701
1702 switch (mapping) {
1703 case MV88E6XXX_POLICY_MAPPING_DA:
1704 case MV88E6XXX_POLICY_MAPPING_SA:
1705 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1706 state = 0; /* Dissociate the port and address */
1707 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1708 is_multicast_ether_addr(addr))
1709 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY;
1710 else if (action == MV88E6XXX_POLICY_ACTION_DISCARD &&
1711 is_unicast_ether_addr(addr))
1712 state = MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY;
1713 else
1714 return -EOPNOTSUPP;
1715
1716 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
1717 state);
1718 if (err)
1719 return err;
1720 break;
1721 default:
1722 return -EOPNOTSUPP;
1723 }
1724
1725 /* Skip the port's policy clearing if the mapping is still in use */
1726 if (action == MV88E6XXX_POLICY_ACTION_NORMAL)
1727 idr_for_each_entry(&chip->policies, policy, id)
1728 if (policy->port == port &&
1729 policy->mapping == mapping &&
1730 policy->action != action)
1731 return 0;
1732
1733 return chip->info->ops->port_set_policy(chip, port, mapping, action);
1734}
1735
1736static int mv88e6xxx_policy_insert(struct mv88e6xxx_chip *chip, int port,
1737 struct ethtool_rx_flow_spec *fs)
1738{
1739 struct ethhdr *mac_entry = &fs->h_u.ether_spec;
1740 struct ethhdr *mac_mask = &fs->m_u.ether_spec;
1741 enum mv88e6xxx_policy_mapping mapping;
1742 enum mv88e6xxx_policy_action action;
1743 struct mv88e6xxx_policy *policy;
1744 u16 vid = 0;
1745 u8 *addr;
1746 int err;
1747 int id;
1748
1749 if (fs->location != RX_CLS_LOC_ANY)
1750 return -EINVAL;
1751
1752 if (fs->ring_cookie == RX_CLS_FLOW_DISC)
1753 action = MV88E6XXX_POLICY_ACTION_DISCARD;
1754 else
1755 return -EOPNOTSUPP;
1756
1757 switch (fs->flow_type & ~FLOW_EXT) {
1758 case ETHER_FLOW:
1759 if (!is_zero_ether_addr(mac_mask->h_dest) &&
1760 is_zero_ether_addr(mac_mask->h_source)) {
1761 mapping = MV88E6XXX_POLICY_MAPPING_DA;
1762 addr = mac_entry->h_dest;
1763 } else if (is_zero_ether_addr(mac_mask->h_dest) &&
1764 !is_zero_ether_addr(mac_mask->h_source)) {
1765 mapping = MV88E6XXX_POLICY_MAPPING_SA;
1766 addr = mac_entry->h_source;
1767 } else {
1768 /* Cannot support DA and SA mapping in the same rule */
1769 return -EOPNOTSUPP;
1770 }
1771 break;
1772 default:
1773 return -EOPNOTSUPP;
1774 }
1775
1776 if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
1777 if (fs->m_ext.vlan_tci != 0xffff)
1778 return -EOPNOTSUPP;
1779 vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
1780 }
1781
1782 idr_for_each_entry(&chip->policies, policy, id) {
1783 if (policy->port == port && policy->mapping == mapping &&
1784 policy->action == action && policy->vid == vid &&
1785 ether_addr_equal(policy->addr, addr))
1786 return -EEXIST;
1787 }
1788
1789 policy = devm_kzalloc(chip->dev, sizeof(*policy), GFP_KERNEL);
1790 if (!policy)
1791 return -ENOMEM;
1792
1793 fs->location = 0;
1794 err = idr_alloc_u32(&chip->policies, policy, &fs->location, 0xffffffff,
1795 GFP_KERNEL);
1796 if (err) {
1797 devm_kfree(chip->dev, policy);
1798 return err;
1799 }
1800
1801 memcpy(&policy->fs, fs, sizeof(*fs));
1802 ether_addr_copy(policy->addr, addr);
1803 policy->mapping = mapping;
1804 policy->action = action;
1805 policy->port = port;
1806 policy->vid = vid;
1807
1808 err = mv88e6xxx_policy_apply(chip, port, policy);
1809 if (err) {
1810 idr_remove(&chip->policies, fs->location);
1811 devm_kfree(chip->dev, policy);
1812 return err;
1813 }
1814
1815 return 0;
1816}
1817
1818static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
1819 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
1820{
1821 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1822 struct mv88e6xxx_chip *chip = ds->priv;
1823 struct mv88e6xxx_policy *policy;
1824 int err;
1825 int id;
1826
1827 mv88e6xxx_reg_lock(chip);
1828
1829 switch (rxnfc->cmd) {
1830 case ETHTOOL_GRXCLSRLCNT:
1831 rxnfc->data = 0;
1832 rxnfc->data |= RX_CLS_LOC_SPECIAL;
1833 rxnfc->rule_cnt = 0;
1834 idr_for_each_entry(&chip->policies, policy, id)
1835 if (policy->port == port)
1836 rxnfc->rule_cnt++;
1837 err = 0;
1838 break;
1839 case ETHTOOL_GRXCLSRULE:
1840 err = -ENOENT;
1841 policy = idr_find(&chip->policies, fs->location);
1842 if (policy) {
1843 memcpy(fs, &policy->fs, sizeof(*fs));
1844 err = 0;
1845 }
1846 break;
1847 case ETHTOOL_GRXCLSRLALL:
1848 rxnfc->data = 0;
1849 rxnfc->rule_cnt = 0;
1850 idr_for_each_entry(&chip->policies, policy, id)
1851 if (policy->port == port)
1852 rule_locs[rxnfc->rule_cnt++] = id;
1853 err = 0;
1854 break;
1855 default:
1856 err = -EOPNOTSUPP;
1857 break;
1858 }
1859
1860 mv88e6xxx_reg_unlock(chip);
1861
1862 return err;
1863}
1864
1865static int mv88e6xxx_set_rxnfc(struct dsa_switch *ds, int port,
1866 struct ethtool_rxnfc *rxnfc)
1867{
1868 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
1869 struct mv88e6xxx_chip *chip = ds->priv;
1870 struct mv88e6xxx_policy *policy;
1871 int err;
1872
1873 mv88e6xxx_reg_lock(chip);
1874
1875 switch (rxnfc->cmd) {
1876 case ETHTOOL_SRXCLSRLINS:
1877 err = mv88e6xxx_policy_insert(chip, port, fs);
1878 break;
1879 case ETHTOOL_SRXCLSRLDEL:
1880 err = -ENOENT;
1881 policy = idr_remove(&chip->policies, fs->location);
1882 if (policy) {
1883 policy->action = MV88E6XXX_POLICY_ACTION_NORMAL;
1884 err = mv88e6xxx_policy_apply(chip, port, policy);
1885 devm_kfree(chip->dev, policy);
1886 }
1887 break;
1888 default:
1889 err = -EOPNOTSUPP;
1890 break;
1891 }
1892
1893 mv88e6xxx_reg_unlock(chip);
1894
1895 return err;
1896}
1897
Andrew Lunn87fa8862017-11-09 22:29:56 +01001898static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port,
1899 u16 vid)
1900{
1901 const char broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1902 u8 state = MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC;
1903
1904 return mv88e6xxx_port_db_load_purge(chip, port, broadcast, vid, state);
1905}
1906
1907static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid)
1908{
1909 int port;
1910 int err;
1911
1912 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
1913 err = mv88e6xxx_port_add_broadcast(chip, port, vid);
1914 if (err)
1915 return err;
1916 }
1917
1918 return 0;
1919}
1920
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001921static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port,
Russell King933b4422020-02-26 17:14:26 +00001922 u16 vid, u8 member, bool warn)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001923{
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001924 const u8 non_member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001925 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001926 int i, err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001927
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001928 if (!vid)
1929 return -EOPNOTSUPP;
1930
1931 vlan.vid = vid - 1;
1932 vlan.valid = false;
1933
1934 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001935 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001936 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001937
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001938 if (vlan.vid != vid || !vlan.valid) {
1939 memset(&vlan, 0, sizeof(vlan));
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001940
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001941 err = mv88e6xxx_atu_new(chip, &vlan.fid);
1942 if (err)
1943 return err;
Andrew Lunn87fa8862017-11-09 22:29:56 +01001944
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001945 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1946 if (i == port)
1947 vlan.member[i] = member;
1948 else
1949 vlan.member[i] = non_member;
1950
1951 vlan.vid = vid;
1952 vlan.valid = true;
1953
1954 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1955 if (err)
1956 return err;
1957
1958 err = mv88e6xxx_broadcast_setup(chip, vlan.vid);
1959 if (err)
1960 return err;
1961 } else if (vlan.member[port] != member) {
1962 vlan.member[port] = member;
1963
1964 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
1965 if (err)
1966 return err;
Russell King933b4422020-02-26 17:14:26 +00001967 } else if (warn) {
Vivien Didelotb1ac6fb2019-08-01 14:36:37 -04001968 dev_info(chip->dev, "p%d: already a member of VLAN %d\n",
1969 port, vid);
1970 }
1971
1972 return 0;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001973}
1974
Vivien Didelotf81ec902016-05-09 13:22:58 -04001975static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
Vivien Didelot80e02362017-11-30 11:23:57 -05001976 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001977{
Vivien Didelot04bed142016-08-31 18:06:13 -04001978 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001979 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1980 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Russell King933b4422020-02-26 17:14:26 +00001981 bool warn;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001982 u8 member;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001983 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001984
Vivien Didelot3cf3c842017-05-01 14:05:10 -04001985 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04001986 return;
1987
Vivien Didelotc91498e2017-06-07 18:12:13 -04001988 if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001989 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001990 else if (untagged)
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001991 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNTAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001992 else
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04001993 member = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_TAGGED;
Vivien Didelotc91498e2017-06-07 18:12:13 -04001994
Russell King933b4422020-02-26 17:14:26 +00001995 /* net/dsa/slave.c will call dsa_port_vlan_add() for the affected port
1996 * and then the CPU port. Do not warn for duplicates for the CPU port.
1997 */
1998 warn = !dsa_is_cpu_port(ds, port) && !dsa_is_dsa_port(ds, port);
1999
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002000 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002001
Vivien Didelot4d5770b2016-04-06 11:55:05 -04002002 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Russell King933b4422020-02-26 17:14:26 +00002003 if (mv88e6xxx_port_vlan_join(chip, port, vid, member, warn))
Vivien Didelot774439e52017-06-08 18:34:08 -04002004 dev_err(ds->dev, "p%d: failed to add VLAN %d%c\n", port,
2005 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05002006
Vivien Didelot77064f32016-11-04 03:23:30 +01002007 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Vivien Didelot774439e52017-06-08 18:34:08 -04002008 dev_err(ds->dev, "p%d: failed to set PVID %d\n", port,
2009 vlan->vid_end);
Vivien Didelot4d5770b2016-04-06 11:55:05 -04002010
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002011 mv88e6xxx_reg_unlock(chip);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04002012}
2013
Vivien Didelot521098922019-08-01 14:36:36 -04002014static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip,
2015 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002016{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002017 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002018 int i, err;
2019
Vivien Didelot521098922019-08-01 14:36:36 -04002020 if (!vid)
2021 return -EOPNOTSUPP;
2022
2023 vlan.vid = vid - 1;
2024 vlan.valid = false;
2025
2026 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002027 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002028 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04002029
Vivien Didelot521098922019-08-01 14:36:36 -04002030 /* If the VLAN doesn't exist in hardware or the port isn't a member,
2031 * tell switchdev that this VLAN is likely handled in software.
2032 */
2033 if (vlan.vid != vid || !vlan.valid ||
2034 vlan.member[port] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05002035 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002036
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002037 vlan.member[port] = MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002038
2039 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002040 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002041 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -04002042 if (vlan.member[i] !=
2043 MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04002044 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002045 break;
2046 }
2047 }
2048
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04002049 err = mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002050 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002051 return err;
2052
Vivien Didelote606ca32017-03-11 16:12:55 -05002053 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002054}
2055
Vivien Didelotf81ec902016-05-09 13:22:58 -04002056static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2057 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002058{
Vivien Didelot04bed142016-08-31 18:06:13 -04002059 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002060 u16 pvid, vid;
2061 int err = 0;
2062
Vivien Didelot3cf3c842017-05-01 14:05:10 -04002063 if (!chip->info->max_vid)
Vivien Didelot54d77b52016-05-09 13:22:47 -04002064 return -EOPNOTSUPP;
2065
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002066 mv88e6xxx_reg_lock(chip);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002067
Vivien Didelot77064f32016-11-04 03:23:30 +01002068 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002069 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002070 goto unlock;
2071
Vivien Didelot76e398a2015-11-01 12:33:55 -05002072 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelot521098922019-08-01 14:36:36 -04002073 err = mv88e6xxx_port_vlan_leave(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002074 if (err)
2075 goto unlock;
2076
2077 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01002078 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002079 if (err)
2080 goto unlock;
2081 }
2082 }
2083
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002084unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002085 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002086
2087 return err;
2088}
2089
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002090static int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2091 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002092{
Vivien Didelot04bed142016-08-31 18:06:13 -04002093 struct mv88e6xxx_chip *chip = ds->priv;
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002094 int err;
Vivien Didelot6630e232015-08-06 01:44:07 -04002095
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002096 mv88e6xxx_reg_lock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002097 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid,
2098 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002099 mv88e6xxx_reg_unlock(chip);
Arkadi Sharshevsky1b6dd552017-08-06 16:15:40 +03002100
2101 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002102}
2103
Vivien Didelotf81ec902016-05-09 13:22:58 -04002104static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
Arkadi Sharshevsky6c2c1dc2017-08-06 16:15:39 +03002105 const unsigned char *addr, u16 vid)
David S. Millercdf09692015-08-11 12:00:37 -07002106{
Vivien Didelot04bed142016-08-31 18:06:13 -04002107 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002108 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002109
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002110 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04002111 err = mv88e6xxx_port_db_load_purge(chip, port, addr, vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002112 mv88e6xxx_reg_unlock(chip);
David S. Millercdf09692015-08-11 12:00:37 -07002113
Vivien Didelot83dabd12016-08-31 11:50:04 -04002114 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002115}
2116
Vivien Didelot83dabd12016-08-31 11:50:04 -04002117static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2118 u16 fid, u16 vid, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002119 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002120{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002121 struct mv88e6xxx_atu_entry addr;
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002122 bool is_static;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002123 int err;
2124
Vivien Didelotd8291a92019-09-07 16:00:47 -04002125 addr.state = 0;
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002126 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002127
2128 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002129 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002130 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002131 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002132
Vivien Didelotd8291a92019-09-07 16:00:47 -04002133 if (!addr.state)
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002134 break;
2135
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002136 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002137 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002138
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002139 if (!is_unicast_ether_addr(addr.mac))
2140 continue;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002141
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002142 is_static = (addr.state ==
2143 MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC);
2144 err = cb(addr.mac, vid, is_static, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002145 if (err)
2146 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002147 } while (!is_broadcast_ether_addr(addr.mac));
2148
2149 return err;
2150}
2151
Vivien Didelot83dabd12016-08-31 11:50:04 -04002152static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002153 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002154{
Vivien Didelot425d2d32019-08-01 14:36:34 -04002155 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002156 u16 fid;
2157 int err;
2158
2159 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002160 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002161 if (err)
2162 return err;
2163
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002164 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002165 if (err)
2166 return err;
2167
2168 /* Dump VLANs' Filtering Information Databases */
Vivien Didelot425d2d32019-08-01 14:36:34 -04002169 vlan.vid = chip->info->max_vid;
2170 vlan.valid = false;
2171
Vivien Didelot83dabd12016-08-31 11:50:04 -04002172 do {
Vivien Didelotf1394b782017-05-01 14:05:22 -04002173 err = mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002174 if (err)
2175 return err;
2176
2177 if (!vlan.valid)
2178 break;
2179
2180 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002181 cb, data);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002182 if (err)
2183 return err;
Vivien Didelot3cf3c842017-05-01 14:05:10 -04002184 } while (vlan.vid < chip->info->max_vid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002185
2186 return err;
2187}
2188
Vivien Didelotf81ec902016-05-09 13:22:58 -04002189static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
Arkadi Sharshevsky2bedde12017-08-06 16:15:49 +03002190 dsa_fdb_dump_cb_t *cb, void *data)
Vivien Didelotf33475b2015-10-22 09:34:41 -04002191{
Vivien Didelot04bed142016-08-31 18:06:13 -04002192 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfcf15362019-06-12 12:42:47 -04002193 int err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002194
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002195 mv88e6xxx_reg_lock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002196 err = mv88e6xxx_port_db_dump(chip, port, cb, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002197 mv88e6xxx_reg_unlock(chip);
Vivien Didelotfcf15362019-06-12 12:42:47 -04002198
2199 return err;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002200}
2201
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002202static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2203 struct net_device *br)
2204{
Vivien Didelotef2025e2019-10-21 16:51:27 -04002205 struct dsa_switch *ds = chip->ds;
2206 struct dsa_switch_tree *dst = ds->dst;
2207 struct dsa_port *dp;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002208 int err;
2209
Vivien Didelotef2025e2019-10-21 16:51:27 -04002210 list_for_each_entry(dp, &dst->ports, list) {
2211 if (dp->bridge_dev == br) {
2212 if (dp->ds == ds) {
2213 /* This is a local bridge group member,
2214 * remap its Port VLAN Map.
2215 */
2216 err = mv88e6xxx_port_vlan_map(chip, dp->index);
2217 if (err)
2218 return err;
2219 } else {
2220 /* This is an external bridge group member,
2221 * remap its cross-chip Port VLAN Table entry.
2222 */
2223 err = mv88e6xxx_pvt_map(chip, dp->ds->index,
2224 dp->index);
Vivien Didelote96a6e02017-03-30 17:37:13 -04002225 if (err)
2226 return err;
2227 }
2228 }
2229 }
2230
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002231 return 0;
2232}
2233
Vivien Didelotf81ec902016-05-09 13:22:58 -04002234static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002235 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002236{
Vivien Didelot04bed142016-08-31 18:06:13 -04002237 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002238 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002239
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002240 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002241 err = mv88e6xxx_bridge_map(chip, br);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002242 mv88e6xxx_reg_unlock(chip);
Vivien Didelota6692752016-02-12 12:09:39 -05002243
Vivien Didelot466dfa02016-02-26 13:16:05 -05002244 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002245}
2246
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002247static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2248 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002249{
Vivien Didelot04bed142016-08-31 18:06:13 -04002250 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002251
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002252 mv88e6xxx_reg_lock(chip);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002253 if (mv88e6xxx_bridge_map(chip, br) ||
2254 mv88e6xxx_port_vlan_map(chip, port))
2255 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002256 mv88e6xxx_reg_unlock(chip);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002257}
2258
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002259static int mv88e6xxx_crosschip_bridge_join(struct dsa_switch *ds, int dev,
2260 int port, struct net_device *br)
2261{
2262 struct mv88e6xxx_chip *chip = ds->priv;
2263 int err;
2264
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002265 mv88e6xxx_reg_lock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002266 err = mv88e6xxx_pvt_map(chip, dev, port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002267 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002268
2269 return err;
2270}
2271
2272static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, int dev,
2273 int port, struct net_device *br)
2274{
2275 struct mv88e6xxx_chip *chip = ds->priv;
2276
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002277 mv88e6xxx_reg_lock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002278 if (mv88e6xxx_pvt_map(chip, dev, port))
2279 dev_err(ds->dev, "failed to remap cross-chip Port VLAN\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002280 mv88e6xxx_reg_unlock(chip);
Vivien Didelotaec5ac82017-03-30 17:37:15 -04002281}
2282
Vivien Didelot17e708b2016-12-05 17:30:27 -05002283static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2284{
2285 if (chip->info->ops->reset)
2286 return chip->info->ops->reset(chip);
2287
2288 return 0;
2289}
2290
Vivien Didelot309eca62016-12-05 17:30:26 -05002291static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2292{
2293 struct gpio_desc *gpiod = chip->reset;
2294
2295 /* If there is a GPIO connected to the reset pin, toggle it */
2296 if (gpiod) {
2297 gpiod_set_value_cansleep(gpiod, 1);
2298 usleep_range(10000, 20000);
2299 gpiod_set_value_cansleep(gpiod, 0);
2300 usleep_range(10000, 20000);
2301 }
2302}
2303
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002304static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2305{
2306 int i, err;
2307
2308 /* Set all ports to the Disabled state */
2309 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotf894c292017-06-08 18:34:10 -04002310 err = mv88e6xxx_port_set_state(chip, i, BR_STATE_DISABLED);
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002311 if (err)
2312 return err;
2313 }
2314
2315 /* Wait for transmit queues to drain,
2316 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2317 */
2318 usleep_range(2000, 4000);
2319
2320 return 0;
2321}
2322
Vivien Didelotfad09c72016-06-21 12:28:20 -04002323static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002324{
Vivien Didelota935c052016-09-29 12:21:53 -04002325 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002326
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002327 err = mv88e6xxx_disable_ports(chip);
2328 if (err)
2329 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002330
Vivien Didelot309eca62016-12-05 17:30:26 -05002331 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002332
Vivien Didelot17e708b2016-12-05 17:30:27 -05002333 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002334}
2335
Vivien Didelot43145572017-03-11 16:12:59 -05002336static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002337 enum mv88e6xxx_frame_mode frame,
2338 enum mv88e6xxx_egress_mode egress, u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002339{
2340 int err;
2341
Vivien Didelot43145572017-03-11 16:12:59 -05002342 if (!chip->info->ops->port_set_frame_mode)
2343 return -EOPNOTSUPP;
2344
2345 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002346 if (err)
2347 return err;
2348
Vivien Didelot43145572017-03-11 16:12:59 -05002349 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2350 if (err)
2351 return err;
2352
2353 if (chip->info->ops->port_set_ether_type)
2354 return chip->info->ops->port_set_ether_type(chip, port, etype);
2355
2356 return 0;
2357}
2358
2359static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2360{
2361 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002362 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002363 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002364}
2365
2366static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2367{
2368 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002369 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
Vivien Didelotb8109592017-06-12 12:37:45 -04002370 MV88E6XXX_PORT_ETH_TYPE_DEFAULT);
Vivien Didelot43145572017-03-11 16:12:59 -05002371}
2372
2373static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2374{
2375 return mv88e6xxx_set_port_mode(chip, port,
2376 MV88E6XXX_FRAME_MODE_ETHERTYPE,
Vivien Didelot31bef4e2017-06-08 18:34:09 -04002377 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
2378 ETH_P_EDSA);
Vivien Didelot43145572017-03-11 16:12:59 -05002379}
2380
2381static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2382{
2383 if (dsa_is_dsa_port(chip->ds, port))
2384 return mv88e6xxx_set_port_mode_dsa(chip, port);
2385
Vivien Didelot2b3e9892017-10-26 11:22:54 -04002386 if (dsa_is_user_port(chip->ds, port))
Vivien Didelot43145572017-03-11 16:12:59 -05002387 return mv88e6xxx_set_port_mode_normal(chip, port);
2388
2389 /* Setup CPU port mode depending on its supported tag format */
2390 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2391 return mv88e6xxx_set_port_mode_dsa(chip, port);
2392
2393 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2394 return mv88e6xxx_set_port_mode_edsa(chip, port);
2395
2396 return -EINVAL;
2397}
2398
Vivien Didelotea698f42017-03-11 16:12:50 -05002399static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2400{
2401 bool message = dsa_is_dsa_port(chip->ds, port);
2402
2403 return mv88e6xxx_port_set_message_port(chip, port, message);
2404}
2405
Vivien Didelot601aeed2017-03-11 16:13:00 -05002406static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2407{
Vivien Didelot3ee50cb2017-12-05 15:34:09 -05002408 struct dsa_switch *ds = chip->ds;
David S. Miller407308f2019-06-15 13:35:29 -07002409 bool flood;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002410
David S. Miller407308f2019-06-15 13:35:29 -07002411 /* Upstream ports flood frames with unknown unicast or multicast DA */
2412 flood = dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port);
2413 if (chip->info->ops->port_set_egress_floods)
2414 return chip->info->ops->port_set_egress_floods(chip, port,
2415 flood, flood);
Vivien Didelot601aeed2017-03-11 16:13:00 -05002416
David S. Miller407308f2019-06-15 13:35:29 -07002417 return 0;
Vivien Didelot601aeed2017-03-11 16:13:00 -05002418}
2419
Vivien Didelot45de77f2019-08-31 16:18:36 -04002420static irqreturn_t mv88e6xxx_serdes_irq_thread_fn(int irq, void *dev_id)
2421{
2422 struct mv88e6xxx_port *mvp = dev_id;
2423 struct mv88e6xxx_chip *chip = mvp->chip;
2424 irqreturn_t ret = IRQ_NONE;
2425 int port = mvp->port;
2426 u8 lane;
2427
2428 mv88e6xxx_reg_lock(chip);
2429 lane = mv88e6xxx_serdes_get_lane(chip, port);
2430 if (lane)
2431 ret = mv88e6xxx_serdes_irq_status(chip, port, lane);
2432 mv88e6xxx_reg_unlock(chip);
2433
2434 return ret;
2435}
2436
2437static int mv88e6xxx_serdes_irq_request(struct mv88e6xxx_chip *chip, int port,
2438 u8 lane)
2439{
2440 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2441 unsigned int irq;
2442 int err;
2443
2444 /* Nothing to request if this SERDES port has no IRQ */
2445 irq = mv88e6xxx_serdes_irq_mapping(chip, port);
2446 if (!irq)
2447 return 0;
2448
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002449 snprintf(dev_id->serdes_irq_name, sizeof(dev_id->serdes_irq_name),
2450 "mv88e6xxx-%s-serdes-%d", dev_name(chip->dev), port);
2451
Vivien Didelot45de77f2019-08-31 16:18:36 -04002452 /* Requesting the IRQ will trigger IRQ callbacks, so release the lock */
2453 mv88e6xxx_reg_unlock(chip);
2454 err = request_threaded_irq(irq, NULL, mv88e6xxx_serdes_irq_thread_fn,
Andrew Lunne6f2f6b2020-01-06 17:13:49 +01002455 IRQF_ONESHOT, dev_id->serdes_irq_name,
2456 dev_id);
Vivien Didelot45de77f2019-08-31 16:18:36 -04002457 mv88e6xxx_reg_lock(chip);
2458 if (err)
2459 return err;
2460
2461 dev_id->serdes_irq = irq;
2462
2463 return mv88e6xxx_serdes_irq_enable(chip, port, lane);
2464}
2465
2466static int mv88e6xxx_serdes_irq_free(struct mv88e6xxx_chip *chip, int port,
2467 u8 lane)
2468{
2469 struct mv88e6xxx_port *dev_id = &chip->ports[port];
2470 unsigned int irq = dev_id->serdes_irq;
2471 int err;
2472
2473 /* Nothing to free if no IRQ has been requested */
2474 if (!irq)
2475 return 0;
2476
2477 err = mv88e6xxx_serdes_irq_disable(chip, port, lane);
2478
2479 /* Freeing the IRQ will trigger IRQ callbacks, so release the lock */
2480 mv88e6xxx_reg_unlock(chip);
2481 free_irq(irq, dev_id);
2482 mv88e6xxx_reg_lock(chip);
2483
2484 dev_id->serdes_irq = 0;
2485
2486 return err;
2487}
2488
Andrew Lunn6d917822017-05-26 01:03:21 +02002489static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
2490 bool on)
2491{
Vivien Didelotdc272f62019-08-31 16:18:33 -04002492 u8 lane;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002493 int err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002494
Vivien Didelotdc272f62019-08-31 16:18:33 -04002495 lane = mv88e6xxx_serdes_get_lane(chip, port);
2496 if (!lane)
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002497 return 0;
2498
2499 if (on) {
Vivien Didelotdc272f62019-08-31 16:18:33 -04002500 err = mv88e6xxx_serdes_power_up(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002501 if (err)
2502 return err;
2503
Vivien Didelot45de77f2019-08-31 16:18:36 -04002504 err = mv88e6xxx_serdes_irq_request(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002505 } else {
Vivien Didelot45de77f2019-08-31 16:18:36 -04002506 err = mv88e6xxx_serdes_irq_free(chip, port, lane);
2507 if (err)
2508 return err;
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002509
Vivien Didelotdc272f62019-08-31 16:18:33 -04002510 err = mv88e6xxx_serdes_power_down(chip, port, lane);
Vivien Didelotfc0bc012019-08-19 16:00:53 -04002511 }
2512
2513 return err;
Andrew Lunn6d917822017-05-26 01:03:21 +02002514}
2515
Vivien Didelotfa371c82017-12-05 15:34:10 -05002516static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
2517{
2518 struct dsa_switch *ds = chip->ds;
2519 int upstream_port;
2520 int err;
2521
Vivien Didelot07073c72017-12-05 15:34:13 -05002522 upstream_port = dsa_upstream_port(ds, port);
Vivien Didelotfa371c82017-12-05 15:34:10 -05002523 if (chip->info->ops->port_set_upstream_port) {
2524 err = chip->info->ops->port_set_upstream_port(chip, port,
2525 upstream_port);
2526 if (err)
2527 return err;
2528 }
2529
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002530 if (port == upstream_port) {
2531 if (chip->info->ops->set_cpu_port) {
2532 err = chip->info->ops->set_cpu_port(chip,
2533 upstream_port);
2534 if (err)
2535 return err;
2536 }
2537
2538 if (chip->info->ops->set_egress_port) {
2539 err = chip->info->ops->set_egress_port(chip,
Iwan R Timmer5c74c542019-11-07 22:11:13 +01002540 MV88E6XXX_EGRESS_DIR_INGRESS,
2541 upstream_port);
2542 if (err)
2543 return err;
2544
2545 err = chip->info->ops->set_egress_port(chip,
2546 MV88E6XXX_EGRESS_DIR_EGRESS,
2547 upstream_port);
Vivien Didelot0ea54dd2017-12-05 15:34:11 -05002548 if (err)
2549 return err;
2550 }
2551 }
2552
Vivien Didelotfa371c82017-12-05 15:34:10 -05002553 return 0;
2554}
2555
Vivien Didelotfad09c72016-06-21 12:28:20 -04002556static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002557{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002558 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002559 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002560 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002561
Andrew Lunn7b898462018-08-09 15:38:47 +02002562 chip->ports[port].chip = chip;
2563 chip->ports[port].port = port;
2564
Vivien Didelotd78343d2016-11-04 03:23:36 +01002565 /* MAC Forcing register: don't force link, speed, duplex or flow control
2566 * state to any particular values on physical ports, but force the CPU
2567 * port and all DSA ports to their maximum bandwidth and full duplex.
2568 */
2569 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2570 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2571 SPEED_MAX, DUPLEX_FULL,
Andrew Lunn54186b92018-08-09 15:38:37 +02002572 PAUSE_OFF,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002573 PHY_INTERFACE_MODE_NA);
2574 else
2575 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2576 SPEED_UNFORCED, DUPLEX_UNFORCED,
Andrew Lunn54186b92018-08-09 15:38:37 +02002577 PAUSE_ON,
Vivien Didelotd78343d2016-11-04 03:23:36 +01002578 PHY_INTERFACE_MODE_NA);
2579 if (err)
2580 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002581
2582 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2583 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2584 * tunneling, determine priority by looking at 802.1p and IP
2585 * priority fields (IP prio has precedence), and set STP state
2586 * to Forwarding.
2587 *
2588 * If this is the CPU link, use DSA or EDSA tagging depending
2589 * on which tagging mode was configured.
2590 *
2591 * If this is a link to another switch, use DSA tagging mode.
2592 *
2593 * If this is the upstream port for this switch, enable
2594 * forwarding of unknown unicasts and multicasts.
2595 */
Vivien Didelota89b433be2017-06-12 12:37:37 -04002596 reg = MV88E6XXX_PORT_CTL0_IGMP_MLD_SNOOP |
2597 MV88E6185_PORT_CTL0_USE_TAG | MV88E6185_PORT_CTL0_USE_IP |
2598 MV88E6XXX_PORT_CTL0_STATE_FORWARDING;
2599 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL0, reg);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002600 if (err)
2601 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002602
Vivien Didelot601aeed2017-03-11 16:13:00 -05002603 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002604 if (err)
2605 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002606
Vivien Didelot601aeed2017-03-11 16:13:00 -05002607 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002608 if (err)
2609 return err;
2610
Vivien Didelot8efdda42015-08-13 12:52:23 -04002611 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002612 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002613 * untagged frames on this port, do a destination address lookup on all
2614 * received packets as usual, disable ARP mirroring and don't send a
2615 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002616 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002617 err = mv88e6xxx_port_set_map_da(chip, port);
2618 if (err)
2619 return err;
2620
Vivien Didelotfa371c82017-12-05 15:34:10 -05002621 err = mv88e6xxx_setup_upstream_port(chip, port);
2622 if (err)
2623 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002624
Andrew Lunna23b2962017-02-04 20:15:28 +01002625 err = mv88e6xxx_port_set_8021q_mode(chip, port,
Vivien Didelot81c6edb2017-06-12 12:37:41 -04002626 MV88E6XXX_PORT_CTL2_8021Q_MODE_DISABLED);
Andrew Lunna23b2962017-02-04 20:15:28 +01002627 if (err)
2628 return err;
2629
Vivien Didelotcd782652017-06-08 18:34:13 -04002630 if (chip->info->ops->port_set_jumbo_size) {
2631 err = chip->info->ops->port_set_jumbo_size(chip, port, 10240);
Andrew Lunn5f436662016-12-03 04:45:17 +01002632 if (err)
2633 return err;
2634 }
2635
Andrew Lunn54d792f2015-05-06 01:09:47 +02002636 /* Port Association Vector: when learning source addresses
2637 * of packets, add the address to the address database using
2638 * a port bitmap that has only the bit for this port set and
2639 * the other bits clear.
2640 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002641 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002642 /* Disable learning for CPU port */
2643 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002644 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002645
Vivien Didelot2a4614e2017-06-12 12:37:43 -04002646 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_ASSOC_VECTOR,
2647 reg);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002648 if (err)
2649 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002650
2651 /* Egress rate control 2: disable egress rate control. */
Vivien Didelot2cb8cb12017-06-12 12:37:42 -04002652 err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_EGRESS_RATE_CTL2,
2653 0x0000);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002654 if (err)
2655 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002656
Vivien Didelot08984322017-06-08 18:34:12 -04002657 if (chip->info->ops->port_pause_limit) {
2658 err = chip->info->ops->port_pause_limit(chip, port, 0, 0);
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002659 if (err)
2660 return err;
2661 }
2662
Vivien Didelotc8c94892017-03-11 16:13:01 -05002663 if (chip->info->ops->port_disable_learn_limit) {
2664 err = chip->info->ops->port_disable_learn_limit(chip, port);
2665 if (err)
2666 return err;
2667 }
2668
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002669 if (chip->info->ops->port_disable_pri_override) {
2670 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002671 if (err)
2672 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002673 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002674
Andrew Lunnef0a7312016-12-03 04:35:16 +01002675 if (chip->info->ops->port_tag_remap) {
2676 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002677 if (err)
2678 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002679 }
2680
Andrew Lunnef70b112016-12-03 04:45:18 +01002681 if (chip->info->ops->port_egress_rate_limiting) {
2682 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002683 if (err)
2684 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002685 }
2686
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02002687 if (chip->info->ops->port_setup_message_port) {
2688 err = chip->info->ops->port_setup_message_port(chip, port);
2689 if (err)
2690 return err;
2691 }
Guenter Roeckd827e882015-03-26 18:36:29 -07002692
Vivien Didelot207afda2016-04-14 14:42:09 -04002693 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002694 * database, and allow bidirectional communication between the
2695 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002696 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002697 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002698 if (err)
2699 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002700
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002701 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002702 if (err)
2703 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002704
2705 /* Default VLAN ID and priority: don't set a default VLAN
2706 * ID, and set the default packet priority to zero.
2707 */
Vivien Didelotb7929fb2017-06-12 12:37:40 -04002708 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_DEFAULT_VLAN, 0);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002709}
2710
Andrew Lunn04aca992017-05-26 01:03:24 +02002711static int mv88e6xxx_port_enable(struct dsa_switch *ds, int port,
2712 struct phy_device *phydev)
2713{
2714 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot523a8902017-05-26 18:02:42 -04002715 int err;
Andrew Lunn04aca992017-05-26 01:03:24 +02002716
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002717 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002718 err = mv88e6xxx_serdes_power(chip, port, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002719 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002720
2721 return err;
2722}
2723
Andrew Lunn75104db2019-02-24 20:44:43 +01002724static void mv88e6xxx_port_disable(struct dsa_switch *ds, int port)
Andrew Lunn04aca992017-05-26 01:03:24 +02002725{
2726 struct mv88e6xxx_chip *chip = ds->priv;
2727
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002728 mv88e6xxx_reg_lock(chip);
Vivien Didelot523a8902017-05-26 18:02:42 -04002729 if (mv88e6xxx_serdes_power(chip, port, false))
2730 dev_err(chip->dev, "failed to power off SERDES\n");
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002731 mv88e6xxx_reg_unlock(chip);
Andrew Lunn04aca992017-05-26 01:03:24 +02002732}
2733
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002734static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2735 unsigned int ageing_time)
2736{
Vivien Didelot04bed142016-08-31 18:06:13 -04002737 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002738 int err;
2739
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002740 mv88e6xxx_reg_lock(chip);
Vivien Didelot720c6342017-03-11 16:12:48 -05002741 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00002742 mv88e6xxx_reg_unlock(chip);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002743
2744 return err;
2745}
2746
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002747static int mv88e6xxx_stats_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002748{
2749 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002750
Andrew Lunnde2273872016-11-21 23:27:01 +01002751 /* Initialize the statistics unit */
Vivien Didelot447b1bb2018-05-11 17:16:36 -04002752 if (chip->info->ops->stats_set_histogram) {
2753 err = chip->info->ops->stats_set_histogram(chip);
2754 if (err)
2755 return err;
2756 }
Andrew Lunnde2273872016-11-21 23:27:01 +01002757
Andrew Lunn40cff8f2017-11-10 00:36:41 +01002758 return mv88e6xxx_g1_stats_clear(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002759}
2760
Andrew Lunnea890982019-01-09 00:24:03 +01002761/* Check if the errata has already been applied. */
2762static bool mv88e6390_setup_errata_applied(struct mv88e6xxx_chip *chip)
2763{
2764 int port;
2765 int err;
2766 u16 val;
2767
2768 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002769 err = mv88e6xxx_port_hidden_read(chip, 0xf, port, 0, &val);
Andrew Lunnea890982019-01-09 00:24:03 +01002770 if (err) {
2771 dev_err(chip->dev,
2772 "Error reading hidden register: %d\n", err);
2773 return false;
2774 }
2775 if (val != 0x01c0)
2776 return false;
2777 }
2778
2779 return true;
2780}
2781
2782/* The 6390 copper ports have an errata which require poking magic
2783 * values into undocumented hidden registers and then performing a
2784 * software reset.
2785 */
2786static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)
2787{
2788 int port;
2789 int err;
2790
2791 if (mv88e6390_setup_errata_applied(chip))
2792 return 0;
2793
2794 /* Set the ports into blocking mode */
2795 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
2796 err = mv88e6xxx_port_set_state(chip, port, BR_STATE_DISABLED);
2797 if (err)
2798 return err;
2799 }
2800
2801 for (port = 0; port < mv88e6xxx_num_ports(chip); port++) {
Marek Behún60907012019-08-26 23:31:51 +02002802 err = mv88e6xxx_port_hidden_write(chip, 0xf, port, 0, 0x01c0);
Andrew Lunnea890982019-01-09 00:24:03 +01002803 if (err)
2804 return err;
2805 }
2806
2807 return mv88e6xxx_software_reset(chip);
2808}
2809
Andrew Lunn23e8b472019-10-25 01:03:52 +02002810enum mv88e6xxx_devlink_param_id {
2811 MV88E6XXX_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
2812 MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH,
2813};
2814
2815static int mv88e6xxx_devlink_param_get(struct dsa_switch *ds, u32 id,
2816 struct devlink_param_gset_ctx *ctx)
2817{
2818 struct mv88e6xxx_chip *chip = ds->priv;
2819 int err;
2820
2821 mv88e6xxx_reg_lock(chip);
2822
2823 switch (id) {
2824 case MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH:
2825 err = mv88e6xxx_atu_get_hash(chip, &ctx->val.vu8);
2826 break;
2827 default:
2828 err = -EOPNOTSUPP;
2829 break;
2830 }
2831
2832 mv88e6xxx_reg_unlock(chip);
2833
2834 return err;
2835}
2836
2837static int mv88e6xxx_devlink_param_set(struct dsa_switch *ds, u32 id,
2838 struct devlink_param_gset_ctx *ctx)
2839{
2840 struct mv88e6xxx_chip *chip = ds->priv;
2841 int err;
2842
2843 mv88e6xxx_reg_lock(chip);
2844
2845 switch (id) {
2846 case MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH:
2847 err = mv88e6xxx_atu_set_hash(chip, ctx->val.vu8);
2848 break;
2849 default:
2850 err = -EOPNOTSUPP;
2851 break;
2852 }
2853
2854 mv88e6xxx_reg_unlock(chip);
2855
2856 return err;
2857}
2858
2859static const struct devlink_param mv88e6xxx_devlink_params[] = {
2860 DSA_DEVLINK_PARAM_DRIVER(MV88E6XXX_DEVLINK_PARAM_ID_ATU_HASH,
2861 "ATU_hash", DEVLINK_PARAM_TYPE_U8,
2862 BIT(DEVLINK_PARAM_CMODE_RUNTIME)),
2863};
2864
2865static int mv88e6xxx_setup_devlink_params(struct dsa_switch *ds)
2866{
2867 return dsa_devlink_params_register(ds, mv88e6xxx_devlink_params,
2868 ARRAY_SIZE(mv88e6xxx_devlink_params));
2869}
2870
2871static void mv88e6xxx_teardown_devlink_params(struct dsa_switch *ds)
2872{
2873 dsa_devlink_params_unregister(ds, mv88e6xxx_devlink_params,
2874 ARRAY_SIZE(mv88e6xxx_devlink_params));
2875}
2876
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002877enum mv88e6xxx_devlink_resource_id {
2878 MV88E6XXX_RESOURCE_ID_ATU,
2879 MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
2880 MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
2881 MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
2882 MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
2883};
2884
2885static u64 mv88e6xxx_devlink_atu_bin_get(struct mv88e6xxx_chip *chip,
2886 u16 bin)
2887{
2888 u16 occupancy = 0;
2889 int err;
2890
2891 mv88e6xxx_reg_lock(chip);
2892
2893 err = mv88e6xxx_g2_atu_stats_set(chip, MV88E6XXX_G2_ATU_STATS_MODE_ALL,
2894 bin);
2895 if (err) {
2896 dev_err(chip->dev, "failed to set ATU stats kind/bin\n");
2897 goto unlock;
2898 }
2899
2900 err = mv88e6xxx_g1_atu_get_next(chip, 0);
2901 if (err) {
2902 dev_err(chip->dev, "failed to perform ATU get next\n");
2903 goto unlock;
2904 }
2905
2906 err = mv88e6xxx_g2_atu_stats_get(chip, &occupancy);
2907 if (err) {
2908 dev_err(chip->dev, "failed to get ATU stats\n");
2909 goto unlock;
2910 }
2911
Andrew Lunn012fc742020-03-11 21:02:31 +01002912 occupancy &= MV88E6XXX_G2_ATU_STATS_MASK;
2913
Andrew Lunne0c69ca2019-11-05 01:13:01 +01002914unlock:
2915 mv88e6xxx_reg_unlock(chip);
2916
2917 return occupancy;
2918}
2919
2920static u64 mv88e6xxx_devlink_atu_bin_0_get(void *priv)
2921{
2922 struct mv88e6xxx_chip *chip = priv;
2923
2924 return mv88e6xxx_devlink_atu_bin_get(chip,
2925 MV88E6XXX_G2_ATU_STATS_BIN_0);
2926}
2927
2928static u64 mv88e6xxx_devlink_atu_bin_1_get(void *priv)
2929{
2930 struct mv88e6xxx_chip *chip = priv;
2931
2932 return mv88e6xxx_devlink_atu_bin_get(chip,
2933 MV88E6XXX_G2_ATU_STATS_BIN_1);
2934}
2935
2936static u64 mv88e6xxx_devlink_atu_bin_2_get(void *priv)
2937{
2938 struct mv88e6xxx_chip *chip = priv;
2939
2940 return mv88e6xxx_devlink_atu_bin_get(chip,
2941 MV88E6XXX_G2_ATU_STATS_BIN_2);
2942}
2943
2944static u64 mv88e6xxx_devlink_atu_bin_3_get(void *priv)
2945{
2946 struct mv88e6xxx_chip *chip = priv;
2947
2948 return mv88e6xxx_devlink_atu_bin_get(chip,
2949 MV88E6XXX_G2_ATU_STATS_BIN_3);
2950}
2951
2952static u64 mv88e6xxx_devlink_atu_get(void *priv)
2953{
2954 return mv88e6xxx_devlink_atu_bin_0_get(priv) +
2955 mv88e6xxx_devlink_atu_bin_1_get(priv) +
2956 mv88e6xxx_devlink_atu_bin_2_get(priv) +
2957 mv88e6xxx_devlink_atu_bin_3_get(priv);
2958}
2959
2960static int mv88e6xxx_setup_devlink_resources(struct dsa_switch *ds)
2961{
2962 struct devlink_resource_size_params size_params;
2963 struct mv88e6xxx_chip *chip = ds->priv;
2964 int err;
2965
2966 devlink_resource_size_params_init(&size_params,
2967 mv88e6xxx_num_macs(chip),
2968 mv88e6xxx_num_macs(chip),
2969 1, DEVLINK_RESOURCE_UNIT_ENTRY);
2970
2971 err = dsa_devlink_resource_register(ds, "ATU",
2972 mv88e6xxx_num_macs(chip),
2973 MV88E6XXX_RESOURCE_ID_ATU,
2974 DEVLINK_RESOURCE_ID_PARENT_TOP,
2975 &size_params);
2976 if (err)
2977 goto out;
2978
2979 devlink_resource_size_params_init(&size_params,
2980 mv88e6xxx_num_macs(chip) / 4,
2981 mv88e6xxx_num_macs(chip) / 4,
2982 1, DEVLINK_RESOURCE_UNIT_ENTRY);
2983
2984 err = dsa_devlink_resource_register(ds, "ATU_bin_0",
2985 mv88e6xxx_num_macs(chip) / 4,
2986 MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
2987 MV88E6XXX_RESOURCE_ID_ATU,
2988 &size_params);
2989 if (err)
2990 goto out;
2991
2992 err = dsa_devlink_resource_register(ds, "ATU_bin_1",
2993 mv88e6xxx_num_macs(chip) / 4,
2994 MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
2995 MV88E6XXX_RESOURCE_ID_ATU,
2996 &size_params);
2997 if (err)
2998 goto out;
2999
3000 err = dsa_devlink_resource_register(ds, "ATU_bin_2",
3001 mv88e6xxx_num_macs(chip) / 4,
3002 MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
3003 MV88E6XXX_RESOURCE_ID_ATU,
3004 &size_params);
3005 if (err)
3006 goto out;
3007
3008 err = dsa_devlink_resource_register(ds, "ATU_bin_3",
3009 mv88e6xxx_num_macs(chip) / 4,
3010 MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
3011 MV88E6XXX_RESOURCE_ID_ATU,
3012 &size_params);
3013 if (err)
3014 goto out;
3015
3016 dsa_devlink_resource_occ_get_register(ds,
3017 MV88E6XXX_RESOURCE_ID_ATU,
3018 mv88e6xxx_devlink_atu_get,
3019 chip);
3020
3021 dsa_devlink_resource_occ_get_register(ds,
3022 MV88E6XXX_RESOURCE_ID_ATU_BIN_0,
3023 mv88e6xxx_devlink_atu_bin_0_get,
3024 chip);
3025
3026 dsa_devlink_resource_occ_get_register(ds,
3027 MV88E6XXX_RESOURCE_ID_ATU_BIN_1,
3028 mv88e6xxx_devlink_atu_bin_1_get,
3029 chip);
3030
3031 dsa_devlink_resource_occ_get_register(ds,
3032 MV88E6XXX_RESOURCE_ID_ATU_BIN_2,
3033 mv88e6xxx_devlink_atu_bin_2_get,
3034 chip);
3035
3036 dsa_devlink_resource_occ_get_register(ds,
3037 MV88E6XXX_RESOURCE_ID_ATU_BIN_3,
3038 mv88e6xxx_devlink_atu_bin_3_get,
3039 chip);
3040
3041 return 0;
3042
3043out:
3044 dsa_devlink_resources_unregister(ds);
3045 return err;
3046}
3047
Andrew Lunn23e8b472019-10-25 01:03:52 +02003048static void mv88e6xxx_teardown(struct dsa_switch *ds)
3049{
3050 mv88e6xxx_teardown_devlink_params(ds);
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003051 dsa_devlink_resources_unregister(ds);
Andrew Lunn23e8b472019-10-25 01:03:52 +02003052}
3053
Vivien Didelotf81ec902016-05-09 13:22:58 -04003054static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07003055{
Vivien Didelot04bed142016-08-31 18:06:13 -04003056 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003057 u8 cmode;
Vivien Didelot552238b2016-05-09 13:22:49 -04003058 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04003059 int i;
3060
Vivien Didelotfad09c72016-06-21 12:28:20 -04003061 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003062 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003063
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003064 mv88e6xxx_reg_lock(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04003065
Andrew Lunnea890982019-01-09 00:24:03 +01003066 if (chip->info->ops->setup_errata) {
3067 err = chip->info->ops->setup_errata(chip);
3068 if (err)
3069 goto unlock;
3070 }
3071
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003072 /* Cache the cmode of each port. */
3073 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
3074 if (chip->info->ops->port_get_cmode) {
3075 err = chip->info->ops->port_get_cmode(chip, i, &cmode);
3076 if (err)
Dan Carpentere29129f2018-08-14 12:09:05 +03003077 goto unlock;
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003078
3079 chip->ports[i].cmode = cmode;
3080 }
3081 }
3082
Vivien Didelot97299342016-07-18 20:45:30 -04003083 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04003084 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelotb759f522019-08-19 16:00:52 -04003085 if (dsa_is_unused_port(ds, i))
3086 continue;
3087
Hubert Feursteinc8574862019-07-31 10:23:48 +02003088 /* Prevent the use of an invalid port. */
Vivien Didelotb759f522019-08-19 16:00:52 -04003089 if (mv88e6xxx_is_invalid_port(chip, i)) {
Hubert Feursteinc8574862019-07-31 10:23:48 +02003090 dev_err(chip->dev, "port %d is invalid\n", i);
3091 err = -EINVAL;
3092 goto unlock;
3093 }
3094
Vivien Didelot97299342016-07-18 20:45:30 -04003095 err = mv88e6xxx_setup_port(chip, i);
3096 if (err)
3097 goto unlock;
3098 }
3099
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003100 err = mv88e6xxx_irl_setup(chip);
3101 if (err)
3102 goto unlock;
3103
Vivien Didelot04a69a12017-10-13 14:18:05 -04003104 err = mv88e6xxx_mac_setup(chip);
3105 if (err)
3106 goto unlock;
3107
Vivien Didelot1b17aed2017-05-26 18:03:05 -04003108 err = mv88e6xxx_phy_setup(chip);
3109 if (err)
3110 goto unlock;
3111
Vivien Didelotb486d7c2017-05-01 14:05:13 -04003112 err = mv88e6xxx_vtu_setup(chip);
3113 if (err)
3114 goto unlock;
3115
Vivien Didelot81228992017-03-30 17:37:08 -04003116 err = mv88e6xxx_pvt_setup(chip);
3117 if (err)
3118 goto unlock;
3119
Vivien Didelota2ac29d2017-03-11 16:12:49 -05003120 err = mv88e6xxx_atu_setup(chip);
3121 if (err)
3122 goto unlock;
3123
Andrew Lunn87fa8862017-11-09 22:29:56 +01003124 err = mv88e6xxx_broadcast_setup(chip, 0);
3125 if (err)
3126 goto unlock;
3127
Vivien Didelot9e907d72017-07-17 13:03:43 -04003128 err = mv88e6xxx_pot_setup(chip);
3129 if (err)
3130 goto unlock;
3131
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003132 err = mv88e6xxx_rmu_setup(chip);
3133 if (err)
3134 goto unlock;
3135
Vivien Didelot51c901a2017-07-17 13:03:41 -04003136 err = mv88e6xxx_rsvd2cpu_setup(chip);
3137 if (err)
3138 goto unlock;
Andrew Lunn6e55f692016-12-03 04:45:16 +01003139
Vivien Didelotb28f8722018-04-26 21:56:44 -04003140 err = mv88e6xxx_trunk_setup(chip);
3141 if (err)
3142 goto unlock;
3143
Vivien Didelotc7f047b2018-04-26 21:56:45 -04003144 err = mv88e6xxx_devmap_setup(chip);
3145 if (err)
3146 goto unlock;
3147
Vivien Didelot93e18d62018-05-11 17:16:35 -04003148 err = mv88e6xxx_pri_setup(chip);
3149 if (err)
3150 goto unlock;
3151
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003152 /* Setup PTP Hardware Clock and timestamping */
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003153 if (chip->info->ptp_support) {
3154 err = mv88e6xxx_ptp_setup(chip);
3155 if (err)
3156 goto unlock;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01003157
3158 err = mv88e6xxx_hwtstamp_setup(chip);
3159 if (err)
3160 goto unlock;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01003161 }
3162
Vivien Didelot447b1bb2018-05-11 17:16:36 -04003163 err = mv88e6xxx_stats_setup(chip);
3164 if (err)
3165 goto unlock;
3166
Vivien Didelot6b17e862015-08-13 12:52:18 -04003167unlock:
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003168 mv88e6xxx_reg_unlock(chip);
Andrew Lunndb687a52015-06-20 21:31:29 +02003169
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003170 if (err)
3171 return err;
3172
3173 /* Have to be called without holding the register lock, since
3174 * they take the devlink lock, and we later take the locks in
3175 * the reverse order when getting/setting parameters or
3176 * resource occupancy.
Andrew Lunn23e8b472019-10-25 01:03:52 +02003177 */
Andrew Lunne0c69ca2019-11-05 01:13:01 +01003178 err = mv88e6xxx_setup_devlink_resources(ds);
3179 if (err)
3180 return err;
3181
3182 err = mv88e6xxx_setup_devlink_params(ds);
3183 if (err)
3184 dsa_devlink_resources_unregister(ds);
3185
3186 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02003187}
3188
Vivien Didelote57e5e72016-08-15 17:19:00 -04003189static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003190{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003191 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3192 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003193 u16 val;
3194 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003195
Andrew Lunnee26a222017-01-24 14:53:48 +01003196 if (!chip->info->ops->phy_read)
3197 return -EOPNOTSUPP;
3198
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003199 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003200 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003201 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003202
Andrew Lunnda9f3302017-02-01 03:40:05 +01003203 if (reg == MII_PHYSID2) {
Andrew Lunnddc49ac2018-11-12 18:51:01 +01003204 /* Some internal PHYs don't have a model number. */
3205 if (chip->info->family != MV88E6XXX_FAMILY_6165)
3206 /* Then there is the 6165 family. It gets is
3207 * PHYs correct. But it can also have two
3208 * SERDES interfaces in the PHY address
3209 * space. And these don't have a model
3210 * number. But they are not PHYs, so we don't
3211 * want to give them something a PHY driver
3212 * will recognise.
3213 *
3214 * Use the mv88e6390 family model number
3215 * instead, for anything which really could be
3216 * a PHY,
3217 */
3218 if (!(val & 0x3f0))
3219 val |= MV88E6XXX_PORT_SWITCH_ID_PROD_6390 >> 4;
Andrew Lunnda9f3302017-02-01 03:40:05 +01003220 }
3221
Vivien Didelote57e5e72016-08-15 17:19:00 -04003222 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003223}
3224
Vivien Didelote57e5e72016-08-15 17:19:00 -04003225static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003226{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003227 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
3228 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04003229 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003230
Andrew Lunnee26a222017-01-24 14:53:48 +01003231 if (!chip->info->ops->phy_write)
3232 return -EOPNOTSUPP;
3233
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003234 mv88e6xxx_reg_lock(chip);
Andrew Lunnee26a222017-01-24 14:53:48 +01003235 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003236 mv88e6xxx_reg_unlock(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003237
3238 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02003239}
3240
Vivien Didelotfad09c72016-06-21 12:28:20 -04003241static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01003242 struct device_node *np,
3243 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02003244{
3245 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003246 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003247 struct mii_bus *bus;
3248 int err;
3249
Andrew Lunn2510bab2018-02-22 01:51:49 +01003250 if (external) {
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003251 mv88e6xxx_reg_lock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003252 err = mv88e6xxx_g2_scratch_gpio_set_smi(chip, true);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003253 mv88e6xxx_reg_unlock(chip);
Andrew Lunn2510bab2018-02-22 01:51:49 +01003254
3255 if (err)
3256 return err;
3257 }
3258
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003259 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02003260 if (!bus)
3261 return -ENOMEM;
3262
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003263 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003264 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003265 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01003266 INIT_LIST_HEAD(&mdio_bus->list);
3267 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01003268
Andrew Lunnb516d452016-06-04 21:17:06 +02003269 if (np) {
3270 bus->name = np->full_name;
Rob Herringf7ce9102017-07-18 16:43:19 -05003271 snprintf(bus->id, MII_BUS_ID_SIZE, "%pOF", np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003272 } else {
3273 bus->name = "mv88e6xxx SMI";
3274 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
3275 }
3276
3277 bus->read = mv88e6xxx_mdio_read;
3278 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003279 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02003280
Andrew Lunn6f882842018-03-17 20:32:05 +01003281 if (!external) {
3282 err = mv88e6xxx_g2_irq_mdio_setup(chip, bus);
3283 if (err)
3284 return err;
3285 }
3286
Florian Fainelli00e798c2018-05-15 16:56:19 -07003287 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003288 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003289 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunn6f882842018-03-17 20:32:05 +01003290 mv88e6xxx_g2_irq_mdio_free(chip, bus);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003291 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003292 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003293
3294 if (external)
3295 list_add_tail(&mdio_bus->list, &chip->mdios);
3296 else
3297 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003298
3299 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003300}
3301
Andrew Lunna3c53be52017-01-24 14:53:50 +01003302static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
3303 { .compatible = "marvell,mv88e6xxx-mdio-external",
3304 .data = (void *)true },
3305 { },
3306};
3307
Andrew Lunn3126aee2017-12-07 01:05:57 +01003308static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
3309
3310{
3311 struct mv88e6xxx_mdio_bus *mdio_bus;
3312 struct mii_bus *bus;
3313
3314 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3315 bus = mdio_bus->bus;
3316
Andrew Lunn6f882842018-03-17 20:32:05 +01003317 if (!mdio_bus->external)
3318 mv88e6xxx_g2_irq_mdio_free(chip, bus);
3319
Andrew Lunn3126aee2017-12-07 01:05:57 +01003320 mdiobus_unregister(bus);
3321 }
3322}
3323
Andrew Lunna3c53be52017-01-24 14:53:50 +01003324static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3325 struct device_node *np)
3326{
3327 const struct of_device_id *match;
3328 struct device_node *child;
3329 int err;
3330
3331 /* Always register one mdio bus for the internal/default mdio
3332 * bus. This maybe represented in the device tree, but is
3333 * optional.
3334 */
3335 child = of_get_child_by_name(np, "mdio");
3336 err = mv88e6xxx_mdio_register(chip, child, false);
3337 if (err)
3338 return err;
3339
3340 /* Walk the device tree, and see if there are any other nodes
3341 * which say they are compatible with the external mdio
3342 * bus.
3343 */
3344 for_each_available_child_of_node(np, child) {
3345 match = of_match_node(mv88e6xxx_mdio_external_match, child);
3346 if (match) {
3347 err = mv88e6xxx_mdio_register(chip, child, true);
Andrew Lunn3126aee2017-12-07 01:05:57 +01003348 if (err) {
3349 mv88e6xxx_mdios_unregister(chip);
Nishka Dasgupta78e42042019-07-23 16:13:07 +05303350 of_node_put(child);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003351 return err;
Andrew Lunn3126aee2017-12-07 01:05:57 +01003352 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003353 }
3354 }
3355
3356 return 0;
3357}
3358
Vivien Didelot855b1932016-07-20 18:18:35 -04003359static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3360{
Vivien Didelot04bed142016-08-31 18:06:13 -04003361 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003362
3363 return chip->eeprom_len;
3364}
3365
Vivien Didelot855b1932016-07-20 18:18:35 -04003366static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3367 struct ethtool_eeprom *eeprom, u8 *data)
3368{
Vivien Didelot04bed142016-08-31 18:06:13 -04003369 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003370 int err;
3371
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003372 if (!chip->info->ops->get_eeprom)
3373 return -EOPNOTSUPP;
3374
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003375 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003376 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003377 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003378
3379 if (err)
3380 return err;
3381
3382 eeprom->magic = 0xc3ec4951;
3383
3384 return 0;
3385}
3386
Vivien Didelot855b1932016-07-20 18:18:35 -04003387static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3388 struct ethtool_eeprom *eeprom, u8 *data)
3389{
Vivien Didelot04bed142016-08-31 18:06:13 -04003390 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003391 int err;
3392
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003393 if (!chip->info->ops->set_eeprom)
3394 return -EOPNOTSUPP;
3395
Vivien Didelot855b1932016-07-20 18:18:35 -04003396 if (eeprom->magic != 0xc3ec4951)
3397 return -EINVAL;
3398
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003399 mv88e6xxx_reg_lock(chip);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003400 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00003401 mv88e6xxx_reg_unlock(chip);
Vivien Didelot855b1932016-07-20 18:18:35 -04003402
3403 return err;
3404}
3405
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003406static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003407 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003408 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3409 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003410 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003411 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003412 .phy_read = mv88e6185_phy_ppu_read,
3413 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003414 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003415 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003416 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003417 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003418 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003419 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003420 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003421 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003422 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003423 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003424 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003425 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003426 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003427 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003428 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003429 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003430 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3431 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003432 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003433 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3434 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003435 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003436 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003437 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003438 .ppu_enable = mv88e6185_g1_ppu_enable,
3439 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003440 .reset = mv88e6185_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003441 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003442 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003443 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003444 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003445};
3446
3447static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003448 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003449 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3450 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003451 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003452 .phy_read = mv88e6185_phy_ppu_read,
3453 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003454 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003455 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003456 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003457 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003458 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01003459 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Russell King6c422e32018-08-09 15:38:39 +02003460 .port_link_state = mv88e6185_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003461 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003462 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003463 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003464 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003465 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3466 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003467 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003468 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003469 .ppu_enable = mv88e6185_g1_ppu_enable,
3470 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003471 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003472 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003473 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003474 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003475};
3476
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003477static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003478 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003479 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3480 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003481 .irl_init_all = mv88e6352_g2_irl_init_all,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003482 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3483 .phy_read = mv88e6xxx_g2_smi_phy_read,
3484 .phy_write = mv88e6xxx_g2_smi_phy_write,
3485 .port_set_link = mv88e6xxx_port_set_link,
3486 .port_set_duplex = mv88e6xxx_port_set_duplex,
3487 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003488 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003489 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003490 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003491 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003492 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003493 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003494 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003495 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003496 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003497 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003498 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003499 .port_setup_message_port = mv88e6xxx_setup_message_port,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003500 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003501 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003502 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3503 .stats_get_strings = mv88e6095_stats_get_strings,
3504 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003505 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3506 .set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003507 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003508 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003509 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003510 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003511 .rmu_disable = mv88e6085_g1_rmu_disable,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003512 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003513 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003514 .phylink_validate = mv88e6185_phylink_validate,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003515};
3516
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003517static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003518 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003519 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3520 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003521 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003522 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003523 .phy_read = mv88e6xxx_g2_smi_phy_read,
3524 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003525 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003526 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003527 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003528 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003529 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003530 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003531 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003532 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003533 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003534 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn0ac64c32017-06-02 23:22:46 +02003535 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003536 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003537 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3538 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003539 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003540 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3541 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003542 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003543 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003544 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003545 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003546 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3547 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003548 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003549 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003550 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003551};
3552
3553static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003554 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003555 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3556 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003557 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003558 .phy_read = mv88e6185_phy_ppu_read,
3559 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003560 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003561 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003562 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003563 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003564 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003565 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003566 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003567 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Vivien Didelotcd782652017-06-08 18:34:13 -04003568 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003569 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003570 .port_pause_limit = mv88e6097_port_pause_limit,
Andrew Lunn54186b92018-08-09 15:38:37 +02003571 .port_set_pause = mv88e6185_port_set_pause,
Russell King6c422e32018-08-09 15:38:39 +02003572 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003573 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003574 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003575 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003576 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003577 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3578 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003579 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003580 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3581 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003582 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003583 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003584 .ppu_enable = mv88e6185_g1_ppu_enable,
Vivien Didelot02317e62018-05-09 11:38:49 -04003585 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003586 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003587 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003588 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003589 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003590 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003591};
3592
Vivien Didelot990e27b2017-03-28 13:50:32 -04003593static const struct mv88e6xxx_ops mv88e6141_ops = {
3594 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003595 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3596 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003597 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003598 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3599 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3600 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3601 .phy_read = mv88e6xxx_g2_smi_phy_read,
3602 .phy_write = mv88e6xxx_g2_smi_phy_write,
3603 .port_set_link = mv88e6xxx_port_set_link,
3604 .port_set_duplex = mv88e6xxx_port_set_duplex,
3605 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Marek Behún26422342018-10-13 14:40:31 +02003606 .port_set_speed = mv88e6341_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003607 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003608 .port_tag_remap = mv88e6095_port_tag_remap,
3609 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3610 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3611 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003612 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003613 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003614 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003615 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3616 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003617 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003618 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02003619 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003620 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003621 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003622 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003623 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3624 .stats_get_strings = mv88e6320_stats_get_strings,
3625 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003626 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3627 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003628 .watchdog_ops = &mv88e6390_watchdog_ops,
3629 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003630 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003631 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003632 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003633 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02003634 .serdes_power = mv88e6390_serdes_power,
3635 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003636 /* Check status register pause & lpa register */
3637 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
3638 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
3639 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
3640 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003641 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003642 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003643 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003644 .gpio_ops = &mv88e6352_gpio_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01003645 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003646};
3647
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003648static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003649 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003650 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3651 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003652 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003653 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnec8378b2017-06-02 23:22:45 +02003654 .phy_read = mv88e6xxx_g2_smi_phy_read,
3655 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003656 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003657 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003658 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003659 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003660 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003661 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003662 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003663 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003664 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003665 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003666 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003667 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003668 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003669 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003670 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna6da21b2019-03-01 23:43:39 +01003671 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003672 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003673 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3674 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003675 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003676 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3677 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003678 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003679 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003680 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003681 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003682 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3683 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003684 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003685 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003686 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003687 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003688 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003689};
3690
3691static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003692 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003693 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3694 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003695 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003696 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003697 .phy_read = mv88e6165_phy_read,
3698 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003699 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003700 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003701 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003702 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003703 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003704 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003705 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003706 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003707 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003708 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003709 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3710 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003711 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003712 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3713 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003714 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003715 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003716 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003717 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003718 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3719 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003720 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003721 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Andrew Lunna469a612018-07-18 22:38:21 +02003722 .avb_ops = &mv88e6165_avb_ops,
Andrew Lunndfa54342018-07-18 22:38:22 +02003723 .ptp_ops = &mv88e6165_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02003724 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003725};
3726
3727static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003728 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003729 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3730 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003731 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003732 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003733 .phy_read = mv88e6xxx_g2_smi_phy_read,
3734 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003735 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003736 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003737 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003738 .port_set_speed = mv88e6185_port_set_speed,
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,
Russell King6c422e32018-08-09 15:38:39 +02003748 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003749 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003750 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003751 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003752 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003753 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3754 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003755 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003756 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3757 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003758 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003759 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003760 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003761 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003762 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3763 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003764 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003765 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003766 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003767};
3768
3769static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003770 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003771 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3772 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003773 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003774 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3775 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003776 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003777 .phy_read = mv88e6xxx_g2_smi_phy_read,
3778 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003779 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003780 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003781 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003782 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003783 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003784 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003785 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003786 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003787 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003788 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003789 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003790 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003791 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003792 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003793 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003794 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003795 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003796 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003797 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003798 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3799 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003800 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003801 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3802 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003803 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003804 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003805 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003806 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003807 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003808 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3809 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003810 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003811 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003812 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003813 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3814 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3815 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3816 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003817 .serdes_power = mv88e6352_serdes_power,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003818 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3819 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003820 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003821 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003822};
3823
3824static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003825 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003826 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3827 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003828 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003829 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003830 .phy_read = mv88e6xxx_g2_smi_phy_read,
3831 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003832 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003833 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003834 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003835 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003836 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003837 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003838 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003839 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003840 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003841 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003842 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003843 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003844 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003845 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003846 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003847 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003848 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003849 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003850 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3851 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003852 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003853 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3854 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003855 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003856 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003857 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003858 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003859 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3860 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003861 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003862 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003863 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003864};
3865
3866static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003867 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003868 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3869 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003870 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003871 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3872 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003873 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003874 .phy_read = mv88e6xxx_g2_smi_phy_read,
3875 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003876 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003877 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003878 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003879 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003880 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003881 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003882 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003883 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003884 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04003885 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01003886 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04003887 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003888 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003889 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003890 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003891 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003892 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003893 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003894 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003895 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3896 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003897 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003898 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3899 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003900 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003901 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003902 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003903 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003904 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003905 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3906 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003907 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003908 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04003909 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00003910 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
3911 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
3912 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
3913 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02003914 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04003915 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04003916 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04003917 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01003918 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
3919 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01003920 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02003921 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003922};
3923
3924static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003925 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04003926 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
3927 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003928 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelot7e20cfb2017-05-26 18:03:06 -04003929 .phy_read = mv88e6185_phy_ppu_read,
3930 .phy_write = mv88e6185_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003931 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003932 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003933 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003934 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003935 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003936 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003937 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn54186b92018-08-09 15:38:37 +02003938 .port_set_pause = mv88e6185_port_set_pause,
Russell King6c422e32018-08-09 15:38:39 +02003939 .port_link_state = mv88e6185_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003940 .port_get_cmode = mv88e6185_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003941 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003942 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01003943 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003944 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3945 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003946 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003947 .set_cpu_port = mv88e6095_g1_set_cpu_port,
3948 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003949 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04003950 .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu,
Vivien Didelot02317e62018-05-09 11:38:49 -04003951 .set_cascade_port = mv88e6185_g1_set_cascade_port,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003952 .ppu_enable = mv88e6185_g1_ppu_enable,
3953 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003954 .reset = mv88e6185_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04003955 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04003956 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02003957 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003958};
3959
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003960static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003961 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01003962 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04003963 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003964 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3965 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003966 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3967 .phy_read = mv88e6xxx_g2_smi_phy_read,
3968 .phy_write = mv88e6xxx_g2_smi_phy_write,
3969 .port_set_link = mv88e6xxx_port_set_link,
3970 .port_set_duplex = mv88e6xxx_port_set_duplex,
3971 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3972 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01003973 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003974 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04003975 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003976 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003977 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003978 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04003979 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003980 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003981 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02003982 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02003983 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01003984 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02003985 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01003986 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003987 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003988 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3989 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003990 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04003991 .set_cpu_port = mv88e6390_g1_set_cpu_port,
3992 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003993 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003994 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04003995 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003996 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04003997 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02003998 .atu_get_hash = mv88e6165_g1_atu_get_hash,
3999 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004000 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4001 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004002 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004003 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004004 /* Check status register pause & lpa register */
4005 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4006 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4007 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4008 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004009 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004010 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004011 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004012 .serdes_get_strings = mv88e6390_serdes_get_strings,
4013 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004014 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4015 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn4262c382020-01-18 19:40:56 +01004016 .phylink_validate = mv88e6390_phylink_validate,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004017 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004018 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004019};
4020
4021static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004022 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004023 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004024 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004025 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4026 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004027 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4028 .phy_read = mv88e6xxx_g2_smi_phy_read,
4029 .phy_write = mv88e6xxx_g2_smi_phy_write,
4030 .port_set_link = mv88e6xxx_port_set_link,
4031 .port_set_duplex = mv88e6xxx_port_set_duplex,
4032 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4033 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004034 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004035 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004036 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004037 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004038 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004039 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004040 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004041 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004042 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004043 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004044 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004045 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004046 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004047 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004048 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004049 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4050 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004051 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004052 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4053 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004054 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004055 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004056 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004057 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004058 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004059 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4060 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004061 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4062 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004063 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004064 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004065 /* Check status register pause & lpa register */
4066 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4067 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4068 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4069 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004070 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004071 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004072 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004073 .serdes_get_strings = mv88e6390_serdes_get_strings,
4074 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004075 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4076 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn4262c382020-01-18 19:40:56 +01004077 .phylink_validate = mv88e6390_phylink_validate,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004078 .gpio_ops = &mv88e6352_gpio_ops,
Russell King6c422e32018-08-09 15:38:39 +02004079 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004080};
4081
4082static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004083 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004084 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004085 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004086 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4087 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004088 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4089 .phy_read = mv88e6xxx_g2_smi_phy_read,
4090 .phy_write = mv88e6xxx_g2_smi_phy_write,
4091 .port_set_link = mv88e6xxx_port_set_link,
4092 .port_set_duplex = mv88e6xxx_port_set_duplex,
4093 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4094 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004095 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004096 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004097 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004098 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004099 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004100 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004101 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004102 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004103 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004104 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004105 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004106 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004107 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004108 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004109 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4110 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004111 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004112 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4113 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004114 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004115 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004116 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004117 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004118 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004119 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4120 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004121 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4122 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004123 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004124 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004125 /* Check status register pause & lpa register */
4126 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4127 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4128 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4129 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004130 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004131 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004132 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004133 .serdes_get_strings = mv88e6390_serdes_get_strings,
4134 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004135 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4136 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn4262c382020-01-18 19:40:56 +01004137 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004138 .avb_ops = &mv88e6390_avb_ops,
4139 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004140 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004141};
4142
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004143static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004144 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004145 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4146 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004147 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004148 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4149 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004150 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004151 .phy_read = mv88e6xxx_g2_smi_phy_read,
4152 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004153 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01004154 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004155 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01004156 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004157 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004158 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004159 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004160 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004161 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004162 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004163 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004164 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004165 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004166 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004167 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004168 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004169 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004170 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004171 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004172 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4173 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004174 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004175 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4176 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004177 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004178 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004179 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004180 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004181 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004182 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4183 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004184 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004185 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004186 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004187 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4188 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4189 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4190 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004191 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004192 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004193 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004194 .serdes_irq_status = mv88e6352_serdes_irq_status,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004195 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4196 .serdes_get_regs = mv88e6352_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004197 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004198 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004199 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004200 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004201};
4202
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004203static const struct mv88e6xxx_ops mv88e6250_ops = {
4204 /* MV88E6XXX_FAMILY_6250 */
4205 .ieee_pri_map = mv88e6250_g1_ieee_pri_map,
4206 .ip_pri_map = mv88e6085_g1_ip_pri_map,
4207 .irl_init_all = mv88e6352_g2_irl_init_all,
4208 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4209 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
4210 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4211 .phy_read = mv88e6xxx_g2_smi_phy_read,
4212 .phy_write = mv88e6xxx_g2_smi_phy_write,
4213 .port_set_link = mv88e6xxx_port_set_link,
4214 .port_set_duplex = mv88e6xxx_port_set_duplex,
4215 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
4216 .port_set_speed = mv88e6250_port_set_speed,
4217 .port_tag_remap = mv88e6095_port_tag_remap,
4218 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4219 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
4220 .port_set_ether_type = mv88e6351_port_set_ether_type,
4221 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
4222 .port_pause_limit = mv88e6097_port_pause_limit,
4223 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
4224 .port_link_state = mv88e6250_port_link_state,
4225 .stats_snapshot = mv88e6320_g1_stats_snapshot,
4226 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
4227 .stats_get_sset_count = mv88e6250_stats_get_sset_count,
4228 .stats_get_strings = mv88e6250_stats_get_strings,
4229 .stats_get_stats = mv88e6250_stats_get_stats,
4230 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4231 .set_egress_port = mv88e6095_g1_set_egress_port,
4232 .watchdog_ops = &mv88e6250_watchdog_ops,
4233 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
4234 .pot_clear = mv88e6xxx_g2_pot_clear,
4235 .reset = mv88e6250_g1_reset,
4236 .vtu_getnext = mv88e6250_g1_vtu_getnext,
4237 .vtu_loadpurge = mv88e6250_g1_vtu_loadpurge,
Hubert Feurstein71509612019-07-31 10:23:51 +02004238 .avb_ops = &mv88e6352_avb_ops,
4239 .ptp_ops = &mv88e6250_ptp_ops,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00004240 .phylink_validate = mv88e6065_phylink_validate,
4241};
4242
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004243static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004244 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004245 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004246 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004247 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4248 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004249 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4250 .phy_read = mv88e6xxx_g2_smi_phy_read,
4251 .phy_write = mv88e6xxx_g2_smi_phy_write,
4252 .port_set_link = mv88e6xxx_port_set_link,
4253 .port_set_duplex = mv88e6xxx_port_set_duplex,
4254 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4255 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004256 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004257 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004258 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004259 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004260 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004261 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelot08984322017-06-08 18:34:12 -04004262 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004263 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004264 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004265 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004266 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004267 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004268 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004269 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004270 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004271 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4272 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004273 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004274 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4275 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004276 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004277 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004278 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004279 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004280 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004281 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4282 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004283 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4284 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004285 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004286 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004287 /* Check status register pause & lpa register */
4288 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4289 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4290 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4291 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004292 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004293 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004294 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004295 .serdes_get_strings = mv88e6390_serdes_get_strings,
4296 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004297 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4298 .serdes_get_regs = mv88e6390_serdes_get_regs,
Andrew Lunn4262c382020-01-18 19:40:56 +01004299 .phylink_validate = mv88e6390_phylink_validate,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004300 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004301 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004302 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004303 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004304};
4305
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004306static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004307 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004308 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4309 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004310 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004311 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4312 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004313 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004314 .phy_read = mv88e6xxx_g2_smi_phy_read,
4315 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004316 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01004317 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01004318 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004319 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004320 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004321 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004322 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004323 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004324 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004325 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004326 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004327 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004328 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004329 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004330 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004331 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004332 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004333 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4334 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004335 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004336 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4337 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004338 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004339 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004340 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004341 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004342 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004343 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004344 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004345 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004346 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004347 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004348};
4349
4350static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotbd807202017-07-17 13:03:37 -04004351 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004352 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4353 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004354 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004355 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4356 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004357 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004358 .phy_read = mv88e6xxx_g2_smi_phy_read,
4359 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004360 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01004361 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01004362 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004363 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004364 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004365 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004366 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004367 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004368 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004369 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004370 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004371 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004372 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004373 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004374 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004375 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004376 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004377 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4378 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004379 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004380 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4381 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn9c7f37e2018-12-19 18:28:54 +01004382 .watchdog_ops = &mv88e6390_watchdog_ops,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004383 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004384 .vtu_getnext = mv88e6185_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004385 .vtu_loadpurge = mv88e6185_g1_vtu_loadpurge,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004386 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004387 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004388 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004389 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004390};
4391
Vivien Didelot16e329a2017-03-28 13:50:33 -04004392static const struct mv88e6xxx_ops mv88e6341_ops = {
4393 /* MV88E6XXX_FAMILY_6341 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004394 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4395 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004396 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004397 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4398 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
4399 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4400 .phy_read = mv88e6xxx_g2_smi_phy_read,
4401 .phy_write = mv88e6xxx_g2_smi_phy_write,
4402 .port_set_link = mv88e6xxx_port_set_link,
4403 .port_set_duplex = mv88e6xxx_port_set_duplex,
4404 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
Marek Behún26422342018-10-13 14:40:31 +02004405 .port_set_speed = mv88e6341_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004406 .port_max_speed_mode = mv88e6341_port_max_speed_mode,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004407 .port_tag_remap = mv88e6095_port_tag_remap,
4408 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
4409 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
4410 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004411 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004412 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004413 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004414 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
4415 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004416 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004417 .port_get_cmode = mv88e6352_port_get_cmode,
Marek Behún7a3007d2019-08-26 23:31:55 +02004418 .port_set_cmode = mv88e6341_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004419 .port_setup_message_port = mv88e6xxx_setup_message_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004420 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004421 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004422 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4423 .stats_get_strings = mv88e6320_stats_get_strings,
4424 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004425 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4426 .set_egress_port = mv88e6390_g1_set_egress_port,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004427 .watchdog_ops = &mv88e6390_watchdog_ops,
4428 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004429 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004430 .reset = mv88e6352_g1_reset,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004431 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004432 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004433 .serdes_power = mv88e6390_serdes_power,
4434 .serdes_get_lane = mv88e6341_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004435 /* Check status register pause & lpa register */
4436 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4437 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4438 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4439 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004440 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004441 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004442 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004443 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004444 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004445 .ptp_ops = &mv88e6352_ptp_ops,
Marek Behúne3af71a2019-02-25 12:39:55 +01004446 .phylink_validate = mv88e6341_phylink_validate,
Vivien Didelot16e329a2017-03-28 13:50:33 -04004447};
4448
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004449static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004450 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004451 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4452 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004453 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004454 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004455 .phy_read = mv88e6xxx_g2_smi_phy_read,
4456 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004457 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01004458 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004459 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01004460 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004461 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004462 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004463 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004464 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004465 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004466 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004467 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004468 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004469 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004470 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004471 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004472 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004473 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004474 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004475 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4476 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004477 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004478 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4479 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004480 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004481 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004482 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004483 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004484 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4485 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004486 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004487 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Russell King6c422e32018-08-09 15:38:39 +02004488 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004489};
4490
4491static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004492 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004493 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4494 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004495 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004496 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004497 .phy_read = mv88e6xxx_g2_smi_phy_read,
4498 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004499 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01004500 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01004501 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01004502 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004503 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004504 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004505 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004506 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004507 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004508 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004509 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004510 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004511 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004512 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004513 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004514 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004515 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004516 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004517 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4518 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004519 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004520 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4521 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004522 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004523 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004524 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004525 .reset = mv88e6352_g1_reset,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004526 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4527 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004528 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004529 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004530 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004531 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004532 .phylink_validate = mv88e6185_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004533};
4534
4535static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004536 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelot93e18d62018-05-11 17:16:35 -04004537 .ieee_pri_map = mv88e6085_g1_ieee_pri_map,
4538 .ip_pri_map = mv88e6085_g1_ip_pri_map,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004539 .irl_init_all = mv88e6352_g2_irl_init_all,
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004540 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
4541 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04004542 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004543 .phy_read = mv88e6xxx_g2_smi_phy_read,
4544 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01004545 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01004546 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01004547 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01004548 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004549 .port_tag_remap = mv88e6095_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004550 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004551 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004552 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004553 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004554 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004555 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004556 .port_pause_limit = mv88e6097_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004557 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004558 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004559 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004560 .port_get_cmode = mv88e6352_port_get_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004561 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01004562 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunn40cff8f2017-11-10 00:36:41 +01004563 .stats_set_histogram = mv88e6095_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004564 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
4565 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01004566 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004567 .set_cpu_port = mv88e6095_g1_set_cpu_port,
4568 .set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01004569 .watchdog_ops = &mv88e6097_watchdog_ops,
Vivien Didelot51c901a2017-07-17 13:03:41 -04004570 .mgmt_rsvd2cpu = mv88e6352_g2_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004571 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004572 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004573 .rmu_disable = mv88e6352_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004574 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4575 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelotf1394b782017-05-01 14:05:22 -04004576 .vtu_getnext = mv88e6352_g1_vtu_getnext,
Vivien Didelot0ad5daf2017-05-01 14:05:23 -04004577 .vtu_loadpurge = mv88e6352_g1_vtu_loadpurge,
Vivien Didelot9db4a722019-08-31 16:18:31 -04004578 .serdes_get_lane = mv88e6352_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004579 .serdes_pcs_get_state = mv88e6352_serdes_pcs_get_state,
4580 .serdes_pcs_config = mv88e6352_serdes_pcs_config,
4581 .serdes_pcs_an_restart = mv88e6352_serdes_pcs_an_restart,
4582 .serdes_pcs_link_up = mv88e6352_serdes_pcs_link_up,
Andrew Lunn6d917822017-05-26 01:03:21 +02004583 .serdes_power = mv88e6352_serdes_power,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004584 .serdes_irq_mapping = mv88e6352_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004585 .serdes_irq_enable = mv88e6352_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004586 .serdes_irq_status = mv88e6352_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004587 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004588 .avb_ops = &mv88e6352_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004589 .ptp_ops = &mv88e6352_ptp_ops,
Andrew Lunncda9f4a2018-03-01 02:02:31 +01004590 .serdes_get_sset_count = mv88e6352_serdes_get_sset_count,
4591 .serdes_get_strings = mv88e6352_serdes_get_strings,
4592 .serdes_get_stats = mv88e6352_serdes_get_stats,
Andrew Lunnd3f88a22020-02-16 18:54:14 +01004593 .serdes_get_regs_len = mv88e6352_serdes_get_regs_len,
4594 .serdes_get_regs = mv88e6352_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004595 .phylink_validate = mv88e6352_phylink_validate,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004596};
4597
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004598static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004599 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004600 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004601 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004602 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4603 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004604 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4605 .phy_read = mv88e6xxx_g2_smi_phy_read,
4606 .phy_write = mv88e6xxx_g2_smi_phy_write,
4607 .port_set_link = mv88e6xxx_port_set_link,
4608 .port_set_duplex = mv88e6xxx_port_set_duplex,
4609 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4610 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004611 .port_max_speed_mode = mv88e6390_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004612 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004613 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004614 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004615 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004616 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004617 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004618 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004619 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004620 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004621 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004622 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004623 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnfdc71ee2018-11-11 00:32:15 +01004624 .port_set_cmode = mv88e6390_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004625 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004626 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004627 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004628 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4629 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004630 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004631 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4632 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004633 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004634 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004635 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004636 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004637 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004638 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4639 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004640 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4641 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Andrew Lunn6335e9f2017-05-26 01:03:23 +02004642 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004643 .serdes_get_lane = mv88e6390_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004644 /* Check status register pause & lpa register */
4645 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4646 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4647 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4648 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004649 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004650 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004651 .serdes_irq_status = mv88e6390_serdes_irq_status,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004652 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004653 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004654 .ptp_ops = &mv88e6352_ptp_ops,
Nikita Yushchenko0df95282019-12-25 08:22:38 +03004655 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4656 .serdes_get_strings = mv88e6390_serdes_get_strings,
4657 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004658 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4659 .serdes_get_regs = mv88e6390_serdes_get_regs,
Russell King6c422e32018-08-09 15:38:39 +02004660 .phylink_validate = mv88e6390_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004661};
4662
4663static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01004664 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunnea890982019-01-09 00:24:03 +01004665 .setup_errata = mv88e6390_setup_errata,
Vivien Didelotcd8da8b2017-06-19 10:55:36 -04004666 .irl_init_all = mv88e6390_g2_irl_init_all,
Vivien Didelot98fc3c62017-01-12 18:07:16 -05004667 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
4668 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004669 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
4670 .phy_read = mv88e6xxx_g2_smi_phy_read,
4671 .phy_write = mv88e6xxx_g2_smi_phy_write,
4672 .port_set_link = mv88e6xxx_port_set_link,
4673 .port_set_duplex = mv88e6xxx_port_set_duplex,
4674 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
4675 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunn7cbbee02019-03-08 01:21:27 +01004676 .port_max_speed_mode = mv88e6390x_port_max_speed_mode,
Andrew Lunnef0a7312016-12-03 04:35:16 +01004677 .port_tag_remap = mv88e6390_port_tag_remap,
Vivien Didelotf3a2cd32019-09-07 16:00:48 -04004678 .port_set_policy = mv88e6352_port_set_policy,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004679 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05004680 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01004681 .port_set_ether_type = mv88e6351_port_set_ether_type,
Vivien Didelotcd782652017-06-08 18:34:13 -04004682 .port_set_jumbo_size = mv88e6165_port_set_jumbo_size,
Andrew Lunnef70b112016-12-03 04:45:18 +01004683 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Vivien Didelot08984322017-06-08 18:34:12 -04004684 .port_pause_limit = mv88e6390_port_pause_limit,
Vivien Didelotc8c94892017-03-11 16:13:01 -05004685 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05004686 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Russell King6c422e32018-08-09 15:38:39 +02004687 .port_link_state = mv88e6352_port_link_state,
Andrew Lunn2d2e1dd2018-08-09 15:38:45 +02004688 .port_get_cmode = mv88e6352_port_get_cmode,
Andrew Lunnb3dce4d2018-11-11 00:32:14 +01004689 .port_set_cmode = mv88e6390x_port_set_cmode,
Hubert Feurstein121b8fe2019-07-31 10:23:49 +02004690 .port_setup_message_port = mv88e6xxx_setup_message_port,
Andrew Lunn79523472016-11-21 23:27:00 +01004691 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01004692 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01004693 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
4694 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01004695 .stats_get_stats = mv88e6390_stats_get_stats,
Vivien Didelotfa8d1172017-06-08 18:34:11 -04004696 .set_cpu_port = mv88e6390_g1_set_cpu_port,
4697 .set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01004698 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01004699 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot9e907d72017-07-17 13:03:43 -04004700 .pot_clear = mv88e6xxx_g2_pot_clear,
Vivien Didelot17e708b2016-12-05 17:30:27 -05004701 .reset = mv88e6352_g1_reset,
Vivien Didelot9e5baf92018-05-09 11:38:51 -04004702 .rmu_disable = mv88e6390_g1_rmu_disable,
Andrew Lunn23e8b472019-10-25 01:03:52 +02004703 .atu_get_hash = mv88e6165_g1_atu_get_hash,
4704 .atu_set_hash = mv88e6165_g1_atu_set_hash,
Vivien Didelot931d1822017-05-01 14:05:27 -04004705 .vtu_getnext = mv88e6390_g1_vtu_getnext,
4706 .vtu_loadpurge = mv88e6390_g1_vtu_loadpurge,
Marek Behúnd3cf7d82019-08-26 23:31:53 +02004707 .serdes_power = mv88e6390_serdes_power,
Marek Behún17deaf52019-08-26 23:31:52 +02004708 .serdes_get_lane = mv88e6390x_serdes_get_lane,
Russell Kinga5a68582020-03-14 10:15:43 +00004709 .serdes_pcs_get_state = mv88e6390_serdes_pcs_get_state,
4710 .serdes_pcs_config = mv88e6390_serdes_pcs_config,
4711 .serdes_pcs_an_restart = mv88e6390_serdes_pcs_an_restart,
4712 .serdes_pcs_link_up = mv88e6390_serdes_pcs_link_up,
Vivien Didelot4241ef52019-08-31 16:18:29 -04004713 .serdes_irq_mapping = mv88e6390_serdes_irq_mapping,
Vivien Didelot61a46b42019-08-31 16:18:34 -04004714 .serdes_irq_enable = mv88e6390_serdes_irq_enable,
Vivien Didelot907b9b92019-08-31 16:18:35 -04004715 .serdes_irq_status = mv88e6390_serdes_irq_status,
Andrew Lunn4262c382020-01-18 19:40:56 +01004716 .serdes_get_sset_count = mv88e6390_serdes_get_sset_count,
4717 .serdes_get_strings = mv88e6390_serdes_get_strings,
4718 .serdes_get_stats = mv88e6390_serdes_get_stats,
Andrew Lunnbf3504c2020-02-16 18:54:15 +01004719 .serdes_get_regs_len = mv88e6390_serdes_get_regs_len,
4720 .serdes_get_regs = mv88e6390_serdes_get_regs,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004721 .gpio_ops = &mv88e6352_gpio_ops,
Brandon Streiff0d632c32018-02-14 01:07:44 +01004722 .avb_ops = &mv88e6390_avb_ops,
Andrew Lunn6d2ac8e2018-07-18 22:38:20 +02004723 .ptp_ops = &mv88e6352_ptp_ops,
Russell King6c422e32018-08-09 15:38:39 +02004724 .phylink_validate = mv88e6390x_phylink_validate,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004725};
4726
Vivien Didelotf81ec902016-05-09 13:22:58 -04004727static const struct mv88e6xxx_info mv88e6xxx_table[] = {
4728 [MV88E6085] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004729 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6085,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004730 .family = MV88E6XXX_FAMILY_6097,
4731 .name = "Marvell 88E6085",
4732 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004733 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004734 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01004735 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004736 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004737 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004738 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004739 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004740 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004741 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004742 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004743 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004744 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004745 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004746 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004747 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004748 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004749 },
4750
4751 [MV88E6095] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004752 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6095,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004753 .family = MV88E6XXX_FAMILY_6095,
4754 .name = "Marvell 88E6095/88E6095F",
4755 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004756 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004757 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004758 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004759 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004760 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004761 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004762 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004763 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004764 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004765 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05004766 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004767 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004768 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004769 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004770 },
4771
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004772 [MV88E6097] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004773 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6097,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004774 .family = MV88E6XXX_FAMILY_6097,
4775 .name = "Marvell 88E6097/88E6097F",
4776 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004777 .num_macs = 8192,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004778 .num_ports = 11,
Andrew Lunnbc393152018-03-17 20:32:04 +01004779 .num_internal_phys = 8,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004780 .max_vid = 4095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004781 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004782 .phy_base_addr = 0x0,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004783 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004784 .global2_addr = 0x1c,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004785 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01004786 .g1_irqs = 8,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004787 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004788 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004789 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004790 .multi_chip = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01004791 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01004792 .ops = &mv88e6097_ops,
4793 },
4794
Vivien Didelotf81ec902016-05-09 13:22:58 -04004795 [MV88E6123] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004796 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6123,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004797 .family = MV88E6XXX_FAMILY_6165,
4798 .name = "Marvell 88E6123",
4799 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004800 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004801 .num_ports = 3,
Andrew Lunnbc393152018-03-17 20:32:04 +01004802 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004803 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004804 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004805 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004806 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004807 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004808 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004809 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004810 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004811 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004812 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004813 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004814 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004815 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004816 },
4817
4818 [MV88E6131] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004819 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6131,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004820 .family = MV88E6XXX_FAMILY_6185,
4821 .name = "Marvell 88E6131",
4822 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004823 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004824 .num_ports = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01004825 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004826 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004827 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004828 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004829 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004830 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004831 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004832 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004833 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004834 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004835 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004836 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004837 },
4838
Vivien Didelot990e27b2017-03-28 13:50:32 -04004839 [MV88E6141] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004840 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6141,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004841 .family = MV88E6XXX_FAMILY_6341,
Uwe Kleine-König79a68b22018-03-20 10:44:40 +01004842 .name = "Marvell 88E6141",
Vivien Didelot990e27b2017-03-28 13:50:32 -04004843 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004844 .num_macs = 2048,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004845 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004846 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004847 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004848 .max_vid = 4095,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004849 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004850 .phy_base_addr = 0x10,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004851 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004852 .global2_addr = 0x1c,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004853 .age_time_coeff = 3750,
4854 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01004855 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004856 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04004857 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004858 .multi_chip = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004859 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelot990e27b2017-03-28 13:50:32 -04004860 .ops = &mv88e6141_ops,
4861 },
4862
Vivien Didelotf81ec902016-05-09 13:22:58 -04004863 [MV88E6161] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004864 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6161,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004865 .family = MV88E6XXX_FAMILY_6165,
4866 .name = "Marvell 88E6161",
4867 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004868 .num_macs = 1024,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004869 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004870 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004871 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004872 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004873 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004874 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004875 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004876 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004877 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004878 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004879 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004880 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004881 .multi_chip = true,
Andrew Lunn5ebe31d2017-06-07 15:06:19 +02004882 .tag_protocol = DSA_TAG_PROTO_EDSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004883 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004884 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004885 },
4886
4887 [MV88E6165] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004888 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6165,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004889 .family = MV88E6XXX_FAMILY_6165,
4890 .name = "Marvell 88E6165",
4891 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004892 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004893 .num_ports = 6,
Andrew Lunnbc393152018-03-17 20:32:04 +01004894 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004895 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004896 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004897 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004898 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004899 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004900 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004901 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004902 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004903 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004904 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004905 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004906 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunndfa54342018-07-18 22:38:22 +02004907 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004908 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004909 },
4910
4911 [MV88E6171] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004912 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6171,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004913 .family = MV88E6XXX_FAMILY_6351,
4914 .name = "Marvell 88E6171",
4915 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004916 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004917 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004918 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004919 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004920 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004921 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004922 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004923 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004924 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004925 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004926 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004927 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004928 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004929 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004930 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004931 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004932 },
4933
4934 [MV88E6172] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004935 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6172,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004936 .family = MV88E6XXX_FAMILY_6352,
4937 .name = "Marvell 88E6172",
4938 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004939 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004940 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004941 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004942 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004943 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004944 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004945 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004946 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004947 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004948 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004949 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004950 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004951 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004952 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004953 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004954 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004955 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004956 },
4957
4958 [MV88E6175] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004959 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6175,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004960 .family = MV88E6XXX_FAMILY_6351,
4961 .name = "Marvell 88E6175",
4962 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004963 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004964 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004965 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004966 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004967 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004968 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004969 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004970 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004971 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004972 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004973 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004974 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004975 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04004976 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004977 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004978 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004979 },
4980
4981 [MV88E6176] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04004982 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6176,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004983 .family = MV88E6XXX_FAMILY_6352,
4984 .name = "Marvell 88E6176",
4985 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01004986 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004987 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01004988 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01004989 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04004990 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004991 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02004992 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04004993 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04004994 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004995 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004996 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04004997 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05004998 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004999 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005000 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005001 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005002 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005003 },
5004
5005 [MV88E6185] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005006 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6185,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005007 .family = MV88E6XXX_FAMILY_6185,
5008 .name = "Marvell 88E6185",
5009 .num_databases = 256,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005010 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005011 .num_ports = 10,
Andrew Lunnbc393152018-03-17 20:32:04 +01005012 .num_internal_phys = 0,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005013 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005014 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005015 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005016 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005017 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005018 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005019 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05005020 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005021 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005022 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005023 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005024 },
5025
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005026 [MV88E6190] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005027 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005028 .family = MV88E6XXX_FAMILY_6390,
5029 .name = "Marvell 88E6190",
5030 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005031 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005032 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005033 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005034 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005035 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005036 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005037 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005038 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005039 .global2_addr = 0x1c,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005040 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005041 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005042 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005043 .g2_irqs = 14,
Vivien Didelotf3645652017-03-30 17:37:07 -04005044 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005045 .multi_chip = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05005046 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005047 .ops = &mv88e6190_ops,
5048 },
5049
5050 [MV88E6190X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005051 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6190X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005052 .family = MV88E6XXX_FAMILY_6390,
5053 .name = "Marvell 88E6190X",
5054 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005055 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005056 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005057 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005058 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005059 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005060 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005061 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005062 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005063 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005064 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005065 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005066 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005067 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005068 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005069 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005070 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005071 .ops = &mv88e6190x_ops,
5072 },
5073
5074 [MV88E6191] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005075 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005076 .family = MV88E6XXX_FAMILY_6390,
5077 .name = "Marvell 88E6191",
5078 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005079 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005080 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005081 .num_internal_phys = 9,
Vivien Didelot931d1822017-05-01 14:05:27 -04005082 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005083 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005084 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005085 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005086 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005087 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005088 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005089 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005090 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005091 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005092 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005093 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005094 .ptp_support = true,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04005095 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005096 },
5097
Hubert Feurstein49022642019-07-31 10:23:46 +02005098 [MV88E6220] = {
5099 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6220,
5100 .family = MV88E6XXX_FAMILY_6250,
5101 .name = "Marvell 88E6220",
5102 .num_databases = 64,
5103
5104 /* Ports 2-4 are not routed to pins
5105 * => usable ports 0, 1, 5, 6
5106 */
5107 .num_ports = 7,
5108 .num_internal_phys = 2,
Hubert Feursteinc8574862019-07-31 10:23:48 +02005109 .invalid_port_mask = BIT(2) | BIT(3) | BIT(4),
Hubert Feurstein49022642019-07-31 10:23:46 +02005110 .max_vid = 4095,
5111 .port_base_addr = 0x08,
5112 .phy_base_addr = 0x00,
5113 .global1_addr = 0x0f,
5114 .global2_addr = 0x07,
5115 .age_time_coeff = 15000,
5116 .g1_irqs = 9,
5117 .g2_irqs = 10,
5118 .atu_move_port_mask = 0xf,
5119 .dual_chip = true,
5120 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02005121 .ptp_support = true,
Hubert Feurstein49022642019-07-31 10:23:46 +02005122 .ops = &mv88e6250_ops,
5123 },
5124
Vivien Didelotf81ec902016-05-09 13:22:58 -04005125 [MV88E6240] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005126 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6240,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005127 .family = MV88E6XXX_FAMILY_6352,
5128 .name = "Marvell 88E6240",
5129 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005130 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005131 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005132 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005133 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005134 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005135 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005136 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005137 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005138 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005139 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005140 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005141 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005142 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005143 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005144 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005145 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005146 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005147 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005148 },
5149
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005150 [MV88E6250] = {
5151 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6250,
5152 .family = MV88E6XXX_FAMILY_6250,
5153 .name = "Marvell 88E6250",
5154 .num_databases = 64,
5155 .num_ports = 7,
5156 .num_internal_phys = 5,
5157 .max_vid = 4095,
5158 .port_base_addr = 0x08,
5159 .phy_base_addr = 0x00,
5160 .global1_addr = 0x0f,
5161 .global2_addr = 0x07,
5162 .age_time_coeff = 15000,
5163 .g1_irqs = 9,
5164 .g2_irqs = 10,
5165 .atu_move_port_mask = 0xf,
5166 .dual_chip = true,
5167 .tag_protocol = DSA_TAG_PROTO_DSA,
Hubert Feurstein71509612019-07-31 10:23:51 +02005168 .ptp_support = true,
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005169 .ops = &mv88e6250_ops,
5170 },
5171
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005172 [MV88E6290] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005173 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6290,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005174 .family = MV88E6XXX_FAMILY_6390,
5175 .name = "Marvell 88E6290",
5176 .num_databases = 4096,
5177 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005178 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005179 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005180 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005181 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005182 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005183 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005184 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005185 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005186 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005187 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005188 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005189 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005190 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005191 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005192 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005193 .ops = &mv88e6290_ops,
5194 },
5195
Vivien Didelotf81ec902016-05-09 13:22:58 -04005196 [MV88E6320] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005197 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6320,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005198 .family = MV88E6XXX_FAMILY_6320,
5199 .name = "Marvell 88E6320",
5200 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005201 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005202 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005203 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005204 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005205 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005206 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005207 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005208 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005209 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005210 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005211 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005212 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005213 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005214 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005215 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005216 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005217 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005218 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005219 },
5220
5221 [MV88E6321] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005222 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6321,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005223 .family = MV88E6XXX_FAMILY_6320,
5224 .name = "Marvell 88E6321",
5225 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005226 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005227 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005228 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005229 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005230 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005231 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005232 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005233 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005234 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005235 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005236 .g1_irqs = 8,
Andrew Lunnbc393152018-03-17 20:32:04 +01005237 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005238 .atu_move_port_mask = 0xf,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005239 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005240 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005241 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005242 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005243 },
5244
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005245 [MV88E6341] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005246 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6341,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005247 .family = MV88E6XXX_FAMILY_6341,
5248 .name = "Marvell 88E6341",
5249 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005250 .num_macs = 2048,
Andrew Lunnbc393152018-03-17 20:32:04 +01005251 .num_internal_phys = 5,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005252 .num_ports = 6,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005253 .num_gpio = 11,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005254 .max_vid = 4095,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005255 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005256 .phy_base_addr = 0x10,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005257 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005258 .global2_addr = 0x1c,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005259 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05005260 .atu_move_port_mask = 0x1f,
Andrew Lunnadfccf12018-03-17 20:32:03 +01005261 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005262 .g2_irqs = 10,
Vivien Didelotf3645652017-03-30 17:37:07 -04005263 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005264 .multi_chip = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005265 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005266 .ptp_support = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01005267 .ops = &mv88e6341_ops,
5268 },
5269
Vivien Didelotf81ec902016-05-09 13:22:58 -04005270 [MV88E6350] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005271 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6350,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005272 .family = MV88E6XXX_FAMILY_6351,
5273 .name = "Marvell 88E6350",
5274 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005275 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005276 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005277 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005278 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005279 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005280 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005281 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005282 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005283 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005284 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005285 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005286 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005287 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005288 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005289 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005290 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005291 },
5292
5293 [MV88E6351] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005294 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6351,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005295 .family = MV88E6XXX_FAMILY_6351,
5296 .name = "Marvell 88E6351",
5297 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005298 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005299 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005300 .num_internal_phys = 5,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005301 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005302 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005303 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005304 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005305 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005306 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005307 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005308 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005309 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005310 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005311 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005312 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005313 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005314 },
5315
5316 [MV88E6352] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005317 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6352,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005318 .family = MV88E6XXX_FAMILY_6352,
5319 .name = "Marvell 88E6352",
5320 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005321 .num_macs = 8192,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005322 .num_ports = 7,
Andrew Lunnbc393152018-03-17 20:32:04 +01005323 .num_internal_phys = 5,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005324 .num_gpio = 15,
Vivien Didelot3cf3c842017-05-01 14:05:10 -04005325 .max_vid = 4095,
Vivien Didelot9dddd472016-06-20 13:14:10 -04005326 .port_base_addr = 0x10,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005327 .phy_base_addr = 0x0,
Vivien Didelota935c052016-09-29 12:21:53 -04005328 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005329 .global2_addr = 0x1c,
Vivien Didelotacddbd22016-07-18 20:45:39 -04005330 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02005331 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005332 .g2_irqs = 10,
Vivien Didelote606ca32017-03-11 16:12:55 -05005333 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04005334 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005335 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005336 .tag_protocol = DSA_TAG_PROTO_EDSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005337 .ptp_support = true,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04005338 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005339 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005340 [MV88E6390] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005341 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005342 .family = MV88E6XXX_FAMILY_6390,
5343 .name = "Marvell 88E6390",
5344 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005345 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005346 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005347 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005348 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005349 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005350 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005351 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005352 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005353 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005354 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005355 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005356 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005357 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005358 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005359 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005360 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005361 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005362 .ops = &mv88e6390_ops,
5363 },
5364 [MV88E6390X] = {
Vivien Didelot107fcc12017-06-12 12:37:36 -04005365 .prod_num = MV88E6XXX_PORT_SWITCH_ID_PROD_6390X,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005366 .family = MV88E6XXX_FAMILY_6390,
5367 .name = "Marvell 88E6390X",
5368 .num_databases = 4096,
Andrew Lunnd9ea5622019-11-05 01:12:58 +01005369 .num_macs = 16384,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005370 .num_ports = 11, /* 10 + Z80 */
Heiner Kallweit95150f22019-03-02 10:06:05 +01005371 .num_internal_phys = 9,
Brandon Streiffa73ccd62018-02-14 01:07:46 +01005372 .num_gpio = 16,
Vivien Didelot931d1822017-05-01 14:05:27 -04005373 .max_vid = 8191,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005374 .port_base_addr = 0x0,
Andrew Lunn9255bac2018-05-05 20:58:22 +02005375 .phy_base_addr = 0x0,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005376 .global1_addr = 0x1b,
Vivien Didelot9069c132017-07-17 13:03:44 -04005377 .global2_addr = 0x1c,
Andrew Lunnb91e0552017-02-02 00:46:15 +01005378 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005379 .g1_irqs = 9,
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -04005380 .g2_irqs = 14,
Vivien Didelote606ca32017-03-11 16:12:55 -05005381 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04005382 .pvt = true,
Vivien Didelotb3e05aa2017-07-17 13:03:46 -04005383 .multi_chip = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01005384 .tag_protocol = DSA_TAG_PROTO_DSA,
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005385 .ptp_support = true,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005386 .ops = &mv88e6390x_ops,
5387 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04005388};
5389
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005390static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04005391{
Vivien Didelota439c062016-04-17 13:23:58 -04005392 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04005393
Vivien Didelot5f7c0362016-06-20 13:14:04 -04005394 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
5395 if (mv88e6xxx_table[i].prod_num == prod_num)
5396 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04005397
Vivien Didelotb9b37712015-10-30 19:39:48 -04005398 return NULL;
5399}
5400
Vivien Didelotfad09c72016-06-21 12:28:20 -04005401static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005402{
5403 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005404 unsigned int prod_num, rev;
5405 u16 id;
5406 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005407
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005408 mv88e6xxx_reg_lock(chip);
Vivien Didelot107fcc12017-06-12 12:37:36 -04005409 err = mv88e6xxx_port_read(chip, 0, MV88E6XXX_PORT_SWITCH_ID, &id);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005410 mv88e6xxx_reg_unlock(chip);
Vivien Didelot8f6345b2016-07-20 18:18:36 -04005411 if (err)
5412 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005413
Vivien Didelot107fcc12017-06-12 12:37:36 -04005414 prod_num = id & MV88E6XXX_PORT_SWITCH_ID_PROD_MASK;
5415 rev = id & MV88E6XXX_PORT_SWITCH_ID_REV_MASK;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005416
5417 info = mv88e6xxx_lookup_info(prod_num);
5418 if (!info)
5419 return -ENODEV;
5420
Vivien Didelotcaac8542016-06-20 13:14:09 -04005421 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04005422 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005423
Vivien Didelotca070c12016-09-02 14:45:34 -04005424 err = mv88e6xxx_g2_require(chip);
5425 if (err)
5426 return err;
5427
Vivien Didelotfad09c72016-06-21 12:28:20 -04005428 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
5429 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005430
5431 return 0;
5432}
5433
Vivien Didelotfad09c72016-06-21 12:28:20 -04005434static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04005435{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005436 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005437
Vivien Didelotfad09c72016-06-21 12:28:20 -04005438 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
5439 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04005440 return NULL;
5441
Vivien Didelotfad09c72016-06-21 12:28:20 -04005442 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04005443
Vivien Didelotfad09c72016-06-21 12:28:20 -04005444 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005445 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelotda7dc872019-09-07 16:00:49 -04005446 idr_init(&chip->policies);
Vivien Didelot469d7292016-06-20 13:14:06 -04005447
Vivien Didelotfad09c72016-06-21 12:28:20 -04005448 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04005449}
5450
Florian Fainelli5ed4e3e2017-11-10 15:22:52 -08005451static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -08005452 int port,
5453 enum dsa_tag_protocol m)
Andrew Lunn7b314362016-08-22 16:01:01 +02005454{
Vivien Didelot04bed142016-08-31 18:06:13 -04005455 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02005456
Andrew Lunn443d5a12016-12-03 04:35:18 +01005457 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02005458}
5459
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005460static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05005461 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005462{
5463 /* We don't need any dynamic resource from the kernel (yet),
5464 * so skip the prepare phase.
5465 */
5466
5467 return 0;
5468}
5469
5470static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
Vivien Didelot3709aad2017-11-30 11:23:58 -05005471 const struct switchdev_obj_port_mdb *mdb)
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005472{
Vivien Didelot04bed142016-08-31 18:06:13 -04005473 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005474
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005475 mv88e6xxx_reg_lock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005476 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
Vivien Didelot27c0e602017-06-15 12:14:01 -04005477 MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC))
Vivien Didelot774439e52017-06-08 18:34:08 -04005478 dev_err(ds->dev, "p%d: failed to load multicast MAC address\n",
5479 port);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005480 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005481}
5482
5483static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
5484 const struct switchdev_obj_port_mdb *mdb)
5485{
Vivien Didelot04bed142016-08-31 18:06:13 -04005486 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005487 int err;
5488
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005489 mv88e6xxx_reg_lock(chip);
Vivien Didelotd8291a92019-09-07 16:00:47 -04005490 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid, 0);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005491 mv88e6xxx_reg_unlock(chip);
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005492
5493 return err;
5494}
5495
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005496static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
5497 struct dsa_mall_mirror_tc_entry *mirror,
5498 bool ingress)
5499{
5500 enum mv88e6xxx_egress_direction direction = ingress ?
5501 MV88E6XXX_EGRESS_DIR_INGRESS :
5502 MV88E6XXX_EGRESS_DIR_EGRESS;
5503 struct mv88e6xxx_chip *chip = ds->priv;
5504 bool other_mirrors = false;
5505 int i;
5506 int err;
5507
5508 if (!chip->info->ops->set_egress_port)
5509 return -EOPNOTSUPP;
5510
5511 mutex_lock(&chip->reg_lock);
5512 if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
5513 mirror->to_local_port) {
5514 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5515 other_mirrors |= ingress ?
5516 chip->ports[i].mirror_ingress :
5517 chip->ports[i].mirror_egress;
5518
5519 /* Can't change egress port when other mirror is active */
5520 if (other_mirrors) {
5521 err = -EBUSY;
5522 goto out;
5523 }
5524
5525 err = chip->info->ops->set_egress_port(chip,
5526 direction,
5527 mirror->to_local_port);
5528 if (err)
5529 goto out;
5530 }
5531
5532 err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
5533out:
5534 mutex_unlock(&chip->reg_lock);
5535
5536 return err;
5537}
5538
5539static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
5540 struct dsa_mall_mirror_tc_entry *mirror)
5541{
5542 enum mv88e6xxx_egress_direction direction = mirror->ingress ?
5543 MV88E6XXX_EGRESS_DIR_INGRESS :
5544 MV88E6XXX_EGRESS_DIR_EGRESS;
5545 struct mv88e6xxx_chip *chip = ds->priv;
5546 bool other_mirrors = false;
5547 int i;
5548
5549 mutex_lock(&chip->reg_lock);
5550 if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
5551 dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
5552
5553 for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
5554 other_mirrors |= mirror->ingress ?
5555 chip->ports[i].mirror_ingress :
5556 chip->ports[i].mirror_egress;
5557
5558 /* Reset egress port when no other mirror is active */
5559 if (!other_mirrors) {
5560 if (chip->info->ops->set_egress_port(chip,
5561 direction,
5562 dsa_upstream_port(ds,
Colin Ian King4e4637b2019-11-12 13:05:23 +00005563 port)))
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005564 dev_err(ds->dev, "failed to set egress port\n");
5565 }
5566
5567 mutex_unlock(&chip->reg_lock);
5568}
5569
Russell King4f859012019-02-20 15:35:05 -08005570static int mv88e6xxx_port_egress_floods(struct dsa_switch *ds, int port,
5571 bool unicast, bool multicast)
5572{
5573 struct mv88e6xxx_chip *chip = ds->priv;
5574 int err = -EOPNOTSUPP;
5575
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005576 mv88e6xxx_reg_lock(chip);
Russell King4f859012019-02-20 15:35:05 -08005577 if (chip->info->ops->port_set_egress_floods)
5578 err = chip->info->ops->port_set_egress_floods(chip, port,
5579 unicast,
5580 multicast);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005581 mv88e6xxx_reg_unlock(chip);
Russell King4f859012019-02-20 15:35:05 -08005582
5583 return err;
5584}
5585
Florian Fainellia82f67a2017-01-08 14:52:08 -08005586static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunn7b314362016-08-22 16:01:01 +02005587 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005588 .setup = mv88e6xxx_setup,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005589 .teardown = mv88e6xxx_teardown,
Russell Kingc9a23562018-05-10 13:17:35 -07005590 .phylink_validate = mv88e6xxx_validate,
Russell Kinga5a68582020-03-14 10:15:43 +00005591 .phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
Russell Kingc9a23562018-05-10 13:17:35 -07005592 .phylink_mac_config = mv88e6xxx_mac_config,
Russell Kinga5a68582020-03-14 10:15:43 +00005593 .phylink_mac_an_restart = mv88e6xxx_serdes_pcs_an_restart,
Russell Kingc9a23562018-05-10 13:17:35 -07005594 .phylink_mac_link_down = mv88e6xxx_mac_link_down,
5595 .phylink_mac_link_up = mv88e6xxx_mac_link_up,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005596 .get_strings = mv88e6xxx_get_strings,
5597 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
5598 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunn04aca992017-05-26 01:03:24 +02005599 .port_enable = mv88e6xxx_port_enable,
5600 .port_disable = mv88e6xxx_port_disable,
Vivien Didelot08f50062017-08-01 16:32:41 -04005601 .get_mac_eee = mv88e6xxx_get_mac_eee,
5602 .set_mac_eee = mv88e6xxx_set_mac_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005603 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005604 .get_eeprom = mv88e6xxx_get_eeprom,
5605 .set_eeprom = mv88e6xxx_set_eeprom,
5606 .get_regs_len = mv88e6xxx_get_regs_len,
5607 .get_regs = mv88e6xxx_get_regs,
Vivien Didelotda7dc872019-09-07 16:00:49 -04005608 .get_rxnfc = mv88e6xxx_get_rxnfc,
5609 .set_rxnfc = mv88e6xxx_set_rxnfc,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04005610 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005611 .port_bridge_join = mv88e6xxx_port_bridge_join,
5612 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
Russell King4f859012019-02-20 15:35:05 -08005613 .port_egress_floods = mv88e6xxx_port_egress_floods,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005614 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04005615 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005616 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
5617 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
5618 .port_vlan_add = mv88e6xxx_port_vlan_add,
5619 .port_vlan_del = mv88e6xxx_port_vlan_del,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005620 .port_fdb_add = mv88e6xxx_port_fdb_add,
5621 .port_fdb_del = mv88e6xxx_port_fdb_del,
5622 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04005623 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
5624 .port_mdb_add = mv88e6xxx_port_mdb_add,
5625 .port_mdb_del = mv88e6xxx_port_mdb_del,
Iwan R Timmerf0942e02019-11-07 22:11:14 +01005626 .port_mirror_add = mv88e6xxx_port_mirror_add,
5627 .port_mirror_del = mv88e6xxx_port_mirror_del,
Vivien Didelotaec5ac82017-03-30 17:37:15 -04005628 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
5629 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005630 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
5631 .port_hwtstamp_get = mv88e6xxx_port_hwtstamp_get,
5632 .port_txtstamp = mv88e6xxx_port_txtstamp,
5633 .port_rxtstamp = mv88e6xxx_port_rxtstamp,
5634 .get_ts_info = mv88e6xxx_get_ts_info,
Andrew Lunn23e8b472019-10-25 01:03:52 +02005635 .devlink_param_get = mv88e6xxx_devlink_param_get,
5636 .devlink_param_set = mv88e6xxx_devlink_param_set,
Vivien Didelotf81ec902016-05-09 13:22:58 -04005637};
5638
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005639static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005640{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005641 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005642 struct dsa_switch *ds;
5643
Vivien Didelot7e99e342019-10-21 16:51:30 -04005644 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005645 if (!ds)
5646 return -ENOMEM;
5647
Vivien Didelot7e99e342019-10-21 16:51:30 -04005648 ds->dev = dev;
5649 ds->num_ports = mv88e6xxx_num_ports(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005650 ds->priv = chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005651 ds->dev = dev;
Vivien Didelot9d490b42016-08-23 12:38:56 -04005652 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04005653 ds->ageing_time_min = chip->info->age_time_coeff;
5654 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005655
5656 dev_set_drvdata(dev, ds);
5657
Vivien Didelot23c9ee42017-05-26 18:12:51 -04005658 return dsa_register_switch(ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005659}
5660
Vivien Didelotfad09c72016-06-21 12:28:20 -04005661static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005662{
Vivien Didelotfad09c72016-06-21 12:28:20 -04005663 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04005664}
5665
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005666static const void *pdata_device_get_match_data(struct device *dev)
5667{
5668 const struct of_device_id *matches = dev->driver->of_match_table;
5669 const struct dsa_mv88e6xxx_pdata *pdata = dev->platform_data;
5670
5671 for (; matches->name[0] || matches->type[0] || matches->compatible[0];
5672 matches++) {
5673 if (!strcmp(pdata->compatible, matches->compatible))
5674 return matches->data;
5675 }
5676 return NULL;
5677}
5678
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005679/* There is no suspend to RAM support at DSA level yet, the switch configuration
5680 * would be lost after a power cycle so prevent it to be suspended.
5681 */
5682static int __maybe_unused mv88e6xxx_suspend(struct device *dev)
5683{
5684 return -EOPNOTSUPP;
5685}
5686
5687static int __maybe_unused mv88e6xxx_resume(struct device *dev)
5688{
5689 return 0;
5690}
5691
5692static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);
5693
Vivien Didelot57d32312016-06-20 13:13:58 -04005694static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005695{
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005696 struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;
David S. Miller7ddae242018-05-20 19:04:24 -04005697 const struct mv88e6xxx_info *compat_info = NULL;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005698 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005699 struct device_node *np = dev->of_node;
Vivien Didelotfad09c72016-06-21 12:28:20 -04005700 struct mv88e6xxx_chip *chip;
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005701 int port;
Andrew Lunn52638f72016-05-10 23:27:22 +02005702 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005703
Andrew Lunn7bb8c992018-05-31 00:15:42 +02005704 if (!np && !pdata)
5705 return -EINVAL;
5706
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005707 if (np)
5708 compat_info = of_device_get_match_data(dev);
5709
5710 if (pdata) {
5711 compat_info = pdata_device_get_match_data(dev);
5712
5713 if (!pdata->netdev)
5714 return -EINVAL;
5715
5716 for (port = 0; port < DSA_MAX_PORTS; port++) {
5717 if (!(pdata->enabled_ports & (1 << port)))
5718 continue;
5719 if (strcmp(pdata->cd.port_names[port], "cpu"))
5720 continue;
5721 pdata->cd.netdev[port] = &pdata->netdev->dev;
5722 break;
5723 }
5724 }
5725
Vivien Didelotcaac8542016-06-20 13:14:09 -04005726 if (!compat_info)
5727 return -EINVAL;
5728
Vivien Didelotfad09c72016-06-21 12:28:20 -04005729 chip = mv88e6xxx_alloc_chip(dev);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005730 if (!chip) {
5731 err = -ENOMEM;
5732 goto out;
5733 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005734
Vivien Didelotfad09c72016-06-21 12:28:20 -04005735 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04005736
Vivien Didelotfad09c72016-06-21 12:28:20 -04005737 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04005738 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005739 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005740
Andrew Lunnb4308f02016-11-21 23:26:55 +01005741 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005742 if (IS_ERR(chip->reset)) {
5743 err = PTR_ERR(chip->reset);
5744 goto out;
5745 }
Baruch Siach7b75e492019-06-27 21:17:39 +03005746 if (chip->reset)
5747 usleep_range(1000, 2000);
Andrew Lunnb4308f02016-11-21 23:26:55 +01005748
Vivien Didelotfad09c72016-06-21 12:28:20 -04005749 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04005750 if (err)
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005751 goto out;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005752
Vivien Didelote57e5e72016-08-15 17:19:00 -04005753 mv88e6xxx_phy_init(chip);
5754
Andrew Lunn00baabe2018-05-19 22:31:35 +02005755 if (chip->info->ops->get_eeprom) {
5756 if (np)
5757 of_property_read_u32(np, "eeprom-length",
5758 &chip->eeprom_len);
5759 else
5760 chip->eeprom_len = pdata->eeprom_len;
5761 }
Andrew Lunnf8cd8752016-05-10 23:27:25 +02005762
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005763 mv88e6xxx_reg_lock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005764 err = mv88e6xxx_switch_reset(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005765 mv88e6xxx_reg_unlock(chip);
Andrew Lunnb516d452016-06-04 21:17:06 +02005766 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02005767 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02005768
Andrew Lunna27415d2019-05-01 00:10:50 +02005769 if (np) {
5770 chip->irq = of_irq_get(np, 0);
5771 if (chip->irq == -EPROBE_DEFER) {
5772 err = chip->irq;
5773 goto out;
5774 }
Andrew Lunn83c0afa2016-06-04 21:17:07 +02005775 }
5776
Andrew Lunna27415d2019-05-01 00:10:50 +02005777 if (pdata)
5778 chip->irq = pdata->irq;
5779
Andrew Lunn294d7112018-02-22 22:58:32 +01005780 /* Has to be performed before the MDIO bus is created, because
Uwe Kleine-Königa7087672018-03-20 10:44:41 +01005781 * the PHYs will link their interrupts to these interrupt
Andrew Lunn294d7112018-02-22 22:58:32 +01005782 * controllers
5783 */
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005784 mv88e6xxx_reg_lock(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005785 if (chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005786 err = mv88e6xxx_g1_irq_setup(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005787 else
5788 err = mv88e6xxx_irq_poll_setup(chip);
Rasmus Villemoesc9acece2019-06-20 13:50:42 +00005789 mv88e6xxx_reg_unlock(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005790
Andrew Lunn294d7112018-02-22 22:58:32 +01005791 if (err)
5792 goto out;
5793
5794 if (chip->info->g2_irqs > 0) {
5795 err = mv88e6xxx_g2_irq_setup(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005796 if (err)
Andrew Lunn294d7112018-02-22 22:58:32 +01005797 goto out_g1_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005798 }
5799
Andrew Lunn294d7112018-02-22 22:58:32 +01005800 err = mv88e6xxx_g1_atu_prob_irq_setup(chip);
5801 if (err)
5802 goto out_g2_irq;
5803
5804 err = mv88e6xxx_g1_vtu_prob_irq_setup(chip);
5805 if (err)
5806 goto out_g1_atu_prob_irq;
5807
Andrew Lunna3c53be52017-01-24 14:53:50 +01005808 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02005809 if (err)
Andrew Lunn62eb1162018-01-14 02:32:45 +01005810 goto out_g1_vtu_prob_irq;
Andrew Lunndc30c352016-10-16 19:56:49 +02005811
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08005812 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005813 if (err)
5814 goto out_mdio;
5815
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005816 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02005817
5818out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01005819 mv88e6xxx_mdios_unregister(chip);
Andrew Lunn62eb1162018-01-14 02:32:45 +01005820out_g1_vtu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005821 mv88e6xxx_g1_vtu_prob_irq_free(chip);
Andrew Lunn09776442018-01-14 02:32:44 +01005822out_g1_atu_prob_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005823 mv88e6xxx_g1_atu_prob_irq_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005824out_g2_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005825 if (chip->info->g2_irqs > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02005826 mv88e6xxx_g2_irq_free(chip);
5827out_g1_irq:
Andrew Lunn294d7112018-02-22 22:58:32 +01005828 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005829 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn294d7112018-02-22 22:58:32 +01005830 else
5831 mv88e6xxx_irq_poll_free(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005832out:
Andrew Lunn877b7cb2018-05-19 22:31:34 +02005833 if (pdata)
5834 dev_put(pdata->netdev);
5835
Andrew Lunndc30c352016-10-16 19:56:49 +02005836 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005837}
5838
5839static void mv88e6xxx_remove(struct mdio_device *mdiodev)
5840{
5841 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04005842 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005843
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005844 if (chip->info->ptp_support) {
5845 mv88e6xxx_hwtstamp_free(chip);
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005846 mv88e6xxx_ptp_free(chip);
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +01005847 }
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +01005848
Andrew Lunn930188c2016-08-22 16:01:03 +02005849 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04005850 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01005851 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02005852
Andrew Lunn76f38f12018-03-17 20:21:09 +01005853 mv88e6xxx_g1_vtu_prob_irq_free(chip);
5854 mv88e6xxx_g1_atu_prob_irq_free(chip);
5855
5856 if (chip->info->g2_irqs > 0)
5857 mv88e6xxx_g2_irq_free(chip);
5858
Andrew Lunn76f38f12018-03-17 20:21:09 +01005859 if (chip->irq > 0)
Andrew Lunn467126442016-11-20 20:14:15 +01005860 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn76f38f12018-03-17 20:21:09 +01005861 else
5862 mv88e6xxx_irq_poll_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005863}
5864
5865static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04005866 {
5867 .compatible = "marvell,mv88e6085",
5868 .data = &mv88e6xxx_table[MV88E6085],
5869 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01005870 {
5871 .compatible = "marvell,mv88e6190",
5872 .data = &mv88e6xxx_table[MV88E6190],
5873 },
Rasmus Villemoes1f718362019-06-04 07:34:32 +00005874 {
5875 .compatible = "marvell,mv88e6250",
5876 .data = &mv88e6xxx_table[MV88E6250],
5877 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005878 { /* sentinel */ },
5879};
5880
5881MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
5882
5883static struct mdio_driver mv88e6xxx_driver = {
5884 .probe = mv88e6xxx_probe,
5885 .remove = mv88e6xxx_remove,
5886 .mdiodrv.driver = {
5887 .name = "mv88e6085",
5888 .of_match_table = mv88e6xxx_of_match,
Miquel Raynalbcd3d9d2019-02-05 12:07:28 +01005889 .pm = &mv88e6xxx_pm_ops,
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02005890 },
5891};
5892
Andrew Lunn7324d502019-04-27 19:19:10 +02005893mdio_module_driver(mv88e6xxx_driver);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00005894
5895MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
5896MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
5897MODULE_LICENSE("GPL");