qla_os.c 77 KB

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