xref: /linux/drivers/scsi/lpfc/lpfc_bsg.h (revision d003d772e64df08af04ee63609d47169ee82ae0e)
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 #define LPFC_BSG_VENDOR_GET_TRUNK_INFO		20
46 
47 struct set_ct_event {
48 	uint32_t command;
49 	uint32_t type_mask;
50 	uint32_t ev_req_id;
51 	uint32_t ev_reg_id;
52 };
53 
54 struct get_ct_event {
55 	uint32_t command;
56 	uint32_t ev_reg_id;
57 	uint32_t ev_req_id;
58 };
59 
60 struct get_ct_event_reply {
61 	uint32_t immed_data;
62 	uint32_t type;
63 };
64 
65 struct send_mgmt_resp {
66 	uint32_t command;
67 	uint32_t tag;
68 };
69 
70 
71 #define INTERNAL_LOOP_BACK 0x1 /* adapter short cuts the loop internally */
72 #define EXTERNAL_LOOP_BACK 0x2 /* requires an external loopback plug */
73 
74 struct diag_mode_set {
75 	uint32_t command;
76 	uint32_t type;
77 	uint32_t timeout;
78 };
79 
80 struct sli4_link_diag {
81 	uint32_t command;
82 	uint32_t timeout;
83 	uint32_t test_id;
84 	uint32_t loops;
85 	uint32_t test_version;
86 	uint32_t error_action;
87 };
88 
89 struct diag_mode_test {
90 	uint32_t command;
91 };
92 
93 struct diag_status {
94 	uint32_t mbox_status;
95 	uint32_t shdr_status;
96 	uint32_t shdr_add_status;
97 };
98 
99 #define LPFC_WWNN_TYPE		0
100 #define LPFC_WWPN_TYPE		1
101 
102 struct get_mgmt_rev {
103 	uint32_t command;
104 };
105 
106 #define MANAGEMENT_MAJOR_REV   1
107 #define MANAGEMENT_MINOR_REV   1
108 
109 /* the MgmtRevInfo structure */
110 struct MgmtRevInfo {
111 	uint32_t a_Major;
112 	uint32_t a_Minor;
113 };
114 
115 struct get_mgmt_rev_reply {
116 	struct MgmtRevInfo info;
117 };
118 
119 #define BSG_MBOX_SIZE 4096 /* mailbox command plus extended data */
120 
121 /* BSG mailbox request header */
122 struct dfc_mbox_req {
123 	uint32_t command;
124 	uint32_t mbOffset;
125 	uint32_t inExtWLen;
126 	uint32_t outExtWLen;
127 	uint32_t extMboxTag;
128 	uint32_t extSeqNum;
129 };
130 
131 /* Used for menlo command or menlo data. The xri is only used for menlo data */
132 struct menlo_command {
133 	uint32_t cmd;
134 	uint32_t xri;
135 };
136 
137 struct menlo_response {
138 	uint32_t xri; /* return the xri of the iocb exchange */
139 };
140 
141 /*
142  * macros and data structures for handling sli-config mailbox command
143  * pass-through support, this header file is shared between user and
144  * kernel spaces, note the set of macros are duplicates from lpfc_hw4.h,
145  * with macro names prefixed with bsg_, as the macros defined in
146  * lpfc_hw4.h are not accessible from user space.
147  */
148 
149 /* Macros to deal with bit fields. Each bit field must have 3 #defines
150  * associated with it (_SHIFT, _MASK, and _WORD).
151  * EG. For a bit field that is in the 7th bit of the "field4" field of a
152  * structure and is 2 bits in size the following #defines must exist:
153  *      struct temp {
154  *              uint32_t        field1;
155  *              uint32_t        field2;
156  *              uint32_t        field3;
157  *              uint32_t        field4;
158  *      #define example_bit_field_SHIFT         7
159  *      #define example_bit_field_MASK          0x03
160  *      #define example_bit_field_WORD          field4
161  *              uint32_t        field5;
162  *      };
163  * Then the macros below may be used to get or set the value of that field.
164  * EG. To get the value of the bit field from the above example:
165  *      struct temp t1;
166  *      value = bsg_bf_get(example_bit_field, &t1);
167  * And then to set that bit field:
168  *      bsg_bf_set(example_bit_field, &t1, 2);
169  * Or clear that bit field:
170  *      bsg_bf_set(example_bit_field, &t1, 0);
171  */
172 #define bsg_bf_get_le32(name, ptr) \
173 	((le32_to_cpu((ptr)->name##_WORD) >> name##_SHIFT) & name##_MASK)
174 #define bsg_bf_get(name, ptr) \
175 	(((ptr)->name##_WORD >> name##_SHIFT) & name##_MASK)
176 #define bsg_bf_set_le32(name, ptr, value) \
177 	((ptr)->name##_WORD = cpu_to_le32(((((value) & \
178 	name##_MASK) << name##_SHIFT) | (le32_to_cpu((ptr)->name##_WORD) & \
179 	~(name##_MASK << name##_SHIFT)))))
180 #define bsg_bf_set(name, ptr, value) \
181 	((ptr)->name##_WORD = ((((value) & name##_MASK) << name##_SHIFT) | \
182 	((ptr)->name##_WORD & ~(name##_MASK << name##_SHIFT))))
183 
184 /*
185  * The sli_config structure specified here is based on the following
186  * restriction:
187  *
188  * -- SLI_CONFIG EMB=0, carrying MSEs, will carry subcommands without
189  *    carrying HBD.
190  * -- SLI_CONFIG EMB=1, not carrying MSE, will carry subcommands with or
191  *    without carrying HBDs.
192  */
193 
194 struct lpfc_sli_config_mse {
195 	uint32_t pa_lo;
196 	uint32_t pa_hi;
197 	uint32_t buf_len;
198 #define lpfc_mbox_sli_config_mse_len_SHIFT	0
199 #define lpfc_mbox_sli_config_mse_len_MASK	0xffffff
200 #define lpfc_mbox_sli_config_mse_len_WORD	buf_len
201 };
202 
203 struct lpfc_sli_config_hbd {
204 	uint32_t buf_len;
205 #define lpfc_mbox_sli_config_ecmn_hbd_len_SHIFT	0
206 #define lpfc_mbox_sli_config_ecmn_hbd_len_MASK	0xffffff
207 #define lpfc_mbox_sli_config_ecmn_hbd_len_WORD	buf_len
208 	uint32_t pa_lo;
209 	uint32_t pa_hi;
210 };
211 
212 struct lpfc_sli_config_hdr {
213 	uint32_t word1;
214 #define lpfc_mbox_hdr_emb_SHIFT		0
215 #define lpfc_mbox_hdr_emb_MASK		0x00000001
216 #define lpfc_mbox_hdr_emb_WORD		word1
217 #define lpfc_mbox_hdr_mse_cnt_SHIFT	3
218 #define lpfc_mbox_hdr_mse_cnt_MASK	0x0000001f
219 #define lpfc_mbox_hdr_mse_cnt_WORD	word1
220 	uint32_t payload_length;
221 	uint32_t tag_lo;
222 	uint32_t tag_hi;
223 	uint32_t reserved5;
224 };
225 
226 struct lpfc_sli_config_emb0_subsys {
227 	struct lpfc_sli_config_hdr	sli_config_hdr;
228 #define LPFC_MBX_SLI_CONFIG_MAX_MSE     19
229 	struct lpfc_sli_config_mse	mse[LPFC_MBX_SLI_CONFIG_MAX_MSE];
230 	uint32_t padding;
231 	uint32_t word64;
232 #define lpfc_emb0_subcmnd_opcode_SHIFT	0
233 #define lpfc_emb0_subcmnd_opcode_MASK	0xff
234 #define lpfc_emb0_subcmnd_opcode_WORD	word64
235 #define lpfc_emb0_subcmnd_subsys_SHIFT	8
236 #define lpfc_emb0_subcmnd_subsys_MASK	0xff
237 #define lpfc_emb0_subcmnd_subsys_WORD	word64
238 /* Subsystem FCOE (0x0C) OpCodes */
239 #define SLI_CONFIG_SUBSYS_FCOE		0x0C
240 #define FCOE_OPCODE_READ_FCF		0x08
241 #define FCOE_OPCODE_ADD_FCF		0x09
242 #define FCOE_OPCODE_SET_DPORT_MODE	0x27
243 #define FCOE_OPCODE_GET_DPORT_RESULTS	0x28
244 };
245 
246 struct lpfc_sli_config_emb1_subsys {
247 	struct lpfc_sli_config_hdr	sli_config_hdr;
248 	uint32_t word6;
249 #define lpfc_emb1_subcmnd_opcode_SHIFT	0
250 #define lpfc_emb1_subcmnd_opcode_MASK	0xff
251 #define lpfc_emb1_subcmnd_opcode_WORD	word6
252 #define lpfc_emb1_subcmnd_subsys_SHIFT	8
253 #define lpfc_emb1_subcmnd_subsys_MASK	0xff
254 #define lpfc_emb1_subcmnd_subsys_WORD	word6
255 /* Subsystem COMN (0x01) OpCodes */
256 #define SLI_CONFIG_SUBSYS_COMN		0x01
257 #define COMN_OPCODE_GET_PROFILE_CONFIG	0xA4
258 #define COMN_OPCODE_READ_OBJECT		0xAB
259 #define COMN_OPCODE_WRITE_OBJECT	0xAC
260 #define COMN_OPCODE_READ_OBJECT_LIST	0xAD
261 #define COMN_OPCODE_DELETE_OBJECT	0xAE
262 #define COMN_OPCODE_GET_CNTL_ADDL_ATTRIBUTES	0x79
263 #define COMN_OPCODE_GET_CNTL_ATTRIBUTES	0x20
264 	uint32_t timeout;
265 	uint32_t request_length;
266 	uint32_t word9;
267 #define lpfc_subcmnd_version_SHIFT	0
268 #define lpfc_subcmnd_version_MASK	0xff
269 #define lpfc_subcmnd_version_WORD	word9
270 	uint32_t word10;
271 #define lpfc_subcmnd_ask_rd_len_SHIFT	0
272 #define lpfc_subcmnd_ask_rd_len_MASK	0xffffff
273 #define lpfc_subcmnd_ask_rd_len_WORD	word10
274 	uint32_t rd_offset;
275 	uint32_t obj_name[26];
276 	uint32_t hbd_count;
277 #define LPFC_MBX_SLI_CONFIG_MAX_HBD	8
278 	struct lpfc_sli_config_hbd	hbd[LPFC_MBX_SLI_CONFIG_MAX_HBD];
279 };
280 
281 struct lpfc_sli_config_mbox {
282 	uint32_t word0;
283 #define lpfc_mqe_status_SHIFT		16
284 #define lpfc_mqe_status_MASK		0x0000FFFF
285 #define lpfc_mqe_status_WORD		word0
286 #define lpfc_mqe_command_SHIFT		8
287 #define lpfc_mqe_command_MASK		0x000000FF
288 #define lpfc_mqe_command_WORD		word0
289 	union {
290 		struct lpfc_sli_config_emb0_subsys sli_config_emb0_subsys;
291 		struct lpfc_sli_config_emb1_subsys sli_config_emb1_subsys;
292 	} un;
293 };
294 
295 #define LPFC_FORCED_LINK_SPEED_NOT_SUPPORTED	0
296 #define LPFC_FORCED_LINK_SPEED_SUPPORTED	1
297 struct get_forced_link_speed_support {
298 	uint32_t command;
299 };
300 struct forced_link_speed_support_reply {
301 	uint8_t supported;
302 };
303 
304 struct lpfc_bsg_ras_req {
305 	uint32_t command;
306 };
307 
308 struct lpfc_bsg_get_fwlog_req {
309 	uint32_t command;
310 	uint32_t read_size;
311 	uint32_t read_offset;
312 };
313 
314 struct lpfc_bsg_get_ras_lwpd {
315 	uint32_t offset;
316 	uint32_t wrap_count;
317 };
318 
319 struct lpfc_bsg_set_ras_config_req {
320 	uint32_t command;
321 	uint8_t action;
322 #define LPFC_RASACTION_STOP_LOGGING     0x00
323 #define LPFC_RASACTION_START_LOGGING    0x01
324 	uint8_t log_level;
325 };
326 
327 struct lpfc_bsg_get_ras_config_reply {
328 	uint8_t state;
329 #define LPFC_RASLOG_STATE_STOPPED 0x00
330 #define LPFC_RASLOG_STATE_RUNNING 0x01
331 	uint8_t log_level;
332 	uint32_t log_buff_sz;
333 };
334 
335 struct lpfc_trunk_info {
336 	uint32_t word0;
337 #define lpfc_trunk_info_link_status_SHIFT      0
338 #define lpfc_trunk_info_link_status_MASK       1
339 #define lpfc_trunk_info_link_status_WORD       word0
340 #define lpfc_trunk_info_trunk_active0_SHIFT    8
341 #define lpfc_trunk_info_trunk_active0_MASK     1
342 #define lpfc_trunk_info_trunk_active0_WORD     word0
343 #define lpfc_trunk_info_trunk_active1_SHIFT    9
344 #define lpfc_trunk_info_trunk_active1_MASK     1
345 #define lpfc_trunk_info_trunk_active1_WORD     word0
346 #define lpfc_trunk_info_trunk_active2_SHIFT    10
347 #define lpfc_trunk_info_trunk_active2_MASK     1
348 #define lpfc_trunk_info_trunk_active2_WORD     word0
349 #define lpfc_trunk_info_trunk_active3_SHIFT    11
350 #define lpfc_trunk_info_trunk_active3_MASK     1
351 #define lpfc_trunk_info_trunk_active3_WORD     word0
352 #define lpfc_trunk_info_trunk_config0_SHIFT    12
353 #define lpfc_trunk_info_trunk_config0_MASK     1
354 #define lpfc_trunk_info_trunk_config0_WORD     word0
355 #define lpfc_trunk_info_trunk_config1_SHIFT    13
356 #define lpfc_trunk_info_trunk_config1_MASK     1
357 #define lpfc_trunk_info_trunk_config1_WORD     word0
358 #define lpfc_trunk_info_trunk_config2_SHIFT    14
359 #define lpfc_trunk_info_trunk_config2_MASK     1
360 #define lpfc_trunk_info_trunk_config2_WORD     word0
361 #define lpfc_trunk_info_trunk_config3_SHIFT    15
362 #define lpfc_trunk_info_trunk_config3_MASK     1
363 #define lpfc_trunk_info_trunk_config3_WORD     word0
364 	uint16_t    port_speed;
365 	uint16_t    logical_speed;
366 	uint32_t    reserved3;
367 };
368 
369 struct get_trunk_info_req {
370 	uint32_t command;
371 };
372 
373 /* driver only */
374 #define SLI_CONFIG_NOT_HANDLED		0
375 #define SLI_CONFIG_HANDLED		1
376