1/*-
2 * Copyright (c) 2017 Broadcom. All rights reserved.
3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 *    this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 *    this list of conditions and the following disclaimer in the documentation
13 *    and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 *    may be used to endorse or promote products derived from this software
17 *    without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/**
33 * @file
34 * Common declartaions for the driver's IOCTL interface
35 */
36
37#if !defined(__OCS_IOCTL_H__)
38#define __OCS_IOCTL_H__
39
40/**
41 * @brief OCS test ioctl
42 *
43 * Simple structure for testing the IOCTL interface
44 */
45
46typedef struct {
47	char string[32];		/**< fixed string buffer */
48} ocs_ioctl_test_t;
49
50/**
51 * @brief DRIVER_INFO ioctl structure
52 *
53 * Structure is returned whtn the OCS_IOCTL_CMD_DRIVER_INFO is issued by a user space program.
54 */
55
56typedef struct {
57	uint16_t pci_vendor;		/**< PCI vender ID value (binary) */
58	uint16_t pci_device;		/**< PCI device ID value (binary) */
59	char businfo[16];		/**< Bus information (text) */
60	uint32_t sli_intf;		/**< SLI_INTF register value (binary) */
61	char desc[64];			/**< description (text) */
62	char fw_rev[32];		/**< firmware revision (text) */
63        union {
64            struct {
65	        uint8_t	wwnn[8];		/**< WWNN (binary) */
66	        uint8_t	wwpn[8];		/**< WWPN (binary) */
67            } fc;
68            struct {
69	        uint8_t	mac_addr[6];		/**< MAC address (binary) */
70	        uint8_t	reserved[10];
71            } iscsi;
72        } hw_addr;
73	char serialnum[32];		/**< board serial number (text) */
74} ocs_ioctl_driver_info_t;
75
76#define ELXU_BSD_MAGIC  0x30584c45
77
78/**
79 * @brief IOCTL_CMD_IOCTL_ELXU_MBOX ioctl structure
80 *
81 * Structure used to submit elxsdkutil mailbox requests for firmware download and
82 * dump file retrieveal.
83 */
84
85typedef struct {
86    uint32_t    magic;			/**< magic number */
87    uint32_t    size;			/**< size of MBX command */
88    uint8_t	payload[256];		/**< MBX command in/out payload buffer */
89    uint64_t    in_addr;		/**< user space address of input buffer */
90    uint64_t    in_bytes;		/**< length of user space input buffer in bytes */
91    uint64_t    out_addr;		/**< user space address of output buffer */
92    uint64_t    out_bytes;		/**< length of user space output buffer in bytes */
93} ocs_ioctl_elxu_mbox_t;
94
95enum {
96	ocs_ioctl_scsi_cmd_loop,	/**< Start command loop */
97	ocs_ioctl_scsi_cmd_loop_wait,	/**< Start command loop and wait for completion */
98	ocs_ioctl_scsi_cmd_stop,	/**< Stop command loop */
99	ocs_ioctl_scsi_cmd,		/**< Start one command */
100	ocs_ioctl_scsi_cmd_wait,	/**< Wait for a command to complete */
101	ocs_ioctl_scsi_cmd_abort,	/**< Start an abort */
102	ocs_ioctl_scsi_cmd_tmf,		/**< Start a tmf */
103	ocs_ioctl_els_send,		/**< Start an ELS */
104	ocs_ioctl_tgt_logout,		/**< logout of a target */
105	ocs_ioctl_scsi_cmd_wait_any,	/**< Wait for any command to complete */
106};
107
108enum {
109	ocs_ioctl_scsi_cmd_rd = (1U << 0),	/**< direction is read */
110	ocs_ioctl_scsi_cmd_wr = (1U << 1),	/**< direction is write */
111};
112
113/**
114 * @brief OCS_IOCTL_CMD_SCSI_CMD ioctl command structure
115 */
116
117typedef enum {
118	DIF_OP_DISABLE = 0,
119	DIF_OP_IN_NODIF_OUT_CRC,
120        DIF_OP_IN_CRC_OUT_NODIF,
121        DIF_OP_IN_NODIF_OUT_CHKSUM,
122        DIF_OP_IN_CHKSUM_OUT_NODIF,
123        DIF_OP_IN_CRC_OUT_CRC,
124        DIF_OP_IN_CHKSUM_OUT_CHKSUM,
125        DIF_OP_IN_CRC_OUT_CHKSUM,
126        DIF_OP_IN_CHKSUM_OUT_CRC,
127        DIF_OP_IN_RAW_OUT_RAW,
128	} dif_op_t;
129
130#define DIF_OP_PASS_THRU		DIF_OP_IN_CRC_OUT_CRC
131#define DIF_OP_STRIP			DIF_OP_IN_CRC_OUT_NODIF
132#define DIF_OP_INSERT			DIF_OP_IN_NODIF_OUT_CRC
133
134typedef struct {
135	dif_op_t dif_op;
136	uint32_t
137		check_ref_tag:1,	/* check reference tag on initiator writes */
138		check_app_tag:1,	/* check application tag on initiator writes */
139		check_guard:1,		/* check CRC on initiator writes */
140		dif_separate:1;		/* use DIF separate transfers */
141	uint32_t ref_tag;		/* DIF reference tag */
142	uint16_t app_tag;		/* DIF application tag */
143	uint32_t blocksize;		/* DIF blocksize */
144} dif_info_t;
145
146typedef struct {
147	int command;			/**< SCSI command request command */
148	uint32_t target_idx;		/**< Target device index */
149	uint32_t dir;			/**< rd or wr */
150	uint32_t lun;			/**< lun value */
151	int32_t  tmf;			/**< TMF */
152	uint8_t cdb[32];		/**< SCSI CDB */
153	uint32_t cdb_len;		/**< SCSI CDB length in bytes */
154	uint32_t els_cmd;		/**< ELS command */
155	uint32_t flags;			/**< command flags */
156	uint32_t queue_depth;		/**< queue depth for command looping */
157	uint32_t payload_length;	/**< payload length for command */
158	uint32_t dif_payload_length;	/**< DIF payload length for command if separate */
159	uint32_t io_count;		/**< command count for looping */
160	uint32_t io_timeout;		/**< IO timeout in seconds (0 = no timeout) */
161
162	uint32_t directio;		/**< If set, DMA to and from user buffers */
163
164	uint32_t first_burst:1;		/**< If true send IO writes with first burst */
165	uint32_t first_burst_size;	/**< If first burst is enabled, then this size */
166
167	int32_t wait_timeout_usec;	/**< Wait timeout (usec) for wait, wait_any */
168
169	/* T10-PI */
170	dif_info_t dif;			/* DIF info */
171
172	/* user space buffers */
173	void *payload;			/**< pointer to user space payload buffer */
174	void *dif_payload;		/**< pointer to DIF block data if separate */
175	uint8_t scsi_status;		/**< SCSI status */
176	uint16_t scsi_status_qualifier; /**< SCSI status qualifier */
177	void *sense_data;		/**< pointer to sense data buffer */
178	uint32_t sense_data_length;	/**< length of sense data buffer (call=buffer leng, return=data written) */
179	int32_t residual;		/**< residual */
180	uint32_t tag_to_abort;		/**< tag to abort for an abort task request */
181
182	/* return value */
183	int32_t status;			/**< returned status */
184	uint32_t data_transferred;	/**< updated with data transferred */
185	uint32_t tag;			/**< returned unique I/O context tag */
186
187	/* for scsi loop */
188	uint32_t submit_count;		/**< count of submitted IOs */
189	uint32_t complete_count;	/**< count of completed IOs */
190} ocs_ioctl_scsi_cmd_t;
191
192/**
193 * @brief coredump helper function command values
194 */
195
196typedef enum {
197	OCS_ECD_HELPER_CFG_READ8,
198	OCS_ECD_HELPER_CFG_READ16,
199	OCS_ECD_HELPER_CFG_READ32,
200	OCS_ECD_HELPER_CFG_WRITE8,
201	OCS_ECD_HELPER_CFG_WRITE16,
202	OCS_ECD_HELPER_CFG_WRITE32,
203	OCS_ECD_HELPER_BAR_READ8,
204	OCS_ECD_HELPER_BAR_READ16,
205	OCS_ECD_HELPER_BAR_READ32,
206	OCS_ECD_HELPER_BAR_WRITE8,
207	OCS_ECD_HELPER_BAR_WRITE16,
208	OCS_ECD_HELPER_BAR_WRITE32,
209} ocs_ecd_helper_cmd_t;
210
211/**
212 * @brief OCS_IOCTL_CMD_ECD_HELPER ioctl structure
213 */
214
215typedef struct {
216	ocs_ecd_helper_cmd_t cmd;	/*<< coredump helper function command */
217	uint32_t bar;			/*<< BAR value to use */
218	uint32_t offset;		/*<< offset value to use */
219	uint32_t data;			/*<< 32 bit data value to write or return read data in */
220	int status;			/*<< status of helper function request */
221} ocs_ioctl_ecd_helper_t;
222
223/**
224 * @brief OCS_IOCTL_CMD_VPORT ioctl structure
225 */
226
227typedef struct {
228	uint32_t domain_index;		/*<< domain instance index */
229	uint32_t req_create:1,		/*<< 1 = create vport, zero = remove vport */
230		 enable_ini:1,		/*<< 1 = enable vport as an initiator */
231		 enable_tgt:1;		/*<< 1 = enable vport as a target */
232	uint64_t wwpn;			/*<< wwpn to create or delete */
233	uint64_t wwnn;			/*<< wwnn to create or delete */
234	int status;			/*<< status of helper function request */
235} ocs_ioctl_vport_t;
236
237/**
238 * @brief connection info ioctl structure
239 *
240 * Structure is returned when the OCS_IOCTL_CMD_CONNECTION_INFO is issued by a user space program.
241 */
242typedef struct {
243        uint32_t connection_handle;
244        uint16_t connection_id;
245        uint8_t source_ip_type;
246        uint8_t source_ip[16];
247        uint16_t source_port;
248        uint8_t dest_ip_type;
249        uint8_t dest_ip[16];
250        uint16_t dest_port;
251} ocs_ioctl_connection_info_t;
252
253typedef struct {
254        uint32_t max_connections;
255        uint32_t num_connections;
256        ocs_ioctl_connection_info_t *connections;
257} ocs_ioctl_connections_t;
258
259/**
260 * @brief driver-dump actions
261 */
262
263typedef enum {
264	OCS_IOCTL_DDUMP_GET,
265	OCS_IOCTL_DDUMP_GET_SAVED,
266	OCS_IOCTL_DDUMP_CLR_SAVED,
267} ocs_ddump_action_t;
268
269#define OCS_IOCTL_DDUMP_FLAGS_WQES	(1U << 0)
270#define OCS_IOCTL_DDUMP_FLAGS_CQES	(1U << 1)
271#define OCS_IOCTL_DDUMP_FLAGS_MQES	(1U << 2)
272#define OCS_IOCTL_DDUMP_FLAGS_RQES	(1U << 3)
273#define OCS_IOCTL_DDUMP_FLAGS_EQES	(1U << 4)
274
275typedef struct {
276	ocs_ddump_action_t action;
277	uint32_t flags;
278	uint32_t q_entries;
279} ocs_ioctl_ddump_arg_t;
280
281/**
282 * @brief OCS_CTL_CMD_GET_DDUMP ioctl structure
283 */
284
285typedef struct {
286	ocs_ioctl_ddump_arg_t args;	/*<< arguments for ddump */
287	uint8_t *user_buffer;		/*<< pointer to user space buffer */
288	uint32_t user_buffer_len;	/*<< length in bytes of user space buffer */
289	uint32_t bytes_written;		/*<< number of bytes written */
290} ocs_ioctl_ddump_t;
291
292/**
293 * @brief OCS_CTL_CMD_GET_STATUS, OCS_CTL_CMD_GET_CONFIG
294 */
295
296typedef struct {
297	uint8_t *user_buffer;		/*<< pointer to user space buffer */
298	uint32_t user_buffer_len;	/*<< length in bytes of user space buffer */
299	uint32_t bytes_written;		/*<< number of bytes written */
300} ocs_ioctl_mgmt_buffer_t;
301
302typedef struct {
303	uint8_t		*name;			/*<< Input: name of property to retrieve */
304	uint16_t	name_len;               /*<< Input: Length of name */
305	uint8_t		*value;			/*<< Output: user space buffer in which to place the response */
306	uint32_t	value_length;		/*<< Input: size of the user space buffer */
307	int		status;			/*<< Output: command execution status */
308} ocs_ioctl_cmd_get_t;
309
310typedef struct {
311	uint8_t		*name;			/*<< Input: name of property to set */
312	uint16_t	name_len;               /*<< Input: Length of name */
313	uint8_t		*value;			/*<< Input: user space buffer which contains the new value */
314	int32_t		result;			/*<< Output: result */
315} ocs_ioctl_cmd_set_t;
316
317typedef struct {
318	uint8_t		*name;			/*<< Input: name of action to execute */
319	uint16_t	name_len;               /*<< Input: Length of name */
320	void		*arg_in;		/*<< Input: pointer to argument in user space */
321	uint32_t	arg_in_length;		/*<< Input: size of arg_in in bytes */
322	void		*arg_out;		/*<< Output: pointer to argument from kernel to user */
323	uint32_t	arg_out_length;		/*<< Input: size of arg_out in bytes */
324	int32_t		result;			/*<< Output: result */
325} ocs_ioctl_action_t;
326
327#define FC_HEADER_LEN	24
328typedef struct {
329	uint8_t		fc_header[FC_HEADER_LEN]; /*<< FC Header to send */
330	uint8_t		*payload;		/*<< payload */
331	uint32_t	payload_len;		/*<< payload length (bytes) */
332	uint8_t		sof;			/*<< SOF value */
333	uint8_t		eof;			/*<< EOF Value */
334} ocs_ioctl_send_frame_t;
335
336/*
337 * boardtemp (DUMP_TYPE4_WKI_TAG_SAT_TEM) response buffer length.
338 */
339#define OCS_DUMP_TYPE4_WKI_TAG_SAT_TEM_RESP_LEN (6 * 4)
340
341/**
342 * @brief linkcfg strings
343 */
344#define OCS_CONFIG_LINKCFG_4X10G	"ETH_4x10G"
345#define OCS_CONFIG_LINKCFG_1X40G	"ETH_1x40G"
346#define OCS_CONFIG_LINKCFG_2X16G	"FC_2x16G"
347#define OCS_CONFIG_LINKCFG_4X8G		"FC_4x8G"
348#define OCS_CONFIG_LINKCFG_4X1G		"FC_4x1G"
349#define OCS_CONFIG_LINKCFG_2X10G	"ETH_2x10G"
350#define OCS_CONFIG_LINKCFG_2X10G_2X8G	"ETH_2x10G_FC_2x8G"
351#define OCS_CONFIG_LINKCFG_UNKNOWN	"UNKNOWN"
352
353#define OCS_IOCTL_CMD_BASE		'o'
354#define OCS_IOCTL_CMD_TEST		_IOWR(OCS_IOCTL_CMD_BASE, 1, ocs_ioctl_test_t)
355#define OCS_IOCTL_CMD_ELXU_MBOX		_IOWR(OCS_IOCTL_CMD_BASE, 2, ocs_ioctl_elxu_mbox_t)
356#define OCS_IOCTL_CMD_SCSI_CMD		_IOWR(OCS_IOCTL_CMD_BASE, 3, ocs_ioctl_scsi_cmd_t)
357#define OCS_IOCTL_CMD_DRIVER_INFO	_IOWR(OCS_IOCTL_CMD_BASE, 4, ocs_ioctl_driver_info_t)
358#define OCS_IOCTL_CMD_ECD_HELPER	_IOWR(OCS_IOCTL_CMD_BASE, 5, ocs_ioctl_ecd_helper_t)
359#define OCS_IOCTL_CMD_CONNECTION_INFO   _IOWR(OCS_IOCTL_CMD_BASE, 6, ocs_ioctl_connection_info_t)
360#define OCS_IOCTL_CMD_VPORT		_IOWR(OCS_IOCTL_CMD_BASE, 7, ocs_ioctl_vport_t)
361#define OCS_IOCTL_CMD_GET_DDUMP		_IOWR(OCS_IOCTL_CMD_BASE, 8, ocs_ioctl_ddump_t)
362#define OCS_IOCTL_CMD_MGMT_GET		_IOWR(OCS_IOCTL_CMD_BASE, 9, ocs_ioctl_cmd_get_t)
363#define OCS_IOCTL_CMD_MGMT_GET_ALL	_IOWR(OCS_IOCTL_CMD_BASE, 10, ocs_ioctl_mgmt_buffer_t)
364#define OCS_IOCTL_CMD_MGMT_SET		_IOWR(OCS_IOCTL_CMD_BASE, 11, ocs_ioctl_cmd_set_t)
365#define OCS_IOCTL_CMD_MGMT_LIST		_IOWR(OCS_IOCTL_CMD_BASE, 12, ocs_ioctl_mgmt_buffer_t)
366#define OCS_IOCTL_CMD_MGMT_EXEC		_IOWR(OCS_IOCTL_CMD_BASE, 13, ocs_ioctl_action_t)
367#define OCS_IOCTL_CMD_LINK_ONLINE	_IOWR(OCS_IOCTL_CMD_BASE, 16, int)
368#define OCS_IOCTL_CMD_GEN_DUMP		_IOWR(OCS_IOCTL_CMD_BASE, 17, int)
369#define OCS_IOCTL_CMD_UNLOAD		_IO(OCS_IOCTL_CMD_BASE, 18)
370#define OCS_IOCTL_CMD_SEND_FRAME	_IOWR(OCS_IOCTL_CMD_BASE, 19, ocs_ioctl_send_frame_t)
371
372#endif
373