qlogicfc.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:65k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * QLogic ISP2x00 SCSI-FCP
  3.  * Written by Erik H. Moe, ehm@cris.com
  4.  * Copyright 1995, Erik H. Moe
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify it
  7.  * under the terms of the GNU General Public License as published by the
  8.  * Free Software Foundation; either version 2, or (at your option) any
  9.  * later version.
  10.  *
  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.
  15.  */
  16. /* Renamed and updated to 1.3.x by Michael Griffith <grif@cs.ucr.edu> */
  17. /* This is a version of the isp1020 driver which was modified by
  18.  * Chris Loveland <cwl@iol.unh.edu> to support the isp2100 and isp2200
  19.  *
  20.  * Big endian support and dynamic DMA mapping added
  21.  * by Jakub Jelinek <jakub@redhat.com>.
  22.  *
  23.  * Conversion to final pci64 DMA interfaces
  24.  * by David S. Miller <davem@redhat.com>.
  25.  */
  26. /*
  27.  * $Date: 1995/09/22 02:23:15 $
  28.  * $Revision: 0.5 $
  29.  *
  30.  * $Log: isp1020.c,v $
  31.  * Revision 0.5  1995/09/22  02:23:15  root
  32.  * do auto request sense
  33.  *
  34.  * Revision 0.4  1995/08/07  04:44:33  root
  35.  * supply firmware with driver.
  36.  * numerous bug fixes/general cleanup of code.
  37.  *
  38.  * Revision 0.3  1995/07/16  16:15:39  root
  39.  * added reset/abort code.
  40.  *
  41.  * Revision 0.2  1995/06/29  03:14:19  root
  42.  * fixed biosparam.
  43.  * added queue protocol.
  44.  *
  45.  * Revision 0.1  1995/06/25  01:55:45  root
  46.  * Initial release.
  47.  *
  48.  */
  49. #include <linux/blk.h>
  50. #include <linux/kernel.h>
  51. #include <linux/string.h>
  52. #include <linux/ioport.h>
  53. #include <linux/sched.h>
  54. #include <linux/types.h>
  55. #include <linux/pci.h>
  56. #include <linux/delay.h>
  57. #include <linux/unistd.h>
  58. #include <linux/spinlock.h>
  59. #include <asm/io.h>
  60. #include <asm/irq.h>
  61. #include "sd.h"
  62. #include "hosts.h"
  63. #define pci64_dma_hi32(a) ((u32) (0xffffffff & (((u64)(a))>>32)))
  64. #define pci64_dma_lo32(a) ((u32) (0xffffffff & (((u64)(a)))))
  65. #define pci64_dma_build(hi,lo) 
  66. ((dma_addr_t)(((u64)(lo))|(((u64)(hi))<<32)))
  67. #include "qlogicfc.h"
  68. /* Configuration section **************************************************** */
  69. /* Set the following macro to 1 to reload the ISP2x00's firmware.  This is
  70.    version 1.17.30 of the isp2100's firmware and version 2.00.40 of the 
  71.    isp2200's firmware. 
  72. */
  73. #define USE_NVRAM_DEFAULTS      1
  74. #define ISP2x00_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 */
  77. #define ISP2x00_FABRIC          1
  78. /*  Macros used for debugging */
  79. #define DEBUG_ISP2x00 0
  80. #define DEBUG_ISP2x00_INT 0
  81. #define DEBUG_ISP2x00_INTR 0
  82. #define DEBUG_ISP2x00_SETUP 0
  83. #define DEBUG_ISP2x00_FABRIC    0
  84. #define TRACE_ISP  0 
  85. #define DEFAULT_LOOP_COUNT 1000000000
  86. /* End Configuration section ************************************************ */
  87. #include <linux/module.h>
  88. #if TRACE_ISP
  89. #define TRACE_BUF_LEN (32*1024)
  90. struct {
  91. u_long next;
  92. struct {
  93. u_long time;
  94. u_int index;
  95. u_int addr;
  96. u_char *name;
  97. } buf[TRACE_BUF_LEN];
  98. } trace;
  99. #define TRACE(w, i, a)
  100. {
  101. unsigned long flags;
  102. save_flags(flags);
  103. cli();
  104. trace.buf[trace.next].name  = (w);
  105. trace.buf[trace.next].time  = jiffies;
  106. trace.buf[trace.next].index = (i);
  107. trace.buf[trace.next].addr  = (long) (a);
  108. trace.next = (trace.next + 1) & (TRACE_BUF_LEN - 1);
  109. restore_flags(flags);
  110. }
  111. #else
  112. #define TRACE(w, i, a)
  113. #endif
  114. #if DEBUG_ISP2x00_FABRIC
  115. #define DEBUG_FABRIC(x) x
  116. #else
  117. #define DEBUG_FABRIC(x)
  118. #endif /* DEBUG_ISP2x00_FABRIC */
  119. #if DEBUG_ISP2x00
  120. #define ENTER(x) printk("isp2x00 : entering %s()n", x);
  121. #define LEAVE(x) printk("isp2x00 : leaving %s()n", x);
  122. #define DEBUG(x) x
  123. #else
  124. #define ENTER(x)
  125. #define LEAVE(x)
  126. #define DEBUG(x)
  127. #endif /* DEBUG_ISP2x00 */
  128. #if DEBUG_ISP2x00_INTR
  129. #define ENTER_INTR(x) printk("isp2x00 : entering %s()n", x);
  130. #define LEAVE_INTR(x) printk("isp2x00 : leaving %s()n", x);
  131. #define DEBUG_INTR(x) x
  132. #else
  133. #define ENTER_INTR(x)
  134. #define LEAVE_INTR(x)
  135. #define DEBUG_INTR(x)
  136. #endif /* DEBUG ISP2x00_INTR */
  137. #define ISP2100_REV_ID1        1
  138. #define ISP2100_REV_ID3        3
  139. #define ISP2200_REV_ID5        5
  140. /* host configuration and control registers */
  141. #define HOST_HCCR 0xc0 /* host command and control */
  142. /* pci bus interface registers */
  143. #define FLASH_BIOS_ADDR 0x00
  144. #define FLASH_BIOS_DATA 0x02
  145. #define ISP_CTRL_STATUS 0x06 /* configuration register #1 */
  146. #define PCI_INTER_CTL 0x08 /* pci interrupt control */
  147. #define PCI_INTER_STS 0x0a /* pci interrupt status */
  148. #define PCI_SEMAPHORE 0x0c /* pci semaphore */
  149. #define PCI_NVRAM 0x0e /* pci nvram interface */
  150. /* mailbox registers */
  151. #define MBOX0 0x10 /* mailbox 0 */
  152. #define MBOX1 0x12 /* mailbox 1 */
  153. #define MBOX2 0x14 /* mailbox 2 */
  154. #define MBOX3 0x16 /* mailbox 3 */
  155. #define MBOX4 0x18 /* mailbox 4 */
  156. #define MBOX5 0x1a /* mailbox 5 */
  157. #define MBOX6 0x1c /* mailbox 6 */
  158. #define MBOX7 0x1e /* mailbox 7 */
  159. /* mailbox command complete status codes */
  160. #define MBOX_COMMAND_COMPLETE 0x4000
  161. #define INVALID_COMMAND 0x4001
  162. #define HOST_INTERFACE_ERROR 0x4002
  163. #define TEST_FAILED 0x4003
  164. #define COMMAND_ERROR 0x4005
  165. #define COMMAND_PARAM_ERROR 0x4006
  166. #define PORT_ID_USED                    0x4007
  167. #define LOOP_ID_USED                    0x4008
  168. #define ALL_IDS_USED                    0x4009
  169. /* async event status codes */
  170. #define RESET_DETECTED   0x8001
  171. #define SYSTEM_ERROR 0x8002
  172. #define REQUEST_TRANSFER_ERROR 0x8003
  173. #define RESPONSE_TRANSFER_ERROR 0x8004
  174. #define REQUEST_QUEUE_WAKEUP 0x8005
  175. #define LIP_OCCURRED                     0x8010
  176. #define LOOP_UP                         0x8011
  177. #define LOOP_DOWN                       0x8012
  178. #define LIP_RECEIVED                    0x8013
  179. #define PORT_DB_CHANGED                 0x8014
  180. #define CHANGE_NOTIFICATION             0x8015
  181. #define SCSI_COMMAND_COMPLETE           0x8020
  182. #define POINT_TO_POINT_UP               0x8030
  183. #define CONNECTION_MODE                 0x8036
  184. struct Entry_header {
  185. u_char entry_type;
  186. u_char entry_cnt;
  187. u_char sys_def_1;
  188. u_char flags;
  189. };
  190. /* entry header type commands */
  191. #define ENTRY_COMMAND 0x19
  192. #define ENTRY_CONTINUATION 0x0a
  193. #define ENTRY_STATUS 0x03
  194. #define ENTRY_MARKER 0x04
  195. /* entry header flag definitions */
  196. #define EFLAG_BUSY 2
  197. #define EFLAG_BAD_HEADER 4
  198. #define EFLAG_BAD_PAYLOAD 8
  199. struct dataseg {
  200. u_int d_base;
  201. u_int d_base_hi;
  202. u_int d_count;
  203. };
  204. struct Command_Entry {
  205. struct Entry_header hdr;
  206. u_int handle;
  207. u_char target_lun;
  208. u_char target_id;
  209. u_short expanded_lun;
  210. u_short control_flags;
  211. u_short rsvd2;
  212. u_short time_out;
  213. u_short segment_cnt;
  214. u_char cdb[16];
  215. u_int total_byte_cnt;
  216. struct dataseg dataseg[DATASEGS_PER_COMMAND];
  217. };
  218. /* command entry control flag definitions */
  219. #define CFLAG_NODISC 0x01
  220. #define CFLAG_HEAD_TAG 0x02
  221. #define CFLAG_ORDERED_TAG 0x04
  222. #define CFLAG_SIMPLE_TAG 0x08
  223. #define CFLAG_TAR_RTN 0x10
  224. #define CFLAG_READ 0x20
  225. #define CFLAG_WRITE 0x40
  226. struct Continuation_Entry {
  227. struct Entry_header hdr;
  228. struct dataseg dataseg[DATASEGS_PER_CONT];
  229. };
  230. struct Marker_Entry {
  231. struct Entry_header hdr;
  232. u_int reserved;
  233. u_char target_lun;
  234. u_char target_id;
  235. u_char modifier;
  236. u_char expanded_lun;
  237. u_char rsvds[52];
  238. };
  239. /* marker entry modifier definitions */
  240. #define SYNC_DEVICE 0
  241. #define SYNC_TARGET 1
  242. #define SYNC_ALL 2
  243. struct Status_Entry {
  244. struct Entry_header hdr;
  245. u_int handle;
  246. u_short scsi_status;
  247. u_short completion_status;
  248. u_short state_flags;
  249. u_short status_flags;
  250. u_short res_info_len;
  251. u_short req_sense_len;
  252. u_int residual;
  253. u_char res_info[8];
  254. u_char req_sense_data[32];
  255. };
  256. /* status entry completion status definitions */
  257. #define CS_COMPLETE 0x0000
  258. #define CS_DMA_ERROR 0x0002
  259. #define CS_RESET_OCCURRED 0x0004
  260. #define CS_ABORTED 0x0005
  261. #define CS_TIMEOUT 0x0006
  262. #define CS_DATA_OVERRUN 0x0007
  263. #define CS_DATA_UNDERRUN 0x0015
  264. #define CS_QUEUE_FULL 0x001c
  265. #define CS_PORT_UNAVAILABLE             0x0028
  266. #define CS_PORT_LOGGED_OUT              0x0029
  267. #define CS_PORT_CONFIG_CHANGED 0x002a
  268. /* status entry state flag definitions */
  269. #define SF_SENT_CDB 0x0400
  270. #define SF_TRANSFERRED_DATA 0x0800
  271. #define SF_GOT_STATUS 0x1000
  272. /* status entry status flag definitions */
  273. #define STF_BUS_RESET 0x0008
  274. #define STF_DEVICE_RESET 0x0010
  275. #define STF_ABORTED 0x0020
  276. #define STF_TIMEOUT 0x0040
  277. /* interrupt control commands */
  278. #define ISP_EN_INT 0x8000
  279. #define ISP_EN_RISC 0x0008
  280. /* host control commands */
  281. #define HCCR_NOP 0x0000
  282. #define HCCR_RESET 0x1000
  283. #define HCCR_PAUSE 0x2000
  284. #define HCCR_RELEASE 0x3000
  285. #define HCCR_SINGLE_STEP 0x4000
  286. #define HCCR_SET_HOST_INTR 0x5000
  287. #define HCCR_CLEAR_HOST_INTR 0x6000
  288. #define HCCR_CLEAR_RISC_INTR 0x7000
  289. #define HCCR_BP_ENABLE 0x8000
  290. #define HCCR_BIOS_DISABLE 0x9000
  291. #define HCCR_TEST_MODE 0xf000
  292. #define RISC_BUSY 0x0004
  293. /* mailbox commands */
  294. #define MBOX_NO_OP 0x0000
  295. #define MBOX_LOAD_RAM 0x0001
  296. #define MBOX_EXEC_FIRMWARE 0x0002
  297. #define MBOX_DUMP_RAM 0x0003
  298. #define MBOX_WRITE_RAM_WORD 0x0004
  299. #define MBOX_READ_RAM_WORD 0x0005
  300. #define MBOX_MAILBOX_REG_TEST 0x0006
  301. #define MBOX_VERIFY_CHECKSUM 0x0007
  302. #define MBOX_ABOUT_FIRMWARE 0x0008
  303. #define MBOX_LOAD_RISC_RAM              0x0009
  304. #define MBOX_DUMP_RISC_RAM              0x000a
  305. #define MBOX_CHECK_FIRMWARE 0x000e
  306. #define MBOX_INIT_REQ_QUEUE 0x0010
  307. #define MBOX_INIT_RES_QUEUE 0x0011
  308. #define MBOX_EXECUTE_IOCB 0x0012
  309. #define MBOX_WAKE_UP 0x0013
  310. #define MBOX_STOP_FIRMWARE 0x0014
  311. #define MBOX_ABORT_IOCB 0x0015
  312. #define MBOX_ABORT_DEVICE 0x0016
  313. #define MBOX_ABORT_TARGET 0x0017
  314. #define MBOX_BUS_RESET 0x0018
  315. #define MBOX_STOP_QUEUE 0x0019
  316. #define MBOX_START_QUEUE 0x001a
  317. #define MBOX_SINGLE_STEP_QUEUE 0x001b
  318. #define MBOX_ABORT_QUEUE 0x001c
  319. #define MBOX_GET_DEV_QUEUE_STATUS 0x001d
  320. #define MBOX_GET_FIRMWARE_STATUS 0x001f
  321. #define MBOX_GET_INIT_SCSI_ID 0x0020
  322. #define MBOX_GET_RETRY_COUNT 0x0022
  323. #define MBOX_GET_TARGET_PARAMS 0x0028
  324. #define MBOX_GET_DEV_QUEUE_PARAMS 0x0029
  325. #define MBOX_SET_RETRY_COUNT 0x0032
  326. #define MBOX_SET_TARGET_PARAMS 0x0038
  327. #define MBOX_SET_DEV_QUEUE_PARAMS 0x0039
  328. #define MBOX_EXECUTE_IOCB64             0x0054
  329. #define MBOX_INIT_FIRMWARE              0x0060
  330. #define MBOX_GET_INIT_CB                0x0061
  331. #define MBOX_INIT_LIP 0x0062
  332. #define MBOX_GET_POS_MAP                0x0063
  333. #define MBOX_GET_PORT_DB                0x0064
  334. #define MBOX_CLEAR_ACA                  0x0065
  335. #define MBOX_TARGET_RESET               0x0066
  336. #define MBOX_CLEAR_TASK_SET             0x0067
  337. #define MBOX_ABORT_TASK_SET             0x0068
  338. #define MBOX_GET_FIRMWARE_STATE         0x0069
  339. #define MBOX_GET_PORT_NAME              0x006a
  340. #define MBOX_SEND_SNS                   0x006e
  341. #define MBOX_PORT_LOGIN                 0x006f
  342. #define MBOX_SEND_CHANGE_REQUEST        0x0070
  343. #define MBOX_PORT_LOGOUT                0x0071
  344. /*
  345.  * Firmware if needed (note this is a hack, it belongs in a seperate
  346.  * module.
  347.  */
  348.  
  349. #ifdef CONFIG_SCSI_QLOGIC_FC_FIRMWARE
  350. #include "qlogicfc_asm.c"
  351. #else
  352. static unsigned short risc_code_addr01 = 0x1000 ;
  353. #endif
  354. /* Each element in mbox_param is an 8 bit bitmap where each bit indicates
  355.    if that mbox should be copied as input.  For example 0x2 would mean
  356.    only copy mbox1. */
  357. const u_char mbox_param[] =
  358. {
  359. 0x01, /* MBOX_NO_OP */
  360. 0x1f, /* MBOX_LOAD_RAM */
  361. 0x03, /* MBOX_EXEC_FIRMWARE */
  362. 0x1f, /* MBOX_DUMP_RAM */
  363. 0x07, /* MBOX_WRITE_RAM_WORD */
  364. 0x03, /* MBOX_READ_RAM_WORD */
  365. 0xff, /* MBOX_MAILBOX_REG_TEST */
  366. 0x03, /* MBOX_VERIFY_CHECKSUM */
  367. 0x01, /* MBOX_ABOUT_FIRMWARE */
  368. 0xff, /* MBOX_LOAD_RISC_RAM */
  369. 0xff, /* MBOX_DUMP_RISC_RAM */
  370. 0x00, /* 0x000b */
  371. 0x00, /* 0x000c */
  372. 0x00, /* 0x000d */
  373. 0x01, /* MBOX_CHECK_FIRMWARE */
  374. 0x00, /* 0x000f */
  375. 0x1f, /* MBOX_INIT_REQ_QUEUE */
  376. 0x2f, /* MBOX_INIT_RES_QUEUE */
  377. 0x0f, /* MBOX_EXECUTE_IOCB */
  378. 0x03, /* MBOX_WAKE_UP */
  379. 0x01, /* MBOX_STOP_FIRMWARE */
  380. 0x0f, /* MBOX_ABORT_IOCB */
  381. 0x03, /* MBOX_ABORT_DEVICE */
  382. 0x07, /* MBOX_ABORT_TARGET */
  383. 0x03, /* MBOX_BUS_RESET */
  384. 0x03, /* MBOX_STOP_QUEUE */
  385. 0x03, /* MBOX_START_QUEUE */
  386. 0x03, /* MBOX_SINGLE_STEP_QUEUE */
  387. 0x03, /* MBOX_ABORT_QUEUE */
  388. 0x03, /* MBOX_GET_DEV_QUEUE_STATUS */
  389. 0x00, /* 0x001e */
  390. 0x01, /* MBOX_GET_FIRMWARE_STATUS */
  391. 0x01, /* MBOX_GET_INIT_SCSI_ID */
  392. 0x00, /* 0x0021 */
  393. 0x01, /* MBOX_GET_RETRY_COUNT */
  394. 0x00, /* 0x0023 */
  395. 0x00, /* 0x0024 */
  396. 0x00, /* 0x0025 */
  397. 0x00, /* 0x0026 */
  398. 0x00, /* 0x0027 */
  399. 0x03, /* MBOX_GET_TARGET_PARAMS */
  400. 0x03, /* MBOX_GET_DEV_QUEUE_PARAMS */
  401. 0x00, /* 0x002a */
  402. 0x00, /* 0x002b */
  403. 0x00, /* 0x002c */
  404. 0x00, /* 0x002d */
  405. 0x00, /* 0x002e */
  406. 0x00, /* 0x002f */
  407. 0x00, /* 0x0030 */
  408. 0x00, /* 0x0031 */
  409. 0x07, /* MBOX_SET_RETRY_COUNT */
  410. 0x00, /* 0x0033 */
  411. 0x00, /* 0x0034 */
  412. 0x00, /* 0x0035 */
  413. 0x00, /* 0x0036 */
  414. 0x00, /* 0x0037 */
  415. 0x0f, /* MBOX_SET_TARGET_PARAMS */
  416. 0x0f, /* MBOX_SET_DEV_QUEUE_PARAMS */
  417. 0x00, /* 0x003a */
  418. 0x00, /* 0x003b */
  419. 0x00, /* 0x003c */
  420. 0x00, /* 0x003d */
  421. 0x00, /* 0x003e */
  422. 0x00, /* 0x003f */
  423. 0x00, /* 0x0040 */
  424. 0x00, /* 0x0041 */
  425. 0x00, /* 0x0042 */
  426. 0x00, /* 0x0043 */
  427. 0x00, /* 0x0044 */
  428. 0x00, /* 0x0045 */
  429. 0x00, /* 0x0046 */
  430. 0x00, /* 0x0047 */
  431. 0x00, /* 0x0048 */
  432. 0x00, /* 0x0049 */
  433. 0x00, /* 0x004a */
  434. 0x00, /* 0x004b */
  435. 0x00, /* 0x004c */
  436. 0x00, /* 0x004d */
  437. 0x00, /* 0x004e */
  438. 0x00, /* 0x004f */
  439. 0x00, /* 0x0050 */
  440. 0x00, /* 0x0051 */
  441. 0x00, /* 0x0052 */
  442. 0x00, /* 0x0053 */
  443. 0xcf, /* MBOX_EXECUTE_IOCB64 */
  444. 0x00, /* 0x0055 */
  445. 0x00, /* 0x0056 */
  446. 0x00, /* 0x0057 */
  447. 0x00, /* 0x0058 */
  448. 0x00, /* 0x0059 */
  449. 0x00, /* 0x005a */
  450. 0x00, /* 0x005b */
  451. 0x00, /* 0x005c */
  452. 0x00, /* 0x005d */
  453. 0x00, /* 0x005e */
  454. 0x00, /* 0x005f */
  455. 0xff, /* MBOX_INIT_FIRMWARE */
  456. 0xcd, /* MBOX_GET_INIT_CB */
  457. 0x01, /* MBOX_INIT_LIP */
  458. 0xcd, /* MBOX_GET_POS_MAP */
  459. 0xcf, /* MBOX_GET_PORT_DB */
  460. 0x03, /* MBOX_CLEAR_ACA */
  461. 0x03, /* MBOX_TARGET_RESET */
  462. 0x03, /* MBOX_CLEAR_TASK_SET */
  463. 0x03, /* MBOX_ABORT_TASK_SET */
  464. 0x01, /* MBOX_GET_FIRMWARE_STATE */
  465. 0x03, /* MBOX_GET_PORT_NAME */
  466. 0x00, /* 0x006b */
  467. 0x00, /* 0x006c */
  468. 0x00, /* 0x006d */
  469. 0xcf, /* MBOX_SEND_SNS */
  470. 0x0f, /* MBOX_PORT_LOGIN */
  471. 0x03, /* MBOX_SEND_CHANGE_REQUEST */
  472. 0x03, /* MBOX_PORT_LOGOUT */
  473. };
  474. #define MAX_MBOX_COMMAND (sizeof(mbox_param)/sizeof(u_short))
  475. struct id_name_map {
  476. u64 wwn;
  477. u_char loop_id;
  478. };
  479. struct sns_cb {
  480. u_short len;
  481. u_short res1;
  482. u_int response_low;
  483. u_int response_high;
  484. u_short sub_len;
  485. u_short res2;
  486. u_char data[44];
  487. };
  488. /* address of instance of this struct is passed to adapter to initialize things
  489.  */
  490. struct init_cb {
  491. u_char version;
  492. u_char reseverd1[1];
  493. u_short firm_opts;
  494. u_short max_frame_len;
  495. u_short max_iocb;
  496. u_short exec_throttle;
  497. u_char retry_cnt;
  498. u_char retry_delay;
  499. u_short node_name[4];
  500. u_short hard_addr;
  501. u_char reserved2[10];
  502. u_short req_queue_out;
  503. u_short res_queue_in;
  504. u_short req_queue_len;
  505. u_short res_queue_len;
  506. u_int req_queue_addr_lo;
  507. u_int req_queue_addr_high;
  508. u_int res_queue_addr_lo;
  509. u_int res_queue_addr_high;
  510.         /* the rest of this structure only applies to the isp2200 */
  511.         u_short lun_enables;
  512.         u_char cmd_resource_cnt;
  513.         u_char notify_resource_cnt;
  514.         u_short timeout;
  515.         u_short reserved3;
  516.         u_short add_firm_opts;
  517.         u_char res_accum_timer;
  518.         u_char irq_delay_timer;
  519.         u_short special_options;
  520.         u_short reserved4[13];
  521. };
  522. /*
  523.  * The result queue can be quite a bit smaller since continuation entries
  524.  * do not show up there:
  525.  */
  526. #define RES_QUEUE_LEN ((QLOGICFC_REQ_QUEUE_LEN + 1) / 8 - 1)
  527. #define QUEUE_ENTRY_LEN 64
  528. #if ISP2x00_FABRIC
  529. #define QLOGICFC_MAX_ID    0xff
  530. #else
  531. #define QLOGICFC_MAX_ID    0x7d
  532. #endif
  533. #define QLOGICFC_MAX_LUN 128
  534. #define QLOGICFC_MAX_LOOP_ID 0x7d
  535. /* the following connection options only apply to the 2200.  i have only
  536.  * had success with LOOP_ONLY and P2P_ONLY.
  537.  */
  538. #define LOOP_ONLY              0
  539. #define P2P_ONLY               1
  540. #define LOOP_PREFERED          2
  541. #define P2P_PREFERED           3
  542. #define CONNECTION_PREFERENCE  LOOP_ONLY
  543. /* adapter_state values */
  544. #define AS_FIRMWARE_DEAD      -1
  545. #define AS_LOOP_DOWN           0
  546. #define AS_LOOP_GOOD           1
  547. #define AS_REDO_FABRIC_PORTDB  2
  548. #define AS_REDO_LOOP_PORTDB    4
  549. #define RES_SIZE ((RES_QUEUE_LEN + 1)*QUEUE_ENTRY_LEN)
  550. #define REQ_SIZE ((QLOGICFC_REQ_QUEUE_LEN + 1)*QUEUE_ENTRY_LEN)
  551. struct isp2x00_hostdata {
  552. u_char revision;
  553. struct pci_dev *pci_dev;
  554. /* result and request queues (shared with isp2x00): */
  555. u_int req_in_ptr; /* index of next request slot */
  556. u_int res_out_ptr; /* index of next result slot */
  557. /* this is here so the queues are nicely aligned */
  558. long send_marker; /* do we need to send a marker? */
  559. char * res;
  560. char * req;
  561. struct init_cb control_block;
  562. int adapter_state;
  563. unsigned long int tag_ages[QLOGICFC_MAX_ID + 1];
  564. Scsi_Cmnd *handle_ptrs[QLOGICFC_REQ_QUEUE_LEN + 1];
  565. unsigned long handle_serials[QLOGICFC_REQ_QUEUE_LEN + 1];
  566. struct id_name_map port_db[QLOGICFC_MAX_ID + 1];
  567. u_char mbox_done;
  568. u64 wwn;
  569. u_int port_id;
  570. u_char queued;
  571. u_char host_id;
  572.         struct timer_list explore_timer;
  573. };
  574. /* queue length's _must_ be power of two: */
  575. #define QUEUE_DEPTH(in, out, ql) ((in - out) & (ql))
  576. #define REQ_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out,       
  577.     QLOGICFC_REQ_QUEUE_LEN)
  578. #define RES_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, RES_QUEUE_LEN)
  579. static void isp2x00_enable_irqs(struct Scsi_Host *);
  580. static void isp2x00_disable_irqs(struct Scsi_Host *);
  581. static int isp2x00_init(struct Scsi_Host *);
  582. static int isp2x00_reset_hardware(struct Scsi_Host *);
  583. static int isp2x00_mbox_command(struct Scsi_Host *, u_short[]);
  584. static int isp2x00_return_status(Scsi_Cmnd *, struct Status_Entry *);
  585. static void isp2x00_intr_handler(int, void *, struct pt_regs *);
  586. static void do_isp2x00_intr_handler(int, void *, struct pt_regs *);
  587. static int isp2x00_make_portdb(struct Scsi_Host *);
  588. #if ISP2x00_FABRIC
  589. static int isp2x00_init_fabric(struct Scsi_Host *, struct id_name_map *, int);
  590. #endif
  591. #if USE_NVRAM_DEFAULTS
  592. static int isp2x00_get_nvram_defaults(struct Scsi_Host *, struct init_cb *);
  593. static u_short isp2x00_read_nvram_word(struct Scsi_Host *, u_short);
  594. #endif
  595. #if DEBUG_ISP2x00
  596. static void isp2x00_print_scsi_cmd(Scsi_Cmnd *);
  597. #endif
  598. #if DEBUG_ISP2x00_INTR
  599. static void isp2x00_print_status_entry(struct Status_Entry *);
  600. #endif
  601. static inline void isp2x00_enable_irqs(struct Scsi_Host *host)
  602. {
  603. outw(ISP_EN_INT | ISP_EN_RISC, host->io_port + PCI_INTER_CTL);
  604. }
  605. static inline void isp2x00_disable_irqs(struct Scsi_Host *host)
  606. {
  607. outw(0x0, host->io_port + PCI_INTER_CTL);
  608. }
  609. int isp2x00_detect(Scsi_Host_Template * tmpt)
  610. {
  611. int hosts = 0;
  612. int wait_time;
  613. struct Scsi_Host *host = NULL;
  614. struct isp2x00_hostdata *hostdata;
  615. struct pci_dev *pdev;
  616. unsigned short device_ids[2];
  617. dma_addr_t busaddr;
  618. int i;
  619. ENTER("isp2x00_detect");
  620.         device_ids[0] = PCI_DEVICE_ID_QLOGIC_ISP2100;
  621. device_ids[1] = PCI_DEVICE_ID_QLOGIC_ISP2200;
  622. tmpt->proc_name = "isp2x00";
  623. if (pci_present() == 0) {
  624. printk(KERN_INFO "qlogicfc : PCI not presentn");
  625. return 0;
  626. }
  627. for (i=0; i<2; i++){
  628. pdev = NULL;
  629.         while ((pdev = pci_find_device(PCI_VENDOR_ID_QLOGIC, device_ids[i], pdev))) {
  630. if (pci_enable_device(pdev))
  631. continue;
  632. /* Try to configure DMA attributes. */
  633. if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffff) &&
  634.     pci_set_dma_mask(pdev, (u64) 0xffffffff))
  635. continue;
  636.         host = scsi_register(tmpt, sizeof(struct isp2x00_hostdata));
  637. if (!host) {
  638.         printk("qlogicfc%d : could not register host.n", hosts);
  639. continue;
  640. }
  641.   scsi_set_pci_device(host, pdev);
  642. host->max_id = QLOGICFC_MAX_ID + 1;
  643. host->max_lun = QLOGICFC_MAX_LUN;
  644. host->hostt->use_new_eh_code = 1;
  645. hostdata = (struct isp2x00_hostdata *) host->hostdata;
  646. memset(hostdata, 0, sizeof(struct isp2x00_hostdata));
  647. hostdata->pci_dev = pdev;
  648. hostdata->res = pci_alloc_consistent(pdev, RES_SIZE + REQ_SIZE, &busaddr);
  649. if (!hostdata->res){
  650.         printk("qlogicfc%d : could not allocate memory for request and response queue.n", hosts);
  651. pci_free_consistent(pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
  652.         scsi_unregister(host);
  653. continue;
  654. }
  655. hostdata->req = hostdata->res + (RES_QUEUE_LEN + 1)*QUEUE_ENTRY_LEN;
  656. hostdata->queued = 0;
  657. /* set up the control block */
  658. hostdata->control_block.version = 0x1;
  659. hostdata->control_block.firm_opts = cpu_to_le16(0x800e);
  660. hostdata->control_block.max_frame_len = cpu_to_le16(2048);
  661. hostdata->control_block.max_iocb = cpu_to_le16(QLOGICFC_REQ_QUEUE_LEN);
  662. hostdata->control_block.exec_throttle = cpu_to_le16(QLOGICFC_CMD_PER_LUN);
  663. hostdata->control_block.retry_delay = 5;
  664. hostdata->control_block.retry_cnt = 1;
  665. hostdata->control_block.node_name[0] = cpu_to_le16(0x0020);
  666. hostdata->control_block.node_name[1] = cpu_to_le16(0xE000);
  667. hostdata->control_block.node_name[2] = cpu_to_le16(0x008B);
  668. hostdata->control_block.node_name[3] = cpu_to_le16(0x0000);
  669. hostdata->control_block.hard_addr = cpu_to_le16(0x0003);
  670. hostdata->control_block.req_queue_len = cpu_to_le16(QLOGICFC_REQ_QUEUE_LEN + 1);
  671. hostdata->control_block.res_queue_len = cpu_to_le16(RES_QUEUE_LEN + 1);
  672. hostdata->control_block.res_queue_addr_lo = cpu_to_le32(pci64_dma_lo32(busaddr));
  673. hostdata->control_block.res_queue_addr_high = cpu_to_le32(pci64_dma_hi32(busaddr));
  674. hostdata->control_block.req_queue_addr_lo = cpu_to_le32(pci64_dma_lo32(busaddr + RES_SIZE));
  675. hostdata->control_block.req_queue_addr_high = cpu_to_le32(pci64_dma_hi32(busaddr + RES_SIZE));
  676. hostdata->control_block.add_firm_opts |= cpu_to_le16(CONNECTION_PREFERENCE<<4);
  677. hostdata->adapter_state = AS_LOOP_DOWN;
  678. hostdata->explore_timer.data = 1;
  679. hostdata->host_id = hosts;
  680. if (isp2x00_init(host) || isp2x00_reset_hardware(host)) {
  681. pci_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
  682.         scsi_unregister(host);
  683. continue;
  684. }
  685. host->this_id = 0;
  686. if (request_irq(host->irq, do_isp2x00_intr_handler, SA_INTERRUPT | SA_SHIRQ, "qlogicfc", host)) {
  687.         printk("qlogicfc%d : interrupt %d already in usen",
  688.        hostdata->host_id, host->irq);
  689. pci_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
  690. scsi_unregister(host);
  691. continue;
  692. }
  693. if (!request_region(host->io_port, 0xff, "qlogicfc")) {
  694.         printk("qlogicfc%d : i/o region 0x%lx-0x%lx already "
  695.        "in usen",
  696.        hostdata->host_id, host->io_port, host->io_port + 0xff);
  697. free_irq(host->irq, host);
  698. pci_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
  699. scsi_unregister(host);
  700. continue;
  701. }
  702. outw(0x0, host->io_port + PCI_SEMAPHORE);
  703. outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
  704. isp2x00_enable_irqs(host);
  705. /* wait for the loop to come up */
  706. for (wait_time = jiffies + 10 * HZ; time_before(jiffies, wait_time) && hostdata->adapter_state == AS_LOOP_DOWN;) {
  707.         barrier();
  708. cpu_relax();
  709. }
  710. if (hostdata->adapter_state == AS_LOOP_DOWN) {
  711.         printk("qlogicfc%d : link is not upn", hostdata->host_id);
  712. }
  713. hosts++;
  714. hostdata->explore_timer.data = 0;
  715. }
  716. }
  717. /* this busy loop should not be needed but the isp2x00 seems to need 
  718.    some time before recognizing it is attached to a fabric */
  719. #if ISP2x00_FABRIC
  720. for (wait_time = jiffies + 5 * HZ; time_before(jiffies, wait_time);) {
  721. barrier();
  722. cpu_relax();
  723. }
  724. #endif
  725. LEAVE("isp2x00_detect");
  726. return hosts;
  727. }
  728. static int isp2x00_make_portdb(struct Scsi_Host *host)
  729. {
  730. short param[8];
  731. int i, j;
  732. struct id_name_map temp[QLOGICFC_MAX_ID + 1];
  733. struct isp2x00_hostdata *hostdata;
  734. isp2x00_disable_irqs(host);
  735. memset(temp, 0, sizeof(temp));
  736. hostdata = (struct isp2x00_hostdata *) host->hostdata;
  737. #if ISP2x00_FABRIC
  738. for (i = 0x81; i < QLOGICFC_MAX_ID; i++) {
  739. param[0] = MBOX_PORT_LOGOUT;
  740. param[1] = i << 8;
  741. param[2] = 0;
  742. param[3] = 0;
  743. isp2x00_mbox_command(host, param);
  744. if (param[0] != MBOX_COMMAND_COMPLETE) {
  745. DEBUG_FABRIC(printk("qlogicfc%d : logout failed %x  %xn", hostdata->host_id, i, param[0]));
  746. }
  747. }
  748. #endif
  749. param[0] = MBOX_GET_INIT_SCSI_ID;
  750. isp2x00_mbox_command(host, param);
  751. if (param[0] == MBOX_COMMAND_COMPLETE) {
  752. hostdata->port_id = ((u_int) param[3]) << 16;
  753. hostdata->port_id |= param[2];
  754. temp[0].loop_id = param[1];
  755. temp[0].wwn = hostdata->wwn;
  756. }
  757. else {
  758.         printk("qlogicfc%d : error getting scsi id.n", hostdata->host_id);
  759. }
  760.         for (i = 0; i <=QLOGICFC_MAX_ID; i++)
  761.                 temp[i].loop_id = temp[0].loop_id;
  762.    
  763.         for (i = 0, j = 1; i <= QLOGICFC_MAX_LOOP_ID; i++) {
  764.                 param[0] = MBOX_GET_PORT_NAME;
  765. param[1] = (i << 8) & 0xff00;
  766. isp2x00_mbox_command(host, param);
  767. if (param[0] == MBOX_COMMAND_COMPLETE) {
  768. temp[j].loop_id = i;
  769. temp[j].wwn = ((u64) (param[2] & 0xff)) << 56;
  770. temp[j].wwn |= ((u64) ((param[2] >> 8) & 0xff)) << 48;
  771. temp[j].wwn |= ((u64) (param[3] & 0xff)) << 40;
  772. temp[j].wwn |= ((u64) ((param[3] >> 8) & 0xff)) << 32;
  773. temp[j].wwn |= ((u64) (param[6] & 0xff)) << 24;
  774. temp[j].wwn |= ((u64) ((param[6] >> 8) & 0xff)) << 16;
  775. temp[j].wwn |= ((u64) (param[7] & 0xff)) << 8;
  776. temp[j].wwn |= ((u64) ((param[7] >> 8) & 0xff));
  777. j++;
  778. }
  779. }
  780. #if ISP2x00_FABRIC
  781. isp2x00_init_fabric(host, temp, j);
  782. #endif
  783. for (i = 0; i <= QLOGICFC_MAX_ID; i++) {
  784. if (temp[i].wwn != hostdata->port_db[i].wwn) {
  785. for (j = 0; j <= QLOGICFC_MAX_ID; j++) {
  786. if (temp[j].wwn == hostdata->port_db[i].wwn) {
  787. hostdata->port_db[i].loop_id = temp[j].loop_id;
  788. break;
  789. }
  790. }
  791. if (j == QLOGICFC_MAX_ID + 1)
  792. hostdata->port_db[i].loop_id = temp[0].loop_id;
  793. for (j = 0; j <= QLOGICFC_MAX_ID; j++) {
  794. if (hostdata->port_db[j].wwn == temp[i].wwn || !hostdata->port_db[j].wwn) {
  795. break;
  796. }
  797. }
  798. if (j == QLOGICFC_MAX_ID + 1)
  799. printk("qlogicfc%d : Too many scsi devices, no more room in port map.n", hostdata->host_id);
  800. if (!hostdata->port_db[j].wwn) {
  801. hostdata->port_db[j].loop_id = temp[i].loop_id;
  802. hostdata->port_db[j].wwn = temp[i].wwn;
  803. }
  804. } else
  805. hostdata->port_db[i].loop_id = temp[i].loop_id;
  806. }
  807. isp2x00_enable_irqs(host);
  808. return 0;
  809. }
  810. #if ISP2x00_FABRIC
  811. #define FABRIC_PORT          0x7e
  812. #define FABRIC_CONTROLLER    0x7f
  813. #define FABRIC_SNS           0x80
  814. int isp2x00_init_fabric(struct Scsi_Host *host, struct id_name_map *port_db, int cur_scsi_id)
  815. {
  816. u_short param[8];
  817. u64 wwn;
  818. int done = 0;
  819. u_short loop_id = 0x81;
  820. u_short scsi_id = cur_scsi_id;
  821. u_int port_id;
  822. struct sns_cb *req;
  823. u_char *sns_response;
  824. dma_addr_t busaddr;
  825. struct isp2x00_hostdata *hostdata;
  826. hostdata = (struct isp2x00_hostdata *) host->hostdata;
  827. DEBUG_FABRIC(printk("qlogicfc%d : Checking for a fabric.n", hostdata->host_id));
  828. param[0] = MBOX_GET_PORT_NAME;
  829. param[1] = (u16)FABRIC_PORT << 8;
  830. isp2x00_mbox_command(host, param);
  831. if (param[0] != MBOX_COMMAND_COMPLETE) {
  832. DEBUG_FABRIC(printk("qlogicfc%d : fabric check result %xn", hostdata->host_id, param[0]));
  833. return 0;
  834. }
  835. printk("qlogicfc%d : Fabric found.n", hostdata->host_id);
  836. req = (struct sns_cb *)pci_alloc_consistent(hostdata->pci_dev, sizeof(*req) + 608, &busaddr);
  837. if (!req){
  838. printk("qlogicfc%d : Could not allocate DMA resources for fabric initializationn", hostdata->host_id);
  839. return 0;
  840. }
  841. sns_response = (u_char *)(req + 1);
  842. if (hostdata->adapter_state & AS_REDO_LOOP_PORTDB){
  843.         memset(req, 0, sizeof(*req));
  844. req->len = cpu_to_le16(8);
  845. req->response_low = cpu_to_le32(pci64_dma_lo32(busaddr + sizeof(*req)));
  846. req->response_high = cpu_to_le32(pci64_dma_hi32(busaddr + sizeof(*req)));
  847. req->sub_len = cpu_to_le16(22);
  848. req->data[0] = 0x17;
  849. req->data[1] = 0x02;
  850. req->data[8] = (u_char) (hostdata->port_id & 0xff);
  851. req->data[9] = (u_char) (hostdata->port_id >> 8 & 0xff);
  852. req->data[10] = (u_char) (hostdata->port_id >> 16 & 0xff);
  853. req->data[13] = 0x01;
  854. param[0] = MBOX_SEND_SNS;
  855. param[1] = 30;
  856. param[2] = pci64_dma_lo32(busaddr) >> 16;
  857. param[3] = pci64_dma_lo32(busaddr);
  858. param[6] = pci64_dma_hi32(busaddr) >> 16;
  859. param[7] = pci64_dma_hi32(busaddr);
  860. isp2x00_mbox_command(host, param);
  861. if (param[0] != MBOX_COMMAND_COMPLETE)
  862.         printk("qlogicfc%d : error sending RFC-4n", hostdata->host_id);
  863. }
  864. port_id = hostdata->port_id;
  865. while (!done) {
  866. memset(req, 0, sizeof(*req));
  867. req->len = cpu_to_le16(304);
  868. req->response_low = cpu_to_le32(pci64_dma_lo32(busaddr + sizeof(*req)));
  869. req->response_high = cpu_to_le32(pci64_dma_hi32(busaddr + sizeof(*req)));
  870. req->sub_len = cpu_to_le16(6);
  871. req->data[0] = 0x00;
  872. req->data[1] = 0x01;
  873. req->data[8] = (u_char) (port_id & 0xff);
  874. req->data[9] = (u_char) (port_id >> 8 & 0xff);
  875. req->data[10] = (u_char) (port_id >> 16 & 0xff);
  876. param[0] = MBOX_SEND_SNS;
  877. param[1] = 14;
  878. param[2] = pci64_dma_lo32(busaddr) >> 16;
  879. param[3] = pci64_dma_lo32(busaddr);
  880. param[6] = pci64_dma_hi32(busaddr) >> 16;
  881. param[7] = pci64_dma_hi32(busaddr);
  882. isp2x00_mbox_command(host, param);
  883. if (param[0] == MBOX_COMMAND_COMPLETE) {
  884. 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]));
  885. DEBUG_FABRIC(printk("  port id: %02x%02x%02xn", sns_response[17], sns_response[18], sns_response[19]));
  886. port_id = ((u_int) sns_response[17]) << 16;
  887. port_id |= ((u_int) sns_response[18]) << 8;
  888. port_id |= ((u_int) sns_response[19]);
  889. wwn = ((u64) sns_response[20]) << 56;
  890. wwn |= ((u64) sns_response[21]) << 48;
  891. wwn |= ((u64) sns_response[22]) << 40;
  892. wwn |= ((u64) sns_response[23]) << 32;
  893. wwn |= ((u64) sns_response[24]) << 24;
  894. wwn |= ((u64) sns_response[25]) << 16;
  895. wwn |= ((u64) sns_response[26]) << 8;
  896. wwn |= ((u64) sns_response[27]);
  897. if (hostdata->port_id >> 8 != port_id >> 8) {
  898. DEBUG_FABRIC(printk("qlogicfc%d : adding a fabric port: %xn", hostdata->host_id, port_id));
  899. param[0] = MBOX_PORT_LOGIN;
  900. param[1] = loop_id << 8;
  901. param[2] = (u_short) (port_id >> 16);
  902. param[3] = (u_short) (port_id);
  903. isp2x00_mbox_command(host, param);
  904. if (param[0] == MBOX_COMMAND_COMPLETE) {
  905. port_db[scsi_id].wwn = wwn;
  906. port_db[scsi_id].loop_id = loop_id;
  907. loop_id++;
  908. scsi_id++;
  909. } else {
  910. printk("qlogicfc%d : Error performing port login %xn", hostdata->host_id, param[0]);
  911. DEBUG_FABRIC(printk("qlogicfc%d : loop_id: %xn", hostdata->host_id, loop_id));
  912. param[0] = MBOX_PORT_LOGOUT;
  913. param[1] = loop_id << 8;
  914. param[2] = 0;
  915. param[3] = 0;
  916. isp2x00_mbox_command(host, param);
  917. }
  918. }
  919. if (hostdata->port_id == port_id)
  920. done = 1;
  921. } else {
  922. printk("qlogicfc%d : Get All Next failed %x.n", hostdata->host_id, param[0]);
  923. pci_free_consistent(hostdata->pci_dev, sizeof(*req) + 608, req, busaddr);
  924. return 0;
  925. }
  926. }
  927. pci_free_consistent(hostdata->pci_dev, sizeof(*req) + 608, req, busaddr);
  928. return 1;
  929. }
  930. #endif /* ISP2x00_FABRIC */
  931. int isp2x00_release(struct Scsi_Host *host)
  932. {
  933. struct isp2x00_hostdata *hostdata;
  934. dma_addr_t busaddr;
  935. ENTER("isp2x00_release");
  936. hostdata = (struct isp2x00_hostdata *) host->hostdata;
  937. outw(0x0, host->io_port + PCI_INTER_CTL);
  938. free_irq(host->irq, host);
  939. release_region(host->io_port, 0xff);
  940. busaddr = pci64_dma_build(le32_to_cpu(hostdata->control_block.res_queue_addr_high),
  941.   le32_to_cpu(hostdata->control_block.res_queue_addr_lo));
  942. pci_free_consistent(hostdata->pci_dev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
  943. LEAVE("isp2x00_release");
  944. return 0;
  945. }
  946. const char *isp2x00_info(struct Scsi_Host *host)
  947. {
  948. static char buf[80];
  949. struct isp2x00_hostdata *hostdata;
  950. ENTER("isp2x00_info");
  951. hostdata = (struct isp2x00_hostdata *) host->hostdata;
  952. sprintf(buf,
  953. "QLogic ISP%04x SCSI on PCI bus %02x device %02x irq %d base 0x%lx",
  954. hostdata->pci_dev->device, hostdata->pci_dev->bus->number, hostdata->pci_dev->devfn, host->irq,
  955. host->io_port);
  956. LEAVE("isp2x00_info");
  957. return buf;
  958. }
  959. /*
  960.  * The middle SCSI layer ensures that queuecommand never gets invoked
  961.  * concurrently with itself or the interrupt handler (though the
  962.  * interrupt handler may call this routine as part of
  963.  * request-completion handling).
  964.  */
  965. int isp2x00_queuecommand(Scsi_Cmnd * Cmnd, void (*done) (Scsi_Cmnd *))
  966. {
  967. int i, sg_count, n, num_free;
  968. u_int in_ptr, out_ptr;
  969. struct dataseg *ds;
  970. struct scatterlist *sg;
  971. struct Command_Entry *cmd;
  972. struct Continuation_Entry *cont;
  973. struct Scsi_Host *host;
  974. struct isp2x00_hostdata *hostdata;
  975. ENTER("isp2x00_queuecommand");
  976. host = Cmnd->host;
  977. hostdata = (struct isp2x00_hostdata *) host->hostdata;
  978. Cmnd->scsi_done = done;
  979. DEBUG(isp2x00_print_scsi_cmd(Cmnd));
  980. if (hostdata->adapter_state & AS_REDO_FABRIC_PORTDB || hostdata->adapter_state & AS_REDO_LOOP_PORTDB) {
  981. isp2x00_make_portdb(host);
  982. hostdata->adapter_state = AS_LOOP_GOOD;
  983. printk("qlogicfc%d : Port Databasen", hostdata->host_id);
  984. for (i = 0; hostdata->port_db[i].wwn != 0; i++) {
  985. 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);
  986. if (hostdata->port_db[i].loop_id != hostdata->port_db[0].loop_id || i == 0)
  987.         printk("%x", hostdata->port_db[i].loop_id);
  988. else
  989.         printk("Not Available");
  990. printk("n");
  991. }
  992. }
  993. if (hostdata->adapter_state == AS_FIRMWARE_DEAD) {
  994. printk("qlogicfc%d : The firmware is dead, just return.n", hostdata->host_id);
  995. host->max_id = 0;
  996. return 0;
  997. }
  998. out_ptr = inw(host->io_port + MBOX4);
  999. in_ptr = hostdata->req_in_ptr;
  1000. DEBUG(printk("qlogicfc%d : request queue depth %dn", hostdata->host_id,
  1001.      REQ_QUEUE_DEPTH(in_ptr, out_ptr)));
  1002. cmd = (struct Command_Entry *) &hostdata->req[in_ptr*QUEUE_ENTRY_LEN];
  1003. in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
  1004. if (in_ptr == out_ptr) {
  1005. DEBUG(printk("qlogicfc%d : request queue overflown", hostdata->host_id));
  1006. return 1;
  1007. }
  1008. if (hostdata->send_marker) {
  1009. struct Marker_Entry *marker;
  1010. TRACE("queue marker", in_ptr, 0);
  1011. DEBUG(printk("qlogicfc%d : adding marker entryn", hostdata->host_id));
  1012. marker = (struct Marker_Entry *) cmd;
  1013. memset(marker, 0, sizeof(struct Marker_Entry));
  1014. marker->hdr.entry_type = ENTRY_MARKER;
  1015. marker->hdr.entry_cnt = 1;
  1016. marker->modifier = SYNC_ALL;
  1017. hostdata->send_marker = 0;
  1018. if (((in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN) == out_ptr) {
  1019. outw(in_ptr, host->io_port + MBOX4);
  1020. hostdata->req_in_ptr = in_ptr;
  1021. DEBUG(printk("qlogicfc%d : request queue overflown", hostdata->host_id));
  1022. return 1;
  1023. }
  1024. cmd = (struct Command_Entry *) &hostdata->req[in_ptr*QUEUE_ENTRY_LEN];
  1025. in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
  1026. }
  1027. TRACE("queue command", in_ptr, Cmnd);
  1028. memset(cmd, 0, sizeof(struct Command_Entry));
  1029. /* find a free handle mapping slot */
  1030. for (i = in_ptr; i != (in_ptr - 1) && hostdata->handle_ptrs[i]; i = ((i + 1) % (QLOGICFC_REQ_QUEUE_LEN + 1)));
  1031. if (!hostdata->handle_ptrs[i]) {
  1032. cmd->handle = cpu_to_le32(i);
  1033. hostdata->handle_ptrs[i] = Cmnd;
  1034. hostdata->handle_serials[i] = Cmnd->serial_number;
  1035. } else {
  1036. printk("qlogicfc%d : no handle slots, this should not happen.n", hostdata->host_id);
  1037. printk("hostdata->queued is %x, in_ptr: %xn", hostdata->queued, in_ptr);
  1038. for (i = 0; i <= QLOGICFC_REQ_QUEUE_LEN; i++){
  1039. if (!hostdata->handle_ptrs[i]){
  1040. printk("slot %d has %pn", i, hostdata->handle_ptrs[i]);
  1041. }
  1042. }
  1043. return 1;
  1044. }
  1045. cmd->hdr.entry_type = ENTRY_COMMAND;
  1046. cmd->hdr.entry_cnt = 1;
  1047. cmd->target_lun = Cmnd->lun;
  1048. cmd->expanded_lun = cpu_to_le16(Cmnd->lun);
  1049. #if ISP2x00_PORTDB
  1050. cmd->target_id = hostdata->port_db[Cmnd->target].loop_id;
  1051. #else
  1052. cmd->target_id = Cmnd->target;
  1053. #endif
  1054. cmd->total_byte_cnt = cpu_to_le32(Cmnd->request_bufflen);
  1055. cmd->time_out = 0;
  1056. memcpy(cmd->cdb, Cmnd->cmnd, Cmnd->cmd_len);
  1057. if (Cmnd->use_sg) {
  1058. sg = (struct scatterlist *) Cmnd->request_buffer;
  1059. sg_count = pci_map_sg(hostdata->pci_dev, sg, Cmnd->use_sg, scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
  1060. cmd->segment_cnt = cpu_to_le16(sg_count);
  1061. ds = cmd->dataseg;
  1062. /* fill in first two sg entries: */
  1063. n = sg_count;
  1064. if (n > DATASEGS_PER_COMMAND)
  1065. n = DATASEGS_PER_COMMAND;
  1066. for (i = 0; i < n; i++) {
  1067. ds[i].d_base = cpu_to_le32(pci64_dma_lo32(sg_dma_address(sg)));
  1068. ds[i].d_base_hi = cpu_to_le32(pci64_dma_hi32(sg_dma_address(sg)));
  1069. ds[i].d_count = cpu_to_le32(sg_dma_len(sg));
  1070. ++sg;
  1071. }
  1072. sg_count -= DATASEGS_PER_COMMAND;
  1073. while (sg_count > 0) {
  1074. ++cmd->hdr.entry_cnt;
  1075. cont = (struct Continuation_Entry *)
  1076.     &hostdata->req[in_ptr*QUEUE_ENTRY_LEN];
  1077. memset(cont, 0, sizeof(struct Continuation_Entry));
  1078. in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
  1079. if (in_ptr == out_ptr) {
  1080. DEBUG(printk("qlogicfc%d : unexpected request queue overflown", hostdata->host_id));
  1081. return 1;
  1082. }
  1083. TRACE("queue continuation", in_ptr, 0);
  1084. cont->hdr.entry_type = ENTRY_CONTINUATION;
  1085. ds = cont->dataseg;
  1086. n = sg_count;
  1087. if (n > DATASEGS_PER_CONT)
  1088. n = DATASEGS_PER_CONT;
  1089. for (i = 0; i < n; ++i) {
  1090. ds[i].d_base = cpu_to_le32(pci64_dma_lo32(sg_dma_address(sg)));
  1091. ds[i].d_base_hi = cpu_to_le32(pci64_dma_hi32(sg_dma_address(sg)));
  1092. ds[i].d_count = cpu_to_le32(sg_dma_len(sg));
  1093. ++sg;
  1094. }
  1095. sg_count -= n;
  1096. }
  1097. } else if (Cmnd->request_bufflen && Cmnd->sc_data_direction != PCI_DMA_NONE) {
  1098. struct page *page = virt_to_page(Cmnd->request_buffer);
  1099. unsigned long offset = ((unsigned long)Cmnd->request_buffer &
  1100. ~PAGE_MASK);
  1101. dma_addr_t busaddr = pci_map_page(hostdata->pci_dev,
  1102.   page, offset,
  1103.   Cmnd->request_bufflen,
  1104.   scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
  1105. Cmnd->SCp.dma_handle = busaddr;
  1106. cmd->dataseg[0].d_base = cpu_to_le32(pci64_dma_lo32(busaddr));
  1107. cmd->dataseg[0].d_base_hi = cpu_to_le32(pci64_dma_hi32(busaddr));
  1108. cmd->dataseg[0].d_count = cpu_to_le32(Cmnd->request_bufflen);
  1109. cmd->segment_cnt = cpu_to_le16(1);
  1110. } else {
  1111. cmd->dataseg[0].d_base = 0;
  1112. cmd->dataseg[0].d_base_hi = 0;
  1113. cmd->segment_cnt = cpu_to_le16(1); /* Shouldn't this be 0? */
  1114. }
  1115. if (Cmnd->sc_data_direction == SCSI_DATA_WRITE)
  1116. cmd->control_flags = cpu_to_le16(CFLAG_WRITE);
  1117. else 
  1118. cmd->control_flags = cpu_to_le16(CFLAG_READ);
  1119. if (Cmnd->device->tagged_supported) {
  1120. if ((jiffies - hostdata->tag_ages[Cmnd->target]) > (2 * SCSI_TIMEOUT)) {
  1121. cmd->control_flags |= cpu_to_le16(CFLAG_ORDERED_TAG);
  1122. hostdata->tag_ages[Cmnd->target] = jiffies;
  1123. } else
  1124. switch (Cmnd->tag) {
  1125. case HEAD_OF_QUEUE_TAG:
  1126. cmd->control_flags |= cpu_to_le16(CFLAG_HEAD_TAG);
  1127. break;
  1128. case ORDERED_QUEUE_TAG:
  1129. cmd->control_flags |= cpu_to_le16(CFLAG_ORDERED_TAG);
  1130. break;
  1131. default:
  1132. cmd->control_flags |= cpu_to_le16(CFLAG_SIMPLE_TAG);
  1133. break;
  1134. }
  1135. }
  1136. /*
  1137.  * TEST_UNIT_READY commands from scsi_scan will fail due to "overlapped
  1138.  * commands attempted" unless we setup at least a simple queue (midlayer 
  1139.  * will embelish this once it can do an INQUIRY command to the device)
  1140.  */
  1141. else
  1142. cmd->control_flags |= cpu_to_le16(CFLAG_SIMPLE_TAG);
  1143. outw(in_ptr, host->io_port + MBOX4);
  1144. hostdata->req_in_ptr = in_ptr;
  1145. hostdata->queued++;
  1146. num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
  1147. num_free = (num_free > 2) ? num_free - 2 : 0;
  1148. host->can_queue = host->host_busy + num_free;
  1149. if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)
  1150. host->can_queue = QLOGICFC_REQ_QUEUE_LEN;
  1151. host->sg_tablesize = QLOGICFC_MAX_SG(num_free);
  1152. LEAVE("isp2x00_queuecommand");
  1153. return 0;
  1154. }
  1155. /* we have received an event, such as a lip or an RSCN, which may mean that
  1156.  * our port database is incorrect so the port database must be recreated.
  1157.  */
  1158. static void redo_port_db(unsigned long arg)
  1159. {
  1160.         struct Scsi_Host * host = (struct Scsi_Host *) arg;
  1161. struct isp2x00_hostdata * hostdata;
  1162. unsigned long flags;
  1163. int i;
  1164. hostdata = (struct isp2x00_hostdata *) host->hostdata;
  1165. hostdata->explore_timer.data = 0;
  1166. del_timer(&hostdata->explore_timer);
  1167. spin_lock_irqsave(&io_request_lock, flags);
  1168. if (hostdata->adapter_state & AS_REDO_FABRIC_PORTDB || hostdata->adapter_state & AS_REDO_LOOP_PORTDB) {
  1169. isp2x00_make_portdb(host);
  1170. printk("qlogicfc%d : Port Databasen", hostdata->host_id);
  1171. for (i = 0; hostdata->port_db[i].wwn != 0; i++) {
  1172. 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);
  1173. if (hostdata->port_db[i].loop_id != hostdata->port_db[0].loop_id || i == 0)
  1174.         printk("%x", hostdata->port_db[i].loop_id);
  1175. else
  1176.         printk("Not Available");
  1177. printk("n");
  1178. }
  1179.         for (i = 0; i < QLOGICFC_REQ_QUEUE_LEN; i++){ 
  1180.         if (hostdata->handle_ptrs[i] && (hostdata->port_db[hostdata->handle_ptrs[i]->target].loop_id > QLOGICFC_MAX_LOOP_ID || hostdata->adapter_state & AS_REDO_LOOP_PORTDB)){
  1181.                                 if (hostdata->port_db[hostdata->handle_ptrs[i]->target].loop_id != hostdata->port_db[0].loop_id){
  1182. Scsi_Cmnd *Cmnd = hostdata->handle_ptrs[i];
  1183.  if (Cmnd->use_sg)
  1184.  pci_unmap_sg(hostdata->pci_dev,
  1185.       (struct scatterlist *)Cmnd->buffer,
  1186.       Cmnd->use_sg,
  1187.       scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
  1188.  else if (Cmnd->request_bufflen &&
  1189.   Cmnd->sc_data_direction != PCI_DMA_NONE) {
  1190.  pci_unmap_page(hostdata->pci_dev,
  1191. Cmnd->SCp.dma_handle,
  1192. Cmnd->request_bufflen,
  1193. scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
  1194.  }
  1195.  hostdata->handle_ptrs[i]->result = DID_SOFT_ERROR << 16;
  1196.  if (hostdata->handle_ptrs[i]->scsi_done){
  1197.    (*hostdata->handle_ptrs[i]->scsi_done) (hostdata->handle_ptrs[i]);
  1198.  }
  1199.  else printk("qlogicfc%d : done is null?n", hostdata->host_id);
  1200.  hostdata->handle_ptrs[i] = NULL;
  1201.  hostdata->handle_serials[i] = 0;
  1202. }
  1203. }
  1204. }
  1205. hostdata->adapter_state = AS_LOOP_GOOD;
  1206. }
  1207. spin_unlock_irqrestore(&io_request_lock, flags);
  1208. }
  1209. #define ASYNC_EVENT_INTERRUPT 0x01
  1210. void do_isp2x00_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
  1211. {
  1212. unsigned long flags;
  1213. spin_lock_irqsave(&io_request_lock, flags);
  1214. isp2x00_intr_handler(irq, dev_id, regs);
  1215. spin_unlock_irqrestore(&io_request_lock, flags);
  1216. }
  1217. void isp2x00_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
  1218. {
  1219. Scsi_Cmnd *Cmnd;
  1220. struct Status_Entry *sts;
  1221. struct Scsi_Host *host = dev_id;
  1222. struct isp2x00_hostdata *hostdata;
  1223. u_int in_ptr, out_ptr, handle, num_free;
  1224. u_short status;
  1225. ENTER_INTR("isp2x00_intr_handler");
  1226. hostdata = (struct isp2x00_hostdata *) host->hostdata;
  1227. DEBUG_INTR(printk("qlogicfc%d : interrupt on line %dn", hostdata->host_id, irq));
  1228. if (!(inw(host->io_port + PCI_INTER_STS) & 0x08)) {
  1229. /* spurious interrupts can happen legally */
  1230. DEBUG_INTR(printk("qlogicfc%d : got spurious interruptn", hostdata->host_id));
  1231. return;
  1232. }
  1233. in_ptr = inw(host->io_port + MBOX5);
  1234. out_ptr = hostdata->res_out_ptr;
  1235. if ((inw(host->io_port + PCI_SEMAPHORE) & ASYNC_EVENT_INTERRUPT)) {
  1236. status = inw(host->io_port + MBOX0);
  1237. DEBUG_INTR(printk("qlogicfc%d : mbox completion status: %xn",
  1238.   hostdata->host_id, status));
  1239. switch (status) {
  1240. case LOOP_UP:
  1241. case POINT_TO_POINT_UP:
  1242.         printk("qlogicfc%d : Link is Upn", hostdata->host_id);
  1243. hostdata->adapter_state = AS_REDO_FABRIC_PORTDB | AS_REDO_LOOP_PORTDB;
  1244. break;
  1245. case LOOP_DOWN:
  1246.         printk("qlogicfc%d : Link is Downn", hostdata->host_id);
  1247. hostdata->adapter_state = AS_LOOP_DOWN;
  1248. break;
  1249. case CONNECTION_MODE:
  1250.         printk("received CONNECTION_MODE irq %xn", inw(host->io_port + MBOX1));
  1251. break;
  1252. case CHANGE_NOTIFICATION:
  1253.         printk("qlogicfc%d : RSCN Receivedn", hostdata->host_id);
  1254. if (hostdata->adapter_state == AS_LOOP_GOOD)
  1255. hostdata->adapter_state = AS_REDO_FABRIC_PORTDB;
  1256. break;         
  1257. case LIP_OCCURRED:
  1258. case LIP_RECEIVED:
  1259.         printk("qlogicfc%d : Loop Reinitializedn", hostdata->host_id);
  1260. if (hostdata->adapter_state == AS_LOOP_GOOD)
  1261. hostdata->adapter_state = AS_REDO_LOOP_PORTDB;
  1262. break;
  1263. case SYSTEM_ERROR:
  1264. printk("qlogicfc%d : The firmware just choked.n", hostdata->host_id);
  1265. hostdata->adapter_state = AS_FIRMWARE_DEAD;
  1266. break;
  1267. case SCSI_COMMAND_COMPLETE:
  1268. handle = inw(host->io_port + MBOX1) | (inw(host->io_port + MBOX2) << 16);
  1269. Cmnd = hostdata->handle_ptrs[handle];
  1270. hostdata->handle_ptrs[handle] = NULL;
  1271. hostdata->handle_serials[handle] = 0;
  1272. hostdata->queued--;
  1273. if (Cmnd != NULL) {
  1274. if (Cmnd->use_sg)
  1275. pci_unmap_sg(hostdata->pci_dev,
  1276.      (struct scatterlist *)Cmnd->buffer,
  1277.      Cmnd->use_sg,
  1278.      scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
  1279. else if (Cmnd->request_bufflen &&
  1280.  Cmnd->sc_data_direction != PCI_DMA_NONE)
  1281. pci_unmap_page(hostdata->pci_dev,
  1282.        Cmnd->SCp.dma_handle,
  1283.        Cmnd->request_bufflen,
  1284.        scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
  1285. Cmnd->result = 0x0;
  1286. (*Cmnd->scsi_done) (Cmnd);
  1287. } else
  1288. printk("qlogicfc%d.c : got a null value out of handle_ptrs, this sucksn", hostdata->host_id);
  1289. break;
  1290. case MBOX_COMMAND_COMPLETE:
  1291. case INVALID_COMMAND:
  1292. case HOST_INTERFACE_ERROR:
  1293. case TEST_FAILED:
  1294. case COMMAND_ERROR:
  1295. case COMMAND_PARAM_ERROR:
  1296. case PORT_ID_USED:
  1297. case LOOP_ID_USED:
  1298. case ALL_IDS_USED:
  1299. hostdata->mbox_done = 1;
  1300. outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
  1301. return;
  1302. default:
  1303. printk("qlogicfc%d : got an unknown status? %xn", hostdata->host_id, status);
  1304. }
  1305. if ((hostdata->adapter_state & AS_REDO_LOOP_PORTDB || hostdata->adapter_state & AS_REDO_FABRIC_PORTDB) && hostdata->explore_timer.data == 0){
  1306.                         hostdata->explore_timer.function = redo_port_db;
  1307. hostdata->explore_timer.data = (unsigned long)host;
  1308. hostdata->explore_timer.expires = jiffies + (HZ/4);
  1309. init_timer(&hostdata->explore_timer);
  1310. add_timer(&hostdata->explore_timer);
  1311. }
  1312. outw(0x0, host->io_port + PCI_SEMAPHORE);
  1313. } else {
  1314. DEBUG_INTR(printk("qlogicfc%d : response queue updaten", hostdata->host_id));
  1315. DEBUG_INTR(printk("qlogicfc%d : response queue depth %dn", hostdata->host_id, RES_QUEUE_DEPTH(in_ptr, out_ptr)));
  1316. while (out_ptr != in_ptr) {
  1317. unsigned le_hand;
  1318. sts = (struct Status_Entry *) &hostdata->res[out_ptr*QUEUE_ENTRY_LEN];
  1319. out_ptr = (out_ptr + 1) & RES_QUEUE_LEN;
  1320.                  
  1321. TRACE("done", out_ptr, Cmnd);
  1322. DEBUG_INTR(isp2x00_print_status_entry(sts));
  1323. le_hand = le32_to_cpu(sts->handle);
  1324. if (sts->hdr.entry_type == ENTRY_STATUS && (Cmnd = hostdata->handle_ptrs[le_hand])) {
  1325. Cmnd->result = isp2x00_return_status(Cmnd, sts);
  1326. hostdata->queued--;
  1327. if (Cmnd->use_sg)
  1328. pci_unmap_sg(hostdata->pci_dev,
  1329.      (struct scatterlist *)Cmnd->buffer, Cmnd->use_sg,
  1330.      scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
  1331. else if (Cmnd->request_bufflen && Cmnd->sc_data_direction != PCI_DMA_NONE)
  1332. pci_unmap_page(hostdata->pci_dev,
  1333.        Cmnd->SCp.dma_handle,
  1334.        Cmnd->request_bufflen,
  1335.        scsi_to_pci_dma_dir(Cmnd->sc_data_direction));
  1336. /* 
  1337.  * if any of the following are true we do not
  1338.  * call scsi_done.  if the status is CS_ABORTED
  1339.  * we dont have to call done because the upper
  1340.  * level should already know its aborted.
  1341.  */
  1342. if (hostdata->handle_serials[le_hand] != Cmnd->serial_number 
  1343.     || le16_to_cpu(sts->completion_status) == CS_ABORTED){
  1344. hostdata->handle_serials[le_hand] = 0;
  1345. hostdata->handle_ptrs[le_hand] = NULL;
  1346. outw(out_ptr, host->io_port + MBOX5);
  1347. continue;
  1348. }
  1349. /*
  1350.  * if we get back an error indicating the port
  1351.  * is not there or if the link is down and 
  1352.  * this is a device that used to be there 
  1353.  * allow the command to timeout.
  1354.  * the device may well be back in a couple of
  1355.  * seconds.
  1356.  */
  1357. 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->target].wwn){
  1358. outw(out_ptr, host->io_port + MBOX5);
  1359. continue;
  1360. }
  1361. } else {
  1362. outw(out_ptr, host->io_port + MBOX5);
  1363. continue;
  1364. }
  1365. hostdata->handle_ptrs[le_hand] = NULL;
  1366. if (sts->completion_status == cpu_to_le16(CS_RESET_OCCURRED)
  1367.     || (sts->status_flags & cpu_to_le16(STF_BUS_RESET)))
  1368. hostdata->send_marker = 1;
  1369. if (le16_to_cpu(sts->scsi_status) & 0x0200)
  1370. memcpy(Cmnd->sense_buffer, sts->req_sense_data,
  1371.        sizeof(Cmnd->sense_buffer));
  1372. outw(out_ptr, host->io_port + MBOX5);
  1373. if (Cmnd->scsi_done != NULL) {
  1374. (*Cmnd->scsi_done) (Cmnd);
  1375. } else
  1376. printk("qlogicfc%d : Ouch, scsi done is NULLn", hostdata->host_id);
  1377. }
  1378. hostdata->res_out_ptr = out_ptr;
  1379. }
  1380. out_ptr = inw(host->io_port + MBOX4);
  1381. in_ptr = hostdata->req_in_ptr;
  1382. num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
  1383. num_free = (num_free > 2) ? num_free - 2 : 0;
  1384. host->can_queue = host->host_busy + num_free;
  1385. if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)
  1386. host->can_queue = QLOGICFC_REQ_QUEUE_LEN;
  1387. host->sg_tablesize = QLOGICFC_MAX_SG(num_free);
  1388. outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
  1389. LEAVE_INTR("isp2x00_intr_handler");
  1390. }
  1391. static int isp2x00_return_status(Scsi_Cmnd *Cmnd, struct Status_Entry *sts)
  1392. {
  1393. int host_status = DID_ERROR;
  1394. #if DEBUG_ISP2x00_INTR
  1395. static char *reason[] =
  1396. {
  1397. "DID_OK",
  1398. "DID_NO_CONNECT",
  1399. "DID_BUS_BUSY",
  1400. "DID_TIME_OUT",
  1401. "DID_BAD_TARGET",
  1402. "DID_ABORT",
  1403. "DID_PARITY",
  1404. "DID_ERROR",
  1405. "DID_RESET",
  1406. "DID_BAD_INTR"
  1407. };
  1408. #endif /* DEBUG_ISP2x00_INTR */
  1409. ENTER("isp2x00_return_status");
  1410. DEBUG(printk("qlogicfc : completion status = 0x%04xn",
  1411.      le16_to_cpu(sts->completion_status)));
  1412. switch (le16_to_cpu(sts->completion_status)) {
  1413. case CS_COMPLETE:
  1414. host_status = DID_OK;
  1415. break;
  1416. case CS_DMA_ERROR:
  1417. host_status = DID_ERROR;
  1418. break;
  1419. case CS_RESET_OCCURRED:
  1420. host_status = DID_RESET;
  1421. break;
  1422. case CS_ABORTED:
  1423. host_status = DID_ABORT;
  1424. break;
  1425. case CS_TIMEOUT:
  1426. host_status = DID_TIME_OUT;
  1427. break;
  1428. case CS_DATA_OVERRUN:
  1429. host_status = DID_ERROR;
  1430. break;
  1431. case CS_DATA_UNDERRUN:
  1432.         if (Cmnd->underflow <= (Cmnd->request_bufflen - le32_to_cpu(sts->residual)))
  1433.         host_status = DID_OK;
  1434. else
  1435.         host_status = DID_ERROR;
  1436. break;
  1437. case CS_PORT_UNAVAILABLE:
  1438. case CS_PORT_LOGGED_OUT:
  1439. case CS_PORT_CONFIG_CHANGED:
  1440. host_status = DID_BAD_TARGET;
  1441. break;
  1442. case CS_QUEUE_FULL:
  1443. host_status = DID_ERROR;
  1444. break;
  1445. default:
  1446. printk("qlogicfc : unknown completion status 0x%04xn",
  1447.        le16_to_cpu(sts->completion_status));
  1448. host_status = DID_ERROR;
  1449. break;
  1450. }
  1451. DEBUG_INTR(printk("qlogicfc : host status (%s) scsi status %xn",
  1452.   reason[host_status], le16_to_cpu(sts->scsi_status)));
  1453. LEAVE("isp2x00_return_status");
  1454. return (le16_to_cpu(sts->scsi_status) & STATUS_MASK) | (host_status << 16);
  1455. }
  1456. int isp2x00_abort(Scsi_Cmnd * Cmnd)
  1457. {
  1458. u_short param[8];
  1459. int i;
  1460. struct Scsi_Host *host;
  1461. struct isp2x00_hostdata *hostdata;
  1462. int return_status = SUCCESS;
  1463. ENTER("isp2x00_abort");
  1464. host = Cmnd->host;
  1465. hostdata = (struct isp2x00_hostdata *) host->hostdata;
  1466. for (i = 0; i < QLOGICFC_REQ_QUEUE_LEN; i++)
  1467. if (hostdata->handle_ptrs[i] == Cmnd)
  1468. break;
  1469. if (i == QLOGICFC_REQ_QUEUE_LEN){
  1470. return SUCCESS;
  1471. }
  1472. isp2x00_disable_irqs(host);
  1473. param[0] = MBOX_ABORT_IOCB;
  1474. #if ISP2x00_PORTDB
  1475. param[1] = (((u_short) hostdata->port_db[Cmnd->target].loop_id) << 8) | Cmnd->lun;
  1476. #else
  1477. param[1] = (((u_short) Cmnd->target) << 8) | Cmnd->lun;
  1478. #endif
  1479. param[2] = i & 0xffff;
  1480. param[3] = i >> 16;
  1481. isp2x00_mbox_command(host, param);
  1482. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1483. printk("qlogicfc%d : scsi abort failure: %xn", hostdata->host_id, param[0]);
  1484. if (param[0] == 0x4005)
  1485. Cmnd->result = DID_ERROR << 16;
  1486. if (param[0] == 0x4006)
  1487. Cmnd->result = DID_BAD_TARGET << 16;
  1488. return_status = FAILED;
  1489. }
  1490. if (return_status != SUCCESS){
  1491. param[0] = MBOX_GET_FIRMWARE_STATE;
  1492. isp2x00_mbox_command(host, param);
  1493. printk("qlogicfc%d : abort failedn", hostdata->host_id);
  1494. printk("qlogicfc%d : firmware status is %x %xn", hostdata->host_id, param[0], param[1]);
  1495. }
  1496. isp2x00_enable_irqs(host);
  1497. LEAVE("isp2x00_abort");
  1498. return return_status;
  1499. }
  1500. int isp2x00_reset(Scsi_Cmnd * Cmnd, unsigned int reset_flags)
  1501. {
  1502. u_short param[8];
  1503. struct Scsi_Host *host;
  1504. struct isp2x00_hostdata *hostdata;
  1505. int return_status = SCSI_RESET_SUCCESS;
  1506. ENTER("isp2x00_reset");
  1507. host = Cmnd->host;
  1508. hostdata = (struct isp2x00_hostdata *) host->hostdata;
  1509. param[0] = MBOX_BUS_RESET;
  1510. param[1] = 3;
  1511. isp2x00_disable_irqs(host);
  1512. isp2x00_mbox_command(host, param);
  1513. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1514. printk("qlogicfc%d : scsi bus reset failure: %xn", hostdata->host_id, param[0]);
  1515. return_status = SCSI_RESET_ERROR;
  1516. }
  1517. isp2x00_enable_irqs(host);
  1518. LEAVE("isp2x00_reset");
  1519. return return_status;;
  1520. }
  1521. int isp2x00_biosparam(Disk * disk, kdev_t n, int ip[])
  1522. {
  1523. int size = disk->capacity;
  1524. ENTER("isp2x00_biosparam");
  1525. ip[0] = 64;
  1526. ip[1] = 32;
  1527. ip[2] = size >> 11;
  1528. if (ip[2] > 1024) {
  1529. ip[0] = 255;
  1530. ip[1] = 63;
  1531. ip[2] = size / (ip[0] * ip[1]);
  1532. }
  1533. LEAVE("isp2x00_biosparam");
  1534. return 0;
  1535. }
  1536. static int isp2x00_reset_hardware(struct Scsi_Host *host)
  1537. {
  1538. u_short param[8];
  1539. struct isp2x00_hostdata *hostdata;
  1540. int loop_count;
  1541. dma_addr_t busaddr;
  1542. ENTER("isp2x00_reset_hardware");
  1543. hostdata = (struct isp2x00_hostdata *) host->hostdata;
  1544. /*
  1545.  * This cannot be right - PCI writes are posted
  1546.  * (apparently this is hardware design flaw not software ?)
  1547.  */
  1548.  
  1549. outw(0x01, host->io_port + ISP_CTRL_STATUS);
  1550. udelay(100);
  1551. outw(HCCR_RESET, host->io_port + HOST_HCCR);
  1552. udelay(100);
  1553. outw(HCCR_RELEASE, host->io_port + HOST_HCCR);
  1554. outw(HCCR_BIOS_DISABLE, host->io_port + HOST_HCCR);
  1555. loop_count = DEFAULT_LOOP_COUNT;
  1556. while (--loop_count && inw(host->io_port + HOST_HCCR) == RISC_BUSY) {
  1557. barrier();
  1558. cpu_relax();
  1559. }
  1560. if (!loop_count)
  1561. printk("qlogicfc%d : reset_hardware loop timeoutn", hostdata->host_id);
  1562. #if DEBUG_ISP2x00
  1563. printk("qlogicfc%d : mbox 0 0x%04x n", hostdata->host_id,  inw(host->io_port + MBOX0));
  1564. printk("qlogicfc%d : mbox 1 0x%04x n", hostdata->host_id,  inw(host->io_port + MBOX1));
  1565. printk("qlogicfc%d : mbox 2 0x%04x n", hostdata->host_id,  inw(host->io_port + MBOX2));
  1566. printk("qlogicfc%d : mbox 3 0x%04x n", hostdata->host_id,  inw(host->io_port + MBOX3));
  1567. printk("qlogicfc%d : mbox 4 0x%04x n", hostdata->host_id,  inw(host->io_port + MBOX4));
  1568. printk("qlogicfc%d : mbox 5 0x%04x n", hostdata->host_id,  inw(host->io_port + MBOX5));
  1569. printk("qlogicfc%d : mbox 6 0x%04x n", hostdata->host_id,  inw(host->io_port + MBOX6));
  1570. printk("qlogicfc%d : mbox 7 0x%04x n", hostdata->host_id,  inw(host->io_port + MBOX7));
  1571. #endif /* DEBUG_ISP2x00 */
  1572. DEBUG(printk("qlogicfc%d : verifying checksumn", hostdata->host_id));
  1573. #if defined(CONFIG_SCSI_QLOGIC_FC_FIRMWARE)
  1574. {
  1575. int i;
  1576. unsigned short * risc_code = NULL;
  1577. unsigned short risc_code_len = 0;
  1578. if (hostdata->pci_dev->device == PCI_DEVICE_ID_QLOGIC_ISP2100){
  1579.         risc_code = risc_code2100;
  1580. risc_code_len = risc_code_length2100;
  1581. }
  1582. else if (hostdata->pci_dev->device == PCI_DEVICE_ID_QLOGIC_ISP2200){
  1583.         risc_code = risc_code2200;
  1584. risc_code_len = risc_code_length2200;
  1585. }
  1586. for (i = 0; i < risc_code_len; i++) {
  1587. param[0] = MBOX_WRITE_RAM_WORD;
  1588. param[1] = risc_code_addr01 + i;
  1589. param[2] = risc_code[i];
  1590. isp2x00_mbox_command(host, param);
  1591. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1592. printk("qlogicfc%d : firmware load failuren", hostdata->host_id);
  1593. return 1;
  1594. }
  1595. }
  1596. }
  1597. #endif /* RELOAD_FIRMWARE */
  1598. param[0] = MBOX_VERIFY_CHECKSUM;
  1599. param[1] = risc_code_addr01;
  1600. isp2x00_mbox_command(host, param);
  1601. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1602. printk("qlogicfc%d : ram checksum failuren", hostdata->host_id);
  1603. return 1;
  1604. }
  1605. DEBUG(printk("qlogicfc%d : executing firmwaren", hostdata->host_id));
  1606. param[0] = MBOX_EXEC_FIRMWARE;
  1607. param[1] = risc_code_addr01;
  1608. isp2x00_mbox_command(host, param);
  1609. param[0] = MBOX_ABOUT_FIRMWARE;
  1610. isp2x00_mbox_command(host, param);
  1611. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1612. printk("qlogicfc%d : about firmware failuren", hostdata->host_id);
  1613. return 1;
  1614. }
  1615. DEBUG(printk("qlogicfc%d : firmware major revision %dn", hostdata->host_id,  param[1]));
  1616. DEBUG(printk("qlogicfc%d : firmware minor revision %dn", hostdata->host_id,  param[2]));
  1617. #ifdef USE_NVRAM_DEFAULTS
  1618. if (isp2x00_get_nvram_defaults(host, &hostdata->control_block) != 0) {
  1619. printk("qlogicfc%d : Could not read from NVRAMn", hostdata->host_id);
  1620. }
  1621. #endif
  1622. hostdata->wwn = (u64) (cpu_to_le16(hostdata->control_block.node_name[0])) << 56;
  1623. hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[0]) & 0xff00) << 48;
  1624. hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[1]) & 0xff00) << 24;
  1625. hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[1]) & 0x00ff) << 48;
  1626. hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[2]) & 0x00ff) << 24;
  1627. hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[2]) & 0xff00) << 8;
  1628. hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[3]) & 0x00ff) << 8;
  1629. hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[3]) & 0xff00) >> 8;
  1630. /* FIXME: If the DMA transfer goes one way only, this should use
  1631.  *        PCI_DMA_TODEVICE and below as well.
  1632.  */
  1633. busaddr = pci_map_page(hostdata->pci_dev,
  1634.        virt_to_page(&hostdata->control_block),
  1635.        ((unsigned long) &hostdata->control_block &
  1636. ~PAGE_MASK),
  1637.        sizeof(hostdata->control_block),
  1638.        PCI_DMA_BIDIRECTIONAL);
  1639. param[0] = MBOX_INIT_FIRMWARE;
  1640. param[2] = (u_short) (pci64_dma_lo32(busaddr) >> 16);
  1641. param[3] = (u_short) (pci64_dma_lo32(busaddr) & 0xffff);
  1642. param[4] = 0;
  1643. param[5] = 0;
  1644. param[6] = (u_short) (pci64_dma_hi32(busaddr) >> 16);
  1645. param[7] = (u_short) (pci64_dma_hi32(busaddr) & 0xffff);
  1646. isp2x00_mbox_command(host, param);
  1647. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1648. printk("qlogicfc%d.c: Ouch 0x%04xn", hostdata->host_id,  param[0]);
  1649. pci_unmap_page(hostdata->pci_dev, busaddr,
  1650.        sizeof(hostdata->control_block),
  1651.        PCI_DMA_BIDIRECTIONAL);
  1652. return 1;
  1653. }
  1654. param[0] = MBOX_GET_FIRMWARE_STATE;
  1655. isp2x00_mbox_command(host, param);
  1656. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1657. printk("qlogicfc%d.c: 0x%04xn", hostdata->host_id,  param[0]);
  1658. pci_unmap_page(hostdata->pci_dev, busaddr,
  1659.        sizeof(hostdata->control_block),
  1660.        PCI_DMA_BIDIRECTIONAL);
  1661. return 1;
  1662. }
  1663. pci_unmap_page(hostdata->pci_dev, busaddr,
  1664.        sizeof(hostdata->control_block),
  1665.        PCI_DMA_BIDIRECTIONAL);
  1666. LEAVE("isp2x00_reset_hardware");
  1667. return 0;
  1668. }
  1669. #ifdef USE_NVRAM_DEFAULTS
  1670. static int isp2x00_get_nvram_defaults(struct Scsi_Host *host, struct init_cb *control_block)
  1671. {
  1672. u_short value;
  1673. if (isp2x00_read_nvram_word(host, 0) != 0x5349)
  1674. return 1;
  1675. value = isp2x00_read_nvram_word(host, 8);
  1676. control_block->node_name[0] = cpu_to_le16(isp2x00_read_nvram_word(host, 9));
  1677. control_block->node_name[1] = cpu_to_le16(isp2x00_read_nvram_word(host, 10));
  1678. control_block->node_name[2] = cpu_to_le16(isp2x00_read_nvram_word(host, 11));
  1679. control_block->node_name[3] = cpu_to_le16(isp2x00_read_nvram_word(host, 12));
  1680. control_block->hard_addr = cpu_to_le16(isp2x00_read_nvram_word(host, 13));
  1681. return 0;
  1682. }
  1683. #endif
  1684. static int isp2x00_init(struct Scsi_Host *sh)
  1685. {
  1686. u_long io_base;
  1687. struct isp2x00_hostdata *hostdata;
  1688. u_char revision;
  1689. u_int irq;
  1690. u_short command;
  1691. struct pci_dev *pdev;
  1692. ENTER("isp2x00_init");
  1693. hostdata = (struct isp2x00_hostdata *) sh->hostdata;
  1694. pdev = hostdata->pci_dev;
  1695. if (pci_read_config_word(pdev, PCI_COMMAND, &command)
  1696.   || pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision)) {
  1697. printk("qlogicfc%d : error reading PCI configurationn", hostdata->host_id);
  1698. return 1;
  1699. }
  1700. io_base = pci_resource_start(pdev, 0);
  1701. irq = pdev->irq;
  1702. if (pdev->vendor != PCI_VENDOR_ID_QLOGIC) {
  1703. printk("qlogicfc%d : 0x%04x is not QLogic vendor IDn", hostdata->host_id, 
  1704.        pdev->vendor);
  1705. return 1;
  1706. }
  1707. if (pdev->device != PCI_DEVICE_ID_QLOGIC_ISP2100 && pdev->device != PCI_DEVICE_ID_QLOGIC_ISP2200) {
  1708. printk("qlogicfc%d : 0x%04x does not match ISP2100 or ISP2200 device idn", hostdata->host_id, 
  1709.        pdev->device);
  1710. return 1;
  1711. }
  1712. if (!(command & PCI_COMMAND_IO) ||
  1713.     !(pdev->resource[0].flags & IORESOURCE_IO)) {
  1714. printk("qlogicfc%d : i/o mapping is disabledn", hostdata->host_id);
  1715. return 1;
  1716. }
  1717. if (!(command & PCI_COMMAND_MASTER)) {
  1718. printk("qlogicfc%d : bus mastering is disabledn", hostdata->host_id);
  1719. return 1;
  1720. }
  1721. if (revision != ISP2100_REV_ID1 && revision != ISP2100_REV_ID3 && revision != ISP2200_REV_ID5)
  1722. printk("qlogicfc%d : new isp2x00 revision ID (%d)n", hostdata->host_id,  revision);
  1723. hostdata->revision = revision;
  1724. sh->irq = irq;
  1725. sh->io_port = io_base;
  1726. LEAVE("isp2x00_init");
  1727. return 0;
  1728. }
  1729. #if USE_NVRAM_DEFAULTS
  1730. #define NVRAM_DELAY() udelay(10) /* 10 microsecond delay */
  1731. u_short isp2x00_read_nvram_word(struct Scsi_Host * host, u_short byte)
  1732. {
  1733. int i;
  1734. u_short value, output, input;
  1735. outw(0x2, host->io_port + PCI_NVRAM);
  1736. NVRAM_DELAY();
  1737. outw(0x3, host->io_port + PCI_NVRAM);
  1738. NVRAM_DELAY();
  1739. byte &= 0xff;
  1740. byte |= 0x0600;
  1741. for (i = 10; i >= 0; i--) {
  1742. output = ((byte >> i) & 0x1) ? 0x4 : 0x0;
  1743. outw(output | 0x2, host->io_port + PCI_NVRAM);
  1744. NVRAM_DELAY();
  1745. outw(output | 0x3, host->io_port + PCI_NVRAM);
  1746. NVRAM_DELAY();
  1747. outw(output | 0x2, host->io_port + PCI_NVRAM);
  1748. NVRAM_DELAY();
  1749. }
  1750. for (i = 0xf, value = 0; i >= 0; i--) {
  1751. value <<= 1;
  1752. outw(0x3, host->io_port + PCI_NVRAM);
  1753. NVRAM_DELAY();
  1754. input = inw(host->io_port + PCI_NVRAM);
  1755. NVRAM_DELAY();
  1756. outw(0x2, host->io_port + PCI_NVRAM);
  1757. NVRAM_DELAY();
  1758. if (input & 0x8)
  1759. value |= 1;
  1760. }
  1761. outw(0x0, host->io_port + PCI_NVRAM);
  1762. NVRAM_DELAY();
  1763. return value;
  1764. }
  1765. #endif /* USE_NVRAM_DEFAULTS */
  1766. /*
  1767.  * currently, this is only called during initialization or abort/reset,
  1768.  * at which times interrupts are disabled, so polling is OK, I guess...
  1769.  */
  1770. static int isp2x00_mbox_command(struct Scsi_Host *host, u_short param[])
  1771. {
  1772. int loop_count;
  1773. struct isp2x00_hostdata *hostdata = (struct isp2x00_hostdata *) host->hostdata;
  1774. if (mbox_param[param[0]] == 0 || hostdata->adapter_state == AS_FIRMWARE_DEAD)
  1775. return 1;
  1776. loop_count = DEFAULT_LOOP_COUNT;
  1777. while (--loop_count && inw(host->io_port + HOST_HCCR) & 0x0080) {
  1778. barrier();
  1779. cpu_relax();
  1780. }
  1781. if (!loop_count) {
  1782. printk("qlogicfc%d : mbox_command loop timeout #1n", hostdata->host_id);
  1783. param[0] = 0x4006;
  1784. hostdata->adapter_state = AS_FIRMWARE_DEAD;
  1785. return 1;
  1786. }
  1787. hostdata->mbox_done = 0;
  1788. if (mbox_param[param[0]] == 0)
  1789. printk("qlogicfc%d : invalid mbox commandn", hostdata->host_id);
  1790. if (mbox_param[param[0]] & 0x80)
  1791. outw(param[7], host->io_port + MBOX7);
  1792. if (mbox_param[param[0]] & 0x40)
  1793. outw(param[6], host->io_port + MBOX6);
  1794. if (mbox_param[param[0]] & 0x20)
  1795. outw(param[5], host->io_port + MBOX5);
  1796. if (mbox_param[param[0]] & 0x10)
  1797. outw(param[4], host->io_port + MBOX4);
  1798. if (mbox_param[param[0]] & 0x08)
  1799. outw(param[3], host->io_port + MBOX3);
  1800. if (mbox_param[param[0]] & 0x04)
  1801. outw(param[2], host->io_port + MBOX2);
  1802. if (mbox_param[param[0]] & 0x02)
  1803. outw(param[1], host->io_port + MBOX1);
  1804. if (mbox_param[param[0]] & 0x01)
  1805. outw(param[0], host->io_port + MBOX0);
  1806. outw(HCCR_SET_HOST_INTR, host->io_port + HOST_HCCR);
  1807. while (1) {
  1808. loop_count = DEFAULT_LOOP_COUNT;
  1809. while (--loop_count && !(inw(host->io_port + PCI_INTER_STS) & 0x08)) { 
  1810. barrier();
  1811. cpu_relax();
  1812. }
  1813. if (!loop_count) {
  1814. hostdata->adapter_state = AS_FIRMWARE_DEAD;
  1815. printk("qlogicfc%d : mbox_command loop timeout #2n", hostdata->host_id);
  1816. break;
  1817. }
  1818. isp2x00_intr_handler(host->irq, host, NULL);
  1819. if (hostdata->mbox_done == 1)
  1820. break;
  1821. }
  1822. loop_count = DEFAULT_LOOP_COUNT;
  1823. while (--loop_count && inw(host->io_port + MBOX0) == 0x04) {
  1824. barrier();
  1825. cpu_relax();
  1826. }
  1827. if (!loop_count)
  1828. printk("qlogicfc%d : mbox_command loop timeout #3n", hostdata->host_id);
  1829. param[7] = inw(host->io_port + MBOX7);
  1830. param[6] = inw(host->io_port + MBOX6);
  1831. param[5] = inw(host->io_port + MBOX5);
  1832. param[4] = inw(host->io_port + MBOX4);
  1833. param[3] = inw(host->io_port + MBOX3);
  1834. param[2] = inw(host->io_port + MBOX2);
  1835. param[1] = inw(host->io_port + MBOX1);
  1836. param[0] = inw(host->io_port + MBOX0);
  1837. outw(0x0, host->io_port + PCI_SEMAPHORE);
  1838. if (inw(host->io_port + HOST_HCCR) & 0x0080) {
  1839. hostdata->adapter_state = AS_FIRMWARE_DEAD;
  1840. printk("qlogicfc%d : mbox op is still pendingn", hostdata->host_id);
  1841. }
  1842. return 0;
  1843. }
  1844. #if DEBUG_ISP2x00_INTR
  1845. void isp2x00_print_status_entry(struct Status_Entry *status)
  1846. {
  1847. printk("qlogicfc : entry count = 0x%02x, type = 0x%02x, flags = 0x%02xn", 
  1848. status->hdr.entry_cnt, status->hdr.entry_type, status->hdr.flags);
  1849. printk("qlogicfc : scsi status = 0x%04x, completion status = 0x%04xn",
  1850.        le16_to_cpu(status->scsi_status), le16_to_cpu(status->completion_status));
  1851. printk("qlogicfc : state flags = 0x%04x, status flags = 0x%04xn", 
  1852.        le16_to_cpu(status->state_flags), le16_to_cpu(status->status_flags));
  1853. printk("qlogicfc : response info length = 0x%04x, request sense length = 0x%04xn",
  1854.        le16_to_cpu(status->res_info_len), le16_to_cpu(status->req_sense_len));
  1855. printk("qlogicfc : residual transfer length = 0x%08x, response = 0x%02xn", le32_to_cpu(status->residual), status->res_info[3]);
  1856. }
  1857. #endif                         /* DEBUG_ISP2x00_INTR */
  1858. #if DEBUG_ISP2x00
  1859. void isp2x00_print_scsi_cmd(Scsi_Cmnd * cmd)
  1860. {
  1861. int i;
  1862. printk("qlogicfc : target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02xn", 
  1863.        cmd->target, cmd->lun, cmd->cmd_len);
  1864. printk("qlogicfc : command = ");
  1865. for (i = 0; i < cmd->cmd_len; i++)
  1866. printk("0x%02x ", cmd->cmnd[i]);
  1867. printk("n");
  1868. }
  1869. #endif /* DEBUG_ISP2x00 */
  1870. MODULE_LICENSE("GPL");
  1871. static Scsi_Host_Template driver_template = QLOGICFC;
  1872. #include "scsi_module.c"