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/pci_ids.h>
350 #include <linux/interrupt.h>
351 #include <linux/init.h>
352 #include <linux/dma-mapping.h>
353 #include <linux/firmware.h>
357 #include <asm/byteorder.h>
358 #include <asm/processor.h>
359 #include <asm/types.h>
360 #include <asm/system.h>
362 #include <scsi/scsi.h>
363 #include <scsi/scsi_cmnd.h>
364 #include <scsi/scsi_device.h>
365 #include <scsi/scsi_host.h>
366 #include <scsi/scsi_tcq.h>
368 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
369 #include <asm/sn/io.h>
374 * Compile time Options:
375 * 0 - Disable and 1 - Enable
377 #define DEBUG_QLA1280_INTR 0
378 #define DEBUG_PRINT_NVRAM 0
379 #define DEBUG_QLA1280 0
382 * The SGI VISWS is broken and doesn't support MMIO ;-(
384 #ifdef CONFIG_X86_VISWS
385 #define MEMORY_MAPPED_IO 0
387 #define MEMORY_MAPPED_IO 1
392 #ifndef BITS_PER_LONG
393 #error "BITS_PER_LONG not defined!"
395 #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
396 #define QLA_64BIT_PTR 1
400 #define pci_dma_hi32(a) ((a >> 16) >> 16)
402 #define pci_dma_hi32(a) 0
404 #define pci_dma_lo32(a) (a & 0xffffffff)
406 #define NVRAM_DELAY() udelay(500) /* 2 microseconds */
408 #if defined(__ia64__) && !defined(ia64_platform_is)
409 #define ia64_platform_is(foo) (!strcmp(x, platform_name))
413 #define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
414 #define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
415 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
416 #define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
417 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
420 static int qla1280_probe_one(struct pci_dev
*, const struct pci_device_id
*);
421 static void qla1280_remove_one(struct pci_dev
*);
424 * QLogic Driver Support Function Prototypes.
426 static void qla1280_done(struct scsi_qla_host
*);
427 static int qla1280_get_token(char *);
428 static int qla1280_setup(char *s
) __init
;
431 * QLogic ISP1280 Hardware Support Function Prototypes.
433 static int qla1280_load_firmware(struct scsi_qla_host
*);
434 static int qla1280_init_rings(struct scsi_qla_host
*);
435 static int qla1280_nvram_config(struct scsi_qla_host
*);
436 static int qla1280_mailbox_command(struct scsi_qla_host
*,
437 uint8_t, uint16_t *);
438 static int qla1280_bus_reset(struct scsi_qla_host
*, int);
439 static int qla1280_device_reset(struct scsi_qla_host
*, int, int);
440 static int qla1280_abort_command(struct scsi_qla_host
*, struct srb
*, int);
441 static int qla1280_abort_isp(struct scsi_qla_host
*);
443 static int qla1280_64bit_start_scsi(struct scsi_qla_host
*, struct srb
*);
445 static int qla1280_32bit_start_scsi(struct scsi_qla_host
*, struct srb
*);
447 static void qla1280_nv_write(struct scsi_qla_host
*, uint16_t);
448 static void qla1280_poll(struct scsi_qla_host
*);
449 static void qla1280_reset_adapter(struct scsi_qla_host
*);
450 static void qla1280_marker(struct scsi_qla_host
*, int, int, int, u8
);
451 static void qla1280_isp_cmd(struct scsi_qla_host
*);
452 static void qla1280_isr(struct scsi_qla_host
*, struct list_head
*);
453 static void qla1280_rst_aen(struct scsi_qla_host
*);
454 static void qla1280_status_entry(struct scsi_qla_host
*, struct response
*,
456 static void qla1280_error_entry(struct scsi_qla_host
*, struct response
*,
458 static uint16_t qla1280_get_nvram_word(struct scsi_qla_host
*, uint32_t);
459 static uint16_t qla1280_nvram_request(struct scsi_qla_host
*, uint32_t);
460 static uint16_t qla1280_debounce_register(volatile uint16_t __iomem
*);
461 static request_t
*qla1280_req_pkt(struct scsi_qla_host
*);
462 static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host
*,
464 static void qla1280_get_target_parameters(struct scsi_qla_host
*,
465 struct scsi_device
*);
466 static int qla1280_set_target_parameters(struct scsi_qla_host
*, int, int);
469 static struct qla_driver_setup driver_setup
;
472 * convert scsi data direction to request_t control flags
474 static inline uint16_t
475 qla1280_data_direction(struct scsi_cmnd
*cmnd
)
477 switch(cmnd
->sc_data_direction
) {
478 case DMA_FROM_DEVICE
:
482 case DMA_BIDIRECTIONAL
:
483 return BIT_5
| BIT_6
;
485 * We could BUG() on default here if one of the four cases aren't
486 * met, but then again if we receive something like that from the
487 * SCSI layer we have more serious problems. This shuts up GCC.
496 static void __qla1280_print_scsi_cmd(struct scsi_cmnd
* cmd
);
497 static void __qla1280_dump_buffer(char *, int);
502 * insmod needs to find the variable and make it point to something
505 static char *qla1280
;
507 /* insmod qla1280 options=verbose" */
508 module_param(qla1280
, charp
, 0);
510 __setup("qla1280=", qla1280_setup
);
515 * We use the scsi_pointer structure that's included with each scsi_command
516 * to overlay our struct srb over it. qla1280_init() checks that a srb is not
517 * bigger than a scsi_pointer.
520 #define CMD_SP(Cmnd) &Cmnd->SCp
521 #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
522 #define CMD_CDBP(Cmnd) Cmnd->cmnd
523 #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
524 #define CMD_SNSLEN(Cmnd) SCSI_SENSE_BUFFERSIZE
525 #define CMD_RESULT(Cmnd) Cmnd->result
526 #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
527 #define CMD_REQUEST(Cmnd) Cmnd->request->cmd
529 #define CMD_HOST(Cmnd) Cmnd->device->host
530 #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
531 #define SCSI_TCN_32(Cmnd) Cmnd->device->id
532 #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
535 /*****************************************/
536 /* ISP Boards supported by this driver */
537 /*****************************************/
540 unsigned char name
[9]; /* Board ID String */
541 int numPorts
; /* Number of SCSI ports */
542 char *fwname
; /* firmware name */
545 /* NOTE: the last argument in each entry is used to index ql1280_board_tbl */
546 static struct pci_device_id qla1280_pci_tbl
[] = {
547 {PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP12160
,
548 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
549 {PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP1020
,
550 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 1},
551 {PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP1080
,
552 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 2},
553 {PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP1240
,
554 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 3},
555 {PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP1280
,
556 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 4},
557 {PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP10160
,
558 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 5},
561 MODULE_DEVICE_TABLE(pci
, qla1280_pci_tbl
);
563 static struct qla_boards ql1280_board_tbl
[] = {
564 /* Name , Number of ports, FW details */
565 {"QLA12160", 2, "qlogic/12160.bin"},
566 {"QLA1040", 1, "qlogic/1040.bin"},
567 {"QLA1080", 1, "qlogic/1280.bin"},
568 {"QLA1240", 2, "qlogic/1280.bin"},
569 {"QLA1280", 2, "qlogic/1280.bin"},
570 {"QLA10160", 1, "qlogic/12160.bin"},
574 static int qla1280_verbose
= 1;
577 static int ql_debug_level
= 1;
578 #define dprintk(level, format, a...) \
579 do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
580 #define qla1280_dump_buffer(level, buf, size) \
581 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
582 #define qla1280_print_scsi_cmd(level, cmd) \
583 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
585 #define ql_debug_level 0
586 #define dprintk(level, format, a...) do{}while(0)
587 #define qla1280_dump_buffer(a, b, c) do{}while(0)
588 #define qla1280_print_scsi_cmd(a, b) do{}while(0)
591 #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
592 #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
593 #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
594 #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
597 static int qla1280_read_nvram(struct scsi_qla_host
*ha
)
604 ENTER("qla1280_read_nvram");
606 if (driver_setup
.no_nvram
)
609 printk(KERN_INFO
"scsi(%ld): Reading NVRAM\n", ha
->host_no
);
611 wptr
= (uint16_t *)&ha
->nvram
;
614 for (cnt
= 0; cnt
< 3; cnt
++) {
615 *wptr
= qla1280_get_nvram_word(ha
, cnt
);
616 chksum
+= *wptr
& 0xff;
617 chksum
+= (*wptr
>> 8) & 0xff;
621 if (nv
->id0
!= 'I' || nv
->id1
!= 'S' ||
622 nv
->id2
!= 'P' || nv
->id3
!= ' ' || nv
->version
< 1) {
623 dprintk(2, "Invalid nvram ID or version!\n");
626 for (; cnt
< sizeof(struct nvram
); cnt
++) {
627 *wptr
= qla1280_get_nvram_word(ha
, cnt
);
628 chksum
+= *wptr
& 0xff;
629 chksum
+= (*wptr
>> 8) & 0xff;
634 dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
635 " version %i\n", nv
->id0
, nv
->id1
, nv
->id2
, nv
->id3
,
640 if (!driver_setup
.no_nvram
)
641 printk(KERN_WARNING
"scsi(%ld): Unable to identify or "
642 "validate NVRAM checksum, using default "
643 "settings\n", ha
->host_no
);
648 /* The firmware interface is, um, interesting, in that the
649 * actual firmware image on the chip is little endian, thus,
650 * the process of taking that image to the CPU would end up
651 * little endian. However, the firmware interface requires it
652 * to be read a word (two bytes) at a time.
654 * The net result of this would be that the word (and
655 * doubleword) quantites in the firmware would be correct, but
656 * the bytes would be pairwise reversed. Since most of the
657 * firmware quantites are, in fact, bytes, we do an extra
658 * le16_to_cpu() in the firmware read routine.
660 * The upshot of all this is that the bytes in the firmware
661 * are in the correct places, but the 16 and 32 bit quantites
662 * are still in little endian format. We fix that up below by
663 * doing extra reverses on them */
664 nv
->isp_parameter
= cpu_to_le16(nv
->isp_parameter
);
665 nv
->firmware_feature
.w
= cpu_to_le16(nv
->firmware_feature
.w
);
666 for(i
= 0; i
< MAX_BUSES
; i
++) {
667 nv
->bus
[i
].selection_timeout
= cpu_to_le16(nv
->bus
[i
].selection_timeout
);
668 nv
->bus
[i
].max_queue_depth
= cpu_to_le16(nv
->bus
[i
].max_queue_depth
);
670 dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
671 LEAVE("qla1280_read_nvram");
676 /**************************************************************************
678 * Return a string describing the driver.
679 **************************************************************************/
681 qla1280_info(struct Scsi_Host
*host
)
683 static char qla1280_scsi_name_buffer
[125];
685 struct scsi_qla_host
*ha
;
686 struct qla_boards
*bdp
;
688 bp
= &qla1280_scsi_name_buffer
[0];
689 ha
= (struct scsi_qla_host
*)host
->hostdata
;
690 bdp
= &ql1280_board_tbl
[ha
->devnum
];
691 memset(bp
, 0, sizeof(qla1280_scsi_name_buffer
));
694 "QLogic %s PCI to SCSI Host Adapter\n"
695 " Firmware version: %2d.%02d.%02d, Driver version %s",
696 &bdp
->name
[0], ha
->fwver1
, ha
->fwver2
, ha
->fwver3
,
701 /**************************************************************************
702 * qla1280_queuecommand
703 * Queue a command to the controller.
706 * The mid-level driver tries to ensures that queuecommand never gets invoked
707 * concurrently with itself or the interrupt handler (although the
708 * interrupt handler may call this routine as part of request-completion
709 * handling). Unfortunely, it sometimes calls the scheduler in interrupt
710 * context which is a big NO! NO!.
711 **************************************************************************/
713 qla1280_queuecommand(struct scsi_cmnd
*cmd
, void (*fn
)(struct scsi_cmnd
*))
715 struct Scsi_Host
*host
= cmd
->device
->host
;
716 struct scsi_qla_host
*ha
= (struct scsi_qla_host
*)host
->hostdata
;
717 struct srb
*sp
= (struct srb
*)CMD_SP(cmd
);
724 CMD_HANDLE(cmd
) = (unsigned char *)NULL
;
726 qla1280_print_scsi_cmd(5, cmd
);
730 * Using 64 bit commands if the PCI bridge doesn't support it is a
731 * bit wasteful, however this should really only happen if one's
732 * PCI controller is completely broken, like the BCM1250. For
733 * sane hardware this is not an issue.
735 status
= qla1280_64bit_start_scsi(ha
, sp
);
737 status
= qla1280_32bit_start_scsi(ha
, sp
);
750 static void qla1280_mailbox_timeout(unsigned long __data
)
752 struct scsi_qla_host
*ha
= (struct scsi_qla_host
*)__data
;
753 struct device_reg __iomem
*reg
;
756 ha
->mailbox_out
[0] = RD_REG_WORD(®
->mailbox0
);
757 printk(KERN_ERR
"scsi(%ld): mailbox timed out, mailbox0 %04x, "
758 "ictrl %04x, istatus %04x\n", ha
->host_no
, ha
->mailbox_out
[0],
759 RD_REG_WORD(®
->ictrl
), RD_REG_WORD(®
->istatus
));
760 complete(ha
->mailbox_wait
);
764 _qla1280_wait_for_single_command(struct scsi_qla_host
*ha
, struct srb
*sp
,
765 struct completion
*wait
)
768 struct scsi_cmnd
*cmd
= sp
->cmd
;
770 spin_unlock_irq(ha
->host
->host_lock
);
771 wait_for_completion_timeout(wait
, 4*HZ
);
772 spin_lock_irq(ha
->host
->host_lock
);
774 if(CMD_HANDLE(cmd
) == COMPLETED_HANDLE
) {
776 (*cmd
->scsi_done
)(cmd
);
782 qla1280_wait_for_single_command(struct scsi_qla_host
*ha
, struct srb
*sp
)
784 DECLARE_COMPLETION_ONSTACK(wait
);
787 return _qla1280_wait_for_single_command(ha
, sp
, &wait
);
791 qla1280_wait_for_pending_commands(struct scsi_qla_host
*ha
, int bus
, int target
)
796 struct scsi_cmnd
*cmd
;
801 * Wait for all commands with the designated bus/target
802 * to be completed by the firmware
804 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
805 sp
= ha
->outstanding_cmds
[cnt
];
809 if (bus
>= 0 && SCSI_BUS_32(cmd
) != bus
)
811 if (target
>= 0 && SCSI_TCN_32(cmd
) != target
)
814 status
= qla1280_wait_for_single_command(ha
, sp
);
815 if (status
== FAILED
)
822 /**************************************************************************
823 * qla1280_error_action
824 * The function will attempt to perform a specified error action and
825 * wait for the results (or time out).
828 * cmd = Linux SCSI command packet of the command that cause the
830 * action = error action to take (see action_t)
835 **************************************************************************/
837 qla1280_error_action(struct scsi_cmnd
*cmd
, enum action action
)
839 struct scsi_qla_host
*ha
;
840 int bus
, target
, lun
;
845 int wait_for_target
= -1;
846 DECLARE_COMPLETION_ONSTACK(wait
);
848 ENTER("qla1280_error_action");
850 ha
= (struct scsi_qla_host
*)(CMD_HOST(cmd
)->hostdata
);
851 sp
= (struct srb
*)CMD_SP(cmd
);
852 bus
= SCSI_BUS_32(cmd
);
853 target
= SCSI_TCN_32(cmd
);
854 lun
= SCSI_LUN_32(cmd
);
856 dprintk(4, "error_action %i, istatus 0x%04x\n", action
,
857 RD_REG_WORD(&ha
->iobase
->istatus
));
859 dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
860 RD_REG_WORD(&ha
->iobase
->host_cmd
),
861 RD_REG_WORD(&ha
->iobase
->ictrl
), jiffies
);
864 printk(KERN_INFO
"scsi(%li): Resetting Cmnd=0x%p, "
865 "Handle=0x%p, action=0x%x\n",
866 ha
->host_no
, cmd
, CMD_HANDLE(cmd
), action
);
869 * Check to see if we have the command in the outstanding_cmds[]
870 * array. If not then it must have completed before this error
871 * action was initiated. If the error_action isn't ABORT_COMMAND
872 * then the driver must proceed with the requested action.
875 for (i
= 0; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
876 if (sp
== ha
->outstanding_cmds
[i
]) {
878 sp
->wait
= &wait
; /* we'll wait for it to complete */
883 if (found
< 0) { /* driver doesn't have command */
885 if (qla1280_verbose
) {
887 "scsi(%ld:%d:%d:%d): specified command has "
888 "already completed.\n", ha
->host_no
, bus
,
896 dprintk(1, "qla1280: RISC aborting command\n");
898 * The abort might fail due to race when the host_lock
899 * is released to issue the abort. As such, we
900 * don't bother to check the return status.
903 qla1280_abort_command(ha
, sp
, found
);
909 "scsi(%ld:%d:%d:%d): Queueing device reset "
910 "command.\n", ha
->host_no
, bus
, target
, lun
);
911 if (qla1280_device_reset(ha
, bus
, target
) == 0) {
912 /* issued device reset, set wait conditions */
914 wait_for_target
= target
;
920 printk(KERN_INFO
"qla1280(%ld:%d): Issued bus "
921 "reset.\n", ha
->host_no
, bus
);
922 if (qla1280_bus_reset(ha
, bus
) == 0) {
923 /* issued bus reset, set wait conditions */
930 if (qla1280_verbose
) {
932 "scsi(%ld): Issued ADAPTER RESET\n",
934 printk(KERN_INFO
"scsi(%ld): I/O processing will "
935 "continue automatically\n", ha
->host_no
);
937 ha
->flags
.reset_active
= 1;
939 if (qla1280_abort_isp(ha
) != 0) { /* it's dead */
943 ha
->flags
.reset_active
= 0;
947 * At this point, the host_lock has been released and retaken
948 * by the issuance of the mailbox command.
949 * Wait for the command passed in by the mid-layer if it
950 * was found by the driver. It might have been returned
951 * between eh recovery steps, hence the check of the "found"
956 result
= _qla1280_wait_for_single_command(ha
, sp
, &wait
);
958 if (action
== ABORT_COMMAND
&& result
!= SUCCESS
) {
960 "scsi(%li:%i:%i:%i): "
961 "Unable to abort command!\n",
962 ha
->host_no
, bus
, target
, lun
);
966 * If the command passed in by the mid-layer has been
967 * returned by the board, then wait for any additional
968 * commands which are supposed to complete based upon
971 * All commands are unconditionally returned during a
972 * call to qla1280_abort_isp(), ADAPTER_RESET. No need
975 if (result
== SUCCESS
&& wait_for_bus
>= 0) {
976 result
= qla1280_wait_for_pending_commands(ha
,
977 wait_for_bus
, wait_for_target
);
980 dprintk(1, "RESET returning %d\n", result
);
982 LEAVE("qla1280_error_action");
986 /**************************************************************************
988 * Abort the specified SCSI command(s).
989 **************************************************************************/
991 qla1280_eh_abort(struct scsi_cmnd
* cmd
)
995 spin_lock_irq(cmd
->device
->host
->host_lock
);
996 rc
= qla1280_error_action(cmd
, ABORT_COMMAND
);
997 spin_unlock_irq(cmd
->device
->host
->host_lock
);
1002 /**************************************************************************
1003 * qla1280_device_reset
1004 * Reset the specified SCSI device
1005 **************************************************************************/
1007 qla1280_eh_device_reset(struct scsi_cmnd
*cmd
)
1011 spin_lock_irq(cmd
->device
->host
->host_lock
);
1012 rc
= qla1280_error_action(cmd
, DEVICE_RESET
);
1013 spin_unlock_irq(cmd
->device
->host
->host_lock
);
1018 /**************************************************************************
1020 * Reset the specified bus.
1021 **************************************************************************/
1023 qla1280_eh_bus_reset(struct scsi_cmnd
*cmd
)
1027 spin_lock_irq(cmd
->device
->host
->host_lock
);
1028 rc
= qla1280_error_action(cmd
, BUS_RESET
);
1029 spin_unlock_irq(cmd
->device
->host
->host_lock
);
1034 /**************************************************************************
1035 * qla1280_adapter_reset
1036 * Reset the specified adapter (both channels)
1037 **************************************************************************/
1039 qla1280_eh_adapter_reset(struct scsi_cmnd
*cmd
)
1043 spin_lock_irq(cmd
->device
->host
->host_lock
);
1044 rc
= qla1280_error_action(cmd
, ADAPTER_RESET
);
1045 spin_unlock_irq(cmd
->device
->host
->host_lock
);
1051 qla1280_biosparam(struct scsi_device
*sdev
, struct block_device
*bdev
,
1052 sector_t capacity
, int geom
[])
1054 int heads
, sectors
, cylinders
;
1058 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
1059 if (cylinders
> 1024) {
1062 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
1063 /* if (cylinders > 1023)
1064 cylinders = 1023; */
1069 geom
[2] = cylinders
;
1075 /* disable risc and host interrupts */
1077 qla1280_disable_intrs(struct scsi_qla_host
*ha
)
1079 WRT_REG_WORD(&ha
->iobase
->ictrl
, 0);
1080 RD_REG_WORD(&ha
->iobase
->ictrl
); /* PCI Posted Write flush */
1083 /* enable risc and host interrupts */
1085 qla1280_enable_intrs(struct scsi_qla_host
*ha
)
1087 WRT_REG_WORD(&ha
->iobase
->ictrl
, (ISP_EN_INT
| ISP_EN_RISC
));
1088 RD_REG_WORD(&ha
->iobase
->ictrl
); /* PCI Posted Write flush */
1091 /**************************************************************************
1092 * qla1280_intr_handler
1093 * Handles the H/W interrupt
1094 **************************************************************************/
1096 qla1280_intr_handler(int irq
, void *dev_id
)
1098 struct scsi_qla_host
*ha
;
1099 struct device_reg __iomem
*reg
;
1103 ENTER_INTR ("qla1280_intr_handler");
1104 ha
= (struct scsi_qla_host
*)dev_id
;
1106 spin_lock(ha
->host
->host_lock
);
1111 qla1280_disable_intrs(ha
);
1113 data
= qla1280_debounce_register(®
->istatus
);
1114 /* Check for pending interrupts. */
1115 if (data
& RISC_INT
) {
1116 qla1280_isr(ha
, &ha
->done_q
);
1119 if (!list_empty(&ha
->done_q
))
1122 spin_unlock(ha
->host
->host_lock
);
1124 qla1280_enable_intrs(ha
);
1126 LEAVE_INTR("qla1280_intr_handler");
1127 return IRQ_RETVAL(handled
);
1132 qla1280_set_target_parameters(struct scsi_qla_host
*ha
, int bus
, int target
)
1135 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
1141 mr
= BIT_3
| BIT_2
| BIT_1
| BIT_0
;
1143 /* Set Target Parameters. */
1144 mb
[0] = MBC_SET_TARGET_PARAMETERS
;
1145 mb
[1] = (uint16_t)((bus
? target
| BIT_7
: target
) << 8);
1146 mb
[2] = nv
->bus
[bus
].target
[target
].parameter
.renegotiate_on_error
<< 8;
1147 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.stop_queue_on_check
<< 9;
1148 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.auto_request_sense
<< 10;
1149 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.tag_queuing
<< 11;
1150 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.enable_sync
<< 12;
1151 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.enable_wide
<< 13;
1152 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.parity_checking
<< 14;
1153 mb
[2] |= nv
->bus
[bus
].target
[target
].parameter
.disconnect_allowed
<< 15;
1155 if (IS_ISP1x160(ha
)) {
1156 mb
[2] |= nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.enable_ppr
<< 5;
1157 mb
[3] = (nv
->bus
[bus
].target
[target
].flags
.flags1x160
.sync_offset
<< 8);
1158 mb
[6] = (nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.ppr_options
<< 8) |
1159 nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.ppr_bus_width
;
1162 mb
[3] = (nv
->bus
[bus
].target
[target
].flags
.flags1x80
.sync_offset
<< 8);
1164 mb
[3] |= nv
->bus
[bus
].target
[target
].sync_period
;
1166 status
= qla1280_mailbox_command(ha
, mr
, mb
);
1168 /* Set Device Queue Parameters. */
1169 for (lun
= 0; lun
< MAX_LUNS
; lun
++) {
1170 mb
[0] = MBC_SET_DEVICE_QUEUE
;
1171 mb
[1] = (uint16_t)((bus
? target
| BIT_7
: target
) << 8);
1173 mb
[2] = nv
->bus
[bus
].max_queue_depth
;
1174 mb
[3] = nv
->bus
[bus
].target
[target
].execution_throttle
;
1175 status
|= qla1280_mailbox_command(ha
, 0x0f, mb
);
1179 printk(KERN_WARNING
"scsi(%ld:%i:%i): "
1180 "qla1280_set_target_parameters() failed\n",
1181 ha
->host_no
, bus
, target
);
1186 /**************************************************************************
1187 * qla1280_slave_configure
1190 * Determines the queue depth for a given device. There are two ways
1191 * a queue depth can be obtained for a tagged queueing device. One
1192 * way is the default queue depth which is determined by whether
1193 * If it is defined, then it is used
1194 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1195 * default queue depth (dependent on the number of hardware SCBs).
1196 **************************************************************************/
1198 qla1280_slave_configure(struct scsi_device
*device
)
1200 struct scsi_qla_host
*ha
;
1201 int default_depth
= 3;
1202 int bus
= device
->channel
;
1203 int target
= device
->id
;
1206 unsigned long flags
;
1208 ha
= (struct scsi_qla_host
*)device
->host
->hostdata
;
1211 if (qla1280_check_for_dead_scsi_bus(ha
, bus
))
1214 if (device
->tagged_supported
&&
1215 (ha
->bus_settings
[bus
].qtag_enables
& (BIT_0
<< target
))) {
1216 scsi_adjust_queue_depth(device
, MSG_ORDERED_TAG
,
1217 ha
->bus_settings
[bus
].hiwat
);
1219 scsi_adjust_queue_depth(device
, 0, default_depth
);
1222 nv
->bus
[bus
].target
[target
].parameter
.enable_sync
= device
->sdtr
;
1223 nv
->bus
[bus
].target
[target
].parameter
.enable_wide
= device
->wdtr
;
1224 nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.enable_ppr
= device
->ppr
;
1226 if (driver_setup
.no_sync
||
1227 (driver_setup
.sync_mask
&&
1228 (~driver_setup
.sync_mask
& (1 << target
))))
1229 nv
->bus
[bus
].target
[target
].parameter
.enable_sync
= 0;
1230 if (driver_setup
.no_wide
||
1231 (driver_setup
.wide_mask
&&
1232 (~driver_setup
.wide_mask
& (1 << target
))))
1233 nv
->bus
[bus
].target
[target
].parameter
.enable_wide
= 0;
1234 if (IS_ISP1x160(ha
)) {
1235 if (driver_setup
.no_ppr
||
1236 (driver_setup
.ppr_mask
&&
1237 (~driver_setup
.ppr_mask
& (1 << target
))))
1238 nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.enable_ppr
= 0;
1241 spin_lock_irqsave(ha
->host
->host_lock
, flags
);
1242 if (nv
->bus
[bus
].target
[target
].parameter
.enable_sync
)
1243 status
= qla1280_set_target_parameters(ha
, bus
, target
);
1244 qla1280_get_target_parameters(ha
, device
);
1245 spin_unlock_irqrestore(ha
->host
->host_lock
, flags
);
1252 * Process completed commands.
1255 * ha = adapter block pointer.
1258 qla1280_done(struct scsi_qla_host
*ha
)
1261 struct list_head
*done_q
;
1262 int bus
, target
, lun
;
1263 struct scsi_cmnd
*cmd
;
1265 ENTER("qla1280_done");
1267 done_q
= &ha
->done_q
;
1269 while (!list_empty(done_q
)) {
1270 sp
= list_entry(done_q
->next
, struct srb
, list
);
1272 list_del(&sp
->list
);
1275 bus
= SCSI_BUS_32(cmd
);
1276 target
= SCSI_TCN_32(cmd
);
1277 lun
= SCSI_LUN_32(cmd
);
1279 switch ((CMD_RESULT(cmd
) >> 16)) {
1281 /* Issue marker command. */
1282 if (!ha
->flags
.abort_isp_active
)
1283 qla1280_marker(ha
, bus
, target
, 0, MK_SYNC_ID
);
1286 sp
->flags
&= ~SRB_ABORT_PENDING
;
1287 sp
->flags
|= SRB_ABORTED
;
1293 /* Release memory used for this I/O */
1294 scsi_dma_unmap(cmd
);
1296 /* Call the mid-level driver interrupt handler */
1299 if (sp
->wait
== NULL
)
1300 (*(cmd
)->scsi_done
)(cmd
);
1304 LEAVE("qla1280_done");
1308 * Translates a ISP error to a Linux SCSI error
1311 qla1280_return_status(struct response
* sts
, struct scsi_cmnd
*cp
)
1313 int host_status
= DID_ERROR
;
1314 uint16_t comp_status
= le16_to_cpu(sts
->comp_status
);
1315 uint16_t state_flags
= le16_to_cpu(sts
->state_flags
);
1316 uint32_t residual_length
= le32_to_cpu(sts
->residual_length
);
1317 uint16_t scsi_status
= le16_to_cpu(sts
->scsi_status
);
1318 #if DEBUG_QLA1280_INTR
1319 static char *reason
[] = {
1331 #endif /* DEBUG_QLA1280_INTR */
1333 ENTER("qla1280_return_status");
1335 #if DEBUG_QLA1280_INTR
1337 dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
1342 switch (comp_status
) {
1344 host_status
= DID_OK
;
1348 if (!(state_flags
& SF_GOT_BUS
))
1349 host_status
= DID_NO_CONNECT
;
1350 else if (!(state_flags
& SF_GOT_TARGET
))
1351 host_status
= DID_BAD_TARGET
;
1352 else if (!(state_flags
& SF_SENT_CDB
))
1353 host_status
= DID_ERROR
;
1354 else if (!(state_flags
& SF_TRANSFERRED_DATA
))
1355 host_status
= DID_ERROR
;
1356 else if (!(state_flags
& SF_GOT_STATUS
))
1357 host_status
= DID_ERROR
;
1358 else if (!(state_flags
& SF_GOT_SENSE
))
1359 host_status
= DID_ERROR
;
1363 host_status
= DID_RESET
;
1367 host_status
= DID_ABORT
;
1371 host_status
= DID_TIME_OUT
;
1374 case CS_DATA_OVERRUN
:
1375 dprintk(2, "Data overrun 0x%x\n", residual_length
);
1376 dprintk(2, "qla1280_return_status: response packet data\n");
1377 qla1280_dump_buffer(2, (char *)sts
, RESPONSE_ENTRY_SIZE
);
1378 host_status
= DID_ERROR
;
1381 case CS_DATA_UNDERRUN
:
1382 if ((scsi_bufflen(cp
) - residual_length
) <
1385 "scsi: Underflow detected - retrying "
1387 host_status
= DID_ERROR
;
1389 scsi_set_resid(cp
, residual_length
);
1390 host_status
= DID_OK
;
1395 host_status
= DID_ERROR
;
1399 #if DEBUG_QLA1280_INTR
1400 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
1401 reason
[host_status
], scsi_status
);
1404 LEAVE("qla1280_return_status");
1406 return (scsi_status
& 0xff) | (host_status
<< 16);
1409 /****************************************************************************/
1410 /* QLogic ISP1280 Hardware Support Functions. */
1411 /****************************************************************************/
1414 * qla1280_initialize_adapter
1418 * ha = adapter block pointer.
1423 static int __devinit
1424 qla1280_initialize_adapter(struct scsi_qla_host
*ha
)
1426 struct device_reg __iomem
*reg
;
1429 unsigned long flags
;
1431 ENTER("qla1280_initialize_adapter");
1433 /* Clear adapter flags. */
1434 ha
->flags
.online
= 0;
1435 ha
->flags
.disable_host_adapter
= 0;
1436 ha
->flags
.reset_active
= 0;
1437 ha
->flags
.abort_isp_active
= 0;
1439 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1440 if (ia64_platform_is("sn2")) {
1441 printk(KERN_INFO
"scsi(%li): Enabling SN2 PCI DMA "
1442 "dual channel lockup workaround\n", ha
->host_no
);
1443 ha
->flags
.use_pci_vchannel
= 1;
1444 driver_setup
.no_nvram
= 1;
1448 /* TODO: implement support for the 1040 nvram format */
1450 driver_setup
.no_nvram
= 1;
1452 dprintk(1, "Configure PCI space for adapter...\n");
1456 /* Insure mailbox registers are free. */
1457 WRT_REG_WORD(®
->semaphore
, 0);
1458 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
1459 WRT_REG_WORD(®
->host_cmd
, HC_CLR_HOST_INT
);
1460 RD_REG_WORD(®
->host_cmd
);
1462 if (qla1280_read_nvram(ha
)) {
1463 dprintk(2, "qla1280_initialize_adapter: failed to read "
1468 * It's necessary to grab the spin here as qla1280_mailbox_command
1469 * needs to be able to drop the lock unconditionally to wait
1472 spin_lock_irqsave(ha
->host
->host_lock
, flags
);
1474 status
= qla1280_load_firmware(ha
);
1476 printk(KERN_ERR
"scsi(%li): initialize: pci probe failed!\n",
1481 /* Setup adapter based on NVRAM parameters. */
1482 dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha
->host_no
);
1483 qla1280_nvram_config(ha
);
1485 if (ha
->flags
.disable_host_adapter
) {
1490 status
= qla1280_init_rings(ha
);
1494 /* Issue SCSI reset, if we can't reset twice then bus is dead */
1495 for (bus
= 0; bus
< ha
->ports
; bus
++) {
1496 if (!ha
->bus_settings
[bus
].disable_scsi_reset
&&
1497 qla1280_bus_reset(ha
, bus
) &&
1498 qla1280_bus_reset(ha
, bus
))
1499 ha
->bus_settings
[bus
].scsi_bus_dead
= 1;
1502 ha
->flags
.online
= 1;
1504 spin_unlock_irqrestore(ha
->host
->host_lock
, flags
);
1507 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
1509 LEAVE("qla1280_initialize_adapter");
1515 * Test chip for proper operation.
1518 * ha = adapter block pointer.
1524 qla1280_chip_diag(struct scsi_qla_host
*ha
)
1526 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
1527 struct device_reg __iomem
*reg
= ha
->iobase
;
1531 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®
->id_l
);
1533 dprintk(1, "scsi(%ld): Verifying chip\n", ha
->host_no
);
1535 /* Soft reset chip and wait for it to finish. */
1536 WRT_REG_WORD(®
->ictrl
, ISP_RESET
);
1539 * We can't do a traditional PCI write flush here by reading
1540 * back the register. The card will not respond once the reset
1541 * is in action and we end up with a machine check exception
1542 * instead. Nothing to do but wait and hope for the best.
1543 * A portable pci_write_flush(pdev) call would be very useful here.
1546 data
= qla1280_debounce_register(®
->ictrl
);
1548 * Yet another QLogic gem ;-(
1550 for (cnt
= 1000000; cnt
&& data
& ISP_RESET
; cnt
--) {
1552 data
= RD_REG_WORD(®
->ictrl
);
1558 /* Reset register cleared by chip reset. */
1559 dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
1561 WRT_REG_WORD(®
->cfg_1
, 0);
1563 /* Reset RISC and disable BIOS which
1564 allows RISC to execute out of RAM. */
1565 WRT_REG_WORD(®
->host_cmd
, HC_RESET_RISC
|
1566 HC_RELEASE_RISC
| HC_DISABLE_BIOS
);
1568 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
1569 data
= qla1280_debounce_register(®
->mailbox0
);
1572 * I *LOVE* this code!
1574 for (cnt
= 1000000; cnt
&& data
== MBS_BUSY
; cnt
--) {
1576 data
= RD_REG_WORD(®
->mailbox0
);
1582 /* Check product ID of chip */
1583 dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
1585 if (RD_REG_WORD(®
->mailbox1
) != PROD_ID_1
||
1586 (RD_REG_WORD(®
->mailbox2
) != PROD_ID_2
&&
1587 RD_REG_WORD(®
->mailbox2
) != PROD_ID_2a
) ||
1588 RD_REG_WORD(®
->mailbox3
) != PROD_ID_3
||
1589 RD_REG_WORD(®
->mailbox4
) != PROD_ID_4
) {
1590 printk(KERN_INFO
"qla1280: Wrong product ID = "
1591 "0x%x,0x%x,0x%x,0x%x\n",
1592 RD_REG_WORD(®
->mailbox1
),
1593 RD_REG_WORD(®
->mailbox2
),
1594 RD_REG_WORD(®
->mailbox3
),
1595 RD_REG_WORD(®
->mailbox4
));
1600 * Enable ints early!!!
1602 qla1280_enable_intrs(ha
);
1604 dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
1605 /* Wrap Incoming Mailboxes Test. */
1606 mb
[0] = MBC_MAILBOX_REGISTER_TEST
;
1615 status
= qla1280_mailbox_command(ha
, 0xff, mb
);
1619 if (mb
[1] != 0xAAAA || mb
[2] != 0x5555 || mb
[3] != 0xAA55 ||
1620 mb
[4] != 0x55AA || mb
[5] != 0xA5A5 || mb
[6] != 0x5A5A ||
1622 printk(KERN_INFO
"qla1280: Failed mbox check\n");
1626 dprintk(3, "qla1280_chip_diag: exiting normally\n");
1629 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
1634 qla1280_load_firmware_pio(struct scsi_qla_host
*ha
)
1636 const struct firmware
*fw
;
1637 const __le16
*fw_data
;
1638 uint16_t risc_address
, risc_code_size
;
1639 uint16_t mb
[MAILBOX_REGISTER_COUNT
], i
;
1642 spin_unlock_irq(ha
->host
->host_lock
);
1643 err
= request_firmware(&fw
, ql1280_board_tbl
[ha
->devnum
].fwname
,
1645 spin_lock_irq(ha
->host
->host_lock
);
1647 printk(KERN_ERR
"Failed to load image \"%s\" err %d\n",
1648 ql1280_board_tbl
[ha
->devnum
].fwname
, err
);
1651 if ((fw
->size
% 2) || (fw
->size
< 6)) {
1652 printk(KERN_ERR
"Bogus length %zu in image \"%s\"\n",
1653 fw
->size
, ql1280_board_tbl
[ha
->devnum
].fwname
);
1657 ha
->fwver1
= fw
->data
[0];
1658 ha
->fwver2
= fw
->data
[1];
1659 ha
->fwver3
= fw
->data
[2];
1660 fw_data
= (const __le16
*)&fw
->data
[0];
1661 ha
->fwstart
= __le16_to_cpu(fw_data
[2]);
1663 /* Load RISC code. */
1664 risc_address
= ha
->fwstart
;
1665 fw_data
= (const __le16
*)&fw
->data
[6];
1666 risc_code_size
= (fw
->size
- 6) / 2;
1668 for (i
= 0; i
< risc_code_size
; i
++) {
1669 mb
[0] = MBC_WRITE_RAM_WORD
;
1670 mb
[1] = risc_address
+ i
;
1671 mb
[2] = __le16_to_cpu(fw_data
[i
]);
1673 err
= qla1280_mailbox_command(ha
, BIT_0
| BIT_1
| BIT_2
, mb
);
1675 printk(KERN_ERR
"scsi(%li): Failed to load firmware\n",
1681 release_firmware(fw
);
1685 #define DUMP_IT_BACK 0 /* for debug of RISC loading */
1687 qla1280_load_firmware_dma(struct scsi_qla_host
*ha
)
1689 const struct firmware
*fw
;
1690 const __le16
*fw_data
;
1691 uint16_t risc_address
, risc_code_size
;
1692 uint16_t mb
[MAILBOX_REGISTER_COUNT
], cnt
;
1693 int err
= 0, num
, i
;
1698 tbuf
= pci_alloc_consistent(ha
->pdev
, 8000, &p_tbuf
);
1703 spin_unlock_irq(ha
->host
->host_lock
);
1704 err
= request_firmware(&fw
, ql1280_board_tbl
[ha
->devnum
].fwname
,
1706 spin_lock_irq(ha
->host
->host_lock
);
1708 printk(KERN_ERR
"Failed to load image \"%s\" err %d\n",
1709 ql1280_board_tbl
[ha
->devnum
].fwname
, err
);
1712 if ((fw
->size
% 2) || (fw
->size
< 6)) {
1713 printk(KERN_ERR
"Bogus length %zu in image \"%s\"\n",
1714 fw
->size
, ql1280_board_tbl
[ha
->devnum
].fwname
);
1718 ha
->fwver1
= fw
->data
[0];
1719 ha
->fwver2
= fw
->data
[1];
1720 ha
->fwver3
= fw
->data
[2];
1721 fw_data
= (const __le16
*)&fw
->data
[0];
1722 ha
->fwstart
= __le16_to_cpu(fw_data
[2]);
1724 /* Load RISC code. */
1725 risc_address
= ha
->fwstart
;
1726 fw_data
= (const __le16
*)&fw
->data
[6];
1727 risc_code_size
= (fw
->size
- 6) / 2;
1729 dprintk(1, "%s: DMA RISC code (%i) words\n",
1730 __func__
, risc_code_size
);
1733 while (risc_code_size
> 0) {
1734 int warn
__attribute__((unused
)) = 0;
1738 if (cnt
> risc_code_size
)
1739 cnt
= risc_code_size
;
1741 dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
1743 fw_data
, cnt
, num
, risc_address
);
1744 for(i
= 0; i
< cnt
; i
++)
1745 ((__le16
*)ha
->request_ring
)[i
] = fw_data
[i
];
1747 mb
[0] = MBC_LOAD_RAM
;
1748 mb
[1] = risc_address
;
1750 mb
[3] = ha
->request_dma
& 0xffff;
1751 mb
[2] = (ha
->request_dma
>> 16) & 0xffff;
1752 mb
[7] = pci_dma_hi32(ha
->request_dma
) & 0xffff;
1753 mb
[6] = pci_dma_hi32(ha
->request_dma
) >> 16;
1754 dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
1756 (void *)(long)ha
->request_dma
,
1757 mb
[6], mb
[7], mb
[2], mb
[3]);
1758 err
= qla1280_mailbox_command(ha
, BIT_4
| BIT_3
| BIT_2
|
1761 printk(KERN_ERR
"scsi(%li): Failed to load partial "
1762 "segment of f\n", ha
->host_no
);
1767 mb
[0] = MBC_DUMP_RAM
;
1768 mb
[1] = risc_address
;
1770 mb
[3] = p_tbuf
& 0xffff;
1771 mb
[2] = (p_tbuf
>> 16) & 0xffff;
1772 mb
[7] = pci_dma_hi32(p_tbuf
) & 0xffff;
1773 mb
[6] = pci_dma_hi32(p_tbuf
) >> 16;
1775 err
= qla1280_mailbox_command(ha
, BIT_4
| BIT_3
| BIT_2
|
1779 "Failed to dump partial segment of f/w\n");
1782 sp
= (uint8_t *)ha
->request_ring
;
1783 for (i
= 0; i
< (cnt
<< 1); i
++) {
1784 if (tbuf
[i
] != sp
[i
] && warn
++ < 10) {
1785 printk(KERN_ERR
"%s: FW compare error @ "
1786 "byte(0x%x) loop#=%x\n",
1788 printk(KERN_ERR
"%s: FWbyte=%x "
1790 __func__
, sp
[i
], tbuf
[i
]);
1795 risc_address
+= cnt
;
1796 risc_code_size
= risc_code_size
- cnt
;
1797 fw_data
= fw_data
+ cnt
;
1803 pci_free_consistent(ha
->pdev
, 8000, tbuf
, p_tbuf
);
1805 release_firmware(fw
);
1810 qla1280_start_firmware(struct scsi_qla_host
*ha
)
1812 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
1815 dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
1818 /* Verify checksum of loaded RISC code. */
1819 mb
[0] = MBC_VERIFY_CHECKSUM
;
1820 /* mb[1] = ql12_risc_code_addr01; */
1821 mb
[1] = ha
->fwstart
;
1822 err
= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, mb
);
1824 printk(KERN_ERR
"scsi(%li): RISC checksum failed.\n", ha
->host_no
);
1828 /* Start firmware execution. */
1829 dprintk(1, "%s: start firmware running.\n", __func__
);
1830 mb
[0] = MBC_EXECUTE_FIRMWARE
;
1831 mb
[1] = ha
->fwstart
;
1832 err
= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]);
1834 printk(KERN_ERR
"scsi(%li): Failed to start firmware\n",
1842 qla1280_load_firmware(struct scsi_qla_host
*ha
)
1846 err
= qla1280_chip_diag(ha
);
1850 err
= qla1280_load_firmware_pio(ha
);
1852 err
= qla1280_load_firmware_dma(ha
);
1855 err
= qla1280_start_firmware(ha
);
1864 * ha = adapter block pointer.
1865 * ha->request_ring = request ring virtual address
1866 * ha->response_ring = response ring virtual address
1867 * ha->request_dma = request ring physical address
1868 * ha->response_dma = response ring physical address
1874 qla1280_init_rings(struct scsi_qla_host
*ha
)
1876 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
1879 ENTER("qla1280_init_rings");
1881 /* Clear outstanding commands array. */
1882 memset(ha
->outstanding_cmds
, 0,
1883 sizeof(struct srb
*) * MAX_OUTSTANDING_COMMANDS
);
1885 /* Initialize request queue. */
1886 ha
->request_ring_ptr
= ha
->request_ring
;
1887 ha
->req_ring_index
= 0;
1888 ha
->req_q_cnt
= REQUEST_ENTRY_CNT
;
1889 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
1890 mb
[0] = MBC_INIT_REQUEST_QUEUE_A64
;
1891 mb
[1] = REQUEST_ENTRY_CNT
;
1892 mb
[3] = ha
->request_dma
& 0xffff;
1893 mb
[2] = (ha
->request_dma
>> 16) & 0xffff;
1895 mb
[7] = pci_dma_hi32(ha
->request_dma
) & 0xffff;
1896 mb
[6] = pci_dma_hi32(ha
->request_dma
) >> 16;
1897 if (!(status
= qla1280_mailbox_command(ha
, BIT_7
| BIT_6
| BIT_4
|
1898 BIT_3
| BIT_2
| BIT_1
| BIT_0
,
1900 /* Initialize response queue. */
1901 ha
->response_ring_ptr
= ha
->response_ring
;
1902 ha
->rsp_ring_index
= 0;
1903 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
1904 mb
[0] = MBC_INIT_RESPONSE_QUEUE_A64
;
1905 mb
[1] = RESPONSE_ENTRY_CNT
;
1906 mb
[3] = ha
->response_dma
& 0xffff;
1907 mb
[2] = (ha
->response_dma
>> 16) & 0xffff;
1909 mb
[7] = pci_dma_hi32(ha
->response_dma
) & 0xffff;
1910 mb
[6] = pci_dma_hi32(ha
->response_dma
) >> 16;
1911 status
= qla1280_mailbox_command(ha
, BIT_7
| BIT_6
| BIT_5
|
1912 BIT_3
| BIT_2
| BIT_1
| BIT_0
,
1917 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
1919 LEAVE("qla1280_init_rings");
1924 qla1280_print_settings(struct nvram
*nv
)
1926 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
1927 nv
->bus
[0].config_1
.initiator_id
);
1928 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
1929 nv
->bus
[1].config_1
.initiator_id
);
1931 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
1932 nv
->bus
[0].bus_reset_delay
);
1933 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
1934 nv
->bus
[1].bus_reset_delay
);
1936 dprintk(1, "qla1280 : retry count[0]=%d\n", nv
->bus
[0].retry_count
);
1937 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv
->bus
[0].retry_delay
);
1938 dprintk(1, "qla1280 : retry count[1]=%d\n", nv
->bus
[1].retry_count
);
1939 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv
->bus
[1].retry_delay
);
1941 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
1942 nv
->bus
[0].config_2
.async_data_setup_time
);
1943 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
1944 nv
->bus
[1].config_2
.async_data_setup_time
);
1946 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
1947 nv
->bus
[0].config_2
.req_ack_active_negation
);
1948 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
1949 nv
->bus
[1].config_2
.req_ack_active_negation
);
1951 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
1952 nv
->bus
[0].config_2
.data_line_active_negation
);
1953 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
1954 nv
->bus
[1].config_2
.data_line_active_negation
);
1956 dprintk(1, "qla1280 : disable loading risc code=%d\n",
1957 nv
->cntr_flags_1
.disable_loading_risc_code
);
1959 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
1960 nv
->cntr_flags_1
.enable_64bit_addressing
);
1962 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
1963 nv
->bus
[0].selection_timeout
);
1964 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
1965 nv
->bus
[1].selection_timeout
);
1967 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
1968 nv
->bus
[0].max_queue_depth
);
1969 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
1970 nv
->bus
[1].max_queue_depth
);
1974 qla1280_set_target_defaults(struct scsi_qla_host
*ha
, int bus
, int target
)
1976 struct nvram
*nv
= &ha
->nvram
;
1978 nv
->bus
[bus
].target
[target
].parameter
.renegotiate_on_error
= 1;
1979 nv
->bus
[bus
].target
[target
].parameter
.auto_request_sense
= 1;
1980 nv
->bus
[bus
].target
[target
].parameter
.tag_queuing
= 1;
1981 nv
->bus
[bus
].target
[target
].parameter
.enable_sync
= 1;
1982 #if 1 /* Some SCSI Processors do not seem to like this */
1983 nv
->bus
[bus
].target
[target
].parameter
.enable_wide
= 1;
1985 nv
->bus
[bus
].target
[target
].execution_throttle
=
1986 nv
->bus
[bus
].max_queue_depth
- 1;
1987 nv
->bus
[bus
].target
[target
].parameter
.parity_checking
= 1;
1988 nv
->bus
[bus
].target
[target
].parameter
.disconnect_allowed
= 1;
1990 if (IS_ISP1x160(ha
)) {
1991 nv
->bus
[bus
].target
[target
].flags
.flags1x160
.device_enable
= 1;
1992 nv
->bus
[bus
].target
[target
].flags
.flags1x160
.sync_offset
= 0x0e;
1993 nv
->bus
[bus
].target
[target
].sync_period
= 9;
1994 nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.enable_ppr
= 1;
1995 nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.ppr_options
= 2;
1996 nv
->bus
[bus
].target
[target
].ppr_1x160
.flags
.ppr_bus_width
= 1;
1998 nv
->bus
[bus
].target
[target
].flags
.flags1x80
.device_enable
= 1;
1999 nv
->bus
[bus
].target
[target
].flags
.flags1x80
.sync_offset
= 12;
2000 nv
->bus
[bus
].target
[target
].sync_period
= 10;
2005 qla1280_set_defaults(struct scsi_qla_host
*ha
)
2007 struct nvram
*nv
= &ha
->nvram
;
2010 dprintk(1, "Using defaults for NVRAM: \n");
2011 memset(nv
, 0, sizeof(struct nvram
));
2013 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
2014 nv
->firmware_feature
.f
.enable_fast_posting
= 1;
2015 nv
->firmware_feature
.f
.disable_synchronous_backoff
= 1;
2016 nv
->termination
.scsi_bus_0_control
= 3;
2017 nv
->termination
.scsi_bus_1_control
= 3;
2018 nv
->termination
.auto_term_support
= 1;
2021 * Set default FIFO magic - What appropriate values would be here
2022 * is unknown. This is what I have found testing with 12160s.
2024 * Now, I would love the magic decoder ring for this one, the
2025 * header file provided by QLogic seems to be bogus or incomplete
2028 nv
->isp_config
.burst_enable
= 1;
2030 nv
->isp_config
.fifo_threshold
|= 3;
2032 nv
->isp_config
.fifo_threshold
|= 4;
2034 if (IS_ISP1x160(ha
))
2035 nv
->isp_parameter
= 0x01; /* fast memory enable */
2037 for (bus
= 0; bus
< MAX_BUSES
; bus
++) {
2038 nv
->bus
[bus
].config_1
.initiator_id
= 7;
2039 nv
->bus
[bus
].config_2
.req_ack_active_negation
= 1;
2040 nv
->bus
[bus
].config_2
.data_line_active_negation
= 1;
2041 nv
->bus
[bus
].selection_timeout
= 250;
2042 nv
->bus
[bus
].max_queue_depth
= 32;
2044 if (IS_ISP1040(ha
)) {
2045 nv
->bus
[bus
].bus_reset_delay
= 3;
2046 nv
->bus
[bus
].config_2
.async_data_setup_time
= 6;
2047 nv
->bus
[bus
].retry_delay
= 1;
2049 nv
->bus
[bus
].bus_reset_delay
= 5;
2050 nv
->bus
[bus
].config_2
.async_data_setup_time
= 8;
2053 for (target
= 0; target
< MAX_TARGETS
; target
++)
2054 qla1280_set_target_defaults(ha
, bus
, target
);
2059 qla1280_config_target(struct scsi_qla_host
*ha
, int bus
, int target
)
2061 struct nvram
*nv
= &ha
->nvram
;
2062 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2066 /* Set Target Parameters. */
2067 mb
[0] = MBC_SET_TARGET_PARAMETERS
;
2068 mb
[1] = (uint16_t)((bus
? target
| BIT_7
: target
) << 8);
2071 * Do not enable sync and ppr for the initial INQUIRY run. We
2072 * enable this later if we determine the target actually
2075 mb
[2] = (TP_RENEGOTIATE
| TP_AUTO_REQUEST_SENSE
| TP_TAGGED_QUEUE
2076 | TP_WIDE
| TP_PARITY
| TP_DISCONNECT
);
2078 if (IS_ISP1x160(ha
))
2079 mb
[3] = nv
->bus
[bus
].target
[target
].flags
.flags1x160
.sync_offset
<< 8;
2081 mb
[3] = nv
->bus
[bus
].target
[target
].flags
.flags1x80
.sync_offset
<< 8;
2082 mb
[3] |= nv
->bus
[bus
].target
[target
].sync_period
;
2083 status
= qla1280_mailbox_command(ha
, 0x0f, mb
);
2085 /* Save Tag queuing enable flag. */
2086 flag
= (BIT_0
<< target
);
2087 if (nv
->bus
[bus
].target
[target
].parameter
.tag_queuing
)
2088 ha
->bus_settings
[bus
].qtag_enables
|= flag
;
2090 /* Save Device enable flag. */
2091 if (IS_ISP1x160(ha
)) {
2092 if (nv
->bus
[bus
].target
[target
].flags
.flags1x160
.device_enable
)
2093 ha
->bus_settings
[bus
].device_enables
|= flag
;
2094 ha
->bus_settings
[bus
].lun_disables
|= 0;
2096 if (nv
->bus
[bus
].target
[target
].flags
.flags1x80
.device_enable
)
2097 ha
->bus_settings
[bus
].device_enables
|= flag
;
2098 /* Save LUN disable flag. */
2099 if (nv
->bus
[bus
].target
[target
].flags
.flags1x80
.lun_disable
)
2100 ha
->bus_settings
[bus
].lun_disables
|= flag
;
2103 /* Set Device Queue Parameters. */
2104 for (lun
= 0; lun
< MAX_LUNS
; lun
++) {
2105 mb
[0] = MBC_SET_DEVICE_QUEUE
;
2106 mb
[1] = (uint16_t)((bus
? target
| BIT_7
: target
) << 8);
2108 mb
[2] = nv
->bus
[bus
].max_queue_depth
;
2109 mb
[3] = nv
->bus
[bus
].target
[target
].execution_throttle
;
2110 status
|= qla1280_mailbox_command(ha
, 0x0f, mb
);
2117 qla1280_config_bus(struct scsi_qla_host
*ha
, int bus
)
2119 struct nvram
*nv
= &ha
->nvram
;
2120 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2123 /* SCSI Reset Disable. */
2124 ha
->bus_settings
[bus
].disable_scsi_reset
=
2125 nv
->bus
[bus
].config_1
.scsi_reset_disable
;
2128 ha
->bus_settings
[bus
].id
= nv
->bus
[bus
].config_1
.initiator_id
;
2129 mb
[0] = MBC_SET_INITIATOR_ID
;
2130 mb
[1] = bus
? ha
->bus_settings
[bus
].id
| BIT_7
:
2131 ha
->bus_settings
[bus
].id
;
2132 status
= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]);
2135 ha
->bus_settings
[bus
].bus_reset_delay
=
2136 nv
->bus
[bus
].bus_reset_delay
;
2138 /* Command queue depth per device. */
2139 ha
->bus_settings
[bus
].hiwat
= nv
->bus
[bus
].max_queue_depth
- 1;
2141 /* Set target parameters. */
2142 for (target
= 0; target
< MAX_TARGETS
; target
++)
2143 status
|= qla1280_config_target(ha
, bus
, target
);
2149 qla1280_nvram_config(struct scsi_qla_host
*ha
)
2151 struct device_reg __iomem
*reg
= ha
->iobase
;
2152 struct nvram
*nv
= &ha
->nvram
;
2153 int bus
, target
, status
= 0;
2154 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2156 ENTER("qla1280_nvram_config");
2158 if (ha
->nvram_valid
) {
2159 /* Always force AUTO sense for LINUX SCSI */
2160 for (bus
= 0; bus
< MAX_BUSES
; bus
++)
2161 for (target
= 0; target
< MAX_TARGETS
; target
++) {
2162 nv
->bus
[bus
].target
[target
].parameter
.
2163 auto_request_sense
= 1;
2166 qla1280_set_defaults(ha
);
2169 qla1280_print_settings(nv
);
2171 /* Disable RISC load of firmware. */
2172 ha
->flags
.disable_risc_code_load
=
2173 nv
->cntr_flags_1
.disable_loading_risc_code
;
2175 if (IS_ISP1040(ha
)) {
2176 uint16_t hwrev
, cfg1
, cdma_conf
, ddma_conf
;
2178 hwrev
= RD_REG_WORD(®
->cfg_0
) & ISP_CFG0_HWMSK
;
2180 cfg1
= RD_REG_WORD(®
->cfg_1
) & ~(BIT_4
| BIT_5
| BIT_6
);
2181 cdma_conf
= RD_REG_WORD(®
->cdma_cfg
);
2182 ddma_conf
= RD_REG_WORD(®
->ddma_cfg
);
2184 /* Busted fifo, says mjacob. */
2185 if (hwrev
!= ISP_CFG0_1040A
)
2186 cfg1
|= nv
->isp_config
.fifo_threshold
<< 4;
2188 cfg1
|= nv
->isp_config
.burst_enable
<< 2;
2189 WRT_REG_WORD(®
->cfg_1
, cfg1
);
2191 WRT_REG_WORD(®
->cdma_cfg
, cdma_conf
| CDMA_CONF_BENAB
);
2192 WRT_REG_WORD(®
->ddma_cfg
, cdma_conf
| DDMA_CONF_BENAB
);
2194 uint16_t cfg1
, term
;
2196 /* Set ISP hardware DMA burst */
2197 cfg1
= nv
->isp_config
.fifo_threshold
<< 4;
2198 cfg1
|= nv
->isp_config
.burst_enable
<< 2;
2199 /* Enable DMA arbitration on dual channel controllers */
2202 WRT_REG_WORD(®
->cfg_1
, cfg1
);
2204 /* Set SCSI termination. */
2205 WRT_REG_WORD(®
->gpio_enable
,
2206 BIT_7
| BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2207 term
= nv
->termination
.scsi_bus_1_control
;
2208 term
|= nv
->termination
.scsi_bus_0_control
<< 2;
2209 term
|= nv
->termination
.auto_term_support
<< 7;
2210 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2211 WRT_REG_WORD(®
->gpio_data
, term
);
2213 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2215 /* ISP parameter word. */
2216 mb
[0] = MBC_SET_SYSTEM_PARAMETER
;
2217 mb
[1] = nv
->isp_parameter
;
2218 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]);
2220 if (IS_ISP1x40(ha
)) {
2221 /* clock rate - for qla1240 and older, only */
2222 mb
[0] = MBC_SET_CLOCK_RATE
;
2224 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, mb
);
2227 /* Firmware feature word. */
2228 mb
[0] = MBC_SET_FIRMWARE_FEATURES
;
2229 mb
[1] = nv
->firmware_feature
.f
.enable_fast_posting
;
2230 mb
[1] |= nv
->firmware_feature
.f
.report_lvd_bus_transition
<< 1;
2231 mb
[1] |= nv
->firmware_feature
.f
.disable_synchronous_backoff
<< 5;
2232 #if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
2233 if (ia64_platform_is("sn2")) {
2234 printk(KERN_INFO
"scsi(%li): Enabling SN2 PCI DMA "
2235 "workaround\n", ha
->host_no
);
2236 mb
[1] |= nv
->firmware_feature
.f
.unused_9
<< 9; /* XXX */
2239 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, mb
);
2241 /* Retry count and delay. */
2242 mb
[0] = MBC_SET_RETRY_COUNT
;
2243 mb
[1] = nv
->bus
[0].retry_count
;
2244 mb
[2] = nv
->bus
[0].retry_delay
;
2245 mb
[6] = nv
->bus
[1].retry_count
;
2246 mb
[7] = nv
->bus
[1].retry_delay
;
2247 status
|= qla1280_mailbox_command(ha
, BIT_7
| BIT_6
| BIT_2
|
2248 BIT_1
| BIT_0
, &mb
[0]);
2250 /* ASYNC data setup time. */
2251 mb
[0] = MBC_SET_ASYNC_DATA_SETUP
;
2252 mb
[1] = nv
->bus
[0].config_2
.async_data_setup_time
;
2253 mb
[2] = nv
->bus
[1].config_2
.async_data_setup_time
;
2254 status
|= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
2256 /* Active negation states. */
2257 mb
[0] = MBC_SET_ACTIVE_NEGATION
;
2259 if (nv
->bus
[0].config_2
.req_ack_active_negation
)
2261 if (nv
->bus
[0].config_2
.data_line_active_negation
)
2264 if (nv
->bus
[1].config_2
.req_ack_active_negation
)
2266 if (nv
->bus
[1].config_2
.data_line_active_negation
)
2268 status
|= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, mb
);
2270 mb
[0] = MBC_SET_DATA_OVERRUN_RECOVERY
;
2271 mb
[1] = 2; /* Reset SCSI bus and return all outstanding IO */
2272 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, mb
);
2275 mb
[0] = MBC_SET_PCI_CONTROL
;
2276 mb
[1] = BIT_1
; /* Data DMA Channel Burst Enable */
2277 mb
[2] = BIT_1
; /* Command DMA Channel Burst Enable */
2278 status
|= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, mb
);
2280 mb
[0] = MBC_SET_TAG_AGE_LIMIT
;
2282 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, mb
);
2284 /* Selection timeout. */
2285 mb
[0] = MBC_SET_SELECTION_TIMEOUT
;
2286 mb
[1] = nv
->bus
[0].selection_timeout
;
2287 mb
[2] = nv
->bus
[1].selection_timeout
;
2288 status
|= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, mb
);
2290 for (bus
= 0; bus
< ha
->ports
; bus
++)
2291 status
|= qla1280_config_bus(ha
, bus
);
2294 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
2296 LEAVE("qla1280_nvram_config");
2301 * Get NVRAM data word
2302 * Calculates word position in NVRAM and calls request routine to
2303 * get the word from NVRAM.
2306 * ha = adapter block pointer.
2307 * address = NVRAM word address.
2313 qla1280_get_nvram_word(struct scsi_qla_host
*ha
, uint32_t address
)
2318 nv_cmd
= address
<< 16;
2319 nv_cmd
|= NV_READ_OP
;
2321 data
= le16_to_cpu(qla1280_nvram_request(ha
, nv_cmd
));
2323 dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
2331 * Sends read command to NVRAM and gets data from NVRAM.
2334 * ha = adapter block pointer.
2335 * nv_cmd = Bit 26 = start bit
2336 * Bit 25, 24 = opcode
2337 * Bit 23-16 = address
2338 * Bit 15-0 = write data
2344 qla1280_nvram_request(struct scsi_qla_host
*ha
, uint32_t nv_cmd
)
2346 struct device_reg __iomem
*reg
= ha
->iobase
;
2351 /* Send command to NVRAM. */
2354 for (cnt
= 0; cnt
< 11; cnt
++) {
2355 if (nv_cmd
& BIT_31
)
2356 qla1280_nv_write(ha
, NV_DATA_OUT
);
2358 qla1280_nv_write(ha
, 0);
2362 /* Read data from NVRAM. */
2364 for (cnt
= 0; cnt
< 16; cnt
++) {
2365 WRT_REG_WORD(®
->nvram
, (NV_SELECT
| NV_CLOCK
));
2366 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2369 reg_data
= RD_REG_WORD(®
->nvram
);
2370 if (reg_data
& NV_DATA_IN
)
2372 WRT_REG_WORD(®
->nvram
, NV_SELECT
);
2373 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2377 /* Deselect chip. */
2379 WRT_REG_WORD(®
->nvram
, NV_DESELECT
);
2380 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2387 qla1280_nv_write(struct scsi_qla_host
*ha
, uint16_t data
)
2389 struct device_reg __iomem
*reg
= ha
->iobase
;
2391 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
);
2392 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2394 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
| NV_CLOCK
);
2395 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2397 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
);
2398 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2404 * Issue mailbox command and waits for completion.
2407 * ha = adapter block pointer.
2408 * mr = mailbox registers to load.
2409 * mb = data pointer for mailbox registers.
2412 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
2418 qla1280_mailbox_command(struct scsi_qla_host
*ha
, uint8_t mr
, uint16_t *mb
)
2420 struct device_reg __iomem
*reg
= ha
->iobase
;
2423 uint16_t *optr
, *iptr
;
2424 uint16_t __iomem
*mptr
;
2426 DECLARE_COMPLETION_ONSTACK(wait
);
2427 struct timer_list timer
;
2429 ENTER("qla1280_mailbox_command");
2431 if (ha
->mailbox_wait
) {
2432 printk(KERN_ERR
"Warning mailbox wait already in use!\n");
2434 ha
->mailbox_wait
= &wait
;
2437 * We really should start out by verifying that the mailbox is
2438 * available before starting sending the command data
2440 /* Load mailbox registers. */
2441 mptr
= (uint16_t __iomem
*) ®
->mailbox0
;
2443 for (cnt
= 0; cnt
< MAILBOX_REGISTER_COUNT
; cnt
++) {
2445 WRT_REG_WORD(mptr
, (*iptr
));
2453 /* Issue set host interrupt command. */
2455 /* set up a timer just in case we're really jammed */
2457 timer
.expires
= jiffies
+ 20*HZ
;
2458 timer
.data
= (unsigned long)ha
;
2459 timer
.function
= qla1280_mailbox_timeout
;
2462 spin_unlock_irq(ha
->host
->host_lock
);
2463 WRT_REG_WORD(®
->host_cmd
, HC_SET_HOST_INT
);
2464 data
= qla1280_debounce_register(®
->istatus
);
2466 wait_for_completion(&wait
);
2467 del_timer_sync(&timer
);
2469 spin_lock_irq(ha
->host
->host_lock
);
2471 ha
->mailbox_wait
= NULL
;
2473 /* Check for mailbox command timeout. */
2474 if (ha
->mailbox_out
[0] != MBS_CMD_CMP
) {
2475 printk(KERN_WARNING
"qla1280_mailbox_command: Command failed, "
2476 "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
2478 mb
[0], ha
->mailbox_out
[0], RD_REG_WORD(®
->istatus
));
2479 printk(KERN_WARNING
"m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
2480 RD_REG_WORD(®
->mailbox0
), RD_REG_WORD(®
->mailbox1
),
2481 RD_REG_WORD(®
->mailbox2
), RD_REG_WORD(®
->mailbox3
));
2482 printk(KERN_WARNING
"m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
2483 RD_REG_WORD(®
->mailbox4
), RD_REG_WORD(®
->mailbox5
),
2484 RD_REG_WORD(®
->mailbox6
), RD_REG_WORD(®
->mailbox7
));
2488 /* Load return mailbox registers. */
2490 iptr
= (uint16_t *) &ha
->mailbox_out
[0];
2491 mr
= MAILBOX_REGISTER_COUNT
;
2492 memcpy(optr
, iptr
, MAILBOX_REGISTER_COUNT
* sizeof(uint16_t));
2494 if (ha
->flags
.reset_marker
)
2495 qla1280_rst_aen(ha
);
2498 dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
2499 "0x%x ****\n", mb
[0]);
2501 LEAVE("qla1280_mailbox_command");
2507 * Polls ISP for interrupts.
2510 * ha = adapter block pointer.
2513 qla1280_poll(struct scsi_qla_host
*ha
)
2515 struct device_reg __iomem
*reg
= ha
->iobase
;
2519 /* ENTER("qla1280_poll"); */
2521 /* Check for pending interrupts. */
2522 data
= RD_REG_WORD(®
->istatus
);
2523 if (data
& RISC_INT
)
2524 qla1280_isr(ha
, &done_q
);
2526 if (!ha
->mailbox_wait
) {
2527 if (ha
->flags
.reset_marker
)
2528 qla1280_rst_aen(ha
);
2531 if (!list_empty(&done_q
))
2534 /* LEAVE("qla1280_poll"); */
2539 * Issue SCSI bus reset.
2542 * ha = adapter block pointer.
2543 * bus = SCSI bus number.
2549 qla1280_bus_reset(struct scsi_qla_host
*ha
, int bus
)
2551 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2552 uint16_t reset_delay
;
2555 dprintk(3, "qla1280_bus_reset: entered\n");
2557 if (qla1280_verbose
)
2558 printk(KERN_INFO
"scsi(%li:%i): Resetting SCSI BUS\n",
2561 reset_delay
= ha
->bus_settings
[bus
].bus_reset_delay
;
2562 mb
[0] = MBC_BUS_RESET
;
2563 mb
[1] = reset_delay
;
2564 mb
[2] = (uint16_t) bus
;
2565 status
= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
2568 if (ha
->bus_settings
[bus
].failed_reset_count
> 2)
2569 ha
->bus_settings
[bus
].scsi_bus_dead
= 1;
2570 ha
->bus_settings
[bus
].failed_reset_count
++;
2572 spin_unlock_irq(ha
->host
->host_lock
);
2573 ssleep(reset_delay
);
2574 spin_lock_irq(ha
->host
->host_lock
);
2576 ha
->bus_settings
[bus
].scsi_bus_dead
= 0;
2577 ha
->bus_settings
[bus
].failed_reset_count
= 0;
2578 ha
->bus_settings
[bus
].reset_marker
= 0;
2579 /* Issue marker command. */
2580 qla1280_marker(ha
, bus
, 0, 0, MK_SYNC_ALL
);
2584 * We should probably call qla1280_set_target_parameters()
2585 * here as well for all devices on the bus.
2589 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
2591 dprintk(3, "qla1280_bus_reset: exiting normally\n");
2597 * qla1280_device_reset
2598 * Issue bus device reset message to the target.
2601 * ha = adapter block pointer.
2602 * bus = SCSI BUS number.
2609 qla1280_device_reset(struct scsi_qla_host
*ha
, int bus
, int target
)
2611 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2614 ENTER("qla1280_device_reset");
2616 mb
[0] = MBC_ABORT_TARGET
;
2617 mb
[1] = (bus
? (target
| BIT_7
) : target
) << 8;
2619 status
= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
2621 /* Issue marker command. */
2622 qla1280_marker(ha
, bus
, target
, 0, MK_SYNC_ID
);
2625 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
2627 LEAVE("qla1280_device_reset");
2632 * qla1280_abort_command
2633 * Abort command aborts a specified IOCB.
2636 * ha = adapter block pointer.
2637 * sp = SB structure pointer.
2643 qla1280_abort_command(struct scsi_qla_host
*ha
, struct srb
* sp
, int handle
)
2645 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2646 unsigned int bus
, target
, lun
;
2649 ENTER("qla1280_abort_command");
2651 bus
= SCSI_BUS_32(sp
->cmd
);
2652 target
= SCSI_TCN_32(sp
->cmd
);
2653 lun
= SCSI_LUN_32(sp
->cmd
);
2655 sp
->flags
|= SRB_ABORT_PENDING
;
2657 mb
[0] = MBC_ABORT_COMMAND
;
2658 mb
[1] = (bus
? target
| BIT_7
: target
) << 8 | lun
;
2659 mb
[2] = handle
>> 16;
2660 mb
[3] = handle
& 0xffff;
2661 status
= qla1280_mailbox_command(ha
, 0x0f, &mb
[0]);
2664 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
2665 sp
->flags
&= ~SRB_ABORT_PENDING
;
2669 LEAVE("qla1280_abort_command");
2674 * qla1280_reset_adapter
2678 * ha = adapter block pointer.
2681 qla1280_reset_adapter(struct scsi_qla_host
*ha
)
2683 struct device_reg __iomem
*reg
= ha
->iobase
;
2685 ENTER("qla1280_reset_adapter");
2687 /* Disable ISP chip */
2688 ha
->flags
.online
= 0;
2689 WRT_REG_WORD(®
->ictrl
, ISP_RESET
);
2690 WRT_REG_WORD(®
->host_cmd
,
2691 HC_RESET_RISC
| HC_RELEASE_RISC
| HC_DISABLE_BIOS
);
2692 RD_REG_WORD(®
->id_l
); /* Flush PCI write */
2694 LEAVE("qla1280_reset_adapter");
2698 * Issue marker command.
2699 * Function issues marker IOCB.
2702 * ha = adapter block pointer.
2703 * bus = SCSI BUS number
2706 * type = marker modifier
2709 qla1280_marker(struct scsi_qla_host
*ha
, int bus
, int id
, int lun
, u8 type
)
2711 struct mrk_entry
*pkt
;
2713 ENTER("qla1280_marker");
2715 /* Get request packet. */
2716 if ((pkt
= (struct mrk_entry
*) qla1280_req_pkt(ha
))) {
2717 pkt
->entry_type
= MARKER_TYPE
;
2718 pkt
->lun
= (uint8_t) lun
;
2719 pkt
->target
= (uint8_t) (bus
? (id
| BIT_7
) : id
);
2720 pkt
->modifier
= type
;
2721 pkt
->entry_status
= 0;
2723 /* Issue command to ISP */
2724 qla1280_isp_cmd(ha
);
2727 LEAVE("qla1280_marker");
2732 * qla1280_64bit_start_scsi
2733 * The start SCSI is responsible for building request packets on
2734 * request ring and modifying ISP input pointer.
2737 * ha = adapter block pointer.
2738 * sp = SB structure pointer.
2741 * 0 = success, was able to issue command.
2743 #ifdef QLA_64BIT_PTR
2745 qla1280_64bit_start_scsi(struct scsi_qla_host
*ha
, struct srb
* sp
)
2747 struct device_reg __iomem
*reg
= ha
->iobase
;
2748 struct scsi_cmnd
*cmd
= sp
->cmd
;
2749 cmd_a64_entry_t
*pkt
;
2751 dma_addr_t dma_handle
;
2758 ENTER("qla1280_64bit_start_scsi:");
2760 /* Calculate number of entries and segments required. */
2762 seg_cnt
= scsi_dma_map(cmd
);
2765 req_cnt
+= (seg_cnt
- 2) / 5;
2766 if ((seg_cnt
- 2) % 5)
2769 } else if (seg_cnt
< 0) {
2774 if ((req_cnt
+ 2) >= ha
->req_q_cnt
) {
2775 /* Calculate number of free request entries. */
2776 cnt
= RD_REG_WORD(®
->mailbox4
);
2777 if (ha
->req_ring_index
< cnt
)
2778 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
2781 REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
2784 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
2785 ha
->req_q_cnt
, seg_cnt
);
2787 /* If room for request in request ring. */
2788 if ((req_cnt
+ 2) >= ha
->req_q_cnt
) {
2789 status
= SCSI_MLQUEUE_HOST_BUSY
;
2790 dprintk(2, "qla1280_start_scsi: in-ptr=0x%x req_q_cnt="
2791 "0x%xreq_cnt=0x%x", ha
->req_ring_index
, ha
->req_q_cnt
,
2796 /* Check for room in outstanding command list. */
2797 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
&&
2798 ha
->outstanding_cmds
[cnt
] != NULL
; cnt
++);
2800 if (cnt
>= MAX_OUTSTANDING_COMMANDS
) {
2801 status
= SCSI_MLQUEUE_HOST_BUSY
;
2802 dprintk(2, "qla1280_start_scsi: NO ROOM IN "
2803 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha
->req_q_cnt
);
2807 ha
->outstanding_cmds
[cnt
] = sp
;
2808 ha
->req_q_cnt
-= req_cnt
;
2809 CMD_HANDLE(sp
->cmd
) = (unsigned char *)(unsigned long)(cnt
+ 1);
2811 dprintk(2, "start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd
, sp
,
2812 cmd
->cmnd
[0], (long)CMD_HANDLE(sp
->cmd
));
2813 dprintk(2, " bus %i, target %i, lun %i\n",
2814 SCSI_BUS_32(cmd
), SCSI_TCN_32(cmd
), SCSI_LUN_32(cmd
));
2815 qla1280_dump_buffer(2, cmd
->cmnd
, MAX_COMMAND_SIZE
);
2818 * Build command packet.
2820 pkt
= (cmd_a64_entry_t
*) ha
->request_ring_ptr
;
2822 pkt
->entry_type
= COMMAND_A64_TYPE
;
2823 pkt
->entry_count
= (uint8_t) req_cnt
;
2824 pkt
->sys_define
= (uint8_t) ha
->req_ring_index
;
2825 pkt
->entry_status
= 0;
2826 pkt
->handle
= cpu_to_le32(cnt
);
2828 /* Zero out remaining portion of packet. */
2829 memset(((char *)pkt
+ 8), 0, (REQUEST_ENTRY_SIZE
- 8));
2831 /* Set ISP command timeout. */
2832 pkt
->timeout
= cpu_to_le16(cmd
->request
->timeout
/HZ
);
2834 /* Set device target ID and LUN */
2835 pkt
->lun
= SCSI_LUN_32(cmd
);
2836 pkt
->target
= SCSI_BUS_32(cmd
) ?
2837 (SCSI_TCN_32(cmd
) | BIT_7
) : SCSI_TCN_32(cmd
);
2839 /* Enable simple tag queuing if device supports it. */
2840 if (cmd
->device
->simple_tags
)
2841 pkt
->control_flags
|= cpu_to_le16(BIT_3
);
2843 /* Load SCSI command packet. */
2844 pkt
->cdb_len
= cpu_to_le16(CMD_CDBLEN(cmd
));
2845 memcpy(pkt
->scsi_cdb
, CMD_CDBP(cmd
), CMD_CDBLEN(cmd
));
2846 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
2848 /* Set transfer direction. */
2849 dir
= qla1280_data_direction(cmd
);
2850 pkt
->control_flags
|= cpu_to_le16(dir
);
2852 /* Set total data segment count. */
2853 pkt
->dseg_count
= cpu_to_le16(seg_cnt
);
2856 * Load data segments.
2858 if (seg_cnt
) { /* If data transfer. */
2859 struct scatterlist
*sg
, *s
;
2860 int remseg
= seg_cnt
;
2862 sg
= scsi_sglist(cmd
);
2864 /* Setup packet address segment pointer. */
2865 dword_ptr
= (u32
*)&pkt
->dseg_0_address
;
2867 /* Load command entry data segments. */
2868 for_each_sg(sg
, s
, seg_cnt
, cnt
) {
2872 dma_handle
= sg_dma_address(s
);
2873 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2874 if (ha
->flags
.use_pci_vchannel
)
2875 sn_pci_set_vchan(ha
->pdev
,
2876 (unsigned long *)&dma_handle
,
2880 cpu_to_le32(pci_dma_lo32(dma_handle
));
2882 cpu_to_le32(pci_dma_hi32(dma_handle
));
2883 *dword_ptr
++ = cpu_to_le32(sg_dma_len(s
));
2884 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
2885 cpu_to_le32(pci_dma_hi32(dma_handle
)),
2886 cpu_to_le32(pci_dma_lo32(dma_handle
)),
2887 cpu_to_le32(sg_dma_len(sg_next(s
))));
2890 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
2891 "command packet data - b %i, t %i, l %i \n",
2892 SCSI_BUS_32(cmd
), SCSI_TCN_32(cmd
),
2894 qla1280_dump_buffer(5, (char *)pkt
,
2895 REQUEST_ENTRY_SIZE
);
2898 * Build continuation packets.
2900 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
2901 "remains\n", seg_cnt
);
2903 while (remseg
> 0) {
2904 /* Update sg start */
2906 /* Adjust ring index. */
2907 ha
->req_ring_index
++;
2908 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
2909 ha
->req_ring_index
= 0;
2910 ha
->request_ring_ptr
=
2913 ha
->request_ring_ptr
++;
2915 pkt
= (cmd_a64_entry_t
*)ha
->request_ring_ptr
;
2917 /* Zero out packet. */
2918 memset(pkt
, 0, REQUEST_ENTRY_SIZE
);
2920 /* Load packet defaults. */
2921 ((struct cont_a64_entry
*) pkt
)->entry_type
=
2923 ((struct cont_a64_entry
*) pkt
)->entry_count
= 1;
2924 ((struct cont_a64_entry
*) pkt
)->sys_define
=
2925 (uint8_t)ha
->req_ring_index
;
2926 /* Setup packet address segment pointer. */
2928 (u32
*)&((struct cont_a64_entry
*) pkt
)->dseg_0_address
;
2930 /* Load continuation entry data segments. */
2931 for_each_sg(sg
, s
, remseg
, cnt
) {
2934 dma_handle
= sg_dma_address(s
);
2935 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2936 if (ha
->flags
.use_pci_vchannel
)
2937 sn_pci_set_vchan(ha
->pdev
,
2938 (unsigned long *)&dma_handle
,
2942 cpu_to_le32(pci_dma_lo32(dma_handle
));
2944 cpu_to_le32(pci_dma_hi32(dma_handle
));
2946 cpu_to_le32(sg_dma_len(s
));
2947 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
2948 cpu_to_le32(pci_dma_hi32(dma_handle
)),
2949 cpu_to_le32(pci_dma_lo32(dma_handle
)),
2950 cpu_to_le32(sg_dma_len(s
)));
2953 dprintk(5, "qla1280_64bit_start_scsi: "
2954 "continuation packet data - b %i, t "
2955 "%i, l %i \n", SCSI_BUS_32(cmd
),
2956 SCSI_TCN_32(cmd
), SCSI_LUN_32(cmd
));
2957 qla1280_dump_buffer(5, (char *)pkt
,
2958 REQUEST_ENTRY_SIZE
);
2960 } else { /* No data transfer */
2961 dprintk(5, "qla1280_64bit_start_scsi: No data, command "
2962 "packet data - b %i, t %i, l %i \n",
2963 SCSI_BUS_32(cmd
), SCSI_TCN_32(cmd
), SCSI_LUN_32(cmd
));
2964 qla1280_dump_buffer(5, (char *)pkt
, REQUEST_ENTRY_SIZE
);
2966 /* Adjust ring index. */
2967 ha
->req_ring_index
++;
2968 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
2969 ha
->req_ring_index
= 0;
2970 ha
->request_ring_ptr
= ha
->request_ring
;
2972 ha
->request_ring_ptr
++;
2974 /* Set chip new ring index. */
2976 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
2977 sp
->flags
|= SRB_SENT
;
2979 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
2980 /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
2985 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
2987 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
2991 #else /* !QLA_64BIT_PTR */
2994 * qla1280_32bit_start_scsi
2995 * The start SCSI is responsible for building request packets on
2996 * request ring and modifying ISP input pointer.
2998 * The Qlogic firmware interface allows every queue slot to have a SCSI
2999 * command and up to 4 scatter/gather (SG) entries. If we need more
3000 * than 4 SG entries, then continuation entries are used that can
3001 * hold another 7 entries each. The start routine determines if there
3002 * is eought empty slots then build the combination of requests to
3003 * fulfill the OS request.
3006 * ha = adapter block pointer.
3007 * sp = SCSI Request Block structure pointer.
3010 * 0 = success, was able to issue command.
3013 qla1280_32bit_start_scsi(struct scsi_qla_host
*ha
, struct srb
* sp
)
3015 struct device_reg __iomem
*reg
= ha
->iobase
;
3016 struct scsi_cmnd
*cmd
= sp
->cmd
;
3017 struct cmd_entry
*pkt
;
3025 ENTER("qla1280_32bit_start_scsi");
3027 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd
, sp
,
3030 /* Calculate number of entries and segments required. */
3032 seg_cnt
= scsi_dma_map(cmd
);
3035 * if greater than four sg entries then we need to allocate
3036 * continuation entries
3039 req_cnt
+= (seg_cnt
- 4) / 7;
3040 if ((seg_cnt
- 4) % 7)
3043 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3044 cmd
, seg_cnt
, req_cnt
);
3045 } else if (seg_cnt
< 0) {
3050 if ((req_cnt
+ 2) >= ha
->req_q_cnt
) {
3051 /* Calculate number of free request entries. */
3052 cnt
= RD_REG_WORD(®
->mailbox4
);
3053 if (ha
->req_ring_index
< cnt
)
3054 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
3057 REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
3060 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3061 ha
->req_q_cnt
, seg_cnt
);
3062 /* If room for request in request ring. */
3063 if ((req_cnt
+ 2) >= ha
->req_q_cnt
) {
3064 status
= SCSI_MLQUEUE_HOST_BUSY
;
3065 dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
3066 "req_q_cnt=0x%x, req_cnt=0x%x", ha
->req_ring_index
,
3067 ha
->req_q_cnt
, req_cnt
);
3071 /* Check for empty slot in outstanding command list. */
3072 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
&&
3073 (ha
->outstanding_cmds
[cnt
] != 0); cnt
++) ;
3075 if (cnt
>= MAX_OUTSTANDING_COMMANDS
) {
3076 status
= SCSI_MLQUEUE_HOST_BUSY
;
3077 dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
3078 "ARRAY, req_q_cnt=0x%x\n", ha
->req_q_cnt
);
3082 CMD_HANDLE(sp
->cmd
) = (unsigned char *) (unsigned long)(cnt
+ 1);
3083 ha
->outstanding_cmds
[cnt
] = sp
;
3084 ha
->req_q_cnt
-= req_cnt
;
3087 * Build command packet.
3089 pkt
= (struct cmd_entry
*) ha
->request_ring_ptr
;
3091 pkt
->entry_type
= COMMAND_TYPE
;
3092 pkt
->entry_count
= (uint8_t) req_cnt
;
3093 pkt
->sys_define
= (uint8_t) ha
->req_ring_index
;
3094 pkt
->entry_status
= 0;
3095 pkt
->handle
= cpu_to_le32(cnt
);
3097 /* Zero out remaining portion of packet. */
3098 memset(((char *)pkt
+ 8), 0, (REQUEST_ENTRY_SIZE
- 8));
3100 /* Set ISP command timeout. */
3101 pkt
->timeout
= cpu_to_le16(cmd
->request
->timeout
/HZ
);
3103 /* Set device target ID and LUN */
3104 pkt
->lun
= SCSI_LUN_32(cmd
);
3105 pkt
->target
= SCSI_BUS_32(cmd
) ?
3106 (SCSI_TCN_32(cmd
) | BIT_7
) : SCSI_TCN_32(cmd
);
3108 /* Enable simple tag queuing if device supports it. */
3109 if (cmd
->device
->simple_tags
)
3110 pkt
->control_flags
|= cpu_to_le16(BIT_3
);
3112 /* Load SCSI command packet. */
3113 pkt
->cdb_len
= cpu_to_le16(CMD_CDBLEN(cmd
));
3114 memcpy(pkt
->scsi_cdb
, CMD_CDBP(cmd
), CMD_CDBLEN(cmd
));
3116 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3117 /* Set transfer direction. */
3118 dir
= qla1280_data_direction(cmd
);
3119 pkt
->control_flags
|= cpu_to_le16(dir
);
3121 /* Set total data segment count. */
3122 pkt
->dseg_count
= cpu_to_le16(seg_cnt
);
3125 * Load data segments.
3128 struct scatterlist
*sg
, *s
;
3129 int remseg
= seg_cnt
;
3131 sg
= scsi_sglist(cmd
);
3133 /* Setup packet address segment pointer. */
3134 dword_ptr
= &pkt
->dseg_0_address
;
3136 dprintk(3, "Building S/G data segments..\n");
3137 qla1280_dump_buffer(1, (char *)sg
, 4 * 16);
3139 /* Load command entry data segments. */
3140 for_each_sg(sg
, s
, seg_cnt
, cnt
) {
3144 cpu_to_le32(pci_dma_lo32(sg_dma_address(s
)));
3145 *dword_ptr
++ = cpu_to_le32(sg_dma_len(s
));
3146 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3147 (pci_dma_lo32(sg_dma_address(s
))),
3152 * Build continuation packets.
3154 dprintk(3, "S/G Building Continuation"
3155 "...seg_cnt=0x%x remains\n", seg_cnt
);
3156 while (remseg
> 0) {
3157 /* Continue from end point */
3159 /* Adjust ring index. */
3160 ha
->req_ring_index
++;
3161 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
3162 ha
->req_ring_index
= 0;
3163 ha
->request_ring_ptr
=
3166 ha
->request_ring_ptr
++;
3168 pkt
= (struct cmd_entry
*)ha
->request_ring_ptr
;
3170 /* Zero out packet. */
3171 memset(pkt
, 0, REQUEST_ENTRY_SIZE
);
3173 /* Load packet defaults. */
3174 ((struct cont_entry
*) pkt
)->
3175 entry_type
= CONTINUE_TYPE
;
3176 ((struct cont_entry
*) pkt
)->entry_count
= 1;
3178 ((struct cont_entry
*) pkt
)->sys_define
=
3179 (uint8_t) ha
->req_ring_index
;
3181 /* Setup packet address segment pointer. */
3183 &((struct cont_entry
*) pkt
)->dseg_0_address
;
3185 /* Load continuation entry data segments. */
3186 for_each_sg(sg
, s
, remseg
, cnt
) {
3190 cpu_to_le32(pci_dma_lo32(sg_dma_address(s
)));
3192 cpu_to_le32(sg_dma_len(s
));
3194 "S/G Segment Cont. phys_addr=0x%x, "
3196 cpu_to_le32(pci_dma_lo32(sg_dma_address(s
))),
3197 cpu_to_le32(sg_dma_len(s
)));
3200 dprintk(5, "qla1280_32bit_start_scsi: "
3201 "continuation packet data - "
3202 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd
),
3203 SCSI_TCN_32(cmd
), SCSI_LUN_32(cmd
));
3204 qla1280_dump_buffer(5, (char *)pkt
,
3205 REQUEST_ENTRY_SIZE
);
3207 } else { /* No data transfer at all */
3208 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
3209 "packet data - \n");
3210 qla1280_dump_buffer(5, (char *)pkt
, REQUEST_ENTRY_SIZE
);
3212 dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
3213 qla1280_dump_buffer(5, (char *)ha
->request_ring_ptr
,
3214 REQUEST_ENTRY_SIZE
);
3216 /* Adjust ring index. */
3217 ha
->req_ring_index
++;
3218 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
3219 ha
->req_ring_index
= 0;
3220 ha
->request_ring_ptr
= ha
->request_ring
;
3222 ha
->request_ring_ptr
++;
3224 /* Set chip new ring index. */
3225 dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
3226 "for pending command\n");
3227 sp
->flags
|= SRB_SENT
;
3229 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
3230 /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
3235 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
3237 LEAVE("qla1280_32bit_start_scsi");
3245 * Function is responsible for locking ring and
3246 * getting a zeroed out request packet.
3249 * ha = adapter block pointer.
3252 * 0 = failed to get slot.
3255 qla1280_req_pkt(struct scsi_qla_host
*ha
)
3257 struct device_reg __iomem
*reg
= ha
->iobase
;
3258 request_t
*pkt
= NULL
;
3262 ENTER("qla1280_req_pkt");
3265 * This can be called from interrupt context, damn it!!!
3267 /* Wait for 30 seconds for slot. */
3268 for (timer
= 15000000; timer
; timer
--) {
3269 if (ha
->req_q_cnt
> 0) {
3270 /* Calculate number of free request entries. */
3271 cnt
= RD_REG_WORD(®
->mailbox4
);
3272 if (ha
->req_ring_index
< cnt
)
3273 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
3276 REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
3279 /* Found empty request ring slot? */
3280 if (ha
->req_q_cnt
> 0) {
3282 pkt
= ha
->request_ring_ptr
;
3284 /* Zero out packet. */
3285 memset(pkt
, 0, REQUEST_ENTRY_SIZE
);
3288 * How can this be right when we have a ring
3291 /* Set system defined field. */
3292 pkt
->sys_define
= (uint8_t) ha
->req_ring_index
;
3294 /* Set entry count. */
3295 pkt
->entry_count
= 1;
3302 /* Check for pending interrupts. */
3307 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
3309 dprintk(3, "qla1280_req_pkt: exiting normally\n");
3316 * Function is responsible for modifying ISP input pointer.
3317 * Releases ring lock.
3320 * ha = adapter block pointer.
3323 qla1280_isp_cmd(struct scsi_qla_host
*ha
)
3325 struct device_reg __iomem
*reg
= ha
->iobase
;
3327 ENTER("qla1280_isp_cmd");
3329 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
3330 qla1280_dump_buffer(5, (char *)ha
->request_ring_ptr
,
3331 REQUEST_ENTRY_SIZE
);
3333 /* Adjust ring index. */
3334 ha
->req_ring_index
++;
3335 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
3336 ha
->req_ring_index
= 0;
3337 ha
->request_ring_ptr
= ha
->request_ring
;
3339 ha
->request_ring_ptr
++;
3342 * Update request index to mailbox4 (Request Queue In).
3343 * The mmiowb() ensures that this write is ordered with writes by other
3344 * CPUs. Without the mmiowb(), it is possible for the following:
3345 * CPUA posts write of index 5 to mailbox4
3346 * CPUA releases host lock
3347 * CPUB acquires host lock
3348 * CPUB posts write of index 6 to mailbox4
3349 * On PCI bus, order reverses and write of 6 posts, then index 5,
3350 * causing chip to issue full queue of stale commands
3351 * The mmiowb() prevents future writes from crossing the barrier.
3352 * See Documentation/DocBook/deviceiobook.tmpl for more information.
3354 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
3357 LEAVE("qla1280_isp_cmd");
3360 /****************************************************************************/
3361 /* Interrupt Service Routine. */
3362 /****************************************************************************/
3364 /****************************************************************************
3366 * Calls I/O done on command completion.
3369 * ha = adapter block pointer.
3370 * done_q = done queue.
3371 ****************************************************************************/
3373 qla1280_isr(struct scsi_qla_host
*ha
, struct list_head
*done_q
)
3375 struct device_reg __iomem
*reg
= ha
->iobase
;
3376 struct response
*pkt
;
3377 struct srb
*sp
= NULL
;
3378 uint16_t mailbox
[MAILBOX_REGISTER_COUNT
];
3383 ENTER("qla1280_isr");
3385 istatus
= RD_REG_WORD(®
->istatus
);
3386 if (!(istatus
& (RISC_INT
| PCI_INT
)))
3389 /* Save mailbox register 5 */
3390 mailbox
[5] = RD_REG_WORD(®
->mailbox5
);
3392 /* Check for mailbox interrupt. */
3394 mailbox
[0] = RD_REG_WORD_dmasync(®
->semaphore
);
3396 if (mailbox
[0] & BIT_0
) {
3397 /* Get mailbox data. */
3398 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
3401 *wptr
++ = RD_REG_WORD(®
->mailbox0
);
3402 *wptr
++ = RD_REG_WORD(®
->mailbox1
);
3403 *wptr
= RD_REG_WORD(®
->mailbox2
);
3404 if (mailbox
[0] != MBA_SCSI_COMPLETION
) {
3406 *wptr
++ = RD_REG_WORD(®
->mailbox3
);
3407 *wptr
++ = RD_REG_WORD(®
->mailbox4
);
3409 *wptr
++ = RD_REG_WORD(®
->mailbox6
);
3410 *wptr
= RD_REG_WORD(®
->mailbox7
);
3413 /* Release mailbox registers. */
3415 WRT_REG_WORD(®
->semaphore
, 0);
3416 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
3418 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
3421 /* Handle asynchronous event */
3422 switch (mailbox
[0]) {
3423 case MBA_SCSI_COMPLETION
: /* Response completion */
3424 dprintk(5, "qla1280_isr: mailbox SCSI response "
3427 if (ha
->flags
.online
) {
3428 /* Get outstanding command index. */
3429 index
= mailbox
[2] << 16 | mailbox
[1];
3431 /* Validate handle. */
3432 if (index
< MAX_OUTSTANDING_COMMANDS
)
3433 sp
= ha
->outstanding_cmds
[index
];
3438 /* Free outstanding command slot. */
3439 ha
->outstanding_cmds
[index
] = NULL
;
3441 /* Save ISP completion status */
3442 CMD_RESULT(sp
->cmd
) = 0;
3443 CMD_HANDLE(sp
->cmd
) = COMPLETED_HANDLE
;
3445 /* Place block on done queue */
3446 list_add_tail(&sp
->list
, done_q
);
3449 * If we get here we have a real problem!
3452 "qla1280: ISP invalid handle\n");
3457 case MBA_BUS_RESET
: /* SCSI Bus Reset */
3458 ha
->flags
.reset_marker
= 1;
3459 index
= mailbox
[6] & BIT_0
;
3460 ha
->bus_settings
[index
].reset_marker
= 1;
3462 printk(KERN_DEBUG
"qla1280_isr(): index %i "
3463 "asynchronous BUS_RESET\n", index
);
3466 case MBA_SYSTEM_ERR
: /* System Error */
3468 "qla1280: ISP System Error - mbx1=%xh, mbx2="
3469 "%xh, mbx3=%xh\n", mailbox
[1], mailbox
[2],
3473 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
3475 "qla1280: ISP Request Transfer Error\n");
3478 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
3480 "qla1280: ISP Response Transfer Error\n");
3483 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up */
3484 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
3487 case MBA_TIMEOUT_RESET
: /* Execution Timeout Reset */
3489 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
3492 case MBA_DEVICE_RESET
: /* Bus Device Reset */
3493 printk(KERN_INFO
"qla1280_isr(): asynchronous "
3494 "BUS_DEVICE_RESET\n");
3496 ha
->flags
.reset_marker
= 1;
3497 index
= mailbox
[6] & BIT_0
;
3498 ha
->bus_settings
[index
].reset_marker
= 1;
3501 case MBA_BUS_MODE_CHANGE
:
3503 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
3507 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
3508 if (mailbox
[0] < MBA_ASYNC_EVENT
) {
3510 memcpy((uint16_t *) ha
->mailbox_out
, wptr
,
3511 MAILBOX_REGISTER_COUNT
*
3514 if(ha
->mailbox_wait
!= NULL
)
3515 complete(ha
->mailbox_wait
);
3520 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
3524 * We will receive interrupts during mailbox testing prior to
3525 * the card being marked online, hence the double check.
3527 if (!(ha
->flags
.online
&& !ha
->mailbox_wait
)) {
3528 dprintk(2, "qla1280_isr: Response pointer Error\n");
3532 if (mailbox
[5] >= RESPONSE_ENTRY_CNT
)
3535 while (ha
->rsp_ring_index
!= mailbox
[5]) {
3536 pkt
= ha
->response_ring_ptr
;
3538 dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
3539 " = 0x%x\n", ha
->rsp_ring_index
, mailbox
[5]);
3540 dprintk(5,"qla1280_isr: response packet data\n");
3541 qla1280_dump_buffer(5, (char *)pkt
, RESPONSE_ENTRY_SIZE
);
3543 if (pkt
->entry_type
== STATUS_TYPE
) {
3544 if ((le16_to_cpu(pkt
->scsi_status
) & 0xff)
3545 || pkt
->comp_status
|| pkt
->entry_status
) {
3546 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3547 "0x%x mailbox[5] = 0x%x, comp_status "
3548 "= 0x%x, scsi_status = 0x%x\n",
3549 ha
->rsp_ring_index
, mailbox
[5],
3550 le16_to_cpu(pkt
->comp_status
),
3551 le16_to_cpu(pkt
->scsi_status
));
3554 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3555 "0x%x, mailbox[5] = 0x%x\n",
3556 ha
->rsp_ring_index
, mailbox
[5]);
3557 dprintk(2, "qla1280_isr: response packet data\n");
3558 qla1280_dump_buffer(2, (char *)pkt
,
3559 RESPONSE_ENTRY_SIZE
);
3562 if (pkt
->entry_type
== STATUS_TYPE
|| pkt
->entry_status
) {
3563 dprintk(2, "status: Cmd %p, handle %i\n",
3564 ha
->outstanding_cmds
[pkt
->handle
]->cmd
,
3566 if (pkt
->entry_type
== STATUS_TYPE
)
3567 qla1280_status_entry(ha
, pkt
, done_q
);
3569 qla1280_error_entry(ha
, pkt
, done_q
);
3570 /* Adjust ring index. */
3571 ha
->rsp_ring_index
++;
3572 if (ha
->rsp_ring_index
== RESPONSE_ENTRY_CNT
) {
3573 ha
->rsp_ring_index
= 0;
3574 ha
->response_ring_ptr
= ha
->response_ring
;
3576 ha
->response_ring_ptr
++;
3577 WRT_REG_WORD(®
->mailbox5
, ha
->rsp_ring_index
);
3582 LEAVE("qla1280_isr");
3587 * Processes asynchronous reset.
3590 * ha = adapter block pointer.
3593 qla1280_rst_aen(struct scsi_qla_host
*ha
)
3597 ENTER("qla1280_rst_aen");
3599 if (ha
->flags
.online
&& !ha
->flags
.reset_active
&&
3600 !ha
->flags
.abort_isp_active
) {
3601 ha
->flags
.reset_active
= 1;
3602 while (ha
->flags
.reset_marker
) {
3603 /* Issue marker command. */
3604 ha
->flags
.reset_marker
= 0;
3605 for (bus
= 0; bus
< ha
->ports
&&
3606 !ha
->flags
.reset_marker
; bus
++) {
3607 if (ha
->bus_settings
[bus
].reset_marker
) {
3608 ha
->bus_settings
[bus
].reset_marker
= 0;
3609 qla1280_marker(ha
, bus
, 0, 0,
3616 LEAVE("qla1280_rst_aen");
3621 * qla1280_status_entry
3622 * Processes received ISP status entry.
3625 * ha = adapter block pointer.
3626 * pkt = entry pointer.
3627 * done_q = done queue.
3630 qla1280_status_entry(struct scsi_qla_host
*ha
, struct response
*pkt
,
3631 struct list_head
*done_q
)
3633 unsigned int bus
, target
, lun
;
3636 struct scsi_cmnd
*cmd
;
3637 uint32_t handle
= le32_to_cpu(pkt
->handle
);
3638 uint16_t scsi_status
= le16_to_cpu(pkt
->scsi_status
);
3639 uint16_t comp_status
= le16_to_cpu(pkt
->comp_status
);
3641 ENTER("qla1280_status_entry");
3643 /* Validate handle. */
3644 if (handle
< MAX_OUTSTANDING_COMMANDS
)
3645 sp
= ha
->outstanding_cmds
[handle
];
3650 printk(KERN_WARNING
"qla1280: Status Entry invalid handle\n");
3654 /* Free outstanding command slot. */
3655 ha
->outstanding_cmds
[handle
] = NULL
;
3659 /* Generate LU queue on cntrl, target, LUN */
3660 bus
= SCSI_BUS_32(cmd
);
3661 target
= SCSI_TCN_32(cmd
);
3662 lun
= SCSI_LUN_32(cmd
);
3664 if (comp_status
|| scsi_status
) {
3665 dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
3666 "0x%x, handle = 0x%x\n", comp_status
,
3667 scsi_status
, handle
);
3670 /* Target busy or queue full */
3671 if ((scsi_status
& 0xFF) == SAM_STAT_TASK_SET_FULL
||
3672 (scsi_status
& 0xFF) == SAM_STAT_BUSY
) {
3673 CMD_RESULT(cmd
) = scsi_status
& 0xff;
3676 /* Save ISP completion status */
3677 CMD_RESULT(cmd
) = qla1280_return_status(pkt
, cmd
);
3679 if (scsi_status
& SAM_STAT_CHECK_CONDITION
) {
3680 if (comp_status
!= CS_ARS_FAILED
) {
3681 uint16_t req_sense_length
=
3682 le16_to_cpu(pkt
->req_sense_length
);
3683 if (req_sense_length
< CMD_SNSLEN(cmd
))
3684 sense_sz
= req_sense_length
;
3687 * scsi_cmnd->sense_buffer is
3688 * 64 bytes, why only copy 63?
3689 * This looks wrong! /Jes
3691 sense_sz
= CMD_SNSLEN(cmd
) - 1;
3693 memcpy(cmd
->sense_buffer
,
3694 &pkt
->req_sense_data
, sense_sz
);
3697 memset(cmd
->sense_buffer
+ sense_sz
, 0,
3698 SCSI_SENSE_BUFFERSIZE
- sense_sz
);
3700 dprintk(2, "qla1280_status_entry: Check "
3701 "condition Sense data, b %i, t %i, "
3702 "l %i\n", bus
, target
, lun
);
3704 qla1280_dump_buffer(2,
3705 (char *)cmd
->sense_buffer
,
3710 CMD_HANDLE(sp
->cmd
) = COMPLETED_HANDLE
;
3712 /* Place command on done queue. */
3713 list_add_tail(&sp
->list
, done_q
);
3715 LEAVE("qla1280_status_entry");
3719 * qla1280_error_entry
3720 * Processes error entry.
3723 * ha = adapter block pointer.
3724 * pkt = entry pointer.
3725 * done_q = done queue.
3728 qla1280_error_entry(struct scsi_qla_host
*ha
, struct response
*pkt
,
3729 struct list_head
*done_q
)
3732 uint32_t handle
= le32_to_cpu(pkt
->handle
);
3734 ENTER("qla1280_error_entry");
3736 if (pkt
->entry_status
& BIT_3
)
3737 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
3738 else if (pkt
->entry_status
& BIT_2
)
3739 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
3740 else if (pkt
->entry_status
& BIT_1
)
3741 dprintk(2, "qla1280_error_entry: FULL flag error\n");
3743 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
3745 /* Validate handle. */
3746 if (handle
< MAX_OUTSTANDING_COMMANDS
)
3747 sp
= ha
->outstanding_cmds
[handle
];
3752 /* Free outstanding command slot. */
3753 ha
->outstanding_cmds
[handle
] = NULL
;
3755 /* Bad payload or header */
3756 if (pkt
->entry_status
& (BIT_3
+ BIT_2
)) {
3757 /* Bad payload or header, set error status. */
3758 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
3759 CMD_RESULT(sp
->cmd
) = DID_ERROR
<< 16;
3760 } else if (pkt
->entry_status
& BIT_1
) { /* FULL flag */
3761 CMD_RESULT(sp
->cmd
) = DID_BUS_BUSY
<< 16;
3763 /* Set error status. */
3764 CMD_RESULT(sp
->cmd
) = DID_ERROR
<< 16;
3767 CMD_HANDLE(sp
->cmd
) = COMPLETED_HANDLE
;
3769 /* Place command on done queue. */
3770 list_add_tail(&sp
->list
, done_q
);
3772 #ifdef QLA_64BIT_PTR
3773 else if (pkt
->entry_type
== COMMAND_A64_TYPE
) {
3774 printk(KERN_WARNING
"!qla1280: Error Entry invalid handle");
3778 LEAVE("qla1280_error_entry");
3783 * Resets ISP and aborts all outstanding commands.
3786 * ha = adapter block pointer.
3792 qla1280_abort_isp(struct scsi_qla_host
*ha
)
3794 struct device_reg __iomem
*reg
= ha
->iobase
;
3800 ENTER("qla1280_abort_isp");
3802 if (ha
->flags
.abort_isp_active
|| !ha
->flags
.online
)
3805 ha
->flags
.abort_isp_active
= 1;
3807 /* Disable ISP interrupts. */
3808 qla1280_disable_intrs(ha
);
3809 WRT_REG_WORD(®
->host_cmd
, HC_PAUSE_RISC
);
3810 RD_REG_WORD(®
->id_l
);
3812 printk(KERN_INFO
"scsi(%li): dequeuing outstanding commands\n",
3814 /* Dequeue all commands in outstanding command list. */
3815 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3816 struct scsi_cmnd
*cmd
;
3817 sp
= ha
->outstanding_cmds
[cnt
];
3820 CMD_RESULT(cmd
) = DID_RESET
<< 16;
3821 CMD_HANDLE(cmd
) = COMPLETED_HANDLE
;
3822 ha
->outstanding_cmds
[cnt
] = NULL
;
3823 list_add_tail(&sp
->list
, &ha
->done_q
);
3829 status
= qla1280_load_firmware(ha
);
3833 /* Setup adapter based on NVRAM parameters. */
3834 qla1280_nvram_config (ha
);
3836 status
= qla1280_init_rings(ha
);
3840 /* Issue SCSI reset. */
3841 for (bus
= 0; bus
< ha
->ports
; bus
++)
3842 qla1280_bus_reset(ha
, bus
);
3844 ha
->flags
.abort_isp_active
= 0;
3848 "qla1280: ISP error recovery failed, board disabled");
3849 qla1280_reset_adapter(ha
);
3850 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
3853 LEAVE("qla1280_abort_isp");
3859 * qla1280_debounce_register
3860 * Debounce register.
3863 * port = register address.
3869 qla1280_debounce_register(volatile u16 __iomem
* addr
)
3874 ret
= RD_REG_WORD(addr
);
3875 ret2
= RD_REG_WORD(addr
);
3882 ret
= RD_REG_WORD(addr
);
3883 ret2
= RD_REG_WORD(addr
);
3884 } while (ret
!= ret2
);
3890 /************************************************************************
3891 * qla1280_check_for_dead_scsi_bus *
3893 * This routine checks for a dead SCSI bus *
3894 ************************************************************************/
3895 #define SET_SXP_BANK 0x0100
3896 #define SCSI_PHASE_INVALID 0x87FF
3898 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host
*ha
, unsigned int bus
)
3900 uint16_t config_reg
, scsi_control
;
3901 struct device_reg __iomem
*reg
= ha
->iobase
;
3903 if (ha
->bus_settings
[bus
].scsi_bus_dead
) {
3904 WRT_REG_WORD(®
->host_cmd
, HC_PAUSE_RISC
);
3905 config_reg
= RD_REG_WORD(®
->cfg_1
);
3906 WRT_REG_WORD(®
->cfg_1
, SET_SXP_BANK
);
3907 scsi_control
= RD_REG_WORD(®
->scsiControlPins
);
3908 WRT_REG_WORD(®
->cfg_1
, config_reg
);
3909 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
3911 if (scsi_control
== SCSI_PHASE_INVALID
) {
3912 ha
->bus_settings
[bus
].scsi_bus_dead
= 1;
3913 return 1; /* bus is dead */
3915 ha
->bus_settings
[bus
].scsi_bus_dead
= 0;
3916 ha
->bus_settings
[bus
].failed_reset_count
= 0;
3919 return 0; /* bus is not dead */
3923 qla1280_get_target_parameters(struct scsi_qla_host
*ha
,
3924 struct scsi_device
*device
)
3926 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3927 int bus
, target
, lun
;
3929 bus
= device
->channel
;
3930 target
= device
->id
;
3934 mb
[0] = MBC_GET_TARGET_PARAMETERS
;
3935 mb
[1] = (uint16_t) (bus
? target
| BIT_7
: target
);
3937 qla1280_mailbox_command(ha
, BIT_6
| BIT_3
| BIT_2
| BIT_1
| BIT_0
,
3940 printk(KERN_INFO
"scsi(%li:%d:%d:%d):", ha
->host_no
, bus
, target
, lun
);
3943 printk(" Sync: period %d, offset %d",
3944 (mb
[3] & 0xff), (mb
[3] >> 8));
3947 if ((mb
[2] & BIT_5
) && ((mb
[6] >> 8) & 0xff) >= 2)
3952 if (device
->simple_tags
)
3953 printk(", Tagged queuing: depth %d", device
->queue_depth
);
3960 __qla1280_dump_buffer(char *b
, int size
)
3965 printk(KERN_DEBUG
" 0 1 2 3 4 5 6 7 8 9 Ah "
3966 "Bh Ch Dh Eh Fh\n");
3967 printk(KERN_DEBUG
"---------------------------------------------"
3968 "------------------\n");
3970 for (cnt
= 0; cnt
< size
;) {
3973 printk("0x%02x", c
);
3984 /**************************************************************************
3985 * ql1280_print_scsi_cmd
3987 **************************************************************************/
3989 __qla1280_print_scsi_cmd(struct scsi_cmnd
*cmd
)
3991 struct scsi_qla_host
*ha
;
3992 struct Scsi_Host
*host
= CMD_HOST(cmd
);
3994 /* struct scatterlist *sg; */
3997 ha
= (struct scsi_qla_host
*)host
->hostdata
;
3999 sp
= (struct srb
*)CMD_SP(cmd
);
4000 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd
, CMD_HANDLE(cmd
));
4001 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
4002 SCSI_BUS_32(cmd
), SCSI_TCN_32(cmd
), SCSI_LUN_32(cmd
),
4005 for (i
= 0; i
< cmd
->cmd_len
; i
++) {
4006 printk("0x%02x ", cmd
->cmnd
[i
]);
4008 printk(" seg_cnt =%d\n", scsi_sg_count(cmd
));
4009 printk(" request buffer=0x%p, request buffer len=0x%x\n",
4010 scsi_sglist(cmd
), scsi_bufflen(cmd
));
4013 sg = (struct scatterlist *) cmd->request_buffer;
4014 printk(" SG buffer: \n");
4015 qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
4017 printk(" tag=%d, transfersize=0x%x \n",
4018 cmd
->tag
, cmd
->transfersize
);
4019 printk(" Pid=%li, SP=0x%p\n", cmd
->serial_number
, CMD_SP(cmd
));
4020 printk(" underflow size = 0x%x, direction=0x%x\n",
4021 cmd
->underflow
, cmd
->sc_data_direction
);
4024 /**************************************************************************
4025 * ql1280_dump_device
4027 **************************************************************************/
4029 ql1280_dump_device(struct scsi_qla_host
*ha
)
4032 struct scsi_cmnd
*cp
;
4036 printk(KERN_DEBUG
"Outstanding Commands on controller:\n");
4038 for (i
= 0; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
4039 if ((sp
= ha
->outstanding_cmds
[i
]) == NULL
)
4041 if ((cp
= sp
->cmd
) == NULL
)
4043 qla1280_print_scsi_cmd(1, cp
);
4058 struct setup_tokens
{
4063 static struct setup_tokens setup_token
[] __initdata
=
4065 { "nvram", TOKEN_NVRAM
},
4066 { "sync", TOKEN_SYNC
},
4067 { "wide", TOKEN_WIDE
},
4068 { "ppr", TOKEN_PPR
},
4069 { "verbose", TOKEN_VERBOSE
},
4070 { "debug", TOKEN_DEBUG
},
4074 /**************************************************************************
4077 * Handle boot parameters. This really needs to be changed so one
4078 * can specify per adapter parameters.
4079 **************************************************************************/
4081 qla1280_setup(char *s
)
4089 while (cp
&& (ptr
= strchr(cp
, ':'))) {
4091 if (!strcmp(ptr
, "yes")) {
4094 } else if (!strcmp(ptr
, "no")) {
4098 val
= simple_strtoul(ptr
, &ptr
, 0);
4100 switch ((toke
= qla1280_get_token(cp
))) {
4103 driver_setup
.no_nvram
= 1;
4107 driver_setup
.no_sync
= 1;
4108 else if (val
!= 0x10000)
4109 driver_setup
.sync_mask
= val
;
4113 driver_setup
.no_wide
= 1;
4114 else if (val
!= 0x10000)
4115 driver_setup
.wide_mask
= val
;
4119 driver_setup
.no_ppr
= 1;
4120 else if (val
!= 0x10000)
4121 driver_setup
.ppr_mask
= val
;
4124 qla1280_verbose
= val
;
4127 printk(KERN_INFO
"qla1280: unknown boot option %s\n",
4131 cp
= strchr(ptr
, ';');
4143 qla1280_get_token(char *str
)
4149 sep
= strchr(str
, ':');
4152 for (i
= 0; i
< ARRAY_SIZE(setup_token
); i
++) {
4153 if (!strncmp(setup_token
[i
].token
, str
, (sep
- str
))) {
4154 ret
= setup_token
[i
].val
;
4164 static struct scsi_host_template qla1280_driver_template
= {
4165 .module
= THIS_MODULE
,
4166 .proc_name
= "qla1280",
4167 .name
= "Qlogic ISP 1280/12160",
4168 .info
= qla1280_info
,
4169 .slave_configure
= qla1280_slave_configure
,
4170 .queuecommand
= qla1280_queuecommand
,
4171 .eh_abort_handler
= qla1280_eh_abort
,
4172 .eh_device_reset_handler
= qla1280_eh_device_reset
,
4173 .eh_bus_reset_handler
= qla1280_eh_bus_reset
,
4174 .eh_host_reset_handler
= qla1280_eh_adapter_reset
,
4175 .bios_param
= qla1280_biosparam
,
4176 .can_queue
= 0xfffff,
4178 .sg_tablesize
= SG_ALL
,
4180 .use_clustering
= ENABLE_CLUSTERING
,
4184 static int __devinit
4185 qla1280_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
4187 int devnum
= id
->driver_data
;
4188 struct qla_boards
*bdp
= &ql1280_board_tbl
[devnum
];
4189 struct Scsi_Host
*host
;
4190 struct scsi_qla_host
*ha
;
4191 int error
= -ENODEV
;
4193 /* Bypass all AMI SUBSYS VENDOR IDs */
4194 if (pdev
->subsystem_vendor
== PCI_VENDOR_ID_AMI
) {
4196 "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
4200 printk(KERN_INFO
"qla1280: %s found on PCI bus %i, dev %i\n",
4201 bdp
->name
, pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
));
4203 if (pci_enable_device(pdev
)) {
4205 "qla1280: Failed to enabled pci device, aborting.\n");
4209 pci_set_master(pdev
);
4212 host
= scsi_host_alloc(&qla1280_driver_template
, sizeof(*ha
));
4215 "qla1280: Failed to register host, aborting.\n");
4216 goto error_disable_device
;
4219 ha
= (struct scsi_qla_host
*)host
->hostdata
;
4220 memset(ha
, 0, sizeof(struct scsi_qla_host
));
4223 ha
->devnum
= devnum
; /* specifies microcode load address */
4225 #ifdef QLA_64BIT_PTR
4226 if (pci_set_dma_mask(ha
->pdev
, DMA_BIT_MASK(64))) {
4227 if (pci_set_dma_mask(ha
->pdev
, DMA_BIT_MASK(32))) {
4228 printk(KERN_WARNING
"scsi(%li): Unable to set a "
4229 "suitable DMA mask - aborting\n", ha
->host_no
);
4231 goto error_put_host
;
4234 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4237 if (pci_set_dma_mask(ha
->pdev
, DMA_BIT_MASK(32))) {
4238 printk(KERN_WARNING
"scsi(%li): Unable to set a "
4239 "suitable DMA mask - aborting\n", ha
->host_no
);
4241 goto error_put_host
;
4245 ha
->request_ring
= pci_alloc_consistent(ha
->pdev
,
4246 ((REQUEST_ENTRY_CNT
+ 1) * sizeof(request_t
)),
4248 if (!ha
->request_ring
) {
4249 printk(KERN_INFO
"qla1280: Failed to get request memory\n");
4250 goto error_put_host
;
4253 ha
->response_ring
= pci_alloc_consistent(ha
->pdev
,
4254 ((RESPONSE_ENTRY_CNT
+ 1) * sizeof(struct response
)),
4256 if (!ha
->response_ring
) {
4257 printk(KERN_INFO
"qla1280: Failed to get response memory\n");
4258 goto error_free_request_ring
;
4261 ha
->ports
= bdp
->numPorts
;
4264 ha
->host_no
= host
->host_no
;
4266 host
->irq
= pdev
->irq
;
4267 host
->max_channel
= bdp
->numPorts
- 1;
4268 host
->max_lun
= MAX_LUNS
- 1;
4269 host
->max_id
= MAX_TARGETS
;
4270 host
->max_sectors
= 1024;
4271 host
->unique_id
= host
->host_no
;
4275 #if MEMORY_MAPPED_IO
4276 ha
->mmpbase
= pci_ioremap_bar(ha
->pdev
, 1);
4278 printk(KERN_INFO
"qla1280: Unable to map I/O memory\n");
4279 goto error_free_response_ring
;
4282 host
->base
= (unsigned long)ha
->mmpbase
;
4283 ha
->iobase
= (struct device_reg __iomem
*)ha
->mmpbase
;
4285 host
->io_port
= pci_resource_start(ha
->pdev
, 0);
4286 if (!request_region(host
->io_port
, 0xff, "qla1280")) {
4287 printk(KERN_INFO
"qla1280: Failed to reserve i/o region "
4288 "0x%04lx-0x%04lx - already in use\n",
4289 host
->io_port
, host
->io_port
+ 0xff);
4290 goto error_free_response_ring
;
4293 ha
->iobase
= (struct device_reg
*)host
->io_port
;
4296 INIT_LIST_HEAD(&ha
->done_q
);
4298 /* Disable ISP interrupts. */
4299 qla1280_disable_intrs(ha
);
4301 if (request_irq(pdev
->irq
, qla1280_intr_handler
, IRQF_SHARED
,
4303 printk("qla1280 : Failed to reserve interrupt %d already "
4304 "in use\n", pdev
->irq
);
4305 goto error_release_region
;
4308 /* load the F/W, read paramaters, and init the H/W */
4309 if (qla1280_initialize_adapter(ha
)) {
4310 printk(KERN_INFO
"qla1x160: Failed to initialize adapter\n");
4311 goto error_free_irq
;
4314 /* set our host ID (need to do something about our two IDs) */
4315 host
->this_id
= ha
->bus_settings
[0].id
;
4317 pci_set_drvdata(pdev
, host
);
4319 error
= scsi_add_host(host
, &pdev
->dev
);
4321 goto error_disable_adapter
;
4322 scsi_scan_host(host
);
4326 error_disable_adapter
:
4327 qla1280_disable_intrs(ha
);
4329 free_irq(pdev
->irq
, ha
);
4330 error_release_region
:
4331 #if MEMORY_MAPPED_IO
4332 iounmap(ha
->mmpbase
);
4334 release_region(host
->io_port
, 0xff);
4336 error_free_response_ring
:
4337 pci_free_consistent(ha
->pdev
,
4338 ((RESPONSE_ENTRY_CNT
+ 1) * sizeof(struct response
)),
4339 ha
->response_ring
, ha
->response_dma
);
4340 error_free_request_ring
:
4341 pci_free_consistent(ha
->pdev
,
4342 ((REQUEST_ENTRY_CNT
+ 1) * sizeof(request_t
)),
4343 ha
->request_ring
, ha
->request_dma
);
4345 scsi_host_put(host
);
4346 error_disable_device
:
4347 pci_disable_device(pdev
);
4353 static void __devexit
4354 qla1280_remove_one(struct pci_dev
*pdev
)
4356 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
4357 struct scsi_qla_host
*ha
= (struct scsi_qla_host
*)host
->hostdata
;
4359 scsi_remove_host(host
);
4361 qla1280_disable_intrs(ha
);
4363 free_irq(pdev
->irq
, ha
);
4365 #if MEMORY_MAPPED_IO
4366 iounmap(ha
->mmpbase
);
4368 release_region(host
->io_port
, 0xff);
4371 pci_free_consistent(ha
->pdev
,
4372 ((REQUEST_ENTRY_CNT
+ 1) * (sizeof(request_t
))),
4373 ha
->request_ring
, ha
->request_dma
);
4374 pci_free_consistent(ha
->pdev
,
4375 ((RESPONSE_ENTRY_CNT
+ 1) * (sizeof(struct response
))),
4376 ha
->response_ring
, ha
->response_dma
);
4378 pci_disable_device(pdev
);
4380 scsi_host_put(host
);
4383 static struct pci_driver qla1280_pci_driver
= {
4385 .id_table
= qla1280_pci_tbl
,
4386 .probe
= qla1280_probe_one
,
4387 .remove
= __devexit_p(qla1280_remove_one
),
4393 if (sizeof(struct srb
) > sizeof(struct scsi_pointer
)) {
4395 "qla1280: struct srb too big, aborting\n");
4401 * If we are called as a module, the qla1280 pointer may not be null
4402 * and it would point to our bootup string, just like on the lilo
4403 * command line. IF not NULL, then process this config string with
4407 * To add options at boot time add a line to your lilo.conf file like:
4408 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
4409 * which will result in the first four devices on the first two
4410 * controllers being set to a tagged queue depth of 32.
4413 qla1280_setup(qla1280
);
4416 return pci_register_driver(&qla1280_pci_driver
);
4422 pci_unregister_driver(&qla1280_pci_driver
);
4425 module_init(qla1280_init
);
4426 module_exit(qla1280_exit
);
4429 MODULE_AUTHOR("Qlogic & Jes Sorensen");
4430 MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
4431 MODULE_LICENSE("GPL");
4432 MODULE_FIRMWARE("qlogic/1040.bin");
4433 MODULE_FIRMWARE("qlogic/1280.bin");
4434 MODULE_FIRMWARE("qlogic/12160.bin");
4435 MODULE_VERSION(QLA1280_VERSION
);
4438 * Overrides for Emacs so that we almost follow Linus's tabbing style.
4439 * Emacs will notice this stuff at the end of the file and automatically
4440 * adjust the settings for this buffer only. This must remain at the end
4442 * ---------------------------------------------------------------------------