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_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
{
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
;
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];
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
*);
685 static int isp2x00_init_fabric(struct Scsi_Host
*, struct id_name_map
*, int);
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
);
694 static void isp2x00_print_scsi_cmd(Scsi_Cmnd
*);
697 #if DEBUG_ISP2x00_INTR
698 static void isp2x00_print_status_entry(struct Status_Entry
*);
701 static struct proc_dir_entry proc_scsi_isp2x00
=
703 PROC_SCSI_QLOGICFC
, 7, "isp2x00",
704 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
708 static inline void isp2x00_enable_irqs(struct Scsi_Host
*host
)
710 outw(ISP_EN_INT
| ISP_EN_RISC
, host
->io_port
+ PCI_INTER_CTL
);
714 static inline void isp2x00_disable_irqs(struct Scsi_Host
*host
)
716 outw(0x0, host
->io_port
+ PCI_INTER_CTL
);
720 int isp2x00_detect(Scsi_Host_Template
* tmpt
)
724 struct Scsi_Host
*host
= NULL
;
725 struct isp2x00_hostdata
*hostdata
;
726 struct pci_dev
*pdev
= NULL
;
727 unsigned short device_ids
[2];
731 ENTER("isp2x00_detect");
733 device_ids
[0] = PCI_DEVICE_ID_QLOGIC_ISP2100
;
734 device_ids
[1] = PCI_DEVICE_ID_QLOGIC_ISP2200
;
736 tmpt
->proc_dir
= &proc_scsi_isp2x00
;
738 if (pci_present() == 0) {
739 printk("qlogicfc : PCI not present\n");
744 while ((pdev
= pci_find_device(PCI_VENDOR_ID_QLOGIC
, device_ids
[i
], pdev
))) {
746 host
= scsi_register(tmpt
, sizeof(struct isp2x00_hostdata
));
747 host
->max_id
= QLOGICFC_MAX_ID
+ 1;
748 host
->max_lun
= QLOGICFC_MAX_LUN
;
749 host
->hostt
->use_new_eh_code
= 1;
750 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
752 memset(hostdata
, 0, sizeof(struct isp2x00_hostdata
));
753 hostdata
->pci_dev
= pdev
;
755 hostdata
->queued
= 0;
756 /* set up the control block */
757 hostdata
->control_block
.version
= 0x1;
758 hostdata
->control_block
.firm_opts
= 0x0108;
759 hostdata
->control_block
.max_frame_len
= 2048;
760 hostdata
->control_block
.max_iocb
= 256;
761 hostdata
->control_block
.exec_throttle
= 8;
762 hostdata
->control_block
.retry_delay
= 5;
763 hostdata
->control_block
.retry_cnt
= 1;
764 hostdata
->control_block
.node_name
[0] = 0x0020;
765 hostdata
->control_block
.node_name
[1] = 0xE000;
766 hostdata
->control_block
.node_name
[2] = 0x008B;
767 hostdata
->control_block
.node_name
[3] = 0x0000;
768 hostdata
->control_block
.hard_addr
= 0x0003;
769 hostdata
->control_block
.req_queue_len
= QLOGICFC_REQ_QUEUE_LEN
+ 1;
770 hostdata
->control_block
.res_queue_len
= RES_QUEUE_LEN
+ 1;
771 hostdata
->control_block
.res_queue_addr_lo
= virt_to_bus_low32(&hostdata
->res
);
772 hostdata
->control_block
.res_queue_addr_high
= virt_to_bus_high32(&hostdata
->res
);
773 hostdata
->control_block
.req_queue_addr_lo
= virt_to_bus_low32(&hostdata
->req
);
774 hostdata
->control_block
.req_queue_addr_high
= virt_to_bus_high32(&hostdata
->req
);
777 hostdata
->adapter_state
= AS_LOOP_DOWN
;
778 hostdata
->host_id
= hosts
;
780 if (isp2x00_init(host
) || isp2x00_reset_hardware(host
)) {
781 scsi_unregister(host
);
786 if (request_irq(host
->irq
, do_isp2x00_intr_handler
, SA_INTERRUPT
| SA_SHIRQ
, "qlogicfc", host
)) {
787 printk("qlogicfc%d : interrupt %d already in use\n",
788 hostdata
->host_id
, host
->irq
);
789 scsi_unregister(host
);
792 if (check_region(host
->io_port
, 0xff)) {
793 printk("qlogicfc%d : i/o region 0x%lx-0x%lx already "
795 hostdata
->host_id
, host
->io_port
, host
->io_port
+ 0xff);
796 free_irq(host
->irq
, host
);
797 scsi_unregister(host
);
800 request_region(host
->io_port
, 0xff, "qlogicfc");
802 outw(0x0, host
->io_port
+ PCI_SEMAPHORE
);
803 outw(HCCR_CLEAR_RISC_INTR
, host
->io_port
+ HOST_HCCR
);
804 isp2x00_enable_irqs(host
);
805 /* wait for the loop to come up */
806 for (wait_time
= jiffies
+ 10 * HZ
; wait_time
> jiffies
&& hostdata
->adapter_state
== AS_LOOP_DOWN
;)
809 if (hostdata
->adapter_state
== AS_LOOP_DOWN
) {
810 printk("qlogicfc%d : link is not up\n", hostdata
->host_id
);
817 /* this busy loop should not be needed but the isp2x00 seems to need
818 some time before recognizing it is attached to a fabric */
821 for (wait_time
= jiffies
+ 5 * HZ
; wait_time
> jiffies
;)
825 LEAVE("isp2x00_detect");
831 static int isp2x00_make_portdb(struct Scsi_Host
*host
)
836 struct id_name_map temp
[QLOGICFC_MAX_ID
+ 1];
837 struct isp2x00_hostdata
*hostdata
;
839 isp2x00_disable_irqs(host
);
841 memset(temp
, 0, sizeof(temp
));
842 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
845 for (i
= 0x81; i
< QLOGICFC_MAX_ID
; i
++) {
846 param
[0] = MBOX_PORT_LOGOUT
;
851 isp2x00_mbox_command(host
, param
);
853 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
855 DEBUG_FABRIC(printk("qlogicfc%d : logout failed %x %x\n", hostdata
->host_id
, i
, param
[0]));
861 param
[0] = MBOX_GET_INIT_SCSI_ID
;
863 isp2x00_mbox_command(host
, param
);
865 if (param
[0] == MBOX_COMMAND_COMPLETE
) {
866 hostdata
->port_id
= ((u_int
) param
[3]) << 16;
867 hostdata
->port_id
|= param
[2];
868 temp
[0].loop_id
= param
[1];
869 temp
[0].wwn
= hostdata
->wwn
;
872 printk("qlogicfc%d : error getting scsi id.\n", hostdata
->host_id
);
875 for (i
= 0; i
<=QLOGICFC_MAX_ID
; i
++)
876 temp
[i
].loop_id
= temp
[0].loop_id
;
878 for (i
= 0, j
= 1; i
<= QLOGICFC_MAX_LOOP_ID
; i
++) {
879 param
[0] = MBOX_GET_PORT_NAME
;
880 param
[1] = (i
<< 8) & 0xff00;
882 isp2x00_mbox_command(host
, param
);
884 if (param
[0] == MBOX_COMMAND_COMPLETE
) {
886 temp
[j
].wwn
= ((u64
) (param
[2] & 0xff)) << 56;
887 temp
[j
].wwn
|= ((u64
) ((param
[2] >> 8) & 0xff)) << 48;
888 temp
[j
].wwn
|= ((u64
) (param
[3] & 0xff)) << 40;
889 temp
[j
].wwn
|= ((u64
) ((param
[3] >> 8) & 0xff)) << 32;
890 temp
[j
].wwn
|= ((u64
) (param
[6] & 0xff)) << 24;
891 temp
[j
].wwn
|= ((u64
) ((param
[6] >> 8) & 0xff)) << 16;
892 temp
[j
].wwn
|= ((u64
) (param
[7] & 0xff)) << 8;
893 temp
[j
].wwn
|= ((u64
) ((param
[7] >> 8) & 0xff));
902 isp2x00_init_fabric(host
, temp
, j
);
905 for (i
= 0; i
<= QLOGICFC_MAX_ID
; i
++) {
906 if (temp
[i
].wwn
!= hostdata
->port_db
[i
].wwn
) {
907 for (j
= 0; j
<= QLOGICFC_MAX_ID
; j
++) {
908 if (temp
[j
].wwn
== hostdata
->port_db
[i
].wwn
) {
909 hostdata
->port_db
[i
].loop_id
= temp
[j
].loop_id
;
913 if (j
== QLOGICFC_MAX_ID
+ 1)
914 hostdata
->port_db
[i
].loop_id
= temp
[0].loop_id
;
916 for (j
= 0; j
<= QLOGICFC_MAX_ID
; j
++) {
917 if (hostdata
->port_db
[j
].wwn
== temp
[i
].wwn
|| !hostdata
->port_db
[j
].wwn
) {
921 if (j
== QLOGICFC_MAX_ID
+ 1)
922 printk("qlogicfc%d : Too many scsi devices, no more room in port map.\n", hostdata
->host_id
);
923 if (!hostdata
->port_db
[j
].wwn
) {
924 hostdata
->port_db
[j
].loop_id
= temp
[i
].loop_id
;
925 hostdata
->port_db
[j
].wwn
= temp
[i
].wwn
;
928 hostdata
->port_db
[i
].loop_id
= temp
[i
].loop_id
;
932 isp2x00_enable_irqs(host
);
940 #define FABRIC_PORT 0x7e
941 #define FABRIC_CONTROLLER 0x7f
942 #define FABRIC_SNS 0x80
944 int isp2x00_init_fabric(struct Scsi_Host
*host
, struct id_name_map
*port_db
, int cur_scsi_id
)
950 u_short loop_id
= 0x81;
951 u_short scsi_id
= cur_scsi_id
;
954 u_char sns_response
[608];
955 struct isp2x00_hostdata
*hostdata
;
957 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
959 DEBUG_FABRIC(printk("qlogicfc%d : Checking for a fabric.\n", hostdata
->host_id
));
960 param
[0] = MBOX_GET_PORT_NAME
;
961 param
[1] = (u16
)FABRIC_PORT
<< 8;
963 isp2x00_mbox_command(host
, param
);
965 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
966 DEBUG_FABRIC(printk("qlogicfc%d : fabric check result %x\n", hostdata
->host_id
, param
[0]));
969 printk("qlogicfc%d : Fabric found.\n", hostdata
->host_id
);
971 if (hostdata
->adapter_state
& AS_REDO_LOOP_PORTDB
){
972 memset(&req
, 0, sizeof(req
));
975 req
.response_low
= virt_to_bus_low32(sns_response
);
976 req
.response_high
= virt_to_bus_high32(sns_response
);
980 req
.data
[8] = (u_char
) (hostdata
->port_id
& 0xff);
981 req
.data
[9] = (u_char
) (hostdata
->port_id
>> 8 & 0xff);
982 req
.data
[10] = (u_char
) (hostdata
->port_id
>> 16 & 0xff);
984 param
[0] = MBOX_SEND_SNS
;
986 param
[2] = virt_to_bus_low32(&req
) >> 16;
987 param
[3] = virt_to_bus_low32(&req
);
988 param
[6] = virt_to_bus_high32(&req
) >> 16;
989 param
[7] = virt_to_bus_high32(&req
);
991 isp2x00_mbox_command(host
, param
);
993 if (param
[0] != MBOX_COMMAND_COMPLETE
)
994 printk("qlogicfc%d : error sending RFC-4\n", hostdata
->host_id
);
997 port_id
= hostdata
->port_id
;
999 memset(&req
, 0, sizeof(req
));
1002 req
.response_low
= virt_to_bus_low32(sns_response
);
1003 req
.response_high
= virt_to_bus_high32(sns_response
);
1007 req
.data
[8] = (u_char
) (port_id
& 0xff);
1008 req
.data
[9] = (u_char
) (port_id
>> 8 & 0xff);
1009 req
.data
[10] = (u_char
) (port_id
>> 16 & 0xff);
1011 param
[0] = MBOX_SEND_SNS
;
1013 param
[2] = virt_to_bus_low32(&req
) >> 16;
1014 param
[3] = virt_to_bus_low32(&req
);
1015 param
[6] = virt_to_bus_high32(&req
) >> 16;
1016 param
[7] = virt_to_bus_high32(&req
);
1018 isp2x00_mbox_command(host
, param
);
1020 if (param
[0] == MBOX_COMMAND_COMPLETE
) {
1021 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]));
1022 DEBUG_FABRIC(printk(" port id: %02x%02x%02x\n", sns_response
[17], sns_response
[18], sns_response
[19]));
1023 port_id
= ((u_int
) sns_response
[17]) << 16;
1024 port_id
|= ((u_int
) sns_response
[18]) << 8;
1025 port_id
|= ((u_int
) sns_response
[19]);
1026 wwn
= ((u64
) sns_response
[20]) << 56;
1027 wwn
|= ((u64
) sns_response
[21]) << 48;
1028 wwn
|= ((u64
) sns_response
[22]) << 40;
1029 wwn
|= ((u64
) sns_response
[23]) << 32;
1030 wwn
|= ((u64
) sns_response
[24]) << 24;
1031 wwn
|= ((u64
) sns_response
[25]) << 16;
1032 wwn
|= ((u64
) sns_response
[26]) << 8;
1033 wwn
|= ((u64
) sns_response
[27]);
1034 if (hostdata
->port_id
>> 8 != port_id
>> 8) {
1035 DEBUG_FABRIC(printk("qlogicfc%d : adding a fabric port: %x\n", hostdata
->host_id
, port_id
));
1036 param
[0] = MBOX_PORT_LOGIN
;
1037 param
[1] = loop_id
<< 8;
1038 param
[2] = (u_short
) (port_id
>> 16);
1039 param
[3] = (u_short
) (port_id
);
1041 isp2x00_mbox_command(host
, param
);
1043 if (param
[0] == MBOX_COMMAND_COMPLETE
) {
1044 port_db
[scsi_id
].wwn
= wwn
;
1045 port_db
[scsi_id
].loop_id
= loop_id
;
1049 printk("qlogicfc%d : Error performing port login %x\n", hostdata
->host_id
, param
[0]);
1050 DEBUG_FABRIC(printk("qlogicfc%d : loop_id: %x\n", hostdata
->host_id
, loop_id
));
1051 param
[0] = MBOX_PORT_LOGOUT
;
1052 param
[1] = loop_id
<< 8;
1056 isp2x00_mbox_command(host
, param
);
1061 if (hostdata
->port_id
== port_id
)
1064 printk("qlogicfc%d : Get All Next failed %x.\n", hostdata
->host_id
, param
[0]);
1072 #endif /* ISP2x00_FABRIC */
1075 int isp2x00_release(struct Scsi_Host
*host
)
1077 struct isp2x00_hostdata
*hostdata
;
1079 ENTER("isp2x00_release");
1081 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1083 outw(0x0, host
->io_port
+ PCI_INTER_CTL
);
1084 free_irq(host
->irq
, host
);
1086 release_region(host
->io_port
, 0xff);
1088 LEAVE("isp2x00_release");
1094 const char *isp2x00_info(struct Scsi_Host
*host
)
1096 static char buf
[80];
1097 struct isp2x00_hostdata
*hostdata
;
1098 ENTER("isp2x00_info");
1100 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1102 "QLogic ISP%04x SCSI on PCI bus %02x device %02x irq %d base 0x%lx",
1103 hostdata
->pci_dev
->device
, hostdata
->pci_dev
->bus
->number
, hostdata
->pci_dev
->devfn
, host
->irq
,
1107 LEAVE("isp2x00_info");
1114 * The middle SCSI layer ensures that queuecommand never gets invoked
1115 * concurrently with itself or the interrupt handler (though the
1116 * interrupt handler may call this routine as part of
1117 * request-completion handling).
1119 int isp2x00_queuecommand(Scsi_Cmnd
* Cmnd
, void (*done
) (Scsi_Cmnd
*))
1121 int i
, sg_count
, n
, num_free
;
1122 u_int in_ptr
, out_ptr
;
1124 struct scatterlist
*sg
;
1125 struct Command_Entry
*cmd
;
1126 struct Continuation_Entry
*cont
;
1127 struct Scsi_Host
*host
;
1128 struct isp2x00_hostdata
*hostdata
;
1130 ENTER("isp2x00_queuecommand");
1133 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1134 Cmnd
->scsi_done
= done
;
1136 DEBUG(isp2x00_print_scsi_cmd(Cmnd
));
1138 if (hostdata
->adapter_state
& AS_REDO_FABRIC_PORTDB
|| hostdata
->adapter_state
& AS_REDO_LOOP_PORTDB
) {
1139 isp2x00_make_portdb(host
);
1140 hostdata
->adapter_state
= AS_LOOP_GOOD
;
1141 printk("qlogicfc%d : Port Database\n", hostdata
->host_id
);
1142 for (i
= 0; hostdata
->port_db
[i
].wwn
!= 0; i
++) {
1143 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
);
1146 if (hostdata
->adapter_state
== AS_FIRMWARE_DEAD
) {
1147 printk("qlogicfc%d : The firmware is dead, just return.\n", hostdata
->host_id
);
1152 out_ptr
= inw(host
->io_port
+ MBOX4
);
1153 in_ptr
= hostdata
->req_in_ptr
;
1155 DEBUG(printk("qlogicfc%d : request queue depth %d\n", hostdata
->host_id
,
1156 REQ_QUEUE_DEPTH(in_ptr
, out_ptr
)));
1158 cmd
= (struct Command_Entry
*) &hostdata
->req
[in_ptr
][0];
1159 in_ptr
= (in_ptr
+ 1) & QLOGICFC_REQ_QUEUE_LEN
;
1160 if (in_ptr
== out_ptr
) {
1161 DEBUG(printk("qlogicfc%d : request queue overflow\n", hostdata
->host_id
));
1164 if (hostdata
->send_marker
) {
1165 struct Marker_Entry
*marker
;
1167 TRACE("queue marker", in_ptr
, 0);
1169 DEBUG(printk("qlogicfc%d : adding marker entry\n", hostdata
->host_id
));
1170 marker
= (struct Marker_Entry
*) cmd
;
1171 memset(marker
, 0, sizeof(struct Marker_Entry
));
1173 marker
->hdr
.entry_type
= ENTRY_MARKER
;
1174 marker
->hdr
.entry_cnt
= 1;
1175 marker
->modifier
= SYNC_ALL
;
1177 hostdata
->send_marker
= 0;
1179 if (((in_ptr
+ 1) & QLOGICFC_REQ_QUEUE_LEN
) == out_ptr
) {
1180 outw(in_ptr
, host
->io_port
+ MBOX4
);
1181 hostdata
->req_in_ptr
= in_ptr
;
1182 DEBUG(printk("qlogicfc%d : request queue overflow\n", hostdata
->host_id
));
1185 cmd
= (struct Command_Entry
*) &hostdata
->req
[in_ptr
][0];
1186 in_ptr
= (in_ptr
+ 1) & QLOGICFC_REQ_QUEUE_LEN
;
1188 TRACE("queue command", in_ptr
, Cmnd
);
1190 memset(cmd
, 0, sizeof(struct Command_Entry
));
1192 /* find a free handle mapping slot */
1193 for (i
= in_ptr
; i
!= (in_ptr
- 1) && hostdata
->handle_ptrs
[i
]; i
= ((i
+ 1) % (QLOGICFC_REQ_QUEUE_LEN
+ 1)));
1195 if (!hostdata
->handle_ptrs
[i
]) {
1197 hostdata
->handle_ptrs
[i
] = Cmnd
;
1198 hostdata
->handle_serials
[i
] = Cmnd
->serial_number
;
1200 printk("qlogicfc%d : no handle slots, this should not happen.\n", hostdata
->host_id
);
1201 printk("hostdata->queued is %x, in_ptr: %x\n", hostdata
->queued
, in_ptr
);
1202 for (i
= 0; i
<= QLOGICFC_REQ_QUEUE_LEN
; i
++){
1203 if (!hostdata
->handle_ptrs
[i
]){
1204 printk("slot %d has %p\n", i
, hostdata
->handle_ptrs
[i
]);
1209 cmd
->hdr
.entry_type
= ENTRY_COMMAND
;
1210 cmd
->hdr
.entry_cnt
= 1;
1211 cmd
->target_lun
= Cmnd
->lun
;
1212 cmd
->expanded_lun
= Cmnd
->lun
;
1214 cmd
->target_id
= hostdata
->port_db
[Cmnd
->target
].loop_id
;
1216 cmd
->target_id
= Cmnd
->target
;
1218 cmd
->total_byte_cnt
= (u_int
) Cmnd
->request_bufflen
;
1220 memcpy(cmd
->cdb
, Cmnd
->cmnd
, Cmnd
->cmd_len
);
1223 cmd
->segment_cnt
= sg_count
= Cmnd
->use_sg
;
1224 sg
= (struct scatterlist
*) Cmnd
->request_buffer
;
1226 /* fill in first two sg entries: */
1228 if (n
> DATASEGS_PER_COMMAND
)
1229 n
= DATASEGS_PER_COMMAND
;
1231 for (i
= 0; i
< n
; i
++) {
1232 ds
[i
].d_base
= virt_to_bus_low32(sg
->address
);
1233 #if BITS_PER_LONG > 32
1234 ds
[i
].d_base_hi
= virt_to_bus_high32(sg
->address
);
1236 ds
[i
].d_count
= sg
->length
;
1239 sg_count
-= DATASEGS_PER_COMMAND
;
1241 while (sg_count
> 0) {
1242 ++cmd
->hdr
.entry_cnt
;
1243 cont
= (struct Continuation_Entry
*)
1244 &hostdata
->req
[in_ptr
][0];
1245 memset(cont
, 0, sizeof(struct Continuation_Entry
));
1246 in_ptr
= (in_ptr
+ 1) & QLOGICFC_REQ_QUEUE_LEN
;
1247 if (in_ptr
== out_ptr
) {
1248 DEBUG(printk("qlogicfc%d : unexpected request queue overflow\n", hostdata
->host_id
));
1251 TRACE("queue continuation", in_ptr
, 0);
1252 cont
->hdr
.entry_type
= ENTRY_CONTINUATION
;
1255 if (n
> DATASEGS_PER_CONT
)
1256 n
= DATASEGS_PER_CONT
;
1257 for (i
= 0; i
< n
; ++i
) {
1258 ds
[i
].d_base
= virt_to_bus_low32(sg
->address
);
1259 #if BITS_PER_LONG > 32
1260 ds
[i
].d_base_hi
= virt_to_bus_high32(sg
->address
);
1262 ds
[i
].d_count
= sg
->length
;
1268 cmd
->dataseg
[0].d_base
= virt_to_bus_low32(Cmnd
->request_buffer
);
1269 #if BITS_PER_LONG > 32
1270 cmd
->dataseg
[0].d_base_hi
= virt_to_bus_high32(Cmnd
->request_buffer
);
1272 cmd
->dataseg
[0].d_count
= (u_int
) Cmnd
->request_bufflen
;
1273 cmd
->segment_cnt
= 1;
1276 switch (Cmnd
->cmnd
[0]) {
1277 case TEST_UNIT_READY
:
1284 cmd
->control_flags
= CFLAG_WRITE
;
1287 /* scsi.c expects sense info in a different buffer */
1288 cmd
->dataseg
[0].d_base
= virt_to_bus_low32(Cmnd
->sense_buffer
);
1289 #if BITS_PER_LONG > 32
1290 cmd
->dataseg
[0].d_base_hi
= virt_to_bus_high32(Cmnd
->request_buffer
);
1292 cmd
->segment_cnt
= 1;
1293 cmd
->control_flags
= CFLAG_READ
;
1296 cmd
->control_flags
= CFLAG_READ
;
1301 if (Cmnd
->device
->tagged_supported
) {
1302 if ((jiffies
- hostdata
->tag_ages
[Cmnd
->target
]) > (2 * SCSI_TIMEOUT
)) {
1303 cmd
->control_flags
|= CFLAG_ORDERED_TAG
;
1304 hostdata
->tag_ages
[Cmnd
->target
] = jiffies
;
1306 switch (Cmnd
->tag
) {
1307 case HEAD_OF_QUEUE_TAG
:
1308 cmd
->control_flags
|= CFLAG_HEAD_TAG
;
1310 case ORDERED_QUEUE_TAG
:
1311 cmd
->control_flags
|= CFLAG_ORDERED_TAG
;
1314 cmd
->control_flags
|= CFLAG_SIMPLE_TAG
;
1318 outw(in_ptr
, host
->io_port
+ MBOX4
);
1319 hostdata
->req_in_ptr
= in_ptr
;
1323 num_free
= QLOGICFC_REQ_QUEUE_LEN
- REQ_QUEUE_DEPTH(in_ptr
, out_ptr
);
1324 num_free
= (num_free
> 2) ? num_free
- 2 : 0;
1325 host
->can_queue
= hostdata
->queued
+ num_free
;
1326 if (host
->can_queue
> QLOGICFC_REQ_QUEUE_LEN
)
1327 host
->can_queue
= QLOGICFC_REQ_QUEUE_LEN
;
1328 host
->sg_tablesize
= QLOGICFC_MAX_SG(num_free
);
1330 /* this is really gross */
1331 if (host
->can_queue
<= host
->host_busy
){
1332 if (host
->can_queue
+2 < host
->host_busy
)
1333 DEBUG(printk("qlogicfc%d.c crosses its fingers.\n", hostdata
->host_id
));
1334 host
->can_queue
= host
->host_busy
+ 1;
1337 LEAVE("isp2x00_queuecommand");
1343 #define ASYNC_EVENT_INTERRUPT 0x01
1346 void do_isp2x00_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1348 unsigned long flags
;
1350 spin_lock_irqsave(&io_request_lock
, flags
);
1351 isp2x00_intr_handler(irq
, dev_id
, regs
);
1352 spin_unlock_irqrestore(&io_request_lock
, flags
);
1355 void isp2x00_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1358 struct Status_Entry
*sts
;
1359 struct Scsi_Host
*host
= dev_id
;
1360 struct isp2x00_hostdata
*hostdata
;
1361 u_int in_ptr
, out_ptr
, handle
, num_free
;
1364 ENTER_INTR("isp2x00_intr_handler");
1366 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1368 DEBUG_INTR(printk("qlogicfc%d : interrupt on line %d\n", hostdata
->host_id
, irq
));
1370 if (!(inw(host
->io_port
+ PCI_INTER_STS
) & 0x08)) {
1371 /* spurious interrupts can happen legally */
1372 DEBUG_INTR(printk("qlogicfc%d : got spurious interrupt\n", hostdata
->host_id
));
1375 in_ptr
= inw(host
->io_port
+ MBOX5
);
1376 out_ptr
= hostdata
->res_out_ptr
;
1378 if ((inw(host
->io_port
+ PCI_SEMAPHORE
) & ASYNC_EVENT_INTERRUPT
)) {
1379 status
= inw(host
->io_port
+ MBOX0
);
1381 DEBUG_INTR(printk("qlogicfc%d : mbox completion status: %x\n",
1382 hostdata
->host_id
, status
));
1386 case POINT_TO_POINT_UP
:
1387 printk("qlogicfc%d : link is up\n", hostdata
->host_id
);
1388 hostdata
->adapter_state
= AS_REDO_FABRIC_PORTDB
| AS_REDO_LOOP_PORTDB
;
1391 printk("qlogicfc%d : link is down\n", hostdata
->host_id
);
1392 hostdata
->adapter_state
= AS_LOOP_DOWN
;
1394 case CONNECTION_MODE
:
1395 printk("received CONNECTION_MODE irq %x\n", inw(host
->io_port
+ MBOX1
));
1397 case CHANGE_NOTIFICATION
:
1398 if (hostdata
->adapter_state
== AS_LOOP_GOOD
)
1399 hostdata
->adapter_state
= AS_REDO_FABRIC_PORTDB
;
1402 case PORT_DB_CHANGED
:
1404 if (hostdata
->adapter_state
== AS_LOOP_GOOD
)
1405 hostdata
->adapter_state
= AS_REDO_LOOP_PORTDB
;
1408 printk("qlogicfc%d : The firmware just choked.\n", hostdata
->host_id
);
1409 hostdata
->adapter_state
= AS_FIRMWARE_DEAD
;
1411 case SCSI_COMMAND_COMPLETE
:
1412 handle
= inw(host
->io_port
+ MBOX1
) | (inw(host
->io_port
+ MBOX2
) << 16);
1413 Cmnd
= hostdata
->handle_ptrs
[handle
];
1414 hostdata
->handle_ptrs
[handle
] = NULL
;
1415 hostdata
->handle_serials
[handle
] = 0;
1419 (*Cmnd
->scsi_done
) (Cmnd
);
1421 printk("qlogicfc%d.c : got a null value out of handle_ptrs, this sucks\n", hostdata
->host_id
);
1423 case MBOX_COMMAND_COMPLETE
:
1424 case INVALID_COMMAND
:
1425 case HOST_INTERFACE_ERROR
:
1428 case COMMAND_PARAM_ERROR
:
1432 hostdata
->mbox_done
= 1;
1433 outw(HCCR_CLEAR_RISC_INTR
, host
->io_port
+ HOST_HCCR
);
1436 printk("qlogicfc%d : got an unknown status? %x\n", hostdata
->host_id
, status
);
1438 outw(0x0, host
->io_port
+ PCI_SEMAPHORE
);
1440 DEBUG_INTR(printk("qlogicfc%d : response queue update\n", hostdata
->host_id
));
1441 DEBUG_INTR(printk("qlogicfc%d : response queue depth %d\n", hostdata
->host_id
, RES_QUEUE_DEPTH(in_ptr
, out_ptr
)));
1443 while (out_ptr
!= in_ptr
) {
1444 sts
= (struct Status_Entry
*) &hostdata
->res
[out_ptr
][0];
1445 out_ptr
= (out_ptr
+ 1) & RES_QUEUE_LEN
;
1447 TRACE("done", out_ptr
, Cmnd
);
1448 DEBUG_INTR(isp2x00_print_status_entry(sts
));
1449 if (sts
->hdr
.entry_type
== ENTRY_STATUS
&& (Cmnd
= hostdata
->handle_ptrs
[sts
->handle
])) {
1450 Cmnd
->result
= isp2x00_return_status(sts
);
1451 hostdata
->handle_ptrs
[sts
->handle
] = NULL
;
1455 * if any of the following are true we do not
1456 * call scsi_done. if the status is CS_ABORTED
1457 * we dont have to call done because the upper
1458 * level should already know its aborted.
1460 if (hostdata
->handle_serials
[sts
->handle
] != Cmnd
->serial_number
1461 || sts
->completion_status
== CS_ABORTED
){
1462 hostdata
->handle_serials
[sts
->handle
] = 0;
1463 outw(out_ptr
, host
->io_port
+ MBOX5
);
1467 * if we get back an error indicating the port
1468 * is not there or if the link is down and
1469 * this is a device that used to be there
1470 * allow the command to timeout.
1471 * the device may well be back in a couple of
1474 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
){
1475 outw(out_ptr
, host
->io_port
+ MBOX5
);
1479 outw(out_ptr
, host
->io_port
+ MBOX5
);
1483 if (sts
->completion_status
== CS_RESET_OCCURRED
1484 || (sts
->status_flags
& STF_BUS_RESET
))
1485 hostdata
->send_marker
= 1;
1487 memset(Cmnd
->sense_buffer
, 0, sizeof(Cmnd
->sense_buffer
));
1488 if (sts
->scsi_status
& 0x0200)
1489 memcpy(Cmnd
->sense_buffer
, sts
->req_sense_data
,
1490 sizeof(Cmnd
->sense_buffer
));
1492 outw(out_ptr
, host
->io_port
+ MBOX5
);
1494 if (Cmnd
->scsi_done
!= NULL
) {
1495 (*Cmnd
->scsi_done
) (Cmnd
);
1497 printk("qlogicfc%d : Ouch, scsi done is NULL\n", hostdata
->host_id
);
1499 hostdata
->res_out_ptr
= out_ptr
;
1503 out_ptr
= inw(host
->io_port
+ MBOX4
);
1504 in_ptr
= hostdata
->req_in_ptr
;
1506 num_free
= QLOGICFC_REQ_QUEUE_LEN
- REQ_QUEUE_DEPTH(in_ptr
, out_ptr
);
1507 num_free
= (num_free
> 2) ? num_free
- 2 : 0;
1508 host
->can_queue
= hostdata
->queued
+ num_free
;
1509 if (host
->can_queue
> QLOGICFC_REQ_QUEUE_LEN
)
1510 host
->can_queue
= QLOGICFC_REQ_QUEUE_LEN
;
1511 host
->sg_tablesize
= QLOGICFC_MAX_SG(num_free
);
1513 if (host
->can_queue
<= host
->host_busy
){
1514 if (host
->can_queue
+2 < host
->host_busy
)
1515 DEBUG(printk("qlogicfc%d : crosses its fingers.\n", hostdata
->host_id
));
1516 host
->can_queue
= host
->host_busy
+ 1;
1519 outw(HCCR_CLEAR_RISC_INTR
, host
->io_port
+ HOST_HCCR
);
1520 LEAVE_INTR("isp2x00_intr_handler");
1524 static int isp2x00_return_status(struct Status_Entry
*sts
)
1526 int host_status
= DID_ERROR
;
1527 #if DEBUG_ISP2x00_INTR
1528 static char *reason
[] =
1541 #endif /* DEBUG_ISP2x00_INTR */
1543 ENTER("isp2x00_return_status");
1545 DEBUG(printk("qlogicfc : completion status = 0x%04x\n",
1546 sts
->completion_status
));
1548 switch (sts
->completion_status
) {
1550 host_status
= DID_OK
;
1553 host_status
= DID_ERROR
;
1555 case CS_RESET_OCCURRED
:
1556 host_status
= DID_RESET
;
1559 host_status
= DID_ABORT
;
1562 host_status
= DID_TIME_OUT
;
1564 case CS_DATA_OVERRUN
:
1565 host_status
= DID_ERROR
;
1567 case CS_DATA_UNDERRUN
:
1568 host_status
= DID_OK
;
1570 case CS_PORT_UNAVAILABLE
:
1571 case CS_PORT_LOGGED_OUT
:
1572 case CS_PORT_CONFIG_CHANGED
:
1573 host_status
= DID_BAD_TARGET
;
1576 host_status
= DID_ERROR
;
1579 printk("qlogicfc : unknown completion status 0x%04x\n",
1580 sts
->completion_status
);
1581 host_status
= DID_ERROR
;
1585 DEBUG_INTR(printk("qlogicfc : host status (%s) scsi status %x\n",
1586 reason
[host_status
], sts
->scsi_status
));
1588 LEAVE("isp2x00_return_status");
1590 return (sts
->scsi_status
& STATUS_MASK
) | (host_status
<< 16);
1594 int isp2x00_abort(Scsi_Cmnd
* Cmnd
)
1598 struct Scsi_Host
*host
;
1599 struct isp2x00_hostdata
*hostdata
;
1600 int return_status
= SUCCESS
;
1602 ENTER("isp2x00_abort");
1605 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1607 for (i
= 0; i
< QLOGICFC_REQ_QUEUE_LEN
; i
++)
1608 if (hostdata
->handle_ptrs
[i
] == Cmnd
)
1611 if (i
== QLOGICFC_REQ_QUEUE_LEN
){
1615 isp2x00_disable_irqs(host
);
1617 param
[0] = MBOX_ABORT_IOCB
;
1619 param
[1] = (((u_short
) hostdata
->port_db
[Cmnd
->target
].loop_id
) << 8) | Cmnd
->lun
;
1621 param
[1] = (((u_short
) Cmnd
->target
) << 8) | Cmnd
->lun
;
1623 param
[2] = i
& 0xffff;
1626 isp2x00_mbox_command(host
, param
);
1628 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1629 printk("qlogicfc%d : scsi abort failure: %x\n", hostdata
->host_id
, param
[0]);
1630 if (param
[0] == 0x4005)
1631 Cmnd
->result
= DID_ERROR
<< 16;
1632 if (param
[0] == 0x4006)
1633 Cmnd
->result
= DID_BAD_TARGET
<< 16;
1634 return_status
= FAILED
;
1637 if (return_status
!= SUCCESS
){
1638 param
[0] = MBOX_GET_FIRMWARE_STATE
;
1639 isp2x00_mbox_command(host
, param
);
1640 printk("qlogicfc%d : abort failed\n", hostdata
->host_id
);
1641 printk("qlogicfc%d : firmware status is %x %x\n", hostdata
->host_id
, param
[0], param
[1]);
1644 isp2x00_enable_irqs(host
);
1646 LEAVE("isp2x00_abort");
1648 return return_status
;
1652 int isp2x00_reset(Scsi_Cmnd
* Cmnd
, unsigned int reset_flags
)
1655 struct Scsi_Host
*host
;
1656 struct isp2x00_hostdata
*hostdata
;
1657 int return_status
= SCSI_RESET_SUCCESS
;
1659 ENTER("isp2x00_reset");
1662 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1663 param
[0] = MBOX_BUS_RESET
;
1666 isp2x00_disable_irqs(host
);
1668 isp2x00_mbox_command(host
, param
);
1670 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1671 printk("qlogicfc%d : scsi bus reset failure: %x\n", hostdata
->host_id
, param
[0]);
1672 return_status
= SCSI_RESET_ERROR
;
1674 isp2x00_enable_irqs(host
);
1676 LEAVE("isp2x00_reset");
1678 return return_status
;;
1682 int isp2x00_biosparam(Disk
* disk
, kdev_t n
, int ip
[])
1684 int size
= disk
->capacity
;
1686 ENTER("isp2x00_biosparam");
1694 ip
[2] = size
/ (ip
[0] * ip
[1]);
1696 LEAVE("isp2x00_biosparam");
1702 static int isp2x00_reset_hardware(struct Scsi_Host
*host
)
1705 struct isp2x00_hostdata
*hostdata
;
1708 ENTER("isp2x00_reset_hardware");
1710 hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1712 outw(0x01, host
->io_port
+ ISP_CTRL_STATUS
);
1713 outw(HCCR_RESET
, host
->io_port
+ HOST_HCCR
);
1714 outw(HCCR_RELEASE
, host
->io_port
+ HOST_HCCR
);
1715 outw(HCCR_BIOS_DISABLE
, host
->io_port
+ HOST_HCCR
);
1717 loop_count
= DEFAULT_LOOP_COUNT
;
1718 while (--loop_count
&& inw(host
->io_port
+ HOST_HCCR
) == RISC_BUSY
)
1721 printk("qlogicfc%d : reset_hardware loop timeout\n", hostdata
->host_id
);
1726 printk("qlogicfc%d : mbox 0 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX0
));
1727 printk("qlogicfc%d : mbox 1 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX1
));
1728 printk("qlogicfc%d : mbox 2 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX2
));
1729 printk("qlogicfc%d : mbox 3 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX3
));
1730 printk("qlogicfc%d : mbox 4 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX4
));
1731 printk("qlogicfc%d : mbox 5 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX5
));
1732 printk("qlogicfc%d : mbox 6 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX6
));
1733 printk("qlogicfc%d : mbox 7 0x%04x \n", hostdata
->host_id
, inw(host
->io_port
+ MBOX7
));
1734 #endif /* DEBUG_ISP2x00 */
1736 DEBUG(printk("qlogicfc%d : verifying checksum\n", hostdata
->host_id
));
1741 unsigned short * risc_code
= NULL
;
1742 unsigned short risc_code_len
= 0;
1743 if (hostdata
->pci_dev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2100
){
1744 risc_code
= risc_code2100
;
1745 risc_code_len
= risc_code_length2100
;
1747 else if (hostdata
->pci_dev
->device
== PCI_DEVICE_ID_QLOGIC_ISP2200
){
1748 risc_code
= risc_code2200
;
1749 risc_code_len
= risc_code_length2200
;
1752 for (i
= 0; i
< risc_code_len
; i
++) {
1753 param
[0] = MBOX_WRITE_RAM_WORD
;
1754 param
[1] = risc_code_addr01
+ i
;
1755 param
[2] = risc_code
[i
];
1757 isp2x00_mbox_command(host
, param
);
1759 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1760 printk("qlogicfc%d : firmware load failure\n", hostdata
->host_id
);
1765 #endif /* RELOAD_FIRMWARE */
1767 param
[0] = MBOX_VERIFY_CHECKSUM
;
1768 param
[1] = risc_code_addr01
;
1770 isp2x00_mbox_command(host
, param
);
1772 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1773 printk("qlogicfc%d : ram checksum failure\n", hostdata
->host_id
);
1776 DEBUG(printk("qlogicfc%d : executing firmware\n", hostdata
->host_id
));
1778 param
[0] = MBOX_EXEC_FIRMWARE
;
1779 param
[1] = risc_code_addr01
;
1781 isp2x00_mbox_command(host
, param
);
1783 param
[0] = MBOX_ABOUT_FIRMWARE
;
1785 isp2x00_mbox_command(host
, param
);
1787 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1788 printk("qlogicfc%d : about firmware failure\n", hostdata
->host_id
);
1791 DEBUG(printk("qlogicfc%d : firmware major revision %d\n", hostdata
->host_id
, param
[1]));
1792 DEBUG(printk("qlogicfc%d : firmware minor revision %d\n", hostdata
->host_id
, param
[2]));
1794 #ifdef USE_NVRAM_DEFAULTS
1796 if (isp2x00_get_nvram_defaults(host
, &hostdata
->control_block
) != 0) {
1797 printk("qlogicfc%d : Could not read from NVRAM\n", hostdata
->host_id
);
1801 hostdata
->wwn
= (u64
) (hostdata
->control_block
.node_name
[0]) << 56;
1802 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[0] & 0xff00) << 48;
1803 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[1] & 0xff00) << 24;
1804 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[1] & 0x00ff) << 48;
1805 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[2] & 0x00ff) << 24;
1806 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[2] & 0xff00) << 8;
1807 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[3] & 0x00ff) << 8;
1808 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[3] & 0xff00) >> 8;
1810 param
[0] = MBOX_INIT_FIRMWARE
;
1811 param
[2] = (u_short
) (virt_to_bus_low32(&hostdata
->control_block
) >> 16);
1812 param
[3] = (u_short
) (virt_to_bus_low32(&hostdata
->control_block
) & 0xffff);
1815 param
[6] = (u_short
) (virt_to_bus_high32(&hostdata
->control_block
) >> 16);
1816 param
[7] = (u_short
) (virt_to_bus_high32(&hostdata
->control_block
) & 0xffff);
1817 isp2x00_mbox_command(host
, param
);
1818 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1819 printk("qlogicfc%d.c: Ouch 0x%04x\n", hostdata
->host_id
, param
[0]);
1822 param
[0] = MBOX_GET_FIRMWARE_STATE
;
1823 isp2x00_mbox_command(host
, param
);
1824 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1825 printk("qlogicfc%d.c: 0x%04x\n", hostdata
->host_id
, param
[0]);
1829 LEAVE("isp2x00_reset_hardware");
1834 #ifdef USE_NVRAM_DEFAULTS
1836 static int isp2x00_get_nvram_defaults(struct Scsi_Host
*host
, struct init_cb
*control_block
)
1840 if (isp2x00_read_nvram_word(host
, 0) != 0x5349)
1843 value
= isp2x00_read_nvram_word(host
, 8);
1844 control_block
->node_name
[0] = isp2x00_read_nvram_word(host
, 9);
1845 control_block
->node_name
[1] = isp2x00_read_nvram_word(host
, 10);
1846 control_block
->node_name
[2] = isp2x00_read_nvram_word(host
, 11);
1847 control_block
->node_name
[3] = isp2x00_read_nvram_word(host
, 12);
1848 control_block
->hard_addr
= isp2x00_read_nvram_word(host
, 13);
1856 static int isp2x00_init(struct Scsi_Host
*sh
)
1859 struct isp2x00_hostdata
*hostdata
;
1863 struct pci_dev
*pdev
;
1866 ENTER("isp2x00_init");
1868 hostdata
= (struct isp2x00_hostdata
*) sh
->hostdata
;
1869 pdev
= hostdata
->pci_dev
;
1871 if (pci_read_config_word(pdev
, PCI_COMMAND
, &command
)
1872 || pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &revision
)) {
1873 printk("qlogicfc%d : error reading PCI configuration\n", hostdata
->host_id
);
1876 io_base
= pdev
->resource
[0].start
;
1880 if (pdev
->vendor
!= PCI_VENDOR_ID_QLOGIC
) {
1881 printk("qlogicfc%d : 0x%04x is not QLogic vendor ID\n", hostdata
->host_id
,
1885 if (pdev
->device
!= PCI_DEVICE_ID_QLOGIC_ISP2100
&& pdev
->device
!= PCI_DEVICE_ID_QLOGIC_ISP2200
) {
1886 printk("qlogicfc%d : 0x%04x does not match ISP2100 or ISP2200 device id\n", hostdata
->host_id
,
1890 if (!(command
& PCI_COMMAND_IO
) ||
1891 !(pdev
->resource
[0].flags
& IORESOURCE_IO
)) {
1892 printk("qlogicfc%d : i/o mapping is disabled\n", hostdata
->host_id
);
1896 if (!(command
& PCI_COMMAND_MASTER
)) {
1897 printk("qlogicfc%d : bus mastering is disabled\n", hostdata
->host_id
);
1900 if (revision
!= ISP2100_REV_ID1
&& revision
!= ISP2100_REV_ID3
&& revision
!= ISP2200_REV_ID5
)
1901 printk("qlogicfc%d : new isp2x00 revision ID (%d)\n", hostdata
->host_id
, revision
);
1904 hostdata
->revision
= revision
;
1907 sh
->io_port
= io_base
;
1909 LEAVE("isp2x00_init");
1914 #if USE_NVRAM_DEFAULTS
1916 #define NVRAM_DELAY() udelay(10) /* 10 microsecond delay */
1919 u_short
isp2x00_read_nvram_word(struct Scsi_Host
* host
, u_short byte
)
1922 u_short value
, output
, input
;
1924 outw(0x2, host
->io_port
+ PCI_NVRAM
);
1926 outw(0x3, host
->io_port
+ PCI_NVRAM
);
1931 for (i
= 10; i
>= 0; i
--) {
1932 output
= ((byte
>> i
) & 0x1) ? 0x4 : 0x0;
1933 outw(output
| 0x2, host
->io_port
+ PCI_NVRAM
);
1935 outw(output
| 0x3, host
->io_port
+ PCI_NVRAM
);
1937 outw(output
| 0x2, host
->io_port
+ PCI_NVRAM
);
1941 for (i
= 0xf, value
= 0; i
>= 0; i
--) {
1943 outw(0x3, host
->io_port
+ PCI_NVRAM
);
1945 input
= inw(host
->io_port
+ PCI_NVRAM
);
1947 outw(0x2, host
->io_port
+ PCI_NVRAM
);
1953 outw(0x0, host
->io_port
+ PCI_NVRAM
);
1960 #endif /* USE_NVRAM_DEFAULTS */
1965 * currently, this is only called during initialization or abort/reset,
1966 * at which times interrupts are disabled, so polling is OK, I guess...
1968 static int isp2x00_mbox_command(struct Scsi_Host
*host
, u_short param
[])
1971 struct isp2x00_hostdata
*hostdata
= (struct isp2x00_hostdata
*) host
->hostdata
;
1973 if (mbox_param
[param
[0]] == 0 || hostdata
->adapter_state
== AS_FIRMWARE_DEAD
)
1976 loop_count
= DEFAULT_LOOP_COUNT
;
1977 while (--loop_count
&& inw(host
->io_port
+ HOST_HCCR
) & 0x0080)
1980 printk("qlogicfc%d : mbox_command loop timeout #1\n", hostdata
->host_id
);
1982 hostdata
->adapter_state
= AS_FIRMWARE_DEAD
;
1985 hostdata
->mbox_done
= 0;
1987 if (mbox_param
[param
[0]] == 0)
1988 printk("qlogicfc%d : invalid mbox command\n", hostdata
->host_id
);
1990 if (mbox_param
[param
[0]] & 0x80)
1991 outw(param
[7], host
->io_port
+ MBOX7
);
1992 if (mbox_param
[param
[0]] & 0x40)
1993 outw(param
[6], host
->io_port
+ MBOX6
);
1994 if (mbox_param
[param
[0]] & 0x20)
1995 outw(param
[5], host
->io_port
+ MBOX5
);
1996 if (mbox_param
[param
[0]] & 0x10)
1997 outw(param
[4], host
->io_port
+ MBOX4
);
1998 if (mbox_param
[param
[0]] & 0x08)
1999 outw(param
[3], host
->io_port
+ MBOX3
);
2000 if (mbox_param
[param
[0]] & 0x04)
2001 outw(param
[2], host
->io_port
+ MBOX2
);
2002 if (mbox_param
[param
[0]] & 0x02)
2003 outw(param
[1], host
->io_port
+ MBOX1
);
2004 if (mbox_param
[param
[0]] & 0x01)
2005 outw(param
[0], host
->io_port
+ MBOX0
);
2008 outw(HCCR_SET_HOST_INTR
, host
->io_port
+ HOST_HCCR
);
2011 loop_count
= DEFAULT_LOOP_COUNT
;
2012 while (--loop_count
&& !(inw(host
->io_port
+ PCI_INTER_STS
) & 0x08)) {
2017 hostdata
->adapter_state
= AS_FIRMWARE_DEAD
;
2018 printk("qlogicfc%d : mbox_command loop timeout #2\n", hostdata
->host_id
);
2021 isp2x00_intr_handler(host
->irq
, host
, NULL
);
2023 if (hostdata
->mbox_done
== 1)
2028 loop_count
= DEFAULT_LOOP_COUNT
;
2029 while (--loop_count
&& inw(host
->io_port
+ MBOX0
) == 0x04) {
2033 printk("qlogicfc%d : mbox_command loop timeout #3\n", hostdata
->host_id
);
2035 param
[7] = inw(host
->io_port
+ MBOX7
);
2036 param
[6] = inw(host
->io_port
+ MBOX6
);
2037 param
[5] = inw(host
->io_port
+ MBOX5
);
2038 param
[4] = inw(host
->io_port
+ MBOX4
);
2039 param
[3] = inw(host
->io_port
+ MBOX3
);
2040 param
[2] = inw(host
->io_port
+ MBOX2
);
2041 param
[1] = inw(host
->io_port
+ MBOX1
);
2042 param
[0] = inw(host
->io_port
+ MBOX0
);
2045 outw(0x0, host
->io_port
+ PCI_SEMAPHORE
);
2047 if (inw(host
->io_port
+ HOST_HCCR
) & 0x0080) {
2048 hostdata
->adapter_state
= AS_FIRMWARE_DEAD
;
2049 printk("qlogicfc%d : mbox op is still pending\n", hostdata
->host_id
);
2054 #if DEBUG_ISP2x00_INTR
2056 void isp2x00_print_status_entry(struct Status_Entry
*status
)
2058 printk("qlogicfc : entry count = 0x%02x, type = 0x%02x, flags = 0x%02x\n",
2059 status
->hdr
.entry_cnt
, status
->hdr
.entry_type
, status
->hdr
.flags
);
2060 printk("qlogicfc : scsi status = 0x%04x, completion status = 0x%04x\n",
2061 status
->scsi_status
, status
->completion_status
);
2062 printk("qlogicfc : state flags = 0x%04x, status flags = 0x%04x\n",
2063 status
->state_flags
, status
->status_flags
);
2064 printk("qlogicfc : response info length = 0x%04x, request sense length = 0x%04x\n",
2065 status
->res_info_len
, status
->req_sense_len
);
2066 printk("qlogicfc : residual transfer length = 0x%08x, response = 0x%02x\n", status
->residual
, status
->res_info
[3]);
2070 #endif /* DEBUG_ISP2x00_INTR */
2075 void isp2x00_print_scsi_cmd(Scsi_Cmnd
* cmd
)
2079 printk("qlogicfc : target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
2080 cmd
->target
, cmd
->lun
, cmd
->cmd_len
);
2081 printk("qlogicfc : command = ");
2082 for (i
= 0; i
< cmd
->cmd_len
; i
++)
2083 printk("0x%02x ", cmd
->cmnd
[i
]);
2087 #endif /* DEBUG_ISP2x00 */
2092 Scsi_Host_Template driver_template
= QLOGICFC
;
2094 #include "scsi_module.c"