1 /******************************************************************************
2 * QLOGIC LINUX SOFTWARE
4 * QLogic QLA1280 (Ultra2) and QLA12160 (Ultra3) SCSI driver
5 * Copyright (C) 2000 Qlogic Corporation (www.qlogic.com)
6 * Copyright (C) 2001-2004 Jes Sorensen, Wild Open Source Inc.
7 * Copyright (C) 2003-2004 Christoph Hellwig
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 ******************************************************************************/
20 #define QLA1280_VERSION "3.26"
21 /*****************************************************************************
23 Rev 3.26, January 16, 2006 Jes Sorensen
24 - Ditch all < 2.6 support
25 Rev 3.25.1, February 10, 2005 Christoph Hellwig
26 - use pci_map_single to map non-S/G requests
27 - remove qla1280_proc_info
28 Rev 3.25, September 28, 2004, Christoph Hellwig
29 - add support for ISP1020/1040
30 - don't include "scsi.h" anymore for 2.6.x
31 Rev 3.24.4 June 7, 2004 Christoph Hellwig
32 - restructure firmware loading, cleanup initialization code
33 - prepare support for ISP1020/1040 chips
34 Rev 3.24.3 January 19, 2004, Jes Sorensen
35 - Handle PCI DMA mask settings correctly
36 - Correct order of error handling in probe_one, free_irq should not
37 be called if request_irq failed
38 Rev 3.24.2 January 19, 2004, James Bottomley & Andrew Vasquez
39 - Big endian fixes (James)
40 - Remove bogus IOCB content on zero data transfer commands (Andrew)
41 Rev 3.24.1 January 5, 2004, Jes Sorensen
42 - Initialize completion queue to avoid OOPS on probe
43 - Handle interrupts during mailbox testing
44 Rev 3.24 November 17, 2003, Christoph Hellwig
45 - use struct list_head for completion queue
46 - avoid old Scsi_FOO typedefs
47 - cleanup 2.4 compat glue a bit
48 - use <scsi/scsi_*.h> headers on 2.6 instead of "scsi.h"
49 - make initialization for memory mapped vs port I/O more similar
50 - remove broken pci config space manipulation
52 - this is an almost perfect 2.6 scsi driver now! ;)
53 Rev 3.23.39 December 17, 2003, Jes Sorensen
54 - Delete completion queue from srb if mailbox command failed to
55 to avoid qla1280_done completeting qla1280_error_action's
57 - Reduce arguments for qla1280_done
58 Rev 3.23.38 October 18, 2003, Christoph Hellwig
59 - Convert to new-style hotplugable driver for 2.6
60 - Fix missing scsi_unregister/scsi_host_put on HBA removal
61 - Kill some more cruft
62 Rev 3.23.37 October 1, 2003, Jes Sorensen
63 - Make MMIO depend on CONFIG_X86_VISWS instead of yet another
65 - Clean up locking in probe path
66 Rev 3.23.36 October 1, 2003, Christoph Hellwig
67 - queuecommand only ever receives new commands - clear flags
68 - Reintegrate lost fixes from Linux 2.5
69 Rev 3.23.35 August 14, 2003, Jes Sorensen
71 Rev 3.23.34 July 23, 2003, Jes Sorensen
72 - Remove pointless TRUE/FALSE macros
73 - Clean up vchan handling
74 Rev 3.23.33 July 3, 2003, Jes Sorensen
75 - Don't define register access macros before define determining MMIO.
76 This just happend to work out on ia64 but not elsewhere.
77 - Don't try and read from the card while it is in reset as
78 it won't respond and causes an MCA
79 Rev 3.23.32 June 23, 2003, Jes Sorensen
80 - Basic support for boot time arguments
81 Rev 3.23.31 June 8, 2003, Jes Sorensen
82 - Reduce boot time messages
83 Rev 3.23.30 June 6, 2003, Jes Sorensen
84 - Do not enable sync/wide/ppr before it has been determined
85 that the target device actually supports it
86 - Enable DMA arbitration for multi channel controllers
87 Rev 3.23.29 June 3, 2003, Jes Sorensen
89 Rev 3.23.28 June 3, 2003, Jes Sorensen
90 - Eliminate duplicate marker commands on bus resets
91 - Handle outstanding commands appropriately on bus/device resets
92 Rev 3.23.27 May 28, 2003, Jes Sorensen
93 - Remove bogus input queue code, let the Linux SCSI layer do the work
94 - Clean up NVRAM handling, only read it once from the card
95 - Add a number of missing default nvram parameters
96 Rev 3.23.26 Beta May 28, 2003, Jes Sorensen
97 - Use completion queue for mailbox commands instead of busy wait
98 Rev 3.23.25 Beta May 27, 2003, James Bottomley
99 - Migrate to use new error handling code
100 Rev 3.23.24 Beta May 21, 2003, James Bottomley
102 - Cleanup data direction code
103 Rev 3.23.23 Beta May 12, 2003, Jes Sorensen
104 - Switch to using MMIO instead of PIO
105 Rev 3.23.22 Beta April 15, 2003, Jes Sorensen
106 - Fix PCI parity problem with 12160 during reset.
107 Rev 3.23.21 Beta April 14, 2003, Jes Sorensen
108 - Use pci_map_page()/pci_unmap_page() instead of map_single version.
109 Rev 3.23.20 Beta April 9, 2003, Jes Sorensen
110 - Remove < 2.4.x support
111 - Introduce HOST_LOCK to make the spin lock changes portable.
112 - Remove a bunch of idiotic and unnecessary typedef's
113 - Kill all leftovers of target-mode support which never worked anyway
114 Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
115 - Do qla1280_pci_config() before calling request_irq() and
117 - Use pci_dma_hi32() to handle upper word of DMA addresses instead
119 - Hand correct arguments to free_irq() in case of failure
120 Rev 3.23.18 Beta April 11, 2002, Jes Sorensen
121 - Run source through Lindent and clean up the output
122 Rev 3.23.17 Beta April 11, 2002, Jes Sorensen
123 - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32
124 Rev 3.23.16 Beta March 19, 2002, Jes Sorensen
125 - Rely on mailbox commands generating interrupts - do not
126 run qla1280_isr() from ql1280_mailbox_command()
127 - Remove device_reg_t
128 - Integrate ql12160_set_target_parameters() with 1280 version
129 - Make qla1280_setup() non static
130 - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request
131 sent to the card - this command pauses the firmare!!!
132 Rev 3.23.15 Beta March 19, 2002, Jes Sorensen
133 - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions
134 - Remove a pile of pointless and confusing (srb_t **) and
135 (scsi_lu_t *) typecasts
136 - Explicit mark that we do not use the new error handling (for now)
137 - Remove scsi_qla_host_t and use 'struct' instead
138 - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled,
139 pci_64bit_slot flags which weren't used for anything anyway
140 - Grab host->host_lock while calling qla1280_isr() from abort()
141 - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we
142 do not need to save/restore flags in the interrupt handler
143 - Enable interrupts early (before any mailbox access) in preparation
144 for cleaning up the mailbox handling
145 Rev 3.23.14 Beta March 14, 2002, Jes Sorensen
146 - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace
147 it with proper use of dprintk().
148 - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take
149 a debug level argument to determine if data is to be printed
150 - Add KERN_* info to printk()
151 Rev 3.23.13 Beta March 14, 2002, Jes Sorensen
152 - Significant cosmetic cleanups
153 - Change debug code to use dprintk() and remove #if mess
154 Rev 3.23.12 Beta March 13, 2002, Jes Sorensen
155 - More cosmetic cleanups, fix places treating return as function
156 - use cpu_relax() in qla1280_debounce_register()
157 Rev 3.23.11 Beta March 13, 2002, Jes Sorensen
158 - Make it compile under 2.5.5
159 Rev 3.23.10 Beta October 1, 2001, Jes Sorensen
160 - Do no typecast short * to long * in QL1280BoardTbl, this
161 broke miserably on big endian boxes
162 Rev 3.23.9 Beta September 30, 2001, Jes Sorensen
163 - Remove pre 2.2 hack for checking for reentrance in interrupt handler
164 - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32
165 unsigned int to match the types from struct scsi_cmnd
166 Rev 3.23.8 Beta September 29, 2001, Jes Sorensen
167 - Remove bogus timer_t typedef from qla1280.h
168 - Remove obsolete pre 2.2 PCI setup code, use proper #define's
169 for PCI_ values, call pci_set_master()
170 - Fix memleak of qla1280_buffer on module unload
171 - Only compile module parsing code #ifdef MODULE - should be
172 changed to use individual MODULE_PARM's later
173 - Remove dummy_buffer that was never modified nor printed
174 - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove
175 #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls
176 - Remove \r from print statements, this is Linux, not DOS
177 - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK}
179 - Remove C++ compile hack in header file as Linux driver are not
180 supposed to be compiled as C++
181 - Kill MS_64BITS macro as it makes the code more readable
182 - Remove unnecessary flags.in_interrupts bit
183 Rev 3.23.7 Beta August 20, 2001, Jes Sorensen
184 - Dont' check for set flags on q->q_flag one by one in qla1280_next()
185 - Check whether the interrupt was generated by the QLA1280 before
187 - qla1280_status_entry(): Only zero out part of sense_buffer that
188 is not being copied into
189 - Remove more superflouous typecasts
190 - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy()
191 Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel
192 - Don't walk the entire list in qla1280_putq_t() just to directly
193 grab the pointer to the last element afterwards
194 Rev 3.23.5 Beta August 9, 2001, Jes Sorensen
195 - Don't use SA_INTERRUPT, it's use is deprecated for this kinda driver
196 Rev 3.23.4 Beta August 8, 2001, Jes Sorensen
197 - Set dev->max_sectors to 1024
198 Rev 3.23.3 Beta August 6, 2001, Jes Sorensen
199 - Provide compat macros for pci_enable_device(), pci_find_subsys()
200 and scsi_set_pci_device()
201 - Call scsi_set_pci_device() for all devices
202 - Reduce size of kernel version dependent device probe code
203 - Move duplicate probe/init code to separate function
204 - Handle error if qla1280_mem_alloc() fails
205 - Kill OFFSET() macro and use Linux's PCI definitions instead
206 - Kill private structure defining PCI config space (struct config_reg)
207 - Only allocate I/O port region if not in MMIO mode
208 - Remove duplicate (unused) sanity check of sife of srb_t
209 Rev 3.23.2 Beta August 6, 2001, Jes Sorensen
210 - Change home-brew memset() implementations to use memset()
211 - Remove all references to COMTRACE() - accessing a PC's COM2 serial
212 port directly is not legal under Linux.
213 Rev 3.23.1 Beta April 24, 2001, Jes Sorensen
214 - Remove pre 2.2 kernel support
215 - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat)
216 - Fix MMIO access to use readl/writel instead of directly
217 dereferencing pointers
218 - Nuke MSDOS debugging code
219 - Change true/false data types to int from uint8_t
220 - Use int for counters instead of uint8_t etc.
221 - Clean up size & byte order conversion macro usage
222 Rev 3.23 Beta January 11, 2001 BN Qlogic
223 - Added check of device_id when handling non
224 QLA12160s during detect().
225 Rev 3.22 Beta January 5, 2001 BN Qlogic
226 - Changed queue_task() to schedule_task()
227 for kernels 2.4.0 and higher.
228 Note: 2.4.0-testxx kernels released prior to
229 the actual 2.4.0 kernel release on January 2001
230 will get compile/link errors with schedule_task().
231 Please update your kernel to released 2.4.0 level,
232 or comment lines in this file flagged with 3.22
233 to resolve compile/link error of schedule_task().
234 - Added -DCONFIG_SMP in addition to -D__SMP__
235 in Makefile for 2.4.0 builds of driver as module.
236 Rev 3.21 Beta January 4, 2001 BN Qlogic
237 - Changed criteria of 64/32 Bit mode of HBA
238 operation according to BITS_PER_LONG rather
239 than HBA's NVRAM setting of >4Gig memory bit;
240 so that the HBA auto-configures without the need
241 to setup each system individually.
242 Rev 3.20 Beta December 5, 2000 BN Qlogic
243 - Added priority handling to IA-64 onboard SCSI
244 ISP12160 chip for kernels greater than 2.3.18.
245 - Added irqrestore for qla1280_intr_handler.
246 - Enabled /proc/scsi/qla1280 interface.
247 - Clear /proc/scsi/qla1280 counters in detect().
248 Rev 3.19 Beta October 13, 2000 BN Qlogic
249 - Declare driver_template for new kernel
250 (2.4.0 and greater) scsi initialization scheme.
251 - Update /proc/scsi entry for 2.3.18 kernels and
253 Rev 3.18 Beta October 10, 2000 BN Qlogic
254 - Changed scan order of adapters to map
255 the QLA12160 followed by the QLA1280.
256 Rev 3.17 Beta September 18, 2000 BN Qlogic
257 - Removed warnings for 32 bit 2.4.x compiles
258 - Corrected declared size for request and response
259 DMA addresses that are kept in each ha
260 Rev. 3.16 Beta August 25, 2000 BN Qlogic
261 - Corrected 64 bit addressing issue on IA-64
262 where the upper 32 bits were not properly
263 passed to the RISC engine.
264 Rev. 3.15 Beta August 22, 2000 BN Qlogic
265 - Modified qla1280_setup_chip to properly load
266 ISP firmware for greater that 4 Gig memory on IA-64
267 Rev. 3.14 Beta August 16, 2000 BN Qlogic
268 - Added setting of dma_mask to full 64 bit
269 if flags.enable_64bit_addressing is set in NVRAM
270 Rev. 3.13 Beta August 16, 2000 BN Qlogic
271 - Use new PCI DMA mapping APIs for 2.4.x kernel
272 Rev. 3.12 July 18, 2000 Redhat & BN Qlogic
273 - Added check of pci_enable_device to detect() for 2.3.x
274 - Use pci_resource_start() instead of
275 pdev->resource[0].start in detect() for 2.3.x
276 - Updated driver version
277 Rev. 3.11 July 14, 2000 BN Qlogic
278 - Updated SCSI Firmware to following versions:
281 - Updated driver version to 3.11
282 Rev. 3.10 June 23, 2000 BN Qlogic
283 - Added filtering of AMI SubSys Vendor ID devices
285 - DEBUG_QLA1280 undefined and new version BN Qlogic
286 Rev. 3.08b May 9, 2000 MD Dell
287 - Added logic to check against AMI subsystem vendor ID
288 Rev. 3.08 May 4, 2000 DG Qlogic
289 - Added logic to check for PCI subsystem ID.
290 Rev. 3.07 Apr 24, 2000 DG & BN Qlogic
291 - Updated SCSI Firmware to following versions:
294 Rev. 3.06 Apr 12, 2000 DG & BN Qlogic
295 - Internal revision; not released
296 Rev. 3.05 Mar 28, 2000 DG & BN Qlogic
297 - Edit correction for virt_to_bus and PROC.
298 Rev. 3.04 Mar 28, 2000 DG & BN Qlogic
299 - Merge changes from ia64 port.
300 Rev. 3.03 Mar 28, 2000 BN Qlogic
301 - Increase version to reflect new code drop with compile fix
302 of issue with inclusion of linux/spinlock for 2.3 kernels
303 Rev. 3.02 Mar 15, 2000 BN Qlogic
304 - Merge qla1280_proc_info from 2.10 code base
305 Rev. 3.01 Feb 10, 2000 BN Qlogic
306 - Corrected code to compile on a 2.2.x kernel.
307 Rev. 3.00 Jan 17, 2000 DG Qlogic
308 - Added 64-bit support.
309 Rev. 2.07 Nov 9, 1999 DG Qlogic
310 - Added new routine to set target parameters for ISP12160.
311 Rev. 2.06 Sept 10, 1999 DG Qlogic
312 - Added support for ISP12160 Ultra 3 chip.
313 Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
314 - Modified code to remove errors generated when compiling with
315 Cygnus IA64 Compiler.
316 - Changed conversion of pointers to unsigned longs instead of integers.
317 - Changed type of I/O port variables from uint32_t to unsigned long.
318 - Modified OFFSET macro to work with 64-bit as well as 32-bit.
319 - Changed sprintf and printk format specifiers for pointers to %p.
320 - Changed some int to long type casts where needed in sprintf & printk.
321 - Added l modifiers to sprintf and printk format specifiers for longs.
322 - Removed unused local variables.
323 Rev. 1.20 June 8, 1999 DG, Qlogic
324 Changes to support RedHat release 6.0 (kernel 2.2.5).
325 - Added SCSI exclusive access lock (io_request_lock) when accessing
327 - Added changes for the new LINUX interface template. Some new error
328 handling routines have been added to the template, but for now we
329 will use the old ones.
330 - Initial Beta Release.
331 *****************************************************************************/
334 #include <linux/config.h>
335 #include <linux/module.h>
337 #include <linux/version.h>
338 #include <linux/types.h>
339 #include <linux/string.h>
340 #include <linux/errno.h>
341 #include <linux/kernel.h>
342 #include <linux/ioport.h>
343 #include <linux/delay.h>
344 #include <linux/timer.h>
345 #include <linux/sched.h>
346 #include <linux/pci.h>
347 #include <linux/proc_fs.h>
348 #include <linux/stat.h>
349 #include <linux/slab.h>
350 #include <linux/pci_ids.h>
351 #include <linux/interrupt.h>
352 #include <linux/init.h>
353 #include <linux/dma-mapping.h>
357 #include <asm/byteorder.h>
358 #include <asm/processor.h>
359 #include <asm/types.h>
360 #include <asm/system.h>
362 #include <scsi/scsi.h>
363 #include <scsi/scsi_cmnd.h>
364 #include <scsi/scsi_device.h>
365 #include <scsi/scsi_host.h>
366 #include <scsi/scsi_tcq.h>
368 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
369 #include <asm/sn/io.h>
372 #if LINUX_VERSION_CODE < 0x020600
373 #error "Kernels older than 2.6.0 are no longer supported"
378 * Compile time Options:
379 * 0 - Disable and 1 - Enable
381 #define DEBUG_QLA1280_INTR 0
382 #define DEBUG_PRINT_NVRAM 0
383 #define DEBUG_QLA1280 0
386 * The SGI VISWS is broken and doesn't support MMIO ;-(
388 #ifdef CONFIG_X86_VISWS
389 #define MEMORY_MAPPED_IO 0
391 #define MEMORY_MAPPED_IO 1
394 #define UNIQUE_FW_NAME
396 #include "ql12160_fw.h" /* ISP RISC codes */
397 #include "ql1280_fw.h"
398 #include "ql1040_fw.h"
400 #ifndef BITS_PER_LONG
401 #error "BITS_PER_LONG not defined!"
403 #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
404 #define QLA_64BIT_PTR 1
408 #define pci_dma_hi32(a) ((a >> 16) >> 16)
410 #define pci_dma_hi32(a) 0
412 #define pci_dma_lo32(a) (a & 0xffffffff)
414 #define NVRAM_DELAY() udelay(500) /* 2 microseconds */
416 #if defined(__ia64__) && !defined(ia64_platform_is)
417 #define ia64_platform_is(foo) (!strcmp(x, platform_name))
421 #define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
422 #define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
423 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
424 #define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
425 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
428 static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *);
429 static void qla1280_remove_one(struct pci_dev *);
432 * QLogic Driver Support Function Prototypes.
434 static void qla1280_done(struct scsi_qla_host *);
435 static int qla1280_get_token(char *);
436 static int qla1280_setup(char *s) __init;
439 * QLogic ISP1280 Hardware Support Function Prototypes.
441 static int qla1280_load_firmware(struct scsi_qla_host *);
442 static int qla1280_init_rings(struct scsi_qla_host *);
443 static int qla1280_nvram_config(struct scsi_qla_host *);
444 static int qla1280_mailbox_command(struct scsi_qla_host *,
445 uint8_t, uint16_t *);
446 static int qla1280_bus_reset(struct scsi_qla_host *, int);
447 static int qla1280_device_reset(struct scsi_qla_host *, int, int);
448 static int qla1280_abort_device(struct scsi_qla_host *, int, int, int);
449 static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int);
450 static int qla1280_abort_isp(struct scsi_qla_host *);
452 static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *);
454 static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *);
456 static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
457 static void qla1280_poll(struct scsi_qla_host *);
458 static void qla1280_reset_adapter(struct scsi_qla_host *);
459 static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
460 static void qla1280_isp_cmd(struct scsi_qla_host *);
461 static void qla1280_isr(struct scsi_qla_host *, struct list_head *);
462 static void qla1280_rst_aen(struct scsi_qla_host *);
463 static void qla1280_status_entry(struct scsi_qla_host *, struct response *,
465 static void qla1280_error_entry(struct scsi_qla_host *, struct response *,
467 static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
468 static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
469 static uint16_t qla1280_debounce_register(volatile uint16_t __iomem *);
470 static request_t *qla1280_req_pkt(struct scsi_qla_host *);
471 static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
473 static void qla1280_get_target_parameters(struct scsi_qla_host *,
474 struct scsi_device *);
475 static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int);
478 static struct qla_driver_setup driver_setup;
481 * convert scsi data direction to request_t control flags
483 static inline uint16_t
484 qla1280_data_direction(struct scsi_cmnd *cmnd)
486 switch(cmnd->sc_data_direction) {
487 case DMA_FROM_DEVICE:
491 case DMA_BIDIRECTIONAL:
492 return BIT_5 | BIT_6;
494 * We could BUG() on default here if one of the four cases aren't
495 * met, but then again if we receive something like that from the
496 * SCSI layer we have more serious problems. This shuts up GCC.
505 static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd);
506 static void __qla1280_dump_buffer(char *, int);
511 * insmod needs to find the variable and make it point to something
514 static char *qla1280;
516 /* insmod qla1280 options=verbose" */
517 module_param(qla1280, charp, 0);
519 __setup("qla1280=", qla1280_setup);
524 * We use the scsi_pointer structure that's included with each scsi_command
525 * to overlay our struct srb over it. qla1280_init() checks that a srb is not
526 * bigger than a scsi_pointer.
529 #define CMD_SP(Cmnd) &Cmnd->SCp
530 #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
531 #define CMD_CDBP(Cmnd) Cmnd->cmnd
532 #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
533 #define CMD_SNSLEN(Cmnd) sizeof(Cmnd->sense_buffer)
534 #define CMD_RESULT(Cmnd) Cmnd->result
535 #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
536 #define CMD_REQUEST(Cmnd) Cmnd->request->cmd
538 #define CMD_HOST(Cmnd) Cmnd->device->host
539 #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
540 #define SCSI_TCN_32(Cmnd) Cmnd->device->id
541 #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
544 /*****************************************/
545 /* ISP Boards supported by this driver */
546 /*****************************************/
549 unsigned char name[9]; /* Board ID String */
550 int numPorts; /* Number of SCSI ports */
551 unsigned short *fwcode; /* pointer to FW array */
552 unsigned short *fwlen; /* number of words in array */
553 unsigned short *fwstart; /* start address for F/W */
554 unsigned char *fwver; /* Ptr to F/W version array */
557 /* NOTE: the last argument in each entry is used to index ql1280_board_tbl */
558 static struct pci_device_id qla1280_pci_tbl[] = {
559 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP12160,
560 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
561 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1020,
562 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
563 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1080,
564 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
565 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1240,
566 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
567 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1280,
568 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
569 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP10160,
570 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
573 MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl);
575 static struct qla_boards ql1280_board_tbl[] = {
576 /* Name , Number of ports, FW details */
577 {"QLA12160", 2, &fw12160i_code01[0], &fw12160i_length01,
578 &fw12160i_addr01, &fw12160i_version_str[0]},
579 {"QLA1040", 1, &risc_code01[0], &risc_code_length01,
580 &risc_code_addr01, &firmware_version[0]},
581 {"QLA1080", 1, &fw1280ei_code01[0], &fw1280ei_length01,
582 &fw1280ei_addr01, &fw1280ei_version_str[0]},
583 {"QLA1240", 2, &fw1280ei_code01[0], &fw1280ei_length01,
584 &fw1280ei_addr01, &fw1280ei_version_str[0]},
585 {"QLA1280", 2, &fw1280ei_code01[0], &fw1280ei_length01,
586 &fw1280ei_addr01, &fw1280ei_version_str[0]},
587 {"QLA10160", 1, &fw12160i_code01[0], &fw12160i_length01,
588 &fw12160i_addr01, &fw12160i_version_str[0]},
592 static int qla1280_verbose = 1;
595 static int ql_debug_level = 1;
596 #define dprintk(level, format, a...) \
597 do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
598 #define qla1280_dump_buffer(level, buf, size) \
599 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
600 #define qla1280_print_scsi_cmd(level, cmd) \
601 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
603 #define ql_debug_level 0
604 #define dprintk(level, format, a...) do{}while(0)
605 #define qla1280_dump_buffer(a, b, c) do{}while(0)
606 #define qla1280_print_scsi_cmd(a, b) do{}while(0)
609 #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
610 #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
611 #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
612 #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
615 static int qla1280_read_nvram(struct scsi_qla_host *ha)
622 ENTER("qla1280_read_nvram");
624 if (driver_setup.no_nvram)
627 printk(KERN_INFO "scsi(%ld): Reading NVRAM\n", ha->host_no);
629 wptr = (uint16_t *)&ha->nvram;
632 for (cnt = 0; cnt < 3; cnt++) {
633 *wptr = qla1280_get_nvram_word(ha, cnt);
634 chksum += *wptr & 0xff;
635 chksum += (*wptr >> 8) & 0xff;
639 if (nv->id0 != 'I' || nv->id1 != 'S' ||
640 nv->id2 != 'P' || nv->id3 != ' ' || nv->version < 1) {
641 dprintk(2, "Invalid nvram ID or version!\n");
644 for (; cnt < sizeof(struct nvram); cnt++) {
645 *wptr = qla1280_get_nvram_word(ha, cnt);
646 chksum += *wptr & 0xff;
647 chksum += (*wptr >> 8) & 0xff;
652 dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
653 " version %i\n", nv->id0, nv->id1, nv->id2, nv->id3,
658 if (!driver_setup.no_nvram)
659 printk(KERN_WARNING "scsi(%ld): Unable to identify or "
660 "validate NVRAM checksum, using default "
661 "settings\n", ha->host_no);
666 /* The firmware interface is, um, interesting, in that the
667 * actual firmware image on the chip is little endian, thus,
668 * the process of taking that image to the CPU would end up
669 * little endian. However, the firmare interface requires it
670 * to be read a word (two bytes) at a time.
672 * The net result of this would be that the word (and
673 * doubleword) quantites in the firmware would be correct, but
674 * the bytes would be pairwise reversed. Since most of the
675 * firmware quantites are, in fact, bytes, we do an extra
676 * le16_to_cpu() in the firmware read routine.
678 * The upshot of all this is that the bytes in the firmware
679 * are in the correct places, but the 16 and 32 bit quantites
680 * are still in little endian format. We fix that up below by
681 * doing extra reverses on them */
682 nv->isp_parameter = cpu_to_le16(nv->isp_parameter);
683 nv->firmware_feature.w = cpu_to_le16(nv->firmware_feature.w);
684 for(i = 0; i < MAX_BUSES; i++) {
685 nv->bus[i].selection_timeout = cpu_to_le16(nv->bus[i].selection_timeout);
686 nv->bus[i].max_queue_depth = cpu_to_le16(nv->bus[i].max_queue_depth);
688 dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
689 LEAVE("qla1280_read_nvram");
694 /**************************************************************************
696 * Return a string describing the driver.
697 **************************************************************************/
699 qla1280_info(struct Scsi_Host *host)
701 static char qla1280_scsi_name_buffer[125];
703 struct scsi_qla_host *ha;
704 struct qla_boards *bdp;
706 bp = &qla1280_scsi_name_buffer[0];
707 ha = (struct scsi_qla_host *)host->hostdata;
708 bdp = &ql1280_board_tbl[ha->devnum];
709 memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
712 "QLogic %s PCI to SCSI Host Adapter\n"
713 " Firmware version: %2d.%02d.%02d, Driver version %s",
714 &bdp->name[0], bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
719 /**************************************************************************
720 * qla1200_queuecommand
721 * Queue a command to the controller.
724 * The mid-level driver tries to ensures that queuecommand never gets invoked
725 * concurrently with itself or the interrupt handler (although the
726 * interrupt handler may call this routine as part of request-completion
727 * handling). Unfortunely, it sometimes calls the scheduler in interrupt
728 * context which is a big NO! NO!.
729 **************************************************************************/
731 qla1280_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
733 struct Scsi_Host *host = cmd->device->host;
734 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
735 struct srb *sp = (struct srb *)&cmd->SCp;
742 qla1280_print_scsi_cmd(5, cmd);
746 * Using 64 bit commands if the PCI bridge doesn't support it is a
747 * bit wasteful, however this should really only happen if one's
748 * PCI controller is completely broken, like the BCM1250. For
749 * sane hardware this is not an issue.
751 status = qla1280_64bit_start_scsi(ha, sp);
753 status = qla1280_32bit_start_scsi(ha, sp);
767 /* timer action for error action processor */
768 static void qla1280_error_wait_timeout(unsigned long __data)
770 struct scsi_cmnd *cmd = (struct scsi_cmnd *)__data;
771 struct srb *sp = (struct srb *)CMD_SP(cmd);
776 static void qla1280_mailbox_timeout(unsigned long __data)
778 struct scsi_qla_host *ha = (struct scsi_qla_host *)__data;
779 struct device_reg __iomem *reg;
782 ha->mailbox_out[0] = RD_REG_WORD(®->mailbox0);
783 printk(KERN_ERR "scsi(%ld): mailbox timed out, mailbox0 %04x, "
784 "ictrl %04x, istatus %04x\n", ha->host_no, ha->mailbox_out[0],
785 RD_REG_WORD(®->ictrl), RD_REG_WORD(®->istatus));
786 complete(ha->mailbox_wait);
789 /**************************************************************************
790 * qla1200_error_action
791 * The function will attempt to perform a specified error action and
792 * wait for the results (or time out).
795 * cmd = Linux SCSI command packet of the command that cause the
797 * action = error action to take (see action_t)
803 * Resetting the bus always succeeds - is has to, otherwise the
804 * kernel will panic! Try a surgical technique - sending a BUS
805 * DEVICE RESET message - on the offending target before pulling
806 * the SCSI bus reset line.
807 **************************************************************************/
809 qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
811 struct scsi_qla_host *ha;
812 int bus, target, lun;
815 unsigned char *handle;
817 DECLARE_COMPLETION(wait);
818 struct timer_list timer;
820 ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
822 dprintk(4, "error_action %i, istatus 0x%04x\n", action,
823 RD_REG_WORD(&ha->iobase->istatus));
825 dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
826 RD_REG_WORD(&ha->iobase->host_cmd),
827 RD_REG_WORD(&ha->iobase->ictrl), jiffies);
829 ENTER("qla1280_error_action");
831 printk(KERN_INFO "scsi(%li): Resetting Cmnd=0x%p, "
832 "Handle=0x%p, action=0x%x\n",
833 ha->host_no, cmd, CMD_HANDLE(cmd), action);
836 printk(KERN_WARNING "(scsi?:?:?:?) Reset called with NULL "
837 "si_Cmnd pointer, failing.\n");
838 LEAVE("qla1280_error_action");
842 ha = (struct scsi_qla_host *)cmd->device->host->hostdata;
843 sp = (struct srb *)CMD_SP(cmd);
844 handle = CMD_HANDLE(cmd);
846 /* Check for pending interrupts. */
847 data = qla1280_debounce_register(&ha->iobase->istatus);
849 * The io_request_lock is held when the reset handler is called, hence
850 * the interrupt handler cannot be running in parallel as it also
851 * grabs the lock. /Jes
854 qla1280_isr(ha, &ha->done_q);
857 * Determine the suggested action that the mid-level driver wants
860 if (handle == (unsigned char *)INVALID_HANDLE || handle == NULL) {
861 if(action == ABORT_COMMAND) {
862 /* we never got this command */
863 printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
864 return SUCCESS; /* no action - we don't have command */
870 bus = SCSI_BUS_32(cmd);
871 target = SCSI_TCN_32(cmd);
872 lun = SCSI_LUN_32(cmd);
874 /* Overloading result. Here it means the success or fail of the
875 * *issue* of the action. When we return from the routine, it must
876 * mean the actual success or fail of the action */
883 if ((sp->flags & SRB_ABORT_PENDING)) {
885 "scsi(): Command has a pending abort "
886 "message - ABORT_PENDING.\n");
887 /* This should technically be impossible since we
888 * now wait for abort completion */
892 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
893 if (sp == ha->outstanding_cmds[i]) {
894 dprintk(1, "qla1280: RISC aborting command\n");
895 if (qla1280_abort_command(ha, sp, i) == 0)
899 * Since we don't know what might
900 * have happend to the command, it
901 * is unsafe to remove it from the
902 * device's queue at this point.
903 * Wait and let the escalation
904 * process take care of it.
907 "scsi(%li:%i:%i:%i): Unable"
908 " to abort command!\n",
909 ha->host_no, bus, target, lun);
918 "scsi(%ld:%d:%d:%d): Queueing abort device "
919 "command.\n", ha->host_no, bus, target, lun);
920 if (qla1280_abort_device(ha, bus, target, lun) == 0)
927 "scsi(%ld:%d:%d:%d): Queueing device reset "
928 "command.\n", ha->host_no, bus, target, lun);
929 if (qla1280_device_reset(ha, bus, target) == 0)
935 printk(KERN_INFO "qla1280(%ld:%d): Issuing BUS "
936 "DEVICE RESET\n", ha->host_no, bus);
937 if (qla1280_bus_reset(ha, bus == 0))
944 if (qla1280_verbose) {
946 "scsi(%ld): Issued ADAPTER RESET\n",
948 printk(KERN_INFO "scsi(%ld): I/O processing will "
949 "continue automatically\n", ha->host_no);
951 ha->flags.reset_active = 1;
953 * We restarted all of the commands automatically, so the
954 * mid-level code can expect completions momentitarily.
956 if (qla1280_abort_isp(ha) == 0)
959 ha->flags.reset_active = 0;
962 if (!list_empty(&ha->done_q))
965 /* If we didn't manage to issue the action, or we have no
966 * command to wait for, exit here */
967 if (result == FAILED || handle == NULL ||
968 handle == (unsigned char *)INVALID_HANDLE) {
970 * Clear completion queue to avoid qla1280_done() trying
971 * to complete the command at a later stage after we
972 * have exited the current context
978 /* set up a timer just in case we're really jammed */
980 timer.expires = jiffies + 4*HZ;
981 timer.data = (unsigned long)cmd;
982 timer.function = qla1280_error_wait_timeout;
985 /* wait for the action to complete (or the timer to expire) */
986 spin_unlock_irq(ha->host->host_lock);
987 wait_for_completion(&wait);
988 del_timer_sync(&timer);
989 spin_lock_irq(ha->host->host_lock);
992 /* the only action we might get a fail for is abort */
993 if (action == ABORT_COMMAND) {
994 if(sp->flags & SRB_ABORTED)
1001 dprintk(1, "RESET returning %d\n", result);
1003 LEAVE("qla1280_error_action");
1007 /**************************************************************************
1009 * Abort the specified SCSI command(s).
1010 **************************************************************************/
1012 qla1280_eh_abort(struct scsi_cmnd * cmd)
1016 spin_lock_irq(cmd->device->host->host_lock);
1017 rc = qla1280_error_action(cmd, ABORT_COMMAND);
1018 spin_unlock_irq(cmd->device->host->host_lock);
1023 /**************************************************************************
1024 * qla1280_device_reset
1025 * Reset the specified SCSI device
1026 **************************************************************************/
1028 qla1280_eh_device_reset(struct scsi_cmnd *cmd)
1032 spin_lock_irq(cmd->device->host->host_lock);
1033 rc = qla1280_error_action(cmd, DEVICE_RESET);
1034 spin_unlock_irq(cmd->device->host->host_lock);
1039 /**************************************************************************
1041 * Reset the specified bus.
1042 **************************************************************************/
1044 qla1280_eh_bus_reset(struct scsi_cmnd *cmd)
1048 spin_lock_irq(cmd->device->host->host_lock);
1049 rc = qla1280_error_action(cmd, BUS_RESET);
1050 spin_unlock_irq(cmd->device->host->host_lock);
1055 /**************************************************************************
1056 * qla1280_adapter_reset
1057 * Reset the specified adapter (both channels)
1058 **************************************************************************/
1060 qla1280_eh_adapter_reset(struct scsi_cmnd *cmd)
1064 spin_lock_irq(cmd->device->host->host_lock);
1065 rc = qla1280_error_action(cmd, ADAPTER_RESET);
1066 spin_unlock_irq(cmd->device->host->host_lock);
1072 qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1073 sector_t capacity, int geom[])
1075 int heads, sectors, cylinders;
1079 cylinders = (unsigned long)capacity / (heads * sectors);
1080 if (cylinders > 1024) {
1083 cylinders = (unsigned long)capacity / (heads * sectors);
1084 /* if (cylinders > 1023)
1085 cylinders = 1023; */
1090 geom[2] = cylinders;
1096 /* disable risc and host interrupts */
1098 qla1280_disable_intrs(struct scsi_qla_host *ha)
1100 WRT_REG_WORD(&ha->iobase->ictrl, 0);
1101 RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
1104 /* enable risc and host interrupts */
1106 qla1280_enable_intrs(struct scsi_qla_host *ha)
1108 WRT_REG_WORD(&ha->iobase->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1109 RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
1112 /**************************************************************************
1113 * qla1280_intr_handler
1114 * Handles the H/W interrupt
1115 **************************************************************************/
1117 qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1119 struct scsi_qla_host *ha;
1120 struct device_reg __iomem *reg;
1124 ENTER_INTR ("qla1280_intr_handler");
1125 ha = (struct scsi_qla_host *)dev_id;
1127 spin_lock(ha->host->host_lock);
1132 qla1280_disable_intrs(ha);
1134 data = qla1280_debounce_register(®->istatus);
1135 /* Check for pending interrupts. */
1136 if (data & RISC_INT) {
1137 qla1280_isr(ha, &ha->done_q);
1140 if (!list_empty(&ha->done_q))
1143 spin_unlock(ha->host->host_lock);
1145 qla1280_enable_intrs(ha);
1147 LEAVE_INTR("qla1280_intr_handler");
1148 return IRQ_RETVAL(handled);
1153 qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
1156 uint16_t mb[MAILBOX_REGISTER_COUNT];
1162 mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
1164 /* Set Target Parameters. */
1165 mb[0] = MBC_SET_TARGET_PARAMETERS;
1166 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
1167 mb[2] = nv->bus[bus].target[target].parameter.renegotiate_on_error << 8;
1168 mb[2] |= nv->bus[bus].target[target].parameter.stop_queue_on_check << 9;
1169 mb[2] |= nv->bus[bus].target[target].parameter.auto_request_sense << 10;
1170 mb[2] |= nv->bus[bus].target[target].parameter.tag_queuing << 11;
1171 mb[2] |= nv->bus[bus].target[target].parameter.enable_sync << 12;
1172 mb[2] |= nv->bus[bus].target[target].parameter.enable_wide << 13;
1173 mb[2] |= nv->bus[bus].target[target].parameter.parity_checking << 14;
1174 mb[2] |= nv->bus[bus].target[target].parameter.disconnect_allowed << 15;
1176 if (IS_ISP1x160(ha)) {
1177 mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
1178 mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8);
1179 mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) |
1180 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
1183 mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8);
1185 mb[3] |= nv->bus[bus].target[target].sync_period;
1187 status = qla1280_mailbox_command(ha, mr, mb);
1189 /* Set Device Queue Parameters. */
1190 for (lun = 0; lun < MAX_LUNS; lun++) {
1191 mb[0] = MBC_SET_DEVICE_QUEUE;
1192 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
1194 mb[2] = nv->bus[bus].max_queue_depth;
1195 mb[3] = nv->bus[bus].target[target].execution_throttle;
1196 status |= qla1280_mailbox_command(ha, 0x0f, mb);
1200 printk(KERN_WARNING "scsi(%ld:%i:%i): "
1201 "qla1280_set_target_parameters() failed\n",
1202 ha->host_no, bus, target);
1207 /**************************************************************************
1208 * qla1280_slave_configure
1211 * Determines the queue depth for a given device. There are two ways
1212 * a queue depth can be obtained for a tagged queueing device. One
1213 * way is the default queue depth which is determined by whether
1214 * If it is defined, then it is used
1215 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1216 * default queue depth (dependent on the number of hardware SCBs).
1217 **************************************************************************/
1219 qla1280_slave_configure(struct scsi_device *device)
1221 struct scsi_qla_host *ha;
1222 int default_depth = 3;
1223 int bus = device->channel;
1224 int target = device->id;
1227 unsigned long flags;
1229 ha = (struct scsi_qla_host *)device->host->hostdata;
1232 if (qla1280_check_for_dead_scsi_bus(ha, bus))
1235 if (device->tagged_supported &&
1236 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1237 scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
1238 ha->bus_settings[bus].hiwat);
1240 scsi_adjust_queue_depth(device, 0, default_depth);
1243 nv->bus[bus].target[target].parameter.enable_sync = device->sdtr;
1244 nv->bus[bus].target[target].parameter.enable_wide = device->wdtr;
1245 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
1247 if (driver_setup.no_sync ||
1248 (driver_setup.sync_mask &&
1249 (~driver_setup.sync_mask & (1 << target))))
1250 nv->bus[bus].target[target].parameter.enable_sync = 0;
1251 if (driver_setup.no_wide ||
1252 (driver_setup.wide_mask &&
1253 (~driver_setup.wide_mask & (1 << target))))
1254 nv->bus[bus].target[target].parameter.enable_wide = 0;
1255 if (IS_ISP1x160(ha)) {
1256 if (driver_setup.no_ppr ||
1257 (driver_setup.ppr_mask &&
1258 (~driver_setup.ppr_mask & (1 << target))))
1259 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
1262 spin_lock_irqsave(ha->host->host_lock, flags);
1263 if (nv->bus[bus].target[target].parameter.enable_sync)
1264 status = qla1280_set_target_parameters(ha, bus, target);
1265 qla1280_get_target_parameters(ha, device);
1266 spin_unlock_irqrestore(ha->host->host_lock, flags);
1273 * Process completed commands.
1276 * ha = adapter block pointer.
1279 qla1280_done(struct scsi_qla_host *ha)
1282 struct list_head *done_q;
1283 int bus, target, lun;
1284 struct scsi_cmnd *cmd;
1286 ENTER("qla1280_done");
1288 done_q = &ha->done_q;
1290 while (!list_empty(done_q)) {
1291 sp = list_entry(done_q->next, struct srb, list);
1293 list_del(&sp->list);
1296 bus = SCSI_BUS_32(cmd);
1297 target = SCSI_TCN_32(cmd);
1298 lun = SCSI_LUN_32(cmd);
1300 switch ((CMD_RESULT(cmd) >> 16)) {
1302 /* Issue marker command. */
1303 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
1306 sp->flags &= ~SRB_ABORT_PENDING;
1307 sp->flags |= SRB_ABORTED;
1308 if (sp->flags & SRB_TIMEOUT)
1309 CMD_RESULT(sp->cmd) = DID_TIME_OUT << 16;
1315 /* Release memory used for this I/O */
1317 pci_unmap_sg(ha->pdev, cmd->request_buffer,
1318 cmd->use_sg, cmd->sc_data_direction);
1319 } else if (cmd->request_bufflen) {
1320 pci_unmap_single(ha->pdev, sp->saved_dma_handle,
1321 cmd->request_bufflen,
1322 cmd->sc_data_direction);
1325 /* Call the mid-level driver interrupt handler */
1326 CMD_HANDLE(sp->cmd) = (unsigned char *)INVALID_HANDLE;
1329 (*(cmd)->scsi_done)(cmd);
1331 if(sp->wait != NULL)
1334 LEAVE("qla1280_done");
1338 * Translates a ISP error to a Linux SCSI error
1341 qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1343 int host_status = DID_ERROR;
1344 uint16_t comp_status = le16_to_cpu(sts->comp_status);
1345 uint16_t state_flags = le16_to_cpu(sts->state_flags);
1346 uint16_t residual_length = le32_to_cpu(sts->residual_length);
1347 uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
1348 #if DEBUG_QLA1280_INTR
1349 static char *reason[] = {
1361 #endif /* DEBUG_QLA1280_INTR */
1363 ENTER("qla1280_return_status");
1365 #if DEBUG_QLA1280_INTR
1367 dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
1372 switch (comp_status) {
1374 host_status = DID_OK;
1378 if (!(state_flags & SF_GOT_BUS))
1379 host_status = DID_NO_CONNECT;
1380 else if (!(state_flags & SF_GOT_TARGET))
1381 host_status = DID_BAD_TARGET;
1382 else if (!(state_flags & SF_SENT_CDB))
1383 host_status = DID_ERROR;
1384 else if (!(state_flags & SF_TRANSFERRED_DATA))
1385 host_status = DID_ERROR;
1386 else if (!(state_flags & SF_GOT_STATUS))
1387 host_status = DID_ERROR;
1388 else if (!(state_flags & SF_GOT_SENSE))
1389 host_status = DID_ERROR;
1393 host_status = DID_RESET;
1397 host_status = DID_ABORT;
1401 host_status = DID_TIME_OUT;
1404 case CS_DATA_OVERRUN:
1405 dprintk(2, "Data overrun 0x%x\n", residual_length);
1406 dprintk(2, "qla1280_return_status: response packet data\n");
1407 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
1408 host_status = DID_ERROR;
1411 case CS_DATA_UNDERRUN:
1412 if ((cp->request_bufflen - residual_length) <
1415 "scsi: Underflow detected - retrying "
1417 host_status = DID_ERROR;
1419 host_status = DID_OK;
1423 host_status = DID_ERROR;
1427 #if DEBUG_QLA1280_INTR
1428 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
1429 reason[host_status], scsi_status);
1432 LEAVE("qla1280_return_status");
1434 return (scsi_status & 0xff) | (host_status << 16);
1437 /****************************************************************************/
1438 /* QLogic ISP1280 Hardware Support Functions. */
1439 /****************************************************************************/
1442 * qla1280_initialize_adapter
1446 * ha = adapter block pointer.
1451 static int __devinit
1452 qla1280_initialize_adapter(struct scsi_qla_host *ha)
1454 struct device_reg __iomem *reg;
1457 unsigned long flags;
1459 ENTER("qla1280_initialize_adapter");
1461 /* Clear adapter flags. */
1462 ha->flags.online = 0;
1463 ha->flags.disable_host_adapter = 0;
1464 ha->flags.reset_active = 0;
1465 ha->flags.abort_isp_active = 0;
1467 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1468 if (ia64_platform_is("sn2")) {
1469 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
1470 "dual channel lockup workaround\n", ha->host_no);
1471 ha->flags.use_pci_vchannel = 1;
1472 driver_setup.no_nvram = 1;
1476 /* TODO: implement support for the 1040 nvram format */
1478 driver_setup.no_nvram = 1;
1480 dprintk(1, "Configure PCI space for adapter...\n");
1484 /* Insure mailbox registers are free. */
1485 WRT_REG_WORD(®->semaphore, 0);
1486 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
1487 WRT_REG_WORD(®->host_cmd, HC_CLR_HOST_INT);
1488 RD_REG_WORD(®->host_cmd);
1490 if (qla1280_read_nvram(ha)) {
1491 dprintk(2, "qla1280_initialize_adapter: failed to read "
1496 * It's necessary to grab the spin here as qla1280_mailbox_command
1497 * needs to be able to drop the lock unconditionally to wait
1500 spin_lock_irqsave(ha->host->host_lock, flags);
1502 status = qla1280_load_firmware(ha);
1504 printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
1509 /* Setup adapter based on NVRAM parameters. */
1510 dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha->host_no);
1511 qla1280_nvram_config(ha);
1513 if (ha->flags.disable_host_adapter) {
1518 status = qla1280_init_rings(ha);
1522 /* Issue SCSI reset, if we can't reset twice then bus is dead */
1523 for (bus = 0; bus < ha->ports; bus++) {
1524 if (!ha->bus_settings[bus].disable_scsi_reset &&
1525 qla1280_bus_reset(ha, bus) &&
1526 qla1280_bus_reset(ha, bus))
1527 ha->bus_settings[bus].scsi_bus_dead = 1;
1530 ha->flags.online = 1;
1532 spin_unlock_irqrestore(ha->host->host_lock, flags);
1535 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
1537 LEAVE("qla1280_initialize_adapter");
1543 * Test chip for proper operation.
1546 * ha = adapter block pointer.
1552 qla1280_chip_diag(struct scsi_qla_host *ha)
1554 uint16_t mb[MAILBOX_REGISTER_COUNT];
1555 struct device_reg __iomem *reg = ha->iobase;
1559 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®->id_l);
1561 dprintk(1, "scsi(%ld): Verifying chip\n", ha->host_no);
1563 /* Soft reset chip and wait for it to finish. */
1564 WRT_REG_WORD(®->ictrl, ISP_RESET);
1567 * We can't do a traditional PCI write flush here by reading
1568 * back the register. The card will not respond once the reset
1569 * is in action and we end up with a machine check exception
1570 * instead. Nothing to do but wait and hope for the best.
1571 * A portable pci_write_flush(pdev) call would be very useful here.
1574 data = qla1280_debounce_register(®->ictrl);
1576 * Yet another QLogic gem ;-(
1578 for (cnt = 1000000; cnt && data & ISP_RESET; cnt--) {
1580 data = RD_REG_WORD(®->ictrl);
1586 /* Reset register cleared by chip reset. */
1587 dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
1589 WRT_REG_WORD(®->cfg_1, 0);
1591 /* Reset RISC and disable BIOS which
1592 allows RISC to execute out of RAM. */
1593 WRT_REG_WORD(®->host_cmd, HC_RESET_RISC |
1594 HC_RELEASE_RISC | HC_DISABLE_BIOS);
1596 RD_REG_WORD(®->id_l); /* Flush PCI write */
1597 data = qla1280_debounce_register(®->mailbox0);
1600 * I *LOVE* this code!
1602 for (cnt = 1000000; cnt && data == MBS_BUSY; cnt--) {
1604 data = RD_REG_WORD(®->mailbox0);
1610 /* Check product ID of chip */
1611 dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
1613 if (RD_REG_WORD(®->mailbox1) != PROD_ID_1 ||
1614 (RD_REG_WORD(®->mailbox2) != PROD_ID_2 &&
1615 RD_REG_WORD(®->mailbox2) != PROD_ID_2a) ||
1616 RD_REG_WORD(®->mailbox3) != PROD_ID_3 ||
1617 RD_REG_WORD(®->mailbox4) != PROD_ID_4) {
1618 printk(KERN_INFO "qla1280: Wrong product ID = "
1619 "0x%x,0x%x,0x%x,0x%x\n",
1620 RD_REG_WORD(®->mailbox1),
1621 RD_REG_WORD(®->mailbox2),
1622 RD_REG_WORD(®->mailbox3),
1623 RD_REG_WORD(®->mailbox4));
1628 * Enable ints early!!!
1630 qla1280_enable_intrs(ha);
1632 dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
1633 /* Wrap Incoming Mailboxes Test. */
1634 mb[0] = MBC_MAILBOX_REGISTER_TEST;
1643 status = qla1280_mailbox_command(ha, 0xff, mb);
1647 if (mb[1] != 0xAAAA || mb[2] != 0x5555 || mb[3] != 0xAA55 ||
1648 mb[4] != 0x55AA || mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
1650 printk(KERN_INFO "qla1280: Failed mbox check\n");
1654 dprintk(3, "qla1280_chip_diag: exiting normally\n");
1657 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
1662 qla1280_load_firmware_pio(struct scsi_qla_host *ha)
1664 uint16_t risc_address, *risc_code_address, risc_code_size;
1665 uint16_t mb[MAILBOX_REGISTER_COUNT], i;
1668 /* Load RISC code. */
1669 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
1670 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
1671 risc_code_size = *ql1280_board_tbl[ha->devnum].fwlen;
1673 for (i = 0; i < risc_code_size; i++) {
1674 mb[0] = MBC_WRITE_RAM_WORD;
1675 mb[1] = risc_address + i;
1676 mb[2] = risc_code_address[i];
1678 err = qla1280_mailbox_command(ha, BIT_0 | BIT_1 | BIT_2, mb);
1680 printk(KERN_ERR "scsi(%li): Failed to load firmware\n",
1689 #define DUMP_IT_BACK 0 /* for debug of RISC loading */
1691 qla1280_load_firmware_dma(struct scsi_qla_host *ha)
1693 uint16_t risc_address, *risc_code_address, risc_code_size;
1694 uint16_t mb[MAILBOX_REGISTER_COUNT], cnt;
1695 int err = 0, num, i;
1700 tbuf = pci_alloc_consistent(ha->pdev, 8000, &p_tbuf);
1705 /* Load RISC code. */
1706 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
1707 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
1708 risc_code_size = *ql1280_board_tbl[ha->devnum].fwlen;
1710 dprintk(1, "%s: DMA RISC code (%i) words\n",
1711 __FUNCTION__, risc_code_size);
1714 while (risc_code_size > 0) {
1715 int warn __attribute__((unused)) = 0;
1719 if (cnt > risc_code_size)
1720 cnt = risc_code_size;
1722 dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
1724 risc_code_address, cnt, num, risc_address);
1725 for(i = 0; i < cnt; i++)
1726 ((__le16 *)ha->request_ring)[i] =
1727 cpu_to_le16(risc_code_address[i]);
1729 mb[0] = MBC_LOAD_RAM;
1730 mb[1] = risc_address;
1732 mb[3] = ha->request_dma & 0xffff;
1733 mb[2] = (ha->request_dma >> 16) & 0xffff;
1734 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
1735 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
1736 dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
1737 __FUNCTION__, mb[0],
1738 (void *)(long)ha->request_dma,
1739 mb[6], mb[7], mb[2], mb[3]);
1740 err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
1743 printk(KERN_ERR "scsi(%li): Failed to load partial "
1744 "segment of f\n", ha->host_no);
1749 mb[0] = MBC_DUMP_RAM;
1750 mb[1] = risc_address;
1752 mb[3] = p_tbuf & 0xffff;
1753 mb[2] = (p_tbuf >> 16) & 0xffff;
1754 mb[7] = pci_dma_hi32(p_tbuf) & 0xffff;
1755 mb[6] = pci_dma_hi32(p_tbuf) >> 16;
1757 err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
1761 "Failed to dump partial segment of f/w\n");
1764 sp = (uint8_t *)ha->request_ring;
1765 for (i = 0; i < (cnt << 1); i++) {
1766 if (tbuf[i] != sp[i] && warn++ < 10) {
1767 printk(KERN_ERR "%s: FW compare error @ "
1768 "byte(0x%x) loop#=%x\n",
1769 __FUNCTION__, i, num);
1770 printk(KERN_ERR "%s: FWbyte=%x "
1772 __FUNCTION__, sp[i], tbuf[i]);
1777 risc_address += cnt;
1778 risc_code_size = risc_code_size - cnt;
1779 risc_code_address = risc_code_address + cnt;
1785 pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
1791 qla1280_start_firmware(struct scsi_qla_host *ha)
1793 uint16_t mb[MAILBOX_REGISTER_COUNT];
1796 dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
1799 /* Verify checksum of loaded RISC code. */
1800 mb[0] = MBC_VERIFY_CHECKSUM;
1801 /* mb[1] = ql12_risc_code_addr01; */
1802 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1803 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
1805 printk(KERN_ERR "scsi(%li): RISC checksum failed.\n", ha->host_no);
1809 /* Start firmware execution. */
1810 dprintk(1, "%s: start firmware running.\n", __FUNCTION__);
1811 mb[0] = MBC_EXECUTE_FIRMWARE;
1812 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1813 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
1815 printk(KERN_ERR "scsi(%li): Failed to start firmware\n",
1823 qla1280_load_firmware(struct scsi_qla_host *ha)
1827 err = qla1280_chip_diag(ha);
1831 err = qla1280_load_firmware_pio(ha);
1833 err = qla1280_load_firmware_dma(ha);
1836 err = qla1280_start_firmware(ha);
1845 * ha = adapter block pointer.
1846 * ha->request_ring = request ring virtual address
1847 * ha->response_ring = response ring virtual address
1848 * ha->request_dma = request ring physical address
1849 * ha->response_dma = response ring physical address
1855 qla1280_init_rings(struct scsi_qla_host *ha)
1857 uint16_t mb[MAILBOX_REGISTER_COUNT];
1860 ENTER("qla1280_init_rings");
1862 /* Clear outstanding commands array. */
1863 memset(ha->outstanding_cmds, 0,
1864 sizeof(struct srb *) * MAX_OUTSTANDING_COMMANDS);
1866 /* Initialize request queue. */
1867 ha->request_ring_ptr = ha->request_ring;
1868 ha->req_ring_index = 0;
1869 ha->req_q_cnt = REQUEST_ENTRY_CNT;
1870 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
1871 mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
1872 mb[1] = REQUEST_ENTRY_CNT;
1873 mb[3] = ha->request_dma & 0xffff;
1874 mb[2] = (ha->request_dma >> 16) & 0xffff;
1876 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
1877 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
1878 if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
1879 BIT_3 | BIT_2 | BIT_1 | BIT_0,
1881 /* Initialize response queue. */
1882 ha->response_ring_ptr = ha->response_ring;
1883 ha->rsp_ring_index = 0;
1884 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
1885 mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
1886 mb[1] = RESPONSE_ENTRY_CNT;
1887 mb[3] = ha->response_dma & 0xffff;
1888 mb[2] = (ha->response_dma >> 16) & 0xffff;
1890 mb[7] = pci_dma_hi32(ha->response_dma) & 0xffff;
1891 mb[6] = pci_dma_hi32(ha->response_dma) >> 16;
1892 status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
1893 BIT_3 | BIT_2 | BIT_1 | BIT_0,
1898 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
1900 LEAVE("qla1280_init_rings");
1905 qla1280_print_settings(struct nvram *nv)
1907 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
1908 nv->bus[0].config_1.initiator_id);
1909 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
1910 nv->bus[1].config_1.initiator_id);
1912 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
1913 nv->bus[0].bus_reset_delay);
1914 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
1915 nv->bus[1].bus_reset_delay);
1917 dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
1918 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
1919 dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
1920 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
1922 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
1923 nv->bus[0].config_2.async_data_setup_time);
1924 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
1925 nv->bus[1].config_2.async_data_setup_time);
1927 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
1928 nv->bus[0].config_2.req_ack_active_negation);
1929 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
1930 nv->bus[1].config_2.req_ack_active_negation);
1932 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
1933 nv->bus[0].config_2.data_line_active_negation);
1934 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
1935 nv->bus[1].config_2.data_line_active_negation);
1937 dprintk(1, "qla1280 : disable loading risc code=%d\n",
1938 nv->cntr_flags_1.disable_loading_risc_code);
1940 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
1941 nv->cntr_flags_1.enable_64bit_addressing);
1943 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
1944 nv->bus[0].selection_timeout);
1945 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
1946 nv->bus[1].selection_timeout);
1948 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
1949 nv->bus[0].max_queue_depth);
1950 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
1951 nv->bus[1].max_queue_depth);
1955 qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target)
1957 struct nvram *nv = &ha->nvram;
1959 nv->bus[bus].target[target].parameter.renegotiate_on_error = 1;
1960 nv->bus[bus].target[target].parameter.auto_request_sense = 1;
1961 nv->bus[bus].target[target].parameter.tag_queuing = 1;
1962 nv->bus[bus].target[target].parameter.enable_sync = 1;
1963 #if 1 /* Some SCSI Processors do not seem to like this */
1964 nv->bus[bus].target[target].parameter.enable_wide = 1;
1966 nv->bus[bus].target[target].execution_throttle =
1967 nv->bus[bus].max_queue_depth - 1;
1968 nv->bus[bus].target[target].parameter.parity_checking = 1;
1969 nv->bus[bus].target[target].parameter.disconnect_allowed = 1;
1971 if (IS_ISP1x160(ha)) {
1972 nv->bus[bus].target[target].flags.flags1x160.device_enable = 1;
1973 nv->bus[bus].target[target].flags.flags1x160.sync_offset = 0x0e;
1974 nv->bus[bus].target[target].sync_period = 9;
1975 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
1976 nv->bus[bus].target[target].ppr_1x160.flags.ppr_options = 2;
1977 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width = 1;
1979 nv->bus[bus].target[target].flags.flags1x80.device_enable = 1;
1980 nv->bus[bus].target[target].flags.flags1x80.sync_offset = 12;
1981 nv->bus[bus].target[target].sync_period = 10;
1986 qla1280_set_defaults(struct scsi_qla_host *ha)
1988 struct nvram *nv = &ha->nvram;
1991 dprintk(1, "Using defaults for NVRAM: \n");
1992 memset(nv, 0, sizeof(struct nvram));
1994 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
1995 nv->firmware_feature.f.enable_fast_posting = 1;
1996 nv->firmware_feature.f.disable_synchronous_backoff = 1;
1997 nv->termination.scsi_bus_0_control = 3;
1998 nv->termination.scsi_bus_1_control = 3;
1999 nv->termination.auto_term_support = 1;
2002 * Set default FIFO magic - What appropriate values would be here
2003 * is unknown. This is what I have found testing with 12160s.
2005 * Now, I would love the magic decoder ring for this one, the
2006 * header file provided by QLogic seems to be bogus or incomplete
2009 nv->isp_config.burst_enable = 1;
2011 nv->isp_config.fifo_threshold |= 3;
2013 nv->isp_config.fifo_threshold |= 4;
2015 if (IS_ISP1x160(ha))
2016 nv->isp_parameter = 0x01; /* fast memory enable */
2018 for (bus = 0; bus < MAX_BUSES; bus++) {
2019 nv->bus[bus].config_1.initiator_id = 7;
2020 nv->bus[bus].config_2.req_ack_active_negation = 1;
2021 nv->bus[bus].config_2.data_line_active_negation = 1;
2022 nv->bus[bus].selection_timeout = 250;
2023 nv->bus[bus].max_queue_depth = 256;
2025 if (IS_ISP1040(ha)) {
2026 nv->bus[bus].bus_reset_delay = 3;
2027 nv->bus[bus].config_2.async_data_setup_time = 6;
2028 nv->bus[bus].retry_delay = 1;
2030 nv->bus[bus].bus_reset_delay = 5;
2031 nv->bus[bus].config_2.async_data_setup_time = 8;
2034 for (target = 0; target < MAX_TARGETS; target++)
2035 qla1280_set_target_defaults(ha, bus, target);
2040 qla1280_config_target(struct scsi_qla_host *ha, int bus, int target)
2042 struct nvram *nv = &ha->nvram;
2043 uint16_t mb[MAILBOX_REGISTER_COUNT];
2047 /* Set Target Parameters. */
2048 mb[0] = MBC_SET_TARGET_PARAMETERS;
2049 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
2052 * Do not enable sync and ppr for the initial INQUIRY run. We
2053 * enable this later if we determine the target actually
2056 mb[2] = (TP_RENEGOTIATE | TP_AUTO_REQUEST_SENSE | TP_TAGGED_QUEUE
2057 | TP_WIDE | TP_PARITY | TP_DISCONNECT);
2059 if (IS_ISP1x160(ha))
2060 mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
2062 mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
2063 mb[3] |= nv->bus[bus].target[target].sync_period;
2064 status = qla1280_mailbox_command(ha, 0x0f, mb);
2066 /* Save Tag queuing enable flag. */
2067 flag = (BIT_0 << target) & mb[0];
2068 if (nv->bus[bus].target[target].parameter.tag_queuing)
2069 ha->bus_settings[bus].qtag_enables |= flag;
2071 /* Save Device enable flag. */
2072 if (IS_ISP1x160(ha)) {
2073 if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
2074 ha->bus_settings[bus].device_enables |= flag;
2075 ha->bus_settings[bus].lun_disables |= 0;
2077 if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
2078 ha->bus_settings[bus].device_enables |= flag;
2079 /* Save LUN disable flag. */
2080 if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
2081 ha->bus_settings[bus].lun_disables |= flag;
2084 /* Set Device Queue Parameters. */
2085 for (lun = 0; lun < MAX_LUNS; lun++) {
2086 mb[0] = MBC_SET_DEVICE_QUEUE;
2087 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
2089 mb[2] = nv->bus[bus].max_queue_depth;
2090 mb[3] = nv->bus[bus].target[target].execution_throttle;
2091 status |= qla1280_mailbox_command(ha, 0x0f, mb);
2098 qla1280_config_bus(struct scsi_qla_host *ha, int bus)
2100 struct nvram *nv = &ha->nvram;
2101 uint16_t mb[MAILBOX_REGISTER_COUNT];
2104 /* SCSI Reset Disable. */
2105 ha->bus_settings[bus].disable_scsi_reset =
2106 nv->bus[bus].config_1.scsi_reset_disable;
2109 ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
2110 mb[0] = MBC_SET_INITIATOR_ID;
2111 mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
2112 ha->bus_settings[bus].id;
2113 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2116 ha->bus_settings[bus].bus_reset_delay =
2117 nv->bus[bus].bus_reset_delay;
2119 /* Command queue depth per device. */
2120 ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
2122 /* Set target parameters. */
2123 for (target = 0; target < MAX_TARGETS; target++)
2124 status |= qla1280_config_target(ha, bus, target);
2130 qla1280_nvram_config(struct scsi_qla_host *ha)
2132 struct device_reg __iomem *reg = ha->iobase;
2133 struct nvram *nv = &ha->nvram;
2134 int bus, target, status = 0;
2135 uint16_t mb[MAILBOX_REGISTER_COUNT];
2137 ENTER("qla1280_nvram_config");
2139 if (ha->nvram_valid) {
2140 /* Always force AUTO sense for LINUX SCSI */
2141 for (bus = 0; bus < MAX_BUSES; bus++)
2142 for (target = 0; target < MAX_TARGETS; target++) {
2143 nv->bus[bus].target[target].parameter.
2144 auto_request_sense = 1;
2147 qla1280_set_defaults(ha);
2150 qla1280_print_settings(nv);
2152 /* Disable RISC load of firmware. */
2153 ha->flags.disable_risc_code_load =
2154 nv->cntr_flags_1.disable_loading_risc_code;
2156 if (IS_ISP1040(ha)) {
2157 uint16_t hwrev, cfg1, cdma_conf, ddma_conf;
2159 hwrev = RD_REG_WORD(®->cfg_0) & ISP_CFG0_HWMSK;
2161 cfg1 = RD_REG_WORD(®->cfg_1) & ~(BIT_4 | BIT_5 | BIT_6);
2162 cdma_conf = RD_REG_WORD(®->cdma_cfg);
2163 ddma_conf = RD_REG_WORD(®->ddma_cfg);
2165 /* Busted fifo, says mjacob. */
2166 if (hwrev != ISP_CFG0_1040A)
2167 cfg1 |= nv->isp_config.fifo_threshold << 4;
2169 cfg1 |= nv->isp_config.burst_enable << 2;
2170 WRT_REG_WORD(®->cfg_1, cfg1);
2172 WRT_REG_WORD(®->cdma_cfg, cdma_conf | CDMA_CONF_BENAB);
2173 WRT_REG_WORD(®->ddma_cfg, cdma_conf | DDMA_CONF_BENAB);
2175 uint16_t cfg1, term;
2177 /* Set ISP hardware DMA burst */
2178 cfg1 = nv->isp_config.fifo_threshold << 4;
2179 cfg1 |= nv->isp_config.burst_enable << 2;
2180 /* Enable DMA arbitration on dual channel controllers */
2183 WRT_REG_WORD(®->cfg_1, cfg1);
2185 /* Set SCSI termination. */
2186 WRT_REG_WORD(®->gpio_enable,
2187 BIT_7 | BIT_3 | BIT_2 | BIT_1 | BIT_0);
2188 term = nv->termination.scsi_bus_1_control;
2189 term |= nv->termination.scsi_bus_0_control << 2;
2190 term |= nv->termination.auto_term_support << 7;
2191 RD_REG_WORD(®->id_l); /* Flush PCI write */
2192 WRT_REG_WORD(®->gpio_data, term);
2194 RD_REG_WORD(®->id_l); /* Flush PCI write */
2196 /* ISP parameter word. */
2197 mb[0] = MBC_SET_SYSTEM_PARAMETER;
2198 mb[1] = nv->isp_parameter;
2199 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2201 if (IS_ISP1x40(ha)) {
2202 /* clock rate - for qla1240 and older, only */
2203 mb[0] = MBC_SET_CLOCK_RATE;
2205 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2208 /* Firmware feature word. */
2209 mb[0] = MBC_SET_FIRMWARE_FEATURES;
2210 mb[1] = nv->firmware_feature.f.enable_fast_posting;
2211 mb[1] |= nv->firmware_feature.f.report_lvd_bus_transition << 1;
2212 mb[1] |= nv->firmware_feature.f.disable_synchronous_backoff << 5;
2213 #if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
2214 if (ia64_platform_is("sn2")) {
2215 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
2216 "workaround\n", ha->host_no);
2217 mb[1] |= nv->firmware_feature.f.unused_9 << 9; /* XXX */
2220 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2222 /* Retry count and delay. */
2223 mb[0] = MBC_SET_RETRY_COUNT;
2224 mb[1] = nv->bus[0].retry_count;
2225 mb[2] = nv->bus[0].retry_delay;
2226 mb[6] = nv->bus[1].retry_count;
2227 mb[7] = nv->bus[1].retry_delay;
2228 status |= qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 |
2229 BIT_1 | BIT_0, &mb[0]);
2231 /* ASYNC data setup time. */
2232 mb[0] = MBC_SET_ASYNC_DATA_SETUP;
2233 mb[1] = nv->bus[0].config_2.async_data_setup_time;
2234 mb[2] = nv->bus[1].config_2.async_data_setup_time;
2235 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2237 /* Active negation states. */
2238 mb[0] = MBC_SET_ACTIVE_NEGATION;
2240 if (nv->bus[0].config_2.req_ack_active_negation)
2242 if (nv->bus[0].config_2.data_line_active_negation)
2245 if (nv->bus[1].config_2.req_ack_active_negation)
2247 if (nv->bus[1].config_2.data_line_active_negation)
2249 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2251 mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
2252 mb[1] = 2; /* Reset SCSI bus and return all outstanding IO */
2253 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2256 mb[0] = MBC_SET_PCI_CONTROL;
2257 mb[1] = BIT_1; /* Data DMA Channel Burst Enable */
2258 mb[2] = BIT_1; /* Command DMA Channel Burst Enable */
2259 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2261 mb[0] = MBC_SET_TAG_AGE_LIMIT;
2263 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2265 /* Selection timeout. */
2266 mb[0] = MBC_SET_SELECTION_TIMEOUT;
2267 mb[1] = nv->bus[0].selection_timeout;
2268 mb[2] = nv->bus[1].selection_timeout;
2269 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2271 for (bus = 0; bus < ha->ports; bus++)
2272 status |= qla1280_config_bus(ha, bus);
2275 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
2277 LEAVE("qla1280_nvram_config");
2282 * Get NVRAM data word
2283 * Calculates word position in NVRAM and calls request routine to
2284 * get the word from NVRAM.
2287 * ha = adapter block pointer.
2288 * address = NVRAM word address.
2294 qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
2299 nv_cmd = address << 16;
2300 nv_cmd |= NV_READ_OP;
2302 data = le16_to_cpu(qla1280_nvram_request(ha, nv_cmd));
2304 dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
2312 * Sends read command to NVRAM and gets data from NVRAM.
2315 * ha = adapter block pointer.
2316 * nv_cmd = Bit 26 = start bit
2317 * Bit 25, 24 = opcode
2318 * Bit 23-16 = address
2319 * Bit 15-0 = write data
2325 qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
2327 struct device_reg __iomem *reg = ha->iobase;
2332 /* Send command to NVRAM. */
2335 for (cnt = 0; cnt < 11; cnt++) {
2336 if (nv_cmd & BIT_31)
2337 qla1280_nv_write(ha, NV_DATA_OUT);
2339 qla1280_nv_write(ha, 0);
2343 /* Read data from NVRAM. */
2345 for (cnt = 0; cnt < 16; cnt++) {
2346 WRT_REG_WORD(®->nvram, (NV_SELECT | NV_CLOCK));
2347 RD_REG_WORD(®->id_l); /* Flush PCI write */
2350 reg_data = RD_REG_WORD(®->nvram);
2351 if (reg_data & NV_DATA_IN)
2353 WRT_REG_WORD(®->nvram, NV_SELECT);
2354 RD_REG_WORD(®->id_l); /* Flush PCI write */
2358 /* Deselect chip. */
2360 WRT_REG_WORD(®->nvram, NV_DESELECT);
2361 RD_REG_WORD(®->id_l); /* Flush PCI write */
2368 qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
2370 struct device_reg __iomem *reg = ha->iobase;
2372 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2373 RD_REG_WORD(®->id_l); /* Flush PCI write */
2375 WRT_REG_WORD(®->nvram, data | NV_SELECT | NV_CLOCK);
2376 RD_REG_WORD(®->id_l); /* Flush PCI write */
2378 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2379 RD_REG_WORD(®->id_l); /* Flush PCI write */
2385 * Issue mailbox command and waits for completion.
2388 * ha = adapter block pointer.
2389 * mr = mailbox registers to load.
2390 * mb = data pointer for mailbox registers.
2393 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
2399 qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
2401 struct device_reg __iomem *reg = ha->iobase;
2407 uint16_t *optr, *iptr;
2408 uint16_t __iomem *mptr;
2410 DECLARE_COMPLETION(wait);
2411 struct timer_list timer;
2413 ENTER("qla1280_mailbox_command");
2415 if (ha->mailbox_wait) {
2416 printk(KERN_ERR "Warning mailbox wait already in use!\n");
2418 ha->mailbox_wait = &wait;
2421 * We really should start out by verifying that the mailbox is
2422 * available before starting sending the command data
2424 /* Load mailbox registers. */
2425 mptr = (uint16_t __iomem *) ®->mailbox0;
2427 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
2429 WRT_REG_WORD(mptr, (*iptr));
2437 /* Issue set host interrupt command. */
2439 /* set up a timer just in case we're really jammed */
2441 timer.expires = jiffies + 20*HZ;
2442 timer.data = (unsigned long)ha;
2443 timer.function = qla1280_mailbox_timeout;
2446 spin_unlock_irq(ha->host->host_lock);
2447 WRT_REG_WORD(®->host_cmd, HC_SET_HOST_INT);
2448 data = qla1280_debounce_register(®->istatus);
2450 wait_for_completion(&wait);
2451 del_timer_sync(&timer);
2453 spin_lock_irq(ha->host->host_lock);
2455 ha->mailbox_wait = NULL;
2457 /* Check for mailbox command timeout. */
2458 if (ha->mailbox_out[0] != MBS_CMD_CMP) {
2459 printk(KERN_WARNING "qla1280_mailbox_command: Command failed, "
2460 "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
2462 mb[0], ha->mailbox_out[0], RD_REG_WORD(®->istatus));
2463 printk(KERN_WARNING "m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
2464 RD_REG_WORD(®->mailbox0), RD_REG_WORD(®->mailbox1),
2465 RD_REG_WORD(®->mailbox2), RD_REG_WORD(®->mailbox3));
2466 printk(KERN_WARNING "m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
2467 RD_REG_WORD(®->mailbox4), RD_REG_WORD(®->mailbox5),
2468 RD_REG_WORD(®->mailbox6), RD_REG_WORD(®->mailbox7));
2472 /* Load return mailbox registers. */
2474 iptr = (uint16_t *) &ha->mailbox_out[0];
2475 mr = MAILBOX_REGISTER_COUNT;
2476 memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
2479 /* Go check for any response interrupts pending. */
2480 qla1280_isr(ha, &done_q);
2483 if (ha->flags.reset_marker)
2484 qla1280_rst_aen(ha);
2487 if (!list_empty(&done_q))
2488 qla1280_done(ha, &done_q);
2492 dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
2493 "0x%x ****\n", mb[0]);
2495 LEAVE("qla1280_mailbox_command");
2501 * Polls ISP for interrupts.
2504 * ha = adapter block pointer.
2507 qla1280_poll(struct scsi_qla_host *ha)
2509 struct device_reg __iomem *reg = ha->iobase;
2513 /* ENTER("qla1280_poll"); */
2515 /* Check for pending interrupts. */
2516 data = RD_REG_WORD(®->istatus);
2517 if (data & RISC_INT)
2518 qla1280_isr(ha, &done_q);
2520 if (!ha->mailbox_wait) {
2521 if (ha->flags.reset_marker)
2522 qla1280_rst_aen(ha);
2525 if (!list_empty(&done_q))
2528 /* LEAVE("qla1280_poll"); */
2533 * Issue SCSI bus reset.
2536 * ha = adapter block pointer.
2537 * bus = SCSI bus number.
2543 qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
2545 uint16_t mb[MAILBOX_REGISTER_COUNT];
2546 uint16_t reset_delay;
2549 dprintk(3, "qla1280_bus_reset: entered\n");
2551 if (qla1280_verbose)
2552 printk(KERN_INFO "scsi(%li:%i): Resetting SCSI BUS\n",
2555 reset_delay = ha->bus_settings[bus].bus_reset_delay;
2556 mb[0] = MBC_BUS_RESET;
2557 mb[1] = reset_delay;
2558 mb[2] = (uint16_t) bus;
2559 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2562 if (ha->bus_settings[bus].failed_reset_count > 2)
2563 ha->bus_settings[bus].scsi_bus_dead = 1;
2564 ha->bus_settings[bus].failed_reset_count++;
2566 spin_unlock_irq(ha->host->host_lock);
2567 ssleep(reset_delay);
2568 spin_lock_irq(ha->host->host_lock);
2570 ha->bus_settings[bus].scsi_bus_dead = 0;
2571 ha->bus_settings[bus].failed_reset_count = 0;
2572 ha->bus_settings[bus].reset_marker = 0;
2573 /* Issue marker command. */
2574 qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
2578 * We should probably call qla1280_set_target_parameters()
2579 * here as well for all devices on the bus.
2583 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
2585 dprintk(3, "qla1280_bus_reset: exiting normally\n");
2591 * qla1280_device_reset
2592 * Issue bus device reset message to the target.
2595 * ha = adapter block pointer.
2596 * bus = SCSI BUS number.
2603 qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
2605 uint16_t mb[MAILBOX_REGISTER_COUNT];
2608 ENTER("qla1280_device_reset");
2610 mb[0] = MBC_ABORT_TARGET;
2611 mb[1] = (bus ? (target | BIT_7) : target) << 8;
2613 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2615 /* Issue marker command. */
2616 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
2619 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
2621 LEAVE("qla1280_device_reset");
2626 * qla1280_abort_device
2627 * Issue an abort message to the device
2630 * ha = adapter block pointer.
2639 qla1280_abort_device(struct scsi_qla_host *ha, int bus, int target, int lun)
2641 uint16_t mb[MAILBOX_REGISTER_COUNT];
2644 ENTER("qla1280_abort_device");
2646 mb[0] = MBC_ABORT_DEVICE;
2647 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
2648 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2650 /* Issue marker command. */
2651 qla1280_marker(ha, bus, target, lun, MK_SYNC_ID_LUN);
2654 dprintk(2, "qla1280_abort_device: **** FAILED ****\n");
2656 LEAVE("qla1280_abort_device");
2661 * qla1280_abort_command
2662 * Abort command aborts a specified IOCB.
2665 * ha = adapter block pointer.
2666 * sp = SB structure pointer.
2672 qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
2674 uint16_t mb[MAILBOX_REGISTER_COUNT];
2675 unsigned int bus, target, lun;
2678 ENTER("qla1280_abort_command");
2680 bus = SCSI_BUS_32(sp->cmd);
2681 target = SCSI_TCN_32(sp->cmd);
2682 lun = SCSI_LUN_32(sp->cmd);
2684 sp->flags |= SRB_ABORT_PENDING;
2686 mb[0] = MBC_ABORT_COMMAND;
2687 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
2688 mb[2] = handle >> 16;
2689 mb[3] = handle & 0xffff;
2690 status = qla1280_mailbox_command(ha, 0x0f, &mb[0]);
2693 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
2694 sp->flags &= ~SRB_ABORT_PENDING;
2698 LEAVE("qla1280_abort_command");
2703 * qla1280_reset_adapter
2707 * ha = adapter block pointer.
2710 qla1280_reset_adapter(struct scsi_qla_host *ha)
2712 struct device_reg __iomem *reg = ha->iobase;
2714 ENTER("qla1280_reset_adapter");
2716 /* Disable ISP chip */
2717 ha->flags.online = 0;
2718 WRT_REG_WORD(®->ictrl, ISP_RESET);
2719 WRT_REG_WORD(®->host_cmd,
2720 HC_RESET_RISC | HC_RELEASE_RISC | HC_DISABLE_BIOS);
2721 RD_REG_WORD(®->id_l); /* Flush PCI write */
2723 LEAVE("qla1280_reset_adapter");
2727 * Issue marker command.
2728 * Function issues marker IOCB.
2731 * ha = adapter block pointer.
2732 * bus = SCSI BUS number
2735 * type = marker modifier
2738 qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
2740 struct mrk_entry *pkt;
2742 ENTER("qla1280_marker");
2744 /* Get request packet. */
2745 if ((pkt = (struct mrk_entry *) qla1280_req_pkt(ha))) {
2746 pkt->entry_type = MARKER_TYPE;
2747 pkt->lun = (uint8_t) lun;
2748 pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
2749 pkt->modifier = type;
2750 pkt->entry_status = 0;
2752 /* Issue command to ISP */
2753 qla1280_isp_cmd(ha);
2756 LEAVE("qla1280_marker");
2761 * qla1280_64bit_start_scsi
2762 * The start SCSI is responsible for building request packets on
2763 * request ring and modifying ISP input pointer.
2766 * ha = adapter block pointer.
2767 * sp = SB structure pointer.
2770 * 0 = success, was able to issue command.
2772 #ifdef QLA_64BIT_PTR
2774 qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
2776 struct device_reg __iomem *reg = ha->iobase;
2777 struct scsi_cmnd *cmd = sp->cmd;
2778 cmd_a64_entry_t *pkt;
2779 struct scatterlist *sg = NULL;
2781 dma_addr_t dma_handle;
2788 ENTER("qla1280_64bit_start_scsi:");
2790 /* Calculate number of entries and segments required. */
2793 sg = (struct scatterlist *) cmd->request_buffer;
2794 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
2795 cmd->sc_data_direction);
2798 req_cnt += (seg_cnt - 2) / 5;
2799 if ((seg_cnt - 2) % 5)
2802 } else if (cmd->request_bufflen) { /* If data transfer. */
2808 if ((req_cnt + 2) >= ha->req_q_cnt) {
2809 /* Calculate number of free request entries. */
2810 cnt = RD_REG_WORD(®->mailbox4);
2811 if (ha->req_ring_index < cnt)
2812 ha->req_q_cnt = cnt - ha->req_ring_index;
2815 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
2818 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
2819 ha->req_q_cnt, seg_cnt);
2821 /* If room for request in request ring. */
2822 if ((req_cnt + 2) >= ha->req_q_cnt) {
2824 dprintk(2, "qla1280_start_scsi: in-ptr=0x%x req_q_cnt="
2825 "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
2830 /* Check for room in outstanding command list. */
2831 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
2832 ha->outstanding_cmds[cnt] != 0; cnt++);
2834 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
2836 dprintk(2, "qla1280_start_scsi: NO ROOM IN "
2837 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
2841 ha->outstanding_cmds[cnt] = sp;
2842 ha->req_q_cnt -= req_cnt;
2843 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
2845 dprintk(2, "start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
2846 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
2847 dprintk(2, " bus %i, target %i, lun %i\n",
2848 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2849 qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
2852 * Build command packet.
2854 pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
2856 pkt->entry_type = COMMAND_A64_TYPE;
2857 pkt->entry_count = (uint8_t) req_cnt;
2858 pkt->sys_define = (uint8_t) ha->req_ring_index;
2859 pkt->entry_status = 0;
2860 pkt->handle = cpu_to_le32(cnt);
2862 /* Zero out remaining portion of packet. */
2863 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
2865 /* Set ISP command timeout. */
2866 pkt->timeout = cpu_to_le16(30);
2868 /* Set device target ID and LUN */
2869 pkt->lun = SCSI_LUN_32(cmd);
2870 pkt->target = SCSI_BUS_32(cmd) ?
2871 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
2873 /* Enable simple tag queuing if device supports it. */
2874 if (cmd->device->simple_tags)
2875 pkt->control_flags |= cpu_to_le16(BIT_3);
2877 /* Load SCSI command packet. */
2878 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
2879 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
2880 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
2882 /* Set transfer direction. */
2883 dir = qla1280_data_direction(cmd);
2884 pkt->control_flags |= cpu_to_le16(dir);
2886 /* Set total data segment count. */
2887 pkt->dseg_count = cpu_to_le16(seg_cnt);
2890 * Load data segments.
2892 if (seg_cnt) { /* If data transfer. */
2893 /* Setup packet address segment pointer. */
2894 dword_ptr = (u32 *)&pkt->dseg_0_address;
2896 if (cmd->use_sg) { /* If scatter gather */
2897 /* Load command entry data segments. */
2898 for (cnt = 0; cnt < 2 && seg_cnt; cnt++, seg_cnt--) {
2899 dma_handle = sg_dma_address(sg);
2900 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2901 if (ha->flags.use_pci_vchannel)
2902 sn_pci_set_vchan(ha->pdev,
2903 (unsigned long *)&dma_handle,
2907 cpu_to_le32(pci_dma_lo32(dma_handle));
2909 cpu_to_le32(pci_dma_hi32(dma_handle));
2910 *dword_ptr++ = cpu_to_le32(sg_dma_len(sg));
2912 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
2913 cpu_to_le32(pci_dma_hi32(dma_handle)),
2914 cpu_to_le32(pci_dma_lo32(dma_handle)),
2915 cpu_to_le32(sg_dma_len(sg)));
2917 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
2918 "command packet data - b %i, t %i, l %i \n",
2919 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
2921 qla1280_dump_buffer(5, (char *)pkt,
2922 REQUEST_ENTRY_SIZE);
2925 * Build continuation packets.
2927 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
2928 "remains\n", seg_cnt);
2930 while (seg_cnt > 0) {
2931 /* Adjust ring index. */
2932 ha->req_ring_index++;
2933 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
2934 ha->req_ring_index = 0;
2935 ha->request_ring_ptr =
2938 ha->request_ring_ptr++;
2940 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
2942 /* Zero out packet. */
2943 memset(pkt, 0, REQUEST_ENTRY_SIZE);
2945 /* Load packet defaults. */
2946 ((struct cont_a64_entry *) pkt)->entry_type =
2948 ((struct cont_a64_entry *) pkt)->entry_count = 1;
2949 ((struct cont_a64_entry *) pkt)->sys_define =
2950 (uint8_t)ha->req_ring_index;
2951 /* Setup packet address segment pointer. */
2953 (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
2955 /* Load continuation entry data segments. */
2956 for (cnt = 0; cnt < 5 && seg_cnt;
2958 dma_handle = sg_dma_address(sg);
2959 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2960 if (ha->flags.use_pci_vchannel)
2961 sn_pci_set_vchan(ha->pdev,
2962 (unsigned long *)&dma_handle,
2966 cpu_to_le32(pci_dma_lo32(dma_handle));
2968 cpu_to_le32(pci_dma_hi32(dma_handle));
2970 cpu_to_le32(sg_dma_len(sg));
2971 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
2972 cpu_to_le32(pci_dma_hi32(dma_handle)),
2973 cpu_to_le32(pci_dma_lo32(dma_handle)),
2974 cpu_to_le32(sg_dma_len(sg)));
2977 dprintk(5, "qla1280_64bit_start_scsi: "
2978 "continuation packet data - b %i, t "
2979 "%i, l %i \n", SCSI_BUS_32(cmd),
2980 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2981 qla1280_dump_buffer(5, (char *)pkt,
2982 REQUEST_ENTRY_SIZE);
2984 } else { /* No scatter gather data transfer */
2985 dma_handle = pci_map_single(ha->pdev,
2986 cmd->request_buffer,
2987 cmd->request_bufflen,
2988 cmd->sc_data_direction);
2990 sp->saved_dma_handle = dma_handle;
2991 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2992 if (ha->flags.use_pci_vchannel)
2993 sn_pci_set_vchan(ha->pdev,
2994 (unsigned long *)&dma_handle,
2997 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
2998 *dword_ptr++ = cpu_to_le32(pci_dma_hi32(dma_handle));
2999 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3001 dprintk(5, "qla1280_64bit_start_scsi: No scatter/"
3002 "gather command packet data - b %i, t %i, "
3003 "l %i \n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3005 qla1280_dump_buffer(5, (char *)pkt,
3006 REQUEST_ENTRY_SIZE);
3008 } else { /* No data transfer */
3009 dprintk(5, "qla1280_64bit_start_scsi: No data, command "
3010 "packet data - b %i, t %i, l %i \n",
3011 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3012 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3014 /* Adjust ring index. */
3015 ha->req_ring_index++;
3016 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3017 ha->req_ring_index = 0;
3018 ha->request_ring_ptr = ha->request_ring;
3020 ha->request_ring_ptr++;
3022 /* Set chip new ring index. */
3024 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
3025 sp->flags |= SRB_SENT;
3027 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3028 /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
3033 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
3035 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
3039 #else /* !QLA_64BIT_PTR */
3042 * qla1280_32bit_start_scsi
3043 * The start SCSI is responsible for building request packets on
3044 * request ring and modifying ISP input pointer.
3046 * The Qlogic firmware interface allows every queue slot to have a SCSI
3047 * command and up to 4 scatter/gather (SG) entries. If we need more
3048 * than 4 SG entries, then continuation entries are used that can
3049 * hold another 7 entries each. The start routine determines if there
3050 * is eought empty slots then build the combination of requests to
3051 * fulfill the OS request.
3054 * ha = adapter block pointer.
3055 * sp = SCSI Request Block structure pointer.
3058 * 0 = success, was able to issue command.
3061 qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3063 struct device_reg __iomem *reg = ha->iobase;
3064 struct scsi_cmnd *cmd = sp->cmd;
3065 struct cmd_entry *pkt;
3066 struct scatterlist *sg = NULL;
3072 dma_addr_t dma_handle;
3075 ENTER("qla1280_32bit_start_scsi");
3077 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
3080 /* Calculate number of entries and segments required. */
3084 * We must build an SG list in adapter format, as the kernel's
3085 * SG list cannot be used directly because of data field size
3086 * (__alpha__) differences and the kernel SG list uses virtual
3087 * addresses where we need physical addresses.
3089 sg = (struct scatterlist *) cmd->request_buffer;
3090 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3091 cmd->sc_data_direction);
3094 * if greater than four sg entries then we need to allocate
3095 * continuation entries
3098 req_cnt += (seg_cnt - 4) / 7;
3099 if ((seg_cnt - 4) % 7)
3102 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3103 cmd, seg_cnt, req_cnt);
3104 } else if (cmd->request_bufflen) { /* If data transfer. */
3105 dprintk(3, "No S/G transfer t=%x cmd=%p len=%x CDB=%x\n",
3106 SCSI_TCN_32(cmd), cmd, cmd->request_bufflen,
3110 /* dprintk(1, "No data transfer \n"); */
3114 if ((req_cnt + 2) >= ha->req_q_cnt) {
3115 /* Calculate number of free request entries. */
3116 cnt = RD_REG_WORD(®->mailbox4);
3117 if (ha->req_ring_index < cnt)
3118 ha->req_q_cnt = cnt - ha->req_ring_index;
3121 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3124 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3125 ha->req_q_cnt, seg_cnt);
3126 /* If room for request in request ring. */
3127 if ((req_cnt + 2) >= ha->req_q_cnt) {
3129 dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
3130 "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
3131 ha->req_q_cnt, req_cnt);
3135 /* Check for empty slot in outstanding command list. */
3136 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3137 (ha->outstanding_cmds[cnt] != 0); cnt++) ;
3139 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3141 dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
3142 "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
3146 CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
3147 ha->outstanding_cmds[cnt] = sp;
3148 ha->req_q_cnt -= req_cnt;
3151 * Build command packet.
3153 pkt = (struct cmd_entry *) ha->request_ring_ptr;
3155 pkt->entry_type = COMMAND_TYPE;
3156 pkt->entry_count = (uint8_t) req_cnt;
3157 pkt->sys_define = (uint8_t) ha->req_ring_index;
3158 pkt->entry_status = 0;
3159 pkt->handle = cpu_to_le32(cnt);
3161 /* Zero out remaining portion of packet. */
3162 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3164 /* Set ISP command timeout. */
3165 pkt->timeout = cpu_to_le16(30);
3167 /* Set device target ID and LUN */
3168 pkt->lun = SCSI_LUN_32(cmd);
3169 pkt->target = SCSI_BUS_32(cmd) ?
3170 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3172 /* Enable simple tag queuing if device supports it. */
3173 if (cmd->device->simple_tags)
3174 pkt->control_flags |= cpu_to_le16(BIT_3);
3176 /* Load SCSI command packet. */
3177 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3178 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3180 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3181 /* Set transfer direction. */
3182 dir = qla1280_data_direction(cmd);
3183 pkt->control_flags |= cpu_to_le16(dir);
3185 /* Set total data segment count. */
3186 pkt->dseg_count = cpu_to_le16(seg_cnt);
3189 * Load data segments.
3192 /* Setup packet address segment pointer. */
3193 dword_ptr = &pkt->dseg_0_address;
3195 if (cmd->use_sg) { /* If scatter gather */
3196 dprintk(3, "Building S/G data segments..\n");
3197 qla1280_dump_buffer(1, (char *)sg, 4 * 16);
3199 /* Load command entry data segments. */
3200 for (cnt = 0; cnt < 4 && seg_cnt; cnt++, seg_cnt--) {
3202 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3204 cpu_to_le32(sg_dma_len(sg));
3205 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3206 (pci_dma_lo32(sg_dma_address(sg))),
3211 * Build continuation packets.
3213 dprintk(3, "S/G Building Continuation"
3214 "...seg_cnt=0x%x remains\n", seg_cnt);
3215 while (seg_cnt > 0) {
3216 /* Adjust ring index. */
3217 ha->req_ring_index++;
3218 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3219 ha->req_ring_index = 0;
3220 ha->request_ring_ptr =
3223 ha->request_ring_ptr++;
3225 pkt = (struct cmd_entry *)ha->request_ring_ptr;
3227 /* Zero out packet. */
3228 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3230 /* Load packet defaults. */
3231 ((struct cont_entry *) pkt)->
3232 entry_type = CONTINUE_TYPE;
3233 ((struct cont_entry *) pkt)->entry_count = 1;
3235 ((struct cont_entry *) pkt)->sys_define =
3236 (uint8_t) ha->req_ring_index;
3238 /* Setup packet address segment pointer. */
3240 &((struct cont_entry *) pkt)->dseg_0_address;
3242 /* Load continuation entry data segments. */
3243 for (cnt = 0; cnt < 7 && seg_cnt;
3246 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3248 cpu_to_le32(sg_dma_len(sg));
3250 "S/G Segment Cont. phys_addr=0x%x, "
3252 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
3253 cpu_to_le32(sg_dma_len(sg)));
3256 dprintk(5, "qla1280_32bit_start_scsi: "
3257 "continuation packet data - "
3258 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
3259 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3260 qla1280_dump_buffer(5, (char *)pkt,
3261 REQUEST_ENTRY_SIZE);
3263 } else { /* No S/G data transfer */
3264 dma_handle = pci_map_single(ha->pdev,
3265 cmd->request_buffer,
3266 cmd->request_bufflen,
3267 cmd->sc_data_direction);
3268 sp->saved_dma_handle = dma_handle;
3270 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3271 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3273 } else { /* No data transfer at all */
3274 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
3275 "packet data - \n");
3276 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3278 dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
3279 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3280 REQUEST_ENTRY_SIZE);
3282 /* Adjust ring index. */
3283 ha->req_ring_index++;
3284 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3285 ha->req_ring_index = 0;
3286 ha->request_ring_ptr = ha->request_ring;
3288 ha->request_ring_ptr++;
3290 /* Set chip new ring index. */
3291 dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
3292 "for pending command\n");
3293 sp->flags |= SRB_SENT;
3295 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3296 /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
3301 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
3303 LEAVE("qla1280_32bit_start_scsi");
3311 * Function is responsible for locking ring and
3312 * getting a zeroed out request packet.
3315 * ha = adapter block pointer.
3318 * 0 = failed to get slot.
3321 qla1280_req_pkt(struct scsi_qla_host *ha)
3323 struct device_reg __iomem *reg = ha->iobase;
3324 request_t *pkt = NULL;
3328 ENTER("qla1280_req_pkt");
3331 * This can be called from interrupt context, damn it!!!
3333 /* Wait for 30 seconds for slot. */
3334 for (timer = 15000000; timer; timer--) {
3335 if (ha->req_q_cnt > 0) {
3336 /* Calculate number of free request entries. */
3337 cnt = RD_REG_WORD(®->mailbox4);
3338 if (ha->req_ring_index < cnt)
3339 ha->req_q_cnt = cnt - ha->req_ring_index;
3342 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3345 /* Found empty request ring slot? */
3346 if (ha->req_q_cnt > 0) {
3348 pkt = ha->request_ring_ptr;
3350 /* Zero out packet. */
3351 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3354 * How can this be right when we have a ring
3357 /* Set system defined field. */
3358 pkt->sys_define = (uint8_t) ha->req_ring_index;
3360 /* Set entry count. */
3361 pkt->entry_count = 1;
3368 /* Check for pending interrupts. */
3373 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
3375 dprintk(3, "qla1280_req_pkt: exiting normally\n");
3382 * Function is responsible for modifying ISP input pointer.
3383 * Releases ring lock.
3386 * ha = adapter block pointer.
3389 qla1280_isp_cmd(struct scsi_qla_host *ha)
3391 struct device_reg __iomem *reg = ha->iobase;
3393 ENTER("qla1280_isp_cmd");
3395 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
3396 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3397 REQUEST_ENTRY_SIZE);
3399 /* Adjust ring index. */
3400 ha->req_ring_index++;
3401 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3402 ha->req_ring_index = 0;
3403 ha->request_ring_ptr = ha->request_ring;
3405 ha->request_ring_ptr++;
3408 * Update request index to mailbox4 (Request Queue In).
3409 * The mmiowb() ensures that this write is ordered with writes by other
3410 * CPUs. Without the mmiowb(), it is possible for the following:
3411 * CPUA posts write of index 5 to mailbox4
3412 * CPUA releases host lock
3413 * CPUB acquires host lock
3414 * CPUB posts write of index 6 to mailbox4
3415 * On PCI bus, order reverses and write of 6 posts, then index 5,
3416 * causing chip to issue full queue of stale commands
3417 * The mmiowb() prevents future writes from crossing the barrier.
3418 * See Documentation/DocBook/deviceiobook.tmpl for more information.
3420 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3423 LEAVE("qla1280_isp_cmd");
3426 /****************************************************************************/
3427 /* Interrupt Service Routine. */
3428 /****************************************************************************/
3430 /****************************************************************************
3432 * Calls I/O done on command completion.
3435 * ha = adapter block pointer.
3436 * done_q = done queue.
3437 ****************************************************************************/
3439 qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
3441 struct device_reg __iomem *reg = ha->iobase;
3442 struct response *pkt;
3443 struct srb *sp = NULL;
3444 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
3449 ENTER("qla1280_isr");
3451 istatus = RD_REG_WORD(®->istatus);
3452 if (!(istatus & (RISC_INT | PCI_INT)))
3455 /* Save mailbox register 5 */
3456 mailbox[5] = RD_REG_WORD(®->mailbox5);
3458 /* Check for mailbox interrupt. */
3460 mailbox[0] = RD_REG_WORD_dmasync(®->semaphore);
3462 if (mailbox[0] & BIT_0) {
3463 /* Get mailbox data. */
3464 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
3467 *wptr++ = RD_REG_WORD(®->mailbox0);
3468 *wptr++ = RD_REG_WORD(®->mailbox1);
3469 *wptr = RD_REG_WORD(®->mailbox2);
3470 if (mailbox[0] != MBA_SCSI_COMPLETION) {
3472 *wptr++ = RD_REG_WORD(®->mailbox3);
3473 *wptr++ = RD_REG_WORD(®->mailbox4);
3475 *wptr++ = RD_REG_WORD(®->mailbox6);
3476 *wptr = RD_REG_WORD(®->mailbox7);
3479 /* Release mailbox registers. */
3481 WRT_REG_WORD(®->semaphore, 0);
3482 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3484 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
3487 /* Handle asynchronous event */
3488 switch (mailbox[0]) {
3489 case MBA_SCSI_COMPLETION: /* Response completion */
3490 dprintk(5, "qla1280_isr: mailbox SCSI response "
3493 if (ha->flags.online) {
3494 /* Get outstanding command index. */
3495 index = mailbox[2] << 16 | mailbox[1];
3497 /* Validate handle. */
3498 if (index < MAX_OUTSTANDING_COMMANDS)
3499 sp = ha->outstanding_cmds[index];
3504 /* Free outstanding command slot. */
3505 ha->outstanding_cmds[index] = NULL;
3507 /* Save ISP completion status */
3508 CMD_RESULT(sp->cmd) = 0;
3510 /* Place block on done queue */
3511 list_add_tail(&sp->list, done_q);
3514 * If we get here we have a real problem!
3517 "qla1280: ISP invalid handle");
3522 case MBA_BUS_RESET: /* SCSI Bus Reset */
3523 ha->flags.reset_marker = 1;
3524 index = mailbox[6] & BIT_0;
3525 ha->bus_settings[index].reset_marker = 1;
3527 printk(KERN_DEBUG "qla1280_isr(): index %i "
3528 "asynchronous BUS_RESET\n", index);
3531 case MBA_SYSTEM_ERR: /* System Error */
3533 "qla1280: ISP System Error - mbx1=%xh, mbx2="
3534 "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
3538 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
3540 "qla1280: ISP Request Transfer Error\n");
3543 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
3545 "qla1280: ISP Response Transfer Error\n");
3548 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
3549 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
3552 case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
3554 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
3557 case MBA_DEVICE_RESET: /* Bus Device Reset */
3558 printk(KERN_INFO "qla1280_isr(): asynchronous "
3559 "BUS_DEVICE_RESET\n");
3561 ha->flags.reset_marker = 1;
3562 index = mailbox[6] & BIT_0;
3563 ha->bus_settings[index].reset_marker = 1;
3566 case MBA_BUS_MODE_CHANGE:
3568 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
3572 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
3573 if (mailbox[0] < MBA_ASYNC_EVENT) {
3575 memcpy((uint16_t *) ha->mailbox_out, wptr,
3576 MAILBOX_REGISTER_COUNT *
3579 if(ha->mailbox_wait != NULL)
3580 complete(ha->mailbox_wait);
3585 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3589 * We will receive interrupts during mailbox testing prior to
3590 * the card being marked online, hence the double check.
3592 if (!(ha->flags.online && !ha->mailbox_wait)) {
3593 dprintk(2, "qla1280_isr: Response pointer Error\n");
3597 if (mailbox[5] >= RESPONSE_ENTRY_CNT)
3600 while (ha->rsp_ring_index != mailbox[5]) {
3601 pkt = ha->response_ring_ptr;
3603 dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
3604 " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
3605 dprintk(5,"qla1280_isr: response packet data\n");
3606 qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
3608 if (pkt->entry_type == STATUS_TYPE) {
3609 if ((le16_to_cpu(pkt->scsi_status) & 0xff)
3610 || pkt->comp_status || pkt->entry_status) {
3611 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3612 "0x%x mailbox[5] = 0x%x, comp_status "
3613 "= 0x%x, scsi_status = 0x%x\n",
3614 ha->rsp_ring_index, mailbox[5],
3615 le16_to_cpu(pkt->comp_status),
3616 le16_to_cpu(pkt->scsi_status));
3619 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3620 "0x%x, mailbox[5] = 0x%x\n",
3621 ha->rsp_ring_index, mailbox[5]);
3622 dprintk(2, "qla1280_isr: response packet data\n");
3623 qla1280_dump_buffer(2, (char *)pkt,
3624 RESPONSE_ENTRY_SIZE);
3627 if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
3628 dprintk(2, "status: Cmd %p, handle %i\n",
3629 ha->outstanding_cmds[pkt->handle]->cmd,
3631 if (pkt->entry_type == STATUS_TYPE)
3632 qla1280_status_entry(ha, pkt, done_q);
3634 qla1280_error_entry(ha, pkt, done_q);
3635 /* Adjust ring index. */
3636 ha->rsp_ring_index++;
3637 if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
3638 ha->rsp_ring_index = 0;
3639 ha->response_ring_ptr = ha->response_ring;
3641 ha->response_ring_ptr++;
3642 WRT_REG_WORD(®->mailbox5, ha->rsp_ring_index);
3647 LEAVE("qla1280_isr");
3652 * Processes asynchronous reset.
3655 * ha = adapter block pointer.
3658 qla1280_rst_aen(struct scsi_qla_host *ha)
3662 ENTER("qla1280_rst_aen");
3664 if (ha->flags.online && !ha->flags.reset_active &&
3665 !ha->flags.abort_isp_active) {
3666 ha->flags.reset_active = 1;
3667 while (ha->flags.reset_marker) {
3668 /* Issue marker command. */
3669 ha->flags.reset_marker = 0;
3670 for (bus = 0; bus < ha->ports &&
3671 !ha->flags.reset_marker; bus++) {
3672 if (ha->bus_settings[bus].reset_marker) {
3673 ha->bus_settings[bus].reset_marker = 0;
3674 qla1280_marker(ha, bus, 0, 0,
3681 LEAVE("qla1280_rst_aen");
3686 * qla1280_status_entry
3687 * Processes received ISP status entry.
3690 * ha = adapter block pointer.
3691 * pkt = entry pointer.
3692 * done_q = done queue.
3695 qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
3696 struct list_head *done_q)
3698 unsigned int bus, target, lun;
3701 struct scsi_cmnd *cmd;
3702 uint32_t handle = le32_to_cpu(pkt->handle);
3703 uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
3704 uint16_t comp_status = le16_to_cpu(pkt->comp_status);
3706 ENTER("qla1280_status_entry");
3708 /* Validate handle. */
3709 if (handle < MAX_OUTSTANDING_COMMANDS)
3710 sp = ha->outstanding_cmds[handle];
3715 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
3719 /* Free outstanding command slot. */
3720 ha->outstanding_cmds[handle] = NULL;
3724 /* Generate LU queue on cntrl, target, LUN */
3725 bus = SCSI_BUS_32(cmd);
3726 target = SCSI_TCN_32(cmd);
3727 lun = SCSI_LUN_32(cmd);
3729 if (comp_status || scsi_status) {
3730 dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
3731 "0x%x, handle = 0x%x\n", comp_status,
3732 scsi_status, handle);
3735 /* Target busy or queue full */
3736 if ((scsi_status & 0xFF) == SAM_STAT_TASK_SET_FULL ||
3737 (scsi_status & 0xFF) == SAM_STAT_BUSY) {
3738 CMD_RESULT(cmd) = scsi_status & 0xff;
3741 /* Save ISP completion status */
3742 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
3744 if (scsi_status & SAM_STAT_CHECK_CONDITION) {
3745 if (comp_status != CS_ARS_FAILED) {
3746 uint16_t req_sense_length =
3747 le16_to_cpu(pkt->req_sense_length);
3748 if (req_sense_length < CMD_SNSLEN(cmd))
3749 sense_sz = req_sense_length;
3752 * scsi_cmnd->sense_buffer is
3753 * 64 bytes, why only copy 63?
3754 * This looks wrong! /Jes
3756 sense_sz = CMD_SNSLEN(cmd) - 1;
3758 memcpy(cmd->sense_buffer,
3759 &pkt->req_sense_data, sense_sz);
3762 memset(cmd->sense_buffer + sense_sz, 0,
3763 sizeof(cmd->sense_buffer) - sense_sz);
3765 dprintk(2, "qla1280_status_entry: Check "
3766 "condition Sense data, b %i, t %i, "
3767 "l %i\n", bus, target, lun);
3769 qla1280_dump_buffer(2,
3770 (char *)cmd->sense_buffer,
3775 /* Place command on done queue. */
3776 list_add_tail(&sp->list, done_q);
3778 LEAVE("qla1280_status_entry");
3782 * qla1280_error_entry
3783 * Processes error entry.
3786 * ha = adapter block pointer.
3787 * pkt = entry pointer.
3788 * done_q = done queue.
3791 qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
3792 struct list_head *done_q)
3795 uint32_t handle = le32_to_cpu(pkt->handle);
3797 ENTER("qla1280_error_entry");
3799 if (pkt->entry_status & BIT_3)
3800 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
3801 else if (pkt->entry_status & BIT_2)
3802 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
3803 else if (pkt->entry_status & BIT_1)
3804 dprintk(2, "qla1280_error_entry: FULL flag error\n");
3806 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
3808 /* Validate handle. */
3809 if (handle < MAX_OUTSTANDING_COMMANDS)
3810 sp = ha->outstanding_cmds[handle];
3815 /* Free outstanding command slot. */
3816 ha->outstanding_cmds[handle] = NULL;
3818 /* Bad payload or header */
3819 if (pkt->entry_status & (BIT_3 + BIT_2)) {
3820 /* Bad payload or header, set error status. */
3821 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
3822 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
3823 } else if (pkt->entry_status & BIT_1) { /* FULL flag */
3824 CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
3826 /* Set error status. */
3827 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
3830 /* Place command on done queue. */
3831 list_add_tail(&sp->list, done_q);
3833 #ifdef QLA_64BIT_PTR
3834 else if (pkt->entry_type == COMMAND_A64_TYPE) {
3835 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
3839 LEAVE("qla1280_error_entry");
3844 * Resets ISP and aborts all outstanding commands.
3847 * ha = adapter block pointer.
3853 qla1280_abort_isp(struct scsi_qla_host *ha)
3855 struct device_reg __iomem *reg = ha->iobase;
3861 ENTER("qla1280_abort_isp");
3863 if (ha->flags.abort_isp_active || !ha->flags.online)
3866 ha->flags.abort_isp_active = 1;
3868 /* Disable ISP interrupts. */
3869 qla1280_disable_intrs(ha);
3870 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
3871 RD_REG_WORD(®->id_l);
3873 printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
3875 /* Dequeue all commands in outstanding command list. */
3876 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3877 struct scsi_cmnd *cmd;
3878 sp = ha->outstanding_cmds[cnt];
3882 CMD_RESULT(cmd) = DID_RESET << 16;
3885 ha->outstanding_cmds[cnt] = NULL;
3887 (*cmd->scsi_done)(cmd);
3893 status = qla1280_load_firmware(ha);
3897 /* Setup adapter based on NVRAM parameters. */
3898 qla1280_nvram_config (ha);
3900 status = qla1280_init_rings(ha);
3904 /* Issue SCSI reset. */
3905 for (bus = 0; bus < ha->ports; bus++)
3906 qla1280_bus_reset(ha, bus);
3908 ha->flags.abort_isp_active = 0;
3912 "qla1280: ISP error recovery failed, board disabled");
3913 qla1280_reset_adapter(ha);
3914 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
3917 LEAVE("qla1280_abort_isp");
3923 * qla1280_debounce_register
3924 * Debounce register.
3927 * port = register address.
3933 qla1280_debounce_register(volatile u16 __iomem * addr)
3938 ret = RD_REG_WORD(addr);
3939 ret2 = RD_REG_WORD(addr);
3946 ret = RD_REG_WORD(addr);
3947 ret2 = RD_REG_WORD(addr);
3948 } while (ret != ret2);
3954 /************************************************************************
3955 * qla1280_check_for_dead_scsi_bus *
3957 * This routine checks for a dead SCSI bus *
3958 ************************************************************************/
3959 #define SET_SXP_BANK 0x0100
3960 #define SCSI_PHASE_INVALID 0x87FF
3962 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
3964 uint16_t config_reg, scsi_control;
3965 struct device_reg __iomem *reg = ha->iobase;
3967 if (ha->bus_settings[bus].scsi_bus_dead) {
3968 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
3969 config_reg = RD_REG_WORD(®->cfg_1);
3970 WRT_REG_WORD(®->cfg_1, SET_SXP_BANK);
3971 scsi_control = RD_REG_WORD(®->scsiControlPins);
3972 WRT_REG_WORD(®->cfg_1, config_reg);
3973 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
3975 if (scsi_control == SCSI_PHASE_INVALID) {
3976 ha->bus_settings[bus].scsi_bus_dead = 1;
3978 CMD_RESULT(cp) = DID_NO_CONNECT << 16;
3979 CMD_HANDLE(cp) = INVALID_HANDLE;
3980 /* ha->actthreads--; */
3982 (*(cp)->scsi_done)(cp);
3984 return 1; /* bus is dead */
3986 ha->bus_settings[bus].scsi_bus_dead = 0;
3987 ha->bus_settings[bus].failed_reset_count = 0;
3990 return 0; /* bus is not dead */
3994 qla1280_get_target_parameters(struct scsi_qla_host *ha,
3995 struct scsi_device *device)
3997 uint16_t mb[MAILBOX_REGISTER_COUNT];
3998 int bus, target, lun;
4000 bus = device->channel;
4001 target = device->id;
4005 mb[0] = MBC_GET_TARGET_PARAMETERS;
4006 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
4008 qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
4011 printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
4014 printk(" Sync: period %d, offset %d",
4015 (mb[3] & 0xff), (mb[3] >> 8));
4018 if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
4023 if (device->simple_tags)
4024 printk(", Tagged queuing: depth %d", device->queue_depth);
4031 __qla1280_dump_buffer(char *b, int size)
4036 printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
4037 "Bh Ch Dh Eh Fh\n");
4038 printk(KERN_DEBUG "---------------------------------------------"
4039 "------------------\n");
4041 for (cnt = 0; cnt < size;) {
4044 printk("0x%02x", c);
4055 /**************************************************************************
4056 * ql1280_print_scsi_cmd
4058 **************************************************************************/
4060 __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
4062 struct scsi_qla_host *ha;
4063 struct Scsi_Host *host = CMD_HOST(cmd);
4065 /* struct scatterlist *sg; */
4068 ha = (struct scsi_qla_host *)host->hostdata;
4070 sp = (struct srb *)CMD_SP(cmd);
4071 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
4072 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
4073 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
4076 for (i = 0; i < cmd->cmd_len; i++) {
4077 printk("0x%02x ", cmd->cmnd[i]);
4079 printk(" seg_cnt =%d\n", cmd->use_sg);
4080 printk(" request buffer=0x%p, request buffer len=0x%x\n",
4081 cmd->request_buffer, cmd->request_bufflen);
4084 sg = (struct scatterlist *) cmd->request_buffer;
4085 printk(" SG buffer: \n");
4086 qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
4088 printk(" tag=%d, transfersize=0x%x \n",
4089 cmd->tag, cmd->transfersize);
4090 printk(" Pid=%li, SP=0x%p\n", cmd->pid, CMD_SP(cmd));
4091 printk(" underflow size = 0x%x, direction=0x%x\n",
4092 cmd->underflow, cmd->sc_data_direction);
4095 /**************************************************************************
4096 * ql1280_dump_device
4098 **************************************************************************/
4100 ql1280_dump_device(struct scsi_qla_host *ha)
4103 struct scsi_cmnd *cp;
4107 printk(KERN_DEBUG "Outstanding Commands on controller:\n");
4109 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
4110 if ((sp = ha->outstanding_cmds[i]) == NULL)
4112 if ((cp = sp->cmd) == NULL)
4114 qla1280_print_scsi_cmd(1, cp);
4129 struct setup_tokens {
4134 static struct setup_tokens setup_token[] __initdata =
4136 { "nvram", TOKEN_NVRAM },
4137 { "sync", TOKEN_SYNC },
4138 { "wide", TOKEN_WIDE },
4139 { "ppr", TOKEN_PPR },
4140 { "verbose", TOKEN_VERBOSE },
4141 { "debug", TOKEN_DEBUG },
4145 /**************************************************************************
4148 * Handle boot parameters. This really needs to be changed so one
4149 * can specify per adapter parameters.
4150 **************************************************************************/
4152 qla1280_setup(char *s)
4160 while (cp && (ptr = strchr(cp, ':'))) {
4162 if (!strcmp(ptr, "yes")) {
4165 } else if (!strcmp(ptr, "no")) {
4169 val = simple_strtoul(ptr, &ptr, 0);
4171 switch ((toke = qla1280_get_token(cp))) {
4174 driver_setup.no_nvram = 1;
4178 driver_setup.no_sync = 1;
4179 else if (val != 0x10000)
4180 driver_setup.sync_mask = val;
4184 driver_setup.no_wide = 1;
4185 else if (val != 0x10000)
4186 driver_setup.wide_mask = val;
4190 driver_setup.no_ppr = 1;
4191 else if (val != 0x10000)
4192 driver_setup.ppr_mask = val;
4195 qla1280_verbose = val;
4198 printk(KERN_INFO "qla1280: unknown boot option %s\n",
4202 cp = strchr(ptr, ';');
4214 qla1280_get_token(char *str)
4220 sep = strchr(str, ':');
4223 for (i = 0; i < ARRAY_SIZE(setup_token); i++) {
4224 if (!strncmp(setup_token[i].token, str, (sep - str))) {
4225 ret = setup_token[i].val;
4235 static struct scsi_host_template qla1280_driver_template = {
4236 .module = THIS_MODULE,
4237 .proc_name = "qla1280",
4238 .name = "Qlogic ISP 1280/12160",
4239 .info = qla1280_info,
4240 .slave_configure = qla1280_slave_configure,
4241 .queuecommand = qla1280_queuecommand,
4242 .eh_abort_handler = qla1280_eh_abort,
4243 .eh_device_reset_handler= qla1280_eh_device_reset,
4244 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4245 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4246 .bios_param = qla1280_biosparam,
4247 .can_queue = 0xfffff,
4249 .sg_tablesize = SG_ALL,
4251 .use_clustering = ENABLE_CLUSTERING,
4255 static int __devinit
4256 qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4258 int devnum = id->driver_data;
4259 struct qla_boards *bdp = &ql1280_board_tbl[devnum];
4260 struct Scsi_Host *host;
4261 struct scsi_qla_host *ha;
4262 int error = -ENODEV;
4264 /* Bypass all AMI SUBSYS VENDOR IDs */
4265 if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
4267 "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
4271 printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
4272 bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
4274 if (pci_enable_device(pdev)) {
4276 "qla1280: Failed to enabled pci device, aborting.\n");
4280 pci_set_master(pdev);
4283 host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
4286 "qla1280: Failed to register host, aborting.\n");
4287 goto error_disable_device;
4290 ha = (struct scsi_qla_host *)host->hostdata;
4291 memset(ha, 0, sizeof(struct scsi_qla_host));
4294 ha->devnum = devnum; /* specifies microcode load address */
4296 #ifdef QLA_64BIT_PTR
4297 if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) {
4298 if (pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK)) {
4299 printk(KERN_WARNING "scsi(%li): Unable to set a "
4300 "suitable DMA mask - aborting\n", ha->host_no);
4302 goto error_free_irq;
4305 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4308 if (pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK)) {
4309 printk(KERN_WARNING "scsi(%li): Unable to set a "
4310 "suitable DMA mask - aborting\n", ha->host_no);
4312 goto error_free_irq;
4316 ha->request_ring = pci_alloc_consistent(ha->pdev,
4317 ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
4319 if (!ha->request_ring) {
4320 printk(KERN_INFO "qla1280: Failed to get request memory\n");
4321 goto error_put_host;
4324 ha->response_ring = pci_alloc_consistent(ha->pdev,
4325 ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
4327 if (!ha->response_ring) {
4328 printk(KERN_INFO "qla1280: Failed to get response memory\n");
4329 goto error_free_request_ring;
4332 ha->ports = bdp->numPorts;
4335 ha->host_no = host->host_no;
4337 host->irq = pdev->irq;
4338 host->max_channel = bdp->numPorts - 1;
4339 host->max_lun = MAX_LUNS - 1;
4340 host->max_id = MAX_TARGETS;
4341 host->max_sectors = 1024;
4342 host->unique_id = host->host_no;
4346 #if MEMORY_MAPPED_IO
4347 ha->mmpbase = ioremap(pci_resource_start(ha->pdev, 1),
4348 pci_resource_len(ha->pdev, 1));
4350 printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
4351 goto error_free_response_ring;
4354 host->base = (unsigned long)ha->mmpbase;
4355 ha->iobase = (struct device_reg __iomem *)ha->mmpbase;
4357 host->io_port = pci_resource_start(ha->pdev, 0);
4358 if (!request_region(host->io_port, 0xff, "qla1280")) {
4359 printk(KERN_INFO "qla1280: Failed to reserve i/o region "
4360 "0x%04lx-0x%04lx - already in use\n",
4361 host->io_port, host->io_port + 0xff);
4362 goto error_free_response_ring;
4365 ha->iobase = (struct device_reg *)host->io_port;
4368 INIT_LIST_HEAD(&ha->done_q);
4370 /* Disable ISP interrupts. */
4371 qla1280_disable_intrs(ha);
4373 if (request_irq(pdev->irq, qla1280_intr_handler, SA_SHIRQ,
4375 printk("qla1280 : Failed to reserve interrupt %d already "
4376 "in use\n", pdev->irq);
4377 goto error_release_region;
4380 /* load the F/W, read paramaters, and init the H/W */
4381 if (qla1280_initialize_adapter(ha)) {
4382 printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
4383 goto error_free_irq;
4386 /* set our host ID (need to do something about our two IDs) */
4387 host->this_id = ha->bus_settings[0].id;
4389 pci_set_drvdata(pdev, host);
4391 error = scsi_add_host(host, &pdev->dev);
4393 goto error_disable_adapter;
4394 scsi_scan_host(host);
4398 error_disable_adapter:
4399 qla1280_disable_intrs(ha);
4401 free_irq(pdev->irq, ha);
4402 error_release_region:
4403 #if MEMORY_MAPPED_IO
4404 iounmap(ha->mmpbase);
4406 release_region(host->io_port, 0xff);
4408 error_free_response_ring:
4409 pci_free_consistent(ha->pdev,
4410 ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
4411 ha->response_ring, ha->response_dma);
4412 error_free_request_ring:
4413 pci_free_consistent(ha->pdev,
4414 ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
4415 ha->request_ring, ha->request_dma);
4417 scsi_host_put(host);
4418 error_disable_device:
4419 pci_disable_device(pdev);
4425 static void __devexit
4426 qla1280_remove_one(struct pci_dev *pdev)
4428 struct Scsi_Host *host = pci_get_drvdata(pdev);
4429 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
4431 scsi_remove_host(host);
4433 qla1280_disable_intrs(ha);
4435 free_irq(pdev->irq, ha);
4437 #if MEMORY_MAPPED_IO
4438 iounmap(ha->mmpbase);
4440 release_region(host->io_port, 0xff);
4443 pci_free_consistent(ha->pdev,
4444 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4445 ha->request_ring, ha->request_dma);
4446 pci_free_consistent(ha->pdev,
4447 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4448 ha->response_ring, ha->response_dma);
4450 pci_disable_device(pdev);
4452 scsi_host_put(host);
4455 static struct pci_driver qla1280_pci_driver = {
4457 .id_table = qla1280_pci_tbl,
4458 .probe = qla1280_probe_one,
4459 .remove = __devexit_p(qla1280_remove_one),
4465 if (sizeof(struct srb) > sizeof(struct scsi_pointer)) {
4467 "qla1280: struct srb too big, aborting\n");
4473 * If we are called as a module, the qla1280 pointer may not be null
4474 * and it would point to our bootup string, just like on the lilo
4475 * command line. IF not NULL, then process this config string with
4479 * To add options at boot time add a line to your lilo.conf file like:
4480 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
4481 * which will result in the first four devices on the first two
4482 * controllers being set to a tagged queue depth of 32.
4485 qla1280_setup(qla1280);
4488 return pci_module_init(&qla1280_pci_driver);
4494 pci_unregister_driver(&qla1280_pci_driver);
4497 module_init(qla1280_init);
4498 module_exit(qla1280_exit);
4501 MODULE_AUTHOR("Qlogic & Jes Sorensen");
4502 MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
4503 MODULE_LICENSE("GPL");
4504 MODULE_VERSION(QLA1280_VERSION);
4507 * Overrides for Emacs so that we almost follow Linus's tabbing style.
4508 * Emacs will notice this stuff at the end of the file and automatically
4509 * adjust the settings for this buffer only. This must remain at the end
4511 * ---------------------------------------------------------------------------