qla_os.c 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255
  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. };
  1155. static struct isp_operations qla2300_isp_ops = {
  1156. .pci_config = qla2300_pci_config,
  1157. .reset_chip = qla2x00_reset_chip,
  1158. .chip_diag = qla2x00_chip_diag,
  1159. .config_rings = qla2x00_config_rings,
  1160. .reset_adapter = qla2x00_reset_adapter,
  1161. .nvram_config = qla2x00_nvram_config,
  1162. .update_fw_options = qla2x00_update_fw_options,
  1163. .load_risc = qla2x00_load_risc,
  1164. .pci_info_str = qla2x00_pci_info_str,
  1165. .fw_version_str = qla2x00_fw_version_str,
  1166. .intr_handler = qla2300_intr_handler,
  1167. .enable_intrs = qla2x00_enable_intrs,
  1168. .disable_intrs = qla2x00_disable_intrs,
  1169. .abort_command = qla2x00_abort_command,
  1170. .target_reset = qla2x00_abort_target,
  1171. .lun_reset = qla2x00_lun_reset,
  1172. .fabric_login = qla2x00_login_fabric,
  1173. .fabric_logout = qla2x00_fabric_logout,
  1174. .calc_req_entries = qla2x00_calc_iocbs_32,
  1175. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1176. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1177. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1178. .read_nvram = qla2x00_read_nvram_data,
  1179. .write_nvram = qla2x00_write_nvram_data,
  1180. .fw_dump = qla2300_fw_dump,
  1181. .beacon_on = qla2x00_beacon_on,
  1182. .beacon_off = qla2x00_beacon_off,
  1183. .beacon_blink = qla2x00_beacon_blink,
  1184. .read_optrom = qla2x00_read_optrom_data,
  1185. .write_optrom = qla2x00_write_optrom_data,
  1186. .get_flash_version = qla2x00_get_flash_version,
  1187. .start_scsi = qla2x00_start_scsi,
  1188. };
  1189. static struct isp_operations qla24xx_isp_ops = {
  1190. .pci_config = qla24xx_pci_config,
  1191. .reset_chip = qla24xx_reset_chip,
  1192. .chip_diag = qla24xx_chip_diag,
  1193. .config_rings = qla24xx_config_rings,
  1194. .reset_adapter = qla24xx_reset_adapter,
  1195. .nvram_config = qla24xx_nvram_config,
  1196. .update_fw_options = qla24xx_update_fw_options,
  1197. .load_risc = qla24xx_load_risc,
  1198. .pci_info_str = qla24xx_pci_info_str,
  1199. .fw_version_str = qla24xx_fw_version_str,
  1200. .intr_handler = qla24xx_intr_handler,
  1201. .enable_intrs = qla24xx_enable_intrs,
  1202. .disable_intrs = qla24xx_disable_intrs,
  1203. .abort_command = qla24xx_abort_command,
  1204. .target_reset = qla24xx_abort_target,
  1205. .lun_reset = qla24xx_lun_reset,
  1206. .fabric_login = qla24xx_login_fabric,
  1207. .fabric_logout = qla24xx_fabric_logout,
  1208. .calc_req_entries = NULL,
  1209. .build_iocbs = NULL,
  1210. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1211. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1212. .read_nvram = qla24xx_read_nvram_data,
  1213. .write_nvram = qla24xx_write_nvram_data,
  1214. .fw_dump = qla24xx_fw_dump,
  1215. .beacon_on = qla24xx_beacon_on,
  1216. .beacon_off = qla24xx_beacon_off,
  1217. .beacon_blink = qla24xx_beacon_blink,
  1218. .read_optrom = qla24xx_read_optrom_data,
  1219. .write_optrom = qla24xx_write_optrom_data,
  1220. .get_flash_version = qla24xx_get_flash_version,
  1221. .start_scsi = qla24xx_start_scsi,
  1222. };
  1223. static struct isp_operations qla25xx_isp_ops = {
  1224. .pci_config = qla25xx_pci_config,
  1225. .reset_chip = qla24xx_reset_chip,
  1226. .chip_diag = qla24xx_chip_diag,
  1227. .config_rings = qla24xx_config_rings,
  1228. .reset_adapter = qla24xx_reset_adapter,
  1229. .nvram_config = qla24xx_nvram_config,
  1230. .update_fw_options = qla24xx_update_fw_options,
  1231. .load_risc = qla24xx_load_risc,
  1232. .pci_info_str = qla24xx_pci_info_str,
  1233. .fw_version_str = qla24xx_fw_version_str,
  1234. .intr_handler = qla24xx_intr_handler,
  1235. .enable_intrs = qla24xx_enable_intrs,
  1236. .disable_intrs = qla24xx_disable_intrs,
  1237. .abort_command = qla24xx_abort_command,
  1238. .target_reset = qla24xx_abort_target,
  1239. .lun_reset = qla24xx_lun_reset,
  1240. .fabric_login = qla24xx_login_fabric,
  1241. .fabric_logout = qla24xx_fabric_logout,
  1242. .calc_req_entries = NULL,
  1243. .build_iocbs = NULL,
  1244. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1245. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1246. .read_nvram = qla25xx_read_nvram_data,
  1247. .write_nvram = qla25xx_write_nvram_data,
  1248. .fw_dump = qla25xx_fw_dump,
  1249. .beacon_on = qla24xx_beacon_on,
  1250. .beacon_off = qla24xx_beacon_off,
  1251. .beacon_blink = qla24xx_beacon_blink,
  1252. .read_optrom = qla25xx_read_optrom_data,
  1253. .write_optrom = qla24xx_write_optrom_data,
  1254. .get_flash_version = qla24xx_get_flash_version,
  1255. .start_scsi = qla24xx_start_scsi,
  1256. };
  1257. static struct isp_operations qla81xx_isp_ops = {
  1258. .pci_config = qla25xx_pci_config,
  1259. .reset_chip = qla24xx_reset_chip,
  1260. .chip_diag = qla24xx_chip_diag,
  1261. .config_rings = qla24xx_config_rings,
  1262. .reset_adapter = qla24xx_reset_adapter,
  1263. .nvram_config = qla81xx_nvram_config,
  1264. .update_fw_options = qla81xx_update_fw_options,
  1265. .load_risc = qla81xx_load_risc,
  1266. .pci_info_str = qla24xx_pci_info_str,
  1267. .fw_version_str = qla24xx_fw_version_str,
  1268. .intr_handler = qla24xx_intr_handler,
  1269. .enable_intrs = qla24xx_enable_intrs,
  1270. .disable_intrs = qla24xx_disable_intrs,
  1271. .abort_command = qla24xx_abort_command,
  1272. .target_reset = qla24xx_abort_target,
  1273. .lun_reset = qla24xx_lun_reset,
  1274. .fabric_login = qla24xx_login_fabric,
  1275. .fabric_logout = qla24xx_fabric_logout,
  1276. .calc_req_entries = NULL,
  1277. .build_iocbs = NULL,
  1278. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1279. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1280. .read_nvram = qla25xx_read_nvram_data,
  1281. .write_nvram = qla25xx_write_nvram_data,
  1282. .fw_dump = qla81xx_fw_dump,
  1283. .beacon_on = qla24xx_beacon_on,
  1284. .beacon_off = qla24xx_beacon_off,
  1285. .beacon_blink = qla24xx_beacon_blink,
  1286. .read_optrom = qla25xx_read_optrom_data,
  1287. .write_optrom = qla24xx_write_optrom_data,
  1288. .get_flash_version = qla24xx_get_flash_version,
  1289. .start_scsi = qla24xx_start_scsi,
  1290. };
  1291. static inline void
  1292. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  1293. {
  1294. ha->device_type = DT_EXTENDED_IDS;
  1295. switch (ha->pdev->device) {
  1296. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1297. ha->device_type |= DT_ISP2100;
  1298. ha->device_type &= ~DT_EXTENDED_IDS;
  1299. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1300. break;
  1301. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1302. ha->device_type |= DT_ISP2200;
  1303. ha->device_type &= ~DT_EXTENDED_IDS;
  1304. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1305. break;
  1306. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1307. ha->device_type |= DT_ISP2300;
  1308. ha->device_type |= DT_ZIO_SUPPORTED;
  1309. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1310. break;
  1311. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1312. ha->device_type |= DT_ISP2312;
  1313. ha->device_type |= DT_ZIO_SUPPORTED;
  1314. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1315. break;
  1316. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1317. ha->device_type |= DT_ISP2322;
  1318. ha->device_type |= DT_ZIO_SUPPORTED;
  1319. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1320. ha->pdev->subsystem_device == 0x0170)
  1321. ha->device_type |= DT_OEM_001;
  1322. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1323. break;
  1324. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1325. ha->device_type |= DT_ISP6312;
  1326. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1327. break;
  1328. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1329. ha->device_type |= DT_ISP6322;
  1330. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1331. break;
  1332. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1333. ha->device_type |= DT_ISP2422;
  1334. ha->device_type |= DT_ZIO_SUPPORTED;
  1335. ha->device_type |= DT_FWI2;
  1336. ha->device_type |= DT_IIDMA;
  1337. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1338. break;
  1339. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1340. ha->device_type |= DT_ISP2432;
  1341. ha->device_type |= DT_ZIO_SUPPORTED;
  1342. ha->device_type |= DT_FWI2;
  1343. ha->device_type |= DT_IIDMA;
  1344. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1345. break;
  1346. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1347. ha->device_type |= DT_ISP8432;
  1348. ha->device_type |= DT_ZIO_SUPPORTED;
  1349. ha->device_type |= DT_FWI2;
  1350. ha->device_type |= DT_IIDMA;
  1351. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1352. break;
  1353. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1354. ha->device_type |= DT_ISP5422;
  1355. ha->device_type |= DT_FWI2;
  1356. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1357. break;
  1358. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  1359. ha->device_type |= DT_ISP5432;
  1360. ha->device_type |= DT_FWI2;
  1361. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1362. break;
  1363. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  1364. ha->device_type |= DT_ISP2532;
  1365. ha->device_type |= DT_ZIO_SUPPORTED;
  1366. ha->device_type |= DT_FWI2;
  1367. ha->device_type |= DT_IIDMA;
  1368. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1369. break;
  1370. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  1371. ha->device_type |= DT_ISP8001;
  1372. ha->device_type |= DT_ZIO_SUPPORTED;
  1373. ha->device_type |= DT_FWI2;
  1374. ha->device_type |= DT_IIDMA;
  1375. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1376. break;
  1377. }
  1378. }
  1379. static int
  1380. qla2x00_iospace_config(struct qla_hw_data *ha)
  1381. {
  1382. resource_size_t pio;
  1383. uint16_t msix;
  1384. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1385. QLA2XXX_DRIVER_NAME)) {
  1386. qla_printk(KERN_WARNING, ha,
  1387. "Failed to reserve PIO/MMIO regions (%s)\n",
  1388. pci_name(ha->pdev));
  1389. goto iospace_error_exit;
  1390. }
  1391. if (!(ha->bars & 1))
  1392. goto skip_pio;
  1393. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1394. pio = pci_resource_start(ha->pdev, 0);
  1395. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1396. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1397. qla_printk(KERN_WARNING, ha,
  1398. "Invalid PCI I/O region size (%s)...\n",
  1399. pci_name(ha->pdev));
  1400. pio = 0;
  1401. }
  1402. } else {
  1403. qla_printk(KERN_WARNING, ha,
  1404. "region #0 not a PIO resource (%s)...\n",
  1405. pci_name(ha->pdev));
  1406. pio = 0;
  1407. }
  1408. ha->pio_address = pio;
  1409. skip_pio:
  1410. /* Use MMIO operations for all accesses. */
  1411. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1412. qla_printk(KERN_ERR, ha,
  1413. "region #1 not an MMIO resource (%s), aborting\n",
  1414. pci_name(ha->pdev));
  1415. goto iospace_error_exit;
  1416. }
  1417. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1418. qla_printk(KERN_ERR, ha,
  1419. "Invalid PCI mem region size (%s), aborting\n",
  1420. pci_name(ha->pdev));
  1421. goto iospace_error_exit;
  1422. }
  1423. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1424. if (!ha->iobase) {
  1425. qla_printk(KERN_ERR, ha,
  1426. "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
  1427. goto iospace_error_exit;
  1428. }
  1429. /* Determine queue resources */
  1430. ha->max_queues = 1;
  1431. if (ql2xmaxqueues <= 1 || (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1432. goto mqiobase_exit;
  1433. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1434. pci_resource_len(ha->pdev, 3));
  1435. if (ha->mqiobase) {
  1436. /* Read MSIX vector size of the board */
  1437. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1438. ha->msix_count = msix;
  1439. /* Max queues are bounded by available msix vectors */
  1440. /* queue 0 uses two msix vectors */
  1441. if (ha->msix_count - 1 < ql2xmaxqueues)
  1442. ha->max_queues = ha->msix_count - 1;
  1443. else if (ql2xmaxqueues > QLA_MQ_SIZE)
  1444. ha->max_queues = QLA_MQ_SIZE;
  1445. else
  1446. ha->max_queues = ql2xmaxqueues;
  1447. qla_printk(KERN_INFO, ha,
  1448. "MSI-X vector count: %d\n", msix);
  1449. }
  1450. mqiobase_exit:
  1451. ha->msix_count = ha->max_queues + 1;
  1452. return (0);
  1453. iospace_error_exit:
  1454. return (-ENOMEM);
  1455. }
  1456. static void
  1457. qla2xxx_scan_start(struct Scsi_Host *shost)
  1458. {
  1459. scsi_qla_host_t *vha = shost_priv(shost);
  1460. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  1461. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  1462. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  1463. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  1464. }
  1465. static int
  1466. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1467. {
  1468. scsi_qla_host_t *vha = shost_priv(shost);
  1469. if (!vha->host)
  1470. return 1;
  1471. if (time > vha->hw->loop_reset_delay * HZ)
  1472. return 1;
  1473. return atomic_read(&vha->loop_state) == LOOP_READY;
  1474. }
  1475. /*
  1476. * PCI driver interface
  1477. */
  1478. static int __devinit
  1479. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  1480. {
  1481. int ret = -ENODEV;
  1482. struct Scsi_Host *host;
  1483. scsi_qla_host_t *base_vha = NULL;
  1484. struct qla_hw_data *ha;
  1485. char pci_info[30];
  1486. char fw_str[30];
  1487. struct scsi_host_template *sht;
  1488. int bars, max_id, mem_only = 0;
  1489. uint16_t req_length = 0, rsp_length = 0;
  1490. struct req_que *req = NULL;
  1491. struct rsp_que *rsp = NULL;
  1492. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  1493. sht = &qla2x00_driver_template;
  1494. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  1495. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  1496. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  1497. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  1498. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  1499. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  1500. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
  1501. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1502. sht = &qla24xx_driver_template;
  1503. mem_only = 1;
  1504. }
  1505. if (mem_only) {
  1506. if (pci_enable_device_mem(pdev))
  1507. goto probe_out;
  1508. } else {
  1509. if (pci_enable_device(pdev))
  1510. goto probe_out;
  1511. }
  1512. /* This may fail but that's ok */
  1513. pci_enable_pcie_error_reporting(pdev);
  1514. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  1515. if (!ha) {
  1516. DEBUG(printk("Unable to allocate memory for ha\n"));
  1517. goto probe_out;
  1518. }
  1519. ha->pdev = pdev;
  1520. /* Clear our data area */
  1521. ha->bars = bars;
  1522. ha->mem_only = mem_only;
  1523. spin_lock_init(&ha->hardware_lock);
  1524. /* Set ISP-type information. */
  1525. qla2x00_set_isp_flags(ha);
  1526. /* Configure PCI I/O space */
  1527. ret = qla2x00_iospace_config(ha);
  1528. if (ret)
  1529. goto probe_hw_failed;
  1530. qla_printk(KERN_INFO, ha,
  1531. "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
  1532. ha->iobase);
  1533. ha->prev_topology = 0;
  1534. ha->init_cb_size = sizeof(init_cb_t);
  1535. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  1536. ha->optrom_size = OPTROM_SIZE_2300;
  1537. /* Assign ISP specific operations. */
  1538. max_id = MAX_TARGETS_2200;
  1539. if (IS_QLA2100(ha)) {
  1540. max_id = MAX_TARGETS_2100;
  1541. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  1542. req_length = REQUEST_ENTRY_CNT_2100;
  1543. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1544. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1545. ha->gid_list_info_size = 4;
  1546. ha->flash_conf_off = ~0;
  1547. ha->flash_data_off = ~0;
  1548. ha->nvram_conf_off = ~0;
  1549. ha->nvram_data_off = ~0;
  1550. ha->isp_ops = &qla2100_isp_ops;
  1551. } else if (IS_QLA2200(ha)) {
  1552. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1553. req_length = REQUEST_ENTRY_CNT_2200;
  1554. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1555. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1556. ha->gid_list_info_size = 4;
  1557. ha->flash_conf_off = ~0;
  1558. ha->flash_data_off = ~0;
  1559. ha->nvram_conf_off = ~0;
  1560. ha->nvram_data_off = ~0;
  1561. ha->isp_ops = &qla2100_isp_ops;
  1562. } else if (IS_QLA23XX(ha)) {
  1563. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1564. req_length = REQUEST_ENTRY_CNT_2200;
  1565. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1566. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1567. ha->gid_list_info_size = 6;
  1568. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1569. ha->optrom_size = OPTROM_SIZE_2322;
  1570. ha->flash_conf_off = ~0;
  1571. ha->flash_data_off = ~0;
  1572. ha->nvram_conf_off = ~0;
  1573. ha->nvram_data_off = ~0;
  1574. ha->isp_ops = &qla2300_isp_ops;
  1575. } else if (IS_QLA24XX_TYPE(ha)) {
  1576. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1577. req_length = REQUEST_ENTRY_CNT_24XX;
  1578. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1579. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1580. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1581. ha->gid_list_info_size = 8;
  1582. ha->optrom_size = OPTROM_SIZE_24XX;
  1583. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  1584. ha->isp_ops = &qla24xx_isp_ops;
  1585. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1586. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1587. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1588. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1589. } else if (IS_QLA25XX(ha)) {
  1590. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1591. req_length = REQUEST_ENTRY_CNT_24XX;
  1592. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1593. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1594. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1595. ha->gid_list_info_size = 8;
  1596. ha->optrom_size = OPTROM_SIZE_25XX;
  1597. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1598. ha->isp_ops = &qla25xx_isp_ops;
  1599. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1600. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1601. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1602. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1603. } else if (IS_QLA81XX(ha)) {
  1604. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1605. req_length = REQUEST_ENTRY_CNT_24XX;
  1606. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1607. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1608. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  1609. ha->gid_list_info_size = 8;
  1610. ha->optrom_size = OPTROM_SIZE_81XX;
  1611. ha->isp_ops = &qla81xx_isp_ops;
  1612. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  1613. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  1614. ha->nvram_conf_off = ~0;
  1615. ha->nvram_data_off = ~0;
  1616. }
  1617. mutex_init(&ha->vport_lock);
  1618. init_completion(&ha->mbx_cmd_comp);
  1619. complete(&ha->mbx_cmd_comp);
  1620. init_completion(&ha->mbx_intr_comp);
  1621. set_bit(0, (unsigned long *) ha->vp_idx_map);
  1622. qla2x00_config_dma_addressing(ha);
  1623. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  1624. if (!ret) {
  1625. qla_printk(KERN_WARNING, ha,
  1626. "[ERROR] Failed to allocate memory for adapter\n");
  1627. goto probe_hw_failed;
  1628. }
  1629. req->max_q_depth = MAX_Q_DEPTH;
  1630. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  1631. req->max_q_depth = ql2xmaxqdepth;
  1632. base_vha = qla2x00_create_host(sht, ha);
  1633. if (!base_vha) {
  1634. qla_printk(KERN_WARNING, ha,
  1635. "[ERROR] Failed to allocate memory for scsi_host\n");
  1636. ret = -ENOMEM;
  1637. qla2x00_mem_free(ha);
  1638. qla2x00_free_que(ha, req, rsp);
  1639. goto probe_hw_failed;
  1640. }
  1641. pci_set_drvdata(pdev, base_vha);
  1642. host = base_vha->host;
  1643. base_vha->req_ques[0] = req->id;
  1644. host->can_queue = req->length + 128;
  1645. if (IS_QLA2XXX_MIDTYPE(ha))
  1646. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  1647. else
  1648. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  1649. base_vha->vp_idx;
  1650. if (IS_QLA2100(ha))
  1651. host->sg_tablesize = 32;
  1652. host->max_id = max_id;
  1653. host->this_id = 255;
  1654. host->cmd_per_lun = 3;
  1655. host->unique_id = host->host_no;
  1656. host->max_cmd_len = MAX_CMDSZ;
  1657. host->max_channel = MAX_BUSES - 1;
  1658. host->max_lun = MAX_LUNS;
  1659. host->transportt = qla2xxx_transport_template;
  1660. /* Set up the irqs */
  1661. ret = qla2x00_request_irqs(ha, rsp);
  1662. if (ret)
  1663. goto probe_init_failed;
  1664. /* Alloc arrays of request and response ring ptrs */
  1665. if (!qla2x00_alloc_queues(ha)) {
  1666. qla_printk(KERN_WARNING, ha,
  1667. "[ERROR] Failed to allocate memory for queue"
  1668. " pointers\n");
  1669. goto probe_init_failed;
  1670. }
  1671. ha->rsp_q_map[0] = rsp;
  1672. ha->req_q_map[0] = req;
  1673. /* FWI2-capable only. */
  1674. req->req_q_in = &ha->iobase->isp24.req_q_in;
  1675. req->req_q_out = &ha->iobase->isp24.req_q_out;
  1676. rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
  1677. rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
  1678. if (ha->mqenable) {
  1679. req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
  1680. req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
  1681. rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
  1682. rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
  1683. }
  1684. if (qla2x00_initialize_adapter(base_vha)) {
  1685. qla_printk(KERN_WARNING, ha,
  1686. "Failed to initialize adapter\n");
  1687. DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
  1688. "Adapter flags %x.\n",
  1689. base_vha->host_no, base_vha->device_flags));
  1690. ret = -ENODEV;
  1691. goto probe_failed;
  1692. }
  1693. /*
  1694. * Startup the kernel thread for this host adapter
  1695. */
  1696. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  1697. "%s_dpc", base_vha->host_str);
  1698. if (IS_ERR(ha->dpc_thread)) {
  1699. qla_printk(KERN_WARNING, ha,
  1700. "Unable to start DPC thread!\n");
  1701. ret = PTR_ERR(ha->dpc_thread);
  1702. goto probe_failed;
  1703. }
  1704. list_add_tail(&base_vha->list, &ha->vp_list);
  1705. base_vha->host->irq = ha->pdev->irq;
  1706. /* Initialized the timer */
  1707. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  1708. DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
  1709. base_vha->host_no, ha));
  1710. base_vha->flags.init_done = 1;
  1711. base_vha->flags.online = 1;
  1712. ret = scsi_add_host(host, &pdev->dev);
  1713. if (ret)
  1714. goto probe_failed;
  1715. ha->isp_ops->enable_intrs(ha);
  1716. scsi_scan_host(host);
  1717. qla2x00_alloc_sysfs_attr(base_vha);
  1718. qla2x00_init_host_attr(base_vha);
  1719. qla2x00_dfs_setup(base_vha);
  1720. qla_printk(KERN_INFO, ha, "\n"
  1721. " QLogic Fibre Channel HBA Driver: %s\n"
  1722. " QLogic %s - %s\n"
  1723. " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
  1724. qla2x00_version_str, ha->model_number,
  1725. ha->model_desc ? ha->model_desc : "", pdev->device,
  1726. ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
  1727. ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
  1728. ha->isp_ops->fw_version_str(base_vha, fw_str));
  1729. return 0;
  1730. probe_init_failed:
  1731. qla2x00_free_que(ha, req, rsp);
  1732. ha->max_queues = 0;
  1733. probe_failed:
  1734. qla2x00_free_device(base_vha);
  1735. scsi_host_put(base_vha->host);
  1736. probe_hw_failed:
  1737. if (ha->iobase)
  1738. iounmap(ha->iobase);
  1739. pci_release_selected_regions(ha->pdev, ha->bars);
  1740. kfree(ha);
  1741. ha = NULL;
  1742. probe_out:
  1743. pci_disable_device(pdev);
  1744. return ret;
  1745. }
  1746. static void
  1747. qla2x00_remove_one(struct pci_dev *pdev)
  1748. {
  1749. scsi_qla_host_t *base_vha, *vha, *temp;
  1750. struct qla_hw_data *ha;
  1751. base_vha = pci_get_drvdata(pdev);
  1752. ha = base_vha->hw;
  1753. list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
  1754. if (vha && vha->fc_vport)
  1755. fc_vport_terminate(vha->fc_vport);
  1756. }
  1757. set_bit(UNLOADING, &base_vha->dpc_flags);
  1758. qla2x00_dfs_remove(base_vha);
  1759. qla84xx_put_chip(base_vha);
  1760. qla2x00_free_sysfs_attr(base_vha);
  1761. fc_remove_host(base_vha->host);
  1762. scsi_remove_host(base_vha->host);
  1763. qla2x00_free_device(base_vha);
  1764. scsi_host_put(base_vha->host);
  1765. if (ha->iobase)
  1766. iounmap(ha->iobase);
  1767. if (ha->mqiobase)
  1768. iounmap(ha->mqiobase);
  1769. pci_release_selected_regions(ha->pdev, ha->bars);
  1770. kfree(ha);
  1771. ha = NULL;
  1772. pci_disable_device(pdev);
  1773. pci_set_drvdata(pdev, NULL);
  1774. }
  1775. static void
  1776. qla2x00_free_device(scsi_qla_host_t *vha)
  1777. {
  1778. struct qla_hw_data *ha = vha->hw;
  1779. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  1780. /* Disable timer */
  1781. if (vha->timer_active)
  1782. qla2x00_stop_timer(vha);
  1783. vha->flags.online = 0;
  1784. /* Kill the kernel thread for this host */
  1785. if (ha->dpc_thread) {
  1786. struct task_struct *t = ha->dpc_thread;
  1787. /*
  1788. * qla2xxx_wake_dpc checks for ->dpc_thread
  1789. * so we need to zero it out.
  1790. */
  1791. ha->dpc_thread = NULL;
  1792. kthread_stop(t);
  1793. }
  1794. if (ha->flags.fce_enabled)
  1795. qla2x00_disable_fce_trace(vha, NULL, NULL);
  1796. if (ha->eft)
  1797. qla2x00_disable_eft_trace(vha);
  1798. /* Stop currently executing firmware. */
  1799. qla2x00_try_to_stop_firmware(vha);
  1800. /* turn-off interrupts on the card */
  1801. if (ha->interrupts_on)
  1802. ha->isp_ops->disable_intrs(ha);
  1803. qla2x00_free_irqs(vha);
  1804. qla2x00_mem_free(ha);
  1805. qla2x00_free_queues(ha);
  1806. }
  1807. static inline void
  1808. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  1809. int defer)
  1810. {
  1811. struct fc_rport *rport;
  1812. if (!fcport->rport)
  1813. return;
  1814. rport = fcport->rport;
  1815. if (defer) {
  1816. spin_lock_irq(vha->host->host_lock);
  1817. fcport->drport = rport;
  1818. spin_unlock_irq(vha->host->host_lock);
  1819. set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
  1820. qla2xxx_wake_dpc(vha);
  1821. } else
  1822. fc_remote_port_delete(rport);
  1823. }
  1824. /*
  1825. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  1826. *
  1827. * Input: ha = adapter block pointer. fcport = port structure pointer.
  1828. *
  1829. * Return: None.
  1830. *
  1831. * Context:
  1832. */
  1833. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  1834. int do_login, int defer)
  1835. {
  1836. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  1837. vha->vp_idx == fcport->vp_idx) {
  1838. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1839. qla2x00_schedule_rport_del(vha, fcport, defer);
  1840. }
  1841. /*
  1842. * We may need to retry the login, so don't change the state of the
  1843. * port but do the retries.
  1844. */
  1845. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  1846. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1847. if (!do_login)
  1848. return;
  1849. if (fcport->login_retry == 0) {
  1850. fcport->login_retry = vha->hw->login_retry_count;
  1851. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  1852. DEBUG(printk("scsi(%ld): Port login retry: "
  1853. "%02x%02x%02x%02x%02x%02x%02x%02x, "
  1854. "id = 0x%04x retry cnt=%d\n",
  1855. vha->host_no,
  1856. fcport->port_name[0],
  1857. fcport->port_name[1],
  1858. fcport->port_name[2],
  1859. fcport->port_name[3],
  1860. fcport->port_name[4],
  1861. fcport->port_name[5],
  1862. fcport->port_name[6],
  1863. fcport->port_name[7],
  1864. fcport->loop_id,
  1865. fcport->login_retry));
  1866. }
  1867. }
  1868. /*
  1869. * qla2x00_mark_all_devices_lost
  1870. * Updates fcport state when device goes offline.
  1871. *
  1872. * Input:
  1873. * ha = adapter block pointer.
  1874. * fcport = port structure pointer.
  1875. *
  1876. * Return:
  1877. * None.
  1878. *
  1879. * Context:
  1880. */
  1881. void
  1882. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  1883. {
  1884. fc_port_t *fcport;
  1885. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1886. if (vha->vp_idx != fcport->vp_idx)
  1887. continue;
  1888. /*
  1889. * No point in marking the device as lost, if the device is
  1890. * already DEAD.
  1891. */
  1892. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  1893. continue;
  1894. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  1895. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1896. qla2x00_schedule_rport_del(vha, fcport, defer);
  1897. } else
  1898. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1899. }
  1900. }
  1901. /*
  1902. * qla2x00_mem_alloc
  1903. * Allocates adapter memory.
  1904. *
  1905. * Returns:
  1906. * 0 = success.
  1907. * !0 = failure.
  1908. */
  1909. static int
  1910. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  1911. struct req_que **req, struct rsp_que **rsp)
  1912. {
  1913. char name[16];
  1914. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  1915. &ha->init_cb_dma, GFP_KERNEL);
  1916. if (!ha->init_cb)
  1917. goto fail;
  1918. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
  1919. &ha->gid_list_dma, GFP_KERNEL);
  1920. if (!ha->gid_list)
  1921. goto fail_free_init_cb;
  1922. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  1923. if (!ha->srb_mempool)
  1924. goto fail_free_gid_list;
  1925. /* Get memory for cached NVRAM */
  1926. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  1927. if (!ha->nvram)
  1928. goto fail_free_srb_mempool;
  1929. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  1930. ha->pdev->device);
  1931. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  1932. DMA_POOL_SIZE, 8, 0);
  1933. if (!ha->s_dma_pool)
  1934. goto fail_free_nvram;
  1935. /* Allocate memory for SNS commands */
  1936. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1937. /* Get consistent memory allocated for SNS commands */
  1938. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  1939. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  1940. if (!ha->sns_cmd)
  1941. goto fail_dma_pool;
  1942. } else {
  1943. /* Get consistent memory allocated for MS IOCB */
  1944. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1945. &ha->ms_iocb_dma);
  1946. if (!ha->ms_iocb)
  1947. goto fail_dma_pool;
  1948. /* Get consistent memory allocated for CT SNS commands */
  1949. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  1950. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  1951. if (!ha->ct_sns)
  1952. goto fail_free_ms_iocb;
  1953. }
  1954. /* Allocate memory for request ring */
  1955. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  1956. if (!*req) {
  1957. DEBUG(printk("Unable to allocate memory for req\n"));
  1958. goto fail_req;
  1959. }
  1960. (*req)->length = req_len;
  1961. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  1962. ((*req)->length + 1) * sizeof(request_t),
  1963. &(*req)->dma, GFP_KERNEL);
  1964. if (!(*req)->ring) {
  1965. DEBUG(printk("Unable to allocate memory for req_ring\n"));
  1966. goto fail_req_ring;
  1967. }
  1968. /* Allocate memory for response ring */
  1969. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  1970. if (!*rsp) {
  1971. qla_printk(KERN_WARNING, ha,
  1972. "Unable to allocate memory for rsp\n");
  1973. goto fail_rsp;
  1974. }
  1975. (*rsp)->hw = ha;
  1976. (*rsp)->length = rsp_len;
  1977. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  1978. ((*rsp)->length + 1) * sizeof(response_t),
  1979. &(*rsp)->dma, GFP_KERNEL);
  1980. if (!(*rsp)->ring) {
  1981. qla_printk(KERN_WARNING, ha,
  1982. "Unable to allocate memory for rsp_ring\n");
  1983. goto fail_rsp_ring;
  1984. }
  1985. (*req)->rsp = *rsp;
  1986. (*rsp)->req = *req;
  1987. /* Allocate memory for NVRAM data for vports */
  1988. if (ha->nvram_npiv_size) {
  1989. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  1990. ha->nvram_npiv_size, GFP_KERNEL);
  1991. if (!ha->npiv_info) {
  1992. qla_printk(KERN_WARNING, ha,
  1993. "Unable to allocate memory for npiv info\n");
  1994. goto fail_npiv_info;
  1995. }
  1996. } else
  1997. ha->npiv_info = NULL;
  1998. INIT_LIST_HEAD(&ha->vp_list);
  1999. return 1;
  2000. fail_npiv_info:
  2001. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  2002. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  2003. (*rsp)->ring = NULL;
  2004. (*rsp)->dma = 0;
  2005. fail_rsp_ring:
  2006. kfree(*rsp);
  2007. fail_rsp:
  2008. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  2009. sizeof(request_t), (*req)->ring, (*req)->dma);
  2010. (*req)->ring = NULL;
  2011. (*req)->dma = 0;
  2012. fail_req_ring:
  2013. kfree(*req);
  2014. fail_req:
  2015. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2016. ha->ct_sns, ha->ct_sns_dma);
  2017. ha->ct_sns = NULL;
  2018. ha->ct_sns_dma = 0;
  2019. fail_free_ms_iocb:
  2020. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2021. ha->ms_iocb = NULL;
  2022. ha->ms_iocb_dma = 0;
  2023. fail_dma_pool:
  2024. dma_pool_destroy(ha->s_dma_pool);
  2025. ha->s_dma_pool = NULL;
  2026. fail_free_nvram:
  2027. kfree(ha->nvram);
  2028. ha->nvram = NULL;
  2029. fail_free_srb_mempool:
  2030. mempool_destroy(ha->srb_mempool);
  2031. ha->srb_mempool = NULL;
  2032. fail_free_gid_list:
  2033. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2034. ha->gid_list_dma);
  2035. ha->gid_list = NULL;
  2036. ha->gid_list_dma = 0;
  2037. fail_free_init_cb:
  2038. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  2039. ha->init_cb_dma);
  2040. ha->init_cb = NULL;
  2041. ha->init_cb_dma = 0;
  2042. fail:
  2043. DEBUG(printk("%s: Memory allocation failure\n", __func__));
  2044. return -ENOMEM;
  2045. }
  2046. /*
  2047. * qla2x00_mem_free
  2048. * Frees all adapter allocated memory.
  2049. *
  2050. * Input:
  2051. * ha = adapter block pointer.
  2052. */
  2053. static void
  2054. qla2x00_mem_free(struct qla_hw_data *ha)
  2055. {
  2056. if (ha->srb_mempool)
  2057. mempool_destroy(ha->srb_mempool);
  2058. if (ha->fce)
  2059. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  2060. ha->fce_dma);
  2061. if (ha->fw_dump) {
  2062. if (ha->eft)
  2063. dma_free_coherent(&ha->pdev->dev,
  2064. ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
  2065. vfree(ha->fw_dump);
  2066. }
  2067. if (ha->sns_cmd)
  2068. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  2069. ha->sns_cmd, ha->sns_cmd_dma);
  2070. if (ha->ct_sns)
  2071. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2072. ha->ct_sns, ha->ct_sns_dma);
  2073. if (ha->sfp_data)
  2074. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  2075. if (ha->ms_iocb)
  2076. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2077. if (ha->s_dma_pool)
  2078. dma_pool_destroy(ha->s_dma_pool);
  2079. if (ha->gid_list)
  2080. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2081. ha->gid_list_dma);
  2082. if (ha->init_cb)
  2083. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  2084. ha->init_cb, ha->init_cb_dma);
  2085. vfree(ha->optrom_buffer);
  2086. kfree(ha->nvram);
  2087. kfree(ha->npiv_info);
  2088. ha->srb_mempool = NULL;
  2089. ha->eft = NULL;
  2090. ha->eft_dma = 0;
  2091. ha->sns_cmd = NULL;
  2092. ha->sns_cmd_dma = 0;
  2093. ha->ct_sns = NULL;
  2094. ha->ct_sns_dma = 0;
  2095. ha->ms_iocb = NULL;
  2096. ha->ms_iocb_dma = 0;
  2097. ha->init_cb = NULL;
  2098. ha->init_cb_dma = 0;
  2099. ha->s_dma_pool = NULL;
  2100. ha->gid_list = NULL;
  2101. ha->gid_list_dma = 0;
  2102. ha->fw_dump = NULL;
  2103. ha->fw_dumped = 0;
  2104. ha->fw_dump_reading = 0;
  2105. }
  2106. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  2107. struct qla_hw_data *ha)
  2108. {
  2109. struct Scsi_Host *host;
  2110. struct scsi_qla_host *vha = NULL;
  2111. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  2112. if (host == NULL) {
  2113. printk(KERN_WARNING
  2114. "qla2xxx: Couldn't allocate host from scsi layer!\n");
  2115. goto fail;
  2116. }
  2117. /* Clear our data area */
  2118. vha = shost_priv(host);
  2119. memset(vha, 0, sizeof(scsi_qla_host_t));
  2120. vha->host = host;
  2121. vha->host_no = host->host_no;
  2122. vha->hw = ha;
  2123. INIT_LIST_HEAD(&vha->vp_fcports);
  2124. INIT_LIST_HEAD(&vha->work_list);
  2125. INIT_LIST_HEAD(&vha->list);
  2126. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  2127. return vha;
  2128. fail:
  2129. return vha;
  2130. }
  2131. static struct qla_work_evt *
  2132. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type,
  2133. int locked)
  2134. {
  2135. struct qla_work_evt *e;
  2136. e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
  2137. GFP_KERNEL);
  2138. if (!e)
  2139. return NULL;
  2140. INIT_LIST_HEAD(&e->list);
  2141. e->type = type;
  2142. e->flags = QLA_EVT_FLAG_FREE;
  2143. return e;
  2144. }
  2145. static int
  2146. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked)
  2147. {
  2148. unsigned long uninitialized_var(flags);
  2149. struct qla_hw_data *ha = vha->hw;
  2150. if (!locked)
  2151. spin_lock_irqsave(&ha->hardware_lock, flags);
  2152. list_add_tail(&e->list, &vha->work_list);
  2153. qla2xxx_wake_dpc(vha);
  2154. if (!locked)
  2155. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2156. return QLA_SUCCESS;
  2157. }
  2158. int
  2159. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  2160. u32 data)
  2161. {
  2162. struct qla_work_evt *e;
  2163. e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1);
  2164. if (!e)
  2165. return QLA_FUNCTION_FAILED;
  2166. e->u.aen.code = code;
  2167. e->u.aen.data = data;
  2168. return qla2x00_post_work(vha, e, 1);
  2169. }
  2170. int
  2171. qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
  2172. {
  2173. struct qla_work_evt *e;
  2174. e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK, 1);
  2175. if (!e)
  2176. return QLA_FUNCTION_FAILED;
  2177. memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
  2178. return qla2x00_post_work(vha, e, 1);
  2179. }
  2180. static void
  2181. qla2x00_do_work(struct scsi_qla_host *vha)
  2182. {
  2183. struct qla_work_evt *e;
  2184. struct qla_hw_data *ha = vha->hw;
  2185. spin_lock_irq(&ha->hardware_lock);
  2186. while (!list_empty(&vha->work_list)) {
  2187. e = list_entry(vha->work_list.next, struct qla_work_evt, list);
  2188. list_del_init(&e->list);
  2189. spin_unlock_irq(&ha->hardware_lock);
  2190. switch (e->type) {
  2191. case QLA_EVT_AEN:
  2192. fc_host_post_event(vha->host, fc_get_event_number(),
  2193. e->u.aen.code, e->u.aen.data);
  2194. break;
  2195. case QLA_EVT_IDC_ACK:
  2196. qla81xx_idc_ack(vha, e->u.idc_ack.mb);
  2197. break;
  2198. }
  2199. if (e->flags & QLA_EVT_FLAG_FREE)
  2200. kfree(e);
  2201. spin_lock_irq(&ha->hardware_lock);
  2202. }
  2203. spin_unlock_irq(&ha->hardware_lock);
  2204. }
  2205. /* Relogins all the fcports of a vport
  2206. * Context: dpc thread
  2207. */
  2208. void qla2x00_relogin(struct scsi_qla_host *vha)
  2209. {
  2210. fc_port_t *fcport;
  2211. int status;
  2212. uint16_t next_loopid = 0;
  2213. struct qla_hw_data *ha = vha->hw;
  2214. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2215. /*
  2216. * If the port is not ONLINE then try to login
  2217. * to it if we haven't run out of retries.
  2218. */
  2219. if (atomic_read(&fcport->state) !=
  2220. FCS_ONLINE && fcport->login_retry) {
  2221. if (fcport->flags & FCF_FABRIC_DEVICE) {
  2222. if (fcport->flags & FCF_TAPE_PRESENT)
  2223. ha->isp_ops->fabric_logout(vha,
  2224. fcport->loop_id,
  2225. fcport->d_id.b.domain,
  2226. fcport->d_id.b.area,
  2227. fcport->d_id.b.al_pa);
  2228. status = qla2x00_fabric_login(vha, fcport,
  2229. &next_loopid);
  2230. } else
  2231. status = qla2x00_local_device_login(vha,
  2232. fcport);
  2233. fcport->login_retry--;
  2234. if (status == QLA_SUCCESS) {
  2235. fcport->old_loop_id = fcport->loop_id;
  2236. DEBUG(printk("scsi(%ld): port login OK: logged "
  2237. "in ID 0x%x\n", vha->host_no, fcport->loop_id));
  2238. qla2x00_update_fcport(vha, fcport);
  2239. } else if (status == 1) {
  2240. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2241. /* retry the login again */
  2242. DEBUG(printk("scsi(%ld): Retrying"
  2243. " %d login again loop_id 0x%x\n",
  2244. vha->host_no, fcport->login_retry,
  2245. fcport->loop_id));
  2246. } else {
  2247. fcport->login_retry = 0;
  2248. }
  2249. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  2250. fcport->loop_id = FC_NO_LOOP_ID;
  2251. }
  2252. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2253. break;
  2254. }
  2255. }
  2256. /**************************************************************************
  2257. * qla2x00_do_dpc
  2258. * This kernel thread is a task that is schedule by the interrupt handler
  2259. * to perform the background processing for interrupts.
  2260. *
  2261. * Notes:
  2262. * This task always run in the context of a kernel thread. It
  2263. * is kick-off by the driver's detect code and starts up
  2264. * up one per adapter. It immediately goes to sleep and waits for
  2265. * some fibre event. When either the interrupt handler or
  2266. * the timer routine detects a event it will one of the task
  2267. * bits then wake us up.
  2268. **************************************************************************/
  2269. static int
  2270. qla2x00_do_dpc(void *data)
  2271. {
  2272. int rval;
  2273. scsi_qla_host_t *base_vha;
  2274. struct qla_hw_data *ha;
  2275. ha = (struct qla_hw_data *)data;
  2276. base_vha = pci_get_drvdata(ha->pdev);
  2277. set_user_nice(current, -20);
  2278. while (!kthread_should_stop()) {
  2279. DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
  2280. set_current_state(TASK_INTERRUPTIBLE);
  2281. schedule();
  2282. __set_current_state(TASK_RUNNING);
  2283. DEBUG3(printk("qla2x00: DPC handler waking up\n"));
  2284. /* Initialization not yet finished. Don't do anything yet. */
  2285. if (!base_vha->flags.init_done)
  2286. continue;
  2287. DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
  2288. ha->dpc_active = 1;
  2289. if (ha->flags.mbox_busy) {
  2290. ha->dpc_active = 0;
  2291. continue;
  2292. }
  2293. qla2x00_do_work(base_vha);
  2294. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  2295. &base_vha->dpc_flags)) {
  2296. DEBUG(printk("scsi(%ld): dpc: sched "
  2297. "qla2x00_abort_isp ha = %p\n",
  2298. base_vha->host_no, ha));
  2299. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  2300. &base_vha->dpc_flags))) {
  2301. if (qla2x00_abort_isp(base_vha)) {
  2302. /* failed. retry later */
  2303. set_bit(ISP_ABORT_NEEDED,
  2304. &base_vha->dpc_flags);
  2305. }
  2306. clear_bit(ABORT_ISP_ACTIVE,
  2307. &base_vha->dpc_flags);
  2308. }
  2309. DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
  2310. base_vha->host_no));
  2311. }
  2312. if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
  2313. qla2x00_update_fcports(base_vha);
  2314. clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  2315. }
  2316. if (test_and_clear_bit(RESET_MARKER_NEEDED,
  2317. &base_vha->dpc_flags) &&
  2318. (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
  2319. DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
  2320. base_vha->host_no));
  2321. qla2x00_rst_aen(base_vha);
  2322. clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
  2323. }
  2324. /* Retry each device up to login retry count */
  2325. if ((test_and_clear_bit(RELOGIN_NEEDED,
  2326. &base_vha->dpc_flags)) &&
  2327. !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
  2328. atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
  2329. DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
  2330. base_vha->host_no));
  2331. qla2x00_relogin(base_vha);
  2332. DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
  2333. base_vha->host_no));
  2334. }
  2335. if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
  2336. &base_vha->dpc_flags)) {
  2337. DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
  2338. base_vha->host_no));
  2339. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  2340. &base_vha->dpc_flags))) {
  2341. rval = qla2x00_loop_resync(base_vha);
  2342. clear_bit(LOOP_RESYNC_ACTIVE,
  2343. &base_vha->dpc_flags);
  2344. }
  2345. DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
  2346. base_vha->host_no));
  2347. }
  2348. if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
  2349. atomic_read(&base_vha->loop_state) == LOOP_READY) {
  2350. clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
  2351. qla2xxx_flash_npiv_conf(base_vha);
  2352. }
  2353. if (!ha->interrupts_on)
  2354. ha->isp_ops->enable_intrs(ha);
  2355. if (test_and_clear_bit(BEACON_BLINK_NEEDED,
  2356. &base_vha->dpc_flags))
  2357. ha->isp_ops->beacon_blink(base_vha);
  2358. qla2x00_do_dpc_all_vps(base_vha);
  2359. ha->dpc_active = 0;
  2360. } /* End of while(1) */
  2361. DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
  2362. /*
  2363. * Make sure that nobody tries to wake us up again.
  2364. */
  2365. ha->dpc_active = 0;
  2366. return 0;
  2367. }
  2368. void
  2369. qla2xxx_wake_dpc(struct scsi_qla_host *vha)
  2370. {
  2371. struct qla_hw_data *ha = vha->hw;
  2372. struct task_struct *t = ha->dpc_thread;
  2373. if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
  2374. wake_up_process(t);
  2375. }
  2376. /*
  2377. * qla2x00_rst_aen
  2378. * Processes asynchronous reset.
  2379. *
  2380. * Input:
  2381. * ha = adapter block pointer.
  2382. */
  2383. static void
  2384. qla2x00_rst_aen(scsi_qla_host_t *vha)
  2385. {
  2386. if (vha->flags.online && !vha->flags.reset_active &&
  2387. !atomic_read(&vha->loop_down_timer) &&
  2388. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
  2389. do {
  2390. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  2391. /*
  2392. * Issue marker command only when we are going to start
  2393. * the I/O.
  2394. */
  2395. vha->marker_needed = 1;
  2396. } while (!atomic_read(&vha->loop_down_timer) &&
  2397. (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
  2398. }
  2399. }
  2400. static void
  2401. qla2x00_sp_free_dma(srb_t *sp)
  2402. {
  2403. struct scsi_cmnd *cmd = sp->cmd;
  2404. if (sp->flags & SRB_DMA_VALID) {
  2405. scsi_dma_unmap(cmd);
  2406. sp->flags &= ~SRB_DMA_VALID;
  2407. }
  2408. CMD_SP(cmd) = NULL;
  2409. }
  2410. void
  2411. qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
  2412. {
  2413. struct scsi_cmnd *cmd = sp->cmd;
  2414. qla2x00_sp_free_dma(sp);
  2415. mempool_free(sp, ha->srb_mempool);
  2416. cmd->scsi_done(cmd);
  2417. }
  2418. /**************************************************************************
  2419. * qla2x00_timer
  2420. *
  2421. * Description:
  2422. * One second timer
  2423. *
  2424. * Context: Interrupt
  2425. ***************************************************************************/
  2426. void
  2427. qla2x00_timer(scsi_qla_host_t *vha)
  2428. {
  2429. unsigned long cpu_flags = 0;
  2430. fc_port_t *fcport;
  2431. int start_dpc = 0;
  2432. int index;
  2433. srb_t *sp;
  2434. int t;
  2435. struct qla_hw_data *ha = vha->hw;
  2436. struct req_que *req;
  2437. /*
  2438. * Ports - Port down timer.
  2439. *
  2440. * Whenever, a port is in the LOST state we start decrementing its port
  2441. * down timer every second until it reaches zero. Once it reaches zero
  2442. * the port it marked DEAD.
  2443. */
  2444. t = 0;
  2445. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2446. if (fcport->port_type != FCT_TARGET)
  2447. continue;
  2448. if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  2449. if (atomic_read(&fcport->port_down_timer) == 0)
  2450. continue;
  2451. if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
  2452. atomic_set(&fcport->state, FCS_DEVICE_DEAD);
  2453. DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
  2454. "%d remaining\n",
  2455. vha->host_no,
  2456. t, atomic_read(&fcport->port_down_timer)));
  2457. }
  2458. t++;
  2459. } /* End of for fcport */
  2460. /* Loop down handler. */
  2461. if (atomic_read(&vha->loop_down_timer) > 0 &&
  2462. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
  2463. && vha->flags.online) {
  2464. if (atomic_read(&vha->loop_down_timer) ==
  2465. vha->loop_down_abort_time) {
  2466. DEBUG(printk("scsi(%ld): Loop Down - aborting the "
  2467. "queues before time expire\n",
  2468. vha->host_no));
  2469. if (!IS_QLA2100(ha) && vha->link_down_timeout)
  2470. atomic_set(&vha->loop_state, LOOP_DEAD);
  2471. /* Schedule an ISP abort to return any tape commands. */
  2472. /* NPIV - scan physical port only */
  2473. if (!vha->vp_idx) {
  2474. spin_lock_irqsave(&ha->hardware_lock,
  2475. cpu_flags);
  2476. req = ha->req_q_map[0];
  2477. for (index = 1;
  2478. index < MAX_OUTSTANDING_COMMANDS;
  2479. index++) {
  2480. fc_port_t *sfcp;
  2481. sp = req->outstanding_cmds[index];
  2482. if (!sp)
  2483. continue;
  2484. sfcp = sp->fcport;
  2485. if (!(sfcp->flags & FCF_TAPE_PRESENT))
  2486. continue;
  2487. set_bit(ISP_ABORT_NEEDED,
  2488. &vha->dpc_flags);
  2489. break;
  2490. }
  2491. spin_unlock_irqrestore(&ha->hardware_lock,
  2492. cpu_flags);
  2493. }
  2494. set_bit(ABORT_QUEUES_NEEDED, &vha->dpc_flags);
  2495. start_dpc++;
  2496. }
  2497. /* if the loop has been down for 4 minutes, reinit adapter */
  2498. if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
  2499. DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
  2500. "restarting queues.\n",
  2501. vha->host_no));
  2502. set_bit(RESTART_QUEUES_NEEDED, &vha->dpc_flags);
  2503. start_dpc++;
  2504. if (!(vha->device_flags & DFLG_NO_CABLE) &&
  2505. !vha->vp_idx) {
  2506. DEBUG(printk("scsi(%ld): Loop down - "
  2507. "aborting ISP.\n",
  2508. vha->host_no));
  2509. qla_printk(KERN_WARNING, ha,
  2510. "Loop down - aborting ISP.\n");
  2511. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  2512. }
  2513. }
  2514. DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
  2515. vha->host_no,
  2516. atomic_read(&vha->loop_down_timer)));
  2517. }
  2518. /* Check if beacon LED needs to be blinked */
  2519. if (ha->beacon_blink_led == 1) {
  2520. set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
  2521. start_dpc++;
  2522. }
  2523. /* Process any deferred work. */
  2524. if (!list_empty(&vha->work_list))
  2525. start_dpc++;
  2526. /* Schedule the DPC routine if needed */
  2527. if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  2528. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
  2529. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
  2530. start_dpc ||
  2531. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
  2532. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
  2533. test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
  2534. test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
  2535. qla2xxx_wake_dpc(vha);
  2536. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  2537. }
  2538. /* Firmware interface routines. */
  2539. #define FW_BLOBS 7
  2540. #define FW_ISP21XX 0
  2541. #define FW_ISP22XX 1
  2542. #define FW_ISP2300 2
  2543. #define FW_ISP2322 3
  2544. #define FW_ISP24XX 4
  2545. #define FW_ISP25XX 5
  2546. #define FW_ISP81XX 6
  2547. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  2548. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  2549. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  2550. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  2551. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  2552. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  2553. #define FW_FILE_ISP81XX "ql8100_fw.bin"
  2554. static DEFINE_MUTEX(qla_fw_lock);
  2555. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  2556. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  2557. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  2558. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  2559. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  2560. { .name = FW_FILE_ISP24XX, },
  2561. { .name = FW_FILE_ISP25XX, },
  2562. { .name = FW_FILE_ISP81XX, },
  2563. };
  2564. struct fw_blob *
  2565. qla2x00_request_firmware(scsi_qla_host_t *vha)
  2566. {
  2567. struct qla_hw_data *ha = vha->hw;
  2568. struct fw_blob *blob;
  2569. blob = NULL;
  2570. if (IS_QLA2100(ha)) {
  2571. blob = &qla_fw_blobs[FW_ISP21XX];
  2572. } else if (IS_QLA2200(ha)) {
  2573. blob = &qla_fw_blobs[FW_ISP22XX];
  2574. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  2575. blob = &qla_fw_blobs[FW_ISP2300];
  2576. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  2577. blob = &qla_fw_blobs[FW_ISP2322];
  2578. } else if (IS_QLA24XX_TYPE(ha)) {
  2579. blob = &qla_fw_blobs[FW_ISP24XX];
  2580. } else if (IS_QLA25XX(ha)) {
  2581. blob = &qla_fw_blobs[FW_ISP25XX];
  2582. } else if (IS_QLA81XX(ha)) {
  2583. blob = &qla_fw_blobs[FW_ISP81XX];
  2584. }
  2585. mutex_lock(&qla_fw_lock);
  2586. if (blob->fw)
  2587. goto out;
  2588. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  2589. DEBUG2(printk("scsi(%ld): Failed to load firmware image "
  2590. "(%s).\n", vha->host_no, blob->name));
  2591. blob->fw = NULL;
  2592. blob = NULL;
  2593. goto out;
  2594. }
  2595. out:
  2596. mutex_unlock(&qla_fw_lock);
  2597. return blob;
  2598. }
  2599. static void
  2600. qla2x00_release_firmware(void)
  2601. {
  2602. int idx;
  2603. mutex_lock(&qla_fw_lock);
  2604. for (idx = 0; idx < FW_BLOBS; idx++)
  2605. if (qla_fw_blobs[idx].fw)
  2606. release_firmware(qla_fw_blobs[idx].fw);
  2607. mutex_unlock(&qla_fw_lock);
  2608. }
  2609. static pci_ers_result_t
  2610. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  2611. {
  2612. switch (state) {
  2613. case pci_channel_io_normal:
  2614. return PCI_ERS_RESULT_CAN_RECOVER;
  2615. case pci_channel_io_frozen:
  2616. pci_disable_device(pdev);
  2617. return PCI_ERS_RESULT_NEED_RESET;
  2618. case pci_channel_io_perm_failure:
  2619. qla2x00_remove_one(pdev);
  2620. return PCI_ERS_RESULT_DISCONNECT;
  2621. }
  2622. return PCI_ERS_RESULT_NEED_RESET;
  2623. }
  2624. static pci_ers_result_t
  2625. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  2626. {
  2627. int risc_paused = 0;
  2628. uint32_t stat;
  2629. unsigned long flags;
  2630. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  2631. struct qla_hw_data *ha = base_vha->hw;
  2632. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2633. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  2634. spin_lock_irqsave(&ha->hardware_lock, flags);
  2635. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  2636. stat = RD_REG_DWORD(&reg->hccr);
  2637. if (stat & HCCR_RISC_PAUSE)
  2638. risc_paused = 1;
  2639. } else if (IS_QLA23XX(ha)) {
  2640. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  2641. if (stat & HSR_RISC_PAUSED)
  2642. risc_paused = 1;
  2643. } else if (IS_FWI2_CAPABLE(ha)) {
  2644. stat = RD_REG_DWORD(&reg24->host_status);
  2645. if (stat & HSRX_RISC_PAUSED)
  2646. risc_paused = 1;
  2647. }
  2648. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2649. if (risc_paused) {
  2650. qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
  2651. "Dumping firmware!\n");
  2652. ha->isp_ops->fw_dump(base_vha, 0);
  2653. return PCI_ERS_RESULT_NEED_RESET;
  2654. } else
  2655. return PCI_ERS_RESULT_RECOVERED;
  2656. }
  2657. static pci_ers_result_t
  2658. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  2659. {
  2660. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  2661. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  2662. struct qla_hw_data *ha = base_vha->hw;
  2663. int rc;
  2664. if (ha->mem_only)
  2665. rc = pci_enable_device_mem(pdev);
  2666. else
  2667. rc = pci_enable_device(pdev);
  2668. if (rc) {
  2669. qla_printk(KERN_WARNING, ha,
  2670. "Can't re-enable PCI device after reset.\n");
  2671. return ret;
  2672. }
  2673. pci_set_master(pdev);
  2674. if (ha->isp_ops->pci_config(base_vha))
  2675. return ret;
  2676. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  2677. if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
  2678. ret = PCI_ERS_RESULT_RECOVERED;
  2679. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  2680. return ret;
  2681. }
  2682. static void
  2683. qla2xxx_pci_resume(struct pci_dev *pdev)
  2684. {
  2685. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  2686. struct qla_hw_data *ha = base_vha->hw;
  2687. int ret;
  2688. ret = qla2x00_wait_for_hba_online(base_vha);
  2689. if (ret != QLA_SUCCESS) {
  2690. qla_printk(KERN_ERR, ha,
  2691. "the device failed to resume I/O "
  2692. "from slot/link_reset");
  2693. }
  2694. pci_cleanup_aer_uncorrect_error_status(pdev);
  2695. }
  2696. static struct pci_error_handlers qla2xxx_err_handler = {
  2697. .error_detected = qla2xxx_pci_error_detected,
  2698. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  2699. .slot_reset = qla2xxx_pci_slot_reset,
  2700. .resume = qla2xxx_pci_resume,
  2701. };
  2702. static struct pci_device_id qla2xxx_pci_tbl[] = {
  2703. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  2704. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  2705. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  2706. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  2707. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  2708. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  2709. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  2710. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  2711. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  2712. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  2713. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  2714. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  2715. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  2716. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
  2717. { 0 },
  2718. };
  2719. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  2720. static struct pci_driver qla2xxx_pci_driver = {
  2721. .name = QLA2XXX_DRIVER_NAME,
  2722. .driver = {
  2723. .owner = THIS_MODULE,
  2724. },
  2725. .id_table = qla2xxx_pci_tbl,
  2726. .probe = qla2x00_probe_one,
  2727. .remove = qla2x00_remove_one,
  2728. .err_handler = &qla2xxx_err_handler,
  2729. };
  2730. /**
  2731. * qla2x00_module_init - Module initialization.
  2732. **/
  2733. static int __init
  2734. qla2x00_module_init(void)
  2735. {
  2736. int ret = 0;
  2737. /* Allocate cache for SRBs. */
  2738. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  2739. SLAB_HWCACHE_ALIGN, NULL);
  2740. if (srb_cachep == NULL) {
  2741. printk(KERN_ERR
  2742. "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
  2743. return -ENOMEM;
  2744. }
  2745. /* Derive version string. */
  2746. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  2747. if (ql2xextended_error_logging)
  2748. strcat(qla2x00_version_str, "-debug");
  2749. qla2xxx_transport_template =
  2750. fc_attach_transport(&qla2xxx_transport_functions);
  2751. if (!qla2xxx_transport_template) {
  2752. kmem_cache_destroy(srb_cachep);
  2753. return -ENODEV;
  2754. }
  2755. qla2xxx_transport_vport_template =
  2756. fc_attach_transport(&qla2xxx_transport_vport_functions);
  2757. if (!qla2xxx_transport_vport_template) {
  2758. kmem_cache_destroy(srb_cachep);
  2759. fc_release_transport(qla2xxx_transport_template);
  2760. return -ENODEV;
  2761. }
  2762. printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
  2763. qla2x00_version_str);
  2764. ret = pci_register_driver(&qla2xxx_pci_driver);
  2765. if (ret) {
  2766. kmem_cache_destroy(srb_cachep);
  2767. fc_release_transport(qla2xxx_transport_template);
  2768. fc_release_transport(qla2xxx_transport_vport_template);
  2769. }
  2770. return ret;
  2771. }
  2772. /**
  2773. * qla2x00_module_exit - Module cleanup.
  2774. **/
  2775. static void __exit
  2776. qla2x00_module_exit(void)
  2777. {
  2778. pci_unregister_driver(&qla2xxx_pci_driver);
  2779. qla2x00_release_firmware();
  2780. kmem_cache_destroy(srb_cachep);
  2781. fc_release_transport(qla2xxx_transport_template);
  2782. fc_release_transport(qla2xxx_transport_vport_template);
  2783. }
  2784. module_init(qla2x00_module_init);
  2785. module_exit(qla2x00_module_exit);
  2786. MODULE_AUTHOR("QLogic Corporation");
  2787. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  2788. MODULE_LICENSE("GPL");
  2789. MODULE_VERSION(QLA2XXX_VERSION);
  2790. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  2791. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  2792. MODULE_FIRMWARE(FW_FILE_ISP2300);
  2793. MODULE_FIRMWARE(FW_FILE_ISP2322);
  2794. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  2795. MODULE_FIRMWARE(FW_FILE_ISP25XX);
  2796. MODULE_FIRMWARE(FW_FILE_ISP81XX);