6 struct sfp_eeprom_base {
10 #if defined __BIG_ENDIAN_BITFIELD
17 u8 if_1x_copper_active:1;
18 u8 if_1x_copper_passive:1;
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;
30 u8 sonet_oc12_smf_long_reach:1;
31 u8 sonet_oc12_smf_intermediate_reach:1;
32 u8 sonet_oc12_short_reach:1;
34 u8 sonet_oc3_smf_long_reach:1;
35 u8 sonet_oc3_smf_intermediate_reach:1;
36 u8 sonet_oc3_short_reach:1;
54 u8 fc_tech_electrical_inter_enclosure:1;
56 u8 fc_tech_electrical_intra_enclosure:1;
80 u8 unallocated_10_1:1;
82 #elif defined __LITTLE_ENDIAN_BITFIELD
83 u8 if_1x_copper_passive:1;
84 u8 if_1x_copper_active:1;
92 u8 sonet_oc3_short_reach:1;
93 u8 sonet_oc3_smf_intermediate_reach:1;
94 u8 sonet_oc3_smf_long_reach:1;
96 u8 sonet_oc12_short_reach:1;
97 u8 sonet_oc12_smf_intermediate_reach:1;
98 u8 sonet_oc12_smf_long_reach:1;
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;
119 u8 fc_tech_electrical_inter_enclosure:1;
128 u8 unallocated_8_0:1;
129 u8 unallocated_8_1:1;
135 u8 fc_tech_electrical_intra_enclosure:1;
138 u8 unallocated_9_1:1;
147 u8 unallocated_10_1:1;
155 #error Unknown Endian
161 char vendor_name[16];
167 __be16 optical_wavelength;
168 __be16 cable_compliance;
170 #if defined __BIG_ENDIAN_BITFIELD
175 #elif defined __LITTLE_ENDIAN_BITFIELD
181 #error Unknown Endian
185 #if defined __BIG_ENDIAN_BITFIELD
192 #elif defined __LITTLE_ENDIAN_BITFIELD
200 #error Unknown Endian
208 struct sfp_eeprom_ext {
216 u8 sff8472_compliance;
221 * struct sfp_eeprom_id - raw SFP module identification information
222 * @base: base SFP module identification structure
223 * @ext: extended SFP module identification structure
225 * See the SFF-8472 specification and related documents for the definition
226 * of these structure members. This can be obtained from
227 * https://www.snia.org/technology-communities/sff/specifications
229 struct sfp_eeprom_id {
230 struct sfp_eeprom_base base;
231 struct sfp_eeprom_ext ext;
235 __be16 temp_high_alarm;
236 __be16 temp_low_alarm;
237 __be16 temp_high_warn;
238 __be16 temp_low_warn;
239 __be16 volt_high_alarm;
240 __be16 volt_low_alarm;
241 __be16 volt_high_warn;
242 __be16 volt_low_warn;
243 __be16 bias_high_alarm;
244 __be16 bias_low_alarm;
245 __be16 bias_high_warn;
246 __be16 bias_low_warn;
247 __be16 txpwr_high_alarm;
248 __be16 txpwr_low_alarm;
249 __be16 txpwr_high_warn;
250 __be16 txpwr_low_warn;
251 __be16 rxpwr_high_alarm;
252 __be16 rxpwr_low_alarm;
253 __be16 rxpwr_high_warn;
254 __be16 rxpwr_low_warn;
255 __be16 laser_temp_high_alarm;
256 __be16 laser_temp_low_alarm;
257 __be16 laser_temp_high_warn;
258 __be16 laser_temp_low_warn;
259 __be16 tec_cur_high_alarm;
260 __be16 tec_cur_low_alarm;
261 __be16 tec_cur_high_warn;
262 __be16 tec_cur_low_warn;
268 __be16 cal_txi_slope;
269 __be16 cal_txi_offset;
270 __be16 cal_txpwr_slope;
271 __be16 cal_txpwr_offset;
278 /* SFF8024 defined constants */
280 SFF8024_ID_UNK = 0x00,
281 SFF8024_ID_SFF_8472 = 0x02,
282 SFF8024_ID_SFP = 0x03,
283 SFF8024_ID_DWDM_SFP = 0x0b,
284 SFF8024_ID_QSFP_8438 = 0x0c,
285 SFF8024_ID_QSFP_8436_8636 = 0x0d,
286 SFF8024_ID_QSFP28_8636 = 0x11,
288 SFF8024_ENCODING_UNSPEC = 0x00,
289 SFF8024_ENCODING_8B10B = 0x01,
290 SFF8024_ENCODING_4B5B = 0x02,
291 SFF8024_ENCODING_NRZ = 0x03,
292 SFF8024_ENCODING_8472_MANCHESTER= 0x04,
293 SFF8024_ENCODING_8472_SONET = 0x05,
294 SFF8024_ENCODING_8472_64B66B = 0x06,
295 SFF8024_ENCODING_8436_MANCHESTER= 0x06,
296 SFF8024_ENCODING_8436_SONET = 0x04,
297 SFF8024_ENCODING_8436_64B66B = 0x05,
298 SFF8024_ENCODING_256B257B = 0x07,
299 SFF8024_ENCODING_PAM4 = 0x08,
301 SFF8024_CONNECTOR_UNSPEC = 0x00,
302 /* codes 01-05 not supportable on SFP, but some modules have single SC */
303 SFF8024_CONNECTOR_SC = 0x01,
304 SFF8024_CONNECTOR_FIBERJACK = 0x06,
305 SFF8024_CONNECTOR_LC = 0x07,
306 SFF8024_CONNECTOR_MT_RJ = 0x08,
307 SFF8024_CONNECTOR_MU = 0x09,
308 SFF8024_CONNECTOR_SG = 0x0a,
309 SFF8024_CONNECTOR_OPTICAL_PIGTAIL= 0x0b,
310 SFF8024_CONNECTOR_MPO_1X12 = 0x0c,
311 SFF8024_CONNECTOR_MPO_2X16 = 0x0d,
312 SFF8024_CONNECTOR_HSSDC_II = 0x20,
313 SFF8024_CONNECTOR_COPPER_PIGTAIL= 0x21,
314 SFF8024_CONNECTOR_RJ45 = 0x22,
315 SFF8024_CONNECTOR_NOSEPARATE = 0x23,
316 SFF8024_CONNECTOR_MXC_2X16 = 0x24,
318 SFF8024_ECC_UNSPEC = 0x00,
319 SFF8024_ECC_100G_25GAUI_C2M_AOC = 0x01,
320 SFF8024_ECC_100GBASE_SR4_25GBASE_SR = 0x02,
321 SFF8024_ECC_100GBASE_LR4_25GBASE_LR = 0x03,
322 SFF8024_ECC_100GBASE_ER4_25GBASE_ER = 0x04,
323 SFF8024_ECC_100GBASE_SR10 = 0x05,
324 SFF8024_ECC_100GBASE_CR4 = 0x0b,
325 SFF8024_ECC_25GBASE_CR_S = 0x0c,
326 SFF8024_ECC_25GBASE_CR_N = 0x0d,
327 SFF8024_ECC_10GBASE_T_SFI = 0x16,
328 SFF8024_ECC_10GBASE_T_SR = 0x1c,
329 SFF8024_ECC_5GBASE_T = 0x1d,
330 SFF8024_ECC_2_5GBASE_T = 0x1e,
333 /* SFP EEPROM registers */
336 SFP_PHYS_EXT_ID = 0x01,
337 SFP_CONNECTOR = 0x02,
338 SFP_COMPLIANCE = 0x03,
340 SFP_BR_NOMINAL = 0x0c,
342 SFP_LINK_LEN_SM_KM = 0x0e,
343 SFP_LINK_LEN_SM_100M = 0x0f,
344 SFP_LINK_LEN_50UM_OM2_10M = 0x10,
345 SFP_LINK_LEN_62_5UM_OM1_10M = 0x11,
346 SFP_LINK_LEN_COPPER_1M = 0x12,
347 SFP_LINK_LEN_50UM_OM4_10M = 0x12,
348 SFP_LINK_LEN_50UM_OM3_10M = 0x13,
349 SFP_VENDOR_NAME = 0x14,
350 SFP_VENDOR_OUI = 0x25,
351 SFP_VENDOR_PN = 0x28,
352 SFP_VENDOR_REV = 0x38,
353 SFP_OPTICAL_WAVELENGTH_MSB = 0x3c,
354 SFP_OPTICAL_WAVELENGTH_LSB = 0x3d,
355 SFP_CABLE_SPEC = 0x3c,
357 SFP_OPTIONS = 0x40, /* 2 bytes, MSB, LSB */
360 SFP_VENDOR_SN = 0x44,
364 SFP_SFF8472_COMPLIANCE = 0x5e,
367 SFP_PHYS_EXT_ID_SFP = 0x04,
368 SFP_OPTIONS_HIGH_POWER_LEVEL = BIT(13),
369 SFP_OPTIONS_PAGING_A2 = BIT(12),
370 SFP_OPTIONS_RETIMER = BIT(11),
371 SFP_OPTIONS_COOLED_XCVR = BIT(10),
372 SFP_OPTIONS_POWER_DECL = BIT(9),
373 SFP_OPTIONS_RX_LINEAR_OUT = BIT(8),
374 SFP_OPTIONS_RX_DECISION_THRESH = BIT(7),
375 SFP_OPTIONS_TUNABLE_TX = BIT(6),
376 SFP_OPTIONS_RATE_SELECT = BIT(5),
377 SFP_OPTIONS_TX_DISABLE = BIT(4),
378 SFP_OPTIONS_TX_FAULT = BIT(3),
379 SFP_OPTIONS_LOS_INVERTED = BIT(2),
380 SFP_OPTIONS_LOS_NORMAL = BIT(1),
381 SFP_DIAGMON_DDM = BIT(6),
382 SFP_DIAGMON_INT_CAL = BIT(5),
383 SFP_DIAGMON_EXT_CAL = BIT(4),
384 SFP_DIAGMON_RXPWR_AVG = BIT(3),
385 SFP_DIAGMON_ADDRMODE = BIT(2),
386 SFP_ENHOPTS_ALARMWARN = BIT(7),
387 SFP_ENHOPTS_SOFT_TX_DISABLE = BIT(6),
388 SFP_ENHOPTS_SOFT_TX_FAULT = BIT(5),
389 SFP_ENHOPTS_SOFT_RX_LOS = BIT(4),
390 SFP_ENHOPTS_SOFT_RATE_SELECT = BIT(3),
391 SFP_ENHOPTS_APP_SELECT_SFF8079 = BIT(2),
392 SFP_ENHOPTS_SOFT_RATE_SFF8431 = BIT(1),
393 SFP_SFF8472_COMPLIANCE_NONE = 0x00,
394 SFP_SFF8472_COMPLIANCE_REV9_3 = 0x01,
395 SFP_SFF8472_COMPLIANCE_REV9_5 = 0x02,
396 SFP_SFF8472_COMPLIANCE_REV10_2 = 0x03,
397 SFP_SFF8472_COMPLIANCE_REV10_4 = 0x04,
398 SFP_SFF8472_COMPLIANCE_REV11_0 = 0x05,
399 SFP_SFF8472_COMPLIANCE_REV11_3 = 0x06,
400 SFP_SFF8472_COMPLIANCE_REV11_4 = 0x07,
401 SFP_SFF8472_COMPLIANCE_REV12_0 = 0x08,
404 /* SFP Diagnostics */
406 /* Alarm and warnings stored MSB at lower address then LSB */
407 SFP_TEMP_HIGH_ALARM = 0x00,
408 SFP_TEMP_LOW_ALARM = 0x02,
409 SFP_TEMP_HIGH_WARN = 0x04,
410 SFP_TEMP_LOW_WARN = 0x06,
411 SFP_VOLT_HIGH_ALARM = 0x08,
412 SFP_VOLT_LOW_ALARM = 0x0a,
413 SFP_VOLT_HIGH_WARN = 0x0c,
414 SFP_VOLT_LOW_WARN = 0x0e,
415 SFP_BIAS_HIGH_ALARM = 0x10,
416 SFP_BIAS_LOW_ALARM = 0x12,
417 SFP_BIAS_HIGH_WARN = 0x14,
418 SFP_BIAS_LOW_WARN = 0x16,
419 SFP_TXPWR_HIGH_ALARM = 0x18,
420 SFP_TXPWR_LOW_ALARM = 0x1a,
421 SFP_TXPWR_HIGH_WARN = 0x1c,
422 SFP_TXPWR_LOW_WARN = 0x1e,
423 SFP_RXPWR_HIGH_ALARM = 0x20,
424 SFP_RXPWR_LOW_ALARM = 0x22,
425 SFP_RXPWR_HIGH_WARN = 0x24,
426 SFP_RXPWR_LOW_WARN = 0x26,
427 SFP_LASER_TEMP_HIGH_ALARM = 0x28,
428 SFP_LASER_TEMP_LOW_ALARM = 0x2a,
429 SFP_LASER_TEMP_HIGH_WARN = 0x2c,
430 SFP_LASER_TEMP_LOW_WARN = 0x2e,
431 SFP_TEC_CUR_HIGH_ALARM = 0x30,
432 SFP_TEC_CUR_LOW_ALARM = 0x32,
433 SFP_TEC_CUR_HIGH_WARN = 0x34,
434 SFP_TEC_CUR_LOW_WARN = 0x36,
435 SFP_CAL_RXPWR4 = 0x38,
436 SFP_CAL_RXPWR3 = 0x3c,
437 SFP_CAL_RXPWR2 = 0x40,
438 SFP_CAL_RXPWR1 = 0x44,
439 SFP_CAL_RXPWR0 = 0x48,
440 SFP_CAL_TXI_SLOPE = 0x4c,
441 SFP_CAL_TXI_OFFSET = 0x4e,
442 SFP_CAL_TXPWR_SLOPE = 0x50,
443 SFP_CAL_TXPWR_OFFSET = 0x52,
444 SFP_CAL_T_SLOPE = 0x54,
445 SFP_CAL_T_OFFSET = 0x56,
446 SFP_CAL_V_SLOPE = 0x58,
447 SFP_CAL_V_OFFSET = 0x5a,
455 SFP_LASER_TEMP = 0x6a,
459 SFP_STATUS_TX_DISABLE = BIT(7),
460 SFP_STATUS_TX_DISABLE_FORCE = BIT(6),
461 SFP_STATUS_TX_FAULT = BIT(2),
462 SFP_STATUS_RX_LOS = BIT(1),
464 SFP_ALARM0_TEMP_HIGH = BIT(7),
465 SFP_ALARM0_TEMP_LOW = BIT(6),
466 SFP_ALARM0_VCC_HIGH = BIT(5),
467 SFP_ALARM0_VCC_LOW = BIT(4),
468 SFP_ALARM0_TX_BIAS_HIGH = BIT(3),
469 SFP_ALARM0_TX_BIAS_LOW = BIT(2),
470 SFP_ALARM0_TXPWR_HIGH = BIT(1),
471 SFP_ALARM0_TXPWR_LOW = BIT(0),
474 SFP_ALARM1_RXPWR_HIGH = BIT(7),
475 SFP_ALARM1_RXPWR_LOW = BIT(6),
478 SFP_WARN0_TEMP_HIGH = BIT(7),
479 SFP_WARN0_TEMP_LOW = BIT(6),
480 SFP_WARN0_VCC_HIGH = BIT(5),
481 SFP_WARN0_VCC_LOW = BIT(4),
482 SFP_WARN0_TX_BIAS_HIGH = BIT(3),
483 SFP_WARN0_TX_BIAS_LOW = BIT(2),
484 SFP_WARN0_TXPWR_HIGH = BIT(1),
485 SFP_WARN0_TXPWR_LOW = BIT(0),
488 SFP_WARN1_RXPWR_HIGH = BIT(7),
489 SFP_WARN1_RXPWR_LOW = BIT(6),
491 SFP_EXT_STATUS = 0x76,
496 struct fwnode_handle;
497 struct ethtool_eeprom;
498 struct ethtool_modinfo;
502 * struct sfp_upstream_ops - upstream operations structure
503 * @attach: called when the sfp socket driver is bound to the upstream
505 * @detach: called when the sfp socket driver is unbound from the upstream
507 * @module_insert: called after a module has been detected to determine
508 * whether the module is supported for the upstream device.
509 * @module_remove: called after the module has been removed.
510 * @module_start: called after the PHY probe step
511 * @module_stop: called before the PHY is removed
512 * @link_down: called when the link is non-operational for whatever
514 * @link_up: called when the link is operational.
515 * @connect_phy: called when an I2C accessible PHY has been detected
517 * @disconnect_phy: called when a module with an I2C accessible PHY has
520 struct sfp_upstream_ops {
521 void (*attach)(void *priv, struct sfp_bus *bus);
522 void (*detach)(void *priv, struct sfp_bus *bus);
523 int (*module_insert)(void *priv, const struct sfp_eeprom_id *id);
524 void (*module_remove)(void *priv);
525 int (*module_start)(void *priv);
526 void (*module_stop)(void *priv);
527 void (*link_down)(void *priv);
528 void (*link_up)(void *priv);
529 int (*connect_phy)(void *priv, struct phy_device *);
530 void (*disconnect_phy)(void *priv);
533 #if IS_ENABLED(CONFIG_SFP)
534 int sfp_parse_port(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
535 unsigned long *support);
536 bool sfp_may_have_phy(struct sfp_bus *bus, const struct sfp_eeprom_id *id);
537 void sfp_parse_support(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
538 unsigned long *support);
539 phy_interface_t sfp_select_interface(struct sfp_bus *bus,
540 unsigned long *link_modes);
542 int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo);
543 int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
545 int sfp_get_module_eeprom_by_page(struct sfp_bus *bus,
546 const struct ethtool_module_eeprom *page,
547 struct netlink_ext_ack *extack);
548 void sfp_upstream_start(struct sfp_bus *bus);
549 void sfp_upstream_stop(struct sfp_bus *bus);
550 void sfp_bus_put(struct sfp_bus *bus);
551 struct sfp_bus *sfp_bus_find_fwnode(struct fwnode_handle *fwnode);
552 int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
553 const struct sfp_upstream_ops *ops);
554 void sfp_bus_del_upstream(struct sfp_bus *bus);
556 static inline int sfp_parse_port(struct sfp_bus *bus,
557 const struct sfp_eeprom_id *id,
558 unsigned long *support)
563 static inline bool sfp_may_have_phy(struct sfp_bus *bus,
564 const struct sfp_eeprom_id *id)
569 static inline void sfp_parse_support(struct sfp_bus *bus,
570 const struct sfp_eeprom_id *id,
571 unsigned long *support)
575 static inline phy_interface_t sfp_select_interface(struct sfp_bus *bus,
576 unsigned long *link_modes)
578 return PHY_INTERFACE_MODE_NA;
581 static inline int sfp_get_module_info(struct sfp_bus *bus,
582 struct ethtool_modinfo *modinfo)
587 static inline int sfp_get_module_eeprom(struct sfp_bus *bus,
588 struct ethtool_eeprom *ee, u8 *data)
593 static inline int sfp_get_module_eeprom_by_page(struct sfp_bus *bus,
594 const struct ethtool_module_eeprom *page,
595 struct netlink_ext_ack *extack)
600 static inline void sfp_upstream_start(struct sfp_bus *bus)
604 static inline void sfp_upstream_stop(struct sfp_bus *bus)
608 static inline void sfp_bus_put(struct sfp_bus *bus)
612 static inline struct sfp_bus *sfp_bus_find_fwnode(struct fwnode_handle *fwnode)
617 static inline int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
618 const struct sfp_upstream_ops *ops)
623 static inline void sfp_bus_del_upstream(struct sfp_bus *bus)