summaryrefslogtreecommitdiffstats
path: root/drivers/scsi/snic/snic_fwint.h
blob: 2cfaf2dc915ff3cbe435023489823739e6366d59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
/*
 * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
 *
 * This program is free software; you may redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef __SNIC_FWINT_H
#define __SNIC_FWINT_H

#define SNIC_CDB_LEN	32	/* SCSI CDB size 32, can be used for 16 bytes */
#define LUN_ADDR_LEN	8

/*
 * Command entry type
 */
enum snic_io_type {
	/*
	 * Initiator request types
	 */
	SNIC_REQ_REPORT_TGTS = 0x2,	/* Report Targets */
	SNIC_REQ_ICMND,			/* Initiator command for SCSI IO */
	SNIC_REQ_ITMF,			/* Initiator command for Task Mgmt */
	SNIC_REQ_HBA_RESET,		/* SNIC Reset */
	SNIC_REQ_EXCH_VER,		/* Exchange Version Information */
	SNIC_REQ_TGT_INFO,		/* Backend/Target Information */
	SNIC_REQ_BOOT_LUNS,

	/*
	 * Response type
	 */
	SNIC_RSP_REPORT_TGTS_CMPL = 0x12,/* Report Targets Completion */
	SNIC_RSP_ICMND_CMPL,		/* SCSI IO Completion */
	SNIC_RSP_ITMF_CMPL,		/* Task Management Completion */
	SNIC_RSP_HBA_RESET_CMPL,	/* SNIC Reset Completion */
	SNIC_RSP_EXCH_VER_CMPL,		/* Exchange Version Completion*/
	SNIC_RSP_BOOT_LUNS_CMPL,

	/*
	 * Misc Request types
	 */
	SNIC_MSG_ACK = 0x80,		/* Ack: snic_notify_msg */
	SNIC_MSG_ASYNC_EVNOTIFY,	/* Asynchronous Event Notification */
}; /* end of enum snic_io_type */


/*
 * Header status codes from firmware
 */
enum snic_io_status {
	SNIC_STAT_IO_SUCCESS = 0,	/* request was successful */

	/*
	 * If a request to the fw is rejected, the original request header
	 * will be returned with the status set to one of the following:
	 */
	SNIC_STAT_INVALID_HDR,	/* header contains invalid data */
	SNIC_STAT_OUT_OF_RES,	/* out of resources to complete request */
	SNIC_STAT_INVALID_PARM,	/* some parameter in request is not valid */
	SNIC_STAT_REQ_NOT_SUP,	/* req type is not supported */
	SNIC_STAT_IO_NOT_FOUND,	/* requested IO was not found */

	/*
	 * Once a request is processed, the fw will usually return
	 * a cmpl message type. In cases where errors occurred,
	 * the header status would be filled in with one of the following:
	 */
	SNIC_STAT_ABORTED,		/* req was aborted */
	SNIC_STAT_TIMEOUT,		/* req was timed out */
	SNIC_STAT_SGL_INVALID,		/* req was aborted due to sgl error */
	SNIC_STAT_DATA_CNT_MISMATCH,	/*recv/sent more/less data than expec */
	SNIC_STAT_FW_ERR,		/* req was terminated due to fw error */
	SNIC_STAT_ITMF_REJECT,		/* itmf req was rejected by target */
	SNIC_STAT_ITMF_FAIL,		/* itmf req was failed */
	SNIC_STAT_ITMF_INCORRECT_LUN,	/* itmf req has incorrect LUN id*/
	SNIC_STAT_CMND_REJECT,		/* req was invalid and rejected */
	SNIC_STAT_DEV_OFFLINE,		/* req sent to offline device */
	SNIC_STAT_NO_BOOTLUN,
	SNIC_STAT_SCSI_ERR,		/* SCSI error returned by Target. */
	SNIC_STAT_NOT_READY,		/* sNIC Subsystem is not ready */
	SNIC_STAT_FATAL_ERROR,		/* sNIC is in unrecoverable state */
}; /* end of enum snic_io_status */

/*
 * snic_io_hdr : host <--> firmare
 *
 * for any other message that will be queued to firmware should
 *  have the following request header
 */
struct snic_io_hdr {
	__le32	hid;
	__le32	cmnd_id;	/* tag here */
	ulong	init_ctx;	/* initiator context */
	u8	type;		/* request/response type */
	u8	status;		/* header status entry */
	u8	protocol;	/* Protocol specific, may needed for RoCE*/
	u8	flags;
	__le16	sg_cnt;
	u16	resvd;
};

