qla_os.c 89 KB

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