1 /******************************************************************************
2 * QLOGIC LINUX SOFTWARE
4 * QLogic QLA1280 (Ultra2) and QLA12160 (Ultra3) SCSI driver
5 * Copyright (C) 2000 Qlogic Corporation (www.qlogic.com)
6 * Copyright (C) 2001-2004 Jes Sorensen, Wild Open Source Inc.
7 * Copyright (C) 2003-2004 Christoph Hellwig
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 ******************************************************************************/
20 #define QLA1280_VERSION "3.25"
21 /*****************************************************************************
23 Rev 3.25.1, February 10, 2005 Christoph Hellwig
24 - use pci_map_single to map non-S/G requests
25 - remove qla1280_proc_info
26 Rev 3.25, September 28, 2004, Christoph Hellwig
27 - add support for ISP1020/1040
28 - don't include "scsi.h" anymore for 2.6.x
29 Rev 3.24.4 June 7, 2004 Christoph Hellwig
30 - restructure firmware loading, cleanup initialization code
31 - prepare support for ISP1020/1040 chips
32 Rev 3.24.3 January 19, 2004, Jes Sorensen
33 - Handle PCI DMA mask settings correctly
34 - Correct order of error handling in probe_one, free_irq should not
35 be called if request_irq failed
36 Rev 3.24.2 January 19, 2004, James Bottomley & Andrew Vasquez
37 - Big endian fixes (James)
38 - Remove bogus IOCB content on zero data transfer commands (Andrew)
39 Rev 3.24.1 January 5, 2004, Jes Sorensen
40 - Initialize completion queue to avoid OOPS on probe
41 - Handle interrupts during mailbox testing
42 Rev 3.24 November 17, 2003, Christoph Hellwig
43 - use struct list_head for completion queue
44 - avoid old Scsi_FOO typedefs
45 - cleanup 2.4 compat glue a bit
46 - use <scsi/scsi_*.h> headers on 2.6 instead of "scsi.h"
47 - make initialization for memory mapped vs port I/O more similar
48 - remove broken pci config space manipulation
50 - this is an almost perfect 2.6 scsi driver now! ;)
51 Rev 3.23.39 December 17, 2003, Jes Sorensen
52 - Delete completion queue from srb if mailbox command failed to
53 to avoid qla1280_done completeting qla1280_error_action's
55 - Reduce arguments for qla1280_done
56 Rev 3.23.38 October 18, 2003, Christoph Hellwig
57 - Convert to new-style hotplugable driver for 2.6
58 - Fix missing scsi_unregister/scsi_host_put on HBA removal
59 - Kill some more cruft
60 Rev 3.23.37 October 1, 2003, Jes Sorensen
61 - Make MMIO depend on CONFIG_X86_VISWS instead of yet another
63 - Clean up locking in probe path
64 Rev 3.23.36 October 1, 2003, Christoph Hellwig
65 - queuecommand only ever receives new commands - clear flags
66 - Reintegrate lost fixes from Linux 2.5
67 Rev 3.23.35 August 14, 2003, Jes Sorensen
69 Rev 3.23.34 July 23, 2003, Jes Sorensen
70 - Remove pointless TRUE/FALSE macros
71 - Clean up vchan handling
72 Rev 3.23.33 July 3, 2003, Jes Sorensen
73 - Don't define register access macros before define determining MMIO.
74 This just happend to work out on ia64 but not elsewhere.
75 - Don't try and read from the card while it is in reset as
76 it won't respond and causes an MCA
77 Rev 3.23.32 June 23, 2003, Jes Sorensen
78 - Basic support for boot time arguments
79 Rev 3.23.31 June 8, 2003, Jes Sorensen
80 - Reduce boot time messages
81 Rev 3.23.30 June 6, 2003, Jes Sorensen
82 - Do not enable sync/wide/ppr before it has been determined
83 that the target device actually supports it
84 - Enable DMA arbitration for multi channel controllers
85 Rev 3.23.29 June 3, 2003, Jes Sorensen
87 Rev 3.23.28 June 3, 2003, Jes Sorensen
88 - Eliminate duplicate marker commands on bus resets
89 - Handle outstanding commands appropriately on bus/device resets
90 Rev 3.23.27 May 28, 2003, Jes Sorensen
91 - Remove bogus input queue code, let the Linux SCSI layer do the work
92 - Clean up NVRAM handling, only read it once from the card
93 - Add a number of missing default nvram parameters
94 Rev 3.23.26 Beta May 28, 2003, Jes Sorensen
95 - Use completion queue for mailbox commands instead of busy wait
96 Rev 3.23.25 Beta May 27, 2003, James Bottomley
97 - Migrate to use new error handling code
98 Rev 3.23.24 Beta May 21, 2003, James Bottomley
100 - Cleanup data direction code
101 Rev 3.23.23 Beta May 12, 2003, Jes Sorensen
102 - Switch to using MMIO instead of PIO
103 Rev 3.23.22 Beta April 15, 2003, Jes Sorensen
104 - Fix PCI parity problem with 12160 during reset.
105 Rev 3.23.21 Beta April 14, 2003, Jes Sorensen
106 - Use pci_map_page()/pci_unmap_page() instead of map_single version.
107 Rev 3.23.20 Beta April 9, 2003, Jes Sorensen
108 - Remove < 2.4.x support
109 - Introduce HOST_LOCK to make the spin lock changes portable.
110 - Remove a bunch of idiotic and unnecessary typedef's
111 - Kill all leftovers of target-mode support which never worked anyway
112 Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
113 - Do qla1280_pci_config() before calling request_irq() and
115 - Use pci_dma_hi32() to handle upper word of DMA addresses instead
117 - Hand correct arguments to free_irq() in case of failure
118 Rev 3.23.18 Beta April 11, 2002, Jes Sorensen
119 - Run source through Lindent and clean up the output
120 Rev 3.23.17 Beta April 11, 2002, Jes Sorensen
121 - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32
122 Rev 3.23.16 Beta March 19, 2002, Jes Sorensen
123 - Rely on mailbox commands generating interrupts - do not
124 run qla1280_isr() from ql1280_mailbox_command()
125 - Remove device_reg_t
126 - Integrate ql12160_set_target_parameters() with 1280 version
127 - Make qla1280_setup() non static
128 - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request
129 sent to the card - this command pauses the firmare!!!
130 Rev 3.23.15 Beta March 19, 2002, Jes Sorensen
131 - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions
132 - Remove a pile of pointless and confusing (srb_t **) and
133 (scsi_lu_t *) typecasts
134 - Explicit mark that we do not use the new error handling (for now)
135 - Remove scsi_qla_host_t and use 'struct' instead
136 - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled,
137 pci_64bit_slot flags which weren't used for anything anyway
138 - Grab host->host_lock while calling qla1280_isr() from abort()
139 - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we
140 do not need to save/restore flags in the interrupt handler
141 - Enable interrupts early (before any mailbox access) in preparation
142 for cleaning up the mailbox handling
143 Rev 3.23.14 Beta March 14, 2002, Jes Sorensen
144 - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace
145 it with proper use of dprintk().
146 - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take
147 a debug level argument to determine if data is to be printed
148 - Add KERN_* info to printk()
149 Rev 3.23.13 Beta March 14, 2002, Jes Sorensen
150 - Significant cosmetic cleanups
151 - Change debug code to use dprintk() and remove #if mess
152 Rev 3.23.12 Beta March 13, 2002, Jes Sorensen
153 - More cosmetic cleanups, fix places treating return as function
154 - use cpu_relax() in qla1280_debounce_register()
155 Rev 3.23.11 Beta March 13, 2002, Jes Sorensen
156 - Make it compile under 2.5.5
157 Rev 3.23.10 Beta October 1, 2001, Jes Sorensen
158 - Do no typecast short * to long * in QL1280BoardTbl, this
159 broke miserably on big endian boxes
160 Rev 3.23.9 Beta September 30, 2001, Jes Sorensen
161 - Remove pre 2.2 hack for checking for reentrance in interrupt handler
162 - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32
163 unsigned int to match the types from struct scsi_cmnd
164 Rev 3.23.8 Beta September 29, 2001, Jes Sorensen
165 - Remove bogus timer_t typedef from qla1280.h
166 - Remove obsolete pre 2.2 PCI setup code, use proper #define's
167 for PCI_ values, call pci_set_master()
168 - Fix memleak of qla1280_buffer on module unload
169 - Only compile module parsing code #ifdef MODULE - should be
170 changed to use individual MODULE_PARM's later
171 - Remove dummy_buffer that was never modified nor printed
172 - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove
173 #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls
174 - Remove \r from print statements, this is Linux, not DOS
175 - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK}
177 - Remove C++ compile hack in header file as Linux driver are not
178 supposed to be compiled as C++
179 - Kill MS_64BITS macro as it makes the code more readable
180 - Remove unnecessary flags.in_interrupts bit
181 Rev 3.23.7 Beta August 20, 2001, Jes Sorensen
182 - Dont' check for set flags on q->q_flag one by one in qla1280_next()
183 - Check whether the interrupt was generated by the QLA1280 before
185 - qla1280_status_entry(): Only zero out part of sense_buffer that
186 is not being copied into
187 - Remove more superflouous typecasts
188 - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy()
189 Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel
190 - Don't walk the entire list in qla1280_putq_t() just to directly
191 grab the pointer to the last element afterwards
192 Rev 3.23.5 Beta August 9, 2001, Jes Sorensen
193 - Don't use SA_INTERRUPT, it's use is deprecated for this kinda driver
194 Rev 3.23.4 Beta August 8, 2001, Jes Sorensen
195 - Set dev->max_sectors to 1024
196 Rev 3.23.3 Beta August 6, 2001, Jes Sorensen
197 - Provide compat macros for pci_enable_device(), pci_find_subsys()
198 and scsi_set_pci_device()
199 - Call scsi_set_pci_device() for all devices
200 - Reduce size of kernel version dependent device probe code
201 - Move duplicate probe/init code to separate function
202 - Handle error if qla1280_mem_alloc() fails
203 - Kill OFFSET() macro and use Linux's PCI definitions instead
204 - Kill private structure defining PCI config space (struct config_reg)
205 - Only allocate I/O port region if not in MMIO mode
206 - Remove duplicate (unused) sanity check of sife of srb_t
207 Rev 3.23.2 Beta August 6, 2001, Jes Sorensen
208 - Change home-brew memset() implementations to use memset()
209 - Remove all references to COMTRACE() - accessing a PC's COM2 serial
210 port directly is not legal under Linux.
211 Rev 3.23.1 Beta April 24, 2001, Jes Sorensen
212 - Remove pre 2.2 kernel support
213 - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat)
214 - Fix MMIO access to use readl/writel instead of directly
215 dereferencing pointers
216 - Nuke MSDOS debugging code
217 - Change true/false data types to int from uint8_t
218 - Use int for counters instead of uint8_t etc.
219 - Clean up size & byte order conversion macro usage
220 Rev 3.23 Beta January 11, 2001 BN Qlogic
221 - Added check of device_id when handling non
222 QLA12160s during detect().
223 Rev 3.22 Beta January 5, 2001 BN Qlogic
224 - Changed queue_task() to schedule_task()
225 for kernels 2.4.0 and higher.
226 Note: 2.4.0-testxx kernels released prior to
227 the actual 2.4.0 kernel release on January 2001
228 will get compile/link errors with schedule_task().
229 Please update your kernel to released 2.4.0 level,
230 or comment lines in this file flagged with 3.22
231 to resolve compile/link error of schedule_task().
232 - Added -DCONFIG_SMP in addition to -D__SMP__
233 in Makefile for 2.4.0 builds of driver as module.
234 Rev 3.21 Beta January 4, 2001 BN Qlogic
235 - Changed criteria of 64/32 Bit mode of HBA
236 operation according to BITS_PER_LONG rather
237 than HBA's NVRAM setting of >4Gig memory bit;
238 so that the HBA auto-configures without the need
239 to setup each system individually.
240 Rev 3.20 Beta December 5, 2000 BN Qlogic
241 - Added priority handling to IA-64 onboard SCSI
242 ISP12160 chip for kernels greater than 2.3.18.
243 - Added irqrestore for qla1280_intr_handler.
244 - Enabled /proc/scsi/qla1280 interface.
245 - Clear /proc/scsi/qla1280 counters in detect().
246 Rev 3.19 Beta October 13, 2000 BN Qlogic
247 - Declare driver_template for new kernel
248 (2.4.0 and greater) scsi initialization scheme.
249 - Update /proc/scsi entry for 2.3.18 kernels and
251 Rev 3.18 Beta October 10, 2000 BN Qlogic
252 - Changed scan order of adapters to map
253 the QLA12160 followed by the QLA1280.
254 Rev 3.17 Beta September 18, 2000 BN Qlogic
255 - Removed warnings for 32 bit 2.4.x compiles
256 - Corrected declared size for request and response
257 DMA addresses that are kept in each ha
258 Rev. 3.16 Beta August 25, 2000 BN Qlogic
259 - Corrected 64 bit addressing issue on IA-64
260 where the upper 32 bits were not properly
261 passed to the RISC engine.
262 Rev. 3.15 Beta August 22, 2000 BN Qlogic
263 - Modified qla1280_setup_chip to properly load
264 ISP firmware for greater that 4 Gig memory on IA-64
265 Rev. 3.14 Beta August 16, 2000 BN Qlogic
266 - Added setting of dma_mask to full 64 bit
267 if flags.enable_64bit_addressing is set in NVRAM
268 Rev. 3.13 Beta August 16, 2000 BN Qlogic
269 - Use new PCI DMA mapping APIs for 2.4.x kernel
270 Rev. 3.12 July 18, 2000 Redhat & BN Qlogic
271 - Added check of pci_enable_device to detect() for 2.3.x
272 - Use pci_resource_start() instead of
273 pdev->resource[0].start in detect() for 2.3.x
274 - Updated driver version
275 Rev. 3.11 July 14, 2000 BN Qlogic
276 - Updated SCSI Firmware to following versions:
279 - Updated driver version to 3.11
280 Rev. 3.10 June 23, 2000 BN Qlogic
281 - Added filtering of AMI SubSys Vendor ID devices
283 - DEBUG_QLA1280 undefined and new version BN Qlogic
284 Rev. 3.08b May 9, 2000 MD Dell
285 - Added logic to check against AMI subsystem vendor ID
286 Rev. 3.08 May 4, 2000 DG Qlogic
287 - Added logic to check for PCI subsystem ID.
288 Rev. 3.07 Apr 24, 2000 DG & BN Qlogic
289 - Updated SCSI Firmware to following versions:
292 Rev. 3.06 Apr 12, 2000 DG & BN Qlogic
293 - Internal revision; not released
294 Rev. 3.05 Mar 28, 2000 DG & BN Qlogic
295 - Edit correction for virt_to_bus and PROC.
296 Rev. 3.04 Mar 28, 2000 DG & BN Qlogic
297 - Merge changes from ia64 port.
298 Rev. 3.03 Mar 28, 2000 BN Qlogic
299 - Increase version to reflect new code drop with compile fix
300 of issue with inclusion of linux/spinlock for 2.3 kernels
301 Rev. 3.02 Mar 15, 2000 BN Qlogic
302 - Merge qla1280_proc_info from 2.10 code base
303 Rev. 3.01 Feb 10, 2000 BN Qlogic
304 - Corrected code to compile on a 2.2.x kernel.
305 Rev. 3.00 Jan 17, 2000 DG Qlogic
306 - Added 64-bit support.
307 Rev. 2.07 Nov 9, 1999 DG Qlogic
308 - Added new routine to set target parameters for ISP12160.
309 Rev. 2.06 Sept 10, 1999 DG Qlogic
310 - Added support for ISP12160 Ultra 3 chip.
311 Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
312 - Modified code to remove errors generated when compiling with
313 Cygnus IA64 Compiler.
314 - Changed conversion of pointers to unsigned longs instead of integers.
315 - Changed type of I/O port variables from uint32_t to unsigned long.
316 - Modified OFFSET macro to work with 64-bit as well as 32-bit.
317 - Changed sprintf and printk format specifiers for pointers to %p.
318 - Changed some int to long type casts where needed in sprintf & printk.
319 - Added l modifiers to sprintf and printk format specifiers for longs.
320 - Removed unused local variables.
321 Rev. 1.20 June 8, 1999 DG, Qlogic
322 Changes to support RedHat release 6.0 (kernel 2.2.5).
323 - Added SCSI exclusive access lock (io_request_lock) when accessing
325 - Added changes for the new LINUX interface template. Some new error
326 handling routines have been added to the template, but for now we
327 will use the old ones.
328 - Initial Beta Release.
329 *****************************************************************************/
332 #include <linux/config.h>
333 #include <linux/module.h>
335 #include <linux/version.h>
336 #include <linux/types.h>
337 #include <linux/string.h>
338 #include <linux/errno.h>
339 #include <linux/kernel.h>
340 #include <linux/ioport.h>
341 #include <linux/delay.h>
342 #include <linux/timer.h>
343 #include <linux/sched.h>
344 #include <linux/pci.h>
345 #include <linux/proc_fs.h>
346 #include <linux/stat.h>
347 #include <linux/slab.h>
348 #include <linux/pci_ids.h>
349 #include <linux/interrupt.h>
350 #include <linux/init.h>
354 #include <asm/byteorder.h>
355 #include <asm/processor.h>
356 #include <asm/types.h>
357 #include <asm/system.h>
359 #if LINUX_VERSION_CODE >= 0x020545
360 #include <scsi/scsi.h>
361 #include <scsi/scsi_cmnd.h>
362 #include <scsi/scsi_device.h>
363 #include <scsi/scsi_host.h>
364 #include <scsi/scsi_tcq.h>
366 #include <linux/blk.h>
368 #include <scsi/scsi_host.h>
372 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
373 #include <asm/sn/io.h>
376 #if LINUX_VERSION_CODE < 0x020407
377 #error "Kernels older than 2.4.7 are no longer supported"
382 * Compile time Options:
383 * 0 - Disable and 1 - Enable
385 #define DEBUG_QLA1280_INTR 0
386 #define DEBUG_PRINT_NVRAM 0
387 #define DEBUG_QLA1280 0
390 * The SGI VISWS is broken and doesn't support MMIO ;-(
392 #ifdef CONFIG_X86_VISWS
393 #define MEMORY_MAPPED_IO 0
395 #define MEMORY_MAPPED_IO 1
398 #define UNIQUE_FW_NAME
400 #include "ql12160_fw.h" /* ISP RISC codes */
401 #include "ql1280_fw.h"
402 #include "ql1040_fw.h"
408 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1080
409 #define PCI_DEVICE_ID_QLOGIC_ISP1080 0x1080
411 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1240
412 #define PCI_DEVICE_ID_QLOGIC_ISP1240 0x1240
414 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1280
415 #define PCI_DEVICE_ID_QLOGIC_ISP1280 0x1280
417 #ifndef PCI_DEVICE_ID_QLOGIC_ISP10160
418 #define PCI_DEVICE_ID_QLOGIC_ISP10160 0x1016
420 #ifndef PCI_DEVICE_ID_QLOGIC_ISP12160
421 #define PCI_DEVICE_ID_QLOGIC_ISP12160 0x1216
424 #ifndef PCI_VENDOR_ID_AMI
425 #define PCI_VENDOR_ID_AMI 0x101e
428 #ifndef BITS_PER_LONG
429 #error "BITS_PER_LONG not defined!"
431 #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
432 #define QLA_64BIT_PTR 1
436 #define pci_dma_hi32(a) ((a >> 16) >> 16)
438 #define pci_dma_hi32(a) 0
440 #define pci_dma_lo32(a) (a & 0xffffffff)
442 #define NVRAM_DELAY() udelay(500) /* 2 microseconds */
444 #if LINUX_VERSION_CODE < 0x020500
445 #define HOST_LOCK &io_request_lock
446 #define irqreturn_t void
447 #define IRQ_RETVAL(foo)
448 #define MSG_ORDERED_TAG 1
450 #define DMA_BIDIRECTIONAL SCSI_DATA_UNKNOWN
451 #define DMA_TO_DEVICE SCSI_DATA_WRITE
452 #define DMA_FROM_DEVICE SCSI_DATA_READ
453 #define DMA_NONE SCSI_DATA_NONE
455 #ifndef HAVE_SECTOR_T
456 typedef unsigned int sector_t;
460 scsi_adjust_queue_depth(struct scsi_device *device, int tag, int depth)
463 device->tagged_queue = tag;
464 device->current_tag = 0;
466 device->queue_depth = depth;
468 static inline struct Scsi_Host *scsi_host_alloc(Scsi_Host_Template *t, size_t s)
470 return scsi_register(t, s);
472 static inline void scsi_host_put(struct Scsi_Host *h)
477 #define HOST_LOCK ha->host->host_lock
479 #if LINUX_VERSION_CODE < 0x020600
480 #define DEV_SIMPLE_TAGS(device) device->tagged_queue
482 * Hack around that qla1280_remove_one is called from
483 * qla1280_release in 2.4
488 #define DEV_SIMPLE_TAGS(device) device->simple_tags
490 #if defined(__ia64__) && !defined(ia64_platform_is)
491 #define ia64_platform_is(foo) (!strcmp(x, platform_name))
495 #define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
496 #define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
497 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
498 #define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
499 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
502 static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *);
503 static void qla1280_remove_one(struct pci_dev *);
506 * QLogic Driver Support Function Prototypes.
508 static void qla1280_done(struct scsi_qla_host *);
509 #if LINUX_VERSION_CODE < 0x020545
510 static void qla1280_get_target_options(struct scsi_cmnd *, struct scsi_qla_host *);
512 static int qla1280_get_token(char *);
513 static int qla1280_setup(char *s) __init;
516 * QLogic ISP1280 Hardware Support Function Prototypes.
518 static int qla1280_load_firmware(struct scsi_qla_host *);
519 static int qla1280_init_rings(struct scsi_qla_host *);
520 static int qla1280_nvram_config(struct scsi_qla_host *);
521 static int qla1280_mailbox_command(struct scsi_qla_host *,
522 uint8_t, uint16_t *);
523 static int qla1280_bus_reset(struct scsi_qla_host *, int);
524 static int qla1280_device_reset(struct scsi_qla_host *, int, int);
525 static int qla1280_abort_device(struct scsi_qla_host *, int, int, int);
526 static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int);
527 static int qla1280_abort_isp(struct scsi_qla_host *);
529 static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *);
531 static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *);
533 static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
534 static void qla1280_poll(struct scsi_qla_host *);
535 static void qla1280_reset_adapter(struct scsi_qla_host *);
536 static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
537 static void qla1280_isp_cmd(struct scsi_qla_host *);
538 static void qla1280_isr(struct scsi_qla_host *, struct list_head *);
539 static void qla1280_rst_aen(struct scsi_qla_host *);
540 static void qla1280_status_entry(struct scsi_qla_host *, struct response *,
542 static void qla1280_error_entry(struct scsi_qla_host *, struct response *,
544 static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
545 static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
546 static uint16_t qla1280_debounce_register(volatile uint16_t __iomem *);
547 static request_t *qla1280_req_pkt(struct scsi_qla_host *);
548 static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
550 static void qla1280_get_target_parameters(struct scsi_qla_host *,
551 struct scsi_device *);
552 static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int);
555 static struct qla_driver_setup driver_setup;
558 * convert scsi data direction to request_t control flags
560 static inline uint16_t
561 qla1280_data_direction(struct scsi_cmnd *cmnd)
563 switch(cmnd->sc_data_direction) {
564 case DMA_FROM_DEVICE:
568 case DMA_BIDIRECTIONAL:
569 return BIT_5 | BIT_6;
571 * We could BUG() on default here if one of the four cases aren't
572 * met, but then again if we receive something like that from the
573 * SCSI layer we have more serious problems. This shuts up GCC.
582 static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd);
583 static void __qla1280_dump_buffer(char *, int);
588 * insmod needs to find the variable and make it point to something
591 static char *qla1280;
593 /* insmod qla1280 options=verbose" */
594 module_param(qla1280, charp, 0);
596 __setup("qla1280=", qla1280_setup);
601 * We use the scsi_pointer structure that's included with each scsi_command
602 * to overlay our struct srb over it. qla1280_init() checks that a srb is not
603 * bigger than a scsi_pointer.
606 #define CMD_SP(Cmnd) &Cmnd->SCp
607 #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
608 #define CMD_CDBP(Cmnd) Cmnd->cmnd
609 #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
610 #define CMD_SNSLEN(Cmnd) sizeof(Cmnd->sense_buffer)
611 #define CMD_RESULT(Cmnd) Cmnd->result
612 #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
613 #if LINUX_VERSION_CODE < 0x020545
614 #define CMD_REQUEST(Cmnd) Cmnd->request.cmd
616 #define CMD_REQUEST(Cmnd) Cmnd->request->cmd
619 #define CMD_HOST(Cmnd) Cmnd->device->host
620 #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
621 #define SCSI_TCN_32(Cmnd) Cmnd->device->id
622 #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
625 /*****************************************/
626 /* ISP Boards supported by this driver */
627 /*****************************************/
630 unsigned char name[9]; /* Board ID String */
631 int numPorts; /* Number of SCSI ports */
632 unsigned short *fwcode; /* pointer to FW array */
633 unsigned short *fwlen; /* number of words in array */
634 unsigned short *fwstart; /* start address for F/W */
635 unsigned char *fwver; /* Ptr to F/W version array */
638 /* NOTE: the last argument in each entry is used to index ql1280_board_tbl */
639 static struct pci_device_id qla1280_pci_tbl[] = {
640 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP12160,
641 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
642 #ifdef CONFIG_SCSI_QLOGIC_1280_1040
643 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1020,
644 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
646 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1080,
647 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
648 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1240,
649 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
650 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1280,
651 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
652 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP10160,
653 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
656 MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl);
658 static struct qla_boards ql1280_board_tbl[] = {
659 /* Name , Number of ports, FW details */
660 {"QLA12160", 2, &fw12160i_code01[0], &fw12160i_length01,
661 &fw12160i_addr01, &fw12160i_version_str[0]},
662 {"QLA1040", 1, &risc_code01[0], &risc_code_length01,
663 &risc_code_addr01, &firmware_version[0]},
664 {"QLA1080", 1, &fw1280ei_code01[0], &fw1280ei_length01,
665 &fw1280ei_addr01, &fw1280ei_version_str[0]},
666 {"QLA1240", 2, &fw1280ei_code01[0], &fw1280ei_length01,
667 &fw1280ei_addr01, &fw1280ei_version_str[0]},
668 {"QLA1280", 2, &fw1280ei_code01[0], &fw1280ei_length01,
669 &fw1280ei_addr01, &fw1280ei_version_str[0]},
670 {"QLA10160", 1, &fw12160i_code01[0], &fw12160i_length01,
671 &fw12160i_addr01, &fw12160i_version_str[0]},
675 static int qla1280_verbose = 1;
678 static int ql_debug_level = 1;
679 #define dprintk(level, format, a...) \
680 do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
681 #define qla1280_dump_buffer(level, buf, size) \
682 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
683 #define qla1280_print_scsi_cmd(level, cmd) \
684 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
686 #define ql_debug_level 0
687 #define dprintk(level, format, a...) do{}while(0)
688 #define qla1280_dump_buffer(a, b, c) do{}while(0)
689 #define qla1280_print_scsi_cmd(a, b) do{}while(0)
692 #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
693 #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
694 #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
695 #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
698 static int qla1280_read_nvram(struct scsi_qla_host *ha)
705 ENTER("qla1280_read_nvram");
707 if (driver_setup.no_nvram)
710 printk(KERN_INFO "scsi(%ld): Reading NVRAM\n", ha->host_no);
712 wptr = (uint16_t *)&ha->nvram;
715 for (cnt = 0; cnt < 3; cnt++) {
716 *wptr = qla1280_get_nvram_word(ha, cnt);
717 chksum += *wptr & 0xff;
718 chksum += (*wptr >> 8) & 0xff;
722 if (nv->id0 != 'I' || nv->id1 != 'S' ||
723 nv->id2 != 'P' || nv->id3 != ' ' || nv->version < 1) {
724 dprintk(2, "Invalid nvram ID or version!\n");
727 for (; cnt < sizeof(struct nvram); cnt++) {
728 *wptr = qla1280_get_nvram_word(ha, cnt);
729 chksum += *wptr & 0xff;
730 chksum += (*wptr >> 8) & 0xff;
735 dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
736 " version %i\n", nv->id0, nv->id1, nv->id2, nv->id3,
741 if (!driver_setup.no_nvram)
742 printk(KERN_WARNING "scsi(%ld): Unable to identify or "
743 "validate NVRAM checksum, using default "
744 "settings\n", ha->host_no);
749 /* The firmware interface is, um, interesting, in that the
750 * actual firmware image on the chip is little endian, thus,
751 * the process of taking that image to the CPU would end up
752 * little endian. However, the firmare interface requires it
753 * to be read a word (two bytes) at a time.
755 * The net result of this would be that the word (and
756 * doubleword) quantites in the firmware would be correct, but
757 * the bytes would be pairwise reversed. Since most of the
758 * firmware quantites are, in fact, bytes, we do an extra
759 * le16_to_cpu() in the firmware read routine.
761 * The upshot of all this is that the bytes in the firmware
762 * are in the correct places, but the 16 and 32 bit quantites
763 * are still in little endian format. We fix that up below by
764 * doing extra reverses on them */
765 nv->isp_parameter = cpu_to_le16(nv->isp_parameter);
766 nv->firmware_feature.w = cpu_to_le16(nv->firmware_feature.w);
767 for(i = 0; i < MAX_BUSES; i++) {
768 nv->bus[i].selection_timeout = cpu_to_le16(nv->bus[i].selection_timeout);
769 nv->bus[i].max_queue_depth = cpu_to_le16(nv->bus[i].max_queue_depth);
771 dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
772 LEAVE("qla1280_read_nvram");
777 /**************************************************************************
779 * Return a string describing the driver.
780 **************************************************************************/
782 qla1280_info(struct Scsi_Host *host)
784 static char qla1280_scsi_name_buffer[125];
786 struct scsi_qla_host *ha;
787 struct qla_boards *bdp;
789 bp = &qla1280_scsi_name_buffer[0];
790 ha = (struct scsi_qla_host *)host->hostdata;
791 bdp = &ql1280_board_tbl[ha->devnum];
792 memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
795 "QLogic %s PCI to SCSI Host Adapter\n"
796 " Firmware version: %2d.%02d.%02d, Driver version %s",
797 &bdp->name[0], bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
802 /**************************************************************************
803 * qla1200_queuecommand
804 * Queue a command to the controller.
807 * The mid-level driver tries to ensures that queuecommand never gets invoked
808 * concurrently with itself or the interrupt handler (although the
809 * interrupt handler may call this routine as part of request-completion
810 * handling). Unfortunely, it sometimes calls the scheduler in interrupt
811 * context which is a big NO! NO!.
812 **************************************************************************/
814 qla1280_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
816 struct Scsi_Host *host = cmd->device->host;
817 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
818 struct srb *sp = (struct srb *)&cmd->SCp;
825 qla1280_print_scsi_cmd(5, cmd);
829 * Using 64 bit commands if the PCI bridge doesn't support it is a
830 * bit wasteful, however this should really only happen if one's
831 * PCI controller is completely broken, like the BCM1250. For
832 * sane hardware this is not an issue.
834 status = qla1280_64bit_start_scsi(ha, sp);
836 status = qla1280_32bit_start_scsi(ha, sp);
850 /* timer action for error action processor */
851 static void qla1280_error_wait_timeout(unsigned long __data)
853 struct scsi_cmnd *cmd = (struct scsi_cmnd *)__data;
854 struct srb *sp = (struct srb *)CMD_SP(cmd);
859 static void qla1280_mailbox_timeout(unsigned long __data)
861 struct scsi_qla_host *ha = (struct scsi_qla_host *)__data;
862 struct device_reg __iomem *reg;
865 ha->mailbox_out[0] = RD_REG_WORD(®->mailbox0);
866 printk(KERN_ERR "scsi(%ld): mailbox timed out, mailbox0 %04x, "
867 "ictrl %04x, istatus %04x\n", ha->host_no, ha->mailbox_out[0],
868 RD_REG_WORD(®->ictrl), RD_REG_WORD(®->istatus));
869 complete(ha->mailbox_wait);
872 /**************************************************************************
873 * qla1200_error_action
874 * The function will attempt to perform a specified error action and
875 * wait for the results (or time out).
878 * cmd = Linux SCSI command packet of the command that cause the
880 * action = error action to take (see action_t)
886 * Resetting the bus always succeeds - is has to, otherwise the
887 * kernel will panic! Try a surgical technique - sending a BUS
888 * DEVICE RESET message - on the offending target before pulling
889 * the SCSI bus reset line.
890 **************************************************************************/
892 qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
894 struct scsi_qla_host *ha;
895 int bus, target, lun;
898 unsigned char *handle;
900 DECLARE_COMPLETION(wait);
901 struct timer_list timer;
903 ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
905 dprintk(4, "error_action %i, istatus 0x%04x\n", action,
906 RD_REG_WORD(&ha->iobase->istatus));
908 dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
909 RD_REG_WORD(&ha->iobase->host_cmd),
910 RD_REG_WORD(&ha->iobase->ictrl), jiffies);
912 ENTER("qla1280_error_action");
914 printk(KERN_INFO "scsi(%li): Resetting Cmnd=0x%p, "
915 "Handle=0x%p, action=0x%x\n",
916 ha->host_no, cmd, CMD_HANDLE(cmd), action);
919 printk(KERN_WARNING "(scsi?:?:?:?) Reset called with NULL "
920 "si_Cmnd pointer, failing.\n");
921 LEAVE("qla1280_error_action");
925 ha = (struct scsi_qla_host *)cmd->device->host->hostdata;
926 sp = (struct srb *)CMD_SP(cmd);
927 handle = CMD_HANDLE(cmd);
929 /* Check for pending interrupts. */
930 data = qla1280_debounce_register(&ha->iobase->istatus);
932 * The io_request_lock is held when the reset handler is called, hence
933 * the interrupt handler cannot be running in parallel as it also
934 * grabs the lock. /Jes
937 qla1280_isr(ha, &ha->done_q);
940 * Determine the suggested action that the mid-level driver wants
943 if (handle == (unsigned char *)INVALID_HANDLE || handle == NULL) {
944 if(action == ABORT_COMMAND) {
945 /* we never got this command */
946 printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
947 return SUCCESS; /* no action - we don't have command */
953 bus = SCSI_BUS_32(cmd);
954 target = SCSI_TCN_32(cmd);
955 lun = SCSI_LUN_32(cmd);
957 /* Overloading result. Here it means the success or fail of the
958 * *issue* of the action. When we return from the routine, it must
959 * mean the actual success or fail of the action */
966 if ((sp->flags & SRB_ABORT_PENDING)) {
968 "scsi(): Command has a pending abort "
969 "message - ABORT_PENDING.\n");
970 /* This should technically be impossible since we
971 * now wait for abort completion */
975 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
976 if (sp == ha->outstanding_cmds[i]) {
977 dprintk(1, "qla1280: RISC aborting command\n");
978 if (qla1280_abort_command(ha, sp, i) == 0)
982 * Since we don't know what might
983 * have happend to the command, it
984 * is unsafe to remove it from the
985 * device's queue at this point.
986 * Wait and let the escalation
987 * process take care of it.
990 "scsi(%li:%i:%i:%i): Unable"
991 " to abort command!\n",
992 ha->host_no, bus, target, lun);
1001 "scsi(%ld:%d:%d:%d): Queueing abort device "
1002 "command.\n", ha->host_no, bus, target, lun);
1003 if (qla1280_abort_device(ha, bus, target, lun) == 0)
1008 if (qla1280_verbose)
1010 "scsi(%ld:%d:%d:%d): Queueing device reset "
1011 "command.\n", ha->host_no, bus, target, lun);
1012 if (qla1280_device_reset(ha, bus, target) == 0)
1017 if (qla1280_verbose)
1018 printk(KERN_INFO "qla1280(%ld:%d): Issuing BUS "
1019 "DEVICE RESET\n", ha->host_no, bus);
1020 if (qla1280_bus_reset(ha, bus == 0))
1027 if (qla1280_verbose) {
1029 "scsi(%ld): Issued ADAPTER RESET\n",
1031 printk(KERN_INFO "scsi(%ld): I/O processing will "
1032 "continue automatically\n", ha->host_no);
1034 ha->flags.reset_active = 1;
1036 * We restarted all of the commands automatically, so the
1037 * mid-level code can expect completions momentitarily.
1039 if (qla1280_abort_isp(ha) == 0)
1042 ha->flags.reset_active = 0;
1045 if (!list_empty(&ha->done_q))
1048 /* If we didn't manage to issue the action, or we have no
1049 * command to wait for, exit here */
1050 if (result == FAILED || handle == NULL ||
1051 handle == (unsigned char *)INVALID_HANDLE) {
1053 * Clear completion queue to avoid qla1280_done() trying
1054 * to complete the command at a later stage after we
1055 * have exited the current context
1061 /* set up a timer just in case we're really jammed */
1063 timer.expires = jiffies + 4*HZ;
1064 timer.data = (unsigned long)cmd;
1065 timer.function = qla1280_error_wait_timeout;
1068 /* wait for the action to complete (or the timer to expire) */
1069 spin_unlock_irq(HOST_LOCK);
1070 wait_for_completion(&wait);
1071 del_timer_sync(&timer);
1072 spin_lock_irq(HOST_LOCK);
1075 /* the only action we might get a fail for is abort */
1076 if (action == ABORT_COMMAND) {
1077 if(sp->flags & SRB_ABORTED)
1084 dprintk(1, "RESET returning %d\n", result);
1086 LEAVE("qla1280_error_action");
1090 /**************************************************************************
1092 * Abort the specified SCSI command(s).
1093 **************************************************************************/
1095 qla1280_eh_abort(struct scsi_cmnd * cmd)
1099 spin_lock_irq(cmd->device->host->host_lock);
1100 rc = qla1280_error_action(cmd, ABORT_COMMAND);
1101 spin_unlock_irq(cmd->device->host->host_lock);
1106 /**************************************************************************
1107 * qla1280_device_reset
1108 * Reset the specified SCSI device
1109 **************************************************************************/
1111 qla1280_eh_device_reset(struct scsi_cmnd *cmd)
1115 spin_lock_irq(cmd->device->host->host_lock);
1116 rc = qla1280_error_action(cmd, DEVICE_RESET);
1117 spin_unlock_irq(cmd->device->host->host_lock);
1122 /**************************************************************************
1124 * Reset the specified bus.
1125 **************************************************************************/
1127 qla1280_eh_bus_reset(struct scsi_cmnd *cmd)
1131 spin_lock_irq(cmd->device->host->host_lock);
1132 rc = qla1280_error_action(cmd, BUS_RESET);
1133 spin_unlock_irq(cmd->device->host->host_lock);
1138 /**************************************************************************
1139 * qla1280_adapter_reset
1140 * Reset the specified adapter (both channels)
1141 **************************************************************************/
1143 qla1280_eh_adapter_reset(struct scsi_cmnd *cmd)
1147 spin_lock_irq(cmd->device->host->host_lock);
1148 rc = qla1280_error_action(cmd, ADAPTER_RESET);
1149 spin_unlock_irq(cmd->device->host->host_lock);
1155 qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1156 sector_t capacity, int geom[])
1158 int heads, sectors, cylinders;
1162 cylinders = (unsigned long)capacity / (heads * sectors);
1163 if (cylinders > 1024) {
1166 cylinders = (unsigned long)capacity / (heads * sectors);
1167 /* if (cylinders > 1023)
1168 cylinders = 1023; */
1173 geom[2] = cylinders;
1178 #if LINUX_VERSION_CODE < 0x020600
1180 qla1280_detect(Scsi_Host_Template *template)
1182 struct pci_device_id *id = &qla1280_pci_tbl[0];
1183 struct pci_dev *pdev = NULL;
1186 if (sizeof(struct srb) > sizeof(Scsi_Pointer)) {
1188 "qla1280: struct srb too big, aborting\n");
1192 if ((DMA_BIDIRECTIONAL != PCI_DMA_BIDIRECTIONAL) ||
1193 (DMA_TO_DEVICE != PCI_DMA_TODEVICE) ||
1194 (DMA_FROM_DEVICE != PCI_DMA_FROMDEVICE) ||
1195 (DMA_NONE != PCI_DMA_NONE)) {
1197 "qla1280: dma direction bits don't match\n");
1203 * If we are called as a module, the qla1280 pointer may not be null
1204 * and it would point to our bootup string, just like on the lilo
1205 * command line. IF not NULL, then process this config string with
1209 * To add options at boot time add a line to your lilo.conf file like:
1210 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
1211 * which will result in the first four devices on the first two
1212 * controllers being set to a tagged queue depth of 32.
1215 qla1280_setup(qla1280);
1218 /* First Initialize QLA12160 on PCI Bus 1 Dev 2 */
1219 while ((pdev = pci_find_device(id->vendor, id->device, pdev))) {
1220 if (pdev->bus->number == 1 && PCI_SLOT(pdev->devfn) == 2) {
1221 if (!qla1280_probe_one(pdev, id))
1227 /* Try and find each different type of adapter we support */
1228 for (id = &qla1280_pci_tbl[0]; id->device; id++) {
1229 while ((pdev = pci_find_device(id->vendor, id->device, pdev))) {
1231 * skip QLA12160 already initialized on
1232 * PCI Bus 1 Dev 2 since we already initialized
1235 if (id->device == PCI_DEVICE_ID_QLOGIC_ISP12160 &&
1236 pdev->bus->number == 1 &&
1237 PCI_SLOT(pdev->devfn) == 2)
1240 if (!qla1280_probe_one(pdev, id))
1249 * This looks a bit ugly as we could just pass down host to
1250 * qla1280_remove_one, but I want to keep qla1280_release purely a wrapper
1251 * around pci_driver::remove as used from 2.6 onwards.
1254 qla1280_release(struct Scsi_Host *host)
1256 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
1258 qla1280_remove_one(ha->pdev);
1263 qla1280_biosparam_old(Disk * disk, kdev_t dev, int geom[])
1265 return qla1280_biosparam(disk->device, NULL, disk->capacity, geom);
1269 /* disable risc and host interrupts */
1271 qla1280_disable_intrs(struct scsi_qla_host *ha)
1273 WRT_REG_WORD(&ha->iobase->ictrl, 0);
1274 RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
1277 /* enable risc and host interrupts */
1279 qla1280_enable_intrs(struct scsi_qla_host *ha)
1281 WRT_REG_WORD(&ha->iobase->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1282 RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
1285 /**************************************************************************
1286 * qla1280_intr_handler
1287 * Handles the H/W interrupt
1288 **************************************************************************/
1290 qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1292 struct scsi_qla_host *ha;
1293 struct device_reg __iomem *reg;
1297 ENTER_INTR ("qla1280_intr_handler");
1298 ha = (struct scsi_qla_host *)dev_id;
1300 spin_lock(HOST_LOCK);
1305 qla1280_disable_intrs(ha);
1307 data = qla1280_debounce_register(®->istatus);
1308 /* Check for pending interrupts. */
1309 if (data & RISC_INT) {
1310 qla1280_isr(ha, &ha->done_q);
1313 if (!list_empty(&ha->done_q))
1316 spin_unlock(HOST_LOCK);
1318 qla1280_enable_intrs(ha);
1320 LEAVE_INTR("qla1280_intr_handler");
1321 return IRQ_RETVAL(handled);
1326 qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
1329 uint16_t mb[MAILBOX_REGISTER_COUNT];
1335 mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
1337 /* Set Target Parameters. */
1338 mb[0] = MBC_SET_TARGET_PARAMETERS;
1339 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
1342 mb[2] = (nv->bus[bus].target[target].parameter.c << 8);
1344 if (IS_ISP1x160(ha)) {
1345 mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
1346 mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8) |
1347 nv->bus[bus].target[target].sync_period;
1348 mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) |
1349 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
1352 mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8) |
1353 nv->bus[bus].target[target].sync_period;
1356 status = qla1280_mailbox_command(ha, mr, &mb[0]);
1359 printk(KERN_WARNING "scsi(%ld:%i:%i): "
1360 "qla1280_set_target_parameters() failed\n",
1361 ha->host_no, bus, target);
1366 /**************************************************************************
1367 * qla1280_slave_configure
1370 * Determines the queue depth for a given device. There are two ways
1371 * a queue depth can be obtained for a tagged queueing device. One
1372 * way is the default queue depth which is determined by whether
1373 * If it is defined, then it is used
1374 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1375 * default queue depth (dependent on the number of hardware SCBs).
1376 **************************************************************************/
1378 qla1280_slave_configure(struct scsi_device *device)
1380 struct scsi_qla_host *ha;
1381 int default_depth = 3;
1382 int bus = device->channel;
1383 int target = device->id;
1386 unsigned long flags;
1388 ha = (struct scsi_qla_host *)device->host->hostdata;
1391 if (qla1280_check_for_dead_scsi_bus(ha, bus))
1394 if (device->tagged_supported &&
1395 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1396 scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
1397 ha->bus_settings[bus].hiwat);
1399 scsi_adjust_queue_depth(device, 0, default_depth);
1402 #if LINUX_VERSION_CODE > 0x020500
1403 nv->bus[bus].target[target].parameter.f.enable_sync = device->sdtr;
1404 nv->bus[bus].target[target].parameter.f.enable_wide = device->wdtr;
1405 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
1408 if (driver_setup.no_sync ||
1409 (driver_setup.sync_mask &&
1410 (~driver_setup.sync_mask & (1 << target))))
1411 nv->bus[bus].target[target].parameter.f.enable_sync = 0;
1412 if (driver_setup.no_wide ||
1413 (driver_setup.wide_mask &&
1414 (~driver_setup.wide_mask & (1 << target))))
1415 nv->bus[bus].target[target].parameter.f.enable_wide = 0;
1416 if (IS_ISP1x160(ha)) {
1417 if (driver_setup.no_ppr ||
1418 (driver_setup.ppr_mask &&
1419 (~driver_setup.ppr_mask & (1 << target))))
1420 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
1423 spin_lock_irqsave(HOST_LOCK, flags);
1424 if (nv->bus[bus].target[target].parameter.f.enable_sync)
1425 status = qla1280_set_target_parameters(ha, bus, target);
1426 qla1280_get_target_parameters(ha, device);
1427 spin_unlock_irqrestore(HOST_LOCK, flags);
1431 #if LINUX_VERSION_CODE < 0x020545
1432 /**************************************************************************
1433 * qla1280_select_queue_depth
1435 * Sets the queue depth for each SCSI device hanging off the input
1436 * host adapter. We use a queue depth of 2 for devices that do not
1437 * support tagged queueing.
1438 **************************************************************************/
1440 qla1280_select_queue_depth(struct Scsi_Host *host, struct scsi_device *sdev_q)
1442 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
1443 struct scsi_device *sdev;
1445 ENTER("qla1280_select_queue_depth");
1446 for (sdev = sdev_q; sdev; sdev = sdev->next)
1447 if (sdev->host == host)
1448 qla1280_slave_configure(sdev);
1451 qla1280_check_for_dead_scsi_bus(ha, sdev_q->channel);
1452 LEAVE("qla1280_select_queue_depth");
1458 * Process completed commands.
1461 * ha = adapter block pointer.
1464 qla1280_done(struct scsi_qla_host *ha)
1467 struct list_head *done_q;
1468 int bus, target, lun;
1469 struct scsi_cmnd *cmd;
1471 ENTER("qla1280_done");
1473 done_q = &ha->done_q;
1475 while (!list_empty(done_q)) {
1476 sp = list_entry(done_q->next, struct srb, list);
1478 list_del(&sp->list);
1481 bus = SCSI_BUS_32(cmd);
1482 target = SCSI_TCN_32(cmd);
1483 lun = SCSI_LUN_32(cmd);
1485 switch ((CMD_RESULT(cmd) >> 16)) {
1487 /* Issue marker command. */
1488 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
1491 sp->flags &= ~SRB_ABORT_PENDING;
1492 sp->flags |= SRB_ABORTED;
1493 if (sp->flags & SRB_TIMEOUT)
1494 CMD_RESULT(sp->cmd) = DID_TIME_OUT << 16;
1500 /* Release memory used for this I/O */
1502 pci_unmap_sg(ha->pdev, cmd->request_buffer,
1503 cmd->use_sg, cmd->sc_data_direction);
1504 } else if (cmd->request_bufflen) {
1505 pci_unmap_single(ha->pdev, sp->saved_dma_handle,
1506 cmd->request_bufflen,
1507 cmd->sc_data_direction);
1510 /* Call the mid-level driver interrupt handler */
1511 CMD_HANDLE(sp->cmd) = (unsigned char *)INVALID_HANDLE;
1514 #if LINUX_VERSION_CODE < 0x020500
1515 if (cmd->cmnd[0] == INQUIRY)
1516 qla1280_get_target_options(cmd, ha);
1518 (*(cmd)->scsi_done)(cmd);
1520 if(sp->wait != NULL)
1523 LEAVE("qla1280_done");
1527 * Translates a ISP error to a Linux SCSI error
1530 qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1532 int host_status = DID_ERROR;
1533 uint16_t comp_status = le16_to_cpu(sts->comp_status);
1534 uint16_t state_flags = le16_to_cpu(sts->state_flags);
1535 uint16_t residual_length = le16_to_cpu(sts->residual_length);
1536 uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
1537 #if DEBUG_QLA1280_INTR
1538 static char *reason[] = {
1550 #endif /* DEBUG_QLA1280_INTR */
1552 ENTER("qla1280_return_status");
1554 #if DEBUG_QLA1280_INTR
1556 dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
1561 switch (comp_status) {
1563 host_status = DID_OK;
1567 if (!(state_flags & SF_GOT_BUS))
1568 host_status = DID_NO_CONNECT;
1569 else if (!(state_flags & SF_GOT_TARGET))
1570 host_status = DID_BAD_TARGET;
1571 else if (!(state_flags & SF_SENT_CDB))
1572 host_status = DID_ERROR;
1573 else if (!(state_flags & SF_TRANSFERRED_DATA))
1574 host_status = DID_ERROR;
1575 else if (!(state_flags & SF_GOT_STATUS))
1576 host_status = DID_ERROR;
1577 else if (!(state_flags & SF_GOT_SENSE))
1578 host_status = DID_ERROR;
1582 host_status = DID_RESET;
1586 host_status = DID_ABORT;
1590 host_status = DID_TIME_OUT;
1593 case CS_DATA_OVERRUN:
1594 dprintk(2, "Data overrun 0x%x\n", residual_length);
1595 dprintk(2, "qla1280_return_status: response packet data\n");
1596 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
1597 host_status = DID_ERROR;
1600 case CS_DATA_UNDERRUN:
1601 if ((cp->request_bufflen - residual_length) <
1604 "scsi: Underflow detected - retrying "
1606 host_status = DID_ERROR;
1608 host_status = DID_OK;
1612 host_status = DID_ERROR;
1616 #if DEBUG_QLA1280_INTR
1617 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
1618 reason[host_status], scsi_status);
1621 LEAVE("qla1280_return_status");
1623 return (scsi_status & 0xff) | (host_status << 16);
1626 /****************************************************************************/
1627 /* QLogic ISP1280 Hardware Support Functions. */
1628 /****************************************************************************/
1631 * qla1280_initialize_adapter
1635 * ha = adapter block pointer.
1640 static int __devinit
1641 qla1280_initialize_adapter(struct scsi_qla_host *ha)
1643 struct device_reg __iomem *reg;
1646 #if LINUX_VERSION_CODE > 0x020500
1647 unsigned long flags;
1650 ENTER("qla1280_initialize_adapter");
1652 /* Clear adapter flags. */
1653 ha->flags.online = 0;
1654 ha->flags.disable_host_adapter = 0;
1655 ha->flags.reset_active = 0;
1656 ha->flags.abort_isp_active = 0;
1658 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1659 if (ia64_platform_is("sn2")) {
1660 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
1661 "dual channel lockup workaround\n", ha->host_no);
1662 ha->flags.use_pci_vchannel = 1;
1663 driver_setup.no_nvram = 1;
1667 /* TODO: implement support for the 1040 nvram format */
1669 driver_setup.no_nvram = 1;
1671 dprintk(1, "Configure PCI space for adapter...\n");
1675 /* Insure mailbox registers are free. */
1676 WRT_REG_WORD(®->semaphore, 0);
1677 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
1678 WRT_REG_WORD(®->host_cmd, HC_CLR_HOST_INT);
1679 RD_REG_WORD(®->host_cmd);
1681 if (qla1280_read_nvram(ha)) {
1682 dprintk(2, "qla1280_initialize_adapter: failed to read "
1686 #if LINUX_VERSION_CODE >= 0x020500
1688 * It's necessary to grab the spin here as qla1280_mailbox_command
1689 * needs to be able to drop the lock unconditionally to wait
1691 * In 2.4 ->detect is called with the io_request_lock held.
1693 spin_lock_irqsave(HOST_LOCK, flags);
1696 status = qla1280_load_firmware(ha);
1698 printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
1703 /* Setup adapter based on NVRAM parameters. */
1704 dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha->host_no);
1705 qla1280_nvram_config(ha);
1707 if (ha->flags.disable_host_adapter) {
1712 status = qla1280_init_rings(ha);
1716 /* Issue SCSI reset, if we can't reset twice then bus is dead */
1717 for (bus = 0; bus < ha->ports; bus++) {
1718 if (!ha->bus_settings[bus].disable_scsi_reset &&
1719 qla1280_bus_reset(ha, bus) &&
1720 qla1280_bus_reset(ha, bus))
1721 ha->bus_settings[bus].scsi_bus_dead = 1;
1724 ha->flags.online = 1;
1726 #if LINUX_VERSION_CODE >= 0x020500
1727 spin_unlock_irqrestore(HOST_LOCK, flags);
1730 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
1732 LEAVE("qla1280_initialize_adapter");
1739 * Checks if present version of RISC firmware is older than
1743 * ha = adapter block pointer.
1746 * 0 = firmware does not need to be loaded.
1749 qla1280_isp_firmware(struct scsi_qla_host *ha)
1751 struct nvram *nv = (struct nvram *) ha->response_ring;
1752 int status = 0; /* dg 2/27 always loads RISC */
1753 uint16_t mb[MAILBOX_REGISTER_COUNT];
1755 ENTER("qla1280_isp_firmware");
1757 dprintk(1, "scsi(%li): Determining if RISC is loaded\n", ha->host_no);
1759 /* Bad NVRAM data, load RISC code. */
1760 if (!ha->nvram_valid) {
1761 ha->flags.disable_risc_code_load = 0;
1763 ha->flags.disable_risc_code_load =
1764 nv->cntr_flags_1.disable_loading_risc_code;
1766 if (ha->flags.disable_risc_code_load) {
1767 dprintk(3, "qla1280_isp_firmware: Telling RISC to verify "
1768 "checksum of loaded BIOS code.\n");
1770 /* Verify checksum of loaded RISC code. */
1771 mb[0] = MBC_VERIFY_CHECKSUM;
1772 /* mb[1] = ql12_risc_code_addr01; */
1773 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1776 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]))) {
1777 /* Start firmware execution. */
1778 dprintk(3, "qla1280_isp_firmware: Startng F/W "
1781 mb[0] = MBC_EXECUTE_FIRMWARE;
1782 /* mb[1] = ql12_risc_code_addr01; */
1783 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1784 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
1786 printk(KERN_INFO "qla1280: RISC checksum failed.\n");
1788 dprintk(1, "qla1280: NVRAM configured to load RISC load.\n");
1793 dprintk(2, "qla1280_isp_firmware: **** Load RISC code ****\n");
1795 LEAVE("qla1280_isp_firmware");
1801 * Test chip for proper operation.
1804 * ha = adapter block pointer.
1810 qla1280_chip_diag(struct scsi_qla_host *ha)
1812 uint16_t mb[MAILBOX_REGISTER_COUNT];
1813 struct device_reg __iomem *reg = ha->iobase;
1817 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®->id_l);
1819 dprintk(1, "scsi(%ld): Verifying chip\n", ha->host_no);
1821 /* Soft reset chip and wait for it to finish. */
1822 WRT_REG_WORD(®->ictrl, ISP_RESET);
1825 * We can't do a traditional PCI write flush here by reading
1826 * back the register. The card will not respond once the reset
1827 * is in action and we end up with a machine check exception
1828 * instead. Nothing to do but wait and hope for the best.
1829 * A portable pci_write_flush(pdev) call would be very useful here.
1832 data = qla1280_debounce_register(®->ictrl);
1834 * Yet another QLogic gem ;-(
1836 for (cnt = 1000000; cnt && data & ISP_RESET; cnt--) {
1838 data = RD_REG_WORD(®->ictrl);
1844 /* Reset register cleared by chip reset. */
1845 dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
1847 WRT_REG_WORD(®->cfg_1, 0);
1849 /* Reset RISC and disable BIOS which
1850 allows RISC to execute out of RAM. */
1851 WRT_REG_WORD(®->host_cmd, HC_RESET_RISC |
1852 HC_RELEASE_RISC | HC_DISABLE_BIOS);
1854 RD_REG_WORD(®->id_l); /* Flush PCI write */
1855 data = qla1280_debounce_register(®->mailbox0);
1858 * I *LOVE* this code!
1860 for (cnt = 1000000; cnt && data == MBS_BUSY; cnt--) {
1862 data = RD_REG_WORD(®->mailbox0);
1868 /* Check product ID of chip */
1869 dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
1871 if (RD_REG_WORD(®->mailbox1) != PROD_ID_1 ||
1872 (RD_REG_WORD(®->mailbox2) != PROD_ID_2 &&
1873 RD_REG_WORD(®->mailbox2) != PROD_ID_2a) ||
1874 RD_REG_WORD(®->mailbox3) != PROD_ID_3 ||
1875 RD_REG_WORD(®->mailbox4) != PROD_ID_4) {
1876 printk(KERN_INFO "qla1280: Wrong product ID = "
1877 "0x%x,0x%x,0x%x,0x%x\n",
1878 RD_REG_WORD(®->mailbox1),
1879 RD_REG_WORD(®->mailbox2),
1880 RD_REG_WORD(®->mailbox3),
1881 RD_REG_WORD(®->mailbox4));
1886 * Enable ints early!!!
1888 qla1280_enable_intrs(ha);
1890 dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
1891 /* Wrap Incoming Mailboxes Test. */
1892 mb[0] = MBC_MAILBOX_REGISTER_TEST;
1901 status = qla1280_mailbox_command(ha, 0xff, mb);
1905 if (mb[1] != 0xAAAA || mb[2] != 0x5555 || mb[3] != 0xAA55 ||
1906 mb[4] != 0x55AA || mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
1908 printk(KERN_INFO "qla1280: Failed mbox check\n");
1912 dprintk(3, "qla1280_chip_diag: exiting normally\n");
1915 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
1920 qla1280_load_firmware_pio(struct scsi_qla_host *ha)
1922 uint16_t risc_address, *risc_code_address, risc_code_size;
1923 uint16_t mb[MAILBOX_REGISTER_COUNT], i;
1926 /* Load RISC code. */
1927 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
1928 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
1929 risc_code_size = *ql1280_board_tbl[ha->devnum].fwlen;
1931 for (i = 0; i < risc_code_size; i++) {
1932 mb[0] = MBC_WRITE_RAM_WORD;
1933 mb[1] = risc_address + i;
1934 mb[2] = risc_code_address[i];
1936 err = qla1280_mailbox_command(ha, BIT_0 | BIT_1 | BIT_2, mb);
1938 printk(KERN_ERR "scsi(%li): Failed to load firmware\n",
1947 #define DUMP_IT_BACK 0 /* for debug of RISC loading */
1949 qla1280_load_firmware_dma(struct scsi_qla_host *ha)
1951 uint16_t risc_address, *risc_code_address, risc_code_size;
1952 uint16_t mb[MAILBOX_REGISTER_COUNT], cnt;
1953 int err = 0, num, i;
1958 tbuf = pci_alloc_consistent(ha->pdev, 8000, &p_tbuf);
1963 /* Load RISC code. */
1964 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
1965 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
1966 risc_code_size = *ql1280_board_tbl[ha->devnum].fwlen;
1968 dprintk(1, "%s: DMA RISC code (%i) words\n",
1969 __FUNCTION__, risc_code_size);
1972 while (risc_code_size > 0) {
1973 int warn __attribute__((unused)) = 0;
1977 if (cnt > risc_code_size)
1978 cnt = risc_code_size;
1980 dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
1982 risc_code_address, cnt, num, risc_address);
1983 for(i = 0; i < cnt; i++)
1984 ((uint16_t *)ha->request_ring)[i] =
1985 cpu_to_le16(risc_code_address[i]);
1987 mb[0] = MBC_LOAD_RAM;
1988 mb[1] = risc_address;
1990 mb[3] = ha->request_dma & 0xffff;
1991 mb[2] = (ha->request_dma >> 16) & 0xffff;
1992 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
1993 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
1994 dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
1995 __FUNCTION__, mb[0],
1996 (void *)(long)ha->request_dma,
1997 mb[6], mb[7], mb[2], mb[3]);
1998 err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
2001 printk(KERN_ERR "scsi(%li): Failed to load partial "
2002 "segment of f\n", ha->host_no);
2007 mb[0] = MBC_DUMP_RAM;
2008 mb[1] = risc_address;
2010 mb[3] = p_tbuf & 0xffff;
2011 mb[2] = (p_tbuf >> 16) & 0xffff;
2012 mb[7] = pci_dma_hi32(p_tbuf) & 0xffff;
2013 mb[6] = pci_dma_hi32(p_tbuf) >> 16;
2015 err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
2019 "Failed to dump partial segment of f/w\n");
2022 sp = (uint8_t *)ha->request_ring;
2023 for (i = 0; i < (cnt << 1); i++) {
2024 if (tbuf[i] != sp[i] && warn++ < 10) {
2025 printk(KERN_ERR "%s: FW compare error @ "
2026 "byte(0x%x) loop#=%x\n",
2027 __FUNCTION__, i, num);
2028 printk(KERN_ERR "%s: FWbyte=%x "
2030 __FUNCTION__, sp[i], tbuf[i]);
2035 risc_address += cnt;
2036 risc_code_size = risc_code_size - cnt;
2037 risc_code_address = risc_code_address + cnt;
2043 pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
2049 qla1280_start_firmware(struct scsi_qla_host *ha)
2051 uint16_t mb[MAILBOX_REGISTER_COUNT];
2054 dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
2057 /* Verify checksum of loaded RISC code. */
2058 mb[0] = MBC_VERIFY_CHECKSUM;
2059 /* mb[1] = ql12_risc_code_addr01; */
2060 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2061 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2063 printk(KERN_ERR "scsi(%li): RISC checksum failed.\n", ha->host_no);
2067 /* Start firmware execution. */
2068 dprintk(1, "%s: start firmware running.\n", __FUNCTION__);
2069 mb[0] = MBC_EXECUTE_FIRMWARE;
2070 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2071 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2073 printk(KERN_ERR "scsi(%li): Failed to start firmware\n",
2081 qla1280_load_firmware(struct scsi_qla_host *ha)
2085 /* If firmware needs to be loaded */
2086 if (!qla1280_isp_firmware(ha)) {
2087 printk(KERN_ERR "scsi(%li): isp_firmware() failed!\n",
2092 err = qla1280_chip_diag(ha);
2096 err = qla1280_load_firmware_pio(ha);
2098 err = qla1280_load_firmware_dma(ha);
2101 err = qla1280_start_firmware(ha);
2110 * ha = adapter block pointer.
2111 * ha->request_ring = request ring virtual address
2112 * ha->response_ring = response ring virtual address
2113 * ha->request_dma = request ring physical address
2114 * ha->response_dma = response ring physical address
2120 qla1280_init_rings(struct scsi_qla_host *ha)
2122 uint16_t mb[MAILBOX_REGISTER_COUNT];
2125 ENTER("qla1280_init_rings");
2127 /* Clear outstanding commands array. */
2128 memset(ha->outstanding_cmds, 0,
2129 sizeof(struct srb *) * MAX_OUTSTANDING_COMMANDS);
2131 /* Initialize request queue. */
2132 ha->request_ring_ptr = ha->request_ring;
2133 ha->req_ring_index = 0;
2134 ha->req_q_cnt = REQUEST_ENTRY_CNT;
2135 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
2136 mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
2137 mb[1] = REQUEST_ENTRY_CNT;
2138 mb[3] = ha->request_dma & 0xffff;
2139 mb[2] = (ha->request_dma >> 16) & 0xffff;
2141 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2142 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2143 if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
2144 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2146 /* Initialize response queue. */
2147 ha->response_ring_ptr = ha->response_ring;
2148 ha->rsp_ring_index = 0;
2149 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
2150 mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
2151 mb[1] = RESPONSE_ENTRY_CNT;
2152 mb[3] = ha->response_dma & 0xffff;
2153 mb[2] = (ha->response_dma >> 16) & 0xffff;
2155 mb[7] = pci_dma_hi32(ha->response_dma) & 0xffff;
2156 mb[6] = pci_dma_hi32(ha->response_dma) >> 16;
2157 status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
2158 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2163 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
2165 LEAVE("qla1280_init_rings");
2170 qla1280_print_settings(struct nvram *nv)
2172 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
2173 nv->bus[0].config_1.initiator_id);
2174 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
2175 nv->bus[1].config_1.initiator_id);
2177 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
2178 nv->bus[0].bus_reset_delay);
2179 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
2180 nv->bus[1].bus_reset_delay);
2182 dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
2183 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
2184 dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
2185 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
2187 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
2188 nv->bus[0].config_2.async_data_setup_time);
2189 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
2190 nv->bus[1].config_2.async_data_setup_time);
2192 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
2193 nv->bus[0].config_2.req_ack_active_negation);
2194 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
2195 nv->bus[1].config_2.req_ack_active_negation);
2197 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
2198 nv->bus[0].config_2.data_line_active_negation);
2199 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
2200 nv->bus[1].config_2.data_line_active_negation);
2202 dprintk(1, "qla1280 : disable loading risc code=%d\n",
2203 nv->cntr_flags_1.disable_loading_risc_code);
2205 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
2206 nv->cntr_flags_1.enable_64bit_addressing);
2208 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
2209 nv->bus[0].selection_timeout);
2210 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
2211 nv->bus[1].selection_timeout);
2213 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
2214 nv->bus[0].max_queue_depth);
2215 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
2216 nv->bus[1].max_queue_depth);
2220 qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target)
2222 struct nvram *nv = &ha->nvram;
2224 nv->bus[bus].target[target].parameter.f.renegotiate_on_error = 1;
2225 nv->bus[bus].target[target].parameter.f.auto_request_sense = 1;
2226 nv->bus[bus].target[target].parameter.f.tag_queuing = 1;
2227 nv->bus[bus].target[target].parameter.f.enable_sync = 1;
2228 #if 1 /* Some SCSI Processors do not seem to like this */
2229 nv->bus[bus].target[target].parameter.f.enable_wide = 1;
2231 nv->bus[bus].target[target].parameter.f.parity_checking = 1;
2232 nv->bus[bus].target[target].parameter.f.disconnect_allowed = 1;
2233 nv->bus[bus].target[target].execution_throttle =
2234 nv->bus[bus].max_queue_depth - 1;
2236 if (IS_ISP1x160(ha)) {
2237 nv->bus[bus].target[target].flags.flags1x160.device_enable = 1;
2238 nv->bus[bus].target[target].flags.flags1x160.sync_offset = 0x0e;
2239 nv->bus[bus].target[target].sync_period = 9;
2240 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
2241 nv->bus[bus].target[target].ppr_1x160.flags.ppr_options = 2;
2242 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width = 1;
2244 nv->bus[bus].target[target].flags.flags1x80.device_enable = 1;
2245 nv->bus[bus].target[target].flags.flags1x80.sync_offset = 12;
2246 nv->bus[bus].target[target].sync_period = 10;
2251 qla1280_set_defaults(struct scsi_qla_host *ha)
2253 struct nvram *nv = &ha->nvram;
2256 dprintk(1, "Using defaults for NVRAM: \n");
2257 memset(nv, 0, sizeof(struct nvram));
2259 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
2260 nv->firmware_feature.f.enable_fast_posting = 1;
2261 nv->firmware_feature.f.disable_synchronous_backoff = 1;
2262 nv->termination.f.scsi_bus_0_control = 3;
2263 nv->termination.f.scsi_bus_1_control = 3;
2264 nv->termination.f.auto_term_support = 1;
2267 * Set default FIFO magic - What appropriate values would be here
2268 * is unknown. This is what I have found testing with 12160s.
2270 * Now, I would love the magic decoder ring for this one, the
2271 * header file provided by QLogic seems to be bogus or incomplete
2274 nv->isp_config.c = ISP_CFG1_BENAB|ISP_CFG1_F128;
2275 if (IS_ISP1x160(ha))
2276 nv->isp_parameter = 0x01; /* fast memory enable */
2278 for (bus = 0; bus < MAX_BUSES; bus++) {
2279 nv->bus[bus].config_1.initiator_id = 7;
2280 nv->bus[bus].config_2.req_ack_active_negation = 1;
2281 nv->bus[bus].config_2.data_line_active_negation = 1;
2282 nv->bus[bus].selection_timeout = 250;
2283 nv->bus[bus].max_queue_depth = 256;
2285 if (IS_ISP1040(ha)) {
2286 nv->bus[bus].bus_reset_delay = 3;
2287 nv->bus[bus].config_2.async_data_setup_time = 6;
2288 nv->bus[bus].retry_delay = 1;
2290 nv->bus[bus].bus_reset_delay = 5;
2291 nv->bus[bus].config_2.async_data_setup_time = 8;
2294 for (target = 0; target < MAX_TARGETS; target++)
2295 qla1280_set_target_defaults(ha, bus, target);
2300 qla1280_config_target(struct scsi_qla_host *ha, int bus, int target)
2302 struct nvram *nv = &ha->nvram;
2303 uint16_t mb[MAILBOX_REGISTER_COUNT];
2306 /* Set Target Parameters. */
2307 mb[0] = MBC_SET_TARGET_PARAMETERS;
2308 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
2312 * Do not enable wide, sync, and ppr for the initial
2313 * INQUIRY run. We enable this later if we determine
2314 * the target actually supports it.
2316 nv->bus[bus].target[target].parameter.f.
2317 auto_request_sense = 1;
2318 nv->bus[bus].target[target].parameter.f.
2319 stop_queue_on_check = 0;
2321 if (IS_ISP1x160(ha))
2322 nv->bus[bus].target[target].ppr_1x160.
2323 flags.enable_ppr = 0;
2326 * No sync, wide, etc. while probing
2328 mb[2] = (nv->bus[bus].target[target].parameter.c << 8) &
2329 ~(TP_SYNC /*| TP_WIDE | TP_PPR*/);
2331 if (IS_ISP1x160(ha))
2332 mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
2334 mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
2335 mb[3] |= nv->bus[bus].target[target].sync_period;
2337 status = qla1280_mailbox_command(ha, BIT_3 | BIT_2 | BIT_1 | BIT_0, &mb[0]);
2339 /* Save Tag queuing enable flag. */
2340 mb[0] = BIT_0 << target;
2341 if (nv->bus[bus].target[target].parameter.f.tag_queuing)
2342 ha->bus_settings[bus].qtag_enables |= mb[0];
2344 /* Save Device enable flag. */
2345 if (IS_ISP1x160(ha)) {
2346 if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
2347 ha->bus_settings[bus].device_enables |= mb[0];
2348 ha->bus_settings[bus].lun_disables |= 0;
2350 if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
2351 ha->bus_settings[bus].device_enables |= mb[0];
2352 /* Save LUN disable flag. */
2353 if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
2354 ha->bus_settings[bus].lun_disables |= mb[0];
2357 /* Set Device Queue Parameters. */
2358 for (lun = 0; lun < MAX_LUNS; lun++) {
2359 mb[0] = MBC_SET_DEVICE_QUEUE;
2360 mb[1] = (uint16_t)(bus ? target | BIT_7 : target);
2361 mb[1] = mb[1] << 8 | lun;
2362 mb[2] = nv->bus[bus].max_queue_depth;
2363 mb[3] = nv->bus[bus].target[target].execution_throttle;
2364 status |= qla1280_mailbox_command(ha, 0x0f, &mb[0]);
2371 qla1280_config_bus(struct scsi_qla_host *ha, int bus)
2373 struct nvram *nv = &ha->nvram;
2374 uint16_t mb[MAILBOX_REGISTER_COUNT];
2377 /* SCSI Reset Disable. */
2378 ha->bus_settings[bus].disable_scsi_reset =
2379 nv->bus[bus].config_1.scsi_reset_disable;
2382 ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
2383 mb[0] = MBC_SET_INITIATOR_ID;
2384 mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
2385 ha->bus_settings[bus].id;
2386 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2389 ha->bus_settings[bus].bus_reset_delay =
2390 nv->bus[bus].bus_reset_delay;
2392 /* Command queue depth per device. */
2393 ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
2395 /* Set target parameters. */
2396 for (target = 0; target < MAX_TARGETS; target++)
2397 status |= qla1280_config_target(ha, bus, target);
2403 qla1280_nvram_config(struct scsi_qla_host *ha)
2405 struct device_reg __iomem *reg = ha->iobase;
2406 struct nvram *nv = &ha->nvram;
2407 int bus, target, status = 0;
2408 uint16_t mb[MAILBOX_REGISTER_COUNT];
2411 ENTER("qla1280_nvram_config");
2413 if (ha->nvram_valid) {
2414 /* Always force AUTO sense for LINUX SCSI */
2415 for (bus = 0; bus < MAX_BUSES; bus++)
2416 for (target = 0; target < MAX_TARGETS; target++) {
2417 nv->bus[bus].target[target].parameter.f.
2418 auto_request_sense = 1;
2421 qla1280_set_defaults(ha);
2424 qla1280_print_settings(nv);
2426 /* Disable RISC load of firmware. */
2427 ha->flags.disable_risc_code_load =
2428 nv->cntr_flags_1.disable_loading_risc_code;
2430 if (IS_ISP1040(ha)) {
2431 uint16_t hwrev, cfg1, cdma_conf, ddma_conf;
2433 hwrev = RD_REG_WORD(®->cfg_0) & ISP_CFG0_HWMSK;
2435 cfg1 = RD_REG_WORD(®->cfg_1);
2436 cdma_conf = RD_REG_WORD(®->cdma_cfg);
2437 ddma_conf = RD_REG_WORD(®->ddma_cfg);
2439 /* Busted fifo, says mjacob. */
2440 if (hwrev == ISP_CFG0_1040A)
2441 WRT_REG_WORD(®->cfg_1, cfg1 | ISP_CFG1_F64);
2443 WRT_REG_WORD(®->cfg_1, cfg1 | ISP_CFG1_F64 | ISP_CFG1_BENAB);
2445 WRT_REG_WORD(®->cdma_cfg, cdma_conf | CDMA_CONF_BENAB);
2446 WRT_REG_WORD(®->ddma_cfg, cdma_conf | DDMA_CONF_BENAB);
2448 /* Set ISP hardware DMA burst */
2449 mb[0] = nv->isp_config.c;
2450 /* Enable DMA arbitration on dual channel controllers */
2453 WRT_REG_WORD(®->cfg_1, mb[0]);
2455 /* Set SCSI termination. */
2456 WRT_REG_WORD(®->gpio_enable, (BIT_3 + BIT_2 + BIT_1 + BIT_0));
2457 mb[0] = nv->termination.c & (BIT_3 + BIT_2 + BIT_1 + BIT_0);
2458 WRT_REG_WORD(®->gpio_data, mb[0]);
2461 /* ISP parameter word. */
2462 mb[0] = MBC_SET_SYSTEM_PARAMETER;
2463 mb[1] = nv->isp_parameter;
2464 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2466 if (IS_ISP1x40(ha)) {
2467 /* clock rate - for qla1240 and older, only */
2468 mb[0] = MBC_SET_CLOCK_RATE;
2470 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2473 /* Firmware feature word. */
2474 mb[0] = MBC_SET_FIRMWARE_FEATURES;
2475 mask = BIT_5 | BIT_1 | BIT_0;
2476 mb[1] = le16_to_cpu(nv->firmware_feature.w) & (mask);
2477 #if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
2478 if (ia64_platform_is("sn2")) {
2479 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
2480 "workaround\n", ha->host_no);
2484 status |= qla1280_mailbox_command(ha, mask, &mb[0]);
2486 /* Retry count and delay. */
2487 mb[0] = MBC_SET_RETRY_COUNT;
2488 mb[1] = nv->bus[0].retry_count;
2489 mb[2] = nv->bus[0].retry_delay;
2490 mb[6] = nv->bus[1].retry_count;
2491 mb[7] = nv->bus[1].retry_delay;
2492 status |= qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 |
2493 BIT_1 | BIT_0, &mb[0]);
2495 /* ASYNC data setup time. */
2496 mb[0] = MBC_SET_ASYNC_DATA_SETUP;
2497 mb[1] = nv->bus[0].config_2.async_data_setup_time;
2498 mb[2] = nv->bus[1].config_2.async_data_setup_time;
2499 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2501 /* Active negation states. */
2502 mb[0] = MBC_SET_ACTIVE_NEGATION;
2504 if (nv->bus[0].config_2.req_ack_active_negation)
2506 if (nv->bus[0].config_2.data_line_active_negation)
2509 if (nv->bus[1].config_2.req_ack_active_negation)
2511 if (nv->bus[1].config_2.data_line_active_negation)
2513 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2515 mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
2516 mb[1] = 2; /* Reset SCSI bus and return all outstanding IO */
2517 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2520 mb[0] = MBC_SET_PCI_CONTROL;
2521 mb[1] = 2; /* Data DMA Channel Burst Enable */
2522 mb[2] = 2; /* Command DMA Channel Burst Enable */
2523 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2525 mb[0] = MBC_SET_TAG_AGE_LIMIT;
2527 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2529 /* Selection timeout. */
2530 mb[0] = MBC_SET_SELECTION_TIMEOUT;
2531 mb[1] = nv->bus[0].selection_timeout;
2532 mb[2] = nv->bus[1].selection_timeout;
2533 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2535 for (bus = 0; bus < ha->ports; bus++)
2536 status |= qla1280_config_bus(ha, bus);
2539 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
2541 LEAVE("qla1280_nvram_config");
2546 * Get NVRAM data word
2547 * Calculates word position in NVRAM and calls request routine to
2548 * get the word from NVRAM.
2551 * ha = adapter block pointer.
2552 * address = NVRAM word address.
2558 qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
2563 nv_cmd = address << 16;
2564 nv_cmd |= NV_READ_OP;
2566 data = le16_to_cpu(qla1280_nvram_request(ha, nv_cmd));
2568 dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
2576 * Sends read command to NVRAM and gets data from NVRAM.
2579 * ha = adapter block pointer.
2580 * nv_cmd = Bit 26 = start bit
2581 * Bit 25, 24 = opcode
2582 * Bit 23-16 = address
2583 * Bit 15-0 = write data
2589 qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
2591 struct device_reg __iomem *reg = ha->iobase;
2596 /* Send command to NVRAM. */
2599 for (cnt = 0; cnt < 11; cnt++) {
2600 if (nv_cmd & BIT_31)
2601 qla1280_nv_write(ha, NV_DATA_OUT);
2603 qla1280_nv_write(ha, 0);
2607 /* Read data from NVRAM. */
2609 for (cnt = 0; cnt < 16; cnt++) {
2610 WRT_REG_WORD(®->nvram, (NV_SELECT | NV_CLOCK));
2611 RD_REG_WORD(®->id_l); /* Flush PCI write */
2614 reg_data = RD_REG_WORD(®->nvram);
2615 if (reg_data & NV_DATA_IN)
2617 WRT_REG_WORD(®->nvram, NV_SELECT);
2618 RD_REG_WORD(®->id_l); /* Flush PCI write */
2622 /* Deselect chip. */
2624 WRT_REG_WORD(®->nvram, NV_DESELECT);
2625 RD_REG_WORD(®->id_l); /* Flush PCI write */
2632 qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
2634 struct device_reg __iomem *reg = ha->iobase;
2636 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2637 RD_REG_WORD(®->id_l); /* Flush PCI write */
2639 WRT_REG_WORD(®->nvram, data | NV_SELECT | NV_CLOCK);
2640 RD_REG_WORD(®->id_l); /* Flush PCI write */
2642 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2643 RD_REG_WORD(®->id_l); /* Flush PCI write */
2649 * Issue mailbox command and waits for completion.
2652 * ha = adapter block pointer.
2653 * mr = mailbox registers to load.
2654 * mb = data pointer for mailbox registers.
2657 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
2663 qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
2665 struct device_reg __iomem *reg = ha->iobase;
2671 uint16_t *optr, *iptr;
2672 uint16_t __iomem *mptr;
2674 DECLARE_COMPLETION(wait);
2675 struct timer_list timer;
2677 ENTER("qla1280_mailbox_command");
2679 if (ha->mailbox_wait) {
2680 printk(KERN_ERR "Warning mailbox wait already in use!\n");
2682 ha->mailbox_wait = &wait;
2685 * We really should start out by verifying that the mailbox is
2686 * available before starting sending the command data
2688 /* Load mailbox registers. */
2689 mptr = (uint16_t __iomem *) ®->mailbox0;
2691 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
2693 WRT_REG_WORD(mptr, (*iptr));
2701 /* Issue set host interrupt command. */
2703 /* set up a timer just in case we're really jammed */
2705 timer.expires = jiffies + 20*HZ;
2706 timer.data = (unsigned long)ha;
2707 timer.function = qla1280_mailbox_timeout;
2710 spin_unlock_irq(HOST_LOCK);
2711 WRT_REG_WORD(®->host_cmd, HC_SET_HOST_INT);
2712 data = qla1280_debounce_register(®->istatus);
2714 wait_for_completion(&wait);
2715 del_timer_sync(&timer);
2717 spin_lock_irq(HOST_LOCK);
2719 ha->mailbox_wait = NULL;
2721 /* Check for mailbox command timeout. */
2722 if (ha->mailbox_out[0] != MBS_CMD_CMP) {
2723 printk(KERN_WARNING "qla1280_mailbox_command: Command failed, "
2724 "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
2726 mb[0], ha->mailbox_out[0], RD_REG_WORD(®->istatus));
2727 printk(KERN_WARNING "m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
2728 RD_REG_WORD(®->mailbox0), RD_REG_WORD(®->mailbox1),
2729 RD_REG_WORD(®->mailbox2), RD_REG_WORD(®->mailbox3));
2730 printk(KERN_WARNING "m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
2731 RD_REG_WORD(®->mailbox4), RD_REG_WORD(®->mailbox5),
2732 RD_REG_WORD(®->mailbox6), RD_REG_WORD(®->mailbox7));
2736 /* Load return mailbox registers. */
2738 iptr = (uint16_t *) &ha->mailbox_out[0];
2739 mr = MAILBOX_REGISTER_COUNT;
2740 memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
2743 /* Go check for any response interrupts pending. */
2744 qla1280_isr(ha, &done_q);
2747 if (ha->flags.reset_marker)
2748 qla1280_rst_aen(ha);
2751 if (!list_empty(&done_q))
2752 qla1280_done(ha, &done_q);
2756 dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
2757 "0x%x ****\n", mb[0]);
2759 LEAVE("qla1280_mailbox_command");
2765 * Polls ISP for interrupts.
2768 * ha = adapter block pointer.
2771 qla1280_poll(struct scsi_qla_host *ha)
2773 struct device_reg __iomem *reg = ha->iobase;
2777 /* ENTER("qla1280_poll"); */
2779 /* Check for pending interrupts. */
2780 data = RD_REG_WORD(®->istatus);
2781 if (data & RISC_INT)
2782 qla1280_isr(ha, &done_q);
2784 if (!ha->mailbox_wait) {
2785 if (ha->flags.reset_marker)
2786 qla1280_rst_aen(ha);
2789 if (!list_empty(&done_q))
2792 /* LEAVE("qla1280_poll"); */
2797 * Issue SCSI bus reset.
2800 * ha = adapter block pointer.
2801 * bus = SCSI bus number.
2807 qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
2809 uint16_t mb[MAILBOX_REGISTER_COUNT];
2810 uint16_t reset_delay;
2813 dprintk(3, "qla1280_bus_reset: entered\n");
2815 if (qla1280_verbose)
2816 printk(KERN_INFO "scsi(%li:%i): Resetting SCSI BUS\n",
2819 reset_delay = ha->bus_settings[bus].bus_reset_delay;
2820 mb[0] = MBC_BUS_RESET;
2821 mb[1] = reset_delay;
2822 mb[2] = (uint16_t) bus;
2823 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2826 if (ha->bus_settings[bus].failed_reset_count > 2)
2827 ha->bus_settings[bus].scsi_bus_dead = 1;
2828 ha->bus_settings[bus].failed_reset_count++;
2830 spin_unlock_irq(HOST_LOCK);
2831 ssleep(reset_delay);
2832 spin_lock_irq(HOST_LOCK);
2834 ha->bus_settings[bus].scsi_bus_dead = 0;
2835 ha->bus_settings[bus].failed_reset_count = 0;
2836 ha->bus_settings[bus].reset_marker = 0;
2837 /* Issue marker command. */
2838 qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
2842 * We should probably call qla1280_set_target_parameters()
2843 * here as well for all devices on the bus.
2847 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
2849 dprintk(3, "qla1280_bus_reset: exiting normally\n");
2855 * qla1280_device_reset
2856 * Issue bus device reset message to the target.
2859 * ha = adapter block pointer.
2860 * bus = SCSI BUS number.
2867 qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
2869 uint16_t mb[MAILBOX_REGISTER_COUNT];
2872 ENTER("qla1280_device_reset");
2874 mb[0] = MBC_ABORT_TARGET;
2875 mb[1] = (bus ? (target | BIT_7) : target) << 8;
2877 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2879 /* Issue marker command. */
2880 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
2883 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
2885 LEAVE("qla1280_device_reset");
2890 * qla1280_abort_device
2891 * Issue an abort message to the device
2894 * ha = adapter block pointer.
2903 qla1280_abort_device(struct scsi_qla_host *ha, int bus, int target, int lun)
2905 uint16_t mb[MAILBOX_REGISTER_COUNT];
2908 ENTER("qla1280_abort_device");
2910 mb[0] = MBC_ABORT_DEVICE;
2911 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
2912 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2914 /* Issue marker command. */
2915 qla1280_marker(ha, bus, target, lun, MK_SYNC_ID_LUN);
2918 dprintk(2, "qla1280_abort_device: **** FAILED ****\n");
2920 LEAVE("qla1280_abort_device");
2925 * qla1280_abort_command
2926 * Abort command aborts a specified IOCB.
2929 * ha = adapter block pointer.
2930 * sp = SB structure pointer.
2936 qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
2938 uint16_t mb[MAILBOX_REGISTER_COUNT];
2939 unsigned int bus, target, lun;
2942 ENTER("qla1280_abort_command");
2944 bus = SCSI_BUS_32(sp->cmd);
2945 target = SCSI_TCN_32(sp->cmd);
2946 lun = SCSI_LUN_32(sp->cmd);
2948 sp->flags |= SRB_ABORT_PENDING;
2950 mb[0] = MBC_ABORT_COMMAND;
2951 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
2952 mb[2] = handle >> 16;
2953 mb[3] = handle & 0xffff;
2954 status = qla1280_mailbox_command(ha, 0x0f, &mb[0]);
2957 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
2958 sp->flags &= ~SRB_ABORT_PENDING;
2962 LEAVE("qla1280_abort_command");
2967 * qla1280_reset_adapter
2971 * ha = adapter block pointer.
2974 qla1280_reset_adapter(struct scsi_qla_host *ha)
2976 struct device_reg __iomem *reg = ha->iobase;
2978 ENTER("qla1280_reset_adapter");
2980 /* Disable ISP chip */
2981 ha->flags.online = 0;
2982 WRT_REG_WORD(®->ictrl, ISP_RESET);
2983 WRT_REG_WORD(®->host_cmd,
2984 HC_RESET_RISC | HC_RELEASE_RISC | HC_DISABLE_BIOS);
2985 RD_REG_WORD(®->id_l); /* Flush PCI write */
2987 LEAVE("qla1280_reset_adapter");
2991 * Issue marker command.
2992 * Function issues marker IOCB.
2995 * ha = adapter block pointer.
2996 * bus = SCSI BUS number
2999 * type = marker modifier
3002 qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
3004 struct mrk_entry *pkt;
3006 ENTER("qla1280_marker");
3008 /* Get request packet. */
3009 if ((pkt = (struct mrk_entry *) qla1280_req_pkt(ha))) {
3010 pkt->entry_type = MARKER_TYPE;
3011 pkt->lun = (uint8_t) lun;
3012 pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
3013 pkt->modifier = type;
3014 pkt->entry_status = 0;
3016 /* Issue command to ISP */
3017 qla1280_isp_cmd(ha);
3020 LEAVE("qla1280_marker");
3025 * qla1280_64bit_start_scsi
3026 * The start SCSI is responsible for building request packets on
3027 * request ring and modifying ISP input pointer.
3030 * ha = adapter block pointer.
3031 * sp = SB structure pointer.
3034 * 0 = success, was able to issue command.
3036 #ifdef QLA_64BIT_PTR
3038 qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3040 struct device_reg __iomem *reg = ha->iobase;
3041 struct scsi_cmnd *cmd = sp->cmd;
3042 cmd_a64_entry_t *pkt;
3043 struct scatterlist *sg = NULL;
3045 dma_addr_t dma_handle;
3052 ENTER("qla1280_64bit_start_scsi:");
3054 /* Calculate number of entries and segments required. */
3057 sg = (struct scatterlist *) cmd->request_buffer;
3058 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3059 cmd->sc_data_direction);
3062 req_cnt += (seg_cnt - 2) / 5;
3063 if ((seg_cnt - 2) % 5)
3066 } else if (cmd->request_bufflen) { /* If data transfer. */
3072 if ((req_cnt + 2) >= ha->req_q_cnt) {
3073 /* Calculate number of free request entries. */
3074 cnt = RD_REG_WORD(®->mailbox4);
3075 if (ha->req_ring_index < cnt)
3076 ha->req_q_cnt = cnt - ha->req_ring_index;
3079 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3082 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3083 ha->req_q_cnt, seg_cnt);
3085 /* If room for request in request ring. */
3086 if ((req_cnt + 2) >= ha->req_q_cnt) {
3088 dprintk(2, "qla1280_start_scsi: in-ptr=0x%x req_q_cnt="
3089 "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
3094 /* Check for room in outstanding command list. */
3095 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3096 ha->outstanding_cmds[cnt] != 0; cnt++);
3098 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3100 dprintk(2, "qla1280_start_scsi: NO ROOM IN "
3101 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
3105 ha->outstanding_cmds[cnt] = sp;
3106 ha->req_q_cnt -= req_cnt;
3107 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
3109 dprintk(2, "start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
3110 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
3111 dprintk(2, " bus %i, target %i, lun %i\n",
3112 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3113 qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
3116 * Build command packet.
3118 pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
3120 pkt->entry_type = COMMAND_A64_TYPE;
3121 pkt->entry_count = (uint8_t) req_cnt;
3122 pkt->sys_define = (uint8_t) ha->req_ring_index;
3123 pkt->entry_status = 0;
3124 pkt->handle = cpu_to_le32(cnt);
3126 /* Zero out remaining portion of packet. */
3127 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3129 /* Set ISP command timeout. */
3130 pkt->timeout = cpu_to_le16(30);
3132 /* Set device target ID and LUN */
3133 pkt->lun = SCSI_LUN_32(cmd);
3134 pkt->target = SCSI_BUS_32(cmd) ?
3135 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3137 /* Enable simple tag queuing if device supports it. */
3138 if (DEV_SIMPLE_TAGS(cmd->device))
3139 pkt->control_flags |= cpu_to_le16(BIT_3);
3141 /* Load SCSI command packet. */
3142 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3143 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3144 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3146 /* Set transfer direction. */
3147 dir = qla1280_data_direction(cmd);
3148 pkt->control_flags |= cpu_to_le16(dir);
3150 /* Set total data segment count. */
3151 pkt->dseg_count = cpu_to_le16(seg_cnt);
3154 * Load data segments.
3156 if (seg_cnt) { /* If data transfer. */
3157 /* Setup packet address segment pointer. */
3158 dword_ptr = (u32 *)&pkt->dseg_0_address;
3160 if (cmd->use_sg) { /* If scatter gather */
3161 /* Load command entry data segments. */
3162 for (cnt = 0; cnt < 2 && seg_cnt; cnt++, seg_cnt--) {
3163 dma_handle = sg_dma_address(sg);
3164 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3165 if (ha->flags.use_pci_vchannel)
3166 sn_pci_set_vchan(ha->pdev,
3167 (unsigned long *)&dma_handle,
3171 cpu_to_le32(pci_dma_lo32(dma_handle));
3173 cpu_to_le32(pci_dma_hi32(dma_handle));
3174 *dword_ptr++ = cpu_to_le32(sg_dma_len(sg));
3176 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
3177 cpu_to_le32(pci_dma_hi32(dma_handle)),
3178 cpu_to_le32(pci_dma_lo32(dma_handle)),
3179 cpu_to_le32(sg_dma_len(sg)));
3181 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
3182 "command packet data - b %i, t %i, l %i \n",
3183 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3185 qla1280_dump_buffer(5, (char *)pkt,
3186 REQUEST_ENTRY_SIZE);
3189 * Build continuation packets.
3191 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
3192 "remains\n", seg_cnt);
3194 while (seg_cnt > 0) {
3195 /* Adjust ring index. */
3196 ha->req_ring_index++;
3197 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3198 ha->req_ring_index = 0;
3199 ha->request_ring_ptr =
3202 ha->request_ring_ptr++;
3204 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
3206 /* Zero out packet. */
3207 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3209 /* Load packet defaults. */
3210 ((struct cont_a64_entry *) pkt)->entry_type =
3212 ((struct cont_a64_entry *) pkt)->entry_count = 1;
3213 ((struct cont_a64_entry *) pkt)->sys_define =
3214 (uint8_t)ha->req_ring_index;
3215 /* Setup packet address segment pointer. */
3217 (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
3219 /* Load continuation entry data segments. */
3220 for (cnt = 0; cnt < 5 && seg_cnt;
3222 dma_handle = sg_dma_address(sg);
3223 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3224 if (ha->flags.use_pci_vchannel)
3225 sn_pci_set_vchan(ha->pdev,
3226 (unsigned long *)&dma_handle,
3230 cpu_to_le32(pci_dma_lo32(dma_handle));
3232 cpu_to_le32(pci_dma_hi32(dma_handle));
3234 cpu_to_le32(sg_dma_len(sg));
3235 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
3236 cpu_to_le32(pci_dma_hi32(dma_handle)),
3237 cpu_to_le32(pci_dma_lo32(dma_handle)),
3238 cpu_to_le32(sg_dma_len(sg)));
3241 dprintk(5, "qla1280_64bit_start_scsi: "
3242 "continuation packet data - b %i, t "
3243 "%i, l %i \n", SCSI_BUS_32(cmd),
3244 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3245 qla1280_dump_buffer(5, (char *)pkt,
3246 REQUEST_ENTRY_SIZE);
3248 } else { /* No scatter gather data transfer */
3249 dma_handle = pci_map_single(ha->pdev,
3250 cmd->request_buffer,
3251 cmd->request_bufflen,
3252 cmd->sc_data_direction);
3254 sp->saved_dma_handle = dma_handle;
3255 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3256 if (ha->flags.use_pci_vchannel)
3257 sn_pci_set_vchan(ha->pdev,
3258 (unsigned long *)&dma_handle,
3261 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3262 *dword_ptr++ = cpu_to_le32(pci_dma_hi32(dma_handle));
3263 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3265 dprintk(5, "qla1280_64bit_start_scsi: No scatter/"
3266 "gather command packet data - b %i, t %i, "
3267 "l %i \n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3269 qla1280_dump_buffer(5, (char *)pkt,
3270 REQUEST_ENTRY_SIZE);
3272 } else { /* No data transfer */
3273 dprintk(5, "qla1280_64bit_start_scsi: No data, command "
3274 "packet data - b %i, t %i, l %i \n",
3275 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3276 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3278 /* Adjust ring index. */
3279 ha->req_ring_index++;
3280 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3281 ha->req_ring_index = 0;
3282 ha->request_ring_ptr = ha->request_ring;
3284 ha->request_ring_ptr++;
3286 /* Set chip new ring index. */
3288 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
3289 sp->flags |= SRB_SENT;
3291 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3292 /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
3297 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
3299 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
3303 #else /* !QLA_64BIT_PTR */
3306 * qla1280_32bit_start_scsi
3307 * The start SCSI is responsible for building request packets on
3308 * request ring and modifying ISP input pointer.
3310 * The Qlogic firmware interface allows every queue slot to have a SCSI
3311 * command and up to 4 scatter/gather (SG) entries. If we need more
3312 * than 4 SG entries, then continuation entries are used that can
3313 * hold another 7 entries each. The start routine determines if there
3314 * is eought empty slots then build the combination of requests to
3315 * fulfill the OS request.
3318 * ha = adapter block pointer.
3319 * sp = SCSI Request Block structure pointer.
3322 * 0 = success, was able to issue command.
3325 qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3327 struct device_reg __iomem *reg = ha->iobase;
3328 struct scsi_cmnd *cmd = sp->cmd;
3329 struct cmd_entry *pkt;
3330 struct scatterlist *sg = NULL;
3331 uint32_t *dword_ptr;
3336 dma_addr_t dma_handle;
3339 ENTER("qla1280_32bit_start_scsi");
3341 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
3344 /* Calculate number of entries and segments required. */
3348 * We must build an SG list in adapter format, as the kernel's
3349 * SG list cannot be used directly because of data field size
3350 * (__alpha__) differences and the kernel SG list uses virtual
3351 * addresses where we need physical addresses.
3353 sg = (struct scatterlist *) cmd->request_buffer;
3354 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3355 cmd->sc_data_direction);
3358 * if greater than four sg entries then we need to allocate
3359 * continuation entries
3362 req_cnt += (seg_cnt - 4) / 7;
3363 if ((seg_cnt - 4) % 7)
3366 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3367 cmd, seg_cnt, req_cnt);
3368 } else if (cmd->request_bufflen) { /* If data transfer. */
3369 dprintk(3, "No S/G transfer t=%x cmd=%p len=%x CDB=%x\n",
3370 SCSI_TCN_32(cmd), cmd, cmd->request_bufflen,
3374 /* dprintk(1, "No data transfer \n"); */
3378 if ((req_cnt + 2) >= ha->req_q_cnt) {
3379 /* Calculate number of free request entries. */
3380 cnt = RD_REG_WORD(®->mailbox4);
3381 if (ha->req_ring_index < cnt)
3382 ha->req_q_cnt = cnt - ha->req_ring_index;
3385 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3388 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3389 ha->req_q_cnt, seg_cnt);
3390 /* If room for request in request ring. */
3391 if ((req_cnt + 2) >= ha->req_q_cnt) {
3393 dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
3394 "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
3395 ha->req_q_cnt, req_cnt);
3399 /* Check for empty slot in outstanding command list. */
3400 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3401 (ha->outstanding_cmds[cnt] != 0); cnt++) ;
3403 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3405 dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
3406 "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
3410 CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
3411 ha->outstanding_cmds[cnt] = sp;
3412 ha->req_q_cnt -= req_cnt;
3415 * Build command packet.
3417 pkt = (struct cmd_entry *) ha->request_ring_ptr;
3419 pkt->entry_type = COMMAND_TYPE;
3420 pkt->entry_count = (uint8_t) req_cnt;
3421 pkt->sys_define = (uint8_t) ha->req_ring_index;
3422 pkt->entry_status = 0;
3423 pkt->handle = cpu_to_le32(cnt);
3425 /* Zero out remaining portion of packet. */
3426 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3428 /* Set ISP command timeout. */
3429 pkt->timeout = cpu_to_le16(30);
3431 /* Set device target ID and LUN */
3432 pkt->lun = SCSI_LUN_32(cmd);
3433 pkt->target = SCSI_BUS_32(cmd) ?
3434 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3436 /* Enable simple tag queuing if device supports it. */
3437 if (DEV_SIMPLE_TAGS(cmd->device))
3438 pkt->control_flags |= cpu_to_le16(BIT_3);
3440 /* Load SCSI command packet. */
3441 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3442 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3444 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3445 /* Set transfer direction. */
3446 dir = qla1280_data_direction(cmd);
3447 pkt->control_flags |= cpu_to_le16(dir);
3449 /* Set total data segment count. */
3450 pkt->dseg_count = cpu_to_le16(seg_cnt);
3453 * Load data segments.
3456 /* Setup packet address segment pointer. */
3457 dword_ptr = &pkt->dseg_0_address;
3459 if (cmd->use_sg) { /* If scatter gather */
3460 dprintk(3, "Building S/G data segments..\n");
3461 qla1280_dump_buffer(1, (char *)sg, 4 * 16);
3463 /* Load command entry data segments. */
3464 for (cnt = 0; cnt < 4 && seg_cnt; cnt++, seg_cnt--) {
3466 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3468 cpu_to_le32(sg_dma_len(sg));
3469 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3470 (pci_dma_lo32(sg_dma_address(sg))),
3475 * Build continuation packets.
3477 dprintk(3, "S/G Building Continuation"
3478 "...seg_cnt=0x%x remains\n", seg_cnt);
3479 while (seg_cnt > 0) {
3480 /* Adjust ring index. */
3481 ha->req_ring_index++;
3482 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3483 ha->req_ring_index = 0;
3484 ha->request_ring_ptr =
3487 ha->request_ring_ptr++;
3489 pkt = (struct cmd_entry *)ha->request_ring_ptr;
3491 /* Zero out packet. */
3492 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3494 /* Load packet defaults. */
3495 ((struct cont_entry *) pkt)->
3496 entry_type = CONTINUE_TYPE;
3497 ((struct cont_entry *) pkt)->entry_count = 1;
3499 ((struct cont_entry *) pkt)->sys_define =
3500 (uint8_t) ha->req_ring_index;
3502 /* Setup packet address segment pointer. */
3504 &((struct cont_entry *) pkt)->dseg_0_address;
3506 /* Load continuation entry data segments. */
3507 for (cnt = 0; cnt < 7 && seg_cnt;
3510 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3512 cpu_to_le32(sg_dma_len(sg));
3514 "S/G Segment Cont. phys_addr=0x%x, "
3516 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
3517 cpu_to_le32(sg_dma_len(sg)));
3520 dprintk(5, "qla1280_32bit_start_scsi: "
3521 "continuation packet data - "
3522 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
3523 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3524 qla1280_dump_buffer(5, (char *)pkt,
3525 REQUEST_ENTRY_SIZE);
3527 } else { /* No S/G data transfer */
3528 dma_handle = pci_map_single(ha->pdev,
3529 cmd->request_buffer,
3530 cmd->request_bufflen,
3531 cmd->sc_data_direction);
3532 sp->saved_dma_handle = dma_handle;
3534 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3535 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3537 } else { /* No data transfer at all */
3538 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
3539 "packet data - \n");
3540 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3542 dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
3543 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3544 REQUEST_ENTRY_SIZE);
3546 /* Adjust ring index. */
3547 ha->req_ring_index++;
3548 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3549 ha->req_ring_index = 0;
3550 ha->request_ring_ptr = ha->request_ring;
3552 ha->request_ring_ptr++;
3554 /* Set chip new ring index. */
3555 dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
3556 "for pending command\n");
3557 sp->flags |= SRB_SENT;
3559 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3560 /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
3565 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
3567 LEAVE("qla1280_32bit_start_scsi");
3575 * Function is responsible for locking ring and
3576 * getting a zeroed out request packet.
3579 * ha = adapter block pointer.
3582 * 0 = failed to get slot.
3585 qla1280_req_pkt(struct scsi_qla_host *ha)
3587 struct device_reg __iomem *reg = ha->iobase;
3588 request_t *pkt = NULL;
3592 ENTER("qla1280_req_pkt");
3595 * This can be called from interrupt context, damn it!!!
3597 /* Wait for 30 seconds for slot. */
3598 for (timer = 15000000; timer; timer--) {
3599 if (ha->req_q_cnt > 0) {
3600 /* Calculate number of free request entries. */
3601 cnt = RD_REG_WORD(®->mailbox4);
3602 if (ha->req_ring_index < cnt)
3603 ha->req_q_cnt = cnt - ha->req_ring_index;
3606 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3609 /* Found empty request ring slot? */
3610 if (ha->req_q_cnt > 0) {
3612 pkt = ha->request_ring_ptr;
3614 /* Zero out packet. */
3615 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3618 * How can this be right when we have a ring
3621 /* Set system defined field. */
3622 pkt->sys_define = (uint8_t) ha->req_ring_index;
3624 /* Set entry count. */
3625 pkt->entry_count = 1;
3632 /* Check for pending interrupts. */
3637 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
3639 dprintk(3, "qla1280_req_pkt: exiting normally\n");
3646 * Function is responsible for modifying ISP input pointer.
3647 * Releases ring lock.
3650 * ha = adapter block pointer.
3653 qla1280_isp_cmd(struct scsi_qla_host *ha)
3655 struct device_reg __iomem *reg = ha->iobase;
3657 ENTER("qla1280_isp_cmd");
3659 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
3660 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3661 REQUEST_ENTRY_SIZE);
3663 /* Adjust ring index. */
3664 ha->req_ring_index++;
3665 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3666 ha->req_ring_index = 0;
3667 ha->request_ring_ptr = ha->request_ring;
3669 ha->request_ring_ptr++;
3672 * Update request index to mailbox4 (Request Queue In).
3673 * The mmiowb() ensures that this write is ordered with writes by other
3674 * CPUs. Without the mmiowb(), it is possible for the following:
3675 * CPUA posts write of index 5 to mailbox4
3676 * CPUA releases host lock
3677 * CPUB acquires host lock
3678 * CPUB posts write of index 6 to mailbox4
3679 * On PCI bus, order reverses and write of 6 posts, then index 5,
3680 * causing chip to issue full queue of stale commands
3681 * The mmiowb() prevents future writes from crossing the barrier.
3682 * See Documentation/DocBook/deviceiobook.tmpl for more information.
3684 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3687 LEAVE("qla1280_isp_cmd");
3690 /****************************************************************************/
3691 /* Interrupt Service Routine. */
3692 /****************************************************************************/
3694 /****************************************************************************
3696 * Calls I/O done on command completion.
3699 * ha = adapter block pointer.
3700 * done_q = done queue.
3701 ****************************************************************************/
3703 qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
3705 struct device_reg __iomem *reg = ha->iobase;
3706 struct response *pkt;
3707 struct srb *sp = NULL;
3708 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
3713 ENTER("qla1280_isr");
3715 istatus = RD_REG_WORD(®->istatus);
3716 if (!(istatus & (RISC_INT | PCI_INT)))
3719 /* Save mailbox register 5 */
3720 mailbox[5] = RD_REG_WORD(®->mailbox5);
3722 /* Check for mailbox interrupt. */
3724 mailbox[0] = RD_REG_WORD_dmasync(®->semaphore);
3726 if (mailbox[0] & BIT_0) {
3727 /* Get mailbox data. */
3728 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
3731 *wptr++ = RD_REG_WORD(®->mailbox0);
3732 *wptr++ = RD_REG_WORD(®->mailbox1);
3733 *wptr = RD_REG_WORD(®->mailbox2);
3734 if (mailbox[0] != MBA_SCSI_COMPLETION) {
3736 *wptr++ = RD_REG_WORD(®->mailbox3);
3737 *wptr++ = RD_REG_WORD(®->mailbox4);
3739 *wptr++ = RD_REG_WORD(®->mailbox6);
3740 *wptr = RD_REG_WORD(®->mailbox7);
3743 /* Release mailbox registers. */
3745 WRT_REG_WORD(®->semaphore, 0);
3746 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3748 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
3751 /* Handle asynchronous event */
3752 switch (mailbox[0]) {
3753 case MBA_SCSI_COMPLETION: /* Response completion */
3754 dprintk(5, "qla1280_isr: mailbox SCSI response "
3757 if (ha->flags.online) {
3758 /* Get outstanding command index. */
3759 index = mailbox[2] << 16 | mailbox[1];
3761 /* Validate handle. */
3762 if (index < MAX_OUTSTANDING_COMMANDS)
3763 sp = ha->outstanding_cmds[index];
3768 /* Free outstanding command slot. */
3769 ha->outstanding_cmds[index] = NULL;
3771 /* Save ISP completion status */
3772 CMD_RESULT(sp->cmd) = 0;
3774 /* Place block on done queue */
3775 list_add_tail(&sp->list, done_q);
3778 * If we get here we have a real problem!
3781 "qla1280: ISP invalid handle");
3786 case MBA_BUS_RESET: /* SCSI Bus Reset */
3787 ha->flags.reset_marker = 1;
3788 index = mailbox[6] & BIT_0;
3789 ha->bus_settings[index].reset_marker = 1;
3791 printk(KERN_DEBUG "qla1280_isr(): index %i "
3792 "asynchronous BUS_RESET\n", index);
3795 case MBA_SYSTEM_ERR: /* System Error */
3797 "qla1280: ISP System Error - mbx1=%xh, mbx2="
3798 "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
3802 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
3804 "qla1280: ISP Request Transfer Error\n");
3807 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
3809 "qla1280: ISP Response Transfer Error\n");
3812 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
3813 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
3816 case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
3818 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
3821 case MBA_DEVICE_RESET: /* Bus Device Reset */
3822 printk(KERN_INFO "qla1280_isr(): asynchronous "
3823 "BUS_DEVICE_RESET\n");
3825 ha->flags.reset_marker = 1;
3826 index = mailbox[6] & BIT_0;
3827 ha->bus_settings[index].reset_marker = 1;
3830 case MBA_BUS_MODE_CHANGE:
3832 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
3836 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
3837 if (mailbox[0] < MBA_ASYNC_EVENT) {
3839 memcpy((uint16_t *) ha->mailbox_out, wptr,
3840 MAILBOX_REGISTER_COUNT *
3843 if(ha->mailbox_wait != NULL)
3844 complete(ha->mailbox_wait);
3849 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3853 * We will receive interrupts during mailbox testing prior to
3854 * the card being marked online, hence the double check.
3856 if (!(ha->flags.online && !ha->mailbox_wait)) {
3857 dprintk(2, "qla1280_isr: Response pointer Error\n");
3861 if (mailbox[5] >= RESPONSE_ENTRY_CNT)
3864 while (ha->rsp_ring_index != mailbox[5]) {
3865 pkt = ha->response_ring_ptr;
3867 dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
3868 " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
3869 dprintk(5,"qla1280_isr: response packet data\n");
3870 qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
3872 if (pkt->entry_type == STATUS_TYPE) {
3873 if ((le16_to_cpu(pkt->scsi_status) & 0xff)
3874 || pkt->comp_status || pkt->entry_status) {
3875 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3876 "0x%x mailbox[5] = 0x%x, comp_status "
3877 "= 0x%x, scsi_status = 0x%x\n",
3878 ha->rsp_ring_index, mailbox[5],
3879 le16_to_cpu(pkt->comp_status),
3880 le16_to_cpu(pkt->scsi_status));
3883 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3884 "0x%x, mailbox[5] = 0x%x\n",
3885 ha->rsp_ring_index, mailbox[5]);
3886 dprintk(2, "qla1280_isr: response packet data\n");
3887 qla1280_dump_buffer(2, (char *)pkt,
3888 RESPONSE_ENTRY_SIZE);
3891 if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
3892 dprintk(2, "status: Cmd %p, handle %i\n",
3893 ha->outstanding_cmds[pkt->handle]->cmd,
3895 if (pkt->entry_type == STATUS_TYPE)
3896 qla1280_status_entry(ha, pkt, done_q);
3898 qla1280_error_entry(ha, pkt, done_q);
3899 /* Adjust ring index. */
3900 ha->rsp_ring_index++;
3901 if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
3902 ha->rsp_ring_index = 0;
3903 ha->response_ring_ptr = ha->response_ring;
3905 ha->response_ring_ptr++;
3906 WRT_REG_WORD(®->mailbox5, ha->rsp_ring_index);
3911 LEAVE("qla1280_isr");
3916 * Processes asynchronous reset.
3919 * ha = adapter block pointer.
3922 qla1280_rst_aen(struct scsi_qla_host *ha)
3926 ENTER("qla1280_rst_aen");
3928 if (ha->flags.online && !ha->flags.reset_active &&
3929 !ha->flags.abort_isp_active) {
3930 ha->flags.reset_active = 1;
3931 while (ha->flags.reset_marker) {
3932 /* Issue marker command. */
3933 ha->flags.reset_marker = 0;
3934 for (bus = 0; bus < ha->ports &&
3935 !ha->flags.reset_marker; bus++) {
3936 if (ha->bus_settings[bus].reset_marker) {
3937 ha->bus_settings[bus].reset_marker = 0;
3938 qla1280_marker(ha, bus, 0, 0,
3945 LEAVE("qla1280_rst_aen");
3949 #if LINUX_VERSION_CODE < 0x020500
3954 qla1280_get_target_options(struct scsi_cmnd *cmd, struct scsi_qla_host *ha)
3956 unsigned char *result;
3958 int bus, target, lun;
3960 bus = SCSI_BUS_32(cmd);
3961 target = SCSI_TCN_32(cmd);
3962 lun = SCSI_LUN_32(cmd);
3965 * Make sure to not touch anything if someone is using the
3968 if (cmd->use_sg || (CMD_RESULT(cmd) >> 16) != DID_OK || lun)
3971 result = cmd->request_buffer;
3974 n->bus[bus].target[target].parameter.f.enable_wide = 0;
3975 n->bus[bus].target[target].parameter.f.enable_sync = 0;
3976 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
3978 if (result[7] & 0x60)
3979 n->bus[bus].target[target].parameter.f.enable_wide = 1;
3980 if (result[7] & 0x10)
3981 n->bus[bus].target[target].parameter.f.enable_sync = 1;
3982 if ((result[2] >= 3) && (result[4] + 5 > 56) &&
3984 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
3986 dprintk(2, "get_target_options(): wide %i, sync %i, ppr %i\n",
3987 n->bus[bus].target[target].parameter.f.enable_wide,
3988 n->bus[bus].target[target].parameter.f.enable_sync,
3989 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr);
3994 * qla1280_status_entry
3995 * Processes received ISP status entry.
3998 * ha = adapter block pointer.
3999 * pkt = entry pointer.
4000 * done_q = done queue.
4003 qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
4004 struct list_head *done_q)
4006 unsigned int bus, target, lun;
4009 struct scsi_cmnd *cmd;
4010 uint32_t handle = le32_to_cpu(pkt->handle);
4011 uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
4012 uint16_t comp_status = le16_to_cpu(pkt->comp_status);
4014 ENTER("qla1280_status_entry");
4016 /* Validate handle. */
4017 if (handle < MAX_OUTSTANDING_COMMANDS)
4018 sp = ha->outstanding_cmds[handle];
4023 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
4027 /* Free outstanding command slot. */
4028 ha->outstanding_cmds[handle] = NULL;
4032 /* Generate LU queue on cntrl, target, LUN */
4033 bus = SCSI_BUS_32(cmd);
4034 target = SCSI_TCN_32(cmd);
4035 lun = SCSI_LUN_32(cmd);
4037 if (comp_status || scsi_status) {
4038 dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
4039 "0x%x, handle = 0x%x\n", comp_status,
4040 scsi_status, handle);
4043 /* Target busy or queue full */
4044 if ((scsi_status & 0xFF) == SAM_STAT_TASK_SET_FULL ||
4045 (scsi_status & 0xFF) == SAM_STAT_BUSY) {
4046 CMD_RESULT(cmd) = scsi_status & 0xff;
4049 /* Save ISP completion status */
4050 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
4052 if (scsi_status & SS_CHECK_CONDITION) {
4053 if (comp_status != CS_ARS_FAILED) {
4054 uint16_t req_sense_length =
4055 le16_to_cpu(pkt->req_sense_length);
4056 if (req_sense_length < CMD_SNSLEN(cmd))
4057 sense_sz = req_sense_length;
4060 * scsi_cmnd->sense_buffer is
4061 * 64 bytes, why only copy 63?
4062 * This looks wrong! /Jes
4064 sense_sz = CMD_SNSLEN(cmd) - 1;
4066 memcpy(cmd->sense_buffer,
4067 &pkt->req_sense_data, sense_sz);
4070 memset(cmd->sense_buffer + sense_sz, 0,
4071 sizeof(cmd->sense_buffer) - sense_sz);
4073 dprintk(2, "qla1280_status_entry: Check "
4074 "condition Sense data, b %i, t %i, "
4075 "l %i\n", bus, target, lun);
4077 qla1280_dump_buffer(2,
4078 (char *)cmd->sense_buffer,
4083 /* Place command on done queue. */
4084 list_add_tail(&sp->list, done_q);
4086 LEAVE("qla1280_status_entry");
4090 * qla1280_error_entry
4091 * Processes error entry.
4094 * ha = adapter block pointer.
4095 * pkt = entry pointer.
4096 * done_q = done queue.
4099 qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
4100 struct list_head *done_q)
4103 uint32_t handle = le32_to_cpu(pkt->handle);
4105 ENTER("qla1280_error_entry");
4107 if (pkt->entry_status & BIT_3)
4108 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
4109 else if (pkt->entry_status & BIT_2)
4110 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
4111 else if (pkt->entry_status & BIT_1)
4112 dprintk(2, "qla1280_error_entry: FULL flag error\n");
4114 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
4116 /* Validate handle. */
4117 if (handle < MAX_OUTSTANDING_COMMANDS)
4118 sp = ha->outstanding_cmds[handle];
4123 /* Free outstanding command slot. */
4124 ha->outstanding_cmds[handle] = NULL;
4126 /* Bad payload or header */
4127 if (pkt->entry_status & (BIT_3 + BIT_2)) {
4128 /* Bad payload or header, set error status. */
4129 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
4130 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
4131 } else if (pkt->entry_status & BIT_1) { /* FULL flag */
4132 CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
4134 /* Set error status. */
4135 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
4138 /* Place command on done queue. */
4139 list_add_tail(&sp->list, done_q);
4141 #ifdef QLA_64BIT_PTR
4142 else if (pkt->entry_type == COMMAND_A64_TYPE) {
4143 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
4147 LEAVE("qla1280_error_entry");
4152 * Resets ISP and aborts all outstanding commands.
4155 * ha = adapter block pointer.
4161 qla1280_abort_isp(struct scsi_qla_host *ha)
4163 struct device_reg __iomem *reg = ha->iobase;
4169 ENTER("qla1280_abort_isp");
4171 if (ha->flags.abort_isp_active || !ha->flags.online)
4174 ha->flags.abort_isp_active = 1;
4176 /* Disable ISP interrupts. */
4177 qla1280_disable_intrs(ha);
4178 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
4179 RD_REG_WORD(®->id_l);
4181 printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
4183 /* Dequeue all commands in outstanding command list. */
4184 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
4185 struct scsi_cmnd *cmd;
4186 sp = ha->outstanding_cmds[cnt];
4190 CMD_RESULT(cmd) = DID_RESET << 16;
4193 ha->outstanding_cmds[cnt] = NULL;
4195 (*cmd->scsi_done)(cmd);
4201 status = qla1280_load_firmware(ha);
4205 /* Setup adapter based on NVRAM parameters. */
4206 qla1280_nvram_config (ha);
4208 status = qla1280_init_rings(ha);
4212 /* Issue SCSI reset. */
4213 for (bus = 0; bus < ha->ports; bus++)
4214 qla1280_bus_reset(ha, bus);
4216 ha->flags.abort_isp_active = 0;
4220 "qla1280: ISP error recovery failed, board disabled");
4221 qla1280_reset_adapter(ha);
4222 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
4225 LEAVE("qla1280_abort_isp");
4231 * qla1280_debounce_register
4232 * Debounce register.
4235 * port = register address.
4241 qla1280_debounce_register(volatile u16 __iomem * addr)
4246 ret = RD_REG_WORD(addr);
4247 ret2 = RD_REG_WORD(addr);
4254 ret = RD_REG_WORD(addr);
4255 ret2 = RD_REG_WORD(addr);
4256 } while (ret != ret2);
4262 /************************************************************************
4263 * qla1280_check_for_dead_scsi_bus *
4265 * This routine checks for a dead SCSI bus *
4266 ************************************************************************/
4267 #define SET_SXP_BANK 0x0100
4268 #define SCSI_PHASE_INVALID 0x87FF
4270 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
4272 uint16_t config_reg, scsi_control;
4273 struct device_reg __iomem *reg = ha->iobase;
4275 if (ha->bus_settings[bus].scsi_bus_dead) {
4276 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
4277 config_reg = RD_REG_WORD(®->cfg_1);
4278 WRT_REG_WORD(®->cfg_1, SET_SXP_BANK);
4279 scsi_control = RD_REG_WORD(®->scsiControlPins);
4280 WRT_REG_WORD(®->cfg_1, config_reg);
4281 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
4283 if (scsi_control == SCSI_PHASE_INVALID) {
4284 ha->bus_settings[bus].scsi_bus_dead = 1;
4286 CMD_RESULT(cp) = DID_NO_CONNECT << 16;
4287 CMD_HANDLE(cp) = INVALID_HANDLE;
4288 /* ha->actthreads--; */
4290 (*(cp)->scsi_done)(cp);
4292 return 1; /* bus is dead */
4294 ha->bus_settings[bus].scsi_bus_dead = 0;
4295 ha->bus_settings[bus].failed_reset_count = 0;
4298 return 0; /* bus is not dead */
4302 qla1280_get_target_parameters(struct scsi_qla_host *ha,
4303 struct scsi_device *device)
4305 uint16_t mb[MAILBOX_REGISTER_COUNT];
4306 int bus, target, lun;
4308 bus = device->channel;
4309 target = device->id;
4313 mb[0] = MBC_GET_TARGET_PARAMETERS;
4314 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
4316 qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
4319 printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
4322 printk(" Sync: period %d, offset %d",
4323 (mb[3] & 0xff), (mb[3] >> 8));
4326 if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
4331 if (DEV_SIMPLE_TAGS(device))
4332 printk(", Tagged queuing: depth %d", device->queue_depth);
4339 __qla1280_dump_buffer(char *b, int size)
4344 printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
4345 "Bh Ch Dh Eh Fh\n");
4346 printk(KERN_DEBUG "---------------------------------------------"
4347 "------------------\n");
4349 for (cnt = 0; cnt < size;) {
4352 printk("0x%02x", c);
4363 /**************************************************************************
4364 * ql1280_print_scsi_cmd
4366 **************************************************************************/
4368 __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
4370 struct scsi_qla_host *ha;
4371 struct Scsi_Host *host = CMD_HOST(cmd);
4373 /* struct scatterlist *sg; */
4376 ha = (struct scsi_qla_host *)host->hostdata;
4378 sp = (struct srb *)CMD_SP(cmd);
4379 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
4380 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
4381 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
4384 for (i = 0; i < cmd->cmd_len; i++) {
4385 printk("0x%02x ", cmd->cmnd[i]);
4387 printk(" seg_cnt =%d\n", cmd->use_sg);
4388 printk(" request buffer=0x%p, request buffer len=0x%x\n",
4389 cmd->request_buffer, cmd->request_bufflen);
4392 sg = (struct scatterlist *) cmd->request_buffer;
4393 printk(" SG buffer: \n");
4394 qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
4396 printk(" tag=%d, transfersize=0x%x \n",
4397 cmd->tag, cmd->transfersize);
4398 printk(" Pid=%li, SP=0x%p\n", cmd->pid, CMD_SP(cmd));
4399 printk(" underflow size = 0x%x, direction=0x%x\n",
4400 cmd->underflow, cmd->sc_data_direction);
4403 /**************************************************************************
4404 * ql1280_dump_device
4406 **************************************************************************/
4408 ql1280_dump_device(struct scsi_qla_host *ha)
4411 struct scsi_cmnd *cp;
4415 printk(KERN_DEBUG "Outstanding Commands on controller:\n");
4417 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
4418 if ((sp = ha->outstanding_cmds[i]) == NULL)
4420 if ((cp = sp->cmd) == NULL)
4422 qla1280_print_scsi_cmd(1, cp);
4437 struct setup_tokens {
4442 static struct setup_tokens setup_token[] __initdata =
4444 { "nvram", TOKEN_NVRAM },
4445 { "sync", TOKEN_SYNC },
4446 { "wide", TOKEN_WIDE },
4447 { "ppr", TOKEN_PPR },
4448 { "verbose", TOKEN_VERBOSE },
4449 { "debug", TOKEN_DEBUG },
4453 /**************************************************************************
4456 * Handle boot parameters. This really needs to be changed so one
4457 * can specify per adapter parameters.
4458 **************************************************************************/
4460 qla1280_setup(char *s)
4468 while (cp && (ptr = strchr(cp, ':'))) {
4470 if (!strcmp(ptr, "yes")) {
4473 } else if (!strcmp(ptr, "no")) {
4477 val = simple_strtoul(ptr, &ptr, 0);
4479 switch ((toke = qla1280_get_token(cp))) {
4482 driver_setup.no_nvram = 1;
4486 driver_setup.no_sync = 1;
4487 else if (val != 0x10000)
4488 driver_setup.sync_mask = val;
4492 driver_setup.no_wide = 1;
4493 else if (val != 0x10000)
4494 driver_setup.wide_mask = val;
4498 driver_setup.no_ppr = 1;
4499 else if (val != 0x10000)
4500 driver_setup.ppr_mask = val;
4503 qla1280_verbose = val;
4506 printk(KERN_INFO "qla1280: unknown boot option %s\n",
4510 cp = strchr(ptr, ';');
4522 qla1280_get_token(char *str)
4528 len = sizeof(setup_token)/sizeof(struct setup_tokens);
4530 sep = strchr(str, ':');
4533 for (i = 0; i < len; i++){
4535 if (!strncmp(setup_token[i].token, str, (sep - str))) {
4536 ret = setup_token[i].val;
4545 #if LINUX_VERSION_CODE >= 0x020600
4546 static struct scsi_host_template qla1280_driver_template = {
4547 .module = THIS_MODULE,
4548 .proc_name = "qla1280",
4549 .name = "Qlogic ISP 1280/12160",
4550 .info = qla1280_info,
4551 .slave_configure = qla1280_slave_configure,
4552 .queuecommand = qla1280_queuecommand,
4553 .eh_abort_handler = qla1280_eh_abort,
4554 .eh_device_reset_handler= qla1280_eh_device_reset,
4555 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4556 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4557 .bios_param = qla1280_biosparam,
4558 .can_queue = 0xfffff,
4560 .sg_tablesize = SG_ALL,
4562 .use_clustering = ENABLE_CLUSTERING,
4565 static Scsi_Host_Template qla1280_driver_template = {
4566 .proc_name = "qla1280",
4567 .name = "Qlogic ISP 1280/12160",
4568 .detect = qla1280_detect,
4569 .release = qla1280_release,
4570 .info = qla1280_info,
4571 .queuecommand = qla1280_queuecommand,
4572 .eh_abort_handler = qla1280_eh_abort,
4573 .eh_device_reset_handler= qla1280_eh_device_reset,
4574 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4575 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4576 .bios_param = qla1280_biosparam_old,
4577 .can_queue = 0xfffff,
4579 .sg_tablesize = SG_ALL,
4581 .use_clustering = ENABLE_CLUSTERING,
4582 .use_new_eh_code = 1,
4586 static int __devinit
4587 qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4589 int devnum = id->driver_data;
4590 struct qla_boards *bdp = &ql1280_board_tbl[devnum];
4591 struct Scsi_Host *host;
4592 struct scsi_qla_host *ha;
4593 int error = -ENODEV;
4595 /* Bypass all AMI SUBSYS VENDOR IDs */
4596 if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
4598 "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
4602 printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
4603 bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
4605 if (pci_enable_device(pdev)) {
4607 "qla1280: Failed to enabled pci device, aborting.\n");
4611 pci_set_master(pdev);
4614 host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
4617 "qla1280: Failed to register host, aborting.\n");
4618 goto error_disable_device;
4621 ha = (struct scsi_qla_host *)host->hostdata;
4622 memset(ha, 0, sizeof(struct scsi_qla_host));
4625 ha->devnum = devnum; /* specifies microcode load address */
4627 #ifdef QLA_64BIT_PTR
4628 if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) {
4629 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4630 printk(KERN_WARNING "scsi(%li): Unable to set a "
4631 "suitable DMA mask - aborting\n", ha->host_no);
4633 goto error_free_irq;
4636 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4639 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4640 printk(KERN_WARNING "scsi(%li): Unable to set a "
4641 "suitable DMA mask - aborting\n", ha->host_no);
4643 goto error_free_irq;
4647 ha->request_ring = pci_alloc_consistent(ha->pdev,
4648 ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
4650 if (!ha->request_ring) {
4651 printk(KERN_INFO "qla1280: Failed to get request memory\n");
4652 goto error_put_host;
4655 ha->response_ring = pci_alloc_consistent(ha->pdev,
4656 ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
4658 if (!ha->response_ring) {
4659 printk(KERN_INFO "qla1280: Failed to get response memory\n");
4660 goto error_free_request_ring;
4663 ha->ports = bdp->numPorts;
4666 ha->host_no = host->host_no;
4668 host->irq = pdev->irq;
4669 host->max_channel = bdp->numPorts - 1;
4670 host->max_lun = MAX_LUNS - 1;
4671 host->max_id = MAX_TARGETS;
4672 host->max_sectors = 1024;
4673 host->unique_id = host->host_no;
4675 #if LINUX_VERSION_CODE < 0x020545
4676 host->select_queue_depths = qla1280_select_queue_depth;
4681 #if MEMORY_MAPPED_IO
4682 ha->mmpbase = ioremap(pci_resource_start(ha->pdev, 1),
4683 pci_resource_len(ha->pdev, 1));
4685 printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
4686 goto error_free_response_ring;
4689 host->base = (unsigned long)ha->mmpbase;
4690 ha->iobase = (struct device_reg __iomem *)ha->mmpbase;
4692 host->io_port = pci_resource_start(ha->pdev, 0);
4693 if (!request_region(host->io_port, 0xff, "qla1280")) {
4694 printk(KERN_INFO "qla1280: Failed to reserve i/o region "
4695 "0x%04lx-0x%04lx - already in use\n",
4696 host->io_port, host->io_port + 0xff);
4697 goto error_free_response_ring;
4700 ha->iobase = (struct device_reg *)host->io_port;
4703 INIT_LIST_HEAD(&ha->done_q);
4705 /* Disable ISP interrupts. */
4706 qla1280_disable_intrs(ha);
4708 if (request_irq(pdev->irq, qla1280_intr_handler, SA_SHIRQ,
4710 printk("qla1280 : Failed to reserve interrupt %d already "
4711 "in use\n", pdev->irq);
4712 goto error_release_region;
4715 /* load the F/W, read paramaters, and init the H/W */
4716 if (qla1280_initialize_adapter(ha)) {
4717 printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
4718 goto error_free_irq;
4721 /* set our host ID (need to do something about our two IDs) */
4722 host->this_id = ha->bus_settings[0].id;
4724 pci_set_drvdata(pdev, host);
4726 #if LINUX_VERSION_CODE >= 0x020600
4727 error = scsi_add_host(host, &pdev->dev);
4729 goto error_disable_adapter;
4730 scsi_scan_host(host);
4732 scsi_set_pci_device(host, pdev);
4737 #if LINUX_VERSION_CODE >= 0x020600
4738 error_disable_adapter:
4739 qla1280_disable_intrs(ha);
4742 free_irq(pdev->irq, ha);
4743 error_release_region:
4744 #if MEMORY_MAPPED_IO
4745 iounmap(ha->mmpbase);
4747 release_region(host->io_port, 0xff);
4749 error_free_response_ring:
4750 pci_free_consistent(ha->pdev,
4751 ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
4752 ha->response_ring, ha->response_dma);
4753 error_free_request_ring:
4754 pci_free_consistent(ha->pdev,
4755 ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
4756 ha->request_ring, ha->request_dma);
4758 scsi_host_put(host);
4759 error_disable_device:
4760 pci_disable_device(pdev);
4766 static void __devexit
4767 qla1280_remove_one(struct pci_dev *pdev)
4769 struct Scsi_Host *host = pci_get_drvdata(pdev);
4770 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
4772 #if LINUX_VERSION_CODE >= 0x020600
4773 scsi_remove_host(host);
4776 qla1280_disable_intrs(ha);
4778 free_irq(pdev->irq, ha);
4780 #if MEMORY_MAPPED_IO
4781 iounmap(ha->mmpbase);
4783 release_region(host->io_port, 0xff);
4786 pci_free_consistent(ha->pdev,
4787 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4788 ha->request_ring, ha->request_dma);
4789 pci_free_consistent(ha->pdev,
4790 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4791 ha->response_ring, ha->response_dma);
4793 pci_disable_device(pdev);
4795 scsi_host_put(host);
4798 #if LINUX_VERSION_CODE >= 0x020600
4799 static struct pci_driver qla1280_pci_driver = {
4801 .id_table = qla1280_pci_tbl,
4802 .probe = qla1280_probe_one,
4803 .remove = __devexit_p(qla1280_remove_one),
4809 if (sizeof(struct srb) > sizeof(struct scsi_pointer)) {
4811 "qla1280: struct srb too big, aborting\n");
4817 * If we are called as a module, the qla1280 pointer may not be null
4818 * and it would point to our bootup string, just like on the lilo
4819 * command line. IF not NULL, then process this config string with
4823 * To add options at boot time add a line to your lilo.conf file like:
4824 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
4825 * which will result in the first four devices on the first two
4826 * controllers being set to a tagged queue depth of 32.
4829 qla1280_setup(qla1280);
4832 return pci_module_init(&qla1280_pci_driver);
4838 pci_unregister_driver(&qla1280_pci_driver);
4841 module_init(qla1280_init);
4842 module_exit(qla1280_exit);
4845 # define driver_template qla1280_driver_template
4846 # include "scsi_module.c"
4849 MODULE_AUTHOR("Qlogic & Jes Sorensen");
4850 MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
4851 MODULE_LICENSE("GPL");
4852 MODULE_VERSION(QLA1280_VERSION);
4855 * Overrides for Emacs so that we almost follow Linus's tabbing style.
4856 * Emacs will notice this stuff at the end of the file and automatically
4857 * adjust the settings for this buffer only. This must remain at the end
4859 * ---------------------------------------------------------------------------