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