cmis.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #define ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH 120
  3. #define ETHTOOL_CMIS_CDB_EPL_MAX_PL_LENGTH 2048
  4. #define ETHTOOL_CMIS_CDB_CMD_PAGE 0x9F
  5. #define ETHTOOL_CMIS_CDB_PAGE_I2C_ADDR 0x50
  6. /**
  7. * struct ethtool_cmis_cdb - CDB commands parameters
  8. * @cmis_rev: CMIS revision major.
  9. * @read_write_len_ext: Allowable additional number of byte octets to the LPL
  10. * in a READ or a WRITE CDB commands.
  11. * @max_completion_time: Maximum CDB command completion time in msec.
  12. */
  13. struct ethtool_cmis_cdb {
  14. u8 cmis_rev;
  15. u8 read_write_len_ext;
  16. u16 max_completion_time;
  17. };
  18. enum ethtool_cmis_cdb_cmd_id {
  19. ETHTOOL_CMIS_CDB_CMD_QUERY_STATUS = 0x0000,
  20. ETHTOOL_CMIS_CDB_CMD_MODULE_FEATURES = 0x0040,
  21. ETHTOOL_CMIS_CDB_CMD_FW_MANAGMENT_FEATURES = 0x0041,
  22. ETHTOOL_CMIS_CDB_CMD_START_FW_DOWNLOAD = 0x0101,
  23. ETHTOOL_CMIS_CDB_CMD_WRITE_FW_BLOCK_LPL = 0x0103,
  24. ETHTOOL_CMIS_CDB_CMD_WRITE_FW_BLOCK_EPL = 0x0104,
  25. ETHTOOL_CMIS_CDB_CMD_COMPLETE_FW_DOWNLOAD = 0x0107,
  26. ETHTOOL_CMIS_CDB_CMD_RUN_FW_IMAGE = 0x0109,
  27. ETHTOOL_CMIS_CDB_CMD_COMMIT_FW_IMAGE = 0x010A,
  28. };
  29. /**
  30. * struct ethtool_cmis_cdb_request - CDB commands request fields as decribed in
  31. * the CMIS standard
  32. * @id: Command ID.
  33. * @epl_len: EPL memory length.
  34. * @lpl_len: LPL memory length.
  35. * @chk_code: Check code for the previous field and the payload.
  36. * @resv1: Added to match the CMIS standard request continuity.
  37. * @resv2: Added to match the CMIS standard request continuity.
  38. * @payload: Payload for the CDB commands.
  39. * @epl: Extended payload for the CDB commands.
  40. */
  41. struct ethtool_cmis_cdb_request {
  42. __be16 id;
  43. struct_group(body,
  44. __be16 epl_len;
  45. u8 lpl_len;
  46. u8 chk_code;
  47. u8 resv1;
  48. u8 resv2;
  49. u8 payload[ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH];
  50. );
  51. u8 *epl; /* Everything above this field checksummed. */
  52. };
  53. #define CDB_F_COMPLETION_VALID BIT(0)
  54. #define CDB_F_STATUS_VALID BIT(1)
  55. #define CDB_F_MODULE_STATE_VALID BIT(2)
  56. /**
  57. * struct ethtool_cmis_cdb_cmd_args - CDB commands execution arguments
  58. * @req: CDB command fields as described in the CMIS standard.
  59. * @max_duration: Maximum duration time for command completion in msec.
  60. * @read_write_len_ext: Allowable additional number of byte octets to the LPL
  61. * in a READ or a WRITE commands.
  62. * @msleep_pre_rpl: Waiting time before checking reply in msec.
  63. * @rpl_exp_len: Expected reply length in bytes.
  64. * @flags: Validation flags for CDB commands.
  65. * @err_msg: Error message to be sent to user space.
  66. */
  67. struct ethtool_cmis_cdb_cmd_args {
  68. struct ethtool_cmis_cdb_request req;
  69. u16 max_duration;
  70. u8 read_write_len_ext;
  71. u8 msleep_pre_rpl;
  72. u8 rpl_exp_len;
  73. u8 flags;
  74. char *err_msg;
  75. };
  76. /**
  77. * struct ethtool_cmis_cdb_rpl_hdr - CDB commands reply header arguments
  78. * @rpl_len: Reply length.
  79. * @rpl_chk_code: Reply check code.
  80. */
  81. struct ethtool_cmis_cdb_rpl_hdr {
  82. u8 rpl_len;
  83. u8 rpl_chk_code;
  84. };
  85. /**
  86. * struct ethtool_cmis_cdb_rpl - CDB commands reply arguments
  87. * @hdr: CDB commands reply header arguments.
  88. * @payload: Payload for the CDB commands reply.
  89. */
  90. struct ethtool_cmis_cdb_rpl {
  91. struct ethtool_cmis_cdb_rpl_hdr hdr;
  92. u8 payload[ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH];
  93. };
  94. u32 ethtool_cmis_get_max_lpl_size(u8 num_of_byte_octs);
  95. void ethtool_cmis_cdb_compose_args(struct ethtool_cmis_cdb_cmd_args *args,
  96. enum ethtool_cmis_cdb_cmd_id cmd, u8 *lpl,
  97. u8 lpl_len, u8 *epl, u16 epl_len,
  98. u16 max_duration, u8 read_write_len_ext,
  99. u16 msleep_pre_rpl, u8 rpl_exp_len,
  100. u8 flags);
  101. void ethtool_cmis_cdb_check_completion_flag(u8 cmis_rev, u8 *flags);
  102. void ethtool_cmis_page_init(struct ethtool_module_eeprom *page_data,
  103. u8 page, u32 offset, u32 length);
  104. struct ethtool_cmis_cdb *
  105. ethtool_cmis_cdb_init(struct net_device *dev,
  106. const struct ethtool_module_fw_flash_params *params,
  107. struct ethnl_module_fw_flash_ntf_params *ntf_params);
  108. void ethtool_cmis_cdb_fini(struct ethtool_cmis_cdb *cdb);
  109. int ethtool_cmis_wait_for_cond(struct net_device *dev, u8 flags, u8 flag,
  110. u16 max_duration, u32 offset,
  111. bool (*cond_success)(u8), bool (*cond_fail)(u8), u8 *state);
  112. int ethtool_cmis_cdb_execute_cmd(struct net_device *dev,
  113. struct ethtool_cmis_cdb_cmd_args *args);