qla_os.c 75 KB

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