qla_os.c 77 KB

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