[SCSI] allow sleeping in ->eh_abort_handler()
[deliverable/linux.git] / drivers / scsi / qla1280.c
1 /******************************************************************************
2 * QLOGIC LINUX SOFTWARE
3 *
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
8 *
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
12 * later version.
13 *
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.
18 *
19 ******************************************************************************/
20 #define QLA1280_VERSION "3.25"
21 /*****************************************************************************
22 Revision History:
23 Rev 3.25.1, February 10, 2005 Christoph Hellwig
24 - use pci_map_single to map non-S/G requests
25 - remove qla1280_proc_info
26 Rev 3.25, September 28, 2004, Christoph Hellwig
27 - add support for ISP1020/1040
28 - don't include "scsi.h" anymore for 2.6.x
29 Rev 3.24.4 June 7, 2004 Christoph Hellwig
30 - restructure firmware loading, cleanup initialization code
31 - prepare support for ISP1020/1040 chips
32 Rev 3.24.3 January 19, 2004, Jes Sorensen
33 - Handle PCI DMA mask settings correctly
34 - Correct order of error handling in probe_one, free_irq should not
35 be called if request_irq failed
36 Rev 3.24.2 January 19, 2004, James Bottomley & Andrew Vasquez
37 - Big endian fixes (James)
38 - Remove bogus IOCB content on zero data transfer commands (Andrew)
39 Rev 3.24.1 January 5, 2004, Jes Sorensen
40 - Initialize completion queue to avoid OOPS on probe
41 - Handle interrupts during mailbox testing
42 Rev 3.24 November 17, 2003, Christoph Hellwig
43 - use struct list_head for completion queue
44 - avoid old Scsi_FOO typedefs
45 - cleanup 2.4 compat glue a bit
46 - use <scsi/scsi_*.h> headers on 2.6 instead of "scsi.h"
47 - make initialization for memory mapped vs port I/O more similar
48 - remove broken pci config space manipulation
49 - kill more cruft
50 - this is an almost perfect 2.6 scsi driver now! ;)
51 Rev 3.23.39 December 17, 2003, Jes Sorensen
52 - Delete completion queue from srb if mailbox command failed to
53 to avoid qla1280_done completeting qla1280_error_action's
54 obsolete context
55 - Reduce arguments for qla1280_done
56 Rev 3.23.38 October 18, 2003, Christoph Hellwig
57 - Convert to new-style hotplugable driver for 2.6
58 - Fix missing scsi_unregister/scsi_host_put on HBA removal
59 - Kill some more cruft
60 Rev 3.23.37 October 1, 2003, Jes Sorensen
61 - Make MMIO depend on CONFIG_X86_VISWS instead of yet another
62 random CONFIG option
63 - Clean up locking in probe path
64 Rev 3.23.36 October 1, 2003, Christoph Hellwig
65 - queuecommand only ever receives new commands - clear flags
66 - Reintegrate lost fixes from Linux 2.5
67 Rev 3.23.35 August 14, 2003, Jes Sorensen
68 - Build against 2.6
69 Rev 3.23.34 July 23, 2003, Jes Sorensen
70 - Remove pointless TRUE/FALSE macros
71 - Clean up vchan handling
72 Rev 3.23.33 July 3, 2003, Jes Sorensen
73 - Don't define register access macros before define determining MMIO.
74 This just happend to work out on ia64 but not elsewhere.
75 - Don't try and read from the card while it is in reset as
76 it won't respond and causes an MCA
77 Rev 3.23.32 June 23, 2003, Jes Sorensen
78 - Basic support for boot time arguments
79 Rev 3.23.31 June 8, 2003, Jes Sorensen
80 - Reduce boot time messages
81 Rev 3.23.30 June 6, 2003, Jes Sorensen
82 - Do not enable sync/wide/ppr before it has been determined
83 that the target device actually supports it
84 - Enable DMA arbitration for multi channel controllers
85 Rev 3.23.29 June 3, 2003, Jes Sorensen
86 - Port to 2.5.69
87 Rev 3.23.28 June 3, 2003, Jes Sorensen
88 - Eliminate duplicate marker commands on bus resets
89 - Handle outstanding commands appropriately on bus/device resets
90 Rev 3.23.27 May 28, 2003, Jes Sorensen
91 - Remove bogus input queue code, let the Linux SCSI layer do the work
92 - Clean up NVRAM handling, only read it once from the card
93 - Add a number of missing default nvram parameters
94 Rev 3.23.26 Beta May 28, 2003, Jes Sorensen
95 - Use completion queue for mailbox commands instead of busy wait
96 Rev 3.23.25 Beta May 27, 2003, James Bottomley
97 - Migrate to use new error handling code
98 Rev 3.23.24 Beta May 21, 2003, James Bottomley
99 - Big endian support
100 - Cleanup data direction code
101 Rev 3.23.23 Beta May 12, 2003, Jes Sorensen
102 - Switch to using MMIO instead of PIO
103 Rev 3.23.22 Beta April 15, 2003, Jes Sorensen
104 - Fix PCI parity problem with 12160 during reset.
105 Rev 3.23.21 Beta April 14, 2003, Jes Sorensen
106 - Use pci_map_page()/pci_unmap_page() instead of map_single version.
107 Rev 3.23.20 Beta April 9, 2003, Jes Sorensen
108 - Remove < 2.4.x support
109 - Introduce HOST_LOCK to make the spin lock changes portable.
110 - Remove a bunch of idiotic and unnecessary typedef's
111 - Kill all leftovers of target-mode support which never worked anyway
112 Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
113 - Do qla1280_pci_config() before calling request_irq() and
114 request_region()
115 - Use pci_dma_hi32() to handle upper word of DMA addresses instead
116 of large shifts
117 - Hand correct arguments to free_irq() in case of failure
118 Rev 3.23.18 Beta April 11, 2002, Jes Sorensen
119 - Run source through Lindent and clean up the output
120 Rev 3.23.17 Beta April 11, 2002, Jes Sorensen
121 - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32
122 Rev 3.23.16 Beta March 19, 2002, Jes Sorensen
123 - Rely on mailbox commands generating interrupts - do not
124 run qla1280_isr() from ql1280_mailbox_command()
125 - Remove device_reg_t
126 - Integrate ql12160_set_target_parameters() with 1280 version
127 - Make qla1280_setup() non static
128 - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request
129 sent to the card - this command pauses the firmare!!!
130 Rev 3.23.15 Beta March 19, 2002, Jes Sorensen
131 - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions
132 - Remove a pile of pointless and confusing (srb_t **) and
133 (scsi_lu_t *) typecasts
134 - Explicit mark that we do not use the new error handling (for now)
135 - Remove scsi_qla_host_t and use 'struct' instead
136 - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled,
137 pci_64bit_slot flags which weren't used for anything anyway
138 - Grab host->host_lock while calling qla1280_isr() from abort()
139 - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we
140 do not need to save/restore flags in the interrupt handler
141 - Enable interrupts early (before any mailbox access) in preparation
142 for cleaning up the mailbox handling
143 Rev 3.23.14 Beta March 14, 2002, Jes Sorensen
144 - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace
145 it with proper use of dprintk().
146 - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take
147 a debug level argument to determine if data is to be printed
148 - Add KERN_* info to printk()
149 Rev 3.23.13 Beta March 14, 2002, Jes Sorensen
150 - Significant cosmetic cleanups
151 - Change debug code to use dprintk() and remove #if mess
152 Rev 3.23.12 Beta March 13, 2002, Jes Sorensen
153 - More cosmetic cleanups, fix places treating return as function
154 - use cpu_relax() in qla1280_debounce_register()
155 Rev 3.23.11 Beta March 13, 2002, Jes Sorensen
156 - Make it compile under 2.5.5
157 Rev 3.23.10 Beta October 1, 2001, Jes Sorensen
158 - Do no typecast short * to long * in QL1280BoardTbl, this
159 broke miserably on big endian boxes
160 Rev 3.23.9 Beta September 30, 2001, Jes Sorensen
161 - Remove pre 2.2 hack for checking for reentrance in interrupt handler
162 - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32
163 unsigned int to match the types from struct scsi_cmnd
164 Rev 3.23.8 Beta September 29, 2001, Jes Sorensen
165 - Remove bogus timer_t typedef from qla1280.h
166 - Remove obsolete pre 2.2 PCI setup code, use proper #define's
167 for PCI_ values, call pci_set_master()
168 - Fix memleak of qla1280_buffer on module unload
169 - Only compile module parsing code #ifdef MODULE - should be
170 changed to use individual MODULE_PARM's later
171 - Remove dummy_buffer that was never modified nor printed
172 - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove
173 #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls
174 - Remove \r from print statements, this is Linux, not DOS
175 - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK}
176 dummy macros
177 - Remove C++ compile hack in header file as Linux driver are not
178 supposed to be compiled as C++
179 - Kill MS_64BITS macro as it makes the code more readable
180 - Remove unnecessary flags.in_interrupts bit
181 Rev 3.23.7 Beta August 20, 2001, Jes Sorensen
182 - Dont' check for set flags on q->q_flag one by one in qla1280_next()
183 - Check whether the interrupt was generated by the QLA1280 before
184 doing any processing
185 - qla1280_status_entry(): Only zero out part of sense_buffer that
186 is not being copied into
187 - Remove more superflouous typecasts
188 - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy()
189 Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel
190 - Don't walk the entire list in qla1280_putq_t() just to directly
191 grab the pointer to the last element afterwards
192 Rev 3.23.5 Beta August 9, 2001, Jes Sorensen
193 - Don't use SA_INTERRUPT, it's use is deprecated for this kinda driver
194 Rev 3.23.4 Beta August 8, 2001, Jes Sorensen
195 - Set dev->max_sectors to 1024
196 Rev 3.23.3 Beta August 6, 2001, Jes Sorensen
197 - Provide compat macros for pci_enable_device(), pci_find_subsys()
198 and scsi_set_pci_device()
199 - Call scsi_set_pci_device() for all devices
200 - Reduce size of kernel version dependent device probe code
201 - Move duplicate probe/init code to separate function
202 - Handle error if qla1280_mem_alloc() fails
203 - Kill OFFSET() macro and use Linux's PCI definitions instead
204 - Kill private structure defining PCI config space (struct config_reg)
205 - Only allocate I/O port region if not in MMIO mode
206 - Remove duplicate (unused) sanity check of sife of srb_t
207 Rev 3.23.2 Beta August 6, 2001, Jes Sorensen
208 - Change home-brew memset() implementations to use memset()
209 - Remove all references to COMTRACE() - accessing a PC's COM2 serial
210 port directly is not legal under Linux.
211 Rev 3.23.1 Beta April 24, 2001, Jes Sorensen
212 - Remove pre 2.2 kernel support
213 - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat)
214 - Fix MMIO access to use readl/writel instead of directly
215 dereferencing pointers
216 - Nuke MSDOS debugging code
217 - Change true/false data types to int from uint8_t
218 - Use int for counters instead of uint8_t etc.
219 - Clean up size & byte order conversion macro usage
220 Rev 3.23 Beta January 11, 2001 BN Qlogic
221 - Added check of device_id when handling non
222 QLA12160s during detect().
223 Rev 3.22 Beta January 5, 2001 BN Qlogic
224 - Changed queue_task() to schedule_task()
225 for kernels 2.4.0 and higher.
226 Note: 2.4.0-testxx kernels released prior to
227 the actual 2.4.0 kernel release on January 2001
228 will get compile/link errors with schedule_task().
229 Please update your kernel to released 2.4.0 level,
230 or comment lines in this file flagged with 3.22
231 to resolve compile/link error of schedule_task().
232 - Added -DCONFIG_SMP in addition to -D__SMP__
233 in Makefile for 2.4.0 builds of driver as module.
234 Rev 3.21 Beta January 4, 2001 BN Qlogic
235 - Changed criteria of 64/32 Bit mode of HBA
236 operation according to BITS_PER_LONG rather
237 than HBA's NVRAM setting of >4Gig memory bit;
238 so that the HBA auto-configures without the need
239 to setup each system individually.
240 Rev 3.20 Beta December 5, 2000 BN Qlogic
241 - Added priority handling to IA-64 onboard SCSI
242 ISP12160 chip for kernels greater than 2.3.18.
243 - Added irqrestore for qla1280_intr_handler.
244 - Enabled /proc/scsi/qla1280 interface.
245 - Clear /proc/scsi/qla1280 counters in detect().
246 Rev 3.19 Beta October 13, 2000 BN Qlogic
247 - Declare driver_template for new kernel
248 (2.4.0 and greater) scsi initialization scheme.
249 - Update /proc/scsi entry for 2.3.18 kernels and
250 above as qla1280
251 Rev 3.18 Beta October 10, 2000 BN Qlogic
252 - Changed scan order of adapters to map
253 the QLA12160 followed by the QLA1280.
254 Rev 3.17 Beta September 18, 2000 BN Qlogic
255 - Removed warnings for 32 bit 2.4.x compiles
256 - Corrected declared size for request and response
257 DMA addresses that are kept in each ha
258 Rev. 3.16 Beta August 25, 2000 BN Qlogic
259 - Corrected 64 bit addressing issue on IA-64
260 where the upper 32 bits were not properly
261 passed to the RISC engine.
262 Rev. 3.15 Beta August 22, 2000 BN Qlogic
263 - Modified qla1280_setup_chip to properly load
264 ISP firmware for greater that 4 Gig memory on IA-64
265 Rev. 3.14 Beta August 16, 2000 BN Qlogic
266 - Added setting of dma_mask to full 64 bit
267 if flags.enable_64bit_addressing is set in NVRAM
268 Rev. 3.13 Beta August 16, 2000 BN Qlogic
269 - Use new PCI DMA mapping APIs for 2.4.x kernel
270 Rev. 3.12 July 18, 2000 Redhat & BN Qlogic
271 - Added check of pci_enable_device to detect() for 2.3.x
272 - Use pci_resource_start() instead of
273 pdev->resource[0].start in detect() for 2.3.x
274 - Updated driver version
275 Rev. 3.11 July 14, 2000 BN Qlogic
276 - Updated SCSI Firmware to following versions:
277 qla1x80: 8.13.08
278 qla1x160: 10.04.08
279 - Updated driver version to 3.11
280 Rev. 3.10 June 23, 2000 BN Qlogic
281 - Added filtering of AMI SubSys Vendor ID devices
282 Rev. 3.9
283 - DEBUG_QLA1280 undefined and new version BN Qlogic
284 Rev. 3.08b May 9, 2000 MD Dell
285 - Added logic to check against AMI subsystem vendor ID
286 Rev. 3.08 May 4, 2000 DG Qlogic
287 - Added logic to check for PCI subsystem ID.
288 Rev. 3.07 Apr 24, 2000 DG & BN Qlogic
289 - Updated SCSI Firmware to following versions:
290 qla12160: 10.01.19
291 qla1280: 8.09.00
292 Rev. 3.06 Apr 12, 2000 DG & BN Qlogic
293 - Internal revision; not released
294 Rev. 3.05 Mar 28, 2000 DG & BN Qlogic
295 - Edit correction for virt_to_bus and PROC.
296 Rev. 3.04 Mar 28, 2000 DG & BN Qlogic
297 - Merge changes from ia64 port.
298 Rev. 3.03 Mar 28, 2000 BN Qlogic
299 - Increase version to reflect new code drop with compile fix
300 of issue with inclusion of linux/spinlock for 2.3 kernels
301 Rev. 3.02 Mar 15, 2000 BN Qlogic
302 - Merge qla1280_proc_info from 2.10 code base
303 Rev. 3.01 Feb 10, 2000 BN Qlogic
304 - Corrected code to compile on a 2.2.x kernel.
305 Rev. 3.00 Jan 17, 2000 DG Qlogic
306 - Added 64-bit support.
307 Rev. 2.07 Nov 9, 1999 DG Qlogic
308 - Added new routine to set target parameters for ISP12160.
309 Rev. 2.06 Sept 10, 1999 DG Qlogic
310 - Added support for ISP12160 Ultra 3 chip.
311 Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
312 - Modified code to remove errors generated when compiling with
313 Cygnus IA64 Compiler.
314 - Changed conversion of pointers to unsigned longs instead of integers.
315 - Changed type of I/O port variables from uint32_t to unsigned long.
316 - Modified OFFSET macro to work with 64-bit as well as 32-bit.
317 - Changed sprintf and printk format specifiers for pointers to %p.
318 - Changed some int to long type casts where needed in sprintf & printk.
319 - Added l modifiers to sprintf and printk format specifiers for longs.
320 - Removed unused local variables.
321 Rev. 1.20 June 8, 1999 DG, Qlogic
322 Changes to support RedHat release 6.0 (kernel 2.2.5).
323 - Added SCSI exclusive access lock (io_request_lock) when accessing
324 the adapter.
325 - Added changes for the new LINUX interface template. Some new error
326 handling routines have been added to the template, but for now we
327 will use the old ones.
328 - Initial Beta Release.
329 *****************************************************************************/
330
331
332 #include <linux/config.h>
333 #include <linux/module.h>
334
335 #include <linux/version.h>
336 #include <linux/types.h>
337 #include <linux/string.h>
338 #include <linux/errno.h>
339 #include <linux/kernel.h>
340 #include <linux/ioport.h>
341 #include <linux/delay.h>
342 #include <linux/timer.h>
343 #include <linux/sched.h>
344 #include <linux/pci.h>
345 #include <linux/proc_fs.h>
346 #include <linux/stat.h>
347 #include <linux/slab.h>
348 #include <linux/pci_ids.h>
349 #include <linux/interrupt.h>
350 #include <linux/init.h>
351
352 #include <asm/io.h>
353 #include <asm/irq.h>
354 #include <asm/byteorder.h>
355 #include <asm/processor.h>
356 #include <asm/types.h>
357 #include <asm/system.h>
358
359 #if LINUX_VERSION_CODE >= 0x020545
360 #include <scsi/scsi.h>
361 #include <scsi/scsi_cmnd.h>
362 #include <scsi/scsi_device.h>
363 #include <scsi/scsi_host.h>
364 #include <scsi/scsi_tcq.h>
365 #else
366 #include <linux/blk.h>
367 #include "scsi.h"
368 #include <scsi/scsi_host.h>
369 #include "sd.h"
370 #endif
371
372 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
373 #include <asm/sn/io.h>
374 #endif
375
376 #if LINUX_VERSION_CODE < 0x020407
377 #error "Kernels older than 2.4.7 are no longer supported"
378 #endif
379
380
381 /*
382 * Compile time Options:
383 * 0 - Disable and 1 - Enable
384 */
385 #define DEBUG_QLA1280_INTR 0
386 #define DEBUG_PRINT_NVRAM 0
387 #define DEBUG_QLA1280 0
388
389 /*
390 * The SGI VISWS is broken and doesn't support MMIO ;-(
391 */
392 #ifdef CONFIG_X86_VISWS
393 #define MEMORY_MAPPED_IO 0
394 #else
395 #define MEMORY_MAPPED_IO 1
396 #endif
397
398 #define UNIQUE_FW_NAME
399 #include "qla1280.h"
400 #include "ql12160_fw.h" /* ISP RISC codes */
401 #include "ql1280_fw.h"
402 #include "ql1040_fw.h"
403
404
405 /*
406 * Missing PCI ID's
407 */
408 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1080
409 #define PCI_DEVICE_ID_QLOGIC_ISP1080 0x1080
410 #endif
411 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1240
412 #define PCI_DEVICE_ID_QLOGIC_ISP1240 0x1240
413 #endif
414 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1280
415 #define PCI_DEVICE_ID_QLOGIC_ISP1280 0x1280
416 #endif
417 #ifndef PCI_DEVICE_ID_QLOGIC_ISP10160
418 #define PCI_DEVICE_ID_QLOGIC_ISP10160 0x1016
419 #endif
420 #ifndef PCI_DEVICE_ID_QLOGIC_ISP12160
421 #define PCI_DEVICE_ID_QLOGIC_ISP12160 0x1216
422 #endif
423
424 #ifndef PCI_VENDOR_ID_AMI
425 #define PCI_VENDOR_ID_AMI 0x101e
426 #endif
427
428 #ifndef BITS_PER_LONG
429 #error "BITS_PER_LONG not defined!"
430 #endif
431 #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
432 #define QLA_64BIT_PTR 1
433 #endif
434
435 #ifdef QLA_64BIT_PTR
436 #define pci_dma_hi32(a) ((a >> 16) >> 16)
437 #else
438 #define pci_dma_hi32(a) 0
439 #endif
440 #define pci_dma_lo32(a) (a & 0xffffffff)
441
442 #define NVRAM_DELAY() udelay(500) /* 2 microseconds */
443
444 #if LINUX_VERSION_CODE < 0x020500
445 #define HOST_LOCK &io_request_lock
446 #define irqreturn_t void
447 #define IRQ_RETVAL(foo)
448 #define MSG_ORDERED_TAG 1
449
450 #define DMA_BIDIRECTIONAL SCSI_DATA_UNKNOWN
451 #define DMA_TO_DEVICE SCSI_DATA_WRITE
452 #define DMA_FROM_DEVICE SCSI_DATA_READ
453 #define DMA_NONE SCSI_DATA_NONE
454
455 #ifndef HAVE_SECTOR_T
456 typedef unsigned int sector_t;
457 #endif
458
459 static inline void
460 scsi_adjust_queue_depth(struct scsi_device *device, int tag, int depth)
461 {
462 if (tag) {
463 device->tagged_queue = tag;
464 device->current_tag = 0;
465 }
466 device->queue_depth = depth;
467 }
468 static inline struct Scsi_Host *scsi_host_alloc(Scsi_Host_Template *t, size_t s)
469 {
470 return scsi_register(t, s);
471 }
472 static inline void scsi_host_put(struct Scsi_Host *h)
473 {
474 scsi_unregister(h);
475 }
476 #else
477 #define HOST_LOCK ha->host->host_lock
478 #endif
479 #if LINUX_VERSION_CODE < 0x020600
480 #define DEV_SIMPLE_TAGS(device) device->tagged_queue
481 /*
482 * Hack around that qla1280_remove_one is called from
483 * qla1280_release in 2.4
484 */
485 #undef __devexit
486 #define __devexit
487 #else
488 #define DEV_SIMPLE_TAGS(device) device->simple_tags
489 #endif
490 #if defined(__ia64__) && !defined(ia64_platform_is)
491 #define ia64_platform_is(foo) (!strcmp(x, platform_name))
492 #endif
493
494
495 #define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
496 #define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
497 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
498 #define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
499 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
500
501
502 static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *);
503 static void qla1280_remove_one(struct pci_dev *);
504
505 /*
506 * QLogic Driver Support Function Prototypes.
507 */
508 static void qla1280_done(struct scsi_qla_host *);
509 #if LINUX_VERSION_CODE < 0x020545
510 static void qla1280_get_target_options(struct scsi_cmnd *, struct scsi_qla_host *);
511 #endif
512 static int qla1280_get_token(char *);
513 static int qla1280_setup(char *s) __init;
514
515 /*
516 * QLogic ISP1280 Hardware Support Function Prototypes.
517 */
518 static int qla1280_load_firmware(struct scsi_qla_host *);
519 static int qla1280_init_rings(struct scsi_qla_host *);
520 static int qla1280_nvram_config(struct scsi_qla_host *);
521 static int qla1280_mailbox_command(struct scsi_qla_host *,
522 uint8_t, uint16_t *);
523 static int qla1280_bus_reset(struct scsi_qla_host *, int);
524 static int qla1280_device_reset(struct scsi_qla_host *, int, int);
525 static int qla1280_abort_device(struct scsi_qla_host *, int, int, int);
526 static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int);
527 static int qla1280_abort_isp(struct scsi_qla_host *);
528 #ifdef QLA_64BIT_PTR
529 static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *);
530 #else
531 static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *);
532 #endif
533 static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
534 static void qla1280_poll(struct scsi_qla_host *);
535 static void qla1280_reset_adapter(struct scsi_qla_host *);
536 static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
537 static void qla1280_isp_cmd(struct scsi_qla_host *);
538 static void qla1280_isr(struct scsi_qla_host *, struct list_head *);
539 static void qla1280_rst_aen(struct scsi_qla_host *);
540 static void qla1280_status_entry(struct scsi_qla_host *, struct response *,
541 struct list_head *);
542 static void qla1280_error_entry(struct scsi_qla_host *, struct response *,
543 struct list_head *);
544 static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
545 static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
546 static uint16_t qla1280_debounce_register(volatile uint16_t __iomem *);
547 static request_t *qla1280_req_pkt(struct scsi_qla_host *);
548 static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
549 unsigned int);
550 static void qla1280_get_target_parameters(struct scsi_qla_host *,
551 struct scsi_device *);
552 static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int);
553
554
555 static struct qla_driver_setup driver_setup;
556
557 /*
558 * convert scsi data direction to request_t control flags
559 */
560 static inline uint16_t
561 qla1280_data_direction(struct scsi_cmnd *cmnd)
562 {
563 switch(cmnd->sc_data_direction) {
564 case DMA_FROM_DEVICE:
565 return BIT_5;
566 case DMA_TO_DEVICE:
567 return BIT_6;
568 case DMA_BIDIRECTIONAL:
569 return BIT_5 | BIT_6;
570 /*
571 * We could BUG() on default here if one of the four cases aren't
572 * met, but then again if we receive something like that from the
573 * SCSI layer we have more serious problems. This shuts up GCC.
574 */
575 case DMA_NONE:
576 default:
577 return 0;
578 }
579 }
580
581 #if DEBUG_QLA1280
582 static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd);
583 static void __qla1280_dump_buffer(char *, int);
584 #endif
585
586
587 /*
588 * insmod needs to find the variable and make it point to something
589 */
590 #ifdef MODULE
591 static char *qla1280;
592
593 /* insmod qla1280 options=verbose" */
594 module_param(qla1280, charp, 0);
595 #else
596 __setup("qla1280=", qla1280_setup);
597 #endif
598
599
600 /*
601 * We use the scsi_pointer structure that's included with each scsi_command
602 * to overlay our struct srb over it. qla1280_init() checks that a srb is not
603 * bigger than a scsi_pointer.
604 */
605
606 #define CMD_SP(Cmnd) &Cmnd->SCp
607 #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
608 #define CMD_CDBP(Cmnd) Cmnd->cmnd
609 #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
610 #define CMD_SNSLEN(Cmnd) sizeof(Cmnd->sense_buffer)
611 #define CMD_RESULT(Cmnd) Cmnd->result
612 #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
613 #if LINUX_VERSION_CODE < 0x020545
614 #define CMD_REQUEST(Cmnd) Cmnd->request.cmd
615 #else
616 #define CMD_REQUEST(Cmnd) Cmnd->request->cmd
617 #endif
618
619 #define CMD_HOST(Cmnd) Cmnd->device->host
620 #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
621 #define SCSI_TCN_32(Cmnd) Cmnd->device->id
622 #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
623
624
625 /*****************************************/
626 /* ISP Boards supported by this driver */
627 /*****************************************/
628
629 struct qla_boards {
630 unsigned char name[9]; /* Board ID String */
631 int numPorts; /* Number of SCSI ports */
632 unsigned short *fwcode; /* pointer to FW array */
633 unsigned short *fwlen; /* number of words in array */
634 unsigned short *fwstart; /* start address for F/W */
635 unsigned char *fwver; /* Ptr to F/W version array */
636 };
637
638 /* NOTE: the last argument in each entry is used to index ql1280_board_tbl */
639 static struct pci_device_id qla1280_pci_tbl[] = {
640 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP12160,
641 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
642 #ifdef CONFIG_SCSI_QLOGIC_1280_1040
643 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1020,
644 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
645 #endif
646 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1080,
647 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
648 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1240,
649 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
650 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1280,
651 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
652 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP10160,
653 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
654 {0,}
655 };
656 MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl);
657
658 static struct qla_boards ql1280_board_tbl[] = {
659 /* Name , Number of ports, FW details */
660 {"QLA12160", 2, &fw12160i_code01[0], &fw12160i_length01,
661 &fw12160i_addr01, &fw12160i_version_str[0]},
662 {"QLA1040", 1, &risc_code01[0], &risc_code_length01,
663 &risc_code_addr01, &firmware_version[0]},
664 {"QLA1080", 1, &fw1280ei_code01[0], &fw1280ei_length01,
665 &fw1280ei_addr01, &fw1280ei_version_str[0]},
666 {"QLA1240", 2, &fw1280ei_code01[0], &fw1280ei_length01,
667 &fw1280ei_addr01, &fw1280ei_version_str[0]},
668 {"QLA1280", 2, &fw1280ei_code01[0], &fw1280ei_length01,
669 &fw1280ei_addr01, &fw1280ei_version_str[0]},
670 {"QLA10160", 1, &fw12160i_code01[0], &fw12160i_length01,
671 &fw12160i_addr01, &fw12160i_version_str[0]},
672 {" ", 0}
673 };
674
675 static int qla1280_verbose = 1;
676
677 #if DEBUG_QLA1280
678 static int ql_debug_level = 1;
679 #define dprintk(level, format, a...) \
680 do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
681 #define qla1280_dump_buffer(level, buf, size) \
682 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
683 #define qla1280_print_scsi_cmd(level, cmd) \
684 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
685 #else
686 #define ql_debug_level 0
687 #define dprintk(level, format, a...) do{}while(0)
688 #define qla1280_dump_buffer(a, b, c) do{}while(0)
689 #define qla1280_print_scsi_cmd(a, b) do{}while(0)
690 #endif
691
692 #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
693 #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
694 #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
695 #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
696
697
698 static int qla1280_read_nvram(struct scsi_qla_host *ha)
699 {
700 uint16_t *wptr;
701 uint8_t chksum;
702 int cnt, i;
703 struct nvram *nv;
704
705 ENTER("qla1280_read_nvram");
706
707 if (driver_setup.no_nvram)
708 return 1;
709
710 printk(KERN_INFO "scsi(%ld): Reading NVRAM\n", ha->host_no);
711
712 wptr = (uint16_t *)&ha->nvram;
713 nv = &ha->nvram;
714 chksum = 0;
715 for (cnt = 0; cnt < 3; cnt++) {
716 *wptr = qla1280_get_nvram_word(ha, cnt);
717 chksum += *wptr & 0xff;
718 chksum += (*wptr >> 8) & 0xff;
719 wptr++;
720 }
721
722 if (nv->id0 != 'I' || nv->id1 != 'S' ||
723 nv->id2 != 'P' || nv->id3 != ' ' || nv->version < 1) {
724 dprintk(2, "Invalid nvram ID or version!\n");
725 chksum = 1;
726 } else {
727 for (; cnt < sizeof(struct nvram); cnt++) {
728 *wptr = qla1280_get_nvram_word(ha, cnt);
729 chksum += *wptr & 0xff;
730 chksum += (*wptr >> 8) & 0xff;
731 wptr++;
732 }
733 }
734
735 dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
736 " version %i\n", nv->id0, nv->id1, nv->id2, nv->id3,
737 nv->version);
738
739
740 if (chksum) {
741 if (!driver_setup.no_nvram)
742 printk(KERN_WARNING "scsi(%ld): Unable to identify or "
743 "validate NVRAM checksum, using default "
744 "settings\n", ha->host_no);
745 ha->nvram_valid = 0;
746 } else
747 ha->nvram_valid = 1;
748
749 /* The firmware interface is, um, interesting, in that the
750 * actual firmware image on the chip is little endian, thus,
751 * the process of taking that image to the CPU would end up
752 * little endian. However, the firmare interface requires it
753 * to be read a word (two bytes) at a time.
754 *
755 * The net result of this would be that the word (and
756 * doubleword) quantites in the firmware would be correct, but
757 * the bytes would be pairwise reversed. Since most of the
758 * firmware quantites are, in fact, bytes, we do an extra
759 * le16_to_cpu() in the firmware read routine.
760 *
761 * The upshot of all this is that the bytes in the firmware
762 * are in the correct places, but the 16 and 32 bit quantites
763 * are still in little endian format. We fix that up below by
764 * doing extra reverses on them */
765 nv->isp_parameter = cpu_to_le16(nv->isp_parameter);
766 nv->firmware_feature.w = cpu_to_le16(nv->firmware_feature.w);
767 for(i = 0; i < MAX_BUSES; i++) {
768 nv->bus[i].selection_timeout = cpu_to_le16(nv->bus[i].selection_timeout);
769 nv->bus[i].max_queue_depth = cpu_to_le16(nv->bus[i].max_queue_depth);
770 }
771 dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
772 LEAVE("qla1280_read_nvram");
773
774 return chksum;
775 }
776
777 /**************************************************************************
778 * qla1280_info
779 * Return a string describing the driver.
780 **************************************************************************/
781 static const char *
782 qla1280_info(struct Scsi_Host *host)
783 {
784 static char qla1280_scsi_name_buffer[125];
785 char *bp;
786 struct scsi_qla_host *ha;
787 struct qla_boards *bdp;
788
789 bp = &qla1280_scsi_name_buffer[0];
790 ha = (struct scsi_qla_host *)host->hostdata;
791 bdp = &ql1280_board_tbl[ha->devnum];
792 memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
793
794 sprintf (bp,
795 "QLogic %s PCI to SCSI Host Adapter\n"
796 " Firmware version: %2d.%02d.%02d, Driver version %s",
797 &bdp->name[0], bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
798 QLA1280_VERSION);
799 return bp;
800 }
801
802 /**************************************************************************
803 * qla1200_queuecommand
804 * Queue a command to the controller.
805 *
806 * Note:
807 * The mid-level driver tries to ensures that queuecommand never gets invoked
808 * concurrently with itself or the interrupt handler (although the
809 * interrupt handler may call this routine as part of request-completion
810 * handling). Unfortunely, it sometimes calls the scheduler in interrupt
811 * context which is a big NO! NO!.
812 **************************************************************************/
813 static int
814 qla1280_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
815 {
816 struct Scsi_Host *host = cmd->device->host;
817 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
818 struct srb *sp = (struct srb *)&cmd->SCp;
819 int status;
820
821 cmd->scsi_done = fn;
822 sp->cmd = cmd;
823 sp->flags = 0;
824
825 qla1280_print_scsi_cmd(5, cmd);
826
827 #ifdef QLA_64BIT_PTR
828 /*
829 * Using 64 bit commands if the PCI bridge doesn't support it is a
830 * bit wasteful, however this should really only happen if one's
831 * PCI controller is completely broken, like the BCM1250. For
832 * sane hardware this is not an issue.
833 */
834 status = qla1280_64bit_start_scsi(ha, sp);
835 #else
836 status = qla1280_32bit_start_scsi(ha, sp);
837 #endif
838 return status;
839 }
840
841 enum action {
842 ABORT_COMMAND,
843 ABORT_DEVICE,
844 DEVICE_RESET,
845 BUS_RESET,
846 ADAPTER_RESET,
847 FAIL
848 };
849
850 /* timer action for error action processor */
851 static void qla1280_error_wait_timeout(unsigned long __data)
852 {
853 struct scsi_cmnd *cmd = (struct scsi_cmnd *)__data;
854 struct srb *sp = (struct srb *)CMD_SP(cmd);
855
856 complete(sp->wait);
857 }
858
859 static void qla1280_mailbox_timeout(unsigned long __data)
860 {
861 struct scsi_qla_host *ha = (struct scsi_qla_host *)__data;
862 struct device_reg __iomem *reg;
863 reg = ha->iobase;
864
865 ha->mailbox_out[0] = RD_REG_WORD(&reg->mailbox0);
866 printk(KERN_ERR "scsi(%ld): mailbox timed out, mailbox0 %04x, "
867 "ictrl %04x, istatus %04x\n", ha->host_no, ha->mailbox_out[0],
868 RD_REG_WORD(&reg->ictrl), RD_REG_WORD(&reg->istatus));
869 complete(ha->mailbox_wait);
870 }
871
872 /**************************************************************************
873 * qla1200_error_action
874 * The function will attempt to perform a specified error action and
875 * wait for the results (or time out).
876 *
877 * Input:
878 * cmd = Linux SCSI command packet of the command that cause the
879 * bus reset.
880 * action = error action to take (see action_t)
881 *
882 * Returns:
883 * SUCCESS or FAILED
884 *
885 * Note:
886 * Resetting the bus always succeeds - is has to, otherwise the
887 * kernel will panic! Try a surgical technique - sending a BUS
888 * DEVICE RESET message - on the offending target before pulling
889 * the SCSI bus reset line.
890 **************************************************************************/
891 static int
892 qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
893 {
894 struct scsi_qla_host *ha;
895 int bus, target, lun;
896 struct srb *sp;
897 uint16_t data;
898 unsigned char *handle;
899 int result, i;
900 DECLARE_COMPLETION(wait);
901 struct timer_list timer;
902
903 ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
904
905 dprintk(4, "error_action %i, istatus 0x%04x\n", action,
906 RD_REG_WORD(&ha->iobase->istatus));
907
908 dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
909 RD_REG_WORD(&ha->iobase->host_cmd),
910 RD_REG_WORD(&ha->iobase->ictrl), jiffies);
911
912 ENTER("qla1280_error_action");
913 if (qla1280_verbose)
914 printk(KERN_INFO "scsi(%li): Resetting Cmnd=0x%p, "
915 "Handle=0x%p, action=0x%x\n",
916 ha->host_no, cmd, CMD_HANDLE(cmd), action);
917
918 if (cmd == NULL) {
919 printk(KERN_WARNING "(scsi?:?:?:?) Reset called with NULL "
920 "si_Cmnd pointer, failing.\n");
921 LEAVE("qla1280_error_action");
922 return FAILED;
923 }
924
925 ha = (struct scsi_qla_host *)cmd->device->host->hostdata;
926 sp = (struct srb *)CMD_SP(cmd);
927 handle = CMD_HANDLE(cmd);
928
929 /* Check for pending interrupts. */
930 data = qla1280_debounce_register(&ha->iobase->istatus);
931 /*
932 * The io_request_lock is held when the reset handler is called, hence
933 * the interrupt handler cannot be running in parallel as it also
934 * grabs the lock. /Jes
935 */
936 if (data & RISC_INT)
937 qla1280_isr(ha, &ha->done_q);
938
939 /*
940 * Determine the suggested action that the mid-level driver wants
941 * us to perform.
942 */
943 if (handle == (unsigned char *)INVALID_HANDLE || handle == NULL) {
944 if(action == ABORT_COMMAND) {
945 /* we never got this command */
946 printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
947 return SUCCESS; /* no action - we don't have command */
948 }
949 } else {
950 sp->wait = &wait;
951 }
952
953 bus = SCSI_BUS_32(cmd);
954 target = SCSI_TCN_32(cmd);
955 lun = SCSI_LUN_32(cmd);
956
957 /* Overloading result. Here it means the success or fail of the
958 * *issue* of the action. When we return from the routine, it must
959 * mean the actual success or fail of the action */
960 result = FAILED;
961 switch (action) {
962 case FAIL:
963 break;
964
965 case ABORT_COMMAND:
966 if ((sp->flags & SRB_ABORT_PENDING)) {
967 printk(KERN_WARNING
968 "scsi(): Command has a pending abort "
969 "message - ABORT_PENDING.\n");
970 /* This should technically be impossible since we
971 * now wait for abort completion */
972 break;
973 }
974
975 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
976 if (sp == ha->outstanding_cmds[i]) {
977 dprintk(1, "qla1280: RISC aborting command\n");
978 if (qla1280_abort_command(ha, sp, i) == 0)
979 result = SUCCESS;
980 else {
981 /*
982 * Since we don't know what might
983 * have happend to the command, it
984 * is unsafe to remove it from the
985 * device's queue at this point.
986 * Wait and let the escalation
987 * process take care of it.
988 */
989 printk(KERN_WARNING
990 "scsi(%li:%i:%i:%i): Unable"
991 " to abort command!\n",
992 ha->host_no, bus, target, lun);
993 }
994 }
995 }
996 break;
997
998 case ABORT_DEVICE:
999 ha->flags.in_reset = 1;
1000 if (qla1280_verbose)
1001 printk(KERN_INFO
1002 "scsi(%ld:%d:%d:%d): Queueing abort device "
1003 "command.\n", ha->host_no, bus, target, lun);
1004 if (qla1280_abort_device(ha, bus, target, lun) == 0)
1005 result = SUCCESS;
1006 break;
1007
1008 case DEVICE_RESET:
1009 if (qla1280_verbose)
1010 printk(KERN_INFO
1011 "scsi(%ld:%d:%d:%d): Queueing device reset "
1012 "command.\n", ha->host_no, bus, target, lun);
1013 ha->flags.in_reset = 1;
1014 if (qla1280_device_reset(ha, bus, target) == 0)
1015 result = SUCCESS;
1016 break;
1017
1018 case BUS_RESET:
1019 if (qla1280_verbose)
1020 printk(KERN_INFO "qla1280(%ld:%d): Issuing BUS "
1021 "DEVICE RESET\n", ha->host_no, bus);
1022 ha->flags.in_reset = 1;
1023 if (qla1280_bus_reset(ha, bus == 0))
1024 result = SUCCESS;
1025
1026 break;
1027
1028 case ADAPTER_RESET:
1029 default:
1030 if (qla1280_verbose) {
1031 printk(KERN_INFO
1032 "scsi(%ld): Issued ADAPTER RESET\n",
1033 ha->host_no);
1034 printk(KERN_INFO "scsi(%ld): I/O processing will "
1035 "continue automatically\n", ha->host_no);
1036 }
1037 ha->flags.reset_active = 1;
1038 /*
1039 * We restarted all of the commands automatically, so the
1040 * mid-level code can expect completions momentitarily.
1041 */
1042 if (qla1280_abort_isp(ha) == 0)
1043 result = SUCCESS;
1044
1045 ha->flags.reset_active = 0;
1046 }
1047
1048 if (!list_empty(&ha->done_q))
1049 qla1280_done(ha);
1050 ha->flags.in_reset = 0;
1051
1052 /* If we didn't manage to issue the action, or we have no
1053 * command to wait for, exit here */
1054 if (result == FAILED || handle == NULL ||
1055 handle == (unsigned char *)INVALID_HANDLE) {
1056 /*
1057 * Clear completion queue to avoid qla1280_done() trying
1058 * to complete the command at a later stage after we
1059 * have exited the current context
1060 */
1061 sp->wait = NULL;
1062 goto leave;
1063 }
1064
1065 /* set up a timer just in case we're really jammed */
1066 init_timer(&timer);
1067 timer.expires = jiffies + 4*HZ;
1068 timer.data = (unsigned long)cmd;
1069 timer.function = qla1280_error_wait_timeout;
1070 add_timer(&timer);
1071
1072 /* wait for the action to complete (or the timer to expire) */
1073 spin_unlock_irq(HOST_LOCK);
1074 wait_for_completion(&wait);
1075 del_timer_sync(&timer);
1076 spin_lock_irq(HOST_LOCK);
1077 sp->wait = NULL;
1078
1079 /* the only action we might get a fail for is abort */
1080 if (action == ABORT_COMMAND) {
1081 if(sp->flags & SRB_ABORTED)
1082 result = SUCCESS;
1083 else
1084 result = FAILED;
1085 }
1086
1087 leave:
1088 dprintk(1, "RESET returning %d\n", result);
1089
1090 LEAVE("qla1280_error_action");
1091 return result;
1092 }
1093
1094 /**************************************************************************
1095 * qla1280_abort
1096 * Abort the specified SCSI command(s).
1097 **************************************************************************/
1098 static int
1099 qla1280_eh_abort(struct scsi_cmnd * cmd)
1100 {
1101 int rc;
1102
1103 spin_lock_irq(cmd->device->host->host_lock);
1104 rc = qla1280_error_action(cmd, ABORT_COMMAND);
1105 spin_unlock_irq(cmd->device->host->host_lock);
1106
1107 return rc;
1108 }
1109
1110 /**************************************************************************
1111 * qla1280_device_reset
1112 * Reset the specified SCSI device
1113 **************************************************************************/
1114 static int
1115 qla1280_eh_device_reset(struct scsi_cmnd *cmd)
1116 {
1117 return qla1280_error_action(cmd, DEVICE_RESET);
1118 }
1119
1120 /**************************************************************************
1121 * qla1280_bus_reset
1122 * Reset the specified bus.
1123 **************************************************************************/
1124 static int
1125 qla1280_eh_bus_reset(struct scsi_cmnd *cmd)
1126 {
1127 return qla1280_error_action(cmd, BUS_RESET);
1128 }
1129
1130 /**************************************************************************
1131 * qla1280_adapter_reset
1132 * Reset the specified adapter (both channels)
1133 **************************************************************************/
1134 static int
1135 qla1280_eh_adapter_reset(struct scsi_cmnd *cmd)
1136 {
1137 return qla1280_error_action(cmd, ADAPTER_RESET);
1138 }
1139
1140 static int
1141 qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1142 sector_t capacity, int geom[])
1143 {
1144 int heads, sectors, cylinders;
1145
1146 heads = 64;
1147 sectors = 32;
1148 cylinders = (unsigned long)capacity / (heads * sectors);
1149 if (cylinders > 1024) {
1150 heads = 255;
1151 sectors = 63;
1152 cylinders = (unsigned long)capacity / (heads * sectors);
1153 /* if (cylinders > 1023)
1154 cylinders = 1023; */
1155 }
1156
1157 geom[0] = heads;
1158 geom[1] = sectors;
1159 geom[2] = cylinders;
1160
1161 return 0;
1162 }
1163
1164 #if LINUX_VERSION_CODE < 0x020600
1165 static int
1166 qla1280_detect(Scsi_Host_Template *template)
1167 {
1168 struct pci_device_id *id = &qla1280_pci_tbl[0];
1169 struct pci_dev *pdev = NULL;
1170 int num_hosts = 0;
1171
1172 if (sizeof(struct srb) > sizeof(Scsi_Pointer)) {
1173 printk(KERN_WARNING
1174 "qla1280: struct srb too big, aborting\n");
1175 return 0;
1176 }
1177
1178 if ((DMA_BIDIRECTIONAL != PCI_DMA_BIDIRECTIONAL) ||
1179 (DMA_TO_DEVICE != PCI_DMA_TODEVICE) ||
1180 (DMA_FROM_DEVICE != PCI_DMA_FROMDEVICE) ||
1181 (DMA_NONE != PCI_DMA_NONE)) {
1182 printk(KERN_WARNING
1183 "qla1280: dma direction bits don't match\n");
1184 return 0;
1185 }
1186
1187 #ifdef MODULE
1188 /*
1189 * If we are called as a module, the qla1280 pointer may not be null
1190 * and it would point to our bootup string, just like on the lilo
1191 * command line. IF not NULL, then process this config string with
1192 * qla1280_setup
1193 *
1194 * Boot time Options
1195 * To add options at boot time add a line to your lilo.conf file like:
1196 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
1197 * which will result in the first four devices on the first two
1198 * controllers being set to a tagged queue depth of 32.
1199 */
1200 if (qla1280)
1201 qla1280_setup(qla1280);
1202 #endif
1203
1204 /* First Initialize QLA12160 on PCI Bus 1 Dev 2 */
1205 while ((pdev = pci_find_device(id->vendor, id->device, pdev))) {
1206 if (pdev->bus->number == 1 && PCI_SLOT(pdev->devfn) == 2) {
1207 if (!qla1280_probe_one(pdev, id))
1208 num_hosts++;
1209 }
1210 }
1211
1212 pdev = NULL;
1213 /* Try and find each different type of adapter we support */
1214 for (id = &qla1280_pci_tbl[0]; id->device; id++) {
1215 while ((pdev = pci_find_device(id->vendor, id->device, pdev))) {
1216 /*
1217 * skip QLA12160 already initialized on
1218 * PCI Bus 1 Dev 2 since we already initialized
1219 * and presented it
1220 */
1221 if (id->device == PCI_DEVICE_ID_QLOGIC_ISP12160 &&
1222 pdev->bus->number == 1 &&
1223 PCI_SLOT(pdev->devfn) == 2)
1224 continue;
1225
1226 if (!qla1280_probe_one(pdev, id))
1227 num_hosts++;
1228 }
1229 }
1230
1231 return num_hosts;
1232 }
1233
1234 /*
1235 * This looks a bit ugly as we could just pass down host to
1236 * qla1280_remove_one, but I want to keep qla1280_release purely a wrapper
1237 * around pci_driver::remove as used from 2.6 onwards.
1238 */
1239 static int
1240 qla1280_release(struct Scsi_Host *host)
1241 {
1242 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
1243
1244 qla1280_remove_one(ha->pdev);
1245 return 0;
1246 }
1247
1248 static int
1249 qla1280_biosparam_old(Disk * disk, kdev_t dev, int geom[])
1250 {
1251 return qla1280_biosparam(disk->device, NULL, disk->capacity, geom);
1252 }
1253 #endif
1254
1255 /**************************************************************************
1256 * qla1280_intr_handler
1257 * Handles the H/W interrupt
1258 **************************************************************************/
1259 static irqreturn_t
1260 qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1261 {
1262 struct scsi_qla_host *ha;
1263 struct device_reg __iomem *reg;
1264 u16 data;
1265 int handled = 0;
1266
1267 ENTER_INTR ("qla1280_intr_handler");
1268 ha = (struct scsi_qla_host *)dev_id;
1269
1270 spin_lock(HOST_LOCK);
1271
1272 ha->isr_count++;
1273 reg = ha->iobase;
1274
1275 WRT_REG_WORD(&reg->ictrl, 0); /* disable our interrupt. */
1276
1277 data = qla1280_debounce_register(&reg->istatus);
1278 /* Check for pending interrupts. */
1279 if (data & RISC_INT) {
1280 qla1280_isr(ha, &ha->done_q);
1281 handled = 1;
1282 }
1283 if (!list_empty(&ha->done_q))
1284 qla1280_done(ha);
1285
1286 spin_unlock(HOST_LOCK);
1287
1288 /* enable our interrupt. */
1289 WRT_REG_WORD(&reg->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1290
1291 LEAVE_INTR("qla1280_intr_handler");
1292 return IRQ_RETVAL(handled);
1293 }
1294
1295
1296 static int
1297 qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
1298 {
1299 uint8_t mr;
1300 uint16_t mb[MAILBOX_REGISTER_COUNT];
1301 struct nvram *nv;
1302 int status;
1303
1304 nv = &ha->nvram;
1305
1306 mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
1307
1308 /* Set Target Parameters. */
1309 mb[0] = MBC_SET_TARGET_PARAMETERS;
1310 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
1311 mb[1] <<= 8;
1312
1313 mb[2] = (nv->bus[bus].target[target].parameter.c << 8);
1314
1315 if (IS_ISP1x160(ha)) {
1316 mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
1317 mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8) |
1318 nv->bus[bus].target[target].sync_period;
1319 mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) |
1320 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
1321 mr |= BIT_6;
1322 } else {
1323 mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8) |
1324 nv->bus[bus].target[target].sync_period;
1325 }
1326
1327 status = qla1280_mailbox_command(ha, mr, &mb[0]);
1328
1329 if (status)
1330 printk(KERN_WARNING "scsi(%ld:%i:%i): "
1331 "qla1280_set_target_parameters() failed\n",
1332 ha->host_no, bus, target);
1333 return status;
1334 }
1335
1336
1337 /**************************************************************************
1338 * qla1280_slave_configure
1339 *
1340 * Description:
1341 * Determines the queue depth for a given device. There are two ways
1342 * a queue depth can be obtained for a tagged queueing device. One
1343 * way is the default queue depth which is determined by whether
1344 * If it is defined, then it is used
1345 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1346 * default queue depth (dependent on the number of hardware SCBs).
1347 **************************************************************************/
1348 static int
1349 qla1280_slave_configure(struct scsi_device *device)
1350 {
1351 struct scsi_qla_host *ha;
1352 int default_depth = 3;
1353 int bus = device->channel;
1354 int target = device->id;
1355 int status = 0;
1356 struct nvram *nv;
1357 unsigned long flags;
1358
1359 ha = (struct scsi_qla_host *)device->host->hostdata;
1360 nv = &ha->nvram;
1361
1362 if (qla1280_check_for_dead_scsi_bus(ha, bus))
1363 return 1;
1364
1365 if (device->tagged_supported &&
1366 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1367 scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
1368 ha->bus_settings[bus].hiwat);
1369 } else {
1370 scsi_adjust_queue_depth(device, 0, default_depth);
1371 }
1372
1373 #if LINUX_VERSION_CODE > 0x020500
1374 nv->bus[bus].target[target].parameter.f.enable_sync = device->sdtr;
1375 nv->bus[bus].target[target].parameter.f.enable_wide = device->wdtr;
1376 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
1377 #endif
1378
1379 if (driver_setup.no_sync ||
1380 (driver_setup.sync_mask &&
1381 (~driver_setup.sync_mask & (1 << target))))
1382 nv->bus[bus].target[target].parameter.f.enable_sync = 0;
1383 if (driver_setup.no_wide ||
1384 (driver_setup.wide_mask &&
1385 (~driver_setup.wide_mask & (1 << target))))
1386 nv->bus[bus].target[target].parameter.f.enable_wide = 0;
1387 if (IS_ISP1x160(ha)) {
1388 if (driver_setup.no_ppr ||
1389 (driver_setup.ppr_mask &&
1390 (~driver_setup.ppr_mask & (1 << target))))
1391 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
1392 }
1393
1394 spin_lock_irqsave(HOST_LOCK, flags);
1395 if (nv->bus[bus].target[target].parameter.f.enable_sync)
1396 status = qla1280_set_target_parameters(ha, bus, target);
1397 qla1280_get_target_parameters(ha, device);
1398 spin_unlock_irqrestore(HOST_LOCK, flags);
1399 return status;
1400 }
1401
1402 #if LINUX_VERSION_CODE < 0x020545
1403 /**************************************************************************
1404 * qla1280_select_queue_depth
1405 *
1406 * Sets the queue depth for each SCSI device hanging off the input
1407 * host adapter. We use a queue depth of 2 for devices that do not
1408 * support tagged queueing.
1409 **************************************************************************/
1410 static void
1411 qla1280_select_queue_depth(struct Scsi_Host *host, struct scsi_device *sdev_q)
1412 {
1413 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
1414 struct scsi_device *sdev;
1415
1416 ENTER("qla1280_select_queue_depth");
1417 for (sdev = sdev_q; sdev; sdev = sdev->next)
1418 if (sdev->host == host)
1419 qla1280_slave_configure(sdev);
1420
1421 if (sdev_q)
1422 qla1280_check_for_dead_scsi_bus(ha, sdev_q->channel);
1423 LEAVE("qla1280_select_queue_depth");
1424 }
1425 #endif
1426
1427 /*
1428 * qla1280_done
1429 * Process completed commands.
1430 *
1431 * Input:
1432 * ha = adapter block pointer.
1433 * done_q = done queue.
1434 */
1435 static void
1436 qla1280_done(struct scsi_qla_host *ha)
1437 {
1438 struct srb *sp;
1439 struct list_head *done_q;
1440 int bus, target, lun;
1441 struct scsi_cmnd *cmd;
1442
1443 ENTER("qla1280_done");
1444
1445 done_q = &ha->done_q;
1446
1447 while (!list_empty(done_q)) {
1448 sp = list_entry(done_q->next, struct srb, list);
1449
1450 list_del(&sp->list);
1451
1452 cmd = sp->cmd;
1453 bus = SCSI_BUS_32(cmd);
1454 target = SCSI_TCN_32(cmd);
1455 lun = SCSI_LUN_32(cmd);
1456
1457 switch ((CMD_RESULT(cmd) >> 16)) {
1458 case DID_RESET:
1459 /* Issue marker command. */
1460 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
1461 break;
1462 case DID_ABORT:
1463 sp->flags &= ~SRB_ABORT_PENDING;
1464 sp->flags |= SRB_ABORTED;
1465 if (sp->flags & SRB_TIMEOUT)
1466 CMD_RESULT(sp->cmd) = DID_TIME_OUT << 16;
1467 break;
1468 default:
1469 break;
1470 }
1471
1472 /* Release memory used for this I/O */
1473 if (cmd->use_sg) {
1474 pci_unmap_sg(ha->pdev, cmd->request_buffer,
1475 cmd->use_sg, cmd->sc_data_direction);
1476 } else if (cmd->request_bufflen) {
1477 pci_unmap_single(ha->pdev, sp->saved_dma_handle,
1478 cmd->request_bufflen,
1479 cmd->sc_data_direction);
1480 }
1481
1482 /* Call the mid-level driver interrupt handler */
1483 CMD_HANDLE(sp->cmd) = (unsigned char *)INVALID_HANDLE;
1484 ha->actthreads--;
1485
1486 #if LINUX_VERSION_CODE < 0x020500
1487 if (cmd->cmnd[0] == INQUIRY)
1488 qla1280_get_target_options(cmd, ha);
1489 #endif
1490 (*(cmd)->scsi_done)(cmd);
1491
1492 if(sp->wait != NULL)
1493 complete(sp->wait);
1494 }
1495 LEAVE("qla1280_done");
1496 }
1497
1498 /*
1499 * Translates a ISP error to a Linux SCSI error
1500 */
1501 static int
1502 qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1503 {
1504 int host_status = DID_ERROR;
1505 uint16_t comp_status = le16_to_cpu(sts->comp_status);
1506 uint16_t state_flags = le16_to_cpu(sts->state_flags);
1507 uint16_t residual_length = le16_to_cpu(sts->residual_length);
1508 uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
1509 #if DEBUG_QLA1280_INTR
1510 static char *reason[] = {
1511 "DID_OK",
1512 "DID_NO_CONNECT",
1513 "DID_BUS_BUSY",
1514 "DID_TIME_OUT",
1515 "DID_BAD_TARGET",
1516 "DID_ABORT",
1517 "DID_PARITY",
1518 "DID_ERROR",
1519 "DID_RESET",
1520 "DID_BAD_INTR"
1521 };
1522 #endif /* DEBUG_QLA1280_INTR */
1523
1524 ENTER("qla1280_return_status");
1525
1526 #if DEBUG_QLA1280_INTR
1527 /*
1528 dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
1529 comp_status);
1530 */
1531 #endif
1532
1533 switch (comp_status) {
1534 case CS_COMPLETE:
1535 host_status = DID_OK;
1536 break;
1537
1538 case CS_INCOMPLETE:
1539 if (!(state_flags & SF_GOT_BUS))
1540 host_status = DID_NO_CONNECT;
1541 else if (!(state_flags & SF_GOT_TARGET))
1542 host_status = DID_BAD_TARGET;
1543 else if (!(state_flags & SF_SENT_CDB))
1544 host_status = DID_ERROR;
1545 else if (!(state_flags & SF_TRANSFERRED_DATA))
1546 host_status = DID_ERROR;
1547 else if (!(state_flags & SF_GOT_STATUS))
1548 host_status = DID_ERROR;
1549 else if (!(state_flags & SF_GOT_SENSE))
1550 host_status = DID_ERROR;
1551 break;
1552
1553 case CS_RESET:
1554 host_status = DID_RESET;
1555 break;
1556
1557 case CS_ABORTED:
1558 host_status = DID_ABORT;
1559 break;
1560
1561 case CS_TIMEOUT:
1562 host_status = DID_TIME_OUT;
1563 break;
1564
1565 case CS_DATA_OVERRUN:
1566 dprintk(2, "Data overrun 0x%x\n", residual_length);
1567 dprintk(2, "qla1280_isr: response packet data\n");
1568 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
1569 host_status = DID_ERROR;
1570 break;
1571
1572 case CS_DATA_UNDERRUN:
1573 if ((cp->request_bufflen - residual_length) <
1574 cp->underflow) {
1575 printk(KERN_WARNING
1576 "scsi: Underflow detected - retrying "
1577 "command.\n");
1578 host_status = DID_ERROR;
1579 } else
1580 host_status = DID_OK;
1581 break;
1582
1583 default:
1584 host_status = DID_ERROR;
1585 break;
1586 }
1587
1588 #if DEBUG_QLA1280_INTR
1589 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
1590 reason[host_status], scsi_status);
1591 #endif
1592
1593 LEAVE("qla1280_return_status");
1594
1595 return (scsi_status & 0xff) | (host_status << 16);
1596 }
1597
1598 /****************************************************************************/
1599 /* QLogic ISP1280 Hardware Support Functions. */
1600 /****************************************************************************/
1601
1602 /*
1603 * qla2100_enable_intrs
1604 * qla2100_disable_intrs
1605 *
1606 * Input:
1607 * ha = adapter block pointer.
1608 *
1609 * Returns:
1610 * None
1611 */
1612 static inline void
1613 qla1280_enable_intrs(struct scsi_qla_host *ha)
1614 {
1615 struct device_reg __iomem *reg;
1616
1617 reg = ha->iobase;
1618 /* enable risc and host interrupts */
1619 WRT_REG_WORD(&reg->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1620 RD_REG_WORD(&reg->ictrl); /* PCI Posted Write flush */
1621 ha->flags.ints_enabled = 1;
1622 }
1623
1624 static inline void
1625 qla1280_disable_intrs(struct scsi_qla_host *ha)
1626 {
1627 struct device_reg __iomem *reg;
1628
1629 reg = ha->iobase;
1630 /* disable risc and host interrupts */
1631 WRT_REG_WORD(&reg->ictrl, 0);
1632 RD_REG_WORD(&reg->ictrl); /* PCI Posted Write flush */
1633 ha->flags.ints_enabled = 0;
1634 }
1635
1636 /*
1637 * qla1280_initialize_adapter
1638 * Initialize board.
1639 *
1640 * Input:
1641 * ha = adapter block pointer.
1642 *
1643 * Returns:
1644 * 0 = success
1645 */
1646 static int __devinit
1647 qla1280_initialize_adapter(struct scsi_qla_host *ha)
1648 {
1649 struct device_reg __iomem *reg;
1650 int status;
1651 int bus;
1652 #if LINUX_VERSION_CODE > 0x020500
1653 unsigned long flags;
1654 #endif
1655
1656 ENTER("qla1280_initialize_adapter");
1657
1658 /* Clear adapter flags. */
1659 ha->flags.online = 0;
1660 ha->flags.disable_host_adapter = 0;
1661 ha->flags.reset_active = 0;
1662 ha->flags.abort_isp_active = 0;
1663
1664 ha->flags.ints_enabled = 0;
1665 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1666 if (ia64_platform_is("sn2")) {
1667 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
1668 "dual channel lockup workaround\n", ha->host_no);
1669 ha->flags.use_pci_vchannel = 1;
1670 driver_setup.no_nvram = 1;
1671 }
1672 #endif
1673
1674 /* TODO: implement support for the 1040 nvram format */
1675 if (IS_ISP1040(ha))
1676 driver_setup.no_nvram = 1;
1677
1678 dprintk(1, "Configure PCI space for adapter...\n");
1679
1680 reg = ha->iobase;
1681
1682 /* Insure mailbox registers are free. */
1683 WRT_REG_WORD(&reg->semaphore, 0);
1684 WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
1685 WRT_REG_WORD(&reg->host_cmd, HC_CLR_HOST_INT);
1686 RD_REG_WORD(&reg->host_cmd);
1687
1688 if (qla1280_read_nvram(ha)) {
1689 dprintk(2, "qla1280_initialize_adapter: failed to read "
1690 "NVRAM\n");
1691 }
1692
1693 #if LINUX_VERSION_CODE >= 0x020500
1694 /*
1695 * It's necessary to grab the spin here as qla1280_mailbox_command
1696 * needs to be able to drop the lock unconditionally to wait
1697 * for completion.
1698 * In 2.4 ->detect is called with the io_request_lock held.
1699 */
1700 spin_lock_irqsave(HOST_LOCK, flags);
1701 #endif
1702
1703 status = qla1280_load_firmware(ha);
1704 if (status) {
1705 printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
1706 ha->host_no);
1707 goto out;
1708 }
1709
1710 /* Setup adapter based on NVRAM parameters. */
1711 dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha->host_no);
1712 qla1280_nvram_config(ha);
1713
1714 if (ha->flags.disable_host_adapter) {
1715 status = 1;
1716 goto out;
1717 }
1718
1719 status = qla1280_init_rings(ha);
1720 if (status)
1721 goto out;
1722
1723 /* Issue SCSI reset, if we can't reset twice then bus is dead */
1724 for (bus = 0; bus < ha->ports; bus++) {
1725 if (!ha->bus_settings[bus].disable_scsi_reset &&
1726 qla1280_bus_reset(ha, bus) &&
1727 qla1280_bus_reset(ha, bus))
1728 ha->bus_settings[bus].scsi_bus_dead = 1;
1729 }
1730
1731 ha->flags.online = 1;
1732 out:
1733 #if LINUX_VERSION_CODE >= 0x020500
1734 spin_unlock_irqrestore(HOST_LOCK, flags);
1735 #endif
1736 if (status)
1737 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
1738
1739 LEAVE("qla1280_initialize_adapter");
1740 return status;
1741 }
1742
1743
1744 /*
1745 * ISP Firmware Test
1746 * Checks if present version of RISC firmware is older than
1747 * driver firmware.
1748 *
1749 * Input:
1750 * ha = adapter block pointer.
1751 *
1752 * Returns:
1753 * 0 = firmware does not need to be loaded.
1754 */
1755 static int
1756 qla1280_isp_firmware(struct scsi_qla_host *ha)
1757 {
1758 struct nvram *nv = (struct nvram *) ha->response_ring;
1759 int status = 0; /* dg 2/27 always loads RISC */
1760 uint16_t mb[MAILBOX_REGISTER_COUNT];
1761
1762 ENTER("qla1280_isp_firmware");
1763
1764 dprintk(1, "scsi(%li): Determining if RISC is loaded\n", ha->host_no);
1765
1766 /* Bad NVRAM data, load RISC code. */
1767 if (!ha->nvram_valid) {
1768 ha->flags.disable_risc_code_load = 0;
1769 } else
1770 ha->flags.disable_risc_code_load =
1771 nv->cntr_flags_1.disable_loading_risc_code;
1772
1773 if (ha->flags.disable_risc_code_load) {
1774 dprintk(3, "qla1280_isp_firmware: Telling RISC to verify "
1775 "checksum of loaded BIOS code.\n");
1776
1777 /* Verify checksum of loaded RISC code. */
1778 mb[0] = MBC_VERIFY_CHECKSUM;
1779 /* mb[1] = ql12_risc_code_addr01; */
1780 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1781
1782 if (!(status =
1783 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]))) {
1784 /* Start firmware execution. */
1785 dprintk(3, "qla1280_isp_firmware: Startng F/W "
1786 "execution.\n");
1787
1788 mb[0] = MBC_EXECUTE_FIRMWARE;
1789 /* mb[1] = ql12_risc_code_addr01; */
1790 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1791 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
1792 } else
1793 printk(KERN_INFO "qla1280: RISC checksum failed.\n");
1794 } else {
1795 dprintk(1, "qla1280: NVRAM configured to load RISC load.\n");
1796 status = 1;
1797 }
1798
1799 if (status)
1800 dprintk(2, "qla1280_isp_firmware: **** Load RISC code ****\n");
1801
1802 LEAVE("qla1280_isp_firmware");
1803 return status;
1804 }
1805
1806 /*
1807 * Chip diagnostics
1808 * Test chip for proper operation.
1809 *
1810 * Input:
1811 * ha = adapter block pointer.
1812 *
1813 * Returns:
1814 * 0 = success.
1815 */
1816 static int
1817 qla1280_chip_diag(struct scsi_qla_host *ha)
1818 {
1819 uint16_t mb[MAILBOX_REGISTER_COUNT];
1820 struct device_reg __iomem *reg = ha->iobase;
1821 int status = 0;
1822 int cnt;
1823 uint16_t data;
1824 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", &reg->id_l);
1825
1826 dprintk(1, "scsi(%ld): Verifying chip\n", ha->host_no);
1827
1828 /* Soft reset chip and wait for it to finish. */
1829 WRT_REG_WORD(&reg->ictrl, ISP_RESET);
1830
1831 /*
1832 * We can't do a traditional PCI write flush here by reading
1833 * back the register. The card will not respond once the reset
1834 * is in action and we end up with a machine check exception
1835 * instead. Nothing to do but wait and hope for the best.
1836 * A portable pci_write_flush(pdev) call would be very useful here.
1837 */
1838 udelay(20);
1839 data = qla1280_debounce_register(&reg->ictrl);
1840 /*
1841 * Yet another QLogic gem ;-(
1842 */
1843 for (cnt = 1000000; cnt && data & ISP_RESET; cnt--) {
1844 udelay(5);
1845 data = RD_REG_WORD(&reg->ictrl);
1846 }
1847
1848 if (!cnt)
1849 goto fail;
1850
1851 /* Reset register cleared by chip reset. */
1852 dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
1853
1854 WRT_REG_WORD(&reg->cfg_1, 0);
1855
1856 /* Reset RISC and disable BIOS which
1857 allows RISC to execute out of RAM. */
1858 WRT_REG_WORD(&reg->host_cmd, HC_RESET_RISC |
1859 HC_RELEASE_RISC | HC_DISABLE_BIOS);
1860
1861 RD_REG_WORD(&reg->id_l); /* Flush PCI write */
1862 data = qla1280_debounce_register(&reg->mailbox0);
1863
1864 /*
1865 * I *LOVE* this code!
1866 */
1867 for (cnt = 1000000; cnt && data == MBS_BUSY; cnt--) {
1868 udelay(5);
1869 data = RD_REG_WORD(&reg->mailbox0);
1870 }
1871
1872 if (!cnt)
1873 goto fail;
1874
1875 /* Check product ID of chip */
1876 dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
1877
1878 if (RD_REG_WORD(&reg->mailbox1) != PROD_ID_1 ||
1879 (RD_REG_WORD(&reg->mailbox2) != PROD_ID_2 &&
1880 RD_REG_WORD(&reg->mailbox2) != PROD_ID_2a) ||
1881 RD_REG_WORD(&reg->mailbox3) != PROD_ID_3 ||
1882 RD_REG_WORD(&reg->mailbox4) != PROD_ID_4) {
1883 printk(KERN_INFO "qla1280: Wrong product ID = "
1884 "0x%x,0x%x,0x%x,0x%x\n",
1885 RD_REG_WORD(&reg->mailbox1),
1886 RD_REG_WORD(&reg->mailbox2),
1887 RD_REG_WORD(&reg->mailbox3),
1888 RD_REG_WORD(&reg->mailbox4));
1889 goto fail;
1890 }
1891
1892 /*
1893 * Enable ints early!!!
1894 */
1895 qla1280_enable_intrs(ha);
1896
1897 dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
1898 /* Wrap Incoming Mailboxes Test. */
1899 mb[0] = MBC_MAILBOX_REGISTER_TEST;
1900 mb[1] = 0xAAAA;
1901 mb[2] = 0x5555;
1902 mb[3] = 0xAA55;
1903 mb[4] = 0x55AA;
1904 mb[5] = 0xA5A5;
1905 mb[6] = 0x5A5A;
1906 mb[7] = 0x2525;
1907
1908 status = qla1280_mailbox_command(ha, 0xff, mb);
1909 if (status)
1910 goto fail;
1911
1912 if (mb[1] != 0xAAAA || mb[2] != 0x5555 || mb[3] != 0xAA55 ||
1913 mb[4] != 0x55AA || mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
1914 mb[7] != 0x2525) {
1915 printk(KERN_INFO "qla1280: Failed mbox check\n");
1916 goto fail;
1917 }
1918
1919 dprintk(3, "qla1280_chip_diag: exiting normally\n");
1920 return 0;
1921 fail:
1922 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
1923 return status;
1924 }
1925
1926 static int
1927 qla1280_load_firmware_pio(struct scsi_qla_host *ha)
1928 {
1929 uint16_t risc_address, *risc_code_address, risc_code_size;
1930 uint16_t mb[MAILBOX_REGISTER_COUNT], i;
1931 int err;
1932
1933 /* Load RISC code. */
1934 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
1935 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
1936 risc_code_size = *ql1280_board_tbl[ha->devnum].fwlen;
1937
1938 for (i = 0; i < risc_code_size; i++) {
1939 mb[0] = MBC_WRITE_RAM_WORD;
1940 mb[1] = risc_address + i;
1941 mb[2] = risc_code_address[i];
1942
1943 err = qla1280_mailbox_command(ha, BIT_0 | BIT_1 | BIT_2, mb);
1944 if (err) {
1945 printk(KERN_ERR "scsi(%li): Failed to load firmware\n",
1946 ha->host_no);
1947 return err;
1948 }
1949 }
1950
1951 return 0;
1952 }
1953
1954 #define DUMP_IT_BACK 0 /* for debug of RISC loading */
1955 static int
1956 qla1280_load_firmware_dma(struct scsi_qla_host *ha)
1957 {
1958 uint16_t risc_address, *risc_code_address, risc_code_size;
1959 uint16_t mb[MAILBOX_REGISTER_COUNT], cnt;
1960 int err = 0, num, i;
1961 #if DUMP_IT_BACK
1962 uint8_t *sp, *tbuf;
1963 dma_addr_t p_tbuf;
1964
1965 tbuf = pci_alloc_consistent(ha->pdev, 8000, &p_tbuf);
1966 if (!tbuf)
1967 return -ENOMEM;
1968 #endif
1969
1970 /* Load RISC code. */
1971 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
1972 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
1973 risc_code_size = *ql1280_board_tbl[ha->devnum].fwlen;
1974
1975 dprintk(1, "%s: DMA RISC code (%i) words\n",
1976 __FUNCTION__, risc_code_size);
1977
1978 num = 0;
1979 while (risc_code_size > 0) {
1980 int warn __attribute__((unused)) = 0;
1981
1982 cnt = 2000 >> 1;
1983
1984 if (cnt > risc_code_size)
1985 cnt = risc_code_size;
1986
1987 dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
1988 "%d,%d(0x%x)\n",
1989 risc_code_address, cnt, num, risc_address);
1990 for(i = 0; i < cnt; i++)
1991 ((uint16_t *)ha->request_ring)[i] =
1992 cpu_to_le16(risc_code_address[i]);
1993
1994 mb[0] = MBC_LOAD_RAM;
1995 mb[1] = risc_address;
1996 mb[4] = cnt;
1997 mb[3] = ha->request_dma & 0xffff;
1998 mb[2] = (ha->request_dma >> 16) & 0xffff;
1999 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2000 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2001 dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
2002 __FUNCTION__, mb[0],
2003 (void *)(long)ha->request_dma,
2004 mb[6], mb[7], mb[2], mb[3]);
2005 err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
2006 BIT_1 | BIT_0, mb);
2007 if (err) {
2008 printk(KERN_ERR "scsi(%li): Failed to load partial "
2009 "segment of f\n", ha->host_no);
2010 goto out;
2011 }
2012
2013 #if DUMP_IT_BACK
2014 mb[0] = MBC_DUMP_RAM;
2015 mb[1] = risc_address;
2016 mb[4] = cnt;
2017 mb[3] = p_tbuf & 0xffff;
2018 mb[2] = (p_tbuf >> 16) & 0xffff;
2019 mb[7] = pci_dma_hi32(p_tbuf) & 0xffff;
2020 mb[6] = pci_dma_hi32(p_tbuf) >> 16;
2021
2022 err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
2023 BIT_1 | BIT_0, mb);
2024 if (err) {
2025 printk(KERN_ERR
2026 "Failed to dump partial segment of f/w\n");
2027 goto out;
2028 }
2029 sp = (uint8_t *)ha->request_ring;
2030 for (i = 0; i < (cnt << 1); i++) {
2031 if (tbuf[i] != sp[i] && warn++ < 10) {
2032 printk(KERN_ERR "%s: FW compare error @ "
2033 "byte(0x%x) loop#=%x\n",
2034 __FUNCTION__, i, num);
2035 printk(KERN_ERR "%s: FWbyte=%x "
2036 "FWfromChip=%x\n",
2037 __FUNCTION__, sp[i], tbuf[i]);
2038 /*break; */
2039 }
2040 }
2041 #endif
2042 risc_address += cnt;
2043 risc_code_size = risc_code_size - cnt;
2044 risc_code_address = risc_code_address + cnt;
2045 num++;
2046 }
2047
2048 out:
2049 #if DUMP_IT_BACK
2050 pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
2051 #endif
2052 return err;
2053 }
2054
2055 static int
2056 qla1280_start_firmware(struct scsi_qla_host *ha)
2057 {
2058 uint16_t mb[MAILBOX_REGISTER_COUNT];
2059 int err;
2060
2061 dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
2062 __FUNCTION__);
2063
2064 /* Verify checksum of loaded RISC code. */
2065 mb[0] = MBC_VERIFY_CHECKSUM;
2066 /* mb[1] = ql12_risc_code_addr01; */
2067 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2068 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2069 if (err) {
2070 printk(KERN_ERR "scsi(%li): Failed checksum\n", ha->host_no);
2071 return err;
2072 }
2073
2074 /* Start firmware execution. */
2075 dprintk(1, "%s: start firmware running.\n", __FUNCTION__);
2076 mb[0] = MBC_EXECUTE_FIRMWARE;
2077 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2078 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2079 if (err) {
2080 printk(KERN_ERR "scsi(%li): Failed to start firmware\n",
2081 ha->host_no);
2082 }
2083
2084 return err;
2085 }
2086
2087 static int
2088 qla1280_load_firmware(struct scsi_qla_host *ha)
2089 {
2090 int err = -ENODEV;
2091
2092 /* If firmware needs to be loaded */
2093 if (!qla1280_isp_firmware(ha)) {
2094 printk(KERN_ERR "scsi(%li): isp_firmware() failed!\n",
2095 ha->host_no);
2096 goto out;
2097 }
2098
2099 err = qla1280_chip_diag(ha);
2100 if (err)
2101 goto out;
2102 if (IS_ISP1040(ha))
2103 err = qla1280_load_firmware_pio(ha);
2104 else
2105 err = qla1280_load_firmware_dma(ha);
2106 if (err)
2107 goto out;
2108 err = qla1280_start_firmware(ha);
2109 out:
2110 return err;
2111 }
2112
2113 /*
2114 * Initialize rings
2115 *
2116 * Input:
2117 * ha = adapter block pointer.
2118 * ha->request_ring = request ring virtual address
2119 * ha->response_ring = response ring virtual address
2120 * ha->request_dma = request ring physical address
2121 * ha->response_dma = response ring physical address
2122 *
2123 * Returns:
2124 * 0 = success.
2125 */
2126 static int
2127 qla1280_init_rings(struct scsi_qla_host *ha)
2128 {
2129 uint16_t mb[MAILBOX_REGISTER_COUNT];
2130 int status = 0;
2131
2132 ENTER("qla1280_init_rings");
2133
2134 /* Clear outstanding commands array. */
2135 memset(ha->outstanding_cmds, 0,
2136 sizeof(struct srb *) * MAX_OUTSTANDING_COMMANDS);
2137
2138 /* Initialize request queue. */
2139 ha->request_ring_ptr = ha->request_ring;
2140 ha->req_ring_index = 0;
2141 ha->req_q_cnt = REQUEST_ENTRY_CNT;
2142 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
2143 mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
2144 mb[1] = REQUEST_ENTRY_CNT;
2145 mb[3] = ha->request_dma & 0xffff;
2146 mb[2] = (ha->request_dma >> 16) & 0xffff;
2147 mb[4] = 0;
2148 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2149 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2150 if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
2151 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2152 &mb[0]))) {
2153 /* Initialize response queue. */
2154 ha->response_ring_ptr = ha->response_ring;
2155 ha->rsp_ring_index = 0;
2156 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
2157 mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
2158 mb[1] = RESPONSE_ENTRY_CNT;
2159 mb[3] = ha->response_dma & 0xffff;
2160 mb[2] = (ha->response_dma >> 16) & 0xffff;
2161 mb[5] = 0;
2162 mb[7] = pci_dma_hi32(ha->response_dma) & 0xffff;
2163 mb[6] = pci_dma_hi32(ha->response_dma) >> 16;
2164 status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
2165 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2166 &mb[0]);
2167 }
2168
2169 if (status)
2170 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
2171
2172 LEAVE("qla1280_init_rings");
2173 return status;
2174 }
2175
2176 static void
2177 qla1280_print_settings(struct nvram *nv)
2178 {
2179 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
2180 nv->bus[0].config_1.initiator_id);
2181 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
2182 nv->bus[1].config_1.initiator_id);
2183
2184 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
2185 nv->bus[0].bus_reset_delay);
2186 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
2187 nv->bus[1].bus_reset_delay);
2188
2189 dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
2190 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
2191 dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
2192 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
2193
2194 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
2195 nv->bus[0].config_2.async_data_setup_time);
2196 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
2197 nv->bus[1].config_2.async_data_setup_time);
2198
2199 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
2200 nv->bus[0].config_2.req_ack_active_negation);
2201 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
2202 nv->bus[1].config_2.req_ack_active_negation);
2203
2204 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
2205 nv->bus[0].config_2.data_line_active_negation);
2206 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
2207 nv->bus[1].config_2.data_line_active_negation);
2208
2209 dprintk(1, "qla1280 : disable loading risc code=%d\n",
2210 nv->cntr_flags_1.disable_loading_risc_code);
2211
2212 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
2213 nv->cntr_flags_1.enable_64bit_addressing);
2214
2215 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
2216 nv->bus[0].selection_timeout);
2217 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
2218 nv->bus[1].selection_timeout);
2219
2220 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
2221 nv->bus[0].max_queue_depth);
2222 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
2223 nv->bus[1].max_queue_depth);
2224 }
2225
2226 static void
2227 qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target)
2228 {
2229 struct nvram *nv = &ha->nvram;
2230
2231 nv->bus[bus].target[target].parameter.f.renegotiate_on_error = 1;
2232 nv->bus[bus].target[target].parameter.f.auto_request_sense = 1;
2233 nv->bus[bus].target[target].parameter.f.tag_queuing = 1;
2234 nv->bus[bus].target[target].parameter.f.enable_sync = 1;
2235 #if 1 /* Some SCSI Processors do not seem to like this */
2236 nv->bus[bus].target[target].parameter.f.enable_wide = 1;
2237 #endif
2238 nv->bus[bus].target[target].parameter.f.parity_checking = 1;
2239 nv->bus[bus].target[target].parameter.f.disconnect_allowed = 1;
2240 nv->bus[bus].target[target].execution_throttle =
2241 nv->bus[bus].max_queue_depth - 1;
2242
2243 if (IS_ISP1x160(ha)) {
2244 nv->bus[bus].target[target].flags.flags1x160.device_enable = 1;
2245 nv->bus[bus].target[target].flags.flags1x160.sync_offset = 0x0e;
2246 nv->bus[bus].target[target].sync_period = 9;
2247 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
2248 nv->bus[bus].target[target].ppr_1x160.flags.ppr_options = 2;
2249 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width = 1;
2250 } else {
2251 nv->bus[bus].target[target].flags.flags1x80.device_enable = 1;
2252 nv->bus[bus].target[target].flags.flags1x80.sync_offset = 12;
2253 nv->bus[bus].target[target].sync_period = 10;
2254 }
2255 }
2256
2257 static void
2258 qla1280_set_defaults(struct scsi_qla_host *ha)
2259 {
2260 struct nvram *nv = &ha->nvram;
2261 int bus, target;
2262
2263 dprintk(1, "Using defaults for NVRAM: \n");
2264 memset(nv, 0, sizeof(struct nvram));
2265
2266 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
2267 nv->firmware_feature.f.enable_fast_posting = 1;
2268 nv->firmware_feature.f.disable_synchronous_backoff = 1;
2269 nv->termination.f.scsi_bus_0_control = 3;
2270 nv->termination.f.scsi_bus_1_control = 3;
2271 nv->termination.f.auto_term_support = 1;
2272
2273 /*
2274 * Set default FIFO magic - What appropriate values would be here
2275 * is unknown. This is what I have found testing with 12160s.
2276 *
2277 * Now, I would love the magic decoder ring for this one, the
2278 * header file provided by QLogic seems to be bogus or incomplete
2279 * at best.
2280 */
2281 nv->isp_config.c = ISP_CFG1_BENAB|ISP_CFG1_F128;
2282 if (IS_ISP1x160(ha))
2283 nv->isp_parameter = 0x01; /* fast memory enable */
2284
2285 for (bus = 0; bus < MAX_BUSES; bus++) {
2286 nv->bus[bus].config_1.initiator_id = 7;
2287 nv->bus[bus].config_2.req_ack_active_negation = 1;
2288 nv->bus[bus].config_2.data_line_active_negation = 1;
2289 nv->bus[bus].selection_timeout = 250;
2290 nv->bus[bus].max_queue_depth = 256;
2291
2292 if (IS_ISP1040(ha)) {
2293 nv->bus[bus].bus_reset_delay = 3;
2294 nv->bus[bus].config_2.async_data_setup_time = 6;
2295 nv->bus[bus].retry_delay = 1;
2296 } else {
2297 nv->bus[bus].bus_reset_delay = 5;
2298 nv->bus[bus].config_2.async_data_setup_time = 8;
2299 }
2300
2301 for (target = 0; target < MAX_TARGETS; target++)
2302 qla1280_set_target_defaults(ha, bus, target);
2303 }
2304 }
2305
2306 static int
2307 qla1280_config_target(struct scsi_qla_host *ha, int bus, int target)
2308 {
2309 struct nvram *nv = &ha->nvram;
2310 uint16_t mb[MAILBOX_REGISTER_COUNT];
2311 int status, lun;
2312
2313 /* Set Target Parameters. */
2314 mb[0] = MBC_SET_TARGET_PARAMETERS;
2315 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
2316 mb[1] <<= 8;
2317
2318 /*
2319 * Do not enable wide, sync, and ppr for the initial
2320 * INQUIRY run. We enable this later if we determine
2321 * the target actually supports it.
2322 */
2323 nv->bus[bus].target[target].parameter.f.
2324 auto_request_sense = 1;
2325 nv->bus[bus].target[target].parameter.f.
2326 stop_queue_on_check = 0;
2327
2328 if (IS_ISP1x160(ha))
2329 nv->bus[bus].target[target].ppr_1x160.
2330 flags.enable_ppr = 0;
2331
2332 /*
2333 * No sync, wide, etc. while probing
2334 */
2335 mb[2] = (nv->bus[bus].target[target].parameter.c << 8) &
2336 ~(TP_SYNC /*| TP_WIDE | TP_PPR*/);
2337
2338 if (IS_ISP1x160(ha))
2339 mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
2340 else
2341 mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
2342 mb[3] |= nv->bus[bus].target[target].sync_period;
2343
2344 status = qla1280_mailbox_command(ha, BIT_3 | BIT_2 | BIT_1 | BIT_0, &mb[0]);
2345
2346 /* Save Tag queuing enable flag. */
2347 mb[0] = BIT_0 << target;
2348 if (nv->bus[bus].target[target].parameter.f.tag_queuing)
2349 ha->bus_settings[bus].qtag_enables |= mb[0];
2350
2351 /* Save Device enable flag. */
2352 if (IS_ISP1x160(ha)) {
2353 if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
2354 ha->bus_settings[bus].device_enables |= mb[0];
2355 ha->bus_settings[bus].lun_disables |= 0;
2356 } else {
2357 if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
2358 ha->bus_settings[bus].device_enables |= mb[0];
2359 /* Save LUN disable flag. */
2360 if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
2361 ha->bus_settings[bus].lun_disables |= mb[0];
2362 }
2363
2364 /* Set Device Queue Parameters. */
2365 for (lun = 0; lun < MAX_LUNS; lun++) {
2366 mb[0] = MBC_SET_DEVICE_QUEUE;
2367 mb[1] = (uint16_t)(bus ? target | BIT_7 : target);
2368 mb[1] = mb[1] << 8 | lun;
2369 mb[2] = nv->bus[bus].max_queue_depth;
2370 mb[3] = nv->bus[bus].target[target].execution_throttle;
2371 status |= qla1280_mailbox_command(ha, 0x0f, &mb[0]);
2372 }
2373
2374 return status;
2375 }
2376
2377 static int
2378 qla1280_config_bus(struct scsi_qla_host *ha, int bus)
2379 {
2380 struct nvram *nv = &ha->nvram;
2381 uint16_t mb[MAILBOX_REGISTER_COUNT];
2382 int target, status;
2383
2384 /* SCSI Reset Disable. */
2385 ha->bus_settings[bus].disable_scsi_reset =
2386 nv->bus[bus].config_1.scsi_reset_disable;
2387
2388 /* Initiator ID. */
2389 ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
2390 mb[0] = MBC_SET_INITIATOR_ID;
2391 mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
2392 ha->bus_settings[bus].id;
2393 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2394
2395 /* Reset Delay. */
2396 ha->bus_settings[bus].bus_reset_delay =
2397 nv->bus[bus].bus_reset_delay;
2398
2399 /* Command queue depth per device. */
2400 ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
2401
2402 /* Set target parameters. */
2403 for (target = 0; target < MAX_TARGETS; target++)
2404 status |= qla1280_config_target(ha, bus, target);
2405
2406 return status;
2407 }
2408
2409 static int
2410 qla1280_nvram_config(struct scsi_qla_host *ha)
2411 {
2412 struct device_reg __iomem *reg = ha->iobase;
2413 struct nvram *nv = &ha->nvram;
2414 int bus, target, status = 0;
2415 uint16_t mb[MAILBOX_REGISTER_COUNT];
2416 uint16_t mask;
2417
2418 ENTER("qla1280_nvram_config");
2419
2420 if (ha->nvram_valid) {
2421 /* Always force AUTO sense for LINUX SCSI */
2422 for (bus = 0; bus < MAX_BUSES; bus++)
2423 for (target = 0; target < MAX_TARGETS; target++) {
2424 nv->bus[bus].target[target].parameter.f.
2425 auto_request_sense = 1;
2426 }
2427 } else {
2428 qla1280_set_defaults(ha);
2429 }
2430
2431 qla1280_print_settings(nv);
2432
2433 /* Disable RISC load of firmware. */
2434 ha->flags.disable_risc_code_load =
2435 nv->cntr_flags_1.disable_loading_risc_code;
2436
2437 if (IS_ISP1040(ha)) {
2438 uint16_t hwrev, cfg1, cdma_conf, ddma_conf;
2439
2440 hwrev = RD_REG_WORD(&reg->cfg_0) & ISP_CFG0_HWMSK;
2441
2442 cfg1 = RD_REG_WORD(&reg->cfg_1);
2443 cdma_conf = RD_REG_WORD(&reg->cdma_cfg);
2444 ddma_conf = RD_REG_WORD(&reg->ddma_cfg);
2445
2446 /* Busted fifo, says mjacob. */
2447 if (hwrev == ISP_CFG0_1040A)
2448 WRT_REG_WORD(&reg->cfg_1, cfg1 | ISP_CFG1_F64);
2449 else
2450 WRT_REG_WORD(&reg->cfg_1, cfg1 | ISP_CFG1_F64 | ISP_CFG1_BENAB);
2451
2452 WRT_REG_WORD(&reg->cdma_cfg, cdma_conf | CDMA_CONF_BENAB);
2453 WRT_REG_WORD(&reg->ddma_cfg, cdma_conf | DDMA_CONF_BENAB);
2454 } else {
2455 /* Set ISP hardware DMA burst */
2456 mb[0] = nv->isp_config.c;
2457 /* Enable DMA arbitration on dual channel controllers */
2458 if (ha->ports > 1)
2459 mb[0] |= BIT_13;
2460 WRT_REG_WORD(&reg->cfg_1, mb[0]);
2461
2462 /* Set SCSI termination. */
2463 WRT_REG_WORD(&reg->gpio_enable, (BIT_3 + BIT_2 + BIT_1 + BIT_0));
2464 mb[0] = nv->termination.c & (BIT_3 + BIT_2 + BIT_1 + BIT_0);
2465 WRT_REG_WORD(&reg->gpio_data, mb[0]);
2466 }
2467
2468 /* ISP parameter word. */
2469 mb[0] = MBC_SET_SYSTEM_PARAMETER;
2470 mb[1] = nv->isp_parameter;
2471 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2472
2473 if (IS_ISP1x40(ha)) {
2474 /* clock rate - for qla1240 and older, only */
2475 mb[0] = MBC_SET_CLOCK_RATE;
2476 mb[1] = 40;
2477 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2478 }
2479
2480 /* Firmware feature word. */
2481 mb[0] = MBC_SET_FIRMWARE_FEATURES;
2482 mask = BIT_5 | BIT_1 | BIT_0;
2483 mb[1] = le16_to_cpu(nv->firmware_feature.w) & (mask);
2484 #if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
2485 if (ia64_platform_is("sn2")) {
2486 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
2487 "workaround\n", ha->host_no);
2488 mb[1] |= BIT_9;
2489 }
2490 #endif
2491 status |= qla1280_mailbox_command(ha, mask, &mb[0]);
2492
2493 /* Retry count and delay. */
2494 mb[0] = MBC_SET_RETRY_COUNT;
2495 mb[1] = nv->bus[0].retry_count;
2496 mb[2] = nv->bus[0].retry_delay;
2497 mb[6] = nv->bus[1].retry_count;
2498 mb[7] = nv->bus[1].retry_delay;
2499 status |= qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 |
2500 BIT_1 | BIT_0, &mb[0]);
2501
2502 /* ASYNC data setup time. */
2503 mb[0] = MBC_SET_ASYNC_DATA_SETUP;
2504 mb[1] = nv->bus[0].config_2.async_data_setup_time;
2505 mb[2] = nv->bus[1].config_2.async_data_setup_time;
2506 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2507
2508 /* Active negation states. */
2509 mb[0] = MBC_SET_ACTIVE_NEGATION;
2510 mb[1] = 0;
2511 if (nv->bus[0].config_2.req_ack_active_negation)
2512 mb[1] |= BIT_5;
2513 if (nv->bus[0].config_2.data_line_active_negation)
2514 mb[1] |= BIT_4;
2515 mb[2] = 0;
2516 if (nv->bus[1].config_2.req_ack_active_negation)
2517 mb[2] |= BIT_5;
2518 if (nv->bus[1].config_2.data_line_active_negation)
2519 mb[2] |= BIT_4;
2520 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2521
2522 mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
2523 mb[1] = 2; /* Reset SCSI bus and return all outstanding IO */
2524 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2525
2526 /* thingy */
2527 mb[0] = MBC_SET_PCI_CONTROL;
2528 mb[1] = 2; /* Data DMA Channel Burst Enable */
2529 mb[2] = 2; /* Command DMA Channel Burst Enable */
2530 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2531
2532 mb[0] = MBC_SET_TAG_AGE_LIMIT;
2533 mb[1] = 8;
2534 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2535
2536 /* Selection timeout. */
2537 mb[0] = MBC_SET_SELECTION_TIMEOUT;
2538 mb[1] = nv->bus[0].selection_timeout;
2539 mb[2] = nv->bus[1].selection_timeout;
2540 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2541
2542 for (bus = 0; bus < ha->ports; bus++)
2543 status |= qla1280_config_bus(ha, bus);
2544
2545 if (status)
2546 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
2547
2548 LEAVE("qla1280_nvram_config");
2549 return status;
2550 }
2551
2552 /*
2553 * Get NVRAM data word
2554 * Calculates word position in NVRAM and calls request routine to
2555 * get the word from NVRAM.
2556 *
2557 * Input:
2558 * ha = adapter block pointer.
2559 * address = NVRAM word address.
2560 *
2561 * Returns:
2562 * data word.
2563 */
2564 static uint16_t
2565 qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
2566 {
2567 uint32_t nv_cmd;
2568 uint16_t data;
2569
2570 nv_cmd = address << 16;
2571 nv_cmd |= NV_READ_OP;
2572
2573 data = le16_to_cpu(qla1280_nvram_request(ha, nv_cmd));
2574
2575 dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
2576 "0x%x", data);
2577
2578 return data;
2579 }
2580
2581 /*
2582 * NVRAM request
2583 * Sends read command to NVRAM and gets data from NVRAM.
2584 *
2585 * Input:
2586 * ha = adapter block pointer.
2587 * nv_cmd = Bit 26 = start bit
2588 * Bit 25, 24 = opcode
2589 * Bit 23-16 = address
2590 * Bit 15-0 = write data
2591 *
2592 * Returns:
2593 * data word.
2594 */
2595 static uint16_t
2596 qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
2597 {
2598 struct device_reg __iomem *reg = ha->iobase;
2599 int cnt;
2600 uint16_t data = 0;
2601 uint16_t reg_data;
2602
2603 /* Send command to NVRAM. */
2604
2605 nv_cmd <<= 5;
2606 for (cnt = 0; cnt < 11; cnt++) {
2607 if (nv_cmd & BIT_31)
2608 qla1280_nv_write(ha, NV_DATA_OUT);
2609 else
2610 qla1280_nv_write(ha, 0);
2611 nv_cmd <<= 1;
2612 }
2613
2614 /* Read data from NVRAM. */
2615
2616 for (cnt = 0; cnt < 16; cnt++) {
2617 WRT_REG_WORD(&reg->nvram, (NV_SELECT | NV_CLOCK));
2618 RD_REG_WORD(&reg->id_l); /* Flush PCI write */
2619 NVRAM_DELAY();
2620 data <<= 1;
2621 reg_data = RD_REG_WORD(&reg->nvram);
2622 if (reg_data & NV_DATA_IN)
2623 data |= BIT_0;
2624 WRT_REG_WORD(&reg->nvram, NV_SELECT);
2625 RD_REG_WORD(&reg->id_l); /* Flush PCI write */
2626 NVRAM_DELAY();
2627 }
2628
2629 /* Deselect chip. */
2630
2631 WRT_REG_WORD(&reg->nvram, NV_DESELECT);
2632 RD_REG_WORD(&reg->id_l); /* Flush PCI write */
2633 NVRAM_DELAY();
2634
2635 return data;
2636 }
2637
2638 static void
2639 qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
2640 {
2641 struct device_reg __iomem *reg = ha->iobase;
2642
2643 WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
2644 RD_REG_WORD(&reg->id_l); /* Flush PCI write */
2645 NVRAM_DELAY();
2646 WRT_REG_WORD(&reg->nvram, data | NV_SELECT | NV_CLOCK);
2647 RD_REG_WORD(&reg->id_l); /* Flush PCI write */
2648 NVRAM_DELAY();
2649 WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
2650 RD_REG_WORD(&reg->id_l); /* Flush PCI write */
2651 NVRAM_DELAY();
2652 }
2653
2654 /*
2655 * Mailbox Command
2656 * Issue mailbox command and waits for completion.
2657 *
2658 * Input:
2659 * ha = adapter block pointer.
2660 * mr = mailbox registers to load.
2661 * mb = data pointer for mailbox registers.
2662 *
2663 * Output:
2664 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
2665 *
2666 * Returns:
2667 * 0 = success
2668 */
2669 static int
2670 qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
2671 {
2672 struct device_reg __iomem *reg = ha->iobase;
2673 #if 0
2674 LIST_HEAD(done_q);
2675 #endif
2676 int status = 0;
2677 int cnt;
2678 uint16_t *optr, *iptr;
2679 uint16_t __iomem *mptr;
2680 uint16_t data;
2681 DECLARE_COMPLETION(wait);
2682 struct timer_list timer;
2683
2684 ENTER("qla1280_mailbox_command");
2685
2686 if (ha->mailbox_wait) {
2687 printk(KERN_ERR "Warning mailbox wait already in use!\n");
2688 }
2689 ha->mailbox_wait = &wait;
2690
2691 /*
2692 * We really should start out by verifying that the mailbox is
2693 * available before starting sending the command data
2694 */
2695 /* Load mailbox registers. */
2696 mptr = (uint16_t __iomem *) &reg->mailbox0;
2697 iptr = mb;
2698 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
2699 if (mr & BIT_0) {
2700 WRT_REG_WORD(mptr, (*iptr));
2701 }
2702
2703 mr >>= 1;
2704 mptr++;
2705 iptr++;
2706 }
2707
2708 /* Issue set host interrupt command. */
2709
2710 /* set up a timer just in case we're really jammed */
2711 init_timer(&timer);
2712 timer.expires = jiffies + 20*HZ;
2713 timer.data = (unsigned long)ha;
2714 timer.function = qla1280_mailbox_timeout;
2715 add_timer(&timer);
2716
2717 spin_unlock_irq(HOST_LOCK);
2718 WRT_REG_WORD(&reg->host_cmd, HC_SET_HOST_INT);
2719 data = qla1280_debounce_register(&reg->istatus);
2720
2721 wait_for_completion(&wait);
2722 del_timer_sync(&timer);
2723
2724 spin_lock_irq(HOST_LOCK);
2725
2726 ha->mailbox_wait = NULL;
2727
2728 /* Check for mailbox command timeout. */
2729 if (ha->mailbox_out[0] != MBS_CMD_CMP) {
2730 printk(KERN_WARNING "qla1280_mailbox_command: Command failed, "
2731 "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
2732 "0x%04x\n",
2733 mb[0], ha->mailbox_out[0], RD_REG_WORD(&reg->istatus));
2734 printk(KERN_WARNING "m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
2735 RD_REG_WORD(&reg->mailbox0), RD_REG_WORD(&reg->mailbox1),
2736 RD_REG_WORD(&reg->mailbox2), RD_REG_WORD(&reg->mailbox3));
2737 printk(KERN_WARNING "m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
2738 RD_REG_WORD(&reg->mailbox4), RD_REG_WORD(&reg->mailbox5),
2739 RD_REG_WORD(&reg->mailbox6), RD_REG_WORD(&reg->mailbox7));
2740 status = 1;
2741 }
2742
2743 /* Load return mailbox registers. */
2744 optr = mb;
2745 iptr = (uint16_t *) &ha->mailbox_out[0];
2746 mr = MAILBOX_REGISTER_COUNT;
2747 memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
2748
2749 #if 0
2750 /* Go check for any response interrupts pending. */
2751 qla1280_isr(ha, &done_q);
2752 #endif
2753
2754 if (ha->flags.reset_marker)
2755 qla1280_rst_aen(ha);
2756
2757 #if 0
2758 if (!list_empty(&done_q))
2759 qla1280_done(ha, &done_q);
2760 #endif
2761
2762 if (status)
2763 dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
2764 "0x%x ****\n", mb[0]);
2765
2766 LEAVE("qla1280_mailbox_command");
2767 return status;
2768 }
2769
2770 /*
2771 * qla1280_poll
2772 * Polls ISP for interrupts.
2773 *
2774 * Input:
2775 * ha = adapter block pointer.
2776 */
2777 static void
2778 qla1280_poll(struct scsi_qla_host *ha)
2779 {
2780 struct device_reg __iomem *reg = ha->iobase;
2781 uint16_t data;
2782 LIST_HEAD(done_q);
2783
2784 /* ENTER("qla1280_poll"); */
2785
2786 /* Check for pending interrupts. */
2787 data = RD_REG_WORD(&reg->istatus);
2788 if (data & RISC_INT)
2789 qla1280_isr(ha, &done_q);
2790
2791 if (!ha->mailbox_wait) {
2792 if (ha->flags.reset_marker)
2793 qla1280_rst_aen(ha);
2794 }
2795
2796 if (!list_empty(&done_q))
2797 qla1280_done(ha);
2798
2799 /* LEAVE("qla1280_poll"); */
2800 }
2801
2802 /*
2803 * qla1280_bus_reset
2804 * Issue SCSI bus reset.
2805 *
2806 * Input:
2807 * ha = adapter block pointer.
2808 * bus = SCSI bus number.
2809 *
2810 * Returns:
2811 * 0 = success
2812 */
2813 static int
2814 qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
2815 {
2816 uint16_t mb[MAILBOX_REGISTER_COUNT];
2817 uint16_t reset_delay;
2818 int status;
2819
2820 dprintk(3, "qla1280_bus_reset: entered\n");
2821
2822 if (qla1280_verbose)
2823 printk(KERN_INFO "scsi(%li:%i): Resetting SCSI BUS\n",
2824 ha->host_no, bus);
2825
2826 reset_delay = ha->bus_settings[bus].bus_reset_delay;
2827 mb[0] = MBC_BUS_RESET;
2828 mb[1] = reset_delay;
2829 mb[2] = (uint16_t) bus;
2830 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2831
2832 if (status) {
2833 if (ha->bus_settings[bus].failed_reset_count > 2)
2834 ha->bus_settings[bus].scsi_bus_dead = 1;
2835 ha->bus_settings[bus].failed_reset_count++;
2836 } else {
2837 spin_unlock_irq(HOST_LOCK);
2838 schedule_timeout(reset_delay * HZ);
2839 spin_lock_irq(HOST_LOCK);
2840
2841 ha->bus_settings[bus].scsi_bus_dead = 0;
2842 ha->bus_settings[bus].failed_reset_count = 0;
2843 ha->bus_settings[bus].reset_marker = 0;
2844 /* Issue marker command. */
2845 qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
2846 }
2847
2848 /*
2849 * We should probably call qla1280_set_target_parameters()
2850 * here as well for all devices on the bus.
2851 */
2852
2853 if (status)
2854 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
2855 else
2856 dprintk(3, "qla1280_bus_reset: exiting normally\n");
2857
2858 return status;
2859 }
2860
2861 /*
2862 * qla1280_device_reset
2863 * Issue bus device reset message to the target.
2864 *
2865 * Input:
2866 * ha = adapter block pointer.
2867 * bus = SCSI BUS number.
2868 * target = SCSI ID.
2869 *
2870 * Returns:
2871 * 0 = success
2872 */
2873 static int
2874 qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
2875 {
2876 uint16_t mb[MAILBOX_REGISTER_COUNT];
2877 int status;
2878
2879 ENTER("qla1280_device_reset");
2880
2881 mb[0] = MBC_ABORT_TARGET;
2882 mb[1] = (bus ? (target | BIT_7) : target) << 8;
2883 mb[2] = 1;
2884 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2885
2886 /* Issue marker command. */
2887 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
2888
2889 if (status)
2890 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
2891
2892 LEAVE("qla1280_device_reset");
2893 return status;
2894 }
2895
2896 /*
2897 * qla1280_abort_device
2898 * Issue an abort message to the device
2899 *
2900 * Input:
2901 * ha = adapter block pointer.
2902 * bus = SCSI BUS.
2903 * target = SCSI ID.
2904 * lun = SCSI LUN.
2905 *
2906 * Returns:
2907 * 0 = success
2908 */
2909 static int
2910 qla1280_abort_device(struct scsi_qla_host *ha, int bus, int target, int lun)
2911 {
2912 uint16_t mb[MAILBOX_REGISTER_COUNT];
2913 int status;
2914
2915 ENTER("qla1280_abort_device");
2916
2917 mb[0] = MBC_ABORT_DEVICE;
2918 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
2919 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2920
2921 /* Issue marker command. */
2922 qla1280_marker(ha, bus, target, lun, MK_SYNC_ID_LUN);
2923
2924 if (status)
2925 dprintk(2, "qla1280_abort_device: **** FAILED ****\n");
2926
2927 LEAVE("qla1280_abort_device");
2928 return status;
2929 }
2930
2931 /*
2932 * qla1280_abort_command
2933 * Abort command aborts a specified IOCB.
2934 *
2935 * Input:
2936 * ha = adapter block pointer.
2937 * sp = SB structure pointer.
2938 *
2939 * Returns:
2940 * 0 = success
2941 */
2942 static int
2943 qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
2944 {
2945 uint16_t mb[MAILBOX_REGISTER_COUNT];
2946 unsigned int bus, target, lun;
2947 int status;
2948
2949 ENTER("qla1280_abort_command");
2950
2951 bus = SCSI_BUS_32(sp->cmd);
2952 target = SCSI_TCN_32(sp->cmd);
2953 lun = SCSI_LUN_32(sp->cmd);
2954
2955 sp->flags |= SRB_ABORT_PENDING;
2956
2957 mb[0] = MBC_ABORT_COMMAND;
2958 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
2959 mb[2] = handle >> 16;
2960 mb[3] = handle & 0xffff;
2961 status = qla1280_mailbox_command(ha, 0x0f, &mb[0]);
2962
2963 if (status) {
2964 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
2965 sp->flags &= ~SRB_ABORT_PENDING;
2966 }
2967
2968
2969 LEAVE("qla1280_abort_command");
2970 return status;
2971 }
2972
2973 /*
2974 * qla1280_reset_adapter
2975 * Reset adapter.
2976 *
2977 * Input:
2978 * ha = adapter block pointer.
2979 */
2980 static void
2981 qla1280_reset_adapter(struct scsi_qla_host *ha)
2982 {
2983 struct device_reg __iomem *reg = ha->iobase;
2984
2985 ENTER("qla1280_reset_adapter");
2986
2987 /* Disable ISP chip */
2988 ha->flags.online = 0;
2989 WRT_REG_WORD(&reg->ictrl, ISP_RESET);
2990 WRT_REG_WORD(&reg->host_cmd,
2991 HC_RESET_RISC | HC_RELEASE_RISC | HC_DISABLE_BIOS);
2992 RD_REG_WORD(&reg->id_l); /* Flush PCI write */
2993
2994 LEAVE("qla1280_reset_adapter");
2995 }
2996
2997 /*
2998 * Issue marker command.
2999 * Function issues marker IOCB.
3000 *
3001 * Input:
3002 * ha = adapter block pointer.
3003 * bus = SCSI BUS number
3004 * id = SCSI ID
3005 * lun = SCSI LUN
3006 * type = marker modifier
3007 */
3008 static void
3009 qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
3010 {
3011 struct mrk_entry *pkt;
3012
3013 ENTER("qla1280_marker");
3014
3015 /* Get request packet. */
3016 if ((pkt = (struct mrk_entry *) qla1280_req_pkt(ha))) {
3017 pkt->entry_type = MARKER_TYPE;
3018 pkt->lun = (uint8_t) lun;
3019 pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
3020 pkt->modifier = type;
3021 pkt->entry_status = 0;
3022
3023 /* Issue command to ISP */
3024 qla1280_isp_cmd(ha);
3025 }
3026
3027 LEAVE("qla1280_marker");
3028 }
3029
3030
3031 /*
3032 * qla1280_64bit_start_scsi
3033 * The start SCSI is responsible for building request packets on
3034 * request ring and modifying ISP input pointer.
3035 *
3036 * Input:
3037 * ha = adapter block pointer.
3038 * sp = SB structure pointer.
3039 *
3040 * Returns:
3041 * 0 = success, was able to issue command.
3042 */
3043 #ifdef QLA_64BIT_PTR
3044 static int
3045 qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3046 {
3047 struct device_reg __iomem *reg = ha->iobase;
3048 struct scsi_cmnd *cmd = sp->cmd;
3049 cmd_a64_entry_t *pkt;
3050 struct scatterlist *sg = NULL;
3051 u32 *dword_ptr;
3052 dma_addr_t dma_handle;
3053 int status = 0;
3054 int cnt;
3055 int req_cnt;
3056 u16 seg_cnt;
3057 u8 dir;
3058
3059 ENTER("qla1280_64bit_start_scsi:");
3060
3061 /* Calculate number of entries and segments required. */
3062 req_cnt = 1;
3063 if (cmd->use_sg) {
3064 sg = (struct scatterlist *) cmd->request_buffer;
3065 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3066 cmd->sc_data_direction);
3067
3068 if (seg_cnt > 2) {
3069 req_cnt += (seg_cnt - 2) / 5;
3070 if ((seg_cnt - 2) % 5)
3071 req_cnt++;
3072 }
3073 } else if (cmd->request_bufflen) { /* If data transfer. */
3074 seg_cnt = 1;
3075 } else {
3076 seg_cnt = 0;
3077 }
3078
3079 if ((req_cnt + 2) >= ha->req_q_cnt) {
3080 /* Calculate number of free request entries. */
3081 cnt = RD_REG_WORD(&reg->mailbox4);
3082 if (ha->req_ring_index < cnt)
3083 ha->req_q_cnt = cnt - ha->req_ring_index;
3084 else
3085 ha->req_q_cnt =
3086 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3087 }
3088
3089 /* If room for request in request ring. */
3090 if ((req_cnt + 2) >= ha->req_q_cnt) {
3091 status = 1;
3092 dprintk(2, "qla1280_64bit_start_scsi: in-ptr=0x%x req_q_cnt="
3093 "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
3094 req_cnt);
3095 goto out;
3096 }
3097
3098 /* Check for room in outstanding command list. */
3099 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3100 ha->outstanding_cmds[cnt] != 0; cnt++);
3101
3102 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3103 status = 1;
3104 dprintk(2, "qla1280_64bit_start_scsi: NO ROOM IN "
3105 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
3106 goto out;
3107 }
3108
3109 ha->outstanding_cmds[cnt] = sp;
3110 ha->req_q_cnt -= req_cnt;
3111 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
3112
3113 dprintk(2, "64bit_start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
3114 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
3115 dprintk(2, " bus %i, target %i, lun %i\n",
3116 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3117 qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
3118
3119 /*
3120 * Build command packet.
3121 */
3122 pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
3123
3124 pkt->entry_type = COMMAND_A64_TYPE;
3125 pkt->entry_count = (uint8_t) req_cnt;
3126 pkt->sys_define = (uint8_t) ha->req_ring_index;
3127 pkt->entry_status = 0;
3128 pkt->handle = cpu_to_le32(cnt);
3129
3130 /* Zero out remaining portion of packet. */
3131 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3132
3133 /* Set ISP command timeout. */
3134 pkt->timeout = cpu_to_le16(30);
3135
3136 /* Set device target ID and LUN */
3137 pkt->lun = SCSI_LUN_32(cmd);
3138 pkt->target = SCSI_BUS_32(cmd) ?
3139 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3140
3141 /* Enable simple tag queuing if device supports it. */
3142 if (DEV_SIMPLE_TAGS(cmd->device))
3143 pkt->control_flags |= cpu_to_le16(BIT_3);
3144
3145 /* Load SCSI command packet. */
3146 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3147 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3148 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3149
3150 /* Set transfer direction. */
3151 dir = qla1280_data_direction(cmd);
3152 pkt->control_flags |= cpu_to_le16(dir);
3153
3154 /* Set total data segment count. */
3155 pkt->dseg_count = cpu_to_le16(seg_cnt);
3156
3157 /*
3158 * Load data segments.
3159 */
3160 if (seg_cnt) { /* If data transfer. */
3161 /* Setup packet address segment pointer. */
3162 dword_ptr = (u32 *)&pkt->dseg_0_address;
3163
3164 if (cmd->use_sg) { /* If scatter gather */
3165 /* Load command entry data segments. */
3166 for (cnt = 0; cnt < 2 && seg_cnt; cnt++, seg_cnt--) {
3167 dma_handle = sg_dma_address(sg);
3168 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3169 if (ha->flags.use_pci_vchannel)
3170 sn_pci_set_vchan(ha->pdev,
3171 (unsigned long *)&dma_handle,
3172 SCSI_BUS_32(cmd));
3173 #endif
3174 *dword_ptr++ =
3175 cpu_to_le32(pci_dma_lo32(dma_handle));
3176 *dword_ptr++ =
3177 cpu_to_le32(pci_dma_hi32(dma_handle));
3178 *dword_ptr++ = cpu_to_le32(sg_dma_len(sg));
3179 sg++;
3180 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
3181 cpu_to_le32(pci_dma_hi32(dma_handle)),
3182 cpu_to_le32(pci_dma_lo32(dma_handle)),
3183 cpu_to_le32(sg_dma_len(sg)));
3184 }
3185 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
3186 "command packet data - b %i, t %i, l %i \n",
3187 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3188 SCSI_LUN_32(cmd));
3189 qla1280_dump_buffer(5, (char *)pkt,
3190 REQUEST_ENTRY_SIZE);
3191
3192 /*
3193 * Build continuation packets.
3194 */
3195 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
3196 "remains\n", seg_cnt);
3197
3198 while (seg_cnt > 0) {
3199 /* Adjust ring index. */
3200 ha->req_ring_index++;
3201 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3202 ha->req_ring_index = 0;
3203 ha->request_ring_ptr =
3204 ha->request_ring;
3205 } else
3206 ha->request_ring_ptr++;
3207
3208 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
3209
3210 /* Zero out packet. */
3211 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3212
3213 /* Load packet defaults. */
3214 ((struct cont_a64_entry *) pkt)->entry_type =
3215 CONTINUE_A64_TYPE;
3216 ((struct cont_a64_entry *) pkt)->entry_count = 1;
3217 ((struct cont_a64_entry *) pkt)->sys_define =
3218 (uint8_t)ha->req_ring_index;
3219 /* Setup packet address segment pointer. */
3220 dword_ptr =
3221 (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
3222
3223 /* Load continuation entry data segments. */
3224 for (cnt = 0; cnt < 5 && seg_cnt;
3225 cnt++, seg_cnt--) {
3226 dma_handle = sg_dma_address(sg);
3227 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3228 if (ha->flags.use_pci_vchannel)
3229 sn_pci_set_vchan(ha->pdev,
3230 (unsigned long *)&dma_handle,
3231 SCSI_BUS_32(cmd));
3232 #endif
3233 *dword_ptr++ =
3234 cpu_to_le32(pci_dma_lo32(dma_handle));
3235 *dword_ptr++ =
3236 cpu_to_le32(pci_dma_hi32(dma_handle));
3237 *dword_ptr++ =
3238 cpu_to_le32(sg_dma_len(sg));
3239 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
3240 cpu_to_le32(pci_dma_hi32(dma_handle)),
3241 cpu_to_le32(pci_dma_lo32(dma_handle)),
3242 cpu_to_le32(sg_dma_len(sg)));
3243 sg++;
3244 }
3245 dprintk(5, "qla1280_64bit_start_scsi: "
3246 "continuation packet data - b %i, t "
3247 "%i, l %i \n", SCSI_BUS_32(cmd),
3248 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3249 qla1280_dump_buffer(5, (char *)pkt,
3250 REQUEST_ENTRY_SIZE);
3251 }
3252 } else { /* No scatter gather data transfer */
3253 dma_handle = pci_map_single(ha->pdev,
3254 cmd->request_buffer,
3255 cmd->request_bufflen,
3256 cmd->sc_data_direction);
3257
3258 sp->saved_dma_handle = dma_handle;
3259 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3260 if (ha->flags.use_pci_vchannel)
3261 sn_pci_set_vchan(ha->pdev,
3262 (unsigned long *)&dma_handle,
3263 SCSI_BUS_32(cmd));
3264 #endif
3265 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3266 *dword_ptr++ = cpu_to_le32(pci_dma_hi32(dma_handle));
3267 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3268
3269 dprintk(5, "qla1280_64bit_start_scsi: No scatter/"
3270 "gather command packet data - b %i, t %i, "
3271 "l %i \n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3272 SCSI_LUN_32(cmd));
3273 qla1280_dump_buffer(5, (char *)pkt,
3274 REQUEST_ENTRY_SIZE);
3275 }
3276 } else { /* No data transfer */
3277 dprintk(5, "qla1280_64bit_start_scsi: No data, command "
3278 "packet data - b %i, t %i, l %i \n",
3279 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3280 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3281 }
3282 /* Adjust ring index. */
3283 ha->req_ring_index++;
3284 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3285 ha->req_ring_index = 0;
3286 ha->request_ring_ptr = ha->request_ring;
3287 } else
3288 ha->request_ring_ptr++;
3289
3290 /* Set chip new ring index. */
3291 dprintk(2,
3292 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
3293 sp->flags |= SRB_SENT;
3294 ha->actthreads++;
3295 WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
3296 /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
3297 mmiowb();
3298
3299 out:
3300 if (status)
3301 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
3302 else
3303 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
3304
3305 return status;
3306 }
3307 #else /* !QLA_64BIT_PTR */
3308
3309 /*
3310 * qla1280_32bit_start_scsi
3311 * The start SCSI is responsible for building request packets on
3312 * request ring and modifying ISP input pointer.
3313 *
3314 * The Qlogic firmware interface allows every queue slot to have a SCSI
3315 * command and up to 4 scatter/gather (SG) entries. If we need more
3316 * than 4 SG entries, then continuation entries are used that can
3317 * hold another 7 entries each. The start routine determines if there
3318 * is eought empty slots then build the combination of requests to
3319 * fulfill the OS request.
3320 *
3321 * Input:
3322 * ha = adapter block pointer.
3323 * sp = SCSI Request Block structure pointer.
3324 *
3325 * Returns:
3326 * 0 = success, was able to issue command.
3327 */
3328 static int
3329 qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3330 {
3331 struct device_reg __iomem *reg = ha->iobase;
3332 struct scsi_cmnd *cmd = sp->cmd;
3333 struct cmd_entry *pkt;
3334 struct scatterlist *sg = NULL;
3335 uint32_t *dword_ptr;
3336 int status = 0;
3337 int cnt;
3338 int req_cnt;
3339 uint16_t seg_cnt;
3340 dma_addr_t dma_handle;
3341 u8 dir;
3342
3343 ENTER("qla1280_32bit_start_scsi");
3344
3345 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
3346 cmd->cmnd[0]);
3347
3348 /* Calculate number of entries and segments required. */
3349 req_cnt = 1;
3350 if (cmd->use_sg) {
3351 /*
3352 * We must build an SG list in adapter format, as the kernel's
3353 * SG list cannot be used directly because of data field size
3354 * (__alpha__) differences and the kernel SG list uses virtual
3355 * addresses where we need physical addresses.
3356 */
3357 sg = (struct scatterlist *) cmd->request_buffer;
3358 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3359 cmd->sc_data_direction);
3360
3361 /*
3362 * if greater than four sg entries then we need to allocate
3363 * continuation entries
3364 */
3365 if (seg_cnt > 4) {
3366 req_cnt += (seg_cnt - 4) / 7;
3367 if ((seg_cnt - 4) % 7)
3368 req_cnt++;
3369 }
3370 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3371 cmd, seg_cnt, req_cnt);
3372 } else if (cmd->request_bufflen) { /* If data transfer. */
3373 dprintk(3, "No S/G transfer t=%x cmd=%p len=%x CDB=%x\n",
3374 SCSI_TCN_32(cmd), cmd, cmd->request_bufflen,
3375 cmd->cmnd[0]);
3376 seg_cnt = 1;
3377 } else {
3378 /* dprintk(1, "No data transfer \n"); */
3379 seg_cnt = 0;
3380 }
3381
3382 if ((req_cnt + 2) >= ha->req_q_cnt) {
3383 /* Calculate number of free request entries. */
3384 cnt = RD_REG_WORD(&reg->mailbox4);
3385 if (ha->req_ring_index < cnt)
3386 ha->req_q_cnt = cnt - ha->req_ring_index;
3387 else
3388 ha->req_q_cnt =
3389 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3390 }
3391
3392 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3393 ha->req_q_cnt, seg_cnt);
3394 /* If room for request in request ring. */
3395 if ((req_cnt + 2) >= ha->req_q_cnt) {
3396 status = 1;
3397 dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
3398 "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
3399 ha->req_q_cnt, req_cnt);
3400 goto out;
3401 }
3402
3403 /* Check for empty slot in outstanding command list. */
3404 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3405 (ha->outstanding_cmds[cnt] != 0); cnt++) ;
3406
3407 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3408 status = 1;
3409 dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
3410 "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
3411 goto out;
3412 }
3413
3414 CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
3415 ha->outstanding_cmds[cnt] = sp;
3416 ha->req_q_cnt -= req_cnt;
3417
3418 /*
3419 * Build command packet.
3420 */
3421 pkt = (struct cmd_entry *) ha->request_ring_ptr;
3422
3423 pkt->entry_type = COMMAND_TYPE;
3424 pkt->entry_count = (uint8_t) req_cnt;
3425 pkt->sys_define = (uint8_t) ha->req_ring_index;
3426 pkt->entry_status = 0;
3427 pkt->handle = cpu_to_le32(cnt);
3428
3429 /* Zero out remaining portion of packet. */
3430 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3431
3432 /* Set ISP command timeout. */
3433 pkt->timeout = cpu_to_le16(30);
3434
3435 /* Set device target ID and LUN */
3436 pkt->lun = SCSI_LUN_32(cmd);
3437 pkt->target = SCSI_BUS_32(cmd) ?
3438 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3439
3440 /* Enable simple tag queuing if device supports it. */
3441 if (DEV_SIMPLE_TAGS(cmd->device))
3442 pkt->control_flags |= cpu_to_le16(BIT_3);
3443
3444 /* Load SCSI command packet. */
3445 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3446 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd));
3447
3448 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3449 /* Set transfer direction. */
3450 dir = qla1280_data_direction(cmd);
3451 pkt->control_flags |= cpu_to_le16(dir);
3452
3453 /* Set total data segment count. */
3454 pkt->dseg_count = cpu_to_le16(seg_cnt);
3455
3456 /*
3457 * Load data segments.
3458 */
3459 if (seg_cnt) {
3460 /* Setup packet address segment pointer. */
3461 dword_ptr = &pkt->dseg_0_address;
3462
3463 if (cmd->use_sg) { /* If scatter gather */
3464 dprintk(3, "Building S/G data segments..\n");
3465 qla1280_dump_buffer(1, (char *)sg, 4 * 16);
3466
3467 /* Load command entry data segments. */
3468 for (cnt = 0; cnt < 4 && seg_cnt; cnt++, seg_cnt--) {
3469 *dword_ptr++ =
3470 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3471 *dword_ptr++ =
3472 cpu_to_le32(sg_dma_len(sg));
3473 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3474 (pci_dma_lo32(sg_dma_address(sg))),
3475 (sg_dma_len(sg)));
3476 sg++;
3477 }
3478 /*
3479 * Build continuation packets.
3480 */
3481 dprintk(3, "S/G Building Continuation"
3482 "...seg_cnt=0x%x remains\n", seg_cnt);
3483 while (seg_cnt > 0) {
3484 /* Adjust ring index. */
3485 ha->req_ring_index++;
3486 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3487 ha->req_ring_index = 0;
3488 ha->request_ring_ptr =
3489 ha->request_ring;
3490 } else
3491 ha->request_ring_ptr++;
3492
3493 pkt = (struct cmd_entry *)ha->request_ring_ptr;
3494
3495 /* Zero out packet. */
3496 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3497
3498 /* Load packet defaults. */
3499 ((struct cont_entry *) pkt)->
3500 entry_type = CONTINUE_TYPE;
3501 ((struct cont_entry *) pkt)->entry_count = 1;
3502
3503 ((struct cont_entry *) pkt)->sys_define =
3504 (uint8_t) ha->req_ring_index;
3505
3506 /* Setup packet address segment pointer. */
3507 dword_ptr =
3508 &((struct cont_entry *) pkt)->dseg_0_address;
3509
3510 /* Load continuation entry data segments. */
3511 for (cnt = 0; cnt < 7 && seg_cnt;
3512 cnt++, seg_cnt--) {
3513 *dword_ptr++ =
3514 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3515 *dword_ptr++ =
3516 cpu_to_le32(sg_dma_len(sg));
3517 dprintk(1,
3518 "S/G Segment Cont. phys_addr=0x%x, "
3519 "len=0x%x\n",
3520 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
3521 cpu_to_le32(sg_dma_len(sg)));
3522 sg++;
3523 }
3524 dprintk(5, "qla1280_32bit_start_scsi: "
3525 "continuation packet data - "
3526 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
3527 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3528 qla1280_dump_buffer(5, (char *)pkt,
3529 REQUEST_ENTRY_SIZE);
3530 }
3531 } else { /* No S/G data transfer */
3532 dma_handle = pci_map_single(ha->pdev,
3533 cmd->request_buffer,
3534 cmd->request_bufflen,
3535 cmd->sc_data_direction);
3536 sp->saved_dma_handle = dma_handle;
3537
3538 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3539 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3540 }
3541 } else { /* No data transfer at all */
3542 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
3543 "packet data - \n");
3544 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3545 }
3546 dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
3547 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3548 REQUEST_ENTRY_SIZE);
3549
3550 /* Adjust ring index. */
3551 ha->req_ring_index++;
3552 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3553 ha->req_ring_index = 0;
3554 ha->request_ring_ptr = ha->request_ring;
3555 } else
3556 ha->request_ring_ptr++;
3557
3558 /* Set chip new ring index. */
3559 dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
3560 "for pending command\n");
3561 sp->flags |= SRB_SENT;
3562 ha->actthreads++;
3563 WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
3564 /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
3565 mmiowb();
3566
3567 out:
3568 if (status)
3569 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
3570
3571 LEAVE("qla1280_32bit_start_scsi");
3572
3573 return status;
3574 }
3575 #endif
3576
3577 /*
3578 * qla1280_req_pkt
3579 * Function is responsible for locking ring and
3580 * getting a zeroed out request packet.
3581 *
3582 * Input:
3583 * ha = adapter block pointer.
3584 *
3585 * Returns:
3586 * 0 = failed to get slot.
3587 */
3588 static request_t *
3589 qla1280_req_pkt(struct scsi_qla_host *ha)
3590 {
3591 struct device_reg __iomem *reg = ha->iobase;
3592 request_t *pkt = NULL;
3593 int cnt;
3594 uint32_t timer;
3595
3596 ENTER("qla1280_req_pkt");
3597
3598 /*
3599 * This can be called from interrupt context, damn it!!!
3600 */
3601 /* Wait for 30 seconds for slot. */
3602 for (timer = 15000000; timer; timer--) {
3603 if (ha->req_q_cnt > 0) {
3604 /* Calculate number of free request entries. */
3605 cnt = RD_REG_WORD(&reg->mailbox4);
3606 if (ha->req_ring_index < cnt)
3607 ha->req_q_cnt = cnt - ha->req_ring_index;
3608 else
3609 ha->req_q_cnt =
3610 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3611 }
3612
3613 /* Found empty request ring slot? */
3614 if (ha->req_q_cnt > 0) {
3615 ha->req_q_cnt--;
3616 pkt = ha->request_ring_ptr;
3617
3618 /* Zero out packet. */
3619 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3620
3621 /*
3622 * How can this be right when we have a ring
3623 * size of 512???
3624 */
3625 /* Set system defined field. */
3626 pkt->sys_define = (uint8_t) ha->req_ring_index;
3627
3628 /* Set entry count. */
3629 pkt->entry_count = 1;
3630
3631 break;
3632 }
3633
3634 udelay(2); /* 10 */
3635
3636 /* Check for pending interrupts. */
3637 qla1280_poll(ha);
3638 }
3639
3640 if (!pkt)
3641 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
3642 else
3643 dprintk(3, "qla1280_req_pkt: exiting normally\n");
3644
3645 return pkt;
3646 }
3647
3648 /*
3649 * qla1280_isp_cmd
3650 * Function is responsible for modifying ISP input pointer.
3651 * Releases ring lock.
3652 *
3653 * Input:
3654 * ha = adapter block pointer.
3655 */
3656 static void
3657 qla1280_isp_cmd(struct scsi_qla_host *ha)
3658 {
3659 struct device_reg __iomem *reg = ha->iobase;
3660
3661 ENTER("qla1280_isp_cmd");
3662
3663 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
3664 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3665 REQUEST_ENTRY_SIZE);
3666
3667 /* Adjust ring index. */
3668 ha->req_ring_index++;
3669 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3670 ha->req_ring_index = 0;
3671 ha->request_ring_ptr = ha->request_ring;
3672 } else
3673 ha->request_ring_ptr++;
3674
3675 /*
3676 * Update request index to mailbox4 (Request Queue In).
3677 * The mmiowb() ensures that this write is ordered with writes by other
3678 * CPUs. Without the mmiowb(), it is possible for the following:
3679 * CPUA posts write of index 5 to mailbox4
3680 * CPUA releases host lock
3681 * CPUB acquires host lock
3682 * CPUB posts write of index 6 to mailbox4
3683 * On PCI bus, order reverses and write of 6 posts, then index 5,
3684 * causing chip to issue full queue of stale commands
3685 * The mmiowb() prevents future writes from crossing the barrier.
3686 * See Documentation/DocBook/deviceiobook.tmpl for more information.
3687 */
3688 WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
3689 mmiowb();
3690
3691 LEAVE("qla1280_isp_cmd");
3692 }
3693
3694 /****************************************************************************/
3695 /* Interrupt Service Routine. */
3696 /****************************************************************************/
3697
3698 /****************************************************************************
3699 * qla1280_isr
3700 * Calls I/O done on command completion.
3701 *
3702 * Input:
3703 * ha = adapter block pointer.
3704 * done_q = done queue.
3705 ****************************************************************************/
3706 static void
3707 qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
3708 {
3709 struct device_reg __iomem *reg = ha->iobase;
3710 struct response *pkt;
3711 struct srb *sp = NULL;
3712 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
3713 uint16_t *wptr;
3714 uint32_t index;
3715 u16 istatus;
3716
3717 ENTER("qla1280_isr");
3718
3719 istatus = RD_REG_WORD(&reg->istatus);
3720 if (!(istatus & (RISC_INT | PCI_INT)))
3721 return;
3722
3723 /* Save mailbox register 5 */
3724 mailbox[5] = RD_REG_WORD(&reg->mailbox5);
3725
3726 /* Check for mailbox interrupt. */
3727
3728 mailbox[0] = RD_REG_WORD_dmasync(&reg->semaphore);
3729
3730 if (mailbox[0] & BIT_0) {
3731 /* Get mailbox data. */
3732 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
3733
3734 wptr = &mailbox[0];
3735 *wptr++ = RD_REG_WORD(&reg->mailbox0);
3736 *wptr++ = RD_REG_WORD(&reg->mailbox1);
3737 *wptr = RD_REG_WORD(&reg->mailbox2);
3738 if (mailbox[0] != MBA_SCSI_COMPLETION) {
3739 wptr++;
3740 *wptr++ = RD_REG_WORD(&reg->mailbox3);
3741 *wptr++ = RD_REG_WORD(&reg->mailbox4);
3742 wptr++;
3743 *wptr++ = RD_REG_WORD(&reg->mailbox6);
3744 *wptr = RD_REG_WORD(&reg->mailbox7);
3745 }
3746
3747 /* Release mailbox registers. */
3748
3749 WRT_REG_WORD(&reg->semaphore, 0);
3750 WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
3751
3752 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
3753 mailbox[0]);
3754
3755 /* Handle asynchronous event */
3756 switch (mailbox[0]) {
3757 case MBA_SCSI_COMPLETION: /* Response completion */
3758 dprintk(5, "qla1280_isr: mailbox SCSI response "
3759 "completion\n");
3760
3761 if (ha->flags.online) {
3762 /* Get outstanding command index. */
3763 index = mailbox[2] << 16 | mailbox[1];
3764
3765 /* Validate handle. */
3766 if (index < MAX_OUTSTANDING_COMMANDS)
3767 sp = ha->outstanding_cmds[index];
3768 else
3769 sp = NULL;
3770
3771 if (sp) {
3772 /* Free outstanding command slot. */
3773 ha->outstanding_cmds[index] = NULL;
3774
3775 /* Save ISP completion status */
3776 CMD_RESULT(sp->cmd) = 0;
3777
3778 /* Place block on done queue */
3779 list_add_tail(&sp->list, done_q);
3780 } else {
3781 /*
3782 * If we get here we have a real problem!
3783 */
3784 printk(KERN_WARNING
3785 "qla1280: ISP invalid handle");
3786 }
3787 }
3788 break;
3789
3790 case MBA_BUS_RESET: /* SCSI Bus Reset */
3791 ha->flags.reset_marker = 1;
3792 index = mailbox[6] & BIT_0;
3793 ha->bus_settings[index].reset_marker = 1;
3794
3795 printk(KERN_DEBUG "qla1280_isr(): index %i "
3796 "asynchronous BUS_RESET\n", index);
3797 break;
3798
3799 case MBA_SYSTEM_ERR: /* System Error */
3800 printk(KERN_WARNING
3801 "qla1280: ISP System Error - mbx1=%xh, mbx2="
3802 "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
3803 mailbox[3]);
3804 break;
3805
3806 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
3807 printk(KERN_WARNING
3808 "qla1280: ISP Request Transfer Error\n");
3809 break;
3810
3811 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
3812 printk(KERN_WARNING
3813 "qla1280: ISP Response Transfer Error\n");
3814 break;
3815
3816 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
3817 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
3818 break;
3819
3820 case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
3821 dprintk(2,
3822 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
3823 break;
3824
3825 case MBA_DEVICE_RESET: /* Bus Device Reset */
3826 printk(KERN_INFO "qla1280_isr(): asynchronous "
3827 "BUS_DEVICE_RESET\n");
3828
3829 ha->flags.reset_marker = 1;
3830 index = mailbox[6] & BIT_0;
3831 ha->bus_settings[index].reset_marker = 1;
3832 break;
3833
3834 case MBA_BUS_MODE_CHANGE:
3835 dprintk(2,
3836 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
3837 break;
3838
3839 default:
3840 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
3841 if (mailbox[0] < MBA_ASYNC_EVENT) {
3842 wptr = &mailbox[0];
3843 memcpy((uint16_t *) ha->mailbox_out, wptr,
3844 MAILBOX_REGISTER_COUNT *
3845 sizeof(uint16_t));
3846
3847 if(ha->mailbox_wait != NULL)
3848 complete(ha->mailbox_wait);
3849 }
3850 break;
3851 }
3852 } else {
3853 WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
3854 }
3855
3856 /*
3857 * We will receive interrupts during mailbox testing prior to
3858 * the card being marked online, hence the double check.
3859 */
3860 if (!(ha->flags.online && !ha->mailbox_wait)) {
3861 dprintk(2, "qla1280_isr: Response pointer Error\n");
3862 goto out;
3863 }
3864
3865 if (mailbox[5] >= RESPONSE_ENTRY_CNT)
3866 goto out;
3867
3868 while (ha->rsp_ring_index != mailbox[5]) {
3869 pkt = ha->response_ring_ptr;
3870
3871 dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
3872 " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
3873 dprintk(5,"qla1280_isr: response packet data\n");
3874 qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
3875
3876 if (pkt->entry_type == STATUS_TYPE) {
3877 if ((le16_to_cpu(pkt->scsi_status) & 0xff)
3878 || pkt->comp_status || pkt->entry_status) {
3879 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3880 "0x%x mailbox[5] = 0x%x, comp_status "
3881 "= 0x%x, scsi_status = 0x%x\n",
3882 ha->rsp_ring_index, mailbox[5],
3883 le16_to_cpu(pkt->comp_status),
3884 le16_to_cpu(pkt->scsi_status));
3885 }
3886 } else {
3887 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3888 "0x%x, mailbox[5] = 0x%x\n",
3889 ha->rsp_ring_index, mailbox[5]);
3890 dprintk(2, "qla1280_isr: response packet data\n");
3891 qla1280_dump_buffer(2, (char *)pkt,
3892 RESPONSE_ENTRY_SIZE);
3893 }
3894
3895 if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
3896 dprintk(2, "status: Cmd %p, handle %i\n",
3897 ha->outstanding_cmds[pkt->handle]->cmd,
3898 pkt->handle);
3899 if (pkt->entry_type == STATUS_TYPE)
3900 qla1280_status_entry(ha, pkt, done_q);
3901 else
3902 qla1280_error_entry(ha, pkt, done_q);
3903 /* Adjust ring index. */
3904 ha->rsp_ring_index++;
3905 if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
3906 ha->rsp_ring_index = 0;
3907 ha->response_ring_ptr = ha->response_ring;
3908 } else
3909 ha->response_ring_ptr++;
3910 WRT_REG_WORD(&reg->mailbox5, ha->rsp_ring_index);
3911 }
3912 }
3913
3914 out:
3915 LEAVE("qla1280_isr");
3916 }
3917
3918 /*
3919 * qla1280_rst_aen
3920 * Processes asynchronous reset.
3921 *
3922 * Input:
3923 * ha = adapter block pointer.
3924 */
3925 static void
3926 qla1280_rst_aen(struct scsi_qla_host *ha)
3927 {
3928 uint8_t bus;
3929
3930 ENTER("qla1280_rst_aen");
3931
3932 if (ha->flags.online && !ha->flags.reset_active &&
3933 !ha->flags.abort_isp_active) {
3934 ha->flags.reset_active = 1;
3935 while (ha->flags.reset_marker) {
3936 /* Issue marker command. */
3937 ha->flags.reset_marker = 0;
3938 for (bus = 0; bus < ha->ports &&
3939 !ha->flags.reset_marker; bus++) {
3940 if (ha->bus_settings[bus].reset_marker) {
3941 ha->bus_settings[bus].reset_marker = 0;
3942 qla1280_marker(ha, bus, 0, 0,
3943 MK_SYNC_ALL);
3944 }
3945 }
3946 }
3947 }
3948
3949 LEAVE("qla1280_rst_aen");
3950 }
3951
3952
3953 #if LINUX_VERSION_CODE < 0x020500
3954 /*
3955 *
3956 */
3957 static void
3958 qla1280_get_target_options(struct scsi_cmnd *cmd, struct scsi_qla_host *ha)
3959 {
3960 unsigned char *result;
3961 struct nvram *n;
3962 int bus, target, lun;
3963
3964 bus = SCSI_BUS_32(cmd);
3965 target = SCSI_TCN_32(cmd);
3966 lun = SCSI_LUN_32(cmd);
3967
3968 /*
3969 * Make sure to not touch anything if someone is using the
3970 * sg interface.
3971 */
3972 if (cmd->use_sg || (CMD_RESULT(cmd) >> 16) != DID_OK || lun)
3973 return;
3974
3975 result = cmd->request_buffer;
3976 n = &ha->nvram;
3977
3978 n->bus[bus].target[target].parameter.f.enable_wide = 0;
3979 n->bus[bus].target[target].parameter.f.enable_sync = 0;
3980 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
3981
3982 if (result[7] & 0x60)
3983 n->bus[bus].target[target].parameter.f.enable_wide = 1;
3984 if (result[7] & 0x10)
3985 n->bus[bus].target[target].parameter.f.enable_sync = 1;
3986 if ((result[2] >= 3) && (result[4] + 5 > 56) &&
3987 (result[56] & 0x4))
3988 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
3989
3990 dprintk(2, "get_target_options(): wide %i, sync %i, ppr %i\n",
3991 n->bus[bus].target[target].parameter.f.enable_wide,
3992 n->bus[bus].target[target].parameter.f.enable_sync,
3993 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr);
3994 }
3995 #endif
3996
3997 /*
3998 * qla1280_status_entry
3999 * Processes received ISP status entry.
4000 *
4001 * Input:
4002 * ha = adapter block pointer.
4003 * pkt = entry pointer.
4004 * done_q = done queue.
4005 */
4006 static void
4007 qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
4008 struct list_head *done_q)
4009 {
4010 unsigned int bus, target, lun;
4011 int sense_sz;
4012 struct srb *sp;
4013 struct scsi_cmnd *cmd;
4014 uint32_t handle = le32_to_cpu(pkt->handle);
4015 uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
4016 uint16_t comp_status = le16_to_cpu(pkt->comp_status);
4017
4018 ENTER("qla1280_status_entry");
4019
4020 /* Validate handle. */
4021 if (handle < MAX_OUTSTANDING_COMMANDS)
4022 sp = ha->outstanding_cmds[handle];
4023 else
4024 sp = NULL;
4025
4026 if (!sp) {
4027 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
4028 goto out;
4029 }
4030
4031 /* Free outstanding command slot. */
4032 ha->outstanding_cmds[handle] = NULL;
4033
4034 cmd = sp->cmd;
4035
4036 /* Generate LU queue on cntrl, target, LUN */
4037 bus = SCSI_BUS_32(cmd);
4038 target = SCSI_TCN_32(cmd);
4039 lun = SCSI_LUN_32(cmd);
4040
4041 if (comp_status || scsi_status) {
4042 dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
4043 "0x%x, handle = 0x%x\n", comp_status,
4044 scsi_status, handle);
4045 }
4046
4047 /* Target busy or queue full */
4048 if ((scsi_status & 0xFF) == SAM_STAT_TASK_SET_FULL ||
4049 (scsi_status & 0xFF) == SAM_STAT_BUSY) {
4050 CMD_RESULT(cmd) = scsi_status & 0xff;
4051 } else {
4052
4053 /* Save ISP completion status */
4054 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
4055
4056 if (scsi_status & SS_CHECK_CONDITION) {
4057 if (comp_status != CS_ARS_FAILED) {
4058 uint16_t req_sense_length =
4059 le16_to_cpu(pkt->req_sense_length);
4060 if (req_sense_length < CMD_SNSLEN(cmd))
4061 sense_sz = req_sense_length;
4062 else
4063 /*
4064 * scsi_cmnd->sense_buffer is
4065 * 64 bytes, why only copy 63?
4066 * This looks wrong! /Jes
4067 */
4068 sense_sz = CMD_SNSLEN(cmd) - 1;
4069
4070 memcpy(cmd->sense_buffer,
4071 &pkt->req_sense_data, sense_sz);
4072 } else
4073 sense_sz = 0;
4074 memset(cmd->sense_buffer + sense_sz, 0,
4075 sizeof(cmd->sense_buffer) - sense_sz);
4076
4077 dprintk(2, "qla1280_status_entry: Check "
4078 "condition Sense data, b %i, t %i, "
4079 "l %i\n", bus, target, lun);
4080 if (sense_sz)
4081 qla1280_dump_buffer(2,
4082 (char *)cmd->sense_buffer,
4083 sense_sz);
4084 }
4085 }
4086
4087 /* Place command on done queue. */
4088 list_add_tail(&sp->list, done_q);
4089 out:
4090 LEAVE("qla1280_status_entry");
4091 }
4092
4093 /*
4094 * qla1280_error_entry
4095 * Processes error entry.
4096 *
4097 * Input:
4098 * ha = adapter block pointer.
4099 * pkt = entry pointer.
4100 * done_q = done queue.
4101 */
4102 static void
4103 qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
4104 struct list_head *done_q)
4105 {
4106 struct srb *sp;
4107 uint32_t handle = le32_to_cpu(pkt->handle);
4108
4109 ENTER("qla1280_error_entry");
4110
4111 if (pkt->entry_status & BIT_3)
4112 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
4113 else if (pkt->entry_status & BIT_2)
4114 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
4115 else if (pkt->entry_status & BIT_1)
4116 dprintk(2, "qla1280_error_entry: FULL flag error\n");
4117 else
4118 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
4119
4120 /* Validate handle. */
4121 if (handle < MAX_OUTSTANDING_COMMANDS)
4122 sp = ha->outstanding_cmds[handle];
4123 else
4124 sp = NULL;
4125
4126 if (sp) {
4127 /* Free outstanding command slot. */
4128 ha->outstanding_cmds[handle] = NULL;
4129
4130 /* Bad payload or header */
4131 if (pkt->entry_status & (BIT_3 + BIT_2)) {
4132 /* Bad payload or header, set error status. */
4133 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
4134 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
4135 } else if (pkt->entry_status & BIT_1) { /* FULL flag */
4136 CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
4137 } else {
4138 /* Set error status. */
4139 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
4140 }
4141
4142 /* Place command on done queue. */
4143 list_add_tail(&sp->list, done_q);
4144 }
4145 #ifdef QLA_64BIT_PTR
4146 else if (pkt->entry_type == COMMAND_A64_TYPE) {
4147 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
4148 }
4149 #endif
4150
4151 LEAVE("qla1280_error_entry");
4152 }
4153
4154 /*
4155 * qla1280_abort_isp
4156 * Resets ISP and aborts all outstanding commands.
4157 *
4158 * Input:
4159 * ha = adapter block pointer.
4160 *
4161 * Returns:
4162 * 0 = success
4163 */
4164 static int
4165 qla1280_abort_isp(struct scsi_qla_host *ha)
4166 {
4167 struct device_reg __iomem *reg = ha->iobase;
4168 struct srb *sp;
4169 int status = 0;
4170 int cnt;
4171 int bus;
4172
4173 ENTER("qla1280_abort_isp");
4174
4175 if (ha->flags.abort_isp_active || !ha->flags.online)
4176 goto out;
4177
4178 ha->flags.abort_isp_active = 1;
4179
4180 /* Disable ISP interrupts. */
4181 qla1280_disable_intrs(ha);
4182 WRT_REG_WORD(&reg->host_cmd, HC_PAUSE_RISC);
4183 RD_REG_WORD(&reg->id_l);
4184
4185 printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
4186 ha->host_no);
4187 /* Dequeue all commands in outstanding command list. */
4188 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
4189 struct scsi_cmnd *cmd;
4190 sp = ha->outstanding_cmds[cnt];
4191 if (sp) {
4192
4193 cmd = sp->cmd;
4194 CMD_RESULT(cmd) = DID_RESET << 16;
4195
4196 sp->cmd = NULL;
4197 ha->outstanding_cmds[cnt] = NULL;
4198
4199 (*cmd->scsi_done)(cmd);
4200
4201 sp->flags = 0;
4202 }
4203 }
4204
4205 status = qla1280_load_firmware(ha);
4206 if (status)
4207 goto out;
4208
4209 /* Setup adapter based on NVRAM parameters. */
4210 qla1280_nvram_config (ha);
4211
4212 status = qla1280_init_rings(ha);
4213 if (status)
4214 goto out;
4215
4216 /* Issue SCSI reset. */
4217 for (bus = 0; bus < ha->ports; bus++)
4218 qla1280_bus_reset(ha, bus);
4219
4220 ha->flags.abort_isp_active = 0;
4221 out:
4222 if (status) {
4223 printk(KERN_WARNING
4224 "qla1280: ISP error recovery failed, board disabled");
4225 qla1280_reset_adapter(ha);
4226 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
4227 }
4228
4229 LEAVE("qla1280_abort_isp");
4230 return status;
4231 }
4232
4233
4234 /*
4235 * qla1280_debounce_register
4236 * Debounce register.
4237 *
4238 * Input:
4239 * port = register address.
4240 *
4241 * Returns:
4242 * register value.
4243 */
4244 static u16
4245 qla1280_debounce_register(volatile u16 __iomem * addr)
4246 {
4247 volatile u16 ret;
4248 volatile u16 ret2;
4249
4250 ret = RD_REG_WORD(addr);
4251 ret2 = RD_REG_WORD(addr);
4252
4253 if (ret == ret2)
4254 return ret;
4255
4256 do {
4257 cpu_relax();
4258 ret = RD_REG_WORD(addr);
4259 ret2 = RD_REG_WORD(addr);
4260 } while (ret != ret2);
4261
4262 return ret;
4263 }
4264
4265
4266 /************************************************************************
4267 * qla1280_check_for_dead_scsi_bus *
4268 * *
4269 * This routine checks for a dead SCSI bus *
4270 ************************************************************************/
4271 #define SET_SXP_BANK 0x0100
4272 #define SCSI_PHASE_INVALID 0x87FF
4273 static int
4274 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
4275 {
4276 uint16_t config_reg, scsi_control;
4277 struct device_reg __iomem *reg = ha->iobase;
4278
4279 if (ha->bus_settings[bus].scsi_bus_dead) {
4280 WRT_REG_WORD(&reg->host_cmd, HC_PAUSE_RISC);
4281 config_reg = RD_REG_WORD(&reg->cfg_1);
4282 WRT_REG_WORD(&reg->cfg_1, SET_SXP_BANK);
4283 scsi_control = RD_REG_WORD(&reg->scsiControlPins);
4284 WRT_REG_WORD(&reg->cfg_1, config_reg);
4285 WRT_REG_WORD(&reg->host_cmd, HC_RELEASE_RISC);
4286
4287 if (scsi_control == SCSI_PHASE_INVALID) {
4288 ha->bus_settings[bus].scsi_bus_dead = 1;
4289 #if 0
4290 CMD_RESULT(cp) = DID_NO_CONNECT << 16;
4291 CMD_HANDLE(cp) = INVALID_HANDLE;
4292 /* ha->actthreads--; */
4293
4294 (*(cp)->scsi_done)(cp);
4295 #endif
4296 return 1; /* bus is dead */
4297 } else {
4298 ha->bus_settings[bus].scsi_bus_dead = 0;
4299 ha->bus_settings[bus].failed_reset_count = 0;
4300 }
4301 }
4302 return 0; /* bus is not dead */
4303 }
4304
4305 static void
4306 qla1280_get_target_parameters(struct scsi_qla_host *ha,
4307 struct scsi_device *device)
4308 {
4309 uint16_t mb[MAILBOX_REGISTER_COUNT];
4310 int bus, target, lun;
4311
4312 bus = device->channel;
4313 target = device->id;
4314 lun = device->lun;
4315
4316
4317 mb[0] = MBC_GET_TARGET_PARAMETERS;
4318 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
4319 mb[1] <<= 8;
4320 qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
4321 &mb[0]);
4322
4323 printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
4324
4325 if (mb[3] != 0) {
4326 printk(" Sync: period %d, offset %d",
4327 (mb[3] & 0xff), (mb[3] >> 8));
4328 if (mb[2] & BIT_13)
4329 printk(", Wide");
4330 if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
4331 printk(", DT");
4332 } else
4333 printk(" Async");
4334
4335 if (DEV_SIMPLE_TAGS(device))
4336 printk(", Tagged queuing: depth %d", device->queue_depth);
4337 printk("\n");
4338 }
4339
4340
4341 #if DEBUG_QLA1280
4342 static void
4343 __qla1280_dump_buffer(char *b, int size)
4344 {
4345 int cnt;
4346 u8 c;
4347
4348 printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
4349 "Bh Ch Dh Eh Fh\n");
4350 printk(KERN_DEBUG "---------------------------------------------"
4351 "------------------\n");
4352
4353 for (cnt = 0; cnt < size;) {
4354 c = *b++;
4355
4356 printk("0x%02x", c);
4357 cnt++;
4358 if (!(cnt % 16))
4359 printk("\n");
4360 else
4361 printk(" ");
4362 }
4363 if (cnt % 16)
4364 printk("\n");
4365 }
4366
4367 /**************************************************************************
4368 * ql1280_print_scsi_cmd
4369 *
4370 **************************************************************************/
4371 static void
4372 __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
4373 {
4374 struct scsi_qla_host *ha;
4375 struct Scsi_Host *host = CMD_HOST(cmd);
4376 struct srb *sp;
4377 /* struct scatterlist *sg; */
4378
4379 int i;
4380 ha = (struct scsi_qla_host *)host->hostdata;
4381
4382 sp = (struct srb *)CMD_SP(cmd);
4383 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
4384 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
4385 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
4386 CMD_CDBLEN(cmd));
4387 printk(" CDB = ");
4388 for (i = 0; i < cmd->cmd_len; i++) {
4389 printk("0x%02x ", cmd->cmnd[i]);
4390 }
4391 printk(" seg_cnt =%d\n", cmd->use_sg);
4392 printk(" request buffer=0x%p, request buffer len=0x%x\n",
4393 cmd->request_buffer, cmd->request_bufflen);
4394 /* if (cmd->use_sg)
4395 {
4396 sg = (struct scatterlist *) cmd->request_buffer;
4397 printk(" SG buffer: \n");
4398 qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
4399 } */
4400 printk(" tag=%d, transfersize=0x%x \n",
4401 cmd->tag, cmd->transfersize);
4402 printk(" Pid=%li, SP=0x%p\n", cmd->pid, CMD_SP(cmd));
4403 printk(" underflow size = 0x%x, direction=0x%x\n",
4404 cmd->underflow, cmd->sc_data_direction);
4405 }
4406
4407 /**************************************************************************
4408 * ql1280_dump_device
4409 *
4410 **************************************************************************/
4411 static void
4412 ql1280_dump_device(struct scsi_qla_host *ha)
4413 {
4414
4415 struct scsi_cmnd *cp;
4416 struct srb *sp;
4417 int i;
4418
4419 printk(KERN_DEBUG "Outstanding Commands on controller:\n");
4420
4421 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
4422 if ((sp = ha->outstanding_cmds[i]) == NULL)
4423 continue;
4424 if ((cp = sp->cmd) == NULL)
4425 continue;
4426 qla1280_print_scsi_cmd(1, cp);
4427 }
4428 }
4429 #endif
4430
4431
4432 enum tokens {
4433 TOKEN_NVRAM,
4434 TOKEN_SYNC,
4435 TOKEN_WIDE,
4436 TOKEN_PPR,
4437 TOKEN_VERBOSE,
4438 TOKEN_DEBUG,
4439 };
4440
4441 struct setup_tokens {
4442 char *token;
4443 int val;
4444 };
4445
4446 static struct setup_tokens setup_token[] __initdata =
4447 {
4448 { "nvram", TOKEN_NVRAM },
4449 { "sync", TOKEN_SYNC },
4450 { "wide", TOKEN_WIDE },
4451 { "ppr", TOKEN_PPR },
4452 { "verbose", TOKEN_VERBOSE },
4453 { "debug", TOKEN_DEBUG },
4454 };
4455
4456
4457 /**************************************************************************
4458 * qla1280_setup
4459 *
4460 * Handle boot parameters. This really needs to be changed so one
4461 * can specify per adapter parameters.
4462 **************************************************************************/
4463 static int __init
4464 qla1280_setup(char *s)
4465 {
4466 char *cp, *ptr;
4467 unsigned long val;
4468 int toke;
4469
4470 cp = s;
4471
4472 while (cp && (ptr = strchr(cp, ':'))) {
4473 ptr++;
4474 if (!strcmp(ptr, "yes")) {
4475 val = 0x10000;
4476 ptr += 3;
4477 } else if (!strcmp(ptr, "no")) {
4478 val = 0;
4479 ptr += 2;
4480 } else
4481 val = simple_strtoul(ptr, &ptr, 0);
4482
4483 switch ((toke = qla1280_get_token(cp))) {
4484 case TOKEN_NVRAM:
4485 if (!val)
4486 driver_setup.no_nvram = 1;
4487 break;
4488 case TOKEN_SYNC:
4489 if (!val)
4490 driver_setup.no_sync = 1;
4491 else if (val != 0x10000)
4492 driver_setup.sync_mask = val;
4493 break;
4494 case TOKEN_WIDE:
4495 if (!val)
4496 driver_setup.no_wide = 1;
4497 else if (val != 0x10000)
4498 driver_setup.wide_mask = val;
4499 break;
4500 case TOKEN_PPR:
4501 if (!val)
4502 driver_setup.no_ppr = 1;
4503 else if (val != 0x10000)
4504 driver_setup.ppr_mask = val;
4505 break;
4506 case TOKEN_VERBOSE:
4507 qla1280_verbose = val;
4508 break;
4509 default:
4510 printk(KERN_INFO "qla1280: unknown boot option %s\n",
4511 cp);
4512 }
4513
4514 cp = strchr(ptr, ';');
4515 if (cp)
4516 cp++;
4517 else {
4518 break;
4519 }
4520 }
4521 return 1;
4522 }
4523
4524
4525 static int
4526 qla1280_get_token(char *str)
4527 {
4528 char *sep;
4529 long ret = -1;
4530 int i, len;
4531
4532 len = sizeof(setup_token)/sizeof(struct setup_tokens);
4533
4534 sep = strchr(str, ':');
4535
4536 if (sep) {
4537 for (i = 0; i < len; i++){
4538
4539 if (!strncmp(setup_token[i].token, str, (sep - str))) {
4540 ret = setup_token[i].val;
4541 break;
4542 }
4543 }
4544 }
4545
4546 return ret;
4547 }
4548
4549 #if LINUX_VERSION_CODE >= 0x020600
4550 static struct scsi_host_template qla1280_driver_template = {
4551 .module = THIS_MODULE,
4552 .proc_name = "qla1280",
4553 .name = "Qlogic ISP 1280/12160",
4554 .info = qla1280_info,
4555 .slave_configure = qla1280_slave_configure,
4556 .queuecommand = qla1280_queuecommand,
4557 .eh_abort_handler = qla1280_eh_abort,
4558 .eh_device_reset_handler= qla1280_eh_device_reset,
4559 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4560 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4561 .bios_param = qla1280_biosparam,
4562 .can_queue = 0xfffff,
4563 .this_id = -1,
4564 .sg_tablesize = SG_ALL,
4565 .cmd_per_lun = 1,
4566 .use_clustering = ENABLE_CLUSTERING,
4567 };
4568 #else
4569 static Scsi_Host_Template qla1280_driver_template = {
4570 .proc_name = "qla1280",
4571 .name = "Qlogic ISP 1280/12160",
4572 .detect = qla1280_detect,
4573 .release = qla1280_release,
4574 .info = qla1280_info,
4575 .queuecommand = qla1280_queuecommand,
4576 .eh_abort_handler = qla1280_eh_abort,
4577 .eh_device_reset_handler= qla1280_eh_device_reset,
4578 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4579 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4580 .bios_param = qla1280_biosparam_old,
4581 .can_queue = 0xfffff,
4582 .this_id = -1,
4583 .sg_tablesize = SG_ALL,
4584 .cmd_per_lun = 1,
4585 .use_clustering = ENABLE_CLUSTERING,
4586 .use_new_eh_code = 1,
4587 };
4588 #endif
4589
4590 static int __devinit
4591 qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4592 {
4593 int devnum = id->driver_data;
4594 struct qla_boards *bdp = &ql1280_board_tbl[devnum];
4595 struct Scsi_Host *host;
4596 struct scsi_qla_host *ha;
4597 int error = -ENODEV;
4598
4599 /* Bypass all AMI SUBSYS VENDOR IDs */
4600 if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
4601 printk(KERN_INFO
4602 "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
4603 goto error;
4604 }
4605
4606 printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
4607 bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
4608
4609 if (pci_enable_device(pdev)) {
4610 printk(KERN_WARNING
4611 "qla1280: Failed to enabled pci device, aborting.\n");
4612 goto error;
4613 }
4614
4615 pci_set_master(pdev);
4616
4617 error = -ENOMEM;
4618 host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
4619 if (!host) {
4620 printk(KERN_WARNING
4621 "qla1280: Failed to register host, aborting.\n");
4622 goto error_disable_device;
4623 }
4624
4625 ha = (struct scsi_qla_host *)host->hostdata;
4626 memset(ha, 0, sizeof(struct scsi_qla_host));
4627
4628 ha->pdev = pdev;
4629 ha->devnum = devnum; /* specifies microcode load address */
4630
4631 #ifdef QLA_64BIT_PTR
4632 if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) {
4633 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4634 printk(KERN_WARNING "scsi(%li): Unable to set a "
4635 " suitable DMA mask - aboring\n", ha->host_no);
4636 error = -ENODEV;
4637 goto error_free_irq;
4638 }
4639 } else
4640 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4641 ha->host_no);
4642 #else
4643 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4644 printk(KERN_WARNING "scsi(%li): Unable to set a "
4645 " suitable DMA mask - aboring\n", ha->host_no);
4646 error = -ENODEV;
4647 goto error_free_irq;
4648 }
4649 #endif
4650
4651 ha->request_ring = pci_alloc_consistent(ha->pdev,
4652 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4653 &ha->request_dma);
4654 if (!ha->request_ring) {
4655 printk(KERN_INFO "qla1280: Failed to get request memory\n");
4656 goto error_put_host;
4657 }
4658
4659 ha->response_ring = pci_alloc_consistent(ha->pdev,
4660 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4661 &ha->response_dma);
4662 if (!ha->response_ring) {
4663 printk(KERN_INFO "qla1280: Failed to get response memory\n");
4664 goto error_free_request_ring;
4665 }
4666
4667 ha->ports = bdp->numPorts;
4668
4669 ha->host = host;
4670 ha->host_no = host->host_no;
4671
4672 host->irq = pdev->irq;
4673 host->max_channel = bdp->numPorts - 1;
4674 host->max_lun = MAX_LUNS - 1;
4675 host->max_id = MAX_TARGETS;
4676 host->max_sectors = 1024;
4677 host->unique_id = host->host_no;
4678
4679 #if LINUX_VERSION_CODE < 0x020545
4680 host->select_queue_depths = qla1280_select_queue_depth;
4681 #endif
4682
4683 error = -ENODEV;
4684
4685 #if MEMORY_MAPPED_IO
4686 ha->mmpbase = ioremap(pci_resource_start(ha->pdev, 1),
4687 pci_resource_len(ha->pdev, 1));
4688 if (!ha->mmpbase) {
4689 printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
4690 goto error_free_response_ring;
4691 }
4692
4693 host->base = (unsigned long)ha->mmpbase;
4694 ha->iobase = (struct device_reg __iomem *)ha->mmpbase;
4695 #else
4696 host->io_port = pci_resource_start(ha->pdev, 0);
4697 if (!request_region(host->io_port, 0xff, "qla1280")) {
4698 printk(KERN_INFO "qla1280: Failed to reserve i/o region "
4699 "0x%04lx-0x%04lx - already in use\n",
4700 host->io_port, host->io_port + 0xff);
4701 goto error_free_response_ring;
4702 }
4703
4704 ha->iobase = (struct device_reg *)host->io_port;
4705 #endif
4706
4707 INIT_LIST_HEAD(&ha->done_q);
4708
4709 /* Disable ISP interrupts. */
4710 qla1280_disable_intrs(ha);
4711
4712 if (request_irq(pdev->irq, qla1280_intr_handler, SA_SHIRQ,
4713 "qla1280", ha)) {
4714 printk("qla1280 : Failed to reserve interrupt %d already "
4715 "in use\n", pdev->irq);
4716 goto error_release_region;
4717 }
4718
4719 /* load the F/W, read paramaters, and init the H/W */
4720 if (qla1280_initialize_adapter(ha)) {
4721 printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
4722 goto error_free_irq;
4723 }
4724
4725 /* set our host ID (need to do something about our two IDs) */
4726 host->this_id = ha->bus_settings[0].id;
4727
4728 pci_set_drvdata(pdev, host);
4729
4730 #if LINUX_VERSION_CODE >= 0x020600
4731 error = scsi_add_host(host, &pdev->dev);
4732 if (error)
4733 goto error_disable_adapter;
4734 scsi_scan_host(host);
4735 #else
4736 scsi_set_pci_device(host, pdev);
4737 #endif
4738
4739 return 0;
4740
4741 #if LINUX_VERSION_CODE >= 0x020600
4742 error_disable_adapter:
4743 WRT_REG_WORD(&ha->iobase->ictrl, 0);
4744 #endif
4745 error_free_irq:
4746 free_irq(pdev->irq, ha);
4747 error_release_region:
4748 #if MEMORY_MAPPED_IO
4749 iounmap(ha->mmpbase);
4750 #else
4751 release_region(host->io_port, 0xff);
4752 #endif
4753 error_free_response_ring:
4754 pci_free_consistent(ha->pdev,
4755 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4756 ha->response_ring, ha->response_dma);
4757 error_free_request_ring:
4758 pci_free_consistent(ha->pdev,
4759 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4760 ha->request_ring, ha->request_dma);
4761 error_put_host:
4762 scsi_host_put(host);
4763 error_disable_device:
4764 pci_disable_device(pdev);
4765 error:
4766 return error;
4767 }
4768
4769
4770 static void __devexit
4771 qla1280_remove_one(struct pci_dev *pdev)
4772 {
4773 struct Scsi_Host *host = pci_get_drvdata(pdev);
4774 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
4775
4776 #if LINUX_VERSION_CODE >= 0x020600
4777 scsi_remove_host(host);
4778 #endif
4779
4780 WRT_REG_WORD(&ha->iobase->ictrl, 0);
4781
4782 free_irq(pdev->irq, ha);
4783
4784 #if MEMORY_MAPPED_IO
4785 iounmap(ha->mmpbase);
4786 #else
4787 release_region(host->io_port, 0xff);
4788 #endif
4789
4790 pci_free_consistent(ha->pdev,
4791 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4792 ha->request_ring, ha->request_dma);
4793 pci_free_consistent(ha->pdev,
4794 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4795 ha->response_ring, ha->response_dma);
4796
4797 pci_disable_device(pdev);
4798
4799 scsi_host_put(host);
4800 }
4801
4802 #if LINUX_VERSION_CODE >= 0x020600
4803 static struct pci_driver qla1280_pci_driver = {
4804 .name = "qla1280",
4805 .id_table = qla1280_pci_tbl,
4806 .probe = qla1280_probe_one,
4807 .remove = __devexit_p(qla1280_remove_one),
4808 };
4809
4810 static int __init
4811 qla1280_init(void)
4812 {
4813 if (sizeof(struct srb) > sizeof(struct scsi_pointer)) {
4814 printk(KERN_WARNING
4815 "qla1280: struct srb too big, aborting\n");
4816 return -EINVAL;
4817 }
4818
4819 #ifdef MODULE
4820 /*
4821 * If we are called as a module, the qla1280 pointer may not be null
4822 * and it would point to our bootup string, just like on the lilo
4823 * command line. IF not NULL, then process this config string with
4824 * qla1280_setup
4825 *
4826 * Boot time Options
4827 * To add options at boot time add a line to your lilo.conf file like:
4828 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
4829 * which will result in the first four devices on the first two
4830 * controllers being set to a tagged queue depth of 32.
4831 */
4832 if (qla1280)
4833 qla1280_setup(qla1280);
4834 #endif
4835
4836 return pci_module_init(&qla1280_pci_driver);
4837 }
4838
4839 static void __exit
4840 qla1280_exit(void)
4841 {
4842 pci_unregister_driver(&qla1280_pci_driver);
4843 }
4844
4845 module_init(qla1280_init);
4846 module_exit(qla1280_exit);
4847
4848 #else
4849 # define driver_template qla1280_driver_template
4850 # include "scsi_module.c"
4851 #endif
4852
4853 MODULE_AUTHOR("Qlogic & Jes Sorensen");
4854 MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
4855 MODULE_LICENSE("GPL");
4856 MODULE_VERSION(QLA1280_VERSION);
4857
4858 /*
4859 * Overrides for Emacs so that we almost follow Linus's tabbing style.
4860 * Emacs will notice this stuff at the end of the file and automatically
4861 * adjust the settings for this buffer only. This must remain at the end
4862 * of the file.
4863 * ---------------------------------------------------------------------------
4864 * Local variables:
4865 * c-basic-offset: 8
4866 * tab-width: 8
4867 * End:
4868 */
This page took 0.133536 seconds and 5 git commands to generate.