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