- pre4:
[davej-history.git] / drivers / scsi / qla1280.c
blobf3d059df88f2f871748840cab2ff6f14263e2a00
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
16 * are met:
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
30 AND MODIFICATION
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
40 with the Software.
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;
85 or,
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
127 Software at all.
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.
132 NO WARRANTY
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 /****************************************************************************
158 Revision History:
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
178 the adapter.
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 *****************************************************************************/
186 #ifdef MODULE
187 #include <linux/module.h>
188 #endif
190 #define QLA1280_VERSION " 3.00-Beta"
192 #include <stdarg.h>
193 #include <asm/io.h>
194 #include <asm/irq.h>
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>
213 #endif
214 #include "sd.h"
215 #include "scsi.h"
216 #include "hosts.h"
217 #define UNIQUE_FW_NAME
218 #include "qla1280.h"
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))
228 #endif
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)
268 #else
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))
271 #endif
272 #endif /* QLA1280_64BIT_SUPPORT */
274 #define STATIC
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)
290 #else
291 #define LS_64BITS(x) (uint32_t)(0xffffffff & (x))
292 #define MS_64BITS(x) (uint32_t)(0xffffffff & ((x)>>32) )
293 #endif
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);
305 #endif
306 #if STOP_ON_ERROR
307 static void qla1280_panic(char *, struct Scsi_Host *host);
308 #endif
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);
318 #endif
319 static char *qla1280_get_token(char *, char *);
320 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
321 STATIC inline void mdelay(int);
322 #endif
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 *),
344 #endif
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 **,
356 srb_t **),
357 qla1280_error_entry(scsi_qla_host_t *, response_t *, srb_t **,
358 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,
379 paddr32_t *),
380 #endif
381 qla1280_32bit_continue_io(scsi_qla_host_t *, atio_entry_t *, uint32_t,
382 paddr32_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);
402 char debug_buff[80];
403 #if DEBUG_QLA1280
404 STATIC uint8_t ql_debug_print = 1;
405 #else
406 STATIC uint8_t ql_debug_print = 0;
407 #endif
408 #endif
411 * insmod needs to find the variable and make it point to something
413 #ifdef MODULE
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");
419 #endif
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";
427 #endif
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 */
472 } qla_boards_t;
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] },
487 {" ", 0, 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;
495 #endif
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);
506 #define DEBUG3(x) x
507 #else
508 #define ENTER(x)
509 #define LEAVE(x)
510 #define ENTER_INTR(x)
511 #define LEAVE_INTR(x)
512 #define DEBUG3(x)
513 #endif
515 #if DEBUG_QLA1280
516 #define COMTRACE(x)
517 /* #define COMTRACE(x) qla1280_putc(x); */
518 #define DEBUG(x) x
519 #else
520 #define DEBUG(x)
521 #define COMTRACE(x)
522 #endif
524 #ifdef QL_DEBUG_LEVEL_2
525 #define DEBUG2(x) x
526 #else
527 #define DEBUG2(x)
528 #endif
529 #define DEBUG5(x)
531 #if (BITS_PER_LONG==64)
532 # define OFFSET(w) (((uint64_t) &w) & 0xFF) /* 256 byte offsets */
533 #else
534 # define OFFSET(w) (((uint32_t) &w) & 0xFF) /* 256 byte offsets */
535 #endif
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 /*************************************************************************
547 * qla1280_set_info
549 * Description:
550 * Set parameters for the driver from the /proc filesystem.
552 * Returns:
553 *************************************************************************/
555 qla1280_set_info(char *buffer, int length, struct Scsi_Host *HBAptr)
557 return (-ENOSYS); /* Currently this is a no-op */
560 /*************************************************************************
561 * qla1280_proc_info
563 * Description:
564 * Return information to handle /proc support for the driver.
566 * buffer - ptrs to a page buffer
568 * Returns:
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
573 #endif
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;
580 scsi_qla_host_t *ha;
581 int size = 0;
582 int targ_lun;
583 scsi_lu_t *up;
584 int no_devices;
586 printk("Entering proc_info 0x%p,0x%lx,0x%x,0x%x\n",buffer,offset,length,hostno);
587 host = NULL;
588 /* find the host they want to look at */
589 for(ha=qla1280_hostlist; (ha != NULL) && ha->host->host_no != hostno; ha=ha->next)
592 if (!ha)
594 size += sprintf(buffer, "Can't find adapter for host number %d\n", hostno);
595 if (size > length)
597 return (size);
599 else
601 return (length);
605 host = ha->host;
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 */
612 no_devices = 0;
613 for (targ_lun = 0; targ_lun < MAX_EQ; targ_lun++)
615 if( (up = ha->dev[targ_lun]) == NULL )
616 continue;
617 no_devices++;
619 /* size = 112 * no_devices; */
620 size = 4096;
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",
640 __LINE__);
641 return size;
643 qla1280_buffer_size = size;
645 size = 0;
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",
656 ha->request_dma,
657 ha->response_dma);
658 size += sprintf(PROC_BUF, "Request Queue count= 0x%x, Response Queue count= 0x%x\n",
659 REQUEST_ENTRY_CNT,
660 RESPONSE_ENTRY_CNT);
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 )
671 continue;
672 if( up->io_cnt == 0 )
674 size += sprintf(PROC_BUF,"(%2d:%2d:%2d) No stats\n",LUN_ID);
675 continue;
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;
700 *start = NULL;
702 else
704 *start = &qla1280_buffer[offset]; /* Start of wanted data */
705 if (size - offset < length)
707 length = size - offset;
710 #endif
712 return (length);
716 /**************************************************************************
717 * qla1280_detect
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.
724 * Input:
725 * template - pointer to SCSI template
727 * Returns:
728 * num - number of host adapters found.
729 **************************************************************************/
731 qla1280_detect(Scsi_Host_Template *template)
733 int num_hosts = 0;
734 struct Scsi_Host *host;
735 scsi_qla_host_t *ha, *cur_ha;
736 struct _qlaboards *bdp;
737 int i, j;
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;
742 #endif
743 device_reg_t *reg;
744 char *cp;
745 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
746 struct pci_dev *pdev = NULL;
747 #else
748 int index;
749 #endif
751 ENTER("qla1280_detect");
753 #ifdef CHECKSRBSIZE
754 if (sizeof(srb_t) > sizeof(Scsi_Pointer) )
756 printk("Redefine SRB - its too big");
757 return 0;
759 #endif
761 #ifdef MODULE
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
768 * qla1280_setup
770 * Boot time Options
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.
776 if(options)
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 "
782 "module\n"
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");
785 #endif
787 if ((int) !pcibios_present())
789 printk("scsi: PCI not present\n");
790 return 0;
791 } /* end of IF */
792 bdp = &QLBoardTbl[0];
793 qla1280_hostlist = NULL;
794 #if 0
795 template->proc_dir = &proc_scsi_qla1280;
796 #else
797 template->proc_name = "qla1280";
798 #endif
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;
806 #else
807 while (!(pcibios_find_device(QLA1280_VENDOR_ID,
808 bdp->device_id,
809 index++, &pci_bus, &pci_devfn)) ) {
810 #endif
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++)
816 *cp = 0;
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;
823 ha->pdev = pdev;
824 #else
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);
827 host->irq = pci_irq;
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;
832 #endif
833 ha->device_id = bdp->device_id;
835 ha->devnum = i;
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;
842 ha->host = host;
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);
852 continue;
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);
862 continue;
866 reg = ha->iobase;
867 /* Disable ISP interrupts. */
868 qla1280_disable_intrs(ha);
870 /* Insure mailbox registers are free. */
871 WRT_REG_WORD(&reg->semaphore, 0);
872 WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
873 WRT_REG_WORD(&reg->host_cmd, HC_CLR_HOST_INT);
875 /* Enable chip interrupts. */
876 qla1280_enable_intrs(ha);
878 /* Insert new entry into the list of adapters */
879 ha->next = NULL;
880 if( qla1280_hostlist == NULL )
882 cur_ha = qla1280_hostlist = ha;
884 else
886 cur_ha = qla1280_hostlist;
887 while( cur_ha->next != NULL )
888 cur_ha = cur_ha->next;
889 cur_ha->next = ha;
891 num_hosts++;
892 } /* end of WHILE */
893 } /* end of FOR */
895 LEAVE("qla1280_detect");
896 return num_hosts;
899 /**************************************************************************
900 * qla1280_register_with_Linux
902 * Description:
903 * Free the passed in Scsi_Host memory structures prior to unloading the
904 * module.
906 * Input:
907 * ha - pointer to host adapter structure
908 * maxchannels - MAX number of channels.
910 * Returns:
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);
938 return 1;
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);
949 return 1;
952 request_region(host->io_port, 0xff, "qla1280");
954 return 0;
958 /**************************************************************************
959 * qla1280_release
960 * Free the passed in Scsi_Host memory structures prior to unloading the
961 * module.
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 )
971 return(0);
973 /* turn-off interrupts on the card */
974 WRT_REG_WORD(&ha->iobase->ictrl, 0);
976 /* Detach interrupts */
977 if(host->irq)
978 free_irq(host->irq, ha);
980 /* release io space registers */
981 if( host->io_port )
982 release_region(host->io_port, 0xff);
984 #if MEMORY_MAPPED_IO
985 if(ha->mmpbase)
987 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
988 vfree((void *) (((unsigned long) ha->mmpbase) & PAGE_MASK));
989 #else
990 iounmap((void *) (((unsigned long) ha->mmpbase) & PAGE_MASK));
991 #endif
993 #endif /* MEMORY_MAPPED_IO */
994 qla1280_mem_free(ha);
996 ENTER("qla1280_release");
997 return(0);
1000 /**************************************************************************
1001 * qla1280_info
1002 * Return a string describing the driver.
1003 **************************************************************************/
1004 const char *
1005 qla1280_info(struct Scsi_Host *host)
1007 static char qla1280_buffer[125];
1008 char *bp;
1009 scsi_qla_host_t *ha;
1010 qla_boards_t *bdp;
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));
1016 sprintf(bp,
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],
1021 QLA1280_VERSION);
1022 return(bp);
1025 /**************************************************************************
1026 * qla1200_queuecommand
1027 * Queue a command to the controller.
1029 * Note:
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;
1040 srb_t *sp;
1041 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1042 unsigned long cpu_flags = 0;
1043 #endif
1044 struct Scsi_Host *host;
1045 uint32_t b, t, l;
1046 scsi_lu_t *q;
1047 u_long handle;
1049 ENTER("qla1280_queuecommand");
1050 COMTRACE('C')
1052 host = cmd->host;
1053 ha = (scsi_qla_host_t *) host->hostdata;
1055 /* send command to adapter */
1056 sp = (srb_t *) CMD_SP(cmd);
1057 sp->cmd = cmd;
1058 cmd->scsi_done = fn;
1059 if (cmd->flags == 0) /* new command */
1061 sp->flags = 0;
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 )
1072 DRIVER_LOCK
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));
1079 DRIVER_UNLOCK
1081 else
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;
1087 DRIVER_UNLOCK
1088 return(0);
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 */
1098 sp->u_start = 0;
1100 /* add the command to our queue */
1101 ha->qthreads++;
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 */
1108 DRIVER_LOCK
1109 if (q->q_outcnt == 0)
1110 qla1280_restart_queues(ha);
1111 DRIVER_UNLOCK
1114 LEAVE("qla1280_queuecommand");
1115 return (0);
1118 /**************************************************************************
1119 * qla1200_abort
1120 * Abort the speciifed SCSI command(s).
1121 **************************************************************************/
1123 qla1280_abort(Scsi_Cmnd *cmd)
1125 scsi_qla_host_t *ha;
1126 srb_t *sp;
1127 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1128 unsigned long cpu_flags = 0;
1129 #endif
1130 struct Scsi_Host *host;
1131 uint32_t b, t, l;
1132 scsi_lu_t *q;
1133 int return_status = SCSI_ABORT_SUCCESS;
1134 int found = 0;
1135 int i;
1136 u_long handle;
1137 u_short data;
1139 ENTER("qla1280_abort");
1140 COMTRACE('A')
1141 ha = (scsi_qla_host_t *) cmd->host->hostdata;
1142 host = cmd->host;
1143 DRIVER_LOCK
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. */
1152 if( handle == 0L )
1154 COMTRACE('a')
1155 /* we never got this command */
1156 printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
1157 DRIVER_UNLOCK
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 )
1175 COMTRACE('a')
1176 /* No lun queue -- command must not be active */
1177 DRIVER_UNLOCK
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) )
1185 DRIVER_UNLOCK
1186 DEBUG(qla1280_print("qla1280_abort: Abort escalayted - returning SCSI_ABORT_SNOOZE.\n\r"));
1187 return(SCSI_ABORT_SNOOZE);
1189 #endif
1191 if ( (sp->flags & SRB_ABORT_PENDING) )
1193 COMTRACE('a')
1194 DRIVER_UNLOCK
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);
1201 #if STOP_ON_ABORT
1202 printk("Scsi layer issued a ABORT command= 0x%x\n",(int)cmd);
1203 DEBUG2(qla1280_print_scsi_cmd(cmd));
1204 #endif
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
1210 * LUN queue.
1212 if( !(sp->flags&SRB_SENT) )
1214 found++;
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;
1225 else
1226 { /* find the command in our active list */
1227 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++)
1229 if( sp == ha->outstanding_cmds[i] )
1231 found++;
1232 DEBUG(qla1280_print("qla1280: RISC aborting command.\n\r"));
1233 qla1280_abort_command(ha,sp);
1234 return_status = SCSI_ABORT_PENDING;
1235 break;
1240 #if STOP_ON_ABORT
1241 qla1280_panic("qla1280_abort",ha->host);
1242 #endif
1243 if ( found == 0 )
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);
1251 if ( found )
1253 qla1280_restart_queues(ha);
1255 ha->flags.in_abort = FALSE;
1256 DRIVER_UNLOCK
1258 LEAVE("qla1280_abort");
1259 COMTRACE('a')
1260 return(return_status);
1263 /**************************************************************************
1264 * qla1200_reset
1265 * The reset function will reset the SCSI bus and abort any executing
1266 * commands.
1268 * Input:
1269 * cmd = Linux SCSI command packet of the command that cause the
1270 * bus reset.
1271 * flags = SCSI bus reset option flags (see scsi.h)
1273 * Returns:
1274 * DID_RESET in cmd.host_byte of aborted command(s)
1276 * Note:
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;
1288 #endif
1289 uint32_t b, t, l;
1290 srb_t *sp;
1291 typedef enum
1293 ABORT_DEVICE = 1,
1294 DEVICE_RESET = 2,
1295 BUS_RESET = 3,
1296 ADAPTER_RESET= 4,
1297 RESET_DELAYED= 5,
1298 FAIL = 6
1299 } action_t;
1300 action_t action = ADAPTER_RESET;
1301 u_short data;
1302 scsi_lu_t *q;
1303 int result;
1306 ENTER("qla1280_reset");
1307 COMTRACE('R')
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);
1310 if ( cmd == NULL )
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);
1319 #if STOP_ON_RESET
1320 qla1280_panic("qla1280_reset",ha->host);
1321 #endif
1323 DRIVER_LOCK
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);
1330 DRIVER_UNLOCK
1333 * Determine the suggested action that the mid-level driver wants
1334 * us to perform.
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;
1345 else
1346 action = BUS_RESET;
1348 else
1349 { /*
1350 * Mid-level driver has called reset with this SCSI_Cmnd and
1351 * its pending.
1353 if( flags & SCSI_RESET_SUGGEST_HOST_RESET )
1354 action = ADAPTER_RESET;
1355 else if( flags & SCSI_RESET_SUGGEST_BUS_RESET )
1356 action = BUS_RESET;
1357 else
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);
1370 action = BUS_RESET;
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);
1376 action = BUS_RESET;
1378 #endif
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.
1384 DRIVER_LOCK
1385 result = SCSI_RESET_ERROR;
1386 switch (action)
1388 case FAIL:
1389 break;
1391 case RESET_DELAYED:
1392 result = SCSI_RESET_PENDING;
1393 break;
1395 case ABORT_DEVICE:
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;
1402 break;
1404 case DEVICE_RESET:
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;
1413 break;
1415 case BUS_RESET:
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; */
1438 break;
1440 case ADAPTER_RESET:
1441 default:
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;
1463 DRIVER_UNLOCK
1464 DEBUG(printk("RESET returning %d\n", result));
1466 COMTRACE('r')
1467 LEAVE("qla1280_reset");
1468 return( result );
1471 /**************************************************************************
1472 * qla1200_biosparam
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;
1480 heads = 64;
1481 sectors = 32;
1482 cylinders = disk->capacity / (heads * sectors);
1483 if (cylinders > 1024)
1485 heads = 255;
1486 sectors = 63;
1487 cylinders = disk->capacity / (heads * sectors);
1488 /* if (cylinders > 1023)
1489 cylinders = 1023; */
1492 geom[0] = heads;
1493 geom[1] = sectors;
1494 geom[2] = cylinders;
1496 return (0);
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;
1506 #endif
1507 scsi_qla_host_t *ha;
1508 u_short data;
1509 device_reg_t *reg;
1511 ENTER_INTR("qla1280_intr_handler");
1512 COMTRACE('I')
1513 ha = (scsi_qla_host_t *) dev_id;
1514 if(!ha)
1516 printk(KERN_INFO "scsi(): Interrupt with NULL host ptr\n");
1517 COMTRACE('X')
1518 return;
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))
1524 COMTRACE('X')
1525 return;
1527 ha->isr_count++;
1528 reg = ha->iobase;
1529 /* disable our interrupt. */
1530 WRT_REG_WORD(&reg->ictrl, 0);
1531 data = qla1280_debounce_register(&reg->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));
1537 COMTRACE('X')
1539 else
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) )
1550 COMTRACE('X')
1551 printk(KERN_INFO "scsi(%d): Already in interrupt - returning \n", (int)ha->host_no);
1552 return;
1554 set_bit(QLA1280_IN_ISR_BIT, (int *)&ha->flags);
1555 ha->isr_count++;
1556 reg = ha->iobase;
1557 /* disable our interrupt. */
1558 WRT_REG_WORD(&reg->ictrl, 0);
1560 data = qla1280_debounce_register(&reg->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));
1566 COMTRACE('X')
1568 else
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 ||
1577 ha->done_q_first )
1579 ha->run_qla_bh.data = (void *) ha;
1580 ha->run_qla_bh.routine = qla1280_do_dpc;
1582 COMTRACE('P')
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);
1587 #endif
1588 /* enable our interrupt. */
1589 WRT_REG_WORD(&reg->ictrl, ISP_EN_INT + ISP_EN_RISC);
1591 COMTRACE('i')
1592 LEAVE_INTR("qla1280_intr_handler");
1595 /**************************************************************************
1596 * qla1280_do_dpc
1598 * Description:
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
1605 * code .
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;
1612 #endif
1614 COMTRACE('p')
1615 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
1616 spin_lock_irqsave(&io_request_lock, cpu_flags);
1617 #endif
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);
1629 #endif
1632 /**************************************************************************
1633 * qla1280_device_queue_depth
1635 * Description:
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 **************************************************************************/
1673 STATIC void
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)
1694 * mdelay
1695 * Delay in milliseconds
1697 * Input:
1698 * milliseconds = delay
1700 STATIC inline void mdelay(int milliseconds)
1702 int i;
1704 for(i=0; i<milliseconds; i++)
1705 udelay(1000);
1707 #endif
1710 * qla1280_done
1711 * Process completed commands.
1713 * Input:
1714 * ha = adapter block pointer.
1715 * done_q_first = done queue first pointer.
1716 * done_q_last = done queue last pointer.
1718 STATIC void
1719 qla1280_done(scsi_qla_host_t *ha, srb_t **done_q_first, srb_t **done_q_last)
1721 srb_t *sp;
1722 scsi_lu_t *q;
1723 uint32_t b, t, l;
1724 Scsi_Cmnd *cmd;
1725 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1726 unsigned long cpu_flags = 0;
1727 #endif
1729 ENTER("qla1280_done");
1730 COMTRACE('D')
1732 DRIVER_LOCK
1733 while (*done_q_first != NULL)
1735 /* remove command from done list */
1736 sp = *done_q_first;
1737 if (!(*done_q_first = sp->s_next))
1738 *done_q_last = NULL;
1739 else
1740 (*done_q_first)->s_prev = NULL;
1741 cmd = sp->cmd;
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. */
1748 if (q->q_outcnt)
1749 q->q_outcnt--;
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;
1757 q->io_cnt++;
1758 if( sp->dir & BIT_5 )
1759 q->r_cnt++;
1760 else
1761 q->w_cnt++;
1763 switch ( (CMD_RESULT(cmd)>>16))
1765 case DID_RESET:
1766 q->q_flag &= ~QLA1280_QRESET;
1767 /* Issue marker command. */
1768 qla1280_marker(ha, b, t, 0, MK_SYNC_ID);
1769 break;
1770 case DID_ABORT:
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;
1775 break;
1776 default:
1777 break;
1780 /* Call the mid-level driver interrupt handler */
1781 CMD_HANDLE(sp->cmd) = (unsigned char *) 0;
1782 ha->actthreads--;
1783 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1784 sti();
1785 (*(cmd)->scsi_done)(cmd);
1786 cli();
1787 #else
1788 (*(cmd)->scsi_done)(cmd);
1789 #endif
1790 qla1280_next(ha, q, b);
1792 DRIVER_UNLOCK
1795 COMTRACE('d')
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[] =
1808 "DID_OK",
1809 "DID_NO_CONNECT",
1810 "DID_BUS_BUSY",
1811 "DID_TIME_OUT",
1812 "DID_BAD_TARGET",
1813 "DID_ABORT",
1814 "DID_PARITY",
1815 "DID_ERROR",
1816 "DID_RESET",
1817 "DID_BAD_INTR"
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));
1827 #endif
1828 switch(sts->comp_status)
1830 case CS_COMPLETE:
1831 host_status = DID_OK;
1832 break;
1833 case CS_INCOMPLETE:
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;
1846 break;
1847 case CS_RESET:
1848 host_status = DID_RESET;
1849 break;
1850 case CS_ABORTED:
1851 host_status = DID_ABORT;
1852 break;
1853 case CS_TIMEOUT:
1854 host_status = DID_TIME_OUT;
1855 break;
1856 case CS_DATA_OVERRUN:
1857 #ifdef QL_DEBUG_LEVEL_2
1858 printk("Data overrun 0x%x\n",(int)sts->residual_length);
1859 qla1280_print(
1860 "\n\rqla1280_isr: response packet data\n\r");
1861 qla1280_dump_buffer((caddr_t)sts,
1862 RESPONSE_ENTRY_SIZE);
1863 #endif
1864 host_status = DID_ERROR;
1865 break;
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;
1872 else
1873 host_status = DID_OK;
1874 break;
1875 default:
1876 host_status = DID_ERROR;
1877 break;
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);
1883 #endif
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.
1894 * Input:
1895 * sp = srb pointer.
1896 * done_q_first = done queue first pointer.
1897 * done_q_last = done queue last pointer.
1899 STATIC void
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;
1904 #endif
1905 #ifdef QL_DEBUG_LEVEL_3
1906 ENTER("qla1280_put_done_q");
1907 #endif
1908 /* Place block on done queue */
1909 DRIVER_LOCK
1910 sp->s_next = NULL;
1911 sp->s_prev = *done_q_last;
1912 if (!*done_q_first)
1913 *done_q_first = sp;
1914 else
1915 (*done_q_last)->s_next = sp;
1916 *done_q_last = sp;
1918 DRIVER_UNLOCK
1919 #ifdef QL_DEBUG_LEVEL_3
1920 LEAVE("qla1280_put_done_q");
1921 #endif
1925 * qla1280_next
1926 * Retrieve and process next job in the queue.
1928 * Input:
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.
1934 * Output:
1935 * Releases SCSI_LU_Q upon exit.
1937 STATIC void
1938 qla1280_next(scsi_qla_host_t *ha, scsi_lu_t *q, uint8_t b)
1940 srb_t *sp;
1941 uint32_t cnt;
1942 uint8_t status;
1943 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1944 unsigned long cpu_flags = 0;
1945 #endif
1947 ENTER("qla1280_next");
1949 DRIVER_LOCK
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. */
1962 q->q_outcnt++;
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);
1969 else
1970 #endif
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);
1986 else
1987 #endif
1988 status = qla1280_32bit_start_scsi(ha, sp);
1990 if (!status)
1992 break;
1995 /* Go check for pending interrupts. */
1996 qla1280_poll(ha);
1998 SYS_DELAY(5); /* 10 */
2000 if (!cnt)
2002 /* Set timeout status */
2003 CMD_RESULT(sp->cmd) = DID_TIME_OUT << 16;
2005 #if WATCHDOGTIMER
2006 /* Remove command from watchdog queue. */
2007 if (sp->flags & SRB_WATCHDOG)
2008 qla1280_timeout_remove(ha, sp);
2009 #endif
2010 COMTRACE('M')
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)
2015 sti();
2016 (*(sp->cmd)->scsi_done)(sp->cmd);
2017 cli();
2018 #else
2019 (*(sp->cmd)->scsi_done)(sp->cmd);
2020 #endif
2022 /* Acquire LU queue specific lock */
2023 QLA1280_SCSILU_LOCK(q);
2025 if (q->q_outcnt)
2026 q->q_outcnt--;
2028 else
2029 /* Acquire LU queue specific lock */
2030 QLA1280_SCSILU_LOCK(q);
2032 else
2033 { /* Place request back on top of device queue. */
2034 qla1280_putq_t(q, sp);
2036 if (q->q_outcnt)
2037 q->q_outcnt--;
2038 if (q->q_outcnt < ha->bus_settings[b].hiwat)
2039 q->q_flag &= ~QLA1280_QBUSY;
2040 break;
2045 DRIVER_UNLOCK
2047 /* Release SCSI LU queue specific lock */
2048 QLA1280_SCSILU_UNLOCK(q);
2050 LEAVE("qla1280_next");
2054 * qla1280_putq_t
2055 * Add the standard SCB job to the top of standard SCB commands.
2057 * Input:
2058 * q = SCSI LU pointer.
2059 * sp = srb pointer.
2060 * SCSI_LU_Q lock must be already obtained.
2062 STATIC void
2063 qla1280_putq_t(scsi_lu_t *q, srb_t *sp)
2065 srb_t *srb_p;
2066 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2067 unsigned long cpu_flags = 0;
2068 #endif
2070 #ifdef QL_DEBUG_LEVEL_3
2071 ENTER("qla1280_putq_t");
2072 #endif
2073 DRIVER_LOCK
2074 DEBUG(sprintf(debug_buff,"Adding to device 0x%p<-(0x%p)\n\r",q,sp));
2075 DEBUG(qla1280_print(debug_buff));
2076 sp->s_next = NULL;
2077 if (!q->q_first) /* If queue empty */
2079 sp->s_prev = NULL;
2080 q->q_first = sp;
2081 q->q_last = sp;
2083 else
2085 srb_p = q->q_first;
2086 while (srb_p )
2087 srb_p = srb_p->s_next;
2089 if (srb_p)
2091 sp->s_prev = srb_p->s_prev;
2092 if (srb_p->s_prev)
2093 srb_p->s_prev->s_next = sp;
2094 else
2095 q->q_first = sp;
2096 srb_p->s_prev = sp;
2097 sp->s_next = srb_p;
2099 else
2101 sp->s_prev = q->q_last;
2102 q->q_last->s_next = sp;
2103 q->q_last = sp;
2107 DRIVER_UNLOCK
2108 #ifdef QL_DEBUG_LEVEL_3
2109 LEAVE("qla1280_putq_t");
2110 #endif
2114 * qla1280_removeq
2115 * Function used to remove a command block from the
2116 * LU queue.
2118 * Input:
2119 * q = SCSI LU pointer.
2120 * sp = srb pointer.
2121 * SCSI_LU_Q lock must be already obtained.
2123 STATIC void
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;
2128 #endif
2129 DEBUG(sprintf(debug_buff,"Removing from device_q (0x%p)->(0x%p)\n\r",q,sp));
2130 DEBUG(qla1280_print(debug_buff));
2131 DRIVER_LOCK
2132 if (sp->s_prev)
2134 if ((sp->s_prev->s_next = sp->s_next) != NULL)
2135 sp->s_next->s_prev = sp->s_prev;
2136 else
2137 q->q_last = sp->s_prev;
2139 else if (!(q->q_first = sp->s_next))
2140 q->q_last = NULL;
2141 else
2142 q->q_first->s_prev = NULL;
2143 DRIVER_UNLOCK
2147 * qla1280_mem_alloc
2148 * Allocates adapter memory.
2150 * Returns:
2151 * 0 = success.
2152 * 1 = failure.
2154 STATIC uint8_t
2155 qla1280_mem_alloc(scsi_qla_host_t *ha)
2158 uint8_t status = 1;
2160 #ifdef QL_DEBUG_LEVEL_3
2161 ENTER("qla1280_mem_alloc");
2162 #endif
2164 #ifdef DYNAMIC_MEM_ALLOC
2165 ha->request_ring = qla1280_alloc_phys(REQUEST_ENTRY_SIZE * REQUEST_ENTRY_CNT,
2166 &ha->request_dma);
2167 if(ha->request_ring) {
2168 ha->response_ring = qla1280_alloc_phys(RESPONSE_ENTRY_SIZE * RESPONSE_ENTRY_CNT,
2169 &ha->response_dma);
2170 if(ha->response_ring) {
2171 status = 0;
2174 #else
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]);
2179 status = 0;
2180 #endif
2182 if(status) {
2183 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2184 qla1280_print("qla1280_mem_alloc: **** FAILED ****\n");
2185 #endif
2187 #ifdef QL_DEBUG_LEVEL_3
2188 else
2189 LEAVE("qla1280_mem_alloc");
2190 #endif
2191 return(status);
2195 * qla1280_mem_free
2196 * Frees adapter allocated memory.
2198 * Input:
2199 * ha = adapter block pointer.
2201 STATIC void
2202 qla1280_mem_free(scsi_qla_host_t *ha)
2204 scsi_lu_t *q;
2205 uint32_t b, t, l;
2207 ENTER("qlc1280_mem_free");
2208 if (ha)
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
2238 * Input:
2239 * ha = adapter block pointer.
2241 * Returns:
2242 * None
2244 static inline void qla1280_enable_intrs(scsi_qla_host_t *ha) {
2245 device_reg_t *reg;
2247 reg = ha->iobase;
2248 ha->flags.interrupts_on = 1;
2249 /* enable risc and host interrupts */
2250 WRT_REG_WORD(&reg->ictrl, (ISP_EN_INT+ ISP_EN_RISC));
2253 static inline void qla1280_disable_intrs(scsi_qla_host_t *ha) {
2254 device_reg_t *reg;
2256 reg = ha->iobase;
2257 ha->flags.interrupts_on = 0;
2258 /* disable risc and host interrupts */
2259 WRT_REG_WORD(&reg->ictrl, 0);
2263 * qla1280_initialize_adapter
2264 * Initialize board.
2266 * Input:
2267 * ha = adapter block pointer.
2269 * Returns:
2270 * 0 = success
2272 STATIC uint8_t
2273 qla1280_initialize_adapter(scsi_qla_host_t *ha)
2275 device_reg_t *reg;
2276 uint8_t status;
2277 /* uint8_t cnt; */
2278 uint8_t b;
2280 #ifdef QL_DEBUG_LEVEL_3
2281 ENTER("qla1280_initialize_adapter");
2282 #endif
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)))
2295 reg = ha->iobase;
2297 /* Disable ISP interrupts. */
2298 WRT_REG_WORD(&reg->ictrl, 0);
2300 /* Insure mailbox registers are free. */
2301 WRT_REG_WORD(&reg->semaphore, 0);
2302 WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
2303 WRT_REG_WORD(&reg->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);
2320 if (!status)
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);
2363 qla1280_poll(ha);
2366 else
2367 break;
2370 else
2371 status = 1;
2375 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2376 if (status)
2377 qla1280_print("qla1280_initialize_adapter: **** FAILED ****\n\r");
2378 #endif
2379 #ifdef QL_DEBUG_LEVEL_3
2380 else
2381 LEAVE("qla1280_initialize_adapter");
2382 #endif
2383 return(status);
2387 * qla1280_enable_tgt
2388 * Enable target mode.
2390 * Input:
2391 * ha = adapter block pointer.
2392 * b = SCSI bus number.
2394 * Returns:
2395 * 0 = success.
2397 STATIC uint8_t
2398 qla1280_enable_tgt(scsi_qla_host_t *ha, uint8_t b)
2400 uint8_t status = 0;
2401 /* uint16_t mb[MAILBOX_REGISTER_COUNT]; */
2403 #ifdef QL_DEBUG_LEVEL_3
2404 qla1280_print("qla1280_enable_tgt: entered\n\r");
2405 #endif
2407 /* Enable target mode. */
2409 mb[0] = MBC_ENABLE_TARGET_MODE;
2410 mb[1] = BIT_15;
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)
2415 if (status)
2416 qla1280_print("qla1280_enable_tgt: **** FAILED ****\n\r");
2417 #endif
2418 #ifdef QL_DEBUG_LEVEL_3
2419 else
2420 qla1280_print("qla1280_enable_tgt: exiting normally\n\r");
2421 #endif
2422 return(status);
2426 * ISP Firmware Test
2427 * Checks if present version of RISC firmware is older than
2428 * driver firmware.
2430 * Input:
2431 * ha = adapter block pointer.
2433 * Returns:
2434 * 0 = firmware does not need to be loaded.
2436 STATIC uint8_t
2437 qla1280_isp_firmware(scsi_qla_host_t *ha)
2439 nvram_t *nv = (nvram_t *)ha->response_ring;
2440 uint16_t *wptr;
2441 uint8_t chksum;
2442 uint8_t cnt;
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"));
2451 chksum = 0;
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);
2457 wptr++;
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);
2464 #endif
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;
2473 else
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");
2480 #endif
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");
2491 #endif
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]);
2497 else
2498 printk(KERN_INFO "qla1280: RISC checksum failed.\n");
2500 else
2502 DEBUG(printk("qla1280: NVRAM configured to load RISC load.\n"));
2503 status = 1;
2506 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2507 if (status)
2508 qla1280_print(
2509 "qla1280_isp_firmware: **** Load RISC code ****\n\r");
2510 #endif
2511 LEAVE("qla1280_isp_firmware");
2512 return(status);
2516 * PCI configuration
2517 * Setup device PCI configuration registers.
2519 * Input:
2520 * ha = adapter block pointer.
2522 * Returns:
2523 * 0 = success.
2525 STATIC uint8_t
2526 qla1280_pci_config(scsi_qla_host_t *ha)
2528 uint8_t status = 1;
2529 uint32_t command;
2530 #if MEMORY_MAPPED_IO
2531 uint32_t page_offset, base;
2532 uint32_t mmapbase;
2533 #endif
2534 config_reg_t *creg = 0;
2535 uint16_t buf_wd;
2537 ENTER("qla1280_pci_config");
2539 /* Get command register. */
2540 if (pci_read_config_word(ha->pdev,OFFSET(creg->command), &buf_wd) == PCIBIOS_SUCCESSFUL)
2542 command = buf_wd;
2544 * Set Bus Master Enable, Memory Address Space Enable and
2545 * reset any error bits.
2547 buf_wd &= ~0x7;
2548 #if MEMORY_MAPPED_IO
2549 DEBUG(printk("qla1280: MEMORY MAPPED IO is enabled.\n"));
2550 buf_wd |= BIT_2 + BIT_1 + BIT_0;
2551 #else
2552 buf_wd |= BIT_2 + BIT_0;
2553 #endif
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. */
2562 buf_wd &= ~BIT_0;
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);
2576 #else
2577 ha->mmpbase = vremap(base,page_offset + 256);
2578 #endif
2579 if( ha->mmpbase )
2581 ha->mmpbase += page_offset;
2582 /* ha->iobase = ha->mmpbase; */
2583 status = 0;
2585 #else /* MEMORY_MAPPED_IO */
2586 status = 0;
2587 #endif /* MEMORY_MAPPED_IO */
2592 LEAVE("qla1280_pci_config");
2593 return(status);
2597 * Chip diagnostics
2598 * Test chip for proper operation.
2600 * Input:
2601 * ha = adapter block pointer.
2603 * Returns:
2604 * 0 = success.
2606 STATIC uint8_t
2607 qla1280_chip_diag(scsi_qla_host_t *ha)
2609 device_reg_t *reg = ha->iobase;
2610 uint8_t status = 0;
2611 uint16_t data;
2612 uint32_t cnt;
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",&reg->id_l);
2617 qla1280_print(debug_buff);
2618 #endif
2620 /* Soft reset chip and wait for it to finish. */
2621 WRT_REG_WORD(&reg->ictrl, ISP_RESET);
2622 data = qla1280_debounce_register(&reg->ictrl);
2623 for (cnt = 6000000; cnt && data & ISP_RESET; cnt--)
2625 SYS_DELAY(5);
2626 data = RD_REG_WORD(&reg->ictrl);
2628 if (cnt)
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");
2633 #endif
2634 WRT_REG_WORD(&reg->cfg_1, 0);
2636 /* Reset RISC and disable BIOS which
2637 allows RISC to execute out of RAM. */
2638 WRT_REG_WORD(&reg->host_cmd, HC_RESET_RISC);
2639 WRT_REG_WORD(&reg->host_cmd, HC_RELEASE_RISC);
2640 WRT_REG_WORD(&reg->host_cmd, HC_DISABLE_BIOS);
2641 data = qla1280_debounce_register(&reg->mailbox0);
2642 for (cnt = 6000000; cnt && data == MBS_BUSY; cnt--)
2644 SYS_DELAY(5);
2645 data = RD_REG_WORD(&reg->mailbox0);
2648 if (cnt)
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");
2653 #endif
2654 if (RD_REG_WORD(&reg->mailbox1) != PROD_ID_1 ||
2655 (RD_REG_WORD(&reg->mailbox2) != PROD_ID_2 &&
2656 RD_REG_WORD(&reg->mailbox2) != PROD_ID_2a) ||
2657 RD_REG_WORD(&reg->mailbox3) != PROD_ID_3 ||
2658 RD_REG_WORD(&reg->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(&reg->mailbox1),
2662 RD_REG_WORD(&reg->mailbox2),
2663 RD_REG_WORD(&reg->mailbox3),
2664 RD_REG_WORD(&reg->mailbox4) );
2665 status = 1;
2667 else
2669 DEBUG(printk("qla1280_chip_diag: Checking mailboxes of chip\n"));
2670 /* Wrap Incoming Mailboxes Test. */
2671 mb[0] = MBC_MAILBOX_REGISTER_TEST;
2672 mb[1] = 0xAAAA;
2673 mb[2] = 0x5555;
2674 mb[3] = 0xAA55;
2675 mb[4] = 0x55AA;
2676 mb[5] = 0xA5A5;
2677 mb[6] = 0x5A5A;
2678 mb[7] = 0x2525;
2679 if (!(status = qla1280_mailbox_command(ha,
2680 (BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0),
2681 &mb[0])))
2683 if (mb[1] != 0xAAAA || mb[2] != 0x5555 ||
2684 mb[3] != 0xAA55 || mb[4] != 0x55AA)
2685 status = 1;
2686 if (mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
2687 mb[7] != 0x2525)
2688 status = 1;
2689 if( status == 1 )
2690 printk(KERN_INFO "qla1280: Failed mailbox check\n");
2694 else
2695 status = 1;
2697 else
2698 status = 1;
2700 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2701 if (status)
2702 qla1280_print("qla1280_chip_diag: **** FAILED ****\n\r");
2703 #endif
2704 #ifdef QL_DEBUG_LEVEL_3
2705 else
2706 qla1280_print("qla1280_chip_diag: exiting normally\n\r");
2707 #endif
2708 return(status);
2712 * Setup chip
2713 * Load and start RISC firmware.
2715 * Input:
2716 * ha = adapter block pointer.
2718 * Returns:
2719 * 0 = success.
2721 STATIC uint8_t
2722 qla1280_setup_chip(scsi_qla_host_t *ha)
2724 uint8_t status = 0;
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
2730 uint8_t *sp;
2731 int i;
2732 #endif
2733 uint16_t cnt;
2734 int num;
2735 uint8_t *tbuf;
2736 u_long p_tbuf;
2738 #ifdef QL_DEBUG_LEVEL_3
2739 ENTER("qla1280_setup_chip");
2740 #endif
2742 if( (tbuf = (uint8_t *)KMALLOC(8000) ) == NULL )
2744 printk("setup_chip: couldn't alloacte memory\n");
2745 return(1);
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));
2761 num =0;
2762 while (risc_code_size > 0 && !status)
2764 cnt = 2000 >> 1;
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;
2776 mb[4] = cnt;
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,
2783 &mb[0])) )
2785 printk("Failed to load partial segment of f/w\n");
2786 break;
2788 /* dump it back */
2790 #if 0
2791 mb[0] = MBC_DUMP_RAM_A64;
2792 mb[1] = risc_address;
2793 mb[4] = cnt;
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,
2800 &mb[0])) )
2802 printk("Failed to dump partial segment of f/w\n");
2803 break;
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);
2811 break;
2815 #endif
2816 risc_address += cnt;
2817 risc_code_size = risc_code_size - cnt;
2818 risc_code_address = risc_code_address + cnt;
2819 num++;
2821 #ifdef QLA1280_UNUSED
2822 DEBUG(ql_debug_print = 0;)
2824 for (i = 0; i < ql12_risc_code_length01; i++)
2826 mb[0] = 0x4;
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,
2831 &mb[0]);
2832 if (status)
2834 printk("qla1280 : firmware load failure\n");
2835 break;
2838 mb[0] = 0x5;
2839 mb[1] = ql12_risc_code_addr01 + i;
2840 mb[2] = 0;
2842 status = qla1280_mailbox_command(ha, BIT_2|BIT_1|BIT_0,
2843 &mb[0]);
2844 if (status)
2846 printk("qla1280 : firmware dump failure\n");
2847 break;
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;)
2854 #endif
2856 /* Verify checksum of loaded RISC code. */
2857 if (!status)
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]);
2873 else
2874 printk("qla1280_setup_chip: Failed checksum.\n");
2877 KMFREE(tbuf,8000);
2879 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2880 if (status)
2881 qla1280_print("qla1280_setup_chip: **** FAILED ****\n\r");
2882 #endif
2883 #ifdef QL_DEBUG_LEVEL_3
2884 else
2885 LEAVE("qla1280_setup_chip");
2886 #endif
2887 return(status);
2891 * Initialize rings
2893 * Input:
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
2900 * Returns:
2901 * 0 = success.
2903 STATIC uint8_t
2904 qla1280_init_rings(scsi_qla_host_t *ha)
2906 uint8_t status = 0;
2907 uint16_t cnt;
2908 uint16_t mb[MAILBOX_REGISTER_COUNT];
2910 #ifdef QL_DEBUG_LEVEL_3
2911 ENTER("qla1280_init_rings");
2912 #endif
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);
2926 mb[4] = 0;
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,
2931 &mb[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);
2941 mb[5] = 0;
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,
2946 &mb[0]);
2949 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2950 if (status)
2951 qla1280_print("qla1280_init_rings: **** FAILED ****\n\r");
2952 #endif
2953 #ifdef QL_DEBUG_LEVEL_3
2954 else
2955 LEAVE("qla1280_init_rings");
2956 #endif
2957 return(status);
2961 * NVRAM configuration.
2963 * Input:
2964 * ha = adapter block pointer.
2965 * ha->request_ring = request ring virtual address
2967 * Output:
2968 * host adapters parameters in host adapter block
2970 * Returns:
2971 * 0 = success.
2973 STATIC uint8_t
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;
2978 uint8_t status = 0;
2979 uint32_t b, t, l;
2980 uint16_t *wptr;
2981 uint16_t mb[MAILBOX_REGISTER_COUNT];
2982 uint8_t cnt;
2983 uint8_t chksum;
2984 uint32_t nvsize;
2986 #if defined(QL_DEBUG_ROUTINES) && !defined(QL_DEBUG_LEVEL_4)
2987 uint8_t saved_print_status = ql_debug_print;
2988 #endif
2989 ENTER("qla1280_nvram_config");
2990 #if defined(QL_DEBUG_ROUTINES) && !defined(QL_DEBUG_LEVEL_4)
2991 ql_debug_print = FALSE;
2992 #endif
2994 /* Verify valid NVRAM checksum. */
2995 #if USE_NVRAM_DEFAULTS
2996 chksum = 1;
2997 #else
2998 wptr = (uint16_t *)ha->response_ring;
2999 chksum = 0;
3000 if( ha->device_id == QLA12160_DEVICE_ID ||
3001 ha->device_id == QLA10160_DEVICE_ID )
3002 nvsize = sizeof(nvram160_t)/2;
3003 else
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);
3010 wptr++;
3012 #endif
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"));
3021 #else
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; */
3028 #endif
3029 wptr = (uint16_t *)ha->response_ring;
3030 for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++)
3031 *wptr++ = 0;
3032 #endif
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
3061 status = 0;
3062 #else
3063 status = 1;
3064 #endif
3066 else
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
3076 ql_debug_print = 1;
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);
3147 #endif
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(&reg->cfg_1, mb[0]);
3162 /* Set SCSI termination. */
3163 WRT_REG_WORD(&reg->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(&reg->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;
3193 mb[1] = 0;
3194 if (nv->bus[0].config_2.req_ack_active_negation)
3195 mb[1] |= BIT_5;
3196 if (nv->bus[0].config_2.data_line_active_negation)
3197 mb[1] |= BIT_4;
3198 mb[2] = 0;
3199 if (nv->bus[1].config_2.req_ack_active_negation)
3200 mb[2] |= BIT_5;
3201 if (nv->bus[1].config_2.data_line_active_negation)
3202 mb[2] |= BIT_4;
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;
3216 /* Initiator ID. */
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]);
3222 /* Reset Delay. */
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);
3236 else
3238 /* Set Target Parameters. */
3239 mb[0] = MBC_SET_TARGET_PARAMETERS;
3240 mb[1] = (uint16_t)(b ? t | BIT_7 :t);
3241 mb[1] <<= 8;
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,
3248 &mb[0]);
3251 /* Save Tag queuing enable flag. */
3252 mb[0] = BIT_0 << t;
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,
3273 &mb[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;
3281 #endif
3283 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3284 DEBUG(if (status))
3285 DEBUG(qla1280_print("qla1280_nvram_config: **** FAILED ****\n\r");)
3286 #endif
3287 LEAVE("qla1280_nvram_config");
3288 return(status);
3292 * Get NVRAM data word
3293 * Calculates word position in NVRAM and calls request routine to
3294 * get the word from NVRAM.
3296 * Input:
3297 * ha = adapter block pointer.
3298 * address = NVRAM word address.
3300 * Returns:
3301 * data word.
3303 STATIC uint16_t
3304 qla1280_get_nvram_word(scsi_qla_host_t *ha, uint32_t address)
3306 uint32_t nv_cmd;
3307 uint16_t data;
3309 #ifdef QL_DEBUG_ROUTINES
3310 uint8_t saved_print_status = ql_debug_print;
3311 #endif
3312 #ifdef QL_DEBUG_LEVEL_4
3313 ENTER("qla1280_get_nvram_word");
3314 #endif
3316 nv_cmd = address << 16;
3317 nv_cmd |= NV_READ_OP;
3319 #ifdef QL_DEBUG_ROUTINES
3320 ql_debug_print = FALSE;
3321 #endif
3322 data = qla1280_nvram_request(ha, nv_cmd);
3323 #ifdef QL_DEBUG_ROUTINES
3324 ql_debug_print = saved_print_status;
3325 #endif
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");
3331 #endif
3332 return(data);
3336 * NVRAM request
3337 * Sends read command to NVRAM and gets data from NVRAM.
3339 * Input:
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
3346 * Returns:
3347 * data word.
3349 STATIC uint16_t
3350 qla1280_nvram_request(scsi_qla_host_t *ha, uint32_t nv_cmd)
3352 uint8_t cnt;
3353 device_reg_t *reg = ha->iobase;
3354 uint16_t data = 0;
3355 uint16_t reg_data;
3357 /* Send command to NVRAM. */
3359 nv_cmd <<= 5;
3360 for (cnt = 0; cnt < 11; cnt++)
3362 if (nv_cmd & BIT_31)
3363 qla1280_nv_write(ha, NV_DATA_OUT);
3364 else
3365 qla1280_nv_write(ha, 0);
3366 nv_cmd <<= 1;
3369 /* Read data from NVRAM. */
3371 for (cnt = 0; cnt < 16; cnt++)
3373 WRT_REG_WORD(&reg->nvram, NV_SELECT+NV_CLOCK);
3374 /* qla1280_nv_delay(ha); */
3375 NVRAM_DELAY();
3376 data <<= 1;
3377 reg_data = RD_REG_WORD(&reg->nvram);
3378 if (reg_data & NV_DATA_IN)
3379 data |= BIT_0;
3380 WRT_REG_WORD(&reg->nvram, NV_SELECT);
3381 /* qla1280_nv_delay(ha); */
3382 NVRAM_DELAY();
3385 /* Deselect chip. */
3387 WRT_REG_WORD(&reg->nvram, NV_DESELECT);
3388 /* qla1280_nv_delay(ha); */
3389 NVRAM_DELAY();
3391 return(data);
3394 STATIC void
3395 qla1280_nv_write(scsi_qla_host_t *ha, uint16_t data)
3397 device_reg_t *reg = ha->iobase;
3399 WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
3400 NVRAM_DELAY();
3401 /* qla1280_nv_delay(ha); */
3402 WRT_REG_WORD(&reg->nvram, data | NV_SELECT | NV_CLOCK);
3403 /* qla1280_nv_delay(ha); */
3404 NVRAM_DELAY();
3405 WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
3406 /* qla1280_nv_delay(ha); */
3407 NVRAM_DELAY();
3410 STATIC void
3411 qla1280_nv_delay(scsi_qla_host_t *ha)
3413 device_reg_t *reg = ha->iobase;
3414 int cnt = NV_DELAY_COUNT;
3415 uint16_t data = 0;
3417 while (cnt--)
3418 data |= RD_REG_WORD(&reg->nvram);
3422 * Mailbox Command
3423 * Issue mailbox command and waits for completion.
3425 * Input:
3426 * ha = adapter block pointer.
3427 * mr = mailbox registers to load.
3428 * mb = data pointer for mailbox registers.
3430 * Output:
3431 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
3433 * Returns:
3434 * 0 = success
3436 STATIC uint8_t
3437 qla1280_mailbox_command(scsi_qla_host_t *ha, uint8_t mr, uint16_t *mb)
3439 device_reg_t *reg = ha->iobase;
3440 uint8_t status = 0;
3441 uint32_t cnt;
3442 uint16_t *optr, *iptr;
3443 uint16_t data;
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;
3448 #endif
3450 #ifdef QL_DEBUG_LEVEL_3
3451 ENTER("qla1280_mailbox_command");
3452 #endif
3454 /* Acquire interrupt specific lock */
3455 QLA1280_INTR_LOCK(ha);
3456 DRIVER_LOCK
3457 ha->flags.mbox_busy = TRUE;
3459 /* Load mailbox registers. */
3460 optr = (uint16_t *)&reg->mailbox0;
3461 iptr = mb;
3462 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++)
3464 if (mr & BIT_0)
3466 WRT_REG_WORD(optr, (*iptr));
3469 mr >>= 1;
3470 optr++;
3471 iptr++;
3473 /* Issue set host interrupt command. */
3474 ha->flags.mbox_int = FALSE;
3475 WRT_REG_WORD(&reg->host_cmd, HC_SET_HOST_INT);
3476 data = qla1280_debounce_register(&reg->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);
3486 SYS_DELAY(1);
3487 data = RD_REG_WORD(&reg->istatus);
3490 /* Check for mailbox command timeout. */
3491 if ( !cnt )
3493 #ifdef QL_DEBUG_LEVEL_2
3494 qla1280_print(
3495 "qla1280_mailbox_command: **** Command Timeout, mailbox0 = ");
3496 qla1280_output_number((uint32_t)mb[0], 16);
3497 qla1280_print(" ****\n\r");
3498 #endif
3499 ha->flags.isp_abort_needed = TRUE;
3500 status = 1;
3502 else if (ha->mailbox_out[0] != MBS_CMD_CMP)
3503 status = 1;
3505 /* Load return mailbox registers. */
3506 optr = mb;
3507 iptr = (uint16_t *)&ha->mailbox_out[0];
3508 mr = MAILBOX_REGISTER_COUNT;
3509 while (mr--)
3510 *optr++ = *iptr++;
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);
3518 DRIVER_UNLOCK
3520 if (ha->flags.isp_abort_needed)
3521 qla1280_abort_isp(ha);
3523 if (ha->flags.reset_marker)
3524 qla1280_rst_aen(ha);
3526 if (done_q_first)
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)
3530 if (status)
3532 qla1280_print("qla1280_mailbox_command: **** FAILED, mailbox0 = ");
3533 qla1280_output_number((uint32_t)mb[0], 16);
3534 qla1280_print(" ****\n\r");
3536 #endif
3537 #ifdef QL_DEBUG_LEVEL_3
3538 else
3539 LEAVE("qla1280_mailbox_command");
3540 #endif
3541 return(status);
3545 * qla1280_poll
3546 * Polls ISP for interrupts.
3548 * Input:
3549 * ha = adapter block pointer.
3551 STATIC void
3552 qla1280_poll(scsi_qla_host_t *ha)
3554 device_reg_t *reg = ha->iobase;
3555 uint16_t data;
3556 srb_t *done_q_first = 0;
3557 srb_t *done_q_last = 0;
3559 #ifdef QL_DEBUG_LEVEL_3
3560 /* ENTER("qla1280_poll"); */
3561 #endif
3563 /* Acquire interrupt specific lock */
3564 QLA1280_INTR_LOCK(ha);
3566 /* Check for pending interrupts. */
3567 data = RD_REG_WORD(&reg->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);
3582 if (done_q_first)
3583 qla1280_done(ha, (srb_t **)&done_q_first, (srb_t **)&done_q_last);
3585 #ifdef QL_DEBUG_LEVEL_3
3586 /* LEAVE("qla1280_poll"); */
3587 #endif
3591 * qla1280_bus_reset
3592 * Issue SCSI bus reset.
3594 * Input:
3595 * ha = adapter block pointer.
3596 * b = SCSI bus number.
3598 * Returns:
3599 * 0 = success
3601 STATIC uint8_t
3602 qla1280_bus_reset(scsi_qla_host_t *ha, uint8_t b)
3604 uint8_t status;
3605 uint16_t mb[MAILBOX_REGISTER_COUNT];
3607 #ifdef QL_DEBUG_LEVEL_3
3608 qla1280_print("qla1280_bus_reset: entered\n\r");
3609 #endif
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]);
3620 if (status)
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++;
3626 else
3628 QLA1280_DELAY(4);
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)
3635 if (status)
3636 qla1280_print("qla1280_bus_reset: **** FAILED ****\n\r");
3637 #endif
3638 #ifdef QL_DEBUG_LEVEL_3
3639 else
3640 qla1280_print("qla1280_bus_reset: exiting normally\n\r");
3641 #endif
3642 return(status);
3646 * qla1280_device_reset
3647 * Issue bus device reset message to the target.
3649 * Input:
3650 * ha = adapter block pointer.
3651 * b = SCSI BUS number.
3652 * t = SCSI ID.
3654 * Returns:
3655 * 0 = success
3657 STATIC uint8_t
3658 qla1280_device_reset(scsi_qla_host_t *ha, uint8_t b, uint32_t t)
3660 uint8_t status;
3661 uint16_t mb[MAILBOX_REGISTER_COUNT];
3663 #ifdef QL_DEBUG_LEVEL_3
3664 ENTER("qla1280_device_reset");
3665 #endif
3667 mb[0] = MBC_ABORT_TARGET;
3668 mb[1] = (b ? (t | BIT_7) : t) << 8;
3669 mb[2] = 1;
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)
3676 if (status)
3677 qla1280_print("qla1280_device_reset: **** FAILED ****\n\r");
3678 #endif
3679 #ifdef QL_DEBUG_LEVEL_3
3680 else
3681 LEAVE("qla1280_device_reset");
3682 #endif
3683 return(status);
3687 * qla1280_abort_device
3688 * Issue an abort message to the device
3690 * Input:
3691 * ha = adapter block pointer.
3692 * b = SCSI BUS.
3693 * t = SCSI ID.
3694 * l = SCSI LUN.
3696 * Returns:
3697 * 0 = success
3699 STATIC uint8_t
3700 qla1280_abort_device(scsi_qla_host_t *ha, uint8_t b, uint32_t t, uint32_t l)
3702 uint8_t status;
3703 uint16_t mb[MAILBOX_REGISTER_COUNT];
3705 #ifdef QL_DEBUG_LEVEL_3
3706 ENTER("qla1280_abort_device");
3707 #endif
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)
3717 if (status)
3718 qla1280_print("qla1280_abort_device: **** FAILED ****\n\r");
3719 #endif
3720 #ifdef QL_DEBUG_LEVEL_3
3721 else
3722 LEAVE("qla1280_abort_device");
3723 #endif
3724 return(status);
3728 * qla1280_abort_command
3729 * Abort command aborts a specified IOCB.
3731 * Input:
3732 * ha = adapter block pointer.
3733 * sp = SB structure pointer.
3735 * Returns:
3736 * 0 = success
3738 STATIC uint8_t
3739 qla1280_abort_command(scsi_qla_host_t *ha, srb_t *sp)
3741 uint8_t status;
3742 uint16_t mb[MAILBOX_REGISTER_COUNT];
3743 uint32_t b, t, l;
3744 uint32_t handle;
3746 #ifdef QL_DEBUG_LEVEL_3
3747 ENTER("qla1280_abort_command");
3748 #endif
3750 /* Locate handle number. */
3751 for (handle = 0; handle < MAX_OUTSTANDING_COMMANDS; handle++)
3752 if (ha->outstanding_cmds[handle] == sp)
3753 break;
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)
3766 if (status)
3767 qla1280_print("qla1280_abort_command: **** FAILED ****\n\r");
3768 #endif
3769 sp->flags |= SRB_ABORT_PENDING;
3771 LEAVE("qla1280_abort_command");
3772 return(status);
3776 * qla1280_reset_adapter
3777 * Reset adapter.
3779 * Input:
3780 * ha = adapter block pointer.
3782 STATIC void
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");
3789 #endif
3791 /* Disable ISP chip */
3792 ha->flags.online = FALSE;
3793 WRT_REG_WORD(&reg->ictrl, ISP_RESET);
3794 WRT_REG_WORD(&reg->host_cmd, HC_RESET_RISC);
3795 WRT_REG_WORD(&reg->host_cmd, HC_RELEASE_RISC);
3796 WRT_REG_WORD(&reg->host_cmd, HC_DISABLE_BIOS);
3798 #ifdef QL_DEBUG_LEVEL_3
3799 LEAVE("qla1280_reset_adapter");
3800 #endif
3804 * Issue marker command.
3805 * Function issues marker IOCB.
3807 * Input:
3808 * ha = adapter block pointer.
3809 * b = SCSI BUS number
3810 * t = SCSI ID
3811 * l = SCSI LUN
3812 * type = marker modifier
3814 STATIC void
3815 qla1280_marker(scsi_qla_host_t *ha, uint8_t b, uint32_t t, uint32_t l, uint8_t type)
3817 mrk_entry_t *pkt;
3819 #ifdef QL_DEBUG_LEVEL_3
3820 ENTER("qla1280_marker");
3821 #endif
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");
3837 #endif
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.
3846 * Input:
3847 * ha = adapter block pointer.
3848 * sp = SB structure pointer.
3850 * Returns:
3851 * 0 = success, was able to issue command.
3853 STATIC uint8_t
3854 qla1280_64bit_start_scsi(scsi_qla_host_t *ha, srb_t *sp)
3856 device_reg_t *reg = ha->iobase;
3857 uint8_t status = 0;
3858 Scsi_Cmnd *cmd = sp->cmd;
3859 uint32_t cnt;
3860 cmd_a64_entry_t *pkt;
3861 uint16_t req_cnt;
3862 uint16_t seg_cnt;
3863 struct scatterlist *sg = (struct scatterlist *) NULL;
3864 uint32_t *dword_ptr;
3866 #ifdef QL_DEBUG_LEVEL_3
3867 ENTER("qla1280_64bit_start_scsi:");
3868 #endif
3870 if( qla1280_check_for_dead_scsi_bus(ha, sp) )
3872 return(0);
3875 /* Calculate number of entries and segments required. */
3876 seg_cnt = 0;
3877 req_cnt = 1;
3878 if (cmd->use_sg)
3880 seg_cnt = cmd->use_sg;
3881 sg = (struct scatterlist *) cmd->request_buffer;
3883 if (seg_cnt > 2)
3885 req_cnt += (uint16_t)(seg_cnt - 2) / 5;
3886 if ((uint16_t)(seg_cnt - 2) % 5)
3887 req_cnt++;
3890 else if (cmd->request_bufflen) /* If data transfer. */
3892 DEBUG(printk("Single data transfer (0x%x)\n",cmd->request_bufflen));
3893 seg_cnt = 1;
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(&reg->mailbox4);
3903 if (ha->req_ring_index < cnt)
3904 ha->req_q_cnt = cnt - ha->req_ring_index;
3905 else
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++)
3936 *dword_ptr++ = 0;
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;
3963 else
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;
3984 sg++;
3986 #ifdef QL_DEBUG_LEVEL_5
3987 qla1280_print(
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);
3997 #endif
3999 * Build continuation packets.
4001 while (seg_cnt > 0)
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;
4010 else
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++)
4018 *dword_ptr++ = 0;
4020 /* Load packet defaults. */
4021 ((cont_a64_entry_t *)pkt)->entry_type =
4022 CONTINUE_A64_TYPE;
4023 ((cont_a64_entry_t *)pkt)->entry_count = 1;
4024 ((cont_a64_entry_t *)pkt)->sys_define = (uint8_t)
4025 ha->req_ring_index;
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;
4037 sg++;
4039 #ifdef QL_DEBUG_LEVEL_5
4040 qla1280_print(
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);
4051 #endif
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
4060 qla1280_print(
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);
4070 #endif
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;
4079 qla1280_print(
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);
4090 #endif
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;
4098 else
4099 ha->request_ring_ptr++;
4101 /* Set chip new ring index. */
4102 WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
4104 else
4106 status = 1;
4107 #ifdef QL_DEBUG_LEVEL_2
4108 qla1280_print(
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);
4112 #endif
4115 else
4117 status = 1;
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");
4126 #endif
4129 /* Release ring specific lock */
4130 QLA1280_RING_UNLOCK(ha);
4132 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4133 if (status)
4134 qla1280_print("qla1280_64bit_start_scsi: **** FAILED ****\n\r");
4135 #endif
4136 #ifdef QL_DEBUG_LEVEL_3
4137 else
4138 qla1280_print("qla1280_64bit_start_scsi: exiting normally\n\r");
4139 #endif
4140 return(status);
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.
4156 * Input:
4157 * ha = adapter block pointer.
4158 * sp = SCSI Request Block structure pointer.
4160 * Returns:
4161 * 0 = success, was able to issue command.
4163 STATIC uint8_t
4164 qla1280_32bit_start_scsi(scsi_qla_host_t *ha, srb_t *sp)
4166 device_reg_t *reg = ha->iobase;
4167 uint8_t status = 0;
4168 Scsi_Cmnd *cmd = sp->cmd;
4169 uint32_t cnt;
4170 cmd_entry_t *pkt;
4171 uint16_t req_cnt;
4172 uint16_t seg_cnt;
4173 struct scatterlist *sg = (struct scatterlist *) NULL;
4174 uint8_t *data_ptr;
4175 uint32_t *dword_ptr;
4177 ENTER("qla1280_32bit_start_scsi");
4180 if( qla1280_check_for_dead_scsi_bus(ha, sp) )
4182 return(0);
4185 /* Calculate number of entries and segments required. */
4186 req_cnt = 1;
4187 if (cmd->use_sg)
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
4201 if (seg_cnt > 4)
4203 req_cnt += (uint16_t)(seg_cnt - 4) / 7;
4204 if ((uint16_t)(seg_cnt - 4) % 7)
4205 req_cnt++;
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));
4213 seg_cnt = 1;
4215 else
4217 DEBUG(printk("No data transfer \n"));
4218 seg_cnt = 0;
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(&reg->mailbox4);
4228 if (ha->req_ring_index < cnt)
4229 ha->req_q_cnt = cnt - ha->req_ring_index;
4230 else
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++)
4263 *dword_ptr++ = 0;
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.
4286 if (seg_cnt)
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;
4303 else
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));
4325 sg++;
4328 * Build continuation packets.
4330 while (seg_cnt > 0)
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;
4339 else
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++)
4347 *dword_ptr++ = 0;
4349 /* Load packet defaults. */
4350 ((cont_entry_t *)pkt)->entry_type =
4351 CONTINUE_TYPE;
4352 ((cont_entry_t *)pkt)->entry_count = 1;
4354 ((cont_entry_t *)pkt)->sys_define = (uint8_t)
4355 ha->req_ring_index;
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;
4366 sg++;
4368 #ifdef QL_DEBUG_LEVEL_5
4369 qla1280_print(
4370 "qla1280_32bit_start_scsi: continuation packet data - scsi(");
4371 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd), 10);
4372 qla1280_print(":");
4373 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd), 10);
4374 qla1280_print(":");
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);
4378 #endif
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
4393 qla1280_print(
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);
4397 #endif
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);
4402 #endif
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;
4410 else
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"));
4415 ha->qthreads--;
4416 sp->u_start = jiffies;
4417 sp->flags |= SRB_SENT;
4418 ha->actthreads++;
4419 /* qla1280_output_number((uint32_t)ha->actthreads++, 16); */
4420 WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
4422 else
4424 status = 1;
4425 #ifdef QL_DEBUG_LEVEL_2
4426 qla1280_print(
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");
4431 #endif
4434 else
4436 status = 1;
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"); */
4445 #endif
4448 /* Release ring specific lock */
4449 QLA1280_RING_UNLOCK(ha);
4451 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4452 /* if (status)
4453 qla1280_print("qla1280_32bit_start_scsi: **** FAILED ****\n\r"); */
4454 #endif
4455 #ifdef QL_DEBUG_LEVEL_3
4456 LEAVE("qla1280_32bit_start_scsi");
4457 #endif
4458 return(status);
4462 * qla1280_req_pkt
4463 * Function is responsible for locking ring and
4464 * getting a zeroed out request packet.
4466 * Input:
4467 * ha = adapter block pointer.
4469 * Returns:
4470 * 0 = failed to get slot.
4472 STATIC request_t *
4473 qla1280_req_pkt(scsi_qla_host_t *ha)
4475 device_reg_t *reg = ha->iobase;
4476 request_t *pkt = 0;
4477 uint16_t cnt;
4478 uint32_t *dword_ptr;
4479 uint32_t timer;
4481 #ifdef QL_DEBUG_LEVEL_3
4482 ENTER("qla1280_req_pkt");
4483 #endif
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(&reg->mailbox4);
4495 if (ha->req_ring_index < cnt)
4496 ha->req_q_cnt = cnt - ha->req_ring_index;
4497 else
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)
4504 ha->req_q_cnt--;
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++)
4510 *dword_ptr++ = 0;
4512 /* Set system defined field. */
4513 pkt->sys_define = (uint8_t)ha->req_ring_index;
4515 /* Set entry count. */
4516 pkt->entry_count = 1;
4518 break;
4521 /* Release ring specific lock */
4522 QLA1280_RING_UNLOCK(ha);
4524 SYS_DELAY(2); /* 10 */
4526 /* Check for pending interrupts. */
4527 qla1280_poll(ha);
4530 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4531 if (!pkt)
4532 qla1280_print("qla1280_req_pkt: **** FAILED ****\n\r");
4533 #endif
4534 #ifdef QL_DEBUG_LEVEL_3
4535 else
4536 qla1280_print("qla1280_req_pkt: exiting normally\n\r");
4537 #endif
4538 return(pkt);
4542 * qla1280_isp_cmd
4543 * Function is responsible for modifying ISP input pointer.
4544 * Releases ring lock.
4546 * Input:
4547 * ha = adapter block pointer.
4549 STATIC void
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");
4556 #endif
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);
4561 #endif
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;
4570 else
4571 ha->request_ring_ptr++;
4573 /* Set chip new ring index. */
4574 WRT_REG_WORD(&reg->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");
4581 #endif
4585 * qla1280_enable_lun
4586 * Issue enable LUN entry IOCB.
4588 * Input:
4589 * ha = adapter block pointer.
4590 * b = SCSI BUS number.
4591 * l = LUN number.
4593 STATIC void
4594 qla1280_enable_lun(scsi_qla_host_t *ha, uint8_t b, uint32_t l)
4596 elun_entry_t *pkt;
4598 #ifdef QL_DEBUG_LEVEL_3
4599 qla1280_print("qla1280_enable_lun: entered\n\r");
4600 #endif
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)
4620 if (!pkt)
4621 qla1280_print("qla1280_enable_lun: **** FAILED ****\n\r");
4622 #endif
4623 #ifdef QL_DEBUG_LEVEL_3
4624 else
4625 qla1280_print("qla1280_enable_lun: exiting normally\n\r");
4626 #endif
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.
4640 * Input:
4641 * ha = adapter block pointer.
4642 * inotify = immediate notify entry pointer.
4644 STATIC void
4645 qla1280_notify_ack(scsi_qla_host_t *ha, notify_entry_t *inotify)
4647 nack_entry_t *pkt;
4649 #ifdef QL_DEBUG_LEVEL_3
4650 qla1280_print("qla1280_notify_ack: entered\n\r");
4651 #endif
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)
4661 pkt->event = BIT_7;
4662 else
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)
4670 if (!pkt)
4671 qla1280_print("qla1280_notify_ack: **** FAILED ****\n\r");
4672 #endif
4673 #ifdef QL_DEBUG_LEVEL_3
4674 else
4675 qla1280_print("qla1280_notify_ack: exiting normally\n\r");
4676 #endif
4680 * qla1280_immed_notify
4681 * Issue immediate notify IOCB for LUN 0.
4683 * Input:
4684 * ha = adapter block pointer.
4685 * inotify = immediate notify entry pointer.
4687 STATIC void
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");
4694 #endif
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;
4703 pkt->status = 1;
4705 /* Issue command to ISP */
4706 qla1280_isp_cmd(ha);
4709 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4710 if (!pkt)
4711 qla1280_print("qla1280_immed_notify: **** FAILED ****\n\r");
4712 #endif
4713 #ifdef QL_DEBUG_LEVEL_3
4714 else
4715 qla1280_print("qla1280_immed_notify: exiting normally\n\r");
4716 #endif
4720 * qla1280_accept_io
4721 * Issue accept target I/O IOCB for LUN 0.
4723 * Input:
4724 * ha = adapter block pointer.
4725 * ctio = ctio returned entry pointer.
4727 STATIC void
4728 qla1280_accept_io(scsi_qla_host_t *ha, ctio_ret_entry_t *ctio)
4730 atio_entry_t *pkt;
4732 #ifdef QL_DEBUG_LEVEL_3
4733 qla1280_print("qla1280_accept_io: entered\n\r");
4734 #endif
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;
4744 pkt->status = 1;
4746 /* Issue command to ISP */
4747 qla1280_isp_cmd(ha);
4750 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4751 if (!pkt)
4752 qla1280_print("qla1280_accept_io: **** FAILED ****\n\r");
4753 #endif
4754 #ifdef QL_DEBUG_LEVEL_3
4755 else
4756 qla1280_print("qla1280_accept_io: exiting normally\n\r");
4757 #endif
4761 * qla1280_64bit_continue_io
4762 * Issue continue target I/O IOCB.
4764 * Input:
4765 * ha = adapter block pointer.
4766 * atio = atio pointer.
4767 * len = total bytecount.
4768 * addr = physical address pointer.
4770 STATIC void
4771 qla1280_64bit_continue_io(scsi_qla_host_t *ha, atio_entry_t *atio, uint32_t len,
4772 paddr32_t *addr)
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");
4779 #endif
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;
4792 if (len)
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)
4807 if (!pkt)
4808 qla1280_print("qla1280_64bit_continue_io: **** FAILED ****\n\r");
4809 #endif
4810 #ifdef QL_DEBUG_LEVEL_3
4811 else
4812 qla1280_print("qla1280_64bit_continue_io: exiting normally\n\r");
4813 #endif
4817 * qla1280_32bit_continue_io
4818 * Issue continue target I/O IOCB.
4820 * Input:
4821 * ha = adapter block pointer.
4822 * atio = atio pointer.
4823 * len = total bytecount.
4824 * addr = physical address pointer.
4826 STATIC void
4827 qla1280_32bit_continue_io(scsi_qla_host_t *ha, atio_entry_t *atio, uint32_t len,
4828 paddr32_t *addr)
4830 ctio_entry_t *pkt;
4831 uint32_t *dword_ptr;
4833 #ifdef QL_DEBUG_LEVEL_3
4834 qla1280_print("qla1280_32bit_continue_io: entered\n\r");
4835 #endif
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;
4848 if (len)
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)
4862 if (!pkt)
4863 qla1280_print("qla1280_32bit_continue_io: **** FAILED ****\n\r");
4864 #endif
4865 #ifdef QL_DEBUG_LEVEL_3
4866 else
4867 qla1280_print("qla1280_32bit_continue_io: exiting normally\n\r");
4868 #endif
4870 #endif /* QL1280_TARGET_MODE_SUPPORT */
4872 /****************************************************************************/
4873 /* Interrupt Service Routine. */
4874 /****************************************************************************/
4876 /****************************************************************************
4877 * qla1280_isr
4878 * Calls I/O done on command completion.
4880 * Input:
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 ****************************************************************************/
4886 STATIC void
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;
4890 response_t *pkt;
4891 srb_t *sp;
4892 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
4893 uint16_t *wptr;
4894 uint32_t index;
4896 ENTER("qla1280_isr");
4899 /* Save mailbox register 5 */
4900 mailbox[5] = RD_REG_WORD(&reg->mailbox5);
4902 /* Check for mailbox interrupt. */
4904 mailbox[0] = RD_REG_WORD(&reg->semaphore);
4905 if (mailbox[0] & BIT_0)
4907 /* Get mailbox data. */
4909 wptr = &mailbox[0];
4910 *wptr++ = RD_REG_WORD(&reg->mailbox0);
4911 *wptr++ = RD_REG_WORD(&reg->mailbox1);
4912 *wptr = RD_REG_WORD(&reg->mailbox2);
4913 if (mailbox[0] != MBA_SCSI_COMPLETION)
4915 wptr++;
4916 *wptr++ = RD_REG_WORD(&reg->mailbox3);
4917 *wptr++ = RD_REG_WORD(&reg->mailbox4);
4918 wptr++;
4919 *wptr++ = RD_REG_WORD(&reg->mailbox6);
4920 *wptr = RD_REG_WORD(&reg->mailbox7);
4923 /* Release mailbox registers. */
4925 WRT_REG_WORD(&reg->semaphore, 0);
4926 WRT_REG_WORD(&reg->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");
4932 #endif
4934 /* Handle asynchronous event */
4936 switch (mailbox[0])
4938 case MBA_SCSI_COMPLETION: /* Response completion */
4939 #ifdef QL_DEBUG_LEVEL_5
4940 qla1280_print("qla1280_isr: mailbox response completion\n\r");
4941 #endif
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];
4950 else
4951 sp = 0;
4953 if (sp)
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 */
4962 sp->s_next = NULL;
4963 sp->s_prev = *done_q_last;
4964 if (!*done_q_first)
4965 *done_q_first = sp;
4966 else
4967 (*done_q_last)->s_next = sp;
4968 *done_q_last = sp;
4970 else
4972 #ifdef QL_DEBUG_LEVEL_2
4973 qla1280_print("qla1280_isr: ISP invalid handle\n\r");
4974 #endif
4975 printk(KERN_WARNING "qla1280: ISP invalid handle");
4976 ha->flags.isp_abort_needed = TRUE;
4979 break;
4980 case MBA_BUS_RESET: /* SCSI Bus Reset */
4981 #ifdef QL_DEBUG_LEVEL_2
4982 qla1280_print("qla1280_isr: asynchronous BUS_RESET\n\r");
4983 #endif
4984 ha->flags.reset_marker = TRUE;
4985 index = mailbox[6] & BIT_0;
4986 ha->bus_settings[index].reset_marker = TRUE;
4987 break;
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");
4997 #endif
4998 printk(KERN_WARNING
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;
5002 break;
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");
5006 #endif
5007 printk(KERN_WARNING "qla1280: ISP Request Transfer Error\n");
5008 ha->flags.isp_abort_needed = TRUE;
5009 break;
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");
5013 #endif
5014 printk(KERN_WARNING "qla1280: ISP Response Transfer Error\n");
5015 ha->flags.isp_abort_needed = TRUE;
5016 break;
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");
5020 #endif
5021 break;
5022 case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
5023 #ifdef QL_DEBUG_LEVEL_2
5024 qla1280_print("qla1280_isr: asynchronous TIMEOUT_RESET\n\r");
5025 #endif
5026 break;
5027 case MBA_DEVICE_RESET: /* Bus Device Reset */
5028 #ifdef QL_DEBUG_LEVEL_2
5029 qla1280_print(
5030 "qla1280_isr: asynchronous BUS_DEVICE_RESET\n\r");
5031 #endif
5032 ha->flags.reset_marker = TRUE;
5033 index = mailbox[6] & BIT_0;
5034 ha->bus_settings[index].reset_marker = TRUE;
5035 break;
5036 case MBA_BUS_MODE_CHANGE:
5037 #ifdef QL_DEBUG_LEVEL_2
5038 qla1280_print(
5039 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n\r");
5040 #endif
5041 break;
5042 default:
5043 if (mailbox[0] < MBA_ASYNC_EVENT)
5045 wptr = &mailbox[0];
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;
5056 break;
5059 else
5060 WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
5063 * Response ring
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);
5080 #endif
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 ||
5086 pkt->entry_status)
5088 DEBUG(qla1280_print("qla1280_isr: ha->rsp_ring_index = ");)
5089 DEBUG(qla1280_output_number((uint32_t)ha->rsp_ring_index,
5090 16);)
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");)
5099 /* qla1280_print(
5100 "\n\rqla1280_isr: response packet data\n\r");
5101 qla1280_dump_buffer((caddr_t)pkt,
5102 RESPONSE_ENTRY_SIZE); */
5105 else
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);
5111 qla1280_print(
5112 "\n\rqla1280_isr: response packet data\n\r");
5113 qla1280_dump_buffer((caddr_t)pkt, RESPONSE_ENTRY_SIZE);
5115 #endif
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);
5121 else
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;
5132 else
5133 ha->response_ring_ptr++;
5134 WRT_REG_WORD(&reg->mailbox5, ha->rsp_ring_index);
5136 #if QLA1280_TARGET_MODE_SUPPORT
5137 else
5139 pkt = &response_entry;
5141 /* Copy packet. */
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;
5154 else
5155 ha->response_ring_ptr++;
5156 WRT_REG_WORD(&reg->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);
5165 break;
5166 case IMMED_NOTIFY_TYPE:
5167 qla1280_notify_entry(ha, (notify_entry_t *)pkt);
5168 break;
5169 case CTIO_RET_TYPE:
5170 qla1280_accept_io(ha, (ctio_ret_entry_t *)pkt);
5171 break;
5172 default:
5173 break;
5176 /* Acquire interrupt specific lock */
5177 QLA1280_INTR_LOCK(ha);
5179 #endif
5182 else
5184 ha->flags.isp_abort_needed = TRUE;
5185 #ifdef QL_DEBUG_LEVEL_2
5186 qla1280_print("qla1280_isr: Response pointer Error\n");
5187 #endif
5191 LEAVE("qla1280_isr");
5195 * qla1280_rst_aen
5196 * Processes asynchronous reset.
5198 * Input:
5199 * ha = adapter block pointer.
5201 STATIC void
5202 qla1280_rst_aen(scsi_qla_host_t *ha)
5204 #if QL1280_TARGET_MODE_SUPPORT
5205 notify_entry_t nentry;
5206 #endif
5207 uint8_t b;
5209 #ifdef QL_DEBUG_LEVEL_3
5210 ENTER("qla1280_rst_aen");
5211 #endif
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);
5238 #endif
5240 /* Asynchronous event notification */
5247 #ifdef QL_DEBUG_LEVEL_3
5248 LEAVE("qla1280_rst_aen");
5249 #endif
5252 #if QL1280_TARGET_MODE_SUPPORT
5254 * qla1280_atio_entry
5255 * Processes received ISP accept target I/O entry.
5257 * Input:
5258 * ha = adapter block pointer.
5259 * pkt = entry pointer.
5261 STATIC void
5262 qla1280_atio_entry(scsi_qla_host_t *ha, atio_entry_t *pkt)
5264 uint64_t *a64;
5265 uint64_t *end_a64;
5266 paddr32_t phy_addr[2];
5267 paddr32_t end_addr[2];
5268 uint32_t len;
5269 uint32_t offset;
5270 uint8_t t;
5271 uint8_t *sense_ptr;
5273 #ifdef QL_DEBUG_LEVEL_3
5274 qla1280_print("qla1280_atio_entry: entered\n\r");
5275 #endif
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");
5287 #endif
5288 break;
5289 case 0x14: /* Target Bus Phase Sequence Failure */
5290 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5291 qla1280_print(
5292 "qla1280_atio_entry: Target Bus Phase Sequence Failure\n\r");
5293 #endif
5294 if (pkt->status & BIT_7)
5296 BCOPY((caddr_t)&pkt->sense_data, sense_ptr,TARGET_SENSE_SIZE);
5298 else
5300 bzero(sense_ptr, TARGET_SENSE_SIZE);
5301 *sense_ptr = 0x70;
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);
5310 else
5311 qla1280_32bit_continue_io(ha, pkt, 0, 0);
5312 break;
5313 case 0x16: /* Requested Capability Not Available */
5314 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5315 qla1280_print(
5316 "qla1280_atio_entry: Target Bus Phase Sequence Failure\n\r");
5317 #endif
5318 break;
5319 case 0x17: /* Bus Device Reset Message Received */
5320 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5321 qla1280_print(
5322 "qla1280_atio_entry: Target Bus Phase Sequence Failure\n\r");
5323 #endif
5324 break;
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])
5334 case SS_TEST:
5335 #ifdef QL_DEBUG_LEVEL_3
5336 qla1280_print("qla1280_atio_entry: SS_TEST\n\r");
5337 #endif
5338 bzero(sense_ptr, TARGET_SENSE_SIZE);
5339 len = 0;
5340 if (pkt->lun == 0)
5341 pkt->scsi_status = S_GOOD;
5342 else
5344 *sense_ptr = 0x70;
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;
5353 break;
5354 case SS_REQSEN:
5355 #ifdef QL_DEBUG_LEVEL_3
5356 qla1280_print("qla1280_atio_entry: SS_REQSEN\n\r");
5357 #endif
5358 phy_addr[0] = ha->tsense_dma;
5359 phy_addr[1] = 0;
5360 *a64 += t * TARGET_SENSE_SIZE;
5361 if (pkt->cdb[4] > TARGET_SENSE_SIZE)
5362 len = TARGET_SENSE_SIZE;
5363 else
5364 len = pkt->cdb[4];
5365 pkt->scsi_status = S_GOOD;
5366 pkt->option_flags |= (uint32_t)OF_SSTS |
5367 (uint32_t)OF_DATA_IN;
5368 break;
5369 case SS_INQUIR:
5370 #ifdef QL_DEBUG_LEVEL_3
5371 qla1280_print("qla1280_atio_entry: SS_INQUIR\n\r");
5372 #endif
5373 bzero(sense_ptr, TARGET_SENSE_SIZE);
5374 phy_addr[0] = ha->tbuf_dma;
5375 phy_addr[1] = 0;
5376 *a64 += TARGET_INQ_OFFSET;
5378 if (pkt->lun == 0)
5380 ha->tbuf->inq.id_type = ID_PROCESOR;
5381 ha->tbuf->inq.id_pqual = ID_QOK;
5383 else
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);
5391 else
5392 len = pkt->cdb[4];
5393 pkt->scsi_status = S_GOOD;
5394 pkt->option_flags |= (uint32_t)OF_SSTS |
5395 (uint32_t)OF_DATA_IN;
5396 break;
5397 case SM_WRDB:
5398 bzero(sense_ptr, TARGET_SENSE_SIZE);
5399 offset = pkt->cdb[5];
5400 offset |= pkt->cdb[4] << 8;
5401 offset |= pkt->cdb[3] << 16;
5402 len = pkt->cdb[8];
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)
5410 case RW_BUF_HDATA:
5411 #ifdef QL_DEBUG_LEVEL_3
5412 qla1280_print("qla1280_atio_entry: SM_WRDB, RW_BUF_HDATA\n\r");
5413 #endif
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");
5418 #endif
5419 *sense_ptr = 0x70;
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;
5426 len = 0;
5428 else if (len)
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");
5435 #endif
5436 sdi_xaen(SDI_TARMOD_WRCOMP, ha->cntlr,
5437 pkt->target_id, pkt->lun, 0, offset);
5439 else
5441 #ifdef QL_DEBUG_LEVEL_2
5442 qla1280_print("qla1280_atio_entry: SM_WRDB, zero length\n\r");
5443 #endif
5444 pkt->scsi_status = S_GOOD;
5445 pkt->option_flags |= (uint32_t)OF_SSTS |
5446 (uint32_t)OF_NO_DATA;
5449 break;
5450 case RW_BUF_DATA:
5451 #ifdef QL_DEBUG_LEVEL_3
5452 qla1280_print("qla1280_atio_entry: SM_WRDB, RW_BUF_DATA\n\r");
5453 #endif
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");
5467 #endif
5468 *sense_ptr = 0x70;
5469 *(sense_ptr+2) = SD_ILLREQ;
5470 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5471 *(sense_ptr+12) = SC_ILLCDB;
5472 len = 0;
5473 pkt->scsi_status = S_CKCON;
5474 pkt->option_flags |= (uint32_t)OF_SSTS |
5475 (uint32_t)OF_NO_DATA;
5477 else if (len)
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");
5484 #endif
5485 sdi_xaen(SDI_TARMOD_WRCOMP, ha->cntlr,
5486 pkt->target_id, pkt->lun, 0, offset);
5488 else
5490 #ifdef QL_DEBUG_LEVEL_2
5491 qla1280_print("qla1280_atio_entry: SM_WRDB, zero length\n\r");
5492 #endif
5493 pkt->scsi_status = S_GOOD;
5494 pkt->option_flags |= (uint32_t)OF_SSTS |
5495 (uint32_t)OF_NO_DATA;
5497 break;
5498 default:
5499 #ifdef QL_DEBUG_LEVEL_2
5500 qla1280_print("qla1280_atio_entry: SM_WRDB unknown mode\n\r");
5501 #endif
5502 *sense_ptr = 0x70;
5503 *(sense_ptr+2) = SD_ILLREQ;
5504 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5505 *(sense_ptr+12) = SC_ILLCDB;
5506 len = 0;
5507 pkt->scsi_status = S_CKCON;
5508 pkt->option_flags |= (uint32_t)OF_SSTS |
5509 (uint32_t)OF_NO_DATA;
5510 break;
5512 break;
5513 case SM_RDDB:
5514 bzero(sense_ptr, TARGET_SENSE_SIZE);
5515 offset = pkt->cdb[5];
5516 offset |= pkt->cdb[4] << 8;
5517 offset |= pkt->cdb[3] << 16;
5518 len = pkt->cdb[8];
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)
5526 case RW_BUF_HDATA:
5527 #ifdef QL_DEBUG_LEVEL_3
5528 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_HDATA\n\r");
5529 #endif
5530 if (len)
5532 ha->tbuf->hdr[0] = 0;
5533 ha->tbuf->hdr[1] =
5534 (uint8_t)(TARGET_DATA_SIZE >> 16);
5535 ha->tbuf->hdr[2] =
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;
5544 else
5546 #ifdef QL_DEBUG_LEVEL_2
5547 qla1280_print("qla1280_atio_entry: SM_RDDB, zero length\n\r");
5548 #endif
5549 pkt->scsi_status = S_GOOD;
5550 pkt->option_flags |= (uint32_t)OF_SSTS |
5551 (uint32_t)OF_NO_DATA;
5553 break;
5554 case RW_BUF_DATA:
5555 #ifdef QL_DEBUG_LEVEL_3
5556 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_DATA\n\r");
5557 #endif
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");
5568 #endif
5569 *sense_ptr = 0x70;
5570 *(sense_ptr+2) = SD_ILLREQ;
5571 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5572 *(sense_ptr+12) = SC_ILLCDB;
5573 len = 0;
5574 pkt->scsi_status = S_CKCON;
5575 pkt->option_flags |= (uint32_t)OF_SSTS |
5576 (uint32_t)OF_NO_DATA;
5578 else
5580 if (*a64 + len > *end_a64)
5581 len = *end_a64 - *a64;
5582 if (len)
5584 pkt->scsi_status = S_GOOD;
5585 pkt->option_flags |= (uint32_t)OF_SSTS |
5586 (uint32_t)OF_DATA_IN;
5588 else
5590 #ifdef QL_DEBUG_LEVEL_2
5591 qla1280_print("qla1280_atio_entry: SM_RDDB, zero length\n\r");
5592 #endif
5593 pkt->scsi_status = S_GOOD;
5594 pkt->option_flags |= (uint32_t)OF_SSTS |
5595 (uint32_t)OF_NO_DATA;
5598 break;
5599 case RW_BUF_DESC:
5600 #ifdef QL_DEBUG_LEVEL_3
5601 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_DESC\n\r");
5602 #endif
5603 if (len)
5605 if (len > 4)
5606 len = 4;
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;
5615 else
5617 ha->tbuf->hdr[1] =
5618 (uint8_t)(TARGET_DATA_SIZE >> 16);
5619 ha->tbuf->hdr[2] =
5620 (uint8_t)(TARGET_DATA_SIZE >> 8);
5621 ha->tbuf->hdr[3] =
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;
5628 else
5630 #ifdef QL_DEBUG_LEVEL_2
5631 qla1280_print("qla1280_atio_entry: SM_RDDB, zero length\n\r");
5632 #endif
5633 pkt->scsi_status = S_GOOD;
5634 pkt->option_flags |= (uint32_t)OF_SSTS |
5635 (uint32_t)OF_NO_DATA;
5637 break;
5638 default:
5639 #ifdef QL_DEBUG_LEVEL_2
5640 qla1280_print("qla1280_atio_entry: SM_RDDB unknown mode\n\r");
5641 #endif
5642 *sense_ptr = 0x70;
5643 *(sense_ptr+2) = SD_ILLREQ;
5644 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5645 *(sense_ptr+12) = SC_ILLCDB;
5646 len = 0;
5647 pkt->scsi_status = S_CKCON;
5648 pkt->option_flags |= (uint32_t)OF_SSTS |
5649 (uint32_t)OF_NO_DATA;
5650 break;
5652 break;
5653 default:
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);
5657 #endif
5658 bzero(sense_ptr, TARGET_SENSE_SIZE);
5659 *sense_ptr = 0x70;
5660 *(sense_ptr+2) = SD_ILLREQ;
5661 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5662 *(sense_ptr+12) = SC_INVOPCODE;
5663 len = 0;
5664 pkt->scsi_status = S_CKCON;
5665 pkt->option_flags |= (uint32_t)OF_SSTS |
5666 (uint32_t)OF_NO_DATA;
5667 break;
5669 if (ha->flags.enable_64bit_addressing)
5670 qla1280_64bit_continue_io(ha, pkt, len, (paddr32_t *)&phy_addr);
5671 else
5672 qla1280_32bit_continue_io(ha, pkt, len, (paddr32_t *)&phy_addr);
5673 break;
5674 default:
5675 break;
5678 #ifdef QL_DEBUG_LEVEL_3
5679 qla1280_print("qla1280_atio_entry: exiting normally\n\r");
5680 #endif
5684 * qla1280_notify_entry
5685 * Processes received ISP immediate notify entry.
5687 * Input:
5688 * ha = adapter block pointer.
5689 * pkt = entry pointer.
5691 STATIC void
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");
5696 #endif
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");
5706 #endif
5709 #endif /* QLA1280_TARGET_MODE_SUPPORT */
5711 * qla1280_status_entry
5712 * Processes received ISP status entry.
5714 * Input:
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.
5720 STATIC void
5721 qla1280_status_entry(scsi_qla_host_t *ha, sts_entry_t *pkt, srb_t **done_q_first,
5722 srb_t **done_q_last)
5724 uint32_t b, t, l;
5725 uint8_t sense_sz = 0;
5726 srb_t *sp;
5727 scsi_lu_t *q;
5728 Scsi_Cmnd *cp;
5730 #ifdef QL_DEBUG_LEVEL_3
5731 ENTER("qla1280_status_entry");
5732 #endif
5734 /* Validate handle. */
5735 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
5736 sp = ha->outstanding_cmds[pkt->handle];
5737 else
5738 sp = 0;
5740 if (sp)
5742 /* Free outstanding command slot. */
5743 ha->outstanding_cmds[pkt->handle] = 0;
5745 cp = sp->cmd;
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");)
5764 /* Target busy */
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);
5771 else
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;
5784 else
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);)
5801 #endif
5804 /* Place command on done queue. */
5805 qla1280_done_q_put(sp, done_q_first, done_q_last);
5807 else
5809 #ifdef QL_DEBUG_LEVEL_2
5810 qla1280_print("qla1280_status_entry: ISP Invalid handle\n\r");
5811 #endif
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");
5817 #endif
5821 * qla1280_error_entry
5822 * Processes error entry.
5824 * Input:
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.
5830 STATIC void
5831 qla1280_error_entry(scsi_qla_host_t *ha, response_t *pkt, srb_t **done_q_first,
5832 srb_t **done_q_last)
5834 srb_t *sp;
5836 #ifdef QL_DEBUG_LEVEL_3
5837 ENTER("qla1280_error_entry");
5838 #endif
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");
5847 else
5848 qla1280_print("qla1280_error_entry: UNKNOWN flag error\n\r");
5849 #endif
5851 /* Validate handle. */
5852 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
5853 sp = ha->outstanding_cmds[pkt->handle];
5854 else
5855 sp = 0;
5857 if (sp)
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;
5873 else
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");
5886 #endif
5887 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
5888 ha->flags.isp_abort_needed = TRUE;
5890 #endif
5892 #ifdef QL_DEBUG_LEVEL_3
5893 LEAVE("qla1280_error_entry");
5894 #endif
5898 * qla1280_abort_isp
5899 * Resets ISP and aborts all outstanding commands.
5901 * Input:
5902 * ha = adapter block pointer.
5904 * Returns:
5905 * 0 = success
5907 STATIC uint8_t
5908 qla1280_abort_isp(scsi_qla_host_t *ha)
5910 device_reg_t *reg = ha->iobase;
5911 uint8_t status = 0;
5912 uint16_t cnt;
5913 srb_t *sp;
5914 scsi_lu_t *q;
5915 uint32_t b, t, l;
5916 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
5917 unsigned long cpu_flags = 0;
5918 #endif
5920 #ifdef QL_DEBUG_LEVEL_3
5921 ENTER("qla1280_abort_isp");
5922 #endif
5924 DRIVER_LOCK
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(&reg->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];
5937 if (sp)
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. */
5949 q->q_outcnt = 0;
5950 q->q_flag &= ~QLA1280_QBUSY;
5951 q->q_flag = 0;
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); */
5959 sp->flags = 0;
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);
5971 if (!status)
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); */
6002 qla1280_poll(ha);
6005 else
6006 break;
6009 if (!status)
6011 /* Enable ISP interrupts. */
6012 WRT_REG_WORD(&reg->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);
6021 if (status)
6023 printk(KERN_WARNING
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");
6030 #endif
6032 #ifdef QL_DEBUG_LEVEL_3
6033 else
6034 LEAVE("qla1280_abort_isp");
6035 #endif
6036 DRIVER_UNLOCK
6038 return(status);
6042 * qla1280_restart_queues
6043 * Restart all device queues.
6045 * Input:
6046 * ha = adapter block pointer.
6048 STATIC void
6049 qla1280_restart_queues(scsi_qla_host_t *ha)
6051 scsi_lu_t *q;
6052 uint32_t b, t, l;
6054 #ifdef QL_DEBUG_LEVEL_3
6055 ENTER("qla1280_restart_queues");
6056 #endif
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);
6063 if (q != NULL)
6065 /* Acquire LU queue specific lock */
6066 QLA1280_SCSILU_LOCK(q);
6068 if (q->q_first)
6069 qla1280_next(ha, q, b);
6070 else
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");
6077 #endif
6081 * qla1280_abort_queue_single
6082 * Abort all commands on a device queues.
6084 * Input:
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)
6089 scsi_lu_t *q;
6090 srb_t *sp, *sp_next;
6092 ENTER("qla1280_abort_queue_single");
6093 q = (scsi_lu_t * )LU_Q(ha, b, t, l);
6094 if (q != NULL)
6096 /* Acquire LU queue specific lock */
6097 QLA1280_SCSILU_LOCK(q);
6099 sp = q->q_first;
6100 q->q_first = q->q_last = NULL;
6102 QLA1280_SCSILU_UNLOCK(q);
6104 while (sp)
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);
6109 sp = sp_next;
6112 LEAVE("qla1280_abort_queue_single");
6116 * qla1280_abort_queues
6117 * Abort all commands on device queues.
6119 * Input:
6120 * ha = adapter block pointer.
6122 STATIC void
6123 qla1280_abort_queues(scsi_qla_host_t *ha)
6125 uint32_t b, t, l;
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.
6141 * Input:
6142 * port = register address.
6144 * Returns:
6145 * register value.
6147 STATIC uint16_t
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);
6159 return(ret);
6164 * Declarations for load module
6166 #ifdef MODULE
6167 Scsi_Host_Template driver_template = QLA1280_LINUX_TEMPLATE;
6169 #include "scsi_module.c"
6170 #endif
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;
6183 uint32_t b;
6184 Scsi_Cmnd *cp;
6187 * If SCSI Bus is Dead because of bad termination,
6188 * we will return a status of Selection timeout.
6191 cp = sp->cmd;
6192 b = SCSI_BUS_32(cp);
6193 if (ha->bus_settings[b].scsi_bus_dead)
6195 WRT_REG_WORD(&reg->host_cmd, HC_PAUSE_RISC);
6196 config_reg = RD_REG_WORD(&reg->cfg_1);
6197 WRT_REG_WORD(&reg->cfg_1,SET_SXP_BANK);
6198 scsi_control = RD_REG_WORD(&reg->scsiControlPins);
6199 WRT_REG_WORD(&reg->cfg_1,config_reg);
6200 WRT_REG_WORD(&reg->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)
6208 sti();
6209 (*(cp)->scsi_done)(cp);
6210 cli();
6211 #else
6212 (*(cp)->scsi_done)(cp);
6213 #endif
6214 return(TRUE); /* bus is dead */
6216 else
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 */
6225 STATIC uint8_t
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);
6233 mb[1] <<= 8;
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]) ) ;
6246 STATIC void
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);
6253 mb[1] <<= 8;
6254 qla1280_mailbox_command(ha, BIT_6|BIT_3|BIT_2|BIT_1|BIT_0, &mb[0]);
6255 if( mb[3] != 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
6273 STATIC uint8_t
6274 qla1280_getbyte(uint8_t *port)
6276 uint8_t ret;
6278 #if MEMORY_MAPPED_IO
6279 ret = *port;
6280 #else
6281 ret = inb((int)port);
6282 #endif
6284 if (ql_debug_print)
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");
6293 return(ret);
6297 * Get word from I/O port
6299 STATIC uint16_t
6300 qla1280_getword(uint16_t *port)
6302 uint16_t ret;
6304 #if MEMORY_MAPPED_IO
6305 ret = *port;
6306 #else
6307 ret = inw((int)port);
6308 #endif
6310 if (ql_debug_print)
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");
6319 return(ret);
6323 * Get double word from I/O port
6325 STATIC uint32_t
6326 qla1280_getdword(uint32_t *port)
6328 uint32_t ret;
6330 #if MEMORY_MAPPED_IO
6331 ret = *port;
6332 #else
6333 ret = inl((int)port);
6334 #endif
6336 if (ql_debug_print)
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");
6345 return(ret);
6349 * Send byte to I/O port
6351 STATIC void
6352 qla1280_putbyte(uint8_t *port, uint8_t data)
6354 #if MEMORY_MAPPED_IO
6355 *port = data;
6356 #else
6357 outb(data, (int)port);
6358 #endif
6360 if (ql_debug_print)
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
6373 STATIC void
6374 qla1280_putword(uint16_t *port, uint16_t data)
6376 #if MEMORY_MAPPED_IO
6377 *port = data;
6378 #else
6379 #ifdef _LINUX_IOPORTS
6380 outw(data, (int)port);
6381 #else
6382 outw((int)port, data);
6383 #endif
6384 #endif
6386 if (ql_debug_print)
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
6399 STATIC void
6400 qla1280_putdword(uint32_t *port, uint32_t data)
6402 #if MEMORY_MAPPED_IO
6403 *port = data;
6404 #else
6405 #ifdef _LINUX_IOPORTS
6406 outl(data,(int)port);
6407 #else
6408 outl((int)port, data);
6409 #endif
6410 #endif
6412 if (ql_debug_print)
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
6426 void
6427 qla1280_debug(void)
6429 qla1280_getbyte(0);
6430 qla1280_getword(0);
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,
6440 * or COM1 = 0x3F8
6442 #define OUTB(addr,data) outb((data),(addr))
6444 STATIC void
6445 qla1280_putc(uint8_t c)
6447 #ifdef QL_DEBUG_CONSOLE
6448 printk("%c", c);
6449 #else
6450 int com_addr = 0x2f8;
6451 int hardware_flow_control = 1;
6452 int software_flow_control = 0;
6453 uint8_t data;
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 */
6482 OUTB(com_addr+4,3);
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);
6496 if (data & BIT_0)
6498 /* If XOFF */
6499 data = inb(com_addr);
6500 if (data == '\023')
6502 /* Wait for XON */
6505 /* Wait for char */
6508 data = inb(com_addr+5);
6509 }while (!(data & BIT_0));
6510 data = inb(com_addr);
6511 }while (data != '\021');
6516 /* Output character. */
6517 OUTB(com_addr, c);
6518 #endif
6522 * Out NULL terminated string to COM port.
6524 STATIC void
6525 qla1280_print(caddr_t s)
6527 if (ql_debug_print)
6529 #ifdef QL_DEBUG_CONSOLE
6530 printk("%s",s);
6531 #else
6532 /* Output string. */
6533 while (*s)
6534 qla1280_putc(*s++);
6535 #endif
6540 * Output long number to COM port.
6542 STATIC void
6543 qla1280_output_number(uint32_t n, uint8_t base)
6545 int8_t str[12];
6546 int8_t *s = &str[11];
6547 int8_t output = 0;
6548 int8_t hex = FALSE;
6550 if (ql_debug_print)
6552 if (base == 10 || base == 16)
6554 if (base == 16 && n > 9)
6555 hex = TRUE;
6557 *s = 0;
6560 s--;
6561 *s = n % base;
6562 if (*s > 9)
6563 *s += 55;
6564 else
6565 *s += '0';
6566 n /= base;
6567 }while (n);
6569 for (; *s; s++)
6571 if (*s != '0')
6572 output = 1;
6573 if (output)
6574 qla1280_putc(*s);
6576 if (!output)
6577 qla1280_putc(*--s);
6579 if (hex)
6580 qla1280_putc('h');
6585 STATIC void
6586 qla1280_dump_buffer(caddr_t b, uint32_t size)
6588 uint32_t cnt;
6589 uint8_t c;
6591 if (ql_debug_print)
6593 qla1280_print(
6594 " 0 1 2 3 4 5 6 7 8 9 Ah Bh Ch Dh Eh Fh\n\r");
6595 qla1280_print(
6596 "---------------------------------------------------------------\n\r");
6598 for (cnt = 0; cnt < size; )
6600 c = *b++;
6601 if (c < 16)
6602 qla1280_putc(' ');
6603 qla1280_output_number((uint32_t)c, 16);
6604 cnt++;
6605 if (!(cnt % 16))
6606 qla1280_print("\n\r");
6607 else if (c < 10)
6608 qla1280_print(" ");
6609 else
6610 qla1280_putc(' ');
6612 if (cnt % 16)
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;
6624 srb_t *sp;
6625 /* struct scatterlist *sg; */
6627 int i;
6628 ha = (scsi_qla_host_t *) host->hostdata;
6630 ql_debug_print = 1;
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)) );
6652 } */
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 **************************************************************************/
6667 void
6668 ql1280_dump_device(scsi_qla_host_t *ha)
6671 Scsi_Cmnd *cp;
6672 srb_t *sp;
6673 int i;
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 )
6678 continue;
6679 if( (cp = sp->cmd) == NULL )
6680 continue;
6681 qla1280_print_scsi_cmd(cp);
6685 #endif
6687 #ifdef QLA1280_UNUSED
6688 /**************************************************************************
6689 * ql1280_dump_regs
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));
6702 #endif
6706 #if STOP_ON_ERROR
6707 /**************************************************************************
6708 * ql1280_panic
6710 **************************************************************************/
6711 static void qla1280_panic(char *cp, struct Scsi_Host *host)
6713 scsi_qla_host_t *ha;
6714 long *fp;
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",
6723 ha->request_dma,
6724 ha->response_dma);
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);
6732 #endif
6733 sti();
6734 panic("Ooops");
6735 /* cli();
6736 for(;;)
6738 barrier();
6739 sti();
6743 #endif
6745 #ifdef QLA1280_UNUSED
6746 static void qla1280_set_flags(char * s)
6749 #endif
6751 /**************************************************************************
6752 * qla1280_setup
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 **************************************************************************/
6758 void
6759 qla1280_setup(char *s, int *dummy)
6761 char *end, *str, *cp;
6763 #ifdef QLA1280_UNUSED
6764 static struct
6766 const char *name;
6767 int siz;
6768 void (*func)();
6769 int arg;
6770 } options[] =
6772 { "dump_regs", 9, &qla1280_dump_regs, 0
6774 { "verbose", 7, &qla1280_set_flags, 0x1
6776 { "", 0, NULL, 0
6779 #endif
6781 printk("scsi: Processing Option str = %s\n", s);
6782 end = strchr(s, '\0');
6783 /* locate command */
6784 str = s;
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,' '))
6801 ++cp;
6802 /* symbol starts here */
6803 str = cp;
6804 /* skip char if not a space or : */
6805 while (*cp && !( strchr(cp,' ') || strchr(cp,':')) )
6806 cp++;
6807 *cp = '\0';
6808 return( 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
6815 * of the file.
6816 * ---------------------------------------------------------------------------
6817 * Local variables:
6818 * c-indent-level: 2
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
6826 * tab-width: 8
6827 * End: