qla_os.c 89 KB

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