cmis.h 3.9 KB

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