qla_os.c 74 KB

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