qla_os.c 89 KB

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