/* auxillary funciton for encoding the snic_io_hdr */
static inline void
snic_io_hdr_enc(struct snic_io_hdr *hdr, u8 typ, u8 status, u32 id, u32 hid,
		u16 sg_cnt, ulong ctx)
{
	hdr->type = typ;
	hdr->status = status;
	hdr->protocol = 0;
	hdr->hid = cpu_to_le32(hid);
	hdr->cmnd_id = cpu_to_le32(id);
	hdr->sg_cnt = cpu_to_le16(sg_cnt);
	hdr->init_ctx = ctx;
	hdr->flags = 0;
}

/* auxillary funciton for decoding the snic_io_hdr */
static inline void
snic_io_hdr_dec(struct snic_io_hdr *hdr, u8 *typ, u8 *stat, u32 *cmnd_id,
		u32 *hid, ulong *ctx)
{
	*typ = hdr->type;
	*stat = hdr->status;
	*hid = le32_to_cpu(hdr->hid);
	*cmnd_id = le32_to_cpu(hdr->cmnd_id);
	*ctx = hdr->init_ctx;
}

/*
 * snic_host_info: host -> firmware
 *
 * Used for sending host information to firmware, and request fw version
 */
struct snic_exch_ver_req {
	__le32	drvr_ver;	/* for debugging, when fw dump captured */
	__le32	os_type;	/* for OS specific features */
};

/*
 * os_type flags
 * Bit 0-7 : OS information
 * Bit 8-31: Feature/Capability Information
 */
#define SNIC_OS_LINUX	0x1
#define SNIC_OS_WIN	0x2
#define SNIC_OS_ESX	0x3

/*
 * HBA Capabilities
 * Bit 1: Reserved.
 * Bit 2: Dynamic Discovery of LUNs.
 * Bit 3: Async event notifications on on tgt online/offline events.
 * Bit 4: IO timeout support in FW.
 * Bit 5-31: Reserved.
 */
#define SNIC_HBA_CAP_DDL	0x02	/* Supports Dynamic Discovery of LUNs */
#define SNIC_HBA_CAP_AEN	0x04	/* Supports Async Event Noitifcation */
#define SNIC_HBA_CAP_TMO	0x08	/* Supports IO timeout in FW */

/*
 * snic_exch_ver_rsp : firmware -> host
 *
 * Used by firmware to send response to version request
 */
struct snic_exch_ver_rsp {
	__le32	version;
	__le32	hid;
	__le32	max_concur_ios;		/* max concurrent ios */
	__le32	max_sgs_per_cmd;	/* max sgls per IO */
	__le32	max_io_sz;		/* max io size supported */
	__le32	hba_cap;		/* hba capabilities */
	__le32	max_tgts;		/* max tgts supported */
	__le16	io_timeout;		/* FW extended timeout */
	u16	rsvd;
};


/*
 * snic_report_tgts : host -> firmware request
 *
 * Used by the host to request list of targets
 */
struct snic_report_tgts {
	__le16	sg_cnt;
	__le16	flags;		/* specific flags from fw */
	u8	_resvd[4];
	__le64	sg_addr;	/* Points to SGL */
	__le64	sense_addr;
};

enum snic_type {
	SNIC_NONE = 0x0,
	SNIC_DAS,
	SNIC_SAN,
};


/* Report Target Response */
enum snic_tgt_type {
	SNIC_TGT_NONE = 0x0,
	SNIC_TGT_DAS,	/* DAS Target */
	SNIC_TGT_SAN,	/* SAN Target */
};

/* target id format */
struct snic_tgt_id {
	__le32	tgt_id;		/* target id */
	__le16	tgt_type;	/* tgt type */
	__le16	vnic_id;	/* corresponding vnic id */
};

/*
 * snic_report_tgts_cmpl : firmware -> host response
 *
 * Used by firmware to send response to Report Targets request
 */
struct snic_report_tgts_cmpl {
	__le32	tgt_cnt;	/* Number of Targets accessible */
	u32	_resvd;
};

/*
 * Command flags
 *
 * Bit 0: Read flags
 * Bit 1: Write flag
 * Bit 2: ESGL - sg/esg array contains extended sg
 *	  ESGE - is a host buffer contains sg elements
 * Bit 3-4: Task Attributes
 *		00b - simple
 *		01b - head of queue
 *		10b - ordered
 * Bit 5-7: Priority - future use
 * Bit 8-15: Reserved
 */

#define SNIC_ICMND_WR		0x01	/* write command */
#define SNIC_ICMND_RD		0x02	/* read command */
#define SNIC_ICMND_ESGL		0x04	/* SGE/ESGE array contains valid data*/

/*
 * Priority/Task Attribute settings
 */
