xref: /openbmc/linux/drivers/scsi/lpfc/lpfc_bsg.h (revision 6d99a79c)
1 /*******************************************************************
2  * This file is part of the Emulex Linux Device Driver for         *
3  * Fibre Channel Host Bus Adapters.                                *
4  * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.     *
6  * Copyright (C) 2010-2015 Emulex.  All rights reserved.           *
7  * EMULEX and SLI are trademarks of Emulex.                        *
8  * www.broadcom.com                                                *
9  *                                                                 *
10  * This program is free software; you can redistribute it and/or   *
11  * modify it under the terms of version 2 of the GNU General       *
12  * Public License as published by the Free Software Foundation.    *
13  * This program is distributed in the hope that it will be useful. *
14  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
15  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
16  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
17  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
19  * more details, a copy of which can be found in the file COPYING  *
20  * included with this package.                                     *
21  *******************************************************************/
22 /* bsg definitions
23  * No pointers to user data are allowed, all application buffers and sizes will
24  * derived through the bsg interface.
25  *
26  * These are the vendor unique structures passed in using the bsg
27  * FC_BSG_HST_VENDOR message code type.
28  */
29 #define LPFC_BSG_VENDOR_SET_CT_EVENT		1
30 #define LPFC_BSG_VENDOR_GET_CT_EVENT		2
31 #define LPFC_BSG_VENDOR_SEND_MGMT_RESP		3
32 #define LPFC_BSG_VENDOR_DIAG_MODE		4
33 #define LPFC_BSG_VENDOR_DIAG_RUN_LOOPBACK	5
34 #define LPFC_BSG_VENDOR_GET_MGMT_REV		6
35 #define LPFC_BSG_VENDOR_MBOX			7
36 #define LPFC_BSG_VENDOR_MENLO_CMD		8
37 #define LPFC_BSG_VENDOR_MENLO_DATA		9
38 #define LPFC_BSG_VENDOR_DIAG_MODE_END		10
39 #define LPFC_BSG_VENDOR_LINK_DIAG_TEST		11
40 #define LPFC_BSG_VENDOR_FORCED_LINK_SPEED	14
41 #define LPFC_BSG_VENDOR_RAS_GET_LWPD		16
42 #define LPFC_BSG_VENDOR_RAS_GET_FWLOG		17
43 #define LPFC_BSG_VENDOR_RAS_GET_CONFIG		18
44 #define LPFC_BSG_VENDOR_RAS_SET_CONFIG		19
45 
46 struct set_ct_event {
47 	uint32_t command;
48 	uint32_t type_mask;
49 	uint32_t ev_req_id;
50 	uint32_t ev_reg_id;
51 };
52 
53 struct get_ct_event {
54 	uint32_t command;
55 	uint32_t ev_reg_id;
56 	uint32_t ev_req_id;
57 };
58 
59 struct get_ct_event_reply {
60 	uint32_t immed_data;
61 	uint32_t type;
62 };
63 
64 struct send_mgmt_resp {
65 	uint32_t command;
66 	uint32_t tag;
67 };
68 
69 
70 #define INTERNAL_LOOP_BACK 0x1 /* adapter short cuts the loop internally */
71 #define EXTERNAL_LOOP_BACK 0x2 /* requires an external loopback plug */
72 
73 struct diag_mode_set {
74 	uint32_t command;
75 	uint32_t type;
76 	uint32_t timeout;
77 };
78 
79 struct sli4_link_diag {
80 	uint32_t command;
81 	uint32_t timeout;
82 	uint32_t test_id;
83 	uint32_t loops;
84 	uint32_t test_version;
85 	uint32_t error_action;
86 };
87 
88 struct diag_mode_test {
89 	uint32_t command;
90 };
91 
92 struct diag_status {
93 	uint32_t mbox_status;
94 	uint32_t shdr_status;
95 	uint32_t shdr_add_status;
96 };
97 
98 #define LPFC_WWNN_TYPE		0
99 #define LPFC_WWPN_TYPE		1
100 
101 struct get_mgmt_rev {
102 	uint32_t command;
103 };
104 
105 #define MANAGEMENT_MAJOR_REV   1
106 #define MANAGEMENT_MINOR_REV   1
107 
108 /* the MgmtRevInfo structure */
109 struct MgmtRevInfo {
110 	uint32_t a_Major;
111 	uint32_t a_Minor;
112 };
113 
114 struct get_mgmt_rev_reply {
115 	struct MgmtRevInfo info;
116 };
117 
118 #define BSG_MBOX_SIZE 4096 /* mailbox command plus extended data */
119 
120 /* BSG mailbox request header */
121 struct dfc_mbox_req {
122 	uint32_t command;
123 	uint32_t mbOffset;
124 	uint32_t inExtWLen;
125 	uint32_t outExtWLen;
126 	uint32_t extMboxTag;
127 	uint32_t extSeqNum;
128 };
129 
130 /* Used for menlo command or menlo data. The xri is only used for menlo data */
131 struct menlo_command {
132 	uint32_t cmd;
133 	uint32_t xri;
134 };
135 
136 struct menlo_response {
137 	uint32_t xri; /* return the xri of the iocb exchange */
138 };
139 
140 /*
141  * macros and data structures for handling sli-config mailbox command
142  * pass-through support, this header file is shared between user and
143  * kernel spaces, note the set of macros are duplicates from lpfc_hw4.h,
144  * with macro names prefixed with bsg_, as the macros defined in
145  * lpfc_hw4.h are not accessible from user space.
146  */
147 
148 /* Macros to deal with bit fields. Each bit field must have 3 #defines
149  * associated with it (_SHIFT, _MASK, and _WORD).
150  * EG. For a bit field that is in the 7th bit of the "field4" field of a
151  * structure and is 2 bits in size the following #defines must exist:
152  *      struct temp {
153  *              uint32_t        field1;
154  *              uint32_t        field2;
155  *              uint32_t        field3;
156  *              uint32_t        field4;
157  *      #define example_bit_field_SHIFT         7
158  *      #define example_bit_field_MASK          0x03
159  *      #define example_bit_field_WORD          field4
160  *              uint32_t        field5;
161  *      };
162  * Then the macros below may be used to get or set the value of that field.
163  * EG. To get the value of the bit field from the above example:
164  *      struct temp t1;
165  *      value = bsg_bf_get(example_bit_field, &t1);
166  * And then to set that bit field:
167  *      bsg_bf_set(example_bit_field, &t1, 2);
168  * Or clear that bit field:
169  *      bsg_bf_set(example_bit_field, &t1, 0);
170  */
171 #define bsg_bf_get_le32(name, ptr) \
172 	((le32_to_cpu((ptr)->name##_WORD) >> name##_SHIFT) & name##_MASK)
173 #define bsg_bf_get(name, ptr) \
174 	(((ptr)->name##_WORD >> name##_SHIFT) & name##_MASK)
175 #define bsg_bf_set_le32(name, ptr, value) \
176 	((ptr)->name##_WORD = cpu_to_le32(((((value) & \
177 	name##_MASK) << name##_SHIFT) | (le32_to_cpu((ptr)->name##_WORD) & \
178 	~(name##_MASK << name##_SHIFT)))))
179 #define bsg_bf_set(name, ptr, value) \
180 	((ptr)->name##_WORD = ((((value) & name##_MASK) << name##_SHIFT) | \
181 	((ptr)->name##_WORD & ~(name##_MASK << name##_SHIFT))))
182 
183 /*
184  * The sli_config structure specified here is based on the following
185  * restriction:
186  *
187  * -- SLI_CONFIG EMB=0, carrying MSEs, will carry subcommands without
188  *    carrying HBD.
189  * -- SLI_CONFIG EMB=1, not carrying MSE, will carry subcommands with or
190  *    without carrying HBDs.
191  */
192 
193 struct lpfc_sli_config_mse {
194 	uint32_t pa_lo;
195 	uint32_t pa_hi;
196 	uint32_t buf_len;
197 #define lpfc_mbox_sli_config_mse_len_SHIFT	0
198 #define lpfc_mbox_sli_config_mse_len_MASK	0xffffff
199 #define lpfc_mbox_sli_config_mse_len_WORD	buf_len
200 };
201 
202 struct lpfc_sli_config_hbd {
203 	uint32_t buf_len;
204 #define lpfc_mbox_sli_config_ecmn_hbd_len_SHIFT	0
205 #define lpfc_mbox_sli_config_ecmn_hbd_len_MASK	0xffffff
206 #define lpfc_mbox_sli_config_ecmn_hbd_len_WORD	buf_len
207 	uint32_t pa_lo;
208 	uint32_t pa_hi;
209 };
210 
211 struct lpfc_sli_config_hdr {
212 	uint32_t word1;
213 #define lpfc_mbox_hdr_emb_SHIFT		0
214 #define lpfc_mbox_hdr_emb_MASK		0x00000001
215 #define lpfc_mbox_hdr_emb_WORD		word1
216 #define lpfc_mbox_hdr_mse_cnt_SHIFT	3
217 #define lpfc_mbox_hdr_mse_cnt_MASK	0x0000001f
218 #define lpfc_mbox_hdr_mse_cnt_WORD	word1
219 	uint32_t payload_length;
220 	uint32_t tag_lo;
221 	uint32_t tag_hi;
222 	uint32_t reserved5;
223 };
224 
225 struct lpfc_sli_config_emb0_subsys {
226 	struct lpfc_sli_config_hdr	sli_config_hdr;
227 #define LPFC_MBX_SLI_CONFIG_MAX_MSE     19
228 	struct lpfc_sli_config_mse	mse[LPFC_MBX_SLI_CONFIG_MAX_MSE];
229 	uint32_t padding;
230 	uint32_t word64;
231 #define lpfc_emb0_subcmnd_opcode_SHIFT	0
232 #define lpfc_emb0_subcmnd_opcode_MASK	0xff
233 #define lpfc_emb0_subcmnd_opcode_WORD	word64
234 #define lpfc_emb0_subcmnd_subsys_SHIFT	8
235 #define lpfc_emb0_subcmnd_subsys_MASK	0xff
236 #define lpfc_emb0_subcmnd_subsys_WORD	word64
237 /* Subsystem FCOE (0x0C) OpCodes */
238 #define SLI_CONFIG_SUBSYS_FCOE		0x0C
239 #define FCOE_OPCODE_READ_FCF		0x08
240 #define FCOE_OPCODE_ADD_FCF		0x09
241 #define FCOE_OPCODE_SET_DPORT_MODE	0x27
242 #define FCOE_OPCODE_GET_DPORT_RESULTS	0x28
243 };
244 
245 struct lpfc_sli_config_emb1_subsys {
246 	struct lpfc_sli_config_hdr	sli_config_hdr;
247 	uint32_t word6;
248 #define lpfc_emb1_subcmnd_opcode_SHIFT	0
249 #define lpfc_emb1_subcmnd_opcode_MASK	0xff
250 #define lpfc_emb1_subcmnd_opcode_WORD	word6
251 #define lpfc_emb1_subcmnd_subsys_SHIFT	8
252 #define lpfc_emb1_subcmnd_subsys_MASK	0xff
253 #define lpfc_emb1_subcmnd_subsys_WORD	word6
254 /* Subsystem COMN (0x01) OpCodes */
255 #define SLI_CONFIG_SUBSYS_COMN		0x01
256 #define COMN_OPCODE_GET_PROFILE_CONFIG	0xA4
257 #define COMN_OPCODE_READ_OBJECT		0xAB
258 #define COMN_OPCODE_WRITE_OBJECT	0xAC
259 #define COMN_OPCODE_READ_OBJECT_LIST	0xAD
260 #define COMN_OPCODE_DELETE_OBJECT	0xAE
261 #define COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES	0x79
262 #define COMN_OPCODE_GET_CNTL_ATTRIBUTES	0x20
263 	uint32_t timeout;
264 	uint32_t request_length;
265 	uint32_t word9;
266 #define lpfc_subcmnd_version_SHIFT	0
267 #define lpfc_subcmnd_version_MASK	0xff
268 #define lpfc_subcmnd_version_WORD	word9
269 	uint32_t word10;
270 #define lpfc_subcmnd_ask_rd_len_SHIFT	0
271 #define lpfc_subcmnd_ask_rd_len_MASK	0xffffff
272 #define lpfc_subcmnd_ask_rd_len_WORD	word10
273 	uint32_t rd_offset;
274 	uint32_t obj_name[26];
275 	uint32_t hbd_count;
276 #define LPFC_MBX_SLI_CONFIG_MAX_HBD	8
277 	struct lpfc_sli_config_hbd	hbd[LPFC_MBX_SLI_CONFIG_MAX_HBD];
278 };
279 
280 struct lpfc_sli_config_mbox {
281 	uint32_t word0;
282 #define lpfc_mqe_status_SHIFT		16
283 #define lpfc_mqe_status_MASK		0x0000FFFF
284 #define lpfc_mqe_status_WORD		word0
285 #define lpfc_mqe_command_SHIFT		8
286 #define lpfc_mqe_command_MASK		0x000000FF
287 #define lpfc_mqe_command_WORD		word0
288 	union {
289 		struct lpfc_sli_config_emb0_subsys sli_config_emb0_subsys;
290 		struct lpfc_sli_config_emb1_subsys sli_config_emb1_subsys;
291 	} un;
292 };
293 
294 #define LPFC_FORCED_LINK_SPEED_NOT_SUPPORTED	0
295 #define LPFC_FORCED_LINK_SPEED_SUPPORTED	1
296 struct get_forced_link_speed_support {
297 	uint32_t command;
298 };
299 struct forced_link_speed_support_reply {
300 	uint8_t supported;
301 };
302 
303 struct lpfc_bsg_ras_req {
304 	uint32_t command;
305 };
306 
307 struct lpfc_bsg_get_fwlog_req {
308 	uint32_t command;
309 	uint32_t read_size;
310 	uint32_t read_offset;
311 };
312 
313 struct lpfc_bsg_get_ras_lwpd {
314 	uint32_t offset;
315 	uint32_t wrap_count;
316 };
317 
318 struct lpfc_bsg_set_ras_config_req {
319 	uint32_t command;
320 	uint8_t action;
321 #define LPFC_RASACTION_STOP_LOGGING     0x00
322 #define LPFC_RASACTION_START_LOGGING    0x01
323 	uint8_t log_level;
324 };
325 
326 struct lpfc_bsg_get_ras_config_reply {
327 	uint8_t state;
328 #define LPFC_RASLOG_STATE_STOPPED 0x00
329 #define LPFC_RASLOG_STATE_RUNNING 0x01
330 	uint8_t log_level;
331 	uint32_t log_buff_sz;
332 };
333 
334 
335 /* driver only */
336 #define SLI_CONFIG_NOT_HANDLED		0
337 #define SLI_CONFIG_HANDLED		1
338