xref: /openbmc/linux/drivers/scsi/qla4xxx/ql4_def.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1e3976af5SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2afaf5a2dSDavid Somayajulu /*
3afaf5a2dSDavid Somayajulu  * QLogic iSCSI HBA Driver
44a4f51e9SVikas Chaudhary  * Copyright (c)  2003-2013 QLogic Corporation
5afaf5a2dSDavid Somayajulu  */
6afaf5a2dSDavid Somayajulu 
7afaf5a2dSDavid Somayajulu #ifndef __QL4_DEF_H
8afaf5a2dSDavid Somayajulu #define __QL4_DEF_H
9afaf5a2dSDavid Somayajulu 
10afaf5a2dSDavid Somayajulu #include <linux/kernel.h>
11afaf5a2dSDavid Somayajulu #include <linux/init.h>
12afaf5a2dSDavid Somayajulu #include <linux/types.h>
13afaf5a2dSDavid Somayajulu #include <linux/module.h>
14afaf5a2dSDavid Somayajulu #include <linux/list.h>
15afaf5a2dSDavid Somayajulu #include <linux/pci.h>
16afaf5a2dSDavid Somayajulu #include <linux/dma-mapping.h>
17afaf5a2dSDavid Somayajulu #include <linux/sched.h>
18afaf5a2dSDavid Somayajulu #include <linux/slab.h>
19afaf5a2dSDavid Somayajulu #include <linux/dmapool.h>
20afaf5a2dSDavid Somayajulu #include <linux/mempool.h>
21afaf5a2dSDavid Somayajulu #include <linux/spinlock.h>
22afaf5a2dSDavid Somayajulu #include <linux/workqueue.h>
23afaf5a2dSDavid Somayajulu #include <linux/delay.h>
24afaf5a2dSDavid Somayajulu #include <linux/interrupt.h>
25afaf5a2dSDavid Somayajulu #include <linux/mutex.h>
26a355943cSVikas Chaudhary #include <linux/bsg-lib.h>
27c6bfda8dSEric Dumazet #include <linux/vmalloc.h>
28afaf5a2dSDavid Somayajulu 
29afaf5a2dSDavid Somayajulu #include <net/tcp.h>
30afaf5a2dSDavid Somayajulu #include <scsi/scsi.h>
31afaf5a2dSDavid Somayajulu #include <scsi/scsi_host.h>
32afaf5a2dSDavid Somayajulu #include <scsi/scsi_device.h>
33afaf5a2dSDavid Somayajulu #include <scsi/scsi_cmnd.h>
34afaf5a2dSDavid Somayajulu #include <scsi/scsi_transport.h>
35afaf5a2dSDavid Somayajulu #include <scsi/scsi_transport_iscsi.h>
36a355943cSVikas Chaudhary #include <scsi/scsi_bsg_iscsi.h>
37a355943cSVikas Chaudhary #include <scsi/scsi_netlink.h>
38b3a271a9SManish Rangankar #include <scsi/libiscsi.h>
39afaf5a2dSDavid Somayajulu 
40f4f5df23SVikas Chaudhary #include "ql4_dbg.h"
41f4f5df23SVikas Chaudhary #include "ql4_nx.h"
42b3a271a9SManish Rangankar #include "ql4_fw.h"
43b3a271a9SManish Rangankar #include "ql4_nvram.h"
446e7b4292SVikas Chaudhary #include "ql4_83xx.h"
45afaf5a2dSDavid Somayajulu 
46afaf5a2dSDavid Somayajulu #ifndef PCI_DEVICE_ID_QLOGIC_ISP4010
47afaf5a2dSDavid Somayajulu #define PCI_DEVICE_ID_QLOGIC_ISP4010	0x4010
48afaf5a2dSDavid Somayajulu #endif
49afaf5a2dSDavid Somayajulu 
50afaf5a2dSDavid Somayajulu #ifndef PCI_DEVICE_ID_QLOGIC_ISP4022
51afaf5a2dSDavid Somayajulu #define PCI_DEVICE_ID_QLOGIC_ISP4022	0x4022
52d915058fSDavid C Somayajulu #endif
53d915058fSDavid C Somayajulu 
54d915058fSDavid C Somayajulu #ifndef PCI_DEVICE_ID_QLOGIC_ISP4032
55d915058fSDavid C Somayajulu #define PCI_DEVICE_ID_QLOGIC_ISP4032	0x4032
56d915058fSDavid C Somayajulu #endif
57afaf5a2dSDavid Somayajulu 
58f4f5df23SVikas Chaudhary #ifndef PCI_DEVICE_ID_QLOGIC_ISP8022
59f4f5df23SVikas Chaudhary #define PCI_DEVICE_ID_QLOGIC_ISP8022	0x8022
60f4f5df23SVikas Chaudhary #endif
61f4f5df23SVikas Chaudhary 
626e7b4292SVikas Chaudhary #ifndef PCI_DEVICE_ID_QLOGIC_ISP8324
636e7b4292SVikas Chaudhary #define PCI_DEVICE_ID_QLOGIC_ISP8324	0x8032
646e7b4292SVikas Chaudhary #endif
656e7b4292SVikas Chaudhary 
66b37ca418SVikas Chaudhary #ifndef PCI_DEVICE_ID_QLOGIC_ISP8042
67b37ca418SVikas Chaudhary #define PCI_DEVICE_ID_QLOGIC_ISP8042	0x8042
68b37ca418SVikas Chaudhary #endif
69b37ca418SVikas Chaudhary 
707eece5a0SKaren Higgins #define ISP4XXX_PCI_FN_1	0x1
717eece5a0SKaren Higgins #define ISP4XXX_PCI_FN_2	0x3
727eece5a0SKaren Higgins 
73afaf5a2dSDavid Somayajulu #define QLA_SUCCESS			0
74afaf5a2dSDavid Somayajulu #define QLA_ERROR			1
75df86f771SVikas Chaudhary #define STATUS(status)		status == QLA_ERROR ? "FAILED" : "SUCCEEDED"
76afaf5a2dSDavid Somayajulu 
77afaf5a2dSDavid Somayajulu /*
78afaf5a2dSDavid Somayajulu  * Data bit definitions
79afaf5a2dSDavid Somayajulu  */
80afaf5a2dSDavid Somayajulu #define BIT_0	0x1
81afaf5a2dSDavid Somayajulu #define BIT_1	0x2
82afaf5a2dSDavid Somayajulu #define BIT_2	0x4
83afaf5a2dSDavid Somayajulu #define BIT_3	0x8
84afaf5a2dSDavid Somayajulu #define BIT_4	0x10
85afaf5a2dSDavid Somayajulu #define BIT_5	0x20
86afaf5a2dSDavid Somayajulu #define BIT_6	0x40
87afaf5a2dSDavid Somayajulu #define BIT_7	0x80
88afaf5a2dSDavid Somayajulu #define BIT_8	0x100
89afaf5a2dSDavid Somayajulu #define BIT_9	0x200
90afaf5a2dSDavid Somayajulu #define BIT_10	0x400
91afaf5a2dSDavid Somayajulu #define BIT_11	0x800
92afaf5a2dSDavid Somayajulu #define BIT_12	0x1000
93afaf5a2dSDavid Somayajulu #define BIT_13	0x2000
94afaf5a2dSDavid Somayajulu #define BIT_14	0x4000
95afaf5a2dSDavid Somayajulu #define BIT_15	0x8000
96afaf5a2dSDavid Somayajulu #define BIT_16	0x10000
97afaf5a2dSDavid Somayajulu #define BIT_17	0x20000
98afaf5a2dSDavid Somayajulu #define BIT_18	0x40000
99afaf5a2dSDavid Somayajulu #define BIT_19	0x80000
100afaf5a2dSDavid Somayajulu #define BIT_20	0x100000
101afaf5a2dSDavid Somayajulu #define BIT_21	0x200000
102afaf5a2dSDavid Somayajulu #define BIT_22	0x400000
103afaf5a2dSDavid Somayajulu #define BIT_23	0x800000
104afaf5a2dSDavid Somayajulu #define BIT_24	0x1000000
105afaf5a2dSDavid Somayajulu #define BIT_25	0x2000000
106afaf5a2dSDavid Somayajulu #define BIT_26	0x4000000
107afaf5a2dSDavid Somayajulu #define BIT_27	0x8000000
108afaf5a2dSDavid Somayajulu #define BIT_28	0x10000000
109afaf5a2dSDavid Somayajulu #define BIT_29	0x20000000
110afaf5a2dSDavid Somayajulu #define BIT_30	0x40000000
111afaf5a2dSDavid Somayajulu #define BIT_31	0x80000000
112afaf5a2dSDavid Somayajulu 
113f4f5df23SVikas Chaudhary /**
114f4f5df23SVikas Chaudhary  * Macros to help code, maintain, etc.
115f4f5df23SVikas Chaudhary  **/
116f4f5df23SVikas Chaudhary #define ql4_printk(level, ha, format, arg...) \
117f4f5df23SVikas Chaudhary 	dev_printk(level , &((ha)->pdev->dev) , format , ## arg)
118f4f5df23SVikas Chaudhary 
119f4f5df23SVikas Chaudhary 
120afaf5a2dSDavid Somayajulu /*
121afaf5a2dSDavid Somayajulu  * Host adapter default definitions
122afaf5a2dSDavid Somayajulu  ***********************************/
123afaf5a2dSDavid Somayajulu #define MAX_HBAS		16
124afaf5a2dSDavid Somayajulu #define MAX_BUSES		1
125f4f5df23SVikas Chaudhary #define MAX_TARGETS		MAX_DEV_DB_ENTRIES
126afaf5a2dSDavid Somayajulu #define MAX_LUNS		0xffff
127b3a271a9SManish Rangankar #define MAX_AEN_ENTRIES		MAX_DEV_DB_ENTRIES
128f4f5df23SVikas Chaudhary #define MAX_DDB_ENTRIES		MAX_DEV_DB_ENTRIES
129afaf5a2dSDavid Somayajulu #define MAX_PDU_ENTRIES		32
130afaf5a2dSDavid Somayajulu #define INVALID_ENTRY		0xFFFF
131afaf5a2dSDavid Somayajulu #define MAX_CMDS_TO_RISC	1024
132afaf5a2dSDavid Somayajulu #define MAX_SRBS		MAX_CMDS_TO_RISC
133185f107eSPrasanna Mumbai #define MBOX_AEN_REG_COUNT	8
134afaf5a2dSDavid Somayajulu #define MAX_INIT_RETRIES	5
135afaf5a2dSDavid Somayajulu 
136afaf5a2dSDavid Somayajulu /*
137afaf5a2dSDavid Somayajulu  * Buffer sizes
138afaf5a2dSDavid Somayajulu  */
139afaf5a2dSDavid Somayajulu #define REQUEST_QUEUE_DEPTH		MAX_CMDS_TO_RISC
140afaf5a2dSDavid Somayajulu #define RESPONSE_QUEUE_DEPTH		64
141afaf5a2dSDavid Somayajulu #define QUEUE_SIZE			64
142afaf5a2dSDavid Somayajulu #define DMA_BUFFER_SIZE			512
1435b1c1bffSKaren Higgins #define IOCB_HIWAT_CUSHION		4
144afaf5a2dSDavid Somayajulu 
145afaf5a2dSDavid Somayajulu /*
146afaf5a2dSDavid Somayajulu  * Misc
147afaf5a2dSDavid Somayajulu  */
148afaf5a2dSDavid Somayajulu #define MAC_ADDR_LEN			6	/* in bytes */
149afaf5a2dSDavid Somayajulu #define IP_ADDR_LEN			4	/* in bytes */
1502a49a78eSVikas Chaudhary #define IPv6_ADDR_LEN			16	/* IPv6 address size */
151afaf5a2dSDavid Somayajulu #define DRIVER_NAME			"qla4xxx"
152afaf5a2dSDavid Somayajulu 
153afaf5a2dSDavid Somayajulu #define MAX_LINKED_CMDS_PER_LUN		3
154dbaf82ecSRavi Anand #define MAX_REQS_SERVICED_PER_INTR	1
155afaf5a2dSDavid Somayajulu 
156afaf5a2dSDavid Somayajulu #define ISCSI_IPADDR_SIZE		4	/* IP address size */
157b1c11812SJoe Perches #define ISCSI_ALIAS_SIZE		32	/* ISCSI Alias name size */
1585c8bfc94SDavid C Somayajulu #define ISCSI_NAME_SIZE			0xE0	/* ISCSI Name size */
159afaf5a2dSDavid Somayajulu 
16013483730SMike Christie #define QL4_SESS_RECOVERY_TMO		120	/* iSCSI session */
1613013cea8SVikas Chaudhary 						/* recovery timeout */
1623013cea8SVikas Chaudhary 
163afaf5a2dSDavid Somayajulu #define LSDW(x) ((u32)((u64)(x)))
164afaf5a2dSDavid Somayajulu #define MSDW(x) ((u32)((((u64)(x)) >> 16) >> 16))
165afaf5a2dSDavid Somayajulu 
1661e9e2be3SAdheer Chandravanshi #define DEV_DB_NON_PERSISTENT	0
1671e9e2be3SAdheer Chandravanshi #define DEV_DB_PERSISTENT	1
1681e9e2be3SAdheer Chandravanshi 
1691bc5ad3aSManish Rangankar #define QL4_ISP_REG_DISCONNECT 0xffffffffU
1701bc5ad3aSManish Rangankar 
1711e9e2be3SAdheer Chandravanshi #define COPY_ISID(dst_isid, src_isid) {			\
1721e9e2be3SAdheer Chandravanshi 	int i, j;					\
1731e9e2be3SAdheer Chandravanshi 	for (i = 0, j = ISID_SIZE - 1; i < ISID_SIZE;)	\
1741e9e2be3SAdheer Chandravanshi 		dst_isid[i++] = src_isid[j--];		\
1751e9e2be3SAdheer Chandravanshi }
1761e9e2be3SAdheer Chandravanshi 
1771e9e2be3SAdheer Chandravanshi #define SET_BITVAL(o, n, v) {	\
1781e9e2be3SAdheer Chandravanshi 	if (o)			\
1791e9e2be3SAdheer Chandravanshi 		n |= v;		\
1801e9e2be3SAdheer Chandravanshi 	else			\
1811e9e2be3SAdheer Chandravanshi 		n &= ~v;	\
1821e9e2be3SAdheer Chandravanshi }
1831e9e2be3SAdheer Chandravanshi 
184f8e93412SHarish Zunjarrao #define OP_STATE(o, f, p) {			\
185f8e93412SHarish Zunjarrao 	p = (o & f) ? "enable" : "disable";	\
186f8e93412SHarish Zunjarrao }
187f8e93412SHarish Zunjarrao 
188afaf5a2dSDavid Somayajulu /*
189afaf5a2dSDavid Somayajulu  * Retry & Timeout Values
190afaf5a2dSDavid Somayajulu  */
191afaf5a2dSDavid Somayajulu #define MBOX_TOV			60
192afaf5a2dSDavid Somayajulu #define SOFT_RESET_TOV			30
193afaf5a2dSDavid Somayajulu #define RESET_INTR_TOV			3
194afaf5a2dSDavid Somayajulu #define SEMAPHORE_TOV			10
195f4f5df23SVikas Chaudhary #define ADAPTER_INIT_TOV		30
196afaf5a2dSDavid Somayajulu #define ADAPTER_RESET_TOV		180
197afaf5a2dSDavid Somayajulu #define EXTEND_CMD_TOV			60
19861d9a2b6STej Parkash #define WAIT_CMD_TOV			5
199afaf5a2dSDavid Somayajulu #define EH_WAIT_CMD_TOV			120
200afaf5a2dSDavid Somayajulu #define FIRMWARE_UP_TOV			60
201afaf5a2dSDavid Somayajulu #define RESET_FIRMWARE_TOV		30
202afaf5a2dSDavid Somayajulu #define LOGOUT_TOV			10
203afaf5a2dSDavid Somayajulu #define IOCB_TOV_MARGIN			10
204afaf5a2dSDavid Somayajulu #define RELOGIN_TOV			18
205afaf5a2dSDavid Somayajulu #define ISNS_DEREG_TOV			5
206f581a3f7SVikas Chaudhary #define HBA_ONLINE_TOV			30
20795d31262SVikas Chaudhary #define DISABLE_ACB_TOV			30
20813483730SMike Christie #define IP_CONFIG_TOV			30
20913483730SMike Christie #define LOGIN_TOV			12
2101dc8ed5dSManish Rangankar #define BOOT_LOGIN_RESP_TOV		60
211afaf5a2dSDavid Somayajulu 
212afaf5a2dSDavid Somayajulu #define MAX_RESET_HA_RETRIES		2
2139ee91a38SShyam Sunder #define FW_ALIVE_WAIT_TOV		3
2147ab284c9SNilesh Javali #define IDC_EXTEND_TOV			8
215df86f771SVikas Chaudhary #define IDC_COMP_TOV			5
216df86f771SVikas Chaudhary #define LINK_UP_COMP_TOV		30
217afaf5a2dSDavid Somayajulu 
218*db22de3eSBart Van Assche /*
219*db22de3eSBart Van Assche  * Note: the data structure below does not have a struct iscsi_cmd member since
220*db22de3eSBart Van Assche  * the qla4xxx driver does not use libiscsi for SCSI I/O.
221*db22de3eSBart Van Assche  */
222*db22de3eSBart Van Assche struct qla4xxx_cmd_priv {
223*db22de3eSBart Van Assche 	struct srb *srb;
224*db22de3eSBart Van Assche };
225*db22de3eSBart Van Assche 
qla4xxx_cmd_priv(struct scsi_cmnd * cmd)226*db22de3eSBart Van Assche static inline struct qla4xxx_cmd_priv *qla4xxx_cmd_priv(struct scsi_cmnd *cmd)
227*db22de3eSBart Van Assche {
228*db22de3eSBart Van Assche 	return scsi_cmd_priv(cmd);
229*db22de3eSBart Van Assche }
2305369887aSVikas Chaudhary 
231afaf5a2dSDavid Somayajulu /*
232*db22de3eSBart Van Assche  * SCSI Request Block structure (srb) that is associated with each scsi_cmnd.
233afaf5a2dSDavid Somayajulu  */
234afaf5a2dSDavid Somayajulu struct srb {
235afaf5a2dSDavid Somayajulu 	struct list_head list;	/* (8)	 */
236afaf5a2dSDavid Somayajulu 	struct scsi_qla_host *ha;	/* HA the SP is queued on */
237afaf5a2dSDavid Somayajulu 	struct ddb_entry *ddb;
238afaf5a2dSDavid Somayajulu 	uint16_t flags;		/* (1) Status flags. */
239afaf5a2dSDavid Somayajulu 
240afaf5a2dSDavid Somayajulu #define SRB_DMA_VALID		BIT_3	/* DMA Buffer mapped. */
24125985edcSLucas De Marchi #define SRB_GOT_SENSE		BIT_4	/* sense data received. */
242afaf5a2dSDavid Somayajulu 	uint8_t state;		/* (1) Status flags. */
243afaf5a2dSDavid Somayajulu 
244afaf5a2dSDavid Somayajulu #define SRB_NO_QUEUE_STATE	 0	/* Request is in between states */
245afaf5a2dSDavid Somayajulu #define SRB_FREE_STATE		 1
246afaf5a2dSDavid Somayajulu #define SRB_ACTIVE_STATE	 3
247afaf5a2dSDavid Somayajulu #define SRB_ACTIVE_TIMEOUT_STATE 4
248afaf5a2dSDavid Somayajulu #define SRB_SUSPENDED_STATE	 7	/* Request in suspended state */
249afaf5a2dSDavid Somayajulu 
250afaf5a2dSDavid Somayajulu 	struct scsi_cmnd *cmd;	/* (4) SCSI command block */
251afaf5a2dSDavid Somayajulu 	dma_addr_t dma_handle;	/* (4) for unmap of single transfers */
25209a0f719SVikas Chaudhary 	struct kref srb_ref;	/* reference count for this srb */
253afaf5a2dSDavid Somayajulu 	uint8_t err_id;		/* error id */
254afaf5a2dSDavid Somayajulu #define SRB_ERR_PORT	   1	/* Request failed because "port down" */
255afaf5a2dSDavid Somayajulu #define SRB_ERR_LOOP	   2	/* Request failed because "loop down" */
256afaf5a2dSDavid Somayajulu #define SRB_ERR_DEVICE	   3	/* Request failed because "device error" */
257afaf5a2dSDavid Somayajulu #define SRB_ERR_OTHER	   4
258afaf5a2dSDavid Somayajulu 
259afaf5a2dSDavid Somayajulu 	uint16_t reserved;
260afaf5a2dSDavid Somayajulu 	uint16_t iocb_tov;
261afaf5a2dSDavid Somayajulu 	uint16_t iocb_cnt;	/* Number of used iocbs */
262afaf5a2dSDavid Somayajulu 	uint16_t cc_stat;
26394bced3cSKaren Higgins 
26494bced3cSKaren Higgins 	/* Used for extended sense / status continuation */
26594bced3cSKaren Higgins 	uint8_t *req_sense_ptr;
26694bced3cSKaren Higgins 	uint16_t req_sense_len;
26794bced3cSKaren Higgins 	uint16_t reserved2;
268afaf5a2dSDavid Somayajulu };
269afaf5a2dSDavid Somayajulu 
270c0b9d3f7SVikas Chaudhary /* Mailbox request block structure */
271c0b9d3f7SVikas Chaudhary struct mrb {
272c0b9d3f7SVikas Chaudhary 	struct scsi_qla_host *ha;
273c0b9d3f7SVikas Chaudhary 	struct mbox_cmd_iocb *mbox;
274c0b9d3f7SVikas Chaudhary 	uint32_t mbox_cmd;
275c0b9d3f7SVikas Chaudhary 	uint16_t iocb_cnt;		/* Number of used iocbs */
276c0b9d3f7SVikas Chaudhary 	uint32_t pid;
277c0b9d3f7SVikas Chaudhary };
278c0b9d3f7SVikas Chaudhary 
279afaf5a2dSDavid Somayajulu /*
2805c8bfc94SDavid C Somayajulu  * Asynchronous Event Queue structure
2815c8bfc94SDavid C Somayajulu  */
2825c8bfc94SDavid C Somayajulu struct aen {
2835c8bfc94SDavid C Somayajulu         uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
2845c8bfc94SDavid C Somayajulu };
2855c8bfc94SDavid C Somayajulu 
2865c8bfc94SDavid C Somayajulu struct ql4_aen_log {
2875c8bfc94SDavid C Somayajulu         int count;
2885c8bfc94SDavid C Somayajulu         struct aen entry[MAX_AEN_ENTRIES];
2895c8bfc94SDavid C Somayajulu };
2905c8bfc94SDavid C Somayajulu 
2915c8bfc94SDavid C Somayajulu /*
292afaf5a2dSDavid Somayajulu  * Device Database (DDB) structure
293afaf5a2dSDavid Somayajulu  */
294afaf5a2dSDavid Somayajulu struct ddb_entry {
295afaf5a2dSDavid Somayajulu 	struct scsi_qla_host *ha;
296afaf5a2dSDavid Somayajulu 	struct iscsi_cls_session *sess;
297afaf5a2dSDavid Somayajulu 	struct iscsi_cls_conn *conn;
298afaf5a2dSDavid Somayajulu 
299afaf5a2dSDavid Somayajulu 	uint16_t fw_ddb_index;	/* DDB firmware index */
300afaf5a2dSDavid Somayajulu 	uint32_t fw_ddb_device_state; /* F/W Device State  -- see ql4_fw.h */
30113483730SMike Christie 	uint16_t ddb_type;
30213483730SMike Christie #define FLASH_DDB 0x01
30313483730SMike Christie 
30413483730SMike Christie 	struct dev_db_entry fw_ddb_entry;
30513483730SMike Christie 	int (*unblock_sess)(struct iscsi_cls_session *cls_session);
30613483730SMike Christie 	int (*ddb_change)(struct scsi_qla_host *ha, uint32_t fw_ddb_index,
30713483730SMike Christie 			  struct ddb_entry *ddb_entry, uint32_t state);
30813483730SMike Christie 
30913483730SMike Christie 	/* Driver Re-login  */
31013483730SMike Christie 	unsigned long flags;		  /* DDB Flags */
311de2efea6SNilesh Javali #define DDB_CONN_CLOSE_FAILURE		0 /* 0x00000001 */
312de2efea6SNilesh Javali 
31313483730SMike Christie 	uint16_t default_relogin_timeout; /*  Max time to wait for
31413483730SMike Christie 					   *  relogin to complete */
31513483730SMike Christie 	atomic_t retry_relogin_timer;	  /* Min Time between relogins
31613483730SMike Christie 					   * (4000 only) */
31713483730SMike Christie 	atomic_t relogin_timer;		  /* Max Time to wait for
31813483730SMike Christie 					   * relogin to complete */
31913483730SMike Christie 	atomic_t relogin_retry_count;	  /* Num of times relogin has been
32013483730SMike Christie 					   * retried */
32113483730SMike Christie 	uint32_t default_time2wait;	  /* Default Min time between
32213483730SMike Christie 					   * relogins (+aens) */
323376738afSNilesh Javali 	uint16_t chap_tbl_idx;
32413483730SMike Christie };
32513483730SMike Christie 
32613483730SMike Christie struct qla_ddb_index {
32713483730SMike Christie 	struct list_head list;
32813483730SMike Christie 	uint16_t fw_ddb_idx;
329ad8bd45eSManish Rangankar 	uint16_t flash_ddb_idx;
33013483730SMike Christie 	struct dev_db_entry fw_ddb;
3311cb78d73SVikas Chaudhary 	uint8_t flash_isid[6];
33213483730SMike Christie };
33313483730SMike Christie 
33413483730SMike Christie #define DDB_IPADDR_LEN 64
33513483730SMike Christie 
33613483730SMike Christie struct ql4_tuple_ddb {
33713483730SMike Christie 	int port;
33813483730SMike Christie 	int tpgt;
33913483730SMike Christie 	char ip_addr[DDB_IPADDR_LEN];
34013483730SMike Christie 	char iscsi_name[ISCSI_NAME_SIZE];
34113483730SMike Christie 	uint16_t options;
34213483730SMike Christie #define DDB_OPT_IPV6 0x0e0e
34313483730SMike Christie #define DDB_OPT_IPV4 0x0f0f
344173269efSManish Rangankar 	uint8_t isid[6];
345afaf5a2dSDavid Somayajulu };
346afaf5a2dSDavid Somayajulu 
347afaf5a2dSDavid Somayajulu /*
348afaf5a2dSDavid Somayajulu  * DDB states.
349afaf5a2dSDavid Somayajulu  */
350afaf5a2dSDavid Somayajulu #define DDB_STATE_DEAD		0	/* We can no longer talk to
351afaf5a2dSDavid Somayajulu 					 * this device */
352afaf5a2dSDavid Somayajulu #define DDB_STATE_ONLINE	1	/* Device ready to accept
353afaf5a2dSDavid Somayajulu 					 * commands */
354afaf5a2dSDavid Somayajulu #define DDB_STATE_MISSING	2	/* Device logged off, trying
355afaf5a2dSDavid Somayajulu 					 * to re-login */
356afaf5a2dSDavid Somayajulu 
357afaf5a2dSDavid Somayajulu /*
358afaf5a2dSDavid Somayajulu  * DDB flags.
359afaf5a2dSDavid Somayajulu  */
360afaf5a2dSDavid Somayajulu #define DF_RELOGIN		0	/* Relogin to device */
3611dc8ed5dSManish Rangankar #define DF_BOOT_TGT		1	/* Boot target entry */
362afaf5a2dSDavid Somayajulu #define DF_ISNS_DISCOVERED	2	/* Device was discovered via iSNS */
363afaf5a2dSDavid Somayajulu #define DF_FO_MASKED		3
36499c6a33bSAdheer Chandravanshi #define DF_DISABLE_RELOGIN		4	/* Disable relogin to device */
365afaf5a2dSDavid Somayajulu 
366ff884430SVikas Chaudhary enum qla4_work_type {
367ff884430SVikas Chaudhary 	QLA4_EVENT_AEN,
368c0b9d3f7SVikas Chaudhary 	QLA4_EVENT_PING_STATUS,
369ff884430SVikas Chaudhary };
370afaf5a2dSDavid Somayajulu 
371ff884430SVikas Chaudhary struct qla4_work_evt {
372ff884430SVikas Chaudhary 	struct list_head list;
373ff884430SVikas Chaudhary 	enum qla4_work_type type;
374ff884430SVikas Chaudhary 	union {
375ff884430SVikas Chaudhary 		struct {
376ff884430SVikas Chaudhary 			enum iscsi_host_event_code code;
377ff884430SVikas Chaudhary 			uint32_t data_size;
37847c66248SKees Cook 			uint8_t data[];
379ff884430SVikas Chaudhary 		} aen;
380c0b9d3f7SVikas Chaudhary 		struct {
381c0b9d3f7SVikas Chaudhary 			uint32_t status;
382c0b9d3f7SVikas Chaudhary 			uint32_t pid;
383c0b9d3f7SVikas Chaudhary 			uint32_t data_size;
38447c66248SKees Cook 			uint8_t data[];
385c0b9d3f7SVikas Chaudhary 		} ping;
386ff884430SVikas Chaudhary 	} u;
387ff884430SVikas Chaudhary };
388afaf5a2dSDavid Somayajulu 
389f4f5df23SVikas Chaudhary struct ql82xx_hw_data {
390f4f5df23SVikas Chaudhary 	/* Offsets for flash/nvram access (set to ~0 if not used). */
391f4f5df23SVikas Chaudhary 	uint32_t flash_conf_off;
392f4f5df23SVikas Chaudhary 	uint32_t flash_data_off;
393f4f5df23SVikas Chaudhary 
394f4f5df23SVikas Chaudhary 	uint32_t fdt_wrt_disable;
395f4f5df23SVikas Chaudhary 	uint32_t fdt_erase_cmd;
396f4f5df23SVikas Chaudhary 	uint32_t fdt_block_size;
397f4f5df23SVikas Chaudhary 	uint32_t fdt_unprotect_sec_cmd;
398f4f5df23SVikas Chaudhary 	uint32_t fdt_protect_sec_cmd;
399f4f5df23SVikas Chaudhary 
400f4f5df23SVikas Chaudhary 	uint32_t flt_region_flt;
401f4f5df23SVikas Chaudhary 	uint32_t flt_region_fdt;
402f4f5df23SVikas Chaudhary 	uint32_t flt_region_boot;
403f4f5df23SVikas Chaudhary 	uint32_t flt_region_bootload;
404f4f5df23SVikas Chaudhary 	uint32_t flt_region_fw;
4052a991c21SManish Rangankar 
4062a991c21SManish Rangankar 	uint32_t flt_iscsi_param;
4074549415aSLalit Chandivade 	uint32_t flt_region_chap;
4084549415aSLalit Chandivade 	uint32_t flt_chap_size;
4091e9e2be3SAdheer Chandravanshi 	uint32_t flt_region_ddb;
4101e9e2be3SAdheer Chandravanshi 	uint32_t flt_ddb_size;
411f4f5df23SVikas Chaudhary };
412f4f5df23SVikas Chaudhary 
413f4f5df23SVikas Chaudhary struct qla4_8xxx_legacy_intr_set {
414f4f5df23SVikas Chaudhary 	uint32_t int_vec_bit;
415f4f5df23SVikas Chaudhary 	uint32_t tgt_status_reg;
416f4f5df23SVikas Chaudhary 	uint32_t tgt_mask_reg;
417f4f5df23SVikas Chaudhary 	uint32_t pci_int_reg;
418f4f5df23SVikas Chaudhary };
419f4f5df23SVikas Chaudhary 
420f4f5df23SVikas Chaudhary /* MSI-X Support */
421f4f5df23SVikas Chaudhary #define QLA_MSIX_ENTRIES	2
422f4f5df23SVikas Chaudhary 
423f4f5df23SVikas Chaudhary /*
424f4f5df23SVikas Chaudhary  * ISP Operations
425f4f5df23SVikas Chaudhary  */
426f4f5df23SVikas Chaudhary struct isp_operations {
427f4f5df23SVikas Chaudhary 	int (*iospace_config) (struct scsi_qla_host *ha);
428f4f5df23SVikas Chaudhary 	void (*pci_config) (struct scsi_qla_host *);
429f4f5df23SVikas Chaudhary 	void (*disable_intrs) (struct scsi_qla_host *);
430f4f5df23SVikas Chaudhary 	void (*enable_intrs) (struct scsi_qla_host *);
431f4f5df23SVikas Chaudhary 	int (*start_firmware) (struct scsi_qla_host *);
43233693c7aSVikas Chaudhary 	int (*restart_firmware) (struct scsi_qla_host *);
433f4f5df23SVikas Chaudhary 	irqreturn_t (*intr_handler) (int , void *);
434f4f5df23SVikas Chaudhary 	void (*interrupt_service_routine) (struct scsi_qla_host *, uint32_t);
43533693c7aSVikas Chaudhary 	int (*need_reset) (struct scsi_qla_host *);
436f4f5df23SVikas Chaudhary 	int (*reset_chip) (struct scsi_qla_host *);
437f4f5df23SVikas Chaudhary 	int (*reset_firmware) (struct scsi_qla_host *);
438f4f5df23SVikas Chaudhary 	void (*queue_iocb) (struct scsi_qla_host *);
439f4f5df23SVikas Chaudhary 	void (*complete_iocb) (struct scsi_qla_host *);
440f4f5df23SVikas Chaudhary 	uint16_t (*rd_shdw_req_q_out) (struct scsi_qla_host *);
441f4f5df23SVikas Chaudhary 	uint16_t (*rd_shdw_rsp_q_in) (struct scsi_qla_host *);
442f4f5df23SVikas Chaudhary 	int (*get_sys_info) (struct scsi_qla_host *);
44333693c7aSVikas Chaudhary 	uint32_t (*rd_reg_direct) (struct scsi_qla_host *, ulong);
44433693c7aSVikas Chaudhary 	void (*wr_reg_direct) (struct scsi_qla_host *, ulong, uint32_t);
44533693c7aSVikas Chaudhary 	int (*rd_reg_indirect) (struct scsi_qla_host *, uint32_t, uint32_t *);
44633693c7aSVikas Chaudhary 	int (*wr_reg_indirect) (struct scsi_qla_host *, uint32_t, uint32_t);
4473627668cSAhmed S. Darwish 	int (*idc_lock) (struct scsi_qla_host *); /* Context: task, can sleep */
44833693c7aSVikas Chaudhary 	void (*idc_unlock) (struct scsi_qla_host *);
449014aced1SAhmed S. Darwish 	void (*rom_lock_recovery) (struct scsi_qla_host *); /* Context: task, can sleep */
45033693c7aSVikas Chaudhary 	void (*queue_mailbox_command) (struct scsi_qla_host *, uint32_t *, int);
45133693c7aSVikas Chaudhary 	void (*process_mailbox_interrupt) (struct scsi_qla_host *, int);
452f4f5df23SVikas Chaudhary };
453f4f5df23SVikas Chaudhary 
454068237c8STej Parkash struct ql4_mdump_size_table {
455068237c8STej Parkash 	uint32_t size;
456068237c8STej Parkash 	uint32_t size_cmask_02;
457068237c8STej Parkash 	uint32_t size_cmask_04;
458068237c8STej Parkash 	uint32_t size_cmask_08;
459068237c8STej Parkash 	uint32_t size_cmask_10;
460068237c8STej Parkash 	uint32_t size_cmask_FF;
461068237c8STej Parkash 	uint32_t version;
462068237c8STej Parkash };
463068237c8STej Parkash 
4642bab08fcSVikas Chaudhary /*qla4xxx ipaddress configuration details */
4652bab08fcSVikas Chaudhary struct ipaddress_config {
4662bab08fcSVikas Chaudhary 	uint16_t ipv4_options;
4672bab08fcSVikas Chaudhary 	uint16_t tcp_options;
4682bab08fcSVikas Chaudhary 	uint16_t ipv4_vlan_tag;
4692bab08fcSVikas Chaudhary 	uint8_t ipv4_addr_state;
4702bab08fcSVikas Chaudhary 	uint8_t ip_address[IP_ADDR_LEN];
4712bab08fcSVikas Chaudhary 	uint8_t subnet_mask[IP_ADDR_LEN];
4722bab08fcSVikas Chaudhary 	uint8_t gateway[IP_ADDR_LEN];
4732bab08fcSVikas Chaudhary 	uint32_t ipv6_options;
4742bab08fcSVikas Chaudhary 	uint32_t ipv6_addl_options;
4752bab08fcSVikas Chaudhary 	uint8_t ipv6_link_local_state;
4762bab08fcSVikas Chaudhary 	uint8_t ipv6_addr0_state;
4772bab08fcSVikas Chaudhary 	uint8_t ipv6_addr1_state;
4782bab08fcSVikas Chaudhary 	uint8_t ipv6_default_router_state;
4792bab08fcSVikas Chaudhary 	uint16_t ipv6_vlan_tag;
4802bab08fcSVikas Chaudhary 	struct in6_addr ipv6_link_local_addr;
4812bab08fcSVikas Chaudhary 	struct in6_addr ipv6_addr0;
4822bab08fcSVikas Chaudhary 	struct in6_addr ipv6_addr1;
4832bab08fcSVikas Chaudhary 	struct in6_addr ipv6_default_router_addr;
484943c157bSVikas Chaudhary 	uint16_t eth_mtu_size;
4852ada7fc5SVikas Chaudhary 	uint16_t ipv4_port;
4862ada7fc5SVikas Chaudhary 	uint16_t ipv6_port;
487f8e93412SHarish Zunjarrao 	uint8_t control;
488f8e93412SHarish Zunjarrao 	uint16_t ipv6_tcp_options;
489f8e93412SHarish Zunjarrao 	uint8_t tcp_wsf;
490f8e93412SHarish Zunjarrao 	uint8_t ipv6_tcp_wsf;
491f8e93412SHarish Zunjarrao 	uint8_t ipv4_tos;
492f8e93412SHarish Zunjarrao 	uint8_t ipv4_cache_id;
493f8e93412SHarish Zunjarrao 	uint8_t ipv6_cache_id;
494f8e93412SHarish Zunjarrao 	uint8_t ipv4_alt_cid_len;
495f8e93412SHarish Zunjarrao 	uint8_t ipv4_alt_cid[11];
496f8e93412SHarish Zunjarrao 	uint8_t ipv4_vid_len;
497f8e93412SHarish Zunjarrao 	uint8_t ipv4_vid[11];
498f8e93412SHarish Zunjarrao 	uint8_t ipv4_ttl;
499f8e93412SHarish Zunjarrao 	uint16_t ipv6_flow_lbl;
500f8e93412SHarish Zunjarrao 	uint8_t ipv6_traffic_class;
501f8e93412SHarish Zunjarrao 	uint8_t ipv6_hop_limit;
502f8e93412SHarish Zunjarrao 	uint32_t ipv6_nd_reach_time;
503f8e93412SHarish Zunjarrao 	uint32_t ipv6_nd_rexmit_timer;
504f8e93412SHarish Zunjarrao 	uint32_t ipv6_nd_stale_timeout;
505f8e93412SHarish Zunjarrao 	uint8_t ipv6_dup_addr_detect_count;
506f8e93412SHarish Zunjarrao 	uint32_t ipv6_gw_advrt_mtu;
507f8e93412SHarish Zunjarrao 	uint16_t def_timeout;
508f8e93412SHarish Zunjarrao 	uint8_t abort_timer;
509f8e93412SHarish Zunjarrao 	uint16_t iscsi_options;
510f8e93412SHarish Zunjarrao 	uint16_t iscsi_max_pdu_size;
511f8e93412SHarish Zunjarrao 	uint16_t iscsi_first_burst_len;
512f8e93412SHarish Zunjarrao 	uint16_t iscsi_max_outstnd_r2t;
513f8e93412SHarish Zunjarrao 	uint16_t iscsi_max_burst_len;
514f8e93412SHarish Zunjarrao 	uint8_t iscsi_name[224];
5152bab08fcSVikas Chaudhary };
5162bab08fcSVikas Chaudhary 
5172a991c21SManish Rangankar #define QL4_CHAP_MAX_NAME_LEN 256
5182a991c21SManish Rangankar #define QL4_CHAP_MAX_SECRET_LEN 100
5190854f665SLalit Chandivade #define LOCAL_CHAP	0
5200854f665SLalit Chandivade #define BIDI_CHAP	1
5212a991c21SManish Rangankar 
5222a991c21SManish Rangankar struct ql4_chap_format {
5232a991c21SManish Rangankar 	u8  intr_chap_name[QL4_CHAP_MAX_NAME_LEN];
5242a991c21SManish Rangankar 	u8  intr_secret[QL4_CHAP_MAX_SECRET_LEN];
5252a991c21SManish Rangankar 	u8  target_chap_name[QL4_CHAP_MAX_NAME_LEN];
5262a991c21SManish Rangankar 	u8  target_secret[QL4_CHAP_MAX_SECRET_LEN];
5272a991c21SManish Rangankar 	u16 intr_chap_name_length;
5282a991c21SManish Rangankar 	u16 intr_secret_length;
5292a991c21SManish Rangankar 	u16 target_chap_name_length;
5302a991c21SManish Rangankar 	u16 target_secret_length;
5312a991c21SManish Rangankar };
5322a991c21SManish Rangankar 
5332a991c21SManish Rangankar struct ip_address_format {
5342a991c21SManish Rangankar 	u8 ip_type;
5352a991c21SManish Rangankar 	u8 ip_address[16];
5362a991c21SManish Rangankar };
5372a991c21SManish Rangankar 
5382a991c21SManish Rangankar struct	ql4_conn_info {
5392a991c21SManish Rangankar 	u16	dest_port;
5402a991c21SManish Rangankar 	struct	ip_address_format dest_ipaddr;
5412a991c21SManish Rangankar 	struct	ql4_chap_format chap;
5422a991c21SManish Rangankar };
5432a991c21SManish Rangankar 
5442a991c21SManish Rangankar struct ql4_boot_session_info {
5452a991c21SManish Rangankar 	u8	target_name[224];
5462a991c21SManish Rangankar 	struct	ql4_conn_info conn_list[1];
5472a991c21SManish Rangankar };
5482a991c21SManish Rangankar 
5492a991c21SManish Rangankar struct ql4_boot_tgt_info {
5502a991c21SManish Rangankar 	struct ql4_boot_session_info boot_pri_sess;
5512a991c21SManish Rangankar 	struct ql4_boot_session_info boot_sec_sess;
5522a991c21SManish Rangankar };
5532a991c21SManish Rangankar 
554afaf5a2dSDavid Somayajulu /*
555afaf5a2dSDavid Somayajulu  * Linux Host Adapter structure
556afaf5a2dSDavid Somayajulu  */
557afaf5a2dSDavid Somayajulu struct scsi_qla_host {
558afaf5a2dSDavid Somayajulu 	/* Linux adapter configuration data */
559afaf5a2dSDavid Somayajulu 	unsigned long flags;
560afaf5a2dSDavid Somayajulu 
561afaf5a2dSDavid Somayajulu #define AF_ONLINE			0 /* 0x00000001 */
562afaf5a2dSDavid Somayajulu #define AF_INIT_DONE			1 /* 0x00000002 */
563afaf5a2dSDavid Somayajulu #define AF_MBOX_COMMAND			2 /* 0x00000004 */
564afaf5a2dSDavid Somayajulu #define AF_MBOX_COMMAND_DONE		3 /* 0x00000008 */
5651e9e2be3SAdheer Chandravanshi #define AF_ST_DISCOVERY_IN_PROGRESS	4 /* 0x00000010 */
5665c8bfc94SDavid C Somayajulu #define AF_INTERRUPTS_ON		6 /* 0x00000040 */
567afaf5a2dSDavid Somayajulu #define AF_GET_CRASH_RECORD		7 /* 0x00000080 */
568afaf5a2dSDavid Somayajulu #define AF_LINK_UP			8 /* 0x00000100 */
569026fbd3aSNilesh Javali #define AF_LOOPBACK			9 /* 0x00000200 */
570afaf5a2dSDavid Somayajulu #define AF_IRQ_ATTACHED			10 /* 0x00000400 */
5715c8bfc94SDavid C Somayajulu #define AF_DISABLE_ACB_COMPLETE		11 /* 0x00000800 */
5727eece5a0SKaren Higgins #define AF_HA_REMOVAL			12 /* 0x00001000 */
573f4f5df23SVikas Chaudhary #define AF_MBOX_COMMAND_NOPOLL		18 /* 0x00040000 */
57421033639SNilesh Javali #define AF_FW_RECOVERY			19 /* 0x00080000 */
5752232be0dSLalit Chandivade #define AF_EEH_BUSY			20 /* 0x00100000 */
5762232be0dSLalit Chandivade #define AF_PCI_CHANNEL_IO_PERM_FAILURE	21 /* 0x00200000 */
57713483730SMike Christie #define AF_BUILD_DDB_LIST		22 /* 0x00400000 */
578068237c8STej Parkash #define AF_82XX_FW_DUMPED		24 /* 0x01000000 */
579de8c72daSVikas Chaudhary #define AF_8XXX_RST_OWNER		25 /* 0x02000000 */
580068237c8STej Parkash #define AF_82XX_DUMP_READING		26 /* 0x04000000 */
5815c19b92aSVikas Chaudhary #define AF_83XX_IOCB_INTR_ON		28 /* 0x10000000 */
5825c19b92aSVikas Chaudhary #define AF_83XX_MBOX_INTR_ON		29 /* 0x20000000 */
583068237c8STej Parkash 
584afaf5a2dSDavid Somayajulu 	unsigned long dpc_flags;
585afaf5a2dSDavid Somayajulu 
586afaf5a2dSDavid Somayajulu #define DPC_RESET_HA			1 /* 0x00000002 */
587afaf5a2dSDavid Somayajulu #define DPC_RETRY_RESET_HA		2 /* 0x00000004 */
588afaf5a2dSDavid Somayajulu #define DPC_RELOGIN_DEVICE		3 /* 0x00000008 */
589f4f5df23SVikas Chaudhary #define DPC_RESET_HA_FW_CONTEXT		4 /* 0x00000010 */
590afaf5a2dSDavid Somayajulu #define DPC_RESET_HA_INTR		5 /* 0x00000020 */
591afaf5a2dSDavid Somayajulu #define DPC_ISNS_RESTART		7 /* 0x00000080 */
592afaf5a2dSDavid Somayajulu #define DPC_AEN				9 /* 0x00000200 */
593afaf5a2dSDavid Somayajulu #define DPC_GET_DHCP_IP_ADDR		15 /* 0x00008000 */
594065aa1b4SVikas Chaudhary #define DPC_LINK_CHANGED		18 /* 0x00040000 */
595c4e3c368SVikas Chaudhary #define DPC_RESET_ACTIVE		20 /* 0x00100000 */
596c4e3c368SVikas Chaudhary #define DPC_HA_UNRECOVERABLE		21 /* 0x00200000 ISP-82xx only*/
597c4e3c368SVikas Chaudhary #define DPC_HA_NEED_QUIESCENT		22 /* 0x00400000 ISP-82xx only*/
598c4e3c368SVikas Chaudhary #define DPC_POST_IDC_ACK		23 /* 0x00800000 */
5997ab284c9SNilesh Javali #define DPC_RESTORE_ACB			24 /* 0x01000000 */
600906cbf3dSNilesh Javali #define DPC_SYSFS_DDB_EXPORT		25 /* 0x02000000 */
601afaf5a2dSDavid Somayajulu 
6025c8bfc94SDavid C Somayajulu 	struct Scsi_Host *host; /* pointer to host data */
6035c8bfc94SDavid C Somayajulu 	uint32_t tot_ddbs;
6045c8bfc94SDavid C Somayajulu 
605afaf5a2dSDavid Somayajulu 	uint16_t iocb_cnt;
6065b1c1bffSKaren Higgins 	uint16_t iocb_hiwat;
607afaf5a2dSDavid Somayajulu 
608afaf5a2dSDavid Somayajulu 	/* SRB cache. */
609afaf5a2dSDavid Somayajulu #define SRB_MIN_REQ	128
610afaf5a2dSDavid Somayajulu 	mempool_t *srb_mempool;
611afaf5a2dSDavid Somayajulu 
612afaf5a2dSDavid Somayajulu 	/* pci information */
613afaf5a2dSDavid Somayajulu 	struct pci_dev *pdev;
614afaf5a2dSDavid Somayajulu 
615afaf5a2dSDavid Somayajulu 	struct isp_reg __iomem *reg; /* Base I/O address */
616afaf5a2dSDavid Somayajulu 	unsigned long pio_address;
617afaf5a2dSDavid Somayajulu 	unsigned long pio_length;
618afaf5a2dSDavid Somayajulu #define MIN_IOBASE_LEN		0x100
619afaf5a2dSDavid Somayajulu 
620afaf5a2dSDavid Somayajulu 	uint16_t req_q_count;
621afaf5a2dSDavid Somayajulu 
622afaf5a2dSDavid Somayajulu 	unsigned long host_no;
623afaf5a2dSDavid Somayajulu 
624afaf5a2dSDavid Somayajulu 	/* NVRAM registers */
625afaf5a2dSDavid Somayajulu 	struct eeprom_data *nvram;
626afaf5a2dSDavid Somayajulu 	spinlock_t hardware_lock ____cacheline_aligned;
627afaf5a2dSDavid Somayajulu 	uint32_t eeprom_cmd_data;
628afaf5a2dSDavid Somayajulu 
629afaf5a2dSDavid Somayajulu 	/* Counters for general statistics */
630d915058fSDavid C Somayajulu 	uint64_t isr_count;
631afaf5a2dSDavid Somayajulu 	uint64_t adapter_error_count;
632afaf5a2dSDavid Somayajulu 	uint64_t device_error_count;
633afaf5a2dSDavid Somayajulu 	uint64_t total_io_count;
634afaf5a2dSDavid Somayajulu 	uint64_t total_mbytes_xferred;
635afaf5a2dSDavid Somayajulu 	uint64_t link_failure_count;
636afaf5a2dSDavid Somayajulu 	uint64_t invalid_crc_count;
637d915058fSDavid C Somayajulu 	uint32_t bytes_xfered;
638afaf5a2dSDavid Somayajulu 	uint32_t spurious_int_count;
639afaf5a2dSDavid Somayajulu 	uint32_t aborted_io_count;
640afaf5a2dSDavid Somayajulu 	uint32_t io_timeout_count;
641afaf5a2dSDavid Somayajulu 	uint32_t mailbox_timeout_count;
642afaf5a2dSDavid Somayajulu 	uint32_t seconds_since_last_intr;
643afaf5a2dSDavid Somayajulu 	uint32_t seconds_since_last_heartbeat;
644afaf5a2dSDavid Somayajulu 	uint32_t mac_index;
645afaf5a2dSDavid Somayajulu 
646afaf5a2dSDavid Somayajulu 	/* Info Needed for Management App */
647afaf5a2dSDavid Somayajulu 	/* --- From GetFwVersion --- */
648afaf5a2dSDavid Somayajulu 	uint32_t firmware_version[2];
649afaf5a2dSDavid Somayajulu 	uint32_t patch_number;
650afaf5a2dSDavid Somayajulu 	uint32_t build_number;
6515c8bfc94SDavid C Somayajulu 	uint32_t board_id;
652afaf5a2dSDavid Somayajulu 
653afaf5a2dSDavid Somayajulu 	/* --- From Init_FW --- */
654afaf5a2dSDavid Somayajulu 	/* init_cb_t *init_cb; */
655afaf5a2dSDavid Somayajulu 	uint16_t firmware_options;
656afaf5a2dSDavid Somayajulu 	uint8_t alias[32];
657afaf5a2dSDavid Somayajulu 	uint8_t name_string[256];
658afaf5a2dSDavid Somayajulu 	uint8_t heartbeat_interval;
659afaf5a2dSDavid Somayajulu 
660afaf5a2dSDavid Somayajulu 	/* --- From FlashSysInfo --- */
661afaf5a2dSDavid Somayajulu 	uint8_t my_mac[MAC_ADDR_LEN];
662afaf5a2dSDavid Somayajulu 	uint8_t serial_number[16];
6632a991c21SManish Rangankar 	uint16_t port_num;
664afaf5a2dSDavid Somayajulu 	/* --- From GetFwState --- */
665afaf5a2dSDavid Somayajulu 	uint32_t firmware_state;
666afaf5a2dSDavid Somayajulu 	uint32_t addl_fw_state;
667afaf5a2dSDavid Somayajulu 
668afaf5a2dSDavid Somayajulu 	/* Linux kernel thread */
669afaf5a2dSDavid Somayajulu 	struct workqueue_struct *dpc_thread;
670afaf5a2dSDavid Somayajulu 	struct work_struct dpc_work;
671afaf5a2dSDavid Somayajulu 
672afaf5a2dSDavid Somayajulu 	/* Linux timer thread */
673afaf5a2dSDavid Somayajulu 	struct timer_list timer;
674afaf5a2dSDavid Somayajulu 	uint32_t timer_active;
675afaf5a2dSDavid Somayajulu 
676afaf5a2dSDavid Somayajulu 	/* Recovery Timers */
677afaf5a2dSDavid Somayajulu 	atomic_t check_relogin_timeouts;
678afaf5a2dSDavid Somayajulu 	uint32_t retry_reset_ha_cnt;
679afaf5a2dSDavid Somayajulu 	uint32_t isp_reset_timer;	/* reset test timer */
680afaf5a2dSDavid Somayajulu 	uint32_t nic_reset_timer;	/* simulated nic reset test timer */
681afaf5a2dSDavid Somayajulu 	int eh_start;
682afaf5a2dSDavid Somayajulu 	struct list_head free_srb_q;
683afaf5a2dSDavid Somayajulu 	uint16_t free_srb_q_count;
684afaf5a2dSDavid Somayajulu 	uint16_t num_srbs_allocated;
685afaf5a2dSDavid Somayajulu 
686afaf5a2dSDavid Somayajulu 	/* DMA Memory Block */
687afaf5a2dSDavid Somayajulu 	void *queues;
688afaf5a2dSDavid Somayajulu 	dma_addr_t queues_dma;
689afaf5a2dSDavid Somayajulu 	unsigned long queues_len;
690afaf5a2dSDavid Somayajulu 
691afaf5a2dSDavid Somayajulu #define MEM_ALIGN_VALUE \
692afaf5a2dSDavid Somayajulu 	    ((max(REQUEST_QUEUE_DEPTH, RESPONSE_QUEUE_DEPTH)) * \
693afaf5a2dSDavid Somayajulu 	     sizeof(struct queue_entry))
694afaf5a2dSDavid Somayajulu 	/* request and response queue variables */
695afaf5a2dSDavid Somayajulu 	dma_addr_t request_dma;
696afaf5a2dSDavid Somayajulu 	struct queue_entry *request_ring;
697afaf5a2dSDavid Somayajulu 	struct queue_entry *request_ptr;
698afaf5a2dSDavid Somayajulu 	dma_addr_t response_dma;
699afaf5a2dSDavid Somayajulu 	struct queue_entry *response_ring;
700afaf5a2dSDavid Somayajulu 	struct queue_entry *response_ptr;
701afaf5a2dSDavid Somayajulu 	dma_addr_t shadow_regs_dma;
702afaf5a2dSDavid Somayajulu 	struct shadow_regs *shadow_regs;
703afaf5a2dSDavid Somayajulu 	uint16_t request_in;	/* Current indexes. */
704afaf5a2dSDavid Somayajulu 	uint16_t request_out;
705afaf5a2dSDavid Somayajulu 	uint16_t response_in;
706afaf5a2dSDavid Somayajulu 	uint16_t response_out;
707afaf5a2dSDavid Somayajulu 
708afaf5a2dSDavid Somayajulu 	/* aen queue variables */
709afaf5a2dSDavid Somayajulu 	uint16_t aen_q_count;	/* Number of available aen_q entries */
710afaf5a2dSDavid Somayajulu 	uint16_t aen_in;	/* Current indexes */
711afaf5a2dSDavid Somayajulu 	uint16_t aen_out;
712afaf5a2dSDavid Somayajulu 	struct aen aen_q[MAX_AEN_ENTRIES];
713afaf5a2dSDavid Somayajulu 
7145c8bfc94SDavid C Somayajulu 	struct ql4_aen_log aen_log;/* tracks all aens */
7155c8bfc94SDavid C Somayajulu 
716afaf5a2dSDavid Somayajulu 	/* This mutex protects several threads to do mailbox commands
717afaf5a2dSDavid Somayajulu 	 * concurrently.
718afaf5a2dSDavid Somayajulu 	 */
719afaf5a2dSDavid Somayajulu 	struct mutex  mbox_sem;
720afaf5a2dSDavid Somayajulu 
721afaf5a2dSDavid Somayajulu 	/* temporary mailbox status registers */
722afaf5a2dSDavid Somayajulu 	volatile uint8_t mbox_status_count;
723afaf5a2dSDavid Somayajulu 	volatile uint32_t mbox_status[MBOX_REG_COUNT];
724afaf5a2dSDavid Somayajulu 
7250e7e8501SManish Rangankar 	/* FW ddb index map */
726afaf5a2dSDavid Somayajulu 	struct ddb_entry *fw_ddb_index_map[MAX_DDB_ENTRIES];
727afaf5a2dSDavid Somayajulu 
72894bced3cSKaren Higgins 	/* Saved srb for status continuation entry processing */
72994bced3cSKaren Higgins 	struct srb *status_srb;
7302a49a78eSVikas Chaudhary 
7312a49a78eSVikas Chaudhary 	uint8_t acb_version;
732f4f5df23SVikas Chaudhary 
733f4f5df23SVikas Chaudhary 	/* qla82xx specific fields */
7347664a1fdSVikas Chaudhary 	struct device_reg_82xx  __iomem *qla4_82xx_reg; /* Base I/O address */
735f4f5df23SVikas Chaudhary 	unsigned long nx_pcibase;	/* Base I/O address */
736f4f5df23SVikas Chaudhary 	uint8_t *nx_db_rd_ptr;		/* Doorbell read pointer */
737f4f5df23SVikas Chaudhary 	unsigned long nx_db_wr_ptr;	/* Door bell write pointer */
738f4f5df23SVikas Chaudhary 	unsigned long first_page_group_start;
739f4f5df23SVikas Chaudhary 	unsigned long first_page_group_end;
740f4f5df23SVikas Chaudhary 
741f4f5df23SVikas Chaudhary 	uint32_t crb_win;
742f4f5df23SVikas Chaudhary 	uint32_t curr_window;
743f4f5df23SVikas Chaudhary 	uint32_t ddr_mn_window;
744f4f5df23SVikas Chaudhary 	unsigned long mn_win_crb;
745f4f5df23SVikas Chaudhary 	unsigned long ms_win_crb;
746f4f5df23SVikas Chaudhary 	int qdr_sn_window;
747f4f5df23SVikas Chaudhary 	rwlock_t hw_lock;
748f4f5df23SVikas Chaudhary 	uint16_t func_num;
749f4f5df23SVikas Chaudhary 	int link_width;
750f4f5df23SVikas Chaudhary 
751f4f5df23SVikas Chaudhary 	struct qla4_8xxx_legacy_intr_set nx_legacy_intr;
752f4f5df23SVikas Chaudhary 	u32 nx_crb_mask;
753f4f5df23SVikas Chaudhary 
754f4f5df23SVikas Chaudhary 	uint8_t revision_id;
755f4f5df23SVikas Chaudhary 	uint32_t fw_heartbeat_counter;
756f4f5df23SVikas Chaudhary 
757f4f5df23SVikas Chaudhary 	struct isp_operations *isp_ops;
758f4f5df23SVikas Chaudhary 	struct ql82xx_hw_data hw;
759f4f5df23SVikas Chaudhary 
760f4f5df23SVikas Chaudhary 	uint32_t nx_dev_init_timeout;
761f4f5df23SVikas Chaudhary 	uint32_t nx_reset_timeout;
762068237c8STej Parkash 	void *fw_dump;
763068237c8STej Parkash 	uint32_t fw_dump_size;
764068237c8STej Parkash 	uint32_t fw_dump_capture_mask;
765068237c8STej Parkash 	void *fw_dump_tmplt_hdr;
766068237c8STej Parkash 	uint32_t fw_dump_tmplt_size;
76758e2bbe9STej Parkash 	uint32_t fw_dump_skip_size;
768f4f5df23SVikas Chaudhary 
769f4f5df23SVikas Chaudhary 	struct completion mbx_intr_comp;
7707ad633c0SHarish Zunjarrao 
7712bab08fcSVikas Chaudhary 	struct ipaddress_config ip_config;
772ed1086e0SVikas Chaudhary 	struct iscsi_iface *iface_ipv4;
773ed1086e0SVikas Chaudhary 	struct iscsi_iface *iface_ipv6_0;
774ed1086e0SVikas Chaudhary 	struct iscsi_iface *iface_ipv6_1;
7752bab08fcSVikas Chaudhary 
7767ad633c0SHarish Zunjarrao 	/* --- From About Firmware --- */
777eee06a0fSAdheer Chandravanshi 	struct about_fw_info fw_info;
778eee06a0fSAdheer Chandravanshi 	uint32_t fw_uptime_secs;  /* seconds elapsed since fw bootup */
779eee06a0fSAdheer Chandravanshi 	uint32_t fw_uptime_msecs; /* milliseconds beyond elapsed seconds */
78013483730SMike Christie 	uint16_t def_timeout; /* Default login timeout */
781a355943cSVikas Chaudhary 
782a355943cSVikas Chaudhary 	uint32_t flash_state;
783a355943cSVikas Chaudhary #define	QLFLASH_WAITING		0
784a355943cSVikas Chaudhary #define	QLFLASH_READING		1
785a355943cSVikas Chaudhary #define	QLFLASH_WRITING		2
786b3a271a9SManish Rangankar 	struct dma_pool *chap_dma_pool;
7874549415aSLalit Chandivade 	uint8_t *chap_list; /* CHAP table cache */
7884549415aSLalit Chandivade 	struct mutex  chap_sem;
789376738afSNilesh Javali 
790b3a271a9SManish Rangankar #define CHAP_DMA_BLOCK_SIZE    512
791b3a271a9SManish Rangankar 	struct workqueue_struct *task_wq;
792b3a271a9SManish Rangankar 	unsigned long ddb_idx_map[MAX_DDB_ENTRIES / BITS_PER_LONG];
7932a991c21SManish Rangankar #define SYSFS_FLAG_FW_SEL_BOOT 2
7942a991c21SManish Rangankar 	struct iscsi_boot_kset *boot_kset;
7952a991c21SManish Rangankar 	struct ql4_boot_tgt_info boot_tgt;
79691ec7cecSVikas Chaudhary 	uint16_t phy_port_num;
79791ec7cecSVikas Chaudhary 	uint16_t phy_port_cnt;
79891ec7cecSVikas Chaudhary 	uint16_t iscsi_pci_func_cnt;
79991ec7cecSVikas Chaudhary 	uint8_t model_name[16];
80095d31262SVikas Chaudhary 	struct completion disable_acb_comp;
80113483730SMike Christie 	struct dma_pool *fw_ddb_dma_pool;
80213483730SMike Christie #define DDB_DMA_BLOCK_SIZE 512
80313483730SMike Christie 	uint16_t pri_ddb_idx;
80413483730SMike Christie 	uint16_t sec_ddb_idx;
80513483730SMike Christie 	int is_reset;
8064f77083eSMike Hernandez 	uint16_t temperature;
807ff884430SVikas Chaudhary 
808ff884430SVikas Chaudhary 	/* event work list */
809ff884430SVikas Chaudhary 	struct list_head work_list;
810ff884430SVikas Chaudhary 	spinlock_t work_lock;
811c0b9d3f7SVikas Chaudhary 
812c0b9d3f7SVikas Chaudhary 	/* mbox iocb */
813c0b9d3f7SVikas Chaudhary #define MAX_MRB		128
814c0b9d3f7SVikas Chaudhary 	struct mrb *active_mrb_array[MAX_MRB];
815c0b9d3f7SVikas Chaudhary 	uint32_t mrb_index;
81633693c7aSVikas Chaudhary 
81733693c7aSVikas Chaudhary 	uint32_t *reg_tbl;
8186e7b4292SVikas Chaudhary 	struct qla4_83xx_reset_template reset_tmplt;
8196e7b4292SVikas Chaudhary 	struct device_reg_83xx  __iomem *qla4_83xx_reg; /* Base I/O address
820b37ca418SVikas Chaudhary 							   for ISP8324 and
821b37ca418SVikas Chaudhary 							   and ISP8042 */
8226e7b4292SVikas Chaudhary 	uint32_t pf_bit;
823320a61deSNilesh Javali 	struct qla4_83xx_idc_information idc_info;
8247ab284c9SNilesh Javali 	struct addr_ctrl_blk *saved_acb;
825df86f771SVikas Chaudhary 	int notify_idc_comp;
826df86f771SVikas Chaudhary 	int notify_link_up_comp;
827df86f771SVikas Chaudhary 	int idc_extend_tmo;
828df86f771SVikas Chaudhary 	struct completion idc_comp;
829df86f771SVikas Chaudhary 	struct completion link_up_comp;
830b3a271a9SManish Rangankar };
831b3a271a9SManish Rangankar 
832b3a271a9SManish Rangankar struct ql4_task_data {
833b3a271a9SManish Rangankar 	struct scsi_qla_host *ha;
834b3a271a9SManish Rangankar 	uint8_t iocb_req_cnt;
835b3a271a9SManish Rangankar 	dma_addr_t data_dma;
836b3a271a9SManish Rangankar 	void *req_buffer;
837b3a271a9SManish Rangankar 	dma_addr_t req_dma;
83869ca216eSManish Rangankar 	uint32_t req_len;
839b3a271a9SManish Rangankar 	void *resp_buffer;
840b3a271a9SManish Rangankar 	dma_addr_t resp_dma;
841b3a271a9SManish Rangankar 	uint32_t resp_len;
842b3a271a9SManish Rangankar 	struct iscsi_task *task;
843b3a271a9SManish Rangankar 	struct passthru_status sts;
844b3a271a9SManish Rangankar 	struct work_struct task_work;
845b3a271a9SManish Rangankar };
846b3a271a9SManish Rangankar 
847b3a271a9SManish Rangankar struct qla_endpoint {
848b3a271a9SManish Rangankar 	struct Scsi_Host *host;
849d46bdeb1SManish Rangankar 	struct sockaddr_storage dst_addr;
850b3a271a9SManish Rangankar };
851b3a271a9SManish Rangankar 
852b3a271a9SManish Rangankar struct qla_conn {
853b3a271a9SManish Rangankar 	struct qla_endpoint *qla_ep;
854afaf5a2dSDavid Somayajulu };
855afaf5a2dSDavid Somayajulu 
is_ipv4_enabled(struct scsi_qla_host * ha)8562a49a78eSVikas Chaudhary static inline int is_ipv4_enabled(struct scsi_qla_host *ha)
8572a49a78eSVikas Chaudhary {
8582bab08fcSVikas Chaudhary 	return ((ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE) != 0);
8592a49a78eSVikas Chaudhary }
8602a49a78eSVikas Chaudhary 
is_ipv6_enabled(struct scsi_qla_host * ha)8612a49a78eSVikas Chaudhary static inline int is_ipv6_enabled(struct scsi_qla_host *ha)
8622a49a78eSVikas Chaudhary {
8632bab08fcSVikas Chaudhary 	return ((ha->ip_config.ipv6_options &
8642bab08fcSVikas Chaudhary 		IPV6_OPT_IPV6_PROTOCOL_ENABLE) != 0);
8652a49a78eSVikas Chaudhary }
8662a49a78eSVikas Chaudhary 
is_qla4010(struct scsi_qla_host * ha)867afaf5a2dSDavid Somayajulu static inline int is_qla4010(struct scsi_qla_host *ha)
868afaf5a2dSDavid Somayajulu {
869afaf5a2dSDavid Somayajulu 	return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4010;
870afaf5a2dSDavid Somayajulu }
871afaf5a2dSDavid Somayajulu 
is_qla4022(struct scsi_qla_host * ha)872afaf5a2dSDavid Somayajulu static inline int is_qla4022(struct scsi_qla_host *ha)
873afaf5a2dSDavid Somayajulu {
874afaf5a2dSDavid Somayajulu 	return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4022;
875afaf5a2dSDavid Somayajulu }
876afaf5a2dSDavid Somayajulu 
is_qla4032(struct scsi_qla_host * ha)877d915058fSDavid C Somayajulu static inline int is_qla4032(struct scsi_qla_host *ha)
878d915058fSDavid C Somayajulu {
879d915058fSDavid C Somayajulu 	return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4032;
880d915058fSDavid C Somayajulu }
881d915058fSDavid C Somayajulu 
is_qla40XX(struct scsi_qla_host * ha)8824549415aSLalit Chandivade static inline int is_qla40XX(struct scsi_qla_host *ha)
8834549415aSLalit Chandivade {
8844549415aSLalit Chandivade 	return is_qla4032(ha) || is_qla4022(ha) || is_qla4010(ha);
8854549415aSLalit Chandivade }
8864549415aSLalit Chandivade 
is_qla8022(struct scsi_qla_host * ha)887f4f5df23SVikas Chaudhary static inline int is_qla8022(struct scsi_qla_host *ha)
888f4f5df23SVikas Chaudhary {
889f4f5df23SVikas Chaudhary 	return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8022;
890f4f5df23SVikas Chaudhary }
891f4f5df23SVikas Chaudhary 
is_qla8032(struct scsi_qla_host * ha)8926e7b4292SVikas Chaudhary static inline int is_qla8032(struct scsi_qla_host *ha)
8936e7b4292SVikas Chaudhary {
8946e7b4292SVikas Chaudhary 	return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8324;
8956e7b4292SVikas Chaudhary }
8966e7b4292SVikas Chaudhary 
is_qla8042(struct scsi_qla_host * ha)897b37ca418SVikas Chaudhary static inline int is_qla8042(struct scsi_qla_host *ha)
898b37ca418SVikas Chaudhary {
899b37ca418SVikas Chaudhary 	return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8042;
900b37ca418SVikas Chaudhary }
901b37ca418SVikas Chaudhary 
is_qla80XX(struct scsi_qla_host * ha)9026e7b4292SVikas Chaudhary static inline int is_qla80XX(struct scsi_qla_host *ha)
9036e7b4292SVikas Chaudhary {
904b37ca418SVikas Chaudhary 	return is_qla8022(ha) || is_qla8032(ha) || is_qla8042(ha);
9056e7b4292SVikas Chaudhary }
9066e7b4292SVikas Chaudhary 
is_aer_supported(struct scsi_qla_host * ha)9072232be0dSLalit Chandivade static inline int is_aer_supported(struct scsi_qla_host *ha)
9082232be0dSLalit Chandivade {
9096e7b4292SVikas Chaudhary 	return ((ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8022) ||
910daa34eb4STej Parkash 		(ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8324) ||
911daa34eb4STej Parkash 		(ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8042));
9122232be0dSLalit Chandivade }
9132232be0dSLalit Chandivade 
adapter_up(struct scsi_qla_host * ha)914afaf5a2dSDavid Somayajulu static inline int adapter_up(struct scsi_qla_host *ha)
915afaf5a2dSDavid Somayajulu {
916afaf5a2dSDavid Somayajulu 	return (test_bit(AF_ONLINE, &ha->flags) != 0) &&
917026fbd3aSNilesh Javali 	       (test_bit(AF_LINK_UP, &ha->flags) != 0) &&
918026fbd3aSNilesh Javali 	       (!test_bit(AF_LOOPBACK, &ha->flags));
919afaf5a2dSDavid Somayajulu }
920afaf5a2dSDavid Somayajulu 
to_qla_host(struct Scsi_Host * shost)921afaf5a2dSDavid Somayajulu static inline struct scsi_qla_host* to_qla_host(struct Scsi_Host *shost)
922afaf5a2dSDavid Somayajulu {
923b3a271a9SManish Rangankar 	return (struct scsi_qla_host *)iscsi_host_priv(shost);
924afaf5a2dSDavid Somayajulu }
925afaf5a2dSDavid Somayajulu 
isp_semaphore(struct scsi_qla_host * ha)926afaf5a2dSDavid Somayajulu static inline void __iomem* isp_semaphore(struct scsi_qla_host *ha)
927afaf5a2dSDavid Somayajulu {
928d915058fSDavid C Somayajulu 	return (is_qla4010(ha) ?
929d915058fSDavid C Somayajulu 		&ha->reg->u1.isp4010.nvram :
930d915058fSDavid C Somayajulu 		&ha->reg->u1.isp4022.semaphore);
931afaf5a2dSDavid Somayajulu }
932afaf5a2dSDavid Somayajulu 
isp_nvram(struct scsi_qla_host * ha)933afaf5a2dSDavid Somayajulu static inline void __iomem* isp_nvram(struct scsi_qla_host *ha)
934afaf5a2dSDavid Somayajulu {
935d915058fSDavid C Somayajulu 	return (is_qla4010(ha) ?
936d915058fSDavid C Somayajulu 		&ha->reg->u1.isp4010.nvram :
937d915058fSDavid C Somayajulu 		&ha->reg->u1.isp4022.nvram);
938afaf5a2dSDavid Somayajulu }
939afaf5a2dSDavid Somayajulu 
isp_ext_hw_conf(struct scsi_qla_host * ha)940afaf5a2dSDavid Somayajulu static inline void __iomem* isp_ext_hw_conf(struct scsi_qla_host *ha)
941afaf5a2dSDavid Somayajulu {
942d915058fSDavid C Somayajulu 	return (is_qla4010(ha) ?
943d915058fSDavid C Somayajulu 		&ha->reg->u2.isp4010.ext_hw_conf :
944d915058fSDavid C Somayajulu 		&ha->reg->u2.isp4022.p0.ext_hw_conf);
945afaf5a2dSDavid Somayajulu }
946afaf5a2dSDavid Somayajulu 
isp_port_status(struct scsi_qla_host * ha)947afaf5a2dSDavid Somayajulu static inline void __iomem* isp_port_status(struct scsi_qla_host *ha)
948afaf5a2dSDavid Somayajulu {
949d915058fSDavid C Somayajulu 	return (is_qla4010(ha) ?
950d915058fSDavid C Somayajulu 		&ha->reg->u2.isp4010.port_status :
951d915058fSDavid C Somayajulu 		&ha->reg->u2.isp4022.p0.port_status);
952afaf5a2dSDavid Somayajulu }
953afaf5a2dSDavid Somayajulu 
isp_port_ctrl(struct scsi_qla_host * ha)954afaf5a2dSDavid Somayajulu static inline void __iomem* isp_port_ctrl(struct scsi_qla_host *ha)
955afaf5a2dSDavid Somayajulu {
956d915058fSDavid C Somayajulu 	return (is_qla4010(ha) ?
957d915058fSDavid C Somayajulu 		&ha->reg->u2.isp4010.port_ctrl :
958d915058fSDavid C Somayajulu 		&ha->reg->u2.isp4022.p0.port_ctrl);
959afaf5a2dSDavid Somayajulu }
960afaf5a2dSDavid Somayajulu 
isp_port_error_status(struct scsi_qla_host * ha)961afaf5a2dSDavid Somayajulu static inline void __iomem* isp_port_error_status(struct scsi_qla_host *ha)
962afaf5a2dSDavid Somayajulu {
963d915058fSDavid C Somayajulu 	return (is_qla4010(ha) ?
964d915058fSDavid C Somayajulu 		&ha->reg->u2.isp4010.port_err_status :
965d915058fSDavid C Somayajulu 		&ha->reg->u2.isp4022.p0.port_err_status);
966afaf5a2dSDavid Somayajulu }
967afaf5a2dSDavid Somayajulu 
isp_gp_out(struct scsi_qla_host * ha)968afaf5a2dSDavid Somayajulu static inline void __iomem * isp_gp_out(struct scsi_qla_host *ha)
969afaf5a2dSDavid Somayajulu {
970d915058fSDavid C Somayajulu 	return (is_qla4010(ha) ?
971d915058fSDavid C Somayajulu 		&ha->reg->u2.isp4010.gp_out :
972d915058fSDavid C Somayajulu 		&ha->reg->u2.isp4022.p0.gp_out);
973afaf5a2dSDavid Somayajulu }
974afaf5a2dSDavid Somayajulu 
eeprom_ext_hw_conf_offset(struct scsi_qla_host * ha)975afaf5a2dSDavid Somayajulu static inline int eeprom_ext_hw_conf_offset(struct scsi_qla_host *ha)
976afaf5a2dSDavid Somayajulu {
977d915058fSDavid C Somayajulu 	return (is_qla4010(ha) ?
978d915058fSDavid C Somayajulu 		offsetof(struct eeprom_data, isp4010.ext_hw_conf) / 2 :
979d915058fSDavid C Somayajulu 		offsetof(struct eeprom_data, isp4022.ext_hw_conf) / 2);
980afaf5a2dSDavid Somayajulu }
981afaf5a2dSDavid Somayajulu 
982afaf5a2dSDavid Somayajulu int ql4xxx_sem_spinlock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits);
983afaf5a2dSDavid Somayajulu void ql4xxx_sem_unlock(struct scsi_qla_host * ha, u32 sem_mask);
984afaf5a2dSDavid Somayajulu int ql4xxx_sem_lock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits);
985afaf5a2dSDavid Somayajulu 
ql4xxx_lock_flash(struct scsi_qla_host * a)986afaf5a2dSDavid Somayajulu static inline int ql4xxx_lock_flash(struct scsi_qla_host *a)
987afaf5a2dSDavid Somayajulu {
988d915058fSDavid C Somayajulu 	if (is_qla4010(a))
989d915058fSDavid C Somayajulu 		return ql4xxx_sem_spinlock(a, QL4010_FLASH_SEM_MASK,
990d915058fSDavid C Somayajulu 					   QL4010_FLASH_SEM_BITS);
991d915058fSDavid C Somayajulu 	else
992afaf5a2dSDavid Somayajulu 		return ql4xxx_sem_spinlock(a, QL4022_FLASH_SEM_MASK,
993afaf5a2dSDavid Somayajulu 					   (QL4022_RESOURCE_BITS_BASE_CODE |
994afaf5a2dSDavid Somayajulu 					    (a->mac_index)) << 13);
995afaf5a2dSDavid Somayajulu }
996afaf5a2dSDavid Somayajulu 
ql4xxx_unlock_flash(struct scsi_qla_host * a)997afaf5a2dSDavid Somayajulu static inline void ql4xxx_unlock_flash(struct scsi_qla_host *a)
998afaf5a2dSDavid Somayajulu {
999d915058fSDavid C Somayajulu 	if (is_qla4010(a))
1000afaf5a2dSDavid Somayajulu 		ql4xxx_sem_unlock(a, QL4010_FLASH_SEM_MASK);
1001d915058fSDavid C Somayajulu 	else
1002d915058fSDavid C Somayajulu 		ql4xxx_sem_unlock(a, QL4022_FLASH_SEM_MASK);
1003afaf5a2dSDavid Somayajulu }
1004afaf5a2dSDavid Somayajulu 
ql4xxx_lock_nvram(struct scsi_qla_host * a)1005afaf5a2dSDavid Somayajulu static inline int ql4xxx_lock_nvram(struct scsi_qla_host *a)
1006afaf5a2dSDavid Somayajulu {
1007d915058fSDavid C Somayajulu 	if (is_qla4010(a))
1008d915058fSDavid C Somayajulu 		return ql4xxx_sem_spinlock(a, QL4010_NVRAM_SEM_MASK,
1009d915058fSDavid C Somayajulu 					   QL4010_NVRAM_SEM_BITS);
1010d915058fSDavid C Somayajulu 	else
1011afaf5a2dSDavid Somayajulu 		return ql4xxx_sem_spinlock(a, QL4022_NVRAM_SEM_MASK,
1012afaf5a2dSDavid Somayajulu 					   (QL4022_RESOURCE_BITS_BASE_CODE |
1013afaf5a2dSDavid Somayajulu 					    (a->mac_index)) << 10);
1014afaf5a2dSDavid Somayajulu }
1015afaf5a2dSDavid Somayajulu 
ql4xxx_unlock_nvram(struct scsi_qla_host * a)1016afaf5a2dSDavid Somayajulu static inline void ql4xxx_unlock_nvram(struct scsi_qla_host *a)
1017afaf5a2dSDavid Somayajulu {
1018d915058fSDavid C Somayajulu 	if (is_qla4010(a))
1019afaf5a2dSDavid Somayajulu 		ql4xxx_sem_unlock(a, QL4010_NVRAM_SEM_MASK);
1020d915058fSDavid C Somayajulu 	else
1021d915058fSDavid C Somayajulu 		ql4xxx_sem_unlock(a, QL4022_NVRAM_SEM_MASK);
1022afaf5a2dSDavid Somayajulu }
1023afaf5a2dSDavid Somayajulu 
ql4xxx_lock_drvr(struct scsi_qla_host * a)1024afaf5a2dSDavid Somayajulu static inline int ql4xxx_lock_drvr(struct scsi_qla_host *a)
1025afaf5a2dSDavid Somayajulu {
1026d915058fSDavid C Somayajulu 	if (is_qla4010(a))
1027d915058fSDavid C Somayajulu 		return ql4xxx_sem_lock(a, QL4010_DRVR_SEM_MASK,
1028d915058fSDavid C Somayajulu 				       QL4010_DRVR_SEM_BITS);
1029d915058fSDavid C Somayajulu 	else
1030afaf5a2dSDavid Somayajulu 		return ql4xxx_sem_lock(a, QL4022_DRVR_SEM_MASK,
1031afaf5a2dSDavid Somayajulu 				       (QL4022_RESOURCE_BITS_BASE_CODE |
1032afaf5a2dSDavid Somayajulu 					(a->mac_index)) << 1);
1033afaf5a2dSDavid Somayajulu }
1034afaf5a2dSDavid Somayajulu 
ql4xxx_unlock_drvr(struct scsi_qla_host * a)1035afaf5a2dSDavid Somayajulu static inline void ql4xxx_unlock_drvr(struct scsi_qla_host *a)
1036afaf5a2dSDavid Somayajulu {
1037d915058fSDavid C Somayajulu 	if (is_qla4010(a))
1038afaf5a2dSDavid Somayajulu 		ql4xxx_sem_unlock(a, QL4010_DRVR_SEM_MASK);
1039d915058fSDavid C Somayajulu 	else
1040d915058fSDavid C Somayajulu 		ql4xxx_sem_unlock(a, QL4022_DRVR_SEM_MASK);
1041afaf5a2dSDavid Somayajulu }
1042afaf5a2dSDavid Somayajulu 
ql4xxx_reset_active(struct scsi_qla_host * ha)1043ef7830bbSHarish Zunjarrao static inline int ql4xxx_reset_active(struct scsi_qla_host *ha)
1044ef7830bbSHarish Zunjarrao {
1045ef7830bbSHarish Zunjarrao 	return test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
1046ef7830bbSHarish Zunjarrao 	       test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1047ef7830bbSHarish Zunjarrao 	       test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
1048ef7830bbSHarish Zunjarrao 	       test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1049ef7830bbSHarish Zunjarrao 	       test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
1050ef7830bbSHarish Zunjarrao 	       test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
1051ef7830bbSHarish Zunjarrao 
1052ef7830bbSHarish Zunjarrao }
105333693c7aSVikas Chaudhary 
qla4_8xxx_rd_direct(struct scsi_qla_host * ha,const uint32_t crb_reg)105433693c7aSVikas Chaudhary static inline int qla4_8xxx_rd_direct(struct scsi_qla_host *ha,
105533693c7aSVikas Chaudhary 				      const uint32_t crb_reg)
105633693c7aSVikas Chaudhary {
105733693c7aSVikas Chaudhary 	return ha->isp_ops->rd_reg_direct(ha, ha->reg_tbl[crb_reg]);
105833693c7aSVikas Chaudhary }
105933693c7aSVikas Chaudhary 
qla4_8xxx_wr_direct(struct scsi_qla_host * ha,const uint32_t crb_reg,const uint32_t value)106033693c7aSVikas Chaudhary static inline void qla4_8xxx_wr_direct(struct scsi_qla_host *ha,
106133693c7aSVikas Chaudhary 				       const uint32_t crb_reg,
106233693c7aSVikas Chaudhary 				       const uint32_t value)
106333693c7aSVikas Chaudhary {
106433693c7aSVikas Chaudhary 	ha->isp_ops->wr_reg_direct(ha, ha->reg_tbl[crb_reg], value);
106533693c7aSVikas Chaudhary }
106633693c7aSVikas Chaudhary 
1067afaf5a2dSDavid Somayajulu /*---------------------------------------------------------------------------*/
1068afaf5a2dSDavid Somayajulu 
1069afaf5a2dSDavid Somayajulu /* Defines for qla4xxx_initialize_adapter() and qla4xxx_recover_adapter() */
107013483730SMike Christie 
107113483730SMike Christie #define INIT_ADAPTER    0
107213483730SMike Christie #define RESET_ADAPTER   1
107313483730SMike Christie 
1074afaf5a2dSDavid Somayajulu #define PRESERVE_DDB_LIST	0
1075afaf5a2dSDavid Somayajulu #define REBUILD_DDB_LIST	1
1076afaf5a2dSDavid Somayajulu 
1077afaf5a2dSDavid Somayajulu /* Defines for process_aen() */
1078afaf5a2dSDavid Somayajulu #define PROCESS_ALL_AENS	 0
1079afaf5a2dSDavid Somayajulu #define FLUSH_DDB_CHANGED_AENS	 1
1080afaf5a2dSDavid Somayajulu 
1081068237c8STej Parkash /* Defines for udev events */
1082068237c8STej Parkash #define QL4_UEVENT_CODE_FW_DUMP		0
1083068237c8STej Parkash 
1084afaf5a2dSDavid Somayajulu #endif	/*_QLA4XXX_H */
1085