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.27"
21 /*****************************************************************************
23 Rev 3.27, February 10, 2009, Michael Reed
24 - General code cleanup.
25 - Improve error recovery.
26 Rev 3.26, January 16, 2006 Jes Sorensen
27 - Ditch all < 2.6 support
28 Rev 3.25.1, February 10, 2005 Christoph Hellwig
29 - use pci_map_single to map non-S/G requests
30 - remove qla1280_proc_info
31 Rev 3.25, September 28, 2004, Christoph Hellwig
32 - add support for ISP1020/1040
33 - don't include "scsi.h" anymore for 2.6.x
34 Rev 3.24.4 June 7, 2004 Christoph Hellwig
35 - restructure firmware loading, cleanup initialization code
36 - prepare support for ISP1020/1040 chips
37 Rev 3.24.3 January 19, 2004, Jes Sorensen
38 - Handle PCI DMA mask settings correctly
39 - Correct order of error handling in probe_one, free_irq should not
40 be called if request_irq failed
41 Rev 3.24.2 January 19, 2004, James Bottomley & Andrew Vasquez
42 - Big endian fixes (James)
43 - Remove bogus IOCB content on zero data transfer commands (Andrew)
44 Rev 3.24.1 January 5, 2004, Jes Sorensen
45 - Initialize completion queue to avoid OOPS on probe
46 - Handle interrupts during mailbox testing
47 Rev 3.24 November 17, 2003, Christoph Hellwig
48 - use struct list_head for completion queue
49 - avoid old Scsi_FOO typedefs
50 - cleanup 2.4 compat glue a bit
51 - use <scsi/scsi_*.h> headers on 2.6 instead of "scsi.h"
52 - make initialization for memory mapped vs port I/O more similar
53 - remove broken pci config space manipulation
55 - this is an almost perfect 2.6 scsi driver now! ;)
56 Rev 3.23.39 December 17, 2003, Jes Sorensen
57 - Delete completion queue from srb if mailbox command failed to
58 to avoid qla1280_done completeting qla1280_error_action's
60 - Reduce arguments for qla1280_done
61 Rev 3.23.38 October 18, 2003, Christoph Hellwig
62 - Convert to new-style hotplugable driver for 2.6
63 - Fix missing scsi_unregister/scsi_host_put on HBA removal
64 - Kill some more cruft
65 Rev 3.23.37 October 1, 2003, Jes Sorensen
66 - Make MMIO depend on CONFIG_X86_VISWS instead of yet another
68 - Clean up locking in probe path
69 Rev 3.23.36 October 1, 2003, Christoph Hellwig
70 - queuecommand only ever receives new commands - clear flags
71 - Reintegrate lost fixes from Linux 2.5
72 Rev 3.23.35 August 14, 2003, Jes Sorensen
74 Rev 3.23.34 July 23, 2003, Jes Sorensen
75 - Remove pointless TRUE/FALSE macros
76 - Clean up vchan handling
77 Rev 3.23.33 July 3, 2003, Jes Sorensen
78 - Don't define register access macros before define determining MMIO.
79 This just happend to work out on ia64 but not elsewhere.
80 - Don't try and read from the card while it is in reset as
81 it won't respond and causes an MCA
82 Rev 3.23.32 June 23, 2003, Jes Sorensen
83 - Basic support for boot time arguments
84 Rev 3.23.31 June 8, 2003, Jes Sorensen
85 - Reduce boot time messages
86 Rev 3.23.30 June 6, 2003, Jes Sorensen
87 - Do not enable sync/wide/ppr before it has been determined
88 that the target device actually supports it
89 - Enable DMA arbitration for multi channel controllers
90 Rev 3.23.29 June 3, 2003, Jes Sorensen
92 Rev 3.23.28 June 3, 2003, Jes Sorensen
93 - Eliminate duplicate marker commands on bus resets
94 - Handle outstanding commands appropriately on bus/device resets
95 Rev 3.23.27 May 28, 2003, Jes Sorensen
96 - Remove bogus input queue code, let the Linux SCSI layer do the work
97 - Clean up NVRAM handling, only read it once from the card
98 - Add a number of missing default nvram parameters
99 Rev 3.23.26 Beta May 28, 2003, Jes Sorensen
100 - Use completion queue for mailbox commands instead of busy wait
101 Rev 3.23.25 Beta May 27, 2003, James Bottomley
102 - Migrate to use new error handling code
103 Rev 3.23.24 Beta May 21, 2003, James Bottomley
105 - Cleanup data direction code
106 Rev 3.23.23 Beta May 12, 2003, Jes Sorensen
107 - Switch to using MMIO instead of PIO
108 Rev 3.23.22 Beta April 15, 2003, Jes Sorensen
109 - Fix PCI parity problem with 12160 during reset.
110 Rev 3.23.21 Beta April 14, 2003, Jes Sorensen
111 - Use pci_map_page()/pci_unmap_page() instead of map_single version.
112 Rev 3.23.20 Beta April 9, 2003, Jes Sorensen
113 - Remove < 2.4.x support
114 - Introduce HOST_LOCK to make the spin lock changes portable.
115 - Remove a bunch of idiotic and unnecessary typedef's
116 - Kill all leftovers of target-mode support which never worked anyway
117 Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
118 - Do qla1280_pci_config() before calling request_irq() and
120 - Use pci_dma_hi32() to handle upper word of DMA addresses instead
122 - Hand correct arguments to free_irq() in case of failure
123 Rev 3.23.18 Beta April 11, 2002, Jes Sorensen
124 - Run source through Lindent and clean up the output
125 Rev 3.23.17 Beta April 11, 2002, Jes Sorensen
126 - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32
127 Rev 3.23.16 Beta March 19, 2002, Jes Sorensen
128 - Rely on mailbox commands generating interrupts - do not
129 run qla1280_isr() from ql1280_mailbox_command()
130 - Remove device_reg_t
131 - Integrate ql12160_set_target_parameters() with 1280 version
132 - Make qla1280_setup() non static
133 - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request
134 sent to the card - this command pauses the firmware!!!
135 Rev 3.23.15 Beta March 19, 2002, Jes Sorensen
136 - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions
137 - Remove a pile of pointless and confusing (srb_t **) and
138 (scsi_lu_t *) typecasts
139 - Explicit mark that we do not use the new error handling (for now)
140 - Remove scsi_qla_host_t and use 'struct' instead
141 - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled,
142 pci_64bit_slot flags which weren't used for anything anyway
143 - Grab host->host_lock while calling qla1280_isr() from abort()
144 - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we
145 do not need to save/restore flags in the interrupt handler
146 - Enable interrupts early (before any mailbox access) in preparation
147 for cleaning up the mailbox handling
148 Rev 3.23.14 Beta March 14, 2002, Jes Sorensen
149 - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace
150 it with proper use of dprintk().
151 - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take
152 a debug level argument to determine if data is to be printed
153 - Add KERN_* info to printk()
154 Rev 3.23.13 Beta March 14, 2002, Jes Sorensen
155 - Significant cosmetic cleanups
156 - Change debug code to use dprintk() and remove #if mess
157 Rev 3.23.12 Beta March 13, 2002, Jes Sorensen
158 - More cosmetic cleanups, fix places treating return as function
159 - use cpu_relax() in qla1280_debounce_register()
160 Rev 3.23.11 Beta March 13, 2002, Jes Sorensen
161 - Make it compile under 2.5.5
162 Rev 3.23.10 Beta October 1, 2001, Jes Sorensen
163 - Do no typecast short * to long * in QL1280BoardTbl, this
164 broke miserably on big endian boxes
165 Rev 3.23.9 Beta September 30, 2001, Jes Sorensen
166 - Remove pre 2.2 hack for checking for reentrance in interrupt handler
167 - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32
168 unsigned int to match the types from struct scsi_cmnd
169 Rev 3.23.8 Beta September 29, 2001, Jes Sorensen
170 - Remove bogus timer_t typedef from qla1280.h
171 - Remove obsolete pre 2.2 PCI setup code, use proper #define's
172 for PCI_ values, call pci_set_master()
173 - Fix memleak of qla1280_buffer on module unload
174 - Only compile module parsing code #ifdef MODULE - should be
175 changed to use individual MODULE_PARM's later
176 - Remove dummy_buffer that was never modified nor printed
177 - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove
178 #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls
179 - Remove \r from print statements, this is Linux, not DOS
180 - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK}
182 - Remove C++ compile hack in header file as Linux driver are not
183 supposed to be compiled as C++
184 - Kill MS_64BITS macro as it makes the code more readable
185 - Remove unnecessary flags.in_interrupts bit
186 Rev 3.23.7 Beta August 20, 2001, Jes Sorensen
187 - Dont' check for set flags on q->q_flag one by one in qla1280_next()
188 - Check whether the interrupt was generated by the QLA1280 before
190 - qla1280_status_entry(): Only zero out part of sense_buffer that
191 is not being copied into
192 - Remove more superflouous typecasts
193 - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy()
194 Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel
195 - Don't walk the entire list in qla1280_putq_t() just to directly
196 grab the pointer to the last element afterwards
197 Rev 3.23.5 Beta August 9, 2001, Jes Sorensen
198 - Don't use IRQF_DISABLED, it's use is deprecated for this kinda driver
199 Rev 3.23.4 Beta August 8, 2001, Jes Sorensen
200 - Set dev->max_sectors to 1024
201 Rev 3.23.3 Beta August 6, 2001, Jes Sorensen
202 - Provide compat macros for pci_enable_device(), pci_find_subsys()
203 and scsi_set_pci_device()
204 - Call scsi_set_pci_device() for all devices
205 - Reduce size of kernel version dependent device probe code
206 - Move duplicate probe/init code to separate function
207 - Handle error if qla1280_mem_alloc() fails
208 - Kill OFFSET() macro and use Linux's PCI definitions instead
209 - Kill private structure defining PCI config space (struct config_reg)
210 - Only allocate I/O port region if not in MMIO mode
211 - Remove duplicate (unused) sanity check of sife of srb_t
212 Rev 3.23.2 Beta August 6, 2001, Jes Sorensen
213 - Change home-brew memset() implementations to use memset()
214 - Remove all references to COMTRACE() - accessing a PC's COM2 serial
215 port directly is not legal under Linux.
216 Rev 3.23.1 Beta April 24, 2001, Jes Sorensen
217 - Remove pre 2.2 kernel support
218 - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat)
219 - Fix MMIO access to use readl/writel instead of directly
220 dereferencing pointers
221 - Nuke MSDOS debugging code
222 - Change true/false data types to int from uint8_t
223 - Use int for counters instead of uint8_t etc.
224 - Clean up size & byte order conversion macro usage
225 Rev 3.23 Beta January 11, 2001 BN Qlogic
226 - Added check of device_id when handling non
227 QLA12160s during detect().
228 Rev 3.22 Beta January 5, 2001 BN Qlogic
229 - Changed queue_task() to schedule_task()
230 for kernels 2.4.0 and higher.
231 Note: 2.4.0-testxx kernels released prior to
232 the actual 2.4.0 kernel release on January 2001
233 will get compile/link errors with schedule_task().
234 Please update your kernel to released 2.4.0 level,
235 or comment lines in this file flagged with 3.22
236 to resolve compile/link error of schedule_task().
237 - Added -DCONFIG_SMP in addition to -D__SMP__
238 in Makefile for 2.4.0 builds of driver as module.
239 Rev 3.21 Beta January 4, 2001 BN Qlogic
240 - Changed criteria of 64/32 Bit mode of HBA
241 operation according to BITS_PER_LONG rather
242 than HBA's NVRAM setting of >4Gig memory bit;
243 so that the HBA auto-configures without the need
244 to setup each system individually.
245 Rev 3.20 Beta December 5, 2000 BN Qlogic
246 - Added priority handling to IA-64 onboard SCSI
247 ISP12160 chip for kernels greater than 2.3.18.
248 - Added irqrestore for qla1280_intr_handler.
249 - Enabled /proc/scsi/qla1280 interface.
250 - Clear /proc/scsi/qla1280 counters in detect().
251 Rev 3.19 Beta October 13, 2000 BN Qlogic
252 - Declare driver_template for new kernel
253 (2.4.0 and greater) scsi initialization scheme.
254 - Update /proc/scsi entry for 2.3.18 kernels and
256 Rev 3.18 Beta October 10, 2000 BN Qlogic
257 - Changed scan order of adapters to map
258 the QLA12160 followed by the QLA1280.
259 Rev 3.17 Beta September 18, 2000 BN Qlogic
260 - Removed warnings for 32 bit 2.4.x compiles
261 - Corrected declared size for request and response
262 DMA addresses that are kept in each ha
263 Rev. 3.16 Beta August 25, 2000 BN Qlogic
264 - Corrected 64 bit addressing issue on IA-64
265 where the upper 32 bits were not properly
266 passed to the RISC engine.
267 Rev. 3.15 Beta August 22, 2000 BN Qlogic
268 - Modified qla1280_setup_chip to properly load
269 ISP firmware for greater that 4 Gig memory on IA-64
270 Rev. 3.14 Beta August 16, 2000 BN Qlogic
271 - Added setting of dma_mask to full 64 bit
272 if flags.enable_64bit_addressing is set in NVRAM
273 Rev. 3.13 Beta August 16, 2000 BN Qlogic
274 - Use new PCI DMA mapping APIs for 2.4.x kernel
275 Rev. 3.12 July 18, 2000 Redhat & BN Qlogic
276 - Added check of pci_enable_device to detect() for 2.3.x
277 - Use pci_resource_start() instead of
278 pdev->resource[0].start in detect() for 2.3.x
279 - Updated driver version
280 Rev. 3.11 July 14, 2000 BN Qlogic
281 - Updated SCSI Firmware to following versions:
284 - Updated driver version to 3.11
285 Rev. 3.10 June 23, 2000 BN Qlogic
286 - Added filtering of AMI SubSys Vendor ID devices
288 - DEBUG_QLA1280 undefined and new version BN Qlogic
289 Rev. 3.08b May 9, 2000 MD Dell
290 - Added logic to check against AMI subsystem vendor ID
291 Rev. 3.08 May 4, 2000 DG Qlogic
292 - Added logic to check for PCI subsystem ID.
293 Rev. 3.07 Apr 24, 2000 DG & BN Qlogic
294 - Updated SCSI Firmware to following versions:
297 Rev. 3.06 Apr 12, 2000 DG & BN Qlogic
298 - Internal revision; not released
299 Rev. 3.05 Mar 28, 2000 DG & BN Qlogic
300 - Edit correction for virt_to_bus and PROC.
301 Rev. 3.04 Mar 28, 2000 DG & BN Qlogic
302 - Merge changes from ia64 port.
303 Rev. 3.03 Mar 28, 2000 BN Qlogic
304 - Increase version to reflect new code drop with compile fix
305 of issue with inclusion of linux/spinlock for 2.3 kernels
306 Rev. 3.02 Mar 15, 2000 BN Qlogic
307 - Merge qla1280_proc_info from 2.10 code base
308 Rev. 3.01 Feb 10, 2000 BN Qlogic
309 - Corrected code to compile on a 2.2.x kernel.
310 Rev. 3.00 Jan 17, 2000 DG Qlogic
311 - Added 64-bit support.
312 Rev. 2.07 Nov 9, 1999 DG Qlogic
313 - Added new routine to set target parameters for ISP12160.
314 Rev. 2.06 Sept 10, 1999 DG Qlogic
315 - Added support for ISP12160 Ultra 3 chip.
316 Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
317 - Modified code to remove errors generated when compiling with
318 Cygnus IA64 Compiler.
319 - Changed conversion of pointers to unsigned longs instead of integers.
320 - Changed type of I/O port variables from uint32_t to unsigned long.
321 - Modified OFFSET macro to work with 64-bit as well as 32-bit.
322 - Changed sprintf and printk format specifiers for pointers to %p.
323 - Changed some int to long type casts where needed in sprintf & printk.
324 - Added l modifiers to sprintf and printk format specifiers for longs.
325 - Removed unused local variables.
326 Rev. 1.20 June 8, 1999 DG, Qlogic
327 Changes to support RedHat release 6.0 (kernel 2.2.5).
328 - Added SCSI exclusive access lock (io_request_lock) when accessing
330 - Added changes for the new LINUX interface template. Some new error
331 handling routines have been added to the template, but for now we
332 will use the old ones.
333 - Initial Beta Release.
334 *****************************************************************************/
337 #include <linux/module.h>
339 #include <linux/types.h>
340 #include <linux/string.h>
341 #include <linux/errno.h>
342 #include <linux/kernel.h>
343 #include <linux/ioport.h>
344 #include <linux/delay.h>
345 #include <linux/timer.h>
346 #include <linux/pci.h>
347 #include <linux/proc_fs.h>
348 #include <linux/stat.h>
349 #include <linux/slab.h>
350 #include <linux/pci_ids.h>
351 #include <linux/interrupt.h>
352 #include <linux/init.h>
353 #include <linux/dma-mapping.h>
354 #include <linux/firmware.h>
358 #include <asm/byteorder.h>
359 #include <asm/processor.h>
360 #include <asm/types.h>
361 #include <asm/system.h>
363 #include <scsi/scsi.h>
364 #include <scsi/scsi_cmnd.h>
365 #include <scsi/scsi_device.h>
366 #include <scsi/scsi_host.h>
367 #include <scsi/scsi_tcq.h>
369 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
370 #include <asm/sn/io.h>
375 * Compile time Options:
376 * 0 - Disable and 1 - Enable
378 #define DEBUG_QLA1280_INTR 0
379 #define DEBUG_PRINT_NVRAM 0
380 #define DEBUG_QLA1280 0
383 * The SGI VISWS is broken and doesn't support MMIO ;-(
385 #ifdef CONFIG_X86_VISWS
386 #define MEMORY_MAPPED_IO 0
388 #define MEMORY_MAPPED_IO 1
393 #ifndef BITS_PER_LONG
394 #error "BITS_PER_LONG not defined!"
396 #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
397 #define QLA_64BIT_PTR 1
401 #define pci_dma_hi32(a) ((a >> 16) >> 16)
403 #define pci_dma_hi32(a) 0
405 #define pci_dma_lo32(a) (a & 0xffffffff)
407 #define NVRAM_DELAY() udelay(500) /* 2 microseconds */
409 #if defined(__ia64__) && !defined(ia64_platform_is)
410 #define ia64_platform_is(foo) (!strcmp(x, platform_name))
414 #define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
415 #define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
416 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
417 #define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
418 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
421 static int qla1280_probe_one(struct pci_dev
*, const struct pci_device_id
*);
422 static void qla1280_remove_one(struct pci_dev
*);
425 * QLogic Driver Support Function Prototypes.
427 static void qla1280_done(struct scsi_qla_host
*);
428 static int qla1280_get_token(char *);
429 static int qla1280_setup(char *s
) __init
;
432 * QLogic ISP1280 Hardware Support Function Prototypes.
434 static int qla1280_load_firmware(struct scsi_qla_host
*);
435 static int qla1280_init_rings(struct scsi_qla_host
*);
436 static int qla1280_nvram_config(struct scsi_qla_host
*);
437 static int qla1280_mailbox_command(struct scsi_qla_host
*,
438 uint8_t, uint16_t *);
439 static int qla1280_bus_reset(struct scsi_qla_host
*, int);
440 static int qla1280_device_reset(struct scsi_qla_host
*, int, int);
441 static int qla1280_abort_command(struct scsi_qla_host
*, struct srb
*, int);
442 static int qla1280_abort_isp(struct scsi_qla_host
*);
444 static int qla1280_64bit_start_scsi(struct scsi_qla_host
*, struct srb
*);
446 static int qla1280_32bit_start_scsi(struct scsi_qla_host
*, struct srb
*);
448 static void qla1280_nv_write(struct scsi_qla_host
*, uint16_t);
449 static void qla1280_poll(struct scsi_qla_host
*);
450 static void qla1280_reset_adapter(struct scsi_qla_host
*);
451 static void qla1280_marker(struct scsi_qla_host
*, int, int, int, u8
);
452 static void qla1280_isp_cmd(struct scsi_qla_host
*);
453 static void qla1280_isr(struct scsi_qla_host
*, struct list_head
*);
454 static void qla1280_rst_aen(struct scsi_qla_host
*);
455 static void qla1280_status_entry(struct scsi_qla_host
*, struct response
*,
457 static void qla1280_error_entry(struct scsi_qla_host
*, struct response
*,
459 static uint16_t qla1280_get_nvram_word(struct scsi_qla_host
*, uint32_t);
460 static uint16_t qla1280_nvram_request(struct scsi_qla_host
*, uint32_t);
461 static uint16_t qla1280_debounce_register(volatile uint16_t __iomem
*);
462 static request_t
*qla1280_req_pkt(struct scsi_qla_host
*);
463 static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host
*,
465 static void qla1280_get_target_parameters(struct scsi_qla_host
*,
466 struct scsi_device
*);
467 static int qla1280_set_target_parameters(struct scsi_qla_host
*, int, int);
470 static struct qla_driver_setup driver_setup
;
473 * convert scsi data direction to request_t control flags
475 static inline uint16_t
476 qla1280_data_direction(struct scsi_cmnd
*cmnd
)
478 switch(cmnd
->sc_data_direction
) {
479 case DMA_FROM_DEVICE
:
483 case DMA_BIDIRECTIONAL
:
484 return BIT_5
| BIT_6
;
486 * We could BUG() on default here if one of the four cases aren't
487 * met, but then again if we receive something like that from the
488 * SCSI layer we have more serious problems. This shuts up GCC.
497 static void __qla1280_print_scsi_cmd(struct scsi_cmnd
* cmd
);
498 static void __qla1280_dump_buffer(char *, int);
503 * insmod needs to find the variable and make it point to something
506 static char *qla1280
;
508 /* insmod qla1280 options=verbose" */
509 module_param(qla1280
, charp
, 0);
511 __setup("qla1280=", qla1280_setup
);
516 * We use the scsi_pointer structure that's included with each scsi_command
517 * to overlay our struct srb over it. qla1280_init() checks that a srb is not
518 * bigger than a scsi_pointer.
521 #define CMD_SP(Cmnd) &Cmnd->SCp
522 #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
523 #define CMD_CDBP(Cmnd) Cmnd->cmnd
524 #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
525 #define CMD_SNSLEN(Cmnd) SCSI_SENSE_BUFFERSIZE
526 #define CMD_RESULT(Cmnd) Cmnd->result
527 #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
528 #define CMD_REQUEST(Cmnd) Cmnd->request->cmd
530 #define CMD_HOST(Cmnd) Cmnd->device->host
531 #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
532 #define SCSI_TCN_32(Cmnd) Cmnd->device->id
533 #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
536 /*****************************************/
537 /* ISP Boards supported by this driver */
538 /*****************************************/
541 unsigned char name
[9]; /* Board ID String */
542 int numPorts
; /* Number of SCSI ports */
543 char *fwname
; /* firmware name */
546 /* NOTE: the last argument in each entry is used to index ql1280_board_tbl */
547 static struct pci_device_id qla1280_pci_tbl
[] = {
548 {PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP12160
,
549 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
550 {PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP1020
,
551 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 1},
552 {PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP1080
,
553 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 2},
554 {PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP1240
,
555 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 3},
556 {PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP1280
,
557 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 4},
558 {PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP10160
,
559 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 5},
562 MODULE_DEVICE_TABLE(pci
, qla1280_pci_tbl
);
564 static struct qla_boards ql1280_board_tbl
[] = {
565 /* Name , Number of ports, FW details */
566 {"QLA12160", 2, "qlogic/12160.bin"},
567 {"QLA1040", 1, "qlogic/1040.bin"},
568 {"QLA1080", 1, "qlogic/1280.bin"},
569 {"QLA1240", 2, "qlogic/1280.bin"},
570 {"QLA1280", 2, "qlogic/1280.bin"},
571 {"QLA10160", 1, "qlogic/12160.bin"},
575 static int qla1280_verbose
= 1;
578 static int ql_debug_level
= 1;
579 #define dprintk(level, format, a...) \
580 do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
581 #define qla1280_dump_buffer(level, buf, size) \
582 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
583 #define qla1280_print_scsi_cmd(level, cmd) \
584 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
586 #define ql_debug_level 0
587 #define dprintk(level, format, a...) do{}while(0)
588 #define qla1280_dump_buffer(a, b, c) do{}while(0)
589 #define qla1280_print_scsi_cmd(a, b) do{}while(0)
592 #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
593 #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
594 #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
595 #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
598 static int qla1280_read_nvram(struct scsi_qla_host
*ha
)
605 ENTER("qla1280_read_nvram");
607 if (driver_setup
.no_nvram
)
610 printk(KERN_INFO
"scsi(%ld): Reading NVRAM\n", ha
->host_no
);
612 wptr
= (uint16_t *)&ha
->nvram
;
615 for (cnt
= 0; cnt
< 3; cnt
++) {
616 *wptr
= qla1280_get_nvram_word(ha
, cnt
);
617 chksum
+= *wptr
& 0xff;
618 chksum
+= (*wptr
>> 8) & 0xff;
622 if (nv
->id0
!= 'I' || nv
->id1
!= 'S' ||
623 nv
->id2
!= 'P' || nv
->id3
!= ' ' || nv
->version
< 1) {
624 dprintk(2, "Invalid nvram ID or version!\n");
627 for (; cnt
< sizeof(struct nvram
); cnt
++) {
628 *wptr
= qla1280_get_nvram_word(ha
, cnt
);
629 chksum
+= *wptr
& 0xff;
630 chksum
+= (*wptr
>> 8) & 0xff;
635 dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
636 " version %i\n", nv
->id0
, nv
->id1
, nv
->id2
, nv
->id3
,
641 if (!driver_setup
.no_nvram
)
642 printk(KERN_WARNING
"scsi(%ld): Unable to identify or "
643 "validate NVRAM checksum, using default "
644 "settings\n", ha
->host_no
);
649 /* The firmware interface is, um, interesting, in that the
650 * actual firmware image on the chip is little endian, thus,
651 * the process of taking that image to the CPU would end up
652 * little endian. However, the firmware interface requires it
653 * to be read a word (two bytes) at a time.
655 * The net result of this would be that the word (and
656 * doubleword) quantites in the firmware would be correct, but
657 * the bytes would be pairwise reversed. Since most of the
658 * firmware quantites are, in fact, bytes, we do an extra
659 * le16_to_cpu() in the firmware read routine.
661 * The upshot of all this is that the bytes in the firmware
662 * are in the correct places, but the 16 and 32 bit quantites
663 * are still in little endian format. We fix that up below by
664 * doing extra reverses on them */
665 nv
->isp_parameter
= cpu_to_le16(nv
->isp_parameter
);
666 nv
->firmware_feature
.w
= cpu_to_le16(nv
->firmware_feature
.w
);
667 for(i
= 0; i
< MAX_BUSES
; i
++) {
668 nv
->bus
[i
].selection_timeout
= cpu_to_le16(nv
->bus
[i
].selection_timeout
);
669 nv
->bus
[i
].max_queue_depth
= cpu_to_le16(nv
->bus
[i
].max_queue_depth
);
671 dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
672 LEAVE("qla1280_read_nvram");
677 /**************************************************************************
679 * Return a string describing the driver.
680 **************************************************************************/
682 qla1280_info(struct Scsi_Host
*host
)
684 static char qla1280_scsi_name_buffer
[125];
686 struct scsi_qla_host
*ha
;
687 struct qla_boards
*bdp
;
689 bp
= &qla1280_scsi_name_buffer
[0];
690 ha
= (struct scsi_qla_host
*)host
->hostdata
;
691 bdp
= &ql1280_board_tbl
[ha
->devnum
];
692 memset(bp
, 0, sizeof(qla1280_scsi_name_buffer
));
695 "QLogic %s PCI to SCSI Host Adapter\n"
696 " Firmware version: %2d.%02d.%02d, Driver version %s",
697 &bdp
->name
[0], ha
->fwver1
, ha
->fwver2
, ha
->fwver3
,
702 /**************************************************************************
703 * qla1280_queuecommand
704 * Queue a command to the controller.
707 * The mid-level driver tries to ensures that queuecommand never gets invoked
708 * concurrently with itself or the interrupt handler (although the
709 * interrupt handler may call this routine as part of request-completion
710 * handling). Unfortunely, it sometimes calls the scheduler in interrupt
711 * context which is a big NO! NO!.
712 **************************************************************************/
714 qla1280_queuecommand(struct scsi_cmnd
*cmd
, void (*fn
)(struct scsi_cmnd
*))
716 struct Scsi_Host
*host
= cmd
->device
->host
;
717 struct scsi_qla_host
*ha
= (struct scsi_qla_host
*)host
->hostdata
;
718 struct srb
*sp
= (struct srb
*)CMD_SP(cmd
);
725 CMD_HANDLE(cmd
) = (unsigned char *)NULL
;
727 qla1280_print_scsi_cmd(5, cmd
);
731 * Using 64 bit commands if the PCI bridge doesn't support it is a
732 * bit wasteful, however this should really only happen if one's
733 * PCI controller is completely broken, like the BCM1250. For
734 * sane hardware this is not an issue.
736 status
= qla1280_64bit_start_scsi(ha
, sp
);
738 status
= qla1280_32bit_start_scsi(ha
, sp
);
751 static void qla1280_mailbox_timeout(unsigned long __data
)
753 struct scsi_qla_host
*ha
= (struct scsi_qla_host
*)__data
;
754 struct device_reg __iomem
*reg
;
757 ha
->mailbox_out
[0] = RD_REG_WORD(®
->mailbox0
);
758 printk(KERN_ERR
"scsi(%ld): mailbox timed out, mailbox0 %04x, "
759 "ictrl %04x, istatus %04x\n", ha
->host_no
, ha
->mailbox_out
[0],
760 RD_REG_WORD(®
->ictrl
), RD_REG_WORD(®
->istatus
));
761 complete(ha
->mailbox_wait
);
765 _qla1280_wait_for_single_command(struct scsi_qla_host
*ha
, struct srb
*sp
,
766 struct completion
*wait
)
769 struct scsi_cmnd
*cmd
= sp
->cmd
;
771 spin_unlock_irq(ha
->host
->host_lock
);
772 wait_for_completion_timeout(wait
, 4*HZ
);
773 spin_lock_irq(ha
->host
->host_lock
);
775 if(CMD_HANDLE(cmd
) == COMPLETED_HANDLE
) {
777 (*cmd
->scsi_done
)(cmd
);
783 qla1280_wait_for_single_command(struct scsi_qla_host
*ha
, struct srb
*sp
)
785 DECLARE_COMPLETION_ONSTACK(wait
);
788 return _qla1280_wait_for_single_command(ha
, sp
, &wait
);
792 qla1280_wait_for_pending_commands(struct scsi_qla_host
*ha
, int bus
, int target
)
797 struct scsi_cmnd
*cmd
;
802 * Wait for all commands with the designated bus/target
803 * to be completed by the firmware
805 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
806 sp
= ha
->outstanding_cmds
[cnt
];
810 if (bus
>= 0 && SCSI_BUS_32(cmd
) != bus
)
812 if (target
>= 0 && SCSI_TCN_32(cmd
) != target
)
815 status
= qla1280_wait_for_single_command(ha
, sp
);
816 if (status
== FAILED
)
823 /**************************************************************************
824 * qla1280_error_action
825 * The function will attempt to perform a specified error action and
826 * wait for the results (or time out).
829 * cmd = Linux SCSI command packet of the command that cause the
831 * action = error action to take (see action_t)
836 **************************************************************************/
838 qla1280_error_action(struct scsi_cmnd
*cmd
, enum action action
)
840 struct scsi_qla_host
*ha
;
841 int bus
, target
, lun
;
846 int wait_for_target
= -1;
847 DECLARE_COMPLETION_ONSTACK(wait
);
849 ENTER("qla1280_error_action");
851 ha
= (struct scsi_qla_host
*)(CMD_HOST(cmd
)->hostdata
);
852 sp
= (struct srb
*)CMD_SP(cmd
);
853 bus
= SCSI_BUS_32(cmd
);
854 target
= SCSI_TCN_32(cmd
);
855 lun
= SCSI_LUN_32(cmd
);
857 dprintk(4, "error_action %i, istatus 0x%04x\n", action
,
858 RD_REG_WORD(&ha
->iobase
->istatus
));
860 dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
861 RD_REG_WORD(&ha
->iobase
->host_cmd
),
862 RD_REG_WORD(&ha
->iobase
->ictrl
), jiffies
);
865 printk(KERN_INFO
"scsi(%li): Resetting Cmnd=0x%p, "
866 "Handle=0x%p, action=0x%x\n",
867 ha
->host_no
, cmd
, CMD_HANDLE(cmd
), action
);
870 * Check to see if we have the command in the outstanding_cmds[]
871 * array. If not then it must have completed before this error
872 * action was initiated. If the error_action isn't ABORT_COMMAND
873 * then the driver must proceed with the requested action.
876 for (i
= 0; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
877 if (sp
== ha
->outstanding_cmds
[i
]) {
879 sp
->wait
= &wait
; /* we'll wait for it to complete */
884 if (found
< 0) { /* driver doesn't have command */
886 if (qla1280_verbose
) {
888 "scsi(%ld:%d:%d:%d): specified command has "
889 "already completed.\n", ha
->host_no
, bus
,
897 dprintk(1, "qla1280: RISC aborting command\n");
899 * The abort might fail due to race when the host_lock
900 * is released to issue the abort. As such, we
901 * don't bother to check the return status.
904 qla1280_abort_command(ha
, sp
, found
);
910 "scsi(%ld:%d:%d:%d): Queueing device reset "
911 "command.\n", ha
->host_no
, bus
, target
, lun
);
912 if (qla1280_device_reset(ha
, bus
, target
) == 0) {
913 /* issued device reset, set wait conditions */
915 wait_for_target
= target
;
921 printk(KERN_INFO
"qla1280(%ld:%d): Issued bus "
922 "reset.\n", ha
->host_no
, bus
);
923 if (qla1280_bus_reset(ha
, bus
) == 0) {
924 /* issued bus reset, set wait conditions */
931 if (qla1280_verbose
) {
933 "scsi(%ld): Issued ADAPTER RESET\n",
935 printk(KERN_INFO
"scsi(%ld): I/O processing will "
936 "continue automatically\n", ha
->host_no
);
938 ha
->flags
.reset_active
= 1;
940 if (qla1280_abort_isp(ha
) != 0) { /* it's dead */
944 ha
->flags
.reset_active
= 0;
948 * At this point, the host_lock has been released and retaken
949 * by the issuance of the mailbox command.
950 * Wait for the command passed in by the mid-layer if it
951 * was found by the driver. It might have been returned
952 * between eh recovery steps, hence the check of the "found"
957 result
= _qla1280_wait_for_single_command(ha
, sp
, &wait
);
959 if (action
== ABORT_COMMAND
&& result
!= SUCCESS
) {
961 "scsi(%li:%i:%i:%i): "
962 "Unable to abort command!\n",
963 ha
->host_no
, bus
, target
, lun
);
967 * If the command passed in by the mid-layer has been
968 * returned by the board, then wait for any additional
969 * commands which are supposed to complete based upon
972 * All commands are unconditionally returned during a
973 * call to qla1280_abort_isp(), ADAPTER_RESET. No need
976 if (result
== SUCCESS
&& wait_for_bus
>= 0) {
977 result
= qla1280_wait_for_pending_commands(ha
,
978 wait_for_bus
, wait_for_target
);
981 dprintk(1, "RESET returning %d\n", result
);
983 LEAVE("qla1280_error_action");
987 /**************************************************************************
989 * Abort the specified SCSI command(s).
990 **************************************************************************/
992 qla1280_eh_abort(struct scsi_cmnd
* cmd
)
996 spin_lock_irq(cmd
->device
->host
->host_lock
);
997 rc
= qla1280_error_action(cmd
, ABORT_COMMAND
);
998 spin_unlock_irq(cmd
->device
->host
->host_lock
);
1003 /**************************************************************************
1004 * qla1280_device_reset
1005 * Reset the specified SCSI device
1006 **************************************************************************/
1008 qla1280_eh_device_reset(struct scsi_cmnd
*cmd
)
1012 spin_lock_irq(cmd
->device
->host
->host_lock
);
1013 rc
= qla1280_error_action(cmd
, DEVICE_RESET
);
1014 spin_unlock_irq(cmd
->device
->host
->host_lock
);
1019 /**************************************************************************
1021 * Reset the specified bus.
1022 **************************************************************************/
1024 qla1280_eh_bus_reset(struct scsi_cmnd
*cmd
)
1028 spin_lock_irq(cmd
->device
->host
->host_lock
);
1029 rc
= qla1280_error_action(cmd
, BUS_RESET
);
1030 spin_unlock_irq(cmd
->device
->host
->host_lock
);
1035 /**************************************************************************
1036 * qla1280_adapter_reset
1037 * Reset the specified adapter (both channels)
1038 **************************************************************************/
1040 qla1280_eh_adapter_reset(struct scsi_cmnd
*cmd
)
1044 spin_lock_irq(cmd
->device
->host
->host_lock
);
1045 rc
= qla1280_error_action(cmd
, ADAPTER_RESET
);
1046 spin_unlock_irq(cmd
->device
->host
->host_lock
);
1052 qla1280_biosparam(struct scsi_device
*sdev
, struct block_device
*bdev
,
1053 sector_t capacity
, int geom
[])
1055 int heads
, sectors
, cylinders
;
1059 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
1060 if (cylinders
> 1024) {
1063 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
1064 /* if (cylinders > 1023)
1065 cylinders = 1023; */
1070 geom
[2] = cylinders
;
1076 /* disable risc and host interrupts */
1078 qla1280_disable_intrs(struct scsi_qla_host
*ha
)
1080 WRT_REG_WORD(&ha
->iobase
->ictrl
, 0);
1081 RD_REG_WORD(&ha
->iobase
->ictrl
); /* PCI Posted Write flush */
1084 /* enable risc and host interrupts */
1086 qla1280_enable_intrs(struct scsi_qla_host
*ha
)
1088 WRT_REG_WORD(&ha
->iobase
->ictrl
, (ISP_EN_INT
| ISP_EN_RISC
));
1089 RD_REG_WORD(&ha
->iobase
->ictrl
); /* PCI Posted Write flush */
1092 /**************************************************************************
1093 * qla1280_intr_handler
1094 * Handles the H/W interrupt
1095 **************************************************************************/
1097 qla1280_intr_handler(int irq
, void *dev_id
)
1099 struct scsi_qla_host
*ha
;
1100 struct device_reg __iomem
*reg
;
1104 ENTER_INTR ("qla1280_intr_handler");
1105 ha
= (struct scsi_qla_host
*)dev_id
;
1107 spin_lock(ha
->host
->host_lock
);
1112 qla1280_disable_intrs(ha
);
1114 data
= qla1280_debounce_register(®
->istatus
);
1115 /* Check for pending interrupts. */
1116 if (data
& RISC_INT
) {
1117 qla1280_isr(ha
, &ha
->done_q
);
1120 if (!list_empty(&ha
->done_q
))
1123 spin_unlock(ha
->host
->host_lock
);
1125 qla1280_enable_intrs(ha
);
1127 LEAVE_INTR("qla1280_intr_handler");
1128 return IRQ_RETVAL(handled
);
1133 qla1280_set_target_parameters(struct scsi_qla_host
*ha
, int bus
, int target
)
1136 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
1142 mr
= BIT_3
| BIT_2
| BIT_1
| BIT_0
;
1144 /* Set Target Parameters. */
1145 mb
[0] = MBC_SET_TARGET_PARAMETERS
;
1146 mb
[1] = (uint16_t)((bus
? target
| BIT_7
: target
) << 8);
1147 mb
[2] = nv
->bus
[bus
].target
[target
].parameter
.renegotiate_on_error
<< 8;
1148 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.stop_queue_on_check
<< 9;
1149 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.auto_request_sense
<< 10;
1150 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.tag_queuing
<< 11;
1151 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.enable_sync
<< 12;
1152 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.enable_wide
<< 13;
1153 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.parity_checking
<< 14;
1154 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.disconnect_allowed
<< 15;
1156 if (IS_ISP1x160(ha
)) {
1157 mb
[2] |= nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.enable_ppr
<< 5;
1158 mb
[3] = (nv
->bus
[bus
].target
[target
].flags
.flags1x160
.sync_offset
<< 8);
1159 mb
[6] = (nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.ppr_options
<< 8) |
1160 nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.ppr_bus_width
;
1163 mb
[3] = (nv
->bus
[bus
].target
[target
].flags
.flags1x80
.sync_offset
<< 8);
1165 mb
[3] |= nv
->bus
[bus
].target
[target
].sync_period
;
1167 status
= qla1280_mailbox_command(ha
, mr
, mb
);
1169 /* Set Device Queue Parameters. */
1170 for (lun
= 0; lun
< MAX_LUNS
; lun
++) {
1171 mb
[0] = MBC_SET_DEVICE_QUEUE
;
1172 mb
[1] = (uint16_t)((bus
? target
| BIT_7
: target
) << 8);
1174 mb
[2] = nv
->bus
[bus
].max_queue_depth
;
1175 mb
[3] = nv
->bus
[bus
].target
[target
].execution_throttle
;
1176 status
|= qla1280_mailbox_command(ha
, 0x0f, mb
);
1180 printk(KERN_WARNING
"scsi(%ld:%i:%i): "
1181 "qla1280_set_target_parameters() failed\n",
1182 ha
->host_no
, bus
, target
);
1187 /**************************************************************************
1188 * qla1280_slave_configure
1191 * Determines the queue depth for a given device. There are two ways
1192 * a queue depth can be obtained for a tagged queueing device. One
1193 * way is the default queue depth which is determined by whether
1194 * If it is defined, then it is used
1195 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1196 * default queue depth (dependent on the number of hardware SCBs).
1197 **************************************************************************/
1199 qla1280_slave_configure(struct scsi_device
*device
)
1201 struct scsi_qla_host
*ha
;
1202 int default_depth
= 3;
1203 int bus
= device
->channel
;
1204 int target
= device
->id
;
1207 unsigned long flags
;
1209 ha
= (struct scsi_qla_host
*)device
->host
->hostdata
;
1212 if (qla1280_check_for_dead_scsi_bus(ha
, bus
))
1215 if (device
->tagged_supported
&&
1216 (ha
->bus_settings
[bus
].qtag_enables
& (BIT_0
<< target
))) {
1217 scsi_adjust_queue_depth(device
, MSG_ORDERED_TAG
,
1218 ha
->bus_settings
[bus
].hiwat
);
1220 scsi_adjust_queue_depth(device
, 0, default_depth
);
1223 nv
->bus
[bus
].target
[target
].parameter
.enable_sync
= device
->sdtr
;
1224 nv
->bus
[bus
].target
[target
].parameter
.enable_wide
= device
->wdtr
;
1225 nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.enable_ppr
= device
->ppr
;
1227 if (driver_setup
.no_sync
||
1228 (driver_setup
.sync_mask
&&
1229 (~driver_setup
.sync_mask
& (1 << target
))))
1230 nv
->bus
[bus
].target
[target
].parameter
.enable_sync
= 0;
1231 if (driver_setup
.no_wide
||
1232 (driver_setup
.wide_mask
&&
1233 (~driver_setup
.wide_mask
& (1 << target
))))
1234 nv
->bus
[bus
].target
[target
].parameter
.enable_wide
= 0;
1235 if (IS_ISP1x160(ha
)) {
1236 if (driver_setup
.no_ppr
||
1237 (driver_setup
.ppr_mask
&&
1238 (~driver_setup
.ppr_mask
& (1 << target
))))
1239 nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.enable_ppr
= 0;
1242 spin_lock_irqsave(ha
->host
->host_lock
, flags
);
1243 if (nv
->bus
[bus
].target
[target
].parameter
.enable_sync
)
1244 status
= qla1280_set_target_parameters(ha
, bus
, target
);
1245 qla1280_get_target_parameters(ha
, device
);
1246 spin_unlock_irqrestore(ha
->host
->host_lock
, flags
);
1253 * Process completed commands.
1256 * ha = adapter block pointer.
1259 qla1280_done(struct scsi_qla_host
*ha
)
1262 struct list_head
*done_q
;
1263 int bus
, target
, lun
;
1264 struct scsi_cmnd
*cmd
;
1266 ENTER("qla1280_done");
1268 done_q
= &ha
->done_q
;
1270 while (!list_empty(done_q
)) {
1271 sp
= list_entry(done_q
->next
, struct srb
, list
);
1273 list_del(&sp
->list
);
1276 bus
= SCSI_BUS_32(cmd
);
1277 target
= SCSI_TCN_32(cmd
);
1278 lun
= SCSI_LUN_32(cmd
);
1280 switch ((CMD_RESULT(cmd
) >> 16)) {
1282 /* Issue marker command. */
1283 if (!ha
->flags
.abort_isp_active
)
1284 qla1280_marker(ha
, bus
, target
, 0, MK_SYNC_ID
);
1287 sp
->flags
&= ~SRB_ABORT_PENDING
;
1288 sp
->flags
|= SRB_ABORTED
;
1294 /* Release memory used for this I/O */
1295 scsi_dma_unmap(cmd
);
1297 /* Call the mid-level driver interrupt handler */
1300 if (sp
->wait
== NULL
)
1301 (*(cmd
)->scsi_done
)(cmd
);
1305 LEAVE("qla1280_done");
1309 * Translates a ISP error to a Linux SCSI error
1312 qla1280_return_status(struct response
* sts
, struct scsi_cmnd
*cp
)
1314 int host_status
= DID_ERROR
;
1315 uint16_t comp_status
= le16_to_cpu(sts
->comp_status
);
1316 uint16_t state_flags
= le16_to_cpu(sts
->state_flags
);
1317 uint32_t residual_length
= le32_to_cpu(sts
->residual_length
);
1318 uint16_t scsi_status
= le16_to_cpu(sts
->scsi_status
);
1319 #if DEBUG_QLA1280_INTR
1320 static char *reason
[] = {
1332 #endif /* DEBUG_QLA1280_INTR */
1334 ENTER("qla1280_return_status");
1336 #if DEBUG_QLA1280_INTR
1338 dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
1343 switch (comp_status
) {
1345 host_status
= DID_OK
;
1349 if (!(state_flags
& SF_GOT_BUS
))
1350 host_status
= DID_NO_CONNECT
;
1351 else if (!(state_flags
& SF_GOT_TARGET
))
1352 host_status
= DID_BAD_TARGET
;
1353 else if (!(state_flags
& SF_SENT_CDB
))
1354 host_status
= DID_ERROR
;
1355 else if (!(state_flags
& SF_TRANSFERRED_DATA
))
1356 host_status
= DID_ERROR
;
1357 else if (!(state_flags
& SF_GOT_STATUS
))
1358 host_status
= DID_ERROR
;
1359 else if (!(state_flags
& SF_GOT_SENSE
))
1360 host_status
= DID_ERROR
;
1364 host_status
= DID_RESET
;
1368 host_status
= DID_ABORT
;
1372 host_status
= DID_TIME_OUT
;
1375 case CS_DATA_OVERRUN
:
1376 dprintk(2, "Data overrun 0x%x\n", residual_length
);
1377 dprintk(2, "qla1280_return_status: response packet data\n");
1378 qla1280_dump_buffer(2, (char *)sts
, RESPONSE_ENTRY_SIZE
);
1379 host_status
= DID_ERROR
;
1382 case CS_DATA_UNDERRUN
:
1383 if ((scsi_bufflen(cp
) - residual_length
) <
1386 "scsi: Underflow detected - retrying "
1388 host_status
= DID_ERROR
;
1390 scsi_set_resid(cp
, residual_length
);
1391 host_status
= DID_OK
;
1396 host_status
= DID_ERROR
;
1400 #if DEBUG_QLA1280_INTR
1401 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
1402 reason
[host_status
], scsi_status
);
1405 LEAVE("qla1280_return_status");
1407 return (scsi_status
& 0xff) | (host_status
<< 16);
1410 /****************************************************************************/
1411 /* QLogic ISP1280 Hardware Support Functions. */
1412 /****************************************************************************/
1415 * qla1280_initialize_adapter
1419 * ha = adapter block pointer.
1424 static int __devinit
1425 qla1280_initialize_adapter(struct scsi_qla_host
*ha
)
1427 struct device_reg __iomem
*reg
;
1430 unsigned long flags
;
1432 ENTER("qla1280_initialize_adapter");
1434 /* Clear adapter flags. */
1435 ha
->flags
.online
= 0;
1436 ha
->flags
.disable_host_adapter
= 0;
1437 ha
->flags
.reset_active
= 0;
1438 ha
->flags
.abort_isp_active
= 0;
1440 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1441 if (ia64_platform_is("sn2")) {
1442 printk(KERN_INFO
"scsi(%li): Enabling SN2 PCI DMA "
1443 "dual channel lockup workaround\n", ha
->host_no
);
1444 ha
->flags
.use_pci_vchannel
= 1;
1445 driver_setup
.no_nvram
= 1;
1449 /* TODO: implement support for the 1040 nvram format */
1451 driver_setup
.no_nvram
= 1;
1453 dprintk(1, "Configure PCI space for adapter...\n");
1457 /* Insure mailbox registers are free. */
1458 WRT_REG_WORD(®
->semaphore
, 0);
1459 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
1460 WRT_REG_WORD(®
->host_cmd
, HC_CLR_HOST_INT
);
1461 RD_REG_WORD(®
->host_cmd
);
1463 if (qla1280_read_nvram(ha
)) {
1464 dprintk(2, "qla1280_initialize_adapter: failed to read "
1469 * It's necessary to grab the spin here as qla1280_mailbox_command
1470 * needs to be able to drop the lock unconditionally to wait
1473 spin_lock_irqsave(ha
->host
->host_lock
, flags
);
1475 status
= qla1280_load_firmware(ha
);
1477 printk(KERN_ERR
"scsi(%li): initialize: pci probe failed!\n",
1482 /* Setup adapter based on NVRAM parameters. */
1483 dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha
->host_no
);
1484 qla1280_nvram_config(ha
);
1486 if (ha
->flags
.disable_host_adapter
) {
1491 status
= qla1280_init_rings(ha
);
1495 /* Issue SCSI reset, if we can't reset twice then bus is dead */
1496 for (bus
= 0; bus
< ha
->ports
; bus
++) {
1497 if (!ha
->bus_settings
[bus
].disable_scsi_reset
&&
1498 qla1280_bus_reset(ha
, bus
) &&
1499 qla1280_bus_reset(ha
, bus
))
1500 ha
->bus_settings
[bus
].scsi_bus_dead
= 1;
1503 ha
->flags
.online
= 1;
1505 spin_unlock_irqrestore(ha
->host
->host_lock
, flags
);
1508 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
1510 LEAVE("qla1280_initialize_adapter");
1516 * Test chip for proper operation.
1519 * ha = adapter block pointer.
1525 qla1280_chip_diag(struct scsi_qla_host
*ha
)
1527 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
1528 struct device_reg __iomem
*reg
= ha
->iobase
;
1532 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®
->id_l
);
1534 dprintk(1, "scsi(%ld): Verifying chip\n", ha
->host_no
);
1536 /* Soft reset chip and wait for it to finish. */
1537 WRT_REG_WORD(®
->ictrl
, ISP_RESET
);
1540 * We can't do a traditional PCI write flush here by reading
1541 * back the register. The card will not respond once the reset
1542 * is in action and we end up with a machine check exception
1543 * instead. Nothing to do but wait and hope for the best.
1544 * A portable pci_write_flush(pdev) call would be very useful here.
1547 data
= qla1280_debounce_register(®
->ictrl
);
1549 * Yet another QLogic gem ;-(
1551 for (cnt
= 1000000; cnt
&& data
& ISP_RESET
; cnt
--) {
1553 data
= RD_REG_WORD(®
->ictrl
);
1559 /* Reset register cleared by chip reset. */
1560 dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
1562 WRT_REG_WORD(®
->cfg_1
, 0);
1564 /* Reset RISC and disable BIOS which
1565 allows RISC to execute out of RAM. */
1566 WRT_REG_WORD(®
->host_cmd
, HC_RESET_RISC
|
1567 HC_RELEASE_RISC
| HC_DISABLE_BIOS
);
1569 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
1570 data
= qla1280_debounce_register(®
->mailbox0
);
1573 * I *LOVE* this code!
1575 for (cnt
= 1000000; cnt
&& data
== MBS_BUSY
; cnt
--) {
1577 data
= RD_REG_WORD(®
->mailbox0
);
1583 /* Check product ID of chip */
1584 dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
1586 if (RD_REG_WORD(®
->mailbox1
) != PROD_ID_1
||
1587 (RD_REG_WORD(®
->mailbox2
) != PROD_ID_2
&&
1588 RD_REG_WORD(®
->mailbox2
) != PROD_ID_2a
) ||
1589 RD_REG_WORD(®
->mailbox3
) != PROD_ID_3
||
1590 RD_REG_WORD(®
->mailbox4
) != PROD_ID_4
) {
1591 printk(KERN_INFO
"qla1280: Wrong product ID = "
1592 "0x%x,0x%x,0x%x,0x%x\n",
1593 RD_REG_WORD(®
->mailbox1
),
1594 RD_REG_WORD(®
->mailbox2
),
1595 RD_REG_WORD(®
->mailbox3
),
1596 RD_REG_WORD(®
->mailbox4
));
1601 * Enable ints early!!!
1603 qla1280_enable_intrs(ha
);
1605 dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
1606 /* Wrap Incoming Mailboxes Test. */
1607 mb
[0] = MBC_MAILBOX_REGISTER_TEST
;
1616 status
= qla1280_mailbox_command(ha
, 0xff, mb
);
1620 if (mb
[1] != 0xAAAA || mb
[2] != 0x5555 || mb
[3] != 0xAA55 ||
1621 mb
[4] != 0x55AA || mb
[5] != 0xA5A5 || mb
[6] != 0x5A5A ||
1623 printk(KERN_INFO
"qla1280: Failed mbox check\n");
1627 dprintk(3, "qla1280_chip_diag: exiting normally\n");
1630 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
1635 qla1280_load_firmware_pio(struct scsi_qla_host
*ha
)
1637 const struct firmware
*fw
;
1638 const __le16
*fw_data
;
1639 uint16_t risc_address
, risc_code_size
;
1640 uint16_t mb
[MAILBOX_REGISTER_COUNT
], i
;
1643 spin_unlock_irq(ha
->host
->host_lock
);
1644 err
= request_firmware(&fw
, ql1280_board_tbl
[ha
->devnum
].fwname
,
1646 spin_lock_irq(ha
->host
->host_lock
);
1648 printk(KERN_ERR
"Failed to load image \"%s\" err %d\n",
1649 ql1280_board_tbl
[ha
->devnum
].fwname
, err
);
1652 if ((fw
->size
% 2) || (fw
->size
< 6)) {
1653 printk(KERN_ERR
"Bogus length %zu in image \"%s\"\n",
1654 fw
->size
, ql1280_board_tbl
[ha
->devnum
].fwname
);
1658 ha
->fwver1
= fw
->data
[0];
1659 ha
->fwver2
= fw
->data
[1];
1660 ha
->fwver3
= fw
->data
[2];
1661 fw_data
= (const __le16
*)&fw
->data
[0];
1662 ha
->fwstart
= __le16_to_cpu(fw_data
[2]);
1664 /* Load RISC code. */
1665 risc_address
= ha
->fwstart
;
1666 fw_data
= (const __le16
*)&fw
->data
[6];
1667 risc_code_size
= (fw
->size
- 6) / 2;
1669 for (i
= 0; i
< risc_code_size
; i
++) {
1670 mb
[0] = MBC_WRITE_RAM_WORD
;
1671 mb
[1] = risc_address
+ i
;
1672 mb
[2] = __le16_to_cpu(fw_data
[i
]);
1674 err
= qla1280_mailbox_command(ha
, BIT_0
| BIT_1
| BIT_2
, mb
);
1676 printk(KERN_ERR
"scsi(%li): Failed to load firmware\n",
1682 release_firmware(fw
);
1686 #define DUMP_IT_BACK 0 /* for debug of RISC loading */
1688 qla1280_load_firmware_dma(struct scsi_qla_host
*ha
)
1690 const struct firmware
*fw
;
1691 const __le16
*fw_data
;
1692 uint16_t risc_address
, risc_code_size
;
1693 uint16_t mb
[MAILBOX_REGISTER_COUNT
], cnt
;
1694 int err
= 0, num
, i
;
1699 tbuf
= pci_alloc_consistent(ha
->pdev
, 8000, &p_tbuf
);
1704 spin_unlock_irq(ha
->host
->host_lock
);
1705 err
= request_firmware(&fw
, ql1280_board_tbl
[ha
->devnum
].fwname
,
1707 spin_lock_irq(ha
->host
->host_lock
);
1709 printk(KERN_ERR
"Failed to load image \"%s\" err %d\n",
1710 ql1280_board_tbl
[ha
->devnum
].fwname
, err
);
1713 if ((fw
->size
% 2) || (fw
->size
< 6)) {
1714 printk(KERN_ERR
"Bogus length %zu in image \"%s\"\n",
1715 fw
->size
, ql1280_board_tbl
[ha
->devnum
].fwname
);
1719 ha
->fwver1
= fw
->data
[0];
1720 ha
->fwver2
= fw
->data
[1];
1721 ha
->fwver3
= fw
->data
[2];
1722 fw_data
= (const __le16
*)&fw
->data
[0];
1723 ha
->fwstart
= __le16_to_cpu(fw_data
[2]);
1725 /* Load RISC code. */
1726 risc_address
= ha
->fwstart
;
1727 fw_data
= (const __le16
*)&fw
->data
[6];
1728 risc_code_size
= (fw
->size
- 6) / 2;
1730 dprintk(1, "%s: DMA RISC code (%i) words\n",
1731 __func__
, risc_code_size
);
1734 while (risc_code_size
> 0) {
1735 int warn
__attribute__((unused
)) = 0;
1739 if (cnt
> risc_code_size
)
1740 cnt
= risc_code_size
;
1742 dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
1744 fw_data
, cnt
, num
, risc_address
);
1745 for(i
= 0; i
< cnt
; i
++)
1746 ((__le16
*)ha
->request_ring
)[i
] = fw_data
[i
];
1748 mb
[0] = MBC_LOAD_RAM
;
1749 mb
[1] = risc_address
;
1751 mb
[3] = ha
->request_dma
& 0xffff;
1752 mb
[2] = (ha
->request_dma
>> 16) & 0xffff;
1753 mb
[7] = pci_dma_hi32(ha
->request_dma
) & 0xffff;
1754 mb
[6] = pci_dma_hi32(ha
->request_dma
) >> 16;
1755 dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
1757 (void *)(long)ha
->request_dma
,
1758 mb
[6], mb
[7], mb
[2], mb
[3]);
1759 err
= qla1280_mailbox_command(ha
, BIT_4
| BIT_3
| BIT_2
|
1762 printk(KERN_ERR
"scsi(%li): Failed to load partial "
1763 "segment of f\n", ha
->host_no
);
1768 mb
[0] = MBC_DUMP_RAM
;
1769 mb
[1] = risc_address
;
1771 mb
[3] = p_tbuf
& 0xffff;
1772 mb
[2] = (p_tbuf
>> 16) & 0xffff;
1773 mb
[7] = pci_dma_hi32(p_tbuf
) & 0xffff;
1774 mb
[6] = pci_dma_hi32(p_tbuf
) >> 16;
1776 err
= qla1280_mailbox_command(ha
, BIT_4
| BIT_3
| BIT_2
|
1780 "Failed to dump partial segment of f/w\n");
1783 sp
= (uint8_t *)ha
->request_ring
;
1784 for (i
= 0; i
< (cnt
<< 1); i
++) {
1785 if (tbuf
[i
] != sp
[i
] && warn
++ < 10) {
1786 printk(KERN_ERR
"%s: FW compare error @ "
1787 "byte(0x%x) loop#=%x\n",
1789 printk(KERN_ERR
"%s: FWbyte=%x "
1791 __func__
, sp
[i
], tbuf
[i
]);
1796 risc_address
+= cnt
;
1797 risc_code_size
= risc_code_size
- cnt
;
1798 fw_data
= fw_data
+ cnt
;
1804 pci_free_consistent(ha
->pdev
, 8000, tbuf
, p_tbuf
);
1806 release_firmware(fw
);
1811 qla1280_start_firmware(struct scsi_qla_host
*ha
)
1813 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
1816 dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
1819 /* Verify checksum of loaded RISC code. */
1820 mb
[0] = MBC_VERIFY_CHECKSUM
;
1821 /* mb[1] = ql12_risc_code_addr01; */
1822 mb
[1] = ha
->fwstart
;
1823 err
= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, mb
);
1825 printk(KERN_ERR
"scsi(%li): RISC checksum failed.\n", ha
->host_no
);
1829 /* Start firmware execution. */
1830 dprintk(1, "%s: start firmware running.\n", __func__
);
1831 mb
[0] = MBC_EXECUTE_FIRMWARE
;
1832 mb
[1] = ha
->fwstart
;
1833 err
= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]);
1835 printk(KERN_ERR
"scsi(%li): Failed to start firmware\n",
1843 qla1280_load_firmware(struct scsi_qla_host
*ha
)
1847 err
= qla1280_chip_diag(ha
);
1851 err
= qla1280_load_firmware_pio(ha
);
1853 err
= qla1280_load_firmware_dma(ha
);
1856 err
= qla1280_start_firmware(ha
);
1865 * ha = adapter block pointer.
1866 * ha->request_ring = request ring virtual address
1867 * ha->response_ring = response ring virtual address
1868 * ha->request_dma = request ring physical address
1869 * ha->response_dma = response ring physical address
1875 qla1280_init_rings(struct scsi_qla_host
*ha
)
1877 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
1880 ENTER("qla1280_init_rings");
1882 /* Clear outstanding commands array. */
1883 memset(ha
->outstanding_cmds
, 0,
1884 sizeof(struct srb
*) * MAX_OUTSTANDING_COMMANDS
);
1886 /* Initialize request queue. */
1887 ha
->request_ring_ptr
= ha
->request_ring
;
1888 ha
->req_ring_index
= 0;
1889 ha
->req_q_cnt
= REQUEST_ENTRY_CNT
;
1890 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
1891 mb
[0] = MBC_INIT_REQUEST_QUEUE_A64
;
1892 mb
[1] = REQUEST_ENTRY_CNT
;
1893 mb
[3] = ha
->request_dma
& 0xffff;
1894 mb
[2] = (ha
->request_dma
>> 16) & 0xffff;
1896 mb
[7] = pci_dma_hi32(ha
->request_dma
) & 0xffff;
1897 mb
[6] = pci_dma_hi32(ha
->request_dma
) >> 16;
1898 if (!(status
= qla1280_mailbox_command(ha
, BIT_7
| BIT_6
| BIT_4
|
1899 BIT_3
| BIT_2
| BIT_1
| BIT_0
,
1901 /* Initialize response queue. */
1902 ha
->response_ring_ptr
= ha
->response_ring
;
1903 ha
->rsp_ring_index
= 0;
1904 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
1905 mb
[0] = MBC_INIT_RESPONSE_QUEUE_A64
;
1906 mb
[1] = RESPONSE_ENTRY_CNT
;
1907 mb
[3] = ha
->response_dma
& 0xffff;
1908 mb
[2] = (ha
->response_dma
>> 16) & 0xffff;
1910 mb
[7] = pci_dma_hi32(ha
->response_dma
) & 0xffff;
1911 mb
[6] = pci_dma_hi32(ha
->response_dma
) >> 16;
1912 status
= qla1280_mailbox_command(ha
, BIT_7
| BIT_6
| BIT_5
|
1913 BIT_3
| BIT_2
| BIT_1
| BIT_0
,
1918 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
1920 LEAVE("qla1280_init_rings");
1925 qla1280_print_settings(struct nvram
*nv
)
1927 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
1928 nv
->bus
[0].config_1
.initiator_id
);
1929 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
1930 nv
->bus
[1].config_1
.initiator_id
);
1932 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
1933 nv
->bus
[0].bus_reset_delay
);
1934 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
1935 nv
->bus
[1].bus_reset_delay
);
1937 dprintk(1, "qla1280 : retry count[0]=%d\n", nv
->bus
[0].retry_count
);
1938 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv
->bus
[0].retry_delay
);
1939 dprintk(1, "qla1280 : retry count[1]=%d\n", nv
->bus
[1].retry_count
);
1940 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv
->bus
[1].retry_delay
);
1942 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
1943 nv
->bus
[0].config_2
.async_data_setup_time
);
1944 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
1945 nv
->bus
[1].config_2
.async_data_setup_time
);
1947 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
1948 nv
->bus
[0].config_2
.req_ack_active_negation
);
1949 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
1950 nv
->bus
[1].config_2
.req_ack_active_negation
);
1952 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
1953 nv
->bus
[0].config_2
.data_line_active_negation
);
1954 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
1955 nv
->bus
[1].config_2
.data_line_active_negation
);
1957 dprintk(1, "qla1280 : disable loading risc code=%d\n",
1958 nv
->cntr_flags_1
.disable_loading_risc_code
);
1960 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
1961 nv
->cntr_flags_1
.enable_64bit_addressing
);
1963 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
1964 nv
->bus
[0].selection_timeout
);
1965 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
1966 nv
->bus
[1].selection_timeout
);
1968 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
1969 nv
->bus
[0].max_queue_depth
);
1970 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
1971 nv
->bus
[1].max_queue_depth
);
1975 qla1280_set_target_defaults(struct scsi_qla_host
*ha
, int bus
, int target
)
1977 struct nvram
*nv
= &ha
->nvram
;
1979 nv
->bus
[bus
].target
[target
].parameter
.renegotiate_on_error
= 1;
1980 nv
->bus
[bus
].target
[target
].parameter
.auto_request_sense
= 1;
1981 nv
->bus
[bus
].target
[target
].parameter
.tag_queuing
= 1;
1982 nv
->bus
[bus
].target
[target
].parameter
.enable_sync
= 1;
1983 #if 1 /* Some SCSI Processors do not seem to like this */
1984 nv
->bus
[bus
].target
[target
].parameter
.enable_wide
= 1;
1986 nv
->bus
[bus
].target
[target
].execution_throttle
=
1987 nv
->bus
[bus
].max_queue_depth
- 1;
1988 nv
->bus
[bus
].target
[target
].parameter
.parity_checking
= 1;
1989 nv
->bus
[bus
].target
[target
].parameter
.disconnect_allowed
= 1;
1991 if (IS_ISP1x160(ha
)) {
1992 nv
->bus
[bus
].target
[target
].flags
.flags1x160
.device_enable
= 1;
1993 nv
->bus
[bus
].target
[target
].flags
.flags1x160
.sync_offset
= 0x0e;
1994 nv
->bus
[bus
].target
[target
].sync_period
= 9;
1995 nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.enable_ppr
= 1;
1996 nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.ppr_options
= 2;
1997 nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.ppr_bus_width
= 1;
1999 nv
->bus
[bus
].target
[target
].flags
.flags1x80
.device_enable
= 1;
2000 nv
->bus
[bus
].target
[target
].flags
.flags1x80
.sync_offset
= 12;
2001 nv
->bus
[bus
].target
[target
].sync_period
= 10;
2006 qla1280_set_defaults(struct scsi_qla_host
*ha
)
2008 struct nvram
*nv
= &ha
->nvram
;
2011 dprintk(1, "Using defaults for NVRAM: \n");
2012 memset(nv
, 0, sizeof(struct nvram
));
2014 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
2015 nv
->firmware_feature
.f
.enable_fast_posting
= 1;
2016 nv
->firmware_feature
.f
.disable_synchronous_backoff
= 1;
2017 nv
->termination
.scsi_bus_0_control
= 3;
2018 nv
->termination
.scsi_bus_1_control
= 3;
2019 nv
->termination
.auto_term_support
= 1;
2022 * Set default FIFO magic - What appropriate values would be here
2023 * is unknown. This is what I have found testing with 12160s.
2025 * Now, I would love the magic decoder ring for this one, the
2026 * header file provided by QLogic seems to be bogus or incomplete
2029 nv
->isp_config
.burst_enable
= 1;
2031 nv
->isp_config
.fifo_threshold
|= 3;
2033 nv
->isp_config
.fifo_threshold
|= 4;
2035 if (IS_ISP1x160(ha
))
2036 nv
->isp_parameter
= 0x01; /* fast memory enable */
2038 for (bus
= 0; bus
< MAX_BUSES
; bus
++) {
2039 nv
->bus
[bus
].config_1
.initiator_id
= 7;
2040 nv
->bus
[bus
].config_2
.req_ack_active_negation
= 1;
2041 nv
->bus
[bus
].config_2
.data_line_active_negation
= 1;
2042 nv
->bus
[bus
].selection_timeout
= 250;
2043 nv
->bus
[bus
].max_queue_depth
= 32;
2045 if (IS_ISP1040(ha
)) {
2046 nv
->bus
[bus
].bus_reset_delay
= 3;
2047 nv
->bus
[bus
].config_2
.async_data_setup_time
= 6;
2048 nv
->bus
[bus
].retry_delay
= 1;
2050 nv
->bus
[bus
].bus_reset_delay
= 5;
2051 nv
->bus
[bus
].config_2
.async_data_setup_time
= 8;
2054 for (target
= 0; target
< MAX_TARGETS
; target
++)
2055 qla1280_set_target_defaults(ha
, bus
, target
);
2060 qla1280_config_target(struct scsi_qla_host
*ha
, int bus
, int target
)
2062 struct nvram
*nv
= &ha
->nvram
;
2063 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2067 /* Set Target Parameters. */
2068 mb
[0] = MBC_SET_TARGET_PARAMETERS
;
2069 mb
[1] = (uint16_t)((bus
? target
| BIT_7
: target
) << 8);
2072 * Do not enable sync and ppr for the initial INQUIRY run. We
2073 * enable this later if we determine the target actually
2076 mb
[2] = (TP_RENEGOTIATE
| TP_AUTO_REQUEST_SENSE
| TP_TAGGED_QUEUE
2077 | TP_WIDE
| TP_PARITY
| TP_DISCONNECT
);
2079 if (IS_ISP1x160(ha
))
2080 mb
[3] = nv
->bus
[bus
].target
[target
].flags
.flags1x160
.sync_offset
<< 8;
2082 mb
[3] = nv
->bus
[bus
].target
[target
].flags
.flags1x80
.sync_offset
<< 8;
2083 mb
[3] |= nv
->bus
[bus
].target
[target
].sync_period
;
2084 status
= qla1280_mailbox_command(ha
, 0x0f, mb
);
2086 /* Save Tag queuing enable flag. */
2087 flag
= (BIT_0
<< target
);
2088 if (nv
->bus
[bus
].target
[target
].parameter
.tag_queuing
)
2089 ha
->bus_settings
[bus
].qtag_enables
|= flag
;
2091 /* Save Device enable flag. */
2092 if (IS_ISP1x160(ha
)) {
2093 if (nv
->bus
[bus
].target
[target
].flags
.flags1x160
.device_enable
)
2094 ha
->bus_settings
[bus
].device_enables
|= flag
;
2095 ha
->bus_settings
[bus
].lun_disables
|= 0;
2097 if (nv
->bus
[bus
].target
[target
].flags
.flags1x80
.device_enable
)
2098 ha
->bus_settings
[bus
].device_enables
|= flag
;
2099 /* Save LUN disable flag. */
2100 if (nv
->bus
[bus
].target
[target
].flags
.flags1x80
.lun_disable
)
2101 ha
->bus_settings
[bus
].lun_disables
|= flag
;
2104 /* Set Device Queue Parameters. */
2105 for (lun
= 0; lun
< MAX_LUNS
; lun
++) {
2106 mb
[0] = MBC_SET_DEVICE_QUEUE
;
2107 mb
[1] = (uint16_t)((bus
? target
| BIT_7
: target
) << 8);
2109 mb
[2] = nv
->bus
[bus
].max_queue_depth
;
2110 mb
[3] = nv
->bus
[bus
].target
[target
].execution_throttle
;
2111 status
|= qla1280_mailbox_command(ha
, 0x0f, mb
);
2118 qla1280_config_bus(struct scsi_qla_host
*ha
, int bus
)
2120 struct nvram
*nv
= &ha
->nvram
;
2121 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2124 /* SCSI Reset Disable. */
2125 ha
->bus_settings
[bus
].disable_scsi_reset
=
2126 nv
->bus
[bus
].config_1
.scsi_reset_disable
;
2129 ha
->bus_settings
[bus
].id
= nv
->bus
[bus
].config_1
.initiator_id
;
2130 mb
[0] = MBC_SET_INITIATOR_ID
;
2131 mb
[1] = bus
? ha
->bus_settings
[bus
].id
| BIT_7
:
2132 ha
->bus_settings
[bus
].id
;
2133 status
= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]);
2136 ha
->bus_settings
[bus
].bus_reset_delay
=
2137 nv
->bus
[bus
].bus_reset_delay
;
2139 /* Command queue depth per device. */
2140 ha
->bus_settings
[bus
].hiwat
= nv
->bus
[bus
].max_queue_depth
- 1;
2142 /* Set target parameters. */
2143 for (target
= 0; target
< MAX_TARGETS
; target
++)
2144 status
|= qla1280_config_target(ha
, bus
, target
);
2150 qla1280_nvram_config(struct scsi_qla_host
*ha
)
2152 struct device_reg __iomem
*reg
= ha
->iobase
;
2153 struct nvram
*nv
= &ha
->nvram
;
2154 int bus
, target
, status
= 0;
2155 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2157 ENTER("qla1280_nvram_config");
2159 if (ha
->nvram_valid
) {
2160 /* Always force AUTO sense for LINUX SCSI */
2161 for (bus
= 0; bus
< MAX_BUSES
; bus
++)
2162 for (target
= 0; target
< MAX_TARGETS
; target
++) {
2163 nv
->bus
[bus
].target
[target
].parameter
.
2164 auto_request_sense
= 1;
2167 qla1280_set_defaults(ha
);
2170 qla1280_print_settings(nv
);
2172 /* Disable RISC load of firmware. */
2173 ha
->flags
.disable_risc_code_load
=
2174 nv
->cntr_flags_1
.disable_loading_risc_code
;
2176 if (IS_ISP1040(ha
)) {
2177 uint16_t hwrev
, cfg1
, cdma_conf
, ddma_conf
;
2179 hwrev
= RD_REG_WORD(®
->cfg_0
) & ISP_CFG0_HWMSK
;
2181 cfg1
= RD_REG_WORD(®
->cfg_1
) & ~(BIT_4
| BIT_5
| BIT_6
);
2182 cdma_conf
= RD_REG_WORD(®
->cdma_cfg
);
2183 ddma_conf
= RD_REG_WORD(®
->ddma_cfg
);
2185 /* Busted fifo, says mjacob. */
2186 if (hwrev
!= ISP_CFG0_1040A
)
2187 cfg1
|= nv
->isp_config
.fifo_threshold
<< 4;
2189 cfg1
|= nv
->isp_config
.burst_enable
<< 2;
2190 WRT_REG_WORD(®
->cfg_1
, cfg1
);
2192 WRT_REG_WORD(®
->cdma_cfg
, cdma_conf
| CDMA_CONF_BENAB
);
2193 WRT_REG_WORD(®
->ddma_cfg
, cdma_conf
| DDMA_CONF_BENAB
);
2195 uint16_t cfg1
, term
;
2197 /* Set ISP hardware DMA burst */
2198 cfg1
= nv
->isp_config
.fifo_threshold
<< 4;
2199 cfg1
|= nv
->isp_config
.burst_enable
<< 2;
2200 /* Enable DMA arbitration on dual channel controllers */
2203 WRT_REG_WORD(®
->cfg_1
, cfg1
);
2205 /* Set SCSI termination. */
2206 WRT_REG_WORD(®
->gpio_enable
,
2207 BIT_7
| BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2208 term
= nv
->termination
.scsi_bus_1_control
;
2209 term
|= nv
->termination
.scsi_bus_0_control
<< 2;
2210 term
|= nv
->termination
.auto_term_support
<< 7;
2211 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2212 WRT_REG_WORD(®
->gpio_data
, term
);
2214 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2216 /* ISP parameter word. */
2217 mb
[0] = MBC_SET_SYSTEM_PARAMETER
;
2218 mb
[1] = nv
->isp_parameter
;
2219 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]);
2221 if (IS_ISP1x40(ha
)) {
2222 /* clock rate - for qla1240 and older, only */
2223 mb
[0] = MBC_SET_CLOCK_RATE
;
2225 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, mb
);
2228 /* Firmware feature word. */
2229 mb
[0] = MBC_SET_FIRMWARE_FEATURES
;
2230 mb
[1] = nv
->firmware_feature
.f
.enable_fast_posting
;
2231 mb
[1] |= nv
->firmware_feature
.f
.report_lvd_bus_transition
<< 1;
2232 mb
[1] |= nv
->firmware_feature
.f
.disable_synchronous_backoff
<< 5;
2233 #if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
2234 if (ia64_platform_is("sn2")) {
2235 printk(KERN_INFO
"scsi(%li): Enabling SN2 PCI DMA "
2236 "workaround\n", ha
->host_no
);
2237 mb
[1] |= nv
->firmware_feature
.f
.unused_9
<< 9; /* XXX */
2240 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, mb
);
2242 /* Retry count and delay. */
2243 mb
[0] = MBC_SET_RETRY_COUNT
;
2244 mb
[1] = nv
->bus
[0].retry_count
;
2245 mb
[2] = nv
->bus
[0].retry_delay
;
2246 mb
[6] = nv
->bus
[1].retry_count
;
2247 mb
[7] = nv
->bus
[1].retry_delay
;
2248 status
|= qla1280_mailbox_command(ha
, BIT_7
| BIT_6
| BIT_2
|
2249 BIT_1
| BIT_0
, &mb
[0]);
2251 /* ASYNC data setup time. */
2252 mb
[0] = MBC_SET_ASYNC_DATA_SETUP
;
2253 mb
[1] = nv
->bus
[0].config_2
.async_data_setup_time
;
2254 mb
[2] = nv
->bus
[1].config_2
.async_data_setup_time
;
2255 status
|= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
2257 /* Active negation states. */
2258 mb
[0] = MBC_SET_ACTIVE_NEGATION
;
2260 if (nv
->bus
[0].config_2
.req_ack_active_negation
)
2262 if (nv
->bus
[0].config_2
.data_line_active_negation
)
2265 if (nv
->bus
[1].config_2
.req_ack_active_negation
)
2267 if (nv
->bus
[1].config_2
.data_line_active_negation
)
2269 status
|= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, mb
);
2271 mb
[0] = MBC_SET_DATA_OVERRUN_RECOVERY
;
2272 mb
[1] = 2; /* Reset SCSI bus and return all outstanding IO */
2273 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, mb
);
2276 mb
[0] = MBC_SET_PCI_CONTROL
;
2277 mb
[1] = BIT_1
; /* Data DMA Channel Burst Enable */
2278 mb
[2] = BIT_1
; /* Command DMA Channel Burst Enable */
2279 status
|= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, mb
);
2281 mb
[0] = MBC_SET_TAG_AGE_LIMIT
;
2283 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, mb
);
2285 /* Selection timeout. */
2286 mb
[0] = MBC_SET_SELECTION_TIMEOUT
;
2287 mb
[1] = nv
->bus
[0].selection_timeout
;
2288 mb
[2] = nv
->bus
[1].selection_timeout
;
2289 status
|= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, mb
);
2291 for (bus
= 0; bus
< ha
->ports
; bus
++)
2292 status
|= qla1280_config_bus(ha
, bus
);
2295 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
2297 LEAVE("qla1280_nvram_config");
2302 * Get NVRAM data word
2303 * Calculates word position in NVRAM and calls request routine to
2304 * get the word from NVRAM.
2307 * ha = adapter block pointer.
2308 * address = NVRAM word address.
2314 qla1280_get_nvram_word(struct scsi_qla_host
*ha
, uint32_t address
)
2319 nv_cmd
= address
<< 16;
2320 nv_cmd
|= NV_READ_OP
;
2322 data
= le16_to_cpu(qla1280_nvram_request(ha
, nv_cmd
));
2324 dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
2332 * Sends read command to NVRAM and gets data from NVRAM.
2335 * ha = adapter block pointer.
2336 * nv_cmd = Bit 26 = start bit
2337 * Bit 25, 24 = opcode
2338 * Bit 23-16 = address
2339 * Bit 15-0 = write data
2345 qla1280_nvram_request(struct scsi_qla_host
*ha
, uint32_t nv_cmd
)
2347 struct device_reg __iomem
*reg
= ha
->iobase
;
2352 /* Send command to NVRAM. */
2355 for (cnt
= 0; cnt
< 11; cnt
++) {
2356 if (nv_cmd
& BIT_31
)
2357 qla1280_nv_write(ha
, NV_DATA_OUT
);
2359 qla1280_nv_write(ha
, 0);
2363 /* Read data from NVRAM. */
2365 for (cnt
= 0; cnt
< 16; cnt
++) {
2366 WRT_REG_WORD(®
->nvram
, (NV_SELECT
| NV_CLOCK
));
2367 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2370 reg_data
= RD_REG_WORD(®
->nvram
);
2371 if (reg_data
& NV_DATA_IN
)
2373 WRT_REG_WORD(®
->nvram
, NV_SELECT
);
2374 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2378 /* Deselect chip. */
2380 WRT_REG_WORD(®
->nvram
, NV_DESELECT
);
2381 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2388 qla1280_nv_write(struct scsi_qla_host
*ha
, uint16_t data
)
2390 struct device_reg __iomem
*reg
= ha
->iobase
;
2392 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
);
2393 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2395 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
| NV_CLOCK
);
2396 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2398 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
);
2399 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2405 * Issue mailbox command and waits for completion.
2408 * ha = adapter block pointer.
2409 * mr = mailbox registers to load.
2410 * mb = data pointer for mailbox registers.
2413 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
2419 qla1280_mailbox_command(struct scsi_qla_host
*ha
, uint8_t mr
, uint16_t *mb
)
2421 struct device_reg __iomem
*reg
= ha
->iobase
;
2424 uint16_t *optr
, *iptr
;
2425 uint16_t __iomem
*mptr
;
2427 DECLARE_COMPLETION_ONSTACK(wait
);
2428 struct timer_list timer
;
2430 ENTER("qla1280_mailbox_command");
2432 if (ha
->mailbox_wait
) {
2433 printk(KERN_ERR
"Warning mailbox wait already in use!\n");
2435 ha
->mailbox_wait
= &wait
;
2438 * We really should start out by verifying that the mailbox is
2439 * available before starting sending the command data
2441 /* Load mailbox registers. */
2442 mptr
= (uint16_t __iomem
*) ®
->mailbox0
;
2444 for (cnt
= 0; cnt
< MAILBOX_REGISTER_COUNT
; cnt
++) {
2446 WRT_REG_WORD(mptr
, (*iptr
));
2454 /* Issue set host interrupt command. */
2456 /* set up a timer just in case we're really jammed */
2458 timer
.expires
= jiffies
+ 20*HZ
;
2459 timer
.data
= (unsigned long)ha
;
2460 timer
.function
= qla1280_mailbox_timeout
;
2463 spin_unlock_irq(ha
->host
->host_lock
);
2464 WRT_REG_WORD(®
->host_cmd
, HC_SET_HOST_INT
);
2465 data
= qla1280_debounce_register(®
->istatus
);
2467 wait_for_completion(&wait
);
2468 del_timer_sync(&timer
);
2470 spin_lock_irq(ha
->host
->host_lock
);
2472 ha
->mailbox_wait
= NULL
;
2474 /* Check for mailbox command timeout. */
2475 if (ha
->mailbox_out
[0] != MBS_CMD_CMP
) {
2476 printk(KERN_WARNING
"qla1280_mailbox_command: Command failed, "
2477 "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
2479 mb
[0], ha
->mailbox_out
[0], RD_REG_WORD(®
->istatus
));
2480 printk(KERN_WARNING
"m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
2481 RD_REG_WORD(®
->mailbox0
), RD_REG_WORD(®
->mailbox1
),
2482 RD_REG_WORD(®
->mailbox2
), RD_REG_WORD(®
->mailbox3
));
2483 printk(KERN_WARNING
"m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
2484 RD_REG_WORD(®
->mailbox4
), RD_REG_WORD(®
->mailbox5
),
2485 RD_REG_WORD(®
->mailbox6
), RD_REG_WORD(®
->mailbox7
));
2489 /* Load return mailbox registers. */
2491 iptr
= (uint16_t *) &ha
->mailbox_out
[0];
2492 mr
= MAILBOX_REGISTER_COUNT
;
2493 memcpy(optr
, iptr
, MAILBOX_REGISTER_COUNT
* sizeof(uint16_t));
2495 if (ha
->flags
.reset_marker
)
2496 qla1280_rst_aen(ha
);
2499 dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
2500 "0x%x ****\n", mb
[0]);
2502 LEAVE("qla1280_mailbox_command");
2508 * Polls ISP for interrupts.
2511 * ha = adapter block pointer.
2514 qla1280_poll(struct scsi_qla_host
*ha
)
2516 struct device_reg __iomem
*reg
= ha
->iobase
;
2520 /* ENTER("qla1280_poll"); */
2522 /* Check for pending interrupts. */
2523 data
= RD_REG_WORD(®
->istatus
);
2524 if (data
& RISC_INT
)
2525 qla1280_isr(ha
, &done_q
);
2527 if (!ha
->mailbox_wait
) {
2528 if (ha
->flags
.reset_marker
)
2529 qla1280_rst_aen(ha
);
2532 if (!list_empty(&done_q
))
2535 /* LEAVE("qla1280_poll"); */
2540 * Issue SCSI bus reset.
2543 * ha = adapter block pointer.
2544 * bus = SCSI bus number.
2550 qla1280_bus_reset(struct scsi_qla_host
*ha
, int bus
)
2552 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2553 uint16_t reset_delay
;
2556 dprintk(3, "qla1280_bus_reset: entered\n");
2558 if (qla1280_verbose
)
2559 printk(KERN_INFO
"scsi(%li:%i): Resetting SCSI BUS\n",
2562 reset_delay
= ha
->bus_settings
[bus
].bus_reset_delay
;
2563 mb
[0] = MBC_BUS_RESET
;
2564 mb
[1] = reset_delay
;
2565 mb
[2] = (uint16_t) bus
;
2566 status
= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
2569 if (ha
->bus_settings
[bus
].failed_reset_count
> 2)
2570 ha
->bus_settings
[bus
].scsi_bus_dead
= 1;
2571 ha
->bus_settings
[bus
].failed_reset_count
++;
2573 spin_unlock_irq(ha
->host
->host_lock
);
2574 ssleep(reset_delay
);
2575 spin_lock_irq(ha
->host
->host_lock
);
2577 ha
->bus_settings
[bus
].scsi_bus_dead
= 0;
2578 ha
->bus_settings
[bus
].failed_reset_count
= 0;
2579 ha
->bus_settings
[bus
].reset_marker
= 0;
2580 /* Issue marker command. */
2581 qla1280_marker(ha
, bus
, 0, 0, MK_SYNC_ALL
);
2585 * We should probably call qla1280_set_target_parameters()
2586 * here as well for all devices on the bus.
2590 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
2592 dprintk(3, "qla1280_bus_reset: exiting normally\n");
2598 * qla1280_device_reset
2599 * Issue bus device reset message to the target.
2602 * ha = adapter block pointer.
2603 * bus = SCSI BUS number.
2610 qla1280_device_reset(struct scsi_qla_host
*ha
, int bus
, int target
)
2612 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2615 ENTER("qla1280_device_reset");
2617 mb
[0] = MBC_ABORT_TARGET
;
2618 mb
[1] = (bus
? (target
| BIT_7
) : target
) << 8;
2620 status
= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
2622 /* Issue marker command. */
2623 qla1280_marker(ha
, bus
, target
, 0, MK_SYNC_ID
);
2626 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
2628 LEAVE("qla1280_device_reset");
2633 * qla1280_abort_command
2634 * Abort command aborts a specified IOCB.
2637 * ha = adapter block pointer.
2638 * sp = SB structure pointer.
2644 qla1280_abort_command(struct scsi_qla_host
*ha
, struct srb
* sp
, int handle
)
2646 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2647 unsigned int bus
, target
, lun
;
2650 ENTER("qla1280_abort_command");
2652 bus
= SCSI_BUS_32(sp
->cmd
);
2653 target
= SCSI_TCN_32(sp
->cmd
);
2654 lun
= SCSI_LUN_32(sp
->cmd
);
2656 sp
->flags
|= SRB_ABORT_PENDING
;
2658 mb
[0] = MBC_ABORT_COMMAND
;
2659 mb
[1] = (bus
? target
| BIT_7
: target
) << 8 | lun
;
2660 mb
[2] = handle
>> 16;
2661 mb
[3] = handle
& 0xffff;
2662 status
= qla1280_mailbox_command(ha
, 0x0f, &mb
[0]);
2665 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
2666 sp
->flags
&= ~SRB_ABORT_PENDING
;
2670 LEAVE("qla1280_abort_command");
2675 * qla1280_reset_adapter
2679 * ha = adapter block pointer.
2682 qla1280_reset_adapter(struct scsi_qla_host
*ha
)
2684 struct device_reg __iomem
*reg
= ha
->iobase
;
2686 ENTER("qla1280_reset_adapter");
2688 /* Disable ISP chip */
2689 ha
->flags
.online
= 0;
2690 WRT_REG_WORD(®
->ictrl
, ISP_RESET
);
2691 WRT_REG_WORD(®
->host_cmd
,
2692 HC_RESET_RISC
| HC_RELEASE_RISC
| HC_DISABLE_BIOS
);
2693 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2695 LEAVE("qla1280_reset_adapter");
2699 * Issue marker command.
2700 * Function issues marker IOCB.
2703 * ha = adapter block pointer.
2704 * bus = SCSI BUS number
2707 * type = marker modifier
2710 qla1280_marker(struct scsi_qla_host
*ha
, int bus
, int id
, int lun
, u8 type
)
2712 struct mrk_entry
*pkt
;
2714 ENTER("qla1280_marker");
2716 /* Get request packet. */
2717 if ((pkt
= (struct mrk_entry
*) qla1280_req_pkt(ha
))) {
2718 pkt
->entry_type
= MARKER_TYPE
;
2719 pkt
->lun
= (uint8_t) lun
;
2720 pkt
->target
= (uint8_t) (bus
? (id
| BIT_7
) : id
);
2721 pkt
->modifier
= type
;
2722 pkt
->entry_status
= 0;
2724 /* Issue command to ISP */
2725 qla1280_isp_cmd(ha
);
2728 LEAVE("qla1280_marker");
2733 * qla1280_64bit_start_scsi
2734 * The start SCSI is responsible for building request packets on
2735 * request ring and modifying ISP input pointer.
2738 * ha = adapter block pointer.
2739 * sp = SB structure pointer.
2742 * 0 = success, was able to issue command.
2744 #ifdef QLA_64BIT_PTR
2746 qla1280_64bit_start_scsi(struct scsi_qla_host
*ha
, struct srb
* sp
)
2748 struct device_reg __iomem
*reg
= ha
->iobase
;
2749 struct scsi_cmnd
*cmd
= sp
->cmd
;
2750 cmd_a64_entry_t
*pkt
;
2752 dma_addr_t dma_handle
;
2759 ENTER("qla1280_64bit_start_scsi:");
2761 /* Calculate number of entries and segments required. */
2763 seg_cnt
= scsi_dma_map(cmd
);
2766 req_cnt
+= (seg_cnt
- 2) / 5;
2767 if ((seg_cnt
- 2) % 5)
2770 } else if (seg_cnt
< 0) {
2775 if ((req_cnt
+ 2) >= ha
->req_q_cnt
) {
2776 /* Calculate number of free request entries. */
2777 cnt
= RD_REG_WORD(®
->mailbox4
);
2778 if (ha
->req_ring_index
< cnt
)
2779 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
2782 REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
2785 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
2786 ha
->req_q_cnt
, seg_cnt
);
2788 /* If room for request in request ring. */
2789 if ((req_cnt
+ 2) >= ha
->req_q_cnt
) {
2790 status
= SCSI_MLQUEUE_HOST_BUSY
;
2791 dprintk(2, "qla1280_start_scsi: in-ptr=0x%x req_q_cnt="
2792 "0x%xreq_cnt=0x%x", ha
->req_ring_index
, ha
->req_q_cnt
,
2797 /* Check for room in outstanding command list. */
2798 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
&&
2799 ha
->outstanding_cmds
[cnt
] != NULL
; cnt
++);
2801 if (cnt
>= MAX_OUTSTANDING_COMMANDS
) {
2802 status
= SCSI_MLQUEUE_HOST_BUSY
;
2803 dprintk(2, "qla1280_start_scsi: NO ROOM IN "
2804 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha
->req_q_cnt
);
2808 ha
->outstanding_cmds
[cnt
] = sp
;
2809 ha
->req_q_cnt
-= req_cnt
;
2810 CMD_HANDLE(sp
->cmd
) = (unsigned char *)(unsigned long)(cnt
+ 1);
2812 dprintk(2, "start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd
, sp
,
2813 cmd
->cmnd
[0], (long)CMD_HANDLE(sp
->cmd
));
2814 dprintk(2, " bus %i, target %i, lun %i\n",
2815 SCSI_BUS_32(cmd
), SCSI_TCN_32(cmd
), SCSI_LUN_32(cmd
));
2816 qla1280_dump_buffer(2, cmd
->cmnd
, MAX_COMMAND_SIZE
);
2819 * Build command packet.
2821 pkt
= (cmd_a64_entry_t
*) ha
->request_ring_ptr
;
2823 pkt
->entry_type
= COMMAND_A64_TYPE
;
2824 pkt
->entry_count
= (uint8_t) req_cnt
;
2825 pkt
->sys_define
= (uint8_t) ha
->req_ring_index
;
2826 pkt
->entry_status
= 0;
2827 pkt
->handle
= cpu_to_le32(cnt
);
2829 /* Zero out remaining portion of packet. */
2830 memset(((char *)pkt
+ 8), 0, (REQUEST_ENTRY_SIZE
- 8));
2832 /* Set ISP command timeout. */
2833 pkt
->timeout
= cpu_to_le16(cmd
->request
->timeout
/HZ
);
2835 /* Set device target ID and LUN */
2836 pkt
->lun
= SCSI_LUN_32(cmd
);
2837 pkt
->target
= SCSI_BUS_32(cmd
) ?
2838 (SCSI_TCN_32(cmd
) | BIT_7
) : SCSI_TCN_32(cmd
);
2840 /* Enable simple tag queuing if device supports it. */
2841 if (cmd
->device
->simple_tags
)
2842 pkt
->control_flags
|= cpu_to_le16(BIT_3
);
2844 /* Load SCSI command packet. */
2845 pkt
->cdb_len
= cpu_to_le16(CMD_CDBLEN(cmd
));
2846 memcpy(pkt
->scsi_cdb
, CMD_CDBP(cmd
), CMD_CDBLEN(cmd
));
2847 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
2849 /* Set transfer direction. */
2850 dir
= qla1280_data_direction(cmd
);
2851 pkt
->control_flags
|= cpu_to_le16(dir
);
2853 /* Set total data segment count. */
2854 pkt
->dseg_count
= cpu_to_le16(seg_cnt
);
2857 * Load data segments.
2859 if (seg_cnt
) { /* If data transfer. */
2860 struct scatterlist
*sg
, *s
;
2861 int remseg
= seg_cnt
;
2863 sg
= scsi_sglist(cmd
);
2865 /* Setup packet address segment pointer. */
2866 dword_ptr
= (u32
*)&pkt
->dseg_0_address
;
2868 /* Load command entry data segments. */
2869 for_each_sg(sg
, s
, seg_cnt
, cnt
) {
2873 dma_handle
= sg_dma_address(s
);
2874 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2875 if (ha
->flags
.use_pci_vchannel
)
2876 sn_pci_set_vchan(ha
->pdev
,
2877 (unsigned long *)&dma_handle
,
2881 cpu_to_le32(pci_dma_lo32(dma_handle
));
2883 cpu_to_le32(pci_dma_hi32(dma_handle
));
2884 *dword_ptr
++ = cpu_to_le32(sg_dma_len(s
));
2885 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
2886 cpu_to_le32(pci_dma_hi32(dma_handle
)),
2887 cpu_to_le32(pci_dma_lo32(dma_handle
)),
2888 cpu_to_le32(sg_dma_len(sg_next(s
))));
2891 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
2892 "command packet data - b %i, t %i, l %i \n",
2893 SCSI_BUS_32(cmd
), SCSI_TCN_32(cmd
),
2895 qla1280_dump_buffer(5, (char *)pkt
,
2896 REQUEST_ENTRY_SIZE
);
2899 * Build continuation packets.
2901 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
2902 "remains\n", seg_cnt
);
2904 while (remseg
> 0) {
2905 /* Update sg start */
2907 /* Adjust ring index. */
2908 ha
->req_ring_index
++;
2909 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
2910 ha
->req_ring_index
= 0;
2911 ha
->request_ring_ptr
=
2914 ha
->request_ring_ptr
++;
2916 pkt
= (cmd_a64_entry_t
*)ha
->request_ring_ptr
;
2918 /* Zero out packet. */
2919 memset(pkt
, 0, REQUEST_ENTRY_SIZE
);
2921 /* Load packet defaults. */
2922 ((struct cont_a64_entry
*) pkt
)->entry_type
=
2924 ((struct cont_a64_entry
*) pkt
)->entry_count
= 1;
2925 ((struct cont_a64_entry
*) pkt
)->sys_define
=
2926 (uint8_t)ha
->req_ring_index
;
2927 /* Setup packet address segment pointer. */
2929 (u32
*)&((struct cont_a64_entry
*) pkt
)->dseg_0_address
;
2931 /* Load continuation entry data segments. */
2932 for_each_sg(sg
, s
, remseg
, cnt
) {
2935 dma_handle
= sg_dma_address(s
);
2936 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2937 if (ha
->flags
.use_pci_vchannel
)
2938 sn_pci_set_vchan(ha
->pdev
,
2939 (unsigned long *)&dma_handle
,
2943 cpu_to_le32(pci_dma_lo32(dma_handle
));
2945 cpu_to_le32(pci_dma_hi32(dma_handle
));
2947 cpu_to_le32(sg_dma_len(s
));
2948 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
2949 cpu_to_le32(pci_dma_hi32(dma_handle
)),
2950 cpu_to_le32(pci_dma_lo32(dma_handle
)),
2951 cpu_to_le32(sg_dma_len(s
)));
2954 dprintk(5, "qla1280_64bit_start_scsi: "
2955 "continuation packet data - b %i, t "
2956 "%i, l %i \n", SCSI_BUS_32(cmd
),
2957 SCSI_TCN_32(cmd
), SCSI_LUN_32(cmd
));
2958 qla1280_dump_buffer(5, (char *)pkt
,
2959 REQUEST_ENTRY_SIZE
);
2961 } else { /* No data transfer */
2962 dprintk(5, "qla1280_64bit_start_scsi: No data, command "
2963 "packet data - b %i, t %i, l %i \n",
2964 SCSI_BUS_32(cmd
), SCSI_TCN_32(cmd
), SCSI_LUN_32(cmd
));
2965 qla1280_dump_buffer(5, (char *)pkt
, REQUEST_ENTRY_SIZE
);
2967 /* Adjust ring index. */
2968 ha
->req_ring_index
++;
2969 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
2970 ha
->req_ring_index
= 0;
2971 ha
->request_ring_ptr
= ha
->request_ring
;
2973 ha
->request_ring_ptr
++;
2975 /* Set chip new ring index. */
2977 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
2978 sp
->flags
|= SRB_SENT
;
2980 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
2981 /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
2986 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
2988 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
2992 #else /* !QLA_64BIT_PTR */
2995 * qla1280_32bit_start_scsi
2996 * The start SCSI is responsible for building request packets on
2997 * request ring and modifying ISP input pointer.
2999 * The Qlogic firmware interface allows every queue slot to have a SCSI
3000 * command and up to 4 scatter/gather (SG) entries. If we need more
3001 * than 4 SG entries, then continuation entries are used that can
3002 * hold another 7 entries each. The start routine determines if there
3003 * is eought empty slots then build the combination of requests to
3004 * fulfill the OS request.
3007 * ha = adapter block pointer.
3008 * sp = SCSI Request Block structure pointer.
3011 * 0 = success, was able to issue command.
3014 qla1280_32bit_start_scsi(struct scsi_qla_host
*ha
, struct srb
* sp
)
3016 struct device_reg __iomem
*reg
= ha
->iobase
;
3017 struct scsi_cmnd
*cmd
= sp
->cmd
;
3018 struct cmd_entry
*pkt
;
3026 ENTER("qla1280_32bit_start_scsi");
3028 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd
, sp
,
3031 /* Calculate number of entries and segments required. */
3033 seg_cnt
= scsi_dma_map(cmd
);
3036 * if greater than four sg entries then we need to allocate
3037 * continuation entries
3040 req_cnt
+= (seg_cnt
- 4) / 7;
3041 if ((seg_cnt
- 4) % 7)
3044 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3045 cmd
, seg_cnt
, req_cnt
);
3046 } else if (seg_cnt
< 0) {
3051 if ((req_cnt
+ 2) >= ha
->req_q_cnt
) {
3052 /* Calculate number of free request entries. */
3053 cnt
= RD_REG_WORD(®
->mailbox4
);
3054 if (ha
->req_ring_index
< cnt
)
3055 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
3058 REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
3061 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3062 ha
->req_q_cnt
, seg_cnt
);
3063 /* If room for request in request ring. */
3064 if ((req_cnt
+ 2) >= ha
->req_q_cnt
) {
3065 status
= SCSI_MLQUEUE_HOST_BUSY
;
3066 dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
3067 "req_q_cnt=0x%x, req_cnt=0x%x", ha
->req_ring_index
,
3068 ha
->req_q_cnt
, req_cnt
);
3072 /* Check for empty slot in outstanding command list. */
3073 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
&&
3074 (ha
->outstanding_cmds
[cnt
] != 0); cnt
++) ;
3076 if (cnt
>= MAX_OUTSTANDING_COMMANDS
) {
3077 status
= SCSI_MLQUEUE_HOST_BUSY
;
3078 dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
3079 "ARRAY, req_q_cnt=0x%x\n", ha
->req_q_cnt
);
3083 CMD_HANDLE(sp
->cmd
) = (unsigned char *) (unsigned long)(cnt
+ 1);
3084 ha
->outstanding_cmds
[cnt
] = sp
;
3085 ha
->req_q_cnt
-= req_cnt
;
3088 * Build command packet.
3090 pkt
= (struct cmd_entry
*) ha
->request_ring_ptr
;
3092 pkt
->entry_type
= COMMAND_TYPE
;
3093 pkt
->entry_count
= (uint8_t) req_cnt
;
3094 pkt
->sys_define
= (uint8_t) ha
->req_ring_index
;
3095 pkt
->entry_status
= 0;
3096 pkt
->handle
= cpu_to_le32(cnt
);
3098 /* Zero out remaining portion of packet. */
3099 memset(((char *)pkt
+ 8), 0, (REQUEST_ENTRY_SIZE
- 8));
3101 /* Set ISP command timeout. */
3102 pkt
->timeout
= cpu_to_le16(cmd
->request
->timeout
/HZ
);
3104 /* Set device target ID and LUN */
3105 pkt
->lun
= SCSI_LUN_32(cmd
);
3106 pkt
->target
= SCSI_BUS_32(cmd
) ?
3107 (SCSI_TCN_32(cmd
) | BIT_7
) : SCSI_TCN_32(cmd
);
3109 /* Enable simple tag queuing if device supports it. */
3110 if (cmd
->device
->simple_tags
)
3111 pkt
->control_flags
|= cpu_to_le16(BIT_3
);
3113 /* Load SCSI command packet. */
3114 pkt
->cdb_len
= cpu_to_le16(CMD_CDBLEN(cmd
));
3115 memcpy(pkt
->scsi_cdb
, CMD_CDBP(cmd
), CMD_CDBLEN(cmd
));
3117 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3118 /* Set transfer direction. */
3119 dir
= qla1280_data_direction(cmd
);
3120 pkt
->control_flags
|= cpu_to_le16(dir
);
3122 /* Set total data segment count. */
3123 pkt
->dseg_count
= cpu_to_le16(seg_cnt
);
3126 * Load data segments.
3129 struct scatterlist
*sg
, *s
;
3130 int remseg
= seg_cnt
;
3132 sg
= scsi_sglist(cmd
);
3134 /* Setup packet address segment pointer. */
3135 dword_ptr
= &pkt
->dseg_0_address
;
3137 dprintk(3, "Building S/G data segments..\n");
3138 qla1280_dump_buffer(1, (char *)sg
, 4 * 16);
3140 /* Load command entry data segments. */
3141 for_each_sg(sg
, s
, seg_cnt
, cnt
) {
3145 cpu_to_le32(pci_dma_lo32(sg_dma_address(s
)));
3146 *dword_ptr
++ = cpu_to_le32(sg_dma_len(s
));
3147 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3148 (pci_dma_lo32(sg_dma_address(s
))),
3153 * Build continuation packets.
3155 dprintk(3, "S/G Building Continuation"
3156 "...seg_cnt=0x%x remains\n", seg_cnt
);
3157 while (remseg
> 0) {
3158 /* Continue from end point */
3160 /* Adjust ring index. */
3161 ha
->req_ring_index
++;
3162 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
3163 ha
->req_ring_index
= 0;
3164 ha
->request_ring_ptr
=
3167 ha
->request_ring_ptr
++;
3169 pkt
= (struct cmd_entry
*)ha
->request_ring_ptr
;
3171 /* Zero out packet. */
3172 memset(pkt
, 0, REQUEST_ENTRY_SIZE
);
3174 /* Load packet defaults. */
3175 ((struct cont_entry
*) pkt
)->
3176 entry_type
= CONTINUE_TYPE
;
3177 ((struct cont_entry
*) pkt
)->entry_count
= 1;
3179 ((struct cont_entry
*) pkt
)->sys_define
=
3180 (uint8_t) ha
->req_ring_index
;
3182 /* Setup packet address segment pointer. */
3184 &((struct cont_entry
*) pkt
)->dseg_0_address
;
3186 /* Load continuation entry data segments. */
3187 for_each_sg(sg
, s
, remseg
, cnt
) {
3191 cpu_to_le32(pci_dma_lo32(sg_dma_address(s
)));
3193 cpu_to_le32(sg_dma_len(s
));
3195 "S/G Segment Cont. phys_addr=0x%x, "
3197 cpu_to_le32(pci_dma_lo32(sg_dma_address(s
))),
3198 cpu_to_le32(sg_dma_len(s
)));
3201 dprintk(5, "qla1280_32bit_start_scsi: "
3202 "continuation packet data - "
3203 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd
),
3204 SCSI_TCN_32(cmd
), SCSI_LUN_32(cmd
));
3205 qla1280_dump_buffer(5, (char *)pkt
,
3206 REQUEST_ENTRY_SIZE
);
3208 } else { /* No data transfer at all */
3209 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
3210 "packet data - \n");
3211 qla1280_dump_buffer(5, (char *)pkt
, REQUEST_ENTRY_SIZE
);
3213 dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
3214 qla1280_dump_buffer(5, (char *)ha
->request_ring_ptr
,
3215 REQUEST_ENTRY_SIZE
);
3217 /* Adjust ring index. */
3218 ha
->req_ring_index
++;
3219 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
3220 ha
->req_ring_index
= 0;
3221 ha
->request_ring_ptr
= ha
->request_ring
;
3223 ha
->request_ring_ptr
++;
3225 /* Set chip new ring index. */
3226 dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
3227 "for pending command\n");
3228 sp
->flags
|= SRB_SENT
;
3230 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
3231 /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
3236 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
3238 LEAVE("qla1280_32bit_start_scsi");
3246 * Function is responsible for locking ring and
3247 * getting a zeroed out request packet.
3250 * ha = adapter block pointer.
3253 * 0 = failed to get slot.
3256 qla1280_req_pkt(struct scsi_qla_host
*ha
)
3258 struct device_reg __iomem
*reg
= ha
->iobase
;
3259 request_t
*pkt
= NULL
;
3263 ENTER("qla1280_req_pkt");
3266 * This can be called from interrupt context, damn it!!!
3268 /* Wait for 30 seconds for slot. */
3269 for (timer
= 15000000; timer
; timer
--) {
3270 if (ha
->req_q_cnt
> 0) {
3271 /* Calculate number of free request entries. */
3272 cnt
= RD_REG_WORD(®
->mailbox4
);
3273 if (ha
->req_ring_index
< cnt
)
3274 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
3277 REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
3280 /* Found empty request ring slot? */
3281 if (ha
->req_q_cnt
> 0) {
3283 pkt
= ha
->request_ring_ptr
;
3285 /* Zero out packet. */
3286 memset(pkt
, 0, REQUEST_ENTRY_SIZE
);
3289 * How can this be right when we have a ring
3292 /* Set system defined field. */
3293 pkt
->sys_define
= (uint8_t) ha
->req_ring_index
;
3295 /* Set entry count. */
3296 pkt
->entry_count
= 1;
3303 /* Check for pending interrupts. */
3308 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
3310 dprintk(3, "qla1280_req_pkt: exiting normally\n");
3317 * Function is responsible for modifying ISP input pointer.
3318 * Releases ring lock.
3321 * ha = adapter block pointer.
3324 qla1280_isp_cmd(struct scsi_qla_host
*ha
)
3326 struct device_reg __iomem
*reg
= ha
->iobase
;
3328 ENTER("qla1280_isp_cmd");
3330 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
3331 qla1280_dump_buffer(5, (char *)ha
->request_ring_ptr
,
3332 REQUEST_ENTRY_SIZE
);
3334 /* Adjust ring index. */
3335 ha
->req_ring_index
++;
3336 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
3337 ha
->req_ring_index
= 0;
3338 ha
->request_ring_ptr
= ha
->request_ring
;
3340 ha
->request_ring_ptr
++;
3343 * Update request index to mailbox4 (Request Queue In).
3344 * The mmiowb() ensures that this write is ordered with writes by other
3345 * CPUs. Without the mmiowb(), it is possible for the following:
3346 * CPUA posts write of index 5 to mailbox4
3347 * CPUA releases host lock
3348 * CPUB acquires host lock
3349 * CPUB posts write of index 6 to mailbox4
3350 * On PCI bus, order reverses and write of 6 posts, then index 5,
3351 * causing chip to issue full queue of stale commands
3352 * The mmiowb() prevents future writes from crossing the barrier.
3353 * See Documentation/DocBook/deviceiobook.tmpl for more information.
3355 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
3358 LEAVE("qla1280_isp_cmd");
3361 /****************************************************************************/
3362 /* Interrupt Service Routine. */
3363 /****************************************************************************/
3365 /****************************************************************************
3367 * Calls I/O done on command completion.
3370 * ha = adapter block pointer.
3371 * done_q = done queue.
3372 ****************************************************************************/
3374 qla1280_isr(struct scsi_qla_host
*ha
, struct list_head
*done_q
)
3376 struct device_reg __iomem
*reg
= ha
->iobase
;
3377 struct response
*pkt
;
3378 struct srb
*sp
= NULL
;
3379 uint16_t mailbox
[MAILBOX_REGISTER_COUNT
];
3384 ENTER("qla1280_isr");
3386 istatus
= RD_REG_WORD(®
->istatus
);
3387 if (!(istatus
& (RISC_INT
| PCI_INT
)))
3390 /* Save mailbox register 5 */
3391 mailbox
[5] = RD_REG_WORD(®
->mailbox5
);
3393 /* Check for mailbox interrupt. */
3395 mailbox
[0] = RD_REG_WORD_dmasync(®
->semaphore
);
3397 if (mailbox
[0] & BIT_0
) {
3398 /* Get mailbox data. */
3399 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
3402 *wptr
++ = RD_REG_WORD(®
->mailbox0
);
3403 *wptr
++ = RD_REG_WORD(®
->mailbox1
);
3404 *wptr
= RD_REG_WORD(®
->mailbox2
);
3405 if (mailbox
[0] != MBA_SCSI_COMPLETION
) {
3407 *wptr
++ = RD_REG_WORD(®
->mailbox3
);
3408 *wptr
++ = RD_REG_WORD(®
->mailbox4
);
3410 *wptr
++ = RD_REG_WORD(®
->mailbox6
);
3411 *wptr
= RD_REG_WORD(®
->mailbox7
);
3414 /* Release mailbox registers. */
3416 WRT_REG_WORD(®
->semaphore
, 0);
3417 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
3419 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
3422 /* Handle asynchronous event */
3423 switch (mailbox
[0]) {
3424 case MBA_SCSI_COMPLETION
: /* Response completion */
3425 dprintk(5, "qla1280_isr: mailbox SCSI response "
3428 if (ha
->flags
.online
) {
3429 /* Get outstanding command index. */
3430 index
= mailbox
[2] << 16 | mailbox
[1];
3432 /* Validate handle. */
3433 if (index
< MAX_OUTSTANDING_COMMANDS
)
3434 sp
= ha
->outstanding_cmds
[index
];
3439 /* Free outstanding command slot. */
3440 ha
->outstanding_cmds
[index
] = NULL
;
3442 /* Save ISP completion status */
3443 CMD_RESULT(sp
->cmd
) = 0;
3444 CMD_HANDLE(sp
->cmd
) = COMPLETED_HANDLE
;
3446 /* Place block on done queue */
3447 list_add_tail(&sp
->list
, done_q
);
3450 * If we get here we have a real problem!
3453 "qla1280: ISP invalid handle\n");
3458 case MBA_BUS_RESET
: /* SCSI Bus Reset */
3459 ha
->flags
.reset_marker
= 1;
3460 index
= mailbox
[6] & BIT_0
;
3461 ha
->bus_settings
[index
].reset_marker
= 1;
3463 printk(KERN_DEBUG
"qla1280_isr(): index %i "
3464 "asynchronous BUS_RESET\n", index
);
3467 case MBA_SYSTEM_ERR
: /* System Error */
3469 "qla1280: ISP System Error - mbx1=%xh, mbx2="
3470 "%xh, mbx3=%xh\n", mailbox
[1], mailbox
[2],
3474 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
3476 "qla1280: ISP Request Transfer Error\n");
3479 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
3481 "qla1280: ISP Response Transfer Error\n");
3484 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up */
3485 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
3488 case MBA_TIMEOUT_RESET
: /* Execution Timeout Reset */
3490 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
3493 case MBA_DEVICE_RESET
: /* Bus Device Reset */
3494 printk(KERN_INFO
"qla1280_isr(): asynchronous "
3495 "BUS_DEVICE_RESET\n");
3497 ha
->flags
.reset_marker
= 1;
3498 index
= mailbox
[6] & BIT_0
;
3499 ha
->bus_settings
[index
].reset_marker
= 1;
3502 case MBA_BUS_MODE_CHANGE
:
3504 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
3508 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
3509 if (mailbox
[0] < MBA_ASYNC_EVENT
) {
3511 memcpy((uint16_t *) ha
->mailbox_out
, wptr
,
3512 MAILBOX_REGISTER_COUNT
*
3515 if(ha
->mailbox_wait
!= NULL
)
3516 complete(ha
->mailbox_wait
);
3521 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
3525 * We will receive interrupts during mailbox testing prior to
3526 * the card being marked online, hence the double check.
3528 if (!(ha
->flags
.online
&& !ha
->mailbox_wait
)) {
3529 dprintk(2, "qla1280_isr: Response pointer Error\n");
3533 if (mailbox
[5] >= RESPONSE_ENTRY_CNT
)
3536 while (ha
->rsp_ring_index
!= mailbox
[5]) {
3537 pkt
= ha
->response_ring_ptr
;
3539 dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
3540 " = 0x%x\n", ha
->rsp_ring_index
, mailbox
[5]);
3541 dprintk(5,"qla1280_isr: response packet data\n");
3542 qla1280_dump_buffer(5, (char *)pkt
, RESPONSE_ENTRY_SIZE
);
3544 if (pkt
->entry_type
== STATUS_TYPE
) {
3545 if ((le16_to_cpu(pkt
->scsi_status
) & 0xff)
3546 || pkt
->comp_status
|| pkt
->entry_status
) {
3547 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3548 "0x%x mailbox[5] = 0x%x, comp_status "
3549 "= 0x%x, scsi_status = 0x%x\n",
3550 ha
->rsp_ring_index
, mailbox
[5],
3551 le16_to_cpu(pkt
->comp_status
),
3552 le16_to_cpu(pkt
->scsi_status
));
3555 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3556 "0x%x, mailbox[5] = 0x%x\n",
3557 ha
->rsp_ring_index
, mailbox
[5]);
3558 dprintk(2, "qla1280_isr: response packet data\n");
3559 qla1280_dump_buffer(2, (char *)pkt
,
3560 RESPONSE_ENTRY_SIZE
);
3563 if (pkt
->entry_type
== STATUS_TYPE
|| pkt
->entry_status
) {
3564 dprintk(2, "status: Cmd %p, handle %i\n",
3565 ha
->outstanding_cmds
[pkt
->handle
]->cmd
,
3567 if (pkt
->entry_type
== STATUS_TYPE
)
3568 qla1280_status_entry(ha
, pkt
, done_q
);
3570 qla1280_error_entry(ha
, pkt
, done_q
);
3571 /* Adjust ring index. */
3572 ha
->rsp_ring_index
++;
3573 if (ha
->rsp_ring_index
== RESPONSE_ENTRY_CNT
) {
3574 ha
->rsp_ring_index
= 0;
3575 ha
->response_ring_ptr
= ha
->response_ring
;
3577 ha
->response_ring_ptr
++;
3578 WRT_REG_WORD(®
->mailbox5
, ha
->rsp_ring_index
);
3583 LEAVE("qla1280_isr");
3588 * Processes asynchronous reset.
3591 * ha = adapter block pointer.
3594 qla1280_rst_aen(struct scsi_qla_host
*ha
)
3598 ENTER("qla1280_rst_aen");
3600 if (ha
->flags
.online
&& !ha
->flags
.reset_active
&&
3601 !ha
->flags
.abort_isp_active
) {
3602 ha
->flags
.reset_active
= 1;
3603 while (ha
->flags
.reset_marker
) {
3604 /* Issue marker command. */
3605 ha
->flags
.reset_marker
= 0;
3606 for (bus
= 0; bus
< ha
->ports
&&
3607 !ha
->flags
.reset_marker
; bus
++) {
3608 if (ha
->bus_settings
[bus
].reset_marker
) {
3609 ha
->bus_settings
[bus
].reset_marker
= 0;
3610 qla1280_marker(ha
, bus
, 0, 0,
3617 LEAVE("qla1280_rst_aen");
3622 * qla1280_status_entry
3623 * Processes received ISP status entry.
3626 * ha = adapter block pointer.
3627 * pkt = entry pointer.
3628 * done_q = done queue.
3631 qla1280_status_entry(struct scsi_qla_host
*ha
, struct response
*pkt
,
3632 struct list_head
*done_q
)
3634 unsigned int bus
, target
, lun
;
3637 struct scsi_cmnd
*cmd
;
3638 uint32_t handle
= le32_to_cpu(pkt
->handle
);
3639 uint16_t scsi_status
= le16_to_cpu(pkt
->scsi_status
);
3640 uint16_t comp_status
= le16_to_cpu(pkt
->comp_status
);
3642 ENTER("qla1280_status_entry");
3644 /* Validate handle. */
3645 if (handle
< MAX_OUTSTANDING_COMMANDS
)
3646 sp
= ha
->outstanding_cmds
[handle
];
3651 printk(KERN_WARNING
"qla1280: Status Entry invalid handle\n");
3655 /* Free outstanding command slot. */
3656 ha
->outstanding_cmds
[handle
] = NULL
;
3660 /* Generate LU queue on cntrl, target, LUN */
3661 bus
= SCSI_BUS_32(cmd
);
3662 target
= SCSI_TCN_32(cmd
);
3663 lun
= SCSI_LUN_32(cmd
);
3665 if (comp_status
|| scsi_status
) {
3666 dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
3667 "0x%x, handle = 0x%x\n", comp_status
,
3668 scsi_status
, handle
);
3671 /* Target busy or queue full */
3672 if ((scsi_status
& 0xFF) == SAM_STAT_TASK_SET_FULL
||
3673 (scsi_status
& 0xFF) == SAM_STAT_BUSY
) {
3674 CMD_RESULT(cmd
) = scsi_status
& 0xff;
3677 /* Save ISP completion status */
3678 CMD_RESULT(cmd
) = qla1280_return_status(pkt
, cmd
);
3680 if (scsi_status
& SAM_STAT_CHECK_CONDITION
) {
3681 if (comp_status
!= CS_ARS_FAILED
) {
3682 uint16_t req_sense_length
=
3683 le16_to_cpu(pkt
->req_sense_length
);
3684 if (req_sense_length
< CMD_SNSLEN(cmd
))
3685 sense_sz
= req_sense_length
;
3688 * scsi_cmnd->sense_buffer is
3689 * 64 bytes, why only copy 63?
3690 * This looks wrong! /Jes
3692 sense_sz
= CMD_SNSLEN(cmd
) - 1;
3694 memcpy(cmd
->sense_buffer
,
3695 &pkt
->req_sense_data
, sense_sz
);
3698 memset(cmd
->sense_buffer
+ sense_sz
, 0,
3699 SCSI_SENSE_BUFFERSIZE
- sense_sz
);
3701 dprintk(2, "qla1280_status_entry: Check "
3702 "condition Sense data, b %i, t %i, "
3703 "l %i\n", bus
, target
, lun
);
3705 qla1280_dump_buffer(2,
3706 (char *)cmd
->sense_buffer
,
3711 CMD_HANDLE(sp
->cmd
) = COMPLETED_HANDLE
;
3713 /* Place command on done queue. */
3714 list_add_tail(&sp
->list
, done_q
);
3716 LEAVE("qla1280_status_entry");
3720 * qla1280_error_entry
3721 * Processes error entry.
3724 * ha = adapter block pointer.
3725 * pkt = entry pointer.
3726 * done_q = done queue.
3729 qla1280_error_entry(struct scsi_qla_host
*ha
, struct response
*pkt
,
3730 struct list_head
*done_q
)
3733 uint32_t handle
= le32_to_cpu(pkt
->handle
);
3735 ENTER("qla1280_error_entry");
3737 if (pkt
->entry_status
& BIT_3
)
3738 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
3739 else if (pkt
->entry_status
& BIT_2
)
3740 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
3741 else if (pkt
->entry_status
& BIT_1
)
3742 dprintk(2, "qla1280_error_entry: FULL flag error\n");
3744 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
3746 /* Validate handle. */
3747 if (handle
< MAX_OUTSTANDING_COMMANDS
)
3748 sp
= ha
->outstanding_cmds
[handle
];
3753 /* Free outstanding command slot. */
3754 ha
->outstanding_cmds
[handle
] = NULL
;
3756 /* Bad payload or header */
3757 if (pkt
->entry_status
& (BIT_3
+ BIT_2
)) {
3758 /* Bad payload or header, set error status. */
3759 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
3760 CMD_RESULT(sp
->cmd
) = DID_ERROR
<< 16;
3761 } else if (pkt
->entry_status
& BIT_1
) { /* FULL flag */
3762 CMD_RESULT(sp
->cmd
) = DID_BUS_BUSY
<< 16;
3764 /* Set error status. */
3765 CMD_RESULT(sp
->cmd
) = DID_ERROR
<< 16;
3768 CMD_HANDLE(sp
->cmd
) = COMPLETED_HANDLE
;
3770 /* Place command on done queue. */
3771 list_add_tail(&sp
->list
, done_q
);
3773 #ifdef QLA_64BIT_PTR
3774 else if (pkt
->entry_type
== COMMAND_A64_TYPE
) {
3775 printk(KERN_WARNING
"!qla1280: Error Entry invalid handle");
3779 LEAVE("qla1280_error_entry");
3784 * Resets ISP and aborts all outstanding commands.
3787 * ha = adapter block pointer.
3793 qla1280_abort_isp(struct scsi_qla_host
*ha
)
3795 struct device_reg __iomem
*reg
= ha
->iobase
;
3801 ENTER("qla1280_abort_isp");
3803 if (ha
->flags
.abort_isp_active
|| !ha
->flags
.online
)
3806 ha
->flags
.abort_isp_active
= 1;
3808 /* Disable ISP interrupts. */
3809 qla1280_disable_intrs(ha
);
3810 WRT_REG_WORD(®
->host_cmd
, HC_PAUSE_RISC
);
3811 RD_REG_WORD(®
->id_l
);
3813 printk(KERN_INFO
"scsi(%li): dequeuing outstanding commands\n",
3815 /* Dequeue all commands in outstanding command list. */
3816 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3817 struct scsi_cmnd
*cmd
;
3818 sp
= ha
->outstanding_cmds
[cnt
];
3821 CMD_RESULT(cmd
) = DID_RESET
<< 16;
3822 CMD_HANDLE(cmd
) = COMPLETED_HANDLE
;
3823 ha
->outstanding_cmds
[cnt
] = NULL
;
3824 list_add_tail(&sp
->list
, &ha
->done_q
);
3830 status
= qla1280_load_firmware(ha
);
3834 /* Setup adapter based on NVRAM parameters. */
3835 qla1280_nvram_config (ha
);
3837 status
= qla1280_init_rings(ha
);
3841 /* Issue SCSI reset. */
3842 for (bus
= 0; bus
< ha
->ports
; bus
++)
3843 qla1280_bus_reset(ha
, bus
);
3845 ha
->flags
.abort_isp_active
= 0;
3849 "qla1280: ISP error recovery failed, board disabled");
3850 qla1280_reset_adapter(ha
);
3851 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
3854 LEAVE("qla1280_abort_isp");
3860 * qla1280_debounce_register
3861 * Debounce register.
3864 * port = register address.
3870 qla1280_debounce_register(volatile u16 __iomem
* addr
)
3875 ret
= RD_REG_WORD(addr
);
3876 ret2
= RD_REG_WORD(addr
);
3883 ret
= RD_REG_WORD(addr
);
3884 ret2
= RD_REG_WORD(addr
);
3885 } while (ret
!= ret2
);
3891 /************************************************************************
3892 * qla1280_check_for_dead_scsi_bus *
3894 * This routine checks for a dead SCSI bus *
3895 ************************************************************************/
3896 #define SET_SXP_BANK 0x0100
3897 #define SCSI_PHASE_INVALID 0x87FF
3899 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host
*ha
, unsigned int bus
)
3901 uint16_t config_reg
, scsi_control
;
3902 struct device_reg __iomem
*reg
= ha
->iobase
;
3904 if (ha
->bus_settings
[bus
].scsi_bus_dead
) {
3905 WRT_REG_WORD(®
->host_cmd
, HC_PAUSE_RISC
);
3906 config_reg
= RD_REG_WORD(®
->cfg_1
);
3907 WRT_REG_WORD(®
->cfg_1
, SET_SXP_BANK
);
3908 scsi_control
= RD_REG_WORD(®
->scsiControlPins
);
3909 WRT_REG_WORD(®
->cfg_1
, config_reg
);
3910 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
3912 if (scsi_control
== SCSI_PHASE_INVALID
) {
3913 ha
->bus_settings
[bus
].scsi_bus_dead
= 1;
3914 return 1; /* bus is dead */
3916 ha
->bus_settings
[bus
].scsi_bus_dead
= 0;
3917 ha
->bus_settings
[bus
].failed_reset_count
= 0;
3920 return 0; /* bus is not dead */
3924 qla1280_get_target_parameters(struct scsi_qla_host
*ha
,
3925 struct scsi_device
*device
)
3927 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3928 int bus
, target
, lun
;
3930 bus
= device
->channel
;
3931 target
= device
->id
;
3935 mb
[0] = MBC_GET_TARGET_PARAMETERS
;
3936 mb
[1] = (uint16_t) (bus
? target
| BIT_7
: target
);
3938 qla1280_mailbox_command(ha
, BIT_6
| BIT_3
| BIT_2
| BIT_1
| BIT_0
,
3941 printk(KERN_INFO
"scsi(%li:%d:%d:%d):", ha
->host_no
, bus
, target
, lun
);
3944 printk(" Sync: period %d, offset %d",
3945 (mb
[3] & 0xff), (mb
[3] >> 8));
3948 if ((mb
[2] & BIT_5
) && ((mb
[6] >> 8) & 0xff) >= 2)
3953 if (device
->simple_tags
)
3954 printk(", Tagged queuing: depth %d", device
->queue_depth
);
3961 __qla1280_dump_buffer(char *b
, int size
)
3966 printk(KERN_DEBUG
" 0 1 2 3 4 5 6 7 8 9 Ah "
3967 "Bh Ch Dh Eh Fh\n");
3968 printk(KERN_DEBUG
"---------------------------------------------"
3969 "------------------\n");
3971 for (cnt
= 0; cnt
< size
;) {
3974 printk("0x%02x", c
);
3985 /**************************************************************************
3986 * ql1280_print_scsi_cmd
3988 **************************************************************************/
3990 __qla1280_print_scsi_cmd(struct scsi_cmnd
*cmd
)
3992 struct scsi_qla_host
*ha
;
3993 struct Scsi_Host
*host
= CMD_HOST(cmd
);
3995 /* struct scatterlist *sg; */
3998 ha
= (struct scsi_qla_host
*)host
->hostdata
;
4000 sp
= (struct srb
*)CMD_SP(cmd
);
4001 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd
, CMD_HANDLE(cmd
));
4002 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
4003 SCSI_BUS_32(cmd
), SCSI_TCN_32(cmd
), SCSI_LUN_32(cmd
),
4006 for (i
= 0; i
< cmd
->cmd_len
; i
++) {
4007 printk("0x%02x ", cmd
->cmnd
[i
]);
4009 printk(" seg_cnt =%d\n", scsi_sg_count(cmd
));
4010 printk(" request buffer=0x%p, request buffer len=0x%x\n",
4011 scsi_sglist(cmd
), scsi_bufflen(cmd
));
4014 sg = (struct scatterlist *) cmd->request_buffer;
4015 printk(" SG buffer: \n");
4016 qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
4018 printk(" tag=%d, transfersize=0x%x \n",
4019 cmd
->tag
, cmd
->transfersize
);
4020 printk(" Pid=%li, SP=0x%p\n", cmd
->serial_number
, CMD_SP(cmd
));
4021 printk(" underflow size = 0x%x, direction=0x%x\n",
4022 cmd
->underflow
, cmd
->sc_data_direction
);
4025 /**************************************************************************
4026 * ql1280_dump_device
4028 **************************************************************************/
4030 ql1280_dump_device(struct scsi_qla_host
*ha
)
4033 struct scsi_cmnd
*cp
;
4037 printk(KERN_DEBUG
"Outstanding Commands on controller:\n");
4039 for (i
= 0; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
4040 if ((sp
= ha
->outstanding_cmds
[i
]) == NULL
)
4042 if ((cp
= sp
->cmd
) == NULL
)
4044 qla1280_print_scsi_cmd(1, cp
);
4059 struct setup_tokens
{
4064 static struct setup_tokens setup_token
[] __initdata
=
4066 { "nvram", TOKEN_NVRAM
},
4067 { "sync", TOKEN_SYNC
},
4068 { "wide", TOKEN_WIDE
},
4069 { "ppr", TOKEN_PPR
},
4070 { "verbose", TOKEN_VERBOSE
},
4071 { "debug", TOKEN_DEBUG
},
4075 /**************************************************************************
4078 * Handle boot parameters. This really needs to be changed so one
4079 * can specify per adapter parameters.
4080 **************************************************************************/
4082 qla1280_setup(char *s
)
4090 while (cp
&& (ptr
= strchr(cp
, ':'))) {
4092 if (!strcmp(ptr
, "yes")) {
4095 } else if (!strcmp(ptr
, "no")) {
4099 val
= simple_strtoul(ptr
, &ptr
, 0);
4101 switch ((toke
= qla1280_get_token(cp
))) {
4104 driver_setup
.no_nvram
= 1;
4108 driver_setup
.no_sync
= 1;
4109 else if (val
!= 0x10000)
4110 driver_setup
.sync_mask
= val
;
4114 driver_setup
.no_wide
= 1;
4115 else if (val
!= 0x10000)
4116 driver_setup
.wide_mask
= val
;
4120 driver_setup
.no_ppr
= 1;
4121 else if (val
!= 0x10000)
4122 driver_setup
.ppr_mask
= val
;
4125 qla1280_verbose
= val
;
4128 printk(KERN_INFO
"qla1280: unknown boot option %s\n",
4132 cp
= strchr(ptr
, ';');
4144 qla1280_get_token(char *str
)
4150 sep
= strchr(str
, ':');
4153 for (i
= 0; i
< ARRAY_SIZE(setup_token
); i
++) {
4154 if (!strncmp(setup_token
[i
].token
, str
, (sep
- str
))) {
4155 ret
= setup_token
[i
].val
;
4165 static struct scsi_host_template qla1280_driver_template
= {
4166 .module
= THIS_MODULE
,
4167 .proc_name
= "qla1280",
4168 .name
= "Qlogic ISP 1280/12160",
4169 .info
= qla1280_info
,
4170 .slave_configure
= qla1280_slave_configure
,
4171 .queuecommand
= qla1280_queuecommand
,
4172 .eh_abort_handler
= qla1280_eh_abort
,
4173 .eh_device_reset_handler
= qla1280_eh_device_reset
,
4174 .eh_bus_reset_handler
= qla1280_eh_bus_reset
,
4175 .eh_host_reset_handler
= qla1280_eh_adapter_reset
,
4176 .bios_param
= qla1280_biosparam
,
4177 .can_queue
= 0xfffff,
4179 .sg_tablesize
= SG_ALL
,
4181 .use_clustering
= ENABLE_CLUSTERING
,
4185 static int __devinit
4186 qla1280_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
4188 int devnum
= id
->driver_data
;
4189 struct qla_boards
*bdp
= &ql1280_board_tbl
[devnum
];
4190 struct Scsi_Host
*host
;
4191 struct scsi_qla_host
*ha
;
4192 int error
= -ENODEV
;
4194 /* Bypass all AMI SUBSYS VENDOR IDs */
4195 if (pdev
->subsystem_vendor
== PCI_VENDOR_ID_AMI
) {
4197 "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
4201 printk(KERN_INFO
"qla1280: %s found on PCI bus %i, dev %i\n",
4202 bdp
->name
, pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
));
4204 if (pci_enable_device(pdev
)) {
4206 "qla1280: Failed to enabled pci device, aborting.\n");
4210 pci_set_master(pdev
);
4213 host
= scsi_host_alloc(&qla1280_driver_template
, sizeof(*ha
));
4216 "qla1280: Failed to register host, aborting.\n");
4217 goto error_disable_device
;
4220 ha
= (struct scsi_qla_host
*)host
->hostdata
;
4221 memset(ha
, 0, sizeof(struct scsi_qla_host
));
4224 ha
->devnum
= devnum
; /* specifies microcode load address */
4226 #ifdef QLA_64BIT_PTR
4227 if (pci_set_dma_mask(ha
->pdev
, DMA_BIT_MASK(64))) {
4228 if (pci_set_dma_mask(ha
->pdev
, DMA_BIT_MASK(32))) {
4229 printk(KERN_WARNING
"scsi(%li): Unable to set a "
4230 "suitable DMA mask - aborting\n", ha
->host_no
);
4232 goto error_put_host
;
4235 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4238 if (pci_set_dma_mask(ha
->pdev
, DMA_BIT_MASK(32))) {
4239 printk(KERN_WARNING
"scsi(%li): Unable to set a "
4240 "suitable DMA mask - aborting\n", ha
->host_no
);
4242 goto error_put_host
;
4246 ha
->request_ring
= pci_alloc_consistent(ha
->pdev
,
4247 ((REQUEST_ENTRY_CNT
+ 1) * sizeof(request_t
)),
4249 if (!ha
->request_ring
) {
4250 printk(KERN_INFO
"qla1280: Failed to get request memory\n");
4251 goto error_put_host
;
4254 ha
->response_ring
= pci_alloc_consistent(ha
->pdev
,
4255 ((RESPONSE_ENTRY_CNT
+ 1) * sizeof(struct response
)),
4257 if (!ha
->response_ring
) {
4258 printk(KERN_INFO
"qla1280: Failed to get response memory\n");
4259 goto error_free_request_ring
;
4262 ha
->ports
= bdp
->numPorts
;
4265 ha
->host_no
= host
->host_no
;
4267 host
->irq
= pdev
->irq
;
4268 host
->max_channel
= bdp
->numPorts
- 1;
4269 host
->max_lun
= MAX_LUNS
- 1;
4270 host
->max_id
= MAX_TARGETS
;
4271 host
->max_sectors
= 1024;
4272 host
->unique_id
= host
->host_no
;
4276 #if MEMORY_MAPPED_IO
4277 ha
->mmpbase
= pci_ioremap_bar(ha
->pdev
, 1);
4279 printk(KERN_INFO
"qla1280: Unable to map I/O memory\n");
4280 goto error_free_response_ring
;
4283 host
->base
= (unsigned long)ha
->mmpbase
;
4284 ha
->iobase
= (struct device_reg __iomem
*)ha
->mmpbase
;
4286 host
->io_port
= pci_resource_start(ha
->pdev
, 0);
4287 if (!request_region(host
->io_port
, 0xff, "qla1280")) {
4288 printk(KERN_INFO
"qla1280: Failed to reserve i/o region "
4289 "0x%04lx-0x%04lx - already in use\n",
4290 host
->io_port
, host
->io_port
+ 0xff);
4291 goto error_free_response_ring
;
4294 ha
->iobase
= (struct device_reg
*)host
->io_port
;
4297 INIT_LIST_HEAD(&ha
->done_q
);
4299 /* Disable ISP interrupts. */
4300 qla1280_disable_intrs(ha
);
4302 if (request_irq(pdev
->irq
, qla1280_intr_handler
, IRQF_SHARED
,
4304 printk("qla1280 : Failed to reserve interrupt %d already "
4305 "in use\n", pdev
->irq
);
4306 goto error_release_region
;
4309 /* load the F/W, read paramaters, and init the H/W */
4310 if (qla1280_initialize_adapter(ha
)) {
4311 printk(KERN_INFO
"qla1x160: Failed to initialize adapter\n");
4312 goto error_free_irq
;
4315 /* set our host ID (need to do something about our two IDs) */
4316 host
->this_id
= ha
->bus_settings
[0].id
;
4318 pci_set_drvdata(pdev
, host
);
4320 error
= scsi_add_host(host
, &pdev
->dev
);
4322 goto error_disable_adapter
;
4323 scsi_scan_host(host
);
4327 error_disable_adapter
:
4328 qla1280_disable_intrs(ha
);
4330 free_irq(pdev
->irq
, ha
);
4331 error_release_region
:
4332 #if MEMORY_MAPPED_IO
4333 iounmap(ha
->mmpbase
);
4335 release_region(host
->io_port
, 0xff);
4337 error_free_response_ring
:
4338 pci_free_consistent(ha
->pdev
,
4339 ((RESPONSE_ENTRY_CNT
+ 1) * sizeof(struct response
)),
4340 ha
->response_ring
, ha
->response_dma
);
4341 error_free_request_ring
:
4342 pci_free_consistent(ha
->pdev
,
4343 ((REQUEST_ENTRY_CNT
+ 1) * sizeof(request_t
)),
4344 ha
->request_ring
, ha
->request_dma
);
4346 scsi_host_put(host
);
4347 error_disable_device
:
4348 pci_disable_device(pdev
);
4354 static void __devexit
4355 qla1280_remove_one(struct pci_dev
*pdev
)
4357 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
4358 struct scsi_qla_host
*ha
= (struct scsi_qla_host
*)host
->hostdata
;
4360 scsi_remove_host(host
);
4362 qla1280_disable_intrs(ha
);
4364 free_irq(pdev
->irq
, ha
);
4366 #if MEMORY_MAPPED_IO
4367 iounmap(ha
->mmpbase
);
4369 release_region(host
->io_port
, 0xff);
4372 pci_free_consistent(ha
->pdev
,
4373 ((REQUEST_ENTRY_CNT
+ 1) * (sizeof(request_t
))),
4374 ha
->request_ring
, ha
->request_dma
);
4375 pci_free_consistent(ha
->pdev
,
4376 ((RESPONSE_ENTRY_CNT
+ 1) * (sizeof(struct response
))),
4377 ha
->response_ring
, ha
->response_dma
);
4379 pci_disable_device(pdev
);
4381 scsi_host_put(host
);
4384 static struct pci_driver qla1280_pci_driver
= {
4386 .id_table
= qla1280_pci_tbl
,
4387 .probe
= qla1280_probe_one
,
4388 .remove
= __devexit_p(qla1280_remove_one
),
4394 if (sizeof(struct srb
) > sizeof(struct scsi_pointer
)) {
4396 "qla1280: struct srb too big, aborting\n");
4402 * If we are called as a module, the qla1280 pointer may not be null
4403 * and it would point to our bootup string, just like on the lilo
4404 * command line. IF not NULL, then process this config string with
4408 * To add options at boot time add a line to your lilo.conf file like:
4409 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
4410 * which will result in the first four devices on the first two
4411 * controllers being set to a tagged queue depth of 32.
4414 qla1280_setup(qla1280
);
4417 return pci_register_driver(&qla1280_pci_driver
);
4423 pci_unregister_driver(&qla1280_pci_driver
);
4426 module_init(qla1280_init
);
4427 module_exit(qla1280_exit
);
4430 MODULE_AUTHOR("Qlogic & Jes Sorensen");
4431 MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
4432 MODULE_LICENSE("GPL");
4433 MODULE_FIRMWARE("qlogic/1040.bin");
4434 MODULE_FIRMWARE("qlogic/1280.bin");
4435 MODULE_FIRMWARE("qlogic/12160.bin");
4436 MODULE_VERSION(QLA1280_VERSION
);
4439 * Overrides for Emacs so that we almost follow Linus's tabbing style.
4440 * Emacs will notice this stuff at the end of the file and automatically
4441 * adjust the settings for this buffer only. This must remain at the end
4443 * ---------------------------------------------------------------------------