qla_def.h 122.2 KB
Newer Older
A
Andrew Vasquez 已提交
1 2
/*
 * QLogic Fibre Channel HBA Driver
3
 * Copyright (c)  2003-2014 QLogic Corporation
A
Andrew Vasquez 已提交
4 5 6
 *
 * See LICENSE.qla2xxx for copyright and licensing details.
 */
L
Linus Torvalds 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#ifndef __QLA_DEF_H
#define __QLA_DEF_H

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/module.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <linux/dma-mapping.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/dmapool.h>
#include <linux/mempool.h>
#include <linux/spinlock.h>
#include <linux/completion.h>
23
#include <linux/interrupt.h>
24
#include <linux/workqueue.h>
25
#include <linux/firmware.h>
26
#include <linux/aer.h>
27
#include <linux/mutex.h>
28
#include <linux/btree.h>
L
Linus Torvalds 已提交
29 30 31 32 33

#include <scsi/scsi.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_cmnd.h>
34
#include <scsi/scsi_transport_fc.h>
35
#include <scsi/scsi_bsg_fc.h>
L
Linus Torvalds 已提交
36

37
#include "qla_bsg.h"
38
#include "qla_nx.h"
39
#include "qla_nx2.h"
40
#include "qla_nvme.h"
41 42
#define QLA2XXX_DRIVER_NAME	"qla2xxx"
#define QLA2XXX_APIDEV		"ql2xapidev"
43
#define QLA2XXX_MANUFACTURER	"QLogic Corporation"
44

L
Linus Torvalds 已提交
45 46 47 48 49 50
/*
 * We have MAILBOX_REGISTER_COUNT sized arrays in a few places,
 * but that's fine as we don't look at the last 24 ones for
 * ISP2100 HBAs.
 */
#define MAILBOX_REGISTER_COUNT_2100	8
51
#define MAILBOX_REGISTER_COUNT_2200	24
L
Linus Torvalds 已提交
52 53 54 55 56 57 58 59
#define MAILBOX_REGISTER_COUNT		32

#define QLA2200A_RISC_ROM_VER	4
#define FPM_2300		6
#define FPM_2310		7

#include "qla_settings.h"

60 61
#define MODE_DUAL (MODE_TARGET | MODE_INITIATOR)

A
Andrew Vasquez 已提交
62
/*
L
Linus Torvalds 已提交
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
 * Data bit definitions
 */
#define BIT_0	0x1
#define BIT_1	0x2
#define BIT_2	0x4
#define BIT_3	0x8
#define BIT_4	0x10
#define BIT_5	0x20
#define BIT_6	0x40
#define BIT_7	0x80
#define BIT_8	0x100
#define BIT_9	0x200
#define BIT_10	0x400
#define BIT_11	0x800
#define BIT_12	0x1000
#define BIT_13	0x2000
#define BIT_14	0x4000
#define BIT_15	0x8000
#define BIT_16	0x10000
#define BIT_17	0x20000
#define BIT_18	0x40000
#define BIT_19	0x80000
#define BIT_20	0x100000
#define BIT_21	0x200000
#define BIT_22	0x400000
#define BIT_23	0x800000
#define BIT_24	0x1000000
#define BIT_25	0x2000000
#define BIT_26	0x4000000
#define BIT_27	0x8000000
#define BIT_28	0x10000000
#define BIT_29	0x20000000
#define BIT_30	0x40000000
#define BIT_31	0x80000000

#define LSB(x)	((uint8_t)(x))
#define MSB(x)	((uint8_t)((uint16_t)(x) >> 8))

#define LSW(x)	((uint16_t)(x))
#define MSW(x)	((uint16_t)((uint32_t)(x) >> 16))

#define LSD(x)	((uint32_t)((uint64_t)(x)))
#define MSD(x)	((uint32_t)((((uint64_t)(x)) >> 16) >> 16))

107
#define MAKE_HANDLE(x, y) ((uint32_t)((((uint32_t)(x)) << 16) | (uint32_t)(y)))
L
Linus Torvalds 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

/*
 * I/O register
*/

#define RD_REG_BYTE(addr)		readb(addr)
#define RD_REG_WORD(addr)		readw(addr)
#define RD_REG_DWORD(addr)		readl(addr)
#define RD_REG_BYTE_RELAXED(addr)	readb_relaxed(addr)
#define RD_REG_WORD_RELAXED(addr)	readw_relaxed(addr)
#define RD_REG_DWORD_RELAXED(addr)	readl_relaxed(addr)
#define WRT_REG_BYTE(addr, data)	writeb(data,addr)
#define WRT_REG_WORD(addr, data)	writew(data,addr)
#define WRT_REG_DWORD(addr, data)	writel(data,addr)

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
/*
 * ISP83XX specific remote register addresses
 */
#define QLA83XX_LED_PORT0			0x00201320
#define QLA83XX_LED_PORT1			0x00201328
#define QLA83XX_IDC_DEV_STATE		0x22102384
#define QLA83XX_IDC_MAJOR_VERSION	0x22102380
#define QLA83XX_IDC_MINOR_VERSION	0x22102398
#define QLA83XX_IDC_DRV_PRESENCE	0x22102388
#define QLA83XX_IDC_DRIVER_ACK		0x2210238c
#define QLA83XX_IDC_CONTROL			0x22102390
#define QLA83XX_IDC_AUDIT			0x22102394
#define QLA83XX_IDC_LOCK_RECOVERY	0x2210239c
#define QLA83XX_DRIVER_LOCKID		0x22102104
#define QLA83XX_DRIVER_LOCK			0x8111c028
#define QLA83XX_DRIVER_UNLOCK		0x8111c02c
#define QLA83XX_FLASH_LOCKID		0x22102100
#define QLA83XX_FLASH_LOCK			0x8111c010
#define QLA83XX_FLASH_UNLOCK		0x8111c014
#define QLA83XX_DEV_PARTINFO1		0x221023e0
#define QLA83XX_DEV_PARTINFO2		0x221023e4
#define QLA83XX_FW_HEARTBEAT		0x221020b0
#define QLA83XX_PEG_HALT_STATUS1	0x221020a8
#define QLA83XX_PEG_HALT_STATUS2	0x221020ac

/* 83XX: Macros defining 8200 AEN Reason codes */
#define IDC_DEVICE_STATE_CHANGE BIT_0
#define IDC_PEG_HALT_STATUS_CHANGE BIT_1
#define IDC_NIC_FW_REPORTED_FAILURE BIT_2
#define IDC_HEARTBEAT_FAILURE BIT_3

/* 83XX: Macros defining 8200 AEN Error-levels */
#define ERR_LEVEL_NON_FATAL 0x1
#define ERR_LEVEL_RECOVERABLE_FATAL 0x2
#define ERR_LEVEL_UNRECOVERABLE_FATAL 0x4

/* 83XX: Macros for IDC Version */
#define QLA83XX_SUPP_IDC_MAJOR_VERSION 0x01
#define QLA83XX_SUPP_IDC_MINOR_VERSION 0x0

/* 83XX: Macros for scheduling dpc tasks */
#define QLA83XX_NIC_CORE_RESET 0x1
#define QLA83XX_IDC_STATE_HANDLER 0x2
#define QLA83XX_NIC_CORE_UNRECOVERABLE 0x3

/* 83XX: Macros for defining IDC-Control bits */
#define QLA83XX_IDC_RESET_DISABLED BIT_0
#define QLA83XX_IDC_GRACEFUL_RESET BIT_1

/* 83XX: Macros for different timeouts */
#define QLA83XX_IDC_INITIALIZATION_TIMEOUT 30
#define QLA83XX_IDC_RESET_ACK_TIMEOUT 10
#define QLA83XX_MAX_LOCK_RECOVERY_WAIT (2 * HZ)

/* 83XX: Macros for defining class in DEV-Partition Info register */
#define QLA83XX_CLASS_TYPE_NONE		0x0
#define QLA83XX_CLASS_TYPE_NIC		0x1
#define QLA83XX_CLASS_TYPE_FCOE		0x2
#define QLA83XX_CLASS_TYPE_ISCSI	0x3

/* 83XX: Macros for IDC Lock-Recovery stages */
#define IDC_LOCK_RECOVERY_STAGE1	0x1 /* Stage1: Intent for
					     * lock-recovery
					     */
#define IDC_LOCK_RECOVERY_STAGE2	0x2 /* Stage2: Perform lock-recovery */

/* 83XX: Macros for IDC Audit type */
#define IDC_AUDIT_TIMESTAMP		0x0 /* IDC-AUDIT: Record timestamp of
					     * dev-state change to NEED-RESET
					     * or NEED-QUIESCENT
					     */
#define IDC_AUDIT_COMPLETION		0x1 /* IDC-AUDIT: Record duration of
					     * reset-recovery completion is
					     * second
					     */
198 199 200 201 202
/* ISP2031: Values for laser on/off */
#define PORT_0_2031	0x00201340
#define PORT_1_2031	0x00201350
#define LASER_ON_2031	0x01800100
#define LASER_OFF_2031	0x01800180
203

204 205 206 207 208 209 210
/*
 * The ISP2312 v2 chip cannot access the FLASH/GPIO registers via MMIO in an
 * 133Mhz slot.
 */
#define RD_REG_WORD_PIO(addr)		(inw((unsigned long)addr))
#define WRT_REG_WORD_PIO(addr, data)	(outw(data,(unsigned long)addr))

L
Linus Torvalds 已提交
211 212 213 214
/*
 * Fibre Channel device definitions.
 */
#define WWN_SIZE		8	/* Size of WWPN, WWN & WWNN */
215 216 217 218
#define MAX_FIBRE_DEVICES_2100	512
#define MAX_FIBRE_DEVICES_2400	2048
#define MAX_FIBRE_DEVICES_LOOP	128
#define MAX_FIBRE_DEVICES_MAX	MAX_FIBRE_DEVICES_2400
219
#define LOOPID_MAP_SIZE		(ha->max_fibre_devices)
220
#define MAX_FIBRE_LUNS  	0xFFFF
L
Linus Torvalds 已提交
221 222 223 224 225 226 227 228
#define	MAX_HOST_COUNT		16

/*
 * Host adapter default definitions.
 */
#define MAX_BUSES		1  /* We only have one bus today */
#define MIN_LUNS		8
#define MAX_LUNS		MAX_FIBRE_LUNS
A
Andrew Vasquez 已提交
229 230
#define MAX_CMDS_PER_LUN	255

L
Linus Torvalds 已提交
231 232 233 234 235 236 237 238 239 240 241 242 243 244
/*
 * Fibre Channel device definitions.
 */
#define SNS_LAST_LOOP_ID_2100	0xfe
#define SNS_LAST_LOOP_ID_2300	0x7ff

#define LAST_LOCAL_LOOP_ID	0x7d
#define SNS_FL_PORT		0x7e
#define FABRIC_CONTROLLER	0x7f
#define SIMPLE_NAME_SERVER	0x80
#define SNS_FIRST_LOOP_ID	0x81
#define MANAGEMENT_SERVER	0xfe
#define BROADCAST		0xff

245 246 247 248 249
/*
 * There is no correspondence between an N-PORT id and an AL_PA.  Therefore the
 * valid range of an N-PORT id is 0 through 0x7ef.
 */
#define NPH_LAST_HANDLE		0x7ef
250
#define NPH_MGMT_SERVER		0x7fa		/*  FFFFFA */
251 252 253 254 255
#define NPH_SNS			0x7fc		/*  FFFFFC */
#define NPH_FABRIC_CONTROLLER	0x7fd		/*  FFFFFD */
#define NPH_F_PORT		0x7fe		/*  FFFFFE */
#define NPH_IP_BROADCAST	0x7ff		/*  FFFFFF */

256 257
#define NPH_SNS_LID(ha)	(IS_FWI2_CAPABLE(ha) ? NPH_SNS : SIMPLE_NAME_SERVER)

258 259
#define MAX_CMDSZ	16		/* SCSI maximum CDB size. */
#include "qla_fw.h"
260 261 262 263 264 265 266 267

struct name_list_extended {
	struct get_name_list_extended *l;
	dma_addr_t		ldma;
	struct list_head 	fcports;	/* protect by sess_list */
	u32			size;
	u8			sent;
};
L
Linus Torvalds 已提交
268 269 270
/*
 * Timeout timer counts in seconds
 */
已提交
271
#define PORT_RETRY_TIME			1
L
Linus Torvalds 已提交
272 273 274 275
#define LOOP_DOWN_TIMEOUT		60
#define LOOP_DOWN_TIME			255	/* 240 */
#define	LOOP_DOWN_RESET			(LOOP_DOWN_TIME - 30)

Q
Quinn Tran 已提交
276
#define DEFAULT_OUTSTANDING_COMMANDS	4096
277
#define MIN_OUTSTANDING_COMMANDS	128
L
Linus Torvalds 已提交
278 279 280 281

/* ISP request and response entry counts (37-65535) */
#define REQUEST_ENTRY_CNT_2100		128	/* Number of request entries. */
#define REQUEST_ENTRY_CNT_2200		2048	/* Number of request entries. */
282
#define REQUEST_ENTRY_CNT_24XX		2048	/* Number of request entries. */
283
#define REQUEST_ENTRY_CNT_83XX		8192	/* Number of request entries. */
Q
Quinn Tran 已提交
284
#define RESPONSE_ENTRY_CNT_83XX		4096	/* Number of response entries.*/
L
Linus Torvalds 已提交
285 286
#define RESPONSE_ENTRY_CNT_2100		64	/* Number of response entries.*/
#define RESPONSE_ENTRY_CNT_2300		512	/* Number of response entries.*/
287
#define RESPONSE_ENTRY_CNT_MQ		128	/* Number of response entries.*/
288
#define ATIO_ENTRY_CNT_24XX		4096	/* Number of ATIO entries. */
289
#define RESPONSE_ENTRY_CNT_FX00		256     /* Number of response entries.*/
290
#define FW_DEF_EXCHANGES_CNT 2048
291 292
#define FW_MAX_EXCHANGES_CNT (32 * 1024)
#define REDUCE_EXCHANGES_CNT  (8 * 1024)
L
Linus Torvalds 已提交
293

294
struct req_que;
295
struct qla_tgt_sess;
296

L
Linus Torvalds 已提交
297
/*
A
Andrew Vasquez 已提交
298
 * SCSI Request Block
L
Linus Torvalds 已提交
299
 */
300
struct srb_cmd {
L
Linus Torvalds 已提交
301 302
	struct scsi_cmnd *cmd;		/* Linux SCSI command pkt */
	uint32_t request_sense_length;
303
	uint32_t fw_sense_length;
L
Linus Torvalds 已提交
304
	uint8_t *request_sense_ptr;
305
	void *ctx;
306
};
L
Linus Torvalds 已提交
307 308 309 310

/*
 * SRB flag definitions
 */
311 312 313 314 315 316 317 318
#define SRB_DMA_VALID			BIT_0	/* Command sent to ISP */
#define SRB_FCP_CMND_DMA_VALID		BIT_12	/* DIF: DSD List valid */
#define SRB_CRC_CTX_DMA_VALID		BIT_2	/* DIF: context DMA valid */
#define SRB_CRC_PROT_DMA_VALID		BIT_4	/* DIF: prot DMA valid */
#define SRB_CRC_CTX_DSD_VALID		BIT_5	/* DIF: dsd_list valid */

/* To identify if a srb is of T10-CRC type. @sp => srb_t pointer */
#define IS_PROT_IO(sp)	(sp->flags & SRB_CRC_CTX_DSD_VALID)
L
Linus Torvalds 已提交
319

320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
/*
 * 24 bit port ID type definition.
 */
typedef union {
	uint32_t b24 : 24;

	struct {
#ifdef __BIG_ENDIAN
		uint8_t domain;
		uint8_t area;
		uint8_t al_pa;
#elif defined(__LITTLE_ENDIAN)
		uint8_t al_pa;
		uint8_t area;
		uint8_t domain;
#else
#error "__BIG_ENDIAN or __LITTLE_ENDIAN must be defined!"
#endif
		uint8_t rsvd_1;
	} b;
} port_id_t;
#define INVALID_PORT_ID	0xFFFFFF

343 344 345 346 347 348 349 350
struct els_logo_payload {
	uint8_t opcode;
	uint8_t rsvd[3];
	uint8_t s_id[3];
	uint8_t rsvd1[1];
	uint8_t wwpn[WWN_SIZE];
};

351 352 353 354 355 356
struct els_plogi_payload {
	uint8_t opcode;
	uint8_t rsvd[3];
	uint8_t data[112];
};

357 358 359 360 361 362 363 364 365
struct ct_arg {
	void		*iocb;
	u16		nport_handle;
	dma_addr_t	req_dma;
	dma_addr_t	rsp_dma;
	u32		req_size;
	u32		rsp_size;
	void		*req;
	void		*rsp;
366
	port_id_t	id;
367 368
};

369 370 371
/*
 * SRB extensions.
 */
372 373 374 375 376 377 378
struct srb_iocb {
	union {
		struct {
			uint16_t flags;
#define SRB_LOGIN_RETRIED	BIT_0
#define SRB_LOGIN_COND_PLOGI	BIT_1
#define SRB_LOGIN_SKIP_PRLI	BIT_2
379
#define SRB_LOGIN_NVME_PRLI	BIT_3
380
			uint16_t data[2];
381
			u32 iop[2];
382
		} logio;
383
		struct {
384 385 386 387 388 389 390 391 392
#define ELS_DCMD_TIMEOUT 20
#define ELS_DCMD_LOGO 0x5
			uint32_t flags;
			uint32_t els_cmd;
			struct completion comp;
			struct els_logo_payload *els_logo_pyld;
			dma_addr_t els_logo_pyld_dma;
		} els_logo;
		struct {
393 394 395 396 397 398 399 400 401 402 403 404 405
#define ELS_DCMD_PLOGI 0x3
			uint32_t flags;
			uint32_t els_cmd;
			struct completion comp;
			struct els_plogi_payload *els_plogi_pyld;
			struct els_plogi_payload *els_resp_pyld;
			dma_addr_t els_plogi_pyld_dma;
			dma_addr_t els_resp_pyld_dma;
			uint32_t	fw_status[3];
			__le16	comp_status;
			__le16	len;
		} els_plogi;
		struct {
406 407 408 409 410
			/*
			 * Values for flags field below are as
			 * defined in tsk_mgmt_entry struct
			 * for control_flags field in qla_fw.h.
			 */
H
Hannes Reinecke 已提交
411
			uint64_t lun;
412 413
			uint32_t flags;
			uint32_t data;
414
			struct completion comp;
415
			__le16 comp_status;
416
		} tmf;
417 418 419 420 421 422 423 424 425 426 427 428 429
		struct {
#define SRB_FXDISC_REQ_DMA_VALID	BIT_0
#define SRB_FXDISC_RESP_DMA_VALID	BIT_1
#define SRB_FXDISC_REQ_DWRD_VALID	BIT_2
#define SRB_FXDISC_RSP_DWRD_VALID	BIT_3
#define FXDISC_TIMEOUT 20
			uint8_t flags;
			uint32_t req_len;
			uint32_t rsp_len;
			void *req_addr;
			void *rsp_addr;
			dma_addr_t req_dma_handle;
			dma_addr_t rsp_dma_handle;
430 431 432 433 434 435 436 437
			__le32 adapter_id;
			__le32 adapter_id_hi;
			__le16 req_func_type;
			__le32 req_data;
			__le32 req_data_extra;
			__le32 result;
			__le32 seq_number;
			__le16 fw_flags;
438
			struct completion fxiocb_comp;
439
			__le32 reserved_0;
440 441 442 443
			uint8_t reserved_1;
		} fxiocb;
		struct {
			uint32_t cmd_hndl;
444
			__le16 comp_status;
445 446
			struct completion comp;
		} abt;
447
		struct ct_arg ctarg;
448 449
#define MAX_IOCB_MB_REG 28
#define SIZEOF_IOCB_MB_REG (MAX_IOCB_MB_REG * sizeof(uint16_t))
450
		struct {
451 452
			__le16 in_mb[MAX_IOCB_MB_REG];	/* from FW */
			__le16 out_mb[MAX_IOCB_MB_REG];	/* to FW */
453 454
			void *out, *in;
			dma_addr_t out_dma, in_dma;
455 456
			struct completion comp;
			int rc;
457 458 459 460
		} mbx;
		struct {
			struct imm_ntfy_from_isp *ntfy;
		} nack;
461 462 463 464 465 466 467 468 469 470 471
		struct {
			__le16 comp_status;
			uint16_t rsp_pyld_len;
			uint8_t	aen_op;
			void *desc;

			/* These are only used with ls4 requests */
			int cmd_len;
			int rsp_len;
			dma_addr_t cmd_dma;
			dma_addr_t rsp_dma;
472
			enum nvmefc_fcp_datadir dir;
473 474
			uint32_t dl;
			uint32_t timeout_sec;
475
			struct	list_head   entry;
476
		} nvme;
477 478 479 480
		struct {
			u16 cmd;
			u16 vp_index;
		} ctrlvp;
481
	} u;
482

483
	struct timer_list timer;
484
	void (*timeout)(void *);
485 486
};

487 488 489 490 491 492 493
/* Values for srb_ctx type */
#define SRB_LOGIN_CMD	1
#define SRB_LOGOUT_CMD	2
#define SRB_ELS_CMD_RPT 3
#define SRB_ELS_CMD_HST 4
#define SRB_CT_CMD	5
#define SRB_ADISC_CMD	6
494
#define SRB_TM_CMD	7
495
#define SRB_SCSI_CMD	8
496
#define SRB_BIDI_CMD	9
497 498 499
#define SRB_FXIOCB_DCMD	10
#define SRB_FXIOCB_BCMD	11
#define SRB_ABT_CMD	12
500
#define SRB_ELS_DCMD	13
501 502 503 504 505
#define SRB_MB_IOCB	14
#define SRB_CT_PTHRU_CMD 15
#define SRB_NACK_PLOGI	16
#define SRB_NACK_PRLI	17
#define SRB_NACK_LOGO	18
506
#define SRB_NVME_CMD	19
507
#define SRB_NVME_LS	20
508
#define SRB_PRLI_CMD	21
509
#define SRB_CTRL_VP	22
510
#define SRB_PRLO_CMD	23
511

512 513 514 515 516
enum {
	TYPE_SRB,
	TYPE_TGT_CMD,
};

517
typedef struct srb {
518 519 520 521 522 523
	/*
	 * Do not move cmd_type field, it needs to
	 * line up with qla_tgt_cmd->cmd_type
	 */
	uint8_t cmd_type;
	uint8_t pad[3];
524
	atomic_t ref_count;
525
	wait_queue_head_t nvme_ls_waitq;
526
	struct fc_port *fcport;
527
	struct scsi_qla_host *vha;
528 529
	uint32_t handle;
	uint16_t flags;
530
	uint16_t type;
531
	const char *name;
532
	int iocbs;
533
	struct qla_qpair *qpair;
534
	struct list_head elem;
535 536
	u32 gen1;	/* scratch */
	u32 gen2;	/* scratch */
537 538
	int rc;
	struct completion comp;
539
	union {
540
		struct srb_iocb iocb_cmd;
541
		struct bsg_job *bsg_job;
542
		struct srb_cmd scmd;
543
	} u;
544 545
	void (*done)(void *, int);
	void (*free)(void *);
546 547 548 549 550 551 552 553 554 555 556 557 558 559
} srb_t;

#define GET_CMD_SP(sp) (sp->u.scmd.cmd)
#define SET_CMD_SP(sp, cmd) (sp->u.scmd.cmd = cmd)
#define GET_CMD_CTX_SP(sp) (sp->u.scmd.ctx)

#define GET_CMD_SENSE_LEN(sp) \
	(sp->u.scmd.request_sense_length)
#define SET_CMD_SENSE_LEN(sp, len) \
	(sp->u.scmd.request_sense_length = len)
#define GET_CMD_SENSE_PTR(sp) \
	(sp->u.scmd.request_sense_ptr)
#define SET_CMD_SENSE_PTR(sp, ptr) \
	(sp->u.scmd.request_sense_ptr = ptr)
560 561 562 563
#define GET_FW_SENSE_LEN(sp) \
	(sp->u.scmd.fw_sense_length)
#define SET_FW_SENSE_LEN(sp, len) \
	(sp->u.scmd.fw_sense_length = len)
564 565 566 567 568 569 570 571

struct msg_echo_lb {
	dma_addr_t send_dma;
	dma_addr_t rcv_dma;
	uint16_t req_sg_cnt;
	uint16_t rsp_sg_cnt;
	uint16_t options;
	uint32_t transfer_size;
572
	uint32_t iteration_count;
573 574
};

L
Linus Torvalds 已提交
575 576 577
/*
 * ISP I/O Register Set structure definitions.
 */
