qla_os.c 83 KB

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