1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
3 * QLOGIC LINUX SOFTWARE
5 * QLogic QLA1280 (Ultra2) and QLA12160 (Ultra3) SCSI driver
6 * Copyright (C) 2000 Qlogic Corporation (www.qlogic.com)
7 * Copyright (C) 2001-2004 Jes Sorensen, Wild Open Source Inc.
8 * Copyright (C) 2003-2004 Christoph Hellwig
10 ******************************************************************************/
11 #define QLA1280_VERSION "3.27.1"
12 /*****************************************************************************
14 Rev 3.27.1, February 8, 2010, Michael Reed
15 - Retain firmware image for error recovery.
16 Rev 3.27, February 10, 2009, Michael Reed
17 - General code cleanup.
18 - Improve error recovery.
19 Rev 3.26, January 16, 2006 Jes Sorensen
20 - Ditch all < 2.6 support
21 Rev 3.25.1, February 10, 2005 Christoph Hellwig
22 - use pci_map_single to map non-S/G requests
23 - remove qla1280_proc_info
24 Rev 3.25, September 28, 2004, Christoph Hellwig
25 - add support for ISP1020/1040
26 - don't include "scsi.h" anymore for 2.6.x
27 Rev 3.24.4 June 7, 2004 Christoph Hellwig
28 - restructure firmware loading, cleanup initialization code
29 - prepare support for ISP1020/1040 chips
30 Rev 3.24.3 January 19, 2004, Jes Sorensen
31 - Handle PCI DMA mask settings correctly
32 - Correct order of error handling in probe_one, free_irq should not
33 be called if request_irq failed
34 Rev 3.24.2 January 19, 2004, James Bottomley & Andrew Vasquez
35 - Big endian fixes (James)
36 - Remove bogus IOCB content on zero data transfer commands (Andrew)
37 Rev 3.24.1 January 5, 2004, Jes Sorensen
38 - Initialize completion queue to avoid OOPS on probe
39 - Handle interrupts during mailbox testing
40 Rev 3.24 November 17, 2003, Christoph Hellwig
41 - use struct list_head for completion queue
42 - avoid old Scsi_FOO typedefs
43 - cleanup 2.4 compat glue a bit
44 - use <scsi/scsi_*.h> headers on 2.6 instead of "scsi.h"
45 - make initialization for memory mapped vs port I/O more similar
46 - remove broken pci config space manipulation
48 - this is an almost perfect 2.6 scsi driver now! ;)
49 Rev 3.23.39 December 17, 2003, Jes Sorensen
50 - Delete completion queue from srb if mailbox command failed to
51 to avoid qla1280_done completeting qla1280_error_action's
53 - Reduce arguments for qla1280_done
54 Rev 3.23.38 October 18, 2003, Christoph Hellwig
55 - Convert to new-style hotplugable driver for 2.6
56 - Fix missing scsi_unregister/scsi_host_put on HBA removal
57 - Kill some more cruft
58 Rev 3.23.37 October 1, 2003, Jes Sorensen
59 - Make MMIO depend on CONFIG_X86_VISWS instead of yet another
61 - Clean up locking in probe path
62 Rev 3.23.36 October 1, 2003, Christoph Hellwig
63 - queuecommand only ever receives new commands - clear flags
64 - Reintegrate lost fixes from Linux 2.5
65 Rev 3.23.35 August 14, 2003, Jes Sorensen
67 Rev 3.23.34 July 23, 2003, Jes Sorensen
68 - Remove pointless TRUE/FALSE macros
69 - Clean up vchan handling
70 Rev 3.23.33 July 3, 2003, Jes Sorensen
71 - Don't define register access macros before define determining MMIO.
72 This just happened to work out on ia64 but not elsewhere.
73 - Don't try and read from the card while it is in reset as
74 it won't respond and causes an MCA
75 Rev 3.23.32 June 23, 2003, Jes Sorensen
76 - Basic support for boot time arguments
77 Rev 3.23.31 June 8, 2003, Jes Sorensen
78 - Reduce boot time messages
79 Rev 3.23.30 June 6, 2003, Jes Sorensen
80 - Do not enable sync/wide/ppr before it has been determined
81 that the target device actually supports it
82 - Enable DMA arbitration for multi channel controllers
83 Rev 3.23.29 June 3, 2003, Jes Sorensen
85 Rev 3.23.28 June 3, 2003, Jes Sorensen
86 - Eliminate duplicate marker commands on bus resets
87 - Handle outstanding commands appropriately on bus/device resets
88 Rev 3.23.27 May 28, 2003, Jes Sorensen
89 - Remove bogus input queue code, let the Linux SCSI layer do the work
90 - Clean up NVRAM handling, only read it once from the card
91 - Add a number of missing default nvram parameters
92 Rev 3.23.26 Beta May 28, 2003, Jes Sorensen
93 - Use completion queue for mailbox commands instead of busy wait
94 Rev 3.23.25 Beta May 27, 2003, James Bottomley
95 - Migrate to use new error handling code
96 Rev 3.23.24 Beta May 21, 2003, James Bottomley
98 - Cleanup data direction code
99 Rev 3.23.23 Beta May 12, 2003, Jes Sorensen
100 - Switch to using MMIO instead of PIO
101 Rev 3.23.22 Beta April 15, 2003, Jes Sorensen
102 - Fix PCI parity problem with 12160 during reset.
103 Rev 3.23.21 Beta April 14, 2003, Jes Sorensen
104 - Use pci_map_page()/pci_unmap_page() instead of map_single version.
105 Rev 3.23.20 Beta April 9, 2003, Jes Sorensen
106 - Remove < 2.4.x support
107 - Introduce HOST_LOCK to make the spin lock changes portable.
108 - Remove a bunch of idiotic and unnecessary typedef's
109 - Kill all leftovers of target-mode support which never worked anyway
110 Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
111 - Do qla1280_pci_config() before calling request_irq() and
113 - Use pci_dma_hi32() to handle upper word of DMA addresses instead
115 - Hand correct arguments to free_irq() in case of failure
116 Rev 3.23.18 Beta April 11, 2002, Jes Sorensen
117 - Run source through Lindent and clean up the output
118 Rev 3.23.17 Beta April 11, 2002, Jes Sorensen
119 - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32
120 Rev 3.23.16 Beta March 19, 2002, Jes Sorensen
121 - Rely on mailbox commands generating interrupts - do not
122 run qla1280_isr() from ql1280_mailbox_command()
123 - Remove device_reg_t
124 - Integrate ql12160_set_target_parameters() with 1280 version
125 - Make qla1280_setup() non static
126 - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request
127 sent to the card - this command pauses the firmware!!!
128 Rev 3.23.15 Beta March 19, 2002, Jes Sorensen
129 - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions
130 - Remove a pile of pointless and confusing (srb_t **) and
131 (scsi_lu_t *) typecasts
132 - Explicit mark that we do not use the new error handling (for now)
133 - Remove scsi_qla_host_t and use 'struct' instead
134 - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled,
135 pci_64bit_slot flags which weren't used for anything anyway
136 - Grab host->host_lock while calling qla1280_isr() from abort()
137 - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we
138 do not need to save/restore flags in the interrupt handler
139 - Enable interrupts early (before any mailbox access) in preparation
140 for cleaning up the mailbox handling
141 Rev 3.23.14 Beta March 14, 2002, Jes Sorensen
142 - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace
143 it with proper use of dprintk().
144 - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take
145 a debug level argument to determine if data is to be printed
146 - Add KERN_* info to printk()
147 Rev 3.23.13 Beta March 14, 2002, Jes Sorensen
148 - Significant cosmetic cleanups
149 - Change debug code to use dprintk() and remove #if mess
150 Rev 3.23.12 Beta March 13, 2002, Jes Sorensen
151 - More cosmetic cleanups, fix places treating return as function
152 - use cpu_relax() in qla1280_debounce_register()
153 Rev 3.23.11 Beta March 13, 2002, Jes Sorensen
154 - Make it compile under 2.5.5
155 Rev 3.23.10 Beta October 1, 2001, Jes Sorensen
156 - Do no typecast short * to long * in QL1280BoardTbl, this
157 broke miserably on big endian boxes
158 Rev 3.23.9 Beta September 30, 2001, Jes Sorensen
159 - Remove pre 2.2 hack for checking for reentrance in interrupt handler
160 - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32
161 unsigned int to match the types from struct scsi_cmnd
162 Rev 3.23.8 Beta September 29, 2001, Jes Sorensen
163 - Remove bogus timer_t typedef from qla1280.h
164 - Remove obsolete pre 2.2 PCI setup code, use proper #define's
165 for PCI_ values, call pci_set_master()
166 - Fix memleak of qla1280_buffer on module unload
167 - Only compile module parsing code #ifdef MODULE - should be
168 changed to use individual MODULE_PARM's later
169 - Remove dummy_buffer that was never modified nor printed
170 - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove
171 #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls
172 - Remove \r from print statements, this is Linux, not DOS
173 - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK}
175 - Remove C++ compile hack in header file as Linux driver are not
176 supposed to be compiled as C++
177 - Kill MS_64BITS macro as it makes the code more readable
178 - Remove unnecessary flags.in_interrupts bit
179 Rev 3.23.7 Beta August 20, 2001, Jes Sorensen
180 - Dont' check for set flags on q->q_flag one by one in qla1280_next()
181 - Check whether the interrupt was generated by the QLA1280 before
183 - qla1280_status_entry(): Only zero out part of sense_buffer that
184 is not being copied into
185 - Remove more superflouous typecasts
186 - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy()
187 Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel
188 - Don't walk the entire list in qla1280_putq_t() just to directly
189 grab the pointer to the last element afterwards
190 Rev 3.23.5 Beta August 9, 2001, Jes Sorensen
191 - Don't use IRQF_DISABLED, it's use is deprecated for this kinda driver
192 Rev 3.23.4 Beta August 8, 2001, Jes Sorensen
193 - Set dev->max_sectors to 1024
194 Rev 3.23.3 Beta August 6, 2001, Jes Sorensen
195 - Provide compat macros for pci_enable_device(), pci_find_subsys()
196 and scsi_set_pci_device()
197 - Call scsi_set_pci_device() for all devices
198 - Reduce size of kernel version dependent device probe code
199 - Move duplicate probe/init code to separate function
200 - Handle error if qla1280_mem_alloc() fails
201 - Kill OFFSET() macro and use Linux's PCI definitions instead
202 - Kill private structure defining PCI config space (struct config_reg)
203 - Only allocate I/O port region if not in MMIO mode
204 - Remove duplicate (unused) sanity check of sife of srb_t
205 Rev 3.23.2 Beta August 6, 2001, Jes Sorensen
206 - Change home-brew memset() implementations to use memset()
207 - Remove all references to COMTRACE() - accessing a PC's COM2 serial
208 port directly is not legal under Linux.
209 Rev 3.23.1 Beta April 24, 2001, Jes Sorensen
210 - Remove pre 2.2 kernel support
211 - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat)
212 - Fix MMIO access to use readl/writel instead of directly
213 dereferencing pointers
214 - Nuke MSDOS debugging code
215 - Change true/false data types to int from uint8_t
216 - Use int for counters instead of uint8_t etc.
217 - Clean up size & byte order conversion macro usage
218 Rev 3.23 Beta January 11, 2001 BN Qlogic
219 - Added check of device_id when handling non
220 QLA12160s during detect().
221 Rev 3.22 Beta January 5, 2001 BN Qlogic
222 - Changed queue_task() to schedule_task()
223 for kernels 2.4.0 and higher.
224 Note: 2.4.0-testxx kernels released prior to
225 the actual 2.4.0 kernel release on January 2001
226 will get compile/link errors with schedule_task().
227 Please update your kernel to released 2.4.0 level,
228 or comment lines in this file flagged with 3.22
229 to resolve compile/link error of schedule_task().
230 - Added -DCONFIG_SMP in addition to -D__SMP__
231 in Makefile for 2.4.0 builds of driver as module.
232 Rev 3.21 Beta January 4, 2001 BN Qlogic
233 - Changed criteria of 64/32 Bit mode of HBA
234 operation according to BITS_PER_LONG rather
235 than HBA's NVRAM setting of >4Gig memory bit;
236 so that the HBA auto-configures without the need
237 to setup each system individually.
238 Rev 3.20 Beta December 5, 2000 BN Qlogic
239 - Added priority handling to IA-64 onboard SCSI
240 ISP12160 chip for kernels greater than 2.3.18.
241 - Added irqrestore for qla1280_intr_handler.
242 - Enabled /proc/scsi/qla1280 interface.
243 - Clear /proc/scsi/qla1280 counters in detect().
244 Rev 3.19 Beta October 13, 2000 BN Qlogic
245 - Declare driver_template for new kernel
246 (2.4.0 and greater) scsi initialization scheme.
247 - Update /proc/scsi entry for 2.3.18 kernels and
249 Rev 3.18 Beta October 10, 2000 BN Qlogic
250 - Changed scan order of adapters to map
251 the QLA12160 followed by the QLA1280.
252 Rev 3.17 Beta September 18, 2000 BN Qlogic
253 - Removed warnings for 32 bit 2.4.x compiles
254 - Corrected declared size for request and response
255 DMA addresses that are kept in each ha
256 Rev. 3.16 Beta August 25, 2000 BN Qlogic
257 - Corrected 64 bit addressing issue on IA-64
258 where the upper 32 bits were not properly
259 passed to the RISC engine.
260 Rev. 3.15 Beta August 22, 2000 BN Qlogic
261 - Modified qla1280_setup_chip to properly load
262 ISP firmware for greater that 4 Gig memory on IA-64
263 Rev. 3.14 Beta August 16, 2000 BN Qlogic
264 - Added setting of dma_mask to full 64 bit
265 if flags.enable_64bit_addressing is set in NVRAM
266 Rev. 3.13 Beta August 16, 2000 BN Qlogic
267 - Use new PCI DMA mapping APIs for 2.4.x kernel
268 Rev. 3.12 July 18, 2000 Redhat & BN Qlogic
269 - Added check of pci_enable_device to detect() for 2.3.x
270 - Use pci_resource_start() instead of
271 pdev->resource[0].start in detect() for 2.3.x
272 - Updated driver version
273 Rev. 3.11 July 14, 2000 BN Qlogic
274 - Updated SCSI Firmware to following versions:
277 - Updated driver version to 3.11
278 Rev. 3.10 June 23, 2000 BN Qlogic
279 - Added filtering of AMI SubSys Vendor ID devices
281 - DEBUG_QLA1280 undefined and new version BN Qlogic
282 Rev. 3.08b May 9, 2000 MD Dell
283 - Added logic to check against AMI subsystem vendor ID
284 Rev. 3.08 May 4, 2000 DG Qlogic
285 - Added logic to check for PCI subsystem ID.
286 Rev. 3.07 Apr 24, 2000 DG & BN Qlogic
287 - Updated SCSI Firmware to following versions:
290 Rev. 3.06 Apr 12, 2000 DG & BN Qlogic
291 - Internal revision; not released
292 Rev. 3.05 Mar 28, 2000 DG & BN Qlogic
293 - Edit correction for virt_to_bus and PROC.
294 Rev. 3.04 Mar 28, 2000 DG & BN Qlogic
295 - Merge changes from ia64 port.
296 Rev. 3.03 Mar 28, 2000 BN Qlogic
297 - Increase version to reflect new code drop with compile fix
298 of issue with inclusion of linux/spinlock for 2.3 kernels
299 Rev. 3.02 Mar 15, 2000 BN Qlogic
300 - Merge qla1280_proc_info from 2.10 code base
301 Rev. 3.01 Feb 10, 2000 BN Qlogic
302 - Corrected code to compile on a 2.2.x kernel.
303 Rev. 3.00 Jan 17, 2000 DG Qlogic
304 - Added 64-bit support.
305 Rev. 2.07 Nov 9, 1999 DG Qlogic
306 - Added new routine to set target parameters for ISP12160.
307 Rev. 2.06 Sept 10, 1999 DG Qlogic
308 - Added support for ISP12160 Ultra 3 chip.
309 Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
310 - Modified code to remove errors generated when compiling with
311 Cygnus IA64 Compiler.
312 - Changed conversion of pointers to unsigned longs instead of integers.
313 - Changed type of I/O port variables from uint32_t to unsigned long.
314 - Modified OFFSET macro to work with 64-bit as well as 32-bit.
315 - Changed sprintf and printk format specifiers for pointers to %p.
316 - Changed some int to long type casts where needed in sprintf & printk.
317 - Added l modifiers to sprintf and printk format specifiers for longs.
318 - Removed unused local variables.
319 Rev. 1.20 June 8, 1999 DG, Qlogic
320 Changes to support RedHat release 6.0 (kernel 2.2.5).
321 - Added SCSI exclusive access lock (io_request_lock) when accessing
323 - Added changes for the new LINUX interface template. Some new error
324 handling routines have been added to the template, but for now we
325 will use the old ones.
326 - Initial Beta Release.
327 *****************************************************************************/
330 #include <linux/module.h>
332 #include <linux/types.h>
333 #include <linux/string.h>
334 #include <linux/errno.h>
335 #include <linux/kernel.h>
336 #include <linux/ioport.h>
337 #include <linux/delay.h>
338 #include <linux/timer.h>
339 #include <linux/pci.h>
340 #include <linux/proc_fs.h>
341 #include <linux/stat.h>
342 #include <linux/pci_ids.h>
343 #include <linux/interrupt.h>
344 #include <linux/init.h>
345 #include <linux/dma-mapping.h>
346 #include <linux/firmware.h>
350 #include <asm/byteorder.h>
351 #include <asm/processor.h>
352 #include <asm/types.h>
354 #include <scsi/scsi.h>
355 #include <scsi/scsi_cmnd.h>
356 #include <scsi/scsi_device.h>
357 #include <scsi/scsi_host.h>
358 #include <scsi/scsi_tcq.h>
360 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
361 #include <asm/sn/io.h>
366 * Compile time Options:
367 * 0 - Disable and 1 - Enable
369 #define DEBUG_QLA1280_INTR 0
370 #define DEBUG_PRINT_NVRAM 0
371 #define DEBUG_QLA1280 0
373 #define MEMORY_MAPPED_IO 1
377 #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
378 #define QLA_64BIT_PTR 1
381 #define NVRAM_DELAY() udelay(500) /* 2 microseconds */
383 #if defined(__ia64__) && !defined(ia64_platform_is)
384 #define ia64_platform_is(foo) (!strcmp(x, platform_name))
388 #define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
389 #define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
390 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
391 #define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
392 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
395 static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *);
396 static void qla1280_remove_one(struct pci_dev *);
399 * QLogic Driver Support Function Prototypes.
401 static void qla1280_done(struct scsi_qla_host *);
402 static int qla1280_get_token(char *);
403 static int qla1280_setup(char *s) __init;
406 * QLogic ISP1280 Hardware Support Function Prototypes.
408 static int qla1280_load_firmware(struct scsi_qla_host *);
409 static int qla1280_init_rings(struct scsi_qla_host *);
410 static int qla1280_nvram_config(struct scsi_qla_host *);
411 static int qla1280_mailbox_command(struct scsi_qla_host *,
412 uint8_t, uint16_t *);
413 static int qla1280_bus_reset(struct scsi_qla_host *, int);
414 static int qla1280_device_reset(struct scsi_qla_host *, int, int);
415 static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int);
416 static int qla1280_abort_isp(struct scsi_qla_host *);
418 static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *);
420 static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *);
422 static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
423 static void qla1280_poll(struct scsi_qla_host *);
424 static void qla1280_reset_adapter(struct scsi_qla_host *);
425 static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
426 static void qla1280_isp_cmd(struct scsi_qla_host *);
427 static void qla1280_isr(struct scsi_qla_host *, struct list_head *);
428 static void qla1280_rst_aen(struct scsi_qla_host *);
429 static void qla1280_status_entry(struct scsi_qla_host *, struct response *,
431 static void qla1280_error_entry(struct scsi_qla_host *, struct response *,
433 static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
434 static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
435 static uint16_t qla1280_debounce_register(volatile uint16_t __iomem *);
436 static request_t *qla1280_req_pkt(struct scsi_qla_host *);
437 static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
439 static void qla1280_get_target_parameters(struct scsi_qla_host *,
440 struct scsi_device *);
441 static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int);
444 static struct qla_driver_setup driver_setup;
447 * convert scsi data direction to request_t control flags
449 static inline uint16_t
450 qla1280_data_direction(struct scsi_cmnd *cmnd)
452 switch(cmnd->sc_data_direction) {
453 case DMA_FROM_DEVICE:
457 case DMA_BIDIRECTIONAL:
458 return BIT_5 | BIT_6;
460 * We could BUG() on default here if one of the four cases aren't
461 * met, but then again if we receive something like that from the
462 * SCSI layer we have more serious problems. This shuts up GCC.
471 static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd);
472 static void __qla1280_dump_buffer(char *, int);
477 * insmod needs to find the variable and make it point to something
480 static char *qla1280;
482 /* insmod qla1280 options=verbose" */
483 module_param(qla1280, charp, 0);
485 __setup("qla1280=", qla1280_setup);
490 * We use the scsi_pointer structure that's included with each scsi_command
491 * to overlay our struct srb over it. qla1280_init() checks that a srb is not
492 * bigger than a scsi_pointer.
495 #define CMD_SP(Cmnd) &Cmnd->SCp
496 #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
497 #define CMD_CDBP(Cmnd) Cmnd->cmnd
498 #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
499 #define CMD_SNSLEN(Cmnd) SCSI_SENSE_BUFFERSIZE
500 #define CMD_RESULT(Cmnd) Cmnd->result
501 #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
502 #define CMD_REQUEST(Cmnd) Cmnd->request->cmd
504 #define CMD_HOST(Cmnd) Cmnd->device->host
505 #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
506 #define SCSI_TCN_32(Cmnd) Cmnd->device->id
507 #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
510 /*****************************************/
511 /* ISP Boards supported by this driver */
512 /*****************************************/
515 char *name; /* Board ID String */
516 int numPorts; /* Number of SCSI ports */
517 int fw_index; /* index into qla1280_fw_tbl for firmware */
520 /* NOTE: the last argument in each entry is used to index ql1280_board_tbl */
521 static struct pci_device_id qla1280_pci_tbl[] = {
522 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP12160,
523 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
524 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1020,
525 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
526 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1080,
527 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
528 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1240,
529 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
530 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1280,
531 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
532 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP10160,
533 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
536 MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl);
538 DEFINE_MUTEX(qla1280_firmware_mutex);
542 const struct firmware *fw;
545 #define QL_NUM_FW_IMAGES 3
547 struct qla_fw qla1280_fw_tbl[QL_NUM_FW_IMAGES] = {
548 {"qlogic/1040.bin", NULL}, /* image 0 */
549 {"qlogic/1280.bin", NULL}, /* image 1 */
550 {"qlogic/12160.bin", NULL}, /* image 2 */
553 /* NOTE: Order of boards in this table must match order in qla1280_pci_tbl */
554 static struct qla_boards ql1280_board_tbl[] = {
555 {.name = "QLA12160", .numPorts = 2, .fw_index = 2},
556 {.name = "QLA1040" , .numPorts = 1, .fw_index = 0},
557 {.name = "QLA1080" , .numPorts = 1, .fw_index = 1},
558 {.name = "QLA1240" , .numPorts = 2, .fw_index = 1},
559 {.name = "QLA1280" , .numPorts = 2, .fw_index = 1},
560 {.name = "QLA10160", .numPorts = 1, .fw_index = 2},
561 {.name = " ", .numPorts = 0, .fw_index = -1},
564 static int qla1280_verbose = 1;
567 static int ql_debug_level = 1;
568 #define dprintk(level, format, a...) \
569 do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
570 #define qla1280_dump_buffer(level, buf, size) \
571 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
572 #define qla1280_print_scsi_cmd(level, cmd) \
573 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
575 #define ql_debug_level 0
576 #define dprintk(level, format, a...) do{}while(0)
577 #define qla1280_dump_buffer(a, b, c) do{}while(0)
578 #define qla1280_print_scsi_cmd(a, b) do{}while(0)
581 #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
582 #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
583 #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
584 #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
587 static int qla1280_read_nvram(struct scsi_qla_host *ha)
594 ENTER("qla1280_read_nvram");
596 if (driver_setup.no_nvram)
599 printk(KERN_INFO "scsi(%ld): Reading NVRAM\n", ha->host_no);
601 wptr = (uint16_t *)&ha->nvram;
604 for (cnt = 0; cnt < 3; cnt++) {
605 *wptr = qla1280_get_nvram_word(ha, cnt);
606 chksum += *wptr & 0xff;
607 chksum += (*wptr >> 8) & 0xff;
611 if (nv->id0 != 'I' || nv->id1 != 'S' ||
612 nv->id2 != 'P' || nv->id3 != ' ' || nv->version < 1) {
613 dprintk(2, "Invalid nvram ID or version!\n");
616 for (; cnt < sizeof(struct nvram); cnt++) {
617 *wptr = qla1280_get_nvram_word(ha, cnt);
618 chksum += *wptr & 0xff;
619 chksum += (*wptr >> 8) & 0xff;
624 dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
625 " version %i\n", nv->id0, nv->id1, nv->id2, nv->id3,
630 if (!driver_setup.no_nvram)
631 printk(KERN_WARNING "scsi(%ld): Unable to identify or "
632 "validate NVRAM checksum, using default "
633 "settings\n", ha->host_no);
638 /* The firmware interface is, um, interesting, in that the
639 * actual firmware image on the chip is little endian, thus,
640 * the process of taking that image to the CPU would end up
641 * little endian. However, the firmware interface requires it
642 * to be read a word (two bytes) at a time.
644 * The net result of this would be that the word (and
645 * doubleword) quantites in the firmware would be correct, but
646 * the bytes would be pairwise reversed. Since most of the
647 * firmware quantites are, in fact, bytes, we do an extra
648 * le16_to_cpu() in the firmware read routine.
650 * The upshot of all this is that the bytes in the firmware
651 * are in the correct places, but the 16 and 32 bit quantites
652 * are still in little endian format. We fix that up below by
653 * doing extra reverses on them */
654 nv->isp_parameter = cpu_to_le16(nv->isp_parameter);
655 nv->firmware_feature.w = cpu_to_le16(nv->firmware_feature.w);
656 for(i = 0; i < MAX_BUSES; i++) {
657 nv->bus[i].selection_timeout = cpu_to_le16(nv->bus[i].selection_timeout);
658 nv->bus[i].max_queue_depth = cpu_to_le16(nv->bus[i].max_queue_depth);
660 dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
661 LEAVE("qla1280_read_nvram");
666 /**************************************************************************
668 * Return a string describing the driver.
669 **************************************************************************/
671 qla1280_info(struct Scsi_Host *host)
673 static char qla1280_scsi_name_buffer[125];
675 struct scsi_qla_host *ha;
676 struct qla_boards *bdp;
678 bp = &qla1280_scsi_name_buffer[0];
679 ha = (struct scsi_qla_host *)host->hostdata;
680 bdp = &ql1280_board_tbl[ha->devnum];
681 memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
684 "QLogic %s PCI to SCSI Host Adapter\n"
685 " Firmware version: %2d.%02d.%02d, Driver version %s",
686 &bdp->name[0], ha->fwver1, ha->fwver2, ha->fwver3,
691 /**************************************************************************
692 * qla1280_queuecommand
693 * Queue a command to the controller.
696 * The mid-level driver tries to ensures that queuecommand never gets invoked
697 * concurrently with itself or the interrupt handler (although the
698 * interrupt handler may call this routine as part of request-completion
699 * handling). Unfortunely, it sometimes calls the scheduler in interrupt
700 * context which is a big NO! NO!.
701 **************************************************************************/
703 qla1280_queuecommand_lck(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
705 struct Scsi_Host *host = cmd->device->host;
706 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
707 struct srb *sp = (struct srb *)CMD_SP(cmd);
714 CMD_HANDLE(cmd) = (unsigned char *)NULL;
716 qla1280_print_scsi_cmd(5, cmd);
720 * Using 64 bit commands if the PCI bridge doesn't support it is a
721 * bit wasteful, however this should really only happen if one's
722 * PCI controller is completely broken, like the BCM1250. For
723 * sane hardware this is not an issue.
725 status = qla1280_64bit_start_scsi(ha, sp);
727 status = qla1280_32bit_start_scsi(ha, sp);
732 static DEF_SCSI_QCMD(qla1280_queuecommand)
742 static void qla1280_mailbox_timeout(struct timer_list *t)
744 struct scsi_qla_host *ha = from_timer(ha, t, mailbox_timer);
745 struct device_reg __iomem *reg;
748 ha->mailbox_out[0] = RD_REG_WORD(®->mailbox0);
749 printk(KERN_ERR "scsi(%ld): mailbox timed out, mailbox0 %04x, "
750 "ictrl %04x, istatus %04x\n", ha->host_no, ha->mailbox_out[0],
751 RD_REG_WORD(®->ictrl), RD_REG_WORD(®->istatus));
752 complete(ha->mailbox_wait);
756 _qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp,
757 struct completion *wait)
760 struct scsi_cmnd *cmd = sp->cmd;
762 spin_unlock_irq(ha->host->host_lock);
763 wait_for_completion_timeout(wait, 4*HZ);
764 spin_lock_irq(ha->host->host_lock);
766 if(CMD_HANDLE(cmd) == COMPLETED_HANDLE) {
768 (*cmd->scsi_done)(cmd);
774 qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp)
776 DECLARE_COMPLETION_ONSTACK(wait);
779 return _qla1280_wait_for_single_command(ha, sp, &wait);
783 qla1280_wait_for_pending_commands(struct scsi_qla_host *ha, int bus, int target)
788 struct scsi_cmnd *cmd;
793 * Wait for all commands with the designated bus/target
794 * to be completed by the firmware
796 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
797 sp = ha->outstanding_cmds[cnt];
801 if (bus >= 0 && SCSI_BUS_32(cmd) != bus)
803 if (target >= 0 && SCSI_TCN_32(cmd) != target)
806 status = qla1280_wait_for_single_command(ha, sp);
807 if (status == FAILED)
814 /**************************************************************************
815 * qla1280_error_action
816 * The function will attempt to perform a specified error action and
817 * wait for the results (or time out).
820 * cmd = Linux SCSI command packet of the command that cause the
822 * action = error action to take (see action_t)
827 **************************************************************************/
829 qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
831 struct scsi_qla_host *ha;
832 int bus, target, lun;
837 int wait_for_target = -1;
838 DECLARE_COMPLETION_ONSTACK(wait);
840 ENTER("qla1280_error_action");
842 ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
843 sp = (struct srb *)CMD_SP(cmd);
844 bus = SCSI_BUS_32(cmd);
845 target = SCSI_TCN_32(cmd);
846 lun = SCSI_LUN_32(cmd);
848 dprintk(4, "error_action %i, istatus 0x%04x\n", action,
849 RD_REG_WORD(&ha->iobase->istatus));
851 dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
852 RD_REG_WORD(&ha->iobase->host_cmd),
853 RD_REG_WORD(&ha->iobase->ictrl), jiffies);
856 printk(KERN_INFO "scsi(%li): Resetting Cmnd=0x%p, "
857 "Handle=0x%p, action=0x%x\n",
858 ha->host_no, cmd, CMD_HANDLE(cmd), action);
861 * Check to see if we have the command in the outstanding_cmds[]
862 * array. If not then it must have completed before this error
863 * action was initiated. If the error_action isn't ABORT_COMMAND
864 * then the driver must proceed with the requested action.
867 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
868 if (sp == ha->outstanding_cmds[i]) {
870 sp->wait = &wait; /* we'll wait for it to complete */
875 if (found < 0) { /* driver doesn't have command */
877 if (qla1280_verbose) {
879 "scsi(%ld:%d:%d:%d): specified command has "
880 "already completed.\n", ha->host_no, bus,
888 dprintk(1, "qla1280: RISC aborting command\n");
890 * The abort might fail due to race when the host_lock
891 * is released to issue the abort. As such, we
892 * don't bother to check the return status.
895 qla1280_abort_command(ha, sp, found);
901 "scsi(%ld:%d:%d:%d): Queueing device reset "
902 "command.\n", ha->host_no, bus, target, lun);
903 if (qla1280_device_reset(ha, bus, target) == 0) {
904 /* issued device reset, set wait conditions */
906 wait_for_target = target;
912 printk(KERN_INFO "qla1280(%ld:%d): Issued bus "
913 "reset.\n", ha->host_no, bus);
914 if (qla1280_bus_reset(ha, bus) == 0) {
915 /* issued bus reset, set wait conditions */
922 if (qla1280_verbose) {
924 "scsi(%ld): Issued ADAPTER RESET\n",
926 printk(KERN_INFO "scsi(%ld): I/O processing will "
927 "continue automatically\n", ha->host_no);
929 ha->flags.reset_active = 1;
931 if (qla1280_abort_isp(ha) != 0) { /* it's dead */
935 ha->flags.reset_active = 0;
939 * At this point, the host_lock has been released and retaken
940 * by the issuance of the mailbox command.
941 * Wait for the command passed in by the mid-layer if it
942 * was found by the driver. It might have been returned
943 * between eh recovery steps, hence the check of the "found"
948 result = _qla1280_wait_for_single_command(ha, sp, &wait);
950 if (action == ABORT_COMMAND && result != SUCCESS) {
952 "scsi(%li:%i:%i:%i): "
953 "Unable to abort command!\n",
954 ha->host_no, bus, target, lun);
958 * If the command passed in by the mid-layer has been
959 * returned by the board, then wait for any additional
960 * commands which are supposed to complete based upon
963 * All commands are unconditionally returned during a
964 * call to qla1280_abort_isp(), ADAPTER_RESET. No need
967 if (result == SUCCESS && wait_for_bus >= 0) {
968 result = qla1280_wait_for_pending_commands(ha,
969 wait_for_bus, wait_for_target);
972 dprintk(1, "RESET returning %d\n", result);
974 LEAVE("qla1280_error_action");
978 /**************************************************************************
980 * Abort the specified SCSI command(s).
981 **************************************************************************/
983 qla1280_eh_abort(struct scsi_cmnd * cmd)
987 spin_lock_irq(cmd->device->host->host_lock);
988 rc = qla1280_error_action(cmd, ABORT_COMMAND);
989 spin_unlock_irq(cmd->device->host->host_lock);
994 /**************************************************************************
995 * qla1280_device_reset
996 * Reset the specified SCSI device
997 **************************************************************************/
999 qla1280_eh_device_reset(struct scsi_cmnd *cmd)
1003 spin_lock_irq(cmd->device->host->host_lock);
1004 rc = qla1280_error_action(cmd, DEVICE_RESET);
1005 spin_unlock_irq(cmd->device->host->host_lock);
1010 /**************************************************************************
1012 * Reset the specified bus.
1013 **************************************************************************/
1015 qla1280_eh_bus_reset(struct scsi_cmnd *cmd)
1019 spin_lock_irq(cmd->device->host->host_lock);
1020 rc = qla1280_error_action(cmd, BUS_RESET);
1021 spin_unlock_irq(cmd->device->host->host_lock);
1026 /**************************************************************************
1027 * qla1280_adapter_reset
1028 * Reset the specified adapter (both channels)
1029 **************************************************************************/
1031 qla1280_eh_adapter_reset(struct scsi_cmnd *cmd)
1035 spin_lock_irq(cmd->device->host->host_lock);
1036 rc = qla1280_error_action(cmd, ADAPTER_RESET);
1037 spin_unlock_irq(cmd->device->host->host_lock);
1043 qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1044 sector_t capacity, int geom[])
1046 int heads, sectors, cylinders;
1050 cylinders = (unsigned long)capacity / (heads * sectors);
1051 if (cylinders > 1024) {
1054 cylinders = (unsigned long)capacity / (heads * sectors);
1055 /* if (cylinders > 1023)
1056 cylinders = 1023; */
1061 geom[2] = cylinders;
1067 /* disable risc and host interrupts */
1069 qla1280_disable_intrs(struct scsi_qla_host *ha)
1071 WRT_REG_WORD(&ha->iobase->ictrl, 0);
1072 RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
1075 /* enable risc and host interrupts */
1077 qla1280_enable_intrs(struct scsi_qla_host *ha)
1079 WRT_REG_WORD(&ha->iobase->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1080 RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
1083 /**************************************************************************
1084 * qla1280_intr_handler
1085 * Handles the H/W interrupt
1086 **************************************************************************/
1088 qla1280_intr_handler(int irq, void *dev_id)
1090 struct scsi_qla_host *ha;
1091 struct device_reg __iomem *reg;
1095 ENTER_INTR ("qla1280_intr_handler");
1096 ha = (struct scsi_qla_host *)dev_id;
1098 spin_lock(ha->host->host_lock);
1103 qla1280_disable_intrs(ha);
1105 data = qla1280_debounce_register(®->istatus);
1106 /* Check for pending interrupts. */
1107 if (data & RISC_INT) {
1108 qla1280_isr(ha, &ha->done_q);
1111 if (!list_empty(&ha->done_q))
1114 spin_unlock(ha->host->host_lock);
1116 qla1280_enable_intrs(ha);
1118 LEAVE_INTR("qla1280_intr_handler");
1119 return IRQ_RETVAL(handled);
1124 qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
1127 uint16_t mb[MAILBOX_REGISTER_COUNT];
1133 mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
1135 /* Set Target Parameters. */
1136 mb[0] = MBC_SET_TARGET_PARAMETERS;
1137 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
1138 mb[2] = nv->bus[bus].target[target].parameter.renegotiate_on_error << 8;
1139 mb[2] |= nv->bus[bus].target[target].parameter.stop_queue_on_check << 9;
1140 mb[2] |= nv->bus[bus].target[target].parameter.auto_request_sense << 10;
1141 mb[2] |= nv->bus[bus].target[target].parameter.tag_queuing << 11;
1142 mb[2] |= nv->bus[bus].target[target].parameter.enable_sync << 12;
1143 mb[2] |= nv->bus[bus].target[target].parameter.enable_wide << 13;
1144 mb[2] |= nv->bus[bus].target[target].parameter.parity_checking << 14;
1145 mb[2] |= nv->bus[bus].target[target].parameter.disconnect_allowed << 15;
1147 if (IS_ISP1x160(ha)) {
1148 mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
1149 mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8);
1150 mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) |
1151 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
1154 mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8);
1156 mb[3] |= nv->bus[bus].target[target].sync_period;
1158 status = qla1280_mailbox_command(ha, mr, mb);
1160 /* Set Device Queue Parameters. */
1161 for (lun = 0; lun < MAX_LUNS; lun++) {
1162 mb[0] = MBC_SET_DEVICE_QUEUE;
1163 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
1165 mb[2] = nv->bus[bus].max_queue_depth;
1166 mb[3] = nv->bus[bus].target[target].execution_throttle;
1167 status |= qla1280_mailbox_command(ha, 0x0f, mb);
1171 printk(KERN_WARNING "scsi(%ld:%i:%i): "
1172 "qla1280_set_target_parameters() failed\n",
1173 ha->host_no, bus, target);
1178 /**************************************************************************
1179 * qla1280_slave_configure
1182 * Determines the queue depth for a given device. There are two ways
1183 * a queue depth can be obtained for a tagged queueing device. One
1184 * way is the default queue depth which is determined by whether
1185 * If it is defined, then it is used
1186 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1187 * default queue depth (dependent on the number of hardware SCBs).
1188 **************************************************************************/
1190 qla1280_slave_configure(struct scsi_device *device)
1192 struct scsi_qla_host *ha;
1193 int default_depth = 3;
1194 int bus = device->channel;
1195 int target = device->id;
1198 unsigned long flags;
1200 ha = (struct scsi_qla_host *)device->host->hostdata;
1203 if (qla1280_check_for_dead_scsi_bus(ha, bus))
1206 if (device->tagged_supported &&
1207 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1208 scsi_change_queue_depth(device, ha->bus_settings[bus].hiwat);
1210 scsi_change_queue_depth(device, default_depth);
1213 nv->bus[bus].target[target].parameter.enable_sync = device->sdtr;
1214 nv->bus[bus].target[target].parameter.enable_wide = device->wdtr;
1215 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
1217 if (driver_setup.no_sync ||
1218 (driver_setup.sync_mask &&
1219 (~driver_setup.sync_mask & (1 << target))))
1220 nv->bus[bus].target[target].parameter.enable_sync = 0;
1221 if (driver_setup.no_wide ||
1222 (driver_setup.wide_mask &&
1223 (~driver_setup.wide_mask & (1 << target))))
1224 nv->bus[bus].target[target].parameter.enable_wide = 0;
1225 if (IS_ISP1x160(ha)) {
1226 if (driver_setup.no_ppr ||
1227 (driver_setup.ppr_mask &&
1228 (~driver_setup.ppr_mask & (1 << target))))
1229 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
1232 spin_lock_irqsave(ha->host->host_lock, flags);
1233 if (nv->bus[bus].target[target].parameter.enable_sync)
1234 status = qla1280_set_target_parameters(ha, bus, target);
1235 qla1280_get_target_parameters(ha, device);
1236 spin_unlock_irqrestore(ha->host->host_lock, flags);
1243 * Process completed commands.
1246 * ha = adapter block pointer.
1249 qla1280_done(struct scsi_qla_host *ha)
1252 struct list_head *done_q;
1253 int bus, target, lun;
1254 struct scsi_cmnd *cmd;
1256 ENTER("qla1280_done");
1258 done_q = &ha->done_q;
1260 while (!list_empty(done_q)) {
1261 sp = list_entry(done_q->next, struct srb, list);
1263 list_del(&sp->list);
1266 bus = SCSI_BUS_32(cmd);
1267 target = SCSI_TCN_32(cmd);
1268 lun = SCSI_LUN_32(cmd);
1270 switch ((CMD_RESULT(cmd) >> 16)) {
1272 /* Issue marker command. */
1273 if (!ha->flags.abort_isp_active)
1274 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
1277 sp->flags &= ~SRB_ABORT_PENDING;
1278 sp->flags |= SRB_ABORTED;
1284 /* Release memory used for this I/O */
1285 scsi_dma_unmap(cmd);
1287 /* Call the mid-level driver interrupt handler */
1290 if (sp->wait == NULL)
1291 (*(cmd)->scsi_done)(cmd);
1295 LEAVE("qla1280_done");
1299 * Translates a ISP error to a Linux SCSI error
1302 qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1304 int host_status = DID_ERROR;
1305 uint16_t comp_status = le16_to_cpu(sts->comp_status);
1306 uint16_t state_flags = le16_to_cpu(sts->state_flags);
1307 uint32_t residual_length = le32_to_cpu(sts->residual_length);
1308 uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
1309 #if DEBUG_QLA1280_INTR
1310 static char *reason[] = {
1322 #endif /* DEBUG_QLA1280_INTR */
1324 ENTER("qla1280_return_status");
1326 #if DEBUG_QLA1280_INTR
1328 dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
1333 switch (comp_status) {
1335 host_status = DID_OK;
1339 if (!(state_flags & SF_GOT_BUS))
1340 host_status = DID_NO_CONNECT;
1341 else if (!(state_flags & SF_GOT_TARGET))
1342 host_status = DID_BAD_TARGET;
1343 else if (!(state_flags & SF_SENT_CDB))
1344 host_status = DID_ERROR;
1345 else if (!(state_flags & SF_TRANSFERRED_DATA))
1346 host_status = DID_ERROR;
1347 else if (!(state_flags & SF_GOT_STATUS))
1348 host_status = DID_ERROR;
1349 else if (!(state_flags & SF_GOT_SENSE))
1350 host_status = DID_ERROR;
1354 host_status = DID_RESET;
1358 host_status = DID_ABORT;
1362 host_status = DID_TIME_OUT;
1365 case CS_DATA_OVERRUN:
1366 dprintk(2, "Data overrun 0x%x\n", residual_length);
1367 dprintk(2, "qla1280_return_status: response packet data\n");
1368 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
1369 host_status = DID_ERROR;
1372 case CS_DATA_UNDERRUN:
1373 if ((scsi_bufflen(cp) - residual_length) <
1376 "scsi: Underflow detected - retrying "
1378 host_status = DID_ERROR;
1380 scsi_set_resid(cp, residual_length);
1381 host_status = DID_OK;
1386 host_status = DID_ERROR;
1390 #if DEBUG_QLA1280_INTR
1391 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
1392 reason[host_status], scsi_status);
1395 LEAVE("qla1280_return_status");
1397 return (scsi_status & 0xff) | (host_status << 16);
1400 /****************************************************************************/
1401 /* QLogic ISP1280 Hardware Support Functions. */
1402 /****************************************************************************/
1405 * qla1280_initialize_adapter
1409 * ha = adapter block pointer.
1415 qla1280_initialize_adapter(struct scsi_qla_host *ha)
1417 struct device_reg __iomem *reg;
1420 unsigned long flags;
1422 ENTER("qla1280_initialize_adapter");
1424 /* Clear adapter flags. */
1425 ha->flags.online = 0;
1426 ha->flags.disable_host_adapter = 0;
1427 ha->flags.reset_active = 0;
1428 ha->flags.abort_isp_active = 0;
1430 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1431 if (ia64_platform_is("sn2")) {
1432 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
1433 "dual channel lockup workaround\n", ha->host_no);
1434 ha->flags.use_pci_vchannel = 1;
1435 driver_setup.no_nvram = 1;
1439 /* TODO: implement support for the 1040 nvram format */
1441 driver_setup.no_nvram = 1;
1443 dprintk(1, "Configure PCI space for adapter...\n");
1447 /* Insure mailbox registers are free. */
1448 WRT_REG_WORD(®->semaphore, 0);
1449 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
1450 WRT_REG_WORD(®->host_cmd, HC_CLR_HOST_INT);
1451 RD_REG_WORD(®->host_cmd);
1453 if (qla1280_read_nvram(ha)) {
1454 dprintk(2, "qla1280_initialize_adapter: failed to read "
1459 * It's necessary to grab the spin here as qla1280_mailbox_command
1460 * needs to be able to drop the lock unconditionally to wait
1463 spin_lock_irqsave(ha->host->host_lock, flags);
1465 status = qla1280_load_firmware(ha);
1467 printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
1472 /* Setup adapter based on NVRAM parameters. */
1473 dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha->host_no);
1474 qla1280_nvram_config(ha);
1476 if (ha->flags.disable_host_adapter) {
1481 status = qla1280_init_rings(ha);
1485 /* Issue SCSI reset, if we can't reset twice then bus is dead */
1486 for (bus = 0; bus < ha->ports; bus++) {
1487 if (!ha->bus_settings[bus].disable_scsi_reset &&
1488 qla1280_bus_reset(ha, bus) &&
1489 qla1280_bus_reset(ha, bus))
1490 ha->bus_settings[bus].scsi_bus_dead = 1;
1493 ha->flags.online = 1;
1495 spin_unlock_irqrestore(ha->host->host_lock, flags);
1498 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
1500 LEAVE("qla1280_initialize_adapter");
1505 * qla1280_request_firmware
1506 * Acquire firmware for chip. Retain in memory
1507 * for error recovery.
1510 * ha = adapter block pointer.
1513 * Pointer to firmware image or an error code
1514 * cast to pointer via ERR_PTR().
1516 static const struct firmware *
1517 qla1280_request_firmware(struct scsi_qla_host *ha)
1519 const struct firmware *fw;
1524 spin_unlock_irq(ha->host->host_lock);
1525 mutex_lock(&qla1280_firmware_mutex);
1527 index = ql1280_board_tbl[ha->devnum].fw_index;
1528 fw = qla1280_fw_tbl[index].fw;
1532 fwname = qla1280_fw_tbl[index].fwname;
1533 err = request_firmware(&fw, fwname, &ha->pdev->dev);
1536 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
1541 if ((fw->size % 2) || (fw->size < 6)) {
1542 printk(KERN_ERR "Invalid firmware length %zu in image \"%s\"\n",
1544 release_firmware(fw);
1545 fw = ERR_PTR(-EINVAL);
1549 qla1280_fw_tbl[index].fw = fw;
1552 ha->fwver1 = fw->data[0];
1553 ha->fwver2 = fw->data[1];
1554 ha->fwver3 = fw->data[2];
1556 mutex_unlock(&qla1280_firmware_mutex);
1557 spin_lock_irq(ha->host->host_lock);
1563 * Test chip for proper operation.
1566 * ha = adapter block pointer.
1572 qla1280_chip_diag(struct scsi_qla_host *ha)
1574 uint16_t mb[MAILBOX_REGISTER_COUNT];
1575 struct device_reg __iomem *reg = ha->iobase;
1579 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®->id_l);
1581 dprintk(1, "scsi(%ld): Verifying chip\n", ha->host_no);
1583 /* Soft reset chip and wait for it to finish. */
1584 WRT_REG_WORD(®->ictrl, ISP_RESET);
1587 * We can't do a traditional PCI write flush here by reading
1588 * back the register. The card will not respond once the reset
1589 * is in action and we end up with a machine check exception
1590 * instead. Nothing to do but wait and hope for the best.
1591 * A portable pci_write_flush(pdev) call would be very useful here.
1594 data = qla1280_debounce_register(®->ictrl);
1596 * Yet another QLogic gem ;-(
1598 for (cnt = 1000000; cnt && data & ISP_RESET; cnt--) {
1600 data = RD_REG_WORD(®->ictrl);
1606 /* Reset register cleared by chip reset. */
1607 dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
1609 WRT_REG_WORD(®->cfg_1, 0);
1611 /* Reset RISC and disable BIOS which
1612 allows RISC to execute out of RAM. */
1613 WRT_REG_WORD(®->host_cmd, HC_RESET_RISC |
1614 HC_RELEASE_RISC | HC_DISABLE_BIOS);
1616 RD_REG_WORD(®->id_l); /* Flush PCI write */
1617 data = qla1280_debounce_register(®->mailbox0);
1620 * I *LOVE* this code!
1622 for (cnt = 1000000; cnt && data == MBS_BUSY; cnt--) {
1624 data = RD_REG_WORD(®->mailbox0);
1630 /* Check product ID of chip */
1631 dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
1633 if (RD_REG_WORD(®->mailbox1) != PROD_ID_1 ||
1634 (RD_REG_WORD(®->mailbox2) != PROD_ID_2 &&
1635 RD_REG_WORD(®->mailbox2) != PROD_ID_2a) ||
1636 RD_REG_WORD(®->mailbox3) != PROD_ID_3 ||
1637 RD_REG_WORD(®->mailbox4) != PROD_ID_4) {
1638 printk(KERN_INFO "qla1280: Wrong product ID = "
1639 "0x%x,0x%x,0x%x,0x%x\n",
1640 RD_REG_WORD(®->mailbox1),
1641 RD_REG_WORD(®->mailbox2),
1642 RD_REG_WORD(®->mailbox3),
1643 RD_REG_WORD(®->mailbox4));
1648 * Enable ints early!!!
1650 qla1280_enable_intrs(ha);
1652 dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
1653 /* Wrap Incoming Mailboxes Test. */
1654 mb[0] = MBC_MAILBOX_REGISTER_TEST;
1663 status = qla1280_mailbox_command(ha, 0xff, mb);
1667 if (mb[1] != 0xAAAA || mb[2] != 0x5555 || mb[3] != 0xAA55 ||
1668 mb[4] != 0x55AA || mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
1670 printk(KERN_INFO "qla1280: Failed mbox check\n");
1674 dprintk(3, "qla1280_chip_diag: exiting normally\n");
1677 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
1682 qla1280_load_firmware_pio(struct scsi_qla_host *ha)
1684 /* enter with host_lock acquired */
1686 const struct firmware *fw;
1687 const __le16 *fw_data;
1688 uint16_t risc_address, risc_code_size;
1689 uint16_t mb[MAILBOX_REGISTER_COUNT], i;
1692 fw = qla1280_request_firmware(ha);
1696 fw_data = (const __le16 *)&fw->data[0];
1697 ha->fwstart = __le16_to_cpu(fw_data[2]);
1699 /* Load RISC code. */
1700 risc_address = ha->fwstart;
1701 fw_data = (const __le16 *)&fw->data[6];
1702 risc_code_size = (fw->size - 6) / 2;
1704 for (i = 0; i < risc_code_size; i++) {
1705 mb[0] = MBC_WRITE_RAM_WORD;
1706 mb[1] = risc_address + i;
1707 mb[2] = __le16_to_cpu(fw_data[i]);
1709 err = qla1280_mailbox_command(ha, BIT_0 | BIT_1 | BIT_2, mb);
1711 printk(KERN_ERR "scsi(%li): Failed to load firmware\n",
1720 #define DUMP_IT_BACK 0 /* for debug of RISC loading */
1722 qla1280_load_firmware_dma(struct scsi_qla_host *ha)
1724 /* enter with host_lock acquired */
1725 const struct firmware *fw;
1726 const __le16 *fw_data;
1727 uint16_t risc_address, risc_code_size;
1728 uint16_t mb[MAILBOX_REGISTER_COUNT], cnt;
1729 int err = 0, num, i;
1734 tbuf = dma_alloc_coherent(&ha->pdev->dev, 8000, &p_tbuf, GFP_KERNEL);
1739 fw = qla1280_request_firmware(ha);
1743 fw_data = (const __le16 *)&fw->data[0];
1744 ha->fwstart = __le16_to_cpu(fw_data[2]);
1746 /* Load RISC code. */
1747 risc_address = ha->fwstart;
1748 fw_data = (const __le16 *)&fw->data[6];
1749 risc_code_size = (fw->size - 6) / 2;
1751 dprintk(1, "%s: DMA RISC code (%i) words\n",
1752 __func__, risc_code_size);
1755 while (risc_code_size > 0) {
1756 int warn __attribute__((unused)) = 0;
1760 if (cnt > risc_code_size)
1761 cnt = risc_code_size;
1763 dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
1765 fw_data, cnt, num, risc_address);
1766 for(i = 0; i < cnt; i++)
1767 ((__le16 *)ha->request_ring)[i] = fw_data[i];
1769 mb[0] = MBC_LOAD_RAM;
1770 mb[1] = risc_address;
1772 mb[3] = ha->request_dma & 0xffff;
1773 mb[2] = (ha->request_dma >> 16) & 0xffff;
1774 mb[7] = upper_32_bits(ha->request_dma) & 0xffff;
1775 mb[6] = upper_32_bits(ha->request_dma) >> 16;
1776 dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
1778 (void *)(long)ha->request_dma,
1779 mb[6], mb[7], mb[2], mb[3]);
1780 err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
1783 printk(KERN_ERR "scsi(%li): Failed to load partial "
1784 "segment of f\n", ha->host_no);
1789 mb[0] = MBC_DUMP_RAM;
1790 mb[1] = risc_address;
1792 mb[3] = p_tbuf & 0xffff;
1793 mb[2] = (p_tbuf >> 16) & 0xffff;
1794 mb[7] = upper_32_bits(p_tbuf) & 0xffff;
1795 mb[6] = upper_32_bits(p_tbuf) >> 16;
1797 err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
1801 "Failed to dump partial segment of f/w\n");
1804 sp = (uint8_t *)ha->request_ring;
1805 for (i = 0; i < (cnt << 1); i++) {
1806 if (tbuf[i] != sp[i] && warn++ < 10) {
1807 printk(KERN_ERR "%s: FW compare error @ "
1808 "byte(0x%x) loop#=%x\n",
1810 printk(KERN_ERR "%s: FWbyte=%x "
1812 __func__, sp[i], tbuf[i]);
1817 risc_address += cnt;
1818 risc_code_size = risc_code_size - cnt;
1819 fw_data = fw_data + cnt;
1825 dma_free_coherent(&ha->pdev->dev, 8000, tbuf, p_tbuf);
1831 qla1280_start_firmware(struct scsi_qla_host *ha)
1833 uint16_t mb[MAILBOX_REGISTER_COUNT];
1836 dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
1839 /* Verify checksum of loaded RISC code. */
1840 mb[0] = MBC_VERIFY_CHECKSUM;
1841 /* mb[1] = ql12_risc_code_addr01; */
1842 mb[1] = ha->fwstart;
1843 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
1845 printk(KERN_ERR "scsi(%li): RISC checksum failed.\n", ha->host_no);
1849 /* Start firmware execution. */
1850 dprintk(1, "%s: start firmware running.\n", __func__);
1851 mb[0] = MBC_EXECUTE_FIRMWARE;
1852 mb[1] = ha->fwstart;
1853 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
1855 printk(KERN_ERR "scsi(%li): Failed to start firmware\n",
1863 qla1280_load_firmware(struct scsi_qla_host *ha)
1865 /* enter with host_lock taken */
1868 err = qla1280_chip_diag(ha);
1872 err = qla1280_load_firmware_pio(ha);
1874 err = qla1280_load_firmware_dma(ha);
1877 err = qla1280_start_firmware(ha);
1886 * ha = adapter block pointer.
1887 * ha->request_ring = request ring virtual address
1888 * ha->response_ring = response ring virtual address
1889 * ha->request_dma = request ring physical address
1890 * ha->response_dma = response ring physical address
1896 qla1280_init_rings(struct scsi_qla_host *ha)
1898 uint16_t mb[MAILBOX_REGISTER_COUNT];
1901 ENTER("qla1280_init_rings");
1903 /* Clear outstanding commands array. */
1904 memset(ha->outstanding_cmds, 0,
1905 sizeof(struct srb *) * MAX_OUTSTANDING_COMMANDS);
1907 /* Initialize request queue. */
1908 ha->request_ring_ptr = ha->request_ring;
1909 ha->req_ring_index = 0;
1910 ha->req_q_cnt = REQUEST_ENTRY_CNT;
1911 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
1912 mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
1913 mb[1] = REQUEST_ENTRY_CNT;
1914 mb[3] = ha->request_dma & 0xffff;
1915 mb[2] = (ha->request_dma >> 16) & 0xffff;
1917 mb[7] = upper_32_bits(ha->request_dma) & 0xffff;
1918 mb[6] = upper_32_bits(ha->request_dma) >> 16;
1919 if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
1920 BIT_3 | BIT_2 | BIT_1 | BIT_0,
1922 /* Initialize response queue. */
1923 ha->response_ring_ptr = ha->response_ring;
1924 ha->rsp_ring_index = 0;
1925 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
1926 mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
1927 mb[1] = RESPONSE_ENTRY_CNT;
1928 mb[3] = ha->response_dma & 0xffff;
1929 mb[2] = (ha->response_dma >> 16) & 0xffff;
1931 mb[7] = upper_32_bits(ha->response_dma) & 0xffff;
1932 mb[6] = upper_32_bits(ha->response_dma) >> 16;
1933 status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
1934 BIT_3 | BIT_2 | BIT_1 | BIT_0,
1939 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
1941 LEAVE("qla1280_init_rings");
1946 qla1280_print_settings(struct nvram *nv)
1948 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
1949 nv->bus[0].config_1.initiator_id);
1950 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
1951 nv->bus[1].config_1.initiator_id);
1953 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
1954 nv->bus[0].bus_reset_delay);
1955 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
1956 nv->bus[1].bus_reset_delay);
1958 dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
1959 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
1960 dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
1961 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
1963 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
1964 nv->bus[0].config_2.async_data_setup_time);
1965 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
1966 nv->bus[1].config_2.async_data_setup_time);
1968 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
1969 nv->bus[0].config_2.req_ack_active_negation);
1970 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
1971 nv->bus[1].config_2.req_ack_active_negation);
1973 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
1974 nv->bus[0].config_2.data_line_active_negation);
1975 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
1976 nv->bus[1].config_2.data_line_active_negation);
1978 dprintk(1, "qla1280 : disable loading risc code=%d\n",
1979 nv->cntr_flags_1.disable_loading_risc_code);
1981 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
1982 nv->cntr_flags_1.enable_64bit_addressing);
1984 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
1985 nv->bus[0].selection_timeout);
1986 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
1987 nv->bus[1].selection_timeout);
1989 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
1990 nv->bus[0].max_queue_depth);
1991 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
1992 nv->bus[1].max_queue_depth);
1996 qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target)
1998 struct nvram *nv = &ha->nvram;
2000 nv->bus[bus].target[target].parameter.renegotiate_on_error = 1;
2001 nv->bus[bus].target[target].parameter.auto_request_sense = 1;
2002 nv->bus[bus].target[target].parameter.tag_queuing = 1;
2003 nv->bus[bus].target[target].parameter.enable_sync = 1;
2004 #if 1 /* Some SCSI Processors do not seem to like this */
2005 nv->bus[bus].target[target].parameter.enable_wide = 1;
2007 nv->bus[bus].target[target].execution_throttle =
2008 nv->bus[bus].max_queue_depth - 1;
2009 nv->bus[bus].target[target].parameter.parity_checking = 1;
2010 nv->bus[bus].target[target].parameter.disconnect_allowed = 1;
2012 if (IS_ISP1x160(ha)) {
2013 nv->bus[bus].target[target].flags.flags1x160.device_enable = 1;
2014 nv->bus[bus].target[target].flags.flags1x160.sync_offset = 0x0e;
2015 nv->bus[bus].target[target].sync_period = 9;
2016 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
2017 nv->bus[bus].target[target].ppr_1x160.flags.ppr_options = 2;
2018 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width = 1;
2020 nv->bus[bus].target[target].flags.flags1x80.device_enable = 1;
2021 nv->bus[bus].target[target].flags.flags1x80.sync_offset = 12;
2022 nv->bus[bus].target[target].sync_period = 10;
2027 qla1280_set_defaults(struct scsi_qla_host *ha)
2029 struct nvram *nv = &ha->nvram;
2032 dprintk(1, "Using defaults for NVRAM: \n");
2033 memset(nv, 0, sizeof(struct nvram));
2035 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
2036 nv->firmware_feature.f.enable_fast_posting = 1;
2037 nv->firmware_feature.f.disable_synchronous_backoff = 1;
2038 nv->termination.scsi_bus_0_control = 3;
2039 nv->termination.scsi_bus_1_control = 3;
2040 nv->termination.auto_term_support = 1;
2043 * Set default FIFO magic - What appropriate values would be here
2044 * is unknown. This is what I have found testing with 12160s.
2046 * Now, I would love the magic decoder ring for this one, the
2047 * header file provided by QLogic seems to be bogus or incomplete
2050 nv->isp_config.burst_enable = 1;
2052 nv->isp_config.fifo_threshold |= 3;
2054 nv->isp_config.fifo_threshold |= 4;
2056 if (IS_ISP1x160(ha))
2057 nv->isp_parameter = 0x01; /* fast memory enable */
2059 for (bus = 0; bus < MAX_BUSES; bus++) {
2060 nv->bus[bus].config_1.initiator_id = 7;
2061 nv->bus[bus].config_2.req_ack_active_negation = 1;
2062 nv->bus[bus].config_2.data_line_active_negation = 1;
2063 nv->bus[bus].selection_timeout = 250;
2064 nv->bus[bus].max_queue_depth = 32;
2066 if (IS_ISP1040(ha)) {
2067 nv->bus[bus].bus_reset_delay = 3;
2068 nv->bus[bus].config_2.async_data_setup_time = 6;
2069 nv->bus[bus].retry_delay = 1;
2071 nv->bus[bus].bus_reset_delay = 5;
2072 nv->bus[bus].config_2.async_data_setup_time = 8;
2075 for (target = 0; target < MAX_TARGETS; target++)
2076 qla1280_set_target_defaults(ha, bus, target);
2081 qla1280_config_target(struct scsi_qla_host *ha, int bus, int target)
2083 struct nvram *nv = &ha->nvram;
2084 uint16_t mb[MAILBOX_REGISTER_COUNT];
2088 /* Set Target Parameters. */
2089 mb[0] = MBC_SET_TARGET_PARAMETERS;
2090 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
2093 * Do not enable sync and ppr for the initial INQUIRY run. We
2094 * enable this later if we determine the target actually
2097 mb[2] = (TP_RENEGOTIATE | TP_AUTO_REQUEST_SENSE | TP_TAGGED_QUEUE
2098 | TP_WIDE | TP_PARITY | TP_DISCONNECT);
2100 if (IS_ISP1x160(ha))
2101 mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
2103 mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
2104 mb[3] |= nv->bus[bus].target[target].sync_period;
2105 status = qla1280_mailbox_command(ha, 0x0f, mb);
2107 /* Save Tag queuing enable flag. */
2108 flag = (BIT_0 << target);
2109 if (nv->bus[bus].target[target].parameter.tag_queuing)
2110 ha->bus_settings[bus].qtag_enables |= flag;
2112 /* Save Device enable flag. */
2113 if (IS_ISP1x160(ha)) {
2114 if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
2115 ha->bus_settings[bus].device_enables |= flag;
2116 ha->bus_settings[bus].lun_disables |= 0;
2118 if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
2119 ha->bus_settings[bus].device_enables |= flag;
2120 /* Save LUN disable flag. */
2121 if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
2122 ha->bus_settings[bus].lun_disables |= flag;
2125 /* Set Device Queue Parameters. */
2126 for (lun = 0; lun < MAX_LUNS; lun++) {
2127 mb[0] = MBC_SET_DEVICE_QUEUE;
2128 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
2130 mb[2] = nv->bus[bus].max_queue_depth;
2131 mb[3] = nv->bus[bus].target[target].execution_throttle;
2132 status |= qla1280_mailbox_command(ha, 0x0f, mb);
2139 qla1280_config_bus(struct scsi_qla_host *ha, int bus)
2141 struct nvram *nv = &ha->nvram;
2142 uint16_t mb[MAILBOX_REGISTER_COUNT];
2145 /* SCSI Reset Disable. */
2146 ha->bus_settings[bus].disable_scsi_reset =
2147 nv->bus[bus].config_1.scsi_reset_disable;
2150 ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
2151 mb[0] = MBC_SET_INITIATOR_ID;
2152 mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
2153 ha->bus_settings[bus].id;
2154 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2157 ha->bus_settings[bus].bus_reset_delay =
2158 nv->bus[bus].bus_reset_delay;
2160 /* Command queue depth per device. */
2161 ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
2163 /* Set target parameters. */
2164 for (target = 0; target < MAX_TARGETS; target++)
2165 status |= qla1280_config_target(ha, bus, target);
2171 qla1280_nvram_config(struct scsi_qla_host *ha)
2173 struct device_reg __iomem *reg = ha->iobase;
2174 struct nvram *nv = &ha->nvram;
2175 int bus, target, status = 0;
2176 uint16_t mb[MAILBOX_REGISTER_COUNT];
2178 ENTER("qla1280_nvram_config");
2180 if (ha->nvram_valid) {
2181 /* Always force AUTO sense for LINUX SCSI */
2182 for (bus = 0; bus < MAX_BUSES; bus++)
2183 for (target = 0; target < MAX_TARGETS; target++) {
2184 nv->bus[bus].target[target].parameter.
2185 auto_request_sense = 1;
2188 qla1280_set_defaults(ha);
2191 qla1280_print_settings(nv);
2193 /* Disable RISC load of firmware. */
2194 ha->flags.disable_risc_code_load =
2195 nv->cntr_flags_1.disable_loading_risc_code;
2197 if (IS_ISP1040(ha)) {
2198 uint16_t hwrev, cfg1, cdma_conf, ddma_conf;
2200 hwrev = RD_REG_WORD(®->cfg_0) & ISP_CFG0_HWMSK;
2202 cfg1 = RD_REG_WORD(®->cfg_1) & ~(BIT_4 | BIT_5 | BIT_6);
2203 cdma_conf = RD_REG_WORD(®->cdma_cfg);
2204 ddma_conf = RD_REG_WORD(®->ddma_cfg);
2206 /* Busted fifo, says mjacob. */
2207 if (hwrev != ISP_CFG0_1040A)
2208 cfg1 |= nv->isp_config.fifo_threshold << 4;
2210 cfg1 |= nv->isp_config.burst_enable << 2;
2211 WRT_REG_WORD(®->cfg_1, cfg1);
2213 WRT_REG_WORD(®->cdma_cfg, cdma_conf | CDMA_CONF_BENAB);
2214 WRT_REG_WORD(®->ddma_cfg, cdma_conf | DDMA_CONF_BENAB);
2216 uint16_t cfg1, term;
2218 /* Set ISP hardware DMA burst */
2219 cfg1 = nv->isp_config.fifo_threshold << 4;
2220 cfg1 |= nv->isp_config.burst_enable << 2;
2221 /* Enable DMA arbitration on dual channel controllers */
2224 WRT_REG_WORD(®->cfg_1, cfg1);
2226 /* Set SCSI termination. */
2227 WRT_REG_WORD(®->gpio_enable,
2228 BIT_7 | BIT_3 | BIT_2 | BIT_1 | BIT_0);
2229 term = nv->termination.scsi_bus_1_control;
2230 term |= nv->termination.scsi_bus_0_control << 2;
2231 term |= nv->termination.auto_term_support << 7;
2232 RD_REG_WORD(®->id_l); /* Flush PCI write */
2233 WRT_REG_WORD(®->gpio_data, term);
2235 RD_REG_WORD(®->id_l); /* Flush PCI write */
2237 /* ISP parameter word. */
2238 mb[0] = MBC_SET_SYSTEM_PARAMETER;
2239 mb[1] = nv->isp_parameter;
2240 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2242 if (IS_ISP1x40(ha)) {
2243 /* clock rate - for qla1240 and older, only */
2244 mb[0] = MBC_SET_CLOCK_RATE;
2246 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2249 /* Firmware feature word. */
2250 mb[0] = MBC_SET_FIRMWARE_FEATURES;
2251 mb[1] = nv->firmware_feature.f.enable_fast_posting;
2252 mb[1] |= nv->firmware_feature.f.report_lvd_bus_transition << 1;
2253 mb[1] |= nv->firmware_feature.f.disable_synchronous_backoff << 5;
2254 #if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
2255 if (ia64_platform_is("sn2")) {
2256 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
2257 "workaround\n", ha->host_no);
2258 mb[1] |= nv->firmware_feature.f.unused_9 << 9; /* XXX */
2261 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2263 /* Retry count and delay. */
2264 mb[0] = MBC_SET_RETRY_COUNT;
2265 mb[1] = nv->bus[0].retry_count;
2266 mb[2] = nv->bus[0].retry_delay;
2267 mb[6] = nv->bus[1].retry_count;
2268 mb[7] = nv->bus[1].retry_delay;
2269 status |= qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 |
2270 BIT_1 | BIT_0, &mb[0]);
2272 /* ASYNC data setup time. */
2273 mb[0] = MBC_SET_ASYNC_DATA_SETUP;
2274 mb[1] = nv->bus[0].config_2.async_data_setup_time;
2275 mb[2] = nv->bus[1].config_2.async_data_setup_time;
2276 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2278 /* Active negation states. */
2279 mb[0] = MBC_SET_ACTIVE_NEGATION;
2281 if (nv->bus[0].config_2.req_ack_active_negation)
2283 if (nv->bus[0].config_2.data_line_active_negation)
2286 if (nv->bus[1].config_2.req_ack_active_negation)
2288 if (nv->bus[1].config_2.data_line_active_negation)
2290 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2292 mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
2293 mb[1] = 2; /* Reset SCSI bus and return all outstanding IO */
2294 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2297 mb[0] = MBC_SET_PCI_CONTROL;
2298 mb[1] = BIT_1; /* Data DMA Channel Burst Enable */
2299 mb[2] = BIT_1; /* Command DMA Channel Burst Enable */
2300 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2302 mb[0] = MBC_SET_TAG_AGE_LIMIT;
2304 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2306 /* Selection timeout. */
2307 mb[0] = MBC_SET_SELECTION_TIMEOUT;
2308 mb[1] = nv->bus[0].selection_timeout;
2309 mb[2] = nv->bus[1].selection_timeout;
2310 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2312 for (bus = 0; bus < ha->ports; bus++)
2313 status |= qla1280_config_bus(ha, bus);
2316 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
2318 LEAVE("qla1280_nvram_config");
2323 * Get NVRAM data word
2324 * Calculates word position in NVRAM and calls request routine to
2325 * get the word from NVRAM.
2328 * ha = adapter block pointer.
2329 * address = NVRAM word address.
2335 qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
2340 nv_cmd = address << 16;
2341 nv_cmd |= NV_READ_OP;
2343 data = le16_to_cpu(qla1280_nvram_request(ha, nv_cmd));
2345 dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
2353 * Sends read command to NVRAM and gets data from NVRAM.
2356 * ha = adapter block pointer.
2357 * nv_cmd = Bit 26 = start bit
2358 * Bit 25, 24 = opcode
2359 * Bit 23-16 = address
2360 * Bit 15-0 = write data
2366 qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
2368 struct device_reg __iomem *reg = ha->iobase;
2373 /* Send command to NVRAM. */
2376 for (cnt = 0; cnt < 11; cnt++) {
2377 if (nv_cmd & BIT_31)
2378 qla1280_nv_write(ha, NV_DATA_OUT);
2380 qla1280_nv_write(ha, 0);
2384 /* Read data from NVRAM. */
2386 for (cnt = 0; cnt < 16; cnt++) {
2387 WRT_REG_WORD(®->nvram, (NV_SELECT | NV_CLOCK));
2388 RD_REG_WORD(®->id_l); /* Flush PCI write */
2391 reg_data = RD_REG_WORD(®->nvram);
2392 if (reg_data & NV_DATA_IN)
2394 WRT_REG_WORD(®->nvram, NV_SELECT);
2395 RD_REG_WORD(®->id_l); /* Flush PCI write */
2399 /* Deselect chip. */
2401 WRT_REG_WORD(®->nvram, NV_DESELECT);
2402 RD_REG_WORD(®->id_l); /* Flush PCI write */
2409 qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
2411 struct device_reg __iomem *reg = ha->iobase;
2413 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2414 RD_REG_WORD(®->id_l); /* Flush PCI write */
2416 WRT_REG_WORD(®->nvram, data | NV_SELECT | NV_CLOCK);
2417 RD_REG_WORD(®->id_l); /* Flush PCI write */
2419 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2420 RD_REG_WORD(®->id_l); /* Flush PCI write */
2426 * Issue mailbox command and waits for completion.
2429 * ha = adapter block pointer.
2430 * mr = mailbox registers to load.
2431 * mb = data pointer for mailbox registers.
2434 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
2440 qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
2442 struct device_reg __iomem *reg = ha->iobase;
2445 uint16_t *optr, *iptr;
2446 uint16_t __iomem *mptr;
2448 DECLARE_COMPLETION_ONSTACK(wait);
2450 ENTER("qla1280_mailbox_command");
2452 if (ha->mailbox_wait) {
2453 printk(KERN_ERR "Warning mailbox wait already in use!\n");
2455 ha->mailbox_wait = &wait;
2458 * We really should start out by verifying that the mailbox is
2459 * available before starting sending the command data
2461 /* Load mailbox registers. */
2462 mptr = (uint16_t __iomem *) ®->mailbox0;
2464 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
2466 WRT_REG_WORD(mptr, (*iptr));
2474 /* Issue set host interrupt command. */
2476 /* set up a timer just in case we're really jammed */
2477 timer_setup(&ha->mailbox_timer, qla1280_mailbox_timeout, 0);
2478 mod_timer(&ha->mailbox_timer, jiffies + 20 * HZ);
2480 spin_unlock_irq(ha->host->host_lock);
2481 WRT_REG_WORD(®->host_cmd, HC_SET_HOST_INT);
2482 data = qla1280_debounce_register(®->istatus);
2484 wait_for_completion(&wait);
2485 del_timer_sync(&ha->mailbox_timer);
2487 spin_lock_irq(ha->host->host_lock);
2489 ha->mailbox_wait = NULL;
2491 /* Check for mailbox command timeout. */
2492 if (ha->mailbox_out[0] != MBS_CMD_CMP) {
2493 printk(KERN_WARNING "qla1280_mailbox_command: Command failed, "
2494 "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
2496 mb[0], ha->mailbox_out[0], RD_REG_WORD(®->istatus));
2497 printk(KERN_WARNING "m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
2498 RD_REG_WORD(®->mailbox0), RD_REG_WORD(®->mailbox1),
2499 RD_REG_WORD(®->mailbox2), RD_REG_WORD(®->mailbox3));
2500 printk(KERN_WARNING "m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
2501 RD_REG_WORD(®->mailbox4), RD_REG_WORD(®->mailbox5),
2502 RD_REG_WORD(®->mailbox6), RD_REG_WORD(®->mailbox7));
2506 /* Load return mailbox registers. */
2508 iptr = (uint16_t *) &ha->mailbox_out[0];
2509 mr = MAILBOX_REGISTER_COUNT;
2510 memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
2512 if (ha->flags.reset_marker)
2513 qla1280_rst_aen(ha);
2516 dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
2517 "0x%x ****\n", mb[0]);
2519 LEAVE("qla1280_mailbox_command");
2525 * Polls ISP for interrupts.
2528 * ha = adapter block pointer.
2531 qla1280_poll(struct scsi_qla_host *ha)
2533 struct device_reg __iomem *reg = ha->iobase;
2537 /* ENTER("qla1280_poll"); */
2539 /* Check for pending interrupts. */
2540 data = RD_REG_WORD(®->istatus);
2541 if (data & RISC_INT)
2542 qla1280_isr(ha, &done_q);
2544 if (!ha->mailbox_wait) {
2545 if (ha->flags.reset_marker)
2546 qla1280_rst_aen(ha);
2549 if (!list_empty(&done_q))
2552 /* LEAVE("qla1280_poll"); */
2557 * Issue SCSI bus reset.
2560 * ha = adapter block pointer.
2561 * bus = SCSI bus number.
2567 qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
2569 uint16_t mb[MAILBOX_REGISTER_COUNT];
2570 uint16_t reset_delay;
2573 dprintk(3, "qla1280_bus_reset: entered\n");
2575 if (qla1280_verbose)
2576 printk(KERN_INFO "scsi(%li:%i): Resetting SCSI BUS\n",
2579 reset_delay = ha->bus_settings[bus].bus_reset_delay;
2580 mb[0] = MBC_BUS_RESET;
2581 mb[1] = reset_delay;
2582 mb[2] = (uint16_t) bus;
2583 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2586 if (ha->bus_settings[bus].failed_reset_count > 2)
2587 ha->bus_settings[bus].scsi_bus_dead = 1;
2588 ha->bus_settings[bus].failed_reset_count++;
2590 spin_unlock_irq(ha->host->host_lock);
2591 ssleep(reset_delay);
2592 spin_lock_irq(ha->host->host_lock);
2594 ha->bus_settings[bus].scsi_bus_dead = 0;
2595 ha->bus_settings[bus].failed_reset_count = 0;
2596 ha->bus_settings[bus].reset_marker = 0;
2597 /* Issue marker command. */
2598 qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
2602 * We should probably call qla1280_set_target_parameters()
2603 * here as well for all devices on the bus.
2607 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
2609 dprintk(3, "qla1280_bus_reset: exiting normally\n");
2615 * qla1280_device_reset
2616 * Issue bus device reset message to the target.
2619 * ha = adapter block pointer.
2620 * bus = SCSI BUS number.
2627 qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
2629 uint16_t mb[MAILBOX_REGISTER_COUNT];
2632 ENTER("qla1280_device_reset");
2634 mb[0] = MBC_ABORT_TARGET;
2635 mb[1] = (bus ? (target | BIT_7) : target) << 8;
2637 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2639 /* Issue marker command. */
2640 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
2643 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
2645 LEAVE("qla1280_device_reset");
2650 * qla1280_abort_command
2651 * Abort command aborts a specified IOCB.
2654 * ha = adapter block pointer.
2655 * sp = SB structure pointer.
2661 qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
2663 uint16_t mb[MAILBOX_REGISTER_COUNT];
2664 unsigned int bus, target, lun;
2667 ENTER("qla1280_abort_command");
2669 bus = SCSI_BUS_32(sp->cmd);
2670 target = SCSI_TCN_32(sp->cmd);
2671 lun = SCSI_LUN_32(sp->cmd);
2673 sp->flags |= SRB_ABORT_PENDING;
2675 mb[0] = MBC_ABORT_COMMAND;
2676 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
2677 mb[2] = handle >> 16;
2678 mb[3] = handle & 0xffff;
2679 status = qla1280_mailbox_command(ha, 0x0f, &mb[0]);
2682 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
2683 sp->flags &= ~SRB_ABORT_PENDING;
2687 LEAVE("qla1280_abort_command");
2692 * qla1280_reset_adapter
2696 * ha = adapter block pointer.
2699 qla1280_reset_adapter(struct scsi_qla_host *ha)
2701 struct device_reg __iomem *reg = ha->iobase;
2703 ENTER("qla1280_reset_adapter");
2705 /* Disable ISP chip */
2706 ha->flags.online = 0;
2707 WRT_REG_WORD(®->ictrl, ISP_RESET);
2708 WRT_REG_WORD(®->host_cmd,
2709 HC_RESET_RISC | HC_RELEASE_RISC | HC_DISABLE_BIOS);
2710 RD_REG_WORD(®->id_l); /* Flush PCI write */
2712 LEAVE("qla1280_reset_adapter");
2716 * Issue marker command.
2717 * Function issues marker IOCB.
2720 * ha = adapter block pointer.
2721 * bus = SCSI BUS number
2724 * type = marker modifier
2727 qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
2729 struct mrk_entry *pkt;
2731 ENTER("qla1280_marker");
2733 /* Get request packet. */
2734 if ((pkt = (struct mrk_entry *) qla1280_req_pkt(ha))) {
2735 pkt->entry_type = MARKER_TYPE;
2736 pkt->lun = (uint8_t) lun;
2737 pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
2738 pkt->modifier = type;
2739 pkt->entry_status = 0;
2741 /* Issue command to ISP */
2742 qla1280_isp_cmd(ha);
2745 LEAVE("qla1280_marker");
2750 * qla1280_64bit_start_scsi
2751 * The start SCSI is responsible for building request packets on
2752 * request ring and modifying ISP input pointer.
2755 * ha = adapter block pointer.
2756 * sp = SB structure pointer.
2759 * 0 = success, was able to issue command.
2761 #ifdef QLA_64BIT_PTR
2763 qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
2765 struct device_reg __iomem *reg = ha->iobase;
2766 struct scsi_cmnd *cmd = sp->cmd;
2767 cmd_a64_entry_t *pkt;
2769 dma_addr_t dma_handle;
2776 ENTER("qla1280_64bit_start_scsi:");
2778 /* Calculate number of entries and segments required. */
2780 seg_cnt = scsi_dma_map(cmd);
2783 req_cnt += (seg_cnt - 2) / 5;
2784 if ((seg_cnt - 2) % 5)
2787 } else if (seg_cnt < 0) {
2792 if ((req_cnt + 2) >= ha->req_q_cnt) {
2793 /* Calculate number of free request entries. */
2794 cnt = RD_REG_WORD(®->mailbox4);
2795 if (ha->req_ring_index < cnt)
2796 ha->req_q_cnt = cnt - ha->req_ring_index;
2799 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
2802 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
2803 ha->req_q_cnt, seg_cnt);
2805 /* If room for request in request ring. */
2806 if ((req_cnt + 2) >= ha->req_q_cnt) {
2807 status = SCSI_MLQUEUE_HOST_BUSY;
2808 dprintk(2, "qla1280_start_scsi: in-ptr=0x%x req_q_cnt="
2809 "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
2814 /* Check for room in outstanding command list. */
2815 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
2816 ha->outstanding_cmds[cnt] != NULL; cnt++);
2818 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
2819 status = SCSI_MLQUEUE_HOST_BUSY;
2820 dprintk(2, "qla1280_start_scsi: NO ROOM IN "
2821 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
2825 ha->outstanding_cmds[cnt] = sp;
2826 ha->req_q_cnt -= req_cnt;
2827 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
2829 dprintk(2, "start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
2830 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
2831 dprintk(2, " bus %i, target %i, lun %i\n",
2832 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2833 qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
2836 * Build command packet.
2838 pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
2840 pkt->entry_type = COMMAND_A64_TYPE;
2841 pkt->entry_count = (uint8_t) req_cnt;
2842 pkt->sys_define = (uint8_t) ha->req_ring_index;
2843 pkt->entry_status = 0;
2844 pkt->handle = cpu_to_le32(cnt);
2846 /* Zero out remaining portion of packet. */
2847 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
2849 /* Set ISP command timeout. */
2850 pkt->timeout = cpu_to_le16(cmd->request->timeout/HZ);
2852 /* Set device target ID and LUN */
2853 pkt->lun = SCSI_LUN_32(cmd);
2854 pkt->target = SCSI_BUS_32(cmd) ?
2855 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
2857 /* Enable simple tag queuing if device supports it. */
2858 if (cmd->device->simple_tags)
2859 pkt->control_flags |= cpu_to_le16(BIT_3);
2861 /* Load SCSI command packet. */
2862 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
2863 memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd));
2864 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
2866 /* Set transfer direction. */
2867 dir = qla1280_data_direction(cmd);
2868 pkt->control_flags |= cpu_to_le16(dir);
2870 /* Set total data segment count. */
2871 pkt->dseg_count = cpu_to_le16(seg_cnt);
2874 * Load data segments.
2876 if (seg_cnt) { /* If data transfer. */
2877 struct scatterlist *sg, *s;
2878 int remseg = seg_cnt;
2880 sg = scsi_sglist(cmd);
2882 /* Setup packet address segment pointer. */
2883 dword_ptr = (u32 *)&pkt->dseg_0_address;
2885 /* Load command entry data segments. */
2886 for_each_sg(sg, s, seg_cnt, cnt) {
2890 dma_handle = sg_dma_address(s);
2891 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2892 if (ha->flags.use_pci_vchannel)
2893 sn_pci_set_vchan(ha->pdev,
2894 (unsigned long *)&dma_handle,
2898 cpu_to_le32(lower_32_bits(dma_handle));
2900 cpu_to_le32(upper_32_bits(dma_handle));
2901 *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
2902 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
2903 cpu_to_le32(upper_32_bits(dma_handle)),
2904 cpu_to_le32(lower_32_bits(dma_handle)),
2905 cpu_to_le32(sg_dma_len(sg_next(s))));
2908 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
2909 "command packet data - b %i, t %i, l %i \n",
2910 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
2912 qla1280_dump_buffer(5, (char *)pkt,
2913 REQUEST_ENTRY_SIZE);
2916 * Build continuation packets.
2918 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
2919 "remains\n", seg_cnt);
2921 while (remseg > 0) {
2922 /* Update sg start */
2924 /* Adjust ring index. */
2925 ha->req_ring_index++;
2926 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
2927 ha->req_ring_index = 0;
2928 ha->request_ring_ptr =
2931 ha->request_ring_ptr++;
2933 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
2935 /* Zero out packet. */
2936 memset(pkt, 0, REQUEST_ENTRY_SIZE);
2938 /* Load packet defaults. */
2939 ((struct cont_a64_entry *) pkt)->entry_type =
2941 ((struct cont_a64_entry *) pkt)->entry_count = 1;
2942 ((struct cont_a64_entry *) pkt)->sys_define =
2943 (uint8_t)ha->req_ring_index;
2944 /* Setup packet address segment pointer. */
2946 (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
2948 /* Load continuation entry data segments. */
2949 for_each_sg(sg, s, remseg, cnt) {
2952 dma_handle = sg_dma_address(s);
2953 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2954 if (ha->flags.use_pci_vchannel)
2955 sn_pci_set_vchan(ha->pdev,
2956 (unsigned long *)&dma_handle,
2960 cpu_to_le32(lower_32_bits(dma_handle));
2962 cpu_to_le32(upper_32_bits(dma_handle));
2964 cpu_to_le32(sg_dma_len(s));
2965 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
2966 cpu_to_le32(upper_32_bits(dma_handle)),
2967 cpu_to_le32(lower_32_bits(dma_handle)),
2968 cpu_to_le32(sg_dma_len(s)));
2971 dprintk(5, "qla1280_64bit_start_scsi: "
2972 "continuation packet data - b %i, t "
2973 "%i, l %i \n", SCSI_BUS_32(cmd),
2974 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2975 qla1280_dump_buffer(5, (char *)pkt,
2976 REQUEST_ENTRY_SIZE);
2978 } else { /* No data transfer */
2979 dprintk(5, "qla1280_64bit_start_scsi: No data, command "
2980 "packet data - b %i, t %i, l %i \n",
2981 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2982 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
2984 /* Adjust ring index. */
2985 ha->req_ring_index++;
2986 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
2987 ha->req_ring_index = 0;
2988 ha->request_ring_ptr = ha->request_ring;
2990 ha->request_ring_ptr++;
2992 /* Set chip new ring index. */
2994 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
2995 sp->flags |= SRB_SENT;
2997 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3001 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
3003 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
3007 #else /* !QLA_64BIT_PTR */
3010 * qla1280_32bit_start_scsi
3011 * The start SCSI is responsible for building request packets on
3012 * request ring and modifying ISP input pointer.
3014 * The Qlogic firmware interface allows every queue slot to have a SCSI
3015 * command and up to 4 scatter/gather (SG) entries. If we need more
3016 * than 4 SG entries, then continuation entries are used that can
3017 * hold another 7 entries each. The start routine determines if there
3018 * is eought empty slots then build the combination of requests to
3019 * fulfill the OS request.
3022 * ha = adapter block pointer.
3023 * sp = SCSI Request Block structure pointer.
3026 * 0 = success, was able to issue command.
3029 qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3031 struct device_reg __iomem *reg = ha->iobase;
3032 struct scsi_cmnd *cmd = sp->cmd;
3033 struct cmd_entry *pkt;
3041 ENTER("qla1280_32bit_start_scsi");
3043 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
3046 /* Calculate number of entries and segments required. */
3048 seg_cnt = scsi_dma_map(cmd);
3051 * if greater than four sg entries then we need to allocate
3052 * continuation entries
3055 req_cnt += (seg_cnt - 4) / 7;
3056 if ((seg_cnt - 4) % 7)
3059 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3060 cmd, seg_cnt, req_cnt);
3061 } else if (seg_cnt < 0) {
3066 if ((req_cnt + 2) >= ha->req_q_cnt) {
3067 /* Calculate number of free request entries. */
3068 cnt = RD_REG_WORD(®->mailbox4);
3069 if (ha->req_ring_index < cnt)
3070 ha->req_q_cnt = cnt - ha->req_ring_index;
3073 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3076 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3077 ha->req_q_cnt, seg_cnt);
3078 /* If room for request in request ring. */
3079 if ((req_cnt + 2) >= ha->req_q_cnt) {
3080 status = SCSI_MLQUEUE_HOST_BUSY;
3081 dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
3082 "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
3083 ha->req_q_cnt, req_cnt);
3087 /* Check for empty slot in outstanding command list. */
3088 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3089 (ha->outstanding_cmds[cnt] != 0); cnt++) ;
3091 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3092 status = SCSI_MLQUEUE_HOST_BUSY;
3093 dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
3094 "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
3098 CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
3099 ha->outstanding_cmds[cnt] = sp;
3100 ha->req_q_cnt -= req_cnt;
3103 * Build command packet.
3105 pkt = (struct cmd_entry *) ha->request_ring_ptr;
3107 pkt->entry_type = COMMAND_TYPE;
3108 pkt->entry_count = (uint8_t) req_cnt;
3109 pkt->sys_define = (uint8_t) ha->req_ring_index;
3110 pkt->entry_status = 0;
3111 pkt->handle = cpu_to_le32(cnt);
3113 /* Zero out remaining portion of packet. */
3114 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3116 /* Set ISP command timeout. */
3117 pkt->timeout = cpu_to_le16(cmd->request->timeout/HZ);
3119 /* Set device target ID and LUN */
3120 pkt->lun = SCSI_LUN_32(cmd);
3121 pkt->target = SCSI_BUS_32(cmd) ?
3122 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3124 /* Enable simple tag queuing if device supports it. */
3125 if (cmd->device->simple_tags)
3126 pkt->control_flags |= cpu_to_le16(BIT_3);
3128 /* Load SCSI command packet. */
3129 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3130 memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd));
3132 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3133 /* Set transfer direction. */
3134 dir = qla1280_data_direction(cmd);
3135 pkt->control_flags |= cpu_to_le16(dir);
3137 /* Set total data segment count. */
3138 pkt->dseg_count = cpu_to_le16(seg_cnt);
3141 * Load data segments.
3144 struct scatterlist *sg, *s;
3145 int remseg = seg_cnt;
3147 sg = scsi_sglist(cmd);
3149 /* Setup packet address segment pointer. */
3150 dword_ptr = &pkt->dseg_0_address;
3152 dprintk(3, "Building S/G data segments..\n");
3153 qla1280_dump_buffer(1, (char *)sg, 4 * 16);
3155 /* Load command entry data segments. */
3156 for_each_sg(sg, s, seg_cnt, cnt) {
3160 cpu_to_le32(lower_32_bits(sg_dma_address(s)));
3161 *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
3162 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3163 (lower_32_bits(sg_dma_address(s))),
3168 * Build continuation packets.
3170 dprintk(3, "S/G Building Continuation"
3171 "...seg_cnt=0x%x remains\n", seg_cnt);
3172 while (remseg > 0) {
3173 /* Continue from end point */
3175 /* Adjust ring index. */
3176 ha->req_ring_index++;
3177 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3178 ha->req_ring_index = 0;
3179 ha->request_ring_ptr =
3182 ha->request_ring_ptr++;
3184 pkt = (struct cmd_entry *)ha->request_ring_ptr;
3186 /* Zero out packet. */
3187 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3189 /* Load packet defaults. */
3190 ((struct cont_entry *) pkt)->
3191 entry_type = CONTINUE_TYPE;
3192 ((struct cont_entry *) pkt)->entry_count = 1;
3194 ((struct cont_entry *) pkt)->sys_define =
3195 (uint8_t) ha->req_ring_index;
3197 /* Setup packet address segment pointer. */
3199 &((struct cont_entry *) pkt)->dseg_0_address;
3201 /* Load continuation entry data segments. */
3202 for_each_sg(sg, s, remseg, cnt) {
3206 cpu_to_le32(lower_32_bits(sg_dma_address(s)));
3208 cpu_to_le32(sg_dma_len(s));
3210 "S/G Segment Cont. phys_addr=0x%x, "
3212 cpu_to_le32(lower_32_bits(sg_dma_address(s))),
3213 cpu_to_le32(sg_dma_len(s)));
3216 dprintk(5, "qla1280_32bit_start_scsi: "
3217 "continuation packet data - "
3218 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
3219 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3220 qla1280_dump_buffer(5, (char *)pkt,
3221 REQUEST_ENTRY_SIZE);
3223 } else { /* No data transfer at all */
3224 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
3225 "packet data - \n");
3226 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3228 dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
3229 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3230 REQUEST_ENTRY_SIZE);
3232 /* Adjust ring index. */
3233 ha->req_ring_index++;
3234 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3235 ha->req_ring_index = 0;
3236 ha->request_ring_ptr = ha->request_ring;
3238 ha->request_ring_ptr++;
3240 /* Set chip new ring index. */
3241 dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
3242 "for pending command\n");
3243 sp->flags |= SRB_SENT;
3245 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3249 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
3251 LEAVE("qla1280_32bit_start_scsi");
3259 * Function is responsible for locking ring and
3260 * getting a zeroed out request packet.
3263 * ha = adapter block pointer.
3266 * 0 = failed to get slot.
3269 qla1280_req_pkt(struct scsi_qla_host *ha)
3271 struct device_reg __iomem *reg = ha->iobase;
3272 request_t *pkt = NULL;
3276 ENTER("qla1280_req_pkt");
3279 * This can be called from interrupt context, damn it!!!
3281 /* Wait for 30 seconds for slot. */
3282 for (timer = 15000000; timer; timer--) {
3283 if (ha->req_q_cnt > 0) {
3284 /* Calculate number of free request entries. */
3285 cnt = RD_REG_WORD(®->mailbox4);
3286 if (ha->req_ring_index < cnt)
3287 ha->req_q_cnt = cnt - ha->req_ring_index;
3290 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3293 /* Found empty request ring slot? */
3294 if (ha->req_q_cnt > 0) {
3296 pkt = ha->request_ring_ptr;
3298 /* Zero out packet. */
3299 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3302 * How can this be right when we have a ring
3305 /* Set system defined field. */
3306 pkt->sys_define = (uint8_t) ha->req_ring_index;
3308 /* Set entry count. */
3309 pkt->entry_count = 1;
3316 /* Check for pending interrupts. */
3321 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
3323 dprintk(3, "qla1280_req_pkt: exiting normally\n");
3330 * Function is responsible for modifying ISP input pointer.
3331 * Releases ring lock.
3334 * ha = adapter block pointer.
3337 qla1280_isp_cmd(struct scsi_qla_host *ha)
3339 struct device_reg __iomem *reg = ha->iobase;
3341 ENTER("qla1280_isp_cmd");
3343 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
3344 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3345 REQUEST_ENTRY_SIZE);
3347 /* Adjust ring index. */
3348 ha->req_ring_index++;
3349 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3350 ha->req_ring_index = 0;
3351 ha->request_ring_ptr = ha->request_ring;
3353 ha->request_ring_ptr++;
3356 * Update request index to mailbox4 (Request Queue In).
3358 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3360 LEAVE("qla1280_isp_cmd");
3363 /****************************************************************************/
3364 /* Interrupt Service Routine. */
3365 /****************************************************************************/
3367 /****************************************************************************
3369 * Calls I/O done on command completion.
3372 * ha = adapter block pointer.
3373 * done_q = done queue.
3374 ****************************************************************************/
3376 qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
3378 struct device_reg __iomem *reg = ha->iobase;
3379 struct response *pkt;
3380 struct srb *sp = NULL;
3381 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
3386 ENTER("qla1280_isr");
3388 istatus = RD_REG_WORD(®->istatus);
3389 if (!(istatus & (RISC_INT | PCI_INT)))
3392 /* Save mailbox register 5 */
3393 mailbox[5] = RD_REG_WORD(®->mailbox5);
3395 /* Check for mailbox interrupt. */
3397 mailbox[0] = RD_REG_WORD_dmasync(®->semaphore);
3399 if (mailbox[0] & BIT_0) {
3400 /* Get mailbox data. */
3401 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
3404 *wptr++ = RD_REG_WORD(®->mailbox0);
3405 *wptr++ = RD_REG_WORD(®->mailbox1);
3406 *wptr = RD_REG_WORD(®->mailbox2);
3407 if (mailbox[0] != MBA_SCSI_COMPLETION) {
3409 *wptr++ = RD_REG_WORD(®->mailbox3);
3410 *wptr++ = RD_REG_WORD(®->mailbox4);
3412 *wptr++ = RD_REG_WORD(®->mailbox6);
3413 *wptr = RD_REG_WORD(®->mailbox7);
3416 /* Release mailbox registers. */
3418 WRT_REG_WORD(®->semaphore, 0);
3419 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3421 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
3424 /* Handle asynchronous event */
3425 switch (mailbox[0]) {
3426 case MBA_SCSI_COMPLETION: /* Response completion */
3427 dprintk(5, "qla1280_isr: mailbox SCSI response "
3430 if (ha->flags.online) {
3431 /* Get outstanding command index. */
3432 index = mailbox[2] << 16 | mailbox[1];
3434 /* Validate handle. */
3435 if (index < MAX_OUTSTANDING_COMMANDS)
3436 sp = ha->outstanding_cmds[index];
3441 /* Free outstanding command slot. */
3442 ha->outstanding_cmds[index] = NULL;
3444 /* Save ISP completion status */
3445 CMD_RESULT(sp->cmd) = 0;
3446 CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
3448 /* Place block on done queue */
3449 list_add_tail(&sp->list, done_q);
3452 * If we get here we have a real problem!
3455 "qla1280: ISP invalid handle\n");
3460 case MBA_BUS_RESET: /* SCSI Bus Reset */
3461 ha->flags.reset_marker = 1;
3462 index = mailbox[6] & BIT_0;
3463 ha->bus_settings[index].reset_marker = 1;
3465 printk(KERN_DEBUG "qla1280_isr(): index %i "
3466 "asynchronous BUS_RESET\n", index);
3469 case MBA_SYSTEM_ERR: /* System Error */
3471 "qla1280: ISP System Error - mbx1=%xh, mbx2="
3472 "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
3476 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
3478 "qla1280: ISP Request Transfer Error\n");
3481 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
3483 "qla1280: ISP Response Transfer Error\n");
3486 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
3487 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
3490 case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
3492 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
3495 case MBA_DEVICE_RESET: /* Bus Device Reset */
3496 printk(KERN_INFO "qla1280_isr(): asynchronous "
3497 "BUS_DEVICE_RESET\n");
3499 ha->flags.reset_marker = 1;
3500 index = mailbox[6] & BIT_0;
3501 ha->bus_settings[index].reset_marker = 1;
3504 case MBA_BUS_MODE_CHANGE:
3506 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
3510 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
3511 if (mailbox[0] < MBA_ASYNC_EVENT) {
3513 memcpy((uint16_t *) ha->mailbox_out, wptr,
3514 MAILBOX_REGISTER_COUNT *
3517 if(ha->mailbox_wait != NULL)
3518 complete(ha->mailbox_wait);
3523 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3527 * We will receive interrupts during mailbox testing prior to
3528 * the card being marked online, hence the double check.
3530 if (!(ha->flags.online && !ha->mailbox_wait)) {
3531 dprintk(2, "qla1280_isr: Response pointer Error\n");
3535 if (mailbox[5] >= RESPONSE_ENTRY_CNT)
3538 while (ha->rsp_ring_index != mailbox[5]) {
3539 pkt = ha->response_ring_ptr;
3541 dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
3542 " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
3543 dprintk(5,"qla1280_isr: response packet data\n");
3544 qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
3546 if (pkt->entry_type == STATUS_TYPE) {
3547 if ((le16_to_cpu(pkt->scsi_status) & 0xff)
3548 || pkt->comp_status || pkt->entry_status) {
3549 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3550 "0x%x mailbox[5] = 0x%x, comp_status "
3551 "= 0x%x, scsi_status = 0x%x\n",
3552 ha->rsp_ring_index, mailbox[5],
3553 le16_to_cpu(pkt->comp_status),
3554 le16_to_cpu(pkt->scsi_status));
3557 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3558 "0x%x, mailbox[5] = 0x%x\n",
3559 ha->rsp_ring_index, mailbox[5]);
3560 dprintk(2, "qla1280_isr: response packet data\n");
3561 qla1280_dump_buffer(2, (char *)pkt,
3562 RESPONSE_ENTRY_SIZE);
3565 if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
3566 dprintk(2, "status: Cmd %p, handle %i\n",
3567 ha->outstanding_cmds[pkt->handle]->cmd,
3569 if (pkt->entry_type == STATUS_TYPE)
3570 qla1280_status_entry(ha, pkt, done_q);
3572 qla1280_error_entry(ha, pkt, done_q);
3573 /* Adjust ring index. */
3574 ha->rsp_ring_index++;
3575 if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
3576 ha->rsp_ring_index = 0;
3577 ha->response_ring_ptr = ha->response_ring;
3579 ha->response_ring_ptr++;
3580 WRT_REG_WORD(®->mailbox5, ha->rsp_ring_index);
3585 LEAVE("qla1280_isr");
3590 * Processes asynchronous reset.
3593 * ha = adapter block pointer.
3596 qla1280_rst_aen(struct scsi_qla_host *ha)
3600 ENTER("qla1280_rst_aen");
3602 if (ha->flags.online && !ha->flags.reset_active &&
3603 !ha->flags.abort_isp_active) {
3604 ha->flags.reset_active = 1;
3605 while (ha->flags.reset_marker) {
3606 /* Issue marker command. */
3607 ha->flags.reset_marker = 0;
3608 for (bus = 0; bus < ha->ports &&
3609 !ha->flags.reset_marker; bus++) {
3610 if (ha->bus_settings[bus].reset_marker) {
3611 ha->bus_settings[bus].reset_marker = 0;
3612 qla1280_marker(ha, bus, 0, 0,
3619 LEAVE("qla1280_rst_aen");
3624 * qla1280_status_entry
3625 * Processes received ISP status entry.
3628 * ha = adapter block pointer.
3629 * pkt = entry pointer.
3630 * done_q = done queue.
3633 qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
3634 struct list_head *done_q)
3636 unsigned int bus, target, lun;
3639 struct scsi_cmnd *cmd;
3640 uint32_t handle = le32_to_cpu(pkt->handle);
3641 uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
3642 uint16_t comp_status = le16_to_cpu(pkt->comp_status);
3644 ENTER("qla1280_status_entry");
3646 /* Validate handle. */
3647 if (handle < MAX_OUTSTANDING_COMMANDS)
3648 sp = ha->outstanding_cmds[handle];
3653 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
3657 /* Free outstanding command slot. */
3658 ha->outstanding_cmds[handle] = NULL;
3662 /* Generate LU queue on cntrl, target, LUN */
3663 bus = SCSI_BUS_32(cmd);
3664 target = SCSI_TCN_32(cmd);
3665 lun = SCSI_LUN_32(cmd);
3667 if (comp_status || scsi_status) {
3668 dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
3669 "0x%x, handle = 0x%x\n", comp_status,
3670 scsi_status, handle);
3673 /* Target busy or queue full */
3674 if ((scsi_status & 0xFF) == SAM_STAT_TASK_SET_FULL ||
3675 (scsi_status & 0xFF) == SAM_STAT_BUSY) {
3676 CMD_RESULT(cmd) = scsi_status & 0xff;
3679 /* Save ISP completion status */
3680 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
3682 if (scsi_status & SAM_STAT_CHECK_CONDITION) {
3683 if (comp_status != CS_ARS_FAILED) {
3684 uint16_t req_sense_length =
3685 le16_to_cpu(pkt->req_sense_length);
3686 if (req_sense_length < CMD_SNSLEN(cmd))
3687 sense_sz = req_sense_length;
3690 * scsi_cmnd->sense_buffer is
3691 * 64 bytes, why only copy 63?
3692 * This looks wrong! /Jes
3694 sense_sz = CMD_SNSLEN(cmd) - 1;
3696 memcpy(cmd->sense_buffer,
3697 &pkt->req_sense_data, sense_sz);
3700 memset(cmd->sense_buffer + sense_sz, 0,
3701 SCSI_SENSE_BUFFERSIZE - sense_sz);
3703 dprintk(2, "qla1280_status_entry: Check "
3704 "condition Sense data, b %i, t %i, "
3705 "l %i\n", bus, target, lun);
3707 qla1280_dump_buffer(2,
3708 (char *)cmd->sense_buffer,
3713 CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
3715 /* Place command on done queue. */
3716 list_add_tail(&sp->list, done_q);
3718 LEAVE("qla1280_status_entry");
3722 * qla1280_error_entry
3723 * Processes error entry.
3726 * ha = adapter block pointer.
3727 * pkt = entry pointer.
3728 * done_q = done queue.
3731 qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
3732 struct list_head *done_q)
3735 uint32_t handle = le32_to_cpu(pkt->handle);
3737 ENTER("qla1280_error_entry");
3739 if (pkt->entry_status & BIT_3)
3740 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
3741 else if (pkt->entry_status & BIT_2)
3742 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
3743 else if (pkt->entry_status & BIT_1)
3744 dprintk(2, "qla1280_error_entry: FULL flag error\n");
3746 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
3748 /* Validate handle. */
3749 if (handle < MAX_OUTSTANDING_COMMANDS)
3750 sp = ha->outstanding_cmds[handle];
3755 /* Free outstanding command slot. */
3756 ha->outstanding_cmds[handle] = NULL;
3758 /* Bad payload or header */
3759 if (pkt->entry_status & (BIT_3 + BIT_2)) {
3760 /* Bad payload or header, set error status. */
3761 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
3762 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
3763 } else if (pkt->entry_status & BIT_1) { /* FULL flag */
3764 CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
3766 /* Set error status. */
3767 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
3770 CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
3772 /* Place command on done queue. */
3773 list_add_tail(&sp->list, done_q);
3775 #ifdef QLA_64BIT_PTR
3776 else if (pkt->entry_type == COMMAND_A64_TYPE) {
3777 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
3781 LEAVE("qla1280_error_entry");
3786 * Resets ISP and aborts all outstanding commands.
3789 * ha = adapter block pointer.
3795 qla1280_abort_isp(struct scsi_qla_host *ha)
3797 struct device_reg __iomem *reg = ha->iobase;
3803 ENTER("qla1280_abort_isp");
3805 if (ha->flags.abort_isp_active || !ha->flags.online)
3808 ha->flags.abort_isp_active = 1;
3810 /* Disable ISP interrupts. */
3811 qla1280_disable_intrs(ha);
3812 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
3813 RD_REG_WORD(®->id_l);
3815 printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
3817 /* Dequeue all commands in outstanding command list. */
3818 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3819 struct scsi_cmnd *cmd;
3820 sp = ha->outstanding_cmds[cnt];
3823 CMD_RESULT(cmd) = DID_RESET << 16;
3824 CMD_HANDLE(cmd) = COMPLETED_HANDLE;
3825 ha->outstanding_cmds[cnt] = NULL;
3826 list_add_tail(&sp->list, &ha->done_q);
3832 status = qla1280_load_firmware(ha);
3836 /* Setup adapter based on NVRAM parameters. */
3837 qla1280_nvram_config (ha);
3839 status = qla1280_init_rings(ha);
3843 /* Issue SCSI reset. */
3844 for (bus = 0; bus < ha->ports; bus++)
3845 qla1280_bus_reset(ha, bus);
3847 ha->flags.abort_isp_active = 0;
3851 "qla1280: ISP error recovery failed, board disabled");
3852 qla1280_reset_adapter(ha);
3853 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
3856 LEAVE("qla1280_abort_isp");
3862 * qla1280_debounce_register
3863 * Debounce register.
3866 * port = register address.
3872 qla1280_debounce_register(volatile u16 __iomem * addr)
3877 ret = RD_REG_WORD(addr);
3878 ret2 = RD_REG_WORD(addr);
3885 ret = RD_REG_WORD(addr);
3886 ret2 = RD_REG_WORD(addr);
3887 } while (ret != ret2);
3893 /************************************************************************
3894 * qla1280_check_for_dead_scsi_bus *
3896 * This routine checks for a dead SCSI bus *
3897 ************************************************************************/
3898 #define SET_SXP_BANK 0x0100
3899 #define SCSI_PHASE_INVALID 0x87FF
3901 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
3903 uint16_t config_reg, scsi_control;
3904 struct device_reg __iomem *reg = ha->iobase;
3906 if (ha->bus_settings[bus].scsi_bus_dead) {
3907 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
3908 config_reg = RD_REG_WORD(®->cfg_1);
3909 WRT_REG_WORD(®->cfg_1, SET_SXP_BANK);
3910 scsi_control = RD_REG_WORD(®->scsiControlPins);
3911 WRT_REG_WORD(®->cfg_1, config_reg);
3912 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
3914 if (scsi_control == SCSI_PHASE_INVALID) {
3915 ha->bus_settings[bus].scsi_bus_dead = 1;
3916 return 1; /* bus is dead */
3918 ha->bus_settings[bus].scsi_bus_dead = 0;
3919 ha->bus_settings[bus].failed_reset_count = 0;
3922 return 0; /* bus is not dead */
3926 qla1280_get_target_parameters(struct scsi_qla_host *ha,
3927 struct scsi_device *device)
3929 uint16_t mb[MAILBOX_REGISTER_COUNT];
3930 int bus, target, lun;
3932 bus = device->channel;
3933 target = device->id;
3937 mb[0] = MBC_GET_TARGET_PARAMETERS;
3938 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
3940 qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
3943 printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
3946 printk(" Sync: period %d, offset %d",
3947 (mb[3] & 0xff), (mb[3] >> 8));
3950 if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
3955 if (device->simple_tags)
3956 printk(", Tagged queuing: depth %d", device->queue_depth);
3963 __qla1280_dump_buffer(char *b, int size)
3968 printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
3969 "Bh Ch Dh Eh Fh\n");
3970 printk(KERN_DEBUG "---------------------------------------------"
3971 "------------------\n");
3973 for (cnt = 0; cnt < size;) {
3976 printk("0x%02x", c);
3987 /**************************************************************************
3988 * ql1280_print_scsi_cmd
3990 **************************************************************************/
3992 __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
3994 struct scsi_qla_host *ha;
3995 struct Scsi_Host *host = CMD_HOST(cmd);
3997 /* struct scatterlist *sg; */
4000 ha = (struct scsi_qla_host *)host->hostdata;
4002 sp = (struct srb *)CMD_SP(cmd);
4003 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
4004 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
4005 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
4008 for (i = 0; i < cmd->cmd_len; i++) {
4009 printk("0x%02x ", cmd->cmnd[i]);
4011 printk(" seg_cnt =%d\n", scsi_sg_count(cmd));
4012 printk(" request buffer=0x%p, request buffer len=0x%x\n",
4013 scsi_sglist(cmd), scsi_bufflen(cmd));
4016 sg = (struct scatterlist *) cmd->request_buffer;
4017 printk(" SG buffer: \n");
4018 qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
4020 printk(" tag=%d, transfersize=0x%x \n",
4021 cmd->tag, cmd->transfersize);
4022 printk(" SP=0x%p\n", CMD_SP(cmd));
4023 printk(" underflow size = 0x%x, direction=0x%x\n",
4024 cmd->underflow, cmd->sc_data_direction);
4027 /**************************************************************************
4028 * ql1280_dump_device
4030 **************************************************************************/
4032 ql1280_dump_device(struct scsi_qla_host *ha)
4035 struct scsi_cmnd *cp;
4039 printk(KERN_DEBUG "Outstanding Commands on controller:\n");
4041 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
4042 if ((sp = ha->outstanding_cmds[i]) == NULL)
4044 if ((cp = sp->cmd) == NULL)
4046 qla1280_print_scsi_cmd(1, cp);
4061 struct setup_tokens {
4066 static struct setup_tokens setup_token[] __initdata =
4068 { "nvram", TOKEN_NVRAM },
4069 { "sync", TOKEN_SYNC },
4070 { "wide", TOKEN_WIDE },
4071 { "ppr", TOKEN_PPR },
4072 { "verbose", TOKEN_VERBOSE },
4073 { "debug", TOKEN_DEBUG },
4077 /**************************************************************************
4080 * Handle boot parameters. This really needs to be changed so one
4081 * can specify per adapter parameters.
4082 **************************************************************************/
4084 qla1280_setup(char *s)
4092 while (cp && (ptr = strchr(cp, ':'))) {
4094 if (!strcmp(ptr, "yes")) {
4097 } else if (!strcmp(ptr, "no")) {
4101 val = simple_strtoul(ptr, &ptr, 0);
4103 switch ((toke = qla1280_get_token(cp))) {
4106 driver_setup.no_nvram = 1;
4110 driver_setup.no_sync = 1;
4111 else if (val != 0x10000)
4112 driver_setup.sync_mask = val;
4116 driver_setup.no_wide = 1;
4117 else if (val != 0x10000)
4118 driver_setup.wide_mask = val;
4122 driver_setup.no_ppr = 1;
4123 else if (val != 0x10000)
4124 driver_setup.ppr_mask = val;
4127 qla1280_verbose = val;
4130 printk(KERN_INFO "qla1280: unknown boot option %s\n",
4134 cp = strchr(ptr, ';');
4146 qla1280_get_token(char *str)
4152 sep = strchr(str, ':');
4155 for (i = 0; i < ARRAY_SIZE(setup_token); i++) {
4156 if (!strncmp(setup_token[i].token, str, (sep - str))) {
4157 ret = setup_token[i].val;
4167 static struct scsi_host_template qla1280_driver_template = {
4168 .module = THIS_MODULE,
4169 .proc_name = "qla1280",
4170 .name = "Qlogic ISP 1280/12160",
4171 .info = qla1280_info,
4172 .slave_configure = qla1280_slave_configure,
4173 .queuecommand = qla1280_queuecommand,
4174 .eh_abort_handler = qla1280_eh_abort,
4175 .eh_device_reset_handler= qla1280_eh_device_reset,
4176 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4177 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4178 .bios_param = qla1280_biosparam,
4179 .can_queue = MAX_OUTSTANDING_COMMANDS,
4181 .sg_tablesize = SG_ALL,
4186 qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4188 int devnum = id->driver_data;
4189 struct qla_boards *bdp = &ql1280_board_tbl[devnum];
4190 struct Scsi_Host *host;
4191 struct scsi_qla_host *ha;
4192 int error = -ENODEV;
4194 /* Bypass all AMI SUBSYS VENDOR IDs */
4195 if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
4197 "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
4201 printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
4202 bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
4204 if (pci_enable_device(pdev)) {
4206 "qla1280: Failed to enabled pci device, aborting.\n");
4210 pci_set_master(pdev);
4213 host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
4216 "qla1280: Failed to register host, aborting.\n");
4217 goto error_disable_device;
4220 ha = (struct scsi_qla_host *)host->hostdata;
4221 memset(ha, 0, sizeof(struct scsi_qla_host));
4224 ha->devnum = devnum; /* specifies microcode load address */
4226 #ifdef QLA_64BIT_PTR
4227 if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) {
4228 if (dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32))) {
4229 printk(KERN_WARNING "scsi(%li): Unable to set a "
4230 "suitable DMA mask - aborting\n", ha->host_no);
4232 goto error_put_host;
4235 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4238 if (dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32))) {
4239 printk(KERN_WARNING "scsi(%li): Unable to set a "
4240 "suitable DMA mask - aborting\n", ha->host_no);
4242 goto error_put_host;
4246 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
4247 ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
4248 &ha->request_dma, GFP_KERNEL);
4249 if (!ha->request_ring) {
4250 printk(KERN_INFO "qla1280: Failed to get request memory\n");
4251 goto error_put_host;
4254 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
4255 ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
4256 &ha->response_dma, GFP_KERNEL);
4257 if (!ha->response_ring) {
4258 printk(KERN_INFO "qla1280: Failed to get response memory\n");
4259 goto error_free_request_ring;
4262 ha->ports = bdp->numPorts;
4265 ha->host_no = host->host_no;
4267 host->irq = pdev->irq;
4268 host->max_channel = bdp->numPorts - 1;
4269 host->max_lun = MAX_LUNS - 1;
4270 host->max_id = MAX_TARGETS;
4271 host->max_sectors = 1024;
4272 host->unique_id = host->host_no;
4276 #if MEMORY_MAPPED_IO
4277 ha->mmpbase = pci_ioremap_bar(ha->pdev, 1);
4279 printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
4280 goto error_free_response_ring;
4283 host->base = (unsigned long)ha->mmpbase;
4284 ha->iobase = (struct device_reg __iomem *)ha->mmpbase;
4286 host->io_port = pci_resource_start(ha->pdev, 0);
4287 if (!request_region(host->io_port, 0xff, "qla1280")) {
4288 printk(KERN_INFO "qla1280: Failed to reserve i/o region "
4289 "0x%04lx-0x%04lx - already in use\n",
4290 host->io_port, host->io_port + 0xff);
4291 goto error_free_response_ring;
4294 ha->iobase = (struct device_reg *)host->io_port;
4297 INIT_LIST_HEAD(&ha->done_q);
4299 /* Disable ISP interrupts. */
4300 qla1280_disable_intrs(ha);
4302 if (request_irq(pdev->irq, qla1280_intr_handler, IRQF_SHARED,
4304 printk("qla1280 : Failed to reserve interrupt %d already "
4305 "in use\n", pdev->irq);
4306 goto error_release_region;
4309 /* load the F/W, read paramaters, and init the H/W */
4310 if (qla1280_initialize_adapter(ha)) {
4311 printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
4312 goto error_free_irq;
4315 /* set our host ID (need to do something about our two IDs) */
4316 host->this_id = ha->bus_settings[0].id;
4318 pci_set_drvdata(pdev, host);
4320 error = scsi_add_host(host, &pdev->dev);
4322 goto error_disable_adapter;
4323 scsi_scan_host(host);
4327 error_disable_adapter:
4328 qla1280_disable_intrs(ha);
4330 free_irq(pdev->irq, ha);
4331 error_release_region:
4332 #if MEMORY_MAPPED_IO
4333 iounmap(ha->mmpbase);
4335 release_region(host->io_port, 0xff);
4337 error_free_response_ring:
4338 dma_free_coherent(&ha->pdev->dev,
4339 ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
4340 ha->response_ring, ha->response_dma);
4341 error_free_request_ring:
4342 dma_free_coherent(&ha->pdev->dev,
4343 ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
4344 ha->request_ring, ha->request_dma);
4346 scsi_host_put(host);
4347 error_disable_device:
4348 pci_disable_device(pdev);
4355 qla1280_remove_one(struct pci_dev *pdev)
4357 struct Scsi_Host *host = pci_get_drvdata(pdev);
4358 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
4360 scsi_remove_host(host);
4362 qla1280_disable_intrs(ha);
4364 free_irq(pdev->irq, ha);
4366 #if MEMORY_MAPPED_IO
4367 iounmap(ha->mmpbase);
4369 release_region(host->io_port, 0xff);
4372 dma_free_coherent(&ha->pdev->dev,
4373 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4374 ha->request_ring, ha->request_dma);
4375 dma_free_coherent(&ha->pdev->dev,
4376 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4377 ha->response_ring, ha->response_dma);
4379 pci_disable_device(pdev);
4381 scsi_host_put(host);
4384 static struct pci_driver qla1280_pci_driver = {
4386 .id_table = qla1280_pci_tbl,
4387 .probe = qla1280_probe_one,
4388 .remove = qla1280_remove_one,
4394 if (sizeof(struct srb) > sizeof(struct scsi_pointer)) {
4396 "qla1280: struct srb too big, aborting\n");
4402 * If we are called as a module, the qla1280 pointer may not be null
4403 * and it would point to our bootup string, just like on the lilo
4404 * command line. IF not NULL, then process this config string with
4408 * To add options at boot time add a line to your lilo.conf file like:
4409 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
4410 * which will result in the first four devices on the first two
4411 * controllers being set to a tagged queue depth of 32.
4414 qla1280_setup(qla1280);
4417 return pci_register_driver(&qla1280_pci_driver);
4425 pci_unregister_driver(&qla1280_pci_driver);
4426 /* release any allocated firmware images */
4427 for (i = 0; i < QL_NUM_FW_IMAGES; i++) {
4428 release_firmware(qla1280_fw_tbl[i].fw);
4429 qla1280_fw_tbl[i].fw = NULL;
4433 module_init(qla1280_init);
4434 module_exit(qla1280_exit);
4436 MODULE_AUTHOR("Qlogic & Jes Sorensen");
4437 MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
4438 MODULE_LICENSE("GPL");
4439 MODULE_FIRMWARE("qlogic/1040.bin");
4440 MODULE_FIRMWARE("qlogic/1280.bin");
4441 MODULE_FIRMWARE("qlogic/12160.bin");
4442 MODULE_VERSION(QLA1280_VERSION);
4445 * Overrides for Emacs so that we almost follow Linus's tabbing style.
4446 * Emacs will notice this stuff at the end of the file and automatically
4447 * adjust the settings for this buffer only. This must remain at the end
4449 * ---------------------------------------------------------------------------