blob: 3175709d4861c1d15155b8d6ee75d59a92fa2db9 [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
36
37#ifndef PCI_DEVICE_ID_QLOGIC_ISP4010
38#define PCI_DEVICE_ID_QLOGIC_ISP4010 0x4010
39#endif
40
41#ifndef PCI_DEVICE_ID_QLOGIC_ISP4022
42#define PCI_DEVICE_ID_QLOGIC_ISP4022 0x4022
David C Somayajulud9150582006-11-15 17:38:40 -080043#endif
44
45#ifndef PCI_DEVICE_ID_QLOGIC_ISP4032
46#define PCI_DEVICE_ID_QLOGIC_ISP4032 0x4032
47#endif
David Somayajuluafaf5a22006-09-19 10:28:00 -070048
49#define QLA_SUCCESS 0
50#define QLA_ERROR 1
51
52/*
53 * Data bit definitions
54 */
55#define BIT_0 0x1
56#define BIT_1 0x2
57#define BIT_2 0x4
58#define BIT_3 0x8
59#define BIT_4 0x10
60#define BIT_5 0x20
61#define BIT_6 0x40
62#define BIT_7 0x80
63#define BIT_8 0x100
64#define BIT_9 0x200
65#define BIT_10 0x400
66#define BIT_11 0x800
67#define BIT_12 0x1000
68#define BIT_13 0x2000
69#define BIT_14 0x4000
70#define BIT_15 0x8000
71#define BIT_16 0x10000
72#define BIT_17 0x20000
73#define BIT_18 0x40000
74#define BIT_19 0x80000
75#define BIT_20 0x100000
76#define BIT_21 0x200000
77#define BIT_22 0x400000
78#define BIT_23 0x800000
79#define BIT_24 0x1000000
80#define BIT_25 0x2000000
81#define BIT_26 0x4000000
82#define BIT_27 0x8000000
83#define BIT_28 0x10000000
84#define BIT_29 0x20000000
85#define BIT_30 0x40000000
86#define BIT_31 0x80000000
87
88/*
89 * Host adapter default definitions
90 ***********************************/
91#define MAX_HBAS 16
92#define MAX_BUSES 1
93#define MAX_TARGETS (MAX_PRST_DEV_DB_ENTRIES + MAX_DEV_DB_ENTRIES)
94#define MAX_LUNS 0xffff
95#define MAX_AEN_ENTRIES 256 /* should be > EXT_DEF_MAX_AEN_QUEUE */
96#define MAX_DDB_ENTRIES (MAX_PRST_DEV_DB_ENTRIES + MAX_DEV_DB_ENTRIES)
97#define MAX_PDU_ENTRIES 32
98#define INVALID_ENTRY 0xFFFF
99#define MAX_CMDS_TO_RISC 1024
100#define MAX_SRBS MAX_CMDS_TO_RISC
101#define MBOX_AEN_REG_COUNT 5
102#define MAX_INIT_RETRIES 5
David Somayajuluafaf5a22006-09-19 10:28:00 -0700103
104/*
105 * Buffer sizes
106 */
107#define REQUEST_QUEUE_DEPTH MAX_CMDS_TO_RISC
108#define RESPONSE_QUEUE_DEPTH 64
109#define QUEUE_SIZE 64
110#define DMA_BUFFER_SIZE 512
111
112/*
113 * Misc
114 */
115#define MAC_ADDR_LEN 6 /* in bytes */
116#define IP_ADDR_LEN 4 /* in bytes */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530117#define IPv6_ADDR_LEN 16 /* IPv6 address size */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700118#define DRIVER_NAME "qla4xxx"
119
120#define MAX_LINKED_CMDS_PER_LUN 3
121#define MAX_REQS_SERVICED_PER_INTR 16
122
123#define ISCSI_IPADDR_SIZE 4 /* IP address size */
Joe Perchesb1c11812008-02-03 17:28:22 +0200124#define ISCSI_ALIAS_SIZE 32 /* ISCSI Alias name size */
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700125#define ISCSI_NAME_SIZE 0xE0 /* ISCSI Name size */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700126
127#define LSDW(x) ((u32)((u64)(x)))
128#define MSDW(x) ((u32)((((u64)(x)) >> 16) >> 16))
129
130/*
131 * Retry & Timeout Values
132 */
133#define MBOX_TOV 60
134#define SOFT_RESET_TOV 30
135#define RESET_INTR_TOV 3
136#define SEMAPHORE_TOV 10
137#define ADAPTER_INIT_TOV 120
138#define ADAPTER_RESET_TOV 180
139#define EXTEND_CMD_TOV 60
140#define WAIT_CMD_TOV 30
141#define EH_WAIT_CMD_TOV 120
142#define FIRMWARE_UP_TOV 60
143#define RESET_FIRMWARE_TOV 30
144#define LOGOUT_TOV 10
145#define IOCB_TOV_MARGIN 10
146#define RELOGIN_TOV 18
147#define ISNS_DEREG_TOV 5
148
149#define MAX_RESET_HA_RETRIES 2
150
151/*
152 * SCSI Request Block structure (srb) that is placed
153 * on cmd->SCp location of every I/O [We have 22 bytes available]
154 */
155struct srb {
156 struct list_head list; /* (8) */
157 struct scsi_qla_host *ha; /* HA the SP is queued on */
158 struct ddb_entry *ddb;
159 uint16_t flags; /* (1) Status flags. */
160
161#define SRB_DMA_VALID BIT_3 /* DMA Buffer mapped. */
162#define SRB_GOT_SENSE BIT_4 /* sense data recieved. */
163 uint8_t state; /* (1) Status flags. */
164
165#define SRB_NO_QUEUE_STATE 0 /* Request is in between states */
166#define SRB_FREE_STATE 1
167#define SRB_ACTIVE_STATE 3
168#define SRB_ACTIVE_TIMEOUT_STATE 4
169#define SRB_SUSPENDED_STATE 7 /* Request in suspended state */
170
171 struct scsi_cmnd *cmd; /* (4) SCSI command block */
172 dma_addr_t dma_handle; /* (4) for unmap of single transfers */
173 atomic_t ref_count; /* reference count for this srb */
174 uint32_t fw_ddb_index;
175 uint8_t err_id; /* error id */
176#define SRB_ERR_PORT 1 /* Request failed because "port down" */
177#define SRB_ERR_LOOP 2 /* Request failed because "loop down" */
178#define SRB_ERR_DEVICE 3 /* Request failed because "device error" */
179#define SRB_ERR_OTHER 4
180
181 uint16_t reserved;
182 uint16_t iocb_tov;
183 uint16_t iocb_cnt; /* Number of used iocbs */
184 uint16_t cc_stat;
185 u_long r_start; /* Time we recieve a cmd from OS */
186 u_long u_start; /* Time when we handed the cmd to F/W */
Karen Higgins94bced32009-07-15 15:02:58 -0500187
188 /* Used for extended sense / status continuation */
189 uint8_t *req_sense_ptr;
190 uint16_t req_sense_len;
191 uint16_t reserved2;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700192};
193
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700194/*
195 * Asynchronous Event Queue structure
196 */
197struct aen {
198 uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
199};
200
201struct ql4_aen_log {
202 int count;
203 struct aen entry[MAX_AEN_ENTRIES];
204};
205
206/*
207 * Device Database (DDB) structure
208 */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700209struct ddb_entry {
210 struct list_head list; /* ddb list */
211 struct scsi_qla_host *ha;
212 struct iscsi_cls_session *sess;
213 struct iscsi_cls_conn *conn;
214
215 atomic_t state; /* DDB State */
216
217 unsigned long flags; /* DDB Flags */
218
219 unsigned long dev_scan_wait_to_start_relogin;
220 unsigned long dev_scan_wait_to_complete_relogin;
221
222 uint16_t os_target_id; /* Target ID */
223 uint16_t fw_ddb_index; /* DDB firmware index */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530224 uint16_t options;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700225 uint32_t fw_ddb_device_state; /* F/W Device State -- see ql4_fw.h */
226
227 uint32_t CmdSn;
228 uint16_t target_session_id;
229 uint16_t connection_id;
230 uint16_t exe_throttle; /* Max mumber of cmds outstanding
231 * simultaneously */
232 uint16_t task_mgmt_timeout; /* Min time for task mgmt cmds to
233 * complete */
234 uint16_t default_relogin_timeout; /* Max time to wait for
235 * relogin to complete */
236 uint16_t tcp_source_port_num;
237 uint32_t default_time2wait; /* Default Min time between
238 * relogins (+aens) */
239
240 atomic_t port_down_timer; /* Device connection timer */
241 atomic_t retry_relogin_timer; /* Min Time between relogins
242 * (4000 only) */
243 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
244 atomic_t relogin_retry_count; /* Num of times relogin has been
245 * retried */
246
247 uint16_t port;
248 uint32_t tpgt;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530249 uint8_t ip_addr[IP_ADDR_LEN];
David Somayajuluafaf5a22006-09-19 10:28:00 -0700250 uint8_t iscsi_name[ISCSI_NAME_SIZE]; /* 72 x48 */
251 uint8_t iscsi_alias[0x20];
Mike Christie41bbdbe2009-01-16 12:36:52 -0600252 uint8_t isid[6];
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530253 uint16_t iscsi_max_burst_len;
254 uint16_t iscsi_max_outsnd_r2t;
255 uint16_t iscsi_first_burst_len;
256 uint16_t iscsi_max_rcv_data_seg_len;
257 uint16_t iscsi_max_snd_data_seg_len;
258
259 struct in6_addr remote_ipv6_addr;
260 struct in6_addr link_local_ipv6_addr;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700261};
262
263/*
264 * DDB states.
265 */
266#define DDB_STATE_DEAD 0 /* We can no longer talk to
267 * this device */
268#define DDB_STATE_ONLINE 1 /* Device ready to accept
269 * commands */
270#define DDB_STATE_MISSING 2 /* Device logged off, trying
271 * to re-login */
272
273/*
274 * DDB flags.
275 */
276#define DF_RELOGIN 0 /* Relogin to device */
277#define DF_NO_RELOGIN 1 /* Do not relogin if IOCTL
278 * logged it out */
279#define DF_ISNS_DISCOVERED 2 /* Device was discovered via iSNS */
280#define DF_FO_MASKED 3
281
David Somayajuluafaf5a22006-09-19 10:28:00 -0700282
283#include "ql4_fw.h"
284#include "ql4_nvram.h"
285
286/*
287 * Linux Host Adapter structure
288 */
289struct scsi_qla_host {
290 /* Linux adapter configuration data */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700291 unsigned long flags;
292
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700293#define AF_ONLINE 0 /* 0x00000001 */
294#define AF_INIT_DONE 1 /* 0x00000002 */
295#define AF_MBOX_COMMAND 2 /* 0x00000004 */
296#define AF_MBOX_COMMAND_DONE 3 /* 0x00000008 */
297#define AF_INTERRUPTS_ON 6 /* 0x00000040 */
298#define AF_GET_CRASH_RECORD 7 /* 0x00000080 */
299#define AF_LINK_UP 8 /* 0x00000100 */
300#define AF_IRQ_ATTACHED 10 /* 0x00000400 */
301#define AF_DISABLE_ACB_COMPLETE 11 /* 0x00000800 */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700302
303 unsigned long dpc_flags;
304
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700305#define DPC_RESET_HA 1 /* 0x00000002 */
306#define DPC_RETRY_RESET_HA 2 /* 0x00000004 */
307#define DPC_RELOGIN_DEVICE 3 /* 0x00000008 */
308#define DPC_RESET_HA_DESTROY_DDB_LIST 4 /* 0x00000010 */
309#define DPC_RESET_HA_INTR 5 /* 0x00000020 */
310#define DPC_ISNS_RESTART 7 /* 0x00000080 */
311#define DPC_AEN 9 /* 0x00000200 */
312#define DPC_GET_DHCP_IP_ADDR 15 /* 0x00008000 */
313
314 struct Scsi_Host *host; /* pointer to host data */
315 uint32_t tot_ddbs;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700316
317 uint16_t iocb_cnt;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700318
319 /* SRB cache. */
320#define SRB_MIN_REQ 128
321 mempool_t *srb_mempool;
322
323 /* pci information */
324 struct pci_dev *pdev;
325
326 struct isp_reg __iomem *reg; /* Base I/O address */
327 unsigned long pio_address;
328 unsigned long pio_length;
329#define MIN_IOBASE_LEN 0x100
330
331 uint16_t req_q_count;
332 uint8_t marker_needed;
333 uint8_t rsvd1;
334
335 unsigned long host_no;
336
337 /* NVRAM registers */
338 struct eeprom_data *nvram;
339 spinlock_t hardware_lock ____cacheline_aligned;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700340 uint32_t eeprom_cmd_data;
341
342 /* Counters for general statistics */
David C Somayajulud9150582006-11-15 17:38:40 -0800343 uint64_t isr_count;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700344 uint64_t adapter_error_count;
345 uint64_t device_error_count;
346 uint64_t total_io_count;
347 uint64_t total_mbytes_xferred;
348 uint64_t link_failure_count;
349 uint64_t invalid_crc_count;
David C Somayajulud9150582006-11-15 17:38:40 -0800350 uint32_t bytes_xfered;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700351 uint32_t spurious_int_count;
352 uint32_t aborted_io_count;
353 uint32_t io_timeout_count;
354 uint32_t mailbox_timeout_count;
355 uint32_t seconds_since_last_intr;
356 uint32_t seconds_since_last_heartbeat;
357 uint32_t mac_index;
358
359 /* Info Needed for Management App */
360 /* --- From GetFwVersion --- */
361 uint32_t firmware_version[2];
362 uint32_t patch_number;
363 uint32_t build_number;
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700364 uint32_t board_id;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700365
366 /* --- From Init_FW --- */
367 /* init_cb_t *init_cb; */
368 uint16_t firmware_options;
369 uint16_t tcp_options;
370 uint8_t ip_address[IP_ADDR_LEN];
371 uint8_t subnet_mask[IP_ADDR_LEN];
372 uint8_t gateway[IP_ADDR_LEN];
373 uint8_t alias[32];
374 uint8_t name_string[256];
375 uint8_t heartbeat_interval;
376 uint8_t rsvd;
377
378 /* --- From FlashSysInfo --- */
379 uint8_t my_mac[MAC_ADDR_LEN];
380 uint8_t serial_number[16];
381
382 /* --- From GetFwState --- */
383 uint32_t firmware_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700384 uint32_t addl_fw_state;
385
386 /* Linux kernel thread */
387 struct workqueue_struct *dpc_thread;
388 struct work_struct dpc_work;
389
390 /* Linux timer thread */
391 struct timer_list timer;
392 uint32_t timer_active;
393
394 /* Recovery Timers */
395 uint32_t port_down_retry_count;
396 uint32_t discovery_wait;
397 atomic_t check_relogin_timeouts;
398 uint32_t retry_reset_ha_cnt;
399 uint32_t isp_reset_timer; /* reset test timer */
400 uint32_t nic_reset_timer; /* simulated nic reset test timer */
401 int eh_start;
402 struct list_head free_srb_q;
403 uint16_t free_srb_q_count;
404 uint16_t num_srbs_allocated;
405
406 /* DMA Memory Block */
407 void *queues;
408 dma_addr_t queues_dma;
409 unsigned long queues_len;
410
411#define MEM_ALIGN_VALUE \
412 ((max(REQUEST_QUEUE_DEPTH, RESPONSE_QUEUE_DEPTH)) * \
413 sizeof(struct queue_entry))
414 /* request and response queue variables */
415 dma_addr_t request_dma;
416 struct queue_entry *request_ring;
417 struct queue_entry *request_ptr;
418 dma_addr_t response_dma;
419 struct queue_entry *response_ring;
420 struct queue_entry *response_ptr;
421 dma_addr_t shadow_regs_dma;
422 struct shadow_regs *shadow_regs;
423 uint16_t request_in; /* Current indexes. */
424 uint16_t request_out;
425 uint16_t response_in;
426 uint16_t response_out;
427
428 /* aen queue variables */
429 uint16_t aen_q_count; /* Number of available aen_q entries */
430 uint16_t aen_in; /* Current indexes */
431 uint16_t aen_out;
432 struct aen aen_q[MAX_AEN_ENTRIES];
433
David C Somayajulu5c8bfc92007-05-23 17:50:55 -0700434 struct ql4_aen_log aen_log;/* tracks all aens */
435
David Somayajuluafaf5a22006-09-19 10:28:00 -0700436 /* This mutex protects several threads to do mailbox commands
437 * concurrently.
438 */
439 struct mutex mbox_sem;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700440
441 /* temporary mailbox status registers */
442 volatile uint8_t mbox_status_count;
443 volatile uint32_t mbox_status[MBOX_REG_COUNT];
444
445 /* local device database list (contains internal ddb entries) */
446 struct list_head ddb_list;
447
448 /* Map ddb_list entry by FW ddb index */
449 struct ddb_entry *fw_ddb_index_map[MAX_DDB_ENTRIES];
450
Karen Higgins94bced32009-07-15 15:02:58 -0500451 /* Saved srb for status continuation entry processing */
452 struct srb *status_srb;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530453
454 /* IPv6 support info from InitFW */
455 uint8_t acb_version;
456 uint8_t ipv4_addr_state;
457 uint16_t ipv4_options;
458
459 uint32_t resvd2;
460 uint32_t ipv6_options;
461 uint32_t ipv6_addl_options;
462 uint8_t ipv6_link_local_state;
463 uint8_t ipv6_addr0_state;
464 uint8_t ipv6_addr1_state;
465 uint8_t ipv6_default_router_state;
466 struct in6_addr ipv6_link_local_addr;
467 struct in6_addr ipv6_addr0;
468 struct in6_addr ipv6_addr1;
469 struct in6_addr ipv6_default_router_addr;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700470};
471
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530472static inline int is_ipv4_enabled(struct scsi_qla_host *ha)
473{
474 return ((ha->ipv4_options & IPOPT_IPv4_PROTOCOL_ENABLE) != 0);
475}
476
477static inline int is_ipv6_enabled(struct scsi_qla_host *ha)
478{
479 return ((ha->ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE) != 0);
480}
481
David Somayajuluafaf5a22006-09-19 10:28:00 -0700482static inline int is_qla4010(struct scsi_qla_host *ha)
483{
484 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4010;
485}
486
487static inline int is_qla4022(struct scsi_qla_host *ha)
488{
489 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4022;
490}
491
David C Somayajulud9150582006-11-15 17:38:40 -0800492static inline int is_qla4032(struct scsi_qla_host *ha)
493{
494 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP4032;
495}
496
David Somayajuluafaf5a22006-09-19 10:28:00 -0700497static inline int adapter_up(struct scsi_qla_host *ha)
498{
499 return (test_bit(AF_ONLINE, &ha->flags) != 0) &&
500 (test_bit(AF_LINK_UP, &ha->flags) != 0);
501}
502
503static inline struct scsi_qla_host* to_qla_host(struct Scsi_Host *shost)
504{
505 return (struct scsi_qla_host *)shost->hostdata;
506}
507
508static inline void __iomem* isp_semaphore(struct scsi_qla_host *ha)
509{
David C Somayajulud9150582006-11-15 17:38:40 -0800510 return (is_qla4010(ha) ?
511 &ha->reg->u1.isp4010.nvram :
512 &ha->reg->u1.isp4022.semaphore);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700513}
514
515static inline void __iomem* isp_nvram(struct scsi_qla_host *ha)
516{
David C Somayajulud9150582006-11-15 17:38:40 -0800517 return (is_qla4010(ha) ?
518 &ha->reg->u1.isp4010.nvram :
519 &ha->reg->u1.isp4022.nvram);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700520}
521
522static inline void __iomem* isp_ext_hw_conf(struct scsi_qla_host *ha)
523{
David C Somayajulud9150582006-11-15 17:38:40 -0800524 return (is_qla4010(ha) ?
525 &ha->reg->u2.isp4010.ext_hw_conf :
526 &ha->reg->u2.isp4022.p0.ext_hw_conf);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700527}
528
529static inline void __iomem* isp_port_status(struct scsi_qla_host *ha)
530{
David C Somayajulud9150582006-11-15 17:38:40 -0800531 return (is_qla4010(ha) ?
532 &ha->reg->u2.isp4010.port_status :
533 &ha->reg->u2.isp4022.p0.port_status);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700534}
535
536static inline void __iomem* isp_port_ctrl(struct scsi_qla_host *ha)
537{
David C Somayajulud9150582006-11-15 17:38:40 -0800538 return (is_qla4010(ha) ?
539 &ha->reg->u2.isp4010.port_ctrl :
540 &ha->reg->u2.isp4022.p0.port_ctrl);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700541}
542
543static inline void __iomem* isp_port_error_status(struct scsi_qla_host *ha)
544{
David C Somayajulud9150582006-11-15 17:38:40 -0800545 return (is_qla4010(ha) ?
546 &ha->reg->u2.isp4010.port_err_status :
547 &ha->reg->u2.isp4022.p0.port_err_status);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700548}
549
550static inline void __iomem * isp_gp_out(struct scsi_qla_host *ha)
551{
David C Somayajulud9150582006-11-15 17:38:40 -0800552 return (is_qla4010(ha) ?
553 &ha->reg->u2.isp4010.gp_out :
554 &ha->reg->u2.isp4022.p0.gp_out);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700555}
556
557static inline int eeprom_ext_hw_conf_offset(struct scsi_qla_host *ha)
558{
David C Somayajulud9150582006-11-15 17:38:40 -0800559 return (is_qla4010(ha) ?
560 offsetof(struct eeprom_data, isp4010.ext_hw_conf) / 2 :
561 offsetof(struct eeprom_data, isp4022.ext_hw_conf) / 2);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700562}
563
564int ql4xxx_sem_spinlock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits);
565void ql4xxx_sem_unlock(struct scsi_qla_host * ha, u32 sem_mask);
566int ql4xxx_sem_lock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits);
567
568static inline int ql4xxx_lock_flash(struct scsi_qla_host *a)
569{
David C Somayajulud9150582006-11-15 17:38:40 -0800570 if (is_qla4010(a))
571 return ql4xxx_sem_spinlock(a, QL4010_FLASH_SEM_MASK,
572 QL4010_FLASH_SEM_BITS);
573 else
David Somayajuluafaf5a22006-09-19 10:28:00 -0700574 return ql4xxx_sem_spinlock(a, QL4022_FLASH_SEM_MASK,
575 (QL4022_RESOURCE_BITS_BASE_CODE |
576 (a->mac_index)) << 13);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700577}
578
579static inline void ql4xxx_unlock_flash(struct scsi_qla_host *a)
580{
David C Somayajulud9150582006-11-15 17:38:40 -0800581 if (is_qla4010(a))
David Somayajuluafaf5a22006-09-19 10:28:00 -0700582 ql4xxx_sem_unlock(a, QL4010_FLASH_SEM_MASK);
David C Somayajulud9150582006-11-15 17:38:40 -0800583 else
584 ql4xxx_sem_unlock(a, QL4022_FLASH_SEM_MASK);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700585}
586
587static inline int ql4xxx_lock_nvram(struct scsi_qla_host *a)
588{
David C Somayajulud9150582006-11-15 17:38:40 -0800589 if (is_qla4010(a))
590 return ql4xxx_sem_spinlock(a, QL4010_NVRAM_SEM_MASK,
591 QL4010_NVRAM_SEM_BITS);
592 else
David Somayajuluafaf5a22006-09-19 10:28:00 -0700593 return ql4xxx_sem_spinlock(a, QL4022_NVRAM_SEM_MASK,
594 (QL4022_RESOURCE_BITS_BASE_CODE |
595 (a->mac_index)) << 10);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700596}
597
598static inline void ql4xxx_unlock_nvram(struct scsi_qla_host *a)
599{
David C Somayajulud9150582006-11-15 17:38:40 -0800600 if (is_qla4010(a))
David Somayajuluafaf5a22006-09-19 10:28:00 -0700601 ql4xxx_sem_unlock(a, QL4010_NVRAM_SEM_MASK);
David C Somayajulud9150582006-11-15 17:38:40 -0800602 else
603 ql4xxx_sem_unlock(a, QL4022_NVRAM_SEM_MASK);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700604}
605
606static inline int ql4xxx_lock_drvr(struct scsi_qla_host *a)
607{
David C Somayajulud9150582006-11-15 17:38:40 -0800608 if (is_qla4010(a))
609 return ql4xxx_sem_lock(a, QL4010_DRVR_SEM_MASK,
610 QL4010_DRVR_SEM_BITS);
611 else
David Somayajuluafaf5a22006-09-19 10:28:00 -0700612 return ql4xxx_sem_lock(a, QL4022_DRVR_SEM_MASK,
613 (QL4022_RESOURCE_BITS_BASE_CODE |
614 (a->mac_index)) << 1);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700615}
616
617static inline void ql4xxx_unlock_drvr(struct scsi_qla_host *a)
618{
David C Somayajulud9150582006-11-15 17:38:40 -0800619 if (is_qla4010(a))
David Somayajuluafaf5a22006-09-19 10:28:00 -0700620 ql4xxx_sem_unlock(a, QL4010_DRVR_SEM_MASK);
David C Somayajulud9150582006-11-15 17:38:40 -0800621 else
622 ql4xxx_sem_unlock(a, QL4022_DRVR_SEM_MASK);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700623}
624
625/*---------------------------------------------------------------------------*/
626
627/* Defines for qla4xxx_initialize_adapter() and qla4xxx_recover_adapter() */
628#define PRESERVE_DDB_LIST 0
629#define REBUILD_DDB_LIST 1
630
631/* Defines for process_aen() */
632#define PROCESS_ALL_AENS 0
633#define FLUSH_DDB_CHANGED_AENS 1
634#define RELOGIN_DDB_CHANGED_AENS 2
635
David Somayajuluafaf5a22006-09-19 10:28:00 -0700636#endif /*_QLA4XXX_H */