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>
360 #include <scsi/scsi_host.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.
3122 #ifdef QLA_64BIT_PTR
3124 qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3126 struct device_reg *reg = ha->iobase;
3127 struct scsi_cmnd *cmd = sp->cmd;
3128 cmd_a64_entry_t *pkt;
3129 struct scatterlist *sg = NULL;
3131 dma_addr_t dma_handle;
3138 ENTER("qla1280_64bit_start_scsi:");
3140 /* Calculate number of entries and segments required. */
3143 sg = (struct scatterlist *) cmd->request_buffer;
3144 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3145 cmd->sc_data_direction);
3148 req_cnt += (seg_cnt - 2) / 5;
3149 if ((seg_cnt - 2) % 5)
3152 } else if (cmd->request_bufflen) { /* If data transfer. */
3158 if ((req_cnt + 2) >= ha->req_q_cnt) {
3159 /* Calculate number of free request entries. */
3160 cnt = RD_REG_WORD(®->mailbox4);
3161 if (ha->req_ring_index < cnt)
3162 ha->req_q_cnt = cnt - ha->req_ring_index;
3165 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3168 /* If room for request in request ring. */
3169 if ((req_cnt + 2) >= ha->req_q_cnt) {
3171 dprintk(2, "qla1280_64bit_start_scsi: in-ptr=0x%x req_q_cnt="
3172 "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
3177 /* Check for room in outstanding command list. */
3178 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3179 ha->outstanding_cmds[cnt] != 0; cnt++);
3181 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3183 dprintk(2, "qla1280_64bit_start_scsi: NO ROOM IN "
3184 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
3188 ha->outstanding_cmds[cnt] = sp;
3189 ha->req_q_cnt -= req_cnt;
3190 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
3192 dprintk(2, "64bit_start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
3193 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
3194 dprintk(2, " bus %i, target %i, lun %i\n",
3195 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3196 qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
3199 * Build command packet.
3201 pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
3203 pkt->entry_type = COMMAND_A64_TYPE;
3204 pkt->entry_count = (uint8_t) req_cnt;
3205 pkt->sys_define = (uint8_t) ha->req_ring_index;
3206 pkt->entry_status = 0;
3207 pkt->handle = cpu_to_le32(cnt);
3209 /* Zero out remaining portion of packet. */
3210 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3212 /* Set ISP command timeout. */
3213 pkt->timeout = cpu_to_le16(30);
3215 /* Set device target ID and LUN */
3216 pkt->lun = SCSI_LUN_32(cmd);
3217 pkt->target = SCSI_BUS_32(cmd) ?
3218 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3220 /* Enable simple tag queuing if device supports it. */
3221 if (DEV_SIMPLE_TAGS(cmd->device))
3222 pkt->control_flags |= cpu_to_le16(BIT_3);
3224 /* Load SCSI command packet. */
3225 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3226 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3227 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3229 /* Set transfer direction. */
3230 dir = qla1280_data_direction(cmd);
3231 pkt->control_flags |= cpu_to_le16(dir);
3233 /* Set total data segment count. */
3234 pkt->dseg_count = cpu_to_le16(seg_cnt);
3237 * Load data segments.
3239 if (seg_cnt) { /* If data transfer. */
3240 /* Setup packet address segment pointer. */
3241 dword_ptr = (u32 *)&pkt->dseg_0_address;
3243 if (cmd->use_sg) { /* If scatter gather */
3244 /* Load command entry data segments. */
3245 for (cnt = 0; cnt < 2 && seg_cnt; cnt++, seg_cnt--) {
3246 dma_handle = sg_dma_address(sg);
3247 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3248 if (ha->flags.use_pci_vchannel)
3249 sn_pci_set_vchan(ha->pdev, &dma_handle,
3253 cpu_to_le32(pci_dma_lo32(dma_handle));
3255 cpu_to_le32(pci_dma_hi32(dma_handle));
3256 *dword_ptr++ = cpu_to_le32(sg_dma_len(sg));
3258 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
3259 cpu_to_le32(pci_dma_hi32(dma_handle)),
3260 cpu_to_le32(pci_dma_lo32(dma_handle)),
3261 cpu_to_le32(sg_dma_len(sg)));
3263 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
3264 "command packet data - b %i, t %i, l %i \n",
3265 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3267 qla1280_dump_buffer(5, (char *)pkt,
3268 REQUEST_ENTRY_SIZE);
3271 * Build continuation packets.
3273 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
3274 "remains\n", seg_cnt);
3276 while (seg_cnt > 0) {
3277 /* Adjust ring index. */
3278 ha->req_ring_index++;
3279 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3280 ha->req_ring_index = 0;
3281 ha->request_ring_ptr =
3284 ha->request_ring_ptr++;
3286 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
3288 /* Zero out packet. */
3289 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3291 /* Load packet defaults. */
3292 ((struct cont_a64_entry *) pkt)->entry_type =
3294 ((struct cont_a64_entry *) pkt)->entry_count = 1;
3295 ((struct cont_a64_entry *) pkt)->sys_define =
3296 (uint8_t)ha->req_ring_index;
3297 /* Setup packet address segment pointer. */
3299 (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
3301 /* Load continuation entry data segments. */
3302 for (cnt = 0; cnt < 5 && seg_cnt;
3304 dma_handle = sg_dma_address(sg);
3305 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3306 if (ha->flags.use_pci_vchannel)
3307 sn_pci_set_vchan(ha->pdev, &dma_handle,
3311 cpu_to_le32(pci_dma_lo32(dma_handle));
3313 cpu_to_le32(pci_dma_hi32(dma_handle));
3315 cpu_to_le32(sg_dma_len(sg));
3316 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
3317 cpu_to_le32(pci_dma_hi32(dma_handle)),
3318 cpu_to_le32(pci_dma_lo32(dma_handle)),
3319 cpu_to_le32(sg_dma_len(sg)));
3322 dprintk(5, "qla1280_64bit_start_scsi: "
3323 "continuation packet data - b %i, t "
3324 "%i, l %i \n", SCSI_BUS_32(cmd),
3325 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3326 qla1280_dump_buffer(5, (char *)pkt,
3327 REQUEST_ENTRY_SIZE);
3329 } else { /* No scatter gather data transfer */
3330 struct page *page = virt_to_page(cmd->request_buffer);
3331 unsigned long off = (unsigned long)cmd->request_buffer & ~PAGE_MASK;
3333 dma_handle = pci_map_page(ha->pdev, page, off,
3334 cmd->request_bufflen,
3335 cmd->sc_data_direction);
3337 /* save dma_handle for pci_unmap_page */
3338 sp->saved_dma_handle = dma_handle;
3339 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3340 if (ha->flags.use_pci_vchannel)
3341 sn_pci_set_vchan(ha->pdev, &dma_handle,
3344 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3345 *dword_ptr++ = cpu_to_le32(pci_dma_hi32(dma_handle));
3346 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3348 dprintk(5, "qla1280_64bit_start_scsi: No scatter/"
3349 "gather command packet data - b %i, t %i, "
3350 "l %i \n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3352 qla1280_dump_buffer(5, (char *)pkt,
3353 REQUEST_ENTRY_SIZE);
3355 } else { /* No data transfer */
3356 dprintk(5, "qla1280_64bit_start_scsi: No data, command "
3357 "packet data - b %i, t %i, l %i \n",
3358 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3359 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3361 /* Adjust ring index. */
3362 ha->req_ring_index++;
3363 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3364 ha->req_ring_index = 0;
3365 ha->request_ring_ptr = ha->request_ring;
3367 ha->request_ring_ptr++;
3369 /* Set chip new ring index. */
3371 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
3372 sp->flags |= SRB_SENT;
3374 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3375 (void) RD_REG_WORD(®->mailbox4); /* PCI posted write flush */
3379 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
3381 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
3385 #else /* !QLA_64BIT_PTR */
3388 * qla1280_32bit_start_scsi
3389 * The start SCSI is responsible for building request packets on
3390 * request ring and modifying ISP input pointer.
3392 * The Qlogic firmware interface allows every queue slot to have a SCSI
3393 * command and up to 4 scatter/gather (SG) entries. If we need more
3394 * than 4 SG entries, then continuation entries are used that can
3395 * hold another 7 entries each. The start routine determines if there
3396 * is eought empty slots then build the combination of requests to
3397 * fulfill the OS request.
3400 * ha = adapter block pointer.
3401 * sp = SCSI Request Block structure pointer.
3404 * 0 = success, was able to issue command.
3407 qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3409 struct device_reg *reg = ha->iobase;
3410 struct scsi_cmnd *cmd = sp->cmd;
3411 struct cmd_entry *pkt;
3412 struct scatterlist *sg = NULL;
3413 uint32_t *dword_ptr;
3418 dma_addr_t dma_handle;
3421 ENTER("qla1280_32bit_start_scsi");
3423 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
3426 /* Calculate number of entries and segments required. */
3430 * We must build an SG list in adapter format, as the kernel's
3431 * SG list cannot be used directly because of data field size
3432 * (__alpha__) differences and the kernel SG list uses virtual
3433 * addresses where we need physical addresses.
3435 sg = (struct scatterlist *) cmd->request_buffer;
3436 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3437 cmd->sc_data_direction);
3440 * if greater than four sg entries then we need to allocate
3441 * continuation entries
3444 req_cnt += (seg_cnt - 4) / 7;
3445 if ((seg_cnt - 4) % 7)
3448 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3449 cmd, seg_cnt, req_cnt);
3450 } else if (cmd->request_bufflen) { /* If data transfer. */
3451 dprintk(3, "No S/G transfer t=%x cmd=%p len=%x CDB=%x\n",
3452 SCSI_TCN_32(cmd), cmd, cmd->request_bufflen,
3456 /* dprintk(1, "No data transfer \n"); */
3460 if ((req_cnt + 2) >= ha->req_q_cnt) {
3461 /* Calculate number of free request entries. */
3462 cnt = RD_REG_WORD(®->mailbox4);
3463 if (ha->req_ring_index < cnt)
3464 ha->req_q_cnt = cnt - ha->req_ring_index;
3467 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3470 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3471 ha->req_q_cnt, seg_cnt);
3472 /* If room for request in request ring. */
3473 if ((req_cnt + 2) >= ha->req_q_cnt) {
3475 dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
3476 "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
3477 ha->req_q_cnt, req_cnt);
3481 /* Check for empty slot in outstanding command list. */
3482 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3483 (ha->outstanding_cmds[cnt] != 0); cnt++) ;
3485 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3487 dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
3488 "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
3492 CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
3493 ha->outstanding_cmds[cnt] = sp;
3494 ha->req_q_cnt -= req_cnt;
3497 * Build command packet.
3499 pkt = (struct cmd_entry *) ha->request_ring_ptr;
3501 pkt->entry_type = COMMAND_TYPE;
3502 pkt->entry_count = (uint8_t) req_cnt;
3503 pkt->sys_define = (uint8_t) ha->req_ring_index;
3504 pkt->entry_status = 0;
3505 pkt->handle = cpu_to_le32(cnt);
3507 /* Zero out remaining portion of packet. */
3508 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3510 /* Set ISP command timeout. */
3511 pkt->timeout = cpu_to_le16(30);
3513 /* Set device target ID and LUN */
3514 pkt->lun = SCSI_LUN_32(cmd);
3515 pkt->target = SCSI_BUS_32(cmd) ?
3516 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3518 /* Enable simple tag queuing if device supports it. */
3519 if (DEV_SIMPLE_TAGS(cmd->device))
3520 pkt->control_flags |= cpu_to_le16(BIT_3);
3522 /* Load SCSI command packet. */
3523 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3524 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3526 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3527 /* Set transfer direction. */
3528 dir = qla1280_data_direction(cmd);
3529 pkt->control_flags |= cpu_to_le16(dir);
3531 /* Set total data segment count. */
3532 pkt->dseg_count = cpu_to_le16(seg_cnt);
3535 * Load data segments.
3538 /* Setup packet address segment pointer. */
3539 dword_ptr = &pkt->dseg_0_address;
3541 if (cmd->use_sg) { /* If scatter gather */
3542 dprintk(3, "Building S/G data segments..\n");
3543 qla1280_dump_buffer(1, (char *)sg, 4 * 16);
3545 /* Load command entry data segments. */
3546 for (cnt = 0; cnt < 4 && seg_cnt; cnt++, seg_cnt--) {
3548 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3550 cpu_to_le32(sg_dma_len(sg));
3551 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3552 (pci_dma_lo32(sg_dma_address(sg))),
3557 * Build continuation packets.
3559 dprintk(3, "S/G Building Continuation"
3560 "...seg_cnt=0x%x remains\n", seg_cnt);
3561 while (seg_cnt > 0) {
3562 /* Adjust ring index. */
3563 ha->req_ring_index++;
3564 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3565 ha->req_ring_index = 0;
3566 ha->request_ring_ptr =
3569 ha->request_ring_ptr++;
3571 pkt = (struct cmd_entry *)ha->request_ring_ptr;
3573 /* Zero out packet. */
3574 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3576 /* Load packet defaults. */
3577 ((struct cont_entry *) pkt)->
3578 entry_type = CONTINUE_TYPE;
3579 ((struct cont_entry *) pkt)->entry_count = 1;
3581 ((struct cont_entry *) pkt)->sys_define =
3582 (uint8_t) ha->req_ring_index;
3584 /* Setup packet address segment pointer. */
3586 &((struct cont_entry *) pkt)->dseg_0_address;
3588 /* Load continuation entry data segments. */
3589 for (cnt = 0; cnt < 7 && seg_cnt;
3592 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3594 cpu_to_le32(sg_dma_len(sg));
3596 "S/G Segment Cont. phys_addr=0x%x, "
3598 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
3599 cpu_to_le32(sg_dma_len(sg)));
3602 dprintk(5, "qla1280_32bit_start_scsi: "
3603 "continuation packet data - "
3604 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
3605 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3606 qla1280_dump_buffer(5, (char *)pkt,
3607 REQUEST_ENTRY_SIZE);
3609 } else { /* No S/G data transfer */
3610 struct page *page = virt_to_page(cmd->request_buffer);
3611 unsigned long off = (unsigned long)cmd->request_buffer & ~PAGE_MASK;
3612 dma_handle = pci_map_page(ha->pdev, page, off,
3613 cmd->request_bufflen,
3614 cmd->sc_data_direction);
3615 sp->saved_dma_handle = dma_handle;
3617 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3618 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3620 } else { /* No data transfer at all */
3621 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
3622 "packet data - \n");
3623 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3625 dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
3626 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3627 REQUEST_ENTRY_SIZE);
3629 /* Adjust ring index. */
3630 ha->req_ring_index++;
3631 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3632 ha->req_ring_index = 0;
3633 ha->request_ring_ptr = ha->request_ring;
3635 ha->request_ring_ptr++;
3637 /* Set chip new ring index. */
3638 dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
3639 "for pending command\n");
3640 sp->flags |= SRB_SENT;
3642 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3643 (void) RD_REG_WORD(®->mailbox4); /* PCI posted write flush */
3647 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
3649 LEAVE("qla1280_32bit_start_scsi");
3657 * Function is responsible for locking ring and
3658 * getting a zeroed out request packet.
3661 * ha = adapter block pointer.
3664 * 0 = failed to get slot.
3667 qla1280_req_pkt(struct scsi_qla_host *ha)
3669 struct device_reg *reg = ha->iobase;
3674 ENTER("qla1280_req_pkt");
3677 * This can be called from interrupt context, damn it!!!
3679 /* Wait for 30 seconds for slot. */
3680 for (timer = 15000000; timer; timer--) {
3681 if (ha->req_q_cnt > 0) {
3682 /* Calculate number of free request entries. */
3683 cnt = RD_REG_WORD(®->mailbox4);
3684 if (ha->req_ring_index < cnt)
3685 ha->req_q_cnt = cnt - ha->req_ring_index;
3688 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3691 /* Found empty request ring slot? */
3692 if (ha->req_q_cnt > 0) {
3694 pkt = ha->request_ring_ptr;
3696 /* Zero out packet. */
3697 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3700 * How can this be right when we have a ring
3703 /* Set system defined field. */
3704 pkt->sys_define = (uint8_t) ha->req_ring_index;
3706 /* Set entry count. */
3707 pkt->entry_count = 1;
3714 /* Check for pending interrupts. */
3719 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
3721 dprintk(3, "qla1280_req_pkt: exiting normally\n");
3728 * Function is responsible for modifying ISP input pointer.
3729 * Releases ring lock.
3732 * ha = adapter block pointer.
3735 qla1280_isp_cmd(struct scsi_qla_host *ha)
3737 struct device_reg *reg = ha->iobase;
3739 ENTER("qla1280_isp_cmd");
3741 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
3742 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3743 REQUEST_ENTRY_SIZE);
3745 /* Adjust ring index. */
3746 ha->req_ring_index++;
3747 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3748 ha->req_ring_index = 0;
3749 ha->request_ring_ptr = ha->request_ring;
3751 ha->request_ring_ptr++;
3753 /* Set chip new ring index. */
3754 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3755 (void) RD_REG_WORD(®->mailbox4); /* PCI posted write flush */
3757 LEAVE("qla1280_isp_cmd");
3760 /****************************************************************************/
3761 /* Interrupt Service Routine. */
3762 /****************************************************************************/
3764 /****************************************************************************
3766 * Calls I/O done on command completion.
3769 * ha = adapter block pointer.
3770 * done_q = done queue.
3771 ****************************************************************************/
3773 qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
3775 struct device_reg *reg = ha->iobase;
3776 struct response *pkt;
3778 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
3783 ENTER("qla1280_isr");
3785 istatus = RD_REG_WORD(®->istatus);
3786 if (!(istatus & (RISC_INT | PCI_INT)))
3789 /* Save mailbox register 5 */
3790 mailbox[5] = RD_REG_WORD(®->mailbox5);
3792 /* Check for mailbox interrupt. */
3794 mailbox[0] = RD_REG_WORD_dmasync(®->semaphore);
3796 if (mailbox[0] & BIT_0) {
3797 /* Get mailbox data. */
3798 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
3801 *wptr++ = RD_REG_WORD(®->mailbox0);
3802 *wptr++ = RD_REG_WORD(®->mailbox1);
3803 *wptr = RD_REG_WORD(®->mailbox2);
3804 if (mailbox[0] != MBA_SCSI_COMPLETION) {
3806 *wptr++ = RD_REG_WORD(®->mailbox3);
3807 *wptr++ = RD_REG_WORD(®->mailbox4);
3809 *wptr++ = RD_REG_WORD(®->mailbox6);
3810 *wptr = RD_REG_WORD(®->mailbox7);
3813 /* Release mailbox registers. */
3815 WRT_REG_WORD(®->semaphore, 0);
3816 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3818 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
3821 /* Handle asynchronous event */
3822 switch (mailbox[0]) {
3823 case MBA_SCSI_COMPLETION: /* Response completion */
3824 dprintk(5, "qla1280_isr: mailbox SCSI response "
3827 if (ha->flags.online) {
3828 /* Get outstanding command index. */
3829 index = mailbox[2] << 16 | mailbox[1];
3831 /* Validate handle. */
3832 if (index < MAX_OUTSTANDING_COMMANDS)
3833 sp = ha->outstanding_cmds[index];
3838 /* Free outstanding command slot. */
3839 ha->outstanding_cmds[index] = 0;
3841 /* Save ISP completion status */
3842 CMD_RESULT(sp->cmd) = 0;
3844 /* Place block on done queue */
3845 list_add_tail(&sp->list, done_q);
3848 * If we get here we have a real problem!
3851 "qla1280: ISP invalid handle");
3856 case MBA_BUS_RESET: /* SCSI Bus Reset */
3857 ha->flags.reset_marker = 1;
3858 index = mailbox[6] & BIT_0;
3859 ha->bus_settings[index].reset_marker = 1;
3861 printk(KERN_DEBUG "qla1280_isr(): index %i "
3862 "asynchronous BUS_RESET\n", index);
3865 case MBA_SYSTEM_ERR: /* System Error */
3867 "qla1280: ISP System Error - mbx1=%xh, mbx2="
3868 "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
3872 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
3874 "qla1280: ISP Request Transfer Error\n");
3877 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
3879 "qla1280: ISP Response Transfer Error\n");
3882 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
3883 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
3886 case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
3888 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
3891 case MBA_DEVICE_RESET: /* Bus Device Reset */
3892 printk(KERN_INFO "qla1280_isr(): asynchronous "
3893 "BUS_DEVICE_RESET\n");
3895 ha->flags.reset_marker = 1;
3896 index = mailbox[6] & BIT_0;
3897 ha->bus_settings[index].reset_marker = 1;
3900 case MBA_BUS_MODE_CHANGE:
3902 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
3906 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
3907 if (mailbox[0] < MBA_ASYNC_EVENT) {
3909 memcpy((uint16_t *) ha->mailbox_out, wptr,
3910 MAILBOX_REGISTER_COUNT *
3913 if(ha->mailbox_wait != NULL)
3914 complete(ha->mailbox_wait);
3919 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3923 * We will receive interrupts during mailbox testing prior to
3924 * the card being marked online, hence the double check.
3926 if (!(ha->flags.online && !ha->mailbox_wait)) {
3927 dprintk(2, "qla1280_isr: Response pointer Error\n");
3931 if (mailbox[5] >= RESPONSE_ENTRY_CNT)
3934 while (ha->rsp_ring_index != mailbox[5]) {
3935 pkt = ha->response_ring_ptr;
3937 dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
3938 " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
3939 dprintk(5,"qla1280_isr: response packet data\n");
3940 qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
3942 if (pkt->entry_type == STATUS_TYPE) {
3943 if ((le16_to_cpu(pkt->scsi_status) & 0xff)
3944 || pkt->comp_status || pkt->entry_status) {
3945 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3946 "0x%x mailbox[5] = 0x%x, comp_status "
3947 "= 0x%x, scsi_status = 0x%x\n",
3948 ha->rsp_ring_index, mailbox[5],
3949 le16_to_cpu(pkt->comp_status),
3950 le16_to_cpu(pkt->scsi_status));
3953 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3954 "0x%x, mailbox[5] = 0x%x\n",
3955 ha->rsp_ring_index, mailbox[5]);
3956 dprintk(2, "qla1280_isr: response packet data\n");
3957 qla1280_dump_buffer(2, (char *)pkt,
3958 RESPONSE_ENTRY_SIZE);
3961 if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
3962 dprintk(2, "status: Cmd %p, handle %i\n",
3963 ha->outstanding_cmds[pkt->handle]->cmd,
3965 if (pkt->entry_type == STATUS_TYPE)
3966 qla1280_status_entry(ha, pkt, done_q);
3968 qla1280_error_entry(ha, pkt, done_q);
3969 /* Adjust ring index. */
3970 ha->rsp_ring_index++;
3971 if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
3972 ha->rsp_ring_index = 0;
3973 ha->response_ring_ptr = ha->response_ring;
3975 ha->response_ring_ptr++;
3976 WRT_REG_WORD(®->mailbox5, ha->rsp_ring_index);
3981 LEAVE("qla1280_isr");
3986 * Processes asynchronous reset.
3989 * ha = adapter block pointer.
3992 qla1280_rst_aen(struct scsi_qla_host *ha)
3996 ENTER("qla1280_rst_aen");
3998 if (ha->flags.online && !ha->flags.reset_active &&
3999 !ha->flags.abort_isp_active) {
4000 ha->flags.reset_active = 1;
4001 while (ha->flags.reset_marker) {
4002 /* Issue marker command. */
4003 ha->flags.reset_marker = 0;
4004 for (bus = 0; bus < ha->ports &&
4005 !ha->flags.reset_marker; bus++) {
4006 if (ha->bus_settings[bus].reset_marker) {
4007 ha->bus_settings[bus].reset_marker = 0;
4008 qla1280_marker(ha, bus, 0, 0,
4015 LEAVE("qla1280_rst_aen");
4019 #if LINUX_VERSION_CODE < 0x020500
4024 qla1280_get_target_options(struct scsi_cmnd *cmd, struct scsi_qla_host *ha)
4026 unsigned char *result;
4028 int bus, target, lun;
4030 bus = SCSI_BUS_32(cmd);
4031 target = SCSI_TCN_32(cmd);
4032 lun = SCSI_LUN_32(cmd);
4035 * Make sure to not touch anything if someone is using the
4038 if (cmd->use_sg || (CMD_RESULT(cmd) >> 16) != DID_OK || lun)
4041 result = cmd->request_buffer;
4044 n->bus[bus].target[target].parameter.f.enable_wide = 0;
4045 n->bus[bus].target[target].parameter.f.enable_sync = 0;
4046 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
4048 if (result[7] & 0x60)
4049 n->bus[bus].target[target].parameter.f.enable_wide = 1;
4050 if (result[7] & 0x10)
4051 n->bus[bus].target[target].parameter.f.enable_sync = 1;
4052 if ((result[2] >= 3) && (result[4] + 5 > 56) &&
4054 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
4056 dprintk(2, "get_target_options(): wide %i, sync %i, ppr %i\n",
4057 n->bus[bus].target[target].parameter.f.enable_wide,
4058 n->bus[bus].target[target].parameter.f.enable_sync,
4059 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr);
4064 * qla1280_status_entry
4065 * Processes received ISP status entry.
4068 * ha = adapter block pointer.
4069 * pkt = entry pointer.
4070 * done_q = done queue.
4073 qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
4074 struct list_head *done_q)
4076 unsigned int bus, target, lun;
4079 struct scsi_cmnd *cmd;
4080 uint32_t handle = le32_to_cpu(pkt->handle);
4081 uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
4082 uint16_t comp_status = le16_to_cpu(pkt->comp_status);
4084 ENTER("qla1280_status_entry");
4086 /* Validate handle. */
4087 if (handle < MAX_OUTSTANDING_COMMANDS)
4088 sp = ha->outstanding_cmds[handle];
4093 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
4097 /* Free outstanding command slot. */
4098 ha->outstanding_cmds[handle] = 0;
4102 /* Generate LU queue on cntrl, target, LUN */
4103 bus = SCSI_BUS_32(cmd);
4104 target = SCSI_TCN_32(cmd);
4105 lun = SCSI_LUN_32(cmd);
4107 if (comp_status || scsi_status) {
4108 dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
4109 "0x%x, handle = 0x%x\n", comp_status,
4110 scsi_status, handle);
4114 if (scsi_status & SS_BUSY_CONDITION &&
4115 scsi_status != SS_RESERVE_CONFLICT) {
4117 DID_BUS_BUSY << 16 | (scsi_status & 0xff);
4120 /* Save ISP completion status */
4121 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
4123 if (scsi_status & SS_CHECK_CONDITION) {
4124 if (comp_status != CS_ARS_FAILED) {
4125 uint16_t req_sense_length =
4126 le16_to_cpu(pkt->req_sense_length);
4127 if (req_sense_length < CMD_SNSLEN(cmd))
4128 sense_sz = req_sense_length;
4131 * scsi_cmnd->sense_buffer is
4132 * 64 bytes, why only copy 63?
4133 * This looks wrong! /Jes
4135 sense_sz = CMD_SNSLEN(cmd) - 1;
4137 memcpy(cmd->sense_buffer,
4138 &pkt->req_sense_data, sense_sz);
4141 memset(cmd->sense_buffer + sense_sz, 0,
4142 sizeof(cmd->sense_buffer) - sense_sz);
4144 dprintk(2, "qla1280_status_entry: Check "
4145 "condition Sense data, b %i, t %i, "
4146 "l %i\n", bus, target, lun);
4148 qla1280_dump_buffer(2,
4149 (char *)cmd->sense_buffer,
4154 /* Place command on done queue. */
4155 list_add_tail(&sp->list, done_q);
4157 LEAVE("qla1280_status_entry");
4161 * qla1280_error_entry
4162 * Processes error entry.
4165 * ha = adapter block pointer.
4166 * pkt = entry pointer.
4167 * done_q = done queue.
4170 qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
4171 struct list_head *done_q)
4174 uint32_t handle = le32_to_cpu(pkt->handle);
4176 ENTER("qla1280_error_entry");
4178 if (pkt->entry_status & BIT_3)
4179 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
4180 else if (pkt->entry_status & BIT_2)
4181 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
4182 else if (pkt->entry_status & BIT_1)
4183 dprintk(2, "qla1280_error_entry: FULL flag error\n");
4185 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
4187 /* Validate handle. */
4188 if (handle < MAX_OUTSTANDING_COMMANDS)
4189 sp = ha->outstanding_cmds[handle];
4194 /* Free outstanding command slot. */
4195 ha->outstanding_cmds[handle] = 0;
4197 /* Bad payload or header */
4198 if (pkt->entry_status & (BIT_3 + BIT_2)) {
4199 /* Bad payload or header, set error status. */
4200 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
4201 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
4202 } else if (pkt->entry_status & BIT_1) { /* FULL flag */
4203 CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
4205 /* Set error status. */
4206 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
4209 /* Place command on done queue. */
4210 list_add_tail(&sp->list, done_q);
4212 #ifdef QLA_64BIT_PTR
4213 else if (pkt->entry_type == COMMAND_A64_TYPE) {
4214 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
4218 LEAVE("qla1280_error_entry");
4223 * Resets ISP and aborts all outstanding commands.
4226 * ha = adapter block pointer.
4232 qla1280_abort_isp(struct scsi_qla_host *ha)
4239 ENTER("qla1280_abort_isp");
4241 if (!ha->flags.abort_isp_active && ha->flags.online) {
4242 struct device_reg *reg = ha->iobase;
4243 ha->flags.abort_isp_active = 1;
4245 /* Disable ISP interrupts. */
4246 qla1280_disable_intrs(ha);
4247 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
4248 RD_REG_WORD(®->id_l);
4250 printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
4252 /* Dequeue all commands in outstanding command list. */
4253 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
4254 struct scsi_cmnd *cmd;
4255 sp = ha->outstanding_cmds[cnt];
4259 CMD_RESULT(cmd) = DID_RESET << 16;
4262 ha->outstanding_cmds[cnt] = NULL;
4264 (*cmd->scsi_done)(cmd);
4270 /* If firmware needs to be loaded */
4271 if (qla1280_isp_firmware (ha)) {
4272 if (!(status = qla1280_chip_diag(ha)))
4273 status = qla1280_setup_chip(ha);
4277 /* Setup adapter based on NVRAM parameters. */
4278 qla1280_nvram_config (ha);
4280 if (!(status = qla1280_init_rings(ha))) {
4281 /* Issue SCSI reset. */
4282 for (bus = 0; bus < ha->ports; bus++) {
4283 qla1280_bus_reset(ha, bus);
4286 * qla1280_bus_reset() will do the marker
4287 * dance - no reason to repeat here!
4290 /* Issue marker command. */
4291 ha->flags.reset_marker = 0;
4292 for (bus = 0; bus < ha->ports; bus++) {
4293 ha->bus_settings[bus].
4295 qla1280_marker(ha, bus, 0, 0,
4299 ha->flags.abort_isp_active = 0;
4306 "qla1280: ISP error recovery failed, board disabled");
4307 qla1280_reset_adapter(ha);
4308 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
4311 LEAVE("qla1280_abort_isp");
4317 * qla1280_debounce_register
4318 * Debounce register.
4321 * port = register address.
4327 qla1280_debounce_register(volatile u16 * addr)
4332 ret = RD_REG_WORD(addr);
4333 ret2 = RD_REG_WORD(addr);
4340 ret = RD_REG_WORD(addr);
4341 ret2 = RD_REG_WORD(addr);
4342 } while (ret != ret2);
4348 /************************************************************************
4349 * qla1280_check_for_dead_scsi_bus *
4351 * This routine checks for a dead SCSI bus *
4352 ************************************************************************/
4353 #define SET_SXP_BANK 0x0100
4354 #define SCSI_PHASE_INVALID 0x87FF
4356 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
4358 uint16_t config_reg, scsi_control;
4359 struct device_reg *reg = ha->iobase;
4361 if (ha->bus_settings[bus].scsi_bus_dead) {
4362 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
4363 config_reg = RD_REG_WORD(®->cfg_1);
4364 WRT_REG_WORD(®->cfg_1, SET_SXP_BANK);
4365 scsi_control = RD_REG_WORD(®->scsiControlPins);
4366 WRT_REG_WORD(®->cfg_1, config_reg);
4367 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
4369 if (scsi_control == SCSI_PHASE_INVALID) {
4370 ha->bus_settings[bus].scsi_bus_dead = 1;
4372 CMD_RESULT(cp) = DID_NO_CONNECT << 16;
4373 CMD_HANDLE(cp) = INVALID_HANDLE;
4374 /* ha->actthreads--; */
4376 (*(cp)->scsi_done)(cp);
4378 return 1; /* bus is dead */
4380 ha->bus_settings[bus].scsi_bus_dead = 0;
4381 ha->bus_settings[bus].failed_reset_count = 0;
4384 return 0; /* bus is not dead */
4388 qla1280_get_target_parameters(struct scsi_qla_host *ha,
4389 struct scsi_device *device)
4391 uint16_t mb[MAILBOX_REGISTER_COUNT];
4392 int bus, target, lun;
4394 bus = device->channel;
4395 target = device->id;
4399 mb[0] = MBC_GET_TARGET_PARAMETERS;
4400 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
4402 qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
4405 printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
4408 printk(" Sync: period %d, offset %d",
4409 (mb[3] & 0xff), (mb[3] >> 8));
4412 if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
4417 if (DEV_SIMPLE_TAGS(device))
4418 printk(", Tagged queuing: depth %d", device->queue_depth);
4425 __qla1280_dump_buffer(char *b, int size)
4430 printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
4431 "Bh Ch Dh Eh Fh\n");
4432 printk(KERN_DEBUG "---------------------------------------------"
4433 "------------------\n");
4435 for (cnt = 0; cnt < size;) {
4438 printk("0x%02x", c);
4449 /**************************************************************************
4450 * ql1280_print_scsi_cmd
4452 **************************************************************************/
4454 __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
4456 struct scsi_qla_host *ha;
4457 struct Scsi_Host *host = CMD_HOST(cmd);
4459 /* struct scatterlist *sg; */
4462 ha = (struct scsi_qla_host *)host->hostdata;
4464 sp = (struct srb *)CMD_SP(cmd);
4465 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
4466 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
4467 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
4470 for (i = 0; i < cmd->cmd_len; i++) {
4471 printk("0x%02x ", cmd->cmnd[i]);
4473 printk(" seg_cnt =%d\n", cmd->use_sg);
4474 printk(" request buffer=0x%p, request buffer len=0x%x\n",
4475 cmd->request_buffer, cmd->request_bufflen);
4478 sg = (struct scatterlist *) cmd->request_buffer;
4479 printk(" SG buffer: \n");
4480 qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
4482 printk(" tag=%d, transfersize=0x%x \n",
4483 cmd->tag, cmd->transfersize);
4484 printk(" Pid=%li, SP=0x%p\n", cmd->pid, CMD_SP(cmd));
4485 printk(" underflow size = 0x%x, direction=0x%x\n",
4486 cmd->underflow, cmd->sc_data_direction);
4489 /**************************************************************************
4490 * ql1280_dump_device
4492 **************************************************************************/
4494 ql1280_dump_device(struct scsi_qla_host *ha)
4497 struct scsi_cmnd *cp;
4501 printk(KERN_DEBUG "Outstanding Commands on controller:\n");
4503 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
4504 if ((sp = ha->outstanding_cmds[i]) == NULL)
4506 if ((cp = sp->cmd) == NULL)
4508 qla1280_print_scsi_cmd(1, cp);
4523 struct setup_tokens {
4528 static struct setup_tokens setup_token[] __initdata =
4530 { "nvram", TOKEN_NVRAM },
4531 { "sync", TOKEN_SYNC },
4532 { "wide", TOKEN_WIDE },
4533 { "ppr", TOKEN_PPR },
4534 { "verbose", TOKEN_VERBOSE },
4535 { "debug", TOKEN_DEBUG },
4539 /**************************************************************************
4542 * Handle boot parameters. This really needs to be changed so one
4543 * can specify per adapter parameters.
4544 **************************************************************************/
4546 qla1280_setup(char *s)
4554 while (cp && (ptr = strchr(cp, ':'))) {
4556 if (!strcmp(ptr, "yes")) {
4559 } else if (!strcmp(ptr, "no")) {
4563 val = simple_strtoul(ptr, &ptr, 0);
4565 switch ((toke = qla1280_get_token(cp))) {
4568 driver_setup.no_nvram = 1;
4572 driver_setup.no_sync = 1;
4573 else if (val != 0x10000)
4574 driver_setup.sync_mask = val;
4578 driver_setup.no_wide = 1;
4579 else if (val != 0x10000)
4580 driver_setup.wide_mask = val;
4584 driver_setup.no_ppr = 1;
4585 else if (val != 0x10000)
4586 driver_setup.ppr_mask = val;
4589 qla1280_verbose = val;
4592 printk(KERN_INFO "qla1280: unknown boot option %s\n",
4596 cp = strchr(ptr, ';');
4608 qla1280_get_token(char *str)
4614 len = sizeof(setup_token)/sizeof(struct setup_tokens);
4616 sep = strchr(str, ':');
4619 for (i = 0; i < len; i++){
4621 if (!strncmp(setup_token[i].token, str, (sep - str))) {
4622 ret = setup_token[i].val;
4631 #if LINUX_VERSION_CODE >= 0x020600
4632 static struct scsi_host_template qla1280_driver_template = {
4633 .proc_name = "qla1280",
4634 .name = "Qlogic ISP 1280/12160",
4635 .info = qla1280_info,
4636 .slave_configure = qla1280_slave_configure,
4637 .queuecommand = qla1280_queuecommand,
4638 .eh_abort_handler = qla1280_eh_abort,
4639 .eh_device_reset_handler= qla1280_eh_device_reset,
4640 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4641 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4642 .bios_param = qla1280_biosparam,
4643 .proc_info = qla1280_proc_info,
4644 .can_queue = 0xfffff,
4646 .sg_tablesize = SG_ALL,
4648 .use_clustering = ENABLE_CLUSTERING,
4651 static Scsi_Host_Template qla1280_driver_template = {
4652 .proc_name = "qla1280",
4653 .name = "Qlogic ISP 1280/12160",
4654 .detect = qla1280_detect,
4655 .release = qla1280_release,
4656 .info = qla1280_info,
4657 .queuecommand = qla1280_queuecommand,
4658 .eh_abort_handler = qla1280_eh_abort,
4659 .eh_device_reset_handler= qla1280_eh_device_reset,
4660 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4661 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4662 .bios_param = qla1280_biosparam_old,
4663 .proc_info = qla1280_proc_info_old,
4664 .can_queue = 0xfffff,
4666 .sg_tablesize = SG_ALL,
4668 .use_clustering = ENABLE_CLUSTERING,
4669 .use_new_eh_code = 1,
4673 static int __devinit
4674 qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4676 int devnum = id->driver_data;
4677 struct qla_boards *bdp = &ql1280_board_tbl[devnum];
4678 struct Scsi_Host *host;
4679 struct scsi_qla_host *ha;
4680 int error = -ENODEV;
4682 /* Bypass all AMI SUBSYS VENDOR IDs */
4683 if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
4685 "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
4689 printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
4690 bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
4692 if (pci_enable_device(pdev)) {
4694 "qla1280: Failed to enabled pci device, aborting.\n");
4698 pci_set_master(pdev);
4701 host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
4704 "qla1280: Failed to register host, aborting.\n");
4705 goto error_disable_device;
4708 ha = (struct scsi_qla_host *)host->hostdata;
4709 memset(ha, 0, sizeof(struct scsi_qla_host));
4712 ha->devnum = devnum; /* specifies microcode load address */
4714 #ifdef QLA_64BIT_PTR
4715 if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) {
4716 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4717 printk(KERN_WARNING "scsi(%li): Unable to set a "
4718 " suitable DMA mask - aboring\n", ha->host_no);
4720 goto error_free_irq;
4723 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4726 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4727 printk(KERN_WARNING "scsi(%li): Unable to set a "
4728 " suitable DMA mask - aboring\n", ha->host_no);
4730 goto error_free_irq;
4734 ha->request_ring = pci_alloc_consistent(ha->pdev,
4735 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4737 if (!ha->request_ring) {
4738 printk(KERN_INFO "qla1280: Failed to get request memory\n");
4739 goto error_put_host;
4742 ha->response_ring = pci_alloc_consistent(ha->pdev,
4743 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4745 if (!ha->response_ring) {
4746 printk(KERN_INFO "qla1280: Failed to get response memory\n");
4747 goto error_free_request_ring;
4750 ha->ports = bdp->numPorts;
4753 ha->host_no = host->host_no;
4755 host->irq = pdev->irq;
4756 host->max_channel = bdp->numPorts - 1;
4757 host->max_lun = MAX_LUNS - 1;
4758 host->max_id = MAX_TARGETS;
4759 host->max_sectors = 1024;
4760 host->unique_id = host->host_no;
4762 #if LINUX_VERSION_CODE < 0x020545
4763 host->select_queue_depths = qla1280_select_queue_depth;
4768 #if MEMORY_MAPPED_IO
4769 ha->mmpbase = ioremap(pci_resource_start(ha->pdev, 1),
4770 pci_resource_len(ha->pdev, 1));
4772 printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
4773 goto error_free_response_ring;
4776 host->base = (unsigned long)ha->mmpbase;
4777 ha->iobase = (struct device_reg *)ha->mmpbase;
4779 host->io_port = pci_resource_start(ha->pdev, 0);
4780 if (!request_region(host->io_port, 0xff, "qla1280")) {
4781 printk(KERN_INFO "qla1280: Failed to reserve i/o region "
4782 "0x%04lx-0x%04lx - already in use\n",
4783 host->io_port, host->io_port + 0xff);
4784 goto error_free_response_ring;
4787 ha->iobase = (struct device_reg *)host->io_port;
4790 INIT_LIST_HEAD(&ha->done_q);
4792 /* Disable ISP interrupts. */
4793 qla1280_disable_intrs(ha);
4795 if (request_irq(pdev->irq, qla1280_intr_handler, SA_SHIRQ,
4797 printk("qla1280 : Failed to reserve interrupt %d already "
4798 "in use\n", pdev->irq);
4799 goto error_release_region;
4802 /* load the F/W, read paramaters, and init the H/W */
4803 if (qla1280_initialize_adapter(ha)) {
4804 printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
4805 goto error_free_irq;
4808 /* set our host ID (need to do something about our two IDs) */
4809 host->this_id = ha->bus_settings[0].id;
4811 pci_set_drvdata(pdev, host);
4813 #if LINUX_VERSION_CODE >= 0x020600
4814 error = scsi_add_host(host, &pdev->dev);
4816 goto error_disable_adapter;
4817 scsi_scan_host(host);
4819 scsi_set_pci_device(host, pdev);
4824 #if LINUX_VERSION_CODE >= 0x020600
4825 error_disable_adapter:
4826 WRT_REG_WORD(&ha->iobase->ictrl, 0);
4829 free_irq(pdev->irq, ha);
4830 error_release_region:
4831 #if MEMORY_MAPPED_IO
4832 iounmap(ha->mmpbase);
4834 release_region(host->io_port, 0xff);
4836 error_free_response_ring:
4837 pci_free_consistent(ha->pdev,
4838 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4839 ha->response_ring, ha->response_dma);
4840 error_free_request_ring:
4841 pci_free_consistent(ha->pdev,
4842 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4843 ha->request_ring, ha->request_dma);
4845 scsi_host_put(host);
4846 error_disable_device:
4847 pci_disable_device(pdev);
4853 static void __devexit
4854 qla1280_remove_one(struct pci_dev *pdev)
4856 struct Scsi_Host *host = pci_get_drvdata(pdev);
4857 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
4859 #if LINUX_VERSION_CODE >= 0x020600
4860 scsi_remove_host(host);
4863 WRT_REG_WORD(&ha->iobase->ictrl, 0);
4865 free_irq(pdev->irq, ha);
4867 #if MEMORY_MAPPED_IO
4868 iounmap(ha->mmpbase);
4870 release_region(host->io_port, 0xff);
4873 pci_free_consistent(ha->pdev,
4874 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4875 ha->request_ring, ha->request_dma);
4876 pci_free_consistent(ha->pdev,
4877 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4878 ha->response_ring, ha->response_dma);
4880 pci_disable_device(pdev);
4882 scsi_host_put(host);
4885 #if LINUX_VERSION_CODE >= 0x020600
4886 static struct pci_driver qla1280_pci_driver = {
4888 .id_table = qla1280_pci_tbl,
4889 .probe = qla1280_probe_one,
4890 .remove = __devexit_p(qla1280_remove_one),
4896 if (sizeof(struct srb) > sizeof(struct scsi_pointer)) {
4898 "qla1280: struct srb too big, aborting\n");
4904 * If we are called as a module, the qla1280 pointer may not be null
4905 * and it would point to our bootup string, just like on the lilo
4906 * command line. IF not NULL, then process this config string with
4910 * To add options at boot time add a line to your lilo.conf file like:
4911 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
4912 * which will result in the first four devices on the first two
4913 * controllers being set to a tagged queue depth of 32.
4916 qla1280_setup(qla1280);
4919 return pci_module_init(&qla1280_pci_driver);
4925 pci_unregister_driver(&qla1280_pci_driver);
4928 module_init(qla1280_init);
4929 module_exit(qla1280_exit);
4932 # define driver_template qla1280_driver_template
4933 # include "scsi_module.c"
4936 MODULE_AUTHOR("Qlogic & Jes Sorensen");
4937 MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
4938 MODULE_LICENSE("GPL");
4941 * Overrides for Emacs so that we almost follow Linus's tabbing style.
4942 * Emacs will notice this stuff at the end of the file and automatically
4943 * adjust the settings for this buffer only. This must remain at the end
4945 * ---------------------------------------------------------------------------