qla_os.c 76 KB

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