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
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 $
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
40 * added queue protocol.
42 * Revision 0.1 1995/06/25 01:55:45 root
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>
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
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>
102 #define TRACE_BUF_LEN (32*1024)
111 } buf
[TRACE_BUF_LEN
];
114 #define TRACE(w, i, a) \
116 unsigned long flags; \
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); \
129 #define TRACE(w, i, a)
132 #if DEBUG_ISP2x00_FABRIC
133 #define DEBUG_FABRIC(x) x
135 #define DEBUG_FABRIC(x)
136 #endif /* DEBUG_ISP2x00_FABRIC */
140 #define ENTER(x) printk("isp2x00 : entering %s()\n", x);
141 #define LEAVE(x) printk("isp2x00 : leaving %s()\n", 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
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)))
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
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
{
232 /* entry header type commands */
233 #if BITS_PER_LONG > 32
234 #define ENTRY_COMMAND 0x19
235 #define ENTRY_CONTINUATION 0x0a
237 #define ENTRY_COMMAND 0x11
238 #define ENTRY_CONTINUATION 0x02
241 #define ENTRY_STATUS 0x03
242 #define ENTRY_MARKER 0x04
245 /* entry header flag definitions */
247 #define EFLAG_BAD_HEADER 4
248 #define EFLAG_BAD_PAYLOAD 8
250 #if BITS_PER_LONG > 32
257 struct Command_Entry
{
258 struct Entry_header hdr
;
262 u_short expanded_lun
;
263 u_short control_flags
;
268 u_int total_byte_cnt
;
269 struct dataseg dataseg
[DATASEGS_PER_COMMAND
];
278 struct Command_Entry
{
279 struct Entry_header hdr
;
283 u_short expanded_lun
;
284 u_short control_flags
;
289 u_int total_byte_cnt
;
290 struct dataseg dataseg
[DATASEGS_PER_COMMAND
];
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
];
311 struct Continuation_Entry
{
312 struct Entry_header hdr
;
314 struct dataseg dataseg
[DATASEGS_PER_CONT
];
318 struct Marker_Entry
{
319 struct Entry_header hdr
;
328 /* marker entry modifier definitions */
329 #define SYNC_DEVICE 0
330 #define SYNC_TARGET 1
333 struct Status_Entry
{
334 struct Entry_header hdr
;
337 u_short completion_status
;
339 u_short status_flags
;
340 u_short res_info_len
;
341 u_short req_sense_len
;
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
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 */
464 0x01, /* MBOX_CHECK_FIRMWARE */
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 */
481 0x01, /* MBOX_GET_FIRMWARE_STATUS */
482 0x01, /* MBOX_GET_INIT_SCSI_ID */
484 0x01, /* MBOX_GET_RETRY_COUNT */
490 0x03, /* MBOX_GET_TARGET_PARAMS */
491 0x03, /* MBOX_GET_DEV_QUEUE_PARAMS */
500 0x07, /* MBOX_SET_RETRY_COUNT */
506 0x0f, /* MBOX_SET_TARGET_PARAMS */
507 0x0f, /* MBOX_SET_DEV_QUEUE_PARAMS */
534 0xcf, /* MBOX_EXECUTE_IOCB64 */
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 */
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))
584 /* address of instance of this struct is passed to adapter to initialize things
590 u_short max_frame_len
;
592 u_short exec_throttle
;
595 u_short node_name
[4];
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 */
608 u_char cmd_resource_cnt
;
609 u_char notify_resource_cnt
;
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
627 #define QLOGICFC_MAX_ID 0xff
629 #define QLOGICFC_MAX_ID 0x7d
632 #define QLOGICFC_MAX_LOOP_ID 0x7d
634 /* adapter_state values */
635 #define AS_FIRMWARE_DEAD -1
636 #define AS_LOOP_DOWN 0
637 #define AS_LOOP_GOOD 1
638 #define AS_REDO_FABRIC_PORTDB 2
639 #define AS_REDO_LOOP_PORTDB 4
641 struct isp2x00_hostdata
{
643 struct pci_dev
*pci_dev
;
644 /* result and request queues (shared with isp2x00): */
645 u_int req_in_ptr
; /* index of next request slot */
646 u_int res_out_ptr
; /* index of next result slot */
648 /* this is here so the queues are nicely aligned */
649 long send_marker
; /* do we need to send a marker? */
651 char res
[RES_QUEUE_LEN
+ 1][QUEUE_ENTRY_LEN
];
652 char req
[QLOGICFC_REQ_QUEUE_LEN
+ 1][QUEUE_ENTRY_LEN
];
653 struct init_cb control_block
;
655 unsigned long int tag_ages
[126];
656 Scsi_Cmnd
*handle_ptrs
[QLOGICFC_REQ_QUEUE_LEN
+ 1];
657 unsigned long handle_serials
[QLOGICFC_REQ_QUEUE_LEN
+ 1];
658 struct id_name_map port_db
[QLOGICFC_MAX_ID
+ 1];
667 /* queue length's _must_ be power of two: */
668 #define QUEUE_DEPTH(in, out, ql) ((in - out) & (ql))
669 #define REQ_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, \
670 QLOGICFC_REQ_QUEUE_LEN)
671 #define RES_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, RES_QUEUE_LEN)
673 static void isp2x00_enable_irqs(struct Scsi_Host
*);
674 static void isp2x00_disable_irqs(struct Scsi_Host
*);
675 static int isp2x00_init(struct Scsi_Host
*);
676 static int isp2x00_reset_hardware(struct Scsi_Host
*);
677 static int isp2x00_mbox_command(struct Scsi_Host
*, u_short
[]);
678 static int isp2x00_return_status(struct Status_Entry
*);
679 static void isp2x00_intr_handler(int, void *, struct pt_regs
*);
680 static void do_isp2x00_intr_handler(int, void *, struct pt_regs
*);
681 static int isp2x00_make_portdb(struct Scsi_Host
*);
684 static int isp2x00_init_fabric(struct Scsi_Host
*, struct id_name_map
*, int);
687 #if USE_NVRAM_DEFAULTS
688 static int isp2x00_get_nvram_defaults(struct Scsi_Host
*, struct init_cb
*);
689 static u_short
isp2x00_read_nvram_word(struct Scsi_Host
*, u_short
);
693 static void isp2x00_print_scsi_cmd(Scsi_Cmnd
*);
696 #if DEBUG_ISP2x00_INTR
697 static void isp2x00_print_status_entry(struct Status_Entry
*);
700 static struct proc_dir_entry proc_scsi_isp2x00
=
702 PROC_SCSI_QLOGICFC
, 7, "isp2x00",
703 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
707 static inline void isp2x00_enable_irqs(struct Scsi_Host
*host
)
709 outw(ISP_EN_INT
| ISP_EN_RISC
, host
->io_port
+ PCI_INTER_CTL
);
713 static inline void isp2x00_disable_irqs(struct Scsi_Host
*host
)
715 outw(0x0, host
->io_port
+ PCI_INTER_CTL
);
719 int isp2x00_detect(Scsi_Host_Template
* tmpt
)
723 struct Scsi_Host
*host
= NULL
;
724 struct isp2x00_hostdata
*hostdata
;
725 struct pci_dev
*pdev
= NULL
;
726 unsigned short device_ids
[2];
730 ENTER("isp2x00_detect");
732 device_ids
[0] = PCI_DEVICE_ID_QLOGIC_ISP2100
;
733 device_ids
[1] = PCI_DEVICE_ID_QLOGIC_ISP2200
;
735 tmpt
->proc_dir
= &proc_scsi_isp2x00
;
737 if (pci_present() == 0) {
738 printk("qlogicfc : PCI not present\n");
743 while ((pdev
= pci_find_device(PCI_VENDOR_ID_QLOGIC
, device_ids
[i
], pdev
))) {
745 host
= scsi_register(tmpt
, sizeof(struct isp2x00_hostdata
));
746 host
->max_id
= QLOGICFC_MAX_ID
+ 1;
747 host
->hostt
->use_new_eh_code
= 1;
748 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
750 memset(hostdata
, 0, sizeof(struct isp2x00_hostdata
));
751 hostdata
->pci_dev
= pdev
;
753 hostdata
->queued
= 0;
754 /* set up the control block */
755 hostdata
->control_block
.version
= 0x1;
756 hostdata
->control_block
.firm_opts
= 0x0108;
757 hostdata
->control_block
.max_frame_len
= 2048;
758 hostdata
->control_block
.max_iocb
= 256;
759 hostdata
->control_block
.exec_throttle
= 8;
760 hostdata
->control_block
.retry_delay
= 5;
761 hostdata
->control_block
.retry_cnt
= 1;
762 hostdata
->control_block
.node_name
[0] = 0x0020;
763 hostdata
->control_block
.node_name
[1] = 0xE000;
764 hostdata
->control_block
.node_name
[2] = 0x008B;
765 hostdata
->control_block
.node_name
[3] = 0x0000;
766 hostdata
->control_block
.hard_addr
= 0x0003;
767 hostdata
->control_block
.req_queue_len
= QLOGICFC_REQ_QUEUE_LEN
+ 1;
768 hostdata
->control_block
.res_queue_len
= RES_QUEUE_LEN
+ 1;
769 hostdata
->control_block
.res_queue_addr_lo
= virt_to_bus_low32(&hostdata
->res
);
770 hostdata
->control_block
.res_queue_addr_high
= virt_to_bus_high32(&hostdata
->res
);
771 hostdata
->control_block
.req_queue_addr_lo
= virt_to_bus_low32(&hostdata
->req
);
772 hostdata
->control_block
.req_queue_addr_high
= virt_to_bus_high32(&hostdata
->req
);
775 hostdata
->adapter_state
= AS_LOOP_DOWN
;
776 hostdata
->host_id
= hosts
;
778 if (isp2x00_init(host
) || isp2x00_reset_hardware(host
)) {
779 scsi_unregister(host
);
784 if (request_irq(host
->irq
, do_isp2x00_intr_handler
, SA_INTERRUPT
| SA_SHIRQ
, "qlogicfc", host
)) {
785 printk("qlogicfc%d : interrupt %d already in use\n",
786 hostdata
->host_id
, host
->irq
);
787 scsi_unregister(host
);
790 if (check_region(host
->io_port
, 0xff)) {
791 printk("qlogicfc%d : i/o region 0x%lx-0x%lx already "
793 hostdata
->host_id
, host
->io_port
, host
->io_port
+ 0xff);
794 free_irq(host
->irq
, host
);
795 scsi_unregister(host
);
798 request_region(host
->io_port
, 0xff, "qlogicfc");
800 outw(0x0, host
->io_port
+ PCI_SEMAPHORE
);
801 outw(HCCR_CLEAR_RISC_INTR
, host
->io_port
+ HOST_HCCR
);
802 isp2x00_enable_irqs(host
);
803 /* wait for the loop to come up */
804 for (wait_time
= jiffies
+ 10 * HZ
; wait_time
> jiffies
&& hostdata
->adapter_state
== AS_LOOP_DOWN
;)
807 if (hostdata
->adapter_state
== AS_LOOP_DOWN
) {
808 printk("qlogicfc%d : link is not up\n", hostdata
->host_id
);
815 /* this busy loop should not be needed but the isp2x00 seems to need
816 some time before recognizing it is attached to a fabric */
819 for (wait_time
= jiffies
+ 5 * HZ
; wait_time
> jiffies
;)
823 LEAVE("isp2x00_detect");
829 static int isp2x00_make_portdb(struct Scsi_Host
*host
)
834 struct id_name_map temp
[QLOGICFC_MAX_ID
+ 1];
835 struct isp2x00_hostdata
*hostdata
;
837 isp2x00_disable_irqs(host
);
839 memset(temp
, 0, sizeof(temp
));
840 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
843 for (i
= 0x81; i
< QLOGICFC_MAX_ID
; i
++) {
844 param
[0] = MBOX_PORT_LOGOUT
;
849 isp2x00_mbox_command(host
, param
);
851 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
853 DEBUG_FABRIC(printk("qlogicfc%d : logout failed %x %x\n", hostdata
->host_id
, i
, param
[0]));
859 param
[0] = MBOX_GET_INIT_SCSI_ID
;
861 isp2x00_mbox_command(host
, param
);
863 if (param
[0] == MBOX_COMMAND_COMPLETE
) {
864 hostdata
->port_id
= ((u_int
) param
[3]) << 16;
865 hostdata
->port_id
|= param
[2];
866 temp
[0].loop_id
= param
[1];
867 temp
[0].wwn
= hostdata
->wwn
;
870 printk("qlogicfc%d : error getting scsi id.\n", hostdata
->host_id
);
873 for (i
= 0; i
<=QLOGICFC_MAX_ID
; i
++)
874 temp
[i
].loop_id
= temp
[0].loop_id
;
876 for (i
= 0, j
= 1; i
<= QLOGICFC_MAX_LOOP_ID
; i
++) {
877 param
[0] = MBOX_GET_PORT_NAME
;
878 param
[1] = (i
<< 8) & 0xff00;
880 isp2x00_mbox_command(host
, param
);
882 if (param
[0] == MBOX_COMMAND_COMPLETE
) {
884 temp
[j
].wwn
= ((u64
) (param
[2] & 0xff)) << 56;
885 temp
[j
].wwn
|= ((u64
) ((param
[2] >> 8) & 0xff)) << 48;
886 temp
[j
].wwn
|= ((u64
) (param
[3] & 0xff)) << 40;
887 temp
[j
].wwn
|= ((u64
) ((param
[3] >> 8) & 0xff)) << 32;
888 temp
[j
].wwn
|= ((u64
) (param
[6] & 0xff)) << 24;
889 temp
[j
].wwn
|= ((u64
) ((param
[6] >> 8) & 0xff)) << 16;
890 temp
[j
].wwn
|= ((u64
) (param
[7] & 0xff)) << 8;
891 temp
[j
].wwn
|= ((u64
) ((param
[7] >> 8) & 0xff));
900 isp2x00_init_fabric(host
, temp
, j
);
903 for (i
= 0; i
<= QLOGICFC_MAX_ID
; i
++) {
904 if (temp
[i
].wwn
!= hostdata
->port_db
[i
].wwn
) {
905 for (j
= 0; j
<= QLOGICFC_MAX_ID
; j
++) {
906 if (temp
[j
].wwn
== hostdata
->port_db
[i
].wwn
) {
907 hostdata
->port_db
[i
].loop_id
= temp
[j
].loop_id
;
911 if (j
== QLOGICFC_MAX_ID
+ 1)
912 hostdata
->port_db
[i
].loop_id
= temp
[0].loop_id
;
914 for (j
= 0; j
<= QLOGICFC_MAX_ID
; j
++) {
915 if (hostdata
->port_db
[j
].wwn
== temp
[i
].wwn
|| !hostdata
->port_db
[j
].wwn
) {
919 if (j
== QLOGICFC_MAX_ID
+ 1)
920 printk("qlogicfc%d : Too many scsi devices, no more room in port map.\n", hostdata
->host_id
);
921 if (!hostdata
->port_db
[j
].wwn
) {
922 hostdata
->port_db
[j
].loop_id
= temp
[i
].loop_id
;
923 hostdata
->port_db
[j
].wwn
= temp
[i
].wwn
;
926 hostdata
->port_db
[i
].loop_id
= temp
[i
].loop_id
;
930 isp2x00_enable_irqs(host
);
938 #define FABRIC_PORT 0x7e
939 #define FABRIC_CONTROLLER 0x7f
940 #define FABRIC_SNS 0x80
942 int isp2x00_init_fabric(struct Scsi_Host
*host
, struct id_name_map
*port_db
, int cur_scsi_id
)
948 u_short loop_id
= 0x81;
949 u_short scsi_id
= cur_scsi_id
;
952 u_char sns_response
[608];
953 struct isp2x00_hostdata
*hostdata
;
955 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
957 DEBUG_FABRIC(printk("qlogicfc%d : Checking for a fabric.\n", hostdata
->host_id
));
958 param
[0] = MBOX_GET_PORT_NAME
;
959 param
[1] = (u16
)FABRIC_PORT
<< 8;
961 isp2x00_mbox_command(host
, param
);
963 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
964 DEBUG_FABRIC(printk("qlogicfc%d : fabric check result %x\n", hostdata
->host_id
, param
[0]));
967 printk("qlogicfc%d : Fabric found.\n", hostdata
->host_id
);
969 if (hostdata
->adapter_state
& AS_REDO_LOOP_PORTDB
){
970 memset(&req
, 0, sizeof(req
));
973 req
.response_low
= virt_to_bus_low32(sns_response
);
974 req
.response_high
= virt_to_bus_high32(sns_response
);
978 req
.data
[8] = (u_char
) (hostdata
->port_id
& 0xff);
979 req
.data
[9] = (u_char
) (hostdata
->port_id
>> 8 & 0xff);
980 req
.data
[10] = (u_char
) (hostdata
->port_id
>> 16 & 0xff);
982 param
[0] = MBOX_SEND_SNS
;
984 param
[2] = virt_to_bus_low32(&req
) >> 16;
985 param
[3] = virt_to_bus_low32(&req
);
986 param
[6] = virt_to_bus_high32(&req
) >> 16;
987 param
[7] = virt_to_bus_high32(&req
);
989 isp2x00_mbox_command(host
, param
);
991 if (param
[0] != MBOX_COMMAND_COMPLETE
)
992 printk("qlogicfc%d : error sending RFC-4\n", hostdata
->host_id
);
995 port_id
= hostdata
->port_id
;
997 memset(&req
, 0, sizeof(req
));
1000 req
.response_low
= virt_to_bus_low32(sns_response
);
1001 req
.response_high
= virt_to_bus_high32(sns_response
);
1005 req
.data
[8] = (u_char
) (port_id
& 0xff);
1006 req
.data
[9] = (u_char
) (port_id
>> 8 & 0xff);
1007 req
.data
[10] = (u_char
) (port_id
>> 16 & 0xff);
1009 param
[0] = MBOX_SEND_SNS
;
1011 param
[2] = virt_to_bus_low32(&req
) >> 16;
1012 param
[3] = virt_to_bus_low32(&req
);
1013 param
[6] = virt_to_bus_high32(&req
) >> 16;
1014 param
[7] = virt_to_bus_high32(&req
);
1016 isp2x00_mbox_command(host
, param
);
1018 if (param
[0] == MBOX_COMMAND_COMPLETE
) {
1019 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]));
1020 DEBUG_FABRIC(printk(" port id: %02x%02x%02x\n", sns_response
[17], sns_response
[18], sns_response
[19]));
1021 port_id
= ((u_int
) sns_response
[17]) << 16;
1022 port_id
|= ((u_int
) sns_response
[18]) << 8;
1023 port_id
|= ((u_int
) sns_response
[19]);
1024 wwn
= ((u64
) sns_response
[20]) << 56;
1025 wwn
|= ((u64
) sns_response
[21]) << 48;
1026 wwn
|= ((u64
) sns_response
[22]) << 40;
1027 wwn
|= ((u64
) sns_response
[23]) << 32;
1028 wwn
|= ((u64
) sns_response
[24]) << 24;
1029 wwn
|= ((u64
) sns_response
[25]) << 16;
1030 wwn
|= ((u64
) sns_response
[26]) << 8;
1031 wwn
|= ((u64
) sns_response
[27]);
1032 if (hostdata
->port_id
>> 8 != port_id
>> 8) {
1033 DEBUG_FABRIC(printk("qlogicfc%d : adding a fabric port: %x\n", hostdata
->host_id
, port_id
));
1034 param
[0] = MBOX_PORT_LOGIN
;
1035 param
[1] = loop_id
<< 8;
1036 param
[2] = (u_short
) (port_id
>> 16);
1037 param
[3] = (u_short
) (port_id
);
1039 isp2x00_mbox_command(host
, param
);
1041 if (param
[0] == MBOX_COMMAND_COMPLETE
) {
1042 port_db
[scsi_id
].wwn
= wwn
;
1043 port_db
[scsi_id
].loop_id
= loop_id
;
1047 printk("qlogicfc%d : Error performing port login %x\n", hostdata
->host_id
, param
[0]);
1048 DEBUG_FABRIC(printk("qlogicfc%d : loop_id: %x\n", hostdata
->host_id
, loop_id
));
1049 param
[0] = MBOX_PORT_LOGOUT
;
1050 param
[1] = loop_id
<< 8;
1054 isp2x00_mbox_command(host
, param
);
1059 if (hostdata
->port_id
== port_id
)
1062 printk("qlogicfc%d : Get All Next failed %x.\n", hostdata
->host_id
, param
[0]);
1070 #endif /* ISP2x00_FABRIC */
1073 int isp2x00_release(struct Scsi_Host
*host
)
1075 struct isp2x00_hostdata
*hostdata
;
1077 ENTER("isp2x00_release");
1079 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1081 outw(0x0, host
->io_port
+ PCI_INTER_CTL
);
1082 free_irq(host
->irq
, host
);
1084 release_region(host
->io_port
, 0xff);
1086 LEAVE("isp2x00_release");
1092 const char *isp2x00_info(struct Scsi_Host
*host
)
1094 static char buf
[80];
1095 struct isp2x00_hostdata
*hostdata
;
1096 ENTER("isp2x00_info");
1098 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1100 "QLogic ISP%04x SCSI on PCI bus %02x device %02x irq %d base 0x%lx",
1101 hostdata
->pci_dev
->device
, hostdata
->pci_dev
->bus
->number
, hostdata
->pci_dev
->devfn
, host
->irq
,
1105 LEAVE("isp2x00_info");
1112 * The middle SCSI layer ensures that queuecommand never gets invoked
1113 * concurrently with itself or the interrupt handler (though the
1114 * interrupt handler may call this routine as part of
1115 * request-completion handling).
1117 int isp2x00_queuecommand(Scsi_Cmnd
* Cmnd
, void (*done
) (Scsi_Cmnd
*))
1119 int i
, sg_count
, n
, num_free
;
1120 u_int in_ptr
, out_ptr
;
1122 struct scatterlist
*sg
;
1123 struct Command_Entry
*cmd
;
1124 struct Continuation_Entry
*cont
;
1125 struct Scsi_Host
*host
;
1126 struct isp2x00_hostdata
*hostdata
;
1128 ENTER("isp2x00_queuecommand");
1131 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1132 Cmnd
->scsi_done
= done
;
1134 DEBUG(isp2x00_print_scsi_cmd(Cmnd
));
1136 if (hostdata
->adapter_state
& AS_REDO_FABRIC_PORTDB
|| hostdata
->adapter_state
& AS_REDO_LOOP_PORTDB
) {
1137 isp2x00_make_portdb(host
);
1138 hostdata
->adapter_state
= AS_LOOP_GOOD
;
1139 printk("qlogicfc%d : Port Database\n", hostdata
->host_id
);
1140 for (i
= 0; hostdata
->port_db
[i
].wwn
!= 0; i
++) {
1141 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
);
1144 if (hostdata
->adapter_state
== AS_FIRMWARE_DEAD
) {
1145 printk("qlogicfc%d : The firmware is dead, just return.\n", hostdata
->host_id
);
1150 out_ptr
= inw(host
->io_port
+ MBOX4
);
1151 in_ptr
= hostdata
->req_in_ptr
;
1153 DEBUG(printk("qlogicfc%d : request queue depth %d\n", hostdata
->host_id
,
1154 REQ_QUEUE_DEPTH(in_ptr
, out_ptr
)));
1156 cmd
= (struct Command_Entry
*) &hostdata
->req
[in_ptr
][0];
1157 in_ptr
= (in_ptr
+ 1) & QLOGICFC_REQ_QUEUE_LEN
;
1158 if (in_ptr
== out_ptr
) {
1159 DEBUG(printk("qlogicfc%d : request queue overflow\n", hostdata
->host_id
));
1162 if (hostdata
->send_marker
) {
1163 struct Marker_Entry
*marker
;
1165 TRACE("queue marker", in_ptr
, 0);
1167 DEBUG(printk("qlogicfc%d : adding marker entry\n", hostdata
->host_id
));
1168 marker
= (struct Marker_Entry
*) cmd
;
1169 memset(marker
, 0, sizeof(struct Marker_Entry
));
1171 marker
->hdr
.entry_type
= ENTRY_MARKER
;
1172 marker
->hdr
.entry_cnt
= 1;
1173 marker
->modifier
= SYNC_ALL
;
1175 hostdata
->send_marker
= 0;
1177 if (((in_ptr
+ 1) & QLOGICFC_REQ_QUEUE_LEN
) == out_ptr
) {
1178 outw(in_ptr
, host
->io_port
+ MBOX4
);
1179 hostdata
->req_in_ptr
= in_ptr
;
1180 DEBUG(printk("qlogicfc%d : request queue overflow\n", hostdata
->host_id
));
1183 cmd
= (struct Command_Entry
*) &hostdata
->req
[in_ptr
][0];
1184 in_ptr
= (in_ptr
+ 1) & QLOGICFC_REQ_QUEUE_LEN
;
1186 TRACE("queue command", in_ptr
, Cmnd
);
1188 memset(cmd
, 0, sizeof(struct Command_Entry
));
1190 /* find a free handle mapping slot */
1191 for (i
= in_ptr
; i
!= (in_ptr
- 1) && hostdata
->handle_ptrs
[i
]; i
= ((i
+ 1) % (QLOGICFC_REQ_QUEUE_LEN
+ 1)));
1193 if (!hostdata
->handle_ptrs
[i
]) {
1195 hostdata
->handle_ptrs
[i
] = Cmnd
;
1196 hostdata
->handle_serials
[i
] = Cmnd
->serial_number
;
1198 printk("qlogicfc%d : no handle slots, this should not happen.\n", hostdata
->host_id
);
1199 printk("hostdata->queued is %x, in_ptr: %x\n", hostdata
->queued
, in_ptr
);
1200 for (i
= 0; i
<= QLOGICFC_REQ_QUEUE_LEN
; i
++){
1201 if (!hostdata
->handle_ptrs
[i
]){
1202 printk("slot %d has %p\n", i
, hostdata
->handle_ptrs
[i
]);
1207 cmd
->hdr
.entry_type
= ENTRY_COMMAND
;
1208 cmd
->hdr
.entry_cnt
= 1;
1209 cmd
->target_lun
= Cmnd
->lun
;
1210 cmd
->expanded_lun
= Cmnd
->lun
;
1212 cmd
->target_id
= hostdata
->port_db
[Cmnd
->target
].loop_id
;
1214 cmd
->target_id
= Cmnd
->target
;
1216 cmd
->total_byte_cnt
= (u_int
) Cmnd
->request_bufflen
;
1218 memcpy(cmd
->cdb
, Cmnd
->cmnd
, Cmnd
->cmd_len
);
1221 cmd
->segment_cnt
= sg_count
= Cmnd
->use_sg
;
1222 sg
= (struct scatterlist
*) Cmnd
->request_buffer
;
1224 /* fill in first two sg entries: */
1226 if (n
> DATASEGS_PER_COMMAND
)
1227 n
= DATASEGS_PER_COMMAND
;
1229 for (i
= 0; i
< n
; i
++) {
1230 ds
[i
].d_base
= virt_to_bus_low32(sg
->address
);
1231 #if BITS_PER_LONG > 32
1232 ds
[i
].d_base_hi
= virt_to_bus_high32(sg
->address
);
1234 ds
[i
].d_count
= sg
->length
;
1237 sg_count
-= DATASEGS_PER_COMMAND
;
1239 while (sg_count
> 0) {
1240 ++cmd
->hdr
.entry_cnt
;
1241 cont
= (struct Continuation_Entry
*)
1242 &hostdata
->req
[in_ptr
][0];
1243 memset(cont
, 0, sizeof(struct Continuation_Entry
));
1244 in_ptr
= (in_ptr
+ 1) & QLOGICFC_REQ_QUEUE_LEN
;
1245 if (in_ptr
== out_ptr
) {
1246 DEBUG(printk("qlogicfc%d : unexpected request queue overflow\n", hostdata
->host_id
));
1249 TRACE("queue continuation", in_ptr
, 0);
1250 cont
->hdr
.entry_type
= ENTRY_CONTINUATION
;
1253 if (n
> DATASEGS_PER_CONT
)
1254 n
= DATASEGS_PER_CONT
;
1255 for (i
= 0; i
< n
; ++i
) {
1256 ds
[i
].d_base
= virt_to_bus_low32(sg
->address
);
1257 #if BITS_PER_LONG > 32
1258 ds
[i
].d_base_hi
= virt_to_bus_high32(sg
->address
);
1260 ds
[i
].d_count
= sg
->length
;
1266 cmd
->dataseg
[0].d_base
= virt_to_bus_low32(Cmnd
->request_buffer
);
1267 #if BITS_PER_LONG > 32
1268 cmd
->dataseg
[0].d_base_hi
= virt_to_bus_high32(Cmnd
->request_buffer
);
1270 cmd
->dataseg
[0].d_count
= (u_int
) Cmnd
->request_bufflen
;
1271 cmd
->segment_cnt
= 1;
1274 switch (Cmnd
->cmnd
[0]) {
1275 case TEST_UNIT_READY
:
1282 cmd
->control_flags
= CFLAG_WRITE
;
1285 /* scsi.c expects sense info in a different buffer */
1286 cmd
->dataseg
[0].d_base
= virt_to_bus_low32(Cmnd
->sense_buffer
);
1287 #if BITS_PER_LONG > 32
1288 cmd
->dataseg
[0].d_base_hi
= virt_to_bus_high32(Cmnd
->request_buffer
);
1290 cmd
->segment_cnt
= 1;
1291 cmd
->control_flags
= CFLAG_READ
;
1294 cmd
->control_flags
= CFLAG_READ
;
1299 if (Cmnd
->device
->tagged_supported
) {
1300 if ((jiffies
- hostdata
->tag_ages
[Cmnd
->target
]) > (2 * SCSI_TIMEOUT
)) {
1301 cmd
->control_flags
|= CFLAG_ORDERED_TAG
;
1302 hostdata
->tag_ages
[Cmnd
->target
] = jiffies
;
1304 switch (Cmnd
->tag
) {
1305 case HEAD_OF_QUEUE_TAG
:
1306 cmd
->control_flags
|= CFLAG_HEAD_TAG
;
1308 case ORDERED_QUEUE_TAG
:
1309 cmd
->control_flags
|= CFLAG_ORDERED_TAG
;
1312 cmd
->control_flags
|= CFLAG_SIMPLE_TAG
;
1316 outw(in_ptr
, host
->io_port
+ MBOX4
);
1317 hostdata
->req_in_ptr
= in_ptr
;
1321 num_free
= QLOGICFC_REQ_QUEUE_LEN
- REQ_QUEUE_DEPTH(in_ptr
, out_ptr
);
1322 num_free
= (num_free
> 2) ? num_free
- 2 : 0;
1323 host
->can_queue
= hostdata
->queued
+ num_free
;
1324 if (host
->can_queue
> QLOGICFC_REQ_QUEUE_LEN
)
1325 host
->can_queue
= QLOGICFC_REQ_QUEUE_LEN
;
1326 host
->sg_tablesize
= QLOGICFC_MAX_SG(num_free
);
1328 /* this is really gross */
1329 if (host
->can_queue
<= host
->host_busy
){
1330 if (host
->can_queue
+2 < host
->host_busy
)
1331 DEBUG(printk("qlogicfc%d.c crosses its fingers.\n", hostdata
->host_id
));
1332 host
->can_queue
= host
->host_busy
+ 1;
1335 LEAVE("isp2x00_queuecommand");
1341 #define ASYNC_EVENT_INTERRUPT 0x01
1344 void do_isp2x00_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1346 unsigned long flags
;
1348 spin_lock_irqsave(&io_request_lock
, flags
);
1349 isp2x00_intr_handler(irq
, dev_id
, regs
);
1350 spin_unlock_irqrestore(&io_request_lock
, flags
);
1353 void isp2x00_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1356 struct Status_Entry
*sts
;
1357 struct Scsi_Host
*host
= dev_id
;
1358 struct isp2x00_hostdata
*hostdata
;
1359 u_int in_ptr
, out_ptr
, handle
, num_free
;
1362 ENTER_INTR("isp2x00_intr_handler");
1364 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1366 DEBUG_INTR(printk("qlogicfc%d : interrupt on line %d\n", hostdata
->host_id
, irq
));
1368 if (!(inw(host
->io_port
+ PCI_INTER_STS
) & 0x08)) {
1369 /* spurious interrupts can happen legally */
1370 DEBUG_INTR(printk("qlogicfc%d : got spurious interrupt\n", hostdata
->host_id
));
1373 in_ptr
= inw(host
->io_port
+ MBOX5
);
1374 out_ptr
= hostdata
->res_out_ptr
;
1376 if ((inw(host
->io_port
+ PCI_SEMAPHORE
) & ASYNC_EVENT_INTERRUPT
)) {
1377 status
= inw(host
->io_port
+ MBOX0
);
1379 DEBUG_INTR(printk("qlogicfc%d : mbox completion status: %x\n",
1380 hostdata
->host_id
, status
));
1384 case POINT_TO_POINT_UP
:
1385 printk("qlogicfc%d : link is up\n", hostdata
->host_id
);
1386 hostdata
->adapter_state
= AS_REDO_FABRIC_PORTDB
| AS_REDO_LOOP_PORTDB
;
1389 printk("qlogicfc%d : link is down\n", hostdata
->host_id
);
1390 hostdata
->adapter_state
= AS_LOOP_DOWN
;
1392 case CONNECTION_MODE
:
1393 printk("received CONNECTION_MODE irq %x\n", inw(host
->io_port
+ MBOX1
));
1395 case CHANGE_NOTIFICATION
:
1396 if (hostdata
->adapter_state
== AS_LOOP_GOOD
)
1397 hostdata
->adapter_state
= AS_REDO_FABRIC_PORTDB
;
1400 case PORT_DB_CHANGED
:
1402 if (hostdata
->adapter_state
== AS_LOOP_GOOD
)
1403 hostdata
->adapter_state
= AS_REDO_LOOP_PORTDB
;
1406 printk("qlogicfc%d : The firmware just choked.\n", hostdata
->host_id
);
1407 hostdata
->adapter_state
= AS_FIRMWARE_DEAD
;
1409 case SCSI_COMMAND_COMPLETE
:
1410 handle
= inw(host
->io_port
+ MBOX1
) | (inw(host
->io_port
+ MBOX2
) << 16);
1411 Cmnd
= hostdata
->handle_ptrs
[handle
];
1412 hostdata
->handle_ptrs
[handle
] = NULL
;
1413 hostdata
->handle_serials
[handle
] = 0;
1417 (*Cmnd
->scsi_done
) (Cmnd
);
1419 printk("qlogicfc%d.c : got a null value out of handle_ptrs, this sucks\n", hostdata
->host_id
);
1421 case MBOX_COMMAND_COMPLETE
:
1422 case INVALID_COMMAND
:
1423 case HOST_INTERFACE_ERROR
:
1426 case COMMAND_PARAM_ERROR
:
1430 hostdata
->mbox_done
= 1;
1431 outw(HCCR_CLEAR_RISC_INTR
, host
->io_port
+ HOST_HCCR
);
1434 printk("qlogicfc%d : got an unknown status? %x\n", hostdata
->host_id
, status
);
1436 outw(0x0, host
->io_port
+ PCI_SEMAPHORE
);
1438 DEBUG_INTR(printk("qlogicfc%d : response queue update\n", hostdata
->host_id
));
1439 DEBUG_INTR(printk("qlogicfc%d : response queue depth %d\n", hostdata
->host_id
, RES_QUEUE_DEPTH(in_ptr
, out_ptr
)));
1441 while (out_ptr
!= in_ptr
) {
1442 sts
= (struct Status_Entry
*) &hostdata
->res
[out_ptr
][0];
1443 out_ptr
= (out_ptr
+ 1) & RES_QUEUE_LEN
;
1445 TRACE("done", out_ptr
, Cmnd
);
1446 DEBUG_INTR(isp2x00_print_status_entry(sts
));
1447 if (sts
->hdr
.entry_type
== ENTRY_STATUS
&& (Cmnd
= hostdata
->handle_ptrs
[sts
->handle
])) {
1448 Cmnd
->result
= isp2x00_return_status(sts
);
1449 hostdata
->handle_ptrs
[sts
->handle
] = NULL
;
1453 * if any of the following are true we do not
1454 * call scsi_done. if the status is CS_ABORTED
1455 * we dont have to call done because the upper
1456 * level should already know its aborted.
1458 if (hostdata
->handle_serials
[sts
->handle
] != Cmnd
->serial_number
1459 || sts
->completion_status
== CS_ABORTED
){
1460 hostdata
->handle_serials
[sts
->handle
] = 0;
1461 outw(out_ptr
, host
->io_port
+ MBOX5
);
1465 * if we get back an error indicating the port
1466 * is not there or if the link is down and
1467 * this is a device that used to be there
1468 * allow the command to timeout.
1469 * the device may well be back in a couple of
1472 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
){
1473 outw(out_ptr
, host
->io_port
+ MBOX5
);
1477 outw(out_ptr
, host
->io_port
+ MBOX5
);
1481 if (sts
->completion_status
== CS_RESET_OCCURRED
1482 || (sts
->status_flags
& STF_BUS_RESET
))
1483 hostdata
->send_marker
= 1;
1485 memset(Cmnd
->sense_buffer
, 0, sizeof(Cmnd
->sense_buffer
));
1486 if (sts
->scsi_status
& 0x0200)
1487 memcpy(Cmnd
->sense_buffer
, sts
->req_sense_data
,
1488 sizeof(Cmnd
->sense_buffer
));
1490 outw(out_ptr
, host
->io_port
+ MBOX5
);
1492 if (Cmnd
->scsi_done
!= NULL
) {
1493 (*Cmnd
->scsi_done
) (Cmnd
);
1495 printk("qlogicfc%d : Ouch, scsi done is NULL\n", hostdata
->host_id
);
1497 hostdata
->res_out_ptr
= out_ptr
;
1501 out_ptr
= inw(host
->io_port
+ MBOX4
);
1502 in_ptr
= hostdata
->req_in_ptr
;
1504 num_free
= QLOGICFC_REQ_QUEUE_LEN
- REQ_QUEUE_DEPTH(in_ptr
, out_ptr
);
1505 num_free
= (num_free
> 2) ? num_free
- 2 : 0;
1506 host
->can_queue
= hostdata
->queued
+ num_free
;
1507 if (host
->can_queue
> QLOGICFC_REQ_QUEUE_LEN
)
1508 host
->can_queue
= QLOGICFC_REQ_QUEUE_LEN
;
1509 host
->sg_tablesize
= QLOGICFC_MAX_SG(num_free
);
1511 if (host
->can_queue
<= host
->host_busy
){
1512 if (host
->can_queue
+2 < host
->host_busy
)
1513 DEBUG(printk("qlogicfc%d : crosses its fingers.\n", hostdata
->host_id
));
1514 host
->can_queue
= host
->host_busy
+ 1;
1517 outw(HCCR_CLEAR_RISC_INTR
, host
->io_port
+ HOST_HCCR
);
1518 LEAVE_INTR("isp2x00_intr_handler");
1522 static int isp2x00_return_status(struct Status_Entry
*sts
)
1524 int host_status
= DID_ERROR
;
1525 #if DEBUG_ISP2x00_INTR
1526 static char *reason
[] =
1539 #endif /* DEBUG_ISP2x00_INTR */
1541 ENTER("isp2x00_return_status");
1543 DEBUG(printk("qlogicfc : completion status = 0x%04x\n",
1544 sts
->completion_status
));
1546 switch (sts
->completion_status
) {
1548 host_status
= DID_OK
;
1551 host_status
= DID_ERROR
;
1553 case CS_RESET_OCCURRED
:
1554 host_status
= DID_RESET
;
1557 host_status
= DID_ABORT
;
1560 host_status
= DID_TIME_OUT
;
1562 case CS_DATA_OVERRUN
:
1563 host_status
= DID_ERROR
;
1565 case CS_DATA_UNDERRUN
:
1566 host_status
= DID_OK
;
1568 case CS_PORT_UNAVAILABLE
:
1569 case CS_PORT_LOGGED_OUT
:
1570 case CS_PORT_CONFIG_CHANGED
:
1571 host_status
= DID_BAD_TARGET
;
1574 host_status
= DID_ERROR
;
1577 printk("qlogicfc : unknown completion status 0x%04x\n",
1578 sts
->completion_status
);
1579 host_status
= DID_ERROR
;
1583 DEBUG_INTR(printk("qlogicfc : host status (%s) scsi status %x\n",
1584 reason
[host_status
], sts
->scsi_status
));
1586 LEAVE("isp2x00_return_status");
1588 return (sts
->scsi_status
& STATUS_MASK
) | (host_status
<< 16);
1592 int isp2x00_abort(Scsi_Cmnd
* Cmnd
)
1596 struct Scsi_Host
*host
;
1597 struct isp2x00_hostdata
*hostdata
;
1598 int return_status
= SUCCESS
;
1600 ENTER("isp2x00_abort");
1603 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1605 for (i
= 0; i
< QLOGICFC_REQ_QUEUE_LEN
; i
++)
1606 if (hostdata
->handle_ptrs
[i
] == Cmnd
)
1609 if (i
== QLOGICFC_REQ_QUEUE_LEN
){
1613 isp2x00_disable_irqs(host
);
1615 param
[0] = MBOX_ABORT_IOCB
;
1617 param
[1] = (((u_short
) hostdata
->port_db
[Cmnd
->target
].loop_id
) << 8) | Cmnd
->lun
;
1619 param
[1] = (((u_short
) Cmnd
->target
) << 8) | Cmnd
->lun
;
1621 param
[2] = i
& 0xffff;
1624 isp2x00_mbox_command(host
, param
);
1626 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1627 printk("qlogicfc%d : scsi abort failure: %x\n", hostdata
->host_id
, param
[0]);
1628 if (param
[0] == 0x4005)
1629 Cmnd
->result
= DID_ERROR
<< 16;
1630 if (param
[0] == 0x4006)
1631 Cmnd
->result
= DID_BAD_TARGET
<< 16;
1632 return_status
= FAILED
;
1635 if (return_status
!= SUCCESS
){
1636 param
[0] = MBOX_GET_FIRMWARE_STATE
;
1637 isp2x00_mbox_command(host
, param
);
1638 printk("qlogicfc%d : abort failed\n", hostdata
->host_id
);
1639 printk("qlogicfc%d : firmware status is %x %x\n", hostdata
->host_id
, param
[0], param
[1]);
1642 isp2x00_enable_irqs(host
);
1644 LEAVE("isp2x00_abort");
1646 return return_status
;
1650 int isp2x00_reset(Scsi_Cmnd
* Cmnd
, unsigned int reset_flags
)
1653 struct Scsi_Host
*host
;
1654 struct isp2x00_hostdata
*hostdata
;
1655 int return_status
= SCSI_RESET_SUCCESS
;
1657 ENTER("isp2x00_reset");
1660 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1661 param
[0] = MBOX_BUS_RESET
;
1664 isp2x00_disable_irqs(host
);
1666 isp2x00_mbox_command(host
, param
);
1668 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1669 printk("qlogicfc%d : scsi bus reset failure: %x\n", hostdata
->host_id
, param
[0]);
1670 return_status
= SCSI_RESET_ERROR
;
1672 isp2x00_enable_irqs(host
);
1674 LEAVE("isp2x00_reset");
1676 return return_status
;;
1680 int isp2x00_biosparam(Disk
* disk
, kdev_t n
, int ip
[])
1682 int size
= disk
->capacity
;
1684 ENTER("isp2x00_biosparam");
1692 ip
[2] = size
/ (ip
[0] * ip
[1]);
1694 LEAVE("isp2x00_biosparam");
1700 static int isp2x00_reset_hardware(struct Scsi_Host
*host
)
1703 struct isp2x00_hostdata
*hostdata
;
1706 ENTER("isp2x00_reset_hardware");
1708 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1710 outw(0x01, host
->io_port
+ ISP_CTRL_STATUS
);
1711 outw(HCCR_RESET
, host
->io_port
+ HOST_HCCR
);
1712 outw(HCCR_RELEASE
, host
->io_port
+ HOST_HCCR
);
1713 outw(HCCR_BIOS_DISABLE
, host
->io_port
+ HOST_HCCR
);
1715 loop_count
= DEFAULT_LOOP_COUNT
;
1716 while (--loop_count
&& inw(host
->io_port
+ HOST_HCCR
) == RISC_BUSY
)
1719 printk("qlogicfc%d : reset_hardware loop timeout\n", hostdata
->host_id
);
1724 printk("qlogicfc%d : mbox 0 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX0
));
1725 printk("qlogicfc%d : mbox 1 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX1
));
1726 printk("qlogicfc%d : mbox 2 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX2
));
1727 printk("qlogicfc%d : mbox 3 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX3
));
1728 printk("qlogicfc%d : mbox 4 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX4
));
1729 printk("qlogicfc%d : mbox 5 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX5
));
1730 printk("qlogicfc%d : mbox 6 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX6
));
1731 printk("qlogicfc%d : mbox 7 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX7
));
1732 #endif /* DEBUG_ISP2x00 */
1734 DEBUG(printk("qlogicfc%d : verifying checksum\n", hostdata
->host_id
));
1739 unsigned short * risc_code
= NULL
;
1740 unsigned short risc_code_len
= 0;
1741 if (hostdata
->pci_dev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2100
){
1742 risc_code
= risc_code2100
;
1743 risc_code_len
= risc_code_length2100
;
1745 else if (hostdata
->pci_dev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2200
){
1746 risc_code
= risc_code2200
;
1747 risc_code_len
= risc_code_length2200
;
1750 for (i
= 0; i
< risc_code_len
; i
++) {
1751 param
[0] = MBOX_WRITE_RAM_WORD
;
1752 param
[1] = risc_code_addr01
+ i
;
1753 param
[2] = risc_code
[i
];
1755 isp2x00_mbox_command(host
, param
);
1757 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1758 printk("qlogicfc%d : firmware load failure\n", hostdata
->host_id
);
1763 #endif /* RELOAD_FIRMWARE */
1765 param
[0] = MBOX_VERIFY_CHECKSUM
;
1766 param
[1] = risc_code_addr01
;
1768 isp2x00_mbox_command(host
, param
);
1770 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1771 printk("qlogicfc%d : ram checksum failure\n", hostdata
->host_id
);
1774 DEBUG(printk("qlogicfc%d : executing firmware\n", hostdata
->host_id
));
1776 param
[0] = MBOX_EXEC_FIRMWARE
;
1777 param
[1] = risc_code_addr01
;
1779 isp2x00_mbox_command(host
, param
);
1781 param
[0] = MBOX_ABOUT_FIRMWARE
;
1783 isp2x00_mbox_command(host
, param
);
1785 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1786 printk("qlogicfc%d : about firmware failure\n", hostdata
->host_id
);
1789 DEBUG(printk("qlogicfc%d : firmware major revision %d\n", hostdata
->host_id
, param
[1]));
1790 DEBUG(printk("qlogicfc%d : firmware minor revision %d\n", hostdata
->host_id
, param
[2]));
1792 #ifdef USE_NVRAM_DEFAULTS
1794 if (isp2x00_get_nvram_defaults(host
, &hostdata
->control_block
) != 0) {
1795 printk("qlogicfc%d : Could not read from NVRAM\n", hostdata
->host_id
);
1799 hostdata
->wwn
= (u64
) (hostdata
->control_block
.node_name
[0]) << 56;
1800 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[0] & 0xff00) << 48;
1801 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[1] & 0xff00) << 24;
1802 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[1] & 0x00ff) << 48;
1803 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[2] & 0x00ff) << 24;
1804 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[2] & 0xff00) << 8;
1805 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[3] & 0x00ff) << 8;
1806 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[3] & 0xff00) >> 8;
1808 param
[0] = MBOX_INIT_FIRMWARE
;
1809 param
[2] = (u_short
) (virt_to_bus_low32(&hostdata
->control_block
) >> 16);
1810 param
[3] = (u_short
) (virt_to_bus_low32(&hostdata
->control_block
) & 0xffff);
1813 param
[6] = (u_short
) (virt_to_bus_high32(&hostdata
->control_block
) >> 16);
1814 param
[7] = (u_short
) (virt_to_bus_high32(&hostdata
->control_block
) & 0xffff);
1815 isp2x00_mbox_command(host
, param
);
1816 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1817 printk("qlogicfc%d.c: Ouch 0x%04x\n", hostdata
->host_id
, param
[0]);
1820 param
[0] = MBOX_GET_FIRMWARE_STATE
;
1821 isp2x00_mbox_command(host
, param
);
1822 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1823 printk("qlogicfc%d.c: 0x%04x\n", hostdata
->host_id
, param
[0]);
1827 LEAVE("isp2x00_reset_hardware");
1832 #ifdef USE_NVRAM_DEFAULTS
1834 static int isp2x00_get_nvram_defaults(struct Scsi_Host
*host
, struct init_cb
*control_block
)
1838 if (isp2x00_read_nvram_word(host
, 0) != 0x5349)
1841 value
= isp2x00_read_nvram_word(host
, 8);
1842 control_block
->node_name
[0] = isp2x00_read_nvram_word(host
, 9);
1843 control_block
->node_name
[1] = isp2x00_read_nvram_word(host
, 10);
1844 control_block
->node_name
[2] = isp2x00_read_nvram_word(host
, 11);
1845 control_block
->node_name
[3] = isp2x00_read_nvram_word(host
, 12);
1846 control_block
->hard_addr
= isp2x00_read_nvram_word(host
, 13);
1854 static int isp2x00_init(struct Scsi_Host
*sh
)
1857 struct isp2x00_hostdata
*hostdata
;
1861 struct pci_dev
*pdev
;
1864 ENTER("isp2x00_init");
1866 hostdata
= (struct isp2x00_hostdata
*) sh
->hostdata
;
1867 pdev
= hostdata
->pci_dev
;
1869 if (pci_read_config_word(pdev
, PCI_COMMAND
, &command
)
1870 || pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &revision
)) {
1871 printk("qlogicfc%d : error reading PCI configuration\n", hostdata
->host_id
);
1874 io_base
= pdev
->resource
[0].start
;
1878 if (pdev
->vendor
!= PCI_VENDOR_ID_QLOGIC
) {
1879 printk("qlogicfc%d : 0x%04x is not QLogic vendor ID\n", hostdata
->host_id
,
1883 if (pdev
->device
!= PCI_DEVICE_ID_QLOGIC_ISP2100
&& pdev
->device
!= PCI_DEVICE_ID_QLOGIC_ISP2200
) {
1884 printk("qlogicfc%d : 0x%04x does not match ISP2100 or ISP2200 device id\n", hostdata
->host_id
,
1888 if (!(command
& PCI_COMMAND_IO
) ||
1889 !(pdev
->resource
[0].flags
& IORESOURCE_IO
)) {
1890 printk("qlogicfc%d : i/o mapping is disabled\n", hostdata
->host_id
);
1894 if (!(command
& PCI_COMMAND_MASTER
)) {
1895 printk("qlogicfc%d : bus mastering is disabled\n", hostdata
->host_id
);
1898 if (revision
!= ISP2100_REV_ID1
&& revision
!= ISP2100_REV_ID3
&& revision
!= ISP2200_REV_ID5
)
1899 printk("qlogicfc%d : new isp2x00 revision ID (%d)\n", hostdata
->host_id
, revision
);
1902 hostdata
->revision
= revision
;
1905 sh
->io_port
= io_base
;
1907 LEAVE("isp2x00_init");
1912 #if USE_NVRAM_DEFAULTS
1914 #define NVRAM_DELAY() udelay(10) /* 10 microsecond delay */
1917 u_short
isp2x00_read_nvram_word(struct Scsi_Host
* host
, u_short byte
)
1920 u_short value
, output
, input
;
1922 outw(0x2, host
->io_port
+ PCI_NVRAM
);
1924 outw(0x3, host
->io_port
+ PCI_NVRAM
);
1929 for (i
= 10; i
>= 0; i
--) {
1930 output
= ((byte
>> i
) & 0x1) ? 0x4 : 0x0;
1931 outw(output
| 0x2, host
->io_port
+ PCI_NVRAM
);
1933 outw(output
| 0x3, host
->io_port
+ PCI_NVRAM
);
1935 outw(output
| 0x2, host
->io_port
+ PCI_NVRAM
);
1939 for (i
= 0xf, value
= 0; i
>= 0; i
--) {
1941 outw(0x3, host
->io_port
+ PCI_NVRAM
);
1943 input
= inw(host
->io_port
+ PCI_NVRAM
);
1945 outw(0x2, host
->io_port
+ PCI_NVRAM
);
1951 outw(0x0, host
->io_port
+ PCI_NVRAM
);
1958 #endif /* USE_NVRAM_DEFAULTS */
1963 * currently, this is only called during initialization or abort/reset,
1964 * at which times interrupts are disabled, so polling is OK, I guess...
1966 static int isp2x00_mbox_command(struct Scsi_Host
*host
, u_short param
[])
1969 struct isp2x00_hostdata
*hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1971 if (mbox_param
[param
[0]] == 0 || hostdata
->adapter_state
== AS_FIRMWARE_DEAD
)
1974 loop_count
= DEFAULT_LOOP_COUNT
;
1975 while (--loop_count
&& inw(host
->io_port
+ HOST_HCCR
) & 0x0080)
1978 printk("qlogicfc%d : mbox_command loop timeout #1\n", hostdata
->host_id
);
1980 hostdata
->adapter_state
= AS_FIRMWARE_DEAD
;
1983 hostdata
->mbox_done
= 0;
1985 if (mbox_param
[param
[0]] == 0)
1986 printk("qlogicfc%d : invalid mbox command\n", hostdata
->host_id
);
1988 if (mbox_param
[param
[0]] & 0x80)
1989 outw(param
[7], host
->io_port
+ MBOX7
);
1990 if (mbox_param
[param
[0]] & 0x40)
1991 outw(param
[6], host
->io_port
+ MBOX6
);
1992 if (mbox_param
[param
[0]] & 0x20)
1993 outw(param
[5], host
->io_port
+ MBOX5
);
1994 if (mbox_param
[param
[0]] & 0x10)
1995 outw(param
[4], host
->io_port
+ MBOX4
);
1996 if (mbox_param
[param
[0]] & 0x08)
1997 outw(param
[3], host
->io_port
+ MBOX3
);
1998 if (mbox_param
[param
[0]] & 0x04)
1999 outw(param
[2], host
->io_port
+ MBOX2
);
2000 if (mbox_param
[param
[0]] & 0x02)
2001 outw(param
[1], host
->io_port
+ MBOX1
);
2002 if (mbox_param
[param
[0]] & 0x01)
2003 outw(param
[0], host
->io_port
+ MBOX0
);
2006 outw(HCCR_SET_HOST_INTR
, host
->io_port
+ HOST_HCCR
);
2009 loop_count
= DEFAULT_LOOP_COUNT
;
2010 while (--loop_count
&& !(inw(host
->io_port
+ PCI_INTER_STS
) & 0x08)) {
2015 hostdata
->adapter_state
= AS_FIRMWARE_DEAD
;
2016 printk("qlogicfc%d : mbox_command loop timeout #2\n", hostdata
->host_id
);
2019 isp2x00_intr_handler(host
->irq
, host
, NULL
);
2021 if (hostdata
->mbox_done
== 1)
2026 loop_count
= DEFAULT_LOOP_COUNT
;
2027 while (--loop_count
&& inw(host
->io_port
+ MBOX0
) == 0x04) {
2031 printk("qlogicfc%d : mbox_command loop timeout #3\n", hostdata
->host_id
);
2033 param
[7] = inw(host
->io_port
+ MBOX7
);
2034 param
[6] = inw(host
->io_port
+ MBOX6
);
2035 param
[5] = inw(host
->io_port
+ MBOX5
);
2036 param
[4] = inw(host
->io_port
+ MBOX4
);
2037 param
[3] = inw(host
->io_port
+ MBOX3
);
2038 param
[2] = inw(host
->io_port
+ MBOX2
);
2039 param
[1] = inw(host
->io_port
+ MBOX1
);
2040 param
[0] = inw(host
->io_port
+ MBOX0
);
2043 outw(0x0, host
->io_port
+ PCI_SEMAPHORE
);
2045 if (inw(host
->io_port
+ HOST_HCCR
) & 0x0080) {
2046 hostdata
->adapter_state
= AS_FIRMWARE_DEAD
;
2047 printk("qlogicfc%d : mbox op is still pending\n", hostdata
->host_id
);
2052 #if DEBUG_ISP2x00_INTR
2054 void isp2x00_print_status_entry(struct Status_Entry
*status
)
2056 printk("qlogicfc : entry count = 0x%02x, type = 0x%02x, flags = 0x%02x\n",
2057 status
->hdr
.entry_cnt
, status
->hdr
.entry_type
, status
->hdr
.flags
);
2058 printk("qlogicfc : scsi status = 0x%04x, completion status = 0x%04x\n",
2059 status
->scsi_status
, status
->completion_status
);
2060 printk("qlogicfc : state flags = 0x%04x, status flags = 0x%04x\n",
2061 status
->state_flags
, status
->status_flags
);
2062 printk("qlogicfc : response info length = 0x%04x, request sense length = 0x%04x\n",
2063 status
->res_info_len
, status
->req_sense_len
);
2064 printk("qlogicfc : residual transfer length = 0x%08x, response = 0x%02x\n", status
->residual
, status
->res_info
[3]);
2068 #endif /* DEBUG_ISP2x00_INTR */
2073 void isp2x00_print_scsi_cmd(Scsi_Cmnd
* cmd
)
2077 printk("qlogicfc : target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
2078 cmd
->target
, cmd
->lun
, cmd
->cmd_len
);
2079 printk("qlogicfc : command = ");
2080 for (i
= 0; i
< cmd
->cmd_len
; i
++)
2081 printk("0x%02x ", cmd
->cmnd
[i
]);
2085 #endif /* DEBUG_ISP2x00 */
2090 Scsi_Host_Template driver_template
= QLOGICFC
;
2092 #include "scsi_module.c"