blob: 086444016352a05ea006cf3d99b3918f02f25acf [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 */
111
Vivien Didelot6dc10bb2016-09-29 12:21:55 -0400112 /* Switch Global (1) Registers.
113 */
114 MV88E6XXX_CAP_G1_ATU_FID, /* (0x01) ATU FID Register */
115 MV88E6XXX_CAP_G1_VTU_FID, /* (0x02) VTU FID Register */
116
Vivien Didelot97299342016-07-18 20:45:30 -0400117 /* Switch Global 2 Registers.
118 * The device contains a second set of global 16-bit registers.
119 */
120 MV88E6XXX_CAP_GLOBAL2,
Andrew Lunndc30c352016-10-16 19:56:49 +0200121 MV88E6XXX_CAP_G2_INT, /* (0x00) Interrupt Status */
Vivien Didelot47395ed2016-07-18 20:45:33 -0400122 MV88E6XXX_CAP_G2_MGMT_EN_2X, /* (0x02) MGMT Enable Register 2x */
123 MV88E6XXX_CAP_G2_MGMT_EN_0X, /* (0x03) MGMT Enable Register 0x */
Vivien Didelot9bda8892016-07-18 20:45:36 -0400124 MV88E6XXX_CAP_G2_POT, /* (0x0f) Priority Override Table */
Vivien Didelot97299342016-07-18 20:45:30 -0400125
Vivien Didelotcb9b9022016-05-10 15:44:29 -0400126 /* Per VLAN Spanning Tree Unit (STU).
127 * The Port State database, if present, is accessed through VTU
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -0400128 * operations and dedicated SID registers. See MV88E6352_G1_VTU_SID.
Vivien Didelotcb9b9022016-05-10 15:44:29 -0400129 */
130 MV88E6XXX_CAP_STU,
131
Vivien Didelot54d77b52016-05-09 13:22:47 -0400132 /* VLAN Table Unit.
Vivien Didelot7ec60d6e2017-06-15 12:14:02 -0400133 * The VTU is used to program 802.1Q VLANs. See MV88E6XXX_G1_VTU_OP.
Vivien Didelot54d77b52016-05-09 13:22:47 -0400134 */
135 MV88E6XXX_CAP_VTU,
Vivien Didelot8c9983a2016-05-09 13:22:39 -0400136};
Vivien Didelotb5058d72016-05-09 13:22:38 -0400137
Vivien Didelot8c9983a2016-05-09 13:22:39 -0400138/* Bitmask of capabilities */
Andrew Lunnd6b10232016-09-21 01:40:32 +0200139#define MV88E6XXX_FLAG_EEE BIT_ULL(MV88E6XXX_CAP_EEE)
Vivien Didelota0ffff22016-08-15 17:18:58 -0400140
Andrew Lunnd6b10232016-09-21 01:40:32 +0200141#define MV88E6XXX_FLAG_SMI_CMD BIT_ULL(MV88E6XXX_CAP_SMI_CMD)
142#define MV88E6XXX_FLAG_SMI_DATA BIT_ULL(MV88E6XXX_CAP_SMI_DATA)
Vivien Didelota0ffff22016-08-15 17:18:58 -0400143
Vivien Didelot6dc10bb2016-09-29 12:21:55 -0400144#define MV88E6XXX_FLAG_G1_VTU_FID BIT_ULL(MV88E6XXX_CAP_G1_VTU_FID)
145
Andrew Lunnd6b10232016-09-21 01:40:32 +0200146#define MV88E6XXX_FLAG_GLOBAL2 BIT_ULL(MV88E6XXX_CAP_GLOBAL2)
Andrew Lunndc30c352016-10-16 19:56:49 +0200147#define MV88E6XXX_FLAG_G2_INT BIT_ULL(MV88E6XXX_CAP_G2_INT)
Andrew Lunnd6b10232016-09-21 01:40:32 +0200148#define MV88E6XXX_FLAG_G2_MGMT_EN_2X BIT_ULL(MV88E6XXX_CAP_G2_MGMT_EN_2X)
149#define MV88E6XXX_FLAG_G2_MGMT_EN_0X BIT_ULL(MV88E6XXX_CAP_G2_MGMT_EN_0X)
Andrew Lunnd6b10232016-09-21 01:40:32 +0200150#define MV88E6XXX_FLAG_G2_POT BIT_ULL(MV88E6XXX_CAP_G2_POT)
Vivien Didelota0ffff22016-08-15 17:18:58 -0400151
Vivien Didelota0ffff22016-08-15 17:18:58 -0400152/* Multi-chip Addressing Mode */
153#define MV88E6XXX_FLAGS_MULTI_CHIP \
154 (MV88E6XXX_FLAG_SMI_CMD | \
155 MV88E6XXX_FLAG_SMI_DATA)
156
Vivien Didelot8c9983a2016-05-09 13:22:39 -0400157#define MV88E6XXX_FLAGS_FAMILY_6095 \
Vivien Didelot97299342016-07-18 20:45:30 -0400158 (MV88E6XXX_FLAG_GLOBAL2 | \
Vivien Didelot47395ed2016-07-18 20:45:33 -0400159 MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
Vivien Didelota0ffff22016-08-15 17:18:58 -0400160 MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelot8c9983a2016-05-09 13:22:39 -0400161
162#define MV88E6XXX_FLAGS_FAMILY_6097 \
Vivien Didelote606ca32017-03-11 16:12:55 -0500163 (MV88E6XXX_FLAG_G1_VTU_FID | \
Vivien Didelot6dc10bb2016-09-29 12:21:55 -0400164 MV88E6XXX_FLAG_GLOBAL2 | \
Volodymyr Bendiuga56b46b42017-01-05 10:44:18 +0100165 MV88E6XXX_FLAG_G2_INT | \
Vivien Didelot47395ed2016-07-18 20:45:33 -0400166 MV88E6XXX_FLAG_G2_MGMT_EN_2X | \
167 MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
Vivien Didelot9bda8892016-07-18 20:45:36 -0400168 MV88E6XXX_FLAG_G2_POT | \
Vivien Didelotf3645652017-03-30 17:37:07 -0400169 MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelotb5058d72016-05-09 13:22:38 -0400170
Vivien Didelot6594f612016-05-09 13:22:42 -0400171#define MV88E6XXX_FLAGS_FAMILY_6165 \
Vivien Didelote606ca32017-03-11 16:12:55 -0500172 (MV88E6XXX_FLAG_G1_VTU_FID | \
Vivien Didelot6dc10bb2016-09-29 12:21:55 -0400173 MV88E6XXX_FLAG_GLOBAL2 | \
Andrew Lunndc30c352016-10-16 19:56:49 +0200174 MV88E6XXX_FLAG_G2_INT | \
Vivien Didelot47395ed2016-07-18 20:45:33 -0400175 MV88E6XXX_FLAG_G2_MGMT_EN_2X | \
176 MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
Vivien Didelot9bda8892016-07-18 20:45:36 -0400177 MV88E6XXX_FLAG_G2_POT | \
Vivien Didelotf3645652017-03-30 17:37:07 -0400178 MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelotb5058d72016-05-09 13:22:38 -0400179
Vivien Didelot8c9983a2016-05-09 13:22:39 -0400180#define MV88E6XXX_FLAGS_FAMILY_6185 \
Vivien Didelot97299342016-07-18 20:45:30 -0400181 (MV88E6XXX_FLAG_GLOBAL2 | \
Andrew Lunndc30c352016-10-16 19:56:49 +0200182 MV88E6XXX_FLAG_G2_INT | \
Vivien Didelot47395ed2016-07-18 20:45:33 -0400183 MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
Vivien Didelot3cf3c842017-05-01 14:05:10 -0400184 MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelotb5058d72016-05-09 13:22:38 -0400185
Vivien Didelot6d5834a2016-05-09 13:22:40 -0400186#define MV88E6XXX_FLAGS_FAMILY_6320 \
Andrew Lunn443d5a12016-12-03 04:35:18 +0100187 (MV88E6XXX_FLAG_EEE | \
Vivien Didelot97299342016-07-18 20:45:30 -0400188 MV88E6XXX_FLAG_GLOBAL2 | \
Vivien Didelot47395ed2016-07-18 20:45:33 -0400189 MV88E6XXX_FLAG_G2_MGMT_EN_2X | \
190 MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
Vivien Didelot9bda8892016-07-18 20:45:36 -0400191 MV88E6XXX_FLAG_G2_POT | \
Vivien Didelotf3645652017-03-30 17:37:07 -0400192 MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelotb5058d72016-05-09 13:22:38 -0400193
Gregory CLEMENTa75961d2017-01-30 20:29:34 +0100194#define MV88E6XXX_FLAGS_FAMILY_6341 \
195 (MV88E6XXX_FLAG_EEE | \
Gregory CLEMENTa75961d2017-01-30 20:29:34 +0100196 MV88E6XXX_FLAG_G1_VTU_FID | \
197 MV88E6XXX_FLAG_GLOBAL2 | \
198 MV88E6XXX_FLAG_G2_INT | \
199 MV88E6XXX_FLAG_G2_POT | \
Andrew Lunnba9b9892017-05-26 01:03:22 +0200200 MV88E6XXX_FLAGS_MULTI_CHIP)
Gregory CLEMENTa75961d2017-01-30 20:29:34 +0100201
Vivien Didelot6d5834a2016-05-09 13:22:40 -0400202#define MV88E6XXX_FLAGS_FAMILY_6351 \
Vivien Didelote606ca32017-03-11 16:12:55 -0500203 (MV88E6XXX_FLAG_G1_VTU_FID | \
Andrew Lunn2bbb33b2016-08-22 16:01:02 +0200204 MV88E6XXX_FLAG_GLOBAL2 | \
Andrew Lunndc30c352016-10-16 19:56:49 +0200205 MV88E6XXX_FLAG_G2_INT | \
Vivien Didelot47395ed2016-07-18 20:45:33 -0400206 MV88E6XXX_FLAG_G2_MGMT_EN_2X | \
207 MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
Vivien Didelot9bda8892016-07-18 20:45:36 -0400208 MV88E6XXX_FLAG_G2_POT | \
Vivien Didelotf3645652017-03-30 17:37:07 -0400209 MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelotb5058d72016-05-09 13:22:38 -0400210
Vivien Didelot6d5834a2016-05-09 13:22:40 -0400211#define MV88E6XXX_FLAGS_FAMILY_6352 \
Andrew Lunn443d5a12016-12-03 04:35:18 +0100212 (MV88E6XXX_FLAG_EEE | \
Vivien Didelot6dc10bb2016-09-29 12:21:55 -0400213 MV88E6XXX_FLAG_G1_VTU_FID | \
Vivien Didelot97299342016-07-18 20:45:30 -0400214 MV88E6XXX_FLAG_GLOBAL2 | \
Andrew Lunndc30c352016-10-16 19:56:49 +0200215 MV88E6XXX_FLAG_G2_INT | \
Vivien Didelot47395ed2016-07-18 20:45:33 -0400216 MV88E6XXX_FLAG_G2_MGMT_EN_2X | \
217 MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
Vivien Didelot9bda8892016-07-18 20:45:36 -0400218 MV88E6XXX_FLAG_G2_POT | \
Andrew Lunnba9b9892017-05-26 01:03:22 +0200219 MV88E6XXX_FLAGS_MULTI_CHIP)
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400220
Andrew Lunn1a3b39e2016-11-21 23:26:57 +0100221#define MV88E6XXX_FLAGS_FAMILY_6390 \
222 (MV88E6XXX_FLAG_EEE | \
223 MV88E6XXX_FLAG_GLOBAL2 | \
Andrew Lunn61303732017-02-09 00:03:43 +0100224 MV88E6XXX_FLAG_G2_INT | \
Vivien Didelotf3645652017-03-30 17:37:07 -0400225 MV88E6XXX_FLAGS_MULTI_CHIP)
Andrew Lunn1a3b39e2016-11-21 23:26:57 +0100226
Andrew Lunnc0e4dad2017-02-09 00:00:43 +0100227struct mv88e6xxx_ops;
228
Vivien Didelotf6271e62016-04-17 13:23:59 -0400229struct mv88e6xxx_info {
Vivien Didelot22356472016-04-17 13:24:00 -0400230 enum mv88e6xxx_family family;
Vivien Didelotf6271e62016-04-17 13:23:59 -0400231 u16 prod_num;
232 const char *name;
Vivien Didelotcd5a2c82016-04-17 13:24:02 -0400233 unsigned int num_databases;
Vivien Didelot009a2b92016-04-17 13:24:01 -0400234 unsigned int num_ports;
Vivien Didelot3cf3c842017-05-01 14:05:10 -0400235 unsigned int max_vid;
Vivien Didelot9dddd472016-06-20 13:14:10 -0400236 unsigned int port_base_addr;
Vivien Didelota935c052016-09-29 12:21:53 -0400237 unsigned int global1_addr;
Vivien Didelotacddbd22016-07-18 20:45:39 -0400238 unsigned int age_time_coeff;
Andrew Lunndc30c352016-10-16 19:56:49 +0200239 unsigned int g1_irqs;
Vivien Didelotf3645652017-03-30 17:37:07 -0400240 bool pvt;
Andrew Lunn443d5a12016-12-03 04:35:18 +0100241 enum dsa_tag_protocol tag_protocol;
Andrew Lunnd6b10232016-09-21 01:40:32 +0200242 unsigned long long flags;
Vivien Didelote606ca32017-03-11 16:12:55 -0500243
244 /* Mask for FromPort and ToPort value of PortVec used in ATU Move
245 * operation. 0 means that the ATU Move operation is not supported.
246 */
247 u8 atu_move_port_mask;
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400248 const struct mv88e6xxx_ops *ops;
Vivien Didelotb9b37712015-10-30 19:39:48 -0400249};
250
Vivien Didelotfd231c82015-08-10 09:09:50 -0400251struct mv88e6xxx_atu_entry {
Vivien Didelotfd231c82015-08-10 09:09:50 -0400252 u8 state;
253 bool trunk;
Vivien Didelot01bd96c2017-03-11 16:12:57 -0500254 u16 portvec;
Vivien Didelotfd231c82015-08-10 09:09:50 -0400255 u8 mac[ETH_ALEN];
256};
257
Vivien Didelotb4e47c02016-09-29 12:21:58 -0400258struct mv88e6xxx_vtu_entry {
Vivien Didelotb8fee952015-08-13 12:52:19 -0400259 u16 vid;
260 u16 fid;
Vivien Didelotb8fee952015-08-13 12:52:19 -0400261 u8 sid;
262 bool valid;
Vivien Didelotbd00e052017-05-01 14:05:11 -0400263 u8 member[DSA_MAX_PORTS];
264 u8 state[DSA_MAX_PORTS];
Vivien Didelotb8fee952015-08-13 12:52:19 -0400265};
266
Vivien Didelotc08026a2016-09-29 12:21:59 -0400267struct mv88e6xxx_bus_ops;
Andrew Lunnfcd25162017-02-09 00:03:42 +0100268struct mv88e6xxx_irq_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -0400269
Andrew Lunndc30c352016-10-16 19:56:49 +0200270struct mv88e6xxx_irq {
271 u16 masked;
272 struct irq_chip chip;
273 struct irq_domain *domain;
274 unsigned int nirqs;
275};
276
Vivien Didelotfad09c72016-06-21 12:28:20 -0400277struct mv88e6xxx_chip {
Vivien Didelotf6271e62016-04-17 13:23:59 -0400278 const struct mv88e6xxx_info *info;
279
Andrew Lunn7543a6d2016-04-13 02:40:40 +0200280 /* The dsa_switch this private structure is related to */
281 struct dsa_switch *ds;
282
Andrew Lunn158bc062016-04-28 21:24:06 -0400283 /* The device this structure is associated to */
284 struct device *dev;
285
Vivien Didelot9f8b3ee2016-06-20 13:14:05 -0400286 /* This mutex protects the access to the switch registers */
287 struct mutex reg_lock;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000288
Andrew Lunna77d43f2016-04-13 02:40:42 +0200289 /* The MII bus and the address on the bus that is used to
290 * communication with the switch
291 */
Vivien Didelotc08026a2016-09-29 12:21:59 -0400292 const struct mv88e6xxx_bus_ops *smi_ops;
Andrew Lunna77d43f2016-04-13 02:40:42 +0200293 struct mii_bus *bus;
294 int sw_addr;
295
Barry Grussling3675c8d2013-01-08 16:05:53 +0000296 /* Handles automatic disabling and re-enabling of the PHY
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000297 * polling unit.
298 */
Vivien Didelotc08026a2016-09-29 12:21:59 -0400299 const struct mv88e6xxx_bus_ops *phy_ops;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000300 struct mutex ppu_mutex;
301 int ppu_disabled;
302 struct work_struct ppu_work;
303 struct timer_list ppu_timer;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000304
Barry Grussling3675c8d2013-01-08 16:05:53 +0000305 /* This mutex serialises access to the statistics unit.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000306 * Hold this mutex over snapshot + dump sequences.
307 */
308 struct mutex stats_mutex;
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000309
Andrew Lunn52638f72016-05-10 23:27:22 +0200310 /* A switch may have a GPIO line tied to its reset pin. Parse
311 * this from the device tree, and use it before performing
312 * switch soft reset.
313 */
314 struct gpio_desc *reset;
Andrew Lunnf8cd8752016-05-10 23:27:25 +0200315
316 /* set to size of eeprom if supported by the switch */
317 int eeprom_len;
Andrew Lunnb516d452016-06-04 21:17:06 +0200318
Andrew Lunna3c53be52017-01-24 14:53:50 +0100319 /* List of mdio busses */
320 struct list_head mdios;
Andrew Lunndc30c352016-10-16 19:56:49 +0200321
322 /* There can be two interrupt controllers, which are chained
323 * off a GPIO as interrupt source
324 */
325 struct mv88e6xxx_irq g1_irq;
326 struct mv88e6xxx_irq g2_irq;
327 int irq;
Andrew Lunn8e757eb2016-11-20 20:14:18 +0100328 int device_irq;
Andrew Lunnfcd25162017-02-09 00:03:42 +0100329 int watchdog_irq;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000330};
331
Vivien Didelotc08026a2016-09-29 12:21:59 -0400332struct mv88e6xxx_bus_ops {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400333 int (*read)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
334 int (*write)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400335};
336
Andrew Lunn0dd12d52017-01-24 14:53:49 +0100337struct mv88e6xxx_mdio_bus {
Andrew Lunna3c53be52017-01-24 14:53:50 +0100338 struct mii_bus *bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +0100339 struct mv88e6xxx_chip *chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +0100340 struct list_head list;
341 bool external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +0100342};
343
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400344struct mv88e6xxx_ops {
Vivien Didelotcd8da8b2017-06-19 10:55:36 -0400345 /* Ingress Rate Limit unit (IRL) operations */
346 int (*irl_init_all)(struct mv88e6xxx_chip *chip, int port);
347
Vivien Didelotee4dc2e72016-09-29 12:22:02 -0400348 int (*get_eeprom)(struct mv88e6xxx_chip *chip,
349 struct ethtool_eeprom *eeprom, u8 *data);
350 int (*set_eeprom)(struct mv88e6xxx_chip *chip,
351 struct ethtool_eeprom *eeprom, u8 *data);
352
Vivien Didelotb073d4e2016-09-29 12:22:01 -0400353 int (*set_switch_mac)(struct mv88e6xxx_chip *chip, u8 *addr);
354
Andrew Lunnee26a222017-01-24 14:53:48 +0100355 int (*phy_read)(struct mv88e6xxx_chip *chip,
356 struct mii_bus *bus,
357 int addr, int reg, u16 *val);
358 int (*phy_write)(struct mv88e6xxx_chip *chip,
359 struct mii_bus *bus,
360 int addr, int reg, u16 val);
Vivien Didelot08ef7f12016-11-04 03:23:32 +0100361
Vivien Didelota199d8b2016-12-05 17:30:28 -0500362 /* PHY Polling Unit (PPU) operations */
363 int (*ppu_enable)(struct mv88e6xxx_chip *chip);
364 int (*ppu_disable)(struct mv88e6xxx_chip *chip);
365
Vivien Didelot17e708b2016-12-05 17:30:27 -0500366 /* Switch Software Reset */
367 int (*reset)(struct mv88e6xxx_chip *chip);
368
Vivien Didelota0a0f622016-11-04 03:23:34 +0100369 /* RGMII Receive/Transmit Timing Control
370 * Add delay on PHY_INTERFACE_MODE_RGMII_*ID, no delay otherwise.
371 */
372 int (*port_set_rgmii_delay)(struct mv88e6xxx_chip *chip, int port,
373 phy_interface_t mode);
374
Vivien Didelot08ef7f12016-11-04 03:23:32 +0100375#define LINK_FORCED_DOWN 0
376#define LINK_FORCED_UP 1
377#define LINK_UNFORCED -2
378
379 /* Port's MAC link state
380 * Use LINK_FORCED_UP or LINK_FORCED_DOWN to force link up or down,
381 * or LINK_UNFORCED for normal link detection.
382 */
383 int (*port_set_link)(struct mv88e6xxx_chip *chip, int port, int link);
Vivien Didelot7f1ae072016-11-04 03:23:33 +0100384
385#define DUPLEX_UNFORCED -2
386
387 /* Port's MAC duplex mode
388 *
389 * Use DUPLEX_HALF or DUPLEX_FULL to force half or full duplex,
390 * or DUPLEX_UNFORCED for normal duplex detection.
391 */
392 int (*port_set_duplex)(struct mv88e6xxx_chip *chip, int port, int dup);
Vivien Didelot96a2b402016-11-04 03:23:35 +0100393
394#define SPEED_MAX INT_MAX
395#define SPEED_UNFORCED -2
396
397 /* Port's MAC speed (in Mbps)
398 *
399 * Depending on the chip, 10, 100, 200, 1000, 2500, 10000 are valid.
400 * Use SPEED_UNFORCED for normal detection, SPEED_MAX for max value.
401 */
402 int (*port_set_speed)(struct mv88e6xxx_chip *chip, int port, int speed);
Andrew Lunna605a0f2016-11-21 23:26:58 +0100403
Andrew Lunnef0a7312016-12-03 04:35:16 +0100404 int (*port_tag_remap)(struct mv88e6xxx_chip *chip, int port);
405
Andrew Lunn56995cb2016-12-03 04:35:19 +0100406 int (*port_set_frame_mode)(struct mv88e6xxx_chip *chip, int port,
407 enum mv88e6xxx_frame_mode mode);
Vivien Didelot601aeed2017-03-11 16:13:00 -0500408 int (*port_set_egress_floods)(struct mv88e6xxx_chip *chip, int port,
409 bool unicast, bool multicast);
Andrew Lunn56995cb2016-12-03 04:35:19 +0100410 int (*port_set_ether_type)(struct mv88e6xxx_chip *chip, int port,
411 u16 etype);
Vivien Didelotcd782652017-06-08 18:34:13 -0400412 int (*port_set_jumbo_size)(struct mv88e6xxx_chip *chip, int port,
413 size_t size);
Andrew Lunn56995cb2016-12-03 04:35:19 +0100414
Andrew Lunnef70b112016-12-03 04:45:18 +0100415 int (*port_egress_rate_limiting)(struct mv88e6xxx_chip *chip, int port);
Vivien Didelot08984322017-06-08 18:34:12 -0400416 int (*port_pause_limit)(struct mv88e6xxx_chip *chip, int port, u8 in,
417 u8 out);
Vivien Didelotc8c94892017-03-11 16:13:01 -0500418 int (*port_disable_learn_limit)(struct mv88e6xxx_chip *chip, int port);
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -0500419 int (*port_disable_pri_override)(struct mv88e6xxx_chip *chip, int port);
Andrew Lunnef70b112016-12-03 04:45:18 +0100420
Andrew Lunnf39908d2017-02-04 20:02:50 +0100421 /* CMODE control what PHY mode the MAC will use, eg. SGMII, RGMII, etc.
422 * Some chips allow this to be configured on specific ports.
423 */
424 int (*port_set_cmode)(struct mv88e6xxx_chip *chip, int port,
425 phy_interface_t mode);
426
Andrew Lunna23b2962017-02-04 20:15:28 +0100427 /* Some devices have a per port register indicating what is
428 * the upstream port this port should forward to.
429 */
430 int (*port_set_upstream_port)(struct mv88e6xxx_chip *chip, int port,
431 int upstream_port);
432
Andrew Lunna605a0f2016-11-21 23:26:58 +0100433 /* Snapshot the statistics for a port. The statistics can then
434 * be read back a leisure but still with a consistent view.
435 */
436 int (*stats_snapshot)(struct mv88e6xxx_chip *chip, int port);
Andrew Lunnde2273872016-11-21 23:27:01 +0100437
438 /* Set the histogram mode for statistics, when the control registers
439 * are separated out of the STATS_OP register.
440 */
441 int (*stats_set_histogram)(struct mv88e6xxx_chip *chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100442
443 /* Return the number of strings describing statistics */
444 int (*stats_get_sset_count)(struct mv88e6xxx_chip *chip);
445 void (*stats_get_strings)(struct mv88e6xxx_chip *chip, uint8_t *data);
Andrew Lunn052f9472016-11-21 23:27:03 +0100446 void (*stats_get_stats)(struct mv88e6xxx_chip *chip, int port,
447 uint64_t *data);
Vivien Didelotfa8d1172017-06-08 18:34:11 -0400448 int (*set_cpu_port)(struct mv88e6xxx_chip *chip, int port);
449 int (*set_egress_port)(struct mv88e6xxx_chip *chip, int port);
Andrew Lunnfcd25162017-02-09 00:03:42 +0100450 const struct mv88e6xxx_irq_ops *watchdog_ops;
Andrew Lunn6e55f692016-12-03 04:45:16 +0100451
452 /* Can be either in g1 or g2, so don't use a prefix */
453 int (*mgmt_rsvd2cpu)(struct mv88e6xxx_chip *chip);
Vivien Didelotf1394b72017-05-01 14:05:22 -0400454
Andrew Lunn6d917822017-05-26 01:03:21 +0200455 /* Power on/off a SERDES interface */
456 int (*serdes_power)(struct mv88e6xxx_chip *chip, int port, bool on);
457
Vivien Didelotf1394b72017-05-01 14:05:22 -0400458 /* VLAN Translation Unit operations */
459 int (*vtu_getnext)(struct mv88e6xxx_chip *chip,
460 struct mv88e6xxx_vtu_entry *entry);
Vivien Didelot0ad5daf2017-05-01 14:05:23 -0400461 int (*vtu_loadpurge)(struct mv88e6xxx_chip *chip,
462 struct mv88e6xxx_vtu_entry *entry);
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400463};
464
Andrew Lunnfcd25162017-02-09 00:03:42 +0100465struct mv88e6xxx_irq_ops {
466 /* Action to be performed when the interrupt happens */
467 int (*irq_action)(struct mv88e6xxx_chip *chip, int irq);
468 /* Setup the hardware to generate the interrupt */
469 int (*irq_setup)(struct mv88e6xxx_chip *chip);
470 /* Reset the hardware to stop generating the interrupt */
471 void (*irq_free)(struct mv88e6xxx_chip *chip);
472};
473
Andrew Lunndfafe442016-11-21 23:27:02 +0100474#define STATS_TYPE_PORT BIT(0)
475#define STATS_TYPE_BANK0 BIT(1)
476#define STATS_TYPE_BANK1 BIT(2)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100477
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000478struct mv88e6xxx_hw_stat {
479 char string[ETH_GSTRING_LEN];
480 int sizeof_stat;
481 int reg;
Andrew Lunndfafe442016-11-21 23:27:02 +0100482 int type;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000483};
484
Vivien Didelotfad09c72016-06-21 12:28:20 -0400485static inline bool mv88e6xxx_has(struct mv88e6xxx_chip *chip,
Vivien Didelotb5058d72016-05-09 13:22:38 -0400486 unsigned long flags)
487{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400488 return (chip->info->flags & flags) == flags;
Vivien Didelotb5058d72016-05-09 13:22:38 -0400489}
490
Vivien Didelotf3645652017-03-30 17:37:07 -0400491static inline bool mv88e6xxx_has_pvt(struct mv88e6xxx_chip *chip)
492{
493 return chip->info->pvt;
494}
495
Vivien Didelotde333762016-09-29 12:21:56 -0400496static inline unsigned int mv88e6xxx_num_databases(struct mv88e6xxx_chip *chip)
497{
498 return chip->info->num_databases;
499}
500
Vivien Didelot370b4ff2016-09-29 12:21:57 -0400501static inline unsigned int mv88e6xxx_num_ports(struct mv88e6xxx_chip *chip)
502{
503 return chip->info->num_ports;
504}
505
Vivien Didelot4d294af2017-03-11 16:12:47 -0500506static inline u16 mv88e6xxx_port_mask(struct mv88e6xxx_chip *chip)
507{
508 return GENMASK(mv88e6xxx_num_ports(chip) - 1, 0);
509}
510
Vivien Didelotec561272016-09-02 14:45:33 -0400511int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
512int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
513int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg,
514 u16 update);
515int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask);
Andrew Lunn10fa5bf2017-05-26 01:03:20 +0200516struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip);
Vivien Didelot4d5f2ba72017-06-02 17:06:15 -0400517
518#endif /* _MV88E6XXX_CHIP_H */