Merge with Linux 2.5.48.
[linux-2.6/linux-mips.git] / drivers / scsi / qla1280.c
blobe57e1c43067e779209b4254391dfff2f0ef3a5bc
1 /******************************************************************************
2 * QLOGIC LINUX SOFTWARE
4 * QLogic QLA1280 (Ultra2) and QLA12160 (Ultra3) SCSI driver
5 * Copyright (C) 2000 Qlogic Corporation (www.qlogic.com)
6 * Copyright (C) 2001-2002 Jes Sorensen, Wild Open Source Inc.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 ******************************************************************************/
19 #define QLA1280_VERSION "3.23.19 Beta"
20 /******************************************************************************
21 Revision History:
22 Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
23 - Do qla1280_pci_config() before calling request_irq() and
24 request_region()
25 - Use pci_dma_hi32() to handle upper word of DMA addresses instead
26 of large shifts
27 - Hand correct arguments to free_irq() in case of failure
28 Rev 3.23.18 Beta April 11, 2002, Jes Sorensen
29 - Run source through Lindent and clean up the output
30 Rev 3.23.17 Beta April 11, 2002, Jes Sorensen
31 - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32
32 Rev 3.23.16 Beta March 19, 2002, Jes Sorensen
33 - Rely on mailbox commands generating interrupts - do not
34 run qla1280_isr() from ql1280_mailbox_command()
35 - Remove device_reg_t
36 - Integrate ql12160_set_target_parameters() with 1280 version
37 - Make qla1280_setup() non static
38 - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request
39 sent to the card - this command pauses the firmare!!!
40 Rev 3.23.15 Beta March 19, 2002, Jes Sorensen
41 - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions
42 - Remove a pile of pointless and confusing (srb_t **) and
43 (scsi_lu_t *) typecasts
44 - Explicit mark that we do not use the new error handling (for now)
45 - Remove scsi_qla_host_t and use 'struct' instead
46 - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled,
47 pci_64bit_slot flags which weren't used for anything anyway
48 - Grab host->host_lock while calling qla1280_isr() from abort()
49 - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we
50 do not need to save/restore flags in the interrupt handler
51 - Enable interrupts early (before any mailbox access) in preparation
52 for cleaning up the mailbox handling
53 Rev 3.23.14 Beta March 14, 2002, Jes Sorensen
54 - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace
55 it with proper use of dprintk().
56 - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take
57 a debug level argument to determine if data is to be printed
58 - Add KERN_* info to printk()
59 Rev 3.23.13 Beta March 14, 2002, Jes Sorensen
60 - Significant cosmetic cleanups
61 - Change debug code to use dprintk() and remove #if mess
62 Rev 3.23.12 Beta March 13, 2002, Jes Sorensen
63 - More cosmetic cleanups, fix places treating return as function
64 - use cpu_relax() in qla1280_debounce_register()
65 Rev 3.23.11 Beta March 13, 2002, Jes Sorensen
66 - Make it compile under 2.5.5
67 Rev 3.23.10 Beta October 1, 2001, Jes Sorensen
68 - Do no typecast short * to long * in QL1280BoardTbl, this
69 broke miserably on big endian boxes
70 Rev 3.23.9 Beta September 30, 2001, Jes Sorensen
71 - Remove pre 2.2 hack for checking for reentrance in interrupt handler
72 - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32
73 unsigned int to match the types from struct scsi_cmnd
74 Rev 3.23.8 Beta September 29, 2001, Jes Sorensen
75 - Remove bogus timer_t typedef from qla1280.h
76 - Remove obsolete pre 2.2 PCI setup code, use proper #define's
77 for PCI_ values, call pci_set_master()
78 - Fix memleak of qla1280_buffer on module unload
79 - Only compile module parsing code #ifdef MODULE - should be
80 changed to use individual MODULE_PARM's later
81 - Remove dummy_buffer that was never modified nor printed
82 - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove
83 #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls
84 - Remove \r from print statements, this is Linux, not DOS
85 - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK}
86 dummy macros
87 - Remove C++ compile hack in header file as Linux driver are not
88 supposed to be compiled as C++
89 - Kill MS_64BITS macro as it makes the code more readable
90 - Remove unnecessary flags.in_interrupts bit
91 Rev 3.23.7 Beta August 20, 2001, Jes Sorensen
92 - Dont' check for set flags on q->q_flag one by one in qla1280_next()
93 - Check whether the interrupt was generated by the QLA1280 before
94 doing any processing
95 - qla1280_status_entry(): Only zero out part of sense_buffer that
96 is not being copied into
97 - Remove more superflouous typecasts
98 - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy()
99 Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel
100 - Don't walk the entire list in qla1280_putq_t() just to directly
101 grab the pointer to the last element afterwards
102 Rev 3.23.5 Beta August 9, 2001, Jes Sorensen
103 - Don't use SA_INTERRUPT, it's use is deprecated for this kinda driver
104 Rev 3.23.4 Beta August 8, 2001, Jes Sorensen
105 - Set dev->max_sectors to 1024
106 Rev 3.23.3 Beta August 6, 2001, Jes Sorensen
107 - Provide compat macros for pci_enable_device(), pci_find_subsys()
108 and scsi_set_pci_device()
109 - Call scsi_set_pci_device() for all devices
110 - Reduce size of kernel version dependant device probe code
111 - Move duplicate probe/init code to seperate function
112 - Handle error if qla1280_mem_alloc() fails
113 - Kill OFFSET() macro and use Linux's PCI definitions instead
114 - Kill private structure defining PCI config space (struct config_reg)
115 - Only allocate I/O port region if not in MMIO mode
116 - Remove duplicate (unused) sanity check of sife of srb_t
117 Rev 3.23.2 Beta August 6, 2001, Jes Sorensen
118 - Change home-brew memset() implementations to use memset()
119 - Remove all references to COMTRACE() - accessing a PC's COM2 serial
120 port directly is not legal under Linux.
121 Rev 3.23.1 Beta April 24, 2001, Jes Sorensen
122 - Remove pre 2.2 kernel support
123 - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat)
124 - Fix MMIO access to use readl/writel instead of directly
125 dereferencing pointers
126 - Nuke MSDOS debugging code
127 - Change true/false data types to int from uint8_t
128 - Use int for counters instead of uint8_t etc.
129 - Clean up size & byte order conversion macro usage
130 Rev 3.23 Beta January 11, 2001 BN Qlogic
131 - Added check of device_id when handling non
132 QLA12160s during detect().
133 Rev 3.22 Beta January 5, 2001 BN Qlogic
134 - Changed queue_task() to schedule_work()
135 for kernels 2.4.0 and higher.
136 Note: 2.4.0-testxx kernels released prior to
137 the actual 2.4.0 kernel release on January 2001
138 will get compile/link errors with schedule_work().
139 Please update your kernel to released 2.4.0 level,
140 or comment lines in this file flagged with 3.22
141 to resolve compile/link error of schedule_work().
142 - Added -DCONFIG_SMP in addition to -D__SMP__
143 in Makefile for 2.4.0 builds of driver as module.
144 Rev 3.21 Beta January 4, 2001 BN Qlogic
145 - Changed criteria of 64/32 Bit mode of HBA
146 operation according to BITS_PER_LONG rather
147 than HBA's NVRAM setting of >4Gig memory bit;
148 so that the HBA auto-configures without the need
149 to setup each system individually.
150 Rev 3.20 Beta December 5, 2000 BN Qlogic
151 - Added priority handling to IA-64 onboard SCSI
152 ISP12160 chip for kernels greater than 2.3.18.
153 - Added irqrestore for qla1280_intr_handler.
154 - Enabled /proc/scsi/qla1280 interface.
155 - Clear /proc/scsi/qla1280 counters in detect().
156 Rev 3.19 Beta October 13, 2000 BN Qlogic
157 - Declare driver_template for new kernel
158 (2.4.0 and greater) scsi initialization scheme.
159 - Update /proc/scsi entry for 2.3.18 kernels and
160 above as qla1280
161 Rev 3.18 Beta October 10, 2000 BN Qlogic
162 - Changed scan order of adapters to map
163 the QLA12160 followed by the QLA1280.
164 Rev 3.17 Beta September 18, 2000 BN Qlogic
165 - Removed warnings for 32 bit 2.4.x compiles
166 - Corrected declared size for request and response
167 DMA addresses that are kept in each ha
168 Rev. 3.16 Beta August 25, 2000 BN Qlogic
169 - Corrected 64 bit addressing issue on IA-64
170 where the upper 32 bits were not properly
171 passed to the RISC engine.
172 Rev. 3.15 Beta August 22, 2000 BN Qlogic
173 - Modified qla1280_setup_chip to properly load
174 ISP firmware for greater that 4 Gig memory on IA-64
175 Rev. 3.14 Beta August 16, 2000 BN Qlogic
176 - Added setting of dma_mask to full 64 bit
177 if flags.enable_64bit_addressing is set in NVRAM
178 Rev. 3.13 Beta August 16, 2000 BN Qlogic
179 - Use new PCI DMA mapping APIs for 2.4.x kernel
180 Rev. 3.12 July 18, 2000 Redhat & BN Qlogic
181 - Added check of pci_enable_device to detect() for 2.3.x
182 - Use pci_resource_start() instead of
183 pdev->resource[0].start in detect() for 2.3.x
184 - Updated driver version
185 Rev. 3.11 July 14, 2000 BN Qlogic
186 - Updated SCSI Firmware to following versions:
187 qla1x80: 8.13.08
188 qla1x160: 10.04.08
189 - Updated driver version to 3.11
190 Rev. 3.10 June 23, 2000 BN Qlogic
191 - Added filtering of AMI SubSys Vendor ID devices
192 Rev. 3.9
193 - DEBUG_QLA1280 undefined and new version BN Qlogic
194 Rev. 3.08b May 9, 2000 MD Dell
195 - Added logic to check against AMI subsystem vendor ID
196 Rev. 3.08 May 4, 2000 DG Qlogic
197 - Added logic to check for PCI subsystem ID.
198 Rev. 3.07 Apr 24, 2000 DG & BN Qlogic
199 - Updated SCSI Firmware to following versions:
200 qla12160: 10.01.19
201 qla1280: 8.09.00
202 Rev. 3.06 Apr 12, 2000 DG & BN Qlogic
203 - Internal revision; not released
204 Rev. 3.05 Mar 28, 2000 DG & BN Qlogic
205 - Edit correction for virt_to_bus and PROC.
206 Rev. 3.04 Mar 28, 2000 DG & BN Qlogic
207 - Merge changes from ia64 port.
208 Rev. 3.03 Mar 28, 2000 BN Qlogic
209 - Increase version to reflect new code drop with compile fix
210 of issue with inclusion of linux/spinlock for 2.3 kernels
211 Rev. 3.02 Mar 15, 2000 BN Qlogic
212 - Merge qla1280_proc_info from 2.10 code base
213 Rev. 3.01 Feb 10, 2000 BN Qlogic
214 - Corrected code to compile on a 2.2.x kernel.
215 Rev. 3.00 Jan 17, 2000 DG Qlogic
216 - Added 64-bit support.
217 Rev. 2.07 Nov 9, 1999 DG Qlogic
218 - Added new routine to set target parameters for ISP12160.
219 Rev. 2.06 Sept 10, 1999 DG Qlogic
220 - Added support for ISP12160 Ultra 3 chip.
221 Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
222 - Modified code to remove errors generated when compiling with
223 Cygnus IA64 Compiler.
224 - Changed conversion of pointers to unsigned longs instead of integers.
225 - Changed type of I/O port variables from uint32_t to unsigned long.
226 - Modified OFFSET macro to work with 64-bit as well as 32-bit.
227 - Changed sprintf and printk format specifiers for pointers to %p.
228 - Changed some int to long type casts where needed in sprintf & printk.
229 - Added l modifiers to sprintf and printk format specifiers for longs.
230 - Removed unused local variables.
231 Rev. 1.20 June 8, 1999 DG, Qlogic
232 Changes to support RedHat release 6.0 (kernel 2.2.5).
233 - Added SCSI exclusive access lock (io_request_lock) when accessing
234 the adapter.
235 - Added changes for the new LINUX interface template. Some new error
236 handling routines have been added to the template, but for now we
237 will use the old ones.
238 - Initial Beta Release.
239 *****************************************************************************/
241 #include <linux/config.h>
242 #include <linux/module.h>
244 #include <linux/version.h>
245 #include <linux/types.h>
246 #include <linux/string.h>
247 #include <linux/errno.h>
248 #include <linux/kernel.h>
249 #include <linux/interrupt.h>
250 #include <linux/ioport.h>
251 #include <linux/delay.h>
252 #include <linux/timer.h>
253 #include <linux/pci.h>
254 #include <linux/proc_fs.h>
255 #include <linux/blk.h>
256 #include <linux/workqueue.h>
257 #include <linux/stat.h>
258 #include <linux/slab.h>
260 #include <asm/io.h>
261 #include <asm/irq.h>
262 #include <asm/byteorder.h>
263 #include <asm/processor.h>
265 #ifndef KERNEL_VERSION
266 #define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
267 #endif
269 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,18)
270 #include <linux/pci_ids.h>
271 #endif
273 #include "scsi.h"
274 #include "hosts.h"
275 #define UNIQUE_FW_NAME
276 #include "qla1280.h"
277 #include "ql12160_fw.h" /* ISP RISC codes */
278 #include "ql1280_fw.h"
281 * Compile time Options:
282 * 0 - Disable and 1 - Enable
284 #define QL1280_TARGET_MODE_SUPPORT 0 /* Target mode support */
285 #define QL1280_LUN_SUPPORT 0
286 #define WATCHDOGTIMER 0
287 #define MEMORY_MAPPED_IO 0
288 #define DEBUG_QLA1280_INTR 0
289 #define USE_NVRAM_DEFAULTS 0
290 #define DEBUG_PRINT_NVRAM 0
291 #define LOADING_RISC_ACTIVITY 0
292 #define AUTO_ESCALATE_RESET 0 /* Automatically escalate resets */
293 #define AUTO_ESCALATE_ABORT 0 /* Automatically escalate aborts */
294 #define STOP_ON_ERROR 0 /* Stop on aborts and resets */
295 #define STOP_ON_RESET 0
296 #define STOP_ON_ABORT 0
297 #define QLA1280_PROFILE 1 /* 3.20 */
298 #define DEBUG_QLA1280 0
301 * Missing PCI ID's
303 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1080
304 #define PCI_DEVICE_ID_QLOGIC_ISP1080 0x1080
305 #endif
306 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1240
307 #define PCI_DEVICE_ID_QLOGIC_ISP1240 0x1240
308 #endif
309 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1280
310 #define PCI_DEVICE_ID_QLOGIC_ISP1280 0x1280
311 #endif
312 #ifndef PCI_DEVICE_ID_QLOGIC_ISP10160
313 #define PCI_DEVICE_ID_QLOGIC_ISP10160 0x1016
314 #endif
315 #ifndef PCI_DEVICE_ID_QLOGIC_ISP12160
316 #define PCI_DEVICE_ID_QLOGIC_ISP12160 0x1216
317 #endif
319 #ifndef PCI_VENDOR_ID_AMI
320 #define PCI_VENDOR_ID_AMI 0x101e
321 #endif
323 #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
324 #define QLA_64BIT_PTR 1
325 #endif
327 /* 3.16 */
328 #ifdef QLA_64BIT_PTR
329 #define pci_dma_lo32(a) (a & 0xffffffff)
330 #define pci_dma_hi32(a) (a >> 32)
331 #else
332 #define pci_dma_lo32(a) (a & 0xffffffff)
333 #define pci_dma_hi32(a) 0
334 #endif
336 #define NVRAM_DELAY() udelay(500) /* 2 microsecond delay */
338 #define CACHE_FLUSH(a) RD_REG_WORD(a)
339 #define INVALID_HANDLE (MAX_OUTSTANDING_COMMANDS + 1)
342 * Compat macros
344 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
345 #define pci_set_dma_mask(dev, mask) dev->dma_mask = mask;
346 #define pci_present() pcibios_present()
347 #define pci_enable_device(pdev) 0
348 #define pci_find_subsys(id, dev, sid, sdev, pdev) pci_find_device(id,dev,pdev)
349 #define scsi_set_pci_device(host, pdev)
350 #endif
352 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
353 typedef unsigned long dma_addr_t;
355 static inline void *
356 pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
357 dma_addr_t * dma_handle)
359 void *virt_ptr;
361 virt_ptr = kmalloc(size, GFP_KERNEL);
362 if (!virt_ptr)
363 return NULL;
364 *dma_handle = virt_to_bus(virt_ptr);
365 return virt_ptr;
368 #define pci_free_consistent(cookie, size, ptr, dma_ptr) kfree(ptr)
369 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
370 #define pci_map_sg(cookie, scatter, ents, dir) ents
371 #define pci_unmap_single(cookie, address, size, dir)
372 #define pci_unmap_sg(cookie, scatter, ents, dir)
374 #define pci_resource_start(dev, i) dev->base_address[i]
375 #endif
378 * QLogic Driver Support Function Prototypes.
380 static void qla1280_done(struct scsi_qla_host *, srb_t **, srb_t **);
381 static void qla1280_next(struct scsi_qla_host *, scsi_lu_t *, int);
382 static void qla1280_putq_t(scsi_lu_t *, srb_t *);
383 static void qla1280_done_q_put(srb_t *, srb_t **, srb_t **);
384 static int qla1280_slave_attach(Scsi_Device *);
385 #if STOP_ON_ERROR
386 static void qla1280_panic(char *, struct Scsi_Host *host);
387 #endif
388 static void qla1280_abort_queue_single(struct scsi_qla_host *, int, int,
389 int, uint32_t);
391 static int qla1280_return_status(sts_entry_t * sts, Scsi_Cmnd * cp);
392 static void qla1280_removeq(scsi_lu_t * q, srb_t * sp);
393 static void qla1280_mem_free(struct scsi_qla_host *ha);
394 void qla1280_do_dpc(void *p);
395 #ifdef MODULE
396 static char *qla1280_get_token(char *, char *);
397 #endif
398 static inline void qla1280_enable_intrs(struct scsi_qla_host *);
399 static inline void qla1280_disable_intrs(struct scsi_qla_host *);
402 * QLogic ISP1280 Hardware Support Function Prototypes.
404 static int qla1280_initialize_adapter(struct scsi_qla_host *ha);
405 static int qla1280_enable_tgt(struct scsi_qla_host *, int);
406 static int qla1280_isp_firmware(struct scsi_qla_host *);
407 static int qla1280_pci_config(struct scsi_qla_host *);
408 static int qla1280_chip_diag(struct scsi_qla_host *);
409 static int qla1280_setup_chip(struct scsi_qla_host *);
410 static int qla1280_init_rings(struct scsi_qla_host *);
411 static int qla1280_nvram_config(struct scsi_qla_host *);
412 static int qla1280_mailbox_command(struct scsi_qla_host *,
413 uint8_t, uint16_t *);
414 static int qla1280_bus_reset(struct scsi_qla_host *, int);
415 static int qla1280_device_reset(struct scsi_qla_host *, int, int);
416 static int qla1280_abort_device(struct scsi_qla_host *, int, int, int);
417 static int qla1280_abort_command(struct scsi_qla_host *, srb_t *);
418 static int qla1280_abort_isp(struct scsi_qla_host *);
419 static int qla1280_64bit_start_scsi(struct scsi_qla_host *, srb_t *);
420 static int qla1280_32bit_start_scsi(struct scsi_qla_host *, srb_t *);
421 static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
422 static void qla1280_poll(struct scsi_qla_host *);
423 static void qla1280_reset_adapter(struct scsi_qla_host *);
424 static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
425 static void qla1280_isp_cmd(struct scsi_qla_host *);
426 static void qla1280_isr(struct scsi_qla_host *, srb_t **, srb_t **);
427 static void qla1280_rst_aen(struct scsi_qla_host *);
428 static void qla1280_status_entry(struct scsi_qla_host *, sts_entry_t *,
429 srb_t **, srb_t **);
430 static void qla1280_error_entry(struct scsi_qla_host *, response_t *,
431 srb_t **, srb_t **);
432 static void qla1280_restart_queues(struct scsi_qla_host *);
433 static void qla1280_abort_queues(struct scsi_qla_host *);
434 static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
435 static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
436 static uint16_t qla1280_debounce_register(volatile uint16_t *);
437 static request_t *qla1280_req_pkt(struct scsi_qla_host *);
438 static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
439 unsigned int);
440 static int qla1280_mem_alloc(struct scsi_qla_host *ha);
442 static void qla12160_get_target_parameters(struct scsi_qla_host *,
443 uint32_t, uint32_t, uint32_t);
445 #if QL1280_LUN_SUPPORT
446 static void qla1280_enable_lun(struct scsi_qla_host *, int, int);
447 #endif
449 #if QL1280_TARGET_MODE_SUPPORT
450 static void qla1280_notify_ack(struct scsi_qla_host *, notify_entry_t *);
451 static void qla1280_immed_notify(struct scsi_qla_host *, notify_entry_t *);
452 static void qla1280_accept_io(struct scsi_qla_host *, ctio_ret_entry_t *);
453 static void qla1280_64bit_continue_io(struct scsi_qla_host *, atio_entry_t *,
454 uint32_t, paddr32_t *);
455 static void qla1280_32bit_continue_io(struct scsi_qla_host *, atio_entry_t *,
456 uint32_t, paddr32_t *);
457 static void qla1280_atio_entry(struct scsi_qla_host *, atio_entry_t *);
458 static void qla1280_notify_entry(struct scsi_qla_host *, notify_entry_t *);
459 #endif /* QLA1280_TARGET_MODE_SUPPORT */
461 #ifdef QL_DEBUG_ROUTINES
463 * Driver Debug Function Prototypes.
465 static u8 qla1280_getbyte(u8 *);
466 static u16 qla1280_getword(u16 *);
467 static u32 qla1280_getdword(u32 *);
468 static void qla1280_putbyte(u8 *, u8);
469 static void qla1280_putword(u16 *, u8);
470 static void qla1280_putdword(u32 *, u32);
471 static void __qla1280_print_scsi_cmd(Scsi_Cmnd * cmd);
472 static void __qla1280_dump_buffer(char *, u32);
473 #endif
476 * insmod needs to find the variable and make it point to something
478 #ifdef MODULE
479 static char *options = NULL;
481 /* insmod qla1280 options=verbose" */
482 MODULE_PARM(options, "s");
483 #endif
485 MODULE_LICENSE("GPL");
487 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
489 * Our directory Entry in /proc/scsi for the user to
490 * access the driver.
492 /* Need to add in proc_fs.h PROC_SCSI_QL1280 */
493 #define PROC_SCSI_QL1280 PROC_SCSI_QLOGICISP
495 struct proc_dir_entry proc_scsi_qla1280 = {
496 PROC_SCSI_QL1280, 7, "qla1280",
497 S_IFDIR | S_IRUGO | S_IXUGO, 2,
498 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL
500 #endif
502 /* We use the Scsi_Pointer structure that's included with each command
503 * SCSI_Cmnd as a scratchpad for our SRB.
505 * SCp will always point to the SRB structure (defined in qla1280.h).
506 * It is define as follows:
507 * - SCp.ptr -- > pointer back to the cmd
508 * - SCp.this_residual --> used as forward pointer to next srb
509 * - SCp.buffer --> used as backward pointer to next srb
510 * - SCp.buffers_residual --> used as flags field
511 * - SCp.have_data_in --> not used
512 * - SCp.sent_command --> not used
513 * - SCp.phase --> not used
516 #define CMD_SP(Cmnd) &Cmnd->SCp
517 #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
518 #define CMD_CDBP(Cmnd) Cmnd->cmnd
519 #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
520 #define CMD_SNSLEN(Cmnd) sizeof(Cmnd->sense_buffer)
521 #define CMD_RESULT(Cmnd) Cmnd->result
522 #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
524 /*****************************************/
525 /* ISP Boards supported by this driver */
526 /*****************************************/
528 #define NUM_OF_ISP_DEVICES 6
530 struct qla_boards {
531 unsigned char bdName[9]; /* Board ID String */
532 unsigned long device_id; /* Device PCI ID */
533 int numPorts; /* Number of SCSI ports */
534 unsigned short *fwcode; /* pointer to FW array */
535 unsigned short *fwlen; /* number of words in array */
536 unsigned short *fwstart; /* start address for F/W */
537 unsigned char *fwver; /* Ptr to F/W version array */
540 struct qla_boards ql1280_board_tbl[NUM_OF_ISP_DEVICES] = {
541 /* Name , Board PCI Device ID, Number of ports */
542 {"QLA12160 ", PCI_DEVICE_ID_QLOGIC_ISP12160, 2,
543 &fw12160i_code01[0], &fw12160i_length01,
544 &fw12160i_addr01, &fw12160i_version_str[0]},
545 {"QLA1080 ", PCI_DEVICE_ID_QLOGIC_ISP1080, 1,
546 &fw1280ei_code01[0], &fw1280ei_length01,
547 &fw1280ei_addr01, &fw1280ei_version_str[0]},
548 {"QLA1240 ", PCI_DEVICE_ID_QLOGIC_ISP1240, 2,
549 &fw1280ei_code01[0], &fw1280ei_length01,
550 &fw1280ei_addr01, &fw1280ei_version_str[0]},
551 {"QLA1280 ", PCI_DEVICE_ID_QLOGIC_ISP1280, 2,
552 &fw1280ei_code01[0], &fw1280ei_length01,
553 &fw1280ei_addr01, &fw1280ei_version_str[0]},
554 {"QLA10160 ", PCI_DEVICE_ID_QLOGIC_ISP10160, 1,
555 &fw12160i_code01[0], &fw12160i_length01,
556 &fw12160i_addr01, &fw12160i_version_str[0]},
557 {" ", 0, 0}
560 static int qla1280_verbose = 1;
561 static struct scsi_qla_host *qla1280_hostlist = NULL;
562 #if QLA1280_PROFILE
563 static int qla1280_buffer_size = 0;
564 static char *qla1280_buffer = NULL;
565 #endif
567 #if DEBUG_QLA1280
568 static int ql_debug_print = 1;
569 char debug_buff[80];
570 #define DEBUG(x) x
571 static int ql_debug_level = 0;
572 #define dprintk(level, format, a...) \
573 if ((ql_debug_level >= level) && ql_debug_print) printk(KERN_DEBUG format, ##a)
574 #define qla1280_dump_buffer(level, buf, size) \
575 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
576 #define qla1280_dump_print_cmd(level, cmd) \
577 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
578 #else
579 #define DEBUG(x)
580 #define ql_debug_level 0
581 #define dprintk(level, format, a...) do{}while(0)
582 #define qla1280_dump_buffer(a, b, c) do{}while(0)
583 #define qla1280_print_scsi_cmd(a, b) do{}while(0)
584 #endif
586 #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
587 #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
588 #define ENTER_INTR(x) dprintk(3, "qla1280 : Entering %s()\n", x);
589 #define LEAVE_INTR(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
591 #define SCSI_BUS_32(scp) scp->channel
592 #define SCSI_TCN_32(scp) scp->target
593 #define SCSI_LUN_32(scp) scp->lun
595 /****************************************************************************/
596 /* LINUX - Loadable Module Functions. */
597 /****************************************************************************/
599 /*************************************************************************
600 * qla1280_set_info
602 * Description:
603 * Set parameters for the driver from the /proc filesystem.
605 * Returns:
606 *************************************************************************/
608 qla1280_set_info(char *buffer, int length, struct Scsi_Host *HBAptr)
610 return -ENOSYS; /* Currently this is a no-op */
613 /*************************************************************************
614 * qla1280_proc_info
616 * Description:
617 * Return information to handle /proc support for the driver.
619 * buffer - ptrs to a page buffer
621 * Returns:
622 *************************************************************************/
623 #define PROC_BUF &qla1280_buffer[len]
626 qla1280_proc_info(char *buffer, char **start, off_t offset, int length,
627 int hostno, int inout)
629 #if QLA1280_PROFILE
630 struct Scsi_Host *host;
631 struct scsi_qla_host *ha;
632 int size = 0;
633 scsi_lu_t *up;
634 int len = 0;
635 struct qla_boards *bdp;
636 uint32_t b, t, l;
637 host = NULL;
639 /* Find the host that was specified */
640 for (ha = qla1280_hostlist; (ha != NULL) && ha->host->host_no != hostno;
641 ha = ha->next) ;
643 /* if host wasn't found then exit */
644 if (!ha) {
645 size = sprintf(buffer, "Can't find adapter for host "
646 "number %d\n", hostno);
647 if (size > length) {
648 return size;
649 } else {
650 return 0;
654 host = ha->host;
656 if (inout == TRUE) { /* Has data been written to the file? */
657 printk(KERN_INFO
658 "qla1280_proc: has data been written to the file.\n");
659 return qla1280_set_info(buffer, length, host);
663 * if our old buffer is the right size use it otherwise
664 * allocate a new one.
666 if (qla1280_buffer_size != PAGE_SIZE) {
667 /* deallocate this buffer and get a new one */
668 if (qla1280_buffer != NULL) {
669 free_page((unsigned long)qla1280_buffer);
670 qla1280_buffer_size = 0;
672 qla1280_buffer = (char *)get_zeroed_page(GFP_KERNEL);
674 if (qla1280_buffer == NULL) {
675 size = sprintf(buffer, "qla1280 - kmalloc error at line %d\n",
676 __LINE__);
677 return size;
679 /* save the size of our buffer */
680 qla1280_buffer_size = PAGE_SIZE;
682 /* 3.20 clear the buffer we use for proc display */
683 memset(qla1280_buffer, 0, PAGE_SIZE);
685 /* start building the print buffer */
686 bdp = &ql1280_board_tbl[ha->devnum];
687 size = sprintf(PROC_BUF,
688 "QLogic PCI to SCSI Adapter for ISP 1280/12160:\n"
689 " Firmware version: %2d.%02d.%02d, Driver version %s\n",
690 bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
691 QLA1280_VERSION);
693 len += size;
695 size = sprintf(PROC_BUF, "SCSI Host Adapter Information: %s\n",
696 bdp->bdName);
697 len += size;
698 size = sprintf(PROC_BUF, "Request Queue = 0x%p, Response Queue = 0x%p\n",
699 (void *)ha->request_dma, (void *)ha->response_dma);
700 len += size;
701 size = sprintf(PROC_BUF, "Request Queue count= 0x%x, Response "
702 "Queue count= 0x%x\n",
703 REQUEST_ENTRY_CNT, RESPONSE_ENTRY_CNT);
704 len += size;
705 size = sprintf(PROC_BUF, "Number of pending commands = 0x%lx\n",
706 ha->actthreads);
707 len += size;
708 size = sprintf(PROC_BUF, "Number of queued commands = 0x%lx\n",
709 ha->qthreads);
710 len += size;
711 size = sprintf(PROC_BUF, "Number of free request entries = %d\n",
712 ha->req_q_cnt);
713 len += size;
714 size = sprintf(PROC_BUF, "\n"); /* 1 */
715 len += size;
717 size = sprintf(PROC_BUF, "SCSI device Information:\n");
718 len += size;
719 /* scan for all equipment stats */
720 for (b = 0; b < MAX_BUSES; b++)
721 for (t = 0; t < MAX_TARGETS; t++) {
722 for (l = 0; l < MAX_LUNS; l++) {
723 up = LU_Q(ha, b, t, l);
724 if (up == NULL)
725 continue;
726 /* unused device/lun */
727 if (up->io_cnt == 0 || up->io_cnt < 2)
728 continue;
729 /* total reads since boot */
730 /* total writes since boot */
731 /* total requests since boot */
732 size = sprintf (PROC_BUF,
733 "(%2d:%2d:%2d): Total reqs %ld,",
734 b, t, l, up->io_cnt);
735 len += size;
736 /* current number of pending requests */
737 size = sprintf(PROC_BUF, " Pend reqs %d,",
738 up->q_outcnt);
739 len += size;
740 #if 0
741 /* avg response time */
742 size = sprintf(PROC_BUF, " Avg resp time %ld%%,",
743 (up->resp_time / up->io_cnt) *
744 100);
745 len += size;
747 /* avg active time */
748 size = sprintf(PROC_BUF,
749 " Avg active time %ld%%\n",
750 (up->act_time / up->io_cnt) * 100);
751 #else
752 size = sprintf(PROC_BUF, "\n");
753 #endif
754 len += size;
756 if (len >= qla1280_buffer_size)
757 break;
760 if (len >= qla1280_buffer_size) {
761 printk(KERN_WARNING
762 "qla1280: Overflow buffer in qla1280_proc.c\n");
765 if (offset > len - 1) {
766 free_page((unsigned long) qla1280_buffer);
767 qla1280_buffer = NULL;
768 qla1280_buffer_size = length = 0;
769 *start = NULL;
770 } else {
771 *start = &qla1280_buffer[offset]; /* Start of wanted data */
772 if (len - offset < length) {
773 length = len - offset;
776 return length;
777 #else
778 return 0;
779 #endif
782 /**************************************************************************
783 * qla1280_do_device_init
784 * This routine will register the device with the SCSI subsystem,
785 * initialize the host adapter structure and call the device init
786 * routines.
788 * Input:
789 * pdev - pointer to struct pci_dev for adapter
790 * template - pointer to SCSI template
791 * devnum - the device number
792 * bdp - pointer to struct _qlaboards
793 * num_hosts - the host number
795 * Returns:
796 * host - pointer to SCSI host structure
797 **************************************************************************/
798 struct Scsi_Host *
799 qla1280_do_device_init(struct pci_dev *pdev,
800 Scsi_Host_Template * template,
801 int devnum, struct qla_boards *bdp, int num_hosts)
803 struct Scsi_Host *host;
804 struct scsi_qla_host *ha;
805 struct device_reg *reg;
807 printk("qla1x160: Initializing ISP12160 on PCI bus %i, dev %i, irq %i\n",
808 pdev->bus->number, PCI_SLOT(pdev->devfn), pdev->irq);
810 host = scsi_register(template, sizeof(struct scsi_qla_host));
811 if (!host) {
812 printk(KERN_WARNING
813 "qla1280: Failed to register host, aborting.\n");
814 goto error;
817 scsi_set_pci_device(host, pdev);
818 ha = (struct scsi_qla_host *)host->hostdata;
819 /* Clear our data area */
820 memset(ha, 0, sizeof(struct scsi_qla_host));
821 /* Sanitize the information from PCI BIOS. */
822 host->irq = pdev->irq;
823 ha->pci_bus = pdev->bus->number;
824 ha->pci_device_fn = pdev->devfn;
825 ha->pdev = pdev;
826 ha->device_id = bdp->device_id;
827 ha->devnum = devnum; /* specifies microcode load address */
829 if (qla1280_mem_alloc(ha)) {
830 printk(KERN_INFO "qla1x160: Failed to get memory\n");
831 goto error;
834 ha->ports = bdp->numPorts;
835 /* following needed for all cases of OS versions */
836 ha->host = host;
837 ha->host_no = host->host_no;
839 host->can_queue = 0xfffff; /* unlimited */
840 host->cmd_per_lun = 1;
841 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
842 host->base = (unsigned char *)ha->mmpbase;
843 #else
844 host->base = (unsigned long)ha->mmpbase;
845 #endif
846 host->max_channel = bdp->numPorts - 1;
847 host->max_lun = MAX_LUNS - 1;
848 host->max_id = MAX_TARGETS;
849 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)
850 host->max_sectors = 1024;
851 #endif
853 ha->instance = num_hosts;
854 host->unique_id = ha->instance;
856 if (qla1280_pci_config(ha)) {
857 printk(KERN_INFO "qla1x160: Unable to configure PCI\n");
858 goto error_mem_alloced;
861 /* Disable ISP interrupts. */
862 qla1280_disable_intrs(ha);
864 /* Register the IRQ with Linux (sharable) */
865 if (request_irq(host->irq, qla1280_intr_handler, SA_SHIRQ,
866 "qla1280", ha)) {
867 printk("qla1280 : Failed to reserve interrupt %d already "
868 "in use\n", host->irq);
869 goto error_mem_alloced;
871 #if !MEMORY_MAPPED_IO
872 /* Register the I/O space with Linux */
873 if (check_region(host->io_port, 0xff)) {
874 printk("qla1280 : Failed to reserve i/o region 0x%04lx-0x%04lx"
875 " already in use\n",
876 host->io_port, host->io_port + 0xff);
877 free_irq(host->irq, ha);
878 goto error_mem_alloced;
881 request_region(host->io_port, 0xff, "qla1280");
882 #endif
884 reg = ha->iobase;
886 /* load the F/W, read paramaters, and init the H/W */
887 if (qla1280_initialize_adapter(ha)) {
888 printk(KERN_INFO "qla1x160:Failed to initialize adapter\n");
889 goto error_mem_alloced;
892 /* set our host ID (need to do something about our two IDs) */
893 host->this_id = ha->bus_settings[0].id;
895 return host;
897 error_mem_alloced:
898 qla1280_mem_free(ha);
900 error:
901 if (host) {
902 scsi_unregister(host);
904 return NULL;
907 /**************************************************************************
908 * qla1280_detect
909 * This routine will probe for Qlogic 1280 SCSI host adapters.
910 * It returns the number of host adapters of a particular
911 * type that were found. It also initialize all data necessary for
912 * the driver. It is passed-in the host number, so that it
913 * knows where its first entry is in the scsi_hosts[] array.
915 * Input:
916 * template - pointer to SCSI template
918 * Returns:
919 * num - number of host adapters found.
920 **************************************************************************/
922 qla1280_detect(Scsi_Host_Template * template)
924 struct pci_dev *pdev = NULL;
925 struct Scsi_Host *host;
926 struct scsi_qla_host *ha, *cur_ha;
927 struct qla_boards *bdp;
928 uint16_t subsys_vendor, subsys_device;
929 int num_hosts = 0;
930 int devnum = 0;
932 ENTER("qla1280_detect");
934 if (sizeof(srb_t) > sizeof(Scsi_Pointer)) {
935 printk(KERN_WARNING
936 "qla1280_detect: [WARNING] srb_t too big\n");
937 return 0;
939 #ifdef MODULE
940 dprintk(1, "DEBUG: qla1280_detect starts at address = %p\n",
941 qla1280_detect);
943 * If we are called as a module, the qla1280 pointer may not be null
944 * and it would point to our bootup string, just like on the lilo
945 * command line. IF not NULL, then process this config string with
946 * qla1280_setup
948 * Boot time Options
949 * To add options at boot time add a line to your lilo.conf file like:
950 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
951 * which will result in the first four devices on the first two
952 * controllers being set to a tagged queue depth of 32.
954 if (options)
955 qla1280_setup(options, NULL);
957 printk(KERN_WARNING
958 "qla1280: Please read the file /usr/src/linux/Documentation"
959 "/scsi/qla1280.txt\n"
960 "qla1280: to see the proper way to specify options to the qla1280 "
961 "module\n"
962 "qla1280: Specifically, don't use any commas when passing "
963 "arguments to\n"
964 "qla1280: insmod or else it might trash certain memory areas.\n");
965 #endif
967 if (!pci_present()) {
968 printk(KERN_INFO "scsi: PCI not present\n");
969 return 0;
972 bdp = &ql1280_board_tbl[0];
973 qla1280_hostlist = NULL;
974 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
975 template->proc_dir = &proc_scsi_qla1280;
976 #else
977 template->proc_name = "qla1280";
978 #endif
980 /* 3.20 */
981 /* First Initialize QLA12160 on PCI Bus 1 Dev 2 */
982 while ((pdev = pci_find_subsys(PCI_VENDOR_ID_QLOGIC, bdp->device_id,
983 PCI_ANY_ID, PCI_ANY_ID, pdev))) {
985 /* find QLA12160 device on PCI bus=1 slot=2 */
986 if ((pdev->bus->number != 1) || (PCI_SLOT(pdev->devfn) != 2))
987 continue;
989 /* Bypass all AMI SUBSYS VENDOR IDs */
990 if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
991 printk(KERN_INFO
992 "qla1x160: Skip AMI SubSys Vendor ID Chip\n");
993 continue;
996 if (pci_enable_device(pdev))
997 goto find_devices;
999 host = qla1280_do_device_init(pdev, template, devnum,
1000 bdp, num_hosts);
1001 if (!host)
1002 continue;
1003 ha = (struct scsi_qla_host *)host->hostdata;
1005 /* this preferred device will always be the first one found */
1006 cur_ha = qla1280_hostlist = ha;
1007 num_hosts++;
1010 find_devices:
1012 pdev = NULL;
1013 /* Try and find each different type of adapter we support */
1014 for (devnum = 0; bdp->device_id != 0 && devnum < NUM_OF_ISP_DEVICES;
1015 devnum++, bdp++) {
1016 /* PCI_SUBSYSTEM_IDS supported */
1017 while ((pdev = pci_find_subsys(PCI_VENDOR_ID_QLOGIC,
1018 bdp->device_id, PCI_ANY_ID,
1019 PCI_ANY_ID, pdev))) {
1020 if (pci_enable_device(pdev))
1021 continue;
1022 /* found an adapter */
1023 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,18)
1024 subsys_vendor = pdev->subsystem_vendor;
1025 subsys_device = pdev->subsystem_device;
1026 #else
1027 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID,
1028 &subsys_vendor);
1029 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID,
1030 &subsys_device);
1031 #endif
1033 * skip QLA12160 already initialized on
1034 * PCI Bus 1 Dev 2 since we already initialized
1035 * and presented it
1037 if ((bdp->device_id == PCI_DEVICE_ID_QLOGIC_ISP12160)&&
1038 (pdev->bus->number == 1) &&
1039 (PCI_SLOT(pdev->devfn) == 2))
1040 continue;
1042 /* Bypass all AMI SUBSYS VENDOR IDs */
1043 if (subsys_vendor == PCI_VENDOR_ID_AMI) {
1044 printk(KERN_INFO
1045 "qla1x160: Skip AMI SubSys Vendor ID Chip\n");
1046 continue;
1048 printk(KERN_INFO
1049 "qla1x160: Supported Device Found VID=%x "
1050 "DID=%x SSVID=%x SSDID=%x\n", pdev->vendor,
1051 pdev->device, subsys_vendor, subsys_device);
1053 host = qla1280_do_device_init(pdev, template,
1054 devnum, bdp, num_hosts);
1055 if (!host)
1056 continue;
1057 ha = (struct scsi_qla_host *)host->hostdata;
1059 if (qla1280_hostlist == NULL) {
1060 cur_ha = qla1280_hostlist = ha;
1061 } else {
1062 cur_ha = qla1280_hostlist;
1063 while (cur_ha->next != NULL)
1064 cur_ha = cur_ha->next;
1065 cur_ha->next = ha;
1067 num_hosts++;
1068 } /* end of WHILE */
1069 } /* end of FOR */
1071 LEAVE("qla1280_detect");
1072 return num_hosts;
1075 /**************************************************************************
1076 * qla1280_release
1077 * Free the passed in Scsi_Host memory structures prior to unloading the
1078 * module.
1079 **************************************************************************/
1081 qla1280_release(struct Scsi_Host *host)
1083 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
1085 ENTER("qla1280_release");
1087 if (!ha->flags.online)
1088 return 0;
1090 /* turn-off interrupts on the card */
1091 WRT_REG_WORD(&ha->iobase->ictrl, 0);
1093 /* Detach interrupts */
1094 if (host->irq)
1095 free_irq(host->irq, ha);
1097 #if MEMORY_MAPPED_IO
1098 if (ha->mmpbase)
1099 iounmap((void *)(((unsigned long) ha->mmpbase) & PAGE_MASK));
1100 #else
1101 /* release io space registers */
1102 if (host->io_port)
1103 release_region(host->io_port, 0xff);
1104 #endif /* MEMORY_MAPPED_IO */
1106 qla1280_mem_free(ha);
1108 ENTER("qla1280_release");
1109 return 0;
1112 /**************************************************************************
1113 * qla1280_info
1114 * Return a string describing the driver.
1115 **************************************************************************/
1116 const char *
1117 qla1280_info(struct Scsi_Host *host)
1119 static char qla1280_scsi_name_buffer[125];
1120 char *bp;
1121 struct scsi_qla_host *ha;
1122 struct qla_boards *bdp;
1124 bp = &qla1280_scsi_name_buffer[0];
1125 ha = (struct scsi_qla_host *)host->hostdata;
1126 bdp = &ql1280_board_tbl[ha->devnum];
1127 memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
1128 sprintf (bp,
1129 "QLogic %s PCI to SCSI Host Adapter: bus %d device %d irq %d\n"
1130 " Firmware version: %2d.%02d.%02d, Driver version %s",
1131 &bdp->bdName[0], ha->pci_bus, (ha->pci_device_fn & 0xf8) >> 3,
1132 host->irq, bdp->fwver[0], bdp->fwver[1], bdp->fwver[2],
1133 QLA1280_VERSION);
1134 return bp;
1137 /**************************************************************************
1138 * qla1200_queuecommand
1139 * Queue a command to the controller.
1141 * Note:
1142 * The mid-level driver tries to ensures that queuecommand never gets invoked
1143 * concurrently with itself or the interrupt handler (although the
1144 * interrupt handler may call this routine as part of request-completion
1145 * handling). Unfortunely, it sometimes calls the scheduler in interrupt
1146 * context which is a big NO! NO!.
1147 **************************************************************************/
1149 qla1280_queuecommand(Scsi_Cmnd * cmd, void (*fn) (Scsi_Cmnd *))
1151 struct scsi_qla_host *ha;
1152 srb_t *sp;
1153 struct Scsi_Host *host;
1154 int bus, target, lun;
1155 scsi_lu_t *q;
1157 /*ENTER("qla1280_queuecommand");
1160 host = cmd->host;
1161 ha = (struct scsi_qla_host *)host->hostdata;
1163 /* send command to adapter */
1164 sp = (srb_t *)CMD_SP(cmd);
1165 sp->cmd = cmd;
1166 cmd->scsi_done = fn;
1167 if (cmd->flags == 0) { /* new command */
1168 sp->flags = 0;
1171 qla1280_print_scsi_cmd(5, cmd);
1173 /* Generate LU queue on bus, target, LUN */
1174 bus = SCSI_BUS_32(cmd);
1175 target = SCSI_TCN_32(cmd);
1176 lun = SCSI_LUN_32(cmd);
1177 if ((q = LU_Q(ha, bus, target, lun)) == NULL) {
1178 if ((q = (scsi_lu_t *)kmalloc(sizeof(struct scsi_lu),
1179 GFP_ATOMIC))) {
1180 LU_Q(ha, bus, target, lun) = q;
1181 memset(q, 0, sizeof(struct scsi_lu));
1182 dprintk(1, "Allocate new device queue 0x%p\n",
1183 (void *)q);
1184 } else {
1185 CMD_RESULT(cmd) = DID_BUS_BUSY << 16;
1186 qla1280_done_q_put(sp, &ha->done_q_first,
1187 &ha->done_q_last);
1188 /* 3.22 */
1189 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) /* 3.22 */
1190 schedule_work(&ha->run_qla_bh);
1191 #else /* 3.22 */
1192 schedule_work(&ha->run_qla_bh); /* 3.22 */
1193 #endif /* 3.22 */
1194 return 0;
1197 /* Set an invalid handle until we issue the command to ISP */
1198 /* then we will set the real handle value. */
1199 CMD_HANDLE(cmd) = (unsigned char *)INVALID_HANDLE;
1201 /* add the command to our queue */
1202 ha->qthreads++;
1203 qla1280_putq_t(q, sp);
1205 dprintk(1, "qla1280_QC: t=%x CDB=%x I/OSize=0x%x haQueueCount=0x%lx\n",
1206 target, cmd->cmnd[0], cmd->request_bufflen, ha->qthreads);
1208 /* send command to adapter */
1209 if (q->q_outcnt == 0)
1210 qla1280_restart_queues(ha);
1212 /*LEAVE("qla1280_queuecommand"); */
1213 return 0;
1216 /**************************************************************************
1217 * qla1200_abort
1218 * Abort the speciifed SCSI command(s).
1219 **************************************************************************/
1221 qla1280_abort(Scsi_Cmnd * cmd)
1223 struct scsi_qla_host *ha;
1224 srb_t *sp;
1225 struct Scsi_Host *host;
1226 unsigned int bus, target, lun;
1227 scsi_lu_t *q;
1228 int return_status = SCSI_ABORT_SUCCESS;
1229 int found = 0;
1230 int i;
1231 unsigned char *handle;
1232 u16 data;
1234 ENTER("qla1280_abort");
1235 ha = (struct scsi_qla_host *)cmd->host->hostdata;
1236 host = cmd->host;
1238 /* Get the SCSI request ptr */
1239 sp = (srb_t *)CMD_SP(cmd);
1240 handle = CMD_HANDLE(cmd);
1241 if (qla1280_verbose)
1242 printk(KERN_ERR "scsi(%li): ABORT Command=0x%p, handle=0x%p\n",
1243 ha->host_no, (void *) cmd, (void *) handle);
1245 /* Check for pending interrupts. */
1246 if (handle == NULL) {
1247 /* we never got this command */
1248 printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
1249 return SCSI_ABORT_NOT_RUNNING; /* no action - we don't have command */
1251 data = qla1280_debounce_register(&ha->iobase->istatus);
1253 * The io_request_lock is held when the reset handler is called, hence
1254 * the interrupt handler cannot be running in parallel as it also
1255 * grabs the lock. No reason to play funny games with set_bit() in
1256 * order to test for interrupt handler entry as the driver used to
1257 * do here.
1258 * /Jes
1260 if (data & RISC_INT) {
1261 /* put any pending command in done queue */
1262 qla1280_isr(ha, &ha->done_q_first, &ha->done_q_last);
1266 * This seems unnecessary, it's not used below! / Jes
1268 #ifdef UNUSED
1269 handle = CMD_HANDLE(cmd);
1270 #endif
1272 /* Generate LU queue on bus, target, LUN */
1273 bus = SCSI_BUS_32(cmd);
1274 target = SCSI_TCN_32(cmd);
1275 lun = SCSI_LUN_32(cmd);
1276 if ((q = LU_Q(ha, bus, target, lun)) == NULL) {
1277 /* No lun queue -- command must not be active */
1278 printk(KERN_WARNING "qla1280 (%d:%d:%d): No LUN queue for the "
1279 "specified device\n", bus, target, lun);
1280 return SCSI_ABORT_NOT_RUNNING; /* no action - we don't have command */
1282 #if AUTO_ESCALATE_ABORT
1283 if ((sp->flags & SRB_ABORTED)) {
1284 dprintk(1, "qla1280_abort: Abort escalayted - returning "
1285 "SCSI_ABORT_SNOOZE.\n");
1286 return SCSI_ABORT_SNOOZE;
1288 #endif
1290 if ((sp->flags & SRB_ABORT_PENDING)) {
1291 if (qla1280_verbose)
1292 printk(KERN_WARNING
1293 "scsi(): Command has a pending abort "
1294 "message - ABORT_PENDING.\n");
1296 return SCSI_ABORT_PENDING;
1298 #if STOP_ON_ABORT
1299 printk(KERN_WARNING "Scsi layer issued a ABORT command= 0x%p\n", cmd);
1300 qla1280_print_scsi_cmd(2, cmd);
1301 #endif
1304 * Normally, would would need to search our queue for the specified command
1305 * but; since our sp contains the cmd ptr, we can just remove it from our
1306 * LUN queue.
1308 if (!(sp->flags & SRB_SENT)) {
1309 found++;
1310 if (qla1280_verbose)
1311 printk(KERN_WARNING
1312 "scsi(): Command returned from queue "
1313 "aborted.\n");
1315 /* Remove srb from SCSI LU queue. */
1316 qla1280_removeq(q, sp);
1317 sp->flags |= SRB_ABORTED;
1318 CMD_RESULT(cmd) = DID_ABORT << 16;
1319 qla1280_done_q_put(sp, &ha->done_q_first, &ha->done_q_last);
1320 return_status = SCSI_ABORT_SUCCESS;
1321 } else { /* find the command in our active list */
1322 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
1323 if (sp == ha->outstanding_cmds[i]) {
1324 found++;
1325 dprintk(1,
1326 "qla1280: RISC aborting command.\n");
1327 qla1280_abort_command(ha, sp);
1328 return_status = SCSI_ABORT_PENDING;
1329 break;
1334 #if STOP_ON_ABORT
1335 qla1280_panic("qla1280_abort", ha->host);
1336 #endif
1337 if (found == 0)
1338 return_status = SCSI_ABORT_NOT_RUNNING; /* no action - we don't have command */
1340 dprintk(1, "qla1280_abort: Aborted status returned = 0x%x.\n",
1341 return_status);
1343 if (ha->done_q_first)
1344 qla1280_done(ha, &ha->done_q_first, &ha->done_q_last);
1345 if (found)
1346 qla1280_restart_queues(ha);
1348 LEAVE("qla1280_abort");
1349 return return_status;
1353 qla1280_new_abort(Scsi_Cmnd * cmd)
1355 struct scsi_qla_host *ha;
1356 srb_t *sp;
1357 struct Scsi_Host *host;
1358 int bus, target, lun;
1359 scsi_lu_t *q;
1360 unsigned long cpu_flags;
1361 int return_status = SCSI_ABORT_SUCCESS;
1362 int found = 0;
1363 int i;
1364 unsigned char *handle;
1365 u16 data;
1367 ENTER("qla1280_abort");
1368 host = cmd->host;
1369 ha = (struct scsi_qla_host *)host->hostdata;
1371 /* Get the SCSI request ptr */
1372 sp = (srb_t *) CMD_SP(cmd);
1373 handle = CMD_HANDLE(cmd);
1374 if (qla1280_verbose)
1375 printk(KERN_ERR "scsi(%li): ABORT Command=0x%p, handle=0x%p\n",
1376 ha->host_no, cmd, handle);
1378 /* Check for pending interrupts. */
1379 if (handle == NULL) {
1380 /* we never got this command */
1381 printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
1382 return SUCCESS; /* no action - we don't have command */
1385 spin_lock_irqsave (ha->host->host_lock, cpu_flags);
1386 data = qla1280_debounce_register(&ha->iobase->istatus);
1388 * We grab the host lock in the interrupt handler to
1389 * prevent racing here.
1391 * Then again, running the interrupt handler from here is somewhat
1392 * questionable.
1393 * /Jes
1395 if (data & RISC_INT) {
1396 /* put any pending command in done queue */
1397 qla1280_isr(ha, &ha->done_q_first, &ha->done_q_last);
1400 /* Generate LU queue on bus, target, LUN */
1401 bus = SCSI_BUS_32(cmd);
1402 target = SCSI_TCN_32(cmd);
1403 lun = SCSI_LUN_32(cmd);
1404 if ((q = LU_Q(ha, bus, target, lun)) == NULL) {
1405 /* No lun queue -- command must not be active */
1406 printk(KERN_WARNING "qla1280 (%d:%d:%d): No LUN queue for the "
1407 "specified device\n", bus, target, lun);
1408 return_status = SUCCESS; /* no action - we don't have command */
1409 goto out;
1412 if ((sp->flags & SRB_ABORT_PENDING)) {
1413 if (qla1280_verbose)
1414 printk(KERN_WARNING
1415 "scsi(): Command has a pending abort "
1416 "message - ABORT_PENDING.\n");
1418 return_status = SCSI_ABORT_PENDING;
1419 goto out;
1421 #if STOP_ON_ABORT
1422 printk(KERN_WARNING "Scsi layer issued a ABORT command= 0x%p\n", cmd);
1423 qla1280_print_scsi_cmd(2, cmd);
1424 #endif
1427 * Normally, would would need to search our queue for the specified command
1428 * but; since our sp contains the cmd ptr, we can just remove it from our
1429 * LUN queue.
1431 if (!(sp->flags & SRB_SENT)) {
1432 found++;
1433 if (qla1280_verbose)
1434 printk(KERN_WARNING
1435 "scsi(): Command returned from queue "
1436 "aborted.\n");
1438 /* Remove srb from SCSI LU queue. */
1439 qla1280_removeq(q, sp);
1440 sp->flags |= SRB_ABORTED;
1441 CMD_RESULT(cmd) = DID_ABORT << 16;
1442 qla1280_done_q_put(sp, &ha->done_q_first, &ha->done_q_last);
1443 return_status = SUCCESS;
1444 } else { /* find the command in our active list */
1445 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
1446 if (sp == ha->outstanding_cmds[i]) {
1447 found++;
1448 dprintk(1,
1449 "qla1280: RISC aborting command.\n");
1450 qla1280_abort_command(ha, sp);
1451 return_status = SCSI_ABORT_PENDING;
1452 break;
1457 #if STOP_ON_ABORT
1458 qla1280_panic("qla1280_abort", ha->host);
1459 #endif
1460 if (found == 0)
1461 return_status = SUCCESS; /* no action - we don't have the command */
1463 dprintk(1, "qla1280_abort: Aborted status returned = 0x%x.\n",
1464 return_status);
1466 if (ha->done_q_first)
1467 qla1280_done(ha, &ha->done_q_first, &ha->done_q_last);
1468 if (found)
1469 qla1280_restart_queues(ha);
1471 out:
1472 spin_unlock_irqrestore(ha->host->host_lock, cpu_flags);
1474 LEAVE("qla1280_abort");
1475 return return_status;
1478 /**************************************************************************
1479 * qla1200_reset
1480 * The reset function will reset the SCSI bus and abort any executing
1481 * commands.
1483 * Input:
1484 * cmd = Linux SCSI command packet of the command that cause the
1485 * bus reset.
1486 * flags = SCSI bus reset option flags (see scsi.h)
1488 * Returns:
1489 * DID_RESET in cmd.host_byte of aborted command(s)
1491 * Note:
1492 * Resetting the bus always succeeds - is has to, otherwise the
1493 * kernel will panic! Try a surgical technique - sending a BUS
1494 * DEVICE RESET message - on the offending target before pulling
1495 * the SCSI bus reset line.
1496 **************************************************************************/
1498 qla1280_reset(Scsi_Cmnd * cmd, unsigned int flags)
1500 struct scsi_qla_host *ha;
1501 int bus, target, lun;
1502 srb_t *sp;
1503 typedef enum {
1504 ABORT_DEVICE = 1,
1505 DEVICE_RESET = 2,
1506 BUS_RESET = 3,
1507 ADAPTER_RESET = 4,
1508 RESET_DELAYED = 5,
1509 FAIL = 6
1510 } action_t;
1511 action_t action = ADAPTER_RESET;
1512 u16 data;
1513 scsi_lu_t *q;
1514 int result;
1516 ENTER("qla1280_reset");
1517 if (qla1280_verbose)
1518 printk(KERN_INFO "scsi(): Resetting Cmnd=0x%p, Handle=0x%p, "
1519 "flags=0x%x\n", cmd, CMD_HANDLE(cmd), flags);
1520 if (cmd == NULL) {
1521 printk(KERN_WARNING
1522 "(scsi?:?:?:?) Reset called with NULL Scsi_Cmnd "
1523 "pointer, failing.\n");
1524 return SCSI_RESET_SNOOZE;
1526 ha = (struct scsi_qla_host *)cmd->host->hostdata;
1527 sp = (srb_t *)CMD_SP(cmd);
1529 #if STOP_ON_RESET
1530 qla1280_panic("qla1280_reset", ha->host);
1531 #endif
1533 /* Check for pending interrupts. */
1534 data = qla1280_debounce_register(&ha->iobase->istatus);
1536 * The io_request_lock is held when the reset handler is called, hence
1537 * the interrupt handler cannot be running in parallel as it also
1538 * grabs the lock. /Jes
1540 if (data & RISC_INT)
1541 qla1280_isr(ha, &ha->done_q_first, &ha->done_q_last);
1544 * Determine the suggested action that the mid-level driver wants
1545 * us to perform.
1547 if (CMD_HANDLE(cmd) == NULL) {
1549 * if mid-level driver called reset with a orphan SCSI_Cmnd
1550 * (i.e. a command that's not pending), so perform the
1551 * function specified.
1553 if (flags & SCSI_RESET_SUGGEST_HOST_RESET)
1554 action = ADAPTER_RESET;
1555 else
1556 action = BUS_RESET;
1557 } else {
1559 * Mid-level driver has called reset with this SCSI_Cmnd and
1560 * its pending.
1562 if (flags & SCSI_RESET_SUGGEST_HOST_RESET)
1563 action = ADAPTER_RESET;
1564 else if (flags & SCSI_RESET_SUGGEST_BUS_RESET)
1565 action = BUS_RESET;
1566 else
1567 action = DEVICE_RESET;
1570 bus = SCSI_BUS_32(cmd);
1571 target = SCSI_TCN_32(cmd);
1572 lun = SCSI_LUN_32(cmd);
1573 q = LU_Q(ha, bus, target, lun);
1575 #if AUTO_ESCALATE_RESET
1576 if ((action & DEVICE_RESET) && (q->q_flag & QLA1280_QRESET)) {
1577 printk(KERN_INFO
1578 "qla1280(%ld): Bus device reset already sent to "
1579 "device, escalating.\n", ha->host_no);
1580 action = BUS_RESET;
1582 if ((action & DEVICE_RESET) && (sp->flags & SRB_ABORT_PENDING)) {
1583 printk(KERN_INFO
1584 "qla1280(%ld):Have already attempted to reach "
1585 "device with abort device\n", ha->host_no);
1586 printk(KERN_INFO "qla1280(%ld):message, will escalate to BUS "
1587 "RESET.\n", ha->host_no);
1588 action = BUS_RESET;
1590 #endif
1593 * By this point, we want to already know what we are going to do,
1594 * so we only need to perform the course of action.
1596 result = SCSI_RESET_ERROR;
1597 switch (action) {
1598 case FAIL:
1599 break;
1601 case RESET_DELAYED:
1602 result = SCSI_RESET_PENDING;
1603 break;
1605 case ABORT_DEVICE:
1606 ha->flags.in_reset = TRUE;
1607 if (qla1280_verbose)
1608 printk(KERN_INFO
1609 "scsi(%ld:%d:%d:%d): Queueing abort device "
1610 "command.\n", ha->host_no, bus, target, lun);
1611 qla1280_abort_queue_single(ha, bus, target, lun, DID_ABORT);
1612 if (qla1280_abort_device(ha, bus, target, lun) == 0)
1613 result = SCSI_RESET_PENDING;
1614 break;
1616 case DEVICE_RESET:
1617 if (qla1280_verbose)
1618 printk(KERN_INFO
1619 "scsi(%ld:%d:%d:%d): Queueing device reset "
1620 "command.\n", ha->host_no, bus, target, lun);
1621 ha->flags.in_reset = TRUE;
1622 for (lun = 0; lun < MAX_LUNS; lun++)
1623 qla1280_abort_queue_single(ha, bus, target, lun,
1624 DID_ABORT);
1625 if (qla1280_device_reset(ha, bus, target) == 0)
1626 result = SCSI_RESET_PENDING;
1627 q->q_flag |= QLA1280_QRESET;
1628 break;
1630 case BUS_RESET:
1631 if (qla1280_verbose)
1632 printk(KERN_INFO "qla1280(%ld:%d:%d:%d): Issuing BUS "
1633 "DEVICE RESET.\n", ha->host_no, bus, target,
1634 lun);
1635 ha->flags.in_reset = TRUE;
1636 for (target = 0; target < MAX_TARGETS; target++)
1637 for (lun = 0; lun < MAX_LUNS; lun++)
1638 qla1280_abort_queue_single(ha, bus, target,
1639 lun, DID_RESET);
1640 qla1280_bus_reset(ha, bus);
1642 * The bus reset routine returns all the outstanding commands
1643 * back with "DID_RESET" in the status field after a short
1644 * delay by the firmware. If the mid-level time out the SCSI
1645 * reset before our delay we may need to ignore it.
1647 /* result = SCSI_RESET_PENDING | SCSI_RESET_BUS_RESET; */
1648 result = SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET;
1650 * Wheeeee!!!
1652 mdelay(4 * 1000);
1653 barrier();
1654 if (flags & SCSI_RESET_SYNCHRONOUS) {
1655 CMD_RESULT(cmd) = DID_BUS_BUSY << 16;
1656 (*(cmd)->scsi_done)(cmd);
1658 /* ha->reset_start = jiffies; */
1659 break;
1661 case ADAPTER_RESET:
1662 default:
1663 if (qla1280_verbose) {
1664 printk(KERN_INFO
1665 "scsi(%ld:%d:%d:%d): Issued an ADAPTER "
1666 "RESET.\n", ha->host_no, bus, target, lun);
1667 printk(KERN_INFO
1668 "scsi(%ld:%d:%d:%d): I/O processing will "
1669 "continue automatically.\n", ha->host_no, bus,
1670 target, lun);
1672 ha->flags.reset_active = TRUE;
1674 * We restarted all of the commands automatically, so the
1675 * mid-level code can expect completions momentitarily.
1677 if (qla1280_abort_isp(ha) == 0)
1678 result = SCSI_RESET_SUCCESS | SCSI_RESET_HOST_RESET;
1680 ha->flags.reset_active = FALSE;
1683 if (ha->done_q_first)
1684 qla1280_done(ha, &ha->done_q_first, &ha->done_q_last);
1685 qla1280_restart_queues(ha);
1686 ha->flags.in_reset = FALSE;
1688 dprintk(1, "RESET returning %d\n", result);
1690 LEAVE("qla1280_reset");
1691 return result;
1694 /**************************************************************************
1695 * qla1280_biosparam
1696 * Return the disk geometry for the given SCSI device.
1697 **************************************************************************/
1699 qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1700 sector_t capacity, int geom[])
1702 int heads, sectors, cylinders;
1704 heads = 64;
1705 sectors = 32;
1706 cylinders = (unsigned long)capacity / (heads * sectors);
1707 if (cylinders > 1024) {
1708 heads = 255;
1709 sectors = 63;
1710 cylinders = (unsigned long)capacity / (heads * sectors);
1711 /* if (cylinders > 1023)
1712 cylinders = 1023; */
1715 geom[0] = heads;
1716 geom[1] = sectors;
1717 geom[2] = cylinders;
1719 return 0;
1722 /**************************************************************************
1723 * qla1280_intr_handler
1724 * Handles the H/W interrupt
1725 **************************************************************************/
1726 void
1727 qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1729 struct scsi_qla_host *ha;
1730 struct device_reg *reg;
1731 u16 data;
1733 ENTER_INTR ("qla1280_intr_handler");
1734 ha = (struct scsi_qla_host *)dev_id;
1736 spin_lock(ha->host->host_lock);
1738 ha->isr_count++;
1739 reg = ha->iobase;
1741 WRT_REG_WORD(&reg->ictrl, 0); /* disable our interrupt. */
1743 data = qla1280_debounce_register(&reg->istatus);
1744 /* Check for pending interrupts. */
1745 if (data & RISC_INT) {
1746 qla1280_isr(ha, &ha->done_q_first, &ha->done_q_last);
1747 } else {
1748 /* spurious interrupts can happen legally */
1749 dprintk(1, "scsi(%ld): Spurious interrupt - ignoring\n",
1750 ha->host_no);
1753 if (ha->done_q_first)
1754 qla1280_done(ha, &ha->done_q_first, &ha->done_q_last);
1756 spin_unlock(ha->host->host_lock);
1758 /* enable our interrupt. */
1759 WRT_REG_WORD(&reg->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1761 LEAVE_INTR("qla1280_intr_handler");
1764 /**************************************************************************
1765 * qla1280_do_dpc
1767 * Description:
1768 * This routine is a task that is schedule by the interrupt handler
1769 * to perform the background processing for interrupts. We put it
1770 * on a task queue that is consumed whenever the scheduler runs; that's
1771 * so you can do anything (i.e. put the process to sleep etc). In fact, the
1772 * mid-level tries to sleep when it reaches the driver threshold
1773 * "host->can_queue". This can cause a panic if we were in our interrupt
1774 * code .
1775 **************************************************************************/
1776 void
1777 qla1280_do_dpc(void *p)
1779 struct scsi_qla_host *ha = (struct scsi_qla_host *) p;
1780 unsigned long cpu_flags;
1782 spin_lock_irqsave(ha->host->host_lock, cpu_flags);
1784 if (ha->flags.isp_abort_needed)
1785 qla1280_abort_isp(ha);
1787 if (ha->flags.reset_marker)
1788 qla1280_rst_aen(ha);
1790 if (ha->done_q_first)
1791 qla1280_done(ha, &ha->done_q_first, &ha->done_q_last);
1793 spin_unlock_irqrestore(ha->host->host_lock, cpu_flags);
1796 /**************************************************************************
1797 * qla1280_slave_attach
1799 * Description:
1800 * Determines the queue depth for a given device. There are two ways
1801 * a queue depth can be obtained for a tagged queueing device. One
1802 * way is the default queue depth which is determined by whether
1803 * If it is defined, then it is used
1804 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1805 * default queue depth (dependent on the number of hardware SCBs).
1806 **************************************************************************/
1807 static int
1808 qla1280_slave_attach(Scsi_Device * device)
1810 struct scsi_qla_host *p = (struct scsi_qla_host *)device->host->hostdata;
1811 int bus = device->channel;
1812 int target = device->id;
1814 if (qla1280_check_for_dead_scsi_bus(p, bus))
1815 return 1;
1816 if (device->tagged_supported &&
1817 (p->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1818 scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
1819 p->bus_settings[bus].hiwat);
1820 /* device->queue_depth = 20; */
1821 printk(KERN_INFO "scsi(%li:%d:%d:%d): Enabled tagged queuing, "
1822 "queue depth %d.\n", p->host_no, device->channel,
1823 device->id, device->lun, device->new_queue_depth);
1824 } else {
1825 scsi_adjust_queue_depth(device, 0 /* TCQ off */, 3);
1827 qla12160_get_target_parameters(p, bus, target, device->lun);
1828 return 0;
1832 * Driver Support Routines
1836 * qla1280_done
1837 * Process completed commands.
1839 * Input:
1840 * ha = adapter block pointer.
1841 * done_q_first = done queue first pointer.
1842 * done_q_last = done queue last pointer.
1844 static void
1845 qla1280_done(struct scsi_qla_host *ha, srb_t ** done_q_first,
1846 srb_t ** done_q_last)
1848 srb_t *sp;
1849 scsi_lu_t *q;
1850 int bus, target, lun;
1851 Scsi_Cmnd *cmd;
1853 ENTER("qla1280_done");
1855 while (*done_q_first != NULL) {
1856 /* remove command from done list */
1857 sp = *done_q_first;
1858 if (!(*done_q_first = sp->s_next))
1859 *done_q_last = NULL;
1860 else
1861 (*done_q_first)->s_prev = NULL;
1863 cmd = sp->cmd;
1864 bus = SCSI_BUS_32(cmd);
1865 target = SCSI_TCN_32(cmd);
1866 lun = SCSI_LUN_32(cmd);
1867 q = LU_Q(ha, bus, target, lun);
1869 /* Decrement outstanding commands on device. */
1870 if (q->q_outcnt)
1871 q->q_outcnt--;
1872 if (q->q_outcnt < ha->bus_settings[bus].hiwat) {
1873 q->q_flag &= ~QLA1280_QBUSY;
1876 q->io_cnt++;
1877 if (sp->dir & BIT_5)
1878 q->r_cnt++;
1879 else
1880 q->w_cnt++;
1882 switch ((CMD_RESULT(cmd) >> 16)) {
1883 case DID_RESET:
1884 q->q_flag &= ~QLA1280_QRESET;
1885 /* Issue marker command. */
1886 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
1887 break;
1888 case DID_ABORT:
1889 sp->flags &= ~SRB_ABORT_PENDING;
1890 sp->flags |= SRB_ABORTED;
1891 if (sp->flags & SRB_TIMEOUT)
1892 CMD_RESULT(sp->cmd) = DID_TIME_OUT << 16;
1893 break;
1894 default:
1895 break;
1898 /* 3.13 64 and 32 bit */
1899 /* Release memory used for this I/O */
1900 if (cmd->use_sg) {
1901 dprintk(1, "S/G unmap_sg cmd=%p\n", cmd);
1903 pci_unmap_sg(ha->pdev, cmd->request_buffer,
1904 cmd->use_sg,
1905 scsi_to_pci_dma_dir(cmd->sc_data_direction));
1906 } else if (cmd->request_bufflen) {
1907 /*dprintk(1, "No S/G unmap_single cmd=%x saved_dma_handle=%lx\n",
1908 cmd, sp->saved_dma_handle); */
1910 pci_unmap_single(ha->pdev, sp->saved_dma_handle,
1911 cmd->request_bufflen,
1912 scsi_to_pci_dma_dir(cmd->sc_data_direction));
1915 /* Call the mid-level driver interrupt handler */
1916 CMD_HANDLE(sp->cmd) = NULL;
1917 ha->actthreads--;
1919 (*(cmd)->scsi_done)(cmd);
1921 qla1280_next(ha, q, bus);
1923 LEAVE("qla1280_done");
1927 * Translates a ISP error to a Linux SCSI error
1929 static int
1930 qla1280_return_status(sts_entry_t * sts, Scsi_Cmnd * cp)
1932 int host_status = DID_ERROR;
1933 #if DEBUG_QLA1280_INTR
1934 static char *reason[] = {
1935 "DID_OK",
1936 "DID_NO_CONNECT",
1937 "DID_BUS_BUSY",
1938 "DID_TIME_OUT",
1939 "DID_BAD_TARGET",
1940 "DID_ABORT",
1941 "DID_PARITY",
1942 "DID_ERROR",
1943 "DID_RESET",
1944 "DID_BAD_INTR"
1946 #endif /* DEBUG_QLA1280_INTR */
1948 ENTER("qla1280_return_status");
1950 #if DEBUG_QLA1280_INTR
1952 dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
1953 sts->comp_status);
1955 #endif
1956 switch (sts->comp_status) {
1957 case CS_COMPLETE:
1958 host_status = DID_OK;
1959 break;
1961 case CS_INCOMPLETE:
1962 if (!(sts->state_flags & SF_GOT_BUS))
1963 host_status = DID_NO_CONNECT;
1964 else if (!(sts->state_flags & SF_GOT_TARGET))
1965 host_status = DID_BAD_TARGET;
1966 else if (!(sts->state_flags & SF_SENT_CDB))
1967 host_status = DID_ERROR;
1968 else if (!(sts->state_flags & SF_TRANSFERRED_DATA))
1969 host_status = DID_ERROR;
1970 else if (!(sts->state_flags & SF_GOT_STATUS))
1971 host_status = DID_ERROR;
1972 else if (!(sts->state_flags & SF_GOT_SENSE))
1973 host_status = DID_ERROR;
1974 break;
1976 case CS_RESET:
1977 host_status = DID_RESET;
1978 break;
1980 case CS_ABORTED:
1981 host_status = DID_ABORT;
1982 break;
1984 case CS_TIMEOUT:
1985 host_status = DID_TIME_OUT;
1986 break;
1988 case CS_DATA_OVERRUN:
1989 dprintk(2, "Data overrun 0x%x\n", sts->residual_length);
1990 dprintk(2, "qla1280_isr: response packet data\n");
1991 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
1992 host_status = DID_ERROR;
1993 break;
1995 case CS_DATA_UNDERRUN:
1996 if ((cp->request_bufflen - sts->residual_length) <
1997 cp->underflow) {
1998 printk(KERN_WARNING
1999 "scsi: Underflow detected - retrying "
2000 "command.\n");
2001 host_status = DID_ERROR;
2002 } else
2003 host_status = DID_OK;
2004 break;
2006 default:
2007 host_status = DID_ERROR;
2008 break;
2011 #if DEBUG_QLA1280_INTR
2012 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
2013 reason[host_status], sts->scsi_status);
2014 #endif
2016 LEAVE("qla1280_return_status");
2018 return (sts->scsi_status & 0xff) | (host_status << 16);
2022 * qla1280_done_q_put
2023 * Place SRB command on done queue.
2025 * Input:
2026 * sp = srb pointer.
2027 * done_q_first = done queue first pointer.
2028 * done_q_last = done queue last pointer.
2030 static void
2031 qla1280_done_q_put(srb_t * sp, srb_t ** done_q_first, srb_t ** done_q_last)
2033 ENTER("qla1280_put_done_q");
2035 /* Place block on done queue */
2036 sp->s_next = NULL;
2037 sp->s_prev = *done_q_last;
2038 if (!*done_q_first)
2039 *done_q_first = sp;
2040 else
2041 (*done_q_last)->s_next = sp;
2042 *done_q_last = sp;
2044 LEAVE("qla1280_put_done_q");
2048 * qla1280_next
2049 * Retrieve and process next job in the queue.
2051 * Input:
2052 * ha = adapter block pointer.
2053 * q = SCSI LU pointer.
2054 * bus = SCSI bus number.
2055 * SCSI_LU_Qlock must be already obtained and no other locks.
2057 * Output:
2058 * Releases SCSI_LU_Qupon exit.
2060 static void
2061 qla1280_next(struct scsi_qla_host *ha, scsi_lu_t * q, int bus)
2063 srb_t *sp;
2064 int cnt, status;
2066 ENTER("qla1280_next");
2068 while (((sp = q->q_first) != NULL) && /* we have a queue pending */
2069 /* device not busy/suspended */
2070 !(q->q_flag & (QLA1280_QBUSY | QLA1280_QSUSP)) && !ha->flags.abort_isp_active) { /* not resetting the adapter */
2071 /* Remove srb from SCSI LU queue. */
2072 qla1280_removeq(q, sp);
2074 dprintk(1, "starting request 0x%p<-(0x%p)\n", q, sp);
2076 /* Set busy flag if reached high water mark. */
2077 q->q_outcnt++;
2078 if (q->q_outcnt >= ha->bus_settings[bus].hiwat)
2079 q->q_flag |= QLA1280_QBUSY;
2081 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,18)
2082 if (ha->flags.enable_64bit_addressing)
2083 status = qla1280_64bit_start_scsi(ha, sp);
2084 else
2085 #endif
2086 status = qla1280_32bit_start_scsi(ha, sp);
2088 if (status) { /* if couldn't start the request */
2089 if (q->q_outcnt == 1) {
2090 /* Wait for 30 sec for command to be accepted. */
2091 for (cnt = 6000000; cnt; cnt--) {
2092 #if QLA_64BIT_PTR
2093 if (ha->flags.enable_64bit_addressing)
2094 status =
2095 qla1280_64bit_start_scsi(ha, sp);
2096 else
2097 #endif
2098 status =
2099 qla1280_32bit_start_scsi(ha, sp);
2101 if (!status)
2102 break;
2104 /* Go check for pending interrupts. */
2105 qla1280_poll(ha);
2107 udelay(5); /* 10 */
2109 if (!cnt) {
2110 /* Set timeout status */
2111 CMD_RESULT(sp->cmd) =
2112 DID_TIME_OUT << 16;
2114 #if WATCHDOGTIMER
2115 /* Remove command from watchdog queue. */
2116 if (sp->flags & SRB_WATCHDOG)
2117 qla1280_timeout_remove
2118 (ha, sp);
2119 #endif
2120 CMD_HANDLE(sp->cmd) = NULL;
2122 /* Call the mid-level driver interrupt handler */
2123 (*(sp->cmd)->scsi_done)(sp->cmd);
2125 if (q->q_outcnt)
2126 q->q_outcnt--;
2128 } else { /* Place request back on top of device queue. */
2129 qla1280_putq_t(q, sp);
2131 if (q->q_outcnt)
2132 q->q_outcnt--;
2133 if (q->q_outcnt <
2134 ha->bus_settings[bus].hiwat)
2135 q->q_flag &= ~QLA1280_QBUSY;
2136 break;
2142 LEAVE("qla1280_next");
2146 * qla1280_putq_t
2147 * Add the standard SCB job to the top of standard SCB commands.
2149 * Input:
2150 * q = SCSI LU pointer.
2151 * sp = srb pointer.
2152 * SCSI_LU_Qlock must be already obtained.
2154 static void
2155 qla1280_putq_t(scsi_lu_t * q, srb_t * sp)
2157 ENTER("qla1280_putq_t");
2159 dprintk(1, "Adding to device q=0x%p<-(0x%p)sp\n", (void *) q,
2160 (void *) sp);
2162 sp->s_next = NULL;
2163 if (!q->q_first) { /* If queue empty */
2164 sp->s_prev = NULL;
2165 q->q_first = sp;
2166 q->q_last = sp;
2167 } else {
2168 sp->s_prev = q->q_last;
2169 q->q_last->s_next = sp;
2170 q->q_last = sp;
2173 LEAVE("qla1280_putq_t");
2177 * qla1280_removeq
2178 * Function used to remove a command block from the
2179 * LU queue.
2181 * Input:
2182 * q = SCSI LU pointer.
2183 * sp = srb pointer.
2184 * SCSI_LU_Qlock must be already obtained.
2186 static void
2187 qla1280_removeq(scsi_lu_t * q, srb_t * sp)
2189 dprintk(1, "Removing from device_q (0x%p)->(0x%p)\n", q, sp);
2191 if (sp->s_prev) {
2192 if ((sp->s_prev->s_next = sp->s_next) != NULL)
2193 sp->s_next->s_prev = sp->s_prev;
2194 else
2195 q->q_last = sp->s_prev;
2196 } else if (!(q->q_first = sp->s_next))
2197 q->q_last = NULL;
2198 else
2199 q->q_first->s_prev = NULL;
2203 * qla1280_mem_alloc
2204 * Allocates adapter memory.
2206 * Returns:
2207 * 0 = success.
2208 * 1 = failure.
2210 static int
2211 qla1280_mem_alloc(struct scsi_qla_host *ha)
2213 int status = 1;
2214 dma_addr_t dma_handle;
2216 ENTER("qla1280_mem_alloc");
2218 /* 3.13 */
2219 /* get consistent memory allocated for request and response rings */
2220 ha->request_ring = pci_alloc_consistent(ha->pdev,
2221 ((REQUEST_ENTRY_CNT + 1) *
2222 (sizeof(request_t))),
2223 &dma_handle);
2224 if (!ha->request_ring)
2225 goto error;
2226 ha->request_dma = dma_handle;
2227 ha->response_ring = pci_alloc_consistent(ha->pdev,
2228 ((RESPONSE_ENTRY_CNT + 1) *
2229 (sizeof(response_t))),
2230 &dma_handle);
2231 if (!ha->request_ring)
2232 goto error;
2233 ha->response_dma = dma_handle;
2234 status = 0;
2236 error:
2237 if (status)
2238 dprintk(2, "qla1280_mem_alloc: **** FAILED ****\n");
2240 LEAVE("qla1280_mem_alloc");
2241 return status;
2245 * qla1280_mem_free
2246 * Frees adapter allocated memory.
2248 * Input:
2249 * ha = adapter block pointer.
2251 static void
2252 qla1280_mem_free(struct scsi_qla_host *ha)
2254 scsi_lu_t *q;
2255 int bus, target, lun;
2257 ENTER("qlc1280_mem_free");
2258 if (ha) {
2259 /* Free device queues. */
2260 for (bus = 0; bus < MAX_BUSES; bus++) {
2261 q = LU_Q(ha, bus, ha->bus_settings[bus].id, 0);
2262 for (target = 0; target < MAX_TARGETS; target++)
2263 for (lun = 0; lun < MAX_LUNS; lun++)
2264 if (LU_Q(ha, bus, target, lun) != NULL
2265 && LU_Q(ha, bus, target, lun) != q)
2266 kfree(LU_Q(ha, bus, target, lun));
2267 kfree(q);
2269 for (bus = 0; bus < MAX_EQ; bus++)
2270 ha->dev[bus] = NULL;
2273 /* 3.13 */
2274 /* free consistent memory allocated for request and response rings */
2275 if (ha->request_ring)
2276 pci_free_consistent(ha->pdev,
2277 ((REQUEST_ENTRY_CNT + 1) *
2278 (sizeof(request_t))),
2279 ha->request_ring, ha->request_dma);
2281 if (ha->response_ring)
2282 pci_free_consistent(ha->pdev,
2283 ((RESPONSE_ENTRY_CNT + 1) *
2284 (sizeof(response_t))),
2285 ha->response_ring, ha->response_dma);
2287 if (qla1280_buffer) {
2288 free_page((unsigned long) qla1280_buffer);
2289 qla1280_buffer = NULL;
2292 LEAVE("qlc1280_mem_free");
2295 /****************************************************************************/
2296 /* QLogic ISP1280 Hardware Support Functions. */
2297 /****************************************************************************/
2300 * qla2100_enable_intrs
2301 * qla2100_disable_intrs
2303 * Input:
2304 * ha = adapter block pointer.
2306 * Returns:
2307 * None
2309 static inline void
2310 qla1280_enable_intrs(struct scsi_qla_host *ha)
2312 struct device_reg *reg;
2314 reg = ha->iobase;
2315 /* enable risc and host interrupts */
2316 WRT_REG_WORD(&reg->ictrl, (ISP_EN_INT | ISP_EN_RISC));
2317 ha->flags.ints_enabled = 1;
2318 #if 0
2319 printk("Enabling ints\n");
2320 #endif
2323 static inline void
2324 qla1280_disable_intrs(struct scsi_qla_host *ha)
2326 struct device_reg *reg;
2328 reg = ha->iobase;
2329 /* disable risc and host interrupts */
2330 WRT_REG_WORD(&reg->ictrl, 0);
2331 ha->flags.ints_enabled = 0;
2332 #if 0
2333 printk("Disabling ints\n");
2334 #endif
2338 * qla1280_initialize_adapter
2339 * Initialize board.
2341 * Input:
2342 * ha = adapter block pointer.
2344 * Returns:
2345 * 0 = success
2347 static int
2348 qla1280_initialize_adapter(struct scsi_qla_host *ha)
2350 struct device_reg *reg;
2351 int status;
2352 int bus;
2354 ENTER("qla1280_initialize_adapter");
2356 /* Clear adapter flags. */
2357 ha->flags.online = FALSE;
2358 ha->flags.isp_abort_needed = FALSE;
2359 ha->flags.disable_host_adapter = FALSE;
2360 ha->flags.reset_active = FALSE;
2361 ha->flags.abort_isp_active = FALSE;
2363 ha->flags.ints_enabled = FALSE;
2365 dprintk(1, "Configure PCI space for adapter...\n");
2367 reg = ha->iobase;
2369 /* Insure mailbox registers are free. */
2370 WRT_REG_WORD(&reg->semaphore, 0);
2371 WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
2372 WRT_REG_WORD(&reg->host_cmd, HC_CLR_HOST_INT);
2374 /* If firmware needs to be loaded */
2375 if (qla1280_verbose)
2376 printk(KERN_INFO "scsi(%li): Determining if RISC is "
2377 "loaded...\n", ha->host_no);
2378 if (qla1280_isp_firmware(ha)) {
2379 if (qla1280_verbose)
2380 printk(KERN_INFO "scsi(%ld): Verifying chip...\n",
2381 ha->host_no);
2382 if (!(status = qla1280_chip_diag (ha))) {
2383 if (qla1280_verbose)
2384 printk(KERN_INFO "scsi(%ld): Setup chip...\n",
2385 ha->host_no);
2386 status = qla1280_setup_chip(ha);
2388 } else {
2389 printk(KERN_ERR "initialize: isp_firmware() failed!\n");
2390 status = 1;
2393 if (!status) {
2394 /* Setup adapter based on NVRAM parameters. */
2395 if (qla1280_verbose)
2396 printk(KERN_INFO
2397 "scsi(%ld): Configure NVRAM parameters...\n",
2398 ha->host_no);
2399 qla1280_nvram_config(ha);
2401 if (!ha->flags.disable_host_adapter
2402 && !qla1280_init_rings(ha)) {
2403 /* Issue SCSI reset. */
2404 /* dg 03/13 if we can't reset twice then bus is dead */
2405 for (bus = 0; bus < ha->ports; bus++) {
2406 if (!ha->bus_settings[bus].disable_scsi_reset){
2407 if (qla1280_bus_reset(ha, bus)) {
2408 if (qla1280_bus_reset(ha, bus)) {
2409 ha->bus_settings[bus].scsi_bus_dead = TRUE;
2414 do {
2415 /* Issue marker command. */
2416 ha->flags.reset_marker = FALSE;
2417 for (bus = 0; bus < ha->ports; bus++) {
2418 ha->bus_settings[bus].reset_marker = FALSE;
2419 qla1280_marker(ha, bus, 0, 0,
2420 MK_SYNC_ALL);
2422 } while (ha->flags.reset_marker);
2424 ha->flags.online = TRUE;
2426 /* Enable host adapter target mode. */
2427 for (bus = 0; bus < ha->ports; bus++) {
2428 if (!(status = qla1280_enable_tgt(ha, bus))) {
2429 #if 0
2430 int cnt;
2431 for (cnt = 0; cnt < MAX_LUNS; cnt++) {
2432 qla1280_enable_lun(ha, bus,
2433 cnt);
2434 qla1280_poll(ha);
2436 #endif
2437 } else
2438 break;
2440 } else
2441 status = 1;
2442 } else
2443 printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
2444 ha->host_no);
2446 if (status)
2447 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
2449 LEAVE("qla1280_initialize_adapter");
2450 return status;
2454 * qla1280_enable_tgt
2455 * Enable target mode.
2457 * Input:
2458 * ha = adapter block pointer.
2459 * bus = SCSI bus number.
2461 * Returns:
2462 * 0 = success.
2464 static int
2465 qla1280_enable_tgt(struct scsi_qla_host *ha, int bus)
2467 int status = 0;
2468 /* uint16_t mb[MAILBOX_REGISTER_COUNT]; */
2470 dprintk(3, "qla1280_enable_tgt: entered\n");
2472 /* Enable target mode. */
2473 #if 0
2474 mb[0] = MBC_ENABLE_TARGET_MODE;
2475 mb[1] = BIT_15;
2476 mb[2] = (uint16_t) (bus << 15);
2477 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2478 #endif
2479 if (status)
2480 dprintk(2, "qla1280_enable_tgt: **** FAILED ****\n");
2481 else
2482 dprintk(3, "qla1280_enable_tgt: exiting normally\n");
2484 return status;
2488 * ISP Firmware Test
2489 * Checks if present version of RISC firmware is older than
2490 * driver firmware.
2492 * Input:
2493 * ha = adapter block pointer.
2495 * Returns:
2496 * 0 = firmware does not need to be loaded.
2498 static int
2499 qla1280_isp_firmware(struct scsi_qla_host *ha)
2501 nvram_t *nv = (nvram_t *) ha->response_ring;
2502 uint16_t *wptr;
2503 int status = 0; /* dg 2/27 always loads RISC */
2504 int cnt;
2505 uint8_t chksum;
2506 uint16_t mb[MAILBOX_REGISTER_COUNT];
2508 ENTER("qla1280_isp_firmware");
2510 /* Verify valid NVRAM checksum. */
2511 wptr = (uint16_t *) ha->response_ring;
2512 dprintk(1, "qla1280_isp_firmware: Reading NVRAM\n");
2514 chksum = 0;
2515 for (cnt = 0; cnt < sizeof(nvram_t) / 2; cnt++) {
2516 *wptr = qla1280_get_nvram_word (ha, cnt);
2517 chksum += (uint8_t) * wptr;
2518 chksum += (uint8_t) (*wptr >> 8);
2519 wptr++;
2521 dprintk(1, "qla1280_isp_firmware: Completed Reading NVRAM\n");
2523 dprintk(3, "qla1280_isp_firmware: NVRAM Magic ID= %c %c %c\n",
2524 (char *)nv->id[0], nv->id[1], nv->id[2]);
2526 /* Bad NVRAM data, load RISC code. */
2527 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2528 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->version < 1) {
2529 printk(KERN_INFO "qla1280_isp_firmware: Bad checksum or magic "
2530 "number or version in NVRAM.\n");
2531 ha->flags.disable_risc_code_load = FALSE;
2532 } else
2533 ha->flags.disable_risc_code_load =
2534 nv->cntr_flags_1.disable_loading_risc_code;
2536 if (ha->flags.disable_risc_code_load) {
2537 dprintk(3,
2538 "qla1280_isp_firmware: Telling RISC to verify checksum "
2539 "of loaded BIOS code.\n");
2541 /* Verify checksum of loaded RISC code. */
2542 mb[0] = MBC_VERIFY_CHECKSUM;
2543 /* mb[1] = ql12_risc_code_addr01; */
2544 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2546 if (!
2547 (status =
2548 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]))) {
2549 /* Start firmware execution. */
2550 dprintk(3, "qla1280_isp_firmware: Startng F/W "
2551 "execution.\n");
2553 mb[0] = MBC_EXECUTE_FIRMWARE;
2554 /* mb[1] = ql12_risc_code_addr01; */
2555 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2556 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2557 } else
2558 printk(KERN_INFO "qla1280: RISC checksum failed.\n");
2559 } else {
2560 dprintk(1, "qla1280: NVRAM configured to load RISC load.\n");
2561 status = 1;
2564 if (status)
2565 dprintk(2, "qla1280_isp_firmware: **** Load RISC code ****\n");
2567 LEAVE("qla1280_isp_firmware");
2568 return status;
2572 * PCI configuration
2573 * Setup device PCI configuration registers.
2575 * Input:
2576 * ha = adapter block pointer.
2578 * Returns:
2579 * 0 = success.
2581 static int
2582 qla1280_pci_config(struct scsi_qla_host *ha)
2584 #if MEMORY_MAPPED_IO
2585 uint32_t page_offset, base;
2586 uint32_t mmapbase;
2587 #endif
2588 uint16_t buf_wd;
2589 int status = 1;
2591 ENTER("qla1280_pci_config");
2593 pci_set_master(ha->pdev);
2595 * Set Bus Master Enable, Memory Address Space Enable and
2596 * reset any error bits, in the command register.
2598 pci_read_config_word (ha->pdev, PCI_COMMAND, &buf_wd);
2599 #if MEMORY_MAPPED_IO
2600 dprintk(1, "qla1280: MEMORY MAPPED IO is enabled.\n");
2601 buf_wd |= PCI_COMMAND_MEMORY + PCI_COMMAND_IO;
2602 #else
2603 buf_wd |= PCI_COMMAND_IO;
2604 #endif
2605 pci_write_config_word (ha->pdev, PCI_COMMAND, buf_wd);
2607 * Reset expansion ROM address decode enable.
2609 pci_read_config_word (ha->pdev, PCI_ROM_ADDRESS, &buf_wd);
2610 buf_wd &= ~PCI_ROM_ADDRESS_ENABLE;
2611 pci_write_config_word (ha->pdev, PCI_ROM_ADDRESS, buf_wd);
2613 ha->host->io_port = pci_resource_start(ha->pdev, 0);
2614 ha->host->io_port &= PCI_BASE_ADDRESS_IO_MASK;
2615 ha->iobase = (struct device_reg *) ha->host->io_port;
2617 #if MEMORY_MAPPED_IO
2619 * Get memory mapped I/O address.
2621 pci_read_config_word (ha->pdev, PCI_BASE_ADDRESS_1, &mmapbase);
2622 mmapbase &= PCI_BASE_ADDRESS_MEM_MASK;
2625 * Find proper memory chunk for memory map I/O reg.
2627 base = mmapbase & PAGE_MASK;
2628 page_offset = mmapbase - base;
2630 * Get virtual address for I/O registers.
2632 ha->mmpbase = ioremap(base, page_offset + 256);
2633 if (ha->mmpbase) {
2634 ha->mmpbase += page_offset;
2635 /* ha->iobase = ha->mmpbase; */
2636 status = 0;
2638 #else /* MEMORY_MAPPED_IO */
2639 status = 0;
2640 #endif /* MEMORY_MAPPED_IO */
2642 LEAVE("qla1280_pci_config");
2643 return status;
2647 * Chip diagnostics
2648 * Test chip for proper operation.
2650 * Input:
2651 * ha = adapter block pointer.
2653 * Returns:
2654 * 0 = success.
2656 static int
2657 qla1280_chip_diag(struct scsi_qla_host *ha)
2659 uint16_t mb[MAILBOX_REGISTER_COUNT];
2660 struct device_reg *reg = ha->iobase;
2661 int status = 0;
2662 int cnt;
2663 uint16_t data;
2665 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", &reg->id_l);
2667 /* Soft reset chip and wait for it to finish. */
2668 WRT_REG_WORD(&reg->ictrl, ISP_RESET);
2669 data = qla1280_debounce_register(&reg->ictrl);
2671 * This is *AWESOME*
2673 for (cnt = 6000000; cnt && data & ISP_RESET; cnt--) {
2674 udelay(5);
2675 data = RD_REG_WORD(&reg->ictrl);
2677 if (cnt) {
2678 /* Reset register not cleared by chip reset. */
2679 dprintk(3,
2680 "qla1280_chip_diag: reset register cleared by chip reset\n");
2682 WRT_REG_WORD(&reg->cfg_1, 0);
2684 /* Reset RISC and disable BIOS which
2685 allows RISC to execute out of RAM. */
2686 WRT_REG_WORD(&reg->host_cmd, HC_RESET_RISC);
2687 WRT_REG_WORD(&reg->host_cmd, HC_RELEASE_RISC);
2688 WRT_REG_WORD(&reg->host_cmd, HC_DISABLE_BIOS);
2689 data = qla1280_debounce_register(&reg->mailbox0);
2691 * I *LOVE* this code!
2693 for (cnt = 6000000; cnt && data == MBS_BUSY; cnt--) {
2694 udelay(5);
2695 data = RD_REG_WORD(&reg->mailbox0);
2698 if (cnt) {
2699 /* Check product ID of chip */
2700 dprintk(3,
2701 "qla1280_chip_diag: Checking product ID of chip\n");
2703 if (RD_REG_WORD(&reg->mailbox1) != PROD_ID_1 ||
2704 (RD_REG_WORD(&reg->mailbox2) != PROD_ID_2 &&
2705 RD_REG_WORD(&reg->mailbox2) != PROD_ID_2a) ||
2706 RD_REG_WORD(&reg->mailbox3) != PROD_ID_3 ||
2707 RD_REG_WORD(&reg->mailbox4) != PROD_ID_4) {
2708 printk(KERN_INFO
2709 "qla1280: Wrong product ID = 0x%x,0x%x,0x%x,"
2710 "0x%x\n", RD_REG_WORD(&reg->mailbox1),
2711 RD_REG_WORD(&reg->mailbox2),
2712 RD_REG_WORD(&reg->mailbox3),
2713 RD_REG_WORD(&reg->mailbox4));
2714 status = 1;
2715 } else {
2717 * Enable ints early!!!
2719 qla1280_enable_intrs(ha);
2720 dprintk(1,
2721 "qla1280_chip_diag: Checking mailboxes of chip\n");
2722 /* Wrap Incoming Mailboxes Test. */
2723 mb[0] = MBC_MAILBOX_REGISTER_TEST;
2724 mb[1] = 0xAAAA;
2725 mb[2] = 0x5555;
2726 mb[3] = 0xAA55;
2727 mb[4] = 0x55AA;
2728 mb[5] = 0xA5A5;
2729 mb[6] = 0x5A5A;
2730 mb[7] = 0x2525;
2731 if (!(status = qla1280_mailbox_command(ha,
2732 BIT_7 |
2733 BIT_6 |
2734 BIT_5 |
2735 BIT_4 |
2736 BIT_3 |
2737 BIT_2 |
2738 BIT_1 |
2739 BIT_0,
2741 [0]))) {
2742 if (mb[1] != 0xAAAA ||
2743 mb[2] != 0x5555 ||
2744 mb[3] != 0xAA55 ||
2745 mb[4] != 0x55AA ||
2746 mb[5] != 0xA5A5 ||
2747 mb[6] != 0x5A5A ||
2748 mb[7] != 0x2525)
2749 status = 1;
2750 if (status == 1)
2751 printk(KERN_INFO
2752 "qla1280: Failed mailbox check\n");
2755 } else
2756 status = 1;
2757 } else
2758 status = 1;
2760 if (status)
2761 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
2762 else
2763 dprintk(3, "qla1280_chip_diag: exiting normally\n");
2765 return status;
2769 * Setup chip
2770 * Load and start RISC firmware.
2772 * Input:
2773 * ha = adapter block pointer.
2775 * Returns:
2776 * 0 = success.
2778 #define DUMP_IT_BACK 0 /* for debug of RISC loading */
2779 static int
2780 qla1280_setup_chip(struct scsi_qla_host *ha)
2782 int status = 0;
2783 uint16_t risc_address;
2784 uint16_t *risc_code_address;
2785 int risc_code_size;
2786 uint16_t mb[MAILBOX_REGISTER_COUNT];
2787 uint16_t cnt;
2788 int num;
2789 #if DUMP_IT_BACK
2790 int i;
2791 uint8_t *sp;
2792 uint8_t *tbuf;
2793 #ifdef QLA_64BIT_PTR
2794 dma_addr_t p_tbuf;
2795 #else
2796 uint32_t p_tbuf;
2797 #endif
2798 #endif
2800 ENTER("qla1280_setup_chip");
2802 /* 3.13 */
2803 #if DUMP_IT_BACK
2804 /* get consistent memory allocated for setup_chip */
2805 tbuf = pci_alloc_consistent(ha->pdev, 8000, &p_tbuf);
2806 #endif
2808 /* Load RISC code. */
2809 risc_address = *ql1280_board_tbl[ha->devnum].fwstart;
2810 risc_code_address = ql1280_board_tbl[ha->devnum].fwcode;
2811 risc_code_size = (int) *ql1280_board_tbl[ha->devnum].fwlen;
2813 dprintk(1, "qla1280_setup_chip: DMA RISC code (%i) words\n",
2814 risc_code_size);
2816 num = 0;
2817 while (risc_code_size > 0 && !status) {
2818 cnt = 2000 >> 1;
2820 if (cnt > risc_code_size)
2821 cnt = risc_code_size;
2823 dprintk(1, "qla1280_setup_chip: loading risc @ =(0x%p),"
2824 "%d,%d(0x%x)\n",
2825 risc_code_address, cnt, num, risc_address);
2826 memcpy(ha->request_ring, risc_code_address, (cnt << 1));
2828 flush_cache_all();
2830 mb[0] = MBC_LOAD_RAM;
2831 mb[1] = risc_address;
2832 mb[4] = cnt;
2833 mb[3] = ha->request_dma & 0xffff;
2834 mb[2] = (ha->request_dma >> 16) & 0xffff;
2835 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2836 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2837 dprintk(1, "qla1280_setup_chip: op=%d 0x%p = 0x%4x,0x%4x,"
2838 "0x%4x,0x%4x\n",
2839 mb[0], ha->request_dma, mb[6], mb[7], mb[2], mb[3]);
2840 if ((status = qla1280_mailbox_command(ha, BIT_4 | BIT_3 |
2841 BIT_2 | BIT_1 | BIT_0,
2842 &mb[0]))) {
2843 printk(KERN_ERR
2844 "Failed to load partial segment of f/w\n");
2845 break;
2847 #if DUMP_IT_BACK
2848 mb[0] = MBC_READ_RAM_WORD;
2849 mb[1] = risc_address;
2850 mb[4] = cnt;
2851 mb[3] = p_tbuf & 0xffff;
2852 mb[2] = (p_tbuf >> 16) & 0xffff;
2853 mb[7] = pci_dma_hi32(p_tbuf) & 0xffff;
2854 mb[6] = pci_dma_hi32(p_tbuf) >> 16;
2856 if ((status = qla1280_mailbox_command(ha,
2857 BIT_4 | BIT_3 | BIT_2 |
2858 BIT_1 | BIT_0,
2859 &mb[0]))) {
2860 printk(KERN_ERR
2861 "Failed to dump partial segment of f/w\n");
2862 break;
2864 sp = (uint8_t *)ha->request_ring;
2865 for (i = 0; i < (cnt << 1); i++) {
2866 if (tbuf[i] != sp[i]) {
2867 printk(KERN_ERR "qla1280_setup_chip: FW "
2868 "compare error @ byte(0x%x) loop#=%x\n",
2869 i, num);
2870 printk(KERN_ERR "setup_chip: FWbyte=%x "
2871 "FWfromChip=%x\n", sp[i], tbuf[i]);
2872 /*break; */
2875 #endif
2876 risc_address += cnt;
2877 risc_code_size = risc_code_size - cnt;
2878 risc_code_address = risc_code_address + cnt;
2879 num++;
2882 /* Verify checksum of loaded RISC code. */
2883 if (!status) {
2884 dprintk(1, "qla1280_setup_chip: Verifying checksum of "
2885 "loaded RISC code.\n");
2886 mb[0] = MBC_VERIFY_CHECKSUM;
2887 /* mb[1] = ql12_risc_code_addr01; */
2888 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2890 if (!(status =
2891 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]))) {
2892 /* Start firmware execution. */
2893 dprintk(1,
2894 "qla1280_setup_chip: start firmware running.\n");
2895 mb[0] = MBC_EXECUTE_FIRMWARE;
2896 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2897 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2898 } else
2899 printk(KERN_ERR
2900 "qla1280_setup_chip: Failed checksum.\n");
2903 /* 3.13 */
2904 #if DUMP_IT_BACK
2905 /* free consistent memory allocated for setup_chip */
2906 pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
2907 #endif
2909 if (status)
2910 dprintk(2, "qla1280_setup_chip: **** FAILED ****\n");
2912 LEAVE("qla1280_setup_chip");
2913 return status;
2917 * Initialize rings
2919 * Input:
2920 * ha = adapter block pointer.
2921 * ha->request_ring = request ring virtual address
2922 * ha->response_ring = response ring virtual address
2923 * ha->request_dma = request ring physical address
2924 * ha->response_dma = response ring physical address
2926 * Returns:
2927 * 0 = success.
2929 static int
2930 qla1280_init_rings(struct scsi_qla_host *ha)
2932 uint16_t mb[MAILBOX_REGISTER_COUNT];
2933 int status = 0;
2934 int cnt;
2936 ENTER("qla1280_init_rings");
2938 /* Clear outstanding commands array. */
2939 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
2940 ha->outstanding_cmds[cnt] = 0;
2942 /* Initialize request queue. */
2943 ha->request_ring_ptr = ha->request_ring;
2944 ha->req_ring_index = 0;
2945 ha->req_q_cnt = REQUEST_ENTRY_CNT;
2946 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
2947 mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
2948 mb[1] = REQUEST_ENTRY_CNT;
2949 mb[3] = ha->request_dma & 0xffff;
2950 mb[2] = (ha->request_dma >> 16) & 0xffff;
2951 mb[4] = 0;
2952 mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
2953 mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
2954 if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
2955 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2956 &mb[0]))) {
2957 /* Initialize response queue. */
2958 ha->response_ring_ptr = ha->response_ring;
2959 ha->rsp_ring_index = 0;
2960 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
2961 mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
2962 mb[1] = RESPONSE_ENTRY_CNT;
2963 mb[3] = ha->response_dma & 0xffff;
2964 mb[2] = (ha->response_dma >> 16) & 0xffff;
2965 mb[5] = 0;
2966 mb[7] = pci_dma_hi32(ha->response_dma) & 0xffff;
2967 mb[6] = pci_dma_hi32(ha->response_dma) >> 16;
2968 status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
2969 BIT_3 | BIT_2 | BIT_1 | BIT_0,
2970 &mb[0]);
2973 if (status)
2974 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
2976 LEAVE("qla1280_init_rings");
2977 return status;
2981 * NVRAM configuration.
2983 * Input:
2984 * ha = adapter block pointer.
2985 * ha->request_ring = request ring virtual address
2987 * Output:
2988 * host adapters parameters in host adapter block
2990 * Returns:
2991 * 0 = success.
2993 static int
2994 qla1280_nvram_config(struct scsi_qla_host *ha)
2996 struct device_reg *reg = ha->iobase;
2997 nvram_t *nv = (nvram_t *)ha->response_ring;
2998 int status = 0;
2999 int cnt;
3000 int bus, target, lun;
3001 uint16_t *wptr;
3002 uint16_t mb[MAILBOX_REGISTER_COUNT];
3003 uint8_t chksum;
3004 int nvsize;
3006 #if DEBUG_PRINT_NVRAM
3007 int saved_print_status = ql_debug_print;
3008 #endif
3009 ENTER("qla1280_nvram_config");
3011 /* Verify valid NVRAM checksum. */
3012 #if USE_NVRAM_DEFAULTS
3013 chksum = 1;
3014 #else
3015 wptr = (uint16_t *) ha->response_ring;
3016 chksum = 0;
3017 if (ha->device_id == PCI_DEVICE_ID_QLOGIC_ISP12160 ||
3018 ha->device_id == PCI_DEVICE_ID_QLOGIC_ISP10160)
3019 nvsize = sizeof(nvram160_t) / 2;
3020 else
3021 nvsize = sizeof(nvram_t) / 2;
3022 for (cnt = 0; cnt < nvsize; cnt++) {
3023 *wptr = qla1280_get_nvram_word(ha, cnt);
3024 chksum += (uint8_t) * wptr;
3025 chksum += (uint8_t) (*wptr >> 8);
3026 wptr++;
3028 #endif
3030 /* Bad NVRAM data, set defaults parameters. */
3031 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
3032 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->version < 1) {
3033 #if USE_NVRAM_DEFAULTS
3034 dprintk(1, "Using defaults for NVRAM\n");
3035 #else
3036 dprintk(1, "Using defaults for NVRAM: \n");
3037 dprintk(1, "checksum=0x%x, Id=%c, version=0x%x\n",
3038 chksum, nv->id[0], nv->version);
3039 memset(ha->response_ring, 0, sizeof(nvram_t));
3040 #endif
3042 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
3043 nv->firmware_feature.w = BIT_0;
3044 nv->termination.f.scsi_bus_0_control = 3;
3045 nv->termination.f.scsi_bus_1_control = 3;
3046 nv->termination.f.auto_term_support = 1;
3048 for (bus = 0; bus < MAX_BUSES; bus++) {
3049 nv->bus[bus].config_1.initiator_id = 7;
3050 nv->bus[bus].bus_reset_delay = 5;
3051 nv->bus[bus].config_2.async_data_setup_time = 9;
3052 nv->bus[bus].config_2.req_ack_active_negation = 1;
3053 nv->bus[bus].config_2.data_line_active_negation = 1;
3054 nv->bus[bus].selection_timeout = 250;
3055 nv->bus[bus].max_queue_depth = 256;
3057 for (target = 0; target < MAX_TARGETS; target++) {
3058 nv->bus[bus].target[target].parameter.f.
3059 auto_request_sense = 1;
3060 nv->bus[bus].target[target].parameter.f.
3061 disconnect_allowed = 1;
3062 nv->bus[bus].target[target].parameter.f.
3063 tag_queuing = 1;
3064 nv->bus[bus].target[target].flags.
3065 device_enable = 1;
3069 #if USE_NVRAM_DEFAULTS
3070 status = 0;
3071 #else
3072 status = 1;
3073 #endif
3074 } else {
3075 /* Always force AUTO sense for LINUX SCSI */
3076 for (bus = 0; bus < MAX_BUSES; bus++)
3077 for (target = 0; target < MAX_TARGETS; target++) {
3078 nv->bus[bus].target[target].parameter.f.
3079 auto_request_sense = 1;
3082 #if DEBUG_PRINT_NVRAM
3083 ql_debug_print = 1;
3084 #endif
3085 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
3086 nv->bus[0].config_1.initiator_id);
3087 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
3088 nv->bus[1].config_1.initiator_id);
3090 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
3091 nv->bus[0].bus_reset_delay);
3092 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
3093 nv->bus[1].bus_reset_delay);
3095 dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
3096 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
3097 dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
3098 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
3100 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
3101 nv->bus[0].config_2.async_data_setup_time);
3102 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
3103 nv->bus[1].config_2.async_data_setup_time);
3105 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
3106 nv->bus[0].config_2.req_ack_active_negation);
3107 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
3108 nv->bus[1].config_2.req_ack_active_negation);
3110 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
3111 nv->bus[0].config_2.data_line_active_negation);
3112 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
3113 nv->bus[1].config_2.data_line_active_negation);
3115 dprintk(1, "qla1280 : disable loading risc code=%d\n",
3116 nv->cntr_flags_1.disable_loading_risc_code);
3118 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
3119 nv->cntr_flags_1.enable_64bit_addressing);
3121 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
3122 nv->bus[0].selection_timeout);
3123 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
3124 nv->bus[1].selection_timeout);
3126 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
3127 nv->bus[0].max_queue_depth);
3128 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
3129 nv->bus[1].max_queue_depth);
3131 /* Disable RISC load of firmware. */
3132 ha->flags.disable_risc_code_load =
3133 nv->cntr_flags_1.disable_loading_risc_code;
3135 #ifdef QLA_64BIT_PTR
3136 /* Enable 64bit addressing for OS/System combination supporting it */
3137 /* actual NVRAM bit is: nv->cntr_flags_1.enable_64bit_addressing */
3138 /* but we will ignore it and use BITS_PER_LONG macro to setup for */
3139 /* 64 or 32 bit access of host memory in all x86/ia-64/Alpha systems */
3140 ha->flags.enable_64bit_addressing = 1;
3141 #else
3142 ha->flags.enable_64bit_addressing = 0;
3143 #endif
3145 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,18)
3146 if (ha->flags.enable_64bit_addressing) {
3147 printk(KERN_INFO "scsi(%li): 64 Bit PCI Addressing Enabled\n",
3148 ha->host_no);
3150 pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL);
3152 #endif
3154 /* Set ISP hardware DMA burst */
3155 mb[0] = nv->isp_config.c;
3156 WRT_REG_WORD(&reg->cfg_1, mb[0]);
3158 /* Set SCSI termination. */
3159 WRT_REG_WORD(&reg->gpio_enable, (BIT_3 + BIT_2 + BIT_1 + BIT_0));
3160 mb[0] = nv->termination.c & (BIT_3 + BIT_2 + BIT_1 + BIT_0);
3161 WRT_REG_WORD(&reg->gpio_data, mb[0]);
3163 /* ISP parameter word. */
3164 mb[0] = MBC_SET_SYSTEM_PARAMETER;
3165 mb[1] = nv->isp_parameter;
3166 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
3168 /* Firmware feature word. */
3169 mb[0] = MBC_SET_FIRMWARE_FEATURES;
3170 mb[1] = nv->firmware_feature.w & (BIT_1 | BIT_0);
3171 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
3173 /* Retry count and delay. */
3174 mb[0] = MBC_SET_RETRY_COUNT;
3175 mb[1] = nv->bus[0].retry_count;
3176 mb[2] = nv->bus[0].retry_delay;
3177 mb[6] = nv->bus[1].retry_count;
3178 mb[7] = nv->bus[1].retry_delay;
3179 status |=
3180 qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 | BIT_1 | BIT_0,
3181 &mb[0]);
3183 /* ASYNC data setup time. */
3184 mb[0] = MBC_SET_ASYNC_DATA_SETUP;
3185 mb[1] = nv->bus[0].config_2.async_data_setup_time;
3186 mb[2] = nv->bus[1].config_2.async_data_setup_time;
3187 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
3189 /* Active negation states. */
3190 mb[0] = MBC_SET_ACTIVE_NEGATION;
3191 mb[1] = 0;
3192 if (nv->bus[0].config_2.req_ack_active_negation)
3193 mb[1] |= BIT_5;
3194 if (nv->bus[0].config_2.data_line_active_negation)
3195 mb[1] |= BIT_4;
3196 mb[2] = 0;
3197 if (nv->bus[1].config_2.req_ack_active_negation)
3198 mb[2] |= BIT_5;
3199 if (nv->bus[1].config_2.data_line_active_negation)
3200 mb[2] |= BIT_4;
3201 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
3203 /* Selection timeout. */
3204 mb[0] = MBC_SET_SELECTION_TIMEOUT;
3205 mb[1] = nv->bus[0].selection_timeout;
3206 mb[2] = nv->bus[1].selection_timeout;
3207 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
3209 for (bus = 0; bus < ha->ports; bus++) {
3210 /* SCSI Reset Disable. */
3211 ha->bus_settings[bus].disable_scsi_reset =
3212 nv->bus[bus].config_1.scsi_reset_disable;
3214 /* Initiator ID. */
3215 ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
3216 mb[0] = MBC_SET_INITIATOR_ID;
3217 mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
3218 ha->bus_settings[bus].id;
3219 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
3221 /* Reset Delay. */
3222 ha->bus_settings[bus].bus_reset_delay =
3223 nv->bus[bus].bus_reset_delay;
3225 /* Command queue depth per device. */
3226 ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
3228 /* Set target parameters. */
3229 for (target = 0; target < MAX_TARGETS; target++) {
3230 uint8_t mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
3232 /* Set Target Parameters. */
3233 mb[0] = MBC_SET_TARGET_PARAMETERS;
3234 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
3235 mb[1] <<= 8;
3237 mb[2] = nv->bus[bus].target[target].parameter.c << 8;
3238 mb[2] |= TP_AUTO_REQUEST_SENSE;
3239 mb[2] &= ~TP_STOP_QUEUE;
3241 mb[3] =
3242 nv->bus[bus].target[target].flags.sync_offset << 8;
3243 mb[3] |= nv->bus[bus].target[target].sync_period;
3245 if (ha->device_id == PCI_DEVICE_ID_QLOGIC_ISP12160 ||
3246 ha->device_id == PCI_DEVICE_ID_QLOGIC_ISP10160) {
3247 nvram160_t *nv2 = (nvram160_t *) nv;
3248 mb[2] |=
3249 nv2->bus[bus].target[target].flags.
3250 enable_ppr << 5;
3252 mb[6] =
3253 nv2->bus[bus].target[target].flags.
3254 ppr_options << 8;
3255 mb[6] |=
3256 nv2->bus[bus].target[target].flags.
3257 ppr_bus_width;
3258 mr |= BIT_6;
3260 status = qla1280_mailbox_command(ha, mr, &mb[0]);
3262 /* Save Tag queuing enable flag. */
3263 mb[0] = BIT_0 << target;
3264 if (nv->bus[bus].target[target].parameter.f.tag_queuing)
3265 ha->bus_settings[bus].qtag_enables |= mb[0];
3267 /* Save Device enable flag. */
3268 if (nv->bus[bus].target[target].flags.device_enable)
3269 ha->bus_settings[bus].device_enables |= mb[0];
3271 /* Save LUN disable flag. */
3272 if (nv->bus[bus].target[target].flags.lun_disable)
3273 ha->bus_settings[bus].lun_disables |= mb[0];
3275 /* Set Device Queue Parameters. */
3276 for (lun = 0; lun < MAX_LUNS; lun++) {
3277 mb[0] = MBC_SET_DEVICE_QUEUE;
3278 mb[1] = (uint16_t)(bus ? target | BIT_7 : target);
3279 mb[1] = mb[1] << 8 | lun;
3280 mb[2] = nv->bus[bus].max_queue_depth;
3281 mb[3] = nv->bus[bus].target[target].execution_throttle;
3282 status |=
3283 qla1280_mailbox_command(ha,
3284 BIT_3 | BIT_2 |
3285 BIT_1 | BIT_0,
3286 &mb[0]);
3291 #if DEBUG_PRINT_NVRAM
3292 ql_debug_print = saved_print_status;
3293 #endif
3295 if (status)
3296 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
3298 LEAVE("qla1280_nvram_config");
3299 return status;
3303 * Get NVRAM data word
3304 * Calculates word position in NVRAM and calls request routine to
3305 * get the word from NVRAM.
3307 * Input:
3308 * ha = adapter block pointer.
3309 * address = NVRAM word address.
3311 * Returns:
3312 * data word.
3314 static uint16_t
3315 qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
3317 uint32_t nv_cmd;
3318 uint16_t data;
3320 #ifdef QL_DEBUG_ROUTINES
3321 int saved_print_status = ql_debug_print;
3322 #endif
3324 nv_cmd = address << 16;
3325 nv_cmd |= NV_READ_OP;
3327 #ifdef QL_DEBUG_ROUTINES
3328 ql_debug_print = FALSE;
3329 #endif
3330 data = qla1280_nvram_request(ha, nv_cmd);
3331 #ifdef QL_DEBUG_ROUTINES
3332 ql_debug_print = saved_print_status;
3333 #endif
3335 dprintk(4,
3336 "qla1280_get_nvram_word: exiting normally NVRAM data = 0x%x",
3337 data);
3339 return data;
3343 * NVRAM request
3344 * Sends read command to NVRAM and gets data from NVRAM.
3346 * Input:
3347 * ha = adapter block pointer.
3348 * nv_cmd = Bit 26 = start bit
3349 * Bit 25, 24 = opcode
3350 * Bit 23-16 = address
3351 * Bit 15-0 = write data
3353 * Returns:
3354 * data word.
3356 static uint16_t
3357 qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
3359 struct device_reg *reg = ha->iobase;
3360 int cnt;
3361 uint16_t data = 0;
3362 uint16_t reg_data;
3364 /* Send command to NVRAM. */
3366 nv_cmd <<= 5;
3367 for (cnt = 0; cnt < 11; cnt++) {
3368 if (nv_cmd & BIT_31)
3369 qla1280_nv_write(ha, NV_DATA_OUT);
3370 else
3371 qla1280_nv_write(ha, 0);
3372 nv_cmd <<= 1;
3375 /* Read data from NVRAM. */
3377 for (cnt = 0; cnt < 16; cnt++) {
3378 WRT_REG_WORD(&reg->nvram, (NV_SELECT | NV_CLOCK));
3379 NVRAM_DELAY();
3380 data <<= 1;
3381 reg_data = RD_REG_WORD(&reg->nvram);
3382 if (reg_data & NV_DATA_IN)
3383 data |= BIT_0;
3384 WRT_REG_WORD(&reg->nvram, NV_SELECT);
3385 NVRAM_DELAY();
3388 /* Deselect chip. */
3390 WRT_REG_WORD(&reg->nvram, NV_DESELECT);
3391 NVRAM_DELAY();
3393 return data;
3396 static void
3397 qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
3399 struct device_reg *reg = ha->iobase;
3401 WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
3402 NVRAM_DELAY();
3403 WRT_REG_WORD(&reg->nvram, data | NV_SELECT | NV_CLOCK);
3404 NVRAM_DELAY();
3405 WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
3406 NVRAM_DELAY();
3410 * Mailbox Command
3411 * Issue mailbox command and waits for completion.
3413 * Input:
3414 * ha = adapter block pointer.
3415 * mr = mailbox registers to load.
3416 * mb = data pointer for mailbox registers.
3418 * Output:
3419 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
3421 * Returns:
3422 * 0 = success
3424 static int
3425 qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t * mb)
3427 struct device_reg *reg = ha->iobase;
3428 #if 0
3429 srb_t *done_q_first = 0;
3430 srb_t *done_q_last = 0;
3431 #endif
3432 int status = 0;
3433 int cnt;
3434 uint16_t *optr, *iptr;
3435 uint16_t data;
3437 ENTER("qla1280_mailbox_command");
3439 ha->flags.mbox_busy = TRUE;
3441 if (!ha->flags.ints_enabled)
3442 printk(KERN_DEBUG
3443 "Running qla1280_mailbox_command() with interrupts "
3444 "disabled!\n");
3446 * We really should start out by verifying that the mailbox is available
3447 * before starting sending the command data
3449 /* Load mailbox registers. */
3450 optr = (uint16_t *) &reg->mailbox0;
3451 iptr = mb;
3452 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
3453 if (mr & BIT_0) {
3454 WRT_REG_WORD(optr, (*iptr));
3457 mr >>= 1;
3458 optr++;
3459 iptr++;
3462 /* Issue set host interrupt command. */
3463 ha->flags.mbox_int = FALSE;
3464 ha->flags.mbox_busy = FALSE;
3465 WRT_REG_WORD(&reg->host_cmd, HC_SET_HOST_INT);
3466 data = qla1280_debounce_register(&reg->istatus);
3469 * This is insane - instead of looping to wait for the interrupt
3470 * to appear and run the handler (this is insane!!), use a waitqueue
3471 * and go to sleep.
3473 * We are never called here from interrupt context anyway! /Jes
3475 /* Wait for 30 seconds for command to finish. */
3476 for (cnt = 30000000; cnt > 0 && !ha->flags.mbox_int; cnt--) {
3477 /* Check for pending interrupts. */
3478 #if 0
3479 if (data & RISC_INT) {
3480 qla1280_isr(ha, &done_q_first, &done_q_last);
3481 } else
3482 #endif
3483 udelay(1);
3485 data = RD_REG_WORD(&reg->istatus);
3488 /* Check for mailbox command timeout. */
3489 if (!cnt) {
3490 printk(KERN_WARNING
3491 "qla1280_mailbox_command: **** Command Timeout, "
3492 "mailbox0 = 0x%x****\n", mb[0]);
3494 ha->flags.isp_abort_needed = TRUE;
3495 status = 1;
3496 } else if (ha->mailbox_out[0] != MBS_CMD_CMP)
3497 status = 1;
3499 /* Load return mailbox registers. */
3500 optr = mb;
3501 iptr = (uint16_t *) &ha->mailbox_out[0];
3502 mr = MAILBOX_REGISTER_COUNT;
3503 memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
3505 #if 0
3506 /* Go check for any response interrupts pending. */
3507 qla1280_isr(ha, &done_q_first, &done_q_last);
3508 #endif
3510 if (ha->flags.isp_abort_needed)
3511 qla1280_abort_isp(ha);
3513 if (ha->flags.reset_marker)
3514 qla1280_rst_aen(ha);
3516 #if 0
3517 if (done_q_first)
3518 qla1280_done (ha, &done_q_first, &done_q_last);
3519 #endif
3521 if (status)
3522 dprintk(2,
3523 "qla1280_mailbox_command: **** FAILED, mailbox0 = 0x%x "
3524 "****n", mb[0]);
3526 LEAVE("qla1280_mailbox_command");
3527 return status;
3531 * qla1280_poll
3532 * Polls ISP for interrupts.
3534 * Input:
3535 * ha = adapter block pointer.
3537 static void
3538 qla1280_poll(struct scsi_qla_host *ha)
3540 struct device_reg *reg = ha->iobase;
3541 uint16_t data;
3542 srb_t *done_q_first = 0;
3543 srb_t *done_q_last = 0;
3545 /* ENTER("qla1280_poll"); */
3547 /* Check for pending interrupts. */
3548 data = RD_REG_WORD(&reg->istatus);
3549 if (data & RISC_INT)
3550 qla1280_isr(ha, &done_q_first, &done_q_last);
3552 if (!ha->flags.mbox_busy) {
3553 if (ha->flags.isp_abort_needed)
3554 qla1280_abort_isp(ha);
3555 if (ha->flags.reset_marker)
3556 qla1280_rst_aen(ha);
3559 if (done_q_first)
3560 qla1280_done(ha, &done_q_first, &done_q_last);
3562 /* LEAVE("qla1280_poll"); */
3566 * qla1280_bus_reset
3567 * Issue SCSI bus reset.
3569 * Input:
3570 * ha = adapter block pointer.
3571 * bus = SCSI bus number.
3573 * Returns:
3574 * 0 = success
3576 static int
3577 qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
3579 uint16_t mb[MAILBOX_REGISTER_COUNT];
3580 int status;
3582 dprintk(3, "qla1280_bus_reset: entered\n");
3584 if (qla1280_verbose)
3585 printk(KERN_INFO "scsi(%li): Resetting SCSI BUS (%i)\n",
3586 ha->host_no, bus);
3588 mb[0] = MBC_BUS_RESET;
3589 mb[1] = ha->bus_settings[bus].bus_reset_delay;
3590 mb[2] = (uint16_t) bus;
3591 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
3593 if (status) {
3594 if (ha->bus_settings[bus].failed_reset_count > 2) /* dg - 03/13/99 */
3595 ha->bus_settings[bus].scsi_bus_dead = TRUE;
3596 ha->bus_settings[bus].failed_reset_count++;
3597 } else {
3599 * Eeeeep! This is evil! /Jes
3601 #if 0
3602 mdelay(4000);
3603 #else
3604 schedule_timeout(4 * HZ);
3605 #endif
3606 ha->bus_settings[bus].scsi_bus_dead = FALSE; /* dg - 03/13/99 */
3607 ha->bus_settings[bus].failed_reset_count = 0;
3608 /* Issue marker command. */
3609 qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
3612 if (status)
3613 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
3614 else
3615 dprintk(3, "qla1280_bus_reset: exiting normally\n");
3617 return status;
3621 * qla1280_device_reset
3622 * Issue bus device reset message to the target.
3624 * Input:
3625 * ha = adapter block pointer.
3626 * bus = SCSI BUS number.
3627 * target = SCSI ID.
3629 * Returns:
3630 * 0 = success
3632 static int
3633 qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
3635 uint16_t mb[MAILBOX_REGISTER_COUNT];
3636 int status;
3638 ENTER("qla1280_device_reset");
3640 mb[0] = MBC_ABORT_TARGET;
3641 mb[1] = (bus ? (target | BIT_7) : target) << 8;
3642 mb[2] = 1;
3643 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
3645 /* Issue marker command. */
3646 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
3648 if (status)
3649 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
3651 LEAVE("qla1280_device_reset");
3652 return status;
3656 * qla1280_abort_device
3657 * Issue an abort message to the device
3659 * Input:
3660 * ha = adapter block pointer.
3661 * bus = SCSI BUS.
3662 * target = SCSI ID.
3663 * lun = SCSI LUN.
3665 * Returns:
3666 * 0 = success
3668 static int
3669 qla1280_abort_device(struct scsi_qla_host *ha, int bus, int target, int lun)
3671 uint16_t mb[MAILBOX_REGISTER_COUNT];
3672 int status;
3674 ENTER("qla1280_abort_device");
3676 mb[0] = MBC_ABORT_DEVICE;
3677 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
3678 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
3680 /* Issue marker command. */
3681 qla1280_marker(ha, bus, target, lun, MK_SYNC_ID_LUN);
3683 if (status)
3684 dprintk(2, "qla1280_abort_device: **** FAILED ****\n");
3686 LEAVE("qla1280_abort_device");
3687 return status;
3691 * qla1280_abort_command
3692 * Abort command aborts a specified IOCB.
3694 * Input:
3695 * ha = adapter block pointer.
3696 * sp = SB structure pointer.
3698 * Returns:
3699 * 0 = success
3701 static int
3702 qla1280_abort_command(struct scsi_qla_host *ha, srb_t * sp)
3704 uint16_t mb[MAILBOX_REGISTER_COUNT];
3705 unsigned int bus, target, lun;
3706 uint32_t handle;
3707 int status;
3709 ENTER("qla1280_abort_command");
3711 /* Locate handle number. */
3712 for (handle = 0; handle < MAX_OUTSTANDING_COMMANDS; handle++)
3713 if (ha->outstanding_cmds[handle] == sp)
3714 break;
3716 bus = SCSI_BUS_32(sp->cmd);
3717 target = SCSI_TCN_32(sp->cmd);
3718 lun = SCSI_LUN_32(sp->cmd);
3720 mb[0] = MBC_ABORT_COMMAND;
3721 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
3722 mb[2] = handle >> 16;
3723 mb[3] = handle & 0xffff;
3724 status =
3725 qla1280_mailbox_command(ha, BIT_3 | BIT_2 | BIT_1 | BIT_0, &mb[0]);
3727 if (status)
3728 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
3730 sp->flags |= SRB_ABORT_PENDING;
3732 LEAVE("qla1280_abort_command");
3733 return status;
3737 * qla1280_reset_adapter
3738 * Reset adapter.
3740 * Input:
3741 * ha = adapter block pointer.
3743 static void
3744 qla1280_reset_adapter(struct scsi_qla_host *ha)
3746 struct device_reg *reg = ha->iobase;
3748 ENTER("qla1280_reset_adapter");
3750 /* Disable ISP chip */
3751 ha->flags.online = FALSE;
3752 WRT_REG_WORD(&reg->ictrl, ISP_RESET);
3753 WRT_REG_WORD(&reg->host_cmd, HC_RESET_RISC);
3754 WRT_REG_WORD(&reg->host_cmd, HC_RELEASE_RISC);
3755 WRT_REG_WORD(&reg->host_cmd, HC_DISABLE_BIOS);
3757 LEAVE("qla1280_reset_adapter");
3761 * Issue marker command.
3762 * Function issues marker IOCB.
3764 * Input:
3765 * ha = adapter block pointer.
3766 * bus = SCSI BUS number
3767 * id = SCSI ID
3768 * lun = SCSI LUN
3769 * type = marker modifier
3771 static void
3772 qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
3774 mrk_entry_t *pkt;
3776 ENTER("qla1280_marker");
3778 /* Get request packet. */
3779 if ((pkt = (mrk_entry_t *) qla1280_req_pkt(ha))) {
3780 pkt->entry_type = MARKER_TYPE;
3781 pkt->lun = (uint8_t) lun;
3782 pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
3783 pkt->modifier = type;
3785 /* Issue command to ISP */
3786 qla1280_isp_cmd(ha);
3789 LEAVE("qla1280_marker");
3792 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,18)
3794 * qla1280_64bit_start_scsi
3795 * The start SCSI is responsible for building request packets on
3796 * request ring and modifying ISP input pointer.
3798 * Input:
3799 * ha = adapter block pointer.
3800 * sp = SB structure pointer.
3802 * Returns:
3803 * 0 = success, was able to issue command.
3805 static int
3806 qla1280_64bit_start_scsi(struct scsi_qla_host *ha, srb_t * sp)
3808 struct device_reg *reg = ha->iobase;
3809 Scsi_Cmnd *cmd = sp->cmd;
3810 cmd_a64_entry_t *pkt;
3811 struct scatterlist *sg = NULL;
3812 u32 *dword_ptr;
3813 dma_addr_t dma_handle;
3814 int status = 0;
3815 int cnt;
3816 int req_cnt;
3817 u16 seg_cnt;
3819 ENTER("qla1280_64bit_start_scsi:");
3821 dprintk(1, "64bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
3822 cmd->cmnd[0]);
3824 /* Calculate number of entries and segments required. */
3825 req_cnt = 1;
3826 if (cmd->use_sg) { /* 3.13 64 bit */
3827 sg = (struct scatterlist *) cmd->request_buffer;
3828 seg_cnt = pci_map_sg (ha->pdev, sg, cmd->use_sg,
3829 scsi_to_pci_dma_dir(cmd->sc_data_direction));
3831 if (seg_cnt > 2) {
3832 req_cnt += (seg_cnt - 2) / 5;
3833 if ((seg_cnt - 2) % 5)
3834 req_cnt++;
3836 } else if (cmd->request_bufflen) { /* If data transfer. */
3837 seg_cnt = 1;
3838 } else {
3839 seg_cnt = 0;
3842 if ((req_cnt + 2) >= ha->req_q_cnt) {
3843 /* Calculate number of free request entries. */
3844 cnt = RD_REG_WORD(&reg->mailbox4);
3845 if (ha->req_ring_index < cnt)
3846 ha->req_q_cnt = cnt - ha->req_ring_index;
3847 else
3848 ha->req_q_cnt =
3849 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3852 /* If room for request in request ring. */
3853 if ((req_cnt + 2) < ha->req_q_cnt) {
3854 /* Check for room in outstanding command list. */
3855 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS &&
3856 ha->outstanding_cmds[cnt] != 0; cnt++) ;
3858 if (cnt < MAX_OUTSTANDING_COMMANDS) {
3859 ha->outstanding_cmds[cnt] = sp;
3860 ha->req_q_cnt -= req_cnt;
3861 CMD_HANDLE(sp->cmd) =
3862 (unsigned char *)(unsigned long)cnt;
3865 * Build command packet.
3867 pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
3869 pkt->entry_type = COMMAND_A64_TYPE;
3870 pkt->entry_count = (uint8_t) req_cnt;
3871 pkt->sys_define = (uint8_t) ha->req_ring_index;
3872 pkt->handle = (uint32_t) cnt;
3874 /* Zero out remaining portion of packet. */
3875 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3877 /* Set ISP command timeout. */
3878 pkt->timeout = 30;
3880 /* Set device target ID and LUN */
3881 pkt->lun = SCSI_LUN_32(cmd);
3882 pkt->target = SCSI_BUS_32(cmd) ?
3883 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3885 /* Enable simple tag queuing if device supports it. */
3886 if (cmd->device->tagged_queue)
3887 pkt->control_flags |= BIT_3;
3889 /* Load SCSI command packet. */
3890 pkt->cdb_len = (uint16_t)CMD_CDBLEN(cmd);
3891 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), pkt->cdb_len);
3892 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3895 * Load data segments.
3897 if (seg_cnt) { /* If data transfer. */
3898 /* Set transfer direction. */
3899 if ((cmd->data_cmnd[0] == WRITE_6))
3900 pkt->control_flags |= BIT_6;
3901 else
3902 pkt->control_flags |= (BIT_5 | BIT_6);
3904 sp->dir = pkt->control_flags & (BIT_5 | BIT_6);
3906 /* Set total data segment count. */
3907 pkt->dseg_count = seg_cnt;
3909 /* Setup packet address segment pointer. */
3910 dword_ptr = (u32 *)&pkt->dseg_0_address;
3912 if (cmd->use_sg) { /* If scatter gather */
3913 /* Load command entry data segments. */
3914 for (cnt = 0; cnt < 2 && seg_cnt;
3915 cnt++, seg_cnt--) {
3916 /* 3.13 64 bit */
3917 *dword_ptr++ =
3918 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3919 *dword_ptr++ =
3920 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg)));
3921 *dword_ptr++ =
3922 cpu_to_le32(sg_dma_len(sg));
3923 sg++;
3924 dprintk(1,
3925 "S/G Segment phys_addr=%x %x, len=0x%x\n",
3926 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg))),
3927 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
3928 cpu_to_le32(sg_dma_len(sg)));
3930 dprintk(5,
3931 "qla1280_64bit_start_scsi: Scatter/gather "
3932 "command packet data - b %i, t %i, l %i \n",
3933 SCSI_BUS_32(cmd),
3934 SCSI_TCN_32(cmd),
3935 SCSI_LUN_32(cmd));
3936 qla1280_dump_buffer(5, (char *)pkt,
3937 REQUEST_ENTRY_SIZE);
3940 * Build continuation packets.
3942 dprintk(1,
3943 "S/G Building Continuation...seg_cnt=0x%x "
3944 "remains\n", seg_cnt);
3946 while (seg_cnt > 0) {
3947 /* Adjust ring index. */
3948 ha->req_ring_index++;
3949 if (ha->req_ring_index ==
3950 REQUEST_ENTRY_CNT) {
3951 ha->req_ring_index = 0;
3952 ha->request_ring_ptr =
3953 ha->request_ring;
3954 } else
3955 ha->request_ring_ptr++;
3957 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
3959 /* Zero out packet. */
3960 memset(pkt, 0,
3961 REQUEST_ENTRY_SIZE);
3963 /* Load packet defaults. */
3964 ((cont_a64_entry_t *) pkt)->entry_type =
3965 CONTINUE_A64_TYPE;
3966 ((cont_a64_entry_t *) pkt)->entry_count = 1;
3967 ((cont_a64_entry_t *) pkt)->sys_define =
3968 (uint8_t)ha->req_ring_index;
3969 /* Setup packet address segment pointer. */
3970 dword_ptr =
3971 (u32 *)&((cont_a64_entry_t *) pkt)->dseg_0_address;
3973 /* Load continuation entry data segments. */
3974 for (cnt = 0;
3975 cnt < 5 && seg_cnt;
3976 cnt++, seg_cnt--) {
3977 /* 3.13 64 bit */
3978 *dword_ptr++ =
3979 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
3980 *dword_ptr++ =
3981 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg)));
3982 *dword_ptr++ =
3983 cpu_to_le32(sg_dma_len(sg));
3984 dprintk(1,
3985 "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
3986 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg))),
3987 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
3988 cpu_to_le32(sg_dma_len(sg)));
3989 sg++;
3991 dprintk(5,
3992 "qla1280_64bit_start_scsi: continuation "
3993 "packet data - b %i, t %i, l %i \n",
3994 SCSI_BUS_32(cmd),
3995 SCSI_TCN_32(cmd),
3996 SCSI_LUN_32(cmd));
3997 qla1280_dump_buffer(5,
3998 (char *)pkt,
3999 REQUEST_ENTRY_SIZE);
4001 } else { /* No scatter gather data transfer */
4002 /* 3.13 64 bit */
4003 dma_handle = pci_map_single(ha->pdev,
4004 cmd->request_buffer,
4005 cmd->request_bufflen,
4006 scsi_to_pci_dma_dir(cmd->sc_data_direction));
4007 /* save dma_handle for pci_unmap_single */
4008 sp->saved_dma_handle = dma_handle;
4010 *dword_ptr++ =
4011 cpu_to_le32(pci_dma_lo32(dma_handle));
4012 *dword_ptr++ =
4013 cpu_to_le32(pci_dma_hi32(dma_handle));
4014 *dword_ptr =
4015 (uint32_t)cmd->request_bufflen;
4016 /* dprintk(1,
4017 "No S/G map_single saved_dma_handle=%lx\n",dma_handle);
4019 dprintk(5,
4020 "qla1280_64bit_start_scsi: No scatter/gather "
4021 "command packet data - b %i, t %i, l %i \n",
4022 SCSI_BUS_32(cmd),
4023 SCSI_TCN_32(cmd),
4024 SCSI_LUN_32(cmd));
4025 qla1280_dump_buffer(5, (char *)pkt,
4026 REQUEST_ENTRY_SIZE);
4028 } else { /* No data transfer */
4030 dword_ptr = (uint32_t *)(pkt + 1);
4031 *dword_ptr++ = 0;
4032 *dword_ptr++ = 0;
4033 *dword_ptr = 0;
4034 dprintk(5,
4035 "qla1280_64bit_start_scsi: No data, command "
4036 "packet data - b %i, t %i, l %i \n",
4037 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
4038 SCSI_LUN_32(cmd));
4039 qla1280_dump_buffer(5, (char *)pkt,
4040 REQUEST_ENTRY_SIZE);
4042 /* Adjust ring index. */
4043 ha->req_ring_index++;
4044 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
4045 ha->req_ring_index = 0;
4046 ha->request_ring_ptr = ha->request_ring;
4047 } else
4048 ha->request_ring_ptr++;
4050 /* Set chip new ring index. */
4051 dprintk(1,
4052 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
4053 ha->qthreads--;
4054 sp->flags |= SRB_SENT;
4055 ha->actthreads++;
4056 WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
4057 } else {
4058 status = 1;
4059 dprintk(2, "qla1280_64bit_start_scsi: NO ROOM IN "
4060 "OUTSTANDING ARRAY, req_q_cnt=0x%x",
4061 ha->req_q_cnt);
4063 } else {
4064 status = 1;
4065 dprintk(2,
4066 "qla1280_64bit_start_scsi: in-ptr=0x%x req_q_cnt=0x%x"
4067 "req_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
4068 req_cnt);
4071 if (status)
4072 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
4073 else
4074 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
4076 return status;
4078 #endif
4081 * qla1280_32bit_start_scsi
4082 * The start SCSI is responsible for building request packets on
4083 * request ring and modifying ISP input pointer.
4085 * The Qlogic firmware interface allows every queue slot to have a SCSI
4086 * command and up to 4 scatter/gather (SG) entries. If we need more
4087 * than 4 SG entries, then continuation entries are used that can
4088 * hold another 7 entries each. The start routine determines if there
4089 * is eought empty slots then build the combination of requests to
4090 * fulfill the OS request.
4092 * Input:
4093 * ha = adapter block pointer.
4094 * sp = SCSI Request Block structure pointer.
4096 * Returns:
4097 * 0 = success, was able to issue command.
4099 static int
4100 qla1280_32bit_start_scsi(struct scsi_qla_host *ha, srb_t * sp)
4102 struct device_reg *reg = ha->iobase;
4103 Scsi_Cmnd *cmd = sp->cmd;
4104 cmd_entry_t *pkt;
4105 struct scatterlist *sg = NULL;
4106 uint32_t *dword_ptr;
4107 int status = 0;
4108 int cnt;
4109 int req_cnt;
4110 uint16_t seg_cnt;
4111 dma_addr_t dma_handle;
4113 ENTER("qla1280_32bit_start_scsi");
4115 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
4116 cmd->cmnd[0]);
4118 /* Calculate number of entries and segments required. */
4119 req_cnt = 1;
4120 if (cmd->use_sg) {
4122 * We must build an SG list in adapter format, as the kernel's SG list
4123 * cannot be used directly because of data field size (__alpha__)
4124 * differences and the kernel SG list uses virtual addresses where
4125 * we need physical addresses.
4127 sg = (struct scatterlist *) cmd->request_buffer;
4128 /* 3.13 32 bit */
4129 seg_cnt = pci_map_sg (ha->pdev, sg, cmd->use_sg,
4130 scsi_to_pci_dma_dir(cmd->sc_data_direction));
4133 * if greater than four sg entries then we need to allocate
4134 * continuation entries
4136 if (seg_cnt > 4) {
4137 req_cnt += (seg_cnt - 4) / 7;
4138 if ((seg_cnt - 4) % 7)
4139 req_cnt++;
4141 dprintk(1, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
4142 cmd, seg_cnt, req_cnt);
4143 } else if (cmd->request_bufflen) { /* If data transfer. */
4144 dprintk(1, "No S/G transfer t=%x cmd=%p len=%x CDB=%x\n",
4145 SCSI_TCN_32(cmd), cmd, cmd->request_bufflen,
4146 cmd->cmnd[0]);
4147 seg_cnt = 1;
4148 } else {
4149 /* dprintk(1, "No data transfer \n"); */
4150 seg_cnt = 0;
4153 if ((req_cnt + 2) >= ha->req_q_cnt) {
4154 /* Calculate number of free request entries. */
4155 cnt = RD_REG_WORD(&reg->mailbox4);
4156 if (ha->req_ring_index < cnt)
4157 ha->req_q_cnt = cnt - ha->req_ring_index;
4158 else
4159 ha->req_q_cnt =
4160 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
4163 dprintk(1, "Number of free entries=(%d) seg_cnt=0x%x\n",
4164 ha->req_q_cnt, seg_cnt);
4165 /* If room for request in request ring. */
4166 if ((req_cnt + 2) < ha->req_q_cnt) {
4167 /* Check for empty slot in outstanding command list. */
4168 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS &&
4169 (ha->outstanding_cmds[cnt] != 0); cnt++) ;
4171 if (cnt < MAX_OUTSTANDING_COMMANDS) {
4172 CMD_HANDLE(sp->cmd) =
4173 (unsigned char *) (unsigned long) cnt;
4174 ha->outstanding_cmds[cnt] = sp;
4175 ha->req_q_cnt -= req_cnt;
4178 * Build command packet.
4180 pkt = (cmd_entry_t *) ha->request_ring_ptr;
4182 pkt->entry_type = COMMAND_TYPE;
4183 pkt->entry_count = (uint8_t) req_cnt;
4184 pkt->sys_define = (uint8_t) ha->req_ring_index;
4185 pkt->handle = (uint32_t) cnt;
4187 /* Zero out remaining portion of packet. */
4188 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
4190 /* Set ISP command timeout. */
4191 pkt->timeout = 30;
4193 /* Set device target ID and LUN */
4194 pkt->lun = SCSI_LUN_32(cmd);
4195 pkt->target = SCSI_BUS_32(cmd) ?
4196 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
4198 /* Enable simple tag queuing if device supports it. */
4199 if (cmd->device->tagged_queue)
4200 pkt->control_flags |= BIT_3;
4202 /* Load SCSI command packet. */
4203 pkt->cdb_len = (uint16_t) CMD_CDBLEN(cmd);
4204 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), pkt->cdb_len);
4206 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
4208 * Load data segments.
4210 if (seg_cnt) {
4211 /* Set transfer direction (READ and WRITE) */
4212 /* Linux doesn't tell us */
4214 * For block devices, cmd->request->cmd has the operation
4215 * For character devices, this isn't always set properly, so
4216 * we need to check data_cmnd[0]. This catches the conditions
4217 * for st.c, but not sg. Generic commands are pass down to us.
4219 if ((cmd->data_cmnd[0] == WRITE_6))
4220 pkt->control_flags |= BIT_6;
4221 else
4222 pkt->control_flags |= (BIT_5 | BIT_6);
4224 sp->dir = pkt->control_flags & (BIT_5 | BIT_6);
4226 /* Set total data segment count. */
4227 pkt->dseg_count = seg_cnt;
4229 /* Setup packet address segment pointer. */
4230 dword_ptr = &pkt->dseg_0_address;
4232 if (cmd->use_sg) { /* If scatter gather */
4233 dprintk(1, "Building S/G data "
4234 "segments..\n");
4235 qla1280_dump_buffer(1, (char *)sg,
4236 4 * 16);
4238 /* Load command entry data segments. */
4239 for (cnt = 0; cnt < 4 && seg_cnt;
4240 cnt++, seg_cnt--) {
4241 /* 3.13 32 bit */
4242 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
4243 *dword_ptr++ =
4244 cpu_to_le32(virt_to_bus(sg->address));
4245 *dword_ptr++ = sg->length;
4246 dprintk(1,
4247 "S/G Segment phys_addr=0x%x, len=0x%x\n",
4248 cpu_to_le32(virt_to_bus(sg->address)),
4249 sg->length);
4250 #else
4251 *dword_ptr++ =
4252 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
4253 *dword_ptr++ =
4254 cpu_to_le32(sg_dma_len(sg));
4255 dprintk(1, "S/G Segment phys_addr=0x%x, len=0x%x\n",
4256 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
4257 cpu_to_le32(sg_dma_len(sg)));
4258 #endif
4259 sg++;
4262 * Build continuation packets.
4264 dprintk(1, "S/G Building Continuation"
4265 "...seg_cnt=0x%x remains\n",
4266 seg_cnt);
4267 while (seg_cnt > 0) {
4268 /* Adjust ring index. */
4269 ha->req_ring_index++;
4270 if (ha->req_ring_index ==
4271 REQUEST_ENTRY_CNT) {
4272 ha->req_ring_index = 0;
4273 ha->request_ring_ptr =
4274 ha->request_ring;
4275 } else
4276 ha->request_ring_ptr++;
4278 pkt = (cmd_entry_t *)
4279 ha->request_ring_ptr;
4281 /* Zero out packet. */
4282 memset(pkt, 0,
4283 REQUEST_ENTRY_SIZE);
4285 /* Load packet defaults. */
4286 ((cont_entry_t *) pkt)->
4287 entry_type = CONTINUE_TYPE;
4288 ((cont_entry_t *) pkt)->
4289 entry_count = 1;
4291 ((cont_entry_t *) pkt)->
4292 sys_define =
4293 (uint8_t) ha->
4294 req_ring_index;
4296 /* Setup packet address segment pointer. */
4297 dword_ptr =
4298 &((cont_entry_t *) pkt)->dseg_0_address;
4300 /* Load continuation entry data segments. */
4301 for (cnt = 0;
4302 cnt < 7 && seg_cnt;
4303 cnt++, seg_cnt--) {
4304 /* 3.13 32 bit */
4305 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
4306 *dword_ptr++ =
4307 cpu_to_le32(virt_to_bus(sg->address));
4308 *dword_ptr++ = sg->length;
4309 dprintk(1,
4310 "S/G Segment Cont. phys_addr=0x%x, len=0x%x\n",
4311 cpu_to_le32(pci_dma_lo32(virt_to_bus(sg->address))), sg->length);
4312 #else
4313 *dword_ptr++ =
4314 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg)));
4315 *dword_ptr++ =
4316 cpu_to_le32(sg_dma_len(sg));
4317 dprintk(1,
4318 "S/G Segment Cont. phys_addr=0x%x, "
4319 "len=0x%x\n",
4320 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg))),
4321 cpu_to_le32(sg_dma_len(sg)));
4322 #endif
4323 sg++;
4325 dprintk(5,
4326 "qla1280_32bit_start_scsi: continuation "
4327 "packet data - scsi(%i:%i:%i)\n",
4328 SCSI_BUS_32(cmd),
4329 SCSI_TCN_32(cmd),
4330 SCSI_LUN_32(cmd));
4331 qla1280_dump_buffer(5,
4332 (char *)pkt,
4333 REQUEST_ENTRY_SIZE);
4335 } else { /* No S/G data transfer */
4337 /* 3.13 32 bit */
4338 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
4339 *dword_ptr++ =
4340 cpu_to_le32 (virt_to_bus
4341 (cmd->request_buffer));
4342 #else
4343 dma_handle = pci_map_single(ha->pdev,
4344 cmd->request_buffer,
4345 cmd->request_bufflen,
4346 scsi_to_pci_dma_dir(cmd->sc_data_direction));
4347 sp->saved_dma_handle = dma_handle;
4349 *dword_ptr++ =
4350 cpu_to_le32(pci_dma_lo32(dma_handle));
4351 #endif
4352 *dword_ptr =
4353 (uint32_t)cmd->request_bufflen;
4355 } else { /* No data transfer at all */
4357 dword_ptr = (uint32_t *)(pkt + 1);
4358 *dword_ptr++ = 0;
4359 *dword_ptr = 0;
4360 dprintk(5,
4361 "qla1280_32bit_start_scsi: No data, command "
4362 "packet data - \n");
4363 qla1280_dump_buffer(5, (char *)pkt,
4364 REQUEST_ENTRY_SIZE);
4366 dprintk(5,
4367 "qla1280_32bit_start_scsi: First IOCB block:\n");
4368 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
4369 REQUEST_ENTRY_SIZE);
4371 /* Adjust ring index. */
4372 ha->req_ring_index++;
4373 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
4374 ha->req_ring_index = 0;
4375 ha->request_ring_ptr = ha->request_ring;
4376 } else
4377 ha->request_ring_ptr++;
4379 /* Set chip new ring index. */
4380 dprintk(1, "qla1280_32bit_start_scsi: Wakeup RISC "
4381 "for pending command\n");
4382 ha->qthreads--;
4383 sp->flags |= SRB_SENT;
4384 ha->actthreads++;
4385 WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
4386 } else {
4387 status = 1;
4388 dprintk(2,
4389 "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
4390 "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
4392 } else {
4393 status = 1;
4394 dprintk(2,
4395 "qla1280_32bit_start_scsi: in-ptr=0x%x, req_q_cnt=0x%x, "
4396 "req_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
4397 req_cnt);
4400 if (status)
4401 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
4403 LEAVE("qla1280_32bit_start_scsi");
4405 return status;
4409 * qla1280_req_pkt
4410 * Function is responsible for locking ring and
4411 * getting a zeroed out request packet.
4413 * Input:
4414 * ha = adapter block pointer.
4416 * Returns:
4417 * 0 = failed to get slot.
4419 static request_t *
4420 qla1280_req_pkt(struct scsi_qla_host *ha)
4422 struct device_reg *reg = ha->iobase;
4423 request_t *pkt = 0;
4424 int cnt;
4425 uint32_t timer;
4427 ENTER("qla1280_req_pkt");
4430 * This can be called from interrupt context, damn it!!!
4432 /* Wait for 30 seconds for slot. */
4433 for (timer = 15000000; timer; timer--) {
4434 if (ha->req_q_cnt > 0) {
4435 /* Calculate number of free request entries. */
4436 cnt = RD_REG_WORD(&reg->mailbox4);
4437 if (ha->req_ring_index < cnt)
4438 ha->req_q_cnt = cnt - ha->req_ring_index;
4439 else
4440 ha->req_q_cnt =
4441 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
4444 /* Found empty request ring slot? */
4445 if (ha->req_q_cnt > 0) {
4446 ha->req_q_cnt--;
4447 pkt = ha->request_ring_ptr;
4449 /* Zero out packet. */
4450 memset(pkt, 0, REQUEST_ENTRY_SIZE);
4452 /* Set system defined field. */
4453 pkt->sys_define = (uint8_t) ha->req_ring_index;
4455 /* Set entry count. */
4456 pkt->entry_count = 1;
4458 break;
4461 udelay(2); /* 10 */
4463 /* Check for pending interrupts. */
4464 qla1280_poll(ha);
4467 if (!pkt)
4468 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
4469 else
4470 dprintk(3, "qla1280_req_pkt: exiting normally\n");
4472 return pkt;
4476 * qla1280_isp_cmd
4477 * Function is responsible for modifying ISP input pointer.
4478 * Releases ring lock.
4480 * Input:
4481 * ha = adapter block pointer.
4483 static void
4484 qla1280_isp_cmd(struct scsi_qla_host *ha)
4486 struct device_reg *reg = ha->iobase;
4488 ENTER("qla1280_isp_cmd");
4490 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
4491 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
4492 REQUEST_ENTRY_SIZE);
4494 /* Adjust ring index. */
4495 ha->req_ring_index++;
4496 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
4497 ha->req_ring_index = 0;
4498 ha->request_ring_ptr = ha->request_ring;
4499 } else
4500 ha->request_ring_ptr++;
4502 /* Set chip new ring index. */
4503 WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
4505 LEAVE("qla1280_isp_cmd");
4508 #if QL1280_LUN_SUPPORT
4510 * qla1280_enable_lun
4511 * Issue enable LUN entry IOCB.
4513 * Input:
4514 * ha = adapter block pointer.
4515 * bus = SCSI BUS number.
4516 * lun = LUN number.
4518 static void
4519 qla1280_enable_lun(struct scsi_qla_host *ha, int bus, int lun)
4521 elun_entry_t *pkt;
4523 ENTER("qla1280_enable_lun");
4525 /* Get request packet. */
4527 if (pkt = (elun_entry_t *)qla1280_req_pkt(ha))
4529 pkt->entry_type = ENABLE_LUN_TYPE;
4530 pkt->lun = (uint16_t)(bus ? lun | BIT_15 : lun);
4531 pkt->command_count = 32;
4532 pkt->immed_notify_count = 1;
4533 pkt->group_6_length = MAX_CMDSZ;
4534 pkt->group_7_length = MAX_CMDSZ;
4535 pkt->timeout = 0x30;
4537 qla1280_isp_cmd(ha);
4540 pkt = (elun_entry_t *) 1;
4542 if (!pkt)
4543 dprintk(2, "qla1280_enable_lun: **** FAILED ****\n");
4544 else
4545 dprintk(3, "qla1280_enable_lun: exiting normally\n");
4547 #endif
4549 #if QL1280_TARGET_MODE_SUPPORT
4550 /****************************************************************************/
4551 /* Target Mode Support Functions. */
4552 /****************************************************************************/
4555 * qla1280_notify_ack
4556 * Issue notify acknowledge IOCB.
4557 * If sequence ID is zero, acknowledgement of
4558 * SCSI bus reset or bus device reset is assumed.
4560 * Input:
4561 * ha = adapter block pointer.
4562 * inotify = immediate notify entry pointer.
4564 static void
4565 qla1280_notify_ack(struct scsi_qla_host *ha, notify_entry_t * inotify)
4567 nack_entry_t *pkt;
4569 dprintk(3, "qla1280_notify_ack: entered\n");
4571 /* Get request packet. */
4572 if (pkt = (nack_entry_t *) qla1280_req_pkt(ha)) {
4573 pkt->entry_type = NOTIFY_ACK_TYPE;
4574 pkt->lun = inotify->lun;
4575 pkt->initiator_id = inotify->initiator_id;
4576 pkt->target_id = inotify->target_id;
4577 if (inotify->seq_id == 0)
4578 pkt->event = BIT_7;
4579 else
4580 pkt->seq_id = inotify->seq_id;
4582 /* Issue command to ISP */
4583 qla1280_isp_cmd(ha);
4586 if (!pkt)
4587 dprintk(2, "qla1280_notify_ack: **** FAILED ****\n");
4588 else
4589 dprintk(3, "qla1280_notify_ack: exiting normally\n");
4593 * qla1280_immed_notify
4594 * Issue immediate notify IOCB for LUN 0.
4596 * Input:
4597 * ha = adapter block pointer.
4598 * inotify = immediate notify entry pointer.
4600 static void
4601 qla1280_immed_notify(struct scsi_qla_host *ha, notify_entry_t * inotify)
4603 notify_entry_t *pkt;
4605 dprintk(3, "qla1280_immed_notify: entered\n");
4607 /* Get request packet. */
4608 if (pkt = (notify_entry_t *) qla1280_req_pkt(ha)) {
4609 pkt->entry_type = IMMED_NOTIFY_TYPE;
4610 pkt->lun = inotify->lun;
4611 pkt->initiator_id = inotify->initiator_id;
4612 pkt->target_id = inotify->target_id;
4613 pkt->status = 1;
4615 /* Issue command to ISP */
4616 qla1280_isp_cmd(ha);
4619 if (!pkt)
4620 dprintk(2, "qla1280_immed_notify: **** FAILED ****\n");
4621 else
4622 dprintk(3, "qla1280_immed_notify: exiting normally\n");
4626 * qla1280_accept_io
4627 * Issue accept target I/O IOCB for LUN 0.
4629 * Input:
4630 * ha = adapter block pointer.
4631 * ctio = ctio returned entry pointer.
4633 static void
4634 qla1280_accept_io(struct scsi_qla_host *ha, ctio_ret_entry_t * ctio)
4636 atio_entry_t *pkt;
4638 dprintk(3, "qla1280_accept_io: entered\n");
4640 /* Get request packet. */
4641 if (pkt = (atio_entry_t *) qla1280_req_pkt(ha)) {
4642 pkt->entry_type = ACCEPT_TGT_IO_TYPE;
4643 pkt->lun = ctio->lun;
4644 pkt->initiator_id = ctio->initiator_id;
4645 pkt->target_id = ctio->target_id;
4646 pkt->tag_value = ctio->tag_value;
4647 pkt->status = 1;
4649 /* Issue command to ISP */
4650 qla1280_isp_cmd(ha);
4653 if (!pkt)
4654 dprintk(2, "qla1280_accept_io: **** FAILED ****\n");
4655 else
4656 dprintk(3, "qla1280_accept_io: exiting normally\n");
4660 * qla1280_64bit_continue_io
4661 * Issue continue target I/O IOCB.
4663 * Input:
4664 * ha = adapter block pointer.
4665 * atio = atio pointer.
4666 * len = total bytecount.
4667 * addr = physical address pointer.
4669 static void
4670 qla1280_64bit_continue_io(struct scsi_qla_host *ha, atio_entry_t * atio,
4671 uint32_t len, paddr32_t * addr)
4673 ctio_a64_entry_t *pkt;
4674 uint32_t *dword_ptr;
4676 dprintk(3, "qla1280_64bit_continue_io: entered\n");
4678 /* Get request packet. */
4679 if (pkt = (ctio_a64_entry_t *) qla1280_req_pkt(ha)) {
4680 pkt->entry_type = CTIO_A64_TYPE;
4681 pkt->lun = atio->lun;
4682 pkt->initiator_id = atio->initiator_id;
4683 pkt->target_id = atio->target_id;
4684 pkt->option_flags = atio->option_flags;
4685 pkt->tag_value = atio->tag_value;
4686 pkt->scsi_status = atio->scsi_status;
4688 if (len) {
4689 pkt->dseg_count = 1;
4690 pkt->transfer_length = len;
4691 pkt->dseg_0_length = len;
4692 dword_ptr = (uint32_t *) addr;
4693 pkt->dseg_0_address[0] = *dword_ptr++;
4694 pkt->dseg_0_address[1] = *dword_ptr;
4697 /* Issue command to ISP */
4698 qla1280_isp_cmd(ha);
4701 if (!pkt)
4702 dprintk(2, "qla1280_64bit_continue_io: **** FAILED ****\n");
4703 else
4704 dprintk(3, "qla1280_64bit_continue_io: exiting normally\n");
4708 * qla1280_32bit_continue_io
4709 * Issue continue target I/O IOCB.
4711 * Input:
4712 * ha = adapter block pointer.
4713 * atio = atio pointer.
4714 * len = total bytecount.
4715 * addr = physical address pointer.
4717 static void
4718 qla1280_32bit_continue_io(struct scsi_qla_host *ha, atio_entry_t * atio,
4719 uint32_t len, paddr32_t * addr)
4721 ctio_entry_t *pkt;
4722 uint32_t *dword_ptr;
4724 dprintk(3, "qla1280_32bit_continue_io: entered\n");
4726 /* Get request packet. */
4727 if (pkt = (ctio_entry_t *) qla1280_req_pkt(ha)) {
4728 pkt->entry_type = CONTINUE_TGT_IO_TYPE;
4729 pkt->lun = atio->lun;
4730 pkt->initiator_id = atio->initiator_id;
4731 pkt->target_id = atio->target_id;
4732 pkt->option_flags = atio->option_flags;
4733 pkt->tag_value = atio->tag_value;
4734 pkt->scsi_status = atio->scsi_status;
4736 if (len) {
4737 pkt->dseg_count = 1;
4738 pkt->transfer_length = len;
4739 pkt->dseg_0_length = len;
4740 dword_ptr = (uint32_t *) addr;
4741 pkt->dseg_0_address = *dword_ptr;
4744 /* Issue command to ISP */
4745 qla1280_isp_cmd(ha);
4748 if (!pkt)
4749 dprintk(2, "qla1280_32bit_continue_io: **** FAILED ****\n");
4750 else
4751 dprintk(3, "qla1280_32bit_continue_io: exiting normally\n");
4753 #endif /* QL1280_TARGET_MODE_SUPPORT */
4755 /****************************************************************************/
4756 /* Interrupt Service Routine. */
4757 /****************************************************************************/
4759 /****************************************************************************
4760 * qla1280_isr
4761 * Calls I/O done on command completion.
4763 * Input:
4764 * ha = adapter block pointer.
4765 * done_q_first = done queue first pointer.
4766 * done_q_last = done queue last pointer.
4767 ****************************************************************************/
4768 static void
4769 qla1280_isr(struct scsi_qla_host *ha, srb_t ** done_q_first,
4770 srb_t ** done_q_last)
4772 struct device_reg *reg = ha->iobase;
4773 response_t *pkt;
4774 srb_t *sp = 0;
4775 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
4776 uint16_t *wptr;
4777 uint32_t index;
4778 u16 istatus;
4780 ENTER("qla1280_isr");
4782 istatus = RD_REG_WORD(&reg->istatus);
4783 if (!(istatus & (RISC_INT | PCI_INT)))
4784 return;
4786 /* Save mailbox register 5 */
4787 mailbox[5] = RD_REG_WORD(&reg->mailbox5);
4789 /* Check for mailbox interrupt. */
4791 mailbox[0] = RD_REG_WORD(&reg->semaphore);
4793 if (mailbox[0] & BIT_0) {
4794 /* Get mailbox data. */
4795 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
4797 wptr = &mailbox[0];
4798 *wptr++ = RD_REG_WORD(&reg->mailbox0);
4799 *wptr++ = RD_REG_WORD(&reg->mailbox1);
4800 *wptr = RD_REG_WORD(&reg->mailbox2);
4801 if (mailbox[0] != MBA_SCSI_COMPLETION) {
4802 wptr++;
4803 *wptr++ = RD_REG_WORD(&reg->mailbox3);
4804 *wptr++ = RD_REG_WORD(&reg->mailbox4);
4805 wptr++;
4806 *wptr++ = RD_REG_WORD(&reg->mailbox6);
4807 *wptr = RD_REG_WORD(&reg->mailbox7);
4810 /* Release mailbox registers. */
4812 WRT_REG_WORD(&reg->semaphore, 0);
4813 WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
4815 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
4816 mailbox[0]);
4818 /* Handle asynchronous event */
4819 switch (mailbox[0]) {
4820 case MBA_SCSI_COMPLETION: /* Response completion */
4821 dprintk(5,
4822 "qla1280_isr: mailbox SCSI response completion\n");
4824 if (ha->flags.online) {
4825 /* Get outstanding command index. */
4826 index = mailbox[2] << 16 | mailbox[1];
4828 /* Validate handle. */
4829 if (index < MAX_OUTSTANDING_COMMANDS)
4830 sp = ha->outstanding_cmds[index];
4831 else
4832 sp = 0;
4834 if (sp) {
4835 /* Free outstanding command slot. */
4836 ha->outstanding_cmds[index] = 0;
4838 /* Save ISP completion status */
4839 CMD_RESULT(sp->cmd) = 0;
4841 /* Place block on done queue */
4842 sp->s_next = NULL;
4843 sp->s_prev = *done_q_last;
4844 if (!*done_q_first)
4845 *done_q_first = sp;
4846 else
4847 (*done_q_last)->s_next = sp;
4848 *done_q_last = sp;
4849 } else {
4851 * If we get here we have a real problem!
4853 printk(KERN_WARNING
4854 "qla1280: ISP invalid handle");
4855 ha->flags.isp_abort_needed = TRUE;
4858 break;
4860 case MBA_BUS_RESET: /* SCSI Bus Reset */
4861 ha->flags.reset_marker = TRUE;
4862 index = mailbox[6] & BIT_0;
4863 ha->bus_settings[index].reset_marker = TRUE;
4865 printk(KERN_DEBUG
4866 "qla1280_isr(): index %i asynchronous "
4867 "BUS_RESET\n", index);
4868 break;
4870 case MBA_SYSTEM_ERR: /* System Error */
4871 printk(KERN_WARNING
4872 "qla1280: ISP System Error - mbx1=%xh, mbx2=%xh, "
4873 "mbx3=%xh\n", mailbox[1], mailbox[2],
4874 mailbox[3]);
4875 ha->flags.isp_abort_needed = TRUE;
4876 break;
4878 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
4879 printk(KERN_WARNING
4880 "qla1280: ISP Request Transfer Error\n");
4881 ha->flags.isp_abort_needed = TRUE;
4882 break;
4884 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
4885 printk(KERN_WARNING
4886 "qla1280: ISP Response Transfer Error\n");
4887 ha->flags.isp_abort_needed = TRUE;
4888 break;
4890 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
4891 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
4892 break;
4894 case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
4895 dprintk(2,
4896 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
4897 break;
4899 case MBA_DEVICE_RESET: /* Bus Device Reset */
4900 dprintk(2,
4901 "qla1280_isr: asynchronous BUS_DEVICE_RESET\n");
4902 printk(KERN_INFO "qla1280_isr(): asynchronous "
4903 "BUS_DEVICE_RESET\n");
4905 ha->flags.reset_marker = TRUE;
4906 index = mailbox[6] & BIT_0;
4907 ha->bus_settings[index].reset_marker = TRUE;
4908 break;
4910 case MBA_BUS_MODE_CHANGE:
4911 dprintk(2,
4912 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
4913 break;
4915 default:
4916 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
4917 if (mailbox[0] < MBA_ASYNC_EVENT) {
4918 wptr = &mailbox[0];
4919 memcpy((uint16_t *) ha->mailbox_out, wptr,
4920 MAILBOX_REGISTER_COUNT *
4921 sizeof(uint16_t));
4922 ha->flags.mbox_int = TRUE;
4924 break;
4926 } else {
4927 WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
4931 * Response ring - waiting for the mbox_busy flag here seems
4932 * unnecessary as the mailbox data has been copied to ha->mailbox_out
4933 * by the time we actually get here!
4935 if (ha->flags.online
4936 #if 0
4937 && !ha->flags.mbox_busy
4938 #endif
4940 if (mailbox[5] < RESPONSE_ENTRY_CNT) {
4941 while (ha->rsp_ring_index != mailbox[5]) {
4942 pkt = ha->response_ring_ptr;
4944 dprintk(5,
4945 "qla1280_isr: ha->rsp_ring_index = 0x%x, "
4946 "mailbox[5] = 0x%x\n",
4947 ha->rsp_ring_index, mailbox[5]);
4948 dprintk(5,
4949 "qla1280_isr: response packet data\n");
4950 qla1280_dump_buffer(5, (char *)pkt,
4951 RESPONSE_ENTRY_SIZE);
4953 if (pkt->entry_type == STATUS_TYPE) {
4954 if ((pkt->scsi_status & 0xff)
4955 || pkt->comp_status
4956 || pkt->entry_status) {
4957 dprintk(2,
4958 "qla1280_isr: ha->rsp_ring_index = 0x%x"
4959 "mailbox[5] = 0x%x, comp_status = 0x%x, "
4960 "scsi_status = 0x%x\n",
4961 ha->rsp_ring_index,
4962 mailbox[5],
4963 pkt->comp_status,
4964 pkt->scsi_status);
4966 } else {
4967 dprintk(2,
4968 "qla1280_isr: ha->rsp_ring_index = 0x%x, "
4969 "mailbox[5] = 0x%x\n",
4970 ha->rsp_ring_index,
4971 mailbox[5]);
4972 dprintk(2,
4973 "qla1280_isr: response packet data\n");
4974 qla1280_dump_buffer(2, (char *)pkt,
4975 RESPONSE_ENTRY_SIZE);
4978 if (pkt->entry_type == STATUS_TYPE
4979 || pkt->entry_status) {
4980 if (pkt->entry_type == STATUS_TYPE)
4981 qla1280_status_entry(ha,
4982 (sts_entry_t *) pkt,
4983 done_q_first,
4984 done_q_last);
4985 else
4986 qla1280_error_entry(ha, pkt,
4987 done_q_first,
4988 done_q_last);
4990 /* Adjust ring index. */
4991 ha->rsp_ring_index++;
4992 if (ha->rsp_ring_index ==
4993 RESPONSE_ENTRY_CNT) {
4994 ha->rsp_ring_index = 0;
4995 ha->response_ring_ptr =
4996 ha->response_ring;
4997 } else
4998 ha->response_ring_ptr++;
4999 WRT_REG_WORD(&reg->mailbox5,
5000 ha->rsp_ring_index);
5002 #if QLA1280_TARGET_MODE_SUPPORT
5003 else {
5004 pkt = &response_entry;
5006 /* Copy packet. */
5007 dptr1 =
5008 (uint32_t *)ha->response_ring_ptr;
5009 dptr2 = (uint32_t *) pkt;
5010 for (index = 0;
5011 index < RESPONSE_ENTRY_SIZE / 4;
5012 index++)
5013 *dptr2++ = *dptr1++;
5015 /* Adjust ring index. */
5016 ha->rsp_ring_index++;
5017 if (ha->rsp_ring_index ==
5018 RESPONSE_ENTRY_CNT) {
5019 ha->rsp_ring_index = 0;
5020 ha->response_ring_ptr =
5021 ha->response_ring;
5022 } else
5023 ha->response_ring_ptr++;
5024 WRT_REG_WORD(&reg->mailbox5,
5025 ha->rsp_ring_index);
5027 switch (pkt->entry_type) {
5028 case ACCEPT_TGT_IO_TYPE:
5029 qla1280_atio_entry(ha,
5030 (atio_entry_t *) pkt);
5031 break;
5032 case IMMED_NOTIFY_TYPE:
5033 qla1280_notify_entry(ha,
5034 (notify_entry_t *) pkt);
5035 break;
5036 case CTIO_RET_TYPE:
5037 qla1280_accept_io(ha,
5038 (ctio_ret_entry_t *) pkt);
5039 break;
5040 default:
5041 break;
5044 #endif
5046 } else {
5047 ha->flags.isp_abort_needed = TRUE;
5048 dprintk(2, "qla1280_isr: Response pointer Error\n");
5052 LEAVE("qla1280_isr");
5056 * qla1280_rst_aen
5057 * Processes asynchronous reset.
5059 * Input:
5060 * ha = adapter block pointer.
5062 static void
5063 qla1280_rst_aen(struct scsi_qla_host *ha)
5065 #if QL1280_TARGET_MODE_SUPPORT
5066 notify_entry_t nentry;
5067 #endif
5068 uint8_t bus;
5070 ENTER("qla1280_rst_aen");
5072 if (ha->flags.online && !ha->flags.reset_active &&
5073 !ha->flags.abort_isp_active) {
5074 ha->flags.reset_active = TRUE;
5075 while (ha->flags.reset_marker) {
5076 /* Issue marker command. */
5077 ha->flags.reset_marker = FALSE;
5078 for (bus = 0; bus < ha->ports &&
5079 !ha->flags.reset_marker; bus++) {
5080 if (ha->bus_settings[bus].reset_marker) {
5081 ha->bus_settings[bus].reset_marker =
5082 FALSE;
5083 qla1280_marker(ha, bus, 0, 0,
5084 MK_SYNC_ALL);
5086 if (!ha->flags.reset_marker) {
5087 #if QL1280_TARGET_MODE_SUPPORT
5088 /* Issue notify acknowledgement command. */
5089 memset(&nentry, 0,
5090 sizeof(notify_entry_t));
5092 nentry.initiator_id =
5093 nentry.target_id =
5094 bus ? ha->bus_settings[bus].id | BIT_7 :
5095 ha->bus_settings[bus].id;
5096 qla1280_notify_entry(ha,
5097 &nentry);
5098 #endif
5099 /* Asynchronous event notification */
5106 LEAVE("qla1280_rst_aen");
5109 #if QL1280_TARGET_MODE_SUPPORT
5111 * qla1280_atio_entry
5112 * Processes received ISP accept target I/O entry.
5114 * Input:
5115 * ha = adapter block pointer.
5116 * pkt = entry pointer.
5118 static void
5119 qla1280_atio_entry(struct scsi_qla_host *ha, atio_entry_t * pkt)
5121 uint64_t *a64;
5122 uint64_t *end_a64;
5123 paddr32_t phy_addr[2];
5124 paddr32_t end_addr[2];
5125 uint32_t len;
5126 uint32_t offset;
5127 uint8_t t;
5128 uint8_t *sense_ptr;
5130 dprintk(3, "qla1280_atio_entry: entered\n");
5132 t = pkt->initiator_id;
5133 sense_ptr = ha->tsense + t * TARGET_SENSE_SIZE;
5134 a64 = (uint64_t *)&phy_addr[0];
5135 end_a64 = (uint64_t *)&end_addr[0];
5137 switch (pkt->status & ~BIT_7) {
5138 case 7: /* Path invalid */
5139 dprintk(2, "qla1280_atio_entry: Path invalid\n");
5140 break;
5142 case 0x14: /* Target Bus Phase Sequence Failure */
5143 dprintk(2, "qla1280_atio_entry: Target Bus Phase "
5144 "Sequence Failure\n");
5146 if (pkt->status & BIT_7) {
5147 memcpy(sense_ptr, &pkt->sense_data, TARGET_SENSE_SIZE);
5148 } else {
5149 memset(sense_ptr, 0, TARGET_SENSE_SIZE);
5150 *sense_ptr = 0x70;
5151 *(sense_ptr + 2) = SD_HARDERR;
5152 *(sense_ptr + 7) = TARGET_SENSE_SIZE - 8;
5153 *(sense_ptr + 12) = SC_SELFAIL;
5155 pkt->scsi_status = S_CKCON;
5156 pkt->option_flags |= OF_SSTS | OF_NO_DATA;
5158 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,18)
5159 if (ha->flags.enable_64bit_addressing)
5160 qla1280_64bit_continue_io(ha, pkt, 0, 0);
5161 else
5162 #endif
5163 qla1280_32bit_continue_io(ha, pkt, 0, 0);
5164 break;
5166 case 0x16: /* Requested Capability Not Available */
5167 dprintk(2, "qla1280_atio_entry: Target Bus Phase "
5168 "Sequence Failure\n");
5169 break;
5171 case 0x17: /* Bus Device Reset Message Received */
5172 dprintk(2, "qla1280_atio_entry: Target Bus Phase "
5173 "Sequence Failure\n");
5174 break;
5176 case 0x3D: /* CDB Received */
5178 /* Check for invalid LUN */
5179 if (pkt->lun && pkt->cdb[0] != SS_INQUIR &&
5180 pkt->cdb[0] != SS_REQSEN)
5181 pkt->cdb[0] = SS_TEST;
5183 switch (pkt->cdb[0]) {
5184 case SS_TEST:
5185 dprintk(3, "qla1280_atio_entry: SS_TEST\n");
5187 memset(sense_ptr, 0, TARGET_SENSE_SIZE);
5188 len = 0;
5189 if (pkt->lun == 0)
5190 pkt->scsi_status = S_GOOD;
5191 else {
5192 *sense_ptr = 0x70;
5193 *(sense_ptr + 2) = SD_ILLREQ;
5194 *(sense_ptr + 7) = TARGET_SENSE_SIZE - 8;
5195 *(sense_ptr + 12) = SC_INVLUN;
5196 pkt->scsi_status = S_CKCON;
5199 pkt->option_flags |= (OF_SSTS | OF_NO_DATA);
5200 break;
5202 case SS_REQSEN:
5203 dprintk(3, "qla1280_atio_entry: SS_REQSEN\n");
5205 phy_addr[0] = ha->tsense_dma;
5206 phy_addr[1] = 0;
5207 *a64 += t * TARGET_SENSE_SIZE;
5208 if (pkt->cdb[4] > TARGET_SENSE_SIZE)
5209 len = TARGET_SENSE_SIZE;
5210 else
5211 len = pkt->cdb[4];
5212 pkt->scsi_status = S_GOOD;
5213 pkt->option_flags |= (OF_SSTS | OF_DATA_IN);
5214 break;
5216 case SS_INQUIR:
5217 dprintk(3, "qla1280_atio_entry: SS_INQUIR\n");
5219 memset(sense_ptr, 0, TARGET_SENSE_SIZE);
5220 phy_addr[0] = ha->tbuf_dma;
5221 phy_addr[1] = 0;
5222 *a64 += TARGET_INQ_OFFSET;
5224 if (pkt->lun == 0) {
5225 ha->tbuf->inq.id_type = ID_PROCESOR;
5226 ha->tbuf->inq.id_pqual = ID_QOK;
5227 } else {
5228 ha->tbuf->inq.id_type = ID_NODEV;
5229 ha->tbuf->inq.id_pqual = ID_QNOLU;
5232 if (pkt->cdb[4] > sizeof(struct ident))
5233 len = sizeof(struct ident);
5234 else
5235 len = pkt->cdb[4];
5236 pkt->scsi_status = S_GOOD;
5237 pkt->option_flags |= (OF_SSTS | OF_DATA_IN);
5238 break;
5240 case SM_WRDB:
5241 memset(sense_ptr, 0, TARGET_SENSE_SIZE);
5242 offset = pkt->cdb[5];
5243 offset |= pkt->cdb[4] << 8;
5244 offset |= pkt->cdb[3] << 16;
5245 len = pkt->cdb[8];
5246 len |= pkt->cdb[7] << 8;
5247 len |= pkt->cdb[6] << 16;
5248 end_addr[0] = phy_addr[0] = ha->tbuf_dma;
5249 end_addr[1] = phy_addr[1] = 0;
5250 *end_a64 += TARGET_DATA_OFFSET + TARGET_DATA_SIZE;
5251 switch (pkt->cdb[1] & 7) {
5252 case RW_BUF_HDATA:
5253 dprintk(3, "qla1280_atio_entry: SM_WRDB, "
5254 "RW_BUF_HDATA\n");
5256 if (len > TARGET_DATA_SIZE + 4) {
5257 dprintk(2,
5258 "qla1280_atio_entry: SM_WRDB, "
5259 "length > buffer size\n");
5261 *sense_ptr = 0x70;
5262 *(sense_ptr + 2) = SD_ILLREQ;
5263 *(sense_ptr + 7) =
5264 TARGET_SENSE_SIZE - 8;
5265 *(sense_ptr + 12) = SC_ILLCDB;
5266 pkt->scsi_status = S_CKCON;
5267 pkt->option_flags |=
5268 (OF_SSTS | OF_NO_DATA);
5269 len = 0;
5270 } else if (len) {
5271 pkt->scsi_status = S_GOOD;
5272 pkt->option_flags |=
5273 (OF_SSTS | OF_DATA_OUT);
5274 dprintk(3,
5275 "qla1280_atio_entry: Issuing "
5276 "SDI_TARMOD_WRCOMP\n");
5278 sdi_xaen(SDI_TARMOD_WRCOMP, ha->cntlr,
5279 pkt->target_id, pkt->lun, 0,
5280 offset);
5281 } else {
5282 dprintk(2,
5283 "qla1280_atio_entry: SM_WRDB, "
5284 "zero length\n");
5286 pkt->scsi_status = S_GOOD;
5287 pkt->option_flags |=
5288 (OF_SSTS | OF_NO_DATA);
5291 break;
5292 case RW_BUF_DATA:
5293 dprintk(3, "qla1280_atio_entry: SM_WRDB, "
5294 "RW_BUF_DATA\n");
5296 *a64 += offset + TARGET_DATA_OFFSET;
5297 if (pkt->cdb[2] != 0 || *a64 >= *end_a64 ||
5298 *a64 + len > *end_a64) {
5299 dprintk(2,
5300 "qla1280_atio_entry: SM_WRDB, "
5301 "RW_BUF_DATA BAD\n");
5302 dprintk(2, "buf_id=0x%x, offset=0x%x, "
5303 "length=0x%x\n", pkt->cdb[2],
5304 offset, len);
5306 *sense_ptr = 0x70;
5307 *(sense_ptr + 2) = SD_ILLREQ;
5308 *(sense_ptr + 7) =
5309 TARGET_SENSE_SIZE - 8;
5310 *(sense_ptr + 12) = SC_ILLCDB;
5311 len = 0;
5312 pkt->scsi_status = S_CKCON;
5313 pkt->option_flags |=
5314 (OF_SSTS | OF_NO_DATA);
5315 } else if (len) {
5316 pkt->scsi_status = S_GOOD;
5317 pkt->option_flags |=
5318 (OF_SSTS | OF_DATA_OUT);
5319 dprintk(3,
5320 "qla1280_atio_entry: Issuing "
5321 "SDI_TARMOD_WRCOMP\n");
5323 sdi_xaen(SDI_TARMOD_WRCOMP, ha->cntlr,
5324 pkt->target_id, pkt->lun, 0,
5325 offset);
5326 } else {
5327 dprintk(2,
5328 "qla1280_atio_entry: SM_WRDB, "
5329 "zero length\n");
5331 pkt->scsi_status = S_GOOD;
5332 pkt->option_flags |=
5333 (OF_SSTS | OF_NO_DATA);
5335 break;
5337 default:
5338 dprintk(2, "qla1280_atio_entry: SM_WRDB "
5339 "unknown mode\n");
5341 *sense_ptr = 0x70;
5342 *(sense_ptr + 2) = SD_ILLREQ;
5343 *(sense_ptr + 7) = TARGET_SENSE_SIZE - 8;
5344 *(sense_ptr + 12) = SC_ILLCDB;
5345 len = 0;
5346 pkt->scsi_status = S_CKCON;
5347 pkt->option_flags |= (OF_SSTS | OF_NO_DATA);
5348 break;
5350 break;
5352 case SM_RDDB:
5353 memset(sense_ptr, 0, TARGET_SENSE_SIZE);
5354 offset = pkt->cdb[5];
5355 offset |= pkt->cdb[4] << 8;
5356 offset |= pkt->cdb[3] << 16;
5357 len = pkt->cdb[8];
5358 len |= pkt->cdb[7] << 8;
5359 len |= pkt->cdb[6] << 16;
5360 end_addr[0] = phy_addr[0] = ha->tbuf_dma;
5361 end_addr[1] = phy_addr[1] = 0;
5362 *end_a64 += TARGET_DATA_OFFSET + TARGET_DATA_SIZE;
5363 switch (pkt->cdb[1] & 7) {
5364 case RW_BUF_HDATA:
5365 dprintk(3, "qla1280_atio_entry: SM_RDDB, "
5366 "RW_BUF_HDATA\n");
5368 if (len) {
5369 ha->tbuf->hdr[0] = 0;
5370 ha->tbuf->hdr[1] =
5371 (TARGET_DATA_SIZE >> 16) & 0xff;
5372 ha->tbuf->hdr[2] =
5373 (TARGET_DATA_SIZE >> 8) & 0xff;
5374 ha->tbuf->hdr[3] =
5375 TARGET_DATA_SIZE & 0xff;
5376 if (len > TARGET_DATA_SIZE + 4)
5377 len = TARGET_DATA_SIZE + 4;
5378 pkt->scsi_status = S_GOOD;
5379 pkt->option_flags |=
5380 (OF_SSTS | OF_DATA_IN);
5381 } else {
5382 dprintk(2,
5383 "qla1280_atio_entry: SM_RDDB, "
5384 "zero length\n");
5386 pkt->scsi_status = S_GOOD;
5387 pkt->option_flags |=
5388 (OF_SSTS | OF_NO_DATA);
5390 break;
5391 case RW_BUF_DATA:
5392 dprintk(3, "qla1280_atio_entry: SM_RDDB, "
5393 "RW_BUF_DATA\n");
5395 *a64 += offset + TARGET_DATA_OFFSET;
5396 if (pkt->cdb[2] != 0 || *a64 >= *end_a64) {
5397 dprintk(2,
5398 "qla1280_atio_entry: SM_RDDB, "
5399 "RW_BUF_DATA BAD\n");
5400 dprintk(2, "buf_id=0x%x, offset=0x%x\n"
5401 pkt->cdb[2], offset);
5403 *sense_ptr = 0x70;
5404 *(sense_ptr + 2) = SD_ILLREQ;
5405 *(sense_ptr + 7) =
5406 TARGET_SENSE_SIZE - 8;
5407 *(sense_ptr + 12) = SC_ILLCDB;
5408 len = 0;
5409 pkt->scsi_status = S_CKCON;
5410 pkt->option_flags |=
5411 (OF_SSTS | OF_NO_DATA);
5412 } else {
5413 if (*a64 + len > *end_a64)
5414 len = *end_a64 - *a64;
5415 if (len) {
5416 pkt->scsi_status = S_GOOD;
5417 pkt->option_flags |=
5418 (OF_SSTS | OF_DATA_IN);
5419 } else {
5420 dprintk(2,
5421 "qla1280_atio_entry: SM_RDDB, "
5422 "zero length\n");
5424 pkt->scsi_status = S_GOOD;
5425 pkt->option_flags |=
5426 (OF_SSTS | OF_NO_DATA);
5429 break;
5430 case RW_BUF_DESC:
5431 dprintk(3, "qla1280_atio_entry: SM_RDDB, "
5432 "RW_BUF_DESC\n");
5434 if (len) {
5435 if (len > 4)
5436 len = 4;
5438 ha->tbuf->hdr[0] = 0;
5439 if (pkt->cdb[2] != 0) {
5440 ha->tbuf->hdr[1] = 0;
5441 ha->tbuf->hdr[2] = 0;
5442 ha->tbuf->hdr[3] = 0;
5443 } else {
5444 ha->tbuf->hdr[1] =
5445 (TARGET_DATA_SIZE >> 16) &
5446 0xff;
5447 ha->tbuf->hdr[2] =
5448 (TARGET_DATA_SIZE >> 8) &
5449 0xff;
5450 ha->tbuf->hdr[3] =
5451 TARGET_DATA_SIZE & 0xff;
5453 pkt->scsi_status = S_GOOD;
5454 pkt->option_flags |=
5455 (OF_SSTS | OF_DATA_IN);
5456 } else {
5457 dprintk(2,
5458 "qla1280_atio_entry: SM_RDDB,"
5459 " zero length\n");
5461 pkt->scsi_status = S_GOOD;
5462 pkt->option_flags |=
5463 (OF_SSTS | OF_NO_DATA);
5465 break;
5466 default:
5467 dprintk(2, "qla1280_atio_entry: SM_RDDB "
5468 "unknown mode\n");
5470 *sense_ptr = 0x70;
5471 *(sense_ptr + 2) = SD_ILLREQ;
5472 *(sense_ptr + 7) = TARGET_SENSE_SIZE - 8;
5473 *(sense_ptr + 12) = SC_ILLCDB;
5474 len = 0;
5475 pkt->scsi_status = S_CKCON;
5476 pkt->option_flags |= (OF_SSTS | OF_NO_DATA);
5477 break;
5479 break;
5481 default:
5482 dprintk(2,
5483 "qla1280_atio_entry: Unknown SCSI command\n");
5484 qla1280_dump_buffer(2, &pkt->cdb[0], pkt->cdb_len);
5486 memset(sense_ptr, 0, TARGET_SENSE_SIZE);
5487 *sense_ptr = 0x70;
5488 *(sense_ptr + 2) = SD_ILLREQ;
5489 *(sense_ptr + 7) = TARGET_SENSE_SIZE - 8;
5490 *(sense_ptr + 12) = SC_INVOPCODE;
5491 len = 0;
5492 pkt->scsi_status = S_CKCON;
5493 pkt->option_flags |= (OF_SSTS | OF_NO_DATA);
5494 break;
5496 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,18)
5497 if (ha->flags.enable_64bit_addressing)
5498 qla1280_64bit_continue_io(ha, pkt, len,
5499 (paddr32_t *)&phy_addr);
5500 else
5501 #endif
5502 qla1280_32bit_continue_io(ha, pkt, len,
5503 (paddr32_t *)&phy_addr);
5504 break;
5506 default:
5507 break;
5510 dprintk(3, "qla1280_atio_entry: exiting normally\n");
5514 * qla1280_notify_entry
5515 * Processes received ISP immediate notify entry.
5517 * Input:
5518 * ha = adapter block pointer.
5519 * pkt = entry pointer.
5521 static void
5522 qla1280_notify_entry(struct scsi_qla_host *ha, notify_entry_t * pkt)
5524 dprintk(3, "qla1280_notify_entry: entered\n");
5526 /* Acknowledge immediate notify */
5527 qla1280_notify_ack(ha, pkt);
5529 /* Issue notify entry to increment resource count */
5530 qla1280_immed_notify(ha, pkt);
5532 dprintk(3, "qla1280_notify_entry: exiting normally\n");
5534 #endif /* QLA1280_TARGET_MODE_SUPPORT */
5537 * qla1280_status_entry
5538 * Processes received ISP status entry.
5540 * Input:
5541 * ha = adapter block pointer.
5542 * pkt = entry pointer.
5543 * done_q_first = done queue first pointer.
5544 * done_q_last = done queue last pointer.
5546 static void
5547 qla1280_status_entry(struct scsi_qla_host *ha, sts_entry_t * pkt,
5548 srb_t ** done_q_first, srb_t ** done_q_last)
5550 unsigned int bus, target, lun;
5551 int sense_sz;
5552 srb_t *sp;
5553 scsi_lu_t *q;
5554 Scsi_Cmnd *cmd;
5556 ENTER("qla1280_status_entry");
5558 /* Validate handle. */
5559 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
5560 sp = ha->outstanding_cmds[pkt->handle];
5561 else
5562 sp = 0;
5564 if (sp) {
5565 /* Free outstanding command slot. */
5566 ha->outstanding_cmds[pkt->handle] = 0;
5568 cmd = sp->cmd;
5570 /* Generate LU queue on cntrl, target, LUN */
5571 bus = SCSI_BUS_32(cmd);
5572 target = SCSI_TCN_32(cmd);
5573 lun = SCSI_LUN_32(cmd);
5574 q = LU_Q(ha, bus, target, lun);
5576 if (pkt->comp_status || pkt->scsi_status) {
5577 dprintk(1, "scsi: comp_status = 0x%x, scsi_status = "
5578 "0x%x, handle = 0x%x\n", pkt->comp_status,
5579 pkt->scsi_status, pkt->handle);
5582 /* Target busy */
5583 if (pkt->scsi_status & SS_BUSY_CONDITION &&
5584 pkt->scsi_status != SS_RESERVE_CONFLICT) {
5585 CMD_RESULT(cmd) =
5586 DID_BUS_BUSY << 16 | (pkt->scsi_status & 0xff);
5587 } else {
5589 /* Save ISP completion status */
5590 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
5592 if (pkt->scsi_status & SS_CHECK_CONDITION) {
5593 if (pkt->comp_status != CS_ARS_FAILED) {
5594 if (pkt->req_sense_length <
5595 CMD_SNSLEN(cmd))
5596 sense_sz = pkt->req_sense_length;
5597 else
5599 * Scsi_Cmnd->sense_buffer is
5600 * 64 bytes, why only copy 63?
5601 * This looks wrong! /Jes
5603 sense_sz = CMD_SNSLEN(cmd) - 1;
5605 memcpy(cmd->sense_buffer,
5606 &pkt->req_sense_data, sense_sz);
5607 } else
5608 sense_sz = 0;
5609 memset(cmd->sense_buffer + sense_sz, 0,
5610 sizeof(cmd->sense_buffer) - sense_sz);
5612 dprintk(2, "qla1280_status_entry: Check "
5613 "condition Sense data, b %i, t %i, "
5614 "l %i\n", bus, target, lun);
5615 if (sense_sz)
5616 qla1280_dump_buffer(2, (char *)cmd->sense_buffer,
5617 sense_sz);
5620 /* Place command on done queue. */
5621 qla1280_done_q_put(sp, done_q_first, done_q_last);
5622 } else {
5623 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
5624 ha->flags.isp_abort_needed = TRUE;
5627 LEAVE("qla1280_status_entry");
5631 * qla1280_error_entry
5632 * Processes error entry.
5634 * Input:
5635 * ha = adapter block pointer.
5636 * pkt = entry pointer.
5637 * done_q_first = done queue first pointer.
5638 * done_q_last = done queue last pointer.
5640 static void
5641 qla1280_error_entry(struct scsi_qla_host *ha, response_t * pkt,
5642 srb_t ** done_q_first, srb_t ** done_q_last)
5644 srb_t *sp;
5646 ENTER("qla1280_error_entry");
5648 if (pkt->entry_status & BIT_3)
5649 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
5650 else if (pkt->entry_status & BIT_2)
5651 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
5652 else if (pkt->entry_status & BIT_1)
5653 dprintk(2, "qla1280_error_entry: FULL flag error\n");
5654 else
5655 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
5657 /* Validate handle. */
5658 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
5659 sp = ha->outstanding_cmds[pkt->handle];
5660 else
5661 sp = 0;
5663 if (sp) {
5664 /* Free outstanding command slot. */
5665 ha->outstanding_cmds[pkt->handle] = 0;
5667 /* Bad payload or header */
5668 if (pkt->entry_status & (BIT_3 + BIT_2)) {
5669 /* Bad payload or header, set error status. */
5670 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
5671 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
5672 } else if (pkt->entry_status & BIT_1) { /* FULL flag */
5673 CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
5674 } else {
5675 /* Set error status. */
5676 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
5678 /* Place command on done queue. */
5679 qla1280_done_q_put(sp, done_q_first, done_q_last);
5681 #ifdef QLA_64BIT_PTR
5682 else if (pkt->entry_type == COMMAND_A64_TYPE) {
5683 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
5684 ha->flags.isp_abort_needed = TRUE;
5686 #endif
5688 LEAVE("qla1280_error_entry");
5692 * qla1280_abort_isp
5693 * Resets ISP and aborts all outstanding commands.
5695 * Input:
5696 * ha = adapter block pointer.
5698 * Returns:
5699 * 0 = success
5701 static int
5702 qla1280_abort_isp(struct scsi_qla_host *ha)
5704 #if 0
5705 struct device_reg *reg = ha->iobase;
5706 #endif
5707 srb_t *sp;
5708 scsi_lu_t *q;
5709 int status = 0;
5710 int cnt;
5711 int bus, target, lun;
5713 ENTER("qla1280_abort_isp");
5715 ha->flags.isp_abort_needed = FALSE;
5716 if (!ha->flags.abort_isp_active && ha->flags.online) {
5717 ha->flags.abort_isp_active = TRUE;
5719 /* Disable ISP interrupts. */
5720 qla1280_disable_intrs(ha);
5722 /* Dequeue all commands in outstanding command list. */
5723 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
5724 sp = ha->outstanding_cmds[cnt];
5725 if (sp) {
5726 ha->outstanding_cmds[cnt] = 0;
5728 /* Generate LU queue on controller, target, LUN */
5729 bus = SCSI_BUS_32(sp->cmd);
5730 target = SCSI_TCN_32(sp->cmd);
5731 lun = SCSI_LUN_32(sp->cmd);
5733 q = LU_Q(ha, bus, target, lun);
5735 /* Reset outstanding command count. */
5736 q->q_outcnt = 0;
5737 q->q_flag &= ~QLA1280_QBUSY;
5738 q->q_flag = 0;
5740 /* Adjust watchdog timer for command. */
5741 /* if (sp->flags & SRB_WATCHDOG)
5742 sp->timeout += 2; */
5744 /* Place request back on top of device queue. */
5745 sp->flags = 0;
5746 qla1280_putq_t(q, sp);
5750 /* If firmware needs to be loaded */
5751 if (qla1280_isp_firmware (ha)) {
5752 if (!(status = qla1280_chip_diag(ha)))
5753 status = qla1280_setup_chip(ha);
5756 if (!status) {
5757 /* Setup adapter based on NVRAM parameters. */
5758 qla1280_nvram_config (ha);
5760 if (!(status = qla1280_init_rings(ha))) {
5761 /* Issue SCSI reset. */
5762 for (bus = 0; bus < ha->ports; bus++) {
5763 qla1280_bus_reset(ha, bus);
5765 do {
5766 /* Issue marker command. */
5767 ha->flags.reset_marker = FALSE;
5768 for (bus = 0; bus < ha->ports; bus++) {
5769 ha->bus_settings[bus].
5770 reset_marker = FALSE;
5771 qla1280_marker(ha, bus, 0, 0,
5772 MK_SYNC_ALL);
5774 } while (ha->flags.reset_marker);
5776 /* Enable host adapter target mode. */
5777 for (bus = 0; bus < ha->ports; bus++) {
5778 if (!
5779 (status =
5780 qla1280_enable_tgt(ha, bus))) {
5781 for (cnt = 0; cnt < MAX_LUNS;
5782 cnt++) {
5783 /* qla1280_enable_lun(ha, bus, cnt); */
5784 qla1280_poll(ha);
5786 } else
5787 break;
5790 if (!status) {
5791 /* Enable ISP interrupts. */
5792 qla1280_enable_intrs(ha);
5793 ha->flags.abort_isp_active = FALSE;
5794 /* Restart queues that may have been stopped. */
5795 qla1280_restart_queues(ha);
5801 if (status) {
5802 printk(KERN_WARNING
5803 "qla1280: ISP error recovery failed, board disabled");
5804 qla1280_reset_adapter(ha);
5805 qla1280_abort_queues(ha);
5807 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
5810 LEAVE("qla1280_abort_isp");
5811 return status;
5815 * qla1280_restart_queues
5816 * Restart all device queues.
5818 * Input:
5819 * ha = adapter block pointer.
5821 static void
5822 qla1280_restart_queues(struct scsi_qla_host *ha)
5824 scsi_lu_t *q;
5825 int bus, target, lun;
5827 ENTER("qla1280_restart_queues");
5829 for (bus = 0; bus < ha->ports; bus++)
5830 for (target = 0; target < MAX_TARGETS; target++)
5831 for (lun = 0; lun < MAX_LUNS; lun++) {
5832 q = LU_Q(ha, bus, target, lun);
5833 if (q != NULL) {
5834 if (q->q_first)
5835 qla1280_next(ha, q, bus);
5838 dprintk(3, "qla1280_restart_queues: exiting normally\n");
5842 * qla1280_abort_queue_single
5843 * Abort all commands on a device queues.
5845 * Input:
5846 * ha = adapter block pointer.
5848 static void
5849 qla1280_abort_queue_single(struct scsi_qla_host *ha, int bus,
5850 int target, int lun, uint32_t stat)
5852 scsi_lu_t *q;
5853 srb_t *sp, *sp_next;
5855 ENTER("qla1280_abort_queue_single");
5856 q = LU_Q(ha, bus, target, lun);
5857 if (q != NULL) {
5858 sp = q->q_first;
5859 q->q_first = q->q_last = NULL;
5861 while (sp) {
5862 sp_next = sp->s_next;
5863 CMD_RESULT(sp->cmd) = stat;
5864 qla1280_done_q_put(sp, &ha->done_q_first,
5865 &ha->done_q_last);
5866 sp = sp_next;
5869 LEAVE("qla1280_abort_queue_single");
5873 * qla1280_abort_queues
5874 * Abort all commands on device queues.
5876 * Input:
5877 * ha = adapter block pointer.
5879 static void
5880 qla1280_abort_queues(struct scsi_qla_host *ha)
5882 uint32_t bus, target, lun;
5884 ENTER("qla1280_abort_queues");
5886 for (bus = 0; bus < ha->ports; bus++)
5887 for (target = 0; target < MAX_TARGETS; target++)
5888 for (lun = 0; lun < MAX_LUNS; lun++)
5889 qla1280_abort_queue_single(ha, bus, target,
5890 lun, DID_RESET);
5892 LEAVE("qla1280_abort_queues");
5896 * qla1280_debounce_register
5897 * Debounce register.
5899 * Input:
5900 * port = register address.
5902 * Returns:
5903 * register value.
5905 static u16
5906 qla1280_debounce_register(volatile u16 * addr)
5908 volatile u16 ret;
5909 volatile u16 ret2;
5911 ret = RD_REG_WORD(addr);
5912 ret2 = RD_REG_WORD(addr);
5914 if (ret == ret2)
5915 return ret;
5917 do {
5918 cpu_relax();
5919 ret = RD_REG_WORD(addr);
5920 ret2 = RD_REG_WORD(addr);
5921 } while (ret != ret2);
5923 return ret;
5926 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
5927 #ifdef MODULE
5928 Scsi_Host_Template driver_template = QLA1280_LINUX_TEMPLATE;
5929 #include "scsi_module.c"
5930 #endif
5931 #else /* new kernel scsi initialization scheme */
5932 static Scsi_Host_Template driver_template = QLA1280_LINUX_TEMPLATE;
5933 #include "scsi_module.c"
5934 #endif
5936 /************************************************************************
5937 * qla1280_check_for_dead_scsi_bus *
5939 * This routine checks for a dead SCSI bus *
5940 ************************************************************************/
5941 #define SET_SXP_BANK 0x0100
5942 #define SCSI_PHASE_INVALID 0x87FF
5943 static int
5944 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
5946 uint16_t config_reg, scsi_control;
5947 struct device_reg *reg = ha->iobase;
5948 #if 0
5949 unsigned int bus;
5950 Scsi_Cmnd *cp;
5953 * If SCSI Bus is Dead because of bad termination,
5954 * we will return a status of Selection timeout.
5957 cp = sp->cmd;
5958 bus = SCSI_BUS_32(cp);
5959 #endif
5960 if (ha->bus_settings[bus].scsi_bus_dead) {
5961 WRT_REG_WORD(&reg->host_cmd, HC_PAUSE_RISC);
5962 config_reg = RD_REG_WORD(&reg->cfg_1);
5963 WRT_REG_WORD(&reg->cfg_1, SET_SXP_BANK);
5964 scsi_control = RD_REG_WORD(&reg->scsiControlPins);
5965 WRT_REG_WORD(&reg->cfg_1, config_reg);
5966 WRT_REG_WORD(&reg->host_cmd, HC_RELEASE_RISC);
5968 if (scsi_control == SCSI_PHASE_INVALID) {
5969 ha->bus_settings[bus].scsi_bus_dead = TRUE;
5970 #if 0
5971 CMD_RESULT(cp) = DID_NO_CONNECT << 16;
5972 CMD_HANDLE(cp) = NULL;
5973 /* ha->actthreads--; */
5975 (*(cp)->scsi_done)(cp);
5976 #endif
5977 return TRUE; /* bus is dead */
5978 } else {
5979 ha->bus_settings[bus].scsi_bus_dead = FALSE;
5980 ha->bus_settings[bus].failed_reset_count = 0;
5983 return FALSE; /* bus is not dead */
5986 static void
5987 qla12160_get_target_parameters(struct scsi_qla_host *ha, uint32_t bus,
5988 uint32_t target, uint32_t lun)
5990 uint16_t mb[MAILBOX_REGISTER_COUNT];
5992 mb[0] = MBC_GET_TARGET_PARAMETERS;
5993 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
5994 mb[1] <<= 8;
5995 qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
5996 &mb[0]);
5997 if (mb[3] != 0) {
5998 printk(KERN_INFO
5999 "scsi(%ld:%d:%d:%d): Synchronous transfer at period "
6000 "%d, offset %d. \n", ha->host_no, bus, target, lun,
6001 (mb[3] & 0xff), (mb[3] >> 8));
6004 if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2) {
6005 printk(KERN_INFO
6006 "scsi(%ld:%d:%d:%d): Dual Transition enabled.\n",
6007 ha->host_no, bus, target, lun);
6011 #ifdef QL_DEBUG_ROUTINES
6012 /****************************************************************************/
6013 /* Driver Debug Functions. */
6014 /****************************************************************************/
6017 * Get byte from I/O port
6019 static u8
6020 qla1280_getbyte (u8 * port)
6022 u8 ret;
6024 #if MEMORY_MAPPED_IO
6025 ret = readb((unsigned long) port);
6026 #else
6027 ret = inb((unsigned long) port);
6028 #endif
6030 if (ql_debug_print)
6031 printk(KERN_DEBUG
6032 "qla1280_getbyte: address = 0x%p, data = 0x%x", port,
6033 ret);
6035 return ret;
6039 * Get word from I/O port
6041 static u16
6042 qla1280_getword (u16 * port)
6044 u16 ret;
6046 #if MEMORY_MAPPED_IO
6047 ret = readw(unsigned long) port;
6048 #else
6049 ret = inw((unsigned long) port);
6050 #endif
6052 if (ql_debug_print)
6053 printk(KERN_DEBUG
6054 "qla1280_getbyte: address = 0x%p, data = 0x%x", port,
6055 ret);
6057 return ret;
6061 * Get double word from I/O port
6063 static u32
6064 qla1280_getdword (u32 * port)
6066 u32 ret;
6068 #if MEMORY_MAPPED_IO
6069 ret = readl((unsigned long) port);
6070 #else
6071 ret = inl((unsigned long) port);
6072 #endif
6074 if (ql_debug_print)
6075 printk(KERN_DEBUG
6076 "qla1280_getbyte: address = 0x%p, data = 0x%x", port,
6077 ret);
6079 return ret;
6083 * Send byte to I/O port
6085 static void
6086 qla1280_putbyte(u8 * port, u8 data)
6088 #if MEMORY_MAPPED_IO
6089 writeb(data, (unsigned long) port);
6090 #else
6091 outb(data, (unsigned long) port);
6092 #endif
6094 if (ql_debug_print)
6095 printk(KERN_DEBUG
6096 "qla1280_getbyte: address = 0x%p, data = 0x%x", port,
6097 data);
6101 * Send word to I/O port
6103 static void
6104 qla1280_putword(u16 * port, u16 data)
6106 #if MEMORY_MAPPED_IO
6107 writew(data, (unsigned long) port);
6108 #else
6109 outw(data, (unsigned long) port);
6110 #endif
6112 if (ql_debug_print)
6113 printk(KERN_DEBUG
6114 "qla1280_getbyte: address = 0x%p, data = 0x%x", port,
6115 data);
6119 * Send double word to I/O port
6121 static void
6122 qla1280_putdword(u32 * port, u32 data)
6124 #if MEMORY_MAPPED_IO
6125 writel(data, (unsigned long) port);
6126 #else
6127 outl(data, (unsigned long) port);
6128 #endif
6130 if (ql_debug_print)
6131 printk(KERN_DEBUG
6132 "qla1280_getbyte: address = 0x%p, data = 0x%x", port,
6133 data);
6137 * Dummy function to prevent warnings for
6138 * declared and unused debug functions
6140 static void
6141 qla1280_debug(void)
6143 qla1280_getbyte(0);
6144 qla1280_getword(0);
6145 qla1280_getdword(0);
6146 qla1280_putbyte(0, 0);
6147 qla1280_putword(0, 0);
6148 qla1280_putdword(0, 0);
6151 static void
6152 __qla1280_dump_buffer(char *b, int size)
6154 int cnt;
6155 u8 c;
6157 if (ql_debug_print) {
6158 printk(KERN_DEBUG
6159 " 0 1 2 3 4 5 6 7 8 9 Ah "
6160 "Bh Ch Dh Eh Fh\n");
6161 printk(KERN_DEBUG
6162 "---------------------------------------------"
6163 "------------------\n");
6165 for (cnt = 0; cnt < size;) {
6166 c = *b++;
6167 if (c < 16)
6168 printk(' ');
6169 printk("0x%x", c);
6170 cnt++;
6171 if (!(cnt % 16))
6172 printk("\n");
6173 else if (c < 10)
6174 printk(" ");
6175 else
6176 printk(' ');
6178 if (cnt % 16)
6179 printk("\n");
6183 /**************************************************************************
6184 * ql1280_print_scsi_cmd
6186 **************************************************************************/
6187 static void
6188 qla1280_print_scsi_cmd(Scsi_Cmnd * cmd)
6190 struct scsi_qla_host *ha;
6191 struct Scsi_Host *host = cmd->host;
6192 srb_t *sp;
6193 /* struct scatterlist *sg; */
6195 int i;
6196 ha = (struct scsi_qla_host *)host->hostdata;
6198 sp = (srb_t *)CMD_SP(cmd);
6199 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
6200 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
6201 cmd->channel, cmd->target, cmd->lun, cmd->cmd_len);
6202 printk(" CDB = ");
6203 for (i = 0; i < cmd->cmd_len; i++) {
6204 printk("0x%02x ", cmd->cmnd[i]);
6206 printk(" seg_cnt =%d\n", cmd->use_sg);
6207 printk(" request buffer=0x%p, request buffer len=0x%x\n",
6208 cmd->request_buffer, cmd->request_bufflen);
6209 /* if (cmd->use_sg)
6211 sg = (struct scatterlist *) cmd->request_buffer;
6212 printk(" SG buffer: \n");
6213 qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
6214 } */
6215 printk(" tag=%d, flags=0x%x, transfersize=0x%x \n",
6216 cmd->tag, cmd->flags, cmd->transfersize);
6217 printk(" Pid=%li, SP=0x%p\n", cmd->pid, CMD_SP(cmd));
6218 printk(" underflow size = 0x%x, direction=0x%x, req.cmd=0x%x \n",
6219 cmd->underflow, sp->dir, cmd->request->cmd);
6222 /**************************************************************************
6223 * ql1280_dump_device
6225 **************************************************************************/
6226 void
6227 ql1280_dump_device(struct scsi_qla_host *ha)
6230 Scsi_Cmnd *cp;
6231 srb_t *sp;
6232 int i;
6233 if (ql_debug_print) {
6234 printk(KERN_DEBUG "Outstanding Commands on controller:\n");
6236 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
6237 if ((sp = ha->outstanding_cmds[i]) == NULL)
6238 continue;
6239 if ((cp = sp->cmd) == NULL)
6240 continue;
6241 qla1280_print_scsi_cmd(1, cp);
6245 #endif
6247 #if STOP_ON_ERROR
6248 /**************************************************************************
6249 * ql1280_panic
6251 **************************************************************************/
6252 static void
6253 qla1280_panic(char *cp, struct Scsi_Host *host)
6255 struct scsi_qla_host *ha;
6256 long *fp;
6258 ha = (struct scsi_qla_host *)host->hostdata;
6259 printk(KERN_ERR "qla1280 - PANIC: %s\n", cp);
6260 printk(KERN_ERR "Current time=0x%lx\n", jiffies);
6261 printk(KERN_ERR "Number of pending commands =0x%lx\n", ha->actthreads);
6262 printk(KERN_ERR "Number of SCSI queued commands =0x%lx\n",
6263 ha->qthreads);
6264 printk(KERN_ERR "Number of free entries = (%d)\n", ha->req_q_cnt);
6265 printk(KERN_ERR "Request Queue @ 0x%lx, Response Queue @ 0x%lx\n",
6266 ha->request_dma, ha->response_dma);
6267 printk(KERN_ERR "Request In Ptr %d\n", ha->req_ring_index);
6268 fp = (long *) &ha->flags;
6269 printk(KERN_ERR "HA flags =0x%lx\n", *fp);
6270 if (ql_debug_level >= 2) {
6271 ql_debug_print = 1;
6272 #if 0
6273 ql1280_dump_device((struct scsi_qla_host *)host->hostdata);
6274 #endif
6276 sti();
6277 panic("Ooops");
6278 /* cli();
6279 for(;;)
6281 barrier();
6282 sti();
6286 #endif
6288 #ifdef MODULE
6289 /**************************************************************************
6290 * qla1280_setup
6292 * Handle Linux boot parameters. This routine allows for assigning a value
6293 * to a parameter with a ':' between the parameter and the value.
6294 * ie. qla1280=max_reqs:0x0A,verbose
6295 **************************************************************************/
6296 void
6297 qla1280_setup(char *s, int *dummy)
6299 char *end, *str, *cp;
6301 printk(KERN_INFO "scsi: Processing Option str = %s\n", s);
6302 end = strchr (s, '\0');
6303 /* locate command */
6304 str = s;
6305 for (cp = s; *cp && cp != end; cp++) {
6306 cp = qla1280_get_token(cp, str);
6307 printk(KERN_INFO "scsi: token str = %s\n", str);
6308 /* if found execute routine */
6312 static char *
6313 qla1280_get_token(char *cmdline, char *str)
6315 register char *cp = cmdline;
6317 /* skip preceeding spaces */
6318 while (strchr (cp, ' '))
6319 ++cp;
6320 /* symbol starts here */
6321 str = cp;
6322 /* skip char if not a space or : */
6323 while (*cp && !(strchr (cp, ' ') || strchr (cp, ':')))
6324 cp++;
6325 *cp = '\0';
6326 return cp;
6328 #endif
6331 * Overrides for Emacs so that we almost follow Linus's tabbing style.
6332 * Emacs will notice this stuff at the end of the file and automatically
6333 * adjust the settings for this buffer only. This must remain at the end
6334 * of the file.
6335 * ---------------------------------------------------------------------------
6336 * Local variables:
6337 * c-basic-offset: 8
6338 * tab-width: 8
6339 * End: