qla_os.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 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/delay.h>
  11. #include <linux/kthread.h>
  12. #include <linux/mutex.h>
  13. #include <scsi/scsi_tcq.h>
  14. #include <scsi/scsicam.h>
  15. #include <scsi/scsi_transport.h>
  16. #include <scsi/scsi_transport_fc.h>
  17. /*
  18. * Driver version
  19. */
  20. char qla2x00_version_str[40];
  21. /*
  22. * SRB allocation cache
  23. */
  24. static struct kmem_cache *srb_cachep;
  25. int ql2xlogintimeout = 20;
  26. module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
  27. MODULE_PARM_DESC(ql2xlogintimeout,
  28. "Login timeout value in seconds.");
  29. int qlport_down_retry;
  30. module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
  31. MODULE_PARM_DESC(qlport_down_retry,
  32. "Maximum number of command retries to a port that returns "
  33. "a PORT-DOWN status.");
  34. int ql2xplogiabsentdevice;
  35. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  36. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  37. "Option to enable PLOGI to devices that are not present after "
  38. "a Fabric scan. This is needed for several broken switches. "
  39. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  40. int ql2xloginretrycount = 0;
  41. module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
  42. MODULE_PARM_DESC(ql2xloginretrycount,
  43. "Specify an alternate value for the NVRAM login retry count.");
  44. int ql2xallocfwdump = 1;
  45. module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
  46. MODULE_PARM_DESC(ql2xallocfwdump,
  47. "Option to enable allocation of memory for a firmware dump "
  48. "during HBA initialization. Memory allocation requirements "
  49. "vary by ISP type. Default is 1 - allocate memory.");
  50. int ql2xextended_error_logging;
  51. module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  52. MODULE_PARM_DESC(ql2xextended_error_logging,
  53. "Option to enable extended error logging, "
  54. "Default is 0 - no logging. 1 - log errors.");
  55. static void qla2x00_free_device(scsi_qla_host_t *);
  56. static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
  57. int ql2xfdmienable=1;
  58. module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
  59. MODULE_PARM_DESC(ql2xfdmienable,
  60. "Enables FDMI registratons "
  61. "Default is 0 - no FDMI. 1 - perfom FDMI.");
  62. #define MAX_Q_DEPTH 32
  63. static int ql2xmaxqdepth = MAX_Q_DEPTH;
  64. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  65. MODULE_PARM_DESC(ql2xmaxqdepth,
  66. "Maximum queue depth to report for target devices.");
  67. int ql2xqfullrampup = 120;
  68. module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
  69. MODULE_PARM_DESC(ql2xqfullrampup,
  70. "Number of seconds to wait to begin to ramp-up the queue "
  71. "depth for a device after a queue-full condition has been "
  72. "detected. Default is 120 seconds.");
  73. int ql2xiidmaenable=1;
  74. module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
  75. MODULE_PARM_DESC(ql2xiidmaenable,
  76. "Enables iIDMA settings "
  77. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  78. /*
  79. * SCSI host template entry points
  80. */
  81. static int qla2xxx_slave_configure(struct scsi_device * device);
  82. static int qla2xxx_slave_alloc(struct scsi_device *);
  83. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  84. static void qla2xxx_scan_start(struct Scsi_Host *);
  85. static void qla2xxx_slave_destroy(struct scsi_device *);
  86. static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
  87. void (*fn)(struct scsi_cmnd *));
  88. static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
  89. void (*fn)(struct scsi_cmnd *));
  90. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  91. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  92. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  93. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  94. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  95. static int qla2x00_change_queue_depth(struct scsi_device *, int);
  96. static int qla2x00_change_queue_type(struct scsi_device *, int);
  97. static struct scsi_host_template qla2x00_driver_template = {
  98. .module = THIS_MODULE,
  99. .name = QLA2XXX_DRIVER_NAME,
  100. .queuecommand = qla2x00_queuecommand,
  101. .eh_abort_handler = qla2xxx_eh_abort,
  102. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  103. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  104. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  105. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  106. .slave_configure = qla2xxx_slave_configure,
  107. .slave_alloc = qla2xxx_slave_alloc,
  108. .slave_destroy = qla2xxx_slave_destroy,
  109. .scan_finished = qla2xxx_scan_finished,
  110. .scan_start = qla2xxx_scan_start,
  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. /*
  118. * The RISC allows for each command to transfer (2^32-1) bytes of data,
  119. * which equates to 0x800000 sectors.
  120. */
  121. .max_sectors = 0xFFFF,
  122. .shost_attrs = qla2x00_host_attrs,
  123. };
  124. struct scsi_host_template qla24xx_driver_template = {
  125. .module = THIS_MODULE,
  126. .name = QLA2XXX_DRIVER_NAME,
  127. .queuecommand = qla24xx_queuecommand,
  128. .eh_abort_handler = qla2xxx_eh_abort,
  129. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  130. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  131. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  132. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  133. .slave_configure = qla2xxx_slave_configure,
  134. .slave_alloc = qla2xxx_slave_alloc,
  135. .slave_destroy = qla2xxx_slave_destroy,
  136. .scan_finished = qla2xxx_scan_finished,
  137. .scan_start = qla2xxx_scan_start,
  138. .change_queue_depth = qla2x00_change_queue_depth,
  139. .change_queue_type = qla2x00_change_queue_type,
  140. .this_id = -1,
  141. .cmd_per_lun = 3,
  142. .use_clustering = ENABLE_CLUSTERING,
  143. .sg_tablesize = SG_ALL,
  144. .max_sectors = 0xFFFF,
  145. .shost_attrs = qla2x00_host_attrs,
  146. };
  147. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  148. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  149. /* TODO Convert to inlines
  150. *
  151. * Timer routines
  152. */
  153. __inline__ void
  154. qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
  155. {
  156. init_timer(&ha->timer);
  157. ha->timer.expires = jiffies + interval * HZ;
  158. ha->timer.data = (unsigned long)ha;
  159. ha->timer.function = (void (*)(unsigned long))func;
  160. add_timer(&ha->timer);
  161. ha->timer_active = 1;
  162. }
  163. static inline void
  164. qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
  165. {
  166. mod_timer(&ha->timer, jiffies + interval * HZ);
  167. }
  168. static __inline__ void
  169. qla2x00_stop_timer(scsi_qla_host_t *ha)
  170. {
  171. del_timer_sync(&ha->timer);
  172. ha->timer_active = 0;
  173. }
  174. static int qla2x00_do_dpc(void *data);
  175. static void qla2x00_rst_aen(scsi_qla_host_t *);
  176. static int qla2x00_mem_alloc(scsi_qla_host_t *);
  177. static void qla2x00_mem_free(scsi_qla_host_t *ha);
  178. static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
  179. /* -------------------------------------------------------------------------- */
  180. static char *
  181. qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
  182. {
  183. static char *pci_bus_modes[] = {
  184. "33", "66", "100", "133",
  185. };
  186. uint16_t pci_bus;
  187. strcpy(str, "PCI");
  188. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  189. if (pci_bus) {
  190. strcat(str, "-X (");
  191. strcat(str, pci_bus_modes[pci_bus]);
  192. } else {
  193. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  194. strcat(str, " (");
  195. strcat(str, pci_bus_modes[pci_bus]);
  196. }
  197. strcat(str, " MHz)");
  198. return (str);
  199. }
  200. static char *
  201. qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
  202. {
  203. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  204. uint32_t pci_bus;
  205. int pcie_reg;
  206. pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
  207. if (pcie_reg) {
  208. char lwstr[6];
  209. uint16_t pcie_lstat, lspeed, lwidth;
  210. pcie_reg += 0x12;
  211. pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
  212. lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
  213. lwidth = (pcie_lstat &
  214. (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
  215. strcpy(str, "PCIe (");
  216. if (lspeed == 1)
  217. strcat(str, "2.5GT/s ");
  218. else if (lspeed == 2)
  219. strcat(str, "5.0GT/s ");
  220. else
  221. strcat(str, "<unknown> ");
  222. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  223. strcat(str, lwstr);
  224. return str;
  225. }
  226. strcpy(str, "PCI");
  227. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  228. if (pci_bus == 0 || pci_bus == 8) {
  229. strcat(str, " (");
  230. strcat(str, pci_bus_modes[pci_bus >> 3]);
  231. } else {
  232. strcat(str, "-X ");
  233. if (pci_bus & BIT_2)
  234. strcat(str, "Mode 2");
  235. else
  236. strcat(str, "Mode 1");
  237. strcat(str, " (");
  238. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  239. }
  240. strcat(str, " MHz)");
  241. return str;
  242. }
  243. static char *
  244. qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
  245. {
  246. char un_str[10];
  247. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  248. ha->fw_minor_version,
  249. ha->fw_subminor_version);
  250. if (ha->fw_attributes & BIT_9) {
  251. strcat(str, "FLX");
  252. return (str);
  253. }
  254. switch (ha->fw_attributes & 0xFF) {
  255. case 0x7:
  256. strcat(str, "EF");
  257. break;
  258. case 0x17:
  259. strcat(str, "TP");
  260. break;
  261. case 0x37:
  262. strcat(str, "IP");
  263. break;
  264. case 0x77:
  265. strcat(str, "VI");
  266. break;
  267. default:
  268. sprintf(un_str, "(%x)", ha->fw_attributes);
  269. strcat(str, un_str);
  270. break;
  271. }
  272. if (ha->fw_attributes & 0x100)
  273. strcat(str, "X");
  274. return (str);
  275. }
  276. static char *
  277. qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
  278. {
  279. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  280. ha->fw_minor_version,
  281. ha->fw_subminor_version);
  282. if (ha->fw_attributes & BIT_0)
  283. strcat(str, "[Class 2] ");
  284. if (ha->fw_attributes & BIT_1)
  285. strcat(str, "[IP] ");
  286. if (ha->fw_attributes & BIT_2)
  287. strcat(str, "[Multi-ID] ");
  288. if (ha->fw_attributes & BIT_3)
  289. strcat(str, "[SB-2] ");
  290. if (ha->fw_attributes & BIT_4)
  291. strcat(str, "[T10 CRC] ");
  292. if (ha->fw_attributes & BIT_5)
  293. strcat(str, "[VI] ");
  294. if (ha->fw_attributes & BIT_10)
  295. strcat(str, "[84XX] ");
  296. if (ha->fw_attributes & BIT_13)
  297. strcat(str, "[Experimental]");
  298. return str;
  299. }
  300. static inline srb_t *
  301. qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
  302. struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  303. {
  304. srb_t *sp;
  305. sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  306. if (!sp)
  307. return sp;
  308. sp->ha = ha;
  309. sp->fcport = fcport;
  310. sp->cmd = cmd;
  311. sp->flags = 0;
  312. CMD_SP(cmd) = (void *)sp;
  313. cmd->scsi_done = done;
  314. return sp;
  315. }
  316. static int
  317. qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  318. {
  319. scsi_qla_host_t *ha = shost_priv(cmd->device->host);
  320. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  321. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  322. srb_t *sp;
  323. int rval;
  324. if (unlikely(pci_channel_offline(ha->pdev))) {
  325. cmd->result = DID_REQUEUE << 16;
  326. goto qc_fail_command;
  327. }
  328. rval = fc_remote_port_chkready(rport);
  329. if (rval) {
  330. cmd->result = rval;
  331. goto qc_fail_command;
  332. }
  333. /* Close window on fcport/rport state-transitioning. */
  334. if (fcport->drport) {
  335. cmd->result = DID_IMM_RETRY << 16;
  336. goto qc_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 qc_fail_command;
  343. }
  344. goto qc_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 qc_host_busy_lock;
  350. rval = qla2x00_start_scsi(sp);
  351. if (rval != QLA_SUCCESS)
  352. goto qc_host_busy_free_sp;
  353. spin_lock_irq(ha->host->host_lock);
  354. return 0;
  355. qc_host_busy_free_sp:
  356. qla2x00_sp_free_dma(ha, sp);
  357. mempool_free(sp, ha->srb_mempool);
  358. qc_host_busy_lock:
  359. spin_lock_irq(ha->host->host_lock);
  360. qc_host_busy:
  361. return SCSI_MLQUEUE_HOST_BUSY;
  362. qc_fail_command:
  363. done(cmd);
  364. return 0;
  365. }
  366. static int
  367. qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  368. {
  369. scsi_qla_host_t *ha = shost_priv(cmd->device->host);
  370. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  371. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  372. srb_t *sp;
  373. int rval;
  374. scsi_qla_host_t *pha = to_qla_parent(ha);
  375. if (unlikely(pci_channel_offline(pha->pdev))) {
  376. cmd->result = DID_REQUEUE << 16;
  377. goto qc24_fail_command;
  378. }
  379. rval = fc_remote_port_chkready(rport);
  380. if (rval) {
  381. cmd->result = rval;
  382. goto qc24_fail_command;
  383. }
  384. /* Close window on fcport/rport state-transitioning. */
  385. if (fcport->drport) {
  386. cmd->result = DID_IMM_RETRY << 16;
  387. goto qc24_fail_command;
  388. }
  389. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  390. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  391. atomic_read(&pha->loop_state) == LOOP_DEAD) {
  392. cmd->result = DID_NO_CONNECT << 16;
  393. goto qc24_fail_command;
  394. }
  395. goto qc24_host_busy;
  396. }
  397. spin_unlock_irq(ha->host->host_lock);
  398. sp = qla2x00_get_new_sp(pha, fcport, cmd, done);
  399. if (!sp)
  400. goto qc24_host_busy_lock;
  401. rval = qla24xx_start_scsi(sp);
  402. if (rval != QLA_SUCCESS)
  403. goto qc24_host_busy_free_sp;
  404. spin_lock_irq(ha->host->host_lock);
  405. return 0;
  406. qc24_host_busy_free_sp:
  407. qla2x00_sp_free_dma(pha, sp);
  408. mempool_free(sp, pha->srb_mempool);
  409. qc24_host_busy_lock:
  410. spin_lock_irq(ha->host->host_lock);
  411. qc24_host_busy:
  412. return SCSI_MLQUEUE_HOST_BUSY;
  413. qc24_fail_command:
  414. done(cmd);
  415. return 0;
  416. }
  417. /*
  418. * qla2x00_eh_wait_on_command
  419. * Waits for the command to be returned by the Firmware for some
  420. * max time.
  421. *
  422. * Input:
  423. * ha = actual ha whose done queue will contain the command
  424. * returned by firmware.
  425. * cmd = Scsi Command to wait on.
  426. * flag = Abort/Reset(Bus or Device Reset)
  427. *
  428. * Return:
  429. * Not Found : 0
  430. * Found : 1
  431. */
  432. static int
  433. qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
  434. {
  435. #define ABORT_POLLING_PERIOD 1000
  436. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  437. unsigned long wait_iter = ABORT_WAIT_ITER;
  438. int ret = QLA_SUCCESS;
  439. while (CMD_SP(cmd)) {
  440. msleep(ABORT_POLLING_PERIOD);
  441. if (--wait_iter)
  442. break;
  443. }
  444. if (CMD_SP(cmd))
  445. ret = QLA_FUNCTION_FAILED;
  446. return ret;
  447. }
  448. /*
  449. * qla2x00_wait_for_hba_online
  450. * Wait till the HBA is online after going through
  451. * <= MAX_RETRIES_OF_ISP_ABORT or
  452. * finally HBA is disabled ie marked offline
  453. *
  454. * Input:
  455. * ha - pointer to host adapter structure
  456. *
  457. * Note:
  458. * Does context switching-Release SPIN_LOCK
  459. * (if any) before calling this routine.
  460. *
  461. * Return:
  462. * Success (Adapter is online) : 0
  463. * Failed (Adapter is offline/disabled) : 1
  464. */
  465. int
  466. qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
  467. {
  468. int return_status;
  469. unsigned long wait_online;
  470. scsi_qla_host_t *pha = to_qla_parent(ha);
  471. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  472. while (((test_bit(ISP_ABORT_NEEDED, &pha->dpc_flags)) ||
  473. test_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags) ||
  474. test_bit(ISP_ABORT_RETRY, &pha->dpc_flags) ||
  475. pha->dpc_active) && time_before(jiffies, wait_online)) {
  476. msleep(1000);
  477. }
  478. if (pha->flags.online)
  479. return_status = QLA_SUCCESS;
  480. else
  481. return_status = QLA_FUNCTION_FAILED;
  482. return (return_status);
  483. }
  484. /*
  485. * qla2x00_wait_for_loop_ready
  486. * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
  487. * to be in LOOP_READY state.
  488. * Input:
  489. * ha - pointer to host adapter structure
  490. *
  491. * Note:
  492. * Does context switching-Release SPIN_LOCK
  493. * (if any) before calling this routine.
  494. *
  495. *
  496. * Return:
  497. * Success (LOOP_READY) : 0
  498. * Failed (LOOP_NOT_READY) : 1
  499. */
  500. static inline int
  501. qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
  502. {
  503. int return_status = QLA_SUCCESS;
  504. unsigned long loop_timeout ;
  505. scsi_qla_host_t *pha = to_qla_parent(ha);
  506. /* wait for 5 min at the max for loop to be ready */
  507. loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  508. while ((!atomic_read(&pha->loop_down_timer) &&
  509. atomic_read(&pha->loop_state) == LOOP_DOWN) ||
  510. atomic_read(&pha->loop_state) != LOOP_READY) {
  511. if (atomic_read(&pha->loop_state) == LOOP_DEAD) {
  512. return_status = QLA_FUNCTION_FAILED;
  513. break;
  514. }
  515. msleep(1000);
  516. if (time_after_eq(jiffies, loop_timeout)) {
  517. return_status = QLA_FUNCTION_FAILED;
  518. break;
  519. }
  520. }
  521. return (return_status);
  522. }
  523. void
  524. qla2x00_abort_fcport_cmds(fc_port_t *fcport)
  525. {
  526. int cnt;
  527. unsigned long flags;
  528. srb_t *sp;
  529. scsi_qla_host_t *ha = fcport->ha;
  530. scsi_qla_host_t *pha = to_qla_parent(ha);
  531. spin_lock_irqsave(&pha->hardware_lock, flags);
  532. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  533. sp = pha->outstanding_cmds[cnt];
  534. if (!sp)
  535. continue;
  536. if (sp->fcport != fcport)
  537. continue;
  538. spin_unlock_irqrestore(&pha->hardware_lock, flags);
  539. if (ha->isp_ops->abort_command(ha, sp)) {
  540. DEBUG2(qla_printk(KERN_WARNING, ha,
  541. "Abort failed -- %lx\n", sp->cmd->serial_number));
  542. } else {
  543. if (qla2x00_eh_wait_on_command(ha, sp->cmd) !=
  544. QLA_SUCCESS)
  545. DEBUG2(qla_printk(KERN_WARNING, ha,
  546. "Abort failed while waiting -- %lx\n",
  547. sp->cmd->serial_number));
  548. }
  549. spin_lock_irqsave(&pha->hardware_lock, flags);
  550. }
  551. spin_unlock_irqrestore(&pha->hardware_lock, flags);
  552. }
  553. static void
  554. qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
  555. {
  556. struct Scsi_Host *shost = cmnd->device->host;
  557. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  558. unsigned long flags;
  559. spin_lock_irqsave(shost->host_lock, flags);
  560. while (rport->port_state == FC_PORTSTATE_BLOCKED) {
  561. spin_unlock_irqrestore(shost->host_lock, flags);
  562. msleep(1000);
  563. spin_lock_irqsave(shost->host_lock, flags);
  564. }
  565. spin_unlock_irqrestore(shost->host_lock, flags);
  566. return;
  567. }
  568. /**************************************************************************
  569. * qla2xxx_eh_abort
  570. *
  571. * Description:
  572. * The abort function will abort the specified command.
  573. *
  574. * Input:
  575. * cmd = Linux SCSI command packet to be aborted.
  576. *
  577. * Returns:
  578. * Either SUCCESS or FAILED.
  579. *
  580. * Note:
  581. * Only return FAILED if command not returned by firmware.
  582. **************************************************************************/
  583. static int
  584. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  585. {
  586. scsi_qla_host_t *ha = shost_priv(cmd->device->host);
  587. srb_t *sp;
  588. int ret, i;
  589. unsigned int id, lun;
  590. unsigned long serial;
  591. unsigned long flags;
  592. int wait = 0;
  593. scsi_qla_host_t *pha = to_qla_parent(ha);
  594. qla2x00_block_error_handler(cmd);
  595. if (!CMD_SP(cmd))
  596. return SUCCESS;
  597. ret = SUCCESS;
  598. id = cmd->device->id;
  599. lun = cmd->device->lun;
  600. serial = cmd->serial_number;
  601. /* Check active list for command command. */
  602. spin_lock_irqsave(&pha->hardware_lock, flags);
  603. for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
  604. sp = pha->outstanding_cmds[i];
  605. if (sp == NULL)
  606. continue;
  607. if (sp->cmd != cmd)
  608. continue;
  609. DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n",
  610. __func__, ha->host_no, sp, serial));
  611. spin_unlock_irqrestore(&pha->hardware_lock, flags);
  612. if (ha->isp_ops->abort_command(ha, sp)) {
  613. DEBUG2(printk("%s(%ld): abort_command "
  614. "mbx failed.\n", __func__, ha->host_no));
  615. } else {
  616. DEBUG3(printk("%s(%ld): abort_command "
  617. "mbx success.\n", __func__, ha->host_no));
  618. wait = 1;
  619. }
  620. spin_lock_irqsave(&pha->hardware_lock, flags);
  621. break;
  622. }
  623. spin_unlock_irqrestore(&pha->hardware_lock, flags);
  624. /* Wait for the command to be returned. */
  625. if (wait) {
  626. if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
  627. qla_printk(KERN_ERR, ha,
  628. "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
  629. "%x.\n", ha->host_no, id, lun, serial, ret);
  630. ret = FAILED;
  631. }
  632. }
  633. qla_printk(KERN_INFO, ha,
  634. "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
  635. ha->host_no, id, lun, wait, serial, ret);
  636. return ret;
  637. }
  638. enum nexus_wait_type {
  639. WAIT_HOST = 0,
  640. WAIT_TARGET,
  641. WAIT_LUN,
  642. };
  643. static int
  644. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha, unsigned int t,
  645. unsigned int l, enum nexus_wait_type type)
  646. {
  647. int cnt, match, status;
  648. srb_t *sp;
  649. unsigned long flags;
  650. scsi_qla_host_t *pha = to_qla_parent(ha);
  651. status = QLA_SUCCESS;
  652. spin_lock_irqsave(&pha->hardware_lock, flags);
  653. for (cnt = 1; status == QLA_SUCCESS && cnt < MAX_OUTSTANDING_COMMANDS;
  654. cnt++) {
  655. sp = pha->outstanding_cmds[cnt];
  656. if (!sp)
  657. continue;
  658. if (ha->vp_idx != sp->ha->vp_idx)
  659. continue;
  660. match = 0;
  661. switch (type) {
  662. case WAIT_HOST:
  663. match = 1;
  664. break;
  665. case WAIT_TARGET:
  666. match = sp->cmd->device->id == t;
  667. break;
  668. case WAIT_LUN:
  669. match = (sp->cmd->device->id == t &&
  670. sp->cmd->device->lun == l);
  671. break;
  672. }
  673. if (!match)
  674. continue;
  675. spin_unlock_irqrestore(&pha->hardware_lock, flags);
  676. status = qla2x00_eh_wait_on_command(ha, sp->cmd);
  677. spin_lock_irqsave(&pha->hardware_lock, flags);
  678. }
  679. spin_unlock_irqrestore(&pha->hardware_lock, flags);
  680. return status;
  681. }
  682. static char *reset_errors[] = {
  683. "HBA not online",
  684. "HBA not ready",
  685. "Task management failed",
  686. "Waiting for command completions",
  687. };
  688. static int
  689. __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
  690. struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
  691. {
  692. scsi_qla_host_t *ha = shost_priv(cmd->device->host);
  693. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  694. int err;
  695. qla2x00_block_error_handler(cmd);
  696. if (!fcport)
  697. return FAILED;
  698. qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
  699. ha->host_no, cmd->device->id, cmd->device->lun, name);
  700. err = 0;
  701. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
  702. goto eh_reset_failed;
  703. err = 1;
  704. if (qla2x00_wait_for_loop_ready(ha) != QLA_SUCCESS)
  705. goto eh_reset_failed;
  706. err = 2;
  707. if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
  708. goto eh_reset_failed;
  709. err = 3;
  710. if (qla2x00_eh_wait_for_pending_commands(ha, cmd->device->id,
  711. cmd->device->lun, type) != QLA_SUCCESS)
  712. goto eh_reset_failed;
  713. qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
  714. ha->host_no, cmd->device->id, cmd->device->lun, name);
  715. return SUCCESS;
  716. eh_reset_failed:
  717. qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n",
  718. ha->host_no, cmd->device->id, cmd->device->lun, name,
  719. reset_errors[err]);
  720. return FAILED;
  721. }
  722. static int
  723. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  724. {
  725. scsi_qla_host_t *ha = shost_priv(cmd->device->host);
  726. return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
  727. ha->isp_ops->lun_reset);
  728. }
  729. static int
  730. qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
  731. {
  732. scsi_qla_host_t *ha = shost_priv(cmd->device->host);
  733. return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
  734. ha->isp_ops->target_reset);
  735. }
  736. /**************************************************************************
  737. * qla2xxx_eh_bus_reset
  738. *
  739. * Description:
  740. * The bus reset function will reset the bus and abort any executing
  741. * commands.
  742. *
  743. * Input:
  744. * cmd = Linux SCSI command packet of the command that cause the
  745. * bus reset.
  746. *
  747. * Returns:
  748. * SUCCESS/FAILURE (defined as macro in scsi.h).
  749. *
  750. **************************************************************************/
  751. static int
  752. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  753. {
  754. scsi_qla_host_t *ha = shost_priv(cmd->device->host);
  755. scsi_qla_host_t *pha = to_qla_parent(ha);
  756. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  757. int ret = FAILED;
  758. unsigned int id, lun;
  759. unsigned long serial;
  760. qla2x00_block_error_handler(cmd);
  761. id = cmd->device->id;
  762. lun = cmd->device->lun;
  763. serial = cmd->serial_number;
  764. if (!fcport)
  765. return ret;
  766. qla_printk(KERN_INFO, ha,
  767. "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
  768. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
  769. DEBUG2(printk("%s failed:board disabled\n",__func__));
  770. goto eh_bus_reset_done;
  771. }
  772. if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
  773. if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
  774. ret = SUCCESS;
  775. }
  776. if (ret == FAILED)
  777. goto eh_bus_reset_done;
  778. /* Flush outstanding commands. */
  779. if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) !=
  780. QLA_SUCCESS)
  781. ret = FAILED;
  782. eh_bus_reset_done:
  783. qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
  784. (ret == FAILED) ? "failed" : "succeded");
  785. return ret;
  786. }
  787. /**************************************************************************
  788. * qla2xxx_eh_host_reset
  789. *
  790. * Description:
  791. * The reset function will reset the Adapter.
  792. *
  793. * Input:
  794. * cmd = Linux SCSI command packet of the command that cause the
  795. * adapter reset.
  796. *
  797. * Returns:
  798. * Either SUCCESS or FAILED.
  799. *
  800. * Note:
  801. **************************************************************************/
  802. static int
  803. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  804. {
  805. scsi_qla_host_t *ha = shost_priv(cmd->device->host);
  806. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  807. int ret = FAILED;
  808. unsigned int id, lun;
  809. unsigned long serial;
  810. scsi_qla_host_t *pha = to_qla_parent(ha);
  811. qla2x00_block_error_handler(cmd);
  812. id = cmd->device->id;
  813. lun = cmd->device->lun;
  814. serial = cmd->serial_number;
  815. if (!fcport)
  816. return ret;
  817. qla_printk(KERN_INFO, ha,
  818. "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
  819. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
  820. goto eh_host_reset_lock;
  821. /*
  822. * Fixme-may be dpc thread is active and processing
  823. * loop_resync,so wait a while for it to
  824. * be completed and then issue big hammer.Otherwise
  825. * it may cause I/O failure as big hammer marks the
  826. * devices as lost kicking of the port_down_timer
  827. * while dpc is stuck for the mailbox to complete.
  828. */
  829. qla2x00_wait_for_loop_ready(ha);
  830. set_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
  831. if (qla2x00_abort_isp(pha)) {
  832. clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
  833. /* failed. schedule dpc to try */
  834. set_bit(ISP_ABORT_NEEDED, &pha->dpc_flags);
  835. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
  836. goto eh_host_reset_lock;
  837. }
  838. clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
  839. /* Waiting for our command in done_queue to be returned to OS.*/
  840. if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) ==
  841. QLA_SUCCESS)
  842. ret = SUCCESS;
  843. if (ha->parent)
  844. qla2x00_vp_abort_isp(ha);
  845. eh_host_reset_lock:
  846. qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
  847. (ret == FAILED) ? "failed" : "succeded");
  848. return ret;
  849. }
  850. /*
  851. * qla2x00_loop_reset
  852. * Issue loop reset.
  853. *
  854. * Input:
  855. * ha = adapter block pointer.
  856. *
  857. * Returns:
  858. * 0 = success
  859. */
  860. int
  861. qla2x00_loop_reset(scsi_qla_host_t *ha)
  862. {
  863. int ret;
  864. struct fc_port *fcport;
  865. if (ha->flags.enable_lip_full_login) {
  866. ret = qla2x00_full_login_lip(ha);
  867. if (ret != QLA_SUCCESS) {
  868. DEBUG2_3(printk("%s(%ld): bus_reset failed: "
  869. "full_login_lip=%d.\n", __func__, ha->host_no,
  870. ret));
  871. }
  872. atomic_set(&ha->loop_state, LOOP_DOWN);
  873. atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
  874. qla2x00_mark_all_devices_lost(ha, 0);
  875. qla2x00_wait_for_loop_ready(ha);
  876. }
  877. if (ha->flags.enable_lip_reset) {
  878. ret = qla2x00_lip_reset(ha);
  879. if (ret != QLA_SUCCESS) {
  880. DEBUG2_3(printk("%s(%ld): bus_reset failed: "
  881. "lip_reset=%d.\n", __func__, ha->host_no, ret));
  882. }
  883. qla2x00_wait_for_loop_ready(ha);
  884. }
  885. if (ha->flags.enable_target_reset) {
  886. list_for_each_entry(fcport, &ha->fcports, list) {
  887. if (fcport->port_type != FCT_TARGET)
  888. continue;
  889. ret = ha->isp_ops->target_reset(fcport, 0);
  890. if (ret != QLA_SUCCESS) {
  891. DEBUG2_3(printk("%s(%ld): bus_reset failed: "
  892. "target_reset=%d d_id=%x.\n", __func__,
  893. ha->host_no, ret, fcport->d_id.b24));
  894. }
  895. }
  896. }
  897. /* Issue marker command only when we are going to start the I/O */
  898. ha->marker_needed = 1;
  899. return QLA_SUCCESS;
  900. }
  901. void
  902. qla2x00_abort_all_cmds(scsi_qla_host_t *ha, int res)
  903. {
  904. int cnt;
  905. unsigned long flags;
  906. srb_t *sp;
  907. spin_lock_irqsave(&ha->hardware_lock, flags);
  908. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  909. sp = ha->outstanding_cmds[cnt];
  910. if (sp) {
  911. ha->outstanding_cmds[cnt] = NULL;
  912. sp->flags = 0;
  913. sp->cmd->result = res;
  914. sp->cmd->host_scribble = (unsigned char *)NULL;
  915. qla2x00_sp_compl(ha, sp);
  916. }
  917. }
  918. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  919. }
  920. static int
  921. qla2xxx_slave_alloc(struct scsi_device *sdev)
  922. {
  923. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  924. if (!rport || fc_remote_port_chkready(rport))
  925. return -ENXIO;
  926. sdev->hostdata = *(fc_port_t **)rport->dd_data;
  927. return 0;
  928. }
  929. static int
  930. qla2xxx_slave_configure(struct scsi_device *sdev)
  931. {
  932. scsi_qla_host_t *ha = shost_priv(sdev->host);
  933. struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
  934. if (sdev->tagged_supported)
  935. scsi_activate_tcq(sdev, ha->max_q_depth);
  936. else
  937. scsi_deactivate_tcq(sdev, ha->max_q_depth);
  938. rport->dev_loss_tmo = ha->port_down_retry_count;
  939. return 0;
  940. }
  941. static void
  942. qla2xxx_slave_destroy(struct scsi_device *sdev)
  943. {
  944. sdev->hostdata = NULL;
  945. }
  946. static int
  947. qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
  948. {
  949. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  950. return sdev->queue_depth;
  951. }
  952. static int
  953. qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
  954. {
  955. if (sdev->tagged_supported) {
  956. scsi_set_tag_type(sdev, tag_type);
  957. if (tag_type)
  958. scsi_activate_tcq(sdev, sdev->queue_depth);
  959. else
  960. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  961. } else
  962. tag_type = 0;
  963. return tag_type;
  964. }
  965. /**
  966. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  967. * @ha: HA context
  968. *
  969. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  970. * supported addressing method.
  971. */
  972. static void
  973. qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
  974. {
  975. /* Assume a 32bit DMA mask. */
  976. ha->flags.enable_64bit_addressing = 0;
  977. if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
  978. /* Any upper-dword bits set? */
  979. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  980. !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
  981. /* Ok, a 64bit DMA mask is applicable. */
  982. ha->flags.enable_64bit_addressing = 1;
  983. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  984. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  985. return;
  986. }
  987. }
  988. dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
  989. pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
  990. }
  991. static void
  992. qla2x00_enable_intrs(scsi_qla_host_t *ha)
  993. {
  994. unsigned long flags = 0;
  995. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  996. spin_lock_irqsave(&ha->hardware_lock, flags);
  997. ha->interrupts_on = 1;
  998. /* enable risc and host interrupts */
  999. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1000. RD_REG_WORD(&reg->ictrl);
  1001. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1002. }
  1003. static void
  1004. qla2x00_disable_intrs(scsi_qla_host_t *ha)
  1005. {
  1006. unsigned long flags = 0;
  1007. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1008. spin_lock_irqsave(&ha->hardware_lock, flags);
  1009. ha->interrupts_on = 0;
  1010. /* disable risc and host interrupts */
  1011. WRT_REG_WORD(&reg->ictrl, 0);
  1012. RD_REG_WORD(&reg->ictrl);
  1013. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1014. }
  1015. static void
  1016. qla24xx_enable_intrs(scsi_qla_host_t *ha)
  1017. {
  1018. unsigned long flags = 0;
  1019. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1020. spin_lock_irqsave(&ha->hardware_lock, flags);
  1021. ha->interrupts_on = 1;
  1022. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1023. RD_REG_DWORD(&reg->ictrl);
  1024. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1025. }
  1026. static void
  1027. qla24xx_disable_intrs(scsi_qla_host_t *ha)
  1028. {
  1029. unsigned long flags = 0;
  1030. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1031. spin_lock_irqsave(&ha->hardware_lock, flags);
  1032. ha->interrupts_on = 0;
  1033. WRT_REG_DWORD(&reg->ictrl, 0);
  1034. RD_REG_DWORD(&reg->ictrl);
  1035. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1036. }
  1037. static struct isp_operations qla2100_isp_ops = {
  1038. .pci_config = qla2100_pci_config,
  1039. .reset_chip = qla2x00_reset_chip,
  1040. .chip_diag = qla2x00_chip_diag,
  1041. .config_rings = qla2x00_config_rings,
  1042. .reset_adapter = qla2x00_reset_adapter,
  1043. .nvram_config = qla2x00_nvram_config,
  1044. .update_fw_options = qla2x00_update_fw_options,
  1045. .load_risc = qla2x00_load_risc,
  1046. .pci_info_str = qla2x00_pci_info_str,
  1047. .fw_version_str = qla2x00_fw_version_str,
  1048. .intr_handler = qla2100_intr_handler,
  1049. .enable_intrs = qla2x00_enable_intrs,
  1050. .disable_intrs = qla2x00_disable_intrs,
  1051. .abort_command = qla2x00_abort_command,
  1052. .target_reset = qla2x00_abort_target,
  1053. .lun_reset = qla2x00_lun_reset,
  1054. .fabric_login = qla2x00_login_fabric,
  1055. .fabric_logout = qla2x00_fabric_logout,
  1056. .calc_req_entries = qla2x00_calc_iocbs_32,
  1057. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1058. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1059. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1060. .read_nvram = qla2x00_read_nvram_data,
  1061. .write_nvram = qla2x00_write_nvram_data,
  1062. .fw_dump = qla2100_fw_dump,
  1063. .beacon_on = NULL,
  1064. .beacon_off = NULL,
  1065. .beacon_blink = NULL,
  1066. .read_optrom = qla2x00_read_optrom_data,
  1067. .write_optrom = qla2x00_write_optrom_data,
  1068. .get_flash_version = qla2x00_get_flash_version,
  1069. };
  1070. static struct isp_operations qla2300_isp_ops = {
  1071. .pci_config = qla2300_pci_config,
  1072. .reset_chip = qla2x00_reset_chip,
  1073. .chip_diag = qla2x00_chip_diag,
  1074. .config_rings = qla2x00_config_rings,
  1075. .reset_adapter = qla2x00_reset_adapter,
  1076. .nvram_config = qla2x00_nvram_config,
  1077. .update_fw_options = qla2x00_update_fw_options,
  1078. .load_risc = qla2x00_load_risc,
  1079. .pci_info_str = qla2x00_pci_info_str,
  1080. .fw_version_str = qla2x00_fw_version_str,
  1081. .intr_handler = qla2300_intr_handler,
  1082. .enable_intrs = qla2x00_enable_intrs,
  1083. .disable_intrs = qla2x00_disable_intrs,
  1084. .abort_command = qla2x00_abort_command,
  1085. .target_reset = qla2x00_abort_target,
  1086. .lun_reset = qla2x00_lun_reset,
  1087. .fabric_login = qla2x00_login_fabric,
  1088. .fabric_logout = qla2x00_fabric_logout,
  1089. .calc_req_entries = qla2x00_calc_iocbs_32,
  1090. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1091. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1092. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1093. .read_nvram = qla2x00_read_nvram_data,
  1094. .write_nvram = qla2x00_write_nvram_data,
  1095. .fw_dump = qla2300_fw_dump,
  1096. .beacon_on = qla2x00_beacon_on,
  1097. .beacon_off = qla2x00_beacon_off,
  1098. .beacon_blink = qla2x00_beacon_blink,
  1099. .read_optrom = qla2x00_read_optrom_data,
  1100. .write_optrom = qla2x00_write_optrom_data,
  1101. .get_flash_version = qla2x00_get_flash_version,
  1102. };
  1103. static struct isp_operations qla24xx_isp_ops = {
  1104. .pci_config = qla24xx_pci_config,
  1105. .reset_chip = qla24xx_reset_chip,
  1106. .chip_diag = qla24xx_chip_diag,
  1107. .config_rings = qla24xx_config_rings,
  1108. .reset_adapter = qla24xx_reset_adapter,
  1109. .nvram_config = qla24xx_nvram_config,
  1110. .update_fw_options = qla24xx_update_fw_options,
  1111. .load_risc = qla24xx_load_risc,
  1112. .pci_info_str = qla24xx_pci_info_str,
  1113. .fw_version_str = qla24xx_fw_version_str,
  1114. .intr_handler = qla24xx_intr_handler,
  1115. .enable_intrs = qla24xx_enable_intrs,
  1116. .disable_intrs = qla24xx_disable_intrs,
  1117. .abort_command = qla24xx_abort_command,
  1118. .target_reset = qla24xx_abort_target,
  1119. .lun_reset = qla24xx_lun_reset,
  1120. .fabric_login = qla24xx_login_fabric,
  1121. .fabric_logout = qla24xx_fabric_logout,
  1122. .calc_req_entries = NULL,
  1123. .build_iocbs = NULL,
  1124. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1125. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1126. .read_nvram = qla24xx_read_nvram_data,
  1127. .write_nvram = qla24xx_write_nvram_data,
  1128. .fw_dump = qla24xx_fw_dump,
  1129. .beacon_on = qla24xx_beacon_on,
  1130. .beacon_off = qla24xx_beacon_off,
  1131. .beacon_blink = qla24xx_beacon_blink,
  1132. .read_optrom = qla24xx_read_optrom_data,
  1133. .write_optrom = qla24xx_write_optrom_data,
  1134. .get_flash_version = qla24xx_get_flash_version,
  1135. };
  1136. static struct isp_operations qla25xx_isp_ops = {
  1137. .pci_config = qla25xx_pci_config,
  1138. .reset_chip = qla24xx_reset_chip,
  1139. .chip_diag = qla24xx_chip_diag,
  1140. .config_rings = qla24xx_config_rings,
  1141. .reset_adapter = qla24xx_reset_adapter,
  1142. .nvram_config = qla24xx_nvram_config,
  1143. .update_fw_options = qla24xx_update_fw_options,
  1144. .load_risc = qla24xx_load_risc,
  1145. .pci_info_str = qla24xx_pci_info_str,
  1146. .fw_version_str = qla24xx_fw_version_str,
  1147. .intr_handler = qla24xx_intr_handler,
  1148. .enable_intrs = qla24xx_enable_intrs,
  1149. .disable_intrs = qla24xx_disable_intrs,
  1150. .abort_command = qla24xx_abort_command,
  1151. .target_reset = qla24xx_abort_target,
  1152. .lun_reset = qla24xx_lun_reset,
  1153. .fabric_login = qla24xx_login_fabric,
  1154. .fabric_logout = qla24xx_fabric_logout,
  1155. .calc_req_entries = NULL,
  1156. .build_iocbs = NULL,
  1157. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1158. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1159. .read_nvram = qla25xx_read_nvram_data,
  1160. .write_nvram = qla25xx_write_nvram_data,
  1161. .fw_dump = qla25xx_fw_dump,
  1162. .beacon_on = qla24xx_beacon_on,
  1163. .beacon_off = qla24xx_beacon_off,
  1164. .beacon_blink = qla24xx_beacon_blink,
  1165. .read_optrom = qla25xx_read_optrom_data,
  1166. .write_optrom = qla24xx_write_optrom_data,
  1167. .get_flash_version = qla24xx_get_flash_version,
  1168. };
  1169. static inline void
  1170. qla2x00_set_isp_flags(scsi_qla_host_t *ha)
  1171. {
  1172. ha->device_type = DT_EXTENDED_IDS;
  1173. switch (ha->pdev->device) {
  1174. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1175. ha->device_type |= DT_ISP2100;
  1176. ha->device_type &= ~DT_EXTENDED_IDS;
  1177. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1178. break;
  1179. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1180. ha->device_type |= DT_ISP2200;
  1181. ha->device_type &= ~DT_EXTENDED_IDS;
  1182. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1183. break;
  1184. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1185. ha->device_type |= DT_ISP2300;
  1186. ha->device_type |= DT_ZIO_SUPPORTED;
  1187. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1188. break;
  1189. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1190. ha->device_type |= DT_ISP2312;
  1191. ha->device_type |= DT_ZIO_SUPPORTED;
  1192. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1193. break;
  1194. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1195. ha->device_type |= DT_ISP2322;
  1196. ha->device_type |= DT_ZIO_SUPPORTED;
  1197. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1198. ha->pdev->subsystem_device == 0x0170)
  1199. ha->device_type |= DT_OEM_001;
  1200. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1201. break;
  1202. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1203. ha->device_type |= DT_ISP6312;
  1204. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1205. break;
  1206. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1207. ha->device_type |= DT_ISP6322;
  1208. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1209. break;
  1210. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1211. ha->device_type |= DT_ISP2422;
  1212. ha->device_type |= DT_ZIO_SUPPORTED;
  1213. ha->device_type |= DT_FWI2;
  1214. ha->device_type |= DT_IIDMA;
  1215. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1216. break;
  1217. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1218. ha->device_type |= DT_ISP2432;
  1219. ha->device_type |= DT_ZIO_SUPPORTED;
  1220. ha->device_type |= DT_FWI2;
  1221. ha->device_type |= DT_IIDMA;
  1222. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1223. break;
  1224. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1225. ha->device_type |= DT_ISP8432;
  1226. ha->device_type |= DT_ZIO_SUPPORTED;
  1227. ha->device_type |= DT_FWI2;
  1228. ha->device_type |= DT_IIDMA;
  1229. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1230. break;
  1231. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1232. ha->device_type |= DT_ISP5422;
  1233. ha->device_type |= DT_FWI2;
  1234. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1235. break;
  1236. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  1237. ha->device_type |= DT_ISP5432;
  1238. ha->device_type |= DT_FWI2;
  1239. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1240. break;
  1241. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  1242. ha->device_type |= DT_ISP2532;
  1243. ha->device_type |= DT_ZIO_SUPPORTED;
  1244. ha->device_type |= DT_FWI2;
  1245. ha->device_type |= DT_IIDMA;
  1246. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1247. break;
  1248. }
  1249. }
  1250. static int
  1251. qla2x00_iospace_config(scsi_qla_host_t *ha)
  1252. {
  1253. resource_size_t pio;
  1254. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1255. QLA2XXX_DRIVER_NAME)) {
  1256. qla_printk(KERN_WARNING, ha,
  1257. "Failed to reserve PIO/MMIO regions (%s)\n",
  1258. pci_name(ha->pdev));
  1259. goto iospace_error_exit;
  1260. }
  1261. if (!(ha->bars & 1))
  1262. goto skip_pio;
  1263. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1264. pio = pci_resource_start(ha->pdev, 0);
  1265. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1266. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1267. qla_printk(KERN_WARNING, ha,
  1268. "Invalid PCI I/O region size (%s)...\n",
  1269. pci_name(ha->pdev));
  1270. pio = 0;
  1271. }
  1272. } else {
  1273. qla_printk(KERN_WARNING, ha,
  1274. "region #0 not a PIO resource (%s)...\n",
  1275. pci_name(ha->pdev));
  1276. pio = 0;
  1277. }
  1278. ha->pio_address = pio;
  1279. skip_pio:
  1280. /* Use MMIO operations for all accesses. */
  1281. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1282. qla_printk(KERN_ERR, ha,
  1283. "region #1 not an MMIO resource (%s), aborting\n",
  1284. pci_name(ha->pdev));
  1285. goto iospace_error_exit;
  1286. }
  1287. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1288. qla_printk(KERN_ERR, ha,
  1289. "Invalid PCI mem region size (%s), aborting\n",
  1290. pci_name(ha->pdev));
  1291. goto iospace_error_exit;
  1292. }
  1293. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1294. if (!ha->iobase) {
  1295. qla_printk(KERN_ERR, ha,
  1296. "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
  1297. goto iospace_error_exit;
  1298. }
  1299. return (0);
  1300. iospace_error_exit:
  1301. return (-ENOMEM);
  1302. }
  1303. static void
  1304. qla2xxx_scan_start(struct Scsi_Host *shost)
  1305. {
  1306. scsi_qla_host_t *ha = shost_priv(shost);
  1307. set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  1308. set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
  1309. set_bit(RSCN_UPDATE, &ha->dpc_flags);
  1310. }
  1311. static int
  1312. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1313. {
  1314. scsi_qla_host_t *ha = shost_priv(shost);
  1315. if (!ha->host)
  1316. return 1;
  1317. if (time > ha->loop_reset_delay * HZ)
  1318. return 1;
  1319. return atomic_read(&ha->loop_state) == LOOP_READY;
  1320. }
  1321. /*
  1322. * PCI driver interface
  1323. */
  1324. static int __devinit
  1325. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  1326. {
  1327. int ret = -ENODEV;
  1328. struct Scsi_Host *host;
  1329. scsi_qla_host_t *ha;
  1330. char pci_info[30];
  1331. char fw_str[30];
  1332. struct scsi_host_template *sht;
  1333. int bars, mem_only = 0;
  1334. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  1335. sht = &qla2x00_driver_template;
  1336. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  1337. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  1338. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  1339. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  1340. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  1341. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532) {
  1342. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1343. sht = &qla24xx_driver_template;
  1344. mem_only = 1;
  1345. }
  1346. if (mem_only) {
  1347. if (pci_enable_device_mem(pdev))
  1348. goto probe_out;
  1349. } else {
  1350. if (pci_enable_device(pdev))
  1351. goto probe_out;
  1352. }
  1353. if (pci_find_aer_capability(pdev))
  1354. if (pci_enable_pcie_error_reporting(pdev))
  1355. goto probe_out;
  1356. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  1357. if (host == NULL) {
  1358. printk(KERN_WARNING
  1359. "qla2xxx: Couldn't allocate host from scsi layer!\n");
  1360. goto probe_disable_device;
  1361. }
  1362. /* Clear our data area */
  1363. ha = shost_priv(host);
  1364. memset(ha, 0, sizeof(scsi_qla_host_t));
  1365. ha->pdev = pdev;
  1366. ha->host = host;
  1367. ha->host_no = host->host_no;
  1368. sprintf(ha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, ha->host_no);
  1369. ha->parent = NULL;
  1370. ha->bars = bars;
  1371. ha->mem_only = mem_only;
  1372. spin_lock_init(&ha->hardware_lock);
  1373. /* Set ISP-type information. */
  1374. qla2x00_set_isp_flags(ha);
  1375. /* Configure PCI I/O space */
  1376. ret = qla2x00_iospace_config(ha);
  1377. if (ret)
  1378. goto probe_failed;
  1379. qla_printk(KERN_INFO, ha,
  1380. "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
  1381. ha->iobase);
  1382. ha->prev_topology = 0;
  1383. ha->init_cb_size = sizeof(init_cb_t);
  1384. ha->mgmt_svr_loop_id = MANAGEMENT_SERVER + ha->vp_idx;
  1385. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  1386. ha->optrom_size = OPTROM_SIZE_2300;
  1387. ha->max_q_depth = MAX_Q_DEPTH;
  1388. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  1389. ha->max_q_depth = ql2xmaxqdepth;
  1390. /* Assign ISP specific operations. */
  1391. if (IS_QLA2100(ha)) {
  1392. host->max_id = MAX_TARGETS_2100;
  1393. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  1394. ha->request_q_length = REQUEST_ENTRY_CNT_2100;
  1395. ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
  1396. ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
  1397. host->sg_tablesize = 32;
  1398. ha->gid_list_info_size = 4;
  1399. ha->isp_ops = &qla2100_isp_ops;
  1400. } else if (IS_QLA2200(ha)) {
  1401. host->max_id = MAX_TARGETS_2200;
  1402. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1403. ha->request_q_length = REQUEST_ENTRY_CNT_2200;
  1404. ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
  1405. ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
  1406. ha->gid_list_info_size = 4;
  1407. ha->isp_ops = &qla2100_isp_ops;
  1408. } else if (IS_QLA23XX(ha)) {
  1409. host->max_id = MAX_TARGETS_2200;
  1410. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1411. ha->request_q_length = REQUEST_ENTRY_CNT_2200;
  1412. ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
  1413. ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
  1414. ha->gid_list_info_size = 6;
  1415. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1416. ha->optrom_size = OPTROM_SIZE_2322;
  1417. ha->isp_ops = &qla2300_isp_ops;
  1418. } else if (IS_QLA24XX_TYPE(ha)) {
  1419. host->max_id = MAX_TARGETS_2200;
  1420. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1421. ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
  1422. ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
  1423. ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
  1424. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1425. ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
  1426. ha->gid_list_info_size = 8;
  1427. ha->optrom_size = OPTROM_SIZE_24XX;
  1428. ha->isp_ops = &qla24xx_isp_ops;
  1429. } else if (IS_QLA25XX(ha)) {
  1430. host->max_id = MAX_TARGETS_2200;
  1431. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1432. ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
  1433. ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
  1434. ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
  1435. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1436. ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
  1437. ha->gid_list_info_size = 8;
  1438. ha->optrom_size = OPTROM_SIZE_25XX;
  1439. ha->isp_ops = &qla25xx_isp_ops;
  1440. ha->hw_event_start = PCI_FUNC(pdev->devfn) ?
  1441. FA_HW_EVENT1_ADDR: FA_HW_EVENT0_ADDR;
  1442. }
  1443. host->can_queue = ha->request_q_length + 128;
  1444. mutex_init(&ha->vport_lock);
  1445. init_completion(&ha->mbx_cmd_comp);
  1446. complete(&ha->mbx_cmd_comp);
  1447. init_completion(&ha->mbx_intr_comp);
  1448. INIT_LIST_HEAD(&ha->list);
  1449. INIT_LIST_HEAD(&ha->fcports);
  1450. INIT_LIST_HEAD(&ha->vp_list);
  1451. INIT_LIST_HEAD(&ha->work_list);
  1452. set_bit(0, (unsigned long *) ha->vp_idx_map);
  1453. qla2x00_config_dma_addressing(ha);
  1454. if (qla2x00_mem_alloc(ha)) {
  1455. qla_printk(KERN_WARNING, ha,
  1456. "[ERROR] Failed to allocate memory for adapter\n");
  1457. ret = -ENOMEM;
  1458. goto probe_failed;
  1459. }
  1460. if (qla2x00_initialize_adapter(ha)) {
  1461. qla_printk(KERN_WARNING, ha,
  1462. "Failed to initialize adapter\n");
  1463. DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
  1464. "Adapter flags %x.\n",
  1465. ha->host_no, ha->device_flags));
  1466. ret = -ENODEV;
  1467. goto probe_failed;
  1468. }
  1469. /*
  1470. * Startup the kernel thread for this host adapter
  1471. */
  1472. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  1473. "%s_dpc", ha->host_str);
  1474. if (IS_ERR(ha->dpc_thread)) {
  1475. qla_printk(KERN_WARNING, ha,
  1476. "Unable to start DPC thread!\n");
  1477. ret = PTR_ERR(ha->dpc_thread);
  1478. goto probe_failed;
  1479. }
  1480. host->this_id = 255;
  1481. host->cmd_per_lun = 3;
  1482. host->unique_id = host->host_no;
  1483. host->max_cmd_len = MAX_CMDSZ;
  1484. host->max_channel = MAX_BUSES - 1;
  1485. host->max_lun = MAX_LUNS;
  1486. host->transportt = qla2xxx_transport_template;
  1487. ret = qla2x00_request_irqs(ha);
  1488. if (ret)
  1489. goto probe_failed;
  1490. /* Initialized the timer */
  1491. qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
  1492. DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
  1493. ha->host_no, ha));
  1494. pci_set_drvdata(pdev, ha);
  1495. ha->flags.init_done = 1;
  1496. ha->flags.online = 1;
  1497. ret = scsi_add_host(host, &pdev->dev);
  1498. if (ret)
  1499. goto probe_failed;
  1500. scsi_scan_host(host);
  1501. qla2x00_alloc_sysfs_attr(ha);
  1502. qla2x00_init_host_attr(ha);
  1503. qla2x00_dfs_setup(ha);
  1504. qla_printk(KERN_INFO, ha, "\n"
  1505. " QLogic Fibre Channel HBA Driver: %s\n"
  1506. " QLogic %s - %s\n"
  1507. " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
  1508. qla2x00_version_str, ha->model_number,
  1509. ha->model_desc ? ha->model_desc: "", pdev->device,
  1510. ha->isp_ops->pci_info_str(ha, pci_info), pci_name(pdev),
  1511. ha->flags.enable_64bit_addressing ? '+': '-', ha->host_no,
  1512. ha->isp_ops->fw_version_str(ha, fw_str));
  1513. return 0;
  1514. probe_failed:
  1515. qla2x00_free_device(ha);
  1516. scsi_host_put(host);
  1517. probe_disable_device:
  1518. pci_disable_device(pdev);
  1519. probe_out:
  1520. return ret;
  1521. }
  1522. static void
  1523. qla2x00_remove_one(struct pci_dev *pdev)
  1524. {
  1525. scsi_qla_host_t *ha;
  1526. ha = pci_get_drvdata(pdev);
  1527. qla2x00_dfs_remove(ha);
  1528. qla84xx_put_chip(ha);
  1529. qla2x00_free_sysfs_attr(ha);
  1530. fc_remove_host(ha->host);
  1531. scsi_remove_host(ha->host);
  1532. qla2x00_free_device(ha);
  1533. scsi_host_put(ha->host);
  1534. pci_disable_device(pdev);
  1535. pci_set_drvdata(pdev, NULL);
  1536. }
  1537. static void
  1538. qla2x00_free_device(scsi_qla_host_t *ha)
  1539. {
  1540. qla2x00_abort_all_cmds(ha, DID_NO_CONNECT << 16);
  1541. /* Disable timer */
  1542. if (ha->timer_active)
  1543. qla2x00_stop_timer(ha);
  1544. ha->flags.online = 0;
  1545. /* Kill the kernel thread for this host */
  1546. if (ha->dpc_thread) {
  1547. struct task_struct *t = ha->dpc_thread;
  1548. /*
  1549. * qla2xxx_wake_dpc checks for ->dpc_thread
  1550. * so we need to zero it out.
  1551. */
  1552. ha->dpc_thread = NULL;
  1553. kthread_stop(t);
  1554. }
  1555. if (ha->flags.fce_enabled)
  1556. qla2x00_disable_fce_trace(ha, NULL, NULL);
  1557. if (ha->eft)
  1558. qla2x00_disable_eft_trace(ha);
  1559. /* Stop currently executing firmware. */
  1560. qla2x00_try_to_stop_firmware(ha);
  1561. /* turn-off interrupts on the card */
  1562. if (ha->interrupts_on)
  1563. ha->isp_ops->disable_intrs(ha);
  1564. qla2x00_mem_free(ha);
  1565. qla2x00_free_irqs(ha);
  1566. /* release io space registers */
  1567. if (ha->iobase)
  1568. iounmap(ha->iobase);
  1569. pci_release_selected_regions(ha->pdev, ha->bars);
  1570. }
  1571. static inline void
  1572. qla2x00_schedule_rport_del(struct scsi_qla_host *ha, fc_port_t *fcport,
  1573. int defer)
  1574. {
  1575. struct fc_rport *rport;
  1576. scsi_qla_host_t *pha = to_qla_parent(ha);
  1577. if (!fcport->rport)
  1578. return;
  1579. rport = fcport->rport;
  1580. if (defer) {
  1581. spin_lock_irq(ha->host->host_lock);
  1582. fcport->drport = rport;
  1583. spin_unlock_irq(ha->host->host_lock);
  1584. set_bit(FCPORT_UPDATE_NEEDED, &pha->dpc_flags);
  1585. qla2xxx_wake_dpc(pha);
  1586. } else
  1587. fc_remote_port_delete(rport);
  1588. }
  1589. /*
  1590. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  1591. *
  1592. * Input: ha = adapter block pointer. fcport = port structure pointer.
  1593. *
  1594. * Return: None.
  1595. *
  1596. * Context:
  1597. */
  1598. void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
  1599. int do_login, int defer)
  1600. {
  1601. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  1602. ha->vp_idx == fcport->vp_idx)
  1603. qla2x00_schedule_rport_del(ha, fcport, defer);
  1604. /*
  1605. * We may need to retry the login, so don't change the state of the
  1606. * port but do the retries.
  1607. */
  1608. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  1609. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1610. if (!do_login)
  1611. return;
  1612. if (fcport->login_retry == 0) {
  1613. fcport->login_retry = ha->login_retry_count;
  1614. set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
  1615. DEBUG(printk("scsi(%ld): Port login retry: "
  1616. "%02x%02x%02x%02x%02x%02x%02x%02x, "
  1617. "id = 0x%04x retry cnt=%d\n",
  1618. ha->host_no,
  1619. fcport->port_name[0],
  1620. fcport->port_name[1],
  1621. fcport->port_name[2],
  1622. fcport->port_name[3],
  1623. fcport->port_name[4],
  1624. fcport->port_name[5],
  1625. fcport->port_name[6],
  1626. fcport->port_name[7],
  1627. fcport->loop_id,
  1628. fcport->login_retry));
  1629. }
  1630. }
  1631. /*
  1632. * qla2x00_mark_all_devices_lost
  1633. * Updates fcport state when device goes offline.
  1634. *
  1635. * Input:
  1636. * ha = adapter block pointer.
  1637. * fcport = port structure pointer.
  1638. *
  1639. * Return:
  1640. * None.
  1641. *
  1642. * Context:
  1643. */
  1644. void
  1645. qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
  1646. {
  1647. fc_port_t *fcport;
  1648. scsi_qla_host_t *pha = to_qla_parent(ha);
  1649. list_for_each_entry(fcport, &pha->fcports, list) {
  1650. if (ha->vp_idx != fcport->vp_idx)
  1651. continue;
  1652. /*
  1653. * No point in marking the device as lost, if the device is
  1654. * already DEAD.
  1655. */
  1656. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  1657. continue;
  1658. if (atomic_read(&fcport->state) == FCS_ONLINE)
  1659. qla2x00_schedule_rport_del(ha, fcport, defer);
  1660. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1661. }
  1662. }
  1663. /*
  1664. * qla2x00_mem_alloc
  1665. * Allocates adapter memory.
  1666. *
  1667. * Returns:
  1668. * 0 = success.
  1669. * !0 = failure.
  1670. */
  1671. static int
  1672. qla2x00_mem_alloc(scsi_qla_host_t *ha)
  1673. {
  1674. char name[16];
  1675. ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
  1676. (ha->request_q_length + 1) * sizeof(request_t), &ha->request_dma,
  1677. GFP_KERNEL);
  1678. if (!ha->request_ring)
  1679. goto fail;
  1680. ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
  1681. (ha->response_q_length + 1) * sizeof(response_t),
  1682. &ha->response_dma, GFP_KERNEL);
  1683. if (!ha->response_ring)
  1684. goto fail_free_request_ring;
  1685. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
  1686. &ha->gid_list_dma, GFP_KERNEL);
  1687. if (!ha->gid_list)
  1688. goto fail_free_response_ring;
  1689. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  1690. &ha->init_cb_dma, GFP_KERNEL);
  1691. if (!ha->init_cb)
  1692. goto fail_free_gid_list;
  1693. snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME,
  1694. ha->host_no);
  1695. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  1696. DMA_POOL_SIZE, 8, 0);
  1697. if (!ha->s_dma_pool)
  1698. goto fail_free_init_cb;
  1699. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  1700. if (!ha->srb_mempool)
  1701. goto fail_free_s_dma_pool;
  1702. /* Get memory for cached NVRAM */
  1703. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  1704. if (!ha->nvram)
  1705. goto fail_free_srb_mempool;
  1706. /* Allocate memory for SNS commands */
  1707. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1708. /* Get consistent memory allocated for SNS commands */
  1709. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  1710. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  1711. if (!ha->sns_cmd)
  1712. goto fail_free_nvram;
  1713. } else {
  1714. /* Get consistent memory allocated for MS IOCB */
  1715. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1716. &ha->ms_iocb_dma);
  1717. if (!ha->ms_iocb)
  1718. goto fail_free_nvram;
  1719. /* Get consistent memory allocated for CT SNS commands */
  1720. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  1721. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  1722. if (!ha->ct_sns)
  1723. goto fail_free_ms_iocb;
  1724. }
  1725. return 0;
  1726. fail_free_ms_iocb:
  1727. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  1728. ha->ms_iocb = NULL;
  1729. ha->ms_iocb_dma = 0;
  1730. fail_free_nvram:
  1731. kfree(ha->nvram);
  1732. ha->nvram = NULL;
  1733. fail_free_srb_mempool:
  1734. mempool_destroy(ha->srb_mempool);
  1735. ha->srb_mempool = NULL;
  1736. fail_free_s_dma_pool:
  1737. dma_pool_destroy(ha->s_dma_pool);
  1738. ha->s_dma_pool = NULL;
  1739. fail_free_init_cb:
  1740. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  1741. ha->init_cb_dma);
  1742. ha->init_cb = NULL;
  1743. ha->init_cb_dma = 0;
  1744. fail_free_gid_list:
  1745. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  1746. ha->gid_list_dma);
  1747. ha->gid_list = NULL;
  1748. ha->gid_list_dma = 0;
  1749. fail_free_response_ring:
  1750. dma_free_coherent(&ha->pdev->dev, (ha->response_q_length + 1) *
  1751. sizeof(response_t), ha->response_ring, ha->response_dma);
  1752. ha->response_ring = NULL;
  1753. ha->response_dma = 0;
  1754. fail_free_request_ring:
  1755. dma_free_coherent(&ha->pdev->dev, (ha->request_q_length + 1) *
  1756. sizeof(request_t), ha->request_ring, ha->request_dma);
  1757. ha->request_ring = NULL;
  1758. ha->request_dma = 0;
  1759. fail:
  1760. return -ENOMEM;
  1761. }
  1762. /*
  1763. * qla2x00_mem_free
  1764. * Frees all adapter allocated memory.
  1765. *
  1766. * Input:
  1767. * ha = adapter block pointer.
  1768. */
  1769. static void
  1770. qla2x00_mem_free(scsi_qla_host_t *ha)
  1771. {
  1772. struct list_head *fcpl, *fcptemp;
  1773. fc_port_t *fcport;
  1774. if (ha->srb_mempool)
  1775. mempool_destroy(ha->srb_mempool);
  1776. if (ha->fce)
  1777. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  1778. ha->fce_dma);
  1779. if (ha->fw_dump) {
  1780. if (ha->eft)
  1781. dma_free_coherent(&ha->pdev->dev,
  1782. ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
  1783. vfree(ha->fw_dump);
  1784. }
  1785. if (ha->sns_cmd)
  1786. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  1787. ha->sns_cmd, ha->sns_cmd_dma);
  1788. if (ha->ct_sns)
  1789. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  1790. ha->ct_sns, ha->ct_sns_dma);
  1791. if (ha->sfp_data)
  1792. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  1793. if (ha->ms_iocb)
  1794. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  1795. if (ha->s_dma_pool)
  1796. dma_pool_destroy(ha->s_dma_pool);
  1797. if (ha->init_cb)
  1798. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  1799. ha->init_cb, ha->init_cb_dma);
  1800. if (ha->gid_list)
  1801. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  1802. ha->gid_list_dma);
  1803. if (ha->response_ring)
  1804. dma_free_coherent(&ha->pdev->dev,
  1805. (ha->response_q_length + 1) * sizeof(response_t),
  1806. ha->response_ring, ha->response_dma);
  1807. if (ha->request_ring)
  1808. dma_free_coherent(&ha->pdev->dev,
  1809. (ha->request_q_length + 1) * sizeof(request_t),
  1810. ha->request_ring, ha->request_dma);
  1811. ha->srb_mempool = NULL;
  1812. ha->eft = NULL;
  1813. ha->eft_dma = 0;
  1814. ha->sns_cmd = NULL;
  1815. ha->sns_cmd_dma = 0;
  1816. ha->ct_sns = NULL;
  1817. ha->ct_sns_dma = 0;
  1818. ha->ms_iocb = NULL;
  1819. ha->ms_iocb_dma = 0;
  1820. ha->init_cb = NULL;
  1821. ha->init_cb_dma = 0;
  1822. ha->s_dma_pool = NULL;
  1823. ha->gid_list = NULL;
  1824. ha->gid_list_dma = 0;
  1825. ha->response_ring = NULL;
  1826. ha->response_dma = 0;
  1827. ha->request_ring = NULL;
  1828. ha->request_dma = 0;
  1829. list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
  1830. fcport = list_entry(fcpl, fc_port_t, list);
  1831. /* fc ports */
  1832. list_del_init(&fcport->list);
  1833. kfree(fcport);
  1834. }
  1835. INIT_LIST_HEAD(&ha->fcports);
  1836. ha->fw_dump = NULL;
  1837. ha->fw_dumped = 0;
  1838. ha->fw_dump_reading = 0;
  1839. vfree(ha->optrom_buffer);
  1840. kfree(ha->nvram);
  1841. }
  1842. static struct qla_work_evt *
  1843. qla2x00_alloc_work(struct scsi_qla_host *ha, enum qla_work_type type,
  1844. int locked)
  1845. {
  1846. struct qla_work_evt *e;
  1847. e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
  1848. GFP_KERNEL);
  1849. if (!e)
  1850. return NULL;
  1851. INIT_LIST_HEAD(&e->list);
  1852. e->type = type;
  1853. e->flags = QLA_EVT_FLAG_FREE;
  1854. return e;
  1855. }
  1856. static int
  1857. qla2x00_post_work(struct scsi_qla_host *ha, struct qla_work_evt *e, int locked)
  1858. {
  1859. unsigned long uninitialized_var(flags);
  1860. scsi_qla_host_t *pha = to_qla_parent(ha);
  1861. if (!locked)
  1862. spin_lock_irqsave(&pha->hardware_lock, flags);
  1863. list_add_tail(&e->list, &ha->work_list);
  1864. qla2xxx_wake_dpc(ha);
  1865. if (!locked)
  1866. spin_unlock_irqrestore(&pha->hardware_lock, flags);
  1867. return QLA_SUCCESS;
  1868. }
  1869. int
  1870. qla2x00_post_aen_work(struct scsi_qla_host *ha, enum fc_host_event_code code,
  1871. u32 data)
  1872. {
  1873. struct qla_work_evt *e;
  1874. e = qla2x00_alloc_work(ha, QLA_EVT_AEN, 1);
  1875. if (!e)
  1876. return QLA_FUNCTION_FAILED;
  1877. e->u.aen.code = code;
  1878. e->u.aen.data = data;
  1879. return qla2x00_post_work(ha, e, 1);
  1880. }
  1881. int
  1882. qla2x00_post_hwe_work(struct scsi_qla_host *ha, uint16_t code, uint16_t d1,
  1883. uint16_t d2, uint16_t d3)
  1884. {
  1885. struct qla_work_evt *e;
  1886. e = qla2x00_alloc_work(ha, QLA_EVT_HWE_LOG, 1);
  1887. if (!e)
  1888. return QLA_FUNCTION_FAILED;
  1889. e->u.hwe.code = code;
  1890. e->u.hwe.d1 = d1;
  1891. e->u.hwe.d2 = d2;
  1892. e->u.hwe.d3 = d3;
  1893. return qla2x00_post_work(ha, e, 1);
  1894. }
  1895. static void
  1896. qla2x00_do_work(struct scsi_qla_host *ha)
  1897. {
  1898. struct qla_work_evt *e;
  1899. scsi_qla_host_t *pha = to_qla_parent(ha);
  1900. spin_lock_irq(&pha->hardware_lock);
  1901. while (!list_empty(&ha->work_list)) {
  1902. e = list_entry(ha->work_list.next, struct qla_work_evt, list);
  1903. list_del_init(&e->list);
  1904. spin_unlock_irq(&pha->hardware_lock);
  1905. switch (e->type) {
  1906. case QLA_EVT_AEN:
  1907. fc_host_post_event(ha->host, fc_get_event_number(),
  1908. e->u.aen.code, e->u.aen.data);
  1909. break;
  1910. case QLA_EVT_HWE_LOG:
  1911. qla2xxx_hw_event_log(ha, e->u.hwe.code, e->u.hwe.d1,
  1912. e->u.hwe.d2, e->u.hwe.d3);
  1913. break;
  1914. }
  1915. if (e->flags & QLA_EVT_FLAG_FREE)
  1916. kfree(e);
  1917. spin_lock_irq(&pha->hardware_lock);
  1918. }
  1919. spin_unlock_irq(&pha->hardware_lock);
  1920. }
  1921. /**************************************************************************
  1922. * qla2x00_do_dpc
  1923. * This kernel thread is a task that is schedule by the interrupt handler
  1924. * to perform the background processing for interrupts.
  1925. *
  1926. * Notes:
  1927. * This task always run in the context of a kernel thread. It
  1928. * is kick-off by the driver's detect code and starts up
  1929. * up one per adapter. It immediately goes to sleep and waits for
  1930. * some fibre event. When either the interrupt handler or
  1931. * the timer routine detects a event it will one of the task
  1932. * bits then wake us up.
  1933. **************************************************************************/
  1934. static int
  1935. qla2x00_do_dpc(void *data)
  1936. {
  1937. int rval;
  1938. scsi_qla_host_t *ha;
  1939. fc_port_t *fcport;
  1940. uint8_t status;
  1941. uint16_t next_loopid;
  1942. struct scsi_qla_host *vha;
  1943. int i;
  1944. ha = (scsi_qla_host_t *)data;
  1945. set_user_nice(current, -20);
  1946. while (!kthread_should_stop()) {
  1947. DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
  1948. set_current_state(TASK_INTERRUPTIBLE);
  1949. schedule();
  1950. __set_current_state(TASK_RUNNING);
  1951. DEBUG3(printk("qla2x00: DPC handler waking up\n"));
  1952. /* Initialization not yet finished. Don't do anything yet. */
  1953. if (!ha->flags.init_done)
  1954. continue;
  1955. DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
  1956. ha->dpc_active = 1;
  1957. if (ha->flags.mbox_busy) {
  1958. ha->dpc_active = 0;
  1959. continue;
  1960. }
  1961. qla2x00_do_work(ha);
  1962. if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
  1963. DEBUG(printk("scsi(%ld): dpc: sched "
  1964. "qla2x00_abort_isp ha = %p\n",
  1965. ha->host_no, ha));
  1966. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  1967. &ha->dpc_flags))) {
  1968. if (qla2x00_abort_isp(ha)) {
  1969. /* failed. retry later */
  1970. set_bit(ISP_ABORT_NEEDED,
  1971. &ha->dpc_flags);
  1972. }
  1973. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  1974. }
  1975. for_each_mapped_vp_idx(ha, i) {
  1976. list_for_each_entry(vha, &ha->vp_list,
  1977. vp_list) {
  1978. if (i == vha->vp_idx) {
  1979. set_bit(ISP_ABORT_NEEDED,
  1980. &vha->dpc_flags);
  1981. break;
  1982. }
  1983. }
  1984. }
  1985. DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
  1986. ha->host_no));
  1987. }
  1988. if (test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags)) {
  1989. qla2x00_update_fcports(ha);
  1990. clear_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags);
  1991. }
  1992. if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
  1993. (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
  1994. DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
  1995. ha->host_no));
  1996. qla2x00_rst_aen(ha);
  1997. clear_bit(RESET_ACTIVE, &ha->dpc_flags);
  1998. }
  1999. /* Retry each device up to login retry count */
  2000. if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
  2001. !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
  2002. atomic_read(&ha->loop_state) != LOOP_DOWN) {
  2003. DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
  2004. ha->host_no));
  2005. next_loopid = 0;
  2006. list_for_each_entry(fcport, &ha->fcports, list) {
  2007. /*
  2008. * If the port is not ONLINE then try to login
  2009. * to it if we haven't run out of retries.
  2010. */
  2011. if (atomic_read(&fcport->state) != FCS_ONLINE &&
  2012. fcport->login_retry) {
  2013. if (fcport->flags & FCF_FABRIC_DEVICE) {
  2014. if (fcport->flags &
  2015. FCF_TAPE_PRESENT)
  2016. ha->isp_ops->fabric_logout(
  2017. ha, fcport->loop_id,
  2018. fcport->d_id.b.domain,
  2019. fcport->d_id.b.area,
  2020. fcport->d_id.b.al_pa);
  2021. status = qla2x00_fabric_login(
  2022. ha, fcport, &next_loopid);
  2023. } else
  2024. status =
  2025. qla2x00_local_device_login(
  2026. ha, fcport);
  2027. fcport->login_retry--;
  2028. if (status == QLA_SUCCESS) {
  2029. fcport->old_loop_id = fcport->loop_id;
  2030. DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
  2031. ha->host_no, fcport->loop_id));
  2032. qla2x00_update_fcport(ha,
  2033. fcport);
  2034. } else if (status == 1) {
  2035. set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
  2036. /* retry the login again */
  2037. DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
  2038. ha->host_no,
  2039. fcport->login_retry, fcport->loop_id));
  2040. } else {
  2041. fcport->login_retry = 0;
  2042. }
  2043. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  2044. fcport->loop_id = FC_NO_LOOP_ID;
  2045. }
  2046. if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
  2047. break;
  2048. }
  2049. DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
  2050. ha->host_no));
  2051. }
  2052. if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
  2053. DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
  2054. ha->host_no));
  2055. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  2056. &ha->dpc_flags))) {
  2057. rval = qla2x00_loop_resync(ha);
  2058. clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
  2059. }
  2060. DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
  2061. ha->host_no));
  2062. }
  2063. if (!ha->interrupts_on)
  2064. ha->isp_ops->enable_intrs(ha);
  2065. if (test_and_clear_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags))
  2066. ha->isp_ops->beacon_blink(ha);
  2067. qla2x00_do_dpc_all_vps(ha);
  2068. ha->dpc_active = 0;
  2069. } /* End of while(1) */
  2070. DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
  2071. /*
  2072. * Make sure that nobody tries to wake us up again.
  2073. */
  2074. ha->dpc_active = 0;
  2075. return 0;
  2076. }
  2077. void
  2078. qla2xxx_wake_dpc(scsi_qla_host_t *ha)
  2079. {
  2080. if (ha->dpc_thread)
  2081. wake_up_process(ha->dpc_thread);
  2082. }
  2083. /*
  2084. * qla2x00_rst_aen
  2085. * Processes asynchronous reset.
  2086. *
  2087. * Input:
  2088. * ha = adapter block pointer.
  2089. */
  2090. static void
  2091. qla2x00_rst_aen(scsi_qla_host_t *ha)
  2092. {
  2093. if (ha->flags.online && !ha->flags.reset_active &&
  2094. !atomic_read(&ha->loop_down_timer) &&
  2095. !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
  2096. do {
  2097. clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
  2098. /*
  2099. * Issue marker command only when we are going to start
  2100. * the I/O.
  2101. */
  2102. ha->marker_needed = 1;
  2103. } while (!atomic_read(&ha->loop_down_timer) &&
  2104. (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
  2105. }
  2106. }
  2107. static void
  2108. qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
  2109. {
  2110. struct scsi_cmnd *cmd = sp->cmd;
  2111. if (sp->flags & SRB_DMA_VALID) {
  2112. scsi_dma_unmap(cmd);
  2113. sp->flags &= ~SRB_DMA_VALID;
  2114. }
  2115. CMD_SP(cmd) = NULL;
  2116. }
  2117. void
  2118. qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
  2119. {
  2120. struct scsi_cmnd *cmd = sp->cmd;
  2121. qla2x00_sp_free_dma(ha, sp);
  2122. mempool_free(sp, ha->srb_mempool);
  2123. cmd->scsi_done(cmd);
  2124. }
  2125. /**************************************************************************
  2126. * qla2x00_timer
  2127. *
  2128. * Description:
  2129. * One second timer
  2130. *
  2131. * Context: Interrupt
  2132. ***************************************************************************/
  2133. void
  2134. qla2x00_timer(scsi_qla_host_t *ha)
  2135. {
  2136. unsigned long cpu_flags = 0;
  2137. fc_port_t *fcport;
  2138. int start_dpc = 0;
  2139. int index;
  2140. srb_t *sp;
  2141. int t;
  2142. scsi_qla_host_t *pha = to_qla_parent(ha);
  2143. /*
  2144. * Ports - Port down timer.
  2145. *
  2146. * Whenever, a port is in the LOST state we start decrementing its port
  2147. * down timer every second until it reaches zero. Once it reaches zero
  2148. * the port it marked DEAD.
  2149. */
  2150. t = 0;
  2151. list_for_each_entry(fcport, &ha->fcports, list) {
  2152. if (fcport->port_type != FCT_TARGET)
  2153. continue;
  2154. if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  2155. if (atomic_read(&fcport->port_down_timer) == 0)
  2156. continue;
  2157. if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
  2158. atomic_set(&fcport->state, FCS_DEVICE_DEAD);
  2159. DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
  2160. "%d remaining\n",
  2161. ha->host_no,
  2162. t, atomic_read(&fcport->port_down_timer)));
  2163. }
  2164. t++;
  2165. } /* End of for fcport */
  2166. /* Loop down handler. */
  2167. if (atomic_read(&ha->loop_down_timer) > 0 &&
  2168. !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
  2169. if (atomic_read(&ha->loop_down_timer) ==
  2170. ha->loop_down_abort_time) {
  2171. DEBUG(printk("scsi(%ld): Loop Down - aborting the "
  2172. "queues before time expire\n",
  2173. ha->host_no));
  2174. if (!IS_QLA2100(ha) && ha->link_down_timeout)
  2175. atomic_set(&ha->loop_state, LOOP_DEAD);
  2176. /* Schedule an ISP abort to return any tape commands. */
  2177. /* NPIV - scan physical port only */
  2178. if (!ha->parent) {
  2179. spin_lock_irqsave(&ha->hardware_lock,
  2180. cpu_flags);
  2181. for (index = 1;
  2182. index < MAX_OUTSTANDING_COMMANDS;
  2183. index++) {
  2184. fc_port_t *sfcp;
  2185. sp = ha->outstanding_cmds[index];
  2186. if (!sp)
  2187. continue;
  2188. sfcp = sp->fcport;
  2189. if (!(sfcp->flags & FCF_TAPE_PRESENT))
  2190. continue;
  2191. set_bit(ISP_ABORT_NEEDED,
  2192. &ha->dpc_flags);
  2193. break;
  2194. }
  2195. spin_unlock_irqrestore(&ha->hardware_lock,
  2196. cpu_flags);
  2197. }
  2198. set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
  2199. start_dpc++;
  2200. }
  2201. /* if the loop has been down for 4 minutes, reinit adapter */
  2202. if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
  2203. DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
  2204. "restarting queues.\n",
  2205. ha->host_no));
  2206. set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
  2207. start_dpc++;
  2208. if (!(ha->device_flags & DFLG_NO_CABLE) &&
  2209. !ha->parent) {
  2210. DEBUG(printk("scsi(%ld): Loop down - "
  2211. "aborting ISP.\n",
  2212. ha->host_no));
  2213. qla_printk(KERN_WARNING, ha,
  2214. "Loop down - aborting ISP.\n");
  2215. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  2216. }
  2217. }
  2218. DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
  2219. ha->host_no,
  2220. atomic_read(&ha->loop_down_timer)));
  2221. }
  2222. /* Check if beacon LED needs to be blinked */
  2223. if (ha->beacon_blink_led == 1) {
  2224. set_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags);
  2225. start_dpc++;
  2226. }
  2227. /* Process any deferred work. */
  2228. if (!list_empty(&ha->work_list))
  2229. start_dpc++;
  2230. /* Schedule the DPC routine if needed */
  2231. if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
  2232. test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
  2233. test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags) ||
  2234. start_dpc ||
  2235. test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
  2236. test_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags) ||
  2237. test_bit(VP_DPC_NEEDED, &ha->dpc_flags) ||
  2238. test_bit(RELOGIN_NEEDED, &ha->dpc_flags)))
  2239. qla2xxx_wake_dpc(pha);
  2240. qla2x00_restart_timer(ha, WATCH_INTERVAL);
  2241. }
  2242. /* Firmware interface routines. */
  2243. #define FW_BLOBS 6
  2244. #define FW_ISP21XX 0
  2245. #define FW_ISP22XX 1
  2246. #define FW_ISP2300 2
  2247. #define FW_ISP2322 3
  2248. #define FW_ISP24XX 4
  2249. #define FW_ISP25XX 5
  2250. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  2251. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  2252. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  2253. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  2254. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  2255. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  2256. static DEFINE_MUTEX(qla_fw_lock);
  2257. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  2258. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  2259. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  2260. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  2261. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  2262. { .name = FW_FILE_ISP24XX, },
  2263. { .name = FW_FILE_ISP25XX, },
  2264. };
  2265. struct fw_blob *
  2266. qla2x00_request_firmware(scsi_qla_host_t *ha)
  2267. {
  2268. struct fw_blob *blob;
  2269. blob = NULL;
  2270. if (IS_QLA2100(ha)) {
  2271. blob = &qla_fw_blobs[FW_ISP21XX];
  2272. } else if (IS_QLA2200(ha)) {
  2273. blob = &qla_fw_blobs[FW_ISP22XX];
  2274. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  2275. blob = &qla_fw_blobs[FW_ISP2300];
  2276. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  2277. blob = &qla_fw_blobs[FW_ISP2322];
  2278. } else if (IS_QLA24XX_TYPE(ha)) {
  2279. blob = &qla_fw_blobs[FW_ISP24XX];
  2280. } else if (IS_QLA25XX(ha)) {
  2281. blob = &qla_fw_blobs[FW_ISP25XX];
  2282. }
  2283. mutex_lock(&qla_fw_lock);
  2284. if (blob->fw)
  2285. goto out;
  2286. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  2287. DEBUG2(printk("scsi(%ld): Failed to load firmware image "
  2288. "(%s).\n", ha->host_no, blob->name));
  2289. blob->fw = NULL;
  2290. blob = NULL;
  2291. goto out;
  2292. }
  2293. out:
  2294. mutex_unlock(&qla_fw_lock);
  2295. return blob;
  2296. }
  2297. static void
  2298. qla2x00_release_firmware(void)
  2299. {
  2300. int idx;
  2301. mutex_lock(&qla_fw_lock);
  2302. for (idx = 0; idx < FW_BLOBS; idx++)
  2303. if (qla_fw_blobs[idx].fw)
  2304. release_firmware(qla_fw_blobs[idx].fw);
  2305. mutex_unlock(&qla_fw_lock);
  2306. }
  2307. static pci_ers_result_t
  2308. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  2309. {
  2310. switch (state) {
  2311. case pci_channel_io_normal:
  2312. return PCI_ERS_RESULT_CAN_RECOVER;
  2313. case pci_channel_io_frozen:
  2314. pci_disable_device(pdev);
  2315. return PCI_ERS_RESULT_NEED_RESET;
  2316. case pci_channel_io_perm_failure:
  2317. qla2x00_remove_one(pdev);
  2318. return PCI_ERS_RESULT_DISCONNECT;
  2319. }
  2320. return PCI_ERS_RESULT_NEED_RESET;
  2321. }
  2322. static pci_ers_result_t
  2323. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  2324. {
  2325. int risc_paused = 0;
  2326. uint32_t stat;
  2327. unsigned long flags;
  2328. scsi_qla_host_t *ha = pci_get_drvdata(pdev);
  2329. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2330. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  2331. spin_lock_irqsave(&ha->hardware_lock, flags);
  2332. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  2333. stat = RD_REG_DWORD(&reg->hccr);
  2334. if (stat & HCCR_RISC_PAUSE)
  2335. risc_paused = 1;
  2336. } else if (IS_QLA23XX(ha)) {
  2337. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  2338. if (stat & HSR_RISC_PAUSED)
  2339. risc_paused = 1;
  2340. } else if (IS_FWI2_CAPABLE(ha)) {
  2341. stat = RD_REG_DWORD(&reg24->host_status);
  2342. if (stat & HSRX_RISC_PAUSED)
  2343. risc_paused = 1;
  2344. }
  2345. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2346. if (risc_paused) {
  2347. qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
  2348. "Dumping firmware!\n");
  2349. ha->isp_ops->fw_dump(ha, 0);
  2350. return PCI_ERS_RESULT_NEED_RESET;
  2351. } else
  2352. return PCI_ERS_RESULT_RECOVERED;
  2353. }
  2354. static pci_ers_result_t
  2355. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  2356. {
  2357. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  2358. scsi_qla_host_t *ha = pci_get_drvdata(pdev);
  2359. int rc;
  2360. if (ha->mem_only)
  2361. rc = pci_enable_device_mem(pdev);
  2362. else
  2363. rc = pci_enable_device(pdev);
  2364. if (rc) {
  2365. qla_printk(KERN_WARNING, ha,
  2366. "Can't re-enable PCI device after reset.\n");
  2367. return ret;
  2368. }
  2369. pci_set_master(pdev);
  2370. if (ha->isp_ops->pci_config(ha))
  2371. return ret;
  2372. set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  2373. if (qla2x00_abort_isp(ha)== QLA_SUCCESS)
  2374. ret = PCI_ERS_RESULT_RECOVERED;
  2375. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  2376. return ret;
  2377. }
  2378. static void
  2379. qla2xxx_pci_resume(struct pci_dev *pdev)
  2380. {
  2381. scsi_qla_host_t *ha = pci_get_drvdata(pdev);
  2382. int ret;
  2383. ret = qla2x00_wait_for_hba_online(ha);
  2384. if (ret != QLA_SUCCESS) {
  2385. qla_printk(KERN_ERR, ha,
  2386. "the device failed to resume I/O "
  2387. "from slot/link_reset");
  2388. }
  2389. pci_cleanup_aer_uncorrect_error_status(pdev);
  2390. }
  2391. static struct pci_error_handlers qla2xxx_err_handler = {
  2392. .error_detected = qla2xxx_pci_error_detected,
  2393. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  2394. .slot_reset = qla2xxx_pci_slot_reset,
  2395. .resume = qla2xxx_pci_resume,
  2396. };
  2397. static struct pci_device_id qla2xxx_pci_tbl[] = {
  2398. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  2399. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  2400. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  2401. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  2402. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  2403. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  2404. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  2405. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  2406. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  2407. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  2408. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  2409. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  2410. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  2411. { 0 },
  2412. };
  2413. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  2414. static struct pci_driver qla2xxx_pci_driver = {
  2415. .name = QLA2XXX_DRIVER_NAME,
  2416. .driver = {
  2417. .owner = THIS_MODULE,
  2418. },
  2419. .id_table = qla2xxx_pci_tbl,
  2420. .probe = qla2x00_probe_one,
  2421. .remove = qla2x00_remove_one,
  2422. .err_handler = &qla2xxx_err_handler,
  2423. };
  2424. /**
  2425. * qla2x00_module_init - Module initialization.
  2426. **/
  2427. static int __init
  2428. qla2x00_module_init(void)
  2429. {
  2430. int ret = 0;
  2431. /* Allocate cache for SRBs. */
  2432. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  2433. SLAB_HWCACHE_ALIGN, NULL);
  2434. if (srb_cachep == NULL) {
  2435. printk(KERN_ERR
  2436. "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
  2437. return -ENOMEM;
  2438. }
  2439. /* Derive version string. */
  2440. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  2441. if (ql2xextended_error_logging)
  2442. strcat(qla2x00_version_str, "-debug");
  2443. qla2xxx_transport_template =
  2444. fc_attach_transport(&qla2xxx_transport_functions);
  2445. if (!qla2xxx_transport_template) {
  2446. kmem_cache_destroy(srb_cachep);
  2447. return -ENODEV;
  2448. }
  2449. qla2xxx_transport_vport_template =
  2450. fc_attach_transport(&qla2xxx_transport_vport_functions);
  2451. if (!qla2xxx_transport_vport_template) {
  2452. kmem_cache_destroy(srb_cachep);
  2453. fc_release_transport(qla2xxx_transport_template);
  2454. return -ENODEV;
  2455. }
  2456. printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
  2457. qla2x00_version_str);
  2458. ret = pci_register_driver(&qla2xxx_pci_driver);
  2459. if (ret) {
  2460. kmem_cache_destroy(srb_cachep);
  2461. fc_release_transport(qla2xxx_transport_template);
  2462. fc_release_transport(qla2xxx_transport_vport_template);
  2463. }
  2464. return ret;
  2465. }
  2466. /**
  2467. * qla2x00_module_exit - Module cleanup.
  2468. **/
  2469. static void __exit
  2470. qla2x00_module_exit(void)
  2471. {
  2472. pci_unregister_driver(&qla2xxx_pci_driver);
  2473. qla2x00_release_firmware();
  2474. kmem_cache_destroy(srb_cachep);
  2475. fc_release_transport(qla2xxx_transport_template);
  2476. fc_release_transport(qla2xxx_transport_vport_template);
  2477. }
  2478. module_init(qla2x00_module_init);
  2479. module_exit(qla2x00_module_exit);
  2480. MODULE_AUTHOR("QLogic Corporation");
  2481. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  2482. MODULE_LICENSE("GPL");
  2483. MODULE_VERSION(QLA2XXX_VERSION);
  2484. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  2485. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  2486. MODULE_FIRMWARE(FW_FILE_ISP2300);
  2487. MODULE_FIRMWARE(FW_FILE_ISP2322);
  2488. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  2489. MODULE_FIRMWARE(FW_FILE_ISP25XX);