- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / scsi / qla1280.c
blob50db38c9742af234656c24f0388d18b75fc66609
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 static 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);
1086 schedule_task(&ha->run_qla_bh);
1087 ha->flags.dpc_sched = TRUE;
1088 DRIVER_UNLOCK
1089 return(0);
1092 /* Set an invalid handle until we issue the command to ISP */
1093 /* then we will set the real handle value. */
1094 handle = INVALID_HANDLE;
1095 CMD_HANDLE(cmd) = (unsigned char *)handle;
1097 /* Bookkeeping information */
1098 sp->r_start = jiffies; /* time the request was recieved */
1099 sp->u_start = 0;
1101 /* add the command to our queue */
1102 ha->qthreads++;
1103 qla1280_putq_t(q,sp);
1105 DEBUG(sprintf(debug_buff,"qla1280_queuecmd: queue pid=%d, hndl=0x%x\n\r",cmd->pid,handle));
1106 DEBUG(qla1280_print(debug_buff));
1108 /* send command to adapter */
1109 DRIVER_LOCK
1110 if (q->q_outcnt == 0)
1111 qla1280_restart_queues(ha);
1112 DRIVER_UNLOCK
1115 LEAVE("qla1280_queuecommand");
1116 return (0);
1119 /**************************************************************************
1120 * qla1200_abort
1121 * Abort the speciifed SCSI command(s).
1122 **************************************************************************/
1124 qla1280_abort(Scsi_Cmnd *cmd)
1126 scsi_qla_host_t *ha;
1127 srb_t *sp;
1128 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1129 unsigned long cpu_flags = 0;
1130 #endif
1131 struct Scsi_Host *host;
1132 uint32_t b, t, l;
1133 scsi_lu_t *q;
1134 int return_status = SCSI_ABORT_SUCCESS;
1135 int found = 0;
1136 int i;
1137 u_long handle;
1138 u_short data;
1140 ENTER("qla1280_abort");
1141 COMTRACE('A')
1142 ha = (scsi_qla_host_t *) cmd->host->hostdata;
1143 host = cmd->host;
1144 DRIVER_LOCK
1146 /* Get the SCSI request ptr */
1147 sp = (srb_t *) CMD_SP(cmd);
1148 handle = (u_long) CMD_HANDLE(cmd);
1149 if (qla1280_verbose)
1150 printk("scsi(%d): ABORT Command=0x%lx, handle=0x%lx\n",(int)ha->host_no,(long)cmd,handle);
1152 /* Check for pending interrupts. */
1153 if( handle == 0L )
1155 COMTRACE('a')
1156 /* we never got this command */
1157 printk(KERN_INFO "qla1280: Aborting a NULL handle\n");
1158 DRIVER_UNLOCK
1159 return(SCSI_ABORT_NOT_RUNNING); /* no action - we don't have command */
1161 data = qla1280_debounce_register(&ha->iobase->istatus);
1162 if( !(ha->flags.in_isr) && (data & RISC_INT) )
1164 /* put any pending command in done queue */
1165 qla1280_isr(ha, (srb_t **)&ha->done_q_first, (srb_t **)&ha->done_q_last);
1168 handle = (u_long) CMD_HANDLE(cmd);
1170 /* Generate LU queue on bus, target, LUN */
1171 b = SCSI_BUS_32(cmd);
1172 t = SCSI_TCN_32(cmd);
1173 l = SCSI_LUN_32(cmd);
1174 if((q = LU_Q(ha, b, t, l)) == NULL )
1176 COMTRACE('a')
1177 /* No lun queue -- command must not be active */
1178 DRIVER_UNLOCK
1179 printk(KERN_WARNING "qla1280 (%d:%d:%d): No LUN queue for the specified device\n",(int)b,(int)t,(int)l);
1180 return(SCSI_ABORT_NOT_RUNNING); /* no action - we don't have command */
1183 #if AUTO_ESCALATE_ABORT
1184 if ( (sp->flags & SRB_ABORTED) )
1186 DRIVER_UNLOCK
1187 DEBUG(qla1280_print("qla1280_abort: Abort escalayted - returning SCSI_ABORT_SNOOZE.\n\r"));
1188 return(SCSI_ABORT_SNOOZE);
1190 #endif
1192 if ( (sp->flags & SRB_ABORT_PENDING) )
1194 COMTRACE('a')
1195 DRIVER_UNLOCK
1196 if( qla1280_verbose )
1197 printk("scsi(): Command has a pending abort message - ABORT_PENDING.\n");
1198 DEBUG(qla1280_print("qla1280: Command has a pending abort message - ABORT_PENDING.\n\r"));
1199 return(SCSI_ABORT_PENDING);
1202 #if STOP_ON_ABORT
1203 printk("Scsi layer issued a ABORT command= 0x%x\n",(int)cmd);
1204 DEBUG2(qla1280_print_scsi_cmd(cmd));
1205 #endif
1207 ha->flags.in_abort = TRUE;
1209 * Normally, would would need to search our queue for the specified command
1210 * but; since our sp contains the cmd ptr, we can just remove it from our
1211 * LUN queue.
1213 if( !(sp->flags&SRB_SENT) )
1215 found++;
1216 if( qla1280_verbose )
1217 printk("scsi(): Command returned from queue aborted.\n");
1218 DEBUG(qla1280_print("qla1280: Command returned from queue aborted.\n\r"));
1219 /* Remove srb from SCSI LU queue. */
1220 qla1280_removeq(q, sp);
1221 sp->flags |= SRB_ABORTED;
1222 CMD_RESULT(cmd) = DID_ABORT << 16;
1223 qla1280_done_q_put(sp, &ha->done_q_first, &ha->done_q_last);
1224 return_status = SCSI_ABORT_SUCCESS;
1226 else
1227 { /* find the command in our active list */
1228 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++)
1230 if( sp == ha->outstanding_cmds[i] )
1232 found++;
1233 DEBUG(qla1280_print("qla1280: RISC aborting command.\n\r"));
1234 qla1280_abort_command(ha,sp);
1235 return_status = SCSI_ABORT_PENDING;
1236 break;
1241 #if STOP_ON_ABORT
1242 qla1280_panic("qla1280_abort",ha->host);
1243 #endif
1244 if ( found == 0 )
1245 return_status = SCSI_ABORT_NOT_RUNNING; /* no action - we don't have command */
1247 DEBUG(sprintf(debug_buff, "qla1280_abort: Aborted status returned = 0x%x.\n\r",return_status));
1248 DEBUG(qla1280_print(debug_buff));
1250 if( ha->done_q_first )
1251 qla1280_done(ha, (srb_t **)&ha->done_q_first, (srb_t **)&ha->done_q_last);
1252 if ( found )
1254 qla1280_restart_queues(ha);
1256 ha->flags.in_abort = FALSE;
1257 DRIVER_UNLOCK
1259 LEAVE("qla1280_abort");
1260 COMTRACE('a')
1261 return(return_status);
1264 /**************************************************************************
1265 * qla1200_reset
1266 * The reset function will reset the SCSI bus and abort any executing
1267 * commands.
1269 * Input:
1270 * cmd = Linux SCSI command packet of the command that cause the
1271 * bus reset.
1272 * flags = SCSI bus reset option flags (see scsi.h)
1274 * Returns:
1275 * DID_RESET in cmd.host_byte of aborted command(s)
1277 * Note:
1278 * Resetting the bus always succeeds - is has to, otherwise the
1279 * kernel will panic! Try a surgical technique - sending a BUS
1280 * DEVICE RESET message - on the offending target before pulling
1281 * the SCSI bus reset line.
1282 **************************************************************************/
1284 qla1280_reset(Scsi_Cmnd *cmd, unsigned int flags)
1286 scsi_qla_host_t *ha;
1287 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1288 unsigned long cpu_flags = 0;
1289 #endif
1290 uint32_t b, t, l;
1291 srb_t *sp;
1292 typedef enum
1294 ABORT_DEVICE = 1,
1295 DEVICE_RESET = 2,
1296 BUS_RESET = 3,
1297 ADAPTER_RESET= 4,
1298 RESET_DELAYED= 5,
1299 FAIL = 6
1300 } action_t;
1301 action_t action = ADAPTER_RESET;
1302 u_short data;
1303 scsi_lu_t *q;
1304 int result;
1307 ENTER("qla1280_reset");
1308 COMTRACE('R')
1309 if (qla1280_verbose)
1310 printk("scsi(): Resetting Cmnd=0x%lx, Handle=0x%lx, flags=0x%x\n",(long)cmd,(long)CMD_HANDLE(cmd),flags);
1311 if ( cmd == NULL )
1313 printk(KERN_WARNING "(scsi?:?:?:?) Reset called with NULL Scsi_Cmnd "
1314 "pointer, failing.\n");
1315 return(SCSI_RESET_SNOOZE);
1317 ha = (scsi_qla_host_t *) cmd->host->hostdata;
1318 sp = (srb_t *) CMD_SP(cmd);
1320 #if STOP_ON_RESET
1321 qla1280_panic("qla1280_reset",ha->host);
1322 #endif
1324 DRIVER_LOCK
1325 /* Check for pending interrupts. */
1326 data = qla1280_debounce_register(&ha->iobase->istatus);
1327 if( !(ha->flags.in_isr) && (data & RISC_INT) )
1329 qla1280_isr(ha, (srb_t **)&ha->done_q_first, (srb_t **)&ha->done_q_last);
1331 DRIVER_UNLOCK
1334 * Determine the suggested action that the mid-level driver wants
1335 * us to perform.
1337 if( CMD_HANDLE(cmd) == (unsigned char *) 0 )
1340 * if mid-level driver called reset with a orphan SCSI_Cmnd
1341 * (i.e. a command that's not pending ), so perform the
1342 * function specified.
1344 if( (flags & SCSI_RESET_SUGGEST_HOST_RESET) )
1345 action = ADAPTER_RESET;
1346 else
1347 action = BUS_RESET;
1349 else
1350 { /*
1351 * Mid-level driver has called reset with this SCSI_Cmnd and
1352 * its pending.
1354 if( flags & SCSI_RESET_SUGGEST_HOST_RESET )
1355 action = ADAPTER_RESET;
1356 else if( flags & SCSI_RESET_SUGGEST_BUS_RESET )
1357 action = BUS_RESET;
1358 else
1359 action = DEVICE_RESET;
1362 b = SCSI_BUS_32(cmd);
1363 t = SCSI_TCN_32(cmd);
1364 l = SCSI_LUN_32(cmd);
1365 q = LU_Q(ha, b, t, l);
1367 #if AUTO_ESCALATE_RESET
1368 if ( (action & DEVICE_RESET) && (q->q_flag & QLA1280_QRESET) )
1370 printk(KERN_INFO "qla1280(%d): Bus device reset already sent to " "device, escalating.\n", (int)ha->host_no);
1371 action = BUS_RESET;
1373 if ( (action & DEVICE_RESET) && (sp->flags & SRB_ABORT_PENDING) )
1375 printk(KERN_INFO "qla1280(%d):Have already attempted to reach " "device with abort device\n", (int)ha->host_no);
1376 printk(KERN_INFO "qla1280(%d):message, will escalate to BUS " "RESET.\n",(int) ha->host_no);
1377 action = BUS_RESET;
1379 #endif
1382 * By this point, we want to already know what we are going to do,
1383 * so we only need to perform the course of action.
1385 DRIVER_LOCK
1386 result = SCSI_RESET_ERROR;
1387 switch (action)
1389 case FAIL:
1390 break;
1392 case RESET_DELAYED:
1393 result = SCSI_RESET_PENDING;
1394 break;
1396 case ABORT_DEVICE:
1397 ha->flags.in_reset = TRUE;
1398 if (qla1280_verbose)
1399 printk(KERN_INFO "scsi(%d:%d:%d:%d): Queueing abort device command.\n", (int)ha->host_no,(int)b,(int)t,(int)l);
1400 qla1280_abort_queue_single(ha,b,t,l,DID_ABORT);
1401 if( qla1280_abort_device(ha, b, t, l) == 0)
1402 result = SCSI_RESET_PENDING;
1403 break;
1405 case DEVICE_RESET:
1406 if (qla1280_verbose)
1407 printk(KERN_INFO "scsi(%d:%d:%d:%d): Queueing device reset command.\n",(int) ha->host_no,(int)b,(int)t,(int)l);
1408 ha->flags.in_reset = TRUE;
1409 for (l = 0; l < MAX_LUNS; l++)
1410 qla1280_abort_queue_single(ha,b,t,l,DID_ABORT);
1411 if( qla1280_device_reset(ha, b, t) == 0 )
1412 result = SCSI_RESET_PENDING;
1413 q->q_flag |= QLA1280_QRESET;
1414 break;
1416 case BUS_RESET:
1417 if (qla1280_verbose)
1418 printk(KERN_INFO "qla1280(%d:%d:%d:%d): Issuing BUS DEVICE RESET.\n",(int) ha->host_no,(int)b,(int)t,(int)l);
1419 ha->flags.in_reset = TRUE;
1420 for (t = 0; t < MAX_TARGETS; t++)
1421 for (l = 0; l < MAX_LUNS; l++)
1422 qla1280_abort_queue_single(ha,b,t,l,DID_RESET);
1423 qla1280_bus_reset(ha, b);
1425 * The bus reset routine returns all the outstanding commands back
1426 * with "DID_RESET" in the status field after a short delay
1427 * by the firmware. If the mid-level time out the SCSI reset before
1428 * our delay we may need to ignore it.
1430 /* result = SCSI_RESET_PENDING | SCSI_RESET_BUS_RESET; */
1431 result = SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET;
1432 mdelay(4 * 1000); barrier();
1433 if( flags & SCSI_RESET_SYNCHRONOUS )
1435 CMD_RESULT(cmd) = (int) (DID_BUS_BUSY << 16);
1436 (*(cmd)->scsi_done)(cmd);
1438 /* ha->reset_start = jiffies; */
1439 break;
1441 case ADAPTER_RESET:
1442 default:
1443 if (qla1280_verbose)
1445 printk(KERN_INFO "scsi(%d:%d:%d:%d): Issued an ADAPTER RESET.\n",(int) ha->host_no,(int)b,(int)t,(int)l);
1446 printk(KERN_INFO "scsi(%d:%d:%d:%d): I/O processing will continue automatically.\n",(int) ha->host_no,(int)b,(int)t,(int)l);
1448 ha->flags.reset_active = TRUE;
1450 * We restarted all of the commands automatically, so the mid-level code can expect
1451 * completions momentitarily.
1453 if( qla1280_abort_isp(ha) == 0 )
1454 result = SCSI_RESET_SUCCESS | SCSI_RESET_HOST_RESET;
1456 ha->flags.reset_active = FALSE;
1459 if( ha->done_q_first )
1460 qla1280_done(ha, (srb_t **)&ha->done_q_first, (srb_t **)&ha->done_q_last);
1461 qla1280_restart_queues(ha);
1462 ha->flags.in_reset = FALSE;
1464 DRIVER_UNLOCK
1465 DEBUG(printk("RESET returning %d\n", result));
1467 COMTRACE('r')
1468 LEAVE("qla1280_reset");
1469 return( result );
1472 /**************************************************************************
1473 * qla1200_biosparam
1474 * Return the disk geometry for the given SCSI device.
1475 **************************************************************************/
1477 qla1280_biosparam(Disk *disk, kdev_t dev, int geom[])
1479 int heads, sectors, cylinders;
1481 heads = 64;
1482 sectors = 32;
1483 cylinders = disk->capacity / (heads * sectors);
1484 if (cylinders > 1024)
1486 heads = 255;
1487 sectors = 63;
1488 cylinders = disk->capacity / (heads * sectors);
1489 /* if (cylinders > 1023)
1490 cylinders = 1023; */
1493 geom[0] = heads;
1494 geom[1] = sectors;
1495 geom[2] = cylinders;
1497 return (0);
1499 /**************************************************************************
1500 * qla1280_intr_handler
1501 * Handles the H/W interrupt
1502 **************************************************************************/
1503 void qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1505 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,95)
1506 unsigned long cpu_flags = 0;
1507 #endif
1508 scsi_qla_host_t *ha;
1509 u_short data;
1510 device_reg_t *reg;
1512 ENTER_INTR("qla1280_intr_handler");
1513 COMTRACE('I')
1514 ha = (scsi_qla_host_t *) dev_id;
1515 if(!ha)
1517 printk(KERN_INFO "scsi(): Interrupt with NULL host ptr\n");
1518 COMTRACE('X')
1519 return;
1521 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,95)
1522 spin_lock_irqsave(&io_request_lock, cpu_flags);
1523 if(test_and_set_bit(QLA1280_IN_ISR_BIT, &ha->flags))
1525 COMTRACE('X')
1526 return;
1528 ha->isr_count++;
1529 reg = ha->iobase;
1530 /* disable our interrupt. */
1531 WRT_REG_WORD(&reg->ictrl, 0);
1532 data = qla1280_debounce_register(&reg->istatus);
1533 /* Check for pending interrupts. */
1534 if ( !(data & RISC_INT) )
1536 /* spurious interrupts can happen legally */
1537 DEBUG(printk("scsi(%d): Spurious interrupt - ignoring\n",(int)ha->host_no));
1538 COMTRACE('X')
1540 else
1541 qla1280_isr(ha, (srb_t **)&ha->done_q_first, (srb_t **)&ha->done_q_last);
1542 if (ha->done_q_first)
1543 qla1280_done(ha, (srb_t **)&ha->done_q_first, (srb_t **)&ha->done_q_last);
1545 clear_bit(QLA1280_IN_ISR_BIT, &ha->flags);
1546 spin_unlock_irqrestore(&io_request_lock, cpu_flags);
1547 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95) */
1549 if( test_bit(QLA1280_IN_ISR_BIT, (int *)&ha->flags) )
1551 COMTRACE('X')
1552 printk(KERN_INFO "scsi(%d): Already in interrupt - returning \n", (int)ha->host_no);
1553 return;
1555 set_bit(QLA1280_IN_ISR_BIT, (int *)&ha->flags);
1556 ha->isr_count++;
1557 reg = ha->iobase;
1558 /* disable our interrupt. */
1559 WRT_REG_WORD(&reg->ictrl, 0);
1561 data = qla1280_debounce_register(&reg->istatus);
1562 /* Check for pending interrupts. */
1563 if ( !(data & RISC_INT) )
1565 /* spurious interrupts can happen legally */
1566 DEBUG(printk("scsi(%d): Spurious interrupt - ignoring\n",(int)ha->host_no));
1567 COMTRACE('X')
1569 else
1570 qla1280_isr(ha, (srb_t **)&ha->done_q_first, (srb_t **)&ha->done_q_last);
1572 /* if no work to do then call the SCSI mid-level right away */
1573 if( ha->done_q_first )
1574 qla1280_done(ha, (srb_t **)&ha->done_q_first, (srb_t **)&ha->done_q_last);
1576 /* Schedule the DPC routine */
1577 if (ha->flags.isp_abort_needed || ha->flags.reset_marker ||
1578 ha->done_q_first )
1580 ha->run_qla_bh.data = (void *) ha;
1581 ha->run_qla_bh.routine = qla1280_do_dpc;
1583 COMTRACE('P')
1584 schedule_task(&ha->run_qla_bh);
1585 ha->flags.dpc_sched = TRUE;
1587 clear_bit(QLA1280_IN_ISR_BIT, (int *)&ha->flags);
1588 #endif
1589 /* enable our interrupt. */
1590 WRT_REG_WORD(&reg->ictrl, ISP_EN_INT + ISP_EN_RISC);
1592 COMTRACE('i')
1593 LEAVE_INTR("qla1280_intr_handler");
1596 /**************************************************************************
1597 * qla1280_do_dpc
1599 * Description:
1600 * This routine is a task that is schedule by the interrupt handler
1601 * to perform the background processing for interrupts. We put it
1602 * on a task queue that is consumed whenever the scheduler runs; that's
1603 * so you can do anything (i.e. put the process to sleep etc). In fact, the
1604 * mid-level tries to sleep when it reaches the driver threshold
1605 * "host->can_queue". This can cause a panic if we were in our interrupt
1606 * code .
1607 **************************************************************************/
1608 static void qla1280_do_dpc(void *p)
1610 scsi_qla_host_t *ha = (scsi_qla_host_t *) p;
1611 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
1612 unsigned long cpu_flags = 0;
1613 #endif
1615 COMTRACE('p')
1616 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
1617 spin_lock_irqsave(&io_request_lock, cpu_flags);
1618 #endif
1619 if (ha->flags.isp_abort_needed)
1620 qla1280_abort_isp(ha);
1622 if (ha->flags.reset_marker)
1623 qla1280_rst_aen(ha);
1625 if (ha->done_q_first)
1626 qla1280_done(ha, (srb_t **)&ha->done_q_first, (srb_t **)&ha->done_q_last);
1627 ha->flags.dpc_sched = FALSE;
1628 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,95)
1629 spin_unlock_irqrestore(&io_request_lock, cpu_flags);
1630 #endif
1633 /**************************************************************************
1634 * qla1280_device_queue_depth
1636 * Description:
1637 * Determines the queue depth for a given device. There are two ways
1638 * a queue depth can be obtained for a tagged queueing device. One
1639 * way is the default queue depth which is determined by whether
1640 * If it is defined, then it is used
1641 * as the default queue depth. Otherwise, we use either 4 or 8 as the
1642 * default queue depth (dependent on the number of hardware SCBs).
1643 **************************************************************************/
1644 STATIC void qla1280_device_queue_depth(scsi_qla_host_t *p, Scsi_Device *device)
1646 int default_depth = 3;
1647 int bus = device->channel;
1648 int target = device->id;
1650 device->queue_depth = default_depth;
1652 if (device->tagged_supported &&
1653 (p->bus_settings[bus].qtag_enables & (BIT_0 << target)) )
1655 device->tagged_queue = 1;
1656 device->current_tag = 0;
1657 device->queue_depth = p->bus_settings[bus].hiwat;
1658 /* device->queue_depth = 20; */
1659 printk(KERN_INFO "scsi(%d:%d:%d:%d): Enabled tagged queuing, queue depth %d.\n",
1660 (int)p->host_no, device->channel, device->id,
1661 device->lun, device->queue_depth);
1663 qla12160_get_target_parameters(p, bus, target, device->lun);
1667 /**************************************************************************
1668 * qla1280_select_queue_depth
1670 * Sets the queue depth for each SCSI device hanging off the input
1671 * host adapter. We use a queue depth of 2 for devices that do not
1672 * support tagged queueing.
1673 **************************************************************************/
1674 STATIC void
1675 qla1280_select_queue_depth(struct Scsi_Host *host, Scsi_Device *scsi_devs)
1677 Scsi_Device *device;
1678 scsi_qla_host_t *p = (scsi_qla_host_t *) host->hostdata;
1680 ENTER("qla1280_select_queue_depth");
1681 for (device = scsi_devs; device != NULL; device = device->next)
1683 if (device->host == host)
1684 qla1280_device_queue_depth(p, device);
1686 LEAVE("qla1280_select_queue_depth");
1689 /*--------------------------**
1690 ** Driver Support Routines **
1691 **--------------------------*/
1693 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
1695 * mdelay
1696 * Delay in milliseconds
1698 * Input:
1699 * milliseconds = delay
1701 STATIC inline void mdelay(int milliseconds)
1703 int i;
1705 for(i=0; i<milliseconds; i++)
1706 udelay(1000);
1708 #endif
1711 * qla1280_done
1712 * Process completed commands.
1714 * Input:
1715 * ha = adapter block pointer.
1716 * done_q_first = done queue first pointer.
1717 * done_q_last = done queue last pointer.
1719 STATIC void
1720 qla1280_done(scsi_qla_host_t *ha, srb_t **done_q_first, srb_t **done_q_last)
1722 srb_t *sp;
1723 scsi_lu_t *q;
1724 uint32_t b, t, l;
1725 Scsi_Cmnd *cmd;
1726 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1727 unsigned long cpu_flags = 0;
1728 #endif
1730 ENTER("qla1280_done");
1731 COMTRACE('D')
1733 DRIVER_LOCK
1734 while (*done_q_first != NULL)
1736 /* remove command from done list */
1737 sp = *done_q_first;
1738 if (!(*done_q_first = sp->s_next))
1739 *done_q_last = NULL;
1740 else
1741 (*done_q_first)->s_prev = NULL;
1742 cmd = sp->cmd;
1743 b = SCSI_BUS_32(cmd);
1744 t = SCSI_TCN_32(cmd);
1745 l = SCSI_LUN_32(cmd);
1746 q = LU_Q(ha, b, t, l);
1748 /* Decrement outstanding commands on device. */
1749 if (q->q_outcnt)
1750 q->q_outcnt--;
1751 if (q->q_outcnt < ha->bus_settings[b].hiwat)
1753 q->q_flag &= ~QLA1280_QBUSY;
1756 q->resp_time += jiffies - sp->r_start; /* Lun bookkeeping information */
1757 q->act_time += jiffies - sp->u_start;
1758 q->io_cnt++;
1759 if( sp->dir & BIT_5 )
1760 q->r_cnt++;
1761 else
1762 q->w_cnt++;
1764 switch ( (CMD_RESULT(cmd)>>16))
1766 case DID_RESET:
1767 q->q_flag &= ~QLA1280_QRESET;
1768 /* Issue marker command. */
1769 qla1280_marker(ha, b, t, 0, MK_SYNC_ID);
1770 break;
1771 case DID_ABORT:
1772 sp->flags &= ~SRB_ABORT_PENDING;
1773 sp->flags |= SRB_ABORTED;
1774 if (sp->flags & SRB_TIMEOUT)
1775 CMD_RESULT(sp->cmd)= DID_TIME_OUT << 16;
1776 break;
1777 default:
1778 break;
1781 /* Call the mid-level driver interrupt handler */
1782 CMD_HANDLE(sp->cmd) = (unsigned char *) 0;
1783 ha->actthreads--;
1784 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1785 sti();
1786 (*(cmd)->scsi_done)(cmd);
1787 cli();
1788 #else
1789 (*(cmd)->scsi_done)(cmd);
1790 #endif
1791 qla1280_next(ha, q, b);
1793 DRIVER_UNLOCK
1796 COMTRACE('d')
1797 LEAVE("qla1280_done");
1801 * Translates a ISP error to a Linux SCSI error
1803 STATIC int qla1280_return_status( sts_entry_t *sts, Scsi_Cmnd *cp)
1805 int host_status = DID_ERROR;
1806 #if DEBUG_QLA1280_INTR
1807 STATIC char *reason[] =
1809 "DID_OK",
1810 "DID_NO_CONNECT",
1811 "DID_BUS_BUSY",
1812 "DID_TIME_OUT",
1813 "DID_BAD_TARGET",
1814 "DID_ABORT",
1815 "DID_PARITY",
1816 "DID_ERROR",
1817 "DID_RESET",
1818 "DID_BAD_INTR"
1820 #endif /* DEBUG_QLA1280_INTR */
1822 ENTER("qla1280_return_status");
1824 #if DEBUG_QLA1280_INTR
1826 DEBUG(printk("qla1280_return_status: compl status = 0x%04x\n", sts->comp_status));
1828 #endif
1829 switch(sts->comp_status)
1831 case CS_COMPLETE:
1832 host_status = DID_OK;
1833 break;
1834 case CS_INCOMPLETE:
1835 if (!(sts->state_flags & SF_GOT_BUS))
1836 host_status = DID_NO_CONNECT;
1837 else if (!(sts->state_flags & SF_GOT_TARGET))
1838 host_status = DID_BAD_TARGET;
1839 else if (!(sts->state_flags & SF_SENT_CDB))
1840 host_status = DID_ERROR;
1841 else if (!(sts->state_flags & SF_TRANSFERRED_DATA))
1842 host_status = DID_ERROR;
1843 else if (!(sts->state_flags & SF_GOT_STATUS))
1844 host_status = DID_ERROR;
1845 else if (!(sts->state_flags & SF_GOT_SENSE))
1846 host_status = DID_ERROR;
1847 break;
1848 case CS_RESET:
1849 host_status = DID_RESET;
1850 break;
1851 case CS_ABORTED:
1852 host_status = DID_ABORT;
1853 break;
1854 case CS_TIMEOUT:
1855 host_status = DID_TIME_OUT;
1856 break;
1857 case CS_DATA_OVERRUN:
1858 #ifdef QL_DEBUG_LEVEL_2
1859 printk("Data overrun 0x%x\n",(int)sts->residual_length);
1860 qla1280_print(
1861 "\n\rqla1280_isr: response packet data\n\r");
1862 qla1280_dump_buffer((caddr_t)sts,
1863 RESPONSE_ENTRY_SIZE);
1864 #endif
1865 host_status = DID_ERROR;
1866 break;
1867 case CS_DATA_UNDERRUN:
1868 if ( (CMD_XFRLEN(cp) - sts->residual_length) < cp->underflow)
1870 printk("scsi: Underflow detected - retrying command.\n");
1871 host_status = DID_ERROR;
1873 else
1874 host_status = DID_OK;
1875 break;
1876 default:
1877 host_status = DID_ERROR;
1878 break;
1881 #if DEBUG_QLA1280_INTR
1882 sprintf(debug_buff, "qla1280 ISP status: host status (%s) scsi status %x\n\r", reason[host_status], sts->scsi_status);
1883 qla1280_print(debug_buff);
1884 #endif
1886 LEAVE("qla1280_return_status");
1888 return (sts->scsi_status & 0xff) | (host_status << 16);
1892 * qla1280_done_q_put
1893 * Place SRB command on done queue.
1895 * Input:
1896 * sp = srb pointer.
1897 * done_q_first = done queue first pointer.
1898 * done_q_last = done queue last pointer.
1900 STATIC void
1901 qla1280_done_q_put(srb_t *sp, srb_t **done_q_first, srb_t **done_q_last)
1903 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1904 unsigned long cpu_flags = 0;
1905 #endif
1906 #ifdef QL_DEBUG_LEVEL_3
1907 ENTER("qla1280_put_done_q");
1908 #endif
1909 /* Place block on done queue */
1910 DRIVER_LOCK
1911 sp->s_next = NULL;
1912 sp->s_prev = *done_q_last;
1913 if (!*done_q_first)
1914 *done_q_first = sp;
1915 else
1916 (*done_q_last)->s_next = sp;
1917 *done_q_last = sp;
1919 DRIVER_UNLOCK
1920 #ifdef QL_DEBUG_LEVEL_3
1921 LEAVE("qla1280_put_done_q");
1922 #endif
1926 * qla1280_next
1927 * Retrieve and process next job in the queue.
1929 * Input:
1930 * ha = adapter block pointer.
1931 * q = SCSI LU pointer.
1932 * b = SCSI bus number.
1933 * SCSI_LU_Q lock must be already obtained and no other locks.
1935 * Output:
1936 * Releases SCSI_LU_Q upon exit.
1938 STATIC void
1939 qla1280_next(scsi_qla_host_t *ha, scsi_lu_t *q, uint8_t b)
1941 srb_t *sp;
1942 uint32_t cnt;
1943 uint8_t status;
1944 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
1945 unsigned long cpu_flags = 0;
1946 #endif
1948 ENTER("qla1280_next");
1950 DRIVER_LOCK
1951 while ( ((sp = q->q_first) != NULL) && /* we have a queue pending */
1952 !(q->q_flag & QLA1280_QBUSY) && /* device not busy */
1953 !ha->flags.abort_isp_active && /* not resetting the adapter */
1954 !(q->q_flag & QLA1280_QSUSP) ) /* device not suspended */
1956 /* Remove srb from SCSI LU queue. */
1957 qla1280_removeq(q, sp);
1959 DEBUG(sprintf(debug_buff,"starting request 0x%p<-(0x%p)\n\r",q,sp));
1960 DEBUG(qla1280_print(debug_buff));
1962 /* Set busy flag if reached high water mark. */
1963 q->q_outcnt++;
1964 if (q->q_outcnt >= ha->bus_settings[b].hiwat)
1965 q->q_flag |= QLA1280_QBUSY;
1967 #if QLA1280_64BIT_SUPPORT
1968 if (ha->flags.enable_64bit_addressing)
1969 status = qla1280_64bit_start_scsi(ha, sp);
1970 else
1971 #endif
1972 status = qla1280_32bit_start_scsi(ha, sp);
1974 if (status) /* if couldn't start the request */
1976 if (q->q_outcnt == 1)
1978 /* Release SCSI LU queue specific lock */
1979 QLA1280_SCSILU_UNLOCK(q);
1981 /* Wait for 30 sec for command to be accepted. */
1982 for (cnt = 6000000; cnt; cnt--)
1984 #if QLA1280_64BIT_SUPPORT
1985 if (ha->flags.enable_64bit_addressing)
1986 status = qla1280_64bit_start_scsi(ha, sp);
1987 else
1988 #endif
1989 status = qla1280_32bit_start_scsi(ha, sp);
1991 if (!status)
1993 break;
1996 /* Go check for pending interrupts. */
1997 qla1280_poll(ha);
1999 SYS_DELAY(5); /* 10 */
2001 if (!cnt)
2003 /* Set timeout status */
2004 CMD_RESULT(sp->cmd) = DID_TIME_OUT << 16;
2006 #if WATCHDOGTIMER
2007 /* Remove command from watchdog queue. */
2008 if (sp->flags & SRB_WATCHDOG)
2009 qla1280_timeout_remove(ha, sp);
2010 #endif
2011 COMTRACE('M')
2012 CMD_HANDLE(sp->cmd) = (unsigned char *) 0;
2014 /* Call the mid-level driver interrupt handler */
2015 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2016 sti();
2017 (*(sp->cmd)->scsi_done)(sp->cmd);
2018 cli();
2019 #else
2020 (*(sp->cmd)->scsi_done)(sp->cmd);
2021 #endif
2023 /* Acquire LU queue specific lock */
2024 QLA1280_SCSILU_LOCK(q);
2026 if (q->q_outcnt)
2027 q->q_outcnt--;
2029 else
2030 /* Acquire LU queue specific lock */
2031 QLA1280_SCSILU_LOCK(q);
2033 else
2034 { /* Place request back on top of device queue. */
2035 qla1280_putq_t(q, sp);
2037 if (q->q_outcnt)
2038 q->q_outcnt--;
2039 if (q->q_outcnt < ha->bus_settings[b].hiwat)
2040 q->q_flag &= ~QLA1280_QBUSY;
2041 break;
2046 DRIVER_UNLOCK
2048 /* Release SCSI LU queue specific lock */
2049 QLA1280_SCSILU_UNLOCK(q);
2051 LEAVE("qla1280_next");
2055 * qla1280_putq_t
2056 * Add the standard SCB job to the top of standard SCB commands.
2058 * Input:
2059 * q = SCSI LU pointer.
2060 * sp = srb pointer.
2061 * SCSI_LU_Q lock must be already obtained.
2063 STATIC void
2064 qla1280_putq_t(scsi_lu_t *q, srb_t *sp)
2066 srb_t *srb_p;
2067 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2068 unsigned long cpu_flags = 0;
2069 #endif
2071 #ifdef QL_DEBUG_LEVEL_3
2072 ENTER("qla1280_putq_t");
2073 #endif
2074 DRIVER_LOCK
2075 DEBUG(sprintf(debug_buff,"Adding to device 0x%p<-(0x%p)\n\r",q,sp));
2076 DEBUG(qla1280_print(debug_buff));
2077 sp->s_next = NULL;
2078 if (!q->q_first) /* If queue empty */
2080 sp->s_prev = NULL;
2081 q->q_first = sp;
2082 q->q_last = sp;
2084 else
2086 srb_p = q->q_first;
2087 while (srb_p )
2088 srb_p = srb_p->s_next;
2090 if (srb_p)
2092 sp->s_prev = srb_p->s_prev;
2093 if (srb_p->s_prev)
2094 srb_p->s_prev->s_next = sp;
2095 else
2096 q->q_first = sp;
2097 srb_p->s_prev = sp;
2098 sp->s_next = srb_p;
2100 else
2102 sp->s_prev = q->q_last;
2103 q->q_last->s_next = sp;
2104 q->q_last = sp;
2108 DRIVER_UNLOCK
2109 #ifdef QL_DEBUG_LEVEL_3
2110 LEAVE("qla1280_putq_t");
2111 #endif
2115 * qla1280_removeq
2116 * Function used to remove a command block from the
2117 * LU queue.
2119 * Input:
2120 * q = SCSI LU pointer.
2121 * sp = srb pointer.
2122 * SCSI_LU_Q lock must be already obtained.
2124 STATIC void
2125 qla1280_removeq(scsi_lu_t *q, srb_t *sp)
2127 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
2128 unsigned long cpu_flags = 0;
2129 #endif
2130 DEBUG(sprintf(debug_buff,"Removing from device_q (0x%p)->(0x%p)\n\r",q,sp));
2131 DEBUG(qla1280_print(debug_buff));
2132 DRIVER_LOCK
2133 if (sp->s_prev)
2135 if ((sp->s_prev->s_next = sp->s_next) != NULL)
2136 sp->s_next->s_prev = sp->s_prev;
2137 else
2138 q->q_last = sp->s_prev;
2140 else if (!(q->q_first = sp->s_next))
2141 q->q_last = NULL;
2142 else
2143 q->q_first->s_prev = NULL;
2144 DRIVER_UNLOCK
2148 * qla1280_mem_alloc
2149 * Allocates adapter memory.
2151 * Returns:
2152 * 0 = success.
2153 * 1 = failure.
2155 STATIC uint8_t
2156 qla1280_mem_alloc(scsi_qla_host_t *ha)
2159 uint8_t status = 1;
2161 #ifdef QL_DEBUG_LEVEL_3
2162 ENTER("qla1280_mem_alloc");
2163 #endif
2165 #ifdef DYNAMIC_MEM_ALLOC
2166 ha->request_ring = qla1280_alloc_phys(REQUEST_ENTRY_SIZE * REQUEST_ENTRY_CNT,
2167 &ha->request_dma);
2168 if(ha->request_ring) {
2169 ha->response_ring = qla1280_alloc_phys(RESPONSE_ENTRY_SIZE * RESPONSE_ENTRY_CNT,
2170 &ha->response_dma);
2171 if(ha->response_ring) {
2172 status = 0;
2175 #else
2176 ha->request_ring = &ha->req[0];
2177 ha->request_dma = VIRT_TO_BUS(&ha->req[0]);
2178 ha->response_ring = &ha->res[0];
2179 ha->response_dma = VIRT_TO_BUS(&ha->res[0]);
2180 status = 0;
2181 #endif
2183 if(status) {
2184 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2185 qla1280_print("qla1280_mem_alloc: **** FAILED ****\n");
2186 #endif
2188 #ifdef QL_DEBUG_LEVEL_3
2189 else
2190 LEAVE("qla1280_mem_alloc");
2191 #endif
2192 return(status);
2196 * qla1280_mem_free
2197 * Frees adapter allocated memory.
2199 * Input:
2200 * ha = adapter block pointer.
2202 STATIC void
2203 qla1280_mem_free(scsi_qla_host_t *ha)
2205 scsi_lu_t *q;
2206 uint32_t b, t, l;
2208 ENTER("qlc1280_mem_free");
2209 if (ha)
2211 /* Free device queues. */
2212 for (b = 0; b < MAX_BUSES; b++)
2214 q = LU_Q(ha, b, ha->bus_settings[b].id, 0);
2215 for (t = 0; t < MAX_TARGETS; t++)
2216 for (l = 0; l < MAX_LUNS; l++)
2217 if (LU_Q(ha, b, t, l) != NULL && LU_Q(ha, b, t, l) != q)
2218 KMFREE(LU_Q(ha, b, t, l),sizeof(struct scsi_lu));
2219 KMFREE(q, sizeof(struct scsi_lu));
2221 for( b =0; b < MAX_EQ; b++ )
2222 ha->dev[b] = (scsi_lu_t *)NULL;
2225 LEAVE("qlc1280_mem_free");
2231 /****************************************************************************/
2232 /* QLogic ISP1280 Hardware Support Functions. */
2233 /****************************************************************************/
2236 * qla2100_enable_intrs
2237 * qla2100_disable_intrs
2239 * Input:
2240 * ha = adapter block pointer.
2242 * Returns:
2243 * None
2245 static inline void qla1280_enable_intrs(scsi_qla_host_t *ha) {
2246 device_reg_t *reg;
2248 reg = ha->iobase;
2249 ha->flags.interrupts_on = 1;
2250 /* enable risc and host interrupts */
2251 WRT_REG_WORD(&reg->ictrl, (ISP_EN_INT+ ISP_EN_RISC));
2254 static inline void qla1280_disable_intrs(scsi_qla_host_t *ha) {
2255 device_reg_t *reg;
2257 reg = ha->iobase;
2258 ha->flags.interrupts_on = 0;
2259 /* disable risc and host interrupts */
2260 WRT_REG_WORD(&reg->ictrl, 0);
2264 * qla1280_initialize_adapter
2265 * Initialize board.
2267 * Input:
2268 * ha = adapter block pointer.
2270 * Returns:
2271 * 0 = success
2273 STATIC uint8_t
2274 qla1280_initialize_adapter(scsi_qla_host_t *ha)
2276 device_reg_t *reg;
2277 uint8_t status;
2278 /* uint8_t cnt; */
2279 uint8_t b;
2281 #ifdef QL_DEBUG_LEVEL_3
2282 ENTER("qla1280_initialize_adapter");
2283 #endif
2285 /* Clear adapter flags. */
2286 ha->flags.online = FALSE;
2287 ha->flags.isp_abort_needed = FALSE;
2288 ha->flags.disable_host_adapter = FALSE;
2289 ha->flags.reset_active = FALSE;
2290 ha->flags.abort_isp_active = FALSE;
2291 ha->flags.watchdog_enabled = FALSE;
2293 DEBUG(printk("Configure PCI space for adapter...\n"));
2294 if (!(status = qla1280_pci_config(ha)))
2296 reg = ha->iobase;
2298 /* Disable ISP interrupts. */
2299 WRT_REG_WORD(&reg->ictrl, 0);
2301 /* Insure mailbox registers are free. */
2302 WRT_REG_WORD(&reg->semaphore, 0);
2303 WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
2304 WRT_REG_WORD(&reg->host_cmd, HC_CLR_HOST_INT);
2306 /* If firmware needs to be loaded */
2307 if (qla1280_verbose)
2308 printk("scsi(%d): Determining if RISC is loaded...\n",(int)ha->host_no);
2309 if (qla1280_isp_firmware(ha))
2311 if (qla1280_verbose)
2312 printk("scsi(%d): Verifying chip...\n",(int)ha->host_no);
2313 if (!(status = qla1280_chip_diag(ha)))
2315 if (qla1280_verbose)
2316 printk("scsi(%d): Setup chip...\n",(int)ha->host_no);
2317 status = qla1280_setup_chip(ha);
2321 if (!status)
2323 /* Setup adapter based on NVRAM parameters. */
2324 if (qla1280_verbose)
2325 printk("scsi(%d): Configure NVRAM parameters...\n",(int)ha->host_no);
2326 qla1280_nvram_config(ha);
2328 if (!ha->flags.disable_host_adapter &&
2329 !qla1280_init_rings(ha))
2331 /* Issue SCSI reset. */
2332 for (b = 0; b < ha->ports; b++)
2333 if (!ha->bus_settings[b].disable_scsi_reset)
2335 /* dg 03/13 if we can't reset twice then bus is dead */
2336 if( qla1280_bus_reset(ha, b) )
2337 if( qla1280_bus_reset(ha, b) )
2339 ha->bus_settings[b].scsi_bus_dead = TRUE;
2345 /* Issue marker command. */
2346 ha->flags.reset_marker = FALSE;
2347 for (b = 0; b < ha->ports; b++)
2349 ha->bus_settings[b].reset_marker = FALSE;
2350 qla1280_marker(ha, b, 0, 0, MK_SYNC_ALL);
2352 }while (ha->flags.reset_marker);
2354 ha->flags.online = TRUE;
2356 /* Enable host adapter target mode. */
2357 for (b = 0; b < ha->ports; b++)
2359 if (!(status = qla1280_enable_tgt(ha, b)))
2361 /* for (cnt = 0; cnt < MAX_LUNS; cnt++)
2363 qla1280_enable_lun(ha, b, cnt);
2364 qla1280_poll(ha);
2367 else
2368 break;
2371 else
2372 status = 1;
2376 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2377 if (status)
2378 qla1280_print("qla1280_initialize_adapter: **** FAILED ****\n\r");
2379 #endif
2380 #ifdef QL_DEBUG_LEVEL_3
2381 else
2382 LEAVE("qla1280_initialize_adapter");
2383 #endif
2384 return(status);
2388 * qla1280_enable_tgt
2389 * Enable target mode.
2391 * Input:
2392 * ha = adapter block pointer.
2393 * b = SCSI bus number.
2395 * Returns:
2396 * 0 = success.
2398 STATIC uint8_t
2399 qla1280_enable_tgt(scsi_qla_host_t *ha, uint8_t b)
2401 uint8_t status = 0;
2402 /* uint16_t mb[MAILBOX_REGISTER_COUNT]; */
2404 #ifdef QL_DEBUG_LEVEL_3
2405 qla1280_print("qla1280_enable_tgt: entered\n\r");
2406 #endif
2408 /* Enable target mode. */
2410 mb[0] = MBC_ENABLE_TARGET_MODE;
2411 mb[1] = BIT_15;
2412 mb[2] = (uint16_t)(b << 15);
2413 status = qla1280_mailbox_command(ha, BIT_2|BIT_1|BIT_0, &mb[0]);
2415 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2416 if (status)
2417 qla1280_print("qla1280_enable_tgt: **** FAILED ****\n\r");
2418 #endif
2419 #ifdef QL_DEBUG_LEVEL_3
2420 else
2421 qla1280_print("qla1280_enable_tgt: exiting normally\n\r");
2422 #endif
2423 return(status);
2427 * ISP Firmware Test
2428 * Checks if present version of RISC firmware is older than
2429 * driver firmware.
2431 * Input:
2432 * ha = adapter block pointer.
2434 * Returns:
2435 * 0 = firmware does not need to be loaded.
2437 STATIC uint8_t
2438 qla1280_isp_firmware(scsi_qla_host_t *ha)
2440 nvram_t *nv = (nvram_t *)ha->response_ring;
2441 uint16_t *wptr;
2442 uint8_t chksum;
2443 uint8_t cnt;
2444 uint8_t status = 0; /* dg 2/27 always loads RISC */
2445 uint16_t mb[MAILBOX_REGISTER_COUNT];
2447 ENTER("qla1280_isp_firmware");
2449 /* Verify valid NVRAM checksum. */
2450 wptr = (uint16_t *)ha->response_ring;
2451 DEBUG(printk("qla1280_isp_firmware: Reading NVRAM\n"));
2452 chksum = 0;
2453 for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++)
2455 *wptr = qla1280_get_nvram_word(ha, cnt);
2456 chksum += (uint8_t)*wptr;
2457 chksum += (uint8_t)(*wptr >> 8);
2458 wptr++;
2460 DEBUG(printk("qla1280_isp_firmware: Completed Reading NVRAM\n"));
2462 #if defined(QL_DEBUG_LEVEL_3)
2463 sprintf(debug_buff,"qla1280_isp_firmware: NVRAM Magic ID= %c %c %c\n\r",(char *) nv->id[0],nv->id[1],nv->id[2]);
2464 qla1280_print(debug_buff);
2465 #endif
2467 /* Bad NVRAM data, load RISC code. */
2468 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2469 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->version < 1)
2471 printk(KERN_INFO "qla1280_isp_firmware: Bad checksum or magic number or version in NVRAM.\n");
2472 ha->flags.disable_risc_code_load = FALSE;
2474 else
2475 ha->flags.disable_risc_code_load = nv->cntr_flags_1.disable_loading_risc_code;
2477 if (ha->flags.disable_risc_code_load)
2479 #if defined(QL_DEBUG_LEVEL_3)
2480 qla1280_print("qla1280_isp_firmware: Telling RISC to verify checksum of loaded BIOS code.\n\r");
2481 #endif
2482 /* Verify checksum of loaded RISC code. */
2483 mb[0] = MBC_VERIFY_CHECKSUM;
2484 /* mb[1] = ql12_risc_code_addr01; */
2485 mb[1] = *QLBoardTbl[ha->devnum].fwstart;
2487 if (!(status = qla1280_mailbox_command(ha, BIT_1|BIT_0, &mb[0])))
2489 /* Start firmware execution. */
2490 #if defined(QL_DEBUG_LEVEL_3)
2491 qla1280_print("qla1280_isp_firmware: Startng F/W execution.\n\r");
2492 #endif
2493 mb[0] = MBC_EXECUTE_FIRMWARE;
2494 /* mb[1] = ql12_risc_code_addr01; */
2495 mb[1] = *QLBoardTbl[ha->devnum].fwstart;
2496 qla1280_mailbox_command(ha, BIT_1|BIT_0, &mb[0]);
2498 else
2499 printk(KERN_INFO "qla1280: RISC checksum failed.\n");
2501 else
2503 DEBUG(printk("qla1280: NVRAM configured to load RISC load.\n"));
2504 status = 1;
2507 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2508 if (status)
2509 qla1280_print(
2510 "qla1280_isp_firmware: **** Load RISC code ****\n\r");
2511 #endif
2512 LEAVE("qla1280_isp_firmware");
2513 return(status);
2517 * PCI configuration
2518 * Setup device PCI configuration registers.
2520 * Input:
2521 * ha = adapter block pointer.
2523 * Returns:
2524 * 0 = success.
2526 STATIC uint8_t
2527 qla1280_pci_config(scsi_qla_host_t *ha)
2529 uint8_t status = 1;
2530 uint32_t command;
2531 #if MEMORY_MAPPED_IO
2532 uint32_t page_offset, base;
2533 uint32_t mmapbase;
2534 #endif
2535 config_reg_t *creg = 0;
2536 uint16_t buf_wd;
2538 ENTER("qla1280_pci_config");
2540 /* Get command register. */
2541 if (pci_read_config_word(ha->pdev,OFFSET(creg->command), &buf_wd) == PCIBIOS_SUCCESSFUL)
2543 command = buf_wd;
2545 * Set Bus Master Enable, Memory Address Space Enable and
2546 * reset any error bits.
2548 buf_wd &= ~0x7;
2549 #if MEMORY_MAPPED_IO
2550 DEBUG(printk("qla1280: MEMORY MAPPED IO is enabled.\n"));
2551 buf_wd |= BIT_2 + BIT_1 + BIT_0;
2552 #else
2553 buf_wd |= BIT_2 + BIT_0;
2554 #endif
2555 if( pci_write_config_word(ha->pdev,OFFSET(creg->command), buf_wd) )
2557 printk(KERN_WARNING "qla1280: Could not write config word.\n");
2559 /* Get expansion ROM address. */
2560 if (pci_read_config_word(ha->pdev,OFFSET(creg->expansion_rom), &buf_wd) == PCIBIOS_SUCCESSFUL)
2562 /* Reset expansion ROM address decode enable. */
2563 buf_wd &= ~BIT_0;
2564 if (pci_write_config_word(ha->pdev,OFFSET(creg->expansion_rom), buf_wd) == PCIBIOS_SUCCESSFUL)
2566 #if MEMORY_MAPPED_IO
2567 /* Get memory mapped I/O address. */
2568 pci_read_config_dword(ha->pdev,OFFSET(cfgp->mem_base_addr), &mmapbase);
2569 mmapbase &= PCI_BASE_ADDRESS_MEM_MASK;
2571 /* Find proper memory chunk for memory map I/O reg. */
2572 base = mmapbase & PAGE_MASK;
2573 page_offset = mmapbase - base;
2574 /* Get virtual address for I/O registers. */
2575 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
2576 ha->mmpbase = ioremap_nocache(base, page_offset + 256);
2577 #else
2578 ha->mmpbase = vremap(base,page_offset + 256);
2579 #endif
2580 if( ha->mmpbase )
2582 ha->mmpbase += page_offset;
2583 /* ha->iobase = ha->mmpbase; */
2584 status = 0;
2586 #else /* MEMORY_MAPPED_IO */
2587 status = 0;
2588 #endif /* MEMORY_MAPPED_IO */
2593 LEAVE("qla1280_pci_config");
2594 return(status);
2598 * Chip diagnostics
2599 * Test chip for proper operation.
2601 * Input:
2602 * ha = adapter block pointer.
2604 * Returns:
2605 * 0 = success.
2607 STATIC uint8_t
2608 qla1280_chip_diag(scsi_qla_host_t *ha)
2610 device_reg_t *reg = ha->iobase;
2611 uint8_t status = 0;
2612 uint16_t data;
2613 uint32_t cnt;
2614 uint16_t mb[MAILBOX_REGISTER_COUNT];
2616 #ifdef QL_DEBUG_LEVEL_3
2617 sprintf(debug_buff, "qla1280_chip_diag: testing device at 0x%p \n\r",&reg->id_l);
2618 qla1280_print(debug_buff);
2619 #endif
2621 /* Soft reset chip and wait for it to finish. */
2622 WRT_REG_WORD(&reg->ictrl, ISP_RESET);
2623 data = qla1280_debounce_register(&reg->ictrl);
2624 for (cnt = 6000000; cnt && data & ISP_RESET; cnt--)
2626 SYS_DELAY(5);
2627 data = RD_REG_WORD(&reg->ictrl);
2629 if (cnt)
2631 /* Reset register not cleared by chip reset. */
2632 #if defined(QL_DEBUG_LEVEL_3)
2633 qla1280_print("qla1280_chip_diag: reset register cleared by chip reset\n\r");
2634 #endif
2635 WRT_REG_WORD(&reg->cfg_1, 0);
2637 /* Reset RISC and disable BIOS which
2638 allows RISC to execute out of RAM. */
2639 WRT_REG_WORD(&reg->host_cmd, HC_RESET_RISC);
2640 WRT_REG_WORD(&reg->host_cmd, HC_RELEASE_RISC);
2641 WRT_REG_WORD(&reg->host_cmd, HC_DISABLE_BIOS);
2642 data = qla1280_debounce_register(&reg->mailbox0);
2643 for (cnt = 6000000; cnt && data == MBS_BUSY; cnt--)
2645 SYS_DELAY(5);
2646 data = RD_REG_WORD(&reg->mailbox0);
2649 if (cnt)
2651 /* Check product ID of chip */
2652 #if defined(QL_DEBUG_LEVEL_3)
2653 qla1280_print("qla1280_chip_diag: Checking product ID of chip\n\r");
2654 #endif
2655 if (RD_REG_WORD(&reg->mailbox1) != PROD_ID_1 ||
2656 (RD_REG_WORD(&reg->mailbox2) != PROD_ID_2 &&
2657 RD_REG_WORD(&reg->mailbox2) != PROD_ID_2a) ||
2658 RD_REG_WORD(&reg->mailbox3) != PROD_ID_3 ||
2659 RD_REG_WORD(&reg->mailbox4) != PROD_ID_4)
2661 printk(KERN_INFO "qla1280: Wrong product ID = 0x%x,0x%x,0x%x,0x%x\n",
2662 RD_REG_WORD(&reg->mailbox1),
2663 RD_REG_WORD(&reg->mailbox2),
2664 RD_REG_WORD(&reg->mailbox3),
2665 RD_REG_WORD(&reg->mailbox4) );
2666 status = 1;
2668 else
2670 DEBUG(printk("qla1280_chip_diag: Checking mailboxes of chip\n"));
2671 /* Wrap Incoming Mailboxes Test. */
2672 mb[0] = MBC_MAILBOX_REGISTER_TEST;
2673 mb[1] = 0xAAAA;
2674 mb[2] = 0x5555;
2675 mb[3] = 0xAA55;
2676 mb[4] = 0x55AA;
2677 mb[5] = 0xA5A5;
2678 mb[6] = 0x5A5A;
2679 mb[7] = 0x2525;
2680 if (!(status = qla1280_mailbox_command(ha,
2681 (BIT_7|BIT_6|BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0),
2682 &mb[0])))
2684 if (mb[1] != 0xAAAA || mb[2] != 0x5555 ||
2685 mb[3] != 0xAA55 || mb[4] != 0x55AA)
2686 status = 1;
2687 if (mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
2688 mb[7] != 0x2525)
2689 status = 1;
2690 if( status == 1 )
2691 printk(KERN_INFO "qla1280: Failed mailbox check\n");
2695 else
2696 status = 1;
2698 else
2699 status = 1;
2701 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2702 if (status)
2703 qla1280_print("qla1280_chip_diag: **** FAILED ****\n\r");
2704 #endif
2705 #ifdef QL_DEBUG_LEVEL_3
2706 else
2707 qla1280_print("qla1280_chip_diag: exiting normally\n\r");
2708 #endif
2709 return(status);
2713 * Setup chip
2714 * Load and start RISC firmware.
2716 * Input:
2717 * ha = adapter block pointer.
2719 * Returns:
2720 * 0 = success.
2722 STATIC uint8_t
2723 qla1280_setup_chip(scsi_qla_host_t *ha)
2725 uint8_t status = 0;
2726 uint16_t risc_address;
2727 uint16_t *risc_code_address;
2728 long risc_code_size;
2729 uint16_t mb[MAILBOX_REGISTER_COUNT];
2730 #ifdef QLA1280_UNUSED
2731 uint8_t *sp;
2732 int i;
2733 #endif
2734 uint16_t cnt;
2735 int num;
2736 uint8_t *tbuf;
2737 u_long p_tbuf;
2739 #ifdef QL_DEBUG_LEVEL_3
2740 ENTER("qla1280_setup_chip");
2741 #endif
2743 if( (tbuf = (uint8_t *)KMALLOC(8000) ) == NULL )
2745 printk("setup_chip: couldn't alloacte memory\n");
2746 return(1);
2748 p_tbuf = VIRT_TO_BUS(tbuf);
2749 /* Load RISC code. */
2751 risc_address = ql12_risc_code_addr01;
2752 risc_code_address = &ql12_risc_code01[0];
2753 risc_code_size = ql12_risc_code_length01;
2755 risc_address = *QLBoardTbl[ha->devnum].fwstart;
2756 risc_code_address = QLBoardTbl[ha->devnum].fwcode;
2757 risc_code_size = (long)(*QLBoardTbl[ha->devnum].fwlen & 0xffff);
2759 DEBUG(printk("qla1280: DMAing RISC code (%d) words.\n",(int)risc_code_size));
2760 DEBUG(sprintf(debug_buff,"qla1280_setup_chip: Loading RISC code size =(%ld).\n\r",risc_code_size);)
2761 DEBUG(qla1280_print(debug_buff));
2762 num =0;
2763 while (risc_code_size > 0 && !status)
2765 cnt = 2000 >> 1;
2767 if ( cnt > risc_code_size )
2768 cnt = risc_code_size;
2770 DEBUG(sprintf(debug_buff,"qla1280_setup_chip: loading risc @ =(0x%p),%d,%d(0x%x).\n\r",risc_code_address,cnt,num,risc_address);)
2771 DEBUG(qla1280_print(debug_buff));
2772 DEBUG(printk("qla1280_setup_chip: loading risc @ =code=(0x%p),cnt=%d,seg=%d,addr=0x%x\n\r",risc_code_address,cnt,num,risc_address));
2773 BCOPY((caddr_t) risc_code_address,(caddr_t) ha->request_ring, (cnt <<1));
2774 mb[0] = MBC_LOAD_RAM;
2775 /* mb[0] = MBC_LOAD_RAM_A64; */
2776 mb[1] = risc_address;
2777 mb[4] = cnt;
2778 mb[3] = (uint16_t) ha->request_dma & 0xffff;
2779 mb[2] = (uint16_t) (ha->request_dma >> 16) & 0xffff;
2780 mb[7] = (uint16_t) (MS_64BITS(ha->request_dma) & 0xffff);
2781 mb[6] = (uint16_t) (MS_64BITS(ha->request_dma) >> 16) & 0xffff;
2782 DEBUG(printk("qla1280_setup_chip: op=%d 0x%lx = 0x%4x,0x%4x,0x%4x,0x%4x\n",mb[0],ha->request_dma,mb[6],mb[7],mb[2],mb[3]));
2783 if( (status = qla1280_mailbox_command(ha, BIT_4|BIT_3|BIT_2|BIT_1|BIT_0,
2784 &mb[0])) )
2786 printk("Failed to load partial segment of f/w\n");
2787 break;
2789 /* dump it back */
2791 #if 0
2792 mb[0] = MBC_DUMP_RAM_A64;
2793 mb[1] = risc_address;
2794 mb[4] = cnt;
2795 mb[3] = (uint16_t) p_tbuf & 0xffff;
2796 mb[2] = (uint16_t) (p_tbuf >> 16) & 0xffff;
2797 mb[7] = (uint16_t) (p_tbuf >> 32) & 0xffff;
2798 mb[6] = (uint16_t) (p_tbuf >> 48) & 0xffff;
2800 if( (status = qla1280_mailbox_command(ha, BIT_4|BIT_3|BIT_2|BIT_1|BIT_0,
2801 &mb[0])) )
2803 printk("Failed to dump partial segment of f/w\n");
2804 break;
2806 sp = (uint8_t *)ha->request_ring;
2807 for (i = 0; i < (cnt<< 1) ; i++)
2809 if( tbuf[i] != sp[i] )
2811 printk("qla1280 : firmware compare error @ byte (0x%x)\n",i);
2812 break;
2816 #endif
2817 risc_address += cnt;
2818 risc_code_size = risc_code_size - cnt;
2819 risc_code_address = risc_code_address + cnt;
2820 num++;
2822 #ifdef QLA1280_UNUSED
2823 DEBUG(ql_debug_print = 0;)
2825 for (i = 0; i < ql12_risc_code_length01; i++)
2827 mb[0] = 0x4;
2828 mb[1] = ql12_risc_code_addr01 + i;
2829 mb[2] = ql12_risc_code01[i];
2831 status = qla1280_mailbox_command(ha, BIT_2|BIT_1|BIT_0,
2832 &mb[0]);
2833 if (status)
2835 printk("qla1280 : firmware load failure\n");
2836 break;
2839 mb[0] = 0x5;
2840 mb[1] = ql12_risc_code_addr01 + i;
2841 mb[2] = 0;
2843 status = qla1280_mailbox_command(ha, BIT_2|BIT_1|BIT_0,
2844 &mb[0]);
2845 if (status)
2847 printk("qla1280 : firmware dump failure\n");
2848 break;
2850 if( mb[2] != ql12_risc_code01[i] )
2851 printk("qla1280 : firmware compare error @ (0x%x)\n",ql12_risc_code_addr01+i);
2854 DEBUG(ql_debug_print = 1;)
2855 #endif
2857 /* Verify checksum of loaded RISC code. */
2858 if (!status)
2860 DEBUG(printk("qla1280_setup_chip: Verifying checksum of loaded RISC code.\n");)
2861 mb[0] = MBC_VERIFY_CHECKSUM;
2862 /* mb[1] = ql12_risc_code_addr01; */
2863 mb[1] = *QLBoardTbl[ha->devnum].fwstart;
2865 if (!(status = qla1280_mailbox_command(ha, BIT_1|BIT_0, &mb[0])))
2867 /* Start firmware execution. */
2868 DEBUG(qla1280_print("qla1280_setup_chip: start firmware running.\n\r");)
2869 mb[0] = MBC_EXECUTE_FIRMWARE;
2870 /* mb[1] = ql12_risc_code_addr01; */
2871 mb[1] = *QLBoardTbl[ha->devnum].fwstart;
2872 qla1280_mailbox_command(ha, BIT_1|BIT_0, &mb[0]);
2874 else
2875 printk("qla1280_setup_chip: Failed checksum.\n");
2878 KMFREE(tbuf,8000);
2880 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2881 if (status)
2882 qla1280_print("qla1280_setup_chip: **** FAILED ****\n\r");
2883 #endif
2884 #ifdef QL_DEBUG_LEVEL_3
2885 else
2886 LEAVE("qla1280_setup_chip");
2887 #endif
2888 return(status);
2892 * Initialize rings
2894 * Input:
2895 * ha = adapter block pointer.
2896 * ha->request_ring = request ring virtual address
2897 * ha->response_ring = response ring virtual address
2898 * ha->request_dma = request ring physical address
2899 * ha->response_dma = response ring physical address
2901 * Returns:
2902 * 0 = success.
2904 STATIC uint8_t
2905 qla1280_init_rings(scsi_qla_host_t *ha)
2907 uint8_t status = 0;
2908 uint16_t cnt;
2909 uint16_t mb[MAILBOX_REGISTER_COUNT];
2911 #ifdef QL_DEBUG_LEVEL_3
2912 ENTER("qla1280_init_rings");
2913 #endif
2914 /* Clear outstanding commands array. */
2915 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
2916 ha->outstanding_cmds[cnt] = 0;
2918 /* Initialize request queue. */
2919 ha->request_ring_ptr = ha->request_ring;
2920 ha->req_ring_index = 0;
2921 ha->req_q_cnt = REQUEST_ENTRY_CNT;
2922 /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
2923 mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
2924 mb[1] = REQUEST_ENTRY_CNT;
2925 mb[3] = (uint16_t)LS_64BITS(ha->request_dma);
2926 mb[2] = (uint16_t)( LS_64BITS(ha->request_dma) >> 16);
2927 mb[4] = 0;
2928 mb[7] = (uint16_t)MS_64BITS(ha->request_dma);
2929 mb[6] = (uint16_t)( MS_64BITS(ha->request_dma) >> 16);
2930 if (!(status = qla1280_mailbox_command(ha,
2931 BIT_7|BIT_6|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0,
2932 &mb[0])))
2934 /* Initialize response queue. */
2935 ha->response_ring_ptr = ha->response_ring;
2936 ha->rsp_ring_index = 0;
2937 /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
2938 mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
2939 mb[1] = RESPONSE_ENTRY_CNT;
2940 mb[3] = (uint16_t)LS_64BITS(ha->response_dma);
2941 mb[2] = (uint16_t)(LS_64BITS(ha->response_dma) >> 16);
2942 mb[5] = 0;
2943 mb[7] = (uint16_t)MS_64BITS(ha->response_dma);
2944 mb[6] = (uint16_t)(MS_64BITS(ha->response_dma) >> 16);
2945 status = qla1280_mailbox_command(ha,
2946 BIT_7|BIT_6|BIT_5|BIT_3|BIT_2|BIT_1|BIT_0,
2947 &mb[0]);
2950 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
2951 if (status)
2952 qla1280_print("qla1280_init_rings: **** FAILED ****\n\r");
2953 #endif
2954 #ifdef QL_DEBUG_LEVEL_3
2955 else
2956 LEAVE("qla1280_init_rings");
2957 #endif
2958 return(status);
2962 * NVRAM configuration.
2964 * Input:
2965 * ha = adapter block pointer.
2966 * ha->request_ring = request ring virtual address
2968 * Output:
2969 * host adapters parameters in host adapter block
2971 * Returns:
2972 * 0 = success.
2974 STATIC uint8_t
2975 qla1280_nvram_config(scsi_qla_host_t *ha)
2977 device_reg_t *reg = ha->iobase;
2978 nvram_t *nv = (nvram_t *)ha->response_ring;
2979 uint8_t status = 0;
2980 uint32_t b, t, l;
2981 uint16_t *wptr;
2982 uint16_t mb[MAILBOX_REGISTER_COUNT];
2983 uint8_t cnt;
2984 uint8_t chksum;
2985 uint32_t nvsize;
2987 #if defined(QL_DEBUG_ROUTINES) && !defined(QL_DEBUG_LEVEL_4)
2988 uint8_t saved_print_status = ql_debug_print;
2989 #endif
2990 ENTER("qla1280_nvram_config");
2991 #if defined(QL_DEBUG_ROUTINES) && !defined(QL_DEBUG_LEVEL_4)
2992 ql_debug_print = FALSE;
2993 #endif
2995 /* Verify valid NVRAM checksum. */
2996 #if USE_NVRAM_DEFAULTS
2997 chksum = 1;
2998 #else
2999 wptr = (uint16_t *)ha->response_ring;
3000 chksum = 0;
3001 if( ha->device_id == QLA12160_DEVICE_ID ||
3002 ha->device_id == QLA10160_DEVICE_ID )
3003 nvsize = sizeof(nvram160_t)/2;
3004 else
3005 nvsize = sizeof(nvram_t)/2;
3006 for( cnt = 0; cnt < nvsize; cnt++ )
3008 *wptr = qla1280_get_nvram_word(ha, cnt);
3009 chksum += (uint8_t)*wptr;
3010 chksum += (uint8_t)(*wptr >> 8);
3011 wptr++;
3013 #endif
3016 /* Bad NVRAM data, set defaults parameters. */
3017 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
3018 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->version < 1)
3020 #if USE_NVRAM_DEFAULTS
3021 DEBUG(printk("Using defaults for NVRAM\n"));
3022 #else
3023 DEBUG(printk("Using defaults for NVRAM: \n"));
3024 DEBUG(printk("checksum=0x%x, Id=%c, version=0x%x\n",chksum,nv->id[0],nv->version));
3025 #if defined(QL_DEBUG_LEVEL_3)
3026 /* ql_debug_print = 1;
3027 qla1280_dump_buffer((caddr_t)ha->response_ring, REQUEST_ENTRY_SIZE);
3028 ql_debug_print = 0; */
3029 #endif
3030 wptr = (uint16_t *)ha->response_ring;
3031 for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++)
3032 *wptr++ = 0;
3033 #endif
3036 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
3037 nv->firmware_feature.w = BIT_0;
3038 nv->termination.f.scsi_bus_0_control = 3;
3039 nv->termination.f.scsi_bus_1_control = 3;
3040 nv->termination.f.auto_term_support = 1;
3042 for (b = 0; b < MAX_BUSES; b++)
3044 nv->bus[b].config_1.initiator_id = 7;
3045 nv->bus[b].bus_reset_delay = 5;
3046 nv->bus[b].config_2.async_data_setup_time = 9;
3047 nv->bus[b].config_2.req_ack_active_negation = 1;
3048 nv->bus[b].config_2.data_line_active_negation = 1;
3049 nv->bus[b].selection_timeout = 250;
3050 nv->bus[b].max_queue_depth = 256;
3052 for (t = 0; t < MAX_TARGETS; t++)
3054 nv->bus[b].target[t].parameter.f.auto_request_sense = 1;
3055 nv->bus[b].target[t].parameter.f.disconnect_allowed = 1;
3056 nv->bus[b].target[t].parameter.f.tag_queuing = 1;
3057 nv->bus[b].target[t].flags.device_enable = 1;
3061 #if USE_NVRAM_DEFAULTS
3062 status = 0;
3063 #else
3064 status = 1;
3065 #endif
3067 else
3069 /* Always force AUTO sense for LINUX SCSI */
3070 for (b = 0; b < MAX_BUSES; b++)
3071 for (t = 0; t < MAX_TARGETS; t++)
3073 nv->bus[b].target[t].parameter.f.auto_request_sense = 1;
3076 #if DEBUG_PRINT_NVRAM
3077 ql_debug_print = 1;
3078 sprintf(debug_buff,"qla1280 : initiator scsi id bus[0]=%d\n\r",
3079 nv->bus[0].config_1.initiator_id);
3080 qla1280_print(debug_buff);
3081 sprintf(debug_buff,"qla1280 : initiator scsi id bus[1]=%d\n\r",
3082 nv->bus[1].config_1.initiator_id);
3083 qla1280_print(debug_buff);
3085 sprintf(debug_buff,"qla1280 : bus reset delay[0]=%d\n\r",
3086 nv->bus[0].bus_reset_delay);
3087 qla1280_print(debug_buff);
3088 sprintf(debug_buff,"qla1280 : bus reset delay[1]=%d\n\r",
3089 nv->bus[1].bus_reset_delay);
3090 qla1280_print(debug_buff);
3092 sprintf(debug_buff,"qla1280 : retry count[0]=%d\n\r",
3093 nv->bus[0].retry_count);
3094 qla1280_print(debug_buff);
3095 sprintf(debug_buff,"qla1280 : retry delay[0]=%d\n\r",
3096 nv->bus[0].retry_delay);
3097 qla1280_print(debug_buff);
3098 sprintf(debug_buff,"qla1280 : retry count[1]=%d\n\r",
3099 nv->bus[1].retry_count);
3100 qla1280_print(debug_buff);
3101 sprintf(debug_buff,"qla1280 : retry delay[1]=%d\n\r",
3102 nv->bus[1].retry_delay);
3103 qla1280_print(debug_buff);
3105 sprintf(debug_buff,"qla1280 : async data setup time[0]=%d\n\r",
3106 nv->bus[0].config_2.async_data_setup_time);
3107 qla1280_print(debug_buff);
3108 sprintf(debug_buff,"qla1280 : async data setup time[1]=%d\n\r",
3109 nv->bus[1].config_2.async_data_setup_time);
3110 qla1280_print(debug_buff);
3112 sprintf(debug_buff,"qla1280 : req/ack active negation[0]=%d\n\r",
3113 nv->bus[0].config_2.req_ack_active_negation);
3114 qla1280_print(debug_buff);
3115 sprintf(debug_buff,"qla1280 : req/ack active negation[1]=%d\n\r",
3116 nv->bus[1].config_2.req_ack_active_negation);
3117 qla1280_print(debug_buff);
3119 sprintf(debug_buff,"qla1280 : data line active negation[0]=%d\n\r",
3120 nv->bus[0].config_2.data_line_active_negation);
3121 qla1280_print(debug_buff);
3122 sprintf(debug_buff,"qla1280 : data line active negation[1]=%d\n\r",
3123 nv->bus[1].config_2.data_line_active_negation);
3124 qla1280_print(debug_buff);
3127 sprintf(debug_buff,"qla1280 : disable loading risc code=%d\n\r",
3128 nv->cntr_flags_1.disable_loading_risc_code);
3129 qla1280_print(debug_buff);
3131 sprintf(debug_buff,"qla1280 : enable 64bit addressing=%d\n\r",
3132 nv->cntr_flags_1.enable_64bit_addressing);
3133 qla1280_print(debug_buff);
3135 sprintf(debug_buff,"qla1280 : selection timeout limit[0]=%d\n\r",
3136 nv->bus[0].selection_timeout);
3137 qla1280_print(debug_buff);
3138 sprintf(debug_buff,"qla1280 : selection timeout limit[1]=%d\n\r",
3139 nv->bus[1].selection_timeout);
3141 qla1280_print(debug_buff);
3142 sprintf(debug_buff,"qla1280 : max queue depth[0]=%d\n\r",
3143 nv->bus[0].max_queue_depth);
3144 qla1280_print(debug_buff);
3145 sprintf(debug_buff,"qla1280 : max queue depth[1]=%d\n\r",
3146 nv->bus[1].max_queue_depth);
3147 qla1280_print(debug_buff);
3148 #endif
3150 DEBUG(ql_debug_print = 0;)
3152 /* Disable RISC load of firmware. */
3153 ha->flags.disable_risc_code_load =
3154 nv->cntr_flags_1.disable_loading_risc_code;
3155 /* Enable 64bit addressing. */
3156 ha->flags.enable_64bit_addressing =
3157 nv->cntr_flags_1.enable_64bit_addressing;
3159 /* Set ISP hardware DMA burst */
3160 mb[0] = nv->isp_config.c;
3161 WRT_REG_WORD(&reg->cfg_1, mb[0]);
3163 /* Set SCSI termination. */
3164 WRT_REG_WORD(&reg->gpio_enable, (BIT_3 + BIT_2 + BIT_1 + BIT_0));
3165 mb[0] = nv->termination.c & (BIT_3 + BIT_2 + BIT_1 + BIT_0);
3166 WRT_REG_WORD(&reg->gpio_data, mb[0]);
3168 /* ISP parameter word. */
3169 mb[0] = MBC_SET_SYSTEM_PARAMETER;
3170 mb[1] = nv->isp_parameter;
3171 status |= qla1280_mailbox_command(ha, BIT_1|BIT_0, &mb[0]);
3173 /* Firmware feature word. */
3174 mb[0] = MBC_SET_FIRMWARE_FEATURES;
3175 mb[1] = nv->firmware_feature.w & (BIT_1|BIT_0);
3176 status |= qla1280_mailbox_command(ha, BIT_1|BIT_0, &mb[0]);
3178 /* Retry count and delay. */
3179 mb[0] = MBC_SET_RETRY_COUNT;
3180 mb[1] = nv->bus[0].retry_count;
3181 mb[2] = nv->bus[0].retry_delay;
3182 mb[6] = nv->bus[1].retry_count;
3183 mb[7] = nv->bus[1].retry_delay;
3184 status |= qla1280_mailbox_command(ha, BIT_7|BIT_6|BIT_2|BIT_1|BIT_0, &mb[0]);
3186 /* ASYNC data setup time. */
3187 mb[0] = MBC_SET_ASYNC_DATA_SETUP;
3188 mb[1] = nv->bus[0].config_2.async_data_setup_time;
3189 mb[2] = nv->bus[1].config_2.async_data_setup_time;
3190 status |= qla1280_mailbox_command(ha, BIT_2|BIT_1|BIT_0, &mb[0]);
3192 /* Active negation states. */
3193 mb[0] = MBC_SET_ACTIVE_NEGATION;
3194 mb[1] = 0;
3195 if (nv->bus[0].config_2.req_ack_active_negation)
3196 mb[1] |= BIT_5;
3197 if (nv->bus[0].config_2.data_line_active_negation)
3198 mb[1] |= BIT_4;
3199 mb[2] = 0;
3200 if (nv->bus[1].config_2.req_ack_active_negation)
3201 mb[2] |= BIT_5;
3202 if (nv->bus[1].config_2.data_line_active_negation)
3203 mb[2] |= BIT_4;
3204 status |= qla1280_mailbox_command(ha, BIT_2|BIT_1|BIT_0, &mb[0]);
3206 /* Selection timeout. */
3207 mb[0] = MBC_SET_SELECTION_TIMEOUT;
3208 mb[1] = nv->bus[0].selection_timeout;
3209 mb[2] = nv->bus[1].selection_timeout;
3210 status |= qla1280_mailbox_command(ha, BIT_2|BIT_1|BIT_0, &mb[0]);
3212 for (b = 0; b < ha->ports; b++)
3214 /* SCSI Reset Disable. */
3215 ha->bus_settings[b].disable_scsi_reset = nv->bus[b].config_1.scsi_reset_disable;
3217 /* Initiator ID. */
3218 ha->bus_settings[b].id = nv->bus[b].config_1.initiator_id;
3219 mb[0] = MBC_SET_INITIATOR_ID;
3220 mb[1] = b ? ha->bus_settings[b].id | BIT_7 : ha->bus_settings[b].id;
3221 status |= qla1280_mailbox_command(ha, BIT_1|BIT_0, &mb[0]);
3223 /* Reset Delay. */
3224 ha->bus_settings[b].bus_reset_delay = nv->bus[b].bus_reset_delay;
3226 /* Command queue depth per device. */
3227 ha->bus_settings[b].hiwat = nv->bus[b].max_queue_depth - 1;
3229 /* Set target parameters. */
3230 for (t = 0; t < MAX_TARGETS; t++)
3232 if( ha->device_id == QLA12160_DEVICE_ID ||
3233 ha->device_id == QLA10160_DEVICE_ID )
3235 status = qla12160_set_target_parameters(ha,b,t,0,(nvram160_t *)nv);
3237 else
3239 /* Set Target Parameters. */
3240 mb[0] = MBC_SET_TARGET_PARAMETERS;
3241 mb[1] = (uint16_t)(b ? t | BIT_7 :t);
3242 mb[1] <<= 8;
3243 mb[2] = nv->bus[b].target[t].parameter.c << 8;
3244 mb[2] |= TP_AUTO_REQUEST_SENSE;
3245 mb[2] &= ~TP_STOP_QUEUE;
3246 mb[3] = nv->bus[b].target[t].flags.sync_offset << 8;
3247 mb[3] |= nv->bus[b].target[t].sync_period;
3248 status |= qla1280_mailbox_command(ha, BIT_3|BIT_2|BIT_1|BIT_0,
3249 &mb[0]);
3252 /* Save Tag queuing enable flag. */
3253 mb[0] = BIT_0 << t;
3254 if (nv->bus[b].target[t].parameter.f.tag_queuing)
3255 ha->bus_settings[b].qtag_enables |= mb[0];
3257 /* Save Device enable flag. */
3258 if (nv->bus[b].target[t].flags.device_enable)
3259 ha->bus_settings[b].device_enables |= mb[0];
3261 /* Save LUN disable flag. */
3262 if (nv->bus[b].target[t].flags.lun_disable)
3263 ha->bus_settings[b].lun_disables |= mb[0];
3265 /* Set Device Queue Parameters. */
3266 for (l = 0; l < MAX_LUNS; l++)
3268 mb[0] = MBC_SET_DEVICE_QUEUE;
3269 mb[1] = (uint16_t)(b ? t | BIT_7 :t);
3270 mb[1] = mb[1] << 8 | l;
3271 mb[2] = nv->bus[b].max_queue_depth;
3272 mb[3] = nv->bus[b].target[t].execution_throttle;
3273 status |= qla1280_mailbox_command(ha, BIT_3|BIT_2|BIT_1|BIT_0,
3274 &mb[0]);
3278 DEBUG(ql_debug_print = 0;)
3280 #if defined(QL_DEBUG_ROUTINES) && !defined(QL_DEBUG_LEVEL_4)
3281 ql_debug_print = saved_print_status;
3282 #endif
3284 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3285 DEBUG(if (status))
3286 DEBUG(qla1280_print("qla1280_nvram_config: **** FAILED ****\n\r");)
3287 #endif
3288 LEAVE("qla1280_nvram_config");
3289 return(status);
3293 * Get NVRAM data word
3294 * Calculates word position in NVRAM and calls request routine to
3295 * get the word from NVRAM.
3297 * Input:
3298 * ha = adapter block pointer.
3299 * address = NVRAM word address.
3301 * Returns:
3302 * data word.
3304 STATIC uint16_t
3305 qla1280_get_nvram_word(scsi_qla_host_t *ha, uint32_t address)
3307 uint32_t nv_cmd;
3308 uint16_t data;
3310 #ifdef QL_DEBUG_ROUTINES
3311 uint8_t saved_print_status = ql_debug_print;
3312 #endif
3313 #ifdef QL_DEBUG_LEVEL_4
3314 ENTER("qla1280_get_nvram_word");
3315 #endif
3317 nv_cmd = address << 16;
3318 nv_cmd |= NV_READ_OP;
3320 #ifdef QL_DEBUG_ROUTINES
3321 ql_debug_print = FALSE;
3322 #endif
3323 data = qla1280_nvram_request(ha, nv_cmd);
3324 #ifdef QL_DEBUG_ROUTINES
3325 ql_debug_print = saved_print_status;
3326 #endif
3328 #ifdef QL_DEBUG_LEVEL_4
3329 qla1280_print("qla1280_get_nvram_word: exiting normally NVRAM data = ");
3330 qla1280_output_number((uint32_t)data, 16);
3331 qla1280_print("\n\r");
3332 #endif
3333 return(data);
3337 * NVRAM request
3338 * Sends read command to NVRAM and gets data from NVRAM.
3340 * Input:
3341 * ha = adapter block pointer.
3342 * nv_cmd = Bit 26 = start bit
3343 * Bit 25, 24 = opcode
3344 * Bit 23-16 = address
3345 * Bit 15-0 = write data
3347 * Returns:
3348 * data word.
3350 STATIC uint16_t
3351 qla1280_nvram_request(scsi_qla_host_t *ha, uint32_t nv_cmd)
3353 uint8_t cnt;
3354 device_reg_t *reg = ha->iobase;
3355 uint16_t data = 0;
3356 uint16_t reg_data;
3358 /* Send command to NVRAM. */
3360 nv_cmd <<= 5;
3361 for (cnt = 0; cnt < 11; cnt++)
3363 if (nv_cmd & BIT_31)
3364 qla1280_nv_write(ha, NV_DATA_OUT);
3365 else
3366 qla1280_nv_write(ha, 0);
3367 nv_cmd <<= 1;
3370 /* Read data from NVRAM. */
3372 for (cnt = 0; cnt < 16; cnt++)
3374 WRT_REG_WORD(&reg->nvram, NV_SELECT+NV_CLOCK);
3375 /* qla1280_nv_delay(ha); */
3376 NVRAM_DELAY();
3377 data <<= 1;
3378 reg_data = RD_REG_WORD(&reg->nvram);
3379 if (reg_data & NV_DATA_IN)
3380 data |= BIT_0;
3381 WRT_REG_WORD(&reg->nvram, NV_SELECT);
3382 /* qla1280_nv_delay(ha); */
3383 NVRAM_DELAY();
3386 /* Deselect chip. */
3388 WRT_REG_WORD(&reg->nvram, NV_DESELECT);
3389 /* qla1280_nv_delay(ha); */
3390 NVRAM_DELAY();
3392 return(data);
3395 STATIC void
3396 qla1280_nv_write(scsi_qla_host_t *ha, uint16_t data)
3398 device_reg_t *reg = ha->iobase;
3400 WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
3401 NVRAM_DELAY();
3402 /* qla1280_nv_delay(ha); */
3403 WRT_REG_WORD(&reg->nvram, data | NV_SELECT | NV_CLOCK);
3404 /* qla1280_nv_delay(ha); */
3405 NVRAM_DELAY();
3406 WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
3407 /* qla1280_nv_delay(ha); */
3408 NVRAM_DELAY();
3411 STATIC void
3412 qla1280_nv_delay(scsi_qla_host_t *ha)
3414 device_reg_t *reg = ha->iobase;
3415 int cnt = NV_DELAY_COUNT;
3416 uint16_t data = 0;
3418 while (cnt--)
3419 data |= RD_REG_WORD(&reg->nvram);
3423 * Mailbox Command
3424 * Issue mailbox command and waits for completion.
3426 * Input:
3427 * ha = adapter block pointer.
3428 * mr = mailbox registers to load.
3429 * mb = data pointer for mailbox registers.
3431 * Output:
3432 * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
3434 * Returns:
3435 * 0 = success
3437 STATIC uint8_t
3438 qla1280_mailbox_command(scsi_qla_host_t *ha, uint8_t mr, uint16_t *mb)
3440 device_reg_t *reg = ha->iobase;
3441 uint8_t status = 0;
3442 uint32_t cnt;
3443 uint16_t *optr, *iptr;
3444 uint16_t data;
3445 srb_t *done_q_first = 0;
3446 srb_t *done_q_last = 0;
3447 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
3448 unsigned long cpu_flags = 0;
3449 #endif
3451 #ifdef QL_DEBUG_LEVEL_3
3452 ENTER("qla1280_mailbox_command");
3453 #endif
3455 /* Acquire interrupt specific lock */
3456 QLA1280_INTR_LOCK(ha);
3457 DRIVER_LOCK
3458 ha->flags.mbox_busy = TRUE;
3460 /* Load mailbox registers. */
3461 optr = (uint16_t *)&reg->mailbox0;
3462 iptr = mb;
3463 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++)
3465 if (mr & BIT_0)
3467 WRT_REG_WORD(optr, (*iptr));
3470 mr >>= 1;
3471 optr++;
3472 iptr++;
3474 /* Issue set host interrupt command. */
3475 ha->flags.mbox_int = FALSE;
3476 WRT_REG_WORD(&reg->host_cmd, HC_SET_HOST_INT);
3477 data = qla1280_debounce_register(&reg->istatus);
3479 /* Wait for 30 seconds for command to finish. */
3480 for (cnt = 30000000; cnt > 0 && !ha->flags.mbox_int; cnt--)
3482 /* Check for pending interrupts. */
3483 if (data & RISC_INT)
3485 qla1280_isr(ha, (srb_t **)&done_q_first, (srb_t **)&done_q_last);
3487 SYS_DELAY(1);
3488 data = RD_REG_WORD(&reg->istatus);
3491 /* Check for mailbox command timeout. */
3492 if ( !cnt )
3494 #ifdef QL_DEBUG_LEVEL_2
3495 qla1280_print(
3496 "qla1280_mailbox_command: **** Command Timeout, mailbox0 = ");
3497 qla1280_output_number((uint32_t)mb[0], 16);
3498 qla1280_print(" ****\n\r");
3499 #endif
3500 ha->flags.isp_abort_needed = TRUE;
3501 status = 1;
3503 else if (ha->mailbox_out[0] != MBS_CMD_CMP)
3504 status = 1;
3506 /* Load return mailbox registers. */
3507 optr = mb;
3508 iptr = (uint16_t *)&ha->mailbox_out[0];
3509 mr = MAILBOX_REGISTER_COUNT;
3510 while (mr--)
3511 *optr++ = *iptr++;
3513 /* Go check for any response interrupts pending. */
3514 ha->flags.mbox_busy = FALSE;
3515 qla1280_isr(ha, (srb_t **)&done_q_first, (srb_t **)&done_q_last);
3517 /* Release interrupt specific lock */
3518 QLA1280_INTR_UNLOCK(ha);
3519 DRIVER_UNLOCK
3521 if (ha->flags.isp_abort_needed)
3522 qla1280_abort_isp(ha);
3524 if (ha->flags.reset_marker)
3525 qla1280_rst_aen(ha);
3527 if (done_q_first)
3528 qla1280_done(ha, (srb_t **)&done_q_first, (srb_t **)&done_q_last);
3530 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3531 if (status)
3533 qla1280_print("qla1280_mailbox_command: **** FAILED, mailbox0 = ");
3534 qla1280_output_number((uint32_t)mb[0], 16);
3535 qla1280_print(" ****\n\r");
3537 #endif
3538 #ifdef QL_DEBUG_LEVEL_3
3539 else
3540 LEAVE("qla1280_mailbox_command");
3541 #endif
3542 return(status);
3546 * qla1280_poll
3547 * Polls ISP for interrupts.
3549 * Input:
3550 * ha = adapter block pointer.
3552 STATIC void
3553 qla1280_poll(scsi_qla_host_t *ha)
3555 device_reg_t *reg = ha->iobase;
3556 uint16_t data;
3557 srb_t *done_q_first = 0;
3558 srb_t *done_q_last = 0;
3560 #ifdef QL_DEBUG_LEVEL_3
3561 /* ENTER("qla1280_poll"); */
3562 #endif
3564 /* Acquire interrupt specific lock */
3565 QLA1280_INTR_LOCK(ha);
3567 /* Check for pending interrupts. */
3568 data = RD_REG_WORD(&reg->istatus);
3569 if (data & RISC_INT)
3570 qla1280_isr(ha, (srb_t **)&done_q_first, (srb_t **)&done_q_last);
3572 /* Release interrupt specific lock */
3573 QLA1280_INTR_UNLOCK(ha);
3575 if (!ha->flags.mbox_busy)
3577 if (ha->flags.isp_abort_needed)
3578 qla1280_abort_isp(ha);
3579 if (ha->flags.reset_marker)
3580 qla1280_rst_aen(ha);
3583 if (done_q_first)
3584 qla1280_done(ha, (srb_t **)&done_q_first, (srb_t **)&done_q_last);
3586 #ifdef QL_DEBUG_LEVEL_3
3587 /* LEAVE("qla1280_poll"); */
3588 #endif
3592 * qla1280_bus_reset
3593 * Issue SCSI bus reset.
3595 * Input:
3596 * ha = adapter block pointer.
3597 * b = SCSI bus number.
3599 * Returns:
3600 * 0 = success
3602 STATIC uint8_t
3603 qla1280_bus_reset(scsi_qla_host_t *ha, uint8_t b)
3605 uint8_t status;
3606 uint16_t mb[MAILBOX_REGISTER_COUNT];
3608 #ifdef QL_DEBUG_LEVEL_3
3609 qla1280_print("qla1280_bus_reset: entered\n\r");
3610 #endif
3611 if( qla1280_verbose )
3613 printk("scsi(%d): Resetting SCSI BUS (%d)\n",(int)ha->host_no,b);
3616 mb[0] = MBC_BUS_RESET;
3617 mb[1] = ha->bus_settings[b].bus_reset_delay;
3618 mb[2] = (uint16_t)b;
3619 status = qla1280_mailbox_command(ha, BIT_2|BIT_1|BIT_0, &mb[0]);
3621 if (status)
3623 if (ha->bus_settings[b].failed_reset_count > 2) /* dg - 03/13/99 */
3624 ha->bus_settings[b].scsi_bus_dead = TRUE;
3625 ha->bus_settings[b].failed_reset_count++;
3627 else
3629 QLA1280_DELAY(4);
3630 ha->bus_settings[b].scsi_bus_dead = FALSE; /* dg - 03/13/99 */
3631 ha->bus_settings[b].failed_reset_count = 0;
3632 /* Issue marker command. */
3633 qla1280_marker(ha, b, 0, 0, MK_SYNC_ALL);
3635 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3636 if (status)
3637 qla1280_print("qla1280_bus_reset: **** FAILED ****\n\r");
3638 #endif
3639 #ifdef QL_DEBUG_LEVEL_3
3640 else
3641 qla1280_print("qla1280_bus_reset: exiting normally\n\r");
3642 #endif
3643 return(status);
3647 * qla1280_device_reset
3648 * Issue bus device reset message to the target.
3650 * Input:
3651 * ha = adapter block pointer.
3652 * b = SCSI BUS number.
3653 * t = SCSI ID.
3655 * Returns:
3656 * 0 = success
3658 STATIC uint8_t
3659 qla1280_device_reset(scsi_qla_host_t *ha, uint8_t b, uint32_t t)
3661 uint8_t status;
3662 uint16_t mb[MAILBOX_REGISTER_COUNT];
3664 #ifdef QL_DEBUG_LEVEL_3
3665 ENTER("qla1280_device_reset");
3666 #endif
3668 mb[0] = MBC_ABORT_TARGET;
3669 mb[1] = (b ? (t | BIT_7) : t) << 8;
3670 mb[2] = 1;
3671 status = qla1280_mailbox_command(ha, BIT_2|BIT_1|BIT_0, &mb[0]);
3673 /* Issue marker command. */
3674 qla1280_marker(ha, b, t, 0, MK_SYNC_ID);
3676 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3677 if (status)
3678 qla1280_print("qla1280_device_reset: **** FAILED ****\n\r");
3679 #endif
3680 #ifdef QL_DEBUG_LEVEL_3
3681 else
3682 LEAVE("qla1280_device_reset");
3683 #endif
3684 return(status);
3688 * qla1280_abort_device
3689 * Issue an abort message to the device
3691 * Input:
3692 * ha = adapter block pointer.
3693 * b = SCSI BUS.
3694 * t = SCSI ID.
3695 * l = SCSI LUN.
3697 * Returns:
3698 * 0 = success
3700 STATIC uint8_t
3701 qla1280_abort_device(scsi_qla_host_t *ha, uint8_t b, uint32_t t, uint32_t l)
3703 uint8_t status;
3704 uint16_t mb[MAILBOX_REGISTER_COUNT];
3706 #ifdef QL_DEBUG_LEVEL_3
3707 ENTER("qla1280_abort_device");
3708 #endif
3710 mb[0] = MBC_ABORT_DEVICE;
3711 mb[1] = (b ? t | BIT_7 : t) << 8 | l;
3712 status = qla1280_mailbox_command(ha, BIT_1|BIT_0, &mb[0]);
3714 /* Issue marker command. */
3715 qla1280_marker(ha, b, t, l, MK_SYNC_ID_LUN);
3717 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3718 if (status)
3719 qla1280_print("qla1280_abort_device: **** FAILED ****\n\r");
3720 #endif
3721 #ifdef QL_DEBUG_LEVEL_3
3722 else
3723 LEAVE("qla1280_abort_device");
3724 #endif
3725 return(status);
3729 * qla1280_abort_command
3730 * Abort command aborts a specified IOCB.
3732 * Input:
3733 * ha = adapter block pointer.
3734 * sp = SB structure pointer.
3736 * Returns:
3737 * 0 = success
3739 STATIC uint8_t
3740 qla1280_abort_command(scsi_qla_host_t *ha, srb_t *sp)
3742 uint8_t status;
3743 uint16_t mb[MAILBOX_REGISTER_COUNT];
3744 uint32_t b, t, l;
3745 uint32_t handle;
3747 #ifdef QL_DEBUG_LEVEL_3
3748 ENTER("qla1280_abort_command");
3749 #endif
3751 /* Locate handle number. */
3752 for (handle = 0; handle < MAX_OUTSTANDING_COMMANDS; handle++)
3753 if (ha->outstanding_cmds[handle] == sp)
3754 break;
3756 b = SCSI_BUS_32(sp->cmd);
3757 t = SCSI_TCN_32(sp->cmd);
3758 l = SCSI_LUN_32(sp->cmd);
3760 mb[0] = MBC_ABORT_COMMAND;
3761 mb[1] = (b ? t | BIT_7 : t) << 8 | l;
3762 mb[2] = handle >> 16;
3763 mb[3] = (uint16_t)handle;
3764 status = qla1280_mailbox_command(ha, BIT_3|BIT_2|BIT_1|BIT_0, &mb[0]);
3766 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
3767 if (status)
3768 qla1280_print("qla1280_abort_command: **** FAILED ****\n\r");
3769 #endif
3770 sp->flags |= SRB_ABORT_PENDING;
3772 LEAVE("qla1280_abort_command");
3773 return(status);
3777 * qla1280_reset_adapter
3778 * Reset adapter.
3780 * Input:
3781 * ha = adapter block pointer.
3783 STATIC void
3784 qla1280_reset_adapter(scsi_qla_host_t *ha)
3786 device_reg_t *reg = ha->iobase;
3788 #ifdef QL_DEBUG_LEVEL_3
3789 ENTER("qla1280_reset_adapter");
3790 #endif
3792 /* Disable ISP chip */
3793 ha->flags.online = FALSE;
3794 WRT_REG_WORD(&reg->ictrl, ISP_RESET);
3795 WRT_REG_WORD(&reg->host_cmd, HC_RESET_RISC);
3796 WRT_REG_WORD(&reg->host_cmd, HC_RELEASE_RISC);
3797 WRT_REG_WORD(&reg->host_cmd, HC_DISABLE_BIOS);
3799 #ifdef QL_DEBUG_LEVEL_3
3800 LEAVE("qla1280_reset_adapter");
3801 #endif
3805 * Issue marker command.
3806 * Function issues marker IOCB.
3808 * Input:
3809 * ha = adapter block pointer.
3810 * b = SCSI BUS number
3811 * t = SCSI ID
3812 * l = SCSI LUN
3813 * type = marker modifier
3815 STATIC void
3816 qla1280_marker(scsi_qla_host_t *ha, uint8_t b, uint32_t t, uint32_t l, uint8_t type)
3818 mrk_entry_t *pkt;
3820 #ifdef QL_DEBUG_LEVEL_3
3821 ENTER("qla1280_marker");
3822 #endif
3824 /* Get request packet. */
3825 if ( (pkt = (mrk_entry_t *)qla1280_req_pkt(ha)) )
3827 pkt->entry_type = MARKER_TYPE;
3828 pkt->lun = (uint8_t)l;
3829 pkt->target = (uint8_t)(b ? (t | BIT_7) : t);
3830 pkt->modifier = type;
3832 /* Issue command to ISP */
3833 qla1280_isp_cmd(ha);
3836 #ifdef QL_DEBUG_LEVEL_3
3837 LEAVE("qla1280_marker");
3838 #endif
3841 #if QLA1280_64BIT_SUPPORT
3843 * qla1280_64bit_start_scsi
3844 * The start SCSI is responsible for building request packets on
3845 * request ring and modifying ISP input pointer.
3847 * Input:
3848 * ha = adapter block pointer.
3849 * sp = SB structure pointer.
3851 * Returns:
3852 * 0 = success, was able to issue command.
3854 STATIC uint8_t
3855 qla1280_64bit_start_scsi(scsi_qla_host_t *ha, srb_t *sp)
3857 device_reg_t *reg = ha->iobase;
3858 uint8_t status = 0;
3859 Scsi_Cmnd *cmd = sp->cmd;
3860 uint32_t cnt;
3861 cmd_a64_entry_t *pkt;
3862 uint16_t req_cnt;
3863 uint16_t seg_cnt;
3864 struct scatterlist *sg = (struct scatterlist *) NULL;
3865 uint32_t *dword_ptr;
3867 #ifdef QL_DEBUG_LEVEL_3
3868 ENTER("qla1280_64bit_start_scsi:");
3869 #endif
3871 if( qla1280_check_for_dead_scsi_bus(ha, sp) )
3873 return(0);
3876 /* Calculate number of entries and segments required. */
3877 seg_cnt = 0;
3878 req_cnt = 1;
3879 if (cmd->use_sg)
3881 seg_cnt = cmd->use_sg;
3882 sg = (struct scatterlist *) cmd->request_buffer;
3884 if (seg_cnt > 2)
3886 req_cnt += (uint16_t)(seg_cnt - 2) / 5;
3887 if ((uint16_t)(seg_cnt - 2) % 5)
3888 req_cnt++;
3891 else if (cmd->request_bufflen) /* If data transfer. */
3893 DEBUG(printk("Single data transfer (0x%x)\n",cmd->request_bufflen));
3894 seg_cnt = 1;
3897 /* Acquire ring specific lock */
3898 QLA1280_RING_LOCK(ha);
3900 if ((uint16_t)(req_cnt + 2) >= ha->req_q_cnt)
3902 /* Calculate number of free request entries. */
3903 cnt = RD_REG_WORD(&reg->mailbox4);
3904 if (ha->req_ring_index < cnt)
3905 ha->req_q_cnt = cnt - ha->req_ring_index;
3906 else
3907 ha->req_q_cnt = REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3910 /* If room for request in request ring. */
3911 if ((uint16_t)(req_cnt + 2) < ha->req_q_cnt)
3913 /* Check for room in outstanding command list. */
3914 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS &&
3915 ha->outstanding_cmds[cnt] != 0; cnt++)
3918 if (cnt < MAX_OUTSTANDING_COMMANDS)
3920 ha->outstanding_cmds[cnt] = sp;
3921 ha->req_q_cnt -= req_cnt;
3922 CMD_HANDLE(sp->cmd) = (unsigned char *) (u_long) cnt;
3925 * Build command packet.
3927 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
3929 pkt->entry_type = COMMAND_A64_TYPE;
3930 pkt->entry_count = (uint8_t)req_cnt;
3931 pkt->sys_define = (uint8_t)ha->req_ring_index;
3932 pkt->handle = (uint32_t)cnt;
3934 /* Zero out remaining portion of packet. */
3935 dword_ptr = (uint32_t *)pkt + 2;
3936 for (cnt = 2; cnt < REQUEST_ENTRY_SIZE/4; cnt++)
3937 *dword_ptr++ = 0;
3939 /* Set ISP command timeout. */
3940 pkt->timeout = (uint16_t)30;
3942 /* Set device target ID and LUN */
3943 pkt->lun = SCSI_LUN_32(cmd);
3944 pkt->target = SCSI_BUS_32(cmd) ?
3945 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3947 /* Enable simple tag queuing if device supports it. */
3948 if (cmd->device->tagged_queue )
3949 pkt->control_flags |= BIT_3;
3951 /* Load SCSI command packet. */
3952 pkt->cdb_len = (uint16_t)CMD_CDBLEN(cmd);
3953 BCOPY(&(CMD_CDBP(cmd)), pkt->scsi_cdb, pkt->cdb_len);
3954 DEBUG(printk("Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]));
3957 * Load data segments.
3959 if (seg_cnt) /* If data transfer. */
3961 /* Set transfer direction. */
3962 if ( (cmd->data_cmnd[0] == WRITE_6) )
3963 pkt->control_flags |= BIT_6;
3964 else
3965 pkt->control_flags |= (BIT_5|BIT_6);
3967 sp->dir = pkt->control_flags & (BIT_5|BIT_6);
3969 /* Set total data segment count. */
3970 pkt->dseg_count = seg_cnt;
3972 /* Setup packet address segment pointer. */
3973 dword_ptr = (uint32_t *)&pkt->dseg_0_address;
3975 if (cmd->use_sg) /* If scatter gather */
3977 /* Load command entry data segments. */
3978 for (cnt = 0; cnt < 2 && seg_cnt; cnt++, seg_cnt--)
3980 DEBUG(sprintf(debug_buff,"SG Segment ap=0x%p, len=0x%x\n\r",sg->address,sg->length));
3981 DEBUG(qla1280_print(debug_buff));
3982 *dword_ptr++ = cpu_to_le32(VIRT_TO_BUS_LOW(sg->address));
3983 *dword_ptr++ = cpu_to_le32(VIRT_TO_BUS_HIGH(sg->address));
3984 *dword_ptr++ = sg->length;
3985 sg++;
3987 #ifdef QL_DEBUG_LEVEL_5
3988 qla1280_print(
3989 "qla1280_64bit_start_scsi: Scatter/gather command packet data - ");
3990 qla1280_print("b ");
3991 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd), 10);
3992 qla1280_print(" t ");
3993 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd), 10);
3994 qla1280_print(" d ");
3995 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd), 10);
3996 qla1280_print("\n\r");
3997 qla1280_dump_buffer((caddr_t)pkt, REQUEST_ENTRY_SIZE);
3998 #endif
4000 * Build continuation packets.
4002 while (seg_cnt > 0)
4004 /* Adjust ring index. */
4005 ha->req_ring_index++;
4006 if (ha->req_ring_index == REQUEST_ENTRY_CNT)
4008 ha->req_ring_index = 0;
4009 ha->request_ring_ptr = ha->request_ring;
4011 else
4012 ha->request_ring_ptr++;
4014 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
4016 /* Zero out packet. */
4017 dword_ptr = (uint32_t *)pkt;
4018 for (cnt = 0;cnt < REQUEST_ENTRY_SIZE/4; cnt++)
4019 *dword_ptr++ = 0;
4021 /* Load packet defaults. */
4022 ((cont_a64_entry_t *)pkt)->entry_type =
4023 CONTINUE_A64_TYPE;
4024 ((cont_a64_entry_t *)pkt)->entry_count = 1;
4025 ((cont_a64_entry_t *)pkt)->sys_define = (uint8_t)
4026 ha->req_ring_index;
4028 /* Setup packet address segment pointer. */
4029 dword_ptr = (uint32_t *)
4030 &((cont_a64_entry_t *)pkt)->dseg_0_address;
4032 /* Load continuation entry data segments. */
4033 for (cnt = 0; cnt < 5 && seg_cnt; cnt++, seg_cnt--)
4035 *dword_ptr++ = cpu_to_le32(VIRT_TO_BUS_LOW(sg->address));
4036 *dword_ptr++ = cpu_to_le32(VIRT_TO_BUS_HIGH(sg->address));
4037 *dword_ptr++ = sg->length;
4038 sg++;
4040 #ifdef QL_DEBUG_LEVEL_5
4041 qla1280_print(
4042 "qla1280_64bit_start_scsi: continuation packet data - c");
4043 qla1280_print(" b ");
4044 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd), 10);
4046 qla1280_print(" t ");
4047 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd), 10);
4048 qla1280_print(" d ");
4049 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd), 10);
4050 qla1280_print("\n\r");
4051 qla1280_dump_buffer((caddr_t)pkt, REQUEST_ENTRY_SIZE);
4052 #endif
4055 else /* No scatter gather data transfer */
4057 *dword_ptr++ = cpu_to_le32(VIRT_TO_BUS_LOW(cmd->request_buffer));
4058 *dword_ptr++ = cpu_to_le32(VIRT_TO_BUS_HIGH(cmd->request_buffer));
4059 *dword_ptr = (uint32_t) cmd->request_bufflen;
4060 #ifdef QL_DEBUG_LEVEL_5
4061 qla1280_print(
4062 "qla1280_64bit_start_scsi: No scatter/gather command packet data - c");
4063 qla1280_print(" b ");
4064 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd), 10);
4065 qla1280_print(" t ");
4066 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd), 10);
4067 qla1280_print(" d ");
4068 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd), 10);
4069 qla1280_print("\n\r");
4070 qla1280_dump_buffer((caddr_t)pkt, REQUEST_ENTRY_SIZE);
4071 #endif
4074 #ifdef QL_DEBUG_LEVEL_5
4075 else /* No data transfer */
4077 *dword_ptr++ = (uint32_t) 0;
4078 *dword_ptr++ = (uint32_t) 0;
4079 *dword_ptr = (uint32_t) 0;
4080 qla1280_print(
4081 "qla1280_64bit_start_scsi: No data, command packet data - c");
4082 qla1280_print(" b ");
4083 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd), 10);
4084 qla1280_print(" t ");
4085 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd), 10);
4086 qla1280_print(" d ");
4087 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd), 10);
4088 qla1280_print("\n\r");
4089 qla1280_dump_buffer((caddr_t)pkt, REQUEST_ENTRY_SIZE);
4091 #endif
4092 /* Adjust ring index. */
4093 ha->req_ring_index++;
4094 if (ha->req_ring_index == REQUEST_ENTRY_CNT)
4096 ha->req_ring_index = 0;
4097 ha->request_ring_ptr = ha->request_ring;
4099 else
4100 ha->request_ring_ptr++;
4102 /* Set chip new ring index. */
4103 WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
4105 else
4107 status = 1;
4108 #ifdef QL_DEBUG_LEVEL_2
4109 qla1280_print(
4110 "qla1280_64bit_start_scsi: NO ROOM IN OUTSTANDING ARRAY\n\r");
4111 qla1280_print(" req_q_cnt=");
4112 qla1280_output_number((uint32_t)ha->req_q_cnt, 16);
4113 #endif
4116 else
4118 status = 1;
4119 #ifdef QL_DEBUG_LEVEL_2
4120 qla1280_print("qla1280_64bit_start_scsi: in-ptr=");
4121 qla1280_output_number((uint32_t)ha->req_ring_index, 16);
4122 qla1280_print(" req_q_cnt=");
4123 qla1280_output_number((uint32_t)ha->req_q_cnt, 16);
4124 qla1280_print(" req_cnt=");
4125 qla1280_output_number((uint32_t)req_cnt, 16);
4126 qla1280_print("\n\r");
4127 #endif
4130 /* Release ring specific lock */
4131 QLA1280_RING_UNLOCK(ha);
4133 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4134 if (status)
4135 qla1280_print("qla1280_64bit_start_scsi: **** FAILED ****\n\r");
4136 #endif
4137 #ifdef QL_DEBUG_LEVEL_3
4138 else
4139 qla1280_print("qla1280_64bit_start_scsi: exiting normally\n\r");
4140 #endif
4141 return(status);
4143 #endif /* QLA1280_64BIT_SUPPORT */
4146 * qla1280_32bit_start_scsi
4147 * The start SCSI is responsible for building request packets on
4148 * request ring and modifying ISP input pointer.
4150 * The Qlogic firmware interface allows every queue slot to have a SCSI
4151 * command and up to 4 scatter/gather (SG) entries. If we need more
4152 * than 4 SG entries, then continuation entries are used that can
4153 * hold another 7 entries each. The start routine determines if there
4154 * is eought empty slots then build the combination of requests to
4155 * fulfill the OS request.
4157 * Input:
4158 * ha = adapter block pointer.
4159 * sp = SCSI Request Block structure pointer.
4161 * Returns:
4162 * 0 = success, was able to issue command.
4164 STATIC uint8_t
4165 qla1280_32bit_start_scsi(scsi_qla_host_t *ha, srb_t *sp)
4167 device_reg_t *reg = ha->iobase;
4168 uint8_t status = 0;
4169 Scsi_Cmnd *cmd = sp->cmd;
4170 uint32_t cnt;
4171 cmd_entry_t *pkt;
4172 uint16_t req_cnt;
4173 uint16_t seg_cnt;
4174 struct scatterlist *sg = (struct scatterlist *) NULL;
4175 uint8_t *data_ptr;
4176 uint32_t *dword_ptr;
4178 ENTER("qla1280_32bit_start_scsi");
4181 if( qla1280_check_for_dead_scsi_bus(ha, sp) )
4183 return(0);
4186 /* Calculate number of entries and segments required. */
4187 req_cnt = 1;
4188 if (cmd->use_sg)
4191 * We must build an SG list in adapter format, as the kernel's SG list
4192 * cannot be used directly because of data field size (__alpha__)
4193 * differences and the kernel SG list uses virtual addresses where
4194 * we need physical addresses.
4196 seg_cnt = cmd->use_sg;
4197 sg = (struct scatterlist *) cmd->request_buffer;
4199 * if greater than four sg entries then we need to allocate
4200 * continuation entries
4202 if (seg_cnt > 4)
4204 req_cnt += (uint16_t)(seg_cnt - 4) / 7;
4205 if ((uint16_t)(seg_cnt - 4) % 7)
4206 req_cnt++;
4208 DEBUG(sprintf(debug_buff,"S/G for data transfer -num segs(%d), req blk cnt(%d)\n\r",seg_cnt,req_cnt));
4209 DEBUG(qla1280_print(debug_buff));
4211 else if (cmd->request_bufflen) /* If data transfer. */
4213 DEBUG(printk("Single data transfer (0x%x)\n",cmd->request_bufflen));
4214 seg_cnt = 1;
4216 else
4218 DEBUG(printk("No data transfer \n"));
4219 seg_cnt = 0;
4222 /* Acquire ring specific lock */
4223 QLA1280_RING_LOCK(ha);
4225 if ((uint16_t)(req_cnt + 2) >= ha->req_q_cnt)
4227 /* Calculate number of free request entries. */
4228 cnt = RD_REG_WORD(&reg->mailbox4);
4229 if (ha->req_ring_index < cnt)
4230 ha->req_q_cnt = cnt - ha->req_ring_index;
4231 else
4232 ha->req_q_cnt = REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
4235 DEBUG(sprintf(debug_buff,"Number of free entries = (%d)\n\r",ha->req_q_cnt));
4236 DEBUG(qla1280_print(debug_buff));
4237 /* If room for request in request ring. */
4238 if ((uint16_t)(req_cnt + 2) < ha->req_q_cnt)
4240 /* Check for empty slot in outstanding command list. */
4241 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS &&
4242 (ha->outstanding_cmds[cnt] != 0); cnt++)
4245 if (cnt < MAX_OUTSTANDING_COMMANDS)
4247 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)cnt;
4248 ha->outstanding_cmds[cnt] = sp;
4249 ha->req_q_cnt -= req_cnt;
4252 * Build command packet.
4254 pkt = (cmd_entry_t *)ha->request_ring_ptr;
4256 pkt->entry_type = COMMAND_TYPE;
4257 pkt->entry_count = (uint8_t)req_cnt;
4258 pkt->sys_define = (uint8_t)ha->req_ring_index;
4259 pkt->handle = (uint32_t)cnt;
4261 /* Zero out remaining portion of packet. */
4262 dword_ptr = (uint32_t *)pkt + 2;
4263 for (cnt = 2; cnt < REQUEST_ENTRY_SIZE/4; cnt++)
4264 *dword_ptr++ = 0;
4266 /* Set ISP command timeout. */
4267 pkt->timeout = (uint16_t)30;
4269 /* Set device target ID and LUN */
4270 pkt->lun = SCSI_LUN_32(cmd);
4271 pkt->target = SCSI_BUS_32(cmd) ?
4272 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
4274 /* Enable simple tag queuing if device supports it. */
4275 if (cmd->device->tagged_queue )
4276 pkt->control_flags |= BIT_3;
4278 /* Load SCSI command packet. */
4279 pkt->cdb_len = (uint16_t)CMD_CDBLEN(cmd);
4280 data_ptr = (uint8_t *) &(CMD_CDBP(cmd));
4281 for (cnt = 0; cnt < pkt->cdb_len; cnt++)
4282 pkt->scsi_cdb[cnt] = *data_ptr++;
4283 DEBUG(printk("Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]));
4285 * Load data segments.
4287 if (seg_cnt)
4289 DEBUG(printk("loading data segments..\n"));
4290 /* Set transfer direction (READ and WRITE) */
4291 /* Linux doesn't tell us */
4294 * 3/10 dg - Normally, we should need this check with our F/W
4295 * but because of a small issue with it we do.
4297 * For block devices, cmd->request.cmd has the operation
4298 * For character devices, this isn't always set properly, so
4299 * we need to check data_cmnd[0]. This catches the conditions
4300 * for st.c, but not sg. Generic commands are pass down to us.
4302 if ( (cmd->data_cmnd[0] == WRITE_6) )
4303 pkt->control_flags |= BIT_6;
4304 else
4305 pkt->control_flags |= (BIT_5|BIT_6);
4307 sp->dir = pkt->control_flags & (BIT_5|BIT_6);
4309 /* Set total data segment count. */
4310 pkt->dseg_count = seg_cnt;
4312 /* Setup packet address segment pointer. */
4313 dword_ptr = (uint32_t *)&pkt->dseg_0_address;
4315 if (cmd->use_sg) /* If scatter gather */
4317 DEBUG(qla1280_print("Building S/G data segments..\n\r"));
4318 DEBUG(qla1280_dump_buffer((caddr_t)sg, 4*16 ));
4319 /* Load command entry data segments. */
4320 for (cnt = 0; cnt < 4 && seg_cnt; cnt++, seg_cnt--)
4322 *dword_ptr++ = (uint32_t) cpu_to_le32(VIRT_TO_BUS(sg->address));
4323 *dword_ptr++ = sg->length;
4324 DEBUG(sprintf(debug_buff,"SG Segment ap=0x%p, len=0x%x\n\r",sg->address,sg->length));
4325 DEBUG(qla1280_print(debug_buff));
4326 sg++;
4329 * Build continuation packets.
4331 while (seg_cnt > 0)
4333 /* Adjust ring index. */
4334 ha->req_ring_index++;
4335 if (ha->req_ring_index == REQUEST_ENTRY_CNT)
4337 ha->req_ring_index = 0;
4338 ha->request_ring_ptr = ha->request_ring;
4340 else
4341 ha->request_ring_ptr++;
4343 pkt = (cmd_entry_t *)ha->request_ring_ptr;
4345 /* Zero out packet. */
4346 dword_ptr = (uint32_t *)pkt;
4347 for (cnt = 0;cnt < REQUEST_ENTRY_SIZE/4; cnt++)
4348 *dword_ptr++ = 0;
4350 /* Load packet defaults. */
4351 ((cont_entry_t *)pkt)->entry_type =
4352 CONTINUE_TYPE;
4353 ((cont_entry_t *)pkt)->entry_count = 1;
4355 ((cont_entry_t *)pkt)->sys_define = (uint8_t)
4356 ha->req_ring_index;
4358 /* Setup packet address segment pointer. */
4359 dword_ptr = (uint32_t *)
4360 &((cont_entry_t *)pkt)->dseg_0_address;
4362 /* Load continuation entry data segments. */
4363 for (cnt = 0; cnt < 7 && seg_cnt; cnt++, seg_cnt--)
4365 *dword_ptr++ = (u_int) cpu_to_le32(VIRT_TO_BUS(sg->address));
4366 *dword_ptr++ = sg->length;
4367 sg++;
4369 #ifdef QL_DEBUG_LEVEL_5
4370 qla1280_print(
4371 "qla1280_32bit_start_scsi: continuation packet data - scsi(");
4372 qla1280_output_number((uint32_t)SCSI_BUS_32(cmd), 10);
4373 qla1280_print(":");
4374 qla1280_output_number((uint32_t)SCSI_TCN_32(cmd), 10);
4375 qla1280_print(":");
4376 qla1280_output_number((uint32_t)SCSI_LUN_32(cmd), 10);
4377 qla1280_print(")\n\r");
4378 qla1280_dump_buffer((caddr_t)pkt, REQUEST_ENTRY_SIZE);
4379 #endif
4382 else /* No scatter gather data transfer */
4384 *dword_ptr++ = (uint32_t) cpu_to_le32(VIRT_TO_BUS(cmd->request_buffer));
4385 *dword_ptr = (uint32_t) cmd->request_bufflen;
4386 DEBUG(printk("Single Segment ap=0x%p, len=0x%x\n",cmd->request_buffer,cmd->request_bufflen));
4389 else /* No data transfer */
4391 *dword_ptr++ = (uint32_t) 0;
4392 *dword_ptr = (uint32_t) 0;
4393 #ifdef QL_DEBUG_LEVEL_5
4394 qla1280_print(
4395 "qla1280_32bit_start_scsi: No data, command packet data - ");
4396 qla1280_print("\n\r");
4397 qla1280_dump_buffer((caddr_t)pkt, REQUEST_ENTRY_SIZE);
4398 #endif
4400 #ifdef QL_DEBUG_LEVEL_5
4401 qla1280_print("qla1280_32bit_start_scsi: First IOCB block:\n\r");
4402 qla1280_dump_buffer((caddr_t)ha->request_ring_ptr, REQUEST_ENTRY_SIZE);
4403 #endif
4404 /* Adjust ring index. */
4405 ha->req_ring_index++;
4406 if (ha->req_ring_index == REQUEST_ENTRY_CNT)
4408 ha->req_ring_index = 0;
4409 ha->request_ring_ptr = ha->request_ring;
4411 else
4412 ha->request_ring_ptr++;
4414 /* Set chip new ring index. */
4415 DEBUG(qla1280_print("qla1280_32bit_start_scsi: Wakeup RISC for pending command\n\r"));
4416 ha->qthreads--;
4417 sp->u_start = jiffies;
4418 sp->flags |= SRB_SENT;
4419 ha->actthreads++;
4420 /* qla1280_output_number((uint32_t)ha->actthreads++, 16); */
4421 WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
4423 else
4425 status = 1;
4426 #ifdef QL_DEBUG_LEVEL_2
4427 qla1280_print(
4428 "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING ARRAY\n\r");
4429 qla1280_print(" req_q_cnt=");
4430 qla1280_output_number((uint32_t)ha->req_q_cnt, 16);
4431 qla1280_print("\n\r");
4432 #endif
4435 else
4437 status = 1;
4438 #ifdef QL_DEBUG_LEVEL_2
4439 /* qla1280_print("qla1280_32bit_start_scsi: in-ptr=");
4440 qla1280_output_number((uint32_t)ha->req_ring_index, 16);
4441 qla1280_print(" req_q_cnt=");
4442 qla1280_output_number((uint32_t)ha->req_q_cnt, 16);
4443 qla1280_print(" req_cnt=");
4444 qla1280_output_number((uint32_t)req_cnt, 16);
4445 qla1280_print("\n\r"); */
4446 #endif
4449 /* Release ring specific lock */
4450 QLA1280_RING_UNLOCK(ha);
4452 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4453 /* if (status)
4454 qla1280_print("qla1280_32bit_start_scsi: **** FAILED ****\n\r"); */
4455 #endif
4456 #ifdef QL_DEBUG_LEVEL_3
4457 LEAVE("qla1280_32bit_start_scsi");
4458 #endif
4459 return(status);
4463 * qla1280_req_pkt
4464 * Function is responsible for locking ring and
4465 * getting a zeroed out request packet.
4467 * Input:
4468 * ha = adapter block pointer.
4470 * Returns:
4471 * 0 = failed to get slot.
4473 STATIC request_t *
4474 qla1280_req_pkt(scsi_qla_host_t *ha)
4476 device_reg_t *reg = ha->iobase;
4477 request_t *pkt = 0;
4478 uint16_t cnt;
4479 uint32_t *dword_ptr;
4480 uint32_t timer;
4482 #ifdef QL_DEBUG_LEVEL_3
4483 ENTER("qla1280_req_pkt");
4484 #endif
4486 /* Wait for 30 seconds for slot. */
4487 for (timer = 15000000; timer; timer--)
4489 /* Acquire ring specific lock */
4490 QLA1280_RING_LOCK(ha);
4492 if (ha->req_q_cnt > 0)
4494 /* Calculate number of free request entries. */
4495 cnt = RD_REG_WORD(&reg->mailbox4);
4496 if (ha->req_ring_index < cnt)
4497 ha->req_q_cnt = cnt - ha->req_ring_index;
4498 else
4499 ha->req_q_cnt = REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
4502 /* Found empty request ring slot? */
4503 if (ha->req_q_cnt > 0)
4505 ha->req_q_cnt--;
4506 pkt = ha->request_ring_ptr;
4508 /* Zero out packet. */
4509 dword_ptr = (uint32_t *)pkt;
4510 for (cnt = 0; cnt < REQUEST_ENTRY_SIZE/4; cnt++)
4511 *dword_ptr++ = 0;
4513 /* Set system defined field. */
4514 pkt->sys_define = (uint8_t)ha->req_ring_index;
4516 /* Set entry count. */
4517 pkt->entry_count = 1;
4519 break;
4522 /* Release ring specific lock */
4523 QLA1280_RING_UNLOCK(ha);
4525 SYS_DELAY(2); /* 10 */
4527 /* Check for pending interrupts. */
4528 qla1280_poll(ha);
4531 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4532 if (!pkt)
4533 qla1280_print("qla1280_req_pkt: **** FAILED ****\n\r");
4534 #endif
4535 #ifdef QL_DEBUG_LEVEL_3
4536 else
4537 qla1280_print("qla1280_req_pkt: exiting normally\n\r");
4538 #endif
4539 return(pkt);
4543 * qla1280_isp_cmd
4544 * Function is responsible for modifying ISP input pointer.
4545 * Releases ring lock.
4547 * Input:
4548 * ha = adapter block pointer.
4550 STATIC void
4551 qla1280_isp_cmd(scsi_qla_host_t *ha)
4553 device_reg_t *reg = ha->iobase;
4555 #ifdef QL_DEBUG_LEVEL_3
4556 ENTER("qla1280_isp_cmd");
4557 #endif
4559 #ifdef QL_DEBUG_LEVEL_5
4560 qla1280_print("qla1280_isp_cmd: IOCB data:\n\r");
4561 qla1280_dump_buffer((caddr_t)ha->request_ring_ptr, REQUEST_ENTRY_SIZE);
4562 #endif
4564 /* Adjust ring index. */
4565 ha->req_ring_index++;
4566 if (ha->req_ring_index == REQUEST_ENTRY_CNT)
4568 ha->req_ring_index = 0;
4569 ha->request_ring_ptr = ha->request_ring;
4571 else
4572 ha->request_ring_ptr++;
4574 /* Set chip new ring index. */
4575 WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
4577 /* Release ring specific lock */
4578 QLA1280_RING_UNLOCK(ha);
4580 #ifdef QL_DEBUG_LEVEL_3
4581 LEAVE("qla1280_isp_cmd");
4582 #endif
4586 * qla1280_enable_lun
4587 * Issue enable LUN entry IOCB.
4589 * Input:
4590 * ha = adapter block pointer.
4591 * b = SCSI BUS number.
4592 * l = LUN number.
4594 STATIC void
4595 qla1280_enable_lun(scsi_qla_host_t *ha, uint8_t b, uint32_t l)
4597 elun_entry_t *pkt;
4599 #ifdef QL_DEBUG_LEVEL_3
4600 qla1280_print("qla1280_enable_lun: entered\n\r");
4601 #endif
4603 /* Get request packet. */
4605 if (pkt = (elun_entry_t *)qla1280_req_pkt(ha))
4607 pkt->entry_type = ENABLE_LUN_TYPE;
4608 pkt->lun = (uint16_t)(b ? l | BIT_15 : l);
4609 pkt->command_count = 32;
4610 pkt->immed_notify_count = 1;
4611 pkt->group_6_length = MAX_CMDSZ;
4612 pkt->group_7_length = MAX_CMDSZ;
4613 pkt->timeout = 0x30;
4615 qla1280_isp_cmd(ha);
4618 pkt = (elun_entry_t *)1;
4620 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4621 if (!pkt)
4622 qla1280_print("qla1280_enable_lun: **** FAILED ****\n\r");
4623 #endif
4624 #ifdef QL_DEBUG_LEVEL_3
4625 else
4626 qla1280_print("qla1280_enable_lun: exiting normally\n\r");
4627 #endif
4630 #if QL1280_TARGET_MODE_SUPPORT
4631 /****************************************************************************/
4632 /* Target Mode Support Functions. */
4633 /****************************************************************************/
4636 * qla1280_notify_ack
4637 * Issue notify acknowledge IOCB.
4638 * If sequence ID is zero, acknowledgement of
4639 * SCSI bus reset or bus device reset is assumed.
4641 * Input:
4642 * ha = adapter block pointer.
4643 * inotify = immediate notify entry pointer.
4645 STATIC void
4646 qla1280_notify_ack(scsi_qla_host_t *ha, notify_entry_t *inotify)
4648 nack_entry_t *pkt;
4650 #ifdef QL_DEBUG_LEVEL_3
4651 qla1280_print("qla1280_notify_ack: entered\n\r");
4652 #endif
4654 /* Get request packet. */
4655 if (pkt = (nack_entry_t *)qla1280_req_pkt(ha))
4657 pkt->entry_type = NOTIFY_ACK_TYPE;
4658 pkt->lun = inotify->lun;
4659 pkt->initiator_id = inotify->initiator_id;
4660 pkt->target_id = inotify->target_id;
4661 if (inotify->seq_id == 0)
4662 pkt->event = BIT_7;
4663 else
4664 pkt->seq_id = inotify->seq_id;
4666 /* Issue command to ISP */
4667 qla1280_isp_cmd(ha);
4670 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4671 if (!pkt)
4672 qla1280_print("qla1280_notify_ack: **** FAILED ****\n\r");
4673 #endif
4674 #ifdef QL_DEBUG_LEVEL_3
4675 else
4676 qla1280_print("qla1280_notify_ack: exiting normally\n\r");
4677 #endif
4681 * qla1280_immed_notify
4682 * Issue immediate notify IOCB for LUN 0.
4684 * Input:
4685 * ha = adapter block pointer.
4686 * inotify = immediate notify entry pointer.
4688 STATIC void
4689 qla1280_immed_notify(scsi_qla_host_t *ha, notify_entry_t *inotify)
4691 notify_entry_t *pkt;
4693 #ifdef QL_DEBUG_LEVEL_3
4694 qla1280_print("qla1280_immed_notify: entered\n\r");
4695 #endif
4697 /* Get request packet. */
4698 if (pkt = (notify_entry_t *)qla1280_req_pkt(ha))
4700 pkt->entry_type = IMMED_NOTIFY_TYPE;
4701 pkt->lun = inotify->lun;
4702 pkt->initiator_id = inotify->initiator_id;
4703 pkt->target_id = inotify->target_id;
4704 pkt->status = 1;
4706 /* Issue command to ISP */
4707 qla1280_isp_cmd(ha);
4710 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4711 if (!pkt)
4712 qla1280_print("qla1280_immed_notify: **** FAILED ****\n\r");
4713 #endif
4714 #ifdef QL_DEBUG_LEVEL_3
4715 else
4716 qla1280_print("qla1280_immed_notify: exiting normally\n\r");
4717 #endif
4721 * qla1280_accept_io
4722 * Issue accept target I/O IOCB for LUN 0.
4724 * Input:
4725 * ha = adapter block pointer.
4726 * ctio = ctio returned entry pointer.
4728 STATIC void
4729 qla1280_accept_io(scsi_qla_host_t *ha, ctio_ret_entry_t *ctio)
4731 atio_entry_t *pkt;
4733 #ifdef QL_DEBUG_LEVEL_3
4734 qla1280_print("qla1280_accept_io: entered\n\r");
4735 #endif
4737 /* Get request packet. */
4738 if (pkt = (atio_entry_t *)qla1280_req_pkt(ha))
4740 pkt->entry_type = ACCEPT_TGT_IO_TYPE;
4741 pkt->lun = ctio->lun;
4742 pkt->initiator_id = ctio->initiator_id;
4743 pkt->target_id = ctio->target_id;
4744 pkt->tag_value = ctio->tag_value;
4745 pkt->status = 1;
4747 /* Issue command to ISP */
4748 qla1280_isp_cmd(ha);
4751 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4752 if (!pkt)
4753 qla1280_print("qla1280_accept_io: **** FAILED ****\n\r");
4754 #endif
4755 #ifdef QL_DEBUG_LEVEL_3
4756 else
4757 qla1280_print("qla1280_accept_io: exiting normally\n\r");
4758 #endif
4762 * qla1280_64bit_continue_io
4763 * Issue continue target I/O IOCB.
4765 * Input:
4766 * ha = adapter block pointer.
4767 * atio = atio pointer.
4768 * len = total bytecount.
4769 * addr = physical address pointer.
4771 STATIC void
4772 qla1280_64bit_continue_io(scsi_qla_host_t *ha, atio_entry_t *atio, uint32_t len,
4773 paddr32_t *addr)
4775 ctio_a64_entry_t *pkt;
4776 uint32_t *dword_ptr;
4778 #ifdef QL_DEBUG_LEVEL_3
4779 qla1280_print("qla1280_64bit_continue_io: entered\n\r");
4780 #endif
4782 /* Get request packet. */
4783 if (pkt = (ctio_a64_entry_t *)qla1280_req_pkt(ha))
4785 pkt->entry_type = CTIO_A64_TYPE;
4786 pkt->lun = atio->lun;
4787 pkt->initiator_id = atio->initiator_id;
4788 pkt->target_id = atio->target_id;
4789 pkt->option_flags = atio->option_flags;
4790 pkt->tag_value = atio->tag_value;
4791 pkt->scsi_status = atio->scsi_status;
4793 if (len)
4795 pkt->dseg_count = 1;
4796 pkt->transfer_length = len;
4797 pkt->dseg_0_length = len;
4798 dword_ptr = (uint32_t *)addr;
4799 pkt->dseg_0_address[0] = *dword_ptr++;
4800 pkt->dseg_0_address[1] = *dword_ptr;
4803 /* Issue command to ISP */
4804 qla1280_isp_cmd(ha);
4807 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4808 if (!pkt)
4809 qla1280_print("qla1280_64bit_continue_io: **** FAILED ****\n\r");
4810 #endif
4811 #ifdef QL_DEBUG_LEVEL_3
4812 else
4813 qla1280_print("qla1280_64bit_continue_io: exiting normally\n\r");
4814 #endif
4818 * qla1280_32bit_continue_io
4819 * Issue continue target I/O IOCB.
4821 * Input:
4822 * ha = adapter block pointer.
4823 * atio = atio pointer.
4824 * len = total bytecount.
4825 * addr = physical address pointer.
4827 STATIC void
4828 qla1280_32bit_continue_io(scsi_qla_host_t *ha, atio_entry_t *atio, uint32_t len,
4829 paddr32_t *addr)
4831 ctio_entry_t *pkt;
4832 uint32_t *dword_ptr;
4834 #ifdef QL_DEBUG_LEVEL_3
4835 qla1280_print("qla1280_32bit_continue_io: entered\n\r");
4836 #endif
4838 /* Get request packet. */
4839 if (pkt = (ctio_entry_t *)qla1280_req_pkt(ha))
4841 pkt->entry_type = CONTINUE_TGT_IO_TYPE;
4842 pkt->lun = atio->lun;
4843 pkt->initiator_id = atio->initiator_id;
4844 pkt->target_id = atio->target_id;
4845 pkt->option_flags = atio->option_flags;
4846 pkt->tag_value = atio->tag_value;
4847 pkt->scsi_status = atio->scsi_status;
4849 if (len)
4851 pkt->dseg_count = 1;
4852 pkt->transfer_length = len;
4853 pkt->dseg_0_length = len;
4854 dword_ptr = (uint32_t *)addr;
4855 pkt->dseg_0_address = *dword_ptr;
4858 /* Issue command to ISP */
4859 qla1280_isp_cmd(ha);
4862 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
4863 if (!pkt)
4864 qla1280_print("qla1280_32bit_continue_io: **** FAILED ****\n\r");
4865 #endif
4866 #ifdef QL_DEBUG_LEVEL_3
4867 else
4868 qla1280_print("qla1280_32bit_continue_io: exiting normally\n\r");
4869 #endif
4871 #endif /* QL1280_TARGET_MODE_SUPPORT */
4873 /****************************************************************************/
4874 /* Interrupt Service Routine. */
4875 /****************************************************************************/
4877 /****************************************************************************
4878 * qla1280_isr
4879 * Calls I/O done on command completion.
4881 * Input:
4882 * ha = adapter block pointer.
4883 * done_q_first = done queue first pointer.
4884 * done_q_last = done queue last pointer.
4885 * INTR_LOCK must be already obtained.
4886 ****************************************************************************/
4887 STATIC void
4888 qla1280_isr(scsi_qla_host_t *ha, srb_t **done_q_first, srb_t **done_q_last)
4890 device_reg_t *reg = ha->iobase;
4891 response_t *pkt;
4892 srb_t *sp;
4893 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
4894 uint16_t *wptr;
4895 uint32_t index;
4897 ENTER("qla1280_isr");
4900 /* Save mailbox register 5 */
4901 mailbox[5] = RD_REG_WORD(&reg->mailbox5);
4903 /* Check for mailbox interrupt. */
4905 mailbox[0] = RD_REG_WORD(&reg->semaphore);
4906 if (mailbox[0] & BIT_0)
4908 /* Get mailbox data. */
4910 wptr = &mailbox[0];
4911 *wptr++ = RD_REG_WORD(&reg->mailbox0);
4912 *wptr++ = RD_REG_WORD(&reg->mailbox1);
4913 *wptr = RD_REG_WORD(&reg->mailbox2);
4914 if (mailbox[0] != MBA_SCSI_COMPLETION)
4916 wptr++;
4917 *wptr++ = RD_REG_WORD(&reg->mailbox3);
4918 *wptr++ = RD_REG_WORD(&reg->mailbox4);
4919 wptr++;
4920 *wptr++ = RD_REG_WORD(&reg->mailbox6);
4921 *wptr = RD_REG_WORD(&reg->mailbox7);
4924 /* Release mailbox registers. */
4926 WRT_REG_WORD(&reg->semaphore, 0);
4927 WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
4929 #ifdef QL_DEBUG_LEVEL_5
4930 qla1280_print("qla1280_isr: mailbox interrupt mailbox[0] = ");
4931 qla1280_output_number((uint32_t)mailbox[0], 16);
4932 qla1280_print("\n\r");
4933 #endif
4935 /* Handle asynchronous event */
4937 switch (mailbox[0])
4939 case MBA_SCSI_COMPLETION: /* Response completion */
4940 #ifdef QL_DEBUG_LEVEL_5
4941 qla1280_print("qla1280_isr: mailbox response completion\n\r");
4942 #endif
4943 if (ha->flags.online)
4945 /* Get outstanding command index. */
4946 index = (uint32_t)(mailbox[2] << 16 | mailbox[1]);
4948 /* Validate handle. */
4949 if (index < MAX_OUTSTANDING_COMMANDS)
4950 sp = ha->outstanding_cmds[index];
4951 else
4952 sp = 0;
4954 if (sp)
4956 /* Free outstanding command slot. */
4957 ha->outstanding_cmds[index] = 0;
4959 /* Save ISP completion status */
4960 CMD_RESULT(sp->cmd) = 0;
4962 /* Place block on done queue */
4963 sp->s_next = NULL;
4964 sp->s_prev = *done_q_last;
4965 if (!*done_q_first)
4966 *done_q_first = sp;
4967 else
4968 (*done_q_last)->s_next = sp;
4969 *done_q_last = sp;
4971 else
4973 #ifdef QL_DEBUG_LEVEL_2
4974 qla1280_print("qla1280_isr: ISP invalid handle\n\r");
4975 #endif
4976 printk(KERN_WARNING "qla1280: ISP invalid handle");
4977 ha->flags.isp_abort_needed = TRUE;
4980 break;
4981 case MBA_BUS_RESET: /* SCSI Bus Reset */
4982 #ifdef QL_DEBUG_LEVEL_2
4983 qla1280_print("qla1280_isr: asynchronous BUS_RESET\n\r");
4984 #endif
4985 ha->flags.reset_marker = TRUE;
4986 index = mailbox[6] & BIT_0;
4987 ha->bus_settings[index].reset_marker = TRUE;
4988 break;
4989 case MBA_SYSTEM_ERR: /* System Error */
4990 #ifdef QL_DEBUG_LEVEL_2
4991 qla1280_print("qla1280_isr: ISP System Error - mbx1=");
4992 qla1280_output_number((uint32_t)mailbox[1], 16);
4993 qla1280_print(", mbx2=");
4994 qla1280_output_number((uint32_t)mailbox[2], 16);
4995 qla1280_print(", mbx3=");
4996 qla1280_output_number((uint32_t)mailbox[3], 16);
4997 qla1280_print("\n\r");
4998 #endif
4999 printk(KERN_WARNING
5000 "qla1280: ISP System Error - mbx1=%xh, mbx2=%xh, mbx3=%xh\n",
5001 mailbox[1], mailbox[2], mailbox[3]);
5002 ha->flags.isp_abort_needed = TRUE;
5003 break;
5004 case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
5005 #ifdef QL_DEBUG_LEVEL_2
5006 qla1280_print("qla1280_isr: ISP Request Transfer Error\n\r");
5007 #endif
5008 printk(KERN_WARNING "qla1280: ISP Request Transfer Error\n");
5009 ha->flags.isp_abort_needed = TRUE;
5010 break;
5011 case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
5012 #ifdef QL_DEBUG_LEVEL_2
5013 qla1280_print("qla1280_isr: ISP Response Transfer Error\n\r");
5014 #endif
5015 printk(KERN_WARNING "qla1280: ISP Response Transfer Error\n");
5016 ha->flags.isp_abort_needed = TRUE;
5017 break;
5018 case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
5019 #ifdef QL_DEBUG_LEVEL_2
5020 qla1280_print("qla1280_isr: asynchronous WAKEUP_THRES\n\r");
5021 #endif
5022 break;
5023 case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
5024 #ifdef QL_DEBUG_LEVEL_2
5025 qla1280_print("qla1280_isr: asynchronous TIMEOUT_RESET\n\r");
5026 #endif
5027 break;
5028 case MBA_DEVICE_RESET: /* Bus Device Reset */
5029 #ifdef QL_DEBUG_LEVEL_2
5030 qla1280_print(
5031 "qla1280_isr: asynchronous BUS_DEVICE_RESET\n\r");
5032 #endif
5033 ha->flags.reset_marker = TRUE;
5034 index = mailbox[6] & BIT_0;
5035 ha->bus_settings[index].reset_marker = TRUE;
5036 break;
5037 case MBA_BUS_MODE_CHANGE:
5038 #ifdef QL_DEBUG_LEVEL_2
5039 qla1280_print(
5040 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n\r");
5041 #endif
5042 break;
5043 default:
5044 if (mailbox[0] < MBA_ASYNC_EVENT)
5046 wptr = &mailbox[0];
5047 ha->mailbox_out[0] = *wptr++;
5048 ha->mailbox_out[1] = *wptr++;
5049 ha->mailbox_out[2] = *wptr++;
5050 ha->mailbox_out[3] = *wptr++;
5051 ha->mailbox_out[4] = *wptr++;
5052 ha->mailbox_out[5] = *wptr++;
5053 ha->mailbox_out[6] = *wptr++;
5054 ha->mailbox_out[7] = *wptr;
5055 ha->flags.mbox_int = TRUE;
5057 break;
5060 else
5061 WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
5064 * Response ring
5066 if (ha->flags.online && !ha->flags.mbox_busy)
5068 if (mailbox[5] < RESPONSE_ENTRY_CNT)
5070 while (ha->rsp_ring_index != mailbox[5])
5072 pkt = ha->response_ring_ptr;
5074 #ifdef QL_DEBUG_LEVEL_5
5075 qla1280_print("qla1280_isr: ha->rsp_ring_index = ");
5076 qla1280_output_number((uint32_t)ha->rsp_ring_index, 16);
5077 qla1280_print(" mailbox[5] = ");
5078 qla1280_output_number((uint32_t)mailbox[5], 16);
5079 qla1280_print("\n\rqla1280_isr: response packet data\n\r");
5080 qla1280_dump_buffer((caddr_t)pkt, RESPONSE_ENTRY_SIZE);
5081 #endif
5083 #if defined(QL_DEBUG_LEVEL_2) && !defined(QL_DEBUG_LEVEL_5)
5084 if (pkt->entry_type == STATUS_TYPE)
5086 if ((uint8_t)(pkt->scsi_status) || pkt->comp_status ||
5087 pkt->entry_status)
5089 DEBUG(qla1280_print("qla1280_isr: ha->rsp_ring_index = ");)
5090 DEBUG(qla1280_output_number((uint32_t)ha->rsp_ring_index,
5091 16);)
5092 DEBUG(qla1280_print(" mailbox[5] = ");)
5093 DEBUG(qla1280_output_number((uint32_t)mailbox[5], 16);)
5094 DEBUG(qla1280_print( "\n\r comp_status = ");)
5095 DEBUG(qla1280_output_number((uint32_t)pkt->comp_status,16);)
5096 DEBUG(qla1280_print( ", ");)
5097 DEBUG(qla1280_print( " scsi_status = ");)
5098 DEBUG(qla1280_output_number((uint32_t)pkt->scsi_status,16);)
5099 DEBUG(qla1280_print( "\n\r");)
5100 /* qla1280_print(
5101 "\n\rqla1280_isr: response packet data\n\r");
5102 qla1280_dump_buffer((caddr_t)pkt,
5103 RESPONSE_ENTRY_SIZE); */
5106 else
5108 qla1280_print("qla1280_isr: ha->rsp_ring_index = ");
5109 qla1280_output_number((uint32_t)ha->rsp_ring_index, 16);
5110 qla1280_print(" mailbox[5] = ");
5111 qla1280_output_number((uint32_t)mailbox[5], 16);
5112 qla1280_print(
5113 "\n\rqla1280_isr: response packet data\n\r");
5114 qla1280_dump_buffer((caddr_t)pkt, RESPONSE_ENTRY_SIZE);
5116 #endif
5117 if (pkt->entry_type == STATUS_TYPE || pkt->entry_status)
5119 if (pkt->entry_type == STATUS_TYPE)
5120 qla1280_status_entry(ha, (sts_entry_t *)pkt,
5121 done_q_first, done_q_last);
5122 else
5123 qla1280_error_entry(ha, pkt,
5124 done_q_first, done_q_last);
5126 /* Adjust ring index. */
5127 ha->rsp_ring_index++;
5128 if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT)
5130 ha->rsp_ring_index = 0;
5131 ha->response_ring_ptr = ha->response_ring;
5133 else
5134 ha->response_ring_ptr++;
5135 WRT_REG_WORD(&reg->mailbox5, ha->rsp_ring_index);
5137 #if QLA1280_TARGET_MODE_SUPPORT
5138 else
5140 pkt = &response_entry;
5142 /* Copy packet. */
5143 dptr1 = (uint32_t *)ha->response_ring_ptr;
5144 dptr2 = (uint32_t *)pkt;
5145 for (index = 0; index < RESPONSE_ENTRY_SIZE/4; index++)
5146 *dptr2++ = *dptr1++;
5148 /* Adjust ring index. */
5149 ha->rsp_ring_index++;
5150 if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT)
5152 ha->rsp_ring_index = 0;
5153 ha->response_ring_ptr = ha->response_ring;
5155 else
5156 ha->response_ring_ptr++;
5157 WRT_REG_WORD(&reg->mailbox5, ha->rsp_ring_index);
5159 /* Release interrupt specific lock */
5160 QLA1280_INTR_UNLOCK(ha);
5162 switch (pkt->entry_type)
5164 case ACCEPT_TGT_IO_TYPE:
5165 qla1280_atio_entry(ha, (atio_entry_t *)pkt);
5166 break;
5167 case IMMED_NOTIFY_TYPE:
5168 qla1280_notify_entry(ha, (notify_entry_t *)pkt);
5169 break;
5170 case CTIO_RET_TYPE:
5171 qla1280_accept_io(ha, (ctio_ret_entry_t *)pkt);
5172 break;
5173 default:
5174 break;
5177 /* Acquire interrupt specific lock */
5178 QLA1280_INTR_LOCK(ha);
5180 #endif
5183 else
5185 ha->flags.isp_abort_needed = TRUE;
5186 #ifdef QL_DEBUG_LEVEL_2
5187 qla1280_print("qla1280_isr: Response pointer Error\n");
5188 #endif
5192 LEAVE("qla1280_isr");
5196 * qla1280_rst_aen
5197 * Processes asynchronous reset.
5199 * Input:
5200 * ha = adapter block pointer.
5202 STATIC void
5203 qla1280_rst_aen(scsi_qla_host_t *ha)
5205 #if QL1280_TARGET_MODE_SUPPORT
5206 notify_entry_t nentry;
5207 #endif
5208 uint8_t b;
5210 #ifdef QL_DEBUG_LEVEL_3
5211 ENTER("qla1280_rst_aen");
5212 #endif
5214 if (ha->flags.online && !ha->flags.reset_active &&
5215 !ha->flags.abort_isp_active)
5217 ha->flags.reset_active = TRUE;
5218 while (ha->flags.reset_marker)
5220 /* Issue marker command. */
5221 ha->flags.reset_marker = FALSE;
5222 for (b = 0; b < ha->ports && !ha->flags.reset_marker; b++)
5224 if (ha->bus_settings[b].reset_marker)
5226 ha->bus_settings[b].reset_marker = FALSE;
5227 qla1280_marker(ha, b, 0, 0, MK_SYNC_ALL);
5229 if (!ha->flags.reset_marker)
5231 #if QL1280_TARGET_MODE_SUPPORT
5232 /* Issue notify acknowledgement command. */
5233 bzero((caddr_t)&nentry, sizeof(notify_entry_t));
5235 nentry.initiator_id = nentry.target_id = b ?
5236 ha->bus_settings[b].id | BIT_7 :
5237 ha->bus_settings[b].id;
5238 qla1280_notify_entry(ha, &nentry);
5239 #endif
5241 /* Asynchronous event notification */
5248 #ifdef QL_DEBUG_LEVEL_3
5249 LEAVE("qla1280_rst_aen");
5250 #endif
5253 #if QL1280_TARGET_MODE_SUPPORT
5255 * qla1280_atio_entry
5256 * Processes received ISP accept target I/O entry.
5258 * Input:
5259 * ha = adapter block pointer.
5260 * pkt = entry pointer.
5262 STATIC void
5263 qla1280_atio_entry(scsi_qla_host_t *ha, atio_entry_t *pkt)
5265 uint64_t *a64;
5266 uint64_t *end_a64;
5267 paddr32_t phy_addr[2];
5268 paddr32_t end_addr[2];
5269 uint32_t len;
5270 uint32_t offset;
5271 uint8_t t;
5272 uint8_t *sense_ptr;
5274 #ifdef QL_DEBUG_LEVEL_3
5275 qla1280_print("qla1280_atio_entry: entered\n\r");
5276 #endif
5278 t = pkt->initiator_id;
5279 sense_ptr = ha->tsense + t * TARGET_SENSE_SIZE;
5280 a64 = (uint64_t *)&phy_addr[0];
5281 end_a64 = (uint64_t *)&end_addr[0];
5283 switch (pkt->status & ~BIT_7)
5285 case 7: /* Path invalid */
5286 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5287 qla1280_print("qla1280_atio_entry: Path invalid\n\r");
5288 #endif
5289 break;
5290 case 0x14: /* Target Bus Phase Sequence Failure */
5291 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5292 qla1280_print(
5293 "qla1280_atio_entry: Target Bus Phase Sequence Failure\n\r");
5294 #endif
5295 if (pkt->status & BIT_7)
5297 BCOPY((caddr_t)&pkt->sense_data, sense_ptr,TARGET_SENSE_SIZE);
5299 else
5301 bzero(sense_ptr, TARGET_SENSE_SIZE);
5302 *sense_ptr = 0x70;
5303 *(sense_ptr+2) = SD_HARDERR;
5304 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5305 *(sense_ptr+12) = SC_SELFAIL;
5307 pkt->scsi_status = S_CKCON;
5308 pkt->option_flags |= (uint32_t)OF_SSTS | (uint32_t)OF_NO_DATA;
5309 if (ha->flags.enable_64bit_addressing)
5310 qla1280_64bit_continue_io(ha, pkt, 0, 0);
5311 else
5312 qla1280_32bit_continue_io(ha, pkt, 0, 0);
5313 break;
5314 case 0x16: /* Requested Capability Not Available */
5315 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5316 qla1280_print(
5317 "qla1280_atio_entry: Target Bus Phase Sequence Failure\n\r");
5318 #endif
5319 break;
5320 case 0x17: /* Bus Device Reset Message Received */
5321 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
5322 qla1280_print(
5323 "qla1280_atio_entry: Target Bus Phase Sequence Failure\n\r");
5324 #endif
5325 break;
5326 case 0x3D: /* CDB Received */
5328 /* Check for invalid LUN */
5329 if (pkt->lun && pkt->cdb[0] != SS_INQUIR &&
5330 pkt->cdb[0] != SS_REQSEN)
5331 pkt->cdb[0] = SS_TEST;
5333 switch (pkt->cdb[0])
5335 case SS_TEST:
5336 #ifdef QL_DEBUG_LEVEL_3
5337 qla1280_print("qla1280_atio_entry: SS_TEST\n\r");
5338 #endif
5339 bzero(sense_ptr, TARGET_SENSE_SIZE);
5340 len = 0;
5341 if (pkt->lun == 0)
5342 pkt->scsi_status = S_GOOD;
5343 else
5345 *sense_ptr = 0x70;
5346 *(sense_ptr+2) = SD_ILLREQ;
5347 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5348 *(sense_ptr+12) = SC_INVLUN;
5349 pkt->scsi_status = S_CKCON;
5352 pkt->option_flags |= (uint32_t)OF_SSTS |
5353 (uint32_t)OF_NO_DATA;
5354 break;
5355 case SS_REQSEN:
5356 #ifdef QL_DEBUG_LEVEL_3
5357 qla1280_print("qla1280_atio_entry: SS_REQSEN\n\r");
5358 #endif
5359 phy_addr[0] = ha->tsense_dma;
5360 phy_addr[1] = 0;
5361 *a64 += t * TARGET_SENSE_SIZE;
5362 if (pkt->cdb[4] > TARGET_SENSE_SIZE)
5363 len = TARGET_SENSE_SIZE;
5364 else
5365 len = pkt->cdb[4];
5366 pkt->scsi_status = S_GOOD;
5367 pkt->option_flags |= (uint32_t)OF_SSTS |
5368 (uint32_t)OF_DATA_IN;
5369 break;
5370 case SS_INQUIR:
5371 #ifdef QL_DEBUG_LEVEL_3
5372 qla1280_print("qla1280_atio_entry: SS_INQUIR\n\r");
5373 #endif
5374 bzero(sense_ptr, TARGET_SENSE_SIZE);
5375 phy_addr[0] = ha->tbuf_dma;
5376 phy_addr[1] = 0;
5377 *a64 += TARGET_INQ_OFFSET;
5379 if (pkt->lun == 0)
5381 ha->tbuf->inq.id_type = ID_PROCESOR;
5382 ha->tbuf->inq.id_pqual = ID_QOK;
5384 else
5386 ha->tbuf->inq.id_type = ID_NODEV;
5387 ha->tbuf->inq.id_pqual = ID_QNOLU;
5390 if (pkt->cdb[4] > sizeof(struct ident))
5391 len = sizeof(struct ident);
5392 else
5393 len = pkt->cdb[4];
5394 pkt->scsi_status = S_GOOD;
5395 pkt->option_flags |= (uint32_t)OF_SSTS |
5396 (uint32_t)OF_DATA_IN;
5397 break;
5398 case SM_WRDB:
5399 bzero(sense_ptr, TARGET_SENSE_SIZE);
5400 offset = pkt->cdb[5];
5401 offset |= pkt->cdb[4] << 8;
5402 offset |= pkt->cdb[3] << 16;
5403 len = pkt->cdb[8];
5404 len |= pkt->cdb[7] << 8;
5405 len |= pkt->cdb[6] << 16;
5406 end_addr[0] = phy_addr[0] = ha->tbuf_dma;
5407 end_addr[1] = phy_addr[1] = 0;
5408 *end_a64 += TARGET_DATA_OFFSET + TARGET_DATA_SIZE;
5409 switch (pkt->cdb[1] & 7)
5411 case RW_BUF_HDATA:
5412 #ifdef QL_DEBUG_LEVEL_3
5413 qla1280_print("qla1280_atio_entry: SM_WRDB, RW_BUF_HDATA\n\r");
5414 #endif
5415 if (len > TARGET_DATA_SIZE + 4)
5417 #ifdef QL_DEBUG_LEVEL_2
5418 qla1280_print("qla1280_atio_entry: SM_WRDB, length > buffer size\n\r");
5419 #endif
5420 *sense_ptr = 0x70;
5421 *(sense_ptr+2) = SD_ILLREQ;
5422 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5423 *(sense_ptr+12) = SC_ILLCDB;
5424 pkt->scsi_status = S_CKCON;
5425 pkt->option_flags |= (uint32_t)OF_SSTS |
5426 (uint32_t)OF_NO_DATA;
5427 len = 0;
5429 else if (len)
5431 pkt->scsi_status = S_GOOD;
5432 pkt->option_flags |= (uint32_t)OF_SSTS |
5433 (uint32_t)OF_DATA_OUT;
5434 #ifdef QL_DEBUG_LEVEL_3
5435 qla1280_print("qla1280_atio_entry: Issuing SDI_TARMOD_WRCOMP\n\r");
5436 #endif
5437 sdi_xaen(SDI_TARMOD_WRCOMP, ha->cntlr,
5438 pkt->target_id, pkt->lun, 0, offset);
5440 else
5442 #ifdef QL_DEBUG_LEVEL_2
5443 qla1280_print("qla1280_atio_entry: SM_WRDB, zero length\n\r");
5444 #endif
5445 pkt->scsi_status = S_GOOD;
5446 pkt->option_flags |= (uint32_t)OF_SSTS |
5447 (uint32_t)OF_NO_DATA;
5450 break;
5451 case RW_BUF_DATA:
5452 #ifdef QL_DEBUG_LEVEL_3
5453 qla1280_print("qla1280_atio_entry: SM_WRDB, RW_BUF_DATA\n\r");
5454 #endif
5455 *a64 += offset + TARGET_DATA_OFFSET;
5456 if (pkt->cdb[2] != 0 || *a64 >= *end_a64 ||
5457 *a64 + len > *end_a64)
5459 #ifdef QL_DEBUG_LEVEL_2
5460 qla1280_print("qla1280_atio_entry: SM_WRDB, RW_BUF_DATA BAD\n\r");
5461 qla1280_print("buf_id=");
5462 qla1280_output_number((uint32_t)pkt->cdb[2], 16);
5463 qla1280_print(", offset=");
5464 qla1280_output_number((uint32_t)offset, 16);
5465 qla1280_print(", length=");
5466 qla1280_output_number((uint32_t)len, 16);
5467 qla1280_print("\n\r");
5468 #endif
5469 *sense_ptr = 0x70;
5470 *(sense_ptr+2) = SD_ILLREQ;
5471 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5472 *(sense_ptr+12) = SC_ILLCDB;
5473 len = 0;
5474 pkt->scsi_status = S_CKCON;
5475 pkt->option_flags |= (uint32_t)OF_SSTS |
5476 (uint32_t)OF_NO_DATA;
5478 else if (len)
5480 pkt->scsi_status = S_GOOD;
5481 pkt->option_flags |= (uint32_t)OF_SSTS |
5482 (uint32_t)OF_DATA_OUT;
5483 #ifdef QL_DEBUG_LEVEL_3
5484 qla1280_print("qla1280_atio_entry: Issuing SDI_TARMOD_WRCOMP\n\r");
5485 #endif
5486 sdi_xaen(SDI_TARMOD_WRCOMP, ha->cntlr,
5487 pkt->target_id, pkt->lun, 0, offset);
5489 else
5491 #ifdef QL_DEBUG_LEVEL_2
5492 qla1280_print("qla1280_atio_entry: SM_WRDB, zero length\n\r");
5493 #endif
5494 pkt->scsi_status = S_GOOD;
5495 pkt->option_flags |= (uint32_t)OF_SSTS |
5496 (uint32_t)OF_NO_DATA;
5498 break;
5499 default:
5500 #ifdef QL_DEBUG_LEVEL_2
5501 qla1280_print("qla1280_atio_entry: SM_WRDB unknown mode\n\r");
5502 #endif
5503 *sense_ptr = 0x70;
5504 *(sense_ptr+2) = SD_ILLREQ;
5505 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5506 *(sense_ptr+12) = SC_ILLCDB;
5507 len = 0;
5508 pkt->scsi_status = S_CKCON;
5509 pkt->option_flags |= (uint32_t)OF_SSTS |
5510 (uint32_t)OF_NO_DATA;
5511 break;
5513 break;
5514 case SM_RDDB:
5515 bzero(sense_ptr, TARGET_SENSE_SIZE);
5516 offset = pkt->cdb[5];
5517 offset |= pkt->cdb[4] << 8;
5518 offset |= pkt->cdb[3] << 16;
5519 len = pkt->cdb[8];
5520 len |= pkt->cdb[7] << 8;
5521 len |= pkt->cdb[6] << 16;
5522 end_addr[0] = phy_addr[0] = ha->tbuf_dma;
5523 end_addr[1] = phy_addr[1] = 0;
5524 *end_a64 += TARGET_DATA_OFFSET + TARGET_DATA_SIZE;
5525 switch (pkt->cdb[1] & 7)
5527 case RW_BUF_HDATA:
5528 #ifdef QL_DEBUG_LEVEL_3
5529 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_HDATA\n\r");
5530 #endif
5531 if (len)
5533 ha->tbuf->hdr[0] = 0;
5534 ha->tbuf->hdr[1] =
5535 (uint8_t)(TARGET_DATA_SIZE >> 16);
5536 ha->tbuf->hdr[2] =
5537 (uint8_t)(TARGET_DATA_SIZE >> 8);
5538 ha->tbuf->hdr[3] = (uint8_t)TARGET_DATA_SIZE;
5539 if (len > TARGET_DATA_SIZE + 4)
5540 len = TARGET_DATA_SIZE + 4;
5541 pkt->scsi_status = S_GOOD;
5542 pkt->option_flags |= (uint32_t)OF_SSTS |
5543 (uint32_t)OF_DATA_IN;
5545 else
5547 #ifdef QL_DEBUG_LEVEL_2
5548 qla1280_print("qla1280_atio_entry: SM_RDDB, zero length\n\r");
5549 #endif
5550 pkt->scsi_status = S_GOOD;
5551 pkt->option_flags |= (uint32_t)OF_SSTS |
5552 (uint32_t)OF_NO_DATA;
5554 break;
5555 case RW_BUF_DATA:
5556 #ifdef QL_DEBUG_LEVEL_3
5557 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_DATA\n\r");
5558 #endif
5559 *a64 += offset + TARGET_DATA_OFFSET;
5560 if (pkt->cdb[2] != 0 || *a64 >= *end_a64)
5562 #ifdef QL_DEBUG_LEVEL_2
5563 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_DATA BAD\n\r");
5564 qla1280_print("buf_id=");
5565 qla1280_output_number((uint32_t)pkt->cdb[2], 16);
5566 qla1280_print(", offset=");
5567 qla1280_output_number((uint32_t)offset, 16);
5568 qla1280_print("\n\r");
5569 #endif
5570 *sense_ptr = 0x70;
5571 *(sense_ptr+2) = SD_ILLREQ;
5572 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5573 *(sense_ptr+12) = SC_ILLCDB;
5574 len = 0;
5575 pkt->scsi_status = S_CKCON;
5576 pkt->option_flags |= (uint32_t)OF_SSTS |
5577 (uint32_t)OF_NO_DATA;
5579 else
5581 if (*a64 + len > *end_a64)
5582 len = *end_a64 - *a64;
5583 if (len)
5585 pkt->scsi_status = S_GOOD;
5586 pkt->option_flags |= (uint32_t)OF_SSTS |
5587 (uint32_t)OF_DATA_IN;
5589 else
5591 #ifdef QL_DEBUG_LEVEL_2
5592 qla1280_print("qla1280_atio_entry: SM_RDDB, zero length\n\r");
5593 #endif
5594 pkt->scsi_status = S_GOOD;
5595 pkt->option_flags |= (uint32_t)OF_SSTS |
5596 (uint32_t)OF_NO_DATA;
5599 break;
5600 case RW_BUF_DESC:
5601 #ifdef QL_DEBUG_LEVEL_3
5602 qla1280_print("qla1280_atio_entry: SM_RDDB, RW_BUF_DESC\n\r");
5603 #endif
5604 if (len)
5606 if (len > 4)
5607 len = 4;
5609 ha->tbuf->hdr[0] = 0;
5610 if (pkt->cdb[2] != 0)
5612 ha->tbuf->hdr[1] = 0;
5613 ha->tbuf->hdr[2] = 0;
5614 ha->tbuf->hdr[3] = 0;
5616 else
5618 ha->tbuf->hdr[1] =
5619 (uint8_t)(TARGET_DATA_SIZE >> 16);
5620 ha->tbuf->hdr[2] =
5621 (uint8_t)(TARGET_DATA_SIZE >> 8);
5622 ha->tbuf->hdr[3] =
5623 (uint8_t)TARGET_DATA_SIZE;
5625 pkt->scsi_status = S_GOOD;
5626 pkt->option_flags |= (uint32_t)OF_SSTS |
5627 (uint32_t)OF_DATA_IN;
5629 else
5631 #ifdef QL_DEBUG_LEVEL_2
5632 qla1280_print("qla1280_atio_entry: SM_RDDB, zero length\n\r");
5633 #endif
5634 pkt->scsi_status = S_GOOD;
5635 pkt->option_flags |= (uint32_t)OF_SSTS |
5636 (uint32_t)OF_NO_DATA;
5638 break;
5639 default:
5640 #ifdef QL_DEBUG_LEVEL_2
5641 qla1280_print("qla1280_atio_entry: SM_RDDB unknown mode\n\r");
5642 #endif
5643 *sense_ptr = 0x70;
5644 *(sense_ptr+2) = SD_ILLREQ;
5645 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5646 *(sense_ptr+12) = SC_ILLCDB;
5647 len = 0;
5648 pkt->scsi_status = S_CKCON;
5649 pkt->option_flags |= (uint32_t)OF_SSTS |
5650 (uint32_t)OF_NO_DATA;
5651 break;
5653 break;
5654 default:
5655 #ifdef QL_DEBUG_LEVEL_2
5656 qla1280_print("qla1280_atio_entry: Unknown SCSI command\n\r");
5657 qla1280_dump_buffer((caddr_t)&pkt->cdb[0], pkt->cdb_len);
5658 #endif
5659 bzero(sense_ptr, TARGET_SENSE_SIZE);
5660 *sense_ptr = 0x70;
5661 *(sense_ptr+2) = SD_ILLREQ;
5662 *(sense_ptr+7) = TARGET_SENSE_SIZE-8;
5663 *(sense_ptr+12) = SC_INVOPCODE;
5664 len = 0;
5665 pkt->scsi_status = S_CKCON;
5666 pkt->option_flags |= (uint32_t)OF_SSTS |
5667 (uint32_t)OF_NO_DATA;
5668 break;
5670 if (ha->flags.enable_64bit_addressing)
5671 qla1280_64bit_continue_io(ha, pkt, len, (paddr32_t *)&phy_addr);
5672 else
5673 qla1280_32bit_continue_io(ha, pkt, len, (paddr32_t *)&phy_addr);
5674 break;
5675 default:
5676 break;
5679 #ifdef QL_DEBUG_LEVEL_3
5680 qla1280_print("qla1280_atio_entry: exiting normally\n\r");
5681 #endif
5685 * qla1280_notify_entry
5686 * Processes received ISP immediate notify entry.
5688 * Input:
5689 * ha = adapter block pointer.
5690 * pkt = entry pointer.
5692 STATIC void
5693 qla1280_notify_entry(scsi_qla_host_t *ha, notify_entry_t *pkt)
5695 #ifdef QL_DEBUG_LEVEL_3
5696 qla1280_print("qla1280_notify_entry: entered\n\r");
5697 #endif
5699 /* Acknowledge immediate notify */
5700 qla1280_notify_ack(ha, pkt);
5702 /* Issue notify entry to increment resource count */
5703 qla1280_immed_notify(ha, pkt);
5705 #ifdef QL_DEBUG_LEVEL_3
5706 qla1280_print("qla1280_notify_entry: exiting normally\n\r");
5707 #endif
5710 #endif /* QLA1280_TARGET_MODE_SUPPORT */
5712 * qla1280_status_entry
5713 * Processes received ISP status entry.
5715 * Input:
5716 * ha = adapter block pointer.
5717 * pkt = entry pointer.
5718 * done_q_first = done queue first pointer.
5719 * done_q_last = done queue last pointer.
5721 STATIC void
5722 qla1280_status_entry(scsi_qla_host_t *ha, sts_entry_t *pkt, srb_t **done_q_first,
5723 srb_t **done_q_last)
5725 uint32_t b, t, l;
5726 uint8_t sense_sz = 0;
5727 srb_t *sp;
5728 scsi_lu_t *q;
5729 Scsi_Cmnd *cp;
5731 #ifdef QL_DEBUG_LEVEL_3
5732 ENTER("qla1280_status_entry");
5733 #endif
5735 /* Validate handle. */
5736 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
5737 sp = ha->outstanding_cmds[pkt->handle];
5738 else
5739 sp = 0;
5741 if (sp)
5743 /* Free outstanding command slot. */
5744 ha->outstanding_cmds[pkt->handle] = 0;
5746 cp = sp->cmd;
5747 /* Generate LU queue on cntrl, target, LUN */
5748 b = SCSI_BUS_32(cp);
5749 t = SCSI_TCN_32(cp);
5750 l = SCSI_LUN_32(cp);
5751 q = LU_Q(ha, b, t, l);
5752 if( pkt->comp_status || pkt->scsi_status )
5754 DEBUG(qla1280_print( "scsi: comp_status = ");)
5755 DEBUG(qla1280_output_number((uint32_t)pkt->comp_status,16);)
5756 DEBUG(qla1280_print( ", ");)
5757 DEBUG(qla1280_print( " scsi_status = ");)
5758 DEBUG(qla1280_output_number((uint32_t)pkt->scsi_status,16);)
5759 DEBUG(qla1280_print( "\n\r");)
5760 DEBUG(qla1280_print(", handle = ");)
5761 DEBUG(qla1280_output_number((uint32_t)pkt->handle, 16);)
5762 DEBUG(qla1280_print("\n\r");)
5765 /* Target busy */
5766 if ( pkt->scsi_status & SS_BUSY_CONDITION &&
5767 pkt->scsi_status != SS_RESERVE_CONFLICT )
5769 CMD_RESULT(cp) = (int) (DID_BUS_BUSY << 16) |
5770 (pkt->scsi_status & 0xff);
5772 else
5775 /* Save ISP completion status */
5776 CMD_RESULT(cp) = qla1280_return_status( pkt, cp );
5778 if (pkt->scsi_status & SS_CHECK_CONDITION)
5780 BZERO(cp->sense_buffer, CMD_SNSLEN(cp));
5781 if (pkt->comp_status != CS_ARS_FAILED)
5783 if ( pkt->req_sense_length < CMD_SNSLEN(cp) )
5784 sense_sz = pkt->req_sense_length;
5785 else
5786 sense_sz = CMD_SNSLEN(cp) - 1;
5788 BCOPY((caddr_t)&pkt->req_sense_data, cp->sense_buffer, sense_sz);
5791 #ifdef QL_DEBUG_LEVEL_2
5792 DEBUG(qla1280_print(
5793 "qla1280_status_entry: Check condition Sense data, b");)
5794 DEBUG(qla1280_output_number((uint32_t)b, 10);)
5795 DEBUG(qla1280_print("t");)
5796 DEBUG(qla1280_output_number((uint32_t)t, 10);)
5797 DEBUG(qla1280_print("d");)
5798 DEBUG(qla1280_output_number((uint32_t)l, 10);)
5799 DEBUG(qla1280_print("\n\r");)
5800 DEBUG(if (sense_sz))
5801 DEBUG(qla1280_dump_buffer(cp->sense_buffer, sense_sz);)
5802 #endif
5805 /* Place command on done queue. */
5806 qla1280_done_q_put(sp, done_q_first, done_q_last);
5808 else
5810 #ifdef QL_DEBUG_LEVEL_2
5811 qla1280_print("qla1280_status_entry: ISP Invalid handle\n\r");
5812 #endif
5813 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
5814 ha->flags.isp_abort_needed = TRUE;
5816 #ifdef QL_DEBUG_LEVEL_3
5817 LEAVE("qla1280_status_entry");
5818 #endif
5822 * qla1280_error_entry
5823 * Processes error entry.
5825 * Input:
5826 * ha = adapter block pointer.
5827 * pkt = entry pointer.
5828 * done_q_first = done queue first pointer.
5829 * done_q_last = done queue last pointer.
5831 STATIC void
5832 qla1280_error_entry(scsi_qla_host_t *ha, response_t *pkt, srb_t **done_q_first,
5833 srb_t **done_q_last)
5835 srb_t *sp;
5837 #ifdef QL_DEBUG_LEVEL_3
5838 ENTER("qla1280_error_entry");
5839 #endif
5841 #ifdef QL_DEBUG_LEVEL_2
5842 if (pkt->entry_status & BIT_3)
5843 qla1280_print("qla1280_error_entry: BAD PAYLOAD flag error\n\r");
5844 else if (pkt->entry_status & BIT_2)
5845 qla1280_print("qla1280_error_entry: BAD HEADER flag error\n\r");
5846 else if (pkt->entry_status & BIT_1)
5847 qla1280_print("qla1280_error_entry: FULL flag error\n\r");
5848 else
5849 qla1280_print("qla1280_error_entry: UNKNOWN flag error\n\r");
5850 #endif
5852 /* Validate handle. */
5853 if (pkt->handle < MAX_OUTSTANDING_COMMANDS)
5854 sp = ha->outstanding_cmds[pkt->handle];
5855 else
5856 sp = 0;
5858 if (sp)
5860 /* Free outstanding command slot. */
5861 ha->outstanding_cmds[pkt->handle] = 0;
5863 /* Bad payload or header */
5864 if (pkt->entry_status & (BIT_3 + BIT_2))
5866 /* Bad payload or header, set error status. */
5867 /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
5868 CMD_RESULT(sp->cmd) = (int) DID_ERROR << 16;
5870 else if (pkt->entry_status & BIT_1 ) /* FULL flag */
5872 CMD_RESULT(sp->cmd) = (int) DID_BUS_BUSY << 16;
5874 else
5876 /* Set error status. */
5877 CMD_RESULT(sp->cmd) =(int) DID_ERROR << 16;
5879 /* Place command on done queue. */
5880 qla1280_done_q_put(sp, done_q_first, done_q_last);
5882 #if QLA1280_64BIT_SUPPORT
5883 else if (pkt->entry_type == COMMAND_A64_TYPE)
5885 #ifdef QL_DEBUG_LEVEL_2
5886 qla1280_print("qla1280_error_entry: ISP Invalid handle\n\r");
5887 #endif
5888 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
5889 ha->flags.isp_abort_needed = TRUE;
5891 #endif
5893 #ifdef QL_DEBUG_LEVEL_3
5894 LEAVE("qla1280_error_entry");
5895 #endif
5899 * qla1280_abort_isp
5900 * Resets ISP and aborts all outstanding commands.
5902 * Input:
5903 * ha = adapter block pointer.
5905 * Returns:
5906 * 0 = success
5908 STATIC uint8_t
5909 qla1280_abort_isp(scsi_qla_host_t *ha)
5911 device_reg_t *reg = ha->iobase;
5912 uint8_t status = 0;
5913 uint16_t cnt;
5914 srb_t *sp;
5915 scsi_lu_t *q;
5916 uint32_t b, t, l;
5917 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
5918 unsigned long cpu_flags = 0;
5919 #endif
5921 #ifdef QL_DEBUG_LEVEL_3
5922 ENTER("qla1280_abort_isp");
5923 #endif
5925 DRIVER_LOCK
5926 ha->flags.isp_abort_needed = FALSE;
5927 if (!ha->flags.abort_isp_active && ha->flags.online)
5929 ha->flags.abort_isp_active = TRUE;
5931 /* Disable ISP interrupts. */
5932 WRT_REG_WORD(&reg->ictrl, 0);
5934 /* Dequeue all commands in outstanding command list. */
5935 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
5937 sp = ha->outstanding_cmds[cnt];
5938 if (sp)
5940 ha->outstanding_cmds[cnt] = 0;
5942 /* Generate LU queue on controller, target, LUN */
5943 b = SCSI_BUS_32(sp->cmd);
5944 t = SCSI_TCN_32(sp->cmd);
5945 l = SCSI_LUN_32(sp->cmd);
5947 q = (scsi_lu_t *)LU_Q(ha, b, t, l);
5949 /* Reset outstanding command count. */
5950 q->q_outcnt = 0;
5951 q->q_flag &= ~QLA1280_QBUSY;
5952 q->q_flag = 0;
5954 /* Adjust watchdog timer for command. */
5955 /* if (sp->flags & SRB_WATCHDOG)
5956 sp->timeout += 2; */
5958 /* Place request back on top of device queue. */
5959 /* sp->flags &= ~(SRB_SENT | SRB_TIMEOUT); */
5960 sp->flags = 0;
5961 qla1280_putq_t(q, sp);
5965 /* If firmware needs to be loaded */
5966 if (qla1280_isp_firmware(ha))
5968 if (!(status = qla1280_chip_diag(ha)))
5969 status = qla1280_setup_chip(ha);
5972 if (!status)
5974 /* Setup adapter based on NVRAM parameters. */
5975 qla1280_nvram_config(ha);
5977 if (!(status = qla1280_init_rings(ha)))
5979 /* Issue SCSI reset. */
5980 for (b = 0; b < ha->ports; b++)
5982 qla1280_bus_reset(ha, b);
5986 /* Issue marker command. */
5987 ha->flags.reset_marker = FALSE;
5988 for (b = 0; b < ha->ports; b++)
5990 ha->bus_settings[b].reset_marker = FALSE;
5991 qla1280_marker(ha, b, 0, 0, MK_SYNC_ALL);
5993 }while (ha->flags.reset_marker);
5995 /* Enable host adapter target mode. */
5996 for (b = 0; b < ha->ports; b++)
5998 if (!(status = qla1280_enable_tgt(ha, b)))
6000 for (cnt = 0; cnt < MAX_LUNS; cnt++)
6002 /* qla1280_enable_lun(ha, b, cnt); */
6003 qla1280_poll(ha);
6006 else
6007 break;
6010 if (!status)
6012 /* Enable ISP interrupts. */
6013 WRT_REG_WORD(&reg->ictrl, ISP_EN_INT + ISP_EN_RISC);
6014 ha->flags.abort_isp_active = FALSE;
6015 /* Restart queues that may have been stopped. */
6016 qla1280_restart_queues(ha);
6022 if (status)
6024 printk(KERN_WARNING
6025 "qla1280: ISP error recovery failed, board disabled");
6026 qla1280_reset_adapter(ha);
6027 qla1280_abort_queues(ha);
6029 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
6030 qla1280_print("qla1280_abort_isp: **** FAILED ****\n\r");
6031 #endif
6033 #ifdef QL_DEBUG_LEVEL_3
6034 else
6035 LEAVE("qla1280_abort_isp");
6036 #endif
6037 DRIVER_UNLOCK
6039 return(status);
6043 * qla1280_restart_queues
6044 * Restart all device queues.
6046 * Input:
6047 * ha = adapter block pointer.
6049 STATIC void
6050 qla1280_restart_queues(scsi_qla_host_t *ha)
6052 scsi_lu_t *q;
6053 uint32_t b, t, l;
6055 #ifdef QL_DEBUG_LEVEL_3
6056 ENTER("qla1280_restart_queues");
6057 #endif
6059 for (b = 0; b < ha->ports; b++)
6060 for (t = 0; t < MAX_TARGETS; t++)
6061 for (l = 0; l < MAX_LUNS; l++)
6063 q = (scsi_lu_t *) LU_Q(ha, b, t, l);
6064 if (q != NULL)
6066 /* Acquire LU queue specific lock */
6067 QLA1280_SCSILU_LOCK(q);
6069 if (q->q_first)
6070 qla1280_next(ha, q, b);
6071 else
6072 /* Release LU queue specific lock */
6073 QLA1280_SCSILU_UNLOCK(q);
6076 #ifdef QL_DEBUG_LEVEL_3
6077 qla1280_print("qla1280_restart_queues: exiting normally\n");
6078 #endif
6082 * qla1280_abort_queue_single
6083 * Abort all commands on a device queues.
6085 * Input:
6086 * ha = adapter block pointer.
6088 STATIC void qla1280_abort_queue_single(scsi_qla_host_t *ha,uint32_t b,uint32_t t,uint32_t l,uint32_t stat)
6090 scsi_lu_t *q;
6091 srb_t *sp, *sp_next;
6093 ENTER("qla1280_abort_queue_single");
6094 q = (scsi_lu_t * )LU_Q(ha, b, t, l);
6095 if (q != NULL)
6097 /* Acquire LU queue specific lock */
6098 QLA1280_SCSILU_LOCK(q);
6100 sp = q->q_first;
6101 q->q_first = q->q_last = NULL;
6103 QLA1280_SCSILU_UNLOCK(q);
6105 while (sp)
6107 sp_next = sp->s_next;
6108 CMD_RESULT(sp->cmd) = stat;
6109 qla1280_done_q_put(sp, (srb_t **)&ha->done_q_first, (srb_t **)&ha->done_q_last);
6110 sp = sp_next;
6113 LEAVE("qla1280_abort_queue_single");
6117 * qla1280_abort_queues
6118 * Abort all commands on device queues.
6120 * Input:
6121 * ha = adapter block pointer.
6123 STATIC void
6124 qla1280_abort_queues(scsi_qla_host_t *ha)
6126 uint32_t b, t, l;
6128 ENTER("qla1280_abort_queues");
6130 for (b = 0; b < ha->ports; b++)
6131 for (t = 0; t < MAX_TARGETS; t++)
6132 for (l = 0; l < MAX_LUNS; l++)
6133 qla1280_abort_queue_single(ha,b,t,l,DID_RESET);
6135 LEAVE("qla1280_abort_queues");
6139 * qla1280_debounce_register
6140 * Debounce register.
6142 * Input:
6143 * port = register address.
6145 * Returns:
6146 * register value.
6148 STATIC uint16_t
6149 qla1280_debounce_register(volatile uint16_t *addr)
6151 volatile uint16_t ret;
6152 volatile uint16_t ret2;
6156 ret = RD_REG_WORD(addr);
6157 ret2 = RD_REG_WORD(addr);
6158 }while (ret != ret2);
6160 return(ret);
6165 * Declarations for load module
6167 static Scsi_Host_Template driver_template = QLA1280_LINUX_TEMPLATE;
6169 #include "scsi_module.c"
6171 /************************************************************************
6172 * qla1280_check_for_dead_scsi_bus *
6174 * This routine checks for a dead SCSI bus *
6175 ************************************************************************/
6176 #define SET_SXP_BANK 0x0100
6177 #define SCSI_PHASE_INVALID 0x87FF
6178 int qla1280_check_for_dead_scsi_bus(scsi_qla_host_t *ha, srb_t *sp)
6180 uint16_t config_reg, scsi_control;
6181 device_reg_t *reg = ha->iobase;
6182 uint32_t b;
6183 Scsi_Cmnd *cp;
6186 * If SCSI Bus is Dead because of bad termination,
6187 * we will return a status of Selection timeout.
6190 cp = sp->cmd;
6191 b = SCSI_BUS_32(cp);
6192 if (ha->bus_settings[b].scsi_bus_dead)
6194 WRT_REG_WORD(&reg->host_cmd, HC_PAUSE_RISC);
6195 config_reg = RD_REG_WORD(&reg->cfg_1);
6196 WRT_REG_WORD(&reg->cfg_1,SET_SXP_BANK);
6197 scsi_control = RD_REG_WORD(&reg->scsiControlPins);
6198 WRT_REG_WORD(&reg->cfg_1,config_reg);
6199 WRT_REG_WORD(&reg->host_cmd, HC_RELEASE_RISC);
6201 if (scsi_control == SCSI_PHASE_INVALID)
6203 CMD_RESULT(cp) = DID_NO_CONNECT << 16;
6204 CMD_HANDLE(cp) = (unsigned char *) 0;
6205 /* ha->actthreads--; */
6206 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,95)
6207 sti();
6208 (*(cp)->scsi_done)(cp);
6209 cli();
6210 #else
6211 (*(cp)->scsi_done)(cp);
6212 #endif
6213 return(TRUE); /* bus is dead */
6215 else
6217 ha->bus_settings[b].scsi_bus_dead = FALSE;
6218 ha->bus_settings[b].failed_reset_count= 0;
6221 return(FALSE); /* bus is not dead */
6224 STATIC uint8_t
6225 qla12160_set_target_parameters(scsi_qla_host_t *ha, uint32_t b, uint32_t t, uint32_t l, nvram160_t *nv)
6227 uint16_t mb[MAILBOX_REGISTER_COUNT];
6229 /* Set Target Parameters. */
6230 mb[0] = MBC_SET_TARGET_PARAMETERS;
6231 mb[1] = (uint16_t)(b ? t | BIT_7 :t);
6232 mb[1] <<= 8;
6233 mb[2] = nv->bus[b].target[t].parameter.c << 8;
6234 mb[2] |= TP_AUTO_REQUEST_SENSE;
6235 mb[2] &= ~TP_STOP_QUEUE;
6236 mb[2] |= (nv->bus[b].target[t].flags.enable_ppr << 5);
6237 mb[3] = nv->bus[b].target[t].flags.sync_offset << 8;
6238 mb[3] |= nv->bus[b].target[t].sync_period;
6240 mb[6] = nv->bus[b].target[t].flags.ppr_options << 8;
6241 mb[6] |= nv->bus[b].target[t].flags.ppr_bus_width;
6242 return( qla1280_mailbox_command(ha, BIT_6|BIT_3|BIT_2|BIT_1|BIT_0, &mb[0]) ) ;
6245 STATIC void
6246 qla12160_get_target_parameters(scsi_qla_host_t *ha, uint32_t b, uint32_t t, uint32_t l)
6248 uint16_t mb[MAILBOX_REGISTER_COUNT];
6250 mb[0] = MBC_GET_TARGET_PARAMETERS;
6251 mb[1] = (uint16_t)(b ? t | BIT_7 :t);
6252 mb[1] <<= 8;
6253 qla1280_mailbox_command(ha, BIT_6|BIT_3|BIT_2|BIT_1|BIT_0, &mb[0]);
6254 if( mb[3] != 0 )
6255 printk(KERN_INFO "scsi(%d:%d:%d:%d): Synchronous tranfer at period %d, offset %d. \n",
6256 (int)ha->host_no, b, t, l, (mb[3] &0xff), (mb[3] >> 8));
6258 if ( (mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2 )
6259 printk(KERN_INFO "scsi(%d:%d:%d:%d): Dual Transition enabled.\n",
6260 (int)ha->host_no, b, t, l);
6264 #ifdef QL_DEBUG_ROUTINES
6265 /****************************************************************************/
6266 /* Driver Debug Functions. */
6267 /****************************************************************************/
6270 * Get byte from I/O port
6272 STATIC uint8_t
6273 qla1280_getbyte(uint8_t *port)
6275 uint8_t ret;
6277 #if MEMORY_MAPPED_IO
6278 ret = *port;
6279 #else
6280 ret = inb((int)port);
6281 #endif
6283 if (ql_debug_print)
6285 qla1280_print("qla1280_getbyte: address = ");
6286 qla1280_output_number((uint32_t)port, 16);
6287 qla1280_print(" data = 0x");
6288 qla1280_output_number((uint32_t)ret, 16);
6289 qla1280_print("\n\r");
6292 return(ret);
6296 * Get word from I/O port
6298 STATIC uint16_t
6299 qla1280_getword(uint16_t *port)
6301 uint16_t ret;
6303 #if MEMORY_MAPPED_IO
6304 ret = *port;
6305 #else
6306 ret = inw((int)port);
6307 #endif
6309 if (ql_debug_print)
6311 qla1280_print("qla1280_getword: address = ");
6312 qla1280_output_number((uint32_t)port, 16);
6313 qla1280_print(" data = 0x");
6314 qla1280_output_number((uint32_t)ret, 16);
6315 qla1280_print("\n\r");
6318 return(ret);
6322 * Get double word from I/O port
6324 STATIC uint32_t
6325 qla1280_getdword(uint32_t *port)
6327 uint32_t ret;
6329 #if MEMORY_MAPPED_IO
6330 ret = *port;
6331 #else
6332 ret = inl((int)port);
6333 #endif
6335 if (ql_debug_print)
6337 qla1280_print("qla1280_getdword: address = ");
6338 qla1280_output_number((uint32_t)port, 16);
6339 qla1280_print(" data = 0x");
6340 qla1280_output_number((uint32_t)ret, 16);
6341 qla1280_print("\n\r");
6344 return(ret);
6348 * Send byte to I/O port
6350 STATIC void
6351 qla1280_putbyte(uint8_t *port, uint8_t data)
6353 #if MEMORY_MAPPED_IO
6354 *port = data;
6355 #else
6356 outb(data, (int)port);
6357 #endif
6359 if (ql_debug_print)
6361 qla1280_print("qla1280_putbyte: address = ");
6362 qla1280_output_number((uint32_t)port, 16);
6363 qla1280_print(" data = 0x");
6364 qla1280_output_number((uint32_t)data, 16);
6365 qla1280_print("\n\r");
6370 * Send word to I/O port
6372 STATIC void
6373 qla1280_putword(uint16_t *port, uint16_t data)
6375 #if MEMORY_MAPPED_IO
6376 *port = data;
6377 #else
6378 #ifdef _LINUX_IOPORTS
6379 outw(data, (int)port);
6380 #else
6381 outw((int)port, data);
6382 #endif
6383 #endif
6385 if (ql_debug_print)
6387 qla1280_print("qla1280_putword: address = ");
6388 qla1280_output_number((uint32_t)port, 16);
6389 qla1280_print(" data = 0x");
6390 qla1280_output_number((uint32_t)data, 16);
6391 qla1280_print("\n\r");
6396 * Send double word to I/O port
6398 STATIC void
6399 qla1280_putdword(uint32_t *port, uint32_t data)
6401 #if MEMORY_MAPPED_IO
6402 *port = data;
6403 #else
6404 #ifdef _LINUX_IOPORTS
6405 outl(data,(int)port);
6406 #else
6407 outl((int)port, data);
6408 #endif
6409 #endif
6411 if (ql_debug_print)
6413 qla1280_print("qla1280_putdword: address = ");
6414 qla1280_output_number((uint32_t)port, 16);
6415 qla1280_print(" data = 0x");
6416 qla1280_output_number((uint32_t)data, 16);
6417 qla1280_print("\n\r");
6422 * Dummy function to prevent warnings for
6423 * declared and unused debug functions
6425 void
6426 qla1280_debug(void)
6428 qla1280_getbyte(0);
6429 qla1280_getword(0);
6430 qla1280_getdword(0);
6431 qla1280_putbyte(0, 0);
6432 qla1280_putword(0, 0);
6433 qla1280_putdword(0, 0);
6437 * Out character to COM2 port.
6438 * PORT must be at standard address for COM2 = 0x2F8,
6439 * or COM1 = 0x3F8
6441 #define OUTB(addr,data) outb((data),(addr))
6443 STATIC void
6444 qla1280_putc(uint8_t c)
6446 #ifdef QL_DEBUG_CONSOLE
6447 printk("%c", c);
6448 #else
6449 int com_addr = 0x2f8;
6450 int hardware_flow_control = 1;
6451 int software_flow_control = 0;
6452 uint8_t data;
6454 /* Wait for transmitter holding and shift registers for empty. */
6457 data = inb(com_addr+5);
6458 }while (!(data & BIT_6));
6461 * Set BAUD rate for COM2 to 19200 (0x6)
6464 /* Select rate divisor. */
6465 OUTB(com_addr+3, 0x83);
6467 /* BAUD rate divisor LSB. */
6468 OUTB(com_addr, 0xc); /* 0xC = 9600 baud */
6470 /* BAUD rate divisor MSB. */
6471 OUTB(com_addr+1, 0);
6473 /* Set No parity, 8 bits, 1 stop bit and
6474 select interrupt enable register. */
6475 OUTB(com_addr+3, 3);
6477 /* Disable interrupts. */
6478 OUTB(com_addr+1, 0);
6480 /* Set data terminal ready and request to send */
6481 OUTB(com_addr+4,3);
6483 if (hardware_flow_control)
6485 /* Wait for clear-to-send and data-set-ready */
6488 data = inb(com_addr+6) & (BIT_5 + BIT_4);
6489 }while (data != (BIT_5 + BIT_4));
6491 else if (software_flow_control)
6493 /* Test for data ready. */
6494 data = inb(com_addr+5);
6495 if (data & BIT_0)
6497 /* If XOFF */
6498 data = inb(com_addr);
6499 if (data == '\023')
6501 /* Wait for XON */
6504 /* Wait for char */
6507 data = inb(com_addr+5);
6508 }while (!(data & BIT_0));
6509 data = inb(com_addr);
6510 }while (data != '\021');
6515 /* Output character. */
6516 OUTB(com_addr, c);
6517 #endif
6521 * Out NULL terminated string to COM port.
6523 STATIC void
6524 qla1280_print(caddr_t s)
6526 if (ql_debug_print)
6528 #ifdef QL_DEBUG_CONSOLE
6529 printk("%s",s);
6530 #else
6531 /* Output string. */
6532 while (*s)
6533 qla1280_putc(*s++);
6534 #endif
6539 * Output long number to COM port.
6541 STATIC void
6542 qla1280_output_number(uint32_t n, uint8_t base)
6544 int8_t str[12];
6545 int8_t *s = &str[11];
6546 int8_t output = 0;
6547 int8_t hex = FALSE;
6549 if (ql_debug_print)
6551 if (base == 10 || base == 16)
6553 if (base == 16 && n > 9)
6554 hex = TRUE;
6556 *s = 0;
6559 s--;
6560 *s = n % base;
6561 if (*s > 9)
6562 *s += 55;
6563 else
6564 *s += '0';
6565 n /= base;
6566 }while (n);
6568 for (; *s; s++)
6570 if (*s != '0')
6571 output = 1;
6572 if (output)
6573 qla1280_putc(*s);
6575 if (!output)
6576 qla1280_putc(*--s);
6578 if (hex)
6579 qla1280_putc('h');
6584 STATIC void
6585 qla1280_dump_buffer(caddr_t b, uint32_t size)
6587 uint32_t cnt;
6588 uint8_t c;
6590 if (ql_debug_print)
6592 qla1280_print(
6593 " 0 1 2 3 4 5 6 7 8 9 Ah Bh Ch Dh Eh Fh\n\r");
6594 qla1280_print(
6595 "---------------------------------------------------------------\n\r");
6597 for (cnt = 0; cnt < size; )
6599 c = *b++;
6600 if (c < 16)
6601 qla1280_putc(' ');
6602 qla1280_output_number((uint32_t)c, 16);
6603 cnt++;
6604 if (!(cnt % 16))
6605 qla1280_print("\n\r");
6606 else if (c < 10)
6607 qla1280_print(" ");
6608 else
6609 qla1280_putc(' ');
6611 if (cnt % 16)
6612 qla1280_print("\n\r");
6615 /**************************************************************************
6616 * ql1280_print_scsi_cmd
6618 **************************************************************************/
6619 void qla1280_print_scsi_cmd(Scsi_Cmnd *cmd)
6621 scsi_qla_host_t *ha;
6622 struct Scsi_Host *host = cmd->host;
6623 srb_t *sp;
6624 /* struct scatterlist *sg; */
6626 int i;
6627 ha = (scsi_qla_host_t *) host->hostdata;
6629 ql_debug_print = 1;
6630 sp = (srb_t *) CMD_SP(cmd);
6631 sprintf(debug_buff,"SCSI Command @= 0x%p, Handle=0x%p\n\r", cmd, CMD_HANDLE(cmd));
6632 qla1280_print(debug_buff);
6633 sprintf(debug_buff," chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n\r",
6634 cmd->channel, cmd->target, cmd->lun, cmd->cmd_len);
6635 qla1280_print(debug_buff);
6636 qla1280_print(" CDB = ");
6637 for (i = 0; i < cmd->cmd_len; i++)
6639 sprintf(debug_buff,"0x%02x ", cmd->cmnd[i]);
6640 qla1280_print(debug_buff);
6642 sprintf(debug_buff," seg_cnt =%d\n\r",cmd->use_sg);
6643 qla1280_print(debug_buff);
6644 sprintf(debug_buff," request buffer=0x%p, request buffer len=0x%x\n\r",cmd->request_buffer,cmd->request_bufflen);
6645 qla1280_print(debug_buff);
6646 /* if( cmd->use_sg )
6648 sg = (struct scatterlist *) cmd->request_buffer;
6649 qla1280_print(" SG buffer: \n\r");
6650 qla1280_dump_buffer((caddr_t)sg, (cmd->use_sg*sizeof(struct scatterlist)) );
6651 } */
6652 sprintf(debug_buff," tag=%d, flags=0x%x, transfersize=0x%x \n\r",
6653 cmd->tag, cmd->flags,cmd->transfersize );
6654 qla1280_print(debug_buff);
6655 sprintf(debug_buff," Pid=%d, SP=0x%p\n\r", (int)cmd->pid, CMD_SP(cmd));
6656 qla1280_print(debug_buff);
6657 sprintf(debug_buff," r_start=0x%lx, u_start=0x%lx\n\r",sp->r_start,sp->u_start);
6658 qla1280_print(debug_buff);
6659 sprintf(debug_buff," underflow size = 0x%x, direction=0x%x, req.cmd=0x%x \n\r", cmd->underflow, sp->dir,cmd->request.cmd);
6660 qla1280_print(debug_buff);
6662 /**************************************************************************
6663 * ql1280_dump_device
6665 **************************************************************************/
6666 void
6667 ql1280_dump_device(scsi_qla_host_t *ha)
6670 Scsi_Cmnd *cp;
6671 srb_t *sp;
6672 int i;
6673 qla1280_print("Outstanding Commands on controller:\n\r");
6674 for ( i=0; i < MAX_OUTSTANDING_COMMANDS; i++ )
6676 if( (sp = ha->outstanding_cmds[i]) == NULL )
6677 continue;
6678 if( (cp = sp->cmd) == NULL )
6679 continue;
6680 qla1280_print_scsi_cmd(cp);
6684 #endif
6686 #ifdef QLA1280_UNUSED
6687 /**************************************************************************
6688 * ql1280_dump_regs
6690 **************************************************************************/
6691 static void qla1280_dump_regs(struct Scsi_Host *host)
6693 printk("Mailbox registers:\n");
6694 printk("qla1280 : mbox 0 0x%04x \n", inw(host->io_port + 0x70));
6695 printk("qla1280 : mbox 1 0x%04x \n", inw(host->io_port + 0x72));
6696 printk("qla1280 : mbox 2 0x%04x \n", inw(host->io_port + 0x74));
6697 printk("qla1280 : mbox 3 0x%04x \n", inw(host->io_port + 0x76));
6698 printk("qla1280 : mbox 4 0x%04x \n", inw(host->io_port + 0x78));
6699 printk("qla1280 : mbox 5 0x%04x \n", inw(host->io_port + 0x7a));
6701 #endif
6705 #if STOP_ON_ERROR
6706 /**************************************************************************
6707 * ql1280_panic
6709 **************************************************************************/
6710 static void qla1280_panic(char *cp, struct Scsi_Host *host)
6712 scsi_qla_host_t *ha;
6713 long *fp;
6715 ha = (scsi_qla_host_t *) host->hostdata;
6716 printk("qla1280 - PANIC: %s\n",cp);
6717 printk("Current time=0x%lx\n", jiffies);
6718 printk("Number of pending commands =0x%lx\n", ha->actthreads);
6719 printk("Number of SCSI queued commands =0x%lx\n", ha->qthreads);
6720 printk("Number of free entries = (%d)\n",ha->req_q_cnt);
6721 printk("Request Queue @ 0x%lx, Response Queue @ 0x%lx\n",
6722 ha->request_dma,
6723 ha->response_dma);
6724 printk("Request In Ptr %d\n", ha->req_ring_index );
6725 fp = (long *) &ha->flags;
6726 printk("HA flags =0x%lx\n", *fp);
6727 DEBUG2(ql_debug_print = 1;)
6728 /* DEBUG2(ql1280_dump_device((scsi_qla_host_t *) host->hostdata)); */
6729 #ifdef QLA1280_UNUSED
6730 qla1280_dump_regs(host);
6731 #endif
6732 sti();
6733 panic("Ooops");
6734 /* cli();
6735 for(;;)
6737 barrier();
6738 sti();
6742 #endif
6744 #ifdef QLA1280_UNUSED
6745 static void qla1280_set_flags(char * s)
6748 #endif
6750 /**************************************************************************
6751 * qla1280_setup
6753 * Handle Linux boot parameters. This routine allows for assigning a value
6754 * to a parameter with a ':' between the parameter and the value.
6755 * ie. qla1280=max_reqs:0x0A,verbose
6756 **************************************************************************/
6757 void
6758 qla1280_setup(char *s, int *dummy)
6760 char *end, *str, *cp;
6762 #ifdef QLA1280_UNUSED
6763 static struct
6765 const char *name;
6766 int siz;
6767 void (*func)();
6768 int arg;
6769 } options[] =
6771 { "dump_regs", 9, &qla1280_dump_regs, 0
6773 { "verbose", 7, &qla1280_set_flags, 0x1
6775 { "", 0, NULL, 0
6778 #endif
6780 printk("scsi: Processing Option str = %s\n", s);
6781 end = strchr(s, '\0');
6782 /* locate command */
6783 str = s;
6784 for( cp = s; *cp && cp != end; cp++ )
6786 cp = qla1280_get_token(cp, str);
6787 printk("scsi: token str = %s\n", str);
6788 /* if found execute routine */
6794 static char *qla1280_get_token(char *cmdline, char *str )
6796 register char *cp = cmdline;
6798 /* skip preceeding spaces */
6799 while(strchr(cp,' '))
6800 ++cp;
6801 /* symbol starts here */
6802 str = cp;
6803 /* skip char if not a space or : */
6804 while (*cp && !( strchr(cp,' ') || strchr(cp,':')) )
6805 cp++;
6806 *cp = '\0';
6807 return( cp );
6811 * Overrides for Emacs so that we almost follow Linus's tabbing style.
6812 * Emacs will notice this stuff at the end of the file and automatically
6813 * adjust the settings for this buffer only. This must remain at the end
6814 * of the file.
6815 * ---------------------------------------------------------------------------
6816 * Local variables:
6817 * c-indent-level: 2
6818 * c-brace-imaginary-offset: 0
6819 * c-brace-offset: -2
6820 * c-argdecl-indent: 2
6821 * c-label-offset: -2
6822 * c-continued-statement-offset: 2
6823 * c-continued-brace-offset: 0
6824 * indent-tabs-mode: nil
6825 * tab-width: 8
6826 * End: