qlogicfc.c 66 KB

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