blob: f595ab13c2e17b3be7ee6b39cb93dbfde8e1bea9 [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
4 *
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
7
8#ifndef __QL4_DEF_H
9#define __QL4_DEF_H
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/types.h>
14#include <linux/module.h>
15#include <linux/list.h>
16#include <linux/pci.h>
17#include <linux/dma-mapping.h>
18#include <linux/sched.h>
19#include <linux/slab.h>
20#include <linux/dmapool.h>
21#include <linux/mempool.h>
22#include <linux/spinlock.h>
23#include <linux/workqueue.h>
24#include <linux/delay.h>
25#include <linux/interrupt.h>
26#include <linux/mutex.h>
27
28#include <net/tcp.h>
29#include <scsi/scsi.h>
30#include <scsi/scsi_host.h>
31#include <scsi/scsi_device.h>
32#include <scsi/scsi_cmnd.h>
33#include <scsi/scsi_transport.h>
34#include <scsi/scsi_transport_iscsi.h>
35
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053036#include "ql4_dbg.h"
37#include "ql4_nx.h"
David Somayajuluafaf5a22006-09-19 10:28:00 -070038
Lalit Chandivade2232be02010-07-30 14:38:47 +053039#if defined(CONFIG_PCIEAER)
40#include <linux/aer.h>
41#else
42/* AER releated */
43static inline int pci_enable_pcie_error_reporting(struct pci_dev *dev)
44{
45 return -EINVAL;
46}
47static inline int pci_disable_pcie_error_reporting(struct pci_dev *dev)
48{
49 return -EINVAL;
50}
51static inline int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
52{
53 return -EINVAL;
54}
55#endif
56
David Somayajuluafaf5a22006-09-19 10:28:00 -070057#ifndef PCI_DEVICE_ID_QLOGIC_ISP4010
58#define PCI_DEVICE_ID_QLOGIC_ISP4010 0x4010
59#endif
60
61#ifndef PCI_DEVICE_ID_QLOGIC_ISP4022
62#define PCI_DEVICE_ID_QLOGIC_ISP4022 0x4022
David C Somayajulud9150582006-11-15 17:38:40 -080063#endif
64
65#ifndef PCI_DEVICE_ID_QLOGIC_ISP4032
66#define PCI_DEVICE_ID_QLOGIC_ISP4032 0x4032
67#endif
David Somayajuluafaf5a22006-09-19 10:28:00 -070068
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053069#ifndef PCI_DEVICE_ID_QLOGIC_ISP8022
70#define PCI_DEVICE_ID_QLOGIC_ISP8022 0x8022
71#endif
72
David Somayajuluafaf5a22006-09-19 10:28:00 -070073#define QLA_SUCCESS 0
74#define QLA_ERROR 1
75
76/*
77 * Data bit definitions
78 */
79#define BIT_0 0x1
80#define BIT_1 0x2
81#define BIT_2 0x4
82#define BIT_3 0x8
83#define BIT_4 0x10
84#define BIT_5 0x20
85#define BIT_6 0x40
86#define BIT_7 0x80
87#define BIT_8 0x100
88#define BIT_9 0x200
89#define BIT_10 0x400
90#define BIT_11 0x800
91#define BIT_12 0x1000
92#define BIT_13 0x2000
93#define BIT_14 0x4000
94#define BIT_15 0x8000
95#define BIT_16 0x10000
96#define BIT_17 0x20000
97#define BIT_18 0x40000
98#define BIT_19 0x80000
99#define BIT_20 0x100000
100#define BIT_21 0x200000
101#define BIT_22 0x400000
102#define BIT_23 0x800000
103#define BIT_24 0x1000000
104#define BIT_25 0x2000000
105#define BIT_26 0x4000000
106#define BIT_27 0x8000000
107#define BIT_28 0x10000000
108#define BIT_29 0x20000000
109#define BIT_30 0x40000000
110#define BIT_31 0x80000000
111
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530112/**
113 * Macros to help code, maintain, etc.
114 **/
115#define ql4_printk(level, ha, format, arg...) \
116 dev_printk(level , &((ha)->pdev->dev) , format , ## arg)
117
118
David Somayajuluafaf5a22006-09-19 10:28:00 -0700119/*
120 * Host adapter default definitions
121 ***********************************/
122#define MAX_HBAS 16
123#define MAX_BUSES 1
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530124#define MAX_TARGETS MAX_DEV_DB_ENTRIES
David Somayajuluafaf5a22006-09-19 10:28:00 -0700125#define MAX_LUNS 0xffff
126#define MAX_AEN_ENTRIES 256 /* should be > EXT_DEF_MAX_AEN_QUEUE */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530127#define MAX_DDB_ENTRIES MAX_DEV_DB_ENTRIES
David Somayajuluafaf5a22006-09-19 10:28:00 -0700128#define MAX_PDU_ENTRIES 32
129#define INVALID_ENTRY 0xFFFF
130#define MAX_CMDS_TO_RISC 1024
131#define MAX_SRBS MAX_CMDS_TO_RISC
132#define MBOX_AEN_REG_COUNT 5
133#define MAX_INIT_RETRIES 5
David Somayajuluafaf5a22006-09-19 10:28:00 -0700134
135/*
136 * Buffer sizes
137 */
138#define REQUEST_QUEUE_DEPTH MAX_CMDS_TO_RISC
139#define RESPONSE_QUEUE_DEPTH 64
140#define QUEUE_SIZE 64
141#define DMA_BUFFER_SIZE 512
142
143/*
144 * Misc
145 */
146#define MAC_ADDR_LEN 6 /* in bytes */
147#define IP_ADDR_LEN 4 /* in bytes */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530148#define IPv6_ADDR_LEN 16 /* IPv6 address size */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700149#define DRIVER_NAME "qla4xxx"
150
151#define MAX_LINKED_CMDS_PER_LUN 3
Ravi Ananddbaf82e2010-07-10 14:50:32 +0530152#define MAX_REQS_SERVICED_PER_INTR 1
David Somayajuluafaf5a22006-09-19 10:28:00 -0700153
154#define ISCSI_IPADDR_SIZE 4 /* IP address size */
Joe Perchesb1c11812008-02-03 17:28:22 +0200155#define ISCSI_ALIAS_SIZE 32 /* ISCSI Alias name size */
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700156#define ISCSI_NAME_SIZE 0xE0 /* ISCSI Name size */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700157
Vikas Chaudhary3013cea2010-07-30 14:25:46 +0530158#define QL4_SESS_RECOVERY_TMO 30 /* iSCSI session */
159 /* recovery timeout */
160
David Somayajuluafaf5a22006-09-19 10:28:00 -0700161#define LSDW(x) ((u32)((u64)(x)))
162#define MSDW(x) ((u32)((((u64)(x)) >> 16) >> 16))
163
164/*
165 * Retry & Timeout Values
166 */
167#define MBOX_TOV 60
168#define SOFT_RESET_TOV 30
169#define RESET_INTR_TOV 3
170#define SEMAPHORE_TOV 10
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530171#define ADAPTER_INIT_TOV 30
David Somayajuluafaf5a22006-09-19 10:28:00 -0700172#define ADAPTER_RESET_TOV 180
173#define EXTEND_CMD_TOV 60
174#define WAIT_CMD_TOV 30
175#define EH_WAIT_CMD_TOV 120
176#define FIRMWARE_UP_TOV 60
177#define RESET_FIRMWARE_TOV 30
178#define LOGOUT_TOV 10
179#define IOCB_TOV_MARGIN 10
180#define RELOGIN_TOV 18
181#define ISNS_DEREG_TOV 5
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -0700182#define HBA_ONLINE_TOV 30
David Somayajuluafaf5a22006-09-19 10:28:00 -0700183
184#define MAX_RESET_HA_RETRIES 2
185
Vikas Chaudhary53698872010-04-28 11:41:59 +0530186#define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr)
187
David Somayajuluafaf5a22006-09-19 10:28:00 -0700188/*
189 * SCSI Request Block structure (srb) that is placed
190 * on cmd->SCp location of every I/O [We have 22 bytes available]
191 */
192struct srb {
193 struct list_head list; /* (8) */
194 struct scsi_qla_host *ha; /* HA the SP is queued on */
195 struct ddb_entry *ddb;
196 uint16_t flags; /* (1) Status flags. */
197
198#define SRB_DMA_VALID BIT_3 /* DMA Buffer mapped. */
199#define SRB_GOT_SENSE BIT_4 /* sense data recieved. */
200 uint8_t state; /* (1) Status flags. */
201
202#define SRB_NO_QUEUE_STATE 0 /* Request is in between states */
203#define SRB_FREE_STATE 1
204#define SRB_ACTIVE_STATE 3
205#define SRB_ACTIVE_TIMEOUT_STATE 4
206#define SRB_SUSPENDED_STATE 7 /* Request in suspended state */
207
208 struct scsi_cmnd *cmd; /* (4) SCSI command block */
209 dma_addr_t dma_handle; /* (4) for unmap of single transfers */
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530210 struct kref srb_ref; /* reference count for this srb */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700211 uint32_t fw_ddb_index;
212 uint8_t err_id; /* error id */
213#define SRB_ERR_PORT 1 /* Request failed because "port down" */
214#define SRB_ERR_LOOP 2 /* Request failed because "loop down" */
215#define SRB_ERR_DEVICE 3 /* Request failed because "device error" */
216#define SRB_ERR_OTHER 4
217
218 uint16_t reserved;
219 uint16_t iocb_tov;
220 uint16_t iocb_cnt; /* Number of used iocbs */
221 uint16_t cc_stat;
Karen Higgins94bced32009-07-15 15:02:58 -0500222
223 /* Used for extended sense / status continuation */
224 uint8_t *req_sense_ptr;
225 uint16_t req_sense_len;
226 uint16_t reserved2;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700227};
228
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700229/*
230 * Asynchronous Event Queue structure
231 */
232struct aen {
233 uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
234};
235
236struct ql4_aen_log {
237 int count;
238 struct aen entry[MAX_AEN_ENTRIES];
239};
240
241/*
242 * Device Database (DDB) structure
243 */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700244struct ddb_entry {
245 struct list_head list; /* ddb list */
246 struct scsi_qla_host *ha;
247 struct iscsi_cls_session *sess;
248 struct iscsi_cls_conn *conn;
249
250 atomic_t state; /* DDB State */
251
252 unsigned long flags; /* DDB Flags */
253
254 unsigned long dev_scan_wait_to_start_relogin;
255 unsigned long dev_scan_wait_to_complete_relogin;
256
David Somayajuluafaf5a22006-09-19 10:28:00 -0700257 uint16_t fw_ddb_index; /* DDB firmware index */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530258 uint16_t options;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700259 uint32_t fw_ddb_device_state; /* F/W Device State -- see ql4_fw.h */
260
261 uint32_t CmdSn;
262 uint16_t target_session_id;
263 uint16_t connection_id;
264 uint16_t exe_throttle; /* Max mumber of cmds outstanding
265 * simultaneously */
266 uint16_t task_mgmt_timeout; /* Min time for task mgmt cmds to
267 * complete */
268 uint16_t default_relogin_timeout; /* Max time to wait for
269 * relogin to complete */
270 uint16_t tcp_source_port_num;
271 uint32_t default_time2wait; /* Default Min time between
272 * relogins (+aens) */
273
David Somayajuluafaf5a22006-09-19 10:28:00 -0700274 atomic_t retry_relogin_timer; /* Min Time between relogins
275 * (4000 only) */
276 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
277 atomic_t relogin_retry_count; /* Num of times relogin has been
278 * retried */
279
280 uint16_t port;
281 uint32_t tpgt;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530282 uint8_t ip_addr[IP_ADDR_LEN];
David Somayajuluafaf5a22006-09-19 10:28:00 -0700283 uint8_t iscsi_name[ISCSI_NAME_SIZE]; /* 72 x48 */
284 uint8_t iscsi_alias[0x20];
Mike Christie41bbdbe2009-01-16 12:36:52 -0600285 uint8_t isid[6];
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530286 uint16_t iscsi_max_burst_len;
287 uint16_t iscsi_max_outsnd_r2t;
288 uint16_t iscsi_first_burst_len;
289 uint16_t iscsi_max_rcv_data_seg_len;
290 uint16_t iscsi_max_snd_data_seg_len;
291
292 struct in6_addr remote_ipv6_addr;
293 struct in6_addr link_local_ipv6_addr;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700294};
295
296/*
297 * DDB states.
298 */
299#define DDB_STATE_DEAD 0 /* We can no longer talk to
300 * this device */
301#define DDB_STATE_ONLINE 1 /* Device ready to accept
302 * commands */
303#define DDB_STATE_MISSING 2 /* Device logged off, trying
304 * to re-login */
305
306/*
307 * DDB flags.
308 */
309#define DF_RELOGIN 0 /* Relogin to device */
310#define DF_NO_RELOGIN 1 /* Do not relogin if IOCTL
311 * logged it out */
312#define DF_ISNS_DISCOVERED 2 /* Device was discovered via iSNS */
313#define DF_FO_MASKED 3
314
David Somayajuluafaf5a22006-09-19 10:28:00 -0700315
316#include "ql4_fw.h"
317#include "ql4_nvram.h"
318
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530319struct ql82xx_hw_data {
320 /* Offsets for flash/nvram access (set to ~0 if not used). */
321 uint32_t flash_conf_off;
322 uint32_t flash_data_off;
323
324 uint32_t fdt_wrt_disable;
325 uint32_t fdt_erase_cmd;
326 uint32_t fdt_block_size;
327 uint32_t fdt_unprotect_sec_cmd;
328 uint32_t fdt_protect_sec_cmd;
329
330 uint32_t flt_region_flt;
331 uint32_t flt_region_fdt;
332 uint32_t flt_region_boot;
333 uint32_t flt_region_bootload;
334 uint32_t flt_region_fw;
335 uint32_t reserved;
336};
337
338struct qla4_8xxx_legacy_intr_set {
339 uint32_t int_vec_bit;
340 uint32_t tgt_status_reg;
341 uint32_t tgt_mask_reg;
342 uint32_t pci_int_reg;
343};
344
345/* MSI-X Support */
346
347#define QLA_MSIX_DEFAULT 0x00
348#define QLA_MSIX_RSP_Q 0x01
349
350#define QLA_MSIX_ENTRIES 2
351#define QLA_MIDX_DEFAULT 0
352#define QLA_MIDX_RSP_Q 1
353
354struct ql4_msix_entry {
355 int have_irq;
356 uint16_t msix_vector;
357 uint16_t msix_entry;
358};
359
360/*
361 * ISP Operations
362 */
363struct isp_operations {
364 int (*iospace_config) (struct scsi_qla_host *ha);
365 void (*pci_config) (struct scsi_qla_host *);
366 void (*disable_intrs) (struct scsi_qla_host *);
367 void (*enable_intrs) (struct scsi_qla_host *);
368 int (*start_firmware) (struct scsi_qla_host *);
369 irqreturn_t (*intr_handler) (int , void *);
370 void (*interrupt_service_routine) (struct scsi_qla_host *, uint32_t);
371 int (*reset_chip) (struct scsi_qla_host *);
372 int (*reset_firmware) (struct scsi_qla_host *);
373 void (*queue_iocb) (struct scsi_qla_host *);
374 void (*complete_iocb) (struct scsi_qla_host *);
375 uint16_t (*rd_shdw_req_q_out) (struct scsi_qla_host *);
376 uint16_t (*rd_shdw_rsp_q_in) (struct scsi_qla_host *);
377 int (*get_sys_info) (struct scsi_qla_host *);
378};
379
David Somayajuluafaf5a22006-09-19 10:28:00 -0700380/*
381 * Linux Host Adapter structure
382 */
383struct scsi_qla_host {
384 /* Linux adapter configuration data */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700385 unsigned long flags;
386
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700387#define AF_ONLINE 0 /* 0x00000001 */
388#define AF_INIT_DONE 1 /* 0x00000002 */
389#define AF_MBOX_COMMAND 2 /* 0x00000004 */
390#define AF_MBOX_COMMAND_DONE 3 /* 0x00000008 */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530391#define AF_DPC_SCHEDULED 5 /* 0x00000020 */
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700392#define AF_INTERRUPTS_ON 6 /* 0x00000040 */
393#define AF_GET_CRASH_RECORD 7 /* 0x00000080 */
394#define AF_LINK_UP 8 /* 0x00000100 */
395#define AF_IRQ_ATTACHED 10 /* 0x00000400 */
396#define AF_DISABLE_ACB_COMPLETE 11 /* 0x00000800 */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530397#define AF_HBA_GOING_AWAY 12 /* 0x00001000 */
398#define AF_INTx_ENABLED 15 /* 0x00008000 */
399#define AF_MSI_ENABLED 16 /* 0x00010000 */
400#define AF_MSIX_ENABLED 17 /* 0x00020000 */
401#define AF_MBOX_COMMAND_NOPOLL 18 /* 0x00040000 */
Nilesh Javali21033632010-07-30 14:28:07 +0530402#define AF_FW_RECOVERY 19 /* 0x00080000 */
Lalit Chandivade2232be02010-07-30 14:38:47 +0530403#define AF_EEH_BUSY 20 /* 0x00100000 */
404#define AF_PCI_CHANNEL_IO_PERM_FAILURE 21 /* 0x00200000 */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700405
406 unsigned long dpc_flags;
407
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700408#define DPC_RESET_HA 1 /* 0x00000002 */
409#define DPC_RETRY_RESET_HA 2 /* 0x00000004 */
410#define DPC_RELOGIN_DEVICE 3 /* 0x00000008 */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530411#define DPC_RESET_HA_FW_CONTEXT 4 /* 0x00000010 */
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700412#define DPC_RESET_HA_INTR 5 /* 0x00000020 */
413#define DPC_ISNS_RESTART 7 /* 0x00000080 */
414#define DPC_AEN 9 /* 0x00000200 */
415#define DPC_GET_DHCP_IP_ADDR 15 /* 0x00008000 */
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +0530416#define DPC_LINK_CHANGED 18 /* 0x00040000 */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530417#define DPC_RESET_ACTIVE 20 /* 0x00040000 */
418#define DPC_HA_UNRECOVERABLE 21 /* 0x00080000 ISP-82xx only*/
419#define DPC_HA_NEED_QUIESCENT 22 /* 0x00100000 ISP-82xx only*/
420
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700421
422 struct Scsi_Host *host; /* pointer to host data */
423 uint32_t tot_ddbs;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700424
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530425 uint16_t iocb_cnt;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700426
427 /* SRB cache. */
428#define SRB_MIN_REQ 128
429 mempool_t *srb_mempool;
430
431 /* pci information */
432 struct pci_dev *pdev;
433
434 struct isp_reg __iomem *reg; /* Base I/O address */
435 unsigned long pio_address;
436 unsigned long pio_length;
437#define MIN_IOBASE_LEN 0x100
438
439 uint16_t req_q_count;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700440
441 unsigned long host_no;
442
443 /* NVRAM registers */
444 struct eeprom_data *nvram;
445 spinlock_t hardware_lock ____cacheline_aligned;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530446 uint32_t eeprom_cmd_data;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700447
448 /* Counters for general statistics */
David C Somayajulud9150582006-11-15 17:38:40 -0800449 uint64_t isr_count;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700450 uint64_t adapter_error_count;
451 uint64_t device_error_count;
452 uint64_t total_io_count;
453 uint64_t total_mbytes_xferred;
454 uint64_t link_failure_count;
455 uint64_t invalid_crc_count;
David C Somayajulud9150582006-11-15 17:38:40 -0800456 uint32_t bytes_xfered;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700457 uint32_t spurious_int_count;
458 uint32_t aborted_io_count;
459 uint32_t io_timeout_count;
460 uint32_t mailbox_timeout_count;
461 uint32_t seconds_since_last_intr;
462 uint32_t seconds_since_last_heartbeat;
463 uint32_t mac_index;
464
465 /* Info Needed for Management App */
466 /* --- From GetFwVersion --- */
467 uint32_t firmware_version[2];
468 uint32_t patch_number;
469 uint32_t build_number;
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700470 uint32_t board_id;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700471
472 /* --- From Init_FW --- */
473 /* init_cb_t *init_cb; */
474 uint16_t firmware_options;
475 uint16_t tcp_options;
476 uint8_t ip_address[IP_ADDR_LEN];
477 uint8_t subnet_mask[IP_ADDR_LEN];
478 uint8_t gateway[IP_ADDR_LEN];
479 uint8_t alias[32];
480 uint8_t name_string[256];
481 uint8_t heartbeat_interval;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700482
483 /* --- From FlashSysInfo --- */
484 uint8_t my_mac[MAC_ADDR_LEN];
485 uint8_t serial_number[16];
486
487 /* --- From GetFwState --- */
488 uint32_t firmware_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700489 uint32_t addl_fw_state;
490
491 /* Linux kernel thread */
492 struct workqueue_struct *dpc_thread;
493 struct work_struct dpc_work;
494
495 /* Linux timer thread */
496 struct timer_list timer;
497 uint32_t timer_active;
498
499 /* Recovery Timers */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700500 uint32_t discovery_wait;
501 atomic_t check_relogin_timeouts;
502 uint32_t retry_reset_ha_cnt;
503 uint32_t isp_reset_timer; /* reset test timer */
504 uint32_t nic_reset_timer; /* simulated nic reset test timer */
505 int eh_start;
506 struct list_head free_srb_q;
507 uint16_t free_srb_q_count;
508 uint16_t num_srbs_allocated;
509
510 /* DMA Memory Block */
511 void *queues;
512 dma_addr_t queues_dma;
513 unsigned long queues_len;
514
515#define MEM_ALIGN_VALUE \
516 ((max(REQUEST_QUEUE_DEPTH, RESPONSE_QUEUE_DEPTH)) * \
517 sizeof(struct queue_entry))
518 /* request and response queue variables */
519 dma_addr_t request_dma;
520 struct queue_entry *request_ring;
521 struct queue_entry *request_ptr;
522 dma_addr_t response_dma;
523 struct queue_entry *response_ring;
524 struct queue_entry *response_ptr;
525 dma_addr_t shadow_regs_dma;
526 struct shadow_regs *shadow_regs;
527 uint16_t request_in; /* Current indexes. */
528 uint16_t request_out;
529 uint16_t response_in;
530 uint16_t response_out;
531
532 /* aen queue variables */
533 uint16_t aen_q_count; /* Number of available aen_q entries */
534 uint16_t aen_in; /* Current indexes */
535 uint16_t aen_out;
536 struct aen aen_q[MAX_AEN_ENTRIES];
537
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700538 struct ql4_aen_log aen_log;/* tracks all aens */
539
David Somayajuluafaf5a22006-09-19 10:28:00 -0700540 /* This mutex protects several threads to do mailbox commands
541 * concurrently.
542 */
543 struct mutex mbox_sem;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700544
545 /* temporary mailbox status registers */
546 volatile uint8_t mbox_status_count;
547 volatile uint32_t mbox_status[MBOX_REG_COUNT];
548
549 /* local device database list (contains internal ddb entries) */
550 struct list_head ddb_list;
551
552 /* Map ddb_list entry by FW ddb index */
553 struct ddb_entry *fw_ddb_index_map[MAX_DDB_ENTRIES];
554
Karen Higgins94bced32009-07-15 15:02:58 -0500555 /* Saved srb for status continuation entry processing */
556 struct srb *status_srb;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530557
558 /* IPv6 support info from InitFW */
559 uint8_t acb_version;
560 uint8_t ipv4_addr_state;
561 uint16_t ipv4_options;
562
563 uint32_t resvd2;
564 uint32_t ipv6_options;
565 uint32_t ipv6_addl_options;
566 uint8_t ipv6_link_local_state;
567 uint8_t ipv6_addr0_state;
568 uint8_t ipv6_addr1_state;
569 uint8_t ipv6_default_router_state;
570 struct in6_addr ipv6_link_local_addr;
571 struct in6_addr ipv6_addr0;
572 struct in6_addr ipv6_addr1;
573 struct in6_addr ipv6_default_router_addr;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530574
575 /* qla82xx specific fields */
576 struct device_reg_82xx __iomem *qla4_8xxx_reg; /* Base I/O address */
577 unsigned long nx_pcibase; /* Base I/O address */
578 uint8_t *nx_db_rd_ptr; /* Doorbell read pointer */
579 unsigned long nx_db_wr_ptr; /* Door bell write pointer */
580 unsigned long first_page_group_start;
581 unsigned long first_page_group_end;
582
583 uint32_t crb_win;
584 uint32_t curr_window;
585 uint32_t ddr_mn_window;
586 unsigned long mn_win_crb;
587 unsigned long ms_win_crb;
588 int qdr_sn_window;
589 rwlock_t hw_lock;
590 uint16_t func_num;
591 int link_width;
592
593 struct qla4_8xxx_legacy_intr_set nx_legacy_intr;
594 u32 nx_crb_mask;
595
596 uint8_t revision_id;
597 uint32_t fw_heartbeat_counter;
598
599 struct isp_operations *isp_ops;
600 struct ql82xx_hw_data hw;
601
602 struct ql4_msix_entry msix_entries[QLA_MSIX_ENTRIES];
603
604 uint32_t nx_dev_init_timeout;
605 uint32_t nx_reset_timeout;
606
607 struct completion mbx_intr_comp;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700608};
609
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530610static inline int is_ipv4_enabled(struct scsi_qla_host *ha)
611{
612 return ((ha->ipv4_options & IPOPT_IPv4_PROTOCOL_ENABLE) != 0);
613}
614
615static inline int is_ipv6_enabled(struct scsi_qla_host *ha)
616{
617 return ((ha->ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE) != 0);
618}
619
David Somayajuluafaf5a22006-09-19 10:28:00 -0700620static inline int is_qla4010(struct scsi_qla_host *ha)
621{
622 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4010;
623}
624
625static inline int is_qla4022(struct scsi_qla_host *ha)
626{
627 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4022;
628}
629
David C Somayajulud9150582006-11-15 17:38:40 -0800630static inline int is_qla4032(struct scsi_qla_host *ha)
631{
632 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4032;
633}
634
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530635static inline int is_qla8022(struct scsi_qla_host *ha)
636{
637 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8022;
638}
639
Lalit Chandivade2232be02010-07-30 14:38:47 +0530640/* Note: Currently AER/EEH is now supported only for 8022 cards
641 * This function needs to be updated when AER/EEH is enabled
642 * for other cards.
643 */
644static inline int is_aer_supported(struct scsi_qla_host *ha)
645{
646 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8022;
647}
648
David Somayajuluafaf5a22006-09-19 10:28:00 -0700649static inline int adapter_up(struct scsi_qla_host *ha)
650{
651 return (test_bit(AF_ONLINE, &ha->flags) != 0) &&
652 (test_bit(AF_LINK_UP, &ha->flags) != 0);
653}
654
655static inline struct scsi_qla_host* to_qla_host(struct Scsi_Host *shost)
656{
657 return (struct scsi_qla_host *)shost->hostdata;
658}
659
660static inline void __iomem* isp_semaphore(struct scsi_qla_host *ha)
661{
David C Somayajulud9150582006-11-15 17:38:40 -0800662 return (is_qla4010(ha) ?
663 &ha->reg->u1.isp4010.nvram :
664 &ha->reg->u1.isp4022.semaphore);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700665}
666
667static inline void __iomem* isp_nvram(struct scsi_qla_host *ha)
668{
David C Somayajulud9150582006-11-15 17:38:40 -0800669 return (is_qla4010(ha) ?
670 &ha->reg->u1.isp4010.nvram :
671 &ha->reg->u1.isp4022.nvram);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700672}
673
674static inline void __iomem* isp_ext_hw_conf(struct scsi_qla_host *ha)
675{
David C Somayajulud9150582006-11-15 17:38:40 -0800676 return (is_qla4010(ha) ?
677 &ha->reg->u2.isp4010.ext_hw_conf :
678 &ha->reg->u2.isp4022.p0.ext_hw_conf);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700679}
680
681static inline void __iomem* isp_port_status(struct scsi_qla_host *ha)
682{
David C Somayajulud9150582006-11-15 17:38:40 -0800683 return (is_qla4010(ha) ?
684 &ha->reg->u2.isp4010.port_status :
685 &ha->reg->u2.isp4022.p0.port_status);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700686}
687
688static inline void __iomem* isp_port_ctrl(struct scsi_qla_host *ha)
689{
David C Somayajulud9150582006-11-15 17:38:40 -0800690 return (is_qla4010(ha) ?
691 &ha->reg->u2.isp4010.port_ctrl :
692 &ha->reg->u2.isp4022.p0.port_ctrl);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700693}
694
695static inline void __iomem* isp_port_error_status(struct scsi_qla_host *ha)
696{
David C Somayajulud9150582006-11-15 17:38:40 -0800697 return (is_qla4010(ha) ?
698 &ha->reg->u2.isp4010.port_err_status :
699 &ha->reg->u2.isp4022.p0.port_err_status);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700700}
701
702static inline void __iomem * isp_gp_out(struct scsi_qla_host *ha)
703{
David C Somayajulud9150582006-11-15 17:38:40 -0800704 return (is_qla4010(ha) ?
705 &ha->reg->u2.isp4010.gp_out :
706 &ha->reg->u2.isp4022.p0.gp_out);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700707}
708
709static inline int eeprom_ext_hw_conf_offset(struct scsi_qla_host *ha)
710{
David C Somayajulud9150582006-11-15 17:38:40 -0800711 return (is_qla4010(ha) ?
712 offsetof(struct eeprom_data, isp4010.ext_hw_conf) / 2 :
713 offsetof(struct eeprom_data, isp4022.ext_hw_conf) / 2);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700714}
715
716int ql4xxx_sem_spinlock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits);
717void ql4xxx_sem_unlock(struct scsi_qla_host * ha, u32 sem_mask);
718int ql4xxx_sem_lock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits);
719
720static inline int ql4xxx_lock_flash(struct scsi_qla_host *a)
721{
David C Somayajulud9150582006-11-15 17:38:40 -0800722 if (is_qla4010(a))
723 return ql4xxx_sem_spinlock(a, QL4010_FLASH_SEM_MASK,
724 QL4010_FLASH_SEM_BITS);
725 else
David Somayajuluafaf5a22006-09-19 10:28:00 -0700726 return ql4xxx_sem_spinlock(a, QL4022_FLASH_SEM_MASK,
727 (QL4022_RESOURCE_BITS_BASE_CODE |
728 (a->mac_index)) << 13);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700729}
730
731static inline void ql4xxx_unlock_flash(struct scsi_qla_host *a)
732{
David C Somayajulud9150582006-11-15 17:38:40 -0800733 if (is_qla4010(a))
David Somayajuluafaf5a22006-09-19 10:28:00 -0700734 ql4xxx_sem_unlock(a, QL4010_FLASH_SEM_MASK);
David C Somayajulud9150582006-11-15 17:38:40 -0800735 else
736 ql4xxx_sem_unlock(a, QL4022_FLASH_SEM_MASK);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700737}
738
739static inline int ql4xxx_lock_nvram(struct scsi_qla_host *a)
740{
David C Somayajulud9150582006-11-15 17:38:40 -0800741 if (is_qla4010(a))
742 return ql4xxx_sem_spinlock(a, QL4010_NVRAM_SEM_MASK,
743 QL4010_NVRAM_SEM_BITS);
744 else
David Somayajuluafaf5a22006-09-19 10:28:00 -0700745 return ql4xxx_sem_spinlock(a, QL4022_NVRAM_SEM_MASK,
746 (QL4022_RESOURCE_BITS_BASE_CODE |
747 (a->mac_index)) << 10);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700748}
749
750static inline void ql4xxx_unlock_nvram(struct scsi_qla_host *a)
751{
David C Somayajulud9150582006-11-15 17:38:40 -0800752 if (is_qla4010(a))
David Somayajuluafaf5a22006-09-19 10:28:00 -0700753 ql4xxx_sem_unlock(a, QL4010_NVRAM_SEM_MASK);
David C Somayajulud9150582006-11-15 17:38:40 -0800754 else
755 ql4xxx_sem_unlock(a, QL4022_NVRAM_SEM_MASK);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700756}
757
758static inline int ql4xxx_lock_drvr(struct scsi_qla_host *a)
759{
David C Somayajulud9150582006-11-15 17:38:40 -0800760 if (is_qla4010(a))
761 return ql4xxx_sem_lock(a, QL4010_DRVR_SEM_MASK,
762 QL4010_DRVR_SEM_BITS);
763 else
David Somayajuluafaf5a22006-09-19 10:28:00 -0700764 return ql4xxx_sem_lock(a, QL4022_DRVR_SEM_MASK,
765 (QL4022_RESOURCE_BITS_BASE_CODE |
766 (a->mac_index)) << 1);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700767}
768
769static inline void ql4xxx_unlock_drvr(struct scsi_qla_host *a)
770{
David C Somayajulud9150582006-11-15 17:38:40 -0800771 if (is_qla4010(a))
David Somayajuluafaf5a22006-09-19 10:28:00 -0700772 ql4xxx_sem_unlock(a, QL4010_DRVR_SEM_MASK);
David C Somayajulud9150582006-11-15 17:38:40 -0800773 else
774 ql4xxx_sem_unlock(a, QL4022_DRVR_SEM_MASK);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700775}
776
777/*---------------------------------------------------------------------------*/
778
779/* Defines for qla4xxx_initialize_adapter() and qla4xxx_recover_adapter() */
780#define PRESERVE_DDB_LIST 0
781#define REBUILD_DDB_LIST 1
782
783/* Defines for process_aen() */
784#define PROCESS_ALL_AENS 0
785#define FLUSH_DDB_CHANGED_AENS 1
786#define RELOGIN_DDB_CHANGED_AENS 2
787
David Somayajuluafaf5a22006-09-19 10:28:00 -0700788#endif /*_QLA4XXX_H */