qla_os.c 77 KB

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