2 * QLogic ISP2100 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
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>
58 #include <asm/spinlock.h>
64 /* Configuration section **************************************************** */
66 /* Set the following macro to 1 to reload the ISP2100's firmware. This is
67 version 1.15.19 of the firmware. */
69 #define RELOAD_FIRMWARE 1
71 #define USE_NVRAM_DEFAULTS 1
73 #define ISP2100_PORTDB 1
75 /* Set the following to 1 to include fabric support, fabric support is
76 * currently not as well tested as the other aspects of the driver */
78 #define ISP2100_FABRIC 0
80 /* Macros used for debugging */
82 #define DEBUG_ISP2100 1
83 #define DEBUG_ISP2100_INT 1
84 #define DEBUG_ISP2100_INTR 1
85 #define DEBUG_ISP2100_SETUP 1
87 #define DEBUG_ISP2100_FABRIC 1
89 /* #define TRACE_ISP 1 */
92 #define DEFAULT_LOOP_COUNT 10000000
94 /* End Configuration section ************************************************ */
96 #include <linux/module.h>
100 #define TRACE_BUF_LEN (32*1024)
109 } buf
[TRACE_BUF_LEN
];
112 #define TRACE(w, i, a) \
114 unsigned long flags; \
118 trace.buf[trace.next].name = (w); \
119 trace.buf[trace.next].time = jiffies; \
120 trace.buf[trace.next].index = (i); \
121 trace.buf[trace.next].addr = (long) (a); \
122 trace.next = (trace.next + 1) & (TRACE_BUF_LEN - 1); \
123 restore_flags(flags); \
127 #define TRACE(w, i, a)
130 #if DEBUG_ISP2100_FABRIC
131 #define DEBUG_FABRIC(x) x
133 #define DEBUG_FABRIC(x)
134 #endif /* DEBUG_ISP2100_FABRIC */
138 #define ENTER(x) printk("isp2100 : entering %s()\n", x);
139 #define LEAVE(x) printk("isp2100 : leaving %s()\n", x);
145 #endif /* DEBUG_ISP2100 */
147 #if DEBUG_ISP2100_INTR
148 #define ENTER_INTR(x) printk("isp2100 : entering %s()\n", x);
149 #define LEAVE_INTR(x) printk("isp2100 : leaving %s()\n", x);
150 #define DEBUG_INTR(x) x
152 #define ENTER_INTR(x)
153 #define LEAVE_INTR(x)
154 #define DEBUG_INTR(x)
155 #endif /* DEBUG ISP2100_INTR */
158 #if defined(__i386__)
159 #define virt_to_bus_low32(x) virt_to_bus(x)
160 #define virt_to_bus_high32(x) 0x0
161 #define bus_to_virt_low32(x) bus_to_virt(x)
162 #define bus_to_virt_high32(x) 0x0
163 #elif defined(__alpha__)
164 #define virt_to_bus_low32(x) ((u32) (0xffffffff & virt_to_bus(x)))
165 #define virt_to_bus_high32(x) ((u32) (0xffffffff & (virt_to_bus(x)>>32)))
166 #define bus_to_virt_low32(x) ((u32) (0xffffffff & bus_to_virt(x)))
167 #define bus_to_virt_high32(x) ((u32) (0xffffffff & (bus_to_virt(x)>>32)))
170 #define ISP2100_REV_ID 1
171 #define ISP2100_REV_ID3 3
173 #define MAX_TARGETS 16
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
223 struct Entry_header
{
230 /* entry header type commands */
231 #define ENTRY_COMMAND 0x19
232 #define ENTRY_CONTINUATION 0x0a
233 #define ENTRY_STATUS 0x03
234 #define ENTRY_MARKER 0x04
236 /* entry header flag definitions */
238 #define EFLAG_BAD_HEADER 4
239 #define EFLAG_BAD_PAYLOAD 8
247 struct Command_Entry
{
248 struct Entry_header hdr
;
253 u_short control_flags
;
258 u_int total_byte_cnt
;
259 struct dataseg dataseg
[2];
262 /* command entry control flag definitions */
263 #define CFLAG_NODISC 0x01
264 #define CFLAG_HEAD_TAG 0x02
265 #define CFLAG_ORDERED_TAG 0x04
266 #define CFLAG_SIMPLE_TAG 0x08
267 #define CFLAG_TAR_RTN 0x10
268 #define CFLAG_READ 0x20
269 #define CFLAG_WRITE 0x40
271 struct Ext_Command_Entry
{
272 struct Entry_header hdr
;
277 u_short control_flags
;
284 struct Continuation_Entry
{
285 struct Entry_header hdr
;
286 struct dataseg dataseg
[5];
289 struct Marker_Entry
{
290 struct Entry_header hdr
;
299 /* marker entry modifier definitions */
300 #define SYNC_DEVICE 0
301 #define SYNC_TARGET 1
304 struct Status_Entry
{
305 struct Entry_header hdr
;
308 u_short completion_status
;
310 u_short status_flags
;
311 u_short res_info_len
;
312 u_short req_sense_len
;
315 u_char req_sense_data
[32];
318 /* status entry completion status definitions */
319 #define CS_COMPLETE 0x0000
320 #define CS_DMA_ERROR 0x0002
321 #define CS_RESET_OCCURRED 0x0004
322 #define CS_ABORTED 0x0005
323 #define CS_TIMEOUT 0x0006
324 #define CS_DATA_OVERRUN 0x0007
325 #define CS_DATA_UNDERRUN 0x0015
326 #define CS_QUEUE_FULL 0x001c
327 #define CS_PORT_UNAVAILABLE 0x0028
328 #define CS_PORT_LOGGED_OUT 0x0029
329 #define CS_PORT_CONFIG_CHANGED 0x002a
331 /* status entry state flag definitions */
332 #define SF_SENT_CDB 0x0400
333 #define SF_TRANSFERRED_DATA 0x0800
334 #define SF_GOT_STATUS 0x1000
336 /* status entry status flag definitions */
337 #define STF_BUS_RESET 0x0008
338 #define STF_DEVICE_RESET 0x0010
339 #define STF_ABORTED 0x0020
340 #define STF_TIMEOUT 0x0040
342 /* interupt control commands */
343 #define ISP_EN_INT 0x8000
344 #define ISP_EN_RISC 0x0008
346 /* host control commands */
347 #define HCCR_NOP 0x0000
348 #define HCCR_RESET 0x1000
349 #define HCCR_PAUSE 0x2000
350 #define HCCR_RELEASE 0x3000
351 #define HCCR_SINGLE_STEP 0x4000
352 #define HCCR_SET_HOST_INTR 0x5000
353 #define HCCR_CLEAR_HOST_INTR 0x6000
354 #define HCCR_CLEAR_RISC_INTR 0x7000
355 #define HCCR_BP_ENABLE 0x8000
356 #define HCCR_BIOS_DISABLE 0x9000
357 #define HCCR_TEST_MODE 0xf000
359 #define RISC_BUSY 0x0004
361 /* mailbox commands */
362 #define MBOX_NO_OP 0x0000
363 #define MBOX_LOAD_RAM 0x0001
364 #define MBOX_EXEC_FIRMWARE 0x0002
365 #define MBOX_DUMP_RAM 0x0003
366 #define MBOX_WRITE_RAM_WORD 0x0004
367 #define MBOX_READ_RAM_WORD 0x0005
368 #define MBOX_MAILBOX_REG_TEST 0x0006
369 #define MBOX_VERIFY_CHECKSUM 0x0007
370 #define MBOX_ABOUT_FIRMWARE 0x0008
371 #define MBOX_LOAD_RISC_RAM 0x0009
372 #define MBOX_DUMP_RISC_RAM 0x000a
373 #define MBOX_CHECK_FIRMWARE 0x000e
374 #define MBOX_INIT_REQ_QUEUE 0x0010
375 #define MBOX_INIT_RES_QUEUE 0x0011
376 #define MBOX_EXECUTE_IOCB 0x0012
377 #define MBOX_WAKE_UP 0x0013
378 #define MBOX_STOP_FIRMWARE 0x0014
379 #define MBOX_ABORT_IOCB 0x0015
380 #define MBOX_ABORT_DEVICE 0x0016
381 #define MBOX_ABORT_TARGET 0x0017
382 #define MBOX_BUS_RESET 0x0018
383 #define MBOX_STOP_QUEUE 0x0019
384 #define MBOX_START_QUEUE 0x001a
385 #define MBOX_SINGLE_STEP_QUEUE 0x001b
386 #define MBOX_ABORT_QUEUE 0x001c
387 #define MBOX_GET_DEV_QUEUE_STATUS 0x001d
388 #define MBOX_GET_FIRMWARE_STATUS 0x001f
389 #define MBOX_GET_INIT_SCSI_ID 0x0020
390 #define MBOX_GET_RETRY_COUNT 0x0022
391 #define MBOX_GET_TARGET_PARAMS 0x0028
392 #define MBOX_GET_DEV_QUEUE_PARAMS 0x0029
393 #define MBOX_SET_RETRY_COUNT 0x0032
394 #define MBOX_SET_TARGET_PARAMS 0x0038
395 #define MBOX_SET_DEV_QUEUE_PARAMS 0x0039
396 #define MBOX_EXECUTE_IOCB64 0x0054
397 #define MBOX_INIT_FIRMWARE 0x0060
398 #define MBOX_GET_INIT_CB 0x0061
399 #define MBOX_INIT_LIP 0x0062
400 #define MBOX_GET_POS_MAP 0x0063
401 #define MBOX_GET_PORT_DB 0x0064
402 #define MBOX_CLEAR_ACA 0x0065
403 #define MBOX_TARGET_RESET 0x0066
404 #define MBOX_CLEAR_TASK_SET 0x0067
405 #define MBOX_ABORT_TASK_SET 0x0068
406 #define MBOX_GET_FIRMWARE_STATE 0x0069
407 #define MBOX_GET_PORT_NAME 0x006a
408 #define MBOX_SEND_SNS 0x006e
409 #define MBOX_PORT_LOGIN 0x006f
410 #define MBOX_SEND_CHANGE_REQUEST 0x0070
411 #define MBOX_PORT_LOGOUT 0x0071
413 #include "qlogicfc_asm.c"
415 /* Each element in mbox_param is an 8 bit bitmap where each bit indicates
416 if that mbox should be copied as input. For example 0x2 would mean
419 const u_char mbox_param
[] =
421 0x01, /* MBOX_NO_OP */
422 0x1f, /* MBOX_LOAD_RAM */
423 0x03, /* MBOX_EXEC_FIRMWARE */
424 0x1f, /* MBOX_DUMP_RAM */
425 0x07, /* MBOX_WRITE_RAM_WORD */
426 0x03, /* MBOX_READ_RAM_WORD */
427 0xff, /* MBOX_MAILBOX_REG_TEST */
428 0x03, /* MBOX_VERIFY_CHECKSUM */
429 0x01, /* MBOX_ABOUT_FIRMWARE */
430 0xff, /* MBOX_LOAD_RISC_RAM */
431 0xff, /* MBOX_DUMP_RISC_RAM */
435 0x01, /* MBOX_CHECK_FIRMWARE */
437 0x1f, /* MBOX_INIT_REQ_QUEUE */
438 0x2f, /* MBOX_INIT_RES_QUEUE */
439 0x0f, /* MBOX_EXECUTE_IOCB */
440 0x03, /* MBOX_WAKE_UP */
441 0x01, /* MBOX_STOP_FIRMWARE */
442 0x0f, /* MBOX_ABORT_IOCB */
443 0x03, /* MBOX_ABORT_DEVICE */
444 0x07, /* MBOX_ABORT_TARGET */
445 0x03, /* MBOX_BUS_RESET */
446 0x03, /* MBOX_STOP_QUEUE */
447 0x03, /* MBOX_START_QUEUE */
448 0x03, /* MBOX_SINGLE_STEP_QUEUE */
449 0x03, /* MBOX_ABORT_QUEUE */
450 0x03, /* MBOX_GET_DEV_QUEUE_STATUS */
452 0x01, /* MBOX_GET_FIRMWARE_STATUS */
453 0x01, /* MBOX_GET_INIT_SCSI_ID */
455 0x01, /* MBOX_GET_RETRY_COUNT */
461 0x03, /* MBOX_GET_TARGET_PARAMS */
462 0x03, /* MBOX_GET_DEV_QUEUE_PARAMS */
471 0x07, /* MBOX_SET_RETRY_COUNT */
477 0x0f, /* MBOX_SET_TARGET_PARAMS */
478 0x0f, /* MBOX_SET_DEV_QUEUE_PARAMS */
505 0xcf, /* MBOX_EXECUTE_IOCB64 */
517 0xff, /* MBOX_INIT_FIRMWARE */
518 0xcd, /* MBOX_GET_INIT_CB */
519 0x01, /* MBOX_INIT_LIP */
520 0xcd, /* MBOX_GET_POS_MAP */
521 0xcf, /* MBOX_GET_PORT_DB */
522 0x03, /* MBOX_CLEAR_ACA */
523 0x03, /* MBOX_TARGET_RESET */
524 0x03, /* MBOX_CLEAR_TASK_SET */
525 0x03, /* MBOX_ABORT_TASK_SET */
526 0x01, /* MBOX_GET_FIRMWARE_STATE */
527 0x03, /* MBOX_GET_PORT_NAME */
531 0xcf, /* MBOX_SEND_SNS */
532 0x0f, /* MBOX_PORT_LOGIN */
533 0x03, /* MBOX_SEND_CHANGE_REQUEST */
534 0x03, /* MBOX_PORT_LOGOUT */
537 #define MAX_MBOX_COMMAND (sizeof(mbox_param)/sizeof(u_short))
555 /* address of instance of this struct is passed to adapter to initialize things
561 u_short max_frame_len
;
563 u_short exec_throttle
;
566 u_short node_name
[4];
568 u_char reserved2
[10];
569 u_short req_queue_out
;
570 u_short res_queue_in
;
571 u_short req_queue_len
;
572 u_short res_queue_len
;
573 u_int req_queue_addr_lo
;
574 u_int req_queue_addr_high
;
575 u_int res_queue_addr_lo
;
576 u_int res_queue_addr_high
;
580 * The result queue can be quite a bit smaller since continuation entries
581 * do not show up there:
583 #define RES_QUEUE_LEN ((QLOGICFC_REQ_QUEUE_LEN + 1) / 8 - 1)
584 #define QUEUE_ENTRY_LEN 64
587 #define QLOGICFC_MAX_ID 0xff
589 #define QLOGICFC_MAX_ID 0x80
592 struct isp2100_hostdata
{
594 struct pci_dev
*pci_dev
;
595 /* result and request queues (shared with isp2100): */
596 u_int req_in_ptr
; /* index of next request slot */
597 u_int res_out_ptr
; /* index of next result slot */
599 /* this is here so the queues are nicely aligned */
600 long send_marker
; /* do we need to send a marker? */
602 char res
[RES_QUEUE_LEN
+ 1][QUEUE_ENTRY_LEN
];
603 char req
[QLOGICFC_REQ_QUEUE_LEN
+ 1][QUEUE_ENTRY_LEN
];
604 struct init_cb control_block
;
606 unsigned long int tag_ages
[126];
607 Scsi_Cmnd
*handle_ptrs
[QLOGICFC_REQ_QUEUE_LEN
+ 1];
608 unsigned long handle_serials
[QLOGICFC_REQ_QUEUE_LEN
+ 1];
609 struct id_name_map port_db
[QLOGICFC_MAX_ID
+ 1];
617 /* queue length's _must_ be power of two: */
618 #define QUEUE_DEPTH(in, out, ql) ((in - out) & (ql))
619 #define REQ_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, \
620 QLOGICFC_REQ_QUEUE_LEN)
621 #define RES_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, RES_QUEUE_LEN)
623 static void isp2100_enable_irqs(struct Scsi_Host
*);
624 static void isp2100_disable_irqs(struct Scsi_Host
*);
625 static int isp2100_init(struct Scsi_Host
*);
626 static int isp2100_reset_hardware(struct Scsi_Host
*);
627 static int isp2100_mbox_command(struct Scsi_Host
*, u_short
[]);
628 static int isp2100_return_status(struct Status_Entry
*);
629 static void isp2100_intr_handler(int, void *, struct pt_regs
*);
630 static void do_isp2100_intr_handler(int, void *, struct pt_regs
*);
631 static int isp2100_make_portdb(struct Scsi_Host
*);
634 static int isp2100_init_fabric(struct Scsi_Host
*, struct id_name_map
*, int);
637 #if USE_NVRAM_DEFAULTS
638 static int isp2100_get_nvram_defaults(struct Scsi_Host
*, struct init_cb
*);
639 static u_short
isp2100_read_nvram_word(struct Scsi_Host
*, u_short
);
643 static void isp2100_print_scsi_cmd(Scsi_Cmnd
*);
646 static void isp2100_print_status_entry(struct Status_Entry
*);
648 static struct proc_dir_entry proc_scsi_isp2100
=
650 PROC_SCSI_QLOGICFC
, 7, "isp2100",
651 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
655 static inline void isp2100_enable_irqs(struct Scsi_Host
*host
)
657 outw(ISP_EN_INT
| ISP_EN_RISC
, host
->io_port
+ PCI_INTER_CTL
);
661 static inline void isp2100_disable_irqs(struct Scsi_Host
*host
)
663 outw(0x0, host
->io_port
+ PCI_INTER_CTL
);
667 int isp2100_detect(Scsi_Host_Template
* tmpt
)
671 struct Scsi_Host
*host
= NULL
;
672 struct isp2100_hostdata
*hostdata
;
673 struct pci_dev
*pdev
= NULL
;
675 ENTER("isp2100_detect");
677 tmpt
->proc_dir
= &proc_scsi_isp2100
;
679 if (pci_present() == 0) {
680 printk("qlogicfc : PCI not present\n");
683 while ((pdev
= pci_find_device(PCI_VENDOR_ID_QLOGIC
, PCI_DEVICE_ID_QLOGIC_ISP2100
, pdev
))) {
685 host
= scsi_register(tmpt
, sizeof(struct isp2100_hostdata
));
686 host
->max_id
= QLOGICFC_MAX_ID
+ 1;
687 host
->hostt
->use_new_eh_code
= 1;
688 hostdata
= (struct isp2100_hostdata
*) host
->hostdata
;
690 memset(hostdata
, 0, sizeof(struct isp2100_hostdata
));
691 hostdata
->pci_dev
= pdev
;
693 hostdata
->queued
= 0;
694 /* set up the control block */
695 hostdata
->control_block
.version
= 0x0f;
696 hostdata
->control_block
.firm_opts
= 0x010c;
697 hostdata
->control_block
.max_frame_len
= 2048;
698 hostdata
->control_block
.max_iocb
= 256;
699 hostdata
->control_block
.exec_throttle
= 8;
700 hostdata
->control_block
.retry_delay
= 5;
701 hostdata
->control_block
.retry_cnt
= 0;
702 hostdata
->control_block
.node_name
[0] = 0x0020;
703 hostdata
->control_block
.node_name
[1] = 0xE000;
704 hostdata
->control_block
.node_name
[2] = 0x008B;
705 hostdata
->control_block
.node_name
[3] = 0x0000;
706 hostdata
->control_block
.hard_addr
= 0x0003;
707 hostdata
->control_block
.req_queue_len
= QLOGICFC_REQ_QUEUE_LEN
+ 1;
708 hostdata
->control_block
.res_queue_len
= RES_QUEUE_LEN
+ 1;
709 hostdata
->control_block
.res_queue_addr_lo
= virt_to_bus_low32(&hostdata
->res
);
710 hostdata
->control_block
.res_queue_addr_high
= virt_to_bus_high32(&hostdata
->res
);
711 hostdata
->control_block
.req_queue_addr_lo
= virt_to_bus_low32(&hostdata
->req
);
712 hostdata
->control_block
.req_queue_addr_high
= virt_to_bus_high32(&hostdata
->req
);
714 hostdata
->loop_up
= 0;
716 if (isp2100_init(host
) || isp2100_reset_hardware(host
)) {
717 scsi_unregister(host
);
722 if (request_irq(host
->irq
, do_isp2100_intr_handler
, SA_INTERRUPT
| SA_SHIRQ
, "qlogicfc", host
)) {
723 printk("qlogicfc : interrupt %d already in use\n",
725 scsi_unregister(host
);
728 if (check_region(host
->io_port
, 0xff)) {
729 printk("qlogicfc : i/o region 0x%lx-0x%lx already "
731 host
->io_port
, host
->io_port
+ 0xff);
732 free_irq(host
->irq
, host
);
733 scsi_unregister(host
);
736 request_region(host
->io_port
, 0xff, "qlogicfc");
738 outw(0x0, host
->io_port
+ PCI_SEMAPHORE
);
739 outw(HCCR_CLEAR_RISC_INTR
, host
->io_port
+ HOST_HCCR
);
740 isp2100_enable_irqs(host
);
741 /* wait for the loop to come up */
742 for (wait_time
= jiffies
+ 10 * HZ
; wait_time
> jiffies
&& hostdata
->loop_up
== 0;)
745 if (hostdata
->loop_up
== 0) {
746 printk("qlogicfc: loop is not up\n");
747 release_region(host
->io_port
, 0xff);
748 free_irq(host
->irq
, host
);
749 scsi_unregister(host
);
756 /* this busy loop should not be needed but the isp2100 seems to need
757 some time before recognizing it is attached to a fabric */
760 for (wait_time
= jiffies
+ 5 * HZ
; wait_time
> jiffies
;)
764 LEAVE("isp2100_detect");
770 static int isp2100_make_portdb(struct Scsi_Host
*host
)
775 struct id_name_map temp
[QLOGICFC_MAX_ID
+ 1];
776 struct isp2100_hostdata
*hostdata
;
778 isp2100_disable_irqs(host
);
780 memset(temp
, 0, sizeof(temp
));
781 hostdata
= (struct isp2100_hostdata
*) host
->hostdata
;
784 for (i
= 0x81; i
< QLOGICFC_MAX_ID
; i
++) {
785 param
[0] = MBOX_PORT_LOGOUT
;
790 isp2100_mbox_command(host
, param
);
792 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
793 printk("logout failed %x %x\n", i
, param
[0]);
799 param
[0] = MBOX_GET_INIT_SCSI_ID
;
801 isp2100_mbox_command(host
, param
);
803 if (param
[0] == MBOX_COMMAND_COMPLETE
) {
804 hostdata
->port_id
= ((u_int
) param
[3]) << 16;
805 hostdata
->port_id
|= param
[2];
806 temp
[0].loop_id
= param
[1];
807 temp
[0].wwn
= hostdata
->wwn
;
810 printk("qlogicfc: error getting scsi id.\n");
813 for (i
= 1, j
= 1; i
<= QLOGICFC_MAX_ID
; i
++) {
814 temp
[i
].loop_id
= temp
[0].loop_id
;
816 param
[0] = MBOX_GET_PORT_NAME
;
817 param
[1] = (i
<< 8) & 0xff00;
819 isp2100_mbox_command(host
, param
);
821 if (param
[0] == MBOX_COMMAND_COMPLETE
) {
823 temp
[j
].wwn
= ((u64
) (param
[2] & 0xff)) << 56;
824 temp
[j
].wwn
|= ((u64
) ((param
[2] >> 8) & 0xff)) << 48;
825 temp
[j
].wwn
|= ((u64
) (param
[3] & 0xff)) << 40;
826 temp
[j
].wwn
|= ((u64
) ((param
[3] >> 8) & 0xff)) << 32;
827 temp
[j
].wwn
|= ((u64
) (param
[6] & 0xff)) << 24;
828 temp
[j
].wwn
|= ((u64
) ((param
[6] >> 8) & 0xff)) << 16;
829 temp
[j
].wwn
|= ((u64
) (param
[7] & 0xff)) << 8;
830 temp
[j
].wwn
|= ((u64
) ((param
[7] >> 8) & 0xff));
839 isp2100_init_fabric(host
, temp
, j
);
842 for (i
= 0; i
<= QLOGICFC_MAX_ID
; i
++) {
843 if (temp
[i
].wwn
!= hostdata
->port_db
[i
].wwn
) {
844 for (j
= 0; j
<= QLOGICFC_MAX_ID
; j
++) {
845 if (temp
[j
].wwn
== hostdata
->port_db
[i
].wwn
) {
846 hostdata
->port_db
[i
].loop_id
= temp
[j
].loop_id
;
850 if (j
== QLOGICFC_MAX_ID
+ 1)
851 hostdata
->port_db
[i
].loop_id
= temp
[0].loop_id
;
853 for (j
= 0; j
<= QLOGICFC_MAX_ID
; j
++) {
854 if (hostdata
->port_db
[j
].wwn
== temp
[i
].wwn
|| !hostdata
->port_db
[j
].wwn
) {
858 if (j
== QLOGICFC_MAX_ID
+ 1)
859 printk("qlogicfc.c: Too many scsi devices, no more room in port map.\n");
860 if (!hostdata
->port_db
[j
].wwn
) {
861 hostdata
->port_db
[j
].loop_id
= temp
[i
].loop_id
;
862 hostdata
->port_db
[j
].wwn
= temp
[i
].wwn
;
865 hostdata
->port_db
[i
].loop_id
= temp
[i
].loop_id
;
869 isp2100_enable_irqs(host
);
877 int isp2100_init_fabric(struct Scsi_Host
*host
, struct id_name_map
*port_db
, int j
)
883 u_short loop_id
= 0x81;
887 u_char sns_response
[608];
888 struct isp2100_hostdata
*hostdata
;
890 hostdata
= (struct isp2100_hostdata
*) host
->hostdata
;
892 DEBUG_FABRIC(printk("qlogicfc.c: Checking for a fabric.\n"));
893 param
[0] = MBOX_GET_PORT_NAME
;
896 isp2100_mbox_command(host
, param
);
898 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
899 DEBUG_FABRIC(printk("fabric check result %x\n", param
[0]));
902 printk("qlogicfc.c: Fabric found.\n");
905 port_id
= hostdata
->port_id
;
907 memset(&req
, 0, sizeof(req
));
910 req
.response_low
= virt_to_bus_low32(sns_response
);
911 req
.response_high
= virt_to_bus_high32(sns_response
);
913 req
.data
[0] = 0x0100;
914 req
.data
[4] = (u_short
) (port_id
& 0xffff);
915 req
.data
[5] = (u_short
) (port_id
>> 16 & 0xffff);
917 param
[0] = MBOX_SEND_SNS
;
919 param
[2] = virt_to_bus_low32(&req
) >> 16;
920 param
[3] = virt_to_bus_low32(&req
);
921 param
[6] = virt_to_bus_high32(&req
) >> 16;
922 param
[7] = virt_to_bus_high32(&req
);
924 isp2100_mbox_command(host
, param
);
926 if (param
[0] == MBOX_COMMAND_COMPLETE
) {
927 DEBUG_FABRIC(printk("found node %02x%02x%02x%02x%02x%02x%02x%02x ", sns_response
[20], sns_response
[21], sns_response
[22], sns_response
[23], sns_response
[24], sns_response
[25], sns_response
[26], sns_response
[27]));
928 DEBUG_FABRIC(printk(" port id: %02x%02x%02x\n", sns_response
[17], sns_response
[18], sns_response
[19]));
929 port_id
= ((u_int
) sns_response
[17]) << 16;
930 port_id
|= ((u_int
) sns_response
[18]) << 8;
931 port_id
|= ((u_int
) sns_response
[19]);
932 wwn
= ((u64
) sns_response
[20]) << 56;
933 wwn
|= ((u64
) sns_response
[21]) << 48;
934 wwn
|= ((u64
) sns_response
[22]) << 40;
935 wwn
|= ((u64
) sns_response
[23]) << 32;
936 wwn
|= ((u64
) sns_response
[24]) << 24;
937 wwn
|= ((u64
) sns_response
[25]) << 16;
938 wwn
|= ((u64
) sns_response
[26]) << 8;
939 wwn
|= ((u64
) sns_response
[27]);
940 if (hostdata
->port_id
>> 8 != port_id
>> 8) {
941 DEBUG_FABRIC(printk("adding a fabric port: %x\n", port_id
));
942 param
[0] = MBOX_PORT_LOGIN
;
943 param
[1] = loop_id
<< 8;
944 param
[2] = (u_short
) (port_id
>> 16);
945 param
[3] = (u_short
) (port_id
);
947 isp2100_mbox_command(host
, param
);
949 if (param
[0] == MBOX_COMMAND_COMPLETE
) {
950 port_db
[scsi_id
].wwn
= wwn
;
951 port_db
[scsi_id
].loop_id
= loop_id
;
955 printk("qlogicfc.c: Error performing port login %x\n", param
[0]);
956 DEBUG_FABRIC(printk("loop_id: %x\n", loop_id
));
960 if (hostdata
->port_id
== port_id
)
963 printk("qlogicfc.c: Get All Next failed %x.\n", param
[0]);
971 #endif /* ISP2100_FABRIC */
974 int isp2100_release(struct Scsi_Host
*host
)
976 struct isp2100_hostdata
*hostdata
;
978 ENTER("isp2100_release");
980 hostdata
= (struct isp2100_hostdata
*) host
->hostdata
;
982 outw(0x0, host
->io_port
+ PCI_INTER_CTL
);
983 free_irq(host
->irq
, host
);
985 release_region(host
->io_port
, 0xff);
987 LEAVE("isp2100_release");
993 const char *isp2100_info(struct Scsi_Host
*host
)
996 struct isp2100_hostdata
*hostdata
;
997 ENTER("isp2100_info");
999 hostdata
= (struct isp2100_hostdata
*) host
->hostdata
;
1001 "QLogic ISP2100 SCSI on PCI bus %02x device %02x irq %d base 0x%lx",
1002 hostdata
->pci_dev
->bus
->number
, hostdata
->pci_dev
->devfn
, host
->irq
,
1006 LEAVE("isp2100_info");
1013 * The middle SCSI layer ensures that queuecommand never gets invoked
1014 * concurrently with itself or the interrupt handler (though the
1015 * interrupt handler may call this routine as part of
1016 * request-completion handling).
1018 int isp2100_queuecommand(Scsi_Cmnd
* Cmnd
, void (*done
) (Scsi_Cmnd
*))
1020 int i
, sg_count
, n
, num_free
;
1021 u_int in_ptr
, out_ptr
;
1023 struct scatterlist
*sg
;
1024 struct Command_Entry
*cmd
;
1025 struct Continuation_Entry
*cont
;
1026 struct Scsi_Host
*host
;
1027 struct isp2100_hostdata
*hostdata
;
1029 ENTER("isp2100_queuecommand");
1032 hostdata
= (struct isp2100_hostdata
*) host
->hostdata
;
1033 Cmnd
->scsi_done
= done
;
1035 DEBUG(isp2100_print_scsi_cmd(Cmnd
));
1037 if (hostdata
->loop_up
== 2) {
1038 hostdata
->loop_up
= 1;
1039 isp2100_make_portdb(host
);
1040 for (i
= 0; hostdata
->port_db
[i
].wwn
!= 0; i
++) {
1041 DEBUG(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
));
1044 if (hostdata
->loop_up
== -1) {
1045 printk("qlogicfc.c: The firmware is dead, just return.\n");
1050 out_ptr
= inw(host
->io_port
+ MBOX4
);
1051 in_ptr
= hostdata
->req_in_ptr
;
1053 DEBUG(printk("qlogicfc : request queue depth %d\n",
1054 REQ_QUEUE_DEPTH(in_ptr
, out_ptr
)));
1056 cmd
= (struct Command_Entry
*) &hostdata
->req
[in_ptr
][0];
1057 in_ptr
= (in_ptr
+ 1) & QLOGICFC_REQ_QUEUE_LEN
;
1058 if (in_ptr
== out_ptr
) {
1059 DEBUG(printk("qlogicfc : request queue overflow\n"));
1062 if (hostdata
->send_marker
) {
1063 struct Marker_Entry
*marker
;
1065 TRACE("queue marker", in_ptr
, 0);
1067 DEBUG(printk("qlogicfc : adding marker entry\n"));
1068 marker
= (struct Marker_Entry
*) cmd
;
1069 memset(marker
, 0, sizeof(struct Marker_Entry
));
1071 marker
->hdr
.entry_type
= ENTRY_MARKER
;
1072 marker
->hdr
.entry_cnt
= 1;
1073 marker
->modifier
= SYNC_ALL
;
1075 hostdata
->send_marker
= 0;
1077 if (((in_ptr
+ 1) & QLOGICFC_REQ_QUEUE_LEN
) == out_ptr
) {
1078 outw(in_ptr
, host
->io_port
+ MBOX4
);
1079 hostdata
->req_in_ptr
= in_ptr
;
1080 DEBUG(printk("qlogicfc : request queue overflow\n"));
1083 cmd
= (struct Command_Entry
*) &hostdata
->req
[in_ptr
][0];
1084 in_ptr
= (in_ptr
+ 1) & QLOGICFC_REQ_QUEUE_LEN
;
1086 TRACE("queue command", in_ptr
, Cmnd
);
1088 memset(cmd
, 0, sizeof(struct Command_Entry
));
1090 /* find a free handle mapping slot */
1091 for (i
= in_ptr
; i
!= (in_ptr
- 1) && hostdata
->handle_ptrs
[i
]; i
= ((i
+ 1) % (QLOGICFC_REQ_QUEUE_LEN
+ 1)));
1093 if (!hostdata
->handle_ptrs
[i
]) {
1095 hostdata
->handle_ptrs
[i
] = Cmnd
;
1096 hostdata
->handle_serials
[i
] = Cmnd
->serial_number
;
1098 printk("qlogicfc: no handle slots, this should not happen.\n");
1100 cmd
->hdr
.entry_type
= ENTRY_COMMAND
;
1101 cmd
->hdr
.entry_cnt
= 1;
1102 cmd
->target_lun
= Cmnd
->lun
;
1104 cmd
->target_id
= hostdata
->port_db
[Cmnd
->target
].loop_id
;
1106 cmd
->target_id
= Cmnd
->target
;
1108 cmd
->total_byte_cnt
= (u_int
) Cmnd
->request_bufflen
;
1109 cmd
->time_out
= (SCSI_TIMEOUT
/ HZ
) * 5;
1110 memcpy(cmd
->cdb
, Cmnd
->cmnd
, Cmnd
->cmd_len
);
1113 cmd
->segment_cnt
= sg_count
= Cmnd
->use_sg
;
1114 sg
= (struct scatterlist
*) Cmnd
->request_buffer
;
1116 /* fill in first two sg entries: */
1120 for (i
= 0; i
< n
; i
++) {
1121 ds
[i
].d_base_lo
= virt_to_bus_low32(sg
->address
);
1122 ds
[i
].d_base_high
= virt_to_bus_high32(sg
->address
);
1123 ds
[i
].d_count
= sg
->length
;
1128 while (sg_count
> 0) {
1129 ++cmd
->hdr
.entry_cnt
;
1130 cont
= (struct Continuation_Entry
*)
1131 &hostdata
->req
[in_ptr
][0];
1132 memset(cont
, 0, sizeof(struct Continuation_Entry
));
1133 in_ptr
= (in_ptr
+ 1) & QLOGICFC_REQ_QUEUE_LEN
;
1134 if (in_ptr
== out_ptr
) {
1135 DEBUG(printk("isp2100: unexpected request queue overflow\n"));
1138 TRACE("queue continuation", in_ptr
, 0);
1139 cont
->hdr
.entry_type
= ENTRY_CONTINUATION
;
1144 for (i
= 0; i
< n
; ++i
) {
1145 ds
[i
].d_base_lo
= virt_to_bus_low32(sg
->address
);
1146 ds
[i
].d_base_high
= virt_to_bus_high32(sg
->address
);
1147 ds
[i
].d_count
= sg
->length
;
1153 cmd
->dataseg
[0].d_base_lo
= virt_to_bus_low32(Cmnd
->request_buffer
);
1154 cmd
->dataseg
[0].d_base_high
= virt_to_bus_high32(Cmnd
->request_buffer
);
1155 cmd
->dataseg
[0].d_count
=
1156 (u_int
) Cmnd
->request_bufflen
;
1157 cmd
->segment_cnt
= 1;
1160 switch (Cmnd
->cmnd
[0]) {
1164 cmd
->control_flags
= CFLAG_WRITE
;
1167 /* scsi.c expects sense info in a different buffer */
1168 cmd
->dataseg
[0].d_base_lo
= virt_to_bus_low32(Cmnd
->sense_buffer
);
1169 cmd
->dataseg
[0].d_base_high
= virt_to_bus_high32(Cmnd
->sense_buffer
);
1170 cmd
->segment_cnt
= 1;
1171 cmd
->control_flags
= CFLAG_READ
;
1174 cmd
->control_flags
= CFLAG_READ
;
1179 if (Cmnd
->device
->tagged_supported
) {
1180 if ((jiffies
- hostdata
->tag_ages
[Cmnd
->target
]) > (2 * SCSI_TIMEOUT
)) {
1181 cmd
->control_flags
|= CFLAG_ORDERED_TAG
;
1182 hostdata
->tag_ages
[Cmnd
->target
] = jiffies
;
1184 switch (Cmnd
->tag
) {
1185 case HEAD_OF_QUEUE_TAG
:
1186 cmd
->control_flags
|= CFLAG_HEAD_TAG
;
1188 case ORDERED_QUEUE_TAG
:
1189 cmd
->control_flags
|= CFLAG_ORDERED_TAG
;
1192 cmd
->control_flags
|= CFLAG_SIMPLE_TAG
;
1196 outw(in_ptr
, host
->io_port
+ MBOX4
);
1197 hostdata
->req_in_ptr
= in_ptr
;
1200 num_free
= QLOGICFC_REQ_QUEUE_LEN
- REQ_QUEUE_DEPTH(in_ptr
, out_ptr
);
1201 num_free
= (num_free
> 2) ? num_free
- 2 : 0;
1202 host
->can_queue
= hostdata
->queued
+ num_free
;
1203 if (host
->can_queue
> QLOGICFC_REQ_QUEUE_LEN
)
1204 host
->can_queue
= QLOGICFC_REQ_QUEUE_LEN
;
1205 host
->sg_tablesize
= QLOGICFC_MAX_SG(num_free
);
1207 /* this is really gross */
1208 if (host
->can_queue
<= host
->host_busy
){
1209 if (host
->can_queue
+2 < host
->host_busy
)
1210 DEBUG(printk("qlogicfc.c crosses its fingers.\n"));
1211 host
->can_queue
= host
->host_busy
+ 1;
1214 LEAVE("isp2100_queuecommand");
1220 #define ASYNC_EVENT_INTERRUPT 0x01
1223 void do_isp2100_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1225 unsigned long flags
;
1227 spin_lock_irqsave(&io_request_lock
, flags
);
1228 isp2100_intr_handler(irq
, dev_id
, regs
);
1229 spin_unlock_irqrestore(&io_request_lock
, flags
);
1232 void isp2100_intr_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1235 struct Status_Entry
*sts
;
1236 struct Scsi_Host
*host
= dev_id
;
1237 struct isp2100_hostdata
*hostdata
;
1238 u_int in_ptr
, out_ptr
, handle
, num_free
;
1241 ENTER_INTR("isp2100_intr_handler");
1243 hostdata
= (struct isp2100_hostdata
*) host
->hostdata
;
1245 DEBUG_INTR(printk("qlogicfc : interrupt on line %d\n", irq
));
1247 if (!(inw(host
->io_port
+ PCI_INTER_STS
) & 0x08)) {
1248 /* spurious interrupts can happen legally */
1249 DEBUG_INTR(printk("qlogicfc: got spurious interrupt\n"));
1252 in_ptr
= inw(host
->io_port
+ MBOX5
);
1253 out_ptr
= hostdata
->res_out_ptr
;
1255 if ((inw(host
->io_port
+ PCI_SEMAPHORE
) & ASYNC_EVENT_INTERRUPT
)) {
1256 status
= inw(host
->io_port
+ MBOX0
);
1258 DEBUG_INTR(printk("qlogicfc : mbox completion status: %x\n",
1263 hostdata
->loop_up
= 2;
1266 hostdata
->loop_up
= 0;
1269 case CHANGE_NOTIFICATION
:
1270 case PORT_DB_CHANGED
:
1272 if (hostdata
->loop_up
== 1)
1273 hostdata
->loop_up
= 2;
1276 printk("The firmware just choked.\n");
1277 hostdata
->loop_up
= -1;
1279 case SCSI_COMMAND_COMPLETE
:
1280 handle
= inw(host
->io_port
+ MBOX1
) | (inw(host
->io_port
+ MBOX2
) << 16);
1281 Cmnd
= hostdata
->handle_ptrs
[handle
];
1282 hostdata
->handle_ptrs
[handle
] = NULL
;
1283 hostdata
->handle_serials
[handle
] = 0;
1287 (*Cmnd
->scsi_done
) (Cmnd
);
1289 printk("qlogicfc.c: got a null value out of handle_ptrs, this sucks\n");
1291 case MBOX_COMMAND_COMPLETE
:
1292 case INVALID_COMMAND
:
1293 case HOST_INTERFACE_ERROR
:
1296 case COMMAND_PARAM_ERROR
:
1300 hostdata
->mbox_done
= 1;
1301 outw(HCCR_CLEAR_RISC_INTR
, host
->io_port
+ HOST_HCCR
);
1304 printk("qlogicfc: got an unknown status? %x\n", status
);
1306 outw(0x0, host
->io_port
+ PCI_SEMAPHORE
);
1308 DEBUG_INTR(printk("qlogicfc : response queue update\n"));
1309 DEBUG_INTR(printk("qlogicfc : response queue depth %d\n", RES_QUEUE_DEPTH(in_ptr
, out_ptr
)));
1311 while (out_ptr
!= in_ptr
) {
1312 sts
= (struct Status_Entry
*) &hostdata
->res
[out_ptr
][0];
1313 out_ptr
= (out_ptr
+ 1) & RES_QUEUE_LEN
;
1315 TRACE("done", out_ptr
, Cmnd
);
1316 DEBUG_INTR(isp2100_print_status_entry(sts
));
1317 if (sts
->hdr
.entry_type
== ENTRY_STATUS
) {
1318 Cmnd
= hostdata
->handle_ptrs
[sts
->handle
];
1319 Cmnd
->result
= isp2100_return_status(sts
);
1320 hostdata
->handle_ptrs
[sts
->handle
] = NULL
;
1322 if (hostdata
->handle_serials
[sts
->handle
] != Cmnd
->serial_number
) {
1323 hostdata
->handle_serials
[sts
->handle
] = 0;
1324 outw(out_ptr
, host
->io_port
+ MBOX5
);
1327 hostdata
->handle_serials
[sts
->handle
] = 0;
1329 outw(out_ptr
, host
->io_port
+ MBOX5
);
1333 if (sts
->completion_status
== CS_RESET_OCCURRED
1334 || sts
->completion_status
== CS_ABORTED
1335 || (sts
->status_flags
& STF_BUS_RESET
))
1336 hostdata
->send_marker
= 1;
1338 memset(Cmnd
->sense_buffer
, 0, sizeof(Cmnd
->sense_buffer
));
1339 if (sts
->scsi_status
& 0x0200)
1340 memcpy(Cmnd
->sense_buffer
, sts
->req_sense_data
,
1341 sizeof(Cmnd
->sense_buffer
));
1343 outw(out_ptr
, host
->io_port
+ MBOX5
);
1345 if (Cmnd
->scsi_done
!= NULL
) {
1346 (*Cmnd
->scsi_done
) (Cmnd
);
1348 printk("Ouch, scsi done is NULL\n");
1350 hostdata
->res_out_ptr
= out_ptr
;
1354 out_ptr
= inw(host
->io_port
+ MBOX4
);
1355 in_ptr
= hostdata
->req_in_ptr
;
1357 num_free
= QLOGICFC_REQ_QUEUE_LEN
- REQ_QUEUE_DEPTH(in_ptr
, out_ptr
);
1358 num_free
= (num_free
> 2) ? num_free
- 2 : 0;
1359 host
->can_queue
= hostdata
->queued
+ num_free
;
1360 if (host
->can_queue
> QLOGICFC_REQ_QUEUE_LEN
)
1361 host
->can_queue
= QLOGICFC_REQ_QUEUE_LEN
;
1362 host
->sg_tablesize
= QLOGICFC_MAX_SG(num_free
);
1364 if (host
->can_queue
<= host
->host_busy
){
1365 if (host
->can_queue
+2 < host
->host_busy
)
1366 DEBUG(printk("qlogicfc crosses its fingers.\n"));
1367 host
->can_queue
= host
->host_busy
+ 1;
1370 outw(HCCR_CLEAR_RISC_INTR
, host
->io_port
+ HOST_HCCR
);
1371 LEAVE_INTR("isp2100_intr_handler");
1375 static int isp2100_return_status(struct Status_Entry
*sts
)
1377 int host_status
= DID_ERROR
;
1378 #if DEBUG_ISP2100_INTR
1379 static char *reason
[] =
1392 #endif /* DEBUG_ISP2100_INTR */
1394 ENTER("isp2100_return_status");
1396 DEBUG(printk("qlogicfc : completion status = 0x%04x\n",
1397 sts
->completion_status
));
1399 switch (sts
->completion_status
) {
1401 host_status
= DID_OK
;
1404 host_status
= DID_ERROR
;
1406 case CS_RESET_OCCURRED
:
1407 host_status
= DID_RESET
;
1410 host_status
= DID_ABORT
;
1413 host_status
= DID_TIME_OUT
;
1415 case CS_DATA_OVERRUN
:
1416 host_status
= DID_ERROR
;
1418 case CS_DATA_UNDERRUN
:
1419 host_status
= DID_OK
;
1421 case CS_PORT_UNAVAILABLE
:
1422 case CS_PORT_LOGGED_OUT
:
1423 case CS_PORT_CONFIG_CHANGED
:
1424 host_status
= DID_BAD_TARGET
;
1427 host_status
= DID_ERROR
;
1430 printk("qlogicfc : unknown completion status 0x%04x\n",
1431 sts
->completion_status
);
1432 host_status
= DID_ERROR
;
1436 DEBUG_INTR(printk("qlogicfc : host status (%s) scsi status %x\n",
1437 reason
[host_status
], sts
->scsi_status
));
1439 LEAVE("isp2100_return_status");
1441 return (sts
->scsi_status
& STATUS_MASK
) | (host_status
<< 16);
1445 int isp2100_abort(Scsi_Cmnd
* Cmnd
)
1449 struct Scsi_Host
*host
;
1450 struct isp2100_hostdata
*hostdata
;
1451 int return_status
= SCSI_ABORT_SUCCESS
;
1453 ENTER("isp2100_abort");
1456 hostdata
= (struct isp2100_hostdata
*) host
->hostdata
;
1458 for (i
= 0; i
< QLOGICFC_REQ_QUEUE_LEN
; i
++)
1459 if (hostdata
->handle_ptrs
[i
] == Cmnd
)
1462 if (i
== QLOGICFC_REQ_QUEUE_LEN
)
1463 return SCSI_ABORT_ERROR
;
1465 isp2100_disable_irqs(host
);
1467 param
[0] = MBOX_ABORT_IOCB
;
1468 param
[1] = (((u_short
) Cmnd
->target
) << 8) | Cmnd
->lun
;
1470 param
[3] = i
& 0xffff;
1472 isp2100_mbox_command(host
, param
);
1474 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1475 printk("qlogicfc : scsi abort failure: %x\n", param
[0]);
1476 if (param
[0] == 0x4005)
1477 Cmnd
->result
= DID_ERROR
<< 16;
1478 if (param
[0] == 0x4006)
1479 Cmnd
->result
= DID_BAD_TARGET
<< 16;
1480 (*Cmnd
->scsi_done
) (Cmnd
);
1481 return_status
= SCSI_ABORT_ERROR
;
1483 isp2100_enable_irqs(host
);
1485 LEAVE("isp2100_abort");
1487 return return_status
;
1491 int isp2100_reset(Scsi_Cmnd
* Cmnd
, unsigned int reset_flags
)
1494 struct Scsi_Host
*host
;
1495 struct isp2100_hostdata
*hostdata
;
1496 int return_status
= SCSI_RESET_SUCCESS
;
1498 ENTER("isp2100_reset");
1501 hostdata
= (struct isp2100_hostdata
*) host
->hostdata
;
1502 param
[0] = MBOX_BUS_RESET
;
1505 isp2100_disable_irqs(host
);
1507 isp2100_mbox_command(host
, param
);
1509 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1510 printk("qlogicfc : scsi bus reset failure: %x\n", param
[0]);
1511 return_status
= SCSI_RESET_ERROR
;
1513 isp2100_enable_irqs(host
);
1515 LEAVE("isp2100_reset");
1517 return return_status
;;
1521 int isp2100_biosparam(Disk
* disk
, kdev_t n
, int ip
[])
1523 int size
= disk
->capacity
;
1525 ENTER("isp2100_biosparam");
1533 ip
[2] = size
/ (ip
[0] * ip
[1]);
1535 LEAVE("isp2100_biosparam");
1541 static int isp2100_reset_hardware(struct Scsi_Host
*host
)
1544 struct isp2100_hostdata
*hostdata
;
1547 ENTER("isp2100_reset_hardware");
1549 outw(0x01, host
->io_port
+ ISP_CTRL_STATUS
);
1550 outw(HCCR_RESET
, host
->io_port
+ HOST_HCCR
);
1551 outw(HCCR_RELEASE
, host
->io_port
+ HOST_HCCR
);
1552 outw(HCCR_BIOS_DISABLE
, host
->io_port
+ HOST_HCCR
);
1554 loop_count
= DEFAULT_LOOP_COUNT
;
1555 while (--loop_count
&& inw(host
->io_port
+ HOST_HCCR
) == RISC_BUSY
)
1558 printk("qlogicfc: reset_hardware loop timeout\n");
1563 printk("qlogicfc : mbox 0 0x%04x \n", inw(host
->io_port
+ MBOX0
));
1564 printk("qlogicfc : mbox 1 0x%04x \n", inw(host
->io_port
+ MBOX1
));
1565 printk("qlogicfc : mbox 2 0x%04x \n", inw(host
->io_port
+ MBOX2
));
1566 printk("qlogicfc : mbox 3 0x%04x \n", inw(host
->io_port
+ MBOX3
));
1567 printk("qlogicfc : mbox 4 0x%04x \n", inw(host
->io_port
+ MBOX4
));
1568 printk("qlogicfc : mbox 5 0x%04x \n", inw(host
->io_port
+ MBOX5
));
1569 printk("qlogicfc : mbox 6 0x%04x \n", inw(host
->io_port
+ MBOX6
));
1570 printk("qlogicfc : mbox 7 0x%04x \n", inw(host
->io_port
+ MBOX7
));
1571 #endif /* DEBUG_ISP2100 */
1573 DEBUG(printk("qlogicfc : verifying checksum\n"));
1578 for (i
= 0; i
< risc_code_length01
; i
++) {
1579 param
[0] = MBOX_WRITE_RAM_WORD
;
1580 param
[1] = risc_code_addr01
+ i
;
1581 param
[2] = risc_code01
[i
];
1583 isp2100_mbox_command(host
, param
);
1585 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1586 printk("qlogicfc : firmware load failure\n");
1591 #endif /* RELOAD_FIRMWARE */
1593 param
[0] = MBOX_VERIFY_CHECKSUM
;
1594 param
[1] = risc_code_addr01
;
1596 isp2100_mbox_command(host
, param
);
1598 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1599 printk("qlogicfc : ram checksum failure\n");
1602 DEBUG(printk("qlogicfc : executing firmware\n"));
1604 param
[0] = MBOX_EXEC_FIRMWARE
;
1605 param
[1] = risc_code_addr01
;
1607 isp2100_mbox_command(host
, param
);
1609 param
[0] = MBOX_ABOUT_FIRMWARE
;
1611 isp2100_mbox_command(host
, param
);
1613 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1614 printk("qlogicfc : about firmware failure\n");
1617 DEBUG(printk("qlogicfc : firmware major revision %d\n", param
[1]));
1618 DEBUG(printk("qlogicfc : firmware minor revision %d\n", param
[2]));
1620 hostdata
= (struct isp2100_hostdata
*) host
->hostdata
;
1622 #ifdef USE_NVRAM_DEFAULTS
1624 if (isp2100_get_nvram_defaults(host
, &hostdata
->control_block
) != 0) {
1625 printk("qlogicfc: Could not read from NVRAM\n");
1629 hostdata
->wwn
= (u64
) (hostdata
->control_block
.node_name
[0]) << 56;
1630 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[0] & 0xff00) << 48;
1631 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[1] & 0xff00) << 24;
1632 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[1] & 0x00ff) << 48;
1633 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[2] & 0x00ff) << 24;
1634 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[2] & 0xff00) << 8;
1635 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[3] & 0x00ff) << 8;
1636 hostdata
->wwn
|= (u64
) (hostdata
->control_block
.node_name
[3] & 0xff00) >> 8;
1638 param
[0] = MBOX_INIT_FIRMWARE
;
1639 param
[2] = (u_short
) (virt_to_bus_low32(&hostdata
->control_block
) >> 16);
1640 param
[3] = (u_short
) (virt_to_bus_low32(&hostdata
->control_block
) & 0xffff);
1643 param
[6] = (u_short
) (virt_to_bus_high32(&hostdata
->control_block
) >> 16);
1644 param
[7] = (u_short
) (virt_to_bus_high32(&hostdata
->control_block
) & 0xffff);
1645 isp2100_mbox_command(host
, param
);
1646 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1647 printk("qlogicfc.c: Ouch 0x%04x\n", param
[0]);
1650 param
[0] = MBOX_GET_FIRMWARE_STATE
;
1651 isp2100_mbox_command(host
, param
);
1652 if (param
[0] != MBOX_COMMAND_COMPLETE
) {
1653 printk("qlogicfc.c: 0x%04x\n", param
[0]);
1657 LEAVE("isp2100_reset_hardware");
1662 #ifdef USE_NVRAM_DEFAULTS
1664 static int isp2100_get_nvram_defaults(struct Scsi_Host
*host
, struct init_cb
*control_block
)
1668 if (isp2100_read_nvram_word(host
, 0) != 0x5349)
1671 value
= isp2100_read_nvram_word(host
, 8);
1672 control_block
->node_name
[0] = isp2100_read_nvram_word(host
, 9);
1673 control_block
->node_name
[1] = isp2100_read_nvram_word(host
, 10);
1674 control_block
->node_name
[2] = isp2100_read_nvram_word(host
, 11);
1675 control_block
->node_name
[3] = isp2100_read_nvram_word(host
, 12);
1676 control_block
->hard_addr
= isp2100_read_nvram_word(host
, 13);
1684 static int isp2100_init(struct Scsi_Host
*sh
)
1687 struct isp2100_hostdata
*hostdata
;
1691 struct pci_dev
*pdev
;
1694 ENTER("isp2100_init");
1696 hostdata
= (struct isp2100_hostdata
*) sh
->hostdata
;
1697 pdev
= hostdata
->pci_dev
;
1699 if (pci_read_config_word(pdev
, PCI_COMMAND
, &command
)
1700 || pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &revision
)) {
1701 printk("qlogicfc : error reading PCI configuration\n");
1704 io_base
= pdev
->base_address
[0];
1709 if (pdev
->vendor
!= PCI_VENDOR_ID_QLOGIC
) {
1710 printk("qlogicfc : 0x%04x is not QLogic vendor ID\n",
1714 if (pdev
->device
!= PCI_DEVICE_ID_QLOGIC_ISP2100
) {
1715 printk("qlogicfc : 0x%04x does not match ISP2100 device id\n",
1719 if (command
& PCI_COMMAND_IO
&& (io_base
& 3) == 1)
1720 io_base
&= PCI_BASE_ADDRESS_IO_MASK
;
1722 printk("qlogicfc : i/o mapping is disabled\n");
1726 if (!(command
& PCI_COMMAND_MASTER
)) {
1727 printk("qlogicfc : bus mastering is disabled\n");
1730 if (revision
!= ISP2100_REV_ID
&& revision
!= ISP2100_REV_ID3
)
1731 printk("qlogicfc : new isp2100 revision ID (%d)\n", revision
);
1734 hostdata
->revision
= revision
;
1737 sh
->io_port
= io_base
;
1739 LEAVE("isp2100_init");
1744 #if USE_NVRAM_DEFAULTS
1746 #define NVRAM_DELAY() udelay(10) /* 10 microsecond delay */
1749 u_short
isp2100_read_nvram_word(struct Scsi_Host
* host
, u_short byte
)
1752 u_short value
, output
, input
;
1754 outw(0x2, host
->io_port
+ PCI_NVRAM
);
1756 outw(0x3, host
->io_port
+ PCI_NVRAM
);
1761 for (i
= 10; i
>= 0; i
--) {
1762 output
= ((byte
>> i
) & 0x1) ? 0x4 : 0x0;
1763 outw(output
| 0x2, host
->io_port
+ PCI_NVRAM
);
1765 outw(output
| 0x3, host
->io_port
+ PCI_NVRAM
);
1767 outw(output
| 0x2, host
->io_port
+ PCI_NVRAM
);
1771 for (i
= 0xf, value
= 0; i
>= 0; i
--) {
1773 outw(0x3, host
->io_port
+ PCI_NVRAM
);
1775 input
= inw(host
->io_port
+ PCI_NVRAM
);
1777 outw(0x2, host
->io_port
+ PCI_NVRAM
);
1783 outw(0x0, host
->io_port
+ PCI_NVRAM
);
1790 #endif /* USE_NVRAM_DEFAULTS */
1795 * currently, this is only called during initialization or abort/reset,
1796 * at which times interrupts are disabled, so polling is OK, I guess...
1798 static int isp2100_mbox_command(struct Scsi_Host
*host
, u_short param
[])
1801 struct isp2100_hostdata
*hostdata
= (struct isp2100_hostdata
*) host
->hostdata
;
1803 if (mbox_param
[param
[0]] == 0)
1806 loop_count
= DEFAULT_LOOP_COUNT
;
1807 while (--loop_count
&& inw(host
->io_port
+ HOST_HCCR
) & 0x0080)
1810 printk("qlogicfc: mbox_command loop timeout #1\n");
1814 hostdata
->mbox_done
= 0;
1816 if (mbox_param
[param
[0]] == 0)
1817 printk("qlogicfc: invalid mbox command\n");
1819 if (mbox_param
[param
[0]] & 0x80)
1820 outw(param
[7], host
->io_port
+ MBOX7
);
1821 if (mbox_param
[param
[0]] & 0x40)
1822 outw(param
[6], host
->io_port
+ MBOX6
);
1823 if (mbox_param
[param
[0]] & 0x20)
1824 outw(param
[5], host
->io_port
+ MBOX5
);
1825 if (mbox_param
[param
[0]] & 0x10)
1826 outw(param
[4], host
->io_port
+ MBOX4
);
1827 if (mbox_param
[param
[0]] & 0x08)
1828 outw(param
[3], host
->io_port
+ MBOX3
);
1829 if (mbox_param
[param
[0]] & 0x04)
1830 outw(param
[2], host
->io_port
+ MBOX2
);
1831 if (mbox_param
[param
[0]] & 0x02)
1832 outw(param
[1], host
->io_port
+ MBOX1
);
1833 if (mbox_param
[param
[0]] & 0x01)
1834 outw(param
[0], host
->io_port
+ MBOX0
);
1837 outw(HCCR_SET_HOST_INTR
, host
->io_port
+ HOST_HCCR
);
1840 loop_count
= DEFAULT_LOOP_COUNT
;
1841 while (--loop_count
&& !(inw(host
->io_port
+ PCI_INTER_STS
) & 0x08)) {
1846 printk("qlogicfc: mbox_command loop timeout #2\n");
1849 isp2100_intr_handler(host
->irq
, host
, NULL
);
1851 if (hostdata
->mbox_done
== 1)
1856 loop_count
= DEFAULT_LOOP_COUNT
;
1857 while (--loop_count
&& inw(host
->io_port
+ MBOX0
) == 0x04) {
1861 printk("qlogicfc: mbox_command loop timeout #3\n");
1863 param
[7] = inw(host
->io_port
+ MBOX7
);
1864 param
[6] = inw(host
->io_port
+ MBOX6
);
1865 param
[5] = inw(host
->io_port
+ MBOX5
);
1866 param
[4] = inw(host
->io_port
+ MBOX4
);
1867 param
[3] = inw(host
->io_port
+ MBOX3
);
1868 param
[2] = inw(host
->io_port
+ MBOX2
);
1869 param
[1] = inw(host
->io_port
+ MBOX1
);
1870 param
[0] = inw(host
->io_port
+ MBOX0
);
1873 outw(0x0, host
->io_port
+ PCI_SEMAPHORE
);
1875 if (inw(host
->io_port
+ HOST_HCCR
) & 0x0080) {
1876 printk("mbox op is still pending\n");
1882 void isp2100_print_status_entry(struct Status_Entry
*status
)
1884 printk("qlogicfc : entry count = 0x%02x, type = 0x%02x, flags = 0x%02x\n",
1885 status
->hdr
.entry_cnt
, status
->hdr
.entry_type
, status
->hdr
.flags
);
1886 printk("qlogicfc : scsi status = 0x%04x, completion status = 0x%04x\n",
1887 status
->scsi_status
, status
->completion_status
);
1888 printk("qlogicfc : state flags = 0x%04x, status flags = 0x%04x\n",
1889 status
->state_flags
, status
->status_flags
);
1890 printk("qlogicfc : response info length = 0x%04x, request sense length = 0x%04x\n",
1891 status
->res_info_len
, status
->req_sense_len
);
1892 printk("qlogicfc : residual transfer length = 0x%08x, response = 0x%02x\n", status
->residual
, status
->res_info
[3]);
1900 void isp2100_print_scsi_cmd(Scsi_Cmnd
* cmd
)
1904 printk("qlogicfc : target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
1905 cmd
->target
, cmd
->lun
, cmd
->cmd_len
);
1906 printk("qlogicfc : command = ");
1907 for (i
= 0; i
< cmd
->cmd_len
; i
++)
1908 printk("0x%02x ", cmd
->cmnd
[i
]);
1912 #endif /* DEBUG_ISP2100 */
1917 Scsi_Host_Template driver_template
= QLOGICFC
;
1919 #include "scsi_module.c"