qla_os.c 75 KB

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