578 579 580
struct device_reg_2xxx {
	uint16_t flash_address; 	/* Flash BIOS address */
	uint16_t flash_data;		/* Flash BIOS data */
L
Linus Torvalds 已提交
581
	uint16_t unused_1[1];		/* Gap */
582
	uint16_t ctrl_status;		/* Control/Status */
A
Andrew Vasquez 已提交
583
#define CSR_FLASH_64K_BANK	BIT_3	/* Flash upper 64K bank select */
L
Linus Torvalds 已提交
584 585 586
#define CSR_FLASH_ENABLE	BIT_1	/* Flash BIOS Read/Write enable */
#define CSR_ISP_SOFT_RESET	BIT_0	/* ISP soft reset */

587
	uint16_t ictrl;			/* Interrupt control */
L
Linus Torvalds 已提交
588 589 590
#define ICR_EN_INT		BIT_15	/* ISP enable interrupts. */
#define ICR_EN_RISC		BIT_3	/* ISP enable RISC interrupts. */

591
	uint16_t istatus;		/* Interrupt status */
L
Linus Torvalds 已提交
592 593
#define ISR_RISC_INT		BIT_3	/* RISC interrupt */

594 595
	uint16_t semaphore;		/* Semaphore */
	uint16_t nvram;			/* NVRAM register. */
L
Linus Torvalds 已提交
596 597 598 599 600 601 602 603 604
#define NVR_DESELECT		0
#define NVR_BUSY		BIT_15
#define NVR_WRT_ENABLE		BIT_14	/* Write enable */
#define NVR_PR_ENABLE		BIT_13	/* Protection register enable */
#define NVR_DATA_IN		BIT_3
#define NVR_DATA_OUT		BIT_2
#define NVR_SELECT		BIT_1
#define NVR_CLOCK		BIT_0

605 606
#define NVR_WAIT_CNT		20000

L
Linus Torvalds 已提交
607 608
	union {
		struct {
609 610 611 612 613 614 615 616 617
			uint16_t mailbox0;
			uint16_t mailbox1;
			uint16_t mailbox2;
			uint16_t mailbox3;
			uint16_t mailbox4;
			uint16_t mailbox5;
			uint16_t mailbox6;
			uint16_t mailbox7;
			uint16_t unused_2[59];	/* Gap */
L
Linus Torvalds 已提交
618 619
		} __attribute__((packed)) isp2100;
		struct {
620 621 622 623 624 625
						/* Request Queue */
			uint16_t req_q_in;	/*  In-Pointer */
			uint16_t req_q_out;	/*  Out-Pointer */
						/* Response Queue */
			uint16_t rsp_q_in;	/*  In-Pointer */
			uint16_t rsp_q_out;	/*  Out-Pointer */
L
Linus Torvalds 已提交
626 627

						/* RISC to Host Status */
A
Andrew Vasquez 已提交
628
			uint32_t host_status;
L
Linus Torvalds 已提交
629 630 631 632
#define HSR_RISC_INT		BIT_15	/* RISC interrupt */
#define HSR_RISC_PAUSED		BIT_8	/* RISC Paused */

					/* Host to Host Semaphore */
A
Andrew Vasquez 已提交
633
			uint16_t host_semaphore;
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
			uint16_t unused_3[17];	/* Gap */
			uint16_t mailbox0;
			uint16_t mailbox1;
			uint16_t mailbox2;
			uint16_t mailbox3;
			uint16_t mailbox4;
			uint16_t mailbox5;
			uint16_t mailbox6;
			uint16_t mailbox7;
			uint16_t mailbox8;
			uint16_t mailbox9;
			uint16_t mailbox10;
			uint16_t mailbox11;
			uint16_t mailbox12;
			uint16_t mailbox13;
			uint16_t mailbox14;
			uint16_t mailbox15;
			uint16_t mailbox16;
			uint16_t mailbox17;
			uint16_t mailbox18;
			uint16_t mailbox19;
			uint16_t mailbox20;
			uint16_t mailbox21;
			uint16_t mailbox22;
			uint16_t mailbox23;
			uint16_t mailbox24;
			uint16_t mailbox25;
			uint16_t mailbox26;
			uint16_t mailbox27;
			uint16_t mailbox28;
			uint16_t mailbox29;
			uint16_t mailbox30;
			uint16_t mailbox31;
			uint16_t fb_cmd;
			uint16_t unused_4[10];	/* Gap */
L
Linus Torvalds 已提交
669 670 671
		} __attribute__((packed)) isp2300;
	} u;

672
	uint16_t fpm_diag_config;
673 674 675
	uint16_t unused_5[0x4];		/* Gap */
	uint16_t risc_hw;
	uint16_t unused_5_1;		/* Gap */
676
	uint16_t pcr;			/* Processor Control Register. */
L
Linus Torvalds 已提交
677
	uint16_t unused_6[0x5];		/* Gap */
678
	uint16_t mctr;			/* Memory Configuration and Timing. */
L
Linus Torvalds 已提交
679
	uint16_t unused_7[0x3];		/* Gap */
680
	uint16_t fb_cmd_2100;		/* Unused on 23XX */
L
Linus Torvalds 已提交
681
	uint16_t unused_8[0x3];		/* Gap */
682
	uint16_t hccr;			/* Host command & control register. */
L
Linus Torvalds 已提交
683 684 685 686 687 688 689 690 691 692 693 694 695
#define HCCR_HOST_INT		BIT_7	/* Host interrupt bit */
#define HCCR_RISC_PAUSE		BIT_5	/* Pause mode bit */
					/* HCCR commands */
#define HCCR_RESET_RISC		0x1000	/* Reset RISC */
#define HCCR_PAUSE_RISC		0x2000	/* Pause RISC */
#define HCCR_RELEASE_RISC	0x3000	/* Release RISC from reset. */
#define HCCR_SET_HOST_INT	0x5000	/* Set host interrupt */
#define HCCR_CLR_HOST_INT	0x6000	/* Clear HOST interrupt */
#define HCCR_CLR_RISC_INT	0x7000	/* Clear RISC interrupt */
#define	HCCR_DISABLE_PARITY_PAUSE 0x4001 /* Disable parity error RISC pause. */
#define HCCR_ENABLE_PARITY	0xA000	/* Enable PARITY interrupt */

	uint16_t unused_9[5];		/* Gap */
696 697
	uint16_t gpiod;			/* GPIO Data register. */
	uint16_t gpioe;			/* GPIO Enable register. */
L
Linus Torvalds 已提交
698 699 700 701 702
#define GPIO_LED_MASK			0x00C0
#define GPIO_LED_GREEN_OFF_AMBER_OFF	0x0000
#define GPIO_LED_GREEN_ON_AMBER_OFF	0x0040
#define GPIO_LED_GREEN_OFF_AMBER_ON	0x0080
#define GPIO_LED_GREEN_ON_AMBER_ON	0x00C0
703 704 705
#define GPIO_LED_ALL_OFF		0x0000
#define GPIO_LED_RED_ON_OTHER_OFF	0x0001	/* isp2322 */
#define GPIO_LED_RGA_ON			0x00C1	/* isp2322: red green amber */
L
Linus Torvalds 已提交
706 707 708

	union {
		struct {
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
			uint16_t unused_10[8];	/* Gap */
			uint16_t mailbox8;
			uint16_t mailbox9;
			uint16_t mailbox10;
			uint16_t mailbox11;
			uint16_t mailbox12;
			uint16_t mailbox13;
			uint16_t mailbox14;
			uint16_t mailbox15;
			uint16_t mailbox16;
			uint16_t mailbox17;
			uint16_t mailbox18;
			uint16_t mailbox19;
			uint16_t mailbox20;
			uint16_t mailbox21;
			uint16_t mailbox22;
			uint16_t mailbox23;	/* Also probe reg. */
L
Linus Torvalds 已提交
726 727
		} __attribute__((packed)) isp2200;
	} u_end;
728 729
};

730
struct device_reg_25xxmq {
731 732 733 734
	uint32_t req_q_in;
	uint32_t req_q_out;
	uint32_t rsp_q_in;
	uint32_t rsp_q_out;
735 736
	uint32_t atio_q_in;
	uint32_t atio_q_out;
737 738
};

739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796

struct device_reg_fx00 {
	uint32_t mailbox0;		/* 00 */
	uint32_t mailbox1;		/* 04 */
	uint32_t mailbox2;		/* 08 */
	uint32_t mailbox3;		/* 0C */
	uint32_t mailbox4;		/* 10 */
	uint32_t mailbox5;		/* 14 */
	uint32_t mailbox6;		/* 18 */
	uint32_t mailbox7;		/* 1C */
	uint32_t mailbox8;		/* 20 */
	uint32_t mailbox9;		/* 24 */
	uint32_t mailbox10;		/* 28 */
	uint32_t mailbox11;
	uint32_t mailbox12;
	uint32_t mailbox13;
	uint32_t mailbox14;
	uint32_t mailbox15;
	uint32_t mailbox16;
	uint32_t mailbox17;
	uint32_t mailbox18;
	uint32_t mailbox19;
	uint32_t mailbox20;
	uint32_t mailbox21;
	uint32_t mailbox22;
	uint32_t mailbox23;
	uint32_t mailbox24;
	uint32_t mailbox25;
	uint32_t mailbox26;
	uint32_t mailbox27;
	uint32_t mailbox28;
	uint32_t mailbox29;
	uint32_t mailbox30;
	uint32_t mailbox31;
	uint32_t aenmailbox0;
	uint32_t aenmailbox1;
	uint32_t aenmailbox2;
	uint32_t aenmailbox3;
	uint32_t aenmailbox4;
	uint32_t aenmailbox5;
	uint32_t aenmailbox6;
	uint32_t aenmailbox7;
	/* Request Queue. */
	uint32_t req_q_in;		/* A0 - Request Queue In-Pointer */
	uint32_t req_q_out;		/* A4 - Request Queue Out-Pointer */
	/* Response Queue. */
	uint32_t rsp_q_in;		/* A8 - Response Queue In-Pointer */
	uint32_t rsp_q_out;		/* AC - Response Queue Out-Pointer */
	/* Init values shadowed on FW Up Event */
	uint32_t initval0;		/* B0 */
	uint32_t initval1;		/* B4 */
	uint32_t initval2;		/* B8 */
	uint32_t initval3;		/* BC */
	uint32_t initval4;		/* C0 */
	uint32_t initval5;		/* C4 */
	uint32_t initval6;		/* C8 */
	uint32_t initval7;		/* CC */
	uint32_t fwheartbeat;		/* D0 */
797
	uint32_t pseudoaen;		/* D4 */
798 799 800 801
};



802
typedef union {
803 804
		struct device_reg_2xxx isp;
		struct device_reg_24xx isp24;
805
		struct device_reg_25xxmq isp25mq;
806
		struct device_reg_82xx isp82;
807
		struct device_reg_fx00 ispfx00;
808
} __iomem device_reg_t;
L
Linus Torvalds 已提交
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826

#define ISP_REQ_Q_IN(ha, reg) \
	(IS_QLA2100(ha) || IS_QLA2200(ha) ? \
	 &(reg)->u.isp2100.mailbox4 : \
	 &(reg)->u.isp2300.req_q_in)
#define ISP_REQ_Q_OUT(ha, reg) \
	(IS_QLA2100(ha) || IS_QLA2200(ha) ? \
	 &(reg)->u.isp2100.mailbox4 : \
	 &(reg)->u.isp2300.req_q_out)
#define ISP_RSP_Q_IN(ha, reg) \
	(IS_QLA2100(ha) || IS_QLA2200(ha) ? \
	 &(reg)->u.isp2100.mailbox5 : \
	 &(reg)->u.isp2300.rsp_q_in)
#define ISP_RSP_Q_OUT(ha, reg) \
	(IS_QLA2100(ha) || IS_QLA2200(ha) ? \
	 &(reg)->u.isp2100.mailbox5 : \
	 &(reg)->u.isp2300.rsp_q_out)

827 828 829
#define ISP_ATIO_Q_IN(vha) (vha->hw->tgt.atio_q_in)
#define ISP_ATIO_Q_OUT(vha) (vha->hw->tgt.atio_q_out)

L
Linus Torvalds 已提交
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862
#define MAILBOX_REG(ha, reg, num) \
	(IS_QLA2100(ha) || IS_QLA2200(ha) ? \
	 (num < 8 ? \
	  &(reg)->u.isp2100.mailbox0 + (num) : \
	  &(reg)->u_end.isp2200.mailbox8 + (num) - 8) : \
	 &(reg)->u.isp2300.mailbox0 + (num))
#define RD_MAILBOX_REG(ha, reg, num) \
	RD_REG_WORD(MAILBOX_REG(ha, reg, num))
#define WRT_MAILBOX_REG(ha, reg, num, data) \
	WRT_REG_WORD(MAILBOX_REG(ha, reg, num), data)

#define FB_CMD_REG(ha, reg) \
	(IS_QLA2100(ha) || IS_QLA2200(ha) ? \
	 &(reg)->fb_cmd_2100 : \
	 &(reg)->u.isp2300.fb_cmd)
#define RD_FB_CMD_REG(ha, reg) \
	RD_REG_WORD(FB_CMD_REG(ha, reg))
#define WRT_FB_CMD_REG(ha, reg, data) \
	WRT_REG_WORD(FB_CMD_REG(ha, reg), data)

typedef struct {
	uint32_t	out_mb;		/* outbound from driver */
	uint32_t	in_mb;			/* Incoming from RISC */
	uint16_t	mb[MAILBOX_REGISTER_COUNT];
	long		buf_size;
	void		*bufp;
	uint32_t	tov;
	uint8_t		flags;
#define MBX_DMA_IN	BIT_0
#define	MBX_DMA_OUT	BIT_1
#define IOCTL_CMD	BIT_2
} mbx_cmd_t;

863 864 865 866 867 868 869 870 871 872 873 874 875 876
struct mbx_cmd_32 {
	uint32_t	out_mb;		/* outbound from driver */
	uint32_t	in_mb;			/* Incoming from RISC */
	uint32_t	mb[MAILBOX_REGISTER_COUNT];
	long		buf_size;
	void		*bufp;
	uint32_t	tov;
	uint8_t		flags;
#define MBX_DMA_IN	BIT_0
#define	MBX_DMA_OUT	BIT_1
#define IOCTL_CMD	BIT_2
};


L
Linus Torvalds 已提交
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
#define	MBX_TOV_SECONDS	30

/*
 *  ISP product identification definitions in mailboxes after reset.
 */
#define PROD_ID_1		0x4953
#define PROD_ID_2		0x0000
#define PROD_ID_2a		0x5020
#define PROD_ID_3		0x2020

/*
 * ISP mailbox Self-Test status codes
 */
#define MBS_FRM_ALIVE		0	/* Firmware Alive. */
#define MBS_CHKSUM_ERR		1	/* Checksum Error. */
#define MBS_BUSY		4	/* Busy. */

/*
 * ISP mailbox command complete status codes
 */
#define MBS_COMMAND_COMPLETE		0x4000
#define MBS_INVALID_COMMAND		0x4001
#define MBS_HOST_INTERFACE_ERROR	0x4002
#define MBS_TEST_FAILED			0x4003
#define MBS_COMMAND_ERROR		0x4005
#define MBS_COMMAND_PARAMETER_ERROR	0x4006
#define MBS_PORT_ID_USED		0x4007
#define MBS_LOOP_ID_USED		0x4008
#define MBS_ALL_IDS_IN_USE		0x4009
#define MBS_NOT_LOGGED_IN		0x400A
907 908
#define MBS_LINK_DOWN_ERROR		0x400B
#define MBS_DIAG_ECHO_TEST_ERROR	0x400C
L
Linus Torvalds 已提交
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937

/*
 * ISP mailbox asynchronous event status codes
 */
#define MBA_ASYNC_EVENT		0x8000	/* Asynchronous event. */
#define MBA_RESET		0x8001	/* Reset Detected. */
#define MBA_SYSTEM_ERR		0x8002	/* System Error. */
#define MBA_REQ_TRANSFER_ERR	0x8003	/* Request Transfer Error. */
#define MBA_RSP_TRANSFER_ERR	0x8004	/* Response Transfer Error. */
#define MBA_WAKEUP_THRES	0x8005	/* Request Queue Wake-up. */
#define MBA_LIP_OCCURRED	0x8010	/* Loop Initialization Procedure */
					/* occurred. */
#define MBA_LOOP_UP		0x8011	/* FC Loop UP. */
#define MBA_LOOP_DOWN		0x8012	/* FC Loop Down. */
#define MBA_LIP_RESET		0x8013	/* LIP reset occurred. */
#define MBA_PORT_UPDATE		0x8014	/* Port Database update. */
#define MBA_RSCN_UPDATE		0x8015	/* Register State Chg Notification. */
#define MBA_LIP_F8		0x8016	/* Received a LIP F8. */
#define MBA_LOOP_INIT_ERR	0x8017	/* Loop Initialization Error. */
#define MBA_FABRIC_AUTH_REQ	0x801b	/* Fabric Authentication Required. */
#define MBA_SCSI_COMPLETION	0x8020	/* SCSI Command Complete. */
#define MBA_CTIO_COMPLETION	0x8021	/* CTIO Complete. */
#define MBA_IP_COMPLETION	0x8022	/* IP Transmit Command Complete. */
#define MBA_IP_RECEIVE		0x8023	/* IP Received. */
#define MBA_IP_BROADCAST	0x8024	/* IP Broadcast Received. */
#define MBA_IP_LOW_WATER_MARK	0x8025	/* IP Low Water Mark reached. */
#define MBA_IP_RCV_BUFFER_EMPTY 0x8026	/* IP receive buffer queue empty. */
#define MBA_IP_HDR_DATA_SPLIT	0x8027	/* IP header/data splitting feature */
					/* used. */
938
#define MBA_TRACE_NOTIFICATION	0x8028	/* Trace/Diagnostic notification. */
L
Linus Torvalds 已提交
939 940 941 942 943 944 945 946 947 948 949 950 951
#define MBA_POINT_TO_POINT	0x8030	/* Point to point mode. */
#define MBA_CMPLT_1_16BIT	0x8031	/* Completion 1 16bit IOSB. */
#define MBA_CMPLT_2_16BIT	0x8032	/* Completion 2 16bit IOSB. */
#define MBA_CMPLT_3_16BIT	0x8033	/* Completion 3 16bit IOSB. */
#define MBA_CMPLT_4_16BIT	0x8034	/* Completion 4 16bit IOSB. */
#define MBA_CMPLT_5_16BIT	0x8035	/* Completion 5 16bit IOSB. */
#define MBA_CHG_IN_CONNECTION	0x8036	/* Change in connection mode. */
#define MBA_RIO_RESPONSE	0x8040	/* RIO response queue update. */
#define MBA_ZIO_RESPONSE	0x8040	/* ZIO response queue update. */
#define MBA_CMPLT_2_32BIT	0x8042	/* Completion 2 32bit IOSB. */
#define MBA_BYPASS_NOTIFICATION	0x8043	/* Auto bypass notification. */
#define MBA_DISCARD_RND_FRAME	0x8048	/* discard RND frame due to error. */
#define MBA_REJECTED_FCP_CMD	0x8049	/* rejected FCP_CMD. */
952 953 954 955 956
#define MBA_FW_NOT_STARTED	0x8050	/* Firmware not started */
#define MBA_FW_STARTING		0x8051	/* Firmware starting */
#define MBA_FW_RESTART_CMPLT	0x8060	/* Firmware restart complete */
#define MBA_INIT_REQUIRED	0x8061	/* Initialization required */
#define MBA_SHUTDOWN_REQUESTED	0x8062	/* Shutdown Requested */
957
#define MBA_TEMPERATURE_ALERT	0x8070	/* Temperature Alert */
958
#define MBA_DPORT_DIAGNOSTICS	0x8080	/* D-port Diagnostics */
959
#define MBA_TRANS_INSERT	0x8130	/* Transceiver Insertion */
960 961 962 963
#define MBA_FW_INIT_FAILURE	0x8401	/* Firmware initialization failure */
#define MBA_MIRROR_LUN_CHANGE	0x8402	/* Mirror LUN State Change
					   Notification */
#define MBA_FW_POLL_STATE	0x8600  /* Firmware in poll diagnostic state */
964
#define MBA_FW_RESET_FCT	0x8502	/* Firmware reset factory defaults */
965
#define MBA_FW_INIT_INPROGRESS	0x8500	/* Firmware boot in progress */
966 967
/* 83XX FCoE specific */
#define MBA_IDC_AEN		0x8200  /* FCoE: NIC Core state change AEN */
968 969 970 971 972 973 974 975 976 977 978

/* Interrupt type codes */
#define INTR_ROM_MB_SUCCESS		0x1
#define INTR_ROM_MB_FAILED		0x2
#define INTR_MB_SUCCESS			0x10
#define INTR_MB_FAILED			0x11
#define INTR_ASYNC_EVENT		0x12
#define INTR_RSP_QUE_UPDATE		0x13
#define INTR_RSP_QUE_UPDATE_83XX	0x14
#define INTR_ATIO_QUE_UPDATE		0x1C
#define INTR_ATIO_RSP_QUE_UPDATE	0x1D
979
#define INTR_ATIO_QUE_UPDATE_27XX	0x1E
980

981 982
/* ISP mailbox loopback echo diagnostic error code */
#define MBS_LB_RESET	0x17
L
Linus Torvalds 已提交
983 984 985 986 987 988 989 990
/*
 * Firmware options 1, 2, 3.
 */
#define FO1_AE_ON_LIPF8			BIT_0
#define FO1_AE_ALL_LIP_RESET		BIT_1
#define FO1_CTIO_RETRY			BIT_3
#define FO1_DISABLE_LIP_F7_SW		BIT_4
#define FO1_DISABLE_100MS_LOS_WAIT	BIT_5
991
#define FO1_DISABLE_GPIO6_7		BIT_6	/* LED bits */
L
Linus Torvalds 已提交
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
#define FO1_AE_ON_LOOP_INIT_ERR		BIT_7
#define FO1_SET_EMPHASIS_SWING		BIT_8
#define FO1_AE_AUTO_BYPASS		BIT_9
#define FO1_ENABLE_PURE_IOCB		BIT_10
#define FO1_AE_PLOGI_RJT		BIT_11
#define FO1_ENABLE_ABORT_SEQUENCE	BIT_12
#define FO1_AE_QUEUE_FULL		BIT_13

#define FO2_ENABLE_ATIO_TYPE_3		BIT_0
#define FO2_REV_LOOPBACK		BIT_1

#define FO3_ENABLE_EMERG_IOCB		BIT_0
#define FO3_AE_RND_ERROR		BIT_1

1006 1007 1008 1009 1010 1011 1012 1013 1014
/* 24XX additional firmware options */
#define ADD_FO_COUNT			3
#define ADD_FO1_DISABLE_GPIO_LED_CTRL	BIT_6	/* LED bits */
#define ADD_FO1_ENABLE_PUREX_IOCB	BIT_10

#define ADD_FO2_ENABLE_SEL_CLS2		BIT_5

#define ADD_FO3_NO_ABT_ON_LINK_DOWN	BIT_14

L
Linus Torvalds 已提交
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
/*
 * ISP mailbox commands
 */
#define MBC_LOAD_RAM			1	/* Load RAM. */
#define MBC_EXECUTE_FIRMWARE		2	/* Execute firmware. */
#define MBC_READ_RAM_WORD		5	/* Read RAM word. */
#define MBC_MAILBOX_REGISTER_TEST	6	/* Wrap incoming mailboxes */
#define MBC_VERIFY_CHECKSUM		7	/* Verify checksum. */
#define MBC_GET_FIRMWARE_VERSION	8	/* Get firmware revision. */
#define MBC_LOAD_RISC_RAM		9	/* Load RAM command. */
#define MBC_DUMP_RISC_RAM		0xa	/* Dump RAM command. */
#define MBC_LOAD_RISC_RAM_EXTENDED	0xb	/* Load RAM extended. */
#define MBC_DUMP_RISC_RAM_EXTENDED	0xc	/* Dump RAM extended. */
#define MBC_WRITE_RAM_WORD_EXTENDED	0xd	/* Write RAM word extended */
#define MBC_READ_RAM_EXTENDED		0xf	/* Read RAM extended. */
#define MBC_IOCB_COMMAND		0x12	/* Execute IOCB command. */
1031
#define MBC_STOP_FIRMWARE		0x14	/* Stop firmware. */
L
Linus Torvalds 已提交
1032 1033 1034 1035 1036
#define MBC_ABORT_COMMAND		0x15	/* Abort IOCB command. */
#define MBC_ABORT_DEVICE		0x16	/* Abort device (ID/LUN). */
#define MBC_ABORT_TARGET		0x17	/* Abort target (ID). */
#define MBC_RESET			0x18	/* Reset. */
#define MBC_GET_ADAPTER_LOOP_ID		0x20	/* Get loop id of ISP2200. */
1037
#define MBC_GET_SET_ZIO_THRESHOLD	0x21	/* Get/SET ZIO THRESHOLD. */
L
Linus Torvalds 已提交
1038 1039 1040 1041
#define MBC_GET_RETRY_COUNT		0x22	/* Get f/w retry cnt/delay. */
#define MBC_DISABLE_VI			0x24	/* Disable VI operation. */
#define MBC_ENABLE_VI			0x25	/* Enable VI operation. */
#define MBC_GET_FIRMWARE_OPTION		0x28	/* Get Firmware Options. */
1042
#define MBC_GET_MEM_OFFLOAD_CNTRL_STAT	0x34	/* Memory Offload ctrl/Stat*/
L
Linus Torvalds 已提交
1043 1044 1045 1046 1047 1048 1049 1050 1051
#define MBC_SET_FIRMWARE_OPTION		0x38	/* Set Firmware Options. */
#define MBC_LOOP_PORT_BYPASS		0x40	/* Loop Port Bypass. */
#define MBC_LOOP_PORT_ENABLE		0x41	/* Loop Port Enable. */
#define MBC_GET_RESOURCE_COUNTS		0x42	/* Get Resource Counts. */
#define MBC_NON_PARTICIPATE		0x43	/* Non-Participating Mode. */
#define MBC_DIAGNOSTIC_ECHO		0x44	/* Diagnostic echo. */
#define MBC_DIAGNOSTIC_LOOP_BACK	0x45	/* Diagnostic loop back. */
#define MBC_ONLINE_SELF_TEST		0x46	/* Online self-test. */
#define MBC_ENHANCED_GET_PORT_DATABASE	0x47	/* Get port database + login */
1052
#define MBC_CONFIGURE_VF		0x4b	/* Configure VFs */
L
Linus Torvalds 已提交
1053 1054
#define MBC_RESET_LINK_STATUS		0x52	/* Reset Link Error Status */
#define MBC_IOCB_COMMAND_A64		0x54	/* Execute IOCB command (64) */
1055
#define MBC_PORT_LOGOUT			0x56	/* Port Logout request */
L
Linus Torvalds 已提交
1056 1057
#define MBC_SEND_RNID_ELS		0x57	/* Send RNID ELS request */
#define MBC_SET_RNID_PARAMS		0x59	/* Set RNID parameters */
1058 1059
#define MBC_GET_RNID_PARAMS		0x5a	/* Get RNID parameters */
#define MBC_DATA_RATE			0x5d	/* Data Rate */
L
Linus Torvalds 已提交
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
#define MBC_INITIALIZE_FIRMWARE		0x60	/* Initialize firmware */
#define MBC_INITIATE_LIP		0x62	/* Initiate Loop */
						/* Initialization Procedure */