#define SNIC_ICMND_TSK_SHIFT		2	/* task attr starts at bit 2 */
#define SNIC_ICMND_TSK_MASK(x)		((x>>SNIC_ICMND_TSK_SHIFT) & ~(0xffff))
#define SNIC_ICMND_TSK_SIMPLE		0	/* simple task attr */
#define SNIC_ICMND_TSK_HEAD_OF_QUEUE	1	/* head of qeuue task attr */
#define SNIC_ICMND_TSK_ORDERED		2	/* ordered task attr */

#define SNIC_ICMND_PRI_SHIFT		5	/* prio val starts at bit 5 */

/*
 * snic_icmnd : host-> firmware request
 *
 * used for sending out an initiator SCSI 16/32-byte command
 */
struct snic_icmnd {
	__le16	sg_cnt;		/* Number of SG Elements */
	__le16	flags;		/* flags */
	__le32	sense_len;	/* Sense buffer length */
	__le64	tgt_id;		/* Destination Target ID */
	__le64	lun_id;		/* Destination LUN ID */
	u8	cdb_len;
	u8	_resvd;
	__le16	time_out;	/* ms time for Res allocations fw to handle io*/
	__le32	data_len;	/* Total number of bytes to be transferred */
	u8	cdb[SNIC_CDB_LEN];
	__le64	sg_addr;	/* Points to SG List */
	__le64	sense_addr;	/* Sense buffer address */
};


/* Response flags */
/* Bit 0: Under run
 * Bit 1: Over Run
 * Bit 2-7: Reserved
 */
#define SNIC_ICMND_CMPL_UNDR_RUN	0x01	/* resid under and valid */
#define SNIC_ICMND_CMPL_OVER_RUN	0x02	/* resid over and valid */

/*
 * snic_icmnd_cmpl: firmware -> host response
 *
 * Used for sending the host a response to an icmnd (initiator command)
 */
struct snic_icmnd_cmpl {
	u8	scsi_status;	/* value as per SAM */
	u8	flags;
	__le16	sense_len;	/* Sense Length */
	__le32	resid;		/* Residue : # bytes under or over run */
};

/*
 * snic_itmf: host->firmware request
 *
 * used for requesting the firmware to abort a request and/or send out
 * a task management function
 *
 * the req_id field is valid in case of abort task and clear task
 */
struct snic_itmf {
	u8	tm_type;	/* SCSI Task Management request */
	u8	resvd;
	__le16	flags;		/* flags */
	__le32	req_id;		/* Command id of snic req to be aborted */
	__le64	tgt_id;		/* Target ID */
	__le64	lun_id;		/* Destination LUN ID */
	__le16	timeout;	/* in sec */
};

/*
 * Task Management Request
 */
enum snic_itmf_tm_type {
	SNIC_ITMF_ABTS_TASK = 0x01,	/* Abort Task */
	SNIC_ITMF_ABTS_TASK_SET,	/* Abort Task Set */
	SNIC_ITMF_CLR_TASK,		/* Clear Task */
	SNIC_ITMF_CLR_TASKSET,		/* Clear Task Set */
	SNIC_ITMF_LUN_RESET,		/* Lun Reset */
	SNIC_ITMF_ABTS_TASK_TERM,	/* Supported for SAN Targets */
};

/*
 * snic_itmf_cmpl: firmware -> host resposne
 *
 * used for sending the host a response for a itmf request
 */
struct snic_itmf_cmpl {
	__le32	nterminated;	/* # IOs terminated as a result of tmf */
	u8	flags;		/* flags */
	u8	_resvd[3];
};

/*
 * itmfl_cmpl flags
 * Bit 0 : 1 - Num terminated field valid
 * Bit 1 - 7 : Reserved
 */
#define SNIC_NUM_TERM_VALID	0x01	/* Number of IOs terminated */

/*
 * snic_hba_reset: host -> firmware request
 *
 * used for requesting firmware to reset snic
 */
struct snic_hba_reset {
	__le16	flags;		/* flags */
	u8	_resvd[6];
};

/*
 * snic_hba_reset_cmpl: firmware -> host response
 *
 * Used by firmware to respond to the host's hba reset request
 */
struct snic_hba_reset_cmpl {
	u8	flags;		/* flags : more info needs to be added*/
	u8	_resvd[7];
};

/*
 * snic_notify_msg: firmware -> host response
 *
 * Used by firmware to notify host of the last work queue entry received
 */
struct snic_notify_msg {
	__le32	wqe_num;	/* wq entry number */
	u8	flags;		/* flags, macros */
	u8	_resvd[4];
};


#define SNIC_EVDATA_LEN		24	/* in bytes */
/* snic_async_evnotify: firmware -> host notification
 *
 * Used by firmware to notify the host about configuration/state changes
 */
