blob: b6089fe7237827a9f10ddea5123bcc3e47bd61c2 [file] [log] [blame]
Russell Kingce0aa272017-07-25 15:03:18 +01001#ifndef LINUX_SFP_H
2#define LINUX_SFP_H
3
4#include <linux/phy.h>
5
Russell King0a6fcd3f2017-12-01 10:24:53 +00006struct sfp_eeprom_base {
Russell Kingce0aa272017-07-25 15:03:18 +01007 u8 phys_id;
8 u8 phys_ext_id;
9 u8 connector;
10#if defined __BIG_ENDIAN_BITFIELD
11 u8 e10g_base_er:1;
12 u8 e10g_base_lrm:1;
13 u8 e10g_base_lr:1;
14 u8 e10g_base_sr:1;
15 u8 if_1x_sx:1;
16 u8 if_1x_lx:1;
17 u8 if_1x_copper_active:1;
18 u8 if_1x_copper_passive:1;
19
20 u8 escon_mmf_1310_led:1;
21 u8 escon_smf_1310_laser:1;
22 u8 sonet_oc192_short_reach:1;
23 u8 sonet_reach_bit1:1;
24 u8 sonet_reach_bit2:1;
25 u8 sonet_oc48_long_reach:1;
26 u8 sonet_oc48_intermediate_reach:1;
27 u8 sonet_oc48_short_reach:1;
28
29 u8 unallocated_5_7:1;
30 u8 sonet_oc12_smf_long_reach:1;
31 u8 sonet_oc12_smf_intermediate_reach:1;
32 u8 sonet_oc12_short_reach:1;
33 u8 unallocated_5_3:1;
34 u8 sonet_oc3_smf_long_reach:1;
35 u8 sonet_oc3_smf_intermediate_reach:1;
36 u8 sonet_oc3_short_reach:1;
37
38 u8 e_base_px:1;
39 u8 e_base_bx10:1;
40 u8 e100_base_fx:1;
41 u8 e100_base_lx:1;
42 u8 e1000_base_t:1;
43 u8 e1000_base_cx:1;
44 u8 e1000_base_lx:1;
45 u8 e1000_base_sx:1;
46
47 u8 fc_ll_v:1;
48 u8 fc_ll_s:1;
49 u8 fc_ll_i:1;
50 u8 fc_ll_l:1;
51 u8 fc_ll_m:1;
52 u8 fc_tech_sa:1;
53 u8 fc_tech_lc:1;
54 u8 fc_tech_electrical_inter_enclosure:1;
55
56 u8 fc_tech_electrical_intra_enclosure:1;
57 u8 fc_tech_sn:1;
58 u8 fc_tech_sl:1;
59 u8 fc_tech_ll:1;
60 u8 sfp_ct_active:1;
61 u8 sfp_ct_passive:1;
62 u8 unallocated_8_1:1;
63 u8 unallocated_8_0:1;
64
65 u8 fc_media_tw:1;
66 u8 fc_media_tp:1;
67 u8 fc_media_mi:1;
68 u8 fc_media_tv:1;
69 u8 fc_media_m6:1;
70 u8 fc_media_m5:1;
71 u8 unallocated_9_1:1;
72 u8 fc_media_sm:1;
73
74 u8 fc_speed_1200:1;
75 u8 fc_speed_800:1;
76 u8 fc_speed_1600:1;
77 u8 fc_speed_400:1;
78 u8 fc_speed_3200:1;
79 u8 fc_speed_200:1;
80 u8 unallocated_10_1:1;
81 u8 fc_speed_100:1;
82#elif defined __LITTLE_ENDIAN_BITFIELD
83 u8 if_1x_copper_passive:1;
84 u8 if_1x_copper_active:1;
85 u8 if_1x_lx:1;
86 u8 if_1x_sx:1;
87 u8 e10g_base_sr:1;
88 u8 e10g_base_lr:1;
89 u8 e10g_base_lrm:1;
90 u8 e10g_base_er:1;
91
92 u8 sonet_oc3_short_reach:1;
93 u8 sonet_oc3_smf_intermediate_reach:1;
94 u8 sonet_oc3_smf_long_reach:1;
95 u8 unallocated_5_3:1;
96 u8 sonet_oc12_short_reach:1;
97 u8 sonet_oc12_smf_intermediate_reach:1;
98 u8 sonet_oc12_smf_long_reach:1;
99 u8 unallocated_5_7:1;
100
101 u8 sonet_oc48_short_reach:1;
102 u8 sonet_oc48_intermediate_reach:1;
103 u8 sonet_oc48_long_reach:1;
104 u8 sonet_reach_bit2:1;
105 u8 sonet_reach_bit1:1;
106 u8 sonet_oc192_short_reach:1;
107 u8 escon_smf_1310_laser:1;
108 u8 escon_mmf_1310_led:1;
109
110 u8 e1000_base_sx:1;
111 u8 e1000_base_lx:1;
112 u8 e1000_base_cx:1;
113 u8 e1000_base_t:1;
114 u8 e100_base_lx:1;
115 u8 e100_base_fx:1;
116 u8 e_base_bx10:1;
117 u8 e_base_px:1;
118
119 u8 fc_tech_electrical_inter_enclosure:1;
120 u8 fc_tech_lc:1;
121 u8 fc_tech_sa:1;
122 u8 fc_ll_m:1;
123 u8 fc_ll_l:1;
124 u8 fc_ll_i:1;
125 u8 fc_ll_s:1;
126 u8 fc_ll_v:1;
127
128 u8 unallocated_8_0:1;
129 u8 unallocated_8_1:1;
130 u8 sfp_ct_passive:1;
131 u8 sfp_ct_active:1;
132 u8 fc_tech_ll:1;
133 u8 fc_tech_sl:1;
134 u8 fc_tech_sn:1;
135 u8 fc_tech_electrical_intra_enclosure:1;
136
137 u8 fc_media_sm:1;
138 u8 unallocated_9_1:1;
139 u8 fc_media_m5:1;
140 u8 fc_media_m6:1;
141 u8 fc_media_tv:1;
142 u8 fc_media_mi:1;
143 u8 fc_media_tp:1;
144 u8 fc_media_tw:1;
145
146 u8 fc_speed_100:1;
147 u8 unallocated_10_1:1;
148 u8 fc_speed_200:1;
149 u8 fc_speed_3200:1;
150 u8 fc_speed_400:1;
151 u8 fc_speed_1600:1;
152 u8 fc_speed_800:1;
153 u8 fc_speed_1200:1;
154#else
155#error Unknown Endian
156#endif
157 u8 encoding;
158 u8 br_nominal;
159 u8 rate_id;
160 u8 link_len[6];
161 char vendor_name[16];
162 u8 extended_cc;
163 char vendor_oui[3];
164 char vendor_pn[16];
165 char vendor_rev[4];
166 union {
167 __be16 optical_wavelength;
168 u8 cable_spec;
Russell King0a6fcd3f2017-12-01 10:24:53 +0000169 } __packed;
Russell Kingce0aa272017-07-25 15:03:18 +0100170 u8 reserved62;
171 u8 cc_base;
Russell King0a6fcd3f2017-12-01 10:24:53 +0000172} __packed;
Russell Kingce0aa272017-07-25 15:03:18 +0100173
Russell King0a6fcd3f2017-12-01 10:24:53 +0000174struct sfp_eeprom_ext {
Russell Kingce0aa272017-07-25 15:03:18 +0100175 __be16 options;
176 u8 br_max;
177 u8 br_min;
178 char vendor_sn[16];
179 char datecode[8];
180 u8 diagmon;
181 u8 enhopts;
182 u8 sff8472_compliance;
183 u8 cc_ext;
Russell King0a6fcd3f2017-12-01 10:24:53 +0000184} __packed;
Russell Kingce0aa272017-07-25 15:03:18 +0100185
Russell King0a6fcd3f2017-12-01 10:24:53 +0000186/**
187 * struct sfp_eeprom_id - raw SFP module identification information
188 * @base: base SFP module identification structure
189 * @ext: extended SFP module identification structure
190 *
191 * See the SFF-8472 specification and related documents for the definition
192 * of these structure members. This can be obtained from
193 * ftp://ftp.seagate.com/sff
194 */
195struct sfp_eeprom_id {
Russell Kingce0aa272017-07-25 15:03:18 +0100196 struct sfp_eeprom_base base;
197 struct sfp_eeprom_ext ext;
Russell King0a6fcd3f2017-12-01 10:24:53 +0000198} __packed;
Russell Kingce0aa272017-07-25 15:03:18 +0100199
200/* SFP EEPROM registers */
201enum {
202 SFP_PHYS_ID = 0x00,
203 SFP_PHYS_EXT_ID = 0x01,
204 SFP_CONNECTOR = 0x02,
205 SFP_COMPLIANCE = 0x03,
206 SFP_ENCODING = 0x0b,
207 SFP_BR_NOMINAL = 0x0c,
208 SFP_RATE_ID = 0x0d,
209 SFP_LINK_LEN_SM_KM = 0x0e,
210 SFP_LINK_LEN_SM_100M = 0x0f,
211 SFP_LINK_LEN_50UM_OM2_10M = 0x10,
212 SFP_LINK_LEN_62_5UM_OM1_10M = 0x11,
213 SFP_LINK_LEN_COPPER_1M = 0x12,
214 SFP_LINK_LEN_50UM_OM4_10M = 0x12,
215 SFP_LINK_LEN_50UM_OM3_10M = 0x13,
216 SFP_VENDOR_NAME = 0x14,
217 SFP_VENDOR_OUI = 0x25,
218 SFP_VENDOR_PN = 0x28,
219 SFP_VENDOR_REV = 0x38,
220 SFP_OPTICAL_WAVELENGTH_MSB = 0x3c,
221 SFP_OPTICAL_WAVELENGTH_LSB = 0x3d,
222 SFP_CABLE_SPEC = 0x3c,
223 SFP_CC_BASE = 0x3f,
224 SFP_OPTIONS = 0x40, /* 2 bytes, MSB, LSB */
225 SFP_BR_MAX = 0x42,
226 SFP_BR_MIN = 0x43,
227 SFP_VENDOR_SN = 0x44,
228 SFP_DATECODE = 0x54,
229 SFP_DIAGMON = 0x5c,
230 SFP_ENHOPTS = 0x5d,
231 SFP_SFF8472_COMPLIANCE = 0x5e,
232 SFP_CC_EXT = 0x5f,
233
234 SFP_PHYS_ID_SFP = 0x03,
235 SFP_PHYS_EXT_ID_SFP = 0x04,
236 SFP_CONNECTOR_UNSPEC = 0x00,
237 /* codes 01-05 not supportable on SFP, but some modules have single SC */
238 SFP_CONNECTOR_SC = 0x01,
239 SFP_CONNECTOR_FIBERJACK = 0x06,
240 SFP_CONNECTOR_LC = 0x07,
241 SFP_CONNECTOR_MT_RJ = 0x08,
242 SFP_CONNECTOR_MU = 0x09,
243 SFP_CONNECTOR_SG = 0x0a,
244 SFP_CONNECTOR_OPTICAL_PIGTAIL = 0x0b,
245 SFP_CONNECTOR_MPO_1X12 = 0x0c,
246 SFP_CONNECTOR_MPO_2X16 = 0x0d,
247 SFP_CONNECTOR_HSSDC_II = 0x20,
248 SFP_CONNECTOR_COPPER_PIGTAIL = 0x21,
249 SFP_CONNECTOR_RJ45 = 0x22,
250 SFP_CONNECTOR_NOSEPARATE = 0x23,
251 SFP_CONNECTOR_MXC_2X16 = 0x24,
252 SFP_ENCODING_UNSPEC = 0x00,
253 SFP_ENCODING_8B10B = 0x01,
254 SFP_ENCODING_4B5B = 0x02,
255 SFP_ENCODING_NRZ = 0x03,
256 SFP_ENCODING_8472_MANCHESTER = 0x04,
257 SFP_ENCODING_8472_SONET = 0x05,
258 SFP_ENCODING_8472_64B66B = 0x06,
259 SFP_ENCODING_256B257B = 0x07,
260 SFP_ENCODING_PAM4 = 0x08,
261 SFP_OPTIONS_HIGH_POWER_LEVEL = BIT(13),
262 SFP_OPTIONS_PAGING_A2 = BIT(12),
263 SFP_OPTIONS_RETIMER = BIT(11),
264 SFP_OPTIONS_COOLED_XCVR = BIT(10),
265 SFP_OPTIONS_POWER_DECL = BIT(9),
266 SFP_OPTIONS_RX_LINEAR_OUT = BIT(8),
267 SFP_OPTIONS_RX_DECISION_THRESH = BIT(7),
268 SFP_OPTIONS_TUNABLE_TX = BIT(6),
269 SFP_OPTIONS_RATE_SELECT = BIT(5),
270 SFP_OPTIONS_TX_DISABLE = BIT(4),
271 SFP_OPTIONS_TX_FAULT = BIT(3),
272 SFP_OPTIONS_LOS_INVERTED = BIT(2),
273 SFP_OPTIONS_LOS_NORMAL = BIT(1),
274 SFP_DIAGMON_DDM = BIT(6),
275 SFP_DIAGMON_INT_CAL = BIT(5),
276 SFP_DIAGMON_EXT_CAL = BIT(4),
277 SFP_DIAGMON_RXPWR_AVG = BIT(3),
278 SFP_DIAGMON_ADDRMODE = BIT(2),
279 SFP_ENHOPTS_ALARMWARN = BIT(7),
280 SFP_ENHOPTS_SOFT_TX_DISABLE = BIT(6),
281 SFP_ENHOPTS_SOFT_TX_FAULT = BIT(5),
282 SFP_ENHOPTS_SOFT_RX_LOS = BIT(4),
283 SFP_ENHOPTS_SOFT_RATE_SELECT = BIT(3),
284 SFP_ENHOPTS_APP_SELECT_SFF8079 = BIT(2),
285 SFP_ENHOPTS_SOFT_RATE_SFF8431 = BIT(1),
286 SFP_SFF8472_COMPLIANCE_NONE = 0x00,
287 SFP_SFF8472_COMPLIANCE_REV9_3 = 0x01,
288 SFP_SFF8472_COMPLIANCE_REV9_5 = 0x02,
289 SFP_SFF8472_COMPLIANCE_REV10_2 = 0x03,
290 SFP_SFF8472_COMPLIANCE_REV10_4 = 0x04,
291 SFP_SFF8472_COMPLIANCE_REV11_0 = 0x05,
292 SFP_SFF8472_COMPLIANCE_REV11_3 = 0x06,
293 SFP_SFF8472_COMPLIANCE_REV11_4 = 0x07,
294 SFP_SFF8472_COMPLIANCE_REV12_0 = 0x08,
295};
296
297/* SFP Diagnostics */
298enum {
299 /* Alarm and warnings stored MSB at lower address then LSB */
300 SFP_TEMP_HIGH_ALARM = 0x00,
301 SFP_TEMP_LOW_ALARM = 0x02,
302 SFP_TEMP_HIGH_WARN = 0x04,
303 SFP_TEMP_LOW_WARN = 0x06,
304 SFP_VOLT_HIGH_ALARM = 0x08,
305 SFP_VOLT_LOW_ALARM = 0x0a,
306 SFP_VOLT_HIGH_WARN = 0x0c,
307 SFP_VOLT_LOW_WARN = 0x0e,
308 SFP_BIAS_HIGH_ALARM = 0x10,
309 SFP_BIAS_LOW_ALARM = 0x12,
310 SFP_BIAS_HIGH_WARN = 0x14,
311 SFP_BIAS_LOW_WARN = 0x16,
312 SFP_TXPWR_HIGH_ALARM = 0x18,
313 SFP_TXPWR_LOW_ALARM = 0x1a,
314 SFP_TXPWR_HIGH_WARN = 0x1c,
315 SFP_TXPWR_LOW_WARN = 0x1e,
316 SFP_RXPWR_HIGH_ALARM = 0x20,
317 SFP_RXPWR_LOW_ALARM = 0x22,
318 SFP_RXPWR_HIGH_WARN = 0x24,
319 SFP_RXPWR_LOW_WARN = 0x26,
320 SFP_LASER_TEMP_HIGH_ALARM = 0x28,
321 SFP_LASER_TEMP_LOW_ALARM = 0x2a,
322 SFP_LASER_TEMP_HIGH_WARN = 0x2c,
323 SFP_LASER_TEMP_LOW_WARN = 0x2e,
324 SFP_TEC_CUR_HIGH_ALARM = 0x30,
325 SFP_TEC_CUR_LOW_ALARM = 0x32,
326 SFP_TEC_CUR_HIGH_WARN = 0x34,
327 SFP_TEC_CUR_LOW_WARN = 0x36,
328 SFP_CAL_RXPWR4 = 0x38,
329 SFP_CAL_RXPWR3 = 0x3c,
330 SFP_CAL_RXPWR2 = 0x40,
331 SFP_CAL_RXPWR1 = 0x44,
332 SFP_CAL_RXPWR0 = 0x48,
333 SFP_CAL_TXI_SLOPE = 0x4c,
334 SFP_CAL_TXI_OFFSET = 0x4e,
335 SFP_CAL_TXPWR_SLOPE = 0x50,
336 SFP_CAL_TXPWR_OFFSET = 0x52,
337 SFP_CAL_T_SLOPE = 0x54,
338 SFP_CAL_T_OFFSET = 0x56,
339 SFP_CAL_V_SLOPE = 0x58,
340 SFP_CAL_V_OFFSET = 0x5a,
341 SFP_CHKSUM = 0x5f,
342
343 SFP_TEMP = 0x60,
344 SFP_VCC = 0x62,
345 SFP_TX_BIAS = 0x64,
346 SFP_TX_POWER = 0x66,
347 SFP_RX_POWER = 0x68,
348 SFP_LASER_TEMP = 0x6a,
349 SFP_TEC_CUR = 0x6c,
350
351 SFP_STATUS = 0x6e,
352 SFP_ALARM = 0x70,
353
354 SFP_EXT_STATUS = 0x76,
355 SFP_VSL = 0x78,
356 SFP_PAGE = 0x7f,
357};
358
359struct device_node;
360struct ethtool_eeprom;
361struct ethtool_modinfo;
362struct net_device;
363struct sfp_bus;
364
Russell King0a6fcd3f2017-12-01 10:24:53 +0000365/**
366 * struct sfp_upstream_ops - upstream operations structure
367 * @module_insert: called after a module has been detected to determine
368 * whether the module is supported for the upstream device.
369 * @module_remove: called after the module has been removed.
370 * @link_down: called when the link is non-operational for whatever
371 * reason.
372 * @link_up: called when the link is operational.
373 * @connect_phy: called when an I2C accessible PHY has been detected
374 * on the module.
375 * @disconnect_phy: called when a module with an I2C accessible PHY has
376 * been removed.
377 */
Russell Kingce0aa272017-07-25 15:03:18 +0100378struct sfp_upstream_ops {
Russell King0a6fcd3f2017-12-01 10:24:53 +0000379 int (*module_insert)(void *priv, const struct sfp_eeprom_id *id);
380 void (*module_remove)(void *priv);
381 void (*link_down)(void *priv);
382 void (*link_up)(void *priv);
383 int (*connect_phy)(void *priv, struct phy_device *);
384 void (*disconnect_phy)(void *priv);
Russell Kingce0aa272017-07-25 15:03:18 +0100385};
386
387#if IS_ENABLED(CONFIG_SFP)
388int sfp_parse_port(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
389 unsigned long *support);
390phy_interface_t sfp_parse_interface(struct sfp_bus *bus,
391 const struct sfp_eeprom_id *id);
392void sfp_parse_support(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
393 unsigned long *support);
394
395int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo);
396int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
397 u8 *data);
398void sfp_upstream_start(struct sfp_bus *bus);
399void sfp_upstream_stop(struct sfp_bus *bus);
400struct sfp_bus *sfp_register_upstream(struct device_node *np,
401 struct net_device *ndev, void *upstream,
402 const struct sfp_upstream_ops *ops);
403void sfp_unregister_upstream(struct sfp_bus *bus);
404#else
405static inline int sfp_parse_port(struct sfp_bus *bus,
406 const struct sfp_eeprom_id *id,
407 unsigned long *support)
408{
409 return PORT_OTHER;
410}
411
412static inline phy_interface_t sfp_parse_interface(struct sfp_bus *bus,
413 const struct sfp_eeprom_id *id)
414{
415 return PHY_INTERFACE_MODE_NA;
416}
417
418static inline void sfp_parse_support(struct sfp_bus *bus,
419 const struct sfp_eeprom_id *id,
420 unsigned long *support)
421{
422}
423
424static inline int sfp_get_module_info(struct sfp_bus *bus,
425 struct ethtool_modinfo *modinfo)
426{
427 return -EOPNOTSUPP;
428}
429
430static inline int sfp_get_module_eeprom(struct sfp_bus *bus,
431 struct ethtool_eeprom *ee, u8 *data)
432{
433 return -EOPNOTSUPP;
434}
435
436static inline void sfp_upstream_start(struct sfp_bus *bus)
437{
438}
439
440static inline void sfp_upstream_stop(struct sfp_bus *bus)
441{
442}
443
444static inline struct sfp_bus *sfp_register_upstream(struct device_node *np,
445 struct net_device *ndev, void *upstream,
446 const struct sfp_upstream_ops *ops)
447{
448 return (struct sfp_bus *)-1;
449}
450
451static inline void sfp_unregister_upstream(struct sfp_bus *bus)
452{
453}
454#endif
455
456#endif