1 /******************************************************************************
2 * QLOGIC LINUX SOFTWARE
4 * QLogic QLA1280 (Ultra2) and QLA12160 (Ultra3) SCSI driver
5 * Copyright (C) 2000 Qlogic Corporation (www.qlogic.com)
6 * Copyright (C) 2001-2004 Jes Sorensen, Wild Open Source Inc.
7 * Copyright (C) 2003-2004 Christoph Hellwig
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 ******************************************************************************/
20 #define QLA1280_VERSION "3.25"
21 /*****************************************************************************
23 Rev 3.25, September 28, 2004, Christoph Hellwig
24 - add support for ISP1020/1040
25 - don't include "scsi.h" anymore for 2.6.x
26 Rev 3.24.4 June 7, 2004 Christoph Hellwig
27 - restructure firmware loading, cleanup initialization code
28 - prepare support for ISP1020/1040 chips
29 Rev 3.24.3 January 19, 2004, Jes Sorensen
30 - Handle PCI DMA mask settings correctly
31 - Correct order of error handling in probe_one, free_irq should not
32 be called if request_irq failed
33 Rev 3.24.2 January 19, 2004, James Bottomley & Andrew Vasquez
34 - Big endian fixes (James)
35 - Remove bogus IOCB content on zero data transfer commands (Andrew)
36 Rev 3.24.1 January 5, 2004, Jes Sorensen
37 - Initialize completion queue to avoid OOPS on probe
38 - Handle interrupts during mailbox testing
39 Rev 3.24 November 17, 2003, Christoph Hellwig
40 - use struct list_head for completion queue
41 - avoid old Scsi_FOO typedefs
42 - cleanup 2.4 compat glue a bit
43 - use <scsi/scsi_*.h> headers on 2.6 instead of "scsi.h"
44 - make initialization for memory mapped vs port I/O more similar
45 - remove broken pci config space manipulation
47 - this is an almost perfect 2.6 scsi driver now! ;)
48 Rev 3.23.39 December 17, 2003, Jes Sorensen
49 - Delete completion queue from srb if mailbox command failed to
50 to avoid qla1280_done completeting qla1280_error_action's
52 - Reduce arguments for qla1280_done
53 Rev 3.23.38 October 18, 2003, Christoph Hellwig
54 - Convert to new-style hotplugable driver for 2.6
55 - Fix missing scsi_unregister/scsi_host_put on HBA removal
56 - Kill some more cruft
57 Rev 3.23.37 October 1, 2003, Jes Sorensen
58 - Make MMIO depend on CONFIG_X86_VISWS instead of yet another
60 - Clean up locking in probe path
61 Rev 3.23.36 October 1, 2003, Christoph Hellwig
62 - queuecommand only ever receives new commands - clear flags
63 - Reintegrate lost fixes from Linux 2.5
64 Rev 3.23.35 August 14, 2003, Jes Sorensen
66 Rev 3.23.34 July 23, 2003, Jes Sorensen
67 - Remove pointless TRUE/FALSE macros
68 - Clean up vchan handling
69 Rev 3.23.33 July 3, 2003, Jes Sorensen
70 - Don't define register access macros before define determining MMIO.
71 This just happend to work out on ia64 but not elsewhere.
72 - Don't try and read from the card while it is in reset as
73 it won't respond and causes an MCA
74 Rev 3.23.32 June 23, 2003, Jes Sorensen
75 - Basic support for boot time arguments
76 Rev 3.23.31 June 8, 2003, Jes Sorensen
77 - Reduce boot time messages
78 Rev 3.23.30 June 6, 2003, Jes Sorensen
79 - Do not enable sync/wide/ppr before it has been determined
80 that the target device actually supports it
81 - Enable DMA arbitration for multi channel controllers
82 Rev 3.23.29 June 3, 2003, Jes Sorensen
84 Rev 3.23.28 June 3, 2003, Jes Sorensen
85 - Eliminate duplicate marker commands on bus resets
86 - Handle outstanding commands appropriately on bus/device resets
87 Rev 3.23.27 May 28, 2003, Jes Sorensen
88 - Remove bogus input queue code, let the Linux SCSI layer do the work
89 - Clean up NVRAM handling, only read it once from the card
90 - Add a number of missing default nvram parameters
91 Rev 3.23.26 Beta May 28, 2003, Jes Sorensen
92 - Use completion queue for mailbox commands instead of busy wait
93 Rev 3.23.25 Beta May 27, 2003, James Bottomley
94 - Migrate to use new error handling code
95 Rev 3.23.24 Beta May 21, 2003, James Bottomley
97 - Cleanup data direction code
98 Rev 3.23.23 Beta May 12, 2003, Jes Sorensen
99 - Switch to using MMIO instead of PIO
100 Rev 3.23.22 Beta April 15, 2003, Jes Sorensen
101 - Fix PCI parity problem with 12160 during reset.
102 Rev 3.23.21 Beta April 14, 2003, Jes Sorensen
103 - Use pci_map_page()/pci_unmap_page() instead of map_single version.
104 Rev 3.23.20 Beta April 9, 2003, Jes Sorensen
105 - Remove < 2.4.x support
106 - Introduce HOST_LOCK to make the spin lock changes portable.
107 - Remove a bunch of idiotic and unnecessary typedef's
108 - Kill all leftovers of target-mode support which never worked anyway
109 Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
110 - Do qla1280_pci_config() before calling request_irq() and
112 - Use pci_dma_hi32() to handle upper word of DMA addresses instead
114 - Hand correct arguments to free_irq() in case of failure
115 Rev 3.23.18 Beta April 11, 2002, Jes Sorensen
116 - Run source through Lindent and clean up the output
117 Rev 3.23.17 Beta April 11, 2002, Jes Sorensen
118 - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32
119 Rev 3.23.16 Beta March 19, 2002, Jes Sorensen
120 - Rely on mailbox commands generating interrupts - do not
121 run qla1280_isr() from ql1280_mailbox_command()
122 - Remove device_reg_t
123 - Integrate ql12160_set_target_parameters() with 1280 version
124 - Make qla1280_setup() non static
125 - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request
126 sent to the card - this command pauses the firmare!!!
127 Rev 3.23.15 Beta March 19, 2002, Jes Sorensen
128 - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions
129 - Remove a pile of pointless and confusing (srb_t **) and
130 (scsi_lu_t *) typecasts
131 - Explicit mark that we do not use the new error handling (for now)
132 - Remove scsi_qla_host_t and use 'struct' instead
133 - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled,
134 pci_64bit_slot flags which weren't used for anything anyway
135 - Grab host->host_lock while calling qla1280_isr() from abort()
136 - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we
137 do not need to save/restore flags in the interrupt handler
138 - Enable interrupts early (before any mailbox access) in preparation
139 for cleaning up the mailbox handling
140 Rev 3.23.14 Beta March 14, 2002, Jes Sorensen
141 - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace
142 it with proper use of dprintk().
143 - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take
144 a debug level argument to determine if data is to be printed
145 - Add KERN_* info to printk()
146 Rev 3.23.13 Beta March 14, 2002, Jes Sorensen
147 - Significant cosmetic cleanups
148 - Change debug code to use dprintk() and remove #if mess
149 Rev 3.23.12 Beta March 13, 2002, Jes Sorensen
150 - More cosmetic cleanups, fix places treating return as function
151 - use cpu_relax() in qla1280_debounce_register()
152 Rev 3.23.11 Beta March 13, 2002, Jes Sorensen
153 - Make it compile under 2.5.5
154 Rev 3.23.10 Beta October 1, 2001, Jes Sorensen
155 - Do no typecast short * to long * in QL1280BoardTbl, this
156 broke miserably on big endian boxes
157 Rev 3.23.9 Beta September 30, 2001, Jes Sorensen
158 - Remove pre 2.2 hack for checking for reentrance in interrupt handler
159 - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32
160 unsigned int to match the types from struct scsi_cmnd
161 Rev 3.23.8 Beta September 29, 2001, Jes Sorensen
162 - Remove bogus timer_t typedef from qla1280.h
163 - Remove obsolete pre 2.2 PCI setup code, use proper #define's
164 for PCI_ values, call pci_set_master()
165 - Fix memleak of qla1280_buffer on module unload
166 - Only compile module parsing code #ifdef MODULE - should be
167 changed to use individual MODULE_PARM's later
168 - Remove dummy_buffer that was never modified nor printed
169 - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove
170 #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls
171 - Remove \r from print statements, this is Linux, not DOS
172 - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK}
174 - Remove C++ compile hack in header file as Linux driver are not
175 supposed to be compiled as C++
176 - Kill MS_64BITS macro as it makes the code more readable
177 - Remove unnecessary flags.in_interrupts bit
178 Rev 3.23.7 Beta August 20, 2001, Jes Sorensen
179 - Dont' check for set flags on q->q_flag one by one in qla1280_next()
180 - Check whether the interrupt was generated by the QLA1280 before
182 - qla1280_status_entry(): Only zero out part of sense_buffer that
183 is not being copied into
184 - Remove more superflouous typecasts
185 - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy()
186 Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel
187 - Don't walk the entire list in qla1280_putq_t() just to directly
188 grab the pointer to the last element afterwards
189 Rev 3.23.5 Beta August 9, 2001, Jes Sorensen
190 - Don't use SA_INTERRUPT, it's use is deprecated for this kinda driver
191 Rev 3.23.4 Beta August 8, 2001, Jes Sorensen
192 - Set dev->max_sectors to 1024
193 Rev 3.23.3 Beta August 6, 2001, Jes Sorensen
194 - Provide compat macros for pci_enable_device(), pci_find_subsys()
195 and scsi_set_pci_device()
196 - Call scsi_set_pci_device() for all devices
197 - Reduce size of kernel version dependent device probe code
198 - Move duplicate probe/init code to separate function
199 - Handle error if qla1280_mem_alloc() fails
200 - Kill OFFSET() macro and use Linux's PCI definitions instead
201 - Kill private structure defining PCI config space (struct config_reg)
202 - Only allocate I/O port region if not in MMIO mode
203 - Remove duplicate (unused) sanity check of sife of srb_t
204 Rev 3.23.2 Beta August 6, 2001, Jes Sorensen
205 - Change home-brew memset() implementations to use memset()
206 - Remove all references to COMTRACE() - accessing a PC's COM2 serial
207 port directly is not legal under Linux.
208 Rev 3.23.1 Beta April 24, 2001, Jes Sorensen
209 - Remove pre 2.2 kernel support
210 - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat)
211 - Fix MMIO access to use readl/writel instead of directly
212 dereferencing pointers
213 - Nuke MSDOS debugging code
214 - Change true/false data types to int from uint8_t
215 - Use int for counters instead of uint8_t etc.
216 - Clean up size & byte order conversion macro usage
217 Rev 3.23 Beta January 11, 2001 BN Qlogic
218 - Added check of device_id when handling non
219 QLA12160s during detect().
220 Rev 3.22 Beta January 5, 2001 BN Qlogic
221 - Changed queue_task() to schedule_task()
222 for kernels 2.4.0 and higher.
223 Note: 2.4.0-testxx kernels released prior to
224 the actual 2.4.0 kernel release on January 2001
225 will get compile/link errors with schedule_task().
226 Please update your kernel to released 2.4.0 level,
227 or comment lines in this file flagged with 3.22
228 to resolve compile/link error of schedule_task().
229 - Added -DCONFIG_SMP in addition to -D__SMP__
230 in Makefile for 2.4.0 builds of driver as module.
231 Rev 3.21 Beta January 4, 2001 BN Qlogic
232 - Changed criteria of 64/32 Bit mode of HBA
233 operation according to BITS_PER_LONG rather
234 than HBA's NVRAM setting of >4Gig memory bit;
235 so that the HBA auto-configures without the need
236 to setup each system individually.
237 Rev 3.20 Beta December 5, 2000 BN Qlogic
238 - Added priority handling to IA-64 onboard SCSI
239 ISP12160 chip for kernels greater than 2.3.18.
240 - Added irqrestore for qla1280_intr_handler.
241 - Enabled /proc/scsi/qla1280 interface.
242 - Clear /proc/scsi/qla1280 counters in detect().
243 Rev 3.19 Beta October 13, 2000 BN Qlogic
244 - Declare driver_template for new kernel
245 (2.4.0 and greater) scsi initialization scheme.
246 - Update /proc/scsi entry for 2.3.18 kernels and
248 Rev 3.18 Beta October 10, 2000 BN Qlogic
249 - Changed scan order of adapters to map
250 the QLA12160 followed by the QLA1280.
251 Rev 3.17 Beta September 18, 2000 BN Qlogic
252 - Removed warnings for 32 bit 2.4.x compiles
253 - Corrected declared size for request and response
254 DMA addresses that are kept in each ha
255 Rev. 3.16 Beta August 25, 2000 BN Qlogic
256 - Corrected 64 bit addressing issue on IA-64
257 where the upper 32 bits were not properly
258 passed to the RISC engine.
259 Rev. 3.15 Beta August 22, 2000 BN Qlogic
260 - Modified qla1280_setup_chip to properly load
261 ISP firmware for greater that 4 Gig memory on IA-64
262 Rev. 3.14 Beta August 16, 2000 BN Qlogic
263 - Added setting of dma_mask to full 64 bit
264 if flags.enable_64bit_addressing is set in NVRAM
265 Rev. 3.13 Beta August 16, 2000 BN Qlogic
266 - Use new PCI DMA mapping APIs for 2.4.x kernel
267 Rev. 3.12 July 18, 2000 Redhat & BN Qlogic
268 - Added check of pci_enable_device to detect() for 2.3.x
269 - Use pci_resource_start() instead of
270 pdev->resource[0].start in detect() for 2.3.x
271 - Updated driver version
272 Rev. 3.11 July 14, 2000 BN Qlogic
273 - Updated SCSI Firmware to following versions:
276 - Updated driver version to 3.11
277 Rev. 3.10 June 23, 2000 BN Qlogic
278 - Added filtering of AMI SubSys Vendor ID devices
280 - DEBUG_QLA1280 undefined and new version BN Qlogic
281 Rev. 3.08b May 9, 2000 MD Dell
282 - Added logic to check against AMI subsystem vendor ID
283 Rev. 3.08 May 4, 2000 DG Qlogic
284 - Added logic to check for PCI subsystem ID.
285 Rev. 3.07 Apr 24, 2000 DG & BN Qlogic
286 - Updated SCSI Firmware to following versions:
289 Rev. 3.06 Apr 12, 2000 DG & BN Qlogic
290 - Internal revision; not released
291 Rev. 3.05 Mar 28, 2000 DG & BN Qlogic
292 - Edit correction for virt_to_bus and PROC.
293 Rev. 3.04 Mar 28, 2000 DG & BN Qlogic
294 - Merge changes from ia64 port.
295 Rev. 3.03 Mar 28, 2000 BN Qlogic
296 - Increase version to reflect new code drop with compile fix
297 of issue with inclusion of linux/spinlock for 2.3 kernels
298 Rev. 3.02 Mar 15, 2000 BN Qlogic
299 - Merge qla1280_proc_info from 2.10 code base
300 Rev. 3.01 Feb 10, 2000 BN Qlogic
301 - Corrected code to compile on a 2.2.x kernel.
302 Rev. 3.00 Jan 17, 2000 DG Qlogic
303 - Added 64-bit support.
304 Rev. 2.07 Nov 9, 1999 DG Qlogic
305 - Added new routine to set target parameters for ISP12160.
306 Rev. 2.06 Sept 10, 1999 DG Qlogic
307 - Added support for ISP12160 Ultra 3 chip.
308 Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
309 - Modified code to remove errors generated when compiling with
310 Cygnus IA64 Compiler.
311 - Changed conversion of pointers to unsigned longs instead of integers.
312 - Changed type of I/O port variables from uint32_t to unsigned long.
313 - Modified OFFSET macro to work with 64-bit as well as 32-bit.
314 - Changed sprintf and printk format specifiers for pointers to %p.
315 - Changed some int to long type casts where needed in sprintf & printk.
316 - Added l modifiers to sprintf and printk format specifiers for longs.
317 - Removed unused local variables.
318 Rev. 1.20 June 8, 1999 DG, Qlogic
319 Changes to support RedHat release 6.0 (kernel 2.2.5).
320 - Added SCSI exclusive access lock (io_request_lock) when accessing
322 - Added changes for the new LINUX interface template. Some new error
323 handling routines have been added to the template, but for now we
324 will use the old ones.
325 - Initial Beta Release.
326 *****************************************************************************/
329 #include <linux/config.h>
330 #include <linux/module.h>
332 #include <linux/version.h>
333 #include <linux/types.h>
334 #include <linux/string.h>
335 #include <linux/errno.h>
336 #include <linux/kernel.h>
337 #include <linux/ioport.h>
338 #include <linux/delay.h>
339 #include <linux/timer.h>
340 #include <linux/sched.h>
341 #include <linux/pci.h>
342 #include <linux/proc_fs.h>
343 #include <linux/stat.h>
344 #include <linux/slab.h>
345 #include <linux/pci_ids.h>
346 #include <linux/interrupt.h>
347 #include <linux/init.h>
351 #include <asm/byteorder.h>
352 #include <asm/processor.h>
353 #include <asm/types.h>
354 #include <asm/system.h>
356 #if LINUX_VERSION_CODE >= 0x020545
357 #include <scsi/scsi.h>
358 #include <scsi/scsi_cmnd.h>
359 #include <scsi/scsi_device.h>
360 #include <scsi/scsi_host.h>
361 #include <scsi/scsi_tcq.h>
363 #include <linux/blk.h>
365 #include <scsi/scsi_host.h>
369 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
370 #include <asm/sn/io.h>
373 #if LINUX_VERSION_CODE < 0x020407
374 #error "Kernels older than 2.4.7 are no longer supported"
379 * Compile time Options:
380 * 0 - Disable and 1 - Enable
382 #define DEBUG_QLA1280_INTR 0
383 #define DEBUG_PRINT_NVRAM 0
384 #define DEBUG_QLA1280 0
387 * The SGI VISWS is broken and doesn't support MMIO ;-(
389 #ifdef CONFIG_X86_VISWS
390 #define MEMORY_MAPPED_IO 0
392 #define MEMORY_MAPPED_IO 1
395 #define UNIQUE_FW_NAME
397 #include "ql12160_fw.h" /* ISP RISC codes */
398 #include "ql1280_fw.h"
399 #include "ql1040_fw.h"
405 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1080
406 #define PCI_DEVICE_ID_QLOGIC_ISP1080 0x1080
408 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1240
409 #define PCI_DEVICE_ID_QLOGIC_ISP1240 0x1240
411 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1280
412 #define PCI_DEVICE_ID_QLOGIC_ISP1280 0x1280
414 #ifndef PCI_DEVICE_ID_QLOGIC_ISP10160
415 #define PCI_DEVICE_ID_QLOGIC_ISP10160 0x1016
417 #ifndef PCI_DEVICE_ID_QLOGIC_ISP12160
418 #define PCI_DEVICE_ID_QLOGIC_ISP12160 0x1216
421 #ifndef PCI_VENDOR_ID_AMI
422 #define PCI_VENDOR_ID_AMI 0x101e
425 #ifndef BITS_PER_LONG
426 #error "BITS_PER_LONG not defined!"
428 #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
429 #define QLA_64BIT_PTR 1
433 #define pci_dma_hi32(a) ((a >> 16) >> 16)
435 #define pci_dma_hi32(a) 0
437 #define pci_dma_lo32(a) (a & 0xffffffff)
439 #define NVRAM_DELAY() udelay(500) /* 2 microseconds */
441 #if LINUX_VERSION_CODE < 0x020500
442 #define HOST_LOCK &io_request_lock
443 #define irqreturn_t void
444 #define IRQ_RETVAL(foo)
445 #define MSG_ORDERED_TAG 1
447 #define DMA_BIDIRECTIONAL SCSI_DATA_UNKNOWN
448 #define DMA_TO_DEVICE SCSI_DATA_WRITE
449 #define DMA_FROM_DEVICE SCSI_DATA_READ
450 #define DMA_NONE SCSI_DATA_NONE
452 #ifndef HAVE_SECTOR_T
453 typedef unsigned int sector_t;
457 scsi_adjust_queue_depth(struct scsi_device *device, int tag, int depth)
460 device->tagged_queue = tag;
461 device->current_tag = 0;
463 device->queue_depth = depth;
465 static inline struct Scsi_Host *scsi_host_alloc(Scsi_Host_Template *t, size_t s)
467 return scsi_register(t, s);
469 static inline void scsi_host_put(struct Scsi_Host *h)
474 #define HOST_LOCK ha->host->host_lock
476 #if LINUX_VERSION_CODE < 0x020600
477 #define DEV_SIMPLE_TAGS(device) device->tagged_queue
479 * Hack around that qla1280_remove_one is called from
480 * qla1280_release in 2.4
485 #define DEV_SIMPLE_TAGS(device) device->simple_tags
487 #if defined(__ia64__) && !defined(ia64_platform_is)
488 #define ia64_platform_is(foo) (!strcmp(x, platform_name))
492 #define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
493 #define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
494 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
495 #define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
496 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
499 static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *);
500 static void qla1280_remove_one(struct pci_dev *);
503 * QLogic Driver Support Function Prototypes.
505 static void qla1280_done(struct scsi_qla_host *);
506 #if LINUX_VERSION_CODE < 0x020545
507 static void qla1280_get_target_options(struct scsi_cmnd *, struct scsi_qla_host *);
509 static int qla1280_get_token(char *);
510 static int qla1280_setup(char *s) __init;
513 * QLogic ISP1280 Hardware Support Function Prototypes.
515 static int qla1280_load_firmware(struct scsi_qla_host *);
516 static int qla1280_init_rings(struct scsi_qla_host *);
517 static int qla1280_nvram_config(struct scsi_qla_host *);
518 static int qla1280_mailbox_command(struct scsi_qla_host *,
519 uint8_t, uint16_t *);
520 static int qla1280_bus_reset(struct scsi_qla_host *, int);
521 static int qla1280_device_reset(struct scsi_qla_host *, int, int);
522 static int qla1280_abort_device(struct scsi_qla_host *, int, int, int);
523 static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int);
524 static int qla1280_abort_isp(struct scsi_qla_host *);
526 static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *);
528 static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *);
530 static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
531 static void qla1280_poll(struct scsi_qla_host *);
532 static void qla1280_reset_adapter(struct scsi_qla_host *);
533 static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
534 static void qla1280_isp_cmd(struct scsi_qla_host *);
535 static void qla1280_isr(struct scsi_qla_host *, struct list_head *);
536 static void qla1280_rst_aen(struct scsi_qla_host *);
537 static void qla1280_status_entry(struct scsi_qla_host *, struct response *,
539 static void qla1280_error_entry(struct scsi_qla_host *, struct response *,
541 static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
542 static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
543 static uint16_t qla1280_debounce_register(volatile uint16_t __iomem *);
544 static request_t *qla1280_req_pkt(struct scsi_qla_host *);
545 static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
547 static void qla1280_get_target_parameters(struct scsi_qla_host *,
548 struct scsi_device *);
549 static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int);
552 static struct qla_driver_setup driver_setup;
555 * convert scsi data direction to request_t control flags
557 static inline uint16_t
558 qla1280_data_direction(struct scsi_cmnd *cmnd)
560 switch(cmnd->sc_data_direction) {
561 case DMA_FROM_DEVICE:
565 case DMA_BIDIRECTIONAL:
566 return BIT_5 | BIT_6;
568 * We could BUG() on default here if one of the four cases aren't
569 * met, but then again if we receive something like that from the
570 * SCSI layer we have more serious problems. This shuts up GCC.
579 static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd);
580 static void __qla1280_dump_buffer(char *, int);
585 * insmod needs to find the variable and make it point to something
588 static char *qla1280;
590 /* insmod qla1280 options=verbose" */
591 module_param(qla1280, charp, 0);
593 __setup("qla1280=", qla1280_setup);
598 * We use the scsi_pointer structure that's included with each scsi_command
599 * to overlay our struct srb over it. qla1280_init() checks that a srb is not
600 * bigger than a scsi_pointer.
603 #define CMD_SP(Cmnd) &Cmnd->SCp
604 #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
605 #define CMD_CDBP(Cmnd) Cmnd->cmnd
606 #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
607 #define CMD_SNSLEN(Cmnd) sizeof(Cmnd->sense_buffer)
608 #define CMD_RESULT(Cmnd) Cmnd->result
609 #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
610 #if LINUX_VERSION_CODE < 0x020545
611 #define CMD_REQUEST(Cmnd) Cmnd->request.cmd
613 #define CMD_REQUEST(Cmnd) Cmnd->request->cmd
616 #define CMD_HOST(Cmnd) Cmnd->device->host
617 #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
618 #define SCSI_TCN_32(Cmnd) Cmnd->device->id
619 #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
622 /*****************************************/
623 /* ISP Boards supported by this driver */
624 /*****************************************/
627 unsigned char name[9]; /* Board ID String */
628 int numPorts; /* Number of SCSI ports */
629 unsigned short *fwcode; /* pointer to FW array */
630 unsigned short *fwlen; /* number of words in array */
631 unsigned short *fwstart; /* start address for F/W */
632 unsigned char *fwver; /* Ptr to F/W version array */
635 /* NOTE: the last argument in each entry is used to index ql1280_board_tbl */
636 static struct pci_device_id qla1280_pci_tbl[] = {
637 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP12160,
638 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
639 #ifdef CONFIG_SCSI_QLOGIC_1280_1040
640 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1020,
641 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
643 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1080,
644 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
645 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1240,
646 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
647 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1280,
648 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
649 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP10160,
650 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
653 MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl);
655 static struct qla_boards ql1280_board_tbl[] = {
656 /* Name , Number of ports, FW details */
657 {"QLA12160", 2, &fw12160i_code01[0], &fw12160i_length01,
658 &fw12160i_addr01, &fw12160i_version_str[0]},
659 {"QLA1040", 1, &risc_code01[0], &risc_code_length01,
660 &risc_code_addr01, &firmware_version[0]},
661 {"QLA1080", 1, &fw1280ei_code01[0], &fw1280ei_length01,
662 &fw1280ei_addr01, &fw1280ei_version_str[0]},
663 {"QLA1240", 2, &fw1280ei_code01[0], &fw1280ei_length01,
664 &fw1280ei_addr01, &fw1280ei_version_str[0]},
665 {"QLA1280", 2, &fw1280ei_code01[0], &fw1280ei_length01,
666 &fw1280ei_addr01, &fw1280ei_version_str[0]},
667 {"QLA10160", 1, &fw12160i_code01[0], &fw12160i_length01,
668 &fw12160i_addr01, &fw12160i_version_str[0]},
672 static int qla1280_verbose = 1;
673 static int qla1280_buffer_size;
674 static char *qla1280_buffer;
677 static int ql_debug_level = 1;
678 #define dprintk(level, format, a...) \
679 do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
680 #define qla1280_dump_buffer(level, buf, size) \
681 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
682 #define qla1280_print_scsi_cmd(level, cmd) \
683 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
685 #define ql_debug_level 0
686 #define dprintk(level, format, a...) do{}while(0)
687 #define qla1280_dump_buffer(a, b, c) do{}while(0)
688 #define qla1280_print_scsi_cmd(a, b) do{}while(0)
691 #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
692 #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
693 #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
694 #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
697 /*************************************************************************
701 * Return information to handle /proc support for the driver.
703 * buffer - ptrs to a page buffer
706 *************************************************************************/
707 #define PROC_BUF &qla1280_buffer[len]
709 static int qla1280_proc_info(struct Scsi_Host *host, char *buffer,
710 char **start, off_t offset, int length, int inout)
712 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
713 struct qla_boards *bdp = &ql1280_board_tbl[ha->devnum];
721 * if our old buffer is the right size use it otherwise
722 * allocate a new one.
724 if (qla1280_buffer_size != PAGE_SIZE) {
725 /* deallocate this buffer and get a new one */
726 if (qla1280_buffer != NULL) {
727 free_page((unsigned long)qla1280_buffer);
728 qla1280_buffer_size = 0;
730 qla1280_buffer = (char *)get_zeroed_page(GFP_KERNEL);
732 if (qla1280_buffer == NULL) {
733 size = sprintf(buffer, "qla1280 - kmalloc error at line %d\n",
737 /* save the size of our buffer */
738 qla1280_buffer_size = PAGE_SIZE;
740 /* 3.20 clear the buffer we use for proc display */
741 memset(qla1280_buffer, 0, PAGE_SIZE);
743 /* start building the print buffer */
744 size = sprintf(PROC_BUF,
745 "QLogic PCI to SCSI Adapter for ISP 1280/12160:\n"
746 " Firmware version: %2d.%02d.%02d, Driver version %s\n",
747 bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
752 size = sprintf(PROC_BUF, "SCSI Host Adapter Information: %s\n",
755 size = sprintf(PROC_BUF, "Request Queue count= 0x%x, Response "
756 "Queue count= 0x%x\n",
757 REQUEST_ENTRY_CNT, RESPONSE_ENTRY_CNT);
759 size = sprintf(PROC_BUF, "Number of pending commands = 0x%lx\n",
762 size = sprintf(PROC_BUF, "Number of free request entries = %d\n",
765 size = sprintf(PROC_BUF, "\n"); /* 1 */
768 if (len >= qla1280_buffer_size) {
770 "qla1280: Overflow buffer in qla1280_proc.c\n");
773 if (offset > len - 1) {
774 free_page((unsigned long) qla1280_buffer);
775 qla1280_buffer = NULL;
776 qla1280_buffer_size = length = 0;
779 *start = &qla1280_buffer[offset]; /* Start of wanted data */
780 if (len - offset < length) {
781 length = len - offset;
788 static int qla1280_read_nvram(struct scsi_qla_host *ha)
795 ENTER("qla1280_read_nvram");
797 if (driver_setup.no_nvram)
800 printk(KERN_INFO "scsi(%ld): Reading NVRAM\n", ha->host_no);
802 wptr = (uint16_t *)&ha->nvram;
805 for (cnt = 0; cnt < 3; cnt++) {
806 *wptr = qla1280_get_nvram_word(ha, cnt);
807 chksum += *wptr & 0xff;
808 chksum += (*wptr >> 8) & 0xff;
812 if (nv->id0 != 'I' || nv->id1 != 'S' ||
813 nv->id2 != 'P' || nv->id3 != ' ' || nv->version < 1) {
814 dprintk(2, "Invalid nvram ID or version!\n");
817 for (; cnt < sizeof(struct nvram); cnt++) {
818 *wptr = qla1280_get_nvram_word(ha, cnt);
819 chksum += *wptr & 0xff;
820 chksum += (*wptr >> 8) & 0xff;
825 dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
826 " version %i\n", nv->id0, nv->id1, nv->id2, nv->id3,
831 if (!driver_setup.no_nvram)
832 printk(KERN_WARNING "scsi(%ld): Unable to identify or "
833 "validate NVRAM checksum, using default "
834 "settings\n", ha->host_no);
839 /* The firmware interface is, um, interesting, in that the
840 * actual firmware image on the chip is little endian, thus,
841 * the process of taking that image to the CPU would end up
842 * little endian. However, the firmare interface requires it
843 * to be read a word (two bytes) at a time.
845 * The net result of this would be that the word (and
846 * doubleword) quantites in the firmware would be correct, but
847 * the bytes would be pairwise reversed. Since most of the
848 * firmware quantites are, in fact, bytes, we do an extra
849 * le16_to_cpu() in the firmware read routine.
851 * The upshot of all this is that the bytes in the firmware
852 * are in the correct places, but the 16 and 32 bit quantites
853 * are still in little endian format. We fix that up below by
854 * doing extra reverses on them */
855 nv->isp_parameter = cpu_to_le16(nv->isp_parameter);
856 nv->firmware_feature.w = cpu_to_le16(nv->firmware_feature.w);
857 for(i = 0; i < MAX_BUSES; i++) {
858 nv->bus[i].selection_timeout = cpu_to_le16(nv->bus[i].selection_timeout);
859 nv->bus[i].max_queue_depth = cpu_to_le16(nv->bus[i].max_queue_depth);
861 dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
862 LEAVE("qla1280_read_nvram");
867 /**************************************************************************
869 * Return a string describing the driver.
870 **************************************************************************/
872 qla1280_info(struct Scsi_Host *host)
874 static char qla1280_scsi_name_buffer[125];
876 struct scsi_qla_host *ha;
877 struct qla_boards *bdp;
879 bp = &qla1280_scsi_name_buffer[0];
880 ha = (struct scsi_qla_host *)host->hostdata;
881 bdp = &ql1280_board_tbl[ha->devnum];
882 memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
885 "QLogic %s PCI to SCSI Host Adapter\n"
886 " Firmware version: %2d.%02d.%02d, Driver version %s",
887 &bdp->name[0], bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
892 /**************************************************************************
893 * qla1200_queuecommand
894 * Queue a command to the controller.
897 * The mid-level driver tries to ensures that queuecommand never gets invoked
898 * concurrently with itself or the interrupt handler (although the
899 * interrupt handler may call this routine as part of request-completion
900 * handling). Unfortunely, it sometimes calls the scheduler in interrupt
901 * context which is a big NO! NO!.
902 **************************************************************************/
904 qla1280_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
906 struct Scsi_Host *host = cmd->device->host;
907 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
908 struct srb *sp = (struct srb *)&cmd->SCp;
915 qla1280_print_scsi_cmd(5, cmd);
919 * Using 64 bit commands if the PCI bridge doesn't support it is a
920 * bit wasteful, however this should really only happen if one's
921 * PCI controller is completely broken, like the BCM1250. For
922 * sane hardware this is not an issue.
924 status = qla1280_64bit_start_scsi(ha, sp);
926 status = qla1280_32bit_start_scsi(ha, sp);
940 /* timer action for error action processor */
941 static void qla1280_error_wait_timeout(unsigned long __data)
943 struct scsi_cmnd *cmd = (struct scsi_cmnd *)__data;
944 struct srb *sp = (struct srb *)CMD_SP(cmd);
949 static void qla1280_mailbox_timeout(unsigned long __data)
951 struct scsi_qla_host *ha = (struct scsi_qla_host *)__data;
952 struct device_reg __iomem *reg;
955 ha->mailbox_out[0] = RD_REG_WORD(®->mailbox0);
956 printk(KERN_ERR "scsi(%ld): mailbox timed out, mailbox0 %04x, "
957 "ictrl %04x, istatus %04x\n", ha->host_no, ha->mailbox_out[0],
958 RD_REG_WORD(®->ictrl), RD_REG_WORD(®->istatus));
959 complete(ha->mailbox_wait);
962 /**************************************************************************
963 * qla1200_error_action
964 * The function will attempt to perform a specified error action and
965 * wait for the results (or time out).
968 * cmd = Linux SCSI command packet of the command that cause the
970 * action = error action to take (see action_t)
976 * Resetting the bus always succeeds - is has to, otherwise the
977 * kernel will panic! Try a surgical technique - sending a BUS
978 * DEVICE RESET message - on the offending target before pulling
979 * the SCSI bus reset line.
980 **************************************************************************/
982 qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
984 struct scsi_qla_host *ha;
985 int bus, target, lun;
988 unsigned char *handle;
990 DECLARE_COMPLETION(wait);
991 struct timer_list timer;
993 ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
995 dprintk(4, "error_action %i, istatus 0x%04x\n", action,
996 RD_REG_WORD(&ha->iobase->istatus));
998 dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
999 RD_REG_WORD(&ha->iobase->host_cmd),
1000 RD_REG_WORD(&ha->iobase->ictrl), jiffies);
1002 ENTER("qla1280_error_action");
1003 if (qla1280_verbose)
1004 printk(KERN_INFO "scsi(%li): Resetting Cmnd=0x%p, "
1005 "Handle=0x%p, action=0x%x\n",
1006 ha->host_no, cmd, CMD_HANDLE(cmd), action);
1009 printk(KERN_WARNING "(scsi?:?:?:?) Reset called with NULL "
1010 "si_Cmnd pointer, failing.\n");
1011 LEAVE("qla1280_error_action");
1015 ha = (struct scsi_qla_host *)cmd->device->host->hostdata;
1016 sp = (struct srb *)CMD_SP(cmd);
1017 handle = CMD_HANDLE(cmd);
1019 /* Check for pending interrupts. */
1020 data = qla1280_debounce_register(&ha->iobase->istatus);
1022 * The io_request_lock is held when the reset handler is called, hence
1023 * the interrupt handler cannot be running in parallel as it also
1024 * grabs the lock. /Jes
1026 if (data & RISC_INT)
1027 qla1280_isr(ha, &ha->done_q);
1030 * Determine the suggested action that the mid-level driver wants
1033 if (handle == (unsigned char *)INVALID_HANDLE || handle == NULL) {
1034 if(action == ABORT_COMMAND) {
1035 /* we never got this command */
1036 printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
1037 return SUCCESS; /* no action - we don't have command */
1043 bus = SCSI_BUS_32(cmd);
1044 target = SCSI_TCN_32(cmd);
1045 lun = SCSI_LUN_32(cmd);
1047 /* Overloading result. Here it means the success or fail of the
1048 * *issue* of the action. When we return from the routine, it must
1049 * mean the actual success or fail of the action */
1056 if ((sp->flags & SRB_ABORT_PENDING)) {
1058 "scsi(): Command has a pending abort "
1059 "message - ABORT_PENDING.\n");
1060 /* This should technically be impossible since we
1061 * now wait for abort completion */
1065 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
1066 if (sp == ha->outstanding_cmds[i]) {
1067 dprintk(1, "qla1280: RISC aborting command\n");
1068 if (qla1280_abort_command(ha, sp, i) == 0)
1072 * Since we don't know what might
1073 * have happend to the command, it
1074 * is unsafe to remove it from the
1075 * device's queue at this point.
1076 * Wait and let the escalation
1077 * process take care of it.
1080 "scsi(%li:%i:%i:%i): Unable"
1081 " to abort command!\n",
1082 ha->host_no, bus, target, lun);
1089 ha->flags.in_reset = 1;
1090 if (qla1280_verbose)
1092 "scsi(%ld:%d:%d:%d): Queueing abort device "
1093 "command.\n", ha->host_no, bus, target, lun);
1094 if (qla1280_abort_device(ha, bus, target, lun) == 0)
1099 if (qla1280_verbose)
1101 "scsi(%ld:%d:%d:%d): Queueing device reset "
1102 "command.\n", ha->host_no, bus, target, lun);
1103 ha->flags.in_reset = 1;
1104 if (qla1280_device_reset(ha, bus, target) == 0)
1109 if (qla1280_verbose)
1110 printk(KERN_INFO "qla1280(%ld:%d): Issuing BUS "
1111 "DEVICE RESET\n", ha->host_no, bus);
1112 ha->flags.in_reset = 1;
1113 if (qla1280_bus_reset(ha, bus == 0))
1120 if (qla1280_verbose) {
1122 "scsi(%ld): Issued ADAPTER RESET\n",
1124 printk(KERN_INFO "scsi(%ld): I/O processing will "
1125 "continue automatically\n", ha->host_no);
1127 ha->flags.reset_active = 1;
1129 * We restarted all of the commands automatically, so the
1130 * mid-level code can expect completions momentitarily.
1132 if (qla1280_abort_isp(ha) == 0)
1135 ha->flags.reset_active = 0;
1138 if (!list_empty(&ha->done_q))
1140 ha->flags.in_reset = 0;
1142 /* If we didn't manage to issue the action, or we have no
1143 * command to wait for, exit here */
1144 if (result == FAILED || handle == NULL ||
1145 handle == (unsigned char *)INVALID_HANDLE) {
1147 * Clear completion queue to avoid qla1280_done() trying
1148 * to complete the command at a later stage after we
1149 * have exited the current context
1155 /* set up a timer just in case we're really jammed */
1157 timer.expires = jiffies + 4*HZ;
1158 timer.data = (unsigned long)cmd;
1159 timer.function = qla1280_error_wait_timeout;
1162 /* wait for the action to complete (or the timer to expire) */
1163 spin_unlock_irq(HOST_LOCK);
1164 wait_for_completion(&wait);
1165 del_timer_sync(&timer);
1166 spin_lock_irq(HOST_LOCK);
1169 /* the only action we might get a fail for is abort */
1170 if (action == ABORT_COMMAND) {
1171 if(sp->flags & SRB_ABORTED)
1178 dprintk(1, "RESET returning %d\n", result);
1180 LEAVE("qla1280_error_action");
1184 /**************************************************************************
1186 * Abort the specified SCSI command(s).
1187 **************************************************************************/
1189 qla1280_eh_abort(struct scsi_cmnd * cmd)
1191 return qla1280_error_action(cmd, ABORT_COMMAND);
1194 /**************************************************************************
1195 * qla1280_device_reset
1196 * Reset the specified SCSI device
1197 **************************************************************************/
1199 qla1280_eh_device_reset(struct scsi_cmnd *cmd)
1201 return qla1280_error_action(cmd, DEVICE_RESET);
1204 /**************************************************************************
1206 * Reset the specified bus.
1207 **************************************************************************/
1209 qla1280_eh_bus_reset(struct scsi_cmnd *cmd)
1211 return qla1280_error_action(cmd, BUS_RESET);
1214 /**************************************************************************
1215 * qla1280_adapter_reset
1216 * Reset the specified adapter (both channels)
1217 **************************************************************************/
1219 qla1280_eh_adapter_reset(struct scsi_cmnd *cmd)
1221 return qla1280_error_action(cmd, ADAPTER_RESET);
1225 qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1226 sector_t capacity, int geom[])
1228 int heads, sectors, cylinders;
1232 cylinders = (unsigned long)capacity / (heads * sectors);
1233 if (cylinders > 1024) {
1236 cylinders = (unsigned long)capacity / (heads * sectors);
1237 /* if (cylinders > 1023)
1238 cylinders = 1023; */
1243 geom[2] = cylinders;
1248 #if LINUX_VERSION_CODE < 0x020600
1250 qla1280_detect(Scsi_Host_Template *template)
1252 struct pci_device_id *id = &qla1280_pci_tbl[0];
1253 struct pci_dev *pdev = NULL;
1256 if (sizeof(struct srb) > sizeof(Scsi_Pointer)) {
1258 "qla1280: struct srb too big, aborting\n");
1262 if ((DMA_BIDIRECTIONAL != PCI_DMA_BIDIRECTIONAL) ||
1263 (DMA_TO_DEVICE != PCI_DMA_TODEVICE) ||
1264 (DMA_FROM_DEVICE != PCI_DMA_FROMDEVICE) ||
1265 (DMA_NONE != PCI_DMA_NONE)) {
1267 "qla1280: dma direction bits don't match\n");
1273 * If we are called as a module, the qla1280 pointer may not be null
1274 * and it would point to our bootup string, just like on the lilo
1275 * command line. IF not NULL, then process this config string with
1279 * To add options at boot time add a line to your lilo.conf file like:
1280 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
1281 * which will result in the first four devices on the first two
1282 * controllers being set to a tagged queue depth of 32.
1285 qla1280_setup(qla1280);
1288 /* First Initialize QLA12160 on PCI Bus 1 Dev 2 */
1289 while ((pdev = pci_find_device(id->vendor, id->device, pdev))) {
1290 if (pdev->bus->number == 1 && PCI_SLOT(pdev->devfn) == 2) {
1291 if (!qla1280_probe_one(pdev, id))
1297 /* Try and find each different type of adapter we support */
1298 for (id = &qla1280_pci_tbl[0]; id->device; id++) {
1299 while ((pdev = pci_find_device(id->vendor, id->device, pdev))) {
1301 * skip QLA12160 already initialized on
1302 * PCI Bus 1 Dev 2 since we already initialized
1305 if (id->device == PCI_DEVICE_ID_QLOGIC_ISP12160 &&
1306 pdev->bus->number == 1 &&
1307 PCI_SLOT(pdev->devfn) == 2)
1310 if (!qla1280_probe_one(pdev, id))
1319 * This looks a bit ugly as we could just pass down host to
1320 * qla1280_remove_one, but I want to keep qla1280_release purely a wrapper
1321 * around pci_driver::remove as used from 2.6 onwards.
1324 qla1280_release(struct Scsi_Host *host)
1326 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
1328 qla1280_remove_one(ha->pdev);
1333 qla1280_biosparam_old(Disk * disk, kdev_t dev, int geom[])
1335 return qla1280_biosparam(disk->device, NULL, disk->capacity, geom);
1339 qla1280_proc_info_old(char *buffer, char **start, off_t offset, int length,
1340 int hostno, int inout)
1342 struct Scsi_Host *host;
1344 for (host = scsi_hostlist; host; host = host->next) {
1345 if (host->host_no == hostno) {
1346 return qla1280_proc_info(host, buffer, start,
1347 offset, length, inout);
1355 /**************************************************************************
1356 * qla1280_intr_handler
1357 * Handles the H/W interrupt
1358 **************************************************************************/
1360 qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1362 struct scsi_qla_host *ha;
1363 struct device_reg __iomem *reg;
1367 ENTER_INTR ("qla1280_intr_handler");
1368 ha = (struct scsi_qla_host *)dev_id;
1370 spin_lock(HOST_LOCK);
1375 WRT_REG_WORD(®->ictrl, 0); /* disable our interrupt. */
1377 data = qla1280_debounce_register(®->istatus);
1378 /* Check for pending interrupts. */
1379 if (data & RISC_INT) {
1380 qla1280_isr(ha, &ha->done_q);
1383 if (!list_empty(&ha->done_q))
1386 spin_unlock(HOST_LOCK);
1388 /* enable our interrupt. */
1389 WRT_REG_WORD(®->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1391 LEAVE_INTR("qla1280_intr_handler");
1392 return IRQ_RETVAL(handled);
1397 qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
1400 uint16_t mb[MAILBOX_REGISTER_COUNT];
1406 mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
1408 /* Set Target Parameters. */
1409 mb[0] = MBC_SET_TARGET_PARAMETERS;
1410 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
1413 mb[2] = (nv->bus[bus].target[target].parameter.c << 8);
1415 if (IS_ISP1x160(ha)) {
1416 mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
1417 mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8) |
1418 nv->bus[bus].target[target].sync_period;
1419 mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) |
1420 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
1423 mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8) |
1424 nv->bus[bus].target[target].sync_period;
1427 status = qla1280_mailbox_command(ha, mr, &mb[0]);
1430 printk(KERN_WARNING "scsi(%ld:%i:%i): "
1431 "qla1280_set_target_parameters() failed\n",
1432 ha->host_no, bus, target);
1437 /**************************************************************************
1438 * qla1280_slave_configure
1441 * Determines the queue depth for a given device. There are two ways
1442 * a queue depth can be obtained for a tagged queueing device. One
1443 * way is the default queue depth which is determined by whether
1444 * If it is defined, then it is used
1445 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1446 * default queue depth (dependent on the number of hardware SCBs).
1447 **************************************************************************/
1449 qla1280_slave_configure(struct scsi_device *device)
1451 struct scsi_qla_host *ha;
1452 int default_depth = 3;
1453 int bus = device->channel;
1454 int target = device->id;
1457 unsigned long flags;
1459 ha = (struct scsi_qla_host *)device->host->hostdata;
1462 if (qla1280_check_for_dead_scsi_bus(ha, bus))
1465 if (device->tagged_supported &&
1466 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1467 scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
1468 ha->bus_settings[bus].hiwat);
1470 scsi_adjust_queue_depth(device, 0, default_depth);
1473 #if LINUX_VERSION_CODE > 0x020500
1474 nv->bus[bus].target[target].parameter.f.enable_sync = device->sdtr;
1475 nv->bus[bus].target[target].parameter.f.enable_wide = device->wdtr;
1476 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
1479 if (driver_setup.no_sync ||
1480 (driver_setup.sync_mask &&
1481 (~driver_setup.sync_mask & (1 << target))))
1482 nv->bus[bus].target[target].parameter.f.enable_sync = 0;
1483 if (driver_setup.no_wide ||
1484 (driver_setup.wide_mask &&
1485 (~driver_setup.wide_mask & (1 << target))))
1486 nv->bus[bus].target[target].parameter.f.enable_wide = 0;
1487 if (IS_ISP1x160(ha)) {
1488 if (driver_setup.no_ppr ||
1489 (driver_setup.ppr_mask &&
1490 (~driver_setup.ppr_mask & (1 << target))))
1491 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
1494 spin_lock_irqsave(HOST_LOCK, flags);
1495 if (nv->bus[bus].target[target].parameter.f.enable_sync)
1496 status = qla1280_set_target_parameters(ha, bus, target);
1497 qla1280_get_target_parameters(ha, device);
1498 spin_unlock_irqrestore(HOST_LOCK, flags);
1502 #if LINUX_VERSION_CODE < 0x020545
1503 /**************************************************************************
1504 * qla1280_select_queue_depth
1506 * Sets the queue depth for each SCSI device hanging off the input
1507 * host adapter. We use a queue depth of 2 for devices that do not
1508 * support tagged queueing.
1509 **************************************************************************/
1511 qla1280_select_queue_depth(struct Scsi_Host *host, struct scsi_device *sdev_q)
1513 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
1514 struct scsi_device *sdev;
1516 ENTER("qla1280_select_queue_depth");
1517 for (sdev = sdev_q; sdev; sdev = sdev->next)
1518 if (sdev->host == host)
1519 qla1280_slave_configure(sdev);
1522 qla1280_check_for_dead_scsi_bus(ha, sdev_q->channel);
1523 LEAVE("qla1280_select_queue_depth");
1529 * Process completed commands.
1532 * ha = adapter block pointer.
1533 * done_q = done queue.
1536 qla1280_done(struct scsi_qla_host *ha)
1539 struct list_head *done_q;
1540 int bus, target, lun;
1541 struct scsi_cmnd *cmd;
1543 ENTER("qla1280_done");
1545 done_q = &ha->done_q;
1547 while (!list_empty(done_q)) {
1548 sp = list_entry(done_q->next, struct srb, list);
1550 list_del(&sp->list);
1553 bus = SCSI_BUS_32(cmd);
1554 target = SCSI_TCN_32(cmd);
1555 lun = SCSI_LUN_32(cmd);
1557 switch ((CMD_RESULT(cmd) >> 16)) {
1559 /* Issue marker command. */
1560 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
1563 sp->flags &= ~SRB_ABORT_PENDING;
1564 sp->flags |= SRB_ABORTED;
1565 if (sp->flags & SRB_TIMEOUT)
1566 CMD_RESULT(sp->cmd) = DID_TIME_OUT << 16;
1572 /* Release memory used for this I/O */
1574 dprintk(3, "S/G unmap_sg cmd=%p\n", cmd);
1576 pci_unmap_sg(ha->pdev, cmd->request_buffer,
1577 cmd->use_sg, cmd->sc_data_direction);
1578 } else if (cmd->request_bufflen) {
1579 /*dprintk(1, "No S/G unmap_single cmd=%x saved_dma_handle=%lx\n",
1580 cmd, sp->saved_dma_handle); */
1582 pci_unmap_page(ha->pdev, sp->saved_dma_handle,
1583 cmd->request_bufflen, cmd->sc_data_direction);
1586 /* Call the mid-level driver interrupt handler */
1587 CMD_HANDLE(sp->cmd) = (unsigned char *)INVALID_HANDLE;
1590 #if LINUX_VERSION_CODE < 0x020500
1591 if (cmd->cmnd[0] == INQUIRY)
1592 qla1280_get_target_options(cmd, ha);
1594 (*(cmd)->scsi_done)(cmd);
1596 if(sp->wait != NULL)
1599 LEAVE("qla1280_done");
1603 * Translates a ISP error to a Linux SCSI error
1606 qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1608 int host_status = DID_ERROR;
1609 uint16_t comp_status = le16_to_cpu(sts->comp_status);
1610 uint16_t state_flags = le16_to_cpu(sts->state_flags);
1611 uint16_t residual_length = le16_to_cpu(sts->residual_length);
1612 uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
1613 #if DEBUG_QLA1280_INTR
1614 static char *reason[] = {
1626 #endif /* DEBUG_QLA1280_INTR */
1628 ENTER("qla1280_return_status");
1630 #if DEBUG_QLA1280_INTR
1632 dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
1637 switch (comp_status) {
1639 host_status = DID_OK;
1643 if (!(state_flags & SF_GOT_BUS))
1644 host_status = DID_NO_CONNECT;
1645 else if (!(state_flags & SF_GOT_TARGET))
1646 host_status = DID_BAD_TARGET;
1647 else if (!(state_flags & SF_SENT_CDB))
1648 host_status = DID_ERROR;
1649 else if (!(state_flags & SF_TRANSFERRED_DATA))
1650 host_status = DID_ERROR;
1651 else if (!(state_flags & SF_GOT_STATUS))
1652 host_status = DID_ERROR;
1653 else if (!(state_flags & SF_GOT_SENSE))
1654 host_status = DID_ERROR;
1658 host_status = DID_RESET;
1662 host_status = DID_ABORT;
1666 host_status = DID_TIME_OUT;
1669 case CS_DATA_OVERRUN:
1670 dprintk(2, "Data overrun 0x%x\n", residual_length);
1671 dprintk(2, "qla1280_isr: response packet data\n");
1672 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
1673 host_status = DID_ERROR;
1676 case CS_DATA_UNDERRUN:
1677 if ((cp->request_bufflen - residual_length) <
1680 "scsi: Underflow detected - retrying "
1682 host_status = DID_ERROR;
1684 host_status = DID_OK;
1688 host_status = DID_ERROR;
1692 #if DEBUG_QLA1280_INTR
1693 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
1694 reason[host_status], scsi_status);
1697 LEAVE("qla1280_return_status");
1699 return (scsi_status & 0xff) | (host_status << 16);
1702 /****************************************************************************/
1703 /* QLogic ISP1280 Hardware Support Functions. */
1704 /****************************************************************************/
1707 * qla2100_enable_intrs
1708 * qla2100_disable_intrs
1711 * ha = adapter block pointer.
1717 qla1280_enable_intrs(struct scsi_qla_host *ha)
1719 struct device_reg __iomem *reg;
1722 /* enable risc and host interrupts */
1723 WRT_REG_WORD(®->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1724 RD_REG_WORD(®->ictrl); /* PCI Posted Write flush */
1725 ha->flags.ints_enabled = 1;
1729 qla1280_disable_intrs(struct scsi_qla_host *ha)
1731 struct device_reg __iomem *reg;
1734 /* disable risc and host interrupts */
1735 WRT_REG_WORD(®->ictrl, 0);
1736 RD_REG_WORD(®->ictrl); /* PCI Posted Write flush */
1737 ha->flags.ints_enabled = 0;
1741 * qla1280_initialize_adapter
1745 * ha = adapter block pointer.
1750 static int __devinit
1751 qla1280_initialize_adapter(struct scsi_qla_host *ha)
1753 struct device_reg __iomem *reg;
1756 #if LINUX_VERSION_CODE > 0x020500
1757 unsigned long flags;
1760 ENTER("qla1280_initialize_adapter");
1762 /* Clear adapter flags. */
1763 ha->flags.online = 0;
1764 ha->flags.disable_host_adapter = 0;
1765 ha->flags.reset_active = 0;
1766 ha->flags.abort_isp_active = 0;
1768 ha->flags.ints_enabled = 0;
1769 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1770 if (ia64_platform_is("sn2")) {
1771 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
1772 "dual channel lockup workaround\n", ha->host_no);
1773 ha->flags.use_pci_vchannel = 1;
1774 driver_setup.no_nvram = 1;
1778 /* TODO: implement support for the 1040 nvram format */
1780 driver_setup.no_nvram = 1;
1782 dprintk(1, "Configure PCI space for adapter...\n");
1786 /* Insure mailbox registers are free. */
1787 WRT_REG_WORD(®->semaphore, 0);
1788 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
1789 WRT_REG_WORD(®->host_cmd, HC_CLR_HOST_INT);
1790 RD_REG_WORD(®->host_cmd);
1792 if (qla1280_read_nvram(ha)) {
1793 dprintk(2, "qla1280_initialize_adapter: failed to read "
1797 #if LINUX_VERSION_CODE >= 0x020500
1799 * It's necessary to grab the spin here as qla1280_mailbox_command
1800 * needs to be able to drop the lock unconditionally to wait
1802 * In 2.4 ->detect is called with the io_request_lock held.
1804 spin_lock_irqsave(HOST_LOCK, flags);
1807 status = qla1280_load_firmware(ha);
1809 printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
1814 /* Setup adapter based on NVRAM parameters. */
1815 dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha->host_no);
1816 qla1280_nvram_config(ha);
1818 if (ha->flags.disable_host_adapter) {
1823 status = qla1280_init_rings(ha);
1827 /* Issue SCSI reset, if we can't reset twice then bus is dead */
1828 for (bus = 0; bus < ha->ports; bus++) {
1829 if (!ha->bus_settings[bus].disable_scsi_reset &&
1830 qla1280_bus_reset(ha, bus) &&
1831 qla1280_bus_reset(ha, bus))
1832 ha->bus_settings[bus].scsi_bus_dead = 1;
1835 ha->flags.online = 1;
1837 #if LINUX_VERSION_CODE >= 0x020500
1838 spin_unlock_irqrestore(HOST_LOCK, flags);
1841 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
1843 LEAVE("qla1280_initialize_adapter");
1850 * Checks if present version of RISC firmware is older than
1854 * ha = adapter block pointer.
1857 * 0 = firmware does not need to be loaded.
1860 qla1280_isp_firmware(struct scsi_qla_host *ha)
1862 struct nvram *nv = (struct nvram *) ha->response_ring;
1863 int status = 0; /* dg 2/27 always loads RISC */
1864 uint16_t mb[MAILBOX_REGISTER_COUNT];
1866 ENTER("qla1280_isp_firmware");
1868 dprintk(1, "scsi(%li): Determining if RISC is loaded\n", ha->host_no);
1870 /* Bad NVRAM data, load RISC code. */
1871 if (!ha->nvram_valid) {
1872 ha->flags.disable_risc_code_load = 0;
1874 ha->flags.disable_risc_code_load =
1875 nv->cntr_flags_1.disable_loading_risc_code;
1877 if (ha->flags.disable_risc_code_load) {
1878 dprintk(3, "qla1280_isp_firmware: Telling RISC to verify "
1879 "checksum of loaded BIOS code.\n");
1881 /* Verify checksum of loaded RISC code. */
1882 mb[0] = MBC_VERIFY_CHECKSUM;
1883 /* mb[1] = ql12_risc_code_addr01; */
1884 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1887 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]))) {
1888 /* Start firmware execution. */
1889 dprintk(3, "qla1280_isp_firmware: Startng F/W "
1892 mb[0] = MBC_EXECUTE_FIRMWARE;
1893 /* mb[1] = ql12_risc_code_addr01; */
1894 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1895 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
1897 printk(KERN_INFO "qla1280: RISC checksum failed.\n");
1899 dprintk(1, "qla1280: NVRAM configured to load RISC load.\n");
1904 dprintk(2, "qla1280_isp_firmware: **** Load RISC code ****\n");
1906 LEAVE("qla1280_isp_firmware");
1912 * Test chip for proper operation.
1915 * ha = adapter block pointer.
1921 qla1280_chip_diag(struct scsi_qla_host *ha)
1923 uint16_t mb[MAILBOX_REGISTER_COUNT];
1924 struct device_reg __iomem *reg = ha->iobase;
1928 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®->id_l);
1930 dprintk(1, "scsi(%ld): Verifying chip\n", ha->host_no);
1932 /* Soft reset chip and wait for it to finish. */
1933 WRT_REG_WORD(®->ictrl, ISP_RESET);
1936 * We can't do a traditional PCI write flush here by reading
1937 * back the register. The card will not respond once the reset
1938 * is in action and we end up with a machine check exception
1939 * instead. Nothing to do but wait and hope for the best.
1940 * A portable pci_write_flush(pdev) call would be very useful here.
1943 data = qla1280_debounce_register(®->ictrl);
1945 * Yet another QLogic gem ;-(
1947 for (cnt = 1000000; cnt && data & ISP_RESET; cnt--) {
1949 data = RD_REG_WORD(®->ictrl);
1955 /* Reset register cleared by chip reset. */
1956 dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
1958 WRT_REG_WORD(®->cfg_1, 0);
1960 /* Reset RISC and disable BIOS which
1961 allows RISC to execute out of RAM. */
1962 WRT_REG_WORD(®->host_cmd, HC_RESET_RISC |
1963 HC_RELEASE_RISC | HC_DISABLE_BIOS);
1965 RD_REG_WORD(®->id_l); /* Flush PCI write */
1966 data = qla1280_debounce_register(®->mailbox0);
1969 * I *LOVE* this code!
1971 for (cnt = 1000000; cnt && data == MBS_BUSY; cnt--) {
1973 data = RD_REG_WORD(®->mailbox0);
1979 /* Check product ID of chip */
1980 dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
1982 if (RD_REG_WORD(®->mailbox1) != PROD_ID_1 ||
1983 (RD_REG_WORD(®->mailbox2) != PROD_ID_2 &&
1984 RD_REG_WORD(®->mailbox2) != PROD_ID_2a) ||
1985 RD_REG_WORD(®->mailbox3) != PROD_ID_3 ||
1986 RD_REG_WORD(®->mailbox4) != PROD_ID_4) {
1987 printk(KERN_INFO "qla1280: Wrong product ID = "
1988 "0x%x,0x%x,0x%x,0x%x\n",
1989 RD_REG_WORD(®->mailbox1),
1990 RD_REG_WORD(®->mailbox2),
1991 RD_REG_WORD(®->mailbox3),
1992 RD_REG_WORD(®->mailbox4));
1997 * Enable ints early!!!
1999 qla1280_enable_intrs(ha);
2001 dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
2002 /* Wrap Incoming Mailboxes Test. */
2003 mb[0] = MBC_MAILBOX_REGISTER_TEST;
2012 status = qla1280_mailbox_command(ha, 0xff, mb);
2016 if (mb[1] != 0xAAAA || mb[2] != 0x5555 || mb[3] != 0xAA55 ||
2017 mb[4] != 0x55AA || mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
2019 printk(KERN_INFO "qla1280: Failed mbox check\n");
2023 dprintk(3, "qla1280_chip_diag: exiting normally\n");
2026 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
2031 qla1280_load_firmware_pio(struct scsi_qla_host *ha)
2033 uint16_t risc_address, *risc_code_address, risc_code_size;
2034 uint16_t mb[MAILBOX_REGISTER_COUNT], i;
2037 /* Load RISC code. */
2038 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
2039 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
2040 risc_code_size = *ql1280_board_tbl[ha->devnum].fwlen;
2042 for (i = 0; i < risc_code_size; i++) {
2043 mb[0] = MBC_WRITE_RAM_WORD;
2044 mb[1] = risc_address + i;
2045 mb[2] = risc_code_address[i];
2047 err = qla1280_mailbox_command(ha, BIT_0 | BIT_1 | BIT_2, mb);
2049 printk(KERN_ERR "scsi(%li): Failed to load firmware\n",
2058 #define DUMP_IT_BACK 0 /* for debug of RISC loading */
2060 qla1280_load_firmware_dma(struct scsi_qla_host *ha)
2062 uint16_t risc_address, *risc_code_address, risc_code_size;
2063 uint16_t mb[MAILBOX_REGISTER_COUNT], cnt;
2064 int err = 0, num, i;
2069 tbuf = pci_alloc_consistent(ha->pdev, 8000, &p_tbuf);
2074 /* Load RISC code. */
2075 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
2076 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
2077 risc_code_size = *ql1280_board_tbl[ha->devnum].fwlen;
2079 dprintk(1, "%s: DMA RISC code (%i) words\n",
2080 __FUNCTION__, risc_code_size);
2083 while (risc_code_size > 0) {
2084 int warn __attribute__((unused)) = 0;
2088 if (cnt > risc_code_size)
2089 cnt = risc_code_size;
2091 dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
2093 risc_code_address, cnt, num, risc_address);
2094 for(i = 0; i < cnt; i++)
2095 ((uint16_t *)ha->request_ring)[i] =
2096 cpu_to_le16(risc_code_address[i]);
2098 mb[0] = MBC_LOAD_RAM;
2099 mb[1] = risc_address;
2101 mb[3] = ha->request_dma & 0xffff;
2102 mb[2] = (ha->request_dma >> 16) & 0xffff;
2103 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2104 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2105 dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
2106 __FUNCTION__, mb[0],
2107 (void *)(long)ha->request_dma,
2108 mb[6], mb[7], mb[2], mb[3]);
2109 err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
2112 printk(KERN_ERR "scsi(%li): Failed to load partial "
2113 "segment of f\n", ha->host_no);
2118 mb[0] = MBC_DUMP_RAM;
2119 mb[1] = risc_address;
2121 mb[3] = p_tbuf & 0xffff;
2122 mb[2] = (p_tbuf >> 16) & 0xffff;
2123 mb[7] = pci_dma_hi32(p_tbuf) & 0xffff;
2124 mb[6] = pci_dma_hi32(p_tbuf) >> 16;
2126 err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
2130 "Failed to dump partial segment of f/w\n");
2133 sp = (uint8_t *)ha->request_ring;
2134 for (i = 0; i < (cnt << 1); i++) {
2135 if (tbuf[i] != sp[i] && warn++ < 10) {
2136 printk(KERN_ERR "%s: FW compare error @ "
2137 "byte(0x%x) loop#=%x\n",
2138 __FUNCTION__, i, num);
2139 printk(KERN_ERR "%s: FWbyte=%x "
2141 __FUNCTION__, sp[i], tbuf[i]);
2146 risc_address += cnt;
2147 risc_code_size = risc_code_size - cnt;
2148 risc_code_address = risc_code_address + cnt;
2154 pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
2160 qla1280_start_firmware(struct scsi_qla_host *ha)
2162 uint16_t mb[MAILBOX_REGISTER_COUNT];
2165 dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
2168 /* Verify checksum of loaded RISC code. */
2169 mb[0] = MBC_VERIFY_CHECKSUM;
2170 /* mb[1] = ql12_risc_code_addr01; */
2171 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2172 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2174 printk(KERN_ERR "scsi(%li): Failed checksum\n", ha->host_no);
2178 /* Start firmware execution. */
2179 dprintk(1, "%s: start firmware running.\n", __FUNCTION__);
2180 mb[0] = MBC_EXECUTE_FIRMWARE;
2181 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2182 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2184 printk(KERN_ERR "scsi(%li): Failed to start firmware\n",
2192 qla1280_load_firmware(struct scsi_qla_host *ha)
2196 /* If firmware needs to be loaded */
2197 if (!qla1280_isp_firmware(ha)) {
2198 printk(KERN_ERR "scsi(%li): isp_firmware() failed!\n",
2203 err = qla1280_chip_diag(ha);
2207 err = qla1280_load_firmware_pio(ha);
2209 err = qla1280_load_firmware_dma(ha);
2212 err = qla1280_start_firmware(ha);
2221 * ha = adapter block pointer.
2222 * ha->request_ring = request ring virtual address
2223 * ha->response_ring = response ring virtual address
2224 * ha->request_dma = request ring physical address
2225 * ha->response_dma = response ring physical address
2231 qla1280_init_rings(struct scsi_qla_host *ha)
2233 uint16_t mb[MAILBOX_REGISTER_COUNT];
2236 ENTER("qla1280_init_rings");
2238 /* Clear outstanding commands array. */
2239 memset(ha->outstanding_cmds, 0,
2240 sizeof(struct srb *) * MAX_OUTSTANDING_COMMANDS);
2242 /* Initialize request queue. */
2243 ha->request_ring_ptr = ha->request_ring;
2244 ha->req_ring_index = 0;
2245 ha->req_q_cnt = REQUEST_ENTRY_CNT;
2246 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
2247 mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
2248 mb[1] = REQUEST_ENTRY_CNT;
2249 mb[3] = ha->request_dma & 0xffff;
2250 mb[2] = (ha->request_dma >> 16) & 0xffff;
2252 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2253 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2254 if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
2255 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2257 /* Initialize response queue. */
2258 ha->response_ring_ptr = ha->response_ring;
2259 ha->rsp_ring_index = 0;
2260 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
2261 mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
2262 mb[1] = RESPONSE_ENTRY_CNT;
2263 mb[3] = ha->response_dma & 0xffff;
2264 mb[2] = (ha->response_dma >> 16) & 0xffff;
2266 mb[7] = pci_dma_hi32(ha->response_dma) & 0xffff;
2267 mb[6] = pci_dma_hi32(ha->response_dma) >> 16;
2268 status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
2269 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2274 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
2276 LEAVE("qla1280_init_rings");
2281 qla1280_print_settings(struct nvram *nv)
2283 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
2284 nv->bus[0].config_1.initiator_id);
2285 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
2286 nv->bus[1].config_1.initiator_id);
2288 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
2289 nv->bus[0].bus_reset_delay);
2290 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
2291 nv->bus[1].bus_reset_delay);
2293 dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
2294 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
2295 dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
2296 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
2298 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
2299 nv->bus[0].config_2.async_data_setup_time);
2300 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
2301 nv->bus[1].config_2.async_data_setup_time);
2303 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
2304 nv->bus[0].config_2.req_ack_active_negation);
2305 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
2306 nv->bus[1].config_2.req_ack_active_negation);
2308 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
2309 nv->bus[0].config_2.data_line_active_negation);
2310 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
2311 nv->bus[1].config_2.data_line_active_negation);
2313 dprintk(1, "qla1280 : disable loading risc code=%d\n",
2314 nv->cntr_flags_1.disable_loading_risc_code);
2316 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
2317 nv->cntr_flags_1.enable_64bit_addressing);
2319 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
2320 nv->bus[0].selection_timeout);
2321 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
2322 nv->bus[1].selection_timeout);
2324 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
2325 nv->bus[0].max_queue_depth);
2326 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
2327 nv->bus[1].max_queue_depth);
2331 qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target)
2333 struct nvram *nv = &ha->nvram;
2335 nv->bus[bus].target[target].parameter.f.renegotiate_on_error = 1;
2336 nv->bus[bus].target[target].parameter.f.auto_request_sense = 1;
2337 nv->bus[bus].target[target].parameter.f.tag_queuing = 1;
2338 nv->bus[bus].target[target].parameter.f.enable_sync = 1;
2339 #if 1 /* Some SCSI Processors do not seem to like this */
2340 nv->bus[bus].target[target].parameter.f.enable_wide = 1;
2342 nv->bus[bus].target[target].parameter.f.parity_checking = 1;
2343 nv->bus[bus].target[target].parameter.f.disconnect_allowed = 1;
2344 nv->bus[bus].target[target].execution_throttle =
2345 nv->bus[bus].max_queue_depth - 1;
2347 if (IS_ISP1x160(ha)) {
2348 nv->bus[bus].target[target].flags.flags1x160.device_enable = 1;
2349 nv->bus[bus].target[target].flags.flags1x160.sync_offset = 0x0e;
2350 nv->bus[bus].target[target].sync_period = 9;
2351 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
2352 nv->bus[bus].target[target].ppr_1x160.flags.ppr_options = 2;
2353 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width = 1;
2355 nv->bus[bus].target[target].flags.flags1x80.device_enable = 1;
2356 nv->bus[bus].target[target].flags.flags1x80.sync_offset = 12;
2357 nv->bus[bus].target[target].sync_period = 10;
2362 qla1280_set_defaults(struct scsi_qla_host *ha)
2364 struct nvram *nv = &ha->nvram;
2367 dprintk(1, "Using defaults for NVRAM: \n");
2368 memset(nv, 0, sizeof(struct nvram));
2370 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
2371 nv->firmware_feature.f.enable_fast_posting = 1;
2372 nv->firmware_feature.f.disable_synchronous_backoff = 1;
2373 nv->termination.f.scsi_bus_0_control = 3;
2374 nv->termination.f.scsi_bus_1_control = 3;
2375 nv->termination.f.auto_term_support = 1;
2378 * Set default FIFO magic - What appropriate values would be here
2379 * is unknown. This is what I have found testing with 12160s.
2381 * Now, I would love the magic decoder ring for this one, the
2382 * header file provided by QLogic seems to be bogus or incomplete
2385 nv->isp_config.c = ISP_CFG1_BENAB|ISP_CFG1_F128;
2386 if (IS_ISP1x160(ha))
2387 nv->isp_parameter = 0x01; /* fast memory enable */
2389 for (bus = 0; bus < MAX_BUSES; bus++) {
2390 nv->bus[bus].config_1.initiator_id = 7;
2391 nv->bus[bus].config_2.req_ack_active_negation = 1;
2392 nv->bus[bus].config_2.data_line_active_negation = 1;
2393 nv->bus[bus].selection_timeout = 250;
2394 nv->bus[bus].max_queue_depth = 256;
2396 if (IS_ISP1040(ha)) {
2397 nv->bus[bus].bus_reset_delay = 3;
2398 nv->bus[bus].config_2.async_data_setup_time = 6;
2399 nv->bus[bus].retry_delay = 1;
2401 nv->bus[bus].bus_reset_delay = 5;
2402 nv->bus[bus].config_2.async_data_setup_time = 8;
2405 for (target = 0; target < MAX_TARGETS; target++)
2406 qla1280_set_target_defaults(ha, bus, target);
2411 qla1280_config_target(struct scsi_qla_host *ha, int bus, int target)
2413 struct nvram *nv = &ha->nvram;
2414 uint16_t mb[MAILBOX_REGISTER_COUNT];
2417 /* Set Target Parameters. */
2418 mb[0] = MBC_SET_TARGET_PARAMETERS;
2419 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
2423 * Do not enable wide, sync, and ppr for the initial
2424 * INQUIRY run. We enable this later if we determine
2425 * the target actually supports it.
2427 nv->bus[bus].target[target].parameter.f.
2428 auto_request_sense = 1;
2429 nv->bus[bus].target[target].parameter.f.
2430 stop_queue_on_check = 0;
2432 if (IS_ISP1x160(ha))
2433 nv->bus[bus].target[target].ppr_1x160.
2434 flags.enable_ppr = 0;
2437 * No sync, wide, etc. while probing
2439 mb[2] = (nv->bus[bus].target[target].parameter.c << 8) &
2440 ~(TP_SYNC /*| TP_WIDE | TP_PPR*/);
2442 if (IS_ISP1x160(ha))
2443 mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
2445 mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
2446 mb[3] |= nv->bus[bus].target[target].sync_period;
2448 status = qla1280_mailbox_command(ha, BIT_3 | BIT_2 | BIT_1 | BIT_0, &mb[0]);
2450 /* Save Tag queuing enable flag. */
2451 mb[0] = BIT_0 << target;
2452 if (nv->bus[bus].target[target].parameter.f.tag_queuing)
2453 ha->bus_settings[bus].qtag_enables |= mb[0];
2455 /* Save Device enable flag. */
2456 if (IS_ISP1x160(ha)) {
2457 if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
2458 ha->bus_settings[bus].device_enables |= mb[0];
2459 ha->bus_settings[bus].lun_disables |= 0;
2461 if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
2462 ha->bus_settings[bus].device_enables |= mb[0];
2463 /* Save LUN disable flag. */
2464 if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
2465 ha->bus_settings[bus].lun_disables |= mb[0];
2468 /* Set Device Queue Parameters. */
2469 for (lun = 0; lun < MAX_LUNS; lun++) {
2470 mb[0] = MBC_SET_DEVICE_QUEUE;
2471 mb[1] = (uint16_t)(bus ? target | BIT_7 : target);
2472 mb[1] = mb[1] << 8 | lun;
2473 mb[2] = nv->bus[bus].max_queue_depth;
2474 mb[3] = nv->bus[bus].target[target].execution_throttle;
2475 status |= qla1280_mailbox_command(ha, 0x0f, &mb[0]);
2482 qla1280_config_bus(struct scsi_qla_host *ha, int bus)
2484 struct nvram *nv = &ha->nvram;
2485 uint16_t mb[MAILBOX_REGISTER_COUNT];
2488 /* SCSI Reset Disable. */
2489 ha->bus_settings[bus].disable_scsi_reset =
2490 nv->bus[bus].config_1.scsi_reset_disable;
2493 ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
2494 mb[0] = MBC_SET_INITIATOR_ID;
2495 mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
2496 ha->bus_settings[bus].id;
2497 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2500 ha->bus_settings[bus].bus_reset_delay =
2501 nv->bus[bus].bus_reset_delay;
2503 /* Command queue depth per device. */
2504 ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
2506 /* Set target parameters. */
2507 for (target = 0; target < MAX_TARGETS; target++)
2508 status |= qla1280_config_target(ha, bus, target);
2514 qla1280_nvram_config(struct scsi_qla_host *ha)
2516 struct device_reg __iomem *reg = ha->iobase;
2517 struct nvram *nv = &ha->nvram;
2518 int bus, target, status = 0;
2519 uint16_t mb[MAILBOX_REGISTER_COUNT];
2522 ENTER("qla1280_nvram_config");
2524 if (ha->nvram_valid) {
2525 /* Always force AUTO sense for LINUX SCSI */
2526 for (bus = 0; bus < MAX_BUSES; bus++)
2527 for (target = 0; target < MAX_TARGETS; target++) {
2528 nv->bus[bus].target[target].parameter.f.
2529 auto_request_sense = 1;
2532 qla1280_set_defaults(ha);
2535 qla1280_print_settings(nv);
2537 /* Disable RISC load of firmware. */
2538 ha->flags.disable_risc_code_load =
2539 nv->cntr_flags_1.disable_loading_risc_code;
2541 if (IS_ISP1040(ha)) {
2542 uint16_t hwrev, cfg1, cdma_conf, ddma_conf;
2544 hwrev = RD_REG_WORD(®->cfg_0) & ISP_CFG0_HWMSK;
2546 cfg1 = RD_REG_WORD(®->cfg_1);
2547 cdma_conf = RD_REG_WORD(®->cdma_cfg);
2548 ddma_conf = RD_REG_WORD(®->ddma_cfg);
2550 /* Busted fifo, says mjacob. */
2551 if (hwrev == ISP_CFG0_1040A)
2552 WRT_REG_WORD(®->cfg_1, cfg1 | ISP_CFG1_F64);
2554 WRT_REG_WORD(®->cfg_1, cfg1 | ISP_CFG1_F64 | ISP_CFG1_BENAB);
2556 WRT_REG_WORD(®->cdma_cfg, cdma_conf | CDMA_CONF_BENAB);
2557 WRT_REG_WORD(®->ddma_cfg, cdma_conf | DDMA_CONF_BENAB);
2559 /* Set ISP hardware DMA burst */
2560 mb[0] = nv->isp_config.c;
2561 /* Enable DMA arbitration on dual channel controllers */
2564 WRT_REG_WORD(®->cfg_1, mb[0]);
2566 /* Set SCSI termination. */
2567 WRT_REG_WORD(®->gpio_enable, (BIT_3 + BIT_2 + BIT_1 + BIT_0));
2568 mb[0] = nv->termination.c & (BIT_3 + BIT_2 + BIT_1 + BIT_0);
2569 WRT_REG_WORD(®->gpio_data, mb[0]);
2572 /* ISP parameter word. */
2573 mb[0] = MBC_SET_SYSTEM_PARAMETER;
2574 mb[1] = nv->isp_parameter;
2575 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2577 if (IS_ISP1x40(ha)) {
2578 /* clock rate - for qla1240 and older, only */
2579 mb[0] = MBC_SET_CLOCK_RATE;
2581 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2584 /* Firmware feature word. */
2585 mb[0] = MBC_SET_FIRMWARE_FEATURES;
2586 mask = BIT_5 | BIT_1 | BIT_0;
2587 mb[1] = le16_to_cpu(nv->firmware_feature.w) & (mask);
2588 #if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
2589 if (ia64_platform_is("sn2")) {
2590 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
2591 "workaround\n", ha->host_no);
2595 status |= qla1280_mailbox_command(ha, mask, &mb[0]);
2597 /* Retry count and delay. */
2598 mb[0] = MBC_SET_RETRY_COUNT;
2599 mb[1] = nv->bus[0].retry_count;
2600 mb[2] = nv->bus[0].retry_delay;
2601 mb[6] = nv->bus[1].retry_count;
2602 mb[7] = nv->bus[1].retry_delay;
2603 status |= qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 |
2604 BIT_1 | BIT_0, &mb[0]);
2606 /* ASYNC data setup time. */
2607 mb[0] = MBC_SET_ASYNC_DATA_SETUP;
2608 mb[1] = nv->bus[0].config_2.async_data_setup_time;
2609 mb[2] = nv->bus[1].config_2.async_data_setup_time;
2610 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2612 /* Active negation states. */
2613 mb[0] = MBC_SET_ACTIVE_NEGATION;
2615 if (nv->bus[0].config_2.req_ack_active_negation)
2617 if (nv->bus[0].config_2.data_line_active_negation)
2620 if (nv->bus[1].config_2.req_ack_active_negation)
2622 if (nv->bus[1].config_2.data_line_active_negation)
2624 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2626 mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
2627 mb[1] = 2; /* Reset SCSI bus and return all outstanding IO */
2628 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2631 mb[0] = MBC_SET_PCI_CONTROL;
2632 mb[1] = 2; /* Data DMA Channel Burst Enable */
2633 mb[2] = 2; /* Command DMA Channel Burst Enable */
2634 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2636 mb[0] = MBC_SET_TAG_AGE_LIMIT;
2638 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2640 /* Selection timeout. */
2641 mb[0] = MBC_SET_SELECTION_TIMEOUT;
2642 mb[1] = nv->bus[0].selection_timeout;
2643 mb[2] = nv->bus[1].selection_timeout;
2644 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2646 for (bus = 0; bus < ha->ports; bus++)
2647 status |= qla1280_config_bus(ha, bus);
2650 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
2652 LEAVE("qla1280_nvram_config");
2657 * Get NVRAM data word
2658 * Calculates word position in NVRAM and calls request routine to
2659 * get the word from NVRAM.
2662 * ha = adapter block pointer.
2663 * address = NVRAM word address.
2669 qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
2674 nv_cmd = address << 16;
2675 nv_cmd |= NV_READ_OP;
2677 data = le16_to_cpu(qla1280_nvram_request(ha, nv_cmd));
2679 dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
2687 * Sends read command to NVRAM and gets data from NVRAM.
2690 * ha = adapter block pointer.
2691 * nv_cmd = Bit 26 = start bit
2692 * Bit 25, 24 = opcode
2693 * Bit 23-16 = address
2694 * Bit 15-0 = write data
2700 qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
2702 struct device_reg __iomem *reg = ha->iobase;
2707 /* Send command to NVRAM. */
2710 for (cnt = 0; cnt < 11; cnt++) {
2711 if (nv_cmd & BIT_31)
2712 qla1280_nv_write(ha, NV_DATA_OUT);
2714 qla1280_nv_write(ha, 0);
2718 /* Read data from NVRAM. */
2720 for (cnt = 0; cnt < 16; cnt++) {
2721 WRT_REG_WORD(®->nvram, (NV_SELECT | NV_CLOCK));
2722 RD_REG_WORD(®->id_l); /* Flush PCI write */
2725 reg_data = RD_REG_WORD(®->nvram);
2726 if (reg_data & NV_DATA_IN)
2728 WRT_REG_WORD(®->nvram, NV_SELECT);
2729 RD_REG_WORD(®->id_l); /* Flush PCI write */
2733 /* Deselect chip. */
2735 WRT_REG_WORD(®->nvram, NV_DESELECT);
2736 RD_REG_WORD(®->id_l); /* Flush PCI write */
2743 qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
2745 struct device_reg __iomem *reg = ha->iobase;
2747 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2748 RD_REG_WORD(®->id_l); /* Flush PCI write */
2750 WRT_REG_WORD(®->nvram, data | NV_SELECT | NV_CLOCK);
2751 RD_REG_WORD(®->id_l); /* Flush PCI write */
2753 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2754 RD_REG_WORD(®->id_l); /* Flush PCI write */
2760 * Issue mailbox command and waits for completion.
2763 * ha = adapter block pointer.
2764 * mr = mailbox registers to load.
2765 * mb = data pointer for mailbox registers.
2768 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
2774 qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
2776 struct device_reg __iomem *reg = ha->iobase;
2782 uint16_t *optr, *iptr;
2783 uint16_t __iomem *mptr;
2785 DECLARE_COMPLETION(wait);
2786 struct timer_list timer;
2788 ENTER("qla1280_mailbox_command");
2790 if (ha->mailbox_wait) {
2791 printk(KERN_ERR "Warning mailbox wait already in use!\n");
2793 ha->mailbox_wait = &wait;
2796 * We really should start out by verifying that the mailbox is
2797 * available before starting sending the command data
2799 /* Load mailbox registers. */
2800 mptr = (uint16_t __iomem *) ®->mailbox0;
2802 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
2804 WRT_REG_WORD(mptr, (*iptr));
2812 /* Issue set host interrupt command. */
2814 /* set up a timer just in case we're really jammed */
2816 timer.expires = jiffies + 20*HZ;
2817 timer.data = (unsigned long)ha;
2818 timer.function = qla1280_mailbox_timeout;
2821 spin_unlock_irq(HOST_LOCK);
2822 WRT_REG_WORD(®->host_cmd, HC_SET_HOST_INT);
2823 data = qla1280_debounce_register(®->istatus);
2825 wait_for_completion(&wait);
2826 del_timer_sync(&timer);
2828 spin_lock_irq(HOST_LOCK);
2830 ha->mailbox_wait = NULL;
2832 /* Check for mailbox command timeout. */
2833 if (ha->mailbox_out[0] != MBS_CMD_CMP) {
2834 printk(KERN_WARNING "qla1280_mailbox_command: Command failed, "
2835 "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
2837 mb[0], ha->mailbox_out[0], RD_REG_WORD(®->istatus));
2838 printk(KERN_WARNING "m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
2839 RD_REG_WORD(®->mailbox0), RD_REG_WORD(®->mailbox1),
2840 RD_REG_WORD(®->mailbox2), RD_REG_WORD(®->mailbox3));
2841 printk(KERN_WARNING "m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
2842 RD_REG_WORD(®->mailbox4), RD_REG_WORD(®->mailbox5),
2843 RD_REG_WORD(®->mailbox6), RD_REG_WORD(®->mailbox7));
2847 /* Load return mailbox registers. */
2849 iptr = (uint16_t *) &ha->mailbox_out[0];
2850 mr = MAILBOX_REGISTER_COUNT;
2851 memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
2854 /* Go check for any response interrupts pending. */
2855 qla1280_isr(ha, &done_q);
2858 if (ha->flags.reset_marker)
2859 qla1280_rst_aen(ha);
2862 if (!list_empty(&done_q))
2863 qla1280_done(ha, &done_q);
2867 dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
2868 "0x%x ****\n", mb[0]);
2870 LEAVE("qla1280_mailbox_command");
2876 * Polls ISP for interrupts.
2879 * ha = adapter block pointer.
2882 qla1280_poll(struct scsi_qla_host *ha)
2884 struct device_reg __iomem *reg = ha->iobase;
2888 /* ENTER("qla1280_poll"); */
2890 /* Check for pending interrupts. */
2891 data = RD_REG_WORD(®->istatus);
2892 if (data & RISC_INT)
2893 qla1280_isr(ha, &done_q);
2895 if (!ha->mailbox_wait) {
2896 if (ha->flags.reset_marker)
2897 qla1280_rst_aen(ha);
2900 if (!list_empty(&done_q))
2903 /* LEAVE("qla1280_poll"); */
2908 * Issue SCSI bus reset.
2911 * ha = adapter block pointer.
2912 * bus = SCSI bus number.
2918 qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
2920 uint16_t mb[MAILBOX_REGISTER_COUNT];
2921 uint16_t reset_delay;
2924 dprintk(3, "qla1280_bus_reset: entered\n");
2926 if (qla1280_verbose)
2927 printk(KERN_INFO "scsi(%li:%i): Resetting SCSI BUS\n",
2930 reset_delay = ha->bus_settings[bus].bus_reset_delay;
2931 mb[0] = MBC_BUS_RESET;
2932 mb[1] = reset_delay;
2933 mb[2] = (uint16_t) bus;
2934 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2937 if (ha->bus_settings[bus].failed_reset_count > 2)
2938 ha->bus_settings[bus].scsi_bus_dead = 1;
2939 ha->bus_settings[bus].failed_reset_count++;
2941 spin_unlock_irq(HOST_LOCK);
2942 schedule_timeout(reset_delay * HZ);
2943 spin_lock_irq(HOST_LOCK);
2945 ha->bus_settings[bus].scsi_bus_dead = 0;
2946 ha->bus_settings[bus].failed_reset_count = 0;
2947 ha->bus_settings[bus].reset_marker = 0;
2948 /* Issue marker command. */
2949 qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
2953 * We should probably call qla1280_set_target_parameters()
2954 * here as well for all devices on the bus.
2958 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
2960 dprintk(3, "qla1280_bus_reset: exiting normally\n");
2966 * qla1280_device_reset
2967 * Issue bus device reset message to the target.
2970 * ha = adapter block pointer.
2971 * bus = SCSI BUS number.
2978 qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
2980 uint16_t mb[MAILBOX_REGISTER_COUNT];
2983 ENTER("qla1280_device_reset");
2985 mb[0] = MBC_ABORT_TARGET;
2986 mb[1] = (bus ? (target | BIT_7) : target) << 8;
2988 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2990 /* Issue marker command. */
2991 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
2994 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
2996 LEAVE("qla1280_device_reset");
3001 * qla1280_abort_device
3002 * Issue an abort message to the device
3005 * ha = adapter block pointer.
3014 qla1280_abort_device(struct scsi_qla_host *ha, int bus, int target, int lun)
3016 uint16_t mb[MAILBOX_REGISTER_COUNT];
3019 ENTER("qla1280_abort_device");
3021 mb[0] = MBC_ABORT_DEVICE;
3022 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
3023 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
3025 /* Issue marker command. */
3026 qla1280_marker(ha, bus, target, lun, MK_SYNC_ID_LUN);
3029 dprintk(2, "qla1280_abort_device: **** FAILED ****\n");
3031 LEAVE("qla1280_abort_device");
3036 * qla1280_abort_command
3037 * Abort command aborts a specified IOCB.
3040 * ha = adapter block pointer.
3041 * sp = SB structure pointer.
3047 qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
3049 uint16_t mb[MAILBOX_REGISTER_COUNT];
3050 unsigned int bus, target, lun;
3053 ENTER("qla1280_abort_command");
3055 bus = SCSI_BUS_32(sp->cmd);
3056 target = SCSI_TCN_32(sp->cmd);
3057 lun = SCSI_LUN_32(sp->cmd);
3059 sp->flags |= SRB_ABORT_PENDING;
3061 mb[0] = MBC_ABORT_COMMAND;
3062 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
3063 mb[2] = handle >> 16;
3064 mb[3] = handle & 0xffff;
3065 status = qla1280_mailbox_command(ha, 0x0f, &mb[0]);
3068 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
3069 sp->flags &= ~SRB_ABORT_PENDING;
3073 LEAVE("qla1280_abort_command");
3078 * qla1280_reset_adapter
3082 * ha = adapter block pointer.
3085 qla1280_reset_adapter(struct scsi_qla_host *ha)
3087 struct device_reg __iomem *reg = ha->iobase;
3089 ENTER("qla1280_reset_adapter");
3091 /* Disable ISP chip */
3092 ha->flags.online = 0;
3093 WRT_REG_WORD(®->ictrl, ISP_RESET);
3094 WRT_REG_WORD(®->host_cmd,
3095 HC_RESET_RISC | HC_RELEASE_RISC | HC_DISABLE_BIOS);
3096 RD_REG_WORD(®->id_l); /* Flush PCI write */
3098 LEAVE("qla1280_reset_adapter");
3102 * Issue marker command.
3103 * Function issues marker IOCB.
3106 * ha = adapter block pointer.
3107 * bus = SCSI BUS number
3110 * type = marker modifier
3113 qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
3115 struct mrk_entry *pkt;
3117 ENTER("qla1280_marker");
3119 /* Get request packet. */
3120 if ((pkt = (struct mrk_entry *) qla1280_req_pkt(ha))) {
3121 pkt->entry_type = MARKER_TYPE;
3122 pkt->lun = (uint8_t) lun;
3123 pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
3124 pkt->modifier = type;
3125 pkt->entry_status = 0;
3127 /* Issue command to ISP */
3128 qla1280_isp_cmd(ha);
3131 LEAVE("qla1280_marker");
3136 * qla1280_64bit_start_scsi
3137 * The start SCSI is responsible for building request packets on
3138 * request ring and modifying ISP input pointer.
3141 * ha = adapter block pointer.
3142 * sp = SB structure pointer.
3145 * 0 = success, was able to issue command.
3147 #ifdef QLA_64BIT_PTR
3149 qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3151 struct device_reg __iomem *reg = ha->iobase;
3152 struct scsi_cmnd *cmd = sp->cmd;
3153 cmd_a64_entry_t *pkt;
3154 struct scatterlist *sg = NULL;
3156 dma_addr_t dma_handle;
3163 ENTER("qla1280_64bit_start_scsi:");
3165 /* Calculate number of entries and segments required. */
3168 sg = (struct scatterlist *) cmd->request_buffer;
3169 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3170 cmd->sc_data_direction);
3173 req_cnt += (seg_cnt - 2) / 5;
3174 if ((seg_cnt - 2) % 5)
3177 } else if (cmd->request_bufflen) { /* If data transfer. */
3183 if ((req_cnt + 2) >= ha->req_q_cnt) {
3184 /* Calculate number of free request entries. */
3185 cnt = RD_REG_WORD(®->mailbox4);
3186 if (ha->req_ring_index < cnt)
3187 ha->req_q_cnt = cnt - ha->req_ring_index;
3190 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3193 /* If room for request in request ring. */
3194 if ((req_cnt + 2) >= ha->req_q_cnt) {
3196 dprintk(2, "qla1280_64bit_start_scsi: in-ptr=0x%x req_q_cnt="
3197 "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
3202 /* Check for room in outstanding command list. */
3203 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3204 ha->outstanding_cmds[cnt] != 0; cnt++);
3206 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3208 dprintk(2, "qla1280_64bit_start_scsi: NO ROOM IN "
3209 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
3213 ha->outstanding_cmds[cnt] = sp;
3214 ha->req_q_cnt -= req_cnt;
3215 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
3217 dprintk(2, "64bit_start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
3218 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
3219 dprintk(2, " bus %i, target %i, lun %i\n",
3220 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3221 qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
3224 * Build command packet.
3226 pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
3228 pkt->entry_type = COMMAND_A64_TYPE;
3229 pkt->entry_count = (uint8_t) req_cnt;
3230 pkt->sys_define = (uint8_t) ha->req_ring_index;
3231 pkt->entry_status = 0;
3232 pkt->handle = cpu_to_le32(cnt);
3234 /* Zero out remaining portion of packet. */
3235 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3237 /* Set ISP command timeout. */
3238 pkt->timeout = cpu_to_le16(30);
3240 /* Set device target ID and LUN */
3241 pkt->lun = SCSI_LUN_32(cmd);
3242 pkt->target = SCSI_BUS_32(cmd) ?
3243 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3245 /* Enable simple tag queuing if device supports it. */
3246 if (DEV_SIMPLE_TAGS(cmd->device))
3247 pkt->control_flags |= cpu_to_le16(BIT_3);
3249 /* Load SCSI command packet. */
3250 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3251 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3252 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3254 /* Set transfer direction. */
3255 dir = qla1280_data_direction(cmd);
3256 pkt->control_flags |= cpu_to_le16(dir);
3258 /* Set total data segment count. */
3259 pkt->dseg_count = cpu_to_le16(seg_cnt);
3262 * Load data segments.
3264 if (seg_cnt) { /* If data transfer. */
3265 /* Setup packet address segment pointer. */
3266 dword_ptr = (u32 *)&pkt->dseg_0_address;
3268 if (cmd->use_sg) { /* If scatter gather */
3269 /* Load command entry data segments. */
3270 for (cnt = 0; cnt < 2 && seg_cnt; cnt++, seg_cnt--) {
3271 dma_handle = sg_dma_address(sg);
3272 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3273 if (ha->flags.use_pci_vchannel)
3274 sn_pci_set_vchan(ha->pdev,
3275 (unsigned long *)&dma_handle,
3279 cpu_to_le32(pci_dma_lo32(dma_handle));
3281 cpu_to_le32(pci_dma_hi32(dma_handle));
3282 *dword_ptr++ = cpu_to_le32(sg_dma_len(sg));
3284 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
3285 cpu_to_le32(pci_dma_hi32(dma_handle)),
3286 cpu_to_le32(pci_dma_lo32(dma_handle)),
3287 cpu_to_le32(sg_dma_len(sg)));
3289 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
3290 "command packet data - b %i, t %i, l %i \n",
3291 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3293 qla1280_dump_buffer(5, (char *)pkt,
3294 REQUEST_ENTRY_SIZE);
3297 * Build continuation packets.
3299 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
3300 "remains\n", seg_cnt);
3302 while (seg_cnt > 0) {
3303 /* Adjust ring index. */
3304 ha->req_ring_index++;
3305 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3306 ha->req_ring_index = 0;
3307 ha->request_ring_ptr =
3310 ha->request_ring_ptr++;
3312 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
3314 /* Zero out packet. */
3315 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3317 /* Load packet defaults. */
3318 ((struct cont_a64_entry *) pkt)->entry_type =
3320 ((struct cont_a64_entry *) pkt)->entry_count = 1;
3321 ((struct cont_a64_entry *) pkt)->sys_define =
3322 (uint8_t)ha->req_ring_index;
3323 /* Setup packet address segment pointer. */
3325 (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
3327 /* Load continuation entry data segments. */
3328 for (cnt = 0; cnt < 5 && seg_cnt;
3330 dma_handle = sg_dma_address(sg);
3331 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3332 if (ha->flags.use_pci_vchannel)
3333 sn_pci_set_vchan(ha->pdev,
3334 (unsigned long *)&dma_handle,
3338 cpu_to_le32(pci_dma_lo32(dma_handle));
3340 cpu_to_le32(pci_dma_hi32(dma_handle));
3342 cpu_to_le32(sg_dma_len(sg));
3343 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
3344 cpu_to_le32(pci_dma_hi32(dma_handle)),
3345 cpu_to_le32(pci_dma_lo32(dma_handle)),
3346 cpu_to_le32(sg_dma_len(sg)));
3349 dprintk(5, "qla1280_64bit_start_scsi: "
3350 "continuation packet data - b %i, t "
3351 "%i, l %i \n", SCSI_BUS_32(cmd),
3352 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3353 qla1280_dump_buffer(5, (char *)pkt,
3354 REQUEST_ENTRY_SIZE);
3356 } else { /* No scatter gather data transfer */
3357 struct page *page = virt_to_page(cmd->request_buffer);
3358 unsigned long off = (unsigned long)cmd->request_buffer & ~PAGE_MASK;
3360 dma_handle = pci_map_page(ha->pdev, page, off,
3361 cmd->request_bufflen,
3362 cmd->sc_data_direction);
3364 /* save dma_handle for pci_unmap_page */
3365 sp->saved_dma_handle = dma_handle;
3366 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3367 if (ha->flags.use_pci_vchannel)
3368 sn_pci_set_vchan(ha->pdev,
3369 (unsigned long *)&dma_handle,
3372 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3373 *dword_ptr++ = cpu_to_le32(pci_dma_hi32(dma_handle));
3374 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3376 dprintk(5, "qla1280_64bit_start_scsi: No scatter/"
3377 "gather command packet data - b %i, t %i, "
3378 "l %i \n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3380 qla1280_dump_buffer(5, (char *)pkt,
3381 REQUEST_ENTRY_SIZE);
3383 } else { /* No data transfer */
3384 dprintk(5, "qla1280_64bit_start_scsi: No data, command "
3385 "packet data - b %i, t %i, l %i \n",
3386 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3387 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3389 /* Adjust ring index. */
3390 ha->req_ring_index++;
3391 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3392 ha->req_ring_index = 0;
3393 ha->request_ring_ptr = ha->request_ring;
3395 ha->request_ring_ptr++;
3397 /* Set chip new ring index. */
3399 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
3400 sp->flags |= SRB_SENT;
3402 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3403 /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
3408 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
3410 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
3414 #else /* !QLA_64BIT_PTR */
3417 * qla1280_32bit_start_scsi
3418 * The start SCSI is responsible for building request packets on
3419 * request ring and modifying ISP input pointer.
3421 * The Qlogic firmware interface allows every queue slot to have a SCSI
3422 * command and up to 4 scatter/gather (SG) entries. If we need more
3423 * than 4 SG entries, then continuation entries are used that can
3424 * hold another 7 entries each. The start routine determines if there
3425 * is eought empty slots then build the combination of requests to
3426 * fulfill the OS request.
3429 * ha = adapter block pointer.
3430 * sp = SCSI Request Block structure pointer.
3433 * 0 = success, was able to issue command.
3436 qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3438 struct device_reg __iomem *reg = ha->iobase;
3439 struct scsi_cmnd *cmd = sp->cmd;
3440 struct cmd_entry *pkt;
3441 struct scatterlist *sg = NULL;
3442 uint32_t *dword_ptr;
3447 dma_addr_t dma_handle;
3450 ENTER("qla1280_32bit_start_scsi");
3452 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
3455 /* Calculate number of entries and segments required. */
3459 * We must build an SG list in adapter format, as the kernel's
3460 * SG list cannot be used directly because of data field size
3461 * (__alpha__) differences and the kernel SG list uses virtual
3462 * addresses where we need physical addresses.
3464 sg = (struct scatterlist *) cmd->request_buffer;
3465 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3466 cmd->sc_data_direction);
3469 * if greater than four sg entries then we need to allocate
3470 * continuation entries
3473 req_cnt += (seg_cnt - 4) / 7;
3474 if ((seg_cnt - 4) % 7)
3477 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3478 cmd, seg_cnt, req_cnt);
3479 } else if (cmd->request_bufflen) { /* If data transfer. */
3480 dprintk(3, "No S/G transfer t=%x cmd=%p len=%x CDB=%x\n",
3481 SCSI_TCN_32(cmd), cmd, cmd->request_bufflen,
3485 /* dprintk(1, "No data transfer \n"); */
3489 if ((req_cnt + 2) >= ha->req_q_cnt) {
3490 /* Calculate number of free request entries. */
3491 cnt = RD_REG_WORD(®->mailbox4);
3492 if (ha->req_ring_index < cnt)
3493 ha->req_q_cnt = cnt - ha->req_ring_index;
3496 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3499 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3500 ha->req_q_cnt, seg_cnt);
3501 /* If room for request in request ring. */
3502 if ((req_cnt + 2) >= ha->req_q_cnt) {
3504 dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
3505 "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
3506 ha->req_q_cnt, req_cnt);
3510 /* Check for empty slot in outstanding command list. */
3511 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3512 (ha->outstanding_cmds[cnt] != 0); cnt++) ;
3514 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3516 dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
3517 "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
3521 CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
3522 ha->outstanding_cmds[cnt] = sp;
3523 ha->req_q_cnt -= req_cnt;
3526 * Build command packet.
3528 pkt = (struct cmd_entry *) ha->request_ring_ptr;
3530 pkt->entry_type = COMMAND_TYPE;
3531 pkt->entry_count = (uint8_t) req_cnt;
3532 pkt->sys_define = (uint8_t) ha->req_ring_index;
3533 pkt->entry_status = 0;
3534 pkt->handle = cpu_to_le32(cnt);
3536 /* Zero out remaining portion of packet. */
3537 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3539 /* Set ISP command timeout. */
3540 pkt->timeout = cpu_to_le16(30);
3542 /* Set device target ID and LUN */
3543 pkt->lun = SCSI_LUN_32(cmd);
3544 pkt->target = SCSI_BUS_32(cmd) ?
3545 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3547 /* Enable simple tag queuing if device supports it. */
3548 if (DEV_SIMPLE_TAGS(cmd->device))
3549 pkt->control_flags |= cpu_to_le16(BIT_3);
3551 /* Load SCSI command packet. */
3552 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3553 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3555 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3556 /* Set transfer direction. */
3557 dir = qla1280_data_direction(cmd);
3558 pkt->control_flags |= cpu_to_le16(dir);
3560 /* Set total data segment count. */
3561 pkt->dseg_count = cpu_to_le16(seg_cnt);
3564 * Load data segments.
3567 /* Setup packet address segment pointer. */
3568 dword_ptr = &pkt->dseg_0_address;
3570 if (cmd->use_sg) { /* If scatter gather */
3571 dprintk(3, "Building S/G data segments..\n");
3572 qla1280_dump_buffer(1, (char *)sg, 4 * 16);
3574 /* Load command entry data segments. */
3575 for (cnt = 0; cnt < 4 && seg_cnt; cnt++, seg_cnt--) {
3577 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3579 cpu_to_le32(sg_dma_len(sg));
3580 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3581 (pci_dma_lo32(sg_dma_address(sg))),
3586 * Build continuation packets.
3588 dprintk(3, "S/G Building Continuation"
3589 "...seg_cnt=0x%x remains\n", seg_cnt);
3590 while (seg_cnt > 0) {
3591 /* Adjust ring index. */
3592 ha->req_ring_index++;
3593 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3594 ha->req_ring_index = 0;
3595 ha->request_ring_ptr =
3598 ha->request_ring_ptr++;
3600 pkt = (struct cmd_entry *)ha->request_ring_ptr;
3602 /* Zero out packet. */
3603 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3605 /* Load packet defaults. */
3606 ((struct cont_entry *) pkt)->
3607 entry_type = CONTINUE_TYPE;
3608 ((struct cont_entry *) pkt)->entry_count = 1;
3610 ((struct cont_entry *) pkt)->sys_define =
3611 (uint8_t) ha->req_ring_index;
3613 /* Setup packet address segment pointer. */
3615 &((struct cont_entry *) pkt)->dseg_0_address;
3617 /* Load continuation entry data segments. */
3618 for (cnt = 0; cnt < 7 && seg_cnt;
3621 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3623 cpu_to_le32(sg_dma_len(sg));
3625 "S/G Segment Cont. phys_addr=0x%x, "
3627 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
3628 cpu_to_le32(sg_dma_len(sg)));
3631 dprintk(5, "qla1280_32bit_start_scsi: "
3632 "continuation packet data - "
3633 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
3634 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3635 qla1280_dump_buffer(5, (char *)pkt,
3636 REQUEST_ENTRY_SIZE);
3638 } else { /* No S/G data transfer */
3639 struct page *page = virt_to_page(cmd->request_buffer);
3640 unsigned long off = (unsigned long)cmd->request_buffer & ~PAGE_MASK;
3641 dma_handle = pci_map_page(ha->pdev, page, off,
3642 cmd->request_bufflen,
3643 cmd->sc_data_direction);
3644 sp->saved_dma_handle = dma_handle;
3646 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3647 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3649 } else { /* No data transfer at all */
3650 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
3651 "packet data - \n");
3652 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3654 dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
3655 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3656 REQUEST_ENTRY_SIZE);
3658 /* Adjust ring index. */
3659 ha->req_ring_index++;
3660 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3661 ha->req_ring_index = 0;
3662 ha->request_ring_ptr = ha->request_ring;
3664 ha->request_ring_ptr++;
3666 /* Set chip new ring index. */
3667 dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
3668 "for pending command\n");
3669 sp->flags |= SRB_SENT;
3671 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3672 /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
3677 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
3679 LEAVE("qla1280_32bit_start_scsi");
3687 * Function is responsible for locking ring and
3688 * getting a zeroed out request packet.
3691 * ha = adapter block pointer.
3694 * 0 = failed to get slot.
3697 qla1280_req_pkt(struct scsi_qla_host *ha)
3699 struct device_reg __iomem *reg = ha->iobase;
3700 request_t *pkt = NULL;
3704 ENTER("qla1280_req_pkt");
3707 * This can be called from interrupt context, damn it!!!
3709 /* Wait for 30 seconds for slot. */
3710 for (timer = 15000000; timer; timer--) {
3711 if (ha->req_q_cnt > 0) {
3712 /* Calculate number of free request entries. */
3713 cnt = RD_REG_WORD(®->mailbox4);
3714 if (ha->req_ring_index < cnt)
3715 ha->req_q_cnt = cnt - ha->req_ring_index;
3718 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3721 /* Found empty request ring slot? */
3722 if (ha->req_q_cnt > 0) {
3724 pkt = ha->request_ring_ptr;
3726 /* Zero out packet. */
3727 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3730 * How can this be right when we have a ring
3733 /* Set system defined field. */
3734 pkt->sys_define = (uint8_t) ha->req_ring_index;
3736 /* Set entry count. */
3737 pkt->entry_count = 1;
3744 /* Check for pending interrupts. */
3749 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
3751 dprintk(3, "qla1280_req_pkt: exiting normally\n");
3758 * Function is responsible for modifying ISP input pointer.
3759 * Releases ring lock.
3762 * ha = adapter block pointer.
3765 qla1280_isp_cmd(struct scsi_qla_host *ha)
3767 struct device_reg __iomem *reg = ha->iobase;
3769 ENTER("qla1280_isp_cmd");
3771 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
3772 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3773 REQUEST_ENTRY_SIZE);
3775 /* Adjust ring index. */
3776 ha->req_ring_index++;
3777 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3778 ha->req_ring_index = 0;
3779 ha->request_ring_ptr = ha->request_ring;
3781 ha->request_ring_ptr++;
3784 * Update request index to mailbox4 (Request Queue In).
3785 * The mmiowb() ensures that this write is ordered with writes by other
3786 * CPUs. Without the mmiowb(), it is possible for the following:
3787 * CPUA posts write of index 5 to mailbox4
3788 * CPUA releases host lock
3789 * CPUB acquires host lock
3790 * CPUB posts write of index 6 to mailbox4
3791 * On PCI bus, order reverses and write of 6 posts, then index 5,
3792 * causing chip to issue full queue of stale commands
3793 * The mmiowb() prevents future writes from crossing the barrier.
3794 * See Documentation/DocBook/deviceiobook.tmpl for more information.
3796 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3799 LEAVE("qla1280_isp_cmd");
3802 /****************************************************************************/
3803 /* Interrupt Service Routine. */
3804 /****************************************************************************/
3806 /****************************************************************************
3808 * Calls I/O done on command completion.
3811 * ha = adapter block pointer.
3812 * done_q = done queue.
3813 ****************************************************************************/
3815 qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
3817 struct device_reg __iomem *reg = ha->iobase;
3818 struct response *pkt;
3819 struct srb *sp = NULL;
3820 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
3825 ENTER("qla1280_isr");
3827 istatus = RD_REG_WORD(®->istatus);
3828 if (!(istatus & (RISC_INT | PCI_INT)))
3831 /* Save mailbox register 5 */
3832 mailbox[5] = RD_REG_WORD(®->mailbox5);
3834 /* Check for mailbox interrupt. */
3836 mailbox[0] = RD_REG_WORD_dmasync(®->semaphore);
3838 if (mailbox[0] & BIT_0) {
3839 /* Get mailbox data. */
3840 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
3843 *wptr++ = RD_REG_WORD(®->mailbox0);
3844 *wptr++ = RD_REG_WORD(®->mailbox1);
3845 *wptr = RD_REG_WORD(®->mailbox2);
3846 if (mailbox[0] != MBA_SCSI_COMPLETION) {
3848 *wptr++ = RD_REG_WORD(®->mailbox3);
3849 *wptr++ = RD_REG_WORD(®->mailbox4);
3851 *wptr++ = RD_REG_WORD(®->mailbox6);
3852 *wptr = RD_REG_WORD(®->mailbox7);
3855 /* Release mailbox registers. */
3857 WRT_REG_WORD(®->semaphore, 0);
3858 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3860 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
3863 /* Handle asynchronous event */
3864 switch (mailbox[0]) {
3865 case MBA_SCSI_COMPLETION: /* Response completion */
3866 dprintk(5, "qla1280_isr: mailbox SCSI response "
3869 if (ha->flags.online) {
3870 /* Get outstanding command index. */
3871 index = mailbox[2] << 16 | mailbox[1];
3873 /* Validate handle. */
3874 if (index < MAX_OUTSTANDING_COMMANDS)
3875 sp = ha->outstanding_cmds[index];
3880 /* Free outstanding command slot. */
3881 ha->outstanding_cmds[index] = NULL;
3883 /* Save ISP completion status */
3884 CMD_RESULT(sp->cmd) = 0;
3886 /* Place block on done queue */
3887 list_add_tail(&sp->list, done_q);
3890 * If we get here we have a real problem!
3893 "qla1280: ISP invalid handle");
3898 case MBA_BUS_RESET: /* SCSI Bus Reset */
3899 ha->flags.reset_marker = 1;
3900 index = mailbox[6] & BIT_0;
3901 ha->bus_settings[index].reset_marker = 1;
3903 printk(KERN_DEBUG "qla1280_isr(): index %i "
3904 "asynchronous BUS_RESET\n", index);
3907 case MBA_SYSTEM_ERR: /* System Error */
3909 "qla1280: ISP System Error - mbx1=%xh, mbx2="
3910 "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
3914 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
3916 "qla1280: ISP Request Transfer Error\n");
3919 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
3921 "qla1280: ISP Response Transfer Error\n");
3924 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
3925 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
3928 case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
3930 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
3933 case MBA_DEVICE_RESET: /* Bus Device Reset */
3934 printk(KERN_INFO "qla1280_isr(): asynchronous "
3935 "BUS_DEVICE_RESET\n");
3937 ha->flags.reset_marker = 1;
3938 index = mailbox[6] & BIT_0;
3939 ha->bus_settings[index].reset_marker = 1;
3942 case MBA_BUS_MODE_CHANGE:
3944 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
3948 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
3949 if (mailbox[0] < MBA_ASYNC_EVENT) {
3951 memcpy((uint16_t *) ha->mailbox_out, wptr,
3952 MAILBOX_REGISTER_COUNT *
3955 if(ha->mailbox_wait != NULL)
3956 complete(ha->mailbox_wait);
3961 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3965 * We will receive interrupts during mailbox testing prior to
3966 * the card being marked online, hence the double check.
3968 if (!(ha->flags.online && !ha->mailbox_wait)) {
3969 dprintk(2, "qla1280_isr: Response pointer Error\n");
3973 if (mailbox[5] >= RESPONSE_ENTRY_CNT)
3976 while (ha->rsp_ring_index != mailbox[5]) {
3977 pkt = ha->response_ring_ptr;
3979 dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
3980 " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
3981 dprintk(5,"qla1280_isr: response packet data\n");
3982 qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
3984 if (pkt->entry_type == STATUS_TYPE) {
3985 if ((le16_to_cpu(pkt->scsi_status) & 0xff)
3986 || pkt->comp_status || pkt->entry_status) {
3987 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3988 "0x%x mailbox[5] = 0x%x, comp_status "
3989 "= 0x%x, scsi_status = 0x%x\n",
3990 ha->rsp_ring_index, mailbox[5],
3991 le16_to_cpu(pkt->comp_status),
3992 le16_to_cpu(pkt->scsi_status));
3995 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3996 "0x%x, mailbox[5] = 0x%x\n",
3997 ha->rsp_ring_index, mailbox[5]);
3998 dprintk(2, "qla1280_isr: response packet data\n");
3999 qla1280_dump_buffer(2, (char *)pkt,
4000 RESPONSE_ENTRY_SIZE);
4003 if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
4004 dprintk(2, "status: Cmd %p, handle %i\n",
4005 ha->outstanding_cmds[pkt->handle]->cmd,
4007 if (pkt->entry_type == STATUS_TYPE)
4008 qla1280_status_entry(ha, pkt, done_q);
4010 qla1280_error_entry(ha, pkt, done_q);
4011 /* Adjust ring index. */
4012 ha->rsp_ring_index++;
4013 if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
4014 ha->rsp_ring_index = 0;
4015 ha->response_ring_ptr = ha->response_ring;
4017 ha->response_ring_ptr++;
4018 WRT_REG_WORD(®->mailbox5, ha->rsp_ring_index);
4023 LEAVE("qla1280_isr");
4028 * Processes asynchronous reset.
4031 * ha = adapter block pointer.
4034 qla1280_rst_aen(struct scsi_qla_host *ha)
4038 ENTER("qla1280_rst_aen");
4040 if (ha->flags.online && !ha->flags.reset_active &&
4041 !ha->flags.abort_isp_active) {
4042 ha->flags.reset_active = 1;
4043 while (ha->flags.reset_marker) {
4044 /* Issue marker command. */
4045 ha->flags.reset_marker = 0;
4046 for (bus = 0; bus < ha->ports &&
4047 !ha->flags.reset_marker; bus++) {
4048 if (ha->bus_settings[bus].reset_marker) {
4049 ha->bus_settings[bus].reset_marker = 0;
4050 qla1280_marker(ha, bus, 0, 0,
4057 LEAVE("qla1280_rst_aen");
4061 #if LINUX_VERSION_CODE < 0x020500
4066 qla1280_get_target_options(struct scsi_cmnd *cmd, struct scsi_qla_host *ha)
4068 unsigned char *result;
4070 int bus, target, lun;
4072 bus = SCSI_BUS_32(cmd);
4073 target = SCSI_TCN_32(cmd);
4074 lun = SCSI_LUN_32(cmd);
4077 * Make sure to not touch anything if someone is using the
4080 if (cmd->use_sg || (CMD_RESULT(cmd) >> 16) != DID_OK || lun)
4083 result = cmd->request_buffer;
4086 n->bus[bus].target[target].parameter.f.enable_wide = 0;
4087 n->bus[bus].target[target].parameter.f.enable_sync = 0;
4088 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
4090 if (result[7] & 0x60)
4091 n->bus[bus].target[target].parameter.f.enable_wide = 1;
4092 if (result[7] & 0x10)
4093 n->bus[bus].target[target].parameter.f.enable_sync = 1;
4094 if ((result[2] >= 3) && (result[4] + 5 > 56) &&
4096 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
4098 dprintk(2, "get_target_options(): wide %i, sync %i, ppr %i\n",
4099 n->bus[bus].target[target].parameter.f.enable_wide,
4100 n->bus[bus].target[target].parameter.f.enable_sync,
4101 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr);
4106 * qla1280_status_entry
4107 * Processes received ISP status entry.
4110 * ha = adapter block pointer.
4111 * pkt = entry pointer.
4112 * done_q = done queue.
4115 qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
4116 struct list_head *done_q)
4118 unsigned int bus, target, lun;
4121 struct scsi_cmnd *cmd;
4122 uint32_t handle = le32_to_cpu(pkt->handle);
4123 uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
4124 uint16_t comp_status = le16_to_cpu(pkt->comp_status);
4126 ENTER("qla1280_status_entry");
4128 /* Validate handle. */
4129 if (handle < MAX_OUTSTANDING_COMMANDS)
4130 sp = ha->outstanding_cmds[handle];
4135 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
4139 /* Free outstanding command slot. */
4140 ha->outstanding_cmds[handle] = NULL;
4144 /* Generate LU queue on cntrl, target, LUN */
4145 bus = SCSI_BUS_32(cmd);
4146 target = SCSI_TCN_32(cmd);
4147 lun = SCSI_LUN_32(cmd);
4149 if (comp_status || scsi_status) {
4150 dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
4151 "0x%x, handle = 0x%x\n", comp_status,
4152 scsi_status, handle);
4156 if (scsi_status & SS_BUSY_CONDITION &&
4157 scsi_status != SS_RESERVE_CONFLICT) {
4159 DID_BUS_BUSY << 16 | (scsi_status & 0xff);
4162 /* Save ISP completion status */
4163 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
4165 if (scsi_status & SS_CHECK_CONDITION) {
4166 if (comp_status != CS_ARS_FAILED) {
4167 uint16_t req_sense_length =
4168 le16_to_cpu(pkt->req_sense_length);
4169 if (req_sense_length < CMD_SNSLEN(cmd))
4170 sense_sz = req_sense_length;
4173 * scsi_cmnd->sense_buffer is
4174 * 64 bytes, why only copy 63?
4175 * This looks wrong! /Jes
4177 sense_sz = CMD_SNSLEN(cmd) - 1;
4179 memcpy(cmd->sense_buffer,
4180 &pkt->req_sense_data, sense_sz);
4183 memset(cmd->sense_buffer + sense_sz, 0,
4184 sizeof(cmd->sense_buffer) - sense_sz);
4186 dprintk(2, "qla1280_status_entry: Check "
4187 "condition Sense data, b %i, t %i, "
4188 "l %i\n", bus, target, lun);
4190 qla1280_dump_buffer(2,
4191 (char *)cmd->sense_buffer,
4196 /* Place command on done queue. */
4197 list_add_tail(&sp->list, done_q);
4199 LEAVE("qla1280_status_entry");
4203 * qla1280_error_entry
4204 * Processes error entry.
4207 * ha = adapter block pointer.
4208 * pkt = entry pointer.
4209 * done_q = done queue.
4212 qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
4213 struct list_head *done_q)
4216 uint32_t handle = le32_to_cpu(pkt->handle);
4218 ENTER("qla1280_error_entry");
4220 if (pkt->entry_status & BIT_3)
4221 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
4222 else if (pkt->entry_status & BIT_2)
4223 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
4224 else if (pkt->entry_status & BIT_1)
4225 dprintk(2, "qla1280_error_entry: FULL flag error\n");
4227 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
4229 /* Validate handle. */
4230 if (handle < MAX_OUTSTANDING_COMMANDS)
4231 sp = ha->outstanding_cmds[handle];
4236 /* Free outstanding command slot. */
4237 ha->outstanding_cmds[handle] = NULL;
4239 /* Bad payload or header */
4240 if (pkt->entry_status & (BIT_3 + BIT_2)) {
4241 /* Bad payload or header, set error status. */
4242 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
4243 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
4244 } else if (pkt->entry_status & BIT_1) { /* FULL flag */
4245 CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
4247 /* Set error status. */
4248 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
4251 /* Place command on done queue. */
4252 list_add_tail(&sp->list, done_q);
4254 #ifdef QLA_64BIT_PTR
4255 else if (pkt->entry_type == COMMAND_A64_TYPE) {
4256 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
4260 LEAVE("qla1280_error_entry");
4265 * Resets ISP and aborts all outstanding commands.
4268 * ha = adapter block pointer.
4274 qla1280_abort_isp(struct scsi_qla_host *ha)
4276 struct device_reg __iomem *reg = ha->iobase;
4282 ENTER("qla1280_abort_isp");
4284 if (ha->flags.abort_isp_active || !ha->flags.online)
4287 ha->flags.abort_isp_active = 1;
4289 /* Disable ISP interrupts. */
4290 qla1280_disable_intrs(ha);
4291 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
4292 RD_REG_WORD(®->id_l);
4294 printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
4296 /* Dequeue all commands in outstanding command list. */
4297 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
4298 struct scsi_cmnd *cmd;
4299 sp = ha->outstanding_cmds[cnt];
4303 CMD_RESULT(cmd) = DID_RESET << 16;
4306 ha->outstanding_cmds[cnt] = NULL;
4308 (*cmd->scsi_done)(cmd);
4314 status = qla1280_load_firmware(ha);
4318 /* Setup adapter based on NVRAM parameters. */
4319 qla1280_nvram_config (ha);
4321 status = qla1280_init_rings(ha);
4325 /* Issue SCSI reset. */
4326 for (bus = 0; bus < ha->ports; bus++)
4327 qla1280_bus_reset(ha, bus);
4329 ha->flags.abort_isp_active = 0;
4333 "qla1280: ISP error recovery failed, board disabled");
4334 qla1280_reset_adapter(ha);
4335 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
4338 LEAVE("qla1280_abort_isp");
4344 * qla1280_debounce_register
4345 * Debounce register.
4348 * port = register address.
4354 qla1280_debounce_register(volatile u16 __iomem * addr)
4359 ret = RD_REG_WORD(addr);
4360 ret2 = RD_REG_WORD(addr);
4367 ret = RD_REG_WORD(addr);
4368 ret2 = RD_REG_WORD(addr);
4369 } while (ret != ret2);
4375 /************************************************************************
4376 * qla1280_check_for_dead_scsi_bus *
4378 * This routine checks for a dead SCSI bus *
4379 ************************************************************************/
4380 #define SET_SXP_BANK 0x0100
4381 #define SCSI_PHASE_INVALID 0x87FF
4383 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
4385 uint16_t config_reg, scsi_control;
4386 struct device_reg __iomem *reg = ha->iobase;
4388 if (ha->bus_settings[bus].scsi_bus_dead) {
4389 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
4390 config_reg = RD_REG_WORD(®->cfg_1);
4391 WRT_REG_WORD(®->cfg_1, SET_SXP_BANK);
4392 scsi_control = RD_REG_WORD(®->scsiControlPins);
4393 WRT_REG_WORD(®->cfg_1, config_reg);
4394 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
4396 if (scsi_control == SCSI_PHASE_INVALID) {
4397 ha->bus_settings[bus].scsi_bus_dead = 1;
4399 CMD_RESULT(cp) = DID_NO_CONNECT << 16;
4400 CMD_HANDLE(cp) = INVALID_HANDLE;
4401 /* ha->actthreads--; */
4403 (*(cp)->scsi_done)(cp);
4405 return 1; /* bus is dead */
4407 ha->bus_settings[bus].scsi_bus_dead = 0;
4408 ha->bus_settings[bus].failed_reset_count = 0;
4411 return 0; /* bus is not dead */
4415 qla1280_get_target_parameters(struct scsi_qla_host *ha,
4416 struct scsi_device *device)
4418 uint16_t mb[MAILBOX_REGISTER_COUNT];
4419 int bus, target, lun;
4421 bus = device->channel;
4422 target = device->id;
4426 mb[0] = MBC_GET_TARGET_PARAMETERS;
4427 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
4429 qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
4432 printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
4435 printk(" Sync: period %d, offset %d",
4436 (mb[3] & 0xff), (mb[3] >> 8));
4439 if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
4444 if (DEV_SIMPLE_TAGS(device))
4445 printk(", Tagged queuing: depth %d", device->queue_depth);
4452 __qla1280_dump_buffer(char *b, int size)
4457 printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
4458 "Bh Ch Dh Eh Fh\n");
4459 printk(KERN_DEBUG "---------------------------------------------"
4460 "------------------\n");
4462 for (cnt = 0; cnt < size;) {
4465 printk("0x%02x", c);
4476 /**************************************************************************
4477 * ql1280_print_scsi_cmd
4479 **************************************************************************/
4481 __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
4483 struct scsi_qla_host *ha;
4484 struct Scsi_Host *host = CMD_HOST(cmd);
4486 /* struct scatterlist *sg; */
4489 ha = (struct scsi_qla_host *)host->hostdata;
4491 sp = (struct srb *)CMD_SP(cmd);
4492 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
4493 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
4494 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
4497 for (i = 0; i < cmd->cmd_len; i++) {
4498 printk("0x%02x ", cmd->cmnd[i]);
4500 printk(" seg_cnt =%d\n", cmd->use_sg);
4501 printk(" request buffer=0x%p, request buffer len=0x%x\n",
4502 cmd->request_buffer, cmd->request_bufflen);
4505 sg = (struct scatterlist *) cmd->request_buffer;
4506 printk(" SG buffer: \n");
4507 qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
4509 printk(" tag=%d, transfersize=0x%x \n",
4510 cmd->tag, cmd->transfersize);
4511 printk(" Pid=%li, SP=0x%p\n", cmd->pid, CMD_SP(cmd));
4512 printk(" underflow size = 0x%x, direction=0x%x\n",
4513 cmd->underflow, cmd->sc_data_direction);
4516 /**************************************************************************
4517 * ql1280_dump_device
4519 **************************************************************************/
4521 ql1280_dump_device(struct scsi_qla_host *ha)
4524 struct scsi_cmnd *cp;
4528 printk(KERN_DEBUG "Outstanding Commands on controller:\n");
4530 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
4531 if ((sp = ha->outstanding_cmds[i]) == NULL)
4533 if ((cp = sp->cmd) == NULL)
4535 qla1280_print_scsi_cmd(1, cp);
4550 struct setup_tokens {
4555 static struct setup_tokens setup_token[] __initdata =
4557 { "nvram", TOKEN_NVRAM },
4558 { "sync", TOKEN_SYNC },
4559 { "wide", TOKEN_WIDE },
4560 { "ppr", TOKEN_PPR },
4561 { "verbose", TOKEN_VERBOSE },
4562 { "debug", TOKEN_DEBUG },
4566 /**************************************************************************
4569 * Handle boot parameters. This really needs to be changed so one
4570 * can specify per adapter parameters.
4571 **************************************************************************/
4573 qla1280_setup(char *s)
4581 while (cp && (ptr = strchr(cp, ':'))) {
4583 if (!strcmp(ptr, "yes")) {
4586 } else if (!strcmp(ptr, "no")) {
4590 val = simple_strtoul(ptr, &ptr, 0);
4592 switch ((toke = qla1280_get_token(cp))) {
4595 driver_setup.no_nvram = 1;
4599 driver_setup.no_sync = 1;
4600 else if (val != 0x10000)
4601 driver_setup.sync_mask = val;
4605 driver_setup.no_wide = 1;
4606 else if (val != 0x10000)
4607 driver_setup.wide_mask = val;
4611 driver_setup.no_ppr = 1;
4612 else if (val != 0x10000)
4613 driver_setup.ppr_mask = val;
4616 qla1280_verbose = val;
4619 printk(KERN_INFO "qla1280: unknown boot option %s\n",
4623 cp = strchr(ptr, ';');
4635 qla1280_get_token(char *str)
4641 len = sizeof(setup_token)/sizeof(struct setup_tokens);
4643 sep = strchr(str, ':');
4646 for (i = 0; i < len; i++){
4648 if (!strncmp(setup_token[i].token, str, (sep - str))) {
4649 ret = setup_token[i].val;
4658 #if LINUX_VERSION_CODE >= 0x020600
4659 static struct scsi_host_template qla1280_driver_template = {
4660 .module = THIS_MODULE,
4661 .proc_name = "qla1280",
4662 .name = "Qlogic ISP 1280/12160",
4663 .info = qla1280_info,
4664 .slave_configure = qla1280_slave_configure,
4665 .queuecommand = qla1280_queuecommand,
4666 .eh_abort_handler = qla1280_eh_abort,
4667 .eh_device_reset_handler= qla1280_eh_device_reset,
4668 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4669 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4670 .bios_param = qla1280_biosparam,
4671 .proc_info = qla1280_proc_info,
4672 .can_queue = 0xfffff,
4674 .sg_tablesize = SG_ALL,
4676 .use_clustering = ENABLE_CLUSTERING,
4679 static Scsi_Host_Template qla1280_driver_template = {
4680 .proc_name = "qla1280",
4681 .name = "Qlogic ISP 1280/12160",
4682 .detect = qla1280_detect,
4683 .release = qla1280_release,
4684 .info = qla1280_info,
4685 .queuecommand = qla1280_queuecommand,
4686 .eh_abort_handler = qla1280_eh_abort,
4687 .eh_device_reset_handler= qla1280_eh_device_reset,
4688 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4689 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4690 .bios_param = qla1280_biosparam_old,
4691 .proc_info = qla1280_proc_info_old,
4692 .can_queue = 0xfffff,
4694 .sg_tablesize = SG_ALL,
4696 .use_clustering = ENABLE_CLUSTERING,
4697 .use_new_eh_code = 1,
4701 static int __devinit
4702 qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4704 int devnum = id->driver_data;
4705 struct qla_boards *bdp = &ql1280_board_tbl[devnum];
4706 struct Scsi_Host *host;
4707 struct scsi_qla_host *ha;
4708 int error = -ENODEV;
4710 /* Bypass all AMI SUBSYS VENDOR IDs */
4711 if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
4713 "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
4717 printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
4718 bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
4720 if (pci_enable_device(pdev)) {
4722 "qla1280: Failed to enabled pci device, aborting.\n");
4726 pci_set_master(pdev);
4729 host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
4732 "qla1280: Failed to register host, aborting.\n");
4733 goto error_disable_device;
4736 ha = (struct scsi_qla_host *)host->hostdata;
4737 memset(ha, 0, sizeof(struct scsi_qla_host));
4740 ha->devnum = devnum; /* specifies microcode load address */
4742 #ifdef QLA_64BIT_PTR
4743 if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) {
4744 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4745 printk(KERN_WARNING "scsi(%li): Unable to set a "
4746 " suitable DMA mask - aboring\n", ha->host_no);
4748 goto error_free_irq;
4751 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4754 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4755 printk(KERN_WARNING "scsi(%li): Unable to set a "
4756 " suitable DMA mask - aboring\n", ha->host_no);
4758 goto error_free_irq;
4762 ha->request_ring = pci_alloc_consistent(ha->pdev,
4763 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4765 if (!ha->request_ring) {
4766 printk(KERN_INFO "qla1280: Failed to get request memory\n");
4767 goto error_put_host;
4770 ha->response_ring = pci_alloc_consistent(ha->pdev,
4771 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4773 if (!ha->response_ring) {
4774 printk(KERN_INFO "qla1280: Failed to get response memory\n");
4775 goto error_free_request_ring;
4778 ha->ports = bdp->numPorts;
4781 ha->host_no = host->host_no;
4783 host->irq = pdev->irq;
4784 host->max_channel = bdp->numPorts - 1;
4785 host->max_lun = MAX_LUNS - 1;
4786 host->max_id = MAX_TARGETS;
4787 host->max_sectors = 1024;
4788 host->unique_id = host->host_no;
4790 #if LINUX_VERSION_CODE < 0x020545
4791 host->select_queue_depths = qla1280_select_queue_depth;
4796 #if MEMORY_MAPPED_IO
4797 ha->mmpbase = ioremap(pci_resource_start(ha->pdev, 1),
4798 pci_resource_len(ha->pdev, 1));
4800 printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
4801 goto error_free_response_ring;
4804 host->base = (unsigned long)ha->mmpbase;
4805 ha->iobase = (struct device_reg __iomem *)ha->mmpbase;
4807 host->io_port = pci_resource_start(ha->pdev, 0);
4808 if (!request_region(host->io_port, 0xff, "qla1280")) {
4809 printk(KERN_INFO "qla1280: Failed to reserve i/o region "
4810 "0x%04lx-0x%04lx - already in use\n",
4811 host->io_port, host->io_port + 0xff);
4812 goto error_free_response_ring;
4815 ha->iobase = (struct device_reg *)host->io_port;
4818 INIT_LIST_HEAD(&ha->done_q);
4820 /* Disable ISP interrupts. */
4821 qla1280_disable_intrs(ha);
4823 if (request_irq(pdev->irq, qla1280_intr_handler, SA_SHIRQ,
4825 printk("qla1280 : Failed to reserve interrupt %d already "
4826 "in use\n", pdev->irq);
4827 goto error_release_region;
4830 /* load the F/W, read paramaters, and init the H/W */
4831 if (qla1280_initialize_adapter(ha)) {
4832 printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
4833 goto error_free_irq;
4836 /* set our host ID (need to do something about our two IDs) */
4837 host->this_id = ha->bus_settings[0].id;
4839 pci_set_drvdata(pdev, host);
4841 #if LINUX_VERSION_CODE >= 0x020600
4842 error = scsi_add_host(host, &pdev->dev);
4844 goto error_disable_adapter;
4845 scsi_scan_host(host);
4847 scsi_set_pci_device(host, pdev);
4852 #if LINUX_VERSION_CODE >= 0x020600
4853 error_disable_adapter:
4854 WRT_REG_WORD(&ha->iobase->ictrl, 0);
4857 free_irq(pdev->irq, ha);
4858 error_release_region:
4859 #if MEMORY_MAPPED_IO
4860 iounmap(ha->mmpbase);
4862 release_region(host->io_port, 0xff);
4864 error_free_response_ring:
4865 pci_free_consistent(ha->pdev,
4866 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4867 ha->response_ring, ha->response_dma);
4868 error_free_request_ring:
4869 pci_free_consistent(ha->pdev,
4870 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4871 ha->request_ring, ha->request_dma);
4873 scsi_host_put(host);
4874 error_disable_device:
4875 pci_disable_device(pdev);
4881 static void __devexit
4882 qla1280_remove_one(struct pci_dev *pdev)
4884 struct Scsi_Host *host = pci_get_drvdata(pdev);
4885 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
4887 #if LINUX_VERSION_CODE >= 0x020600
4888 scsi_remove_host(host);
4891 WRT_REG_WORD(&ha->iobase->ictrl, 0);
4893 free_irq(pdev->irq, ha);
4895 #if MEMORY_MAPPED_IO
4896 iounmap(ha->mmpbase);
4898 release_region(host->io_port, 0xff);
4901 pci_free_consistent(ha->pdev,
4902 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4903 ha->request_ring, ha->request_dma);
4904 pci_free_consistent(ha->pdev,
4905 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4906 ha->response_ring, ha->response_dma);
4908 pci_disable_device(pdev);
4910 scsi_host_put(host);
4913 #if LINUX_VERSION_CODE >= 0x020600
4914 static struct pci_driver qla1280_pci_driver = {
4916 .id_table = qla1280_pci_tbl,
4917 .probe = qla1280_probe_one,
4918 .remove = __devexit_p(qla1280_remove_one),
4924 if (sizeof(struct srb) > sizeof(struct scsi_pointer)) {
4926 "qla1280: struct srb too big, aborting\n");
4932 * If we are called as a module, the qla1280 pointer may not be null
4933 * and it would point to our bootup string, just like on the lilo
4934 * command line. IF not NULL, then process this config string with
4938 * To add options at boot time add a line to your lilo.conf file like:
4939 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
4940 * which will result in the first four devices on the first two
4941 * controllers being set to a tagged queue depth of 32.
4944 qla1280_setup(qla1280);
4947 return pci_module_init(&qla1280_pci_driver);
4953 pci_unregister_driver(&qla1280_pci_driver);
4956 module_init(qla1280_init);
4957 module_exit(qla1280_exit);
4960 # define driver_template qla1280_driver_template
4961 # include "scsi_module.c"
4964 MODULE_AUTHOR("Qlogic & Jes Sorensen");
4965 MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
4966 MODULE_LICENSE("GPL");
4967 MODULE_VERSION(QLA1280_VERSION);
4970 * Overrides for Emacs so that we almost follow Linus's tabbing style.
4971 * Emacs will notice this stuff at the end of the file and automatically
4972 * adjust the settings for this buffer only. This must remain at the end
4974 * ---------------------------------------------------------------------------