qlogicisp.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935
  1. /*
  2. * QLogic ISP1020 Intelligent SCSI Processor Driver (PCI)
  3. * Written by Erik H. Moe, ehm@cris.com
  4. * Copyright 1995, Erik H. Moe
  5. * Copyright 1996, 1997 Michael A. Griffith <grif@acm.org>
  6. * Copyright 2000, Jayson C. Vantuyl <vantuyl@csc.smsu.edu>
  7. * and Bryon W. Roche <bryon@csc.smsu.edu>
  8. *
  9. * 64-bit addressing added by Kanoj Sarcar <kanoj@sgi.com>
  10. * and Leo Dagum <dagum@sgi.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2, or (at your option) any
  15. * later version.
  16. *
  17. * This program is distributed in the hope that it will be useful, but
  18. * WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * General Public License for more details.
  21. */
  22. #include <linux/blkdev.h>
  23. #include <linux/config.h>
  24. #include <linux/kernel.h>
  25. #include <linux/string.h>
  26. #include <linux/ioport.h>
  27. #include <linux/sched.h>
  28. #include <linux/types.h>
  29. #include <linux/pci.h>
  30. #include <linux/delay.h>
  31. #include <linux/unistd.h>
  32. #include <linux/spinlock.h>
  33. #include <linux/interrupt.h>
  34. #include <asm/io.h>
  35. #include <asm/irq.h>
  36. #include <asm/byteorder.h>
  37. #include "scsi.h"
  38. #include <scsi/scsi_host.h>
  39. /*
  40. * With the qlogic interface, every queue slot can hold a SCSI
  41. * command with up to 4 scatter/gather entries. If we need more
  42. * than 4 entries, continuation entries can be used that hold
  43. * another 7 entries each. Unlike for other drivers, this means
  44. * that the maximum number of scatter/gather entries we can
  45. * support at any given time is a function of the number of queue
  46. * slots available. That is, host->can_queue and host->sg_tablesize
  47. * are dynamic and _not_ independent. This all works fine because
  48. * requests are queued serially and the scatter/gather limit is
  49. * determined for each queue request anew.
  50. */
  51. #define QLOGICISP_REQ_QUEUE_LEN 63 /* must be power of two - 1 */
  52. #define QLOGICISP_MAX_SG(ql) (4 + ((ql) > 0) ? 7*((ql) - 1) : 0)
  53. /* Configuration section *****************************************************/
  54. /* Set the following macro to 1 to reload the ISP1020's firmware. This is
  55. the latest firmware provided by QLogic. This may be an earlier/later
  56. revision than supplied by your board. */
  57. #define RELOAD_FIRMWARE 1
  58. /* Set the following macro to 1 to reload the ISP1020's defaults from nvram.
  59. If you are not sure of your settings, leave this alone, the driver will
  60. use a set of 'safe' defaults */
  61. #define USE_NVRAM_DEFAULTS 0
  62. /* Macros used for debugging */
  63. #define DEBUG_ISP1020 0
  64. #define DEBUG_ISP1020_INTR 0
  65. #define DEBUG_ISP1020_SETUP 0
  66. #define TRACE_ISP 0
  67. #define DEFAULT_LOOP_COUNT 1000000
  68. /* End Configuration section *************************************************/
  69. #include <linux/module.h>
  70. #if TRACE_ISP
  71. # define TRACE_BUF_LEN (32*1024)
  72. struct {
  73. u_long next;
  74. struct {
  75. u_long time;
  76. u_int index;
  77. u_int addr;
  78. u_char * name;
  79. } buf[TRACE_BUF_LEN];
  80. } trace;
  81. #define TRACE(w, i, a) \
  82. { \
  83. unsigned long flags; \
  84. \
  85. trace.buf[trace.next].name = (w); \
  86. trace.buf[trace.next].time = jiffies; \
  87. trace.buf[trace.next].index = (i); \
  88. trace.buf[trace.next].addr = (long) (a); \
  89. trace.next = (trace.next + 1) & (TRACE_BUF_LEN - 1); \
  90. }
  91. #else
  92. # define TRACE(w, i, a)
  93. #endif
  94. #if DEBUG_ISP1020
  95. #define ENTER(x) printk("isp1020 : entering %s()\n", x);
  96. #define LEAVE(x) printk("isp1020 : leaving %s()\n", x);
  97. #define DEBUG(x) x
  98. #else
  99. #define ENTER(x)
  100. #define LEAVE(x)
  101. #define DEBUG(x)
  102. #endif /* DEBUG_ISP1020 */
  103. #if DEBUG_ISP1020_INTR
  104. #define ENTER_INTR(x) printk("isp1020 : entering %s()\n", x);
  105. #define LEAVE_INTR(x) printk("isp1020 : leaving %s()\n", x);
  106. #define DEBUG_INTR(x) x
  107. #else
  108. #define ENTER_INTR(x)
  109. #define LEAVE_INTR(x)
  110. #define DEBUG_INTR(x)
  111. #endif /* DEBUG ISP1020_INTR */
  112. #define ISP1020_REV_ID 1
  113. #define MAX_TARGETS 16
  114. #define MAX_LUNS 8
  115. /* host configuration and control registers */
  116. #define HOST_HCCR 0xc0 /* host command and control */
  117. /* pci bus interface registers */
  118. #define PCI_ID_LOW 0x00 /* vendor id */
  119. #define PCI_ID_HIGH 0x02 /* device id */
  120. #define ISP_CFG0 0x04 /* configuration register #0 */
  121. #define ISP_CFG0_HWMSK 0x000f /* Hardware revision mask */
  122. #define ISP_CFG0_1020 0x0001 /* ISP1020 */
  123. #define ISP_CFG0_1020A 0x0002 /* ISP1020A */
  124. #define ISP_CFG0_1040 0x0003 /* ISP1040 */
  125. #define ISP_CFG0_1040A 0x0004 /* ISP1040A */
  126. #define ISP_CFG0_1040B 0x0005 /* ISP1040B */
  127. #define ISP_CFG0_1040C 0x0006 /* ISP1040C */
  128. #define ISP_CFG1 0x06 /* configuration register #1 */
  129. #define ISP_CFG1_F128 0x0040 /* 128-byte FIFO threshold */
  130. #define ISP_CFG1_F64 0x0030 /* 128-byte FIFO threshold */
  131. #define ISP_CFG1_F32 0x0020 /* 128-byte FIFO threshold */
  132. #define ISP_CFG1_F16 0x0010 /* 128-byte FIFO threshold */
  133. #define ISP_CFG1_BENAB 0x0004 /* Global Bus burst enable */
  134. #define ISP_CFG1_SXP 0x0001 /* SXP register select */
  135. #define PCI_INTF_CTL 0x08 /* pci interface control */
  136. #define PCI_INTF_STS 0x0a /* pci interface status */
  137. #define PCI_SEMAPHORE 0x0c /* pci semaphore */
  138. #define PCI_NVRAM 0x0e /* pci nvram interface */
  139. #define CDMA_CONF 0x20 /* Command DMA Config */
  140. #define DDMA_CONF 0x40 /* Data DMA Config */
  141. #define DMA_CONF_SENAB 0x0008 /* SXP to DMA Data enable */
  142. #define DMA_CONF_RIRQ 0x0004 /* RISC interrupt enable */
  143. #define DMA_CONF_BENAB 0x0002 /* Bus burst enable */
  144. #define DMA_CONF_DIR 0x0001 /* DMA direction (0=fifo->host 1=host->fifo) */
  145. /* mailbox registers */
  146. #define MBOX0 0x70 /* mailbox 0 */
  147. #define MBOX1 0x72 /* mailbox 1 */
  148. #define MBOX2 0x74 /* mailbox 2 */
  149. #define MBOX3 0x76 /* mailbox 3 */
  150. #define MBOX4 0x78 /* mailbox 4 */
  151. #define MBOX5 0x7a /* mailbox 5 */
  152. #define MBOX6 0x7c /* mailbox 6 */
  153. #define MBOX7 0x7e /* mailbox 7 */
  154. /* mailbox command complete status codes */
  155. #define MBOX_COMMAND_COMPLETE 0x4000
  156. #define INVALID_COMMAND 0x4001
  157. #define HOST_INTERFACE_ERROR 0x4002
  158. #define TEST_FAILED 0x4003
  159. #define COMMAND_ERROR 0x4005
  160. #define COMMAND_PARAM_ERROR 0x4006
  161. /* async event status codes */
  162. #define ASYNC_SCSI_BUS_RESET 0x8001
  163. #define SYSTEM_ERROR 0x8002
  164. #define REQUEST_TRANSFER_ERROR 0x8003
  165. #define RESPONSE_TRANSFER_ERROR 0x8004
  166. #define REQUEST_QUEUE_WAKEUP 0x8005
  167. #define EXECUTION_TIMEOUT_RESET 0x8006
  168. #ifdef CONFIG_QL_ISP_A64
  169. #define IOCB_SEGS 2
  170. #define CONTINUATION_SEGS 5
  171. #define MAX_CONTINUATION_ENTRIES 254
  172. #else
  173. #define IOCB_SEGS 4
  174. #define CONTINUATION_SEGS 7
  175. #endif /* CONFIG_QL_ISP_A64 */
  176. struct Entry_header {
  177. u_char entry_type;
  178. u_char entry_cnt;
  179. u_char sys_def_1;
  180. u_char flags;
  181. };
  182. /* entry header type commands */
  183. #ifdef CONFIG_QL_ISP_A64
  184. #define ENTRY_COMMAND 9
  185. #define ENTRY_CONTINUATION 0xa
  186. #else
  187. #define ENTRY_COMMAND 1
  188. #define ENTRY_CONTINUATION 2
  189. #endif /* CONFIG_QL_ISP_A64 */
  190. #define ENTRY_STATUS 3
  191. #define ENTRY_MARKER 4
  192. #define ENTRY_EXTENDED_COMMAND 5
  193. /* entry header flag definitions */
  194. #define EFLAG_CONTINUATION 1
  195. #define EFLAG_BUSY 2
  196. #define EFLAG_BAD_HEADER 4
  197. #define EFLAG_BAD_PAYLOAD 8
  198. struct dataseg {
  199. u_int d_base;
  200. #ifdef CONFIG_QL_ISP_A64
  201. u_int d_base_hi;
  202. #endif
  203. u_int d_count;
  204. };
  205. struct Command_Entry {
  206. struct Entry_header hdr;
  207. u_int handle;
  208. u_char target_lun;
  209. u_char target_id;
  210. u_short cdb_length;
  211. u_short control_flags;
  212. u_short rsvd;
  213. u_short time_out;
  214. u_short segment_cnt;
  215. u_char cdb[12];
  216. #ifdef CONFIG_QL_ISP_A64
  217. u_int rsvd1;
  218. u_int rsvd2;
  219. #endif
  220. struct dataseg dataseg[IOCB_SEGS];
  221. };
  222. /* command entry control flag definitions */
  223. #define CFLAG_NODISC 0x01
  224. #define CFLAG_HEAD_TAG 0x02
  225. #define CFLAG_ORDERED_TAG 0x04
  226. #define CFLAG_SIMPLE_TAG 0x08
  227. #define CFLAG_TAR_RTN 0x10
  228. #define CFLAG_READ 0x20
  229. #define CFLAG_WRITE 0x40
  230. struct Ext_Command_Entry {
  231. struct Entry_header hdr;
  232. u_int handle;
  233. u_char target_lun;
  234. u_char target_id;
  235. u_short cdb_length;
  236. u_short control_flags;
  237. u_short rsvd;
  238. u_short time_out;
  239. u_short segment_cnt;
  240. u_char cdb[44];
  241. };
  242. struct Continuation_Entry {
  243. struct Entry_header hdr;
  244. #ifndef CONFIG_QL_ISP_A64
  245. u_int reserved;
  246. #endif
  247. struct dataseg dataseg[CONTINUATION_SEGS];
  248. };
  249. struct Marker_Entry {
  250. struct Entry_header hdr;
  251. u_int reserved;
  252. u_char target_lun;
  253. u_char target_id;
  254. u_char modifier;
  255. u_char rsvd;
  256. u_char rsvds[52];
  257. };
  258. /* marker entry modifier definitions */
  259. #define SYNC_DEVICE 0
  260. #define SYNC_TARGET 1
  261. #define SYNC_ALL 2
  262. struct Status_Entry {
  263. struct Entry_header hdr;
  264. u_int handle;
  265. u_short scsi_status;
  266. u_short completion_status;
  267. u_short state_flags;
  268. u_short status_flags;
  269. u_short time;
  270. u_short req_sense_len;
  271. u_int residual;
  272. u_char rsvd[8];
  273. u_char req_sense_data[32];
  274. };
  275. /* status entry completion status definitions */
  276. #define CS_COMPLETE 0x0000
  277. #define CS_INCOMPLETE 0x0001
  278. #define CS_DMA_ERROR 0x0002
  279. #define CS_TRANSPORT_ERROR 0x0003
  280. #define CS_RESET_OCCURRED 0x0004
  281. #define CS_ABORTED 0x0005
  282. #define CS_TIMEOUT 0x0006
  283. #define CS_DATA_OVERRUN 0x0007
  284. #define CS_COMMAND_OVERRUN 0x0008
  285. #define CS_STATUS_OVERRUN 0x0009
  286. #define CS_BAD_MESSAGE 0x000a
  287. #define CS_NO_MESSAGE_OUT 0x000b
  288. #define CS_EXT_ID_FAILED 0x000c
  289. #define CS_IDE_MSG_FAILED 0x000d
  290. #define CS_ABORT_MSG_FAILED 0x000e
  291. #define CS_REJECT_MSG_FAILED 0x000f
  292. #define CS_NOP_MSG_FAILED 0x0010
  293. #define CS_PARITY_ERROR_MSG_FAILED 0x0011
  294. #define CS_DEVICE_RESET_MSG_FAILED 0x0012
  295. #define CS_ID_MSG_FAILED 0x0013
  296. #define CS_UNEXP_BUS_FREE 0x0014
  297. #define CS_DATA_UNDERRUN 0x0015
  298. /* status entry state flag definitions */
  299. #define SF_GOT_BUS 0x0100
  300. #define SF_GOT_TARGET 0x0200
  301. #define SF_SENT_CDB 0x0400
  302. #define SF_TRANSFERRED_DATA 0x0800
  303. #define SF_GOT_STATUS 0x1000
  304. #define SF_GOT_SENSE 0x2000
  305. /* status entry status flag definitions */
  306. #define STF_DISCONNECT 0x0001
  307. #define STF_SYNCHRONOUS 0x0002
  308. #define STF_PARITY_ERROR 0x0004
  309. #define STF_BUS_RESET 0x0008
  310. #define STF_DEVICE_RESET 0x0010
  311. #define STF_ABORTED 0x0020
  312. #define STF_TIMEOUT 0x0040
  313. #define STF_NEGOTIATION 0x0080
  314. /* interface control commands */
  315. #define ISP_RESET 0x0001
  316. #define ISP_EN_INT 0x0002
  317. #define ISP_EN_RISC 0x0004
  318. /* host control commands */
  319. #define HCCR_NOP 0x0000
  320. #define HCCR_RESET 0x1000
  321. #define HCCR_PAUSE 0x2000
  322. #define HCCR_RELEASE 0x3000
  323. #define HCCR_SINGLE_STEP 0x4000
  324. #define HCCR_SET_HOST_INTR 0x5000
  325. #define HCCR_CLEAR_HOST_INTR 0x6000
  326. #define HCCR_CLEAR_RISC_INTR 0x7000
  327. #define HCCR_BP_ENABLE 0x8000
  328. #define HCCR_BIOS_DISABLE 0x9000
  329. #define HCCR_TEST_MODE 0xf000
  330. #define RISC_BUSY 0x0004
  331. /* mailbox commands */
  332. #define MBOX_NO_OP 0x0000
  333. #define MBOX_LOAD_RAM 0x0001
  334. #define MBOX_EXEC_FIRMWARE 0x0002
  335. #define MBOX_DUMP_RAM 0x0003
  336. #define MBOX_WRITE_RAM_WORD 0x0004
  337. #define MBOX_READ_RAM_WORD 0x0005
  338. #define MBOX_MAILBOX_REG_TEST 0x0006
  339. #define MBOX_VERIFY_CHECKSUM 0x0007
  340. #define MBOX_ABOUT_FIRMWARE 0x0008
  341. #define MBOX_CHECK_FIRMWARE 0x000e
  342. #define MBOX_INIT_REQ_QUEUE 0x0010
  343. #define MBOX_INIT_RES_QUEUE 0x0011
  344. #define MBOX_EXECUTE_IOCB 0x0012
  345. #define MBOX_WAKE_UP 0x0013
  346. #define MBOX_STOP_FIRMWARE 0x0014
  347. #define MBOX_ABORT 0x0015
  348. #define MBOX_ABORT_DEVICE 0x0016
  349. #define MBOX_ABORT_TARGET 0x0017
  350. #define MBOX_BUS_RESET 0x0018
  351. #define MBOX_STOP_QUEUE 0x0019
  352. #define MBOX_START_QUEUE 0x001a
  353. #define MBOX_SINGLE_STEP_QUEUE 0x001b
  354. #define MBOX_ABORT_QUEUE 0x001c
  355. #define MBOX_GET_DEV_QUEUE_STATUS 0x001d
  356. #define MBOX_GET_FIRMWARE_STATUS 0x001f
  357. #define MBOX_GET_INIT_SCSI_ID 0x0020
  358. #define MBOX_GET_SELECT_TIMEOUT 0x0021
  359. #define MBOX_GET_RETRY_COUNT 0x0022
  360. #define MBOX_GET_TAG_AGE_LIMIT 0x0023
  361. #define MBOX_GET_CLOCK_RATE 0x0024
  362. #define MBOX_GET_ACT_NEG_STATE 0x0025
  363. #define MBOX_GET_ASYNC_DATA_SETUP_TIME 0x0026
  364. #define MBOX_GET_PCI_PARAMS 0x0027
  365. #define MBOX_GET_TARGET_PARAMS 0x0028
  366. #define MBOX_GET_DEV_QUEUE_PARAMS 0x0029
  367. #define MBOX_SET_INIT_SCSI_ID 0x0030
  368. #define MBOX_SET_SELECT_TIMEOUT 0x0031
  369. #define MBOX_SET_RETRY_COUNT 0x0032
  370. #define MBOX_SET_TAG_AGE_LIMIT 0x0033
  371. #define MBOX_SET_CLOCK_RATE 0x0034
  372. #define MBOX_SET_ACTIVE_NEG_STATE 0x0035
  373. #define MBOX_SET_ASYNC_DATA_SETUP_TIME 0x0036
  374. #define MBOX_SET_PCI_CONTROL_PARAMS 0x0037
  375. #define MBOX_SET_TARGET_PARAMS 0x0038
  376. #define MBOX_SET_DEV_QUEUE_PARAMS 0x0039
  377. #define MBOX_RETURN_BIOS_BLOCK_ADDR 0x0040
  378. #define MBOX_WRITE_FOUR_RAM_WORDS 0x0041
  379. #define MBOX_EXEC_BIOS_IOCB 0x0042
  380. #ifdef CONFIG_QL_ISP_A64
  381. #define MBOX_CMD_INIT_REQUEST_QUEUE_64 0x0052
  382. #define MBOX_CMD_INIT_RESPONSE_QUEUE_64 0x0053
  383. #endif /* CONFIG_QL_ISP_A64 */
  384. #include "qlogicisp_asm.c"
  385. #define PACKB(a, b) (((a)<<4)|(b))
  386. static const u_char mbox_param[] = {
  387. PACKB(1, 1), /* MBOX_NO_OP */
  388. PACKB(5, 5), /* MBOX_LOAD_RAM */
  389. PACKB(2, 0), /* MBOX_EXEC_FIRMWARE */
  390. PACKB(5, 5), /* MBOX_DUMP_RAM */
  391. PACKB(3, 3), /* MBOX_WRITE_RAM_WORD */
  392. PACKB(2, 3), /* MBOX_READ_RAM_WORD */
  393. PACKB(6, 6), /* MBOX_MAILBOX_REG_TEST */
  394. PACKB(2, 3), /* MBOX_VERIFY_CHECKSUM */
  395. PACKB(1, 3), /* MBOX_ABOUT_FIRMWARE */
  396. PACKB(0, 0), /* 0x0009 */
  397. PACKB(0, 0), /* 0x000a */
  398. PACKB(0, 0), /* 0x000b */
  399. PACKB(0, 0), /* 0x000c */
  400. PACKB(0, 0), /* 0x000d */
  401. PACKB(1, 2), /* MBOX_CHECK_FIRMWARE */
  402. PACKB(0, 0), /* 0x000f */
  403. PACKB(5, 5), /* MBOX_INIT_REQ_QUEUE */
  404. PACKB(6, 6), /* MBOX_INIT_RES_QUEUE */
  405. PACKB(4, 4), /* MBOX_EXECUTE_IOCB */
  406. PACKB(2, 2), /* MBOX_WAKE_UP */
  407. PACKB(1, 6), /* MBOX_STOP_FIRMWARE */
  408. PACKB(4, 4), /* MBOX_ABORT */
  409. PACKB(2, 2), /* MBOX_ABORT_DEVICE */
  410. PACKB(3, 3), /* MBOX_ABORT_TARGET */
  411. PACKB(2, 2), /* MBOX_BUS_RESET */
  412. PACKB(2, 3), /* MBOX_STOP_QUEUE */
  413. PACKB(2, 3), /* MBOX_START_QUEUE */
  414. PACKB(2, 3), /* MBOX_SINGLE_STEP_QUEUE */
  415. PACKB(2, 3), /* MBOX_ABORT_QUEUE */
  416. PACKB(2, 4), /* MBOX_GET_DEV_QUEUE_STATUS */
  417. PACKB(0, 0), /* 0x001e */
  418. PACKB(1, 3), /* MBOX_GET_FIRMWARE_STATUS */
  419. PACKB(1, 2), /* MBOX_GET_INIT_SCSI_ID */
  420. PACKB(1, 2), /* MBOX_GET_SELECT_TIMEOUT */
  421. PACKB(1, 3), /* MBOX_GET_RETRY_COUNT */
  422. PACKB(1, 2), /* MBOX_GET_TAG_AGE_LIMIT */
  423. PACKB(1, 2), /* MBOX_GET_CLOCK_RATE */
  424. PACKB(1, 2), /* MBOX_GET_ACT_NEG_STATE */
  425. PACKB(1, 2), /* MBOX_GET_ASYNC_DATA_SETUP_TIME */
  426. PACKB(1, 3), /* MBOX_GET_PCI_PARAMS */
  427. PACKB(2, 4), /* MBOX_GET_TARGET_PARAMS */
  428. PACKB(2, 4), /* MBOX_GET_DEV_QUEUE_PARAMS */
  429. PACKB(0, 0), /* 0x002a */
  430. PACKB(0, 0), /* 0x002b */
  431. PACKB(0, 0), /* 0x002c */
  432. PACKB(0, 0), /* 0x002d */
  433. PACKB(0, 0), /* 0x002e */
  434. PACKB(0, 0), /* 0x002f */
  435. PACKB(2, 2), /* MBOX_SET_INIT_SCSI_ID */
  436. PACKB(2, 2), /* MBOX_SET_SELECT_TIMEOUT */
  437. PACKB(3, 3), /* MBOX_SET_RETRY_COUNT */
  438. PACKB(2, 2), /* MBOX_SET_TAG_AGE_LIMIT */
  439. PACKB(2, 2), /* MBOX_SET_CLOCK_RATE */
  440. PACKB(2, 2), /* MBOX_SET_ACTIVE_NEG_STATE */
  441. PACKB(2, 2), /* MBOX_SET_ASYNC_DATA_SETUP_TIME */
  442. PACKB(3, 3), /* MBOX_SET_PCI_CONTROL_PARAMS */
  443. PACKB(4, 4), /* MBOX_SET_TARGET_PARAMS */
  444. PACKB(4, 4), /* MBOX_SET_DEV_QUEUE_PARAMS */
  445. PACKB(0, 0), /* 0x003a */
  446. PACKB(0, 0), /* 0x003b */
  447. PACKB(0, 0), /* 0x003c */
  448. PACKB(0, 0), /* 0x003d */
  449. PACKB(0, 0), /* 0x003e */
  450. PACKB(0, 0), /* 0x003f */
  451. PACKB(1, 2), /* MBOX_RETURN_BIOS_BLOCK_ADDR */
  452. PACKB(6, 1), /* MBOX_WRITE_FOUR_RAM_WORDS */
  453. PACKB(2, 3) /* MBOX_EXEC_BIOS_IOCB */
  454. #ifdef CONFIG_QL_ISP_A64
  455. ,PACKB(0, 0), /* 0x0043 */
  456. PACKB(0, 0), /* 0x0044 */
  457. PACKB(0, 0), /* 0x0045 */
  458. PACKB(0, 0), /* 0x0046 */
  459. PACKB(0, 0), /* 0x0047 */
  460. PACKB(0, 0), /* 0x0048 */
  461. PACKB(0, 0), /* 0x0049 */
  462. PACKB(0, 0), /* 0x004a */
  463. PACKB(0, 0), /* 0x004b */
  464. PACKB(0, 0), /* 0x004c */
  465. PACKB(0, 0), /* 0x004d */
  466. PACKB(0, 0), /* 0x004e */
  467. PACKB(0, 0), /* 0x004f */
  468. PACKB(0, 0), /* 0x0050 */
  469. PACKB(0, 0), /* 0x0051 */
  470. PACKB(8, 8), /* MBOX_CMD_INIT_REQUEST_QUEUE_64 (0x0052) */
  471. PACKB(8, 8) /* MBOX_CMD_INIT_RESPONSE_QUEUE_64 (0x0053) */
  472. #endif /* CONFIG_QL_ISP_A64 */
  473. };
  474. #define MAX_MBOX_COMMAND (sizeof(mbox_param)/sizeof(u_short))
  475. struct host_param {
  476. u_short fifo_threshold;
  477. u_short host_adapter_enable;
  478. u_short initiator_scsi_id;
  479. u_short bus_reset_delay;
  480. u_short retry_count;
  481. u_short retry_delay;
  482. u_short async_data_setup_time;
  483. u_short req_ack_active_negation;
  484. u_short data_line_active_negation;
  485. u_short data_dma_burst_enable;
  486. u_short command_dma_burst_enable;
  487. u_short tag_aging;
  488. u_short selection_timeout;
  489. u_short max_queue_depth;
  490. };
  491. /*
  492. * Device Flags:
  493. *
  494. * Bit Name
  495. * ---------
  496. * 7 Disconnect Privilege
  497. * 6 Parity Checking
  498. * 5 Wide Data Transfers
  499. * 4 Synchronous Data Transfers
  500. * 3 Tagged Queuing
  501. * 2 Automatic Request Sense
  502. * 1 Stop Queue on Check Condition
  503. * 0 Renegotiate on Error
  504. */
  505. struct dev_param {
  506. u_short device_flags;
  507. u_short execution_throttle;
  508. u_short synchronous_period;
  509. u_short synchronous_offset;
  510. u_short device_enable;
  511. u_short reserved; /* pad */
  512. };
  513. /*
  514. * The result queue can be quite a bit smaller since continuation entries
  515. * do not show up there:
  516. */
  517. #define RES_QUEUE_LEN ((QLOGICISP_REQ_QUEUE_LEN + 1) / 8 - 1)
  518. #define QUEUE_ENTRY_LEN 64
  519. #define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN)
  520. struct isp_queue_entry {
  521. char __opaque[QUEUE_ENTRY_LEN];
  522. };
  523. struct isp1020_hostdata {
  524. void __iomem *memaddr;
  525. u_char revision;
  526. struct host_param host_param;
  527. struct dev_param dev_param[MAX_TARGETS];
  528. struct pci_dev *pci_dev;
  529. struct isp_queue_entry *res_cpu; /* CPU-side address of response queue. */
  530. struct isp_queue_entry *req_cpu; /* CPU-size address of request queue. */
  531. /* result and request queues (shared with isp1020): */
  532. u_int req_in_ptr; /* index of next request slot */
  533. u_int res_out_ptr; /* index of next result slot */
  534. /* this is here so the queues are nicely aligned */
  535. long send_marker; /* do we need to send a marker? */
  536. /* The cmd->handle has a fixed size, and is only 32-bits. We
  537. * need to take care to handle 64-bit systems correctly thus what
  538. * we actually place in cmd->handle is an index to the following
  539. * table. Kudos to Matt Jacob for the technique. -DaveM
  540. */
  541. Scsi_Cmnd *cmd_slots[QLOGICISP_REQ_QUEUE_LEN + 1];
  542. dma_addr_t res_dma; /* PCI side view of response queue */
  543. dma_addr_t req_dma; /* PCI side view of request queue */
  544. };
  545. /* queue length's _must_ be power of two: */
  546. #define QUEUE_DEPTH(in, out, ql) ((in - out) & (ql))
  547. #define REQ_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, \
  548. QLOGICISP_REQ_QUEUE_LEN)
  549. #define RES_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, RES_QUEUE_LEN)
  550. static void isp1020_enable_irqs(struct Scsi_Host *);
  551. static void isp1020_disable_irqs(struct Scsi_Host *);
  552. static int isp1020_init(struct Scsi_Host *);
  553. static int isp1020_reset_hardware(struct Scsi_Host *);
  554. static int isp1020_set_defaults(struct Scsi_Host *);
  555. static int isp1020_load_parameters(struct Scsi_Host *);
  556. static int isp1020_mbox_command(struct Scsi_Host *, u_short []);
  557. static int isp1020_return_status(struct Status_Entry *);
  558. static void isp1020_intr_handler(int, void *, struct pt_regs *);
  559. static irqreturn_t do_isp1020_intr_handler(int, void *, struct pt_regs *);
  560. #if USE_NVRAM_DEFAULTS
  561. static int isp1020_get_defaults(struct Scsi_Host *);
  562. static int isp1020_verify_nvram(struct Scsi_Host *);
  563. static u_short isp1020_read_nvram_word(struct Scsi_Host *, u_short);
  564. #endif
  565. #if DEBUG_ISP1020
  566. static void isp1020_print_scsi_cmd(Scsi_Cmnd *);
  567. #endif
  568. #if DEBUG_ISP1020_INTR
  569. static void isp1020_print_status_entry(struct Status_Entry *);
  570. #endif
  571. /* memaddr should be used to determine if memmapped port i/o is being used
  572. * non-null memaddr == mmap'd
  573. * JV 7-Jan-2000
  574. */
  575. static inline u_short isp_inw(struct Scsi_Host *host, long offset)
  576. {
  577. struct isp1020_hostdata *h = (struct isp1020_hostdata *)host->hostdata;
  578. if (h->memaddr)
  579. return readw(h->memaddr + offset);
  580. else
  581. return inw(host->io_port + offset);
  582. }
  583. static inline void isp_outw(u_short val, struct Scsi_Host *host, long offset)
  584. {
  585. struct isp1020_hostdata *h = (struct isp1020_hostdata *)host->hostdata;
  586. if (h->memaddr)
  587. writew(val, h->memaddr + offset);
  588. else
  589. outw(val, host->io_port + offset);
  590. }
  591. static inline void isp1020_enable_irqs(struct Scsi_Host *host)
  592. {
  593. isp_outw(ISP_EN_INT|ISP_EN_RISC, host, PCI_INTF_CTL);
  594. }
  595. static inline void isp1020_disable_irqs(struct Scsi_Host *host)
  596. {
  597. isp_outw(0x0, host, PCI_INTF_CTL);
  598. }
  599. static int isp1020_detect(Scsi_Host_Template *tmpt)
  600. {
  601. int hosts = 0;
  602. struct Scsi_Host *host;
  603. struct isp1020_hostdata *hostdata;
  604. struct pci_dev *pdev = NULL;
  605. ENTER("isp1020_detect");
  606. tmpt->proc_name = "isp1020";
  607. while ((pdev = pci_find_device(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1020, pdev)))
  608. {
  609. if (pci_enable_device(pdev))
  610. continue;
  611. host = scsi_register(tmpt, sizeof(struct isp1020_hostdata));
  612. if (!host)
  613. continue;
  614. hostdata = (struct isp1020_hostdata *) host->hostdata;
  615. memset(hostdata, 0, sizeof(struct isp1020_hostdata));
  616. hostdata->pci_dev = pdev;
  617. scsi_set_device(host, &pdev->dev);
  618. if (isp1020_init(host))
  619. goto fail_and_unregister;
  620. if (isp1020_reset_hardware(host)
  621. #if USE_NVRAM_DEFAULTS
  622. || isp1020_get_defaults(host)
  623. #else
  624. || isp1020_set_defaults(host)
  625. #endif /* USE_NVRAM_DEFAULTS */
  626. || isp1020_load_parameters(host)) {
  627. goto fail_uninit;
  628. }
  629. host->this_id = hostdata->host_param.initiator_scsi_id;
  630. host->max_sectors = 64;
  631. if (request_irq(host->irq, do_isp1020_intr_handler, SA_INTERRUPT | SA_SHIRQ,
  632. "qlogicisp", host))
  633. {
  634. printk("qlogicisp : interrupt %d already in use\n",
  635. host->irq);
  636. goto fail_uninit;
  637. }
  638. isp_outw(0x0, host, PCI_SEMAPHORE);
  639. isp_outw(HCCR_CLEAR_RISC_INTR, host, HOST_HCCR);
  640. isp1020_enable_irqs(host);
  641. hosts++;
  642. continue;
  643. fail_uninit:
  644. iounmap(hostdata->memaddr);
  645. release_region(host->io_port, 0xff);
  646. fail_and_unregister:
  647. if (hostdata->res_cpu)
  648. pci_free_consistent(hostdata->pci_dev,
  649. QSIZE(RES_QUEUE_LEN),
  650. hostdata->res_cpu,
  651. hostdata->res_dma);
  652. if (hostdata->req_cpu)
  653. pci_free_consistent(hostdata->pci_dev,
  654. QSIZE(QLOGICISP_REQ_QUEUE_LEN),
  655. hostdata->req_cpu,
  656. hostdata->req_dma);
  657. scsi_unregister(host);
  658. }
  659. LEAVE("isp1020_detect");
  660. return hosts;
  661. }
  662. static int isp1020_release(struct Scsi_Host *host)
  663. {
  664. struct isp1020_hostdata *hostdata;
  665. ENTER("isp1020_release");
  666. hostdata = (struct isp1020_hostdata *) host->hostdata;
  667. isp_outw(0x0, host, PCI_INTF_CTL);
  668. free_irq(host->irq, host);
  669. iounmap(hostdata->memaddr);
  670. release_region(host->io_port, 0xff);
  671. LEAVE("isp1020_release");
  672. return 0;
  673. }
  674. static const char *isp1020_info(struct Scsi_Host *host)
  675. {
  676. static char buf[80];
  677. struct isp1020_hostdata *hostdata;
  678. ENTER("isp1020_info");
  679. hostdata = (struct isp1020_hostdata *) host->hostdata;
  680. sprintf(buf,
  681. "QLogic ISP1020 SCSI on PCI bus %02x device %02x irq %d %s base 0x%lx",
  682. hostdata->pci_dev->bus->number, hostdata->pci_dev->devfn, host->irq,
  683. (hostdata->memaddr ? "MEM" : "I/O"),
  684. (hostdata->memaddr ? (unsigned long)hostdata->memaddr : host->io_port));
  685. LEAVE("isp1020_info");
  686. return buf;
  687. }
  688. /*
  689. * The middle SCSI layer ensures that queuecommand never gets invoked
  690. * concurrently with itself or the interrupt handler (though the
  691. * interrupt handler may call this routine as part of
  692. * request-completion handling).
  693. */
  694. static int isp1020_queuecommand(Scsi_Cmnd *Cmnd, void (*done)(Scsi_Cmnd *))
  695. {
  696. int i, n, num_free;
  697. u_int in_ptr, out_ptr;
  698. struct dataseg * ds;
  699. struct scatterlist *sg;
  700. struct Command_Entry *cmd;
  701. struct Continuation_Entry *cont;
  702. struct Scsi_Host *host;
  703. struct isp1020_hostdata *hostdata;
  704. dma_addr_t dma_addr;
  705. ENTER("isp1020_queuecommand");
  706. host = Cmnd->device->host;
  707. hostdata = (struct isp1020_hostdata *) host->hostdata;
  708. Cmnd->scsi_done = done;
  709. DEBUG(isp1020_print_scsi_cmd(Cmnd));
  710. out_ptr = isp_inw(host, + MBOX4);
  711. in_ptr = hostdata->req_in_ptr;
  712. DEBUG(printk("qlogicisp : request queue depth %d\n",
  713. REQ_QUEUE_DEPTH(in_ptr, out_ptr)));
  714. cmd = (struct Command_Entry *) &hostdata->req_cpu[in_ptr];
  715. in_ptr = (in_ptr + 1) & QLOGICISP_REQ_QUEUE_LEN;
  716. if (in_ptr == out_ptr) {
  717. printk("qlogicisp : request queue overflow\n");
  718. return 1;
  719. }
  720. if (hostdata->send_marker) {
  721. struct Marker_Entry *marker;
  722. TRACE("queue marker", in_ptr, 0);
  723. DEBUG(printk("qlogicisp : adding marker entry\n"));
  724. marker = (struct Marker_Entry *) cmd;
  725. memset(marker, 0, sizeof(struct Marker_Entry));
  726. marker->hdr.entry_type = ENTRY_MARKER;
  727. marker->hdr.entry_cnt = 1;
  728. marker->modifier = SYNC_ALL;
  729. hostdata->send_marker = 0;
  730. if (((in_ptr + 1) & QLOGICISP_REQ_QUEUE_LEN) == out_ptr) {
  731. isp_outw(in_ptr, host, MBOX4);
  732. hostdata->req_in_ptr = in_ptr;
  733. printk("qlogicisp : request queue overflow\n");
  734. return 1;
  735. }
  736. cmd = (struct Command_Entry *) &hostdata->req_cpu[in_ptr];
  737. in_ptr = (in_ptr + 1) & QLOGICISP_REQ_QUEUE_LEN;
  738. }
  739. TRACE("queue command", in_ptr, Cmnd);
  740. memset(cmd, 0, sizeof(struct Command_Entry));
  741. cmd->hdr.entry_type = ENTRY_COMMAND;
  742. cmd->hdr.entry_cnt = 1;
  743. cmd->target_lun = Cmnd->device->lun;
  744. cmd->target_id = Cmnd->device->id;
  745. cmd->cdb_length = cpu_to_le16(Cmnd->cmd_len);
  746. cmd->control_flags = cpu_to_le16(CFLAG_READ | CFLAG_WRITE);
  747. cmd->time_out = cpu_to_le16(30);
  748. memcpy(cmd->cdb, Cmnd->cmnd, Cmnd->cmd_len);
  749. if (Cmnd->use_sg) {
  750. int sg_count;
  751. sg = (struct scatterlist *) Cmnd->request_buffer;
  752. ds = cmd->dataseg;
  753. sg_count = pci_map_sg(hostdata->pci_dev, sg, Cmnd->use_sg,
  754. Cmnd->sc_data_direction);
  755. cmd->segment_cnt = cpu_to_le16(sg_count);
  756. /* fill in first four sg entries: */
  757. n = sg_count;
  758. if (n > IOCB_SEGS)
  759. n = IOCB_SEGS;
  760. for (i = 0; i < n; i++) {
  761. dma_addr = sg_dma_address(sg);
  762. ds[i].d_base = cpu_to_le32((u32) dma_addr);
  763. #ifdef CONFIG_QL_ISP_A64
  764. ds[i].d_base_hi = cpu_to_le32((u32) (dma_addr>>32));
  765. #endif /* CONFIG_QL_ISP_A64 */
  766. ds[i].d_count = cpu_to_le32(sg_dma_len(sg));
  767. ++sg;
  768. }
  769. sg_count -= IOCB_SEGS;
  770. while (sg_count > 0) {
  771. ++cmd->hdr.entry_cnt;
  772. cont = (struct Continuation_Entry *)
  773. &hostdata->req_cpu[in_ptr];
  774. in_ptr = (in_ptr + 1) & QLOGICISP_REQ_QUEUE_LEN;
  775. if (in_ptr == out_ptr) {
  776. printk("isp1020: unexpected request queue "
  777. "overflow\n");
  778. return 1;
  779. }
  780. TRACE("queue continuation", in_ptr, 0);
  781. cont->hdr.entry_type = ENTRY_CONTINUATION;
  782. cont->hdr.entry_cnt = 0;
  783. cont->hdr.sys_def_1 = 0;
  784. cont->hdr.flags = 0;
  785. #ifndef CONFIG_QL_ISP_A64
  786. cont->reserved = 0;
  787. #endif
  788. ds = cont->dataseg;
  789. n = sg_count;
  790. if (n > CONTINUATION_SEGS)
  791. n = CONTINUATION_SEGS;
  792. for (i = 0; i < n; ++i) {
  793. dma_addr = sg_dma_address(sg);
  794. ds[i].d_base = cpu_to_le32((u32) dma_addr);
  795. #ifdef CONFIG_QL_ISP_A64
  796. ds[i].d_base_hi = cpu_to_le32((u32)(dma_addr>>32));
  797. #endif /* CONFIG_QL_ISP_A64 */
  798. ds[i].d_count = cpu_to_le32(sg_dma_len(sg));
  799. ++sg;
  800. }
  801. sg_count -= n;
  802. }
  803. } else if (Cmnd->request_bufflen) {
  804. /*Cmnd->SCp.ptr = (char *)(unsigned long)*/
  805. dma_addr = pci_map_single(hostdata->pci_dev,
  806. Cmnd->request_buffer,
  807. Cmnd->request_bufflen,
  808. Cmnd->sc_data_direction);
  809. Cmnd->SCp.ptr = (char *)(unsigned long) dma_addr;
  810. cmd->dataseg[0].d_base =
  811. cpu_to_le32((u32) dma_addr);
  812. #ifdef CONFIG_QL_ISP_A64
  813. cmd->dataseg[0].d_base_hi =
  814. cpu_to_le32((u32) (dma_addr>>32));
  815. #endif /* CONFIG_QL_ISP_A64 */
  816. cmd->dataseg[0].d_count =
  817. cpu_to_le32((u32)Cmnd->request_bufflen);
  818. cmd->segment_cnt = cpu_to_le16(1);
  819. } else {
  820. cmd->dataseg[0].d_base = 0;
  821. #ifdef CONFIG_QL_ISP_A64
  822. cmd->dataseg[0].d_base_hi = 0;
  823. #endif /* CONFIG_QL_ISP_A64 */
  824. cmd->dataseg[0].d_count = 0;
  825. cmd->segment_cnt = cpu_to_le16(1); /* Shouldn't this be 0? */
  826. }
  827. /* Committed, record Scsi_Cmd so we can find it later. */
  828. cmd->handle = in_ptr;
  829. hostdata->cmd_slots[in_ptr] = Cmnd;
  830. isp_outw(in_ptr, host, MBOX4);
  831. hostdata->req_in_ptr = in_ptr;
  832. num_free = QLOGICISP_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
  833. host->can_queue = host->host_busy + num_free;
  834. host->sg_tablesize = QLOGICISP_MAX_SG(num_free);
  835. LEAVE("isp1020_queuecommand");
  836. return 0;
  837. }
  838. #define ASYNC_EVENT_INTERRUPT 0x01
  839. irqreturn_t do_isp1020_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
  840. {
  841. struct Scsi_Host *host = dev_id;
  842. unsigned long flags;
  843. spin_lock_irqsave(host->host_lock, flags);
  844. isp1020_intr_handler(irq, dev_id, regs);
  845. spin_unlock_irqrestore(host->host_lock, flags);
  846. return IRQ_HANDLED;
  847. }
  848. void isp1020_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
  849. {
  850. Scsi_Cmnd *Cmnd;
  851. struct Status_Entry *sts;
  852. struct Scsi_Host *host = dev_id;
  853. struct isp1020_hostdata *hostdata;
  854. u_int in_ptr, out_ptr;
  855. u_short status;
  856. ENTER_INTR("isp1020_intr_handler");
  857. hostdata = (struct isp1020_hostdata *) host->hostdata;
  858. DEBUG_INTR(printk("qlogicisp : interrupt on line %d\n", irq));
  859. if (!(isp_inw(host, PCI_INTF_STS) & 0x04)) {
  860. /* spurious interrupts can happen legally */
  861. DEBUG_INTR(printk("qlogicisp: got spurious interrupt\n"));
  862. return;
  863. }
  864. in_ptr = isp_inw(host, MBOX5);
  865. isp_outw(HCCR_CLEAR_RISC_INTR, host, HOST_HCCR);
  866. if ((isp_inw(host, PCI_SEMAPHORE) & ASYNC_EVENT_INTERRUPT)) {
  867. status = isp_inw(host, MBOX0);
  868. DEBUG_INTR(printk("qlogicisp : mbox completion status: %x\n",
  869. status));
  870. switch (status) {
  871. case ASYNC_SCSI_BUS_RESET:
  872. case EXECUTION_TIMEOUT_RESET:
  873. hostdata->send_marker = 1;
  874. break;
  875. case INVALID_COMMAND:
  876. case HOST_INTERFACE_ERROR:
  877. case COMMAND_ERROR:
  878. case COMMAND_PARAM_ERROR:
  879. printk("qlogicisp : bad mailbox return status\n");
  880. break;
  881. }
  882. isp_outw(0x0, host, PCI_SEMAPHORE);
  883. }
  884. out_ptr = hostdata->res_out_ptr;
  885. DEBUG_INTR(printk("qlogicisp : response queue update\n"));
  886. DEBUG_INTR(printk("qlogicisp : response queue depth %d\n",
  887. QUEUE_DEPTH(in_ptr, out_ptr, RES_QUEUE_LEN)));
  888. while (out_ptr != in_ptr) {
  889. u_int cmd_slot;
  890. sts = (struct Status_Entry *) &hostdata->res_cpu[out_ptr];
  891. out_ptr = (out_ptr + 1) & RES_QUEUE_LEN;
  892. cmd_slot = sts->handle;
  893. Cmnd = hostdata->cmd_slots[cmd_slot];
  894. hostdata->cmd_slots[cmd_slot] = NULL;
  895. TRACE("done", out_ptr, Cmnd);
  896. if (le16_to_cpu(sts->completion_status) == CS_RESET_OCCURRED
  897. || le16_to_cpu(sts->completion_status) == CS_ABORTED
  898. || (le16_to_cpu(sts->status_flags) & STF_BUS_RESET))
  899. hostdata->send_marker = 1;
  900. if (le16_to_cpu(sts->state_flags) & SF_GOT_SENSE)
  901. memcpy(Cmnd->sense_buffer, sts->req_sense_data,
  902. sizeof(Cmnd->sense_buffer));
  903. DEBUG_INTR(isp1020_print_status_entry(sts));
  904. if (sts->hdr.entry_type == ENTRY_STATUS)
  905. Cmnd->result = isp1020_return_status(sts);
  906. else
  907. Cmnd->result = DID_ERROR << 16;
  908. if (Cmnd->use_sg)
  909. pci_unmap_sg(hostdata->pci_dev,
  910. (struct scatterlist *)Cmnd->buffer,
  911. Cmnd->use_sg,
  912. Cmnd->sc_data_direction);
  913. else if (Cmnd->request_bufflen)
  914. pci_unmap_single(hostdata->pci_dev,
  915. #ifdef CONFIG_QL_ISP_A64
  916. (dma_addr_t)((long)Cmnd->SCp.ptr),
  917. #else
  918. (u32)((long)Cmnd->SCp.ptr),
  919. #endif
  920. Cmnd->request_bufflen,
  921. Cmnd->sc_data_direction);
  922. isp_outw(out_ptr, host, MBOX5);
  923. (*Cmnd->scsi_done)(Cmnd);
  924. }
  925. hostdata->res_out_ptr = out_ptr;
  926. LEAVE_INTR("isp1020_intr_handler");
  927. }
  928. static int isp1020_return_status(struct Status_Entry *sts)
  929. {
  930. int host_status = DID_ERROR;
  931. #if DEBUG_ISP1020_INTR
  932. static char *reason[] = {
  933. "DID_OK",
  934. "DID_NO_CONNECT",
  935. "DID_BUS_BUSY",
  936. "DID_TIME_OUT",
  937. "DID_BAD_TARGET",
  938. "DID_ABORT",
  939. "DID_PARITY",
  940. "DID_ERROR",
  941. "DID_RESET",
  942. "DID_BAD_INTR"
  943. };
  944. #endif /* DEBUG_ISP1020_INTR */
  945. ENTER("isp1020_return_status");
  946. DEBUG(printk("qlogicisp : completion status = 0x%04x\n",
  947. le16_to_cpu(sts->completion_status)));
  948. switch(le16_to_cpu(sts->completion_status)) {
  949. case CS_COMPLETE:
  950. host_status = DID_OK;
  951. break;
  952. case CS_INCOMPLETE:
  953. if (!(le16_to_cpu(sts->state_flags) & SF_GOT_BUS))
  954. host_status = DID_NO_CONNECT;
  955. else if (!(le16_to_cpu(sts->state_flags) & SF_GOT_TARGET))
  956. host_status = DID_BAD_TARGET;
  957. else if (!(le16_to_cpu(sts->state_flags) & SF_SENT_CDB))
  958. host_status = DID_ERROR;
  959. else if (!(le16_to_cpu(sts->state_flags) & SF_TRANSFERRED_DATA))
  960. host_status = DID_ERROR;
  961. else if (!(le16_to_cpu(sts->state_flags) & SF_GOT_STATUS))
  962. host_status = DID_ERROR;
  963. else if (!(le16_to_cpu(sts->state_flags) & SF_GOT_SENSE))
  964. host_status = DID_ERROR;
  965. break;
  966. case CS_DMA_ERROR:
  967. case CS_TRANSPORT_ERROR:
  968. host_status = DID_ERROR;
  969. break;
  970. case CS_RESET_OCCURRED:
  971. host_status = DID_RESET;
  972. break;
  973. case CS_ABORTED:
  974. host_status = DID_ABORT;
  975. break;
  976. case CS_TIMEOUT:
  977. host_status = DID_TIME_OUT;
  978. break;
  979. case CS_DATA_OVERRUN:
  980. case CS_COMMAND_OVERRUN:
  981. case CS_STATUS_OVERRUN:
  982. case CS_BAD_MESSAGE:
  983. case CS_NO_MESSAGE_OUT:
  984. case CS_EXT_ID_FAILED:
  985. case CS_IDE_MSG_FAILED:
  986. case CS_ABORT_MSG_FAILED:
  987. case CS_NOP_MSG_FAILED:
  988. case CS_PARITY_ERROR_MSG_FAILED:
  989. case CS_DEVICE_RESET_MSG_FAILED:
  990. case CS_ID_MSG_FAILED:
  991. case CS_UNEXP_BUS_FREE:
  992. host_status = DID_ERROR;
  993. break;
  994. case CS_DATA_UNDERRUN:
  995. host_status = DID_OK;
  996. break;
  997. default:
  998. printk("qlogicisp : unknown completion status 0x%04x\n",
  999. le16_to_cpu(sts->completion_status));
  1000. host_status = DID_ERROR;
  1001. break;
  1002. }
  1003. DEBUG_INTR(printk("qlogicisp : host status (%s) scsi status %x\n",
  1004. reason[host_status], le16_to_cpu(sts->scsi_status)));
  1005. LEAVE("isp1020_return_status");
  1006. return (le16_to_cpu(sts->scsi_status) & STATUS_MASK) | (host_status << 16);
  1007. }
  1008. static int isp1020_biosparam(struct scsi_device *sdev, struct block_device *n,
  1009. sector_t capacity, int ip[])
  1010. {
  1011. int size = capacity;
  1012. ENTER("isp1020_biosparam");
  1013. ip[0] = 64;
  1014. ip[1] = 32;
  1015. ip[2] = size >> 11;
  1016. if (ip[2] > 1024) {
  1017. ip[0] = 255;
  1018. ip[1] = 63;
  1019. ip[2] = size / (ip[0] * ip[1]);
  1020. #if 0
  1021. if (ip[2] > 1023)
  1022. ip[2] = 1023;
  1023. #endif
  1024. }
  1025. LEAVE("isp1020_biosparam");
  1026. return 0;
  1027. }
  1028. static int isp1020_reset_hardware(struct Scsi_Host *host)
  1029. {
  1030. u_short param[6];
  1031. int loop_count;
  1032. ENTER("isp1020_reset_hardware");
  1033. isp_outw(ISP_RESET, host, PCI_INTF_CTL);
  1034. udelay(100);
  1035. isp_outw(HCCR_RESET, host, HOST_HCCR);
  1036. udelay(100);
  1037. isp_outw(HCCR_RELEASE, host, HOST_HCCR);
  1038. isp_outw(HCCR_BIOS_DISABLE, host, HOST_HCCR);
  1039. loop_count = DEFAULT_LOOP_COUNT;
  1040. while (--loop_count && isp_inw(host, HOST_HCCR) == RISC_BUSY) {
  1041. barrier();
  1042. cpu_relax();
  1043. }
  1044. if (!loop_count)
  1045. printk("qlogicisp: reset_hardware loop timeout\n");
  1046. isp_outw(0, host, ISP_CFG1);
  1047. #if DEBUG_ISP1020
  1048. printk("qlogicisp : mbox 0 0x%04x \n", isp_inw(host, MBOX0));
  1049. printk("qlogicisp : mbox 1 0x%04x \n", isp_inw(host, MBOX1));
  1050. printk("qlogicisp : mbox 2 0x%04x \n", isp_inw(host, MBOX2));
  1051. printk("qlogicisp : mbox 3 0x%04x \n", isp_inw(host, MBOX3));
  1052. printk("qlogicisp : mbox 4 0x%04x \n", isp_inw(host, MBOX4));
  1053. printk("qlogicisp : mbox 5 0x%04x \n", isp_inw(host, MBOX5));
  1054. #endif /* DEBUG_ISP1020 */
  1055. param[0] = MBOX_NO_OP;
  1056. isp1020_mbox_command(host, param);
  1057. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1058. printk("qlogicisp : NOP test failed\n");
  1059. return 1;
  1060. }
  1061. DEBUG(printk("qlogicisp : loading risc ram\n"));
  1062. #if RELOAD_FIRMWARE
  1063. for (loop_count = 0; loop_count < risc_code_length01; loop_count++) {
  1064. param[0] = MBOX_WRITE_RAM_WORD;
  1065. param[1] = risc_code_addr01 + loop_count;
  1066. param[2] = risc_code01[loop_count];
  1067. isp1020_mbox_command(host, param);
  1068. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1069. printk("qlogicisp : firmware load failure at %d\n",
  1070. loop_count);
  1071. return 1;
  1072. }
  1073. }
  1074. #endif /* RELOAD_FIRMWARE */
  1075. DEBUG(printk("qlogicisp : verifying checksum\n"));
  1076. param[0] = MBOX_VERIFY_CHECKSUM;
  1077. param[1] = risc_code_addr01;
  1078. isp1020_mbox_command(host, param);
  1079. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1080. printk("qlogicisp : ram checksum failure\n");
  1081. return 1;
  1082. }
  1083. DEBUG(printk("qlogicisp : executing firmware\n"));
  1084. param[0] = MBOX_EXEC_FIRMWARE;
  1085. param[1] = risc_code_addr01;
  1086. isp1020_mbox_command(host, param);
  1087. param[0] = MBOX_ABOUT_FIRMWARE;
  1088. isp1020_mbox_command(host, param);
  1089. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1090. printk("qlogicisp : about firmware failure\n");
  1091. return 1;
  1092. }
  1093. DEBUG(printk("qlogicisp : firmware major revision %d\n", param[1]));
  1094. DEBUG(printk("qlogicisp : firmware minor revision %d\n", param[2]));
  1095. LEAVE("isp1020_reset_hardware");
  1096. return 0;
  1097. }
  1098. static int isp1020_init(struct Scsi_Host *sh)
  1099. {
  1100. u_long io_base, mem_base, io_flags, mem_flags;
  1101. struct isp1020_hostdata *hostdata;
  1102. u_char revision;
  1103. u_int irq;
  1104. u_short command;
  1105. struct pci_dev *pdev;
  1106. ENTER("isp1020_init");
  1107. hostdata = (struct isp1020_hostdata *) sh->hostdata;
  1108. pdev = hostdata->pci_dev;
  1109. if (pci_read_config_word(pdev, PCI_COMMAND, &command)
  1110. || pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision))
  1111. {
  1112. printk("qlogicisp : error reading PCI configuration\n");
  1113. return 1;
  1114. }
  1115. io_base = pci_resource_start(pdev, 0);
  1116. mem_base = pci_resource_start(pdev, 1);
  1117. io_flags = pci_resource_flags(pdev, 0);
  1118. mem_flags = pci_resource_flags(pdev, 1);
  1119. irq = pdev->irq;
  1120. if (pdev->vendor != PCI_VENDOR_ID_QLOGIC) {
  1121. printk("qlogicisp : 0x%04x is not QLogic vendor ID\n",
  1122. pdev->vendor);
  1123. return 1;
  1124. }
  1125. if (pdev->device != PCI_DEVICE_ID_QLOGIC_ISP1020) {
  1126. printk("qlogicisp : 0x%04x does not match ISP1020 device id\n",
  1127. pdev->device);
  1128. return 1;
  1129. }
  1130. #ifdef __alpha__
  1131. /* Force ALPHA to use bus I/O and not bus MEM.
  1132. This is to avoid having to use HAE_MEM registers,
  1133. which is broken on some platforms and with SMP. */
  1134. command &= ~PCI_COMMAND_MEMORY;
  1135. #endif
  1136. sh->io_port = io_base;
  1137. if (!request_region(sh->io_port, 0xff, "qlogicisp")) {
  1138. printk("qlogicisp : i/o region 0x%lx-0x%lx already "
  1139. "in use\n",
  1140. sh->io_port, sh->io_port + 0xff);
  1141. return 1;
  1142. }
  1143. if ((command & PCI_COMMAND_MEMORY) &&
  1144. ((mem_flags & 1) == 0)) {
  1145. hostdata->memaddr = ioremap(mem_base, PAGE_SIZE);
  1146. if (!hostdata->memaddr) {
  1147. printk("qlogicisp : i/o remapping failed.\n");
  1148. goto out_release;
  1149. }
  1150. } else {
  1151. if (command & PCI_COMMAND_IO && (io_flags & 3) != 1) {
  1152. printk("qlogicisp : i/o mapping is disabled\n");
  1153. goto out_release;
  1154. }
  1155. hostdata->memaddr = NULL; /* zero to signify no i/o mapping */
  1156. mem_base = 0;
  1157. }
  1158. if (revision != ISP1020_REV_ID)
  1159. printk("qlogicisp : new isp1020 revision ID (%d)\n", revision);
  1160. if (isp_inw(sh, PCI_ID_LOW) != PCI_VENDOR_ID_QLOGIC
  1161. || isp_inw(sh, PCI_ID_HIGH) != PCI_DEVICE_ID_QLOGIC_ISP1020)
  1162. {
  1163. printk("qlogicisp : can't decode %s address space 0x%lx\n",
  1164. (io_base ? "I/O" : "MEM"),
  1165. (io_base ? io_base : mem_base));
  1166. goto out_unmap;
  1167. }
  1168. hostdata->revision = revision;
  1169. sh->irq = irq;
  1170. sh->max_id = MAX_TARGETS;
  1171. sh->max_lun = MAX_LUNS;
  1172. hostdata->res_cpu = pci_alloc_consistent(hostdata->pci_dev,
  1173. QSIZE(RES_QUEUE_LEN),
  1174. &hostdata->res_dma);
  1175. if (hostdata->res_cpu == NULL) {
  1176. printk("qlogicisp : can't allocate response queue\n");
  1177. goto out_unmap;
  1178. }
  1179. hostdata->req_cpu = pci_alloc_consistent(hostdata->pci_dev,
  1180. QSIZE(QLOGICISP_REQ_QUEUE_LEN),
  1181. &hostdata->req_dma);
  1182. if (hostdata->req_cpu == NULL) {
  1183. pci_free_consistent(hostdata->pci_dev,
  1184. QSIZE(RES_QUEUE_LEN),
  1185. hostdata->res_cpu,
  1186. hostdata->res_dma);
  1187. printk("qlogicisp : can't allocate request queue\n");
  1188. goto out_unmap;
  1189. }
  1190. pci_set_master(pdev);
  1191. LEAVE("isp1020_init");
  1192. return 0;
  1193. out_unmap:
  1194. iounmap(hostdata->memaddr);
  1195. out_release:
  1196. release_region(sh->io_port, 0xff);
  1197. return 1;
  1198. }
  1199. #if USE_NVRAM_DEFAULTS
  1200. static int isp1020_get_defaults(struct Scsi_Host *host)
  1201. {
  1202. int i;
  1203. u_short value;
  1204. struct isp1020_hostdata *hostdata =
  1205. (struct isp1020_hostdata *) host->hostdata;
  1206. ENTER("isp1020_get_defaults");
  1207. if (!isp1020_verify_nvram(host)) {
  1208. printk("qlogicisp : nvram checksum failure\n");
  1209. printk("qlogicisp : attempting to use default parameters\n");
  1210. return isp1020_set_defaults(host);
  1211. }
  1212. value = isp1020_read_nvram_word(host, 2);
  1213. hostdata->host_param.fifo_threshold = (value >> 8) & 0x03;
  1214. hostdata->host_param.host_adapter_enable = (value >> 11) & 0x01;
  1215. hostdata->host_param.initiator_scsi_id = (value >> 12) & 0x0f;
  1216. value = isp1020_read_nvram_word(host, 3);
  1217. hostdata->host_param.bus_reset_delay = value & 0xff;
  1218. hostdata->host_param.retry_count = value >> 8;
  1219. value = isp1020_read_nvram_word(host, 4);
  1220. hostdata->host_param.retry_delay = value & 0xff;
  1221. hostdata->host_param.async_data_setup_time = (value >> 8) & 0x0f;
  1222. hostdata->host_param.req_ack_active_negation = (value >> 12) & 0x01;
  1223. hostdata->host_param.data_line_active_negation = (value >> 13) & 0x01;
  1224. hostdata->host_param.data_dma_burst_enable = (value >> 14) & 0x01;
  1225. hostdata->host_param.command_dma_burst_enable = (value >> 15);
  1226. value = isp1020_read_nvram_word(host, 5);
  1227. hostdata->host_param.tag_aging = value & 0xff;
  1228. value = isp1020_read_nvram_word(host, 6);
  1229. hostdata->host_param.selection_timeout = value & 0xffff;
  1230. value = isp1020_read_nvram_word(host, 7);
  1231. hostdata->host_param.max_queue_depth = value & 0xffff;
  1232. #if DEBUG_ISP1020_SETUP
  1233. printk("qlogicisp : fifo threshold=%d\n",
  1234. hostdata->host_param.fifo_threshold);
  1235. printk("qlogicisp : initiator scsi id=%d\n",
  1236. hostdata->host_param.initiator_scsi_id);
  1237. printk("qlogicisp : bus reset delay=%d\n",
  1238. hostdata->host_param.bus_reset_delay);
  1239. printk("qlogicisp : retry count=%d\n",
  1240. hostdata->host_param.retry_count);
  1241. printk("qlogicisp : retry delay=%d\n",
  1242. hostdata->host_param.retry_delay);
  1243. printk("qlogicisp : async data setup time=%d\n",
  1244. hostdata->host_param.async_data_setup_time);
  1245. printk("qlogicisp : req/ack active negation=%d\n",
  1246. hostdata->host_param.req_ack_active_negation);
  1247. printk("qlogicisp : data line active negation=%d\n",
  1248. hostdata->host_param.data_line_active_negation);
  1249. printk("qlogicisp : data DMA burst enable=%d\n",
  1250. hostdata->host_param.data_dma_burst_enable);
  1251. printk("qlogicisp : command DMA burst enable=%d\n",
  1252. hostdata->host_param.command_dma_burst_enable);
  1253. printk("qlogicisp : tag age limit=%d\n",
  1254. hostdata->host_param.tag_aging);
  1255. printk("qlogicisp : selection timeout limit=%d\n",
  1256. hostdata->host_param.selection_timeout);
  1257. printk("qlogicisp : max queue depth=%d\n",
  1258. hostdata->host_param.max_queue_depth);
  1259. #endif /* DEBUG_ISP1020_SETUP */
  1260. for (i = 0; i < MAX_TARGETS; i++) {
  1261. value = isp1020_read_nvram_word(host, 14 + i * 3);
  1262. hostdata->dev_param[i].device_flags = value & 0xff;
  1263. hostdata->dev_param[i].execution_throttle = value >> 8;
  1264. value = isp1020_read_nvram_word(host, 15 + i * 3);
  1265. hostdata->dev_param[i].synchronous_period = value & 0xff;
  1266. hostdata->dev_param[i].synchronous_offset = (value >> 8) & 0x0f;
  1267. hostdata->dev_param[i].device_enable = (value >> 12) & 0x01;
  1268. #if DEBUG_ISP1020_SETUP
  1269. printk("qlogicisp : target 0x%02x\n", i);
  1270. printk("qlogicisp : device flags=0x%02x\n",
  1271. hostdata->dev_param[i].device_flags);
  1272. printk("qlogicisp : execution throttle=%d\n",
  1273. hostdata->dev_param[i].execution_throttle);
  1274. printk("qlogicisp : synchronous period=%d\n",
  1275. hostdata->dev_param[i].synchronous_period);
  1276. printk("qlogicisp : synchronous offset=%d\n",
  1277. hostdata->dev_param[i].synchronous_offset);
  1278. printk("qlogicisp : device enable=%d\n",
  1279. hostdata->dev_param[i].device_enable);
  1280. #endif /* DEBUG_ISP1020_SETUP */
  1281. }
  1282. LEAVE("isp1020_get_defaults");
  1283. return 0;
  1284. }
  1285. #define ISP1020_NVRAM_LEN 0x40
  1286. #define ISP1020_NVRAM_SIG1 0x5349
  1287. #define ISP1020_NVRAM_SIG2 0x2050
  1288. static int isp1020_verify_nvram(struct Scsi_Host *host)
  1289. {
  1290. int i;
  1291. u_short value;
  1292. u_char checksum = 0;
  1293. for (i = 0; i < ISP1020_NVRAM_LEN; i++) {
  1294. value = isp1020_read_nvram_word(host, i);
  1295. switch (i) {
  1296. case 0:
  1297. if (value != ISP1020_NVRAM_SIG1) return 0;
  1298. break;
  1299. case 1:
  1300. if (value != ISP1020_NVRAM_SIG2) return 0;
  1301. break;
  1302. case 2:
  1303. if ((value & 0xff) != 0x02) return 0;
  1304. break;
  1305. }
  1306. checksum += value & 0xff;
  1307. checksum += value >> 8;
  1308. }
  1309. return (checksum == 0);
  1310. }
  1311. #define NVRAM_DELAY() udelay(2) /* 2 microsecond delay */
  1312. u_short isp1020_read_nvram_word(struct Scsi_Host *host, u_short byte)
  1313. {
  1314. int i;
  1315. u_short value, output, input;
  1316. byte &= 0x3f; byte |= 0x0180;
  1317. for (i = 8; i >= 0; i--) {
  1318. output = ((byte >> i) & 0x1) ? 0x4 : 0x0;
  1319. isp_outw(output | 0x2, host, PCI_NVRAM); NVRAM_DELAY();
  1320. isp_outw(output | 0x3, host, PCI_NVRAM); NVRAM_DELAY();
  1321. isp_outw(output | 0x2, host, PCI_NVRAM); NVRAM_DELAY();
  1322. }
  1323. for (i = 0xf, value = 0; i >= 0; i--) {
  1324. value <<= 1;
  1325. isp_outw(0x3, host, PCI_NVRAM); NVRAM_DELAY();
  1326. input = isp_inw(host, PCI_NVRAM); NVRAM_DELAY();
  1327. isp_outw(0x2, host, PCI_NVRAM); NVRAM_DELAY();
  1328. if (input & 0x8) value |= 1;
  1329. }
  1330. isp_outw(0x0, host, PCI_NVRAM); NVRAM_DELAY();
  1331. return value;
  1332. }
  1333. #endif /* USE_NVRAM_DEFAULTS */
  1334. static int isp1020_set_defaults(struct Scsi_Host *host)
  1335. {
  1336. struct isp1020_hostdata *hostdata =
  1337. (struct isp1020_hostdata *) host->hostdata;
  1338. int i;
  1339. ENTER("isp1020_set_defaults");
  1340. hostdata->host_param.fifo_threshold = 2;
  1341. hostdata->host_param.host_adapter_enable = 1;
  1342. hostdata->host_param.initiator_scsi_id = 7;
  1343. hostdata->host_param.bus_reset_delay = 3;
  1344. hostdata->host_param.retry_count = 0;
  1345. hostdata->host_param.retry_delay = 1;
  1346. hostdata->host_param.async_data_setup_time = 6;
  1347. hostdata->host_param.req_ack_active_negation = 1;
  1348. hostdata->host_param.data_line_active_negation = 1;
  1349. hostdata->host_param.data_dma_burst_enable = 1;
  1350. hostdata->host_param.command_dma_burst_enable = 1;
  1351. hostdata->host_param.tag_aging = 8;
  1352. hostdata->host_param.selection_timeout = 250;
  1353. hostdata->host_param.max_queue_depth = 256;
  1354. for (i = 0; i < MAX_TARGETS; i++) {
  1355. hostdata->dev_param[i].device_flags = 0xfd;
  1356. hostdata->dev_param[i].execution_throttle = 16;
  1357. hostdata->dev_param[i].synchronous_period = 25;
  1358. hostdata->dev_param[i].synchronous_offset = 12;
  1359. hostdata->dev_param[i].device_enable = 1;
  1360. }
  1361. LEAVE("isp1020_set_defaults");
  1362. return 0;
  1363. }
  1364. static int isp1020_load_parameters(struct Scsi_Host *host)
  1365. {
  1366. int i, k;
  1367. #ifdef CONFIG_QL_ISP_A64
  1368. u_long queue_addr;
  1369. u_short param[8];
  1370. #else
  1371. u_int queue_addr;
  1372. u_short param[6];
  1373. #endif
  1374. u_short isp_cfg1, hwrev;
  1375. struct isp1020_hostdata *hostdata =
  1376. (struct isp1020_hostdata *) host->hostdata;
  1377. ENTER("isp1020_load_parameters");
  1378. hwrev = isp_inw(host, ISP_CFG0) & ISP_CFG0_HWMSK;
  1379. isp_cfg1 = ISP_CFG1_F64 | ISP_CFG1_BENAB;
  1380. if (hwrev == ISP_CFG0_1040A) {
  1381. /* Busted fifo, says mjacob. */
  1382. isp_cfg1 &= ISP_CFG1_BENAB;
  1383. }
  1384. isp_outw(isp_inw(host, ISP_CFG1) | isp_cfg1, host, ISP_CFG1);
  1385. isp_outw(isp_inw(host, CDMA_CONF) | DMA_CONF_BENAB, host, CDMA_CONF);
  1386. isp_outw(isp_inw(host, DDMA_CONF) | DMA_CONF_BENAB, host, DDMA_CONF);
  1387. param[0] = MBOX_SET_INIT_SCSI_ID;
  1388. param[1] = hostdata->host_param.initiator_scsi_id;
  1389. isp1020_mbox_command(host, param);
  1390. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1391. printk("qlogicisp : set initiator id failure\n");
  1392. return 1;
  1393. }
  1394. param[0] = MBOX_SET_RETRY_COUNT;
  1395. param[1] = hostdata->host_param.retry_count;
  1396. param[2] = hostdata->host_param.retry_delay;
  1397. isp1020_mbox_command(host, param);
  1398. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1399. printk("qlogicisp : set retry count failure\n");
  1400. return 1;
  1401. }
  1402. param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
  1403. param[1] = hostdata->host_param.async_data_setup_time;
  1404. isp1020_mbox_command(host, param);
  1405. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1406. printk("qlogicisp : async data setup time failure\n");
  1407. return 1;
  1408. }
  1409. param[0] = MBOX_SET_ACTIVE_NEG_STATE;
  1410. param[1] = (hostdata->host_param.req_ack_active_negation << 4)
  1411. | (hostdata->host_param.data_line_active_negation << 5);
  1412. isp1020_mbox_command(host, param);
  1413. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1414. printk("qlogicisp : set active negation state failure\n");
  1415. return 1;
  1416. }
  1417. param[0] = MBOX_SET_PCI_CONTROL_PARAMS;
  1418. param[1] = hostdata->host_param.data_dma_burst_enable << 1;
  1419. param[2] = hostdata->host_param.command_dma_burst_enable << 1;
  1420. isp1020_mbox_command(host, param);
  1421. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1422. printk("qlogicisp : set pci control parameter failure\n");
  1423. return 1;
  1424. }
  1425. param[0] = MBOX_SET_TAG_AGE_LIMIT;
  1426. param[1] = hostdata->host_param.tag_aging;
  1427. isp1020_mbox_command(host, param);
  1428. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1429. printk("qlogicisp : set tag age limit failure\n");
  1430. return 1;
  1431. }
  1432. param[0] = MBOX_SET_SELECT_TIMEOUT;
  1433. param[1] = hostdata->host_param.selection_timeout;
  1434. isp1020_mbox_command(host, param);
  1435. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1436. printk("qlogicisp : set selection timeout failure\n");
  1437. return 1;
  1438. }
  1439. for (i = 0; i < MAX_TARGETS; i++) {
  1440. if (!hostdata->dev_param[i].device_enable)
  1441. continue;
  1442. param[0] = MBOX_SET_TARGET_PARAMS;
  1443. param[1] = i << 8;
  1444. param[2] = hostdata->dev_param[i].device_flags << 8;
  1445. param[3] = (hostdata->dev_param[i].synchronous_offset << 8)
  1446. | hostdata->dev_param[i].synchronous_period;
  1447. isp1020_mbox_command(host, param);
  1448. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1449. printk("qlogicisp : set target parameter failure\n");
  1450. return 1;
  1451. }
  1452. for (k = 0; k < MAX_LUNS; k++) {
  1453. param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
  1454. param[1] = (i << 8) | k;
  1455. param[2] = hostdata->host_param.max_queue_depth;
  1456. param[3] = hostdata->dev_param[i].execution_throttle;
  1457. isp1020_mbox_command(host, param);
  1458. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1459. printk("qlogicisp : set device queue "
  1460. "parameter failure\n");
  1461. return 1;
  1462. }
  1463. }
  1464. }
  1465. queue_addr = hostdata->res_dma;
  1466. #ifdef CONFIG_QL_ISP_A64
  1467. param[0] = MBOX_CMD_INIT_RESPONSE_QUEUE_64;
  1468. #else
  1469. param[0] = MBOX_INIT_RES_QUEUE;
  1470. #endif
  1471. param[1] = RES_QUEUE_LEN + 1;
  1472. param[2] = (u_short) (queue_addr >> 16);
  1473. param[3] = (u_short) (queue_addr & 0xffff);
  1474. param[4] = 0;
  1475. param[5] = 0;
  1476. #ifdef CONFIG_QL_ISP_A64
  1477. param[6] = (u_short) (queue_addr >> 48);
  1478. param[7] = (u_short) (queue_addr >> 32);
  1479. #endif
  1480. isp1020_mbox_command(host, param);
  1481. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1482. printk("qlogicisp : set response queue failure\n");
  1483. return 1;
  1484. }
  1485. queue_addr = hostdata->req_dma;
  1486. #ifdef CONFIG_QL_ISP_A64
  1487. param[0] = MBOX_CMD_INIT_REQUEST_QUEUE_64;
  1488. #else
  1489. param[0] = MBOX_INIT_REQ_QUEUE;
  1490. #endif
  1491. param[1] = QLOGICISP_REQ_QUEUE_LEN + 1;
  1492. param[2] = (u_short) (queue_addr >> 16);
  1493. param[3] = (u_short) (queue_addr & 0xffff);
  1494. param[4] = 0;
  1495. #ifdef CONFIG_QL_ISP_A64
  1496. param[5] = 0;
  1497. param[6] = (u_short) (queue_addr >> 48);
  1498. param[7] = (u_short) (queue_addr >> 32);
  1499. #endif
  1500. isp1020_mbox_command(host, param);
  1501. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1502. printk("qlogicisp : set request queue failure\n");
  1503. return 1;
  1504. }
  1505. LEAVE("isp1020_load_parameters");
  1506. return 0;
  1507. }
  1508. /*
  1509. * currently, this is only called during initialization or abort/reset,
  1510. * at which times interrupts are disabled, so polling is OK, I guess...
  1511. */
  1512. static int isp1020_mbox_command(struct Scsi_Host *host, u_short param[])
  1513. {
  1514. int loop_count;
  1515. if (mbox_param[param[0]] == 0)
  1516. return 1;
  1517. loop_count = DEFAULT_LOOP_COUNT;
  1518. while (--loop_count && isp_inw(host, HOST_HCCR) & 0x0080) {
  1519. barrier();
  1520. cpu_relax();
  1521. }
  1522. if (!loop_count)
  1523. printk("qlogicisp: mbox_command loop timeout #1\n");
  1524. switch(mbox_param[param[0]] >> 4) {
  1525. case 8: isp_outw(param[7], host, MBOX7);
  1526. case 7: isp_outw(param[6], host, MBOX6);
  1527. case 6: isp_outw(param[5], host, MBOX5);
  1528. case 5: isp_outw(param[4], host, MBOX4);
  1529. case 4: isp_outw(param[3], host, MBOX3);
  1530. case 3: isp_outw(param[2], host, MBOX2);
  1531. case 2: isp_outw(param[1], host, MBOX1);
  1532. case 1: isp_outw(param[0], host, MBOX0);
  1533. }
  1534. isp_outw(0x0, host, PCI_SEMAPHORE);
  1535. isp_outw(HCCR_CLEAR_RISC_INTR, host, HOST_HCCR);
  1536. isp_outw(HCCR_SET_HOST_INTR, host, HOST_HCCR);
  1537. loop_count = DEFAULT_LOOP_COUNT;
  1538. while (--loop_count && !(isp_inw(host, PCI_INTF_STS) & 0x04)) {
  1539. barrier();
  1540. cpu_relax();
  1541. }
  1542. if (!loop_count)
  1543. printk("qlogicisp: mbox_command loop timeout #2\n");
  1544. loop_count = DEFAULT_LOOP_COUNT;
  1545. while (--loop_count && isp_inw(host, MBOX0) == 0x04) {
  1546. barrier();
  1547. cpu_relax();
  1548. }
  1549. if (!loop_count)
  1550. printk("qlogicisp: mbox_command loop timeout #3\n");
  1551. switch(mbox_param[param[0]] & 0xf) {
  1552. case 8: param[7] = isp_inw(host, MBOX7);
  1553. case 7: param[6] = isp_inw(host, MBOX6);
  1554. case 6: param[5] = isp_inw(host, MBOX5);
  1555. case 5: param[4] = isp_inw(host, MBOX4);
  1556. case 4: param[3] = isp_inw(host, MBOX3);
  1557. case 3: param[2] = isp_inw(host, MBOX2);
  1558. case 2: param[1] = isp_inw(host, MBOX1);
  1559. case 1: param[0] = isp_inw(host, MBOX0);
  1560. }
  1561. isp_outw(0x0, host, PCI_SEMAPHORE);
  1562. isp_outw(HCCR_CLEAR_RISC_INTR, host, HOST_HCCR);
  1563. return 0;
  1564. }
  1565. #if DEBUG_ISP1020_INTR
  1566. void isp1020_print_status_entry(struct Status_Entry *status)
  1567. {
  1568. int i;
  1569. printk("qlogicisp : entry count = 0x%02x, type = 0x%02x, flags = 0x%02x\n",
  1570. status->hdr.entry_cnt, status->hdr.entry_type, status->hdr.flags);
  1571. printk("qlogicisp : scsi status = 0x%04x, completion status = 0x%04x\n",
  1572. le16_to_cpu(status->scsi_status), le16_to_cpu(status->completion_status));
  1573. printk("qlogicisp : state flags = 0x%04x, status flags = 0x%04x\n",
  1574. le16_to_cpu(status->state_flags), le16_to_cpu(status->status_flags));
  1575. printk("qlogicisp : time = 0x%04x, request sense length = 0x%04x\n",
  1576. le16_to_cpu(status->time), le16_to_cpu(status->req_sense_len));
  1577. printk("qlogicisp : residual transfer length = 0x%08x\n",
  1578. le32_to_cpu(status->residual));
  1579. for (i = 0; i < le16_to_cpu(status->req_sense_len); i++)
  1580. printk("qlogicisp : sense data = 0x%02x\n", status->req_sense_data[i]);
  1581. }
  1582. #endif /* DEBUG_ISP1020_INTR */
  1583. #if DEBUG_ISP1020
  1584. void isp1020_print_scsi_cmd(Scsi_Cmnd *cmd)
  1585. {
  1586. int i;
  1587. printk("qlogicisp : target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
  1588. cmd->target, cmd->lun, cmd->cmd_len);
  1589. printk("qlogicisp : command = ");
  1590. for (i = 0; i < cmd->cmd_len; i++)
  1591. printk("0x%02x ", cmd->cmnd[i]);
  1592. printk("\n");
  1593. }
  1594. #endif /* DEBUG_ISP1020 */
  1595. MODULE_LICENSE("GPL");
  1596. static Scsi_Host_Template driver_template = {
  1597. .detect = isp1020_detect,
  1598. .release = isp1020_release,
  1599. .info = isp1020_info,
  1600. .queuecommand = isp1020_queuecommand,
  1601. .bios_param = isp1020_biosparam,
  1602. .can_queue = QLOGICISP_REQ_QUEUE_LEN,
  1603. .this_id = -1,
  1604. .sg_tablesize = QLOGICISP_MAX_SG(QLOGICISP_REQ_QUEUE_LEN),
  1605. .cmd_per_lun = 1,
  1606. .use_clustering = DISABLE_CLUSTERING,
  1607. };
  1608. #include "scsi_module.c"