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