qla_os.c 86 KB

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