qla_os.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2005 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/moduleparam.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/smp_lock.h>
  11. #include <linux/delay.h>
  12. #include <scsi/scsi_tcq.h>
  13. #include <scsi/scsicam.h>
  14. #include <scsi/scsi_transport.h>
  15. #include <scsi/scsi_transport_fc.h>
  16. /*
  17. * Driver version
  18. */
  19. char qla2x00_version_str[40];
  20. /*
  21. * SRB allocation cache
  22. */
  23. static kmem_cache_t *srb_cachep;
  24. /*
  25. * Ioctl related information.
  26. */
  27. static int num_hosts;
  28. int ql2xlogintimeout = 20;
  29. module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
  30. MODULE_PARM_DESC(ql2xlogintimeout,
  31. "Login timeout value in seconds.");
  32. int qlport_down_retry = 30;
  33. module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
  34. MODULE_PARM_DESC(qlport_down_retry,
  35. "Maximum number of command retries to a port that returns"
  36. "a PORT-DOWN status.");
  37. int ql2xplogiabsentdevice;
  38. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  39. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  40. "Option to enable PLOGI to devices that are not present after "
  41. "a Fabric scan. This is needed for several broken switches."
  42. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  43. int ql2xloginretrycount = 0;
  44. module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
  45. MODULE_PARM_DESC(ql2xloginretrycount,
  46. "Specify an alternate value for the NVRAM login retry count.");
  47. int ql2xfwloadbin=1;
  48. module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
  49. MODULE_PARM_DESC(ql2xfwloadbin,
  50. "Load ISP2xxx firmware image via hotplug.");
  51. static void qla2x00_free_device(scsi_qla_host_t *);
  52. static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
  53. int ql2xfdmienable;
  54. module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
  55. MODULE_PARM_DESC(ql2xfdmienable,
  56. "Enables FDMI registratons "
  57. "Default is 0 - no FDMI. 1 - perfom FDMI.");
  58. /*
  59. * SCSI host template entry points
  60. */
  61. static int qla2xxx_slave_configure(struct scsi_device * device);
  62. static int qla2xxx_slave_alloc(struct scsi_device *);
  63. static void qla2xxx_slave_destroy(struct scsi_device *);
  64. static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
  65. void (*fn)(struct scsi_cmnd *));
  66. static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
  67. void (*fn)(struct scsi_cmnd *));
  68. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  69. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  70. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  71. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  72. static int qla2x00_loop_reset(scsi_qla_host_t *ha);
  73. static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
  74. static int qla2x00_change_queue_depth(struct scsi_device *, int);
  75. static int qla2x00_change_queue_type(struct scsi_device *, int);
  76. static struct scsi_host_template qla2x00_driver_template = {
  77. .module = THIS_MODULE,
  78. .name = "qla2xxx",
  79. .queuecommand = qla2x00_queuecommand,
  80. .eh_abort_handler = qla2xxx_eh_abort,
  81. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  82. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  83. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  84. .slave_configure = qla2xxx_slave_configure,
  85. .slave_alloc = qla2xxx_slave_alloc,
  86. .slave_destroy = qla2xxx_slave_destroy,
  87. .change_queue_depth = qla2x00_change_queue_depth,
  88. .change_queue_type = qla2x00_change_queue_type,
  89. .this_id = -1,
  90. .cmd_per_lun = 3,
  91. .use_clustering = ENABLE_CLUSTERING,
  92. .sg_tablesize = SG_ALL,
  93. /*
  94. * The RISC allows for each command to transfer (2^32-1) bytes of data,
  95. * which equates to 0x800000 sectors.
  96. */
  97. .max_sectors = 0xFFFF,
  98. .shost_attrs = qla2x00_host_attrs,
  99. };
  100. static struct scsi_host_template qla24xx_driver_template = {
  101. .module = THIS_MODULE,
  102. .name = "qla2xxx",
  103. .queuecommand = qla24xx_queuecommand,
  104. .eh_abort_handler = qla2xxx_eh_abort,
  105. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  106. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  107. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  108. .slave_configure = qla2xxx_slave_configure,
  109. .slave_alloc = qla2xxx_slave_alloc,
  110. .slave_destroy = qla2xxx_slave_destroy,
  111. .change_queue_depth = qla2x00_change_queue_depth,
  112. .change_queue_type = qla2x00_change_queue_type,
  113. .this_id = -1,
  114. .cmd_per_lun = 3,
  115. .use_clustering = ENABLE_CLUSTERING,
  116. .sg_tablesize = SG_ALL,
  117. .max_sectors = 0xFFFF,
  118. .shost_attrs = qla2x00_host_attrs,
  119. };
  120. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  121. /* TODO Convert to inlines
  122. *
  123. * Timer routines
  124. */
  125. #define WATCH_INTERVAL 1 /* number of seconds */
  126. static void qla2x00_timer(scsi_qla_host_t *);
  127. static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
  128. void *, unsigned long);
  129. static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
  130. static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
  131. static inline void
  132. qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
  133. {
  134. init_timer(&ha->timer);
  135. ha->timer.expires = jiffies + interval * HZ;
  136. ha->timer.data = (unsigned long)ha;
  137. ha->timer.function = (void (*)(unsigned long))func;
  138. add_timer(&ha->timer);
  139. ha->timer_active = 1;
  140. }
  141. static inline void
  142. qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
  143. {
  144. mod_timer(&ha->timer, jiffies + interval * HZ);
  145. }
  146. static __inline__ void
  147. qla2x00_stop_timer(scsi_qla_host_t *ha)
  148. {
  149. del_timer_sync(&ha->timer);
  150. ha->timer_active = 0;
  151. }
  152. static int qla2x00_do_dpc(void *data);
  153. static void qla2x00_rst_aen(scsi_qla_host_t *);
  154. static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
  155. static void qla2x00_mem_free(scsi_qla_host_t *ha);
  156. static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
  157. static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
  158. static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
  159. void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
  160. /* -------------------------------------------------------------------------- */
  161. static char *
  162. qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
  163. {
  164. static char *pci_bus_modes[] = {
  165. "33", "66", "100", "133",
  166. };
  167. uint16_t pci_bus;
  168. strcpy(str, "PCI");
  169. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  170. if (pci_bus) {
  171. strcat(str, "-X (");
  172. strcat(str, pci_bus_modes[pci_bus]);
  173. } else {
  174. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  175. strcat(str, " (");
  176. strcat(str, pci_bus_modes[pci_bus]);
  177. }
  178. strcat(str, " MHz)");
  179. return (str);
  180. }
  181. static char *
  182. qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
  183. {
  184. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  185. uint32_t pci_bus;
  186. int pcie_reg;
  187. pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
  188. if (pcie_reg) {
  189. char lwstr[6];
  190. uint16_t pcie_lstat, lspeed, lwidth;
  191. pcie_reg += 0x12;
  192. pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
  193. lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
  194. lwidth = (pcie_lstat &
  195. (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
  196. strcpy(str, "PCIe (");
  197. if (lspeed == 1)
  198. strcat(str, "2.5Gb/s ");
  199. else
  200. strcat(str, "<unknown> ");
  201. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  202. strcat(str, lwstr);
  203. return str;
  204. }
  205. strcpy(str, "PCI");
  206. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  207. if (pci_bus == 0 || pci_bus == 8) {
  208. strcat(str, " (");
  209. strcat(str, pci_bus_modes[pci_bus >> 3]);
  210. } else {
  211. strcat(str, "-X ");
  212. if (pci_bus & BIT_2)
  213. strcat(str, "Mode 2");
  214. else
  215. strcat(str, "Mode 1");
  216. strcat(str, " (");
  217. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  218. }
  219. strcat(str, " MHz)");
  220. return str;
  221. }
  222. char *
  223. qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
  224. {
  225. char un_str[10];
  226. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  227. ha->fw_minor_version,
  228. ha->fw_subminor_version);
  229. if (ha->fw_attributes & BIT_9) {
  230. strcat(str, "FLX");
  231. return (str);
  232. }
  233. switch (ha->fw_attributes & 0xFF) {
  234. case 0x7:
  235. strcat(str, "EF");
  236. break;
  237. case 0x17:
  238. strcat(str, "TP");
  239. break;
  240. case 0x37:
  241. strcat(str, "IP");
  242. break;
  243. case 0x77:
  244. strcat(str, "VI");
  245. break;
  246. default:
  247. sprintf(un_str, "(%x)", ha->fw_attributes);
  248. strcat(str, un_str);
  249. break;
  250. }
  251. if (ha->fw_attributes & 0x100)
  252. strcat(str, "X");
  253. return (str);
  254. }
  255. char *
  256. qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
  257. {
  258. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  259. ha->fw_minor_version,
  260. ha->fw_subminor_version);
  261. if (ha->fw_attributes & BIT_0)
  262. strcat(str, "[Class 2] ");
  263. if (ha->fw_attributes & BIT_1)
  264. strcat(str, "[IP] ");
  265. if (ha->fw_attributes & BIT_2)
  266. strcat(str, "[Multi-ID] ");
  267. if (ha->fw_attributes & BIT_13)
  268. strcat(str, "[Experimental]");
  269. return str;
  270. }
  271. static inline srb_t *
  272. qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
  273. struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  274. {
  275. srb_t *sp;
  276. sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  277. if (!sp)
  278. return sp;
  279. atomic_set(&sp->ref_count, 1);
  280. sp->ha = ha;
  281. sp->fcport = fcport;
  282. sp->cmd = cmd;
  283. sp->flags = 0;
  284. CMD_SP(cmd) = (void *)sp;
  285. cmd->scsi_done = done;
  286. return sp;
  287. }
  288. static int
  289. qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  290. {
  291. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  292. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  293. srb_t *sp;
  294. int rval;
  295. if (!fcport) {
  296. cmd->result = DID_NO_CONNECT << 16;
  297. goto qc_fail_command;
  298. }
  299. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  300. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  301. atomic_read(&ha->loop_state) == LOOP_DEAD) {
  302. cmd->result = DID_NO_CONNECT << 16;
  303. goto qc_fail_command;
  304. }
  305. goto qc_host_busy;
  306. }
  307. spin_unlock_irq(ha->host->host_lock);
  308. sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
  309. if (!sp)
  310. goto qc_host_busy_lock;
  311. rval = qla2x00_start_scsi(sp);
  312. if (rval != QLA_SUCCESS)
  313. goto qc_host_busy_free_sp;
  314. spin_lock_irq(ha->host->host_lock);
  315. return 0;
  316. qc_host_busy_free_sp:
  317. qla2x00_sp_free_dma(ha, sp);
  318. mempool_free(sp, ha->srb_mempool);
  319. qc_host_busy_lock:
  320. spin_lock_irq(ha->host->host_lock);
  321. qc_host_busy:
  322. return SCSI_MLQUEUE_HOST_BUSY;
  323. qc_fail_command:
  324. done(cmd);
  325. return 0;
  326. }
  327. static int
  328. qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  329. {
  330. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  331. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  332. srb_t *sp;
  333. int rval;
  334. if (!fcport) {
  335. cmd->result = DID_NO_CONNECT << 16;
  336. goto qc24_fail_command;
  337. }
  338. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  339. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  340. atomic_read(&ha->loop_state) == LOOP_DEAD) {
  341. cmd->result = DID_NO_CONNECT << 16;
  342. goto qc24_fail_command;
  343. }
  344. goto qc24_host_busy;
  345. }
  346. spin_unlock_irq(ha->host->host_lock);
  347. sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
  348. if (!sp)
  349. goto qc24_host_busy_lock;
  350. rval = qla24xx_start_scsi(sp);
  351. if (rval != QLA_SUCCESS)
  352. goto qc24_host_busy_free_sp;
  353. spin_lock_irq(ha->host->host_lock);
  354. return 0;
  355. qc24_host_busy_free_sp:
  356. qla2x00_sp_free_dma(ha, sp);
  357. mempool_free(sp, ha->srb_mempool);
  358. qc24_host_busy_lock:
  359. spin_lock_irq(ha->host->host_lock);
  360. qc24_host_busy:
  361. return SCSI_MLQUEUE_HOST_BUSY;
  362. qc24_fail_command:
  363. done(cmd);
  364. return 0;
  365. }
  366. /*
  367. * qla2x00_eh_wait_on_command
  368. * Waits for the command to be returned by the Firmware for some
  369. * max time.
  370. *
  371. * Input:
  372. * ha = actual ha whose done queue will contain the command
  373. * returned by firmware.
  374. * cmd = Scsi Command to wait on.
  375. * flag = Abort/Reset(Bus or Device Reset)
  376. *
  377. * Return:
  378. * Not Found : 0
  379. * Found : 1
  380. */
  381. static int
  382. qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
  383. {
  384. #define ABORT_POLLING_PERIOD 1000
  385. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  386. unsigned long wait_iter = ABORT_WAIT_ITER;
  387. int ret = QLA_SUCCESS;
  388. while (CMD_SP(cmd)) {
  389. msleep(ABORT_POLLING_PERIOD);
  390. if (--wait_iter)
  391. break;
  392. }
  393. if (CMD_SP(cmd))
  394. ret = QLA_FUNCTION_FAILED;
  395. return ret;
  396. }
  397. /*
  398. * qla2x00_wait_for_hba_online
  399. * Wait till the HBA is online after going through
  400. * <= MAX_RETRIES_OF_ISP_ABORT or
  401. * finally HBA is disabled ie marked offline
  402. *
  403. * Input:
  404. * ha - pointer to host adapter structure
  405. *
  406. * Note:
  407. * Does context switching-Release SPIN_LOCK
  408. * (if any) before calling this routine.
  409. *
  410. * Return:
  411. * Success (Adapter is online) : 0
  412. * Failed (Adapter is offline/disabled) : 1
  413. */
  414. static int
  415. qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
  416. {
  417. int return_status;
  418. unsigned long wait_online;
  419. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  420. while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
  421. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  422. test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
  423. ha->dpc_active) && time_before(jiffies, wait_online)) {
  424. msleep(1000);
  425. }
  426. if (ha->flags.online)
  427. return_status = QLA_SUCCESS;
  428. else
  429. return_status = QLA_FUNCTION_FAILED;
  430. DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
  431. return (return_status);
  432. }
  433. /*
  434. * qla2x00_wait_for_loop_ready
  435. * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
  436. * to be in LOOP_READY state.
  437. * Input:
  438. * ha - pointer to host adapter structure
  439. *
  440. * Note:
  441. * Does context switching-Release SPIN_LOCK
  442. * (if any) before calling this routine.
  443. *
  444. *
  445. * Return:
  446. * Success (LOOP_READY) : 0
  447. * Failed (LOOP_NOT_READY) : 1
  448. */
  449. static inline int
  450. qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
  451. {
  452. int return_status = QLA_SUCCESS;
  453. unsigned long loop_timeout ;
  454. /* wait for 5 min at the max for loop to be ready */
  455. loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  456. while ((!atomic_read(&ha->loop_down_timer) &&
  457. atomic_read(&ha->loop_state) == LOOP_DOWN) ||
  458. atomic_read(&ha->loop_state) != LOOP_READY) {
  459. msleep(1000);
  460. if (time_after_eq(jiffies, loop_timeout)) {
  461. return_status = QLA_FUNCTION_FAILED;
  462. break;
  463. }
  464. }
  465. return (return_status);
  466. }
  467. /**************************************************************************
  468. * qla2xxx_eh_abort
  469. *
  470. * Description:
  471. * The abort function will abort the specified command.
  472. *
  473. * Input:
  474. * cmd = Linux SCSI command packet to be aborted.
  475. *
  476. * Returns:
  477. * Either SUCCESS or FAILED.
  478. *
  479. * Note:
  480. **************************************************************************/
  481. int
  482. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  483. {
  484. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  485. srb_t *sp;
  486. int ret, i;
  487. unsigned int id, lun;
  488. unsigned long serial;
  489. unsigned long flags;
  490. if (!CMD_SP(cmd))
  491. return FAILED;
  492. ret = FAILED;
  493. id = cmd->device->id;
  494. lun = cmd->device->lun;
  495. serial = cmd->serial_number;
  496. /* Check active list for command command. */
  497. spin_lock_irqsave(&ha->hardware_lock, flags);
  498. for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
  499. sp = ha->outstanding_cmds[i];
  500. if (sp == NULL)
  501. continue;
  502. if (sp->cmd != cmd)
  503. continue;
  504. DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
  505. "sp->state=%x\n", __func__, ha->host_no, sp, serial,
  506. sp->state));
  507. DEBUG3(qla2x00_print_scsi_cmd(cmd);)
  508. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  509. if (ha->isp_ops.abort_command(ha, sp)) {
  510. DEBUG2(printk("%s(%ld): abort_command "
  511. "mbx failed.\n", __func__, ha->host_no));
  512. } else {
  513. DEBUG3(printk("%s(%ld): abort_command "
  514. "mbx success.\n", __func__, ha->host_no));
  515. ret = SUCCESS;
  516. }
  517. spin_lock_irqsave(&ha->hardware_lock, flags);
  518. break;
  519. }
  520. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  521. /* Wait for the command to be returned. */
  522. if (ret == SUCCESS) {
  523. if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
  524. qla_printk(KERN_ERR, ha,
  525. "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
  526. "%x.\n", ha->host_no, id, lun, serial, ret);
  527. }
  528. }
  529. qla_printk(KERN_INFO, ha,
  530. "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
  531. id, lun, serial, ret);
  532. return ret;
  533. }
  534. /**************************************************************************
  535. * qla2x00_eh_wait_for_pending_target_commands
  536. *
  537. * Description:
  538. * Waits for all the commands to come back from the specified target.
  539. *
  540. * Input:
  541. * ha - pointer to scsi_qla_host structure.
  542. * t - target
  543. * Returns:
  544. * Either SUCCESS or FAILED.
  545. *
  546. * Note:
  547. **************************************************************************/
  548. static int
  549. qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
  550. {
  551. int cnt;
  552. int status;
  553. srb_t *sp;
  554. struct scsi_cmnd *cmd;
  555. unsigned long flags;
  556. status = 0;
  557. /*
  558. * Waiting for all commands for the designated target in the active
  559. * array
  560. */
  561. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  562. spin_lock_irqsave(&ha->hardware_lock, flags);
  563. sp = ha->outstanding_cmds[cnt];
  564. if (sp) {
  565. cmd = sp->cmd;
  566. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  567. if (cmd->device->id == t) {
  568. if (!qla2x00_eh_wait_on_command(ha, cmd)) {
  569. status = 1;
  570. break;
  571. }
  572. }
  573. } else {
  574. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  575. }
  576. }
  577. return (status);
  578. }
  579. /**************************************************************************
  580. * qla2xxx_eh_device_reset
  581. *
  582. * Description:
  583. * The device reset function will reset the target and abort any
  584. * executing commands.
  585. *
  586. * NOTE: The use of SP is undefined within this context. Do *NOT*
  587. * attempt to use this value, even if you determine it is
  588. * non-null.
  589. *
  590. * Input:
  591. * cmd = Linux SCSI command packet of the command that cause the
  592. * bus device reset.
  593. *
  594. * Returns:
  595. * SUCCESS/FAILURE (defined as macro in scsi.h).
  596. *
  597. **************************************************************************/
  598. int
  599. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  600. {
  601. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  602. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  603. srb_t *sp;
  604. int ret;
  605. unsigned int id, lun;
  606. unsigned long serial;
  607. ret = FAILED;
  608. id = cmd->device->id;
  609. lun = cmd->device->lun;
  610. serial = cmd->serial_number;
  611. sp = (srb_t *) CMD_SP(cmd);
  612. if (!sp || !fcport)
  613. return ret;
  614. qla_printk(KERN_INFO, ha,
  615. "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
  616. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
  617. goto eh_dev_reset_done;
  618. if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
  619. if (qla2x00_device_reset(ha, fcport) == 0)
  620. ret = SUCCESS;
  621. #if defined(LOGOUT_AFTER_DEVICE_RESET)
  622. if (ret == SUCCESS) {
  623. if (fcport->flags & FC_FABRIC_DEVICE) {
  624. ha->isp_ops.fabric_logout(ha, fcport->loop_id);
  625. qla2x00_mark_device_lost(ha, fcport);
  626. }
  627. }
  628. #endif
  629. } else {
  630. DEBUG2(printk(KERN_INFO
  631. "%s failed: loop not ready\n",__func__);)
  632. }
  633. if (ret == FAILED) {
  634. DEBUG3(printk("%s(%ld): device reset failed\n",
  635. __func__, ha->host_no));
  636. qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
  637. __func__);
  638. goto eh_dev_reset_done;
  639. }
  640. /* Flush outstanding commands. */
  641. if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
  642. ret = FAILED;
  643. if (ret == FAILED) {
  644. DEBUG3(printk("%s(%ld): failed while waiting for commands\n",
  645. __func__, ha->host_no));
  646. qla_printk(KERN_INFO, ha,
  647. "%s: failed while waiting for commands\n", __func__);
  648. } else
  649. qla_printk(KERN_INFO, ha,
  650. "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no,
  651. id, lun);
  652. eh_dev_reset_done:
  653. return ret;
  654. }
  655. /**************************************************************************
  656. * qla2x00_eh_wait_for_pending_commands
  657. *
  658. * Description:
  659. * Waits for all the commands to come back from the specified host.
  660. *
  661. * Input:
  662. * ha - pointer to scsi_qla_host structure.
  663. *
  664. * Returns:
  665. * 1 : SUCCESS
  666. * 0 : FAILED
  667. *
  668. * Note:
  669. **************************************************************************/
  670. static int
  671. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
  672. {
  673. int cnt;
  674. int status;
  675. srb_t *sp;
  676. struct scsi_cmnd *cmd;
  677. unsigned long flags;
  678. status = 1;
  679. /*
  680. * Waiting for all commands for the designated target in the active
  681. * array
  682. */
  683. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  684. spin_lock_irqsave(&ha->hardware_lock, flags);
  685. sp = ha->outstanding_cmds[cnt];
  686. if (sp) {
  687. cmd = sp->cmd;
  688. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  689. status = qla2x00_eh_wait_on_command(ha, cmd);
  690. if (status == 0)
  691. break;
  692. }
  693. else {
  694. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  695. }
  696. }
  697. return (status);
  698. }
  699. /**************************************************************************
  700. * qla2xxx_eh_bus_reset
  701. *
  702. * Description:
  703. * The bus reset function will reset the bus and abort any executing
  704. * commands.
  705. *
  706. * Input:
  707. * cmd = Linux SCSI command packet of the command that cause the
  708. * bus reset.
  709. *
  710. * Returns:
  711. * SUCCESS/FAILURE (defined as macro in scsi.h).
  712. *
  713. **************************************************************************/
  714. int
  715. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  716. {
  717. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  718. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  719. srb_t *sp;
  720. int ret;
  721. unsigned int id, lun;
  722. unsigned long serial;
  723. ret = FAILED;
  724. id = cmd->device->id;
  725. lun = cmd->device->lun;
  726. serial = cmd->serial_number;
  727. sp = (srb_t *) CMD_SP(cmd);
  728. if (!sp || !fcport)
  729. return ret;
  730. qla_printk(KERN_INFO, ha,
  731. "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
  732. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
  733. DEBUG2(printk("%s failed:board disabled\n",__func__));
  734. goto eh_bus_reset_done;
  735. }
  736. if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
  737. if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
  738. ret = SUCCESS;
  739. }
  740. if (ret == FAILED)
  741. goto eh_bus_reset_done;
  742. /* Flush outstanding commands. */
  743. if (!qla2x00_eh_wait_for_pending_commands(ha))
  744. ret = FAILED;
  745. eh_bus_reset_done:
  746. qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
  747. (ret == FAILED) ? "failed" : "succeded");
  748. return ret;
  749. }
  750. /**************************************************************************
  751. * qla2xxx_eh_host_reset
  752. *
  753. * Description:
  754. * The reset function will reset the Adapter.
  755. *
  756. * Input:
  757. * cmd = Linux SCSI command packet of the command that cause the
  758. * adapter reset.
  759. *
  760. * Returns:
  761. * Either SUCCESS or FAILED.
  762. *
  763. * Note:
  764. **************************************************************************/
  765. int
  766. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  767. {
  768. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  769. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  770. srb_t *sp;
  771. int ret;
  772. unsigned int id, lun;
  773. unsigned long serial;
  774. ret = FAILED;
  775. id = cmd->device->id;
  776. lun = cmd->device->lun;
  777. serial = cmd->serial_number;
  778. sp = (srb_t *) CMD_SP(cmd);
  779. if (!sp || !fcport)
  780. return ret;
  781. qla_printk(KERN_INFO, ha,
  782. "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
  783. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
  784. goto eh_host_reset_lock;
  785. /*
  786. * Fixme-may be dpc thread is active and processing
  787. * loop_resync,so wait a while for it to
  788. * be completed and then issue big hammer.Otherwise
  789. * it may cause I/O failure as big hammer marks the
  790. * devices as lost kicking of the port_down_timer
  791. * while dpc is stuck for the mailbox to complete.
  792. */
  793. qla2x00_wait_for_loop_ready(ha);
  794. set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  795. if (qla2x00_abort_isp(ha)) {
  796. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  797. /* failed. schedule dpc to try */
  798. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  799. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
  800. goto eh_host_reset_lock;
  801. }
  802. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  803. /* Waiting for our command in done_queue to be returned to OS.*/
  804. if (qla2x00_eh_wait_for_pending_commands(ha))
  805. ret = SUCCESS;
  806. eh_host_reset_lock:
  807. qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
  808. (ret == FAILED) ? "failed" : "succeded");
  809. return ret;
  810. }
  811. /*
  812. * qla2x00_loop_reset
  813. * Issue loop reset.
  814. *
  815. * Input:
  816. * ha = adapter block pointer.
  817. *
  818. * Returns:
  819. * 0 = success
  820. */
  821. static int
  822. qla2x00_loop_reset(scsi_qla_host_t *ha)
  823. {
  824. int status = QLA_SUCCESS;
  825. struct fc_port *fcport;
  826. if (ha->flags.enable_lip_reset) {
  827. status = qla2x00_lip_reset(ha);
  828. }
  829. if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
  830. list_for_each_entry(fcport, &ha->fcports, list) {
  831. if (fcport->port_type != FCT_TARGET)
  832. continue;
  833. status = qla2x00_device_reset(ha, fcport);
  834. if (status != QLA_SUCCESS)
  835. break;
  836. }
  837. }
  838. if (status == QLA_SUCCESS &&
  839. ((!ha->flags.enable_target_reset &&
  840. !ha->flags.enable_lip_reset) ||
  841. ha->flags.enable_lip_full_login)) {
  842. status = qla2x00_full_login_lip(ha);
  843. }
  844. /* Issue marker command only when we are going to start the I/O */
  845. ha->marker_needed = 1;
  846. if (status) {
  847. /* Empty */
  848. DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
  849. __func__,
  850. ha->host_no);)
  851. } else {
  852. /* Empty */
  853. DEBUG3(printk("%s(%ld): exiting normally.\n",
  854. __func__,
  855. ha->host_no);)
  856. }
  857. return(status);
  858. }
  859. /*
  860. * qla2x00_device_reset
  861. * Issue bus device reset message to the target.
  862. *
  863. * Input:
  864. * ha = adapter block pointer.
  865. * t = SCSI ID.
  866. * TARGET_QUEUE_LOCK must be released.
  867. * ADAPTER_STATE_LOCK must be released.
  868. *
  869. * Context:
  870. * Kernel context.
  871. */
  872. static int
  873. qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
  874. {
  875. /* Abort Target command will clear Reservation */
  876. return ha->isp_ops.abort_target(reset_fcport);
  877. }
  878. static int
  879. qla2xxx_slave_alloc(struct scsi_device *sdev)
  880. {
  881. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  882. if (!rport)
  883. return -ENXIO;
  884. sdev->hostdata = rport->dd_data;
  885. return 0;
  886. }
  887. static int
  888. qla2xxx_slave_configure(struct scsi_device *sdev)
  889. {
  890. scsi_qla_host_t *ha = to_qla_host(sdev->host);
  891. struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
  892. if (sdev->tagged_supported)
  893. scsi_activate_tcq(sdev, 32);
  894. else
  895. scsi_deactivate_tcq(sdev, 32);
  896. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  897. return 0;
  898. }
  899. static void
  900. qla2xxx_slave_destroy(struct scsi_device *sdev)
  901. {
  902. sdev->hostdata = NULL;
  903. }
  904. static int
  905. qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
  906. {
  907. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  908. return sdev->queue_depth;
  909. }
  910. static int
  911. qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
  912. {
  913. if (sdev->tagged_supported) {
  914. scsi_set_tag_type(sdev, tag_type);
  915. if (tag_type)
  916. scsi_activate_tcq(sdev, sdev->queue_depth);
  917. else
  918. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  919. } else
  920. tag_type = 0;
  921. return tag_type;
  922. }
  923. /**
  924. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  925. * @ha: HA context
  926. *
  927. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  928. * supported addressing method.
  929. */
  930. static void
  931. qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
  932. {
  933. /* Assume a 32bit DMA mask. */
  934. ha->flags.enable_64bit_addressing = 0;
  935. if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
  936. /* Any upper-dword bits set? */
  937. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  938. !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
  939. /* Ok, a 64bit DMA mask is applicable. */
  940. ha->flags.enable_64bit_addressing = 1;
  941. ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
  942. ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
  943. return;
  944. }
  945. }
  946. dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
  947. pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
  948. }
  949. static int
  950. qla2x00_iospace_config(scsi_qla_host_t *ha)
  951. {
  952. unsigned long pio, pio_len, pio_flags;
  953. unsigned long mmio, mmio_len, mmio_flags;
  954. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  955. pio = pci_resource_start(ha->pdev, 0);
  956. pio_len = pci_resource_len(ha->pdev, 0);
  957. pio_flags = pci_resource_flags(ha->pdev, 0);
  958. if (pio_flags & IORESOURCE_IO) {
  959. if (pio_len < MIN_IOBASE_LEN) {
  960. qla_printk(KERN_WARNING, ha,
  961. "Invalid PCI I/O region size (%s)...\n",
  962. pci_name(ha->pdev));
  963. pio = 0;
  964. }
  965. } else {
  966. qla_printk(KERN_WARNING, ha,
  967. "region #0 not a PIO resource (%s)...\n",
  968. pci_name(ha->pdev));
  969. pio = 0;
  970. }
  971. /* Use MMIO operations for all accesses. */
  972. mmio = pci_resource_start(ha->pdev, 1);
  973. mmio_len = pci_resource_len(ha->pdev, 1);
  974. mmio_flags = pci_resource_flags(ha->pdev, 1);
  975. if (!(mmio_flags & IORESOURCE_MEM)) {
  976. qla_printk(KERN_ERR, ha,
  977. "region #0 not an MMIO resource (%s), aborting\n",
  978. pci_name(ha->pdev));
  979. goto iospace_error_exit;
  980. }
  981. if (mmio_len < MIN_IOBASE_LEN) {
  982. qla_printk(KERN_ERR, ha,
  983. "Invalid PCI mem region size (%s), aborting\n",
  984. pci_name(ha->pdev));
  985. goto iospace_error_exit;
  986. }
  987. if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
  988. qla_printk(KERN_WARNING, ha,
  989. "Failed to reserve PIO/MMIO regions (%s)\n",
  990. pci_name(ha->pdev));
  991. goto iospace_error_exit;
  992. }
  993. ha->pio_address = pio;
  994. ha->pio_length = pio_len;
  995. ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
  996. if (!ha->iobase) {
  997. qla_printk(KERN_ERR, ha,
  998. "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
  999. goto iospace_error_exit;
  1000. }
  1001. return (0);
  1002. iospace_error_exit:
  1003. return (-ENOMEM);
  1004. }
  1005. static void
  1006. qla2x00_enable_intrs(scsi_qla_host_t *ha)
  1007. {
  1008. unsigned long flags = 0;
  1009. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1010. spin_lock_irqsave(&ha->hardware_lock, flags);
  1011. ha->interrupts_on = 1;
  1012. /* enable risc and host interrupts */
  1013. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1014. RD_REG_WORD(&reg->ictrl);
  1015. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1016. }
  1017. static void
  1018. qla2x00_disable_intrs(scsi_qla_host_t *ha)
  1019. {
  1020. unsigned long flags = 0;
  1021. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1022. spin_lock_irqsave(&ha->hardware_lock, flags);
  1023. ha->interrupts_on = 0;
  1024. /* disable risc and host interrupts */
  1025. WRT_REG_WORD(&reg->ictrl, 0);
  1026. RD_REG_WORD(&reg->ictrl);
  1027. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1028. }
  1029. static void
  1030. qla24xx_enable_intrs(scsi_qla_host_t *ha)
  1031. {
  1032. unsigned long flags = 0;
  1033. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1034. spin_lock_irqsave(&ha->hardware_lock, flags);
  1035. ha->interrupts_on = 1;
  1036. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1037. RD_REG_DWORD(&reg->ictrl);
  1038. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1039. }
  1040. static void
  1041. qla24xx_disable_intrs(scsi_qla_host_t *ha)
  1042. {
  1043. unsigned long flags = 0;
  1044. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1045. spin_lock_irqsave(&ha->hardware_lock, flags);
  1046. ha->interrupts_on = 0;
  1047. WRT_REG_DWORD(&reg->ictrl, 0);
  1048. RD_REG_DWORD(&reg->ictrl);
  1049. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1050. }
  1051. /*
  1052. * PCI driver interface
  1053. */
  1054. int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
  1055. {
  1056. int ret = -ENODEV;
  1057. device_reg_t __iomem *reg;
  1058. struct Scsi_Host *host;
  1059. scsi_qla_host_t *ha;
  1060. unsigned long flags = 0;
  1061. unsigned long wait_switch = 0;
  1062. char pci_info[20];
  1063. char fw_str[30];
  1064. fc_port_t *fcport;
  1065. if (pci_enable_device(pdev))
  1066. goto probe_out;
  1067. host = scsi_host_alloc(brd_info->sht ? brd_info->sht:
  1068. &qla2x00_driver_template, sizeof(scsi_qla_host_t));
  1069. if (host == NULL) {
  1070. printk(KERN_WARNING
  1071. "qla2xxx: Couldn't allocate host from scsi layer!\n");
  1072. goto probe_disable_device;
  1073. }
  1074. /* Clear our data area */
  1075. ha = (scsi_qla_host_t *)host->hostdata;
  1076. memset(ha, 0, sizeof(scsi_qla_host_t));
  1077. ha->pdev = pdev;
  1078. ha->host = host;
  1079. ha->host_no = host->host_no;
  1080. ha->brd_info = brd_info;
  1081. sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
  1082. ha->dpc_pid = -1;
  1083. /* Configure PCI I/O space */
  1084. ret = qla2x00_iospace_config(ha);
  1085. if (ret)
  1086. goto probe_failed;
  1087. qla_printk(KERN_INFO, ha,
  1088. "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
  1089. pdev->irq, ha->iobase);
  1090. spin_lock_init(&ha->hardware_lock);
  1091. ha->prev_topology = 0;
  1092. ha->ports = MAX_BUSES;
  1093. ha->init_cb_size = sizeof(init_cb_t);
  1094. ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
  1095. /* Assign ISP specific operations. */
  1096. ha->isp_ops.pci_config = qla2100_pci_config;
  1097. ha->isp_ops.reset_chip = qla2x00_reset_chip;
  1098. ha->isp_ops.chip_diag = qla2x00_chip_diag;
  1099. ha->isp_ops.config_rings = qla2x00_config_rings;
  1100. ha->isp_ops.reset_adapter = qla2x00_reset_adapter;
  1101. ha->isp_ops.nvram_config = qla2x00_nvram_config;
  1102. ha->isp_ops.update_fw_options = qla2x00_update_fw_options;
  1103. ha->isp_ops.load_risc = qla2x00_load_risc;
  1104. ha->isp_ops.pci_info_str = qla2x00_pci_info_str;
  1105. ha->isp_ops.fw_version_str = qla2x00_fw_version_str;
  1106. ha->isp_ops.intr_handler = qla2100_intr_handler;
  1107. ha->isp_ops.enable_intrs = qla2x00_enable_intrs;
  1108. ha->isp_ops.disable_intrs = qla2x00_disable_intrs;
  1109. ha->isp_ops.abort_command = qla2x00_abort_command;
  1110. ha->isp_ops.abort_target = qla2x00_abort_target;
  1111. ha->isp_ops.fabric_login = qla2x00_login_fabric;
  1112. ha->isp_ops.fabric_logout = qla2x00_fabric_logout;
  1113. ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
  1114. ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
  1115. ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
  1116. ha->isp_ops.prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb;
  1117. ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
  1118. ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
  1119. ha->isp_ops.fw_dump = qla2100_fw_dump;
  1120. ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
  1121. if (IS_QLA2100(ha)) {
  1122. host->max_id = MAX_TARGETS_2100;
  1123. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  1124. ha->request_q_length = REQUEST_ENTRY_CNT_2100;
  1125. ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
  1126. ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
  1127. host->sg_tablesize = 32;
  1128. ha->gid_list_info_size = 4;
  1129. } else if (IS_QLA2200(ha)) {
  1130. host->max_id = MAX_TARGETS_2200;
  1131. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1132. ha->request_q_length = REQUEST_ENTRY_CNT_2200;
  1133. ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
  1134. ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
  1135. ha->gid_list_info_size = 4;
  1136. } else if (IS_QLA23XX(ha)) {
  1137. host->max_id = MAX_TARGETS_2200;
  1138. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1139. ha->request_q_length = REQUEST_ENTRY_CNT_2200;
  1140. ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
  1141. ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
  1142. ha->isp_ops.pci_config = qla2300_pci_config;
  1143. ha->isp_ops.intr_handler = qla2300_intr_handler;
  1144. ha->isp_ops.fw_dump = qla2300_fw_dump;
  1145. ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
  1146. ha->gid_list_info_size = 6;
  1147. } else if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1148. host->max_id = MAX_TARGETS_2200;
  1149. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1150. ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
  1151. ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
  1152. ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
  1153. ha->init_cb_size = sizeof(struct init_cb_24xx);
  1154. ha->mgmt_svr_loop_id = 10;
  1155. ha->isp_ops.pci_config = qla24xx_pci_config;
  1156. ha->isp_ops.reset_chip = qla24xx_reset_chip;
  1157. ha->isp_ops.chip_diag = qla24xx_chip_diag;
  1158. ha->isp_ops.config_rings = qla24xx_config_rings;
  1159. ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
  1160. ha->isp_ops.nvram_config = qla24xx_nvram_config;
  1161. ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
  1162. ha->isp_ops.load_risc = qla24xx_load_risc_flash;
  1163. if (ql2xfwloadbin)
  1164. ha->isp_ops.load_risc = qla24xx_load_risc_hotplug;
  1165. ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
  1166. ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
  1167. ha->isp_ops.intr_handler = qla24xx_intr_handler;
  1168. ha->isp_ops.enable_intrs = qla24xx_enable_intrs;
  1169. ha->isp_ops.disable_intrs = qla24xx_disable_intrs;
  1170. ha->isp_ops.abort_command = qla24xx_abort_command;
  1171. ha->isp_ops.abort_target = qla24xx_abort_target;
  1172. ha->isp_ops.fabric_login = qla24xx_login_fabric;
  1173. ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
  1174. ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
  1175. ha->isp_ops.prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb;
  1176. ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
  1177. ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
  1178. ha->isp_ops.fw_dump = qla24xx_fw_dump;
  1179. ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
  1180. ha->gid_list_info_size = 8;
  1181. }
  1182. host->can_queue = ha->request_q_length + 128;
  1183. /* load the F/W, read paramaters, and init the H/W */
  1184. ha->instance = num_hosts;
  1185. init_MUTEX(&ha->mbx_cmd_sem);
  1186. init_MUTEX_LOCKED(&ha->mbx_intr_sem);
  1187. INIT_LIST_HEAD(&ha->list);
  1188. INIT_LIST_HEAD(&ha->fcports);
  1189. INIT_LIST_HEAD(&ha->rscn_fcports);
  1190. /*
  1191. * These locks are used to prevent more than one CPU
  1192. * from modifying the queue at the same time. The
  1193. * higher level "host_lock" will reduce most
  1194. * contention for these locks.
  1195. */
  1196. spin_lock_init(&ha->mbx_reg_lock);
  1197. init_completion(&ha->dpc_inited);
  1198. init_completion(&ha->dpc_exited);
  1199. qla2x00_config_dma_addressing(ha);
  1200. if (qla2x00_mem_alloc(ha)) {
  1201. qla_printk(KERN_WARNING, ha,
  1202. "[ERROR] Failed to allocate memory for adapter\n");
  1203. ret = -ENOMEM;
  1204. goto probe_failed;
  1205. }
  1206. if (qla2x00_initialize_adapter(ha) &&
  1207. !(ha->device_flags & DFLG_NO_CABLE)) {
  1208. qla_printk(KERN_WARNING, ha,
  1209. "Failed to initialize adapter\n");
  1210. DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
  1211. "Adapter flags %x.\n",
  1212. ha->host_no, ha->device_flags));
  1213. ret = -ENODEV;
  1214. goto probe_failed;
  1215. }
  1216. /*
  1217. * Startup the kernel thread for this host adapter
  1218. */
  1219. ha->dpc_should_die = 0;
  1220. ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
  1221. if (ha->dpc_pid < 0) {
  1222. qla_printk(KERN_WARNING, ha,
  1223. "Unable to start DPC thread!\n");
  1224. ret = -ENODEV;
  1225. goto probe_failed;
  1226. }
  1227. wait_for_completion(&ha->dpc_inited);
  1228. host->this_id = 255;
  1229. host->cmd_per_lun = 3;
  1230. host->unique_id = ha->instance;
  1231. host->max_cmd_len = MAX_CMDSZ;
  1232. host->max_channel = ha->ports - 1;
  1233. host->max_lun = MAX_LUNS;
  1234. host->transportt = qla2xxx_transport_template;
  1235. ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
  1236. SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
  1237. if (ret) {
  1238. qla_printk(KERN_WARNING, ha,
  1239. "Failed to reserve interrupt %d already in use.\n",
  1240. pdev->irq);
  1241. goto probe_failed;
  1242. }
  1243. host->irq = pdev->irq;
  1244. /* Initialized the timer */
  1245. qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
  1246. DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
  1247. ha->host_no, ha));
  1248. ha->isp_ops.disable_intrs(ha);
  1249. spin_lock_irqsave(&ha->hardware_lock, flags);
  1250. reg = ha->iobase;
  1251. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1252. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
  1253. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
  1254. } else {
  1255. WRT_REG_WORD(&reg->isp.semaphore, 0);
  1256. WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
  1257. WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
  1258. /* Enable proper parity */
  1259. if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  1260. if (IS_QLA2300(ha))
  1261. /* SRAM parity */
  1262. WRT_REG_WORD(&reg->isp.hccr,
  1263. (HCCR_ENABLE_PARITY + 0x1));
  1264. else
  1265. /* SRAM, Instruction RAM and GP RAM parity */
  1266. WRT_REG_WORD(&reg->isp.hccr,
  1267. (HCCR_ENABLE_PARITY + 0x7));
  1268. }
  1269. }
  1270. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1271. ha->isp_ops.enable_intrs(ha);
  1272. /* v2.19.5b6 */
  1273. /*
  1274. * Wait around max loop_reset_delay secs for the devices to come
  1275. * on-line. We don't want Linux scanning before we are ready.
  1276. *
  1277. */
  1278. for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
  1279. time_before(jiffies,wait_switch) &&
  1280. !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
  1281. && (ha->device_flags & SWITCH_FOUND) ;) {
  1282. qla2x00_check_fabric_devices(ha);
  1283. msleep(10);
  1284. }
  1285. pci_set_drvdata(pdev, ha);
  1286. ha->flags.init_done = 1;
  1287. num_hosts++;
  1288. ret = scsi_add_host(host, &pdev->dev);
  1289. if (ret)
  1290. goto probe_failed;
  1291. qla2x00_alloc_sysfs_attr(ha);
  1292. qla2x00_init_host_attr(ha);
  1293. qla_printk(KERN_INFO, ha, "\n"
  1294. " QLogic Fibre Channel HBA Driver: %s\n"
  1295. " QLogic %s - %s\n"
  1296. " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
  1297. ha->model_number, ha->model_desc ? ha->model_desc: "",
  1298. ha->brd_info->isp_name, ha->isp_ops.pci_info_str(ha, pci_info),
  1299. pci_name(pdev), ha->flags.enable_64bit_addressing ? '+': '-',
  1300. ha->host_no, ha->isp_ops.fw_version_str(ha, fw_str));
  1301. /* Go with fc_rport registration. */
  1302. list_for_each_entry(fcport, &ha->fcports, list)
  1303. qla2x00_reg_remote_port(ha, fcport);
  1304. return 0;
  1305. probe_failed:
  1306. qla2x00_free_device(ha);
  1307. scsi_host_put(host);
  1308. probe_disable_device:
  1309. pci_disable_device(pdev);
  1310. probe_out:
  1311. return ret;
  1312. }
  1313. EXPORT_SYMBOL_GPL(qla2x00_probe_one);
  1314. void qla2x00_remove_one(struct pci_dev *pdev)
  1315. {
  1316. scsi_qla_host_t *ha;
  1317. ha = pci_get_drvdata(pdev);
  1318. qla2x00_free_sysfs_attr(ha);
  1319. fc_remove_host(ha->host);
  1320. scsi_remove_host(ha->host);
  1321. qla2x00_free_device(ha);
  1322. scsi_host_put(ha->host);
  1323. pci_set_drvdata(pdev, NULL);
  1324. }
  1325. EXPORT_SYMBOL_GPL(qla2x00_remove_one);
  1326. static void
  1327. qla2x00_free_device(scsi_qla_host_t *ha)
  1328. {
  1329. int ret;
  1330. /* Abort any outstanding IO descriptors. */
  1331. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  1332. qla2x00_cancel_io_descriptors(ha);
  1333. /* Disable timer */
  1334. if (ha->timer_active)
  1335. qla2x00_stop_timer(ha);
  1336. /* Kill the kernel thread for this host */
  1337. if (ha->dpc_pid >= 0) {
  1338. ha->dpc_should_die = 1;
  1339. wmb();
  1340. ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
  1341. if (ret) {
  1342. qla_printk(KERN_ERR, ha,
  1343. "Unable to signal DPC thread -- (%d)\n", ret);
  1344. /* TODO: SOMETHING MORE??? */
  1345. } else {
  1346. wait_for_completion(&ha->dpc_exited);
  1347. }
  1348. }
  1349. /* Stop currently executing firmware. */
  1350. qla2x00_stop_firmware(ha);
  1351. /* turn-off interrupts on the card */
  1352. if (ha->interrupts_on)
  1353. ha->isp_ops.disable_intrs(ha);
  1354. qla2x00_mem_free(ha);
  1355. ha->flags.online = 0;
  1356. /* Detach interrupts */
  1357. if (ha->pdev->irq)
  1358. free_irq(ha->pdev->irq, ha);
  1359. /* release io space registers */
  1360. if (ha->iobase)
  1361. iounmap(ha->iobase);
  1362. pci_release_regions(ha->pdev);
  1363. pci_disable_device(ha->pdev);
  1364. }
  1365. /*
  1366. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  1367. *
  1368. * Input: ha = adapter block pointer. fcport = port structure pointer.
  1369. *
  1370. * Return: None.
  1371. *
  1372. * Context:
  1373. */
  1374. void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
  1375. int do_login)
  1376. {
  1377. if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
  1378. fc_remote_port_block(fcport->rport);
  1379. /*
  1380. * We may need to retry the login, so don't change the state of the
  1381. * port but do the retries.
  1382. */
  1383. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  1384. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1385. if (!do_login)
  1386. return;
  1387. if (fcport->login_retry == 0) {
  1388. fcport->login_retry = ha->login_retry_count;
  1389. set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
  1390. DEBUG(printk("scsi(%ld): Port login retry: "
  1391. "%02x%02x%02x%02x%02x%02x%02x%02x, "
  1392. "id = 0x%04x retry cnt=%d\n",
  1393. ha->host_no,
  1394. fcport->port_name[0],
  1395. fcport->port_name[1],
  1396. fcport->port_name[2],
  1397. fcport->port_name[3],
  1398. fcport->port_name[4],
  1399. fcport->port_name[5],
  1400. fcport->port_name[6],
  1401. fcport->port_name[7],
  1402. fcport->loop_id,
  1403. fcport->login_retry));
  1404. }
  1405. }
  1406. /*
  1407. * qla2x00_mark_all_devices_lost
  1408. * Updates fcport state when device goes offline.
  1409. *
  1410. * Input:
  1411. * ha = adapter block pointer.
  1412. * fcport = port structure pointer.
  1413. *
  1414. * Return:
  1415. * None.
  1416. *
  1417. * Context:
  1418. */
  1419. void
  1420. qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
  1421. {
  1422. fc_port_t *fcport;
  1423. list_for_each_entry(fcport, &ha->fcports, list) {
  1424. if (fcport->port_type != FCT_TARGET)
  1425. continue;
  1426. /*
  1427. * No point in marking the device as lost, if the device is
  1428. * already DEAD.
  1429. */
  1430. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  1431. continue;
  1432. if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
  1433. fc_remote_port_block(fcport->rport);
  1434. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1435. }
  1436. }
  1437. /*
  1438. * qla2x00_mem_alloc
  1439. * Allocates adapter memory.
  1440. *
  1441. * Returns:
  1442. * 0 = success.
  1443. * 1 = failure.
  1444. */
  1445. static uint8_t
  1446. qla2x00_mem_alloc(scsi_qla_host_t *ha)
  1447. {
  1448. char name[16];
  1449. uint8_t status = 1;
  1450. int retry= 10;
  1451. do {
  1452. /*
  1453. * This will loop only once if everything goes well, else some
  1454. * number of retries will be performed to get around a kernel
  1455. * bug where available mem is not allocated until after a
  1456. * little delay and a retry.
  1457. */
  1458. ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
  1459. (ha->request_q_length + 1) * sizeof(request_t),
  1460. &ha->request_dma, GFP_KERNEL);
  1461. if (ha->request_ring == NULL) {
  1462. qla_printk(KERN_WARNING, ha,
  1463. "Memory Allocation failed - request_ring\n");
  1464. qla2x00_mem_free(ha);
  1465. msleep(100);
  1466. continue;
  1467. }
  1468. ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
  1469. (ha->response_q_length + 1) * sizeof(response_t),
  1470. &ha->response_dma, GFP_KERNEL);
  1471. if (ha->response_ring == NULL) {
  1472. qla_printk(KERN_WARNING, ha,
  1473. "Memory Allocation failed - response_ring\n");
  1474. qla2x00_mem_free(ha);
  1475. msleep(100);
  1476. continue;
  1477. }
  1478. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
  1479. &ha->gid_list_dma, GFP_KERNEL);
  1480. if (ha->gid_list == NULL) {
  1481. qla_printk(KERN_WARNING, ha,
  1482. "Memory Allocation failed - gid_list\n");
  1483. qla2x00_mem_free(ha);
  1484. msleep(100);
  1485. continue;
  1486. }
  1487. ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
  1488. sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
  1489. if (ha->rlc_rsp == NULL) {
  1490. qla_printk(KERN_WARNING, ha,
  1491. "Memory Allocation failed - rlc");
  1492. qla2x00_mem_free(ha);
  1493. msleep(100);
  1494. continue;
  1495. }
  1496. snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
  1497. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  1498. DMA_POOL_SIZE, 8, 0);
  1499. if (ha->s_dma_pool == NULL) {
  1500. qla_printk(KERN_WARNING, ha,
  1501. "Memory Allocation failed - s_dma_pool\n");
  1502. qla2x00_mem_free(ha);
  1503. msleep(100);
  1504. continue;
  1505. }
  1506. /* get consistent memory allocated for init control block */
  1507. ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1508. &ha->init_cb_dma);
  1509. if (ha->init_cb == NULL) {
  1510. qla_printk(KERN_WARNING, ha,
  1511. "Memory Allocation failed - init_cb\n");
  1512. qla2x00_mem_free(ha);
  1513. msleep(100);
  1514. continue;
  1515. }
  1516. memset(ha->init_cb, 0, ha->init_cb_size);
  1517. /* Get consistent memory allocated for Get Port Database cmd */
  1518. ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1519. &ha->iodesc_pd_dma);
  1520. if (ha->iodesc_pd == NULL) {
  1521. /* error */
  1522. qla_printk(KERN_WARNING, ha,
  1523. "Memory Allocation failed - iodesc_pd\n");
  1524. qla2x00_mem_free(ha);
  1525. msleep(100);
  1526. continue;
  1527. }
  1528. memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
  1529. /* Allocate ioctl related memory. */
  1530. if (qla2x00_alloc_ioctl_mem(ha)) {
  1531. qla_printk(KERN_WARNING, ha,
  1532. "Memory Allocation failed - ioctl_mem\n");
  1533. qla2x00_mem_free(ha);
  1534. msleep(100);
  1535. continue;
  1536. }
  1537. if (qla2x00_allocate_sp_pool(ha)) {
  1538. qla_printk(KERN_WARNING, ha,
  1539. "Memory Allocation failed - "
  1540. "qla2x00_allocate_sp_pool()\n");
  1541. qla2x00_mem_free(ha);
  1542. msleep(100);
  1543. continue;
  1544. }
  1545. /* Allocate memory for SNS commands */
  1546. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1547. /* Get consistent memory allocated for SNS commands */
  1548. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  1549. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
  1550. GFP_KERNEL);
  1551. if (ha->sns_cmd == NULL) {
  1552. /* error */
  1553. qla_printk(KERN_WARNING, ha,
  1554. "Memory Allocation failed - sns_cmd\n");
  1555. qla2x00_mem_free(ha);
  1556. msleep(100);
  1557. continue;
  1558. }
  1559. memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
  1560. } else {
  1561. /* Get consistent memory allocated for MS IOCB */
  1562. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1563. &ha->ms_iocb_dma);
  1564. if (ha->ms_iocb == NULL) {
  1565. /* error */
  1566. qla_printk(KERN_WARNING, ha,
  1567. "Memory Allocation failed - ms_iocb\n");
  1568. qla2x00_mem_free(ha);
  1569. msleep(100);
  1570. continue;
  1571. }
  1572. memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
  1573. /*
  1574. * Get consistent memory allocated for CT SNS
  1575. * commands
  1576. */
  1577. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  1578. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
  1579. GFP_KERNEL);
  1580. if (ha->ct_sns == NULL) {
  1581. /* error */
  1582. qla_printk(KERN_WARNING, ha,
  1583. "Memory Allocation failed - ct_sns\n");
  1584. qla2x00_mem_free(ha);
  1585. msleep(100);
  1586. continue;
  1587. }
  1588. memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
  1589. }
  1590. /* Done all allocations without any error. */
  1591. status = 0;
  1592. } while (retry-- && status != 0);
  1593. if (status) {
  1594. printk(KERN_WARNING
  1595. "%s(): **** FAILED ****\n", __func__);
  1596. }
  1597. return(status);
  1598. }
  1599. /*
  1600. * qla2x00_mem_free
  1601. * Frees all adapter allocated memory.
  1602. *
  1603. * Input:
  1604. * ha = adapter block pointer.
  1605. */
  1606. static void
  1607. qla2x00_mem_free(scsi_qla_host_t *ha)
  1608. {
  1609. struct list_head *fcpl, *fcptemp;
  1610. fc_port_t *fcport;
  1611. unsigned int wtime;/* max wait time if mbx cmd is busy. */
  1612. if (ha == NULL) {
  1613. /* error */
  1614. DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
  1615. return;
  1616. }
  1617. /* Make sure all other threads are stopped. */
  1618. wtime = 60 * 1000;
  1619. while (ha->dpc_wait && wtime)
  1620. wtime = msleep_interruptible(wtime);
  1621. /* free ioctl memory */
  1622. qla2x00_free_ioctl_mem(ha);
  1623. /* free sp pool */
  1624. qla2x00_free_sp_pool(ha);
  1625. if (ha->sns_cmd)
  1626. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  1627. ha->sns_cmd, ha->sns_cmd_dma);
  1628. if (ha->ct_sns)
  1629. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  1630. ha->ct_sns, ha->ct_sns_dma);
  1631. if (ha->ms_iocb)
  1632. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  1633. if (ha->iodesc_pd)
  1634. dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
  1635. if (ha->init_cb)
  1636. dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
  1637. if (ha->s_dma_pool)
  1638. dma_pool_destroy(ha->s_dma_pool);
  1639. if (ha->rlc_rsp)
  1640. dma_free_coherent(&ha->pdev->dev,
  1641. sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
  1642. ha->rlc_rsp_dma);
  1643. if (ha->gid_list)
  1644. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  1645. ha->gid_list_dma);
  1646. if (ha->response_ring)
  1647. dma_free_coherent(&ha->pdev->dev,
  1648. (ha->response_q_length + 1) * sizeof(response_t),
  1649. ha->response_ring, ha->response_dma);
  1650. if (ha->request_ring)
  1651. dma_free_coherent(&ha->pdev->dev,
  1652. (ha->request_q_length + 1) * sizeof(request_t),
  1653. ha->request_ring, ha->request_dma);
  1654. ha->sns_cmd = NULL;
  1655. ha->sns_cmd_dma = 0;
  1656. ha->ct_sns = NULL;
  1657. ha->ct_sns_dma = 0;
  1658. ha->ms_iocb = NULL;
  1659. ha->ms_iocb_dma = 0;
  1660. ha->iodesc_pd = NULL;
  1661. ha->iodesc_pd_dma = 0;
  1662. ha->init_cb = NULL;
  1663. ha->init_cb_dma = 0;
  1664. ha->s_dma_pool = NULL;
  1665. ha->rlc_rsp = NULL;
  1666. ha->rlc_rsp_dma = 0;
  1667. ha->gid_list = NULL;
  1668. ha->gid_list_dma = 0;
  1669. ha->response_ring = NULL;
  1670. ha->response_dma = 0;
  1671. ha->request_ring = NULL;
  1672. ha->request_dma = 0;
  1673. list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
  1674. fcport = list_entry(fcpl, fc_port_t, list);
  1675. /* fc ports */
  1676. list_del_init(&fcport->list);
  1677. kfree(fcport);
  1678. }
  1679. INIT_LIST_HEAD(&ha->fcports);
  1680. if (ha->fw_dump)
  1681. free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
  1682. vfree(ha->fw_dump24);
  1683. vfree(ha->fw_dump_buffer);
  1684. ha->fw_dump = NULL;
  1685. ha->fw_dump24 = NULL;
  1686. ha->fw_dumped = 0;
  1687. ha->fw_dump_reading = 0;
  1688. ha->fw_dump_buffer = NULL;
  1689. }
  1690. /*
  1691. * qla2x00_allocate_sp_pool
  1692. * This routine is called during initialization to allocate
  1693. * memory for local srb_t.
  1694. *
  1695. * Input:
  1696. * ha = adapter block pointer.
  1697. *
  1698. * Context:
  1699. * Kernel context.
  1700. *
  1701. * Note: Sets the ref_count for non Null sp to one.
  1702. */
  1703. static int
  1704. qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
  1705. {
  1706. int rval;
  1707. rval = QLA_SUCCESS;
  1708. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  1709. mempool_free_slab, srb_cachep);
  1710. if (ha->srb_mempool == NULL) {
  1711. qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
  1712. rval = QLA_FUNCTION_FAILED;
  1713. }
  1714. return (rval);
  1715. }
  1716. /*
  1717. * This routine frees all adapter allocated memory.
  1718. *
  1719. */
  1720. static void
  1721. qla2x00_free_sp_pool( scsi_qla_host_t *ha)
  1722. {
  1723. if (ha->srb_mempool) {
  1724. mempool_destroy(ha->srb_mempool);
  1725. ha->srb_mempool = NULL;
  1726. }
  1727. }
  1728. /**************************************************************************
  1729. * qla2x00_do_dpc
  1730. * This kernel thread is a task that is schedule by the interrupt handler
  1731. * to perform the background processing for interrupts.
  1732. *
  1733. * Notes:
  1734. * This task always run in the context of a kernel thread. It
  1735. * is kick-off by the driver's detect code and starts up
  1736. * up one per adapter. It immediately goes to sleep and waits for
  1737. * some fibre event. When either the interrupt handler or
  1738. * the timer routine detects a event it will one of the task
  1739. * bits then wake us up.
  1740. **************************************************************************/
  1741. static int
  1742. qla2x00_do_dpc(void *data)
  1743. {
  1744. DECLARE_MUTEX_LOCKED(sem);
  1745. scsi_qla_host_t *ha;
  1746. fc_port_t *fcport;
  1747. uint8_t status;
  1748. uint16_t next_loopid;
  1749. ha = (scsi_qla_host_t *)data;
  1750. lock_kernel();
  1751. daemonize("%s_dpc", ha->host_str);
  1752. allow_signal(SIGHUP);
  1753. ha->dpc_wait = &sem;
  1754. set_user_nice(current, -20);
  1755. unlock_kernel();
  1756. complete(&ha->dpc_inited);
  1757. while (1) {
  1758. DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
  1759. if (down_interruptible(&sem))
  1760. break;
  1761. if (ha->dpc_should_die)
  1762. break;
  1763. DEBUG3(printk("qla2x00: DPC handler waking up\n"));
  1764. /* Initialization not yet finished. Don't do anything yet. */
  1765. if (!ha->flags.init_done || ha->dpc_active)
  1766. continue;
  1767. DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
  1768. ha->dpc_active = 1;
  1769. if (ha->flags.mbox_busy) {
  1770. ha->dpc_active = 0;
  1771. continue;
  1772. }
  1773. if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
  1774. DEBUG(printk("scsi(%ld): dpc: sched "
  1775. "qla2x00_abort_isp ha = %p\n",
  1776. ha->host_no, ha));
  1777. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  1778. &ha->dpc_flags))) {
  1779. if (qla2x00_abort_isp(ha)) {
  1780. /* failed. retry later */
  1781. set_bit(ISP_ABORT_NEEDED,
  1782. &ha->dpc_flags);
  1783. }
  1784. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  1785. }
  1786. DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
  1787. ha->host_no));
  1788. }
  1789. if (test_and_clear_bit(LOOP_RESET_NEEDED, &ha->dpc_flags)) {
  1790. DEBUG(printk("scsi(%ld): dpc: sched loop_reset()\n",
  1791. ha->host_no));
  1792. qla2x00_loop_reset(ha);
  1793. }
  1794. if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
  1795. (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
  1796. DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
  1797. ha->host_no));
  1798. qla2x00_rst_aen(ha);
  1799. clear_bit(RESET_ACTIVE, &ha->dpc_flags);
  1800. }
  1801. /* Retry each device up to login retry count */
  1802. if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
  1803. !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
  1804. atomic_read(&ha->loop_state) != LOOP_DOWN) {
  1805. DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
  1806. ha->host_no));
  1807. next_loopid = 0;
  1808. list_for_each_entry(fcport, &ha->fcports, list) {
  1809. if (fcport->port_type != FCT_TARGET)
  1810. continue;
  1811. /*
  1812. * If the port is not ONLINE then try to login
  1813. * to it if we haven't run out of retries.
  1814. */
  1815. if (atomic_read(&fcport->state) != FCS_ONLINE &&
  1816. fcport->login_retry) {
  1817. fcport->login_retry--;
  1818. if (fcport->flags & FCF_FABRIC_DEVICE) {
  1819. if (fcport->flags &
  1820. FCF_TAPE_PRESENT)
  1821. ha->isp_ops.fabric_logout(
  1822. ha, fcport->loop_id,
  1823. fcport->d_id.b.domain,
  1824. fcport->d_id.b.area,
  1825. fcport->d_id.b.al_pa);
  1826. status = qla2x00_fabric_login(
  1827. ha, fcport, &next_loopid);
  1828. } else
  1829. status =
  1830. qla2x00_local_device_login(
  1831. ha, fcport->loop_id);
  1832. if (status == QLA_SUCCESS) {
  1833. fcport->old_loop_id = fcport->loop_id;
  1834. DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
  1835. ha->host_no, fcport->loop_id));
  1836. fcport->port_login_retry_count =
  1837. ha->port_down_retry_count * PORT_RETRY_TIME;
  1838. atomic_set(&fcport->state, FCS_ONLINE);
  1839. atomic_set(&fcport->port_down_timer,
  1840. ha->port_down_retry_count * PORT_RETRY_TIME);
  1841. fcport->login_retry = 0;
  1842. } else if (status == 1) {
  1843. set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
  1844. /* retry the login again */
  1845. DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
  1846. ha->host_no,
  1847. fcport->login_retry, fcport->loop_id));
  1848. } else {
  1849. fcport->login_retry = 0;
  1850. }
  1851. }
  1852. if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
  1853. break;
  1854. }
  1855. DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
  1856. ha->host_no));
  1857. }
  1858. if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
  1859. atomic_read(&ha->loop_state) != LOOP_DOWN) {
  1860. clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
  1861. DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
  1862. ha->host_no));
  1863. set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  1864. DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
  1865. ha->host_no));
  1866. }
  1867. if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
  1868. DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
  1869. ha->host_no));
  1870. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  1871. &ha->dpc_flags))) {
  1872. qla2x00_loop_resync(ha);
  1873. clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
  1874. }
  1875. DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
  1876. ha->host_no));
  1877. }
  1878. if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
  1879. DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
  1880. ha->host_no));
  1881. qla2x00_rescan_fcports(ha);
  1882. DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
  1883. "end.\n",
  1884. ha->host_no));
  1885. }
  1886. if (!ha->interrupts_on)
  1887. ha->isp_ops.enable_intrs(ha);
  1888. ha->dpc_active = 0;
  1889. } /* End of while(1) */
  1890. DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
  1891. /*
  1892. * Make sure that nobody tries to wake us up again.
  1893. */
  1894. ha->dpc_wait = NULL;
  1895. ha->dpc_active = 0;
  1896. complete_and_exit(&ha->dpc_exited, 0);
  1897. }
  1898. /*
  1899. * qla2x00_rst_aen
  1900. * Processes asynchronous reset.
  1901. *
  1902. * Input:
  1903. * ha = adapter block pointer.
  1904. */
  1905. static void
  1906. qla2x00_rst_aen(scsi_qla_host_t *ha)
  1907. {
  1908. if (ha->flags.online && !ha->flags.reset_active &&
  1909. !atomic_read(&ha->loop_down_timer) &&
  1910. !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
  1911. do {
  1912. clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
  1913. /*
  1914. * Issue marker command only when we are going to start
  1915. * the I/O.
  1916. */
  1917. ha->marker_needed = 1;
  1918. } while (!atomic_read(&ha->loop_down_timer) &&
  1919. (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
  1920. }
  1921. }
  1922. static void
  1923. qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
  1924. {
  1925. struct scsi_cmnd *cmd = sp->cmd;
  1926. if (sp->flags & SRB_DMA_VALID) {
  1927. if (cmd->use_sg) {
  1928. dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
  1929. cmd->use_sg, cmd->sc_data_direction);
  1930. } else if (cmd->request_bufflen) {
  1931. dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
  1932. cmd->request_bufflen, cmd->sc_data_direction);
  1933. }
  1934. sp->flags &= ~SRB_DMA_VALID;
  1935. }
  1936. CMD_SP(cmd) = NULL;
  1937. }
  1938. void
  1939. qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
  1940. {
  1941. struct scsi_cmnd *cmd = sp->cmd;
  1942. qla2x00_sp_free_dma(ha, sp);
  1943. mempool_free(sp, ha->srb_mempool);
  1944. cmd->scsi_done(cmd);
  1945. }
  1946. /**************************************************************************
  1947. * qla2x00_timer
  1948. *
  1949. * Description:
  1950. * One second timer
  1951. *
  1952. * Context: Interrupt
  1953. ***************************************************************************/
  1954. static void
  1955. qla2x00_timer(scsi_qla_host_t *ha)
  1956. {
  1957. unsigned long cpu_flags = 0;
  1958. fc_port_t *fcport;
  1959. int start_dpc = 0;
  1960. int index;
  1961. srb_t *sp;
  1962. int t;
  1963. /*
  1964. * Ports - Port down timer.
  1965. *
  1966. * Whenever, a port is in the LOST state we start decrementing its port
  1967. * down timer every second until it reaches zero. Once it reaches zero
  1968. * the port it marked DEAD.
  1969. */
  1970. t = 0;
  1971. list_for_each_entry(fcport, &ha->fcports, list) {
  1972. if (fcport->port_type != FCT_TARGET)
  1973. continue;
  1974. if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  1975. if (atomic_read(&fcport->port_down_timer) == 0)
  1976. continue;
  1977. if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
  1978. atomic_set(&fcport->state, FCS_DEVICE_DEAD);
  1979. DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
  1980. "%d remaining\n",
  1981. ha->host_no,
  1982. t, atomic_read(&fcport->port_down_timer)));
  1983. }
  1984. t++;
  1985. } /* End of for fcport */
  1986. /* Loop down handler. */
  1987. if (atomic_read(&ha->loop_down_timer) > 0 &&
  1988. !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
  1989. if (atomic_read(&ha->loop_down_timer) ==
  1990. ha->loop_down_abort_time) {
  1991. DEBUG(printk("scsi(%ld): Loop Down - aborting the "
  1992. "queues before time expire\n",
  1993. ha->host_no));
  1994. if (!IS_QLA2100(ha) && ha->link_down_timeout)
  1995. atomic_set(&ha->loop_state, LOOP_DEAD);
  1996. /* Schedule an ISP abort to return any tape commands. */
  1997. spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
  1998. for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
  1999. index++) {
  2000. fc_port_t *sfcp;
  2001. sp = ha->outstanding_cmds[index];
  2002. if (!sp)
  2003. continue;
  2004. sfcp = sp->fcport;
  2005. if (!(sfcp->flags & FCF_TAPE_PRESENT))
  2006. continue;
  2007. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  2008. break;
  2009. }
  2010. spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
  2011. set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
  2012. start_dpc++;
  2013. }
  2014. /* if the loop has been down for 4 minutes, reinit adapter */
  2015. if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
  2016. DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
  2017. "restarting queues.\n",
  2018. ha->host_no));
  2019. set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
  2020. start_dpc++;
  2021. if (!(ha->device_flags & DFLG_NO_CABLE)) {
  2022. DEBUG(printk("scsi(%ld): Loop down - "
  2023. "aborting ISP.\n",
  2024. ha->host_no));
  2025. qla_printk(KERN_WARNING, ha,
  2026. "Loop down - aborting ISP.\n");
  2027. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  2028. }
  2029. }
  2030. DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
  2031. ha->host_no,
  2032. atomic_read(&ha->loop_down_timer)));
  2033. }
  2034. /* Schedule the DPC routine if needed */
  2035. if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
  2036. test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
  2037. test_bit(LOOP_RESET_NEEDED, &ha->dpc_flags) ||
  2038. start_dpc ||
  2039. test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
  2040. test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
  2041. test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
  2042. ha->dpc_wait && !ha->dpc_active) {
  2043. up(ha->dpc_wait);
  2044. }
  2045. qla2x00_restart_timer(ha, WATCH_INTERVAL);
  2046. }
  2047. /* XXX(hch): crude hack to emulate a down_timeout() */
  2048. int
  2049. qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
  2050. {
  2051. const unsigned int step = 100; /* msecs */
  2052. unsigned int iterations = jiffies_to_msecs(timeout)/100;
  2053. do {
  2054. if (!down_trylock(sema))
  2055. return 0;
  2056. if (msleep_interruptible(step))
  2057. break;
  2058. } while (--iterations >= 0);
  2059. return -ETIMEDOUT;
  2060. }
  2061. static struct qla_board_info qla_board_tbl[] = {
  2062. {
  2063. .drv_name = "qla2400",
  2064. .isp_name = "ISP2422",
  2065. .fw_fname = "ql2400_fw.bin",
  2066. .sht = &qla24xx_driver_template,
  2067. },
  2068. {
  2069. .drv_name = "qla2400",
  2070. .isp_name = "ISP2432",
  2071. .fw_fname = "ql2400_fw.bin",
  2072. .sht = &qla24xx_driver_template,
  2073. },
  2074. };
  2075. static struct pci_device_id qla2xxx_pci_tbl[] = {
  2076. {
  2077. .vendor = PCI_VENDOR_ID_QLOGIC,
  2078. .device = PCI_DEVICE_ID_QLOGIC_ISP2422,
  2079. .subvendor = PCI_ANY_ID,
  2080. .subdevice = PCI_ANY_ID,
  2081. .driver_data = (unsigned long)&qla_board_tbl[0],
  2082. },
  2083. {
  2084. .vendor = PCI_VENDOR_ID_QLOGIC,
  2085. .device = PCI_DEVICE_ID_QLOGIC_ISP2432,
  2086. .subvendor = PCI_ANY_ID,
  2087. .subdevice = PCI_ANY_ID,
  2088. .driver_data = (unsigned long)&qla_board_tbl[1],
  2089. },
  2090. {0, 0},
  2091. };
  2092. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  2093. static int __devinit
  2094. qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  2095. {
  2096. return qla2x00_probe_one(pdev,
  2097. (struct qla_board_info *)id->driver_data);
  2098. }
  2099. static void __devexit
  2100. qla2xxx_remove_one(struct pci_dev *pdev)
  2101. {
  2102. qla2x00_remove_one(pdev);
  2103. }
  2104. static struct pci_driver qla2xxx_pci_driver = {
  2105. .name = "qla2xxx",
  2106. .id_table = qla2xxx_pci_tbl,
  2107. .probe = qla2xxx_probe_one,
  2108. .remove = __devexit_p(qla2xxx_remove_one),
  2109. };
  2110. /**
  2111. * qla2x00_module_init - Module initialization.
  2112. **/
  2113. static int __init
  2114. qla2x00_module_init(void)
  2115. {
  2116. int ret = 0;
  2117. /* Allocate cache for SRBs. */
  2118. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  2119. SLAB_HWCACHE_ALIGN, NULL, NULL);
  2120. if (srb_cachep == NULL) {
  2121. printk(KERN_ERR
  2122. "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
  2123. return -ENOMEM;
  2124. }
  2125. /* Derive version string. */
  2126. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  2127. #if DEBUG_QLA2100
  2128. strcat(qla2x00_version_str, "-debug");
  2129. #endif
  2130. qla2xxx_transport_template =
  2131. fc_attach_transport(&qla2xxx_transport_functions);
  2132. if (!qla2xxx_transport_template)
  2133. return -ENODEV;
  2134. printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
  2135. ret = pci_module_init(&qla2xxx_pci_driver);
  2136. if (ret) {
  2137. kmem_cache_destroy(srb_cachep);
  2138. fc_release_transport(qla2xxx_transport_template);
  2139. }
  2140. return ret;
  2141. }
  2142. /**
  2143. * qla2x00_module_exit - Module cleanup.
  2144. **/
  2145. static void __exit
  2146. qla2x00_module_exit(void)
  2147. {
  2148. pci_unregister_driver(&qla2xxx_pci_driver);
  2149. kmem_cache_destroy(srb_cachep);
  2150. fc_release_transport(qla2xxx_transport_template);
  2151. }
  2152. module_init(qla2x00_module_init);
  2153. module_exit(qla2x00_module_exit);
  2154. MODULE_AUTHOR("QLogic Corporation");
  2155. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  2156. MODULE_LICENSE("GPL");
  2157. MODULE_VERSION(QLA2XXX_VERSION);