#define MBC_GET_FC_AL_POSITION_MAP	0x63	/* Get FC_AL Position Map. */
#define MBC_GET_PORT_DATABASE		0x64	/* Get Port Database. */
#define MBC_CLEAR_ACA			0x65	/* Clear ACA. */
#define MBC_TARGET_RESET		0x66	/* Target Reset. */
#define MBC_CLEAR_TASK_SET		0x67	/* Clear Task Set. */
#define MBC_ABORT_TASK_SET		0x68	/* Abort Task Set. */
#define MBC_GET_FIRMWARE_STATE		0x69	/* Get firmware state. */
#define MBC_GET_PORT_NAME		0x6a	/* Get port name. */
#define MBC_GET_LINK_STATUS		0x6b	/* Get port link status. */
#define MBC_LIP_RESET			0x6c	/* LIP reset. */
#define MBC_SEND_SNS_COMMAND		0x6e	/* Send Simple Name Server */
						/* commandd. */
#define MBC_LOGIN_FABRIC_PORT		0x6f	/* Login fabric port. */
#define MBC_SEND_CHANGE_REQUEST		0x70	/* Send Change Request. */
#define MBC_LOGOUT_FABRIC_PORT		0x71	/* Logout fabric port. */
#define MBC_LIP_FULL_LOGIN		0x72	/* Full login LIP. */
#define MBC_LOGIN_LOOP_PORT		0x74	/* Login Loop Port. */
#define MBC_PORT_NODE_NAME_LIST		0x75	/* Get port/node name list. */
#define MBC_INITIALIZE_RECEIVE_QUEUE	0x77	/* Initialize receive queue */
#define MBC_UNLOAD_IP			0x79	/* Shutdown IP */
#define MBC_GET_ID_LIST			0x7C	/* Get Port ID list. */
#define MBC_SEND_LFA_COMMAND		0x7D	/* Send Loop Fabric Address */
#define MBC_LUN_RESET			0x7E	/* Send LUN reset */

1087 1088 1089 1090 1091 1092
/*
 * all the Mt. Rainier mailbox command codes that clash with FC/FCoE ones
 * should be defined with MBC_MR_*
 */
#define MBC_MR_DRV_SHUTDOWN		0x6A

1093 1094 1095
/*
 * ISP24xx mailbox commands
 */
1096 1097
#define MBC_WRITE_SERDES		0x3	/* Write serdes word. */
#define MBC_READ_SERDES			0x4	/* Read serdes word. */
1098
#define MBC_LOAD_DUMP_MPI_RAM		0x5	/* Load/Dump MPI RAM. */
1099 1100
#define MBC_SERDES_PARAMS		0x10	/* Serdes Tx Parameters. */
#define MBC_GET_IOCB_STATUS		0x12	/* Get IOCB status command. */
1101
#define MBC_PORT_PARAMS			0x1A	/* Port iDMA Parameters. */
1102
#define MBC_GET_TIMEOUT_PARAMS		0x22	/* Get FW timeouts. */
1103
#define MBC_TRACE_CONTROL		0x27	/* Trace control command. */
1104
#define MBC_GEN_SYSTEM_ERROR		0x2a	/* Generate System Error. */
1105
#define MBC_WRITE_SFP			0x30	/* Write SFP Data. */
1106
#define MBC_READ_SFP			0x31	/* Read SFP Data. */
1107
#define MBC_SET_TIMEOUT_PARAMS		0x32	/* Set FW timeouts. */
1108
#define MBC_DPORT_DIAGNOSTICS		0x47	/* D-Port Diagnostics */
1109 1110 1111 1112 1113 1114
#define MBC_MID_INITIALIZE_FIRMWARE	0x48	/* MID Initialize firmware. */
#define MBC_MID_GET_VP_DATABASE		0x49	/* MID Get VP Database. */
#define MBC_MID_GET_VP_ENTRY		0x4a	/* MID Get VP Entry. */
#define MBC_HOST_MEMORY_COPY		0x53	/* Host Memory Copy. */
#define MBC_SEND_RNFT_ELS		0x5e	/* Send RNFT ELS request */
#define MBC_GET_LINK_PRIV_STATS		0x6d	/* Get link & private data. */
1115
#define MBC_LINK_INITIALIZATION		0x72	/* Do link initialization. */
1116
#define MBC_SET_VENDOR_ID		0x76	/* Set Vendor ID. */
1117
#define MBC_PORT_RESET			0x120	/* Port Reset */
1118 1119
#define MBC_SET_PORT_CONFIG		0x122	/* Set port configuration */
#define MBC_GET_PORT_CONFIG		0x123	/* Get port configuration */
1120

1121 1122 1123 1124 1125
/*
 * ISP81xx mailbox commands
 */
#define MBC_WRITE_MPI_REGISTER		0x01    /* Write MPI Register. */

1126 1127 1128 1129 1130 1131 1132
/*
 * ISP8044 mailbox commands
 */
#define MBC_SET_GET_ETH_SERDES_REG	0x150
#define HCS_WRITE_SERDES		0x3
#define HCS_READ_SERDES			0x4

L
Linus Torvalds 已提交
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
/* Firmware return data sizes */
#define FCAL_MAP_SIZE	128

/* Mailbox bit definitions for out_mb and in_mb */
#define	MBX_31		BIT_31
#define	MBX_30		BIT_30
#define	MBX_29		BIT_29
#define	MBX_28		BIT_28
#define	MBX_27		BIT_27
#define	MBX_26		BIT_26
#define	MBX_25		BIT_25
#define	MBX_24		BIT_24
#define	MBX_23		BIT_23
#define	MBX_22		BIT_22
#define	MBX_21		BIT_21
#define	MBX_20		BIT_20
#define	MBX_19		BIT_19
#define	MBX_18		BIT_18
#define	MBX_17		BIT_17
#define	MBX_16		BIT_16
#define	MBX_15		BIT_15
#define	MBX_14		BIT_14
#define	MBX_13		BIT_13
#define	MBX_12		BIT_12
#define	MBX_11		BIT_11
#define	MBX_10		BIT_10
#define	MBX_9		BIT_9
#define	MBX_8		BIT_8
#define	MBX_7		BIT_7
#define	MBX_6		BIT_6
#define	MBX_5		BIT_5
#define	MBX_4		BIT_4
#define	MBX_3		BIT_3
#define	MBX_2		BIT_2
#define	MBX_1		BIT_1
#define	MBX_0		BIT_0

1170
#define RNID_TYPE_PORT_LOGIN	0x7
1171
#define RNID_TYPE_SET_VERSION	0x9
1172
#define RNID_TYPE_ASIC_TEMP	0xC
1173

L
Linus Torvalds 已提交
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
/*
 * Firmware state codes from get firmware state mailbox command
 */
#define FSTATE_CONFIG_WAIT      0
#define FSTATE_WAIT_AL_PA       1
#define FSTATE_WAIT_LOGIN       2
#define FSTATE_READY            3
#define FSTATE_LOSS_OF_SYNC     4
#define FSTATE_ERROR            5
#define FSTATE_REINIT           6
#define FSTATE_NON_PART         7

#define FSTATE_CONFIG_CORRECT      0
#define FSTATE_P2P_RCV_LIP         1
#define FSTATE_P2P_CHOOSE_LOOP     2
#define FSTATE_P2P_RCV_UNIDEN_LIP  3
#define FSTATE_FATAL_ERROR         4
#define FSTATE_LOOP_BACK_CONN      5

1193 1194 1195 1196 1197 1198
#define QLA27XX_IMG_STATUS_VER_MAJOR   0x01
#define QLA27XX_IMG_STATUS_VER_MINOR    0x00
#define QLA27XX_IMG_STATUS_SIGN   0xFACEFADE
#define QLA27XX_PRIMARY_IMAGE  1
#define QLA27XX_SECONDARY_IMAGE    2

L
Linus Torvalds 已提交
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
/*
 * Port Database structure definition
 * Little endian except where noted.
 */
#define	PORT_DATABASE_SIZE	128	/* bytes */
typedef struct {
	uint8_t options;
	uint8_t control;
	uint8_t master_state;
	uint8_t slave_state;
	uint8_t reserved[2];
	uint8_t hard_address;
	uint8_t reserved_1;
	uint8_t port_id[4];
	uint8_t node_name[WWN_SIZE];
	uint8_t port_name[WWN_SIZE];
	uint16_t execution_throttle;
	uint16_t execution_count;
	uint8_t reset_count;
	uint8_t reserved_2;
	uint16_t resource_allocation;
	uint16_t current_allocation;
	uint16_t queue_head;
	uint16_t queue_tail;
	uint16_t transmit_execution_list_next;
	uint16_t transmit_execution_list_previous;
	uint16_t common_features;
	uint16_t total_concurrent_sequences;
	uint16_t RO_by_information_category;
	uint8_t recipient;
	uint8_t initiator;
	uint16_t receive_data_size;
	uint16_t concurrent_sequences;
	uint16_t open_sequences_per_exchange;
	uint16_t lun_abort_flags;
	uint16_t lun_stop_flags;
	uint16_t stop_queue_head;
	uint16_t stop_queue_tail;
	uint16_t port_retry_timer;
	uint16_t next_sequence_id;
	uint16_t frame_count;
	uint16_t PRLI_payload_length;
	uint8_t prli_svc_param_word_0[2];	/* Big endian */
						/* Bits 15-0 of word 0 */
	uint8_t prli_svc_param_word_3[2];	/* Big endian */
						/* Bits 15-0 of word 3 */
	uint16_t loop_id;
	uint16_t extended_lun_info_list_pointer;
	uint16_t extended_lun_stop_list_pointer;
} port_database_t;

/*
 * Port database slave/master states
 */
#define PD_STATE_DISCOVERY			0
#define PD_STATE_WAIT_DISCOVERY_ACK		1
#define PD_STATE_PORT_LOGIN			2
#define PD_STATE_WAIT_PORT_LOGIN_ACK		3
#define PD_STATE_PROCESS_LOGIN			4
#define PD_STATE_WAIT_PROCESS_LOGIN_ACK		5
#define PD_STATE_PORT_LOGGED_IN			6
#define PD_STATE_PORT_UNAVAILABLE		7
#define PD_STATE_PROCESS_LOGOUT			8
#define PD_STATE_WAIT_PROCESS_LOGOUT_ACK	9
#define PD_STATE_PORT_LOGOUT			10
#define PD_STATE_WAIT_PORT_LOGOUT_ACK		11


1267 1268 1269 1270
#define QLA_ZIO_MODE_6		(BIT_2 | BIT_1)
#define QLA_ZIO_DISABLED	0
#define QLA_ZIO_DEFAULT_TIMER	2

L
Linus Torvalds 已提交
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
/*
 * ISP Initialization Control Block.
 * Little endian except where noted.
 */
#define	ICB_VERSION 1
typedef struct {
	uint8_t  version;
	uint8_t  reserved_1;

	/*
	 * LSB BIT 0  = Enable Hard Loop Id
	 * LSB BIT 1  = Enable Fairness
	 * LSB BIT 2  = Enable Full-Duplex
	 * LSB BIT 3  = Enable Fast Posting
	 * LSB BIT 4  = Enable Target Mode
	 * LSB BIT 5  = Disable Initiator Mode
	 * LSB BIT 6  = Enable ADISC
	 * LSB BIT 7  = Enable Target Inquiry Data
	 *
	 * MSB BIT 0  = Enable PDBC Notify
	 * MSB BIT 1  = Non Participating LIP
	 * MSB BIT 2  = Descending Loop ID Search
	 * MSB BIT 3  = Acquire Loop ID in LIPA
	 * MSB BIT 4  = Stop PortQ on Full Status
	 * MSB BIT 5  = Full Login after LIP
	 * MSB BIT 6  = Node Name Option
	 * MSB BIT 7  = Ext IFWCB enable bit
	 */
	uint8_t  firmware_options[2];

	uint16_t frame_payload_size;
	uint16_t max_iocb_allocation;
	uint16_t execution_throttle;
	uint8_t  retry_count;
	uint8_t	 retry_delay;			/* unused */
	uint8_t	 port_name[WWN_SIZE];		/* Big endian. */
	uint16_t hard_address;
	uint8_t	 inquiry_data;
	uint8_t	 login_timeout;
	uint8_t	 node_name[WWN_SIZE];		/* Big endian. */

	uint16_t request_q_outpointer;
	uint16_t response_q_inpointer;
	uint16_t request_q_length;
	uint16_t response_q_length;
	uint32_t request_q_address[2];
	uint32_t response_q_address[2];

	uint16_t lun_enables;
	uint8_t  command_resource_count;
	uint8_t  immediate_notify_resource_count;
	uint16_t timeout;
	uint8_t  reserved_2[2];

	/*
	 * LSB BIT 0 = Timer Operation mode bit 0
	 * LSB BIT 1 = Timer Operation mode bit 1
	 * LSB BIT 2 = Timer Operation mode bit 2
	 * LSB BIT 3 = Timer Operation mode bit 3
	 * LSB BIT 4 = Init Config Mode bit 0
	 * LSB BIT 5 = Init Config Mode bit 1
	 * LSB BIT 6 = Init Config Mode bit 2
	 * LSB BIT 7 = Enable Non part on LIHA failure
	 *
	 * MSB BIT 0 = Enable class 2
	 * MSB BIT 1 = Enable ACK0
	 * MSB BIT 2 =
	 * MSB BIT 3 =
	 * MSB BIT 4 = FC Tape Enable
	 * MSB BIT 5 = Enable FC Confirm
	 * MSB BIT 6 = Enable command queuing in target mode
	 * MSB BIT 7 = No Logo On Link Down
	 */
	uint8_t	 add_firmware_options[2];

	uint8_t	 response_accumulation_timer;
	uint8_t	 interrupt_delay_timer;

	/*
	 * LSB BIT 0 = Enable Read xfr_rdy
	 * LSB BIT 1 = Soft ID only
	 * LSB BIT 2 =
	 * LSB BIT 3 =
	 * LSB BIT 4 = FCP RSP Payload [0]
	 * LSB BIT 5 = FCP RSP Payload [1] / Sbus enable - 2200
	 * LSB BIT 6 = Enable Out-of-Order frame handling
	 * LSB BIT 7 = Disable Automatic PLOGI on Local Loop
	 *
	 * MSB BIT 0 = Sbus enable - 2300
	 * MSB BIT 1 =
	 * MSB BIT 2 =
	 * MSB BIT 3 =
1363
	 * MSB BIT 4 = LED mode
L
Linus Torvalds 已提交
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
	 * MSB BIT 5 = enable 50 ohm termination
	 * MSB BIT 6 = Data Rate (2300 only)
	 * MSB BIT 7 = Data Rate (2300 only)
	 */
	uint8_t	 special_options[2];

	uint8_t  reserved_3[26];
} init_cb_t;

/*
 * Get Link Status mailbox command return buffer.
 */
1376 1377 1378
#define GLSO_SEND_RPS	BIT_0
#define GLSO_USE_DID	BIT_3

1379 1380 1381 1382 1383 1384 1385
struct link_statistics {
	uint32_t link_fail_cnt;
	uint32_t loss_sync_cnt;
	uint32_t loss_sig_cnt;
	uint32_t prim_seq_err_cnt;
	uint32_t inval_xmit_word_cnt;
	uint32_t inval_crc_cnt;
1386
	uint32_t lip_cnt;
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
	uint32_t link_up_cnt;
	uint32_t link_down_loop_init_tmo;
	uint32_t link_down_los;
	uint32_t link_down_loss_rcv_clk;
	uint32_t reserved0[5];
	uint32_t port_cfg_chg;
	uint32_t reserved1[11];
	uint32_t rsp_q_full;
	uint32_t atio_q_full;
	uint32_t drop_ae;
	uint32_t els_proto_err;
	uint32_t reserved2;
1399 1400
	uint32_t tx_frames;
	uint32_t rx_frames;
1401 1402
	uint32_t discarded_frames;
	uint32_t dropped_frames;
1403
	uint32_t reserved3;
1404
	uint32_t nos_rcvd;
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
	uint32_t reserved4[4];
	uint32_t tx_prjt;
	uint32_t rcv_exfail;
	uint32_t rcv_abts;
	uint32_t seq_frm_miss;
	uint32_t corr_err;
	uint32_t mb_rqst;
	uint32_t nport_full;
	uint32_t eofa;
	uint32_t reserved5;
	uint32_t fpm_recv_word_cnt_lo;
	uint32_t fpm_recv_word_cnt_hi;
	uint32_t fpm_disc_word_cnt_lo;
	uint32_t fpm_disc_word_cnt_hi;
	uint32_t fpm_xmit_word_cnt_lo;
	uint32_t fpm_xmit_word_cnt_hi;
	uint32_t reserved6[70];
1422
};
L
Linus Torvalds 已提交
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520

/*
 * NVRAM Command values.
 */
#define NV_START_BIT            BIT_2
#define NV_WRITE_OP             (BIT_26+BIT_24)
#define NV_READ_OP              (BIT_26+BIT_25)
#define NV_ERASE_OP             (BIT_26+BIT_25+BIT_24)
#define NV_MASK_OP              (BIT_26+BIT_25+BIT_24)
#define NV_DELAY_COUNT          10

/*
 * QLogic ISP2100, ISP2200 and ISP2300 NVRAM structure definition.
 */
typedef struct {
	/*
	 * NVRAM header
	 */
	uint8_t	id[4];
	uint8_t	nvram_version;
	uint8_t	reserved_0;

	/*
	 * NVRAM RISC parameter block
	 */
	uint8_t	parameter_block_version;
	uint8_t	reserved_1;

	/*
	 * LSB BIT 0  = Enable Hard Loop Id
	 * LSB BIT 1  = Enable Fairness
	 * LSB BIT 2  = Enable Full-Duplex
	 * LSB BIT 3  = Enable Fast Posting
	 * LSB BIT 4  = Enable Target Mode
	 * LSB BIT 5  = Disable Initiator Mode
	 * LSB BIT 6  = Enable ADISC
	 * LSB BIT 7  = Enable Target Inquiry Data
	 *
	 * MSB BIT 0  = Enable PDBC Notify
	 * MSB BIT 1  = Non Participating LIP
	 * MSB BIT 2  = Descending Loop ID Search
	 * MSB BIT 3  = Acquire Loop ID in LIPA
	 * MSB BIT 4  = Stop PortQ on Full Status
	 * MSB BIT 5  = Full Login after LIP
	 * MSB BIT 6  = Node Name Option
	 * MSB BIT 7  = Ext IFWCB enable bit
	 */
	uint8_t	 firmware_options[2];

	uint16_t frame_payload_size;
	uint16_t max_iocb_allocation;
	uint16_t execution_throttle;
	uint8_t	 retry_count;
	uint8_t	 retry_delay;			/* unused */
	uint8_t	 port_name[WWN_SIZE];		/* Big endian. */
	uint16_t hard_address;
	uint8_t	 inquiry_data;
	uint8_t	 login_timeout;
	uint8_t	 node_name[WWN_SIZE];		/* Big endian. */

	/*
	 * LSB BIT 0 = Timer Operation mode bit 0
	 * LSB BIT 1 = Timer Operation mode bit 1
	 * LSB BIT 2 = Timer Operation mode bit 2
	 * LSB BIT 3 = Timer Operation mode bit 3
	 * LSB BIT 4 = Init Config Mode bit 0
	 * LSB BIT 5 = Init Config Mode bit 1
	 * LSB BIT 6 = Init Config Mode bit 2
	 * LSB BIT 7 = Enable Non part on LIHA failure
	 *
	 * MSB BIT 0 = Enable class 2
	 * MSB BIT 1 = Enable ACK0
	 * MSB BIT 2 =
	 * MSB BIT 3 =
	 * MSB BIT 4 = FC Tape Enable
	 * MSB BIT 5 = Enable FC Confirm
	 * MSB BIT 6 = Enable command queuing in target mode
	 * MSB BIT 7 = No Logo On Link Down
	 */
	uint8_t	 add_firmware_options[2];

	uint8_t	 response_accumulation_timer;
	uint8_t	 interrupt_delay_timer;

	/*
	 * LSB BIT 0 = Enable Read xfr_rdy
	 * LSB BIT 1 = Soft ID only
	 * LSB BIT 2 =
	 * LSB BIT 3 =
	 * LSB BIT 4 = FCP RSP Payload [0]
	 * LSB BIT 5 = FCP RSP Payload [1] / Sbus enable - 2200
	 * LSB BIT 6 = Enable Out-of-Order frame handling
	 * LSB BIT 7 = Disable Automatic PLOGI on Local Loop
	 *
	 * MSB BIT 0 = Sbus enable - 2300
	 * MSB BIT 1 =
	 * MSB BIT 2 =
	 * MSB BIT 3 =
1521
	 * MSB BIT 4 = LED mode
L
Linus Torvalds 已提交
1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539
	 * MSB BIT 5 = enable 50 ohm termination
	 * MSB BIT 6 = Data Rate (2300 only)
	 * MSB BIT 7 = Data Rate (2300 only)
	 */
	uint8_t	 special_options[2];

	/* Reserved for expanded RISC parameter block */
	uint8_t reserved_2[22];

	/*
	 * LSB BIT 0 = Tx Sensitivity 1G bit 0
	 * LSB BIT 1 = Tx Sensitivity 1G bit 1
	 * LSB BIT 2 = Tx Sensitivity 1G bit 2
	 * LSB BIT 3 = Tx Sensitivity 1G bit 3
	 * LSB BIT 4 = Rx Sensitivity 1G bit 0
	 * LSB BIT 5 = Rx Sensitivity 1G bit 1
	 * LSB BIT 6 = Rx Sensitivity 1G bit 2
	 * LSB BIT 7 = Rx Sensitivity 1G bit 3
A
Andrew Vasquez 已提交
1540
	 *
L
Linus Torvalds 已提交
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557
	 * MSB BIT 0 = Tx Sensitivity 2G bit 0
	 * MSB BIT 1 = Tx Sensitivity 2G bit 1
	 * MSB BIT 2 = Tx Sensitivity 2G bit 2
	 * MSB BIT 3 = Tx Sensitivity 2G bit 3
	 * MSB BIT 4 = Rx Sensitivity 2G bit 0
	 * MSB BIT 5 = Rx Sensitivity 2G bit 1
	 * MSB BIT 6 = Rx Sensitivity 2G bit 2
	 * MSB BIT 7 = Rx Sensitivity 2G bit 3
	 *
	 * LSB BIT 0 = Output Swing 1G bit 0
	 * LSB BIT 1 = Output Swing 1G bit 1
	 * LSB BIT 2 = Output Swing 1G bit 2
	 * LSB BIT 3 = Output Emphasis 1G bit 0
	 * LSB BIT 4 = Output Emphasis 1G bit 1
	 * LSB BIT 5 = Output Swing 2G bit 0
	 * LSB BIT 6 = Output Swing 2G bit 1
	 * LSB BIT 7 = Output Swing 2G bit 2
A
Andrew Vasquez 已提交
1558
	 *
L
Linus Torvalds 已提交
1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616
	 * MSB BIT 0 = Output Emphasis 2G bit 0
	 * MSB BIT 1 = Output Emphasis 2G bit 1
	 * MSB BIT 2 = Output Enable
	 * MSB BIT 3 =
	 * MSB BIT 4 =
	 * MSB BIT 5 =
	 * MSB BIT 6 =
	 * MSB BIT 7 =
	 */
	uint8_t seriallink_options[4];

	/*
	 * NVRAM host parameter block
	 *
	 * LSB BIT 0 = Enable spinup delay
	 * LSB BIT 1 = Disable BIOS
	 * LSB BIT 2 = Enable Memory Map BIOS
	 * LSB BIT 3 = Enable Selectable Boot
	 * LSB BIT 4 = Disable RISC code load
	 * LSB BIT 5 = Set cache line size 1
	 * LSB BIT 6 = PCI Parity Disable
	 * LSB BIT 7 = Enable extended logging
	 *
	 * MSB BIT 0 = Enable 64bit addressing
	 * MSB BIT 1 = Enable lip reset
	 * MSB BIT 2 = Enable lip full login
	 * MSB BIT 3 = Enable target reset
	 * MSB BIT 4 = Enable database storage
	 * MSB BIT 5 = Enable cache flush read
	 * MSB BIT 6 = Enable database load
	 * MSB BIT 7 = Enable alternate WWN
	 */
	uint8_t host_p[2];

	uint8_t boot_node_name[WWN_SIZE];
	uint8_t boot_lun_number;
	uint8_t reset_delay;
	uint8_t port_down_retry_count;
	uint8_t boot_id_number;
	uint16_t max_luns_per_target;
	uint8_t fcode_boot_port_name[WWN_SIZE];
	uint8_t alternate_port_name[WWN_SIZE];
	uint8_t alternate_node_name[WWN_SIZE];

	/*
	 * BIT 0 = Selective Login
	 * BIT 1 = Alt-Boot Enable
	 * BIT 2 =
	 * BIT 3 = Boot Order List
	 * BIT 4 =
	 * BIT 5 = Selective LUN
	 * BIT 6 =
	 * BIT 7 = unused
	 */
	uint8_t efi_parameters;

	uint8_t link_down_timeout;

1617
	uint8_t adapter_id[16];
L
Linus Torvalds 已提交
1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680

	uint8_t alt1_boot_node_name[WWN_SIZE];
	uint16_t alt1_boot_lun_number;
	uint8_t alt2_boot_node_name[WWN_SIZE];
	uint16_t alt2_boot_lun_number;
	uint8_t alt3_boot_node_name[WWN_SIZE];
	uint16_t alt3_boot_lun_number;
	uint8_t alt4_boot_node_name[WWN_SIZE];
	uint16_t alt4_boot_lun_number;
	uint8_t alt5_boot_node_name[WWN_SIZE];
	uint16_t alt5_boot_lun_number;
	uint8_t alt6_boot_node_name[WWN_SIZE];
	uint16_t alt6_boot_lun_number;
	uint8_t alt7_boot_node_name[WWN_SIZE];
	uint16_t alt7_boot_lun_number;

	uint8_t reserved_3[2];

	/* Offset 200-215 : Model Number */
	uint8_t model_number[16];

	/* OEM related items */
	uint8_t oem_specific[16];

	/*
	 * NVRAM Adapter Features offset 232-239
	 *
	 * LSB BIT 0 = External GBIC
	 * LSB BIT 1 = Risc RAM parity
	 * LSB BIT 2 = Buffer Plus Module
	 * LSB BIT 3 = Multi Chip Adapter
	 * LSB BIT 4 = Internal connector
	 * LSB BIT 5 =
	 * LSB BIT 6 =
	 * LSB BIT 7 =
	 *
	 * MSB BIT 0 =
	 * MSB BIT 1 =
	 * MSB BIT 2 =
	 * MSB BIT 3 =
	 * MSB BIT 4 =
	 * MSB BIT 5 =
	 * MSB BIT 6 =
	 * MSB BIT 7 =
	 */
	uint8_t	adapter_features[2];

	uint8_t reserved_4[16];

	/* Subsystem vendor ID for ISP2200 */
	uint16_t subsystem_vendor_id_2200;

	/* Subsystem device ID for ISP2200 */
	uint16_t subsystem_device_id_2200;

	uint8_t	 reserved_5;
	uint8_t	 checksum;
} nvram_t;

