blob: 12b7f4649b25bfb5f1c9e00e5dcb4b411155823c [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>
Andrew Lunn294d7112018-02-22 22:58:32 +010018#include <linux/kthread.h>
Russell King4d56a292017-02-07 15:03:05 -080019#include <linux/phy.h>
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +010020#include <linux/ptp_clock_kernel.h>
21#include <linux/timecounter.h>
Andrew Lunnc6e970a2017-03-28 23:45:06 +020022#include <net/dsa.h>
Vivien Didelot194fea72015-08-10 09:09:47 -040023
Andrew Lunn80c46272015-06-20 18:42:30 +020024#ifndef UINT64_MAX
25#define UINT64_MAX (u64)(~((u64)0))
26#endif
27
Andrew Lunncca8b132015-04-02 04:06:39 +020028#define SMI_CMD 0x00
29#define SMI_CMD_BUSY BIT(15)
30#define SMI_CMD_CLAUSE_22 BIT(12)
31#define SMI_CMD_OP_22_WRITE ((1 << 10) | SMI_CMD_BUSY | SMI_CMD_CLAUSE_22)
32#define SMI_CMD_OP_22_READ ((2 << 10) | SMI_CMD_BUSY | SMI_CMD_CLAUSE_22)
33#define SMI_CMD_OP_45_WRITE_ADDR ((0 << 10) | SMI_CMD_BUSY)
34#define SMI_CMD_OP_45_WRITE_DATA ((1 << 10) | SMI_CMD_BUSY)
35#define SMI_CMD_OP_45_READ_DATA ((2 << 10) | SMI_CMD_BUSY)
36#define SMI_CMD_OP_45_READ_DATA_INC ((3 << 10) | SMI_CMD_BUSY)
37#define SMI_DATA 0x01
Guenter Roeckb2eb0662015-04-02 04:06:30 +020038
Vivien Didelot3285f9e2016-02-26 13:16:03 -050039#define MV88E6XXX_N_FID 4096
40
Vivien Didelot17a15942017-03-30 17:37:09 -040041/* PVT limits for 4-bit port and 5-bit switch */
42#define MV88E6XXX_MAX_PVT_SWITCHES 32
43#define MV88E6XXX_MAX_PVT_PORTS 16
44
Brandon Streiffa73ccd62018-02-14 01:07:46 +010045#define MV88E6XXX_MAX_GPIO 16
46
Vivien Didelot31bef4e2017-06-08 18:34:09 -040047enum mv88e6xxx_egress_mode {
48 MV88E6XXX_EGRESS_MODE_UNMODIFIED,
49 MV88E6XXX_EGRESS_MODE_UNTAGGED,
50 MV88E6XXX_EGRESS_MODE_TAGGED,
51 MV88E6XXX_EGRESS_MODE_ETHERTYPE,
52};
53
Andrew Lunn56995cb2016-12-03 04:35:19 +010054enum mv88e6xxx_frame_mode {
55 MV88E6XXX_FRAME_MODE_NORMAL,
56 MV88E6XXX_FRAME_MODE_DSA,
57 MV88E6XXX_FRAME_MODE_PROVIDER,
58 MV88E6XXX_FRAME_MODE_ETHERTYPE,
59};
60
Vivien Didelotf81ec902016-05-09 13:22:58 -040061/* List of supported models */
62enum mv88e6xxx_model {
63 MV88E6085,
64 MV88E6095,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +010065 MV88E6097,
Vivien Didelotf81ec902016-05-09 13:22:58 -040066 MV88E6123,
67 MV88E6131,
Gregory CLEMENT15587272017-01-30 20:29:35 +010068 MV88E6141,
Vivien Didelotf81ec902016-05-09 13:22:58 -040069 MV88E6161,
70 MV88E6165,
71 MV88E6171,
72 MV88E6172,
73 MV88E6175,
74 MV88E6176,
75 MV88E6185,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +010076 MV88E6190,
77 MV88E6190X,
78 MV88E6191,
Vivien Didelotf81ec902016-05-09 13:22:58 -040079 MV88E6240,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +010080 MV88E6290,
Vivien Didelotf81ec902016-05-09 13:22:58 -040081 MV88E6320,
82 MV88E6321,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +010083 MV88E6341,
Vivien Didelotf81ec902016-05-09 13:22:58 -040084 MV88E6350,
85 MV88E6351,
86 MV88E6352,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +010087 MV88E6390,
88 MV88E6390X,
Vivien Didelotf81ec902016-05-09 13:22:58 -040089};
90
Vivien Didelot22356472016-04-17 13:24:00 -040091enum mv88e6xxx_family {
92 MV88E6XXX_FAMILY_NONE,
93 MV88E6XXX_FAMILY_6065, /* 6031 6035 6061 6065 */
94 MV88E6XXX_FAMILY_6095, /* 6092 6095 */
95 MV88E6XXX_FAMILY_6097, /* 6046 6085 6096 6097 */
96 MV88E6XXX_FAMILY_6165, /* 6123 6161 6165 */
97 MV88E6XXX_FAMILY_6185, /* 6108 6121 6122 6131 6152 6155 6182 6185 */
98 MV88E6XXX_FAMILY_6320, /* 6320 6321 */
Gregory CLEMENTa75961d2017-01-30 20:29:34 +010099 MV88E6XXX_FAMILY_6341, /* 6141 6341 */
Vivien Didelot22356472016-04-17 13:24:00 -0400100 MV88E6XXX_FAMILY_6351, /* 6171 6175 6350 6351 */
101 MV88E6XXX_FAMILY_6352, /* 6172 6176 6240 6352 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +0100102 MV88E6XXX_FAMILY_6390, /* 6190 6190X 6191 6290 6390 6390X */
Vivien Didelot22356472016-04-17 13:24:00 -0400103};
104
Andrew Lunnc0e4dad2017-02-09 00:00:43 +0100105struct mv88e6xxx_ops;
106
Vivien Didelotf6271e62016-04-17 13:23:59 -0400107struct mv88e6xxx_info {
Vivien Didelot22356472016-04-17 13:24:00 -0400108 enum mv88e6xxx_family family;
Vivien Didelotf6271e62016-04-17 13:23:59 -0400109 u16 prod_num;
110 const char *name;
Vivien Didelotcd5a2c82016-04-17 13:24:02 -0400111 unsigned int num_databases;
Vivien Didelot009a2b92016-04-17 13:24:01 -0400112 unsigned int num_ports;
Andrew Lunnbc393152018-03-17 20:32:04 +0100113 unsigned int num_internal_phys;
Brandon Streiffa73ccd62018-02-14 01:07:46 +0100114 unsigned int num_gpio;
Vivien Didelot3cf3c842017-05-01 14:05:10 -0400115 unsigned int max_vid;
Vivien Didelot9dddd472016-06-20 13:14:10 -0400116 unsigned int port_base_addr;
Andrew Lunn9255bac2018-05-05 20:58:22 +0200117 unsigned int phy_base_addr;
Vivien Didelota935c052016-09-29 12:21:53 -0400118 unsigned int global1_addr;
Vivien Didelot9069c132017-07-17 13:03:44 -0400119 unsigned int global2_addr;
Vivien Didelotacddbd22016-07-18 20:45:39 -0400120 unsigned int age_time_coeff;
Andrew Lunndc30c352016-10-16 19:56:49 +0200121 unsigned int g1_irqs;
Vivien Didelotd6c5e6a2017-07-17 13:03:40 -0400122 unsigned int g2_irqs;
Vivien Didelotf3645652017-03-30 17:37:07 -0400123 bool pvt;
Vivien Didelotb3e05aa2017-07-17 13:03:46 -0400124
125 /* Multi-chip Addressing Mode.
126 * Some chips respond to only 2 registers of its own SMI device address
127 * when it is non-zero, and use indirect access to internal registers.
128 */
129 bool multi_chip;
Andrew Lunn443d5a12016-12-03 04:35:18 +0100130 enum dsa_tag_protocol tag_protocol;
Vivien Didelote606ca32017-03-11 16:12:55 -0500131
132 /* Mask for FromPort and ToPort value of PortVec used in ATU Move
133 * operation. 0 means that the ATU Move operation is not supported.
134 */
135 u8 atu_move_port_mask;
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400136 const struct mv88e6xxx_ops *ops;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +0100137
138 /* Supports PTP */
139 bool ptp_support;
Vivien Didelotb9b37712015-10-30 19:39:48 -0400140};
141
Vivien Didelotfd231c82015-08-10 09:09:50 -0400142struct mv88e6xxx_atu_entry {
Vivien Didelotfd231c82015-08-10 09:09:50 -0400143 u8 state;
144 bool trunk;
Vivien Didelot01bd96c2017-03-11 16:12:57 -0500145 u16 portvec;
Vivien Didelotfd231c82015-08-10 09:09:50 -0400146 u8 mac[ETH_ALEN];
147};
148
Vivien Didelotb4e47c02016-09-29 12:21:58 -0400149struct mv88e6xxx_vtu_entry {
Vivien Didelotb8fee952015-08-13 12:52:19 -0400150 u16 vid;
151 u16 fid;
Vivien Didelotb8fee952015-08-13 12:52:19 -0400152 u8 sid;
153 bool valid;
Vivien Didelotbd00e052017-05-01 14:05:11 -0400154 u8 member[DSA_MAX_PORTS];
155 u8 state[DSA_MAX_PORTS];
Vivien Didelotb8fee952015-08-13 12:52:19 -0400156};
157
Vivien Didelotc08026a2016-09-29 12:21:59 -0400158struct mv88e6xxx_bus_ops;
Andrew Lunnfcd25162017-02-09 00:03:42 +0100159struct mv88e6xxx_irq_ops;
Brandon Streiffa73ccd62018-02-14 01:07:46 +0100160struct mv88e6xxx_gpio_ops;
Brandon Streiff0d632c32018-02-14 01:07:44 +0100161struct mv88e6xxx_avb_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -0400162
Andrew Lunndc30c352016-10-16 19:56:49 +0200163struct mv88e6xxx_irq {
164 u16 masked;
165 struct irq_chip chip;
166 struct irq_domain *domain;
167 unsigned int nirqs;
168};
169
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +0100170/* state flags for mv88e6xxx_port_hwtstamp::state */
171enum {
172 MV88E6XXX_HWTSTAMP_ENABLED,
173 MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS,
174};
175
176struct mv88e6xxx_port_hwtstamp {
177 /* Port index */
178 int port_id;
179
180 /* Timestamping state */
181 unsigned long state;
182
183 /* Resources for receive timestamping */
184 struct sk_buff_head rx_queue;
185 struct sk_buff_head rx_queue2;
186
187 /* Resources for transmit timestamping */
188 unsigned long tx_tstamp_start;
189 struct sk_buff *tx_skb;
190 u16 tx_seq_id;
191
192 /* Current timestamp configuration */
193 struct hwtstamp_config tstamp_config;
194};
195
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100196struct mv88e6xxx_port {
197 u64 serdes_stats[2];
Andrew Lunn65f60e42018-03-28 23:50:28 +0200198 u64 atu_member_violation;
199 u64 atu_miss_violation;
200 u64 atu_full_violation;
201 u64 vtu_member_violation;
202 u64 vtu_miss_violation;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100203};
204
Vivien Didelotfad09c72016-06-21 12:28:20 -0400205struct mv88e6xxx_chip {
Vivien Didelotf6271e62016-04-17 13:23:59 -0400206 const struct mv88e6xxx_info *info;
207
Andrew Lunn7543a6d2016-04-13 02:40:40 +0200208 /* The dsa_switch this private structure is related to */
209 struct dsa_switch *ds;
210
Andrew Lunn158bc062016-04-28 21:24:06 -0400211 /* The device this structure is associated to */
212 struct device *dev;
213
Vivien Didelot9f8b3ee2016-06-20 13:14:05 -0400214 /* This mutex protects the access to the switch registers */
215 struct mutex reg_lock;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000216
Andrew Lunna77d43f2016-04-13 02:40:42 +0200217 /* The MII bus and the address on the bus that is used to
218 * communication with the switch
219 */
Vivien Didelotc08026a2016-09-29 12:21:59 -0400220 const struct mv88e6xxx_bus_ops *smi_ops;
Andrew Lunna77d43f2016-04-13 02:40:42 +0200221 struct mii_bus *bus;
222 int sw_addr;
223
Barry Grussling3675c8d2013-01-08 16:05:53 +0000224 /* Handles automatic disabling and re-enabling of the PHY
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000225 * polling unit.
226 */
Vivien Didelotc08026a2016-09-29 12:21:59 -0400227 const struct mv88e6xxx_bus_ops *phy_ops;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000228 struct mutex ppu_mutex;
229 int ppu_disabled;
230 struct work_struct ppu_work;
231 struct timer_list ppu_timer;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000232
Barry Grussling3675c8d2013-01-08 16:05:53 +0000233 /* This mutex serialises access to the statistics unit.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000234 * Hold this mutex over snapshot + dump sequences.
235 */
236 struct mutex stats_mutex;
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000237
Andrew Lunn52638f72016-05-10 23:27:22 +0200238 /* A switch may have a GPIO line tied to its reset pin. Parse
239 * this from the device tree, and use it before performing
240 * switch soft reset.
241 */
242 struct gpio_desc *reset;
Andrew Lunnf8cd8752016-05-10 23:27:25 +0200243
244 /* set to size of eeprom if supported by the switch */
245 int eeprom_len;
Andrew Lunnb516d452016-06-04 21:17:06 +0200246
Andrew Lunna3c53be52017-01-24 14:53:50 +0100247 /* List of mdio busses */
248 struct list_head mdios;
Andrew Lunndc30c352016-10-16 19:56:49 +0200249
250 /* There can be two interrupt controllers, which are chained
251 * off a GPIO as interrupt source
252 */
253 struct mv88e6xxx_irq g1_irq;
254 struct mv88e6xxx_irq g2_irq;
255 int irq;
Andrew Lunn8e757eb2016-11-20 20:14:18 +0100256 int device_irq;
Andrew Lunnfcd25162017-02-09 00:03:42 +0100257 int watchdog_irq;
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100258
Andrew Lunn09776442018-01-14 02:32:44 +0100259 int atu_prob_irq;
Andrew Lunn62eb1162018-01-14 02:32:45 +0100260 int vtu_prob_irq;
Andrew Lunn294d7112018-02-22 22:58:32 +0100261 struct kthread_worker *kworker;
262 struct kthread_delayed_work irq_poll_work;
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +0100263
Brandon Streiffa73ccd62018-02-14 01:07:46 +0100264 /* GPIO resources */
265 u8 gpio_data[2];
266
Brandon Streiff2fa8d3a2018-02-14 01:07:45 +0100267 /* This cyclecounter abstracts the switch PTP time.
268 * reg_lock must be held for any operation that read()s.
269 */
270 struct cyclecounter tstamp_cc;
271 struct timecounter tstamp_tc;
272 struct delayed_work overflow_work;
273
274 struct ptp_clock *ptp_clock;
275 struct ptp_clock_info ptp_clock_info;
Brandon Streiff4eb3be22018-02-14 01:07:47 +0100276 struct delayed_work tai_event_work;
277 struct ptp_pin_desc pin_config[MV88E6XXX_MAX_GPIO];
278 u16 trig_config;
279 u16 evcap_config;
Brandon Streiffc6fe0ad2018-02-14 01:07:50 +0100280
281 /* Per-port timestamping resources. */
282 struct mv88e6xxx_port_hwtstamp port_hwtstamp[DSA_MAX_PORTS];
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100283
284 /* Array of port structures. */
285 struct mv88e6xxx_port ports[DSA_MAX_PORTS];
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000286};
287
Vivien Didelotc08026a2016-09-29 12:21:59 -0400288struct mv88e6xxx_bus_ops {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400289 int (*read)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
290 int (*write)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400291};
292
Andrew Lunn0dd12d52017-01-24 14:53:49 +0100293struct mv88e6xxx_mdio_bus {
Andrew Lunna3c53be52017-01-24 14:53:50 +0100294 struct mii_bus *bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +0100295 struct mv88e6xxx_chip *chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +0100296 struct list_head list;
297 bool external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +0100298};
299
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400300struct mv88e6xxx_ops {
Vivien Didelotcd8da8b2017-06-19 10:55:36 -0400301 /* Ingress Rate Limit unit (IRL) operations */
302 int (*irl_init_all)(struct mv88e6xxx_chip *chip, int port);
303
Vivien Didelotee4dc2e72016-09-29 12:22:02 -0400304 int (*get_eeprom)(struct mv88e6xxx_chip *chip,
305 struct ethtool_eeprom *eeprom, u8 *data);
306 int (*set_eeprom)(struct mv88e6xxx_chip *chip,
307 struct ethtool_eeprom *eeprom, u8 *data);
308
Vivien Didelotb073d4e2016-09-29 12:22:01 -0400309 int (*set_switch_mac)(struct mv88e6xxx_chip *chip, u8 *addr);
310
Andrew Lunnee26a222017-01-24 14:53:48 +0100311 int (*phy_read)(struct mv88e6xxx_chip *chip,
312 struct mii_bus *bus,
313 int addr, int reg, u16 *val);
314 int (*phy_write)(struct mv88e6xxx_chip *chip,
315 struct mii_bus *bus,
316 int addr, int reg, u16 val);
Vivien Didelot08ef7f12016-11-04 03:23:32 +0100317
Vivien Didelot9e907d72017-07-17 13:03:43 -0400318 /* Priority Override Table operations */
319 int (*pot_clear)(struct mv88e6xxx_chip *chip);
320
Vivien Didelota199d8b2016-12-05 17:30:28 -0500321 /* PHY Polling Unit (PPU) operations */
322 int (*ppu_enable)(struct mv88e6xxx_chip *chip);
323 int (*ppu_disable)(struct mv88e6xxx_chip *chip);
324
Vivien Didelot17e708b2016-12-05 17:30:27 -0500325 /* Switch Software Reset */
326 int (*reset)(struct mv88e6xxx_chip *chip);
327
Vivien Didelota0a0f622016-11-04 03:23:34 +0100328 /* RGMII Receive/Transmit Timing Control
329 * Add delay on PHY_INTERFACE_MODE_RGMII_*ID, no delay otherwise.
330 */
331 int (*port_set_rgmii_delay)(struct mv88e6xxx_chip *chip, int port,
332 phy_interface_t mode);
333
Vivien Didelot08ef7f12016-11-04 03:23:32 +0100334#define LINK_FORCED_DOWN 0
335#define LINK_FORCED_UP 1
336#define LINK_UNFORCED -2
337
338 /* Port's MAC link state
339 * Use LINK_FORCED_UP or LINK_FORCED_DOWN to force link up or down,
340 * or LINK_UNFORCED for normal link detection.
341 */
342 int (*port_set_link)(struct mv88e6xxx_chip *chip, int port, int link);
Vivien Didelot7f1ae072016-11-04 03:23:33 +0100343
344#define DUPLEX_UNFORCED -2
345
346 /* Port's MAC duplex mode
347 *
348 * Use DUPLEX_HALF or DUPLEX_FULL to force half or full duplex,
349 * or DUPLEX_UNFORCED for normal duplex detection.
350 */
351 int (*port_set_duplex)(struct mv88e6xxx_chip *chip, int port, int dup);
Vivien Didelot96a2b402016-11-04 03:23:35 +0100352
353#define SPEED_MAX INT_MAX
354#define SPEED_UNFORCED -2
355
356 /* Port's MAC speed (in Mbps)
357 *
358 * Depending on the chip, 10, 100, 200, 1000, 2500, 10000 are valid.
359 * Use SPEED_UNFORCED for normal detection, SPEED_MAX for max value.
360 */
361 int (*port_set_speed)(struct mv88e6xxx_chip *chip, int port, int speed);
Andrew Lunna605a0f2016-11-21 23:26:58 +0100362
Andrew Lunnef0a7312016-12-03 04:35:16 +0100363 int (*port_tag_remap)(struct mv88e6xxx_chip *chip, int port);
364
Andrew Lunn56995cb2016-12-03 04:35:19 +0100365 int (*port_set_frame_mode)(struct mv88e6xxx_chip *chip, int port,
366 enum mv88e6xxx_frame_mode mode);
Vivien Didelot601aeed2017-03-11 16:13:00 -0500367 int (*port_set_egress_floods)(struct mv88e6xxx_chip *chip, int port,
368 bool unicast, bool multicast);
Andrew Lunn56995cb2016-12-03 04:35:19 +0100369 int (*port_set_ether_type)(struct mv88e6xxx_chip *chip, int port,
370 u16 etype);
Vivien Didelotcd782652017-06-08 18:34:13 -0400371 int (*port_set_jumbo_size)(struct mv88e6xxx_chip *chip, int port,
372 size_t size);
Andrew Lunn56995cb2016-12-03 04:35:19 +0100373
Andrew Lunnef70b112016-12-03 04:45:18 +0100374 int (*port_egress_rate_limiting)(struct mv88e6xxx_chip *chip, int port);
Vivien Didelot08984322017-06-08 18:34:12 -0400375 int (*port_pause_limit)(struct mv88e6xxx_chip *chip, int port, u8 in,
376 u8 out);
Vivien Didelotc8c94892017-03-11 16:13:01 -0500377 int (*port_disable_learn_limit)(struct mv88e6xxx_chip *chip, int port);
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -0500378 int (*port_disable_pri_override)(struct mv88e6xxx_chip *chip, int port);
Andrew Lunnef70b112016-12-03 04:45:18 +0100379
Andrew Lunnf39908d2017-02-04 20:02:50 +0100380 /* CMODE control what PHY mode the MAC will use, eg. SGMII, RGMII, etc.
381 * Some chips allow this to be configured on specific ports.
382 */
383 int (*port_set_cmode)(struct mv88e6xxx_chip *chip, int port,
384 phy_interface_t mode);
385
Andrew Lunna23b2962017-02-04 20:15:28 +0100386 /* Some devices have a per port register indicating what is
387 * the upstream port this port should forward to.
388 */
389 int (*port_set_upstream_port)(struct mv88e6xxx_chip *chip, int port,
390 int upstream_port);
391
Andrew Lunna605a0f2016-11-21 23:26:58 +0100392 /* Snapshot the statistics for a port. The statistics can then
393 * be read back a leisure but still with a consistent view.
394 */
395 int (*stats_snapshot)(struct mv88e6xxx_chip *chip, int port);
Andrew Lunnde2273872016-11-21 23:27:01 +0100396
397 /* Set the histogram mode for statistics, when the control registers
398 * are separated out of the STATS_OP register.
399 */
400 int (*stats_set_histogram)(struct mv88e6xxx_chip *chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100401
402 /* Return the number of strings describing statistics */
403 int (*stats_get_sset_count)(struct mv88e6xxx_chip *chip);
Andrew Lunn436fe172018-03-01 02:02:29 +0100404 int (*stats_get_strings)(struct mv88e6xxx_chip *chip, uint8_t *data);
405 int (*stats_get_stats)(struct mv88e6xxx_chip *chip, int port,
406 uint64_t *data);
Vivien Didelotfa8d1172017-06-08 18:34:11 -0400407 int (*set_cpu_port)(struct mv88e6xxx_chip *chip, int port);
408 int (*set_egress_port)(struct mv88e6xxx_chip *chip, int port);
Andrew Lunnfcd25162017-02-09 00:03:42 +0100409 const struct mv88e6xxx_irq_ops *watchdog_ops;
Andrew Lunn6e55f692016-12-03 04:45:16 +0100410
Andrew Lunn6e55f692016-12-03 04:45:16 +0100411 int (*mgmt_rsvd2cpu)(struct mv88e6xxx_chip *chip);
Vivien Didelotf1394b72017-05-01 14:05:22 -0400412
Andrew Lunn6d917822017-05-26 01:03:21 +0200413 /* Power on/off a SERDES interface */
414 int (*serdes_power)(struct mv88e6xxx_chip *chip, int port, bool on);
415
Andrew Lunn436fe172018-03-01 02:02:29 +0100416 /* Statistics from the SERDES interface */
417 int (*serdes_get_sset_count)(struct mv88e6xxx_chip *chip, int port);
Andrew Lunn65f60e42018-03-28 23:50:28 +0200418 int (*serdes_get_strings)(struct mv88e6xxx_chip *chip, int port,
419 uint8_t *data);
420 int (*serdes_get_stats)(struct mv88e6xxx_chip *chip, int port,
421 uint64_t *data);
Andrew Lunn436fe172018-03-01 02:02:29 +0100422
Vivien Didelotf1394b72017-05-01 14:05:22 -0400423 /* VLAN Translation Unit operations */
424 int (*vtu_getnext)(struct mv88e6xxx_chip *chip,
425 struct mv88e6xxx_vtu_entry *entry);
Vivien Didelot0ad5daf2017-05-01 14:05:23 -0400426 int (*vtu_loadpurge)(struct mv88e6xxx_chip *chip,
427 struct mv88e6xxx_vtu_entry *entry);
Brandon Streiff0d632c32018-02-14 01:07:44 +0100428
Brandon Streiffa73ccd62018-02-14 01:07:46 +0100429 /* GPIO operations */
430 const struct mv88e6xxx_gpio_ops *gpio_ops;
431
Brandon Streiff0d632c32018-02-14 01:07:44 +0100432 /* Interface to the AVB/PTP registers */
433 const struct mv88e6xxx_avb_ops *avb_ops;
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400434};
435
Andrew Lunnfcd25162017-02-09 00:03:42 +0100436struct mv88e6xxx_irq_ops {
437 /* Action to be performed when the interrupt happens */
438 int (*irq_action)(struct mv88e6xxx_chip *chip, int irq);
439 /* Setup the hardware to generate the interrupt */
440 int (*irq_setup)(struct mv88e6xxx_chip *chip);
441 /* Reset the hardware to stop generating the interrupt */
442 void (*irq_free)(struct mv88e6xxx_chip *chip);
443};
444
Brandon Streiffa73ccd62018-02-14 01:07:46 +0100445struct mv88e6xxx_gpio_ops {
446 /* Get/set data on GPIO pin */
447 int (*get_data)(struct mv88e6xxx_chip *chip, unsigned int pin);
448 int (*set_data)(struct mv88e6xxx_chip *chip, unsigned int pin,
449 int value);
450
451 /* get/set GPIO direction */
452 int (*get_dir)(struct mv88e6xxx_chip *chip, unsigned int pin);
453 int (*set_dir)(struct mv88e6xxx_chip *chip, unsigned int pin,
454 bool input);
455
456 /* get/set GPIO pin control */
457 int (*get_pctl)(struct mv88e6xxx_chip *chip, unsigned int pin,
458 int *func);
459 int (*set_pctl)(struct mv88e6xxx_chip *chip, unsigned int pin,
460 int func);
461};
462
Brandon Streiff0d632c32018-02-14 01:07:44 +0100463struct mv88e6xxx_avb_ops {
464 /* Access port-scoped Precision Time Protocol registers */
465 int (*port_ptp_read)(struct mv88e6xxx_chip *chip, int port, int addr,
466 u16 *data, int len);
467 int (*port_ptp_write)(struct mv88e6xxx_chip *chip, int port, int addr,
468 u16 data);
469
470 /* Access global Precision Time Protocol registers */
471 int (*ptp_read)(struct mv88e6xxx_chip *chip, int addr, u16 *data,
472 int len);
473 int (*ptp_write)(struct mv88e6xxx_chip *chip, int addr, u16 data);
474
475 /* Access global Time Application Interface registers */
476 int (*tai_read)(struct mv88e6xxx_chip *chip, int addr, u16 *data,
477 int len);
478 int (*tai_write)(struct mv88e6xxx_chip *chip, int addr, u16 data);
479};
480
Andrew Lunndfafe442016-11-21 23:27:02 +0100481#define STATS_TYPE_PORT BIT(0)
482#define STATS_TYPE_BANK0 BIT(1)
483#define STATS_TYPE_BANK1 BIT(2)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100484
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000485struct mv88e6xxx_hw_stat {
486 char string[ETH_GSTRING_LEN];
Andrew Lunncda9f4a2018-03-01 02:02:31 +0100487 size_t size;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000488 int reg;
Andrew Lunndfafe442016-11-21 23:27:02 +0100489 int type;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000490};
491
Vivien Didelotf3645652017-03-30 17:37:07 -0400492static inline bool mv88e6xxx_has_pvt(struct mv88e6xxx_chip *chip)
493{
494 return chip->info->pvt;
495}
496
Vivien Didelotde333762016-09-29 12:21:56 -0400497static inline unsigned int mv88e6xxx_num_databases(struct mv88e6xxx_chip *chip)
498{
499 return chip->info->num_databases;
500}
501
Vivien Didelot370b4ff2016-09-29 12:21:57 -0400502static inline unsigned int mv88e6xxx_num_ports(struct mv88e6xxx_chip *chip)
503{
504 return chip->info->num_ports;
505}
506
Vivien Didelot4d294af2017-03-11 16:12:47 -0500507static inline u16 mv88e6xxx_port_mask(struct mv88e6xxx_chip *chip)
508{
509 return GENMASK(mv88e6xxx_num_ports(chip) - 1, 0);
510}
511
Brandon Streiffa73ccd62018-02-14 01:07:46 +0100512static inline unsigned int mv88e6xxx_num_gpio(struct mv88e6xxx_chip *chip)
513{
514 return chip->info->num_gpio;
515}
516
Vivien Didelotec561272016-09-02 14:45:33 -0400517int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
518int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
519int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg,
520 u16 update);
521int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask);
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200522struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip);
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -0400523
524#endif /* _MV88E6XXX_CHIP_H */