xref: /openbmc/linux/drivers/scsi/lpfc/lpfc_bsg.h (revision d080abe0a8693c58a4b35b74bab3526d8b554ca3)
1c79c1292SJames Smart /*******************************************************************
2c79c1292SJames Smart  * This file is part of the Emulex Linux Device Driver for         *
3c79c1292SJames Smart  * Fibre Channel Host Bus Adapters.                                *
4*d080abe0SJames Smart  * Copyright (C) 2017 Broadcom. All Rights Reserved. The term      *
5*d080abe0SJames Smart  * “Broadcom” refers to Broadcom Limited and/or its subsidiaries.  *
6f25e8e79SJames Smart  * Copyright (C) 2010-2015 Emulex.  All rights reserved.           *
7c79c1292SJames Smart  * EMULEX and SLI are trademarks of Emulex.                        *
8*d080abe0SJames Smart  * www.broadcom.com                                                *
9c79c1292SJames Smart  *                                                                 *
10c79c1292SJames Smart  * This program is free software; you can redistribute it and/or   *
11c79c1292SJames Smart  * modify it under the terms of version 2 of the GNU General       *
12c79c1292SJames Smart  * Public License as published by the Free Software Foundation.    *
13c79c1292SJames Smart  * This program is distributed in the hope that it will be useful. *
14c79c1292SJames Smart  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
15c79c1292SJames Smart  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
16c79c1292SJames Smart  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
17c79c1292SJames Smart  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18c79c1292SJames Smart  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
19c79c1292SJames Smart  * more details, a copy of which can be found in the file COPYING  *
20c79c1292SJames Smart  * included with this package.                                     *
21c79c1292SJames Smart  *******************************************************************/
22c79c1292SJames Smart /* bsg definitions
23c79c1292SJames Smart  * No pointers to user data are allowed, all application buffers and sizes will
24c79c1292SJames Smart  * derived through the bsg interface.
25c79c1292SJames Smart  *
26c79c1292SJames Smart  * These are the vendor unique structures passed in using the bsg
27c79c1292SJames Smart  * FC_BSG_HST_VENDOR message code type.
28c79c1292SJames Smart  */
29c79c1292SJames Smart #define LPFC_BSG_VENDOR_SET_CT_EVENT		1
30c79c1292SJames Smart #define LPFC_BSG_VENDOR_GET_CT_EVENT		2
31c79c1292SJames Smart #define LPFC_BSG_VENDOR_SEND_MGMT_RESP		3
32c79c1292SJames Smart #define LPFC_BSG_VENDOR_DIAG_MODE		4
337ad20aa9SJames Smart #define LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK	5
34c79c1292SJames Smart #define LPFC_BSG_VENDOR_GET_MGMT_REV		6
35c79c1292SJames Smart #define LPFC_BSG_VENDOR_MBOX			7
36e2aed29fSJames Smart #define LPFC_BSG_VENDOR_MENLO_CMD		8
37e2aed29fSJames Smart #define LPFC_BSG_VENDOR_MENLO_DATA		9
387ad20aa9SJames Smart #define LPFC_BSG_VENDOR_DIAG_MODE_END		10
397ad20aa9SJames Smart #define LPFC_BSG_VENDOR_LINK_DIAG_TEST		11
40c691816eSJames Smart #define LPFC_BSG_VENDOR_FORCED_LINK_SPEED	14
41c79c1292SJames Smart 
42c79c1292SJames Smart struct set_ct_event {
43c79c1292SJames Smart 	uint32_t command;
44c79c1292SJames Smart 	uint32_t type_mask;
45c79c1292SJames Smart 	uint32_t ev_req_id;
46c79c1292SJames Smart 	uint32_t ev_reg_id;
47c79c1292SJames Smart };
48c79c1292SJames Smart 
49c79c1292SJames Smart struct get_ct_event {
50c79c1292SJames Smart 	uint32_t command;
51c79c1292SJames Smart 	uint32_t ev_reg_id;
52c79c1292SJames Smart 	uint32_t ev_req_id;
53c79c1292SJames Smart };
54c79c1292SJames Smart 
55c79c1292SJames Smart struct get_ct_event_reply {
56c79c1292SJames Smart 	uint32_t immed_data;
57c79c1292SJames Smart 	uint32_t type;
58c79c1292SJames Smart };
59c79c1292SJames Smart 
60c79c1292SJames Smart struct send_mgmt_resp {
61c79c1292SJames Smart 	uint32_t command;
62c79c1292SJames Smart 	uint32_t tag;
63c79c1292SJames Smart };
64c79c1292SJames Smart 
65c79c1292SJames Smart 
66c79c1292SJames Smart #define INTERNAL_LOOP_BACK 0x1 /* adapter short cuts the loop internally */
67c79c1292SJames Smart #define EXTERNAL_LOOP_BACK 0x2 /* requires an external loopback plug */
68c79c1292SJames Smart 
69c79c1292SJames Smart struct diag_mode_set {
70c79c1292SJames Smart 	uint32_t command;
71c79c1292SJames Smart 	uint32_t type;
72c79c1292SJames Smart 	uint32_t timeout;
73c79c1292SJames Smart };
74c79c1292SJames Smart 
757ad20aa9SJames Smart struct sli4_link_diag {
767ad20aa9SJames Smart 	uint32_t command;
777ad20aa9SJames Smart 	uint32_t timeout;
787ad20aa9SJames Smart 	uint32_t test_id;
797ad20aa9SJames Smart 	uint32_t loops;
807ad20aa9SJames Smart 	uint32_t test_version;
817ad20aa9SJames Smart 	uint32_t error_action;
827ad20aa9SJames Smart };
837ad20aa9SJames Smart 
84c79c1292SJames Smart struct diag_mode_test {
85c79c1292SJames Smart 	uint32_t command;
86c79c1292SJames Smart };
87c79c1292SJames Smart 
887ad20aa9SJames Smart struct diag_status {
897ad20aa9SJames Smart 	uint32_t mbox_status;
907ad20aa9SJames Smart 	uint32_t shdr_status;
917ad20aa9SJames Smart 	uint32_t shdr_add_status;
927ad20aa9SJames Smart };
937ad20aa9SJames Smart 
94c79c1292SJames Smart #define LPFC_WWNN_TYPE		0
95c79c1292SJames Smart #define LPFC_WWPN_TYPE		1
96c79c1292SJames Smart 
97c79c1292SJames Smart struct get_mgmt_rev {
98c79c1292SJames Smart 	uint32_t command;
99c79c1292SJames Smart };
100c79c1292SJames Smart 
101c79c1292SJames Smart #define MANAGEMENT_MAJOR_REV   1
102026abb87SJames Smart #define MANAGEMENT_MINOR_REV   1
103c79c1292SJames Smart 
104c79c1292SJames Smart /* the MgmtRevInfo structure */
105c79c1292SJames Smart struct MgmtRevInfo {
106c79c1292SJames Smart 	uint32_t a_Major;
107c79c1292SJames Smart 	uint32_t a_Minor;
108c79c1292SJames Smart };
109c79c1292SJames Smart 
110c79c1292SJames Smart struct get_mgmt_rev_reply {
111c79c1292SJames Smart 	struct MgmtRevInfo info;
112c79c1292SJames Smart };
113c79c1292SJames Smart 
11449198b37SJames Smart #define BSG_MBOX_SIZE 4096 /* mailbox command plus extended data */
1157ad20aa9SJames Smart 
1167ad20aa9SJames Smart /* BSG mailbox request header */
117c79c1292SJames Smart struct dfc_mbox_req {
118c79c1292SJames Smart 	uint32_t command;
1197a470277SJames Smart 	uint32_t mbOffset;
120c79c1292SJames Smart 	uint32_t inExtWLen;
121c7495937SJames Smart 	uint32_t outExtWLen;
1227ad20aa9SJames Smart 	uint32_t extMboxTag;
1237ad20aa9SJames Smart 	uint32_t extSeqNum;
124c79c1292SJames Smart };
125c79c1292SJames Smart 
126e2aed29fSJames Smart /* Used for menlo command or menlo data. The xri is only used for menlo data */
127e2aed29fSJames Smart struct menlo_command {
128e2aed29fSJames Smart 	uint32_t cmd;
129e2aed29fSJames Smart 	uint32_t xri;
130e2aed29fSJames Smart };
131e2aed29fSJames Smart 
132e2aed29fSJames Smart struct menlo_response {
133e2aed29fSJames Smart 	uint32_t xri; /* return the xri of the iocb exchange */
134e2aed29fSJames Smart };
135e2aed29fSJames Smart 
136b6e3b9c6SJames Smart /*
137b6e3b9c6SJames Smart  * macros and data structures for handling sli-config mailbox command
138b6e3b9c6SJames Smart  * pass-through support, this header file is shared between user and
139b6e3b9c6SJames Smart  * kernel spaces, note the set of macros are duplicates from lpfc_hw4.h,
140b6e3b9c6SJames Smart  * with macro names prefixed with bsg_, as the macros defined in
141b6e3b9c6SJames Smart  * lpfc_hw4.h are not accessible from user space.
142b6e3b9c6SJames Smart  */
143b6e3b9c6SJames Smart 
144b6e3b9c6SJames Smart /* Macros to deal with bit fields. Each bit field must have 3 #defines
145b6e3b9c6SJames Smart  * associated with it (_SHIFT, _MASK, and _WORD).
146b6e3b9c6SJames Smart  * EG. For a bit field that is in the 7th bit of the "field4" field of a
147b6e3b9c6SJames Smart  * structure and is 2 bits in size the following #defines must exist:
148b6e3b9c6SJames Smart  *      struct temp {
149b6e3b9c6SJames Smart  *              uint32_t        field1;
150b6e3b9c6SJames Smart  *              uint32_t        field2;
151b6e3b9c6SJames Smart  *              uint32_t        field3;
152b6e3b9c6SJames Smart  *              uint32_t        field4;
153b6e3b9c6SJames Smart  *      #define example_bit_field_SHIFT         7
154b6e3b9c6SJames Smart  *      #define example_bit_field_MASK          0x03
155b6e3b9c6SJames Smart  *      #define example_bit_field_WORD          field4
156b6e3b9c6SJames Smart  *              uint32_t        field5;
157b6e3b9c6SJames Smart  *      };
158b6e3b9c6SJames Smart  * Then the macros below may be used to get or set the value of that field.
159b6e3b9c6SJames Smart  * EG. To get the value of the bit field from the above example:
160b6e3b9c6SJames Smart  *      struct temp t1;
161b6e3b9c6SJames Smart  *      value = bsg_bf_get(example_bit_field, &t1);
162b6e3b9c6SJames Smart  * And then to set that bit field:
163b6e3b9c6SJames Smart  *      bsg_bf_set(example_bit_field, &t1, 2);
164b6e3b9c6SJames Smart  * Or clear that bit field:
165b6e3b9c6SJames Smart  *      bsg_bf_set(example_bit_field, &t1, 0);
166b6e3b9c6SJames Smart  */
167b6e3b9c6SJames Smart #define bsg_bf_get_le32(name, ptr) \
168b6e3b9c6SJames Smart 	((le32_to_cpu((ptr)->name##_WORD) >> name##_SHIFT) & name##_MASK)
169b6e3b9c6SJames Smart #define bsg_bf_get(name, ptr) \
170b6e3b9c6SJames Smart 	(((ptr)->name##_WORD >> name##_SHIFT) & name##_MASK)
171b6e3b9c6SJames Smart #define bsg_bf_set_le32(name, ptr, value) \
172b6e3b9c6SJames Smart 	((ptr)->name##_WORD = cpu_to_le32(((((value) & \
173b6e3b9c6SJames Smart 	name##_MASK) << name##_SHIFT) | (le32_to_cpu((ptr)->name##_WORD) & \
174b6e3b9c6SJames Smart 	~(name##_MASK << name##_SHIFT)))))
175b6e3b9c6SJames Smart #define bsg_bf_set(name, ptr, value) \
176b6e3b9c6SJames Smart 	((ptr)->name##_WORD = ((((value) & name##_MASK) << name##_SHIFT) | \
177b6e3b9c6SJames Smart 	((ptr)->name##_WORD & ~(name##_MASK << name##_SHIFT))))
178b6e3b9c6SJames Smart 
179b6e3b9c6SJames Smart /*
180b6e3b9c6SJames Smart  * The sli_config structure specified here is based on the following
181b6e3b9c6SJames Smart  * restriction:
182b6e3b9c6SJames Smart  *
183b6e3b9c6SJames Smart  * -- SLI_CONFIG EMB=0, carrying MSEs, will carry subcommands without
184b6e3b9c6SJames Smart  *    carrying HBD.
185b6e3b9c6SJames Smart  * -- SLI_CONFIG EMB=1, not carrying MSE, will carry subcommands with or
186b6e3b9c6SJames Smart  *    without carrying HBDs.
187b6e3b9c6SJames Smart  */
188b6e3b9c6SJames Smart 
189b6e3b9c6SJames Smart struct lpfc_sli_config_mse {
190b6e3b9c6SJames Smart 	uint32_t pa_lo;
191b6e3b9c6SJames Smart 	uint32_t pa_hi;
192b6e3b9c6SJames Smart 	uint32_t buf_len;
193b6e3b9c6SJames Smart #define lpfc_mbox_sli_config_mse_len_SHIFT	0
194b6e3b9c6SJames Smart #define lpfc_mbox_sli_config_mse_len_MASK	0xffffff
195b6e3b9c6SJames Smart #define lpfc_mbox_sli_config_mse_len_WORD	buf_len
196b6e3b9c6SJames Smart };
197b6e3b9c6SJames Smart 
1987ad20aa9SJames Smart struct lpfc_sli_config_hbd {
199b6e3b9c6SJames Smart 	uint32_t buf_len;
200b6e3b9c6SJames Smart #define lpfc_mbox_sli_config_ecmn_hbd_len_SHIFT	0
201b6e3b9c6SJames Smart #define lpfc_mbox_sli_config_ecmn_hbd_len_MASK	0xffffff
202b6e3b9c6SJames Smart #define lpfc_mbox_sli_config_ecmn_hbd_len_WORD	buf_len
203b6e3b9c6SJames Smart 	uint32_t pa_lo;
204b6e3b9c6SJames Smart 	uint32_t pa_hi;
205b6e3b9c6SJames Smart };
206b6e3b9c6SJames Smart 
207b6e3b9c6SJames Smart struct lpfc_sli_config_hdr {
208b6e3b9c6SJames Smart 	uint32_t word1;
209b6e3b9c6SJames Smart #define lpfc_mbox_hdr_emb_SHIFT		0
210b6e3b9c6SJames Smart #define lpfc_mbox_hdr_emb_MASK		0x00000001
211b6e3b9c6SJames Smart #define lpfc_mbox_hdr_emb_WORD		word1
212b6e3b9c6SJames Smart #define lpfc_mbox_hdr_mse_cnt_SHIFT	3
213b6e3b9c6SJames Smart #define lpfc_mbox_hdr_mse_cnt_MASK	0x0000001f
214b6e3b9c6SJames Smart #define lpfc_mbox_hdr_mse_cnt_WORD	word1
215b6e3b9c6SJames Smart 	uint32_t payload_length;
216b6e3b9c6SJames Smart 	uint32_t tag_lo;
217b6e3b9c6SJames Smart 	uint32_t tag_hi;
218b6e3b9c6SJames Smart 	uint32_t reserved5;
219b6e3b9c6SJames Smart };
220b6e3b9c6SJames Smart 
2217ad20aa9SJames Smart struct lpfc_sli_config_emb0_subsys {
222b6e3b9c6SJames Smart 	struct lpfc_sli_config_hdr	sli_config_hdr;
223b6e3b9c6SJames Smart #define LPFC_MBX_SLI_CONFIG_MAX_MSE     19
224b6e3b9c6SJames Smart 	struct lpfc_sli_config_mse	mse[LPFC_MBX_SLI_CONFIG_MAX_MSE];
2257ad20aa9SJames Smart 	uint32_t padding;
2267ad20aa9SJames Smart 	uint32_t word64;
2277ad20aa9SJames Smart #define lpfc_emb0_subcmnd_opcode_SHIFT	0
2287ad20aa9SJames Smart #define lpfc_emb0_subcmnd_opcode_MASK	0xff
2297ad20aa9SJames Smart #define lpfc_emb0_subcmnd_opcode_WORD	word64
2307ad20aa9SJames Smart #define lpfc_emb0_subcmnd_subsys_SHIFT	8
2317ad20aa9SJames Smart #define lpfc_emb0_subcmnd_subsys_MASK	0xff
2327ad20aa9SJames Smart #define lpfc_emb0_subcmnd_subsys_WORD	word64
2337ad20aa9SJames Smart /* Subsystem FCOE (0x0C) OpCodes */
2347ad20aa9SJames Smart #define SLI_CONFIG_SUBSYS_FCOE		0x0C
2357ad20aa9SJames Smart #define FCOE_OPCODE_READ_FCF		0x08
2367ad20aa9SJames Smart #define FCOE_OPCODE_ADD_FCF		0x09
2372a2719d3SJames Smart #define FCOE_OPCODE_SET_DPORT_MODE	0x27
2382a2719d3SJames Smart #define FCOE_OPCODE_GET_DPORT_RESULTS	0x28
239b6e3b9c6SJames Smart };
240b6e3b9c6SJames Smart 
2417ad20aa9SJames Smart struct lpfc_sli_config_emb1_subsys {
242b6e3b9c6SJames Smart 	struct lpfc_sli_config_hdr	sli_config_hdr;
243b6e3b9c6SJames Smart 	uint32_t word6;
2447ad20aa9SJames Smart #define lpfc_emb1_subcmnd_opcode_SHIFT	0
2457ad20aa9SJames Smart #define lpfc_emb1_subcmnd_opcode_MASK	0xff
2467ad20aa9SJames Smart #define lpfc_emb1_subcmnd_opcode_WORD	word6
2477ad20aa9SJames Smart #define lpfc_emb1_subcmnd_subsys_SHIFT	8
2487ad20aa9SJames Smart #define lpfc_emb1_subcmnd_subsys_MASK	0xff
2497ad20aa9SJames Smart #define lpfc_emb1_subcmnd_subsys_WORD	word6
2507ad20aa9SJames Smart /* Subsystem COMN (0x01) OpCodes */
2517ad20aa9SJames Smart #define SLI_CONFIG_SUBSYS_COMN		0x01
252c6377970SJames Smart #define COMN_OPCODE_GET_PROFILE_CONFIG	0xA4
2537ad20aa9SJames Smart #define COMN_OPCODE_READ_OBJECT		0xAB
2547ad20aa9SJames Smart #define COMN_OPCODE_WRITE_OBJECT	0xAC
2557ad20aa9SJames Smart #define COMN_OPCODE_READ_OBJECT_LIST	0xAD
2567ad20aa9SJames Smart #define COMN_OPCODE_DELETE_OBJECT	0xAE
257026abb87SJames Smart #define COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES	0x79
258b99570ddSJames Smart #define COMN_OPCODE_GET_CNTL_ATTRIBUTES	0x20
259b6e3b9c6SJames Smart 	uint32_t timeout;
260b6e3b9c6SJames Smart 	uint32_t request_length;
261b6e3b9c6SJames Smart 	uint32_t word9;
262b6e3b9c6SJames Smart #define lpfc_subcmnd_version_SHIFT	0
263b6e3b9c6SJames Smart #define lpfc_subcmnd_version_MASK	0xff
264b6e3b9c6SJames Smart #define lpfc_subcmnd_version_WORD	word9
265b6e3b9c6SJames Smart 	uint32_t word10;
266b6e3b9c6SJames Smart #define lpfc_subcmnd_ask_rd_len_SHIFT	0
267b6e3b9c6SJames Smart #define lpfc_subcmnd_ask_rd_len_MASK	0xffffff
268b6e3b9c6SJames Smart #define lpfc_subcmnd_ask_rd_len_WORD	word10
269b6e3b9c6SJames Smart 	uint32_t rd_offset;
270b6e3b9c6SJames Smart 	uint32_t obj_name[26];
271b6e3b9c6SJames Smart 	uint32_t hbd_count;
2727ad20aa9SJames Smart #define LPFC_MBX_SLI_CONFIG_MAX_HBD	8
2737ad20aa9SJames Smart 	struct lpfc_sli_config_hbd	hbd[LPFC_MBX_SLI_CONFIG_MAX_HBD];
274b6e3b9c6SJames Smart };
275b6e3b9c6SJames Smart 
276b6e3b9c6SJames Smart struct lpfc_sli_config_mbox {
277b6e3b9c6SJames Smart 	uint32_t word0;
278b6e3b9c6SJames Smart #define lpfc_mqe_status_SHIFT		16
279b6e3b9c6SJames Smart #define lpfc_mqe_status_MASK		0x0000FFFF
280b6e3b9c6SJames Smart #define lpfc_mqe_status_WORD		word0
281b6e3b9c6SJames Smart #define lpfc_mqe_command_SHIFT		8
282b6e3b9c6SJames Smart #define lpfc_mqe_command_MASK		0x000000FF
283b6e3b9c6SJames Smart #define lpfc_mqe_command_WORD		word0
284b6e3b9c6SJames Smart 	union {
2857ad20aa9SJames Smart 		struct lpfc_sli_config_emb0_subsys sli_config_emb0_subsys;
2867ad20aa9SJames Smart 		struct lpfc_sli_config_emb1_subsys sli_config_emb1_subsys;
287b6e3b9c6SJames Smart 	} un;
288b6e3b9c6SJames Smart };
2897ad20aa9SJames Smart 
290c691816eSJames Smart #define LPFC_FORCED_LINK_SPEED_NOT_SUPPORTED	0
291c691816eSJames Smart #define LPFC_FORCED_LINK_SPEED_SUPPORTED	1
292c691816eSJames Smart struct get_forced_link_speed_support {
293c691816eSJames Smart 	uint32_t command;
294c691816eSJames Smart };
295c691816eSJames Smart struct forced_link_speed_support_reply {
296c691816eSJames Smart 	uint8_t supported;
297c691816eSJames Smart };
298c691816eSJames Smart 
2997ad20aa9SJames Smart /* driver only */
3007ad20aa9SJames Smart #define SLI_CONFIG_NOT_HANDLED		0
3017ad20aa9SJames Smart #define SLI_CONFIG_HANDLED		1
302