qla_os.c 85 KB

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