sfp.h 12 KB

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