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 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.3"
21 /*****************************************************************************
23 Rev 3.24.3 January 19, 2004, Jes Sorensen
24 - Handle PCI DMA mask settings correctly
25 - Correct order of error handling in probe_one, free_irq should not
26 be called if request_irq failed
27 Rev 3.24.2 January 19, 2004, James Bottomley & Andrew Vasquez
28 - Big endian fixes (James)
29 - Remove bogus IOCB content on zero data transfer commands (Andrew)
30 Rev 3.24.1 January 5, 2004, Jes Sorensen
31 - Initialize completion queue to avoid OOPS on probe
32 - Handle interrupts during mailbox testing
33 Rev 3.24 November 17, 2003, Christoph Hellwig
34 - use struct list_head for completion queue
35 - avoid old Scsi_FOO typedefs
36 - cleanup 2.4 compat glue a bit
37 - use <scsi/scsi_*.h> headers on 2.6 instead of "scsi.h"
38 - make initialization for memory mapped vs port I/O more similar
39 - remove broken pci config space manipulation
41 - this is an almost perfect 2.6 scsi driver now! ;)
42 Rev 3.23.39 December 17, 2003, Jes Sorensen
43 - Delete completion queue from srb if mailbox command failed to
44 to avoid qla1280_done completeting qla1280_error_action's
46 - Reduce arguments for qla1280_done
47 Rev 3.23.38 October 18, 2003, Christoph Hellwig
48 - Convert to new-style hotplugable driver for 2.6
49 - Fix missing scsi_unregister/scsi_host_put on HBA removal
50 - Kill some more cruft
51 Rev 3.23.37 October 1, 2003, Jes Sorensen
52 - Make MMIO depend on CONFIG_X86_VISWS instead of yet another
54 - Clean up locking in probe path
55 Rev 3.23.36 October 1, 2003, Christoph Hellwig
56 - queuecommand only ever receives new commands - clear flags
57 - Reintegrate lost fixes from Linux 2.5
58 Rev 3.23.35 August 14, 2003, Jes Sorensen
60 Rev 3.23.34 July 23, 2003, Jes Sorensen
61 - Remove pointless TRUE/FALSE macros
62 - Clean up vchan handling
63 Rev 3.23.33 July 3, 2003, Jes Sorensen
64 - Don't define register access macros before define determining MMIO.
65 This just happend to work out on ia64 but not elsewhere.
66 - Don't try and read from the card while it is in reset as
67 it won't respond and causes an MCA
68 Rev 3.23.32 June 23, 2003, Jes Sorensen
69 - Basic support for boot time arguments
70 Rev 3.23.31 June 8, 2003, Jes Sorensen
71 - Reduce boot time messages
72 Rev 3.23.30 June 6, 2003, Jes Sorensen
73 - Do not enable sync/wide/ppr before it has been determined
74 that the target device actually supports it
75 - Enable DMA arbitration for multi channel controllers
76 Rev 3.23.29 June 3, 2003, Jes Sorensen
78 Rev 3.23.28 June 3, 2003, Jes Sorensen
79 - Eliminate duplicate marker commands on bus resets
80 - Handle outstanding commands appropriately on bus/device resets
81 Rev 3.23.27 May 28, 2003, Jes Sorensen
82 - Remove bogus input queue code, let the Linux SCSI layer do the work
83 - Clean up NVRAM handling, only read it once from the card
84 - Add a number of missing default nvram parameters
85 Rev 3.23.26 Beta May 28, 2003, Jes Sorensen
86 - Use completion queue for mailbox commands instead of busy wait
87 Rev 3.23.25 Beta May 27, 2003, James Bottomley
88 - Migrate to use new error handling code
89 Rev 3.23.24 Beta May 21, 2003, James Bottomley
91 - Cleanup data direction code
92 Rev 3.23.23 Beta May 12, 2003, Jes Sorensen
93 - Switch to using MMIO instead of PIO
94 Rev 3.23.22 Beta April 15, 2003, Jes Sorensen
95 - Fix PCI parity problem with 12160 during reset.
96 Rev 3.23.21 Beta April 14, 2003, Jes Sorensen
97 - Use pci_map_page()/pci_unmap_page() instead of map_single version.
98 Rev 3.23.20 Beta April 9, 2003, Jes Sorensen
99 - Remove < 2.4.x support
100 - Introduce HOST_LOCK to make the spin lock changes portable.
101 - Remove a bunch of idiotic and unnecessary typedef's
102 - Kill all leftovers of target-mode support which never worked anyway
103 Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
104 - Do qla1280_pci_config() before calling request_irq() and
106 - Use pci_dma_hi32() to handle upper word of DMA addresses instead
108 - Hand correct arguments to free_irq() in case of failure
109 Rev 3.23.18 Beta April 11, 2002, Jes Sorensen
110 - Run source through Lindent and clean up the output
111 Rev 3.23.17 Beta April 11, 2002, Jes Sorensen
112 - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32
113 Rev 3.23.16 Beta March 19, 2002, Jes Sorensen
114 - Rely on mailbox commands generating interrupts - do not
115 run qla1280_isr() from ql1280_mailbox_command()
116 - Remove device_reg_t
117 - Integrate ql12160_set_target_parameters() with 1280 version
118 - Make qla1280_setup() non static
119 - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request
120 sent to the card - this command pauses the firmare!!!
121 Rev 3.23.15 Beta March 19, 2002, Jes Sorensen
122 - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions
123 - Remove a pile of pointless and confusing (srb_t **) and
124 (scsi_lu_t *) typecasts
125 - Explicit mark that we do not use the new error handling (for now)
126 - Remove scsi_qla_host_t and use 'struct' instead
127 - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled,
128 pci_64bit_slot flags which weren't used for anything anyway
129 - Grab host->host_lock while calling qla1280_isr() from abort()
130 - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we
131 do not need to save/restore flags in the interrupt handler
132 - Enable interrupts early (before any mailbox access) in preparation
133 for cleaning up the mailbox handling
134 Rev 3.23.14 Beta March 14, 2002, Jes Sorensen
135 - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace
136 it with proper use of dprintk().
137 - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take
138 a debug level argument to determine if data is to be printed
139 - Add KERN_* info to printk()
140 Rev 3.23.13 Beta March 14, 2002, Jes Sorensen
141 - Significant cosmetic cleanups
142 - Change debug code to use dprintk() and remove #if mess
143 Rev 3.23.12 Beta March 13, 2002, Jes Sorensen
144 - More cosmetic cleanups, fix places treating return as function
145 - use cpu_relax() in qla1280_debounce_register()
146 Rev 3.23.11 Beta March 13, 2002, Jes Sorensen
147 - Make it compile under 2.5.5
148 Rev 3.23.10 Beta October 1, 2001, Jes Sorensen
149 - Do no typecast short * to long * in QL1280BoardTbl, this
150 broke miserably on big endian boxes
151 Rev 3.23.9 Beta September 30, 2001, Jes Sorensen
152 - Remove pre 2.2 hack for checking for reentrance in interrupt handler
153 - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32
154 unsigned int to match the types from struct scsi_cmnd
155 Rev 3.23.8 Beta September 29, 2001, Jes Sorensen
156 - Remove bogus timer_t typedef from qla1280.h
157 - Remove obsolete pre 2.2 PCI setup code, use proper #define's
158 for PCI_ values, call pci_set_master()
159 - Fix memleak of qla1280_buffer on module unload
160 - Only compile module parsing code #ifdef MODULE - should be
161 changed to use individual MODULE_PARM's later
162 - Remove dummy_buffer that was never modified nor printed
163 - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove
164 #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls
165 - Remove \r from print statements, this is Linux, not DOS
166 - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK}
168 - Remove C++ compile hack in header file as Linux driver are not
169 supposed to be compiled as C++
170 - Kill MS_64BITS macro as it makes the code more readable
171 - Remove unnecessary flags.in_interrupts bit
172 Rev 3.23.7 Beta August 20, 2001, Jes Sorensen
173 - Dont' check for set flags on q->q_flag one by one in qla1280_next()
174 - Check whether the interrupt was generated by the QLA1280 before
176 - qla1280_status_entry(): Only zero out part of sense_buffer that
177 is not being copied into
178 - Remove more superflouous typecasts
179 - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy()
180 Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel
181 - Don't walk the entire list in qla1280_putq_t() just to directly
182 grab the pointer to the last element afterwards
183 Rev 3.23.5 Beta August 9, 2001, Jes Sorensen
184 - Don't use SA_INTERRUPT, it's use is deprecated for this kinda driver
185 Rev 3.23.4 Beta August 8, 2001, Jes Sorensen
186 - Set dev->max_sectors to 1024
187 Rev 3.23.3 Beta August 6, 2001, Jes Sorensen
188 - Provide compat macros for pci_enable_device(), pci_find_subsys()
189 and scsi_set_pci_device()
190 - Call scsi_set_pci_device() for all devices
191 - Reduce size of kernel version dependent device probe code
192 - Move duplicate probe/init code to separate function
193 - Handle error if qla1280_mem_alloc() fails
194 - Kill OFFSET() macro and use Linux's PCI definitions instead
195 - Kill private structure defining PCI config space (struct config_reg)
196 - Only allocate I/O port region if not in MMIO mode
197 - Remove duplicate (unused) sanity check of sife of srb_t
198 Rev 3.23.2 Beta August 6, 2001, Jes Sorensen
199 - Change home-brew memset() implementations to use memset()
200 - Remove all references to COMTRACE() - accessing a PC's COM2 serial
201 port directly is not legal under Linux.
202 Rev 3.23.1 Beta April 24, 2001, Jes Sorensen
203 - Remove pre 2.2 kernel support
204 - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat)
205 - Fix MMIO access to use readl/writel instead of directly
206 dereferencing pointers
207 - Nuke MSDOS debugging code
208 - Change true/false data types to int from uint8_t
209 - Use int for counters instead of uint8_t etc.
210 - Clean up size & byte order conversion macro usage
211 Rev 3.23 Beta January 11, 2001 BN Qlogic
212 - Added check of device_id when handling non
213 QLA12160s during detect().
214 Rev 3.22 Beta January 5, 2001 BN Qlogic
215 - Changed queue_task() to schedule_task()
216 for kernels 2.4.0 and higher.
217 Note: 2.4.0-testxx kernels released prior to
218 the actual 2.4.0 kernel release on January 2001
219 will get compile/link errors with schedule_task().
220 Please update your kernel to released 2.4.0 level,
221 or comment lines in this file flagged with 3.22
222 to resolve compile/link error of schedule_task().
223 - Added -DCONFIG_SMP in addition to -D__SMP__
224 in Makefile for 2.4.0 builds of driver as module.
225 Rev 3.21 Beta January 4, 2001 BN Qlogic
226 - Changed criteria of 64/32 Bit mode of HBA
227 operation according to BITS_PER_LONG rather
228 than HBA's NVRAM setting of >4Gig memory bit;
229 so that the HBA auto-configures without the need
230 to setup each system individually.
231 Rev 3.20 Beta December 5, 2000 BN Qlogic
232 - Added priority handling to IA-64 onboard SCSI
233 ISP12160 chip for kernels greater than 2.3.18.
234 - Added irqrestore for qla1280_intr_handler.
235 - Enabled /proc/scsi/qla1280 interface.
236 - Clear /proc/scsi/qla1280 counters in detect().
237 Rev 3.19 Beta October 13, 2000 BN Qlogic
238 - Declare driver_template for new kernel
239 (2.4.0 and greater) scsi initialization scheme.
240 - Update /proc/scsi entry for 2.3.18 kernels and
242 Rev 3.18 Beta October 10, 2000 BN Qlogic
243 - Changed scan order of adapters to map
244 the QLA12160 followed by the QLA1280.
245 Rev 3.17 Beta September 18, 2000 BN Qlogic
246 - Removed warnings for 32 bit 2.4.x compiles
247 - Corrected declared size for request and response
248 DMA addresses that are kept in each ha
249 Rev. 3.16 Beta August 25, 2000 BN Qlogic
250 - Corrected 64 bit addressing issue on IA-64
251 where the upper 32 bits were not properly
252 passed to the RISC engine.
253 Rev. 3.15 Beta August 22, 2000 BN Qlogic
254 - Modified qla1280_setup_chip to properly load
255 ISP firmware for greater that 4 Gig memory on IA-64
256 Rev. 3.14 Beta August 16, 2000 BN Qlogic
257 - Added setting of dma_mask to full 64 bit
258 if flags.enable_64bit_addressing is set in NVRAM
259 Rev. 3.13 Beta August 16, 2000 BN Qlogic
260 - Use new PCI DMA mapping APIs for 2.4.x kernel
261 Rev. 3.12 July 18, 2000 Redhat & BN Qlogic
262 - Added check of pci_enable_device to detect() for 2.3.x
263 - Use pci_resource_start() instead of
264 pdev->resource[0].start in detect() for 2.3.x
265 - Updated driver version
266 Rev. 3.11 July 14, 2000 BN Qlogic
267 - Updated SCSI Firmware to following versions:
270 - Updated driver version to 3.11
271 Rev. 3.10 June 23, 2000 BN Qlogic
272 - Added filtering of AMI SubSys Vendor ID devices
274 - DEBUG_QLA1280 undefined and new version BN Qlogic
275 Rev. 3.08b May 9, 2000 MD Dell
276 - Added logic to check against AMI subsystem vendor ID
277 Rev. 3.08 May 4, 2000 DG Qlogic
278 - Added logic to check for PCI subsystem ID.
279 Rev. 3.07 Apr 24, 2000 DG & BN Qlogic
280 - Updated SCSI Firmware to following versions:
283 Rev. 3.06 Apr 12, 2000 DG & BN Qlogic
284 - Internal revision; not released
285 Rev. 3.05 Mar 28, 2000 DG & BN Qlogic
286 - Edit correction for virt_to_bus and PROC.
287 Rev. 3.04 Mar 28, 2000 DG & BN Qlogic
288 - Merge changes from ia64 port.
289 Rev. 3.03 Mar 28, 2000 BN Qlogic
290 - Increase version to reflect new code drop with compile fix
291 of issue with inclusion of linux/spinlock for 2.3 kernels
292 Rev. 3.02 Mar 15, 2000 BN Qlogic
293 - Merge qla1280_proc_info from 2.10 code base
294 Rev. 3.01 Feb 10, 2000 BN Qlogic
295 - Corrected code to compile on a 2.2.x kernel.
296 Rev. 3.00 Jan 17, 2000 DG Qlogic
297 - Added 64-bit support.
298 Rev. 2.07 Nov 9, 1999 DG Qlogic
299 - Added new routine to set target parameters for ISP12160.
300 Rev. 2.06 Sept 10, 1999 DG Qlogic
301 - Added support for ISP12160 Ultra 3 chip.
302 Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
303 - Modified code to remove errors generated when compiling with
304 Cygnus IA64 Compiler.
305 - Changed conversion of pointers to unsigned longs instead of integers.
306 - Changed type of I/O port variables from uint32_t to unsigned long.
307 - Modified OFFSET macro to work with 64-bit as well as 32-bit.
308 - Changed sprintf and printk format specifiers for pointers to %p.
309 - Changed some int to long type casts where needed in sprintf & printk.
310 - Added l modifiers to sprintf and printk format specifiers for longs.
311 - Removed unused local variables.
312 Rev. 1.20 June 8, 1999 DG, Qlogic
313 Changes to support RedHat release 6.0 (kernel 2.2.5).
314 - Added SCSI exclusive access lock (io_request_lock) when accessing
316 - Added changes for the new LINUX interface template. Some new error
317 handling routines have been added to the template, but for now we
318 will use the old ones.
319 - Initial Beta Release.
320 *****************************************************************************/
323 #include <linux/config.h>
324 #include <linux/module.h>
326 #include <linux/version.h>
327 #include <linux/types.h>
328 #include <linux/string.h>
329 #include <linux/errno.h>
330 #include <linux/kernel.h>
331 #include <linux/ioport.h>
332 #include <linux/delay.h>
333 #include <linux/timer.h>
334 #include <linux/sched.h>
335 #include <linux/pci.h>
336 #include <linux/proc_fs.h>
337 #include <linux/stat.h>
338 #include <linux/slab.h>
339 #include <linux/pci_ids.h>
340 #include <linux/interrupt.h>
341 #include <linux/init.h>
345 #include <asm/byteorder.h>
346 #include <asm/processor.h>
347 #include <asm/types.h>
348 #include <asm/system.h>
350 #if LINUX_VERSION_CODE >= 0x020545
351 #include <scsi/scsi.h>
352 #include <scsi/scsi_cmnd.h>
353 #include <scsi/scsi_device.h>
354 #include <scsi/scsi_host.h>
355 #include <scsi/scsi_tcq.h>
358 #include <linux/blk.h>
364 #if LINUX_VERSION_CODE < 0x020407
365 #error "Kernels older than 2.4.7 are no longer supported"
370 * Compile time Options:
371 * 0 - Disable and 1 - Enable
373 #define DEBUG_QLA1280_INTR 0
374 #define DEBUG_PRINT_NVRAM 0
375 #define DEBUG_QLA1280 0
378 * The SGI VISWS is broken and doesn't support MMIO ;-(
380 #ifdef CONFIG_X86_VISWS
381 #define MEMORY_MAPPED_IO 0
383 #define MEMORY_MAPPED_IO 1
386 #define UNIQUE_FW_NAME
388 #include "ql12160_fw.h" /* ISP RISC codes */
389 #include "ql1280_fw.h"
395 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1080
396 #define PCI_DEVICE_ID_QLOGIC_ISP1080 0x1080
398 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1240
399 #define PCI_DEVICE_ID_QLOGIC_ISP1240 0x1240
401 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1280
402 #define PCI_DEVICE_ID_QLOGIC_ISP1280 0x1280
404 #ifndef PCI_DEVICE_ID_QLOGIC_ISP10160
405 #define PCI_DEVICE_ID_QLOGIC_ISP10160 0x1016
407 #ifndef PCI_DEVICE_ID_QLOGIC_ISP12160
408 #define PCI_DEVICE_ID_QLOGIC_ISP12160 0x1216
411 #ifndef PCI_VENDOR_ID_AMI
412 #define PCI_VENDOR_ID_AMI 0x101e
415 #ifndef BITS_PER_LONG
416 #error "BITS_PER_LONG not defined!"
418 #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
419 #define QLA_64BIT_PTR 1
422 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
423 #include <asm/sn/pci/pciio.h>
424 /* Ugly hack needed for the virtual channel fix on SN2 */
425 extern int snia_pcibr_rrb_alloc(struct pci_dev *pci_dev,
426 int *count_vchan0, int *count_vchan1);
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))
488 static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *);
489 static void qla1280_remove_one(struct pci_dev *);
492 * QLogic Driver Support Function Prototypes.
494 static void qla1280_done(struct scsi_qla_host *);
495 #if LINUX_VERSION_CODE < 0x020545
496 static void qla1280_get_target_options(struct scsi_cmnd *, struct scsi_qla_host *);
498 static int qla1280_get_token(char *);
499 static int qla1280_setup(char *s) __init;
502 * QLogic ISP1280 Hardware Support Function Prototypes.
504 static int qla1280_isp_firmware(struct scsi_qla_host *);
505 static int qla1280_chip_diag(struct scsi_qla_host *);
506 static int qla1280_setup_chip(struct scsi_qla_host *);
507 static int qla1280_init_rings(struct scsi_qla_host *);
508 static int qla1280_nvram_config(struct scsi_qla_host *);
509 static int qla1280_mailbox_command(struct scsi_qla_host *,
510 uint8_t, uint16_t *);
511 static int qla1280_bus_reset(struct scsi_qla_host *, int);
512 static int qla1280_device_reset(struct scsi_qla_host *, int, int);
513 static int qla1280_abort_device(struct scsi_qla_host *, int, int, int);
514 static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int);
515 static int qla1280_abort_isp(struct scsi_qla_host *);
517 static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *);
519 static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *);
521 static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
522 static void qla1280_poll(struct scsi_qla_host *);
523 static void qla1280_reset_adapter(struct scsi_qla_host *);
524 static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
525 static void qla1280_isp_cmd(struct scsi_qla_host *);
526 static void qla1280_isr(struct scsi_qla_host *, struct list_head *);
527 static void qla1280_rst_aen(struct scsi_qla_host *);
528 static void qla1280_status_entry(struct scsi_qla_host *, struct response *,
530 static void qla1280_error_entry(struct scsi_qla_host *, struct response *,
532 static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
533 static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
534 static uint16_t qla1280_debounce_register(volatile uint16_t *);
535 static request_t *qla1280_req_pkt(struct scsi_qla_host *);
536 static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
538 static void qla1280_get_target_parameters(struct scsi_qla_host *,
539 struct scsi_device *);
540 static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int);
543 static struct qla_driver_setup driver_setup __initdata;
546 * convert scsi data direction to request_t control flags
548 static inline uint16_t
549 qla1280_data_direction(struct scsi_cmnd *cmnd)
551 switch(cmnd->sc_data_direction) {
552 case DMA_FROM_DEVICE:
556 case DMA_BIDIRECTIONAL:
557 return BIT_5 | BIT_6;
559 * We could BUG() on default here if one of the four cases aren't
560 * met, but then again if we receive something like that from the
561 * SCSI layer we have more serious problems. This shuts up GCC.
570 static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd);
571 static void __qla1280_dump_buffer(char *, int);
576 * insmod needs to find the variable and make it point to something
579 static char *qla1280;
581 /* insmod qla1280 options=verbose" */
582 MODULE_PARM(qla1280, "s");
584 __setup("qla1280=", qla1280_setup);
589 * We use the scsi_pointer structure that's included with each scsi_command
590 * to overlay our struct srb over it. qla1280_init() checks that a srb is not
591 * bigger than a scsi_pointer.
594 #define CMD_SP(Cmnd) &Cmnd->SCp
595 #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
596 #define CMD_CDBP(Cmnd) Cmnd->cmnd
597 #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
598 #define CMD_SNSLEN(Cmnd) sizeof(Cmnd->sense_buffer)
599 #define CMD_RESULT(Cmnd) Cmnd->result
600 #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
601 #if LINUX_VERSION_CODE < 0x020545
602 #define CMD_REQUEST(Cmnd) Cmnd->request.cmd
604 #define CMD_REQUEST(Cmnd) Cmnd->request->cmd
607 #define CMD_HOST(Cmnd) Cmnd->device->host
608 #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
609 #define SCSI_TCN_32(Cmnd) Cmnd->device->id
610 #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
613 /*****************************************/
614 /* ISP Boards supported by this driver */
615 /*****************************************/
618 unsigned char name[9]; /* Board ID String */
619 int numPorts; /* Number of SCSI ports */
620 unsigned short *fwcode; /* pointer to FW array */
621 unsigned short *fwlen; /* number of words in array */
622 unsigned short *fwstart; /* start address for F/W */
623 unsigned char *fwver; /* Ptr to F/W version array */
626 /* NOTE: qla1280_pci_tbl and ql1280_board_tbl must be in the same order */
627 static struct pci_device_id qla1280_pci_tbl[] = {
628 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP12160,
629 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
630 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1080,
631 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
632 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1240,
633 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
634 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1280,
635 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
636 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP10160,
637 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
640 MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl);
642 static struct qla_boards ql1280_board_tbl[] = {
643 /* Name , Number of ports, FW details */
644 {"QLA12160", 2, &fw12160i_code01[0], &fw12160i_length01,
645 &fw12160i_addr01, &fw12160i_version_str[0]},
646 {"QLA1080", 1, &fw1280ei_code01[0], &fw1280ei_length01,
647 &fw1280ei_addr01, &fw1280ei_version_str[0]},
648 {"QLA1240", 2, &fw1280ei_code01[0], &fw1280ei_length01,
649 &fw1280ei_addr01, &fw1280ei_version_str[0]},
650 {"QLA1280", 2, &fw1280ei_code01[0], &fw1280ei_length01,
651 &fw1280ei_addr01, &fw1280ei_version_str[0]},
652 {"QLA10160", 1, &fw12160i_code01[0], &fw12160i_length01,
653 &fw12160i_addr01, &fw12160i_version_str[0]},
657 static int qla1280_verbose = 1;
658 static int qla1280_buffer_size;
659 static char *qla1280_buffer;
662 static int ql_debug_level = 1;
663 #define dprintk(level, format, a...) \
664 do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
665 #define qla1280_dump_buffer(level, buf, size) \
666 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
667 #define qla1280_print_scsi_cmd(level, cmd) \
668 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
670 #define ql_debug_level 0
671 #define dprintk(level, format, a...) do{}while(0)
672 #define qla1280_dump_buffer(a, b, c) do{}while(0)
673 #define qla1280_print_scsi_cmd(a, b) do{}while(0)
676 #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
677 #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
678 #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
679 #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
682 /*************************************************************************
686 * Return information to handle /proc support for the driver.
688 * buffer - ptrs to a page buffer
691 *************************************************************************/
692 #define PROC_BUF &qla1280_buffer[len]
694 static int qla1280_proc_info(struct Scsi_Host *host, char *buffer,
695 char **start, off_t offset, int length, int inout)
697 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
698 struct qla_boards *bdp = &ql1280_board_tbl[ha->devnum];
706 * if our old buffer is the right size use it otherwise
707 * allocate a new one.
709 if (qla1280_buffer_size != PAGE_SIZE) {
710 /* deallocate this buffer and get a new one */
711 if (qla1280_buffer != NULL) {
712 free_page((unsigned long)qla1280_buffer);
713 qla1280_buffer_size = 0;
715 qla1280_buffer = (char *)get_zeroed_page(GFP_KERNEL);
717 if (qla1280_buffer == NULL) {
718 size = sprintf(buffer, "qla1280 - kmalloc error at line %d\n",
722 /* save the size of our buffer */
723 qla1280_buffer_size = PAGE_SIZE;
725 /* 3.20 clear the buffer we use for proc display */
726 memset(qla1280_buffer, 0, PAGE_SIZE);
728 /* start building the print buffer */
729 size = sprintf(PROC_BUF,
730 "QLogic PCI to SCSI Adapter for ISP 1280/12160:\n"
731 " Firmware version: %2d.%02d.%02d, Driver version %s\n",
732 bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
737 size = sprintf(PROC_BUF, "SCSI Host Adapter Information: %s\n",
740 size = sprintf(PROC_BUF, "Request Queue count= 0x%x, Response "
741 "Queue count= 0x%x\n",
742 REQUEST_ENTRY_CNT, RESPONSE_ENTRY_CNT);
744 size = sprintf(PROC_BUF, "Number of pending commands = 0x%lx\n",
747 size = sprintf(PROC_BUF, "Number of free request entries = %d\n",
750 size = sprintf(PROC_BUF, "\n"); /* 1 */
753 if (len >= qla1280_buffer_size) {
755 "qla1280: Overflow buffer in qla1280_proc.c\n");
758 if (offset > len - 1) {
759 free_page((unsigned long) qla1280_buffer);
760 qla1280_buffer = NULL;
761 qla1280_buffer_size = length = 0;
764 *start = &qla1280_buffer[offset]; /* Start of wanted data */
765 if (len - offset < length) {
766 length = len - offset;
773 static int qla1280_read_nvram(struct scsi_qla_host *ha)
780 ENTER("qla1280_read_nvram");
782 if (driver_setup.no_nvram)
785 printk(KERN_INFO "scsi(%ld): Reading NVRAM\n", ha->host_no);
787 wptr = (uint16_t *)&ha->nvram;
790 for (cnt = 0; cnt < 3; cnt++) {
791 *wptr = qla1280_get_nvram_word(ha, cnt);
792 chksum += *wptr & 0xff;
793 chksum += (*wptr >> 8) & 0xff;
797 if (nv->id0 != 'I' || nv->id1 != 'S' ||
798 nv->id2 != 'P' || nv->id3 != ' ' || nv->version < 1) {
799 dprintk(2, "Invalid nvram ID or version!\n");
802 for (; cnt < sizeof(struct nvram); cnt++) {
803 *wptr = qla1280_get_nvram_word(ha, cnt);
804 chksum += *wptr & 0xff;
805 chksum += (*wptr >> 8) & 0xff;
810 dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
811 " version %i\n", nv->id0, nv->id1, nv->id2, nv->id3,
816 if (!driver_setup.no_nvram)
817 printk(KERN_WARNING "scsi(%ld): Unable to identify or "
818 "validate NVRAM checksum, using default "
819 "settings\n", ha->host_no);
824 /* The firmware interface is, um, interesting, in that the
825 * actual firmware image on the chip is little endian, thus,
826 * the process of taking that image to the CPU would end up
827 * little endian. However, the firmare interface requires it
828 * to be read a word (two bytes) at a time.
830 * The net result of this would be that the word (and
831 * doubleword) quantites in the firmware would be correct, but
832 * the bytes would be pairwise reversed. Since most of the
833 * firmware quantites are, in fact, bytes, we do an extra
834 * le16_to_cpu() in the firmware read routine.
836 * The upshot of all this is that the bytes in the firmware
837 * are in the correct places, but the 16 and 32 bit quantites
838 * are still in little endian format. We fix that up below by
839 * doing extra reverses on them */
840 nv->isp_parameter = cpu_to_le16(nv->isp_parameter);
841 nv->firmware_feature.w = cpu_to_le16(nv->firmware_feature.w);
842 for(i = 0; i < MAX_BUSES; i++) {
843 nv->bus[i].selection_timeout = cpu_to_le16(nv->bus[i].selection_timeout);
844 nv->bus[i].max_queue_depth = cpu_to_le16(nv->bus[i].max_queue_depth);
846 dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
847 LEAVE("qla1280_read_nvram");
852 /**************************************************************************
854 * Return a string describing the driver.
855 **************************************************************************/
857 qla1280_info(struct Scsi_Host *host)
859 static char qla1280_scsi_name_buffer[125];
861 struct scsi_qla_host *ha;
862 struct qla_boards *bdp;
864 bp = &qla1280_scsi_name_buffer[0];
865 ha = (struct scsi_qla_host *)host->hostdata;
866 bdp = &ql1280_board_tbl[ha->devnum];
867 memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
870 "QLogic %s PCI to SCSI Host Adapter\n"
871 " Firmware version: %2d.%02d.%02d, Driver version %s",
872 &bdp->name[0], bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
877 /**************************************************************************
878 * qla1200_queuecommand
879 * Queue a command to the controller.
882 * The mid-level driver tries to ensures that queuecommand never gets invoked
883 * concurrently with itself or the interrupt handler (although the
884 * interrupt handler may call this routine as part of request-completion
885 * handling). Unfortunely, it sometimes calls the scheduler in interrupt
886 * context which is a big NO! NO!.
887 **************************************************************************/
889 qla1280_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
891 struct Scsi_Host *host = cmd->device->host;
892 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
893 struct srb *sp = (struct srb *)&cmd->SCp;
900 qla1280_print_scsi_cmd(5, cmd);
904 * Using 64 bit commands if the PCI bridge doesn't support it is a
905 * bit wasteful, however this should really only happen if one's
906 * PCI controller is completely broken, like the BCM1250. For
907 * sane hardware this is not an issue.
909 status = qla1280_64bit_start_scsi(ha, sp);
911 status = qla1280_32bit_start_scsi(ha, sp);
925 /* timer action for error action processor */
926 static void qla1280_error_wait_timeout(unsigned long __data)
928 struct scsi_cmnd *cmd = (struct scsi_cmnd *)__data;
929 struct srb *sp = (struct srb *)CMD_SP(cmd);
934 static void qla1280_mailbox_timeout(unsigned long __data)
936 struct scsi_qla_host *ha = (struct scsi_qla_host *)__data;
937 struct device_reg *reg;
940 ha->mailbox_out[0] = RD_REG_WORD(®->mailbox0);
941 printk(KERN_ERR "scsi(%ld): mailbox timed out, mailbox0 %04x, "
942 "ictrl %04x, istatus %04x\n", ha->host_no, ha->mailbox_out[0],
943 RD_REG_WORD(®->ictrl), RD_REG_WORD(®->istatus));
944 complete(ha->mailbox_wait);
947 /**************************************************************************
948 * qla1200_error_action
949 * The function will attempt to perform a specified error action and
950 * wait for the results (or time out).
953 * cmd = Linux SCSI command packet of the command that cause the
955 * action = error action to take (see action_t)
961 * Resetting the bus always succeeds - is has to, otherwise the
962 * kernel will panic! Try a surgical technique - sending a BUS
963 * DEVICE RESET message - on the offending target before pulling
964 * the SCSI bus reset line.
965 **************************************************************************/
967 qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
969 struct scsi_qla_host *ha;
970 int bus, target, lun;
973 unsigned char *handle;
975 DECLARE_COMPLETION(wait);
976 struct timer_list timer;
978 ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
980 dprintk(4, "error_action %i, istatus 0x%04x\n", action,
981 RD_REG_WORD(&ha->iobase->istatus));
983 dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
984 RD_REG_WORD(&ha->iobase->host_cmd),
985 RD_REG_WORD(&ha->iobase->ictrl), jiffies);
987 ENTER("qla1280_error_action");
989 printk(KERN_INFO "scsi(%li): Resetting Cmnd=0x%p, "
990 "Handle=0x%p, action=0x%x\n",
991 ha->host_no, cmd, CMD_HANDLE(cmd), action);
994 printk(KERN_WARNING "(scsi?:?:?:?) Reset called with NULL "
995 "si_Cmnd pointer, failing.\n");
996 LEAVE("qla1280_error_action");
1000 ha = (struct scsi_qla_host *)cmd->device->host->hostdata;
1001 sp = (struct srb *)CMD_SP(cmd);
1002 handle = CMD_HANDLE(cmd);
1004 /* Check for pending interrupts. */
1005 data = qla1280_debounce_register(&ha->iobase->istatus);
1007 * The io_request_lock is held when the reset handler is called, hence
1008 * the interrupt handler cannot be running in parallel as it also
1009 * grabs the lock. /Jes
1011 if (data & RISC_INT)
1012 qla1280_isr(ha, &ha->done_q);
1015 * Determine the suggested action that the mid-level driver wants
1018 if (handle == (unsigned char *)INVALID_HANDLE || handle == NULL) {
1019 if(action == ABORT_COMMAND) {
1020 /* we never got this command */
1021 printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
1022 return SUCCESS; /* no action - we don't have command */
1028 bus = SCSI_BUS_32(cmd);
1029 target = SCSI_TCN_32(cmd);
1030 lun = SCSI_LUN_32(cmd);
1032 /* Overloading result. Here it means the success or fail of the
1033 * *issue* of the action. When we return from the routine, it must
1034 * mean the actual success or fail of the action */
1041 if ((sp->flags & SRB_ABORT_PENDING)) {
1043 "scsi(): Command has a pending abort "
1044 "message - ABORT_PENDING.\n");
1045 /* This should technically be impossible since we
1046 * now wait for abort completion */
1050 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
1051 if (sp == ha->outstanding_cmds[i]) {
1052 dprintk(1, "qla1280: RISC aborting command\n");
1053 if (qla1280_abort_command(ha, sp, i) == 0)
1057 * Since we don't know what might
1058 * have happend to the command, it
1059 * is unsafe to remove it from the
1060 * device's queue at this point.
1061 * Wait and let the escalation
1062 * process take care of it.
1065 "scsi(%li:%i:%i:%i): Unable"
1066 " to abort command!\n",
1067 ha->host_no, bus, target, lun);
1074 ha->flags.in_reset = 1;
1075 if (qla1280_verbose)
1077 "scsi(%ld:%d:%d:%d): Queueing abort device "
1078 "command.\n", ha->host_no, bus, target, lun);
1079 if (qla1280_abort_device(ha, bus, target, lun) == 0)
1084 if (qla1280_verbose)
1086 "scsi(%ld:%d:%d:%d): Queueing device reset "
1087 "command.\n", ha->host_no, bus, target, lun);
1088 ha->flags.in_reset = 1;
1089 if (qla1280_device_reset(ha, bus, target) == 0)
1094 if (qla1280_verbose)
1095 printk(KERN_INFO "qla1280(%ld:%d): Issuing BUS "
1096 "DEVICE RESET\n", ha->host_no, bus);
1097 ha->flags.in_reset = 1;
1098 if (qla1280_bus_reset(ha, bus == 0))
1105 if (qla1280_verbose) {
1107 "scsi(%ld): Issued ADAPTER RESET\n",
1109 printk(KERN_INFO "scsi(%ld): I/O processing will "
1110 "continue automatically\n", ha->host_no);
1112 ha->flags.reset_active = 1;
1114 * We restarted all of the commands automatically, so the
1115 * mid-level code can expect completions momentitarily.
1117 if (qla1280_abort_isp(ha) == 0)
1120 ha->flags.reset_active = 0;
1123 if (!list_empty(&ha->done_q))
1125 ha->flags.in_reset = 0;
1127 /* If we didn't manage to issue the action, or we have no
1128 * command to wait for, exit here */
1129 if (result == FAILED || handle == NULL ||
1130 handle == (unsigned char *)INVALID_HANDLE) {
1132 * Clear completion queue to avoid qla1280_done() trying
1133 * to complete the command at a later stage after we
1134 * have exited the current context
1140 /* set up a timer just in case we're really jammed */
1142 timer.expires = jiffies + 4*HZ;
1143 timer.data = (unsigned long)cmd;
1144 timer.function = qla1280_error_wait_timeout;
1147 /* wait for the action to complete (or the timer to expire) */
1148 spin_unlock_irq(HOST_LOCK);
1149 wait_for_completion(&wait);
1150 del_timer_sync(&timer);
1151 spin_lock_irq(HOST_LOCK);
1154 /* the only action we might get a fail for is abort */
1155 if (action == ABORT_COMMAND) {
1156 if(sp->flags & SRB_ABORTED)
1163 dprintk(1, "RESET returning %d\n", result);
1165 LEAVE("qla1280_error_action");
1169 /**************************************************************************
1171 * Abort the specified SCSI command(s).
1172 **************************************************************************/
1174 qla1280_eh_abort(struct scsi_cmnd * cmd)
1176 return qla1280_error_action(cmd, ABORT_COMMAND);
1179 /**************************************************************************
1180 * qla1280_device_reset
1181 * Reset the specified SCSI device
1182 **************************************************************************/
1184 qla1280_eh_device_reset(struct scsi_cmnd *cmd)
1186 return qla1280_error_action(cmd, DEVICE_RESET);
1189 /**************************************************************************
1191 * Reset the specified bus.
1192 **************************************************************************/
1194 qla1280_eh_bus_reset(struct scsi_cmnd *cmd)
1196 return qla1280_error_action(cmd, BUS_RESET);
1199 /**************************************************************************
1200 * qla1280_adapter_reset
1201 * Reset the specified adapter (both channels)
1202 **************************************************************************/
1204 qla1280_eh_adapter_reset(struct scsi_cmnd *cmd)
1206 return qla1280_error_action(cmd, ADAPTER_RESET);
1210 qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1211 sector_t capacity, int geom[])
1213 int heads, sectors, cylinders;
1217 cylinders = (unsigned long)capacity / (heads * sectors);
1218 if (cylinders > 1024) {
1221 cylinders = (unsigned long)capacity / (heads * sectors);
1222 /* if (cylinders > 1023)
1223 cylinders = 1023; */
1228 geom[2] = cylinders;
1233 #if LINUX_VERSION_CODE < 0x020600
1235 qla1280_detect(Scsi_Host_Template *template)
1237 struct pci_device_id *id = &qla1280_pci_tbl[0];
1238 struct pci_dev *pdev = NULL;
1241 if (sizeof(struct srb) > sizeof(Scsi_Pointer)) {
1243 "qla1280: struct srb too big, aborting\n");
1247 if ((DMA_BIDIRECTIONAL != PCI_DMA_BIDIRECTIONAL) ||
1248 (DMA_TO_DEVICE != PCI_DMA_TODEVICE) ||
1249 (DMA_FROM_DEVICE != PCI_DMA_FROMDEVICE) ||
1250 (DMA_NONE != PCI_DMA_NONE)) {
1252 "qla1280: dma direction bits don't match\n");
1258 * If we are called as a module, the qla1280 pointer may not be null
1259 * and it would point to our bootup string, just like on the lilo
1260 * command line. IF not NULL, then process this config string with
1264 * To add options at boot time add a line to your lilo.conf file like:
1265 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
1266 * which will result in the first four devices on the first two
1267 * controllers being set to a tagged queue depth of 32.
1270 qla1280_setup(qla1280);
1273 /* First Initialize QLA12160 on PCI Bus 1 Dev 2 */
1274 while ((pdev = pci_find_device(id->vendor, id->device, pdev))) {
1275 if (pdev->bus->number == 1 && PCI_SLOT(pdev->devfn) == 2) {
1276 if (!qla1280_probe_one(pdev, id))
1282 /* Try and find each different type of adapter we support */
1283 for (id = &qla1280_pci_tbl[0]; id->device; id++) {
1284 while ((pdev = pci_find_device(id->vendor, id->device, pdev))) {
1286 * skip QLA12160 already initialized on
1287 * PCI Bus 1 Dev 2 since we already initialized
1290 if (id->device == PCI_DEVICE_ID_QLOGIC_ISP12160 &&
1291 pdev->bus->number == 1 &&
1292 PCI_SLOT(pdev->devfn) == 2)
1295 if (!qla1280_probe_one(pdev, id))
1304 * This looks a bit ugly as we could just pass down host to
1305 * qla1280_remove_one, but I want to keep qla1280_release purely a wrapper
1306 * around pci_driver::remove as used from 2.6 onwards.
1309 qla1280_release(struct Scsi_Host *host)
1311 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
1313 qla1280_remove_one(ha->pdev);
1318 qla1280_biosparam_old(Disk * disk, kdev_t dev, int geom[])
1320 return qla1280_biosparam(disk->device, NULL, disk->capacity, geom);
1324 qla1280_proc_info_old(char *buffer, char **start, off_t offset, int length,
1325 int hostno, int inout)
1327 struct Scsi_Host *host;
1329 for (host = scsi_hostlist; host; host = host->next) {
1330 if (host->host_no == hostno) {
1331 return qla1280_proc_info(host, buffer, start,
1332 offset, length, inout);
1340 /**************************************************************************
1341 * qla1280_intr_handler
1342 * Handles the H/W interrupt
1343 **************************************************************************/
1345 qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1347 struct scsi_qla_host *ha;
1348 struct device_reg *reg;
1352 ENTER_INTR ("qla1280_intr_handler");
1353 ha = (struct scsi_qla_host *)dev_id;
1355 spin_lock(HOST_LOCK);
1360 WRT_REG_WORD(®->ictrl, 0); /* disable our interrupt. */
1362 data = qla1280_debounce_register(®->istatus);
1363 /* Check for pending interrupts. */
1364 if (data & RISC_INT) {
1365 qla1280_isr(ha, &ha->done_q);
1368 if (!list_empty(&ha->done_q))
1371 spin_unlock(HOST_LOCK);
1373 /* enable our interrupt. */
1374 WRT_REG_WORD(®->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1376 LEAVE_INTR("qla1280_intr_handler");
1377 return IRQ_RETVAL(handled);
1382 qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
1385 uint16_t mb[MAILBOX_REGISTER_COUNT];
1387 int is1x160, status;
1391 if (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160 ||
1392 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160)
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);
1407 mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
1409 mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
1410 mb[3] |= nv->bus[bus].target[target].sync_period;
1413 mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
1414 mb[6] = nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8;
1415 mb[6] |= nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
1419 status = qla1280_mailbox_command(ha, mr, &mb[0]);
1422 printk(KERN_WARNING "scsi(%ld:%i:%i): "
1423 "qla1280_set_target_parameters() failed\n",
1424 ha->host_no, bus, target);
1429 /**************************************************************************
1430 * qla1280_slave_configure
1433 * Determines the queue depth for a given device. There are two ways
1434 * a queue depth can be obtained for a tagged queueing device. One
1435 * way is the default queue depth which is determined by whether
1436 * If it is defined, then it is used
1437 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1438 * default queue depth (dependent on the number of hardware SCBs).
1439 **************************************************************************/
1441 qla1280_slave_configure(struct scsi_device *device)
1443 struct scsi_qla_host *ha;
1444 int default_depth = 3;
1445 int bus = device->channel;
1446 int target = device->id;
1449 unsigned long flags;
1451 ha = (struct scsi_qla_host *)device->host->hostdata;
1454 if (qla1280_check_for_dead_scsi_bus(ha, bus))
1457 if (device->tagged_supported &&
1458 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1459 scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
1460 ha->bus_settings[bus].hiwat);
1462 scsi_adjust_queue_depth(device, 0, default_depth);
1465 #if LINUX_VERSION_CODE > 0x020500
1466 nv->bus[bus].target[target].parameter.f.enable_sync = device->sdtr;
1467 nv->bus[bus].target[target].parameter.f.enable_wide = device->wdtr;
1468 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
1471 if (driver_setup.no_sync ||
1472 (driver_setup.sync_mask &&
1473 (~driver_setup.sync_mask & (1 << target))))
1474 nv->bus[bus].target[target].parameter.f.enable_sync = 0;
1475 if (driver_setup.no_wide ||
1476 (driver_setup.wide_mask &&
1477 (~driver_setup.wide_mask & (1 << target))))
1478 nv->bus[bus].target[target].parameter.f.enable_wide = 0;
1479 if (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160 ||
1480 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160) {
1481 if (driver_setup.no_ppr ||
1482 (driver_setup.ppr_mask &&
1483 (~driver_setup.ppr_mask & (1 << target))))
1484 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
1487 spin_lock_irqsave(HOST_LOCK, flags);
1488 if (nv->bus[bus].target[target].parameter.f.enable_sync)
1489 status = qla1280_set_target_parameters(ha, bus, target);
1490 qla1280_get_target_parameters(ha, device);
1491 spin_unlock_irqrestore(HOST_LOCK, flags);
1495 #if LINUX_VERSION_CODE < 0x020545
1496 /**************************************************************************
1497 * qla1280_select_queue_depth
1499 * Sets the queue depth for each SCSI device hanging off the input
1500 * host adapter. We use a queue depth of 2 for devices that do not
1501 * support tagged queueing.
1502 **************************************************************************/
1504 qla1280_select_queue_depth(struct Scsi_Host *host, struct scsi_device *sdev_q)
1506 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
1507 struct scsi_device *sdev;
1509 ENTER("qla1280_select_queue_depth");
1510 for (sdev = sdev_q; sdev; sdev = sdev->next)
1511 if (sdev->host == host)
1512 qla1280_slave_configure(sdev);
1515 qla1280_check_for_dead_scsi_bus(ha, sdev_q->channel);
1516 LEAVE("qla1280_select_queue_depth");
1522 * Process completed commands.
1525 * ha = adapter block pointer.
1526 * done_q = done queue.
1529 qla1280_done(struct scsi_qla_host *ha)
1532 struct list_head *done_q;
1533 int bus, target, lun;
1534 struct scsi_cmnd *cmd;
1536 ENTER("qla1280_done");
1538 done_q = &ha->done_q;
1540 while (!list_empty(done_q)) {
1541 sp = list_entry(done_q->next, struct srb, list);
1543 list_del(&sp->list);
1546 bus = SCSI_BUS_32(cmd);
1547 target = SCSI_TCN_32(cmd);
1548 lun = SCSI_LUN_32(cmd);
1550 switch ((CMD_RESULT(cmd) >> 16)) {
1552 /* Issue marker command. */
1553 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
1556 sp->flags &= ~SRB_ABORT_PENDING;
1557 sp->flags |= SRB_ABORTED;
1558 if (sp->flags & SRB_TIMEOUT)
1559 CMD_RESULT(sp->cmd) = DID_TIME_OUT << 16;
1565 /* Release memory used for this I/O */
1567 dprintk(3, "S/G unmap_sg cmd=%p\n", cmd);
1569 pci_unmap_sg(ha->pdev, cmd->request_buffer,
1570 cmd->use_sg, cmd->sc_data_direction);
1571 } else if (cmd->request_bufflen) {
1572 /*dprintk(1, "No S/G unmap_single cmd=%x saved_dma_handle=%lx\n",
1573 cmd, sp->saved_dma_handle); */
1575 pci_unmap_page(ha->pdev, sp->saved_dma_handle,
1576 cmd->request_bufflen, cmd->sc_data_direction);
1579 /* Call the mid-level driver interrupt handler */
1580 CMD_HANDLE(sp->cmd) = (unsigned char *)INVALID_HANDLE;
1583 #if LINUX_VERSION_CODE < 0x020500
1584 if (cmd->cmnd[0] == INQUIRY)
1585 qla1280_get_target_options(cmd, ha);
1587 (*(cmd)->scsi_done)(cmd);
1589 if(sp->wait != NULL)
1592 LEAVE("qla1280_done");
1596 * Translates a ISP error to a Linux SCSI error
1599 qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1601 int host_status = DID_ERROR;
1602 uint16_t comp_status = le16_to_cpu(sts->comp_status);
1603 uint16_t state_flags = le16_to_cpu(sts->state_flags);
1604 uint16_t residual_length = le16_to_cpu(sts->residual_length);
1605 uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
1606 #if DEBUG_QLA1280_INTR
1607 static char *reason[] = {
1619 #endif /* DEBUG_QLA1280_INTR */
1621 ENTER("qla1280_return_status");
1623 #if DEBUG_QLA1280_INTR
1625 dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
1630 switch (comp_status) {
1632 host_status = DID_OK;
1636 if (!(state_flags & SF_GOT_BUS))
1637 host_status = DID_NO_CONNECT;
1638 else if (!(state_flags & SF_GOT_TARGET))
1639 host_status = DID_BAD_TARGET;
1640 else if (!(state_flags & SF_SENT_CDB))
1641 host_status = DID_ERROR;
1642 else if (!(state_flags & SF_TRANSFERRED_DATA))
1643 host_status = DID_ERROR;
1644 else if (!(state_flags & SF_GOT_STATUS))
1645 host_status = DID_ERROR;
1646 else if (!(state_flags & SF_GOT_SENSE))
1647 host_status = DID_ERROR;
1651 host_status = DID_RESET;
1655 host_status = DID_ABORT;
1659 host_status = DID_TIME_OUT;
1662 case CS_DATA_OVERRUN:
1663 dprintk(2, "Data overrun 0x%x\n", residual_length);
1664 dprintk(2, "qla1280_isr: response packet data\n");
1665 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
1666 host_status = DID_ERROR;
1669 case CS_DATA_UNDERRUN:
1670 if ((cp->request_bufflen - residual_length) <
1673 "scsi: Underflow detected - retrying "
1675 host_status = DID_ERROR;
1677 host_status = DID_OK;
1681 host_status = DID_ERROR;
1685 #if DEBUG_QLA1280_INTR
1686 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
1687 reason[host_status], scsi_status);
1690 LEAVE("qla1280_return_status");
1692 return (scsi_status & 0xff) | (host_status << 16);
1695 /****************************************************************************/
1696 /* QLogic ISP1280 Hardware Support Functions. */
1697 /****************************************************************************/
1700 * qla2100_enable_intrs
1701 * qla2100_disable_intrs
1704 * ha = adapter block pointer.
1710 qla1280_enable_intrs(struct scsi_qla_host *ha)
1712 struct device_reg *reg;
1715 /* enable risc and host interrupts */
1716 WRT_REG_WORD(®->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1717 RD_REG_WORD(®->ictrl); /* PCI Posted Write flush */
1718 ha->flags.ints_enabled = 1;
1722 qla1280_disable_intrs(struct scsi_qla_host *ha)
1724 struct device_reg *reg;
1727 /* disable risc and host interrupts */
1728 WRT_REG_WORD(®->ictrl, 0);
1729 RD_REG_WORD(®->ictrl); /* PCI Posted Write flush */
1730 ha->flags.ints_enabled = 0;
1734 * qla1280_initialize_adapter
1738 * ha = adapter block pointer.
1743 static int __devinit
1744 qla1280_initialize_adapter(struct scsi_qla_host *ha)
1746 struct device_reg *reg;
1749 #if LINUX_VERSION_CODE > 0x020500
1750 unsigned long flags;
1753 ENTER("qla1280_initialize_adapter");
1755 /* Clear adapter flags. */
1756 ha->flags.online = 0;
1757 ha->flags.disable_host_adapter = 0;
1758 ha->flags.reset_active = 0;
1759 ha->flags.abort_isp_active = 0;
1761 ha->flags.ints_enabled = 0;
1762 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1763 if (ia64_platform_is("sn2")) {
1769 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
1770 "dual channel lockup workaround\n", ha->host_no);
1771 if ((c = snia_pcibr_rrb_alloc(ha->pdev, &count1, &count2)) < 0)
1772 printk(KERN_ERR "scsi(%li): Unable to allocate SN2 "
1773 "virtual DMA channels\n", ha->host_no);
1775 ha->flags.use_pci_vchannel = 1;
1777 driver_setup.no_nvram = 1;
1781 dprintk(1, "Configure PCI space for adapter...\n");
1785 /* Insure mailbox registers are free. */
1786 WRT_REG_WORD(®->semaphore, 0);
1787 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
1788 WRT_REG_WORD(®->host_cmd, HC_CLR_HOST_INT);
1789 RD_REG_WORD(®->host_cmd);
1791 if (qla1280_read_nvram(ha)) {
1792 dprintk(2, "qla1280_initialize_adapter: failed to read "
1796 #if LINUX_VERSION_CODE >= 0x020500
1798 * It's necessary to grab the spin here as qla1280_mailbox_command
1799 * needs to be able to drop the lock unconditionally to wait
1801 * In 2.4 ->detect is called with the io_request_lock held.
1803 spin_lock_irqsave(HOST_LOCK, flags);
1805 /* If firmware needs to be loaded */
1806 if (qla1280_isp_firmware(ha)) {
1807 if (!(status = qla1280_chip_diag(ha))) {
1808 status = qla1280_setup_chip(ha);
1811 printk(KERN_ERR "scsi(%li): isp_firmware() failed!\n",
1817 printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
1822 /* Setup adapter based on NVRAM parameters. */
1823 dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha->host_no);
1824 qla1280_nvram_config(ha);
1826 if (!ha->flags.disable_host_adapter && !qla1280_init_rings(ha)) {
1827 /* Issue SCSI reset. */
1828 /* dg 03/13 if we can't reset twice then bus is dead */
1829 for (bus = 0; bus < ha->ports; bus++) {
1830 if (!ha->bus_settings[bus].disable_scsi_reset){
1831 if (qla1280_bus_reset(ha, bus)) {
1832 if (qla1280_bus_reset(ha, bus)) {
1833 ha->bus_settings[bus].scsi_bus_dead = 1;
1840 * qla1280_bus_reset() will take care of issueing markers,
1841 * no need to do that here as well!
1844 /* Issue marker command. */
1845 ha->flags.reset_marker = 0;
1846 for (bus = 0; bus < ha->ports; bus++) {
1847 ha->bus_settings[bus].reset_marker = 0;
1848 qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
1852 ha->flags.online = 1;
1857 #if LINUX_VERSION_CODE >= 0x020500
1858 spin_unlock_irqrestore(HOST_LOCK, flags);
1861 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
1863 LEAVE("qla1280_initialize_adapter");
1870 * Checks if present version of RISC firmware is older than
1874 * ha = adapter block pointer.
1877 * 0 = firmware does not need to be loaded.
1880 qla1280_isp_firmware(struct scsi_qla_host *ha)
1882 struct nvram *nv = (struct nvram *) ha->response_ring;
1883 int status = 0; /* dg 2/27 always loads RISC */
1884 uint16_t mb[MAILBOX_REGISTER_COUNT];
1886 ENTER("qla1280_isp_firmware");
1888 dprintk(1, "scsi(%li): Determining if RISC is loaded\n", ha->host_no);
1890 /* Bad NVRAM data, load RISC code. */
1891 if (!ha->nvram_valid) {
1892 ha->flags.disable_risc_code_load = 0;
1894 ha->flags.disable_risc_code_load =
1895 nv->cntr_flags_1.disable_loading_risc_code;
1897 if (ha->flags.disable_risc_code_load) {
1898 dprintk(3, "qla1280_isp_firmware: Telling RISC to verify "
1899 "checksum of loaded BIOS code.\n");
1901 /* Verify checksum of loaded RISC code. */
1902 mb[0] = MBC_VERIFY_CHECKSUM;
1903 /* mb[1] = ql12_risc_code_addr01; */
1904 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1907 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]))) {
1908 /* Start firmware execution. */
1909 dprintk(3, "qla1280_isp_firmware: Startng F/W "
1912 mb[0] = MBC_EXECUTE_FIRMWARE;
1913 /* mb[1] = ql12_risc_code_addr01; */
1914 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1915 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
1917 printk(KERN_INFO "qla1280: RISC checksum failed.\n");
1919 dprintk(1, "qla1280: NVRAM configured to load RISC load.\n");
1924 dprintk(2, "qla1280_isp_firmware: **** Load RISC code ****\n");
1926 LEAVE("qla1280_isp_firmware");
1932 * Test chip for proper operation.
1935 * ha = adapter block pointer.
1941 qla1280_chip_diag(struct scsi_qla_host *ha)
1943 uint16_t mb[MAILBOX_REGISTER_COUNT];
1944 struct device_reg *reg = ha->iobase;
1949 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®->id_l);
1951 dprintk(1, "scsi(%ld): Verifying chip\n", ha->host_no);
1953 /* Soft reset chip and wait for it to finish. */
1954 WRT_REG_WORD(®->ictrl, ISP_RESET);
1956 * We can't do a traditional PCI write flush here by reading
1957 * back the register. The card will not respond once the reset
1958 * is in action and we end up with a machine check exception
1959 * instead. Nothing to do but wait and hope for the best.
1960 * A portable pci_write_flush(pdev) call would be very useful here.
1963 data = qla1280_debounce_register(®->ictrl);
1965 * Yet another QLogic gem ;-(
1967 for (cnt = 1000000; cnt && data & ISP_RESET; cnt--) {
1969 data = RD_REG_WORD(®->ictrl);
1973 /* Reset register cleared by chip reset. */
1974 dprintk(3, "qla1280_chip_diag: reset register cleared by "
1977 WRT_REG_WORD(®->cfg_1, 0);
1979 /* Reset RISC and disable BIOS which
1980 allows RISC to execute out of RAM. */
1982 WRT_REG_WORD(®->host_cmd, HC_RESET_RISC);
1983 RD_REG_WORD(®->id_l); /* Flush PCI write */
1984 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
1985 RD_REG_WORD(®->id_l); /* Flush PCI write */
1986 WRT_REG_WORD(®->host_cmd, HC_DISABLE_BIOS);
1988 WRT_REG_WORD(®->host_cmd, HC_RESET_RISC |
1989 HC_RELEASE_RISC | HC_DISABLE_BIOS);
1991 RD_REG_WORD(®->id_l); /* Flush PCI write */
1992 data = qla1280_debounce_register(®->mailbox0);
1994 * I *LOVE* this code!
1996 for (cnt = 1000000; cnt && data == MBS_BUSY; cnt--) {
1998 data = RD_REG_WORD(®->mailbox0);
2002 /* Check product ID of chip */
2003 dprintk(3, "qla1280_chip_diag: Checking product "
2006 if (RD_REG_WORD(®->mailbox1) != PROD_ID_1 ||
2007 (RD_REG_WORD(®->mailbox2) != PROD_ID_2 &&
2008 RD_REG_WORD(®->mailbox2) != PROD_ID_2a) ||
2009 RD_REG_WORD(®->mailbox3) != PROD_ID_3 ||
2010 RD_REG_WORD(®->mailbox4) != PROD_ID_4) {
2011 printk(KERN_INFO "qla1280: Wrong product ID = "
2012 "0x%x,0x%x,0x%x,0x%x\n",
2013 RD_REG_WORD(®->mailbox1),
2014 RD_REG_WORD(®->mailbox2),
2015 RD_REG_WORD(®->mailbox3),
2016 RD_REG_WORD(®->mailbox4));
2020 * Enable ints early!!!
2022 qla1280_enable_intrs(ha);
2024 dprintk(1, "qla1280_chip_diag: Checking "
2025 "mailboxes of chip\n");
2026 /* Wrap Incoming Mailboxes Test. */
2027 mb[0] = MBC_MAILBOX_REGISTER_TEST;
2035 if (!(status = qla1280_mailbox_command(ha,
2039 if (mb[1] != 0xAAAA ||
2047 printk(KERN_INFO "qla1280: "
2048 "Failed mbox check\n");
2058 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
2060 dprintk(3, "qla1280_chip_diag: exiting normally\n");
2067 * Load and start RISC firmware.
2070 * ha = adapter block pointer.
2075 #define DUMP_IT_BACK 0 /* for debug of RISC loading */
2077 qla1280_setup_chip(struct scsi_qla_host *ha)
2080 uint16_t risc_address;
2081 uint16_t *risc_code_address;
2083 uint16_t mb[MAILBOX_REGISTER_COUNT];
2092 ENTER("qla1280_setup_chip");
2094 dprintk(1, "scsi(%ld): Setup chip\n", ha->host_no);
2097 /* get consistent memory allocated for setup_chip */
2098 tbuf = pci_alloc_consistent(ha->pdev, 8000, &p_tbuf);
2101 /* Load RISC code. */
2102 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
2103 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
2104 risc_code_size = (int) *ql1280_board_tbl[ha->devnum].fwlen;
2106 dprintk(1, "qla1280_setup_chip: DMA RISC code (%i) words\n",
2110 while (risc_code_size > 0 && !status) {
2111 int warn __attribute__((unused)) = 0;
2115 if (cnt > risc_code_size)
2116 cnt = risc_code_size;
2118 dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
2120 risc_code_address, cnt, num, risc_address);
2121 for(i = 0; i < cnt; i++)
2122 ((uint16_t *)ha->request_ring)[i] =
2123 cpu_to_le16(risc_code_address[i]);
2125 mb[0] = MBC_LOAD_RAM;
2126 mb[1] = risc_address;
2128 mb[3] = ha->request_dma & 0xffff;
2129 mb[2] = (ha->request_dma >> 16) & 0xffff;
2130 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2131 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2132 dprintk(2, "qla1280_setup_chip: op=%d 0x%p = 0x%4x,0x%4x,"
2133 "0x%4x,0x%4x\n", mb[0], (void *)(long)ha->request_dma,
2134 mb[6], mb[7], mb[2], mb[3]);
2135 if ((status = qla1280_mailbox_command(ha, BIT_4 | BIT_3 |
2136 BIT_2 | BIT_1 | BIT_0,
2138 printk(KERN_ERR "scsi(%li): Failed to load partial "
2139 "segment of f\n", ha->host_no);
2144 mb[0] = MBC_DUMP_RAM;
2145 mb[1] = risc_address;
2147 mb[3] = p_tbuf & 0xffff;
2148 mb[2] = (p_tbuf >> 16) & 0xffff;
2149 mb[7] = pci_dma_hi32(p_tbuf) & 0xffff;
2150 mb[6] = pci_dma_hi32(p_tbuf) >> 16;
2152 if ((status = qla1280_mailbox_command(ha,
2153 BIT_4 | BIT_3 | BIT_2 |
2157 "Failed to dump partial segment of f/w\n");
2160 sp = (uint8_t *)ha->request_ring;
2161 for (i = 0; i < (cnt << 1); i++) {
2162 if (tbuf[i] != sp[i] && warn++ < 10) {
2163 printk(KERN_ERR "qla1280_setup_chip: FW "
2164 "compare error @ byte(0x%x) loop#=%x\n",
2166 printk(KERN_ERR "setup_chip: FWbyte=%x "
2167 "FWfromChip=%x\n", sp[i], tbuf[i]);
2172 risc_address += cnt;
2173 risc_code_size = risc_code_size - cnt;
2174 risc_code_address = risc_code_address + cnt;
2178 /* Verify checksum of loaded RISC code. */
2180 dprintk(1, "qla1280_setup_chip: Verifying checksum of "
2181 "loaded RISC code.\n");
2182 mb[0] = MBC_VERIFY_CHECKSUM;
2183 /* mb[1] = ql12_risc_code_addr01; */
2184 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2187 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]))) {
2188 /* Start firmware execution. */
2190 "qla1280_setup_chip: start firmware running.\n");
2191 mb[0] = MBC_EXECUTE_FIRMWARE;
2192 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2193 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2195 printk(KERN_ERR "scsi(%li): qla1280_setup_chip: "
2196 "Failed checksum\n", ha->host_no);
2200 /* free consistent memory allocated for setup_chip */
2201 pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
2205 dprintk(2, "qla1280_setup_chip: **** FAILED ****\n");
2207 LEAVE("qla1280_setup_chip");
2215 * ha = adapter block pointer.
2216 * ha->request_ring = request ring virtual address
2217 * ha->response_ring = response ring virtual address
2218 * ha->request_dma = request ring physical address
2219 * ha->response_dma = response ring physical address
2225 qla1280_init_rings(struct scsi_qla_host *ha)
2227 uint16_t mb[MAILBOX_REGISTER_COUNT];
2230 ENTER("qla1280_init_rings");
2232 /* Clear outstanding commands array. */
2233 memset(ha->outstanding_cmds, 0,
2234 sizeof(struct srb *) * MAX_OUTSTANDING_COMMANDS);
2236 /* Initialize request queue. */
2237 ha->request_ring_ptr = ha->request_ring;
2238 ha->req_ring_index = 0;
2239 ha->req_q_cnt = REQUEST_ENTRY_CNT;
2240 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
2241 mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
2242 mb[1] = REQUEST_ENTRY_CNT;
2243 mb[3] = ha->request_dma & 0xffff;
2244 mb[2] = (ha->request_dma >> 16) & 0xffff;
2246 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2247 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2248 if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
2249 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2251 /* Initialize response queue. */
2252 ha->response_ring_ptr = ha->response_ring;
2253 ha->rsp_ring_index = 0;
2254 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
2255 mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
2256 mb[1] = RESPONSE_ENTRY_CNT;
2257 mb[3] = ha->response_dma & 0xffff;
2258 mb[2] = (ha->response_dma >> 16) & 0xffff;
2260 mb[7] = pci_dma_hi32(ha->response_dma) & 0xffff;
2261 mb[6] = pci_dma_hi32(ha->response_dma) >> 16;
2262 status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
2263 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2268 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
2270 LEAVE("qla1280_init_rings");
2275 * NVRAM configuration.
2278 * ha = adapter block pointer.
2279 * ha->request_ring = request ring virtual address
2282 * host adapters parameters in host adapter block
2288 qla1280_nvram_config(struct scsi_qla_host *ha)
2290 struct device_reg *reg = ha->iobase;
2292 int is1x160, status = 0;
2293 int bus, target, lun;
2294 uint16_t mb[MAILBOX_REGISTER_COUNT];
2297 ENTER("qla1280_nvram_config");
2299 if (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160 ||
2300 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160)
2306 if (!ha->nvram_valid) {
2307 dprintk(1, "Using defaults for NVRAM: \n");
2308 memset(nv, 0, sizeof(struct nvram));
2310 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
2311 nv->firmware_feature.f.enable_fast_posting = 1;
2312 nv->firmware_feature.f.disable_synchronous_backoff = 1;
2314 nv->termination.f.scsi_bus_0_control = 3;
2315 nv->termination.f.scsi_bus_1_control = 3;
2316 nv->termination.f.auto_term_support = 1;
2319 * Set default FIFO magic - What appropriate values
2320 * would be here is unknown. This is what I have found
2321 * testing with 12160s.
2322 * Now, I would love the magic decoder ring for this one,
2323 * the header file provided by QLogic seems to be bogus
2324 * or incomplete at best.
2326 nv->isp_config.c = 0x44;
2329 nv->isp_parameter = 0x01;
2331 for (bus = 0; bus < MAX_BUSES; bus++) {
2332 nv->bus[bus].config_1.initiator_id = 7;
2333 nv->bus[bus].bus_reset_delay = 5;
2334 /* 8 = 5.0 clocks */
2335 nv->bus[bus].config_2.async_data_setup_time = 8;
2336 nv->bus[bus].config_2.req_ack_active_negation = 1;
2337 nv->bus[bus].config_2.data_line_active_negation = 1;
2338 nv->bus[bus].selection_timeout = 250;
2339 nv->bus[bus].max_queue_depth = 256;
2341 for (target = 0; target < MAX_TARGETS; target++) {
2342 nv->bus[bus].target[target].parameter.f.
2343 renegotiate_on_error = 1;
2344 nv->bus[bus].target[target].parameter.f.
2345 auto_request_sense = 1;
2346 nv->bus[bus].target[target].parameter.f.
2348 nv->bus[bus].target[target].parameter.f.
2350 #if 1 /* Some SCSI Processors do not seem to like this */
2351 nv->bus[bus].target[target].parameter.f.
2354 nv->bus[bus].target[target].parameter.f.
2355 parity_checking = 1;
2356 nv->bus[bus].target[target].parameter.f.
2357 disconnect_allowed = 1;
2358 nv->bus[bus].target[target].execution_throttle=
2359 nv->bus[bus].max_queue_depth - 1;
2361 nv->bus[bus].target[target].flags.
2362 flags1x160.device_enable = 1;
2363 nv->bus[bus].target[target].flags.
2364 flags1x160.sync_offset = 0x0e;
2365 nv->bus[bus].target[target].
2367 nv->bus[bus].target[target].
2368 ppr_1x160.flags.enable_ppr = 1;
2369 nv->bus[bus].target[target].ppr_1x160.
2370 flags.ppr_options = 2;
2371 nv->bus[bus].target[target].ppr_1x160.
2372 flags.ppr_bus_width = 1;
2374 nv->bus[bus].target[target].flags.
2375 flags1x80.device_enable = 1;
2376 nv->bus[bus].target[target].flags.
2377 flags1x80.sync_offset = 0x8;
2378 nv->bus[bus].target[target].
2384 /* Always force AUTO sense for LINUX SCSI */
2385 for (bus = 0; bus < MAX_BUSES; bus++)
2386 for (target = 0; target < MAX_TARGETS; target++) {
2387 nv->bus[bus].target[target].parameter.f.
2388 auto_request_sense = 1;
2391 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
2392 nv->bus[0].config_1.initiator_id);
2393 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
2394 nv->bus[1].config_1.initiator_id);
2396 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
2397 nv->bus[0].bus_reset_delay);
2398 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
2399 nv->bus[1].bus_reset_delay);
2401 dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
2402 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
2403 dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
2404 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
2406 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
2407 nv->bus[0].config_2.async_data_setup_time);
2408 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
2409 nv->bus[1].config_2.async_data_setup_time);
2411 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
2412 nv->bus[0].config_2.req_ack_active_negation);
2413 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
2414 nv->bus[1].config_2.req_ack_active_negation);
2416 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
2417 nv->bus[0].config_2.data_line_active_negation);
2418 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
2419 nv->bus[1].config_2.data_line_active_negation);
2421 dprintk(1, "qla1280 : disable loading risc code=%d\n",
2422 nv->cntr_flags_1.disable_loading_risc_code);
2424 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
2425 nv->cntr_flags_1.enable_64bit_addressing);
2427 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
2428 nv->bus[0].selection_timeout);
2429 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
2430 nv->bus[1].selection_timeout);
2432 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
2433 nv->bus[0].max_queue_depth);
2434 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
2435 nv->bus[1].max_queue_depth);
2437 /* Disable RISC load of firmware. */
2438 ha->flags.disable_risc_code_load =
2439 nv->cntr_flags_1.disable_loading_risc_code;
2441 /* Set ISP hardware DMA burst */
2442 mb[0] = nv->isp_config.c;
2443 /* Enable DMA arbitration on dual channel controllers */
2446 WRT_REG_WORD(®->cfg_1, mb[0]);
2448 #if 1 /* Is this safe? */
2449 /* Set SCSI termination. */
2450 WRT_REG_WORD(®->gpio_enable, (BIT_3 + BIT_2 + BIT_1 + BIT_0));
2451 mb[0] = nv->termination.c & (BIT_3 + BIT_2 + BIT_1 + BIT_0);
2452 WRT_REG_WORD(®->gpio_data, mb[0]);
2455 /* ISP parameter word. */
2456 mb[0] = MBC_SET_SYSTEM_PARAMETER;
2457 mb[1] = nv->isp_parameter;
2458 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2461 /* clock rate - for qla1240 and older, only */
2462 mb[0] = MBC_SET_CLOCK_RATE;
2464 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2466 /* Firmware feature word. */
2467 mb[0] = MBC_SET_FIRMWARE_FEATURES;
2468 mask = BIT_5 | BIT_1 | BIT_0;
2469 mb[1] = le16_to_cpu(nv->firmware_feature.w) & (mask);
2470 #if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
2471 if (ia64_platform_is("sn2")) {
2472 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
2473 "workaround\n", ha->host_no);
2477 status |= qla1280_mailbox_command(ha, mask, &mb[0]);
2479 /* Retry count and delay. */
2480 mb[0] = MBC_SET_RETRY_COUNT;
2481 mb[1] = nv->bus[0].retry_count;
2482 mb[2] = nv->bus[0].retry_delay;
2483 mb[6] = nv->bus[1].retry_count;
2484 mb[7] = nv->bus[1].retry_delay;
2485 status |= qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 |
2486 BIT_1 | BIT_0, &mb[0]);
2488 /* ASYNC data setup time. */
2489 mb[0] = MBC_SET_ASYNC_DATA_SETUP;
2490 mb[1] = nv->bus[0].config_2.async_data_setup_time;
2491 mb[2] = nv->bus[1].config_2.async_data_setup_time;
2492 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2494 /* Active negation states. */
2495 mb[0] = MBC_SET_ACTIVE_NEGATION;
2497 if (nv->bus[0].config_2.req_ack_active_negation)
2499 if (nv->bus[0].config_2.data_line_active_negation)
2502 if (nv->bus[1].config_2.req_ack_active_negation)
2504 if (nv->bus[1].config_2.data_line_active_negation)
2506 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2508 mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
2509 mb[1] = 2; /* Reset SCSI bus and return all outstanding IO */
2510 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2513 mb[0] = MBC_SET_PCI_CONTROL;
2514 mb[1] = 2; /* Data DMA Channel Burst Enable */
2515 mb[2] = 2; /* Command DMA Channel Burst Enable */
2516 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2518 /* Selection timeout. */
2519 mb[0] = MBC_SET_SELECTION_TIMEOUT;
2520 mb[1] = nv->bus[0].selection_timeout;
2521 mb[2] = nv->bus[1].selection_timeout;
2522 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2524 for (bus = 0; bus < ha->ports; bus++) {
2525 /* SCSI Reset Disable. */
2526 ha->bus_settings[bus].disable_scsi_reset =
2527 nv->bus[bus].config_1.scsi_reset_disable;
2530 ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
2531 mb[0] = MBC_SET_INITIATOR_ID;
2532 mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
2533 ha->bus_settings[bus].id;
2534 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2537 ha->bus_settings[bus].bus_reset_delay =
2538 nv->bus[bus].bus_reset_delay;
2540 /* Command queue depth per device. */
2541 ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
2543 /* Set target parameters. */
2544 for (target = 0; target < MAX_TARGETS; target++) {
2545 uint8_t mr = BIT_2 | BIT_1 | BIT_0;
2547 /* Set Target Parameters. */
2548 mb[0] = MBC_SET_TARGET_PARAMETERS;
2549 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
2552 * Do not enable wide, sync, and ppr for the initial
2553 * INQUIRY run. We enable this later if we determine
2554 * the target actually supports it.
2556 nv->bus[bus].target[target].parameter.f.
2557 auto_request_sense = 1;
2558 nv->bus[bus].target[target].parameter.f.
2559 stop_queue_on_check = 0;
2562 nv->bus[bus].target[target].ppr_1x160.
2563 flags.enable_ppr = 0;
2565 * No sync, wide, etc. while probing
2567 mb[2] = (nv->bus[bus].target[target].parameter.c << 8)&
2568 ~(TP_SYNC /*| TP_WIDE | TP_PPR*/);
2571 mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
2573 mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
2574 mb[3] |= nv->bus[bus].target[target].sync_period;
2578 * We don't want to enable ppr etc. before we have
2579 * determined that the target actually supports it
2583 mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
2585 mb[6] = nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8;
2586 mb[6] |= nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
2591 status = qla1280_mailbox_command(ha, mr, &mb[0]);
2593 /* Save Tag queuing enable flag. */
2594 mb[0] = BIT_0 << target;
2595 if (nv->bus[bus].target[target].parameter.f.tag_queuing)
2596 ha->bus_settings[bus].qtag_enables |= mb[0];
2598 /* Save Device enable flag. */
2600 if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
2601 ha->bus_settings[bus].device_enables |= mb[0];
2602 ha->bus_settings[bus].lun_disables |= 0;
2604 if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
2605 ha->bus_settings[bus].device_enables |= mb[0];
2606 /* Save LUN disable flag. */
2607 if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
2608 ha->bus_settings[bus].lun_disables |= mb[0];
2612 /* Set Device Queue Parameters. */
2613 for (lun = 0; lun < MAX_LUNS; lun++) {
2614 mb[0] = MBC_SET_DEVICE_QUEUE;
2615 mb[1] = (uint16_t)(bus ? target | BIT_7 : target);
2616 mb[1] = mb[1] << 8 | lun;
2617 mb[2] = nv->bus[bus].max_queue_depth;
2618 mb[3] = nv->bus[bus].target[target].execution_throttle;
2619 status |= qla1280_mailbox_command(ha, 0x0f,
2626 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
2628 LEAVE("qla1280_nvram_config");
2633 * Get NVRAM data word
2634 * Calculates word position in NVRAM and calls request routine to
2635 * get the word from NVRAM.
2638 * ha = adapter block pointer.
2639 * address = NVRAM word address.
2645 qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
2650 nv_cmd = address << 16;
2651 nv_cmd |= NV_READ_OP;
2653 data = le16_to_cpu(qla1280_nvram_request(ha, nv_cmd));
2655 dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
2663 * Sends read command to NVRAM and gets data from NVRAM.
2666 * ha = adapter block pointer.
2667 * nv_cmd = Bit 26 = start bit
2668 * Bit 25, 24 = opcode
2669 * Bit 23-16 = address
2670 * Bit 15-0 = write data
2676 qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
2678 struct device_reg *reg = ha->iobase;
2683 /* Send command to NVRAM. */
2686 for (cnt = 0; cnt < 11; cnt++) {
2687 if (nv_cmd & BIT_31)
2688 qla1280_nv_write(ha, NV_DATA_OUT);
2690 qla1280_nv_write(ha, 0);
2694 /* Read data from NVRAM. */
2696 for (cnt = 0; cnt < 16; cnt++) {
2697 WRT_REG_WORD(®->nvram, (NV_SELECT | NV_CLOCK));
2698 RD_REG_WORD(®->id_l); /* Flush PCI write */
2701 reg_data = RD_REG_WORD(®->nvram);
2702 if (reg_data & NV_DATA_IN)
2704 WRT_REG_WORD(®->nvram, NV_SELECT);
2705 RD_REG_WORD(®->id_l); /* Flush PCI write */
2709 /* Deselect chip. */
2711 WRT_REG_WORD(®->nvram, NV_DESELECT);
2712 RD_REG_WORD(®->id_l); /* Flush PCI write */
2719 qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
2721 struct device_reg *reg = ha->iobase;
2723 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2724 RD_REG_WORD(®->id_l); /* Flush PCI write */
2726 WRT_REG_WORD(®->nvram, data | NV_SELECT | NV_CLOCK);
2727 RD_REG_WORD(®->id_l); /* Flush PCI write */
2729 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2730 RD_REG_WORD(®->id_l); /* Flush PCI write */
2736 * Issue mailbox command and waits for completion.
2739 * ha = adapter block pointer.
2740 * mr = mailbox registers to load.
2741 * mb = data pointer for mailbox registers.
2744 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
2750 qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
2752 struct device_reg *reg = ha->iobase;
2758 uint16_t *optr, *iptr;
2760 DECLARE_COMPLETION(wait);
2761 struct timer_list timer;
2763 ENTER("qla1280_mailbox_command");
2765 if (ha->mailbox_wait) {
2766 printk(KERN_ERR "Warning mailbox wait already in use!\n");
2768 ha->mailbox_wait = &wait;
2771 * We really should start out by verifying that the mailbox is
2772 * available before starting sending the command data
2774 /* Load mailbox registers. */
2775 optr = (uint16_t *) ®->mailbox0;
2777 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
2779 WRT_REG_WORD(optr, (*iptr));
2787 /* Issue set host interrupt command. */
2789 /* set up a timer just in case we're really jammed */
2791 timer.expires = jiffies + 20*HZ;
2792 timer.data = (unsigned long)ha;
2793 timer.function = qla1280_mailbox_timeout;
2796 spin_unlock_irq(HOST_LOCK);
2797 WRT_REG_WORD(®->host_cmd, HC_SET_HOST_INT);
2798 data = qla1280_debounce_register(®->istatus);
2800 wait_for_completion(&wait);
2801 del_timer_sync(&timer);
2803 spin_lock_irq(HOST_LOCK);
2805 ha->mailbox_wait = NULL;
2807 /* Check for mailbox command timeout. */
2808 if (ha->mailbox_out[0] != MBS_CMD_CMP) {
2809 printk(KERN_WARNING "qla1280_mailbox_command: Command failed, "
2810 "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
2812 mb[0], ha->mailbox_out[0], RD_REG_WORD(®->istatus));
2813 printk(KERN_WARNING "m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
2814 RD_REG_WORD(®->mailbox0), RD_REG_WORD(®->mailbox1),
2815 RD_REG_WORD(®->mailbox2), RD_REG_WORD(®->mailbox3));
2816 printk(KERN_WARNING "m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
2817 RD_REG_WORD(®->mailbox4), RD_REG_WORD(®->mailbox5),
2818 RD_REG_WORD(®->mailbox6), RD_REG_WORD(®->mailbox7));
2822 /* Load return mailbox registers. */
2824 iptr = (uint16_t *) &ha->mailbox_out[0];
2825 mr = MAILBOX_REGISTER_COUNT;
2826 memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
2829 /* Go check for any response interrupts pending. */
2830 qla1280_isr(ha, &done_q);
2833 if (ha->flags.reset_marker)
2834 qla1280_rst_aen(ha);
2837 if (!list_empty(&done_q))
2838 qla1280_done(ha, &done_q);
2842 dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
2843 "0x%x ****\n", mb[0]);
2845 LEAVE("qla1280_mailbox_command");
2851 * Polls ISP for interrupts.
2854 * ha = adapter block pointer.
2857 qla1280_poll(struct scsi_qla_host *ha)
2859 struct device_reg *reg = ha->iobase;
2863 /* ENTER("qla1280_poll"); */
2865 /* Check for pending interrupts. */
2866 data = RD_REG_WORD(®->istatus);
2867 if (data & RISC_INT)
2868 qla1280_isr(ha, &done_q);
2870 if (!ha->mailbox_wait) {
2871 if (ha->flags.reset_marker)
2872 qla1280_rst_aen(ha);
2875 if (!list_empty(&done_q))
2878 /* LEAVE("qla1280_poll"); */
2883 * Issue SCSI bus reset.
2886 * ha = adapter block pointer.
2887 * bus = SCSI bus number.
2893 qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
2895 uint16_t mb[MAILBOX_REGISTER_COUNT];
2896 uint16_t reset_delay;
2899 dprintk(3, "qla1280_bus_reset: entered\n");
2901 if (qla1280_verbose)
2902 printk(KERN_INFO "scsi(%li:%i): Resetting SCSI BUS\n",
2905 reset_delay = ha->bus_settings[bus].bus_reset_delay;
2906 mb[0] = MBC_BUS_RESET;
2907 mb[1] = reset_delay;
2908 mb[2] = (uint16_t) bus;
2909 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2912 if (ha->bus_settings[bus].failed_reset_count > 2)
2913 ha->bus_settings[bus].scsi_bus_dead = 1;
2914 ha->bus_settings[bus].failed_reset_count++;
2916 spin_unlock_irq(HOST_LOCK);
2917 schedule_timeout(reset_delay * HZ);
2918 spin_lock_irq(HOST_LOCK);
2920 ha->bus_settings[bus].scsi_bus_dead = 0;
2921 ha->bus_settings[bus].failed_reset_count = 0;
2922 ha->bus_settings[bus].reset_marker = 0;
2923 /* Issue marker command. */
2924 qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
2928 * We should probably call qla1280_set_target_parameters()
2929 * here as well for all devices on the bus.
2933 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
2935 dprintk(3, "qla1280_bus_reset: exiting normally\n");
2941 * qla1280_device_reset
2942 * Issue bus device reset message to the target.
2945 * ha = adapter block pointer.
2946 * bus = SCSI BUS number.
2953 qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
2955 uint16_t mb[MAILBOX_REGISTER_COUNT];
2958 ENTER("qla1280_device_reset");
2960 mb[0] = MBC_ABORT_TARGET;
2961 mb[1] = (bus ? (target | BIT_7) : target) << 8;
2963 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2965 /* Issue marker command. */
2966 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
2969 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
2971 LEAVE("qla1280_device_reset");
2976 * qla1280_abort_device
2977 * Issue an abort message to the device
2980 * ha = adapter block pointer.
2989 qla1280_abort_device(struct scsi_qla_host *ha, int bus, int target, int lun)
2991 uint16_t mb[MAILBOX_REGISTER_COUNT];
2994 ENTER("qla1280_abort_device");
2996 mb[0] = MBC_ABORT_DEVICE;
2997 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
2998 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
3000 /* Issue marker command. */
3001 qla1280_marker(ha, bus, target, lun, MK_SYNC_ID_LUN);
3004 dprintk(2, "qla1280_abort_device: **** FAILED ****\n");
3006 LEAVE("qla1280_abort_device");
3011 * qla1280_abort_command
3012 * Abort command aborts a specified IOCB.
3015 * ha = adapter block pointer.
3016 * sp = SB structure pointer.
3022 qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
3024 uint16_t mb[MAILBOX_REGISTER_COUNT];
3025 unsigned int bus, target, lun;
3028 ENTER("qla1280_abort_command");
3030 bus = SCSI_BUS_32(sp->cmd);
3031 target = SCSI_TCN_32(sp->cmd);
3032 lun = SCSI_LUN_32(sp->cmd);
3034 sp->flags |= SRB_ABORT_PENDING;
3036 mb[0] = MBC_ABORT_COMMAND;
3037 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
3038 mb[2] = handle >> 16;
3039 mb[3] = handle & 0xffff;
3040 status = qla1280_mailbox_command(ha, 0x0f, &mb[0]);
3043 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
3044 sp->flags &= ~SRB_ABORT_PENDING;
3048 LEAVE("qla1280_abort_command");
3053 * qla1280_reset_adapter
3057 * ha = adapter block pointer.
3060 qla1280_reset_adapter(struct scsi_qla_host *ha)
3062 struct device_reg *reg = ha->iobase;
3064 ENTER("qla1280_reset_adapter");
3066 /* Disable ISP chip */
3067 ha->flags.online = 0;
3068 WRT_REG_WORD(®->ictrl, ISP_RESET);
3069 WRT_REG_WORD(®->host_cmd,
3070 HC_RESET_RISC | HC_RELEASE_RISC | HC_DISABLE_BIOS);
3071 RD_REG_WORD(®->id_l); /* Flush PCI write */
3073 LEAVE("qla1280_reset_adapter");
3077 * Issue marker command.
3078 * Function issues marker IOCB.
3081 * ha = adapter block pointer.
3082 * bus = SCSI BUS number
3085 * type = marker modifier
3088 qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
3090 struct mrk_entry *pkt;
3092 ENTER("qla1280_marker");
3094 /* Get request packet. */
3095 if ((pkt = (struct mrk_entry *) qla1280_req_pkt(ha))) {
3096 pkt->entry_type = MARKER_TYPE;
3097 pkt->lun = (uint8_t) lun;
3098 pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
3099 pkt->modifier = type;
3100 pkt->entry_status = 0;
3102 /* Issue command to ISP */
3103 qla1280_isp_cmd(ha);
3106 LEAVE("qla1280_marker");
3111 * qla1280_64bit_start_scsi
3112 * The start SCSI is responsible for building request packets on
3113 * request ring and modifying ISP input pointer.
3116 * ha = adapter block pointer.
3117 * sp = SB structure pointer.
3120 * 0 = success, was able to issue command.
3123 qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3125 struct device_reg *reg = ha->iobase;
3126 struct scsi_cmnd *cmd = sp->cmd;
3127 cmd_a64_entry_t *pkt;
3128 struct scatterlist *sg = NULL;
3130 dma_addr_t dma_handle;
3137 ENTER("qla1280_64bit_start_scsi:");
3139 /* Calculate number of entries and segments required. */
3142 sg = (struct scatterlist *) cmd->request_buffer;
3143 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3144 cmd->sc_data_direction);
3147 req_cnt += (seg_cnt - 2) / 5;
3148 if ((seg_cnt - 2) % 5)
3151 } else if (cmd->request_bufflen) { /* If data transfer. */
3157 if ((req_cnt + 2) >= ha->req_q_cnt) {
3158 /* Calculate number of free request entries. */
3159 cnt = RD_REG_WORD(®->mailbox4);
3160 if (ha->req_ring_index < cnt)
3161 ha->req_q_cnt = cnt - ha->req_ring_index;
3164 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3167 /* If room for request in request ring. */
3168 if ((req_cnt + 2) >= ha->req_q_cnt) {
3170 dprintk(2, "qla1280_64bit_start_scsi: in-ptr=0x%x req_q_cnt="
3171 "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
3176 /* Check for room in outstanding command list. */
3177 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3178 ha->outstanding_cmds[cnt] != 0; cnt++);
3180 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3182 dprintk(2, "qla1280_64bit_start_scsi: NO ROOM IN "
3183 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
3187 ha->outstanding_cmds[cnt] = sp;
3188 ha->req_q_cnt -= req_cnt;
3189 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
3191 dprintk(2, "64bit_start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
3192 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
3193 dprintk(2, " bus %i, target %i, lun %i\n",
3194 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3195 qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
3198 * Build command packet.
3200 pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
3202 pkt->entry_type = COMMAND_A64_TYPE;
3203 pkt->entry_count = (uint8_t) req_cnt;
3204 pkt->sys_define = (uint8_t) ha->req_ring_index;
3205 pkt->entry_status = 0;
3206 pkt->handle = cpu_to_le32(cnt);
3208 /* Zero out remaining portion of packet. */
3209 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3211 /* Set ISP command timeout. */
3212 pkt->timeout = cpu_to_le16(30);
3214 /* Set device target ID and LUN */
3215 pkt->lun = SCSI_LUN_32(cmd);
3216 pkt->target = SCSI_BUS_32(cmd) ?
3217 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3219 /* Enable simple tag queuing if device supports it. */
3220 if (DEV_SIMPLE_TAGS(cmd->device))
3221 pkt->control_flags |= cpu_to_le16(BIT_3);
3223 /* Load SCSI command packet. */
3224 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3225 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3226 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3228 /* Set transfer direction. */
3229 dir = qla1280_data_direction(cmd);
3230 pkt->control_flags |= cpu_to_le16(dir);
3232 /* Set total data segment count. */
3233 pkt->dseg_count = cpu_to_le16(seg_cnt);
3236 * Load data segments.
3238 if (seg_cnt) { /* If data transfer. */
3239 /* Setup packet address segment pointer. */
3240 dword_ptr = (u32 *)&pkt->dseg_0_address;
3242 if (cmd->use_sg) { /* If scatter gather */
3243 /* Load command entry data segments. */
3244 for (cnt = 0; cnt < 2 && seg_cnt; cnt++, seg_cnt--) {
3245 dma_handle = sg_dma_address(sg);
3246 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3247 if (ha->flags.use_pci_vchannel)
3248 sn_pci_set_vchan(ha->pdev, &dma_handle,
3252 cpu_to_le32(pci_dma_lo32(dma_handle));
3254 cpu_to_le32(pci_dma_hi32(dma_handle));
3255 *dword_ptr++ = cpu_to_le32(sg_dma_len(sg));
3257 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
3258 cpu_to_le32(pci_dma_hi32(dma_handle)),
3259 cpu_to_le32(pci_dma_lo32(dma_handle)),
3260 cpu_to_le32(sg_dma_len(sg)));
3262 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
3263 "command packet data - b %i, t %i, l %i \n",
3264 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3266 qla1280_dump_buffer(5, (char *)pkt,
3267 REQUEST_ENTRY_SIZE);
3270 * Build continuation packets.
3272 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
3273 "remains\n", seg_cnt);
3275 while (seg_cnt > 0) {
3276 /* Adjust ring index. */
3277 ha->req_ring_index++;
3278 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3279 ha->req_ring_index = 0;
3280 ha->request_ring_ptr =
3283 ha->request_ring_ptr++;
3285 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
3287 /* Zero out packet. */
3288 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3290 /* Load packet defaults. */
3291 ((struct cont_a64_entry *) pkt)->entry_type =
3293 ((struct cont_a64_entry *) pkt)->entry_count = 1;
3294 ((struct cont_a64_entry *) pkt)->sys_define =
3295 (uint8_t)ha->req_ring_index;
3296 /* Setup packet address segment pointer. */
3298 (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
3300 /* Load continuation entry data segments. */
3301 for (cnt = 0; cnt < 5 && seg_cnt;
3303 dma_handle = sg_dma_address(sg);
3304 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3305 if (ha->flags.use_pci_vchannel)
3306 sn_pci_set_vchan(ha->pdev, &dma_handle,
3310 cpu_to_le32(pci_dma_lo32(dma_handle));
3312 cpu_to_le32(pci_dma_hi32(dma_handle));
3314 cpu_to_le32(sg_dma_len(sg));
3315 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
3316 cpu_to_le32(pci_dma_hi32(dma_handle)),
3317 cpu_to_le32(pci_dma_lo32(dma_handle)),
3318 cpu_to_le32(sg_dma_len(sg)));
3321 dprintk(5, "qla1280_64bit_start_scsi: "
3322 "continuation packet data - b %i, t "
3323 "%i, l %i \n", SCSI_BUS_32(cmd),
3324 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3325 qla1280_dump_buffer(5, (char *)pkt,
3326 REQUEST_ENTRY_SIZE);
3328 } else { /* No scatter gather data transfer */
3329 struct page *page = virt_to_page(cmd->request_buffer);
3330 unsigned long off = (unsigned long)cmd->request_buffer & ~PAGE_MASK;
3332 dma_handle = pci_map_page(ha->pdev, page, off,
3333 cmd->request_bufflen,
3334 cmd->sc_data_direction);
3336 /* save dma_handle for pci_unmap_page */
3337 sp->saved_dma_handle = dma_handle;
3338 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3339 if (ha->flags.use_pci_vchannel)
3340 sn_pci_set_vchan(ha->pdev, &dma_handle,
3343 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3344 *dword_ptr++ = cpu_to_le32(pci_dma_hi32(dma_handle));
3345 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3347 dprintk(5, "qla1280_64bit_start_scsi: No scatter/"
3348 "gather command packet data - b %i, t %i, "
3349 "l %i \n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3351 qla1280_dump_buffer(5, (char *)pkt,
3352 REQUEST_ENTRY_SIZE);
3354 } else { /* No data transfer */
3355 dprintk(5, "qla1280_64bit_start_scsi: No data, command "
3356 "packet data - b %i, t %i, l %i \n",
3357 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3358 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3360 /* Adjust ring index. */
3361 ha->req_ring_index++;
3362 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3363 ha->req_ring_index = 0;
3364 ha->request_ring_ptr = ha->request_ring;
3366 ha->request_ring_ptr++;
3368 /* Set chip new ring index. */
3370 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
3371 sp->flags |= SRB_SENT;
3373 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3377 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
3379 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
3385 #ifndef QLA_64BIT_PTR
3387 * qla1280_32bit_start_scsi
3388 * The start SCSI is responsible for building request packets on
3389 * request ring and modifying ISP input pointer.
3391 * The Qlogic firmware interface allows every queue slot to have a SCSI
3392 * command and up to 4 scatter/gather (SG) entries. If we need more
3393 * than 4 SG entries, then continuation entries are used that can
3394 * hold another 7 entries each. The start routine determines if there
3395 * is eought empty slots then build the combination of requests to
3396 * fulfill the OS request.
3399 * ha = adapter block pointer.
3400 * sp = SCSI Request Block structure pointer.
3403 * 0 = success, was able to issue command.
3406 qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3408 struct device_reg *reg = ha->iobase;
3409 struct scsi_cmnd *cmd = sp->cmd;
3410 struct cmd_entry *pkt;
3411 struct scatterlist *sg = NULL;
3412 uint32_t *dword_ptr;
3417 dma_addr_t dma_handle;
3420 ENTER("qla1280_32bit_start_scsi");
3422 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
3425 /* Calculate number of entries and segments required. */
3429 * We must build an SG list in adapter format, as the kernel's
3430 * SG list cannot be used directly because of data field size
3431 * (__alpha__) differences and the kernel SG list uses virtual
3432 * addresses where we need physical addresses.
3434 sg = (struct scatterlist *) cmd->request_buffer;
3435 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3436 cmd->sc_data_direction);
3439 * if greater than four sg entries then we need to allocate
3440 * continuation entries
3443 req_cnt += (seg_cnt - 4) / 7;
3444 if ((seg_cnt - 4) % 7)
3447 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3448 cmd, seg_cnt, req_cnt);
3449 } else if (cmd->request_bufflen) { /* If data transfer. */
3450 dprintk(3, "No S/G transfer t=%x cmd=%p len=%x CDB=%x\n",
3451 SCSI_TCN_32(cmd), cmd, cmd->request_bufflen,
3455 /* dprintk(1, "No data transfer \n"); */
3459 if ((req_cnt + 2) >= ha->req_q_cnt) {
3460 /* Calculate number of free request entries. */
3461 cnt = RD_REG_WORD(®->mailbox4);
3462 if (ha->req_ring_index < cnt)
3463 ha->req_q_cnt = cnt - ha->req_ring_index;
3466 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3469 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3470 ha->req_q_cnt, seg_cnt);
3471 /* If room for request in request ring. */
3472 if ((req_cnt + 2) >= ha->req_q_cnt) {
3474 dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
3475 "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
3476 ha->req_q_cnt, req_cnt);
3480 /* Check for empty slot in outstanding command list. */
3481 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3482 (ha->outstanding_cmds[cnt] != 0); cnt++) ;
3484 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3486 dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
3487 "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
3491 CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
3492 ha->outstanding_cmds[cnt] = sp;
3493 ha->req_q_cnt -= req_cnt;
3496 * Build command packet.
3498 pkt = (struct cmd_entry *) ha->request_ring_ptr;
3500 pkt->entry_type = COMMAND_TYPE;
3501 pkt->entry_count = (uint8_t) req_cnt;
3502 pkt->sys_define = (uint8_t) ha->req_ring_index;
3503 pkt->entry_status = 0;
3504 pkt->handle = cpu_to_le32(cnt);
3506 /* Zero out remaining portion of packet. */
3507 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3509 /* Set ISP command timeout. */
3510 pkt->timeout = cpu_to_le16(30);
3512 /* Set device target ID and LUN */
3513 pkt->lun = SCSI_LUN_32(cmd);
3514 pkt->target = SCSI_BUS_32(cmd) ?
3515 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3517 /* Enable simple tag queuing if device supports it. */
3518 if (DEV_SIMPLE_TAGS(cmd->device))
3519 pkt->control_flags |= cpu_to_le16(BIT_3);
3521 /* Load SCSI command packet. */
3522 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3523 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3525 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3526 /* Set transfer direction. */
3527 dir = qla1280_data_direction(cmd);
3528 pkt->control_flags |= cpu_to_le16(dir);
3530 /* Set total data segment count. */
3531 pkt->dseg_count = cpu_to_le16(seg_cnt);
3534 * Load data segments.
3537 /* Setup packet address segment pointer. */
3538 dword_ptr = &pkt->dseg_0_address;
3540 if (cmd->use_sg) { /* If scatter gather */
3541 dprintk(3, "Building S/G data segments..\n");
3542 qla1280_dump_buffer(1, (char *)sg, 4 * 16);
3544 /* Load command entry data segments. */
3545 for (cnt = 0; cnt < 4 && seg_cnt; cnt++, seg_cnt--) {
3547 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3549 cpu_to_le32(sg_dma_len(sg));
3550 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3551 (pci_dma_lo32(sg_dma_address(sg))),
3556 * Build continuation packets.
3558 dprintk(3, "S/G Building Continuation"
3559 "...seg_cnt=0x%x remains\n", seg_cnt);
3560 while (seg_cnt > 0) {
3561 /* Adjust ring index. */
3562 ha->req_ring_index++;
3563 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3564 ha->req_ring_index = 0;
3565 ha->request_ring_ptr =
3568 ha->request_ring_ptr++;
3570 pkt = (struct cmd_entry *)ha->request_ring_ptr;
3572 /* Zero out packet. */
3573 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3575 /* Load packet defaults. */
3576 ((struct cont_entry *) pkt)->
3577 entry_type = CONTINUE_TYPE;
3578 ((struct cont_entry *) pkt)->entry_count = 1;
3580 ((struct cont_entry *) pkt)->sys_define =
3581 (uint8_t) ha->req_ring_index;
3583 /* Setup packet address segment pointer. */
3585 &((struct cont_entry *) pkt)->dseg_0_address;
3587 /* Load continuation entry data segments. */
3588 for (cnt = 0; cnt < 7 && seg_cnt;
3591 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3593 cpu_to_le32(sg_dma_len(sg));
3595 "S/G Segment Cont. phys_addr=0x%x, "
3597 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
3598 cpu_to_le32(sg_dma_len(sg)));
3601 dprintk(5, "qla1280_32bit_start_scsi: "
3602 "continuation packet data - "
3603 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
3604 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3605 qla1280_dump_buffer(5, (char *)pkt,
3606 REQUEST_ENTRY_SIZE);
3608 } else { /* No S/G data transfer */
3609 struct page *page = virt_to_page(cmd->request_buffer);
3610 unsigned long off = (unsigned long)cmd->request_buffer & ~PAGE_MASK;
3611 dma_handle = pci_map_page(ha->pdev, page, off,
3612 cmd->request_bufflen,
3613 cmd->sc_data_direction);
3614 sp->saved_dma_handle = dma_handle;
3616 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3617 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3619 } else { /* No data transfer at all */
3620 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
3621 "packet data - \n");
3622 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3624 dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
3625 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3626 REQUEST_ENTRY_SIZE);
3628 /* Adjust ring index. */
3629 ha->req_ring_index++;
3630 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3631 ha->req_ring_index = 0;
3632 ha->request_ring_ptr = ha->request_ring;
3634 ha->request_ring_ptr++;
3636 /* Set chip new ring index. */
3637 dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
3638 "for pending command\n");
3639 sp->flags |= SRB_SENT;
3641 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3645 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
3647 LEAVE("qla1280_32bit_start_scsi");
3655 * Function is responsible for locking ring and
3656 * getting a zeroed out request packet.
3659 * ha = adapter block pointer.
3662 * 0 = failed to get slot.
3665 qla1280_req_pkt(struct scsi_qla_host *ha)
3667 struct device_reg *reg = ha->iobase;
3672 ENTER("qla1280_req_pkt");
3675 * This can be called from interrupt context, damn it!!!
3677 /* Wait for 30 seconds for slot. */
3678 for (timer = 15000000; timer; timer--) {
3679 if (ha->req_q_cnt > 0) {
3680 /* Calculate number of free request entries. */
3681 cnt = RD_REG_WORD(®->mailbox4);
3682 if (ha->req_ring_index < cnt)
3683 ha->req_q_cnt = cnt - ha->req_ring_index;
3686 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3689 /* Found empty request ring slot? */
3690 if (ha->req_q_cnt > 0) {
3692 pkt = ha->request_ring_ptr;
3694 /* Zero out packet. */
3695 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3698 * How can this be right when we have a ring
3701 /* Set system defined field. */
3702 pkt->sys_define = (uint8_t) ha->req_ring_index;
3704 /* Set entry count. */
3705 pkt->entry_count = 1;
3712 /* Check for pending interrupts. */
3717 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
3719 dprintk(3, "qla1280_req_pkt: exiting normally\n");
3726 * Function is responsible for modifying ISP input pointer.
3727 * Releases ring lock.
3730 * ha = adapter block pointer.
3733 qla1280_isp_cmd(struct scsi_qla_host *ha)
3735 struct device_reg *reg = ha->iobase;
3737 ENTER("qla1280_isp_cmd");
3739 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
3740 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3741 REQUEST_ENTRY_SIZE);
3743 /* Adjust ring index. */
3744 ha->req_ring_index++;
3745 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3746 ha->req_ring_index = 0;
3747 ha->request_ring_ptr = ha->request_ring;
3749 ha->request_ring_ptr++;
3751 /* Set chip new ring index. */
3752 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3754 LEAVE("qla1280_isp_cmd");
3757 /****************************************************************************/
3758 /* Interrupt Service Routine. */
3759 /****************************************************************************/
3761 /****************************************************************************
3763 * Calls I/O done on command completion.
3766 * ha = adapter block pointer.
3767 * done_q = done queue.
3768 ****************************************************************************/
3770 qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
3772 struct device_reg *reg = ha->iobase;
3773 struct response *pkt;
3775 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
3780 ENTER("qla1280_isr");
3782 istatus = RD_REG_WORD(®->istatus);
3783 if (!(istatus & (RISC_INT | PCI_INT)))
3786 /* Save mailbox register 5 */
3787 mailbox[5] = RD_REG_WORD(®->mailbox5);
3789 /* Check for mailbox interrupt. */
3791 mailbox[0] = RD_REG_WORD(®->semaphore);
3793 if (mailbox[0] & BIT_0) {
3794 /* Get mailbox data. */
3795 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
3798 *wptr++ = RD_REG_WORD(®->mailbox0);
3799 *wptr++ = RD_REG_WORD(®->mailbox1);
3800 *wptr = RD_REG_WORD(®->mailbox2);
3801 if (mailbox[0] != MBA_SCSI_COMPLETION) {
3803 *wptr++ = RD_REG_WORD(®->mailbox3);
3804 *wptr++ = RD_REG_WORD(®->mailbox4);
3806 *wptr++ = RD_REG_WORD(®->mailbox6);
3807 *wptr = RD_REG_WORD(®->mailbox7);
3810 /* Release mailbox registers. */
3812 WRT_REG_WORD(®->semaphore, 0);
3813 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3815 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
3818 /* Handle asynchronous event */
3819 switch (mailbox[0]) {
3820 case MBA_SCSI_COMPLETION: /* Response completion */
3821 dprintk(5, "qla1280_isr: mailbox SCSI response "
3824 if (ha->flags.online) {
3825 /* Get outstanding command index. */
3826 index = mailbox[2] << 16 | mailbox[1];
3828 /* Validate handle. */
3829 if (index < MAX_OUTSTANDING_COMMANDS)
3830 sp = ha->outstanding_cmds[index];
3835 /* Free outstanding command slot. */
3836 ha->outstanding_cmds[index] = 0;
3838 /* Save ISP completion status */
3839 CMD_RESULT(sp->cmd) = 0;
3841 /* Place block on done queue */
3842 list_add_tail(&sp->list, done_q);
3845 * If we get here we have a real problem!
3848 "qla1280: ISP invalid handle");
3853 case MBA_BUS_RESET: /* SCSI Bus Reset */
3854 ha->flags.reset_marker = 1;
3855 index = mailbox[6] & BIT_0;
3856 ha->bus_settings[index].reset_marker = 1;
3858 printk(KERN_DEBUG "qla1280_isr(): index %i "
3859 "asynchronous BUS_RESET\n", index);
3862 case MBA_SYSTEM_ERR: /* System Error */
3864 "qla1280: ISP System Error - mbx1=%xh, mbx2="
3865 "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
3869 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
3871 "qla1280: ISP Request Transfer Error\n");
3874 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
3876 "qla1280: ISP Response Transfer Error\n");
3879 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
3880 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
3883 case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
3885 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
3888 case MBA_DEVICE_RESET: /* Bus Device Reset */
3889 printk(KERN_INFO "qla1280_isr(): asynchronous "
3890 "BUS_DEVICE_RESET\n");
3892 ha->flags.reset_marker = 1;
3893 index = mailbox[6] & BIT_0;
3894 ha->bus_settings[index].reset_marker = 1;
3897 case MBA_BUS_MODE_CHANGE:
3899 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
3903 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
3904 if (mailbox[0] < MBA_ASYNC_EVENT) {
3906 memcpy((uint16_t *) ha->mailbox_out, wptr,
3907 MAILBOX_REGISTER_COUNT *
3910 if(ha->mailbox_wait != NULL)
3911 complete(ha->mailbox_wait);
3916 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3920 * We will receive interrupts during mailbox testing prior to
3921 * the card being marked online, hence the double check.
3923 if (!(ha->flags.online && !ha->mailbox_wait)) {
3924 dprintk(2, "qla1280_isr: Response pointer Error\n");
3928 if (mailbox[5] >= RESPONSE_ENTRY_CNT)
3931 while (ha->rsp_ring_index != mailbox[5]) {
3932 pkt = ha->response_ring_ptr;
3934 dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
3935 " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
3936 dprintk(5,"qla1280_isr: response packet data\n");
3937 qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
3939 if (pkt->entry_type == STATUS_TYPE) {
3940 if ((le16_to_cpu(pkt->scsi_status) & 0xff)
3941 || pkt->comp_status || pkt->entry_status) {
3942 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3943 "0x%x mailbox[5] = 0x%x, comp_status "
3944 "= 0x%x, scsi_status = 0x%x\n",
3945 ha->rsp_ring_index, mailbox[5],
3946 le16_to_cpu(pkt->comp_status),
3947 le16_to_cpu(pkt->scsi_status));
3950 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3951 "0x%x, mailbox[5] = 0x%x\n",
3952 ha->rsp_ring_index, mailbox[5]);
3953 dprintk(2, "qla1280_isr: response packet data\n");
3954 qla1280_dump_buffer(2, (char *)pkt,
3955 RESPONSE_ENTRY_SIZE);
3958 if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
3959 dprintk(2, "status: Cmd %p, handle %i\n",
3960 ha->outstanding_cmds[pkt->handle]->cmd,
3962 if (pkt->entry_type == STATUS_TYPE)
3963 qla1280_status_entry(ha, pkt, done_q);
3965 qla1280_error_entry(ha, pkt, done_q);
3966 /* Adjust ring index. */
3967 ha->rsp_ring_index++;
3968 if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
3969 ha->rsp_ring_index = 0;
3970 ha->response_ring_ptr = ha->response_ring;
3972 ha->response_ring_ptr++;
3973 WRT_REG_WORD(®->mailbox5, ha->rsp_ring_index);
3978 LEAVE("qla1280_isr");
3983 * Processes asynchronous reset.
3986 * ha = adapter block pointer.
3989 qla1280_rst_aen(struct scsi_qla_host *ha)
3993 ENTER("qla1280_rst_aen");
3995 if (ha->flags.online && !ha->flags.reset_active &&
3996 !ha->flags.abort_isp_active) {
3997 ha->flags.reset_active = 1;
3998 while (ha->flags.reset_marker) {
3999 /* Issue marker command. */
4000 ha->flags.reset_marker = 0;
4001 for (bus = 0; bus < ha->ports &&
4002 !ha->flags.reset_marker; bus++) {
4003 if (ha->bus_settings[bus].reset_marker) {
4004 ha->bus_settings[bus].reset_marker = 0;
4005 qla1280_marker(ha, bus, 0, 0,
4012 LEAVE("qla1280_rst_aen");
4016 #if LINUX_VERSION_CODE < 0x020500
4021 qla1280_get_target_options(struct scsi_cmnd *cmd, struct scsi_qla_host *ha)
4023 unsigned char *result;
4025 int bus, target, lun;
4027 bus = SCSI_BUS_32(cmd);
4028 target = SCSI_TCN_32(cmd);
4029 lun = SCSI_LUN_32(cmd);
4032 * Make sure to not touch anything if someone is using the
4035 if (cmd->use_sg || (CMD_RESULT(cmd) >> 16) != DID_OK || lun)
4038 result = cmd->request_buffer;
4041 n->bus[bus].target[target].parameter.f.enable_wide = 0;
4042 n->bus[bus].target[target].parameter.f.enable_sync = 0;
4043 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
4045 if (result[7] & 0x60)
4046 n->bus[bus].target[target].parameter.f.enable_wide = 1;
4047 if (result[7] & 0x10)
4048 n->bus[bus].target[target].parameter.f.enable_sync = 1;
4049 if ((result[2] >= 3) && (result[4] + 5 > 56) &&
4051 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
4053 dprintk(2, "get_target_options(): wide %i, sync %i, ppr %i\n",
4054 n->bus[bus].target[target].parameter.f.enable_wide,
4055 n->bus[bus].target[target].parameter.f.enable_sync,
4056 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr);
4061 * qla1280_status_entry
4062 * Processes received ISP status entry.
4065 * ha = adapter block pointer.
4066 * pkt = entry pointer.
4067 * done_q = done queue.
4070 qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
4071 struct list_head *done_q)
4073 unsigned int bus, target, lun;
4076 struct scsi_cmnd *cmd;
4077 uint32_t handle = le32_to_cpu(pkt->handle);
4078 uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
4079 uint16_t comp_status = le16_to_cpu(pkt->comp_status);
4081 ENTER("qla1280_status_entry");
4083 /* Validate handle. */
4084 if (handle < MAX_OUTSTANDING_COMMANDS)
4085 sp = ha->outstanding_cmds[handle];
4090 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
4094 /* Free outstanding command slot. */
4095 ha->outstanding_cmds[handle] = 0;
4099 /* Generate LU queue on cntrl, target, LUN */
4100 bus = SCSI_BUS_32(cmd);
4101 target = SCSI_TCN_32(cmd);
4102 lun = SCSI_LUN_32(cmd);
4104 if (comp_status || scsi_status) {
4105 dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
4106 "0x%x, handle = 0x%x\n", comp_status,
4107 scsi_status, handle);
4111 if (scsi_status & SS_BUSY_CONDITION &&
4112 scsi_status != SS_RESERVE_CONFLICT) {
4114 DID_BUS_BUSY << 16 | (scsi_status & 0xff);
4117 /* Save ISP completion status */
4118 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
4120 if (scsi_status & SS_CHECK_CONDITION) {
4121 if (comp_status != CS_ARS_FAILED) {
4122 uint16_t req_sense_length =
4123 le16_to_cpu(pkt->req_sense_length);
4124 if (req_sense_length < CMD_SNSLEN(cmd))
4125 sense_sz = req_sense_length;
4128 * scsi_cmnd->sense_buffer is
4129 * 64 bytes, why only copy 63?
4130 * This looks wrong! /Jes
4132 sense_sz = CMD_SNSLEN(cmd) - 1;
4134 memcpy(cmd->sense_buffer,
4135 &pkt->req_sense_data, sense_sz);
4138 memset(cmd->sense_buffer + sense_sz, 0,
4139 sizeof(cmd->sense_buffer) - sense_sz);
4141 dprintk(2, "qla1280_status_entry: Check "
4142 "condition Sense data, b %i, t %i, "
4143 "l %i\n", bus, target, lun);
4145 qla1280_dump_buffer(2,
4146 (char *)cmd->sense_buffer,
4151 /* Place command on done queue. */
4152 list_add_tail(&sp->list, done_q);
4154 LEAVE("qla1280_status_entry");
4158 * qla1280_error_entry
4159 * Processes error entry.
4162 * ha = adapter block pointer.
4163 * pkt = entry pointer.
4164 * done_q = done queue.
4167 qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
4168 struct list_head *done_q)
4171 uint32_t handle = le32_to_cpu(pkt->handle);
4173 ENTER("qla1280_error_entry");
4175 if (pkt->entry_status & BIT_3)
4176 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
4177 else if (pkt->entry_status & BIT_2)
4178 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
4179 else if (pkt->entry_status & BIT_1)
4180 dprintk(2, "qla1280_error_entry: FULL flag error\n");
4182 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
4184 /* Validate handle. */
4185 if (handle < MAX_OUTSTANDING_COMMANDS)
4186 sp = ha->outstanding_cmds[handle];
4191 /* Free outstanding command slot. */
4192 ha->outstanding_cmds[handle] = 0;
4194 /* Bad payload or header */
4195 if (pkt->entry_status & (BIT_3 + BIT_2)) {
4196 /* Bad payload or header, set error status. */
4197 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
4198 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
4199 } else if (pkt->entry_status & BIT_1) { /* FULL flag */
4200 CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
4202 /* Set error status. */
4203 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
4206 /* Place command on done queue. */
4207 list_add_tail(&sp->list, done_q);
4209 #ifdef QLA_64BIT_PTR
4210 else if (pkt->entry_type == COMMAND_A64_TYPE) {
4211 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
4215 LEAVE("qla1280_error_entry");
4220 * Resets ISP and aborts all outstanding commands.
4223 * ha = adapter block pointer.
4229 qla1280_abort_isp(struct scsi_qla_host *ha)
4236 ENTER("qla1280_abort_isp");
4238 if (!ha->flags.abort_isp_active && ha->flags.online) {
4239 struct device_reg *reg = ha->iobase;
4240 ha->flags.abort_isp_active = 1;
4242 /* Disable ISP interrupts. */
4243 qla1280_disable_intrs(ha);
4244 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
4245 RD_REG_WORD(®->id_l);
4247 printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
4249 /* Dequeue all commands in outstanding command list. */
4250 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
4251 struct scsi_cmnd *cmd;
4252 sp = ha->outstanding_cmds[cnt];
4256 CMD_RESULT(cmd) = DID_RESET << 16;
4259 ha->outstanding_cmds[cnt] = NULL;
4261 (*cmd->scsi_done)(cmd);
4267 /* If firmware needs to be loaded */
4268 if (qla1280_isp_firmware (ha)) {
4269 if (!(status = qla1280_chip_diag(ha)))
4270 status = qla1280_setup_chip(ha);
4274 /* Setup adapter based on NVRAM parameters. */
4275 qla1280_nvram_config (ha);
4277 if (!(status = qla1280_init_rings(ha))) {
4278 /* Issue SCSI reset. */
4279 for (bus = 0; bus < ha->ports; bus++) {
4280 qla1280_bus_reset(ha, bus);
4283 * qla1280_bus_reset() will do the marker
4284 * dance - no reason to repeat here!
4287 /* Issue marker command. */
4288 ha->flags.reset_marker = 0;
4289 for (bus = 0; bus < ha->ports; bus++) {
4290 ha->bus_settings[bus].
4292 qla1280_marker(ha, bus, 0, 0,
4296 ha->flags.abort_isp_active = 0;
4303 "qla1280: ISP error recovery failed, board disabled");
4304 qla1280_reset_adapter(ha);
4305 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
4308 LEAVE("qla1280_abort_isp");
4314 * qla1280_debounce_register
4315 * Debounce register.
4318 * port = register address.
4324 qla1280_debounce_register(volatile u16 * addr)
4329 ret = RD_REG_WORD(addr);
4330 ret2 = RD_REG_WORD(addr);
4337 ret = RD_REG_WORD(addr);
4338 ret2 = RD_REG_WORD(addr);
4339 } while (ret != ret2);
4345 /************************************************************************
4346 * qla1280_check_for_dead_scsi_bus *
4348 * This routine checks for a dead SCSI bus *
4349 ************************************************************************/
4350 #define SET_SXP_BANK 0x0100
4351 #define SCSI_PHASE_INVALID 0x87FF
4353 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
4355 uint16_t config_reg, scsi_control;
4356 struct device_reg *reg = ha->iobase;
4358 if (ha->bus_settings[bus].scsi_bus_dead) {
4359 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
4360 config_reg = RD_REG_WORD(®->cfg_1);
4361 WRT_REG_WORD(®->cfg_1, SET_SXP_BANK);
4362 scsi_control = RD_REG_WORD(®->scsiControlPins);
4363 WRT_REG_WORD(®->cfg_1, config_reg);
4364 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
4366 if (scsi_control == SCSI_PHASE_INVALID) {
4367 ha->bus_settings[bus].scsi_bus_dead = 1;
4369 CMD_RESULT(cp) = DID_NO_CONNECT << 16;
4370 CMD_HANDLE(cp) = INVALID_HANDLE;
4371 /* ha->actthreads--; */
4373 (*(cp)->scsi_done)(cp);
4375 return 1; /* bus is dead */
4377 ha->bus_settings[bus].scsi_bus_dead = 0;
4378 ha->bus_settings[bus].failed_reset_count = 0;
4381 return 0; /* bus is not dead */
4385 qla1280_get_target_parameters(struct scsi_qla_host *ha,
4386 struct scsi_device *device)
4388 uint16_t mb[MAILBOX_REGISTER_COUNT];
4389 int bus, target, lun;
4391 bus = device->channel;
4392 target = device->id;
4396 mb[0] = MBC_GET_TARGET_PARAMETERS;
4397 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
4399 qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
4402 printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
4405 printk(" Sync: period %d, offset %d",
4406 (mb[3] & 0xff), (mb[3] >> 8));
4409 if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
4414 if (DEV_SIMPLE_TAGS(device))
4415 printk(", Tagged queuing: depth %d", device->queue_depth);
4422 __qla1280_dump_buffer(char *b, int size)
4427 printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
4428 "Bh Ch Dh Eh Fh\n");
4429 printk(KERN_DEBUG "---------------------------------------------"
4430 "------------------\n");
4432 for (cnt = 0; cnt < size;) {
4435 printk("0x%02x", c);
4446 /**************************************************************************
4447 * ql1280_print_scsi_cmd
4449 **************************************************************************/
4451 __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
4453 struct scsi_qla_host *ha;
4454 struct Scsi_Host *host = CMD_HOST(cmd);
4456 /* struct scatterlist *sg; */
4459 ha = (struct scsi_qla_host *)host->hostdata;
4461 sp = (struct srb *)CMD_SP(cmd);
4462 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
4463 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
4464 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
4467 for (i = 0; i < cmd->cmd_len; i++) {
4468 printk("0x%02x ", cmd->cmnd[i]);
4470 printk(" seg_cnt =%d\n", cmd->use_sg);
4471 printk(" request buffer=0x%p, request buffer len=0x%x\n",
4472 cmd->request_buffer, cmd->request_bufflen);
4475 sg = (struct scatterlist *) cmd->request_buffer;
4476 printk(" SG buffer: \n");
4477 qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
4479 printk(" tag=%d, transfersize=0x%x \n",
4480 cmd->tag, cmd->transfersize);
4481 printk(" Pid=%li, SP=0x%p\n", cmd->pid, CMD_SP(cmd));
4482 printk(" underflow size = 0x%x, direction=0x%x\n",
4483 cmd->underflow, cmd->sc_data_direction);
4486 /**************************************************************************
4487 * ql1280_dump_device
4489 **************************************************************************/
4491 ql1280_dump_device(struct scsi_qla_host *ha)
4494 struct scsi_cmnd *cp;
4498 printk(KERN_DEBUG "Outstanding Commands on controller:\n");
4500 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
4501 if ((sp = ha->outstanding_cmds[i]) == NULL)
4503 if ((cp = sp->cmd) == NULL)
4505 qla1280_print_scsi_cmd(1, cp);
4520 struct setup_tokens {
4525 static struct setup_tokens setup_token[] __initdata =
4527 { "nvram", TOKEN_NVRAM },
4528 { "sync", TOKEN_SYNC },
4529 { "wide", TOKEN_WIDE },
4530 { "ppr", TOKEN_PPR },
4531 { "verbose", TOKEN_VERBOSE },
4532 { "debug", TOKEN_DEBUG },
4536 /**************************************************************************
4539 * Handle boot parameters. This really needs to be changed so one
4540 * can specify per adapter parameters.
4541 **************************************************************************/
4543 qla1280_setup(char *s)
4551 while (cp && (ptr = strchr(cp, ':'))) {
4553 if (!strcmp(ptr, "yes")) {
4556 } else if (!strcmp(ptr, "no")) {
4560 val = simple_strtoul(ptr, &ptr, 0);
4562 switch ((toke = qla1280_get_token(cp))) {
4565 driver_setup.no_nvram = 1;
4569 driver_setup.no_sync = 1;
4570 else if (val != 0x10000)
4571 driver_setup.sync_mask = val;
4575 driver_setup.no_wide = 1;
4576 else if (val != 0x10000)
4577 driver_setup.wide_mask = val;
4581 driver_setup.no_ppr = 1;
4582 else if (val != 0x10000)
4583 driver_setup.ppr_mask = val;
4586 qla1280_verbose = val;
4589 printk(KERN_INFO "qla1280: unknown boot option %s\n",
4593 cp = strchr(ptr, ';');
4605 qla1280_get_token(char *str)
4611 len = sizeof(setup_token)/sizeof(struct setup_tokens);
4613 sep = strchr(str, ':');
4616 for (i = 0; i < len; i++){
4618 if (!strncmp(setup_token[i].token, str, (sep - str))) {
4619 ret = setup_token[i].val;
4628 #if LINUX_VERSION_CODE >= 0x020600
4629 static struct scsi_host_template qla1280_driver_template = {
4630 .proc_name = "qla1280",
4631 .name = "Qlogic ISP 1280/12160",
4632 .info = qla1280_info,
4633 .slave_configure = qla1280_slave_configure,
4634 .queuecommand = qla1280_queuecommand,
4635 .eh_abort_handler = qla1280_eh_abort,
4636 .eh_device_reset_handler= qla1280_eh_device_reset,
4637 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4638 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4639 .bios_param = qla1280_biosparam,
4640 .proc_info = qla1280_proc_info,
4641 .can_queue = 0xfffff,
4643 .sg_tablesize = SG_ALL,
4645 .use_clustering = ENABLE_CLUSTERING,
4648 static Scsi_Host_Template qla1280_driver_template = {
4649 .proc_name = "qla1280",
4650 .name = "Qlogic ISP 1280/12160",
4651 .detect = qla1280_detect,
4652 .release = qla1280_release,
4653 .info = qla1280_info,
4654 .queuecommand = qla1280_queuecommand,
4655 .eh_abort_handler = qla1280_eh_abort,
4656 .eh_device_reset_handler= qla1280_eh_device_reset,
4657 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4658 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4659 .bios_param = qla1280_biosparam_old,
4660 .proc_info = qla1280_proc_info_old,
4661 .can_queue = 0xfffff,
4663 .sg_tablesize = SG_ALL,
4665 .use_clustering = ENABLE_CLUSTERING,
4666 .use_new_eh_code = 1,
4670 static int __devinit
4671 qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4673 int devnum = id->driver_data;
4674 struct qla_boards *bdp = &ql1280_board_tbl[devnum];
4675 struct Scsi_Host *host;
4676 struct scsi_qla_host *ha;
4677 int error = -ENODEV;
4679 /* Bypass all AMI SUBSYS VENDOR IDs */
4680 if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
4682 "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
4686 printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
4687 bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
4689 if (pci_enable_device(pdev)) {
4691 "qla1280: Failed to enabled pci device, aborting.\n");
4695 pci_set_master(pdev);
4698 host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
4701 "qla1280: Failed to register host, aborting.\n");
4702 goto error_disable_device;
4705 ha = (struct scsi_qla_host *)host->hostdata;
4706 memset(ha, 0, sizeof(struct scsi_qla_host));
4709 ha->devnum = devnum; /* specifies microcode load address */
4711 #ifdef QLA_64BIT_PTR
4712 if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) {
4713 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4714 printk(KERN_WARNING "scsi(%li): Unable to set a "
4715 " suitable DMA mask - aboring\n", ha->host_no);
4717 goto error_free_irq;
4720 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4723 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4724 printk(KERN_WARNING "scsi(%li): Unable to set a "
4725 " suitable DMA mask - aboring\n", ha->host_no);
4727 goto error_free_irq;
4731 ha->request_ring = pci_alloc_consistent(ha->pdev,
4732 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4734 if (!ha->request_ring) {
4735 printk(KERN_INFO "qla1280: Failed to get request memory\n");
4736 goto error_put_host;
4739 ha->response_ring = pci_alloc_consistent(ha->pdev,
4740 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4742 if (!ha->response_ring) {
4743 printk(KERN_INFO "qla1280: Failed to get response memory\n");
4744 goto error_free_request_ring;
4747 ha->ports = bdp->numPorts;
4750 ha->host_no = host->host_no;
4752 host->irq = pdev->irq;
4753 host->max_channel = bdp->numPorts - 1;
4754 host->max_lun = MAX_LUNS - 1;
4755 host->max_id = MAX_TARGETS;
4756 host->max_sectors = 1024;
4757 host->unique_id = host->host_no;
4759 #if LINUX_VERSION_CODE < 0x020545
4760 host->select_queue_depths = qla1280_select_queue_depth;
4765 #if MEMORY_MAPPED_IO
4766 ha->mmpbase = ioremap(pci_resource_start(ha->pdev, 1),
4767 pci_resource_len(ha->pdev, 1));
4769 printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
4770 goto error_free_response_ring;
4773 host->base = (unsigned long)ha->mmpbase;
4774 ha->iobase = (struct device_reg *)ha->mmpbase;
4776 host->io_port = pci_resource_start(ha->pdev, 0);
4777 if (!request_region(host->io_port, 0xff, "qla1280")) {
4778 printk(KERN_INFO "qla1280: Failed to reserve i/o region "
4779 "0x%04lx-0x%04lx - already in use\n",
4780 host->io_port, host->io_port + 0xff);
4781 goto error_free_response_ring;
4784 ha->iobase = (struct device_reg *)host->io_port;
4787 INIT_LIST_HEAD(&ha->done_q);
4789 /* Disable ISP interrupts. */
4790 qla1280_disable_intrs(ha);
4792 if (request_irq(pdev->irq, qla1280_intr_handler, SA_SHIRQ,
4794 printk("qla1280 : Failed to reserve interrupt %d already "
4795 "in use\n", pdev->irq);
4796 goto error_release_region;
4799 /* load the F/W, read paramaters, and init the H/W */
4800 if (qla1280_initialize_adapter(ha)) {
4801 printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
4802 goto error_free_irq;
4805 /* set our host ID (need to do something about our two IDs) */
4806 host->this_id = ha->bus_settings[0].id;
4808 pci_set_drvdata(pdev, host);
4810 #if LINUX_VERSION_CODE >= 0x020600
4811 error = scsi_add_host(host, &pdev->dev);
4813 goto error_disable_adapter;
4814 scsi_scan_host(host);
4816 scsi_set_pci_device(host, pdev);
4821 #if LINUX_VERSION_CODE >= 0x020600
4822 error_disable_adapter:
4823 WRT_REG_WORD(&ha->iobase->ictrl, 0);
4826 free_irq(pdev->irq, ha);
4827 error_release_region:
4828 #if MEMORY_MAPPED_IO
4829 iounmap(ha->mmpbase);
4831 release_region(host->io_port, 0xff);
4833 error_free_response_ring:
4834 pci_free_consistent(ha->pdev,
4835 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4836 ha->response_ring, ha->response_dma);
4837 error_free_request_ring:
4838 pci_free_consistent(ha->pdev,
4839 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4840 ha->request_ring, ha->request_dma);
4842 scsi_host_put(host);
4843 error_disable_device:
4844 pci_disable_device(pdev);
4850 static void __devexit
4851 qla1280_remove_one(struct pci_dev *pdev)
4853 struct Scsi_Host *host = pci_get_drvdata(pdev);
4854 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
4856 #if LINUX_VERSION_CODE >= 0x020600
4857 scsi_remove_host(host);
4860 WRT_REG_WORD(&ha->iobase->ictrl, 0);
4862 free_irq(pdev->irq, ha);
4864 #if MEMORY_MAPPED_IO
4865 iounmap(ha->mmpbase);
4867 release_region(host->io_port, 0xff);
4870 pci_free_consistent(ha->pdev,
4871 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4872 ha->request_ring, ha->request_dma);
4873 pci_free_consistent(ha->pdev,
4874 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4875 ha->response_ring, ha->response_dma);
4877 pci_disable_device(pdev);
4879 scsi_host_put(host);
4882 #if LINUX_VERSION_CODE >= 0x020600
4883 static struct pci_driver qla1280_pci_driver = {
4885 .id_table = qla1280_pci_tbl,
4886 .probe = qla1280_probe_one,
4887 .remove = __devexit_p(qla1280_remove_one),
4893 if (sizeof(struct srb) > sizeof(struct scsi_pointer)) {
4895 "qla1280: struct srb too big, aborting\n");
4901 * If we are called as a module, the qla1280 pointer may not be null
4902 * and it would point to our bootup string, just like on the lilo
4903 * command line. IF not NULL, then process this config string with
4907 * To add options at boot time add a line to your lilo.conf file like:
4908 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
4909 * which will result in the first four devices on the first two
4910 * controllers being set to a tagged queue depth of 32.
4913 qla1280_setup(qla1280);
4916 return pci_module_init(&qla1280_pci_driver);
4922 pci_unregister_driver(&qla1280_pci_driver);
4925 module_init(qla1280_init);
4926 module_exit(qla1280_exit);
4929 # define driver_template qla1280_driver_template
4930 # include "scsi_module.c"
4933 MODULE_AUTHOR("Qlogic & Jes Sorensen");
4934 MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
4935 MODULE_LICENSE("GPL");
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 * ---------------------------------------------------------------------------