qla_os.c 64 KB

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