1 /********************************************************************************
2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP1x80/1x160 device driver for Linux 2.3.x (redhat 6.X).
6 * COPYRIGHT (C) 1999-2000 QLOGIC CORPORATION
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the Qlogic's Linux Software License. See below.
11 * This program is WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
18 * 1. Redistribution's or source code must retain the above copyright
19 * notice, this list of conditions, and the following disclaimer,
20 * without modification, immediately at the beginning of the file.
21 * 2. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
24 ********************************************************************************/
26 /*****************************************************************************************
27 QLOGIC CORPORATION SOFTWARE
28 "GNU" GENERAL PUBLIC LICENSE
29 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION
32 This GNU General Public License ("License") applies solely to QLogic Linux
33 Software ("Software") and may be distributed under the terms of this License.
35 1. You may copy and distribute verbatim copies of the Software's source code as
36 you receive it, in any medium, provided that you conspicuously and appropriately
37 publish on each copy an appropriate copyright notice and disclaimer of warranty;
38 keep intact all the notices that refer to this License and to the absence of any
39 warranty; and give any other recipients of the Software a copy of this License along
42 You may charge a fee for the physical act of transferring a copy, and you may at your
43 option offer warranty protection in exchange for a fee.
45 2. You may modify your copy or copies of the Software or any portion of it, thus forming
46 a work based on the Software, and copy and distribute such modifications or work under
47 the terms of Section 1 above, provided that you also meet all of these conditions:
49 * a) You must cause the modified files to carry prominent notices stating that you
50 changed the files and the date of any change.
52 * b) You must cause any work that you distribute or publish that in whole or in part
53 contains or is derived from the Software or any part thereof, to be licensed as a
54 whole at no charge to all third parties under the terms of this License.
56 * c) If the modified Software normally reads commands interactively when run, you
57 must cause it, when started running for such interactive use in the most ordinary way,
58 to print or display an announcement including an appropriate copyright notice and a
59 notice that there is no warranty (or else, saying that you provide a warranty) and that
60 users may redistribute the Software under these conditions, and telling the user how to
61 view a copy of this License. (Exception:if the Software itself is interactive but does
62 not normally print such an announcement, your work based on the Software is not required
63 to print an announcement.)
65 These requirements apply to the modified work as a whole. If identifiable sections of
66 that work are not derived from the Software, and can be reasonably considered independent
67 and separate works in themselves, then this License, and its terms, do not apply to those
68 sections when you distribute them as separate works. But when you distribute the same
69 sections as part of a whole which is a work based on the Software, the distribution of the
70 whole must be on the terms of this License, whose permissions for other licensees extend
71 to the entire whole, and thus to each and every part regardless of who wrote it.
73 3. You may copy and distribute the Software (or a work based on it, under Section 2) in
74 object code or executable form under the terms of Sections 1 and 2 above provided that
75 you also do one of the following:
77 * a) Accompany it with the complete corresponding machine-readable source code, which must
78 be distributed under the terms of Sections 1 and 2 above on a medium customarily used for
79 software interchange; or,
81 * b) Accompany it with a written offer, valid for at least three years, to give any third
82 party, for a charge no more than your cost of physically performing source distribution,
83 a complete machine-readable copy of the corresponding source code, to be distributed under
84 the terms of Sections 1 and 2 above on a medium customarily used for software interchange;
87 * c) Accompany it with the information you received as to the offer to distribute
88 corresponding source code. (This alternative is allowed only for noncommercial distribution
89 and only if you received the Software in object code or executable form with such an offer,
90 in accord with Subsection b above.)
92 The source code for a work means the preferred form of the work for making modifications
93 to it. For an executable work, complete source code means all the source code for all
94 modules it contains, plus any associated interface definition files, plus the scripts used
95 to control compilation and installation of the executable.
97 If distribution of executable or object code is made by offering access to copy from a
98 designated place, then offering equivalent access to copy the source code from the same
99 place counts as distribution of the source code, even though third parties are not
100 compelled to copy the source along with the object code.
102 4. You may not copy, modify, sublicense, or distribute the Software except as expressly
103 provided under this License. Any attempt otherwise to copy, modify, sublicense or
104 distribute the Software is void, and will automatically terminate your rights under this
105 License. However, parties who have received copies, or rights, from you under this License
106 will not have their licenses terminated so long as such parties remain in full compliance.
108 5. This license grants you world wide, royalty free non-exclusive rights to modify or
109 distribute the Software or its derivative works. These actions are prohibited by law
110 if you do not accept this License. Therefore, by modifying or distributing the Software
111 (or any work based on the Software), you indicate your acceptance of this License to do
112 so, and all its terms and conditions for copying, distributing or modifying the Software
113 or works based on it.
115 6. Each time you redistribute the Software (or any work based on the Software), the
116 recipient automatically receives a license from the original licensor to copy, distribute
117 or modify the Software subject to these terms and conditions. You may not impose any
118 further restrictions on the recipients' exercise of the rights granted herein. You are
119 not responsible for enforcing compliance by third parties to this License.
121 7. If, as a consequence of a court judgment or allegation of patent infringement or for
122 any other reason (not limited to patent issues), conditions are imposed on you
123 (whether by court order, agreement or otherwise) that contradict the conditions of this
124 License, they do not excuse you from the conditions of this License. If you cannot
125 distribute so as to satisfy simultaneously your obligations under this License
126 and any other pertinent obligations, then as a consequence you may not distribute the
129 If any portion of this section is held invalid or unenforceable under any particular
130 circumstance, the balance of the section is intended to apply and the section as a whole
131 is intended to apply in other circumstances.
134 11. THE SOFTWARE IS PROVIDED WITHOUT A WARRANTY OF ANY KIND. THERE IS NO
135 WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
136 EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
137 OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND,
138 EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
139 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
140 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU.
141 SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
142 NECESSARY SERVICING, REPAIR OR CORRECTION.
144 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
145 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
146 REDISTRIBUTE THE SOFTWARE AS PERMITTED ABOVE, BE LIABLE TO YOU FOR
147 DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
148 DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING
149 BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
150 LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO
151 OPERATE WITH ANY OTHER SOFTWARES), EVEN IF SUCH HOLDER OR OTHER PARTY HAS
152 BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
153 END OF TERMS AND CONDITIONS
155 *******************************************************************************************/
157 /****************************************************************************
159 Rev. 3.00 Jan 17, 1999 DG Qlogic
160 - Added 64-bit support.
161 Rev. 2.07 Nov 9, 1999 DG Qlogic
162 - Added new routine to set target parameters for ISP12160.
163 Rev. 2.06 Sept 10, 1999 DG Qlogic
164 - Added support for ISP12160 Ultra 3 chip.
165 Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
166 - Modified code to remove errors generated when compiling with
167 Cygnus IA64 Compiler.
168 - Changed conversion of pointers to unsigned longs instead of integers.
169 - Changed type of I/O port variables from uint32_t to unsigned long.
170 - Modified OFFSET macro to work with 64-bit as well as 32-bit.
171 - Changed sprintf and printk format specifiers for pointers to %p.
172 - Changed some int to long type casts where needed in sprintf & printk.
173 - Added l modifiers to sprintf and printk format specifiers for longs.
174 - Removed unused local variables.
175 Rev. 1.20 June 8, 1999 DG, Qlogic
176 Changes to support RedHat release 6.0 (kernel 2.2.5).
177 - Added SCSI exclusive access lock (io_request_lock) when accessing
179 - Added changes for the new LINUX interface template. Some new error
180 handling routines have been added to the template, but for now we
181 will use the old ones.
182 - Initial Beta Release.
183 *****************************************************************************/
187 #include <linux/module.h>
190 #define QLA1280_VERSION " 3.00-Beta"
195 #include <asm/segment.h>
196 #include <asm/byteorder.h>
197 #include <linux/version.h>
198 #include <linux/types.h>
199 #include <linux/string.h>
200 #include <linux/errno.h>
201 #include <linux/kernel.h>
202 #include <linux/ioport.h>
203 #include <linux/delay.h>
204 #include <linux/timer.h>
205 #include <linux/sched.h>
206 #include <linux/pci.h>
207 #include <linux/proc_fs.h>
208 #include <linux/blk.h>
209 #include <linux/tqueue.h>
210 /* MRS #include <linux/tasks.h> */
211 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
212 # include <linux/bios32.h>
217 #define UNIQUE_FW_NAME
219 #include "ql12160_fw.h" /* ISP RISC code */
220 #include "ql1280_fw.h"
222 #include <linux/stat.h>
223 #include <linux/malloc.h> /* for kmalloc() */
226 #ifndef KERNEL_VERSION
227 # define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
232 * Compile time Options:
233 * 0 - Disable and 1 - Enable
235 #define QLA1280_64BIT_SUPPORT 1 /* 64-bit Support */
236 #define QL1280_TARGET_MODE_SUPPORT 0 /* Target mode support */
237 #define WATCHDOGTIMER 0
238 #define MEMORY_MAPPED_IO 0
239 #define DEBUG_QLA1280_INTR 0
240 #define USE_NVRAM_DEFAULTS 0
241 #define DEBUG_PRINT_NVRAM 0
242 #define LOADING_RISC_ACTIVITY 0
243 #define AUTO_ESCALATE_RESET 0 /* Automatically escalate resets */
244 #define AUTO_ESCALATE_ABORT 0 /* Automatically escalate aborts */
245 #define STOP_ON_ERROR 0 /* Stop on aborts and resets */
246 #define STOP_ON_RESET 0
247 #define STOP_ON_ABORT 0
248 #undef DYNAMIC_MEM_ALLOC
250 #define DEBUG_QLA1280 0 /* Debugging */
251 /* #define CHECKSRBSIZE */
254 * These macros to assist programming
257 #define BZERO(ptr, amt) memset(ptr, 0, amt)
258 #define BCOPY(src, dst, amt) memcpy(dst, src, amt)
259 #define KMALLOC(siz) kmalloc((siz), GFP_ATOMIC)
260 #define KMFREE(ip,siz) kfree((ip))
261 #define SYS_DELAY(x) udelay(x);barrier()
262 #define QLA1280_DELAY(sec) mdelay(sec * 1000)
263 #define VIRT_TO_BUS(a) virt_to_bus((a))
264 #if QLA1280_64BIT_SUPPORT
265 #if BITS_PER_LONG <= 32
266 #define VIRT_TO_BUS_LOW(a) (uint32_t)virt_to_bus((a))
267 #define VIRT_TO_BUS_HIGH(a) (uint32_t)(0x0)
269 #define VIRT_TO_BUS_LOW(a) (uint32_t)(0xffffffff & virt_to_bus((a)))
270 #define VIRT_TO_BUS_HIGH(a) (uint32_t)(0xffffffff & (virt_to_bus((a))>>32))
272 #endif /* QLA1280_64BIT_SUPPORT */
276 #define NVRAM_DELAY() udelay(500) /* 2 microsecond delay */
277 void qla1280_device_queue_depth(scsi_qla_host_t
*, Scsi_Device
*);
279 #define CACHE_FLUSH(a) (RD_REG_WORD(a))
280 #define INVALID_HANDLE (MAX_OUTSTANDING_COMMANDS+1)
282 #define MSW(x) (uint16_t)((uint32_t)(x) >> 16)
283 #define LSW(x) (uint16_t)(x)
284 #define MSB(x) (uint8_t)((uint16_t)(x) >> 8)
285 #define LSB(x) (uint8_t)(x)
287 #if BITS_PER_LONG <= 32
288 #define LS_64BITS(x) (uint32_t)(x)
289 #define MS_64BITS(x) (uint32_t)(0x0)
291 #define LS_64BITS(x) (uint32_t)(0xffffffff & (x))
292 #define MS_64BITS(x) (uint32_t)(0xffffffff & ((x)>>32) )
296 * QLogic Driver Support Function Prototypes.
298 STATIC
void qla1280_done(scsi_qla_host_t
*, srb_t
**, srb_t
**);
299 STATIC
void qla1280_next(scsi_qla_host_t
*, scsi_lu_t
*, uint8_t);
300 STATIC
void qla1280_putq_t(scsi_lu_t
*, srb_t
*);
301 STATIC
void qla1280_done_q_put(srb_t
*, srb_t
**, srb_t
**);
302 STATIC
void qla1280_select_queue_depth(struct Scsi_Host
*, Scsi_Device
*);
303 #ifdef QLA1280_UNUSED
304 static void qla1280_dump_regs(struct Scsi_Host
*host
);
307 static void qla1280_panic(char *, struct Scsi_Host
*host
);
309 void qla1280_print_scsi_cmd(Scsi_Cmnd
*cmd
);
310 STATIC
void qla1280_abort_queue_single(scsi_qla_host_t
*,uint32_t,uint32_t,uint32_t,uint32_t);
312 STATIC
int qla1280_return_status( sts_entry_t
*sts
, Scsi_Cmnd
*cp
);
313 STATIC
void qla1280_removeq(scsi_lu_t
*q
, srb_t
*sp
);
314 STATIC
void qla1280_mem_free(scsi_qla_host_t
*ha
);
315 static void qla1280_do_dpc(void *p
);
316 #ifdef QLA1280_UNUSED
317 static void qla1280_set_flags(char * s
);
319 static char *qla1280_get_token(char *, char *);
320 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
321 STATIC
inline void mdelay(int);
323 static inline void qla1280_enable_intrs(scsi_qla_host_t
*);
324 static inline void qla1280_disable_intrs(scsi_qla_host_t
*);
327 * QLogic ISP1280 Hardware Support Function Prototypes.
329 STATIC
uint8_t qla1280_initialize_adapter(struct scsi_qla_host
*ha
);
330 STATIC
uint8_t qla1280_enable_tgt(scsi_qla_host_t
*, uint8_t);
331 STATIC
uint8_t qla1280_isp_firmware(scsi_qla_host_t
*);
332 STATIC
uint8_t qla1280_pci_config(scsi_qla_host_t
*);
333 STATIC
uint8_t qla1280_chip_diag(scsi_qla_host_t
*);
334 STATIC
uint8_t qla1280_setup_chip(scsi_qla_host_t
*);
335 STATIC
uint8_t qla1280_init_rings(scsi_qla_host_t
*);
336 STATIC
uint8_t qla1280_nvram_config(scsi_qla_host_t
*);
337 STATIC
uint8_t qla1280_mailbox_command(scsi_qla_host_t
*, uint8_t, uint16_t *);
338 STATIC
uint8_t qla1280_bus_reset(scsi_qla_host_t
*, uint8_t);
339 STATIC
uint8_t qla1280_device_reset(scsi_qla_host_t
*, uint8_t, uint32_t);
340 STATIC
uint8_t qla1280_abort_device(scsi_qla_host_t
*, uint8_t, uint32_t, uint32_t);
341 STATIC
uint8_t qla1280_abort_command(scsi_qla_host_t
*, srb_t
*),
342 #if QLA1280_64BIT_SUPPORT
343 qla1280_64bit_start_scsi(scsi_qla_host_t
*, srb_t
*),
345 qla1280_32bit_start_scsi(scsi_qla_host_t
*, srb_t
*),
346 qla1280_abort_isp(scsi_qla_host_t
*);
347 STATIC
void qla1280_nv_write(scsi_qla_host_t
*, uint16_t),
348 qla1280_nv_delay(scsi_qla_host_t
*),
349 qla1280_poll(scsi_qla_host_t
*),
350 qla1280_reset_adapter(scsi_qla_host_t
*),
351 qla1280_marker(scsi_qla_host_t
*, uint8_t, uint32_t, uint32_t, uint8_t),
352 qla1280_isp_cmd(scsi_qla_host_t
*),
353 qla1280_isr(scsi_qla_host_t
*, srb_t
**, srb_t
**),
354 qla1280_rst_aen(scsi_qla_host_t
*),
355 qla1280_status_entry(scsi_qla_host_t
*, sts_entry_t
*, srb_t
**,
357 qla1280_error_entry(scsi_qla_host_t
*, response_t
*, srb_t
**,
359 qla1280_restart_queues(scsi_qla_host_t
*),
360 qla1280_abort_queues(scsi_qla_host_t
*);
361 STATIC
uint16_t qla1280_get_nvram_word(scsi_qla_host_t
*, uint32_t),
362 qla1280_nvram_request(scsi_qla_host_t
*, uint32_t),
363 qla1280_debounce_register(volatile uint16_t *);
364 STATIC request_t
*qla1280_req_pkt(scsi_qla_host_t
*);
365 int qla1280_check_for_dead_scsi_bus(scsi_qla_host_t
*ha
, srb_t
*sp
);
366 STATIC
uint8_t qla1280_mem_alloc(scsi_qla_host_t
*ha
);
367 STATIC
uint8_t qla1280_register_with_Linux(scsi_qla_host_t
*ha
, uint8_t maxchannels
);
369 STATIC
uint8_t qla12160_set_target_parameters(scsi_qla_host_t
*, uint32_t, uint32_t, uint32_t, nvram160_t
*);
370 STATIC
void qla12160_get_target_parameters(scsi_qla_host_t
*, uint32_t, uint32_t, uint32_t);
372 #if QL1280_TARGET_MODE_SUPPORT
373 STATIC
void qla1280_enable_lun(scsi_qla_host_t
*, uint8_t, uint32_t),
374 qla1280_notify_ack(scsi_qla_host_t
*, notify_entry_t
*),
375 qla1280_immed_notify(scsi_qla_host_t
*, notify_entry_t
*),
376 qla1280_accept_io(scsi_qla_host_t
*, ctio_ret_entry_t
*),
377 #if QLA1280_64BIT_SUPPORT
378 qla1280_64bit_continue_io(scsi_qla_host_t
*, atio_entry_t
*, uint32_t,
381 qla1280_32bit_continue_io(scsi_qla_host_t
*, atio_entry_t
*, uint32_t,
383 qla1280_atio_entry(scsi_qla_host_t
*, atio_entry_t
*),
384 qla1280_notify_entry(scsi_qla_host_t
*, notify_entry_t
*);
385 #endif /* QLA1280_TARGET_MODE_SUPPORT */
387 #ifdef QL_DEBUG_ROUTINES
389 * Driver Debug Function Prototypes.
391 STATIC
uint8_t qla1280_getbyte(uint8_t *);
392 STATIC
uint16_t qla1280_getword(uint16_t *);
393 STATIC
uint32_t qla1280_getdword(uint32_t *);
394 STATIC
void qla1280_putbyte(uint8_t *, uint8_t),
395 qla1280_putword(uint16_t *, uint16_t),
396 qla1280_putdword(uint32_t *, uint32_t),
397 qla1280_print(caddr_t
),
398 qla1280_output_number(uint32_t, uint8_t),
399 qla1280_putc(uint8_t),
400 qla1280_dump_buffer(caddr_t
, uint32_t);
404 STATIC
uint8_t ql_debug_print
= 1;
406 STATIC
uint8_t ql_debug_print
= 0;
411 * insmod needs to find the variable and make it point to something
414 static char *options
= NULL
;
415 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,18)
417 /* insmod qla1280 options=verbose" */
418 MODULE_PARM(options
, "s");
421 * Just in case someone uses commas to separate items on the insmod
422 * command line, we define a dummy buffer here to avoid having insmod
423 * write wild stuff into our code segment
425 static char dummy_buffer
[60] = "Please don't add commas in your insmod command!!\n";
429 /* We use the Scsi_Pointer structure that's included with each command
430 * SCSI_Cmnd as a scratchpad for our SRB.
432 * SCp will always point to the SRB structure (defined in qla1280.h).
433 * It is define as follows:
434 * - SCp.ptr -- > pointer back to the cmd
435 * - SCp.this_residual --> used as forward pointer to next srb
436 * - SCp.buffer --> used as backward pointer to next srb
437 * - SCp.buffers_residual --> used as flags field
438 * - SCp.have_data_in --> not used
439 * - SCp.sent_command --> not used
440 * - SCp.phase --> not used
443 #define CMD_SP(Cmnd) (&(Cmnd)->SCp)
444 #define CMD_XFRLEN(Cmnd) (Cmnd)->request_bufflen
445 #define CMD_CDBLEN(Cmnd) (Cmnd)->cmd_len
446 #define CMD_CDBP(Cmnd) (Cmnd)->cmnd
447 #define CMD_SNSP(Cmnd) (Cmnd)->sense_buffer
448 #define CMD_SNSLEN(Cmnd) (sizeof (Cmnd)->sense_buffer)
449 #define CMD_RESULT(Cmnd) ((Cmnd)->result)
450 #define CMD_HANDLE(Cmnd) ((Cmnd)->host_scribble)
452 /*****************************************/
453 /* ISP Boards supported by this driver */
454 /*****************************************/
455 #define QLA1280_VENDOR_ID 0x1077
456 #define QLA1080_DEVICE_ID 0x1080
457 #define QLA1240_DEVICE_ID 0x1240
458 #define QLA1280_DEVICE_ID 0x1280
459 #define QLA12160_DEVICE_ID 0x1216
460 #define QLA10160_DEVICE_ID 0x1016
461 #define NUM_OF_ISP_DEVICES 6
463 typedef struct _qlaboards
465 unsigned char bdName
[9]; /* Board ID String */
466 unsigned long device_id
; /* Device PCI ID */
467 int numPorts
; /* Number of SCSI ports */
468 unsigned short *fwcode
; /* pointer to FW array */
469 unsigned long *fwlen
; /* number of words in array */
470 unsigned short *fwstart
; /* start address for F/W */
471 unsigned char *fwver
; /* Ptr to F/W version array */
474 struct _qlaboards QLBoardTbl
[NUM_OF_ISP_DEVICES
] =
476 /* Name , Board PCI Device ID, Number of ports */
477 {"QLA1080 ", QLA1080_DEVICE_ID
, 1,
478 &fw1280ei_code01
[0], (unsigned long *)&fw1280ei_length01
,&fw1280ei_addr01
, &fw1280ei_version_str
[0] },
479 {"QLA1240 ", QLA1240_DEVICE_ID
, 2,
480 &fw1280ei_code01
[0], (unsigned long *)&fw1280ei_length01
,&fw1280ei_addr01
, &fw1280ei_version_str
[0] },
481 {"QLA1280 ", QLA1280_DEVICE_ID
, 2,
482 &fw1280ei_code01
[0], (unsigned long *)&fw1280ei_length01
,&fw1280ei_addr01
, &fw1280ei_version_str
[0] },
483 {"QLA12160 ", QLA12160_DEVICE_ID
, 2,
484 &fw12160i_code01
[0], (unsigned long *)&fw12160i_length01
,&fw12160i_addr01
, &fw12160i_version_str
[0] },
485 {"QLA10160 ", QLA10160_DEVICE_ID
, 1,
486 &fw12160i_code01
[0], (unsigned long *)&fw12160i_length01
,&fw12160i_addr01
, &fw12160i_version_str
[0] },
490 static unsigned long qla1280_verbose
= 1L;
491 static scsi_qla_host_t
*qla1280_hostlist
= NULL
;
492 #ifdef QLA1280_PROFILE
493 static int qla1280_buffer_size
= 0;
494 static char *qla1280_buffer
= NULL
;
497 #ifdef QL_DEBUG_LEVEL_3
498 #define ENTER(x) sprintf(debug_buff,"qla1280 : Entering %s()\n\r", x); \
499 qla1280_print(debug_buff);
500 #define LEAVE(x) sprintf(debug_buff,"qla1280 : Leaving %s()\n\r", x); \
501 qla1280_print(debug_buff);
502 #define ENTER_INTR(x) sprintf(debug_buff,"qla1280 : Entering %s()\n\r", x); \
503 qla1280_print(debug_buff);
504 #define LEAVE_INTR(x) sprintf(debug_buff,"qla1280 : Leaving %s()\n\r", x); \
505 qla1280_print(debug_buff);
510 #define ENTER_INTR(x)
511 #define LEAVE_INTR(x)
517 /* #define COMTRACE(x) qla1280_putc(x); */
524 #ifdef QL_DEBUG_LEVEL_2
531 #if (BITS_PER_LONG==64)
532 # define OFFSET(w) (((uint64_t) &w) & 0xFF) /* 256 byte offsets */
534 # define OFFSET(w) (((uint32_t) &w) & 0xFF) /* 256 byte offsets */
537 #define SCSI_BUS_32(scp) ((scp)->channel)
538 #define SCSI_TCN_32(scp) ((scp)->target)
539 #define SCSI_LUN_32(scp) ((scp)->lun)
541 /****************************************************************************/
542 /* LINUX - Loadable Module Functions. */
543 /****************************************************************************/
546 /*************************************************************************
550 * Set parameters for the driver from the /proc filesystem.
553 *************************************************************************/
555 qla1280_set_info(char *buffer
, int length
, struct Scsi_Host
*HBAptr
)
557 return (-ENOSYS
); /* Currently this is a no-op */
560 /*************************************************************************
564 * Return information to handle /proc support for the driver.
566 * buffer - ptrs to a page buffer
569 *************************************************************************/
570 #ifdef QLA1280_PROFILE
571 #define PROC_BUF (&qla1280_buffer[size])
572 #define LUN_ID (targ_lun>>(MAX_T_BITS+MAX_L_BITS)),((targ_lun>>MAX_L_BITS)&0xf), targ_lun&0x7
575 qla1280_proc_info ( char *buffer
, char **start
, off_t offset
, int length
,
576 int hostno
, int inout
)
578 #ifdef QLA1280_PROFILE
579 struct Scsi_Host
*host
;
586 printk("Entering proc_info 0x%p,0x%lx,0x%x,0x%x\n",buffer
,offset
,length
,hostno
);
588 /* find the host they want to look at */
589 for(ha
=qla1280_hostlist
; (ha
!= NULL
) && ha
->host
->host_no
!= hostno
; ha
=ha
->next
)
594 size
+= sprintf(buffer
, "Can't find adapter for host number %d\n", hostno
);
606 if (inout
== TRUE
) /* Has data been written to the file? */
608 return (qla1280_set_info(buffer
, length
, host
));
611 /* compute number of active devices */
613 for (targ_lun
= 0; targ_lun
< MAX_EQ
; targ_lun
++)
615 if( (up
= ha
->dev
[targ_lun
]) == NULL
)
619 /* size = 112 * no_devices; */
621 /* round up to the next page */
624 * if our old buffer is the right size use it otherwise
625 * allocate a new one.
627 if (qla1280_buffer_size
!= size
)
629 /* deallocate this buffer and get a new one */
630 if (qla1280_buffer
!= NULL
)
632 kfree(qla1280_buffer
);
633 qla1280_buffer_size
= 0;
635 qla1280_buffer
= kmalloc(size
, GFP_KERNEL
);
637 if (qla1280_buffer
== NULL
)
639 size
= sprintf(buffer
, "qla1280 - kmalloc error at line %d\n",
643 qla1280_buffer_size
= size
;
646 size
+= sprintf(PROC_BUF
, "Qlogic 1280/1080 SCSI driver version: "); /* 43 bytes */
647 size
+= sprintf(PROC_BUF
, "%5s, ", QLA1280_VERSION
); /* 5 */
648 size
+= sprintf(PROC_BUF
, "Qlogic Firmware version: "); /* 25 */
649 size
+= sprintf(PROC_BUF
, "%2d.%2d.%2d",_firmware_version
[0], /* 8 */
650 ql12_firmware_version
[1],
651 ql12_firmware_version
[2]);
652 size
+= sprintf(PROC_BUF
, "\n"); /* 1 */
654 size
+= sprintf(PROC_BUF
, "SCSI Host Adapter Information: %s\n", QLBoardTbl
[ha
->devnum
].bdName
);
655 size
+= sprintf(PROC_BUF
, "Request Queue = 0x%lx, Response Queue = 0x%lx\n",
658 size
+= sprintf(PROC_BUF
, "Request Queue count= 0x%x, Response Queue count= 0x%x\n",
661 size
+= sprintf(PROC_BUF
,"Number of pending commands = 0x%lx\n", ha
->actthreads
);
662 size
+= sprintf(PROC_BUF
,"Number of queued commands = 0x%lx\n", ha
->qthreads
);
663 size
+= sprintf(PROC_BUF
,"Number of free request entries = %d\n",ha
->req_q_cnt
);
664 size
+= sprintf(PROC_BUF
, "\n"); /* 1 */
666 size
+= sprintf(PROC_BUF
, "Attached devices:\n");
667 /* scan for all equipment stats */
668 for (targ_lun
= 0; targ_lun
< MAX_EQ
; targ_lun
++)
670 if( (up
= ha
->dev
[targ_lun
]) == NULL
)
672 if( up
->io_cnt
== 0 )
674 size
+= sprintf(PROC_BUF
,"(%2d:%2d:%2d) No stats\n",LUN_ID
);
677 /* total reads since boot */
678 /* total writes since boot */
679 /* total requests since boot */
680 size
+= sprintf(PROC_BUF
, "Total requests %ld,",up
->io_cnt
);
681 /* current number of pending requests */
682 size
+= sprintf(PROC_BUF
, "(%2d:%2d:%2d) pending requests %d,",LUN_ID
,up
->q_outcnt
);
683 /* avg response time */
684 size
+= sprintf(PROC_BUF
, "Avg response time %ld%%,",(up
->resp_time
/up
->io_cnt
)*100);
686 /* avg active time */
687 size
+= sprintf(PROC_BUF
, "Avg active time %ld%%\n",(up
->act_time
/up
->io_cnt
)*100);
690 if (size
>= qla1280_buffer_size
)
692 printk(KERN_WARNING
"qla1280: Overflow buffer in qla1280_proc.c\n");
695 if (offset
> size
- 1)
697 kfree(qla1280_buffer
);
698 qla1280_buffer
= NULL
;
699 qla1280_buffer_size
= length
= 0;
704 *start
= &qla1280_buffer
[offset
]; /* Start of wanted data */
705 if (size
- offset
< length
)
707 length
= size
- offset
;
716 /**************************************************************************
718 * This routine will probe for Qlogic 1280 SCSI host adapters.
719 * It returns the number of host adapters of a particular
720 * type that were found. It also initialize all data necessary for
721 * the driver. It is passed-in the host number, so that it
722 * knows where its first entry is in the scsi_hosts[] array.
725 * template - pointer to SCSI template
728 * num - number of host adapters found.
729 **************************************************************************/
731 qla1280_detect(Scsi_Host_Template
*template)
734 struct Scsi_Host
*host
;
735 scsi_qla_host_t
*ha
, *cur_ha
;
736 struct _qlaboards
*bdp
;
738 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,1,95)
739 unsigned int piobase
;
740 unsigned char pci_bus
, pci_devfn
, pci_irq
;
741 config_reg_t
*cfgp
= 0;
745 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
746 struct pci_dev
*pdev
= NULL
;
751 ENTER("qla1280_detect");
754 if (sizeof(srb_t
) > sizeof(Scsi_Pointer
) )
756 printk("Redefine SRB - its too big");
762 DEBUG(sprintf(debug_buff
,"DEBUG: qla1280_detect starts at address = %p\n",qla1280_detect
);)
763 DEBUG(qla1280_print(debug_buff
);)
765 * If we are called as a module, the qla1280 pointer may not be null
766 * and it would point to our bootup string, just like on the lilo
767 * command line. IF not NULL, then process this config string with
771 * To add options at boot time add a line to your lilo.conf file like:
772 * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
773 * which will result in the first four devices on the first two
774 * controllers being set to a tagged queue depth of 32.
777 qla1280_setup(options
, NULL
);
778 if(dummy_buffer
[0] != 'P')
779 printk(KERN_WARNING
"qla1280: Please read the file /usr/src/linux/drivers"
780 "/scsi/README.qla1280\n"
781 "qla1280: to see the proper way to specify options to the qla1280 "
783 "qla1280: Specifically, don't use any commas when passing arguments to\n"
784 "qla1280: insmod or else it might trash certain memory areas.\n");
787 if ((int) !pcibios_present())
789 printk("scsi: PCI not present\n");
792 bdp
= &QLBoardTbl
[0];
793 qla1280_hostlist
= NULL
;
795 template->proc_dir
= &proc_scsi_qla1280
;
797 template->proc_name
= "qla1280";
800 /* Try and find each different type of adapter we support */
801 for( i
=0; bdp
->device_id
!= 0 && i
< NUM_OF_ISP_DEVICES
; i
++, bdp
++ ) {
802 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
803 while ((pdev
= pci_find_device(QLA1280_VENDOR_ID
,
804 bdp
->device_id
, pdev
) )) {
805 if (pci_enable_device(pdev
)) continue;
807 while (!(pcibios_find_device(QLA1280_VENDOR_ID
,
809 index
++, &pci_bus
, &pci_devfn
)) ) {
811 /* found a adapter */
812 host
= scsi_register(template, sizeof(scsi_qla_host_t
));
813 ha
= (scsi_qla_host_t
*) host
->hostdata
;
814 /* Clear our data area */
815 for( j
=0, cp
= (char *)ha
; j
< sizeof(scsi_qla_host_t
); j
++)
817 /* Sanitize the information from PCI BIOS. */
818 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
819 host
->irq
= pdev
->irq
;
820 host
->io_port
= pci_resource_start(pdev
, 0);
821 ha
->pci_bus
= pdev
->bus
->number
;
822 ha
->pci_device_fn
= pdev
->devfn
;
825 pcibios_read_config_byte(pci_bus
, pci_devfn
, OFFSET(cfgp
->interrupt_line
), &pci_irq
);
826 pcibios_read_config_dword(pci_bus
, pci_devfn
, OFFSET(cfgp
->base_port
), &piobase
);
828 host
->io_port
= (unsigned int) piobase
;
829 host
->io_port
&= PCI_BASE_ADDRESS_IO_MASK
;
830 ha
->pci_bus
= pci_bus
;
831 ha
->pci_device_fn
= pci_devfn
;
833 ha
->device_id
= bdp
->device_id
;
836 if( qla1280_mem_alloc(ha
) ) {
837 printk(KERN_INFO
"qla1280: Failed to allocate memory for adapter\n");
840 ha
->ports
= bdp
->numPorts
;
841 ha
->iobase
= (device_reg_t
*) host
->io_port
;
843 ha
->host_no
= host
->host_no
;
845 /* load the F/W, read paramaters, and init the H/W */
846 if (qla1280_initialize_adapter(ha
))
849 printk(KERN_INFO
"qla1280: Failed to initialized adapter\n");
850 qla1280_mem_free(ha
);
851 scsi_unregister(host
);
855 host
->max_channel
= bdp
->numPorts
-1;
856 ha
->instance
= num_hosts
;
857 /* Register our resources with Linux */
858 if( qla1280_register_with_Linux(ha
, bdp
->numPorts
-1) ) {
859 printk(KERN_INFO
"qla1280: Failed to register our resources\n");
860 qla1280_mem_free(ha
);
861 scsi_unregister(host
);
867 /* Disable ISP interrupts. */
868 qla1280_disable_intrs(ha
);
870 /* Insure mailbox registers are free. */
871 WRT_REG_WORD(®
->semaphore
, 0);
872 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
873 WRT_REG_WORD(®
->host_cmd
, HC_CLR_HOST_INT
);
875 /* Enable chip interrupts. */
876 qla1280_enable_intrs(ha
);
878 /* Insert new entry into the list of adapters */
880 if( qla1280_hostlist
== NULL
)
882 cur_ha
= qla1280_hostlist
= ha
;
886 cur_ha
= qla1280_hostlist
;
887 while( cur_ha
->next
!= NULL
)
888 cur_ha
= cur_ha
->next
;
895 LEAVE("qla1280_detect");
899 /**************************************************************************
900 * qla1280_register_with_Linux
903 * Free the passed in Scsi_Host memory structures prior to unloading the
907 * ha - pointer to host adapter structure
908 * maxchannels - MAX number of channels.
911 * 0 - Sucessfully reserved resources.
912 * 1 - Failed to reserved a resource.
913 **************************************************************************/
914 STATIC
uint8_t qla1280_register_with_Linux(scsi_qla_host_t
*ha
, uint8_t maxchannels
)
917 struct Scsi_Host
*host
= ha
->host
;
919 host
->can_queue
= 0xfffff; /* unlimited */
920 host
->cmd_per_lun
= 1;
921 host
->select_queue_depths
= qla1280_select_queue_depth
;
922 host
->n_io_port
= 0xFF;
923 host
->base
= (unsigned long) ha
->mmpbase
;
924 host
->max_channel
= maxchannels
;
925 host
->max_lun
= MAX_LUNS
-1;
926 host
->unique_id
= ha
->instance
;
927 host
->max_id
= MAX_TARGETS
;
928 host
->unique_id
= ha
->instance
;
930 /* set our host ID (need to do something about our two IDs) */
931 host
->this_id
= ha
->bus_settings
[0].id
;
932 /* Register the IRQ with Linux (sharable) */
933 if ( request_irq(host
->irq
, qla1280_intr_handler
, SA_INTERRUPT
| SA_SHIRQ
, "qla1280", ha
))
935 printk("qla1280 : Failed to reserved interrupt %d already in use\n", host
->irq
);
936 qla1280_mem_free(ha
);
937 scsi_unregister(host
);
941 /* Register the I/O space with Linux */
942 if (check_region(host
->io_port
, 0xff))
944 printk("qla1280 : Failed to reserved i/o region 0x%04lx-0x%04lx already in use\n",
945 host
->io_port
, host
->io_port
+ 0xff);
946 free_irq(host
->irq
, NULL
);
947 qla1280_mem_free(ha
);
948 scsi_unregister(host
);
952 request_region(host
->io_port
, 0xff, "qla1280");
958 /**************************************************************************
960 * Free the passed in Scsi_Host memory structures prior to unloading the
962 **************************************************************************/
964 qla1280_release(struct Scsi_Host
*host
)
966 scsi_qla_host_t
*ha
= (scsi_qla_host_t
*) host
->hostdata
;
968 ENTER("qla1280_release");
970 if( !ha
->flags
.online
)
973 /* turn-off interrupts on the card */
974 WRT_REG_WORD(&ha
->iobase
->ictrl
, 0);
976 /* Detach interrupts */
978 free_irq(host
->irq
, ha
);
980 /* release io space registers */
982 release_region(host
->io_port
, 0xff);
987 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
988 vfree((void *) (((unsigned long) ha
->mmpbase
) & PAGE_MASK
));
990 iounmap((void *) (((unsigned long) ha
->mmpbase
) & PAGE_MASK
));
993 #endif /* MEMORY_MAPPED_IO */
994 qla1280_mem_free(ha
);
996 ENTER("qla1280_release");
1000 /**************************************************************************
1002 * Return a string describing the driver.
1003 **************************************************************************/
1005 qla1280_info(struct Scsi_Host
*host
)
1007 static char qla1280_buffer
[125];
1009 scsi_qla_host_t
*ha
;
1012 bp
= &qla1280_buffer
[0];
1013 ha
= (scsi_qla_host_t
*)host
->hostdata
;
1014 bdp
= &QLBoardTbl
[ha
->devnum
];
1015 memset(bp
, 0, sizeof(qla1280_buffer
));
1017 "QLogic %sPCI to SCSI Host Adapter: bus %d device %d irq %d\n"
1018 " Firmware version: %2d.%02d.%02d, Driver version %s",
1019 (char *)&bdp
->bdName
[0], ha
->pci_bus
, (ha
->pci_device_fn
& 0xf8) >> 3, host
->irq
,
1020 bdp
->fwver
[0],bdp
->fwver
[1],bdp
->fwver
[2],
1025 /**************************************************************************
1026 * qla1200_queuecommand
1027 * Queue a command to the controller.
1030 * The mid-level driver tries to ensures that queuecommand never gets invoked
1031 * concurrently with itself or the interrupt handler (although the
1032 * interrupt handler may call this routine as part of request-completion
1033 * handling). Unfortunely, it sometimes calls the scheduler in interrupt
1034 * context which is a big NO! NO!.
1035 **************************************************************************/
1037 qla1280_queuecommand(Scsi_Cmnd
*cmd
, void (*fn
)(Scsi_Cmnd
*))
1039 scsi_qla_host_t
*ha
;
1041 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1042 unsigned long cpu_flags
= 0;
1044 struct Scsi_Host
*host
;
1049 ENTER("qla1280_queuecommand");
1053 ha
= (scsi_qla_host_t
*) host
->hostdata
;
1055 /* send command to adapter */
1056 sp
= (srb_t
*) CMD_SP(cmd
);
1058 cmd
->scsi_done
= fn
;
1059 if (cmd
->flags
== 0) /* new command */
1064 DEBUG5(qla1280_print_scsi_cmd(cmd
));
1066 /* Generate LU queue on bus, target, LUN */
1067 b
= SCSI_BUS_32(cmd
);
1068 t
= SCSI_TCN_32(cmd
);
1069 l
= SCSI_LUN_32(cmd
);
1070 if((q
= LU_Q(ha
, b
, t
, l
)) == NULL
)
1073 if( (q
= (scsi_lu_t
*)KMALLOC(sizeof(struct scsi_lu
))) )
1075 LU_Q(ha
, b
, t
, l
) = q
;
1076 BZERO(q
,sizeof(struct scsi_lu
));
1077 DEBUG(sprintf(debug_buff
,"Allocate new device queue 0x%x\n",q
));
1078 DEBUG(qla1280_print(debug_buff
));
1083 CMD_RESULT(cmd
) = (int) (DID_BUS_BUSY
<< 16);
1084 qla1280_done_q_put(sp
, &ha
->done_q_first
, &ha
->done_q_last
);
1086 schedule_task(&ha
->run_qla_bh
);
1087 ha
->flags
.dpc_sched
= TRUE
;
1092 /* Set an invalid handle until we issue the command to ISP */
1093 /* then we will set the real handle value. */
1094 handle
= INVALID_HANDLE
;
1095 CMD_HANDLE(cmd
) = (unsigned char *)handle
;
1097 /* Bookkeeping information */
1098 sp
->r_start
= jiffies
; /* time the request was recieved */
1101 /* add the command to our queue */
1103 qla1280_putq_t(q
,sp
);
1105 DEBUG(sprintf(debug_buff
,"qla1280_queuecmd: queue pid=%d, hndl=0x%x\n\r",cmd
->pid
,handle
));
1106 DEBUG(qla1280_print(debug_buff
));
1108 /* send command to adapter */
1110 if (q
->q_outcnt
== 0)
1111 qla1280_restart_queues(ha
);
1115 LEAVE("qla1280_queuecommand");
1119 /**************************************************************************
1121 * Abort the speciifed SCSI command(s).
1122 **************************************************************************/
1124 qla1280_abort(Scsi_Cmnd
*cmd
)
1126 scsi_qla_host_t
*ha
;
1128 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1129 unsigned long cpu_flags
= 0;
1131 struct Scsi_Host
*host
;
1134 int return_status
= SCSI_ABORT_SUCCESS
;
1140 ENTER("qla1280_abort");
1142 ha
= (scsi_qla_host_t
*) cmd
->host
->hostdata
;
1146 /* Get the SCSI request ptr */
1147 sp
= (srb_t
*) CMD_SP(cmd
);
1148 handle
= (u_long
) CMD_HANDLE(cmd
);
1149 if (qla1280_verbose
)
1150 printk("scsi(%d): ABORT Command=0x%lx, handle=0x%lx\n",(int)ha
->host_no
,(long)cmd
,handle
);
1152 /* Check for pending interrupts. */
1156 /* we never got this command */
1157 printk(KERN_INFO
"qla1280: Aborting a NULL handle\n");
1159 return(SCSI_ABORT_NOT_RUNNING
); /* no action - we don't have command */
1161 data
= qla1280_debounce_register(&ha
->iobase
->istatus
);
1162 if( !(ha
->flags
.in_isr
) && (data
& RISC_INT
) )
1164 /* put any pending command in done queue */
1165 qla1280_isr(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1168 handle
= (u_long
) CMD_HANDLE(cmd
);
1170 /* Generate LU queue on bus, target, LUN */
1171 b
= SCSI_BUS_32(cmd
);
1172 t
= SCSI_TCN_32(cmd
);
1173 l
= SCSI_LUN_32(cmd
);
1174 if((q
= LU_Q(ha
, b
, t
, l
)) == NULL
)
1177 /* No lun queue -- command must not be active */
1179 printk(KERN_WARNING
"qla1280 (%d:%d:%d): No LUN queue for the specified device\n",(int)b
,(int)t
,(int)l
);
1180 return(SCSI_ABORT_NOT_RUNNING
); /* no action - we don't have command */
1183 #if AUTO_ESCALATE_ABORT
1184 if ( (sp
->flags
& SRB_ABORTED
) )
1187 DEBUG(qla1280_print("qla1280_abort: Abort escalayted - returning SCSI_ABORT_SNOOZE.\n\r"));
1188 return(SCSI_ABORT_SNOOZE
);
1192 if ( (sp
->flags
& SRB_ABORT_PENDING
) )
1196 if( qla1280_verbose
)
1197 printk("scsi(): Command has a pending abort message - ABORT_PENDING.\n");
1198 DEBUG(qla1280_print("qla1280: Command has a pending abort message - ABORT_PENDING.\n\r"));
1199 return(SCSI_ABORT_PENDING
);
1203 printk("Scsi layer issued a ABORT command= 0x%x\n",(int)cmd
);
1204 DEBUG2(qla1280_print_scsi_cmd(cmd
));
1207 ha
->flags
.in_abort
= TRUE
;
1209 * Normally, would would need to search our queue for the specified command
1210 * but; since our sp contains the cmd ptr, we can just remove it from our
1213 if( !(sp
->flags
&SRB_SENT
) )
1216 if( qla1280_verbose
)
1217 printk("scsi(): Command returned from queue aborted.\n");
1218 DEBUG(qla1280_print("qla1280: Command returned from queue aborted.\n\r"));
1219 /* Remove srb from SCSI LU queue. */
1220 qla1280_removeq(q
, sp
);
1221 sp
->flags
|= SRB_ABORTED
;
1222 CMD_RESULT(cmd
) = DID_ABORT
<< 16;
1223 qla1280_done_q_put(sp
, &ha
->done_q_first
, &ha
->done_q_last
);
1224 return_status
= SCSI_ABORT_SUCCESS
;
1227 { /* find the command in our active list */
1228 for (i
= 1; i
< MAX_OUTSTANDING_COMMANDS
; i
++)
1230 if( sp
== ha
->outstanding_cmds
[i
] )
1233 DEBUG(qla1280_print("qla1280: RISC aborting command.\n\r"));
1234 qla1280_abort_command(ha
,sp
);
1235 return_status
= SCSI_ABORT_PENDING
;
1242 qla1280_panic("qla1280_abort",ha
->host
);
1245 return_status
= SCSI_ABORT_NOT_RUNNING
; /* no action - we don't have command */
1247 DEBUG(sprintf(debug_buff
, "qla1280_abort: Aborted status returned = 0x%x.\n\r",return_status
));
1248 DEBUG(qla1280_print(debug_buff
));
1250 if( ha
->done_q_first
)
1251 qla1280_done(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1254 qla1280_restart_queues(ha
);
1256 ha
->flags
.in_abort
= FALSE
;
1259 LEAVE("qla1280_abort");
1261 return(return_status
);
1264 /**************************************************************************
1266 * The reset function will reset the SCSI bus and abort any executing
1270 * cmd = Linux SCSI command packet of the command that cause the
1272 * flags = SCSI bus reset option flags (see scsi.h)
1275 * DID_RESET in cmd.host_byte of aborted command(s)
1278 * Resetting the bus always succeeds - is has to, otherwise the
1279 * kernel will panic! Try a surgical technique - sending a BUS
1280 * DEVICE RESET message - on the offending target before pulling
1281 * the SCSI bus reset line.
1282 **************************************************************************/
1284 qla1280_reset(Scsi_Cmnd
*cmd
, unsigned int flags
)
1286 scsi_qla_host_t
*ha
;
1287 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1288 unsigned long cpu_flags
= 0;
1301 action_t action
= ADAPTER_RESET
;
1307 ENTER("qla1280_reset");
1309 if (qla1280_verbose
)
1310 printk("scsi(): Resetting Cmnd=0x%lx, Handle=0x%lx, flags=0x%x\n",(long)cmd
,(long)CMD_HANDLE(cmd
),flags
);
1313 printk(KERN_WARNING
"(scsi?:?:?:?) Reset called with NULL Scsi_Cmnd "
1314 "pointer, failing.\n");
1315 return(SCSI_RESET_SNOOZE
);
1317 ha
= (scsi_qla_host_t
*) cmd
->host
->hostdata
;
1318 sp
= (srb_t
*) CMD_SP(cmd
);
1321 qla1280_panic("qla1280_reset",ha
->host
);
1325 /* Check for pending interrupts. */
1326 data
= qla1280_debounce_register(&ha
->iobase
->istatus
);
1327 if( !(ha
->flags
.in_isr
) && (data
& RISC_INT
) )
1329 qla1280_isr(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1334 * Determine the suggested action that the mid-level driver wants
1337 if( CMD_HANDLE(cmd
) == (unsigned char *) 0 )
1340 * if mid-level driver called reset with a orphan SCSI_Cmnd
1341 * (i.e. a command that's not pending ), so perform the
1342 * function specified.
1344 if( (flags
& SCSI_RESET_SUGGEST_HOST_RESET
) )
1345 action
= ADAPTER_RESET
;
1351 * Mid-level driver has called reset with this SCSI_Cmnd and
1354 if( flags
& SCSI_RESET_SUGGEST_HOST_RESET
)
1355 action
= ADAPTER_RESET
;
1356 else if( flags
& SCSI_RESET_SUGGEST_BUS_RESET
)
1359 action
= DEVICE_RESET
;
1362 b
= SCSI_BUS_32(cmd
);
1363 t
= SCSI_TCN_32(cmd
);
1364 l
= SCSI_LUN_32(cmd
);
1365 q
= LU_Q(ha
, b
, t
, l
);
1367 #if AUTO_ESCALATE_RESET
1368 if ( (action
& DEVICE_RESET
) && (q
->q_flag
& QLA1280_QRESET
) )
1370 printk(KERN_INFO
"qla1280(%d): Bus device reset already sent to " "device, escalating.\n", (int)ha
->host_no
);
1373 if ( (action
& DEVICE_RESET
) && (sp
->flags
& SRB_ABORT_PENDING
) )
1375 printk(KERN_INFO
"qla1280(%d):Have already attempted to reach " "device with abort device\n", (int)ha
->host_no
);
1376 printk(KERN_INFO
"qla1280(%d):message, will escalate to BUS " "RESET.\n",(int) ha
->host_no
);
1382 * By this point, we want to already know what we are going to do,
1383 * so we only need to perform the course of action.
1386 result
= SCSI_RESET_ERROR
;
1393 result
= SCSI_RESET_PENDING
;
1397 ha
->flags
.in_reset
= TRUE
;
1398 if (qla1280_verbose
)
1399 printk(KERN_INFO
"scsi(%d:%d:%d:%d): Queueing abort device command.\n", (int)ha
->host_no
,(int)b
,(int)t
,(int)l
);
1400 qla1280_abort_queue_single(ha
,b
,t
,l
,DID_ABORT
);
1401 if( qla1280_abort_device(ha
, b
, t
, l
) == 0)
1402 result
= SCSI_RESET_PENDING
;
1406 if (qla1280_verbose
)
1407 printk(KERN_INFO
"scsi(%d:%d:%d:%d): Queueing device reset command.\n",(int) ha
->host_no
,(int)b
,(int)t
,(int)l
);
1408 ha
->flags
.in_reset
= TRUE
;
1409 for (l
= 0; l
< MAX_LUNS
; l
++)
1410 qla1280_abort_queue_single(ha
,b
,t
,l
,DID_ABORT
);
1411 if( qla1280_device_reset(ha
, b
, t
) == 0 )
1412 result
= SCSI_RESET_PENDING
;
1413 q
->q_flag
|= QLA1280_QRESET
;
1417 if (qla1280_verbose
)
1418 printk(KERN_INFO
"qla1280(%d:%d:%d:%d): Issuing BUS DEVICE RESET.\n",(int) ha
->host_no
,(int)b
,(int)t
,(int)l
);
1419 ha
->flags
.in_reset
= TRUE
;
1420 for (t
= 0; t
< MAX_TARGETS
; t
++)
1421 for (l
= 0; l
< MAX_LUNS
; l
++)
1422 qla1280_abort_queue_single(ha
,b
,t
,l
,DID_RESET
);
1423 qla1280_bus_reset(ha
, b
);
1425 * The bus reset routine returns all the outstanding commands back
1426 * with "DID_RESET" in the status field after a short delay
1427 * by the firmware. If the mid-level time out the SCSI reset before
1428 * our delay we may need to ignore it.
1430 /* result = SCSI_RESET_PENDING | SCSI_RESET_BUS_RESET; */
1431 result
= SCSI_RESET_SUCCESS
| SCSI_RESET_BUS_RESET
;
1432 mdelay(4 * 1000); barrier();
1433 if( flags
& SCSI_RESET_SYNCHRONOUS
)
1435 CMD_RESULT(cmd
) = (int) (DID_BUS_BUSY
<< 16);
1436 (*(cmd
)->scsi_done
)(cmd
);
1438 /* ha->reset_start = jiffies; */
1443 if (qla1280_verbose
)
1445 printk(KERN_INFO
"scsi(%d:%d:%d:%d): Issued an ADAPTER RESET.\n",(int) ha
->host_no
,(int)b
,(int)t
,(int)l
);
1446 printk(KERN_INFO
"scsi(%d:%d:%d:%d): I/O processing will continue automatically.\n",(int) ha
->host_no
,(int)b
,(int)t
,(int)l
);
1448 ha
->flags
.reset_active
= TRUE
;
1450 * We restarted all of the commands automatically, so the mid-level code can expect
1451 * completions momentitarily.
1453 if( qla1280_abort_isp(ha
) == 0 )
1454 result
= SCSI_RESET_SUCCESS
| SCSI_RESET_HOST_RESET
;
1456 ha
->flags
.reset_active
= FALSE
;
1459 if( ha
->done_q_first
)
1460 qla1280_done(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1461 qla1280_restart_queues(ha
);
1462 ha
->flags
.in_reset
= FALSE
;
1465 DEBUG(printk("RESET returning %d\n", result
));
1468 LEAVE("qla1280_reset");
1472 /**************************************************************************
1474 * Return the disk geometry for the given SCSI device.
1475 **************************************************************************/
1477 qla1280_biosparam(Disk
*disk
, kdev_t dev
, int geom
[])
1479 int heads
, sectors
, cylinders
;
1483 cylinders
= disk
->capacity
/ (heads
* sectors
);
1484 if (cylinders
> 1024)
1488 cylinders
= disk
->capacity
/ (heads
* sectors
);
1489 /* if (cylinders > 1023)
1490 cylinders = 1023; */
1495 geom
[2] = cylinders
;
1499 /**************************************************************************
1500 * qla1280_intr_handler
1501 * Handles the H/W interrupt
1502 **************************************************************************/
1503 void qla1280_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1505 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,95)
1506 unsigned long cpu_flags
= 0;
1508 scsi_qla_host_t
*ha
;
1512 ENTER_INTR("qla1280_intr_handler");
1514 ha
= (scsi_qla_host_t
*) dev_id
;
1517 printk(KERN_INFO
"scsi(): Interrupt with NULL host ptr\n");
1521 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,95)
1522 spin_lock_irqsave(&io_request_lock
, cpu_flags
);
1523 if(test_and_set_bit(QLA1280_IN_ISR_BIT
, &ha
->flags
))
1530 /* disable our interrupt. */
1531 WRT_REG_WORD(®
->ictrl
, 0);
1532 data
= qla1280_debounce_register(®
->istatus
);
1533 /* Check for pending interrupts. */
1534 if ( !(data
& RISC_INT
) )
1536 /* spurious interrupts can happen legally */
1537 DEBUG(printk("scsi(%d): Spurious interrupt - ignoring\n",(int)ha
->host_no
));
1541 qla1280_isr(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1542 if (ha
->done_q_first
)
1543 qla1280_done(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1545 clear_bit(QLA1280_IN_ISR_BIT
, &ha
->flags
);
1546 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
);
1547 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95) */
1549 if( test_bit(QLA1280_IN_ISR_BIT
, (int *)&ha
->flags
) )
1552 printk(KERN_INFO
"scsi(%d): Already in interrupt - returning \n", (int)ha
->host_no
);
1555 set_bit(QLA1280_IN_ISR_BIT
, (int *)&ha
->flags
);
1558 /* disable our interrupt. */
1559 WRT_REG_WORD(®
->ictrl
, 0);
1561 data
= qla1280_debounce_register(®
->istatus
);
1562 /* Check for pending interrupts. */
1563 if ( !(data
& RISC_INT
) )
1565 /* spurious interrupts can happen legally */
1566 DEBUG(printk("scsi(%d): Spurious interrupt - ignoring\n",(int)ha
->host_no
));
1570 qla1280_isr(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1572 /* if no work to do then call the SCSI mid-level right away */
1573 if( ha
->done_q_first
)
1574 qla1280_done(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1576 /* Schedule the DPC routine */
1577 if (ha
->flags
.isp_abort_needed
|| ha
->flags
.reset_marker
||
1580 ha
->run_qla_bh
.data
= (void *) ha
;
1581 ha
->run_qla_bh
.routine
= qla1280_do_dpc
;
1584 schedule_task(&ha
->run_qla_bh
);
1585 ha
->flags
.dpc_sched
= TRUE
;
1587 clear_bit(QLA1280_IN_ISR_BIT
, (int *)&ha
->flags
);
1589 /* enable our interrupt. */
1590 WRT_REG_WORD(®
->ictrl
, ISP_EN_INT
+ ISP_EN_RISC
);
1593 LEAVE_INTR("qla1280_intr_handler");
1596 /**************************************************************************
1600 * This routine is a task that is schedule by the interrupt handler
1601 * to perform the background processing for interrupts. We put it
1602 * on a task queue that is consumed whenever the scheduler runs; that's
1603 * so you can do anything (i.e. put the process to sleep etc). In fact, the
1604 * mid-level tries to sleep when it reaches the driver threshold
1605 * "host->can_queue". This can cause a panic if we were in our interrupt
1607 **************************************************************************/
1608 static void qla1280_do_dpc(void *p
)
1610 scsi_qla_host_t
*ha
= (scsi_qla_host_t
*) p
;
1611 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
1612 unsigned long cpu_flags
= 0;
1616 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
1617 spin_lock_irqsave(&io_request_lock
, cpu_flags
);
1619 if (ha
->flags
.isp_abort_needed
)
1620 qla1280_abort_isp(ha
);
1622 if (ha
->flags
.reset_marker
)
1623 qla1280_rst_aen(ha
);
1625 if (ha
->done_q_first
)
1626 qla1280_done(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1627 ha
->flags
.dpc_sched
= FALSE
;
1628 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
1629 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
);
1633 /**************************************************************************
1634 * qla1280_device_queue_depth
1637 * Determines the queue depth for a given device. There are two ways
1638 * a queue depth can be obtained for a tagged queueing device. One
1639 * way is the default queue depth which is determined by whether
1640 * If it is defined, then it is used
1641 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1642 * default queue depth (dependent on the number of hardware SCBs).
1643 **************************************************************************/
1644 STATIC
void qla1280_device_queue_depth(scsi_qla_host_t
*p
, Scsi_Device
*device
)
1646 int default_depth
= 3;
1647 int bus
= device
->channel
;
1648 int target
= device
->id
;
1650 device
->queue_depth
= default_depth
;
1652 if (device
->tagged_supported
&&
1653 (p
->bus_settings
[bus
].qtag_enables
& (BIT_0
<< target
)) )
1655 device
->tagged_queue
= 1;
1656 device
->current_tag
= 0;
1657 device
->queue_depth
= p
->bus_settings
[bus
].hiwat
;
1658 /* device->queue_depth = 20; */
1659 printk(KERN_INFO
"scsi(%d:%d:%d:%d): Enabled tagged queuing, queue depth %d.\n",
1660 (int)p
->host_no
, device
->channel
, device
->id
,
1661 device
->lun
, device
->queue_depth
);
1663 qla12160_get_target_parameters(p
, bus
, target
, device
->lun
);
1667 /**************************************************************************
1668 * qla1280_select_queue_depth
1670 * Sets the queue depth for each SCSI device hanging off the input
1671 * host adapter. We use a queue depth of 2 for devices that do not
1672 * support tagged queueing.
1673 **************************************************************************/
1675 qla1280_select_queue_depth(struct Scsi_Host
*host
, Scsi_Device
*scsi_devs
)
1677 Scsi_Device
*device
;
1678 scsi_qla_host_t
*p
= (scsi_qla_host_t
*) host
->hostdata
;
1680 ENTER("qla1280_select_queue_depth");
1681 for (device
= scsi_devs
; device
!= NULL
; device
= device
->next
)
1683 if (device
->host
== host
)
1684 qla1280_device_queue_depth(p
, device
);
1686 LEAVE("qla1280_select_queue_depth");
1689 /*--------------------------**
1690 ** Driver Support Routines **
1691 **--------------------------*/
1693 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
1696 * Delay in milliseconds
1699 * milliseconds = delay
1701 STATIC
inline void mdelay(int milliseconds
)
1705 for(i
=0; i
<milliseconds
; i
++)
1712 * Process completed commands.
1715 * ha = adapter block pointer.
1716 * done_q_first = done queue first pointer.
1717 * done_q_last = done queue last pointer.
1720 qla1280_done(scsi_qla_host_t
*ha
, srb_t
**done_q_first
, srb_t
**done_q_last
)
1726 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1727 unsigned long cpu_flags
= 0;
1730 ENTER("qla1280_done");
1734 while (*done_q_first
!= NULL
)
1736 /* remove command from done list */
1738 if (!(*done_q_first
= sp
->s_next
))
1739 *done_q_last
= NULL
;
1741 (*done_q_first
)->s_prev
= NULL
;
1743 b
= SCSI_BUS_32(cmd
);
1744 t
= SCSI_TCN_32(cmd
);
1745 l
= SCSI_LUN_32(cmd
);
1746 q
= LU_Q(ha
, b
, t
, l
);
1748 /* Decrement outstanding commands on device. */
1751 if (q
->q_outcnt
< ha
->bus_settings
[b
].hiwat
)
1753 q
->q_flag
&= ~QLA1280_QBUSY
;
1756 q
->resp_time
+= jiffies
- sp
->r_start
; /* Lun bookkeeping information */
1757 q
->act_time
+= jiffies
- sp
->u_start
;
1759 if( sp
->dir
& BIT_5
)
1764 switch ( (CMD_RESULT(cmd
)>>16))
1767 q
->q_flag
&= ~QLA1280_QRESET
;
1768 /* Issue marker command. */
1769 qla1280_marker(ha
, b
, t
, 0, MK_SYNC_ID
);
1772 sp
->flags
&= ~SRB_ABORT_PENDING
;
1773 sp
->flags
|= SRB_ABORTED
;
1774 if (sp
->flags
& SRB_TIMEOUT
)
1775 CMD_RESULT(sp
->cmd
)= DID_TIME_OUT
<< 16;
1781 /* Call the mid-level driver interrupt handler */
1782 CMD_HANDLE(sp
->cmd
) = (unsigned char *) 0;
1784 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1786 (*(cmd
)->scsi_done
)(cmd
);
1789 (*(cmd
)->scsi_done
)(cmd
);
1791 qla1280_next(ha
, q
, b
);
1797 LEAVE("qla1280_done");
1801 * Translates a ISP error to a Linux SCSI error
1803 STATIC
int qla1280_return_status( sts_entry_t
*sts
, Scsi_Cmnd
*cp
)
1805 int host_status
= DID_ERROR
;
1806 #if DEBUG_QLA1280_INTR
1807 STATIC
char *reason
[] =
1820 #endif /* DEBUG_QLA1280_INTR */
1822 ENTER("qla1280_return_status");
1824 #if DEBUG_QLA1280_INTR
1826 DEBUG(printk("qla1280_return_status: compl status = 0x%04x\n", sts->comp_status));
1829 switch(sts
->comp_status
)
1832 host_status
= DID_OK
;
1835 if (!(sts
->state_flags
& SF_GOT_BUS
))
1836 host_status
= DID_NO_CONNECT
;
1837 else if (!(sts
->state_flags
& SF_GOT_TARGET
))
1838 host_status
= DID_BAD_TARGET
;
1839 else if (!(sts
->state_flags
& SF_SENT_CDB
))
1840 host_status
= DID_ERROR
;
1841 else if (!(sts
->state_flags
& SF_TRANSFERRED_DATA
))
1842 host_status
= DID_ERROR
;
1843 else if (!(sts
->state_flags
& SF_GOT_STATUS
))
1844 host_status
= DID_ERROR
;
1845 else if (!(sts
->state_flags
& SF_GOT_SENSE
))
1846 host_status
= DID_ERROR
;
1849 host_status
= DID_RESET
;
1852 host_status
= DID_ABORT
;
1855 host_status
= DID_TIME_OUT
;
1857 case CS_DATA_OVERRUN
:
1858 #ifdef QL_DEBUG_LEVEL_2
1859 printk("Data overrun 0x%x\n",(int)sts
->residual_length
);
1861 "\n\rqla1280_isr: response packet data\n\r");
1862 qla1280_dump_buffer((caddr_t
)sts
,
1863 RESPONSE_ENTRY_SIZE
);
1865 host_status
= DID_ERROR
;
1867 case CS_DATA_UNDERRUN
:
1868 if ( (CMD_XFRLEN(cp
) - sts
->residual_length
) < cp
->underflow
)
1870 printk("scsi: Underflow detected - retrying command.\n");
1871 host_status
= DID_ERROR
;
1874 host_status
= DID_OK
;
1877 host_status
= DID_ERROR
;
1881 #if DEBUG_QLA1280_INTR
1882 sprintf(debug_buff
, "qla1280 ISP status: host status (%s) scsi status %x\n\r", reason
[host_status
], sts
->scsi_status
);
1883 qla1280_print(debug_buff
);
1886 LEAVE("qla1280_return_status");
1888 return (sts
->scsi_status
& 0xff) | (host_status
<< 16);
1892 * qla1280_done_q_put
1893 * Place SRB command on done queue.
1897 * done_q_first = done queue first pointer.
1898 * done_q_last = done queue last pointer.
1901 qla1280_done_q_put(srb_t
*sp
, srb_t
**done_q_first
, srb_t
**done_q_last
)
1903 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1904 unsigned long cpu_flags
= 0;
1906 #ifdef QL_DEBUG_LEVEL_3
1907 ENTER("qla1280_put_done_q");
1909 /* Place block on done queue */
1912 sp
->s_prev
= *done_q_last
;
1916 (*done_q_last
)->s_next
= sp
;
1920 #ifdef QL_DEBUG_LEVEL_3
1921 LEAVE("qla1280_put_done_q");
1927 * Retrieve and process next job in the queue.
1930 * ha = adapter block pointer.
1931 * q = SCSI LU pointer.
1932 * b = SCSI bus number.
1933 * SCSI_LU_Q lock must be already obtained and no other locks.
1936 * Releases SCSI_LU_Q upon exit.
1939 qla1280_next(scsi_qla_host_t
*ha
, scsi_lu_t
*q
, uint8_t b
)
1944 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1945 unsigned long cpu_flags
= 0;
1948 ENTER("qla1280_next");
1951 while ( ((sp
= q
->q_first
) != NULL
) && /* we have a queue pending */
1952 !(q
->q_flag
& QLA1280_QBUSY
) && /* device not busy */
1953 !ha
->flags
.abort_isp_active
&& /* not resetting the adapter */
1954 !(q
->q_flag
& QLA1280_QSUSP
) ) /* device not suspended */
1956 /* Remove srb from SCSI LU queue. */
1957 qla1280_removeq(q
, sp
);
1959 DEBUG(sprintf(debug_buff
,"starting request 0x%p<-(0x%p)\n\r",q
,sp
));
1960 DEBUG(qla1280_print(debug_buff
));
1962 /* Set busy flag if reached high water mark. */
1964 if (q
->q_outcnt
>= ha
->bus_settings
[b
].hiwat
)
1965 q
->q_flag
|= QLA1280_QBUSY
;
1967 #if QLA1280_64BIT_SUPPORT
1968 if (ha
->flags
.enable_64bit_addressing
)
1969 status
= qla1280_64bit_start_scsi(ha
, sp
);
1972 status
= qla1280_32bit_start_scsi(ha
, sp
);
1974 if (status
) /* if couldn't start the request */
1976 if (q
->q_outcnt
== 1)
1978 /* Release SCSI LU queue specific lock */
1979 QLA1280_SCSILU_UNLOCK(q
);
1981 /* Wait for 30 sec for command to be accepted. */
1982 for (cnt
= 6000000; cnt
; cnt
--)
1984 #if QLA1280_64BIT_SUPPORT
1985 if (ha
->flags
.enable_64bit_addressing
)
1986 status
= qla1280_64bit_start_scsi(ha
, sp
);
1989 status
= qla1280_32bit_start_scsi(ha
, sp
);
1996 /* Go check for pending interrupts. */
1999 SYS_DELAY(5); /* 10 */
2003 /* Set timeout status */
2004 CMD_RESULT(sp
->cmd
) = DID_TIME_OUT
<< 16;
2007 /* Remove command from watchdog queue. */
2008 if (sp
->flags
& SRB_WATCHDOG
)
2009 qla1280_timeout_remove(ha
, sp
);
2012 CMD_HANDLE(sp
->cmd
) = (unsigned char *) 0;
2014 /* Call the mid-level driver interrupt handler */
2015 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2017 (*(sp
->cmd
)->scsi_done
)(sp
->cmd
);
2020 (*(sp
->cmd
)->scsi_done
)(sp
->cmd
);
2023 /* Acquire LU queue specific lock */
2024 QLA1280_SCSILU_LOCK(q
);
2030 /* Acquire LU queue specific lock */
2031 QLA1280_SCSILU_LOCK(q
);
2034 { /* Place request back on top of device queue. */
2035 qla1280_putq_t(q
, sp
);
2039 if (q
->q_outcnt
< ha
->bus_settings
[b
].hiwat
)
2040 q
->q_flag
&= ~QLA1280_QBUSY
;
2048 /* Release SCSI LU queue specific lock */
2049 QLA1280_SCSILU_UNLOCK(q
);
2051 LEAVE("qla1280_next");
2056 * Add the standard SCB job to the top of standard SCB commands.
2059 * q = SCSI LU pointer.
2061 * SCSI_LU_Q lock must be already obtained.
2064 qla1280_putq_t(scsi_lu_t
*q
, srb_t
*sp
)
2067 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2068 unsigned long cpu_flags
= 0;
2071 #ifdef QL_DEBUG_LEVEL_3
2072 ENTER("qla1280_putq_t");
2075 DEBUG(sprintf(debug_buff
,"Adding to device 0x%p<-(0x%p)\n\r",q
,sp
));
2076 DEBUG(qla1280_print(debug_buff
));
2078 if (!q
->q_first
) /* If queue empty */
2088 srb_p
= srb_p
->s_next
;
2092 sp
->s_prev
= srb_p
->s_prev
;
2094 srb_p
->s_prev
->s_next
= sp
;
2102 sp
->s_prev
= q
->q_last
;
2103 q
->q_last
->s_next
= sp
;
2109 #ifdef QL_DEBUG_LEVEL_3
2110 LEAVE("qla1280_putq_t");
2116 * Function used to remove a command block from the
2120 * q = SCSI LU pointer.
2122 * SCSI_LU_Q lock must be already obtained.
2125 qla1280_removeq(scsi_lu_t
*q
, srb_t
*sp
)
2127 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2128 unsigned long cpu_flags
= 0;
2130 DEBUG(sprintf(debug_buff
,"Removing from device_q (0x%p)->(0x%p)\n\r",q
,sp
));
2131 DEBUG(qla1280_print(debug_buff
));
2135 if ((sp
->s_prev
->s_next
= sp
->s_next
) != NULL
)
2136 sp
->s_next
->s_prev
= sp
->s_prev
;
2138 q
->q_last
= sp
->s_prev
;
2140 else if (!(q
->q_first
= sp
->s_next
))
2143 q
->q_first
->s_prev
= NULL
;
2149 * Allocates adapter memory.
2156 qla1280_mem_alloc(scsi_qla_host_t
*ha
)
2161 #ifdef QL_DEBUG_LEVEL_3
2162 ENTER("qla1280_mem_alloc");
2165 #ifdef DYNAMIC_MEM_ALLOC
2166 ha
->request_ring
= qla1280_alloc_phys(REQUEST_ENTRY_SIZE
* REQUEST_ENTRY_CNT
,
2168 if(ha
->request_ring
) {
2169 ha
->response_ring
= qla1280_alloc_phys(RESPONSE_ENTRY_SIZE
* RESPONSE_ENTRY_CNT
,
2171 if(ha
->response_ring
) {
2176 ha
->request_ring
= &ha
->req
[0];
2177 ha
->request_dma
= VIRT_TO_BUS(&ha
->req
[0]);
2178 ha
->response_ring
= &ha
->res
[0];
2179 ha
->response_dma
= VIRT_TO_BUS(&ha
->res
[0]);
2184 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2185 qla1280_print("qla1280_mem_alloc: **** FAILED ****\n");
2188 #ifdef QL_DEBUG_LEVEL_3
2190 LEAVE("qla1280_mem_alloc");
2197 * Frees adapter allocated memory.
2200 * ha = adapter block pointer.
2203 qla1280_mem_free(scsi_qla_host_t
*ha
)
2208 ENTER("qlc1280_mem_free");
2211 /* Free device queues. */
2212 for (b
= 0; b
< MAX_BUSES
; b
++)
2214 q
= LU_Q(ha
, b
, ha
->bus_settings
[b
].id
, 0);
2215 for (t
= 0; t
< MAX_TARGETS
; t
++)
2216 for (l
= 0; l
< MAX_LUNS
; l
++)
2217 if (LU_Q(ha
, b
, t
, l
) != NULL
&& LU_Q(ha
, b
, t
, l
) != q
)
2218 KMFREE(LU_Q(ha
, b
, t
, l
),sizeof(struct scsi_lu
));
2219 KMFREE(q
, sizeof(struct scsi_lu
));
2221 for( b
=0; b
< MAX_EQ
; b
++ )
2222 ha
->dev
[b
] = (scsi_lu_t
*)NULL
;
2225 LEAVE("qlc1280_mem_free");
2231 /****************************************************************************/
2232 /* QLogic ISP1280 Hardware Support Functions. */
2233 /****************************************************************************/
2236 * qla2100_enable_intrs
2237 * qla2100_disable_intrs
2240 * ha = adapter block pointer.
2245 static inline void qla1280_enable_intrs(scsi_qla_host_t
*ha
) {
2249 ha
->flags
.interrupts_on
= 1;
2250 /* enable risc and host interrupts */
2251 WRT_REG_WORD(®
->ictrl
, (ISP_EN_INT
+ ISP_EN_RISC
));
2254 static inline void qla1280_disable_intrs(scsi_qla_host_t
*ha
) {
2258 ha
->flags
.interrupts_on
= 0;
2259 /* disable risc and host interrupts */
2260 WRT_REG_WORD(®
->ictrl
, 0);
2264 * qla1280_initialize_adapter
2268 * ha = adapter block pointer.
2274 qla1280_initialize_adapter(scsi_qla_host_t
*ha
)
2281 #ifdef QL_DEBUG_LEVEL_3
2282 ENTER("qla1280_initialize_adapter");
2285 /* Clear adapter flags. */
2286 ha
->flags
.online
= FALSE
;
2287 ha
->flags
.isp_abort_needed
= FALSE
;
2288 ha
->flags
.disable_host_adapter
= FALSE
;
2289 ha
->flags
.reset_active
= FALSE
;
2290 ha
->flags
.abort_isp_active
= FALSE
;
2291 ha
->flags
.watchdog_enabled
= FALSE
;
2293 DEBUG(printk("Configure PCI space for adapter...\n"));
2294 if (!(status
= qla1280_pci_config(ha
)))
2298 /* Disable ISP interrupts. */
2299 WRT_REG_WORD(®
->ictrl
, 0);
2301 /* Insure mailbox registers are free. */
2302 WRT_REG_WORD(®
->semaphore
, 0);
2303 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
2304 WRT_REG_WORD(®
->host_cmd
, HC_CLR_HOST_INT
);
2306 /* If firmware needs to be loaded */
2307 if (qla1280_verbose
)
2308 printk("scsi(%d): Determining if RISC is loaded...\n",(int)ha
->host_no
);
2309 if (qla1280_isp_firmware(ha
))
2311 if (qla1280_verbose
)
2312 printk("scsi(%d): Verifying chip...\n",(int)ha
->host_no
);
2313 if (!(status
= qla1280_chip_diag(ha
)))
2315 if (qla1280_verbose
)
2316 printk("scsi(%d): Setup chip...\n",(int)ha
->host_no
);
2317 status
= qla1280_setup_chip(ha
);
2323 /* Setup adapter based on NVRAM parameters. */
2324 if (qla1280_verbose
)
2325 printk("scsi(%d): Configure NVRAM parameters...\n",(int)ha
->host_no
);
2326 qla1280_nvram_config(ha
);
2328 if (!ha
->flags
.disable_host_adapter
&&
2329 !qla1280_init_rings(ha
))
2331 /* Issue SCSI reset. */
2332 for (b
= 0; b
< ha
->ports
; b
++)
2333 if (!ha
->bus_settings
[b
].disable_scsi_reset
)
2335 /* dg 03/13 if we can't reset twice then bus is dead */
2336 if( qla1280_bus_reset(ha
, b
) )
2337 if( qla1280_bus_reset(ha
, b
) )
2339 ha
->bus_settings
[b
].scsi_bus_dead
= TRUE
;
2345 /* Issue marker command. */
2346 ha
->flags
.reset_marker
= FALSE
;
2347 for (b
= 0; b
< ha
->ports
; b
++)
2349 ha
->bus_settings
[b
].reset_marker
= FALSE
;
2350 qla1280_marker(ha
, b
, 0, 0, MK_SYNC_ALL
);
2352 }while (ha
->flags
.reset_marker
);
2354 ha
->flags
.online
= TRUE
;
2356 /* Enable host adapter target mode. */
2357 for (b
= 0; b
< ha
->ports
; b
++)
2359 if (!(status
= qla1280_enable_tgt(ha
, b
)))
2361 /* for (cnt = 0; cnt < MAX_LUNS; cnt++)
2363 qla1280_enable_lun(ha, b, cnt);
2376 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2378 qla1280_print("qla1280_initialize_adapter: **** FAILED ****\n\r");
2380 #ifdef QL_DEBUG_LEVEL_3
2382 LEAVE("qla1280_initialize_adapter");
2388 * qla1280_enable_tgt
2389 * Enable target mode.
2392 * ha = adapter block pointer.
2393 * b = SCSI bus number.
2399 qla1280_enable_tgt(scsi_qla_host_t
*ha
, uint8_t b
)
2402 /* uint16_t mb[MAILBOX_REGISTER_COUNT]; */
2404 #ifdef QL_DEBUG_LEVEL_3
2405 qla1280_print("qla1280_enable_tgt: entered\n\r");
2408 /* Enable target mode. */
2410 mb[0] = MBC_ENABLE_TARGET_MODE;
2412 mb[2] = (uint16_t)(b << 15);
2413 status = qla1280_mailbox_command(ha, BIT_2|BIT_1|BIT_0, &mb[0]);
2415 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2417 qla1280_print("qla1280_enable_tgt: **** FAILED ****\n\r");
2419 #ifdef QL_DEBUG_LEVEL_3
2421 qla1280_print("qla1280_enable_tgt: exiting normally\n\r");
2428 * Checks if present version of RISC firmware is older than
2432 * ha = adapter block pointer.
2435 * 0 = firmware does not need to be loaded.
2438 qla1280_isp_firmware(scsi_qla_host_t
*ha
)
2440 nvram_t
*nv
= (nvram_t
*)ha
->response_ring
;
2444 uint8_t status
= 0; /* dg 2/27 always loads RISC */
2445 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2447 ENTER("qla1280_isp_firmware");
2449 /* Verify valid NVRAM checksum. */
2450 wptr
= (uint16_t *)ha
->response_ring
;
2451 DEBUG(printk("qla1280_isp_firmware: Reading NVRAM\n"));
2453 for (cnt
= 0; cnt
< sizeof(nvram_t
)/2; cnt
++)
2455 *wptr
= qla1280_get_nvram_word(ha
, cnt
);
2456 chksum
+= (uint8_t)*wptr
;
2457 chksum
+= (uint8_t)(*wptr
>> 8);
2460 DEBUG(printk("qla1280_isp_firmware: Completed Reading NVRAM\n"));
2462 #if defined(QL_DEBUG_LEVEL_3)
2463 sprintf(debug_buff
,"qla1280_isp_firmware: NVRAM Magic ID= %c %c %c\n\r",(char *) nv
->id
[0],nv
->id
[1],nv
->id
[2]);
2464 qla1280_print(debug_buff
);
2467 /* Bad NVRAM data, load RISC code. */
2468 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
2469 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->version
< 1)
2471 printk(KERN_INFO
"qla1280_isp_firmware: Bad checksum or magic number or version in NVRAM.\n");
2472 ha
->flags
.disable_risc_code_load
= FALSE
;
2475 ha
->flags
.disable_risc_code_load
= nv
->cntr_flags_1
.disable_loading_risc_code
;
2477 if (ha
->flags
.disable_risc_code_load
)
2479 #if defined(QL_DEBUG_LEVEL_3)
2480 qla1280_print("qla1280_isp_firmware: Telling RISC to verify checksum of loaded BIOS code.\n\r");
2482 /* Verify checksum of loaded RISC code. */
2483 mb
[0] = MBC_VERIFY_CHECKSUM
;
2484 /* mb[1] = ql12_risc_code_addr01; */
2485 mb
[1] = *QLBoardTbl
[ha
->devnum
].fwstart
;
2487 if (!(status
= qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0])))
2489 /* Start firmware execution. */
2490 #if defined(QL_DEBUG_LEVEL_3)
2491 qla1280_print("qla1280_isp_firmware: Startng F/W execution.\n\r");
2493 mb
[0] = MBC_EXECUTE_FIRMWARE
;
2494 /* mb[1] = ql12_risc_code_addr01; */
2495 mb
[1] = *QLBoardTbl
[ha
->devnum
].fwstart
;
2496 qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0]);
2499 printk(KERN_INFO
"qla1280: RISC checksum failed.\n");
2503 DEBUG(printk("qla1280: NVRAM configured to load RISC load.\n"));
2507 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2510 "qla1280_isp_firmware: **** Load RISC code ****\n\r");
2512 LEAVE("qla1280_isp_firmware");
2518 * Setup device PCI configuration registers.
2521 * ha = adapter block pointer.
2527 qla1280_pci_config(scsi_qla_host_t
*ha
)
2531 #if MEMORY_MAPPED_IO
2532 uint32_t page_offset
, base
;
2535 config_reg_t
*creg
= 0;
2538 ENTER("qla1280_pci_config");
2540 /* Get command register. */
2541 if (pci_read_config_word(ha
->pdev
,OFFSET(creg
->command
), &buf_wd
) == PCIBIOS_SUCCESSFUL
)
2545 * Set Bus Master Enable, Memory Address Space Enable and
2546 * reset any error bits.
2549 #if MEMORY_MAPPED_IO
2550 DEBUG(printk("qla1280: MEMORY MAPPED IO is enabled.\n"));
2551 buf_wd
|= BIT_2
+ BIT_1
+ BIT_0
;
2553 buf_wd
|= BIT_2
+ BIT_0
;
2555 if( pci_write_config_word(ha
->pdev
,OFFSET(creg
->command
), buf_wd
) )
2557 printk(KERN_WARNING
"qla1280: Could not write config word.\n");
2559 /* Get expansion ROM address. */
2560 if (pci_read_config_word(ha
->pdev
,OFFSET(creg
->expansion_rom
), &buf_wd
) == PCIBIOS_SUCCESSFUL
)
2562 /* Reset expansion ROM address decode enable. */
2564 if (pci_write_config_word(ha
->pdev
,OFFSET(creg
->expansion_rom
), buf_wd
) == PCIBIOS_SUCCESSFUL
)
2566 #if MEMORY_MAPPED_IO
2567 /* Get memory mapped I/O address. */
2568 pci_read_config_dword(ha
->pdev
,OFFSET(cfgp
->mem_base_addr
), &mmapbase
);
2569 mmapbase
&= PCI_BASE_ADDRESS_MEM_MASK
;
2571 /* Find proper memory chunk for memory map I/O reg. */
2572 base
= mmapbase
& PAGE_MASK
;
2573 page_offset
= mmapbase
- base
;
2574 /* Get virtual address for I/O registers. */
2575 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
2576 ha
->mmpbase
= ioremap_nocache(base
, page_offset
+ 256);
2578 ha
->mmpbase
= vremap(base
,page_offset
+ 256);
2582 ha
->mmpbase
+= page_offset
;
2583 /* ha->iobase = ha->mmpbase; */
2586 #else /* MEMORY_MAPPED_IO */
2588 #endif /* MEMORY_MAPPED_IO */
2593 LEAVE("qla1280_pci_config");
2599 * Test chip for proper operation.
2602 * ha = adapter block pointer.
2608 qla1280_chip_diag(scsi_qla_host_t
*ha
)
2610 device_reg_t
*reg
= ha
->iobase
;
2614 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2616 #ifdef QL_DEBUG_LEVEL_3
2617 sprintf(debug_buff
, "qla1280_chip_diag: testing device at 0x%p \n\r",®
->id_l
);
2618 qla1280_print(debug_buff
);
2621 /* Soft reset chip and wait for it to finish. */
2622 WRT_REG_WORD(®
->ictrl
, ISP_RESET
);
2623 data
= qla1280_debounce_register(®
->ictrl
);
2624 for (cnt
= 6000000; cnt
&& data
& ISP_RESET
; cnt
--)
2627 data
= RD_REG_WORD(®
->ictrl
);
2631 /* Reset register not cleared by chip reset. */
2632 #if defined(QL_DEBUG_LEVEL_3)
2633 qla1280_print("qla1280_chip_diag: reset register cleared by chip reset\n\r");
2635 WRT_REG_WORD(®
->cfg_1
, 0);
2637 /* Reset RISC and disable BIOS which
2638 allows RISC to execute out of RAM. */
2639 WRT_REG_WORD(®
->host_cmd
, HC_RESET_RISC
);
2640 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
2641 WRT_REG_WORD(®
->host_cmd
, HC_DISABLE_BIOS
);
2642 data
= qla1280_debounce_register(®
->mailbox0
);
2643 for (cnt
= 6000000; cnt
&& data
== MBS_BUSY
; cnt
--)
2646 data
= RD_REG_WORD(®
->mailbox0
);
2651 /* Check product ID of chip */
2652 #if defined(QL_DEBUG_LEVEL_3)
2653 qla1280_print("qla1280_chip_diag: Checking product ID of chip\n\r");
2655 if (RD_REG_WORD(®
->mailbox1
) != PROD_ID_1
||
2656 (RD_REG_WORD(®
->mailbox2
) != PROD_ID_2
&&
2657 RD_REG_WORD(®
->mailbox2
) != PROD_ID_2a
) ||
2658 RD_REG_WORD(®
->mailbox3
) != PROD_ID_3
||
2659 RD_REG_WORD(®
->mailbox4
) != PROD_ID_4
)
2661 printk(KERN_INFO
"qla1280: Wrong product ID = 0x%x,0x%x,0x%x,0x%x\n",
2662 RD_REG_WORD(®
->mailbox1
),
2663 RD_REG_WORD(®
->mailbox2
),
2664 RD_REG_WORD(®
->mailbox3
),
2665 RD_REG_WORD(®
->mailbox4
) );
2670 DEBUG(printk("qla1280_chip_diag: Checking mailboxes of chip\n"));
2671 /* Wrap Incoming Mailboxes Test. */
2672 mb
[0] = MBC_MAILBOX_REGISTER_TEST
;
2680 if (!(status
= qla1280_mailbox_command(ha
,
2681 (BIT_7
|BIT_6
|BIT_5
|BIT_4
|BIT_3
|BIT_2
|BIT_1
|BIT_0
),
2684 if (mb
[1] != 0xAAAA || mb
[2] != 0x5555 ||
2685 mb
[3] != 0xAA55 || mb
[4] != 0x55AA)
2687 if (mb
[5] != 0xA5A5 || mb
[6] != 0x5A5A ||
2691 printk(KERN_INFO
"qla1280: Failed mailbox check\n");
2701 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2703 qla1280_print("qla1280_chip_diag: **** FAILED ****\n\r");
2705 #ifdef QL_DEBUG_LEVEL_3
2707 qla1280_print("qla1280_chip_diag: exiting normally\n\r");
2714 * Load and start RISC firmware.
2717 * ha = adapter block pointer.
2723 qla1280_setup_chip(scsi_qla_host_t
*ha
)
2726 uint16_t risc_address
;
2727 uint16_t *risc_code_address
;
2728 long risc_code_size
;
2729 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2730 #ifdef QLA1280_UNUSED
2739 #ifdef QL_DEBUG_LEVEL_3
2740 ENTER("qla1280_setup_chip");
2743 if( (tbuf
= (uint8_t *)KMALLOC(8000) ) == NULL
)
2745 printk("setup_chip: couldn't alloacte memory\n");
2748 p_tbuf
= VIRT_TO_BUS(tbuf
);
2749 /* Load RISC code. */
2751 risc_address = ql12_risc_code_addr01;
2752 risc_code_address = &ql12_risc_code01[0];
2753 risc_code_size = ql12_risc_code_length01;
2755 risc_address
= *QLBoardTbl
[ha
->devnum
].fwstart
;
2756 risc_code_address
= QLBoardTbl
[ha
->devnum
].fwcode
;
2757 risc_code_size
= (long)(*QLBoardTbl
[ha
->devnum
].fwlen
& 0xffff);
2759 DEBUG(printk("qla1280: DMAing RISC code (%d) words.\n",(int)risc_code_size
));
2760 DEBUG(sprintf(debug_buff
,"qla1280_setup_chip: Loading RISC code size =(%ld).\n\r",risc_code_size
);)
2761 DEBUG(qla1280_print(debug_buff
));
2763 while (risc_code_size
> 0 && !status
)
2767 if ( cnt
> risc_code_size
)
2768 cnt
= risc_code_size
;
2770 DEBUG(sprintf(debug_buff
,"qla1280_setup_chip: loading risc @ =(0x%p),%d,%d(0x%x).\n\r",risc_code_address
,cnt
,num
,risc_address
);)
2771 DEBUG(qla1280_print(debug_buff
));
2772 DEBUG(printk("qla1280_setup_chip: loading risc @ =code=(0x%p),cnt=%d,seg=%d,addr=0x%x\n\r",risc_code_address
,cnt
,num
,risc_address
));
2773 BCOPY((caddr_t
) risc_code_address
,(caddr_t
) ha
->request_ring
, (cnt
<<1));
2774 mb
[0] = MBC_LOAD_RAM
;
2775 /* mb[0] = MBC_LOAD_RAM_A64; */
2776 mb
[1] = risc_address
;
2778 mb
[3] = (uint16_t) ha
->request_dma
& 0xffff;
2779 mb
[2] = (uint16_t) (ha
->request_dma
>> 16) & 0xffff;
2780 mb
[7] = (uint16_t) (MS_64BITS(ha
->request_dma
) & 0xffff);
2781 mb
[6] = (uint16_t) (MS_64BITS(ha
->request_dma
) >> 16) & 0xffff;
2782 DEBUG(printk("qla1280_setup_chip: op=%d 0x%lx = 0x%4x,0x%4x,0x%4x,0x%4x\n",mb
[0],ha
->request_dma
,mb
[6],mb
[7],mb
[2],mb
[3]));
2783 if( (status
= qla1280_mailbox_command(ha
, BIT_4
|BIT_3
|BIT_2
|BIT_1
|BIT_0
,
2786 printk("Failed to load partial segment of f/w\n");
2792 mb
[0] = MBC_DUMP_RAM_A64
;
2793 mb
[1] = risc_address
;
2795 mb
[3] = (uint16_t) p_tbuf
& 0xffff;
2796 mb
[2] = (uint16_t) (p_tbuf
>> 16) & 0xffff;
2797 mb
[7] = (uint16_t) (p_tbuf
>> 32) & 0xffff;
2798 mb
[6] = (uint16_t) (p_tbuf
>> 48) & 0xffff;
2800 if( (status
= qla1280_mailbox_command(ha
, BIT_4
|BIT_3
|BIT_2
|BIT_1
|BIT_0
,
2803 printk("Failed to dump partial segment of f/w\n");
2806 sp
= (uint8_t *)ha
->request_ring
;
2807 for (i
= 0; i
< (cnt
<< 1) ; i
++)
2809 if( tbuf
[i
] != sp
[i
] )
2811 printk("qla1280 : firmware compare error @ byte (0x%x)\n",i
);
2817 risc_address
+= cnt
;
2818 risc_code_size
= risc_code_size
- cnt
;
2819 risc_code_address
= risc_code_address
+ cnt
;
2822 #ifdef QLA1280_UNUSED
2823 DEBUG(ql_debug_print
= 0;)
2825 for (i
= 0; i
< ql12_risc_code_length01
; i
++)
2828 mb
[1] = ql12_risc_code_addr01
+ i
;
2829 mb
[2] = ql12_risc_code01
[i
];
2831 status
= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
,
2835 printk("qla1280 : firmware load failure\n");
2840 mb
[1] = ql12_risc_code_addr01
+ i
;
2843 status
= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
,
2847 printk("qla1280 : firmware dump failure\n");
2850 if( mb
[2] != ql12_risc_code01
[i
] )
2851 printk("qla1280 : firmware compare error @ (0x%x)\n",ql12_risc_code_addr01
+i
);
2854 DEBUG(ql_debug_print
= 1;)
2857 /* Verify checksum of loaded RISC code. */
2860 DEBUG(printk("qla1280_setup_chip: Verifying checksum of loaded RISC code.\n");)
2861 mb
[0] = MBC_VERIFY_CHECKSUM
;
2862 /* mb[1] = ql12_risc_code_addr01; */
2863 mb
[1] = *QLBoardTbl
[ha
->devnum
].fwstart
;
2865 if (!(status
= qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0])))
2867 /* Start firmware execution. */
2868 DEBUG(qla1280_print("qla1280_setup_chip: start firmware running.\n\r");)
2869 mb
[0] = MBC_EXECUTE_FIRMWARE
;
2870 /* mb[1] = ql12_risc_code_addr01; */
2871 mb
[1] = *QLBoardTbl
[ha
->devnum
].fwstart
;
2872 qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0]);
2875 printk("qla1280_setup_chip: Failed checksum.\n");
2880 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2882 qla1280_print("qla1280_setup_chip: **** FAILED ****\n\r");
2884 #ifdef QL_DEBUG_LEVEL_3
2886 LEAVE("qla1280_setup_chip");
2895 * ha = adapter block pointer.
2896 * ha->request_ring = request ring virtual address
2897 * ha->response_ring = response ring virtual address
2898 * ha->request_dma = request ring physical address
2899 * ha->response_dma = response ring physical address
2905 qla1280_init_rings(scsi_qla_host_t
*ha
)
2909 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2911 #ifdef QL_DEBUG_LEVEL_3
2912 ENTER("qla1280_init_rings");
2914 /* Clear outstanding commands array. */
2915 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
2916 ha
->outstanding_cmds
[cnt
] = 0;
2918 /* Initialize request queue. */
2919 ha
->request_ring_ptr
= ha
->request_ring
;
2920 ha
->req_ring_index
= 0;
2921 ha
->req_q_cnt
= REQUEST_ENTRY_CNT
;
2922 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
2923 mb
[0] = MBC_INIT_REQUEST_QUEUE_A64
;
2924 mb
[1] = REQUEST_ENTRY_CNT
;
2925 mb
[3] = (uint16_t)LS_64BITS(ha
->request_dma
);
2926 mb
[2] = (uint16_t)( LS_64BITS(ha
->request_dma
) >> 16);
2928 mb
[7] = (uint16_t)MS_64BITS(ha
->request_dma
);
2929 mb
[6] = (uint16_t)( MS_64BITS(ha
->request_dma
) >> 16);
2930 if (!(status
= qla1280_mailbox_command(ha
,
2931 BIT_7
|BIT_6
|BIT_4
|BIT_3
|BIT_2
|BIT_1
|BIT_0
,
2934 /* Initialize response queue. */
2935 ha
->response_ring_ptr
= ha
->response_ring
;
2936 ha
->rsp_ring_index
= 0;
2937 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
2938 mb
[0] = MBC_INIT_RESPONSE_QUEUE_A64
;
2939 mb
[1] = RESPONSE_ENTRY_CNT
;
2940 mb
[3] = (uint16_t)LS_64BITS(ha
->response_dma
);
2941 mb
[2] = (uint16_t)(LS_64BITS(ha
->response_dma
) >> 16);
2943 mb
[7] = (uint16_t)MS_64BITS(ha
->response_dma
);
2944 mb
[6] = (uint16_t)(MS_64BITS(ha
->response_dma
) >> 16);
2945 status
= qla1280_mailbox_command(ha
,
2946 BIT_7
|BIT_6
|BIT_5
|BIT_3
|BIT_2
|BIT_1
|BIT_0
,
2950 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2952 qla1280_print("qla1280_init_rings: **** FAILED ****\n\r");
2954 #ifdef QL_DEBUG_LEVEL_3
2956 LEAVE("qla1280_init_rings");
2962 * NVRAM configuration.
2965 * ha = adapter block pointer.
2966 * ha->request_ring = request ring virtual address
2969 * host adapters parameters in host adapter block
2975 qla1280_nvram_config(scsi_qla_host_t
*ha
)
2977 device_reg_t
*reg
= ha
->iobase
;
2978 nvram_t
*nv
= (nvram_t
*)ha
->response_ring
;
2982 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2987 #if defined(QL_DEBUG_ROUTINES) && !defined(QL_DEBUG_LEVEL_4)
2988 uint8_t saved_print_status
= ql_debug_print
;
2990 ENTER("qla1280_nvram_config");
2991 #if defined(QL_DEBUG_ROUTINES) && !defined(QL_DEBUG_LEVEL_4)
2992 ql_debug_print
= FALSE
;
2995 /* Verify valid NVRAM checksum. */
2996 #if USE_NVRAM_DEFAULTS
2999 wptr
= (uint16_t *)ha
->response_ring
;
3001 if( ha
->device_id
== QLA12160_DEVICE_ID
||
3002 ha
->device_id
== QLA10160_DEVICE_ID
)
3003 nvsize
= sizeof(nvram160_t
)/2;
3005 nvsize
= sizeof(nvram_t
)/2;
3006 for( cnt
= 0; cnt
< nvsize
; cnt
++ )
3008 *wptr
= qla1280_get_nvram_word(ha
, cnt
);
3009 chksum
+= (uint8_t)*wptr
;
3010 chksum
+= (uint8_t)(*wptr
>> 8);
3016 /* Bad NVRAM data, set defaults parameters. */
3017 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
3018 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->version
< 1)
3020 #if USE_NVRAM_DEFAULTS
3021 DEBUG(printk("Using defaults for NVRAM\n"));
3023 DEBUG(printk("Using defaults for NVRAM: \n"));
3024 DEBUG(printk("checksum=0x%x, Id=%c, version=0x%x\n",chksum
,nv
->id
[0],nv
->version
));
3025 #if defined(QL_DEBUG_LEVEL_3)
3026 /* ql_debug_print = 1;
3027 qla1280_dump_buffer((caddr_t)ha->response_ring, REQUEST_ENTRY_SIZE);
3028 ql_debug_print = 0; */
3030 wptr
= (uint16_t *)ha
->response_ring
;
3031 for (cnt
= 0; cnt
< sizeof(nvram_t
)/2; cnt
++)
3036 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
3037 nv
->firmware_feature
.w
= BIT_0
;
3038 nv
->termination
.f
.scsi_bus_0_control
= 3;
3039 nv
->termination
.f
.scsi_bus_1_control
= 3;
3040 nv
->termination
.f
.auto_term_support
= 1;
3042 for (b
= 0; b
< MAX_BUSES
; b
++)
3044 nv
->bus
[b
].config_1
.initiator_id
= 7;
3045 nv
->bus
[b
].bus_reset_delay
= 5;
3046 nv
->bus
[b
].config_2
.async_data_setup_time
= 9;
3047 nv
->bus
[b
].config_2
.req_ack_active_negation
= 1;
3048 nv
->bus
[b
].config_2
.data_line_active_negation
= 1;
3049 nv
->bus
[b
].selection_timeout
= 250;
3050 nv
->bus
[b
].max_queue_depth
= 256;
3052 for (t
= 0; t
< MAX_TARGETS
; t
++)
3054 nv
->bus
[b
].target
[t
].parameter
.f
.auto_request_sense
= 1;
3055 nv
->bus
[b
].target
[t
].parameter
.f
.disconnect_allowed
= 1;
3056 nv
->bus
[b
].target
[t
].parameter
.f
.tag_queuing
= 1;
3057 nv
->bus
[b
].target
[t
].flags
.device_enable
= 1;
3061 #if USE_NVRAM_DEFAULTS
3069 /* Always force AUTO sense for LINUX SCSI */
3070 for (b
= 0; b
< MAX_BUSES
; b
++)
3071 for (t
= 0; t
< MAX_TARGETS
; t
++)
3073 nv
->bus
[b
].target
[t
].parameter
.f
.auto_request_sense
= 1;
3076 #if DEBUG_PRINT_NVRAM
3078 sprintf(debug_buff
,"qla1280 : initiator scsi id bus[0]=%d\n\r",
3079 nv
->bus
[0].config_1
.initiator_id
);
3080 qla1280_print(debug_buff
);
3081 sprintf(debug_buff
,"qla1280 : initiator scsi id bus[1]=%d\n\r",
3082 nv
->bus
[1].config_1
.initiator_id
);
3083 qla1280_print(debug_buff
);
3085 sprintf(debug_buff
,"qla1280 : bus reset delay[0]=%d\n\r",
3086 nv
->bus
[0].bus_reset_delay
);
3087 qla1280_print(debug_buff
);
3088 sprintf(debug_buff
,"qla1280 : bus reset delay[1]=%d\n\r",
3089 nv
->bus
[1].bus_reset_delay
);
3090 qla1280_print(debug_buff
);
3092 sprintf(debug_buff
,"qla1280 : retry count[0]=%d\n\r",
3093 nv
->bus
[0].retry_count
);
3094 qla1280_print(debug_buff
);
3095 sprintf(debug_buff
,"qla1280 : retry delay[0]=%d\n\r",
3096 nv
->bus
[0].retry_delay
);
3097 qla1280_print(debug_buff
);
3098 sprintf(debug_buff
,"qla1280 : retry count[1]=%d\n\r",
3099 nv
->bus
[1].retry_count
);
3100 qla1280_print(debug_buff
);
3101 sprintf(debug_buff
,"qla1280 : retry delay[1]=%d\n\r",
3102 nv
->bus
[1].retry_delay
);
3103 qla1280_print(debug_buff
);
3105 sprintf(debug_buff
,"qla1280 : async data setup time[0]=%d\n\r",
3106 nv
->bus
[0].config_2
.async_data_setup_time
);
3107 qla1280_print(debug_buff
);
3108 sprintf(debug_buff
,"qla1280 : async data setup time[1]=%d\n\r",
3109 nv
->bus
[1].config_2
.async_data_setup_time
);
3110 qla1280_print(debug_buff
);
3112 sprintf(debug_buff
,"qla1280 : req/ack active negation[0]=%d\n\r",
3113 nv
->bus
[0].config_2
.req_ack_active_negation
);
3114 qla1280_print(debug_buff
);
3115 sprintf(debug_buff
,"qla1280 : req/ack active negation[1]=%d\n\r",
3116 nv
->bus
[1].config_2
.req_ack_active_negation
);
3117 qla1280_print(debug_buff
);
3119 sprintf(debug_buff
,"qla1280 : data line active negation[0]=%d\n\r",
3120 nv
->bus
[0].config_2
.data_line_active_negation
);
3121 qla1280_print(debug_buff
);
3122 sprintf(debug_buff
,"qla1280 : data line active negation[1]=%d\n\r",
3123 nv
->bus
[1].config_2
.data_line_active_negation
);
3124 qla1280_print(debug_buff
);
3127 sprintf(debug_buff
,"qla1280 : disable loading risc code=%d\n\r",
3128 nv
->cntr_flags_1
.disable_loading_risc_code
);
3129 qla1280_print(debug_buff
);
3131 sprintf(debug_buff
,"qla1280 : enable 64bit addressing=%d\n\r",
3132 nv
->cntr_flags_1
.enable_64bit_addressing
);
3133 qla1280_print(debug_buff
);
3135 sprintf(debug_buff
,"qla1280 : selection timeout limit[0]=%d\n\r",
3136 nv
->bus
[0].selection_timeout
);
3137 qla1280_print(debug_buff
);
3138 sprintf(debug_buff
,"qla1280 : selection timeout limit[1]=%d\n\r",
3139 nv
->bus
[1].selection_timeout
);
3141 qla1280_print(debug_buff
);
3142 sprintf(debug_buff
,"qla1280 : max queue depth[0]=%d\n\r",
3143 nv
->bus
[0].max_queue_depth
);
3144 qla1280_print(debug_buff
);
3145 sprintf(debug_buff
,"qla1280 : max queue depth[1]=%d\n\r",
3146 nv
->bus
[1].max_queue_depth
);
3147 qla1280_print(debug_buff
);
3150 DEBUG(ql_debug_print
= 0;)
3152 /* Disable RISC load of firmware. */
3153 ha
->flags
.disable_risc_code_load
=
3154 nv
->cntr_flags_1
.disable_loading_risc_code
;
3155 /* Enable 64bit addressing. */
3156 ha
->flags
.enable_64bit_addressing
=
3157 nv
->cntr_flags_1
.enable_64bit_addressing
;
3159 /* Set ISP hardware DMA burst */
3160 mb
[0] = nv
->isp_config
.c
;
3161 WRT_REG_WORD(®
->cfg_1
, mb
[0]);
3163 /* Set SCSI termination. */
3164 WRT_REG_WORD(®
->gpio_enable
, (BIT_3
+ BIT_2
+ BIT_1
+ BIT_0
));
3165 mb
[0] = nv
->termination
.c
& (BIT_3
+ BIT_2
+ BIT_1
+ BIT_0
);
3166 WRT_REG_WORD(®
->gpio_data
, mb
[0]);
3168 /* ISP parameter word. */
3169 mb
[0] = MBC_SET_SYSTEM_PARAMETER
;
3170 mb
[1] = nv
->isp_parameter
;
3171 status
|= qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0]);
3173 /* Firmware feature word. */
3174 mb
[0] = MBC_SET_FIRMWARE_FEATURES
;
3175 mb
[1] = nv
->firmware_feature
.w
& (BIT_1
|BIT_0
);
3176 status
|= qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0]);
3178 /* Retry count and delay. */
3179 mb
[0] = MBC_SET_RETRY_COUNT
;
3180 mb
[1] = nv
->bus
[0].retry_count
;
3181 mb
[2] = nv
->bus
[0].retry_delay
;
3182 mb
[6] = nv
->bus
[1].retry_count
;
3183 mb
[7] = nv
->bus
[1].retry_delay
;
3184 status
|= qla1280_mailbox_command(ha
, BIT_7
|BIT_6
|BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3186 /* ASYNC data setup time. */
3187 mb
[0] = MBC_SET_ASYNC_DATA_SETUP
;
3188 mb
[1] = nv
->bus
[0].config_2
.async_data_setup_time
;
3189 mb
[2] = nv
->bus
[1].config_2
.async_data_setup_time
;
3190 status
|= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3192 /* Active negation states. */
3193 mb
[0] = MBC_SET_ACTIVE_NEGATION
;
3195 if (nv
->bus
[0].config_2
.req_ack_active_negation
)
3197 if (nv
->bus
[0].config_2
.data_line_active_negation
)
3200 if (nv
->bus
[1].config_2
.req_ack_active_negation
)
3202 if (nv
->bus
[1].config_2
.data_line_active_negation
)
3204 status
|= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3206 /* Selection timeout. */
3207 mb
[0] = MBC_SET_SELECTION_TIMEOUT
;
3208 mb
[1] = nv
->bus
[0].selection_timeout
;
3209 mb
[2] = nv
->bus
[1].selection_timeout
;
3210 status
|= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3212 for (b
= 0; b
< ha
->ports
; b
++)
3214 /* SCSI Reset Disable. */
3215 ha
->bus_settings
[b
].disable_scsi_reset
= nv
->bus
[b
].config_1
.scsi_reset_disable
;
3218 ha
->bus_settings
[b
].id
= nv
->bus
[b
].config_1
.initiator_id
;
3219 mb
[0] = MBC_SET_INITIATOR_ID
;
3220 mb
[1] = b
? ha
->bus_settings
[b
].id
| BIT_7
: ha
->bus_settings
[b
].id
;
3221 status
|= qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0]);
3224 ha
->bus_settings
[b
].bus_reset_delay
= nv
->bus
[b
].bus_reset_delay
;
3226 /* Command queue depth per device. */
3227 ha
->bus_settings
[b
].hiwat
= nv
->bus
[b
].max_queue_depth
- 1;
3229 /* Set target parameters. */
3230 for (t
= 0; t
< MAX_TARGETS
; t
++)
3232 if( ha
->device_id
== QLA12160_DEVICE_ID
||
3233 ha
->device_id
== QLA10160_DEVICE_ID
)
3235 status
= qla12160_set_target_parameters(ha
,b
,t
,0,(nvram160_t
*)nv
);
3239 /* Set Target Parameters. */
3240 mb
[0] = MBC_SET_TARGET_PARAMETERS
;
3241 mb
[1] = (uint16_t)(b
? t
| BIT_7
:t
);
3243 mb
[2] = nv
->bus
[b
].target
[t
].parameter
.c
<< 8;
3244 mb
[2] |= TP_AUTO_REQUEST_SENSE
;
3245 mb
[2] &= ~TP_STOP_QUEUE
;
3246 mb
[3] = nv
->bus
[b
].target
[t
].flags
.sync_offset
<< 8;
3247 mb
[3] |= nv
->bus
[b
].target
[t
].sync_period
;
3248 status
|= qla1280_mailbox_command(ha
, BIT_3
|BIT_2
|BIT_1
|BIT_0
,
3252 /* Save Tag queuing enable flag. */
3254 if (nv
->bus
[b
].target
[t
].parameter
.f
.tag_queuing
)
3255 ha
->bus_settings
[b
].qtag_enables
|= mb
[0];
3257 /* Save Device enable flag. */
3258 if (nv
->bus
[b
].target
[t
].flags
.device_enable
)
3259 ha
->bus_settings
[b
].device_enables
|= mb
[0];
3261 /* Save LUN disable flag. */
3262 if (nv
->bus
[b
].target
[t
].flags
.lun_disable
)
3263 ha
->bus_settings
[b
].lun_disables
|= mb
[0];
3265 /* Set Device Queue Parameters. */
3266 for (l
= 0; l
< MAX_LUNS
; l
++)
3268 mb
[0] = MBC_SET_DEVICE_QUEUE
;
3269 mb
[1] = (uint16_t)(b
? t
| BIT_7
:t
);
3270 mb
[1] = mb
[1] << 8 | l
;
3271 mb
[2] = nv
->bus
[b
].max_queue_depth
;
3272 mb
[3] = nv
->bus
[b
].target
[t
].execution_throttle
;
3273 status
|= qla1280_mailbox_command(ha
, BIT_3
|BIT_2
|BIT_1
|BIT_0
,
3278 DEBUG(ql_debug_print
= 0;)
3280 #if defined(QL_DEBUG_ROUTINES) && !defined(QL_DEBUG_LEVEL_4)
3281 ql_debug_print
= saved_print_status
;
3284 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3286 DEBUG(qla1280_print("qla1280_nvram_config: **** FAILED ****\n\r");)
3288 LEAVE("qla1280_nvram_config");
3293 * Get NVRAM data word
3294 * Calculates word position in NVRAM and calls request routine to
3295 * get the word from NVRAM.
3298 * ha = adapter block pointer.
3299 * address = NVRAM word address.
3305 qla1280_get_nvram_word(scsi_qla_host_t
*ha
, uint32_t address
)
3310 #ifdef QL_DEBUG_ROUTINES
3311 uint8_t saved_print_status
= ql_debug_print
;
3313 #ifdef QL_DEBUG_LEVEL_4
3314 ENTER("qla1280_get_nvram_word");
3317 nv_cmd
= address
<< 16;
3318 nv_cmd
|= NV_READ_OP
;
3320 #ifdef QL_DEBUG_ROUTINES
3321 ql_debug_print
= FALSE
;
3323 data
= qla1280_nvram_request(ha
, nv_cmd
);
3324 #ifdef QL_DEBUG_ROUTINES
3325 ql_debug_print
= saved_print_status
;
3328 #ifdef QL_DEBUG_LEVEL_4
3329 qla1280_print("qla1280_get_nvram_word: exiting normally NVRAM data = ");
3330 qla1280_output_number((uint32_t)data
, 16);
3331 qla1280_print("\n\r");
3338 * Sends read command to NVRAM and gets data from NVRAM.
3341 * ha = adapter block pointer.
3342 * nv_cmd = Bit 26 = start bit
3343 * Bit 25, 24 = opcode
3344 * Bit 23-16 = address
3345 * Bit 15-0 = write data
3351 qla1280_nvram_request(scsi_qla_host_t
*ha
, uint32_t nv_cmd
)
3354 device_reg_t
*reg
= ha
->iobase
;
3358 /* Send command to NVRAM. */
3361 for (cnt
= 0; cnt
< 11; cnt
++)
3363 if (nv_cmd
& BIT_31
)
3364 qla1280_nv_write(ha
, NV_DATA_OUT
);
3366 qla1280_nv_write(ha
, 0);
3370 /* Read data from NVRAM. */
3372 for (cnt
= 0; cnt
< 16; cnt
++)
3374 WRT_REG_WORD(®
->nvram
, NV_SELECT
+NV_CLOCK
);
3375 /* qla1280_nv_delay(ha); */
3378 reg_data
= RD_REG_WORD(®
->nvram
);
3379 if (reg_data
& NV_DATA_IN
)
3381 WRT_REG_WORD(®
->nvram
, NV_SELECT
);
3382 /* qla1280_nv_delay(ha); */
3386 /* Deselect chip. */
3388 WRT_REG_WORD(®
->nvram
, NV_DESELECT
);
3389 /* qla1280_nv_delay(ha); */
3396 qla1280_nv_write(scsi_qla_host_t
*ha
, uint16_t data
)
3398 device_reg_t
*reg
= ha
->iobase
;
3400 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
);
3402 /* qla1280_nv_delay(ha); */
3403 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
| NV_CLOCK
);
3404 /* qla1280_nv_delay(ha); */
3406 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
);
3407 /* qla1280_nv_delay(ha); */
3412 qla1280_nv_delay(scsi_qla_host_t
*ha
)
3414 device_reg_t
*reg
= ha
->iobase
;
3415 int cnt
= NV_DELAY_COUNT
;
3419 data
|= RD_REG_WORD(®
->nvram
);
3424 * Issue mailbox command and waits for completion.
3427 * ha = adapter block pointer.
3428 * mr = mailbox registers to load.
3429 * mb = data pointer for mailbox registers.
3432 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
3438 qla1280_mailbox_command(scsi_qla_host_t
*ha
, uint8_t mr
, uint16_t *mb
)
3440 device_reg_t
*reg
= ha
->iobase
;
3443 uint16_t *optr
, *iptr
;
3445 srb_t
*done_q_first
= 0;
3446 srb_t
*done_q_last
= 0;
3447 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
3448 unsigned long cpu_flags
= 0;
3451 #ifdef QL_DEBUG_LEVEL_3
3452 ENTER("qla1280_mailbox_command");
3455 /* Acquire interrupt specific lock */
3456 QLA1280_INTR_LOCK(ha
);
3458 ha
->flags
.mbox_busy
= TRUE
;
3460 /* Load mailbox registers. */
3461 optr
= (uint16_t *)®
->mailbox0
;
3463 for (cnt
= 0; cnt
< MAILBOX_REGISTER_COUNT
; cnt
++)
3467 WRT_REG_WORD(optr
, (*iptr
));
3474 /* Issue set host interrupt command. */
3475 ha
->flags
.mbox_int
= FALSE
;
3476 WRT_REG_WORD(®
->host_cmd
, HC_SET_HOST_INT
);
3477 data
= qla1280_debounce_register(®
->istatus
);
3479 /* Wait for 30 seconds for command to finish. */
3480 for (cnt
= 30000000; cnt
> 0 && !ha
->flags
.mbox_int
; cnt
--)
3482 /* Check for pending interrupts. */
3483 if (data
& RISC_INT
)
3485 qla1280_isr(ha
, (srb_t
**)&done_q_first
, (srb_t
**)&done_q_last
);
3488 data
= RD_REG_WORD(®
->istatus
);
3491 /* Check for mailbox command timeout. */
3494 #ifdef QL_DEBUG_LEVEL_2
3496 "qla1280_mailbox_command: **** Command Timeout, mailbox0 = ");
3497 qla1280_output_number((uint32_t)mb
[0], 16);
3498 qla1280_print(" ****\n\r");
3500 ha
->flags
.isp_abort_needed
= TRUE
;
3503 else if (ha
->mailbox_out
[0] != MBS_CMD_CMP
)
3506 /* Load return mailbox registers. */
3508 iptr
= (uint16_t *)&ha
->mailbox_out
[0];
3509 mr
= MAILBOX_REGISTER_COUNT
;
3513 /* Go check for any response interrupts pending. */
3514 ha
->flags
.mbox_busy
= FALSE
;
3515 qla1280_isr(ha
, (srb_t
**)&done_q_first
, (srb_t
**)&done_q_last
);
3517 /* Release interrupt specific lock */
3518 QLA1280_INTR_UNLOCK(ha
);
3521 if (ha
->flags
.isp_abort_needed
)
3522 qla1280_abort_isp(ha
);
3524 if (ha
->flags
.reset_marker
)
3525 qla1280_rst_aen(ha
);
3528 qla1280_done(ha
, (srb_t
**)&done_q_first
, (srb_t
**)&done_q_last
);
3530 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3533 qla1280_print("qla1280_mailbox_command: **** FAILED, mailbox0 = ");
3534 qla1280_output_number((uint32_t)mb
[0], 16);
3535 qla1280_print(" ****\n\r");
3538 #ifdef QL_DEBUG_LEVEL_3
3540 LEAVE("qla1280_mailbox_command");
3547 * Polls ISP for interrupts.
3550 * ha = adapter block pointer.
3553 qla1280_poll(scsi_qla_host_t
*ha
)
3555 device_reg_t
*reg
= ha
->iobase
;
3557 srb_t
*done_q_first
= 0;
3558 srb_t
*done_q_last
= 0;
3560 #ifdef QL_DEBUG_LEVEL_3
3561 /* ENTER("qla1280_poll"); */
3564 /* Acquire interrupt specific lock */
3565 QLA1280_INTR_LOCK(ha
);
3567 /* Check for pending interrupts. */
3568 data
= RD_REG_WORD(®
->istatus
);
3569 if (data
& RISC_INT
)
3570 qla1280_isr(ha
, (srb_t
**)&done_q_first
, (srb_t
**)&done_q_last
);
3572 /* Release interrupt specific lock */
3573 QLA1280_INTR_UNLOCK(ha
);
3575 if (!ha
->flags
.mbox_busy
)
3577 if (ha
->flags
.isp_abort_needed
)
3578 qla1280_abort_isp(ha
);
3579 if (ha
->flags
.reset_marker
)
3580 qla1280_rst_aen(ha
);
3584 qla1280_done(ha
, (srb_t
**)&done_q_first
, (srb_t
**)&done_q_last
);
3586 #ifdef QL_DEBUG_LEVEL_3
3587 /* LEAVE("qla1280_poll"); */
3593 * Issue SCSI bus reset.
3596 * ha = adapter block pointer.
3597 * b = SCSI bus number.
3603 qla1280_bus_reset(scsi_qla_host_t
*ha
, uint8_t b
)
3606 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3608 #ifdef QL_DEBUG_LEVEL_3
3609 qla1280_print("qla1280_bus_reset: entered\n\r");
3611 if( qla1280_verbose
)
3613 printk("scsi(%d): Resetting SCSI BUS (%d)\n",(int)ha
->host_no
,b
);
3616 mb
[0] = MBC_BUS_RESET
;
3617 mb
[1] = ha
->bus_settings
[b
].bus_reset_delay
;
3618 mb
[2] = (uint16_t)b
;
3619 status
= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3623 if (ha
->bus_settings
[b
].failed_reset_count
> 2) /* dg - 03/13/99 */
3624 ha
->bus_settings
[b
].scsi_bus_dead
= TRUE
;
3625 ha
->bus_settings
[b
].failed_reset_count
++;
3630 ha
->bus_settings
[b
].scsi_bus_dead
= FALSE
; /* dg - 03/13/99 */
3631 ha
->bus_settings
[b
].failed_reset_count
= 0;
3632 /* Issue marker command. */
3633 qla1280_marker(ha
, b
, 0, 0, MK_SYNC_ALL
);
3635 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3637 qla1280_print("qla1280_bus_reset: **** FAILED ****\n\r");
3639 #ifdef QL_DEBUG_LEVEL_3
3641 qla1280_print("qla1280_bus_reset: exiting normally\n\r");
3647 * qla1280_device_reset
3648 * Issue bus device reset message to the target.
3651 * ha = adapter block pointer.
3652 * b = SCSI BUS number.
3659 qla1280_device_reset(scsi_qla_host_t
*ha
, uint8_t b
, uint32_t t
)
3662 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3664 #ifdef QL_DEBUG_LEVEL_3
3665 ENTER("qla1280_device_reset");
3668 mb
[0] = MBC_ABORT_TARGET
;
3669 mb
[1] = (b
? (t
| BIT_7
) : t
) << 8;
3671 status
= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3673 /* Issue marker command. */
3674 qla1280_marker(ha
, b
, t
, 0, MK_SYNC_ID
);
3676 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3678 qla1280_print("qla1280_device_reset: **** FAILED ****\n\r");
3680 #ifdef QL_DEBUG_LEVEL_3
3682 LEAVE("qla1280_device_reset");
3688 * qla1280_abort_device
3689 * Issue an abort message to the device
3692 * ha = adapter block pointer.
3701 qla1280_abort_device(scsi_qla_host_t
*ha
, uint8_t b
, uint32_t t
, uint32_t l
)
3704 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3706 #ifdef QL_DEBUG_LEVEL_3
3707 ENTER("qla1280_abort_device");
3710 mb
[0] = MBC_ABORT_DEVICE
;
3711 mb
[1] = (b
? t
| BIT_7
: t
) << 8 | l
;
3712 status
= qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0]);
3714 /* Issue marker command. */
3715 qla1280_marker(ha
, b
, t
, l
, MK_SYNC_ID_LUN
);
3717 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3719 qla1280_print("qla1280_abort_device: **** FAILED ****\n\r");
3721 #ifdef QL_DEBUG_LEVEL_3
3723 LEAVE("qla1280_abort_device");
3729 * qla1280_abort_command
3730 * Abort command aborts a specified IOCB.
3733 * ha = adapter block pointer.
3734 * sp = SB structure pointer.
3740 qla1280_abort_command(scsi_qla_host_t
*ha
, srb_t
*sp
)
3743 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3747 #ifdef QL_DEBUG_LEVEL_3
3748 ENTER("qla1280_abort_command");
3751 /* Locate handle number. */
3752 for (handle
= 0; handle
< MAX_OUTSTANDING_COMMANDS
; handle
++)
3753 if (ha
->outstanding_cmds
[handle
] == sp
)
3756 b
= SCSI_BUS_32(sp
->cmd
);
3757 t
= SCSI_TCN_32(sp
->cmd
);
3758 l
= SCSI_LUN_32(sp
->cmd
);
3760 mb
[0] = MBC_ABORT_COMMAND
;
3761 mb
[1] = (b
? t
| BIT_7
: t
) << 8 | l
;
3762 mb
[2] = handle
>> 16;
3763 mb
[3] = (uint16_t)handle
;
3764 status
= qla1280_mailbox_command(ha
, BIT_3
|BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3766 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3768 qla1280_print("qla1280_abort_command: **** FAILED ****\n\r");
3770 sp
->flags
|= SRB_ABORT_PENDING
;
3772 LEAVE("qla1280_abort_command");
3777 * qla1280_reset_adapter
3781 * ha = adapter block pointer.
3784 qla1280_reset_adapter(scsi_qla_host_t
*ha
)
3786 device_reg_t
*reg
= ha
->iobase
;
3788 #ifdef QL_DEBUG_LEVEL_3
3789 ENTER("qla1280_reset_adapter");
3792 /* Disable ISP chip */
3793 ha
->flags
.online
= FALSE
;
3794 WRT_REG_WORD(®
->ictrl
, ISP_RESET
);
3795 WRT_REG_WORD(®
->host_cmd
, HC_RESET_RISC
);
3796 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
3797 WRT_REG_WORD(®
->host_cmd
, HC_DISABLE_BIOS
);
3799 #ifdef QL_DEBUG_LEVEL_3
3800 LEAVE("qla1280_reset_adapter");
3805 * Issue marker command.
3806 * Function issues marker IOCB.
3809 * ha = adapter block pointer.
3810 * b = SCSI BUS number
3813 * type = marker modifier
3816 qla1280_marker(scsi_qla_host_t
*ha
, uint8_t b
, uint32_t t
, uint32_t l
, uint8_t type
)
3820 #ifdef QL_DEBUG_LEVEL_3
3821 ENTER("qla1280_marker");
3824 /* Get request packet. */
3825 if ( (pkt
= (mrk_entry_t
*)qla1280_req_pkt(ha
)) )
3827 pkt
->entry_type
= MARKER_TYPE
;
3828 pkt
->lun
= (uint8_t)l
;
3829 pkt
->target
= (uint8_t)(b
? (t
| BIT_7
) : t
);
3830 pkt
->modifier
= type
;
3832 /* Issue command to ISP */
3833 qla1280_isp_cmd(ha
);
3836 #ifdef QL_DEBUG_LEVEL_3
3837 LEAVE("qla1280_marker");
3841 #if QLA1280_64BIT_SUPPORT
3843 * qla1280_64bit_start_scsi
3844 * The start SCSI is responsible for building request packets on
3845 * request ring and modifying ISP input pointer.
3848 * ha = adapter block pointer.
3849 * sp = SB structure pointer.
3852 * 0 = success, was able to issue command.
3855 qla1280_64bit_start_scsi(scsi_qla_host_t
*ha
, srb_t
*sp
)
3857 device_reg_t
*reg
= ha
->iobase
;
3859 Scsi_Cmnd
*cmd
= sp
->cmd
;
3861 cmd_a64_entry_t
*pkt
;
3864 struct scatterlist
*sg
= (struct scatterlist
*) NULL
;
3865 uint32_t *dword_ptr
;
3867 #ifdef QL_DEBUG_LEVEL_3
3868 ENTER("qla1280_64bit_start_scsi:");
3871 if( qla1280_check_for_dead_scsi_bus(ha
, sp
) )
3876 /* Calculate number of entries and segments required. */
3881 seg_cnt
= cmd
->use_sg
;
3882 sg
= (struct scatterlist
*) cmd
->request_buffer
;
3886 req_cnt
+= (uint16_t)(seg_cnt
- 2) / 5;
3887 if ((uint16_t)(seg_cnt
- 2) % 5)
3891 else if (cmd
->request_bufflen
) /* If data transfer. */
3893 DEBUG(printk("Single data transfer (0x%x)\n",cmd
->request_bufflen
));
3897 /* Acquire ring specific lock */
3898 QLA1280_RING_LOCK(ha
);
3900 if ((uint16_t)(req_cnt
+ 2) >= ha
->req_q_cnt
)
3902 /* Calculate number of free request entries. */
3903 cnt
= RD_REG_WORD(®
->mailbox4
);
3904 if (ha
->req_ring_index
< cnt
)
3905 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
3907 ha
->req_q_cnt
= REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
3910 /* If room for request in request ring. */
3911 if ((uint16_t)(req_cnt
+ 2) < ha
->req_q_cnt
)
3913 /* Check for room in outstanding command list. */
3914 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
&&
3915 ha
->outstanding_cmds
[cnt
] != 0; cnt
++)
3918 if (cnt
< MAX_OUTSTANDING_COMMANDS
)
3920 ha
->outstanding_cmds
[cnt
] = sp
;
3921 ha
->req_q_cnt
-= req_cnt
;
3922 CMD_HANDLE(sp
->cmd
) = (unsigned char *) (u_long
) cnt
;
3925 * Build command packet.
3927 pkt
= (cmd_a64_entry_t
*)ha
->request_ring_ptr
;
3929 pkt
->entry_type
= COMMAND_A64_TYPE
;
3930 pkt
->entry_count
= (uint8_t)req_cnt
;
3931 pkt
->sys_define
= (uint8_t)ha
->req_ring_index
;
3932 pkt
->handle
= (uint32_t)cnt
;
3934 /* Zero out remaining portion of packet. */
3935 dword_ptr
= (uint32_t *)pkt
+ 2;
3936 for (cnt
= 2; cnt
< REQUEST_ENTRY_SIZE
/4; cnt
++)
3939 /* Set ISP command timeout. */
3940 pkt
->timeout
= (uint16_t)30;
3942 /* Set device target ID and LUN */
3943 pkt
->lun
= SCSI_LUN_32(cmd
);
3944 pkt
->target
= SCSI_BUS_32(cmd
) ?
3945 (SCSI_TCN_32(cmd
) | BIT_7
) : SCSI_TCN_32(cmd
);
3947 /* Enable simple tag queuing if device supports it. */
3948 if (cmd
->device
->tagged_queue
)
3949 pkt
->control_flags
|= BIT_3
;
3951 /* Load SCSI command packet. */
3952 pkt
->cdb_len
= (uint16_t)CMD_CDBLEN(cmd
);
3953 BCOPY(&(CMD_CDBP(cmd
)), pkt
->scsi_cdb
, pkt
->cdb_len
);
3954 DEBUG(printk("Build packet for command[0]=0x%x\n",pkt
->scsi_cdb
[0]));
3957 * Load data segments.
3959 if (seg_cnt
) /* If data transfer. */
3961 /* Set transfer direction. */
3962 if ( (cmd
->data_cmnd
[0] == WRITE_6
) )
3963 pkt
->control_flags
|= BIT_6
;
3965 pkt
->control_flags
|= (BIT_5
|BIT_6
);
3967 sp
->dir
= pkt
->control_flags
& (BIT_5
|BIT_6
);
3969 /* Set total data segment count. */
3970 pkt
->dseg_count
= seg_cnt
;
3972 /* Setup packet address segment pointer. */
3973 dword_ptr
= (uint32_t *)&pkt
->dseg_0_address
;
3975 if (cmd
->use_sg
) /* If scatter gather */
3977 /* Load command entry data segments. */
3978 for (cnt
= 0; cnt
< 2 && seg_cnt
; cnt
++, seg_cnt
--)
3980 DEBUG(sprintf(debug_buff
,"SG Segment ap=0x%p, len=0x%x\n\r",sg
->address
,sg
->length
));
3981 DEBUG(qla1280_print(debug_buff
));
3982 *dword_ptr
++ = cpu_to_le32(VIRT_TO_BUS_LOW(sg
->address
));
3983 *dword_ptr
++ = cpu_to_le32(VIRT_TO_BUS_HIGH(sg
->address
));
3984 *dword_ptr
++ = sg
->length
;
3987 #ifdef QL_DEBUG_LEVEL_5
3989 "qla1280_64bit_start_scsi: Scatter/gather command packet data - ");
3990 qla1280_print("b ");
3991 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd
), 10);
3992 qla1280_print(" t ");
3993 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd
), 10);
3994 qla1280_print(" d ");
3995 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd
), 10);
3996 qla1280_print("\n\r");
3997 qla1280_dump_buffer((caddr_t
)pkt
, REQUEST_ENTRY_SIZE
);
4000 * Build continuation packets.
4004 /* Adjust ring index. */
4005 ha
->req_ring_index
++;
4006 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
)
4008 ha
->req_ring_index
= 0;
4009 ha
->request_ring_ptr
= ha
->request_ring
;
4012 ha
->request_ring_ptr
++;
4014 pkt
= (cmd_a64_entry_t
*)ha
->request_ring_ptr
;
4016 /* Zero out packet. */
4017 dword_ptr
= (uint32_t *)pkt
;
4018 for (cnt
= 0;cnt
< REQUEST_ENTRY_SIZE
/4; cnt
++)
4021 /* Load packet defaults. */
4022 ((cont_a64_entry_t
*)pkt
)->entry_type
=
4024 ((cont_a64_entry_t
*)pkt
)->entry_count
= 1;
4025 ((cont_a64_entry_t
*)pkt
)->sys_define
= (uint8_t)
4028 /* Setup packet address segment pointer. */
4029 dword_ptr
= (uint32_t *)
4030 &((cont_a64_entry_t
*)pkt
)->dseg_0_address
;
4032 /* Load continuation entry data segments. */
4033 for (cnt
= 0; cnt
< 5 && seg_cnt
; cnt
++, seg_cnt
--)
4035 *dword_ptr
++ = cpu_to_le32(VIRT_TO_BUS_LOW(sg
->address
));
4036 *dword_ptr
++ = cpu_to_le32(VIRT_TO_BUS_HIGH(sg
->address
));
4037 *dword_ptr
++ = sg
->length
;
4040 #ifdef QL_DEBUG_LEVEL_5
4042 "qla1280_64bit_start_scsi: continuation packet data - c");
4043 qla1280_print(" b ");
4044 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd
), 10);
4046 qla1280_print(" t ");
4047 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd
), 10);
4048 qla1280_print(" d ");
4049 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd
), 10);
4050 qla1280_print("\n\r");
4051 qla1280_dump_buffer((caddr_t
)pkt
, REQUEST_ENTRY_SIZE
);
4055 else /* No scatter gather data transfer */
4057 *dword_ptr
++ = cpu_to_le32(VIRT_TO_BUS_LOW(cmd
->request_buffer
));
4058 *dword_ptr
++ = cpu_to_le32(VIRT_TO_BUS_HIGH(cmd
->request_buffer
));
4059 *dword_ptr
= (uint32_t) cmd
->request_bufflen
;
4060 #ifdef QL_DEBUG_LEVEL_5
4062 "qla1280_64bit_start_scsi: No scatter/gather command packet data - c");
4063 qla1280_print(" b ");
4064 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd
), 10);
4065 qla1280_print(" t ");
4066 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd
), 10);
4067 qla1280_print(" d ");
4068 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd
), 10);
4069 qla1280_print("\n\r");
4070 qla1280_dump_buffer((caddr_t
)pkt
, REQUEST_ENTRY_SIZE
);
4074 #ifdef QL_DEBUG_LEVEL_5
4075 else /* No data transfer */
4077 *dword_ptr
++ = (uint32_t) 0;
4078 *dword_ptr
++ = (uint32_t) 0;
4079 *dword_ptr
= (uint32_t) 0;
4081 "qla1280_64bit_start_scsi: No data, command packet data - c");
4082 qla1280_print(" b ");
4083 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd
), 10);
4084 qla1280_print(" t ");
4085 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd
), 10);
4086 qla1280_print(" d ");
4087 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd
), 10);
4088 qla1280_print("\n\r");
4089 qla1280_dump_buffer((caddr_t
)pkt
, REQUEST_ENTRY_SIZE
);
4092 /* Adjust ring index. */
4093 ha
->req_ring_index
++;
4094 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
)
4096 ha
->req_ring_index
= 0;
4097 ha
->request_ring_ptr
= ha
->request_ring
;
4100 ha
->request_ring_ptr
++;
4102 /* Set chip new ring index. */
4103 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
4108 #ifdef QL_DEBUG_LEVEL_2
4110 "qla1280_64bit_start_scsi: NO ROOM IN OUTSTANDING ARRAY\n\r");
4111 qla1280_print(" req_q_cnt=");
4112 qla1280_output_number((uint32_t)ha
->req_q_cnt
, 16);
4119 #ifdef QL_DEBUG_LEVEL_2
4120 qla1280_print("qla1280_64bit_start_scsi: in-ptr=");
4121 qla1280_output_number((uint32_t)ha
->req_ring_index
, 16);
4122 qla1280_print(" req_q_cnt=");
4123 qla1280_output_number((uint32_t)ha
->req_q_cnt
, 16);
4124 qla1280_print(" req_cnt=");
4125 qla1280_output_number((uint32_t)req_cnt
, 16);
4126 qla1280_print("\n\r");
4130 /* Release ring specific lock */
4131 QLA1280_RING_UNLOCK(ha
);
4133 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4135 qla1280_print("qla1280_64bit_start_scsi: **** FAILED ****\n\r");
4137 #ifdef QL_DEBUG_LEVEL_3
4139 qla1280_print("qla1280_64bit_start_scsi: exiting normally\n\r");
4143 #endif /* QLA1280_64BIT_SUPPORT */
4146 * qla1280_32bit_start_scsi
4147 * The start SCSI is responsible for building request packets on
4148 * request ring and modifying ISP input pointer.
4150 * The Qlogic firmware interface allows every queue slot to have a SCSI
4151 * command and up to 4 scatter/gather (SG) entries. If we need more
4152 * than 4 SG entries, then continuation entries are used that can
4153 * hold another 7 entries each. The start routine determines if there
4154 * is eought empty slots then build the combination of requests to
4155 * fulfill the OS request.
4158 * ha = adapter block pointer.
4159 * sp = SCSI Request Block structure pointer.
4162 * 0 = success, was able to issue command.
4165 qla1280_32bit_start_scsi(scsi_qla_host_t
*ha
, srb_t
*sp
)
4167 device_reg_t
*reg
= ha
->iobase
;
4169 Scsi_Cmnd
*cmd
= sp
->cmd
;
4174 struct scatterlist
*sg
= (struct scatterlist
*) NULL
;
4176 uint32_t *dword_ptr
;
4178 ENTER("qla1280_32bit_start_scsi");
4181 if( qla1280_check_for_dead_scsi_bus(ha
, sp
) )
4186 /* Calculate number of entries and segments required. */
4191 * We must build an SG list in adapter format, as the kernel's SG list
4192 * cannot be used directly because of data field size (__alpha__)
4193 * differences and the kernel SG list uses virtual addresses where
4194 * we need physical addresses.
4196 seg_cnt
= cmd
->use_sg
;
4197 sg
= (struct scatterlist
*) cmd
->request_buffer
;
4199 * if greater than four sg entries then we need to allocate
4200 * continuation entries
4204 req_cnt
+= (uint16_t)(seg_cnt
- 4) / 7;
4205 if ((uint16_t)(seg_cnt
- 4) % 7)
4208 DEBUG(sprintf(debug_buff
,"S/G for data transfer -num segs(%d), req blk cnt(%d)\n\r",seg_cnt
,req_cnt
));
4209 DEBUG(qla1280_print(debug_buff
));
4211 else if (cmd
->request_bufflen
) /* If data transfer. */
4213 DEBUG(printk("Single data transfer (0x%x)\n",cmd
->request_bufflen
));
4218 DEBUG(printk("No data transfer \n"));
4222 /* Acquire ring specific lock */
4223 QLA1280_RING_LOCK(ha
);
4225 if ((uint16_t)(req_cnt
+ 2) >= ha
->req_q_cnt
)
4227 /* Calculate number of free request entries. */
4228 cnt
= RD_REG_WORD(®
->mailbox4
);
4229 if (ha
->req_ring_index
< cnt
)
4230 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
4232 ha
->req_q_cnt
= REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
4235 DEBUG(sprintf(debug_buff
,"Number of free entries = (%d)\n\r",ha
->req_q_cnt
));
4236 DEBUG(qla1280_print(debug_buff
));
4237 /* If room for request in request ring. */
4238 if ((uint16_t)(req_cnt
+ 2) < ha
->req_q_cnt
)
4240 /* Check for empty slot in outstanding command list. */
4241 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
&&
4242 (ha
->outstanding_cmds
[cnt
] != 0); cnt
++)
4245 if (cnt
< MAX_OUTSTANDING_COMMANDS
)
4247 CMD_HANDLE(sp
->cmd
) = (unsigned char *)(unsigned long)cnt
;
4248 ha
->outstanding_cmds
[cnt
] = sp
;
4249 ha
->req_q_cnt
-= req_cnt
;
4252 * Build command packet.
4254 pkt
= (cmd_entry_t
*)ha
->request_ring_ptr
;
4256 pkt
->entry_type
= COMMAND_TYPE
;
4257 pkt
->entry_count
= (uint8_t)req_cnt
;
4258 pkt
->sys_define
= (uint8_t)ha
->req_ring_index
;
4259 pkt
->handle
= (uint32_t)cnt
;
4261 /* Zero out remaining portion of packet. */
4262 dword_ptr
= (uint32_t *)pkt
+ 2;
4263 for (cnt
= 2; cnt
< REQUEST_ENTRY_SIZE
/4; cnt
++)
4266 /* Set ISP command timeout. */
4267 pkt
->timeout
= (uint16_t)30;
4269 /* Set device target ID and LUN */
4270 pkt
->lun
= SCSI_LUN_32(cmd
);
4271 pkt
->target
= SCSI_BUS_32(cmd
) ?
4272 (SCSI_TCN_32(cmd
) | BIT_7
) : SCSI_TCN_32(cmd
);
4274 /* Enable simple tag queuing if device supports it. */
4275 if (cmd
->device
->tagged_queue
)
4276 pkt
->control_flags
|= BIT_3
;
4278 /* Load SCSI command packet. */
4279 pkt
->cdb_len
= (uint16_t)CMD_CDBLEN(cmd
);
4280 data_ptr
= (uint8_t *) &(CMD_CDBP(cmd
));
4281 for (cnt
= 0; cnt
< pkt
->cdb_len
; cnt
++)
4282 pkt
->scsi_cdb
[cnt
] = *data_ptr
++;
4283 DEBUG(printk("Build packet for command[0]=0x%x\n",pkt
->scsi_cdb
[0]));
4285 * Load data segments.
4289 DEBUG(printk("loading data segments..\n"));
4290 /* Set transfer direction (READ and WRITE) */
4291 /* Linux doesn't tell us */
4294 * 3/10 dg - Normally, we should need this check with our F/W
4295 * but because of a small issue with it we do.
4297 * For block devices, cmd->request.cmd has the operation
4298 * For character devices, this isn't always set properly, so
4299 * we need to check data_cmnd[0]. This catches the conditions
4300 * for st.c, but not sg. Generic commands are pass down to us.
4302 if ( (cmd
->data_cmnd
[0] == WRITE_6
) )
4303 pkt
->control_flags
|= BIT_6
;
4305 pkt
->control_flags
|= (BIT_5
|BIT_6
);
4307 sp
->dir
= pkt
->control_flags
& (BIT_5
|BIT_6
);
4309 /* Set total data segment count. */
4310 pkt
->dseg_count
= seg_cnt
;
4312 /* Setup packet address segment pointer. */
4313 dword_ptr
= (uint32_t *)&pkt
->dseg_0_address
;
4315 if (cmd
->use_sg
) /* If scatter gather */
4317 DEBUG(qla1280_print("Building S/G data segments..\n\r"));
4318 DEBUG(qla1280_dump_buffer((caddr_t
)sg
, 4*16 ));
4319 /* Load command entry data segments. */
4320 for (cnt
= 0; cnt
< 4 && seg_cnt
; cnt
++, seg_cnt
--)
4322 *dword_ptr
++ = (uint32_t) cpu_to_le32(VIRT_TO_BUS(sg
->address
));
4323 *dword_ptr
++ = sg
->length
;
4324 DEBUG(sprintf(debug_buff
,"SG Segment ap=0x%p, len=0x%x\n\r",sg
->address
,sg
->length
));
4325 DEBUG(qla1280_print(debug_buff
));
4329 * Build continuation packets.
4333 /* Adjust ring index. */
4334 ha
->req_ring_index
++;
4335 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
)
4337 ha
->req_ring_index
= 0;
4338 ha
->request_ring_ptr
= ha
->request_ring
;
4341 ha
->request_ring_ptr
++;
4343 pkt
= (cmd_entry_t
*)ha
->request_ring_ptr
;
4345 /* Zero out packet. */
4346 dword_ptr
= (uint32_t *)pkt
;
4347 for (cnt
= 0;cnt
< REQUEST_ENTRY_SIZE
/4; cnt
++)
4350 /* Load packet defaults. */
4351 ((cont_entry_t
*)pkt
)->entry_type
=
4353 ((cont_entry_t
*)pkt
)->entry_count
= 1;
4355 ((cont_entry_t
*)pkt
)->sys_define
= (uint8_t)
4358 /* Setup packet address segment pointer. */
4359 dword_ptr
= (uint32_t *)
4360 &((cont_entry_t
*)pkt
)->dseg_0_address
;
4362 /* Load continuation entry data segments. */
4363 for (cnt
= 0; cnt
< 7 && seg_cnt
; cnt
++, seg_cnt
--)
4365 *dword_ptr
++ = (u_int
) cpu_to_le32(VIRT_TO_BUS(sg
->address
));
4366 *dword_ptr
++ = sg
->length
;
4369 #ifdef QL_DEBUG_LEVEL_5
4371 "qla1280_32bit_start_scsi: continuation packet data - scsi(");
4372 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd
), 10);
4374 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd
), 10);
4376 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd
), 10);
4377 qla1280_print(")\n\r");
4378 qla1280_dump_buffer((caddr_t
)pkt
, REQUEST_ENTRY_SIZE
);
4382 else /* No scatter gather data transfer */
4384 *dword_ptr
++ = (uint32_t) cpu_to_le32(VIRT_TO_BUS(cmd
->request_buffer
));
4385 *dword_ptr
= (uint32_t) cmd
->request_bufflen
;
4386 DEBUG(printk("Single Segment ap=0x%p, len=0x%x\n",cmd
->request_buffer
,cmd
->request_bufflen
));
4389 else /* No data transfer */
4391 *dword_ptr
++ = (uint32_t) 0;
4392 *dword_ptr
= (uint32_t) 0;
4393 #ifdef QL_DEBUG_LEVEL_5
4395 "qla1280_32bit_start_scsi: No data, command packet data - ");
4396 qla1280_print("\n\r");
4397 qla1280_dump_buffer((caddr_t
)pkt
, REQUEST_ENTRY_SIZE
);
4400 #ifdef QL_DEBUG_LEVEL_5
4401 qla1280_print("qla1280_32bit_start_scsi: First IOCB block:\n\r");
4402 qla1280_dump_buffer((caddr_t
)ha
->request_ring_ptr
, REQUEST_ENTRY_SIZE
);
4404 /* Adjust ring index. */
4405 ha
->req_ring_index
++;
4406 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
)
4408 ha
->req_ring_index
= 0;
4409 ha
->request_ring_ptr
= ha
->request_ring
;
4412 ha
->request_ring_ptr
++;
4414 /* Set chip new ring index. */
4415 DEBUG(qla1280_print("qla1280_32bit_start_scsi: Wakeup RISC for pending command\n\r"));
4417 sp
->u_start
= jiffies
;
4418 sp
->flags
|= SRB_SENT
;
4420 /* qla1280_output_number((uint32_t)ha->actthreads++, 16); */
4421 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
4426 #ifdef QL_DEBUG_LEVEL_2
4428 "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING ARRAY\n\r");
4429 qla1280_print(" req_q_cnt=");
4430 qla1280_output_number((uint32_t)ha
->req_q_cnt
, 16);
4431 qla1280_print("\n\r");
4438 #ifdef QL_DEBUG_LEVEL_2
4439 /* qla1280_print("qla1280_32bit_start_scsi: in-ptr=");
4440 qla1280_output_number((uint32_t)ha->req_ring_index, 16);
4441 qla1280_print(" req_q_cnt=");
4442 qla1280_output_number((uint32_t)ha->req_q_cnt, 16);
4443 qla1280_print(" req_cnt=");
4444 qla1280_output_number((uint32_t)req_cnt, 16);
4445 qla1280_print("\n\r"); */
4449 /* Release ring specific lock */
4450 QLA1280_RING_UNLOCK(ha
);
4452 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4454 qla1280_print("qla1280_32bit_start_scsi: **** FAILED ****\n\r"); */
4456 #ifdef QL_DEBUG_LEVEL_3
4457 LEAVE("qla1280_32bit_start_scsi");
4464 * Function is responsible for locking ring and
4465 * getting a zeroed out request packet.
4468 * ha = adapter block pointer.
4471 * 0 = failed to get slot.
4474 qla1280_req_pkt(scsi_qla_host_t
*ha
)
4476 device_reg_t
*reg
= ha
->iobase
;
4479 uint32_t *dword_ptr
;
4482 #ifdef QL_DEBUG_LEVEL_3
4483 ENTER("qla1280_req_pkt");
4486 /* Wait for 30 seconds for slot. */
4487 for (timer
= 15000000; timer
; timer
--)
4489 /* Acquire ring specific lock */
4490 QLA1280_RING_LOCK(ha
);
4492 if (ha
->req_q_cnt
> 0)
4494 /* Calculate number of free request entries. */
4495 cnt
= RD_REG_WORD(®
->mailbox4
);
4496 if (ha
->req_ring_index
< cnt
)
4497 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
4499 ha
->req_q_cnt
= REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
4502 /* Found empty request ring slot? */
4503 if (ha
->req_q_cnt
> 0)
4506 pkt
= ha
->request_ring_ptr
;
4508 /* Zero out packet. */
4509 dword_ptr
= (uint32_t *)pkt
;
4510 for (cnt
= 0; cnt
< REQUEST_ENTRY_SIZE
/4; cnt
++)
4513 /* Set system defined field. */
4514 pkt
->sys_define
= (uint8_t)ha
->req_ring_index
;
4516 /* Set entry count. */
4517 pkt
->entry_count
= 1;
4522 /* Release ring specific lock */
4523 QLA1280_RING_UNLOCK(ha
);
4525 SYS_DELAY(2); /* 10 */
4527 /* Check for pending interrupts. */
4531 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4533 qla1280_print("qla1280_req_pkt: **** FAILED ****\n\r");
4535 #ifdef QL_DEBUG_LEVEL_3
4537 qla1280_print("qla1280_req_pkt: exiting normally\n\r");
4544 * Function is responsible for modifying ISP input pointer.
4545 * Releases ring lock.
4548 * ha = adapter block pointer.
4551 qla1280_isp_cmd(scsi_qla_host_t
*ha
)
4553 device_reg_t
*reg
= ha
->iobase
;
4555 #ifdef QL_DEBUG_LEVEL_3
4556 ENTER("qla1280_isp_cmd");
4559 #ifdef QL_DEBUG_LEVEL_5
4560 qla1280_print("qla1280_isp_cmd: IOCB data:\n\r");
4561 qla1280_dump_buffer((caddr_t
)ha
->request_ring_ptr
, REQUEST_ENTRY_SIZE
);
4564 /* Adjust ring index. */
4565 ha
->req_ring_index
++;
4566 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
)
4568 ha
->req_ring_index
= 0;
4569 ha
->request_ring_ptr
= ha
->request_ring
;
4572 ha
->request_ring_ptr
++;
4574 /* Set chip new ring index. */
4575 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
4577 /* Release ring specific lock */
4578 QLA1280_RING_UNLOCK(ha
);
4580 #ifdef QL_DEBUG_LEVEL_3
4581 LEAVE("qla1280_isp_cmd");
4586 * qla1280_enable_lun
4587 * Issue enable LUN entry IOCB.
4590 * ha = adapter block pointer.
4591 * b = SCSI BUS number.
4595 qla1280_enable_lun(scsi_qla_host_t
*ha
, uint8_t b
, uint32_t l
)
4599 #ifdef QL_DEBUG_LEVEL_3
4600 qla1280_print("qla1280_enable_lun: entered\n\r");
4603 /* Get request packet. */
4605 if (pkt = (elun_entry_t *)qla1280_req_pkt(ha))
4607 pkt->entry_type = ENABLE_LUN_TYPE;
4608 pkt->lun = (uint16_t)(b ? l | BIT_15 : l);
4609 pkt->command_count = 32;
4610 pkt->immed_notify_count = 1;
4611 pkt->group_6_length = MAX_CMDSZ;
4612 pkt->group_7_length = MAX_CMDSZ;
4613 pkt->timeout = 0x30;
4615 qla1280_isp_cmd(ha);
4618 pkt
= (elun_entry_t
*)1;
4620 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4622 qla1280_print("qla1280_enable_lun: **** FAILED ****\n\r");
4624 #ifdef QL_DEBUG_LEVEL_3
4626 qla1280_print("qla1280_enable_lun: exiting normally\n\r");
4630 #if QL1280_TARGET_MODE_SUPPORT
4631 /****************************************************************************/
4632 /* Target Mode Support Functions. */
4633 /****************************************************************************/
4636 * qla1280_notify_ack
4637 * Issue notify acknowledge IOCB.
4638 * If sequence ID is zero, acknowledgement of
4639 * SCSI bus reset or bus device reset is assumed.
4642 * ha = adapter block pointer.
4643 * inotify = immediate notify entry pointer.
4646 qla1280_notify_ack(scsi_qla_host_t
*ha
, notify_entry_t
*inotify
)
4650 #ifdef QL_DEBUG_LEVEL_3
4651 qla1280_print("qla1280_notify_ack: entered\n\r");
4654 /* Get request packet. */
4655 if (pkt
= (nack_entry_t
*)qla1280_req_pkt(ha
))
4657 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
4658 pkt
->lun
= inotify
->lun
;
4659 pkt
->initiator_id
= inotify
->initiator_id
;
4660 pkt
->target_id
= inotify
->target_id
;
4661 if (inotify
->seq_id
== 0)
4664 pkt
->seq_id
= inotify
->seq_id
;
4666 /* Issue command to ISP */
4667 qla1280_isp_cmd(ha
);
4670 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4672 qla1280_print("qla1280_notify_ack: **** FAILED ****\n\r");
4674 #ifdef QL_DEBUG_LEVEL_3
4676 qla1280_print("qla1280_notify_ack: exiting normally\n\r");
4681 * qla1280_immed_notify
4682 * Issue immediate notify IOCB for LUN 0.
4685 * ha = adapter block pointer.
4686 * inotify = immediate notify entry pointer.
4689 qla1280_immed_notify(scsi_qla_host_t
*ha
, notify_entry_t
*inotify
)
4691 notify_entry_t
*pkt
;
4693 #ifdef QL_DEBUG_LEVEL_3
4694 qla1280_print("qla1280_immed_notify: entered\n\r");
4697 /* Get request packet. */
4698 if (pkt
= (notify_entry_t
*)qla1280_req_pkt(ha
))
4700 pkt
->entry_type
= IMMED_NOTIFY_TYPE
;
4701 pkt
->lun
= inotify
->lun
;
4702 pkt
->initiator_id
= inotify
->initiator_id
;
4703 pkt
->target_id
= inotify
->target_id
;
4706 /* Issue command to ISP */
4707 qla1280_isp_cmd(ha
);
4710 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4712 qla1280_print("qla1280_immed_notify: **** FAILED ****\n\r");
4714 #ifdef QL_DEBUG_LEVEL_3
4716 qla1280_print("qla1280_immed_notify: exiting normally\n\r");
4722 * Issue accept target I/O IOCB for LUN 0.
4725 * ha = adapter block pointer.
4726 * ctio = ctio returned entry pointer.
4729 qla1280_accept_io(scsi_qla_host_t
*ha
, ctio_ret_entry_t
*ctio
)
4733 #ifdef QL_DEBUG_LEVEL_3
4734 qla1280_print("qla1280_accept_io: entered\n\r");
4737 /* Get request packet. */
4738 if (pkt
= (atio_entry_t
*)qla1280_req_pkt(ha
))
4740 pkt
->entry_type
= ACCEPT_TGT_IO_TYPE
;
4741 pkt
->lun
= ctio
->lun
;
4742 pkt
->initiator_id
= ctio
->initiator_id
;
4743 pkt
->target_id
= ctio
->target_id
;
4744 pkt
->tag_value
= ctio
->tag_value
;
4747 /* Issue command to ISP */
4748 qla1280_isp_cmd(ha
);
4751 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4753 qla1280_print("qla1280_accept_io: **** FAILED ****\n\r");
4755 #ifdef QL_DEBUG_LEVEL_3
4757 qla1280_print("qla1280_accept_io: exiting normally\n\r");
4762 * qla1280_64bit_continue_io
4763 * Issue continue target I/O IOCB.
4766 * ha = adapter block pointer.
4767 * atio = atio pointer.
4768 * len = total bytecount.
4769 * addr = physical address pointer.
4772 qla1280_64bit_continue_io(scsi_qla_host_t
*ha
, atio_entry_t
*atio
, uint32_t len
,
4775 ctio_a64_entry_t
*pkt
;
4776 uint32_t *dword_ptr
;
4778 #ifdef QL_DEBUG_LEVEL_3
4779 qla1280_print("qla1280_64bit_continue_io: entered\n\r");
4782 /* Get request packet. */
4783 if (pkt
= (ctio_a64_entry_t
*)qla1280_req_pkt(ha
))
4785 pkt
->entry_type
= CTIO_A64_TYPE
;
4786 pkt
->lun
= atio
->lun
;
4787 pkt
->initiator_id
= atio
->initiator_id
;
4788 pkt
->target_id
= atio
->target_id
;
4789 pkt
->option_flags
= atio
->option_flags
;
4790 pkt
->tag_value
= atio
->tag_value
;
4791 pkt
->scsi_status
= atio
->scsi_status
;
4795 pkt
->dseg_count
= 1;
4796 pkt
->transfer_length
= len
;
4797 pkt
->dseg_0_length
= len
;
4798 dword_ptr
= (uint32_t *)addr
;
4799 pkt
->dseg_0_address
[0] = *dword_ptr
++;
4800 pkt
->dseg_0_address
[1] = *dword_ptr
;
4803 /* Issue command to ISP */
4804 qla1280_isp_cmd(ha
);
4807 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4809 qla1280_print("qla1280_64bit_continue_io: **** FAILED ****\n\r");
4811 #ifdef QL_DEBUG_LEVEL_3
4813 qla1280_print("qla1280_64bit_continue_io: exiting normally\n\r");
4818 * qla1280_32bit_continue_io
4819 * Issue continue target I/O IOCB.
4822 * ha = adapter block pointer.
4823 * atio = atio pointer.
4824 * len = total bytecount.
4825 * addr = physical address pointer.
4828 qla1280_32bit_continue_io(scsi_qla_host_t
*ha
, atio_entry_t
*atio
, uint32_t len
,
4832 uint32_t *dword_ptr
;
4834 #ifdef QL_DEBUG_LEVEL_3
4835 qla1280_print("qla1280_32bit_continue_io: entered\n\r");
4838 /* Get request packet. */
4839 if (pkt
= (ctio_entry_t
*)qla1280_req_pkt(ha
))
4841 pkt
->entry_type
= CONTINUE_TGT_IO_TYPE
;
4842 pkt
->lun
= atio
->lun
;
4843 pkt
->initiator_id
= atio
->initiator_id
;
4844 pkt
->target_id
= atio
->target_id
;
4845 pkt
->option_flags
= atio
->option_flags
;
4846 pkt
->tag_value
= atio
->tag_value
;
4847 pkt
->scsi_status
= atio
->scsi_status
;
4851 pkt
->dseg_count
= 1;
4852 pkt
->transfer_length
= len
;
4853 pkt
->dseg_0_length
= len
;
4854 dword_ptr
= (uint32_t *)addr
;
4855 pkt
->dseg_0_address
= *dword_ptr
;
4858 /* Issue command to ISP */
4859 qla1280_isp_cmd(ha
);
4862 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4864 qla1280_print("qla1280_32bit_continue_io: **** FAILED ****\n\r");
4866 #ifdef QL_DEBUG_LEVEL_3
4868 qla1280_print("qla1280_32bit_continue_io: exiting normally\n\r");
4871 #endif /* QL1280_TARGET_MODE_SUPPORT */
4873 /****************************************************************************/
4874 /* Interrupt Service Routine. */
4875 /****************************************************************************/
4877 /****************************************************************************
4879 * Calls I/O done on command completion.
4882 * ha = adapter block pointer.
4883 * done_q_first = done queue first pointer.
4884 * done_q_last = done queue last pointer.
4885 * INTR_LOCK must be already obtained.
4886 ****************************************************************************/
4888 qla1280_isr(scsi_qla_host_t
*ha
, srb_t
**done_q_first
, srb_t
**done_q_last
)
4890 device_reg_t
*reg
= ha
->iobase
;
4893 uint16_t mailbox
[MAILBOX_REGISTER_COUNT
];
4897 ENTER("qla1280_isr");
4900 /* Save mailbox register 5 */
4901 mailbox
[5] = RD_REG_WORD(®
->mailbox5
);
4903 /* Check for mailbox interrupt. */
4905 mailbox
[0] = RD_REG_WORD(®
->semaphore
);
4906 if (mailbox
[0] & BIT_0
)
4908 /* Get mailbox data. */
4911 *wptr
++ = RD_REG_WORD(®
->mailbox0
);
4912 *wptr
++ = RD_REG_WORD(®
->mailbox1
);
4913 *wptr
= RD_REG_WORD(®
->mailbox2
);
4914 if (mailbox
[0] != MBA_SCSI_COMPLETION
)
4917 *wptr
++ = RD_REG_WORD(®
->mailbox3
);
4918 *wptr
++ = RD_REG_WORD(®
->mailbox4
);
4920 *wptr
++ = RD_REG_WORD(®
->mailbox6
);
4921 *wptr
= RD_REG_WORD(®
->mailbox7
);
4924 /* Release mailbox registers. */
4926 WRT_REG_WORD(®
->semaphore
, 0);
4927 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
4929 #ifdef QL_DEBUG_LEVEL_5
4930 qla1280_print("qla1280_isr: mailbox interrupt mailbox[0] = ");
4931 qla1280_output_number((uint32_t)mailbox
[0], 16);
4932 qla1280_print("\n\r");
4935 /* Handle asynchronous event */
4939 case MBA_SCSI_COMPLETION
: /* Response completion */
4940 #ifdef QL_DEBUG_LEVEL_5
4941 qla1280_print("qla1280_isr: mailbox response completion\n\r");
4943 if (ha
->flags
.online
)
4945 /* Get outstanding command index. */
4946 index
= (uint32_t)(mailbox
[2] << 16 | mailbox
[1]);
4948 /* Validate handle. */
4949 if (index
< MAX_OUTSTANDING_COMMANDS
)
4950 sp
= ha
->outstanding_cmds
[index
];
4956 /* Free outstanding command slot. */
4957 ha
->outstanding_cmds
[index
] = 0;
4959 /* Save ISP completion status */
4960 CMD_RESULT(sp
->cmd
) = 0;
4962 /* Place block on done queue */
4964 sp
->s_prev
= *done_q_last
;
4968 (*done_q_last
)->s_next
= sp
;
4973 #ifdef QL_DEBUG_LEVEL_2
4974 qla1280_print("qla1280_isr: ISP invalid handle\n\r");
4976 printk(KERN_WARNING
"qla1280: ISP invalid handle");
4977 ha
->flags
.isp_abort_needed
= TRUE
;
4981 case MBA_BUS_RESET
: /* SCSI Bus Reset */
4982 #ifdef QL_DEBUG_LEVEL_2
4983 qla1280_print("qla1280_isr: asynchronous BUS_RESET\n\r");
4985 ha
->flags
.reset_marker
= TRUE
;
4986 index
= mailbox
[6] & BIT_0
;
4987 ha
->bus_settings
[index
].reset_marker
= TRUE
;
4989 case MBA_SYSTEM_ERR
: /* System Error */
4990 #ifdef QL_DEBUG_LEVEL_2
4991 qla1280_print("qla1280_isr: ISP System Error - mbx1=");
4992 qla1280_output_number((uint32_t)mailbox
[1], 16);
4993 qla1280_print(", mbx2=");
4994 qla1280_output_number((uint32_t)mailbox
[2], 16);
4995 qla1280_print(", mbx3=");
4996 qla1280_output_number((uint32_t)mailbox
[3], 16);
4997 qla1280_print("\n\r");
5000 "qla1280: ISP System Error - mbx1=%xh, mbx2=%xh, mbx3=%xh\n",
5001 mailbox
[1], mailbox
[2], mailbox
[3]);
5002 ha
->flags
.isp_abort_needed
= TRUE
;
5004 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
5005 #ifdef QL_DEBUG_LEVEL_2
5006 qla1280_print("qla1280_isr: ISP Request Transfer Error\n\r");
5008 printk(KERN_WARNING
"qla1280: ISP Request Transfer Error\n");
5009 ha
->flags
.isp_abort_needed
= TRUE
;
5011 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
5012 #ifdef QL_DEBUG_LEVEL_2
5013 qla1280_print("qla1280_isr: ISP Response Transfer Error\n\r");
5015 printk(KERN_WARNING
"qla1280: ISP Response Transfer Error\n");
5016 ha
->flags
.isp_abort_needed
= TRUE
;
5018 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up */
5019 #ifdef QL_DEBUG_LEVEL_2
5020 qla1280_print("qla1280_isr: asynchronous WAKEUP_THRES\n\r");
5023 case MBA_TIMEOUT_RESET
: /* Execution Timeout Reset */
5024 #ifdef QL_DEBUG_LEVEL_2
5025 qla1280_print("qla1280_isr: asynchronous TIMEOUT_RESET\n\r");
5028 case MBA_DEVICE_RESET
: /* Bus Device Reset */
5029 #ifdef QL_DEBUG_LEVEL_2
5031 "qla1280_isr: asynchronous BUS_DEVICE_RESET\n\r");
5033 ha
->flags
.reset_marker
= TRUE
;
5034 index
= mailbox
[6] & BIT_0
;
5035 ha
->bus_settings
[index
].reset_marker
= TRUE
;
5037 case MBA_BUS_MODE_CHANGE
:
5038 #ifdef QL_DEBUG_LEVEL_2
5040 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n\r");
5044 if (mailbox
[0] < MBA_ASYNC_EVENT
)
5047 ha
->mailbox_out
[0] = *wptr
++;
5048 ha
->mailbox_out
[1] = *wptr
++;
5049 ha
->mailbox_out
[2] = *wptr
++;
5050 ha
->mailbox_out
[3] = *wptr
++;
5051 ha
->mailbox_out
[4] = *wptr
++;
5052 ha
->mailbox_out
[5] = *wptr
++;
5053 ha
->mailbox_out
[6] = *wptr
++;
5054 ha
->mailbox_out
[7] = *wptr
;
5055 ha
->flags
.mbox_int
= TRUE
;
5061 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
5066 if (ha
->flags
.online
&& !ha
->flags
.mbox_busy
)
5068 if (mailbox
[5] < RESPONSE_ENTRY_CNT
)
5070 while (ha
->rsp_ring_index
!= mailbox
[5])
5072 pkt
= ha
->response_ring_ptr
;
5074 #ifdef QL_DEBUG_LEVEL_5
5075 qla1280_print("qla1280_isr: ha->rsp_ring_index = ");
5076 qla1280_output_number((uint32_t)ha
->rsp_ring_index
, 16);
5077 qla1280_print(" mailbox[5] = ");
5078 qla1280_output_number((uint32_t)mailbox
[5], 16);
5079 qla1280_print("\n\rqla1280_isr: response packet data\n\r");
5080 qla1280_dump_buffer((caddr_t
)pkt
, RESPONSE_ENTRY_SIZE
);
5083 #if defined(QL_DEBUG_LEVEL_2) && !defined(QL_DEBUG_LEVEL_5)
5084 if (pkt
->entry_type
== STATUS_TYPE
)
5086 if ((uint8_t)(pkt
->scsi_status
) || pkt
->comp_status
||
5089 DEBUG(qla1280_print("qla1280_isr: ha->rsp_ring_index = ");)
5090 DEBUG(qla1280_output_number((uint32_t)ha
->rsp_ring_index
,
5092 DEBUG(qla1280_print(" mailbox[5] = ");)
5093 DEBUG(qla1280_output_number((uint32_t)mailbox
[5], 16);)
5094 DEBUG(qla1280_print( "\n\r comp_status = ");)
5095 DEBUG(qla1280_output_number((uint32_t)pkt
->comp_status
,16);)
5096 DEBUG(qla1280_print( ", ");)
5097 DEBUG(qla1280_print( " scsi_status = ");)
5098 DEBUG(qla1280_output_number((uint32_t)pkt
->scsi_status
,16);)
5099 DEBUG(qla1280_print( "\n\r");)
5101 "\n\rqla1280_isr: response packet data\n\r");
5102 qla1280_dump_buffer((caddr_t)pkt,
5103 RESPONSE_ENTRY_SIZE); */
5108 qla1280_print("qla1280_isr: ha->rsp_ring_index = ");
5109 qla1280_output_number((uint32_t)ha
->rsp_ring_index
, 16);
5110 qla1280_print(" mailbox[5] = ");
5111 qla1280_output_number((uint32_t)mailbox
[5], 16);
5113 "\n\rqla1280_isr: response packet data\n\r");
5114 qla1280_dump_buffer((caddr_t
)pkt
, RESPONSE_ENTRY_SIZE
);
5117 if (pkt
->entry_type
== STATUS_TYPE
|| pkt
->entry_status
)
5119 if (pkt
->entry_type
== STATUS_TYPE
)
5120 qla1280_status_entry(ha
, (sts_entry_t
*)pkt
,
5121 done_q_first
, done_q_last
);
5123 qla1280_error_entry(ha
, pkt
,
5124 done_q_first
, done_q_last
);
5126 /* Adjust ring index. */
5127 ha
->rsp_ring_index
++;
5128 if (ha
->rsp_ring_index
== RESPONSE_ENTRY_CNT
)
5130 ha
->rsp_ring_index
= 0;
5131 ha
->response_ring_ptr
= ha
->response_ring
;
5134 ha
->response_ring_ptr
++;
5135 WRT_REG_WORD(®
->mailbox5
, ha
->rsp_ring_index
);
5137 #if QLA1280_TARGET_MODE_SUPPORT
5140 pkt
= &response_entry
;
5143 dptr1
= (uint32_t *)ha
->response_ring_ptr
;
5144 dptr2
= (uint32_t *)pkt
;
5145 for (index
= 0; index
< RESPONSE_ENTRY_SIZE
/4; index
++)
5146 *dptr2
++ = *dptr1
++;
5148 /* Adjust ring index. */
5149 ha
->rsp_ring_index
++;
5150 if (ha
->rsp_ring_index
== RESPONSE_ENTRY_CNT
)
5152 ha
->rsp_ring_index
= 0;
5153 ha
->response_ring_ptr
= ha
->response_ring
;
5156 ha
->response_ring_ptr
++;
5157 WRT_REG_WORD(®
->mailbox5
, ha
->rsp_ring_index
);
5159 /* Release interrupt specific lock */
5160 QLA1280_INTR_UNLOCK(ha
);
5162 switch (pkt
->entry_type
)
5164 case ACCEPT_TGT_IO_TYPE
:
5165 qla1280_atio_entry(ha
, (atio_entry_t
*)pkt
);
5167 case IMMED_NOTIFY_TYPE
:
5168 qla1280_notify_entry(ha
, (notify_entry_t
*)pkt
);
5171 qla1280_accept_io(ha
, (ctio_ret_entry_t
*)pkt
);
5177 /* Acquire interrupt specific lock */
5178 QLA1280_INTR_LOCK(ha
);
5185 ha
->flags
.isp_abort_needed
= TRUE
;
5186 #ifdef QL_DEBUG_LEVEL_2
5187 qla1280_print("qla1280_isr: Response pointer Error\n");
5192 LEAVE("qla1280_isr");
5197 * Processes asynchronous reset.
5200 * ha = adapter block pointer.
5203 qla1280_rst_aen(scsi_qla_host_t
*ha
)
5205 #if QL1280_TARGET_MODE_SUPPORT
5206 notify_entry_t nentry
;
5210 #ifdef QL_DEBUG_LEVEL_3
5211 ENTER("qla1280_rst_aen");
5214 if (ha
->flags
.online
&& !ha
->flags
.reset_active
&&
5215 !ha
->flags
.abort_isp_active
)
5217 ha
->flags
.reset_active
= TRUE
;
5218 while (ha
->flags
.reset_marker
)
5220 /* Issue marker command. */
5221 ha
->flags
.reset_marker
= FALSE
;
5222 for (b
= 0; b
< ha
->ports
&& !ha
->flags
.reset_marker
; b
++)
5224 if (ha
->bus_settings
[b
].reset_marker
)
5226 ha
->bus_settings
[b
].reset_marker
= FALSE
;
5227 qla1280_marker(ha
, b
, 0, 0, MK_SYNC_ALL
);
5229 if (!ha
->flags
.reset_marker
)
5231 #if QL1280_TARGET_MODE_SUPPORT
5232 /* Issue notify acknowledgement command. */
5233 bzero((caddr_t
)&nentry
, sizeof(notify_entry_t
));
5235 nentry
.initiator_id
= nentry
.target_id
= b
?
5236 ha
->bus_settings
[b
].id
| BIT_7
:
5237 ha
->bus_settings
[b
].id
;
5238 qla1280_notify_entry(ha
, &nentry
);
5241 /* Asynchronous event notification */
5248 #ifdef QL_DEBUG_LEVEL_3
5249 LEAVE("qla1280_rst_aen");
5253 #if QL1280_TARGET_MODE_SUPPORT
5255 * qla1280_atio_entry
5256 * Processes received ISP accept target I/O entry.
5259 * ha = adapter block pointer.
5260 * pkt = entry pointer.
5263 qla1280_atio_entry(scsi_qla_host_t
*ha
, atio_entry_t
*pkt
)
5267 paddr32_t phy_addr
[2];
5268 paddr32_t end_addr
[2];
5274 #ifdef QL_DEBUG_LEVEL_3
5275 qla1280_print("qla1280_atio_entry: entered\n\r");
5278 t
= pkt
->initiator_id
;
5279 sense_ptr
= ha
->tsense
+ t
* TARGET_SENSE_SIZE
;
5280 a64
= (uint64_t *)&phy_addr
[0];
5281 end_a64
= (uint64_t *)&end_addr
[0];
5283 switch (pkt
->status
& ~BIT_7
)
5285 case 7: /* Path invalid */
5286 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5287 qla1280_print("qla1280_atio_entry: Path invalid\n\r");
5290 case 0x14: /* Target Bus Phase Sequence Failure */
5291 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5293 "qla1280_atio_entry: Target Bus Phase Sequence Failure\n\r");
5295 if (pkt
->status
& BIT_7
)
5297 BCOPY((caddr_t
)&pkt
->sense_data
, sense_ptr
,TARGET_SENSE_SIZE
);
5301 bzero(sense_ptr
, TARGET_SENSE_SIZE
);
5303 *(sense_ptr
+2) = SD_HARDERR
;
5304 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5305 *(sense_ptr
+12) = SC_SELFAIL
;
5307 pkt
->scsi_status
= S_CKCON
;
5308 pkt
->option_flags
|= (uint32_t)OF_SSTS
| (uint32_t)OF_NO_DATA
;
5309 if (ha
->flags
.enable_64bit_addressing
)
5310 qla1280_64bit_continue_io(ha
, pkt
, 0, 0);
5312 qla1280_32bit_continue_io(ha
, pkt
, 0, 0);
5314 case 0x16: /* Requested Capability Not Available */
5315 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5317 "qla1280_atio_entry: Target Bus Phase Sequence Failure\n\r");
5320 case 0x17: /* Bus Device Reset Message Received */
5321 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5323 "qla1280_atio_entry: Target Bus Phase Sequence Failure\n\r");
5326 case 0x3D: /* CDB Received */
5328 /* Check for invalid LUN */
5329 if (pkt
->lun
&& pkt
->cdb
[0] != SS_INQUIR
&&
5330 pkt
->cdb
[0] != SS_REQSEN
)
5331 pkt
->cdb
[0] = SS_TEST
;
5333 switch (pkt
->cdb
[0])
5336 #ifdef QL_DEBUG_LEVEL_3
5337 qla1280_print("qla1280_atio_entry: SS_TEST\n\r");
5339 bzero(sense_ptr
, TARGET_SENSE_SIZE
);
5342 pkt
->scsi_status
= S_GOOD
;
5346 *(sense_ptr
+2) = SD_ILLREQ
;
5347 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5348 *(sense_ptr
+12) = SC_INVLUN
;
5349 pkt
->scsi_status
= S_CKCON
;
5352 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5353 (uint32_t)OF_NO_DATA
;
5356 #ifdef QL_DEBUG_LEVEL_3
5357 qla1280_print("qla1280_atio_entry: SS_REQSEN\n\r");
5359 phy_addr
[0] = ha
->tsense_dma
;
5361 *a64
+= t
* TARGET_SENSE_SIZE
;
5362 if (pkt
->cdb
[4] > TARGET_SENSE_SIZE
)
5363 len
= TARGET_SENSE_SIZE
;
5366 pkt
->scsi_status
= S_GOOD
;
5367 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5368 (uint32_t)OF_DATA_IN
;
5371 #ifdef QL_DEBUG_LEVEL_3
5372 qla1280_print("qla1280_atio_entry: SS_INQUIR\n\r");
5374 bzero(sense_ptr
, TARGET_SENSE_SIZE
);
5375 phy_addr
[0] = ha
->tbuf_dma
;
5377 *a64
+= TARGET_INQ_OFFSET
;
5381 ha
->tbuf
->inq
.id_type
= ID_PROCESOR
;
5382 ha
->tbuf
->inq
.id_pqual
= ID_QOK
;
5386 ha
->tbuf
->inq
.id_type
= ID_NODEV
;
5387 ha
->tbuf
->inq
.id_pqual
= ID_QNOLU
;
5390 if (pkt
->cdb
[4] > sizeof(struct ident
))
5391 len
= sizeof(struct ident
);
5394 pkt
->scsi_status
= S_GOOD
;
5395 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5396 (uint32_t)OF_DATA_IN
;
5399 bzero(sense_ptr
, TARGET_SENSE_SIZE
);
5400 offset
= pkt
->cdb
[5];
5401 offset
|= pkt
->cdb
[4] << 8;
5402 offset
|= pkt
->cdb
[3] << 16;
5404 len
|= pkt
->cdb
[7] << 8;
5405 len
|= pkt
->cdb
[6] << 16;
5406 end_addr
[0] = phy_addr
[0] = ha
->tbuf_dma
;
5407 end_addr
[1] = phy_addr
[1] = 0;
5408 *end_a64
+= TARGET_DATA_OFFSET
+ TARGET_DATA_SIZE
;
5409 switch (pkt
->cdb
[1] & 7)
5412 #ifdef QL_DEBUG_LEVEL_3
5413 qla1280_print("qla1280_atio_entry: SM_WRDB, RW_BUF_HDATA\n\r");
5415 if (len
> TARGET_DATA_SIZE
+ 4)
5417 #ifdef QL_DEBUG_LEVEL_2
5418 qla1280_print("qla1280_atio_entry: SM_WRDB, length > buffer size\n\r");
5421 *(sense_ptr
+2) = SD_ILLREQ
;
5422 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5423 *(sense_ptr
+12) = SC_ILLCDB
;
5424 pkt
->scsi_status
= S_CKCON
;
5425 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5426 (uint32_t)OF_NO_DATA
;
5431 pkt
->scsi_status
= S_GOOD
;
5432 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5433 (uint32_t)OF_DATA_OUT
;
5434 #ifdef QL_DEBUG_LEVEL_3
5435 qla1280_print("qla1280_atio_entry: Issuing SDI_TARMOD_WRCOMP\n\r");
5437 sdi_xaen(SDI_TARMOD_WRCOMP
, ha
->cntlr
,
5438 pkt
->target_id
, pkt
->lun
, 0, offset
);
5442 #ifdef QL_DEBUG_LEVEL_2
5443 qla1280_print("qla1280_atio_entry: SM_WRDB, zero length\n\r");
5445 pkt
->scsi_status
= S_GOOD
;
5446 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5447 (uint32_t)OF_NO_DATA
;
5452 #ifdef QL_DEBUG_LEVEL_3
5453 qla1280_print("qla1280_atio_entry: SM_WRDB, RW_BUF_DATA\n\r");
5455 *a64
+= offset
+ TARGET_DATA_OFFSET
;
5456 if (pkt
->cdb
[2] != 0 || *a64
>= *end_a64
||
5457 *a64
+ len
> *end_a64
)
5459 #ifdef QL_DEBUG_LEVEL_2
5460 qla1280_print("qla1280_atio_entry: SM_WRDB, RW_BUF_DATA BAD\n\r");
5461 qla1280_print("buf_id=");
5462 qla1280_output_number((uint32_t)pkt
->cdb
[2], 16);
5463 qla1280_print(", offset=");
5464 qla1280_output_number((uint32_t)offset
, 16);
5465 qla1280_print(", length=");
5466 qla1280_output_number((uint32_t)len
, 16);
5467 qla1280_print("\n\r");
5470 *(sense_ptr
+2) = SD_ILLREQ
;
5471 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5472 *(sense_ptr
+12) = SC_ILLCDB
;
5474 pkt
->scsi_status
= S_CKCON
;
5475 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5476 (uint32_t)OF_NO_DATA
;
5480 pkt
->scsi_status
= S_GOOD
;
5481 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5482 (uint32_t)OF_DATA_OUT
;
5483 #ifdef QL_DEBUG_LEVEL_3
5484 qla1280_print("qla1280_atio_entry: Issuing SDI_TARMOD_WRCOMP\n\r");
5486 sdi_xaen(SDI_TARMOD_WRCOMP
, ha
->cntlr
,
5487 pkt
->target_id
, pkt
->lun
, 0, offset
);
5491 #ifdef QL_DEBUG_LEVEL_2
5492 qla1280_print("qla1280_atio_entry: SM_WRDB, zero length\n\r");
5494 pkt
->scsi_status
= S_GOOD
;
5495 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5496 (uint32_t)OF_NO_DATA
;
5500 #ifdef QL_DEBUG_LEVEL_2
5501 qla1280_print("qla1280_atio_entry: SM_WRDB unknown mode\n\r");
5504 *(sense_ptr
+2) = SD_ILLREQ
;
5505 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5506 *(sense_ptr
+12) = SC_ILLCDB
;
5508 pkt
->scsi_status
= S_CKCON
;
5509 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5510 (uint32_t)OF_NO_DATA
;
5515 bzero(sense_ptr
, TARGET_SENSE_SIZE
);
5516 offset
= pkt
->cdb
[5];
5517 offset
|= pkt
->cdb
[4] << 8;
5518 offset
|= pkt
->cdb
[3] << 16;
5520 len
|= pkt
->cdb
[7] << 8;
5521 len
|= pkt
->cdb
[6] << 16;
5522 end_addr
[0] = phy_addr
[0] = ha
->tbuf_dma
;
5523 end_addr
[1] = phy_addr
[1] = 0;
5524 *end_a64
+= TARGET_DATA_OFFSET
+ TARGET_DATA_SIZE
;
5525 switch (pkt
->cdb
[1] & 7)
5528 #ifdef QL_DEBUG_LEVEL_3
5529 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_HDATA\n\r");
5533 ha
->tbuf
->hdr
[0] = 0;
5535 (uint8_t)(TARGET_DATA_SIZE
>> 16);
5537 (uint8_t)(TARGET_DATA_SIZE
>> 8);
5538 ha
->tbuf
->hdr
[3] = (uint8_t)TARGET_DATA_SIZE
;
5539 if (len
> TARGET_DATA_SIZE
+ 4)
5540 len
= TARGET_DATA_SIZE
+ 4;
5541 pkt
->scsi_status
= S_GOOD
;
5542 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5543 (uint32_t)OF_DATA_IN
;
5547 #ifdef QL_DEBUG_LEVEL_2
5548 qla1280_print("qla1280_atio_entry: SM_RDDB, zero length\n\r");
5550 pkt
->scsi_status
= S_GOOD
;
5551 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5552 (uint32_t)OF_NO_DATA
;
5556 #ifdef QL_DEBUG_LEVEL_3
5557 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_DATA\n\r");
5559 *a64
+= offset
+ TARGET_DATA_OFFSET
;
5560 if (pkt
->cdb
[2] != 0 || *a64
>= *end_a64
)
5562 #ifdef QL_DEBUG_LEVEL_2
5563 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_DATA BAD\n\r");
5564 qla1280_print("buf_id=");
5565 qla1280_output_number((uint32_t)pkt
->cdb
[2], 16);
5566 qla1280_print(", offset=");
5567 qla1280_output_number((uint32_t)offset
, 16);
5568 qla1280_print("\n\r");
5571 *(sense_ptr
+2) = SD_ILLREQ
;
5572 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5573 *(sense_ptr
+12) = SC_ILLCDB
;
5575 pkt
->scsi_status
= S_CKCON
;
5576 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5577 (uint32_t)OF_NO_DATA
;
5581 if (*a64
+ len
> *end_a64
)
5582 len
= *end_a64
- *a64
;
5585 pkt
->scsi_status
= S_GOOD
;
5586 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5587 (uint32_t)OF_DATA_IN
;
5591 #ifdef QL_DEBUG_LEVEL_2
5592 qla1280_print("qla1280_atio_entry: SM_RDDB, zero length\n\r");
5594 pkt
->scsi_status
= S_GOOD
;
5595 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5596 (uint32_t)OF_NO_DATA
;
5601 #ifdef QL_DEBUG_LEVEL_3
5602 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_DESC\n\r");
5609 ha
->tbuf
->hdr
[0] = 0;
5610 if (pkt
->cdb
[2] != 0)
5612 ha
->tbuf
->hdr
[1] = 0;
5613 ha
->tbuf
->hdr
[2] = 0;
5614 ha
->tbuf
->hdr
[3] = 0;
5619 (uint8_t)(TARGET_DATA_SIZE
>> 16);
5621 (uint8_t)(TARGET_DATA_SIZE
>> 8);
5623 (uint8_t)TARGET_DATA_SIZE
;
5625 pkt
->scsi_status
= S_GOOD
;
5626 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5627 (uint32_t)OF_DATA_IN
;
5631 #ifdef QL_DEBUG_LEVEL_2
5632 qla1280_print("qla1280_atio_entry: SM_RDDB, zero length\n\r");
5634 pkt
->scsi_status
= S_GOOD
;
5635 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5636 (uint32_t)OF_NO_DATA
;
5640 #ifdef QL_DEBUG_LEVEL_2
5641 qla1280_print("qla1280_atio_entry: SM_RDDB unknown mode\n\r");
5644 *(sense_ptr
+2) = SD_ILLREQ
;
5645 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5646 *(sense_ptr
+12) = SC_ILLCDB
;
5648 pkt
->scsi_status
= S_CKCON
;
5649 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5650 (uint32_t)OF_NO_DATA
;
5655 #ifdef QL_DEBUG_LEVEL_2
5656 qla1280_print("qla1280_atio_entry: Unknown SCSI command\n\r");
5657 qla1280_dump_buffer((caddr_t
)&pkt
->cdb
[0], pkt
->cdb_len
);
5659 bzero(sense_ptr
, TARGET_SENSE_SIZE
);
5661 *(sense_ptr
+2) = SD_ILLREQ
;
5662 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5663 *(sense_ptr
+12) = SC_INVOPCODE
;
5665 pkt
->scsi_status
= S_CKCON
;
5666 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5667 (uint32_t)OF_NO_DATA
;
5670 if (ha
->flags
.enable_64bit_addressing
)
5671 qla1280_64bit_continue_io(ha
, pkt
, len
, (paddr32_t
*)&phy_addr
);
5673 qla1280_32bit_continue_io(ha
, pkt
, len
, (paddr32_t
*)&phy_addr
);
5679 #ifdef QL_DEBUG_LEVEL_3
5680 qla1280_print("qla1280_atio_entry: exiting normally\n\r");
5685 * qla1280_notify_entry
5686 * Processes received ISP immediate notify entry.
5689 * ha = adapter block pointer.
5690 * pkt = entry pointer.
5693 qla1280_notify_entry(scsi_qla_host_t
*ha
, notify_entry_t
*pkt
)
5695 #ifdef QL_DEBUG_LEVEL_3
5696 qla1280_print("qla1280_notify_entry: entered\n\r");
5699 /* Acknowledge immediate notify */
5700 qla1280_notify_ack(ha
, pkt
);
5702 /* Issue notify entry to increment resource count */
5703 qla1280_immed_notify(ha
, pkt
);
5705 #ifdef QL_DEBUG_LEVEL_3
5706 qla1280_print("qla1280_notify_entry: exiting normally\n\r");
5710 #endif /* QLA1280_TARGET_MODE_SUPPORT */
5712 * qla1280_status_entry
5713 * Processes received ISP status entry.
5716 * ha = adapter block pointer.
5717 * pkt = entry pointer.
5718 * done_q_first = done queue first pointer.
5719 * done_q_last = done queue last pointer.
5722 qla1280_status_entry(scsi_qla_host_t
*ha
, sts_entry_t
*pkt
, srb_t
**done_q_first
,
5723 srb_t
**done_q_last
)
5726 uint8_t sense_sz
= 0;
5731 #ifdef QL_DEBUG_LEVEL_3
5732 ENTER("qla1280_status_entry");
5735 /* Validate handle. */
5736 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
5737 sp
= ha
->outstanding_cmds
[pkt
->handle
];
5743 /* Free outstanding command slot. */
5744 ha
->outstanding_cmds
[pkt
->handle
] = 0;
5747 /* Generate LU queue on cntrl, target, LUN */
5748 b
= SCSI_BUS_32(cp
);
5749 t
= SCSI_TCN_32(cp
);
5750 l
= SCSI_LUN_32(cp
);
5751 q
= LU_Q(ha
, b
, t
, l
);
5752 if( pkt
->comp_status
|| pkt
->scsi_status
)
5754 DEBUG(qla1280_print( "scsi: comp_status = ");)
5755 DEBUG(qla1280_output_number((uint32_t)pkt
->comp_status
,16);)
5756 DEBUG(qla1280_print( ", ");)
5757 DEBUG(qla1280_print( " scsi_status = ");)
5758 DEBUG(qla1280_output_number((uint32_t)pkt
->scsi_status
,16);)
5759 DEBUG(qla1280_print( "\n\r");)
5760 DEBUG(qla1280_print(", handle = ");)
5761 DEBUG(qla1280_output_number((uint32_t)pkt
->handle
, 16);)
5762 DEBUG(qla1280_print("\n\r");)
5766 if ( pkt
->scsi_status
& SS_BUSY_CONDITION
&&
5767 pkt
->scsi_status
!= SS_RESERVE_CONFLICT
)
5769 CMD_RESULT(cp
) = (int) (DID_BUS_BUSY
<< 16) |
5770 (pkt
->scsi_status
& 0xff);
5775 /* Save ISP completion status */
5776 CMD_RESULT(cp
) = qla1280_return_status( pkt
, cp
);
5778 if (pkt
->scsi_status
& SS_CHECK_CONDITION
)
5780 BZERO(cp
->sense_buffer
, CMD_SNSLEN(cp
));
5781 if (pkt
->comp_status
!= CS_ARS_FAILED
)
5783 if ( pkt
->req_sense_length
< CMD_SNSLEN(cp
) )
5784 sense_sz
= pkt
->req_sense_length
;
5786 sense_sz
= CMD_SNSLEN(cp
) - 1;
5788 BCOPY((caddr_t
)&pkt
->req_sense_data
, cp
->sense_buffer
, sense_sz
);
5791 #ifdef QL_DEBUG_LEVEL_2
5792 DEBUG(qla1280_print(
5793 "qla1280_status_entry: Check condition Sense data, b");)
5794 DEBUG(qla1280_output_number((uint32_t)b
, 10);)
5795 DEBUG(qla1280_print("t");)
5796 DEBUG(qla1280_output_number((uint32_t)t
, 10);)
5797 DEBUG(qla1280_print("d");)
5798 DEBUG(qla1280_output_number((uint32_t)l
, 10);)
5799 DEBUG(qla1280_print("\n\r");)
5800 DEBUG(if (sense_sz
))
5801 DEBUG(qla1280_dump_buffer(cp
->sense_buffer
, sense_sz
);)
5805 /* Place command on done queue. */
5806 qla1280_done_q_put(sp
, done_q_first
, done_q_last
);
5810 #ifdef QL_DEBUG_LEVEL_2
5811 qla1280_print("qla1280_status_entry: ISP Invalid handle\n\r");
5813 printk(KERN_WARNING
"qla1280: Status Entry invalid handle\n");
5814 ha
->flags
.isp_abort_needed
= TRUE
;
5816 #ifdef QL_DEBUG_LEVEL_3
5817 LEAVE("qla1280_status_entry");
5822 * qla1280_error_entry
5823 * Processes error entry.
5826 * ha = adapter block pointer.
5827 * pkt = entry pointer.
5828 * done_q_first = done queue first pointer.
5829 * done_q_last = done queue last pointer.
5832 qla1280_error_entry(scsi_qla_host_t
*ha
, response_t
*pkt
, srb_t
**done_q_first
,
5833 srb_t
**done_q_last
)
5837 #ifdef QL_DEBUG_LEVEL_3
5838 ENTER("qla1280_error_entry");
5841 #ifdef QL_DEBUG_LEVEL_2
5842 if (pkt
->entry_status
& BIT_3
)
5843 qla1280_print("qla1280_error_entry: BAD PAYLOAD flag error\n\r");
5844 else if (pkt
->entry_status
& BIT_2
)
5845 qla1280_print("qla1280_error_entry: BAD HEADER flag error\n\r");
5846 else if (pkt
->entry_status
& BIT_1
)
5847 qla1280_print("qla1280_error_entry: FULL flag error\n\r");
5849 qla1280_print("qla1280_error_entry: UNKNOWN flag error\n\r");
5852 /* Validate handle. */
5853 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
5854 sp
= ha
->outstanding_cmds
[pkt
->handle
];
5860 /* Free outstanding command slot. */
5861 ha
->outstanding_cmds
[pkt
->handle
] = 0;
5863 /* Bad payload or header */
5864 if (pkt
->entry_status
& (BIT_3
+ BIT_2
))
5866 /* Bad payload or header, set error status. */
5867 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
5868 CMD_RESULT(sp
->cmd
) = (int) DID_ERROR
<< 16;
5870 else if (pkt
->entry_status
& BIT_1
) /* FULL flag */
5872 CMD_RESULT(sp
->cmd
) = (int) DID_BUS_BUSY
<< 16;
5876 /* Set error status. */
5877 CMD_RESULT(sp
->cmd
) =(int) DID_ERROR
<< 16;
5879 /* Place command on done queue. */
5880 qla1280_done_q_put(sp
, done_q_first
, done_q_last
);
5882 #if QLA1280_64BIT_SUPPORT
5883 else if (pkt
->entry_type
== COMMAND_A64_TYPE
)
5885 #ifdef QL_DEBUG_LEVEL_2
5886 qla1280_print("qla1280_error_entry: ISP Invalid handle\n\r");
5888 printk(KERN_WARNING
"!qla1280: Error Entry invalid handle");
5889 ha
->flags
.isp_abort_needed
= TRUE
;
5893 #ifdef QL_DEBUG_LEVEL_3
5894 LEAVE("qla1280_error_entry");
5900 * Resets ISP and aborts all outstanding commands.
5903 * ha = adapter block pointer.
5909 qla1280_abort_isp(scsi_qla_host_t
*ha
)
5911 device_reg_t
*reg
= ha
->iobase
;
5917 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
5918 unsigned long cpu_flags
= 0;
5921 #ifdef QL_DEBUG_LEVEL_3
5922 ENTER("qla1280_abort_isp");
5926 ha
->flags
.isp_abort_needed
= FALSE
;
5927 if (!ha
->flags
.abort_isp_active
&& ha
->flags
.online
)
5929 ha
->flags
.abort_isp_active
= TRUE
;
5931 /* Disable ISP interrupts. */
5932 WRT_REG_WORD(®
->ictrl
, 0);
5934 /* Dequeue all commands in outstanding command list. */
5935 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
5937 sp
= ha
->outstanding_cmds
[cnt
];
5940 ha
->outstanding_cmds
[cnt
] = 0;
5942 /* Generate LU queue on controller, target, LUN */
5943 b
= SCSI_BUS_32(sp
->cmd
);
5944 t
= SCSI_TCN_32(sp
->cmd
);
5945 l
= SCSI_LUN_32(sp
->cmd
);
5947 q
= (scsi_lu_t
*)LU_Q(ha
, b
, t
, l
);
5949 /* Reset outstanding command count. */
5951 q
->q_flag
&= ~QLA1280_QBUSY
;
5954 /* Adjust watchdog timer for command. */
5955 /* if (sp->flags & SRB_WATCHDOG)
5956 sp->timeout += 2; */
5958 /* Place request back on top of device queue. */
5959 /* sp->flags &= ~(SRB_SENT | SRB_TIMEOUT); */
5961 qla1280_putq_t(q
, sp
);
5965 /* If firmware needs to be loaded */
5966 if (qla1280_isp_firmware(ha
))
5968 if (!(status
= qla1280_chip_diag(ha
)))
5969 status
= qla1280_setup_chip(ha
);
5974 /* Setup adapter based on NVRAM parameters. */
5975 qla1280_nvram_config(ha
);
5977 if (!(status
= qla1280_init_rings(ha
)))
5979 /* Issue SCSI reset. */
5980 for (b
= 0; b
< ha
->ports
; b
++)
5982 qla1280_bus_reset(ha
, b
);
5986 /* Issue marker command. */
5987 ha
->flags
.reset_marker
= FALSE
;
5988 for (b
= 0; b
< ha
->ports
; b
++)
5990 ha
->bus_settings
[b
].reset_marker
= FALSE
;
5991 qla1280_marker(ha
, b
, 0, 0, MK_SYNC_ALL
);
5993 }while (ha
->flags
.reset_marker
);
5995 /* Enable host adapter target mode. */
5996 for (b
= 0; b
< ha
->ports
; b
++)
5998 if (!(status
= qla1280_enable_tgt(ha
, b
)))
6000 for (cnt
= 0; cnt
< MAX_LUNS
; cnt
++)
6002 /* qla1280_enable_lun(ha, b, cnt); */
6012 /* Enable ISP interrupts. */
6013 WRT_REG_WORD(®
->ictrl
, ISP_EN_INT
+ ISP_EN_RISC
);
6014 ha
->flags
.abort_isp_active
= FALSE
;
6015 /* Restart queues that may have been stopped. */
6016 qla1280_restart_queues(ha
);
6025 "qla1280: ISP error recovery failed, board disabled");
6026 qla1280_reset_adapter(ha
);
6027 qla1280_abort_queues(ha
);
6029 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
6030 qla1280_print("qla1280_abort_isp: **** FAILED ****\n\r");
6033 #ifdef QL_DEBUG_LEVEL_3
6035 LEAVE("qla1280_abort_isp");
6043 * qla1280_restart_queues
6044 * Restart all device queues.
6047 * ha = adapter block pointer.
6050 qla1280_restart_queues(scsi_qla_host_t
*ha
)
6055 #ifdef QL_DEBUG_LEVEL_3
6056 ENTER("qla1280_restart_queues");
6059 for (b
= 0; b
< ha
->ports
; b
++)
6060 for (t
= 0; t
< MAX_TARGETS
; t
++)
6061 for (l
= 0; l
< MAX_LUNS
; l
++)
6063 q
= (scsi_lu_t
*) LU_Q(ha
, b
, t
, l
);
6066 /* Acquire LU queue specific lock */
6067 QLA1280_SCSILU_LOCK(q
);
6070 qla1280_next(ha
, q
, b
);
6072 /* Release LU queue specific lock */
6073 QLA1280_SCSILU_UNLOCK(q
);
6076 #ifdef QL_DEBUG_LEVEL_3
6077 qla1280_print("qla1280_restart_queues: exiting normally\n");
6082 * qla1280_abort_queue_single
6083 * Abort all commands on a device queues.
6086 * ha = adapter block pointer.
6088 STATIC
void qla1280_abort_queue_single(scsi_qla_host_t
*ha
,uint32_t b
,uint32_t t
,uint32_t l
,uint32_t stat
)
6091 srb_t
*sp
, *sp_next
;
6093 ENTER("qla1280_abort_queue_single");
6094 q
= (scsi_lu_t
* )LU_Q(ha
, b
, t
, l
);
6097 /* Acquire LU queue specific lock */
6098 QLA1280_SCSILU_LOCK(q
);
6101 q
->q_first
= q
->q_last
= NULL
;
6103 QLA1280_SCSILU_UNLOCK(q
);
6107 sp_next
= sp
->s_next
;
6108 CMD_RESULT(sp
->cmd
) = stat
;
6109 qla1280_done_q_put(sp
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
6113 LEAVE("qla1280_abort_queue_single");
6117 * qla1280_abort_queues
6118 * Abort all commands on device queues.
6121 * ha = adapter block pointer.
6124 qla1280_abort_queues(scsi_qla_host_t
*ha
)
6128 ENTER("qla1280_abort_queues");
6130 for (b
= 0; b
< ha
->ports
; b
++)
6131 for (t
= 0; t
< MAX_TARGETS
; t
++)
6132 for (l
= 0; l
< MAX_LUNS
; l
++)
6133 qla1280_abort_queue_single(ha
,b
,t
,l
,DID_RESET
);
6135 LEAVE("qla1280_abort_queues");
6139 * qla1280_debounce_register
6140 * Debounce register.
6143 * port = register address.
6149 qla1280_debounce_register(volatile uint16_t *addr
)
6151 volatile uint16_t ret
;
6152 volatile uint16_t ret2
;
6156 ret
= RD_REG_WORD(addr
);
6157 ret2
= RD_REG_WORD(addr
);
6158 }while (ret
!= ret2
);
6165 * Declarations for load module
6167 static Scsi_Host_Template driver_template
= QLA1280_LINUX_TEMPLATE
;
6169 #include "scsi_module.c"
6171 /************************************************************************
6172 * qla1280_check_for_dead_scsi_bus *
6174 * This routine checks for a dead SCSI bus *
6175 ************************************************************************/
6176 #define SET_SXP_BANK 0x0100
6177 #define SCSI_PHASE_INVALID 0x87FF
6178 int qla1280_check_for_dead_scsi_bus(scsi_qla_host_t
*ha
, srb_t
*sp
)
6180 uint16_t config_reg
, scsi_control
;
6181 device_reg_t
*reg
= ha
->iobase
;
6186 * If SCSI Bus is Dead because of bad termination,
6187 * we will return a status of Selection timeout.
6191 b
= SCSI_BUS_32(cp
);
6192 if (ha
->bus_settings
[b
].scsi_bus_dead
)
6194 WRT_REG_WORD(®
->host_cmd
, HC_PAUSE_RISC
);
6195 config_reg
= RD_REG_WORD(®
->cfg_1
);
6196 WRT_REG_WORD(®
->cfg_1
,SET_SXP_BANK
);
6197 scsi_control
= RD_REG_WORD(®
->scsiControlPins
);
6198 WRT_REG_WORD(®
->cfg_1
,config_reg
);
6199 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
6201 if (scsi_control
== SCSI_PHASE_INVALID
)
6203 CMD_RESULT(cp
) = DID_NO_CONNECT
<< 16;
6204 CMD_HANDLE(cp
) = (unsigned char *) 0;
6205 /* ha->actthreads--; */
6206 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
6208 (*(cp
)->scsi_done
)(cp
);
6211 (*(cp
)->scsi_done
)(cp
);
6213 return(TRUE
); /* bus is dead */
6217 ha
->bus_settings
[b
].scsi_bus_dead
= FALSE
;
6218 ha
->bus_settings
[b
].failed_reset_count
= 0;
6221 return(FALSE
); /* bus is not dead */
6225 qla12160_set_target_parameters(scsi_qla_host_t
*ha
, uint32_t b
, uint32_t t
, uint32_t l
, nvram160_t
*nv
)
6227 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
6229 /* Set Target Parameters. */
6230 mb
[0] = MBC_SET_TARGET_PARAMETERS
;
6231 mb
[1] = (uint16_t)(b
? t
| BIT_7
:t
);
6233 mb
[2] = nv
->bus
[b
].target
[t
].parameter
.c
<< 8;
6234 mb
[2] |= TP_AUTO_REQUEST_SENSE
;
6235 mb
[2] &= ~TP_STOP_QUEUE
;
6236 mb
[2] |= (nv
->bus
[b
].target
[t
].flags
.enable_ppr
<< 5);
6237 mb
[3] = nv
->bus
[b
].target
[t
].flags
.sync_offset
<< 8;
6238 mb
[3] |= nv
->bus
[b
].target
[t
].sync_period
;
6240 mb
[6] = nv
->bus
[b
].target
[t
].flags
.ppr_options
<< 8;
6241 mb
[6] |= nv
->bus
[b
].target
[t
].flags
.ppr_bus_width
;
6242 return( qla1280_mailbox_command(ha
, BIT_6
|BIT_3
|BIT_2
|BIT_1
|BIT_0
, &mb
[0]) ) ;
6246 qla12160_get_target_parameters(scsi_qla_host_t
*ha
, uint32_t b
, uint32_t t
, uint32_t l
)
6248 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
6250 mb
[0] = MBC_GET_TARGET_PARAMETERS
;
6251 mb
[1] = (uint16_t)(b
? t
| BIT_7
:t
);
6253 qla1280_mailbox_command(ha
, BIT_6
|BIT_3
|BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
6255 printk(KERN_INFO
"scsi(%d:%d:%d:%d): Synchronous tranfer at period %d, offset %d. \n",
6256 (int)ha
->host_no
, b
, t
, l
, (mb
[3] &0xff), (mb
[3] >> 8));
6258 if ( (mb
[2] & BIT_5
) && ((mb
[6] >> 8) & 0xff) >= 2 )
6259 printk(KERN_INFO
"scsi(%d:%d:%d:%d): Dual Transition enabled.\n",
6260 (int)ha
->host_no
, b
, t
, l
);
6264 #ifdef QL_DEBUG_ROUTINES
6265 /****************************************************************************/
6266 /* Driver Debug Functions. */
6267 /****************************************************************************/
6270 * Get byte from I/O port
6273 qla1280_getbyte(uint8_t *port
)
6277 #if MEMORY_MAPPED_IO
6280 ret
= inb((int)port
);
6285 qla1280_print("qla1280_getbyte: address = ");
6286 qla1280_output_number((uint32_t)port
, 16);
6287 qla1280_print(" data = 0x");
6288 qla1280_output_number((uint32_t)ret
, 16);
6289 qla1280_print("\n\r");
6296 * Get word from I/O port
6299 qla1280_getword(uint16_t *port
)
6303 #if MEMORY_MAPPED_IO
6306 ret
= inw((int)port
);
6311 qla1280_print("qla1280_getword: address = ");
6312 qla1280_output_number((uint32_t)port
, 16);
6313 qla1280_print(" data = 0x");
6314 qla1280_output_number((uint32_t)ret
, 16);
6315 qla1280_print("\n\r");
6322 * Get double word from I/O port
6325 qla1280_getdword(uint32_t *port
)
6329 #if MEMORY_MAPPED_IO
6332 ret
= inl((int)port
);
6337 qla1280_print("qla1280_getdword: address = ");
6338 qla1280_output_number((uint32_t)port
, 16);
6339 qla1280_print(" data = 0x");
6340 qla1280_output_number((uint32_t)ret
, 16);
6341 qla1280_print("\n\r");
6348 * Send byte to I/O port
6351 qla1280_putbyte(uint8_t *port
, uint8_t data
)
6353 #if MEMORY_MAPPED_IO
6356 outb(data
, (int)port
);
6361 qla1280_print("qla1280_putbyte: address = ");
6362 qla1280_output_number((uint32_t)port
, 16);
6363 qla1280_print(" data = 0x");
6364 qla1280_output_number((uint32_t)data
, 16);
6365 qla1280_print("\n\r");
6370 * Send word to I/O port
6373 qla1280_putword(uint16_t *port
, uint16_t data
)
6375 #if MEMORY_MAPPED_IO
6378 #ifdef _LINUX_IOPORTS
6379 outw(data
, (int)port
);
6381 outw((int)port
, data
);
6387 qla1280_print("qla1280_putword: address = ");
6388 qla1280_output_number((uint32_t)port
, 16);
6389 qla1280_print(" data = 0x");
6390 qla1280_output_number((uint32_t)data
, 16);
6391 qla1280_print("\n\r");
6396 * Send double word to I/O port
6399 qla1280_putdword(uint32_t *port
, uint32_t data
)
6401 #if MEMORY_MAPPED_IO
6404 #ifdef _LINUX_IOPORTS
6405 outl(data
,(int)port
);
6407 outl((int)port
, data
);
6413 qla1280_print("qla1280_putdword: address = ");
6414 qla1280_output_number((uint32_t)port
, 16);
6415 qla1280_print(" data = 0x");
6416 qla1280_output_number((uint32_t)data
, 16);
6417 qla1280_print("\n\r");
6422 * Dummy function to prevent warnings for
6423 * declared and unused debug functions
6430 qla1280_getdword(0);
6431 qla1280_putbyte(0, 0);
6432 qla1280_putword(0, 0);
6433 qla1280_putdword(0, 0);
6437 * Out character to COM2 port.
6438 * PORT must be at standard address for COM2 = 0x2F8,
6441 #define OUTB(addr,data) outb((data),(addr))
6444 qla1280_putc(uint8_t c
)
6446 #ifdef QL_DEBUG_CONSOLE
6449 int com_addr
= 0x2f8;
6450 int hardware_flow_control
= 1;
6451 int software_flow_control
= 0;
6454 /* Wait for transmitter holding and shift registers for empty. */
6457 data
= inb(com_addr
+5);
6458 }while (!(data
& BIT_6
));
6461 * Set BAUD rate for COM2 to 19200 (0x6)
6464 /* Select rate divisor. */
6465 OUTB(com_addr
+3, 0x83);
6467 /* BAUD rate divisor LSB. */
6468 OUTB(com_addr
, 0xc); /* 0xC = 9600 baud */
6470 /* BAUD rate divisor MSB. */
6471 OUTB(com_addr
+1, 0);
6473 /* Set No parity, 8 bits, 1 stop bit and
6474 select interrupt enable register. */
6475 OUTB(com_addr
+3, 3);
6477 /* Disable interrupts. */
6478 OUTB(com_addr
+1, 0);
6480 /* Set data terminal ready and request to send */
6483 if (hardware_flow_control
)
6485 /* Wait for clear-to-send and data-set-ready */
6488 data
= inb(com_addr
+6) & (BIT_5
+ BIT_4
);
6489 }while (data
!= (BIT_5
+ BIT_4
));
6491 else if (software_flow_control
)
6493 /* Test for data ready. */
6494 data
= inb(com_addr
+5);
6498 data
= inb(com_addr
);
6507 data
= inb(com_addr
+5);
6508 }while (!(data
& BIT_0
));
6509 data
= inb(com_addr
);
6510 }while (data
!= '\021');
6515 /* Output character. */
6521 * Out NULL terminated string to COM port.
6524 qla1280_print(caddr_t s
)
6528 #ifdef QL_DEBUG_CONSOLE
6531 /* Output string. */
6539 * Output long number to COM port.
6542 qla1280_output_number(uint32_t n
, uint8_t base
)
6545 int8_t *s
= &str
[11];
6551 if (base
== 10 || base
== 16)
6553 if (base
== 16 && n
> 9)
6585 qla1280_dump_buffer(caddr_t b
, uint32_t size
)
6593 " 0 1 2 3 4 5 6 7 8 9 Ah Bh Ch Dh Eh Fh\n\r");
6595 "---------------------------------------------------------------\n\r");
6597 for (cnt
= 0; cnt
< size
; )
6602 qla1280_output_number((uint32_t)c
, 16);
6605 qla1280_print("\n\r");
6612 qla1280_print("\n\r");
6615 /**************************************************************************
6616 * ql1280_print_scsi_cmd
6618 **************************************************************************/
6619 void qla1280_print_scsi_cmd(Scsi_Cmnd
*cmd
)
6621 scsi_qla_host_t
*ha
;
6622 struct Scsi_Host
*host
= cmd
->host
;
6624 /* struct scatterlist *sg; */
6627 ha
= (scsi_qla_host_t
*) host
->hostdata
;
6630 sp
= (srb_t
*) CMD_SP(cmd
);
6631 sprintf(debug_buff
,"SCSI Command @= 0x%p, Handle=0x%p\n\r", cmd
, CMD_HANDLE(cmd
));
6632 qla1280_print(debug_buff
);
6633 sprintf(debug_buff
," chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n\r",
6634 cmd
->channel
, cmd
->target
, cmd
->lun
, cmd
->cmd_len
);
6635 qla1280_print(debug_buff
);
6636 qla1280_print(" CDB = ");
6637 for (i
= 0; i
< cmd
->cmd_len
; i
++)
6639 sprintf(debug_buff
,"0x%02x ", cmd
->cmnd
[i
]);
6640 qla1280_print(debug_buff
);
6642 sprintf(debug_buff
," seg_cnt =%d\n\r",cmd
->use_sg
);
6643 qla1280_print(debug_buff
);
6644 sprintf(debug_buff
," request buffer=0x%p, request buffer len=0x%x\n\r",cmd
->request_buffer
,cmd
->request_bufflen
);
6645 qla1280_print(debug_buff
);
6646 /* if( cmd->use_sg )
6648 sg = (struct scatterlist *) cmd->request_buffer;
6649 qla1280_print(" SG buffer: \n\r");
6650 qla1280_dump_buffer((caddr_t)sg, (cmd->use_sg*sizeof(struct scatterlist)) );
6652 sprintf(debug_buff
," tag=%d, flags=0x%x, transfersize=0x%x \n\r",
6653 cmd
->tag
, cmd
->flags
,cmd
->transfersize
);
6654 qla1280_print(debug_buff
);
6655 sprintf(debug_buff
," Pid=%d, SP=0x%p\n\r", (int)cmd
->pid
, CMD_SP(cmd
));
6656 qla1280_print(debug_buff
);
6657 sprintf(debug_buff
," r_start=0x%lx, u_start=0x%lx\n\r",sp
->r_start
,sp
->u_start
);
6658 qla1280_print(debug_buff
);
6659 sprintf(debug_buff
," underflow size = 0x%x, direction=0x%x, req.cmd=0x%x \n\r", cmd
->underflow
, sp
->dir
,cmd
->request
.cmd
);
6660 qla1280_print(debug_buff
);
6662 /**************************************************************************
6663 * ql1280_dump_device
6665 **************************************************************************/
6667 ql1280_dump_device(scsi_qla_host_t
*ha
)
6673 qla1280_print("Outstanding Commands on controller:\n\r");
6674 for ( i
=0; i
< MAX_OUTSTANDING_COMMANDS
; i
++ )
6676 if( (sp
= ha
->outstanding_cmds
[i
]) == NULL
)
6678 if( (cp
= sp
->cmd
) == NULL
)
6680 qla1280_print_scsi_cmd(cp
);
6686 #ifdef QLA1280_UNUSED
6687 /**************************************************************************
6690 **************************************************************************/
6691 static void qla1280_dump_regs(struct Scsi_Host
*host
)
6693 printk("Mailbox registers:\n");
6694 printk("qla1280 : mbox 0 0x%04x \n", inw(host
->io_port
+ 0x70));
6695 printk("qla1280 : mbox 1 0x%04x \n", inw(host
->io_port
+ 0x72));
6696 printk("qla1280 : mbox 2 0x%04x \n", inw(host
->io_port
+ 0x74));
6697 printk("qla1280 : mbox 3 0x%04x \n", inw(host
->io_port
+ 0x76));
6698 printk("qla1280 : mbox 4 0x%04x \n", inw(host
->io_port
+ 0x78));
6699 printk("qla1280 : mbox 5 0x%04x \n", inw(host
->io_port
+ 0x7a));
6706 /**************************************************************************
6709 **************************************************************************/
6710 static void qla1280_panic(char *cp
, struct Scsi_Host
*host
)
6712 scsi_qla_host_t
*ha
;
6715 ha
= (scsi_qla_host_t
*) host
->hostdata
;
6716 printk("qla1280 - PANIC: %s\n",cp
);
6717 printk("Current time=0x%lx\n", jiffies
);
6718 printk("Number of pending commands =0x%lx\n", ha
->actthreads
);
6719 printk("Number of SCSI queued commands =0x%lx\n", ha
->qthreads
);
6720 printk("Number of free entries = (%d)\n",ha
->req_q_cnt
);
6721 printk("Request Queue @ 0x%lx, Response Queue @ 0x%lx\n",
6724 printk("Request In Ptr %d\n", ha
->req_ring_index
);
6725 fp
= (long *) &ha
->flags
;
6726 printk("HA flags =0x%lx\n", *fp
);
6727 DEBUG2(ql_debug_print
= 1;)
6728 /* DEBUG2(ql1280_dump_device((scsi_qla_host_t *) host->hostdata)); */
6729 #ifdef QLA1280_UNUSED
6730 qla1280_dump_regs(host
);
6744 #ifdef QLA1280_UNUSED
6745 static void qla1280_set_flags(char * s
)
6750 /**************************************************************************
6753 * Handle Linux boot parameters. This routine allows for assigning a value
6754 * to a parameter with a ':' between the parameter and the value.
6755 * ie. qla1280=max_reqs:0x0A,verbose
6756 **************************************************************************/
6758 qla1280_setup(char *s
, int *dummy
)
6760 char *end
, *str
, *cp
;
6762 #ifdef QLA1280_UNUSED
6771 { "dump_regs", 9, &qla1280_dump_regs
, 0
6773 { "verbose", 7, &qla1280_set_flags
, 0x1
6780 printk("scsi: Processing Option str = %s\n", s
);
6781 end
= strchr(s
, '\0');
6782 /* locate command */
6784 for( cp
= s
; *cp
&& cp
!= end
; cp
++ )
6786 cp
= qla1280_get_token(cp
, str
);
6787 printk("scsi: token str = %s\n", str
);
6788 /* if found execute routine */
6794 static char *qla1280_get_token(char *cmdline
, char *str
)
6796 register char *cp
= cmdline
;
6798 /* skip preceeding spaces */
6799 while(strchr(cp
,' '))
6801 /* symbol starts here */
6803 /* skip char if not a space or : */
6804 while (*cp
&& !( strchr(cp
,' ') || strchr(cp
,':')) )
6811 * Overrides for Emacs so that we almost follow Linus's tabbing style.
6812 * Emacs will notice this stuff at the end of the file and automatically
6813 * adjust the settings for this buffer only. This must remain at the end
6815 * ---------------------------------------------------------------------------
6818 * c-brace-imaginary-offset: 0
6819 * c-brace-offset: -2
6820 * c-argdecl-indent: 2
6821 * c-label-offset: -2
6822 * c-continued-statement-offset: 2
6823 * c-continued-brace-offset: 0
6824 * indent-tabs-mode: nil