qlogicisp.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934
  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. if (isp1020_init(host))
  618. goto fail_and_unregister;
  619. if (isp1020_reset_hardware(host)
  620. #if USE_NVRAM_DEFAULTS
  621. || isp1020_get_defaults(host)
  622. #else
  623. || isp1020_set_defaults(host)
  624. #endif /* USE_NVRAM_DEFAULTS */
  625. || isp1020_load_parameters(host)) {
  626. goto fail_uninit;
  627. }
  628. host->this_id = hostdata->host_param.initiator_scsi_id;
  629. host->max_sectors = 64;
  630. if (request_irq(host->irq, do_isp1020_intr_handler, SA_INTERRUPT | SA_SHIRQ,
  631. "qlogicisp", host))
  632. {
  633. printk("qlogicisp : interrupt %d already in use\n",
  634. host->irq);
  635. goto fail_uninit;
  636. }
  637. isp_outw(0x0, host, PCI_SEMAPHORE);
  638. isp_outw(HCCR_CLEAR_RISC_INTR, host, HOST_HCCR);
  639. isp1020_enable_irqs(host);
  640. hosts++;
  641. continue;
  642. fail_uninit:
  643. iounmap(hostdata->memaddr);
  644. release_region(host->io_port, 0xff);
  645. fail_and_unregister:
  646. if (hostdata->res_cpu)
  647. pci_free_consistent(hostdata->pci_dev,
  648. QSIZE(RES_QUEUE_LEN),
  649. hostdata->res_cpu,
  650. hostdata->res_dma);
  651. if (hostdata->req_cpu)
  652. pci_free_consistent(hostdata->pci_dev,
  653. QSIZE(QLOGICISP_REQ_QUEUE_LEN),
  654. hostdata->req_cpu,
  655. hostdata->req_dma);
  656. scsi_unregister(host);
  657. }
  658. LEAVE("isp1020_detect");
  659. return hosts;
  660. }
  661. static int isp1020_release(struct Scsi_Host *host)
  662. {
  663. struct isp1020_hostdata *hostdata;
  664. ENTER("isp1020_release");
  665. hostdata = (struct isp1020_hostdata *) host->hostdata;
  666. isp_outw(0x0, host, PCI_INTF_CTL);
  667. free_irq(host->irq, host);
  668. iounmap(hostdata->memaddr);
  669. release_region(host->io_port, 0xff);
  670. LEAVE("isp1020_release");
  671. return 0;
  672. }
  673. static const char *isp1020_info(struct Scsi_Host *host)
  674. {
  675. static char buf[80];
  676. struct isp1020_hostdata *hostdata;
  677. ENTER("isp1020_info");
  678. hostdata = (struct isp1020_hostdata *) host->hostdata;
  679. sprintf(buf,
  680. "QLogic ISP1020 SCSI on PCI bus %02x device %02x irq %d %s base 0x%lx",
  681. hostdata->pci_dev->bus->number, hostdata->pci_dev->devfn, host->irq,
  682. (hostdata->memaddr ? "MEM" : "I/O"),
  683. (hostdata->memaddr ? (unsigned long)hostdata->memaddr : host->io_port));
  684. LEAVE("isp1020_info");
  685. return buf;
  686. }
  687. /*
  688. * The middle SCSI layer ensures that queuecommand never gets invoked
  689. * concurrently with itself or the interrupt handler (though the
  690. * interrupt handler may call this routine as part of
  691. * request-completion handling).
  692. */
  693. static int isp1020_queuecommand(Scsi_Cmnd *Cmnd, void (*done)(Scsi_Cmnd *))
  694. {
  695. int i, n, num_free;
  696. u_int in_ptr, out_ptr;
  697. struct dataseg * ds;
  698. struct scatterlist *sg;
  699. struct Command_Entry *cmd;
  700. struct Continuation_Entry *cont;
  701. struct Scsi_Host *host;
  702. struct isp1020_hostdata *hostdata;
  703. dma_addr_t dma_addr;
  704. ENTER("isp1020_queuecommand");
  705. host = Cmnd->device->host;
  706. hostdata = (struct isp1020_hostdata *) host->hostdata;
  707. Cmnd->scsi_done = done;
  708. DEBUG(isp1020_print_scsi_cmd(Cmnd));
  709. out_ptr = isp_inw(host, + MBOX4);
  710. in_ptr = hostdata->req_in_ptr;
  711. DEBUG(printk("qlogicisp : request queue depth %d\n",
  712. REQ_QUEUE_DEPTH(in_ptr, out_ptr)));
  713. cmd = (struct Command_Entry *) &hostdata->req_cpu[in_ptr];
  714. in_ptr = (in_ptr + 1) & QLOGICISP_REQ_QUEUE_LEN;
  715. if (in_ptr == out_ptr) {
  716. printk("qlogicisp : request queue overflow\n");
  717. return 1;
  718. }
  719. if (hostdata->send_marker) {
  720. struct Marker_Entry *marker;
  721. TRACE("queue marker", in_ptr, 0);
  722. DEBUG(printk("qlogicisp : adding marker entry\n"));
  723. marker = (struct Marker_Entry *) cmd;
  724. memset(marker, 0, sizeof(struct Marker_Entry));
  725. marker->hdr.entry_type = ENTRY_MARKER;
  726. marker->hdr.entry_cnt = 1;
  727. marker->modifier = SYNC_ALL;
  728. hostdata->send_marker = 0;
  729. if (((in_ptr + 1) & QLOGICISP_REQ_QUEUE_LEN) == out_ptr) {
  730. isp_outw(in_ptr, host, MBOX4);
  731. hostdata->req_in_ptr = in_ptr;
  732. printk("qlogicisp : request queue overflow\n");
  733. return 1;
  734. }
  735. cmd = (struct Command_Entry *) &hostdata->req_cpu[in_ptr];
  736. in_ptr = (in_ptr + 1) & QLOGICISP_REQ_QUEUE_LEN;
  737. }
  738. TRACE("queue command", in_ptr, Cmnd);
  739. memset(cmd, 0, sizeof(struct Command_Entry));
  740. cmd->hdr.entry_type = ENTRY_COMMAND;
  741. cmd->hdr.entry_cnt = 1;
  742. cmd->target_lun = Cmnd->device->lun;
  743. cmd->target_id = Cmnd->device->id;
  744. cmd->cdb_length = cpu_to_le16(Cmnd->cmd_len);
  745. cmd->control_flags = cpu_to_le16(CFLAG_READ | CFLAG_WRITE);
  746. cmd->time_out = cpu_to_le16(30);
  747. memcpy(cmd->cdb, Cmnd->cmnd, Cmnd->cmd_len);
  748. if (Cmnd->use_sg) {
  749. int sg_count;
  750. sg = (struct scatterlist *) Cmnd->request_buffer;
  751. ds = cmd->dataseg;
  752. sg_count = pci_map_sg(hostdata->pci_dev, sg, Cmnd->use_sg,
  753. Cmnd->sc_data_direction);
  754. cmd->segment_cnt = cpu_to_le16(sg_count);
  755. /* fill in first four sg entries: */
  756. n = sg_count;
  757. if (n > IOCB_SEGS)
  758. n = IOCB_SEGS;
  759. for (i = 0; i < n; i++) {
  760. dma_addr = sg_dma_address(sg);
  761. ds[i].d_base = cpu_to_le32((u32) dma_addr);
  762. #ifdef CONFIG_QL_ISP_A64
  763. ds[i].d_base_hi = cpu_to_le32((u32) (dma_addr>>32));
  764. #endif /* CONFIG_QL_ISP_A64 */
  765. ds[i].d_count = cpu_to_le32(sg_dma_len(sg));
  766. ++sg;
  767. }
  768. sg_count -= IOCB_SEGS;
  769. while (sg_count > 0) {
  770. ++cmd->hdr.entry_cnt;
  771. cont = (struct Continuation_Entry *)
  772. &hostdata->req_cpu[in_ptr];
  773. in_ptr = (in_ptr + 1) & QLOGICISP_REQ_QUEUE_LEN;
  774. if (in_ptr == out_ptr) {
  775. printk("isp1020: unexpected request queue "
  776. "overflow\n");
  777. return 1;
  778. }
  779. TRACE("queue continuation", in_ptr, 0);
  780. cont->hdr.entry_type = ENTRY_CONTINUATION;
  781. cont->hdr.entry_cnt = 0;
  782. cont->hdr.sys_def_1 = 0;
  783. cont->hdr.flags = 0;
  784. #ifndef CONFIG_QL_ISP_A64
  785. cont->reserved = 0;
  786. #endif
  787. ds = cont->dataseg;
  788. n = sg_count;
  789. if (n > CONTINUATION_SEGS)
  790. n = CONTINUATION_SEGS;
  791. for (i = 0; i < n; ++i) {
  792. dma_addr = sg_dma_address(sg);
  793. ds[i].d_base = cpu_to_le32((u32) dma_addr);
  794. #ifdef CONFIG_QL_ISP_A64
  795. ds[i].d_base_hi = cpu_to_le32((u32)(dma_addr>>32));
  796. #endif /* CONFIG_QL_ISP_A64 */
  797. ds[i].d_count = cpu_to_le32(sg_dma_len(sg));
  798. ++sg;
  799. }
  800. sg_count -= n;
  801. }
  802. } else if (Cmnd->request_bufflen) {
  803. /*Cmnd->SCp.ptr = (char *)(unsigned long)*/
  804. dma_addr = pci_map_single(hostdata->pci_dev,
  805. Cmnd->request_buffer,
  806. Cmnd->request_bufflen,
  807. Cmnd->sc_data_direction);
  808. Cmnd->SCp.ptr = (char *)(unsigned long) dma_addr;
  809. cmd->dataseg[0].d_base =
  810. cpu_to_le32((u32) dma_addr);
  811. #ifdef CONFIG_QL_ISP_A64
  812. cmd->dataseg[0].d_base_hi =
  813. cpu_to_le32((u32) (dma_addr>>32));
  814. #endif /* CONFIG_QL_ISP_A64 */
  815. cmd->dataseg[0].d_count =
  816. cpu_to_le32((u32)Cmnd->request_bufflen);
  817. cmd->segment_cnt = cpu_to_le16(1);
  818. } else {
  819. cmd->dataseg[0].d_base = 0;
  820. #ifdef CONFIG_QL_ISP_A64
  821. cmd->dataseg[0].d_base_hi = 0;
  822. #endif /* CONFIG_QL_ISP_A64 */
  823. cmd->dataseg[0].d_count = 0;
  824. cmd->segment_cnt = cpu_to_le16(1); /* Shouldn't this be 0? */
  825. }
  826. /* Committed, record Scsi_Cmd so we can find it later. */
  827. cmd->handle = in_ptr;
  828. hostdata->cmd_slots[in_ptr] = Cmnd;
  829. isp_outw(in_ptr, host, MBOX4);
  830. hostdata->req_in_ptr = in_ptr;
  831. num_free = QLOGICISP_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
  832. host->can_queue = host->host_busy + num_free;
  833. host->sg_tablesize = QLOGICISP_MAX_SG(num_free);
  834. LEAVE("isp1020_queuecommand");
  835. return 0;
  836. }
  837. #define ASYNC_EVENT_INTERRUPT 0x01
  838. irqreturn_t do_isp1020_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
  839. {
  840. struct Scsi_Host *host = dev_id;
  841. unsigned long flags;
  842. spin_lock_irqsave(host->host_lock, flags);
  843. isp1020_intr_handler(irq, dev_id, regs);
  844. spin_unlock_irqrestore(host->host_lock, flags);
  845. return IRQ_HANDLED;
  846. }
  847. void isp1020_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
  848. {
  849. Scsi_Cmnd *Cmnd;
  850. struct Status_Entry *sts;
  851. struct Scsi_Host *host = dev_id;
  852. struct isp1020_hostdata *hostdata;
  853. u_int in_ptr, out_ptr;
  854. u_short status;
  855. ENTER_INTR("isp1020_intr_handler");
  856. hostdata = (struct isp1020_hostdata *) host->hostdata;
  857. DEBUG_INTR(printk("qlogicisp : interrupt on line %d\n", irq));
  858. if (!(isp_inw(host, PCI_INTF_STS) & 0x04)) {
  859. /* spurious interrupts can happen legally */
  860. DEBUG_INTR(printk("qlogicisp: got spurious interrupt\n"));
  861. return;
  862. }
  863. in_ptr = isp_inw(host, MBOX5);
  864. isp_outw(HCCR_CLEAR_RISC_INTR, host, HOST_HCCR);
  865. if ((isp_inw(host, PCI_SEMAPHORE) & ASYNC_EVENT_INTERRUPT)) {
  866. status = isp_inw(host, MBOX0);
  867. DEBUG_INTR(printk("qlogicisp : mbox completion status: %x\n",
  868. status));
  869. switch (status) {
  870. case ASYNC_SCSI_BUS_RESET:
  871. case EXECUTION_TIMEOUT_RESET:
  872. hostdata->send_marker = 1;
  873. break;
  874. case INVALID_COMMAND:
  875. case HOST_INTERFACE_ERROR:
  876. case COMMAND_ERROR:
  877. case COMMAND_PARAM_ERROR:
  878. printk("qlogicisp : bad mailbox return status\n");
  879. break;
  880. }
  881. isp_outw(0x0, host, PCI_SEMAPHORE);
  882. }
  883. out_ptr = hostdata->res_out_ptr;
  884. DEBUG_INTR(printk("qlogicisp : response queue update\n"));
  885. DEBUG_INTR(printk("qlogicisp : response queue depth %d\n",
  886. QUEUE_DEPTH(in_ptr, out_ptr, RES_QUEUE_LEN)));
  887. while (out_ptr != in_ptr) {
  888. u_int cmd_slot;
  889. sts = (struct Status_Entry *) &hostdata->res_cpu[out_ptr];
  890. out_ptr = (out_ptr + 1) & RES_QUEUE_LEN;
  891. cmd_slot = sts->handle;
  892. Cmnd = hostdata->cmd_slots[cmd_slot];
  893. hostdata->cmd_slots[cmd_slot] = NULL;
  894. TRACE("done", out_ptr, Cmnd);
  895. if (le16_to_cpu(sts->completion_status) == CS_RESET_OCCURRED
  896. || le16_to_cpu(sts->completion_status) == CS_ABORTED
  897. || (le16_to_cpu(sts->status_flags) & STF_BUS_RESET))
  898. hostdata->send_marker = 1;
  899. if (le16_to_cpu(sts->state_flags) & SF_GOT_SENSE)
  900. memcpy(Cmnd->sense_buffer, sts->req_sense_data,
  901. sizeof(Cmnd->sense_buffer));
  902. DEBUG_INTR(isp1020_print_status_entry(sts));
  903. if (sts->hdr.entry_type == ENTRY_STATUS)
  904. Cmnd->result = isp1020_return_status(sts);
  905. else
  906. Cmnd->result = DID_ERROR << 16;
  907. if (Cmnd->use_sg)
  908. pci_unmap_sg(hostdata->pci_dev,
  909. (struct scatterlist *)Cmnd->buffer,
  910. Cmnd->use_sg,
  911. Cmnd->sc_data_direction);
  912. else if (Cmnd->request_bufflen)
  913. pci_unmap_single(hostdata->pci_dev,
  914. #ifdef CONFIG_QL_ISP_A64
  915. (dma_addr_t)((long)Cmnd->SCp.ptr),
  916. #else
  917. (u32)((long)Cmnd->SCp.ptr),
  918. #endif
  919. Cmnd->request_bufflen,
  920. Cmnd->sc_data_direction);
  921. isp_outw(out_ptr, host, MBOX5);
  922. (*Cmnd->scsi_done)(Cmnd);
  923. }
  924. hostdata->res_out_ptr = out_ptr;
  925. LEAVE_INTR("isp1020_intr_handler");
  926. }
  927. static int isp1020_return_status(struct Status_Entry *sts)
  928. {
  929. int host_status = DID_ERROR;
  930. #if DEBUG_ISP1020_INTR
  931. static char *reason[] = {
  932. "DID_OK",
  933. "DID_NO_CONNECT",
  934. "DID_BUS_BUSY",
  935. "DID_TIME_OUT",
  936. "DID_BAD_TARGET",
  937. "DID_ABORT",
  938. "DID_PARITY",
  939. "DID_ERROR",
  940. "DID_RESET",
  941. "DID_BAD_INTR"
  942. };
  943. #endif /* DEBUG_ISP1020_INTR */
  944. ENTER("isp1020_return_status");
  945. DEBUG(printk("qlogicisp : completion status = 0x%04x\n",
  946. le16_to_cpu(sts->completion_status)));
  947. switch(le16_to_cpu(sts->completion_status)) {
  948. case CS_COMPLETE:
  949. host_status = DID_OK;
  950. break;
  951. case CS_INCOMPLETE:
  952. if (!(le16_to_cpu(sts->state_flags) & SF_GOT_BUS))
  953. host_status = DID_NO_CONNECT;
  954. else if (!(le16_to_cpu(sts->state_flags) & SF_GOT_TARGET))
  955. host_status = DID_BAD_TARGET;
  956. else if (!(le16_to_cpu(sts->state_flags) & SF_SENT_CDB))
  957. host_status = DID_ERROR;
  958. else if (!(le16_to_cpu(sts->state_flags) & SF_TRANSFERRED_DATA))
  959. host_status = DID_ERROR;
  960. else if (!(le16_to_cpu(sts->state_flags) & SF_GOT_STATUS))
  961. host_status = DID_ERROR;
  962. else if (!(le16_to_cpu(sts->state_flags) & SF_GOT_SENSE))
  963. host_status = DID_ERROR;
  964. break;
  965. case CS_DMA_ERROR:
  966. case CS_TRANSPORT_ERROR:
  967. host_status = DID_ERROR;
  968. break;
  969. case CS_RESET_OCCURRED:
  970. host_status = DID_RESET;
  971. break;
  972. case CS_ABORTED:
  973. host_status = DID_ABORT;
  974. break;
  975. case CS_TIMEOUT:
  976. host_status = DID_TIME_OUT;
  977. break;
  978. case CS_DATA_OVERRUN:
  979. case CS_COMMAND_OVERRUN:
  980. case CS_STATUS_OVERRUN:
  981. case CS_BAD_MESSAGE:
  982. case CS_NO_MESSAGE_OUT:
  983. case CS_EXT_ID_FAILED:
  984. case CS_IDE_MSG_FAILED:
  985. case CS_ABORT_MSG_FAILED:
  986. case CS_NOP_MSG_FAILED:
  987. case CS_PARITY_ERROR_MSG_FAILED:
  988. case CS_DEVICE_RESET_MSG_FAILED:
  989. case CS_ID_MSG_FAILED:
  990. case CS_UNEXP_BUS_FREE:
  991. host_status = DID_ERROR;
  992. break;
  993. case CS_DATA_UNDERRUN:
  994. host_status = DID_OK;
  995. break;
  996. default:
  997. printk("qlogicisp : unknown completion status 0x%04x\n",
  998. le16_to_cpu(sts->completion_status));
  999. host_status = DID_ERROR;
  1000. break;
  1001. }
  1002. DEBUG_INTR(printk("qlogicisp : host status (%s) scsi status %x\n",
  1003. reason[host_status], le16_to_cpu(sts->scsi_status)));
  1004. LEAVE("isp1020_return_status");
  1005. return (le16_to_cpu(sts->scsi_status) & STATUS_MASK) | (host_status << 16);
  1006. }
  1007. static int isp1020_biosparam(struct scsi_device *sdev, struct block_device *n,
  1008. sector_t capacity, int ip[])
  1009. {
  1010. int size = capacity;
  1011. ENTER("isp1020_biosparam");
  1012. ip[0] = 64;
  1013. ip[1] = 32;
  1014. ip[2] = size >> 11;
  1015. if (ip[2] > 1024) {
  1016. ip[0] = 255;
  1017. ip[1] = 63;
  1018. ip[2] = size / (ip[0] * ip[1]);
  1019. #if 0
  1020. if (ip[2] > 1023)
  1021. ip[2] = 1023;
  1022. #endif
  1023. }
  1024. LEAVE("isp1020_biosparam");
  1025. return 0;
  1026. }
  1027. static int isp1020_reset_hardware(struct Scsi_Host *host)
  1028. {
  1029. u_short param[6];
  1030. int loop_count;
  1031. ENTER("isp1020_reset_hardware");
  1032. isp_outw(ISP_RESET, host, PCI_INTF_CTL);
  1033. udelay(100);
  1034. isp_outw(HCCR_RESET, host, HOST_HCCR);
  1035. udelay(100);
  1036. isp_outw(HCCR_RELEASE, host, HOST_HCCR);
  1037. isp_outw(HCCR_BIOS_DISABLE, host, HOST_HCCR);
  1038. loop_count = DEFAULT_LOOP_COUNT;
  1039. while (--loop_count && isp_inw(host, HOST_HCCR) == RISC_BUSY) {
  1040. barrier();
  1041. cpu_relax();
  1042. }
  1043. if (!loop_count)
  1044. printk("qlogicisp: reset_hardware loop timeout\n");
  1045. isp_outw(0, host, ISP_CFG1);
  1046. #if DEBUG_ISP1020
  1047. printk("qlogicisp : mbox 0 0x%04x \n", isp_inw(host, MBOX0));
  1048. printk("qlogicisp : mbox 1 0x%04x \n", isp_inw(host, MBOX1));
  1049. printk("qlogicisp : mbox 2 0x%04x \n", isp_inw(host, MBOX2));
  1050. printk("qlogicisp : mbox 3 0x%04x \n", isp_inw(host, MBOX3));
  1051. printk("qlogicisp : mbox 4 0x%04x \n", isp_inw(host, MBOX4));
  1052. printk("qlogicisp : mbox 5 0x%04x \n", isp_inw(host, MBOX5));
  1053. #endif /* DEBUG_ISP1020 */
  1054. param[0] = MBOX_NO_OP;
  1055. isp1020_mbox_command(host, param);
  1056. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1057. printk("qlogicisp : NOP test failed\n");
  1058. return 1;
  1059. }
  1060. DEBUG(printk("qlogicisp : loading risc ram\n"));
  1061. #if RELOAD_FIRMWARE
  1062. for (loop_count = 0; loop_count < risc_code_length01; loop_count++) {
  1063. param[0] = MBOX_WRITE_RAM_WORD;
  1064. param[1] = risc_code_addr01 + loop_count;
  1065. param[2] = risc_code01[loop_count];
  1066. isp1020_mbox_command(host, param);
  1067. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1068. printk("qlogicisp : firmware load failure at %d\n",
  1069. loop_count);
  1070. return 1;
  1071. }
  1072. }
  1073. #endif /* RELOAD_FIRMWARE */
  1074. DEBUG(printk("qlogicisp : verifying checksum\n"));
  1075. param[0] = MBOX_VERIFY_CHECKSUM;
  1076. param[1] = risc_code_addr01;
  1077. isp1020_mbox_command(host, param);
  1078. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1079. printk("qlogicisp : ram checksum failure\n");
  1080. return 1;
  1081. }
  1082. DEBUG(printk("qlogicisp : executing firmware\n"));
  1083. param[0] = MBOX_EXEC_FIRMWARE;
  1084. param[1] = risc_code_addr01;
  1085. isp1020_mbox_command(host, param);
  1086. param[0] = MBOX_ABOUT_FIRMWARE;
  1087. isp1020_mbox_command(host, param);
  1088. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1089. printk("qlogicisp : about firmware failure\n");
  1090. return 1;
  1091. }
  1092. DEBUG(printk("qlogicisp : firmware major revision %d\n", param[1]));
  1093. DEBUG(printk("qlogicisp : firmware minor revision %d\n", param[2]));
  1094. LEAVE("isp1020_reset_hardware");
  1095. return 0;
  1096. }
  1097. static int isp1020_init(struct Scsi_Host *sh)
  1098. {
  1099. u_long io_base, mem_base, io_flags, mem_flags;
  1100. struct isp1020_hostdata *hostdata;
  1101. u_char revision;
  1102. u_int irq;
  1103. u_short command;
  1104. struct pci_dev *pdev;
  1105. ENTER("isp1020_init");
  1106. hostdata = (struct isp1020_hostdata *) sh->hostdata;
  1107. pdev = hostdata->pci_dev;
  1108. if (pci_read_config_word(pdev, PCI_COMMAND, &command)
  1109. || pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision))
  1110. {
  1111. printk("qlogicisp : error reading PCI configuration\n");
  1112. return 1;
  1113. }
  1114. io_base = pci_resource_start(pdev, 0);
  1115. mem_base = pci_resource_start(pdev, 1);
  1116. io_flags = pci_resource_flags(pdev, 0);
  1117. mem_flags = pci_resource_flags(pdev, 1);
  1118. irq = pdev->irq;
  1119. if (pdev->vendor != PCI_VENDOR_ID_QLOGIC) {
  1120. printk("qlogicisp : 0x%04x is not QLogic vendor ID\n",
  1121. pdev->vendor);
  1122. return 1;
  1123. }
  1124. if (pdev->device != PCI_DEVICE_ID_QLOGIC_ISP1020) {
  1125. printk("qlogicisp : 0x%04x does not match ISP1020 device id\n",
  1126. pdev->device);
  1127. return 1;
  1128. }
  1129. #ifdef __alpha__
  1130. /* Force ALPHA to use bus I/O and not bus MEM.
  1131. This is to avoid having to use HAE_MEM registers,
  1132. which is broken on some platforms and with SMP. */
  1133. command &= ~PCI_COMMAND_MEMORY;
  1134. #endif
  1135. sh->io_port = io_base;
  1136. if (!request_region(sh->io_port, 0xff, "qlogicisp")) {
  1137. printk("qlogicisp : i/o region 0x%lx-0x%lx already "
  1138. "in use\n",
  1139. sh->io_port, sh->io_port + 0xff);
  1140. return 1;
  1141. }
  1142. if ((command & PCI_COMMAND_MEMORY) &&
  1143. ((mem_flags & 1) == 0)) {
  1144. hostdata->memaddr = ioremap(mem_base, PAGE_SIZE);
  1145. if (!hostdata->memaddr) {
  1146. printk("qlogicisp : i/o remapping failed.\n");
  1147. goto out_release;
  1148. }
  1149. } else {
  1150. if (command & PCI_COMMAND_IO && (io_flags & 3) != 1) {
  1151. printk("qlogicisp : i/o mapping is disabled\n");
  1152. goto out_release;
  1153. }
  1154. hostdata->memaddr = NULL; /* zero to signify no i/o mapping */
  1155. mem_base = 0;
  1156. }
  1157. if (revision != ISP1020_REV_ID)
  1158. printk("qlogicisp : new isp1020 revision ID (%d)\n", revision);
  1159. if (isp_inw(sh, PCI_ID_LOW) != PCI_VENDOR_ID_QLOGIC
  1160. || isp_inw(sh, PCI_ID_HIGH) != PCI_DEVICE_ID_QLOGIC_ISP1020)
  1161. {
  1162. printk("qlogicisp : can't decode %s address space 0x%lx\n",
  1163. (io_base ? "I/O" : "MEM"),
  1164. (io_base ? io_base : mem_base));
  1165. goto out_unmap;
  1166. }
  1167. hostdata->revision = revision;
  1168. sh->irq = irq;
  1169. sh->max_id = MAX_TARGETS;
  1170. sh->max_lun = MAX_LUNS;
  1171. hostdata->res_cpu = pci_alloc_consistent(hostdata->pci_dev,
  1172. QSIZE(RES_QUEUE_LEN),
  1173. &hostdata->res_dma);
  1174. if (hostdata->res_cpu == NULL) {
  1175. printk("qlogicisp : can't allocate response queue\n");
  1176. goto out_unmap;
  1177. }
  1178. hostdata->req_cpu = pci_alloc_consistent(hostdata->pci_dev,
  1179. QSIZE(QLOGICISP_REQ_QUEUE_LEN),
  1180. &hostdata->req_dma);
  1181. if (hostdata->req_cpu == NULL) {
  1182. pci_free_consistent(hostdata->pci_dev,
  1183. QSIZE(RES_QUEUE_LEN),
  1184. hostdata->res_cpu,
  1185. hostdata->res_dma);
  1186. printk("qlogicisp : can't allocate request queue\n");
  1187. goto out_unmap;
  1188. }
  1189. pci_set_master(pdev);
  1190. LEAVE("isp1020_init");
  1191. return 0;
  1192. out_unmap:
  1193. iounmap(hostdata->memaddr);
  1194. out_release:
  1195. release_region(sh->io_port, 0xff);
  1196. return 1;
  1197. }
  1198. #if USE_NVRAM_DEFAULTS
  1199. static int isp1020_get_defaults(struct Scsi_Host *host)
  1200. {
  1201. int i;
  1202. u_short value;
  1203. struct isp1020_hostdata *hostdata =
  1204. (struct isp1020_hostdata *) host->hostdata;
  1205. ENTER("isp1020_get_defaults");
  1206. if (!isp1020_verify_nvram(host)) {
  1207. printk("qlogicisp : nvram checksum failure\n");
  1208. printk("qlogicisp : attempting to use default parameters\n");
  1209. return isp1020_set_defaults(host);
  1210. }
  1211. value = isp1020_read_nvram_word(host, 2);
  1212. hostdata->host_param.fifo_threshold = (value >> 8) & 0x03;
  1213. hostdata->host_param.host_adapter_enable = (value >> 11) & 0x01;
  1214. hostdata->host_param.initiator_scsi_id = (value >> 12) & 0x0f;
  1215. value = isp1020_read_nvram_word(host, 3);
  1216. hostdata->host_param.bus_reset_delay = value & 0xff;
  1217. hostdata->host_param.retry_count = value >> 8;
  1218. value = isp1020_read_nvram_word(host, 4);
  1219. hostdata->host_param.retry_delay = value & 0xff;
  1220. hostdata->host_param.async_data_setup_time = (value >> 8) & 0x0f;
  1221. hostdata->host_param.req_ack_active_negation = (value >> 12) & 0x01;
  1222. hostdata->host_param.data_line_active_negation = (value >> 13) & 0x01;
  1223. hostdata->host_param.data_dma_burst_enable = (value >> 14) & 0x01;
  1224. hostdata->host_param.command_dma_burst_enable = (value >> 15);
  1225. value = isp1020_read_nvram_word(host, 5);
  1226. hostdata->host_param.tag_aging = value & 0xff;
  1227. value = isp1020_read_nvram_word(host, 6);
  1228. hostdata->host_param.selection_timeout = value & 0xffff;
  1229. value = isp1020_read_nvram_word(host, 7);
  1230. hostdata->host_param.max_queue_depth = value & 0xffff;
  1231. #if DEBUG_ISP1020_SETUP
  1232. printk("qlogicisp : fifo threshold=%d\n",
  1233. hostdata->host_param.fifo_threshold);
  1234. printk("qlogicisp : initiator scsi id=%d\n",
  1235. hostdata->host_param.initiator_scsi_id);
  1236. printk("qlogicisp : bus reset delay=%d\n",
  1237. hostdata->host_param.bus_reset_delay);
  1238. printk("qlogicisp : retry count=%d\n",
  1239. hostdata->host_param.retry_count);
  1240. printk("qlogicisp : retry delay=%d\n",
  1241. hostdata->host_param.retry_delay);
  1242. printk("qlogicisp : async data setup time=%d\n",
  1243. hostdata->host_param.async_data_setup_time);
  1244. printk("qlogicisp : req/ack active negation=%d\n",
  1245. hostdata->host_param.req_ack_active_negation);
  1246. printk("qlogicisp : data line active negation=%d\n",
  1247. hostdata->host_param.data_line_active_negation);
  1248. printk("qlogicisp : data DMA burst enable=%d\n",
  1249. hostdata->host_param.data_dma_burst_enable);
  1250. printk("qlogicisp : command DMA burst enable=%d\n",
  1251. hostdata->host_param.command_dma_burst_enable);
  1252. printk("qlogicisp : tag age limit=%d\n",
  1253. hostdata->host_param.tag_aging);
  1254. printk("qlogicisp : selection timeout limit=%d\n",
  1255. hostdata->host_param.selection_timeout);
  1256. printk("qlogicisp : max queue depth=%d\n",
  1257. hostdata->host_param.max_queue_depth);
  1258. #endif /* DEBUG_ISP1020_SETUP */
  1259. for (i = 0; i < MAX_TARGETS; i++) {
  1260. value = isp1020_read_nvram_word(host, 14 + i * 3);
  1261. hostdata->dev_param[i].device_flags = value & 0xff;
  1262. hostdata->dev_param[i].execution_throttle = value >> 8;
  1263. value = isp1020_read_nvram_word(host, 15 + i * 3);
  1264. hostdata->dev_param[i].synchronous_period = value & 0xff;
  1265. hostdata->dev_param[i].synchronous_offset = (value >> 8) & 0x0f;
  1266. hostdata->dev_param[i].device_enable = (value >> 12) & 0x01;
  1267. #if DEBUG_ISP1020_SETUP
  1268. printk("qlogicisp : target 0x%02x\n", i);
  1269. printk("qlogicisp : device flags=0x%02x\n",
  1270. hostdata->dev_param[i].device_flags);
  1271. printk("qlogicisp : execution throttle=%d\n",
  1272. hostdata->dev_param[i].execution_throttle);
  1273. printk("qlogicisp : synchronous period=%d\n",
  1274. hostdata->dev_param[i].synchronous_period);
  1275. printk("qlogicisp : synchronous offset=%d\n",
  1276. hostdata->dev_param[i].synchronous_offset);
  1277. printk("qlogicisp : device enable=%d\n",
  1278. hostdata->dev_param[i].device_enable);
  1279. #endif /* DEBUG_ISP1020_SETUP */
  1280. }
  1281. LEAVE("isp1020_get_defaults");
  1282. return 0;
  1283. }
  1284. #define ISP1020_NVRAM_LEN 0x40
  1285. #define ISP1020_NVRAM_SIG1 0x5349
  1286. #define ISP1020_NVRAM_SIG2 0x2050
  1287. static int isp1020_verify_nvram(struct Scsi_Host *host)
  1288. {
  1289. int i;
  1290. u_short value;
  1291. u_char checksum = 0;
  1292. for (i = 0; i < ISP1020_NVRAM_LEN; i++) {
  1293. value = isp1020_read_nvram_word(host, i);
  1294. switch (i) {
  1295. case 0:
  1296. if (value != ISP1020_NVRAM_SIG1) return 0;
  1297. break;
  1298. case 1:
  1299. if (value != ISP1020_NVRAM_SIG2) return 0;
  1300. break;
  1301. case 2:
  1302. if ((value & 0xff) != 0x02) return 0;
  1303. break;
  1304. }
  1305. checksum += value & 0xff;
  1306. checksum += value >> 8;
  1307. }
  1308. return (checksum == 0);
  1309. }
  1310. #define NVRAM_DELAY() udelay(2) /* 2 microsecond delay */
  1311. u_short isp1020_read_nvram_word(struct Scsi_Host *host, u_short byte)
  1312. {
  1313. int i;
  1314. u_short value, output, input;
  1315. byte &= 0x3f; byte |= 0x0180;
  1316. for (i = 8; i >= 0; i--) {
  1317. output = ((byte >> i) & 0x1) ? 0x4 : 0x0;
  1318. isp_outw(output | 0x2, host, PCI_NVRAM); NVRAM_DELAY();
  1319. isp_outw(output | 0x3, host, PCI_NVRAM); NVRAM_DELAY();
  1320. isp_outw(output | 0x2, host, PCI_NVRAM); NVRAM_DELAY();
  1321. }
  1322. for (i = 0xf, value = 0; i >= 0; i--) {
  1323. value <<= 1;
  1324. isp_outw(0x3, host, PCI_NVRAM); NVRAM_DELAY();
  1325. input = isp_inw(host, PCI_NVRAM); NVRAM_DELAY();
  1326. isp_outw(0x2, host, PCI_NVRAM); NVRAM_DELAY();
  1327. if (input & 0x8) value |= 1;
  1328. }
  1329. isp_outw(0x0, host, PCI_NVRAM); NVRAM_DELAY();
  1330. return value;
  1331. }
  1332. #endif /* USE_NVRAM_DEFAULTS */
  1333. static int isp1020_set_defaults(struct Scsi_Host *host)
  1334. {
  1335. struct isp1020_hostdata *hostdata =
  1336. (struct isp1020_hostdata *) host->hostdata;
  1337. int i;
  1338. ENTER("isp1020_set_defaults");
  1339. hostdata->host_param.fifo_threshold = 2;
  1340. hostdata->host_param.host_adapter_enable = 1;
  1341. hostdata->host_param.initiator_scsi_id = 7;
  1342. hostdata->host_param.bus_reset_delay = 3;
  1343. hostdata->host_param.retry_count = 0;
  1344. hostdata->host_param.retry_delay = 1;
  1345. hostdata->host_param.async_data_setup_time = 6;
  1346. hostdata->host_param.req_ack_active_negation = 1;
  1347. hostdata->host_param.data_line_active_negation = 1;
  1348. hostdata->host_param.data_dma_burst_enable = 1;
  1349. hostdata->host_param.command_dma_burst_enable = 1;
  1350. hostdata->host_param.tag_aging = 8;
  1351. hostdata->host_param.selection_timeout = 250;
  1352. hostdata->host_param.max_queue_depth = 256;
  1353. for (i = 0; i < MAX_TARGETS; i++) {
  1354. hostdata->dev_param[i].device_flags = 0xfd;
  1355. hostdata->dev_param[i].execution_throttle = 16;
  1356. hostdata->dev_param[i].synchronous_period = 25;
  1357. hostdata->dev_param[i].synchronous_offset = 12;
  1358. hostdata->dev_param[i].device_enable = 1;
  1359. }
  1360. LEAVE("isp1020_set_defaults");
  1361. return 0;
  1362. }
  1363. static int isp1020_load_parameters(struct Scsi_Host *host)
  1364. {
  1365. int i, k;
  1366. #ifdef CONFIG_QL_ISP_A64
  1367. u_long queue_addr;
  1368. u_short param[8];
  1369. #else
  1370. u_int queue_addr;
  1371. u_short param[6];
  1372. #endif
  1373. u_short isp_cfg1, hwrev;
  1374. struct isp1020_hostdata *hostdata =
  1375. (struct isp1020_hostdata *) host->hostdata;
  1376. ENTER("isp1020_load_parameters");
  1377. hwrev = isp_inw(host, ISP_CFG0) & ISP_CFG0_HWMSK;
  1378. isp_cfg1 = ISP_CFG1_F64 | ISP_CFG1_BENAB;
  1379. if (hwrev == ISP_CFG0_1040A) {
  1380. /* Busted fifo, says mjacob. */
  1381. isp_cfg1 &= ISP_CFG1_BENAB;
  1382. }
  1383. isp_outw(isp_inw(host, ISP_CFG1) | isp_cfg1, host, ISP_CFG1);
  1384. isp_outw(isp_inw(host, CDMA_CONF) | DMA_CONF_BENAB, host, CDMA_CONF);
  1385. isp_outw(isp_inw(host, DDMA_CONF) | DMA_CONF_BENAB, host, DDMA_CONF);
  1386. param[0] = MBOX_SET_INIT_SCSI_ID;
  1387. param[1] = hostdata->host_param.initiator_scsi_id;
  1388. isp1020_mbox_command(host, param);
  1389. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1390. printk("qlogicisp : set initiator id failure\n");
  1391. return 1;
  1392. }
  1393. param[0] = MBOX_SET_RETRY_COUNT;
  1394. param[1] = hostdata->host_param.retry_count;
  1395. param[2] = hostdata->host_param.retry_delay;
  1396. isp1020_mbox_command(host, param);
  1397. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1398. printk("qlogicisp : set retry count failure\n");
  1399. return 1;
  1400. }
  1401. param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
  1402. param[1] = hostdata->host_param.async_data_setup_time;
  1403. isp1020_mbox_command(host, param);
  1404. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1405. printk("qlogicisp : async data setup time failure\n");
  1406. return 1;
  1407. }
  1408. param[0] = MBOX_SET_ACTIVE_NEG_STATE;
  1409. param[1] = (hostdata->host_param.req_ack_active_negation << 4)
  1410. | (hostdata->host_param.data_line_active_negation << 5);
  1411. isp1020_mbox_command(host, param);
  1412. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1413. printk("qlogicisp : set active negation state failure\n");
  1414. return 1;
  1415. }
  1416. param[0] = MBOX_SET_PCI_CONTROL_PARAMS;
  1417. param[1] = hostdata->host_param.data_dma_burst_enable << 1;
  1418. param[2] = hostdata->host_param.command_dma_burst_enable << 1;
  1419. isp1020_mbox_command(host, param);
  1420. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1421. printk("qlogicisp : set pci control parameter failure\n");
  1422. return 1;
  1423. }
  1424. param[0] = MBOX_SET_TAG_AGE_LIMIT;
  1425. param[1] = hostdata->host_param.tag_aging;
  1426. isp1020_mbox_command(host, param);
  1427. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1428. printk("qlogicisp : set tag age limit failure\n");
  1429. return 1;
  1430. }
  1431. param[0] = MBOX_SET_SELECT_TIMEOUT;
  1432. param[1] = hostdata->host_param.selection_timeout;
  1433. isp1020_mbox_command(host, param);
  1434. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1435. printk("qlogicisp : set selection timeout failure\n");
  1436. return 1;
  1437. }
  1438. for (i = 0; i < MAX_TARGETS; i++) {
  1439. if (!hostdata->dev_param[i].device_enable)
  1440. continue;
  1441. param[0] = MBOX_SET_TARGET_PARAMS;
  1442. param[1] = i << 8;
  1443. param[2] = hostdata->dev_param[i].device_flags << 8;
  1444. param[3] = (hostdata->dev_param[i].synchronous_offset << 8)
  1445. | hostdata->dev_param[i].synchronous_period;
  1446. isp1020_mbox_command(host, param);
  1447. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1448. printk("qlogicisp : set target parameter failure\n");
  1449. return 1;
  1450. }
  1451. for (k = 0; k < MAX_LUNS; k++) {
  1452. param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
  1453. param[1] = (i << 8) | k;
  1454. param[2] = hostdata->host_param.max_queue_depth;
  1455. param[3] = hostdata->dev_param[i].execution_throttle;
  1456. isp1020_mbox_command(host, param);
  1457. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1458. printk("qlogicisp : set device queue "
  1459. "parameter failure\n");
  1460. return 1;
  1461. }
  1462. }
  1463. }
  1464. queue_addr = hostdata->res_dma;
  1465. #ifdef CONFIG_QL_ISP_A64
  1466. param[0] = MBOX_CMD_INIT_RESPONSE_QUEUE_64;
  1467. #else
  1468. param[0] = MBOX_INIT_RES_QUEUE;
  1469. #endif
  1470. param[1] = RES_QUEUE_LEN + 1;
  1471. param[2] = (u_short) (queue_addr >> 16);
  1472. param[3] = (u_short) (queue_addr & 0xffff);
  1473. param[4] = 0;
  1474. param[5] = 0;
  1475. #ifdef CONFIG_QL_ISP_A64
  1476. param[6] = (u_short) (queue_addr >> 48);
  1477. param[7] = (u_short) (queue_addr >> 32);
  1478. #endif
  1479. isp1020_mbox_command(host, param);
  1480. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1481. printk("qlogicisp : set response queue failure\n");
  1482. return 1;
  1483. }
  1484. queue_addr = hostdata->req_dma;
  1485. #ifdef CONFIG_QL_ISP_A64
  1486. param[0] = MBOX_CMD_INIT_REQUEST_QUEUE_64;
  1487. #else
  1488. param[0] = MBOX_INIT_REQ_QUEUE;
  1489. #endif
  1490. param[1] = QLOGICISP_REQ_QUEUE_LEN + 1;
  1491. param[2] = (u_short) (queue_addr >> 16);
  1492. param[3] = (u_short) (queue_addr & 0xffff);
  1493. param[4] = 0;
  1494. #ifdef CONFIG_QL_ISP_A64
  1495. param[5] = 0;
  1496. param[6] = (u_short) (queue_addr >> 48);
  1497. param[7] = (u_short) (queue_addr >> 32);
  1498. #endif
  1499. isp1020_mbox_command(host, param);
  1500. if (param[0] != MBOX_COMMAND_COMPLETE) {
  1501. printk("qlogicisp : set request queue failure\n");
  1502. return 1;
  1503. }
  1504. LEAVE("isp1020_load_parameters");
  1505. return 0;
  1506. }
  1507. /*
  1508. * currently, this is only called during initialization or abort/reset,
  1509. * at which times interrupts are disabled, so polling is OK, I guess...
  1510. */
  1511. static int isp1020_mbox_command(struct Scsi_Host *host, u_short param[])
  1512. {
  1513. int loop_count;
  1514. if (mbox_param[param[0]] == 0)
  1515. return 1;
  1516. loop_count = DEFAULT_LOOP_COUNT;
  1517. while (--loop_count && isp_inw(host, HOST_HCCR) & 0x0080) {
  1518. barrier();
  1519. cpu_relax();
  1520. }
  1521. if (!loop_count)
  1522. printk("qlogicisp: mbox_command loop timeout #1\n");
  1523. switch(mbox_param[param[0]] >> 4) {
  1524. case 8: isp_outw(param[7], host, MBOX7);
  1525. case 7: isp_outw(param[6], host, MBOX6);
  1526. case 6: isp_outw(param[5], host, MBOX5);
  1527. case 5: isp_outw(param[4], host, MBOX4);
  1528. case 4: isp_outw(param[3], host, MBOX3);
  1529. case 3: isp_outw(param[2], host, MBOX2);
  1530. case 2: isp_outw(param[1], host, MBOX1);
  1531. case 1: isp_outw(param[0], host, MBOX0);
  1532. }
  1533. isp_outw(0x0, host, PCI_SEMAPHORE);
  1534. isp_outw(HCCR_CLEAR_RISC_INTR, host, HOST_HCCR);
  1535. isp_outw(HCCR_SET_HOST_INTR, host, HOST_HCCR);
  1536. loop_count = DEFAULT_LOOP_COUNT;
  1537. while (--loop_count && !(isp_inw(host, PCI_INTF_STS) & 0x04)) {
  1538. barrier();
  1539. cpu_relax();
  1540. }
  1541. if (!loop_count)
  1542. printk("qlogicisp: mbox_command loop timeout #2\n");
  1543. loop_count = DEFAULT_LOOP_COUNT;
  1544. while (--loop_count && isp_inw(host, MBOX0) == 0x04) {
  1545. barrier();
  1546. cpu_relax();
  1547. }
  1548. if (!loop_count)
  1549. printk("qlogicisp: mbox_command loop timeout #3\n");
  1550. switch(mbox_param[param[0]] & 0xf) {
  1551. case 8: param[7] = isp_inw(host, MBOX7);
  1552. case 7: param[6] = isp_inw(host, MBOX6);
  1553. case 6: param[5] = isp_inw(host, MBOX5);
  1554. case 5: param[4] = isp_inw(host, MBOX4);
  1555. case 4: param[3] = isp_inw(host, MBOX3);
  1556. case 3: param[2] = isp_inw(host, MBOX2);
  1557. case 2: param[1] = isp_inw(host, MBOX1);
  1558. case 1: param[0] = isp_inw(host, MBOX0);
  1559. }
  1560. isp_outw(0x0, host, PCI_SEMAPHORE);
  1561. isp_outw(HCCR_CLEAR_RISC_INTR, host, HOST_HCCR);
  1562. return 0;
  1563. }
  1564. #if DEBUG_ISP1020_INTR
  1565. void isp1020_print_status_entry(struct Status_Entry *status)
  1566. {
  1567. int i;
  1568. printk("qlogicisp : entry count = 0x%02x, type = 0x%02x, flags = 0x%02x\n",
  1569. status->hdr.entry_cnt, status->hdr.entry_type, status->hdr.flags);
  1570. printk("qlogicisp : scsi status = 0x%04x, completion status = 0x%04x\n",
  1571. le16_to_cpu(status->scsi_status), le16_to_cpu(status->completion_status));
  1572. printk("qlogicisp : state flags = 0x%04x, status flags = 0x%04x\n",
  1573. le16_to_cpu(status->state_flags), le16_to_cpu(status->status_flags));
  1574. printk("qlogicisp : time = 0x%04x, request sense length = 0x%04x\n",
  1575. le16_to_cpu(status->time), le16_to_cpu(status->req_sense_len));
  1576. printk("qlogicisp : residual transfer length = 0x%08x\n",
  1577. le32_to_cpu(status->residual));
  1578. for (i = 0; i < le16_to_cpu(status->req_sense_len); i++)
  1579. printk("qlogicisp : sense data = 0x%02x\n", status->req_sense_data[i]);
  1580. }
  1581. #endif /* DEBUG_ISP1020_INTR */
  1582. #if DEBUG_ISP1020
  1583. void isp1020_print_scsi_cmd(Scsi_Cmnd *cmd)
  1584. {
  1585. int i;
  1586. printk("qlogicisp : target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
  1587. cmd->target, cmd->lun, cmd->cmd_len);
  1588. printk("qlogicisp : command = ");
  1589. for (i = 0; i < cmd->cmd_len; i++)
  1590. printk("0x%02x ", cmd->cmnd[i]);
  1591. printk("\n");
  1592. }
  1593. #endif /* DEBUG_ISP1020 */
  1594. MODULE_LICENSE("GPL");
  1595. static Scsi_Host_Template driver_template = {
  1596. .detect = isp1020_detect,
  1597. .release = isp1020_release,
  1598. .info = isp1020_info,
  1599. .queuecommand = isp1020_queuecommand,
  1600. .bios_param = isp1020_biosparam,
  1601. .can_queue = QLOGICISP_REQ_QUEUE_LEN,
  1602. .this_id = -1,
  1603. .sg_tablesize = QLOGICISP_MAX_SG(QLOGICISP_REQ_QUEUE_LEN),
  1604. .cmd_per_lun = 1,
  1605. .use_clustering = DISABLE_CLUSTERING,
  1606. };
  1607. #include "scsi_module.c"