sfp.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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. * https://www.snia.org/technology-communities/sff/specifications
  210. */
  211. struct sfp_eeprom_id {
  212. struct sfp_eeprom_base base;
  213. struct sfp_eeprom_ext ext;
  214. } __packed;
  215. struct sfp_diag {
  216. __be16 temp_high_alarm;
  217. __be16 temp_low_alarm;
  218. __be16 temp_high_warn;
  219. __be16 temp_low_warn;
  220. __be16 volt_high_alarm;
  221. __be16 volt_low_alarm;
  222. __be16 volt_high_warn;
  223. __be16 volt_low_warn;
  224. __be16 bias_high_alarm;
  225. __be16 bias_low_alarm;
  226. __be16 bias_high_warn;
  227. __be16 bias_low_warn;
  228. __be16 txpwr_high_alarm;
  229. __be16 txpwr_low_alarm;
  230. __be16 txpwr_high_warn;
  231. __be16 txpwr_low_warn;
  232. __be16 rxpwr_high_alarm;
  233. __be16 rxpwr_low_alarm;
  234. __be16 rxpwr_high_warn;
  235. __be16 rxpwr_low_warn;
  236. __be16 laser_temp_high_alarm;
  237. __be16 laser_temp_low_alarm;
  238. __be16 laser_temp_high_warn;
  239. __be16 laser_temp_low_warn;
  240. __be16 tec_cur_high_alarm;
  241. __be16 tec_cur_low_alarm;
  242. __be16 tec_cur_high_warn;
  243. __be16 tec_cur_low_warn;
  244. __be32 cal_rxpwr4;
  245. __be32 cal_rxpwr3;
  246. __be32 cal_rxpwr2;
  247. __be32 cal_rxpwr1;
  248. __be32 cal_rxpwr0;
  249. __be16 cal_txi_slope;
  250. __be16 cal_txi_offset;
  251. __be16 cal_txpwr_slope;
  252. __be16 cal_txpwr_offset;
  253. __be16 cal_t_slope;
  254. __be16 cal_t_offset;
  255. __be16 cal_v_slope;
  256. __be16 cal_v_offset;
  257. } __packed;
  258. /* SFF8024 defined constants */
  259. enum {
  260. SFF8024_ID_UNK = 0x00,
  261. SFF8024_ID_SFF_8472 = 0x02,
  262. SFF8024_ID_SFP = 0x03,
  263. SFF8024_ID_DWDM_SFP = 0x0b,
  264. SFF8024_ID_QSFP_8438 = 0x0c,
  265. SFF8024_ID_QSFP_8436_8636 = 0x0d,
  266. SFF8024_ID_QSFP28_8636 = 0x11,
  267. SFF8024_ENCODING_UNSPEC = 0x00,
  268. SFF8024_ENCODING_8B10B = 0x01,
  269. SFF8024_ENCODING_4B5B = 0x02,
  270. SFF8024_ENCODING_NRZ = 0x03,
  271. SFF8024_ENCODING_8472_MANCHESTER= 0x04,
  272. SFF8024_ENCODING_8472_SONET = 0x05,
  273. SFF8024_ENCODING_8472_64B66B = 0x06,
  274. SFF8024_ENCODING_8436_MANCHESTER= 0x06,
  275. SFF8024_ENCODING_8436_SONET = 0x04,
  276. SFF8024_ENCODING_8436_64B66B = 0x05,
  277. SFF8024_ENCODING_256B257B = 0x07,
  278. SFF8024_ENCODING_PAM4 = 0x08,
  279. SFF8024_CONNECTOR_UNSPEC = 0x00,
  280. /* codes 01-05 not supportable on SFP, but some modules have single SC */
  281. SFF8024_CONNECTOR_SC = 0x01,
  282. SFF8024_CONNECTOR_FIBERJACK = 0x06,
  283. SFF8024_CONNECTOR_LC = 0x07,
  284. SFF8024_CONNECTOR_MT_RJ = 0x08,
  285. SFF8024_CONNECTOR_MU = 0x09,
  286. SFF8024_CONNECTOR_SG = 0x0a,
  287. SFF8024_CONNECTOR_OPTICAL_PIGTAIL= 0x0b,
  288. SFF8024_CONNECTOR_MPO_1X12 = 0x0c,
  289. SFF8024_CONNECTOR_MPO_2X16 = 0x0d,
  290. SFF8024_CONNECTOR_HSSDC_II = 0x20,
  291. SFF8024_CONNECTOR_COPPER_PIGTAIL= 0x21,
  292. SFF8024_CONNECTOR_RJ45 = 0x22,
  293. SFF8024_CONNECTOR_NOSEPARATE = 0x23,
  294. SFF8024_CONNECTOR_MXC_2X16 = 0x24,
  295. SFF8024_ECC_UNSPEC = 0x00,
  296. SFF8024_ECC_100G_25GAUI_C2M_AOC = 0x01,
  297. SFF8024_ECC_100GBASE_SR4_25GBASE_SR = 0x02,
  298. SFF8024_ECC_100GBASE_LR4_25GBASE_LR = 0x03,
  299. SFF8024_ECC_100GBASE_ER4_25GBASE_ER = 0x04,
  300. SFF8024_ECC_100GBASE_SR10 = 0x05,
  301. SFF8024_ECC_100GBASE_CR4 = 0x0b,
  302. SFF8024_ECC_25GBASE_CR_S = 0x0c,
  303. SFF8024_ECC_25GBASE_CR_N = 0x0d,
  304. SFF8024_ECC_10GBASE_T_SFI = 0x16,
  305. SFF8024_ECC_10GBASE_T_SR = 0x1c,
  306. SFF8024_ECC_5GBASE_T = 0x1d,
  307. SFF8024_ECC_2_5GBASE_T = 0x1e,
  308. };
  309. /* SFP EEPROM registers */
  310. enum {
  311. SFP_PHYS_ID = 0x00,
  312. SFP_PHYS_EXT_ID = 0x01,
  313. SFP_CONNECTOR = 0x02,
  314. SFP_COMPLIANCE = 0x03,
  315. SFP_ENCODING = 0x0b,
  316. SFP_BR_NOMINAL = 0x0c,
  317. SFP_RATE_ID = 0x0d,
  318. SFP_LINK_LEN_SM_KM = 0x0e,
  319. SFP_LINK_LEN_SM_100M = 0x0f,
  320. SFP_LINK_LEN_50UM_OM2_10M = 0x10,
  321. SFP_LINK_LEN_62_5UM_OM1_10M = 0x11,
  322. SFP_LINK_LEN_COPPER_1M = 0x12,
  323. SFP_LINK_LEN_50UM_OM4_10M = 0x12,
  324. SFP_LINK_LEN_50UM_OM3_10M = 0x13,
  325. SFP_VENDOR_NAME = 0x14,
  326. SFP_VENDOR_OUI = 0x25,
  327. SFP_VENDOR_PN = 0x28,
  328. SFP_VENDOR_REV = 0x38,
  329. SFP_OPTICAL_WAVELENGTH_MSB = 0x3c,
  330. SFP_OPTICAL_WAVELENGTH_LSB = 0x3d,
  331. SFP_CABLE_SPEC = 0x3c,
  332. SFP_CC_BASE = 0x3f,
  333. SFP_OPTIONS = 0x40, /* 2 bytes, MSB, LSB */
  334. SFP_BR_MAX = 0x42,
  335. SFP_BR_MIN = 0x43,
  336. SFP_VENDOR_SN = 0x44,
  337. SFP_DATECODE = 0x54,
  338. SFP_DIAGMON = 0x5c,
  339. SFP_ENHOPTS = 0x5d,
  340. SFP_SFF8472_COMPLIANCE = 0x5e,
  341. SFP_CC_EXT = 0x5f,
  342. SFP_PHYS_EXT_ID_SFP = 0x04,
  343. SFP_OPTIONS_HIGH_POWER_LEVEL = BIT(13),
  344. SFP_OPTIONS_PAGING_A2 = BIT(12),
  345. SFP_OPTIONS_RETIMER = BIT(11),
  346. SFP_OPTIONS_COOLED_XCVR = BIT(10),
  347. SFP_OPTIONS_POWER_DECL = BIT(9),
  348. SFP_OPTIONS_RX_LINEAR_OUT = BIT(8),
  349. SFP_OPTIONS_RX_DECISION_THRESH = BIT(7),
  350. SFP_OPTIONS_TUNABLE_TX = BIT(6),
  351. SFP_OPTIONS_RATE_SELECT = BIT(5),
  352. SFP_OPTIONS_TX_DISABLE = BIT(4),
  353. SFP_OPTIONS_TX_FAULT = BIT(3),
  354. SFP_OPTIONS_LOS_INVERTED = BIT(2),
  355. SFP_OPTIONS_LOS_NORMAL = BIT(1),
  356. SFP_DIAGMON_DDM = BIT(6),
  357. SFP_DIAGMON_INT_CAL = BIT(5),
  358. SFP_DIAGMON_EXT_CAL = BIT(4),
  359. SFP_DIAGMON_RXPWR_AVG = BIT(3),
  360. SFP_DIAGMON_ADDRMODE = BIT(2),
  361. SFP_ENHOPTS_ALARMWARN = BIT(7),
  362. SFP_ENHOPTS_SOFT_TX_DISABLE = BIT(6),
  363. SFP_ENHOPTS_SOFT_TX_FAULT = BIT(5),
  364. SFP_ENHOPTS_SOFT_RX_LOS = BIT(4),
  365. SFP_ENHOPTS_SOFT_RATE_SELECT = BIT(3),
  366. SFP_ENHOPTS_APP_SELECT_SFF8079 = BIT(2),
  367. SFP_ENHOPTS_SOFT_RATE_SFF8431 = BIT(1),
  368. SFP_SFF8472_COMPLIANCE_NONE = 0x00,
  369. SFP_SFF8472_COMPLIANCE_REV9_3 = 0x01,
  370. SFP_SFF8472_COMPLIANCE_REV9_5 = 0x02,
  371. SFP_SFF8472_COMPLIANCE_REV10_2 = 0x03,
  372. SFP_SFF8472_COMPLIANCE_REV10_4 = 0x04,
  373. SFP_SFF8472_COMPLIANCE_REV11_0 = 0x05,
  374. SFP_SFF8472_COMPLIANCE_REV11_3 = 0x06,
  375. SFP_SFF8472_COMPLIANCE_REV11_4 = 0x07,
  376. SFP_SFF8472_COMPLIANCE_REV12_0 = 0x08,
  377. };
  378. /* SFP Diagnostics */
  379. enum {
  380. /* Alarm and warnings stored MSB at lower address then LSB */
  381. SFP_TEMP_HIGH_ALARM = 0x00,
  382. SFP_TEMP_LOW_ALARM = 0x02,
  383. SFP_TEMP_HIGH_WARN = 0x04,
  384. SFP_TEMP_LOW_WARN = 0x06,
  385. SFP_VOLT_HIGH_ALARM = 0x08,
  386. SFP_VOLT_LOW_ALARM = 0x0a,
  387. SFP_VOLT_HIGH_WARN = 0x0c,
  388. SFP_VOLT_LOW_WARN = 0x0e,
  389. SFP_BIAS_HIGH_ALARM = 0x10,
  390. SFP_BIAS_LOW_ALARM = 0x12,
  391. SFP_BIAS_HIGH_WARN = 0x14,
  392. SFP_BIAS_LOW_WARN = 0x16,
  393. SFP_TXPWR_HIGH_ALARM = 0x18,
  394. SFP_TXPWR_LOW_ALARM = 0x1a,
  395. SFP_TXPWR_HIGH_WARN = 0x1c,
  396. SFP_TXPWR_LOW_WARN = 0x1e,
  397. SFP_RXPWR_HIGH_ALARM = 0x20,
  398. SFP_RXPWR_LOW_ALARM = 0x22,
  399. SFP_RXPWR_HIGH_WARN = 0x24,
  400. SFP_RXPWR_LOW_WARN = 0x26,
  401. SFP_LASER_TEMP_HIGH_ALARM = 0x28,
  402. SFP_LASER_TEMP_LOW_ALARM = 0x2a,
  403. SFP_LASER_TEMP_HIGH_WARN = 0x2c,
  404. SFP_LASER_TEMP_LOW_WARN = 0x2e,
  405. SFP_TEC_CUR_HIGH_ALARM = 0x30,
  406. SFP_TEC_CUR_LOW_ALARM = 0x32,
  407. SFP_TEC_CUR_HIGH_WARN = 0x34,
  408. SFP_TEC_CUR_LOW_WARN = 0x36,
  409. SFP_CAL_RXPWR4 = 0x38,
  410. SFP_CAL_RXPWR3 = 0x3c,
  411. SFP_CAL_RXPWR2 = 0x40,
  412. SFP_CAL_RXPWR1 = 0x44,
  413. SFP_CAL_RXPWR0 = 0x48,
  414. SFP_CAL_TXI_SLOPE = 0x4c,
  415. SFP_CAL_TXI_OFFSET = 0x4e,
  416. SFP_CAL_TXPWR_SLOPE = 0x50,
  417. SFP_CAL_TXPWR_OFFSET = 0x52,
  418. SFP_CAL_T_SLOPE = 0x54,
  419. SFP_CAL_T_OFFSET = 0x56,
  420. SFP_CAL_V_SLOPE = 0x58,
  421. SFP_CAL_V_OFFSET = 0x5a,
  422. SFP_CHKSUM = 0x5f,
  423. SFP_TEMP = 0x60,
  424. SFP_VCC = 0x62,
  425. SFP_TX_BIAS = 0x64,
  426. SFP_TX_POWER = 0x66,
  427. SFP_RX_POWER = 0x68,
  428. SFP_LASER_TEMP = 0x6a,
  429. SFP_TEC_CUR = 0x6c,
  430. SFP_STATUS = 0x6e,
  431. SFP_STATUS_TX_DISABLE = BIT(7),
  432. SFP_STATUS_TX_DISABLE_FORCE = BIT(6),
  433. SFP_STATUS_TX_FAULT = BIT(2),
  434. SFP_STATUS_RX_LOS = BIT(1),
  435. SFP_ALARM0 = 0x70,
  436. SFP_ALARM0_TEMP_HIGH = BIT(7),
  437. SFP_ALARM0_TEMP_LOW = BIT(6),
  438. SFP_ALARM0_VCC_HIGH = BIT(5),
  439. SFP_ALARM0_VCC_LOW = BIT(4),
  440. SFP_ALARM0_TX_BIAS_HIGH = BIT(3),
  441. SFP_ALARM0_TX_BIAS_LOW = BIT(2),
  442. SFP_ALARM0_TXPWR_HIGH = BIT(1),
  443. SFP_ALARM0_TXPWR_LOW = BIT(0),
  444. SFP_ALARM1 = 0x71,
  445. SFP_ALARM1_RXPWR_HIGH = BIT(7),
  446. SFP_ALARM1_RXPWR_LOW = BIT(6),
  447. SFP_WARN0 = 0x74,
  448. SFP_WARN0_TEMP_HIGH = BIT(7),
  449. SFP_WARN0_TEMP_LOW = BIT(6),
  450. SFP_WARN0_VCC_HIGH = BIT(5),
  451. SFP_WARN0_VCC_LOW = BIT(4),
  452. SFP_WARN0_TX_BIAS_HIGH = BIT(3),
  453. SFP_WARN0_TX_BIAS_LOW = BIT(2),
  454. SFP_WARN0_TXPWR_HIGH = BIT(1),
  455. SFP_WARN0_TXPWR_LOW = BIT(0),
  456. SFP_WARN1 = 0x75,
  457. SFP_WARN1_RXPWR_HIGH = BIT(7),
  458. SFP_WARN1_RXPWR_LOW = BIT(6),
  459. SFP_EXT_STATUS = 0x76,
  460. SFP_VSL = 0x78,
  461. SFP_PAGE = 0x7f,
  462. };
  463. struct fwnode_handle;
  464. struct ethtool_eeprom;
  465. struct ethtool_modinfo;
  466. struct sfp_bus;
  467. /**
  468. * struct sfp_upstream_ops - upstream operations structure
  469. * @attach: called when the sfp socket driver is bound to the upstream
  470. * (mandatory).
  471. * @detach: called when the sfp socket driver is unbound from the upstream
  472. * (mandatory).
  473. * @module_insert: called after a module has been detected to determine
  474. * whether the module is supported for the upstream device.
  475. * @module_remove: called after the module has been removed.
  476. * @module_start: called after the PHY probe step
  477. * @module_stop: called before the PHY is removed
  478. * @link_down: called when the link is non-operational for whatever
  479. * reason.
  480. * @link_up: called when the link is operational.
  481. * @connect_phy: called when an I2C accessible PHY has been detected
  482. * on the module.
  483. * @disconnect_phy: called when a module with an I2C accessible PHY has
  484. * been removed.
  485. */
  486. struct sfp_upstream_ops {
  487. void (*attach)(void *priv, struct sfp_bus *bus);
  488. void (*detach)(void *priv, struct sfp_bus *bus);
  489. int (*module_insert)(void *priv, const struct sfp_eeprom_id *id);
  490. void (*module_remove)(void *priv);
  491. int (*module_start)(void *priv);
  492. void (*module_stop)(void *priv);
  493. void (*link_down)(void *priv);
  494. void (*link_up)(void *priv);
  495. int (*connect_phy)(void *priv, struct phy_device *);
  496. void (*disconnect_phy)(void *priv);
  497. };
  498. #if IS_ENABLED(CONFIG_SFP)
  499. int sfp_parse_port(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
  500. unsigned long *support);
  501. bool sfp_may_have_phy(struct sfp_bus *bus, const struct sfp_eeprom_id *id);
  502. void sfp_parse_support(struct sfp_bus *bus, const struct sfp_eeprom_id *id,
  503. unsigned long *support);
  504. phy_interface_t sfp_select_interface(struct sfp_bus *bus,
  505. unsigned long *link_modes);
  506. int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo);
  507. int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
  508. u8 *data);
  509. void sfp_upstream_start(struct sfp_bus *bus);
  510. void sfp_upstream_stop(struct sfp_bus *bus);
  511. void sfp_bus_put(struct sfp_bus *bus);
  512. struct sfp_bus *sfp_bus_find_fwnode(struct fwnode_handle *fwnode);
  513. int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
  514. const struct sfp_upstream_ops *ops);
  515. void sfp_bus_del_upstream(struct sfp_bus *bus);
  516. #else
  517. static inline int sfp_parse_port(struct sfp_bus *bus,
  518. const struct sfp_eeprom_id *id,
  519. unsigned long *support)
  520. {
  521. return PORT_OTHER;
  522. }
  523. static inline bool sfp_may_have_phy(struct sfp_bus *bus,
  524. const struct sfp_eeprom_id *id)
  525. {
  526. return false;
  527. }
  528. static inline void sfp_parse_support(struct sfp_bus *bus,
  529. const struct sfp_eeprom_id *id,
  530. unsigned long *support)
  531. {
  532. }
  533. static inline phy_interface_t sfp_select_interface(struct sfp_bus *bus,
  534. unsigned long *link_modes)
  535. {
  536. return PHY_INTERFACE_MODE_NA;
  537. }
  538. static inline int sfp_get_module_info(struct sfp_bus *bus,
  539. struct ethtool_modinfo *modinfo)
  540. {
  541. return -EOPNOTSUPP;
  542. }
  543. static inline int sfp_get_module_eeprom(struct sfp_bus *bus,
  544. struct ethtool_eeprom *ee, u8 *data)
  545. {
  546. return -EOPNOTSUPP;
  547. }
  548. static inline void sfp_upstream_start(struct sfp_bus *bus)
  549. {
  550. }
  551. static inline void sfp_upstream_stop(struct sfp_bus *bus)
  552. {
  553. }
  554. static inline void sfp_bus_put(struct sfp_bus *bus)
  555. {
  556. }
  557. static inline struct sfp_bus *sfp_bus_find_fwnode(struct fwnode_handle *fwnode)
  558. {
  559. return NULL;
  560. }
  561. static inline int sfp_bus_add_upstream(struct sfp_bus *bus, void *upstream,
  562. const struct sfp_upstream_ops *ops)
  563. {
  564. return 0;
  565. }
  566. static inline void sfp_bus_del_upstream(struct sfp_bus *bus)
  567. {
  568. }
  569. #endif
  570. #endif