qla_os.c 83 KB

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