xref: /openbmc/linux/drivers/net/dsa/mv88e6xxx/serdes.h (revision 7583028d)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Marvell 88E6xxx SERDES manipulation, via SMI bus
4  *
5  * Copyright (c) 2008 Marvell Semiconductor
6  *
7  * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
8  */
9 
10 #ifndef _MV88E6XXX_SERDES_H
11 #define _MV88E6XXX_SERDES_H
12 
13 #include "chip.h"
14 
15 #define MV88E6352_ADDR_SERDES		0x0f
16 #define MV88E6352_SERDES_PAGE_FIBER	0x01
17 #define MV88E6352_SERDES_IRQ		0x0b
18 #define MV88E6352_SERDES_INT_ENABLE	0x12
19 #define MV88E6352_SERDES_INT_SPEED_CHANGE	BIT(14)
20 #define MV88E6352_SERDES_INT_DUPLEX_CHANGE	BIT(13)
21 #define MV88E6352_SERDES_INT_PAGE_RX		BIT(12)
22 #define MV88E6352_SERDES_INT_AN_COMPLETE	BIT(11)
23 #define MV88E6352_SERDES_INT_LINK_CHANGE	BIT(10)
24 #define MV88E6352_SERDES_INT_SYMBOL_ERROR	BIT(9)
25 #define MV88E6352_SERDES_INT_FALSE_CARRIER	BIT(8)
26 #define MV88E6352_SERDES_INT_FIFO_OVER_UNDER	BIT(7)
27 #define MV88E6352_SERDES_INT_FIBRE_ENERGY	BIT(4)
28 #define MV88E6352_SERDES_INT_STATUS	0x13
29 
30 #define MV88E6352_SERDES_SPEC_CTRL2	0x1a
31 #define MV88E6352_SERDES_OUT_AMP_MASK		0x0007
32 
33 #define MV88E6341_PORT5_LANE		0x15
34 
35 #define MV88E6390_PORT9_LANE0		0x09
36 #define MV88E6390_PORT9_LANE1		0x12
37 #define MV88E6390_PORT9_LANE2		0x13
38 #define MV88E6390_PORT9_LANE3		0x14
39 #define MV88E6390_PORT10_LANE0		0x0a
40 #define MV88E6390_PORT10_LANE1		0x15
41 #define MV88E6390_PORT10_LANE2		0x16
42 #define MV88E6390_PORT10_LANE3		0x17
43 
44 /* 10GBASE-R and 10GBASE-X4/X2 */
45 #define MV88E6390_10G_CTRL1		(0x1000 + MDIO_CTRL1)
46 #define MV88E6390_10G_STAT1		(0x1000 + MDIO_STAT1)
47 #define MV88E6393X_10G_INT_ENABLE	0x9000
48 #define MV88E6393X_10G_INT_LINK_CHANGE	BIT(2)
49 #define MV88E6393X_10G_INT_STATUS	0x9001
50 
51 /* USXGMII */
52 #define MV88E6390_USXGMII_LP_STATUS       0xf0a2
53 #define MV88E6390_USXGMII_PHY_STATUS      0xf0a6
54 
55 /* 1000BASE-X and SGMII */
56 #define MV88E6390_SGMII_BMCR		(0x2000 + MII_BMCR)
57 #define MV88E6390_SGMII_BMSR		(0x2000 + MII_BMSR)
58 #define MV88E6390_SGMII_ADVERTISE	(0x2000 + MII_ADVERTISE)
59 #define MV88E6390_SGMII_LPA		(0x2000 + MII_LPA)
60 #define MV88E6390_SGMII_INT_ENABLE	0xa001
61 #define MV88E6390_SGMII_INT_SPEED_CHANGE	BIT(14)
62 #define MV88E6390_SGMII_INT_DUPLEX_CHANGE	BIT(13)
63 #define MV88E6390_SGMII_INT_PAGE_RX		BIT(12)
64 #define MV88E6390_SGMII_INT_AN_COMPLETE		BIT(11)
65 #define MV88E6390_SGMII_INT_LINK_DOWN		BIT(10)
66 #define MV88E6390_SGMII_INT_LINK_UP		BIT(9)
67 #define MV88E6390_SGMII_INT_SYMBOL_ERROR	BIT(8)
68 #define MV88E6390_SGMII_INT_FALSE_CARRIER	BIT(7)
69 #define MV88E6390_SGMII_INT_STATUS	0xa002
70 #define MV88E6390_SGMII_PHY_STATUS	0xa003
71 #define MV88E6390_SGMII_PHY_STATUS_SPEED_MASK	GENMASK(15, 14)
72 #define MV88E6390_SGMII_PHY_STATUS_SPEED_1000	0x8000
73 #define MV88E6390_SGMII_PHY_STATUS_SPEED_100	0x4000
74 #define MV88E6390_SGMII_PHY_STATUS_SPEED_10	0x0000
75 #define MV88E6390_SGMII_PHY_STATUS_DUPLEX_FULL	BIT(13)
76 #define MV88E6390_SGMII_PHY_STATUS_SPD_DPL_VALID BIT(11)
77 #define MV88E6390_SGMII_PHY_STATUS_LINK		BIT(10)
78 #define MV88E6390_SGMII_PHY_STATUS_TX_PAUSE	BIT(3)
79 #define MV88E6390_SGMII_PHY_STATUS_RX_PAUSE	BIT(2)
80 
81 /* Packet generator pad packet checker */
82 #define MV88E6390_PG_CONTROL		0xf010
83 #define MV88E6390_PG_CONTROL_ENABLE_PC		BIT(0)
84 
85 #define MV88E6393X_PORT0_LANE			0x00
86 #define MV88E6393X_PORT9_LANE			0x09
87 #define MV88E6393X_PORT10_LANE			0x0a
88 
89 /* Port Operational Configuration */
90 #define MV88E6393X_SERDES_POC			0xf002
91 #define MV88E6393X_SERDES_POC_PCS_1000BASEX	0x0000
92 #define MV88E6393X_SERDES_POC_PCS_2500BASEX	0x0001
93 #define MV88E6393X_SERDES_POC_PCS_SGMII_PHY	0x0002
94 #define MV88E6393X_SERDES_POC_PCS_SGMII_MAC	0x0003
95 #define MV88E6393X_SERDES_POC_PCS_5GBASER	0x0004
96 #define MV88E6393X_SERDES_POC_PCS_10GBASER	0x0005
97 #define MV88E6393X_SERDES_POC_PCS_USXGMII_PHY	0x0006
98 #define MV88E6393X_SERDES_POC_PCS_USXGMII_MAC	0x0007
99 #define MV88E6393X_SERDES_POC_PCS_MASK		0x0007
100 #define MV88E6393X_SERDES_POC_RESET		BIT(15)
101 #define MV88E6393X_SERDES_POC_PDOWN		BIT(5)
102 #define MV88E6393X_SERDES_POC_AN		BIT(3)
103 #define MV88E6393X_SERDES_CTRL1			0xf003
104 #define MV88E6393X_SERDES_CTRL1_TX_PDOWN	BIT(9)
105 #define MV88E6393X_SERDES_CTRL1_RX_PDOWN	BIT(8)
106 
107 #define MV88E6393X_ERRATA_4_8_REG		0xF074
108 #define MV88E6393X_ERRATA_4_8_BIT		BIT(14)
109 
110 int mv88e6185_serdes_get_lane(struct mv88e6xxx_chip *chip, int port);
111 int mv88e6341_serdes_get_lane(struct mv88e6xxx_chip *chip, int port);
112 int mv88e6352_serdes_get_lane(struct mv88e6xxx_chip *chip, int port);
113 int mv88e6390_serdes_get_lane(struct mv88e6xxx_chip *chip, int port);
114 int mv88e6390x_serdes_get_lane(struct mv88e6xxx_chip *chip, int port);
115 int mv88e6393x_serdes_get_lane(struct mv88e6xxx_chip *chip, int port);
116 int mv88e6352_serdes_pcs_config(struct mv88e6xxx_chip *chip, int port,
117 				int lane, unsigned int mode,
118 				phy_interface_t interface,
119 				const unsigned long *advertise);
120 int mv88e6390_serdes_pcs_config(struct mv88e6xxx_chip *chip, int port,
121 				int lane, unsigned int mode,
122 				phy_interface_t interface,
123 				const unsigned long *advertise);
124 int mv88e6185_serdes_pcs_get_state(struct mv88e6xxx_chip *chip, int port,
125 				   int lane, struct phylink_link_state *state);
126 int mv88e6352_serdes_pcs_get_state(struct mv88e6xxx_chip *chip, int port,
127 				   int lane, struct phylink_link_state *state);
128 int mv88e6390_serdes_pcs_get_state(struct mv88e6xxx_chip *chip, int port,
129 				   int lane, struct phylink_link_state *state);
130 int mv88e6393x_serdes_pcs_get_state(struct mv88e6xxx_chip *chip, int port,
131 				    int lane, struct phylink_link_state *state);
132 int mv88e6352_serdes_pcs_an_restart(struct mv88e6xxx_chip *chip, int port,
133 				    int lane);
134 int mv88e6390_serdes_pcs_an_restart(struct mv88e6xxx_chip *chip, int port,
135 				    int lane);
136 int mv88e6352_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port,
137 				 int lane, int speed, int duplex);
138 int mv88e6390_serdes_pcs_link_up(struct mv88e6xxx_chip *chip, int port,
139 				 int lane, int speed, int duplex);
140 unsigned int mv88e6352_serdes_irq_mapping(struct mv88e6xxx_chip *chip,
141 					  int port);
142 unsigned int mv88e6390_serdes_irq_mapping(struct mv88e6xxx_chip *chip,
143 					  int port);
144 int mv88e6185_serdes_power(struct mv88e6xxx_chip *chip, int port, int lane,
145 			   bool up);
146 int mv88e6352_serdes_power(struct mv88e6xxx_chip *chip, int port, int lane,
147 			   bool on);
148 int mv88e6390_serdes_power(struct mv88e6xxx_chip *chip, int port, int lane,
149 			   bool on);
150 int mv88e6393x_serdes_power(struct mv88e6xxx_chip *chip, int port, int lane,
151 			    bool on);
152 int mv88e6393x_serdes_setup_errata(struct mv88e6xxx_chip *chip);
153 int mv88e6097_serdes_irq_enable(struct mv88e6xxx_chip *chip, int port, int lane,
154 				bool enable);
155 int mv88e6352_serdes_irq_enable(struct mv88e6xxx_chip *chip, int port, int lane,
156 				bool enable);
157 int mv88e6390_serdes_irq_enable(struct mv88e6xxx_chip *chip, int port, int lane,
158 				bool enable);
159 int mv88e6393x_serdes_irq_enable(struct mv88e6xxx_chip *chip, int port,
160 				 int lane, bool enable);
161 irqreturn_t mv88e6097_serdes_irq_status(struct mv88e6xxx_chip *chip, int port,
162 					int lane);
163 irqreturn_t mv88e6352_serdes_irq_status(struct mv88e6xxx_chip *chip, int port,
164 					int lane);
165 irqreturn_t mv88e6390_serdes_irq_status(struct mv88e6xxx_chip *chip, int port,
166 					int lane);
167 irqreturn_t mv88e6393x_serdes_irq_status(struct mv88e6xxx_chip *chip, int port,
168 					 int lane);
169 int mv88e6352_serdes_get_sset_count(struct mv88e6xxx_chip *chip, int port);
170 int mv88e6352_serdes_get_strings(struct mv88e6xxx_chip *chip,
171 				 int port, uint8_t *data);
172 int mv88e6352_serdes_get_stats(struct mv88e6xxx_chip *chip, int port,
173 			       uint64_t *data);
174 int mv88e6390_serdes_get_sset_count(struct mv88e6xxx_chip *chip, int port);
175 int mv88e6390_serdes_get_strings(struct mv88e6xxx_chip *chip,
176 				 int port, uint8_t *data);
177 int mv88e6390_serdes_get_stats(struct mv88e6xxx_chip *chip, int port,
178 			       uint64_t *data);
179 
180 int mv88e6352_serdes_get_regs_len(struct mv88e6xxx_chip *chip, int port);
181 void mv88e6352_serdes_get_regs(struct mv88e6xxx_chip *chip, int port, void *_p);
182 int mv88e6390_serdes_get_regs_len(struct mv88e6xxx_chip *chip, int port);
183 void mv88e6390_serdes_get_regs(struct mv88e6xxx_chip *chip, int port, void *_p);
184 
185 int mv88e6352_serdes_set_tx_amplitude(struct mv88e6xxx_chip *chip, int port,
186 				      int val);
187 
188 /* Return the (first) SERDES lane address a port is using, -errno otherwise. */
189 static inline int mv88e6xxx_serdes_get_lane(struct mv88e6xxx_chip *chip,
190 					    int port)
191 {
192 	if (!chip->info->ops->serdes_get_lane)
193 		return -EOPNOTSUPP;
194 
195 	return chip->info->ops->serdes_get_lane(chip, port);
196 }
197 
198 static inline int mv88e6xxx_serdes_power_up(struct mv88e6xxx_chip *chip,
199 					    int port, int lane)
200 {
201 	if (!chip->info->ops->serdes_power)
202 		return -EOPNOTSUPP;
203 
204 	return chip->info->ops->serdes_power(chip, port, lane, true);
205 }
206 
207 static inline int mv88e6xxx_serdes_power_down(struct mv88e6xxx_chip *chip,
208 					      int port, int lane)
209 {
210 	if (!chip->info->ops->serdes_power)
211 		return -EOPNOTSUPP;
212 
213 	return chip->info->ops->serdes_power(chip, port, lane, false);
214 }
215 
216 static inline unsigned int
217 mv88e6xxx_serdes_irq_mapping(struct mv88e6xxx_chip *chip, int port)
218 {
219 	if (!chip->info->ops->serdes_irq_mapping)
220 		return 0;
221 
222 	return chip->info->ops->serdes_irq_mapping(chip, port);
223 }
224 
225 static inline int mv88e6xxx_serdes_irq_enable(struct mv88e6xxx_chip *chip,
226 					      int port, int lane)
227 {
228 	if (!chip->info->ops->serdes_irq_enable)
229 		return -EOPNOTSUPP;
230 
231 	return chip->info->ops->serdes_irq_enable(chip, port, lane, true);
232 }
233 
234 static inline int mv88e6xxx_serdes_irq_disable(struct mv88e6xxx_chip *chip,
235 					       int port, int lane)
236 {
237 	if (!chip->info->ops->serdes_irq_enable)
238 		return -EOPNOTSUPP;
239 
240 	return chip->info->ops->serdes_irq_enable(chip, port, lane, false);
241 }
242 
243 static inline irqreturn_t
244 mv88e6xxx_serdes_irq_status(struct mv88e6xxx_chip *chip, int port, int lane)
245 {
246 	if (!chip->info->ops->serdes_irq_status)
247 		return IRQ_NONE;
248 
249 	return chip->info->ops->serdes_irq_status(chip, port, lane);
250 }
251 
252 #endif
253