/*
 * ISP queue - response queue entry definition.
 */
typedef struct {
1681 1682 1683 1684 1685 1686
	uint8_t		entry_type;		/* Entry type. */
	uint8_t		entry_count;		/* Entry count. */
	uint8_t		sys_define;		/* System defined. */
	uint8_t		entry_status;		/* Entry Status. */
	uint32_t	handle;			/* System defined handle */
	uint8_t		data[52];
L
Linus Torvalds 已提交
1687 1688 1689 1690
	uint32_t	signature;
#define RESPONSE_PROCESSED	0xDEADDEAD	/* Signature */
} response_t;

1691 1692 1693 1694 1695 1696
/*
 * ISP queue - ATIO queue entry definition.
 */
struct atio {
	uint8_t		entry_type;		/* Entry type. */
	uint8_t		entry_count;		/* Entry count. */
1697 1698
	__le16		attr_n_length;
	uint8_t		data[56];
1699 1700 1701 1702
	uint32_t	signature;
#define ATIO_PROCESSED 0xDEADDEAD		/* Signature */
};

L
Linus Torvalds 已提交
1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820
typedef union {
	uint16_t extended;
	struct {
		uint8_t reserved;
		uint8_t standard;
	} id;
} target_id_t;

#define SET_TARGET_ID(ha, to, from)			\
do {							\
	if (HAS_EXTENDED_IDS(ha))			\
		to.extended = cpu_to_le16(from);	\
	else						\
		to.id.standard = (uint8_t)from;		\
} while (0)

/*
 * ISP queue - command entry structure definition.
 */
#define COMMAND_TYPE	0x11		/* Command entry */
typedef struct {
	uint8_t entry_type;		/* Entry type. */
	uint8_t entry_count;		/* Entry count. */
	uint8_t sys_define;		/* System defined. */
	uint8_t entry_status;		/* Entry Status. */
	uint32_t handle;		/* System handle. */
	target_id_t target;		/* SCSI ID */
	uint16_t lun;			/* SCSI LUN */
	uint16_t control_flags;		/* Control flags. */
#define CF_WRITE	BIT_6
#define CF_READ		BIT_5
#define CF_SIMPLE_TAG	BIT_3
#define CF_ORDERED_TAG	BIT_2
#define CF_HEAD_TAG	BIT_1
	uint16_t reserved_1;
	uint16_t timeout;		/* Command timeout. */
	uint16_t dseg_count;		/* Data segment count. */
	uint8_t scsi_cdb[MAX_CMDSZ]; 	/* SCSI command words. */
	uint32_t byte_count;		/* Total byte count. */
	uint32_t dseg_0_address;	/* Data segment 0 address. */
	uint32_t dseg_0_length;		/* Data segment 0 length. */
	uint32_t dseg_1_address;	/* Data segment 1 address. */
	uint32_t dseg_1_length;		/* Data segment 1 length. */
	uint32_t dseg_2_address;	/* Data segment 2 address. */
	uint32_t dseg_2_length;		/* Data segment 2 length. */
} cmd_entry_t;

/*
 * ISP queue - 64-Bit addressing, command entry structure definition.
 */
#define COMMAND_A64_TYPE	0x19	/* Command A64 entry */
typedef struct {
	uint8_t entry_type;		/* Entry type. */
	uint8_t entry_count;		/* Entry count. */
	uint8_t sys_define;		/* System defined. */
	uint8_t entry_status;		/* Entry Status. */
	uint32_t handle;		/* System handle. */
	target_id_t target;		/* SCSI ID */
	uint16_t lun;			/* SCSI LUN */
	uint16_t control_flags;		/* Control flags. */
	uint16_t reserved_1;
	uint16_t timeout;		/* Command timeout. */
	uint16_t dseg_count;		/* Data segment count. */
	uint8_t scsi_cdb[MAX_CMDSZ];	/* SCSI command words. */
	uint32_t byte_count;		/* Total byte count. */
	uint32_t dseg_0_address[2];	/* Data segment 0 address. */
	uint32_t dseg_0_length;		/* Data segment 0 length. */
	uint32_t dseg_1_address[2];	/* Data segment 1 address. */
	uint32_t dseg_1_length;		/* Data segment 1 length. */
} cmd_a64_entry_t, request_t;

/*
 * ISP queue - continuation entry structure definition.
 */
#define CONTINUE_TYPE		0x02	/* Continuation entry. */
typedef struct {
	uint8_t entry_type;		/* Entry type. */
	uint8_t entry_count;		/* Entry count. */
	uint8_t sys_define;		/* System defined. */
	uint8_t entry_status;		/* Entry Status. */
	uint32_t reserved;
	uint32_t dseg_0_address;	/* Data segment 0 address. */
	uint32_t dseg_0_length;		/* Data segment 0 length. */
	uint32_t dseg_1_address;	/* Data segment 1 address. */
	uint32_t dseg_1_length;		/* Data segment 1 length. */
	uint32_t dseg_2_address;	/* Data segment 2 address. */
	uint32_t dseg_2_length;		/* Data segment 2 length. */
	uint32_t dseg_3_address;	/* Data segment 3 address. */
	uint32_t dseg_3_length;		/* Data segment 3 length. */
	uint32_t dseg_4_address;	/* Data segment 4 address. */
	uint32_t dseg_4_length;		/* Data segment 4 length. */
	uint32_t dseg_5_address;	/* Data segment 5 address. */
	uint32_t dseg_5_length;		/* Data segment 5 length. */
	uint32_t dseg_6_address;	/* Data segment 6 address. */
	uint32_t dseg_6_length;		/* Data segment 6 length. */
} cont_entry_t;

/*
 * ISP queue - 64-Bit addressing, continuation entry structure definition.
 */
#define CONTINUE_A64_TYPE	0x0A	/* Continuation A64 entry. */
typedef struct {
	uint8_t entry_type;		/* Entry type. */
	uint8_t entry_count;		/* Entry count. */
	uint8_t sys_define;		/* System defined. */
	uint8_t entry_status;		/* Entry Status. */
	uint32_t dseg_0_address[2];	/* Data segment 0 address. */
	uint32_t dseg_0_length;		/* Data segment 0 length. */
	uint32_t dseg_1_address[2];	/* Data segment 1 address. */
	uint32_t dseg_1_length;		/* Data segment 1 length. */
	uint32_t dseg_2_address	[2];	/* Data segment 2 address. */
	uint32_t dseg_2_length;		/* Data segment 2 length. */
	uint32_t dseg_3_address[2];	/* Data segment 3 address. */
	uint32_t dseg_3_length;		/* Data segment 3 length. */
	uint32_t dseg_4_address[2];	/* Data segment 4 address. */
	uint32_t dseg_4_length;		/* Data segment 4 length. */
} cont_a64_entry_t;

1821
#define PO_MODE_DIF_INSERT	0
1822 1823 1824 1825
#define PO_MODE_DIF_REMOVE	1
#define PO_MODE_DIF_PASS	2
#define PO_MODE_DIF_REPLACE	3
#define PO_MODE_DIF_TCP_CKSUM	6
1826 1827
#define PO_ENABLE_INCR_GUARD_SEED	BIT_3
#define PO_DISABLE_GUARD_CHECK	BIT_4
1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839
#define PO_DISABLE_INCR_REF_TAG	BIT_5
#define PO_DIS_HEADER_MODE	BIT_7
#define PO_ENABLE_DIF_BUNDLING	BIT_8
#define PO_DIS_FRAME_MODE	BIT_9
#define PO_DIS_VALD_APP_ESC	BIT_10 /* Dis validation for escape tag/ffffh */
#define PO_DIS_VALD_APP_REF_ESC BIT_11

#define PO_DIS_APP_TAG_REPL	BIT_12 /* disable REG Tag replacement */
#define PO_DIS_REF_TAG_REPL	BIT_13
#define PO_DIS_APP_TAG_VALD	BIT_14 /* disable REF Tag validation */
#define PO_DIS_REF_TAG_VALD	BIT_15

1840 1841 1842 1843 1844
/*
 * ISP queue - 64-Bit addressing, continuation crc entry structure definition.
 */
struct crc_context {
	uint32_t handle;		/* System handle. */
1845 1846
	__le32 ref_tag;
	__le16 app_tag;
1847 1848
	uint8_t ref_tag_mask[4];	/* Validation/Replacement Mask*/
	uint8_t app_tag_mask[2];	/* Validation/Replacement Mask*/
1849 1850 1851
	__le16 guard_seed;		/* Initial Guard Seed */
	__le16 prot_opts;		/* Requested Data Protection Mode */
	__le16 blk_size;		/* Data size in bytes */
1852 1853
	uint16_t runt_blk_guard;	/* Guard value for runt block (tape
					 * only) */
1854
	__le32 byte_count;		/* Total byte count/ total data
1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867
					 * transfer count */
	union {
		struct {
			uint32_t	reserved_1;
			uint16_t	reserved_2;
			uint16_t	reserved_3;
			uint32_t	reserved_4;
			uint32_t	data_address[2];
			uint32_t	data_length;
			uint32_t	reserved_5[2];
			uint32_t	reserved_6;
		} nobundling;
		struct {
1868
			__le32	dif_byte_count;	/* Total DIF byte
1869 1870
							 * count */
			uint16_t	reserved_1;
1871
			__le16	dseg_count;	/* Data segment count */
1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891
			uint32_t	reserved_2;
			uint32_t	data_address[2];
			uint32_t	data_length;
			uint32_t	dif_address[2];
			uint32_t	dif_length;	/* Data segment 0
							 * length */
		} bundling;
	} u;

	struct fcp_cmnd	fcp_cmnd;
	dma_addr_t	crc_ctx_dma;
	/* List of DMA context transfers */
	struct list_head dsd_list;

	/* This structure should not exceed 512 bytes */
};

#define CRC_CONTEXT_LEN_FW	(offsetof(struct crc_context, fcp_cmnd.lun))
#define CRC_CONTEXT_FCPCMND_OFF	(offsetof(struct crc_context, fcp_cmnd.lun))

L
Linus Torvalds 已提交
1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915
/*
 * ISP queue - status entry structure definition.
 */
#define	STATUS_TYPE	0x03		/* Status entry. */
typedef struct {
	uint8_t entry_type;		/* Entry type. */
	uint8_t entry_count;		/* Entry count. */
	uint8_t sys_define;		/* System defined. */
	uint8_t entry_status;		/* Entry Status. */
	uint32_t handle;		/* System handle. */
	uint16_t scsi_status;		/* SCSI status. */
	uint16_t comp_status;		/* Completion status. */
	uint16_t state_flags;		/* State flags. */
	uint16_t status_flags;		/* Status flags. */
	uint16_t rsp_info_len;		/* Response Info Length. */
	uint16_t req_sense_length;	/* Request sense data length. */
	uint32_t residual_length;	/* Residual transfer length. */
	uint8_t rsp_info[8];		/* FCP response information. */
	uint8_t req_sense_data[32];	/* Request sense data. */
} sts_entry_t;

/*
 * Status entry entry status
 */
1916
#define RF_RQ_DMA_ERROR	BIT_6		/* Request Queue DMA error. */
L
Linus Torvalds 已提交
1917 1918 1919 1920 1921
#define RF_INV_E_ORDER	BIT_5		/* Invalid entry order. */
#define RF_INV_E_COUNT	BIT_4		/* Invalid entry count. */
#define RF_INV_E_PARAM	BIT_3		/* Invalid entry parameter. */
#define RF_INV_E_TYPE	BIT_2		/* Invalid entry type. */
#define RF_BUSY		BIT_1		/* Busy */
1922 1923 1924 1925
#define RF_MASK		(RF_RQ_DMA_ERROR | RF_INV_E_ORDER | RF_INV_E_COUNT | \
			 RF_INV_E_PARAM | RF_INV_E_TYPE | RF_BUSY)
#define RF_MASK_24XX	(RF_INV_E_ORDER | RF_INV_E_COUNT | RF_INV_E_PARAM | \
			 RF_INV_E_TYPE)
L
Linus Torvalds 已提交
1926 1927 1928 1929 1930 1931 1932 1933 1934

/*
 * Status entry SCSI status bit definitions.
 */
#define SS_MASK				0xfff	/* Reserved bits BIT_12-BIT_15*/
#define SS_RESIDUAL_UNDER		BIT_11
#define SS_RESIDUAL_OVER		BIT_10
#define SS_SENSE_LEN_VALID		BIT_9
#define SS_RESPONSE_INFO_LEN_VALID	BIT_8
1935
#define SS_SCSI_STATUS_BYTE	0xff
L
Linus Torvalds 已提交
1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952

#define SS_RESERVE_CONFLICT		(BIT_4 | BIT_3)
#define SS_BUSY_CONDITION		BIT_3
#define SS_CONDITION_MET		BIT_2
#define SS_CHECK_CONDITION		BIT_1

/*
 * Status entry completion status
 */
#define CS_COMPLETE		0x0	/* No errors */
#define CS_INCOMPLETE		0x1	/* Incomplete transfer of cmd. */
#define CS_DMA			0x2	/* A DMA direction error. */
#define CS_TRANSPORT		0x3	/* Transport error. */
#define CS_RESET		0x4	/* SCSI bus reset occurred */
#define CS_ABORTED		0x5	/* System aborted command. */
#define CS_TIMEOUT		0x6	/* Timeout error. */
#define CS_DATA_OVERRUN		0x7	/* Data overrun. */
1953
#define CS_DIF_ERROR		0xC	/* DIF error detected  */
L
Linus Torvalds 已提交
1954 1955 1956 1957 1958 1959 1960 1961 1962

#define CS_DATA_UNDERRUN	0x15	/* Data Underrun. */
#define CS_QUEUE_FULL		0x1C	/* Queue Full. */
#define CS_PORT_UNAVAILABLE	0x28	/* Port unavailable */
					/* (selection timeout) */
#define CS_PORT_LOGGED_OUT	0x29	/* Port Logged Out */
#define CS_PORT_CONFIG_CHG	0x2A	/* Port Configuration Changed */
#define CS_PORT_BUSY		0x2B	/* Port Busy */
#define CS_COMPLETE_CHKCOND	0x30	/* Error? */
1963 1964
#define CS_IOCB_ERROR		0x31	/* Generic error for IOCB request
					   failure */
L
Linus Torvalds 已提交
1965 1966 1967 1968 1969
#define CS_BAD_PAYLOAD		0x80	/* Driver defined */
#define CS_UNKNOWN		0x81	/* Driver defined */
#define CS_RETRY		0x82	/* Driver defined */
#define CS_LOOP_DOWN_ABORT	0x83	/* Driver defined */

1970 1971 1972 1973 1974 1975 1976
#define CS_BIDIR_RD_OVERRUN			0x700
#define CS_BIDIR_RD_WR_OVERRUN			0x707
#define CS_BIDIR_RD_OVERRUN_WR_UNDERRUN		0x715
#define CS_BIDIR_RD_UNDERRUN			0x1500
#define CS_BIDIR_RD_UNDERRUN_WR_OVERRUN		0x1507
#define CS_BIDIR_RD_WR_UNDERRUN			0x1515
#define CS_BIDIR_DMA				0x200
L
Linus Torvalds 已提交
1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116
/*
 * Status entry status flags
 */
#define SF_ABTS_TERMINATED	BIT_10
#define SF_LOGOUT_SENT		BIT_13

/*
 * ISP queue - status continuation entry structure definition.
 */
#define	STATUS_CONT_TYPE	0x10	/* Status continuation entry. */
typedef struct {
	uint8_t entry_type;		/* Entry type. */
	uint8_t entry_count;		/* Entry count. */
	uint8_t sys_define;		/* System defined. */
	uint8_t entry_status;		/* Entry Status. */
	uint8_t data[60];		/* data */
} sts_cont_entry_t;

/*
 * ISP queue -	RIO Type 1 status entry (32 bit I/O entry handles)
 *		structure definition.
 */
#define	STATUS_TYPE_21 0x21		/* Status entry. */
typedef struct {
	uint8_t entry_type;		/* Entry type. */
	uint8_t entry_count;		/* Entry count. */
	uint8_t handle_count;		/* Handle count. */
	uint8_t entry_status;		/* Entry Status. */
	uint32_t handle[15];		/* System handles. */
} sts21_entry_t;

/*
 * ISP queue -	RIO Type 2 status entry (16 bit I/O entry handles)
 *		structure definition.
 */
#define	STATUS_TYPE_22	0x22		/* Status entry. */
typedef struct {
	uint8_t entry_type;		/* Entry type. */
	uint8_t entry_count;		/* Entry count. */
	uint8_t handle_count;		/* Handle count. */
	uint8_t entry_status;		/* Entry Status. */
	uint16_t handle[30];		/* System handles. */
} sts22_entry_t;

/*
 * ISP queue - marker entry structure definition.
 */
#define MARKER_TYPE	0x04		/* Marker entry. */
typedef struct {
	uint8_t entry_type;		/* Entry type. */
	uint8_t entry_count;		/* Entry count. */
	uint8_t handle_count;		/* Handle count. */
	uint8_t entry_status;		/* Entry Status. */
	uint32_t sys_define_2;		/* System defined. */
	target_id_t target;		/* SCSI ID */
	uint8_t modifier;		/* Modifier (7-0). */
#define MK_SYNC_ID_LUN	0		/* Synchronize ID/LUN */
#define MK_SYNC_ID	1		/* Synchronize ID */
#define MK_SYNC_ALL	2		/* Synchronize all ID/LUN */
#define MK_SYNC_LIP	3		/* Synchronize all ID/LUN, */
					/* clear port changed, */
					/* use sequence number. */
	uint8_t reserved_1;
	uint16_t sequence_number;	/* Sequence number of event */
	uint16_t lun;			/* SCSI LUN */
	uint8_t reserved_2[48];
} mrk_entry_t;

/*
 * ISP queue - Management Server entry structure definition.
 */
#define MS_IOCB_TYPE		0x29	/* Management Server IOCB entry */
typedef struct {
	uint8_t entry_type;		/* Entry type. */
	uint8_t entry_count;		/* Entry count. */
	uint8_t handle_count;		/* Handle count. */
	uint8_t entry_status;		/* Entry Status. */
	uint32_t handle1;		/* System handle. */
	target_id_t loop_id;
	uint16_t status;
	uint16_t control_flags;		/* Control flags. */
	uint16_t reserved2;
	uint16_t timeout;
	uint16_t cmd_dsd_count;
	uint16_t total_dsd_count;
	uint8_t type;
	uint8_t r_ctl;
	uint16_t rx_id;
	uint16_t reserved3;
	uint32_t handle2;
	uint32_t rsp_bytecount;
	uint32_t req_bytecount;
	uint32_t dseg_req_address[2];	/* Data segment 0 address. */
	uint32_t dseg_req_length;	/* Data segment 0 length. */
	uint32_t dseg_rsp_address[2];	/* Data segment 1 address. */
	uint32_t dseg_rsp_length;	/* Data segment 1 length. */
} ms_iocb_entry_t;


/*
 * ISP queue - Mailbox Command entry structure definition.
 */
#define MBX_IOCB_TYPE	0x39
struct mbx_entry {
	uint8_t entry_type;
	uint8_t entry_count;
	uint8_t sys_define1;
	/* Use sys_define1 for source type */
#define SOURCE_SCSI	0x00
#define SOURCE_IP	0x01
#define SOURCE_VI	0x02
#define SOURCE_SCTP	0x03
#define SOURCE_MP	0x04
#define SOURCE_MPIOCTL	0x05
#define SOURCE_ASYNC_IOCB 0x07

	uint8_t entry_status;

	uint32_t handle;
	target_id_t loop_id;

	uint16_t status;
	uint16_t state_flags;
	uint16_t status_flags;

	uint32_t sys_define2[2];

	uint16_t mb0;
	uint16_t mb1;
	uint16_t mb2;
	uint16_t mb3;
	uint16_t mb6;
	uint16_t mb7;
	uint16_t mb9;
	uint16_t mb10;
	uint32_t reserved_2[2];
	uint8_t node_name[WWN_SIZE];
	uint8_t port_name[WWN_SIZE];
};

2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194
#ifndef IMMED_NOTIFY_TYPE
#define IMMED_NOTIFY_TYPE 0x0D		/* Immediate notify entry. */
/*
 * ISP queue -	immediate notify entry structure definition.
 *		This is sent by the ISP to the Target driver.
 *		This IOCB would have report of events sent by the
 *		initiator, that needs to be handled by the target
 *		driver immediately.
 */
struct imm_ntfy_from_isp {
	uint8_t	 entry_type;		    /* Entry type. */
	uint8_t	 entry_count;		    /* Entry count. */
	uint8_t	 sys_define;		    /* System defined. */
	uint8_t	 entry_status;		    /* Entry Status. */
	union {
		struct {
			uint32_t sys_define_2; /* System defined. */
			target_id_t target;
			uint16_t lun;
			uint8_t  target_id;
			uint8_t  reserved_1;
			uint16_t status_modifier;
			uint16_t status;
			uint16_t task_flags;
			uint16_t seq_id;
			uint16_t srr_rx_id;
			uint32_t srr_rel_offs;
			uint16_t srr_ui;
#define SRR_IU_DATA_IN	0x1
#define SRR_IU_DATA_OUT	0x5
#define SRR_IU_STATUS	0x7
			uint16_t srr_ox_id;
			uint8_t reserved_2[28];
		} isp2x;
		struct {
			uint32_t reserved;
			uint16_t nport_handle;
			uint16_t reserved_2;
			uint16_t flags;
#define NOTIFY24XX_FLAGS_GLOBAL_TPRLO   BIT_1
#define NOTIFY24XX_FLAGS_PUREX_IOCB     BIT_0
			uint16_t srr_rx_id;
			uint16_t status;
			uint8_t  status_subcode;
			uint8_t  fw_handle;
			uint32_t exchange_address;
			uint32_t srr_rel_offs;
			uint16_t srr_ui;
			uint16_t srr_ox_id;
			union {
				struct {
					uint8_t node_name[8];
				} plogi; /* PLOGI/ADISC/PDISC */
				struct {
					/* PRLI word 3 bit 0-15 */
					uint16_t wd3_lo;
					uint8_t resv0[6];
				} prli;
				struct {
					uint8_t port_id[3];
					uint8_t resv1;
					uint16_t nport_handle;
					uint16_t resv2;
				} req_els;
			} u;
			uint8_t port_name[8];
			uint8_t resv3[3];
			uint8_t  vp_index;
			uint32_t reserved_5;
			uint8_t  port_id[3];
			uint8_t  reserved_6;
		} isp24;
	} u;
	uint16_t reserved_7;
	uint16_t ox_id;
} __packed;
#endif

