1 /* SPDX-License-Identifier: GPL-2.0-only */
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
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.
14 struct ethtool_cmis_cdb
{
16 u8 read_write_len_ext
;
17 u16 max_completion_time
;
20 enum ethtool_cmis_cdb_cmd_id
{
21 ETHTOOL_CMIS_CDB_CMD_QUERY_STATUS
= 0x0000,
22 ETHTOOL_CMIS_CDB_CMD_MODULE_FEATURES
= 0x0040,
23 ETHTOOL_CMIS_CDB_CMD_FW_MANAGMENT_FEATURES
= 0x0041,
24 ETHTOOL_CMIS_CDB_CMD_START_FW_DOWNLOAD
= 0x0101,
25 ETHTOOL_CMIS_CDB_CMD_WRITE_FW_BLOCK_LPL
= 0x0103,
26 ETHTOOL_CMIS_CDB_CMD_COMPLETE_FW_DOWNLOAD
= 0x0107,
27 ETHTOOL_CMIS_CDB_CMD_RUN_FW_IMAGE
= 0x0109,
28 ETHTOOL_CMIS_CDB_CMD_COMMIT_FW_IMAGE
= 0x010A,
32 * struct ethtool_cmis_cdb_request - CDB commands request fields as decribed in
35 * @epl_len: EPL memory length.
36 * @lpl_len: LPL memory length.
37 * @chk_code: Check code for the previous field and the payload.
38 * @resv1: Added to match the CMIS standard request continuity.
39 * @resv2: Added to match the CMIS standard request continuity.
40 * @payload: Payload for the CDB commands.
42 struct ethtool_cmis_cdb_request
{
50 u8 payload
[ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH
];
54 #define CDB_F_COMPLETION_VALID BIT(0)
55 #define CDB_F_STATUS_VALID BIT(1)
56 #define CDB_F_MODULE_STATE_VALID BIT(2)
59 * struct ethtool_cmis_cdb_cmd_args - CDB commands execution arguments
60 * @req: CDB command fields as described in the CMIS standard.
61 * @max_duration: Maximum duration time for command completion in msec.
62 * @read_write_len_ext: Allowable additional number of byte octets to the LPL
63 * in a READ or a WRITE commands.
64 * @msleep_pre_rpl: Waiting time before checking reply in msec.
65 * @rpl_exp_len: Expected reply length in bytes.
66 * @flags: Validation flags for CDB commands.
67 * @err_msg: Error message to be sent to user space.
69 struct ethtool_cmis_cdb_cmd_args
{
70 struct ethtool_cmis_cdb_request req
;
72 u8 read_write_len_ext
;
80 * struct ethtool_cmis_cdb_rpl_hdr - CDB commands reply header arguments
81 * @rpl_len: Reply length.
82 * @rpl_chk_code: Reply check code.
84 struct ethtool_cmis_cdb_rpl_hdr
{
90 * struct ethtool_cmis_cdb_rpl - CDB commands reply arguments
91 * @hdr: CDB commands reply header arguments.
92 * @payload: Payload for the CDB commands reply.
94 struct ethtool_cmis_cdb_rpl
{
95 struct ethtool_cmis_cdb_rpl_hdr hdr
;
96 u8 payload
[ETHTOOL_CMIS_CDB_LPL_MAX_PL_LENGTH
];
99 u32
ethtool_cmis_get_max_payload_size(u8 num_of_byte_octs
);
101 void ethtool_cmis_cdb_compose_args(struct ethtool_cmis_cdb_cmd_args
*args
,
102 enum ethtool_cmis_cdb_cmd_id cmd
, u8
*pl
,
103 u8 lpl_len
, u16 max_duration
,
104 u8 read_write_len_ext
, u16 msleep_pre_rpl
,
105 u8 rpl_exp_len
, u8 flags
);
107 void ethtool_cmis_cdb_check_completion_flag(u8 cmis_rev
, u8
*flags
);
109 void ethtool_cmis_page_init(struct ethtool_module_eeprom
*page_data
,
110 u8 page
, u32 offset
, u32 length
);
112 struct ethtool_cmis_cdb
*
113 ethtool_cmis_cdb_init(struct net_device
*dev
,
114 const struct ethtool_module_fw_flash_params
*params
,
115 struct ethnl_module_fw_flash_ntf_params
*ntf_params
);
116 void ethtool_cmis_cdb_fini(struct ethtool_cmis_cdb
*cdb
);
118 int ethtool_cmis_wait_for_cond(struct net_device
*dev
, u8 flags
, u8 flag
,
119 u16 max_duration
, u32 offset
,
120 bool (*cond_success
)(u8
), bool (*cond_fail
)(u8
), u8
*state
);
122 int ethtool_cmis_cdb_execute_cmd(struct net_device
*dev
,
123 struct ethtool_cmis_cdb_cmd_args
*args
);