qla_os.c 76 KB

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