L
Linus Torvalds 已提交
2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209
/*
 * ISP request and response queue entry sizes
 */
#define RESPONSE_ENTRY_SIZE	(sizeof(response_t))
#define REQUEST_ENTRY_SIZE	(sizeof(request_t))



/*
 * Switch info gathering structure.
 */
typedef struct {
	port_id_t d_id;
	uint8_t node_name[WWN_SIZE];
	uint8_t port_name[WWN_SIZE];
2210 2211
	uint8_t fabric_port_name[WWN_SIZE];
	uint16_t fp_speed;
2212
	uint8_t fc4_type;
2213
	uint8_t fc4f_nvme;	/* nvme fc4 feature bits */
L
Linus Torvalds 已提交
2214 2215
} sw_info_t;

2216 2217 2218 2219 2220
/* FCP-4 types */
#define FC4_TYPE_FCP_SCSI	0x08
#define FC4_TYPE_OTHER		0x0
#define FC4_TYPE_UNKNOWN	0xff

2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232
/* mailbox command 4G & above */
struct mbx_24xx_entry {
	uint8_t		entry_type;
	uint8_t		entry_count;
	uint8_t		sys_define1;
	uint8_t		entry_status;
	uint32_t	handle;
	uint16_t	mb[28];
};

#define IOCB_SIZE 64

L
Linus Torvalds 已提交
2233 2234 2235
/*
 * Fibre channel port type.
 */
2236
typedef enum {
L
Linus Torvalds 已提交
2237 2238 2239 2240 2241
	FCT_UNKNOWN,
	FCT_RSCN,
	FCT_SWITCH,
	FCT_BROADCAST,
	FCT_INITIATOR,
2242 2243
	FCT_TARGET,
	FCT_NVME
L
Linus Torvalds 已提交
2244 2245
} fc_port_type_t;

2246 2247 2248 2249 2250 2251
enum qla_sess_deletion {
	QLA_SESS_DELETION_NONE		= 0,
	QLA_SESS_DELETION_IN_PROGRESS,
	QLA_SESS_DELETED,
};

2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262
enum qlt_plogi_link_t {
	QLT_PLOGI_LINK_SAME_WWN,
	QLT_PLOGI_LINK_CONFLICT,
	QLT_PLOGI_LINK_MAX
};

struct qlt_plogi_ack_t {
	struct list_head	list;
	struct imm_ntfy_from_isp iocb;
	port_id_t	id;
	int		ref_count;
2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280
	void		*fcport;
};

struct ct_sns_desc {
	struct ct_sns_pkt	*ct_sns;
	dma_addr_t		ct_sns_dma;
};

enum discovery_state {
	DSC_DELETED,
	DSC_GID_PN,
	DSC_GNL,
	DSC_LOGIN_PEND,
	DSC_LOGIN_FAILED,
	DSC_GPDB,
	DSC_GPSC,
	DSC_UPD_FCPORT,
	DSC_LOGIN_COMPLETE,
2281
	DSC_ADISC,
2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300
	DSC_DELETE_PEND,
};

enum login_state {	/* FW control Target side */
	DSC_LS_LLIOCB_SENT = 2,
	DSC_LS_PLOGI_PEND,
	DSC_LS_PLOGI_COMP,
	DSC_LS_PRLI_PEND,
	DSC_LS_PRLI_COMP,
	DSC_LS_PORT_UNAVAIL,
	DSC_LS_PRLO_PEND = 9,
	DSC_LS_LOGO_PEND,
};

enum fcport_mgt_event {
	FCME_RELOGIN = 1,
	FCME_RSCN,
	FCME_GIDPN_DONE,
	FCME_PLOGI_DONE,	/* Initiator side sent LLIOCB */
2301
	FCME_PRLI_DONE,
2302 2303 2304 2305
	FCME_GNL_DONE,
	FCME_GPSC_DONE,
	FCME_GPDB_DONE,
	FCME_GPNID_DONE,
2306
	FCME_GFFID_DONE,
2307
	FCME_DELETE_DONE,
2308
	FCME_ADISC_DONE,
2309 2310
};

2311 2312 2313 2314 2315 2316 2317
enum rscn_addr_format {
	RSCN_PORT_ADDR,
	RSCN_AREA_ADDR,
	RSCN_DOM_ADDR,
	RSCN_FAB_ADDR,
};

L
Linus Torvalds 已提交
2318 2319 2320 2321 2322
/*
 * Fibre channel port structure.
 */
typedef struct fc_port {
	struct list_head list;
2323
	struct scsi_qla_host *vha;
L
Linus Torvalds 已提交
2324 2325 2326 2327 2328 2329 2330

	uint8_t node_name[WWN_SIZE];
	uint8_t port_name[WWN_SIZE];
	port_id_t d_id;
	uint16_t loop_id;
	uint16_t old_loop_id;

2331 2332 2333 2334
	unsigned int conf_compl_supported:1;
	unsigned int deleted:2;
	unsigned int local:1;
	unsigned int logout_on_delete:1;
2335
	unsigned int logo_ack_needed:1;
2336 2337
	unsigned int keep_nport_handle:1;
	unsigned int send_els_logo:1;
2338 2339
	unsigned int login_pause:1;
	unsigned int login_succ:1;
2340
	unsigned int query:1;
2341

2342
	struct work_struct nvme_del_work;
2343
	struct completion nvme_del_done;
2344 2345 2346 2347 2348 2349 2350 2351
	uint32_t nvme_prli_service_param;
#define NVME_PRLI_SP_CONF       BIT_7
#define NVME_PRLI_SP_INITIATOR  BIT_5
#define NVME_PRLI_SP_TARGET     BIT_4
#define NVME_PRLI_SP_DISCOVERY  BIT_3
	uint8_t nvme_flag;
#define NVME_FLAG_REGISTERED 4

2352
	struct fc_port *conflict;
2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364
	unsigned char logout_completed;
	int generation;

	struct se_session *se_sess;
	struct kref sess_kref;
	struct qla_tgt *tgt;
	unsigned long expires;
	struct list_head del_list_entry;
	struct work_struct free_work;

	struct qlt_plogi_ack_t *plogi_link[QLT_PLOGI_LINK_MAX];

2365 2366 2367
	uint16_t tgt_id;
	uint16_t old_tgt_id;

S
Sarang Radke 已提交
2368 2369
	uint8_t fcp_prio;

2370 2371 2372
	uint8_t fabric_port_name[WWN_SIZE];
	uint16_t fp_speed;

L
Linus Torvalds 已提交
2373 2374 2375 2376 2377 2378 2379
	fc_port_type_t port_type;

	atomic_t state;
	uint32_t flags;

	int login_retry;

2380
	struct fc_rport *rport, *drport;
2381
	u32 supported_classes;
2382

2383
	uint8_t fc4_type;
2384
	uint8_t	fc4f_nvme;
2385
	uint8_t scan_state;
2386
	uint8_t n2n_flag;
2387 2388 2389 2390 2391

	unsigned long last_queue_full;
	unsigned long last_ramp_up;

	uint16_t port_id;
2392

2393 2394
	struct nvme_fc_remote_port *nvme_remote_port;

2395
	unsigned long retry_delay_timestamp;
2396
	struct qla_tgt_sess *tgt_session;
2397 2398 2399
	struct ct_sns_desc ct_desc;
	enum discovery_state disc_state;
	enum login_state fw_login_state;
2400 2401
	unsigned long plogi_nack_done_deadline;

2402 2403 2404 2405 2406 2407
	u32 login_gen, last_login_gen;
	u32 rscn_gen, last_rscn_gen;
	u32 chip_reset;
	struct list_head gnl_entry;
	struct work_struct del_work;
	u8 iocb[IOCB_SIZE];
2408 2409
	u8 current_login_state;
	u8 last_login_state;
2410
	struct completion n2n_done;
L
Linus Torvalds 已提交
2411 2412
} fc_port_t;

2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425
#define QLA_FCPORT_SCAN		1
#define QLA_FCPORT_FOUND	2

struct event_arg {
	enum fcport_mgt_event	event;
	fc_port_t		*fcport;
	srb_t			*sp;
	port_id_t		id;
	u16			data[2], rc;
	u8			port_name[WWN_SIZE];
	u32			iop[2];
};

2426 2427
#include "qla_mr.h"

L
Linus Torvalds 已提交
2428 2429 2430 2431 2432 2433 2434 2435
/*
 * Fibre channel port/lun states.
 */
#define FCS_UNCONFIGURED	1
#define FCS_DEVICE_DEAD		2
#define FCS_DEVICE_LOST		3
#define FCS_ONLINE		4

2436 2437 2438 2439 2440 2441 2442 2443
static const char * const port_state_str[] = {
	"Unknown",
	"UNCONFIGURED",
	"DEAD",
	"LOST",
	"ONLINE"
};

L
Linus Torvalds 已提交
2444 2445 2446 2447 2448
/*
 * FC port flags.
 */
#define FCF_FABRIC_DEVICE	BIT_0
#define FCF_LOGIN_NEEDED	BIT_1
2449
#define FCF_FCP2_DEVICE		BIT_2
2450
#define FCF_ASYNC_SENT		BIT_3
2451
#define FCF_CONF_COMP_SUPPORTED BIT_4
L
Linus Torvalds 已提交
2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463

/* No loop ID flag. */
#define FC_NO_LOOP_ID		0x1000

/*
 * FC-CT interface
 *
 * NOTE: All structures are big-endian in form.
 */

#define CT_REJECT_RESPONSE	0x8001
#define CT_ACCEPT_RESPONSE	0x8002
2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478
#define CT_REASON_INVALID_COMMAND_CODE		0x01
#define CT_REASON_CANNOT_PERFORM		0x09
#define CT_REASON_COMMAND_UNSUPPORTED		0x0b
#define CT_EXPL_ALREADY_REGISTERED		0x10
#define CT_EXPL_HBA_ATTR_NOT_REGISTERED		0x11
#define CT_EXPL_MULTIPLE_HBA_ATTR		0x12
#define CT_EXPL_INVALID_HBA_BLOCK_LENGTH	0x13
#define CT_EXPL_MISSING_REQ_HBA_ATTR		0x14
#define CT_EXPL_PORT_NOT_REGISTERED_		0x15
#define CT_EXPL_MISSING_HBA_ID_PORT_LIST	0x16
#define CT_EXPL_HBA_NOT_REGISTERED		0x17
#define CT_EXPL_PORT_ATTR_NOT_REGISTERED	0x20
#define CT_EXPL_PORT_NOT_REGISTERED		0x21
#define CT_EXPL_MULTIPLE_PORT_ATTR		0x22
#define CT_EXPL_INVALID_PORT_BLOCK_LENGTH	0x23
L
Linus Torvalds 已提交
2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502

#define NS_N_PORT_TYPE	0x01
#define NS_NL_PORT_TYPE	0x02
#define NS_NX_PORT_TYPE	0x7F

#define	GA_NXT_CMD	0x100
#define	GA_NXT_REQ_SIZE	(16 + 4)
#define	GA_NXT_RSP_SIZE	(16 + 620)

#define	GID_PT_CMD	0x1A1
#define	GID_PT_REQ_SIZE	(16 + 4)

#define	GPN_ID_CMD	0x112
#define	GPN_ID_REQ_SIZE	(16 + 4)
#define	GPN_ID_RSP_SIZE	(16 + 8)

#define	GNN_ID_CMD	0x113
#define	GNN_ID_REQ_SIZE	(16 + 4)
#define	GNN_ID_RSP_SIZE	(16 + 8)

#define	GFT_ID_CMD	0x117
#define	GFT_ID_REQ_SIZE	(16 + 4)
#define	GFT_ID_RSP_SIZE	(16 + 32)

2503 2504 2505 2506
#define GID_PN_CMD 0x121
#define GID_PN_REQ_SIZE (16 + 8)
#define GID_PN_RSP_SIZE (16 + 4)

L
Linus Torvalds 已提交
2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522
#define	RFT_ID_CMD	0x217
#define	RFT_ID_REQ_SIZE	(16 + 4 + 32)
#define	RFT_ID_RSP_SIZE	16

#define	RFF_ID_CMD	0x21F
#define	RFF_ID_REQ_SIZE	(16 + 4 + 2 + 1 + 1)
#define	RFF_ID_RSP_SIZE	16

#define	RNN_ID_CMD	0x213
#define	RNN_ID_REQ_SIZE	(16 + 4 + 8)
#define	RNN_ID_RSP_SIZE	16

#define	RSNN_NN_CMD	 0x239
#define	RSNN_NN_REQ_SIZE (16 + 8 + 1 + 255)
#define	RSNN_NN_RSP_SIZE 16

2523 2524 2525 2526 2527 2528 2529 2530
#define	GFPN_ID_CMD	0x11C
#define	GFPN_ID_REQ_SIZE (16 + 4)
#define	GFPN_ID_RSP_SIZE (16 + 8)

#define	GPSC_CMD	0x127
#define	GPSC_REQ_SIZE	(16 + 8)
#define	GPSC_RSP_SIZE	(16 + 2 + 2)

2531 2532 2533
#define GFF_ID_CMD	0x011F
#define GFF_ID_REQ_SIZE	(16 + 4)
#define GFF_ID_RSP_SIZE (16 + 128)
2534

2535 2536 2537 2538
/*
 * HBA attribute types.
 */
#define FDMI_HBA_ATTR_COUNT			9
2539 2540 2541 2542 2543 2544 2545 2546 2547 2548
#define FDMIV2_HBA_ATTR_COUNT			17
#define FDMI_HBA_NODE_NAME			0x1
#define FDMI_HBA_MANUFACTURER			0x2
#define FDMI_HBA_SERIAL_NUMBER			0x3
#define FDMI_HBA_MODEL				0x4
#define FDMI_HBA_MODEL_DESCRIPTION		0x5
#define FDMI_HBA_HARDWARE_VERSION		0x6
#define FDMI_HBA_DRIVER_VERSION			0x7
#define FDMI_HBA_OPTION_ROM_VERSION		0x8
#define FDMI_HBA_FIRMWARE_VERSION		0x9
2549 2550
#define FDMI_HBA_OS_NAME_AND_VERSION		0xa
#define FDMI_HBA_MAXIMUM_CT_PAYLOAD_LENGTH	0xb
2551 2552 2553 2554 2555 2556
#define FDMI_HBA_NODE_SYMBOLIC_NAME		0xc
#define FDMI_HBA_VENDOR_ID			0xd
#define FDMI_HBA_NUM_PORTS			0xe
#define FDMI_HBA_FABRIC_NAME			0xf
#define FDMI_HBA_BOOT_BIOS_NAME			0x10
#define FDMI_HBA_TYPE_VENDOR_IDENTIFIER		0xe0
2557 2558 2559 2560 2561 2562

struct ct_fdmi_hba_attr {
	uint16_t type;
	uint16_t len;
	union {
		uint8_t node_name[WWN_SIZE];
2563 2564
		uint8_t manufacturer[64];
		uint8_t serial_num[32];
2565
		uint8_t model[16+1];
2566
		uint8_t model_desc[80];
2567
		uint8_t hw_version[32];
2568 2569
		uint8_t driver_version[32];
		uint8_t orom_version[16];
2570
		uint8_t fw_version[32];
2571
		uint8_t os_version[128];
2572
		uint32_t max_ct_len;
2573 2574 2575 2576 2577 2578 2579 2580
	} a;
};

struct ct_fdmi_hba_attributes {
	uint32_t count;
	struct ct_fdmi_hba_attr entry[FDMI_HBA_ATTR_COUNT];
};

2581 2582 2583 2584 2585
struct ct_fdmiv2_hba_attr {
	uint16_t type;
	uint16_t len;
	union {
		uint8_t node_name[WWN_SIZE];
2586
		uint8_t manufacturer[64];
2587
		uint8_t serial_num[32];
2588
		uint8_t model[16+1];
2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600
		uint8_t model_desc[80];
		uint8_t hw_version[16];
		uint8_t driver_version[32];
		uint8_t orom_version[16];
		uint8_t fw_version[32];
		uint8_t os_version[128];
		uint32_t max_ct_len;
		uint8_t sym_name[256];
		uint32_t vendor_id;
		uint32_t num_ports;
		uint8_t fabric_name[WWN_SIZE];
		uint8_t bios_name[32];
2601
		uint8_t vendor_identifier[8];
2602 2603 2604 2605 2606 2607 2608 2609
	} a;
};

struct ct_fdmiv2_hba_attributes {
	uint32_t count;
	struct ct_fdmiv2_hba_attr entry[FDMIV2_HBA_ATTR_COUNT];
};

2610 2611 2612
/*
 * Port attribute types.
 */
2613
#define FDMI_PORT_ATTR_COUNT		6
2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630
#define FDMIV2_PORT_ATTR_COUNT		16
#define FDMI_PORT_FC4_TYPES		0x1
#define FDMI_PORT_SUPPORT_SPEED		0x2
#define FDMI_PORT_CURRENT_SPEED		0x3
#define FDMI_PORT_MAX_FRAME_SIZE	0x4
#define FDMI_PORT_OS_DEVICE_NAME	0x5
#define FDMI_PORT_HOST_NAME		0x6
#define FDMI_PORT_NODE_NAME		0x7
#define FDMI_PORT_NAME			0x8
#define FDMI_PORT_SYM_NAME		0x9
#define FDMI_PORT_TYPE			0xa
#define FDMI_PORT_SUPP_COS		0xb
#define FDMI_PORT_FABRIC_NAME		0xc
#define FDMI_PORT_FC4_TYPE		0xd
#define FDMI_PORT_STATE			0x101
#define FDMI_PORT_COUNT			0x102
#define FDMI_PORT_ID			0x103
2631

2632 2633 2634 2635 2636 2637
#define FDMI_PORT_SPEED_1GB		0x1
#define FDMI_PORT_SPEED_2GB		0x2
#define FDMI_PORT_SPEED_10GB		0x4
#define FDMI_PORT_SPEED_4GB		0x8
#define FDMI_PORT_SPEED_8GB		0x10
#define FDMI_PORT_SPEED_16GB		0x20
2638
#define FDMI_PORT_SPEED_32GB		0x40
2639 2640
#define FDMI_PORT_SPEED_UNKNOWN		0x8000

2641 2642 2643 2644 2645
#define FC_CLASS_2	0x04
#define FC_CLASS_3	0x08
#define FC_CLASS_2_3	0x0C

struct ct_fdmiv2_port_attr {
2646 2647 2648 2649 2650 2651 2652 2653
	uint16_t type;
	uint16_t len;
	union {
		uint8_t fc4_types[32];
		uint32_t sup_speed;
		uint32_t cur_speed;
		uint32_t max_frame_size;
		uint8_t os_dev_name[32];
2654
		uint8_t host_name[256];
2655 2656 2657 2658 2659 2660 2661 2662 2663 2664
		uint8_t node_name[WWN_SIZE];
		uint8_t port_name[WWN_SIZE];
		uint8_t port_sym_name[128];
		uint32_t port_type;
		uint32_t port_supported_cos;
		uint8_t fabric_name[WWN_SIZE];
		uint8_t port_fc4_type[32];
		uint32_t port_state;
		uint32_t num_ports;
		uint32_t port_id;
2665 2666 2667 2668 2669 2670
	} a;
};

/*
 * Port Attribute Block.
 */
2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684
struct ct_fdmiv2_port_attributes {
	uint32_t count;
	struct ct_fdmiv2_port_attr entry[FDMIV2_PORT_ATTR_COUNT];
};

struct ct_fdmi_port_attr {
	uint16_t type;
	uint16_t len;
	union {
		uint8_t fc4_types[32];
		uint32_t sup_speed;
		uint32_t cur_speed;
		uint32_t max_frame_size;
		uint8_t os_dev_name[32];
2685
		uint8_t host_name[256];
2686 2687 2688
	} a;
};

2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716
struct ct_fdmi_port_attributes {
	uint32_t count;
	struct ct_fdmi_port_attr entry[FDMI_PORT_ATTR_COUNT];
};

/* FDMI definitions. */
#define GRHL_CMD	0x100
#define GHAT_CMD	0x101
#define GRPL_CMD	0x102
#define GPAT_CMD	0x110

#define RHBA_CMD	0x200
#define RHBA_RSP_SIZE	16

#define RHAT_CMD	0x201
#define RPRT_CMD	0x210

#define RPA_CMD		0x211
#define RPA_RSP_SIZE	16

#define DHBA_CMD	0x300
#define DHBA_REQ_SIZE	(16 + 8)
#define DHBA_RSP_SIZE	16

#define DHAT_CMD	0x301
#define DPRT_CMD	0x310
#define DPA_CMD		0x311

L
Linus Torvalds 已提交
2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735
/* CT command header -- request/response common fields */
struct ct_cmd_hdr {
	uint8_t revision;
	uint8_t in_id[3];
	uint8_t gs_type;
	uint8_t gs_subtype;
	uint8_t options;
	uint8_t reserved;
};

/* CT command request */
struct ct_sns_req {
	struct ct_cmd_hdr header;
	uint16_t command;
	uint16_t max_rsp_size;
	uint8_t fragment_id;
	uint8_t reserved[3];

	union {
2736
		/* GA_NXT, GPN_ID, GNN_ID, GFT_ID, GFPN_ID */
L
Linus Torvalds 已提交
2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773
		struct {
			uint8_t reserved;
			uint8_t port_id[3];
		} port_id;

		struct {
			uint8_t port_type;
			uint8_t domain;
			uint8_t area;
			uint8_t reserved;
		} gid_pt;

		struct {
			uint8_t reserved;
			uint8_t port_id[3];
			uint8_t fc4_types[32];
		} rft_id;

		struct {
			uint8_t reserved;
			uint8_t port_id[3];
			uint16_t reserved2;
			uint8_t fc4_feature;
			uint8_t fc4_type;
		} rff_id;

		struct {
			uint8_t reserved;
			uint8_t port_id[3];
			uint8_t node_name[8];
		} rnn_id;

		struct {
			uint8_t node_name[8];
			uint8_t name_len;
			uint8_t sym_node_name[255];
		} rsnn_nn;
2774 2775

		struct {
2776
			uint8_t hba_identifier[8];
2777 2778 2779 2780 2781 2782 2783 2784 2785
		} ghat;

		struct {
			uint8_t hba_identifier[8];
			uint32_t entry_count;
			uint8_t port_name[8];
			struct ct_fdmi_hba_attributes attrs;
		} rhba;

2786 2787 2788 2789 2790 2791 2792
		struct {
			uint8_t hba_identifier[8];
			uint32_t entry_count;
			uint8_t port_name[8];
			struct ct_fdmiv2_hba_attributes attrs;
		} rhba2;

2793 2794 2795 2796 2797 2798 2799 2800 2801 2802
		struct {
			uint8_t hba_identifier[8];
			struct ct_fdmi_hba_attributes attrs;
		} rhat;

		struct {
			uint8_t port_name[8];
			struct ct_fdmi_port_attributes attrs;
		} rpa;

2803 2804 2805 2806 2807
		struct {
			uint8_t port_name[8];
			struct ct_fdmiv2_port_attributes attrs;
		} rpa2;

2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822
		struct {
			uint8_t port_name[8];
		} dhba;

		struct {
			uint8_t port_name[8];
		} dhat;

		struct {
			uint8_t port_name[8];
		} dprt;

		struct {
			uint8_t port_name[8];
		} dpa;
2823 2824 2825 2826

		struct {
			uint8_t port_name[8];
		} gpsc;
2827 2828 2829

		struct {
			uint8_t reserved;
2830
			uint8_t port_id[3];
2831
		} gff_id;
2832 2833 2834 2835

		struct {
			uint8_t port_name[8];
		} gid_pn;
L
Linus Torvalds 已提交
2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878
	} req;
};

/* CT command response header */
struct ct_rsp_hdr {
	struct ct_cmd_hdr header;
	uint16_t response;
	uint16_t residual;
	uint8_t fragment_id;
	uint8_t reason_code;
	uint8_t explanation_code;
	uint8_t vendor_unique;
};

struct ct_sns_gid_pt_data {
	uint8_t control_byte;
	uint8_t port_id[3];
};

struct ct_sns_rsp {
	struct ct_rsp_hdr header;

	union {
		struct {
			uint8_t port_type;
			uint8_t port_id[3];
			uint8_t port_name[8];
			uint8_t sym_port_name_len;
			uint8_t sym_port_name[255];
			uint8_t node_name[8];
			uint8_t sym_node_name_len;
			uint8_t sym_node_name[255];
			uint8_t init_proc_assoc[8];
			uint8_t node_ip_addr[16];
			uint8_t class_of_service[4];
			uint8_t fc4_types[32];
			uint8_t ip_address[16];
			uint8_t fabric_port_name[8];
			uint8_t reserved;
			uint8_t hard_address[3];
		} ga_nxt;

		struct {
2879 2880 2881
			/* Assume the largest number of targets for the union */
			struct ct_sns_gid_pt_data
			    entries[MAX_FIBRE_DEVICES_MAX];
L
Linus Torvalds 已提交
2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894
		} gid_pt;

		struct {
			uint8_t port_name[8];
		} gpn_id;

		struct {
			uint8_t node_name[8];
		} gnn_id;

		struct {
			uint8_t fc4_types[32];
		} gft_id;
2895 2896 2897 2898 2899 2900

		struct {
			uint32_t entry_count;
			uint8_t port_name[8];
			struct ct_fdmi_hba_attributes attrs;
		} ghat;
2901 2902 2903 2904 2905 2906 2907 2908 2909

