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
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 /******************************************************************************
22 Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
23 - Do qla1280_pci_config() before calling request_irq() and
25 - Use pci_dma_hi32() to handle upper word of DMA addresses instead
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()
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}
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
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
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:
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
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:
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
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>
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))
269 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,18)
270 #include <linux/pci_ids.h>
275 #define UNIQUE_FW_NAME
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
303 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1080
304 #define PCI_DEVICE_ID_QLOGIC_ISP1080 0x1080
306 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1240
307 #define PCI_DEVICE_ID_QLOGIC_ISP1240 0x1240
309 #ifndef PCI_DEVICE_ID_QLOGIC_ISP1280
310 #define PCI_DEVICE_ID_QLOGIC_ISP1280 0x1280
312 #ifndef PCI_DEVICE_ID_QLOGIC_ISP10160
313 #define PCI_DEVICE_ID_QLOGIC_ISP10160 0x1016
315 #ifndef PCI_DEVICE_ID_QLOGIC_ISP12160
316 #define PCI_DEVICE_ID_QLOGIC_ISP12160 0x1216
319 #ifndef PCI_VENDOR_ID_AMI
320 #define PCI_VENDOR_ID_AMI 0x101e
323 #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
324 #define QLA_64BIT_PTR 1
329 #define pci_dma_lo32(a) (a & 0xffffffff)
330 #define pci_dma_hi32(a) (a >> 32)
332 #define pci_dma_lo32(a) (a & 0xffffffff)
333 #define pci_dma_hi32(a) 0
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)
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)
352 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
353 typedef unsigned long dma_addr_t
;
356 pci_alloc_consistent(struct pci_dev
*hwdev
, size_t size
,
357 dma_addr_t
* dma_handle
)
361 virt_ptr
= kmalloc(size
, GFP_KERNEL
);
364 *dma_handle
= virt_to_bus(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]
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
*);
386 static void qla1280_panic(char *, struct Scsi_Host
*host
);
388 static void qla1280_abort_queue_single(struct scsi_qla_host
*, int, int,
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
);
396 static char *qla1280_get_token(char *, char *);
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
*,
430 static void qla1280_error_entry(struct scsi_qla_host
*, response_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
*,
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);
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
);
476 * insmod needs to find the variable and make it point to something
479 static char *options
= NULL
;
481 /* insmod qla1280 options=verbose" */
482 MODULE_PARM(options
, "s");
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
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
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
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]},
560 static int qla1280_verbose
= 1;
561 static struct scsi_qla_host
*qla1280_hostlist
= NULL
;
563 static int qla1280_buffer_size
= 0;
564 static char *qla1280_buffer
= NULL
;
568 static int ql_debug_print
= 1;
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)
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)
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 /*************************************************************************
603 * Set parameters for the driver from the /proc filesystem.
606 *************************************************************************/
608 qla1280_set_info(char *buffer
, int length
, struct Scsi_Host
*HBAptr
)
610 return -ENOSYS
; /* Currently this is a no-op */
613 /*************************************************************************
617 * Return information to handle /proc support for the driver.
619 * buffer - ptrs to a page buffer
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
)
630 struct Scsi_Host
*host
;
631 struct scsi_qla_host
*ha
;
635 struct qla_boards
*bdp
;
639 /* Find the host that was specified */
640 for (ha
= qla1280_hostlist
; (ha
!= NULL
) && ha
->host
->host_no
!= hostno
;
643 /* if host wasn't found then exit */
645 size
= sprintf(buffer
, "Can't find adapter for host "
646 "number %d\n", hostno
);
656 if (inout
== TRUE
) { /* Has data been written to the file? */
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",
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],
695 size
= sprintf(PROC_BUF
, "SCSI Host Adapter Information: %s\n",
698 size
= sprintf(PROC_BUF
, "Request Queue = 0x%p, Response Queue = 0x%p\n",
699 (void *)ha
->request_dma
, (void *)ha
->response_dma
);
701 size
= sprintf(PROC_BUF
, "Request Queue count= 0x%x, Response "
702 "Queue count= 0x%x\n",
703 REQUEST_ENTRY_CNT
, RESPONSE_ENTRY_CNT
);
705 size
= sprintf(PROC_BUF
, "Number of pending commands = 0x%lx\n",
708 size
= sprintf(PROC_BUF
, "Number of queued commands = 0x%lx\n",
711 size
= sprintf(PROC_BUF
, "Number of free request entries = %d\n",
714 size
= sprintf(PROC_BUF
, "\n"); /* 1 */
717 size
= sprintf(PROC_BUF
, "SCSI device Information:\n");
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
);
726 /* unused device/lun */
727 if (up
->io_cnt
== 0 || up
->io_cnt
< 2)
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
);
736 /* current number of pending requests */
737 size
= sprintf(PROC_BUF
, " Pend reqs %d,",
741 /* avg response time */
742 size
= sprintf(PROC_BUF
, " Avg resp time %ld%%,",
743 (up
->resp_time
/ up
->io_cnt
) *
747 /* avg active time */
748 size
= sprintf(PROC_BUF
,
749 " Avg active time %ld%%\n",
750 (up
->act_time
/ up
->io_cnt
) * 100);
752 size
= sprintf(PROC_BUF
, "\n");
756 if (len
>= qla1280_buffer_size
)
760 if (len
>= qla1280_buffer_size
) {
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;
771 *start
= &qla1280_buffer
[offset
]; /* Start of wanted data */
772 if (len
- offset
< length
) {
773 length
= len
- offset
;
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
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
796 * host - pointer to SCSI host structure
797 **************************************************************************/
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
));
813 "qla1280: Failed to register host, aborting.\n");
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
;
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");
834 ha
->ports
= bdp
->numPorts
;
835 /* following needed for all cases of OS versions */
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
;
844 host
->base
= (unsigned long)ha
->mmpbase
;
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;
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
,
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"
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");
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
;
898 qla1280_mem_free(ha
);
902 scsi_unregister(host
);
907 /**************************************************************************
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.
916 * template - pointer to SCSI template
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
;
932 ENTER("qla1280_detect");
934 if (sizeof(srb_t
) > sizeof(Scsi_Pointer
)) {
936 "qla1280_detect: [WARNING] srb_t too big\n");
940 dprintk(1, "DEBUG: qla1280_detect starts at address = %p\n",
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
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.
955 qla1280_setup(options
, NULL
);
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 "
962 "qla1280: Specifically, don't use any commas when passing "
964 "qla1280: insmod or else it might trash certain memory areas.\n");
967 if (!pci_present()) {
968 printk(KERN_INFO
"scsi: PCI not present\n");
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
;
977 template->proc_name
= "qla1280";
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))
989 /* Bypass all AMI SUBSYS VENDOR IDs */
990 if (pdev
->subsystem_vendor
== PCI_VENDOR_ID_AMI
) {
992 "qla1x160: Skip AMI SubSys Vendor ID Chip\n");
996 if (pci_enable_device(pdev
))
999 host
= qla1280_do_device_init(pdev
, template, devnum
,
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
;
1013 /* Try and find each different type of adapter we support */
1014 for (devnum
= 0; bdp
->device_id
!= 0 && devnum
< NUM_OF_ISP_DEVICES
;
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
))
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
;
1027 pci_read_config_word(pdev
, PCI_SUBSYSTEM_VENDOR_ID
,
1029 pci_read_config_word(pdev
, PCI_SUBSYSTEM_ID
,
1033 * skip QLA12160 already initialized on
1034 * PCI Bus 1 Dev 2 since we already initialized
1037 if ((bdp
->device_id
== PCI_DEVICE_ID_QLOGIC_ISP12160
)&&
1038 (pdev
->bus
->number
== 1) &&
1039 (PCI_SLOT(pdev
->devfn
) == 2))
1042 /* Bypass all AMI SUBSYS VENDOR IDs */
1043 if (subsys_vendor
== PCI_VENDOR_ID_AMI
) {
1045 "qla1x160: Skip AMI SubSys Vendor ID Chip\n");
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
);
1057 ha
= (struct scsi_qla_host
*)host
->hostdata
;
1059 if (qla1280_hostlist
== NULL
) {
1060 cur_ha
= qla1280_hostlist
= ha
;
1062 cur_ha
= qla1280_hostlist
;
1063 while (cur_ha
->next
!= NULL
)
1064 cur_ha
= cur_ha
->next
;
1068 } /* end of WHILE */
1071 LEAVE("qla1280_detect");
1075 /**************************************************************************
1077 * Free the passed in Scsi_Host memory structures prior to unloading the
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
)
1090 /* turn-off interrupts on the card */
1091 WRT_REG_WORD(&ha
->iobase
->ictrl
, 0);
1093 /* Detach interrupts */
1095 free_irq(host
->irq
, ha
);
1097 #if MEMORY_MAPPED_IO
1099 iounmap((void *)(((unsigned long) ha
->mmpbase
) & PAGE_MASK
));
1101 /* release io space registers */
1103 release_region(host
->io_port
, 0xff);
1104 #endif /* MEMORY_MAPPED_IO */
1106 qla1280_mem_free(ha
);
1108 ENTER("qla1280_release");
1112 /**************************************************************************
1114 * Return a string describing the driver.
1115 **************************************************************************/
1117 qla1280_info(struct Scsi_Host
*host
)
1119 static char qla1280_scsi_name_buffer
[125];
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
));
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],
1137 /**************************************************************************
1138 * qla1200_queuecommand
1139 * Queue a command to the controller.
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
;
1153 struct Scsi_Host
*host
;
1154 int bus
, target
, lun
;
1157 /*ENTER("qla1280_queuecommand");
1161 ha
= (struct scsi_qla_host
*)host
->hostdata
;
1163 /* send command to adapter */
1164 sp
= (srb_t
*)CMD_SP(cmd
);
1166 cmd
->scsi_done
= fn
;
1167 if (cmd
->flags
== 0) { /* new command */
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
),
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",
1185 CMD_RESULT(cmd
) = DID_BUS_BUSY
<< 16;
1186 qla1280_done_q_put(sp
, &ha
->done_q_first
,
1189 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) /* 3.22 */
1190 schedule_work(&ha
->run_qla_bh
);
1192 schedule_work(&ha
->run_qla_bh
); /* 3.22 */
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 */
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"); */
1216 /**************************************************************************
1218 * Abort the speciifed SCSI command(s).
1219 **************************************************************************/
1221 qla1280_abort(Scsi_Cmnd
* cmd
)
1223 struct scsi_qla_host
*ha
;
1225 struct Scsi_Host
*host
;
1226 unsigned int bus
, target
, lun
;
1228 int return_status
= SCSI_ABORT_SUCCESS
;
1231 unsigned char *handle
;
1234 ENTER("qla1280_abort");
1235 ha
= (struct scsi_qla_host
*)cmd
->host
->hostdata
;
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
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
1269 handle
= CMD_HANDLE(cmd
);
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
;
1290 if ((sp
->flags
& SRB_ABORT_PENDING
)) {
1291 if (qla1280_verbose
)
1293 "scsi(): Command has a pending abort "
1294 "message - ABORT_PENDING.\n");
1296 return SCSI_ABORT_PENDING
;
1299 printk(KERN_WARNING
"Scsi layer issued a ABORT command= 0x%p\n", cmd
);
1300 qla1280_print_scsi_cmd(2, cmd
);
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
1308 if (!(sp
->flags
& SRB_SENT
)) {
1310 if (qla1280_verbose
)
1312 "scsi(): Command returned from queue "
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
]) {
1326 "qla1280: RISC aborting command.\n");
1327 qla1280_abort_command(ha
, sp
);
1328 return_status
= SCSI_ABORT_PENDING
;
1335 qla1280_panic("qla1280_abort", ha
->host
);
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",
1343 if (ha
->done_q_first
)
1344 qla1280_done(ha
, &ha
->done_q_first
, &ha
->done_q_last
);
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
;
1357 struct Scsi_Host
*host
;
1358 int bus
, target
, lun
;
1360 unsigned long cpu_flags
;
1361 int return_status
= SCSI_ABORT_SUCCESS
;
1364 unsigned char *handle
;
1367 ENTER("qla1280_abort");
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
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 */
1412 if ((sp
->flags
& SRB_ABORT_PENDING
)) {
1413 if (qla1280_verbose
)
1415 "scsi(): Command has a pending abort "
1416 "message - ABORT_PENDING.\n");
1418 return_status
= SCSI_ABORT_PENDING
;
1422 printk(KERN_WARNING
"Scsi layer issued a ABORT command= 0x%p\n", cmd
);
1423 qla1280_print_scsi_cmd(2, cmd
);
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
1431 if (!(sp
->flags
& SRB_SENT
)) {
1433 if (qla1280_verbose
)
1435 "scsi(): Command returned from queue "
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
]) {
1449 "qla1280: RISC aborting command.\n");
1450 qla1280_abort_command(ha
, sp
);
1451 return_status
= SCSI_ABORT_PENDING
;
1458 qla1280_panic("qla1280_abort", ha
->host
);
1461 return_status
= SUCCESS
; /* no action - we don't have the command */
1463 dprintk(1, "qla1280_abort: Aborted status returned = 0x%x.\n",
1466 if (ha
->done_q_first
)
1467 qla1280_done(ha
, &ha
->done_q_first
, &ha
->done_q_last
);
1469 qla1280_restart_queues(ha
);
1472 spin_unlock_irqrestore(ha
->host
->host_lock
, cpu_flags
);
1474 LEAVE("qla1280_abort");
1475 return return_status
;
1478 /**************************************************************************
1480 * The reset function will reset the SCSI bus and abort any executing
1484 * cmd = Linux SCSI command packet of the command that cause the
1486 * flags = SCSI bus reset option flags (see scsi.h)
1489 * DID_RESET in cmd.host_byte of aborted command(s)
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
;
1511 action_t action
= ADAPTER_RESET
;
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
);
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
);
1530 qla1280_panic("qla1280_reset", ha
->host
);
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
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
;
1559 * Mid-level driver has called reset with this SCSI_Cmnd and
1562 if (flags
& SCSI_RESET_SUGGEST_HOST_RESET
)
1563 action
= ADAPTER_RESET
;
1564 else if (flags
& SCSI_RESET_SUGGEST_BUS_RESET
)
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
)) {
1578 "qla1280(%ld): Bus device reset already sent to "
1579 "device, escalating.\n", ha
->host_no
);
1582 if ((action
& DEVICE_RESET
) && (sp
->flags
& SRB_ABORT_PENDING
)) {
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
);
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
;
1602 result
= SCSI_RESET_PENDING
;
1606 ha
->flags
.in_reset
= TRUE
;
1607 if (qla1280_verbose
)
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
;
1617 if (qla1280_verbose
)
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
,
1625 if (qla1280_device_reset(ha
, bus
, target
) == 0)
1626 result
= SCSI_RESET_PENDING
;
1627 q
->q_flag
|= QLA1280_QRESET
;
1631 if (qla1280_verbose
)
1632 printk(KERN_INFO
"qla1280(%ld:%d:%d:%d): Issuing BUS "
1633 "DEVICE RESET.\n", ha
->host_no
, bus
, target
,
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
,
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
;
1654 if (flags
& SCSI_RESET_SYNCHRONOUS
) {
1655 CMD_RESULT(cmd
) = DID_BUS_BUSY
<< 16;
1656 (*(cmd
)->scsi_done
)(cmd
);
1658 /* ha->reset_start = jiffies; */
1663 if (qla1280_verbose
) {
1665 "scsi(%ld:%d:%d:%d): Issued an ADAPTER "
1666 "RESET.\n", ha
->host_no
, bus
, target
, lun
);
1668 "scsi(%ld:%d:%d:%d): I/O processing will "
1669 "continue automatically.\n", ha
->host_no
, bus
,
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");
1694 /**************************************************************************
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
;
1706 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
1707 if (cylinders
> 1024) {
1710 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
1711 /* if (cylinders > 1023)
1712 cylinders = 1023; */
1717 geom
[2] = cylinders
;
1722 /**************************************************************************
1723 * qla1280_intr_handler
1724 * Handles the H/W interrupt
1725 **************************************************************************/
1727 qla1280_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1729 struct scsi_qla_host
*ha
;
1730 struct device_reg
*reg
;
1733 ENTER_INTR ("qla1280_intr_handler");
1734 ha
= (struct scsi_qla_host
*)dev_id
;
1736 spin_lock(ha
->host
->host_lock
);
1741 WRT_REG_WORD(®
->ictrl
, 0); /* disable our interrupt. */
1743 data
= qla1280_debounce_register(®
->istatus
);
1744 /* Check for pending interrupts. */
1745 if (data
& RISC_INT
) {
1746 qla1280_isr(ha
, &ha
->done_q_first
, &ha
->done_q_last
);
1748 /* spurious interrupts can happen legally */
1749 dprintk(1, "scsi(%ld): Spurious interrupt - ignoring\n",
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(®
->ictrl
, (ISP_EN_INT
| ISP_EN_RISC
));
1761 LEAVE_INTR("qla1280_intr_handler");
1764 /**************************************************************************
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
1775 **************************************************************************/
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
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 **************************************************************************/
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
))
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
);
1825 scsi_adjust_queue_depth(device
, 0 /* TCQ off */, 3);
1827 qla12160_get_target_parameters(p
, bus
, target
, device
->lun
);
1832 * Driver Support Routines
1837 * Process completed commands.
1840 * ha = adapter block pointer.
1841 * done_q_first = done queue first pointer.
1842 * done_q_last = done queue last pointer.
1845 qla1280_done(struct scsi_qla_host
*ha
, srb_t
** done_q_first
,
1846 srb_t
** done_q_last
)
1850 int bus
, target
, lun
;
1853 ENTER("qla1280_done");
1855 while (*done_q_first
!= NULL
) {
1856 /* remove command from done list */
1858 if (!(*done_q_first
= sp
->s_next
))
1859 *done_q_last
= NULL
;
1861 (*done_q_first
)->s_prev
= NULL
;
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. */
1872 if (q
->q_outcnt
< ha
->bus_settings
[bus
].hiwat
) {
1873 q
->q_flag
&= ~QLA1280_QBUSY
;
1877 if (sp
->dir
& BIT_5
)
1882 switch ((CMD_RESULT(cmd
) >> 16)) {
1884 q
->q_flag
&= ~QLA1280_QRESET
;
1885 /* Issue marker command. */
1886 qla1280_marker(ha
, bus
, target
, 0, MK_SYNC_ID
);
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;
1898 /* 3.13 64 and 32 bit */
1899 /* Release memory used for this I/O */
1901 dprintk(1, "S/G unmap_sg cmd=%p\n", cmd
);
1903 pci_unmap_sg(ha
->pdev
, cmd
->request_buffer
,
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
;
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
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
[] = {
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",
1956 switch (sts
->comp_status
) {
1958 host_status
= DID_OK
;
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
;
1977 host_status
= DID_RESET
;
1981 host_status
= DID_ABORT
;
1985 host_status
= DID_TIME_OUT
;
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
;
1995 case CS_DATA_UNDERRUN
:
1996 if ((cp
->request_bufflen
- sts
->residual_length
) <
1999 "scsi: Underflow detected - retrying "
2001 host_status
= DID_ERROR
;
2003 host_status
= DID_OK
;
2007 host_status
= DID_ERROR
;
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
);
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.
2027 * done_q_first = done queue first pointer.
2028 * done_q_last = done queue last pointer.
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 */
2037 sp
->s_prev
= *done_q_last
;
2041 (*done_q_last
)->s_next
= sp
;
2044 LEAVE("qla1280_put_done_q");
2049 * Retrieve and process next job in the queue.
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.
2058 * Releases SCSI_LU_Qupon exit.
2061 qla1280_next(struct scsi_qla_host
*ha
, scsi_lu_t
* q
, int bus
)
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. */
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
);
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
--) {
2093 if (ha
->flags
.enable_64bit_addressing
)
2095 qla1280_64bit_start_scsi(ha
, sp
);
2099 qla1280_32bit_start_scsi(ha
, sp
);
2104 /* Go check for pending interrupts. */
2110 /* Set timeout status */
2111 CMD_RESULT(sp
->cmd
) =
2115 /* Remove command from watchdog queue. */
2116 if (sp
->flags
& SRB_WATCHDOG
)
2117 qla1280_timeout_remove
2120 CMD_HANDLE(sp
->cmd
) = NULL
;
2122 /* Call the mid-level driver interrupt handler */
2123 (*(sp
->cmd
)->scsi_done
)(sp
->cmd
);
2128 } else { /* Place request back on top of device queue. */
2129 qla1280_putq_t(q
, sp
);
2134 ha
->bus_settings
[bus
].hiwat
)
2135 q
->q_flag
&= ~QLA1280_QBUSY
;
2142 LEAVE("qla1280_next");
2147 * Add the standard SCB job to the top of standard SCB commands.
2150 * q = SCSI LU pointer.
2152 * SCSI_LU_Qlock must be already obtained.
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
,
2163 if (!q
->q_first
) { /* If queue empty */
2168 sp
->s_prev
= q
->q_last
;
2169 q
->q_last
->s_next
= sp
;
2173 LEAVE("qla1280_putq_t");
2178 * Function used to remove a command block from the
2182 * q = SCSI LU pointer.
2184 * SCSI_LU_Qlock must be already obtained.
2187 qla1280_removeq(scsi_lu_t
* q
, srb_t
* sp
)
2189 dprintk(1, "Removing from device_q (0x%p)->(0x%p)\n", q
, sp
);
2192 if ((sp
->s_prev
->s_next
= sp
->s_next
) != NULL
)
2193 sp
->s_next
->s_prev
= sp
->s_prev
;
2195 q
->q_last
= sp
->s_prev
;
2196 } else if (!(q
->q_first
= sp
->s_next
))
2199 q
->q_first
->s_prev
= NULL
;
2204 * Allocates adapter memory.
2211 qla1280_mem_alloc(struct scsi_qla_host
*ha
)
2214 dma_addr_t dma_handle
;
2216 ENTER("qla1280_mem_alloc");
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
))),
2224 if (!ha
->request_ring
)
2226 ha
->request_dma
= dma_handle
;
2227 ha
->response_ring
= pci_alloc_consistent(ha
->pdev
,
2228 ((RESPONSE_ENTRY_CNT
+ 1) *
2229 (sizeof(response_t
))),
2231 if (!ha
->request_ring
)
2233 ha
->response_dma
= dma_handle
;
2238 dprintk(2, "qla1280_mem_alloc: **** FAILED ****\n");
2240 LEAVE("qla1280_mem_alloc");
2246 * Frees adapter allocated memory.
2249 * ha = adapter block pointer.
2252 qla1280_mem_free(struct scsi_qla_host
*ha
)
2255 int bus
, target
, lun
;
2257 ENTER("qlc1280_mem_free");
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
));
2269 for (bus
= 0; bus
< MAX_EQ
; bus
++)
2270 ha
->dev
[bus
] = NULL
;
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
2304 * ha = adapter block pointer.
2310 qla1280_enable_intrs(struct scsi_qla_host
*ha
)
2312 struct device_reg
*reg
;
2315 /* enable risc and host interrupts */
2316 WRT_REG_WORD(®
->ictrl
, (ISP_EN_INT
| ISP_EN_RISC
));
2317 ha
->flags
.ints_enabled
= 1;
2319 printk("Enabling ints\n");
2324 qla1280_disable_intrs(struct scsi_qla_host
*ha
)
2326 struct device_reg
*reg
;
2329 /* disable risc and host interrupts */
2330 WRT_REG_WORD(®
->ictrl
, 0);
2331 ha
->flags
.ints_enabled
= 0;
2333 printk("Disabling ints\n");
2338 * qla1280_initialize_adapter
2342 * ha = adapter block pointer.
2348 qla1280_initialize_adapter(struct scsi_qla_host
*ha
)
2350 struct device_reg
*reg
;
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");
2369 /* Insure mailbox registers are free. */
2370 WRT_REG_WORD(®
->semaphore
, 0);
2371 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
2372 WRT_REG_WORD(®
->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",
2382 if (!(status
= qla1280_chip_diag (ha
))) {
2383 if (qla1280_verbose
)
2384 printk(KERN_INFO
"scsi(%ld): Setup chip...\n",
2386 status
= qla1280_setup_chip(ha
);
2389 printk(KERN_ERR
"initialize: isp_firmware() failed!\n");
2394 /* Setup adapter based on NVRAM parameters. */
2395 if (qla1280_verbose
)
2397 "scsi(%ld): Configure NVRAM parameters...\n",
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
;
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,
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
))) {
2431 for (cnt
= 0; cnt
< MAX_LUNS
; cnt
++) {
2432 qla1280_enable_lun(ha
, bus
,
2443 printk(KERN_ERR
"scsi(%li): initialize: pci probe failed!\n",
2447 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
2449 LEAVE("qla1280_initialize_adapter");
2454 * qla1280_enable_tgt
2455 * Enable target mode.
2458 * ha = adapter block pointer.
2459 * bus = SCSI bus number.
2465 qla1280_enable_tgt(struct scsi_qla_host
*ha
, int bus
)
2468 /* uint16_t mb[MAILBOX_REGISTER_COUNT]; */
2470 dprintk(3, "qla1280_enable_tgt: entered\n");
2472 /* Enable target mode. */
2474 mb
[0] = MBC_ENABLE_TARGET_MODE
;
2476 mb
[2] = (uint16_t) (bus
<< 15);
2477 status
= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
2480 dprintk(2, "qla1280_enable_tgt: **** FAILED ****\n");
2482 dprintk(3, "qla1280_enable_tgt: exiting normally\n");
2489 * Checks if present version of RISC firmware is older than
2493 * ha = adapter block pointer.
2496 * 0 = firmware does not need to be loaded.
2499 qla1280_isp_firmware(struct scsi_qla_host
*ha
)
2501 nvram_t
*nv
= (nvram_t
*) ha
->response_ring
;
2503 int status
= 0; /* dg 2/27 always loads RISC */
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");
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);
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
;
2533 ha
->flags
.disable_risc_code_load
=
2534 nv
->cntr_flags_1
.disable_loading_risc_code
;
2536 if (ha
->flags
.disable_risc_code_load
) {
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
;
2548 qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]))) {
2549 /* Start firmware execution. */
2550 dprintk(3, "qla1280_isp_firmware: Startng F/W "
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]);
2558 printk(KERN_INFO
"qla1280: RISC checksum failed.\n");
2560 dprintk(1, "qla1280: NVRAM configured to load RISC load.\n");
2565 dprintk(2, "qla1280_isp_firmware: **** Load RISC code ****\n");
2567 LEAVE("qla1280_isp_firmware");
2573 * Setup device PCI configuration registers.
2576 * ha = adapter block pointer.
2582 qla1280_pci_config(struct scsi_qla_host
*ha
)
2584 #if MEMORY_MAPPED_IO
2585 uint32_t page_offset
, base
;
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
;
2603 buf_wd
|= PCI_COMMAND_IO
;
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);
2634 ha
->mmpbase
+= page_offset
;
2635 /* ha->iobase = ha->mmpbase; */
2638 #else /* MEMORY_MAPPED_IO */
2640 #endif /* MEMORY_MAPPED_IO */
2642 LEAVE("qla1280_pci_config");
2648 * Test chip for proper operation.
2651 * ha = adapter block pointer.
2657 qla1280_chip_diag(struct scsi_qla_host
*ha
)
2659 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2660 struct device_reg
*reg
= ha
->iobase
;
2665 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®
->id_l
);
2667 /* Soft reset chip and wait for it to finish. */
2668 WRT_REG_WORD(®
->ictrl
, ISP_RESET
);
2669 data
= qla1280_debounce_register(®
->ictrl
);
2673 for (cnt
= 6000000; cnt
&& data
& ISP_RESET
; cnt
--) {
2675 data
= RD_REG_WORD(®
->ictrl
);
2678 /* Reset register not cleared by chip reset. */
2680 "qla1280_chip_diag: reset register cleared by chip reset\n");
2682 WRT_REG_WORD(®
->cfg_1
, 0);
2684 /* Reset RISC and disable BIOS which
2685 allows RISC to execute out of RAM. */
2686 WRT_REG_WORD(®
->host_cmd
, HC_RESET_RISC
);
2687 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
2688 WRT_REG_WORD(®
->host_cmd
, HC_DISABLE_BIOS
);
2689 data
= qla1280_debounce_register(®
->mailbox0
);
2691 * I *LOVE* this code!
2693 for (cnt
= 6000000; cnt
&& data
== MBS_BUSY
; cnt
--) {
2695 data
= RD_REG_WORD(®
->mailbox0
);
2699 /* Check product ID of chip */
2701 "qla1280_chip_diag: Checking product ID of chip\n");
2703 if (RD_REG_WORD(®
->mailbox1
) != PROD_ID_1
||
2704 (RD_REG_WORD(®
->mailbox2
) != PROD_ID_2
&&
2705 RD_REG_WORD(®
->mailbox2
) != PROD_ID_2a
) ||
2706 RD_REG_WORD(®
->mailbox3
) != PROD_ID_3
||
2707 RD_REG_WORD(®
->mailbox4
) != PROD_ID_4
) {
2709 "qla1280: Wrong product ID = 0x%x,0x%x,0x%x,"
2710 "0x%x\n", RD_REG_WORD(®
->mailbox1
),
2711 RD_REG_WORD(®
->mailbox2
),
2712 RD_REG_WORD(®
->mailbox3
),
2713 RD_REG_WORD(®
->mailbox4
));
2717 * Enable ints early!!!
2719 qla1280_enable_intrs(ha
);
2721 "qla1280_chip_diag: Checking mailboxes of chip\n");
2722 /* Wrap Incoming Mailboxes Test. */
2723 mb
[0] = MBC_MAILBOX_REGISTER_TEST
;
2731 if (!(status
= qla1280_mailbox_command(ha
,
2742 if (mb
[1] != 0xAAAA ||
2752 "qla1280: Failed mailbox check\n");
2761 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
2763 dprintk(3, "qla1280_chip_diag: exiting normally\n");
2770 * Load and start RISC firmware.
2773 * ha = adapter block pointer.
2778 #define DUMP_IT_BACK 0 /* for debug of RISC loading */
2780 qla1280_setup_chip(struct scsi_qla_host
*ha
)
2783 uint16_t risc_address
;
2784 uint16_t *risc_code_address
;
2786 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2793 #ifdef QLA_64BIT_PTR
2800 ENTER("qla1280_setup_chip");
2804 /* get consistent memory allocated for setup_chip */
2805 tbuf
= pci_alloc_consistent(ha
->pdev
, 8000, &p_tbuf
);
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",
2817 while (risc_code_size
> 0 && !status
) {
2820 if (cnt
> risc_code_size
)
2821 cnt
= risc_code_size
;
2823 dprintk(1, "qla1280_setup_chip: loading risc @ =(0x%p),"
2825 risc_code_address
, cnt
, num
, risc_address
);
2826 memcpy(ha
->request_ring
, risc_code_address
, (cnt
<< 1));
2830 mb
[0] = MBC_LOAD_RAM
;
2831 mb
[1] = risc_address
;
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,"
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
,
2844 "Failed to load partial segment of f/w\n");
2848 mb
[0] = MBC_READ_RAM_WORD
;
2849 mb
[1] = risc_address
;
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
|
2861 "Failed to dump partial segment of f/w\n");
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",
2870 printk(KERN_ERR
"setup_chip: FWbyte=%x "
2871 "FWfromChip=%x\n", sp
[i
], tbuf
[i
]);
2876 risc_address
+= cnt
;
2877 risc_code_size
= risc_code_size
- cnt
;
2878 risc_code_address
= risc_code_address
+ cnt
;
2882 /* Verify checksum of loaded RISC code. */
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
;
2891 qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]))) {
2892 /* Start firmware execution. */
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]);
2900 "qla1280_setup_chip: Failed checksum.\n");
2905 /* free consistent memory allocated for setup_chip */
2906 pci_free_consistent(ha
->pdev
, 8000, tbuf
, p_tbuf
);
2910 dprintk(2, "qla1280_setup_chip: **** FAILED ****\n");
2912 LEAVE("qla1280_setup_chip");
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
2930 qla1280_init_rings(struct scsi_qla_host
*ha
)
2932 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
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;
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
,
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;
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
,
2974 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
2976 LEAVE("qla1280_init_rings");
2981 * NVRAM configuration.
2984 * ha = adapter block pointer.
2985 * ha->request_ring = request ring virtual address
2988 * host adapters parameters in host adapter block
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
;
3000 int bus
, target
, lun
;
3002 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3006 #if DEBUG_PRINT_NVRAM
3007 int saved_print_status
= ql_debug_print
;
3009 ENTER("qla1280_nvram_config");
3011 /* Verify valid NVRAM checksum. */
3012 #if USE_NVRAM_DEFAULTS
3015 wptr
= (uint16_t *) ha
->response_ring
;
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;
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);
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");
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
));
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
.
3064 nv
->bus
[bus
].target
[target
].flags
.
3069 #if USE_NVRAM_DEFAULTS
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
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;
3142 ha
->flags
.enable_64bit_addressing
= 0;
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",
3150 pci_set_dma_mask(ha
->pdev
, (dma_addr_t
) ~ 0ULL);
3154 /* Set ISP hardware DMA burst */
3155 mb
[0] = nv
->isp_config
.c
;
3156 WRT_REG_WORD(®
->cfg_1
, mb
[0]);
3158 /* Set SCSI termination. */
3159 WRT_REG_WORD(®
->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(®
->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
;
3180 qla1280_mailbox_command(ha
, BIT_7
| BIT_6
| BIT_2
| BIT_1
| BIT_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
;
3192 if (nv
->bus
[0].config_2
.req_ack_active_negation
)
3194 if (nv
->bus
[0].config_2
.data_line_active_negation
)
3197 if (nv
->bus
[1].config_2
.req_ack_active_negation
)
3199 if (nv
->bus
[1].config_2
.data_line_active_negation
)
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
;
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]);
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
);
3237 mb
[2] = nv
->bus
[bus
].target
[target
].parameter
.c
<< 8;
3238 mb
[2] |= TP_AUTO_REQUEST_SENSE
;
3239 mb
[2] &= ~TP_STOP_QUEUE
;
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
;
3249 nv2
->bus
[bus
].target
[target
].flags
.
3253 nv2
->bus
[bus
].target
[target
].flags
.
3256 nv2
->bus
[bus
].target
[target
].flags
.
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
;
3283 qla1280_mailbox_command(ha
,
3291 #if DEBUG_PRINT_NVRAM
3292 ql_debug_print
= saved_print_status
;
3296 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
3298 LEAVE("qla1280_nvram_config");
3303 * Get NVRAM data word
3304 * Calculates word position in NVRAM and calls request routine to
3305 * get the word from NVRAM.
3308 * ha = adapter block pointer.
3309 * address = NVRAM word address.
3315 qla1280_get_nvram_word(struct scsi_qla_host
*ha
, uint32_t address
)
3320 #ifdef QL_DEBUG_ROUTINES
3321 int saved_print_status
= ql_debug_print
;
3324 nv_cmd
= address
<< 16;
3325 nv_cmd
|= NV_READ_OP
;
3327 #ifdef QL_DEBUG_ROUTINES
3328 ql_debug_print
= FALSE
;
3330 data
= qla1280_nvram_request(ha
, nv_cmd
);
3331 #ifdef QL_DEBUG_ROUTINES
3332 ql_debug_print
= saved_print_status
;
3336 "qla1280_get_nvram_word: exiting normally NVRAM data = 0x%x",
3344 * Sends read command to NVRAM and gets data from NVRAM.
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
3357 qla1280_nvram_request(struct scsi_qla_host
*ha
, uint32_t nv_cmd
)
3359 struct device_reg
*reg
= ha
->iobase
;
3364 /* Send command to NVRAM. */
3367 for (cnt
= 0; cnt
< 11; cnt
++) {
3368 if (nv_cmd
& BIT_31
)
3369 qla1280_nv_write(ha
, NV_DATA_OUT
);
3371 qla1280_nv_write(ha
, 0);
3375 /* Read data from NVRAM. */
3377 for (cnt
= 0; cnt
< 16; cnt
++) {
3378 WRT_REG_WORD(®
->nvram
, (NV_SELECT
| NV_CLOCK
));
3381 reg_data
= RD_REG_WORD(®
->nvram
);
3382 if (reg_data
& NV_DATA_IN
)
3384 WRT_REG_WORD(®
->nvram
, NV_SELECT
);
3388 /* Deselect chip. */
3390 WRT_REG_WORD(®
->nvram
, NV_DESELECT
);
3397 qla1280_nv_write(struct scsi_qla_host
*ha
, uint16_t data
)
3399 struct device_reg
*reg
= ha
->iobase
;
3401 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
);
3403 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
| NV_CLOCK
);
3405 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
);
3411 * Issue mailbox command and waits for completion.
3414 * ha = adapter block pointer.
3415 * mr = mailbox registers to load.
3416 * mb = data pointer for mailbox registers.
3419 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
3425 qla1280_mailbox_command(struct scsi_qla_host
*ha
, uint8_t mr
, uint16_t * mb
)
3427 struct device_reg
*reg
= ha
->iobase
;
3429 srb_t
*done_q_first
= 0;
3430 srb_t
*done_q_last
= 0;
3434 uint16_t *optr
, *iptr
;
3437 ENTER("qla1280_mailbox_command");
3439 ha
->flags
.mbox_busy
= TRUE
;
3441 if (!ha
->flags
.ints_enabled
)
3443 "Running qla1280_mailbox_command() with interrupts "
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 *) ®
->mailbox0
;
3452 for (cnt
= 0; cnt
< MAILBOX_REGISTER_COUNT
; cnt
++) {
3454 WRT_REG_WORD(optr
, (*iptr
));
3462 /* Issue set host interrupt command. */
3463 ha
->flags
.mbox_int
= FALSE
;
3464 ha
->flags
.mbox_busy
= FALSE
;
3465 WRT_REG_WORD(®
->host_cmd
, HC_SET_HOST_INT
);
3466 data
= qla1280_debounce_register(®
->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
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. */
3479 if (data
& RISC_INT
) {
3480 qla1280_isr(ha
, &done_q_first
, &done_q_last
);
3485 data
= RD_REG_WORD(®
->istatus
);
3488 /* Check for mailbox command timeout. */
3491 "qla1280_mailbox_command: **** Command Timeout, "
3492 "mailbox0 = 0x%x****\n", mb
[0]);
3494 ha
->flags
.isp_abort_needed
= TRUE
;
3496 } else if (ha
->mailbox_out
[0] != MBS_CMD_CMP
)
3499 /* Load return mailbox registers. */
3501 iptr
= (uint16_t *) &ha
->mailbox_out
[0];
3502 mr
= MAILBOX_REGISTER_COUNT
;
3503 memcpy(optr
, iptr
, MAILBOX_REGISTER_COUNT
* sizeof(uint16_t));
3506 /* Go check for any response interrupts pending. */
3507 qla1280_isr(ha
, &done_q_first
, &done_q_last
);
3510 if (ha
->flags
.isp_abort_needed
)
3511 qla1280_abort_isp(ha
);
3513 if (ha
->flags
.reset_marker
)
3514 qla1280_rst_aen(ha
);
3518 qla1280_done (ha
, &done_q_first
, &done_q_last
);
3523 "qla1280_mailbox_command: **** FAILED, mailbox0 = 0x%x "
3526 LEAVE("qla1280_mailbox_command");
3532 * Polls ISP for interrupts.
3535 * ha = adapter block pointer.
3538 qla1280_poll(struct scsi_qla_host
*ha
)
3540 struct device_reg
*reg
= ha
->iobase
;
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(®
->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
);
3560 qla1280_done(ha
, &done_q_first
, &done_q_last
);
3562 /* LEAVE("qla1280_poll"); */
3567 * Issue SCSI bus reset.
3570 * ha = adapter block pointer.
3571 * bus = SCSI bus number.
3577 qla1280_bus_reset(struct scsi_qla_host
*ha
, int bus
)
3579 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3582 dprintk(3, "qla1280_bus_reset: entered\n");
3584 if (qla1280_verbose
)
3585 printk(KERN_INFO
"scsi(%li): Resetting SCSI BUS (%i)\n",
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]);
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
++;
3599 * Eeeeep! This is evil! /Jes
3604 schedule_timeout(4 * HZ
);
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
);
3613 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
3615 dprintk(3, "qla1280_bus_reset: exiting normally\n");
3621 * qla1280_device_reset
3622 * Issue bus device reset message to the target.
3625 * ha = adapter block pointer.
3626 * bus = SCSI BUS number.
3633 qla1280_device_reset(struct scsi_qla_host
*ha
, int bus
, int target
)
3635 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3638 ENTER("qla1280_device_reset");
3640 mb
[0] = MBC_ABORT_TARGET
;
3641 mb
[1] = (bus
? (target
| BIT_7
) : target
) << 8;
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
);
3649 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
3651 LEAVE("qla1280_device_reset");
3656 * qla1280_abort_device
3657 * Issue an abort message to the device
3660 * ha = adapter block pointer.
3669 qla1280_abort_device(struct scsi_qla_host
*ha
, int bus
, int target
, int lun
)
3671 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
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
);
3684 dprintk(2, "qla1280_abort_device: **** FAILED ****\n");
3686 LEAVE("qla1280_abort_device");
3691 * qla1280_abort_command
3692 * Abort command aborts a specified IOCB.
3695 * ha = adapter block pointer.
3696 * sp = SB structure pointer.
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
;
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
)
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;
3725 qla1280_mailbox_command(ha
, BIT_3
| BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
3728 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
3730 sp
->flags
|= SRB_ABORT_PENDING
;
3732 LEAVE("qla1280_abort_command");
3737 * qla1280_reset_adapter
3741 * ha = adapter block pointer.
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(®
->ictrl
, ISP_RESET
);
3753 WRT_REG_WORD(®
->host_cmd
, HC_RESET_RISC
);
3754 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
3755 WRT_REG_WORD(®
->host_cmd
, HC_DISABLE_BIOS
);
3757 LEAVE("qla1280_reset_adapter");
3761 * Issue marker command.
3762 * Function issues marker IOCB.
3765 * ha = adapter block pointer.
3766 * bus = SCSI BUS number
3769 * type = marker modifier
3772 qla1280_marker(struct scsi_qla_host
*ha
, int bus
, int id
, int lun
, u8 type
)
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.
3799 * ha = adapter block pointer.
3800 * sp = SB structure pointer.
3803 * 0 = success, was able to issue command.
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
;
3813 dma_addr_t dma_handle
;
3819 ENTER("qla1280_64bit_start_scsi:");
3821 dprintk(1, "64bit_start: cmd=%p sp=%p CDB=%x\n", cmd
, sp
,
3824 /* Calculate number of entries and segments required. */
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
));
3832 req_cnt
+= (seg_cnt
- 2) / 5;
3833 if ((seg_cnt
- 2) % 5)
3836 } else if (cmd
->request_bufflen
) { /* If data transfer. */
3842 if ((req_cnt
+ 2) >= ha
->req_q_cnt
) {
3843 /* Calculate number of free request entries. */
3844 cnt
= RD_REG_WORD(®
->mailbox4
);
3845 if (ha
->req_ring_index
< cnt
)
3846 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
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. */
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
;
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
;
3918 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg
)));
3920 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg
)));
3922 cpu_to_le32(sg_dma_len(sg
));
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
)));
3931 "qla1280_64bit_start_scsi: Scatter/gather "
3932 "command packet data - b %i, t %i, l %i \n",
3936 qla1280_dump_buffer(5, (char *)pkt
,
3937 REQUEST_ENTRY_SIZE
);
3940 * Build continuation packets.
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
=
3955 ha
->request_ring_ptr
++;
3957 pkt
= (cmd_a64_entry_t
*)ha
->request_ring_ptr
;
3959 /* Zero out packet. */
3961 REQUEST_ENTRY_SIZE
);
3963 /* Load packet defaults. */
3964 ((cont_a64_entry_t
*) pkt
)->entry_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. */
3971 (u32
*)&((cont_a64_entry_t
*) pkt
)->dseg_0_address
;
3973 /* Load continuation entry data segments. */
3979 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg
)));
3981 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg
)));
3983 cpu_to_le32(sg_dma_len(sg
));
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
)));
3992 "qla1280_64bit_start_scsi: continuation "
3993 "packet data - b %i, t %i, l %i \n",
3997 qla1280_dump_buffer(5,
3999 REQUEST_ENTRY_SIZE
);
4001 } else { /* No scatter gather data transfer */
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
;
4011 cpu_to_le32(pci_dma_lo32(dma_handle
));
4013 cpu_to_le32(pci_dma_hi32(dma_handle
));
4015 (uint32_t)cmd
->request_bufflen
;
4017 "No S/G map_single saved_dma_handle=%lx\n",dma_handle);
4020 "qla1280_64bit_start_scsi: No scatter/gather "
4021 "command packet data - b %i, t %i, l %i \n",
4025 qla1280_dump_buffer(5, (char *)pkt
,
4026 REQUEST_ENTRY_SIZE
);
4028 } else { /* No data transfer */
4030 dword_ptr
= (uint32_t *)(pkt
+ 1);
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
),
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
;
4048 ha
->request_ring_ptr
++;
4050 /* Set chip new ring index. */
4052 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
4054 sp
->flags
|= SRB_SENT
;
4056 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
4059 dprintk(2, "qla1280_64bit_start_scsi: NO ROOM IN "
4060 "OUTSTANDING ARRAY, req_q_cnt=0x%x",
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
,
4072 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
4074 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
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.
4093 * ha = adapter block pointer.
4094 * sp = SCSI Request Block structure pointer.
4097 * 0 = success, was able to issue command.
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
;
4105 struct scatterlist
*sg
= NULL
;
4106 uint32_t *dword_ptr
;
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
,
4118 /* Calculate number of entries and segments required. */
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
;
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
4137 req_cnt
+= (seg_cnt
- 4) / 7;
4138 if ((seg_cnt
- 4) % 7)
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
,
4149 /* dprintk(1, "No data transfer \n"); */
4153 if ((req_cnt
+ 2) >= ha
->req_q_cnt
) {
4154 /* Calculate number of free request entries. */
4155 cnt
= RD_REG_WORD(®
->mailbox4
);
4156 if (ha
->req_ring_index
< cnt
)
4157 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
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. */
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.
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
;
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 "
4235 qla1280_dump_buffer(1, (char *)sg
,
4238 /* Load command entry data segments. */
4239 for (cnt
= 0; cnt
< 4 && seg_cnt
;
4242 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
4244 cpu_to_le32(virt_to_bus(sg
->address
));
4245 *dword_ptr
++ = sg
->length
;
4247 "S/G Segment phys_addr=0x%x, len=0x%x\n",
4248 cpu_to_le32(virt_to_bus(sg
->address
)),
4252 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg
)));
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
)));
4262 * Build continuation packets.
4264 dprintk(1, "S/G Building Continuation"
4265 "...seg_cnt=0x%x remains\n",
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
=
4276 ha
->request_ring_ptr
++;
4278 pkt
= (cmd_entry_t
*)
4279 ha
->request_ring_ptr
;
4281 /* Zero out packet. */
4283 REQUEST_ENTRY_SIZE
);
4285 /* Load packet defaults. */
4286 ((cont_entry_t
*) pkt
)->
4287 entry_type
= CONTINUE_TYPE
;
4288 ((cont_entry_t
*) pkt
)->
4291 ((cont_entry_t
*) pkt
)->
4296 /* Setup packet address segment pointer. */
4298 &((cont_entry_t
*) pkt
)->dseg_0_address
;
4300 /* Load continuation entry data segments. */
4305 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
4307 cpu_to_le32(virt_to_bus(sg
->address
));
4308 *dword_ptr
++ = sg
->length
;
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
);
4314 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg
)));
4316 cpu_to_le32(sg_dma_len(sg
));
4318 "S/G Segment Cont. phys_addr=0x%x, "
4320 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg
))),
4321 cpu_to_le32(sg_dma_len(sg
)));
4326 "qla1280_32bit_start_scsi: continuation "
4327 "packet data - scsi(%i:%i:%i)\n",
4331 qla1280_dump_buffer(5,
4333 REQUEST_ENTRY_SIZE
);
4335 } else { /* No S/G data transfer */
4338 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
4340 cpu_to_le32 (virt_to_bus
4341 (cmd
->request_buffer
));
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
;
4350 cpu_to_le32(pci_dma_lo32(dma_handle
));
4353 (uint32_t)cmd
->request_bufflen
;
4355 } else { /* No data transfer at all */
4357 dword_ptr
= (uint32_t *)(pkt
+ 1);
4361 "qla1280_32bit_start_scsi: No data, command "
4362 "packet data - \n");
4363 qla1280_dump_buffer(5, (char *)pkt
,
4364 REQUEST_ENTRY_SIZE
);
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
;
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");
4383 sp
->flags
|= SRB_SENT
;
4385 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
4389 "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
4390 "ARRAY, req_q_cnt=0x%x\n", ha
->req_q_cnt
);
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
,
4401 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
4403 LEAVE("qla1280_32bit_start_scsi");
4410 * Function is responsible for locking ring and
4411 * getting a zeroed out request packet.
4414 * ha = adapter block pointer.
4417 * 0 = failed to get slot.
4420 qla1280_req_pkt(struct scsi_qla_host
*ha
)
4422 struct device_reg
*reg
= ha
->iobase
;
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(®
->mailbox4
);
4437 if (ha
->req_ring_index
< cnt
)
4438 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
4441 REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
4444 /* Found empty request ring slot? */
4445 if (ha
->req_q_cnt
> 0) {
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;
4463 /* Check for pending interrupts. */
4468 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
4470 dprintk(3, "qla1280_req_pkt: exiting normally\n");
4477 * Function is responsible for modifying ISP input pointer.
4478 * Releases ring lock.
4481 * ha = adapter block pointer.
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
;
4500 ha
->request_ring_ptr
++;
4502 /* Set chip new ring index. */
4503 WRT_REG_WORD(®
->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.
4514 * ha = adapter block pointer.
4515 * bus = SCSI BUS number.
4519 qla1280_enable_lun(struct scsi_qla_host
*ha
, int bus
, int lun
)
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;
4543 dprintk(2, "qla1280_enable_lun: **** FAILED ****\n");
4545 dprintk(3, "qla1280_enable_lun: exiting normally\n");
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.
4561 * ha = adapter block pointer.
4562 * inotify = immediate notify entry pointer.
4565 qla1280_notify_ack(struct scsi_qla_host
*ha
, notify_entry_t
* inotify
)
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)
4580 pkt
->seq_id
= inotify
->seq_id
;
4582 /* Issue command to ISP */
4583 qla1280_isp_cmd(ha
);
4587 dprintk(2, "qla1280_notify_ack: **** FAILED ****\n");
4589 dprintk(3, "qla1280_notify_ack: exiting normally\n");
4593 * qla1280_immed_notify
4594 * Issue immediate notify IOCB for LUN 0.
4597 * ha = adapter block pointer.
4598 * inotify = immediate notify entry pointer.
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
;
4615 /* Issue command to ISP */
4616 qla1280_isp_cmd(ha
);
4620 dprintk(2, "qla1280_immed_notify: **** FAILED ****\n");
4622 dprintk(3, "qla1280_immed_notify: exiting normally\n");
4627 * Issue accept target I/O IOCB for LUN 0.
4630 * ha = adapter block pointer.
4631 * ctio = ctio returned entry pointer.
4634 qla1280_accept_io(struct scsi_qla_host
*ha
, ctio_ret_entry_t
* ctio
)
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
;
4649 /* Issue command to ISP */
4650 qla1280_isp_cmd(ha
);
4654 dprintk(2, "qla1280_accept_io: **** FAILED ****\n");
4656 dprintk(3, "qla1280_accept_io: exiting normally\n");
4660 * qla1280_64bit_continue_io
4661 * Issue continue target I/O IOCB.
4664 * ha = adapter block pointer.
4665 * atio = atio pointer.
4666 * len = total bytecount.
4667 * addr = physical address pointer.
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
;
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
);
4702 dprintk(2, "qla1280_64bit_continue_io: **** FAILED ****\n");
4704 dprintk(3, "qla1280_64bit_continue_io: exiting normally\n");
4708 * qla1280_32bit_continue_io
4709 * Issue continue target I/O IOCB.
4712 * ha = adapter block pointer.
4713 * atio = atio pointer.
4714 * len = total bytecount.
4715 * addr = physical address pointer.
4718 qla1280_32bit_continue_io(struct scsi_qla_host
*ha
, atio_entry_t
* atio
,
4719 uint32_t len
, paddr32_t
* addr
)
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
;
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
);
4749 dprintk(2, "qla1280_32bit_continue_io: **** FAILED ****\n");
4751 dprintk(3, "qla1280_32bit_continue_io: exiting normally\n");
4753 #endif /* QL1280_TARGET_MODE_SUPPORT */
4755 /****************************************************************************/
4756 /* Interrupt Service Routine. */
4757 /****************************************************************************/
4759 /****************************************************************************
4761 * Calls I/O done on command completion.
4764 * ha = adapter block pointer.
4765 * done_q_first = done queue first pointer.
4766 * done_q_last = done queue last pointer.
4767 ****************************************************************************/
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
;
4775 uint16_t mailbox
[MAILBOX_REGISTER_COUNT
];
4780 ENTER("qla1280_isr");
4782 istatus
= RD_REG_WORD(®
->istatus
);
4783 if (!(istatus
& (RISC_INT
| PCI_INT
)))
4786 /* Save mailbox register 5 */
4787 mailbox
[5] = RD_REG_WORD(®
->mailbox5
);
4789 /* Check for mailbox interrupt. */
4791 mailbox
[0] = RD_REG_WORD(®
->semaphore
);
4793 if (mailbox
[0] & BIT_0
) {
4794 /* Get mailbox data. */
4795 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
4798 *wptr
++ = RD_REG_WORD(®
->mailbox0
);
4799 *wptr
++ = RD_REG_WORD(®
->mailbox1
);
4800 *wptr
= RD_REG_WORD(®
->mailbox2
);
4801 if (mailbox
[0] != MBA_SCSI_COMPLETION
) {
4803 *wptr
++ = RD_REG_WORD(®
->mailbox3
);
4804 *wptr
++ = RD_REG_WORD(®
->mailbox4
);
4806 *wptr
++ = RD_REG_WORD(®
->mailbox6
);
4807 *wptr
= RD_REG_WORD(®
->mailbox7
);
4810 /* Release mailbox registers. */
4812 WRT_REG_WORD(®
->semaphore
, 0);
4813 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
4815 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
4818 /* Handle asynchronous event */
4819 switch (mailbox
[0]) {
4820 case MBA_SCSI_COMPLETION
: /* Response completion */
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
];
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 */
4843 sp
->s_prev
= *done_q_last
;
4847 (*done_q_last
)->s_next
= sp
;
4851 * If we get here we have a real problem!
4854 "qla1280: ISP invalid handle");
4855 ha
->flags
.isp_abort_needed
= TRUE
;
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
;
4866 "qla1280_isr(): index %i asynchronous "
4867 "BUS_RESET\n", index
);
4870 case MBA_SYSTEM_ERR
: /* System Error */
4872 "qla1280: ISP System Error - mbx1=%xh, mbx2=%xh, "
4873 "mbx3=%xh\n", mailbox
[1], mailbox
[2],
4875 ha
->flags
.isp_abort_needed
= TRUE
;
4878 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
4880 "qla1280: ISP Request Transfer Error\n");
4881 ha
->flags
.isp_abort_needed
= TRUE
;
4884 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
4886 "qla1280: ISP Response Transfer Error\n");
4887 ha
->flags
.isp_abort_needed
= TRUE
;
4890 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up */
4891 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
4894 case MBA_TIMEOUT_RESET
: /* Execution Timeout Reset */
4896 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
4899 case MBA_DEVICE_RESET
: /* Bus Device Reset */
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
;
4910 case MBA_BUS_MODE_CHANGE
:
4912 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
4916 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
4917 if (mailbox
[0] < MBA_ASYNC_EVENT
) {
4919 memcpy((uint16_t *) ha
->mailbox_out
, wptr
,
4920 MAILBOX_REGISTER_COUNT
*
4922 ha
->flags
.mbox_int
= TRUE
;
4927 WRT_REG_WORD(®
->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
4937 && !ha
->flags
.mbox_busy
4940 if (mailbox
[5] < RESPONSE_ENTRY_CNT
) {
4941 while (ha
->rsp_ring_index
!= mailbox
[5]) {
4942 pkt
= ha
->response_ring_ptr
;
4945 "qla1280_isr: ha->rsp_ring_index = 0x%x, "
4946 "mailbox[5] = 0x%x\n",
4947 ha
->rsp_ring_index
, mailbox
[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)
4956 || pkt
->entry_status
) {
4958 "qla1280_isr: ha->rsp_ring_index = 0x%x"
4959 "mailbox[5] = 0x%x, comp_status = 0x%x, "
4960 "scsi_status = 0x%x\n",
4968 "qla1280_isr: ha->rsp_ring_index = 0x%x, "
4969 "mailbox[5] = 0x%x\n",
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
,
4986 qla1280_error_entry(ha
, pkt
,
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
=
4998 ha
->response_ring_ptr
++;
4999 WRT_REG_WORD(®
->mailbox5
,
5000 ha
->rsp_ring_index
);
5002 #if QLA1280_TARGET_MODE_SUPPORT
5004 pkt
= &response_entry
;
5008 (uint32_t *)ha
->response_ring_ptr
;
5009 dptr2
= (uint32_t *) pkt
;
5011 index
< RESPONSE_ENTRY_SIZE
/ 4;
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
=
5023 ha
->response_ring_ptr
++;
5024 WRT_REG_WORD(®
->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
);
5032 case IMMED_NOTIFY_TYPE
:
5033 qla1280_notify_entry(ha
,
5034 (notify_entry_t
*) pkt
);
5037 qla1280_accept_io(ha
,
5038 (ctio_ret_entry_t
*) pkt
);
5047 ha
->flags
.isp_abort_needed
= TRUE
;
5048 dprintk(2, "qla1280_isr: Response pointer Error\n");
5052 LEAVE("qla1280_isr");
5057 * Processes asynchronous reset.
5060 * ha = adapter block pointer.
5063 qla1280_rst_aen(struct scsi_qla_host
*ha
)
5065 #if QL1280_TARGET_MODE_SUPPORT
5066 notify_entry_t nentry
;
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
=
5083 qla1280_marker(ha
, bus
, 0, 0,
5086 if (!ha
->flags
.reset_marker
) {
5087 #if QL1280_TARGET_MODE_SUPPORT
5088 /* Issue notify acknowledgement command. */
5090 sizeof(notify_entry_t
));
5092 nentry
.initiator_id
=
5094 bus
? ha
->bus_settings
[bus
].id
| BIT_7
:
5095 ha
->bus_settings
[bus
].id
;
5096 qla1280_notify_entry(ha
,
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.
5115 * ha = adapter block pointer.
5116 * pkt = entry pointer.
5119 qla1280_atio_entry(struct scsi_qla_host
*ha
, atio_entry_t
* pkt
)
5123 paddr32_t phy_addr
[2];
5124 paddr32_t end_addr
[2];
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");
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
);
5149 memset(sense_ptr
, 0, TARGET_SENSE_SIZE
);
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);
5163 qla1280_32bit_continue_io(ha
, pkt
, 0, 0);
5166 case 0x16: /* Requested Capability Not Available */
5167 dprintk(2, "qla1280_atio_entry: Target Bus Phase "
5168 "Sequence Failure\n");
5171 case 0x17: /* Bus Device Reset Message Received */
5172 dprintk(2, "qla1280_atio_entry: Target Bus Phase "
5173 "Sequence Failure\n");
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]) {
5185 dprintk(3, "qla1280_atio_entry: SS_TEST\n");
5187 memset(sense_ptr
, 0, TARGET_SENSE_SIZE
);
5190 pkt
->scsi_status
= S_GOOD
;
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
);
5203 dprintk(3, "qla1280_atio_entry: SS_REQSEN\n");
5205 phy_addr
[0] = ha
->tsense_dma
;
5207 *a64
+= t
* TARGET_SENSE_SIZE
;
5208 if (pkt
->cdb
[4] > TARGET_SENSE_SIZE
)
5209 len
= TARGET_SENSE_SIZE
;
5212 pkt
->scsi_status
= S_GOOD
;
5213 pkt
->option_flags
|= (OF_SSTS
| OF_DATA_IN
);
5217 dprintk(3, "qla1280_atio_entry: SS_INQUIR\n");
5219 memset(sense_ptr
, 0, TARGET_SENSE_SIZE
);
5220 phy_addr
[0] = ha
->tbuf_dma
;
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
;
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
);
5236 pkt
->scsi_status
= S_GOOD
;
5237 pkt
->option_flags
|= (OF_SSTS
| OF_DATA_IN
);
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;
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) {
5253 dprintk(3, "qla1280_atio_entry: SM_WRDB, "
5256 if (len
> TARGET_DATA_SIZE
+ 4) {
5258 "qla1280_atio_entry: SM_WRDB, "
5259 "length > buffer size\n");
5262 *(sense_ptr
+ 2) = SD_ILLREQ
;
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
);
5271 pkt
->scsi_status
= S_GOOD
;
5272 pkt
->option_flags
|=
5273 (OF_SSTS
| OF_DATA_OUT
);
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,
5283 "qla1280_atio_entry: SM_WRDB, "
5286 pkt
->scsi_status
= S_GOOD
;
5287 pkt
->option_flags
|=
5288 (OF_SSTS
| OF_NO_DATA
);
5293 dprintk(3, "qla1280_atio_entry: SM_WRDB, "
5296 *a64
+= offset
+ TARGET_DATA_OFFSET
;
5297 if (pkt
->cdb
[2] != 0 || *a64
>= *end_a64
||
5298 *a64
+ len
> *end_a64
) {
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],
5307 *(sense_ptr
+ 2) = SD_ILLREQ
;
5309 TARGET_SENSE_SIZE
- 8;
5310 *(sense_ptr
+ 12) = SC_ILLCDB
;
5312 pkt
->scsi_status
= S_CKCON
;
5313 pkt
->option_flags
|=
5314 (OF_SSTS
| OF_NO_DATA
);
5316 pkt
->scsi_status
= S_GOOD
;
5317 pkt
->option_flags
|=
5318 (OF_SSTS
| OF_DATA_OUT
);
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,
5328 "qla1280_atio_entry: SM_WRDB, "
5331 pkt
->scsi_status
= S_GOOD
;
5332 pkt
->option_flags
|=
5333 (OF_SSTS
| OF_NO_DATA
);
5338 dprintk(2, "qla1280_atio_entry: SM_WRDB "
5342 *(sense_ptr
+ 2) = SD_ILLREQ
;
5343 *(sense_ptr
+ 7) = TARGET_SENSE_SIZE
- 8;
5344 *(sense_ptr
+ 12) = SC_ILLCDB
;
5346 pkt
->scsi_status
= S_CKCON
;
5347 pkt
->option_flags
|= (OF_SSTS
| OF_NO_DATA
);
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;
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) {
5365 dprintk(3, "qla1280_atio_entry: SM_RDDB, "
5369 ha
->tbuf
->hdr
[0] = 0;
5371 (TARGET_DATA_SIZE
>> 16) & 0xff;
5373 (TARGET_DATA_SIZE
>> 8) & 0xff;
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
);
5383 "qla1280_atio_entry: SM_RDDB, "
5386 pkt
->scsi_status
= S_GOOD
;
5387 pkt
->option_flags
|=
5388 (OF_SSTS
| OF_NO_DATA
);
5392 dprintk(3, "qla1280_atio_entry: SM_RDDB, "
5395 *a64
+= offset
+ TARGET_DATA_OFFSET
;
5396 if (pkt
->cdb
[2] != 0 || *a64
>= *end_a64
) {
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
);
5404 *(sense_ptr
+ 2) = SD_ILLREQ
;
5406 TARGET_SENSE_SIZE
- 8;
5407 *(sense_ptr
+ 12) = SC_ILLCDB
;
5409 pkt
->scsi_status
= S_CKCON
;
5410 pkt
->option_flags
|=
5411 (OF_SSTS
| OF_NO_DATA
);
5413 if (*a64
+ len
> *end_a64
)
5414 len
= *end_a64
- *a64
;
5416 pkt
->scsi_status
= S_GOOD
;
5417 pkt
->option_flags
|=
5418 (OF_SSTS
| OF_DATA_IN
);
5421 "qla1280_atio_entry: SM_RDDB, "
5424 pkt
->scsi_status
= S_GOOD
;
5425 pkt
->option_flags
|=
5426 (OF_SSTS
| OF_NO_DATA
);
5431 dprintk(3, "qla1280_atio_entry: SM_RDDB, "
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;
5445 (TARGET_DATA_SIZE
>> 16) &
5448 (TARGET_DATA_SIZE
>> 8) &
5451 TARGET_DATA_SIZE
& 0xff;
5453 pkt
->scsi_status
= S_GOOD
;
5454 pkt
->option_flags
|=
5455 (OF_SSTS
| OF_DATA_IN
);
5458 "qla1280_atio_entry: SM_RDDB,"
5461 pkt
->scsi_status
= S_GOOD
;
5462 pkt
->option_flags
|=
5463 (OF_SSTS
| OF_NO_DATA
);
5467 dprintk(2, "qla1280_atio_entry: SM_RDDB "
5471 *(sense_ptr
+ 2) = SD_ILLREQ
;
5472 *(sense_ptr
+ 7) = TARGET_SENSE_SIZE
- 8;
5473 *(sense_ptr
+ 12) = SC_ILLCDB
;
5475 pkt
->scsi_status
= S_CKCON
;
5476 pkt
->option_flags
|= (OF_SSTS
| OF_NO_DATA
);
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
);
5488 *(sense_ptr
+ 2) = SD_ILLREQ
;
5489 *(sense_ptr
+ 7) = TARGET_SENSE_SIZE
- 8;
5490 *(sense_ptr
+ 12) = SC_INVOPCODE
;
5492 pkt
->scsi_status
= S_CKCON
;
5493 pkt
->option_flags
|= (OF_SSTS
| OF_NO_DATA
);
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
);
5502 qla1280_32bit_continue_io(ha
, pkt
, len
,
5503 (paddr32_t
*)&phy_addr
);
5510 dprintk(3, "qla1280_atio_entry: exiting normally\n");
5514 * qla1280_notify_entry
5515 * Processes received ISP immediate notify entry.
5518 * ha = adapter block pointer.
5519 * pkt = entry pointer.
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.
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.
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
;
5556 ENTER("qla1280_status_entry");
5558 /* Validate handle. */
5559 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
5560 sp
= ha
->outstanding_cmds
[pkt
->handle
];
5565 /* Free outstanding command slot. */
5566 ha
->outstanding_cmds
[pkt
->handle
] = 0;
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
);
5583 if (pkt
->scsi_status
& SS_BUSY_CONDITION
&&
5584 pkt
->scsi_status
!= SS_RESERVE_CONFLICT
) {
5586 DID_BUS_BUSY
<< 16 | (pkt
->scsi_status
& 0xff);
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
<
5596 sense_sz
= pkt
->req_sense_length
;
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
);
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
);
5616 qla1280_dump_buffer(2, (char *)cmd
->sense_buffer
,
5620 /* Place command on done queue. */
5621 qla1280_done_q_put(sp
, done_q_first
, done_q_last
);
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.
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.
5641 qla1280_error_entry(struct scsi_qla_host
*ha
, response_t
* pkt
,
5642 srb_t
** done_q_first
, srb_t
** done_q_last
)
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");
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
];
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;
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
;
5688 LEAVE("qla1280_error_entry");
5693 * Resets ISP and aborts all outstanding commands.
5696 * ha = adapter block pointer.
5702 qla1280_abort_isp(struct scsi_qla_host
*ha
)
5705 struct device_reg
*reg
= ha
->iobase
;
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
];
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. */
5737 q
->q_flag
&= ~QLA1280_QBUSY
;
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. */
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
);
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
);
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,
5774 } while (ha
->flags
.reset_marker
);
5776 /* Enable host adapter target mode. */
5777 for (bus
= 0; bus
< ha
->ports
; bus
++) {
5780 qla1280_enable_tgt(ha
, bus
))) {
5781 for (cnt
= 0; cnt
< MAX_LUNS
;
5783 /* qla1280_enable_lun(ha, bus, cnt); */
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
);
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");
5815 * qla1280_restart_queues
5816 * Restart all device queues.
5819 * ha = adapter block pointer.
5822 qla1280_restart_queues(struct scsi_qla_host
*ha
)
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
);
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.
5846 * ha = adapter block pointer.
5849 qla1280_abort_queue_single(struct scsi_qla_host
*ha
, int bus
,
5850 int target
, int lun
, uint32_t stat
)
5853 srb_t
*sp
, *sp_next
;
5855 ENTER("qla1280_abort_queue_single");
5856 q
= LU_Q(ha
, bus
, target
, lun
);
5859 q
->q_first
= q
->q_last
= NULL
;
5862 sp_next
= sp
->s_next
;
5863 CMD_RESULT(sp
->cmd
) = stat
;
5864 qla1280_done_q_put(sp
, &ha
->done_q_first
,
5869 LEAVE("qla1280_abort_queue_single");
5873 * qla1280_abort_queues
5874 * Abort all commands on device queues.
5877 * ha = adapter block pointer.
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
,
5892 LEAVE("qla1280_abort_queues");
5896 * qla1280_debounce_register
5897 * Debounce register.
5900 * port = register address.
5906 qla1280_debounce_register(volatile u16
* addr
)
5911 ret
= RD_REG_WORD(addr
);
5912 ret2
= RD_REG_WORD(addr
);
5919 ret
= RD_REG_WORD(addr
);
5920 ret2
= RD_REG_WORD(addr
);
5921 } while (ret
!= ret2
);
5926 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
5928 Scsi_Host_Template driver_template
= QLA1280_LINUX_TEMPLATE
;
5929 #include "scsi_module.c"
5931 #else /* new kernel scsi initialization scheme */
5932 static Scsi_Host_Template driver_template
= QLA1280_LINUX_TEMPLATE
;
5933 #include "scsi_module.c"
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
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
;
5953 * If SCSI Bus is Dead because of bad termination,
5954 * we will return a status of Selection timeout.
5958 bus
= SCSI_BUS_32(cp
);
5960 if (ha
->bus_settings
[bus
].scsi_bus_dead
) {
5961 WRT_REG_WORD(®
->host_cmd
, HC_PAUSE_RISC
);
5962 config_reg
= RD_REG_WORD(®
->cfg_1
);
5963 WRT_REG_WORD(®
->cfg_1
, SET_SXP_BANK
);
5964 scsi_control
= RD_REG_WORD(®
->scsiControlPins
);
5965 WRT_REG_WORD(®
->cfg_1
, config_reg
);
5966 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
5968 if (scsi_control
== SCSI_PHASE_INVALID
) {
5969 ha
->bus_settings
[bus
].scsi_bus_dead
= TRUE
;
5971 CMD_RESULT(cp
) = DID_NO_CONNECT
<< 16;
5972 CMD_HANDLE(cp
) = NULL
;
5973 /* ha->actthreads--; */
5975 (*(cp
)->scsi_done
)(cp
);
5977 return TRUE
; /* bus is dead */
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 */
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
);
5995 qla1280_mailbox_command(ha
, BIT_6
| BIT_3
| BIT_2
| BIT_1
| BIT_0
,
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) {
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
6020 qla1280_getbyte (u8
* port
)
6024 #if MEMORY_MAPPED_IO
6025 ret
= readb((unsigned long) port
);
6027 ret
= inb((unsigned long) port
);
6032 "qla1280_getbyte: address = 0x%p, data = 0x%x", port
,
6039 * Get word from I/O port
6042 qla1280_getword (u16
* port
)
6046 #if MEMORY_MAPPED_IO
6047 ret
= readw(unsigned long) port
;
6049 ret
= inw((unsigned long) port
);
6054 "qla1280_getbyte: address = 0x%p, data = 0x%x", port
,
6061 * Get double word from I/O port
6064 qla1280_getdword (u32
* port
)
6068 #if MEMORY_MAPPED_IO
6069 ret
= readl((unsigned long) port
);
6071 ret
= inl((unsigned long) port
);
6076 "qla1280_getbyte: address = 0x%p, data = 0x%x", port
,
6083 * Send byte to I/O port
6086 qla1280_putbyte(u8
* port
, u8 data
)
6088 #if MEMORY_MAPPED_IO
6089 writeb(data
, (unsigned long) port
);
6091 outb(data
, (unsigned long) port
);
6096 "qla1280_getbyte: address = 0x%p, data = 0x%x", port
,
6101 * Send word to I/O port
6104 qla1280_putword(u16
* port
, u16 data
)
6106 #if MEMORY_MAPPED_IO
6107 writew(data
, (unsigned long) port
);
6109 outw(data
, (unsigned long) port
);
6114 "qla1280_getbyte: address = 0x%p, data = 0x%x", port
,
6119 * Send double word to I/O port
6122 qla1280_putdword(u32
* port
, u32 data
)
6124 #if MEMORY_MAPPED_IO
6125 writel(data
, (unsigned long) port
);
6127 outl(data
, (unsigned long) port
);
6132 "qla1280_getbyte: address = 0x%p, data = 0x%x", port
,
6137 * Dummy function to prevent warnings for
6138 * declared and unused debug functions
6145 qla1280_getdword(0);
6146 qla1280_putbyte(0, 0);
6147 qla1280_putword(0, 0);
6148 qla1280_putdword(0, 0);
6152 __qla1280_dump_buffer(char *b
, int size
)
6157 if (ql_debug_print
) {
6159 " 0 1 2 3 4 5 6 7 8 9 Ah "
6160 "Bh Ch Dh Eh Fh\n");
6162 "---------------------------------------------"
6163 "------------------\n");
6165 for (cnt
= 0; cnt
< size
;) {
6183 /**************************************************************************
6184 * ql1280_print_scsi_cmd
6186 **************************************************************************/
6188 qla1280_print_scsi_cmd(Scsi_Cmnd
* cmd
)
6190 struct scsi_qla_host
*ha
;
6191 struct Scsi_Host
*host
= cmd
->host
;
6193 /* struct scatterlist *sg; */
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
);
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
);
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)));
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 **************************************************************************/
6227 ql1280_dump_device(struct scsi_qla_host
*ha
)
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
)
6239 if ((cp
= sp
->cmd
) == NULL
)
6241 qla1280_print_scsi_cmd(1, cp
);
6248 /**************************************************************************
6251 **************************************************************************/
6253 qla1280_panic(char *cp
, struct Scsi_Host
*host
)
6255 struct scsi_qla_host
*ha
;
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",
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) {
6273 ql1280_dump_device((struct scsi_qla_host
*)host
->hostdata
);
6289 /**************************************************************************
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 **************************************************************************/
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 */
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 */
6313 qla1280_get_token(char *cmdline
, char *str
)
6315 register char *cp
= cmdline
;
6317 /* skip preceeding spaces */
6318 while (strchr (cp
, ' '))
6320 /* symbol starts here */
6322 /* skip char if not a space or : */
6323 while (*cp
&& !(strchr (cp
, ' ') || strchr (cp
, ':')))
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
6335 * ---------------------------------------------------------------------------