blob: 15b79344640052475b1d72d07c73529383b98420 [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -04002 * Marvell 88E6xxx Ethernet switch single-chip definition
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04003 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 * Copyright (c) 2008 Marvell Semiconductor
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -040012#ifndef _MV88E6XXX_CHIP_H
13#define _MV88E6XXX_CHIP_H
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000014
Vivien Didelot194fea72015-08-10 09:09:47 -040015#include <linux/if_vlan.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020016#include <linux/irq.h>
Andrew Lunn52638f72016-05-10 23:27:22 +020017#include <linux/gpio/consumer.h>
Russell King4d56a292017-02-07 15:03:05 -080018#include <linux/phy.h>
Andrew Lunnc6e970a2017-03-28 23:45:06 +020019#include <net/dsa.h>
Vivien Didelot194fea72015-08-10 09:09:47 -040020
Andrew Lunn80c46272015-06-20 18:42:30 +020021#ifndef UINT64_MAX
22#define UINT64_MAX (u64)(~((u64)0))
23#endif
24
Andrew Lunncca8b132015-04-02 04:06:39 +020025#define SMI_CMD 0x00
26#define SMI_CMD_BUSY BIT(15)
27#define SMI_CMD_CLAUSE_22 BIT(12)
28#define SMI_CMD_OP_22_WRITE ((1 << 10) | SMI_CMD_BUSY | SMI_CMD_CLAUSE_22)
29#define SMI_CMD_OP_22_READ ((2 << 10) | SMI_CMD_BUSY | SMI_CMD_CLAUSE_22)
30#define SMI_CMD_OP_45_WRITE_ADDR ((0 << 10) | SMI_CMD_BUSY)
31#define SMI_CMD_OP_45_WRITE_DATA ((1 << 10) | SMI_CMD_BUSY)
32#define SMI_CMD_OP_45_READ_DATA ((2 << 10) | SMI_CMD_BUSY)
33#define SMI_CMD_OP_45_READ_DATA_INC ((3 << 10) | SMI_CMD_BUSY)
34#define SMI_DATA 0x01
Guenter Roeckb2eb0662015-04-02 04:06:30 +020035
Vivien Didelot3285f9e2016-02-26 13:16:03 -050036#define MV88E6XXX_N_FID 4096
37
Vivien Didelot17a15942017-03-30 17:37:09 -040038/* PVT limits for 4-bit port and 5-bit switch */
39#define MV88E6XXX_MAX_PVT_SWITCHES 32
40#define MV88E6XXX_MAX_PVT_PORTS 16
41
Vivien Didelot31bef4e2017-06-08 18:34:09 -040042enum mv88e6xxx_egress_mode {
43 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
44 MV88E6XXX_EGRESS_MODE_UNTAGGED,
45 MV88E6XXX_EGRESS_MODE_TAGGED,
46 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
47};
48
Andrew Lunn56995cb2016-12-03 04:35:19 +010049enum mv88e6xxx_frame_mode {
50 MV88E6XXX_FRAME_MODE_NORMAL,
51 MV88E6XXX_FRAME_MODE_DSA,
52 MV88E6XXX_FRAME_MODE_PROVIDER,
53 MV88E6XXX_FRAME_MODE_ETHERTYPE,
54};
55
Vivien Didelotf81ec902016-05-09 13:22:58 -040056/* List of supported models */
57enum mv88e6xxx_model {
58 MV88E6085,
59 MV88E6095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +010060 MV88E6097,
Vivien Didelotf81ec902016-05-09 13:22:58 -040061 MV88E6123,
62 MV88E6131,
Gregory CLEMENT15587272017-01-30 20:29:35 +010063 MV88E6141,
Vivien Didelotf81ec902016-05-09 13:22:58 -040064 MV88E6161,
65 MV88E6165,
66 MV88E6171,
67 MV88E6172,
68 MV88E6175,
69 MV88E6176,
70 MV88E6185,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +010071 MV88E6190,
72 MV88E6190X,
73 MV88E6191,
Vivien Didelotf81ec902016-05-09 13:22:58 -040074 MV88E6240,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +010075 MV88E6290,
Vivien Didelotf81ec902016-05-09 13:22:58 -040076 MV88E6320,
77 MV88E6321,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +010078 MV88E6341,
Vivien Didelotf81ec902016-05-09 13:22:58 -040079 MV88E6350,
80 MV88E6351,
81 MV88E6352,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +010082 MV88E6390,
83 MV88E6390X,
Vivien Didelotf81ec902016-05-09 13:22:58 -040084};
85
Vivien Didelot22356472016-04-17 13:24:00 -040086enum mv88e6xxx_family {
87 MV88E6XXX_FAMILY_NONE,
88 MV88E6XXX_FAMILY_6065, /* 6031 6035 6061 6065 */
89 MV88E6XXX_FAMILY_6095, /* 6092 6095 */
90 MV88E6XXX_FAMILY_6097, /* 6046 6085 6096 6097 */
91 MV88E6XXX_FAMILY_6165, /* 6123 6161 6165 */
92 MV88E6XXX_FAMILY_6185, /* 6108 6121 6122 6131 6152 6155 6182 6185 */
93 MV88E6XXX_FAMILY_6320, /* 6320 6321 */
Gregory CLEMENTa75961d2017-01-30 20:29:34 +010094 MV88E6XXX_FAMILY_6341, /* 6141 6341 */
Vivien Didelot22356472016-04-17 13:24:00 -040095 MV88E6XXX_FAMILY_6351, /* 6171 6175 6350 6351 */
96 MV88E6XXX_FAMILY_6352, /* 6172 6176 6240 6352 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +010097 MV88E6XXX_FAMILY_6390, /* 6190 6190X 6191 6290 6390 6390X */
Vivien Didelot22356472016-04-17 13:24:00 -040098};
99
Vivien Didelot8c9983a2016-05-09 13:22:39 -0400100enum mv88e6xxx_cap {
Vivien Didelotaadbdb82016-05-09 13:22:44 -0400101 /* Energy Efficient Ethernet.
102 */
103 MV88E6XXX_CAP_EEE,
104
Vivien Didelota0ffff22016-08-15 17:18:58 -0400105 /* Multi-chip Addressing Mode.
106 * Some chips respond to only 2 registers of its own SMI device address
107 * when it is non-zero, and use indirect access to internal registers.
108 */
109 MV88E6XXX_CAP_SMI_CMD, /* (0x00) SMI Command */
110 MV88E6XXX_CAP_SMI_DATA, /* (0x01) SMI Data */
Vivien Didelot8c9983a2016-05-09 13:22:39 -0400111};
Vivien Didelotb5058d72016-05-09 13:22:38 -0400112
Vivien Didelot8c9983a2016-05-09 13:22:39 -0400113/* Bitmask of capabilities */
Andrew Lunnd6b10232016-09-21 01:40:32 +0200114#define MV88E6XXX_FLAG_EEE BIT_ULL(MV88E6XXX_CAP_EEE)
Vivien Didelota0ffff22016-08-15 17:18:58 -0400115
Andrew Lunnd6b10232016-09-21 01:40:32 +0200116#define MV88E6XXX_FLAG_SMI_CMD BIT_ULL(MV88E6XXX_CAP_SMI_CMD)
117#define MV88E6XXX_FLAG_SMI_DATA BIT_ULL(MV88E6XXX_CAP_SMI_DATA)
Vivien Didelota0ffff22016-08-15 17:18:58 -0400118
Vivien Didelota0ffff22016-08-15 17:18:58 -0400119/* Multi-chip Addressing Mode */
120#define MV88E6XXX_FLAGS_MULTI_CHIP \
121 (MV88E6XXX_FLAG_SMI_CMD | \
122 MV88E6XXX_FLAG_SMI_DATA)
123
Vivien Didelot8c9983a2016-05-09 13:22:39 -0400124#define MV88E6XXX_FLAGS_FAMILY_6095 \
Vivien Didelot9069c132017-07-17 13:03:44 -0400125 (MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelot8c9983a2016-05-09 13:22:39 -0400126
127#define MV88E6XXX_FLAGS_FAMILY_6097 \
Vivien Didelot9069c132017-07-17 13:03:44 -0400128 (MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelotb5058d72016-05-09 13:22:38 -0400129
Vivien Didelot6594f612016-05-09 13:22:42 -0400130#define MV88E6XXX_FLAGS_FAMILY_6165 \
Vivien Didelot9069c132017-07-17 13:03:44 -0400131 (MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelotb5058d72016-05-09 13:22:38 -0400132
Vivien Didelot8c9983a2016-05-09 13:22:39 -0400133#define MV88E6XXX_FLAGS_FAMILY_6185 \
Vivien Didelot9069c132017-07-17 13:03:44 -0400134 (MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelotb5058d72016-05-09 13:22:38 -0400135
Vivien Didelot6d5834a2016-05-09 13:22:40 -0400136#define MV88E6XXX_FLAGS_FAMILY_6320 \
Andrew Lunn443d5a12016-12-03 04:35:18 +0100137 (MV88E6XXX_FLAG_EEE | \
Vivien Didelotf3645652017-03-30 17:37:07 -0400138 MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelotb5058d72016-05-09 13:22:38 -0400139
Gregory CLEMENTa75961d2017-01-30 20:29:34 +0100140#define MV88E6XXX_FLAGS_FAMILY_6341 \
141 (MV88E6XXX_FLAG_EEE | \
Andrew Lunnba9b9892017-05-26 01:03:22 +0200142 MV88E6XXX_FLAGS_MULTI_CHIP)
Gregory CLEMENTa75961d2017-01-30 20:29:34 +0100143
Vivien Didelot6d5834a2016-05-09 13:22:40 -0400144#define MV88E6XXX_FLAGS_FAMILY_6351 \
Vivien Didelot9069c132017-07-17 13:03:44 -0400145 (MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelotb5058d72016-05-09 13:22:38 -0400146
Vivien Didelot6d5834a2016-05-09 13:22:40 -0400147#define MV88E6XXX_FLAGS_FAMILY_6352 \
Andrew Lunn443d5a12016-12-03 04:35:18 +0100148 (MV88E6XXX_FLAG_EEE | \
Andrew Lunnba9b9892017-05-26 01:03:22 +0200149 MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400150
Andrew Lunn1a3b39e2016-11-21 23:26:57 +0100151#define MV88E6XXX_FLAGS_FAMILY_6390 \
152 (MV88E6XXX_FLAG_EEE | \
Vivien Didelotf3645652017-03-30 17:37:07 -0400153 MV88E6XXX_FLAGS_MULTI_CHIP)
Andrew Lunn1a3b39e2016-11-21 23:26:57 +0100154
Andrew Lunnc0e4dad2017-02-09 00:00:43 +0100155struct mv88e6xxx_ops;
156
Vivien Didelotf6271e62016-04-17 13:23:59 -0400157struct mv88e6xxx_info {
Vivien Didelot22356472016-04-17 13:24:00 -0400158 enum mv88e6xxx_family family;
Vivien Didelotf6271e62016-04-17 13:23:59 -0400159 u16 prod_num;
160 const char *name;
Vivien Didelotcd5a2c82016-04-17 13:24:02 -0400161 unsigned int num_databases;
Vivien Didelot009a2b92016-04-17 13:24:01 -0400162 unsigned int num_ports;
Vivien Didelot3cf3c842017-05-01 14:05:10 -0400163 unsigned int max_vid;
Vivien Didelot9dddd472016-06-20 13:14:10 -0400164 unsigned int port_base_addr;
Vivien Didelota935c052016-09-29 12:21:53 -0400165 unsigned int global1_addr;
Vivien Didelot9069c132017-07-17 13:03:44 -0400166 unsigned int global2_addr;
Vivien Didelotacddbd22016-07-18 20:45:39 -0400167 unsigned int age_time_coeff;
Andrew Lunndc30c352016-10-16 19:56:49 +0200168 unsigned int g1_irqs;
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -0400169 unsigned int g2_irqs;
Vivien Didelotf3645652017-03-30 17:37:07 -0400170 bool pvt;
Andrew Lunn443d5a12016-12-03 04:35:18 +0100171 enum dsa_tag_protocol tag_protocol;
Andrew Lunnd6b10232016-09-21 01:40:32 +0200172 unsigned long long flags;
Vivien Didelote606ca32017-03-11 16:12:55 -0500173
174 /* Mask for FromPort and ToPort value of PortVec used in ATU Move
175 * operation. 0 means that the ATU Move operation is not supported.
176 */
177 u8 atu_move_port_mask;
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400178 const struct mv88e6xxx_ops *ops;
Vivien Didelotb9b37712015-10-30 19:39:48 -0400179};
180
Vivien Didelotfd231c82015-08-10 09:09:50 -0400181struct mv88e6xxx_atu_entry {
Vivien Didelotfd231c82015-08-10 09:09:50 -0400182 u8 state;
183 bool trunk;
Vivien Didelot01bd96c2017-03-11 16:12:57 -0500184 u16 portvec;
Vivien Didelotfd231c82015-08-10 09:09:50 -0400185 u8 mac[ETH_ALEN];
186};
187
Vivien Didelotb4e47c02016-09-29 12:21:58 -0400188struct mv88e6xxx_vtu_entry {
Vivien Didelotb8fee952015-08-13 12:52:19 -0400189 u16 vid;
190 u16 fid;
Vivien Didelotb8fee952015-08-13 12:52:19 -0400191 u8 sid;
192 bool valid;
Vivien Didelotbd00e052017-05-01 14:05:11 -0400193 u8 member[DSA_MAX_PORTS];
194 u8 state[DSA_MAX_PORTS];
Vivien Didelotb8fee952015-08-13 12:52:19 -0400195};
196
Vivien Didelotc08026a2016-09-29 12:21:59 -0400197struct mv88e6xxx_bus_ops;
Andrew Lunnfcd25162017-02-09 00:03:42 +0100198struct mv88e6xxx_irq_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -0400199
Andrew Lunndc30c352016-10-16 19:56:49 +0200200struct mv88e6xxx_irq {
201 u16 masked;
202 struct irq_chip chip;
203 struct irq_domain *domain;
204 unsigned int nirqs;
205};
206
Vivien Didelotfad09c72016-06-21 12:28:20 -0400207struct mv88e6xxx_chip {
Vivien Didelotf6271e62016-04-17 13:23:59 -0400208 const struct mv88e6xxx_info *info;
209
Andrew Lunn7543a6d2016-04-13 02:40:40 +0200210 /* The dsa_switch this private structure is related to */
211 struct dsa_switch *ds;
212
Andrew Lunn158bc062016-04-28 21:24:06 -0400213 /* The device this structure is associated to */
214 struct device *dev;
215
Vivien Didelot9f8b3ee2016-06-20 13:14:05 -0400216 /* This mutex protects the access to the switch registers */
217 struct mutex reg_lock;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000218
Andrew Lunna77d43f2016-04-13 02:40:42 +0200219 /* The MII bus and the address on the bus that is used to
220 * communication with the switch
221 */
Vivien Didelotc08026a2016-09-29 12:21:59 -0400222 const struct mv88e6xxx_bus_ops *smi_ops;
Andrew Lunna77d43f2016-04-13 02:40:42 +0200223 struct mii_bus *bus;
224 int sw_addr;
225
Barry Grussling3675c8d2013-01-08 16:05:53 +0000226 /* Handles automatic disabling and re-enabling of the PHY
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000227 * polling unit.
228 */
Vivien Didelotc08026a2016-09-29 12:21:59 -0400229 const struct mv88e6xxx_bus_ops *phy_ops;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000230 struct mutex ppu_mutex;
231 int ppu_disabled;
232 struct work_struct ppu_work;
233 struct timer_list ppu_timer;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000234
Barry Grussling3675c8d2013-01-08 16:05:53 +0000235 /* This mutex serialises access to the statistics unit.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000236 * Hold this mutex over snapshot + dump sequences.
237 */
238 struct mutex stats_mutex;
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000239
Andrew Lunn52638f72016-05-10 23:27:22 +0200240 /* A switch may have a GPIO line tied to its reset pin. Parse
241 * this from the device tree, and use it before performing
242 * switch soft reset.
243 */
244 struct gpio_desc *reset;
Andrew Lunnf8cd8752016-05-10 23:27:25 +0200245
246 /* set to size of eeprom if supported by the switch */
247 int eeprom_len;
Andrew Lunnb516d452016-06-04 21:17:06 +0200248
Andrew Lunna3c53be52017-01-24 14:53:50 +0100249 /* List of mdio busses */
250 struct list_head mdios;
Andrew Lunndc30c352016-10-16 19:56:49 +0200251
252 /* There can be two interrupt controllers, which are chained
253 * off a GPIO as interrupt source
254 */
255 struct mv88e6xxx_irq g1_irq;
256 struct mv88e6xxx_irq g2_irq;
257 int irq;
Andrew Lunn8e757eb2016-11-20 20:14:18 +0100258 int device_irq;
Andrew Lunnfcd25162017-02-09 00:03:42 +0100259 int watchdog_irq;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000260};
261
Vivien Didelotc08026a2016-09-29 12:21:59 -0400262struct mv88e6xxx_bus_ops {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400263 int (*read)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
264 int (*write)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400265};
266
Andrew Lunn0dd12d52017-01-24 14:53:49 +0100267struct mv88e6xxx_mdio_bus {
Andrew Lunna3c53be52017-01-24 14:53:50 +0100268 struct mii_bus *bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +0100269 struct mv88e6xxx_chip *chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +0100270 struct list_head list;
271 bool external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +0100272};
273
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400274struct mv88e6xxx_ops {
Vivien Didelotcd8da8b2017-06-19 10:55:36 -0400275 /* Ingress Rate Limit unit (IRL) operations */
276 int (*irl_init_all)(struct mv88e6xxx_chip *chip, int port);
277
Vivien Didelotee4dc2e72016-09-29 12:22:02 -0400278 int (*get_eeprom)(struct mv88e6xxx_chip *chip,
279 struct ethtool_eeprom *eeprom, u8 *data);
280 int (*set_eeprom)(struct mv88e6xxx_chip *chip,
281 struct ethtool_eeprom *eeprom, u8 *data);
282
Vivien Didelotb073d4e2016-09-29 12:22:01 -0400283 int (*set_switch_mac)(struct mv88e6xxx_chip *chip, u8 *addr);
284
Andrew Lunnee26a222017-01-24 14:53:48 +0100285 int (*phy_read)(struct mv88e6xxx_chip *chip,
286 struct mii_bus *bus,
287 int addr, int reg, u16 *val);
288 int (*phy_write)(struct mv88e6xxx_chip *chip,
289 struct mii_bus *bus,
290 int addr, int reg, u16 val);
Vivien Didelot08ef7f12016-11-04 03:23:32 +0100291
Vivien Didelot9e907d72017-07-17 13:03:43 -0400292 /* Priority Override Table operations */
293 int (*pot_clear)(struct mv88e6xxx_chip *chip);
294
Vivien Didelota199d8b2016-12-05 17:30:28 -0500295 /* PHY Polling Unit (PPU) operations */
296 int (*ppu_enable)(struct mv88e6xxx_chip *chip);
297 int (*ppu_disable)(struct mv88e6xxx_chip *chip);
298
Vivien Didelot17e708b2016-12-05 17:30:27 -0500299 /* Switch Software Reset */
300 int (*reset)(struct mv88e6xxx_chip *chip);
301
Vivien Didelota0a0f622016-11-04 03:23:34 +0100302 /* RGMII Receive/Transmit Timing Control
303 * Add delay on PHY_INTERFACE_MODE_RGMII_*ID, no delay otherwise.
304 */
305 int (*port_set_rgmii_delay)(struct mv88e6xxx_chip *chip, int port,
306 phy_interface_t mode);
307
Vivien Didelot08ef7f12016-11-04 03:23:32 +0100308#define LINK_FORCED_DOWN 0
309#define LINK_FORCED_UP 1
310#define LINK_UNFORCED -2
311
312 /* Port's MAC link state
313 * Use LINK_FORCED_UP or LINK_FORCED_DOWN to force link up or down,
314 * or LINK_UNFORCED for normal link detection.
315 */
316 int (*port_set_link)(struct mv88e6xxx_chip *chip, int port, int link);
Vivien Didelot7f1ae072016-11-04 03:23:33 +0100317
318#define DUPLEX_UNFORCED -2
319
320 /* Port's MAC duplex mode
321 *
322 * Use DUPLEX_HALF or DUPLEX_FULL to force half or full duplex,
323 * or DUPLEX_UNFORCED for normal duplex detection.
324 */
325 int (*port_set_duplex)(struct mv88e6xxx_chip *chip, int port, int dup);
Vivien Didelot96a2b402016-11-04 03:23:35 +0100326
327#define SPEED_MAX INT_MAX
328#define SPEED_UNFORCED -2
329
330 /* Port's MAC speed (in Mbps)
331 *
332 * Depending on the chip, 10, 100, 200, 1000, 2500, 10000 are valid.
333 * Use SPEED_UNFORCED for normal detection, SPEED_MAX for max value.
334 */
335 int (*port_set_speed)(struct mv88e6xxx_chip *chip, int port, int speed);
Andrew Lunna605a0f2016-11-21 23:26:58 +0100336
Andrew Lunnef0a7312016-12-03 04:35:16 +0100337 int (*port_tag_remap)(struct mv88e6xxx_chip *chip, int port);
338
Andrew Lunn56995cb2016-12-03 04:35:19 +0100339 int (*port_set_frame_mode)(struct mv88e6xxx_chip *chip, int port,
340 enum mv88e6xxx_frame_mode mode);
Vivien Didelot601aeed2017-03-11 16:13:00 -0500341 int (*port_set_egress_floods)(struct mv88e6xxx_chip *chip, int port,
342 bool unicast, bool multicast);
Andrew Lunn56995cb2016-12-03 04:35:19 +0100343 int (*port_set_ether_type)(struct mv88e6xxx_chip *chip, int port,
344 u16 etype);
Vivien Didelotcd782652017-06-08 18:34:13 -0400345 int (*port_set_jumbo_size)(struct mv88e6xxx_chip *chip, int port,
346 size_t size);
Andrew Lunn56995cb2016-12-03 04:35:19 +0100347
Andrew Lunnef70b112016-12-03 04:45:18 +0100348 int (*port_egress_rate_limiting)(struct mv88e6xxx_chip *chip, int port);
Vivien Didelot08984322017-06-08 18:34:12 -0400349 int (*port_pause_limit)(struct mv88e6xxx_chip *chip, int port, u8 in,
350 u8 out);
Vivien Didelotc8c94892017-03-11 16:13:01 -0500351 int (*port_disable_learn_limit)(struct mv88e6xxx_chip *chip, int port);
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -0500352 int (*port_disable_pri_override)(struct mv88e6xxx_chip *chip, int port);
Andrew Lunnef70b112016-12-03 04:45:18 +0100353
Andrew Lunnf39908d2017-02-04 20:02:50 +0100354 /* CMODE control what PHY mode the MAC will use, eg. SGMII, RGMII, etc.
355 * Some chips allow this to be configured on specific ports.
356 */
357 int (*port_set_cmode)(struct mv88e6xxx_chip *chip, int port,
358 phy_interface_t mode);
359
Andrew Lunna23b2962017-02-04 20:15:28 +0100360 /* Some devices have a per port register indicating what is
361 * the upstream port this port should forward to.
362 */
363 int (*port_set_upstream_port)(struct mv88e6xxx_chip *chip, int port,
364 int upstream_port);
365
Andrew Lunna605a0f2016-11-21 23:26:58 +0100366 /* Snapshot the statistics for a port. The statistics can then
367 * be read back a leisure but still with a consistent view.
368 */
369 int (*stats_snapshot)(struct mv88e6xxx_chip *chip, int port);
Andrew Lunnde2273872016-11-21 23:27:01 +0100370
371 /* Set the histogram mode for statistics, when the control registers
372 * are separated out of the STATS_OP register.
373 */
374 int (*stats_set_histogram)(struct mv88e6xxx_chip *chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100375
376 /* Return the number of strings describing statistics */
377 int (*stats_get_sset_count)(struct mv88e6xxx_chip *chip);
378 void (*stats_get_strings)(struct mv88e6xxx_chip *chip, uint8_t *data);
Andrew Lunn052f9472016-11-21 23:27:03 +0100379 void (*stats_get_stats)(struct mv88e6xxx_chip *chip, int port,
380 uint64_t *data);
Vivien Didelotfa8d1172017-06-08 18:34:11 -0400381 int (*set_cpu_port)(struct mv88e6xxx_chip *chip, int port);
382 int (*set_egress_port)(struct mv88e6xxx_chip *chip, int port);
Andrew Lunnfcd25162017-02-09 00:03:42 +0100383 const struct mv88e6xxx_irq_ops *watchdog_ops;
Andrew Lunn6e55f692016-12-03 04:45:16 +0100384
Andrew Lunn6e55f692016-12-03 04:45:16 +0100385 int (*mgmt_rsvd2cpu)(struct mv88e6xxx_chip *chip);
Vivien Didelotf1394b72017-05-01 14:05:22 -0400386
Andrew Lunn6d917822017-05-26 01:03:21 +0200387 /* Power on/off a SERDES interface */
388 int (*serdes_power)(struct mv88e6xxx_chip *chip, int port, bool on);
389
Vivien Didelotf1394b72017-05-01 14:05:22 -0400390 /* VLAN Translation Unit operations */
391 int (*vtu_getnext)(struct mv88e6xxx_chip *chip,
392 struct mv88e6xxx_vtu_entry *entry);
Vivien Didelot0ad5daf2017-05-01 14:05:23 -0400393 int (*vtu_loadpurge)(struct mv88e6xxx_chip *chip,
394 struct mv88e6xxx_vtu_entry *entry);
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400395};
396
Andrew Lunnfcd25162017-02-09 00:03:42 +0100397struct mv88e6xxx_irq_ops {
398 /* Action to be performed when the interrupt happens */
399 int (*irq_action)(struct mv88e6xxx_chip *chip, int irq);
400 /* Setup the hardware to generate the interrupt */
401 int (*irq_setup)(struct mv88e6xxx_chip *chip);
402 /* Reset the hardware to stop generating the interrupt */
403 void (*irq_free)(struct mv88e6xxx_chip *chip);
404};
405
Andrew Lunndfafe442016-11-21 23:27:02 +0100406#define STATS_TYPE_PORT BIT(0)
407#define STATS_TYPE_BANK0 BIT(1)
408#define STATS_TYPE_BANK1 BIT(2)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100409
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000410struct mv88e6xxx_hw_stat {
411 char string[ETH_GSTRING_LEN];
412 int sizeof_stat;
413 int reg;
Andrew Lunndfafe442016-11-21 23:27:02 +0100414 int type;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000415};
416
Vivien Didelotfad09c72016-06-21 12:28:20 -0400417static inline bool mv88e6xxx_has(struct mv88e6xxx_chip *chip,
Vivien Didelotb5058d72016-05-09 13:22:38 -0400418 unsigned long flags)
419{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400420 return (chip->info->flags & flags) == flags;
Vivien Didelotb5058d72016-05-09 13:22:38 -0400421}
422
Vivien Didelotf3645652017-03-30 17:37:07 -0400423static inline bool mv88e6xxx_has_pvt(struct mv88e6xxx_chip *chip)
424{
425 return chip->info->pvt;
426}
427
Vivien Didelotde333762016-09-29 12:21:56 -0400428static inline unsigned int mv88e6xxx_num_databases(struct mv88e6xxx_chip *chip)
429{
430 return chip->info->num_databases;
431}
432
Vivien Didelot370b4ff2016-09-29 12:21:57 -0400433static inline unsigned int mv88e6xxx_num_ports(struct mv88e6xxx_chip *chip)
434{
435 return chip->info->num_ports;
436}
437
Vivien Didelot4d294af2017-03-11 16:12:47 -0500438static inline u16 mv88e6xxx_port_mask(struct mv88e6xxx_chip *chip)
439{
440 return GENMASK(mv88e6xxx_num_ports(chip) - 1, 0);
441}
442
Vivien Didelotec561272016-09-02 14:45:33 -0400443int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
444int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
445int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg,
446 u16 update);
447int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask);
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200448struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip);
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -0400449
450#endif /* _MV88E6XXX_CHIP_H */