Import 2.3.41pre2
[davej-history.git] / drivers / scsi / qlogicfc.c
bloba4b9332b0dd5616305e321bf92d68cf483cc8691
1 /*
2 * QLogic ISP2x00 SCSI-FCP
3 * Written by Erik H. Moe, ehm@cris.com
4 * Copyright 1995, Erik H. Moe
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
17 /* Renamed and updated to 1.3.x by Michael Griffith <grif@cs.ucr.edu> */
19 /* This is a version of the isp1020 driver which was modified by
20 * Chris Loveland <cwl@iol.unh.edu> to support the isp2100 and isp2200
24 * $Date: 1995/09/22 02:23:15 $
25 * $Revision: 0.5 $
27 * $Log: isp1020.c,v $
28 * Revision 0.5 1995/09/22 02:23:15 root
29 * do auto request sense
31 * Revision 0.4 1995/08/07 04:44:33 root
32 * supply firmware with driver.
33 * numerous bug fixes/general cleanup of code.
35 * Revision 0.3 1995/07/16 16:15:39 root
36 * added reset/abort code.
38 * Revision 0.2 1995/06/29 03:14:19 root
39 * fixed biosparam.
40 * added queue protocol.
42 * Revision 0.1 1995/06/25 01:55:45 root
43 * Initial release.
47 #include <linux/blk.h>
48 #include <linux/kernel.h>
49 #include <linux/string.h>
50 #include <linux/ioport.h>
51 #include <linux/sched.h>
52 #include <linux/types.h>
53 #include <linux/pci.h>
54 #include <linux/delay.h>
55 #include <linux/unistd.h>
56 #include <linux/spinlock.h>
57 #include <asm/io.h>
58 #include <asm/irq.h>
60 #include "sd.h"
61 #include "hosts.h"
62 #include "qlogicfc.h"
64 /* Configuration section **************************************************** */
66 /* Set the following macro to 1 to reload the ISP2x00's firmware. This is
67 version 1.15.37 of the isp2100's firmware and version 2.00.16 of the
68 isp2200's firmware.
71 #define RELOAD_FIRMWARE 1
73 #define USE_NVRAM_DEFAULTS 1
75 #define ISP2x00_PORTDB 1
77 /* Set the following to 1 to include fabric support, fabric support is
78 * currently not as well tested as the other aspects of the driver */
80 #define ISP2x00_FABRIC 0
82 /* Macros used for debugging */
84 #define DEBUG_ISP2x00 1
85 #define DEBUG_ISP2x00_INT 1
86 #define DEBUG_ISP2x00_INTR 1
87 #define DEBUG_ISP2x00_SETUP 1
89 #define DEBUG_ISP2x00_FABRIC 1
91 /* #define TRACE_ISP 1 */
94 #define DEFAULT_LOOP_COUNT 10000000
96 /* End Configuration section ************************************************ */
98 #include <linux/module.h>
100 #if TRACE_ISP
102 #define TRACE_BUF_LEN (32*1024)
104 struct {
105 u_long next;
106 struct {
107 u_long time;
108 u_int index;
109 u_int addr;
110 u_char *name;
111 } buf[TRACE_BUF_LEN];
112 } trace;
114 #define TRACE(w, i, a) \
116 unsigned long flags; \
118 save_flags(flags); \
119 cli(); \
120 trace.buf[trace.next].name = (w); \
121 trace.buf[trace.next].time = jiffies; \
122 trace.buf[trace.next].index = (i); \
123 trace.buf[trace.next].addr = (long) (a); \
124 trace.next = (trace.next + 1) & (TRACE_BUF_LEN - 1); \
125 restore_flags(flags); \
128 #else
129 #define TRACE(w, i, a)
130 #endif
132 #if DEBUG_ISP2x00_FABRIC
133 #define DEBUG_FABRIC(x) x
134 #else
135 #define DEBUG_FABRIC(x)
136 #endif /* DEBUG_ISP2x00_FABRIC */
139 #if DEBUG_ISP2x00
140 #define ENTER(x) printk("isp2x00 : entering %s()\n", x);
141 #define LEAVE(x) printk("isp2x00 : leaving %s()\n", x);
142 #define DEBUG(x) x
143 #else
144 #define ENTER(x)
145 #define LEAVE(x)
146 #define DEBUG(x)
147 #endif /* DEBUG_ISP2x00 */
149 #if DEBUG_ISP2x00_INTR
150 #define ENTER_INTR(x) printk("isp2x00 : entering %s()\n", x);
151 #define LEAVE_INTR(x) printk("isp2x00 : leaving %s()\n", x);
152 #define DEBUG_INTR(x) x
153 #else
154 #define ENTER_INTR(x)
155 #define LEAVE_INTR(x)
156 #define DEBUG_INTR(x)
157 #endif /* DEBUG ISP2x00_INTR */
160 #if BITS_PER_LONG > 32
161 #define virt_to_bus_low32(x) ((u32) (0xffffffff & virt_to_bus(x)))
162 #define virt_to_bus_high32(x) ((u32) (0xffffffff & (virt_to_bus(x)>>32)))
163 #define bus_to_virt_low32(x) ((u32) (0xffffffff & bus_to_virt(x)))
164 #define bus_to_virt_high32(x) ((u32) (0xffffffff & (bus_to_virt(x)>>32)))
165 #else
166 #define virt_to_bus_low32(x) virt_to_bus(x)
167 #define virt_to_bus_high32(x) 0x0
168 #define bus_to_virt_low32(x) bus_to_virt(x)
169 #define bus_to_virt_high32(x) 0x0
170 #endif
172 #define ISP2100_REV_ID1 1
173 #define ISP2100_REV_ID3 3
174 #define ISP2200_REV_ID5 5
176 /* host configuration and control registers */
177 #define HOST_HCCR 0xc0 /* host command and control */
179 /* pci bus interface registers */
180 #define FLASH_BIOS_ADDR 0x00
181 #define FLASH_BIOS_DATA 0x02
182 #define ISP_CTRL_STATUS 0x06 /* configuration register #1 */
183 #define PCI_INTER_CTL 0x08 /* pci interupt control */
184 #define PCI_INTER_STS 0x0a /* pci interupt status */
185 #define PCI_SEMAPHORE 0x0c /* pci semaphore */
186 #define PCI_NVRAM 0x0e /* pci nvram interface */
188 /* mailbox registers */
189 #define MBOX0 0x10 /* mailbox 0 */
190 #define MBOX1 0x12 /* mailbox 1 */
191 #define MBOX2 0x14 /* mailbox 2 */
192 #define MBOX3 0x16 /* mailbox 3 */
193 #define MBOX4 0x18 /* mailbox 4 */
194 #define MBOX5 0x1a /* mailbox 5 */
195 #define MBOX6 0x1c /* mailbox 6 */
196 #define MBOX7 0x1e /* mailbox 7 */
198 /* mailbox command complete status codes */
199 #define MBOX_COMMAND_COMPLETE 0x4000
200 #define INVALID_COMMAND 0x4001
201 #define HOST_INTERFACE_ERROR 0x4002
202 #define TEST_FAILED 0x4003
203 #define COMMAND_ERROR 0x4005
204 #define COMMAND_PARAM_ERROR 0x4006
205 #define PORT_ID_USED 0x4007
206 #define LOOP_ID_USED 0x4008
207 #define ALL_IDS_USED 0x4009
209 /* async event status codes */
210 #define RESET_DETECTED 0x8001
211 #define SYSTEM_ERROR 0x8002
212 #define REQUEST_TRANSFER_ERROR 0x8003
213 #define RESPONSE_TRANSFER_ERROR 0x8004
214 #define REQUEST_QUEUE_WAKEUP 0x8005
215 #define LIP_OCCURED 0x8010
216 #define LOOP_UP 0x8011
217 #define LOOP_DOWN 0x8012
218 #define LIP_RECEIVED 0x8013
219 #define PORT_DB_CHANGED 0x8014
220 #define CHANGE_NOTIFICATION 0x8015
221 #define SCSI_COMMAND_COMPLETE 0x8020
222 #define POINT_TO_POINT_UP 0x8030
223 #define CONNECTION_MODE 0x8036
225 struct Entry_header {
226 u_char entry_type;
227 u_char entry_cnt;
228 u_char sys_def_1;
229 u_char flags;
232 /* entry header type commands */
233 #if BITS_PER_LONG > 32
234 #define ENTRY_COMMAND 0x19
235 #define ENTRY_CONTINUATION 0x0a
236 #else
237 #define ENTRY_COMMAND 0x11
238 #define ENTRY_CONTINUATION 0x02
239 #endif
241 #define ENTRY_STATUS 0x03
242 #define ENTRY_MARKER 0x04
245 /* entry header flag definitions */
246 #define EFLAG_BUSY 2
247 #define EFLAG_BAD_HEADER 4
248 #define EFLAG_BAD_PAYLOAD 8
250 #if BITS_PER_LONG > 32
251 struct dataseg {
252 u_int d_base;
253 u_int d_base_hi;
254 u_int d_count;
257 struct Command_Entry {
258 struct Entry_header hdr;
259 u_int handle;
260 u_char target_lun;
261 u_char target_id;
262 u_short expanded_lun;
263 u_short control_flags;
264 u_short rsvd2;
265 u_short time_out;
266 u_short segment_cnt;
267 u_char cdb[16];
268 u_int total_byte_cnt;
269 struct dataseg dataseg[DATASEGS_PER_COMMAND];
272 #else
273 struct dataseg {
274 u_int d_base;
275 u_int d_count;
278 struct Command_Entry {
279 struct Entry_header hdr;
280 u_int handle;
281 u_char target_lun;
282 u_char target_id;
283 u_short expanded_lun;
284 u_short control_flags;
285 u_short rsvd2;
286 u_short time_out;
287 u_short segment_cnt;
288 u_char cdb[16];
289 u_int total_byte_cnt;
290 struct dataseg dataseg[DATASEGS_PER_COMMAND];
293 #endif
296 /* command entry control flag definitions */
297 #define CFLAG_NODISC 0x01
298 #define CFLAG_HEAD_TAG 0x02
299 #define CFLAG_ORDERED_TAG 0x04
300 #define CFLAG_SIMPLE_TAG 0x08
301 #define CFLAG_TAR_RTN 0x10
302 #define CFLAG_READ 0x20
303 #define CFLAG_WRITE 0x40
305 #if BITS_PER_LONG > 32
306 struct Continuation_Entry {
307 struct Entry_header hdr;
308 struct dataseg dataseg[DATASEGS_PER_CONT];
310 #else
311 struct Continuation_Entry {
312 struct Entry_header hdr;
313 u32 rsvd;
314 struct dataseg dataseg[DATASEGS_PER_CONT];
316 #endif
318 struct Marker_Entry {
319 struct Entry_header hdr;
320 u_int reserved;
321 u_char target_lun;
322 u_char target_id;
323 u_char modifier;
324 u_char expanded_lun;
325 u_char rsvds[52];
328 /* marker entry modifier definitions */
329 #define SYNC_DEVICE 0
330 #define SYNC_TARGET 1
331 #define SYNC_ALL 2
333 struct Status_Entry {
334 struct Entry_header hdr;
335 u_int handle;
336 u_short scsi_status;
337 u_short completion_status;
338 u_short state_flags;
339 u_short status_flags;
340 u_short res_info_len;
341 u_short req_sense_len;
342 u_int residual;
343 u_char res_info[8];
344 u_char req_sense_data[32];
347 /* status entry completion status definitions */
348 #define CS_COMPLETE 0x0000
349 #define CS_DMA_ERROR 0x0002
350 #define CS_RESET_OCCURRED 0x0004
351 #define CS_ABORTED 0x0005
352 #define CS_TIMEOUT 0x0006
353 #define CS_DATA_OVERRUN 0x0007
354 #define CS_DATA_UNDERRUN 0x0015
355 #define CS_QUEUE_FULL 0x001c
356 #define CS_PORT_UNAVAILABLE 0x0028
357 #define CS_PORT_LOGGED_OUT 0x0029
358 #define CS_PORT_CONFIG_CHANGED 0x002a
360 /* status entry state flag definitions */
361 #define SF_SENT_CDB 0x0400
362 #define SF_TRANSFERRED_DATA 0x0800
363 #define SF_GOT_STATUS 0x1000
365 /* status entry status flag definitions */
366 #define STF_BUS_RESET 0x0008
367 #define STF_DEVICE_RESET 0x0010
368 #define STF_ABORTED 0x0020
369 #define STF_TIMEOUT 0x0040
371 /* interupt control commands */
372 #define ISP_EN_INT 0x8000
373 #define ISP_EN_RISC 0x0008
375 /* host control commands */
376 #define HCCR_NOP 0x0000
377 #define HCCR_RESET 0x1000
378 #define HCCR_PAUSE 0x2000
379 #define HCCR_RELEASE 0x3000
380 #define HCCR_SINGLE_STEP 0x4000
381 #define HCCR_SET_HOST_INTR 0x5000
382 #define HCCR_CLEAR_HOST_INTR 0x6000
383 #define HCCR_CLEAR_RISC_INTR 0x7000
384 #define HCCR_BP_ENABLE 0x8000
385 #define HCCR_BIOS_DISABLE 0x9000
386 #define HCCR_TEST_MODE 0xf000
388 #define RISC_BUSY 0x0004
390 /* mailbox commands */
391 #define MBOX_NO_OP 0x0000
392 #define MBOX_LOAD_RAM 0x0001
393 #define MBOX_EXEC_FIRMWARE 0x0002
394 #define MBOX_DUMP_RAM 0x0003
395 #define MBOX_WRITE_RAM_WORD 0x0004
396 #define MBOX_READ_RAM_WORD 0x0005
397 #define MBOX_MAILBOX_REG_TEST 0x0006
398 #define MBOX_VERIFY_CHECKSUM 0x0007
399 #define MBOX_ABOUT_FIRMWARE 0x0008
400 #define MBOX_LOAD_RISC_RAM 0x0009
401 #define MBOX_DUMP_RISC_RAM 0x000a
402 #define MBOX_CHECK_FIRMWARE 0x000e
403 #define MBOX_INIT_REQ_QUEUE 0x0010
404 #define MBOX_INIT_RES_QUEUE 0x0011
405 #define MBOX_EXECUTE_IOCB 0x0012
406 #define MBOX_WAKE_UP 0x0013
407 #define MBOX_STOP_FIRMWARE 0x0014
408 #define MBOX_ABORT_IOCB 0x0015
409 #define MBOX_ABORT_DEVICE 0x0016
410 #define MBOX_ABORT_TARGET 0x0017
411 #define MBOX_BUS_RESET 0x0018
412 #define MBOX_STOP_QUEUE 0x0019
413 #define MBOX_START_QUEUE 0x001a
414 #define MBOX_SINGLE_STEP_QUEUE 0x001b
415 #define MBOX_ABORT_QUEUE 0x001c
416 #define MBOX_GET_DEV_QUEUE_STATUS 0x001d
417 #define MBOX_GET_FIRMWARE_STATUS 0x001f
418 #define MBOX_GET_INIT_SCSI_ID 0x0020
419 #define MBOX_GET_RETRY_COUNT 0x0022
420 #define MBOX_GET_TARGET_PARAMS 0x0028
421 #define MBOX_GET_DEV_QUEUE_PARAMS 0x0029
422 #define MBOX_SET_RETRY_COUNT 0x0032
423 #define MBOX_SET_TARGET_PARAMS 0x0038
424 #define MBOX_SET_DEV_QUEUE_PARAMS 0x0039
425 #define MBOX_EXECUTE_IOCB64 0x0054
426 #define MBOX_INIT_FIRMWARE 0x0060
427 #define MBOX_GET_INIT_CB 0x0061
428 #define MBOX_INIT_LIP 0x0062
429 #define MBOX_GET_POS_MAP 0x0063
430 #define MBOX_GET_PORT_DB 0x0064
431 #define MBOX_CLEAR_ACA 0x0065
432 #define MBOX_TARGET_RESET 0x0066
433 #define MBOX_CLEAR_TASK_SET 0x0067
434 #define MBOX_ABORT_TASK_SET 0x0068
435 #define MBOX_GET_FIRMWARE_STATE 0x0069
436 #define MBOX_GET_PORT_NAME 0x006a
437 #define MBOX_SEND_SNS 0x006e
438 #define MBOX_PORT_LOGIN 0x006f
439 #define MBOX_SEND_CHANGE_REQUEST 0x0070
440 #define MBOX_PORT_LOGOUT 0x0071
442 #include "qlogicfc_asm.c"
444 /* Each element in mbox_param is an 8 bit bitmap where each bit indicates
445 if that mbox should be copied as input. For example 0x2 would mean
446 only copy mbox1. */
448 const u_char mbox_param[] =
450 0x01, /* MBOX_NO_OP */
451 0x1f, /* MBOX_LOAD_RAM */
452 0x03, /* MBOX_EXEC_FIRMWARE */
453 0x1f, /* MBOX_DUMP_RAM */
454 0x07, /* MBOX_WRITE_RAM_WORD */
455 0x03, /* MBOX_READ_RAM_WORD */
456 0xff, /* MBOX_MAILBOX_REG_TEST */
457 0x03, /* MBOX_VERIFY_CHECKSUM */
458 0x01, /* MBOX_ABOUT_FIRMWARE */
459 0xff, /* MBOX_LOAD_RISC_RAM */
460 0xff, /* MBOX_DUMP_RISC_RAM */
461 0x00, /* 0x000b */
462 0x00, /* 0x000c */
463 0x00, /* 0x000d */
464 0x01, /* MBOX_CHECK_FIRMWARE */
465 0x00, /* 0x000f */
466 0x1f, /* MBOX_INIT_REQ_QUEUE */
467 0x2f, /* MBOX_INIT_RES_QUEUE */
468 0x0f, /* MBOX_EXECUTE_IOCB */
469 0x03, /* MBOX_WAKE_UP */
470 0x01, /* MBOX_STOP_FIRMWARE */
471 0x0f, /* MBOX_ABORT_IOCB */
472 0x03, /* MBOX_ABORT_DEVICE */
473 0x07, /* MBOX_ABORT_TARGET */
474 0x03, /* MBOX_BUS_RESET */
475 0x03, /* MBOX_STOP_QUEUE */
476 0x03, /* MBOX_START_QUEUE */
477 0x03, /* MBOX_SINGLE_STEP_QUEUE */
478 0x03, /* MBOX_ABORT_QUEUE */
479 0x03, /* MBOX_GET_DEV_QUEUE_STATUS */
480 0x00, /* 0x001e */
481 0x01, /* MBOX_GET_FIRMWARE_STATUS */
482 0x01, /* MBOX_GET_INIT_SCSI_ID */
483 0x00, /* 0x0021 */
484 0x01, /* MBOX_GET_RETRY_COUNT */
485 0x00, /* 0x0023 */
486 0x00, /* 0x0024 */
487 0x00, /* 0x0025 */
488 0x00, /* 0x0026 */
489 0x00, /* 0x0027 */
490 0x03, /* MBOX_GET_TARGET_PARAMS */
491 0x03, /* MBOX_GET_DEV_QUEUE_PARAMS */
492 0x00, /* 0x002a */
493 0x00, /* 0x002b */
494 0x00, /* 0x002c */
495 0x00, /* 0x002d */
496 0x00, /* 0x002e */
497 0x00, /* 0x002f */
498 0x00, /* 0x0030 */
499 0x00, /* 0x0031 */
500 0x07, /* MBOX_SET_RETRY_COUNT */
501 0x00, /* 0x0033 */
502 0x00, /* 0x0034 */
503 0x00, /* 0x0035 */
504 0x00, /* 0x0036 */
505 0x00, /* 0x0037 */
506 0x0f, /* MBOX_SET_TARGET_PARAMS */
507 0x0f, /* MBOX_SET_DEV_QUEUE_PARAMS */
508 0x00, /* 0x003a */
509 0x00, /* 0x003b */
510 0x00, /* 0x003c */
511 0x00, /* 0x003d */
512 0x00, /* 0x003e */
513 0x00, /* 0x003f */
514 0x00, /* 0x0040 */
515 0x00, /* 0x0041 */
516 0x00, /* 0x0042 */
517 0x00, /* 0x0043 */
518 0x00, /* 0x0044 */
519 0x00, /* 0x0045 */
520 0x00, /* 0x0046 */
521 0x00, /* 0x0047 */
522 0x00, /* 0x0048 */
523 0x00, /* 0x0049 */
524 0x00, /* 0x004a */
525 0x00, /* 0x004b */
526 0x00, /* 0x004c */
527 0x00, /* 0x004d */
528 0x00, /* 0x004e */
529 0x00, /* 0x004f */
530 0x00, /* 0x0050 */
531 0x00, /* 0x0051 */
532 0x00, /* 0x0052 */
533 0x00, /* 0x0053 */
534 0xcf, /* MBOX_EXECUTE_IOCB64 */
535 0x00, /* 0x0055 */
536 0x00, /* 0x0056 */
537 0x00, /* 0x0057 */
538 0x00, /* 0x0058 */
539 0x00, /* 0x0059 */
540 0x00, /* 0x005a */
541 0x00, /* 0x005b */
542 0x00, /* 0x005c */
543 0x00, /* 0x005d */
544 0x00, /* 0x005e */
545 0x00, /* 0x005f */
546 0xff, /* MBOX_INIT_FIRMWARE */
547 0xcd, /* MBOX_GET_INIT_CB */
548 0x01, /* MBOX_INIT_LIP */
549 0xcd, /* MBOX_GET_POS_MAP */
550 0xcf, /* MBOX_GET_PORT_DB */
551 0x03, /* MBOX_CLEAR_ACA */
552 0x03, /* MBOX_TARGET_RESET */
553 0x03, /* MBOX_CLEAR_TASK_SET */
554 0x03, /* MBOX_ABORT_TASK_SET */
555 0x01, /* MBOX_GET_FIRMWARE_STATE */
556 0x03, /* MBOX_GET_PORT_NAME */
557 0x00, /* 0x006b */
558 0x00, /* 0x006c */
559 0x00, /* 0x006d */
560 0xcf, /* MBOX_SEND_SNS */
561 0x0f, /* MBOX_PORT_LOGIN */
562 0x03, /* MBOX_SEND_CHANGE_REQUEST */
563 0x03, /* MBOX_PORT_LOGOUT */
566 #define MAX_MBOX_COMMAND (sizeof(mbox_param)/sizeof(u_short))
569 struct id_name_map {
570 u64 wwn;
571 u_char loop_id;
574 struct sns_cb {
575 u_short len;
576 u_short res1;
577 u_int response_low;
578 u_int response_high;
579 u_short sub_len;
580 u_short res2;
581 u_char data[44];
584 /* address of instance of this struct is passed to adapter to initialize things
586 struct init_cb {
587 u_char version;
588 u_char reseverd1[1];
589 u_short firm_opts;
590 u_short max_frame_len;
591 u_short max_iocb;
592 u_short exec_throttle;
593 u_char retry_cnt;
594 u_char retry_delay;
595 u_short node_name[4];
596 u_short hard_addr;
597 u_char reserved2[10];
598 u_short req_queue_out;
599 u_short res_queue_in;
600 u_short req_queue_len;
601 u_short res_queue_len;
602 u_int req_queue_addr_lo;
603 u_int req_queue_addr_high;
604 u_int res_queue_addr_lo;
605 u_int res_queue_addr_high;
606 /* the rest of this structure only applies to the isp2200 */
607 u_short lun_enables;
608 u_char cmd_resource_cnt;
609 u_char notify_resource_cnt;
610 u_short timeout;
611 u_short reserved3;
612 u_short add_firm_opts;
613 u_char res_accum_timer;
614 u_char irq_delay_timer;
615 u_short special_options;
616 u_short reserved4[13];
620 * The result queue can be quite a bit smaller since continuation entries
621 * do not show up there:
623 #define RES_QUEUE_LEN ((QLOGICFC_REQ_QUEUE_LEN + 1) / 8 - 1)
624 #define QUEUE_ENTRY_LEN 64
626 #if ISP2x00_FABRIC
627 #define QLOGICFC_MAX_ID 0xff
628 #else
629 #define QLOGICFC_MAX_ID 0x7d
630 #endif
632 #define QLOGICFC_MAX_LUN 128
633 #define QLOGICFC_MAX_LOOP_ID 0x7d
635 /* adapter_state values */
636 #define AS_FIRMWARE_DEAD -1
637 #define AS_LOOP_DOWN 0
638 #define AS_LOOP_GOOD 1
639 #define AS_REDO_FABRIC_PORTDB 2
640 #define AS_REDO_LOOP_PORTDB 4
642 struct isp2x00_hostdata {
643 u_char revision;
644 struct pci_dev *pci_dev;
645 /* result and request queues (shared with isp2x00): */
646 u_int req_in_ptr; /* index of next request slot */
647 u_int res_out_ptr; /* index of next result slot */
649 /* this is here so the queues are nicely aligned */
650 long send_marker; /* do we need to send a marker? */
652 char res[RES_QUEUE_LEN + 1][QUEUE_ENTRY_LEN];
653 char req[QLOGICFC_REQ_QUEUE_LEN + 1][QUEUE_ENTRY_LEN];
654 struct init_cb control_block;
655 int adapter_state;
656 unsigned long int tag_ages[126];
657 Scsi_Cmnd *handle_ptrs[QLOGICFC_REQ_QUEUE_LEN + 1];
658 unsigned long handle_serials[QLOGICFC_REQ_QUEUE_LEN + 1];
659 struct id_name_map port_db[QLOGICFC_MAX_ID + 1];
660 u_char mbox_done;
661 u64 wwn;
662 u_int port_id;
663 u_char queued;
664 u_char host_id;
668 /* queue length's _must_ be power of two: */
669 #define QUEUE_DEPTH(in, out, ql) ((in - out) & (ql))
670 #define REQ_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, \
671 QLOGICFC_REQ_QUEUE_LEN)
672 #define RES_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, RES_QUEUE_LEN)
674 static void isp2x00_enable_irqs(struct Scsi_Host *);
675 static void isp2x00_disable_irqs(struct Scsi_Host *);
676 static int isp2x00_init(struct Scsi_Host *);
677 static int isp2x00_reset_hardware(struct Scsi_Host *);
678 static int isp2x00_mbox_command(struct Scsi_Host *, u_short[]);
679 static int isp2x00_return_status(struct Status_Entry *);
680 static void isp2x00_intr_handler(int, void *, struct pt_regs *);
681 static void do_isp2x00_intr_handler(int, void *, struct pt_regs *);
682 static int isp2x00_make_portdb(struct Scsi_Host *);
684 #if ISP2x00_FABRIC
685 static int isp2x00_init_fabric(struct Scsi_Host *, struct id_name_map *, int);
686 #endif
688 #if USE_NVRAM_DEFAULTS
689 static int isp2x00_get_nvram_defaults(struct Scsi_Host *, struct init_cb *);
690 static u_short isp2x00_read_nvram_word(struct Scsi_Host *, u_short);
691 #endif
693 #if DEBUG_ISP2x00
694 static void isp2x00_print_scsi_cmd(Scsi_Cmnd *);
695 #endif
697 #if DEBUG_ISP2x00_INTR
698 static void isp2x00_print_status_entry(struct Status_Entry *);
699 #endif
701 static inline void isp2x00_enable_irqs(struct Scsi_Host *host)
703 outw(ISP_EN_INT | ISP_EN_RISC, host->io_port + PCI_INTER_CTL);
707 static inline void isp2x00_disable_irqs(struct Scsi_Host *host)
709 outw(0x0, host->io_port + PCI_INTER_CTL);
713 int isp2x00_detect(Scsi_Host_Template * tmpt)
715 int hosts = 0;
716 int wait_time;
717 struct Scsi_Host *host = NULL;
718 struct isp2x00_hostdata *hostdata;
719 struct pci_dev *pdev = NULL;
720 unsigned short device_ids[2];
721 int i;
724 ENTER("isp2x00_detect");
726 device_ids[0] = PCI_DEVICE_ID_QLOGIC_ISP2100;
727 device_ids[1] = PCI_DEVICE_ID_QLOGIC_ISP2200;
729 tmpt->proc_name = "isp2x00";
731 if (pci_present() == 0) {
732 printk("qlogicfc : PCI not present\n");
733 return 0;
736 for (i=0; i<2; i++){
737 while ((pdev = pci_find_device(PCI_VENDOR_ID_QLOGIC, device_ids[i], pdev))) {
739 host = scsi_register(tmpt, sizeof(struct isp2x00_hostdata));
740 host->max_id = QLOGICFC_MAX_ID + 1;
741 host->max_lun = QLOGICFC_MAX_LUN;
742 host->hostt->use_new_eh_code = 1;
743 hostdata = (struct isp2x00_hostdata *) host->hostdata;
745 memset(hostdata, 0, sizeof(struct isp2x00_hostdata));
746 hostdata->pci_dev = pdev;
748 hostdata->queued = 0;
749 /* set up the control block */
750 hostdata->control_block.version = 0x1;
751 hostdata->control_block.firm_opts = 0x0108;
752 hostdata->control_block.max_frame_len = 2048;
753 hostdata->control_block.max_iocb = 256;
754 hostdata->control_block.exec_throttle = QLOGICFC_CMD_PER_LUN;
755 hostdata->control_block.retry_delay = 5;
756 hostdata->control_block.retry_cnt = 1;
757 hostdata->control_block.node_name[0] = 0x0020;
758 hostdata->control_block.node_name[1] = 0xE000;
759 hostdata->control_block.node_name[2] = 0x008B;
760 hostdata->control_block.node_name[3] = 0x0000;
761 hostdata->control_block.hard_addr = 0x0003;
762 hostdata->control_block.req_queue_len = QLOGICFC_REQ_QUEUE_LEN + 1;
763 hostdata->control_block.res_queue_len = RES_QUEUE_LEN + 1;
764 hostdata->control_block.res_queue_addr_lo = virt_to_bus_low32(&hostdata->res);
765 hostdata->control_block.res_queue_addr_high = virt_to_bus_high32(&hostdata->res);
766 hostdata->control_block.req_queue_addr_lo = virt_to_bus_low32(&hostdata->req);
767 hostdata->control_block.req_queue_addr_high = virt_to_bus_high32(&hostdata->req);
770 hostdata->adapter_state = AS_LOOP_DOWN;
771 hostdata->host_id = hosts;
773 if (isp2x00_init(host) || isp2x00_reset_hardware(host)) {
774 scsi_unregister(host);
775 continue;
777 host->this_id = 0;
779 if (request_irq(host->irq, do_isp2x00_intr_handler, SA_INTERRUPT | SA_SHIRQ, "qlogicfc", host)) {
780 printk("qlogicfc%d : interrupt %d already in use\n",
781 hostdata->host_id, host->irq);
782 scsi_unregister(host);
783 continue;
785 if (check_region(host->io_port, 0xff)) {
786 printk("qlogicfc%d : i/o region 0x%lx-0x%lx already "
787 "in use\n",
788 hostdata->host_id, host->io_port, host->io_port + 0xff);
789 free_irq(host->irq, host);
790 scsi_unregister(host);
791 continue;
793 request_region(host->io_port, 0xff, "qlogicfc");
795 outw(0x0, host->io_port + PCI_SEMAPHORE);
796 outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
797 isp2x00_enable_irqs(host);
798 /* wait for the loop to come up */
799 for (wait_time = jiffies + 10 * HZ; wait_time > jiffies && hostdata->adapter_state == AS_LOOP_DOWN;)
800 barrier();
802 if (hostdata->adapter_state == AS_LOOP_DOWN) {
803 printk("qlogicfc%d : link is not up\n", hostdata->host_id);
805 hosts++;
810 /* this busy loop should not be needed but the isp2x00 seems to need
811 some time before recognizing it is attached to a fabric */
813 #if ISP2x00_FABRIC
814 for (wait_time = jiffies + 5 * HZ; wait_time > jiffies;)
815 barrier();
816 #endif
818 LEAVE("isp2x00_detect");
820 return hosts;
824 static int isp2x00_make_portdb(struct Scsi_Host *host)
827 short param[8];
828 int i, j;
829 struct id_name_map temp[QLOGICFC_MAX_ID + 1];
830 struct isp2x00_hostdata *hostdata;
832 isp2x00_disable_irqs(host);
834 memset(temp, 0, sizeof(temp));
835 hostdata = (struct isp2x00_hostdata *) host->hostdata;
837 #if ISP2x00_FABRIC
838 for (i = 0x81; i < QLOGICFC_MAX_ID; i++) {
839 param[0] = MBOX_PORT_LOGOUT;
840 param[1] = i << 8;
841 param[2] = 0;
842 param[3] = 0;
844 isp2x00_mbox_command(host, param);
846 if (param[0] != MBOX_COMMAND_COMPLETE) {
848 DEBUG_FABRIC(printk("qlogicfc%d : logout failed %x %x\n", hostdata->host_id, i, param[0]));
851 #endif
854 param[0] = MBOX_GET_INIT_SCSI_ID;
856 isp2x00_mbox_command(host, param);
858 if (param[0] == MBOX_COMMAND_COMPLETE) {
859 hostdata->port_id = ((u_int) param[3]) << 16;
860 hostdata->port_id |= param[2];
861 temp[0].loop_id = param[1];
862 temp[0].wwn = hostdata->wwn;
864 else {
865 printk("qlogicfc%d : error getting scsi id.\n", hostdata->host_id);
868 for (i = 0; i <=QLOGICFC_MAX_ID; i++)
869 temp[i].loop_id = temp[0].loop_id;
871 for (i = 0, j = 1; i <= QLOGICFC_MAX_LOOP_ID; i++) {
872 param[0] = MBOX_GET_PORT_NAME;
873 param[1] = (i << 8) & 0xff00;
875 isp2x00_mbox_command(host, param);
877 if (param[0] == MBOX_COMMAND_COMPLETE) {
878 temp[j].loop_id = i;
879 temp[j].wwn = ((u64) (param[2] & 0xff)) << 56;
880 temp[j].wwn |= ((u64) ((param[2] >> 8) & 0xff)) << 48;
881 temp[j].wwn |= ((u64) (param[3] & 0xff)) << 40;
882 temp[j].wwn |= ((u64) ((param[3] >> 8) & 0xff)) << 32;
883 temp[j].wwn |= ((u64) (param[6] & 0xff)) << 24;
884 temp[j].wwn |= ((u64) ((param[6] >> 8) & 0xff)) << 16;
885 temp[j].wwn |= ((u64) (param[7] & 0xff)) << 8;
886 temp[j].wwn |= ((u64) ((param[7] >> 8) & 0xff));
888 j++;
894 #if ISP2x00_FABRIC
895 isp2x00_init_fabric(host, temp, j);
896 #endif
898 for (i = 0; i <= QLOGICFC_MAX_ID; i++) {
899 if (temp[i].wwn != hostdata->port_db[i].wwn) {
900 for (j = 0; j <= QLOGICFC_MAX_ID; j++) {
901 if (temp[j].wwn == hostdata->port_db[i].wwn) {
902 hostdata->port_db[i].loop_id = temp[j].loop_id;
903 break;
906 if (j == QLOGICFC_MAX_ID + 1)
907 hostdata->port_db[i].loop_id = temp[0].loop_id;
909 for (j = 0; j <= QLOGICFC_MAX_ID; j++) {
910 if (hostdata->port_db[j].wwn == temp[i].wwn || !hostdata->port_db[j].wwn) {
911 break;
914 if (j == QLOGICFC_MAX_ID + 1)
915 printk("qlogicfc%d : Too many scsi devices, no more room in port map.\n", hostdata->host_id);
916 if (!hostdata->port_db[j].wwn) {
917 hostdata->port_db[j].loop_id = temp[i].loop_id;
918 hostdata->port_db[j].wwn = temp[i].wwn;
920 } else
921 hostdata->port_db[i].loop_id = temp[i].loop_id;
925 isp2x00_enable_irqs(host);
927 return 0;
931 #if ISP2x00_FABRIC
933 #define FABRIC_PORT 0x7e
934 #define FABRIC_CONTROLLER 0x7f
935 #define FABRIC_SNS 0x80
937 int isp2x00_init_fabric(struct Scsi_Host *host, struct id_name_map *port_db, int cur_scsi_id)
940 u_short param[8];
941 u64 wwn;
942 int done = 0;
943 u_short loop_id = 0x81;
944 u_short scsi_id = cur_scsi_id;
945 u_int port_id;
946 struct sns_cb req;
947 u_char sns_response[608];
948 struct isp2x00_hostdata *hostdata;
950 hostdata = (struct isp2x00_hostdata *) host->hostdata;
952 DEBUG_FABRIC(printk("qlogicfc%d : Checking for a fabric.\n", hostdata->host_id));
953 param[0] = MBOX_GET_PORT_NAME;
954 param[1] = (u16)FABRIC_PORT << 8;
956 isp2x00_mbox_command(host, param);
958 if (param[0] != MBOX_COMMAND_COMPLETE) {
959 DEBUG_FABRIC(printk("qlogicfc%d : fabric check result %x\n", hostdata->host_id, param[0]));
960 return 0;
962 printk("qlogicfc%d : Fabric found.\n", hostdata->host_id);
964 if (hostdata->adapter_state & AS_REDO_LOOP_PORTDB){
965 memset(&req, 0, sizeof(req));
967 req.len = 8;
968 req.response_low = virt_to_bus_low32(sns_response);
969 req.response_high = virt_to_bus_high32(sns_response);
970 req.sub_len = 22;
971 req.data[0] = 0x17;
972 req.data[1] = 0x02;
973 req.data[8] = (u_char) (hostdata->port_id & 0xff);
974 req.data[9] = (u_char) (hostdata->port_id >> 8 & 0xff);
975 req.data[10] = (u_char) (hostdata->port_id >> 16 & 0xff);
976 req.data[13] = 0x01;
977 param[0] = MBOX_SEND_SNS;
978 param[1] = 30;
979 param[2] = virt_to_bus_low32(&req) >> 16;
980 param[3] = virt_to_bus_low32(&req);
981 param[6] = virt_to_bus_high32(&req) >> 16;
982 param[7] = virt_to_bus_high32(&req);
984 isp2x00_mbox_command(host, param);
986 if (param[0] != MBOX_COMMAND_COMPLETE)
987 printk("qlogicfc%d : error sending RFC-4\n", hostdata->host_id);
990 port_id = hostdata->port_id;
991 while (!done) {
992 memset(&req, 0, sizeof(req));
994 req.len = 304;
995 req.response_low = virt_to_bus_low32(sns_response);
996 req.response_high = virt_to_bus_high32(sns_response);
997 req.sub_len = 6;
998 req.data[0] = 0x00;
999 req.data[1] = 0x01;
1000 req.data[8] = (u_char) (port_id & 0xff);
1001 req.data[9] = (u_char) (port_id >> 8 & 0xff);
1002 req.data[10] = (u_char) (port_id >> 16 & 0xff);
1004 param[0] = MBOX_SEND_SNS;
1005 param[1] = 14;
1006 param[2] = virt_to_bus_low32(&req) >> 16;
1007 param[3] = virt_to_bus_low32(&req);
1008 param[6] = virt_to_bus_high32(&req) >> 16;
1009 param[7] = virt_to_bus_high32(&req);
1011 isp2x00_mbox_command(host, param);
1013 if (param[0] == MBOX_COMMAND_COMPLETE) {
1014 DEBUG_FABRIC(printk("qlogicfc%d : found node %02x%02x%02x%02x%02x%02x%02x%02x ", hostdata->host_id, sns_response[20], sns_response[21], sns_response[22], sns_response[23], sns_response[24], sns_response[25], sns_response[26], sns_response[27]));
1015 DEBUG_FABRIC(printk(" port id: %02x%02x%02x\n", sns_response[17], sns_response[18], sns_response[19]));
1016 port_id = ((u_int) sns_response[17]) << 16;
1017 port_id |= ((u_int) sns_response[18]) << 8;
1018 port_id |= ((u_int) sns_response[19]);
1019 wwn = ((u64) sns_response[20]) << 56;
1020 wwn |= ((u64) sns_response[21]) << 48;
1021 wwn |= ((u64) sns_response[22]) << 40;
1022 wwn |= ((u64) sns_response[23]) << 32;
1023 wwn |= ((u64) sns_response[24]) << 24;
1024 wwn |= ((u64) sns_response[25]) << 16;
1025 wwn |= ((u64) sns_response[26]) << 8;
1026 wwn |= ((u64) sns_response[27]);
1027 if (hostdata->port_id >> 8 != port_id >> 8) {
1028 DEBUG_FABRIC(printk("qlogicfc%d : adding a fabric port: %x\n", hostdata->host_id, port_id));
1029 param[0] = MBOX_PORT_LOGIN;
1030 param[1] = loop_id << 8;
1031 param[2] = (u_short) (port_id >> 16);
1032 param[3] = (u_short) (port_id);
1034 isp2x00_mbox_command(host, param);
1036 if (param[0] == MBOX_COMMAND_COMPLETE) {
1037 port_db[scsi_id].wwn = wwn;
1038 port_db[scsi_id].loop_id = loop_id;
1039 loop_id++;
1040 scsi_id++;
1041 } else {
1042 printk("qlogicfc%d : Error performing port login %x\n", hostdata->host_id, param[0]);
1043 DEBUG_FABRIC(printk("qlogicfc%d : loop_id: %x\n", hostdata->host_id, loop_id));
1044 param[0] = MBOX_PORT_LOGOUT;
1045 param[1] = loop_id << 8;
1046 param[2] = 0;
1047 param[3] = 0;
1049 isp2x00_mbox_command(host, param);
1054 if (hostdata->port_id == port_id)
1055 done = 1;
1056 } else {
1057 printk("qlogicfc%d : Get All Next failed %x.\n", hostdata->host_id, param[0]);
1058 return 0;
1062 return 1;
1065 #endif /* ISP2x00_FABRIC */
1068 int isp2x00_release(struct Scsi_Host *host)
1070 struct isp2x00_hostdata *hostdata;
1072 ENTER("isp2x00_release");
1074 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1076 outw(0x0, host->io_port + PCI_INTER_CTL);
1077 free_irq(host->irq, host);
1079 release_region(host->io_port, 0xff);
1081 LEAVE("isp2x00_release");
1083 return 0;
1087 const char *isp2x00_info(struct Scsi_Host *host)
1089 static char buf[80];
1090 struct isp2x00_hostdata *hostdata;
1091 ENTER("isp2x00_info");
1093 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1094 sprintf(buf,
1095 "QLogic ISP%04x SCSI on PCI bus %02x device %02x irq %d base 0x%lx",
1096 hostdata->pci_dev->device, hostdata->pci_dev->bus->number, hostdata->pci_dev->devfn, host->irq,
1097 host->io_port);
1100 LEAVE("isp2x00_info");
1102 return buf;
1107 * The middle SCSI layer ensures that queuecommand never gets invoked
1108 * concurrently with itself or the interrupt handler (though the
1109 * interrupt handler may call this routine as part of
1110 * request-completion handling).
1112 int isp2x00_queuecommand(Scsi_Cmnd * Cmnd, void (*done) (Scsi_Cmnd *))
1114 int i, sg_count, n, num_free;
1115 u_int in_ptr, out_ptr;
1116 struct dataseg *ds;
1117 struct scatterlist *sg;
1118 struct Command_Entry *cmd;
1119 struct Continuation_Entry *cont;
1120 struct Scsi_Host *host;
1121 struct isp2x00_hostdata *hostdata;
1123 ENTER("isp2x00_queuecommand");
1125 host = Cmnd->host;
1126 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1127 Cmnd->scsi_done = done;
1129 DEBUG(isp2x00_print_scsi_cmd(Cmnd));
1131 if (hostdata->adapter_state & AS_REDO_FABRIC_PORTDB || hostdata->adapter_state & AS_REDO_LOOP_PORTDB) {
1132 isp2x00_make_portdb(host);
1133 hostdata->adapter_state = AS_LOOP_GOOD;
1134 printk("qlogicfc%d : Port Database\n", hostdata->host_id);
1135 for (i = 0; hostdata->port_db[i].wwn != 0; i++) {
1136 printk("wwn: %08x%08x scsi_id: %x loop_id: %x\n", (u_int) (hostdata->port_db[i].wwn >> 32), (u_int) hostdata->port_db[i].wwn, i, hostdata->port_db[i].loop_id);
1139 if (hostdata->adapter_state == AS_FIRMWARE_DEAD) {
1140 printk("qlogicfc%d : The firmware is dead, just return.\n", hostdata->host_id);
1141 host->max_id = 0;
1142 return 0;
1145 out_ptr = inw(host->io_port + MBOX4);
1146 in_ptr = hostdata->req_in_ptr;
1148 DEBUG(printk("qlogicfc%d : request queue depth %d\n", hostdata->host_id,
1149 REQ_QUEUE_DEPTH(in_ptr, out_ptr)));
1151 cmd = (struct Command_Entry *) &hostdata->req[in_ptr][0];
1152 in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
1153 if (in_ptr == out_ptr) {
1154 DEBUG(printk("qlogicfc%d : request queue overflow\n", hostdata->host_id));
1155 return 1;
1157 if (hostdata->send_marker) {
1158 struct Marker_Entry *marker;
1160 TRACE("queue marker", in_ptr, 0);
1162 DEBUG(printk("qlogicfc%d : adding marker entry\n", hostdata->host_id));
1163 marker = (struct Marker_Entry *) cmd;
1164 memset(marker, 0, sizeof(struct Marker_Entry));
1166 marker->hdr.entry_type = ENTRY_MARKER;
1167 marker->hdr.entry_cnt = 1;
1168 marker->modifier = SYNC_ALL;
1170 hostdata->send_marker = 0;
1172 if (((in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN) == out_ptr) {
1173 outw(in_ptr, host->io_port + MBOX4);
1174 hostdata->req_in_ptr = in_ptr;
1175 DEBUG(printk("qlogicfc%d : request queue overflow\n", hostdata->host_id));
1176 return 1;
1178 cmd = (struct Command_Entry *) &hostdata->req[in_ptr][0];
1179 in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
1181 TRACE("queue command", in_ptr, Cmnd);
1183 memset(cmd, 0, sizeof(struct Command_Entry));
1185 /* find a free handle mapping slot */
1186 for (i = in_ptr; i != (in_ptr - 1) && hostdata->handle_ptrs[i]; i = ((i + 1) % (QLOGICFC_REQ_QUEUE_LEN + 1)));
1188 if (!hostdata->handle_ptrs[i]) {
1189 cmd->handle = i;
1190 hostdata->handle_ptrs[i] = Cmnd;
1191 hostdata->handle_serials[i] = Cmnd->serial_number;
1192 } else {
1193 printk("qlogicfc%d : no handle slots, this should not happen.\n", hostdata->host_id);
1194 printk("hostdata->queued is %x, in_ptr: %x\n", hostdata->queued, in_ptr);
1195 for (i = 0; i <= QLOGICFC_REQ_QUEUE_LEN; i++){
1196 if (!hostdata->handle_ptrs[i]){
1197 printk("slot %d has %p\n", i, hostdata->handle_ptrs[i]);
1202 cmd->hdr.entry_type = ENTRY_COMMAND;
1203 cmd->hdr.entry_cnt = 1;
1204 cmd->target_lun = Cmnd->lun;
1205 cmd->expanded_lun = Cmnd->lun;
1206 #if ISP2x00_PORTDB
1207 cmd->target_id = hostdata->port_db[Cmnd->target].loop_id;
1208 #else
1209 cmd->target_id = Cmnd->target;
1210 #endif
1211 cmd->total_byte_cnt = (u_int) Cmnd->request_bufflen;
1212 cmd->time_out = 0;
1213 memcpy(cmd->cdb, Cmnd->cmnd, Cmnd->cmd_len);
1215 if (Cmnd->use_sg) {
1216 cmd->segment_cnt = sg_count = Cmnd->use_sg;
1217 sg = (struct scatterlist *) Cmnd->request_buffer;
1218 ds = cmd->dataseg;
1219 /* fill in first two sg entries: */
1220 n = sg_count;
1221 if (n > DATASEGS_PER_COMMAND)
1222 n = DATASEGS_PER_COMMAND;
1224 for (i = 0; i < n; i++) {
1225 ds[i].d_base = virt_to_bus_low32(sg->address);
1226 #if BITS_PER_LONG > 32
1227 ds[i].d_base_hi = virt_to_bus_high32(sg->address);
1228 #endif
1229 ds[i].d_count = sg->length;
1230 ++sg;
1232 sg_count -= DATASEGS_PER_COMMAND;
1234 while (sg_count > 0) {
1235 ++cmd->hdr.entry_cnt;
1236 cont = (struct Continuation_Entry *)
1237 &hostdata->req[in_ptr][0];
1238 memset(cont, 0, sizeof(struct Continuation_Entry));
1239 in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
1240 if (in_ptr == out_ptr) {
1241 DEBUG(printk("qlogicfc%d : unexpected request queue overflow\n", hostdata->host_id));
1242 return 1;
1244 TRACE("queue continuation", in_ptr, 0);
1245 cont->hdr.entry_type = ENTRY_CONTINUATION;
1246 ds = cont->dataseg;
1247 n = sg_count;
1248 if (n > DATASEGS_PER_CONT)
1249 n = DATASEGS_PER_CONT;
1250 for (i = 0; i < n; ++i) {
1251 ds[i].d_base = virt_to_bus_low32(sg->address);
1252 #if BITS_PER_LONG > 32
1253 ds[i].d_base_hi = virt_to_bus_high32(sg->address);
1254 #endif
1255 ds[i].d_count = sg->length;
1256 ++sg;
1258 sg_count -= n;
1260 } else {
1261 cmd->dataseg[0].d_base = virt_to_bus_low32(Cmnd->request_buffer);
1262 #if BITS_PER_LONG > 32
1263 cmd->dataseg[0].d_base_hi = virt_to_bus_high32(Cmnd->request_buffer);
1264 #endif
1265 cmd->dataseg[0].d_count = (u_int) Cmnd->request_bufflen;
1266 cmd->segment_cnt = 1;
1269 switch (Cmnd->cmnd[0]) {
1270 case TEST_UNIT_READY:
1271 case START_STOP:
1272 break;
1273 case WRITE_10:
1274 case WRITE_6:
1275 case WRITE_BUFFER:
1276 case MODE_SELECT:
1277 cmd->control_flags = CFLAG_WRITE;
1278 break;
1279 case REQUEST_SENSE:
1280 /* scsi.c expects sense info in a different buffer */
1281 cmd->dataseg[0].d_base = virt_to_bus_low32(Cmnd->sense_buffer);
1282 #if BITS_PER_LONG > 32
1283 cmd->dataseg[0].d_base_hi = virt_to_bus_high32(Cmnd->sense_buffer);
1284 #endif
1285 cmd->dataseg[0].d_count = sizeof(Cmnd->sense_buffer);
1286 cmd->segment_cnt = 1;
1287 cmd->control_flags = CFLAG_READ;
1288 break;
1289 default:
1290 cmd->control_flags = CFLAG_READ;
1291 break;
1295 if (Cmnd->device->tagged_supported) {
1296 if ((jiffies - hostdata->tag_ages[Cmnd->target]) > (2 * SCSI_TIMEOUT)) {
1297 cmd->control_flags |= CFLAG_ORDERED_TAG;
1298 hostdata->tag_ages[Cmnd->target] = jiffies;
1299 } else
1300 switch (Cmnd->tag) {
1301 case HEAD_OF_QUEUE_TAG:
1302 cmd->control_flags |= CFLAG_HEAD_TAG;
1303 break;
1304 case ORDERED_QUEUE_TAG:
1305 cmd->control_flags |= CFLAG_ORDERED_TAG;
1306 break;
1307 default:
1308 cmd->control_flags |= CFLAG_SIMPLE_TAG;
1309 break;
1312 outw(in_ptr, host->io_port + MBOX4);
1313 hostdata->req_in_ptr = in_ptr;
1315 hostdata->queued++;
1317 num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
1318 num_free = (num_free > 2) ? num_free - 2 : 0;
1319 host->can_queue = hostdata->queued + num_free;
1320 if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)
1321 host->can_queue = QLOGICFC_REQ_QUEUE_LEN;
1322 host->sg_tablesize = QLOGICFC_MAX_SG(num_free);
1324 /* this is really gross */
1325 if (host->can_queue <= host->host_busy){
1326 if (host->can_queue+2 < host->host_busy)
1327 DEBUG(printk("qlogicfc%d.c crosses its fingers.\n", hostdata->host_id));
1328 host->can_queue = host->host_busy + 1;
1331 LEAVE("isp2x00_queuecommand");
1333 return 0;
1337 #define ASYNC_EVENT_INTERRUPT 0x01
1340 void do_isp2x00_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1342 unsigned long flags;
1344 spin_lock_irqsave(&io_request_lock, flags);
1345 isp2x00_intr_handler(irq, dev_id, regs);
1346 spin_unlock_irqrestore(&io_request_lock, flags);
1349 void isp2x00_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1351 Scsi_Cmnd *Cmnd;
1352 struct Status_Entry *sts;
1353 struct Scsi_Host *host = dev_id;
1354 struct isp2x00_hostdata *hostdata;
1355 u_int in_ptr, out_ptr, handle, num_free;
1356 u_short status;
1358 ENTER_INTR("isp2x00_intr_handler");
1360 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1362 DEBUG_INTR(printk("qlogicfc%d : interrupt on line %d\n", hostdata->host_id, irq));
1364 if (!(inw(host->io_port + PCI_INTER_STS) & 0x08)) {
1365 /* spurious interrupts can happen legally */
1366 DEBUG_INTR(printk("qlogicfc%d : got spurious interrupt\n", hostdata->host_id));
1367 return;
1369 in_ptr = inw(host->io_port + MBOX5);
1370 out_ptr = hostdata->res_out_ptr;
1372 if ((inw(host->io_port + PCI_SEMAPHORE) & ASYNC_EVENT_INTERRUPT)) {
1373 status = inw(host->io_port + MBOX0);
1375 DEBUG_INTR(printk("qlogicfc%d : mbox completion status: %x\n",
1376 hostdata->host_id, status));
1378 switch (status) {
1379 case LOOP_UP:
1380 case POINT_TO_POINT_UP:
1381 printk("qlogicfc%d : link is up\n", hostdata->host_id);
1382 hostdata->adapter_state = AS_REDO_FABRIC_PORTDB | AS_REDO_LOOP_PORTDB;
1383 break;
1384 case LOOP_DOWN:
1385 printk("qlogicfc%d : link is down\n", hostdata->host_id);
1386 hostdata->adapter_state = AS_LOOP_DOWN;
1387 break;
1388 case CONNECTION_MODE:
1389 printk("received CONNECTION_MODE irq %x\n", inw(host->io_port + MBOX1));
1390 break;
1391 case CHANGE_NOTIFICATION:
1392 if (hostdata->adapter_state == AS_LOOP_GOOD)
1393 hostdata->adapter_state = AS_REDO_FABRIC_PORTDB;
1394 break;
1395 case LIP_OCCURED:
1396 case PORT_DB_CHANGED:
1397 case LIP_RECEIVED:
1398 if (hostdata->adapter_state == AS_LOOP_GOOD)
1399 hostdata->adapter_state = AS_REDO_LOOP_PORTDB;
1400 break;
1401 case SYSTEM_ERROR:
1402 printk("qlogicfc%d : The firmware just choked.\n", hostdata->host_id);
1403 hostdata->adapter_state = AS_FIRMWARE_DEAD;
1404 break;
1405 case SCSI_COMMAND_COMPLETE:
1406 handle = inw(host->io_port + MBOX1) | (inw(host->io_port + MBOX2) << 16);
1407 Cmnd = hostdata->handle_ptrs[handle];
1408 hostdata->handle_ptrs[handle] = NULL;
1409 hostdata->handle_serials[handle] = 0;
1410 hostdata->queued--;
1411 if (Cmnd != NULL) {
1412 Cmnd->result = 0x0;
1413 (*Cmnd->scsi_done) (Cmnd);
1414 } else
1415 printk("qlogicfc%d.c : got a null value out of handle_ptrs, this sucks\n", hostdata->host_id);
1416 break;
1417 case MBOX_COMMAND_COMPLETE:
1418 case INVALID_COMMAND:
1419 case HOST_INTERFACE_ERROR:
1420 case TEST_FAILED:
1421 case COMMAND_ERROR:
1422 case COMMAND_PARAM_ERROR:
1423 case PORT_ID_USED:
1424 case LOOP_ID_USED:
1425 case ALL_IDS_USED:
1426 hostdata->mbox_done = 1;
1427 outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
1428 return;
1429 default:
1430 printk("qlogicfc%d : got an unknown status? %x\n", hostdata->host_id, status);
1432 outw(0x0, host->io_port + PCI_SEMAPHORE);
1433 } else {
1434 DEBUG_INTR(printk("qlogicfc%d : response queue update\n", hostdata->host_id));
1435 DEBUG_INTR(printk("qlogicfc%d : response queue depth %d\n", hostdata->host_id, RES_QUEUE_DEPTH(in_ptr, out_ptr)));
1437 while (out_ptr != in_ptr) {
1438 sts = (struct Status_Entry *) &hostdata->res[out_ptr][0];
1439 out_ptr = (out_ptr + 1) & RES_QUEUE_LEN;
1441 TRACE("done", out_ptr, Cmnd);
1442 DEBUG_INTR(isp2x00_print_status_entry(sts));
1443 if (sts->hdr.entry_type == ENTRY_STATUS && (Cmnd = hostdata->handle_ptrs[sts->handle])) {
1444 Cmnd->result = isp2x00_return_status(sts);
1445 hostdata->handle_ptrs[sts->handle] = NULL;
1446 hostdata->queued--;
1449 * if any of the following are true we do not
1450 * call scsi_done. if the status is CS_ABORTED
1451 * we dont have to call done because the upper
1452 * level should already know its aborted.
1454 if (hostdata->handle_serials[sts->handle] != Cmnd->serial_number
1455 || sts->completion_status == CS_ABORTED){
1456 hostdata->handle_serials[sts->handle] = 0;
1457 outw(out_ptr, host->io_port + MBOX5);
1458 continue;
1461 * if we get back an error indicating the port
1462 * is not there or if the link is down and
1463 * this is a device that used to be there
1464 * allow the command to timeout.
1465 * the device may well be back in a couple of
1466 * seconds.
1468 if ((hostdata->adapter_state == AS_LOOP_DOWN || sts->completion_status == CS_PORT_UNAVAILABLE || sts->completion_status == CS_PORT_LOGGED_OUT || sts->completion_status == CS_PORT_CONFIG_CHANGED) && hostdata->port_db[Cmnd->target].wwn){
1469 outw(out_ptr, host->io_port + MBOX5);
1470 continue;
1472 } else {
1473 outw(out_ptr, host->io_port + MBOX5);
1474 continue;
1477 if (sts->completion_status == CS_RESET_OCCURRED
1478 || (sts->status_flags & STF_BUS_RESET))
1479 hostdata->send_marker = 1;
1481 memset(Cmnd->sense_buffer, 0, sizeof(Cmnd->sense_buffer));
1482 if (sts->scsi_status & 0x0200)
1483 memcpy(Cmnd->sense_buffer, sts->req_sense_data,
1484 sizeof(Cmnd->sense_buffer));
1486 outw(out_ptr, host->io_port + MBOX5);
1488 if (Cmnd->scsi_done != NULL) {
1489 (*Cmnd->scsi_done) (Cmnd);
1490 } else
1491 printk("qlogicfc%d : Ouch, scsi done is NULL\n", hostdata->host_id);
1493 hostdata->res_out_ptr = out_ptr;
1497 out_ptr = inw(host->io_port + MBOX4);
1498 in_ptr = hostdata->req_in_ptr;
1500 num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
1501 num_free = (num_free > 2) ? num_free - 2 : 0;
1502 host->can_queue = hostdata->queued + num_free;
1503 if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)
1504 host->can_queue = QLOGICFC_REQ_QUEUE_LEN;
1505 host->sg_tablesize = QLOGICFC_MAX_SG(num_free);
1507 if (host->can_queue <= host->host_busy){
1508 if (host->can_queue+2 < host->host_busy)
1509 DEBUG(printk("qlogicfc%d : crosses its fingers.\n", hostdata->host_id));
1510 host->can_queue = host->host_busy + 1;
1513 outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
1514 LEAVE_INTR("isp2x00_intr_handler");
1518 static int isp2x00_return_status(struct Status_Entry *sts)
1520 int host_status = DID_ERROR;
1521 #if DEBUG_ISP2x00_INTR
1522 static char *reason[] =
1524 "DID_OK",
1525 "DID_NO_CONNECT",
1526 "DID_BUS_BUSY",
1527 "DID_TIME_OUT",
1528 "DID_BAD_TARGET",
1529 "DID_ABORT",
1530 "DID_PARITY",
1531 "DID_ERROR",
1532 "DID_RESET",
1533 "DID_BAD_INTR"
1535 #endif /* DEBUG_ISP2x00_INTR */
1537 ENTER("isp2x00_return_status");
1539 DEBUG(printk("qlogicfc : completion status = 0x%04x\n",
1540 sts->completion_status));
1542 switch (sts->completion_status) {
1543 case CS_COMPLETE:
1544 host_status = DID_OK;
1545 break;
1546 case CS_DMA_ERROR:
1547 host_status = DID_ERROR;
1548 break;
1549 case CS_RESET_OCCURRED:
1550 host_status = DID_RESET;
1551 break;
1552 case CS_ABORTED:
1553 host_status = DID_ABORT;
1554 break;
1555 case CS_TIMEOUT:
1556 host_status = DID_TIME_OUT;
1557 break;
1558 case CS_DATA_OVERRUN:
1559 host_status = DID_ERROR;
1560 break;
1561 case CS_DATA_UNDERRUN:
1562 host_status = DID_OK;
1563 break;
1564 case CS_PORT_UNAVAILABLE:
1565 case CS_PORT_LOGGED_OUT:
1566 case CS_PORT_CONFIG_CHANGED:
1567 host_status = DID_BAD_TARGET;
1568 break;
1569 case CS_QUEUE_FULL:
1570 host_status = DID_ERROR;
1571 break;
1572 default:
1573 printk("qlogicfc : unknown completion status 0x%04x\n",
1574 sts->completion_status);
1575 host_status = DID_ERROR;
1576 break;
1579 DEBUG_INTR(printk("qlogicfc : host status (%s) scsi status %x\n",
1580 reason[host_status], sts->scsi_status));
1582 LEAVE("isp2x00_return_status");
1584 return (sts->scsi_status & STATUS_MASK) | (host_status << 16);
1588 int isp2x00_abort(Scsi_Cmnd * Cmnd)
1590 u_short param[8];
1591 int i;
1592 struct Scsi_Host *host;
1593 struct isp2x00_hostdata *hostdata;
1594 int return_status = SUCCESS;
1596 ENTER("isp2x00_abort");
1598 host = Cmnd->host;
1599 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1601 for (i = 0; i < QLOGICFC_REQ_QUEUE_LEN; i++)
1602 if (hostdata->handle_ptrs[i] == Cmnd)
1603 break;
1605 if (i == QLOGICFC_REQ_QUEUE_LEN){
1606 return SUCCESS;
1609 isp2x00_disable_irqs(host);
1611 param[0] = MBOX_ABORT_IOCB;
1612 #if ISP2x00_PORTDB
1613 param[1] = (((u_short) hostdata->port_db[Cmnd->target].loop_id) << 8) | Cmnd->lun;
1614 #else
1615 param[1] = (((u_short) Cmnd->target) << 8) | Cmnd->lun;
1616 #endif
1617 param[2] = i & 0xffff;
1618 param[3] = i >> 16;
1620 isp2x00_mbox_command(host, param);
1622 if (param[0] != MBOX_COMMAND_COMPLETE) {
1623 printk("qlogicfc%d : scsi abort failure: %x\n", hostdata->host_id, param[0]);
1624 if (param[0] == 0x4005)
1625 Cmnd->result = DID_ERROR << 16;
1626 if (param[0] == 0x4006)
1627 Cmnd->result = DID_BAD_TARGET << 16;
1628 return_status = FAILED;
1631 if (return_status != SUCCESS){
1632 param[0] = MBOX_GET_FIRMWARE_STATE;
1633 isp2x00_mbox_command(host, param);
1634 printk("qlogicfc%d : abort failed\n", hostdata->host_id);
1635 printk("qlogicfc%d : firmware status is %x %x\n", hostdata->host_id, param[0], param[1]);
1638 isp2x00_enable_irqs(host);
1640 LEAVE("isp2x00_abort");
1642 return return_status;
1646 int isp2x00_reset(Scsi_Cmnd * Cmnd, unsigned int reset_flags)
1648 u_short param[8];
1649 struct Scsi_Host *host;
1650 struct isp2x00_hostdata *hostdata;
1651 int return_status = SCSI_RESET_SUCCESS;
1653 ENTER("isp2x00_reset");
1655 host = Cmnd->host;
1656 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1657 param[0] = MBOX_BUS_RESET;
1658 param[1] = 3;
1660 isp2x00_disable_irqs(host);
1662 isp2x00_mbox_command(host, param);
1664 if (param[0] != MBOX_COMMAND_COMPLETE) {
1665 printk("qlogicfc%d : scsi bus reset failure: %x\n", hostdata->host_id, param[0]);
1666 return_status = SCSI_RESET_ERROR;
1668 isp2x00_enable_irqs(host);
1670 LEAVE("isp2x00_reset");
1672 return return_status;;
1676 int isp2x00_biosparam(Disk * disk, kdev_t n, int ip[])
1678 int size = disk->capacity;
1680 ENTER("isp2x00_biosparam");
1682 ip[0] = 64;
1683 ip[1] = 32;
1684 ip[2] = size >> 11;
1685 if (ip[2] > 1024) {
1686 ip[0] = 255;
1687 ip[1] = 63;
1688 ip[2] = size / (ip[0] * ip[1]);
1690 LEAVE("isp2x00_biosparam");
1692 return 0;
1696 static int isp2x00_reset_hardware(struct Scsi_Host *host)
1698 u_short param[8];
1699 struct isp2x00_hostdata *hostdata;
1700 int loop_count;
1702 ENTER("isp2x00_reset_hardware");
1704 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1706 outw(0x01, host->io_port + ISP_CTRL_STATUS);
1707 outw(HCCR_RESET, host->io_port + HOST_HCCR);
1708 outw(HCCR_RELEASE, host->io_port + HOST_HCCR);
1709 outw(HCCR_BIOS_DISABLE, host->io_port + HOST_HCCR);
1711 loop_count = DEFAULT_LOOP_COUNT;
1712 while (--loop_count && inw(host->io_port + HOST_HCCR) == RISC_BUSY)
1713 barrier();
1714 if (!loop_count)
1715 printk("qlogicfc%d : reset_hardware loop timeout\n", hostdata->host_id);
1719 #if DEBUG_ISP2x00
1720 printk("qlogicfc%d : mbox 0 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX0));
1721 printk("qlogicfc%d : mbox 1 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX1));
1722 printk("qlogicfc%d : mbox 2 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX2));
1723 printk("qlogicfc%d : mbox 3 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX3));
1724 printk("qlogicfc%d : mbox 4 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX4));
1725 printk("qlogicfc%d : mbox 5 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX5));
1726 printk("qlogicfc%d : mbox 6 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX6));
1727 printk("qlogicfc%d : mbox 7 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX7));
1728 #endif /* DEBUG_ISP2x00 */
1730 DEBUG(printk("qlogicfc%d : verifying checksum\n", hostdata->host_id));
1732 #if RELOAD_FIRMWARE
1734 int i;
1735 unsigned short * risc_code = NULL;
1736 unsigned short risc_code_len = 0;
1737 if (hostdata->pci_dev->device == PCI_DEVICE_ID_QLOGIC_ISP2100){
1738 risc_code = risc_code2100;
1739 risc_code_len = risc_code_length2100;
1741 else if (hostdata->pci_dev->device == PCI_DEVICE_ID_QLOGIC_ISP2200){
1742 risc_code = risc_code2200;
1743 risc_code_len = risc_code_length2200;
1746 for (i = 0; i < risc_code_len; i++) {
1747 param[0] = MBOX_WRITE_RAM_WORD;
1748 param[1] = risc_code_addr01 + i;
1749 param[2] = risc_code[i];
1751 isp2x00_mbox_command(host, param);
1753 if (param[0] != MBOX_COMMAND_COMPLETE) {
1754 printk("qlogicfc%d : firmware load failure\n", hostdata->host_id);
1755 return 1;
1759 #endif /* RELOAD_FIRMWARE */
1761 param[0] = MBOX_VERIFY_CHECKSUM;
1762 param[1] = risc_code_addr01;
1764 isp2x00_mbox_command(host, param);
1766 if (param[0] != MBOX_COMMAND_COMPLETE) {
1767 printk("qlogicfc%d : ram checksum failure\n", hostdata->host_id);
1768 return 1;
1770 DEBUG(printk("qlogicfc%d : executing firmware\n", hostdata->host_id));
1772 param[0] = MBOX_EXEC_FIRMWARE;
1773 param[1] = risc_code_addr01;
1775 isp2x00_mbox_command(host, param);
1777 param[0] = MBOX_ABOUT_FIRMWARE;
1779 isp2x00_mbox_command(host, param);
1781 if (param[0] != MBOX_COMMAND_COMPLETE) {
1782 printk("qlogicfc%d : about firmware failure\n", hostdata->host_id);
1783 return 1;
1785 DEBUG(printk("qlogicfc%d : firmware major revision %d\n", hostdata->host_id, param[1]));
1786 DEBUG(printk("qlogicfc%d : firmware minor revision %d\n", hostdata->host_id, param[2]));
1788 #ifdef USE_NVRAM_DEFAULTS
1790 if (isp2x00_get_nvram_defaults(host, &hostdata->control_block) != 0) {
1791 printk("qlogicfc%d : Could not read from NVRAM\n", hostdata->host_id);
1793 #endif
1795 hostdata->wwn = (u64) (hostdata->control_block.node_name[0]) << 56;
1796 hostdata->wwn |= (u64) (hostdata->control_block.node_name[0] & 0xff00) << 48;
1797 hostdata->wwn |= (u64) (hostdata->control_block.node_name[1] & 0xff00) << 24;
1798 hostdata->wwn |= (u64) (hostdata->control_block.node_name[1] & 0x00ff) << 48;
1799 hostdata->wwn |= (u64) (hostdata->control_block.node_name[2] & 0x00ff) << 24;
1800 hostdata->wwn |= (u64) (hostdata->control_block.node_name[2] & 0xff00) << 8;
1801 hostdata->wwn |= (u64) (hostdata->control_block.node_name[3] & 0x00ff) << 8;
1802 hostdata->wwn |= (u64) (hostdata->control_block.node_name[3] & 0xff00) >> 8;
1804 param[0] = MBOX_INIT_FIRMWARE;
1805 param[2] = (u_short) (virt_to_bus_low32(&hostdata->control_block) >> 16);
1806 param[3] = (u_short) (virt_to_bus_low32(&hostdata->control_block) & 0xffff);
1807 param[4] = 0;
1808 param[5] = 0;
1809 param[6] = (u_short) (virt_to_bus_high32(&hostdata->control_block) >> 16);
1810 param[7] = (u_short) (virt_to_bus_high32(&hostdata->control_block) & 0xffff);
1811 isp2x00_mbox_command(host, param);
1812 if (param[0] != MBOX_COMMAND_COMPLETE) {
1813 printk("qlogicfc%d.c: Ouch 0x%04x\n", hostdata->host_id, param[0]);
1814 return 1;
1816 param[0] = MBOX_GET_FIRMWARE_STATE;
1817 isp2x00_mbox_command(host, param);
1818 if (param[0] != MBOX_COMMAND_COMPLETE) {
1819 printk("qlogicfc%d.c: 0x%04x\n", hostdata->host_id, param[0]);
1820 return 1;
1823 LEAVE("isp2x00_reset_hardware");
1825 return 0;
1828 #ifdef USE_NVRAM_DEFAULTS
1830 static int isp2x00_get_nvram_defaults(struct Scsi_Host *host, struct init_cb *control_block)
1833 u_short value;
1834 if (isp2x00_read_nvram_word(host, 0) != 0x5349)
1835 return 1;
1837 value = isp2x00_read_nvram_word(host, 8);
1838 control_block->node_name[0] = isp2x00_read_nvram_word(host, 9);
1839 control_block->node_name[1] = isp2x00_read_nvram_word(host, 10);
1840 control_block->node_name[2] = isp2x00_read_nvram_word(host, 11);
1841 control_block->node_name[3] = isp2x00_read_nvram_word(host, 12);
1842 control_block->hard_addr = isp2x00_read_nvram_word(host, 13);
1844 return 0;
1848 #endif
1850 static int isp2x00_init(struct Scsi_Host *sh)
1852 u_long io_base;
1853 struct isp2x00_hostdata *hostdata;
1854 u_char revision;
1855 u_int irq;
1856 u_short command;
1857 struct pci_dev *pdev;
1860 ENTER("isp2x00_init");
1862 hostdata = (struct isp2x00_hostdata *) sh->hostdata;
1863 pdev = hostdata->pci_dev;
1865 if (pci_read_config_word(pdev, PCI_COMMAND, &command)
1866 || pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision)) {
1867 printk("qlogicfc%d : error reading PCI configuration\n", hostdata->host_id);
1868 return 1;
1870 io_base = pdev->resource[0].start;
1871 irq = pdev->irq;
1874 if (pdev->vendor != PCI_VENDOR_ID_QLOGIC) {
1875 printk("qlogicfc%d : 0x%04x is not QLogic vendor ID\n", hostdata->host_id,
1876 pdev->vendor);
1877 return 1;
1879 if (pdev->device != PCI_DEVICE_ID_QLOGIC_ISP2100 && pdev->device != PCI_DEVICE_ID_QLOGIC_ISP2200) {
1880 printk("qlogicfc%d : 0x%04x does not match ISP2100 or ISP2200 device id\n", hostdata->host_id,
1881 pdev->device);
1882 return 1;
1884 if (!(command & PCI_COMMAND_IO) ||
1885 !(pdev->resource[0].flags & IORESOURCE_IO)) {
1886 printk("qlogicfc%d : i/o mapping is disabled\n", hostdata->host_id);
1887 return 1;
1890 if (!(command & PCI_COMMAND_MASTER)) {
1891 printk("qlogicfc%d : bus mastering is disabled\n", hostdata->host_id);
1892 return 1;
1894 if (revision != ISP2100_REV_ID1 && revision != ISP2100_REV_ID3 && revision != ISP2200_REV_ID5)
1895 printk("qlogicfc%d : new isp2x00 revision ID (%d)\n", hostdata->host_id, revision);
1898 hostdata->revision = revision;
1900 sh->irq = irq;
1901 sh->io_port = io_base;
1903 LEAVE("isp2x00_init");
1905 return 0;
1908 #if USE_NVRAM_DEFAULTS
1910 #define NVRAM_DELAY() udelay(10) /* 10 microsecond delay */
1913 u_short isp2x00_read_nvram_word(struct Scsi_Host * host, u_short byte)
1915 int i;
1916 u_short value, output, input;
1918 outw(0x2, host->io_port + PCI_NVRAM);
1919 NVRAM_DELAY();
1920 outw(0x3, host->io_port + PCI_NVRAM);
1921 NVRAM_DELAY();
1923 byte &= 0xff;
1924 byte |= 0x0600;
1925 for (i = 10; i >= 0; i--) {
1926 output = ((byte >> i) & 0x1) ? 0x4 : 0x0;
1927 outw(output | 0x2, host->io_port + PCI_NVRAM);
1928 NVRAM_DELAY();
1929 outw(output | 0x3, host->io_port + PCI_NVRAM);
1930 NVRAM_DELAY();
1931 outw(output | 0x2, host->io_port + PCI_NVRAM);
1932 NVRAM_DELAY();
1935 for (i = 0xf, value = 0; i >= 0; i--) {
1936 value <<= 1;
1937 outw(0x3, host->io_port + PCI_NVRAM);
1938 NVRAM_DELAY();
1939 input = inw(host->io_port + PCI_NVRAM);
1940 NVRAM_DELAY();
1941 outw(0x2, host->io_port + PCI_NVRAM);
1942 NVRAM_DELAY();
1943 if (input & 0x8)
1944 value |= 1;
1947 outw(0x0, host->io_port + PCI_NVRAM);
1948 NVRAM_DELAY();
1950 return value;
1954 #endif /* USE_NVRAM_DEFAULTS */
1959 * currently, this is only called during initialization or abort/reset,
1960 * at which times interrupts are disabled, so polling is OK, I guess...
1962 static int isp2x00_mbox_command(struct Scsi_Host *host, u_short param[])
1964 int loop_count;
1965 struct isp2x00_hostdata *hostdata = (struct isp2x00_hostdata *) host->hostdata;
1967 if (mbox_param[param[0]] == 0 || hostdata->adapter_state == AS_FIRMWARE_DEAD)
1968 return 1;
1970 loop_count = DEFAULT_LOOP_COUNT;
1971 while (--loop_count && inw(host->io_port + HOST_HCCR) & 0x0080)
1972 barrier();
1973 if (!loop_count) {
1974 printk("qlogicfc%d : mbox_command loop timeout #1\n", hostdata->host_id);
1975 param[0] = 0x4006;
1976 hostdata->adapter_state = AS_FIRMWARE_DEAD;
1977 return 1;
1979 hostdata->mbox_done = 0;
1981 if (mbox_param[param[0]] == 0)
1982 printk("qlogicfc%d : invalid mbox command\n", hostdata->host_id);
1984 if (mbox_param[param[0]] & 0x80)
1985 outw(param[7], host->io_port + MBOX7);
1986 if (mbox_param[param[0]] & 0x40)
1987 outw(param[6], host->io_port + MBOX6);
1988 if (mbox_param[param[0]] & 0x20)
1989 outw(param[5], host->io_port + MBOX5);
1990 if (mbox_param[param[0]] & 0x10)
1991 outw(param[4], host->io_port + MBOX4);
1992 if (mbox_param[param[0]] & 0x08)
1993 outw(param[3], host->io_port + MBOX3);
1994 if (mbox_param[param[0]] & 0x04)
1995 outw(param[2], host->io_port + MBOX2);
1996 if (mbox_param[param[0]] & 0x02)
1997 outw(param[1], host->io_port + MBOX1);
1998 if (mbox_param[param[0]] & 0x01)
1999 outw(param[0], host->io_port + MBOX0);
2002 outw(HCCR_SET_HOST_INTR, host->io_port + HOST_HCCR);
2004 while (1) {
2005 loop_count = DEFAULT_LOOP_COUNT;
2006 while (--loop_count && !(inw(host->io_port + PCI_INTER_STS) & 0x08)) {
2007 barrier();
2010 if (!loop_count) {
2011 hostdata->adapter_state = AS_FIRMWARE_DEAD;
2012 printk("qlogicfc%d : mbox_command loop timeout #2\n", hostdata->host_id);
2013 break;
2015 isp2x00_intr_handler(host->irq, host, NULL);
2017 if (hostdata->mbox_done == 1)
2018 break;
2022 loop_count = DEFAULT_LOOP_COUNT;
2023 while (--loop_count && inw(host->io_port + MBOX0) == 0x04) {
2024 barrier();
2026 if (!loop_count)
2027 printk("qlogicfc%d : mbox_command loop timeout #3\n", hostdata->host_id);
2029 param[7] = inw(host->io_port + MBOX7);
2030 param[6] = inw(host->io_port + MBOX6);
2031 param[5] = inw(host->io_port + MBOX5);
2032 param[4] = inw(host->io_port + MBOX4);
2033 param[3] = inw(host->io_port + MBOX3);
2034 param[2] = inw(host->io_port + MBOX2);
2035 param[1] = inw(host->io_port + MBOX1);
2036 param[0] = inw(host->io_port + MBOX0);
2039 outw(0x0, host->io_port + PCI_SEMAPHORE);
2041 if (inw(host->io_port + HOST_HCCR) & 0x0080) {
2042 hostdata->adapter_state = AS_FIRMWARE_DEAD;
2043 printk("qlogicfc%d : mbox op is still pending\n", hostdata->host_id);
2045 return 0;
2048 #if DEBUG_ISP2x00_INTR
2050 void isp2x00_print_status_entry(struct Status_Entry *status)
2052 printk("qlogicfc : entry count = 0x%02x, type = 0x%02x, flags = 0x%02x\n",
2053 status->hdr.entry_cnt, status->hdr.entry_type, status->hdr.flags);
2054 printk("qlogicfc : scsi status = 0x%04x, completion status = 0x%04x\n",
2055 status->scsi_status, status->completion_status);
2056 printk("qlogicfc : state flags = 0x%04x, status flags = 0x%04x\n",
2057 status->state_flags, status->status_flags);
2058 printk("qlogicfc : response info length = 0x%04x, request sense length = 0x%04x\n",
2059 status->res_info_len, status->req_sense_len);
2060 printk("qlogicfc : residual transfer length = 0x%08x, response = 0x%02x\n", status->residual, status->res_info[3]);
2064 #endif /* DEBUG_ISP2x00_INTR */
2067 #if DEBUG_ISP2x00
2069 void isp2x00_print_scsi_cmd(Scsi_Cmnd * cmd)
2071 int i;
2073 printk("qlogicfc : target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
2074 cmd->target, cmd->lun, cmd->cmd_len);
2075 printk("qlogicfc : command = ");
2076 for (i = 0; i < cmd->cmd_len; i++)
2077 printk("0x%02x ", cmd->cmnd[i]);
2078 printk("\n");
2081 #endif /* DEBUG_ISP2x00 */
2084 #ifdef MODULE
2086 Scsi_Host_Template driver_template = QLOGICFC;
2088 #include "scsi_module.c"
2090 #endif