		struct {
			uint8_t port_name[8];
		} gfpn_id;

		struct {
			uint16_t speeds;
			uint16_t speed;
		} gpsc;
2910 2911

#define GFF_FCP_SCSI_OFFSET	7
2912
#define GFF_NVME_OFFSET		23 /* type = 28h */
2913 2914 2915
		struct {
			uint8_t fc4_features[128];
		} gff_id;
2916 2917 2918 2919
		struct {
			uint8_t reserved;
			uint8_t port_id[3];
		} gid_pn;
L
Linus Torvalds 已提交
2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930
	} rsp;
};

struct ct_sns_pkt {
	union {
		struct ct_sns_req req;
		struct ct_sns_rsp rsp;
	} p;
};

/*
L
Lucas De Marchi 已提交
2931
 * SNS command structures -- for 2200 compatibility.
L
Linus Torvalds 已提交
2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946
 */
#define	RFT_ID_SNS_SCMD_LEN	22
#define	RFT_ID_SNS_CMD_SIZE	60
#define	RFT_ID_SNS_DATA_SIZE	16

#define	RNN_ID_SNS_SCMD_LEN	10
#define	RNN_ID_SNS_CMD_SIZE	36
#define	RNN_ID_SNS_DATA_SIZE	16

#define	GA_NXT_SNS_SCMD_LEN	6
#define	GA_NXT_SNS_CMD_SIZE	28
#define	GA_NXT_SNS_DATA_SIZE	(620 + 16)

#define	GID_PT_SNS_SCMD_LEN	6
#define	GID_PT_SNS_CMD_SIZE	28
2947 2948 2949 2950 2951
/*
 * Assume MAX_FIBRE_DEVICES_2100 as these defines are only used with older
 * adapters.
 */
#define	GID_PT_SNS_DATA_SIZE	(MAX_FIBRE_DEVICES_2100 * 4 + 16)
L
Linus Torvalds 已提交
2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983

#define	GPN_ID_SNS_SCMD_LEN	6
#define	GPN_ID_SNS_CMD_SIZE	28
#define	GPN_ID_SNS_DATA_SIZE	(8 + 16)

#define	GNN_ID_SNS_SCMD_LEN	6
#define	GNN_ID_SNS_CMD_SIZE	28
#define	GNN_ID_SNS_DATA_SIZE	(8 + 16)

struct sns_cmd_pkt {
	union {
		struct {
			uint16_t buffer_length;
			uint16_t reserved_1;
			uint32_t buffer_address[2];
			uint16_t subcommand_length;
			uint16_t reserved_2;
			uint16_t subcommand;
			uint16_t size;
			uint32_t reserved_3;
			uint8_t param[36];
		} cmd;

		uint8_t rft_data[RFT_ID_SNS_DATA_SIZE];
		uint8_t rnn_data[RNN_ID_SNS_DATA_SIZE];
		uint8_t gan_data[GA_NXT_SNS_DATA_SIZE];
		uint8_t gid_data[GID_PT_SNS_DATA_SIZE];
		uint8_t gpn_data[GPN_ID_SNS_DATA_SIZE];
		uint8_t gnn_data[GNN_ID_SNS_DATA_SIZE];
	} p;
};

2984 2985 2986 2987 2988 2989
struct fw_blob {
	char *name;
	uint32_t segs[4];
	const struct firmware *fw;
};

L
Linus Torvalds 已提交
2990 2991 2992 2993
/* Return data from MBC_GET_ID_LIST call. */
struct gid_list_info {
	uint8_t	al_pa;
	uint8_t	area;
A
Andrew Vasquez 已提交
2994
	uint8_t	domain;
L
Linus Torvalds 已提交
2995 2996
	uint8_t	loop_id_2100;	/* ISP2100/ISP2200 -- 4 bytes. */
	uint16_t loop_id;	/* ISP23XX         -- 6 bytes. */
2997
	uint16_t reserved_1;	/* ISP24XX         -- 8 bytes. */
L
Linus Torvalds 已提交
2998 2999
};

3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027
/* NPIV */
typedef struct vport_info {
	uint8_t		port_name[WWN_SIZE];
	uint8_t		node_name[WWN_SIZE];
	int		vp_id;
	uint16_t	loop_id;
	unsigned long	host_no;
	uint8_t		port_id[3];
	int		loop_state;
} vport_info_t;

typedef struct vport_params {
	uint8_t 	port_name[WWN_SIZE];
	uint8_t 	node_name[WWN_SIZE];
	uint32_t 	options;
#define	VP_OPTS_RETRY_ENABLE	BIT_0
#define	VP_OPTS_VP_DISABLE	BIT_1
} vport_params_t;

/* NPIV - return codes of VP create and modify */
#define VP_RET_CODE_OK			0
#define VP_RET_CODE_FATAL		1
#define VP_RET_CODE_WRONG_ID		2
#define VP_RET_CODE_WWPN		3
#define VP_RET_CODE_RESOURCES		4
#define VP_RET_CODE_NO_MEM		5
#define VP_RET_CODE_NOT_FOUND		6

3028
struct qla_hw_data;
3029
struct rsp_que;
3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044
/*
 * ISP operations
 */
struct isp_operations {

	int (*pci_config) (struct scsi_qla_host *);
	void (*reset_chip) (struct scsi_qla_host *);
	int (*chip_diag) (struct scsi_qla_host *);
	void (*config_rings) (struct scsi_qla_host *);
	void (*reset_adapter) (struct scsi_qla_host *);
	int (*nvram_config) (struct scsi_qla_host *);
	void (*update_fw_options) (struct scsi_qla_host *);
	int (*load_risc) (struct scsi_qla_host *, uint32_t *);

	char * (*pci_info_str) (struct scsi_qla_host *, char *);
3045
	char * (*fw_version_str)(struct scsi_qla_host *, char *, size_t);
3046

3047
	irq_handler_t intr_handler;
3048 3049
	void (*enable_intrs) (struct qla_hw_data *);
	void (*disable_intrs) (struct qla_hw_data *);
3050

3051
	int (*abort_command) (srb_t *);
H
Hannes Reinecke 已提交
3052 3053
	int (*target_reset) (struct fc_port *, uint64_t, int);
	int (*lun_reset) (struct fc_port *, uint64_t, int);
3054 3055
	int (*fabric_login) (struct scsi_qla_host *, uint16_t, uint8_t,
		uint8_t, uint8_t, uint16_t *, uint8_t);
3056 3057
	int (*fabric_logout) (struct scsi_qla_host *, uint16_t, uint8_t,
	    uint8_t, uint8_t);
3058 3059 3060

	uint16_t (*calc_req_entries) (uint16_t);
	void (*build_iocbs) (srb_t *, cmd_entry_t *, uint16_t);
3061 3062
	void *(*prep_ms_iocb) (struct scsi_qla_host *, struct ct_arg *);
	void *(*prep_ms_fdmi_iocb) (struct scsi_qla_host *, uint32_t,
3063
	    uint32_t);
3064

3065
	uint8_t *(*read_nvram) (struct scsi_qla_host *, uint8_t *,
3066 3067 3068 3069 3070
		uint32_t, uint32_t);
	int (*write_nvram) (struct scsi_qla_host *, uint8_t *, uint32_t,
		uint32_t);

	void (*fw_dump) (struct scsi_qla_host *, int);
3071 3072 3073 3074

	int (*beacon_on) (struct scsi_qla_host *);
	int (*beacon_off) (struct scsi_qla_host *);
	void (*beacon_blink) (struct scsi_qla_host *);
3075 3076 3077 3078 3079

	uint8_t * (*read_optrom) (struct scsi_qla_host *, uint8_t *,
		uint32_t, uint32_t);
	int (*write_optrom) (struct scsi_qla_host *, uint8_t *, uint32_t,
		uint32_t);
3080 3081

	int (*get_flash_version) (struct scsi_qla_host *, void *);
3082
	int (*start_scsi) (srb_t *);
3083
	int (*start_scsi_mq) (srb_t *);
3084
	int (*abort_isp) (struct scsi_qla_host *);
3085
	int (*iospace_config)(struct qla_hw_data*);
3086
	int (*initialize_adapter)(struct scsi_qla_host *);
3087 3088
};

3089 3090 3091 3092 3093 3094
/* MSI-X Support *************************************************************/

#define QLA_MSIX_CHIP_REV_24XX	3
#define QLA_MSIX_FW_MODE(m)	(((m) & (BIT_7|BIT_8|BIT_9)) >> 7)
#define QLA_MSIX_FW_MODE_1(m)	(QLA_MSIX_FW_MODE(m) == 1)

3095
#define QLA_BASE_VECTORS	2 /* default + RSP */
3096
#define QLA_MSIX_RSP_Q			0x01
3097 3098
#define QLA_ATIO_VECTOR		0x02
#define QLA_MSIX_QPAIR_MULTIQ_RSP_Q	0x03
3099 3100 3101

#define QLA_MIDX_DEFAULT	0
#define QLA_MIDX_RSP_Q		1
3102
#define QLA_PCI_MSIX_CONTROL	0xa2
3103
#define QLA_83XX_PCI_MSIX_CONTROL	0x92
3104 3105 3106

struct scsi_qla_host;

3107 3108 3109

#define QLA83XX_RSPQ_MSIX_ENTRY_NUMBER 1 /* refer to qla83xx_msix_entries */

3110 3111
struct qla_msix_entry {
	int have_irq;
3112
	int in_use;
3113 3114
	uint32_t vector;
	uint16_t entry;
3115
	char name[30];
3116
	void *handle;
3117
	int cpuid;
3118 3119
};

3120 3121
#define	WATCH_INTERVAL		1       /* number of seconds */

3122 3123 3124
/* Work events.  */
enum qla_work_type {
	QLA_EVT_AEN,
3125
	QLA_EVT_IDC_ACK,
3126 3127 3128
	QLA_EVT_ASYNC_LOGIN,
	QLA_EVT_ASYNC_LOGOUT,
	QLA_EVT_ASYNC_LOGOUT_DONE,
3129 3130
	QLA_EVT_ASYNC_ADISC,
	QLA_EVT_ASYNC_ADISC_DONE,
3131
	QLA_EVT_UEVENT,
3132
	QLA_EVT_AENFX,
3133 3134 3135 3136 3137
	QLA_EVT_GIDPN,
	QLA_EVT_GPNID,
	QLA_EVT_GPNID_DONE,
	QLA_EVT_NEW_SESS,
	QLA_EVT_GPDB,
3138
	QLA_EVT_PRLI,
3139 3140 3141 3142
	QLA_EVT_GPSC,
	QLA_EVT_UPD_FCPORT,
	QLA_EVT_GNL,
	QLA_EVT_NACK,
3143
	QLA_EVT_RELOGIN,
3144 3145
	QLA_EVT_ASYNC_PRLO,
	QLA_EVT_ASYNC_PRLO_DONE,
3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159
};


struct qla_work_evt {
	struct list_head	list;
	enum qla_work_type	type;
	u32			flags;
#define QLA_EVT_FLAG_FREE	0x1

	union {
		struct {
			enum fc_host_event_code code;
			u32 data;
		} aen;
3160 3161 3162 3163
		struct {
#define QLA_IDC_ACK_REGS	7
			uint16_t mb[QLA_IDC_ACK_REGS];
		} idc_ack;
3164 3165 3166 3167 3168
		struct {
			struct fc_port *fcport;
#define QLA_LOGIO_LOGIN_RETRIED	BIT_0
			u16 data[2];
		} logio;
3169 3170 3171 3172
		struct {
			u32 code;
#define QLA_UEVENT_CODE_FW_DUMP	0
		} uevent;
3173 3174 3175 3176 3177 3178 3179 3180
		struct {
			uint32_t        evtcode;
			uint32_t        mbx[8];
			uint32_t        count;
		} aenfx;
		struct {
			srb_t *sp;
		} iosb;
3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197
		struct {
			port_id_t id;
		} gpnid;
		struct {
			port_id_t id;
			u8 port_name[8];
			void *pla;
		} new_sess;
		struct { /*Get PDB, Get Speed, update fcport, gnl, gidpn */
			fc_port_t *fcport;
			u8 opt;
		} fcport;
		struct {
			fc_port_t *fcport;
			u8 iocb[IOCB_SIZE];
			int type;
		} nack;
3198
	 } u;
3199 3200
};

3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215
struct qla_chip_state_84xx {
	struct list_head list;
	struct kref kref;

	void *bus;
	spinlock_t access_lock;
	struct mutex fw_update_mutex;
	uint32_t fw_update;
	uint32_t op_fw_version;
	uint32_t op_fw_size;
	uint32_t op_fw_seq_size;
	uint32_t diag_fw_version;
	uint32_t gold_fw_version;
};

3216 3217 3218 3219 3220 3221 3222 3223 3224 3225
struct qla_dif_statistics {
	uint64_t dif_input_bytes;
	uint64_t dif_output_bytes;
	uint64_t dif_input_requests;
	uint64_t dif_output_requests;
	uint32_t dif_guard_err;
	uint32_t dif_ref_tag_err;
	uint32_t dif_app_tag_err;
};

3226 3227
struct qla_statistics {
	uint32_t total_isp_aborts;
3228 3229
	uint64_t input_bytes;
	uint64_t output_bytes;
3230 3231 3232 3233 3234
	uint64_t input_requests;
	uint64_t output_requests;
	uint32_t control_requests;

	uint64_t jiffies_at_last_reset;
3235 3236 3237
	uint32_t stat_max_pend_cmds;
	uint32_t stat_max_qfull_cmds_alloc;
	uint32_t stat_max_qfull_cmds_dropped;
3238 3239

	struct qla_dif_statistics qla_dif_stats;
3240 3241
};

3242 3243 3244 3245 3246
struct bidi_statistics {
	unsigned long long io_count;
	unsigned long long transfer_bytes;
};

3247 3248 3249 3250 3251 3252 3253 3254 3255 3256
struct qla_tc_param {
	struct scsi_qla_host *vha;
	uint32_t blk_sz;
	uint32_t bufflen;
	struct scatterlist *sg;
	struct scatterlist *prot_sg;
	struct crc_context *ctx;
	uint8_t *ctx_dsd_alloced;
};

3257 3258 3259 3260 3261 3262
/* Multi queue support */
#define MBC_INITIALIZE_MULTIQ 0x1f
#define QLA_QUE_PAGE 0X1000
#define QLA_MQ_SIZE 32
#define QLA_MAX_QUEUES 256
#define ISP_QUE_REG(ha, id) \
3263
	((ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) ? \
3264 3265
	 ((void __iomem *)ha->mqiobase + (QLA_QUE_PAGE * id)) :\
	 ((void __iomem *)ha->iobase))
3266 3267 3268 3269 3270 3271
#define QLA_REQ_QUE_ID(tag) \
	((tag < QLA_MAX_QUEUES && tag > 0) ? tag : 0)
#define QLA_DEFAULT_QUE_QOS 5
#define QLA_PRECONFIG_VPORTS 32
#define QLA_MAX_VPORTS_QLA24XX	128
#define QLA_MAX_VPORTS_QLA25XX	256
3272

3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284
struct qla_tgt_counters {
	uint64_t qla_core_sbt_cmd;
	uint64_t core_qla_que_buf;
	uint64_t qla_core_ret_ctio;
	uint64_t core_qla_snd_status;
	uint64_t qla_core_ret_sta_ctio;
	uint64_t core_qla_free_cmd;
	uint64_t num_q_full_sent;
	uint64_t num_alloc_iocb_failed;
	uint64_t num_term_xchg_sent;
};

3285 3286
struct qla_qpair;

3287 3288 3289 3290 3291
/* Response queue data structure */
struct rsp_que {
	dma_addr_t  dma;
	response_t *ring;
	response_t *ring_ptr;
3292 3293
	uint32_t __iomem *rsp_q_in;	/* FWI2-capable only. */
	uint32_t __iomem *rsp_q_out;
3294 3295
	uint16_t  ring_index;
	uint16_t  out_ptr;
3296
	uint16_t  *in_ptr;		/* queue shadow in index */
3297 3298 3299
	uint16_t  length;
	uint16_t  options;
	uint16_t  rid;
3300 3301
	uint16_t  id;
	uint16_t  vp_idx;
3302
	struct qla_hw_data *hw;
3303 3304
	struct qla_msix_entry *msix;
	struct req_que *req;
3305
	srb_t *status_srb; /* status continuation entry */
3306
	struct qla_qpair *qpair;
3307 3308 3309 3310 3311

	dma_addr_t  dma_fx00;
	response_t *ring_fx00;
	uint16_t  length_fx00;
	uint8_t rsp_pkt[REQUEST_ENTRY_SIZE];
3312
};
L
Linus Torvalds 已提交
3313

3314 3315 3316 3317 3318
/* Request queue data structure */
struct req_que {
	dma_addr_t  dma;
	request_t *ring;
	request_t *ring_ptr;
3319 3320
	uint32_t __iomem *req_q_in;	/* FWI2-capable only. */
	uint32_t __iomem *req_q_out;
3321 3322
	uint16_t  ring_index;
	uint16_t  in_ptr;
3323
	uint16_t  *out_ptr;		/* queue shadow out index */
3324 3325 3326 3327
	uint16_t  cnt;
	uint16_t  length;
	uint16_t  options;
	uint16_t  rid;
3328
	uint16_t  id;
3329 3330
	uint16_t  qos;
	uint16_t  vp_idx;
3331
	struct rsp_que *rsp;
3332
	srb_t **outstanding_cmds;
3333
	uint32_t current_outstanding_cmd;
3334
	uint16_t num_outstanding_cmds;
3335
	int max_q_depth;
3336 3337 3338 3339 3340

	dma_addr_t  dma_fx00;
	request_t *ring_fx00;
	uint16_t  length_fx00;
	uint8_t req_pkt[REQUEST_ENTRY_SIZE];
3341
};
L
Linus Torvalds 已提交
3342

3343 3344 3345 3346
/*Queue pair data structure */
struct qla_qpair {
	spinlock_t qp_lock;
	atomic_t ref_count;
3347
	uint32_t lun_cnt;
3348 3349 3350 3351 3352 3353
	/*
	 * For qpair 0, qp_lock_ptr will point at hardware_lock due to
	 * legacy code. For other Qpair(s), it will point at qp_lock.
	 */
	spinlock_t *qp_lock_ptr;
	struct scsi_qla_host *vha;
3354
	u32 chip_reset;
3355

3356 3357 3358 3359 3360 3361 3362 3363 3364
	/* distill these fields down to 'online=0/1'
	 * ha->flags.eeh_busy
	 * ha->flags.pci_channel_io_perm_failure
	 * base_vha->loop_state
	 */
	uint32_t online:1;
	/* move vha->flags.difdix_supported here */
	uint32_t difdix_supported:1;
	uint32_t delete_in_progress:1;
3365
	uint32_t fw_started:1;
3366 3367
	uint32_t enable_class_2:1;
	uint32_t enable_explicit_conf:1;
3368
	uint32_t use_shadow_reg:1;
3369 3370 3371 3372 3373

	uint16_t id;			/* qp number used with FW */
	uint16_t vp_idx;		/* vport ID */
	mempool_t *srb_mempool;

3374 3375 3376
	struct pci_dev  *pdev;
	void (*reqq_start_iocbs)(struct qla_qpair *);

3377 3378 3379 3380 3381 3382 3383 3384
	/* to do: New driver: move queues to here instead of pointers */
	struct req_que *req;
	struct rsp_que *rsp;
	struct atio_que *atio;
	struct qla_msix_entry *msix; /* point to &ha->msix_entries[x] */
	struct qla_hw_data *hw;
	struct work_struct q_work;
	struct list_head qp_list_elem; /* vha->qp_list */
3385
	struct list_head hints_list;
3386
	struct list_head nvme_done_list;
3387
	uint16_t cpuid;
3388
	struct qla_tgt_counters tgt_counters;
3389 3390
};

3391 3392 3393 3394 3395 3396 3397
/* Place holder for FW buffer parameters */
struct qlfc_fw {
	void *fw_buf;
	dma_addr_t fw_dma;
	uint32_t len;
};

3398 3399 3400 3401 3402 3403 3404
struct scsi_qlt_host {
	void *target_lport_ptr;
	struct mutex tgt_mutex;
	struct mutex tgt_host_action_mutex;
	struct qla_tgt *qla_tgt;
};

3405 3406 3407 3408 3409 3410 3411 3412 3413
struct qlt_hw_data {
	/* Protected by hw lock */
	uint32_t node_name_set:1;

	dma_addr_t atio_dma;	/* Physical address. */
	struct atio *atio_ring;	/* Base virtual address */
	struct atio *atio_ring_ptr;	/* Current address. */
	uint16_t atio_ring_index; /* Current index. */
	uint16_t atio_q_length;
3414 3415
	uint32_t __iomem *atio_q_in;
	uint32_t __iomem *atio_q_out;
3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428

	struct qla_tgt_func_tmpl *tgt_ops;
	struct qla_tgt_vp_map *tgt_vp_map;

	int saved_set;
	uint16_t saved_exchange_count;
	uint32_t saved_firmware_options_1;
	uint32_t saved_firmware_options_2;
	uint32_t saved_firmware_options_3;
	uint8_t saved_firmware_options[2];
	uint8_t saved_add_firmware_options[2];

	uint8_t tgt_node_name[WWN_SIZE];
3429

3430
	struct dentry *dfs_tgt_sess;
3431
	struct dentry *dfs_tgt_port_database;
3432
	struct dentry *dfs_naqp;
3433

3434 3435 3436 3437 3438 3439
	struct list_head q_full_list;
	uint32_t num_pend_cmds;
	uint32_t num_qfull_cmds_alloc;
	uint32_t num_qfull_cmds_dropped;
	spinlock_t q_full_lock;
	uint32_t leak_exchg_thresh_hold;
3440
	spinlock_t sess_lock;
3441 3442
	int num_act_qpairs;
#define DEFAULT_NAQP 2
3443
	spinlock_t atio_lock ____cacheline_aligned;
3444
	struct btree_head32 host_map;
3445 3446
};

3447 3448 3449
#define MAX_QFULL_CMDS_ALLOC	8192
#define Q_FULL_THRESH_HOLD_PERCENT 90
#define Q_FULL_THRESH_HOLD(ha) \
3450
	((ha->cur_fw_xcb_count/100) * Q_FULL_THRESH_HOLD_PERCENT)
3451 3452 3453

#define LEAK_EXCHG_THRESH_HOLD_PERCENT 75	/* 75 percent */

3454 3455 3456 3457 3458 3459 3460 3461
/*
 * Qlogic host adapter specific data structure.
*/
struct qla_hw_data {
	struct pci_dev  *pdev;
	/* SRB cache. */
#define SRB_MIN_REQ     128
	mempool_t       *srb_mempool;
L
Linus Torvalds 已提交
3462 3463 3464 3465 3466 3467 3468 3469

	volatile struct {
		uint32_t	mbox_int		:1;
		uint32_t	mbox_busy		:1;
		uint32_t	disable_risc_code_load	:1;
		uint32_t	enable_64bit_addressing	:1;
		uint32_t	enable_lip_reset	:1;
		uint32_t	enable_target_reset	:1;
3470
		uint32_t	enable_lip_full_login	:1;
L
Linus Torvalds 已提交
3471
		uint32_t	enable_led_scheme	:1;
3472

3473 3474
		uint32_t	msi_enabled		:1;
		uint32_t	msix_enabled		:1;
3475
		uint32_t	disable_serdes		:1;
3476
		uint32_t	gpsc_supported		:1;
3477
		uint32_t	npiv_supported		:1;
3478
		uint32_t	pci_channel_io_perm_failure	:1;
3479
		uint32_t	fce_enabled		:1;
3480
		uint32_t	fac_supported		:1;
3481

3482
		uint32_t	chip_reset_done		:1;
3483
		uint32_t	running_gold_fw		:1;
3484
		uint32_t	eeh_busy		:1;
3485
		uint32_t	disable_msix_handshake	:1;
S
Sarang Radke 已提交
3486
		uint32_t	fcp_prio_enabled	:1;
3487
		uint32_t	isp82xx_fw_hung:1;
3488
		uint32_t	nic_core_hung:1;
3489 3490

		uint32_t	quiesce_owner:1;
3491 3492
		uint32_t	nic_core_reset_hdlr_active:1;
		uint32_t	nic_core_reset_owner:1;
3493
		uint32_t	isp82xx_no_md_cap:1;
3494
		uint32_t	host_shutting_down:1;
3495
		uint32_t	idc_compl_status:1;
3496 3497
		uint32_t        mr_reset_hdlr_active:1;
		uint32_t        mr_intr_valid:1;
3498

3499
		uint32_t        dport_enabled:1;
3500
		uint32_t	fawwpn_enabled:1;
3501
		uint32_t	exlogins_enabled:1;
3502
		uint32_t	exchoffld_enabled:1;
3503

3504 3505
		uint32_t	lip_ae:1;
		uint32_t	n2n_ae:1;
3506
		uint32_t	fw_started:1;
3507
		uint32_t	fw_init_done:1;
3508 3509 3510

		uint32_t	detected_lr_sfp:1;
		uint32_t	using_lr_setting:1;
L
Linus Torvalds 已提交
3511 3512
	} flags;

3513
	uint16_t max_exchg;
3514
	uint16_t long_range_distance;	/* 32G & above */
3515 3516 3517
#define LR_DISTANCE_5K  1
#define LR_DISTANCE_10K 0

A
Andrew Vasquez 已提交
3518
	/* This spinlock is used to protect "io transactions", you must
3519 3520 3521 3522 3523
	* acquire it before doing any IO to the card, eg with RD_REG*() and
	* WRT_REG*() for the duration of your entire commandtransaction.
	*
	* This spinlock is of lower priority than the io request lock.
	*/
L
Linus Torvalds 已提交
3524

3525
	spinlock_t	hardware_lock ____cacheline_aligned;
3526
	int		bars;
3527
	int		mem_only;
3528
	device_reg_t *iobase;           /* Base I/O address */
3529
	resource_size_t pio_address;
A
Andrew Vasquez 已提交
3530

3531
#define MIN_IOBASE_LEN          0x100
3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546
	dma_addr_t		bar0_hdl;

