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 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
);
1085 queue_task(&ha
->run_qla_bh
,&tq_scheduler
);
1086 ha
->flags
.dpc_sched
= TRUE
;
1091 /* Set an invalid handle until we issue the command to ISP */
1092 /* then we will set the real handle value. */
1093 handle
= INVALID_HANDLE
;
1094 CMD_HANDLE(cmd
) = (unsigned char *)handle
;
1096 /* Bookkeeping information */
1097 sp
->r_start
= jiffies
; /* time the request was recieved */
1100 /* add the command to our queue */
1102 qla1280_putq_t(q
,sp
);
1104 DEBUG(sprintf(debug_buff
,"qla1280_queuecmd: queue pid=%d, hndl=0x%x\n\r",cmd
->pid
,handle
));
1105 DEBUG(qla1280_print(debug_buff
));
1107 /* send command to adapter */
1109 if (q
->q_outcnt
== 0)
1110 qla1280_restart_queues(ha
);
1114 LEAVE("qla1280_queuecommand");
1118 /**************************************************************************
1120 * Abort the speciifed SCSI command(s).
1121 **************************************************************************/
1123 qla1280_abort(Scsi_Cmnd
*cmd
)
1125 scsi_qla_host_t
*ha
;
1127 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1128 unsigned long cpu_flags
= 0;
1130 struct Scsi_Host
*host
;
1133 int return_status
= SCSI_ABORT_SUCCESS
;
1139 ENTER("qla1280_abort");
1141 ha
= (scsi_qla_host_t
*) cmd
->host
->hostdata
;
1145 /* Get the SCSI request ptr */
1146 sp
= (srb_t
*) CMD_SP(cmd
);
1147 handle
= (u_long
) CMD_HANDLE(cmd
);
1148 if (qla1280_verbose
)
1149 printk("scsi(%d): ABORT Command=0x%lx, handle=0x%lx\n",(int)ha
->host_no
,(long)cmd
,handle
);
1151 /* Check for pending interrupts. */
1155 /* we never got this command */
1156 printk(KERN_INFO
"qla1280: Aborting a NULL handle\n");
1158 return(SCSI_ABORT_NOT_RUNNING
); /* no action - we don't have command */
1160 data
= qla1280_debounce_register(&ha
->iobase
->istatus
);
1161 if( !(ha
->flags
.in_isr
) && (data
& RISC_INT
) )
1163 /* put any pending command in done queue */
1164 qla1280_isr(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1167 handle
= (u_long
) CMD_HANDLE(cmd
);
1169 /* Generate LU queue on bus, target, LUN */
1170 b
= SCSI_BUS_32(cmd
);
1171 t
= SCSI_TCN_32(cmd
);
1172 l
= SCSI_LUN_32(cmd
);
1173 if((q
= LU_Q(ha
, b
, t
, l
)) == NULL
)
1176 /* No lun queue -- command must not be active */
1178 printk(KERN_WARNING
"qla1280 (%d:%d:%d): No LUN queue for the specified device\n",(int)b
,(int)t
,(int)l
);
1179 return(SCSI_ABORT_NOT_RUNNING
); /* no action - we don't have command */
1182 #if AUTO_ESCALATE_ABORT
1183 if ( (sp
->flags
& SRB_ABORTED
) )
1186 DEBUG(qla1280_print("qla1280_abort: Abort escalayted - returning SCSI_ABORT_SNOOZE.\n\r"));
1187 return(SCSI_ABORT_SNOOZE
);
1191 if ( (sp
->flags
& SRB_ABORT_PENDING
) )
1195 if( qla1280_verbose
)
1196 printk("scsi(): Command has a pending abort message - ABORT_PENDING.\n");
1197 DEBUG(qla1280_print("qla1280: Command has a pending abort message - ABORT_PENDING.\n\r"));
1198 return(SCSI_ABORT_PENDING
);
1202 printk("Scsi layer issued a ABORT command= 0x%x\n",(int)cmd
);
1203 DEBUG2(qla1280_print_scsi_cmd(cmd
));
1206 ha
->flags
.in_abort
= TRUE
;
1208 * Normally, would would need to search our queue for the specified command
1209 * but; since our sp contains the cmd ptr, we can just remove it from our
1212 if( !(sp
->flags
&SRB_SENT
) )
1215 if( qla1280_verbose
)
1216 printk("scsi(): Command returned from queue aborted.\n");
1217 DEBUG(qla1280_print("qla1280: Command returned from queue aborted.\n\r"));
1218 /* Remove srb from SCSI LU queue. */
1219 qla1280_removeq(q
, sp
);
1220 sp
->flags
|= SRB_ABORTED
;
1221 CMD_RESULT(cmd
) = DID_ABORT
<< 16;
1222 qla1280_done_q_put(sp
, &ha
->done_q_first
, &ha
->done_q_last
);
1223 return_status
= SCSI_ABORT_SUCCESS
;
1226 { /* find the command in our active list */
1227 for (i
= 1; i
< MAX_OUTSTANDING_COMMANDS
; i
++)
1229 if( sp
== ha
->outstanding_cmds
[i
] )
1232 DEBUG(qla1280_print("qla1280: RISC aborting command.\n\r"));
1233 qla1280_abort_command(ha
,sp
);
1234 return_status
= SCSI_ABORT_PENDING
;
1241 qla1280_panic("qla1280_abort",ha
->host
);
1244 return_status
= SCSI_ABORT_NOT_RUNNING
; /* no action - we don't have command */
1246 DEBUG(sprintf(debug_buff
, "qla1280_abort: Aborted status returned = 0x%x.\n\r",return_status
));
1247 DEBUG(qla1280_print(debug_buff
));
1249 if( ha
->done_q_first
)
1250 qla1280_done(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1253 qla1280_restart_queues(ha
);
1255 ha
->flags
.in_abort
= FALSE
;
1258 LEAVE("qla1280_abort");
1260 return(return_status
);
1263 /**************************************************************************
1265 * The reset function will reset the SCSI bus and abort any executing
1269 * cmd = Linux SCSI command packet of the command that cause the
1271 * flags = SCSI bus reset option flags (see scsi.h)
1274 * DID_RESET in cmd.host_byte of aborted command(s)
1277 * Resetting the bus always succeeds - is has to, otherwise the
1278 * kernel will panic! Try a surgical technique - sending a BUS
1279 * DEVICE RESET message - on the offending target before pulling
1280 * the SCSI bus reset line.
1281 **************************************************************************/
1283 qla1280_reset(Scsi_Cmnd
*cmd
, unsigned int flags
)
1285 scsi_qla_host_t
*ha
;
1286 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1287 unsigned long cpu_flags
= 0;
1300 action_t action
= ADAPTER_RESET
;
1306 ENTER("qla1280_reset");
1308 if (qla1280_verbose
)
1309 printk("scsi(): Resetting Cmnd=0x%lx, Handle=0x%lx, flags=0x%x\n",(long)cmd
,(long)CMD_HANDLE(cmd
),flags
);
1312 printk(KERN_WARNING
"(scsi?:?:?:?) Reset called with NULL Scsi_Cmnd "
1313 "pointer, failing.\n");
1314 return(SCSI_RESET_SNOOZE
);
1316 ha
= (scsi_qla_host_t
*) cmd
->host
->hostdata
;
1317 sp
= (srb_t
*) CMD_SP(cmd
);
1320 qla1280_panic("qla1280_reset",ha
->host
);
1324 /* Check for pending interrupts. */
1325 data
= qla1280_debounce_register(&ha
->iobase
->istatus
);
1326 if( !(ha
->flags
.in_isr
) && (data
& RISC_INT
) )
1328 qla1280_isr(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1333 * Determine the suggested action that the mid-level driver wants
1336 if( CMD_HANDLE(cmd
) == (unsigned char *) 0 )
1339 * if mid-level driver called reset with a orphan SCSI_Cmnd
1340 * (i.e. a command that's not pending ), so perform the
1341 * function specified.
1343 if( (flags
& SCSI_RESET_SUGGEST_HOST_RESET
) )
1344 action
= ADAPTER_RESET
;
1350 * Mid-level driver has called reset with this SCSI_Cmnd and
1353 if( flags
& SCSI_RESET_SUGGEST_HOST_RESET
)
1354 action
= ADAPTER_RESET
;
1355 else if( flags
& SCSI_RESET_SUGGEST_BUS_RESET
)
1358 action
= DEVICE_RESET
;
1361 b
= SCSI_BUS_32(cmd
);
1362 t
= SCSI_TCN_32(cmd
);
1363 l
= SCSI_LUN_32(cmd
);
1364 q
= LU_Q(ha
, b
, t
, l
);
1366 #if AUTO_ESCALATE_RESET
1367 if ( (action
& DEVICE_RESET
) && (q
->q_flag
& QLA1280_QRESET
) )
1369 printk(KERN_INFO
"qla1280(%d): Bus device reset already sent to " "device, escalating.\n", (int)ha
->host_no
);
1372 if ( (action
& DEVICE_RESET
) && (sp
->flags
& SRB_ABORT_PENDING
) )
1374 printk(KERN_INFO
"qla1280(%d):Have already attempted to reach " "device with abort device\n", (int)ha
->host_no
);
1375 printk(KERN_INFO
"qla1280(%d):message, will escalate to BUS " "RESET.\n",(int) ha
->host_no
);
1381 * By this point, we want to already know what we are going to do,
1382 * so we only need to perform the course of action.
1385 result
= SCSI_RESET_ERROR
;
1392 result
= SCSI_RESET_PENDING
;
1396 ha
->flags
.in_reset
= TRUE
;
1397 if (qla1280_verbose
)
1398 printk(KERN_INFO
"scsi(%d:%d:%d:%d): Queueing abort device command.\n", (int)ha
->host_no
,(int)b
,(int)t
,(int)l
);
1399 qla1280_abort_queue_single(ha
,b
,t
,l
,DID_ABORT
);
1400 if( qla1280_abort_device(ha
, b
, t
, l
) == 0)
1401 result
= SCSI_RESET_PENDING
;
1405 if (qla1280_verbose
)
1406 printk(KERN_INFO
"scsi(%d:%d:%d:%d): Queueing device reset command.\n",(int) ha
->host_no
,(int)b
,(int)t
,(int)l
);
1407 ha
->flags
.in_reset
= TRUE
;
1408 for (l
= 0; l
< MAX_LUNS
; l
++)
1409 qla1280_abort_queue_single(ha
,b
,t
,l
,DID_ABORT
);
1410 if( qla1280_device_reset(ha
, b
, t
) == 0 )
1411 result
= SCSI_RESET_PENDING
;
1412 q
->q_flag
|= QLA1280_QRESET
;
1416 if (qla1280_verbose
)
1417 printk(KERN_INFO
"qla1280(%d:%d:%d:%d): Issuing BUS DEVICE RESET.\n",(int) ha
->host_no
,(int)b
,(int)t
,(int)l
);
1418 ha
->flags
.in_reset
= TRUE
;
1419 for (t
= 0; t
< MAX_TARGETS
; t
++)
1420 for (l
= 0; l
< MAX_LUNS
; l
++)
1421 qla1280_abort_queue_single(ha
,b
,t
,l
,DID_RESET
);
1422 qla1280_bus_reset(ha
, b
);
1424 * The bus reset routine returns all the outstanding commands back
1425 * with "DID_RESET" in the status field after a short delay
1426 * by the firmware. If the mid-level time out the SCSI reset before
1427 * our delay we may need to ignore it.
1429 /* result = SCSI_RESET_PENDING | SCSI_RESET_BUS_RESET; */
1430 result
= SCSI_RESET_SUCCESS
| SCSI_RESET_BUS_RESET
;
1431 mdelay(4 * 1000); barrier();
1432 if( flags
& SCSI_RESET_SYNCHRONOUS
)
1434 CMD_RESULT(cmd
) = (int) (DID_BUS_BUSY
<< 16);
1435 (*(cmd
)->scsi_done
)(cmd
);
1437 /* ha->reset_start = jiffies; */
1442 if (qla1280_verbose
)
1444 printk(KERN_INFO
"scsi(%d:%d:%d:%d): Issued an ADAPTER RESET.\n",(int) ha
->host_no
,(int)b
,(int)t
,(int)l
);
1445 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
);
1447 ha
->flags
.reset_active
= TRUE
;
1449 * We restarted all of the commands automatically, so the mid-level code can expect
1450 * completions momentitarily.
1452 if( qla1280_abort_isp(ha
) == 0 )
1453 result
= SCSI_RESET_SUCCESS
| SCSI_RESET_HOST_RESET
;
1455 ha
->flags
.reset_active
= FALSE
;
1458 if( ha
->done_q_first
)
1459 qla1280_done(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1460 qla1280_restart_queues(ha
);
1461 ha
->flags
.in_reset
= FALSE
;
1464 DEBUG(printk("RESET returning %d\n", result
));
1467 LEAVE("qla1280_reset");
1471 /**************************************************************************
1473 * Return the disk geometry for the given SCSI device.
1474 **************************************************************************/
1476 qla1280_biosparam(Disk
*disk
, kdev_t dev
, int geom
[])
1478 int heads
, sectors
, cylinders
;
1482 cylinders
= disk
->capacity
/ (heads
* sectors
);
1483 if (cylinders
> 1024)
1487 cylinders
= disk
->capacity
/ (heads
* sectors
);
1488 /* if (cylinders > 1023)
1489 cylinders = 1023; */
1494 geom
[2] = cylinders
;
1498 /**************************************************************************
1499 * qla1280_intr_handler
1500 * Handles the H/W interrupt
1501 **************************************************************************/
1502 void qla1280_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1504 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,95)
1505 unsigned long cpu_flags
= 0;
1507 scsi_qla_host_t
*ha
;
1511 ENTER_INTR("qla1280_intr_handler");
1513 ha
= (scsi_qla_host_t
*) dev_id
;
1516 printk(KERN_INFO
"scsi(): Interrupt with NULL host ptr\n");
1520 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,95)
1521 spin_lock_irqsave(&io_request_lock
, cpu_flags
);
1522 if(test_and_set_bit(QLA1280_IN_ISR_BIT
, &ha
->flags
))
1529 /* disable our interrupt. */
1530 WRT_REG_WORD(®
->ictrl
, 0);
1531 data
= qla1280_debounce_register(®
->istatus
);
1532 /* Check for pending interrupts. */
1533 if ( !(data
& RISC_INT
) )
1535 /* spurious interrupts can happen legally */
1536 DEBUG(printk("scsi(%d): Spurious interrupt - ignoring\n",(int)ha
->host_no
));
1540 qla1280_isr(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1541 if (ha
->done_q_first
)
1542 qla1280_done(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1544 clear_bit(QLA1280_IN_ISR_BIT
, &ha
->flags
);
1545 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
);
1546 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95) */
1548 if( test_bit(QLA1280_IN_ISR_BIT
, (int *)&ha
->flags
) )
1551 printk(KERN_INFO
"scsi(%d): Already in interrupt - returning \n", (int)ha
->host_no
);
1554 set_bit(QLA1280_IN_ISR_BIT
, (int *)&ha
->flags
);
1557 /* disable our interrupt. */
1558 WRT_REG_WORD(®
->ictrl
, 0);
1560 data
= qla1280_debounce_register(®
->istatus
);
1561 /* Check for pending interrupts. */
1562 if ( !(data
& RISC_INT
) )
1564 /* spurious interrupts can happen legally */
1565 DEBUG(printk("scsi(%d): Spurious interrupt - ignoring\n",(int)ha
->host_no
));
1569 qla1280_isr(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1571 /* if no work to do then call the SCSI mid-level right away */
1572 if( ha
->done_q_first
)
1573 qla1280_done(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1575 /* Schedule the DPC routine */
1576 if (ha
->flags
.isp_abort_needed
|| ha
->flags
.reset_marker
||
1579 ha
->run_qla_bh
.data
= (void *) ha
;
1580 ha
->run_qla_bh
.routine
= qla1280_do_dpc
;
1583 queue_task_irq(&ha
->run_qla_bh
,&tq_scheduler
);
1584 ha
->flags
.dpc_sched
= TRUE
;
1586 clear_bit(QLA1280_IN_ISR_BIT
, (int *)&ha
->flags
);
1588 /* enable our interrupt. */
1589 WRT_REG_WORD(®
->ictrl
, ISP_EN_INT
+ ISP_EN_RISC
);
1592 LEAVE_INTR("qla1280_intr_handler");
1595 /**************************************************************************
1599 * This routine is a task that is schedule by the interrupt handler
1600 * to perform the background processing for interrupts. We put it
1601 * on a task queue that is consumed whenever the scheduler runs; that's
1602 * so you can do anything (i.e. put the process to sleep etc). In fact, the
1603 * mid-level tries to sleep when it reaches the driver threshold
1604 * "host->can_queue". This can cause a panic if we were in our interrupt
1606 **************************************************************************/
1607 void qla1280_do_dpc(void *p
)
1609 scsi_qla_host_t
*ha
= (scsi_qla_host_t
*) p
;
1610 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
1611 unsigned long cpu_flags
= 0;
1615 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
1616 spin_lock_irqsave(&io_request_lock
, cpu_flags
);
1618 if (ha
->flags
.isp_abort_needed
)
1619 qla1280_abort_isp(ha
);
1621 if (ha
->flags
.reset_marker
)
1622 qla1280_rst_aen(ha
);
1624 if (ha
->done_q_first
)
1625 qla1280_done(ha
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
1626 ha
->flags
.dpc_sched
= FALSE
;
1627 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
1628 spin_unlock_irqrestore(&io_request_lock
, cpu_flags
);
1632 /**************************************************************************
1633 * qla1280_device_queue_depth
1636 * Determines the queue depth for a given device. There are two ways
1637 * a queue depth can be obtained for a tagged queueing device. One
1638 * way is the default queue depth which is determined by whether
1639 * If it is defined, then it is used
1640 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1641 * default queue depth (dependent on the number of hardware SCBs).
1642 **************************************************************************/
1643 STATIC
void qla1280_device_queue_depth(scsi_qla_host_t
*p
, Scsi_Device
*device
)
1645 int default_depth
= 3;
1646 int bus
= device
->channel
;
1647 int target
= device
->id
;
1649 device
->queue_depth
= default_depth
;
1651 if (device
->tagged_supported
&&
1652 (p
->bus_settings
[bus
].qtag_enables
& (BIT_0
<< target
)) )
1654 device
->tagged_queue
= 1;
1655 device
->current_tag
= 0;
1656 device
->queue_depth
= p
->bus_settings
[bus
].hiwat
;
1657 /* device->queue_depth = 20; */
1658 printk(KERN_INFO
"scsi(%d:%d:%d:%d): Enabled tagged queuing, queue depth %d.\n",
1659 (int)p
->host_no
, device
->channel
, device
->id
,
1660 device
->lun
, device
->queue_depth
);
1662 qla12160_get_target_parameters(p
, bus
, target
, device
->lun
);
1666 /**************************************************************************
1667 * qla1280_select_queue_depth
1669 * Sets the queue depth for each SCSI device hanging off the input
1670 * host adapter. We use a queue depth of 2 for devices that do not
1671 * support tagged queueing.
1672 **************************************************************************/
1674 qla1280_select_queue_depth(struct Scsi_Host
*host
, Scsi_Device
*scsi_devs
)
1676 Scsi_Device
*device
;
1677 scsi_qla_host_t
*p
= (scsi_qla_host_t
*) host
->hostdata
;
1679 ENTER("qla1280_select_queue_depth");
1680 for (device
= scsi_devs
; device
!= NULL
; device
= device
->next
)
1682 if (device
->host
== host
)
1683 qla1280_device_queue_depth(p
, device
);
1685 LEAVE("qla1280_select_queue_depth");
1688 /*--------------------------**
1689 ** Driver Support Routines **
1690 **--------------------------*/
1692 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
1695 * Delay in milliseconds
1698 * milliseconds = delay
1700 STATIC
inline void mdelay(int milliseconds
)
1704 for(i
=0; i
<milliseconds
; i
++)
1711 * Process completed commands.
1714 * ha = adapter block pointer.
1715 * done_q_first = done queue first pointer.
1716 * done_q_last = done queue last pointer.
1719 qla1280_done(scsi_qla_host_t
*ha
, srb_t
**done_q_first
, srb_t
**done_q_last
)
1725 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1726 unsigned long cpu_flags
= 0;
1729 ENTER("qla1280_done");
1733 while (*done_q_first
!= NULL
)
1735 /* remove command from done list */
1737 if (!(*done_q_first
= sp
->s_next
))
1738 *done_q_last
= NULL
;
1740 (*done_q_first
)->s_prev
= NULL
;
1742 b
= SCSI_BUS_32(cmd
);
1743 t
= SCSI_TCN_32(cmd
);
1744 l
= SCSI_LUN_32(cmd
);
1745 q
= LU_Q(ha
, b
, t
, l
);
1747 /* Decrement outstanding commands on device. */
1750 if (q
->q_outcnt
< ha
->bus_settings
[b
].hiwat
)
1752 q
->q_flag
&= ~QLA1280_QBUSY
;
1755 q
->resp_time
+= jiffies
- sp
->r_start
; /* Lun bookkeeping information */
1756 q
->act_time
+= jiffies
- sp
->u_start
;
1758 if( sp
->dir
& BIT_5
)
1763 switch ( (CMD_RESULT(cmd
)>>16))
1766 q
->q_flag
&= ~QLA1280_QRESET
;
1767 /* Issue marker command. */
1768 qla1280_marker(ha
, b
, t
, 0, MK_SYNC_ID
);
1771 sp
->flags
&= ~SRB_ABORT_PENDING
;
1772 sp
->flags
|= SRB_ABORTED
;
1773 if (sp
->flags
& SRB_TIMEOUT
)
1774 CMD_RESULT(sp
->cmd
)= DID_TIME_OUT
<< 16;
1780 /* Call the mid-level driver interrupt handler */
1781 CMD_HANDLE(sp
->cmd
) = (unsigned char *) 0;
1783 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1785 (*(cmd
)->scsi_done
)(cmd
);
1788 (*(cmd
)->scsi_done
)(cmd
);
1790 qla1280_next(ha
, q
, b
);
1796 LEAVE("qla1280_done");
1800 * Translates a ISP error to a Linux SCSI error
1802 STATIC
int qla1280_return_status( sts_entry_t
*sts
, Scsi_Cmnd
*cp
)
1804 int host_status
= DID_ERROR
;
1805 #if DEBUG_QLA1280_INTR
1806 STATIC
char *reason
[] =
1819 #endif /* DEBUG_QLA1280_INTR */
1821 ENTER("qla1280_return_status");
1823 #if DEBUG_QLA1280_INTR
1825 DEBUG(printk("qla1280_return_status: compl status = 0x%04x\n", sts->comp_status));
1828 switch(sts
->comp_status
)
1831 host_status
= DID_OK
;
1834 if (!(sts
->state_flags
& SF_GOT_BUS
))
1835 host_status
= DID_NO_CONNECT
;
1836 else if (!(sts
->state_flags
& SF_GOT_TARGET
))
1837 host_status
= DID_BAD_TARGET
;
1838 else if (!(sts
->state_flags
& SF_SENT_CDB
))
1839 host_status
= DID_ERROR
;
1840 else if (!(sts
->state_flags
& SF_TRANSFERRED_DATA
))
1841 host_status
= DID_ERROR
;
1842 else if (!(sts
->state_flags
& SF_GOT_STATUS
))
1843 host_status
= DID_ERROR
;
1844 else if (!(sts
->state_flags
& SF_GOT_SENSE
))
1845 host_status
= DID_ERROR
;
1848 host_status
= DID_RESET
;
1851 host_status
= DID_ABORT
;
1854 host_status
= DID_TIME_OUT
;
1856 case CS_DATA_OVERRUN
:
1857 #ifdef QL_DEBUG_LEVEL_2
1858 printk("Data overrun 0x%x\n",(int)sts
->residual_length
);
1860 "\n\rqla1280_isr: response packet data\n\r");
1861 qla1280_dump_buffer((caddr_t
)sts
,
1862 RESPONSE_ENTRY_SIZE
);
1864 host_status
= DID_ERROR
;
1866 case CS_DATA_UNDERRUN
:
1867 if ( (CMD_XFRLEN(cp
) - sts
->residual_length
) < cp
->underflow
)
1869 printk("scsi: Underflow detected - retrying command.\n");
1870 host_status
= DID_ERROR
;
1873 host_status
= DID_OK
;
1876 host_status
= DID_ERROR
;
1880 #if DEBUG_QLA1280_INTR
1881 sprintf(debug_buff
, "qla1280 ISP status: host status (%s) scsi status %x\n\r", reason
[host_status
], sts
->scsi_status
);
1882 qla1280_print(debug_buff
);
1885 LEAVE("qla1280_return_status");
1887 return (sts
->scsi_status
& 0xff) | (host_status
<< 16);
1891 * qla1280_done_q_put
1892 * Place SRB command on done queue.
1896 * done_q_first = done queue first pointer.
1897 * done_q_last = done queue last pointer.
1900 qla1280_done_q_put(srb_t
*sp
, srb_t
**done_q_first
, srb_t
**done_q_last
)
1902 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1903 unsigned long cpu_flags
= 0;
1905 #ifdef QL_DEBUG_LEVEL_3
1906 ENTER("qla1280_put_done_q");
1908 /* Place block on done queue */
1911 sp
->s_prev
= *done_q_last
;
1915 (*done_q_last
)->s_next
= sp
;
1919 #ifdef QL_DEBUG_LEVEL_3
1920 LEAVE("qla1280_put_done_q");
1926 * Retrieve and process next job in the queue.
1929 * ha = adapter block pointer.
1930 * q = SCSI LU pointer.
1931 * b = SCSI bus number.
1932 * SCSI_LU_Q lock must be already obtained and no other locks.
1935 * Releases SCSI_LU_Q upon exit.
1938 qla1280_next(scsi_qla_host_t
*ha
, scsi_lu_t
*q
, uint8_t b
)
1943 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1944 unsigned long cpu_flags
= 0;
1947 ENTER("qla1280_next");
1950 while ( ((sp
= q
->q_first
) != NULL
) && /* we have a queue pending */
1951 !(q
->q_flag
& QLA1280_QBUSY
) && /* device not busy */
1952 !ha
->flags
.abort_isp_active
&& /* not resetting the adapter */
1953 !(q
->q_flag
& QLA1280_QSUSP
) ) /* device not suspended */
1955 /* Remove srb from SCSI LU queue. */
1956 qla1280_removeq(q
, sp
);
1958 DEBUG(sprintf(debug_buff
,"starting request 0x%p<-(0x%p)\n\r",q
,sp
));
1959 DEBUG(qla1280_print(debug_buff
));
1961 /* Set busy flag if reached high water mark. */
1963 if (q
->q_outcnt
>= ha
->bus_settings
[b
].hiwat
)
1964 q
->q_flag
|= QLA1280_QBUSY
;
1966 #if QLA1280_64BIT_SUPPORT
1967 if (ha
->flags
.enable_64bit_addressing
)
1968 status
= qla1280_64bit_start_scsi(ha
, sp
);
1971 status
= qla1280_32bit_start_scsi(ha
, sp
);
1973 if (status
) /* if couldn't start the request */
1975 if (q
->q_outcnt
== 1)
1977 /* Release SCSI LU queue specific lock */
1978 QLA1280_SCSILU_UNLOCK(q
);
1980 /* Wait for 30 sec for command to be accepted. */
1981 for (cnt
= 6000000; cnt
; cnt
--)
1983 #if QLA1280_64BIT_SUPPORT
1984 if (ha
->flags
.enable_64bit_addressing
)
1985 status
= qla1280_64bit_start_scsi(ha
, sp
);
1988 status
= qla1280_32bit_start_scsi(ha
, sp
);
1995 /* Go check for pending interrupts. */
1998 SYS_DELAY(5); /* 10 */
2002 /* Set timeout status */
2003 CMD_RESULT(sp
->cmd
) = DID_TIME_OUT
<< 16;
2006 /* Remove command from watchdog queue. */
2007 if (sp
->flags
& SRB_WATCHDOG
)
2008 qla1280_timeout_remove(ha
, sp
);
2011 CMD_HANDLE(sp
->cmd
) = (unsigned char *) 0;
2013 /* Call the mid-level driver interrupt handler */
2014 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2016 (*(sp
->cmd
)->scsi_done
)(sp
->cmd
);
2019 (*(sp
->cmd
)->scsi_done
)(sp
->cmd
);
2022 /* Acquire LU queue specific lock */
2023 QLA1280_SCSILU_LOCK(q
);
2029 /* Acquire LU queue specific lock */
2030 QLA1280_SCSILU_LOCK(q
);
2033 { /* Place request back on top of device queue. */
2034 qla1280_putq_t(q
, sp
);
2038 if (q
->q_outcnt
< ha
->bus_settings
[b
].hiwat
)
2039 q
->q_flag
&= ~QLA1280_QBUSY
;
2047 /* Release SCSI LU queue specific lock */
2048 QLA1280_SCSILU_UNLOCK(q
);
2050 LEAVE("qla1280_next");
2055 * Add the standard SCB job to the top of standard SCB commands.
2058 * q = SCSI LU pointer.
2060 * SCSI_LU_Q lock must be already obtained.
2063 qla1280_putq_t(scsi_lu_t
*q
, srb_t
*sp
)
2066 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2067 unsigned long cpu_flags
= 0;
2070 #ifdef QL_DEBUG_LEVEL_3
2071 ENTER("qla1280_putq_t");
2074 DEBUG(sprintf(debug_buff
,"Adding to device 0x%p<-(0x%p)\n\r",q
,sp
));
2075 DEBUG(qla1280_print(debug_buff
));
2077 if (!q
->q_first
) /* If queue empty */
2087 srb_p
= srb_p
->s_next
;
2091 sp
->s_prev
= srb_p
->s_prev
;
2093 srb_p
->s_prev
->s_next
= sp
;
2101 sp
->s_prev
= q
->q_last
;
2102 q
->q_last
->s_next
= sp
;
2108 #ifdef QL_DEBUG_LEVEL_3
2109 LEAVE("qla1280_putq_t");
2115 * Function used to remove a command block from the
2119 * q = SCSI LU pointer.
2121 * SCSI_LU_Q lock must be already obtained.
2124 qla1280_removeq(scsi_lu_t
*q
, srb_t
*sp
)
2126 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2127 unsigned long cpu_flags
= 0;
2129 DEBUG(sprintf(debug_buff
,"Removing from device_q (0x%p)->(0x%p)\n\r",q
,sp
));
2130 DEBUG(qla1280_print(debug_buff
));
2134 if ((sp
->s_prev
->s_next
= sp
->s_next
) != NULL
)
2135 sp
->s_next
->s_prev
= sp
->s_prev
;
2137 q
->q_last
= sp
->s_prev
;
2139 else if (!(q
->q_first
= sp
->s_next
))
2142 q
->q_first
->s_prev
= NULL
;
2148 * Allocates adapter memory.
2155 qla1280_mem_alloc(scsi_qla_host_t
*ha
)
2160 #ifdef QL_DEBUG_LEVEL_3
2161 ENTER("qla1280_mem_alloc");
2164 #ifdef DYNAMIC_MEM_ALLOC
2165 ha
->request_ring
= qla1280_alloc_phys(REQUEST_ENTRY_SIZE
* REQUEST_ENTRY_CNT
,
2167 if(ha
->request_ring
) {
2168 ha
->response_ring
= qla1280_alloc_phys(RESPONSE_ENTRY_SIZE
* RESPONSE_ENTRY_CNT
,
2170 if(ha
->response_ring
) {
2175 ha
->request_ring
= &ha
->req
[0];
2176 ha
->request_dma
= VIRT_TO_BUS(&ha
->req
[0]);
2177 ha
->response_ring
= &ha
->res
[0];
2178 ha
->response_dma
= VIRT_TO_BUS(&ha
->res
[0]);
2183 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2184 qla1280_print("qla1280_mem_alloc: **** FAILED ****\n");
2187 #ifdef QL_DEBUG_LEVEL_3
2189 LEAVE("qla1280_mem_alloc");
2196 * Frees adapter allocated memory.
2199 * ha = adapter block pointer.
2202 qla1280_mem_free(scsi_qla_host_t
*ha
)
2207 ENTER("qlc1280_mem_free");
2210 /* Free device queues. */
2211 for (b
= 0; b
< MAX_BUSES
; b
++)
2213 q
= LU_Q(ha
, b
, ha
->bus_settings
[b
].id
, 0);
2214 for (t
= 0; t
< MAX_TARGETS
; t
++)
2215 for (l
= 0; l
< MAX_LUNS
; l
++)
2216 if (LU_Q(ha
, b
, t
, l
) != NULL
&& LU_Q(ha
, b
, t
, l
) != q
)
2217 KMFREE(LU_Q(ha
, b
, t
, l
),sizeof(struct scsi_lu
));
2218 KMFREE(q
, sizeof(struct scsi_lu
));
2220 for( b
=0; b
< MAX_EQ
; b
++ )
2221 ha
->dev
[b
] = (scsi_lu_t
*)NULL
;
2224 LEAVE("qlc1280_mem_free");
2230 /****************************************************************************/
2231 /* QLogic ISP1280 Hardware Support Functions. */
2232 /****************************************************************************/
2235 * qla2100_enable_intrs
2236 * qla2100_disable_intrs
2239 * ha = adapter block pointer.
2244 static inline void qla1280_enable_intrs(scsi_qla_host_t
*ha
) {
2248 ha
->flags
.interrupts_on
= 1;
2249 /* enable risc and host interrupts */
2250 WRT_REG_WORD(®
->ictrl
, (ISP_EN_INT
+ ISP_EN_RISC
));
2253 static inline void qla1280_disable_intrs(scsi_qla_host_t
*ha
) {
2257 ha
->flags
.interrupts_on
= 0;
2258 /* disable risc and host interrupts */
2259 WRT_REG_WORD(®
->ictrl
, 0);
2263 * qla1280_initialize_adapter
2267 * ha = adapter block pointer.
2273 qla1280_initialize_adapter(scsi_qla_host_t
*ha
)
2280 #ifdef QL_DEBUG_LEVEL_3
2281 ENTER("qla1280_initialize_adapter");
2284 /* Clear adapter flags. */
2285 ha
->flags
.online
= FALSE
;
2286 ha
->flags
.isp_abort_needed
= FALSE
;
2287 ha
->flags
.disable_host_adapter
= FALSE
;
2288 ha
->flags
.reset_active
= FALSE
;
2289 ha
->flags
.abort_isp_active
= FALSE
;
2290 ha
->flags
.watchdog_enabled
= FALSE
;
2292 DEBUG(printk("Configure PCI space for adapter...\n"));
2293 if (!(status
= qla1280_pci_config(ha
)))
2297 /* Disable ISP interrupts. */
2298 WRT_REG_WORD(®
->ictrl
, 0);
2300 /* Insure mailbox registers are free. */
2301 WRT_REG_WORD(®
->semaphore
, 0);
2302 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
2303 WRT_REG_WORD(®
->host_cmd
, HC_CLR_HOST_INT
);
2305 /* If firmware needs to be loaded */
2306 if (qla1280_verbose
)
2307 printk("scsi(%d): Determining if RISC is loaded...\n",(int)ha
->host_no
);
2308 if (qla1280_isp_firmware(ha
))
2310 if (qla1280_verbose
)
2311 printk("scsi(%d): Verifying chip...\n",(int)ha
->host_no
);
2312 if (!(status
= qla1280_chip_diag(ha
)))
2314 if (qla1280_verbose
)
2315 printk("scsi(%d): Setup chip...\n",(int)ha
->host_no
);
2316 status
= qla1280_setup_chip(ha
);
2322 /* Setup adapter based on NVRAM parameters. */
2323 if (qla1280_verbose
)
2324 printk("scsi(%d): Configure NVRAM parameters...\n",(int)ha
->host_no
);
2325 qla1280_nvram_config(ha
);
2327 if (!ha
->flags
.disable_host_adapter
&&
2328 !qla1280_init_rings(ha
))
2330 /* Issue SCSI reset. */
2331 for (b
= 0; b
< ha
->ports
; b
++)
2332 if (!ha
->bus_settings
[b
].disable_scsi_reset
)
2334 /* dg 03/13 if we can't reset twice then bus is dead */
2335 if( qla1280_bus_reset(ha
, b
) )
2336 if( qla1280_bus_reset(ha
, b
) )
2338 ha
->bus_settings
[b
].scsi_bus_dead
= TRUE
;
2344 /* Issue marker command. */
2345 ha
->flags
.reset_marker
= FALSE
;
2346 for (b
= 0; b
< ha
->ports
; b
++)
2348 ha
->bus_settings
[b
].reset_marker
= FALSE
;
2349 qla1280_marker(ha
, b
, 0, 0, MK_SYNC_ALL
);
2351 }while (ha
->flags
.reset_marker
);
2353 ha
->flags
.online
= TRUE
;
2355 /* Enable host adapter target mode. */
2356 for (b
= 0; b
< ha
->ports
; b
++)
2358 if (!(status
= qla1280_enable_tgt(ha
, b
)))
2360 /* for (cnt = 0; cnt < MAX_LUNS; cnt++)
2362 qla1280_enable_lun(ha, b, cnt);
2375 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2377 qla1280_print("qla1280_initialize_adapter: **** FAILED ****\n\r");
2379 #ifdef QL_DEBUG_LEVEL_3
2381 LEAVE("qla1280_initialize_adapter");
2387 * qla1280_enable_tgt
2388 * Enable target mode.
2391 * ha = adapter block pointer.
2392 * b = SCSI bus number.
2398 qla1280_enable_tgt(scsi_qla_host_t
*ha
, uint8_t b
)
2401 /* uint16_t mb[MAILBOX_REGISTER_COUNT]; */
2403 #ifdef QL_DEBUG_LEVEL_3
2404 qla1280_print("qla1280_enable_tgt: entered\n\r");
2407 /* Enable target mode. */
2409 mb[0] = MBC_ENABLE_TARGET_MODE;
2411 mb[2] = (uint16_t)(b << 15);
2412 status = qla1280_mailbox_command(ha, BIT_2|BIT_1|BIT_0, &mb[0]);
2414 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2416 qla1280_print("qla1280_enable_tgt: **** FAILED ****\n\r");
2418 #ifdef QL_DEBUG_LEVEL_3
2420 qla1280_print("qla1280_enable_tgt: exiting normally\n\r");
2427 * Checks if present version of RISC firmware is older than
2431 * ha = adapter block pointer.
2434 * 0 = firmware does not need to be loaded.
2437 qla1280_isp_firmware(scsi_qla_host_t
*ha
)
2439 nvram_t
*nv
= (nvram_t
*)ha
->response_ring
;
2443 uint8_t status
= 0; /* dg 2/27 always loads RISC */
2444 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2446 ENTER("qla1280_isp_firmware");
2448 /* Verify valid NVRAM checksum. */
2449 wptr
= (uint16_t *)ha
->response_ring
;
2450 DEBUG(printk("qla1280_isp_firmware: Reading NVRAM\n"));
2452 for (cnt
= 0; cnt
< sizeof(nvram_t
)/2; cnt
++)
2454 *wptr
= qla1280_get_nvram_word(ha
, cnt
);
2455 chksum
+= (uint8_t)*wptr
;
2456 chksum
+= (uint8_t)(*wptr
>> 8);
2459 DEBUG(printk("qla1280_isp_firmware: Completed Reading NVRAM\n"));
2461 #if defined(QL_DEBUG_LEVEL_3)
2462 sprintf(debug_buff
,"qla1280_isp_firmware: NVRAM Magic ID= %c %c %c\n\r",(char *) nv
->id
[0],nv
->id
[1],nv
->id
[2]);
2463 qla1280_print(debug_buff
);
2466 /* Bad NVRAM data, load RISC code. */
2467 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
2468 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->version
< 1)
2470 printk(KERN_INFO
"qla1280_isp_firmware: Bad checksum or magic number or version in NVRAM.\n");
2471 ha
->flags
.disable_risc_code_load
= FALSE
;
2474 ha
->flags
.disable_risc_code_load
= nv
->cntr_flags_1
.disable_loading_risc_code
;
2476 if (ha
->flags
.disable_risc_code_load
)
2478 #if defined(QL_DEBUG_LEVEL_3)
2479 qla1280_print("qla1280_isp_firmware: Telling RISC to verify checksum of loaded BIOS code.\n\r");
2481 /* Verify checksum of loaded RISC code. */
2482 mb
[0] = MBC_VERIFY_CHECKSUM
;
2483 /* mb[1] = ql12_risc_code_addr01; */
2484 mb
[1] = *QLBoardTbl
[ha
->devnum
].fwstart
;
2486 if (!(status
= qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0])))
2488 /* Start firmware execution. */
2489 #if defined(QL_DEBUG_LEVEL_3)
2490 qla1280_print("qla1280_isp_firmware: Startng F/W execution.\n\r");
2492 mb
[0] = MBC_EXECUTE_FIRMWARE
;
2493 /* mb[1] = ql12_risc_code_addr01; */
2494 mb
[1] = *QLBoardTbl
[ha
->devnum
].fwstart
;
2495 qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0]);
2498 printk(KERN_INFO
"qla1280: RISC checksum failed.\n");
2502 DEBUG(printk("qla1280: NVRAM configured to load RISC load.\n"));
2506 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2509 "qla1280_isp_firmware: **** Load RISC code ****\n\r");
2511 LEAVE("qla1280_isp_firmware");
2517 * Setup device PCI configuration registers.
2520 * ha = adapter block pointer.
2526 qla1280_pci_config(scsi_qla_host_t
*ha
)
2530 #if MEMORY_MAPPED_IO
2531 uint32_t page_offset
, base
;
2534 config_reg_t
*creg
= 0;
2537 ENTER("qla1280_pci_config");
2539 /* Get command register. */
2540 if (pci_read_config_word(ha
->pdev
,OFFSET(creg
->command
), &buf_wd
) == PCIBIOS_SUCCESSFUL
)
2544 * Set Bus Master Enable, Memory Address Space Enable and
2545 * reset any error bits.
2548 #if MEMORY_MAPPED_IO
2549 DEBUG(printk("qla1280: MEMORY MAPPED IO is enabled.\n"));
2550 buf_wd
|= BIT_2
+ BIT_1
+ BIT_0
;
2552 buf_wd
|= BIT_2
+ BIT_0
;
2554 if( pci_write_config_word(ha
->pdev
,OFFSET(creg
->command
), buf_wd
) )
2556 printk(KERN_WARNING
"qla1280: Could not write config word.\n");
2558 /* Get expansion ROM address. */
2559 if (pci_read_config_word(ha
->pdev
,OFFSET(creg
->expansion_rom
), &buf_wd
) == PCIBIOS_SUCCESSFUL
)
2561 /* Reset expansion ROM address decode enable. */
2563 if (pci_write_config_word(ha
->pdev
,OFFSET(creg
->expansion_rom
), buf_wd
) == PCIBIOS_SUCCESSFUL
)
2565 #if MEMORY_MAPPED_IO
2566 /* Get memory mapped I/O address. */
2567 pci_read_config_dword(ha
->pdev
,OFFSET(cfgp
->mem_base_addr
), &mmapbase
);
2568 mmapbase
&= PCI_BASE_ADDRESS_MEM_MASK
;
2570 /* Find proper memory chunk for memory map I/O reg. */
2571 base
= mmapbase
& PAGE_MASK
;
2572 page_offset
= mmapbase
- base
;
2573 /* Get virtual address for I/O registers. */
2574 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
2575 ha
->mmpbase
= ioremap_nocache(base
, page_offset
+ 256);
2577 ha
->mmpbase
= vremap(base
,page_offset
+ 256);
2581 ha
->mmpbase
+= page_offset
;
2582 /* ha->iobase = ha->mmpbase; */
2585 #else /* MEMORY_MAPPED_IO */
2587 #endif /* MEMORY_MAPPED_IO */
2592 LEAVE("qla1280_pci_config");
2598 * Test chip for proper operation.
2601 * ha = adapter block pointer.
2607 qla1280_chip_diag(scsi_qla_host_t
*ha
)
2609 device_reg_t
*reg
= ha
->iobase
;
2613 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2615 #ifdef QL_DEBUG_LEVEL_3
2616 sprintf(debug_buff
, "qla1280_chip_diag: testing device at 0x%p \n\r",®
->id_l
);
2617 qla1280_print(debug_buff
);
2620 /* Soft reset chip and wait for it to finish. */
2621 WRT_REG_WORD(®
->ictrl
, ISP_RESET
);
2622 data
= qla1280_debounce_register(®
->ictrl
);
2623 for (cnt
= 6000000; cnt
&& data
& ISP_RESET
; cnt
--)
2626 data
= RD_REG_WORD(®
->ictrl
);
2630 /* Reset register not cleared by chip reset. */
2631 #if defined(QL_DEBUG_LEVEL_3)
2632 qla1280_print("qla1280_chip_diag: reset register cleared by chip reset\n\r");
2634 WRT_REG_WORD(®
->cfg_1
, 0);
2636 /* Reset RISC and disable BIOS which
2637 allows RISC to execute out of RAM. */
2638 WRT_REG_WORD(®
->host_cmd
, HC_RESET_RISC
);
2639 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
2640 WRT_REG_WORD(®
->host_cmd
, HC_DISABLE_BIOS
);
2641 data
= qla1280_debounce_register(®
->mailbox0
);
2642 for (cnt
= 6000000; cnt
&& data
== MBS_BUSY
; cnt
--)
2645 data
= RD_REG_WORD(®
->mailbox0
);
2650 /* Check product ID of chip */
2651 #if defined(QL_DEBUG_LEVEL_3)
2652 qla1280_print("qla1280_chip_diag: Checking product ID of chip\n\r");
2654 if (RD_REG_WORD(®
->mailbox1
) != PROD_ID_1
||
2655 (RD_REG_WORD(®
->mailbox2
) != PROD_ID_2
&&
2656 RD_REG_WORD(®
->mailbox2
) != PROD_ID_2a
) ||
2657 RD_REG_WORD(®
->mailbox3
) != PROD_ID_3
||
2658 RD_REG_WORD(®
->mailbox4
) != PROD_ID_4
)
2660 printk(KERN_INFO
"qla1280: Wrong product ID = 0x%x,0x%x,0x%x,0x%x\n",
2661 RD_REG_WORD(®
->mailbox1
),
2662 RD_REG_WORD(®
->mailbox2
),
2663 RD_REG_WORD(®
->mailbox3
),
2664 RD_REG_WORD(®
->mailbox4
) );
2669 DEBUG(printk("qla1280_chip_diag: Checking mailboxes of chip\n"));
2670 /* Wrap Incoming Mailboxes Test. */
2671 mb
[0] = MBC_MAILBOX_REGISTER_TEST
;
2679 if (!(status
= qla1280_mailbox_command(ha
,
2680 (BIT_7
|BIT_6
|BIT_5
|BIT_4
|BIT_3
|BIT_2
|BIT_1
|BIT_0
),
2683 if (mb
[1] != 0xAAAA || mb
[2] != 0x5555 ||
2684 mb
[3] != 0xAA55 || mb
[4] != 0x55AA)
2686 if (mb
[5] != 0xA5A5 || mb
[6] != 0x5A5A ||
2690 printk(KERN_INFO
"qla1280: Failed mailbox check\n");
2700 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2702 qla1280_print("qla1280_chip_diag: **** FAILED ****\n\r");
2704 #ifdef QL_DEBUG_LEVEL_3
2706 qla1280_print("qla1280_chip_diag: exiting normally\n\r");
2713 * Load and start RISC firmware.
2716 * ha = adapter block pointer.
2722 qla1280_setup_chip(scsi_qla_host_t
*ha
)
2725 uint16_t risc_address
;
2726 uint16_t *risc_code_address
;
2727 long risc_code_size
;
2728 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2729 #ifdef QLA1280_UNUSED
2738 #ifdef QL_DEBUG_LEVEL_3
2739 ENTER("qla1280_setup_chip");
2742 if( (tbuf
= (uint8_t *)KMALLOC(8000) ) == NULL
)
2744 printk("setup_chip: couldn't alloacte memory\n");
2747 p_tbuf
= VIRT_TO_BUS(tbuf
);
2748 /* Load RISC code. */
2750 risc_address = ql12_risc_code_addr01;
2751 risc_code_address = &ql12_risc_code01[0];
2752 risc_code_size = ql12_risc_code_length01;
2754 risc_address
= *QLBoardTbl
[ha
->devnum
].fwstart
;
2755 risc_code_address
= QLBoardTbl
[ha
->devnum
].fwcode
;
2756 risc_code_size
= (long)(*QLBoardTbl
[ha
->devnum
].fwlen
& 0xffff);
2758 DEBUG(printk("qla1280: DMAing RISC code (%d) words.\n",(int)risc_code_size
));
2759 DEBUG(sprintf(debug_buff
,"qla1280_setup_chip: Loading RISC code size =(%ld).\n\r",risc_code_size
);)
2760 DEBUG(qla1280_print(debug_buff
));
2762 while (risc_code_size
> 0 && !status
)
2766 if ( cnt
> risc_code_size
)
2767 cnt
= risc_code_size
;
2769 DEBUG(sprintf(debug_buff
,"qla1280_setup_chip: loading risc @ =(0x%p),%d,%d(0x%x).\n\r",risc_code_address
,cnt
,num
,risc_address
);)
2770 DEBUG(qla1280_print(debug_buff
));
2771 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
));
2772 BCOPY((caddr_t
) risc_code_address
,(caddr_t
) ha
->request_ring
, (cnt
<<1));
2773 mb
[0] = MBC_LOAD_RAM
;
2774 /* mb[0] = MBC_LOAD_RAM_A64; */
2775 mb
[1] = risc_address
;
2777 mb
[3] = (uint16_t) ha
->request_dma
& 0xffff;
2778 mb
[2] = (uint16_t) (ha
->request_dma
>> 16) & 0xffff;
2779 mb
[7] = (uint16_t) (MS_64BITS(ha
->request_dma
) & 0xffff);
2780 mb
[6] = (uint16_t) (MS_64BITS(ha
->request_dma
) >> 16) & 0xffff;
2781 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]));
2782 if( (status
= qla1280_mailbox_command(ha
, BIT_4
|BIT_3
|BIT_2
|BIT_1
|BIT_0
,
2785 printk("Failed to load partial segment of f/w\n");
2791 mb
[0] = MBC_DUMP_RAM_A64
;
2792 mb
[1] = risc_address
;
2794 mb
[3] = (uint16_t) p_tbuf
& 0xffff;
2795 mb
[2] = (uint16_t) (p_tbuf
>> 16) & 0xffff;
2796 mb
[7] = (uint16_t) (p_tbuf
>> 32) & 0xffff;
2797 mb
[6] = (uint16_t) (p_tbuf
>> 48) & 0xffff;
2799 if( (status
= qla1280_mailbox_command(ha
, BIT_4
|BIT_3
|BIT_2
|BIT_1
|BIT_0
,
2802 printk("Failed to dump partial segment of f/w\n");
2805 sp
= (uint8_t *)ha
->request_ring
;
2806 for (i
= 0; i
< (cnt
<< 1) ; i
++)
2808 if( tbuf
[i
] != sp
[i
] )
2810 printk("qla1280 : firmware compare error @ byte (0x%x)\n",i
);
2816 risc_address
+= cnt
;
2817 risc_code_size
= risc_code_size
- cnt
;
2818 risc_code_address
= risc_code_address
+ cnt
;
2821 #ifdef QLA1280_UNUSED
2822 DEBUG(ql_debug_print
= 0;)
2824 for (i
= 0; i
< ql12_risc_code_length01
; i
++)
2827 mb
[1] = ql12_risc_code_addr01
+ i
;
2828 mb
[2] = ql12_risc_code01
[i
];
2830 status
= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
,
2834 printk("qla1280 : firmware load failure\n");
2839 mb
[1] = ql12_risc_code_addr01
+ i
;
2842 status
= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
,
2846 printk("qla1280 : firmware dump failure\n");
2849 if( mb
[2] != ql12_risc_code01
[i
] )
2850 printk("qla1280 : firmware compare error @ (0x%x)\n",ql12_risc_code_addr01
+i
);
2853 DEBUG(ql_debug_print
= 1;)
2856 /* Verify checksum of loaded RISC code. */
2859 DEBUG(printk("qla1280_setup_chip: Verifying checksum of loaded RISC code.\n");)
2860 mb
[0] = MBC_VERIFY_CHECKSUM
;
2861 /* mb[1] = ql12_risc_code_addr01; */
2862 mb
[1] = *QLBoardTbl
[ha
->devnum
].fwstart
;
2864 if (!(status
= qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0])))
2866 /* Start firmware execution. */
2867 DEBUG(qla1280_print("qla1280_setup_chip: start firmware running.\n\r");)
2868 mb
[0] = MBC_EXECUTE_FIRMWARE
;
2869 /* mb[1] = ql12_risc_code_addr01; */
2870 mb
[1] = *QLBoardTbl
[ha
->devnum
].fwstart
;
2871 qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0]);
2874 printk("qla1280_setup_chip: Failed checksum.\n");
2879 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2881 qla1280_print("qla1280_setup_chip: **** FAILED ****\n\r");
2883 #ifdef QL_DEBUG_LEVEL_3
2885 LEAVE("qla1280_setup_chip");
2894 * ha = adapter block pointer.
2895 * ha->request_ring = request ring virtual address
2896 * ha->response_ring = response ring virtual address
2897 * ha->request_dma = request ring physical address
2898 * ha->response_dma = response ring physical address
2904 qla1280_init_rings(scsi_qla_host_t
*ha
)
2908 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2910 #ifdef QL_DEBUG_LEVEL_3
2911 ENTER("qla1280_init_rings");
2913 /* Clear outstanding commands array. */
2914 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
2915 ha
->outstanding_cmds
[cnt
] = 0;
2917 /* Initialize request queue. */
2918 ha
->request_ring_ptr
= ha
->request_ring
;
2919 ha
->req_ring_index
= 0;
2920 ha
->req_q_cnt
= REQUEST_ENTRY_CNT
;
2921 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
2922 mb
[0] = MBC_INIT_REQUEST_QUEUE_A64
;
2923 mb
[1] = REQUEST_ENTRY_CNT
;
2924 mb
[3] = (uint16_t)LS_64BITS(ha
->request_dma
);
2925 mb
[2] = (uint16_t)( LS_64BITS(ha
->request_dma
) >> 16);
2927 mb
[7] = (uint16_t)MS_64BITS(ha
->request_dma
);
2928 mb
[6] = (uint16_t)( MS_64BITS(ha
->request_dma
) >> 16);
2929 if (!(status
= qla1280_mailbox_command(ha
,
2930 BIT_7
|BIT_6
|BIT_4
|BIT_3
|BIT_2
|BIT_1
|BIT_0
,
2933 /* Initialize response queue. */
2934 ha
->response_ring_ptr
= ha
->response_ring
;
2935 ha
->rsp_ring_index
= 0;
2936 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
2937 mb
[0] = MBC_INIT_RESPONSE_QUEUE_A64
;
2938 mb
[1] = RESPONSE_ENTRY_CNT
;
2939 mb
[3] = (uint16_t)LS_64BITS(ha
->response_dma
);
2940 mb
[2] = (uint16_t)(LS_64BITS(ha
->response_dma
) >> 16);
2942 mb
[7] = (uint16_t)MS_64BITS(ha
->response_dma
);
2943 mb
[6] = (uint16_t)(MS_64BITS(ha
->response_dma
) >> 16);
2944 status
= qla1280_mailbox_command(ha
,
2945 BIT_7
|BIT_6
|BIT_5
|BIT_3
|BIT_2
|BIT_1
|BIT_0
,
2949 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2951 qla1280_print("qla1280_init_rings: **** FAILED ****\n\r");
2953 #ifdef QL_DEBUG_LEVEL_3
2955 LEAVE("qla1280_init_rings");
2961 * NVRAM configuration.
2964 * ha = adapter block pointer.
2965 * ha->request_ring = request ring virtual address
2968 * host adapters parameters in host adapter block
2974 qla1280_nvram_config(scsi_qla_host_t
*ha
)
2976 device_reg_t
*reg
= ha
->iobase
;
2977 nvram_t
*nv
= (nvram_t
*)ha
->response_ring
;
2981 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2986 #if defined(QL_DEBUG_ROUTINES) && !defined(QL_DEBUG_LEVEL_4)
2987 uint8_t saved_print_status
= ql_debug_print
;
2989 ENTER("qla1280_nvram_config");
2990 #if defined(QL_DEBUG_ROUTINES) && !defined(QL_DEBUG_LEVEL_4)
2991 ql_debug_print
= FALSE
;
2994 /* Verify valid NVRAM checksum. */
2995 #if USE_NVRAM_DEFAULTS
2998 wptr
= (uint16_t *)ha
->response_ring
;
3000 if( ha
->device_id
== QLA12160_DEVICE_ID
||
3001 ha
->device_id
== QLA10160_DEVICE_ID
)
3002 nvsize
= sizeof(nvram160_t
)/2;
3004 nvsize
= sizeof(nvram_t
)/2;
3005 for( cnt
= 0; cnt
< nvsize
; cnt
++ )
3007 *wptr
= qla1280_get_nvram_word(ha
, cnt
);
3008 chksum
+= (uint8_t)*wptr
;
3009 chksum
+= (uint8_t)(*wptr
>> 8);
3015 /* Bad NVRAM data, set defaults parameters. */
3016 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
3017 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->version
< 1)
3019 #if USE_NVRAM_DEFAULTS
3020 DEBUG(printk("Using defaults for NVRAM\n"));
3022 DEBUG(printk("Using defaults for NVRAM: \n"));
3023 DEBUG(printk("checksum=0x%x, Id=%c, version=0x%x\n",chksum
,nv
->id
[0],nv
->version
));
3024 #if defined(QL_DEBUG_LEVEL_3)
3025 /* ql_debug_print = 1;
3026 qla1280_dump_buffer((caddr_t)ha->response_ring, REQUEST_ENTRY_SIZE);
3027 ql_debug_print = 0; */
3029 wptr
= (uint16_t *)ha
->response_ring
;
3030 for (cnt
= 0; cnt
< sizeof(nvram_t
)/2; cnt
++)
3035 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
3036 nv
->firmware_feature
.w
= BIT_0
;
3037 nv
->termination
.f
.scsi_bus_0_control
= 3;
3038 nv
->termination
.f
.scsi_bus_1_control
= 3;
3039 nv
->termination
.f
.auto_term_support
= 1;
3041 for (b
= 0; b
< MAX_BUSES
; b
++)
3043 nv
->bus
[b
].config_1
.initiator_id
= 7;
3044 nv
->bus
[b
].bus_reset_delay
= 5;
3045 nv
->bus
[b
].config_2
.async_data_setup_time
= 9;
3046 nv
->bus
[b
].config_2
.req_ack_active_negation
= 1;
3047 nv
->bus
[b
].config_2
.data_line_active_negation
= 1;
3048 nv
->bus
[b
].selection_timeout
= 250;
3049 nv
->bus
[b
].max_queue_depth
= 256;
3051 for (t
= 0; t
< MAX_TARGETS
; t
++)
3053 nv
->bus
[b
].target
[t
].parameter
.f
.auto_request_sense
= 1;
3054 nv
->bus
[b
].target
[t
].parameter
.f
.disconnect_allowed
= 1;
3055 nv
->bus
[b
].target
[t
].parameter
.f
.tag_queuing
= 1;
3056 nv
->bus
[b
].target
[t
].flags
.device_enable
= 1;
3060 #if USE_NVRAM_DEFAULTS
3068 /* Always force AUTO sense for LINUX SCSI */
3069 for (b
= 0; b
< MAX_BUSES
; b
++)
3070 for (t
= 0; t
< MAX_TARGETS
; t
++)
3072 nv
->bus
[b
].target
[t
].parameter
.f
.auto_request_sense
= 1;
3075 #if DEBUG_PRINT_NVRAM
3077 sprintf(debug_buff
,"qla1280 : initiator scsi id bus[0]=%d\n\r",
3078 nv
->bus
[0].config_1
.initiator_id
);
3079 qla1280_print(debug_buff
);
3080 sprintf(debug_buff
,"qla1280 : initiator scsi id bus[1]=%d\n\r",
3081 nv
->bus
[1].config_1
.initiator_id
);
3082 qla1280_print(debug_buff
);
3084 sprintf(debug_buff
,"qla1280 : bus reset delay[0]=%d\n\r",
3085 nv
->bus
[0].bus_reset_delay
);
3086 qla1280_print(debug_buff
);
3087 sprintf(debug_buff
,"qla1280 : bus reset delay[1]=%d\n\r",
3088 nv
->bus
[1].bus_reset_delay
);
3089 qla1280_print(debug_buff
);
3091 sprintf(debug_buff
,"qla1280 : retry count[0]=%d\n\r",
3092 nv
->bus
[0].retry_count
);
3093 qla1280_print(debug_buff
);
3094 sprintf(debug_buff
,"qla1280 : retry delay[0]=%d\n\r",
3095 nv
->bus
[0].retry_delay
);
3096 qla1280_print(debug_buff
);
3097 sprintf(debug_buff
,"qla1280 : retry count[1]=%d\n\r",
3098 nv
->bus
[1].retry_count
);
3099 qla1280_print(debug_buff
);
3100 sprintf(debug_buff
,"qla1280 : retry delay[1]=%d\n\r",
3101 nv
->bus
[1].retry_delay
);
3102 qla1280_print(debug_buff
);
3104 sprintf(debug_buff
,"qla1280 : async data setup time[0]=%d\n\r",
3105 nv
->bus
[0].config_2
.async_data_setup_time
);
3106 qla1280_print(debug_buff
);
3107 sprintf(debug_buff
,"qla1280 : async data setup time[1]=%d\n\r",
3108 nv
->bus
[1].config_2
.async_data_setup_time
);
3109 qla1280_print(debug_buff
);
3111 sprintf(debug_buff
,"qla1280 : req/ack active negation[0]=%d\n\r",
3112 nv
->bus
[0].config_2
.req_ack_active_negation
);
3113 qla1280_print(debug_buff
);
3114 sprintf(debug_buff
,"qla1280 : req/ack active negation[1]=%d\n\r",
3115 nv
->bus
[1].config_2
.req_ack_active_negation
);
3116 qla1280_print(debug_buff
);
3118 sprintf(debug_buff
,"qla1280 : data line active negation[0]=%d\n\r",
3119 nv
->bus
[0].config_2
.data_line_active_negation
);
3120 qla1280_print(debug_buff
);
3121 sprintf(debug_buff
,"qla1280 : data line active negation[1]=%d\n\r",
3122 nv
->bus
[1].config_2
.data_line_active_negation
);
3123 qla1280_print(debug_buff
);
3126 sprintf(debug_buff
,"qla1280 : disable loading risc code=%d\n\r",
3127 nv
->cntr_flags_1
.disable_loading_risc_code
);
3128 qla1280_print(debug_buff
);
3130 sprintf(debug_buff
,"qla1280 : enable 64bit addressing=%d\n\r",
3131 nv
->cntr_flags_1
.enable_64bit_addressing
);
3132 qla1280_print(debug_buff
);
3134 sprintf(debug_buff
,"qla1280 : selection timeout limit[0]=%d\n\r",
3135 nv
->bus
[0].selection_timeout
);
3136 qla1280_print(debug_buff
);
3137 sprintf(debug_buff
,"qla1280 : selection timeout limit[1]=%d\n\r",
3138 nv
->bus
[1].selection_timeout
);
3140 qla1280_print(debug_buff
);
3141 sprintf(debug_buff
,"qla1280 : max queue depth[0]=%d\n\r",
3142 nv
->bus
[0].max_queue_depth
);
3143 qla1280_print(debug_buff
);
3144 sprintf(debug_buff
,"qla1280 : max queue depth[1]=%d\n\r",
3145 nv
->bus
[1].max_queue_depth
);
3146 qla1280_print(debug_buff
);
3149 DEBUG(ql_debug_print
= 0;)
3151 /* Disable RISC load of firmware. */
3152 ha
->flags
.disable_risc_code_load
=
3153 nv
->cntr_flags_1
.disable_loading_risc_code
;
3154 /* Enable 64bit addressing. */
3155 ha
->flags
.enable_64bit_addressing
=
3156 nv
->cntr_flags_1
.enable_64bit_addressing
;
3158 /* Set ISP hardware DMA burst */
3159 mb
[0] = nv
->isp_config
.c
;
3160 WRT_REG_WORD(®
->cfg_1
, mb
[0]);
3162 /* Set SCSI termination. */
3163 WRT_REG_WORD(®
->gpio_enable
, (BIT_3
+ BIT_2
+ BIT_1
+ BIT_0
));
3164 mb
[0] = nv
->termination
.c
& (BIT_3
+ BIT_2
+ BIT_1
+ BIT_0
);
3165 WRT_REG_WORD(®
->gpio_data
, mb
[0]);
3167 /* ISP parameter word. */
3168 mb
[0] = MBC_SET_SYSTEM_PARAMETER
;
3169 mb
[1] = nv
->isp_parameter
;
3170 status
|= qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0]);
3172 /* Firmware feature word. */
3173 mb
[0] = MBC_SET_FIRMWARE_FEATURES
;
3174 mb
[1] = nv
->firmware_feature
.w
& (BIT_1
|BIT_0
);
3175 status
|= qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0]);
3177 /* Retry count and delay. */
3178 mb
[0] = MBC_SET_RETRY_COUNT
;
3179 mb
[1] = nv
->bus
[0].retry_count
;
3180 mb
[2] = nv
->bus
[0].retry_delay
;
3181 mb
[6] = nv
->bus
[1].retry_count
;
3182 mb
[7] = nv
->bus
[1].retry_delay
;
3183 status
|= qla1280_mailbox_command(ha
, BIT_7
|BIT_6
|BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3185 /* ASYNC data setup time. */
3186 mb
[0] = MBC_SET_ASYNC_DATA_SETUP
;
3187 mb
[1] = nv
->bus
[0].config_2
.async_data_setup_time
;
3188 mb
[2] = nv
->bus
[1].config_2
.async_data_setup_time
;
3189 status
|= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3191 /* Active negation states. */
3192 mb
[0] = MBC_SET_ACTIVE_NEGATION
;
3194 if (nv
->bus
[0].config_2
.req_ack_active_negation
)
3196 if (nv
->bus
[0].config_2
.data_line_active_negation
)
3199 if (nv
->bus
[1].config_2
.req_ack_active_negation
)
3201 if (nv
->bus
[1].config_2
.data_line_active_negation
)
3203 status
|= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3205 /* Selection timeout. */
3206 mb
[0] = MBC_SET_SELECTION_TIMEOUT
;
3207 mb
[1] = nv
->bus
[0].selection_timeout
;
3208 mb
[2] = nv
->bus
[1].selection_timeout
;
3209 status
|= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3211 for (b
= 0; b
< ha
->ports
; b
++)
3213 /* SCSI Reset Disable. */
3214 ha
->bus_settings
[b
].disable_scsi_reset
= nv
->bus
[b
].config_1
.scsi_reset_disable
;
3217 ha
->bus_settings
[b
].id
= nv
->bus
[b
].config_1
.initiator_id
;
3218 mb
[0] = MBC_SET_INITIATOR_ID
;
3219 mb
[1] = b
? ha
->bus_settings
[b
].id
| BIT_7
: ha
->bus_settings
[b
].id
;
3220 status
|= qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0]);
3223 ha
->bus_settings
[b
].bus_reset_delay
= nv
->bus
[b
].bus_reset_delay
;
3225 /* Command queue depth per device. */
3226 ha
->bus_settings
[b
].hiwat
= nv
->bus
[b
].max_queue_depth
- 1;
3228 /* Set target parameters. */
3229 for (t
= 0; t
< MAX_TARGETS
; t
++)
3231 if( ha
->device_id
== QLA12160_DEVICE_ID
||
3232 ha
->device_id
== QLA10160_DEVICE_ID
)
3234 status
= qla12160_set_target_parameters(ha
,b
,t
,0,(nvram160_t
*)nv
);
3238 /* Set Target Parameters. */
3239 mb
[0] = MBC_SET_TARGET_PARAMETERS
;
3240 mb
[1] = (uint16_t)(b
? t
| BIT_7
:t
);
3242 mb
[2] = nv
->bus
[b
].target
[t
].parameter
.c
<< 8;
3243 mb
[2] |= TP_AUTO_REQUEST_SENSE
;
3244 mb
[2] &= ~TP_STOP_QUEUE
;
3245 mb
[3] = nv
->bus
[b
].target
[t
].flags
.sync_offset
<< 8;
3246 mb
[3] |= nv
->bus
[b
].target
[t
].sync_period
;
3247 status
|= qla1280_mailbox_command(ha
, BIT_3
|BIT_2
|BIT_1
|BIT_0
,
3251 /* Save Tag queuing enable flag. */
3253 if (nv
->bus
[b
].target
[t
].parameter
.f
.tag_queuing
)
3254 ha
->bus_settings
[b
].qtag_enables
|= mb
[0];
3256 /* Save Device enable flag. */
3257 if (nv
->bus
[b
].target
[t
].flags
.device_enable
)
3258 ha
->bus_settings
[b
].device_enables
|= mb
[0];
3260 /* Save LUN disable flag. */
3261 if (nv
->bus
[b
].target
[t
].flags
.lun_disable
)
3262 ha
->bus_settings
[b
].lun_disables
|= mb
[0];
3264 /* Set Device Queue Parameters. */
3265 for (l
= 0; l
< MAX_LUNS
; l
++)
3267 mb
[0] = MBC_SET_DEVICE_QUEUE
;
3268 mb
[1] = (uint16_t)(b
? t
| BIT_7
:t
);
3269 mb
[1] = mb
[1] << 8 | l
;
3270 mb
[2] = nv
->bus
[b
].max_queue_depth
;
3271 mb
[3] = nv
->bus
[b
].target
[t
].execution_throttle
;
3272 status
|= qla1280_mailbox_command(ha
, BIT_3
|BIT_2
|BIT_1
|BIT_0
,
3277 DEBUG(ql_debug_print
= 0;)
3279 #if defined(QL_DEBUG_ROUTINES) && !defined(QL_DEBUG_LEVEL_4)
3280 ql_debug_print
= saved_print_status
;
3283 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3285 DEBUG(qla1280_print("qla1280_nvram_config: **** FAILED ****\n\r");)
3287 LEAVE("qla1280_nvram_config");
3292 * Get NVRAM data word
3293 * Calculates word position in NVRAM and calls request routine to
3294 * get the word from NVRAM.
3297 * ha = adapter block pointer.
3298 * address = NVRAM word address.
3304 qla1280_get_nvram_word(scsi_qla_host_t
*ha
, uint32_t address
)
3309 #ifdef QL_DEBUG_ROUTINES
3310 uint8_t saved_print_status
= ql_debug_print
;
3312 #ifdef QL_DEBUG_LEVEL_4
3313 ENTER("qla1280_get_nvram_word");
3316 nv_cmd
= address
<< 16;
3317 nv_cmd
|= NV_READ_OP
;
3319 #ifdef QL_DEBUG_ROUTINES
3320 ql_debug_print
= FALSE
;
3322 data
= qla1280_nvram_request(ha
, nv_cmd
);
3323 #ifdef QL_DEBUG_ROUTINES
3324 ql_debug_print
= saved_print_status
;
3327 #ifdef QL_DEBUG_LEVEL_4
3328 qla1280_print("qla1280_get_nvram_word: exiting normally NVRAM data = ");
3329 qla1280_output_number((uint32_t)data
, 16);
3330 qla1280_print("\n\r");
3337 * Sends read command to NVRAM and gets data from NVRAM.
3340 * ha = adapter block pointer.
3341 * nv_cmd = Bit 26 = start bit
3342 * Bit 25, 24 = opcode
3343 * Bit 23-16 = address
3344 * Bit 15-0 = write data
3350 qla1280_nvram_request(scsi_qla_host_t
*ha
, uint32_t nv_cmd
)
3353 device_reg_t
*reg
= ha
->iobase
;
3357 /* Send command to NVRAM. */
3360 for (cnt
= 0; cnt
< 11; cnt
++)
3362 if (nv_cmd
& BIT_31
)
3363 qla1280_nv_write(ha
, NV_DATA_OUT
);
3365 qla1280_nv_write(ha
, 0);
3369 /* Read data from NVRAM. */
3371 for (cnt
= 0; cnt
< 16; cnt
++)
3373 WRT_REG_WORD(®
->nvram
, NV_SELECT
+NV_CLOCK
);
3374 /* qla1280_nv_delay(ha); */
3377 reg_data
= RD_REG_WORD(®
->nvram
);
3378 if (reg_data
& NV_DATA_IN
)
3380 WRT_REG_WORD(®
->nvram
, NV_SELECT
);
3381 /* qla1280_nv_delay(ha); */
3385 /* Deselect chip. */
3387 WRT_REG_WORD(®
->nvram
, NV_DESELECT
);
3388 /* qla1280_nv_delay(ha); */
3395 qla1280_nv_write(scsi_qla_host_t
*ha
, uint16_t data
)
3397 device_reg_t
*reg
= ha
->iobase
;
3399 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
);
3401 /* qla1280_nv_delay(ha); */
3402 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
| NV_CLOCK
);
3403 /* qla1280_nv_delay(ha); */
3405 WRT_REG_WORD(®
->nvram
, data
| NV_SELECT
);
3406 /* qla1280_nv_delay(ha); */
3411 qla1280_nv_delay(scsi_qla_host_t
*ha
)
3413 device_reg_t
*reg
= ha
->iobase
;
3414 int cnt
= NV_DELAY_COUNT
;
3418 data
|= RD_REG_WORD(®
->nvram
);
3423 * Issue mailbox command and waits for completion.
3426 * ha = adapter block pointer.
3427 * mr = mailbox registers to load.
3428 * mb = data pointer for mailbox registers.
3431 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
3437 qla1280_mailbox_command(scsi_qla_host_t
*ha
, uint8_t mr
, uint16_t *mb
)
3439 device_reg_t
*reg
= ha
->iobase
;
3442 uint16_t *optr
, *iptr
;
3444 srb_t
*done_q_first
= 0;
3445 srb_t
*done_q_last
= 0;
3446 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
3447 unsigned long cpu_flags
= 0;
3450 #ifdef QL_DEBUG_LEVEL_3
3451 ENTER("qla1280_mailbox_command");
3454 /* Acquire interrupt specific lock */
3455 QLA1280_INTR_LOCK(ha
);
3457 ha
->flags
.mbox_busy
= TRUE
;
3459 /* Load mailbox registers. */
3460 optr
= (uint16_t *)®
->mailbox0
;
3462 for (cnt
= 0; cnt
< MAILBOX_REGISTER_COUNT
; cnt
++)
3466 WRT_REG_WORD(optr
, (*iptr
));
3473 /* Issue set host interrupt command. */
3474 ha
->flags
.mbox_int
= FALSE
;
3475 WRT_REG_WORD(®
->host_cmd
, HC_SET_HOST_INT
);
3476 data
= qla1280_debounce_register(®
->istatus
);
3478 /* Wait for 30 seconds for command to finish. */
3479 for (cnt
= 30000000; cnt
> 0 && !ha
->flags
.mbox_int
; cnt
--)
3481 /* Check for pending interrupts. */
3482 if (data
& RISC_INT
)
3484 qla1280_isr(ha
, (srb_t
**)&done_q_first
, (srb_t
**)&done_q_last
);
3487 data
= RD_REG_WORD(®
->istatus
);
3490 /* Check for mailbox command timeout. */
3493 #ifdef QL_DEBUG_LEVEL_2
3495 "qla1280_mailbox_command: **** Command Timeout, mailbox0 = ");
3496 qla1280_output_number((uint32_t)mb
[0], 16);
3497 qla1280_print(" ****\n\r");
3499 ha
->flags
.isp_abort_needed
= TRUE
;
3502 else if (ha
->mailbox_out
[0] != MBS_CMD_CMP
)
3505 /* Load return mailbox registers. */
3507 iptr
= (uint16_t *)&ha
->mailbox_out
[0];
3508 mr
= MAILBOX_REGISTER_COUNT
;
3512 /* Go check for any response interrupts pending. */
3513 ha
->flags
.mbox_busy
= FALSE
;
3514 qla1280_isr(ha
, (srb_t
**)&done_q_first
, (srb_t
**)&done_q_last
);
3516 /* Release interrupt specific lock */
3517 QLA1280_INTR_UNLOCK(ha
);
3520 if (ha
->flags
.isp_abort_needed
)
3521 qla1280_abort_isp(ha
);
3523 if (ha
->flags
.reset_marker
)
3524 qla1280_rst_aen(ha
);
3527 qla1280_done(ha
, (srb_t
**)&done_q_first
, (srb_t
**)&done_q_last
);
3529 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3532 qla1280_print("qla1280_mailbox_command: **** FAILED, mailbox0 = ");
3533 qla1280_output_number((uint32_t)mb
[0], 16);
3534 qla1280_print(" ****\n\r");
3537 #ifdef QL_DEBUG_LEVEL_3
3539 LEAVE("qla1280_mailbox_command");
3546 * Polls ISP for interrupts.
3549 * ha = adapter block pointer.
3552 qla1280_poll(scsi_qla_host_t
*ha
)
3554 device_reg_t
*reg
= ha
->iobase
;
3556 srb_t
*done_q_first
= 0;
3557 srb_t
*done_q_last
= 0;
3559 #ifdef QL_DEBUG_LEVEL_3
3560 /* ENTER("qla1280_poll"); */
3563 /* Acquire interrupt specific lock */
3564 QLA1280_INTR_LOCK(ha
);
3566 /* Check for pending interrupts. */
3567 data
= RD_REG_WORD(®
->istatus
);
3568 if (data
& RISC_INT
)
3569 qla1280_isr(ha
, (srb_t
**)&done_q_first
, (srb_t
**)&done_q_last
);
3571 /* Release interrupt specific lock */
3572 QLA1280_INTR_UNLOCK(ha
);
3574 if (!ha
->flags
.mbox_busy
)
3576 if (ha
->flags
.isp_abort_needed
)
3577 qla1280_abort_isp(ha
);
3578 if (ha
->flags
.reset_marker
)
3579 qla1280_rst_aen(ha
);
3583 qla1280_done(ha
, (srb_t
**)&done_q_first
, (srb_t
**)&done_q_last
);
3585 #ifdef QL_DEBUG_LEVEL_3
3586 /* LEAVE("qla1280_poll"); */
3592 * Issue SCSI bus reset.
3595 * ha = adapter block pointer.
3596 * b = SCSI bus number.
3602 qla1280_bus_reset(scsi_qla_host_t
*ha
, uint8_t b
)
3605 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3607 #ifdef QL_DEBUG_LEVEL_3
3608 qla1280_print("qla1280_bus_reset: entered\n\r");
3610 if( qla1280_verbose
)
3612 printk("scsi(%d): Resetting SCSI BUS (%d)\n",(int)ha
->host_no
,b
);
3615 mb
[0] = MBC_BUS_RESET
;
3616 mb
[1] = ha
->bus_settings
[b
].bus_reset_delay
;
3617 mb
[2] = (uint16_t)b
;
3618 status
= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3622 if (ha
->bus_settings
[b
].failed_reset_count
> 2) /* dg - 03/13/99 */
3623 ha
->bus_settings
[b
].scsi_bus_dead
= TRUE
;
3624 ha
->bus_settings
[b
].failed_reset_count
++;
3629 ha
->bus_settings
[b
].scsi_bus_dead
= FALSE
; /* dg - 03/13/99 */
3630 ha
->bus_settings
[b
].failed_reset_count
= 0;
3631 /* Issue marker command. */
3632 qla1280_marker(ha
, b
, 0, 0, MK_SYNC_ALL
);
3634 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3636 qla1280_print("qla1280_bus_reset: **** FAILED ****\n\r");
3638 #ifdef QL_DEBUG_LEVEL_3
3640 qla1280_print("qla1280_bus_reset: exiting normally\n\r");
3646 * qla1280_device_reset
3647 * Issue bus device reset message to the target.
3650 * ha = adapter block pointer.
3651 * b = SCSI BUS number.
3658 qla1280_device_reset(scsi_qla_host_t
*ha
, uint8_t b
, uint32_t t
)
3661 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3663 #ifdef QL_DEBUG_LEVEL_3
3664 ENTER("qla1280_device_reset");
3667 mb
[0] = MBC_ABORT_TARGET
;
3668 mb
[1] = (b
? (t
| BIT_7
) : t
) << 8;
3670 status
= qla1280_mailbox_command(ha
, BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3672 /* Issue marker command. */
3673 qla1280_marker(ha
, b
, t
, 0, MK_SYNC_ID
);
3675 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3677 qla1280_print("qla1280_device_reset: **** FAILED ****\n\r");
3679 #ifdef QL_DEBUG_LEVEL_3
3681 LEAVE("qla1280_device_reset");
3687 * qla1280_abort_device
3688 * Issue an abort message to the device
3691 * ha = adapter block pointer.
3700 qla1280_abort_device(scsi_qla_host_t
*ha
, uint8_t b
, uint32_t t
, uint32_t l
)
3703 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3705 #ifdef QL_DEBUG_LEVEL_3
3706 ENTER("qla1280_abort_device");
3709 mb
[0] = MBC_ABORT_DEVICE
;
3710 mb
[1] = (b
? t
| BIT_7
: t
) << 8 | l
;
3711 status
= qla1280_mailbox_command(ha
, BIT_1
|BIT_0
, &mb
[0]);
3713 /* Issue marker command. */
3714 qla1280_marker(ha
, b
, t
, l
, MK_SYNC_ID_LUN
);
3716 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3718 qla1280_print("qla1280_abort_device: **** FAILED ****\n\r");
3720 #ifdef QL_DEBUG_LEVEL_3
3722 LEAVE("qla1280_abort_device");
3728 * qla1280_abort_command
3729 * Abort command aborts a specified IOCB.
3732 * ha = adapter block pointer.
3733 * sp = SB structure pointer.
3739 qla1280_abort_command(scsi_qla_host_t
*ha
, srb_t
*sp
)
3742 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3746 #ifdef QL_DEBUG_LEVEL_3
3747 ENTER("qla1280_abort_command");
3750 /* Locate handle number. */
3751 for (handle
= 0; handle
< MAX_OUTSTANDING_COMMANDS
; handle
++)
3752 if (ha
->outstanding_cmds
[handle
] == sp
)
3755 b
= SCSI_BUS_32(sp
->cmd
);
3756 t
= SCSI_TCN_32(sp
->cmd
);
3757 l
= SCSI_LUN_32(sp
->cmd
);
3759 mb
[0] = MBC_ABORT_COMMAND
;
3760 mb
[1] = (b
? t
| BIT_7
: t
) << 8 | l
;
3761 mb
[2] = handle
>> 16;
3762 mb
[3] = (uint16_t)handle
;
3763 status
= qla1280_mailbox_command(ha
, BIT_3
|BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
3765 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3767 qla1280_print("qla1280_abort_command: **** FAILED ****\n\r");
3769 sp
->flags
|= SRB_ABORT_PENDING
;
3771 LEAVE("qla1280_abort_command");
3776 * qla1280_reset_adapter
3780 * ha = adapter block pointer.
3783 qla1280_reset_adapter(scsi_qla_host_t
*ha
)
3785 device_reg_t
*reg
= ha
->iobase
;
3787 #ifdef QL_DEBUG_LEVEL_3
3788 ENTER("qla1280_reset_adapter");
3791 /* Disable ISP chip */
3792 ha
->flags
.online
= FALSE
;
3793 WRT_REG_WORD(®
->ictrl
, ISP_RESET
);
3794 WRT_REG_WORD(®
->host_cmd
, HC_RESET_RISC
);
3795 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
3796 WRT_REG_WORD(®
->host_cmd
, HC_DISABLE_BIOS
);
3798 #ifdef QL_DEBUG_LEVEL_3
3799 LEAVE("qla1280_reset_adapter");
3804 * Issue marker command.
3805 * Function issues marker IOCB.
3808 * ha = adapter block pointer.
3809 * b = SCSI BUS number
3812 * type = marker modifier
3815 qla1280_marker(scsi_qla_host_t
*ha
, uint8_t b
, uint32_t t
, uint32_t l
, uint8_t type
)
3819 #ifdef QL_DEBUG_LEVEL_3
3820 ENTER("qla1280_marker");
3823 /* Get request packet. */
3824 if ( (pkt
= (mrk_entry_t
*)qla1280_req_pkt(ha
)) )
3826 pkt
->entry_type
= MARKER_TYPE
;
3827 pkt
->lun
= (uint8_t)l
;
3828 pkt
->target
= (uint8_t)(b
? (t
| BIT_7
) : t
);
3829 pkt
->modifier
= type
;
3831 /* Issue command to ISP */
3832 qla1280_isp_cmd(ha
);
3835 #ifdef QL_DEBUG_LEVEL_3
3836 LEAVE("qla1280_marker");
3840 #if QLA1280_64BIT_SUPPORT
3842 * qla1280_64bit_start_scsi
3843 * The start SCSI is responsible for building request packets on
3844 * request ring and modifying ISP input pointer.
3847 * ha = adapter block pointer.
3848 * sp = SB structure pointer.
3851 * 0 = success, was able to issue command.
3854 qla1280_64bit_start_scsi(scsi_qla_host_t
*ha
, srb_t
*sp
)
3856 device_reg_t
*reg
= ha
->iobase
;
3858 Scsi_Cmnd
*cmd
= sp
->cmd
;
3860 cmd_a64_entry_t
*pkt
;
3863 struct scatterlist
*sg
= (struct scatterlist
*) NULL
;
3864 uint32_t *dword_ptr
;
3866 #ifdef QL_DEBUG_LEVEL_3
3867 ENTER("qla1280_64bit_start_scsi:");
3870 if( qla1280_check_for_dead_scsi_bus(ha
, sp
) )
3875 /* Calculate number of entries and segments required. */
3880 seg_cnt
= cmd
->use_sg
;
3881 sg
= (struct scatterlist
*) cmd
->request_buffer
;
3885 req_cnt
+= (uint16_t)(seg_cnt
- 2) / 5;
3886 if ((uint16_t)(seg_cnt
- 2) % 5)
3890 else if (cmd
->request_bufflen
) /* If data transfer. */
3892 DEBUG(printk("Single data transfer (0x%x)\n",cmd
->request_bufflen
));
3896 /* Acquire ring specific lock */
3897 QLA1280_RING_LOCK(ha
);
3899 if ((uint16_t)(req_cnt
+ 2) >= ha
->req_q_cnt
)
3901 /* Calculate number of free request entries. */
3902 cnt
= RD_REG_WORD(®
->mailbox4
);
3903 if (ha
->req_ring_index
< cnt
)
3904 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
3906 ha
->req_q_cnt
= REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
3909 /* If room for request in request ring. */
3910 if ((uint16_t)(req_cnt
+ 2) < ha
->req_q_cnt
)
3912 /* Check for room in outstanding command list. */
3913 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
&&
3914 ha
->outstanding_cmds
[cnt
] != 0; cnt
++)
3917 if (cnt
< MAX_OUTSTANDING_COMMANDS
)
3919 ha
->outstanding_cmds
[cnt
] = sp
;
3920 ha
->req_q_cnt
-= req_cnt
;
3921 CMD_HANDLE(sp
->cmd
) = (unsigned char *) (u_long
) cnt
;
3924 * Build command packet.
3926 pkt
= (cmd_a64_entry_t
*)ha
->request_ring_ptr
;
3928 pkt
->entry_type
= COMMAND_A64_TYPE
;
3929 pkt
->entry_count
= (uint8_t)req_cnt
;
3930 pkt
->sys_define
= (uint8_t)ha
->req_ring_index
;
3931 pkt
->handle
= (uint32_t)cnt
;
3933 /* Zero out remaining portion of packet. */
3934 dword_ptr
= (uint32_t *)pkt
+ 2;
3935 for (cnt
= 2; cnt
< REQUEST_ENTRY_SIZE
/4; cnt
++)
3938 /* Set ISP command timeout. */
3939 pkt
->timeout
= (uint16_t)30;
3941 /* Set device target ID and LUN */
3942 pkt
->lun
= SCSI_LUN_32(cmd
);
3943 pkt
->target
= SCSI_BUS_32(cmd
) ?
3944 (SCSI_TCN_32(cmd
) | BIT_7
) : SCSI_TCN_32(cmd
);
3946 /* Enable simple tag queuing if device supports it. */
3947 if (cmd
->device
->tagged_queue
)
3948 pkt
->control_flags
|= BIT_3
;
3950 /* Load SCSI command packet. */
3951 pkt
->cdb_len
= (uint16_t)CMD_CDBLEN(cmd
);
3952 BCOPY(&(CMD_CDBP(cmd
)), pkt
->scsi_cdb
, pkt
->cdb_len
);
3953 DEBUG(printk("Build packet for command[0]=0x%x\n",pkt
->scsi_cdb
[0]));
3956 * Load data segments.
3958 if (seg_cnt
) /* If data transfer. */
3960 /* Set transfer direction. */
3961 if ( (cmd
->data_cmnd
[0] == WRITE_6
) )
3962 pkt
->control_flags
|= BIT_6
;
3964 pkt
->control_flags
|= (BIT_5
|BIT_6
);
3966 sp
->dir
= pkt
->control_flags
& (BIT_5
|BIT_6
);
3968 /* Set total data segment count. */
3969 pkt
->dseg_count
= seg_cnt
;
3971 /* Setup packet address segment pointer. */
3972 dword_ptr
= (uint32_t *)&pkt
->dseg_0_address
;
3974 if (cmd
->use_sg
) /* If scatter gather */
3976 /* Load command entry data segments. */
3977 for (cnt
= 0; cnt
< 2 && seg_cnt
; cnt
++, seg_cnt
--)
3979 DEBUG(sprintf(debug_buff
,"SG Segment ap=0x%p, len=0x%x\n\r",sg
->address
,sg
->length
));
3980 DEBUG(qla1280_print(debug_buff
));
3981 *dword_ptr
++ = cpu_to_le32(VIRT_TO_BUS_LOW(sg
->address
));
3982 *dword_ptr
++ = cpu_to_le32(VIRT_TO_BUS_HIGH(sg
->address
));
3983 *dword_ptr
++ = sg
->length
;
3986 #ifdef QL_DEBUG_LEVEL_5
3988 "qla1280_64bit_start_scsi: Scatter/gather command packet data - ");
3989 qla1280_print("b ");
3990 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd
), 10);
3991 qla1280_print(" t ");
3992 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd
), 10);
3993 qla1280_print(" d ");
3994 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd
), 10);
3995 qla1280_print("\n\r");
3996 qla1280_dump_buffer((caddr_t
)pkt
, REQUEST_ENTRY_SIZE
);
3999 * Build continuation packets.
4003 /* Adjust ring index. */
4004 ha
->req_ring_index
++;
4005 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
)
4007 ha
->req_ring_index
= 0;
4008 ha
->request_ring_ptr
= ha
->request_ring
;
4011 ha
->request_ring_ptr
++;
4013 pkt
= (cmd_a64_entry_t
*)ha
->request_ring_ptr
;
4015 /* Zero out packet. */
4016 dword_ptr
= (uint32_t *)pkt
;
4017 for (cnt
= 0;cnt
< REQUEST_ENTRY_SIZE
/4; cnt
++)
4020 /* Load packet defaults. */
4021 ((cont_a64_entry_t
*)pkt
)->entry_type
=
4023 ((cont_a64_entry_t
*)pkt
)->entry_count
= 1;
4024 ((cont_a64_entry_t
*)pkt
)->sys_define
= (uint8_t)
4027 /* Setup packet address segment pointer. */
4028 dword_ptr
= (uint32_t *)
4029 &((cont_a64_entry_t
*)pkt
)->dseg_0_address
;
4031 /* Load continuation entry data segments. */
4032 for (cnt
= 0; cnt
< 5 && seg_cnt
; cnt
++, seg_cnt
--)
4034 *dword_ptr
++ = cpu_to_le32(VIRT_TO_BUS_LOW(sg
->address
));
4035 *dword_ptr
++ = cpu_to_le32(VIRT_TO_BUS_HIGH(sg
->address
));
4036 *dword_ptr
++ = sg
->length
;
4039 #ifdef QL_DEBUG_LEVEL_5
4041 "qla1280_64bit_start_scsi: continuation packet data - c");
4042 qla1280_print(" b ");
4043 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd
), 10);
4045 qla1280_print(" t ");
4046 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd
), 10);
4047 qla1280_print(" d ");
4048 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd
), 10);
4049 qla1280_print("\n\r");
4050 qla1280_dump_buffer((caddr_t
)pkt
, REQUEST_ENTRY_SIZE
);
4054 else /* No scatter gather data transfer */
4056 *dword_ptr
++ = cpu_to_le32(VIRT_TO_BUS_LOW(cmd
->request_buffer
));
4057 *dword_ptr
++ = cpu_to_le32(VIRT_TO_BUS_HIGH(cmd
->request_buffer
));
4058 *dword_ptr
= (uint32_t) cmd
->request_bufflen
;
4059 #ifdef QL_DEBUG_LEVEL_5
4061 "qla1280_64bit_start_scsi: No scatter/gather command packet data - c");
4062 qla1280_print(" b ");
4063 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd
), 10);
4064 qla1280_print(" t ");
4065 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd
), 10);
4066 qla1280_print(" d ");
4067 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd
), 10);
4068 qla1280_print("\n\r");
4069 qla1280_dump_buffer((caddr_t
)pkt
, REQUEST_ENTRY_SIZE
);
4073 #ifdef QL_DEBUG_LEVEL_5
4074 else /* No data transfer */
4076 *dword_ptr
++ = (uint32_t) 0;
4077 *dword_ptr
++ = (uint32_t) 0;
4078 *dword_ptr
= (uint32_t) 0;
4080 "qla1280_64bit_start_scsi: No data, command packet data - c");
4081 qla1280_print(" b ");
4082 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd
), 10);
4083 qla1280_print(" t ");
4084 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd
), 10);
4085 qla1280_print(" d ");
4086 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd
), 10);
4087 qla1280_print("\n\r");
4088 qla1280_dump_buffer((caddr_t
)pkt
, REQUEST_ENTRY_SIZE
);
4091 /* Adjust ring index. */
4092 ha
->req_ring_index
++;
4093 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
)
4095 ha
->req_ring_index
= 0;
4096 ha
->request_ring_ptr
= ha
->request_ring
;
4099 ha
->request_ring_ptr
++;
4101 /* Set chip new ring index. */
4102 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
4107 #ifdef QL_DEBUG_LEVEL_2
4109 "qla1280_64bit_start_scsi: NO ROOM IN OUTSTANDING ARRAY\n\r");
4110 qla1280_print(" req_q_cnt=");
4111 qla1280_output_number((uint32_t)ha
->req_q_cnt
, 16);
4118 #ifdef QL_DEBUG_LEVEL_2
4119 qla1280_print("qla1280_64bit_start_scsi: in-ptr=");
4120 qla1280_output_number((uint32_t)ha
->req_ring_index
, 16);
4121 qla1280_print(" req_q_cnt=");
4122 qla1280_output_number((uint32_t)ha
->req_q_cnt
, 16);
4123 qla1280_print(" req_cnt=");
4124 qla1280_output_number((uint32_t)req_cnt
, 16);
4125 qla1280_print("\n\r");
4129 /* Release ring specific lock */
4130 QLA1280_RING_UNLOCK(ha
);
4132 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4134 qla1280_print("qla1280_64bit_start_scsi: **** FAILED ****\n\r");
4136 #ifdef QL_DEBUG_LEVEL_3
4138 qla1280_print("qla1280_64bit_start_scsi: exiting normally\n\r");
4142 #endif /* QLA1280_64BIT_SUPPORT */
4145 * qla1280_32bit_start_scsi
4146 * The start SCSI is responsible for building request packets on
4147 * request ring and modifying ISP input pointer.
4149 * The Qlogic firmware interface allows every queue slot to have a SCSI
4150 * command and up to 4 scatter/gather (SG) entries. If we need more
4151 * than 4 SG entries, then continuation entries are used that can
4152 * hold another 7 entries each. The start routine determines if there
4153 * is eought empty slots then build the combination of requests to
4154 * fulfill the OS request.
4157 * ha = adapter block pointer.
4158 * sp = SCSI Request Block structure pointer.
4161 * 0 = success, was able to issue command.
4164 qla1280_32bit_start_scsi(scsi_qla_host_t
*ha
, srb_t
*sp
)
4166 device_reg_t
*reg
= ha
->iobase
;
4168 Scsi_Cmnd
*cmd
= sp
->cmd
;
4173 struct scatterlist
*sg
= (struct scatterlist
*) NULL
;
4175 uint32_t *dword_ptr
;
4177 ENTER("qla1280_32bit_start_scsi");
4180 if( qla1280_check_for_dead_scsi_bus(ha
, sp
) )
4185 /* Calculate number of entries and segments required. */
4190 * We must build an SG list in adapter format, as the kernel's SG list
4191 * cannot be used directly because of data field size (__alpha__)
4192 * differences and the kernel SG list uses virtual addresses where
4193 * we need physical addresses.
4195 seg_cnt
= cmd
->use_sg
;
4196 sg
= (struct scatterlist
*) cmd
->request_buffer
;
4198 * if greater than four sg entries then we need to allocate
4199 * continuation entries
4203 req_cnt
+= (uint16_t)(seg_cnt
- 4) / 7;
4204 if ((uint16_t)(seg_cnt
- 4) % 7)
4207 DEBUG(sprintf(debug_buff
,"S/G for data transfer -num segs(%d), req blk cnt(%d)\n\r",seg_cnt
,req_cnt
));
4208 DEBUG(qla1280_print(debug_buff
));
4210 else if (cmd
->request_bufflen
) /* If data transfer. */
4212 DEBUG(printk("Single data transfer (0x%x)\n",cmd
->request_bufflen
));
4217 DEBUG(printk("No data transfer \n"));
4221 /* Acquire ring specific lock */
4222 QLA1280_RING_LOCK(ha
);
4224 if ((uint16_t)(req_cnt
+ 2) >= ha
->req_q_cnt
)
4226 /* Calculate number of free request entries. */
4227 cnt
= RD_REG_WORD(®
->mailbox4
);
4228 if (ha
->req_ring_index
< cnt
)
4229 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
4231 ha
->req_q_cnt
= REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
4234 DEBUG(sprintf(debug_buff
,"Number of free entries = (%d)\n\r",ha
->req_q_cnt
));
4235 DEBUG(qla1280_print(debug_buff
));
4236 /* If room for request in request ring. */
4237 if ((uint16_t)(req_cnt
+ 2) < ha
->req_q_cnt
)
4239 /* Check for empty slot in outstanding command list. */
4240 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
&&
4241 (ha
->outstanding_cmds
[cnt
] != 0); cnt
++)
4244 if (cnt
< MAX_OUTSTANDING_COMMANDS
)
4246 CMD_HANDLE(sp
->cmd
) = (unsigned char *)(unsigned long)cnt
;
4247 ha
->outstanding_cmds
[cnt
] = sp
;
4248 ha
->req_q_cnt
-= req_cnt
;
4251 * Build command packet.
4253 pkt
= (cmd_entry_t
*)ha
->request_ring_ptr
;
4255 pkt
->entry_type
= COMMAND_TYPE
;
4256 pkt
->entry_count
= (uint8_t)req_cnt
;
4257 pkt
->sys_define
= (uint8_t)ha
->req_ring_index
;
4258 pkt
->handle
= (uint32_t)cnt
;
4260 /* Zero out remaining portion of packet. */
4261 dword_ptr
= (uint32_t *)pkt
+ 2;
4262 for (cnt
= 2; cnt
< REQUEST_ENTRY_SIZE
/4; cnt
++)
4265 /* Set ISP command timeout. */
4266 pkt
->timeout
= (uint16_t)30;
4268 /* Set device target ID and LUN */
4269 pkt
->lun
= SCSI_LUN_32(cmd
);
4270 pkt
->target
= SCSI_BUS_32(cmd
) ?
4271 (SCSI_TCN_32(cmd
) | BIT_7
) : SCSI_TCN_32(cmd
);
4273 /* Enable simple tag queuing if device supports it. */
4274 if (cmd
->device
->tagged_queue
)
4275 pkt
->control_flags
|= BIT_3
;
4277 /* Load SCSI command packet. */
4278 pkt
->cdb_len
= (uint16_t)CMD_CDBLEN(cmd
);
4279 data_ptr
= (uint8_t *) &(CMD_CDBP(cmd
));
4280 for (cnt
= 0; cnt
< pkt
->cdb_len
; cnt
++)
4281 pkt
->scsi_cdb
[cnt
] = *data_ptr
++;
4282 DEBUG(printk("Build packet for command[0]=0x%x\n",pkt
->scsi_cdb
[0]));
4284 * Load data segments.
4288 DEBUG(printk("loading data segments..\n"));
4289 /* Set transfer direction (READ and WRITE) */
4290 /* Linux doesn't tell us */
4293 * 3/10 dg - Normally, we should need this check with our F/W
4294 * but because of a small issue with it we do.
4296 * For block devices, cmd->request.cmd has the operation
4297 * For character devices, this isn't always set properly, so
4298 * we need to check data_cmnd[0]. This catches the conditions
4299 * for st.c, but not sg. Generic commands are pass down to us.
4301 if ( (cmd
->data_cmnd
[0] == WRITE_6
) )
4302 pkt
->control_flags
|= BIT_6
;
4304 pkt
->control_flags
|= (BIT_5
|BIT_6
);
4306 sp
->dir
= pkt
->control_flags
& (BIT_5
|BIT_6
);
4308 /* Set total data segment count. */
4309 pkt
->dseg_count
= seg_cnt
;
4311 /* Setup packet address segment pointer. */
4312 dword_ptr
= (uint32_t *)&pkt
->dseg_0_address
;
4314 if (cmd
->use_sg
) /* If scatter gather */
4316 DEBUG(qla1280_print("Building S/G data segments..\n\r"));
4317 DEBUG(qla1280_dump_buffer((caddr_t
)sg
, 4*16 ));
4318 /* Load command entry data segments. */
4319 for (cnt
= 0; cnt
< 4 && seg_cnt
; cnt
++, seg_cnt
--)
4321 *dword_ptr
++ = (uint32_t) cpu_to_le32(VIRT_TO_BUS(sg
->address
));
4322 *dword_ptr
++ = sg
->length
;
4323 DEBUG(sprintf(debug_buff
,"SG Segment ap=0x%p, len=0x%x\n\r",sg
->address
,sg
->length
));
4324 DEBUG(qla1280_print(debug_buff
));
4328 * Build continuation packets.
4332 /* Adjust ring index. */
4333 ha
->req_ring_index
++;
4334 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
)
4336 ha
->req_ring_index
= 0;
4337 ha
->request_ring_ptr
= ha
->request_ring
;
4340 ha
->request_ring_ptr
++;
4342 pkt
= (cmd_entry_t
*)ha
->request_ring_ptr
;
4344 /* Zero out packet. */
4345 dword_ptr
= (uint32_t *)pkt
;
4346 for (cnt
= 0;cnt
< REQUEST_ENTRY_SIZE
/4; cnt
++)
4349 /* Load packet defaults. */
4350 ((cont_entry_t
*)pkt
)->entry_type
=
4352 ((cont_entry_t
*)pkt
)->entry_count
= 1;
4354 ((cont_entry_t
*)pkt
)->sys_define
= (uint8_t)
4357 /* Setup packet address segment pointer. */
4358 dword_ptr
= (uint32_t *)
4359 &((cont_entry_t
*)pkt
)->dseg_0_address
;
4361 /* Load continuation entry data segments. */
4362 for (cnt
= 0; cnt
< 7 && seg_cnt
; cnt
++, seg_cnt
--)
4364 *dword_ptr
++ = (u_int
) cpu_to_le32(VIRT_TO_BUS(sg
->address
));
4365 *dword_ptr
++ = sg
->length
;
4368 #ifdef QL_DEBUG_LEVEL_5
4370 "qla1280_32bit_start_scsi: continuation packet data - scsi(");
4371 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd
), 10);
4373 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd
), 10);
4375 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd
), 10);
4376 qla1280_print(")\n\r");
4377 qla1280_dump_buffer((caddr_t
)pkt
, REQUEST_ENTRY_SIZE
);
4381 else /* No scatter gather data transfer */
4383 *dword_ptr
++ = (uint32_t) cpu_to_le32(VIRT_TO_BUS(cmd
->request_buffer
));
4384 *dword_ptr
= (uint32_t) cmd
->request_bufflen
;
4385 DEBUG(printk("Single Segment ap=0x%p, len=0x%x\n",cmd
->request_buffer
,cmd
->request_bufflen
));
4388 else /* No data transfer */
4390 *dword_ptr
++ = (uint32_t) 0;
4391 *dword_ptr
= (uint32_t) 0;
4392 #ifdef QL_DEBUG_LEVEL_5
4394 "qla1280_32bit_start_scsi: No data, command packet data - ");
4395 qla1280_print("\n\r");
4396 qla1280_dump_buffer((caddr_t
)pkt
, REQUEST_ENTRY_SIZE
);
4399 #ifdef QL_DEBUG_LEVEL_5
4400 qla1280_print("qla1280_32bit_start_scsi: First IOCB block:\n\r");
4401 qla1280_dump_buffer((caddr_t
)ha
->request_ring_ptr
, REQUEST_ENTRY_SIZE
);
4403 /* Adjust ring index. */
4404 ha
->req_ring_index
++;
4405 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
)
4407 ha
->req_ring_index
= 0;
4408 ha
->request_ring_ptr
= ha
->request_ring
;
4411 ha
->request_ring_ptr
++;
4413 /* Set chip new ring index. */
4414 DEBUG(qla1280_print("qla1280_32bit_start_scsi: Wakeup RISC for pending command\n\r"));
4416 sp
->u_start
= jiffies
;
4417 sp
->flags
|= SRB_SENT
;
4419 /* qla1280_output_number((uint32_t)ha->actthreads++, 16); */
4420 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
4425 #ifdef QL_DEBUG_LEVEL_2
4427 "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING ARRAY\n\r");
4428 qla1280_print(" req_q_cnt=");
4429 qla1280_output_number((uint32_t)ha
->req_q_cnt
, 16);
4430 qla1280_print("\n\r");
4437 #ifdef QL_DEBUG_LEVEL_2
4438 /* qla1280_print("qla1280_32bit_start_scsi: in-ptr=");
4439 qla1280_output_number((uint32_t)ha->req_ring_index, 16);
4440 qla1280_print(" req_q_cnt=");
4441 qla1280_output_number((uint32_t)ha->req_q_cnt, 16);
4442 qla1280_print(" req_cnt=");
4443 qla1280_output_number((uint32_t)req_cnt, 16);
4444 qla1280_print("\n\r"); */
4448 /* Release ring specific lock */
4449 QLA1280_RING_UNLOCK(ha
);
4451 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4453 qla1280_print("qla1280_32bit_start_scsi: **** FAILED ****\n\r"); */
4455 #ifdef QL_DEBUG_LEVEL_3
4456 LEAVE("qla1280_32bit_start_scsi");
4463 * Function is responsible for locking ring and
4464 * getting a zeroed out request packet.
4467 * ha = adapter block pointer.
4470 * 0 = failed to get slot.
4473 qla1280_req_pkt(scsi_qla_host_t
*ha
)
4475 device_reg_t
*reg
= ha
->iobase
;
4478 uint32_t *dword_ptr
;
4481 #ifdef QL_DEBUG_LEVEL_3
4482 ENTER("qla1280_req_pkt");
4485 /* Wait for 30 seconds for slot. */
4486 for (timer
= 15000000; timer
; timer
--)
4488 /* Acquire ring specific lock */
4489 QLA1280_RING_LOCK(ha
);
4491 if (ha
->req_q_cnt
> 0)
4493 /* Calculate number of free request entries. */
4494 cnt
= RD_REG_WORD(®
->mailbox4
);
4495 if (ha
->req_ring_index
< cnt
)
4496 ha
->req_q_cnt
= cnt
- ha
->req_ring_index
;
4498 ha
->req_q_cnt
= REQUEST_ENTRY_CNT
- (ha
->req_ring_index
- cnt
);
4501 /* Found empty request ring slot? */
4502 if (ha
->req_q_cnt
> 0)
4505 pkt
= ha
->request_ring_ptr
;
4507 /* Zero out packet. */
4508 dword_ptr
= (uint32_t *)pkt
;
4509 for (cnt
= 0; cnt
< REQUEST_ENTRY_SIZE
/4; cnt
++)
4512 /* Set system defined field. */
4513 pkt
->sys_define
= (uint8_t)ha
->req_ring_index
;
4515 /* Set entry count. */
4516 pkt
->entry_count
= 1;
4521 /* Release ring specific lock */
4522 QLA1280_RING_UNLOCK(ha
);
4524 SYS_DELAY(2); /* 10 */
4526 /* Check for pending interrupts. */
4530 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4532 qla1280_print("qla1280_req_pkt: **** FAILED ****\n\r");
4534 #ifdef QL_DEBUG_LEVEL_3
4536 qla1280_print("qla1280_req_pkt: exiting normally\n\r");
4543 * Function is responsible for modifying ISP input pointer.
4544 * Releases ring lock.
4547 * ha = adapter block pointer.
4550 qla1280_isp_cmd(scsi_qla_host_t
*ha
)
4552 device_reg_t
*reg
= ha
->iobase
;
4554 #ifdef QL_DEBUG_LEVEL_3
4555 ENTER("qla1280_isp_cmd");
4558 #ifdef QL_DEBUG_LEVEL_5
4559 qla1280_print("qla1280_isp_cmd: IOCB data:\n\r");
4560 qla1280_dump_buffer((caddr_t
)ha
->request_ring_ptr
, REQUEST_ENTRY_SIZE
);
4563 /* Adjust ring index. */
4564 ha
->req_ring_index
++;
4565 if (ha
->req_ring_index
== REQUEST_ENTRY_CNT
)
4567 ha
->req_ring_index
= 0;
4568 ha
->request_ring_ptr
= ha
->request_ring
;
4571 ha
->request_ring_ptr
++;
4573 /* Set chip new ring index. */
4574 WRT_REG_WORD(®
->mailbox4
, ha
->req_ring_index
);
4576 /* Release ring specific lock */
4577 QLA1280_RING_UNLOCK(ha
);
4579 #ifdef QL_DEBUG_LEVEL_3
4580 LEAVE("qla1280_isp_cmd");
4585 * qla1280_enable_lun
4586 * Issue enable LUN entry IOCB.
4589 * ha = adapter block pointer.
4590 * b = SCSI BUS number.
4594 qla1280_enable_lun(scsi_qla_host_t
*ha
, uint8_t b
, uint32_t l
)
4598 #ifdef QL_DEBUG_LEVEL_3
4599 qla1280_print("qla1280_enable_lun: entered\n\r");
4602 /* Get request packet. */
4604 if (pkt = (elun_entry_t *)qla1280_req_pkt(ha))
4606 pkt->entry_type = ENABLE_LUN_TYPE;
4607 pkt->lun = (uint16_t)(b ? l | BIT_15 : l);
4608 pkt->command_count = 32;
4609 pkt->immed_notify_count = 1;
4610 pkt->group_6_length = MAX_CMDSZ;
4611 pkt->group_7_length = MAX_CMDSZ;
4612 pkt->timeout = 0x30;
4614 qla1280_isp_cmd(ha);
4617 pkt
= (elun_entry_t
*)1;
4619 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4621 qla1280_print("qla1280_enable_lun: **** FAILED ****\n\r");
4623 #ifdef QL_DEBUG_LEVEL_3
4625 qla1280_print("qla1280_enable_lun: exiting normally\n\r");
4629 #if QL1280_TARGET_MODE_SUPPORT
4630 /****************************************************************************/
4631 /* Target Mode Support Functions. */
4632 /****************************************************************************/
4635 * qla1280_notify_ack
4636 * Issue notify acknowledge IOCB.
4637 * If sequence ID is zero, acknowledgement of
4638 * SCSI bus reset or bus device reset is assumed.
4641 * ha = adapter block pointer.
4642 * inotify = immediate notify entry pointer.
4645 qla1280_notify_ack(scsi_qla_host_t
*ha
, notify_entry_t
*inotify
)
4649 #ifdef QL_DEBUG_LEVEL_3
4650 qla1280_print("qla1280_notify_ack: entered\n\r");
4653 /* Get request packet. */
4654 if (pkt
= (nack_entry_t
*)qla1280_req_pkt(ha
))
4656 pkt
->entry_type
= NOTIFY_ACK_TYPE
;
4657 pkt
->lun
= inotify
->lun
;
4658 pkt
->initiator_id
= inotify
->initiator_id
;
4659 pkt
->target_id
= inotify
->target_id
;
4660 if (inotify
->seq_id
== 0)
4663 pkt
->seq_id
= inotify
->seq_id
;
4665 /* Issue command to ISP */
4666 qla1280_isp_cmd(ha
);
4669 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4671 qla1280_print("qla1280_notify_ack: **** FAILED ****\n\r");
4673 #ifdef QL_DEBUG_LEVEL_3
4675 qla1280_print("qla1280_notify_ack: exiting normally\n\r");
4680 * qla1280_immed_notify
4681 * Issue immediate notify IOCB for LUN 0.
4684 * ha = adapter block pointer.
4685 * inotify = immediate notify entry pointer.
4688 qla1280_immed_notify(scsi_qla_host_t
*ha
, notify_entry_t
*inotify
)
4690 notify_entry_t
*pkt
;
4692 #ifdef QL_DEBUG_LEVEL_3
4693 qla1280_print("qla1280_immed_notify: entered\n\r");
4696 /* Get request packet. */
4697 if (pkt
= (notify_entry_t
*)qla1280_req_pkt(ha
))
4699 pkt
->entry_type
= IMMED_NOTIFY_TYPE
;
4700 pkt
->lun
= inotify
->lun
;
4701 pkt
->initiator_id
= inotify
->initiator_id
;
4702 pkt
->target_id
= inotify
->target_id
;
4705 /* Issue command to ISP */
4706 qla1280_isp_cmd(ha
);
4709 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4711 qla1280_print("qla1280_immed_notify: **** FAILED ****\n\r");
4713 #ifdef QL_DEBUG_LEVEL_3
4715 qla1280_print("qla1280_immed_notify: exiting normally\n\r");
4721 * Issue accept target I/O IOCB for LUN 0.
4724 * ha = adapter block pointer.
4725 * ctio = ctio returned entry pointer.
4728 qla1280_accept_io(scsi_qla_host_t
*ha
, ctio_ret_entry_t
*ctio
)
4732 #ifdef QL_DEBUG_LEVEL_3
4733 qla1280_print("qla1280_accept_io: entered\n\r");
4736 /* Get request packet. */
4737 if (pkt
= (atio_entry_t
*)qla1280_req_pkt(ha
))
4739 pkt
->entry_type
= ACCEPT_TGT_IO_TYPE
;
4740 pkt
->lun
= ctio
->lun
;
4741 pkt
->initiator_id
= ctio
->initiator_id
;
4742 pkt
->target_id
= ctio
->target_id
;
4743 pkt
->tag_value
= ctio
->tag_value
;
4746 /* Issue command to ISP */
4747 qla1280_isp_cmd(ha
);
4750 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4752 qla1280_print("qla1280_accept_io: **** FAILED ****\n\r");
4754 #ifdef QL_DEBUG_LEVEL_3
4756 qla1280_print("qla1280_accept_io: exiting normally\n\r");
4761 * qla1280_64bit_continue_io
4762 * Issue continue target I/O IOCB.
4765 * ha = adapter block pointer.
4766 * atio = atio pointer.
4767 * len = total bytecount.
4768 * addr = physical address pointer.
4771 qla1280_64bit_continue_io(scsi_qla_host_t
*ha
, atio_entry_t
*atio
, uint32_t len
,
4774 ctio_a64_entry_t
*pkt
;
4775 uint32_t *dword_ptr
;
4777 #ifdef QL_DEBUG_LEVEL_3
4778 qla1280_print("qla1280_64bit_continue_io: entered\n\r");
4781 /* Get request packet. */
4782 if (pkt
= (ctio_a64_entry_t
*)qla1280_req_pkt(ha
))
4784 pkt
->entry_type
= CTIO_A64_TYPE
;
4785 pkt
->lun
= atio
->lun
;
4786 pkt
->initiator_id
= atio
->initiator_id
;
4787 pkt
->target_id
= atio
->target_id
;
4788 pkt
->option_flags
= atio
->option_flags
;
4789 pkt
->tag_value
= atio
->tag_value
;
4790 pkt
->scsi_status
= atio
->scsi_status
;
4794 pkt
->dseg_count
= 1;
4795 pkt
->transfer_length
= len
;
4796 pkt
->dseg_0_length
= len
;
4797 dword_ptr
= (uint32_t *)addr
;
4798 pkt
->dseg_0_address
[0] = *dword_ptr
++;
4799 pkt
->dseg_0_address
[1] = *dword_ptr
;
4802 /* Issue command to ISP */
4803 qla1280_isp_cmd(ha
);
4806 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4808 qla1280_print("qla1280_64bit_continue_io: **** FAILED ****\n\r");
4810 #ifdef QL_DEBUG_LEVEL_3
4812 qla1280_print("qla1280_64bit_continue_io: exiting normally\n\r");
4817 * qla1280_32bit_continue_io
4818 * Issue continue target I/O IOCB.
4821 * ha = adapter block pointer.
4822 * atio = atio pointer.
4823 * len = total bytecount.
4824 * addr = physical address pointer.
4827 qla1280_32bit_continue_io(scsi_qla_host_t
*ha
, atio_entry_t
*atio
, uint32_t len
,
4831 uint32_t *dword_ptr
;
4833 #ifdef QL_DEBUG_LEVEL_3
4834 qla1280_print("qla1280_32bit_continue_io: entered\n\r");
4837 /* Get request packet. */
4838 if (pkt
= (ctio_entry_t
*)qla1280_req_pkt(ha
))
4840 pkt
->entry_type
= CONTINUE_TGT_IO_TYPE
;
4841 pkt
->lun
= atio
->lun
;
4842 pkt
->initiator_id
= atio
->initiator_id
;
4843 pkt
->target_id
= atio
->target_id
;
4844 pkt
->option_flags
= atio
->option_flags
;
4845 pkt
->tag_value
= atio
->tag_value
;
4846 pkt
->scsi_status
= atio
->scsi_status
;
4850 pkt
->dseg_count
= 1;
4851 pkt
->transfer_length
= len
;
4852 pkt
->dseg_0_length
= len
;
4853 dword_ptr
= (uint32_t *)addr
;
4854 pkt
->dseg_0_address
= *dword_ptr
;
4857 /* Issue command to ISP */
4858 qla1280_isp_cmd(ha
);
4861 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4863 qla1280_print("qla1280_32bit_continue_io: **** FAILED ****\n\r");
4865 #ifdef QL_DEBUG_LEVEL_3
4867 qla1280_print("qla1280_32bit_continue_io: exiting normally\n\r");
4870 #endif /* QL1280_TARGET_MODE_SUPPORT */
4872 /****************************************************************************/
4873 /* Interrupt Service Routine. */
4874 /****************************************************************************/
4876 /****************************************************************************
4878 * Calls I/O done on command completion.
4881 * ha = adapter block pointer.
4882 * done_q_first = done queue first pointer.
4883 * done_q_last = done queue last pointer.
4884 * INTR_LOCK must be already obtained.
4885 ****************************************************************************/
4887 qla1280_isr(scsi_qla_host_t
*ha
, srb_t
**done_q_first
, srb_t
**done_q_last
)
4889 device_reg_t
*reg
= ha
->iobase
;
4892 uint16_t mailbox
[MAILBOX_REGISTER_COUNT
];
4896 ENTER("qla1280_isr");
4899 /* Save mailbox register 5 */
4900 mailbox
[5] = RD_REG_WORD(®
->mailbox5
);
4902 /* Check for mailbox interrupt. */
4904 mailbox
[0] = RD_REG_WORD(®
->semaphore
);
4905 if (mailbox
[0] & BIT_0
)
4907 /* Get mailbox data. */
4910 *wptr
++ = RD_REG_WORD(®
->mailbox0
);
4911 *wptr
++ = RD_REG_WORD(®
->mailbox1
);
4912 *wptr
= RD_REG_WORD(®
->mailbox2
);
4913 if (mailbox
[0] != MBA_SCSI_COMPLETION
)
4916 *wptr
++ = RD_REG_WORD(®
->mailbox3
);
4917 *wptr
++ = RD_REG_WORD(®
->mailbox4
);
4919 *wptr
++ = RD_REG_WORD(®
->mailbox6
);
4920 *wptr
= RD_REG_WORD(®
->mailbox7
);
4923 /* Release mailbox registers. */
4925 WRT_REG_WORD(®
->semaphore
, 0);
4926 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
4928 #ifdef QL_DEBUG_LEVEL_5
4929 qla1280_print("qla1280_isr: mailbox interrupt mailbox[0] = ");
4930 qla1280_output_number((uint32_t)mailbox
[0], 16);
4931 qla1280_print("\n\r");
4934 /* Handle asynchronous event */
4938 case MBA_SCSI_COMPLETION
: /* Response completion */
4939 #ifdef QL_DEBUG_LEVEL_5
4940 qla1280_print("qla1280_isr: mailbox response completion\n\r");
4942 if (ha
->flags
.online
)
4944 /* Get outstanding command index. */
4945 index
= (uint32_t)(mailbox
[2] << 16 | mailbox
[1]);
4947 /* Validate handle. */
4948 if (index
< MAX_OUTSTANDING_COMMANDS
)
4949 sp
= ha
->outstanding_cmds
[index
];
4955 /* Free outstanding command slot. */
4956 ha
->outstanding_cmds
[index
] = 0;
4958 /* Save ISP completion status */
4959 CMD_RESULT(sp
->cmd
) = 0;
4961 /* Place block on done queue */
4963 sp
->s_prev
= *done_q_last
;
4967 (*done_q_last
)->s_next
= sp
;
4972 #ifdef QL_DEBUG_LEVEL_2
4973 qla1280_print("qla1280_isr: ISP invalid handle\n\r");
4975 printk(KERN_WARNING
"qla1280: ISP invalid handle");
4976 ha
->flags
.isp_abort_needed
= TRUE
;
4980 case MBA_BUS_RESET
: /* SCSI Bus Reset */
4981 #ifdef QL_DEBUG_LEVEL_2
4982 qla1280_print("qla1280_isr: asynchronous BUS_RESET\n\r");
4984 ha
->flags
.reset_marker
= TRUE
;
4985 index
= mailbox
[6] & BIT_0
;
4986 ha
->bus_settings
[index
].reset_marker
= TRUE
;
4988 case MBA_SYSTEM_ERR
: /* System Error */
4989 #ifdef QL_DEBUG_LEVEL_2
4990 qla1280_print("qla1280_isr: ISP System Error - mbx1=");
4991 qla1280_output_number((uint32_t)mailbox
[1], 16);
4992 qla1280_print(", mbx2=");
4993 qla1280_output_number((uint32_t)mailbox
[2], 16);
4994 qla1280_print(", mbx3=");
4995 qla1280_output_number((uint32_t)mailbox
[3], 16);
4996 qla1280_print("\n\r");
4999 "qla1280: ISP System Error - mbx1=%xh, mbx2=%xh, mbx3=%xh\n",
5000 mailbox
[1], mailbox
[2], mailbox
[3]);
5001 ha
->flags
.isp_abort_needed
= TRUE
;
5003 case MBA_REQ_TRANSFER_ERR
: /* Request Transfer Error */
5004 #ifdef QL_DEBUG_LEVEL_2
5005 qla1280_print("qla1280_isr: ISP Request Transfer Error\n\r");
5007 printk(KERN_WARNING
"qla1280: ISP Request Transfer Error\n");
5008 ha
->flags
.isp_abort_needed
= TRUE
;
5010 case MBA_RSP_TRANSFER_ERR
: /* Response Transfer Error */
5011 #ifdef QL_DEBUG_LEVEL_2
5012 qla1280_print("qla1280_isr: ISP Response Transfer Error\n\r");
5014 printk(KERN_WARNING
"qla1280: ISP Response Transfer Error\n");
5015 ha
->flags
.isp_abort_needed
= TRUE
;
5017 case MBA_WAKEUP_THRES
: /* Request Queue Wake-up */
5018 #ifdef QL_DEBUG_LEVEL_2
5019 qla1280_print("qla1280_isr: asynchronous WAKEUP_THRES\n\r");
5022 case MBA_TIMEOUT_RESET
: /* Execution Timeout Reset */
5023 #ifdef QL_DEBUG_LEVEL_2
5024 qla1280_print("qla1280_isr: asynchronous TIMEOUT_RESET\n\r");
5027 case MBA_DEVICE_RESET
: /* Bus Device Reset */
5028 #ifdef QL_DEBUG_LEVEL_2
5030 "qla1280_isr: asynchronous BUS_DEVICE_RESET\n\r");
5032 ha
->flags
.reset_marker
= TRUE
;
5033 index
= mailbox
[6] & BIT_0
;
5034 ha
->bus_settings
[index
].reset_marker
= TRUE
;
5036 case MBA_BUS_MODE_CHANGE
:
5037 #ifdef QL_DEBUG_LEVEL_2
5039 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n\r");
5043 if (mailbox
[0] < MBA_ASYNC_EVENT
)
5046 ha
->mailbox_out
[0] = *wptr
++;
5047 ha
->mailbox_out
[1] = *wptr
++;
5048 ha
->mailbox_out
[2] = *wptr
++;
5049 ha
->mailbox_out
[3] = *wptr
++;
5050 ha
->mailbox_out
[4] = *wptr
++;
5051 ha
->mailbox_out
[5] = *wptr
++;
5052 ha
->mailbox_out
[6] = *wptr
++;
5053 ha
->mailbox_out
[7] = *wptr
;
5054 ha
->flags
.mbox_int
= TRUE
;
5060 WRT_REG_WORD(®
->host_cmd
, HC_CLR_RISC_INT
);
5065 if (ha
->flags
.online
&& !ha
->flags
.mbox_busy
)
5067 if (mailbox
[5] < RESPONSE_ENTRY_CNT
)
5069 while (ha
->rsp_ring_index
!= mailbox
[5])
5071 pkt
= ha
->response_ring_ptr
;
5073 #ifdef QL_DEBUG_LEVEL_5
5074 qla1280_print("qla1280_isr: ha->rsp_ring_index = ");
5075 qla1280_output_number((uint32_t)ha
->rsp_ring_index
, 16);
5076 qla1280_print(" mailbox[5] = ");
5077 qla1280_output_number((uint32_t)mailbox
[5], 16);
5078 qla1280_print("\n\rqla1280_isr: response packet data\n\r");
5079 qla1280_dump_buffer((caddr_t
)pkt
, RESPONSE_ENTRY_SIZE
);
5082 #if defined(QL_DEBUG_LEVEL_2) && !defined(QL_DEBUG_LEVEL_5)
5083 if (pkt
->entry_type
== STATUS_TYPE
)
5085 if ((uint8_t)(pkt
->scsi_status
) || pkt
->comp_status
||
5088 DEBUG(qla1280_print("qla1280_isr: ha->rsp_ring_index = ");)
5089 DEBUG(qla1280_output_number((uint32_t)ha
->rsp_ring_index
,
5091 DEBUG(qla1280_print(" mailbox[5] = ");)
5092 DEBUG(qla1280_output_number((uint32_t)mailbox
[5], 16);)
5093 DEBUG(qla1280_print( "\n\r comp_status = ");)
5094 DEBUG(qla1280_output_number((uint32_t)pkt
->comp_status
,16);)
5095 DEBUG(qla1280_print( ", ");)
5096 DEBUG(qla1280_print( " scsi_status = ");)
5097 DEBUG(qla1280_output_number((uint32_t)pkt
->scsi_status
,16);)
5098 DEBUG(qla1280_print( "\n\r");)
5100 "\n\rqla1280_isr: response packet data\n\r");
5101 qla1280_dump_buffer((caddr_t)pkt,
5102 RESPONSE_ENTRY_SIZE); */
5107 qla1280_print("qla1280_isr: ha->rsp_ring_index = ");
5108 qla1280_output_number((uint32_t)ha
->rsp_ring_index
, 16);
5109 qla1280_print(" mailbox[5] = ");
5110 qla1280_output_number((uint32_t)mailbox
[5], 16);
5112 "\n\rqla1280_isr: response packet data\n\r");
5113 qla1280_dump_buffer((caddr_t
)pkt
, RESPONSE_ENTRY_SIZE
);
5116 if (pkt
->entry_type
== STATUS_TYPE
|| pkt
->entry_status
)
5118 if (pkt
->entry_type
== STATUS_TYPE
)
5119 qla1280_status_entry(ha
, (sts_entry_t
*)pkt
,
5120 done_q_first
, done_q_last
);
5122 qla1280_error_entry(ha
, pkt
,
5123 done_q_first
, done_q_last
);
5125 /* Adjust ring index. */
5126 ha
->rsp_ring_index
++;
5127 if (ha
->rsp_ring_index
== RESPONSE_ENTRY_CNT
)
5129 ha
->rsp_ring_index
= 0;
5130 ha
->response_ring_ptr
= ha
->response_ring
;
5133 ha
->response_ring_ptr
++;
5134 WRT_REG_WORD(®
->mailbox5
, ha
->rsp_ring_index
);
5136 #if QLA1280_TARGET_MODE_SUPPORT
5139 pkt
= &response_entry
;
5142 dptr1
= (uint32_t *)ha
->response_ring_ptr
;
5143 dptr2
= (uint32_t *)pkt
;
5144 for (index
= 0; index
< RESPONSE_ENTRY_SIZE
/4; index
++)
5145 *dptr2
++ = *dptr1
++;
5147 /* Adjust ring index. */
5148 ha
->rsp_ring_index
++;
5149 if (ha
->rsp_ring_index
== RESPONSE_ENTRY_CNT
)
5151 ha
->rsp_ring_index
= 0;
5152 ha
->response_ring_ptr
= ha
->response_ring
;
5155 ha
->response_ring_ptr
++;
5156 WRT_REG_WORD(®
->mailbox5
, ha
->rsp_ring_index
);
5158 /* Release interrupt specific lock */
5159 QLA1280_INTR_UNLOCK(ha
);
5161 switch (pkt
->entry_type
)
5163 case ACCEPT_TGT_IO_TYPE
:
5164 qla1280_atio_entry(ha
, (atio_entry_t
*)pkt
);
5166 case IMMED_NOTIFY_TYPE
:
5167 qla1280_notify_entry(ha
, (notify_entry_t
*)pkt
);
5170 qla1280_accept_io(ha
, (ctio_ret_entry_t
*)pkt
);
5176 /* Acquire interrupt specific lock */
5177 QLA1280_INTR_LOCK(ha
);
5184 ha
->flags
.isp_abort_needed
= TRUE
;
5185 #ifdef QL_DEBUG_LEVEL_2
5186 qla1280_print("qla1280_isr: Response pointer Error\n");
5191 LEAVE("qla1280_isr");
5196 * Processes asynchronous reset.
5199 * ha = adapter block pointer.
5202 qla1280_rst_aen(scsi_qla_host_t
*ha
)
5204 #if QL1280_TARGET_MODE_SUPPORT
5205 notify_entry_t nentry
;
5209 #ifdef QL_DEBUG_LEVEL_3
5210 ENTER("qla1280_rst_aen");
5213 if (ha
->flags
.online
&& !ha
->flags
.reset_active
&&
5214 !ha
->flags
.abort_isp_active
)
5216 ha
->flags
.reset_active
= TRUE
;
5217 while (ha
->flags
.reset_marker
)
5219 /* Issue marker command. */
5220 ha
->flags
.reset_marker
= FALSE
;
5221 for (b
= 0; b
< ha
->ports
&& !ha
->flags
.reset_marker
; b
++)
5223 if (ha
->bus_settings
[b
].reset_marker
)
5225 ha
->bus_settings
[b
].reset_marker
= FALSE
;
5226 qla1280_marker(ha
, b
, 0, 0, MK_SYNC_ALL
);
5228 if (!ha
->flags
.reset_marker
)
5230 #if QL1280_TARGET_MODE_SUPPORT
5231 /* Issue notify acknowledgement command. */
5232 bzero((caddr_t
)&nentry
, sizeof(notify_entry_t
));
5234 nentry
.initiator_id
= nentry
.target_id
= b
?
5235 ha
->bus_settings
[b
].id
| BIT_7
:
5236 ha
->bus_settings
[b
].id
;
5237 qla1280_notify_entry(ha
, &nentry
);
5240 /* Asynchronous event notification */
5247 #ifdef QL_DEBUG_LEVEL_3
5248 LEAVE("qla1280_rst_aen");
5252 #if QL1280_TARGET_MODE_SUPPORT
5254 * qla1280_atio_entry
5255 * Processes received ISP accept target I/O entry.
5258 * ha = adapter block pointer.
5259 * pkt = entry pointer.
5262 qla1280_atio_entry(scsi_qla_host_t
*ha
, atio_entry_t
*pkt
)
5266 paddr32_t phy_addr
[2];
5267 paddr32_t end_addr
[2];
5273 #ifdef QL_DEBUG_LEVEL_3
5274 qla1280_print("qla1280_atio_entry: entered\n\r");
5277 t
= pkt
->initiator_id
;
5278 sense_ptr
= ha
->tsense
+ t
* TARGET_SENSE_SIZE
;
5279 a64
= (uint64_t *)&phy_addr
[0];
5280 end_a64
= (uint64_t *)&end_addr
[0];
5282 switch (pkt
->status
& ~BIT_7
)
5284 case 7: /* Path invalid */
5285 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5286 qla1280_print("qla1280_atio_entry: Path invalid\n\r");
5289 case 0x14: /* Target Bus Phase Sequence Failure */
5290 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5292 "qla1280_atio_entry: Target Bus Phase Sequence Failure\n\r");
5294 if (pkt
->status
& BIT_7
)
5296 BCOPY((caddr_t
)&pkt
->sense_data
, sense_ptr
,TARGET_SENSE_SIZE
);
5300 bzero(sense_ptr
, TARGET_SENSE_SIZE
);
5302 *(sense_ptr
+2) = SD_HARDERR
;
5303 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5304 *(sense_ptr
+12) = SC_SELFAIL
;
5306 pkt
->scsi_status
= S_CKCON
;
5307 pkt
->option_flags
|= (uint32_t)OF_SSTS
| (uint32_t)OF_NO_DATA
;
5308 if (ha
->flags
.enable_64bit_addressing
)
5309 qla1280_64bit_continue_io(ha
, pkt
, 0, 0);
5311 qla1280_32bit_continue_io(ha
, pkt
, 0, 0);
5313 case 0x16: /* Requested Capability Not Available */
5314 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5316 "qla1280_atio_entry: Target Bus Phase Sequence Failure\n\r");
5319 case 0x17: /* Bus Device Reset Message Received */
5320 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5322 "qla1280_atio_entry: Target Bus Phase Sequence Failure\n\r");
5325 case 0x3D: /* CDB Received */
5327 /* Check for invalid LUN */
5328 if (pkt
->lun
&& pkt
->cdb
[0] != SS_INQUIR
&&
5329 pkt
->cdb
[0] != SS_REQSEN
)
5330 pkt
->cdb
[0] = SS_TEST
;
5332 switch (pkt
->cdb
[0])
5335 #ifdef QL_DEBUG_LEVEL_3
5336 qla1280_print("qla1280_atio_entry: SS_TEST\n\r");
5338 bzero(sense_ptr
, TARGET_SENSE_SIZE
);
5341 pkt
->scsi_status
= S_GOOD
;
5345 *(sense_ptr
+2) = SD_ILLREQ
;
5346 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5347 *(sense_ptr
+12) = SC_INVLUN
;
5348 pkt
->scsi_status
= S_CKCON
;
5351 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5352 (uint32_t)OF_NO_DATA
;
5355 #ifdef QL_DEBUG_LEVEL_3
5356 qla1280_print("qla1280_atio_entry: SS_REQSEN\n\r");
5358 phy_addr
[0] = ha
->tsense_dma
;
5360 *a64
+= t
* TARGET_SENSE_SIZE
;
5361 if (pkt
->cdb
[4] > TARGET_SENSE_SIZE
)
5362 len
= TARGET_SENSE_SIZE
;
5365 pkt
->scsi_status
= S_GOOD
;
5366 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5367 (uint32_t)OF_DATA_IN
;
5370 #ifdef QL_DEBUG_LEVEL_3
5371 qla1280_print("qla1280_atio_entry: SS_INQUIR\n\r");
5373 bzero(sense_ptr
, TARGET_SENSE_SIZE
);
5374 phy_addr
[0] = ha
->tbuf_dma
;
5376 *a64
+= TARGET_INQ_OFFSET
;
5380 ha
->tbuf
->inq
.id_type
= ID_PROCESOR
;
5381 ha
->tbuf
->inq
.id_pqual
= ID_QOK
;
5385 ha
->tbuf
->inq
.id_type
= ID_NODEV
;
5386 ha
->tbuf
->inq
.id_pqual
= ID_QNOLU
;
5389 if (pkt
->cdb
[4] > sizeof(struct ident
))
5390 len
= sizeof(struct ident
);
5393 pkt
->scsi_status
= S_GOOD
;
5394 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5395 (uint32_t)OF_DATA_IN
;
5398 bzero(sense_ptr
, TARGET_SENSE_SIZE
);
5399 offset
= pkt
->cdb
[5];
5400 offset
|= pkt
->cdb
[4] << 8;
5401 offset
|= pkt
->cdb
[3] << 16;
5403 len
|= pkt
->cdb
[7] << 8;
5404 len
|= pkt
->cdb
[6] << 16;
5405 end_addr
[0] = phy_addr
[0] = ha
->tbuf_dma
;
5406 end_addr
[1] = phy_addr
[1] = 0;
5407 *end_a64
+= TARGET_DATA_OFFSET
+ TARGET_DATA_SIZE
;
5408 switch (pkt
->cdb
[1] & 7)
5411 #ifdef QL_DEBUG_LEVEL_3
5412 qla1280_print("qla1280_atio_entry: SM_WRDB, RW_BUF_HDATA\n\r");
5414 if (len
> TARGET_DATA_SIZE
+ 4)
5416 #ifdef QL_DEBUG_LEVEL_2
5417 qla1280_print("qla1280_atio_entry: SM_WRDB, length > buffer size\n\r");
5420 *(sense_ptr
+2) = SD_ILLREQ
;
5421 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5422 *(sense_ptr
+12) = SC_ILLCDB
;
5423 pkt
->scsi_status
= S_CKCON
;
5424 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5425 (uint32_t)OF_NO_DATA
;
5430 pkt
->scsi_status
= S_GOOD
;
5431 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5432 (uint32_t)OF_DATA_OUT
;
5433 #ifdef QL_DEBUG_LEVEL_3
5434 qla1280_print("qla1280_atio_entry: Issuing SDI_TARMOD_WRCOMP\n\r");
5436 sdi_xaen(SDI_TARMOD_WRCOMP
, ha
->cntlr
,
5437 pkt
->target_id
, pkt
->lun
, 0, offset
);
5441 #ifdef QL_DEBUG_LEVEL_2
5442 qla1280_print("qla1280_atio_entry: SM_WRDB, zero length\n\r");
5444 pkt
->scsi_status
= S_GOOD
;
5445 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5446 (uint32_t)OF_NO_DATA
;
5451 #ifdef QL_DEBUG_LEVEL_3
5452 qla1280_print("qla1280_atio_entry: SM_WRDB, RW_BUF_DATA\n\r");
5454 *a64
+= offset
+ TARGET_DATA_OFFSET
;
5455 if (pkt
->cdb
[2] != 0 || *a64
>= *end_a64
||
5456 *a64
+ len
> *end_a64
)
5458 #ifdef QL_DEBUG_LEVEL_2
5459 qla1280_print("qla1280_atio_entry: SM_WRDB, RW_BUF_DATA BAD\n\r");
5460 qla1280_print("buf_id=");
5461 qla1280_output_number((uint32_t)pkt
->cdb
[2], 16);
5462 qla1280_print(", offset=");
5463 qla1280_output_number((uint32_t)offset
, 16);
5464 qla1280_print(", length=");
5465 qla1280_output_number((uint32_t)len
, 16);
5466 qla1280_print("\n\r");
5469 *(sense_ptr
+2) = SD_ILLREQ
;
5470 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5471 *(sense_ptr
+12) = SC_ILLCDB
;
5473 pkt
->scsi_status
= S_CKCON
;
5474 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5475 (uint32_t)OF_NO_DATA
;
5479 pkt
->scsi_status
= S_GOOD
;
5480 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5481 (uint32_t)OF_DATA_OUT
;
5482 #ifdef QL_DEBUG_LEVEL_3
5483 qla1280_print("qla1280_atio_entry: Issuing SDI_TARMOD_WRCOMP\n\r");
5485 sdi_xaen(SDI_TARMOD_WRCOMP
, ha
->cntlr
,
5486 pkt
->target_id
, pkt
->lun
, 0, offset
);
5490 #ifdef QL_DEBUG_LEVEL_2
5491 qla1280_print("qla1280_atio_entry: SM_WRDB, zero length\n\r");
5493 pkt
->scsi_status
= S_GOOD
;
5494 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5495 (uint32_t)OF_NO_DATA
;
5499 #ifdef QL_DEBUG_LEVEL_2
5500 qla1280_print("qla1280_atio_entry: SM_WRDB unknown mode\n\r");
5503 *(sense_ptr
+2) = SD_ILLREQ
;
5504 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5505 *(sense_ptr
+12) = SC_ILLCDB
;
5507 pkt
->scsi_status
= S_CKCON
;
5508 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5509 (uint32_t)OF_NO_DATA
;
5514 bzero(sense_ptr
, TARGET_SENSE_SIZE
);
5515 offset
= pkt
->cdb
[5];
5516 offset
|= pkt
->cdb
[4] << 8;
5517 offset
|= pkt
->cdb
[3] << 16;
5519 len
|= pkt
->cdb
[7] << 8;
5520 len
|= pkt
->cdb
[6] << 16;
5521 end_addr
[0] = phy_addr
[0] = ha
->tbuf_dma
;
5522 end_addr
[1] = phy_addr
[1] = 0;
5523 *end_a64
+= TARGET_DATA_OFFSET
+ TARGET_DATA_SIZE
;
5524 switch (pkt
->cdb
[1] & 7)
5527 #ifdef QL_DEBUG_LEVEL_3
5528 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_HDATA\n\r");
5532 ha
->tbuf
->hdr
[0] = 0;
5534 (uint8_t)(TARGET_DATA_SIZE
>> 16);
5536 (uint8_t)(TARGET_DATA_SIZE
>> 8);
5537 ha
->tbuf
->hdr
[3] = (uint8_t)TARGET_DATA_SIZE
;
5538 if (len
> TARGET_DATA_SIZE
+ 4)
5539 len
= TARGET_DATA_SIZE
+ 4;
5540 pkt
->scsi_status
= S_GOOD
;
5541 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5542 (uint32_t)OF_DATA_IN
;
5546 #ifdef QL_DEBUG_LEVEL_2
5547 qla1280_print("qla1280_atio_entry: SM_RDDB, zero length\n\r");
5549 pkt
->scsi_status
= S_GOOD
;
5550 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5551 (uint32_t)OF_NO_DATA
;
5555 #ifdef QL_DEBUG_LEVEL_3
5556 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_DATA\n\r");
5558 *a64
+= offset
+ TARGET_DATA_OFFSET
;
5559 if (pkt
->cdb
[2] != 0 || *a64
>= *end_a64
)
5561 #ifdef QL_DEBUG_LEVEL_2
5562 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_DATA BAD\n\r");
5563 qla1280_print("buf_id=");
5564 qla1280_output_number((uint32_t)pkt
->cdb
[2], 16);
5565 qla1280_print(", offset=");
5566 qla1280_output_number((uint32_t)offset
, 16);
5567 qla1280_print("\n\r");
5570 *(sense_ptr
+2) = SD_ILLREQ
;
5571 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5572 *(sense_ptr
+12) = SC_ILLCDB
;
5574 pkt
->scsi_status
= S_CKCON
;
5575 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5576 (uint32_t)OF_NO_DATA
;
5580 if (*a64
+ len
> *end_a64
)
5581 len
= *end_a64
- *a64
;
5584 pkt
->scsi_status
= S_GOOD
;
5585 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5586 (uint32_t)OF_DATA_IN
;
5590 #ifdef QL_DEBUG_LEVEL_2
5591 qla1280_print("qla1280_atio_entry: SM_RDDB, zero length\n\r");
5593 pkt
->scsi_status
= S_GOOD
;
5594 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5595 (uint32_t)OF_NO_DATA
;
5600 #ifdef QL_DEBUG_LEVEL_3
5601 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_DESC\n\r");
5608 ha
->tbuf
->hdr
[0] = 0;
5609 if (pkt
->cdb
[2] != 0)
5611 ha
->tbuf
->hdr
[1] = 0;
5612 ha
->tbuf
->hdr
[2] = 0;
5613 ha
->tbuf
->hdr
[3] = 0;
5618 (uint8_t)(TARGET_DATA_SIZE
>> 16);
5620 (uint8_t)(TARGET_DATA_SIZE
>> 8);
5622 (uint8_t)TARGET_DATA_SIZE
;
5624 pkt
->scsi_status
= S_GOOD
;
5625 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5626 (uint32_t)OF_DATA_IN
;
5630 #ifdef QL_DEBUG_LEVEL_2
5631 qla1280_print("qla1280_atio_entry: SM_RDDB, zero length\n\r");
5633 pkt
->scsi_status
= S_GOOD
;
5634 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5635 (uint32_t)OF_NO_DATA
;
5639 #ifdef QL_DEBUG_LEVEL_2
5640 qla1280_print("qla1280_atio_entry: SM_RDDB unknown mode\n\r");
5643 *(sense_ptr
+2) = SD_ILLREQ
;
5644 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5645 *(sense_ptr
+12) = SC_ILLCDB
;
5647 pkt
->scsi_status
= S_CKCON
;
5648 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5649 (uint32_t)OF_NO_DATA
;
5654 #ifdef QL_DEBUG_LEVEL_2
5655 qla1280_print("qla1280_atio_entry: Unknown SCSI command\n\r");
5656 qla1280_dump_buffer((caddr_t
)&pkt
->cdb
[0], pkt
->cdb_len
);
5658 bzero(sense_ptr
, TARGET_SENSE_SIZE
);
5660 *(sense_ptr
+2) = SD_ILLREQ
;
5661 *(sense_ptr
+7) = TARGET_SENSE_SIZE
-8;
5662 *(sense_ptr
+12) = SC_INVOPCODE
;
5664 pkt
->scsi_status
= S_CKCON
;
5665 pkt
->option_flags
|= (uint32_t)OF_SSTS
|
5666 (uint32_t)OF_NO_DATA
;
5669 if (ha
->flags
.enable_64bit_addressing
)
5670 qla1280_64bit_continue_io(ha
, pkt
, len
, (paddr32_t
*)&phy_addr
);
5672 qla1280_32bit_continue_io(ha
, pkt
, len
, (paddr32_t
*)&phy_addr
);
5678 #ifdef QL_DEBUG_LEVEL_3
5679 qla1280_print("qla1280_atio_entry: exiting normally\n\r");
5684 * qla1280_notify_entry
5685 * Processes received ISP immediate notify entry.
5688 * ha = adapter block pointer.
5689 * pkt = entry pointer.
5692 qla1280_notify_entry(scsi_qla_host_t
*ha
, notify_entry_t
*pkt
)
5694 #ifdef QL_DEBUG_LEVEL_3
5695 qla1280_print("qla1280_notify_entry: entered\n\r");
5698 /* Acknowledge immediate notify */
5699 qla1280_notify_ack(ha
, pkt
);
5701 /* Issue notify entry to increment resource count */
5702 qla1280_immed_notify(ha
, pkt
);
5704 #ifdef QL_DEBUG_LEVEL_3
5705 qla1280_print("qla1280_notify_entry: exiting normally\n\r");
5709 #endif /* QLA1280_TARGET_MODE_SUPPORT */
5711 * qla1280_status_entry
5712 * Processes received ISP status entry.
5715 * ha = adapter block pointer.
5716 * pkt = entry pointer.
5717 * done_q_first = done queue first pointer.
5718 * done_q_last = done queue last pointer.
5721 qla1280_status_entry(scsi_qla_host_t
*ha
, sts_entry_t
*pkt
, srb_t
**done_q_first
,
5722 srb_t
**done_q_last
)
5725 uint8_t sense_sz
= 0;
5730 #ifdef QL_DEBUG_LEVEL_3
5731 ENTER("qla1280_status_entry");
5734 /* Validate handle. */
5735 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
5736 sp
= ha
->outstanding_cmds
[pkt
->handle
];
5742 /* Free outstanding command slot. */
5743 ha
->outstanding_cmds
[pkt
->handle
] = 0;
5746 /* Generate LU queue on cntrl, target, LUN */
5747 b
= SCSI_BUS_32(cp
);
5748 t
= SCSI_TCN_32(cp
);
5749 l
= SCSI_LUN_32(cp
);
5750 q
= LU_Q(ha
, b
, t
, l
);
5751 if( pkt
->comp_status
|| pkt
->scsi_status
)
5753 DEBUG(qla1280_print( "scsi: comp_status = ");)
5754 DEBUG(qla1280_output_number((uint32_t)pkt
->comp_status
,16);)
5755 DEBUG(qla1280_print( ", ");)
5756 DEBUG(qla1280_print( " scsi_status = ");)
5757 DEBUG(qla1280_output_number((uint32_t)pkt
->scsi_status
,16);)
5758 DEBUG(qla1280_print( "\n\r");)
5759 DEBUG(qla1280_print(", handle = ");)
5760 DEBUG(qla1280_output_number((uint32_t)pkt
->handle
, 16);)
5761 DEBUG(qla1280_print("\n\r");)
5765 if ( pkt
->scsi_status
& SS_BUSY_CONDITION
&&
5766 pkt
->scsi_status
!= SS_RESERVE_CONFLICT
)
5768 CMD_RESULT(cp
) = (int) (DID_BUS_BUSY
<< 16) |
5769 (pkt
->scsi_status
& 0xff);
5774 /* Save ISP completion status */
5775 CMD_RESULT(cp
) = qla1280_return_status( pkt
, cp
);
5777 if (pkt
->scsi_status
& SS_CHECK_CONDITION
)
5779 BZERO(cp
->sense_buffer
, CMD_SNSLEN(cp
));
5780 if (pkt
->comp_status
!= CS_ARS_FAILED
)
5782 if ( pkt
->req_sense_length
< CMD_SNSLEN(cp
) )
5783 sense_sz
= pkt
->req_sense_length
;
5785 sense_sz
= CMD_SNSLEN(cp
) - 1;
5787 BCOPY((caddr_t
)&pkt
->req_sense_data
, cp
->sense_buffer
, sense_sz
);
5790 #ifdef QL_DEBUG_LEVEL_2
5791 DEBUG(qla1280_print(
5792 "qla1280_status_entry: Check condition Sense data, b");)
5793 DEBUG(qla1280_output_number((uint32_t)b
, 10);)
5794 DEBUG(qla1280_print("t");)
5795 DEBUG(qla1280_output_number((uint32_t)t
, 10);)
5796 DEBUG(qla1280_print("d");)
5797 DEBUG(qla1280_output_number((uint32_t)l
, 10);)
5798 DEBUG(qla1280_print("\n\r");)
5799 DEBUG(if (sense_sz
))
5800 DEBUG(qla1280_dump_buffer(cp
->sense_buffer
, sense_sz
);)
5804 /* Place command on done queue. */
5805 qla1280_done_q_put(sp
, done_q_first
, done_q_last
);
5809 #ifdef QL_DEBUG_LEVEL_2
5810 qla1280_print("qla1280_status_entry: ISP Invalid handle\n\r");
5812 printk(KERN_WARNING
"qla1280: Status Entry invalid handle\n");
5813 ha
->flags
.isp_abort_needed
= TRUE
;
5815 #ifdef QL_DEBUG_LEVEL_3
5816 LEAVE("qla1280_status_entry");
5821 * qla1280_error_entry
5822 * Processes error entry.
5825 * ha = adapter block pointer.
5826 * pkt = entry pointer.
5827 * done_q_first = done queue first pointer.
5828 * done_q_last = done queue last pointer.
5831 qla1280_error_entry(scsi_qla_host_t
*ha
, response_t
*pkt
, srb_t
**done_q_first
,
5832 srb_t
**done_q_last
)
5836 #ifdef QL_DEBUG_LEVEL_3
5837 ENTER("qla1280_error_entry");
5840 #ifdef QL_DEBUG_LEVEL_2
5841 if (pkt
->entry_status
& BIT_3
)
5842 qla1280_print("qla1280_error_entry: BAD PAYLOAD flag error\n\r");
5843 else if (pkt
->entry_status
& BIT_2
)
5844 qla1280_print("qla1280_error_entry: BAD HEADER flag error\n\r");
5845 else if (pkt
->entry_status
& BIT_1
)
5846 qla1280_print("qla1280_error_entry: FULL flag error\n\r");
5848 qla1280_print("qla1280_error_entry: UNKNOWN flag error\n\r");
5851 /* Validate handle. */
5852 if (pkt
->handle
< MAX_OUTSTANDING_COMMANDS
)
5853 sp
= ha
->outstanding_cmds
[pkt
->handle
];
5859 /* Free outstanding command slot. */
5860 ha
->outstanding_cmds
[pkt
->handle
] = 0;
5862 /* Bad payload or header */
5863 if (pkt
->entry_status
& (BIT_3
+ BIT_2
))
5865 /* Bad payload or header, set error status. */
5866 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
5867 CMD_RESULT(sp
->cmd
) = (int) DID_ERROR
<< 16;
5869 else if (pkt
->entry_status
& BIT_1
) /* FULL flag */
5871 CMD_RESULT(sp
->cmd
) = (int) DID_BUS_BUSY
<< 16;
5875 /* Set error status. */
5876 CMD_RESULT(sp
->cmd
) =(int) DID_ERROR
<< 16;
5878 /* Place command on done queue. */
5879 qla1280_done_q_put(sp
, done_q_first
, done_q_last
);
5881 #if QLA1280_64BIT_SUPPORT
5882 else if (pkt
->entry_type
== COMMAND_A64_TYPE
)
5884 #ifdef QL_DEBUG_LEVEL_2
5885 qla1280_print("qla1280_error_entry: ISP Invalid handle\n\r");
5887 printk(KERN_WARNING
"!qla1280: Error Entry invalid handle");
5888 ha
->flags
.isp_abort_needed
= TRUE
;
5892 #ifdef QL_DEBUG_LEVEL_3
5893 LEAVE("qla1280_error_entry");
5899 * Resets ISP and aborts all outstanding commands.
5902 * ha = adapter block pointer.
5908 qla1280_abort_isp(scsi_qla_host_t
*ha
)
5910 device_reg_t
*reg
= ha
->iobase
;
5916 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
5917 unsigned long cpu_flags
= 0;
5920 #ifdef QL_DEBUG_LEVEL_3
5921 ENTER("qla1280_abort_isp");
5925 ha
->flags
.isp_abort_needed
= FALSE
;
5926 if (!ha
->flags
.abort_isp_active
&& ha
->flags
.online
)
5928 ha
->flags
.abort_isp_active
= TRUE
;
5930 /* Disable ISP interrupts. */
5931 WRT_REG_WORD(®
->ictrl
, 0);
5933 /* Dequeue all commands in outstanding command list. */
5934 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
5936 sp
= ha
->outstanding_cmds
[cnt
];
5939 ha
->outstanding_cmds
[cnt
] = 0;
5941 /* Generate LU queue on controller, target, LUN */
5942 b
= SCSI_BUS_32(sp
->cmd
);
5943 t
= SCSI_TCN_32(sp
->cmd
);
5944 l
= SCSI_LUN_32(sp
->cmd
);
5946 q
= (scsi_lu_t
*)LU_Q(ha
, b
, t
, l
);
5948 /* Reset outstanding command count. */
5950 q
->q_flag
&= ~QLA1280_QBUSY
;
5953 /* Adjust watchdog timer for command. */
5954 /* if (sp->flags & SRB_WATCHDOG)
5955 sp->timeout += 2; */
5957 /* Place request back on top of device queue. */
5958 /* sp->flags &= ~(SRB_SENT | SRB_TIMEOUT); */
5960 qla1280_putq_t(q
, sp
);
5964 /* If firmware needs to be loaded */
5965 if (qla1280_isp_firmware(ha
))
5967 if (!(status
= qla1280_chip_diag(ha
)))
5968 status
= qla1280_setup_chip(ha
);
5973 /* Setup adapter based on NVRAM parameters. */
5974 qla1280_nvram_config(ha
);
5976 if (!(status
= qla1280_init_rings(ha
)))
5978 /* Issue SCSI reset. */
5979 for (b
= 0; b
< ha
->ports
; b
++)
5981 qla1280_bus_reset(ha
, b
);
5985 /* Issue marker command. */
5986 ha
->flags
.reset_marker
= FALSE
;
5987 for (b
= 0; b
< ha
->ports
; b
++)
5989 ha
->bus_settings
[b
].reset_marker
= FALSE
;
5990 qla1280_marker(ha
, b
, 0, 0, MK_SYNC_ALL
);
5992 }while (ha
->flags
.reset_marker
);
5994 /* Enable host adapter target mode. */
5995 for (b
= 0; b
< ha
->ports
; b
++)
5997 if (!(status
= qla1280_enable_tgt(ha
, b
)))
5999 for (cnt
= 0; cnt
< MAX_LUNS
; cnt
++)
6001 /* qla1280_enable_lun(ha, b, cnt); */
6011 /* Enable ISP interrupts. */
6012 WRT_REG_WORD(®
->ictrl
, ISP_EN_INT
+ ISP_EN_RISC
);
6013 ha
->flags
.abort_isp_active
= FALSE
;
6014 /* Restart queues that may have been stopped. */
6015 qla1280_restart_queues(ha
);
6024 "qla1280: ISP error recovery failed, board disabled");
6025 qla1280_reset_adapter(ha
);
6026 qla1280_abort_queues(ha
);
6028 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
6029 qla1280_print("qla1280_abort_isp: **** FAILED ****\n\r");
6032 #ifdef QL_DEBUG_LEVEL_3
6034 LEAVE("qla1280_abort_isp");
6042 * qla1280_restart_queues
6043 * Restart all device queues.
6046 * ha = adapter block pointer.
6049 qla1280_restart_queues(scsi_qla_host_t
*ha
)
6054 #ifdef QL_DEBUG_LEVEL_3
6055 ENTER("qla1280_restart_queues");
6058 for (b
= 0; b
< ha
->ports
; b
++)
6059 for (t
= 0; t
< MAX_TARGETS
; t
++)
6060 for (l
= 0; l
< MAX_LUNS
; l
++)
6062 q
= (scsi_lu_t
*) LU_Q(ha
, b
, t
, l
);
6065 /* Acquire LU queue specific lock */
6066 QLA1280_SCSILU_LOCK(q
);
6069 qla1280_next(ha
, q
, b
);
6071 /* Release LU queue specific lock */
6072 QLA1280_SCSILU_UNLOCK(q
);
6075 #ifdef QL_DEBUG_LEVEL_3
6076 qla1280_print("qla1280_restart_queues: exiting normally\n");
6081 * qla1280_abort_queue_single
6082 * Abort all commands on a device queues.
6085 * ha = adapter block pointer.
6087 STATIC
void qla1280_abort_queue_single(scsi_qla_host_t
*ha
,uint32_t b
,uint32_t t
,uint32_t l
,uint32_t stat
)
6090 srb_t
*sp
, *sp_next
;
6092 ENTER("qla1280_abort_queue_single");
6093 q
= (scsi_lu_t
* )LU_Q(ha
, b
, t
, l
);
6096 /* Acquire LU queue specific lock */
6097 QLA1280_SCSILU_LOCK(q
);
6100 q
->q_first
= q
->q_last
= NULL
;
6102 QLA1280_SCSILU_UNLOCK(q
);
6106 sp_next
= sp
->s_next
;
6107 CMD_RESULT(sp
->cmd
) = stat
;
6108 qla1280_done_q_put(sp
, (srb_t
**)&ha
->done_q_first
, (srb_t
**)&ha
->done_q_last
);
6112 LEAVE("qla1280_abort_queue_single");
6116 * qla1280_abort_queues
6117 * Abort all commands on device queues.
6120 * ha = adapter block pointer.
6123 qla1280_abort_queues(scsi_qla_host_t
*ha
)
6127 ENTER("qla1280_abort_queues");
6129 for (b
= 0; b
< ha
->ports
; b
++)
6130 for (t
= 0; t
< MAX_TARGETS
; t
++)
6131 for (l
= 0; l
< MAX_LUNS
; l
++)
6132 qla1280_abort_queue_single(ha
,b
,t
,l
,DID_RESET
);
6134 LEAVE("qla1280_abort_queues");
6138 * qla1280_debounce_register
6139 * Debounce register.
6142 * port = register address.
6148 qla1280_debounce_register(volatile uint16_t *addr
)
6150 volatile uint16_t ret
;
6151 volatile uint16_t ret2
;
6155 ret
= RD_REG_WORD(addr
);
6156 ret2
= RD_REG_WORD(addr
);
6157 }while (ret
!= ret2
);
6164 * Declarations for load module
6167 Scsi_Host_Template driver_template
= QLA1280_LINUX_TEMPLATE
;
6169 #include "scsi_module.c"
6172 /************************************************************************
6173 * qla1280_check_for_dead_scsi_bus *
6175 * This routine checks for a dead SCSI bus *
6176 ************************************************************************/
6177 #define SET_SXP_BANK 0x0100
6178 #define SCSI_PHASE_INVALID 0x87FF
6179 int qla1280_check_for_dead_scsi_bus(scsi_qla_host_t
*ha
, srb_t
*sp
)
6181 uint16_t config_reg
, scsi_control
;
6182 device_reg_t
*reg
= ha
->iobase
;
6187 * If SCSI Bus is Dead because of bad termination,
6188 * we will return a status of Selection timeout.
6192 b
= SCSI_BUS_32(cp
);
6193 if (ha
->bus_settings
[b
].scsi_bus_dead
)
6195 WRT_REG_WORD(®
->host_cmd
, HC_PAUSE_RISC
);
6196 config_reg
= RD_REG_WORD(®
->cfg_1
);
6197 WRT_REG_WORD(®
->cfg_1
,SET_SXP_BANK
);
6198 scsi_control
= RD_REG_WORD(®
->scsiControlPins
);
6199 WRT_REG_WORD(®
->cfg_1
,config_reg
);
6200 WRT_REG_WORD(®
->host_cmd
, HC_RELEASE_RISC
);
6202 if (scsi_control
== SCSI_PHASE_INVALID
)
6204 CMD_RESULT(cp
) = DID_NO_CONNECT
<< 16;
6205 CMD_HANDLE(cp
) = (unsigned char *) 0;
6206 /* ha->actthreads--; */
6207 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
6209 (*(cp
)->scsi_done
)(cp
);
6212 (*(cp
)->scsi_done
)(cp
);
6214 return(TRUE
); /* bus is dead */
6218 ha
->bus_settings
[b
].scsi_bus_dead
= FALSE
;
6219 ha
->bus_settings
[b
].failed_reset_count
= 0;
6222 return(FALSE
); /* bus is not dead */
6226 qla12160_set_target_parameters(scsi_qla_host_t
*ha
, uint32_t b
, uint32_t t
, uint32_t l
, nvram160_t
*nv
)
6228 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
6230 /* Set Target Parameters. */
6231 mb
[0] = MBC_SET_TARGET_PARAMETERS
;
6232 mb
[1] = (uint16_t)(b
? t
| BIT_7
:t
);
6234 mb
[2] = nv
->bus
[b
].target
[t
].parameter
.c
<< 8;
6235 mb
[2] |= TP_AUTO_REQUEST_SENSE
;
6236 mb
[2] &= ~TP_STOP_QUEUE
;
6237 mb
[2] |= (nv
->bus
[b
].target
[t
].flags
.enable_ppr
<< 5);
6238 mb
[3] = nv
->bus
[b
].target
[t
].flags
.sync_offset
<< 8;
6239 mb
[3] |= nv
->bus
[b
].target
[t
].sync_period
;
6241 mb
[6] = nv
->bus
[b
].target
[t
].flags
.ppr_options
<< 8;
6242 mb
[6] |= nv
->bus
[b
].target
[t
].flags
.ppr_bus_width
;
6243 return( qla1280_mailbox_command(ha
, BIT_6
|BIT_3
|BIT_2
|BIT_1
|BIT_0
, &mb
[0]) ) ;
6247 qla12160_get_target_parameters(scsi_qla_host_t
*ha
, uint32_t b
, uint32_t t
, uint32_t l
)
6249 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
6251 mb
[0] = MBC_GET_TARGET_PARAMETERS
;
6252 mb
[1] = (uint16_t)(b
? t
| BIT_7
:t
);
6254 qla1280_mailbox_command(ha
, BIT_6
|BIT_3
|BIT_2
|BIT_1
|BIT_0
, &mb
[0]);
6256 printk(KERN_INFO
"scsi(%d:%d:%d:%d): Synchronous tranfer at period %d, offset %d. \n",
6257 (int)ha
->host_no
, b
, t
, l
, (mb
[3] &0xff), (mb
[3] >> 8));
6259 if ( (mb
[2] & BIT_5
) && ((mb
[6] >> 8) & 0xff) >= 2 )
6260 printk(KERN_INFO
"scsi(%d:%d:%d:%d): Dual Transition enabled.\n",
6261 (int)ha
->host_no
, b
, t
, l
);
6265 #ifdef QL_DEBUG_ROUTINES
6266 /****************************************************************************/
6267 /* Driver Debug Functions. */
6268 /****************************************************************************/
6271 * Get byte from I/O port
6274 qla1280_getbyte(uint8_t *port
)
6278 #if MEMORY_MAPPED_IO
6281 ret
= inb((int)port
);
6286 qla1280_print("qla1280_getbyte: address = ");
6287 qla1280_output_number((uint32_t)port
, 16);
6288 qla1280_print(" data = 0x");
6289 qla1280_output_number((uint32_t)ret
, 16);
6290 qla1280_print("\n\r");
6297 * Get word from I/O port
6300 qla1280_getword(uint16_t *port
)
6304 #if MEMORY_MAPPED_IO
6307 ret
= inw((int)port
);
6312 qla1280_print("qla1280_getword: address = ");
6313 qla1280_output_number((uint32_t)port
, 16);
6314 qla1280_print(" data = 0x");
6315 qla1280_output_number((uint32_t)ret
, 16);
6316 qla1280_print("\n\r");
6323 * Get double word from I/O port
6326 qla1280_getdword(uint32_t *port
)
6330 #if MEMORY_MAPPED_IO
6333 ret
= inl((int)port
);
6338 qla1280_print("qla1280_getdword: address = ");
6339 qla1280_output_number((uint32_t)port
, 16);
6340 qla1280_print(" data = 0x");
6341 qla1280_output_number((uint32_t)ret
, 16);
6342 qla1280_print("\n\r");
6349 * Send byte to I/O port
6352 qla1280_putbyte(uint8_t *port
, uint8_t data
)
6354 #if MEMORY_MAPPED_IO
6357 outb(data
, (int)port
);
6362 qla1280_print("qla1280_putbyte: address = ");
6363 qla1280_output_number((uint32_t)port
, 16);
6364 qla1280_print(" data = 0x");
6365 qla1280_output_number((uint32_t)data
, 16);
6366 qla1280_print("\n\r");
6371 * Send word to I/O port
6374 qla1280_putword(uint16_t *port
, uint16_t data
)
6376 #if MEMORY_MAPPED_IO
6379 #ifdef _LINUX_IOPORTS
6380 outw(data
, (int)port
);
6382 outw((int)port
, data
);
6388 qla1280_print("qla1280_putword: address = ");
6389 qla1280_output_number((uint32_t)port
, 16);
6390 qla1280_print(" data = 0x");
6391 qla1280_output_number((uint32_t)data
, 16);
6392 qla1280_print("\n\r");
6397 * Send double word to I/O port
6400 qla1280_putdword(uint32_t *port
, uint32_t data
)
6402 #if MEMORY_MAPPED_IO
6405 #ifdef _LINUX_IOPORTS
6406 outl(data
,(int)port
);
6408 outl((int)port
, data
);
6414 qla1280_print("qla1280_putdword: address = ");
6415 qla1280_output_number((uint32_t)port
, 16);
6416 qla1280_print(" data = 0x");
6417 qla1280_output_number((uint32_t)data
, 16);
6418 qla1280_print("\n\r");
6423 * Dummy function to prevent warnings for
6424 * declared and unused debug functions
6431 qla1280_getdword(0);
6432 qla1280_putbyte(0, 0);
6433 qla1280_putword(0, 0);
6434 qla1280_putdword(0, 0);
6438 * Out character to COM2 port.
6439 * PORT must be at standard address for COM2 = 0x2F8,
6442 #define OUTB(addr,data) outb((data),(addr))
6445 qla1280_putc(uint8_t c
)
6447 #ifdef QL_DEBUG_CONSOLE
6450 int com_addr
= 0x2f8;
6451 int hardware_flow_control
= 1;
6452 int software_flow_control
= 0;
6455 /* Wait for transmitter holding and shift registers for empty. */
6458 data
= inb(com_addr
+5);
6459 }while (!(data
& BIT_6
));
6462 * Set BAUD rate for COM2 to 19200 (0x6)
6465 /* Select rate divisor. */
6466 OUTB(com_addr
+3, 0x83);
6468 /* BAUD rate divisor LSB. */
6469 OUTB(com_addr
, 0xc); /* 0xC = 9600 baud */
6471 /* BAUD rate divisor MSB. */
6472 OUTB(com_addr
+1, 0);
6474 /* Set No parity, 8 bits, 1 stop bit and
6475 select interrupt enable register. */
6476 OUTB(com_addr
+3, 3);
6478 /* Disable interrupts. */
6479 OUTB(com_addr
+1, 0);
6481 /* Set data terminal ready and request to send */
6484 if (hardware_flow_control
)
6486 /* Wait for clear-to-send and data-set-ready */
6489 data
= inb(com_addr
+6) & (BIT_5
+ BIT_4
);
6490 }while (data
!= (BIT_5
+ BIT_4
));
6492 else if (software_flow_control
)
6494 /* Test for data ready. */
6495 data
= inb(com_addr
+5);
6499 data
= inb(com_addr
);
6508 data
= inb(com_addr
+5);
6509 }while (!(data
& BIT_0
));
6510 data
= inb(com_addr
);
6511 }while (data
!= '\021');
6516 /* Output character. */
6522 * Out NULL terminated string to COM port.
6525 qla1280_print(caddr_t s
)
6529 #ifdef QL_DEBUG_CONSOLE
6532 /* Output string. */
6540 * Output long number to COM port.
6543 qla1280_output_number(uint32_t n
, uint8_t base
)
6546 int8_t *s
= &str
[11];
6552 if (base
== 10 || base
== 16)
6554 if (base
== 16 && n
> 9)
6586 qla1280_dump_buffer(caddr_t b
, uint32_t size
)
6594 " 0 1 2 3 4 5 6 7 8 9 Ah Bh Ch Dh Eh Fh\n\r");
6596 "---------------------------------------------------------------\n\r");
6598 for (cnt
= 0; cnt
< size
; )
6603 qla1280_output_number((uint32_t)c
, 16);
6606 qla1280_print("\n\r");
6613 qla1280_print("\n\r");
6616 /**************************************************************************
6617 * ql1280_print_scsi_cmd
6619 **************************************************************************/
6620 void qla1280_print_scsi_cmd(Scsi_Cmnd
*cmd
)
6622 scsi_qla_host_t
*ha
;
6623 struct Scsi_Host
*host
= cmd
->host
;
6625 /* struct scatterlist *sg; */
6628 ha
= (scsi_qla_host_t
*) host
->hostdata
;
6631 sp
= (srb_t
*) CMD_SP(cmd
);
6632 sprintf(debug_buff
,"SCSI Command @= 0x%p, Handle=0x%p\n\r", cmd
, CMD_HANDLE(cmd
));
6633 qla1280_print(debug_buff
);
6634 sprintf(debug_buff
," chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n\r",
6635 cmd
->channel
, cmd
->target
, cmd
->lun
, cmd
->cmd_len
);
6636 qla1280_print(debug_buff
);
6637 qla1280_print(" CDB = ");
6638 for (i
= 0; i
< cmd
->cmd_len
; i
++)
6640 sprintf(debug_buff
,"0x%02x ", cmd
->cmnd
[i
]);
6641 qla1280_print(debug_buff
);
6643 sprintf(debug_buff
," seg_cnt =%d\n\r",cmd
->use_sg
);
6644 qla1280_print(debug_buff
);
6645 sprintf(debug_buff
," request buffer=0x%p, request buffer len=0x%x\n\r",cmd
->request_buffer
,cmd
->request_bufflen
);
6646 qla1280_print(debug_buff
);
6647 /* if( cmd->use_sg )
6649 sg = (struct scatterlist *) cmd->request_buffer;
6650 qla1280_print(" SG buffer: \n\r");
6651 qla1280_dump_buffer((caddr_t)sg, (cmd->use_sg*sizeof(struct scatterlist)) );
6653 sprintf(debug_buff
," tag=%d, flags=0x%x, transfersize=0x%x \n\r",
6654 cmd
->tag
, cmd
->flags
,cmd
->transfersize
);
6655 qla1280_print(debug_buff
);
6656 sprintf(debug_buff
," Pid=%d, SP=0x%p\n\r", (int)cmd
->pid
, CMD_SP(cmd
));
6657 qla1280_print(debug_buff
);
6658 sprintf(debug_buff
," r_start=0x%lx, u_start=0x%lx\n\r",sp
->r_start
,sp
->u_start
);
6659 qla1280_print(debug_buff
);
6660 sprintf(debug_buff
," underflow size = 0x%x, direction=0x%x, req.cmd=0x%x \n\r", cmd
->underflow
, sp
->dir
,cmd
->request
.cmd
);
6661 qla1280_print(debug_buff
);
6663 /**************************************************************************
6664 * ql1280_dump_device
6666 **************************************************************************/
6668 ql1280_dump_device(scsi_qla_host_t
*ha
)
6674 qla1280_print("Outstanding Commands on controller:\n\r");
6675 for ( i
=0; i
< MAX_OUTSTANDING_COMMANDS
; i
++ )
6677 if( (sp
= ha
->outstanding_cmds
[i
]) == NULL
)
6679 if( (cp
= sp
->cmd
) == NULL
)
6681 qla1280_print_scsi_cmd(cp
);
6687 #ifdef QLA1280_UNUSED
6688 /**************************************************************************
6691 **************************************************************************/
6692 static void qla1280_dump_regs(struct Scsi_Host
*host
)
6694 printk("Mailbox registers:\n");
6695 printk("qla1280 : mbox 0 0x%04x \n", inw(host
->io_port
+ 0x70));
6696 printk("qla1280 : mbox 1 0x%04x \n", inw(host
->io_port
+ 0x72));
6697 printk("qla1280 : mbox 2 0x%04x \n", inw(host
->io_port
+ 0x74));
6698 printk("qla1280 : mbox 3 0x%04x \n", inw(host
->io_port
+ 0x76));
6699 printk("qla1280 : mbox 4 0x%04x \n", inw(host
->io_port
+ 0x78));
6700 printk("qla1280 : mbox 5 0x%04x \n", inw(host
->io_port
+ 0x7a));
6707 /**************************************************************************
6710 **************************************************************************/
6711 static void qla1280_panic(char *cp
, struct Scsi_Host
*host
)
6713 scsi_qla_host_t
*ha
;
6716 ha
= (scsi_qla_host_t
*) host
->hostdata
;
6717 printk("qla1280 - PANIC: %s\n",cp
);
6718 printk("Current time=0x%lx\n", jiffies
);
6719 printk("Number of pending commands =0x%lx\n", ha
->actthreads
);
6720 printk("Number of SCSI queued commands =0x%lx\n", ha
->qthreads
);
6721 printk("Number of free entries = (%d)\n",ha
->req_q_cnt
);
6722 printk("Request Queue @ 0x%lx, Response Queue @ 0x%lx\n",
6725 printk("Request In Ptr %d\n", ha
->req_ring_index
);
6726 fp
= (long *) &ha
->flags
;
6727 printk("HA flags =0x%lx\n", *fp
);
6728 DEBUG2(ql_debug_print
= 1;)
6729 /* DEBUG2(ql1280_dump_device((scsi_qla_host_t *) host->hostdata)); */
6730 #ifdef QLA1280_UNUSED
6731 qla1280_dump_regs(host
);
6745 #ifdef QLA1280_UNUSED
6746 static void qla1280_set_flags(char * s
)
6751 /**************************************************************************
6754 * Handle Linux boot parameters. This routine allows for assigning a value
6755 * to a parameter with a ':' between the parameter and the value.
6756 * ie. qla1280=max_reqs:0x0A,verbose
6757 **************************************************************************/
6759 qla1280_setup(char *s
, int *dummy
)
6761 char *end
, *str
, *cp
;
6763 #ifdef QLA1280_UNUSED
6772 { "dump_regs", 9, &qla1280_dump_regs
, 0
6774 { "verbose", 7, &qla1280_set_flags
, 0x1
6781 printk("scsi: Processing Option str = %s\n", s
);
6782 end
= strchr(s
, '\0');
6783 /* locate command */
6785 for( cp
= s
; *cp
&& cp
!= end
; cp
++ )
6787 cp
= qla1280_get_token(cp
, str
);
6788 printk("scsi: token str = %s\n", str
);
6789 /* if found execute routine */
6795 static char *qla1280_get_token(char *cmdline
, char *str
)
6797 register char *cp
= cmdline
;
6799 /* skip preceeding spaces */
6800 while(strchr(cp
,' '))
6802 /* symbol starts here */
6804 /* skip char if not a space or : */
6805 while (*cp
&& !( strchr(cp
,' ') || strchr(cp
,':')) )
6812 * Overrides for Emacs so that we almost follow Linus's tabbing style.
6813 * Emacs will notice this stuff at the end of the file and automatically
6814 * adjust the settings for this buffer only. This must remain at the end
6816 * ---------------------------------------------------------------------------
6819 * c-brace-imaginary-offset: 0
6820 * c-brace-offset: -2
6821 * c-argdecl-indent: 2
6822 * c-label-offset: -2
6823 * c-continued-statement-offset: 2
6824 * c-continued-brace-offset: 0
6825 * indent-tabs-mode: nil