struct snic_async_evnotify {
	u8	FLS_EVENT_DESC;
	u8	vnic;			/* vnic id */
	u8	_resvd[2];
	__le32	ev_id;			/* Event ID */
	u8	ev_data[SNIC_EVDATA_LEN]; /* Event Data */
	u8	_resvd2[4];
};

/* async event flags */
enum snic_ev_type {
	SNIC_EV_TGT_OFFLINE = 0x01, /* Target Offline, PL contains TGT ID */
	SNIC_EV_TGT_ONLINE,	/* Target Online, PL contains TGT ID */
	SNIC_EV_LUN_OFFLINE,	/* LUN Offline, PL contains LUN ID */
	SNIC_EV_LUN_ONLINE,	/* LUN Online, PL contains LUN ID */
	SNIC_EV_CONF_CHG,	/* Dev Config/Attr Change Event */
	SNIC_EV_TGT_ADDED,	/* Target Added */
	SNIC_EV_TGT_DELTD,	/* Target Del'd, PL contains TGT ID */
	SNIC_EV_LUN_ADDED,	/* LUN Added */
	SNIC_EV_LUN_DELTD,	/* LUN Del'd, PL cont. TGT & LUN ID */

	SNIC_EV_DISC_CMPL = 0x10, /* Discovery Completed Event */
};


#define SNIC_HOST_REQ_LEN	128	/*Exp length of host req, wq desc sz*/
/* Payload 88 bytes = 128 - 24 - 16 */
#define SNIC_HOST_REQ_PAYLOAD	((int)(SNIC_HOST_REQ_LEN -		\
					sizeof(struct snic_io_hdr) -	\
					(2 * sizeof(u64))))

/*
 * snic_host_req: host -> firmware request
 *
 * Basic structure for all snic requests that are sent from the host to
 * firmware. They are 128 bytes in size.
 */
struct snic_host_req {
	u64	ctrl_data[2];	/*16 bytes - Control Data */
	struct snic_io_hdr hdr;
	union {
		/*
		 * Entry specific space, last byte contains color
		 */
		u8	buf[SNIC_HOST_REQ_PAYLOAD];

		/*
		 * Exchange firmware version
		 */
		struct snic_exch_ver_req	exch_ver;

		/* report targets */
		struct snic_report_tgts		rpt_tgts;

		/* io request */
		struct snic_icmnd		icmnd;

		/* task management request */
		struct snic_itmf		itmf;

		/* hba reset */
		struct snic_hba_reset		reset;
	} u;
}; /* end of snic_host_req structure */


#define SNIC_FW_REQ_LEN		64 /* Expected length of fw req */
struct snic_fw_req {
	struct snic_io_hdr hdr;
	union {
		/*
		 * Entry specific space, last byte contains color
		 */
		u8	buf[SNIC_FW_REQ_LEN - sizeof(struct snic_io_hdr)];

		/* Exchange Version Response */
		struct snic_exch_ver_rsp	exch_ver_cmpl;

		/* Report Targets Response */
		struct snic_report_tgts_cmpl	rpt_tgts_cmpl;

		/* scsi response */
		struct snic_icmnd_cmpl		icmnd_cmpl;

		/* task management response */
		struct snic_itmf_cmpl		itmf_cmpl;

		/* hba reset response */
		struct snic_hba_reset_cmpl	reset_cmpl;

		/* notify message */
		struct snic_notify_msg		ack;

		/* async notification event */
		struct snic_async_evnotify	async_ev;

	} u;
}; /* end of snic_fw_req structure */

/*
 * Auxillary macro to verify specific snic req/cmpl structures
 * to ensure that it will be aligned to 64 bit, and not using
 * color bit field
 */
#define VERIFY_REQ_SZ(x)
#define VERIFY_CMPL_SZ(x)

/*
 * Access routines to encode and decode the color bit, which is the most
 * significant bit of the structure.
 */
static inline void
snic_color_enc(struct snic_fw_req *req, u8 color)
{
	u8 *c = ((u8 *) req) + sizeof(struct snic_fw_req) - 1;

	if (color)
		*c |= 0x80;
	else
		*c &= ~0x80;
}

static inline void
snic_color_dec(struct snic_fw_req *req, u8 *color)
{
	u8 *c = ((u8 *) req) + sizeof(struct snic_fw_req) - 1;

	*color = *c >> 7;

	/* Make sure color bit is read from desc *before* other fields
	 * are read from desc. Hardware guarantees color bit is last
	 * bit (byte) written. Adding the rmb() prevents the compiler
	 * and/or CPU from reordering the reads which would potentially
	 * result in reading stale values.
	 */
	rmb();
}
#endif /* end of __SNIC_FWINT_H */
OpenPOWER on IntegriCloud