qla_os.c 75 KB

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