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 dependent device probe code
111 - Move duplicate probe/init code to separate 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
335 /* MACROS for managing the endian addresses */
336 static inline uint16_t qla1280_addr0_15(dma_addr_t dma
)
338 return ((uint16_t)(dma
& 0xffff));
340 static inline uint16_t qla1280_addr16_31(dma_addr_t dma
)
342 return ((uint16_t)((dma
>> 16) & 0xffff));
344 static inline uint16_t qla1280_addr32_47(dma_addr_t dma
)
346 return ((uint16_t)(pci_dma_hi32(dma
) & 0xffff));
348 static inline uint16_t qla1280_addr48_63(dma_addr_t dma
)
350 return ((uint16_t)((pci_dma_hi32(dma
) >> 16) & 0xffff));
353 #define NVRAM_DELAY() udelay(500) /* 2 microsecond delay */
355 #define CACHE_FLUSH(a) RD_REG_WORD(a)
356 #define INVALID_HANDLE (MAX_OUTSTANDING_COMMANDS + 1)
361 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
362 #define pci_set_dma_mask(dev, mask) dev->dma_mask = mask;
363 #define pci_enable_device(pdev) 0
364 #define pci_find_subsys(id, dev, sid, sdev, pdev) pci_find_device(id,dev,pdev)
365 #define scsi_set_pci_device(host, pdev)
368 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
369 typedef unsigned long dma_addr_t
;
372 pci_alloc_consistent(struct pci_dev
*hwdev
, size_t size
,
373 dma_addr_t
* dma_handle
)
377 virt_ptr
= kmalloc(size
, GFP_KERNEL
);
380 *dma_handle
= virt_to_bus(virt_ptr
);
384 #define pci_free_consistent(cookie, size, ptr, dma_ptr) kfree(ptr)
385 #define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
386 #define pci_map_sg(cookie, scatter, ents, dir) ents
387 #define pci_unmap_single(cookie, address, size, dir)
388 #define pci_unmap_sg(cookie, scatter, ents, dir)
390 #define pci_resource_start(dev, i) dev->base_address[i]
394 * QLogic Driver Support Function Prototypes.
396 static void qla1280_done(struct scsi_qla_host
*, srb_t
**, srb_t
**);
397 static void qla1280_next(struct scsi_qla_host
*, scsi_lu_t
*, int);
398 static void qla1280_putq_t(scsi_lu_t
*, srb_t
*);
399 static void qla1280_done_q_put(srb_t
*, srb_t
**, srb_t
**);
400 static int qla1280_slave_configure(Scsi_Device
*);
402 static void qla1280_panic(char *, struct Scsi_Host
*host
);
404 static void qla1280_abort_queue_single(struct scsi_qla_host
*, int, int,
407 static int qla1280_return_status(sts_entry_t
* sts
, Scsi_Cmnd
* cp
);
408 static void qla1280_removeq(scsi_lu_t
* q
, srb_t
* sp
);
409 static void qla1280_mem_free(struct scsi_qla_host
*ha
);
410 void qla1280_do_dpc(void *p
);
412 static char *qla1280_get_token(char *, char *);
414 static inline void qla1280_enable_intrs(struct scsi_qla_host
*);
415 static inline void qla1280_disable_intrs(struct scsi_qla_host
*);
418 * QLogic ISP1280 Hardware Support Function Prototypes.
420 static int qla1280_initialize_adapter(struct scsi_qla_host
*ha
);
421 static int qla1280_enable_tgt(struct scsi_qla_host
*, int);
422 static int qla1280_isp_firmware(struct scsi_qla_host
*);
423 static int qla1280_pci_config(struct scsi_qla_host
*);
424 static int qla1280_chip_diag(struct scsi_qla_host
*);
425 static int qla1280_setup_chip(struct scsi_qla_host
*);
426 static int qla1280_init_rings(struct scsi_qla_host
*);
427 static int qla1280_nvram_config(struct scsi_qla_host
*);
428 static int qla1280_mailbox_command(struct scsi_qla_host
*,
429 uint8_t, uint16_t *);
430 static int qla1280_bus_reset(struct scsi_qla_host
*, int);
431 static int qla1280_device_reset(struct scsi_qla_host
*, int, int);
432 static int qla1280_abort_device(struct scsi_qla_host
*, int, int, int);
433 static int qla1280_abort_command(struct scsi_qla_host
*, srb_t
*);
434 static int qla1280_abort_isp(struct scsi_qla_host
*);
435 static int qla1280_64bit_start_scsi(struct scsi_qla_host
*, srb_t
*);
436 static int qla1280_32bit_start_scsi(struct scsi_qla_host
*, srb_t
*);
437 static void qla1280_nv_write(struct scsi_qla_host
*, uint16_t);
438 static void qla1280_poll(struct scsi_qla_host
*);
439 static void qla1280_reset_adapter(struct scsi_qla_host
*);
440 static void qla1280_marker(struct scsi_qla_host
*, int, int, int, u8
);
441 static void qla1280_isp_cmd(struct scsi_qla_host
*);
442 static void qla1280_isr(struct scsi_qla_host
*, srb_t
**, srb_t
**);
443 static void qla1280_rst_aen(struct scsi_qla_host
*);
444 static void qla1280_status_entry(struct scsi_qla_host
*, sts_entry_t
*,
446 static void qla1280_error_entry(struct scsi_qla_host
*, response_t
*,
448 static void qla1280_restart_queues(struct scsi_qla_host
*);
449 static void qla1280_abort_queues(struct scsi_qla_host
*);
450 static uint16_t qla1280_get_nvram_word(struct scsi_qla_host
*, uint32_t);
451 static uint16_t qla1280_nvram_request(struct scsi_qla_host
*, uint32_t);
452 static uint16_t qla1280_debounce_register(volatile uint16_t *);
453 static request_t
*qla1280_req_pkt(struct scsi_qla_host
*);
454 static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host
*,
456 static int qla1280_mem_alloc(struct scsi_qla_host
*ha
);
458 static void qla12160_get_target_parameters(struct scsi_qla_host
*,
459 uint32_t, uint32_t, uint32_t);
461 /* convert scsi data direction to request_t control flags
463 static inline uint16_t
464 qla1280_data_direction(struct scsi_cmnd
*cmnd
)
468 switch(cmnd
->sc_data_direction
) {
478 case SCSI_DATA_WRITE
:
482 case SCSI_DATA_UNKNOWN
:
484 flags
= BIT_5
| BIT_6
;
490 #if QL1280_LUN_SUPPORT
491 static void qla1280_enable_lun(struct scsi_qla_host
*, int, int);
494 #if QL1280_TARGET_MODE_SUPPORT
495 static void qla1280_notify_ack(struct scsi_qla_host
*, notify_entry_t
*);
496 static void qla1280_immed_notify(struct scsi_qla_host
*, notify_entry_t
*);
497 static void qla1280_accept_io(struct scsi_qla_host
*, ctio_ret_entry_t
*);
498 static void qla1280_64bit_continue_io(struct scsi_qla_host
*, atio_entry_t
*,
499 uint32_t, paddr32_t
*);
500 static void qla1280_32bit_continue_io(struct scsi_qla_host
*, atio_entry_t
*,
501 uint32_t, paddr32_t
*);
502 static void qla1280_atio_entry(struct scsi_qla_host
*, atio_entry_t
*);
503 static void qla1280_notify_entry(struct scsi_qla_host
*, notify_entry_t
*);
504 #endif /* QLA1280_TARGET_MODE_SUPPORT */
506 #ifdef QL_DEBUG_ROUTINES
508 * Driver Debug Function Prototypes.
510 static u8
qla1280_getbyte(u8
*);
511 static u16
qla1280_getword(u16
*);
512 static u32
qla1280_getdword(u32
*);
513 static void qla1280_putbyte(u8
*, u8
);
514 static void qla1280_putword(u16
*, u8
);
515 static void qla1280_putdword(u32
*, u32
);
516 static void __qla1280_print_scsi_cmd(Scsi_Cmnd
* cmd
);
517 static void __qla1280_dump_buffer(char *, u32
);
521 * insmod needs to find the variable and make it point to something
524 static char *options
= NULL
;
526 /* insmod qla1280 options=verbose" */
527 MODULE_PARM(options
, "s");
530 MODULE_LICENSE("GPL");
532 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
534 * Our directory Entry in /proc/scsi for the user to
537 /* Need to add in proc_fs.h PROC_SCSI_QL1280 */
538 #define PROC_SCSI_QL1280 PROC_SCSI_QLOGICISP
540 struct proc_dir_entry proc_scsi_qla1280
= {
541 PROC_SCSI_QL1280
, 7, "qla1280",
542 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2,
543 0, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
547 /* We use the Scsi_Pointer structure that's included with each command
548 * SCSI_Cmnd as a scratchpad for our SRB.
550 * SCp will always point to the SRB structure (defined in qla1280.h).
551 * It is define as follows:
552 * - SCp.ptr -- > pointer back to the cmd
553 * - SCp.this_residual --> used as forward pointer to next srb
554 * - SCp.buffer --> used as backward pointer to next srb
555 * - SCp.buffers_residual --> used as flags field
556 * - SCp.have_data_in --> not used
557 * - SCp.sent_command --> not used
558 * - SCp.phase --> not used
561 #define CMD_SP(Cmnd) &Cmnd->SCp
562 #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
563 #define CMD_CDBP(Cmnd) Cmnd->cmnd
564 #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
565 #define CMD_SNSLEN(Cmnd) sizeof(Cmnd->sense_buffer)
566 #define CMD_RESULT(Cmnd) Cmnd->result
567 #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
569 /*****************************************/
570 /* ISP Boards supported by this driver */
571 /*****************************************/
573 #define NUM_OF_ISP_DEVICES 6
576 unsigned char bdName
[9]; /* Board ID String */
577 unsigned long device_id
; /* Device PCI ID */
578 int numPorts
; /* Number of SCSI ports */
579 unsigned short *fwcode
; /* pointer to FW array */
580 unsigned short *fwlen
; /* number of words in array */
581 unsigned short *fwstart
; /* start address for F/W */
582 unsigned char *fwver
; /* Ptr to F/W version array */
585 struct qla_boards ql1280_board_tbl
[NUM_OF_ISP_DEVICES
] = {
586 /* Name , Board PCI Device ID, Number of ports */
587 {"QLA12160 ", PCI_DEVICE_ID_QLOGIC_ISP12160
, 2,
588 &fw12160i_code01
[0], &fw12160i_length01
,
589 &fw12160i_addr01
, &fw12160i_version_str
[0]},
590 {"QLA1080 ", PCI_DEVICE_ID_QLOGIC_ISP1080
, 1,
591 &fw1280ei_code01
[0], &fw1280ei_length01
,
592 &fw1280ei_addr01
, &fw1280ei_version_str
[0]},
593 {"QLA1240 ", PCI_DEVICE_ID_QLOGIC_ISP1240
, 2,
594 &fw1280ei_code01
[0], &fw1280ei_length01
,
595 &fw1280ei_addr01
, &fw1280ei_version_str
[0]},
596 {"QLA1280 ", PCI_DEVICE_ID_QLOGIC_ISP1280
, 2,
597 &fw1280ei_code01
[0], &fw1280ei_length01
,
598 &fw1280ei_addr01
, &fw1280ei_version_str
[0]},
599 {"QLA10160 ", PCI_DEVICE_ID_QLOGIC_ISP10160
, 1,
600 &fw12160i_code01
[0], &fw12160i_length01
,
601 &fw12160i_addr01
, &fw12160i_version_str
[0]},
605 static int qla1280_verbose
= 1;
606 static struct scsi_qla_host
*qla1280_hostlist
= NULL
;
608 static int qla1280_buffer_size
= 0;
609 static char *qla1280_buffer
= NULL
;
613 static int ql_debug_print
= 1;
616 static int ql_debug_level
= 0;
617 #define dprintk(level, format, a...) \
618 if ((ql_debug_level >= level) && ql_debug_print) printk(KERN_DEBUG format, ##a)
619 #define qla1280_dump_buffer(level, buf, size) \
620 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
621 #define qla1280_dump_print_cmd(level, cmd) \
622 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
625 #define ql_debug_level 0
626 #define dprintk(level, format, a...) do{}while(0)
627 #define qla1280_dump_buffer(a, b, c) do{}while(0)
628 #define qla1280_print_scsi_cmd(a, b) do{}while(0)
631 #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
632 #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
633 #define ENTER_INTR(x) dprintk(3, "qla1280 : Entering %s()\n", x);
634 #define LEAVE_INTR(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
636 #define SCSI_BUS_32(scp) scp->device->channel
637 #define SCSI_TCN_32(scp) scp->device->id
638 #define SCSI_LUN_32(scp) scp->device->lun
640 /****************************************************************************/
641 /* LINUX - Loadable Module Functions. */
642 /****************************************************************************/
644 /*************************************************************************
648 * Set parameters for the driver from the /proc filesystem.
651 *************************************************************************/
653 qla1280_set_info(char *buffer
, int length
, struct Scsi_Host
*HBAptr
)
655 return -ENOSYS
; /* Currently this is a no-op */
658 /*************************************************************************
662 * Return information to handle /proc support for the driver.
664 * buffer - ptrs to a page buffer
667 *************************************************************************/
668 #define PROC_BUF &qla1280_buffer[len]
671 qla1280_proc_info(struct Scsi_Host
*host
, char *buffer
, char **start
, off_t offset
, int length
,
675 struct scsi_qla_host
*ha
;
679 struct qla_boards
*bdp
;
683 /* Find the host that was specified */
684 for (ha
= qla1280_hostlist
; (ha
!= NULL
) && ha
->host
!= host
;
687 if (inout
== TRUE
) { /* Has data been written to the file? */
689 "qla1280_proc: has data been written to the file.\n");
690 return qla1280_set_info(buffer
, length
, host
);
694 * if our old buffer is the right size use it otherwise
695 * allocate a new one.
697 if (qla1280_buffer_size
!= PAGE_SIZE
) {
698 /* deallocate this buffer and get a new one */
699 if (qla1280_buffer
!= NULL
) {
700 free_page((unsigned long)qla1280_buffer
);
701 qla1280_buffer_size
= 0;
703 qla1280_buffer
= (char *)get_zeroed_page(GFP_KERNEL
);
705 if (qla1280_buffer
== NULL
) {
706 size
= sprintf(buffer
, "qla1280 - kmalloc error at line %d\n",
710 /* save the size of our buffer */
711 qla1280_buffer_size
= PAGE_SIZE
;
713 /* 3.20 clear the buffer we use for proc display */
714 memset(qla1280_buffer
, 0, PAGE_SIZE
);
716 /* start building the print buffer */
717 bdp
= &ql1280_board_tbl
[ha
->devnum
];
718 size
= sprintf(PROC_BUF
,
719 "QLogic PCI to SCSI Adapter for ISP 1280/12160:\n"
720 " Firmware version: %2d.%02d.%02d, Driver version %s\n",
721 bdp
->fwver
[0], bdp
->fwver
[1], bdp
->fwver
[2],
726 size
= sprintf(PROC_BUF
, "SCSI Host Adapter Information: %s\n",
729 size
= sprintf(PROC_BUF
, "Request Queue = 0x%p, Response Queue = 0x%p\n",
730 (void *)ha
->request_dma
, (void *)ha
->response_dma
);
732 size
= sprintf(PROC_BUF
, "Request Queue count= 0x%x, Response "
733 "Queue count= 0x%x\n",
734 REQUEST_ENTRY_CNT
, RESPONSE_ENTRY_CNT
);
736 size
= sprintf(PROC_BUF
, "Number of pending commands = 0x%lx\n",
739 size
= sprintf(PROC_BUF
, "Number of queued commands = 0x%lx\n",
742 size
= sprintf(PROC_BUF
, "Number of free request entries = %d\n",
745 size
= sprintf(PROC_BUF
, "\n"); /* 1 */
748 size
= sprintf(PROC_BUF
, "SCSI device Information:\n");
750 /* scan for all equipment stats */
751 for (b
= 0; b
< MAX_BUSES
; b
++)
752 for (t
= 0; t
< MAX_TARGETS
; t
++) {
753 for (l
= 0; l
< MAX_LUNS
; l
++) {
754 up
= LU_Q(ha
, b
, t
, l
);
757 /* unused device/lun */
758 if (up
->io_cnt
== 0 || up
->io_cnt
< 2)
760 /* total reads since boot */
761 /* total writes since boot */
762 /* total requests since boot */
763 size
= sprintf (PROC_BUF
,
764 "(%2d:%2d:%2d): Total reqs %ld,",
765 b
, t
, l
, up
->io_cnt
);
767 /* current number of pending requests */
768 size
= sprintf(PROC_BUF
, " Pend reqs %d,",
772 /* avg response time */
773 size
= sprintf(PROC_BUF
, " Avg resp time %ld%%,",
774 (up
->resp_time
/ up
->io_cnt
) *
778 /* avg active time */
779 size
= sprintf(PROC_BUF
,
780 " Avg active time %ld%%\n",
781 (up
->act_time
/ up
->io_cnt
) * 100);
783 size
= sprintf(PROC_BUF
, "\n");
787 if (len
>= qla1280_buffer_size
)
791 if (len
>= qla1280_buffer_size
) {
793 "qla1280: Overflow buffer in qla1280_proc.c\n");
796 if (offset
> len
- 1) {
797 free_page((unsigned long) qla1280_buffer
);
798 qla1280_buffer
= NULL
;
799 qla1280_buffer_size
= length
= 0;
802 *start
= &qla1280_buffer
[offset
]; /* Start of wanted data */
803 if (len
- offset
< length
) {
804 length
= len
- offset
;
813 /**************************************************************************
814 * qla1280_do_device_init
815 * This routine will register the device with the SCSI subsystem,
816 * initialize the host adapter structure and call the device init
820 * pdev - pointer to struct pci_dev for adapter
821 * template - pointer to SCSI template
822 * devnum - the device number
823 * bdp - pointer to struct _qlaboards
824 * num_hosts - the host number
827 * host - pointer to SCSI host structure
828 **************************************************************************/
830 qla1280_do_device_init(struct pci_dev
*pdev
,
831 Scsi_Host_Template
* template,
832 int devnum
, struct qla_boards
*bdp
, int num_hosts
)
834 struct Scsi_Host
*host
;
835 struct scsi_qla_host
*ha
;
836 struct device_reg
*reg
;
838 printk("qla1x160: Initializing ISP12160 on PCI bus %i, dev %i, irq %i\n",
839 pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
), pdev
->irq
);
841 host
= scsi_register(template, sizeof(struct scsi_qla_host
));
844 "qla1280: Failed to register host, aborting.\n");
848 scsi_set_device(host
, &pdev
->dev
);
849 ha
= (struct scsi_qla_host
*)host
->hostdata
;
850 /* Clear our data area */
851 memset(ha
, 0, sizeof(struct scsi_qla_host
));
852 /* Sanitize the information from PCI BIOS. */
853 host
->irq
= pdev
->irq
;
854 ha
->pci_bus
= pdev
->bus
->number
;
855 ha
->pci_device_fn
= pdev
->devfn
;
857 ha
->device_id
= bdp
->device_id
;
858 ha
->devnum
= devnum
; /* specifies microcode load address */
860 if (qla1280_mem_alloc(ha
)) {
861 printk(KERN_INFO
"qla1x160: Failed to get memory\n");
865 ha
->ports
= bdp
->numPorts
;
866 /* following needed for all cases of OS versions */
868 ha
->host_no
= host
->host_no
;
870 host
->can_queue
= 0xfffff; /* unlimited */
871 host
->cmd_per_lun
= 1;
872 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
873 host
->base
= (unsigned char *)ha
->mmpbase
;
875 host
->base
= (unsigned long)ha
->mmpbase
;
877 host
->max_channel
= bdp
->numPorts
- 1;
878 host
->max_lun
= MAX_LUNS
- 1;
879 host
->max_id
= MAX_TARGETS
;
880 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)
881 host
->max_sectors
= 1024;
884 ha
->instance
= num_hosts
;
885 host
->unique_id
= ha
->instance
;
887 if (qla1280_pci_config(ha
)) {
888 printk(KERN_INFO
"qla1x160: Unable to configure PCI\n");
889 goto error_mem_alloced
;
892 /* Disable ISP interrupts. */
893 qla1280_disable_intrs(ha
);
895 /* Register the IRQ with Linux (sharable) */
896 if (request_irq(host
->irq
, qla1280_intr_handler
, SA_SHIRQ
,
898 printk("qla1280 : Failed to reserve interrupt %d already "
899 "in use\n", host
->irq
);
902 #if !MEMORY_MAPPED_IO
903 /* Register the I/O space with Linux */
904 if (!request_region(host
->io_port
, 0xff, "qla1280")) {
905 printk("qla1280 : Failed to reserve i/o region 0x%04lx-0x%04lx"
907 host
->io_port
, host
->io_port
+ 0xff);
915 /* load the F/W, read paramaters, and init the H/W */
916 if (qla1280_initialize_adapter(ha
)) {
917 printk(KERN_INFO
"qla1x160:Failed to initialize adapter\n");
921 /* set our host ID (need to do something about our two IDs) */
922 host
->this_id
= ha
->bus_settings
[0].id
;
927 #if !MEMORY_MAPPED_IO
928 release_region(host
->io_port
, 0xff);
932 free_irq(host
->irq
, ha
);
937 iounmap((void *)(((unsigned long) ha
->mmpbase
) & PAGE_MASK
));
942 qla1280_mem_free(ha
);
946 scsi_unregister(host
);
951 /**************************************************************************
953 * This routine will probe for Qlogic 1280 SCSI host adapters.
954 * It returns the number of host adapters of a particular
955 * type that were found. It also initialize all data necessary for
956 * the driver. It is passed-in the host number, so that it
957 * knows where its first entry is in the scsi_hosts[] array.
960 * template - pointer to SCSI template
963 * num - number of host adapters found.
964 **************************************************************************/
966 qla1280_detect(Scsi_Host_Template
* template)
968 struct pci_dev
*pdev
= NULL
;
969 struct Scsi_Host
*host
;
970 struct scsi_qla_host
*ha
, *cur_ha
;
971 struct qla_boards
*bdp
;
972 uint16_t subsys_vendor
, subsys_device
;
976 ENTER("qla1280_detect");
978 if (sizeof(srb_t
) > sizeof(Scsi_Pointer
)) {
980 "qla1280_detect: [WARNING] srb_t too big\n");
984 dprintk(1, "DEBUG: qla1280_detect starts at address = %p\n",
987 * If we are called as a module, the qla1280 pointer may not be null
988 * and it would point to our bootup string, just like on the lilo
989 * command line. IF not NULL, then process this config string with
993 * To add options at boot time add a line to your lilo.conf file like:
994 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
995 * which will result in the first four devices on the first two
996 * controllers being set to a tagged queue depth of 32.
999 qla1280_setup(options
, NULL
);
1002 "qla1280: Please read the file /usr/src/linux/Documentation"
1003 "/scsi/qla1280.txt\n"
1004 "qla1280: to see the proper way to specify options to the qla1280 "
1006 "qla1280: Specifically, don't use any commas when passing "
1008 "qla1280: insmod or else it might trash certain memory areas.\n");
1011 bdp
= &ql1280_board_tbl
[0];
1012 qla1280_hostlist
= NULL
;
1013 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
1014 template->proc_dir
= &proc_scsi_qla1280
;
1016 template->proc_name
= "qla1280";
1020 /* First Initialize QLA12160 on PCI Bus 1 Dev 2 */
1021 while ((pdev
= pci_find_subsys(PCI_VENDOR_ID_QLOGIC
, bdp
->device_id
,
1022 PCI_ANY_ID
, PCI_ANY_ID
, pdev
))) {
1024 /* find QLA12160 device on PCI bus=1 slot=2 */
1025 if ((pdev
->bus
->number
!= 1) || (PCI_SLOT(pdev
->devfn
) != 2))
1028 /* Bypass all AMI SUBSYS VENDOR IDs */
1029 if (pdev
->subsystem_vendor
== PCI_VENDOR_ID_AMI
) {
1031 "qla1x160: Skip AMI SubSys Vendor ID Chip\n");
1035 if (pci_enable_device(pdev
))
1038 host
= qla1280_do_device_init(pdev
, template, devnum
,
1042 ha
= (struct scsi_qla_host
*)host
->hostdata
;
1044 /* this preferred device will always be the first one found */
1045 cur_ha
= qla1280_hostlist
= ha
;
1052 /* Try and find each different type of adapter we support */
1053 for (devnum
= 0; bdp
->device_id
!= 0 && devnum
< NUM_OF_ISP_DEVICES
;
1055 /* PCI_SUBSYSTEM_IDS supported */
1056 while ((pdev
= pci_find_subsys(PCI_VENDOR_ID_QLOGIC
,
1057 bdp
->device_id
, PCI_ANY_ID
,
1058 PCI_ANY_ID
, pdev
))) {
1059 if (pci_enable_device(pdev
))
1061 /* found an adapter */
1062 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,18)
1063 subsys_vendor
= pdev
->subsystem_vendor
;
1064 subsys_device
= pdev
->subsystem_device
;
1066 pci_read_config_word(pdev
, PCI_SUBSYSTEM_VENDOR_ID
,
1068 pci_read_config_word(pdev
, PCI_SUBSYSTEM_ID
,
1072 * skip QLA12160 already initialized on
1073 * PCI Bus 1 Dev 2 since we already initialized
1076 if ((bdp
->device_id
== PCI_DEVICE_ID_QLOGIC_ISP12160
)&&
1077 (pdev
->bus
->number
== 1) &&
1078 (PCI_SLOT(pdev
->devfn
) == 2))
1081 /* Bypass all AMI SUBSYS VENDOR IDs */
1082 if (subsys_vendor
== PCI_VENDOR_ID_AMI
) {
1084 "qla1x160: Skip AMI SubSys Vendor ID Chip\n");
1088 "qla1x160: Supported Device Found VID=%x "
1089 "DID=%x SSVID=%x SSDID=%x\n", pdev
->vendor
,
1090 pdev
->device
, subsys_vendor
, subsys_device
);
1092 host
= qla1280_do_device_init(pdev
, template,
1093 devnum
, bdp
, num_hosts
);
1096 ha
= (struct scsi_qla_host
*)host
->hostdata
;
1098 if (qla1280_hostlist
== NULL
) {
1099 cur_ha
= qla1280_hostlist
= ha
;
1101 cur_ha
= qla1280_hostlist
;
1102 while (cur_ha
->next
!= NULL
)
1103 cur_ha
= cur_ha
->next
;
1107 } /* end of WHILE */
1110 LEAVE("qla1280_detect");
1114 /**************************************************************************
1116 * Free the passed in Scsi_Host memory structures prior to unloading the
1118 **************************************************************************/
1120 qla1280_release(struct Scsi_Host
*host
)
1122 struct scsi_qla_host
*ha
= (struct scsi_qla_host
*)host
->hostdata
;
1124 ENTER("qla1280_release");
1126 if (!ha
->flags
.online
)
1129 /* turn-off interrupts on the card */
1130 WRT_REG_WORD(&ha
->iobase
->ictrl
, 0);
1132 /* Detach interrupts */
1134 free_irq(host
->irq
, ha
);
1136 #if MEMORY_MAPPED_IO
1138 iounmap((void *)(((unsigned long) ha
->mmpbase
) & PAGE_MASK
));
1140 /* release io space registers */
1142 release_region(host
->io_port
, 0xff);
1143 #endif /* MEMORY_MAPPED_IO */
1145 qla1280_mem_free(ha
);
1147 ENTER("qla1280_release");
1151 /**************************************************************************
1153 * Return a string describing the driver.
1154 **************************************************************************/
1156 qla1280_info(struct Scsi_Host
*host
)
1158 static char qla1280_scsi_name_buffer
[125];
1160 struct scsi_qla_host
*ha
;
1161 struct qla_boards
*bdp
;
1163 bp
= &qla1280_scsi_name_buffer
[0];
1164 ha
= (struct scsi_qla_host
*)host
->hostdata
;
1165 bdp
= &ql1280_board_tbl
[ha
->devnum
];
1166 memset(bp
, 0, sizeof(qla1280_scsi_name_buffer
));
1168 "QLogic %s PCI to SCSI Host Adapter: bus %d device %d irq %d\n"
1169 " Firmware version: %2d.%02d.%02d, Driver version %s",
1170 &bdp
->bdName
[0], ha
->pci_bus
, (ha
->pci_device_fn
& 0xf8) >> 3,
1171 host
->irq
, bdp
->fwver
[0], bdp
->fwver
[1], bdp
->fwver
[2],
1176 /**************************************************************************
1177 * qla1200_queuecommand
1178 * Queue a command to the controller.
1181 * The mid-level driver tries to ensures that queuecommand never gets invoked
1182 * concurrently with itself or the interrupt handler (although the
1183 * interrupt handler may call this routine as part of request-completion
1184 * handling). Unfortunely, it sometimes calls the scheduler in interrupt
1185 * context which is a big NO! NO!.
1186 **************************************************************************/
1188 qla1280_queuecommand(Scsi_Cmnd
* cmd
, void (*fn
) (Scsi_Cmnd
*))
1190 struct scsi_qla_host
*ha
;
1192 struct Scsi_Host
*host
;
1193 int bus
, target
, lun
;
1196 /*ENTER("qla1280_queuecommand");
1199 host
= cmd
->device
->host
;
1200 ha
= (struct scsi_qla_host
*)host
->hostdata
;
1202 /* send command to adapter */
1203 sp
= (srb_t
*)CMD_SP(cmd
);
1205 cmd
->scsi_done
= fn
;
1206 if (cmd
->flags
== 0) { /* new command */
1210 qla1280_print_scsi_cmd(5, cmd
);
1212 /* Generate LU queue on bus, target, LUN */
1213 bus
= SCSI_BUS_32(cmd
);
1214 target
= SCSI_TCN_32(cmd
);
1215 lun
= SCSI_LUN_32(cmd
);
1216 if ((q
= LU_Q(ha
, bus
, target
, lun
)) == NULL
) {
1217 if ((q
= (scsi_lu_t
*)kmalloc(sizeof(struct scsi_lu
),
1219 LU_Q(ha
, bus
, target
, lun
) = q
;
1220 memset(q
, 0, sizeof(struct scsi_lu
));
1221 dprintk(1, "Allocate new device queue 0x%p\n",
1224 CMD_RESULT(cmd
) = DID_BUS_BUSY
<< 16;
1225 qla1280_done_q_put(sp
, &ha
->done_q_first
,
1228 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) /* 3.22 */
1229 schedule_work(&ha
->run_qla_bh
);
1231 schedule_work(&ha
->run_qla_bh
); /* 3.22 */
1236 /* Set an invalid handle until we issue the command to ISP */
1237 /* then we will set the real handle value. */
1238 CMD_HANDLE(cmd
) = (unsigned char *)INVALID_HANDLE
;
1240 /* add the command to our queue */
1242 qla1280_putq_t(q
, sp
);
1244 dprintk(1, "qla1280_QC: t=%x CDB=%x I/OSize=0x%x haQueueCount=0x%lx\n",
1245 target
, cmd
->cmnd
[0], cmd
->request_bufflen
, ha
->qthreads
);
1247 /* send command to adapter */
1248 if (q
->q_outcnt
== 0)
1249 qla1280_restart_queues(ha
);
1251 /*LEAVE("qla1280_queuecommand"); */
1264 /* timer action for error action processor */
1265 static void qla1280_error_wait_timeout(unsigned long __data
)
1267 struct scsi_cmnd
*cmd
= (struct scsi_cmnd
*)__data
;
1268 srb_t
*sp
= (srb_t
*)CMD_SP(cmd
);
1273 /**************************************************************************
1274 * qla1200_error_action
1275 * The function will attempt to perform a specified error action and
1276 * wait for the results (or time out).
1279 * cmd = Linux SCSI command packet of the command that cause the
1281 * action = error action to take (see action_t)
1287 * Resetting the bus always succeeds - is has to, otherwise the
1288 * kernel will panic! Try a surgical technique - sending a BUS
1289 * DEVICE RESET message - on the offending target before pulling
1290 * the SCSI bus reset line.
1291 **************************************************************************/
1293 qla1280_error_action(Scsi_Cmnd
* cmd
, action_t action
)
1295 struct scsi_qla_host
*ha
;
1296 int bus
, target
, lun
;
1299 unsigned char *handle
;
1302 DECLARE_COMPLETION(wait
);
1303 struct timer_list timer
;
1305 ENTER("qla1280_error_action");
1306 if (qla1280_verbose
)
1307 printk(KERN_INFO
"scsi(): Resetting Cmnd=0x%p, Handle=0x%p, "
1308 "action=0x%x\n", cmd
, CMD_HANDLE(cmd
), action
);
1312 "(scsi?:?:?:?) Reset called with NULL Scsi_Cmnd "
1313 "pointer, failing.\n");
1314 LEAVE("qla1280_error_action");
1318 ha
= (struct scsi_qla_host
*)cmd
->device
->host
->hostdata
;
1319 sp
= (srb_t
*)CMD_SP(cmd
);
1320 handle
= CMD_HANDLE(cmd
);
1323 qla1280_panic("qla1280_reset", ha
->host
);
1326 /* Check for pending interrupts. */
1327 data
= qla1280_debounce_register(&ha
->iobase
->istatus
);
1329 * The io_request_lock is held when the reset handler is called, hence
1330 * the interrupt handler cannot be running in parallel as it also
1331 * grabs the lock. /Jes
1333 if (data
& RISC_INT
)
1334 qla1280_isr(ha
, &ha
->done_q_first
, &ha
->done_q_last
);
1337 * Determine the suggested action that the mid-level driver wants
1340 if (handle
== NULL
) {
1341 if(action
== ABORT_COMMAND
) {
1342 /* we never got this command */
1343 printk(KERN_INFO
"qla1280: Aborting a NULL handle\n");
1344 return SUCCESS
; /* no action - we don't have command */
1350 bus
= SCSI_BUS_32(cmd
);
1351 target
= SCSI_TCN_32(cmd
);
1352 lun
= SCSI_LUN_32(cmd
);
1353 q
= LU_Q(ha
, bus
, target
, lun
);
1355 /* Overloading result. Here it means the success or fail of the
1356 * *issue* of the action. When we return from the routine, it must
1357 * mean the actual success or fail of the action */
1365 /* No lun queue -- command must not be active */
1366 printk(KERN_WARNING
"qla1280 (%d:%d:%d): No LUN queue for the "
1367 "specified device\n", bus
, target
, lun
);
1370 if ((sp
->flags
& SRB_ABORT_PENDING
)) {
1372 "scsi(): Command has a pending abort "
1373 "message - ABORT_PENDING.\n");
1374 /* This should technically be impossible since we
1375 * now wait for abort completion */
1380 * Normally, would would need to search our queue for
1381 * the specified command but; since our sp contains
1382 * the cmd ptr, we can just remove it from our LUN
1385 if (!(sp
->flags
& SRB_SENT
)) {
1386 if (qla1280_verbose
)
1388 "scsi(): Command returned from queue "
1391 /* Remove srb from SCSI LU queue. */
1392 qla1280_removeq(q
, sp
);
1393 sp
->flags
|= SRB_ABORTED
;
1394 CMD_RESULT(cmd
) = DID_ABORT
<< 16;
1395 qla1280_done_q_put(sp
, &ha
->done_q_first
, &ha
->done_q_last
);
1396 if (ha
->done_q_first
)
1397 qla1280_done(ha
, &ha
->done_q_first
, &ha
->done_q_last
);
1399 qla1280_restart_queues(ha
);
1401 } else { /* find the command in our active list */
1404 for (i
= 1; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
1405 if (sp
== ha
->outstanding_cmds
[i
]) {
1407 "qla1280: RISC aborting command.\n");
1408 qla1280_abort_command(ha
, sp
);
1417 ha
->flags
.in_reset
= TRUE
;
1418 if (qla1280_verbose
)
1420 "scsi(%ld:%d:%d:%d): Queueing abort device "
1421 "command.\n", ha
->host_no
, bus
, target
, lun
);
1422 qla1280_abort_queue_single(ha
, bus
, target
, lun
, DID_ABORT
);
1423 if (qla1280_abort_device(ha
, bus
, target
, lun
) == 0)
1428 if (qla1280_verbose
)
1430 "scsi(%ld:%d:%d:%d): Queueing device reset "
1431 "command.\n", ha
->host_no
, bus
, target
, lun
);
1432 ha
->flags
.in_reset
= TRUE
;
1433 for (lun
= 0; lun
< MAX_LUNS
; lun
++)
1434 qla1280_abort_queue_single(ha
, bus
, target
, lun
,
1436 if (qla1280_device_reset(ha
, bus
, target
) == 0)
1438 q
->q_flag
|= QLA1280_QRESET
;
1442 if (qla1280_verbose
)
1443 printk(KERN_INFO
"qla1280(%ld:%d:%d:%d): Issuing BUS "
1444 "DEVICE RESET.\n", ha
->host_no
, bus
, target
,
1446 ha
->flags
.in_reset
= TRUE
;
1447 for (target
= 0; target
< MAX_TARGETS
; target
++)
1448 for (lun
= 0; lun
< MAX_LUNS
; lun
++)
1449 qla1280_abort_queue_single(ha
, bus
, target
,
1451 qla1280_bus_reset(ha
, bus
);
1453 /* wait 4 seconds */
1454 schedule_timeout(4*HZ
);
1462 if (qla1280_verbose
) {
1464 "scsi(%ld:%d:%d:%d): Issued an ADAPTER "
1465 "RESET.\n", ha
->host_no
, bus
, target
, lun
);
1467 "scsi(%ld:%d:%d:%d): I/O processing will "
1468 "continue automatically.\n", ha
->host_no
, bus
,
1471 ha
->flags
.reset_active
= TRUE
;
1473 * We restarted all of the commands automatically, so the
1474 * mid-level code can expect completions momentitarily.
1476 if (qla1280_abort_isp(ha
) == 0)
1479 ha
->flags
.reset_active
= FALSE
;
1482 if (ha
->done_q_first
)
1483 qla1280_done(ha
, &ha
->done_q_first
, &ha
->done_q_last
);
1484 qla1280_restart_queues(ha
);
1485 ha
->flags
.in_reset
= FALSE
;
1487 /* If we didn't manage to issue the action, or we have no
1488 * command to wait for, exit here */
1489 if(result
== FAIL
|| handle
== NULL
)
1492 /* set up a timer just in case we're really jammed */
1494 timer
.expires
= jiffies
+ 4*HZ
;
1495 timer
.data
= (unsigned long)cmd
;
1496 timer
.function
= qla1280_error_wait_timeout
;
1499 /* wait for the action to complete (or the timer to expire) */
1500 spin_unlock_irq(ha
->host
->host_lock
);
1501 wait_for_completion(&wait
);
1502 del_timer_sync(&timer
);
1503 spin_lock_irq(ha
->host
->host_lock
);
1506 /* the only action we might get a fail for is abort */
1507 if(action
== ABORT_COMMAND
) {
1508 if(sp
->flags
& SRB_ABORTED
)
1515 dprintk(1, "RESET returning %d\n", result
);
1517 LEAVE("qla1280_error_action");
1521 /**************************************************************************
1523 * Abort the specified SCSI command(s).
1524 **************************************************************************/
1526 qla1280_eh_abort(struct scsi_cmnd
* cmd
)
1528 return qla1280_error_action(cmd
, ABORT_COMMAND
);
1531 /**************************************************************************
1532 * qla1200_device_reset
1533 * Reset the specified SCSI device
1534 **************************************************************************/
1536 qla1280_eh_device_reset(struct scsi_cmnd
*cmd
)
1538 return qla1280_error_action(cmd
, DEVICE_RESET
);
1541 /**************************************************************************
1543 * Reset the specified bus.
1544 **************************************************************************/
1546 qla1280_eh_bus_reset(struct scsi_cmnd
*cmd
)
1548 return qla1280_error_action(cmd
, BUS_RESET
);
1551 /**************************************************************************
1552 * qla1200_adapter_reset
1553 * Reset the specified adapter (both channels)
1554 **************************************************************************/
1556 qla1280_eh_adapter_reset(struct scsi_cmnd
*cmd
)
1558 return qla1280_error_action(cmd
, ADAPTER_RESET
);
1561 /**************************************************************************
1563 * Return the disk geometry for the given SCSI device.
1564 **************************************************************************/
1566 qla1280_biosparam(struct scsi_device
*sdev
, struct block_device
*bdev
,
1567 sector_t capacity
, int geom
[])
1569 int heads
, sectors
, cylinders
;
1573 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
1574 if (cylinders
> 1024) {
1577 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
1578 /* if (cylinders > 1023)
1579 cylinders = 1023; */
1584 geom
[2] = cylinders
;
1589 /**************************************************************************
1590 * qla1280_intr_handler
1591 * Handles the H/W interrupt
1592 **************************************************************************/
1594 qla1280_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1596 struct scsi_qla_host
*ha
;
1597 struct device_reg
*reg
;
1601 ENTER_INTR ("qla1280_intr_handler");
1602 ha
= (struct scsi_qla_host
*)dev_id
;
1604 spin_lock(ha
->host
->host_lock
);
1609 WRT_REG_WORD(®
->ictrl
, 0); /* disable our interrupt. */
1611 data
= qla1280_debounce_register(®
->istatus
);
1612 /* Check for pending interrupts. */
1613 if (data
& RISC_INT
) {
1614 qla1280_isr(ha
, &ha
->done_q_first
, &ha
->done_q_last
);
1617 /* spurious interrupts can happen legally */
1618 dprintk(1, "scsi(%ld): Spurious interrupt - ignoring\n",
1622 if (ha
->done_q_first
)
1623 qla1280_done(ha
, &ha
->done_q_first
, &ha
->done_q_last
);
1625 spin_unlock(ha
->host
->host_lock
);
1627 /* enable our interrupt. */
1628 WRT_REG_WORD(®
->ictrl
, (ISP_EN_INT
| ISP_EN_RISC
));
1630 LEAVE_INTR("qla1280_intr_handler");
1631 return IRQ_RETVAL(handled
);
1634 /**************************************************************************
1638 * This routine is a task that is schedule by the interrupt handler
1639 * to perform the background processing for interrupts. We put it
1640 * on a task queue that is consumed whenever the scheduler runs; that's
1641 * so you can do anything (i.e. put the process to sleep etc). In fact, the
1642 * mid-level tries to sleep when it reaches the driver threshold
1643 * "host->can_queue". This can cause a panic if we were in our interrupt
1645 **************************************************************************/
1647 qla1280_do_dpc(void *p
)
1649 struct scsi_qla_host
*ha
= (struct scsi_qla_host
*) p
;
1650 unsigned long cpu_flags
;
1652 spin_lock_irqsave(ha
->host
->host_lock
, cpu_flags
);
1654 if (ha
->flags
.isp_abort_needed
)
1655 qla1280_abort_isp(ha
);
1657 if (ha
->flags
.reset_marker
)
1658 qla1280_rst_aen(ha
);
1660 if (ha
->done_q_first
)
1661 qla1280_done(ha
, &ha
->done_q_first
, &ha
->done_q_last
);
1663 spin_unlock_irqrestore(ha
->host
->host_lock
, cpu_flags
);
1666 /**************************************************************************
1667 * qla1280_slave_configure
1670 * Determines the queue depth for a given device. There are two ways
1671 * a queue depth can be obtained for a tagged queueing device. One
1672 * way is the default queue depth which is determined by whether
1673 * If it is defined, then it is used
1674 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1675 * default queue depth (dependent on the number of hardware SCBs).
1676 **************************************************************************/
1678 qla1280_slave_configure(Scsi_Device
* device
)
1680 struct scsi_qla_host
*p
= (struct scsi_qla_host
*)device
->host
->hostdata
;
1681 int bus
= device
->channel
;
1682 int target
= device
->id
;
1684 if (qla1280_check_for_dead_scsi_bus(p
, bus
))
1686 if (device
->tagged_supported
&&
1687 (p
->bus_settings
[bus
].qtag_enables
& (BIT_0
<< target
))) {
1688 scsi_adjust_queue_depth(device
, MSG_ORDERED_TAG
,
1689 p
->bus_settings
[bus
].hiwat
);
1690 /* device->queue_depth = 20; */
1691 printk(KERN_INFO
"scsi(%li:%d:%d:%d): Enabled tagged queuing, "
1692 "queue depth %d.\n", p
->host_no
, device
->channel
,
1693 device
->id
, device
->lun
, device
->queue_depth
);
1695 scsi_adjust_queue_depth(device
, 0 /* TCQ off */, 3);
1697 qla12160_get_target_parameters(p
, bus
, target
, device
->lun
);
1702 * Driver Support Routines
1707 * Process completed commands.
1710 * ha = adapter block pointer.
1711 * done_q_first = done queue first pointer.
1712 * done_q_last = done queue last pointer.
1715 qla1280_done(struct scsi_qla_host
*ha
, srb_t
** done_q_first
,
1716 srb_t
** done_q_last
)
1720 int bus
, target
, lun
;
1723 ENTER("qla1280_done");
1725 while (*done_q_first
!= NULL
) {
1726 /* remove command from done list */
1728 if (!(*done_q_first
= sp
->s_next
))
1729 *done_q_last
= NULL
;
1731 (*done_q_first
)->s_prev
= NULL
;
1734 bus
= SCSI_BUS_32(cmd
);
1735 target
= SCSI_TCN_32(cmd
);
1736 lun
= SCSI_LUN_32(cmd
);
1737 q
= LU_Q(ha
, bus
, target
, lun
);
1739 /* Decrement outstanding commands on device. */
1742 if (q
->q_outcnt
< ha
->bus_settings
[bus
].hiwat
) {
1743 q
->q_flag
&= ~QLA1280_QBUSY
;
1747 if (sp
->dir
& BIT_5
)
1752 switch ((CMD_RESULT(cmd
) >> 16)) {
1754 q
->q_flag
&= ~QLA1280_QRESET
;
1755 /* Issue marker command. */
1756 qla1280_marker(ha
, bus
, target
, 0, MK_SYNC_ID
);
1759 sp
->flags
&= ~SRB_ABORT_PENDING
;
1760 sp
->flags
|= SRB_ABORTED
;
1761 if (sp
->flags
& SRB_TIMEOUT
)
1762 CMD_RESULT(sp
->cmd
) = DID_TIME_OUT
<< 16;
1768 /* 3.13 64 and 32 bit */
1769 /* Release memory used for this I/O */
1771 dprintk(1, "S/G unmap_sg cmd=%p\n", cmd
);
1773 pci_unmap_sg(ha
->pdev
, cmd
->request_buffer
,
1775 scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
1776 } else if (cmd
->request_bufflen
) {
1777 /*dprintk(1, "No S/G unmap_single cmd=%x saved_dma_handle=%lx\n",
1778 cmd, sp->saved_dma_handle); */
1780 pci_unmap_single(ha
->pdev
, sp
->saved_dma_handle
,
1781 cmd
->request_bufflen
,
1782 scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
1785 /* Call the mid-level driver interrupt handler */
1786 CMD_HANDLE(sp
->cmd
) = NULL
;
1789 (*(cmd
)->scsi_done
)(cmd
);
1791 if(sp
->wait
!= NULL
)
1794 qla1280_next(ha
, q
, bus
);
1796 LEAVE("qla1280_done");
1800 * Translates a ISP error to a Linux SCSI error
1803 qla1280_return_status(sts_entry_t
* sts
, Scsi_Cmnd
* cp
)
1805 int host_status
= DID_ERROR
;
1806 #if DEBUG_QLA1280_INTR
1807 static char *reason
[] = {
1819 #endif /* DEBUG_QLA1280_INTR */
1821 ENTER("qla1280_return_status");
1823 #if DEBUG_QLA1280_INTR
1825 dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
1829 switch (sts
->comp_status
) {
1831 host_status
= DID_OK
;
1835 if (!(sts
->state_flags
& SF_GOT_BUS
))
1836 host_status
= DID_NO_CONNECT
;
1837 else if (!(sts
->state_flags
& SF_GOT_TARGET
))
1838 host_status
= DID_BAD_TARGET
;
1839 else if (!(sts
->state_flags
& SF_SENT_CDB
))
1840 host_status
= DID_ERROR
;
1841 else if (!(sts
->state_flags
& SF_TRANSFERRED_DATA
))
1842 host_status
= DID_ERROR
;
1843 else if (!(sts
->state_flags
& SF_GOT_STATUS
))
1844 host_status
= DID_ERROR
;
1845 else if (!(sts
->state_flags
& SF_GOT_SENSE
))
1846 host_status
= DID_ERROR
;
1850 host_status
= DID_RESET
;
1854 host_status
= DID_ABORT
;
1858 host_status
= DID_TIME_OUT
;
1861 case CS_DATA_OVERRUN
:
1862 dprintk(2, "Data overrun 0x%x\n", sts
->residual_length
);
1863 dprintk(2, "qla1280_isr: response packet data\n");
1864 qla1280_dump_buffer(2, (char *)sts
, RESPONSE_ENTRY_SIZE
);
1865 host_status
= DID_ERROR
;
1868 case CS_DATA_UNDERRUN
:
1869 if ((cp
->request_bufflen
- sts
->residual_length
) <
1872 "scsi: Underflow detected - retrying "
1874 host_status
= DID_ERROR
;
1876 host_status
= DID_OK
;
1880 host_status
= DID_ERROR
;
1884 #if DEBUG_QLA1280_INTR
1885 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
1886 reason
[host_status
], sts
->scsi_status
);
1889 LEAVE("qla1280_return_status");
1891 return (sts
->scsi_status
& 0xff) | (host_status
<< 16);
1895 * qla1280_done_q_put
1896 * Place SRB command on done queue.
1900 * done_q_first = done queue first pointer.
1901 * done_q_last = done queue last pointer.
1904 qla1280_done_q_put(srb_t
* sp
, srb_t
** done_q_first
, srb_t
** done_q_last
)
1906 ENTER("qla1280_put_done_q");
1908 /* Place block on done queue */
1910 sp
->s_prev
= *done_q_last
;
1914 (*done_q_last
)->s_next
= sp
;
1917 LEAVE("qla1280_put_done_q");
1922 * Retrieve and process next job in the queue.
1925 * ha = adapter block pointer.
1926 * q = SCSI LU pointer.
1927 * bus = SCSI bus number.
1928 * SCSI_LU_Qlock must be already obtained and no other locks.
1931 * Releases SCSI_LU_Qupon exit.
1934 qla1280_next(struct scsi_qla_host
*ha
, scsi_lu_t
* q
, int bus
)
1939 ENTER("qla1280_next");
1941 while (((sp
= q
->q_first
) != NULL
) && /* we have a queue pending */
1942 /* device not busy/suspended */
1943 !(q
->q_flag
& (QLA1280_QBUSY
| QLA1280_QSUSP
)) && !ha
->flags
.abort_isp_active
) { /* not resetting the adapter */
1944 /* Remove srb from SCSI LU queue. */
1945 qla1280_removeq(q
, sp
);
1947 dprintk(1, "starting request 0x%p<-(0x%p)\n", q
, sp
);
1949 /* Set busy flag if reached high water mark. */
1951 if (q
->q_outcnt
>= ha
->bus_settings
[bus
].hiwat
)
1952 q
->q_flag
|= QLA1280_QBUSY
;
1954 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,18)
1955 if (ha
->flags
.enable_64bit_addressing
)
1956 status
= qla1280_64bit_start_scsi(ha
, sp
);
1959 status
= qla1280_32bit_start_scsi(ha
, sp
);
1961 if (status
) { /* if couldn't start the request */
1962 if (q
->q_outcnt
== 1) {
1963 /* Wait for 30 sec for command to be accepted. */
1964 for (cnt
= 6000000; cnt
; cnt
--) {
1966 if (ha
->flags
.enable_64bit_addressing
)
1968 qla1280_64bit_start_scsi(ha
, sp
);
1972 qla1280_32bit_start_scsi(ha
, sp
);
1977 /* Go check for pending interrupts. */
1983 /* Set timeout status */
1984 CMD_RESULT(sp
->cmd
) =
1988 /* Remove command from watchdog queue. */
1989 if (sp
->flags
& SRB_WATCHDOG
)
1990 qla1280_timeout_remove
1993 CMD_HANDLE(sp
->cmd
) = NULL
;
1995 /* Call the mid-level driver interrupt handler */
1996 (*(sp
->cmd
)->scsi_done
)(sp
->cmd
);
2001 } else { /* Place request back on top of device queue. */
2002 qla1280_putq_t(q
, sp
);
2007 ha
->bus_settings
[bus
].hiwat
)
2008 q
->q_flag
&= ~QLA1280_QBUSY
;
2015 LEAVE("qla1280_next");
2020 * Add the standard SCB job to the top of standard SCB commands.
2023 * q = SCSI LU pointer.
2025 * SCSI_LU_Qlock must be already obtained.
2028 qla1280_putq_t(scsi_lu_t
* q
, srb_t
* sp
)
2030 ENTER("qla1280_putq_t");
2032 dprintk(1, "Adding to device q=0x%p<-(0x%p)sp\n", (void *) q
,
2036 if (!q
->q_first
) { /* If queue empty */
2041 sp
->s_prev
= q
->q_last
;
2042 q
->q_last
->s_next
= sp
;
2046 LEAVE("qla1280_putq_t");
2051 * Function used to remove a command block from the
2055 * q = SCSI LU pointer.
2057 * SCSI_LU_Qlock must be already obtained.
2060 qla1280_removeq(scsi_lu_t
* q
, srb_t
* sp
)
2062 dprintk(1, "Removing from device_q (0x%p)->(0x%p)\n", q
, sp
);
2065 if ((sp
->s_prev
->s_next
= sp
->s_next
) != NULL
)
2066 sp
->s_next
->s_prev
= sp
->s_prev
;
2068 q
->q_last
= sp
->s_prev
;
2069 } else if (!(q
->q_first
= sp
->s_next
))
2072 q
->q_first
->s_prev
= NULL
;
2077 * Allocates adapter memory.
2084 qla1280_mem_alloc(struct scsi_qla_host
*ha
)
2087 dma_addr_t dma_handle
;
2089 ENTER("qla1280_mem_alloc");
2092 /* get consistent memory allocated for request and response rings */
2093 ha
->request_ring
= pci_alloc_consistent(ha
->pdev
,
2094 ((REQUEST_ENTRY_CNT
+ 1) *
2095 (sizeof(request_t
))),
2097 if (!ha
->request_ring
)
2099 ha
->request_dma
= dma_handle
;
2100 ha
->response_ring
= pci_alloc_consistent(ha
->pdev
,
2101 ((RESPONSE_ENTRY_CNT
+ 1) *
2102 (sizeof(response_t
))),
2104 if (!ha
->request_ring
)
2106 ha
->response_dma
= dma_handle
;
2111 dprintk(2, "qla1280_mem_alloc: **** FAILED ****\n");
2113 LEAVE("qla1280_mem_alloc");
2119 * Frees adapter allocated memory.
2122 * ha = adapter block pointer.
2125 qla1280_mem_free(struct scsi_qla_host
*ha
)
2128 int bus
, target
, lun
;
2130 ENTER("qlc1280_mem_free");
2132 /* Free device queues. */
2133 for (bus
= 0; bus
< MAX_BUSES
; bus
++) {
2134 q
= LU_Q(ha
, bus
, ha
->bus_settings
[bus
].id
, 0);
2135 for (target
= 0; target
< MAX_TARGETS
; target
++)
2136 for (lun
= 0; lun
< MAX_LUNS
; lun
++)
2137 if (LU_Q(ha
, bus
, target
, lun
) != NULL
2138 && LU_Q(ha
, bus
, target
, lun
) != q
)
2139 kfree(LU_Q(ha
, bus
, target
, lun
));
2142 for (bus
= 0; bus
< MAX_EQ
; bus
++)
2143 ha
->dev
[bus
] = NULL
;
2147 /* free consistent memory allocated for request and response rings */
2148 if (ha
->request_ring
)
2149 pci_free_consistent(ha
->pdev
,
2150 ((REQUEST_ENTRY_CNT
+ 1) *
2151 (sizeof(request_t
))),
2152 ha
->request_ring
, ha
->request_dma
);
2154 if (ha
->response_ring
)
2155 pci_free_consistent(ha
->pdev
,
2156 ((RESPONSE_ENTRY_CNT
+ 1) *
2157 (sizeof(response_t
))),
2158 ha
->response_ring
, ha
->response_dma
);
2160 if (qla1280_buffer
) {
2161 free_page((unsigned long) qla1280_buffer
);
2162 qla1280_buffer
= NULL
;
2165 LEAVE("qlc1280_mem_free");
2168 /****************************************************************************/
2169 /* QLogic ISP1280 Hardware Support Functions. */
2170 /****************************************************************************/
2173 * qla2100_enable_intrs
2174 * qla2100_disable_intrs
2177 * ha = adapter block pointer.
2183 qla1280_enable_intrs(struct scsi_qla_host
*ha
)
2185 struct device_reg
*reg
;
2188 /* enable risc and host interrupts */
2189 WRT_REG_WORD(®
->ictrl
, (ISP_EN_INT
| ISP_EN_RISC
));
2190 ha
->flags
.ints_enabled
= 1;
2192 printk("Enabling ints\n");
2197 qla1280_disable_intrs(struct scsi_qla_host
*ha
)
2199 struct device_reg
*reg
;
2202 /* disable risc and host interrupts */
2203 WRT_REG_WORD(®
->ictrl
, 0);
2204 ha
->flags
.ints_enabled
= 0;
2206 printk("Disabling ints\n");
2211 * qla1280_initialize_adapter
2215 * ha = adapter block pointer.
2221 qla1280_initialize_adapter(struct scsi_qla_host
*ha
)
2223 struct device_reg
*reg
;
2227 ENTER("qla1280_initialize_adapter");
2229 /* Clear adapter flags. */
2230 ha
->flags
.online
= FALSE
;
2231 ha
->flags
.isp_abort_needed
= FALSE
;
2232 ha
->flags
.disable_host_adapter
= FALSE
;
2233 ha
->flags
.reset_active
= FALSE
;
2234 ha
->flags
.abort_isp_active
= FALSE
;
2236 ha
->flags
.ints_enabled
= FALSE
;
2238 dprintk(1, "Configure PCI space for adapter...\n");
2242 /* Insure mailbox registers are free. */
2243 WRT_REG_WORD(®
->semaphore
, 0);
2244 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
2245 WRT_REG_WORD(®
->host_cmd
, HC_CLR_HOST_INT
);
2247 /* If firmware needs to be loaded */
2248 if (qla1280_verbose
)
2249 printk(KERN_INFO
"scsi(%li): Determining if RISC is "
2250 "loaded...\n", ha
->host_no
);
2251 if (qla1280_isp_firmware(ha
)) {
2252 if (qla1280_verbose
)
2253 printk(KERN_INFO
"scsi(%ld): Verifying chip...\n",
2255 if (!(status
= qla1280_chip_diag (ha
))) {
2256 if (qla1280_verbose
)
2257 printk(KERN_INFO
"scsi(%ld): Setup chip...\n",
2259 status
= qla1280_setup_chip(ha
);
2262 printk(KERN_ERR
"initialize: isp_firmware() failed!\n");
2267 /* Setup adapter based on NVRAM parameters. */
2268 if (qla1280_verbose
)
2270 "scsi(%ld): Configure NVRAM parameters...\n",
2272 qla1280_nvram_config(ha
);
2274 if (!ha
->flags
.disable_host_adapter
2275 && !qla1280_init_rings(ha
)) {
2276 /* Issue SCSI reset. */
2277 /* dg 03/13 if we can't reset twice then bus is dead */
2278 for (bus
= 0; bus
< ha
->ports
; bus
++) {
2279 if (!ha
->bus_settings
[bus
].disable_scsi_reset
){
2280 if (qla1280_bus_reset(ha
, bus
)) {
2281 if (qla1280_bus_reset(ha
, bus
)) {
2282 ha
->bus_settings
[bus
].scsi_bus_dead
= TRUE
;
2288 /* Issue marker command. */
2289 ha
->flags
.reset_marker
= FALSE
;
2290 for (bus
= 0; bus
< ha
->ports
; bus
++) {
2291 ha
->bus_settings
[bus
].reset_marker
= FALSE
;
2292 qla1280_marker(ha
, bus
, 0, 0,
2295 } while (ha
->flags
.reset_marker
);
2297 ha
->flags
.online
= TRUE
;
2299 /* Enable host adapter target mode. */
2300 for (bus
= 0; bus
< ha
->ports
; bus
++) {
2301 if (!(status
= qla1280_enable_tgt(ha
, bus
))) {
2304 for (cnt
= 0; cnt
< MAX_LUNS
; cnt
++) {
2305 qla1280_enable_lun(ha
, bus
,
2316 printk(KERN_ERR
"scsi(%li): initialize: pci probe failed!\n",
2320 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
2322 LEAVE("qla1280_initialize_adapter");
2327 * qla1280_enable_tgt
2328 * Enable target mode.
2331 * ha = adapter block pointer.
2332 * bus = SCSI bus number.
2338 qla1280_enable_tgt(struct scsi_qla_host
*ha
, int bus
)
2341 /* uint16_t mb[MAILBOX_REGISTER_COUNT]; */
2343 dprintk(3, "qla1280_enable_tgt: entered\n");
2345 /* Enable target mode. */
2347 mb
[0] = MBC_ENABLE_TARGET_MODE
;
2349 mb
[2] = (uint16_t) (bus
<< 15);
2350 status
= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
2353 dprintk(2, "qla1280_enable_tgt: **** FAILED ****\n");
2355 dprintk(3, "qla1280_enable_tgt: exiting normally\n");
2362 * Checks if present version of RISC firmware is older than
2366 * ha = adapter block pointer.
2369 * 0 = firmware does not need to be loaded.
2372 qla1280_isp_firmware(struct scsi_qla_host
*ha
)
2374 nvram_t
*nv
= (nvram_t
*) ha
->response_ring
;
2376 int status
= 0; /* dg 2/27 always loads RISC */
2379 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2381 ENTER("qla1280_isp_firmware");
2383 /* Verify valid NVRAM checksum. */
2384 wptr
= (uint16_t *) ha
->response_ring
;
2385 dprintk(1, "qla1280_isp_firmware: Reading NVRAM\n");
2388 for (cnt
= 0; cnt
< sizeof(nvram_t
) / 2; cnt
++) {
2389 *wptr
= qla1280_get_nvram_word (ha
, cnt
);
2390 chksum
+= (uint8_t) * wptr
;
2391 chksum
+= (uint8_t) (*wptr
>> 8);
2394 dprintk(1, "qla1280_isp_firmware: Completed Reading NVRAM\n");
2396 dprintk(3, "qla1280_isp_firmware: NVRAM Magic ID= %c %c %c\n",
2397 nv
->id0
, nv
->id1
, nv
->id2
);
2399 /* Bad NVRAM data, load RISC code. */
2400 if (chksum
|| nv
->id0
!= 'I' || nv
->id1
!= 'S' ||
2401 nv
->id2
!= 'P' || nv
->id3
!= ' ' || nv
->version
< 1) {
2402 printk(KERN_INFO
"qla1280_isp_firmware: Bad checksum or magic "
2403 "number or version in NVRAM.\n");
2404 ha
->flags
.disable_risc_code_load
= FALSE
;
2406 ha
->flags
.disable_risc_code_load
=
2407 nv
->cntr_flags_1
.disable_loading_risc_code
;
2409 if (ha
->flags
.disable_risc_code_load
) {
2411 "qla1280_isp_firmware: Telling RISC to verify checksum "
2412 "of loaded BIOS code.\n");
2414 /* Verify checksum of loaded RISC code. */
2415 mb
[0] = MBC_VERIFY_CHECKSUM
;
2416 /* mb[1] = ql12_risc_code_addr01; */
2417 mb
[1] = *ql1280_board_tbl
[ha
->devnum
].fwstart
;
2421 qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]))) {
2422 /* Start firmware execution. */
2423 dprintk(3, "qla1280_isp_firmware: Startng F/W "
2426 mb
[0] = MBC_EXECUTE_FIRMWARE
;
2427 /* mb[1] = ql12_risc_code_addr01; */
2428 mb
[1] = *ql1280_board_tbl
[ha
->devnum
].fwstart
;
2429 qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]);
2431 printk(KERN_INFO
"qla1280: RISC checksum failed.\n");
2433 dprintk(1, "qla1280: NVRAM configured to load RISC load.\n");
2438 dprintk(2, "qla1280_isp_firmware: **** Load RISC code ****\n");
2440 LEAVE("qla1280_isp_firmware");
2446 * Setup device PCI configuration registers.
2449 * ha = adapter block pointer.
2455 qla1280_pci_config(struct scsi_qla_host
*ha
)
2457 #if MEMORY_MAPPED_IO
2458 uint32_t page_offset
, base
;
2464 ENTER("qla1280_pci_config");
2466 pci_set_master(ha
->pdev
);
2468 * Set Bus Master Enable, Memory Address Space Enable and
2469 * reset any error bits, in the command register.
2471 pci_read_config_word (ha
->pdev
, PCI_COMMAND
, &buf_wd
);
2472 #if MEMORY_MAPPED_IO
2473 dprintk(1, "qla1280: MEMORY MAPPED IO is enabled.\n");
2474 buf_wd
|= PCI_COMMAND_MEMORY
+ PCI_COMMAND_IO
;
2476 buf_wd
|= PCI_COMMAND_IO
;
2478 pci_write_config_word (ha
->pdev
, PCI_COMMAND
, buf_wd
);
2480 * Reset expansion ROM address decode enable.
2482 pci_read_config_word (ha
->pdev
, PCI_ROM_ADDRESS
, &buf_wd
);
2483 buf_wd
&= ~PCI_ROM_ADDRESS_ENABLE
;
2484 pci_write_config_word (ha
->pdev
, PCI_ROM_ADDRESS
, buf_wd
);
2486 ha
->host
->io_port
= pci_resource_start(ha
->pdev
, 0);
2487 ha
->host
->io_port
&= PCI_BASE_ADDRESS_IO_MASK
;
2488 ha
->iobase
= (struct device_reg
*) ha
->host
->io_port
;
2490 #if MEMORY_MAPPED_IO
2492 * Get memory mapped I/O address.
2494 pci_read_config_word (ha
->pdev
, PCI_BASE_ADDRESS_1
, &mmapbase
);
2495 mmapbase
&= PCI_BASE_ADDRESS_MEM_MASK
;
2498 * Find proper memory chunk for memory map I/O reg.
2500 base
= mmapbase
& PAGE_MASK
;
2501 page_offset
= mmapbase
- base
;
2503 * Get virtual address for I/O registers.
2505 ha
->mmpbase
= ioremap(base
, page_offset
+ 256);
2507 ha
->mmpbase
+= page_offset
;
2508 /* ha->iobase = ha->mmpbase; */
2511 #else /* MEMORY_MAPPED_IO */
2513 #endif /* MEMORY_MAPPED_IO */
2515 LEAVE("qla1280_pci_config");
2521 * Test chip for proper operation.
2524 * ha = adapter block pointer.
2530 qla1280_chip_diag(struct scsi_qla_host
*ha
)
2532 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2533 struct device_reg
*reg
= ha
->iobase
;
2538 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®
->id_l
);
2540 /* Soft reset chip and wait for it to finish. */
2541 WRT_REG_WORD(®
->ictrl
, ISP_RESET
);
2542 data
= qla1280_debounce_register(®
->ictrl
);
2546 for (cnt
= 6000000; cnt
&& data
& ISP_RESET
; cnt
--) {
2548 data
= RD_REG_WORD(®
->ictrl
);
2551 /* Reset register not cleared by chip reset. */
2553 "qla1280_chip_diag: reset register cleared by chip reset\n");
2555 WRT_REG_WORD(®
->cfg_1
, 0);
2557 /* Reset RISC and disable BIOS which
2558 allows RISC to execute out of RAM. */
2559 WRT_REG_WORD(®
->host_cmd
, HC_RESET_RISC
);
2560 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
2561 WRT_REG_WORD(®
->host_cmd
, HC_DISABLE_BIOS
);
2562 data
= qla1280_debounce_register(®
->mailbox0
);
2564 * I *LOVE* this code!
2566 for (cnt
= 6000000; cnt
&& data
== MBS_BUSY
; cnt
--) {
2568 data
= RD_REG_WORD(®
->mailbox0
);
2572 /* Check product ID of chip */
2574 "qla1280_chip_diag: Checking product ID of chip\n");
2576 if (RD_REG_WORD(®
->mailbox1
) != PROD_ID_1
||
2577 (RD_REG_WORD(®
->mailbox2
) != PROD_ID_2
&&
2578 RD_REG_WORD(®
->mailbox2
) != PROD_ID_2a
) ||
2579 RD_REG_WORD(®
->mailbox3
) != PROD_ID_3
||
2580 RD_REG_WORD(®
->mailbox4
) != PROD_ID_4
) {
2582 "qla1280: Wrong product ID = 0x%x,0x%x,0x%x,"
2583 "0x%x\n", RD_REG_WORD(®
->mailbox1
),
2584 RD_REG_WORD(®
->mailbox2
),
2585 RD_REG_WORD(®
->mailbox3
),
2586 RD_REG_WORD(®
->mailbox4
));
2590 * Enable ints early!!!
2592 qla1280_enable_intrs(ha
);
2594 "qla1280_chip_diag: Checking mailboxes of chip\n");
2595 /* Wrap Incoming Mailboxes Test. */
2596 mb
[0] = MBC_MAILBOX_REGISTER_TEST
;
2604 if (!(status
= qla1280_mailbox_command(ha
,
2615 if (mb
[1] != 0xAAAA ||
2625 "qla1280: Failed mailbox check\n");
2634 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
2636 dprintk(3, "qla1280_chip_diag: exiting normally\n");
2643 * Load and start RISC firmware.
2646 * ha = adapter block pointer.
2651 #define DUMP_IT_BACK 1 /* for debug of RISC loading */
2653 qla1280_setup_chip(struct scsi_qla_host
*ha
)
2656 uint16_t risc_address
;
2657 uint16_t *risc_code_address
;
2659 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2669 ENTER("qla1280_setup_chip");
2673 /* get consistent memory allocated for setup_chip */
2674 tbuf
= pci_alloc_consistent(ha
->pdev
, 8000, &p_tbuf
);
2677 /* Load RISC code. */
2678 risc_address
= *ql1280_board_tbl
[ha
->devnum
].fwstart
;
2679 risc_code_address
= ql1280_board_tbl
[ha
->devnum
].fwcode
;
2680 risc_code_size
= (int) *ql1280_board_tbl
[ha
->devnum
].fwlen
;
2682 dprintk(1, "qla1280_setup_chip: DMA RISC code (%i) words\n",
2686 while (risc_code_size
> 0 && !status
) {
2687 int warn
__attribute__((unused
)) = 0;
2691 if (cnt
> risc_code_size
)
2692 cnt
= risc_code_size
;
2694 dprintk(1, "qla1280_setup_chip: loading risc @ =(0x%p),"
2696 risc_code_address
, cnt
, num
, risc_address
);
2697 for(i
= 0; i
< cnt
; i
++)
2698 ((uint16_t *)ha
->request_ring
)[i
] =
2699 cpu_to_le16(risc_code_address
[i
]);
2703 mb
[0] = MBC_LOAD_RAM
;
2704 mb
[1] = risc_address
;
2706 mb
[3] = qla1280_addr0_15(ha
->request_dma
);
2707 mb
[2] = qla1280_addr16_31(ha
->request_dma
);
2708 mb
[7] = qla1280_addr32_47(ha
->request_dma
);
2709 mb
[6] = qla1280_addr48_63(ha
->request_dma
);
2710 dprintk(1, "qla1280_setup_chip: op=%d 0x%p = 0x%4x,0x%4x,"
2712 mb
[0], (void *)ha
->request_dma
, mb
[6], mb
[7], mb
[2], mb
[3]);
2713 if ((status
= qla1280_mailbox_command(ha
, BIT_4
| BIT_3
|
2714 BIT_2
| BIT_1
| BIT_0
,
2717 "Failed to load partial segment of f/w\n");
2722 mb
[0] = MBC_DUMP_RAM
;
2723 mb
[1] = risc_address
;
2725 mb
[3] = qla1280_addr0_15(p_tbuf
);
2726 mb
[2] = qla1280_addr16_31(p_tbuf
);
2727 mb
[7] = qla1280_addr32_47(p_tbuf
);
2728 mb
[6] = qla1280_addr48_63(p_tbuf
);
2730 if ((status
= qla1280_mailbox_command(ha
,
2731 BIT_4
| BIT_3
| BIT_2
|
2735 "Failed to dump partial segment of f/w\n");
2738 sp
= (uint8_t *)ha
->request_ring
;
2739 for (i
= 0; i
< (cnt
<< 1); i
++) {
2740 if (tbuf
[i
] != sp
[i
] &&warn
++ < 10) {
2741 printk(KERN_ERR
"qla1280_setup_chip: FW "
2742 "compare error @ byte(0x%x) loop#=%x\n",
2744 printk(KERN_ERR
"setup_chip: FWbyte=%x "
2745 "FWfromChip=%x\n", sp
[i
], tbuf
[i
]);
2750 risc_address
+= cnt
;
2751 risc_code_size
= risc_code_size
- cnt
;
2752 risc_code_address
= risc_code_address
+ cnt
;
2756 /* Verify checksum of loaded RISC code. */
2758 dprintk(1, "qla1280_setup_chip: Verifying checksum of "
2759 "loaded RISC code.\n");
2760 mb
[0] = MBC_VERIFY_CHECKSUM
;
2761 /* mb[1] = ql12_risc_code_addr01; */
2762 mb
[1] = *ql1280_board_tbl
[ha
->devnum
].fwstart
;
2765 qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]))) {
2766 /* Start firmware execution. */
2768 "qla1280_setup_chip: start firmware running.\n");
2769 mb
[0] = MBC_EXECUTE_FIRMWARE
;
2770 mb
[1] = *ql1280_board_tbl
[ha
->devnum
].fwstart
;
2771 qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]);
2774 "qla1280_setup_chip: Failed checksum.\n");
2779 /* free consistent memory allocated for setup_chip */
2780 pci_free_consistent(ha
->pdev
, 8000, tbuf
, p_tbuf
);
2784 dprintk(2, "qla1280_setup_chip: **** FAILED ****\n");
2786 LEAVE("qla1280_setup_chip");
2794 * ha = adapter block pointer.
2795 * ha->request_ring = request ring virtual address
2796 * ha->response_ring = response ring virtual address
2797 * ha->request_dma = request ring physical address
2798 * ha->response_dma = response ring physical address
2804 qla1280_init_rings(struct scsi_qla_host
*ha
)
2806 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2810 ENTER("qla1280_init_rings");
2812 /* Clear outstanding commands array. */
2813 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
2814 ha
->outstanding_cmds
[cnt
] = 0;
2816 /* Initialize request queue. */
2817 ha
->request_ring_ptr
= ha
->request_ring
;
2818 ha
->req_ring_index
= 0;
2819 ha
->req_q_cnt
= REQUEST_ENTRY_CNT
;
2820 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
2821 mb
[0] = MBC_INIT_REQUEST_QUEUE_A64
;
2822 mb
[1] = REQUEST_ENTRY_CNT
;
2823 mb
[3] = ha
->request_dma
& 0xffff;
2824 mb
[2] = (ha
->request_dma
>> 16) & 0xffff;
2826 mb
[7] = pci_dma_hi32(ha
->request_dma
) & 0xffff;
2827 mb
[6] = pci_dma_hi32(ha
->request_dma
) >> 16;
2828 if (!(status
= qla1280_mailbox_command(ha
, BIT_7
| BIT_6
| BIT_4
|
2829 BIT_3
| BIT_2
| BIT_1
| BIT_0
,
2831 /* Initialize response queue. */
2832 ha
->response_ring_ptr
= ha
->response_ring
;
2833 ha
->rsp_ring_index
= 0;
2834 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
2835 mb
[0] = MBC_INIT_RESPONSE_QUEUE_A64
;
2836 mb
[1] = RESPONSE_ENTRY_CNT
;
2837 mb
[3] = ha
->response_dma
& 0xffff;
2838 mb
[2] = (ha
->response_dma
>> 16) & 0xffff;
2840 mb
[7] = pci_dma_hi32(ha
->response_dma
) & 0xffff;
2841 mb
[6] = pci_dma_hi32(ha
->response_dma
) >> 16;
2842 status
= qla1280_mailbox_command(ha
, BIT_7
| BIT_6
| BIT_5
|
2843 BIT_3
| BIT_2
| BIT_1
| BIT_0
,
2848 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
2850 LEAVE("qla1280_init_rings");
2855 * NVRAM configuration.
2858 * ha = adapter block pointer.
2859 * ha->request_ring = request ring virtual address
2862 * host adapters parameters in host adapter block
2868 qla1280_nvram_config(struct scsi_qla_host
*ha
)
2870 struct device_reg
*reg
= ha
->iobase
;
2871 nvram_t
*nv
= (nvram_t
*)ha
->response_ring
;
2874 int bus
, target
, lun
;
2876 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2880 #if DEBUG_PRINT_NVRAM
2881 int saved_print_status
= ql_debug_print
;
2883 ENTER("qla1280_nvram_config");
2885 /* Verify valid NVRAM checksum. */
2886 #if USE_NVRAM_DEFAULTS
2889 wptr
= (uint16_t *) ha
->response_ring
;
2891 if (ha
->device_id
== PCI_DEVICE_ID_QLOGIC_ISP12160
||
2892 ha
->device_id
== PCI_DEVICE_ID_QLOGIC_ISP10160
)
2893 nvsize
= sizeof(nvram160_t
) / 2;
2895 nvsize
= sizeof(nvram_t
) / 2;
2896 for (cnt
= 0; cnt
< nvsize
; cnt
++) {
2897 *wptr
= qla1280_get_nvram_word(ha
, cnt
);
2898 chksum
+= (uint8_t) * wptr
;
2899 chksum
+= (uint8_t) (*wptr
>> 8);
2904 /* Bad NVRAM data, set defaults parameters. */
2905 if (chksum
|| nv
->id0
!= 'I' || nv
->id1
!= 'S' ||
2906 nv
->id2
!= 'P' || nv
->id3
!= ' ' || nv
->version
< 1) {
2907 #if USE_NVRAM_DEFAULTS
2908 dprintk(1, "Using defaults for NVRAM\n");
2910 dprintk(1, "Using defaults for NVRAM: \n");
2911 dprintk(1, "checksum=0x%x, Id=%c, version=0x%x\n",
2912 chksum
, nv
->id
[0], nv
->version
);
2913 memset(ha
->response_ring
, 0, sizeof(nvram_t
));
2916 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
2917 nv
->firmware_feature
.w
= BIT_0
;
2918 nv
->termination
.f
.scsi_bus_0_control
= 3;
2919 nv
->termination
.f
.scsi_bus_1_control
= 3;
2920 nv
->termination
.f
.auto_term_support
= 1;
2922 for (bus
= 0; bus
< MAX_BUSES
; bus
++) {
2923 nv
->bus
[bus
].config_1
.initiator_id
= 7;
2924 nv
->bus
[bus
].bus_reset_delay
= 5;
2925 nv
->bus
[bus
].config_2
.async_data_setup_time
= 9;
2926 nv
->bus
[bus
].config_2
.req_ack_active_negation
= 1;
2927 nv
->bus
[bus
].config_2
.data_line_active_negation
= 1;
2928 nv
->bus
[bus
].selection_timeout
= 250;
2929 nv
->bus
[bus
].max_queue_depth
= 256;
2931 for (target
= 0; target
< MAX_TARGETS
; target
++) {
2932 nv
->bus
[bus
].target
[target
].parameter
.f
.
2933 auto_request_sense
= 1;
2934 nv
->bus
[bus
].target
[target
].parameter
.f
.
2935 disconnect_allowed
= 1;
2936 nv
->bus
[bus
].target
[target
].parameter
.f
.
2938 nv
->bus
[bus
].target
[target
].flags
.
2943 #if USE_NVRAM_DEFAULTS
2949 /* Always force AUTO sense for LINUX SCSI */
2950 for (bus
= 0; bus
< MAX_BUSES
; bus
++)
2951 for (target
= 0; target
< MAX_TARGETS
; target
++) {
2952 nv
->bus
[bus
].target
[target
].parameter
.f
.
2953 auto_request_sense
= 1;
2956 #if DEBUG_PRINT_NVRAM
2959 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
2960 nv
->bus
[0].config_1
.initiator_id
);
2961 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
2962 nv
->bus
[1].config_1
.initiator_id
);
2964 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
2965 nv
->bus
[0].bus_reset_delay
);
2966 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
2967 nv
->bus
[1].bus_reset_delay
);
2969 dprintk(1, "qla1280 : retry count[0]=%d\n", nv
->bus
[0].retry_count
);
2970 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv
->bus
[0].retry_delay
);
2971 dprintk(1, "qla1280 : retry count[1]=%d\n", nv
->bus
[1].retry_count
);
2972 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv
->bus
[1].retry_delay
);
2974 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
2975 nv
->bus
[0].config_2
.async_data_setup_time
);
2976 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
2977 nv
->bus
[1].config_2
.async_data_setup_time
);
2979 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
2980 nv
->bus
[0].config_2
.req_ack_active_negation
);
2981 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
2982 nv
->bus
[1].config_2
.req_ack_active_negation
);
2984 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
2985 nv
->bus
[0].config_2
.data_line_active_negation
);
2986 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
2987 nv
->bus
[1].config_2
.data_line_active_negation
);
2989 dprintk(1, "qla1280 : disable loading risc code=%d\n",
2990 nv
->cntr_flags_1
.disable_loading_risc_code
);
2992 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
2993 nv
->cntr_flags_1
.enable_64bit_addressing
);
2995 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
2996 nv
->bus
[0].selection_timeout
);
2997 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
2998 nv
->bus
[1].selection_timeout
);
3000 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
3001 nv
->bus
[0].max_queue_depth
);
3002 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
3003 nv
->bus
[1].max_queue_depth
);
3005 /* Disable RISC load of firmware. */
3006 ha
->flags
.disable_risc_code_load
=
3007 nv
->cntr_flags_1
.disable_loading_risc_code
;
3009 #ifdef QLA_64BIT_PTR
3010 /* Enable 64bit addressing for OS/System combination supporting it */
3011 /* actual NVRAM bit is: nv->cntr_flags_1.enable_64bit_addressing */
3012 /* but we will ignore it and use BITS_PER_LONG macro to setup for */
3013 /* 64 or 32 bit access of host memory in all x86/ia-64/Alpha systems */
3014 ha
->flags
.enable_64bit_addressing
= 1;
3016 ha
->flags
.enable_64bit_addressing
= 0;
3019 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,18)
3020 if (ha
->flags
.enable_64bit_addressing
) {
3021 printk(KERN_INFO
"scsi(%li): 64 Bit PCI Addressing Enabled\n",
3024 pci_set_dma_mask(ha
->pdev
, (dma_addr_t
) ~ 0ULL);
3028 /* Set ISP hardware DMA burst */
3029 mb
[0] = nv
->isp_config
.c
;
3030 WRT_REG_WORD(®
->cfg_1
, mb
[0]);
3032 /* Set SCSI termination. */
3033 WRT_REG_WORD(®
->gpio_enable
, (BIT_3
+ BIT_2
+ BIT_1
+ BIT_0
));
3034 mb
[0] = nv
->termination
.c
& (BIT_3
+ BIT_2
+ BIT_1
+ BIT_0
);
3035 WRT_REG_WORD(®
->gpio_data
, mb
[0]);
3037 /* ISP parameter word. */
3038 mb
[0] = MBC_SET_SYSTEM_PARAMETER
;
3039 mb
[1] = nv
->isp_parameter
;
3040 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]);
3042 /* Firmware feature word. */
3043 mb
[0] = MBC_SET_FIRMWARE_FEATURES
;
3044 mb
[1] = nv
->firmware_feature
.w
& (BIT_1
| BIT_0
);
3045 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]);
3047 /* Retry count and delay. */
3048 mb
[0] = MBC_SET_RETRY_COUNT
;
3049 mb
[1] = nv
->bus
[0].retry_count
;
3050 mb
[2] = nv
->bus
[0].retry_delay
;
3051 mb
[6] = nv
->bus
[1].retry_count
;
3052 mb
[7] = nv
->bus
[1].retry_delay
;
3054 qla1280_mailbox_command(ha
, BIT_7
| BIT_6
| BIT_2
| BIT_1
| BIT_0
,
3057 /* ASYNC data setup time. */
3058 mb
[0] = MBC_SET_ASYNC_DATA_SETUP
;
3059 mb
[1] = nv
->bus
[0].config_2
.async_data_setup_time
;
3060 mb
[2] = nv
->bus
[1].config_2
.async_data_setup_time
;
3061 status
|= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
3063 /* Active negation states. */
3064 mb
[0] = MBC_SET_ACTIVE_NEGATION
;
3066 if (nv
->bus
[0].config_2
.req_ack_active_negation
)
3068 if (nv
->bus
[0].config_2
.data_line_active_negation
)
3071 if (nv
->bus
[1].config_2
.req_ack_active_negation
)
3073 if (nv
->bus
[1].config_2
.data_line_active_negation
)
3075 status
|= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
3077 /* Selection timeout. */
3078 mb
[0] = MBC_SET_SELECTION_TIMEOUT
;
3079 mb
[1] = nv
->bus
[0].selection_timeout
;
3080 mb
[2] = nv
->bus
[1].selection_timeout
;
3081 status
|= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
3083 for (bus
= 0; bus
< ha
->ports
; bus
++) {
3084 /* SCSI Reset Disable. */
3085 ha
->bus_settings
[bus
].disable_scsi_reset
=
3086 nv
->bus
[bus
].config_1
.scsi_reset_disable
;
3089 ha
->bus_settings
[bus
].id
= nv
->bus
[bus
].config_1
.initiator_id
;
3090 mb
[0] = MBC_SET_INITIATOR_ID
;
3091 mb
[1] = bus
? ha
->bus_settings
[bus
].id
| BIT_7
:
3092 ha
->bus_settings
[bus
].id
;
3093 status
|= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]);
3096 ha
->bus_settings
[bus
].bus_reset_delay
=
3097 nv
->bus
[bus
].bus_reset_delay
;
3099 /* Command queue depth per device. */
3100 ha
->bus_settings
[bus
].hiwat
= nv
->bus
[bus
].max_queue_depth
- 1;
3102 /* Set target parameters. */
3103 for (target
= 0; target
< MAX_TARGETS
; target
++) {
3104 uint8_t mr
= BIT_3
| BIT_2
| BIT_1
| BIT_0
;
3106 /* Set Target Parameters. */
3107 mb
[0] = MBC_SET_TARGET_PARAMETERS
;
3108 mb
[1] = (uint16_t) (bus
? target
| BIT_7
: target
);
3111 mb
[2] = nv
->bus
[bus
].target
[target
].parameter
.c
<< 8;
3112 mb
[2] |= TP_AUTO_REQUEST_SENSE
;
3113 mb
[2] &= ~TP_STOP_QUEUE
;
3116 nv
->bus
[bus
].target
[target
].flags
.sync_offset
<< 8;
3117 mb
[3] |= nv
->bus
[bus
].target
[target
].sync_period
;
3119 if (ha
->device_id
== PCI_DEVICE_ID_QLOGIC_ISP12160
||
3120 ha
->device_id
== PCI_DEVICE_ID_QLOGIC_ISP10160
) {
3121 nvram160_t
*nv2
= (nvram160_t
*) nv
;
3123 nv2
->bus
[bus
].target
[target
].flags2
.
3127 nv2
->bus
[bus
].target
[target
].flags2
.
3130 nv2
->bus
[bus
].target
[target
].flags2
.
3134 status
= qla1280_mailbox_command(ha
, mr
, &mb
[0]);
3136 /* Save Tag queuing enable flag. */
3137 mb
[0] = BIT_0
<< target
;
3138 if (nv
->bus
[bus
].target
[target
].parameter
.f
.tag_queuing
)
3139 ha
->bus_settings
[bus
].qtag_enables
|= mb
[0];
3141 /* Save Device enable flag. */
3142 if (nv
->bus
[bus
].target
[target
].flags
.device_enable
)
3143 ha
->bus_settings
[bus
].device_enables
|= mb
[0];
3145 /* Save LUN disable flag. */
3146 if (nv
->bus
[bus
].target
[target
].flags
.lun_disable
)
3147 ha
->bus_settings
[bus
].lun_disables
|= mb
[0];
3149 /* Set Device Queue Parameters. */
3150 for (lun
= 0; lun
< MAX_LUNS
; lun
++) {
3151 mb
[0] = MBC_SET_DEVICE_QUEUE
;
3152 mb
[1] = (uint16_t)(bus
? target
| BIT_7
: target
);
3153 mb
[1] = mb
[1] << 8 | lun
;
3154 mb
[2] = nv
->bus
[bus
].max_queue_depth
;
3155 mb
[3] = nv
->bus
[bus
].target
[target
].execution_throttle
;
3157 qla1280_mailbox_command(ha
,
3165 #if DEBUG_PRINT_NVRAM
3166 ql_debug_print
= saved_print_status
;
3170 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
3172 LEAVE("qla1280_nvram_config");
3177 * Get NVRAM data word
3178 * Calculates word position in NVRAM and calls request routine to
3179 * get the word from NVRAM.
3182 * ha = adapter block pointer.
3183 * address = NVRAM word address.
3189 qla1280_get_nvram_word(struct scsi_qla_host
*ha
, uint32_t address
)
3194 #ifdef QL_DEBUG_ROUTINES
3195 int saved_print_status
= ql_debug_print
;
3198 nv_cmd
= address
<< 16;
3199 nv_cmd
|= NV_READ_OP
;
3201 #ifdef QL_DEBUG_ROUTINES
3202 ql_debug_print
= FALSE
;
3204 data
= qla1280_nvram_request(ha
, nv_cmd
);
3205 #ifdef QL_DEBUG_ROUTINES
3206 ql_debug_print
= saved_print_status
;
3210 "qla1280_get_nvram_word: exiting normally NVRAM data = 0x%x",
3218 * Sends read command to NVRAM and gets data from NVRAM.
3221 * ha = adapter block pointer.
3222 * nv_cmd = Bit 26 = start bit
3223 * Bit 25, 24 = opcode
3224 * Bit 23-16 = address
3225 * Bit 15-0 = write data
3231 qla1280_nvram_request(struct scsi_qla_host
*ha
, uint32_t nv_cmd
)
3233 struct device_reg
*reg
= ha
->iobase
;
3238 /* Send command to NVRAM. */
3241 for (cnt
= 0; cnt
< 11; cnt
++) {
3242 if (nv_cmd
& BIT_31
)
3243 qla1280_nv_write(ha
, NV_DATA_OUT
);
3245 qla1280_nv_write(ha
, 0);
3249 /* Read data from NVRAM. */
3251 for (cnt
= 0; cnt
< 16; cnt
++) {
3252 WRT_REG_WORD(®
->nvram
, (NV_SELECT
| NV_CLOCK
));
3255 reg_data
= RD_REG_WORD(®
->nvram
);
3256 if (reg_data
& NV_DATA_IN
)
3258 WRT_REG_WORD(®
->nvram
, NV_SELECT
);
3262 /* Deselect chip. */
3264 WRT_REG_WORD(®
->nvram
, NV_DESELECT
);
3271 qla1280_nv_write(struct scsi_qla_host
*ha
, uint16_t data
)
3273 struct device_reg
*reg
= ha
->iobase
;
3275 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
);
3277 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
| NV_CLOCK
);
3279 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
);
3285 * Issue mailbox command and waits for completion.
3288 * ha = adapter block pointer.
3289 * mr = mailbox registers to load.
3290 * mb = data pointer for mailbox registers.
3293 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
3299 qla1280_mailbox_command(struct scsi_qla_host
*ha
, uint8_t mr
, uint16_t * mb
)
3301 struct device_reg
*reg
= ha
->iobase
;
3303 srb_t
*done_q_first
= 0;
3304 srb_t
*done_q_last
= 0;
3308 uint16_t *optr
, *iptr
;
3311 ENTER("qla1280_mailbox_command");
3313 ha
->flags
.mbox_busy
= TRUE
;
3315 if (!ha
->flags
.ints_enabled
)
3317 "Running qla1280_mailbox_command() with interrupts "
3320 * We really should start out by verifying that the mailbox is available
3321 * before starting sending the command data
3323 /* Load mailbox registers. */
3324 optr
= (uint16_t *) ®
->mailbox0
;
3326 for (cnt
= 0; cnt
< MAILBOX_REGISTER_COUNT
; cnt
++) {
3328 WRT_REG_WORD(optr
, (*iptr
));
3336 /* Issue set host interrupt command. */
3337 ha
->flags
.mbox_int
= FALSE
;
3338 ha
->flags
.mbox_busy
= FALSE
;
3339 WRT_REG_WORD(®
->host_cmd
, HC_SET_HOST_INT
);
3340 data
= qla1280_debounce_register(®
->istatus
);
3343 * This is insane - instead of looping to wait for the interrupt
3344 * to appear and run the handler (this is insane!!), use a waitqueue
3347 * We are never called here from interrupt context anyway! /Jes
3349 /* Wait for 30 seconds for command to finish. */
3350 for (cnt
= 30000000; cnt
> 0 && !ha
->flags
.mbox_int
; cnt
--) {
3351 /* Check for pending interrupts. */
3353 if (data
& RISC_INT
) {
3354 qla1280_isr(ha
, &done_q_first
, &done_q_last
);
3359 data
= RD_REG_WORD(®
->istatus
);
3362 /* Check for mailbox command timeout. */
3365 "qla1280_mailbox_command: **** Command Timeout, "
3366 "mailbox0 = 0x%x****\n", mb
[0]);
3368 ha
->flags
.isp_abort_needed
= TRUE
;
3370 } else if (ha
->mailbox_out
[0] != MBS_CMD_CMP
)
3373 /* Load return mailbox registers. */
3375 iptr
= (uint16_t *) &ha
->mailbox_out
[0];
3376 mr
= MAILBOX_REGISTER_COUNT
;
3377 memcpy(optr
, iptr
, MAILBOX_REGISTER_COUNT
* sizeof(uint16_t));
3380 /* Go check for any response interrupts pending. */
3381 qla1280_isr(ha
, &done_q_first
, &done_q_last
);
3384 if (ha
->flags
.isp_abort_needed
)
3385 qla1280_abort_isp(ha
);
3387 if (ha
->flags
.reset_marker
)
3388 qla1280_rst_aen(ha
);
3392 qla1280_done (ha
, &done_q_first
, &done_q_last
);
3397 "qla1280_mailbox_command: **** FAILED, mailbox0 = 0x%x "
3400 LEAVE("qla1280_mailbox_command");
3406 * Polls ISP for interrupts.
3409 * ha = adapter block pointer.
3412 qla1280_poll(struct scsi_qla_host
*ha
)
3414 struct device_reg
*reg
= ha
->iobase
;
3416 srb_t
*done_q_first
= 0;
3417 srb_t
*done_q_last
= 0;
3419 /* ENTER("qla1280_poll"); */
3421 /* Check for pending interrupts. */
3422 data
= RD_REG_WORD(®
->istatus
);
3423 if (data
& RISC_INT
)
3424 qla1280_isr(ha
, &done_q_first
, &done_q_last
);
3426 if (!ha
->flags
.mbox_busy
) {
3427 if (ha
->flags
.isp_abort_needed
)
3428 qla1280_abort_isp(ha
);
3429 if (ha
->flags
.reset_marker
)
3430 qla1280_rst_aen(ha
);
3434 qla1280_done(ha
, &done_q_first
, &done_q_last
);
3436 /* LEAVE("qla1280_poll"); */
3441 * Issue SCSI bus reset.
3444 * ha = adapter block pointer.
3445 * bus = SCSI bus number.
3451 qla1280_bus_reset(struct scsi_qla_host
*ha
, int bus
)
3453 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3456 dprintk(3, "qla1280_bus_reset: entered\n");
3458 if (qla1280_verbose
)
3459 printk(KERN_INFO
"scsi(%li): Resetting SCSI BUS (%i)\n",
3462 mb
[0] = MBC_BUS_RESET
;
3463 mb
[1] = ha
->bus_settings
[bus
].bus_reset_delay
;
3464 mb
[2] = (uint16_t) bus
;
3465 status
= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
3468 if (ha
->bus_settings
[bus
].failed_reset_count
> 2) /* dg - 03/13/99 */
3469 ha
->bus_settings
[bus
].scsi_bus_dead
= TRUE
;
3470 ha
->bus_settings
[bus
].failed_reset_count
++;
3473 * Eeeeep! This is evil! /Jes
3478 schedule_timeout(4 * HZ
);
3480 ha
->bus_settings
[bus
].scsi_bus_dead
= FALSE
; /* dg - 03/13/99 */
3481 ha
->bus_settings
[bus
].failed_reset_count
= 0;
3482 /* Issue marker command. */
3483 qla1280_marker(ha
, bus
, 0, 0, MK_SYNC_ALL
);
3487 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
3489 dprintk(3, "qla1280_bus_reset: exiting normally\n");
3495 * qla1280_device_reset
3496 * Issue bus device reset message to the target.
3499 * ha = adapter block pointer.
3500 * bus = SCSI BUS number.
3507 qla1280_device_reset(struct scsi_qla_host
*ha
, int bus
, int target
)
3509 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3512 ENTER("qla1280_device_reset");
3514 mb
[0] = MBC_ABORT_TARGET
;
3515 mb
[1] = (bus
? (target
| BIT_7
) : target
) << 8;
3517 status
= qla1280_mailbox_command(ha
, BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
3519 /* Issue marker command. */
3520 qla1280_marker(ha
, bus
, target
, 0, MK_SYNC_ID
);
3523 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
3525 LEAVE("qla1280_device_reset");
3530 * qla1280_abort_device
3531 * Issue an abort message to the device
3534 * ha = adapter block pointer.
3543 qla1280_abort_device(struct scsi_qla_host
*ha
, int bus
, int target
, int lun
)
3545 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3548 ENTER("qla1280_abort_device");
3550 mb
[0] = MBC_ABORT_DEVICE
;
3551 mb
[1] = (bus
? target
| BIT_7
: target
) << 8 | lun
;
3552 status
= qla1280_mailbox_command(ha
, BIT_1
| BIT_0
, &mb
[0]);
3554 /* Issue marker command. */
3555 qla1280_marker(ha
, bus
, target
, lun
, MK_SYNC_ID_LUN
);
3558 dprintk(2, "qla1280_abort_device: **** FAILED ****\n");
3560 LEAVE("qla1280_abort_device");
3565 * qla1280_abort_command
3566 * Abort command aborts a specified IOCB.
3569 * ha = adapter block pointer.
3570 * sp = SB structure pointer.
3576 qla1280_abort_command(struct scsi_qla_host
*ha
, srb_t
* sp
)
3578 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3579 unsigned int bus
, target
, lun
;
3583 ENTER("qla1280_abort_command");
3585 /* Locate handle number. */
3586 for (handle
= 0; handle
< MAX_OUTSTANDING_COMMANDS
; handle
++)
3587 if (ha
->outstanding_cmds
[handle
] == sp
)
3590 bus
= SCSI_BUS_32(sp
->cmd
);
3591 target
= SCSI_TCN_32(sp
->cmd
);
3592 lun
= SCSI_LUN_32(sp
->cmd
);
3594 mb
[0] = MBC_ABORT_COMMAND
;
3595 mb
[1] = (bus
? target
| BIT_7
: target
) << 8 | lun
;
3596 mb
[2] = handle
>> 16;
3597 mb
[3] = handle
& 0xffff;
3599 qla1280_mailbox_command(ha
, BIT_3
| BIT_2
| BIT_1
| BIT_0
, &mb
[0]);
3602 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
3604 sp
->flags
|= SRB_ABORT_PENDING
;
3606 LEAVE("qla1280_abort_command");
3611 * qla1280_reset_adapter
3615 * ha = adapter block pointer.
3618 qla1280_reset_adapter(struct scsi_qla_host
*ha
)
3620 struct device_reg
*reg
= ha
->iobase
;
3622 ENTER("qla1280_reset_adapter");
3624 /* Disable ISP chip */
3625 ha
->flags
.online
= FALSE
;
3626 WRT_REG_WORD(®
->ictrl
, ISP_RESET
);
3627 WRT_REG_WORD(®
->host_cmd
, HC_RESET_RISC
);
3628 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
3629 WRT_REG_WORD(®
->host_cmd
, HC_DISABLE_BIOS
);
3631 LEAVE("qla1280_reset_adapter");
3635 * Issue marker command.
3636 * Function issues marker IOCB.
3639 * ha = adapter block pointer.
3640 * bus = SCSI BUS number
3643 * type = marker modifier
3646 qla1280_marker(struct scsi_qla_host
*ha
, int bus
, int id
, int lun
, u8 type
)
3650 ENTER("qla1280_marker");
3652 /* Get request packet. */
3653 if ((pkt
= (mrk_entry_t
*) qla1280_req_pkt(ha
))) {
3654 pkt
->entry_type
= MARKER_TYPE
;
3655 pkt
->lun
= (uint8_t) lun
;
3656 pkt
->target
= (uint8_t) (bus
? (id
| BIT_7
) : id
);
3657 pkt
->modifier
= type
;
3659 /* Issue command to ISP */
3660 qla1280_isp_cmd(ha
);
3663 LEAVE("qla1280_marker");
3666 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,18)
3668 * qla1280_64bit_start_scsi
3669 * The start SCSI is responsible for building request packets on
3670 * request ring and modifying ISP input pointer.
3673 * ha = adapter block pointer.
3674 * sp = SB structure pointer.
3677 * 0 = success, was able to issue command.
3680 qla1280_64bit_start_scsi(struct scsi_qla_host
*ha
, srb_t
* sp
)
3682 struct device_reg
*reg
= ha
->iobase
;
3683 Scsi_Cmnd
*cmd
= sp
->cmd
;
3684 cmd_a64_entry_t
*pkt
;
3685 struct scatterlist
*sg
= NULL
;
3687 dma_addr_t dma_handle
;
3693 ENTER("qla1280_64bit_start_scsi:");
3695 dprintk(1, "64bit_start: cmd=%p sp=%p CDB=%x\n", cmd
, sp
,
3698 /* Calculate number of entries and segments required. */
3700 if (cmd
->use_sg
) { /* 3.13 64 bit */
3701 sg
= (struct scatterlist
*) cmd
->request_buffer
;
3702 seg_cnt
= pci_map_sg (ha
->pdev
, sg
, cmd
->use_sg
,
3703 scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
3706 req_cnt
+= (seg_cnt
- 2) / 5;
3707 if ((seg_cnt
- 2) % 5)
3710 } else if (cmd
->request_bufflen
) { /* If data transfer. */
3716 if ((req_cnt
+ 2) >= ha
->req_q_cnt
) {
3717 /* Calculate number of free request entries. */
3718 cnt
= RD_REG_WORD(®
->mailbox4
);
3719 if (ha
->req_ring_index
< cnt
)
3720 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
3723 REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
3726 /* If room for request in request ring. */
3727 if ((req_cnt
+ 2) < ha
->req_q_cnt
) {
3728 /* Check for room in outstanding command list. */
3729 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
&&
3730 ha
->outstanding_cmds
[cnt
] != 0; cnt
++) ;
3732 if (cnt
< MAX_OUTSTANDING_COMMANDS
) {
3733 ha
->outstanding_cmds
[cnt
] = sp
;
3734 ha
->req_q_cnt
-= req_cnt
;
3735 CMD_HANDLE(sp
->cmd
) =
3736 (unsigned char *)(unsigned long)cnt
;
3739 * Build command packet.
3741 pkt
= (cmd_a64_entry_t
*) ha
->request_ring_ptr
;
3743 pkt
->entry_type
= COMMAND_A64_TYPE
;
3744 pkt
->entry_count
= (uint8_t) req_cnt
;
3745 pkt
->sys_define
= (uint8_t) ha
->req_ring_index
;
3746 pkt
->handle
= cpu_to_le32(cnt
);
3748 /* Zero out remaining portion of packet. */
3749 memset(((char *)pkt
+ 8), 0, (REQUEST_ENTRY_SIZE
- 8));
3751 /* Set ISP command timeout. */
3752 pkt
->timeout
= cpu_to_le16(30);
3754 /* Set device target ID and LUN */
3755 pkt
->lun
= SCSI_LUN_32(cmd
);
3756 pkt
->target
= SCSI_BUS_32(cmd
) ?
3757 (SCSI_TCN_32(cmd
) | BIT_7
) : SCSI_TCN_32(cmd
);
3759 /* Enable simple tag queuing if device supports it. */
3760 if (cmd
->device
->tagged_queue
)
3761 pkt
->control_flags
|= cpu_to_le16(BIT_3
);
3763 /* Load SCSI command packet. */
3764 pkt
->cdb_len
= cpu_to_le16(CMD_CDBLEN(cmd
));
3765 memcpy(pkt
->scsi_cdb
, &(CMD_CDBP(cmd
)), CMD_CDBLEN(cmd
));
3766 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3768 /* Set transfer direction. */
3769 sp
->dir
= qla1280_data_direction(cmd
);
3770 pkt
->control_flags
|= cpu_to_le16(sp
->dir
);
3772 /* Set total data segment count. */
3773 pkt
->dseg_count
= cpu_to_le16(seg_cnt
);
3776 * Load data segments.
3778 if (seg_cnt
) { /* If data transfer. */
3779 /* Setup packet address segment pointer. */
3780 dword_ptr
= (u32
*)&pkt
->dseg_0_address
;
3782 if (cmd
->use_sg
) { /* If scatter gather */
3783 /* Load command entry data segments. */
3784 for (cnt
= 0; cnt
< 2 && seg_cnt
;
3788 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg
)));
3790 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg
)));
3792 cpu_to_le32(sg_dma_len(sg
));
3795 "S/G Segment phys_addr=%x %x, len=0x%x\n",
3796 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg
))),
3797 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg
))),
3798 cpu_to_le32(sg_dma_len(sg
)));
3801 "qla1280_64bit_start_scsi: Scatter/gather "
3802 "command packet data - b %i, t %i, l %i \n",
3806 qla1280_dump_buffer(5, (char *)pkt
,
3807 REQUEST_ENTRY_SIZE
);
3810 * Build continuation packets.
3813 "S/G Building Continuation...seg_cnt=0x%x "
3814 "remains\n", seg_cnt
);
3816 while (seg_cnt
> 0) {
3817 /* Adjust ring index. */
3818 ha
->req_ring_index
++;
3819 if (ha
->req_ring_index
==
3820 REQUEST_ENTRY_CNT
) {
3821 ha
->req_ring_index
= 0;
3822 ha
->request_ring_ptr
=
3825 ha
->request_ring_ptr
++;
3827 pkt
= (cmd_a64_entry_t
*)ha
->request_ring_ptr
;
3829 /* Zero out packet. */
3831 REQUEST_ENTRY_SIZE
);
3833 /* Load packet defaults. */
3834 ((cont_a64_entry_t
*) pkt
)->entry_type
=
3836 ((cont_a64_entry_t
*) pkt
)->entry_count
= 1;
3837 ((cont_a64_entry_t
*) pkt
)->sys_define
=
3838 (uint8_t)ha
->req_ring_index
;
3839 /* Setup packet address segment pointer. */
3841 (u32
*)&((cont_a64_entry_t
*) pkt
)->dseg_0_address
;
3843 /* Load continuation entry data segments. */
3849 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg
)));
3851 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg
)));
3853 cpu_to_le32(sg_dma_len(sg
));
3855 "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
3856 cpu_to_le32(pci_dma_hi32(sg_dma_address(sg
))),
3857 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg
))),
3858 cpu_to_le32(sg_dma_len(sg
)));
3862 "qla1280_64bit_start_scsi: continuation "
3863 "packet data - b %i, t %i, l %i \n",
3867 qla1280_dump_buffer(5,
3869 REQUEST_ENTRY_SIZE
);
3871 } else { /* No scatter gather data transfer */
3873 dma_handle
= pci_map_single(ha
->pdev
,
3874 cmd
->request_buffer
,
3875 cmd
->request_bufflen
,
3876 scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
3877 /* save dma_handle for pci_unmap_single */
3878 sp
->saved_dma_handle
= dma_handle
;
3881 cpu_to_le32(pci_dma_lo32(dma_handle
));
3883 cpu_to_le32(pci_dma_hi32(dma_handle
));
3885 (uint32_t)cmd
->request_bufflen
;
3887 "No S/G map_single saved_dma_handle=%lx\n",dma_handle);
3890 "qla1280_64bit_start_scsi: No scatter/gather "
3891 "command packet data - b %i, t %i, l %i \n",
3895 qla1280_dump_buffer(5, (char *)pkt
,
3896 REQUEST_ENTRY_SIZE
);
3898 } else { /* No data transfer */
3900 dword_ptr
= (uint32_t *)(pkt
+ 1);
3905 "qla1280_64bit_start_scsi: No data, command "
3906 "packet data - b %i, t %i, l %i \n",
3907 SCSI_BUS_32(cmd
), SCSI_TCN_32(cmd
),
3909 qla1280_dump_buffer(5, (char *)pkt
,
3910 REQUEST_ENTRY_SIZE
);
3912 /* Adjust ring index. */
3913 ha
->req_ring_index
++;
3914 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
3915 ha
->req_ring_index
= 0;
3916 ha
->request_ring_ptr
= ha
->request_ring
;
3918 ha
->request_ring_ptr
++;
3920 /* Set chip new ring index. */
3922 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
3924 sp
->flags
|= SRB_SENT
;
3926 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
3929 dprintk(2, "qla1280_64bit_start_scsi: NO ROOM IN "
3930 "OUTSTANDING ARRAY, req_q_cnt=0x%x",
3936 "qla1280_64bit_start_scsi: in-ptr=0x%x req_q_cnt=0x%x"
3937 "req_cnt=0x%x", ha
->req_ring_index
, ha
->req_q_cnt
,
3942 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
3944 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
3951 * qla1280_32bit_start_scsi
3952 * The start SCSI is responsible for building request packets on
3953 * request ring and modifying ISP input pointer.
3955 * The Qlogic firmware interface allows every queue slot to have a SCSI
3956 * command and up to 4 scatter/gather (SG) entries. If we need more
3957 * than 4 SG entries, then continuation entries are used that can
3958 * hold another 7 entries each. The start routine determines if there
3959 * is eought empty slots then build the combination of requests to
3960 * fulfill the OS request.
3963 * ha = adapter block pointer.
3964 * sp = SCSI Request Block structure pointer.
3967 * 0 = success, was able to issue command.
3970 qla1280_32bit_start_scsi(struct scsi_qla_host
*ha
, srb_t
* sp
)
3972 struct device_reg
*reg
= ha
->iobase
;
3973 Scsi_Cmnd
*cmd
= sp
->cmd
;
3975 struct scatterlist
*sg
= NULL
;
3976 uint32_t *dword_ptr
;
3981 dma_addr_t dma_handle
;
3983 ENTER("qla1280_32bit_start_scsi");
3985 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd
, sp
,
3988 /* Calculate number of entries and segments required. */
3992 * We must build an SG list in adapter format, as the kernel's SG list
3993 * cannot be used directly because of data field size (__alpha__)
3994 * differences and the kernel SG list uses virtual addresses where
3995 * we need physical addresses.
3997 sg
= (struct scatterlist
*) cmd
->request_buffer
;
3999 seg_cnt
= pci_map_sg (ha
->pdev
, sg
, cmd
->use_sg
,
4000 scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
4003 * if greater than four sg entries then we need to allocate
4004 * continuation entries
4007 req_cnt
+= (seg_cnt
- 4) / 7;
4008 if ((seg_cnt
- 4) % 7)
4011 dprintk(1, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
4012 cmd
, seg_cnt
, req_cnt
);
4013 } else if (cmd
->request_bufflen
) { /* If data transfer. */
4014 dprintk(1, "No S/G transfer t=%x cmd=%p len=%x CDB=%x\n",
4015 SCSI_TCN_32(cmd
), cmd
, cmd
->request_bufflen
,
4019 /* dprintk(1, "No data transfer \n"); */
4023 if ((req_cnt
+ 2) >= ha
->req_q_cnt
) {
4024 /* Calculate number of free request entries. */
4025 cnt
= RD_REG_WORD(®
->mailbox4
);
4026 if (ha
->req_ring_index
< cnt
)
4027 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
4030 REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
4033 dprintk(1, "Number of free entries=(%d) seg_cnt=0x%x\n",
4034 ha
->req_q_cnt
, seg_cnt
);
4035 /* If room for request in request ring. */
4036 if ((req_cnt
+ 2) < ha
->req_q_cnt
) {
4037 /* Check for empty slot in outstanding command list. */
4038 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
&&
4039 (ha
->outstanding_cmds
[cnt
] != 0); cnt
++) ;
4041 if (cnt
< MAX_OUTSTANDING_COMMANDS
) {
4042 CMD_HANDLE(sp
->cmd
) =
4043 (unsigned char *) (unsigned long) cnt
;
4044 ha
->outstanding_cmds
[cnt
] = sp
;
4045 ha
->req_q_cnt
-= req_cnt
;
4048 * Build command packet.
4050 pkt
= (cmd_entry_t
*) ha
->request_ring_ptr
;
4052 pkt
->entry_type
= COMMAND_TYPE
;
4053 pkt
->entry_count
= (uint8_t) req_cnt
;
4054 pkt
->sys_define
= (uint8_t) ha
->req_ring_index
;
4055 pkt
->handle
= cpu_to_le32(cnt
);
4057 /* Zero out remaining portion of packet. */
4058 memset(((char *)pkt
+ 8), 0, (REQUEST_ENTRY_SIZE
- 8));
4060 /* Set ISP command timeout. */
4061 pkt
->timeout
= cpu_to_le16(30);
4063 /* Set device target ID and LUN */
4064 pkt
->lun
= SCSI_LUN_32(cmd
);
4065 pkt
->target
= SCSI_BUS_32(cmd
) ?
4066 (SCSI_TCN_32(cmd
) | BIT_7
) : SCSI_TCN_32(cmd
);
4068 /* Enable simple tag queuing if device supports it. */
4069 if (cmd
->device
->tagged_queue
)
4070 pkt
->control_flags
|= cpu_to_le16(BIT_3
);
4072 /* Load SCSI command packet. */
4073 pkt
->cdb_len
= cpu_to_le16(CMD_CDBLEN(cmd
));
4074 memcpy(pkt
->scsi_cdb
, &(CMD_CDBP(cmd
)), CMD_CDBLEN(cmd
));
4076 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
4077 /* Set transfer direction. */
4078 sp
->dir
= qla1280_data_direction(cmd
);
4079 pkt
->control_flags
|= cpu_to_le16(sp
->dir
);
4081 /* Set total data segment count. */
4082 pkt
->dseg_count
= cpu_to_le16(seg_cnt
);
4085 * Load data segments.
4088 /* Setup packet address segment pointer. */
4089 dword_ptr
= &pkt
->dseg_0_address
;
4091 if (cmd
->use_sg
) { /* If scatter gather */
4092 dprintk(1, "Building S/G data "
4094 qla1280_dump_buffer(1, (char *)sg
,
4097 /* Load command entry data segments. */
4098 for (cnt
= 0; cnt
< 4 && seg_cnt
;
4101 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
4103 cpu_to_le32(virt_to_bus(sg
->address
));
4104 *dword_ptr
++ = cpu_to_le32(sg
->length
);
4106 "S/G Segment phys_addr=0x%x, len=0x%x\n",
4107 cpu_to_le32(virt_to_bus(sg
->address
)),
4111 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg
)));
4113 cpu_to_le32(sg_dma_len(sg
));
4114 dprintk(1, "S/G Segment phys_addr=0x%x, len=0x%x\n",
4115 (pci_dma_lo32(sg_dma_address(sg
))),
4121 * Build continuation packets.
4123 dprintk(1, "S/G Building Continuation"
4124 "...seg_cnt=0x%x remains\n",
4126 while (seg_cnt
> 0) {
4127 /* Adjust ring index. */
4128 ha
->req_ring_index
++;
4129 if (ha
->req_ring_index
==
4130 REQUEST_ENTRY_CNT
) {
4131 ha
->req_ring_index
= 0;
4132 ha
->request_ring_ptr
=
4135 ha
->request_ring_ptr
++;
4137 pkt
= (cmd_entry_t
*)
4138 ha
->request_ring_ptr
;
4140 /* Zero out packet. */
4142 REQUEST_ENTRY_SIZE
);
4144 /* Load packet defaults. */
4145 ((cont_entry_t
*) pkt
)->
4146 entry_type
= CONTINUE_TYPE
;
4147 ((cont_entry_t
*) pkt
)->
4150 ((cont_entry_t
*) pkt
)->
4155 /* Setup packet address segment pointer. */
4157 &((cont_entry_t
*) pkt
)->dseg_0_address
;
4159 /* Load continuation entry data segments. */
4164 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
4166 cpu_to_le32(virt_to_bus(sg
->address
));
4167 *dword_ptr
++ = cpu_to_le32(sg
->length
);
4169 "S/G Segment Cont. phys_addr=0x%x, len=0x%x\n",
4170 cpu_to_le32(pci_dma_lo32(virt_to_bus(sg
->address
))), sg
->length
);
4173 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg
)));
4175 cpu_to_le32(sg_dma_len(sg
));
4177 "S/G Segment Cont. phys_addr=0x%x, "
4179 cpu_to_le32(pci_dma_lo32(sg_dma_address(sg
))),
4180 cpu_to_le32(sg_dma_len(sg
)));
4185 "qla1280_32bit_start_scsi: continuation "
4186 "packet data - scsi(%i:%i:%i)\n",
4190 qla1280_dump_buffer(5,
4192 REQUEST_ENTRY_SIZE
);
4194 } else { /* No S/G data transfer */
4197 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,18)
4199 cpu_to_le32 (virt_to_bus
4200 (cmd
->request_buffer
));
4202 dma_handle
= pci_map_single(ha
->pdev
,
4203 cmd
->request_buffer
,
4204 cmd
->request_bufflen
,
4205 scsi_to_pci_dma_dir(cmd
->sc_data_direction
));
4206 sp
->saved_dma_handle
= dma_handle
;
4209 cpu_to_le32(pci_dma_lo32(dma_handle
));
4212 cpu_to_le32(cmd
->request_bufflen
);
4213 qla1280_dump_buffer(1,(char *)pkt
,
4214 REQUEST_ENTRY_SIZE
);
4216 } else { /* No data transfer at all */
4218 //dword_ptr = (uint32_t *)(pkt + 1);
4222 "qla1280_32bit_start_scsi: No data, command "
4223 "packet data - \n");
4224 qla1280_dump_buffer(5, (char *)pkt
,
4225 REQUEST_ENTRY_SIZE
);
4228 "qla1280_32bit_start_scsi: First IOCB block:\n");
4229 qla1280_dump_buffer(5, (char *)ha
->request_ring_ptr
,
4230 REQUEST_ENTRY_SIZE
);
4232 /* Adjust ring index. */
4233 ha
->req_ring_index
++;
4234 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
4235 ha
->req_ring_index
= 0;
4236 ha
->request_ring_ptr
= ha
->request_ring
;
4238 ha
->request_ring_ptr
++;
4240 /* Set chip new ring index. */
4241 dprintk(1, "qla1280_32bit_start_scsi: Wakeup RISC "
4242 "for pending command\n");
4244 sp
->flags
|= SRB_SENT
;
4246 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
4250 "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
4251 "ARRAY, req_q_cnt=0x%x\n", ha
->req_q_cnt
);
4256 "qla1280_32bit_start_scsi: in-ptr=0x%x, req_q_cnt=0x%x, "
4257 "req_cnt=0x%x", ha
->req_ring_index
, ha
->req_q_cnt
,
4262 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
4264 LEAVE("qla1280_32bit_start_scsi");
4271 * Function is responsible for locking ring and
4272 * getting a zeroed out request packet.
4275 * ha = adapter block pointer.
4278 * 0 = failed to get slot.
4281 qla1280_req_pkt(struct scsi_qla_host
*ha
)
4283 struct device_reg
*reg
= ha
->iobase
;
4288 ENTER("qla1280_req_pkt");
4291 * This can be called from interrupt context, damn it!!!
4293 /* Wait for 30 seconds for slot. */
4294 for (timer
= 15000000; timer
; timer
--) {
4295 if (ha
->req_q_cnt
> 0) {
4296 /* Calculate number of free request entries. */
4297 cnt
= RD_REG_WORD(®
->mailbox4
);
4298 if (ha
->req_ring_index
< cnt
)
4299 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
4302 REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
4305 /* Found empty request ring slot? */
4306 if (ha
->req_q_cnt
> 0) {
4308 pkt
= ha
->request_ring_ptr
;
4310 /* Zero out packet. */
4311 memset(pkt
, 0, REQUEST_ENTRY_SIZE
);
4313 /* Set system defined field. */
4314 pkt
->sys_define
= (uint8_t) ha
->req_ring_index
;
4316 /* Set entry count. */
4317 pkt
->entry_count
= 1;
4324 /* Check for pending interrupts. */
4329 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
4331 dprintk(3, "qla1280_req_pkt: exiting normally\n");
4338 * Function is responsible for modifying ISP input pointer.
4339 * Releases ring lock.
4342 * ha = adapter block pointer.
4345 qla1280_isp_cmd(struct scsi_qla_host
*ha
)
4347 struct device_reg
*reg
= ha
->iobase
;
4349 ENTER("qla1280_isp_cmd");
4351 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
4352 qla1280_dump_buffer(5, (char *)ha
->request_ring_ptr
,
4353 REQUEST_ENTRY_SIZE
);
4355 /* Adjust ring index. */
4356 ha
->req_ring_index
++;
4357 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
) {
4358 ha
->req_ring_index
= 0;
4359 ha
->request_ring_ptr
= ha
->request_ring
;
4361 ha
->request_ring_ptr
++;
4363 /* Set chip new ring index. */
4364 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
4366 LEAVE("qla1280_isp_cmd");
4369 #if QL1280_LUN_SUPPORT
4371 * qla1280_enable_lun
4372 * Issue enable LUN entry IOCB.
4375 * ha = adapter block pointer.
4376 * bus = SCSI BUS number.
4380 qla1280_enable_lun(struct scsi_qla_host
*ha
, int bus
, int lun
)
4384 ENTER("qla1280_enable_lun");
4386 /* Get request packet. */
4388 if (pkt = (elun_entry_t *)qla1280_req_pkt(ha))
4390 pkt->entry_type = ENABLE_LUN_TYPE;
4391 pkt->lun = cpu_to_le16(bus ? lun | BIT_15 : lun);
4392 pkt->command_count = 32;
4393 pkt->immed_notify_count = 1;
4394 pkt->group_6_length = MAX_CMDSZ;
4395 pkt->group_7_length = MAX_CMDSZ;
4396 pkt->timeout = cpu_to_le16(0x30);
4398 qla1280_isp_cmd(ha);
4401 pkt
= (elun_entry_t
*) 1;
4404 dprintk(2, "qla1280_enable_lun: **** FAILED ****\n");
4406 dprintk(3, "qla1280_enable_lun: exiting normally\n");
4410 #if QL1280_TARGET_MODE_SUPPORT
4411 /****************************************************************************/
4412 /* Target Mode Support Functions. */
4413 /****************************************************************************/
4416 * qla1280_notify_ack
4417 * Issue notify acknowledge IOCB.
4418 * If sequence ID is zero, acknowledgement of
4419 * SCSI bus reset or bus device reset is assumed.
4422 * ha = adapter block pointer.
4423 * inotify = immediate notify entry pointer.
4426 qla1280_notify_ack(struct scsi_qla_host
*ha
, notify_entry_t
* inotify
)
4430 dprintk(3, "qla1280_notify_ack: entered\n");
4432 /* Get request packet. */
4433 if (pkt
= (nack_entry_t
*) qla1280_req_pkt(ha
)) {
4434 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
4435 pkt
->lun
= inotify
->lun
;
4436 pkt
->initiator_id
= inotify
->initiator_id
;
4437 pkt
->target_id
= inotify
->target_id
;
4438 if (inotify
->seq_id
== 0)
4441 pkt
->seq_id
= cpu_to_le16(inotify
->seq_id
);
4443 /* Issue command to ISP */
4444 qla1280_isp_cmd(ha
);
4448 dprintk(2, "qla1280_notify_ack: **** FAILED ****\n");
4450 dprintk(3, "qla1280_notify_ack: exiting normally\n");
4454 * qla1280_immed_notify
4455 * Issue immediate notify IOCB for LUN 0.
4458 * ha = adapter block pointer.
4459 * inotify = immediate notify entry pointer.
4462 qla1280_immed_notify(struct scsi_qla_host
*ha
, notify_entry_t
* inotify
)
4464 notify_entry_t
*pkt
;
4466 dprintk(3, "qla1280_immed_notify: entered\n");
4468 /* Get request packet. */
4469 if (pkt
= (notify_entry_t
*) qla1280_req_pkt(ha
)) {
4470 pkt
->entry_type
= IMMED_NOTIFY_TYPE
;
4471 pkt
->lun
= inotify
->lun
;
4472 pkt
->initiator_id
= inotify
->initiator_id
;
4473 pkt
->target_id
= inotify
->target_id
;
4476 /* Issue command to ISP */
4477 qla1280_isp_cmd(ha
);
4481 dprintk(2, "qla1280_immed_notify: **** FAILED ****\n");
4483 dprintk(3, "qla1280_immed_notify: exiting normally\n");
4488 * Issue accept target I/O IOCB for LUN 0.
4491 * ha = adapter block pointer.
4492 * ctio = ctio returned entry pointer.
4495 qla1280_accept_io(struct scsi_qla_host
*ha
, ctio_ret_entry_t
* ctio
)
4499 dprintk(3, "qla1280_accept_io: entered\n");
4501 /* Get request packet. */
4502 if (pkt
= (atio_entry_t
*) qla1280_req_pkt(ha
)) {
4503 pkt
->entry_type
= ACCEPT_TGT_IO_TYPE
;
4504 pkt
->lun
= ctio
->lun
;
4505 pkt
->initiator_id
= ctio
->initiator_id
;
4506 pkt
->target_id
= ctio
->target_id
;
4507 pkt
->tag_value
= ctio
->tag_value
;
4510 /* Issue command to ISP */
4511 qla1280_isp_cmd(ha
);
4515 dprintk(2, "qla1280_accept_io: **** FAILED ****\n");
4517 dprintk(3, "qla1280_accept_io: exiting normally\n");
4521 * qla1280_64bit_continue_io
4522 * Issue continue target I/O IOCB.
4525 * ha = adapter block pointer.
4526 * atio = atio pointer.
4527 * len = total bytecount.
4528 * addr = physical address pointer.
4531 qla1280_64bit_continue_io(struct scsi_qla_host
*ha
, atio_entry_t
* atio
,
4532 uint32_t len
, paddr32_t
* addr
)
4534 ctio_a64_entry_t
*pkt
;
4535 uint32_t *dword_ptr
;
4537 dprintk(3, "qla1280_64bit_continue_io: entered\n");
4539 /* Get request packet. */
4540 if (pkt
= (ctio_a64_entry_t
*) qla1280_req_pkt(ha
)) {
4541 pkt
->entry_type
= CTIO_A64_TYPE
;
4542 pkt
->lun
= atio
->lun
;
4543 pkt
->initiator_id
= atio
->initiator_id
;
4544 pkt
->target_id
= atio
->target_id
;
4545 pkt
->option_flags
= cpu_to_le32(atio
->option_flags
);
4546 pkt
->tag_value
= atio
->tag_value
;
4547 pkt
->scsi_status
= atio
->scsi_status
;
4550 pkt
->dseg_count
= cpu_to_le16(1);
4551 pkt
->transfer_length
= cpu_to_le32(len
);
4552 pkt
->dseg_0_length
= cpu_to_le32(len
);
4553 dword_ptr
= (uint32_t *) addr
;
4554 pkt
->dseg_0_address
[0] = cpu_to_le32(*dword_ptr
++);
4555 pkt
->dseg_0_address
[1] = cpu_to_le32(*dword_ptr
);
4558 /* Issue command to ISP */
4559 qla1280_isp_cmd(ha
);
4563 dprintk(2, "qla1280_64bit_continue_io: **** FAILED ****\n");
4565 dprintk(3, "qla1280_64bit_continue_io: exiting normally\n");
4569 * qla1280_32bit_continue_io
4570 * Issue continue target I/O IOCB.
4573 * ha = adapter block pointer.
4574 * atio = atio pointer.
4575 * len = total bytecount.
4576 * addr = physical address pointer.
4579 qla1280_32bit_continue_io(struct scsi_qla_host
*ha
, atio_entry_t
* atio
,
4580 uint32_t len
, paddr32_t
* addr
)
4583 uint32_t *dword_ptr
;
4585 dprintk(3, "qla1280_32bit_continue_io: entered\n");
4587 /* Get request packet. */
4588 if (pkt
= (ctio_entry_t
*) qla1280_req_pkt(ha
)) {
4589 pkt
->entry_type
= CONTINUE_TGT_IO_TYPE
;
4590 pkt
->lun
= atio
->lun
;
4591 pkt
->initiator_id
= atio
->initiator_id
;
4592 pkt
->target_id
= atio
->target_id
;
4593 pkt
->option_flags
= cpu_to_le32(atio
->option_flags
);
4594 pkt
->tag_value
= atio
->tag_value
;
4595 pkt
->scsi_status
= atio
->scsi_status
;
4598 pkt
->dseg_count
= cpu_to_le16(1);
4599 pkt
->transfer_length
= cpu_to_le32(len
);
4600 pkt
->dseg_0_length
= cpu_to_le32(len
);
4601 dword_ptr
= (uint32_t *)addr
;
4602 pkt
->dseg_0_address
= cpu_to_le32(*dword_ptr
);
4605 /* Issue command to ISP */
4606 qla1280_isp_cmd(ha
);
4610 dprintk(2, "qla1280_32bit_continue_io: **** FAILED ****\n");
4612 dprintk(3, "qla1280_32bit_continue_io: exiting normally\n");
4614 #endif /* QL1280_TARGET_MODE_SUPPORT */
4616 /****************************************************************************/
4617 /* Interrupt Service Routine. */
4618 /****************************************************************************/
4620 /****************************************************************************
4622 * Calls I/O done on command completion.
4625 * ha = adapter block pointer.
4626 * done_q_first = done queue first pointer.
4627 * done_q_last = done queue last pointer.
4628 ****************************************************************************/
4630 qla1280_isr(struct scsi_qla_host
*ha
, srb_t
** done_q_first
,
4631 srb_t
** done_q_last
)
4633 struct device_reg
*reg
= ha
->iobase
;
4636 uint16_t mailbox
[MAILBOX_REGISTER_COUNT
];
4641 ENTER("qla1280_isr");
4643 istatus
= RD_REG_WORD(®
->istatus
);
4644 if (!(istatus
& (RISC_INT
| PCI_INT
)))
4647 /* Save mailbox register 5 */
4648 mailbox
[5] = RD_REG_WORD(®
->mailbox5
);
4650 /* Check for mailbox interrupt. */
4652 mailbox
[0] = RD_REG_WORD(®
->semaphore
);
4654 if (mailbox
[0] & BIT_0
) {
4655 /* Get mailbox data. */
4656 /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
4659 *wptr
++ = RD_REG_WORD(®
->mailbox0
);
4660 *wptr
++ = RD_REG_WORD(®
->mailbox1
);
4661 *wptr
= RD_REG_WORD(®
->mailbox2
);
4662 if (mailbox
[0] != MBA_SCSI_COMPLETION
) {
4664 *wptr
++ = RD_REG_WORD(®
->mailbox3
);
4665 *wptr
++ = RD_REG_WORD(®
->mailbox4
);
4667 *wptr
++ = RD_REG_WORD(®
->mailbox6
);
4668 *wptr
= RD_REG_WORD(®
->mailbox7
);
4671 /* Release mailbox registers. */
4673 WRT_REG_WORD(®
->semaphore
, 0);
4674 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
4676 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
4679 /* Handle asynchronous event */
4680 switch (mailbox
[0]) {
4681 case MBA_SCSI_COMPLETION
: /* Response completion */
4683 "qla1280_isr: mailbox SCSI response completion\n");
4685 if (ha
->flags
.online
) {
4686 /* Get outstanding command index. */
4687 index
= mailbox
[2] << 16 | mailbox
[1];
4689 /* Validate handle. */
4690 if (index
< MAX_OUTSTANDING_COMMANDS
)
4691 sp
= ha
->outstanding_cmds
[index
];
4696 /* Free outstanding command slot. */
4697 ha
->outstanding_cmds
[index
] = 0;
4699 /* Save ISP completion status */
4700 CMD_RESULT(sp
->cmd
) = 0;
4702 /* Place block on done queue */
4704 sp
->s_prev
= *done_q_last
;
4708 (*done_q_last
)->s_next
= sp
;
4712 * If we get here we have a real problem!
4715 "qla1280: ISP invalid handle");
4716 ha
->flags
.isp_abort_needed
= TRUE
;
4721 case MBA_BUS_RESET
: /* SCSI Bus Reset */
4722 ha
->flags
.reset_marker
= TRUE
;
4723 index
= mailbox
[6] & BIT_0
;
4724 ha
->bus_settings
[index
].reset_marker
= TRUE
;
4727 "qla1280_isr(): index %i asynchronous "
4728 "BUS_RESET\n", index
);
4731 case MBA_SYSTEM_ERR
: /* System Error */
4733 "qla1280: ISP System Error - mbx1=%xh, mbx2=%xh, "
4734 "mbx3=%xh\n", mailbox
[1], mailbox
[2],
4736 ha
->flags
.isp_abort_needed
= TRUE
;
4739 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
4741 "qla1280: ISP Request Transfer Error\n");
4742 ha
->flags
.isp_abort_needed
= TRUE
;
4745 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
4747 "qla1280: ISP Response Transfer Error\n");
4748 ha
->flags
.isp_abort_needed
= TRUE
;
4751 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up */
4752 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
4755 case MBA_TIMEOUT_RESET
: /* Execution Timeout Reset */
4757 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
4760 case MBA_DEVICE_RESET
: /* Bus Device Reset */
4762 "qla1280_isr: asynchronous BUS_DEVICE_RESET\n");
4763 printk(KERN_INFO
"qla1280_isr(): asynchronous "
4764 "BUS_DEVICE_RESET\n");
4766 ha
->flags
.reset_marker
= TRUE
;
4767 index
= mailbox
[6] & BIT_0
;
4768 ha
->bus_settings
[index
].reset_marker
= TRUE
;
4771 case MBA_BUS_MODE_CHANGE
:
4773 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
4777 /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
4778 if (mailbox
[0] < MBA_ASYNC_EVENT
) {
4780 memcpy((uint16_t *) ha
->mailbox_out
, wptr
,
4781 MAILBOX_REGISTER_COUNT
*
4783 ha
->flags
.mbox_int
= TRUE
;
4788 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
4792 * Response ring - waiting for the mbox_busy flag here seems
4793 * unnecessary as the mailbox data has been copied to ha->mailbox_out
4794 * by the time we actually get here!
4796 if (ha
->flags
.online
4798 && !ha
->flags
.mbox_busy
4801 if (mailbox
[5] < RESPONSE_ENTRY_CNT
) {
4802 while (ha
->rsp_ring_index
!= mailbox
[5]) {
4803 pkt
= ha
->response_ring_ptr
;
4806 "qla1280_isr: ha->rsp_ring_index = 0x%x, "
4807 "mailbox[5] = 0x%x\n",
4808 ha
->rsp_ring_index
, mailbox
[5]);
4810 "qla1280_isr: response packet data\n");
4811 qla1280_dump_buffer(5, (char *)pkt
,
4812 RESPONSE_ENTRY_SIZE
);
4814 if (pkt
->entry_type
== STATUS_TYPE
) {
4815 if ((le16_to_cpu(pkt
->scsi_status
) & 0xff)
4817 || pkt
->entry_status
) {
4819 "qla1280_isr: ha->rsp_ring_index = 0x%x"
4820 "mailbox[5] = 0x%x, comp_status = 0x%x, "
4821 "scsi_status = 0x%x\n",
4824 le16_to_cpu(pkt
->comp_status
),
4825 le16_to_cpu(pkt
->scsi_status
));
4829 "qla1280_isr: ha->rsp_ring_index = 0x%x, "
4830 "mailbox[5] = 0x%x\n",
4834 "qla1280_isr: response packet data\n");
4835 qla1280_dump_buffer(2, (char *)pkt
,
4836 RESPONSE_ENTRY_SIZE
);
4839 if (pkt
->entry_type
== STATUS_TYPE
4840 || pkt
->entry_status
) {
4841 if (pkt
->entry_type
== STATUS_TYPE
)
4842 qla1280_status_entry(ha
,
4843 (sts_entry_t
*) pkt
,
4847 qla1280_error_entry(ha
, pkt
,
4851 /* Adjust ring index. */
4852 ha
->rsp_ring_index
++;
4853 if (ha
->rsp_ring_index
==
4854 RESPONSE_ENTRY_CNT
) {
4855 ha
->rsp_ring_index
= 0;
4856 ha
->response_ring_ptr
=
4859 ha
->response_ring_ptr
++;
4860 WRT_REG_WORD(®
->mailbox5
,
4861 ha
->rsp_ring_index
);
4863 #if QLA1280_TARGET_MODE_SUPPORT
4865 pkt
= &response_entry
;
4869 (uint32_t *)ha
->response_ring_ptr
;
4870 dptr2
= (uint32_t *) pkt
;
4872 index
< RESPONSE_ENTRY_SIZE
/ 4;
4874 *dptr2
++ = *dptr1
++;
4876 /* Adjust ring index. */
4877 ha
->rsp_ring_index
++;
4878 if (ha
->rsp_ring_index
==
4879 RESPONSE_ENTRY_CNT
) {
4880 ha
->rsp_ring_index
= 0;
4881 ha
->response_ring_ptr
=
4884 ha
->response_ring_ptr
++;
4885 WRT_REG_WORD(®
->mailbox5
,
4886 ha
->rsp_ring_index
);
4888 switch (pkt
->entry_type
) {
4889 case ACCEPT_TGT_IO_TYPE
:
4890 qla1280_atio_entry(ha
,
4891 (atio_entry_t
*) pkt
);
4893 case IMMED_NOTIFY_TYPE
:
4894 qla1280_notify_entry(ha
,
4895 (notify_entry_t
*) pkt
);
4898 qla1280_accept_io(ha
,
4899 (ctio_ret_entry_t
*) pkt
);
4908 ha
->flags
.isp_abort_needed
= TRUE
;
4909 dprintk(2, "qla1280_isr: Response pointer Error\n");
4913 LEAVE("qla1280_isr");
4918 * Processes asynchronous reset.
4921 * ha = adapter block pointer.
4924 qla1280_rst_aen(struct scsi_qla_host
*ha
)
4926 #if QL1280_TARGET_MODE_SUPPORT
4927 notify_entry_t nentry
;
4931 ENTER("qla1280_rst_aen");
4933 if (ha
->flags
.online
&& !ha
->flags
.reset_active
&&
4934 !ha
->flags
.abort_isp_active
) {
4935 ha
->flags
.reset_active
= TRUE
;
4936 while (ha
->flags
.reset_marker
) {
4937 /* Issue marker command. */
4938 ha
->flags
.reset_marker
= FALSE
;
4939 for (bus
= 0; bus
< ha
->ports
&&
4940 !ha
->flags
.reset_marker
; bus
++) {
4941 if (ha
->bus_settings
[bus
].reset_marker
) {
4942 ha
->bus_settings
[bus
].reset_marker
=
4944 qla1280_marker(ha
, bus
, 0, 0,
4947 if (!ha
->flags
.reset_marker
) {
4948 #if QL1280_TARGET_MODE_SUPPORT
4949 /* Issue notify acknowledgement command. */
4951 sizeof(notify_entry_t
));
4953 nentry
.initiator_id
=
4955 bus
? ha
->bus_settings
[bus
].id
| BIT_7
:
4956 ha
->bus_settings
[bus
].id
;
4957 qla1280_notify_entry(ha
,
4960 /* Asynchronous event notification */
4967 LEAVE("qla1280_rst_aen");
4970 #if QL1280_TARGET_MODE_SUPPORT
4972 * qla1280_atio_entry
4973 * Processes received ISP accept target I/O entry.
4976 * ha = adapter block pointer.
4977 * pkt = entry pointer.
4980 qla1280_atio_entry(struct scsi_qla_host
*ha
, atio_entry_t
* pkt
)
4984 paddr32_t phy_addr
[2];
4985 paddr32_t end_addr
[2];
4991 dprintk(3, "qla1280_atio_entry: entered\n");
4993 t
= pkt
->initiator_id
;
4994 sense_ptr
= ha
->tsense
+ t
* TARGET_SENSE_SIZE
;
4995 a64
= (uint64_t *)&phy_addr
[0];
4996 end_a64
= (uint64_t *)&end_addr
[0];
4998 switch (pkt
->status
& ~BIT_7
) {
4999 case 7: /* Path invalid */
5000 dprintk(2, "qla1280_atio_entry: Path invalid\n");
5003 case 0x14: /* Target Bus Phase Sequence Failure */
5004 dprintk(2, "qla1280_atio_entry: Target Bus Phase "
5005 "Sequence Failure\n");
5007 if (pkt
->status
& BIT_7
) {
5008 memcpy(sense_ptr
, &pkt
->sense_data
, TARGET_SENSE_SIZE
);
5010 memset(sense_ptr
, 0, TARGET_SENSE_SIZE
);
5012 *(sense_ptr
+ 2) = SD_HARDERR
;
5013 *(sense_ptr
+ 7) = TARGET_SENSE_SIZE
- 8;
5014 *(sense_ptr
+ 12) = SC_SELFAIL
;
5016 pkt
->scsi_status
= S_CKCON
;
5017 pkt
->option_flags
|= cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5019 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,18)
5020 if (ha
->flags
.enable_64bit_addressing
)
5021 qla1280_64bit_continue_io(ha
, pkt
, 0, 0);
5024 qla1280_32bit_continue_io(ha
, pkt
, 0, 0);
5027 case 0x16: /* Requested Capability Not Available */
5028 dprintk(2, "qla1280_atio_entry: Target Bus Phase "
5029 "Sequence Failure\n");
5032 case 0x17: /* Bus Device Reset Message Received */
5033 dprintk(2, "qla1280_atio_entry: Target Bus Phase "
5034 "Sequence Failure\n");
5037 case 0x3D: /* CDB Received */
5039 /* Check for invalid LUN */
5040 if (pkt
->lun
&& pkt
->cdb
[0] != SS_INQUIR
&&
5041 pkt
->cdb
[0] != SS_REQSEN
)
5042 pkt
->cdb
[0] = SS_TEST
;
5044 switch (pkt
->cdb
[0]) {
5046 dprintk(3, "qla1280_atio_entry: SS_TEST\n");
5048 memset(sense_ptr
, 0, TARGET_SENSE_SIZE
);
5051 pkt
->scsi_status
= S_GOOD
;
5054 *(sense_ptr
+ 2) = SD_ILLREQ
;
5055 *(sense_ptr
+ 7) = TARGET_SENSE_SIZE
- 8;
5056 *(sense_ptr
+ 12) = SC_INVLUN
;
5057 pkt
->scsi_status
= S_CKCON
;
5060 pkt
->option_flags
|= cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5064 dprintk(3, "qla1280_atio_entry: SS_REQSEN\n");
5066 phy_addr
[0] = ha
->tsense_dma
;
5068 *a64
+= t
* TARGET_SENSE_SIZE
;
5069 if (pkt
->cdb
[4] > TARGET_SENSE_SIZE
)
5070 len
= TARGET_SENSE_SIZE
;
5073 pkt
->scsi_status
= S_GOOD
;
5074 pkt
->option_flags
|= cpu_to_le32(OF_SSTS
| OF_DATA_IN
);
5078 dprintk(3, "qla1280_atio_entry: SS_INQUIR\n");
5080 memset(sense_ptr
, 0, TARGET_SENSE_SIZE
);
5081 phy_addr
[0] = ha
->tbuf_dma
;
5083 *a64
+= TARGET_INQ_OFFSET
;
5085 if (pkt
->lun
== 0) {
5086 ha
->tbuf
->inq
.id_type
= ID_PROCESOR
;
5087 ha
->tbuf
->inq
.id_pqual
= ID_QOK
;
5089 ha
->tbuf
->inq
.id_type
= ID_NODEV
;
5090 ha
->tbuf
->inq
.id_pqual
= ID_QNOLU
;
5093 if (pkt
->cdb
[4] > sizeof(struct ident
))
5094 len
= sizeof(struct ident
);
5097 pkt
->scsi_status
= S_GOOD
;
5098 pkt
->option_flags
|= cpu_to_le32(OF_SSTS
| OF_DATA_IN
);
5102 memset(sense_ptr
, 0, TARGET_SENSE_SIZE
);
5103 offset
= pkt
->cdb
[5];
5104 offset
|= pkt
->cdb
[4] << 8;
5105 offset
|= pkt
->cdb
[3] << 16;
5107 len
|= pkt
->cdb
[7] << 8;
5108 len
|= pkt
->cdb
[6] << 16;
5109 end_addr
[0] = phy_addr
[0] = ha
->tbuf_dma
;
5110 end_addr
[1] = phy_addr
[1] = 0;
5111 *end_a64
+= TARGET_DATA_OFFSET
+ TARGET_DATA_SIZE
;
5112 switch (pkt
->cdb
[1] & 7) {
5114 dprintk(3, "qla1280_atio_entry: SM_WRDB, "
5117 if (len
> TARGET_DATA_SIZE
+ 4) {
5119 "qla1280_atio_entry: SM_WRDB, "
5120 "length > buffer size\n");
5123 *(sense_ptr
+ 2) = SD_ILLREQ
;
5125 TARGET_SENSE_SIZE
- 8;
5126 *(sense_ptr
+ 12) = SC_ILLCDB
;
5127 pkt
->scsi_status
= S_CKCON
;
5128 pkt
->option_flags
|=
5129 cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5132 pkt
->scsi_status
= S_GOOD
;
5133 pkt
->option_flags
|=
5134 cpu_to_le32(OF_SSTS
| OF_DATA_OUT
);
5136 "qla1280_atio_entry: Issuing "
5137 "SDI_TARMOD_WRCOMP\n");
5139 sdi_xaen(SDI_TARMOD_WRCOMP
, ha
->cntlr
,
5140 pkt
->target_id
, pkt
->lun
, 0,
5144 "qla1280_atio_entry: SM_WRDB, "
5147 pkt
->scsi_status
= S_GOOD
;
5148 pkt
->option_flags
|=
5149 cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5154 dprintk(3, "qla1280_atio_entry: SM_WRDB, "
5157 *a64
+= offset
+ TARGET_DATA_OFFSET
;
5158 if (pkt
->cdb
[2] != 0 || *a64
>= *end_a64
||
5159 *a64
+ len
> *end_a64
) {
5161 "qla1280_atio_entry: SM_WRDB, "
5162 "RW_BUF_DATA BAD\n");
5163 dprintk(2, "buf_id=0x%x, offset=0x%x, "
5164 "length=0x%x\n", pkt
->cdb
[2],
5168 *(sense_ptr
+ 2) = SD_ILLREQ
;
5170 TARGET_SENSE_SIZE
- 8;
5171 *(sense_ptr
+ 12) = SC_ILLCDB
;
5173 pkt
->scsi_status
= S_CKCON
;
5174 pkt
->option_flags
|=
5175 cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5177 pkt
->scsi_status
= S_GOOD
;
5178 pkt
->option_flags
|=
5179 cpu_to_le32(OF_SSTS
| OF_DATA_OUT
);
5181 "qla1280_atio_entry: Issuing "
5182 "SDI_TARMOD_WRCOMP\n");
5184 sdi_xaen(SDI_TARMOD_WRCOMP
, ha
->cntlr
,
5185 pkt
->target_id
, pkt
->lun
, 0,
5189 "qla1280_atio_entry: SM_WRDB, "
5192 pkt
->scsi_status
= S_GOOD
;
5193 pkt
->option_flags
|=
5194 cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5199 dprintk(2, "qla1280_atio_entry: SM_WRDB "
5203 *(sense_ptr
+ 2) = SD_ILLREQ
;
5204 *(sense_ptr
+ 7) = TARGET_SENSE_SIZE
- 8;
5205 *(sense_ptr
+ 12) = SC_ILLCDB
;
5207 pkt
->scsi_status
= S_CKCON
;
5208 pkt
->option_flags
|= cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5214 memset(sense_ptr
, 0, TARGET_SENSE_SIZE
);
5215 offset
= pkt
->cdb
[5];
5216 offset
|= pkt
->cdb
[4] << 8;
5217 offset
|= pkt
->cdb
[3] << 16;
5219 len
|= pkt
->cdb
[7] << 8;
5220 len
|= pkt
->cdb
[6] << 16;
5221 end_addr
[0] = phy_addr
[0] = ha
->tbuf_dma
;
5222 end_addr
[1] = phy_addr
[1] = 0;
5223 *end_a64
+= TARGET_DATA_OFFSET
+ TARGET_DATA_SIZE
;
5224 switch (pkt
->cdb
[1] & 7) {
5226 dprintk(3, "qla1280_atio_entry: SM_RDDB, "
5230 ha
->tbuf
->hdr
[0] = 0;
5232 (TARGET_DATA_SIZE
>> 16) & 0xff;
5234 (TARGET_DATA_SIZE
>> 8) & 0xff;
5236 TARGET_DATA_SIZE
& 0xff;
5237 if (len
> TARGET_DATA_SIZE
+ 4)
5238 len
= TARGET_DATA_SIZE
+ 4;
5239 pkt
->scsi_status
= S_GOOD
;
5240 pkt
->option_flags
|=
5241 cpu_to_le32(OF_SSTS
| OF_DATA_IN
);
5244 "qla1280_atio_entry: SM_RDDB, "
5247 pkt
->scsi_status
= S_GOOD
;
5248 pkt
->option_flags
|=
5249 cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5253 dprintk(3, "qla1280_atio_entry: SM_RDDB, "
5256 *a64
+= offset
+ TARGET_DATA_OFFSET
;
5257 if (pkt
->cdb
[2] != 0 || *a64
>= *end_a64
) {
5259 "qla1280_atio_entry: SM_RDDB, "
5260 "RW_BUF_DATA BAD\n");
5261 dprintk(2, "buf_id=0x%x, offset=0x%x\n"
5262 pkt
->cdb
[2], offset
);
5265 *(sense_ptr
+ 2) = SD_ILLREQ
;
5267 TARGET_SENSE_SIZE
- 8;
5268 *(sense_ptr
+ 12) = SC_ILLCDB
;
5270 pkt
->scsi_status
= S_CKCON
;
5271 pkt
->option_flags
|=
5272 cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5274 if (*a64
+ len
> *end_a64
)
5275 len
= *end_a64
- *a64
;
5277 pkt
->scsi_status
= S_GOOD
;
5278 pkt
->option_flags
|=
5279 (OF_SSTS
| OF_DATA_IN
);
5282 "qla1280_atio_entry: SM_RDDB, "
5285 pkt
->scsi_status
= S_GOOD
;
5286 pkt
->option_flags
|=
5287 cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5292 dprintk(3, "qla1280_atio_entry: SM_RDDB, "
5299 ha
->tbuf
->hdr
[0] = 0;
5300 if (pkt
->cdb
[2] != 0) {
5301 ha
->tbuf
->hdr
[1] = 0;
5302 ha
->tbuf
->hdr
[2] = 0;
5303 ha
->tbuf
->hdr
[3] = 0;
5306 (TARGET_DATA_SIZE
>> 16) &
5309 (TARGET_DATA_SIZE
>> 8) &
5312 TARGET_DATA_SIZE
& 0xff;
5314 pkt
->scsi_status
= S_GOOD
;
5315 pkt
->option_flags
|=
5316 cpu_to_le32(OF_SSTS
| OF_DATA_IN
);
5319 "qla1280_atio_entry: SM_RDDB,"
5322 pkt
->scsi_status
= S_GOOD
;
5323 pkt
->option_flags
|=
5324 cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5328 dprintk(2, "qla1280_atio_entry: SM_RDDB "
5332 *(sense_ptr
+ 2) = SD_ILLREQ
;
5333 *(sense_ptr
+ 7) = TARGET_SENSE_SIZE
- 8;
5334 *(sense_ptr
+ 12) = SC_ILLCDB
;
5336 pkt
->scsi_status
= S_CKCON
;
5337 pkt
->option_flags
|= cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5344 "qla1280_atio_entry: Unknown SCSI command\n");
5345 qla1280_dump_buffer(2, &pkt
->cdb
[0], pkt
->cdb_len
);
5347 memset(sense_ptr
, 0, TARGET_SENSE_SIZE
);
5349 *(sense_ptr
+ 2) = SD_ILLREQ
;
5350 *(sense_ptr
+ 7) = TARGET_SENSE_SIZE
- 8;
5351 *(sense_ptr
+ 12) = SC_INVOPCODE
;
5353 pkt
->scsi_status
= S_CKCON
;
5354 pkt
->option_flags
|= cpu_to_le32(OF_SSTS
| OF_NO_DATA
);
5357 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,18)
5358 if (ha
->flags
.enable_64bit_addressing
)
5359 qla1280_64bit_continue_io(ha
, pkt
, len
,
5360 (paddr32_t
*)&phy_addr
);
5363 qla1280_32bit_continue_io(ha
, pkt
, len
,
5364 (paddr32_t
*)&phy_addr
);
5371 dprintk(3, "qla1280_atio_entry: exiting normally\n");
5375 * qla1280_notify_entry
5376 * Processes received ISP immediate notify entry.
5379 * ha = adapter block pointer.
5380 * pkt = entry pointer.
5383 qla1280_notify_entry(struct scsi_qla_host
*ha
, notify_entry_t
* pkt
)
5385 dprintk(3, "qla1280_notify_entry: entered\n");
5387 /* Acknowledge immediate notify */
5388 qla1280_notify_ack(ha
, pkt
);
5390 /* Issue notify entry to increment resource count */
5391 qla1280_immed_notify(ha
, pkt
);
5393 dprintk(3, "qla1280_notify_entry: exiting normally\n");
5395 #endif /* QLA1280_TARGET_MODE_SUPPORT */
5398 * qla1280_status_entry
5399 * Processes received ISP status entry.
5402 * ha = adapter block pointer.
5403 * pkt = entry pointer.
5404 * done_q_first = done queue first pointer.
5405 * done_q_last = done queue last pointer.
5408 qla1280_status_entry(struct scsi_qla_host
*ha
, sts_entry_t
* pkt
,
5409 srb_t
** done_q_first
, srb_t
** done_q_last
)
5411 unsigned int bus
, target
, lun
;
5416 uint32_t handle
= le32_to_cpu(pkt
->handle
);
5417 uint16_t scsi_status
= le16_to_cpu(pkt
->scsi_status
);
5418 uint16_t comp_status
= le16_to_cpu(pkt
->comp_status
);
5420 ENTER("qla1280_status_entry");
5422 /* Validate handle. */
5423 if (handle
< MAX_OUTSTANDING_COMMANDS
)
5424 sp
= ha
->outstanding_cmds
[handle
];
5429 /* Free outstanding command slot. */
5430 ha
->outstanding_cmds
[handle
] = 0;
5434 /* Generate LU queue on cntrl, target, LUN */
5435 bus
= SCSI_BUS_32(cmd
);
5436 target
= SCSI_TCN_32(cmd
);
5437 lun
= SCSI_LUN_32(cmd
);
5438 q
= LU_Q(ha
, bus
, target
, lun
);
5440 if (comp_status
|| scsi_status
) {
5441 dprintk(1, "scsi: comp_status = 0x%x, scsi_status = "
5442 "0x%x, handle = 0x%lx\n", comp_status
,
5443 scsi_status
, handle
);
5447 if (scsi_status
& SS_BUSY_CONDITION
&&
5448 scsi_status
!= SS_RESERVE_CONFLICT
) {
5450 DID_BUS_BUSY
<< 16 | (scsi_status
& 0xff);
5453 /* Save ISP completion status */
5454 CMD_RESULT(cmd
) = qla1280_return_status(pkt
, cmd
);
5456 if (scsi_status
& SS_CHECK_CONDITION
) {
5457 if (comp_status
!= CS_ARS_FAILED
) {
5458 uint16_t req_sense_length
=
5459 le16_to_cpu(pkt
->req_sense_length
);
5460 if (req_sense_length
<
5462 sense_sz
= req_sense_length
;
5465 * Scsi_Cmnd->sense_buffer is
5466 * 64 bytes, why only copy 63?
5467 * This looks wrong! /Jes
5469 sense_sz
= CMD_SNSLEN(cmd
) - 1;
5471 memcpy(cmd
->sense_buffer
,
5472 &pkt
->req_sense_data
, sense_sz
);
5475 memset(cmd
->sense_buffer
+ sense_sz
, 0,
5476 sizeof(cmd
->sense_buffer
) - sense_sz
);
5478 dprintk(2, "qla1280_status_entry: Check "
5479 "condition Sense data, b %i, t %i, "
5480 "l %i\n", bus
, target
, lun
);
5482 qla1280_dump_buffer(2, (char *)cmd
->sense_buffer
,
5486 /* Place command on done queue. */
5487 qla1280_done_q_put(sp
, done_q_first
, done_q_last
);
5489 printk(KERN_WARNING
"qla1280: Status Entry invalid handle\n");
5490 ha
->flags
.isp_abort_needed
= TRUE
;
5493 LEAVE("qla1280_status_entry");
5497 * qla1280_error_entry
5498 * Processes error entry.
5501 * ha = adapter block pointer.
5502 * pkt = entry pointer.
5503 * done_q_first = done queue first pointer.
5504 * done_q_last = done queue last pointer.
5507 qla1280_error_entry(struct scsi_qla_host
*ha
, response_t
* pkt
,
5508 srb_t
** done_q_first
, srb_t
** done_q_last
)
5511 uint32_t handle
= le32_to_cpu(pkt
->handle
);
5513 ENTER("qla1280_error_entry");
5515 if (pkt
->entry_status
& BIT_3
)
5516 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
5517 else if (pkt
->entry_status
& BIT_2
)
5518 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
5519 else if (pkt
->entry_status
& BIT_1
)
5520 dprintk(2, "qla1280_error_entry: FULL flag error\n");
5522 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
5524 /* Validate handle. */
5525 if (handle
< MAX_OUTSTANDING_COMMANDS
)
5526 sp
= ha
->outstanding_cmds
[handle
];
5531 /* Free outstanding command slot. */
5532 ha
->outstanding_cmds
[handle
] = 0;
5534 /* Bad payload or header */
5535 if (pkt
->entry_status
& (BIT_3
+ BIT_2
)) {
5536 /* Bad payload or header, set error status. */
5537 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
5538 CMD_RESULT(sp
->cmd
) = DID_ERROR
<< 16;
5539 } else if (pkt
->entry_status
& BIT_1
) { /* FULL flag */
5540 CMD_RESULT(sp
->cmd
) = DID_BUS_BUSY
<< 16;
5542 /* Set error status. */
5543 CMD_RESULT(sp
->cmd
) = DID_ERROR
<< 16;
5545 /* Place command on done queue. */
5546 qla1280_done_q_put(sp
, done_q_first
, done_q_last
);
5548 #ifdef QLA_64BIT_PTR
5549 else if (pkt
->entry_type
== COMMAND_A64_TYPE
) {
5550 printk(KERN_WARNING
"!qla1280: Error Entry invalid handle");
5551 ha
->flags
.isp_abort_needed
= TRUE
;
5555 LEAVE("qla1280_error_entry");
5560 * Resets ISP and aborts all outstanding commands.
5563 * ha = adapter block pointer.
5569 qla1280_abort_isp(struct scsi_qla_host
*ha
)
5572 struct device_reg
*reg
= ha
->iobase
;
5578 int bus
, target
, lun
;
5580 ENTER("qla1280_abort_isp");
5582 ha
->flags
.isp_abort_needed
= FALSE
;
5583 if (!ha
->flags
.abort_isp_active
&& ha
->flags
.online
) {
5584 ha
->flags
.abort_isp_active
= TRUE
;
5586 /* Disable ISP interrupts. */
5587 qla1280_disable_intrs(ha
);
5589 /* Dequeue all commands in outstanding command list. */
5590 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
5591 sp
= ha
->outstanding_cmds
[cnt
];
5593 ha
->outstanding_cmds
[cnt
] = 0;
5595 /* Generate LU queue on controller, target, LUN */
5596 bus
= SCSI_BUS_32(sp
->cmd
);
5597 target
= SCSI_TCN_32(sp
->cmd
);
5598 lun
= SCSI_LUN_32(sp
->cmd
);
5600 q
= LU_Q(ha
, bus
, target
, lun
);
5602 /* Reset outstanding command count. */
5604 q
->q_flag
&= ~QLA1280_QBUSY
;
5607 /* Adjust watchdog timer for command. */
5608 /* if (sp->flags & SRB_WATCHDOG)
5609 sp->timeout += 2; */
5611 /* Place request back on top of device queue. */
5613 qla1280_putq_t(q
, sp
);
5617 /* If firmware needs to be loaded */
5618 if (qla1280_isp_firmware (ha
)) {
5619 if (!(status
= qla1280_chip_diag(ha
)))
5620 status
= qla1280_setup_chip(ha
);
5624 /* Setup adapter based on NVRAM parameters. */
5625 qla1280_nvram_config (ha
);
5627 if (!(status
= qla1280_init_rings(ha
))) {
5628 /* Issue SCSI reset. */
5629 for (bus
= 0; bus
< ha
->ports
; bus
++) {
5630 qla1280_bus_reset(ha
, bus
);
5633 /* Issue marker command. */
5634 ha
->flags
.reset_marker
= FALSE
;
5635 for (bus
= 0; bus
< ha
->ports
; bus
++) {
5636 ha
->bus_settings
[bus
].
5637 reset_marker
= FALSE
;
5638 qla1280_marker(ha
, bus
, 0, 0,
5641 } while (ha
->flags
.reset_marker
);
5643 /* Enable host adapter target mode. */
5644 for (bus
= 0; bus
< ha
->ports
; bus
++) {
5647 qla1280_enable_tgt(ha
, bus
))) {
5648 for (cnt
= 0; cnt
< MAX_LUNS
;
5650 /* qla1280_enable_lun(ha, bus, cnt); */
5658 /* Enable ISP interrupts. */
5659 qla1280_enable_intrs(ha
);
5660 ha
->flags
.abort_isp_active
= FALSE
;
5661 /* Restart queues that may have been stopped. */
5662 qla1280_restart_queues(ha
);
5670 "qla1280: ISP error recovery failed, board disabled");
5671 qla1280_reset_adapter(ha
);
5672 qla1280_abort_queues(ha
);
5674 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
5677 LEAVE("qla1280_abort_isp");
5682 * qla1280_restart_queues
5683 * Restart all device queues.
5686 * ha = adapter block pointer.
5689 qla1280_restart_queues(struct scsi_qla_host
*ha
)
5692 int bus
, target
, lun
;
5694 ENTER("qla1280_restart_queues");
5696 for (bus
= 0; bus
< ha
->ports
; bus
++)
5697 for (target
= 0; target
< MAX_TARGETS
; target
++)
5698 for (lun
= 0; lun
< MAX_LUNS
; lun
++) {
5699 q
= LU_Q(ha
, bus
, target
, lun
);
5702 qla1280_next(ha
, q
, bus
);
5705 dprintk(3, "qla1280_restart_queues: exiting normally\n");
5709 * qla1280_abort_queue_single
5710 * Abort all commands on a device queues.
5713 * ha = adapter block pointer.
5716 qla1280_abort_queue_single(struct scsi_qla_host
*ha
, int bus
,
5717 int target
, int lun
, uint32_t stat
)
5720 srb_t
*sp
, *sp_next
;
5722 ENTER("qla1280_abort_queue_single");
5723 q
= LU_Q(ha
, bus
, target
, lun
);
5726 q
->q_first
= q
->q_last
= NULL
;
5729 sp_next
= sp
->s_next
;
5730 CMD_RESULT(sp
->cmd
) = stat
;
5731 qla1280_done_q_put(sp
, &ha
->done_q_first
,
5736 LEAVE("qla1280_abort_queue_single");
5740 * qla1280_abort_queues
5741 * Abort all commands on device queues.
5744 * ha = adapter block pointer.
5747 qla1280_abort_queues(struct scsi_qla_host
*ha
)
5749 uint32_t bus
, target
, lun
;
5751 ENTER("qla1280_abort_queues");
5753 for (bus
= 0; bus
< ha
->ports
; bus
++)
5754 for (target
= 0; target
< MAX_TARGETS
; target
++)
5755 for (lun
= 0; lun
< MAX_LUNS
; lun
++)
5756 qla1280_abort_queue_single(ha
, bus
, target
,
5759 LEAVE("qla1280_abort_queues");
5763 * qla1280_debounce_register
5764 * Debounce register.
5767 * port = register address.
5773 qla1280_debounce_register(volatile u16
* addr
)
5778 ret
= RD_REG_WORD(addr
);
5779 ret2
= RD_REG_WORD(addr
);
5786 ret
= RD_REG_WORD(addr
);
5787 ret2
= RD_REG_WORD(addr
);
5788 } while (ret
!= ret2
);
5793 static Scsi_Host_Template driver_template
= {
5794 .proc_info
= qla1280_proc_info
,
5795 .name
= "Qlogic ISP 1280/12160",
5796 .detect
= qla1280_detect
,
5797 .release
= qla1280_release
,
5798 .info
= qla1280_info
,
5799 .queuecommand
= qla1280_queuecommand
,
5800 .eh_abort_handler
= qla1280_eh_abort
,
5801 .eh_device_reset_handler
= qla1280_eh_device_reset
,
5802 .eh_bus_reset_handler
= qla1280_eh_bus_reset
,
5803 .eh_host_reset_handler
= qla1280_eh_adapter_reset
,
5804 .slave_configure
= qla1280_slave_configure
,
5805 .bios_param
= qla1280_biosparam
,
5808 .sg_tablesize
= SG_ALL
,
5810 .use_clustering
= ENABLE_CLUSTERING
, \
5812 #include "scsi_module.c"
5814 /************************************************************************
5815 * qla1280_check_for_dead_scsi_bus *
5817 * This routine checks for a dead SCSI bus *
5818 ************************************************************************/
5819 #define SET_SXP_BANK 0x0100
5820 #define SCSI_PHASE_INVALID 0x87FF
5822 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host
*ha
, unsigned int bus
)
5824 uint16_t config_reg
, scsi_control
;
5825 struct device_reg
*reg
= ha
->iobase
;
5831 * If SCSI Bus is Dead because of bad termination,
5832 * we will return a status of Selection timeout.
5836 bus
= SCSI_BUS_32(cp
);
5838 if (ha
->bus_settings
[bus
].scsi_bus_dead
) {
5839 WRT_REG_WORD(®
->host_cmd
, HC_PAUSE_RISC
);
5840 config_reg
= RD_REG_WORD(®
->cfg_1
);
5841 WRT_REG_WORD(®
->cfg_1
, SET_SXP_BANK
);
5842 scsi_control
= RD_REG_WORD(®
->scsiControlPins
);
5843 WRT_REG_WORD(®
->cfg_1
, config_reg
);
5844 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
5846 if (scsi_control
== SCSI_PHASE_INVALID
) {
5847 ha
->bus_settings
[bus
].scsi_bus_dead
= TRUE
;
5849 CMD_RESULT(cp
) = DID_NO_CONNECT
<< 16;
5850 CMD_HANDLE(cp
) = NULL
;
5851 /* ha->actthreads--; */
5853 (*(cp
)->scsi_done
)(cp
);
5855 return TRUE
; /* bus is dead */
5857 ha
->bus_settings
[bus
].scsi_bus_dead
= FALSE
;
5858 ha
->bus_settings
[bus
].failed_reset_count
= 0;
5861 return FALSE
; /* bus is not dead */
5865 qla12160_get_target_parameters(struct scsi_qla_host
*ha
, uint32_t bus
,
5866 uint32_t target
, uint32_t lun
)
5868 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5870 mb
[0] = MBC_GET_TARGET_PARAMETERS
;
5871 mb
[1] = (uint16_t) (bus
? target
| BIT_7
: target
);
5873 qla1280_mailbox_command(ha
, BIT_6
| BIT_3
| BIT_2
| BIT_1
| BIT_0
,
5877 "scsi(%ld:%d:%d:%d): Synchronous transfer at period "
5878 "%d, offset %d. \n", ha
->host_no
, bus
, target
, lun
,
5879 (mb
[3] & 0xff), (mb
[3] >> 8));
5882 if ((mb
[2] & BIT_5
) && ((mb
[6] >> 8) & 0xff) >= 2) {
5884 "scsi(%ld:%d:%d:%d): Dual Transition enabled.\n",
5885 ha
->host_no
, bus
, target
, lun
);
5889 #ifdef QL_DEBUG_ROUTINES
5890 /****************************************************************************/
5891 /* Driver Debug Functions. */
5892 /****************************************************************************/
5895 * Get byte from I/O port
5898 qla1280_getbyte (u8
* port
)
5902 #if MEMORY_MAPPED_IO
5903 ret
= readb((unsigned long) port
);
5905 ret
= inb((unsigned long) port
);
5910 "qla1280_getbyte: address = 0x%p, data = 0x%x", port
,
5917 * Get word from I/O port
5920 qla1280_getword (u16
* port
)
5924 #if MEMORY_MAPPED_IO
5925 ret
= readw(unsigned long) port
;
5927 ret
= inw((unsigned long) port
);
5932 "qla1280_getbyte: address = 0x%p, data = 0x%x", port
,
5939 * Get double word from I/O port
5942 qla1280_getdword (u32
* port
)
5946 #if MEMORY_MAPPED_IO
5947 ret
= readl((unsigned long) port
);
5949 ret
= inl((unsigned long) port
);
5954 "qla1280_getbyte: address = 0x%p, data = 0x%x", port
,
5961 * Send byte to I/O port
5964 qla1280_putbyte(u8
* port
, u8 data
)
5966 #if MEMORY_MAPPED_IO
5967 writeb(data
, (unsigned long) port
);
5969 outb(data
, (unsigned long) port
);
5974 "qla1280_getbyte: address = 0x%p, data = 0x%x", port
,
5979 * Send word to I/O port
5982 qla1280_putword(u16
* port
, u16 data
)
5984 #if MEMORY_MAPPED_IO
5985 writew(data
, (unsigned long) port
);
5987 outw(data
, (unsigned long) port
);
5992 "qla1280_getbyte: address = 0x%p, data = 0x%x", port
,
5997 * Send double word to I/O port
6000 qla1280_putdword(u32
* port
, u32 data
)
6002 #if MEMORY_MAPPED_IO
6003 writel(data
, (unsigned long) port
);
6005 outl(data
, (unsigned long) port
);
6010 "qla1280_getbyte: address = 0x%p, data = 0x%x", port
,
6015 * Dummy function to prevent warnings for
6016 * declared and unused debug functions
6023 qla1280_getdword(0);
6024 qla1280_putbyte(0, 0);
6025 qla1280_putword(0, 0);
6026 qla1280_putdword(0, 0);
6030 __qla1280_dump_buffer(char *b
, int size
)
6035 if (ql_debug_print
) {
6037 " 0 1 2 3 4 5 6 7 8 9 Ah "
6038 "Bh Ch Dh Eh Fh\n");
6040 "---------------------------------------------"
6041 "------------------\n");
6043 for (cnt
= 0; cnt
< size
;) {
6061 /**************************************************************************
6062 * ql1280_print_scsi_cmd
6064 **************************************************************************/
6066 qla1280_print_scsi_cmd(Scsi_Cmnd
* cmd
)
6068 struct scsi_qla_host
*ha
;
6069 struct Scsi_Host
*host
= cmd
->host
;
6071 /* struct scatterlist *sg; */
6074 ha
= (struct scsi_qla_host
*)host
->hostdata
;
6076 sp
= (srb_t
*)CMD_SP(cmd
);
6077 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd
, CMD_HANDLE(cmd
));
6078 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
6079 cmd
->channel
, cmd
->target
, cmd
->lun
, cmd
->cmd_len
);
6081 for (i
= 0; i
< cmd
->cmd_len
; i
++) {
6082 printk("0x%02x ", cmd
->cmnd
[i
]);
6084 printk(" seg_cnt =%d\n", cmd
->use_sg
);
6085 printk(" request buffer=0x%p, request buffer len=0x%x\n",
6086 cmd
->request_buffer
, cmd
->request_bufflen
);
6089 sg = (struct scatterlist *) cmd->request_buffer;
6090 printk(" SG buffer: \n");
6091 qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
6093 printk(" tag=%d, flags=0x%x, transfersize=0x%x \n",
6094 cmd
->tag
, cmd
->flags
, cmd
->transfersize
);
6095 printk(" Pid=%li, SP=0x%p\n", cmd
->pid
, CMD_SP(cmd
));
6096 printk(" underflow size = 0x%x, direction=0x%x, req.cmd=0x%x \n",
6097 cmd
->underflow
, sp
->dir
, cmd
->request
->cmd
);
6100 /**************************************************************************
6101 * ql1280_dump_device
6103 **************************************************************************/
6105 ql1280_dump_device(struct scsi_qla_host
*ha
)
6111 if (ql_debug_print
) {
6112 printk(KERN_DEBUG
"Outstanding Commands on controller:\n");
6114 for (i
= 0; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
6115 if ((sp
= ha
->outstanding_cmds
[i
]) == NULL
)
6117 if ((cp
= sp
->cmd
) == NULL
)
6119 qla1280_print_scsi_cmd(1, cp
);
6126 /**************************************************************************
6129 **************************************************************************/
6131 qla1280_panic(char *cp
, struct Scsi_Host
*host
)
6133 struct scsi_qla_host
*ha
;
6136 ha
= (struct scsi_qla_host
*)host
->hostdata
;
6137 printk(KERN_ERR
"qla1280 - PANIC: %s\n", cp
);
6138 printk(KERN_ERR
"Current time=0x%lx\n", jiffies
);
6139 printk(KERN_ERR
"Number of pending commands =0x%lx\n", ha
->actthreads
);
6140 printk(KERN_ERR
"Number of SCSI queued commands =0x%lx\n",
6142 printk(KERN_ERR
"Number of free entries = (%d)\n", ha
->req_q_cnt
);
6143 printk(KERN_ERR
"Request Queue @ 0x%lx, Response Queue @ 0x%lx\n",
6144 ha
->request_dma
, ha
->response_dma
);
6145 printk(KERN_ERR
"Request In Ptr %d\n", ha
->req_ring_index
);
6146 fp
= (long *) &ha
->flags
;
6147 printk(KERN_ERR
"HA flags =0x%lx\n", *fp
);
6148 if (ql_debug_level
>= 2) {
6151 ql1280_dump_device((struct scsi_qla_host
*)host
->hostdata
);
6167 /**************************************************************************
6170 * Handle Linux boot parameters. This routine allows for assigning a value
6171 * to a parameter with a ':' between the parameter and the value.
6172 * ie. qla1280=max_reqs:0x0A,verbose
6173 **************************************************************************/
6175 qla1280_setup(char *s
, int *dummy
)
6177 char *end
, *str
, *cp
;
6179 printk(KERN_INFO
"scsi: Processing Option str = %s\n", s
);
6180 end
= strchr (s
, '\0');
6181 /* locate command */
6183 for (cp
= s
; *cp
&& cp
!= end
; cp
++) {
6184 cp
= qla1280_get_token(cp
, str
);
6185 printk(KERN_INFO
"scsi: token str = %s\n", str
);
6186 /* if found execute routine */
6191 qla1280_get_token(char *cmdline
, char *str
)
6193 register char *cp
= cmdline
;
6195 /* skip preceeding spaces */
6196 while (strchr (cp
, ' '))
6198 /* symbol starts here */
6200 /* skip char if not a space or : */
6201 while (*cp
&& !(strchr (cp
, ' ') || strchr (cp
, ':')))
6209 * Overrides for Emacs so that we almost follow Linus's tabbing style.
6210 * Emacs will notice this stuff at the end of the file and automatically
6211 * adjust the settings for this buffer only. This must remain at the end
6213 * ---------------------------------------------------------------------------