Commit | Line | Data |
---|---|---|
c8806b6c NM |
1 | /* |
2 | * Copyright 2014 Cisco Systems, Inc. All rights reserved. | |
3 | * | |
4 | * This program is free software; you may redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; version 2 of the License. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
9 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
10 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
11 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
12 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
14 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
15 | * SOFTWARE. | |
16 | */ | |
17 | ||
18 | #ifndef __SNIC_FWINT_H | |
19 | #define __SNIC_FWINT_H | |
20 | ||
21 | #define SNIC_CDB_LEN 32 /* SCSI CDB size 32, can be used for 16 bytes */ | |
22 | #define LUN_ADDR_LEN 8 | |
23 | ||
24 | /* | |
25 | * Command entry type | |
26 | */ | |
27 | enum snic_io_type { | |
28 | /* | |
29 | * Initiator request types | |
30 | */ | |
31 | SNIC_REQ_REPORT_TGTS = 0x2, /* Report Targets */ | |
32 | SNIC_REQ_ICMND, /* Initiator command for SCSI IO */ | |
33 | SNIC_REQ_ITMF, /* Initiator command for Task Mgmt */ | |
34 | SNIC_REQ_HBA_RESET, /* SNIC Reset */ | |
35 | SNIC_REQ_EXCH_VER, /* Exchange Version Information */ | |
36 | SNIC_REQ_TGT_INFO, /* Backend/Target Information */ | |
37 | SNIC_REQ_BOOT_LUNS, | |
38 | ||
39 | /* | |
40 | * Response type | |
41 | */ | |
42 | SNIC_RSP_REPORT_TGTS_CMPL = 0x12,/* Report Targets Completion */ | |
43 | SNIC_RSP_ICMND_CMPL, /* SCSI IO Completion */ | |
44 | SNIC_RSP_ITMF_CMPL, /* Task Management Completion */ | |
45 | SNIC_RSP_HBA_RESET_CMPL, /* SNIC Reset Completion */ | |
46 | SNIC_RSP_EXCH_VER_CMPL, /* Exchange Version Completion*/ | |
47 | SNIC_RSP_BOOT_LUNS_CMPL, | |
48 | ||
49 | /* | |
50 | * Misc Request types | |
51 | */ | |
52 | SNIC_MSG_ACK = 0x80, /* Ack: snic_notify_msg */ | |
53 | SNIC_MSG_ASYNC_EVNOTIFY, /* Asynchronous Event Notification */ | |
54 | }; /* end of enum snic_io_type */ | |
55 | ||
56 | ||
57 | /* | |
58 | * Header status codes from firmware | |
59 | */ | |
60 | enum snic_io_status { | |
61 | SNIC_STAT_IO_SUCCESS = 0, /* request was successful */ | |
62 | ||
63 | /* | |
64 | * If a request to the fw is rejected, the original request header | |
65 | * will be returned with the status set to one of the following: | |
66 | */ | |
67 | SNIC_STAT_INVALID_HDR, /* header contains invalid data */ | |
68 | SNIC_STAT_OUT_OF_RES, /* out of resources to complete request */ | |
69 | SNIC_STAT_INVALID_PARM, /* some parameter in request is not valid */ | |
70 | SNIC_STAT_REQ_NOT_SUP, /* req type is not supported */ | |
71 | SNIC_STAT_IO_NOT_FOUND, /* requested IO was not found */ | |
72 | ||
73 | /* | |
74 | * Once a request is processed, the fw will usually return | |
75 | * a cmpl message type. In cases where errors occurred, | |
76 | * the header status would be filled in with one of the following: | |
77 | */ | |
78 | SNIC_STAT_ABORTED, /* req was aborted */ | |
79 | SNIC_STAT_TIMEOUT, /* req was timed out */ | |
80 | SNIC_STAT_SGL_INVALID, /* req was aborted due to sgl error */ | |
81 | SNIC_STAT_DATA_CNT_MISMATCH, /*recv/sent more/less data than expec */ | |
82 | SNIC_STAT_FW_ERR, /* req was terminated due to fw error */ | |
83 | SNIC_STAT_ITMF_REJECT, /* itmf req was rejected by target */ | |
84 | SNIC_STAT_ITMF_FAIL, /* itmf req was failed */ | |
85 | SNIC_STAT_ITMF_INCORRECT_LUN, /* itmf req has incorrect LUN id*/ | |
86 | SNIC_STAT_CMND_REJECT, /* req was invalid and rejected */ | |
87 | SNIC_STAT_DEV_OFFLINE, /* req sent to offline device */ | |
88 | SNIC_STAT_NO_BOOTLUN, | |
89 | SNIC_STAT_SCSI_ERR, /* SCSI error returned by Target. */ | |
90 | SNIC_STAT_NOT_READY, /* sNIC Subsystem is not ready */ | |
91 | SNIC_STAT_FATAL_ERROR, /* sNIC is in unrecoverable state */ | |
92 | }; /* end of enum snic_io_status */ | |
93 | ||
94 | /* | |
95 | * snic_io_hdr : host <--> firmare | |
96 | * | |
97 | * for any other message that will be queued to firmware should | |
98 | * have the following request header | |
99 | */ | |
100 | struct snic_io_hdr { | |
101 | __le32 hid; | |
102 | __le32 cmnd_id; /* tag here */ | |
103 | ulong init_ctx; /* initiator context */ | |
104 | u8 type; /* request/response type */ | |
105 | u8 status; /* header status entry */ | |
106 | u8 protocol; /* Protocol specific, may needed for RoCE*/ | |
107 | u8 flags; | |
108 | __le16 sg_cnt; | |
109 | u16 resvd; | |
110 | }; | |
111 | ||
112 | /* auxillary funciton for encoding the snic_io_hdr */ | |
113 | static inline void | |
114 | snic_io_hdr_enc(struct snic_io_hdr *hdr, u8 typ, u8 status, u32 id, u32 hid, | |
115 | u16 sg_cnt, ulong ctx) | |
116 | { | |
117 | hdr->type = typ; | |
118 | hdr->status = status; | |
119 | hdr->protocol = 0; | |
120 | hdr->hid = cpu_to_le32(hid); | |
121 | hdr->cmnd_id = cpu_to_le32(id); | |
122 | hdr->sg_cnt = cpu_to_le16(sg_cnt); | |
123 | hdr->init_ctx = ctx; | |
124 | hdr->flags = 0; | |
125 | } | |
126 | ||
127 | /* auxillary funciton for decoding the snic_io_hdr */ | |
128 | static inline void | |
129 | snic_io_hdr_dec(struct snic_io_hdr *hdr, u8 *typ, u8 *stat, u32 *cmnd_id, | |
130 | u32 *hid, ulong *ctx) | |
131 | { | |
132 | *typ = hdr->type; | |
133 | *stat = hdr->status; | |
134 | *hid = le32_to_cpu(hdr->hid); | |
135 | *cmnd_id = le32_to_cpu(hdr->cmnd_id); | |
136 | *ctx = hdr->init_ctx; | |
137 | } | |
138 | ||
139 | /* | |
140 | * snic_host_info: host -> firmware | |
141 | * | |
142 | * Used for sending host information to firmware, and request fw version | |
143 | */ | |
144 | struct snic_exch_ver_req { | |
145 | __le32 drvr_ver; /* for debugging, when fw dump captured */ | |
146 | __le32 os_type; /* for OS specific features */ | |
147 | }; | |
148 | ||
149 | /* | |
150 | * os_type flags | |
151 | * Bit 0-7 : OS information | |
152 | * Bit 8-31: Feature/Capability Information | |
153 | */ | |
154 | #define SNIC_OS_LINUX 0x1 | |
155 | #define SNIC_OS_WIN 0x2 | |
156 | #define SNIC_OS_ESX 0x3 | |
157 | ||
158 | /* | |
159 | * HBA Capabilities | |
160 | * Bit 1: Reserved. | |
161 | * Bit 2: Dynamic Discovery of LUNs. | |
162 | * Bit 3: Async event notifications on on tgt online/offline events. | |
163 | * Bit 4: IO timeout support in FW. | |
164 | * Bit 5-31: Reserved. | |
165 | */ | |
166 | #define SNIC_HBA_CAP_DDL 0x02 /* Supports Dynamic Discovery of LUNs */ | |
167 | #define SNIC_HBA_CAP_AEN 0x04 /* Supports Async Event Noitifcation */ | |
168 | #define SNIC_HBA_CAP_TMO 0x08 /* Supports IO timeout in FW */ | |
169 | ||
170 | /* | |
171 | * snic_exch_ver_rsp : firmware -> host | |
172 | * | |
173 | * Used by firmware to send response to version request | |
174 | */ | |
175 | struct snic_exch_ver_rsp { | |
176 | __le32 version; | |
177 | __le32 hid; | |
178 | __le32 max_concur_ios; /* max concurrent ios */ | |
179 | __le32 max_sgs_per_cmd; /* max sgls per IO */ | |
180 | __le32 max_io_sz; /* max io size supported */ | |
181 | __le32 hba_cap; /* hba capabilities */ | |
182 | __le32 max_tgts; /* max tgts supported */ | |
183 | __le16 io_timeout; /* FW extended timeout */ | |
184 | u16 rsvd; | |
185 | }; | |
186 | ||
187 | ||
188 | /* | |
189 | * snic_report_tgts : host -> firmware request | |
190 | * | |
191 | * Used by the host to request list of targets | |
192 | */ | |
193 | struct snic_report_tgts { | |
194 | __le16 sg_cnt; | |
195 | __le16 flags; /* specific flags from fw */ | |
196 | u8 _resvd[4]; | |
197 | __le64 sg_addr; /* Points to SGL */ | |
198 | __le64 sense_addr; | |
199 | }; | |
200 | ||
201 | enum snic_type { | |
202 | SNIC_NONE = 0x0, | |
203 | SNIC_DAS, | |
204 | SNIC_SAN, | |
205 | }; | |
206 | ||
207 | ||
208 | /* Report Target Response */ | |
209 | enum snic_tgt_type { | |
210 | SNIC_TGT_NONE = 0x0, | |
211 | SNIC_TGT_DAS, /* DAS Target */ | |
212 | SNIC_TGT_SAN, /* SAN Target */ | |
213 | }; | |
214 | ||
215 | /* target id format */ | |
216 | struct snic_tgt_id { | |
217 | __le32 tgt_id; /* target id */ | |
218 | __le16 tgt_type; /* tgt type */ | |
219 | __le16 vnic_id; /* corresponding vnic id */ | |
220 | }; | |
221 | ||
222 | /* | |
223 | * snic_report_tgts_cmpl : firmware -> host response | |
224 | * | |
225 | * Used by firmware to send response to Report Targets request | |
226 | */ | |
227 | struct snic_report_tgts_cmpl { | |
228 | __le32 tgt_cnt; /* Number of Targets accessible */ | |
229 | u32 _resvd; | |
230 | }; | |
231 | ||
232 | /* | |
233 | * Command flags | |
234 | * | |
235 | * Bit 0: Read flags | |
236 | * Bit 1: Write flag | |
237 | * Bit 2: ESGL - sg/esg array contains extended sg | |
238 | * ESGE - is a host buffer contains sg elements | |
239 | * Bit 3-4: Task Attributes | |
240 | * 00b - simple | |
241 | * 01b - head of queue | |
242 | * 10b - ordered | |
243 | * Bit 5-7: Priority - future use | |
244 | * Bit 8-15: Reserved | |
245 | */ | |
246 | ||
247 | #define SNIC_ICMND_WR 0x01 /* write command */ | |
248 | #define SNIC_ICMND_RD 0x02 /* read command */ | |
249 | #define SNIC_ICMND_ESGL 0x04 /* SGE/ESGE array contains valid data*/ | |
250 | ||
251 | /* | |
252 | * Priority/Task Attribute settings | |
253 | */ | |
254 | #define SNIC_ICMND_TSK_SHIFT 2 /* task attr starts at bit 2 */ | |
255 | #define SNIC_ICMND_TSK_MASK(x) ((x>>SNIC_ICMND_TSK_SHIFT) & ~(0xffff)) | |
256 | #define SNIC_ICMND_TSK_SIMPLE 0 /* simple task attr */ | |
257 | #define SNIC_ICMND_TSK_HEAD_OF_QUEUE 1 /* head of qeuue task attr */ | |
258 | #define SNIC_ICMND_TSK_ORDERED 2 /* ordered task attr */ | |
259 | ||
260 | #define SNIC_ICMND_PRI_SHIFT 5 /* prio val starts at bit 5 */ | |
261 | ||
262 | /* | |
263 | * snic_icmnd : host-> firmware request | |
264 | * | |
265 | * used for sending out an initiator SCSI 16/32-byte command | |
266 | */ | |
267 | struct snic_icmnd { | |
268 | __le16 sg_cnt; /* Number of SG Elements */ | |
269 | __le16 flags; /* flags */ | |
270 | __le32 sense_len; /* Sense buffer length */ | |
271 | __le64 tgt_id; /* Destination Target ID */ | |
272 | __le64 lun_id; /* Destination LUN ID */ | |
273 | u8 cdb_len; | |
274 | u8 _resvd; | |
275 | __le16 time_out; /* ms time for Res allocations fw to handle io*/ | |
276 | __le32 data_len; /* Total number of bytes to be transferred */ | |
277 | u8 cdb[SNIC_CDB_LEN]; | |
278 | __le64 sg_addr; /* Points to SG List */ | |
279 | __le64 sense_addr; /* Sense buffer address */ | |
280 | }; | |
281 | ||
282 | ||
283 | /* Response flags */ | |
284 | /* Bit 0: Under run | |
285 | * Bit 1: Over Run | |
286 | * Bit 2-7: Reserved | |
287 | */ | |
288 | #define SNIC_ICMND_CMPL_UNDR_RUN 0x01 /* resid under and valid */ | |
289 | #define SNIC_ICMND_CMPL_OVER_RUN 0x02 /* resid over and valid */ | |
290 | ||
291 | /* | |
292 | * snic_icmnd_cmpl: firmware -> host response | |
293 | * | |
294 | * Used for sending the host a response to an icmnd (initiator command) | |
295 | */ | |
296 | struct snic_icmnd_cmpl { | |
297 | u8 scsi_status; /* value as per SAM */ | |
298 | u8 flags; | |
299 | __le16 sense_len; /* Sense Length */ | |
300 | __le32 resid; /* Residue : # bytes under or over run */ | |
301 | }; | |
302 | ||
303 | /* | |
304 | * snic_itmf: host->firmware request | |
305 | * | |
306 | * used for requesting the firmware to abort a request and/or send out | |
307 | * a task management function | |
308 | * | |
309 | * the req_id field is valid in case of abort task and clear task | |
310 | */ | |
311 | struct snic_itmf { | |
312 | u8 tm_type; /* SCSI Task Management request */ | |
313 | u8 resvd; | |
314 | __le16 flags; /* flags */ | |
315 | __le32 req_id; /* Command id of snic req to be aborted */ | |
316 | __le64 tgt_id; /* Target ID */ | |
317 | __le64 lun_id; /* Destination LUN ID */ | |
318 | __le16 timeout; /* in sec */ | |
319 | }; | |
320 | ||
321 | /* | |
322 | * Task Management Request | |
323 | */ | |
324 | enum snic_itmf_tm_type { | |
325 | SNIC_ITMF_ABTS_TASK = 0x01, /* Abort Task */ | |
326 | SNIC_ITMF_ABTS_TASK_SET, /* Abort Task Set */ | |
327 | SNIC_ITMF_CLR_TASK, /* Clear Task */ | |
328 | SNIC_ITMF_CLR_TASKSET, /* Clear Task Set */ | |
329 | SNIC_ITMF_LUN_RESET, /* Lun Reset */ | |
330 | SNIC_ITMF_ABTS_TASK_TERM, /* Supported for SAN Targets */ | |
331 | }; | |
332 | ||
333 | /* | |
334 | * snic_itmf_cmpl: firmware -> host resposne | |
335 | * | |
336 | * used for sending the host a response for a itmf request | |
337 | */ | |
338 | struct snic_itmf_cmpl { | |
339 | __le32 nterminated; /* # IOs terminated as a result of tmf */ | |
340 | u8 flags; /* flags */ | |
341 | u8 _resvd[3]; | |
342 | }; | |
343 | ||
344 | /* | |
345 | * itmfl_cmpl flags | |
346 | * Bit 0 : 1 - Num terminated field valid | |
347 | * Bit 1 - 7 : Reserved | |
348 | */ | |
349 | #define SNIC_NUM_TERM_VALID 0x01 /* Number of IOs terminated */ | |
350 | ||
351 | /* | |
352 | * snic_hba_reset: host -> firmware request | |
353 | * | |
354 | * used for requesting firmware to reset snic | |
355 | */ | |
356 | struct snic_hba_reset { | |
357 | __le16 flags; /* flags */ | |
358 | u8 _resvd[6]; | |
359 | }; | |
360 | ||
361 | /* | |
362 | * snic_hba_reset_cmpl: firmware -> host response | |
363 | * | |
364 | * Used by firmware to respond to the host's hba reset request | |
365 | */ | |
366 | struct snic_hba_reset_cmpl { | |
367 | u8 flags; /* flags : more info needs to be added*/ | |
368 | u8 _resvd[7]; | |
369 | }; | |
370 | ||
371 | /* | |
372 | * snic_notify_msg: firmware -> host response | |
373 | * | |
374 | * Used by firmware to notify host of the last work queue entry received | |
375 | */ | |
376 | struct snic_notify_msg { | |
377 | __le32 wqe_num; /* wq entry number */ | |
378 | u8 flags; /* flags, macros */ | |
379 | u8 _resvd[4]; | |
380 | }; | |
381 | ||
382 | ||
383 | #define SNIC_EVDATA_LEN 24 /* in bytes */ | |
384 | /* snic_async_evnotify: firmware -> host notification | |
385 | * | |
386 | * Used by firmware to notify the host about configuration/state changes | |
387 | */ | |
388 | struct snic_async_evnotify { | |
389 | u8 FLS_EVENT_DESC; | |
390 | u8 vnic; /* vnic id */ | |
391 | u8 _resvd[2]; | |
392 | __le32 ev_id; /* Event ID */ | |
393 | u8 ev_data[SNIC_EVDATA_LEN]; /* Event Data */ | |
394 | u8 _resvd2[4]; | |
395 | }; | |
396 | ||
397 | /* async event flags */ | |
398 | enum snic_ev_type { | |
399 | SNIC_EV_TGT_OFFLINE = 0x01, /* Target Offline, PL contains TGT ID */ | |
400 | SNIC_EV_TGT_ONLINE, /* Target Online, PL contains TGT ID */ | |
401 | SNIC_EV_LUN_OFFLINE, /* LUN Offline, PL contains LUN ID */ | |
402 | SNIC_EV_LUN_ONLINE, /* LUN Online, PL contains LUN ID */ | |
403 | SNIC_EV_CONF_CHG, /* Dev Config/Attr Change Event */ | |
404 | SNIC_EV_TGT_ADDED, /* Target Added */ | |
405 | SNIC_EV_TGT_DELTD, /* Target Del'd, PL contains TGT ID */ | |
406 | SNIC_EV_LUN_ADDED, /* LUN Added */ | |
407 | SNIC_EV_LUN_DELTD, /* LUN Del'd, PL cont. TGT & LUN ID */ | |
408 | ||
409 | SNIC_EV_DISC_CMPL = 0x10, /* Discovery Completed Event */ | |
410 | }; | |
411 | ||
412 | ||
413 | #define SNIC_HOST_REQ_LEN 128 /*Exp length of host req, wq desc sz*/ | |
414 | /* Payload 88 bytes = 128 - 24 - 16 */ | |
415 | #define SNIC_HOST_REQ_PAYLOAD ((int)(SNIC_HOST_REQ_LEN - \ | |
416 | sizeof(struct snic_io_hdr) - \ | |
417 | (2 * sizeof(u64)))) | |
418 | ||
419 | /* | |
420 | * snic_host_req: host -> firmware request | |
421 | * | |
422 | * Basic structure for all snic requests that are sent from the host to | |
423 | * firmware. They are 128 bytes in size. | |
424 | */ | |
425 | struct snic_host_req { | |
426 | u64 ctrl_data[2]; /*16 bytes - Control Data */ | |
427 | struct snic_io_hdr hdr; | |
428 | union { | |
429 | /* | |
430 | * Entry specific space, last byte contains color | |
431 | */ | |
432 | u8 buf[SNIC_HOST_REQ_PAYLOAD]; | |
433 | ||
434 | /* | |
435 | * Exchange firmware version | |
436 | */ | |
437 | struct snic_exch_ver_req exch_ver; | |
438 | ||
439 | /* report targets */ | |
440 | struct snic_report_tgts rpt_tgts; | |
441 | ||
442 | /* io request */ | |
443 | struct snic_icmnd icmnd; | |
444 | ||
445 | /* task management request */ | |
446 | struct snic_itmf itmf; | |
447 | ||
448 | /* hba reset */ | |
449 | struct snic_hba_reset reset; | |
450 | } u; | |
451 | }; /* end of snic_host_req structure */ | |
452 | ||
453 | ||
454 | #define SNIC_FW_REQ_LEN 64 /* Expected length of fw req */ | |
455 | struct snic_fw_req { | |
456 | struct snic_io_hdr hdr; | |
457 | union { | |
458 | /* | |
459 | * Entry specific space, last byte contains color | |
460 | */ | |
461 | u8 buf[SNIC_FW_REQ_LEN - sizeof(struct snic_io_hdr)]; | |
462 | ||
463 | /* Exchange Version Response */ | |
464 | struct snic_exch_ver_rsp exch_ver_cmpl; | |
465 | ||
466 | /* Report Targets Response */ | |
467 | struct snic_report_tgts_cmpl rpt_tgts_cmpl; | |
468 | ||
469 | /* scsi response */ | |
470 | struct snic_icmnd_cmpl icmnd_cmpl; | |
471 | ||
472 | /* task management response */ | |
473 | struct snic_itmf_cmpl itmf_cmpl; | |
474 | ||
475 | /* hba reset response */ | |
476 | struct snic_hba_reset_cmpl reset_cmpl; | |
477 | ||
478 | /* notify message */ | |
479 | struct snic_notify_msg ack; | |
480 | ||
481 | /* async notification event */ | |
482 | struct snic_async_evnotify async_ev; | |
483 | ||
484 | } u; | |
485 | }; /* end of snic_fw_req structure */ | |
486 | ||
487 | /* | |
488 | * Auxillary macro to verify specific snic req/cmpl structures | |
489 | * to ensure that it will be aligned to 64 bit, and not using | |
490 | * color bit field | |
491 | */ | |
492 | #define VERIFY_REQ_SZ(x) | |
493 | #define VERIFY_CMPL_SZ(x) | |
494 | ||
495 | /* | |
496 | * Access routines to encode and decode the color bit, which is the most | |
497 | * significant bit of the structure. | |
498 | */ | |
499 | static inline void | |
500 | snic_color_enc(struct snic_fw_req *req, u8 color) | |
501 | { | |
502 | u8 *c = ((u8 *) req) + sizeof(struct snic_fw_req) - 1; | |
503 | ||
504 | if (color) | |
505 | *c |= 0x80; | |
506 | else | |
507 | *c &= ~0x80; | |
508 | } | |
509 | ||
510 | static inline void | |
511 | snic_color_dec(struct snic_fw_req *req, u8 *color) | |
512 | { | |
513 | u8 *c = ((u8 *) req) + sizeof(struct snic_fw_req) - 1; | |
514 | ||
515 | *color = *c >> 7; | |
516 | ||
517 | /* Make sure color bit is read from desc *before* other fields | |
518 | * are read from desc. Hardware guarantees color bit is last | |
519 | * bit (byte) written. Adding the rmb() prevents the compiler | |
520 | * and/or CPU from reordering the reads which would potentially | |
521 | * result in reading stale values. | |
522 | */ | |
523 | rmb(); | |
524 | } | |
525 | #endif /* end of __SNIC_FWINT_H */ |