qla_os.c 64 KB

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