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