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.24.4"
21 /*****************************************************************************
23 Rev 3.24.4 June 7, 2004 Christoph Hellwig
24 - restructure firmware loading, cleanup initialization code
25 - prepare support for ISP1020/1040 chips
26 Rev 3.24.3 January 19, 2004, Jes Sorensen
27 - Handle PCI DMA mask settings correctly
28 - Correct order of error handling in probe_one, free_irq should not
29 be called if request_irq failed
30 Rev 3.24.2 January 19, 2004, James Bottomley & Andrew Vasquez
31 - Big endian fixes (James)
32 - Remove bogus IOCB content on zero data transfer commands (Andrew)
33 Rev 3.24.1 January 5, 2004, Jes Sorensen
34 - Initialize completion queue to avoid OOPS on probe
35 - Handle interrupts during mailbox testing
36 Rev 3.24 November 17, 2003, Christoph Hellwig
37 - use struct list_head for completion queue
38 - avoid old Scsi_FOO typedefs
39 - cleanup 2.4 compat glue a bit
40 - use <scsi/scsi_*.h> headers on 2.6 instead of "scsi.h"
41 - make initialization for memory mapped vs port I/O more similar
42 - remove broken pci config space manipulation
44 - this is an almost perfect 2.6 scsi driver now! ;)
45 Rev 3.23.39 December 17, 2003, Jes Sorensen
46 - Delete completion queue from srb if mailbox command failed to
47 to avoid qla1280_done completeting qla1280_error_action's
49 - Reduce arguments for qla1280_done
50 Rev 3.23.38 October 18, 2003, Christoph Hellwig
51 - Convert to new-style hotplugable driver for 2.6
52 - Fix missing scsi_unregister/scsi_host_put on HBA removal
53 - Kill some more cruft
54 Rev 3.23.37 October 1, 2003, Jes Sorensen
55 - Make MMIO depend on CONFIG_X86_VISWS instead of yet another
57 - Clean up locking in probe path
58 Rev 3.23.36 October 1, 2003, Christoph Hellwig
59 - queuecommand only ever receives new commands - clear flags
60 - Reintegrate lost fixes from Linux 2.5
61 Rev 3.23.35 August 14, 2003, Jes Sorensen
63 Rev 3.23.34 July 23, 2003, Jes Sorensen
64 - Remove pointless TRUE/FALSE macros
65 - Clean up vchan handling
66 Rev 3.23.33 July 3, 2003, Jes Sorensen
67 - Don't define register access macros before define determining MMIO.
68 This just happend to work out on ia64 but not elsewhere.
69 - Don't try and read from the card while it is in reset as
70 it won't respond and causes an MCA
71 Rev 3.23.32 June 23, 2003, Jes Sorensen
72 - Basic support for boot time arguments
73 Rev 3.23.31 June 8, 2003, Jes Sorensen
74 - Reduce boot time messages
75 Rev 3.23.30 June 6, 2003, Jes Sorensen
76 - Do not enable sync/wide/ppr before it has been determined
77 that the target device actually supports it
78 - Enable DMA arbitration for multi channel controllers
79 Rev 3.23.29 June 3, 2003, Jes Sorensen
81 Rev 3.23.28 June 3, 2003, Jes Sorensen
82 - Eliminate duplicate marker commands on bus resets
83 - Handle outstanding commands appropriately on bus/device resets
84 Rev 3.23.27 May 28, 2003, Jes Sorensen
85 - Remove bogus input queue code, let the Linux SCSI layer do the work
86 - Clean up NVRAM handling, only read it once from the card
87 - Add a number of missing default nvram parameters
88 Rev 3.23.26 Beta May 28, 2003, Jes Sorensen
89 - Use completion queue for mailbox commands instead of busy wait
90 Rev 3.23.25 Beta May 27, 2003, James Bottomley
91 - Migrate to use new error handling code
92 Rev 3.23.24 Beta May 21, 2003, James Bottomley
94 - Cleanup data direction code
95 Rev 3.23.23 Beta May 12, 2003, Jes Sorensen
96 - Switch to using MMIO instead of PIO
97 Rev 3.23.22 Beta April 15, 2003, Jes Sorensen
98 - Fix PCI parity problem with 12160 during reset.
99 Rev 3.23.21 Beta April 14, 2003, Jes Sorensen
100 - Use pci_map_page()/pci_unmap_page() instead of map_single version.
101 Rev 3.23.20 Beta April 9, 2003, Jes Sorensen
102 - Remove < 2.4.x support
103 - Introduce HOST_LOCK to make the spin lock changes portable.
104 - Remove a bunch of idiotic and unnecessary typedef's
105 - Kill all leftovers of target-mode support which never worked anyway
106 Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
107 - Do qla1280_pci_config() before calling request_irq() and
109 - Use pci_dma_hi32() to handle upper word of DMA addresses instead
111 - Hand correct arguments to free_irq() in case of failure
112 Rev 3.23.18 Beta April 11, 2002, Jes Sorensen
113 - Run source through Lindent and clean up the output
114 Rev 3.23.17 Beta April 11, 2002, Jes Sorensen
115 - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32
116 Rev 3.23.16 Beta March 19, 2002, Jes Sorensen
117 - Rely on mailbox commands generating interrupts - do not
118 run qla1280_isr() from ql1280_mailbox_command()
119 - Remove device_reg_t
120 - Integrate ql12160_set_target_parameters() with 1280 version
121 - Make qla1280_setup() non static
122 - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request
123 sent to the card - this command pauses the firmare!!!
124 Rev 3.23.15 Beta March 19, 2002, Jes Sorensen
125 - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions
126 - Remove a pile of pointless and confusing (srb_t **) and
127 (scsi_lu_t *) typecasts
128 - Explicit mark that we do not use the new error handling (for now)
129 - Remove scsi_qla_host_t and use 'struct' instead
130 - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled,
131 pci_64bit_slot flags which weren't used for anything anyway
132 - Grab host->host_lock while calling qla1280_isr() from abort()
133 - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we
134 do not need to save/restore flags in the interrupt handler
135 - Enable interrupts early (before any mailbox access) in preparation
136 for cleaning up the mailbox handling
137 Rev 3.23.14 Beta March 14, 2002, Jes Sorensen
138 - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace
139 it with proper use of dprintk().
140 - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take
141 a debug level argument to determine if data is to be printed
142 - Add KERN_* info to printk()
143 Rev 3.23.13 Beta March 14, 2002, Jes Sorensen
144 - Significant cosmetic cleanups
145 - Change debug code to use dprintk() and remove #if mess
146 Rev 3.23.12 Beta March 13, 2002, Jes Sorensen
147 - More cosmetic cleanups, fix places treating return as function
148 - use cpu_relax() in qla1280_debounce_register()
149 Rev 3.23.11 Beta March 13, 2002, Jes Sorensen
150 - Make it compile under 2.5.5
151 Rev 3.23.10 Beta October 1, 2001, Jes Sorensen
152 - Do no typecast short * to long * in QL1280BoardTbl, this
153 broke miserably on big endian boxes
154 Rev 3.23.9 Beta September 30, 2001, Jes Sorensen
155 - Remove pre 2.2 hack for checking for reentrance in interrupt handler
156 - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32
157 unsigned int to match the types from struct scsi_cmnd
158 Rev 3.23.8 Beta September 29, 2001, Jes Sorensen
159 - Remove bogus timer_t typedef from qla1280.h
160 - Remove obsolete pre 2.2 PCI setup code, use proper #define's
161 for PCI_ values, call pci_set_master()
162 - Fix memleak of qla1280_buffer on module unload
163 - Only compile module parsing code #ifdef MODULE - should be
164 changed to use individual MODULE_PARM's later
165 - Remove dummy_buffer that was never modified nor printed
166 - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove
167 #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls
168 - Remove \r from print statements, this is Linux, not DOS
169 - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK}
171 - Remove C++ compile hack in header file as Linux driver are not
172 supposed to be compiled as C++
173 - Kill MS_64BITS macro as it makes the code more readable
174 - Remove unnecessary flags.in_interrupts bit
175 Rev 3.23.7 Beta August 20, 2001, Jes Sorensen
176 - Dont' check for set flags on q->q_flag one by one in qla1280_next()
177 - Check whether the interrupt was generated by the QLA1280 before
179 - qla1280_status_entry(): Only zero out part of sense_buffer that
180 is not being copied into
181 - Remove more superflouous typecasts
182 - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy()
183 Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel
184 - Don't walk the entire list in qla1280_putq_t() just to directly
185 grab the pointer to the last element afterwards
186 Rev 3.23.5 Beta August 9, 2001, Jes Sorensen
187 - Don't use SA_INTERRUPT, it's use is deprecated for this kinda driver
188 Rev 3.23.4 Beta August 8, 2001, Jes Sorensen
189 - Set dev->max_sectors to 1024
190 Rev 3.23.3 Beta August 6, 2001, Jes Sorensen
191 - Provide compat macros for pci_enable_device(), pci_find_subsys()
192 and scsi_set_pci_device()
193 - Call scsi_set_pci_device() for all devices
194 - Reduce size of kernel version dependent device probe code
195 - Move duplicate probe/init code to separate function
196 - Handle error if qla1280_mem_alloc() fails
197 - Kill OFFSET() macro and use Linux's PCI definitions instead
198 - Kill private structure defining PCI config space (struct config_reg)
199 - Only allocate I/O port region if not in MMIO mode
200 - Remove duplicate (unused) sanity check of sife of srb_t
201 Rev 3.23.2 Beta August 6, 2001, Jes Sorensen
202 - Change home-brew memset() implementations to use memset()
203 - Remove all references to COMTRACE() - accessing a PC's COM2 serial
204 port directly is not legal under Linux.
205 Rev 3.23.1 Beta April 24, 2001, Jes Sorensen
206 - Remove pre 2.2 kernel support
207 - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat)
208 - Fix MMIO access to use readl/writel instead of directly
209 dereferencing pointers
210 - Nuke MSDOS debugging code
211 - Change true/false data types to int from uint8_t
212 - Use int for counters instead of uint8_t etc.
213 - Clean up size & byte order conversion macro usage
214 Rev 3.23 Beta January 11, 2001 BN Qlogic
215 - Added check of device_id when handling non
216 QLA12160s during detect().
217 Rev 3.22 Beta January 5, 2001 BN Qlogic
218 - Changed queue_task() to schedule_task()
219 for kernels 2.4.0 and higher.
220 Note: 2.4.0-testxx kernels released prior to
221 the actual 2.4.0 kernel release on January 2001
222 will get compile/link errors with schedule_task().
223 Please update your kernel to released 2.4.0 level,
224 or comment lines in this file flagged with 3.22
225 to resolve compile/link error of schedule_task().
226 - Added -DCONFIG_SMP in addition to -D__SMP__
227 in Makefile for 2.4.0 builds of driver as module.
228 Rev 3.21 Beta January 4, 2001 BN Qlogic
229 - Changed criteria of 64/32 Bit mode of HBA
230 operation according to BITS_PER_LONG rather
231 than HBA's NVRAM setting of >4Gig memory bit;
232 so that the HBA auto-configures without the need
233 to setup each system individually.
234 Rev 3.20 Beta December 5, 2000 BN Qlogic
235 - Added priority handling to IA-64 onboard SCSI
236 ISP12160 chip for kernels greater than 2.3.18.
237 - Added irqrestore for qla1280_intr_handler.
238 - Enabled /proc/scsi/qla1280 interface.
239 - Clear /proc/scsi/qla1280 counters in detect().
240 Rev 3.19 Beta October 13, 2000 BN Qlogic
241 - Declare driver_template for new kernel
242 (2.4.0 and greater) scsi initialization scheme.
243 - Update /proc/scsi entry for 2.3.18 kernels and
245 Rev 3.18 Beta October 10, 2000 BN Qlogic
246 - Changed scan order of adapters to map
247 the QLA12160 followed by the QLA1280.
248 Rev 3.17 Beta September 18, 2000 BN Qlogic
249 - Removed warnings for 32 bit 2.4.x compiles
250 - Corrected declared size for request and response
251 DMA addresses that are kept in each ha
252 Rev. 3.16 Beta August 25, 2000 BN Qlogic
253 - Corrected 64 bit addressing issue on IA-64
254 where the upper 32 bits were not properly
255 passed to the RISC engine.
256 Rev. 3.15 Beta August 22, 2000 BN Qlogic
257 - Modified qla1280_setup_chip to properly load
258 ISP firmware for greater that 4 Gig memory on IA-64
259 Rev. 3.14 Beta August 16, 2000 BN Qlogic
260 - Added setting of dma_mask to full 64 bit
261 if flags.enable_64bit_addressing is set in NVRAM
262 Rev. 3.13 Beta August 16, 2000 BN Qlogic
263 - Use new PCI DMA mapping APIs for 2.4.x kernel
264 Rev. 3.12 July 18, 2000 Redhat & BN Qlogic
265 - Added check of pci_enable_device to detect() for 2.3.x
266 - Use pci_resource_start() instead of
267 pdev->resource[0].start in detect() for 2.3.x
268 - Updated driver version
269 Rev. 3.11 July 14, 2000 BN Qlogic
270 - Updated SCSI Firmware to following versions:
273 - Updated driver version to 3.11
274 Rev. 3.10 June 23, 2000 BN Qlogic
275 - Added filtering of AMI SubSys Vendor ID devices
277 - DEBUG_QLA1280 undefined and new version BN Qlogic
278 Rev. 3.08b May 9, 2000 MD Dell
279 - Added logic to check against AMI subsystem vendor ID
280 Rev. 3.08 May 4, 2000 DG Qlogic
281 - Added logic to check for PCI subsystem ID.
282 Rev. 3.07 Apr 24, 2000 DG & BN Qlogic
283 - Updated SCSI Firmware to following versions:
286 Rev. 3.06 Apr 12, 2000 DG & BN Qlogic
287 - Internal revision; not released
288 Rev. 3.05 Mar 28, 2000 DG & BN Qlogic
289 - Edit correction for virt_to_bus and PROC.
290 Rev. 3.04 Mar 28, 2000 DG & BN Qlogic
291 - Merge changes from ia64 port.
292 Rev. 3.03 Mar 28, 2000 BN Qlogic
293 - Increase version to reflect new code drop with compile fix
294 of issue with inclusion of linux/spinlock for 2.3 kernels
295 Rev. 3.02 Mar 15, 2000 BN Qlogic
296 - Merge qla1280_proc_info from 2.10 code base
297 Rev. 3.01 Feb 10, 2000 BN Qlogic
298 - Corrected code to compile on a 2.2.x kernel.
299 Rev. 3.00 Jan 17, 2000 DG Qlogic
300 - Added 64-bit support.
301 Rev. 2.07 Nov 9, 1999 DG Qlogic
302 - Added new routine to set target parameters for ISP12160.
303 Rev. 2.06 Sept 10, 1999 DG Qlogic
304 - Added support for ISP12160 Ultra 3 chip.
305 Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
306 - Modified code to remove errors generated when compiling with
307 Cygnus IA64 Compiler.
308 - Changed conversion of pointers to unsigned longs instead of integers.
309 - Changed type of I/O port variables from uint32_t to unsigned long.
310 - Modified OFFSET macro to work with 64-bit as well as 32-bit.
311 - Changed sprintf and printk format specifiers for pointers to %p.
312 - Changed some int to long type casts where needed in sprintf & printk.
313 - Added l modifiers to sprintf and printk format specifiers for longs.
314 - Removed unused local variables.
315 Rev. 1.20 June 8, 1999 DG, Qlogic
316 Changes to support RedHat release 6.0 (kernel 2.2.5).
317 - Added SCSI exclusive access lock (io_request_lock) when accessing
319 - Added changes for the new LINUX interface template. Some new error
320 handling routines have been added to the template, but for now we
321 will use the old ones.
322 - Initial Beta Release.
323 *****************************************************************************/
326 #include <linux/config.h>
327 #include <linux/module.h>
329 #include <linux/version.h>
330 #include <linux/types.h>
331 #include <linux/string.h>
332 #include <linux/errno.h>
333 #include <linux/kernel.h>
334 #include <linux/ioport.h>
335 #include <linux/delay.h>
336 #include <linux/timer.h>
337 #include <linux/sched.h>
338 #include <linux/pci.h>
339 #include <linux/proc_fs.h>
340 #include <linux/stat.h>
341 #include <linux/slab.h>
342 #include <linux/pci_ids.h>
343 #include <linux/interrupt.h>
344 #include <linux/init.h>
348 #include <asm/byteorder.h>
349 #include <asm/processor.h>
350 #include <asm/types.h>
351 #include <asm/system.h>
353 #if LINUX_VERSION_CODE >= 0x020545
354 #include <scsi/scsi.h>
355 #include <scsi/scsi_cmnd.h>
356 #include <scsi/scsi_device.h>
357 #include <scsi/scsi_host.h>
358 #include <scsi/scsi_tcq.h>
361 #include <linux/blk.h>
363 #include <scsi/scsi_host.h>
367 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
368 #include <asm/sn/io.h>
371 #if LINUX_VERSION_CODE < 0x020407
372 #error "Kernels older than 2.4.7 are no longer supported"
377 * Compile time Options:
378 * 0 - Disable and 1 - Enable
380 #define DEBUG_QLA1280_INTR 0
381 #define DEBUG_PRINT_NVRAM 0
382 #define DEBUG_QLA1280 0
385 * The SGI VISWS is broken and doesn't support MMIO ;-(
387 #ifdef CONFIG_X86_VISWS
388 #define MEMORY_MAPPED_IO 0
390 #define MEMORY_MAPPED_IO 1
393 #define UNIQUE_FW_NAME
395 #include "ql12160_fw.h" /* ISP RISC codes */
396 #include "ql1280_fw.h"
402 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1080
403 #define PCI_DEVICE_ID_QLOGIC_ISP1080 0x1080
405 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1240
406 #define PCI_DEVICE_ID_QLOGIC_ISP1240 0x1240
408 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1280
409 #define PCI_DEVICE_ID_QLOGIC_ISP1280 0x1280
411 #ifndef PCI_DEVICE_ID_QLOGIC_ISP10160
412 #define PCI_DEVICE_ID_QLOGIC_ISP10160 0x1016
414 #ifndef PCI_DEVICE_ID_QLOGIC_ISP12160
415 #define PCI_DEVICE_ID_QLOGIC_ISP12160 0x1216
418 #ifndef PCI_VENDOR_ID_AMI
419 #define PCI_VENDOR_ID_AMI 0x101e
422 #ifndef BITS_PER_LONG
423 #error "BITS_PER_LONG not defined!"
425 #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
426 #define QLA_64BIT_PTR 1
430 #define pci_dma_hi32(a) ((a >> 16) >> 16)
432 #define pci_dma_hi32(a) 0
434 #define pci_dma_lo32(a) (a & 0xffffffff)
436 #define NVRAM_DELAY() udelay(500) /* 2 microseconds */
438 #if LINUX_VERSION_CODE < 0x020500
439 #define HOST_LOCK &io_request_lock
440 #define irqreturn_t void
441 #define IRQ_RETVAL(foo)
442 #define MSG_ORDERED_TAG 1
444 #define DMA_BIDIRECTIONAL SCSI_DATA_UNKNOWN
445 #define DMA_TO_DEVICE SCSI_DATA_WRITE
446 #define DMA_FROM_DEVICE SCSI_DATA_READ
447 #define DMA_NONE SCSI_DATA_NONE
449 #ifndef HAVE_SECTOR_T
450 typedef unsigned int sector_t;
454 scsi_adjust_queue_depth(struct scsi_device *device, int tag, int depth)
457 device->tagged_queue = tag;
458 device->current_tag = 0;
460 device->queue_depth = depth;
462 static inline struct Scsi_Host *scsi_host_alloc(Scsi_Host_Template *t, size_t s)
464 return scsi_register(t, s);
466 static inline void scsi_host_put(struct Scsi_Host *h)
471 #define HOST_LOCK ha->host->host_lock
473 #if LINUX_VERSION_CODE < 0x020600
474 #define DEV_SIMPLE_TAGS(device) device->tagged_queue
476 * Hack around that qla1280_remove_one is called from
477 * qla1280_release in 2.4
482 #define DEV_SIMPLE_TAGS(device) device->simple_tags
484 #if defined(__ia64__) && !defined(ia64_platform_is)
485 #define ia64_platform_is(foo) (!strcmp(x, platform_name))
489 #define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
490 #define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
491 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
492 #define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
493 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
496 static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *);
497 static void qla1280_remove_one(struct pci_dev *);
500 * QLogic Driver Support Function Prototypes.
502 static void qla1280_done(struct scsi_qla_host *);
503 #if LINUX_VERSION_CODE < 0x020545
504 static void qla1280_get_target_options(struct scsi_cmnd *, struct scsi_qla_host *);
506 static int qla1280_get_token(char *);
507 static int qla1280_setup(char *s) __init;
510 * QLogic ISP1280 Hardware Support Function Prototypes.
512 static int qla1280_load_firmware(struct scsi_qla_host *);
513 static int qla1280_init_rings(struct scsi_qla_host *);
514 static int qla1280_nvram_config(struct scsi_qla_host *);
515 static int qla1280_mailbox_command(struct scsi_qla_host *,
516 uint8_t, uint16_t *);
517 static int qla1280_bus_reset(struct scsi_qla_host *, int);
518 static int qla1280_device_reset(struct scsi_qla_host *, int, int);
519 static int qla1280_abort_device(struct scsi_qla_host *, int, int, int);
520 static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int);
521 static int qla1280_abort_isp(struct scsi_qla_host *);
523 static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *);
525 static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *);
527 static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
528 static void qla1280_poll(struct scsi_qla_host *);
529 static void qla1280_reset_adapter(struct scsi_qla_host *);
530 static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
531 static void qla1280_isp_cmd(struct scsi_qla_host *);
532 static void qla1280_isr(struct scsi_qla_host *, struct list_head *);
533 static void qla1280_rst_aen(struct scsi_qla_host *);
534 static void qla1280_status_entry(struct scsi_qla_host *, struct response *,
536 static void qla1280_error_entry(struct scsi_qla_host *, struct response *,
538 static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
539 static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
540 static uint16_t qla1280_debounce_register(volatile uint16_t *);
541 static request_t *qla1280_req_pkt(struct scsi_qla_host *);
542 static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
544 static void qla1280_get_target_parameters(struct scsi_qla_host *,
545 struct scsi_device *);
546 static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int);
549 static struct qla_driver_setup driver_setup __initdata;
552 * convert scsi data direction to request_t control flags
554 static inline uint16_t
555 qla1280_data_direction(struct scsi_cmnd *cmnd)
557 switch(cmnd->sc_data_direction) {
558 case DMA_FROM_DEVICE:
562 case DMA_BIDIRECTIONAL:
563 return BIT_5 | BIT_6;
565 * We could BUG() on default here if one of the four cases aren't
566 * met, but then again if we receive something like that from the
567 * SCSI layer we have more serious problems. This shuts up GCC.
576 static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd);
577 static void __qla1280_dump_buffer(char *, int);
582 * insmod needs to find the variable and make it point to something
585 static char *qla1280;
587 /* insmod qla1280 options=verbose" */
588 MODULE_PARM(qla1280, "s");
590 __setup("qla1280=", qla1280_setup);
595 * We use the scsi_pointer structure that's included with each scsi_command
596 * to overlay our struct srb over it. qla1280_init() checks that a srb is not
597 * bigger than a scsi_pointer.
600 #define CMD_SP(Cmnd) &Cmnd->SCp
601 #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
602 #define CMD_CDBP(Cmnd) Cmnd->cmnd
603 #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
604 #define CMD_SNSLEN(Cmnd) sizeof(Cmnd->sense_buffer)
605 #define CMD_RESULT(Cmnd) Cmnd->result
606 #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
607 #if LINUX_VERSION_CODE < 0x020545
608 #define CMD_REQUEST(Cmnd) Cmnd->request.cmd
610 #define CMD_REQUEST(Cmnd) Cmnd->request->cmd
613 #define CMD_HOST(Cmnd) Cmnd->device->host
614 #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
615 #define SCSI_TCN_32(Cmnd) Cmnd->device->id
616 #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
619 /*****************************************/
620 /* ISP Boards supported by this driver */
621 /*****************************************/
624 unsigned char name[9]; /* Board ID String */
625 int numPorts; /* Number of SCSI ports */
626 unsigned short *fwcode; /* pointer to FW array */
627 unsigned short *fwlen; /* number of words in array */
628 unsigned short *fwstart; /* start address for F/W */
629 unsigned char *fwver; /* Ptr to F/W version array */
632 /* NOTE: qla1280_pci_tbl and ql1280_board_tbl must be in the same order */
633 static struct pci_device_id qla1280_pci_tbl[] = {
634 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP12160,
635 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
636 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1080,
637 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
638 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1240,
639 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
640 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1280,
641 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
642 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP10160,
643 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
646 MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl);
648 static struct qla_boards ql1280_board_tbl[] = {
649 /* Name , Number of ports, FW details */
650 {"QLA12160", 2, &fw12160i_code01[0], &fw12160i_length01,
651 &fw12160i_addr01, &fw12160i_version_str[0]},
652 {"QLA1080", 1, &fw1280ei_code01[0], &fw1280ei_length01,
653 &fw1280ei_addr01, &fw1280ei_version_str[0]},
654 {"QLA1240", 2, &fw1280ei_code01[0], &fw1280ei_length01,
655 &fw1280ei_addr01, &fw1280ei_version_str[0]},
656 {"QLA1280", 2, &fw1280ei_code01[0], &fw1280ei_length01,
657 &fw1280ei_addr01, &fw1280ei_version_str[0]},
658 {"QLA10160", 1, &fw12160i_code01[0], &fw12160i_length01,
659 &fw12160i_addr01, &fw12160i_version_str[0]},
663 static int qla1280_verbose = 1;
664 static int qla1280_buffer_size;
665 static char *qla1280_buffer;
668 static int ql_debug_level = 1;
669 #define dprintk(level, format, a...) \
670 do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
671 #define qla1280_dump_buffer(level, buf, size) \
672 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
673 #define qla1280_print_scsi_cmd(level, cmd) \
674 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
676 #define ql_debug_level 0
677 #define dprintk(level, format, a...) do{}while(0)
678 #define qla1280_dump_buffer(a, b, c) do{}while(0)
679 #define qla1280_print_scsi_cmd(a, b) do{}while(0)
682 #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
683 #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
684 #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
685 #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
688 /*************************************************************************
692 * Return information to handle /proc support for the driver.
694 * buffer - ptrs to a page buffer
697 *************************************************************************/
698 #define PROC_BUF &qla1280_buffer[len]
700 static int qla1280_proc_info(struct Scsi_Host *host, char *buffer,
701 char **start, off_t offset, int length, int inout)
703 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
704 struct qla_boards *bdp = &ql1280_board_tbl[ha->devnum];
712 * if our old buffer is the right size use it otherwise
713 * allocate a new one.
715 if (qla1280_buffer_size != PAGE_SIZE) {
716 /* deallocate this buffer and get a new one */
717 if (qla1280_buffer != NULL) {
718 free_page((unsigned long)qla1280_buffer);
719 qla1280_buffer_size = 0;
721 qla1280_buffer = (char *)get_zeroed_page(GFP_KERNEL);
723 if (qla1280_buffer == NULL) {
724 size = sprintf(buffer, "qla1280 - kmalloc error at line %d\n",
728 /* save the size of our buffer */
729 qla1280_buffer_size = PAGE_SIZE;
731 /* 3.20 clear the buffer we use for proc display */
732 memset(qla1280_buffer, 0, PAGE_SIZE);
734 /* start building the print buffer */
735 size = sprintf(PROC_BUF,
736 "QLogic PCI to SCSI Adapter for ISP 1280/12160:\n"
737 " Firmware version: %2d.%02d.%02d, Driver version %s\n",
738 bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
743 size = sprintf(PROC_BUF, "SCSI Host Adapter Information: %s\n",
746 size = sprintf(PROC_BUF, "Request Queue count= 0x%x, Response "
747 "Queue count= 0x%x\n",
748 REQUEST_ENTRY_CNT, RESPONSE_ENTRY_CNT);
750 size = sprintf(PROC_BUF, "Number of pending commands = 0x%lx\n",
753 size = sprintf(PROC_BUF, "Number of free request entries = %d\n",
756 size = sprintf(PROC_BUF, "\n"); /* 1 */
759 if (len >= qla1280_buffer_size) {
761 "qla1280: Overflow buffer in qla1280_proc.c\n");
764 if (offset > len - 1) {
765 free_page((unsigned long) qla1280_buffer);
766 qla1280_buffer = NULL;
767 qla1280_buffer_size = length = 0;
770 *start = &qla1280_buffer[offset]; /* Start of wanted data */
771 if (len - offset < length) {
772 length = len - offset;
779 static int qla1280_read_nvram(struct scsi_qla_host *ha)
786 ENTER("qla1280_read_nvram");
788 if (driver_setup.no_nvram)
791 printk(KERN_INFO "scsi(%ld): Reading NVRAM\n", ha->host_no);
793 wptr = (uint16_t *)&ha->nvram;
796 for (cnt = 0; cnt < 3; cnt++) {
797 *wptr = qla1280_get_nvram_word(ha, cnt);
798 chksum += *wptr & 0xff;
799 chksum += (*wptr >> 8) & 0xff;
803 if (nv->id0 != 'I' || nv->id1 != 'S' ||
804 nv->id2 != 'P' || nv->id3 != ' ' || nv->version < 1) {
805 dprintk(2, "Invalid nvram ID or version!\n");
808 for (; cnt < sizeof(struct nvram); cnt++) {
809 *wptr = qla1280_get_nvram_word(ha, cnt);
810 chksum += *wptr & 0xff;
811 chksum += (*wptr >> 8) & 0xff;
816 dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
817 " version %i\n", nv->id0, nv->id1, nv->id2, nv->id3,
822 if (!driver_setup.no_nvram)
823 printk(KERN_WARNING "scsi(%ld): Unable to identify or "
824 "validate NVRAM checksum, using default "
825 "settings\n", ha->host_no);
830 /* The firmware interface is, um, interesting, in that the
831 * actual firmware image on the chip is little endian, thus,
832 * the process of taking that image to the CPU would end up
833 * little endian. However, the firmare interface requires it
834 * to be read a word (two bytes) at a time.
836 * The net result of this would be that the word (and
837 * doubleword) quantites in the firmware would be correct, but
838 * the bytes would be pairwise reversed. Since most of the
839 * firmware quantites are, in fact, bytes, we do an extra
840 * le16_to_cpu() in the firmware read routine.
842 * The upshot of all this is that the bytes in the firmware
843 * are in the correct places, but the 16 and 32 bit quantites
844 * are still in little endian format. We fix that up below by
845 * doing extra reverses on them */
846 nv->isp_parameter = cpu_to_le16(nv->isp_parameter);
847 nv->firmware_feature.w = cpu_to_le16(nv->firmware_feature.w);
848 for(i = 0; i < MAX_BUSES; i++) {
849 nv->bus[i].selection_timeout = cpu_to_le16(nv->bus[i].selection_timeout);
850 nv->bus[i].max_queue_depth = cpu_to_le16(nv->bus[i].max_queue_depth);
852 dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
853 LEAVE("qla1280_read_nvram");
858 /**************************************************************************
860 * Return a string describing the driver.
861 **************************************************************************/
863 qla1280_info(struct Scsi_Host *host)
865 static char qla1280_scsi_name_buffer[125];
867 struct scsi_qla_host *ha;
868 struct qla_boards *bdp;
870 bp = &qla1280_scsi_name_buffer[0];
871 ha = (struct scsi_qla_host *)host->hostdata;
872 bdp = &ql1280_board_tbl[ha->devnum];
873 memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
876 "QLogic %s PCI to SCSI Host Adapter\n"
877 " Firmware version: %2d.%02d.%02d, Driver version %s",
878 &bdp->name[0], bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
883 /**************************************************************************
884 * qla1200_queuecommand
885 * Queue a command to the controller.
888 * The mid-level driver tries to ensures that queuecommand never gets invoked
889 * concurrently with itself or the interrupt handler (although the
890 * interrupt handler may call this routine as part of request-completion
891 * handling). Unfortunely, it sometimes calls the scheduler in interrupt
892 * context which is a big NO! NO!.
893 **************************************************************************/
895 qla1280_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
897 struct Scsi_Host *host = cmd->device->host;
898 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
899 struct srb *sp = (struct srb *)&cmd->SCp;
906 qla1280_print_scsi_cmd(5, cmd);
910 * Using 64 bit commands if the PCI bridge doesn't support it is a
911 * bit wasteful, however this should really only happen if one's
912 * PCI controller is completely broken, like the BCM1250. For
913 * sane hardware this is not an issue.
915 status = qla1280_64bit_start_scsi(ha, sp);
917 status = qla1280_32bit_start_scsi(ha, sp);
931 /* timer action for error action processor */
932 static void qla1280_error_wait_timeout(unsigned long __data)
934 struct scsi_cmnd *cmd = (struct scsi_cmnd *)__data;
935 struct srb *sp = (struct srb *)CMD_SP(cmd);
940 static void qla1280_mailbox_timeout(unsigned long __data)
942 struct scsi_qla_host *ha = (struct scsi_qla_host *)__data;
943 struct device_reg *reg;
946 ha->mailbox_out[0] = RD_REG_WORD(®->mailbox0);
947 printk(KERN_ERR "scsi(%ld): mailbox timed out, mailbox0 %04x, "
948 "ictrl %04x, istatus %04x\n", ha->host_no, ha->mailbox_out[0],
949 RD_REG_WORD(®->ictrl), RD_REG_WORD(®->istatus));
950 complete(ha->mailbox_wait);
953 /**************************************************************************
954 * qla1200_error_action
955 * The function will attempt to perform a specified error action and
956 * wait for the results (or time out).
959 * cmd = Linux SCSI command packet of the command that cause the
961 * action = error action to take (see action_t)
967 * Resetting the bus always succeeds - is has to, otherwise the
968 * kernel will panic! Try a surgical technique - sending a BUS
969 * DEVICE RESET message - on the offending target before pulling
970 * the SCSI bus reset line.
971 **************************************************************************/
973 qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
975 struct scsi_qla_host *ha;
976 int bus, target, lun;
979 unsigned char *handle;
981 DECLARE_COMPLETION(wait);
982 struct timer_list timer;
984 ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
986 dprintk(4, "error_action %i, istatus 0x%04x\n", action,
987 RD_REG_WORD(&ha->iobase->istatus));
989 dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
990 RD_REG_WORD(&ha->iobase->host_cmd),
991 RD_REG_WORD(&ha->iobase->ictrl), jiffies);
993 ENTER("qla1280_error_action");
995 printk(KERN_INFO "scsi(%li): Resetting Cmnd=0x%p, "
996 "Handle=0x%p, action=0x%x\n",
997 ha->host_no, cmd, CMD_HANDLE(cmd), action);
1000 printk(KERN_WARNING "(scsi?:?:?:?) Reset called with NULL "
1001 "si_Cmnd pointer, failing.\n");
1002 LEAVE("qla1280_error_action");
1006 ha = (struct scsi_qla_host *)cmd->device->host->hostdata;
1007 sp = (struct srb *)CMD_SP(cmd);
1008 handle = CMD_HANDLE(cmd);
1010 /* Check for pending interrupts. */
1011 data = qla1280_debounce_register(&ha->iobase->istatus);
1013 * The io_request_lock is held when the reset handler is called, hence
1014 * the interrupt handler cannot be running in parallel as it also
1015 * grabs the lock. /Jes
1017 if (data & RISC_INT)
1018 qla1280_isr(ha, &ha->done_q);
1021 * Determine the suggested action that the mid-level driver wants
1024 if (handle == (unsigned char *)INVALID_HANDLE || handle == NULL) {
1025 if(action == ABORT_COMMAND) {
1026 /* we never got this command */
1027 printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
1028 return SUCCESS; /* no action - we don't have command */
1034 bus = SCSI_BUS_32(cmd);
1035 target = SCSI_TCN_32(cmd);
1036 lun = SCSI_LUN_32(cmd);
1038 /* Overloading result. Here it means the success or fail of the
1039 * *issue* of the action. When we return from the routine, it must
1040 * mean the actual success or fail of the action */
1047 if ((sp->flags & SRB_ABORT_PENDING)) {
1049 "scsi(): Command has a pending abort "
1050 "message - ABORT_PENDING.\n");
1051 /* This should technically be impossible since we
1052 * now wait for abort completion */
1056 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
1057 if (sp == ha->outstanding_cmds[i]) {
1058 dprintk(1, "qla1280: RISC aborting command\n");
1059 if (qla1280_abort_command(ha, sp, i) == 0)
1063 * Since we don't know what might
1064 * have happend to the command, it
1065 * is unsafe to remove it from the
1066 * device's queue at this point.
1067 * Wait and let the escalation
1068 * process take care of it.
1071 "scsi(%li:%i:%i:%i): Unable"
1072 " to abort command!\n",
1073 ha->host_no, bus, target, lun);
1080 ha->flags.in_reset = 1;
1081 if (qla1280_verbose)
1083 "scsi(%ld:%d:%d:%d): Queueing abort device "
1084 "command.\n", ha->host_no, bus, target, lun);
1085 if (qla1280_abort_device(ha, bus, target, lun) == 0)
1090 if (qla1280_verbose)
1092 "scsi(%ld:%d:%d:%d): Queueing device reset "
1093 "command.\n", ha->host_no, bus, target, lun);
1094 ha->flags.in_reset = 1;
1095 if (qla1280_device_reset(ha, bus, target) == 0)
1100 if (qla1280_verbose)
1101 printk(KERN_INFO "qla1280(%ld:%d): Issuing BUS "
1102 "DEVICE RESET\n", ha->host_no, bus);
1103 ha->flags.in_reset = 1;
1104 if (qla1280_bus_reset(ha, bus == 0))
1111 if (qla1280_verbose) {
1113 "scsi(%ld): Issued ADAPTER RESET\n",
1115 printk(KERN_INFO "scsi(%ld): I/O processing will "
1116 "continue automatically\n", ha->host_no);
1118 ha->flags.reset_active = 1;
1120 * We restarted all of the commands automatically, so the
1121 * mid-level code can expect completions momentitarily.
1123 if (qla1280_abort_isp(ha) == 0)
1126 ha->flags.reset_active = 0;
1129 if (!list_empty(&ha->done_q))
1131 ha->flags.in_reset = 0;
1133 /* If we didn't manage to issue the action, or we have no
1134 * command to wait for, exit here */
1135 if (result == FAILED || handle == NULL ||
1136 handle == (unsigned char *)INVALID_HANDLE) {
1138 * Clear completion queue to avoid qla1280_done() trying
1139 * to complete the command at a later stage after we
1140 * have exited the current context
1146 /* set up a timer just in case we're really jammed */
1148 timer.expires = jiffies + 4*HZ;
1149 timer.data = (unsigned long)cmd;
1150 timer.function = qla1280_error_wait_timeout;
1153 /* wait for the action to complete (or the timer to expire) */
1154 spin_unlock_irq(HOST_LOCK);
1155 wait_for_completion(&wait);
1156 del_timer_sync(&timer);
1157 spin_lock_irq(HOST_LOCK);
1160 /* the only action we might get a fail for is abort */
1161 if (action == ABORT_COMMAND) {
1162 if(sp->flags & SRB_ABORTED)
1169 dprintk(1, "RESET returning %d\n", result);
1171 LEAVE("qla1280_error_action");
1175 /**************************************************************************
1177 * Abort the specified SCSI command(s).
1178 **************************************************************************/
1180 qla1280_eh_abort(struct scsi_cmnd * cmd)
1182 return qla1280_error_action(cmd, ABORT_COMMAND);
1185 /**************************************************************************
1186 * qla1280_device_reset
1187 * Reset the specified SCSI device
1188 **************************************************************************/
1190 qla1280_eh_device_reset(struct scsi_cmnd *cmd)
1192 return qla1280_error_action(cmd, DEVICE_RESET);
1195 /**************************************************************************
1197 * Reset the specified bus.
1198 **************************************************************************/
1200 qla1280_eh_bus_reset(struct scsi_cmnd *cmd)
1202 return qla1280_error_action(cmd, BUS_RESET);
1205 /**************************************************************************
1206 * qla1280_adapter_reset
1207 * Reset the specified adapter (both channels)
1208 **************************************************************************/
1210 qla1280_eh_adapter_reset(struct scsi_cmnd *cmd)
1212 return qla1280_error_action(cmd, ADAPTER_RESET);
1216 qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1217 sector_t capacity, int geom[])
1219 int heads, sectors, cylinders;
1223 cylinders = (unsigned long)capacity / (heads * sectors);
1224 if (cylinders > 1024) {
1227 cylinders = (unsigned long)capacity / (heads * sectors);
1228 /* if (cylinders > 1023)
1229 cylinders = 1023; */
1234 geom[2] = cylinders;
1239 #if LINUX_VERSION_CODE < 0x020600
1241 qla1280_detect(Scsi_Host_Template *template)
1243 struct pci_device_id *id = &qla1280_pci_tbl[0];
1244 struct pci_dev *pdev = NULL;
1247 if (sizeof(struct srb) > sizeof(Scsi_Pointer)) {
1249 "qla1280: struct srb too big, aborting\n");
1253 if ((DMA_BIDIRECTIONAL != PCI_DMA_BIDIRECTIONAL) ||
1254 (DMA_TO_DEVICE != PCI_DMA_TODEVICE) ||
1255 (DMA_FROM_DEVICE != PCI_DMA_FROMDEVICE) ||
1256 (DMA_NONE != PCI_DMA_NONE)) {
1258 "qla1280: dma direction bits don't match\n");
1264 * If we are called as a module, the qla1280 pointer may not be null
1265 * and it would point to our bootup string, just like on the lilo
1266 * command line. IF not NULL, then process this config string with
1270 * To add options at boot time add a line to your lilo.conf file like:
1271 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
1272 * which will result in the first four devices on the first two
1273 * controllers being set to a tagged queue depth of 32.
1276 qla1280_setup(qla1280);
1279 /* First Initialize QLA12160 on PCI Bus 1 Dev 2 */
1280 while ((pdev = pci_find_device(id->vendor, id->device, pdev))) {
1281 if (pdev->bus->number == 1 && PCI_SLOT(pdev->devfn) == 2) {
1282 if (!qla1280_probe_one(pdev, id))
1288 /* Try and find each different type of adapter we support */
1289 for (id = &qla1280_pci_tbl[0]; id->device; id++) {
1290 while ((pdev = pci_find_device(id->vendor, id->device, pdev))) {
1292 * skip QLA12160 already initialized on
1293 * PCI Bus 1 Dev 2 since we already initialized
1296 if (id->device == PCI_DEVICE_ID_QLOGIC_ISP12160 &&
1297 pdev->bus->number == 1 &&
1298 PCI_SLOT(pdev->devfn) == 2)
1301 if (!qla1280_probe_one(pdev, id))
1310 * This looks a bit ugly as we could just pass down host to
1311 * qla1280_remove_one, but I want to keep qla1280_release purely a wrapper
1312 * around pci_driver::remove as used from 2.6 onwards.
1315 qla1280_release(struct Scsi_Host *host)
1317 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
1319 qla1280_remove_one(ha->pdev);
1324 qla1280_biosparam_old(Disk * disk, kdev_t dev, int geom[])
1326 return qla1280_biosparam(disk->device, NULL, disk->capacity, geom);
1330 qla1280_proc_info_old(char *buffer, char **start, off_t offset, int length,
1331 int hostno, int inout)
1333 struct Scsi_Host *host;
1335 for (host = scsi_hostlist; host; host = host->next) {
1336 if (host->host_no == hostno) {
1337 return qla1280_proc_info(host, buffer, start,
1338 offset, length, inout);
1346 /**************************************************************************
1347 * qla1280_intr_handler
1348 * Handles the H/W interrupt
1349 **************************************************************************/
1351 qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1353 struct scsi_qla_host *ha;
1354 struct device_reg *reg;
1358 ENTER_INTR ("qla1280_intr_handler");
1359 ha = (struct scsi_qla_host *)dev_id;
1361 spin_lock(HOST_LOCK);
1366 WRT_REG_WORD(®->ictrl, 0); /* disable our interrupt. */
1368 data = qla1280_debounce_register(®->istatus);
1369 /* Check for pending interrupts. */
1370 if (data & RISC_INT) {
1371 qla1280_isr(ha, &ha->done_q);
1374 if (!list_empty(&ha->done_q))
1377 spin_unlock(HOST_LOCK);
1379 /* enable our interrupt. */
1380 WRT_REG_WORD(®->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1382 LEAVE_INTR("qla1280_intr_handler");
1383 return IRQ_RETVAL(handled);
1388 qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
1391 uint16_t mb[MAILBOX_REGISTER_COUNT];
1397 mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
1399 /* Set Target Parameters. */
1400 mb[0] = MBC_SET_TARGET_PARAMETERS;
1401 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
1404 mb[2] = (nv->bus[bus].target[target].parameter.c << 8);
1406 if (IS_ISP1x160(ha)) {
1407 mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
1408 mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8) |
1409 nv->bus[bus].target[target].sync_period;
1410 mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) |
1411 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
1414 mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8) |
1415 nv->bus[bus].target[target].sync_period;
1418 status = qla1280_mailbox_command(ha, mr, &mb[0]);
1421 printk(KERN_WARNING "scsi(%ld:%i:%i): "
1422 "qla1280_set_target_parameters() failed\n",
1423 ha->host_no, bus, target);
1428 /**************************************************************************
1429 * qla1280_slave_configure
1432 * Determines the queue depth for a given device. There are two ways
1433 * a queue depth can be obtained for a tagged queueing device. One
1434 * way is the default queue depth which is determined by whether
1435 * If it is defined, then it is used
1436 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1437 * default queue depth (dependent on the number of hardware SCBs).
1438 **************************************************************************/
1440 qla1280_slave_configure(struct scsi_device *device)
1442 struct scsi_qla_host *ha;
1443 int default_depth = 3;
1444 int bus = device->channel;
1445 int target = device->id;
1448 unsigned long flags;
1450 ha = (struct scsi_qla_host *)device->host->hostdata;
1453 if (qla1280_check_for_dead_scsi_bus(ha, bus))
1456 if (device->tagged_supported &&
1457 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1458 scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
1459 ha->bus_settings[bus].hiwat);
1461 scsi_adjust_queue_depth(device, 0, default_depth);
1464 #if LINUX_VERSION_CODE > 0x020500
1465 nv->bus[bus].target[target].parameter.f.enable_sync = device->sdtr;
1466 nv->bus[bus].target[target].parameter.f.enable_wide = device->wdtr;
1467 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
1470 if (driver_setup.no_sync ||
1471 (driver_setup.sync_mask &&
1472 (~driver_setup.sync_mask & (1 << target))))
1473 nv->bus[bus].target[target].parameter.f.enable_sync = 0;
1474 if (driver_setup.no_wide ||
1475 (driver_setup.wide_mask &&
1476 (~driver_setup.wide_mask & (1 << target))))
1477 nv->bus[bus].target[target].parameter.f.enable_wide = 0;
1478 if (IS_ISP1x160(ha)) {
1479 if (driver_setup.no_ppr ||
1480 (driver_setup.ppr_mask &&
1481 (~driver_setup.ppr_mask & (1 << target))))
1482 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
1485 spin_lock_irqsave(HOST_LOCK, flags);
1486 if (nv->bus[bus].target[target].parameter.f.enable_sync)
1487 status = qla1280_set_target_parameters(ha, bus, target);
1488 qla1280_get_target_parameters(ha, device);
1489 spin_unlock_irqrestore(HOST_LOCK, flags);
1493 #if LINUX_VERSION_CODE < 0x020545
1494 /**************************************************************************
1495 * qla1280_select_queue_depth
1497 * Sets the queue depth for each SCSI device hanging off the input
1498 * host adapter. We use a queue depth of 2 for devices that do not
1499 * support tagged queueing.
1500 **************************************************************************/
1502 qla1280_select_queue_depth(struct Scsi_Host *host, struct scsi_device *sdev_q)
1504 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
1505 struct scsi_device *sdev;
1507 ENTER("qla1280_select_queue_depth");
1508 for (sdev = sdev_q; sdev; sdev = sdev->next)
1509 if (sdev->host == host)
1510 qla1280_slave_configure(sdev);
1513 qla1280_check_for_dead_scsi_bus(ha, sdev_q->channel);
1514 LEAVE("qla1280_select_queue_depth");
1520 * Process completed commands.
1523 * ha = adapter block pointer.
1524 * done_q = done queue.
1527 qla1280_done(struct scsi_qla_host *ha)
1530 struct list_head *done_q;
1531 int bus, target, lun;
1532 struct scsi_cmnd *cmd;
1534 ENTER("qla1280_done");
1536 done_q = &ha->done_q;
1538 while (!list_empty(done_q)) {
1539 sp = list_entry(done_q->next, struct srb, list);
1541 list_del(&sp->list);
1544 bus = SCSI_BUS_32(cmd);
1545 target = SCSI_TCN_32(cmd);
1546 lun = SCSI_LUN_32(cmd);
1548 switch ((CMD_RESULT(cmd) >> 16)) {
1550 /* Issue marker command. */
1551 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
1554 sp->flags &= ~SRB_ABORT_PENDING;
1555 sp->flags |= SRB_ABORTED;
1556 if (sp->flags & SRB_TIMEOUT)
1557 CMD_RESULT(sp->cmd) = DID_TIME_OUT << 16;
1563 /* Release memory used for this I/O */
1565 dprintk(3, "S/G unmap_sg cmd=%p\n", cmd);
1567 pci_unmap_sg(ha->pdev, cmd->request_buffer,
1568 cmd->use_sg, cmd->sc_data_direction);
1569 } else if (cmd->request_bufflen) {
1570 /*dprintk(1, "No S/G unmap_single cmd=%x saved_dma_handle=%lx\n",
1571 cmd, sp->saved_dma_handle); */
1573 pci_unmap_page(ha->pdev, sp->saved_dma_handle,
1574 cmd->request_bufflen, cmd->sc_data_direction);
1577 /* Call the mid-level driver interrupt handler */
1578 CMD_HANDLE(sp->cmd) = (unsigned char *)INVALID_HANDLE;
1581 #if LINUX_VERSION_CODE < 0x020500
1582 if (cmd->cmnd[0] == INQUIRY)
1583 qla1280_get_target_options(cmd, ha);
1585 (*(cmd)->scsi_done)(cmd);
1587 if(sp->wait != NULL)
1590 LEAVE("qla1280_done");
1594 * Translates a ISP error to a Linux SCSI error
1597 qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1599 int host_status = DID_ERROR;
1600 uint16_t comp_status = le16_to_cpu(sts->comp_status);
1601 uint16_t state_flags = le16_to_cpu(sts->state_flags);
1602 uint16_t residual_length = le16_to_cpu(sts->residual_length);
1603 uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
1604 #if DEBUG_QLA1280_INTR
1605 static char *reason[] = {
1617 #endif /* DEBUG_QLA1280_INTR */
1619 ENTER("qla1280_return_status");
1621 #if DEBUG_QLA1280_INTR
1623 dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
1628 switch (comp_status) {
1630 host_status = DID_OK;
1634 if (!(state_flags & SF_GOT_BUS))
1635 host_status = DID_NO_CONNECT;
1636 else if (!(state_flags & SF_GOT_TARGET))
1637 host_status = DID_BAD_TARGET;
1638 else if (!(state_flags & SF_SENT_CDB))
1639 host_status = DID_ERROR;
1640 else if (!(state_flags & SF_TRANSFERRED_DATA))
1641 host_status = DID_ERROR;
1642 else if (!(state_flags & SF_GOT_STATUS))
1643 host_status = DID_ERROR;
1644 else if (!(state_flags & SF_GOT_SENSE))
1645 host_status = DID_ERROR;
1649 host_status = DID_RESET;
1653 host_status = DID_ABORT;
1657 host_status = DID_TIME_OUT;
1660 case CS_DATA_OVERRUN:
1661 dprintk(2, "Data overrun 0x%x\n", residual_length);
1662 dprintk(2, "qla1280_isr: response packet data\n");
1663 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
1664 host_status = DID_ERROR;
1667 case CS_DATA_UNDERRUN:
1668 if ((cp->request_bufflen - residual_length) <
1671 "scsi: Underflow detected - retrying "
1673 host_status = DID_ERROR;
1675 host_status = DID_OK;
1679 host_status = DID_ERROR;
1683 #if DEBUG_QLA1280_INTR
1684 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
1685 reason[host_status], scsi_status);
1688 LEAVE("qla1280_return_status");
1690 return (scsi_status & 0xff) | (host_status << 16);
1693 /****************************************************************************/
1694 /* QLogic ISP1280 Hardware Support Functions. */
1695 /****************************************************************************/
1698 * qla2100_enable_intrs
1699 * qla2100_disable_intrs
1702 * ha = adapter block pointer.
1708 qla1280_enable_intrs(struct scsi_qla_host *ha)
1710 struct device_reg *reg;
1713 /* enable risc and host interrupts */
1714 WRT_REG_WORD(®->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1715 RD_REG_WORD(®->ictrl); /* PCI Posted Write flush */
1716 ha->flags.ints_enabled = 1;
1720 qla1280_disable_intrs(struct scsi_qla_host *ha)
1722 struct device_reg *reg;
1725 /* disable risc and host interrupts */
1726 WRT_REG_WORD(®->ictrl, 0);
1727 RD_REG_WORD(®->ictrl); /* PCI Posted Write flush */
1728 ha->flags.ints_enabled = 0;
1732 * qla1280_initialize_adapter
1736 * ha = adapter block pointer.
1741 static int __devinit
1742 qla1280_initialize_adapter(struct scsi_qla_host *ha)
1744 struct device_reg *reg;
1747 #if LINUX_VERSION_CODE > 0x020500
1748 unsigned long flags;
1751 ENTER("qla1280_initialize_adapter");
1753 /* Clear adapter flags. */
1754 ha->flags.online = 0;
1755 ha->flags.disable_host_adapter = 0;
1756 ha->flags.reset_active = 0;
1757 ha->flags.abort_isp_active = 0;
1759 ha->flags.ints_enabled = 0;
1760 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1761 if (ia64_platform_is("sn2")) {
1762 ha->flags.use_pci_vchannel = 1;
1763 driver_setup.no_nvram = 1;
1767 dprintk(1, "Configure PCI space for adapter...\n");
1771 /* Insure mailbox registers are free. */
1772 WRT_REG_WORD(®->semaphore, 0);
1773 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
1774 WRT_REG_WORD(®->host_cmd, HC_CLR_HOST_INT);
1775 RD_REG_WORD(®->host_cmd);
1777 if (qla1280_read_nvram(ha)) {
1778 dprintk(2, "qla1280_initialize_adapter: failed to read "
1782 #if LINUX_VERSION_CODE >= 0x020500
1784 * It's necessary to grab the spin here as qla1280_mailbox_command
1785 * needs to be able to drop the lock unconditionally to wait
1787 * In 2.4 ->detect is called with the io_request_lock held.
1789 spin_lock_irqsave(HOST_LOCK, flags);
1792 status = qla1280_load_firmware(ha);
1794 printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
1799 /* Setup adapter based on NVRAM parameters. */
1800 dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha->host_no);
1801 qla1280_nvram_config(ha);
1803 if (ha->flags.disable_host_adapter) {
1808 status = qla1280_init_rings(ha);
1812 /* Issue SCSI reset, if we can't reset twice then bus is dead */
1813 for (bus = 0; bus < ha->ports; bus++) {
1814 if (!ha->bus_settings[bus].disable_scsi_reset &&
1815 qla1280_bus_reset(ha, bus) &&
1816 qla1280_bus_reset(ha, bus))
1817 ha->bus_settings[bus].scsi_bus_dead = 1;
1820 ha->flags.online = 1;
1822 #if LINUX_VERSION_CODE >= 0x020500
1823 spin_unlock_irqrestore(HOST_LOCK, flags);
1826 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
1828 LEAVE("qla1280_initialize_adapter");
1835 * Checks if present version of RISC firmware is older than
1839 * ha = adapter block pointer.
1842 * 0 = firmware does not need to be loaded.
1845 qla1280_isp_firmware(struct scsi_qla_host *ha)
1847 struct nvram *nv = (struct nvram *) ha->response_ring;
1848 int status = 0; /* dg 2/27 always loads RISC */
1849 uint16_t mb[MAILBOX_REGISTER_COUNT];
1851 ENTER("qla1280_isp_firmware");
1853 dprintk(1, "scsi(%li): Determining if RISC is loaded\n", ha->host_no);
1855 /* Bad NVRAM data, load RISC code. */
1856 if (!ha->nvram_valid) {
1857 ha->flags.disable_risc_code_load = 0;
1859 ha->flags.disable_risc_code_load =
1860 nv->cntr_flags_1.disable_loading_risc_code;
1862 if (ha->flags.disable_risc_code_load) {
1863 dprintk(3, "qla1280_isp_firmware: Telling RISC to verify "
1864 "checksum of loaded BIOS code.\n");
1866 /* Verify checksum of loaded RISC code. */
1867 mb[0] = MBC_VERIFY_CHECKSUM;
1868 /* mb[1] = ql12_risc_code_addr01; */
1869 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1872 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]))) {
1873 /* Start firmware execution. */
1874 dprintk(3, "qla1280_isp_firmware: Startng F/W "
1877 mb[0] = MBC_EXECUTE_FIRMWARE;
1878 /* mb[1] = ql12_risc_code_addr01; */
1879 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1880 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
1882 printk(KERN_INFO "qla1280: RISC checksum failed.\n");
1884 dprintk(1, "qla1280: NVRAM configured to load RISC load.\n");
1889 dprintk(2, "qla1280_isp_firmware: **** Load RISC code ****\n");
1891 LEAVE("qla1280_isp_firmware");
1897 * Test chip for proper operation.
1900 * ha = adapter block pointer.
1906 qla1280_chip_diag(struct scsi_qla_host *ha)
1908 uint16_t mb[MAILBOX_REGISTER_COUNT];
1909 struct device_reg *reg = ha->iobase;
1913 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®->id_l);
1915 dprintk(1, "scsi(%ld): Verifying chip\n", ha->host_no);
1917 /* Soft reset chip and wait for it to finish. */
1918 WRT_REG_WORD(®->ictrl, ISP_RESET);
1921 * We can't do a traditional PCI write flush here by reading
1922 * back the register. The card will not respond once the reset
1923 * is in action and we end up with a machine check exception
1924 * instead. Nothing to do but wait and hope for the best.
1925 * A portable pci_write_flush(pdev) call would be very useful here.
1928 data = qla1280_debounce_register(®->ictrl);
1930 * Yet another QLogic gem ;-(
1932 for (cnt = 1000000; cnt && data & ISP_RESET; cnt--) {
1934 data = RD_REG_WORD(®->ictrl);
1940 /* Reset register cleared by chip reset. */
1941 dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
1943 WRT_REG_WORD(®->cfg_1, 0);
1945 /* Reset RISC and disable BIOS which
1946 allows RISC to execute out of RAM. */
1947 WRT_REG_WORD(®->host_cmd, HC_RESET_RISC |
1948 HC_RELEASE_RISC | HC_DISABLE_BIOS);
1950 RD_REG_WORD(®->id_l); /* Flush PCI write */
1951 data = qla1280_debounce_register(®->mailbox0);
1954 * I *LOVE* this code!
1956 for (cnt = 1000000; cnt && data == MBS_BUSY; cnt--) {
1958 data = RD_REG_WORD(®->mailbox0);
1964 /* Check product ID of chip */
1965 dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
1967 if (RD_REG_WORD(®->mailbox1) != PROD_ID_1 ||
1968 (RD_REG_WORD(®->mailbox2) != PROD_ID_2 &&
1969 RD_REG_WORD(®->mailbox2) != PROD_ID_2a) ||
1970 RD_REG_WORD(®->mailbox3) != PROD_ID_3 ||
1971 RD_REG_WORD(®->mailbox4) != PROD_ID_4) {
1972 printk(KERN_INFO "qla1280: Wrong product ID = "
1973 "0x%x,0x%x,0x%x,0x%x\n",
1974 RD_REG_WORD(®->mailbox1),
1975 RD_REG_WORD(®->mailbox2),
1976 RD_REG_WORD(®->mailbox3),
1977 RD_REG_WORD(®->mailbox4));
1982 * Enable ints early!!!
1984 qla1280_enable_intrs(ha);
1986 dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
1987 /* Wrap Incoming Mailboxes Test. */
1988 mb[0] = MBC_MAILBOX_REGISTER_TEST;
1997 status = qla1280_mailbox_command(ha, 0xff, mb);
2001 if (mb[1] != 0xAAAA || mb[2] != 0x5555 || mb[3] != 0xAA55 ||
2002 mb[4] != 0x55AA || mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
2004 printk(KERN_INFO "qla1280: Failed mbox check\n");
2008 dprintk(3, "qla1280_chip_diag: exiting normally\n");
2011 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
2016 qla1280_load_firmware_pio(struct scsi_qla_host *ha)
2018 uint16_t risc_address, *risc_code_address, risc_code_size;
2019 uint16_t mb[MAILBOX_REGISTER_COUNT], i;
2022 /* Load RISC code. */
2023 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
2024 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
2025 risc_code_size = *ql1280_board_tbl[ha->devnum].fwlen;
2027 for (i = 0; i < risc_code_size; i++) {
2028 mb[0] = MBC_WRITE_RAM_WORD;
2029 mb[1] = risc_address + i;
2030 mb[2] = risc_code_address[i];
2032 err = qla1280_mailbox_command(ha, BIT_0 | BIT_1 | BIT_2, mb);
2034 printk(KERN_ERR "scsi(%li): Failed to load firmware\n",
2043 #define DUMP_IT_BACK 0 /* for debug of RISC loading */
2045 qla1280_load_firmware_dma(struct scsi_qla_host *ha)
2047 uint16_t risc_address, *risc_code_address, risc_code_size;
2048 uint16_t mb[MAILBOX_REGISTER_COUNT], cnt;
2049 int err = 0, num, i;
2054 tbuf = pci_alloc_consistent(ha->pdev, 8000, &p_tbuf);
2059 /* Load RISC code. */
2060 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
2061 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
2062 risc_code_size = *ql1280_board_tbl[ha->devnum].fwlen;
2064 dprintk(1, "%s: DMA RISC code (%i) words\n",
2065 __FUNCTION__, risc_code_size);
2068 while (risc_code_size > 0) {
2069 int warn __attribute__((unused)) = 0;
2073 if (cnt > risc_code_size)
2074 cnt = risc_code_size;
2076 dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
2078 risc_code_address, cnt, num, risc_address);
2079 for(i = 0; i < cnt; i++)
2080 ((uint16_t *)ha->request_ring)[i] =
2081 cpu_to_le16(risc_code_address[i]);
2083 mb[0] = MBC_LOAD_RAM;
2084 mb[1] = risc_address;
2086 mb[3] = ha->request_dma & 0xffff;
2087 mb[2] = (ha->request_dma >> 16) & 0xffff;
2088 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2089 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2090 dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
2091 __FUNCTION__, mb[0],
2092 (void *)(long)ha->request_dma,
2093 mb[6], mb[7], mb[2], mb[3]);
2094 err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
2097 printk(KERN_ERR "scsi(%li): Failed to load partial "
2098 "segment of f\n", ha->host_no);
2103 mb[0] = MBC_DUMP_RAM;
2104 mb[1] = risc_address;
2106 mb[3] = p_tbuf & 0xffff;
2107 mb[2] = (p_tbuf >> 16) & 0xffff;
2108 mb[7] = pci_dma_hi32(p_tbuf) & 0xffff;
2109 mb[6] = pci_dma_hi32(p_tbuf) >> 16;
2111 err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
2115 "Failed to dump partial segment of f/w\n");
2118 sp = (uint8_t *)ha->request_ring;
2119 for (i = 0; i < (cnt << 1); i++) {
2120 if (tbuf[i] != sp[i] && warn++ < 10) {
2121 printk(KERN_ERR "%s: FW compare error @ "
2122 "byte(0x%x) loop#=%x\n",
2123 __FUNCTION__, i, num);
2124 printk(KERN_ERR "%s: FWbyte=%x "
2126 __FUNCTION__, sp[i], tbuf[i]);
2131 risc_address += cnt;
2132 risc_code_size = risc_code_size - cnt;
2133 risc_code_address = risc_code_address + cnt;
2139 pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
2145 qla1280_start_firmware(struct scsi_qla_host *ha)
2147 uint16_t mb[MAILBOX_REGISTER_COUNT];
2150 dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
2153 /* Verify checksum of loaded RISC code. */
2154 mb[0] = MBC_VERIFY_CHECKSUM;
2155 /* mb[1] = ql12_risc_code_addr01; */
2156 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2157 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2159 printk(KERN_ERR "scsi(%li): Failed checksum\n", ha->host_no);
2163 /* Start firmware execution. */
2164 dprintk(1, "%s: start firmware running.\n", __FUNCTION__);
2165 mb[0] = MBC_EXECUTE_FIRMWARE;
2166 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2167 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2169 printk(KERN_ERR "scsi(%li): Failed to start firmware\n",
2177 qla1280_load_firmware(struct scsi_qla_host *ha)
2181 /* If firmware needs to be loaded */
2182 if (!qla1280_isp_firmware(ha)) {
2183 printk(KERN_ERR "scsi(%li): isp_firmware() failed!\n",
2188 err = qla1280_chip_diag(ha);
2192 err = qla1280_load_firmware_pio(ha);
2194 err = qla1280_load_firmware_dma(ha);
2197 err = qla1280_start_firmware(ha);
2206 * ha = adapter block pointer.
2207 * ha->request_ring = request ring virtual address
2208 * ha->response_ring = response ring virtual address
2209 * ha->request_dma = request ring physical address
2210 * ha->response_dma = response ring physical address
2216 qla1280_init_rings(struct scsi_qla_host *ha)
2218 uint16_t mb[MAILBOX_REGISTER_COUNT];
2221 ENTER("qla1280_init_rings");
2223 /* Clear outstanding commands array. */
2224 memset(ha->outstanding_cmds, 0,
2225 sizeof(struct srb *) * MAX_OUTSTANDING_COMMANDS);
2227 /* Initialize request queue. */
2228 ha->request_ring_ptr = ha->request_ring;
2229 ha->req_ring_index = 0;
2230 ha->req_q_cnt = REQUEST_ENTRY_CNT;
2231 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
2232 mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
2233 mb[1] = REQUEST_ENTRY_CNT;
2234 mb[3] = ha->request_dma & 0xffff;
2235 mb[2] = (ha->request_dma >> 16) & 0xffff;
2237 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2238 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2239 if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
2240 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2242 /* Initialize response queue. */
2243 ha->response_ring_ptr = ha->response_ring;
2244 ha->rsp_ring_index = 0;
2245 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
2246 mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
2247 mb[1] = RESPONSE_ENTRY_CNT;
2248 mb[3] = ha->response_dma & 0xffff;
2249 mb[2] = (ha->response_dma >> 16) & 0xffff;
2251 mb[7] = pci_dma_hi32(ha->response_dma) & 0xffff;
2252 mb[6] = pci_dma_hi32(ha->response_dma) >> 16;
2253 status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
2254 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2259 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
2261 LEAVE("qla1280_init_rings");
2266 qla1280_print_settings(struct nvram *nv)
2268 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
2269 nv->bus[0].config_1.initiator_id);
2270 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
2271 nv->bus[1].config_1.initiator_id);
2273 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
2274 nv->bus[0].bus_reset_delay);
2275 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
2276 nv->bus[1].bus_reset_delay);
2278 dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
2279 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
2280 dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
2281 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
2283 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
2284 nv->bus[0].config_2.async_data_setup_time);
2285 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
2286 nv->bus[1].config_2.async_data_setup_time);
2288 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
2289 nv->bus[0].config_2.req_ack_active_negation);
2290 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
2291 nv->bus[1].config_2.req_ack_active_negation);
2293 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
2294 nv->bus[0].config_2.data_line_active_negation);
2295 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
2296 nv->bus[1].config_2.data_line_active_negation);
2298 dprintk(1, "qla1280 : disable loading risc code=%d\n",
2299 nv->cntr_flags_1.disable_loading_risc_code);
2301 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
2302 nv->cntr_flags_1.enable_64bit_addressing);
2304 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
2305 nv->bus[0].selection_timeout);
2306 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
2307 nv->bus[1].selection_timeout);
2309 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
2310 nv->bus[0].max_queue_depth);
2311 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
2312 nv->bus[1].max_queue_depth);
2316 qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target)
2318 struct nvram *nv = &ha->nvram;
2320 nv->bus[bus].target[target].parameter.f.renegotiate_on_error = 1;
2321 nv->bus[bus].target[target].parameter.f.auto_request_sense = 1;
2322 nv->bus[bus].target[target].parameter.f.tag_queuing = 1;
2323 nv->bus[bus].target[target].parameter.f.enable_sync = 1;
2324 #if 1 /* Some SCSI Processors do not seem to like this */
2325 nv->bus[bus].target[target].parameter.f.enable_wide = 1;
2327 if (!IS_ISP1040(ha))
2328 nv->bus[bus].target[target].parameter.f.parity_checking = 1;
2330 nv->bus[bus].target[target].parameter.f.disconnect_allowed = 1;
2331 nv->bus[bus].target[target].execution_throttle =
2332 nv->bus[bus].max_queue_depth - 1;
2334 if (IS_ISP1x160(ha)) {
2335 nv->bus[bus].target[target].flags.flags1x160.device_enable = 1;
2336 nv->bus[bus].target[target].flags.flags1x160.sync_offset = 0x0e;
2337 nv->bus[bus].target[target].sync_period = 9;
2338 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
2339 nv->bus[bus].target[target].ppr_1x160.flags.ppr_options = 2;
2340 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width = 1;
2342 nv->bus[bus].target[target].flags.flags1x80.device_enable = 1;
2343 nv->bus[bus].target[target].flags.flags1x80.sync_offset = 12;
2344 nv->bus[bus].target[target].sync_period = 10;
2349 qla1280_set_defaults(struct scsi_qla_host *ha)
2351 struct nvram *nv = &ha->nvram;
2354 dprintk(1, "Using defaults for NVRAM: \n");
2355 memset(nv, 0, sizeof(struct nvram));
2357 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
2358 nv->firmware_feature.f.enable_fast_posting = 1;
2359 nv->firmware_feature.f.disable_synchronous_backoff = 1;
2360 nv->termination.f.scsi_bus_0_control = 3;
2361 nv->termination.f.scsi_bus_1_control = 3;
2362 nv->termination.f.auto_term_support = 1;
2365 * Set default FIFO magic - What appropriate values would be here
2366 * is unknown. This is what I have found testing with 12160s.
2368 * Now, I would love the magic decoder ring for this one, the
2369 * header file provided by QLogic seems to be bogus or incomplete
2372 nv->isp_config.c = ISP_CFG1_BENAB|ISP_CFG1_F128;
2373 if (IS_ISP1x160(ha))
2374 nv->isp_parameter = 0x01; /* fast memory enable */
2376 for (bus = 0; bus < MAX_BUSES; bus++) {
2377 nv->bus[bus].config_1.initiator_id = 7;
2378 nv->bus[bus].config_2.req_ack_active_negation = 1;
2379 nv->bus[bus].config_2.data_line_active_negation = 1;
2380 nv->bus[bus].selection_timeout = 250;
2381 nv->bus[bus].max_queue_depth = 256;
2383 if (IS_ISP1040(ha)) {
2384 nv->bus[bus].bus_reset_delay = 3;
2385 nv->bus[bus].config_2.async_data_setup_time = 6;
2386 nv->bus[bus].retry_delay = 1;
2388 nv->bus[bus].bus_reset_delay = 5;
2389 nv->bus[bus].config_2.async_data_setup_time = 8;
2392 for (target = 0; target < MAX_TARGETS; target++)
2393 qla1280_set_target_defaults(ha, bus, target);
2398 qla1280_config_target(struct scsi_qla_host *ha, int bus, int target)
2400 struct nvram *nv = &ha->nvram;
2401 uint16_t mb[MAILBOX_REGISTER_COUNT];
2404 /* Set Target Parameters. */
2405 mb[0] = MBC_SET_TARGET_PARAMETERS;
2406 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
2410 * Do not enable wide, sync, and ppr for the initial
2411 * INQUIRY run. We enable this later if we determine
2412 * the target actually supports it.
2414 nv->bus[bus].target[target].parameter.f.
2415 auto_request_sense = 1;
2416 nv->bus[bus].target[target].parameter.f.
2417 stop_queue_on_check = 0;
2419 if (IS_ISP1x160(ha))
2420 nv->bus[bus].target[target].ppr_1x160.
2421 flags.enable_ppr = 0;
2424 * No sync, wide, etc. while probing
2426 mb[2] = (nv->bus[bus].target[target].parameter.c << 8) &
2427 ~(TP_SYNC /*| TP_WIDE | TP_PPR*/);
2429 if (IS_ISP1x160(ha))
2430 mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
2432 mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
2433 mb[3] |= nv->bus[bus].target[target].sync_period;
2435 status = qla1280_mailbox_command(ha, BIT_3 | BIT_2 | BIT_1 | BIT_0, &mb[0]);
2437 /* Save Tag queuing enable flag. */
2438 mb[0] = BIT_0 << target;
2439 if (nv->bus[bus].target[target].parameter.f.tag_queuing)
2440 ha->bus_settings[bus].qtag_enables |= mb[0];
2442 /* Save Device enable flag. */
2443 if (IS_ISP1x160(ha)) {
2444 if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
2445 ha->bus_settings[bus].device_enables |= mb[0];
2446 ha->bus_settings[bus].lun_disables |= 0;
2448 if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
2449 ha->bus_settings[bus].device_enables |= mb[0];
2450 /* Save LUN disable flag. */
2451 if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
2452 ha->bus_settings[bus].lun_disables |= mb[0];
2455 /* Set Device Queue Parameters. */
2456 for (lun = 0; lun < MAX_LUNS; lun++) {
2457 mb[0] = MBC_SET_DEVICE_QUEUE;
2458 mb[1] = (uint16_t)(bus ? target | BIT_7 : target);
2459 mb[1] = mb[1] << 8 | lun;
2460 mb[2] = nv->bus[bus].max_queue_depth;
2461 mb[3] = nv->bus[bus].target[target].execution_throttle;
2462 status |= qla1280_mailbox_command(ha, 0x0f, &mb[0]);
2469 qla1280_config_bus(struct scsi_qla_host *ha, int bus)
2471 struct nvram *nv = &ha->nvram;
2472 uint16_t mb[MAILBOX_REGISTER_COUNT];
2475 /* SCSI Reset Disable. */
2476 ha->bus_settings[bus].disable_scsi_reset =
2477 nv->bus[bus].config_1.scsi_reset_disable;
2480 ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
2481 mb[0] = MBC_SET_INITIATOR_ID;
2482 mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
2483 ha->bus_settings[bus].id;
2484 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2487 ha->bus_settings[bus].bus_reset_delay =
2488 nv->bus[bus].bus_reset_delay;
2490 /* Command queue depth per device. */
2491 ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
2493 /* Set target parameters. */
2494 for (target = 0; target < MAX_TARGETS; target++)
2495 status |= qla1280_config_target(ha, bus, target);
2501 qla1280_nvram_config(struct scsi_qla_host *ha)
2503 struct device_reg *reg = ha->iobase;
2504 struct nvram *nv = &ha->nvram;
2505 int bus, target, status = 0;
2506 uint16_t mb[MAILBOX_REGISTER_COUNT];
2509 ENTER("qla1280_nvram_config");
2511 if (ha->nvram_valid) {
2512 /* Always force AUTO sense for LINUX SCSI */
2513 for (bus = 0; bus < MAX_BUSES; bus++)
2514 for (target = 0; target < MAX_TARGETS; target++) {
2515 nv->bus[bus].target[target].parameter.f.
2516 auto_request_sense = 1;
2519 qla1280_set_defaults(ha);
2522 qla1280_print_settings(nv);
2524 /* Disable RISC load of firmware. */
2525 ha->flags.disable_risc_code_load =
2526 nv->cntr_flags_1.disable_loading_risc_code;
2528 if (IS_ISP1040(ha)) {
2529 uint16_t hwrev, cfg1, cdma_conf, ddma_conf;
2531 hwrev = RD_REG_WORD(®->cfg_0) & ISP_CFG0_HWMSK;
2533 cfg1 = RD_REG_WORD(®->cfg_1);
2534 cdma_conf = RD_REG_WORD(®->cdma_cfg);
2535 ddma_conf = RD_REG_WORD(®->ddma_cfg);
2537 /* Busted fifo, says mjacob. */
2538 if (hwrev == ISP_CFG0_1040A)
2539 WRT_REG_WORD(®->cfg_1, cfg1 | ISP_CFG1_F64);
2541 WRT_REG_WORD(®->cfg_1, cfg1 | ISP_CFG1_F64 | ISP_CFG1_BENAB);
2543 WRT_REG_WORD(®->cdma_cfg, cdma_conf | CDMA_CONF_BENAB);
2544 WRT_REG_WORD(®->ddma_cfg, cdma_conf | DDMA_CONF_BENAB);
2546 /* Set ISP hardware DMA burst */
2547 mb[0] = nv->isp_config.c;
2548 /* Enable DMA arbitration on dual channel controllers */
2551 WRT_REG_WORD(®->cfg_1, mb[0]);
2553 /* Set SCSI termination. */
2554 WRT_REG_WORD(®->gpio_enable, (BIT_3 + BIT_2 + BIT_1 + BIT_0));
2555 mb[0] = nv->termination.c & (BIT_3 + BIT_2 + BIT_1 + BIT_0);
2556 WRT_REG_WORD(®->gpio_data, mb[0]);
2559 /* ISP parameter word. */
2560 mb[0] = MBC_SET_SYSTEM_PARAMETER;
2561 mb[1] = nv->isp_parameter;
2562 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2564 if (IS_ISP1x40(ha)) {
2565 /* clock rate - for qla1240 and older, only */
2566 mb[0] = MBC_SET_CLOCK_RATE;
2568 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2571 /* Firmware feature word. */
2572 mb[0] = MBC_SET_FIRMWARE_FEATURES;
2573 mask = BIT_5 | BIT_1 | BIT_0;
2574 mb[1] = le16_to_cpu(nv->firmware_feature.w) & (mask);
2575 #if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
2576 if (ia64_platform_is("sn2")) {
2577 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
2578 "workaround\n", ha->host_no);
2582 status |= qla1280_mailbox_command(ha, mask, &mb[0]);
2584 /* Retry count and delay. */
2585 mb[0] = MBC_SET_RETRY_COUNT;
2586 mb[1] = nv->bus[0].retry_count;
2587 mb[2] = nv->bus[0].retry_delay;
2588 mb[6] = nv->bus[1].retry_count;
2589 mb[7] = nv->bus[1].retry_delay;
2590 status |= qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 |
2591 BIT_1 | BIT_0, &mb[0]);
2593 /* ASYNC data setup time. */
2594 mb[0] = MBC_SET_ASYNC_DATA_SETUP;
2595 mb[1] = nv->bus[0].config_2.async_data_setup_time;
2596 mb[2] = nv->bus[1].config_2.async_data_setup_time;
2597 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2599 /* Active negation states. */
2600 mb[0] = MBC_SET_ACTIVE_NEGATION;
2602 if (nv->bus[0].config_2.req_ack_active_negation)
2604 if (nv->bus[0].config_2.data_line_active_negation)
2607 if (nv->bus[1].config_2.req_ack_active_negation)
2609 if (nv->bus[1].config_2.data_line_active_negation)
2611 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2613 mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
2614 mb[1] = 2; /* Reset SCSI bus and return all outstanding IO */
2615 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2618 mb[0] = MBC_SET_PCI_CONTROL;
2619 mb[1] = 2; /* Data DMA Channel Burst Enable */
2620 mb[2] = 2; /* Command DMA Channel Burst Enable */
2621 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2623 mb[0] = MBC_SET_TAG_AGE_LIMIT;
2625 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2627 /* Selection timeout. */
2628 mb[0] = MBC_SET_SELECTION_TIMEOUT;
2629 mb[1] = nv->bus[0].selection_timeout;
2630 mb[2] = nv->bus[1].selection_timeout;
2631 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2633 for (bus = 0; bus < ha->ports; bus++)
2634 status |= qla1280_config_bus(ha, bus);
2637 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
2639 LEAVE("qla1280_nvram_config");
2644 * Get NVRAM data word
2645 * Calculates word position in NVRAM and calls request routine to
2646 * get the word from NVRAM.
2649 * ha = adapter block pointer.
2650 * address = NVRAM word address.
2656 qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
2661 nv_cmd = address << 16;
2662 nv_cmd |= NV_READ_OP;
2664 data = le16_to_cpu(qla1280_nvram_request(ha, nv_cmd));
2666 dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
2674 * Sends read command to NVRAM and gets data from NVRAM.
2677 * ha = adapter block pointer.
2678 * nv_cmd = Bit 26 = start bit
2679 * Bit 25, 24 = opcode
2680 * Bit 23-16 = address
2681 * Bit 15-0 = write data
2687 qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
2689 struct device_reg *reg = ha->iobase;
2694 /* Send command to NVRAM. */
2697 for (cnt = 0; cnt < 11; cnt++) {
2698 if (nv_cmd & BIT_31)
2699 qla1280_nv_write(ha, NV_DATA_OUT);
2701 qla1280_nv_write(ha, 0);
2705 /* Read data from NVRAM. */
2707 for (cnt = 0; cnt < 16; cnt++) {
2708 WRT_REG_WORD(®->nvram, (NV_SELECT | NV_CLOCK));
2709 RD_REG_WORD(®->id_l); /* Flush PCI write */
2712 reg_data = RD_REG_WORD(®->nvram);
2713 if (reg_data & NV_DATA_IN)
2715 WRT_REG_WORD(®->nvram, NV_SELECT);
2716 RD_REG_WORD(®->id_l); /* Flush PCI write */
2720 /* Deselect chip. */
2722 WRT_REG_WORD(®->nvram, NV_DESELECT);
2723 RD_REG_WORD(®->id_l); /* Flush PCI write */
2730 qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
2732 struct device_reg *reg = ha->iobase;
2734 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2735 RD_REG_WORD(®->id_l); /* Flush PCI write */
2737 WRT_REG_WORD(®->nvram, data | NV_SELECT | NV_CLOCK);
2738 RD_REG_WORD(®->id_l); /* Flush PCI write */
2740 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2741 RD_REG_WORD(®->id_l); /* Flush PCI write */
2747 * Issue mailbox command and waits for completion.
2750 * ha = adapter block pointer.
2751 * mr = mailbox registers to load.
2752 * mb = data pointer for mailbox registers.
2755 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
2761 qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
2763 struct device_reg *reg = ha->iobase;
2769 uint16_t *optr, *iptr;
2771 DECLARE_COMPLETION(wait);
2772 struct timer_list timer;
2774 ENTER("qla1280_mailbox_command");
2776 if (ha->mailbox_wait) {
2777 printk(KERN_ERR "Warning mailbox wait already in use!\n");
2779 ha->mailbox_wait = &wait;
2782 * We really should start out by verifying that the mailbox is
2783 * available before starting sending the command data
2785 /* Load mailbox registers. */
2786 optr = (uint16_t *) ®->mailbox0;
2788 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
2790 WRT_REG_WORD(optr, (*iptr));
2798 /* Issue set host interrupt command. */
2800 /* set up a timer just in case we're really jammed */
2802 timer.expires = jiffies + 20*HZ;
2803 timer.data = (unsigned long)ha;
2804 timer.function = qla1280_mailbox_timeout;
2807 spin_unlock_irq(HOST_LOCK);
2808 WRT_REG_WORD(®->host_cmd, HC_SET_HOST_INT);
2809 data = qla1280_debounce_register(®->istatus);
2811 wait_for_completion(&wait);
2812 del_timer_sync(&timer);
2814 spin_lock_irq(HOST_LOCK);
2816 ha->mailbox_wait = NULL;
2818 /* Check for mailbox command timeout. */
2819 if (ha->mailbox_out[0] != MBS_CMD_CMP) {
2820 printk(KERN_WARNING "qla1280_mailbox_command: Command failed, "
2821 "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
2823 mb[0], ha->mailbox_out[0], RD_REG_WORD(®->istatus));
2824 printk(KERN_WARNING "m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
2825 RD_REG_WORD(®->mailbox0), RD_REG_WORD(®->mailbox1),
2826 RD_REG_WORD(®->mailbox2), RD_REG_WORD(®->mailbox3));
2827 printk(KERN_WARNING "m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
2828 RD_REG_WORD(®->mailbox4), RD_REG_WORD(®->mailbox5),
2829 RD_REG_WORD(®->mailbox6), RD_REG_WORD(®->mailbox7));
2833 /* Load return mailbox registers. */
2835 iptr = (uint16_t *) &ha->mailbox_out[0];
2836 mr = MAILBOX_REGISTER_COUNT;
2837 memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
2840 /* Go check for any response interrupts pending. */
2841 qla1280_isr(ha, &done_q);
2844 if (ha->flags.reset_marker)
2845 qla1280_rst_aen(ha);
2848 if (!list_empty(&done_q))
2849 qla1280_done(ha, &done_q);
2853 dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
2854 "0x%x ****\n", mb[0]);
2856 LEAVE("qla1280_mailbox_command");
2862 * Polls ISP for interrupts.
2865 * ha = adapter block pointer.
2868 qla1280_poll(struct scsi_qla_host *ha)
2870 struct device_reg *reg = ha->iobase;
2874 /* ENTER("qla1280_poll"); */
2876 /* Check for pending interrupts. */
2877 data = RD_REG_WORD(®->istatus);
2878 if (data & RISC_INT)
2879 qla1280_isr(ha, &done_q);
2881 if (!ha->mailbox_wait) {
2882 if (ha->flags.reset_marker)
2883 qla1280_rst_aen(ha);
2886 if (!list_empty(&done_q))
2889 /* LEAVE("qla1280_poll"); */
2894 * Issue SCSI bus reset.
2897 * ha = adapter block pointer.
2898 * bus = SCSI bus number.
2904 qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
2906 uint16_t mb[MAILBOX_REGISTER_COUNT];
2907 uint16_t reset_delay;
2910 dprintk(3, "qla1280_bus_reset: entered\n");
2912 if (qla1280_verbose)
2913 printk(KERN_INFO "scsi(%li:%i): Resetting SCSI BUS\n",
2916 reset_delay = ha->bus_settings[bus].bus_reset_delay;
2917 mb[0] = MBC_BUS_RESET;
2918 mb[1] = reset_delay;
2919 mb[2] = (uint16_t) bus;
2920 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2923 if (ha->bus_settings[bus].failed_reset_count > 2)
2924 ha->bus_settings[bus].scsi_bus_dead = 1;
2925 ha->bus_settings[bus].failed_reset_count++;
2927 spin_unlock_irq(HOST_LOCK);
2928 schedule_timeout(reset_delay * HZ);
2929 spin_lock_irq(HOST_LOCK);
2931 ha->bus_settings[bus].scsi_bus_dead = 0;
2932 ha->bus_settings[bus].failed_reset_count = 0;
2933 ha->bus_settings[bus].reset_marker = 0;
2934 /* Issue marker command. */
2935 qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
2939 * We should probably call qla1280_set_target_parameters()
2940 * here as well for all devices on the bus.
2944 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
2946 dprintk(3, "qla1280_bus_reset: exiting normally\n");
2952 * qla1280_device_reset
2953 * Issue bus device reset message to the target.
2956 * ha = adapter block pointer.
2957 * bus = SCSI BUS number.
2964 qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
2966 uint16_t mb[MAILBOX_REGISTER_COUNT];
2969 ENTER("qla1280_device_reset");
2971 mb[0] = MBC_ABORT_TARGET;
2972 mb[1] = (bus ? (target | BIT_7) : target) << 8;
2974 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2976 /* Issue marker command. */
2977 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
2980 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
2982 LEAVE("qla1280_device_reset");
2987 * qla1280_abort_device
2988 * Issue an abort message to the device
2991 * ha = adapter block pointer.
3000 qla1280_abort_device(struct scsi_qla_host *ha, int bus, int target, int lun)
3002 uint16_t mb[MAILBOX_REGISTER_COUNT];
3005 ENTER("qla1280_abort_device");
3007 mb[0] = MBC_ABORT_DEVICE;
3008 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
3009 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
3011 /* Issue marker command. */
3012 qla1280_marker(ha, bus, target, lun, MK_SYNC_ID_LUN);
3015 dprintk(2, "qla1280_abort_device: **** FAILED ****\n");
3017 LEAVE("qla1280_abort_device");
3022 * qla1280_abort_command
3023 * Abort command aborts a specified IOCB.
3026 * ha = adapter block pointer.
3027 * sp = SB structure pointer.
3033 qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
3035 uint16_t mb[MAILBOX_REGISTER_COUNT];
3036 unsigned int bus, target, lun;
3039 ENTER("qla1280_abort_command");
3041 bus = SCSI_BUS_32(sp->cmd);
3042 target = SCSI_TCN_32(sp->cmd);
3043 lun = SCSI_LUN_32(sp->cmd);
3045 sp->flags |= SRB_ABORT_PENDING;
3047 mb[0] = MBC_ABORT_COMMAND;
3048 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
3049 mb[2] = handle >> 16;
3050 mb[3] = handle & 0xffff;
3051 status = qla1280_mailbox_command(ha, 0x0f, &mb[0]);
3054 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
3055 sp->flags &= ~SRB_ABORT_PENDING;
3059 LEAVE("qla1280_abort_command");
3064 * qla1280_reset_adapter
3068 * ha = adapter block pointer.
3071 qla1280_reset_adapter(struct scsi_qla_host *ha)
3073 struct device_reg *reg = ha->iobase;
3075 ENTER("qla1280_reset_adapter");
3077 /* Disable ISP chip */
3078 ha->flags.online = 0;
3079 WRT_REG_WORD(®->ictrl, ISP_RESET);
3080 WRT_REG_WORD(®->host_cmd,
3081 HC_RESET_RISC | HC_RELEASE_RISC | HC_DISABLE_BIOS);
3082 RD_REG_WORD(®->id_l); /* Flush PCI write */
3084 LEAVE("qla1280_reset_adapter");
3088 * Issue marker command.
3089 * Function issues marker IOCB.
3092 * ha = adapter block pointer.
3093 * bus = SCSI BUS number
3096 * type = marker modifier
3099 qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
3101 struct mrk_entry *pkt;
3103 ENTER("qla1280_marker");
3105 /* Get request packet. */
3106 if ((pkt = (struct mrk_entry *) qla1280_req_pkt(ha))) {
3107 pkt->entry_type = MARKER_TYPE;
3108 pkt->lun = (uint8_t) lun;
3109 pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
3110 pkt->modifier = type;
3111 pkt->entry_status = 0;
3113 /* Issue command to ISP */
3114 qla1280_isp_cmd(ha);
3117 LEAVE("qla1280_marker");
3122 * qla1280_64bit_start_scsi
3123 * The start SCSI is responsible for building request packets on
3124 * request ring and modifying ISP input pointer.
3127 * ha = adapter block pointer.
3128 * sp = SB structure pointer.
3131 * 0 = success, was able to issue command.
3133 #ifdef QLA_64BIT_PTR
3135 qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3137 struct device_reg *reg = ha->iobase;
3138 struct scsi_cmnd *cmd = sp->cmd;
3139 cmd_a64_entry_t *pkt;
3140 struct scatterlist *sg = NULL;
3142 dma_addr_t dma_handle;
3149 ENTER("qla1280_64bit_start_scsi:");
3151 /* Calculate number of entries and segments required. */
3154 sg = (struct scatterlist *) cmd->request_buffer;
3155 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3156 cmd->sc_data_direction);
3159 req_cnt += (seg_cnt - 2) / 5;
3160 if ((seg_cnt - 2) % 5)
3163 } else if (cmd->request_bufflen) { /* If data transfer. */
3169 if ((req_cnt + 2) >= ha->req_q_cnt) {
3170 /* Calculate number of free request entries. */
3171 cnt = RD_REG_WORD(®->mailbox4);
3172 if (ha->req_ring_index < cnt)
3173 ha->req_q_cnt = cnt - ha->req_ring_index;
3176 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3179 /* If room for request in request ring. */
3180 if ((req_cnt + 2) >= ha->req_q_cnt) {
3182 dprintk(2, "qla1280_64bit_start_scsi: in-ptr=0x%x req_q_cnt="
3183 "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
3188 /* Check for room in outstanding command list. */
3189 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3190 ha->outstanding_cmds[cnt] != 0; cnt++);
3192 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3194 dprintk(2, "qla1280_64bit_start_scsi: NO ROOM IN "
3195 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
3199 ha->outstanding_cmds[cnt] = sp;
3200 ha->req_q_cnt -= req_cnt;
3201 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
3203 dprintk(2, "64bit_start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
3204 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
3205 dprintk(2, " bus %i, target %i, lun %i\n",
3206 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3207 qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
3210 * Build command packet.
3212 pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
3214 pkt->entry_type = COMMAND_A64_TYPE;
3215 pkt->entry_count = (uint8_t) req_cnt;
3216 pkt->sys_define = (uint8_t) ha->req_ring_index;
3217 pkt->entry_status = 0;
3218 pkt->handle = cpu_to_le32(cnt);
3220 /* Zero out remaining portion of packet. */
3221 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3223 /* Set ISP command timeout. */
3224 pkt->timeout = cpu_to_le16(30);
3226 /* Set device target ID and LUN */
3227 pkt->lun = SCSI_LUN_32(cmd);
3228 pkt->target = SCSI_BUS_32(cmd) ?
3229 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3231 /* Enable simple tag queuing if device supports it. */
3232 if (DEV_SIMPLE_TAGS(cmd->device))
3233 pkt->control_flags |= cpu_to_le16(BIT_3);
3235 /* Load SCSI command packet. */
3236 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3237 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3238 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3240 /* Set transfer direction. */
3241 dir = qla1280_data_direction(cmd);
3242 pkt->control_flags |= cpu_to_le16(dir);
3244 /* Set total data segment count. */
3245 pkt->dseg_count = cpu_to_le16(seg_cnt);
3248 * Load data segments.
3250 if (seg_cnt) { /* If data transfer. */
3251 /* Setup packet address segment pointer. */
3252 dword_ptr = (u32 *)&pkt->dseg_0_address;
3254 if (cmd->use_sg) { /* If scatter gather */
3255 /* Load command entry data segments. */
3256 for (cnt = 0; cnt < 2 && seg_cnt; cnt++, seg_cnt--) {
3257 dma_handle = sg_dma_address(sg);
3258 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3259 if (ha->flags.use_pci_vchannel)
3260 sn_pci_set_vchan(ha->pdev, &dma_handle,
3264 cpu_to_le32(pci_dma_lo32(dma_handle));
3266 cpu_to_le32(pci_dma_hi32(dma_handle));
3267 *dword_ptr++ = cpu_to_le32(sg_dma_len(sg));
3269 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
3270 cpu_to_le32(pci_dma_hi32(dma_handle)),
3271 cpu_to_le32(pci_dma_lo32(dma_handle)),
3272 cpu_to_le32(sg_dma_len(sg)));
3274 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
3275 "command packet data - b %i, t %i, l %i \n",
3276 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3278 qla1280_dump_buffer(5, (char *)pkt,
3279 REQUEST_ENTRY_SIZE);
3282 * Build continuation packets.
3284 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
3285 "remains\n", seg_cnt);
3287 while (seg_cnt > 0) {
3288 /* Adjust ring index. */
3289 ha->req_ring_index++;
3290 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3291 ha->req_ring_index = 0;
3292 ha->request_ring_ptr =
3295 ha->request_ring_ptr++;
3297 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
3299 /* Zero out packet. */
3300 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3302 /* Load packet defaults. */
3303 ((struct cont_a64_entry *) pkt)->entry_type =
3305 ((struct cont_a64_entry *) pkt)->entry_count = 1;
3306 ((struct cont_a64_entry *) pkt)->sys_define =
3307 (uint8_t)ha->req_ring_index;
3308 /* Setup packet address segment pointer. */
3310 (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
3312 /* Load continuation entry data segments. */
3313 for (cnt = 0; cnt < 5 && seg_cnt;
3315 dma_handle = sg_dma_address(sg);
3316 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3317 if (ha->flags.use_pci_vchannel)
3318 sn_pci_set_vchan(ha->pdev, &dma_handle,
3322 cpu_to_le32(pci_dma_lo32(dma_handle));
3324 cpu_to_le32(pci_dma_hi32(dma_handle));
3326 cpu_to_le32(sg_dma_len(sg));
3327 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
3328 cpu_to_le32(pci_dma_hi32(dma_handle)),
3329 cpu_to_le32(pci_dma_lo32(dma_handle)),
3330 cpu_to_le32(sg_dma_len(sg)));
3333 dprintk(5, "qla1280_64bit_start_scsi: "
3334 "continuation packet data - b %i, t "
3335 "%i, l %i \n", SCSI_BUS_32(cmd),
3336 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3337 qla1280_dump_buffer(5, (char *)pkt,
3338 REQUEST_ENTRY_SIZE);
3340 } else { /* No scatter gather data transfer */
3341 struct page *page = virt_to_page(cmd->request_buffer);
3342 unsigned long off = (unsigned long)cmd->request_buffer & ~PAGE_MASK;
3344 dma_handle = pci_map_page(ha->pdev, page, off,
3345 cmd->request_bufflen,
3346 cmd->sc_data_direction);
3348 /* save dma_handle for pci_unmap_page */
3349 sp->saved_dma_handle = dma_handle;
3350 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3351 if (ha->flags.use_pci_vchannel)
3352 sn_pci_set_vchan(ha->pdev, &dma_handle,
3355 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3356 *dword_ptr++ = cpu_to_le32(pci_dma_hi32(dma_handle));
3357 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3359 dprintk(5, "qla1280_64bit_start_scsi: No scatter/"
3360 "gather command packet data - b %i, t %i, "
3361 "l %i \n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3363 qla1280_dump_buffer(5, (char *)pkt,
3364 REQUEST_ENTRY_SIZE);
3366 } else { /* No data transfer */
3367 dprintk(5, "qla1280_64bit_start_scsi: No data, command "
3368 "packet data - b %i, t %i, l %i \n",
3369 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3370 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3372 /* Adjust ring index. */
3373 ha->req_ring_index++;
3374 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3375 ha->req_ring_index = 0;
3376 ha->request_ring_ptr = ha->request_ring;
3378 ha->request_ring_ptr++;
3380 /* Set chip new ring index. */
3382 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
3383 sp->flags |= SRB_SENT;
3385 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3386 (void) RD_REG_WORD(®->mailbox4); /* PCI posted write flush */
3390 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
3392 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
3396 #else /* !QLA_64BIT_PTR */
3399 * qla1280_32bit_start_scsi
3400 * The start SCSI is responsible for building request packets on
3401 * request ring and modifying ISP input pointer.
3403 * The Qlogic firmware interface allows every queue slot to have a SCSI
3404 * command and up to 4 scatter/gather (SG) entries. If we need more
3405 * than 4 SG entries, then continuation entries are used that can
3406 * hold another 7 entries each. The start routine determines if there
3407 * is eought empty slots then build the combination of requests to
3408 * fulfill the OS request.
3411 * ha = adapter block pointer.
3412 * sp = SCSI Request Block structure pointer.
3415 * 0 = success, was able to issue command.
3418 qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3420 struct device_reg *reg = ha->iobase;
3421 struct scsi_cmnd *cmd = sp->cmd;
3422 struct cmd_entry *pkt;
3423 struct scatterlist *sg = NULL;
3424 uint32_t *dword_ptr;
3429 dma_addr_t dma_handle;
3432 ENTER("qla1280_32bit_start_scsi");
3434 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
3437 /* Calculate number of entries and segments required. */
3441 * We must build an SG list in adapter format, as the kernel's
3442 * SG list cannot be used directly because of data field size
3443 * (__alpha__) differences and the kernel SG list uses virtual
3444 * addresses where we need physical addresses.
3446 sg = (struct scatterlist *) cmd->request_buffer;
3447 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3448 cmd->sc_data_direction);
3451 * if greater than four sg entries then we need to allocate
3452 * continuation entries
3455 req_cnt += (seg_cnt - 4) / 7;
3456 if ((seg_cnt - 4) % 7)
3459 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3460 cmd, seg_cnt, req_cnt);
3461 } else if (cmd->request_bufflen) { /* If data transfer. */
3462 dprintk(3, "No S/G transfer t=%x cmd=%p len=%x CDB=%x\n",
3463 SCSI_TCN_32(cmd), cmd, cmd->request_bufflen,
3467 /* dprintk(1, "No data transfer \n"); */
3471 if ((req_cnt + 2) >= ha->req_q_cnt) {
3472 /* Calculate number of free request entries. */
3473 cnt = RD_REG_WORD(®->mailbox4);
3474 if (ha->req_ring_index < cnt)
3475 ha->req_q_cnt = cnt - ha->req_ring_index;
3478 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3481 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3482 ha->req_q_cnt, seg_cnt);
3483 /* If room for request in request ring. */
3484 if ((req_cnt + 2) >= ha->req_q_cnt) {
3486 dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
3487 "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
3488 ha->req_q_cnt, req_cnt);
3492 /* Check for empty slot in outstanding command list. */
3493 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3494 (ha->outstanding_cmds[cnt] != 0); cnt++) ;
3496 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3498 dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
3499 "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
3503 CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
3504 ha->outstanding_cmds[cnt] = sp;
3505 ha->req_q_cnt -= req_cnt;
3508 * Build command packet.
3510 pkt = (struct cmd_entry *) ha->request_ring_ptr;
3512 pkt->entry_type = COMMAND_TYPE;
3513 pkt->entry_count = (uint8_t) req_cnt;
3514 pkt->sys_define = (uint8_t) ha->req_ring_index;
3515 pkt->entry_status = 0;
3516 pkt->handle = cpu_to_le32(cnt);
3518 /* Zero out remaining portion of packet. */
3519 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3521 /* Set ISP command timeout. */
3522 pkt->timeout = cpu_to_le16(30);
3524 /* Set device target ID and LUN */
3525 pkt->lun = SCSI_LUN_32(cmd);
3526 pkt->target = SCSI_BUS_32(cmd) ?
3527 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3529 /* Enable simple tag queuing if device supports it. */
3530 if (DEV_SIMPLE_TAGS(cmd->device))
3531 pkt->control_flags |= cpu_to_le16(BIT_3);
3533 /* Load SCSI command packet. */
3534 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3535 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3537 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3538 /* Set transfer direction. */
3539 dir = qla1280_data_direction(cmd);
3540 pkt->control_flags |= cpu_to_le16(dir);
3542 /* Set total data segment count. */
3543 pkt->dseg_count = cpu_to_le16(seg_cnt);
3546 * Load data segments.
3549 /* Setup packet address segment pointer. */
3550 dword_ptr = &pkt->dseg_0_address;
3552 if (cmd->use_sg) { /* If scatter gather */
3553 dprintk(3, "Building S/G data segments..\n");
3554 qla1280_dump_buffer(1, (char *)sg, 4 * 16);
3556 /* Load command entry data segments. */
3557 for (cnt = 0; cnt < 4 && seg_cnt; cnt++, seg_cnt--) {
3559 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3561 cpu_to_le32(sg_dma_len(sg));
3562 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3563 (pci_dma_lo32(sg_dma_address(sg))),
3568 * Build continuation packets.
3570 dprintk(3, "S/G Building Continuation"
3571 "...seg_cnt=0x%x remains\n", seg_cnt);
3572 while (seg_cnt > 0) {
3573 /* Adjust ring index. */
3574 ha->req_ring_index++;
3575 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3576 ha->req_ring_index = 0;
3577 ha->request_ring_ptr =
3580 ha->request_ring_ptr++;
3582 pkt = (struct cmd_entry *)ha->request_ring_ptr;
3584 /* Zero out packet. */
3585 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3587 /* Load packet defaults. */
3588 ((struct cont_entry *) pkt)->
3589 entry_type = CONTINUE_TYPE;
3590 ((struct cont_entry *) pkt)->entry_count = 1;
3592 ((struct cont_entry *) pkt)->sys_define =
3593 (uint8_t) ha->req_ring_index;
3595 /* Setup packet address segment pointer. */
3597 &((struct cont_entry *) pkt)->dseg_0_address;
3599 /* Load continuation entry data segments. */
3600 for (cnt = 0; cnt < 7 && seg_cnt;
3603 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3605 cpu_to_le32(sg_dma_len(sg));
3607 "S/G Segment Cont. phys_addr=0x%x, "
3609 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
3610 cpu_to_le32(sg_dma_len(sg)));
3613 dprintk(5, "qla1280_32bit_start_scsi: "
3614 "continuation packet data - "
3615 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
3616 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3617 qla1280_dump_buffer(5, (char *)pkt,
3618 REQUEST_ENTRY_SIZE);
3620 } else { /* No S/G data transfer */
3621 struct page *page = virt_to_page(cmd->request_buffer);
3622 unsigned long off = (unsigned long)cmd->request_buffer & ~PAGE_MASK;
3623 dma_handle = pci_map_page(ha->pdev, page, off,
3624 cmd->request_bufflen,
3625 cmd->sc_data_direction);
3626 sp->saved_dma_handle = dma_handle;
3628 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3629 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3631 } else { /* No data transfer at all */
3632 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
3633 "packet data - \n");
3634 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3636 dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
3637 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3638 REQUEST_ENTRY_SIZE);
3640 /* Adjust ring index. */
3641 ha->req_ring_index++;
3642 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3643 ha->req_ring_index = 0;
3644 ha->request_ring_ptr = ha->request_ring;
3646 ha->request_ring_ptr++;
3648 /* Set chip new ring index. */
3649 dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
3650 "for pending command\n");
3651 sp->flags |= SRB_SENT;
3653 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3654 (void) RD_REG_WORD(®->mailbox4); /* PCI posted write flush */
3658 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
3660 LEAVE("qla1280_32bit_start_scsi");
3668 * Function is responsible for locking ring and
3669 * getting a zeroed out request packet.
3672 * ha = adapter block pointer.
3675 * 0 = failed to get slot.
3678 qla1280_req_pkt(struct scsi_qla_host *ha)
3680 struct device_reg *reg = ha->iobase;
3681 request_t *pkt = NULL;
3685 ENTER("qla1280_req_pkt");
3688 * This can be called from interrupt context, damn it!!!
3690 /* Wait for 30 seconds for slot. */
3691 for (timer = 15000000; timer; timer--) {
3692 if (ha->req_q_cnt > 0) {
3693 /* Calculate number of free request entries. */
3694 cnt = RD_REG_WORD(®->mailbox4);
3695 if (ha->req_ring_index < cnt)
3696 ha->req_q_cnt = cnt - ha->req_ring_index;
3699 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3702 /* Found empty request ring slot? */
3703 if (ha->req_q_cnt > 0) {
3705 pkt = ha->request_ring_ptr;
3707 /* Zero out packet. */
3708 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3711 * How can this be right when we have a ring
3714 /* Set system defined field. */
3715 pkt->sys_define = (uint8_t) ha->req_ring_index;
3717 /* Set entry count. */
3718 pkt->entry_count = 1;
3725 /* Check for pending interrupts. */
3730 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
3732 dprintk(3, "qla1280_req_pkt: exiting normally\n");
3739 * Function is responsible for modifying ISP input pointer.
3740 * Releases ring lock.
3743 * ha = adapter block pointer.
3746 qla1280_isp_cmd(struct scsi_qla_host *ha)
3748 struct device_reg *reg = ha->iobase;
3750 ENTER("qla1280_isp_cmd");
3752 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
3753 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3754 REQUEST_ENTRY_SIZE);
3756 /* Adjust ring index. */
3757 ha->req_ring_index++;
3758 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3759 ha->req_ring_index = 0;
3760 ha->request_ring_ptr = ha->request_ring;
3762 ha->request_ring_ptr++;
3764 /* Set chip new ring index. */
3765 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3766 (void) RD_REG_WORD(®->mailbox4); /* PCI posted write flush */
3768 LEAVE("qla1280_isp_cmd");
3771 /****************************************************************************/
3772 /* Interrupt Service Routine. */
3773 /****************************************************************************/
3775 /****************************************************************************
3777 * Calls I/O done on command completion.
3780 * ha = adapter block pointer.
3781 * done_q = done queue.
3782 ****************************************************************************/
3784 qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
3786 struct device_reg *reg = ha->iobase;
3787 struct response *pkt;
3788 struct srb *sp = NULL;
3789 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
3794 ENTER("qla1280_isr");
3796 istatus = RD_REG_WORD(®->istatus);
3797 if (!(istatus & (RISC_INT | PCI_INT)))
3800 /* Save mailbox register 5 */
3801 mailbox[5] = RD_REG_WORD(®->mailbox5);
3803 /* Check for mailbox interrupt. */
3805 mailbox[0] = RD_REG_WORD_dmasync(®->semaphore);
3807 if (mailbox[0] & BIT_0) {
3808 /* Get mailbox data. */
3809 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
3812 *wptr++ = RD_REG_WORD(®->mailbox0);
3813 *wptr++ = RD_REG_WORD(®->mailbox1);
3814 *wptr = RD_REG_WORD(®->mailbox2);
3815 if (mailbox[0] != MBA_SCSI_COMPLETION) {
3817 *wptr++ = RD_REG_WORD(®->mailbox3);
3818 *wptr++ = RD_REG_WORD(®->mailbox4);
3820 *wptr++ = RD_REG_WORD(®->mailbox6);
3821 *wptr = RD_REG_WORD(®->mailbox7);
3824 /* Release mailbox registers. */
3826 WRT_REG_WORD(®->semaphore, 0);
3827 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3829 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
3832 /* Handle asynchronous event */
3833 switch (mailbox[0]) {
3834 case MBA_SCSI_COMPLETION: /* Response completion */
3835 dprintk(5, "qla1280_isr: mailbox SCSI response "
3838 if (ha->flags.online) {
3839 /* Get outstanding command index. */
3840 index = mailbox[2] << 16 | mailbox[1];
3842 /* Validate handle. */
3843 if (index < MAX_OUTSTANDING_COMMANDS)
3844 sp = ha->outstanding_cmds[index];
3849 /* Free outstanding command slot. */
3850 ha->outstanding_cmds[index] = NULL;
3852 /* Save ISP completion status */
3853 CMD_RESULT(sp->cmd) = 0;
3855 /* Place block on done queue */
3856 list_add_tail(&sp->list, done_q);
3859 * If we get here we have a real problem!
3862 "qla1280: ISP invalid handle");
3867 case MBA_BUS_RESET: /* SCSI Bus Reset */
3868 ha->flags.reset_marker = 1;
3869 index = mailbox[6] & BIT_0;
3870 ha->bus_settings[index].reset_marker = 1;
3872 printk(KERN_DEBUG "qla1280_isr(): index %i "
3873 "asynchronous BUS_RESET\n", index);
3876 case MBA_SYSTEM_ERR: /* System Error */
3878 "qla1280: ISP System Error - mbx1=%xh, mbx2="
3879 "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
3883 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
3885 "qla1280: ISP Request Transfer Error\n");
3888 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
3890 "qla1280: ISP Response Transfer Error\n");
3893 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
3894 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
3897 case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
3899 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
3902 case MBA_DEVICE_RESET: /* Bus Device Reset */
3903 printk(KERN_INFO "qla1280_isr(): asynchronous "
3904 "BUS_DEVICE_RESET\n");
3906 ha->flags.reset_marker = 1;
3907 index = mailbox[6] & BIT_0;
3908 ha->bus_settings[index].reset_marker = 1;
3911 case MBA_BUS_MODE_CHANGE:
3913 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
3917 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
3918 if (mailbox[0] < MBA_ASYNC_EVENT) {
3920 memcpy((uint16_t *) ha->mailbox_out, wptr,
3921 MAILBOX_REGISTER_COUNT *
3924 if(ha->mailbox_wait != NULL)
3925 complete(ha->mailbox_wait);
3930 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3934 * We will receive interrupts during mailbox testing prior to
3935 * the card being marked online, hence the double check.
3937 if (!(ha->flags.online && !ha->mailbox_wait)) {
3938 dprintk(2, "qla1280_isr: Response pointer Error\n");
3942 if (mailbox[5] >= RESPONSE_ENTRY_CNT)
3945 while (ha->rsp_ring_index != mailbox[5]) {
3946 pkt = ha->response_ring_ptr;
3948 dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
3949 " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
3950 dprintk(5,"qla1280_isr: response packet data\n");
3951 qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
3953 if (pkt->entry_type == STATUS_TYPE) {
3954 if ((le16_to_cpu(pkt->scsi_status) & 0xff)
3955 || pkt->comp_status || pkt->entry_status) {
3956 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3957 "0x%x mailbox[5] = 0x%x, comp_status "
3958 "= 0x%x, scsi_status = 0x%x\n",
3959 ha->rsp_ring_index, mailbox[5],
3960 le16_to_cpu(pkt->comp_status),
3961 le16_to_cpu(pkt->scsi_status));
3964 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3965 "0x%x, mailbox[5] = 0x%x\n",
3966 ha->rsp_ring_index, mailbox[5]);
3967 dprintk(2, "qla1280_isr: response packet data\n");
3968 qla1280_dump_buffer(2, (char *)pkt,
3969 RESPONSE_ENTRY_SIZE);
3972 if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
3973 dprintk(2, "status: Cmd %p, handle %i\n",
3974 ha->outstanding_cmds[pkt->handle]->cmd,
3976 if (pkt->entry_type == STATUS_TYPE)
3977 qla1280_status_entry(ha, pkt, done_q);
3979 qla1280_error_entry(ha, pkt, done_q);
3980 /* Adjust ring index. */
3981 ha->rsp_ring_index++;
3982 if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
3983 ha->rsp_ring_index = 0;
3984 ha->response_ring_ptr = ha->response_ring;
3986 ha->response_ring_ptr++;
3987 WRT_REG_WORD(®->mailbox5, ha->rsp_ring_index);
3992 LEAVE("qla1280_isr");
3997 * Processes asynchronous reset.
4000 * ha = adapter block pointer.
4003 qla1280_rst_aen(struct scsi_qla_host *ha)
4007 ENTER("qla1280_rst_aen");
4009 if (ha->flags.online && !ha->flags.reset_active &&
4010 !ha->flags.abort_isp_active) {
4011 ha->flags.reset_active = 1;
4012 while (ha->flags.reset_marker) {
4013 /* Issue marker command. */
4014 ha->flags.reset_marker = 0;
4015 for (bus = 0; bus < ha->ports &&
4016 !ha->flags.reset_marker; bus++) {
4017 if (ha->bus_settings[bus].reset_marker) {
4018 ha->bus_settings[bus].reset_marker = 0;
4019 qla1280_marker(ha, bus, 0, 0,
4026 LEAVE("qla1280_rst_aen");
4030 #if LINUX_VERSION_CODE < 0x020500
4035 qla1280_get_target_options(struct scsi_cmnd *cmd, struct scsi_qla_host *ha)
4037 unsigned char *result;
4039 int bus, target, lun;
4041 bus = SCSI_BUS_32(cmd);
4042 target = SCSI_TCN_32(cmd);
4043 lun = SCSI_LUN_32(cmd);
4046 * Make sure to not touch anything if someone is using the
4049 if (cmd->use_sg || (CMD_RESULT(cmd) >> 16) != DID_OK || lun)
4052 result = cmd->request_buffer;
4055 n->bus[bus].target[target].parameter.f.enable_wide = 0;
4056 n->bus[bus].target[target].parameter.f.enable_sync = 0;
4057 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
4059 if (result[7] & 0x60)
4060 n->bus[bus].target[target].parameter.f.enable_wide = 1;
4061 if (result[7] & 0x10)
4062 n->bus[bus].target[target].parameter.f.enable_sync = 1;
4063 if ((result[2] >= 3) && (result[4] + 5 > 56) &&
4065 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
4067 dprintk(2, "get_target_options(): wide %i, sync %i, ppr %i\n",
4068 n->bus[bus].target[target].parameter.f.enable_wide,
4069 n->bus[bus].target[target].parameter.f.enable_sync,
4070 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr);
4075 * qla1280_status_entry
4076 * Processes received ISP status entry.
4079 * ha = adapter block pointer.
4080 * pkt = entry pointer.
4081 * done_q = done queue.
4084 qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
4085 struct list_head *done_q)
4087 unsigned int bus, target, lun;
4090 struct scsi_cmnd *cmd;
4091 uint32_t handle = le32_to_cpu(pkt->handle);
4092 uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
4093 uint16_t comp_status = le16_to_cpu(pkt->comp_status);
4095 ENTER("qla1280_status_entry");
4097 /* Validate handle. */
4098 if (handle < MAX_OUTSTANDING_COMMANDS)
4099 sp = ha->outstanding_cmds[handle];
4104 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
4108 /* Free outstanding command slot. */
4109 ha->outstanding_cmds[handle] = NULL;
4113 /* Generate LU queue on cntrl, target, LUN */
4114 bus = SCSI_BUS_32(cmd);
4115 target = SCSI_TCN_32(cmd);
4116 lun = SCSI_LUN_32(cmd);
4118 if (comp_status || scsi_status) {
4119 dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
4120 "0x%x, handle = 0x%x\n", comp_status,
4121 scsi_status, handle);
4125 if (scsi_status & SS_BUSY_CONDITION &&
4126 scsi_status != SS_RESERVE_CONFLICT) {
4128 DID_BUS_BUSY << 16 | (scsi_status & 0xff);
4131 /* Save ISP completion status */
4132 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
4134 if (scsi_status & SS_CHECK_CONDITION) {
4135 if (comp_status != CS_ARS_FAILED) {
4136 uint16_t req_sense_length =
4137 le16_to_cpu(pkt->req_sense_length);
4138 if (req_sense_length < CMD_SNSLEN(cmd))
4139 sense_sz = req_sense_length;
4142 * scsi_cmnd->sense_buffer is
4143 * 64 bytes, why only copy 63?
4144 * This looks wrong! /Jes
4146 sense_sz = CMD_SNSLEN(cmd) - 1;
4148 memcpy(cmd->sense_buffer,
4149 &pkt->req_sense_data, sense_sz);
4152 memset(cmd->sense_buffer + sense_sz, 0,
4153 sizeof(cmd->sense_buffer) - sense_sz);
4155 dprintk(2, "qla1280_status_entry: Check "
4156 "condition Sense data, b %i, t %i, "
4157 "l %i\n", bus, target, lun);
4159 qla1280_dump_buffer(2,
4160 (char *)cmd->sense_buffer,
4165 /* Place command on done queue. */
4166 list_add_tail(&sp->list, done_q);
4168 LEAVE("qla1280_status_entry");
4172 * qla1280_error_entry
4173 * Processes error entry.
4176 * ha = adapter block pointer.
4177 * pkt = entry pointer.
4178 * done_q = done queue.
4181 qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
4182 struct list_head *done_q)
4185 uint32_t handle = le32_to_cpu(pkt->handle);
4187 ENTER("qla1280_error_entry");
4189 if (pkt->entry_status & BIT_3)
4190 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
4191 else if (pkt->entry_status & BIT_2)
4192 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
4193 else if (pkt->entry_status & BIT_1)
4194 dprintk(2, "qla1280_error_entry: FULL flag error\n");
4196 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
4198 /* Validate handle. */
4199 if (handle < MAX_OUTSTANDING_COMMANDS)
4200 sp = ha->outstanding_cmds[handle];
4205 /* Free outstanding command slot. */
4206 ha->outstanding_cmds[handle] = NULL;
4208 /* Bad payload or header */
4209 if (pkt->entry_status & (BIT_3 + BIT_2)) {
4210 /* Bad payload or header, set error status. */
4211 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
4212 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
4213 } else if (pkt->entry_status & BIT_1) { /* FULL flag */
4214 CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
4216 /* Set error status. */
4217 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
4220 /* Place command on done queue. */
4221 list_add_tail(&sp->list, done_q);
4223 #ifdef QLA_64BIT_PTR
4224 else if (pkt->entry_type == COMMAND_A64_TYPE) {
4225 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
4229 LEAVE("qla1280_error_entry");
4234 * Resets ISP and aborts all outstanding commands.
4237 * ha = adapter block pointer.
4243 qla1280_abort_isp(struct scsi_qla_host *ha)
4245 struct device_reg *reg = ha->iobase;
4251 ENTER("qla1280_abort_isp");
4253 if (ha->flags.abort_isp_active || !ha->flags.online)
4256 ha->flags.abort_isp_active = 1;
4258 /* Disable ISP interrupts. */
4259 qla1280_disable_intrs(ha);
4260 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
4261 RD_REG_WORD(®->id_l);
4263 printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
4265 /* Dequeue all commands in outstanding command list. */
4266 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
4267 struct scsi_cmnd *cmd;
4268 sp = ha->outstanding_cmds[cnt];
4272 CMD_RESULT(cmd) = DID_RESET << 16;
4275 ha->outstanding_cmds[cnt] = NULL;
4277 (*cmd->scsi_done)(cmd);
4283 status = qla1280_load_firmware(ha);
4287 /* Setup adapter based on NVRAM parameters. */
4288 qla1280_nvram_config (ha);
4290 status = qla1280_init_rings(ha);
4294 /* Issue SCSI reset. */
4295 for (bus = 0; bus < ha->ports; bus++)
4296 qla1280_bus_reset(ha, bus);
4298 ha->flags.abort_isp_active = 0;
4302 "qla1280: ISP error recovery failed, board disabled");
4303 qla1280_reset_adapter(ha);
4304 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
4307 LEAVE("qla1280_abort_isp");
4313 * qla1280_debounce_register
4314 * Debounce register.
4317 * port = register address.
4323 qla1280_debounce_register(volatile u16 * addr)
4328 ret = RD_REG_WORD(addr);
4329 ret2 = RD_REG_WORD(addr);
4336 ret = RD_REG_WORD(addr);
4337 ret2 = RD_REG_WORD(addr);
4338 } while (ret != ret2);
4344 /************************************************************************
4345 * qla1280_check_for_dead_scsi_bus *
4347 * This routine checks for a dead SCSI bus *
4348 ************************************************************************/
4349 #define SET_SXP_BANK 0x0100
4350 #define SCSI_PHASE_INVALID 0x87FF
4352 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
4354 uint16_t config_reg, scsi_control;
4355 struct device_reg *reg = ha->iobase;
4357 if (ha->bus_settings[bus].scsi_bus_dead) {
4358 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
4359 config_reg = RD_REG_WORD(®->cfg_1);
4360 WRT_REG_WORD(®->cfg_1, SET_SXP_BANK);
4361 scsi_control = RD_REG_WORD(®->scsiControlPins);
4362 WRT_REG_WORD(®->cfg_1, config_reg);
4363 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
4365 if (scsi_control == SCSI_PHASE_INVALID) {
4366 ha->bus_settings[bus].scsi_bus_dead = 1;
4368 CMD_RESULT(cp) = DID_NO_CONNECT << 16;
4369 CMD_HANDLE(cp) = INVALID_HANDLE;
4370 /* ha->actthreads--; */
4372 (*(cp)->scsi_done)(cp);
4374 return 1; /* bus is dead */
4376 ha->bus_settings[bus].scsi_bus_dead = 0;
4377 ha->bus_settings[bus].failed_reset_count = 0;
4380 return 0; /* bus is not dead */
4384 qla1280_get_target_parameters(struct scsi_qla_host *ha,
4385 struct scsi_device *device)
4387 uint16_t mb[MAILBOX_REGISTER_COUNT];
4388 int bus, target, lun;
4390 bus = device->channel;
4391 target = device->id;
4395 mb[0] = MBC_GET_TARGET_PARAMETERS;
4396 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
4398 qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
4401 printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
4404 printk(" Sync: period %d, offset %d",
4405 (mb[3] & 0xff), (mb[3] >> 8));
4408 if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
4413 if (DEV_SIMPLE_TAGS(device))
4414 printk(", Tagged queuing: depth %d", device->queue_depth);
4421 __qla1280_dump_buffer(char *b, int size)
4426 printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
4427 "Bh Ch Dh Eh Fh\n");
4428 printk(KERN_DEBUG "---------------------------------------------"
4429 "------------------\n");
4431 for (cnt = 0; cnt < size;) {
4434 printk("0x%02x", c);
4445 /**************************************************************************
4446 * ql1280_print_scsi_cmd
4448 **************************************************************************/
4450 __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
4452 struct scsi_qla_host *ha;
4453 struct Scsi_Host *host = CMD_HOST(cmd);
4455 /* struct scatterlist *sg; */
4458 ha = (struct scsi_qla_host *)host->hostdata;
4460 sp = (struct srb *)CMD_SP(cmd);
4461 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
4462 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
4463 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
4466 for (i = 0; i < cmd->cmd_len; i++) {
4467 printk("0x%02x ", cmd->cmnd[i]);
4469 printk(" seg_cnt =%d\n", cmd->use_sg);
4470 printk(" request buffer=0x%p, request buffer len=0x%x\n",
4471 cmd->request_buffer, cmd->request_bufflen);
4474 sg = (struct scatterlist *) cmd->request_buffer;
4475 printk(" SG buffer: \n");
4476 qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
4478 printk(" tag=%d, transfersize=0x%x \n",
4479 cmd->tag, cmd->transfersize);
4480 printk(" Pid=%li, SP=0x%p\n", cmd->pid, CMD_SP(cmd));
4481 printk(" underflow size = 0x%x, direction=0x%x\n",
4482 cmd->underflow, cmd->sc_data_direction);
4485 /**************************************************************************
4486 * ql1280_dump_device
4488 **************************************************************************/
4490 ql1280_dump_device(struct scsi_qla_host *ha)
4493 struct scsi_cmnd *cp;
4497 printk(KERN_DEBUG "Outstanding Commands on controller:\n");
4499 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
4500 if ((sp = ha->outstanding_cmds[i]) == NULL)
4502 if ((cp = sp->cmd) == NULL)
4504 qla1280_print_scsi_cmd(1, cp);
4519 struct setup_tokens {
4524 static struct setup_tokens setup_token[] __initdata =
4526 { "nvram", TOKEN_NVRAM },
4527 { "sync", TOKEN_SYNC },
4528 { "wide", TOKEN_WIDE },
4529 { "ppr", TOKEN_PPR },
4530 { "verbose", TOKEN_VERBOSE },
4531 { "debug", TOKEN_DEBUG },
4535 /**************************************************************************
4538 * Handle boot parameters. This really needs to be changed so one
4539 * can specify per adapter parameters.
4540 **************************************************************************/
4542 qla1280_setup(char *s)
4550 while (cp && (ptr = strchr(cp, ':'))) {
4552 if (!strcmp(ptr, "yes")) {
4555 } else if (!strcmp(ptr, "no")) {
4559 val = simple_strtoul(ptr, &ptr, 0);
4561 switch ((toke = qla1280_get_token(cp))) {
4564 driver_setup.no_nvram = 1;
4568 driver_setup.no_sync = 1;
4569 else if (val != 0x10000)
4570 driver_setup.sync_mask = val;
4574 driver_setup.no_wide = 1;
4575 else if (val != 0x10000)
4576 driver_setup.wide_mask = val;
4580 driver_setup.no_ppr = 1;
4581 else if (val != 0x10000)
4582 driver_setup.ppr_mask = val;
4585 qla1280_verbose = val;
4588 printk(KERN_INFO "qla1280: unknown boot option %s\n",
4592 cp = strchr(ptr, ';');
4604 qla1280_get_token(char *str)
4610 len = sizeof(setup_token)/sizeof(struct setup_tokens);
4612 sep = strchr(str, ':');
4615 for (i = 0; i < len; i++){
4617 if (!strncmp(setup_token[i].token, str, (sep - str))) {
4618 ret = setup_token[i].val;
4627 #if LINUX_VERSION_CODE >= 0x020600
4628 static struct scsi_host_template qla1280_driver_template = {
4629 .proc_name = "qla1280",
4630 .name = "Qlogic ISP 1280/12160",
4631 .info = qla1280_info,
4632 .slave_configure = qla1280_slave_configure,
4633 .queuecommand = qla1280_queuecommand,
4634 .eh_abort_handler = qla1280_eh_abort,
4635 .eh_device_reset_handler= qla1280_eh_device_reset,
4636 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4637 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4638 .bios_param = qla1280_biosparam,
4639 .proc_info = qla1280_proc_info,
4640 .can_queue = 0xfffff,
4642 .sg_tablesize = SG_ALL,
4644 .use_clustering = ENABLE_CLUSTERING,
4647 static Scsi_Host_Template qla1280_driver_template = {
4648 .proc_name = "qla1280",
4649 .name = "Qlogic ISP 1280/12160",
4650 .detect = qla1280_detect,
4651 .release = qla1280_release,
4652 .info = qla1280_info,
4653 .queuecommand = qla1280_queuecommand,
4654 .eh_abort_handler = qla1280_eh_abort,
4655 .eh_device_reset_handler= qla1280_eh_device_reset,
4656 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4657 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4658 .bios_param = qla1280_biosparam_old,
4659 .proc_info = qla1280_proc_info_old,
4660 .can_queue = 0xfffff,
4662 .sg_tablesize = SG_ALL,
4664 .use_clustering = ENABLE_CLUSTERING,
4665 .use_new_eh_code = 1,
4669 static int __devinit
4670 qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4672 int devnum = id->driver_data;
4673 struct qla_boards *bdp = &ql1280_board_tbl[devnum];
4674 struct Scsi_Host *host;
4675 struct scsi_qla_host *ha;
4676 int error = -ENODEV;
4678 /* Bypass all AMI SUBSYS VENDOR IDs */
4679 if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
4681 "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
4685 printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
4686 bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
4688 if (pci_enable_device(pdev)) {
4690 "qla1280: Failed to enabled pci device, aborting.\n");
4694 pci_set_master(pdev);
4697 host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
4700 "qla1280: Failed to register host, aborting.\n");
4701 goto error_disable_device;
4704 ha = (struct scsi_qla_host *)host->hostdata;
4705 memset(ha, 0, sizeof(struct scsi_qla_host));
4708 ha->devnum = devnum; /* specifies microcode load address */
4710 #ifdef QLA_64BIT_PTR
4711 if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) {
4712 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4713 printk(KERN_WARNING "scsi(%li): Unable to set a "
4714 " suitable DMA mask - aboring\n", ha->host_no);
4716 goto error_free_irq;
4719 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4722 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4723 printk(KERN_WARNING "scsi(%li): Unable to set a "
4724 " suitable DMA mask - aboring\n", ha->host_no);
4726 goto error_free_irq;
4730 ha->request_ring = pci_alloc_consistent(ha->pdev,
4731 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4733 if (!ha->request_ring) {
4734 printk(KERN_INFO "qla1280: Failed to get request memory\n");
4735 goto error_put_host;
4738 ha->response_ring = pci_alloc_consistent(ha->pdev,
4739 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4741 if (!ha->response_ring) {
4742 printk(KERN_INFO "qla1280: Failed to get response memory\n");
4743 goto error_free_request_ring;
4746 ha->ports = bdp->numPorts;
4749 ha->host_no = host->host_no;
4751 host->irq = pdev->irq;
4752 host->max_channel = bdp->numPorts - 1;
4753 host->max_lun = MAX_LUNS - 1;
4754 host->max_id = MAX_TARGETS;
4755 host->max_sectors = 1024;
4756 host->unique_id = host->host_no;
4758 #if LINUX_VERSION_CODE < 0x020545
4759 host->select_queue_depths = qla1280_select_queue_depth;
4764 #if MEMORY_MAPPED_IO
4765 ha->mmpbase = ioremap(pci_resource_start(ha->pdev, 1),
4766 pci_resource_len(ha->pdev, 1));
4768 printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
4769 goto error_free_response_ring;
4772 host->base = (unsigned long)ha->mmpbase;
4773 ha->iobase = (struct device_reg *)ha->mmpbase;
4775 host->io_port = pci_resource_start(ha->pdev, 0);
4776 if (!request_region(host->io_port, 0xff, "qla1280")) {
4777 printk(KERN_INFO "qla1280: Failed to reserve i/o region "
4778 "0x%04lx-0x%04lx - already in use\n",
4779 host->io_port, host->io_port + 0xff);
4780 goto error_free_response_ring;
4783 ha->iobase = (struct device_reg *)host->io_port;
4786 INIT_LIST_HEAD(&ha->done_q);
4788 /* Disable ISP interrupts. */
4789 qla1280_disable_intrs(ha);
4791 if (request_irq(pdev->irq, qla1280_intr_handler, SA_SHIRQ,
4793 printk("qla1280 : Failed to reserve interrupt %d already "
4794 "in use\n", pdev->irq);
4795 goto error_release_region;
4798 /* load the F/W, read paramaters, and init the H/W */
4799 if (qla1280_initialize_adapter(ha)) {
4800 printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
4801 goto error_free_irq;
4804 /* set our host ID (need to do something about our two IDs) */
4805 host->this_id = ha->bus_settings[0].id;
4807 pci_set_drvdata(pdev, host);
4809 #if LINUX_VERSION_CODE >= 0x020600
4810 error = scsi_add_host(host, &pdev->dev);
4812 goto error_disable_adapter;
4813 scsi_scan_host(host);
4815 scsi_set_pci_device(host, pdev);
4820 #if LINUX_VERSION_CODE >= 0x020600
4821 error_disable_adapter:
4822 WRT_REG_WORD(&ha->iobase->ictrl, 0);
4825 free_irq(pdev->irq, ha);
4826 error_release_region:
4827 #if MEMORY_MAPPED_IO
4828 iounmap(ha->mmpbase);
4830 release_region(host->io_port, 0xff);
4832 error_free_response_ring:
4833 pci_free_consistent(ha->pdev,
4834 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4835 ha->response_ring, ha->response_dma);
4836 error_free_request_ring:
4837 pci_free_consistent(ha->pdev,
4838 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4839 ha->request_ring, ha->request_dma);
4841 scsi_host_put(host);
4842 error_disable_device:
4843 pci_disable_device(pdev);
4849 static void __devexit
4850 qla1280_remove_one(struct pci_dev *pdev)
4852 struct Scsi_Host *host = pci_get_drvdata(pdev);
4853 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
4855 #if LINUX_VERSION_CODE >= 0x020600
4856 scsi_remove_host(host);
4859 WRT_REG_WORD(&ha->iobase->ictrl, 0);
4861 free_irq(pdev->irq, ha);
4863 #if MEMORY_MAPPED_IO
4864 iounmap(ha->mmpbase);
4866 release_region(host->io_port, 0xff);
4869 pci_free_consistent(ha->pdev,
4870 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4871 ha->request_ring, ha->request_dma);
4872 pci_free_consistent(ha->pdev,
4873 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4874 ha->response_ring, ha->response_dma);
4876 pci_disable_device(pdev);
4878 scsi_host_put(host);
4881 #if LINUX_VERSION_CODE >= 0x020600
4882 static struct pci_driver qla1280_pci_driver = {
4884 .id_table = qla1280_pci_tbl,
4885 .probe = qla1280_probe_one,
4886 .remove = __devexit_p(qla1280_remove_one),
4892 if (sizeof(struct srb) > sizeof(struct scsi_pointer)) {
4894 "qla1280: struct srb too big, aborting\n");
4900 * If we are called as a module, the qla1280 pointer may not be null
4901 * and it would point to our bootup string, just like on the lilo
4902 * command line. IF not NULL, then process this config string with
4906 * To add options at boot time add a line to your lilo.conf file like:
4907 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
4908 * which will result in the first four devices on the first two
4909 * controllers being set to a tagged queue depth of 32.
4912 qla1280_setup(qla1280);
4915 return pci_module_init(&qla1280_pci_driver);
4921 pci_unregister_driver(&qla1280_pci_driver);
4924 module_init(qla1280_init);
4925 module_exit(qla1280_exit);
4928 # define driver_template qla1280_driver_template
4929 # include "scsi_module.c"
4932 MODULE_AUTHOR("Qlogic & Jes Sorensen");
4933 MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
4934 MODULE_LICENSE("GPL");
4935 MODULE_VERSION(QLA1280_VERSION);
4938 * Overrides for Emacs so that we almost follow Linus's tabbing style.
4939 * Emacs will notice this stuff at the end of the file and automatically
4940 * adjust the settings for this buffer only. This must remain at the end
4942 * ---------------------------------------------------------------------------