	void __iomem *cregbase;
	dma_addr_t		bar2_hdl;
#define BAR0_LEN_FX00			(1024 * 1024)
#define BAR2_LEN_FX00			(128 * 1024)

	uint32_t		rqstq_intr_code;
	uint32_t		mbx_intr_code;
	uint32_t		req_que_len;
	uint32_t		rsp_que_len;
	uint32_t		req_que_off;
	uint32_t		rsp_que_off;

	/* Multi queue data structs */
3547 3548
	device_reg_t *mqiobase;
	device_reg_t *msixbase;
3549 3550 3551 3552
	uint16_t        msix_count;
	uint8_t         mqenable;
	struct req_que **req_q_map;
	struct rsp_que **rsp_q_map;
3553
	struct qla_qpair **queue_pair_map;
3554 3555
	unsigned long req_qid_map[(QLA_MAX_QUEUES / 8) / sizeof(unsigned long)];
	unsigned long rsp_qid_map[(QLA_MAX_QUEUES / 8) / sizeof(unsigned long)];
3556 3557
	unsigned long qpair_qid_map[(QLA_MAX_QUEUES / 8)
		/ sizeof(unsigned long)];
3558 3559
	uint8_t 	max_req_queues;
	uint8_t 	max_rsp_queues;
3560
	uint8_t		max_qpairs;
3561
	uint8_t		num_qpairs;
3562
	struct qla_qpair *base_qpair;
3563 3564
	struct qla_npiv_entry *npiv_info;
	uint16_t	nvram_npiv_size;
L
Linus Torvalds 已提交
3565

3566 3567 3568 3569 3570
	uint16_t        switch_cap;
#define FLOGI_SEQ_DEL           BIT_8
#define FLOGI_MID_SUPPORT       BIT_10
#define FLOGI_VSAN_SUPPORT      BIT_12
#define FLOGI_SP_SUPPORT        BIT_13
3571 3572

	uint8_t		port_no;		/* Physical port of adapter */
3573
	uint8_t		exch_starvation;
3574

3575 3576 3577 3578 3579
	/* Timeout timers. */
	uint8_t 	loop_down_abort_time;    /* port down timer */
	atomic_t	loop_down_timer;         /* loop down timer */
	uint8_t		link_down_timeout;       /* link down timeout */
	uint16_t	max_loop_id;
3580
	uint16_t	max_fibre_devices;	/* Maximum number of targets */
L
Linus Torvalds 已提交
3581 3582

	uint16_t	fb_rev;
3583
	uint16_t	min_external_loopid;    /* First external loop Id */
L
Linus Torvalds 已提交
3584

3585
#define PORT_SPEED_UNKNOWN 0xFFFF
3586 3587 3588 3589
#define PORT_SPEED_1GB  0x00
#define PORT_SPEED_2GB  0x01
#define PORT_SPEED_4GB  0x03
#define PORT_SPEED_8GB  0x04
3590
#define PORT_SPEED_16GB 0x05
3591
#define PORT_SPEED_32GB 0x06
3592
#define PORT_SPEED_10GB	0x13
3593
	uint16_t	link_data_rate;         /* F/W operating speed */
L
Linus Torvalds 已提交
3594 3595 3596 3597 3598 3599 3600 3601

	uint8_t		current_topology;
	uint8_t		prev_topology;
#define ISP_CFG_NL	1
#define ISP_CFG_N	2
#define ISP_CFG_FL	4
#define ISP_CFG_F	8

3602
	uint8_t		operating_mode;         /* F/W operating mode */
L
Linus Torvalds 已提交
3603 3604 3605 3606 3607
#define LOOP      0
#define P2P       1
#define LOOP_P2P  2
#define P2P_LOOP  3
	uint8_t		interrupts_on;
3608 3609 3610
	uint32_t	isp_abort_cnt;
#define PCI_DEVICE_ID_QLOGIC_ISP2532    0x2532
#define PCI_DEVICE_ID_QLOGIC_ISP8432    0x8432
3611
#define PCI_DEVICE_ID_QLOGIC_ISP8001	0x8001
3612 3613
#define PCI_DEVICE_ID_QLOGIC_ISP8031	0x8031
#define PCI_DEVICE_ID_QLOGIC_ISP2031	0x2031
3614
#define PCI_DEVICE_ID_QLOGIC_ISP2071	0x2071
3615
#define PCI_DEVICE_ID_QLOGIC_ISP2271	0x2271
3616
#define PCI_DEVICE_ID_QLOGIC_ISP2261	0x2261
3617

3618
	uint32_t	isp_type;
3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631
#define DT_ISP2100                      BIT_0
#define DT_ISP2200                      BIT_1
#define DT_ISP2300                      BIT_2
#define DT_ISP2312                      BIT_3
#define DT_ISP2322                      BIT_4
#define DT_ISP6312                      BIT_5
#define DT_ISP6322                      BIT_6
#define DT_ISP2422                      BIT_7
#define DT_ISP2432                      BIT_8
#define DT_ISP5422                      BIT_9
#define DT_ISP5432                      BIT_10
#define DT_ISP2532                      BIT_11
#define DT_ISP8432                      BIT_12
3632
#define DT_ISP8001			BIT_13
3633
#define DT_ISP8021			BIT_14
3634 3635
#define DT_ISP2031			BIT_15
#define DT_ISP8031			BIT_16
3636
#define DT_ISPFX00			BIT_17
3637
#define DT_ISP8044			BIT_18
3638
#define DT_ISP2071			BIT_19
3639
#define DT_ISP2271			BIT_20
3640 3641
#define DT_ISP2261			BIT_21
#define DT_ISP_LAST			(DT_ISP2261 << 1)
3642

3643
	uint32_t	device_type;
3644
#define DT_T10_PI                       BIT_25
3645 3646 3647 3648 3649 3650
#define DT_IIDMA                        BIT_26
#define DT_FWI2                         BIT_27
#define DT_ZIO_SUPPORTED                BIT_28
#define DT_OEM_001                      BIT_29
#define DT_ISP2200A                     BIT_30
#define DT_EXTENDED_IDS                 BIT_31
3651 3652

#define DT_MASK(ha)     ((ha)->isp_type & (DT_ISP_LAST - 1))
3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665
#define IS_QLA2100(ha)  (DT_MASK(ha) & DT_ISP2100)
#define IS_QLA2200(ha)  (DT_MASK(ha) & DT_ISP2200)
#define IS_QLA2300(ha)  (DT_MASK(ha) & DT_ISP2300)
#define IS_QLA2312(ha)  (DT_MASK(ha) & DT_ISP2312)
#define IS_QLA2322(ha)  (DT_MASK(ha) & DT_ISP2322)
#define IS_QLA6312(ha)  (DT_MASK(ha) & DT_ISP6312)
#define IS_QLA6322(ha)  (DT_MASK(ha) & DT_ISP6322)
#define IS_QLA2422(ha)  (DT_MASK(ha) & DT_ISP2422)
#define IS_QLA2432(ha)  (DT_MASK(ha) & DT_ISP2432)
#define IS_QLA5422(ha)  (DT_MASK(ha) & DT_ISP5422)
#define IS_QLA5432(ha)  (DT_MASK(ha) & DT_ISP5432)
#define IS_QLA2532(ha)  (DT_MASK(ha) & DT_ISP2532)
#define IS_QLA8432(ha)  (DT_MASK(ha) & DT_ISP8432)
3666
#define IS_QLA8001(ha)	(DT_MASK(ha) & DT_ISP8001)
3667
#define IS_QLA81XX(ha)	(IS_QLA8001(ha))
3668
#define IS_QLA82XX(ha)	(DT_MASK(ha) & DT_ISP8021)
3669
#define IS_QLA8044(ha)  (DT_MASK(ha) & DT_ISP8044)
3670 3671
#define IS_QLA2031(ha)	(DT_MASK(ha) & DT_ISP2031)
#define IS_QLA8031(ha)	(DT_MASK(ha) & DT_ISP8031)
3672
#define IS_QLAFX00(ha)	(DT_MASK(ha) & DT_ISPFX00)
3673
#define IS_QLA2071(ha)	(DT_MASK(ha) & DT_ISP2071)
3674
#define IS_QLA2271(ha)	(DT_MASK(ha) & DT_ISP2271)
3675
#define IS_QLA2261(ha)	(DT_MASK(ha) & DT_ISP2261)
3676 3677 3678 3679 3680 3681

#define IS_QLA23XX(ha)  (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA2322(ha) || \
			IS_QLA6312(ha) || IS_QLA6322(ha))
#define IS_QLA24XX(ha)  (IS_QLA2422(ha) || IS_QLA2432(ha))
#define IS_QLA54XX(ha)  (IS_QLA5422(ha) || IS_QLA5432(ha))
#define IS_QLA25XX(ha)  (IS_QLA2532(ha))
3682
#define IS_QLA83XX(ha)	(IS_QLA2031(ha) || IS_QLA8031(ha))
3683
#define IS_QLA84XX(ha)  (IS_QLA8432(ha))
3684
#define IS_QLA27XX(ha)  (IS_QLA2071(ha) || IS_QLA2271(ha) || IS_QLA2261(ha))
3685 3686
#define IS_QLA24XX_TYPE(ha)     (IS_QLA24XX(ha) || IS_QLA54XX(ha) || \
				IS_QLA84XX(ha))
3687
#define IS_CNA_CAPABLE(ha)	(IS_QLA81XX(ha) || IS_QLA82XX(ha) || \
3688 3689
				IS_QLA8031(ha) || IS_QLA8044(ha))
#define IS_P3P_TYPE(ha)		(IS_QLA82XX(ha) || IS_QLA8044(ha))
3690
#define IS_QLA2XXX_MIDTYPE(ha)	(IS_QLA24XX(ha) || IS_QLA84XX(ha) || \
3691
				IS_QLA25XX(ha) || IS_QLA81XX(ha) || \
3692
				IS_QLA82XX(ha) || IS_QLA83XX(ha) || \
3693
				IS_QLA8044(ha) || IS_QLA27XX(ha))
3694 3695
#define IS_MSIX_NACK_CAPABLE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha) || \
				IS_QLA27XX(ha))
3696
#define IS_NOPOLLING_TYPE(ha)	(IS_QLA81XX(ha) && (ha)->flags.msix_enabled)
3697 3698 3699 3700
#define IS_FAC_REQUIRED(ha)	(IS_QLA81XX(ha) || IS_QLA83XX(ha) || \
				IS_QLA27XX(ha))
#define IS_NOCACHE_VPD_TYPE(ha)	(IS_QLA81XX(ha) || IS_QLA83XX(ha) || \
				IS_QLA27XX(ha))
3701
#define IS_ALOGIO_CAPABLE(ha)	(IS_QLA23XX(ha) || IS_FWI2_CAPABLE(ha))
3702

3703
#define IS_T10_PI_CAPABLE(ha)   ((ha)->device_type & DT_T10_PI)
3704 3705 3706 3707 3708
#define IS_IIDMA_CAPABLE(ha)    ((ha)->device_type & DT_IIDMA)
#define IS_FWI2_CAPABLE(ha)     ((ha)->device_type & DT_FWI2)
#define IS_ZIO_SUPPORTED(ha)    ((ha)->device_type & DT_ZIO_SUPPORTED)
#define IS_OEM_001(ha)          ((ha)->device_type & DT_OEM_001)
#define HAS_EXTENDED_IDS(ha)    ((ha)->device_type & DT_EXTENDED_IDS)
3709
#define IS_CT6_SUPPORTED(ha)	((ha)->device_type & DT_CT6_SUPPORTED)
3710 3711
#define IS_MQUE_CAPABLE(ha)	((ha)->mqenable || IS_QLA83XX(ha) || \
				IS_QLA27XX(ha))
3712
#define IS_BIDI_CAPABLE(ha)	((IS_QLA25XX(ha) || IS_QLA2031(ha)))
3713 3714 3715
/* Bit 21 of fw_attributes decides the MCTP capabilities */
#define IS_MCTP_CAPABLE(ha)	(IS_QLA2031(ha) && \
				((ha)->fw_attributes_ext[0] & BIT_0))
3716 3717
#define IS_PI_UNINIT_CAPABLE(ha)	(IS_QLA83XX(ha) || IS_QLA27XX(ha))
#define IS_PI_IPGUARD_CAPABLE(ha)	(IS_QLA83XX(ha) || IS_QLA27XX(ha))
3718
#define IS_PI_DIFB_DIX0_CAPABLE(ha)	(0)
3719
#define IS_PI_SPLIT_DET_CAPABLE_HBA(ha)	(IS_QLA83XX(ha) || IS_QLA27XX(ha))
3720 3721
#define IS_PI_SPLIT_DET_CAPABLE(ha)	(IS_PI_SPLIT_DET_CAPABLE_HBA(ha) && \
    (((ha)->fw_attributes_h << 16 | (ha)->fw_attributes) & BIT_22))
