qla_os.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604
  1. /*
  2. * QLOGIC LINUX SOFTWARE
  3. *
  4. * QLogic ISP2x00 device driver for Linux 2.6.x
  5. * Copyright (C) 2003-2005 QLogic Corporation
  6. * (www.qlogic.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2, or (at your option) any
  11. * later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. */
  19. #include "qla_def.h"
  20. #include <linux/moduleparam.h>
  21. #include <linux/vmalloc.h>
  22. #include <linux/smp_lock.h>
  23. #include <linux/delay.h>
  24. #include <scsi/scsi_tcq.h>
  25. #include <scsi/scsicam.h>
  26. #include <scsi/scsi_transport.h>
  27. #include <scsi/scsi_transport_fc.h>
  28. /*
  29. * Driver version
  30. */
  31. char qla2x00_version_str[40];
  32. /*
  33. * SRB allocation cache
  34. */
  35. static kmem_cache_t *srb_cachep;
  36. /*
  37. * Ioctl related information.
  38. */
  39. static int num_hosts;
  40. int ql2xlogintimeout = 20;
  41. module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
  42. MODULE_PARM_DESC(ql2xlogintimeout,
  43. "Login timeout value in seconds.");
  44. int qlport_down_retry = 30;
  45. module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
  46. MODULE_PARM_DESC(qlport_down_retry,
  47. "Maximum number of command retries to a port that returns"
  48. "a PORT-DOWN status.");
  49. int ql2xplogiabsentdevice;
  50. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  51. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  52. "Option to enable PLOGI to devices that are not present after "
  53. "a Fabric scan. This is needed for several broken switches."
  54. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  55. int ql2xloginretrycount = 0;
  56. module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
  57. MODULE_PARM_DESC(ql2xloginretrycount,
  58. "Specify an alternate value for the NVRAM login retry count.");
  59. int ql2xfwloadbin=1;
  60. module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
  61. MODULE_PARM_DESC(ql2xfwloadbin,
  62. "Load ISP2xxx firmware image via hotplug.");
  63. static void qla2x00_free_device(scsi_qla_host_t *);
  64. static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
  65. int ql2xfdmienable;
  66. module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
  67. MODULE_PARM_DESC(ql2xfdmienable,
  68. "Enables FDMI registratons "
  69. "Default is 0 - no FDMI. 1 - perfom FDMI.");
  70. /*
  71. * SCSI host template entry points
  72. */
  73. static int qla2xxx_slave_configure(struct scsi_device * device);
  74. static int qla2xxx_slave_alloc(struct scsi_device *);
  75. static void qla2xxx_slave_destroy(struct scsi_device *);
  76. static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
  77. void (*fn)(struct scsi_cmnd *));
  78. static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
  79. void (*fn)(struct scsi_cmnd *));
  80. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  81. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  82. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  83. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  84. static int qla2x00_loop_reset(scsi_qla_host_t *ha);
  85. static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
  86. static int qla2x00_change_queue_depth(struct scsi_device *, int);
  87. static int qla2x00_change_queue_type(struct scsi_device *, int);
  88. static struct scsi_host_template qla2x00_driver_template = {
  89. .module = THIS_MODULE,
  90. .name = "qla2xxx",
  91. .queuecommand = qla2x00_queuecommand,
  92. .eh_abort_handler = qla2xxx_eh_abort,
  93. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  94. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  95. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  96. .slave_configure = qla2xxx_slave_configure,
  97. .slave_alloc = qla2xxx_slave_alloc,
  98. .slave_destroy = qla2xxx_slave_destroy,
  99. .change_queue_depth = qla2x00_change_queue_depth,
  100. .change_queue_type = qla2x00_change_queue_type,
  101. .this_id = -1,
  102. .cmd_per_lun = 3,
  103. .use_clustering = ENABLE_CLUSTERING,
  104. .sg_tablesize = SG_ALL,
  105. /*
  106. * The RISC allows for each command to transfer (2^32-1) bytes of data,
  107. * which equates to 0x800000 sectors.
  108. */
  109. .max_sectors = 0xFFFF,
  110. .shost_attrs = qla2x00_host_attrs,
  111. };
  112. static struct scsi_host_template qla24xx_driver_template = {
  113. .module = THIS_MODULE,
  114. .name = "qla2xxx",
  115. .queuecommand = qla24xx_queuecommand,
  116. .eh_abort_handler = qla2xxx_eh_abort,
  117. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  118. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  119. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  120. .slave_configure = qla2xxx_slave_configure,
  121. .slave_alloc = qla2xxx_slave_alloc,
  122. .slave_destroy = qla2xxx_slave_destroy,
  123. .change_queue_depth = qla2x00_change_queue_depth,
  124. .change_queue_type = qla2x00_change_queue_type,
  125. .this_id = -1,
  126. .cmd_per_lun = 3,
  127. .use_clustering = ENABLE_CLUSTERING,
  128. .sg_tablesize = SG_ALL,
  129. .max_sectors = 0xFFFF,
  130. .shost_attrs = qla2x00_host_attrs,
  131. };
  132. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  133. /* TODO Convert to inlines
  134. *
  135. * Timer routines
  136. */
  137. #define WATCH_INTERVAL 1 /* number of seconds */
  138. static void qla2x00_timer(scsi_qla_host_t *);
  139. static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
  140. void *, unsigned long);
  141. static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
  142. static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
  143. static inline void
  144. qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
  145. {
  146. init_timer(&ha->timer);
  147. ha->timer.expires = jiffies + interval * HZ;
  148. ha->timer.data = (unsigned long)ha;
  149. ha->timer.function = (void (*)(unsigned long))func;
  150. add_timer(&ha->timer);
  151. ha->timer_active = 1;
  152. }
  153. static inline void
  154. qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
  155. {
  156. mod_timer(&ha->timer, jiffies + interval * HZ);
  157. }
  158. static __inline__ void
  159. qla2x00_stop_timer(scsi_qla_host_t *ha)
  160. {
  161. del_timer_sync(&ha->timer);
  162. ha->timer_active = 0;
  163. }
  164. static int qla2x00_do_dpc(void *data);
  165. static void qla2x00_rst_aen(scsi_qla_host_t *);
  166. static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
  167. static void qla2x00_mem_free(scsi_qla_host_t *ha);
  168. static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
  169. static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
  170. static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
  171. void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
  172. /* -------------------------------------------------------------------------- */
  173. static char *
  174. qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
  175. {
  176. static char *pci_bus_modes[] = {
  177. "33", "66", "100", "133",
  178. };
  179. uint16_t pci_bus;
  180. strcpy(str, "PCI");
  181. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  182. if (pci_bus) {
  183. strcat(str, "-X (");
  184. strcat(str, pci_bus_modes[pci_bus]);
  185. } else {
  186. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  187. strcat(str, " (");
  188. strcat(str, pci_bus_modes[pci_bus]);
  189. }
  190. strcat(str, " MHz)");
  191. return (str);
  192. }
  193. static char *
  194. qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
  195. {
  196. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  197. uint32_t pci_bus;
  198. int pcie_reg;
  199. pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
  200. if (pcie_reg) {
  201. char lwstr[6];
  202. uint16_t pcie_lstat, lspeed, lwidth;
  203. pcie_reg += 0x12;
  204. pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
  205. lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
  206. lwidth = (pcie_lstat &
  207. (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
  208. strcpy(str, "PCIe (");
  209. if (lspeed == 1)
  210. strcat(str, "2.5Gb/s ");
  211. else
  212. strcat(str, "<unknown> ");
  213. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  214. strcat(str, lwstr);
  215. return str;
  216. }
  217. strcpy(str, "PCI");
  218. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  219. if (pci_bus == 0 || pci_bus == 8) {
  220. strcat(str, " (");
  221. strcat(str, pci_bus_modes[pci_bus >> 3]);
  222. } else {
  223. strcat(str, "-X ");
  224. if (pci_bus & BIT_2)
  225. strcat(str, "Mode 2");
  226. else
  227. strcat(str, "Mode 1");
  228. strcat(str, " (");
  229. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  230. }
  231. strcat(str, " MHz)");
  232. return str;
  233. }
  234. char *
  235. qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
  236. {
  237. char un_str[10];
  238. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  239. ha->fw_minor_version,
  240. ha->fw_subminor_version);
  241. if (ha->fw_attributes & BIT_9) {
  242. strcat(str, "FLX");
  243. return (str);
  244. }
  245. switch (ha->fw_attributes & 0xFF) {
  246. case 0x7:
  247. strcat(str, "EF");
  248. break;
  249. case 0x17:
  250. strcat(str, "TP");
  251. break;
  252. case 0x37:
  253. strcat(str, "IP");
  254. break;
  255. case 0x77:
  256. strcat(str, "VI");
  257. break;
  258. default:
  259. sprintf(un_str, "(%x)", ha->fw_attributes);
  260. strcat(str, un_str);
  261. break;
  262. }
  263. if (ha->fw_attributes & 0x100)
  264. strcat(str, "X");
  265. return (str);
  266. }
  267. char *
  268. qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
  269. {
  270. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  271. ha->fw_minor_version,
  272. ha->fw_subminor_version);
  273. if (ha->fw_attributes & BIT_0)
  274. strcat(str, "[Class 2] ");
  275. if (ha->fw_attributes & BIT_1)
  276. strcat(str, "[IP] ");
  277. if (ha->fw_attributes & BIT_2)
  278. strcat(str, "[Multi-ID] ");
  279. if (ha->fw_attributes & BIT_13)
  280. strcat(str, "[Experimental]");
  281. return str;
  282. }
  283. static inline srb_t *
  284. qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
  285. struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  286. {
  287. srb_t *sp;
  288. sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  289. if (!sp)
  290. return sp;
  291. atomic_set(&sp->ref_count, 1);
  292. sp->ha = ha;
  293. sp->fcport = fcport;
  294. sp->cmd = cmd;
  295. sp->flags = 0;
  296. CMD_SP(cmd) = (void *)sp;
  297. cmd->scsi_done = done;
  298. return sp;
  299. }
  300. static int
  301. qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  302. {
  303. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  304. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  305. srb_t *sp;
  306. int rval;
  307. if (!fcport) {
  308. cmd->result = DID_NO_CONNECT << 16;
  309. goto qc_fail_command;
  310. }
  311. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  312. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  313. atomic_read(&ha->loop_state) == LOOP_DEAD) {
  314. cmd->result = DID_NO_CONNECT << 16;
  315. goto qc_fail_command;
  316. }
  317. goto qc_host_busy;
  318. }
  319. spin_unlock_irq(ha->host->host_lock);
  320. sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
  321. if (!sp)
  322. goto qc_host_busy_lock;
  323. rval = qla2x00_start_scsi(sp);
  324. if (rval != QLA_SUCCESS)
  325. goto qc_host_busy_free_sp;
  326. spin_lock_irq(ha->host->host_lock);
  327. return 0;
  328. qc_host_busy_free_sp:
  329. qla2x00_sp_free_dma(ha, sp);
  330. mempool_free(sp, ha->srb_mempool);
  331. qc_host_busy_lock:
  332. spin_lock_irq(ha->host->host_lock);
  333. qc_host_busy:
  334. return SCSI_MLQUEUE_HOST_BUSY;
  335. qc_fail_command:
  336. done(cmd);
  337. return 0;
  338. }
  339. static int
  340. qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  341. {
  342. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  343. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  344. srb_t *sp;
  345. int rval;
  346. if (!fcport) {
  347. cmd->result = DID_NO_CONNECT << 16;
  348. goto qc24_fail_command;
  349. }
  350. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  351. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  352. atomic_read(&ha->loop_state) == LOOP_DEAD) {
  353. cmd->result = DID_NO_CONNECT << 16;
  354. goto qc24_fail_command;
  355. }
  356. goto qc24_host_busy;
  357. }
  358. spin_unlock_irq(ha->host->host_lock);
  359. sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
  360. if (!sp)
  361. goto qc24_host_busy_lock;
  362. rval = qla24xx_start_scsi(sp);
  363. if (rval != QLA_SUCCESS)
  364. goto qc24_host_busy_free_sp;
  365. spin_lock_irq(ha->host->host_lock);
  366. return 0;
  367. qc24_host_busy_free_sp:
  368. qla2x00_sp_free_dma(ha, sp);
  369. mempool_free(sp, ha->srb_mempool);
  370. qc24_host_busy_lock:
  371. spin_lock_irq(ha->host->host_lock);
  372. qc24_host_busy:
  373. return SCSI_MLQUEUE_HOST_BUSY;
  374. qc24_fail_command:
  375. done(cmd);
  376. return 0;
  377. }
  378. /*
  379. * qla2x00_eh_wait_on_command
  380. * Waits for the command to be returned by the Firmware for some
  381. * max time.
  382. *
  383. * Input:
  384. * ha = actual ha whose done queue will contain the command
  385. * returned by firmware.
  386. * cmd = Scsi Command to wait on.
  387. * flag = Abort/Reset(Bus or Device Reset)
  388. *
  389. * Return:
  390. * Not Found : 0
  391. * Found : 1
  392. */
  393. static int
  394. qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
  395. {
  396. #define ABORT_POLLING_PERIOD 1000
  397. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  398. unsigned long wait_iter = ABORT_WAIT_ITER;
  399. int ret = QLA_SUCCESS;
  400. while (CMD_SP(cmd)) {
  401. msleep(ABORT_POLLING_PERIOD);
  402. if (--wait_iter)
  403. break;
  404. }
  405. if (CMD_SP(cmd))
  406. ret = QLA_FUNCTION_FAILED;
  407. return ret;
  408. }
  409. /*
  410. * qla2x00_wait_for_hba_online
  411. * Wait till the HBA is online after going through
  412. * <= MAX_RETRIES_OF_ISP_ABORT or
  413. * finally HBA is disabled ie marked offline
  414. *
  415. * Input:
  416. * ha - pointer to host adapter structure
  417. *
  418. * Note:
  419. * Does context switching-Release SPIN_LOCK
  420. * (if any) before calling this routine.
  421. *
  422. * Return:
  423. * Success (Adapter is online) : 0
  424. * Failed (Adapter is offline/disabled) : 1
  425. */
  426. static int
  427. qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
  428. {
  429. int return_status;
  430. unsigned long wait_online;
  431. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  432. while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
  433. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  434. test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
  435. ha->dpc_active) && time_before(jiffies, wait_online)) {
  436. msleep(1000);
  437. }
  438. if (ha->flags.online)
  439. return_status = QLA_SUCCESS;
  440. else
  441. return_status = QLA_FUNCTION_FAILED;
  442. DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
  443. return (return_status);
  444. }
  445. /*
  446. * qla2x00_wait_for_loop_ready
  447. * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
  448. * to be in LOOP_READY state.
  449. * Input:
  450. * ha - pointer to host adapter structure
  451. *
  452. * Note:
  453. * Does context switching-Release SPIN_LOCK
  454. * (if any) before calling this routine.
  455. *
  456. *
  457. * Return:
  458. * Success (LOOP_READY) : 0
  459. * Failed (LOOP_NOT_READY) : 1
  460. */
  461. static inline int
  462. qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
  463. {
  464. int return_status = QLA_SUCCESS;
  465. unsigned long loop_timeout ;
  466. /* wait for 5 min at the max for loop to be ready */
  467. loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  468. while ((!atomic_read(&ha->loop_down_timer) &&
  469. atomic_read(&ha->loop_state) == LOOP_DOWN) ||
  470. atomic_read(&ha->loop_state) != LOOP_READY) {
  471. msleep(1000);
  472. if (time_after_eq(jiffies, loop_timeout)) {
  473. return_status = QLA_FUNCTION_FAILED;
  474. break;
  475. }
  476. }
  477. return (return_status);
  478. }
  479. /**************************************************************************
  480. * qla2xxx_eh_abort
  481. *
  482. * Description:
  483. * The abort function will abort the specified command.
  484. *
  485. * Input:
  486. * cmd = Linux SCSI command packet to be aborted.
  487. *
  488. * Returns:
  489. * Either SUCCESS or FAILED.
  490. *
  491. * Note:
  492. **************************************************************************/
  493. int
  494. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  495. {
  496. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  497. srb_t *sp;
  498. int ret, i;
  499. unsigned int id, lun;
  500. unsigned long serial;
  501. unsigned long flags;
  502. if (!CMD_SP(cmd))
  503. return FAILED;
  504. ret = FAILED;
  505. id = cmd->device->id;
  506. lun = cmd->device->lun;
  507. serial = cmd->serial_number;
  508. /* Check active list for command command. */
  509. spin_lock_irqsave(&ha->hardware_lock, flags);
  510. for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
  511. sp = ha->outstanding_cmds[i];
  512. if (sp == NULL)
  513. continue;
  514. if (sp->cmd != cmd)
  515. continue;
  516. DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
  517. "sp->state=%x\n", __func__, ha->host_no, sp, serial,
  518. sp->state));
  519. DEBUG3(qla2x00_print_scsi_cmd(cmd);)
  520. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  521. if (ha->isp_ops.abort_command(ha, sp)) {
  522. DEBUG2(printk("%s(%ld): abort_command "
  523. "mbx failed.\n", __func__, ha->host_no));
  524. } else {
  525. DEBUG3(printk("%s(%ld): abort_command "
  526. "mbx success.\n", __func__, ha->host_no));
  527. ret = SUCCESS;
  528. }
  529. spin_lock_irqsave(&ha->hardware_lock, flags);
  530. break;
  531. }
  532. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  533. /* Wait for the command to be returned. */
  534. if (ret == SUCCESS) {
  535. if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
  536. qla_printk(KERN_ERR, ha,
  537. "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
  538. "%x.\n", ha->host_no, id, lun, serial, ret);
  539. }
  540. }
  541. qla_printk(KERN_INFO, ha,
  542. "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
  543. id, lun, serial, ret);
  544. return ret;
  545. }
  546. /**************************************************************************
  547. * qla2x00_eh_wait_for_pending_target_commands
  548. *
  549. * Description:
  550. * Waits for all the commands to come back from the specified target.
  551. *
  552. * Input:
  553. * ha - pointer to scsi_qla_host structure.
  554. * t - target
  555. * Returns:
  556. * Either SUCCESS or FAILED.
  557. *
  558. * Note:
  559. **************************************************************************/
  560. static int
  561. qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
  562. {
  563. int cnt;
  564. int status;
  565. srb_t *sp;
  566. struct scsi_cmnd *cmd;
  567. unsigned long flags;
  568. status = 0;
  569. /*
  570. * Waiting for all commands for the designated target in the active
  571. * array
  572. */
  573. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  574. spin_lock_irqsave(&ha->hardware_lock, flags);
  575. sp = ha->outstanding_cmds[cnt];
  576. if (sp) {
  577. cmd = sp->cmd;
  578. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  579. if (cmd->device->id == t) {
  580. if (!qla2x00_eh_wait_on_command(ha, cmd)) {
  581. status = 1;
  582. break;
  583. }
  584. }
  585. } else {
  586. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  587. }
  588. }
  589. return (status);
  590. }
  591. /**************************************************************************
  592. * qla2xxx_eh_device_reset
  593. *
  594. * Description:
  595. * The device reset function will reset the target and abort any
  596. * executing commands.
  597. *
  598. * NOTE: The use of SP is undefined within this context. Do *NOT*
  599. * attempt to use this value, even if you determine it is
  600. * non-null.
  601. *
  602. * Input:
  603. * cmd = Linux SCSI command packet of the command that cause the
  604. * bus device reset.
  605. *
  606. * Returns:
  607. * SUCCESS/FAILURE (defined as macro in scsi.h).
  608. *
  609. **************************************************************************/
  610. int
  611. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  612. {
  613. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  614. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  615. srb_t *sp;
  616. int ret;
  617. unsigned int id, lun;
  618. unsigned long serial;
  619. ret = FAILED;
  620. id = cmd->device->id;
  621. lun = cmd->device->lun;
  622. serial = cmd->serial_number;
  623. sp = (srb_t *) CMD_SP(cmd);
  624. if (!sp || !fcport)
  625. return ret;
  626. qla_printk(KERN_INFO, ha,
  627. "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
  628. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
  629. goto eh_dev_reset_done;
  630. if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
  631. if (qla2x00_device_reset(ha, fcport) == 0)
  632. ret = SUCCESS;
  633. #if defined(LOGOUT_AFTER_DEVICE_RESET)
  634. if (ret == SUCCESS) {
  635. if (fcport->flags & FC_FABRIC_DEVICE) {
  636. ha->isp_ops.fabric_logout(ha, fcport->loop_id);
  637. qla2x00_mark_device_lost(ha, fcport);
  638. }
  639. }
  640. #endif
  641. } else {
  642. DEBUG2(printk(KERN_INFO
  643. "%s failed: loop not ready\n",__func__);)
  644. }
  645. if (ret == FAILED) {
  646. DEBUG3(printk("%s(%ld): device reset failed\n",
  647. __func__, ha->host_no));
  648. qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
  649. __func__);
  650. goto eh_dev_reset_done;
  651. }
  652. /*
  653. * If we are coming down the EH path, wait for all commands to
  654. * complete for the device.
  655. */
  656. if (cmd->device->host->eh_active) {
  657. if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
  658. ret = FAILED;
  659. if (ret == FAILED) {
  660. DEBUG3(printk("%s(%ld): failed while waiting for "
  661. "commands\n", __func__, ha->host_no));
  662. qla_printk(KERN_INFO, ha,
  663. "%s: failed while waiting for commands\n",
  664. __func__);
  665. goto eh_dev_reset_done;
  666. }
  667. }
  668. qla_printk(KERN_INFO, ha,
  669. "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
  670. eh_dev_reset_done:
  671. return ret;
  672. }
  673. /**************************************************************************
  674. * qla2x00_eh_wait_for_pending_commands
  675. *
  676. * Description:
  677. * Waits for all the commands to come back from the specified host.
  678. *
  679. * Input:
  680. * ha - pointer to scsi_qla_host structure.
  681. *
  682. * Returns:
  683. * 1 : SUCCESS
  684. * 0 : FAILED
  685. *
  686. * Note:
  687. **************************************************************************/
  688. static int
  689. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
  690. {
  691. int cnt;
  692. int status;
  693. srb_t *sp;
  694. struct scsi_cmnd *cmd;
  695. unsigned long flags;
  696. status = 1;
  697. /*
  698. * Waiting for all commands for the designated target in the active
  699. * array
  700. */
  701. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  702. spin_lock_irqsave(&ha->hardware_lock, flags);
  703. sp = ha->outstanding_cmds[cnt];
  704. if (sp) {
  705. cmd = sp->cmd;
  706. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  707. status = qla2x00_eh_wait_on_command(ha, cmd);
  708. if (status == 0)
  709. break;
  710. }
  711. else {
  712. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  713. }
  714. }
  715. return (status);
  716. }
  717. /**************************************************************************
  718. * qla2xxx_eh_bus_reset
  719. *
  720. * Description:
  721. * The bus reset function will reset the bus and abort any executing
  722. * commands.
  723. *
  724. * Input:
  725. * cmd = Linux SCSI command packet of the command that cause the
  726. * bus reset.
  727. *
  728. * Returns:
  729. * SUCCESS/FAILURE (defined as macro in scsi.h).
  730. *
  731. **************************************************************************/
  732. int
  733. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  734. {
  735. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  736. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  737. srb_t *sp;
  738. int ret;
  739. unsigned int id, lun;
  740. unsigned long serial;
  741. ret = FAILED;
  742. id = cmd->device->id;
  743. lun = cmd->device->lun;
  744. serial = cmd->serial_number;
  745. sp = (srb_t *) CMD_SP(cmd);
  746. if (!sp || !fcport)
  747. return ret;
  748. qla_printk(KERN_INFO, ha,
  749. "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
  750. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
  751. DEBUG2(printk("%s failed:board disabled\n",__func__));
  752. goto eh_bus_reset_done;
  753. }
  754. if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
  755. if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
  756. ret = SUCCESS;
  757. }
  758. if (ret == FAILED)
  759. goto eh_bus_reset_done;
  760. /* Waiting for our command in done_queue to be returned to OS.*/
  761. if (cmd->device->host->eh_active)
  762. if (!qla2x00_eh_wait_for_pending_commands(ha))
  763. ret = FAILED;
  764. eh_bus_reset_done:
  765. qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
  766. (ret == FAILED) ? "failed" : "succeded");
  767. return ret;
  768. }
  769. /**************************************************************************
  770. * qla2xxx_eh_host_reset
  771. *
  772. * Description:
  773. * The reset function will reset the Adapter.
  774. *
  775. * Input:
  776. * cmd = Linux SCSI command packet of the command that cause the
  777. * adapter reset.
  778. *
  779. * Returns:
  780. * Either SUCCESS or FAILED.
  781. *
  782. * Note:
  783. **************************************************************************/
  784. int
  785. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  786. {
  787. scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
  788. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  789. srb_t *sp;
  790. int ret;
  791. unsigned int id, lun;
  792. unsigned long serial;
  793. ret = FAILED;
  794. id = cmd->device->id;
  795. lun = cmd->device->lun;
  796. serial = cmd->serial_number;
  797. sp = (srb_t *) CMD_SP(cmd);
  798. if (!sp || !fcport)
  799. return ret;
  800. qla_printk(KERN_INFO, ha,
  801. "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
  802. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
  803. goto eh_host_reset_lock;
  804. /*
  805. * Fixme-may be dpc thread is active and processing
  806. * loop_resync,so wait a while for it to
  807. * be completed and then issue big hammer.Otherwise
  808. * it may cause I/O failure as big hammer marks the
  809. * devices as lost kicking of the port_down_timer
  810. * while dpc is stuck for the mailbox to complete.
  811. */
  812. qla2x00_wait_for_loop_ready(ha);
  813. set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  814. if (qla2x00_abort_isp(ha)) {
  815. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  816. /* failed. schedule dpc to try */
  817. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  818. if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
  819. goto eh_host_reset_lock;
  820. }
  821. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  822. /* Waiting for our command in done_queue to be returned to OS.*/
  823. if (qla2x00_eh_wait_for_pending_commands(ha))
  824. ret = SUCCESS;
  825. eh_host_reset_lock:
  826. qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
  827. (ret == FAILED) ? "failed" : "succeded");
  828. return ret;
  829. }
  830. /*
  831. * qla2x00_loop_reset
  832. * Issue loop reset.
  833. *
  834. * Input:
  835. * ha = adapter block pointer.
  836. *
  837. * Returns:
  838. * 0 = success
  839. */
  840. static int
  841. qla2x00_loop_reset(scsi_qla_host_t *ha)
  842. {
  843. int status = QLA_SUCCESS;
  844. struct fc_port *fcport;
  845. if (ha->flags.enable_lip_reset) {
  846. status = qla2x00_lip_reset(ha);
  847. }
  848. if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
  849. list_for_each_entry(fcport, &ha->fcports, list) {
  850. if (fcport->port_type != FCT_TARGET)
  851. continue;
  852. status = qla2x00_device_reset(ha, fcport);
  853. if (status != QLA_SUCCESS)
  854. break;
  855. }
  856. }
  857. if (status == QLA_SUCCESS &&
  858. ((!ha->flags.enable_target_reset &&
  859. !ha->flags.enable_lip_reset) ||
  860. ha->flags.enable_lip_full_login)) {
  861. status = qla2x00_full_login_lip(ha);
  862. }
  863. /* Issue marker command only when we are going to start the I/O */
  864. ha->marker_needed = 1;
  865. if (status) {
  866. /* Empty */
  867. DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
  868. __func__,
  869. ha->host_no);)
  870. } else {
  871. /* Empty */
  872. DEBUG3(printk("%s(%ld): exiting normally.\n",
  873. __func__,
  874. ha->host_no);)
  875. }
  876. return(status);
  877. }
  878. /*
  879. * qla2x00_device_reset
  880. * Issue bus device reset message to the target.
  881. *
  882. * Input:
  883. * ha = adapter block pointer.
  884. * t = SCSI ID.
  885. * TARGET_QUEUE_LOCK must be released.
  886. * ADAPTER_STATE_LOCK must be released.
  887. *
  888. * Context:
  889. * Kernel context.
  890. */
  891. static int
  892. qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
  893. {
  894. /* Abort Target command will clear Reservation */
  895. return ha->isp_ops.abort_target(reset_fcport);
  896. }
  897. static int
  898. qla2xxx_slave_alloc(struct scsi_device *sdev)
  899. {
  900. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  901. if (!rport)
  902. return -ENXIO;
  903. sdev->hostdata = rport->dd_data;
  904. return 0;
  905. }
  906. static int
  907. qla2xxx_slave_configure(struct scsi_device *sdev)
  908. {
  909. scsi_qla_host_t *ha = to_qla_host(sdev->host);
  910. struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
  911. if (sdev->tagged_supported)
  912. scsi_activate_tcq(sdev, 32);
  913. else
  914. scsi_deactivate_tcq(sdev, 32);
  915. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  916. return 0;
  917. }
  918. static void
  919. qla2xxx_slave_destroy(struct scsi_device *sdev)
  920. {
  921. sdev->hostdata = NULL;
  922. }
  923. static int
  924. qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
  925. {
  926. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  927. return sdev->queue_depth;
  928. }
  929. static int
  930. qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
  931. {
  932. if (sdev->tagged_supported) {
  933. scsi_set_tag_type(sdev, tag_type);
  934. if (tag_type)
  935. scsi_activate_tcq(sdev, sdev->queue_depth);
  936. else
  937. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  938. } else
  939. tag_type = 0;
  940. return tag_type;
  941. }
  942. /**
  943. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  944. * @ha: HA context
  945. *
  946. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  947. * supported addressing method.
  948. */
  949. static void
  950. qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
  951. {
  952. /* Assume a 32bit DMA mask. */
  953. ha->flags.enable_64bit_addressing = 0;
  954. if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
  955. /* Any upper-dword bits set? */
  956. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  957. !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
  958. /* Ok, a 64bit DMA mask is applicable. */
  959. ha->flags.enable_64bit_addressing = 1;
  960. ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
  961. ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
  962. return;
  963. }
  964. }
  965. dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
  966. pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
  967. }
  968. static int
  969. qla2x00_iospace_config(scsi_qla_host_t *ha)
  970. {
  971. unsigned long pio, pio_len, pio_flags;
  972. unsigned long mmio, mmio_len, mmio_flags;
  973. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  974. pio = pci_resource_start(ha->pdev, 0);
  975. pio_len = pci_resource_len(ha->pdev, 0);
  976. pio_flags = pci_resource_flags(ha->pdev, 0);
  977. if (pio_flags & IORESOURCE_IO) {
  978. if (pio_len < MIN_IOBASE_LEN) {
  979. qla_printk(KERN_WARNING, ha,
  980. "Invalid PCI I/O region size (%s)...\n",
  981. pci_name(ha->pdev));
  982. pio = 0;
  983. }
  984. } else {
  985. qla_printk(KERN_WARNING, ha,
  986. "region #0 not a PIO resource (%s)...\n",
  987. pci_name(ha->pdev));
  988. pio = 0;
  989. }
  990. /* Use MMIO operations for all accesses. */
  991. mmio = pci_resource_start(ha->pdev, 1);
  992. mmio_len = pci_resource_len(ha->pdev, 1);
  993. mmio_flags = pci_resource_flags(ha->pdev, 1);
  994. if (!(mmio_flags & IORESOURCE_MEM)) {
  995. qla_printk(KERN_ERR, ha,
  996. "region #0 not an MMIO resource (%s), aborting\n",
  997. pci_name(ha->pdev));
  998. goto iospace_error_exit;
  999. }
  1000. if (mmio_len < MIN_IOBASE_LEN) {
  1001. qla_printk(KERN_ERR, ha,
  1002. "Invalid PCI mem region size (%s), aborting\n",
  1003. pci_name(ha->pdev));
  1004. goto iospace_error_exit;
  1005. }
  1006. if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
  1007. qla_printk(KERN_WARNING, ha,
  1008. "Failed to reserve PIO/MMIO regions (%s)\n",
  1009. pci_name(ha->pdev));
  1010. goto iospace_error_exit;
  1011. }
  1012. ha->pio_address = pio;
  1013. ha->pio_length = pio_len;
  1014. ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
  1015. if (!ha->iobase) {
  1016. qla_printk(KERN_ERR, ha,
  1017. "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
  1018. goto iospace_error_exit;
  1019. }
  1020. return (0);
  1021. iospace_error_exit:
  1022. return (-ENOMEM);
  1023. }
  1024. static void
  1025. qla2x00_enable_intrs(scsi_qla_host_t *ha)
  1026. {
  1027. unsigned long flags = 0;
  1028. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1029. spin_lock_irqsave(&ha->hardware_lock, flags);
  1030. ha->interrupts_on = 1;
  1031. /* enable risc and host interrupts */
  1032. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1033. RD_REG_WORD(&reg->ictrl);
  1034. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1035. }
  1036. static void
  1037. qla2x00_disable_intrs(scsi_qla_host_t *ha)
  1038. {
  1039. unsigned long flags = 0;
  1040. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1041. spin_lock_irqsave(&ha->hardware_lock, flags);
  1042. ha->interrupts_on = 0;
  1043. /* disable risc and host interrupts */
  1044. WRT_REG_WORD(&reg->ictrl, 0);
  1045. RD_REG_WORD(&reg->ictrl);
  1046. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1047. }
  1048. static void
  1049. qla24xx_enable_intrs(scsi_qla_host_t *ha)
  1050. {
  1051. unsigned long flags = 0;
  1052. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1053. spin_lock_irqsave(&ha->hardware_lock, flags);
  1054. ha->interrupts_on = 1;
  1055. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1056. RD_REG_DWORD(&reg->ictrl);
  1057. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1058. }
  1059. static void
  1060. qla24xx_disable_intrs(scsi_qla_host_t *ha)
  1061. {
  1062. unsigned long flags = 0;
  1063. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1064. spin_lock_irqsave(&ha->hardware_lock, flags);
  1065. ha->interrupts_on = 0;
  1066. WRT_REG_DWORD(&reg->ictrl, 0);
  1067. RD_REG_DWORD(&reg->ictrl);
  1068. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1069. }
  1070. /*
  1071. * PCI driver interface
  1072. */
  1073. int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
  1074. {
  1075. int ret = -ENODEV;
  1076. device_reg_t __iomem *reg;
  1077. struct Scsi_Host *host;
  1078. scsi_qla_host_t *ha;
  1079. unsigned long flags = 0;
  1080. unsigned long wait_switch = 0;
  1081. char pci_info[20];
  1082. char fw_str[30];
  1083. fc_port_t *fcport;
  1084. if (pci_enable_device(pdev))
  1085. goto probe_out;
  1086. host = scsi_host_alloc(brd_info->sht ? brd_info->sht:
  1087. &qla2x00_driver_template, sizeof(scsi_qla_host_t));
  1088. if (host == NULL) {
  1089. printk(KERN_WARNING
  1090. "qla2xxx: Couldn't allocate host from scsi layer!\n");
  1091. goto probe_disable_device;
  1092. }
  1093. /* Clear our data area */
  1094. ha = (scsi_qla_host_t *)host->hostdata;
  1095. memset(ha, 0, sizeof(scsi_qla_host_t));
  1096. ha->pdev = pdev;
  1097. ha->host = host;
  1098. ha->host_no = host->host_no;
  1099. ha->brd_info = brd_info;
  1100. sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
  1101. ha->dpc_pid = -1;
  1102. /* Configure PCI I/O space */
  1103. ret = qla2x00_iospace_config(ha);
  1104. if (ret)
  1105. goto probe_failed;
  1106. qla_printk(KERN_INFO, ha,
  1107. "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
  1108. pdev->irq, ha->iobase);
  1109. spin_lock_init(&ha->hardware_lock);
  1110. ha->prev_topology = 0;
  1111. ha->ports = MAX_BUSES;
  1112. ha->init_cb_size = sizeof(init_cb_t);
  1113. ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
  1114. /* Assign ISP specific operations. */
  1115. ha->isp_ops.pci_config = qla2100_pci_config;
  1116. ha->isp_ops.reset_chip = qla2x00_reset_chip;
  1117. ha->isp_ops.chip_diag = qla2x00_chip_diag;
  1118. ha->isp_ops.config_rings = qla2x00_config_rings;
  1119. ha->isp_ops.reset_adapter = qla2x00_reset_adapter;
  1120. ha->isp_ops.nvram_config = qla2x00_nvram_config;
  1121. ha->isp_ops.update_fw_options = qla2x00_update_fw_options;
  1122. ha->isp_ops.load_risc = qla2x00_load_risc;
  1123. ha->isp_ops.pci_info_str = qla2x00_pci_info_str;
  1124. ha->isp_ops.fw_version_str = qla2x00_fw_version_str;
  1125. ha->isp_ops.intr_handler = qla2100_intr_handler;
  1126. ha->isp_ops.enable_intrs = qla2x00_enable_intrs;
  1127. ha->isp_ops.disable_intrs = qla2x00_disable_intrs;
  1128. ha->isp_ops.abort_command = qla2x00_abort_command;
  1129. ha->isp_ops.abort_target = qla2x00_abort_target;
  1130. ha->isp_ops.fabric_login = qla2x00_login_fabric;
  1131. ha->isp_ops.fabric_logout = qla2x00_fabric_logout;
  1132. ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
  1133. ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
  1134. ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
  1135. ha->isp_ops.prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb;
  1136. ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
  1137. ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
  1138. ha->isp_ops.fw_dump = qla2100_fw_dump;
  1139. ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
  1140. if (IS_QLA2100(ha)) {
  1141. host->max_id = MAX_TARGETS_2100;
  1142. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  1143. ha->request_q_length = REQUEST_ENTRY_CNT_2100;
  1144. ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
  1145. ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
  1146. host->sg_tablesize = 32;
  1147. ha->gid_list_info_size = 4;
  1148. } else if (IS_QLA2200(ha)) {
  1149. host->max_id = MAX_TARGETS_2200;
  1150. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1151. ha->request_q_length = REQUEST_ENTRY_CNT_2200;
  1152. ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
  1153. ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
  1154. ha->gid_list_info_size = 4;
  1155. } else if (IS_QLA23XX(ha)) {
  1156. host->max_id = MAX_TARGETS_2200;
  1157. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1158. ha->request_q_length = REQUEST_ENTRY_CNT_2200;
  1159. ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
  1160. ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
  1161. ha->isp_ops.pci_config = qla2300_pci_config;
  1162. ha->isp_ops.intr_handler = qla2300_intr_handler;
  1163. ha->isp_ops.fw_dump = qla2300_fw_dump;
  1164. ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
  1165. ha->gid_list_info_size = 6;
  1166. } else if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1167. host->max_id = MAX_TARGETS_2200;
  1168. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1169. ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
  1170. ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
  1171. ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
  1172. ha->init_cb_size = sizeof(struct init_cb_24xx);
  1173. ha->mgmt_svr_loop_id = 10;
  1174. ha->isp_ops.pci_config = qla24xx_pci_config;
  1175. ha->isp_ops.reset_chip = qla24xx_reset_chip;
  1176. ha->isp_ops.chip_diag = qla24xx_chip_diag;
  1177. ha->isp_ops.config_rings = qla24xx_config_rings;
  1178. ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
  1179. ha->isp_ops.nvram_config = qla24xx_nvram_config;
  1180. ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
  1181. ha->isp_ops.load_risc = qla24xx_load_risc_flash;
  1182. if (ql2xfwloadbin)
  1183. ha->isp_ops.load_risc = qla24xx_load_risc_hotplug;
  1184. ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
  1185. ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
  1186. ha->isp_ops.intr_handler = qla24xx_intr_handler;
  1187. ha->isp_ops.enable_intrs = qla24xx_enable_intrs;
  1188. ha->isp_ops.disable_intrs = qla24xx_disable_intrs;
  1189. ha->isp_ops.abort_command = qla24xx_abort_command;
  1190. ha->isp_ops.abort_target = qla24xx_abort_target;
  1191. ha->isp_ops.fabric_login = qla24xx_login_fabric;
  1192. ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
  1193. ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
  1194. ha->isp_ops.prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb;
  1195. ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
  1196. ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
  1197. ha->isp_ops.fw_dump = qla24xx_fw_dump;
  1198. ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
  1199. ha->gid_list_info_size = 8;
  1200. }
  1201. host->can_queue = ha->request_q_length + 128;
  1202. /* load the F/W, read paramaters, and init the H/W */
  1203. ha->instance = num_hosts;
  1204. init_MUTEX(&ha->mbx_cmd_sem);
  1205. init_MUTEX_LOCKED(&ha->mbx_intr_sem);
  1206. INIT_LIST_HEAD(&ha->list);
  1207. INIT_LIST_HEAD(&ha->fcports);
  1208. INIT_LIST_HEAD(&ha->rscn_fcports);
  1209. /*
  1210. * These locks are used to prevent more than one CPU
  1211. * from modifying the queue at the same time. The
  1212. * higher level "host_lock" will reduce most
  1213. * contention for these locks.
  1214. */
  1215. spin_lock_init(&ha->mbx_reg_lock);
  1216. init_completion(&ha->dpc_inited);
  1217. init_completion(&ha->dpc_exited);
  1218. qla2x00_config_dma_addressing(ha);
  1219. if (qla2x00_mem_alloc(ha)) {
  1220. qla_printk(KERN_WARNING, ha,
  1221. "[ERROR] Failed to allocate memory for adapter\n");
  1222. ret = -ENOMEM;
  1223. goto probe_failed;
  1224. }
  1225. if (qla2x00_initialize_adapter(ha) &&
  1226. !(ha->device_flags & DFLG_NO_CABLE)) {
  1227. qla_printk(KERN_WARNING, ha,
  1228. "Failed to initialize adapter\n");
  1229. DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
  1230. "Adapter flags %x.\n",
  1231. ha->host_no, ha->device_flags));
  1232. ret = -ENODEV;
  1233. goto probe_failed;
  1234. }
  1235. /*
  1236. * Startup the kernel thread for this host adapter
  1237. */
  1238. ha->dpc_should_die = 0;
  1239. ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
  1240. if (ha->dpc_pid < 0) {
  1241. qla_printk(KERN_WARNING, ha,
  1242. "Unable to start DPC thread!\n");
  1243. ret = -ENODEV;
  1244. goto probe_failed;
  1245. }
  1246. wait_for_completion(&ha->dpc_inited);
  1247. host->this_id = 255;
  1248. host->cmd_per_lun = 3;
  1249. host->unique_id = ha->instance;
  1250. host->max_cmd_len = MAX_CMDSZ;
  1251. host->max_channel = ha->ports - 1;
  1252. host->max_lun = MAX_LUNS;
  1253. host->transportt = qla2xxx_transport_template;
  1254. ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
  1255. SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
  1256. if (ret) {
  1257. qla_printk(KERN_WARNING, ha,
  1258. "Failed to reserve interrupt %d already in use.\n",
  1259. pdev->irq);
  1260. goto probe_failed;
  1261. }
  1262. host->irq = pdev->irq;
  1263. /* Initialized the timer */
  1264. qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
  1265. DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
  1266. ha->host_no, ha));
  1267. ha->isp_ops.disable_intrs(ha);
  1268. spin_lock_irqsave(&ha->hardware_lock, flags);
  1269. reg = ha->iobase;
  1270. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1271. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
  1272. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
  1273. } else {
  1274. WRT_REG_WORD(&reg->isp.semaphore, 0);
  1275. WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
  1276. WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
  1277. /* Enable proper parity */
  1278. if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  1279. if (IS_QLA2300(ha))
  1280. /* SRAM parity */
  1281. WRT_REG_WORD(&reg->isp.hccr,
  1282. (HCCR_ENABLE_PARITY + 0x1));
  1283. else
  1284. /* SRAM, Instruction RAM and GP RAM parity */
  1285. WRT_REG_WORD(&reg->isp.hccr,
  1286. (HCCR_ENABLE_PARITY + 0x7));
  1287. }
  1288. }
  1289. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1290. ha->isp_ops.enable_intrs(ha);
  1291. /* v2.19.5b6 */
  1292. /*
  1293. * Wait around max loop_reset_delay secs for the devices to come
  1294. * on-line. We don't want Linux scanning before we are ready.
  1295. *
  1296. */
  1297. for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
  1298. time_before(jiffies,wait_switch) &&
  1299. !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
  1300. && (ha->device_flags & SWITCH_FOUND) ;) {
  1301. qla2x00_check_fabric_devices(ha);
  1302. msleep(10);
  1303. }
  1304. pci_set_drvdata(pdev, ha);
  1305. ha->flags.init_done = 1;
  1306. num_hosts++;
  1307. ret = scsi_add_host(host, &pdev->dev);
  1308. if (ret)
  1309. goto probe_failed;
  1310. qla2x00_alloc_sysfs_attr(ha);
  1311. qla2x00_init_host_attr(ha);
  1312. qla_printk(KERN_INFO, ha, "\n"
  1313. " QLogic Fibre Channel HBA Driver: %s\n"
  1314. " QLogic %s - %s\n"
  1315. " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
  1316. ha->model_number, ha->model_desc ? ha->model_desc: "",
  1317. ha->brd_info->isp_name, ha->isp_ops.pci_info_str(ha, pci_info),
  1318. pci_name(pdev), ha->flags.enable_64bit_addressing ? '+': '-',
  1319. ha->host_no, ha->isp_ops.fw_version_str(ha, fw_str));
  1320. /* Go with fc_rport registration. */
  1321. list_for_each_entry(fcport, &ha->fcports, list)
  1322. qla2x00_reg_remote_port(ha, fcport);
  1323. return 0;
  1324. probe_failed:
  1325. qla2x00_free_device(ha);
  1326. scsi_host_put(host);
  1327. probe_disable_device:
  1328. pci_disable_device(pdev);
  1329. probe_out:
  1330. return ret;
  1331. }
  1332. EXPORT_SYMBOL_GPL(qla2x00_probe_one);
  1333. void qla2x00_remove_one(struct pci_dev *pdev)
  1334. {
  1335. scsi_qla_host_t *ha;
  1336. ha = pci_get_drvdata(pdev);
  1337. qla2x00_free_sysfs_attr(ha);
  1338. fc_remove_host(ha->host);
  1339. scsi_remove_host(ha->host);
  1340. qla2x00_free_device(ha);
  1341. scsi_host_put(ha->host);
  1342. pci_set_drvdata(pdev, NULL);
  1343. }
  1344. EXPORT_SYMBOL_GPL(qla2x00_remove_one);
  1345. static void
  1346. qla2x00_free_device(scsi_qla_host_t *ha)
  1347. {
  1348. int ret;
  1349. /* Abort any outstanding IO descriptors. */
  1350. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  1351. qla2x00_cancel_io_descriptors(ha);
  1352. /* Disable timer */
  1353. if (ha->timer_active)
  1354. qla2x00_stop_timer(ha);
  1355. /* Kill the kernel thread for this host */
  1356. if (ha->dpc_pid >= 0) {
  1357. ha->dpc_should_die = 1;
  1358. wmb();
  1359. ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
  1360. if (ret) {
  1361. qla_printk(KERN_ERR, ha,
  1362. "Unable to signal DPC thread -- (%d)\n", ret);
  1363. /* TODO: SOMETHING MORE??? */
  1364. } else {
  1365. wait_for_completion(&ha->dpc_exited);
  1366. }
  1367. }
  1368. /* Stop currently executing firmware. */
  1369. qla2x00_stop_firmware(ha);
  1370. /* turn-off interrupts on the card */
  1371. if (ha->interrupts_on)
  1372. ha->isp_ops.disable_intrs(ha);
  1373. qla2x00_mem_free(ha);
  1374. ha->flags.online = 0;
  1375. /* Detach interrupts */
  1376. if (ha->pdev->irq)
  1377. free_irq(ha->pdev->irq, ha);
  1378. /* release io space registers */
  1379. if (ha->iobase)
  1380. iounmap(ha->iobase);
  1381. pci_release_regions(ha->pdev);
  1382. pci_disable_device(ha->pdev);
  1383. }
  1384. /*
  1385. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  1386. *
  1387. * Input: ha = adapter block pointer. fcport = port structure pointer.
  1388. *
  1389. * Return: None.
  1390. *
  1391. * Context:
  1392. */
  1393. void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
  1394. int do_login)
  1395. {
  1396. if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
  1397. fc_remote_port_block(fcport->rport);
  1398. /*
  1399. * We may need to retry the login, so don't change the state of the
  1400. * port but do the retries.
  1401. */
  1402. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  1403. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1404. if (!do_login)
  1405. return;
  1406. if (fcport->login_retry == 0) {
  1407. fcport->login_retry = ha->login_retry_count;
  1408. set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
  1409. DEBUG(printk("scsi(%ld): Port login retry: "
  1410. "%02x%02x%02x%02x%02x%02x%02x%02x, "
  1411. "id = 0x%04x retry cnt=%d\n",
  1412. ha->host_no,
  1413. fcport->port_name[0],
  1414. fcport->port_name[1],
  1415. fcport->port_name[2],
  1416. fcport->port_name[3],
  1417. fcport->port_name[4],
  1418. fcport->port_name[5],
  1419. fcport->port_name[6],
  1420. fcport->port_name[7],
  1421. fcport->loop_id,
  1422. fcport->login_retry));
  1423. }
  1424. }
  1425. /*
  1426. * qla2x00_mark_all_devices_lost
  1427. * Updates fcport state when device goes offline.
  1428. *
  1429. * Input:
  1430. * ha = adapter block pointer.
  1431. * fcport = port structure pointer.
  1432. *
  1433. * Return:
  1434. * None.
  1435. *
  1436. * Context:
  1437. */
  1438. void
  1439. qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
  1440. {
  1441. fc_port_t *fcport;
  1442. list_for_each_entry(fcport, &ha->fcports, list) {
  1443. if (fcport->port_type != FCT_TARGET)
  1444. continue;
  1445. /*
  1446. * No point in marking the device as lost, if the device is
  1447. * already DEAD.
  1448. */
  1449. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  1450. continue;
  1451. if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
  1452. fc_remote_port_block(fcport->rport);
  1453. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1454. }
  1455. }
  1456. /*
  1457. * qla2x00_mem_alloc
  1458. * Allocates adapter memory.
  1459. *
  1460. * Returns:
  1461. * 0 = success.
  1462. * 1 = failure.
  1463. */
  1464. static uint8_t
  1465. qla2x00_mem_alloc(scsi_qla_host_t *ha)
  1466. {
  1467. char name[16];
  1468. uint8_t status = 1;
  1469. int retry= 10;
  1470. do {
  1471. /*
  1472. * This will loop only once if everything goes well, else some
  1473. * number of retries will be performed to get around a kernel
  1474. * bug where available mem is not allocated until after a
  1475. * little delay and a retry.
  1476. */
  1477. ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
  1478. (ha->request_q_length + 1) * sizeof(request_t),
  1479. &ha->request_dma, GFP_KERNEL);
  1480. if (ha->request_ring == NULL) {
  1481. qla_printk(KERN_WARNING, ha,
  1482. "Memory Allocation failed - request_ring\n");
  1483. qla2x00_mem_free(ha);
  1484. msleep(100);
  1485. continue;
  1486. }
  1487. ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
  1488. (ha->response_q_length + 1) * sizeof(response_t),
  1489. &ha->response_dma, GFP_KERNEL);
  1490. if (ha->response_ring == NULL) {
  1491. qla_printk(KERN_WARNING, ha,
  1492. "Memory Allocation failed - response_ring\n");
  1493. qla2x00_mem_free(ha);
  1494. msleep(100);
  1495. continue;
  1496. }
  1497. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
  1498. &ha->gid_list_dma, GFP_KERNEL);
  1499. if (ha->gid_list == NULL) {
  1500. qla_printk(KERN_WARNING, ha,
  1501. "Memory Allocation failed - gid_list\n");
  1502. qla2x00_mem_free(ha);
  1503. msleep(100);
  1504. continue;
  1505. }
  1506. ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
  1507. sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
  1508. if (ha->rlc_rsp == NULL) {
  1509. qla_printk(KERN_WARNING, ha,
  1510. "Memory Allocation failed - rlc");
  1511. qla2x00_mem_free(ha);
  1512. msleep(100);
  1513. continue;
  1514. }
  1515. snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
  1516. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  1517. DMA_POOL_SIZE, 8, 0);
  1518. if (ha->s_dma_pool == NULL) {
  1519. qla_printk(KERN_WARNING, ha,
  1520. "Memory Allocation failed - s_dma_pool\n");
  1521. qla2x00_mem_free(ha);
  1522. msleep(100);
  1523. continue;
  1524. }
  1525. /* get consistent memory allocated for init control block */
  1526. ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1527. &ha->init_cb_dma);
  1528. if (ha->init_cb == NULL) {
  1529. qla_printk(KERN_WARNING, ha,
  1530. "Memory Allocation failed - init_cb\n");
  1531. qla2x00_mem_free(ha);
  1532. msleep(100);
  1533. continue;
  1534. }
  1535. memset(ha->init_cb, 0, ha->init_cb_size);
  1536. /* Get consistent memory allocated for Get Port Database cmd */
  1537. ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1538. &ha->iodesc_pd_dma);
  1539. if (ha->iodesc_pd == NULL) {
  1540. /* error */
  1541. qla_printk(KERN_WARNING, ha,
  1542. "Memory Allocation failed - iodesc_pd\n");
  1543. qla2x00_mem_free(ha);
  1544. msleep(100);
  1545. continue;
  1546. }
  1547. memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
  1548. /* Allocate ioctl related memory. */
  1549. if (qla2x00_alloc_ioctl_mem(ha)) {
  1550. qla_printk(KERN_WARNING, ha,
  1551. "Memory Allocation failed - ioctl_mem\n");
  1552. qla2x00_mem_free(ha);
  1553. msleep(100);
  1554. continue;
  1555. }
  1556. if (qla2x00_allocate_sp_pool(ha)) {
  1557. qla_printk(KERN_WARNING, ha,
  1558. "Memory Allocation failed - "
  1559. "qla2x00_allocate_sp_pool()\n");
  1560. qla2x00_mem_free(ha);
  1561. msleep(100);
  1562. continue;
  1563. }
  1564. /* Allocate memory for SNS commands */
  1565. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1566. /* Get consistent memory allocated for SNS commands */
  1567. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  1568. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
  1569. GFP_KERNEL);
  1570. if (ha->sns_cmd == NULL) {
  1571. /* error */
  1572. qla_printk(KERN_WARNING, ha,
  1573. "Memory Allocation failed - sns_cmd\n");
  1574. qla2x00_mem_free(ha);
  1575. msleep(100);
  1576. continue;
  1577. }
  1578. memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
  1579. } else {
  1580. /* Get consistent memory allocated for MS IOCB */
  1581. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1582. &ha->ms_iocb_dma);
  1583. if (ha->ms_iocb == NULL) {
  1584. /* error */
  1585. qla_printk(KERN_WARNING, ha,
  1586. "Memory Allocation failed - ms_iocb\n");
  1587. qla2x00_mem_free(ha);
  1588. msleep(100);
  1589. continue;
  1590. }
  1591. memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
  1592. /*
  1593. * Get consistent memory allocated for CT SNS
  1594. * commands
  1595. */
  1596. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  1597. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
  1598. GFP_KERNEL);
  1599. if (ha->ct_sns == NULL) {
  1600. /* error */
  1601. qla_printk(KERN_WARNING, ha,
  1602. "Memory Allocation failed - ct_sns\n");
  1603. qla2x00_mem_free(ha);
  1604. msleep(100);
  1605. continue;
  1606. }
  1607. memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
  1608. }
  1609. /* Done all allocations without any error. */
  1610. status = 0;
  1611. } while (retry-- && status != 0);
  1612. if (status) {
  1613. printk(KERN_WARNING
  1614. "%s(): **** FAILED ****\n", __func__);
  1615. }
  1616. return(status);
  1617. }
  1618. /*
  1619. * qla2x00_mem_free
  1620. * Frees all adapter allocated memory.
  1621. *
  1622. * Input:
  1623. * ha = adapter block pointer.
  1624. */
  1625. static void
  1626. qla2x00_mem_free(scsi_qla_host_t *ha)
  1627. {
  1628. struct list_head *fcpl, *fcptemp;
  1629. fc_port_t *fcport;
  1630. unsigned int wtime;/* max wait time if mbx cmd is busy. */
  1631. if (ha == NULL) {
  1632. /* error */
  1633. DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
  1634. return;
  1635. }
  1636. /* Make sure all other threads are stopped. */
  1637. wtime = 60 * 1000;
  1638. while (ha->dpc_wait && wtime)
  1639. wtime = msleep_interruptible(wtime);
  1640. /* free ioctl memory */
  1641. qla2x00_free_ioctl_mem(ha);
  1642. /* free sp pool */
  1643. qla2x00_free_sp_pool(ha);
  1644. if (ha->sns_cmd)
  1645. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  1646. ha->sns_cmd, ha->sns_cmd_dma);
  1647. if (ha->ct_sns)
  1648. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  1649. ha->ct_sns, ha->ct_sns_dma);
  1650. if (ha->ms_iocb)
  1651. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  1652. if (ha->iodesc_pd)
  1653. dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
  1654. if (ha->init_cb)
  1655. dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
  1656. if (ha->s_dma_pool)
  1657. dma_pool_destroy(ha->s_dma_pool);
  1658. if (ha->rlc_rsp)
  1659. dma_free_coherent(&ha->pdev->dev,
  1660. sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
  1661. ha->rlc_rsp_dma);
  1662. if (ha->gid_list)
  1663. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  1664. ha->gid_list_dma);
  1665. if (ha->response_ring)
  1666. dma_free_coherent(&ha->pdev->dev,
  1667. (ha->response_q_length + 1) * sizeof(response_t),
  1668. ha->response_ring, ha->response_dma);
  1669. if (ha->request_ring)
  1670. dma_free_coherent(&ha->pdev->dev,
  1671. (ha->request_q_length + 1) * sizeof(request_t),
  1672. ha->request_ring, ha->request_dma);
  1673. ha->sns_cmd = NULL;
  1674. ha->sns_cmd_dma = 0;
  1675. ha->ct_sns = NULL;
  1676. ha->ct_sns_dma = 0;
  1677. ha->ms_iocb = NULL;
  1678. ha->ms_iocb_dma = 0;
  1679. ha->iodesc_pd = NULL;
  1680. ha->iodesc_pd_dma = 0;
  1681. ha->init_cb = NULL;
  1682. ha->init_cb_dma = 0;
  1683. ha->s_dma_pool = NULL;
  1684. ha->rlc_rsp = NULL;
  1685. ha->rlc_rsp_dma = 0;
  1686. ha->gid_list = NULL;
  1687. ha->gid_list_dma = 0;
  1688. ha->response_ring = NULL;
  1689. ha->response_dma = 0;
  1690. ha->request_ring = NULL;
  1691. ha->request_dma = 0;
  1692. list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
  1693. fcport = list_entry(fcpl, fc_port_t, list);
  1694. /* fc ports */
  1695. list_del_init(&fcport->list);
  1696. kfree(fcport);
  1697. }
  1698. INIT_LIST_HEAD(&ha->fcports);
  1699. if (ha->fw_dump)
  1700. free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
  1701. vfree(ha->fw_dump24);
  1702. vfree(ha->fw_dump_buffer);
  1703. ha->fw_dump = NULL;
  1704. ha->fw_dump24 = NULL;
  1705. ha->fw_dumped = 0;
  1706. ha->fw_dump_reading = 0;
  1707. ha->fw_dump_buffer = NULL;
  1708. }
  1709. /*
  1710. * qla2x00_allocate_sp_pool
  1711. * This routine is called during initialization to allocate
  1712. * memory for local srb_t.
  1713. *
  1714. * Input:
  1715. * ha = adapter block pointer.
  1716. *
  1717. * Context:
  1718. * Kernel context.
  1719. *
  1720. * Note: Sets the ref_count for non Null sp to one.
  1721. */
  1722. static int
  1723. qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
  1724. {
  1725. int rval;
  1726. rval = QLA_SUCCESS;
  1727. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  1728. mempool_free_slab, srb_cachep);
  1729. if (ha->srb_mempool == NULL) {
  1730. qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
  1731. rval = QLA_FUNCTION_FAILED;
  1732. }
  1733. return (rval);
  1734. }
  1735. /*
  1736. * This routine frees all adapter allocated memory.
  1737. *
  1738. */
  1739. static void
  1740. qla2x00_free_sp_pool( scsi_qla_host_t *ha)
  1741. {
  1742. if (ha->srb_mempool) {
  1743. mempool_destroy(ha->srb_mempool);
  1744. ha->srb_mempool = NULL;
  1745. }
  1746. }
  1747. /**************************************************************************
  1748. * qla2x00_do_dpc
  1749. * This kernel thread is a task that is schedule by the interrupt handler
  1750. * to perform the background processing for interrupts.
  1751. *
  1752. * Notes:
  1753. * This task always run in the context of a kernel thread. It
  1754. * is kick-off by the driver's detect code and starts up
  1755. * up one per adapter. It immediately goes to sleep and waits for
  1756. * some fibre event. When either the interrupt handler or
  1757. * the timer routine detects a event it will one of the task
  1758. * bits then wake us up.
  1759. **************************************************************************/
  1760. static int
  1761. qla2x00_do_dpc(void *data)
  1762. {
  1763. DECLARE_MUTEX_LOCKED(sem);
  1764. scsi_qla_host_t *ha;
  1765. fc_port_t *fcport;
  1766. uint8_t status;
  1767. uint16_t next_loopid;
  1768. ha = (scsi_qla_host_t *)data;
  1769. lock_kernel();
  1770. daemonize("%s_dpc", ha->host_str);
  1771. allow_signal(SIGHUP);
  1772. ha->dpc_wait = &sem;
  1773. set_user_nice(current, -20);
  1774. unlock_kernel();
  1775. complete(&ha->dpc_inited);
  1776. while (1) {
  1777. DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
  1778. if (down_interruptible(&sem))
  1779. break;
  1780. if (ha->dpc_should_die)
  1781. break;
  1782. DEBUG3(printk("qla2x00: DPC handler waking up\n"));
  1783. /* Initialization not yet finished. Don't do anything yet. */
  1784. if (!ha->flags.init_done || ha->dpc_active)
  1785. continue;
  1786. DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
  1787. ha->dpc_active = 1;
  1788. if (ha->flags.mbox_busy) {
  1789. ha->dpc_active = 0;
  1790. continue;
  1791. }
  1792. if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
  1793. DEBUG(printk("scsi(%ld): dpc: sched "
  1794. "qla2x00_abort_isp ha = %p\n",
  1795. ha->host_no, ha));
  1796. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  1797. &ha->dpc_flags))) {
  1798. if (qla2x00_abort_isp(ha)) {
  1799. /* failed. retry later */
  1800. set_bit(ISP_ABORT_NEEDED,
  1801. &ha->dpc_flags);
  1802. }
  1803. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  1804. }
  1805. DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
  1806. ha->host_no));
  1807. }
  1808. if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
  1809. (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
  1810. DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
  1811. ha->host_no));
  1812. qla2x00_rst_aen(ha);
  1813. clear_bit(RESET_ACTIVE, &ha->dpc_flags);
  1814. }
  1815. /* Retry each device up to login retry count */
  1816. if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
  1817. !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
  1818. atomic_read(&ha->loop_state) != LOOP_DOWN) {
  1819. DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
  1820. ha->host_no));
  1821. next_loopid = 0;
  1822. list_for_each_entry(fcport, &ha->fcports, list) {
  1823. if (fcport->port_type != FCT_TARGET)
  1824. continue;
  1825. /*
  1826. * If the port is not ONLINE then try to login
  1827. * to it if we haven't run out of retries.
  1828. */
  1829. if (atomic_read(&fcport->state) != FCS_ONLINE &&
  1830. fcport->login_retry) {
  1831. fcport->login_retry--;
  1832. if (fcport->flags & FCF_FABRIC_DEVICE) {
  1833. if (fcport->flags &
  1834. FCF_TAPE_PRESENT)
  1835. ha->isp_ops.fabric_logout(
  1836. ha, fcport->loop_id,
  1837. fcport->d_id.b.domain,
  1838. fcport->d_id.b.area,
  1839. fcport->d_id.b.al_pa);
  1840. status = qla2x00_fabric_login(
  1841. ha, fcport, &next_loopid);
  1842. } else
  1843. status =
  1844. qla2x00_local_device_login(
  1845. ha, fcport->loop_id);
  1846. if (status == QLA_SUCCESS) {
  1847. fcport->old_loop_id = fcport->loop_id;
  1848. DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
  1849. ha->host_no, fcport->loop_id));
  1850. fcport->port_login_retry_count =
  1851. ha->port_down_retry_count * PORT_RETRY_TIME;
  1852. atomic_set(&fcport->state, FCS_ONLINE);
  1853. atomic_set(&fcport->port_down_timer,
  1854. ha->port_down_retry_count * PORT_RETRY_TIME);
  1855. fcport->login_retry = 0;
  1856. } else if (status == 1) {
  1857. set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
  1858. /* retry the login again */
  1859. DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
  1860. ha->host_no,
  1861. fcport->login_retry, fcport->loop_id));
  1862. } else {
  1863. fcport->login_retry = 0;
  1864. }
  1865. }
  1866. if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
  1867. break;
  1868. }
  1869. DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
  1870. ha->host_no));
  1871. }
  1872. if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
  1873. atomic_read(&ha->loop_state) != LOOP_DOWN) {
  1874. clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
  1875. DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
  1876. ha->host_no));
  1877. set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  1878. DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
  1879. ha->host_no));
  1880. }
  1881. if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
  1882. DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
  1883. ha->host_no));
  1884. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  1885. &ha->dpc_flags))) {
  1886. qla2x00_loop_resync(ha);
  1887. clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
  1888. }
  1889. DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
  1890. ha->host_no));
  1891. }
  1892. if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
  1893. DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
  1894. ha->host_no));
  1895. qla2x00_rescan_fcports(ha);
  1896. DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
  1897. "end.\n",
  1898. ha->host_no));
  1899. }
  1900. if (!ha->interrupts_on)
  1901. ha->isp_ops.enable_intrs(ha);
  1902. ha->dpc_active = 0;
  1903. } /* End of while(1) */
  1904. DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
  1905. /*
  1906. * Make sure that nobody tries to wake us up again.
  1907. */
  1908. ha->dpc_wait = NULL;
  1909. ha->dpc_active = 0;
  1910. complete_and_exit(&ha->dpc_exited, 0);
  1911. }
  1912. /*
  1913. * qla2x00_rst_aen
  1914. * Processes asynchronous reset.
  1915. *
  1916. * Input:
  1917. * ha = adapter block pointer.
  1918. */
  1919. static void
  1920. qla2x00_rst_aen(scsi_qla_host_t *ha)
  1921. {
  1922. if (ha->flags.online && !ha->flags.reset_active &&
  1923. !atomic_read(&ha->loop_down_timer) &&
  1924. !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
  1925. do {
  1926. clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
  1927. /*
  1928. * Issue marker command only when we are going to start
  1929. * the I/O.
  1930. */
  1931. ha->marker_needed = 1;
  1932. } while (!atomic_read(&ha->loop_down_timer) &&
  1933. (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
  1934. }
  1935. }
  1936. static void
  1937. qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
  1938. {
  1939. struct scsi_cmnd *cmd = sp->cmd;
  1940. if (sp->flags & SRB_DMA_VALID) {
  1941. if (cmd->use_sg) {
  1942. dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
  1943. cmd->use_sg, cmd->sc_data_direction);
  1944. } else if (cmd->request_bufflen) {
  1945. dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
  1946. cmd->request_bufflen, cmd->sc_data_direction);
  1947. }
  1948. sp->flags &= ~SRB_DMA_VALID;
  1949. }
  1950. CMD_SP(cmd) = NULL;
  1951. }
  1952. void
  1953. qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
  1954. {
  1955. struct scsi_cmnd *cmd = sp->cmd;
  1956. qla2x00_sp_free_dma(ha, sp);
  1957. mempool_free(sp, ha->srb_mempool);
  1958. cmd->scsi_done(cmd);
  1959. }
  1960. /**************************************************************************
  1961. * qla2x00_timer
  1962. *
  1963. * Description:
  1964. * One second timer
  1965. *
  1966. * Context: Interrupt
  1967. ***************************************************************************/
  1968. static void
  1969. qla2x00_timer(scsi_qla_host_t *ha)
  1970. {
  1971. unsigned long cpu_flags = 0;
  1972. fc_port_t *fcport;
  1973. int start_dpc = 0;
  1974. int index;
  1975. srb_t *sp;
  1976. int t;
  1977. /*
  1978. * Ports - Port down timer.
  1979. *
  1980. * Whenever, a port is in the LOST state we start decrementing its port
  1981. * down timer every second until it reaches zero. Once it reaches zero
  1982. * the port it marked DEAD.
  1983. */
  1984. t = 0;
  1985. list_for_each_entry(fcport, &ha->fcports, list) {
  1986. if (fcport->port_type != FCT_TARGET)
  1987. continue;
  1988. if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  1989. if (atomic_read(&fcport->port_down_timer) == 0)
  1990. continue;
  1991. if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
  1992. atomic_set(&fcport->state, FCS_DEVICE_DEAD);
  1993. DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
  1994. "%d remaining\n",
  1995. ha->host_no,
  1996. t, atomic_read(&fcport->port_down_timer)));
  1997. }
  1998. t++;
  1999. } /* End of for fcport */
  2000. /* Loop down handler. */
  2001. if (atomic_read(&ha->loop_down_timer) > 0 &&
  2002. !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
  2003. if (atomic_read(&ha->loop_down_timer) ==
  2004. ha->loop_down_abort_time) {
  2005. DEBUG(printk("scsi(%ld): Loop Down - aborting the "
  2006. "queues before time expire\n",
  2007. ha->host_no));
  2008. if (!IS_QLA2100(ha) && ha->link_down_timeout)
  2009. atomic_set(&ha->loop_state, LOOP_DEAD);
  2010. /* Schedule an ISP abort to return any tape commands. */
  2011. spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
  2012. for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
  2013. index++) {
  2014. fc_port_t *sfcp;
  2015. sp = ha->outstanding_cmds[index];
  2016. if (!sp)
  2017. continue;
  2018. sfcp = sp->fcport;
  2019. if (!(sfcp->flags & FCF_TAPE_PRESENT))
  2020. continue;
  2021. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  2022. break;
  2023. }
  2024. spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
  2025. set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
  2026. start_dpc++;
  2027. }
  2028. /* if the loop has been down for 4 minutes, reinit adapter */
  2029. if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
  2030. DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
  2031. "restarting queues.\n",
  2032. ha->host_no));
  2033. set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
  2034. start_dpc++;
  2035. if (!(ha->device_flags & DFLG_NO_CABLE)) {
  2036. DEBUG(printk("scsi(%ld): Loop down - "
  2037. "aborting ISP.\n",
  2038. ha->host_no));
  2039. qla_printk(KERN_WARNING, ha,
  2040. "Loop down - aborting ISP.\n");
  2041. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  2042. }
  2043. }
  2044. DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
  2045. ha->host_no,
  2046. atomic_read(&ha->loop_down_timer)));
  2047. }
  2048. /* Schedule the DPC routine if needed */
  2049. if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
  2050. test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
  2051. start_dpc ||
  2052. test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
  2053. test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
  2054. test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
  2055. ha->dpc_wait && !ha->dpc_active) {
  2056. up(ha->dpc_wait);
  2057. }
  2058. qla2x00_restart_timer(ha, WATCH_INTERVAL);
  2059. }
  2060. /* XXX(hch): crude hack to emulate a down_timeout() */
  2061. int
  2062. qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
  2063. {
  2064. const unsigned int step = 100; /* msecs */
  2065. unsigned int iterations = jiffies_to_msecs(timeout)/100;
  2066. do {
  2067. if (!down_trylock(sema))
  2068. return 0;
  2069. if (msleep_interruptible(step))
  2070. break;
  2071. } while (--iterations >= 0);
  2072. return -ETIMEDOUT;
  2073. }
  2074. static struct qla_board_info qla_board_tbl[] = {
  2075. {
  2076. .drv_name = "qla2400",
  2077. .isp_name = "ISP2422",
  2078. .fw_fname = "ql2400_fw.bin",
  2079. .sht = &qla24xx_driver_template,
  2080. },
  2081. {
  2082. .drv_name = "qla2400",
  2083. .isp_name = "ISP2432",
  2084. .fw_fname = "ql2400_fw.bin",
  2085. .sht = &qla24xx_driver_template,
  2086. },
  2087. };
  2088. static struct pci_device_id qla2xxx_pci_tbl[] = {
  2089. {
  2090. .vendor = PCI_VENDOR_ID_QLOGIC,
  2091. .device = PCI_DEVICE_ID_QLOGIC_ISP2422,
  2092. .subvendor = PCI_ANY_ID,
  2093. .subdevice = PCI_ANY_ID,
  2094. .driver_data = (unsigned long)&qla_board_tbl[0],
  2095. },
  2096. {
  2097. .vendor = PCI_VENDOR_ID_QLOGIC,
  2098. .device = PCI_DEVICE_ID_QLOGIC_ISP2432,
  2099. .subvendor = PCI_ANY_ID,
  2100. .subdevice = PCI_ANY_ID,
  2101. .driver_data = (unsigned long)&qla_board_tbl[1],
  2102. },
  2103. {0, 0},
  2104. };
  2105. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  2106. static int __devinit
  2107. qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  2108. {
  2109. return qla2x00_probe_one(pdev,
  2110. (struct qla_board_info *)id->driver_data);
  2111. }
  2112. static void __devexit
  2113. qla2xxx_remove_one(struct pci_dev *pdev)
  2114. {
  2115. qla2x00_remove_one(pdev);
  2116. }
  2117. static struct pci_driver qla2xxx_pci_driver = {
  2118. .name = "qla2xxx",
  2119. .id_table = qla2xxx_pci_tbl,
  2120. .probe = qla2xxx_probe_one,
  2121. .remove = __devexit_p(qla2xxx_remove_one),
  2122. };
  2123. /**
  2124. * qla2x00_module_init - Module initialization.
  2125. **/
  2126. static int __init
  2127. qla2x00_module_init(void)
  2128. {
  2129. int ret = 0;
  2130. /* Allocate cache for SRBs. */
  2131. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  2132. SLAB_HWCACHE_ALIGN, NULL, NULL);
  2133. if (srb_cachep == NULL) {
  2134. printk(KERN_ERR
  2135. "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
  2136. return -ENOMEM;
  2137. }
  2138. /* Derive version string. */
  2139. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  2140. #if DEBUG_QLA2100
  2141. strcat(qla2x00_version_str, "-debug");
  2142. #endif
  2143. qla2xxx_transport_template =
  2144. fc_attach_transport(&qla2xxx_transport_functions);
  2145. if (!qla2xxx_transport_template)
  2146. return -ENODEV;
  2147. printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
  2148. ret = pci_module_init(&qla2xxx_pci_driver);
  2149. if (ret) {
  2150. kmem_cache_destroy(srb_cachep);
  2151. fc_release_transport(qla2xxx_transport_template);
  2152. }
  2153. return ret;
  2154. }
  2155. /**
  2156. * qla2x00_module_exit - Module cleanup.
  2157. **/
  2158. static void __exit
  2159. qla2x00_module_exit(void)
  2160. {
  2161. pci_unregister_driver(&qla2xxx_pci_driver);
  2162. kmem_cache_destroy(srb_cachep);
  2163. fc_release_transport(qla2xxx_transport_template);
  2164. }
  2165. module_init(qla2x00_module_init);
  2166. module_exit(qla2x00_module_exit);
  2167. MODULE_AUTHOR("QLogic Corporation");
  2168. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  2169. MODULE_LICENSE("GPL");
  2170. MODULE_VERSION(QLA2XXX_VERSION);