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