3722
#define IS_ATIO_MSIX_CAPABLE(ha) (IS_QLA83XX(ha) || IS_QLA27XX(ha))
3723
#define IS_TGT_MODE_CAPABLE(ha)	(ha->tgt.atio_q_length)
3724
#define IS_SHADOW_REG_CAPABLE(ha)  (IS_QLA27XX(ha))
3725
#define IS_DPORT_CAPABLE(ha)  (IS_QLA83XX(ha) || IS_QLA27XX(ha))
3726
#define IS_FAWWN_CAPABLE(ha)	(IS_QLA83XX(ha) || IS_QLA27XX(ha))
3727 3728 3729 3730
#define IS_EXCHG_OFFLD_CAPABLE(ha) \
	(IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
#define IS_EXLOGIN_OFFLD_CAPABLE(ha) \
	(IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
L
Linus Torvalds 已提交
3731 3732 3733 3734 3735 3736 3737

	/* HBA serial number */
	uint8_t		serial0;
	uint8_t		serial1;
	uint8_t		serial2;

	/* NVRAM configuration data */
3738 3739
#define MAX_NVRAM_SIZE  4096
#define VPD_OFFSET      MAX_NVRAM_SIZE / 2
3740
	uint16_t	nvram_size;
L
Linus Torvalds 已提交
3741
	uint16_t	nvram_base;
3742
	void		*nvram;
3743 3744
	uint16_t	vpd_size;
	uint16_t	vpd_base;
3745
	void		*vpd;
L
Linus Torvalds 已提交
3746 3747 3748 3749 3750 3751 3752

	uint16_t	loop_reset_delay;
	uint8_t		retry_count;
	uint8_t		login_timeout;
	uint16_t	r_a_tov;
	int		port_down_retry_count;
	uint8_t		mbx_count;
3753
	uint8_t		aen_mbx_count;
L
Linus Torvalds 已提交
3754

3755
	uint32_t	login_retry_count;
L
Linus Torvalds 已提交
3756 3757 3758 3759 3760 3761 3762 3763 3764
	/* SNS command interfaces. */
	ms_iocb_entry_t		*ms_iocb;
	dma_addr_t		ms_iocb_dma;
	struct ct_sns_pkt	*ct_sns;
	dma_addr_t		ct_sns_dma;
	/* SNS command interfaces for 2200. */
	struct sns_cmd_pkt	*sns_cmd;
	dma_addr_t		sns_cmd_dma;

3765
#define SFP_DEV_SIZE    512
3766 3767 3768
#define SFP_BLOCK_SIZE  64
	void		*sfp_data;
	dma_addr_t	sfp_data_dma;
3769

3770
#define XGMAC_DATA_SIZE	4096
3771 3772 3773
	void		*xgmac_data;
	dma_addr_t	xgmac_data_dma;

3774
#define DCBX_TLV_DATA_SIZE 4096
3775 3776 3777
	void		*dcbx_tlv;
	dma_addr_t	dcbx_tlv_dma;

3778
	struct task_struct	*dpc_thread;
L
Linus Torvalds 已提交
3779 3780 3781 3782
	uint8_t dpc_active;                  /* DPC routine is active */

	dma_addr_t	gid_list_dma;
	struct gid_list_info *gid_list;
3783
	int		gid_list_info_size;
L
Linus Torvalds 已提交
3784

A
Andrew Vasquez 已提交
3785
	/* Small DMA pool allocations -- maximum 256 bytes in length. */
3786
#define DMA_POOL_SIZE   256
L
Linus Torvalds 已提交
3787 3788 3789
	struct dma_pool *s_dma_pool;

	dma_addr_t	init_cb_dma;
3790 3791
	init_cb_t	*init_cb;
	int		init_cb_size;
3792 3793
	dma_addr_t	ex_init_cb_dma;
	struct ex_init_cb_81xx *ex_init_cb;
L
Linus Torvalds 已提交
3794

3795 3796 3797
	void		*async_pd;
	dma_addr_t	async_pd_dma;

3798 3799 3800 3801 3802 3803 3804
#define ENABLE_EXTENDED_LOGIN	BIT_7

	/* Extended Logins  */
	void		*exlogin_buf;
	dma_addr_t	exlogin_buf_dma;
	int		exlogin_size;

3805 3806 3807 3808 3809 3810 3811 3812
#define ENABLE_EXCHANGE_OFFLD	BIT_2

	/* Exchange Offload */
	void		*exchoffld_buf;
	dma_addr_t	exchoffld_buf_dma;
	int		exchoffld_size;
	int 		exchoffld_count;

3813 3814
	void		*swl;

L
Linus Torvalds 已提交
3815
	/* These are used by mailbox operations. */
3816 3817 3818
	uint16_t mailbox_out[MAILBOX_REGISTER_COUNT];
	uint32_t mailbox_out32[MAILBOX_REGISTER_COUNT];
	uint32_t aenmb[AEN_MAILBOX_REGISTER_COUNT_FX00];
L
Linus Torvalds 已提交
3819 3820

	mbx_cmd_t	*mcp;
3821 3822
	struct mbx_cmd_32	*mcp32;

L
Linus Torvalds 已提交
3823
	unsigned long	mbx_cmd_flags;
3824 3825
#define MBX_INTERRUPT		1
#define MBX_INTR_WAIT		2
L
Linus Torvalds 已提交
3826 3827
#define MBX_UPDATE_FLASH_ACTIVE	3

3828
	struct mutex vport_lock;        /* Virtual port synchronization */
3829
	spinlock_t vport_slock; /* order is hardware_lock, then vport_slock */
3830
	struct mutex mq_lock;        /* multi-queue synchronization */
3831
	struct completion mbx_cmd_comp; /* Serialize mbx access */
3832
	struct completion mbx_intr_comp;  /* Used for completion notification */
3833
	struct completion dcbx_comp;	/* For set port config notification */
3834 3835 3836 3837 3838
	struct completion lb_portup_comp; /* Used to wait for link up during
					   * loopback */
#define DCBX_COMP_TIMEOUT	20
#define LB_PORTUP_COMP_TIMEOUT	10

3839
	int notify_dcbx_comp;
3840
	int notify_lb_portup_comp;
3841
	struct mutex selflogin_lock;
L
Linus Torvalds 已提交
3842 3843 3844 3845 3846 3847

	/* Basic firmware related information. */
	uint16_t	fw_major_version;
	uint16_t	fw_minor_version;
	uint16_t	fw_subminor_version;
	uint16_t	fw_attributes;
3848 3849
	uint16_t	fw_attributes_h;
	uint16_t	fw_attributes_ext[2];
L
Linus Torvalds 已提交
3850 3851
	uint32_t	fw_memory_size;
	uint32_t	fw_transfer_size;
3852 3853 3854 3855
	uint32_t	fw_srisc_address;
#define RISC_START_ADDRESS_2100 0x1000
#define RISC_START_ADDRESS_2300 0x800
#define RISC_START_ADDRESS_2400 0x100000
3856 3857 3858 3859 3860 3861 3862 3863

	uint16_t	orig_fw_tgt_xcb_count;
	uint16_t	cur_fw_tgt_xcb_count;
	uint16_t	orig_fw_xcb_count;
	uint16_t	cur_fw_xcb_count;
	uint16_t	orig_fw_iocb_count;
	uint16_t	cur_fw_iocb_count;
	uint16_t	fw_max_fcf_count;
L
Linus Torvalds 已提交
3864

3865 3866
	uint32_t	fw_shared_ram_start;
	uint32_t	fw_shared_ram_end;
3867 3868
	uint32_t	fw_ddr_ram_start;
	uint32_t	fw_ddr_ram_end;
3869

3870
	uint16_t	fw_options[16];         /* slots: 1,2,3,10,11 */
L
Linus Torvalds 已提交
3871
	uint8_t		fw_seriallink_options[4];
3872
	uint16_t	fw_seriallink_options24[4];
L
Linus Torvalds 已提交
3873

3874
	uint8_t		mpi_version[3];
3875
	uint32_t	mpi_capabilities;
3876
	uint8_t		phy_version[3];
3877
	uint8_t		pep_version[3];
3878

3879 3880 3881
	/* Firmware dump template */
	void		*fw_dump_template;
	uint32_t	fw_dump_template_len;
L
Linus Torvalds 已提交
3882
	/* Firmware dump information. */
3883 3884
	struct qla2xxx_fw_dump *fw_dump;
	uint32_t	fw_dump_len;
3885
	int		fw_dumped;
3886 3887 3888 3889 3890 3891 3892
	unsigned long	fw_dump_cap_flags;
#define RISC_PAUSE_CMPL		0
#define DMA_SHUTDOWN_CMPL	1
#define ISP_RESET_CMPL		2
#define RISC_RDY_AFT_RESET	3
#define RISC_SRAM_DUMP_CMPL	4
#define RISC_EXT_MEM_DUMP_CMPL	5
3893 3894
#define ISP_MBX_RDY		6
#define ISP_SOFT_RESET_CMPL	7
L
Linus Torvalds 已提交
3895
	int		fw_dump_reading;
3896
	int		prev_minidump_failed;
3897 3898
	dma_addr_t	eft_dma;
	void		*eft;
3899 3900 3901 3902 3903 3904
/* Current size of mctp dump is 0x086064 bytes */
#define MCTP_DUMP_SIZE  0x086064
	dma_addr_t	mctp_dump_dma;
	void		*mctp_dump;
	int		mctp_dumped;
	int		mctp_dump_reading;
3905
	uint32_t	chain_offset;
3906 3907
	struct dentry *dfs_dir;
	struct dentry *dfs_fce;
3908
	struct dentry *dfs_tgt_counters;
3909
	struct dentry *dfs_fw_resource_cnt;
3910

3911 3912 3913 3914 3915 3916 3917
	dma_addr_t	fce_dma;
	void		*fce;
	uint32_t	fce_bufs;
	uint16_t	fce_mb[8];
	uint64_t	fce_wr, fce_rd;
	struct mutex	fce_mutex;

3918
	uint32_t	pci_attr;
3919
	uint16_t	chip_revision;
L
Linus Torvalds 已提交
3920 3921 3922 3923 3924

	uint16_t	product_id[4];

	uint8_t		model_number[16+1];
#define BINZERO		"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
3925
	char		model_desc[80];
3926
	uint8_t		adapter_id[16+1];
L
Linus Torvalds 已提交
3927

3928 3929 3930 3931 3932 3933 3934
	/* Option ROM information. */
	char		*optrom_buffer;
	uint32_t	optrom_size;
	int		optrom_state;
#define QLA_SWAITING	0
#define QLA_SREADING	1
#define QLA_SWRITING	2
3935 3936
	uint32_t	optrom_region_start;
	uint32_t	optrom_region_size;
3937
	struct mutex	optrom_mutex;
3938

3939
/* PCI expansion ROM image information. */
3940 3941 3942
#define ROM_CODE_TYPE_BIOS	0
#define ROM_CODE_TYPE_FCODE	1
#define ROM_CODE_TYPE_EFI	3
3943 3944 3945
	uint8_t 	bios_revision[2];
	uint8_t 	efi_revision[2];
	uint8_t 	fcode_revision[16];
3946 3947
	uint32_t	fw_revision[4];

3948 3949
	uint32_t	gold_fw_version[4];

3950 3951 3952 3953 3954 3955
	/* Offsets for flash/nvram access (set to ~0 if not used). */
	uint32_t	flash_conf_off;
	uint32_t	flash_data_off;
	uint32_t	nvram_conf_off;
	uint32_t	nvram_data_off;

3956
	uint32_t	fdt_wrt_disable;
3957
	uint32_t	fdt_wrt_enable;
3958 3959 3960 3961
	uint32_t	fdt_erase_cmd;
	uint32_t	fdt_block_size;
	uint32_t	fdt_unprotect_sec_cmd;
	uint32_t	fdt_protect_sec_cmd;
3962
	uint32_t	fdt_wrt_sts_reg_cmd;
3963

3964 3965 3966
	uint32_t        flt_region_flt;
	uint32_t        flt_region_fdt;
	uint32_t        flt_region_boot;
3967
	uint32_t        flt_region_boot_sec;
3968
	uint32_t        flt_region_fw;
3969
	uint32_t        flt_region_fw_sec;
3970
	uint32_t        flt_region_vpd_nvram;
3971
	uint32_t        flt_region_vpd;
3972
	uint32_t        flt_region_vpd_sec;
3973
	uint32_t        flt_region_nvram;
3974
	uint32_t        flt_region_npiv_conf;
3975
	uint32_t	flt_region_gold_fw;
S
Sarang Radke 已提交
3976
	uint32_t	flt_region_fcp_prio;
3977
	uint32_t	flt_region_bootload;
3978 3979 3980
	uint32_t	flt_region_img_status_pri;
	uint32_t	flt_region_img_status_sec;
	uint8_t         active_image;
3981

L
Linus Torvalds 已提交
3982
	/* Needed for BEACON */
3983 3984
	uint16_t        beacon_blink_led;
	uint8_t         beacon_color_state;
3985 3986 3987 3988 3989
#define QLA_LED_GRN_ON		0x01
#define QLA_LED_YLW_ON		0x02
#define QLA_LED_ABR_ON		0x04
#define QLA_LED_ALL_ON		0x07	/* yellow, green, amber. */
					/* ISP2322: red, green, amber. */
3990 3991
	uint16_t        zio_mode;
	uint16_t        zio_timer;
3992

3993
	struct qla_msix_entry *msix_entries;
3994

3995 3996 3997 3998 3999 4000 4001 4002 4003 4004
	struct list_head        vp_list;        /* list of VP */
	unsigned long   vp_idx_map[(MAX_MULTI_ID_FABRIC / 8) /
			sizeof(unsigned long)];
	uint16_t        num_vhosts;     /* number of vports created */
	uint16_t        num_vsans;      /* number of vsan created */
	uint16_t        max_npiv_vports;        /* 63 or 125 per topoloty */
	int             cur_vport_count;

	struct qla_chip_state_84xx *cs84xx;
	struct isp_operations *isp_ops;
4005
	struct workqueue_struct *wq;
4006
	struct qlfc_fw fw_buf;
S
Sarang Radke 已提交
4007 4008 4009

	/* FCP_CMND priority support */
	struct qla_fcp_prio_cfg *fcp_prio_cfg;
4010 4011 4012 4013 4014 4015 4016 4017

	struct dma_pool *dl_dma_pool;
#define DSD_LIST_DMA_POOL_SIZE  512

	struct dma_pool *fcp_cmnd_dma_pool;
	mempool_t       *ctx_mempool;
#define FCP_CMND_DMA_POOL_SIZE 512

4018 4019 4020
	void __iomem	*nx_pcibase;		/* Base I/O address */
	void __iomem	*nxdb_rd_ptr;		/* Doorbell read pointer */
	void __iomem	*nxdb_wr_ptr;		/* Door bell write pointer */
4021 4022 4023 4024 4025 4026 4027

	uint32_t	crb_win;
	uint32_t	curr_window;
	uint32_t	ddr_mn_window;
	unsigned long	mn_win_crb;
	unsigned long	ms_win_crb;
	int		qdr_sn_window;
4028 4029
	uint32_t	fcoe_dev_init_timeout;
	uint32_t	fcoe_reset_timeout;
4030 4031 4032 4033 4034 4035 4036 4037 4038 4039
	rwlock_t	hw_lock;
	uint16_t	portnum;		/* port number */
	int		link_width;
	struct fw_blob	*hablob;
	struct qla82xx_legacy_intr_set nx_legacy_intr;

	uint16_t	gbl_dsd_inuse;
	uint16_t	gbl_dsd_avail;
	struct list_head gbl_dsd_list;
#define NUM_DSD_CHAIN 4096
4040 4041 4042

	uint8_t fw_type;
	__le32 file_prd_off;	/* File firmware product offset */
4043 4044 4045 4046 4047 4048

	uint32_t	md_template_size;
	void		*md_tmplt_hdr;
	dma_addr_t      md_tmplt_hdr_dma;
	void            *md_dump;
	uint32_t	md_dump_size;
4049

4050
	void		*loop_id_map;
4051 4052 4053

	/* QLA83XX IDC specific fields */
	uint32_t	idc_audit_ts;
4054
	uint32_t	idc_extend_tmo;
4055 4056 4057 4058 4059 4060 4061 4062 4063

	/* DPC low-priority workqueue */
	struct workqueue_struct *dpc_lp_wq;
	struct work_struct idc_aen;
	/* DPC high-priority workqueue */
	struct workqueue_struct *dpc_hp_wq;
	struct work_struct nic_core_reset;
	struct work_struct idc_state_handler;
	struct work_struct nic_core_unrecoverable;
4064
	struct work_struct board_disable;
4065

4066 4067
	struct mr_data_fx00 mr;

4068
	struct qlt_hw_data tgt;
4069
	int	allow_cna_fw_dump;
4070
	uint32_t fw_ability_mask;
4071 4072
	uint16_t min_link_speed;
	uint16_t max_speed_sup;
4073 4074 4075

	atomic_t        nvme_active_aen_cnt;
	uint16_t        nvme_last_rptd_aen;             /* Last recorded aen count */
4076 4077
};

4078 4079 4080 4081 4082 4083
#define FW_ABILITY_MAX_SPEED_MASK	0xFUL
#define FW_ABILITY_MAX_SPEED_16G	0x0
#define FW_ABILITY_MAX_SPEED_32G	0x1
#define FW_ABILITY_MAX_SPEED(ha)	\
	(ha->fw_ability_mask & FW_ABILITY_MAX_SPEED_MASK)

4084 4085 4086 4087 4088 4089 4090
/*
 * Qlogic scsi host structure
 */
typedef struct scsi_qla_host {
	struct list_head list;
	struct list_head vp_fcports;	/* list of fcports */
	struct list_head work_list;
4091
	spinlock_t work_lock;
4092
	struct work_struct iocb_work;
4093

4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105
	/* Commonly used flags and state information. */
	struct Scsi_Host *host;
	unsigned long	host_no;
	uint8_t		host_str[16];

	volatile struct {
		uint32_t	init_done		:1;
		uint32_t	online			:1;
		uint32_t	reset_active		:1;

		uint32_t	management_server_logged_in :1;
		uint32_t	process_response_queue	:1;
4106
		uint32_t	difdix_supported:1;
4107
		uint32_t	delete_progress:1;
4108 4109

		uint32_t	fw_tgt_reported:1;
4110
		uint32_t	bbcr_enable:1;
4111
		uint32_t	qpairs_available:1;
4112 4113
		uint32_t	qpairs_req_created:1;
		uint32_t	qpairs_rsp_created:1;
4114
		uint32_t	nvme_enabled:1;
4115 4116 4117 4118 4119 4120 4121 4122 4123 4124
	} flags;

	atomic_t	loop_state;
#define LOOP_TIMEOUT	1
#define LOOP_DOWN	2
#define LOOP_UP		3
#define LOOP_UPDATE	4
#define LOOP_READY	5
#define LOOP_DEAD	6

4125
	unsigned long   relogin_jif;
4126 4127 4128 4129 4130 4131 4132 4133 4134
	unsigned long   dpc_flags;
#define RESET_MARKER_NEEDED	0	/* Send marker to ISP. */
#define RESET_ACTIVE		1
#define ISP_ABORT_NEEDED	2	/* Initiate ISP abort. */
#define ABORT_ISP_ACTIVE	3	/* ISP abort in progress. */
#define LOOP_RESYNC_NEEDED	4	/* Device Resync needed. */
#define LOOP_RESYNC_ACTIVE	5
#define LOCAL_LOOP_UPDATE	6	/* Perform a local loop update. */
#define RSCN_UPDATE		7	/* Perform an RSCN update. */
4135 4136 4137 4138 4139 4140 4141 4142 4143
#define RELOGIN_NEEDED		8
#define REGISTER_FC4_NEEDED	9	/* SNS FC4 registration required. */
#define ISP_ABORT_RETRY		10	/* ISP aborted. */
#define BEACON_BLINK_NEEDED	11
#define REGISTER_FDMI_NEEDED	12
#define FCPORT_UPDATE_NEEDED	13
#define VP_DPC_NEEDED		14	/* wake up for VP dpc handling */
#define UNLOADING		15
#define NPIV_CONFIG_NEEDED	16
4144 4145
#define ISP_UNRECOVERABLE	17
#define FCOE_CTX_RESET_NEEDED	18	/* Initiate FCoE context reset */
4146
#define MPI_RESET_NEEDED	19	/* Initiate MPI FW reset */
4147
#define ISP_QUIESCE_NEEDED	20	/* Driver need some quiescence */
4148
#define FREE_BIT 21
4149 4150 4151 4152
#define PORT_UPDATE_NEEDED	22
#define FX00_RESET_RECOVERY	23
#define FX00_TARGET_SCAN	24
#define FX00_CRITEMP_RECOVERY	25
4153
#define FX00_HOST_INFO_RESEND	26
4154
#define QPAIR_ONLINE_CHECK_NEEDED	27
4155
#define SET_ZIO_THRESHOLD_NEEDED	28
4156
#define DETECT_SFP_CHANGE	29
4157
#define N2N_LOGIN_NEEDED	30
4158
#define IOCB_WORK_ACTIVE	31
4159

4160 4161
	unsigned long	pci_flags;
#define PFLG_DISCONNECTED	0	/* PCI device removed */
4162
#define PFLG_DRIVER_REMOVING	1	/* PCI driver .remove */
4163
#define PFLG_DRIVER_PROBING	2	/* PCI driver .probe */
4164

4165
	uint32_t	device_flags;
4166 4167
#define SWITCH_FOUND		BIT_0
#define DFLG_NO_CABLE		BIT_1
4168
#define DFLG_DEV_FAILED		BIT_5
4169 4170 4171

	/* ISP configuration data. */
	uint16_t	loop_id;		/* Host adapter loop id */
4172 4173 4174 4175 4176 4177 4178
	uint16_t        self_login_loop_id;     /* host adapter loop id
						 * get it on self login
						 */
	fc_port_t       bidir_fcport;		/* fcport used for bidir cmnds
						 * no need of allocating it for
						 * each command
						 */
4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196

	port_id_t	d_id;			/* Host adapter port id */
	uint8_t		marker_needed;
	uint16_t	mgmt_svr_loop_id;



	/* Timeout timers. */
	uint8_t         loop_down_abort_time;    /* port down timer */
	atomic_t        loop_down_timer;         /* loop down timer */
	uint8_t         link_down_timeout;       /* link down timeout */

	uint32_t        timer_active;
	struct timer_list        timer;

	uint8_t		node_name[WWN_SIZE];
	uint8_t		port_name[WWN_SIZE];
	uint8_t		fabric_node_name[WWN_SIZE];
4197

4198
	struct		nvme_fc_local_port *nvme_local_port;
4199
	struct completion nvme_del_done;
4200
	struct list_head nvme_rport_list;
4201 4202
	atomic_t 	nvme_active_aen_cnt;
	uint16_t	nvme_last_rptd_aen;
4203

4204 4205 4206 4207
	uint16_t	fcoe_vlan_id;
	uint16_t	fcoe_fcf_idx;
	uint8_t		fcoe_vn_port_mac[6];

4208 4209 4210
	/* list of commands waiting on workqueue */
	struct list_head	qla_cmd_list;
	struct list_head	qla_sess_op_cmd_list;
4211
	struct list_head	unknown_atio_list;
4212
	spinlock_t		cmd_list_lock;
4213
	struct delayed_work	unknown_atio_work;
4214

4215 4216 4217 4218
	/* Counter to detect races between ELS and RSCN events */
	atomic_t		generation_tick;
	/* Time when global fcport update has been scheduled */
	int			total_fcport_update_gen;
4219 4220
	/* List of pending LOGOs, protected by tgt_mutex */
	struct list_head	logo_list;
4221 4222
	/* List of pending PLOGI acks, protected by hw lock */
	struct list_head	plogi_ack_list;
4223

4224 4225
	struct list_head	qp_list;

4226
	uint32_t	vp_abort_cnt;
4227

4228 4229
	struct fc_vport	*fc_vport;	/* holds fc_vport * for each vport */
	uint16_t        vp_idx;		/* vport ID */
4230
	struct qla_qpair *qpair;	/* base qpair */
4231 4232 4233 4234 4235 4236 4237

	unsigned long		vp_flags;
#define VP_IDX_ACQUIRED		0	/* bit no 0 */
#define VP_CREATE_NEEDED	1
#define VP_BIND_NEEDED		2
#define VP_DELETE_NEEDED	3
#define VP_SCR_NEEDED		4	/* State Change Request registration */
4238
#define VP_CONFIG_OK		5	/* Flag to cfg VP, if FW is ready */
4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251
	atomic_t 		vp_state;
#define VP_OFFLINE		0
#define VP_ACTIVE		1
#define VP_FAILED		2
// #define VP_DISABLE		3
	uint16_t 	vp_err_state;
	uint16_t	vp_prev_err_state;
#define VP_ERR_UNKWN		0
#define VP_ERR_PORTDWN		1
#define VP_ERR_FAB_UNSUPPORTED	2
#define VP_ERR_FAB_NORESOURCES	3
#define VP_ERR_FAB_LOGOUT	4
#define VP_ERR_ADAP_NORESOURCES	5
4252
	struct qla_hw_data *hw;
4253
	struct scsi_qlt_host vha_tgt;
4254
	struct req_que *req;
4255 4256
	int		fw_heartbeat_counter;
	int		seconds_since_last_heartbeat;
4257 4258
	struct fc_host_statistics fc_host_stat;
	struct qla_statistics qla_stats;
4259
	struct bidi_statistics bidi_stats;
4260
	atomic_t	vref_count;
4261
	struct qla8044_reset_template reset_tmplt;
4262
	uint16_t	bbcr;
4263 4264 4265 4266
	struct name_list_extended gnl;
	/* Count of active session/fcport */
	int fcport_count;
	wait_queue_head_t fcport_waitQ;
4267
	wait_queue_head_t vref_waitq;
4268
	uint8_t min_link_speed_feat;
4269 4270 4271
	uint8_t n2n_node_name[WWN_SIZE];
	uint8_t n2n_port_name[WWN_SIZE];
	uint16_t	n2n_id;
4272
	struct list_head gpnid_list;
L
Linus Torvalds 已提交
4273 4274
} scsi_qla_host_t;

4275 4276 4277 4278 4279 4280 4281 4282 4283 4284
struct qla27xx_image_status {
	uint8_t image_status_mask;
	uint16_t generation_number;
	uint8_t reserved[3];
	uint8_t ver_minor;
	uint8_t ver_major;
	uint32_t checksum;
	uint32_t signature;
} __packed;

4285 4286 4287 4288 4289 4290 4291 4292 4293
#define SET_VP_IDX	1
#define SET_AL_PA	2
#define RESET_VP_IDX	3
#define RESET_AL_PA	4
struct qla_tgt_vp_map {
	uint8_t	idx;
	scsi_qla_host_t *vha;
};

4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310
struct qla2_sgx {
	dma_addr_t		dma_addr;	/* OUT */
	uint32_t		dma_len;	/* OUT */

	uint32_t		tot_bytes;	/* IN */
	struct scatterlist	*cur_sg;	/* IN */

	/* for book keeping, bzero on initial invocation */
	uint32_t		bytes_consumed;
	uint32_t		num_bytes;
	uint32_t		tot_partial;

	/* for debugging */
	uint32_t		num_sg;
	srb_t			*sp;
};

4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330
#define QLA_FW_STARTED(_ha) {			\
	int i;					\
	_ha->flags.fw_started = 1;		\
	_ha->base_qpair->fw_started = 1;	\
	for (i = 0; i < _ha->max_qpairs; i++) {	\
	if (_ha->queue_pair_map[i])	\
	_ha->queue_pair_map[i]->fw_started = 1;	\
	}					\
}

#define QLA_FW_STOPPED(_ha) {			\
	int i;					\
	_ha->flags.fw_started = 0;		\
	_ha->base_qpair->fw_started = 0;	\
	for (i = 0; i < _ha->max_qpairs; i++) {	\
	if (_ha->queue_pair_map[i])	\
	_ha->queue_pair_map[i]->fw_started = 0;	\
	}					\
}

L
Linus Torvalds 已提交
4331 4332 4333 4334 4335
/*
 * Macros to help code, maintain, etc.
 */
#define LOOP_TRANSITION(ha) \
	(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) || \
4336
	 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) || \
L
Linus Torvalds 已提交
4337
	 atomic_read(&ha->loop_state) == LOOP_DOWN)
A
Andrew Vasquez 已提交
4338

4339 4340 4341 4342
#define STATE_TRANSITION(ha) \
		(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) || \
			 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))

4343 4344 4345 4346 4347
#define QLA_VHA_MARK_BUSY(__vha, __bail) do {		\
	atomic_inc(&__vha->vref_count);			\
	mb();						\
	if (__vha->flags.delete_progress) {		\
		atomic_dec(&__vha->vref_count);		\
4348
		wake_up(&__vha->vref_waitq);		\
4349 4350 4351 4352
		__bail = 1;				\
	} else {					\
		__bail = 0;				\
	}						\
4353 4354
} while (0)

4355
#define QLA_VHA_MARK_NOT_BUSY(__vha) do {		\
4356
	atomic_dec(&__vha->vref_count);			\
4357 4358
	wake_up(&__vha->vref_waitq);			\
} while (0)						\
4359 4360 4361 4362 4363 4364 4365 4366 4367 4368

#define QLA_QPAIR_MARK_BUSY(__qpair, __bail) do {	\
	atomic_inc(&__qpair->ref_count);		\
	mb();						\
	if (__qpair->delete_in_progress) {		\
		atomic_dec(&__qpair->ref_count);	\
		__bail = 1;				\
	} else {					\
	       __bail = 0;				\
	}						\
4369 4370
} while (0)

4371 4372 4373
#define QLA_QPAIR_MARK_NOT_BUSY(__qpair)		\
	atomic_dec(&__qpair->ref_count);		\

4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392

#define QLA_ENA_CONF(_ha) {\
    int i;\
    _ha->base_qpair->enable_explicit_conf = 1;	\
    for (i = 0; i < _ha->max_qpairs; i++) {	\
	if (_ha->queue_pair_map[i])		\
	    _ha->queue_pair_map[i]->enable_explicit_conf = 1; \
    }						\
}

#define QLA_DIS_CONF(_ha) {\
    int i;\
    _ha->base_qpair->enable_explicit_conf = 0;	\
    for (i = 0; i < _ha->max_qpairs; i++) {	\
	if (_ha->queue_pair_map[i])		\
	    _ha->queue_pair_map[i]->enable_explicit_conf = 0; \
    }						\
}

L
Linus Torvalds 已提交
4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416
/*
 * qla2x00 local function return status codes
 */
#define MBS_MASK		0x3fff

#define QLA_SUCCESS		(MBS_COMMAND_COMPLETE & MBS_MASK)
#define QLA_INVALID_COMMAND	(MBS_INVALID_COMMAND & MBS_MASK)
#define QLA_INTERFACE_ERROR	(MBS_HOST_INTERFACE_ERROR & MBS_MASK)
#define QLA_TEST_FAILED		(MBS_TEST_FAILED & MBS_MASK)
#define QLA_COMMAND_ERROR	(MBS_COMMAND_ERROR & MBS_MASK)
#define QLA_PARAMETER_ERROR	(MBS_COMMAND_PARAMETER_ERROR & MBS_MASK)
#define QLA_PORT_ID_USED	(MBS_PORT_ID_USED & MBS_MASK)
#define QLA_LOOP_ID_USED	(MBS_LOOP_ID_USED & MBS_MASK)
#define QLA_ALL_IDS_IN_USE	(MBS_ALL_IDS_IN_USE & MBS_MASK)
#define QLA_NOT_LOGGED_IN	(MBS_NOT_LOGGED_IN & MBS_MASK)

#define QLA_FUNCTION_TIMEOUT		0x100
#define QLA_FUNCTION_PARAMETER_ERROR	0x101
#define QLA_FUNCTION_FAILED		0x102
#define QLA_MEMORY_ALLOC_FAILED		0x103
#define QLA_LOCK_TIMEOUT		0x104
#define QLA_ABORTED			0x105
#define QLA_SUSPENDED			0x106
#define QLA_BUSY			0x107
4417
#define QLA_ALREADY_REGISTERED		0x109
L
Linus Torvalds 已提交
4418 4419 4420 4421 4422 4423

#define NVRAM_DELAY()		udelay(10)

/*
 * Flash support definitions
 */
4424 4425 4426
#define OPTROM_SIZE_2300	0x20000
#define OPTROM_SIZE_2322	0x100000
#define OPTROM_SIZE_24XX	0x100000
4427
#define OPTROM_SIZE_25XX	0x200000
4428
#define OPTROM_SIZE_81XX	0x400000
4429
#define OPTROM_SIZE_82XX	0x800000
4430
#define OPTROM_SIZE_83XX	0x1000000
4431 4432 4433

#define OPTROM_BURST_SIZE	0x1000
#define OPTROM_BURST_DWORDS	(OPTROM_BURST_SIZE / 4)
L
Linus Torvalds 已提交
4434

4435 4436
#define	QLA_DSDS_PER_IOCB	37

4437 4438
#define CMD_SP(Cmnd)		((Cmnd)->SCp.ptr)

4439 4440
#define QLA_SG_ALL	1024

4441 4442 4443 4444 4445 4446
enum nexus_wait_type {
	WAIT_HOST = 0,
	WAIT_TARGET,
	WAIT_LUN,
};

4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528
/* Refer to SNIA SFF 8247 */
struct sff_8247_a0 {
	u8 txid;	/* transceiver id */
	u8 ext_txid;
	u8 connector;
	/* compliance code */
	u8 eth_infi_cc3;	/* ethernet, inifiband */
	u8 sonet_cc4[2];
	u8 eth_cc6;
	/* link length */
#define FC_LL_VL BIT_7	/* very long */
#define FC_LL_S  BIT_6	/* Short */
#define FC_LL_I  BIT_5	/* Intermidiate*/
#define FC_LL_L  BIT_4	/* Long */
#define FC_LL_M  BIT_3	/* Medium */
#define FC_LL_SA BIT_2	/* ShortWave laser */
#define FC_LL_LC BIT_1	/* LongWave laser */
#define FC_LL_EL BIT_0	/* Electrical inter enclosure */
	u8 fc_ll_cc7;
	/* FC technology */
#define FC_TEC_EL BIT_7	/* Electrical inter enclosure */
#define FC_TEC_SN BIT_6	/* short wave w/o OFC */
#define FC_TEC_SL BIT_5	/* short wave with OFC */
#define FC_TEC_LL BIT_4	/* Longwave Laser */
#define FC_TEC_ACT BIT_3	/* Active cable */
#define FC_TEC_PAS BIT_2	/* Passive cable */
	u8 fc_tec_cc8;
	/* Transmission Media */
#define FC_MED_TW BIT_7	/* Twin Ax */
#define FC_MED_TP BIT_6	/* Twited Pair */
#define FC_MED_MI BIT_5	/* Min Coax */
#define FC_MED_TV BIT_4	/* Video Coax */
#define FC_MED_M6 BIT_3	/* Multimode, 62.5um */
#define FC_MED_M5 BIT_2	/* Multimode, 50um */
#define FC_MED_SM BIT_0	/* Single Mode */
	u8 fc_med_cc9;
	/* speed FC_SP_12: 12*100M = 1200 MB/s */
#define FC_SP_12 BIT_7
#define FC_SP_8  BIT_6
#define FC_SP_16 BIT_5
#define FC_SP_4  BIT_4
#define FC_SP_32 BIT_3
#define FC_SP_2  BIT_2
#define FC_SP_1  BIT_0
	u8 fc_sp_cc10;
	u8 encode;
	u8 bitrate;
	u8 rate_id;
	u8 length_km;		/* offset 14/eh */
	u8 length_100m;
	u8 length_50um_10m;
	u8 length_62um_10m;
	u8 length_om4_10m;
	u8 length_om3_10m;
#define SFF_VEN_NAME_LEN 16
	u8 vendor_name[SFF_VEN_NAME_LEN];	/* offset 20/14h */
	u8 tx_compat;
	u8 vendor_oui[3];
#define SFF_PART_NAME_LEN 16
	u8 vendor_pn[SFF_PART_NAME_LEN];	/* part number */
	u8 vendor_rev[4];
	u8 wavelength[2];
	u8 resv;
	u8 cc_base;
	u8 options[2];	/* offset 64 */
	u8 br_max;
	u8 br_min;
	u8 vendor_sn[16];
	u8 date_code[8];
	u8 diag;
	u8 enh_options;
	u8 sff_revision;
	u8 cc_ext;
	u8 vendor_specific[32];
	u8 resv2[128];
};

#define AUTO_DETECT_SFP_SUPPORT(_vha)\
	(ql2xautodetectsfp && !_vha->vp_idx &&		\
	(IS_QLA25XX(_vha->hw) || IS_QLA81XX(_vha->hw) ||\
	IS_QLA83XX(_vha->hw) || IS_QLA27XX(_vha->hw)))

4529 4530 4531
#define USER_CTRL_IRQ(_ha) (ql2xuctrlirq && QLA_TGT_MODE_ENABLED() && \
	(IS_QLA27XX(_ha) || IS_QLA83XX(_ha)))

4532
#include "qla_target.h"
L
Linus Torvalds 已提交
4533 4534 4535 4536
#include "qla_gbl.h"
#include "qla_dbg.h"
#include "qla_inline.h"
#endif