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
22 * Big endian support and dynamic DMA mapping added
23 * by Jakub Jelinek <jakub@redhat.com>.
25 * Conversion to final pci64 DMA interfaces
26 * by David S. Miller <davem@redhat.com>.
30 * $Date: 1995/09/22 02:23:15 $
34 * Revision 0.5 1995/09/22 02:23:15 root
35 * do auto request sense
37 * Revision 0.4 1995/08/07 04:44:33 root
38 * supply firmware with driver.
39 * numerous bug fixes/general cleanup of code.
41 * Revision 0.3 1995/07/16 16:15:39 root
42 * added reset/abort code.
44 * Revision 0.2 1995/06/29 03:14:19 root
46 * added queue protocol.
48 * Revision 0.1 1995/06/25 01:55:45 root
53 #include <linux/blkdev.h>
54 #include <linux/kernel.h>
55 #include <linux/string.h>
56 #include <linux/ioport.h>
57 #include <linux/sched.h>
58 #include <linux/types.h>
59 #include <linux/pci.h>
60 #include <linux/delay.h>
61 #include <linux/unistd.h>
62 #include <linux/spinlock.h>
63 #include <linux/interrupt.h>
69 #define pci64_dma_hi32(a) ((u32) (0xffffffff & (((u64)(a))>>32)))
70 #define pci64_dma_lo32(a) ((u32) (0xffffffff & (((u64)(a)))))
71 #define pci64_dma_build(hi,lo) \
72 ((dma_addr_t)(((u64)(lo))|(((u64)(hi))<<32)))
76 /* Configuration section **************************************************** */
78 /* Set the following macro to 1 to reload the ISP2x00's firmware. This is
79 version 1.17.30 of the isp2100's firmware and version 2.00.40 of the
83 #define USE_NVRAM_DEFAULTS 1
85 #define ISP2x00_PORTDB 1
87 /* Set the following to 1 to include fabric support, fabric support is
88 * currently not as well tested as the other aspects of the driver */
90 #define ISP2x00_FABRIC 1
92 /* Macros used for debugging */
93 #define DEBUG_ISP2x00 0
94 #define DEBUG_ISP2x00_INT 0
95 #define DEBUG_ISP2x00_INTR 0
96 #define DEBUG_ISP2x00_SETUP 0
97 #define DEBUG_ISP2x00_FABRIC 0
101 #define DEFAULT_LOOP_COUNT 1000000000
103 /* End Configuration section ************************************************ */
105 #include <linux/module.h>
109 #define TRACE_BUF_LEN (32*1024)
118 } buf[TRACE_BUF_LEN];
121 #define TRACE(w, i, a) \
123 unsigned long flags; \
127 trace.buf[trace.next].name = (w); \
128 trace.buf[trace.next].time = jiffies; \
129 trace.buf[trace.next].index = (i); \
130 trace.buf[trace.next].addr = (long) (a); \
131 trace.next = (trace.next + 1) & (TRACE_BUF_LEN - 1); \
132 restore_flags(flags); \
136 #define TRACE(w, i, a)
139 #if DEBUG_ISP2x00_FABRIC
140 #define DEBUG_FABRIC(x) x
142 #define DEBUG_FABRIC(x)
143 #endif /* DEBUG_ISP2x00_FABRIC */
147 #define ENTER(x) printk("isp2x00 : entering %s()\n", x);
148 #define LEAVE(x) printk("isp2x00 : leaving %s()\n", x);
154 #endif /* DEBUG_ISP2x00 */
156 #if DEBUG_ISP2x00_INTR
157 #define ENTER_INTR(x) printk("isp2x00 : entering %s()\n", x);
158 #define LEAVE_INTR(x) printk("isp2x00 : leaving %s()\n", x);
159 #define DEBUG_INTR(x) x
161 #define ENTER_INTR(x)
162 #define LEAVE_INTR(x)
163 #define DEBUG_INTR(x)
164 #endif /* DEBUG ISP2x00_INTR */
167 #define ISP2100_REV_ID1 1
168 #define ISP2100_REV_ID3 3
169 #define ISP2200_REV_ID5 5
171 /* host configuration and control registers */
172 #define HOST_HCCR 0xc0 /* host command and control */
174 /* pci bus interface registers */
175 #define FLASH_BIOS_ADDR 0x00
176 #define FLASH_BIOS_DATA 0x02
177 #define ISP_CTRL_STATUS 0x06 /* configuration register #1 */
178 #define PCI_INTER_CTL 0x08 /* pci interrupt control */
179 #define PCI_INTER_STS 0x0a /* pci interrupt status */
180 #define PCI_SEMAPHORE 0x0c /* pci semaphore */
181 #define PCI_NVRAM 0x0e /* pci nvram interface */
183 /* mailbox registers */
184 #define MBOX0 0x10 /* mailbox 0 */
185 #define MBOX1 0x12 /* mailbox 1 */
186 #define MBOX2 0x14 /* mailbox 2 */
187 #define MBOX3 0x16 /* mailbox 3 */
188 #define MBOX4 0x18 /* mailbox 4 */
189 #define MBOX5 0x1a /* mailbox 5 */
190 #define MBOX6 0x1c /* mailbox 6 */
191 #define MBOX7 0x1e /* mailbox 7 */
193 /* mailbox command complete status codes */
194 #define MBOX_COMMAND_COMPLETE 0x4000
195 #define INVALID_COMMAND 0x4001
196 #define HOST_INTERFACE_ERROR 0x4002
197 #define TEST_FAILED 0x4003
198 #define COMMAND_ERROR 0x4005
199 #define COMMAND_PARAM_ERROR 0x4006
200 #define PORT_ID_USED 0x4007
201 #define LOOP_ID_USED 0x4008
202 #define ALL_IDS_USED 0x4009
204 /* async event status codes */
205 #define RESET_DETECTED 0x8001
206 #define SYSTEM_ERROR 0x8002
207 #define REQUEST_TRANSFER_ERROR 0x8003
208 #define RESPONSE_TRANSFER_ERROR 0x8004
209 #define REQUEST_QUEUE_WAKEUP 0x8005
210 #define LIP_OCCURRED 0x8010
211 #define LOOP_UP 0x8011
212 #define LOOP_DOWN 0x8012
213 #define LIP_RECEIVED 0x8013
214 #define PORT_DB_CHANGED 0x8014
215 #define CHANGE_NOTIFICATION 0x8015
216 #define SCSI_COMMAND_COMPLETE 0x8020
217 #define POINT_TO_POINT_UP 0x8030
218 #define CONNECTION_MODE 0x8036
220 struct Entry_header {
227 /* entry header type commands */
228 #define ENTRY_COMMAND 0x19
229 #define ENTRY_CONTINUATION 0x0a
231 #define ENTRY_STATUS 0x03
232 #define ENTRY_MARKER 0x04
235 /* entry header flag definitions */
237 #define EFLAG_BAD_HEADER 4
238 #define EFLAG_BAD_PAYLOAD 8
246 struct Command_Entry {
247 struct Entry_header hdr;
251 u_short expanded_lun;
252 u_short control_flags;
257 u_int total_byte_cnt;
258 struct dataseg dataseg[DATASEGS_PER_COMMAND];
261 /* command entry control flag definitions */
262 #define CFLAG_NODISC 0x01
263 #define CFLAG_HEAD_TAG 0x02
264 #define CFLAG_ORDERED_TAG 0x04
265 #define CFLAG_SIMPLE_TAG 0x08
266 #define CFLAG_TAR_RTN 0x10
267 #define CFLAG_READ 0x20
268 #define CFLAG_WRITE 0x40
270 struct Continuation_Entry {
271 struct Entry_header hdr;
272 struct dataseg dataseg[DATASEGS_PER_CONT];
275 struct Marker_Entry {
276 struct Entry_header hdr;
285 /* marker entry modifier definitions */
286 #define SYNC_DEVICE 0
287 #define SYNC_TARGET 1
290 struct Status_Entry {
291 struct Entry_header hdr;
294 u_short completion_status;
296 u_short status_flags;
297 u_short res_info_len;
298 u_short req_sense_len;
301 u_char req_sense_data[32];
304 /* status entry completion status definitions */
305 #define CS_COMPLETE 0x0000
306 #define CS_DMA_ERROR 0x0002
307 #define CS_RESET_OCCURRED 0x0004
308 #define CS_ABORTED 0x0005
309 #define CS_TIMEOUT 0x0006
310 #define CS_DATA_OVERRUN 0x0007
311 #define CS_DATA_UNDERRUN 0x0015
312 #define CS_QUEUE_FULL 0x001c
313 #define CS_PORT_UNAVAILABLE 0x0028
314 #define CS_PORT_LOGGED_OUT 0x0029
315 #define CS_PORT_CONFIG_CHANGED 0x002a
317 /* status entry state flag definitions */
318 #define SF_SENT_CDB 0x0400
319 #define SF_TRANSFERRED_DATA 0x0800
320 #define SF_GOT_STATUS 0x1000
322 /* status entry status flag definitions */
323 #define STF_BUS_RESET 0x0008
324 #define STF_DEVICE_RESET 0x0010
325 #define STF_ABORTED 0x0020
326 #define STF_TIMEOUT 0x0040
328 /* interrupt control commands */
329 #define ISP_EN_INT 0x8000
330 #define ISP_EN_RISC 0x0008
332 /* host control commands */
333 #define HCCR_NOP 0x0000
334 #define HCCR_RESET 0x1000
335 #define HCCR_PAUSE 0x2000
336 #define HCCR_RELEASE 0x3000
337 #define HCCR_SINGLE_STEP 0x4000
338 #define HCCR_SET_HOST_INTR 0x5000
339 #define HCCR_CLEAR_HOST_INTR 0x6000
340 #define HCCR_CLEAR_RISC_INTR 0x7000
341 #define HCCR_BP_ENABLE 0x8000
342 #define HCCR_BIOS_DISABLE 0x9000
343 #define HCCR_TEST_MODE 0xf000
345 #define RISC_BUSY 0x0004
347 /* mailbox commands */
348 #define MBOX_NO_OP 0x0000
349 #define MBOX_LOAD_RAM 0x0001
350 #define MBOX_EXEC_FIRMWARE 0x0002
351 #define MBOX_DUMP_RAM 0x0003
352 #define MBOX_WRITE_RAM_WORD 0x0004
353 #define MBOX_READ_RAM_WORD 0x0005
354 #define MBOX_MAILBOX_REG_TEST 0x0006
355 #define MBOX_VERIFY_CHECKSUM 0x0007
356 #define MBOX_ABOUT_FIRMWARE 0x0008
357 #define MBOX_LOAD_RISC_RAM 0x0009
358 #define MBOX_DUMP_RISC_RAM 0x000a
359 #define MBOX_CHECK_FIRMWARE 0x000e
360 #define MBOX_INIT_REQ_QUEUE 0x0010
361 #define MBOX_INIT_RES_QUEUE 0x0011
362 #define MBOX_EXECUTE_IOCB 0x0012
363 #define MBOX_WAKE_UP 0x0013
364 #define MBOX_STOP_FIRMWARE 0x0014
365 #define MBOX_ABORT_IOCB 0x0015
366 #define MBOX_ABORT_DEVICE 0x0016
367 #define MBOX_ABORT_TARGET 0x0017
368 #define MBOX_BUS_RESET 0x0018
369 #define MBOX_STOP_QUEUE 0x0019
370 #define MBOX_START_QUEUE 0x001a
371 #define MBOX_SINGLE_STEP_QUEUE 0x001b
372 #define MBOX_ABORT_QUEUE 0x001c
373 #define MBOX_GET_DEV_QUEUE_STATUS 0x001d
374 #define MBOX_GET_FIRMWARE_STATUS 0x001f
375 #define MBOX_GET_INIT_SCSI_ID 0x0020
376 #define MBOX_GET_RETRY_COUNT 0x0022
377 #define MBOX_GET_TARGET_PARAMS 0x0028
378 #define MBOX_GET_DEV_QUEUE_PARAMS 0x0029
379 #define MBOX_SET_RETRY_COUNT 0x0032
380 #define MBOX_SET_TARGET_PARAMS 0x0038
381 #define MBOX_SET_DEV_QUEUE_PARAMS 0x0039
382 #define MBOX_EXECUTE_IOCB64 0x0054
383 #define MBOX_INIT_FIRMWARE 0x0060
384 #define MBOX_GET_INIT_CB 0x0061
385 #define MBOX_INIT_LIP 0x0062
386 #define MBOX_GET_POS_MAP 0x0063
387 #define MBOX_GET_PORT_DB 0x0064
388 #define MBOX_CLEAR_ACA 0x0065
389 #define MBOX_TARGET_RESET 0x0066
390 #define MBOX_CLEAR_TASK_SET 0x0067
391 #define MBOX_ABORT_TASK_SET 0x0068
392 #define MBOX_GET_FIRMWARE_STATE 0x0069
393 #define MBOX_GET_PORT_NAME 0x006a
394 #define MBOX_SEND_SNS 0x006e
395 #define MBOX_PORT_LOGIN 0x006f
396 #define MBOX_SEND_CHANGE_REQUEST 0x0070
397 #define MBOX_PORT_LOGOUT 0x0071
400 * Firmware if needed (note this is a hack, it belongs in a separate
404 #ifdef CONFIG_SCSI_QLOGIC_FC_FIRMWARE
405 #include "qlogicfc_asm.c"
407 static unsigned short risc_code_addr01 = 0x1000 ;
410 /* Each element in mbox_param is an 8 bit bitmap where each bit indicates
411 if that mbox should be copied as input. For example 0x2 would mean
414 static const u_char mbox_param[] =
416 0x01, /* MBOX_NO_OP */
417 0x1f, /* MBOX_LOAD_RAM */
418 0x03, /* MBOX_EXEC_FIRMWARE */
419 0x1f, /* MBOX_DUMP_RAM */
420 0x07, /* MBOX_WRITE_RAM_WORD */
421 0x03, /* MBOX_READ_RAM_WORD */
422 0xff, /* MBOX_MAILBOX_REG_TEST */
423 0x03, /* MBOX_VERIFY_CHECKSUM */
424 0x01, /* MBOX_ABOUT_FIRMWARE */
425 0xff, /* MBOX_LOAD_RISC_RAM */
426 0xff, /* MBOX_DUMP_RISC_RAM */
430 0x01, /* MBOX_CHECK_FIRMWARE */
432 0x1f, /* MBOX_INIT_REQ_QUEUE */
433 0x2f, /* MBOX_INIT_RES_QUEUE */
434 0x0f, /* MBOX_EXECUTE_IOCB */
435 0x03, /* MBOX_WAKE_UP */
436 0x01, /* MBOX_STOP_FIRMWARE */
437 0x0f, /* MBOX_ABORT_IOCB */
438 0x03, /* MBOX_ABORT_DEVICE */
439 0x07, /* MBOX_ABORT_TARGET */
440 0x03, /* MBOX_BUS_RESET */
441 0x03, /* MBOX_STOP_QUEUE */
442 0x03, /* MBOX_START_QUEUE */
443 0x03, /* MBOX_SINGLE_STEP_QUEUE */
444 0x03, /* MBOX_ABORT_QUEUE */
445 0x03, /* MBOX_GET_DEV_QUEUE_STATUS */
447 0x01, /* MBOX_GET_FIRMWARE_STATUS */
448 0x01, /* MBOX_GET_INIT_SCSI_ID */
450 0x01, /* MBOX_GET_RETRY_COUNT */
456 0x03, /* MBOX_GET_TARGET_PARAMS */
457 0x03, /* MBOX_GET_DEV_QUEUE_PARAMS */
466 0x07, /* MBOX_SET_RETRY_COUNT */
472 0x0f, /* MBOX_SET_TARGET_PARAMS */
473 0x0f, /* MBOX_SET_DEV_QUEUE_PARAMS */
500 0xcf, /* MBOX_EXECUTE_IOCB64 */
512 0xff, /* MBOX_INIT_FIRMWARE */
513 0xcd, /* MBOX_GET_INIT_CB */
514 0x01, /* MBOX_INIT_LIP */
515 0xcd, /* MBOX_GET_POS_MAP */
516 0xcf, /* MBOX_GET_PORT_DB */
517 0x03, /* MBOX_CLEAR_ACA */
518 0x03, /* MBOX_TARGET_RESET */
519 0x03, /* MBOX_CLEAR_TASK_SET */
520 0x03, /* MBOX_ABORT_TASK_SET */
521 0x01, /* MBOX_GET_FIRMWARE_STATE */
522 0x03, /* MBOX_GET_PORT_NAME */
526 0xcf, /* MBOX_SEND_SNS */
527 0x0f, /* MBOX_PORT_LOGIN */
528 0x03, /* MBOX_SEND_CHANGE_REQUEST */
529 0x03, /* MBOX_PORT_LOGOUT */
532 #define MAX_MBOX_COMMAND (sizeof(mbox_param)/sizeof(u_short))
550 /* address of instance of this struct is passed to adapter to initialize things
556 u_short max_frame_len;
558 u_short exec_throttle;
561 u_short node_name[4];
563 u_char reserved2[10];
564 u_short req_queue_out;
565 u_short res_queue_in;
566 u_short req_queue_len;
567 u_short res_queue_len;
568 u_int req_queue_addr_lo;
569 u_int req_queue_addr_high;
570 u_int res_queue_addr_lo;
571 u_int res_queue_addr_high;
572 /* the rest of this structure only applies to the isp2200 */
574 u_char cmd_resource_cnt;
575 u_char notify_resource_cnt;
578 u_short add_firm_opts;
579 u_char res_accum_timer;
580 u_char irq_delay_timer;
581 u_short special_options;
582 u_short reserved4[13];
586 * The result queue can be quite a bit smaller since continuation entries
587 * do not show up there:
589 #define RES_QUEUE_LEN ((QLOGICFC_REQ_QUEUE_LEN + 1) / 8 - 1)
590 #define QUEUE_ENTRY_LEN 64
593 #define QLOGICFC_MAX_ID 0xff
595 #define QLOGICFC_MAX_ID 0x7d
598 #define QLOGICFC_MAX_LUN 128
599 #define QLOGICFC_MAX_LOOP_ID 0x7d
601 /* the following connection options only apply to the 2200. i have only
602 * had success with LOOP_ONLY and P2P_ONLY.
607 #define LOOP_PREFERED 2
608 #define P2P_PREFERED 3
610 #define CONNECTION_PREFERENCE LOOP_ONLY
612 /* adapter_state values */
613 #define AS_FIRMWARE_DEAD -1
614 #define AS_LOOP_DOWN 0
615 #define AS_LOOP_GOOD 1
616 #define AS_REDO_FABRIC_PORTDB 2
617 #define AS_REDO_LOOP_PORTDB 4
619 #define RES_SIZE ((RES_QUEUE_LEN + 1)*QUEUE_ENTRY_LEN)
620 #define REQ_SIZE ((QLOGICFC_REQ_QUEUE_LEN + 1)*QUEUE_ENTRY_LEN)
622 struct isp2x00_hostdata {
624 struct pci_dev *pci_dev;
625 /* result and request queues (shared with isp2x00): */
626 u_int req_in_ptr; /* index of next request slot */
627 u_int res_out_ptr; /* index of next result slot */
629 /* this is here so the queues are nicely aligned */
630 long send_marker; /* do we need to send a marker? */
634 struct init_cb control_block;
636 unsigned long int tag_ages[QLOGICFC_MAX_ID + 1];
637 Scsi_Cmnd *handle_ptrs[QLOGICFC_REQ_QUEUE_LEN + 1];
638 unsigned long handle_serials[QLOGICFC_REQ_QUEUE_LEN + 1];
639 struct id_name_map port_db[QLOGICFC_MAX_ID + 1];
645 struct timer_list explore_timer;
646 struct id_name_map tempmap[QLOGICFC_MAX_ID + 1];
650 /* queue length's _must_ be power of two: */
651 #define QUEUE_DEPTH(in, out, ql) ((in - out) & (ql))
652 #define REQ_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, \
653 QLOGICFC_REQ_QUEUE_LEN)
654 #define RES_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, RES_QUEUE_LEN)
656 static void isp2x00_enable_irqs(struct Scsi_Host *);
657 static void isp2x00_disable_irqs(struct Scsi_Host *);
658 static int isp2x00_init(struct Scsi_Host *);
659 static int isp2x00_reset_hardware(struct Scsi_Host *);
660 static int isp2x00_mbox_command(struct Scsi_Host *, u_short[]);
661 static int isp2x00_return_status(Scsi_Cmnd *, struct Status_Entry *);
662 static void isp2x00_intr_handler(int, void *, struct pt_regs *);
663 static irqreturn_t do_isp2x00_intr_handler(int, void *, struct pt_regs *);
664 static int isp2x00_make_portdb(struct Scsi_Host *);
667 static int isp2x00_init_fabric(struct Scsi_Host *, struct id_name_map *, int);
670 #if USE_NVRAM_DEFAULTS
671 static int isp2x00_get_nvram_defaults(struct Scsi_Host *, struct init_cb *);
672 static u_short isp2x00_read_nvram_word(struct Scsi_Host *, u_short);
676 static void isp2x00_print_scsi_cmd(Scsi_Cmnd *);
679 #if DEBUG_ISP2x00_INTR
680 static void isp2x00_print_status_entry(struct Status_Entry *);
683 static inline void isp2x00_enable_irqs(struct Scsi_Host *host)
685 outw(ISP_EN_INT | ISP_EN_RISC, host->io_port + PCI_INTER_CTL);
689 static inline void isp2x00_disable_irqs(struct Scsi_Host *host)
691 outw(0x0, host->io_port + PCI_INTER_CTL);
695 int isp2x00_detect(Scsi_Host_Template * tmpt)
698 unsigned long wait_time;
699 struct Scsi_Host *host = NULL;
700 struct isp2x00_hostdata *hostdata;
701 struct pci_dev *pdev;
702 unsigned short device_ids[2];
707 ENTER("isp2x00_detect");
709 device_ids[0] = PCI_DEVICE_ID_QLOGIC_ISP2100;
710 device_ids[1] = PCI_DEVICE_ID_QLOGIC_ISP2200;
712 tmpt->proc_name = "isp2x00";
716 while ((pdev = pci_find_device(PCI_VENDOR_ID_QLOGIC, device_ids[i], pdev))) {
717 if (pci_enable_device(pdev))
720 /* Try to configure DMA attributes. */
721 if (pci_set_dma_mask(pdev, 0xffffffffffffffffULL) &&
722 pci_set_dma_mask(pdev, 0xffffffffULL))
725 host = scsi_register(tmpt, sizeof(struct isp2x00_hostdata));
727 printk("qlogicfc%d : could not register host.\n", hosts);
730 scsi_set_device(host, &pdev->dev);
731 host->max_id = QLOGICFC_MAX_ID + 1;
732 host->max_lun = QLOGICFC_MAX_LUN;
733 hostdata = (struct isp2x00_hostdata *) host->hostdata;
735 memset(hostdata, 0, sizeof(struct isp2x00_hostdata));
736 hostdata->pci_dev = pdev;
737 hostdata->res = pci_alloc_consistent(pdev, RES_SIZE + REQ_SIZE, &busaddr);
740 printk("qlogicfc%d : could not allocate memory for request and response queue.\n", hosts);
741 scsi_unregister(host);
744 hostdata->req = hostdata->res + (RES_QUEUE_LEN + 1)*QUEUE_ENTRY_LEN;
745 hostdata->queued = 0;
746 /* set up the control block */
747 hostdata->control_block.version = 0x1;
748 hostdata->control_block.firm_opts = cpu_to_le16(0x800e);
749 hostdata->control_block.max_frame_len = cpu_to_le16(2048);
750 hostdata->control_block.max_iocb = cpu_to_le16(QLOGICFC_REQ_QUEUE_LEN);
751 hostdata->control_block.exec_throttle = cpu_to_le16(QLOGICFC_CMD_PER_LUN);
752 hostdata->control_block.retry_delay = 5;
753 hostdata->control_block.retry_cnt = 1;
754 hostdata->control_block.node_name[0] = cpu_to_le16(0x0020);
755 hostdata->control_block.node_name[1] = cpu_to_le16(0xE000);
756 hostdata->control_block.node_name[2] = cpu_to_le16(0x008B);
757 hostdata->control_block.node_name[3] = cpu_to_le16(0x0000);
758 hostdata->control_block.hard_addr = cpu_to_le16(0x0003);
759 hostdata->control_block.req_queue_len = cpu_to_le16(QLOGICFC_REQ_QUEUE_LEN + 1);
760 hostdata->control_block.res_queue_len = cpu_to_le16(RES_QUEUE_LEN + 1);
761 hostdata->control_block.res_queue_addr_lo = cpu_to_le32(pci64_dma_lo32(busaddr));
762 hostdata->control_block.res_queue_addr_high = cpu_to_le32(pci64_dma_hi32(busaddr));
763 hostdata->control_block.req_queue_addr_lo = cpu_to_le32(pci64_dma_lo32(busaddr + RES_SIZE));
764 hostdata->control_block.req_queue_addr_high = cpu_to_le32(pci64_dma_hi32(busaddr + RES_SIZE));
767 hostdata->control_block.add_firm_opts |= cpu_to_le16(CONNECTION_PREFERENCE<<4);
768 hostdata->adapter_state = AS_LOOP_DOWN;
769 hostdata->explore_timer.data = 1;
770 hostdata->host_id = hosts;
772 if (isp2x00_init(host) || isp2x00_reset_hardware(host)) {
773 pci_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
774 scsi_unregister(host);
779 if (request_irq(host->irq, do_isp2x00_intr_handler, SA_INTERRUPT | SA_SHIRQ, "qlogicfc", host)) {
780 printk("qlogicfc%d : interrupt %d already in use\n",
781 hostdata->host_id, host->irq);
782 pci_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
783 scsi_unregister(host);
786 if (!request_region(host->io_port, 0xff, "qlogicfc")) {
787 printk("qlogicfc%d : i/o region 0x%lx-0x%lx already "
789 hostdata->host_id, host->io_port, host->io_port + 0xff);
790 free_irq(host->irq, host);
791 pci_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
792 scsi_unregister(host);
796 outw(0x0, host->io_port + PCI_SEMAPHORE);
797 outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
798 isp2x00_enable_irqs(host);
799 /* wait for the loop to come up */
800 for (wait_time = jiffies + 10 * HZ; time_before(jiffies, wait_time) && hostdata->adapter_state == AS_LOOP_DOWN;) {
804 if (hostdata->adapter_state == AS_LOOP_DOWN) {
805 printk("qlogicfc%d : link is not up\n", hostdata->host_id);
808 hostdata->explore_timer.data = 0;
813 /* this busy loop should not be needed but the isp2x00 seems to need
814 some time before recognizing it is attached to a fabric */
817 for (wait_time = jiffies + 5 * HZ; time_before(jiffies, wait_time);) {
823 LEAVE("isp2x00_detect");
829 static int isp2x00_make_portdb(struct Scsi_Host *host)
834 struct isp2x00_hostdata *hostdata;
836 isp2x00_disable_irqs(host);
838 hostdata = (struct isp2x00_hostdata *) host->hostdata;
839 memset(hostdata->tempmap, 0, sizeof(hostdata->tempmap));
842 for (i = 0x81; i < QLOGICFC_MAX_ID; i++) {
843 param[0] = MBOX_PORT_LOGOUT;
848 isp2x00_mbox_command(host, param);
850 if (param[0] != MBOX_COMMAND_COMPLETE) {
852 DEBUG_FABRIC(printk("qlogicfc%d : logout failed %x %x\n", hostdata->host_id, i, param[0]));
858 param[0] = MBOX_GET_INIT_SCSI_ID;
860 isp2x00_mbox_command(host, param);
862 if (param[0] == MBOX_COMMAND_COMPLETE) {
863 hostdata->port_id = ((u_int) param[3]) << 16;
864 hostdata->port_id |= param[2];
865 hostdata->tempmap[0].loop_id = param[1];
866 hostdata->tempmap[0].wwn = hostdata->wwn;
869 printk("qlogicfc%d : error getting scsi id.\n", hostdata->host_id);
872 for (i = 0; i <=QLOGICFC_MAX_ID; i++)
873 hostdata->tempmap[i].loop_id = hostdata->tempmap[0].loop_id;
875 for (i = 0, j = 1; i <= QLOGICFC_MAX_LOOP_ID; i++) {
876 param[0] = MBOX_GET_PORT_NAME;
877 param[1] = (i << 8) & 0xff00;
879 isp2x00_mbox_command(host, param);
881 if (param[0] == MBOX_COMMAND_COMPLETE) {
882 hostdata->tempmap[j].loop_id = i;
883 hostdata->tempmap[j].wwn = ((u64) (param[2] & 0xff)) << 56;
884 hostdata->tempmap[j].wwn |= ((u64) ((param[2] >> 8) & 0xff)) << 48;
885 hostdata->tempmap[j].wwn |= ((u64) (param[3] & 0xff)) << 40;
886 hostdata->tempmap[j].wwn |= ((u64) ((param[3] >> 8) & 0xff)) << 32;
887 hostdata->tempmap[j].wwn |= ((u64) (param[6] & 0xff)) << 24;
888 hostdata->tempmap[j].wwn |= ((u64) ((param[6] >> 8) & 0xff)) << 16;
889 hostdata->tempmap[j].wwn |= ((u64) (param[7] & 0xff)) << 8;
890 hostdata->tempmap[j].wwn |= ((u64) ((param[7] >> 8) & 0xff));
899 isp2x00_init_fabric(host, hostdata->tempmap, j);
902 for (i = 0; i <= QLOGICFC_MAX_ID; i++) {
903 if (hostdata->tempmap[i].wwn != hostdata->port_db[i].wwn) {
904 for (j = 0; j <= QLOGICFC_MAX_ID; j++) {
905 if (hostdata->tempmap[j].wwn == hostdata->port_db[i].wwn) {
906 hostdata->port_db[i].loop_id = hostdata->tempmap[j].loop_id;
910 if (j == QLOGICFC_MAX_ID + 1)
911 hostdata->port_db[i].loop_id = hostdata->tempmap[0].loop_id;
913 for (j = 0; j <= QLOGICFC_MAX_ID; j++) {
914 if (hostdata->port_db[j].wwn == hostdata->tempmap[i].wwn || !hostdata->port_db[j].wwn) {
918 if (j == QLOGICFC_MAX_ID + 1)
919 printk("qlogicfc%d : Too many scsi devices, no more room in port map.\n", hostdata->host_id);
920 if (!hostdata->port_db[j].wwn) {
921 hostdata->port_db[j].loop_id = hostdata->tempmap[i].loop_id;
922 hostdata->port_db[j].wwn = hostdata->tempmap[i].wwn;
925 hostdata->port_db[i].loop_id = hostdata->tempmap[i].loop_id;
929 isp2x00_enable_irqs(host);
937 #define FABRIC_PORT 0x7e
938 #define FABRIC_CONTROLLER 0x7f
939 #define FABRIC_SNS 0x80
941 int isp2x00_init_fabric(struct Scsi_Host *host, struct id_name_map *port_db, int cur_scsi_id)
947 u_short loop_id = 0x81;
948 u_short scsi_id = cur_scsi_id;
951 u_char *sns_response;
953 struct isp2x00_hostdata *hostdata;
955 hostdata = (struct isp2x00_hostdata *) host->hostdata;
957 DEBUG_FABRIC(printk("qlogicfc%d : Checking for a fabric.\n", hostdata->host_id));
958 param[0] = MBOX_GET_PORT_NAME;
959 param[1] = (u16)FABRIC_PORT << 8;
961 isp2x00_mbox_command(host, param);
963 if (param[0] != MBOX_COMMAND_COMPLETE) {
964 DEBUG_FABRIC(printk("qlogicfc%d : fabric check result %x\n", hostdata->host_id, param[0]));
967 printk("qlogicfc%d : Fabric found.\n", hostdata->host_id);
969 req = (struct sns_cb *)pci_alloc_consistent(hostdata->pci_dev, sizeof(*req) + 608, &busaddr);
972 printk("qlogicfc%d : Could not allocate DMA resources for fabric initialization\n", hostdata->host_id);
975 sns_response = (u_char *)(req + 1);
977 if (hostdata->adapter_state & AS_REDO_LOOP_PORTDB){
978 memset(req, 0, sizeof(*req));
980 req->len = cpu_to_le16(8);
981 req->response_low = cpu_to_le32(pci64_dma_lo32(busaddr + sizeof(*req)));
982 req->response_high = cpu_to_le32(pci64_dma_hi32(busaddr + sizeof(*req)));
983 req->sub_len = cpu_to_le16(22);
986 req->data[8] = (u_char) (hostdata->port_id & 0xff);
987 req->data[9] = (u_char) (hostdata->port_id >> 8 & 0xff);
988 req->data[10] = (u_char) (hostdata->port_id >> 16 & 0xff);
989 req->data[13] = 0x01;
990 param[0] = MBOX_SEND_SNS;
992 param[2] = pci64_dma_lo32(busaddr) >> 16;
993 param[3] = pci64_dma_lo32(busaddr);
994 param[6] = pci64_dma_hi32(busaddr) >> 16;
995 param[7] = pci64_dma_hi32(busaddr);
997 isp2x00_mbox_command(host, param);
999 if (param[0] != MBOX_COMMAND_COMPLETE)
1000 printk("qlogicfc%d : error sending RFC-4\n", hostdata->host_id);
1003 port_id = hostdata->port_id;
1005 memset(req, 0, sizeof(*req));
1007 req->len = cpu_to_le16(304);
1008 req->response_low = cpu_to_le32(pci64_dma_lo32(busaddr + sizeof(*req)));
1009 req->response_high = cpu_to_le32(pci64_dma_hi32(busaddr + sizeof(*req)));
1010 req->sub_len = cpu_to_le16(6);
1011 req->data[0] = 0x00;
1012 req->data[1] = 0x01;
1013 req->data[8] = (u_char) (port_id & 0xff);
1014 req->data[9] = (u_char) (port_id >> 8 & 0xff);
1015 req->data[10] = (u_char) (port_id >> 16 & 0xff);
1017 param[0] = MBOX_SEND_SNS;
1019 param[2] = pci64_dma_lo32(busaddr) >> 16;
1020 param[3] = pci64_dma_lo32(busaddr);
1021 param[6] = pci64_dma_hi32(busaddr) >> 16;
1022 param[7] = pci64_dma_hi32(busaddr);
1024 isp2x00_mbox_command(host, param);
1026 if (param[0] == MBOX_COMMAND_COMPLETE) {
1027 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]));
1028 DEBUG_FABRIC(printk(" port id: %02x%02x%02x\n", sns_response[17], sns_response[18], sns_response[19]));
1029 port_id = ((u_int) sns_response[17]) << 16;
1030 port_id |= ((u_int) sns_response[18]) << 8;
1031 port_id |= ((u_int) sns_response[19]);
1032 wwn = ((u64) sns_response[20]) << 56;
1033 wwn |= ((u64) sns_response[21]) << 48;
1034 wwn |= ((u64) sns_response[22]) << 40;
1035 wwn |= ((u64) sns_response[23]) << 32;
1036 wwn |= ((u64) sns_response[24]) << 24;
1037 wwn |= ((u64) sns_response[25]) << 16;
1038 wwn |= ((u64) sns_response[26]) << 8;
1039 wwn |= ((u64) sns_response[27]);
1040 if (hostdata->port_id >> 8 != port_id >> 8) {
1041 DEBUG_FABRIC(printk("qlogicfc%d : adding a fabric port: %x\n", hostdata->host_id, port_id));
1042 param[0] = MBOX_PORT_LOGIN;
1043 param[1] = loop_id << 8;
1044 param[2] = (u_short) (port_id >> 16);
1045 param[3] = (u_short) (port_id);
1047 isp2x00_mbox_command(host, param);
1049 if (param[0] == MBOX_COMMAND_COMPLETE) {
1050 port_db[scsi_id].wwn = wwn;
1051 port_db[scsi_id].loop_id = loop_id;
1055 printk("qlogicfc%d : Error performing port login %x\n", hostdata->host_id, param[0]);
1056 DEBUG_FABRIC(printk("qlogicfc%d : loop_id: %x\n", hostdata->host_id, loop_id));
1057 param[0] = MBOX_PORT_LOGOUT;
1058 param[1] = loop_id << 8;
1062 isp2x00_mbox_command(host, param);
1067 if (hostdata->port_id == port_id)
1070 printk("qlogicfc%d : Get All Next failed %x.\n", hostdata->host_id, param[0]);
1071 pci_free_consistent(hostdata->pci_dev, sizeof(*req) + 608, req, busaddr);
1076 pci_free_consistent(hostdata->pci_dev, sizeof(*req) + 608, req, busaddr);
1080 #endif /* ISP2x00_FABRIC */
1083 int isp2x00_release(struct Scsi_Host *host)
1085 struct isp2x00_hostdata *hostdata;
1088 ENTER("isp2x00_release");
1090 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1092 outw(0x0, host->io_port + PCI_INTER_CTL);
1093 free_irq(host->irq, host);
1095 release_region(host->io_port, 0xff);
1097 busaddr = pci64_dma_build(le32_to_cpu(hostdata->control_block.res_queue_addr_high),
1098 le32_to_cpu(hostdata->control_block.res_queue_addr_lo));
1099 pci_free_consistent(hostdata->pci_dev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
1101 LEAVE("isp2x00_release");
1107 const char *isp2x00_info(struct Scsi_Host *host)
1109 static char buf[80];
1110 struct isp2x00_hostdata *hostdata;
1111 ENTER("isp2x00_info");
1113 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1115 "QLogic ISP%04x SCSI on PCI bus %02x device %02x irq %d base 0x%lx",
1116 hostdata->pci_dev->device, hostdata->pci_dev->bus->number, hostdata->pci_dev->devfn, host->irq,
1120 LEAVE("isp2x00_info");
1127 * The middle SCSI layer ensures that queuecommand never gets invoked
1128 * concurrently with itself or the interrupt handler (though the
1129 * interrupt handler may call this routine as part of
1130 * request-completion handling).
1132 int isp2x00_queuecommand(Scsi_Cmnd * Cmnd, void (*done) (Scsi_Cmnd *))
1134 int i, sg_count, n, num_free;
1135 u_int in_ptr, out_ptr;
1137 struct scatterlist *sg;
1138 struct Command_Entry *cmd;
1139 struct Continuation_Entry *cont;
1140 struct Scsi_Host *host;
1141 struct isp2x00_hostdata *hostdata;
1143 ENTER("isp2x00_queuecommand");
1145 host = Cmnd->device->host;
1146 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1147 Cmnd->scsi_done = done;
1149 DEBUG(isp2x00_print_scsi_cmd(Cmnd));
1151 if (hostdata->adapter_state & AS_REDO_FABRIC_PORTDB || hostdata->adapter_state & AS_REDO_LOOP_PORTDB) {
1152 isp2x00_make_portdb(host);
1153 hostdata->adapter_state = AS_LOOP_GOOD;
1154 printk("qlogicfc%d : Port Database\n", hostdata->host_id);
1155 for (i = 0; hostdata->port_db[i].wwn != 0; i++) {
1156 printk("wwn: %08x%08x scsi_id: %x loop_id: ", (u_int) (hostdata->port_db[i].wwn >> 32), (u_int) hostdata->port_db[i].wwn, i);
1157 if (hostdata->port_db[i].loop_id != hostdata->port_db[0].loop_id || i == 0)
1158 printk("%x", hostdata->port_db[i].loop_id);
1160 printk("Not Available");
1164 if (hostdata->adapter_state == AS_FIRMWARE_DEAD) {
1165 printk("qlogicfc%d : The firmware is dead, just return.\n", hostdata->host_id);
1170 out_ptr = inw(host->io_port + MBOX4);
1171 in_ptr = hostdata->req_in_ptr;
1173 DEBUG(printk("qlogicfc%d : request queue depth %d\n", hostdata->host_id,
1174 REQ_QUEUE_DEPTH(in_ptr, out_ptr)));
1176 cmd = (struct Command_Entry *) &hostdata->req[in_ptr*QUEUE_ENTRY_LEN];
1177 in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
1178 if (in_ptr == out_ptr) {
1179 DEBUG(printk("qlogicfc%d : request queue overflow\n", hostdata->host_id));
1182 if (hostdata->send_marker) {
1183 struct Marker_Entry *marker;
1185 TRACE("queue marker", in_ptr, 0);
1187 DEBUG(printk("qlogicfc%d : adding marker entry\n", hostdata->host_id));
1188 marker = (struct Marker_Entry *) cmd;
1189 memset(marker, 0, sizeof(struct Marker_Entry));
1191 marker->hdr.entry_type = ENTRY_MARKER;
1192 marker->hdr.entry_cnt = 1;
1193 marker->modifier = SYNC_ALL;
1195 hostdata->send_marker = 0;
1197 if (((in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN) == out_ptr) {
1198 outw(in_ptr, host->io_port + MBOX4);
1199 hostdata->req_in_ptr = in_ptr;
1200 DEBUG(printk("qlogicfc%d : request queue overflow\n", hostdata->host_id));
1203 cmd = (struct Command_Entry *) &hostdata->req[in_ptr*QUEUE_ENTRY_LEN];
1204 in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
1206 TRACE("queue command", in_ptr, Cmnd);
1208 memset(cmd, 0, sizeof(struct Command_Entry));
1210 /* find a free handle mapping slot */
1211 for (i = in_ptr; i != (in_ptr - 1) && hostdata->handle_ptrs[i]; i = ((i + 1) % (QLOGICFC_REQ_QUEUE_LEN + 1)));
1213 if (!hostdata->handle_ptrs[i]) {
1214 cmd->handle = cpu_to_le32(i);
1215 hostdata->handle_ptrs[i] = Cmnd;
1216 hostdata->handle_serials[i] = Cmnd->serial_number;
1218 printk("qlogicfc%d : no handle slots, this should not happen.\n", hostdata->host_id);
1219 printk("hostdata->queued is %x, in_ptr: %x\n", hostdata->queued, in_ptr);
1220 for (i = 0; i <= QLOGICFC_REQ_QUEUE_LEN; i++){
1221 if (!hostdata->handle_ptrs[i]){
1222 printk("slot %d has %p\n", i, hostdata->handle_ptrs[i]);
1228 cmd->hdr.entry_type = ENTRY_COMMAND;
1229 cmd->hdr.entry_cnt = 1;
1230 cmd->target_lun = Cmnd->device->lun;
1231 cmd->expanded_lun = cpu_to_le16(Cmnd->device->lun);
1233 cmd->target_id = hostdata->port_db[Cmnd->device->id].loop_id;
1235 cmd->target_id = Cmnd->target;
1237 cmd->total_byte_cnt = cpu_to_le32(Cmnd->request_bufflen);
1239 memcpy(cmd->cdb, Cmnd->cmnd, Cmnd->cmd_len);
1242 sg = (struct scatterlist *) Cmnd->request_buffer;
1243 sg_count = pci_map_sg(hostdata->pci_dev, sg, Cmnd->use_sg, scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
1244 cmd->segment_cnt = cpu_to_le16(sg_count);
1246 /* fill in first two sg entries: */
1248 if (n > DATASEGS_PER_COMMAND)
1249 n = DATASEGS_PER_COMMAND;
1251 for (i = 0; i < n; i++) {
1252 ds[i].d_base = cpu_to_le32(pci64_dma_lo32(sg_dma_address(sg)));
1253 ds[i].d_base_hi = cpu_to_le32(pci64_dma_hi32(sg_dma_address(sg)));
1254 ds[i].d_count = cpu_to_le32(sg_dma_len(sg));
1257 sg_count -= DATASEGS_PER_COMMAND;
1259 while (sg_count > 0) {
1260 ++cmd->hdr.entry_cnt;
1261 cont = (struct Continuation_Entry *)
1262 &hostdata->req[in_ptr*QUEUE_ENTRY_LEN];
1263 memset(cont, 0, sizeof(struct Continuation_Entry));
1264 in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
1265 if (in_ptr == out_ptr) {
1266 DEBUG(printk("qlogicfc%d : unexpected request queue overflow\n", hostdata->host_id));
1269 TRACE("queue continuation", in_ptr, 0);
1270 cont->hdr.entry_type = ENTRY_CONTINUATION;
1273 if (n > DATASEGS_PER_CONT)
1274 n = DATASEGS_PER_CONT;
1275 for (i = 0; i < n; ++i) {
1276 ds[i].d_base = cpu_to_le32(pci64_dma_lo32(sg_dma_address(sg)));
1277 ds[i].d_base_hi = cpu_to_le32(pci64_dma_hi32(sg_dma_address(sg)));
1278 ds[i].d_count = cpu_to_le32(sg_dma_len(sg));
1283 } else if (Cmnd->request_bufflen && Cmnd->sc_data_direction != PCI_DMA_NONE) {
1284 struct page *page = virt_to_page(Cmnd->request_buffer);
1285 unsigned long offset = offset_in_page(Cmnd->request_buffer);
1286 dma_addr_t busaddr = pci_map_page(hostdata->pci_dev,
1288 Cmnd->request_bufflen,
1289 scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
1290 Cmnd->SCp.dma_handle = busaddr;
1292 cmd->dataseg[0].d_base = cpu_to_le32(pci64_dma_lo32(busaddr));
1293 cmd->dataseg[0].d_base_hi = cpu_to_le32(pci64_dma_hi32(busaddr));
1294 cmd->dataseg[0].d_count = cpu_to_le32(Cmnd->request_bufflen);
1295 cmd->segment_cnt = cpu_to_le16(1);
1297 cmd->dataseg[0].d_base = 0;
1298 cmd->dataseg[0].d_base_hi = 0;
1299 cmd->segment_cnt = cpu_to_le16(1); /* Shouldn't this be 0? */
1302 if (Cmnd->sc_data_direction == SCSI_DATA_WRITE)
1303 cmd->control_flags = cpu_to_le16(CFLAG_WRITE);
1305 cmd->control_flags = cpu_to_le16(CFLAG_READ);
1307 if (Cmnd->device->tagged_supported) {
1308 if ((jiffies - hostdata->tag_ages[Cmnd->device->id]) > (2 * SCSI_TIMEOUT)) {
1309 cmd->control_flags |= cpu_to_le16(CFLAG_ORDERED_TAG);
1310 hostdata->tag_ages[Cmnd->device->id] = jiffies;
1312 switch (Cmnd->tag) {
1313 case HEAD_OF_QUEUE_TAG:
1314 cmd->control_flags |= cpu_to_le16(CFLAG_HEAD_TAG);
1316 case ORDERED_QUEUE_TAG:
1317 cmd->control_flags |= cpu_to_le16(CFLAG_ORDERED_TAG);
1320 cmd->control_flags |= cpu_to_le16(CFLAG_SIMPLE_TAG);
1325 * TEST_UNIT_READY commands from scsi_scan will fail due to "overlapped
1326 * commands attempted" unless we setup at least a simple queue (midlayer
1327 * will embelish this once it can do an INQUIRY command to the device)
1330 cmd->control_flags |= cpu_to_le16(CFLAG_SIMPLE_TAG);
1331 outw(in_ptr, host->io_port + MBOX4);
1332 hostdata->req_in_ptr = in_ptr;
1336 num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
1337 num_free = (num_free > 2) ? num_free - 2 : 0;
1338 host->can_queue = host->host_busy + num_free;
1339 if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)
1340 host->can_queue = QLOGICFC_REQ_QUEUE_LEN;
1341 host->sg_tablesize = QLOGICFC_MAX_SG(num_free);
1343 LEAVE("isp2x00_queuecommand");
1349 /* we have received an event, such as a lip or an RSCN, which may mean that
1350 * our port database is incorrect so the port database must be recreated.
1352 static void redo_port_db(unsigned long arg)
1355 struct Scsi_Host * host = (struct Scsi_Host *) arg;
1356 struct isp2x00_hostdata * hostdata;
1357 unsigned long flags;
1360 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1361 hostdata->explore_timer.data = 0;
1362 del_timer(&hostdata->explore_timer);
1364 spin_lock_irqsave(host->host_lock, flags);
1366 if (hostdata->adapter_state & AS_REDO_FABRIC_PORTDB || hostdata->adapter_state & AS_REDO_LOOP_PORTDB) {
1367 isp2x00_make_portdb(host);
1368 printk("qlogicfc%d : Port Database\n", hostdata->host_id);
1369 for (i = 0; hostdata->port_db[i].wwn != 0; i++) {
1370 printk("wwn: %08x%08x scsi_id: %x loop_id: ", (u_int) (hostdata->port_db[i].wwn >> 32), (u_int) hostdata->port_db[i].wwn, i);
1371 if (hostdata->port_db[i].loop_id != hostdata->port_db[0].loop_id || i == 0)
1372 printk("%x", hostdata->port_db[i].loop_id);
1374 printk("Not Available");
1378 for (i = 0; i < QLOGICFC_REQ_QUEUE_LEN; i++){
1379 if (hostdata->handle_ptrs[i] && (hostdata->port_db[hostdata->handle_ptrs[i]->device->id].loop_id > QLOGICFC_MAX_LOOP_ID || hostdata->adapter_state & AS_REDO_LOOP_PORTDB)){
1380 if (hostdata->port_db[hostdata->handle_ptrs[i]->device->id].loop_id != hostdata->port_db[0].loop_id){
1381 Scsi_Cmnd *Cmnd = hostdata->handle_ptrs[i];
1384 pci_unmap_sg(hostdata->pci_dev,
1385 (struct scatterlist *)Cmnd->buffer,
1387 scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
1388 else if (Cmnd->request_bufflen &&
1389 Cmnd->sc_data_direction != PCI_DMA_NONE) {
1390 pci_unmap_page(hostdata->pci_dev,
1391 Cmnd->SCp.dma_handle,
1392 Cmnd->request_bufflen,
1393 scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
1396 hostdata->handle_ptrs[i]->result = DID_SOFT_ERROR << 16;
1398 if (hostdata->handle_ptrs[i]->scsi_done){
1399 (*hostdata->handle_ptrs[i]->scsi_done) (hostdata->handle_ptrs[i]);
1401 else printk("qlogicfc%d : done is null?\n", hostdata->host_id);
1402 hostdata->handle_ptrs[i] = NULL;
1403 hostdata->handle_serials[i] = 0;
1408 hostdata->adapter_state = AS_LOOP_GOOD;
1411 spin_unlock_irqrestore(host->host_lock, flags);
1415 #define ASYNC_EVENT_INTERRUPT 0x01
1417 irqreturn_t do_isp2x00_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1419 struct Scsi_Host *host = dev_id;
1420 unsigned long flags;
1422 spin_lock_irqsave(host->host_lock, flags);
1423 isp2x00_intr_handler(irq, dev_id, regs);
1424 spin_unlock_irqrestore(host->host_lock, flags);
1429 void isp2x00_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1432 struct Status_Entry *sts;
1433 struct Scsi_Host *host = dev_id;
1434 struct isp2x00_hostdata *hostdata;
1435 u_int in_ptr, out_ptr, handle, num_free;
1438 ENTER_INTR("isp2x00_intr_handler");
1440 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1442 DEBUG_INTR(printk("qlogicfc%d : interrupt on line %d\n", hostdata->host_id, irq));
1444 if (!(inw(host->io_port + PCI_INTER_STS) & 0x08)) {
1445 /* spurious interrupts can happen legally */
1446 DEBUG_INTR(printk("qlogicfc%d : got spurious interrupt\n", hostdata->host_id));
1449 in_ptr = inw(host->io_port + MBOX5);
1450 out_ptr = hostdata->res_out_ptr;
1452 if ((inw(host->io_port + PCI_SEMAPHORE) & ASYNC_EVENT_INTERRUPT)) {
1453 status = inw(host->io_port + MBOX0);
1455 DEBUG_INTR(printk("qlogicfc%d : mbox completion status: %x\n",
1456 hostdata->host_id, status));
1460 case POINT_TO_POINT_UP:
1461 printk("qlogicfc%d : Link is Up\n", hostdata->host_id);
1462 hostdata->adapter_state = AS_REDO_FABRIC_PORTDB | AS_REDO_LOOP_PORTDB;
1465 printk("qlogicfc%d : Link is Down\n", hostdata->host_id);
1466 hostdata->adapter_state = AS_LOOP_DOWN;
1468 case CONNECTION_MODE:
1469 printk("received CONNECTION_MODE irq %x\n", inw(host->io_port + MBOX1));
1471 case CHANGE_NOTIFICATION:
1472 printk("qlogicfc%d : RSCN Received\n", hostdata->host_id);
1473 if (hostdata->adapter_state == AS_LOOP_GOOD)
1474 hostdata->adapter_state = AS_REDO_FABRIC_PORTDB;
1478 printk("qlogicfc%d : Loop Reinitialized\n", hostdata->host_id);
1479 if (hostdata->adapter_state == AS_LOOP_GOOD)
1480 hostdata->adapter_state = AS_REDO_LOOP_PORTDB;
1483 printk("qlogicfc%d : The firmware just choked.\n", hostdata->host_id);
1484 hostdata->adapter_state = AS_FIRMWARE_DEAD;
1486 case SCSI_COMMAND_COMPLETE:
1487 handle = inw(host->io_port + MBOX1) | (inw(host->io_port + MBOX2) << 16);
1488 Cmnd = hostdata->handle_ptrs[handle];
1489 hostdata->handle_ptrs[handle] = NULL;
1490 hostdata->handle_serials[handle] = 0;
1494 pci_unmap_sg(hostdata->pci_dev,
1495 (struct scatterlist *)Cmnd->buffer,
1497 scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
1498 else if (Cmnd->request_bufflen &&
1499 Cmnd->sc_data_direction != PCI_DMA_NONE)
1500 pci_unmap_page(hostdata->pci_dev,
1501 Cmnd->SCp.dma_handle,
1502 Cmnd->request_bufflen,
1503 scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
1505 (*Cmnd->scsi_done) (Cmnd);
1507 printk("qlogicfc%d.c : got a null value out of handle_ptrs, this sucks\n", hostdata->host_id);
1509 case MBOX_COMMAND_COMPLETE:
1510 case INVALID_COMMAND:
1511 case HOST_INTERFACE_ERROR:
1514 case COMMAND_PARAM_ERROR:
1518 hostdata->mbox_done = 1;
1519 outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
1522 printk("qlogicfc%d : got an unknown status? %x\n", hostdata->host_id, status);
1524 if ((hostdata->adapter_state & AS_REDO_LOOP_PORTDB || hostdata->adapter_state & AS_REDO_FABRIC_PORTDB) && hostdata->explore_timer.data == 0){
1525 hostdata->explore_timer.function = redo_port_db;
1526 hostdata->explore_timer.data = (unsigned long)host;
1527 hostdata->explore_timer.expires = jiffies + (HZ/4);
1528 init_timer(&hostdata->explore_timer);
1529 add_timer(&hostdata->explore_timer);
1531 outw(0x0, host->io_port + PCI_SEMAPHORE);
1533 DEBUG_INTR(printk("qlogicfc%d : response queue update\n", hostdata->host_id));
1534 DEBUG_INTR(printk("qlogicfc%d : response queue depth %d\n", hostdata->host_id, RES_QUEUE_DEPTH(in_ptr, out_ptr)));
1536 while (out_ptr != in_ptr) {
1538 sts = (struct Status_Entry *) &hostdata->res[out_ptr*QUEUE_ENTRY_LEN];
1539 out_ptr = (out_ptr + 1) & RES_QUEUE_LEN;
1541 TRACE("done", out_ptr, Cmnd);
1542 DEBUG_INTR(isp2x00_print_status_entry(sts));
1543 le_hand = le32_to_cpu(sts->handle);
1544 if (sts->hdr.entry_type == ENTRY_STATUS && (Cmnd = hostdata->handle_ptrs[le_hand])) {
1545 Cmnd->result = isp2x00_return_status(Cmnd, sts);
1549 pci_unmap_sg(hostdata->pci_dev,
1550 (struct scatterlist *)Cmnd->buffer, Cmnd->use_sg,
1551 scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
1552 else if (Cmnd->request_bufflen && Cmnd->sc_data_direction != PCI_DMA_NONE)
1553 pci_unmap_page(hostdata->pci_dev,
1554 Cmnd->SCp.dma_handle,
1555 Cmnd->request_bufflen,
1556 scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
1559 * if any of the following are true we do not
1560 * call scsi_done. if the status is CS_ABORTED
1561 * we don't have to call done because the upper
1562 * level should already know its aborted.
1564 if (hostdata->handle_serials[le_hand] != Cmnd->serial_number
1565 || le16_to_cpu(sts->completion_status) == CS_ABORTED){
1566 hostdata->handle_serials[le_hand] = 0;
1567 hostdata->handle_ptrs[le_hand] = NULL;
1568 outw(out_ptr, host->io_port + MBOX5);
1572 * if we get back an error indicating the port
1573 * is not there or if the link is down and
1574 * this is a device that used to be there
1575 * allow the command to timeout.
1576 * the device may well be back in a couple of
1579 if ((hostdata->adapter_state == AS_LOOP_DOWN || sts->completion_status == cpu_to_le16(CS_PORT_UNAVAILABLE) || sts->completion_status == cpu_to_le16(CS_PORT_LOGGED_OUT) || sts->completion_status == cpu_to_le16(CS_PORT_CONFIG_CHANGED)) && hostdata->port_db[Cmnd->device->id].wwn){
1580 outw(out_ptr, host->io_port + MBOX5);
1584 outw(out_ptr, host->io_port + MBOX5);
1588 hostdata->handle_ptrs[le_hand] = NULL;
1590 if (sts->completion_status == cpu_to_le16(CS_RESET_OCCURRED)
1591 || (sts->status_flags & cpu_to_le16(STF_BUS_RESET)))
1592 hostdata->send_marker = 1;
1594 if (le16_to_cpu(sts->scsi_status) & 0x0200)
1595 memcpy(Cmnd->sense_buffer, sts->req_sense_data,
1596 sizeof(Cmnd->sense_buffer));
1598 outw(out_ptr, host->io_port + MBOX5);
1600 if (Cmnd->scsi_done != NULL) {
1601 (*Cmnd->scsi_done) (Cmnd);
1603 printk("qlogicfc%d : Ouch, scsi done is NULL\n", hostdata->host_id);
1605 hostdata->res_out_ptr = out_ptr;
1609 out_ptr = inw(host->io_port + MBOX4);
1610 in_ptr = hostdata->req_in_ptr;
1612 num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
1613 num_free = (num_free > 2) ? num_free - 2 : 0;
1614 host->can_queue = host->host_busy + num_free;
1615 if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)
1616 host->can_queue = QLOGICFC_REQ_QUEUE_LEN;
1617 host->sg_tablesize = QLOGICFC_MAX_SG(num_free);
1619 outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
1620 LEAVE_INTR("isp2x00_intr_handler");
1624 static int isp2x00_return_status(Scsi_Cmnd *Cmnd, struct Status_Entry *sts)
1626 int host_status = DID_ERROR;
1627 #if DEBUG_ISP2x00_INTR
1628 static char *reason[] =
1641 #endif /* DEBUG_ISP2x00_INTR */
1643 ENTER("isp2x00_return_status");
1645 DEBUG(printk("qlogicfc : completion status = 0x%04x\n",
1646 le16_to_cpu(sts->completion_status)));
1648 switch (le16_to_cpu(sts->completion_status)) {
1650 host_status = DID_OK;
1653 host_status = DID_ERROR;
1655 case CS_RESET_OCCURRED:
1656 host_status = DID_RESET;
1659 host_status = DID_ABORT;
1662 host_status = DID_TIME_OUT;
1664 case CS_DATA_OVERRUN:
1665 host_status = DID_ERROR;
1667 case CS_DATA_UNDERRUN:
1668 if (Cmnd->underflow <= (Cmnd->request_bufflen - le32_to_cpu(sts->residual)))
1669 host_status = DID_OK;
1671 host_status = DID_ERROR;
1673 case CS_PORT_UNAVAILABLE:
1674 case CS_PORT_LOGGED_OUT:
1675 case CS_PORT_CONFIG_CHANGED:
1676 host_status = DID_BAD_TARGET;
1679 host_status = DID_ERROR;
1682 printk("qlogicfc : unknown completion status 0x%04x\n",
1683 le16_to_cpu(sts->completion_status));
1684 host_status = DID_ERROR;
1688 DEBUG_INTR(printk("qlogicfc : host status (%s) scsi status %x\n",
1689 reason[host_status], le16_to_cpu(sts->scsi_status)));
1691 LEAVE("isp2x00_return_status");
1693 return (le16_to_cpu(sts->scsi_status) & STATUS_MASK) | (host_status << 16);
1697 int isp2x00_abort(Scsi_Cmnd * Cmnd)
1701 struct Scsi_Host *host;
1702 struct isp2x00_hostdata *hostdata;
1703 int return_status = SUCCESS;
1705 ENTER("isp2x00_abort");
1707 host = Cmnd->device->host;
1708 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1710 for (i = 0; i < QLOGICFC_REQ_QUEUE_LEN; i++)
1711 if (hostdata->handle_ptrs[i] == Cmnd)
1714 if (i == QLOGICFC_REQ_QUEUE_LEN){
1718 isp2x00_disable_irqs(host);
1720 param[0] = MBOX_ABORT_IOCB;
1722 param[1] = (((u_short) hostdata->port_db[Cmnd->device->id].loop_id) << 8) | Cmnd->device->lun;
1724 param[1] = (((u_short) Cmnd->target) << 8) | Cmnd->lun;
1726 param[2] = i & 0xffff;
1729 isp2x00_mbox_command(host, param);
1731 if (param[0] != MBOX_COMMAND_COMPLETE) {
1732 printk("qlogicfc%d : scsi abort failure: %x\n", hostdata->host_id, param[0]);
1733 if (param[0] == 0x4005)
1734 Cmnd->result = DID_ERROR << 16;
1735 if (param[0] == 0x4006)
1736 Cmnd->result = DID_BAD_TARGET << 16;
1737 return_status = FAILED;
1740 if (return_status != SUCCESS){
1741 param[0] = MBOX_GET_FIRMWARE_STATE;
1742 isp2x00_mbox_command(host, param);
1743 printk("qlogicfc%d : abort failed\n", hostdata->host_id);
1744 printk("qlogicfc%d : firmware status is %x %x\n", hostdata->host_id, param[0], param[1]);
1747 isp2x00_enable_irqs(host);
1749 LEAVE("isp2x00_abort");
1751 return return_status;
1755 int isp2x00_reset(Scsi_Cmnd * Cmnd, unsigned int reset_flags)
1758 struct Scsi_Host *host;
1759 struct isp2x00_hostdata *hostdata;
1760 int return_status = SCSI_RESET_SUCCESS;
1762 ENTER("isp2x00_reset");
1764 host = Cmnd->device->host;
1765 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1766 param[0] = MBOX_BUS_RESET;
1769 isp2x00_disable_irqs(host);
1771 isp2x00_mbox_command(host, param);
1773 if (param[0] != MBOX_COMMAND_COMPLETE) {
1774 printk("qlogicfc%d : scsi bus reset failure: %x\n", hostdata->host_id, param[0]);
1775 return_status = SCSI_RESET_ERROR;
1777 isp2x00_enable_irqs(host);
1779 LEAVE("isp2x00_reset");
1781 return return_status;
1785 int isp2x00_biosparam(struct scsi_device *sdev, struct block_device *n,
1786 sector_t capacity, int ip[])
1788 int size = capacity;
1790 ENTER("isp2x00_biosparam");
1798 ip[2] = size / (ip[0] * ip[1]);
1800 LEAVE("isp2x00_biosparam");
1805 static int isp2x00_reset_hardware(struct Scsi_Host *host)
1808 struct isp2x00_hostdata *hostdata;
1812 ENTER("isp2x00_reset_hardware");
1814 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1817 * This cannot be right - PCI writes are posted
1818 * (apparently this is hardware design flaw not software ?)
1821 outw(0x01, host->io_port + ISP_CTRL_STATUS);
1823 outw(HCCR_RESET, host->io_port + HOST_HCCR);
1825 outw(HCCR_RELEASE, host->io_port + HOST_HCCR);
1826 outw(HCCR_BIOS_DISABLE, host->io_port + HOST_HCCR);
1828 loop_count = DEFAULT_LOOP_COUNT;
1829 while (--loop_count && inw(host->io_port + HOST_HCCR) == RISC_BUSY) {
1834 printk("qlogicfc%d : reset_hardware loop timeout\n", hostdata->host_id);
1839 printk("qlogicfc%d : mbox 0 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX0));
1840 printk("qlogicfc%d : mbox 1 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX1));
1841 printk("qlogicfc%d : mbox 2 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX2));
1842 printk("qlogicfc%d : mbox 3 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX3));
1843 printk("qlogicfc%d : mbox 4 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX4));
1844 printk("qlogicfc%d : mbox 5 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX5));
1845 printk("qlogicfc%d : mbox 6 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX6));
1846 printk("qlogicfc%d : mbox 7 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX7));
1847 #endif /* DEBUG_ISP2x00 */
1849 DEBUG(printk("qlogicfc%d : verifying checksum\n", hostdata->host_id));
1851 #if defined(CONFIG_SCSI_QLOGIC_FC_FIRMWARE)
1854 unsigned short * risc_code = NULL;
1855 unsigned short risc_code_len = 0;
1856 if (hostdata->pci_dev->device == PCI_DEVICE_ID_QLOGIC_ISP2100){
1857 risc_code = risc_code2100;
1858 risc_code_len = risc_code_length2100;
1860 else if (hostdata->pci_dev->device == PCI_DEVICE_ID_QLOGIC_ISP2200){
1861 risc_code = risc_code2200;
1862 risc_code_len = risc_code_length2200;
1865 for (i = 0; i < risc_code_len; i++) {
1866 param[0] = MBOX_WRITE_RAM_WORD;
1867 param[1] = risc_code_addr01 + i;
1868 param[2] = risc_code[i];
1870 isp2x00_mbox_command(host, param);
1872 if (param[0] != MBOX_COMMAND_COMPLETE) {
1873 printk("qlogicfc%d : firmware load failure\n", hostdata->host_id);
1878 #endif /* RELOAD_FIRMWARE */
1880 param[0] = MBOX_VERIFY_CHECKSUM;
1881 param[1] = risc_code_addr01;
1883 isp2x00_mbox_command(host, param);
1885 if (param[0] != MBOX_COMMAND_COMPLETE) {
1886 printk("qlogicfc%d : ram checksum failure\n", hostdata->host_id);
1889 DEBUG(printk("qlogicfc%d : executing firmware\n", hostdata->host_id));
1891 param[0] = MBOX_EXEC_FIRMWARE;
1892 param[1] = risc_code_addr01;
1894 isp2x00_mbox_command(host, param);
1896 param[0] = MBOX_ABOUT_FIRMWARE;
1898 isp2x00_mbox_command(host, param);
1900 if (param[0] != MBOX_COMMAND_COMPLETE) {
1901 printk("qlogicfc%d : about firmware failure\n", hostdata->host_id);
1904 DEBUG(printk("qlogicfc%d : firmware major revision %d\n", hostdata->host_id, param[1]));
1905 DEBUG(printk("qlogicfc%d : firmware minor revision %d\n", hostdata->host_id, param[2]));
1907 #ifdef USE_NVRAM_DEFAULTS
1909 if (isp2x00_get_nvram_defaults(host, &hostdata->control_block) != 0) {
1910 printk("qlogicfc%d : Could not read from NVRAM\n", hostdata->host_id);
1914 hostdata->wwn = (u64) (cpu_to_le16(hostdata->control_block.node_name[0])) << 56;
1915 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[0]) & 0xff00) << 48;
1916 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[1]) & 0xff00) << 24;
1917 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[1]) & 0x00ff) << 48;
1918 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[2]) & 0x00ff) << 24;
1919 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[2]) & 0xff00) << 8;
1920 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[3]) & 0x00ff) << 8;
1921 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[3]) & 0xff00) >> 8;
1923 /* FIXME: If the DMA transfer goes one way only, this should use
1924 * PCI_DMA_TODEVICE and below as well.
1926 busaddr = pci_map_page(hostdata->pci_dev,
1927 virt_to_page(&hostdata->control_block),
1928 offset_in_page(&hostdata->control_block),
1929 sizeof(hostdata->control_block),
1930 PCI_DMA_BIDIRECTIONAL);
1932 param[0] = MBOX_INIT_FIRMWARE;
1933 param[2] = (u_short) (pci64_dma_lo32(busaddr) >> 16);
1934 param[3] = (u_short) (pci64_dma_lo32(busaddr) & 0xffff);
1937 param[6] = (u_short) (pci64_dma_hi32(busaddr) >> 16);
1938 param[7] = (u_short) (pci64_dma_hi32(busaddr) & 0xffff);
1939 isp2x00_mbox_command(host, param);
1940 if (param[0] != MBOX_COMMAND_COMPLETE) {
1941 printk("qlogicfc%d.c: Ouch 0x%04x\n", hostdata->host_id, param[0]);
1942 pci_unmap_page(hostdata->pci_dev, busaddr,
1943 sizeof(hostdata->control_block),
1944 PCI_DMA_BIDIRECTIONAL);
1947 param[0] = MBOX_GET_FIRMWARE_STATE;
1948 isp2x00_mbox_command(host, param);
1949 if (param[0] != MBOX_COMMAND_COMPLETE) {
1950 printk("qlogicfc%d.c: 0x%04x\n", hostdata->host_id, param[0]);
1951 pci_unmap_page(hostdata->pci_dev, busaddr,
1952 sizeof(hostdata->control_block),
1953 PCI_DMA_BIDIRECTIONAL);
1957 pci_unmap_page(hostdata->pci_dev, busaddr,
1958 sizeof(hostdata->control_block),
1959 PCI_DMA_BIDIRECTIONAL);
1960 LEAVE("isp2x00_reset_hardware");
1965 #ifdef USE_NVRAM_DEFAULTS
1967 static int isp2x00_get_nvram_defaults(struct Scsi_Host *host, struct init_cb *control_block)
1971 if (isp2x00_read_nvram_word(host, 0) != 0x5349)
1974 value = isp2x00_read_nvram_word(host, 8);
1975 control_block->node_name[0] = cpu_to_le16(isp2x00_read_nvram_word(host, 9));
1976 control_block->node_name[1] = cpu_to_le16(isp2x00_read_nvram_word(host, 10));
1977 control_block->node_name[2] = cpu_to_le16(isp2x00_read_nvram_word(host, 11));
1978 control_block->node_name[3] = cpu_to_le16(isp2x00_read_nvram_word(host, 12));
1979 control_block->hard_addr = cpu_to_le16(isp2x00_read_nvram_word(host, 13));
1987 static int isp2x00_init(struct Scsi_Host *sh)
1990 struct isp2x00_hostdata *hostdata;
1994 struct pci_dev *pdev;
1997 ENTER("isp2x00_init");
1999 hostdata = (struct isp2x00_hostdata *) sh->hostdata;
2000 pdev = hostdata->pci_dev;
2002 if (pci_read_config_word(pdev, PCI_COMMAND, &command)
2003 || pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision)) {
2004 printk("qlogicfc%d : error reading PCI configuration\n", hostdata->host_id);
2007 io_base = pci_resource_start(pdev, 0);
2011 if (pdev->vendor != PCI_VENDOR_ID_QLOGIC) {
2012 printk("qlogicfc%d : 0x%04x is not QLogic vendor ID\n", hostdata->host_id,
2016 if (pdev->device != PCI_DEVICE_ID_QLOGIC_ISP2100 && pdev->device != PCI_DEVICE_ID_QLOGIC_ISP2200) {
2017 printk("qlogicfc%d : 0x%04x does not match ISP2100 or ISP2200 device id\n", hostdata->host_id,
2021 if (!(command & PCI_COMMAND_IO) ||
2022 !(pdev->resource[0].flags & IORESOURCE_IO)) {
2023 printk("qlogicfc%d : i/o mapping is disabled\n", hostdata->host_id);
2027 pci_set_master(pdev);
2028 if (revision != ISP2100_REV_ID1 && revision != ISP2100_REV_ID3 && revision != ISP2200_REV_ID5)
2029 printk("qlogicfc%d : new isp2x00 revision ID (%d)\n", hostdata->host_id, revision);
2032 hostdata->revision = revision;
2035 sh->io_port = io_base;
2037 LEAVE("isp2x00_init");
2042 #if USE_NVRAM_DEFAULTS
2044 #define NVRAM_DELAY() udelay(10) /* 10 microsecond delay */
2047 u_short isp2x00_read_nvram_word(struct Scsi_Host * host, u_short byte)
2050 u_short value, output, input;
2052 outw(0x2, host->io_port + PCI_NVRAM);
2054 outw(0x3, host->io_port + PCI_NVRAM);
2059 for (i = 10; i >= 0; i--) {
2060 output = ((byte >> i) & 0x1) ? 0x4 : 0x0;
2061 outw(output | 0x2, host->io_port + PCI_NVRAM);
2063 outw(output | 0x3, host->io_port + PCI_NVRAM);
2065 outw(output | 0x2, host->io_port + PCI_NVRAM);
2069 for (i = 0xf, value = 0; i >= 0; i--) {
2071 outw(0x3, host->io_port + PCI_NVRAM);
2073 input = inw(host->io_port + PCI_NVRAM);
2075 outw(0x2, host->io_port + PCI_NVRAM);
2081 outw(0x0, host->io_port + PCI_NVRAM);
2088 #endif /* USE_NVRAM_DEFAULTS */
2093 * currently, this is only called during initialization or abort/reset,
2094 * at which times interrupts are disabled, so polling is OK, I guess...
2096 static int isp2x00_mbox_command(struct Scsi_Host *host, u_short param[])
2099 struct isp2x00_hostdata *hostdata = (struct isp2x00_hostdata *) host->hostdata;
2101 if (mbox_param[param[0]] == 0 || hostdata->adapter_state == AS_FIRMWARE_DEAD)
2104 loop_count = DEFAULT_LOOP_COUNT;
2105 while (--loop_count && inw(host->io_port + HOST_HCCR) & 0x0080) {
2110 printk("qlogicfc%d : mbox_command loop timeout #1\n", hostdata->host_id);
2112 hostdata->adapter_state = AS_FIRMWARE_DEAD;
2115 hostdata->mbox_done = 0;
2117 if (mbox_param[param[0]] == 0)
2118 printk("qlogicfc%d : invalid mbox command\n", hostdata->host_id);
2120 if (mbox_param[param[0]] & 0x80)
2121 outw(param[7], host->io_port + MBOX7);
2122 if (mbox_param[param[0]] & 0x40)
2123 outw(param[6], host->io_port + MBOX6);
2124 if (mbox_param[param[0]] & 0x20)
2125 outw(param[5], host->io_port + MBOX5);
2126 if (mbox_param[param[0]] & 0x10)
2127 outw(param[4], host->io_port + MBOX4);
2128 if (mbox_param[param[0]] & 0x08)
2129 outw(param[3], host->io_port + MBOX3);
2130 if (mbox_param[param[0]] & 0x04)
2131 outw(param[2], host->io_port + MBOX2);
2132 if (mbox_param[param[0]] & 0x02)
2133 outw(param[1], host->io_port + MBOX1);
2134 if (mbox_param[param[0]] & 0x01)
2135 outw(param[0], host->io_port + MBOX0);
2138 outw(HCCR_SET_HOST_INTR, host->io_port + HOST_HCCR);
2141 loop_count = DEFAULT_LOOP_COUNT;
2142 while (--loop_count && !(inw(host->io_port + PCI_INTER_STS) & 0x08)) {
2148 hostdata->adapter_state = AS_FIRMWARE_DEAD;
2149 printk("qlogicfc%d : mbox_command loop timeout #2\n", hostdata->host_id);
2152 isp2x00_intr_handler(host->irq, host, NULL);
2154 if (hostdata->mbox_done == 1)
2159 loop_count = DEFAULT_LOOP_COUNT;
2160 while (--loop_count && inw(host->io_port + MBOX0) == 0x04) {
2165 printk("qlogicfc%d : mbox_command loop timeout #3\n", hostdata->host_id);
2167 param[7] = inw(host->io_port + MBOX7);
2168 param[6] = inw(host->io_port + MBOX6);
2169 param[5] = inw(host->io_port + MBOX5);
2170 param[4] = inw(host->io_port + MBOX4);
2171 param[3] = inw(host->io_port + MBOX3);
2172 param[2] = inw(host->io_port + MBOX2);
2173 param[1] = inw(host->io_port + MBOX1);
2174 param[0] = inw(host->io_port + MBOX0);
2177 outw(0x0, host->io_port + PCI_SEMAPHORE);
2179 if (inw(host->io_port + HOST_HCCR) & 0x0080) {
2180 hostdata->adapter_state = AS_FIRMWARE_DEAD;
2181 printk("qlogicfc%d : mbox op is still pending\n", hostdata->host_id);
2186 #if DEBUG_ISP2x00_INTR
2188 void isp2x00_print_status_entry(struct Status_Entry *status)
2190 printk("qlogicfc : entry count = 0x%02x, type = 0x%02x, flags = 0x%02x\n",
2191 status->hdr.entry_cnt, status->hdr.entry_type, status->hdr.flags);
2192 printk("qlogicfc : scsi status = 0x%04x, completion status = 0x%04x\n",
2193 le16_to_cpu(status->scsi_status), le16_to_cpu(status->completion_status));
2194 printk("qlogicfc : state flags = 0x%04x, status flags = 0x%04x\n",
2195 le16_to_cpu(status->state_flags), le16_to_cpu(status->status_flags));
2196 printk("qlogicfc : response info length = 0x%04x, request sense length = 0x%04x\n",
2197 le16_to_cpu(status->res_info_len), le16_to_cpu(status->req_sense_len));
2198 printk("qlogicfc : residual transfer length = 0x%08x, response = 0x%02x\n", le32_to_cpu(status->residual), status->res_info[3]);
2202 #endif /* DEBUG_ISP2x00_INTR */
2207 void isp2x00_print_scsi_cmd(Scsi_Cmnd * cmd)
2211 printk("qlogicfc : target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
2212 cmd->target, cmd->lun, cmd->cmd_len);
2213 printk("qlogicfc : command = ");
2214 for (i = 0; i < cmd->cmd_len; i++)
2215 printk("0x%02x ", cmd->cmnd[i]);
2219 #endif /* DEBUG_ISP2x00 */
2221 MODULE_LICENSE("GPL");
2223 static Scsi_Host_Template driver_template = {
2224 .detect = isp2x00_detect,
2225 .release = isp2x00_release,
2226 .info = isp2x00_info,
2227 .queuecommand = isp2x00_queuecommand,
2228 .eh_abort_handler = isp2x00_abort,
2229 .bios_param = isp2x00_biosparam,
2230 .can_queue = QLOGICFC_REQ_QUEUE_LEN,
2232 .sg_tablesize = QLOGICFC_MAX_SG(QLOGICFC_REQ_QUEUE_LEN),
2233 .cmd_per_lun = QLOGICFC_CMD_PER_LUN,
2234 .use_clustering = ENABLE_CLUSTERING,
2236 #include "scsi_module.c"