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. static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
  57. int ql2xfdmienable=1;
  58. module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
  59. MODULE_PARM_DESC(ql2xfdmienable,
  60. "Enables FDMI registratons "
  61. "Default is 0 - no FDMI. 1 - perfom FDMI.");
  62. #define MAX_Q_DEPTH 32
  63. static int ql2xmaxqdepth = MAX_Q_DEPTH;
  64. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  65. MODULE_PARM_DESC(ql2xmaxqdepth,
  66. "Maximum queue depth to report for target devices.");
  67. int ql2xqfullrampup = 120;
  68. module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
  69. MODULE_PARM_DESC(ql2xqfullrampup,
  70. "Number of seconds to wait to begin to ramp-up the queue "
  71. "depth for a device after a queue-full condition has been "
  72. "detected. Default is 120 seconds.");
  73. int ql2xiidmaenable=1;
  74. module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
  75. MODULE_PARM_DESC(ql2xiidmaenable,
  76. "Enables iIDMA settings "
  77. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  78. int ql2xmaxqueues = 1;
  79. module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
  80. MODULE_PARM_DESC(ql2xmaxqueues,
  81. "Enables MQ settings "
  82. "Default is 1 for single queue. Set it to number \
  83. of queues in MQ mode.");
  84. /*
  85. * SCSI host template entry points
  86. */
  87. static int qla2xxx_slave_configure(struct scsi_device * device);
  88. static int qla2xxx_slave_alloc(struct scsi_device *);
  89. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  90. static void qla2xxx_scan_start(struct Scsi_Host *);
  91. static void qla2xxx_slave_destroy(struct scsi_device *);
  92. static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
  93. void (*fn)(struct scsi_cmnd *));
  94. static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
  95. void (*fn)(struct scsi_cmnd *));
  96. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  97. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  98. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  99. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  100. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  101. static int qla2x00_change_queue_depth(struct scsi_device *, int);
  102. static int qla2x00_change_queue_type(struct scsi_device *, int);
  103. static struct scsi_host_template qla2x00_driver_template = {
  104. .module = THIS_MODULE,
  105. .name = QLA2XXX_DRIVER_NAME,
  106. .queuecommand = qla2x00_queuecommand,
  107. .eh_abort_handler = qla2xxx_eh_abort,
  108. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  109. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  110. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  111. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  112. .slave_configure = qla2xxx_slave_configure,
  113. .slave_alloc = qla2xxx_slave_alloc,
  114. .slave_destroy = qla2xxx_slave_destroy,
  115. .scan_finished = qla2xxx_scan_finished,
  116. .scan_start = qla2xxx_scan_start,
  117. .change_queue_depth = qla2x00_change_queue_depth,
  118. .change_queue_type = qla2x00_change_queue_type,
  119. .this_id = -1,
  120. .cmd_per_lun = 3,
  121. .use_clustering = ENABLE_CLUSTERING,
  122. .sg_tablesize = SG_ALL,
  123. /*
  124. * The RISC allows for each command to transfer (2^32-1) bytes of data,
  125. * which equates to 0x800000 sectors.
  126. */
  127. .max_sectors = 0xFFFF,
  128. .shost_attrs = qla2x00_host_attrs,
  129. };
  130. struct scsi_host_template qla24xx_driver_template = {
  131. .module = THIS_MODULE,
  132. .name = QLA2XXX_DRIVER_NAME,
  133. .queuecommand = qla24xx_queuecommand,
  134. .eh_abort_handler = qla2xxx_eh_abort,
  135. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  136. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  137. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  138. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  139. .slave_configure = qla2xxx_slave_configure,
  140. .slave_alloc = qla2xxx_slave_alloc,
  141. .slave_destroy = qla2xxx_slave_destroy,
  142. .scan_finished = qla2xxx_scan_finished,
  143. .scan_start = qla2xxx_scan_start,
  144. .change_queue_depth = qla2x00_change_queue_depth,
  145. .change_queue_type = qla2x00_change_queue_type,
  146. .this_id = -1,
  147. .cmd_per_lun = 3,
  148. .use_clustering = ENABLE_CLUSTERING,
  149. .sg_tablesize = SG_ALL,
  150. .max_sectors = 0xFFFF,
  151. .shost_attrs = qla2x00_host_attrs,
  152. };
  153. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  154. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  155. /* TODO Convert to inlines
  156. *
  157. * Timer routines
  158. */
  159. __inline__ void
  160. qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
  161. {
  162. init_timer(&vha->timer);
  163. vha->timer.expires = jiffies + interval * HZ;
  164. vha->timer.data = (unsigned long)vha;
  165. vha->timer.function = (void (*)(unsigned long))func;
  166. add_timer(&vha->timer);
  167. vha->timer_active = 1;
  168. }
  169. static inline void
  170. qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
  171. {
  172. mod_timer(&vha->timer, jiffies + interval * HZ);
  173. }
  174. static __inline__ void
  175. qla2x00_stop_timer(scsi_qla_host_t *vha)
  176. {
  177. del_timer_sync(&vha->timer);
  178. vha->timer_active = 0;
  179. }
  180. static int qla2x00_do_dpc(void *data);
  181. static void qla2x00_rst_aen(scsi_qla_host_t *);
  182. static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
  183. struct req_que **, struct rsp_que **);
  184. static void qla2x00_mem_free(struct qla_hw_data *);
  185. static void qla2x00_sp_free_dma(srb_t *);
  186. /* -------------------------------------------------------------------------- */
  187. static int qla2x00_alloc_queues(struct qla_hw_data *ha)
  188. {
  189. ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_queues,
  190. GFP_KERNEL);
  191. if (!ha->req_q_map) {
  192. qla_printk(KERN_WARNING, ha,
  193. "Unable to allocate memory for request queue ptrs\n");
  194. goto fail_req_map;
  195. }
  196. ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_queues,
  197. GFP_KERNEL);
  198. if (!ha->rsp_q_map) {
  199. qla_printk(KERN_WARNING, ha,
  200. "Unable to allocate memory for response queue ptrs\n");
  201. goto fail_rsp_map;
  202. }
  203. set_bit(0, ha->rsp_qid_map);
  204. set_bit(0, ha->req_qid_map);
  205. return 1;
  206. fail_rsp_map:
  207. kfree(ha->req_q_map);
  208. ha->req_q_map = NULL;
  209. fail_req_map:
  210. return -ENOMEM;
  211. }
  212. static void qla2x00_free_que(struct qla_hw_data *ha, struct req_que *req,
  213. struct rsp_que *rsp)
  214. {
  215. if (rsp && rsp->ring)
  216. dma_free_coherent(&ha->pdev->dev,
  217. (rsp->length + 1) * sizeof(response_t),
  218. rsp->ring, rsp->dma);
  219. kfree(rsp);
  220. rsp = NULL;
  221. if (req && req->ring)
  222. dma_free_coherent(&ha->pdev->dev,
  223. (req->length + 1) * sizeof(request_t),
  224. req->ring, req->dma);
  225. kfree(req);
  226. req = NULL;
  227. }
  228. static void qla2x00_free_queues(struct qla_hw_data *ha)
  229. {
  230. struct req_que *req;
  231. struct rsp_que *rsp;
  232. int cnt;
  233. for (cnt = 0; cnt < ha->max_queues; cnt++) {
  234. rsp = ha->rsp_q_map[cnt];
  235. req = ha->req_q_map[cnt];
  236. qla2x00_free_que(ha, req, rsp);
  237. }
  238. kfree(ha->rsp_q_map);
  239. ha->rsp_q_map = NULL;
  240. kfree(ha->req_q_map);
  241. ha->req_q_map = NULL;
  242. }
  243. static char *
  244. qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
  245. {
  246. struct qla_hw_data *ha = vha->hw;
  247. static char *pci_bus_modes[] = {
  248. "33", "66", "100", "133",
  249. };
  250. uint16_t pci_bus;
  251. strcpy(str, "PCI");
  252. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  253. if (pci_bus) {
  254. strcat(str, "-X (");
  255. strcat(str, pci_bus_modes[pci_bus]);
  256. } else {
  257. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  258. strcat(str, " (");
  259. strcat(str, pci_bus_modes[pci_bus]);
  260. }
  261. strcat(str, " MHz)");
  262. return (str);
  263. }
  264. static char *
  265. qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
  266. {
  267. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  268. struct qla_hw_data *ha = vha->hw;
  269. uint32_t pci_bus;
  270. int pcie_reg;
  271. pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
  272. if (pcie_reg) {
  273. char lwstr[6];
  274. uint16_t pcie_lstat, lspeed, lwidth;
  275. pcie_reg += 0x12;
  276. pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
  277. lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
  278. lwidth = (pcie_lstat &
  279. (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
  280. strcpy(str, "PCIe (");
  281. if (lspeed == 1)
  282. strcat(str, "2.5GT/s ");
  283. else if (lspeed == 2)
  284. strcat(str, "5.0GT/s ");
  285. else
  286. strcat(str, "<unknown> ");
  287. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  288. strcat(str, lwstr);
  289. return str;
  290. }
  291. strcpy(str, "PCI");
  292. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  293. if (pci_bus == 0 || pci_bus == 8) {
  294. strcat(str, " (");
  295. strcat(str, pci_bus_modes[pci_bus >> 3]);
  296. } else {
  297. strcat(str, "-X ");
  298. if (pci_bus & BIT_2)
  299. strcat(str, "Mode 2");
  300. else
  301. strcat(str, "Mode 1");
  302. strcat(str, " (");
  303. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  304. }
  305. strcat(str, " MHz)");
  306. return str;
  307. }
  308. static char *
  309. qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
  310. {
  311. char un_str[10];
  312. struct qla_hw_data *ha = vha->hw;
  313. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  314. ha->fw_minor_version,
  315. ha->fw_subminor_version);
  316. if (ha->fw_attributes & BIT_9) {
  317. strcat(str, "FLX");
  318. return (str);
  319. }
  320. switch (ha->fw_attributes & 0xFF) {
  321. case 0x7:
  322. strcat(str, "EF");
  323. break;
  324. case 0x17:
  325. strcat(str, "TP");
  326. break;
  327. case 0x37:
  328. strcat(str, "IP");
  329. break;
  330. case 0x77:
  331. strcat(str, "VI");
  332. break;
  333. default:
  334. sprintf(un_str, "(%x)", ha->fw_attributes);
  335. strcat(str, un_str);
  336. break;
  337. }
  338. if (ha->fw_attributes & 0x100)
  339. strcat(str, "X");
  340. return (str);
  341. }
  342. static char *
  343. qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
  344. {
  345. struct qla_hw_data *ha = vha->hw;
  346. sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
  347. ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
  348. return str;
  349. }
  350. static inline srb_t *
  351. qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
  352. struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  353. {
  354. srb_t *sp;
  355. struct qla_hw_data *ha = vha->hw;
  356. sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  357. if (!sp)
  358. return sp;
  359. sp->fcport = fcport;
  360. sp->cmd = cmd;
  361. sp->que = ha->req_q_map[0];
  362. sp->flags = 0;
  363. CMD_SP(cmd) = (void *)sp;
  364. cmd->scsi_done = done;
  365. return sp;
  366. }
  367. static int
  368. qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  369. {
  370. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  371. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  372. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  373. struct qla_hw_data *ha = vha->hw;
  374. srb_t *sp;
  375. int rval;
  376. if (unlikely(pci_channel_offline(ha->pdev))) {
  377. cmd->result = DID_REQUEUE << 16;
  378. goto qc_fail_command;
  379. }
  380. rval = fc_remote_port_chkready(rport);
  381. if (rval) {
  382. cmd->result = rval;
  383. goto qc_fail_command;
  384. }
  385. /* Close window on fcport/rport state-transitioning. */
  386. if (fcport->drport)
  387. goto qc_target_busy;
  388. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  389. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  390. atomic_read(&vha->loop_state) == LOOP_DEAD) {
  391. cmd->result = DID_NO_CONNECT << 16;
  392. goto qc_fail_command;
  393. }
  394. goto qc_target_busy;
  395. }
  396. spin_unlock_irq(vha->host->host_lock);
  397. sp = qla2x00_get_new_sp(vha, fcport, cmd, done);
  398. if (!sp)
  399. goto qc_host_busy_lock;
  400. rval = ha->isp_ops->start_scsi(sp);
  401. if (rval != QLA_SUCCESS)
  402. goto qc_host_busy_free_sp;
  403. spin_lock_irq(vha->host->host_lock);
  404. return 0;
  405. qc_host_busy_free_sp:
  406. qla2x00_sp_free_dma(sp);
  407. mempool_free(sp, ha->srb_mempool);
  408. qc_host_busy_lock:
  409. spin_lock_irq(vha->host->host_lock);
  410. return SCSI_MLQUEUE_HOST_BUSY;
  411. qc_target_busy:
  412. return SCSI_MLQUEUE_TARGET_BUSY;
  413. qc_fail_command:
  414. done(cmd);
  415. return 0;
  416. }
  417. static int
  418. qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  419. {
  420. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  421. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  422. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  423. struct qla_hw_data *ha = vha->hw;
  424. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  425. srb_t *sp;
  426. int rval;
  427. if (unlikely(pci_channel_offline(ha->pdev))) {
  428. cmd->result = DID_REQUEUE << 16;
  429. goto qc24_fail_command;
  430. }
  431. rval = fc_remote_port_chkready(rport);
  432. if (rval) {
  433. cmd->result = rval;
  434. goto qc24_fail_command;
  435. }
  436. /* Close window on fcport/rport state-transitioning. */
  437. if (fcport->drport)
  438. goto qc24_target_busy;
  439. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  440. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  441. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  442. cmd->result = DID_NO_CONNECT << 16;
  443. goto qc24_fail_command;
  444. }
  445. goto qc24_target_busy;
  446. }
  447. spin_unlock_irq(vha->host->host_lock);
  448. sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
  449. if (!sp)
  450. goto qc24_host_busy_lock;
  451. rval = ha->isp_ops->start_scsi(sp);
  452. if (rval != QLA_SUCCESS)
  453. goto qc24_host_busy_free_sp;
  454. spin_lock_irq(vha->host->host_lock);
  455. return 0;
  456. qc24_host_busy_free_sp:
  457. qla2x00_sp_free_dma(sp);
  458. mempool_free(sp, ha->srb_mempool);
  459. qc24_host_busy_lock:
  460. spin_lock_irq(vha->host->host_lock);
  461. return SCSI_MLQUEUE_HOST_BUSY;
  462. qc24_target_busy:
  463. return SCSI_MLQUEUE_TARGET_BUSY;
  464. qc24_fail_command:
  465. done(cmd);
  466. return 0;
  467. }
  468. /*
  469. * qla2x00_eh_wait_on_command
  470. * Waits for the command to be returned by the Firmware for some
  471. * max time.
  472. *
  473. * Input:
  474. * cmd = Scsi Command to wait on.
  475. *
  476. * Return:
  477. * Not Found : 0
  478. * Found : 1
  479. */
  480. static int
  481. qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
  482. {
  483. #define ABORT_POLLING_PERIOD 1000
  484. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  485. unsigned long wait_iter = ABORT_WAIT_ITER;
  486. int ret = QLA_SUCCESS;
  487. while (CMD_SP(cmd)) {
  488. msleep(ABORT_POLLING_PERIOD);
  489. if (--wait_iter)
  490. break;
  491. }
  492. if (CMD_SP(cmd))
  493. ret = QLA_FUNCTION_FAILED;
  494. return ret;
  495. }
  496. /*
  497. * qla2x00_wait_for_hba_online
  498. * Wait till the HBA is online after going through
  499. * <= MAX_RETRIES_OF_ISP_ABORT or
  500. * finally HBA is disabled ie marked offline
  501. *
  502. * Input:
  503. * ha - pointer to host adapter structure
  504. *
  505. * Note:
  506. * Does context switching-Release SPIN_LOCK
  507. * (if any) before calling this routine.
  508. *
  509. * Return:
  510. * Success (Adapter is online) : 0
  511. * Failed (Adapter is offline/disabled) : 1
  512. */
  513. int
  514. qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
  515. {
  516. int return_status;
  517. unsigned long wait_online;
  518. struct qla_hw_data *ha = vha->hw;
  519. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  520. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  521. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  522. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  523. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  524. ha->dpc_active) && time_before(jiffies, wait_online)) {
  525. msleep(1000);
  526. }
  527. if (base_vha->flags.online)
  528. return_status = QLA_SUCCESS;
  529. else
  530. return_status = QLA_FUNCTION_FAILED;
  531. return (return_status);
  532. }
  533. /*
  534. * qla2x00_wait_for_loop_ready
  535. * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
  536. * to be in LOOP_READY state.
  537. * Input:
  538. * ha - pointer to host adapter structure
  539. *
  540. * Note:
  541. * Does context switching-Release SPIN_LOCK
  542. * (if any) before calling this routine.
  543. *
  544. *
  545. * Return:
  546. * Success (LOOP_READY) : 0
  547. * Failed (LOOP_NOT_READY) : 1
  548. */
  549. static inline int
  550. qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
  551. {
  552. int return_status = QLA_SUCCESS;
  553. unsigned long loop_timeout ;
  554. struct qla_hw_data *ha = vha->hw;
  555. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  556. /* wait for 5 min at the max for loop to be ready */
  557. loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  558. while ((!atomic_read(&base_vha->loop_down_timer) &&
  559. atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
  560. atomic_read(&base_vha->loop_state) != LOOP_READY) {
  561. if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  562. return_status = QLA_FUNCTION_FAILED;
  563. break;
  564. }
  565. msleep(1000);
  566. if (time_after_eq(jiffies, loop_timeout)) {
  567. return_status = QLA_FUNCTION_FAILED;
  568. break;
  569. }
  570. }
  571. return (return_status);
  572. }
  573. void
  574. qla2x00_abort_fcport_cmds(fc_port_t *fcport)
  575. {
  576. int cnt, que, id;
  577. unsigned long flags;
  578. srb_t *sp;
  579. scsi_qla_host_t *vha = fcport->vha;
  580. struct qla_hw_data *ha = vha->hw;
  581. struct req_que *req;
  582. spin_lock_irqsave(&ha->hardware_lock, flags);
  583. for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
  584. id = vha->req_ques[que];
  585. req = ha->req_q_map[id];
  586. if (!req)
  587. continue;
  588. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  589. sp = req->outstanding_cmds[cnt];
  590. if (!sp)
  591. continue;
  592. if (sp->fcport != fcport)
  593. continue;
  594. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  595. if (ha->isp_ops->abort_command(vha, sp, req)) {
  596. DEBUG2(qla_printk(KERN_WARNING, ha,
  597. "Abort failed -- %lx\n",
  598. sp->cmd->serial_number));
  599. } else {
  600. if (qla2x00_eh_wait_on_command(sp->cmd) !=
  601. QLA_SUCCESS)
  602. DEBUG2(qla_printk(KERN_WARNING, ha,
  603. "Abort failed while waiting -- %lx\n",
  604. sp->cmd->serial_number));
  605. }
  606. spin_lock_irqsave(&ha->hardware_lock, flags);
  607. }
  608. }
  609. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  610. }
  611. static void
  612. qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
  613. {
  614. struct Scsi_Host *shost = cmnd->device->host;
  615. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  616. unsigned long flags;
  617. spin_lock_irqsave(shost->host_lock, flags);
  618. while (rport->port_state == FC_PORTSTATE_BLOCKED) {
  619. spin_unlock_irqrestore(shost->host_lock, flags);
  620. msleep(1000);
  621. spin_lock_irqsave(shost->host_lock, flags);
  622. }
  623. spin_unlock_irqrestore(shost->host_lock, flags);
  624. return;
  625. }
  626. /**************************************************************************
  627. * qla2xxx_eh_abort
  628. *
  629. * Description:
  630. * The abort function will abort the specified command.
  631. *
  632. * Input:
  633. * cmd = Linux SCSI command packet to be aborted.
  634. *
  635. * Returns:
  636. * Either SUCCESS or FAILED.
  637. *
  638. * Note:
  639. * Only return FAILED if command not returned by firmware.
  640. **************************************************************************/
  641. static int
  642. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  643. {
  644. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  645. srb_t *sp;
  646. int ret, i;
  647. unsigned int id, lun;
  648. unsigned long serial;
  649. unsigned long flags;
  650. int wait = 0;
  651. struct qla_hw_data *ha = vha->hw;
  652. struct req_que *req;
  653. srb_t *spt;
  654. qla2x00_block_error_handler(cmd);
  655. if (!CMD_SP(cmd))
  656. return SUCCESS;
  657. ret = SUCCESS;
  658. id = cmd->device->id;
  659. lun = cmd->device->lun;
  660. serial = cmd->serial_number;
  661. spt = (srb_t *) CMD_SP(cmd);
  662. if (!spt)
  663. return SUCCESS;
  664. req = spt->que;
  665. /* Check active list for command command. */
  666. spin_lock_irqsave(&ha->hardware_lock, flags);
  667. for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
  668. sp = req->outstanding_cmds[i];
  669. if (sp == NULL)
  670. continue;
  671. if (sp->cmd != cmd)
  672. continue;
  673. DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
  674. " pid=%ld.\n", __func__, vha->host_no, sp, serial));
  675. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  676. if (ha->isp_ops->abort_command(vha, sp, req)) {
  677. DEBUG2(printk("%s(%ld): abort_command "
  678. "mbx failed.\n", __func__, vha->host_no));
  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(scsi_qla_host_t *vha)
  1056. {
  1057. struct qla_hw_data *ha = vha->hw;
  1058. /* Assume a 32bit DMA mask. */
  1059. ha->flags.enable_64bit_addressing = 0;
  1060. if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
  1061. /* Any upper-dword bits set? */
  1062. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  1063. !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
  1064. /* Ok, a 64bit DMA mask is applicable. */
  1065. ha->flags.enable_64bit_addressing = 1;
  1066. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  1067. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  1068. return;
  1069. }
  1070. }
  1071. dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
  1072. pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
  1073. }
  1074. static void
  1075. qla2x00_enable_intrs(struct qla_hw_data *ha)
  1076. {
  1077. unsigned long flags = 0;
  1078. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1079. spin_lock_irqsave(&ha->hardware_lock, flags);
  1080. ha->interrupts_on = 1;
  1081. /* enable risc and host interrupts */
  1082. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1083. RD_REG_WORD(&reg->ictrl);
  1084. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1085. }
  1086. static void
  1087. qla2x00_disable_intrs(struct qla_hw_data *ha)
  1088. {
  1089. unsigned long flags = 0;
  1090. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1091. spin_lock_irqsave(&ha->hardware_lock, flags);
  1092. ha->interrupts_on = 0;
  1093. /* disable risc and host interrupts */
  1094. WRT_REG_WORD(&reg->ictrl, 0);
  1095. RD_REG_WORD(&reg->ictrl);
  1096. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1097. }
  1098. static void
  1099. qla24xx_enable_intrs(struct qla_hw_data *ha)
  1100. {
  1101. unsigned long flags = 0;
  1102. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1103. spin_lock_irqsave(&ha->hardware_lock, flags);
  1104. ha->interrupts_on = 1;
  1105. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1106. RD_REG_DWORD(&reg->ictrl);
  1107. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1108. }
  1109. static void
  1110. qla24xx_disable_intrs(struct qla_hw_data *ha)
  1111. {
  1112. unsigned long flags = 0;
  1113. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1114. if (IS_NOPOLLING_TYPE(ha))
  1115. return;
  1116. spin_lock_irqsave(&ha->hardware_lock, flags);
  1117. ha->interrupts_on = 0;
  1118. WRT_REG_DWORD(&reg->ictrl, 0);
  1119. RD_REG_DWORD(&reg->ictrl);
  1120. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1121. }
  1122. static struct isp_operations qla2100_isp_ops = {
  1123. .pci_config = qla2100_pci_config,
  1124. .reset_chip = qla2x00_reset_chip,
  1125. .chip_diag = qla2x00_chip_diag,
  1126. .config_rings = qla2x00_config_rings,
  1127. .reset_adapter = qla2x00_reset_adapter,
  1128. .nvram_config = qla2x00_nvram_config,
  1129. .update_fw_options = qla2x00_update_fw_options,
  1130. .load_risc = qla2x00_load_risc,
  1131. .pci_info_str = qla2x00_pci_info_str,
  1132. .fw_version_str = qla2x00_fw_version_str,
  1133. .intr_handler = qla2100_intr_handler,
  1134. .enable_intrs = qla2x00_enable_intrs,
  1135. .disable_intrs = qla2x00_disable_intrs,
  1136. .abort_command = qla2x00_abort_command,
  1137. .target_reset = qla2x00_abort_target,
  1138. .lun_reset = qla2x00_lun_reset,
  1139. .fabric_login = qla2x00_login_fabric,
  1140. .fabric_logout = qla2x00_fabric_logout,
  1141. .calc_req_entries = qla2x00_calc_iocbs_32,
  1142. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1143. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1144. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1145. .read_nvram = qla2x00_read_nvram_data,
  1146. .write_nvram = qla2x00_write_nvram_data,
  1147. .fw_dump = qla2100_fw_dump,
  1148. .beacon_on = NULL,
  1149. .beacon_off = NULL,
  1150. .beacon_blink = NULL,
  1151. .read_optrom = qla2x00_read_optrom_data,
  1152. .write_optrom = qla2x00_write_optrom_data,
  1153. .get_flash_version = qla2x00_get_flash_version,
  1154. .start_scsi = qla2x00_start_scsi,
  1155. .wrt_req_reg = NULL,
  1156. .wrt_rsp_reg = NULL,
  1157. .rd_req_reg = NULL,
  1158. };
  1159. static struct isp_operations qla2300_isp_ops = {
  1160. .pci_config = qla2300_pci_config,
  1161. .reset_chip = qla2x00_reset_chip,
  1162. .chip_diag = qla2x00_chip_diag,
  1163. .config_rings = qla2x00_config_rings,
  1164. .reset_adapter = qla2x00_reset_adapter,
  1165. .nvram_config = qla2x00_nvram_config,
  1166. .update_fw_options = qla2x00_update_fw_options,
  1167. .load_risc = qla2x00_load_risc,
  1168. .pci_info_str = qla2x00_pci_info_str,
  1169. .fw_version_str = qla2x00_fw_version_str,
  1170. .intr_handler = qla2300_intr_handler,
  1171. .enable_intrs = qla2x00_enable_intrs,
  1172. .disable_intrs = qla2x00_disable_intrs,
  1173. .abort_command = qla2x00_abort_command,
  1174. .target_reset = qla2x00_abort_target,
  1175. .lun_reset = qla2x00_lun_reset,
  1176. .fabric_login = qla2x00_login_fabric,
  1177. .fabric_logout = qla2x00_fabric_logout,
  1178. .calc_req_entries = qla2x00_calc_iocbs_32,
  1179. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1180. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1181. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1182. .read_nvram = qla2x00_read_nvram_data,
  1183. .write_nvram = qla2x00_write_nvram_data,
  1184. .fw_dump = qla2300_fw_dump,
  1185. .beacon_on = qla2x00_beacon_on,
  1186. .beacon_off = qla2x00_beacon_off,
  1187. .beacon_blink = qla2x00_beacon_blink,
  1188. .read_optrom = qla2x00_read_optrom_data,
  1189. .write_optrom = qla2x00_write_optrom_data,
  1190. .get_flash_version = qla2x00_get_flash_version,
  1191. .start_scsi = qla2x00_start_scsi,
  1192. .wrt_req_reg = NULL,
  1193. .wrt_rsp_reg = NULL,
  1194. .rd_req_reg = NULL,
  1195. };
  1196. static struct isp_operations qla24xx_isp_ops = {
  1197. .pci_config = qla24xx_pci_config,
  1198. .reset_chip = qla24xx_reset_chip,
  1199. .chip_diag = qla24xx_chip_diag,
  1200. .config_rings = qla24xx_config_rings,
  1201. .reset_adapter = qla24xx_reset_adapter,
  1202. .nvram_config = qla24xx_nvram_config,
  1203. .update_fw_options = qla24xx_update_fw_options,
  1204. .load_risc = qla24xx_load_risc,
  1205. .pci_info_str = qla24xx_pci_info_str,
  1206. .fw_version_str = qla24xx_fw_version_str,
  1207. .intr_handler = qla24xx_intr_handler,
  1208. .enable_intrs = qla24xx_enable_intrs,
  1209. .disable_intrs = qla24xx_disable_intrs,
  1210. .abort_command = qla24xx_abort_command,
  1211. .target_reset = qla24xx_abort_target,
  1212. .lun_reset = qla24xx_lun_reset,
  1213. .fabric_login = qla24xx_login_fabric,
  1214. .fabric_logout = qla24xx_fabric_logout,
  1215. .calc_req_entries = NULL,
  1216. .build_iocbs = NULL,
  1217. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1218. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1219. .read_nvram = qla24xx_read_nvram_data,
  1220. .write_nvram = qla24xx_write_nvram_data,
  1221. .fw_dump = qla24xx_fw_dump,
  1222. .beacon_on = qla24xx_beacon_on,
  1223. .beacon_off = qla24xx_beacon_off,
  1224. .beacon_blink = qla24xx_beacon_blink,
  1225. .read_optrom = qla24xx_read_optrom_data,
  1226. .write_optrom = qla24xx_write_optrom_data,
  1227. .get_flash_version = qla24xx_get_flash_version,
  1228. .start_scsi = qla24xx_start_scsi,
  1229. .wrt_req_reg = qla24xx_wrt_req_reg,
  1230. .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
  1231. .rd_req_reg = qla24xx_rd_req_reg,
  1232. };
  1233. static struct isp_operations qla25xx_isp_ops = {
  1234. .pci_config = qla25xx_pci_config,
  1235. .reset_chip = qla24xx_reset_chip,
  1236. .chip_diag = qla24xx_chip_diag,
  1237. .config_rings = qla24xx_config_rings,
  1238. .reset_adapter = qla24xx_reset_adapter,
  1239. .nvram_config = qla24xx_nvram_config,
  1240. .update_fw_options = qla24xx_update_fw_options,
  1241. .load_risc = qla24xx_load_risc,
  1242. .pci_info_str = qla24xx_pci_info_str,
  1243. .fw_version_str = qla24xx_fw_version_str,
  1244. .intr_handler = qla24xx_intr_handler,
  1245. .enable_intrs = qla24xx_enable_intrs,
  1246. .disable_intrs = qla24xx_disable_intrs,
  1247. .abort_command = qla24xx_abort_command,
  1248. .target_reset = qla24xx_abort_target,
  1249. .lun_reset = qla24xx_lun_reset,
  1250. .fabric_login = qla24xx_login_fabric,
  1251. .fabric_logout = qla24xx_fabric_logout,
  1252. .calc_req_entries = NULL,
  1253. .build_iocbs = NULL,
  1254. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1255. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1256. .read_nvram = qla25xx_read_nvram_data,
  1257. .write_nvram = qla25xx_write_nvram_data,
  1258. .fw_dump = qla25xx_fw_dump,
  1259. .beacon_on = qla24xx_beacon_on,
  1260. .beacon_off = qla24xx_beacon_off,
  1261. .beacon_blink = qla24xx_beacon_blink,
  1262. .read_optrom = qla25xx_read_optrom_data,
  1263. .write_optrom = qla24xx_write_optrom_data,
  1264. .get_flash_version = qla24xx_get_flash_version,
  1265. .start_scsi = qla24xx_start_scsi,
  1266. .wrt_req_reg = qla24xx_wrt_req_reg,
  1267. .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
  1268. .rd_req_reg = qla24xx_rd_req_reg,
  1269. };
  1270. static struct isp_operations qla81xx_isp_ops = {
  1271. .pci_config = qla25xx_pci_config,
  1272. .reset_chip = qla24xx_reset_chip,
  1273. .chip_diag = qla24xx_chip_diag,
  1274. .config_rings = qla24xx_config_rings,
  1275. .reset_adapter = qla24xx_reset_adapter,
  1276. .nvram_config = qla81xx_nvram_config,
  1277. .update_fw_options = qla81xx_update_fw_options,
  1278. .load_risc = qla81xx_load_risc,
  1279. .pci_info_str = qla24xx_pci_info_str,
  1280. .fw_version_str = qla24xx_fw_version_str,
  1281. .intr_handler = qla24xx_intr_handler,
  1282. .enable_intrs = qla24xx_enable_intrs,
  1283. .disable_intrs = qla24xx_disable_intrs,
  1284. .abort_command = qla24xx_abort_command,
  1285. .target_reset = qla24xx_abort_target,
  1286. .lun_reset = qla24xx_lun_reset,
  1287. .fabric_login = qla24xx_login_fabric,
  1288. .fabric_logout = qla24xx_fabric_logout,
  1289. .calc_req_entries = NULL,
  1290. .build_iocbs = NULL,
  1291. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1292. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1293. .read_nvram = qla25xx_read_nvram_data,
  1294. .write_nvram = qla25xx_write_nvram_data,
  1295. .fw_dump = qla81xx_fw_dump,
  1296. .beacon_on = qla24xx_beacon_on,
  1297. .beacon_off = qla24xx_beacon_off,
  1298. .beacon_blink = qla24xx_beacon_blink,
  1299. .read_optrom = qla25xx_read_optrom_data,
  1300. .write_optrom = qla24xx_write_optrom_data,
  1301. .get_flash_version = qla24xx_get_flash_version,
  1302. .start_scsi = qla24xx_start_scsi,
  1303. .wrt_req_reg = qla24xx_wrt_req_reg,
  1304. .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
  1305. .rd_req_reg = qla24xx_rd_req_reg,
  1306. };
  1307. static inline void
  1308. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  1309. {
  1310. ha->device_type = DT_EXTENDED_IDS;
  1311. switch (ha->pdev->device) {
  1312. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1313. ha->device_type |= DT_ISP2100;
  1314. ha->device_type &= ~DT_EXTENDED_IDS;
  1315. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1316. break;
  1317. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1318. ha->device_type |= DT_ISP2200;
  1319. ha->device_type &= ~DT_EXTENDED_IDS;
  1320. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1321. break;
  1322. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1323. ha->device_type |= DT_ISP2300;
  1324. ha->device_type |= DT_ZIO_SUPPORTED;
  1325. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1326. break;
  1327. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1328. ha->device_type |= DT_ISP2312;
  1329. ha->device_type |= DT_ZIO_SUPPORTED;
  1330. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1331. break;
  1332. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1333. ha->device_type |= DT_ISP2322;
  1334. ha->device_type |= DT_ZIO_SUPPORTED;
  1335. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1336. ha->pdev->subsystem_device == 0x0170)
  1337. ha->device_type |= DT_OEM_001;
  1338. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1339. break;
  1340. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1341. ha->device_type |= DT_ISP6312;
  1342. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1343. break;
  1344. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1345. ha->device_type |= DT_ISP6322;
  1346. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1347. break;
  1348. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1349. ha->device_type |= DT_ISP2422;
  1350. ha->device_type |= DT_ZIO_SUPPORTED;
  1351. ha->device_type |= DT_FWI2;
  1352. ha->device_type |= DT_IIDMA;
  1353. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1354. break;
  1355. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1356. ha->device_type |= DT_ISP2432;
  1357. ha->device_type |= DT_ZIO_SUPPORTED;
  1358. ha->device_type |= DT_FWI2;
  1359. ha->device_type |= DT_IIDMA;
  1360. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1361. break;
  1362. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1363. ha->device_type |= DT_ISP8432;
  1364. ha->device_type |= DT_ZIO_SUPPORTED;
  1365. ha->device_type |= DT_FWI2;
  1366. ha->device_type |= DT_IIDMA;
  1367. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1368. break;
  1369. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1370. ha->device_type |= DT_ISP5422;
  1371. ha->device_type |= DT_FWI2;
  1372. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1373. break;
  1374. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  1375. ha->device_type |= DT_ISP5432;
  1376. ha->device_type |= DT_FWI2;
  1377. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1378. break;
  1379. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  1380. ha->device_type |= DT_ISP2532;
  1381. ha->device_type |= DT_ZIO_SUPPORTED;
  1382. ha->device_type |= DT_FWI2;
  1383. ha->device_type |= DT_IIDMA;
  1384. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1385. break;
  1386. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  1387. ha->device_type |= DT_ISP8001;
  1388. ha->device_type |= DT_ZIO_SUPPORTED;
  1389. ha->device_type |= DT_FWI2;
  1390. ha->device_type |= DT_IIDMA;
  1391. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1392. break;
  1393. }
  1394. }
  1395. static int
  1396. qla2x00_iospace_config(struct qla_hw_data *ha)
  1397. {
  1398. resource_size_t pio;
  1399. uint16_t msix;
  1400. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1401. QLA2XXX_DRIVER_NAME)) {
  1402. qla_printk(KERN_WARNING, ha,
  1403. "Failed to reserve PIO/MMIO regions (%s)\n",
  1404. pci_name(ha->pdev));
  1405. goto iospace_error_exit;
  1406. }
  1407. if (!(ha->bars & 1))
  1408. goto skip_pio;
  1409. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1410. pio = pci_resource_start(ha->pdev, 0);
  1411. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1412. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1413. qla_printk(KERN_WARNING, ha,
  1414. "Invalid PCI I/O region size (%s)...\n",
  1415. pci_name(ha->pdev));
  1416. pio = 0;
  1417. }
  1418. } else {
  1419. qla_printk(KERN_WARNING, ha,
  1420. "region #0 not a PIO resource (%s)...\n",
  1421. pci_name(ha->pdev));
  1422. pio = 0;
  1423. }
  1424. ha->pio_address = pio;
  1425. skip_pio:
  1426. /* Use MMIO operations for all accesses. */
  1427. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1428. qla_printk(KERN_ERR, ha,
  1429. "region #1 not an MMIO resource (%s), aborting\n",
  1430. pci_name(ha->pdev));
  1431. goto iospace_error_exit;
  1432. }
  1433. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1434. qla_printk(KERN_ERR, ha,
  1435. "Invalid PCI mem region size (%s), aborting\n",
  1436. pci_name(ha->pdev));
  1437. goto iospace_error_exit;
  1438. }
  1439. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1440. if (!ha->iobase) {
  1441. qla_printk(KERN_ERR, ha,
  1442. "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
  1443. goto iospace_error_exit;
  1444. }
  1445. /* Determine queue resources */
  1446. ha->max_queues = 1;
  1447. if (ql2xmaxqueues <= 1 || (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1448. goto mqiobase_exit;
  1449. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1450. pci_resource_len(ha->pdev, 3));
  1451. if (ha->mqiobase) {
  1452. /* Read MSIX vector size of the board */
  1453. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1454. ha->msix_count = msix;
  1455. /* Max queues are bounded by available msix vectors */
  1456. /* queue 0 uses two msix vectors */
  1457. if (ha->msix_count - 1 < ql2xmaxqueues)
  1458. ha->max_queues = ha->msix_count - 1;
  1459. else if (ql2xmaxqueues > QLA_MQ_SIZE)
  1460. ha->max_queues = QLA_MQ_SIZE;
  1461. else
  1462. ha->max_queues = ql2xmaxqueues;
  1463. qla_printk(KERN_INFO, ha,
  1464. "MSI-X vector count: %d\n", msix);
  1465. }
  1466. mqiobase_exit:
  1467. ha->msix_count = ha->max_queues + 1;
  1468. return (0);
  1469. iospace_error_exit:
  1470. return (-ENOMEM);
  1471. }
  1472. static void
  1473. qla2xxx_scan_start(struct Scsi_Host *shost)
  1474. {
  1475. scsi_qla_host_t *vha = shost_priv(shost);
  1476. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  1477. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  1478. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  1479. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  1480. }
  1481. static int
  1482. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1483. {
  1484. scsi_qla_host_t *vha = shost_priv(shost);
  1485. if (!vha->host)
  1486. return 1;
  1487. if (time > vha->hw->loop_reset_delay * HZ)
  1488. return 1;
  1489. return atomic_read(&vha->loop_state) == LOOP_READY;
  1490. }
  1491. /*
  1492. * PCI driver interface
  1493. */
  1494. static int __devinit
  1495. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  1496. {
  1497. int ret = -ENODEV;
  1498. struct Scsi_Host *host;
  1499. scsi_qla_host_t *base_vha = NULL;
  1500. struct qla_hw_data *ha;
  1501. char pci_info[30];
  1502. char fw_str[30];
  1503. struct scsi_host_template *sht;
  1504. int bars, max_id, mem_only = 0;
  1505. uint16_t req_length = 0, rsp_length = 0;
  1506. struct req_que *req = NULL;
  1507. struct rsp_que *rsp = NULL;
  1508. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  1509. sht = &qla2x00_driver_template;
  1510. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  1511. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  1512. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  1513. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  1514. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  1515. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  1516. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
  1517. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1518. sht = &qla24xx_driver_template;
  1519. mem_only = 1;
  1520. }
  1521. if (mem_only) {
  1522. if (pci_enable_device_mem(pdev))
  1523. goto probe_out;
  1524. } else {
  1525. if (pci_enable_device(pdev))
  1526. goto probe_out;
  1527. }
  1528. /* This may fail but that's ok */
  1529. pci_enable_pcie_error_reporting(pdev);
  1530. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  1531. if (!ha) {
  1532. DEBUG(printk("Unable to allocate memory for ha\n"));
  1533. goto probe_out;
  1534. }
  1535. ha->pdev = pdev;
  1536. /* Clear our data area */
  1537. ha->bars = bars;
  1538. ha->mem_only = mem_only;
  1539. spin_lock_init(&ha->hardware_lock);
  1540. /* Set ISP-type information. */
  1541. qla2x00_set_isp_flags(ha);
  1542. /* Configure PCI I/O space */
  1543. ret = qla2x00_iospace_config(ha);
  1544. if (ret)
  1545. goto probe_hw_failed;
  1546. qla_printk(KERN_INFO, ha,
  1547. "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
  1548. ha->iobase);
  1549. ha->prev_topology = 0;
  1550. ha->init_cb_size = sizeof(init_cb_t);
  1551. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  1552. ha->optrom_size = OPTROM_SIZE_2300;
  1553. /* Assign ISP specific operations. */
  1554. max_id = MAX_TARGETS_2200;
  1555. if (IS_QLA2100(ha)) {
  1556. max_id = MAX_TARGETS_2100;
  1557. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  1558. req_length = REQUEST_ENTRY_CNT_2100;
  1559. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1560. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1561. ha->gid_list_info_size = 4;
  1562. ha->flash_conf_off = ~0;
  1563. ha->flash_data_off = ~0;
  1564. ha->nvram_conf_off = ~0;
  1565. ha->nvram_data_off = ~0;
  1566. ha->isp_ops = &qla2100_isp_ops;
  1567. } else if (IS_QLA2200(ha)) {
  1568. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1569. req_length = REQUEST_ENTRY_CNT_2200;
  1570. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1571. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1572. ha->gid_list_info_size = 4;
  1573. ha->flash_conf_off = ~0;
  1574. ha->flash_data_off = ~0;
  1575. ha->nvram_conf_off = ~0;
  1576. ha->nvram_data_off = ~0;
  1577. ha->isp_ops = &qla2100_isp_ops;
  1578. } else if (IS_QLA23XX(ha)) {
  1579. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1580. req_length = REQUEST_ENTRY_CNT_2200;
  1581. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1582. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1583. ha->gid_list_info_size = 6;
  1584. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1585. ha->optrom_size = OPTROM_SIZE_2322;
  1586. ha->flash_conf_off = ~0;
  1587. ha->flash_data_off = ~0;
  1588. ha->nvram_conf_off = ~0;
  1589. ha->nvram_data_off = ~0;
  1590. ha->isp_ops = &qla2300_isp_ops;
  1591. } else if (IS_QLA24XX_TYPE(ha)) {
  1592. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1593. req_length = REQUEST_ENTRY_CNT_24XX;
  1594. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1595. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1596. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1597. ha->gid_list_info_size = 8;
  1598. ha->optrom_size = OPTROM_SIZE_24XX;
  1599. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  1600. ha->isp_ops = &qla24xx_isp_ops;
  1601. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1602. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1603. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1604. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1605. } else if (IS_QLA25XX(ha)) {
  1606. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1607. req_length = REQUEST_ENTRY_CNT_24XX;
  1608. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1609. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1610. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1611. ha->gid_list_info_size = 8;
  1612. ha->optrom_size = OPTROM_SIZE_25XX;
  1613. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1614. ha->isp_ops = &qla25xx_isp_ops;
  1615. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1616. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1617. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1618. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1619. } else if (IS_QLA81XX(ha)) {
  1620. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1621. req_length = REQUEST_ENTRY_CNT_24XX;
  1622. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1623. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1624. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  1625. ha->gid_list_info_size = 8;
  1626. ha->optrom_size = OPTROM_SIZE_81XX;
  1627. ha->isp_ops = &qla81xx_isp_ops;
  1628. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  1629. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  1630. ha->nvram_conf_off = ~0;
  1631. ha->nvram_data_off = ~0;
  1632. }
  1633. mutex_init(&ha->vport_lock);
  1634. init_completion(&ha->mbx_cmd_comp);
  1635. complete(&ha->mbx_cmd_comp);
  1636. init_completion(&ha->mbx_intr_comp);
  1637. set_bit(0, (unsigned long *) ha->vp_idx_map);
  1638. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  1639. if (!ret) {
  1640. qla_printk(KERN_WARNING, ha,
  1641. "[ERROR] Failed to allocate memory for adapter\n");
  1642. goto probe_hw_failed;
  1643. }
  1644. req->max_q_depth = MAX_Q_DEPTH;
  1645. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  1646. req->max_q_depth = ql2xmaxqdepth;
  1647. base_vha = qla2x00_create_host(sht, ha);
  1648. if (!base_vha) {
  1649. qla_printk(KERN_WARNING, ha,
  1650. "[ERROR] Failed to allocate memory for scsi_host\n");
  1651. ret = -ENOMEM;
  1652. qla2x00_mem_free(ha);
  1653. qla2x00_free_que(ha, req, rsp);
  1654. goto probe_hw_failed;
  1655. }
  1656. pci_set_drvdata(pdev, base_vha);
  1657. qla2x00_config_dma_addressing(base_vha);
  1658. host = base_vha->host;
  1659. base_vha->req_ques[0] = req->id;
  1660. host->can_queue = req->length + 128;
  1661. if (IS_QLA2XXX_MIDTYPE(ha))
  1662. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  1663. else
  1664. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  1665. base_vha->vp_idx;
  1666. if (IS_QLA2100(ha))
  1667. host->sg_tablesize = 32;
  1668. host->max_id = max_id;
  1669. host->this_id = 255;
  1670. host->cmd_per_lun = 3;
  1671. host->unique_id = host->host_no;
  1672. host->max_cmd_len = MAX_CMDSZ;
  1673. host->max_channel = MAX_BUSES - 1;
  1674. host->max_lun = MAX_LUNS;
  1675. host->transportt = qla2xxx_transport_template;
  1676. /* Set up the irqs */
  1677. ret = qla2x00_request_irqs(ha, rsp);
  1678. if (ret)
  1679. goto probe_init_failed;
  1680. /* Alloc arrays of request and response ring ptrs */
  1681. if (!qla2x00_alloc_queues(ha)) {
  1682. qla_printk(KERN_WARNING, ha,
  1683. "[ERROR] Failed to allocate memory for queue"
  1684. " pointers\n");
  1685. goto probe_init_failed;
  1686. }
  1687. ha->rsp_q_map[0] = rsp;
  1688. ha->req_q_map[0] = req;
  1689. if (ha->mqenable) {
  1690. ha->isp_ops->wrt_req_reg = qla25xx_wrt_req_reg;
  1691. ha->isp_ops->wrt_rsp_reg = qla25xx_wrt_rsp_reg;
  1692. ha->isp_ops->rd_req_reg = qla25xx_rd_req_reg;
  1693. }
  1694. if (qla2x00_initialize_adapter(base_vha)) {
  1695. qla_printk(KERN_WARNING, ha,
  1696. "Failed to initialize adapter\n");
  1697. DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
  1698. "Adapter flags %x.\n",
  1699. base_vha->host_no, base_vha->device_flags));
  1700. ret = -ENODEV;
  1701. goto probe_failed;
  1702. }
  1703. /*
  1704. * Startup the kernel thread for this host adapter
  1705. */
  1706. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  1707. "%s_dpc", base_vha->host_str);
  1708. if (IS_ERR(ha->dpc_thread)) {
  1709. qla_printk(KERN_WARNING, ha,
  1710. "Unable to start DPC thread!\n");
  1711. ret = PTR_ERR(ha->dpc_thread);
  1712. goto probe_failed;
  1713. }
  1714. list_add_tail(&base_vha->list, &ha->vp_list);
  1715. base_vha->host->irq = ha->pdev->irq;
  1716. /* Initialized the timer */
  1717. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  1718. DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
  1719. base_vha->host_no, ha));
  1720. base_vha->flags.init_done = 1;
  1721. base_vha->flags.online = 1;
  1722. ret = scsi_add_host(host, &pdev->dev);
  1723. if (ret)
  1724. goto probe_failed;
  1725. ha->isp_ops->enable_intrs(ha);
  1726. scsi_scan_host(host);
  1727. qla2x00_alloc_sysfs_attr(base_vha);
  1728. qla2x00_init_host_attr(base_vha);
  1729. qla2x00_dfs_setup(base_vha);
  1730. qla_printk(KERN_INFO, ha, "\n"
  1731. " QLogic Fibre Channel HBA Driver: %s\n"
  1732. " QLogic %s - %s\n"
  1733. " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
  1734. qla2x00_version_str, ha->model_number,
  1735. ha->model_desc ? ha->model_desc : "", pdev->device,
  1736. ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
  1737. ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
  1738. ha->isp_ops->fw_version_str(base_vha, fw_str));
  1739. return 0;
  1740. probe_init_failed:
  1741. qla2x00_free_que(ha, req, rsp);
  1742. ha->max_queues = 0;
  1743. probe_failed:
  1744. qla2x00_free_device(base_vha);
  1745. scsi_host_put(base_vha->host);
  1746. probe_hw_failed:
  1747. if (ha->iobase)
  1748. iounmap(ha->iobase);
  1749. pci_release_selected_regions(ha->pdev, ha->bars);
  1750. kfree(ha);
  1751. ha = NULL;
  1752. probe_out:
  1753. pci_disable_device(pdev);
  1754. return ret;
  1755. }
  1756. static void
  1757. qla2x00_remove_one(struct pci_dev *pdev)
  1758. {
  1759. scsi_qla_host_t *base_vha, *vha, *temp;
  1760. struct qla_hw_data *ha;
  1761. base_vha = pci_get_drvdata(pdev);
  1762. ha = base_vha->hw;
  1763. list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
  1764. if (vha && vha->fc_vport)
  1765. fc_vport_terminate(vha->fc_vport);
  1766. }
  1767. set_bit(UNLOADING, &base_vha->dpc_flags);
  1768. qla2x00_dfs_remove(base_vha);
  1769. qla84xx_put_chip(base_vha);
  1770. qla2x00_free_sysfs_attr(base_vha);
  1771. fc_remove_host(base_vha->host);
  1772. scsi_remove_host(base_vha->host);
  1773. qla2x00_free_device(base_vha);
  1774. scsi_host_put(base_vha->host);
  1775. if (ha->iobase)
  1776. iounmap(ha->iobase);
  1777. if (ha->mqiobase)
  1778. iounmap(ha->mqiobase);
  1779. pci_release_selected_regions(ha->pdev, ha->bars);
  1780. kfree(ha);
  1781. ha = NULL;
  1782. pci_disable_device(pdev);
  1783. pci_set_drvdata(pdev, NULL);
  1784. }
  1785. static void
  1786. qla2x00_free_device(scsi_qla_host_t *vha)
  1787. {
  1788. struct qla_hw_data *ha = vha->hw;
  1789. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  1790. /* Disable timer */
  1791. if (vha->timer_active)
  1792. qla2x00_stop_timer(vha);
  1793. vha->flags.online = 0;
  1794. /* Kill the kernel thread for this host */
  1795. if (ha->dpc_thread) {
  1796. struct task_struct *t = ha->dpc_thread;
  1797. /*
  1798. * qla2xxx_wake_dpc checks for ->dpc_thread
  1799. * so we need to zero it out.
  1800. */
  1801. ha->dpc_thread = NULL;
  1802. kthread_stop(t);
  1803. }
  1804. if (ha->flags.fce_enabled)
  1805. qla2x00_disable_fce_trace(vha, NULL, NULL);
  1806. if (ha->eft)
  1807. qla2x00_disable_eft_trace(vha);
  1808. /* Stop currently executing firmware. */
  1809. qla2x00_try_to_stop_firmware(vha);
  1810. /* turn-off interrupts on the card */
  1811. if (ha->interrupts_on)
  1812. ha->isp_ops->disable_intrs(ha);
  1813. qla2x00_free_irqs(vha);
  1814. qla2x00_mem_free(ha);
  1815. qla2x00_free_queues(ha);
  1816. }
  1817. static inline void
  1818. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  1819. int defer)
  1820. {
  1821. struct fc_rport *rport;
  1822. if (!fcport->rport)
  1823. return;
  1824. rport = fcport->rport;
  1825. if (defer) {
  1826. spin_lock_irq(vha->host->host_lock);
  1827. fcport->drport = rport;
  1828. spin_unlock_irq(vha->host->host_lock);
  1829. set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
  1830. qla2xxx_wake_dpc(vha);
  1831. } else
  1832. fc_remote_port_delete(rport);
  1833. }
  1834. /*
  1835. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  1836. *
  1837. * Input: ha = adapter block pointer. fcport = port structure pointer.
  1838. *
  1839. * Return: None.
  1840. *
  1841. * Context:
  1842. */
  1843. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  1844. int do_login, int defer)
  1845. {
  1846. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  1847. vha->vp_idx == fcport->vp_idx) {
  1848. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1849. qla2x00_schedule_rport_del(vha, fcport, defer);
  1850. }
  1851. /*
  1852. * We may need to retry the login, so don't change the state of the
  1853. * port but do the retries.
  1854. */
  1855. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  1856. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1857. if (!do_login)
  1858. return;
  1859. if (fcport->login_retry == 0) {
  1860. fcport->login_retry = vha->hw->login_retry_count;
  1861. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  1862. DEBUG(printk("scsi(%ld): Port login retry: "
  1863. "%02x%02x%02x%02x%02x%02x%02x%02x, "
  1864. "id = 0x%04x retry cnt=%d\n",
  1865. vha->host_no,
  1866. fcport->port_name[0],
  1867. fcport->port_name[1],
  1868. fcport->port_name[2],
  1869. fcport->port_name[3],
  1870. fcport->port_name[4],
  1871. fcport->port_name[5],
  1872. fcport->port_name[6],
  1873. fcport->port_name[7],
  1874. fcport->loop_id,
  1875. fcport->login_retry));
  1876. }
  1877. }
  1878. /*
  1879. * qla2x00_mark_all_devices_lost
  1880. * Updates fcport state when device goes offline.
  1881. *
  1882. * Input:
  1883. * ha = adapter block pointer.
  1884. * fcport = port structure pointer.
  1885. *
  1886. * Return:
  1887. * None.
  1888. *
  1889. * Context:
  1890. */
  1891. void
  1892. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  1893. {
  1894. fc_port_t *fcport;
  1895. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1896. if (vha->vp_idx != fcport->vp_idx)
  1897. continue;
  1898. /*
  1899. * No point in marking the device as lost, if the device is
  1900. * already DEAD.
  1901. */
  1902. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  1903. continue;
  1904. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  1905. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1906. qla2x00_schedule_rport_del(vha, fcport, defer);
  1907. } else
  1908. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1909. }
  1910. }
  1911. /*
  1912. * qla2x00_mem_alloc
  1913. * Allocates adapter memory.
  1914. *
  1915. * Returns:
  1916. * 0 = success.
  1917. * !0 = failure.
  1918. */
  1919. static int
  1920. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  1921. struct req_que **req, struct rsp_que **rsp)
  1922. {
  1923. char name[16];
  1924. ha->init_cb_size = sizeof(init_cb_t);
  1925. if (IS_QLA2XXX_MIDTYPE(ha))
  1926. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1927. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  1928. &ha->init_cb_dma, GFP_KERNEL);
  1929. if (!ha->init_cb)
  1930. goto fail;
  1931. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
  1932. &ha->gid_list_dma, GFP_KERNEL);
  1933. if (!ha->gid_list)
  1934. goto fail_free_init_cb;
  1935. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  1936. if (!ha->srb_mempool)
  1937. goto fail_free_gid_list;
  1938. /* Get memory for cached NVRAM */
  1939. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  1940. if (!ha->nvram)
  1941. goto fail_free_srb_mempool;
  1942. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  1943. ha->pdev->device);
  1944. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  1945. DMA_POOL_SIZE, 8, 0);
  1946. if (!ha->s_dma_pool)
  1947. goto fail_free_nvram;
  1948. /* Allocate memory for SNS commands */
  1949. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1950. /* Get consistent memory allocated for SNS commands */
  1951. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  1952. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  1953. if (!ha->sns_cmd)
  1954. goto fail_dma_pool;
  1955. } else {
  1956. /* Get consistent memory allocated for MS IOCB */
  1957. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1958. &ha->ms_iocb_dma);
  1959. if (!ha->ms_iocb)
  1960. goto fail_dma_pool;
  1961. /* Get consistent memory allocated for CT SNS commands */
  1962. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  1963. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  1964. if (!ha->ct_sns)
  1965. goto fail_free_ms_iocb;
  1966. }
  1967. /* Allocate memory for request ring */
  1968. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  1969. if (!*req) {
  1970. DEBUG(printk("Unable to allocate memory for req\n"));
  1971. goto fail_req;
  1972. }
  1973. (*req)->length = req_len;
  1974. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  1975. ((*req)->length + 1) * sizeof(request_t),
  1976. &(*req)->dma, GFP_KERNEL);
  1977. if (!(*req)->ring) {
  1978. DEBUG(printk("Unable to allocate memory for req_ring\n"));
  1979. goto fail_req_ring;
  1980. }
  1981. /* Allocate memory for response ring */
  1982. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  1983. if (!*rsp) {
  1984. qla_printk(KERN_WARNING, ha,
  1985. "Unable to allocate memory for rsp\n");
  1986. goto fail_rsp;
  1987. }
  1988. (*rsp)->hw = ha;
  1989. (*rsp)->length = rsp_len;
  1990. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  1991. ((*rsp)->length + 1) * sizeof(response_t),
  1992. &(*rsp)->dma, GFP_KERNEL);
  1993. if (!(*rsp)->ring) {
  1994. qla_printk(KERN_WARNING, ha,
  1995. "Unable to allocate memory for rsp_ring\n");
  1996. goto fail_rsp_ring;
  1997. }
  1998. (*req)->rsp = *rsp;
  1999. (*rsp)->req = *req;
  2000. /* Allocate memory for NVRAM data for vports */
  2001. if (ha->nvram_npiv_size) {
  2002. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  2003. ha->nvram_npiv_size, GFP_KERNEL);
  2004. if (!ha->npiv_info) {
  2005. qla_printk(KERN_WARNING, ha,
  2006. "Unable to allocate memory for npiv info\n");
  2007. goto fail_npiv_info;
  2008. }
  2009. } else
  2010. ha->npiv_info = NULL;
  2011. INIT_LIST_HEAD(&ha->vp_list);
  2012. return 1;
  2013. fail_npiv_info:
  2014. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  2015. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  2016. (*rsp)->ring = NULL;
  2017. (*rsp)->dma = 0;
  2018. fail_rsp_ring:
  2019. kfree(*rsp);
  2020. fail_rsp:
  2021. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  2022. sizeof(request_t), (*req)->ring, (*req)->dma);
  2023. (*req)->ring = NULL;
  2024. (*req)->dma = 0;
  2025. fail_req_ring:
  2026. kfree(*req);
  2027. fail_req:
  2028. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2029. ha->ct_sns, ha->ct_sns_dma);
  2030. ha->ct_sns = NULL;
  2031. ha->ct_sns_dma = 0;
  2032. fail_free_ms_iocb:
  2033. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2034. ha->ms_iocb = NULL;
  2035. ha->ms_iocb_dma = 0;
  2036. fail_dma_pool:
  2037. dma_pool_destroy(ha->s_dma_pool);
  2038. ha->s_dma_pool = NULL;
  2039. fail_free_nvram:
  2040. kfree(ha->nvram);
  2041. ha->nvram = NULL;
  2042. fail_free_srb_mempool:
  2043. mempool_destroy(ha->srb_mempool);
  2044. ha->srb_mempool = NULL;
  2045. fail_free_gid_list:
  2046. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2047. ha->gid_list_dma);
  2048. ha->gid_list = NULL;
  2049. ha->gid_list_dma = 0;
  2050. fail_free_init_cb:
  2051. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  2052. ha->init_cb_dma);
  2053. ha->init_cb = NULL;
  2054. ha->init_cb_dma = 0;
  2055. fail:
  2056. DEBUG(printk("%s: Memory allocation failure\n", __func__));
  2057. return -ENOMEM;
  2058. }
  2059. /*
  2060. * qla2x00_mem_free
  2061. * Frees all adapter allocated memory.
  2062. *
  2063. * Input:
  2064. * ha = adapter block pointer.
  2065. */
  2066. static void
  2067. qla2x00_mem_free(struct qla_hw_data *ha)
  2068. {
  2069. if (ha->srb_mempool)
  2070. mempool_destroy(ha->srb_mempool);
  2071. if (ha->fce)
  2072. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  2073. ha->fce_dma);
  2074. if (ha->fw_dump) {
  2075. if (ha->eft)
  2076. dma_free_coherent(&ha->pdev->dev,
  2077. ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
  2078. vfree(ha->fw_dump);
  2079. }
  2080. if (ha->sns_cmd)
  2081. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  2082. ha->sns_cmd, ha->sns_cmd_dma);
  2083. if (ha->ct_sns)
  2084. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2085. ha->ct_sns, ha->ct_sns_dma);
  2086. if (ha->sfp_data)
  2087. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  2088. if (ha->ms_iocb)
  2089. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2090. if (ha->s_dma_pool)
  2091. dma_pool_destroy(ha->s_dma_pool);
  2092. if (ha->gid_list)
  2093. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2094. ha->gid_list_dma);
  2095. if (ha->init_cb)
  2096. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  2097. ha->init_cb, ha->init_cb_dma);
  2098. vfree(ha->optrom_buffer);
  2099. kfree(ha->nvram);
  2100. kfree(ha->npiv_info);
  2101. ha->srb_mempool = NULL;
  2102. ha->eft = NULL;
  2103. ha->eft_dma = 0;
  2104. ha->sns_cmd = NULL;
  2105. ha->sns_cmd_dma = 0;
  2106. ha->ct_sns = NULL;
  2107. ha->ct_sns_dma = 0;
  2108. ha->ms_iocb = NULL;
  2109. ha->ms_iocb_dma = 0;
  2110. ha->init_cb = NULL;
  2111. ha->init_cb_dma = 0;
  2112. ha->s_dma_pool = NULL;
  2113. ha->gid_list = NULL;
  2114. ha->gid_list_dma = 0;
  2115. ha->fw_dump = NULL;
  2116. ha->fw_dumped = 0;
  2117. ha->fw_dump_reading = 0;
  2118. }
  2119. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  2120. struct qla_hw_data *ha)
  2121. {
  2122. struct Scsi_Host *host;
  2123. struct scsi_qla_host *vha = NULL;
  2124. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  2125. if (host == NULL) {
  2126. printk(KERN_WARNING
  2127. "qla2xxx: Couldn't allocate host from scsi layer!\n");
  2128. goto fail;
  2129. }
  2130. /* Clear our data area */
  2131. vha = shost_priv(host);
  2132. memset(vha, 0, sizeof(scsi_qla_host_t));
  2133. vha->host = host;
  2134. vha->host_no = host->host_no;
  2135. vha->hw = ha;
  2136. INIT_LIST_HEAD(&vha->vp_fcports);
  2137. INIT_LIST_HEAD(&vha->work_list);
  2138. INIT_LIST_HEAD(&vha->list);
  2139. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  2140. return vha;
  2141. fail:
  2142. return vha;
  2143. }
  2144. static struct qla_work_evt *
  2145. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type,
  2146. int locked)
  2147. {
  2148. struct qla_work_evt *e;
  2149. e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
  2150. GFP_KERNEL);
  2151. if (!e)
  2152. return NULL;
  2153. INIT_LIST_HEAD(&e->list);
  2154. e->type = type;
  2155. e->flags = QLA_EVT_FLAG_FREE;
  2156. return e;
  2157. }
  2158. static int
  2159. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked)
  2160. {
  2161. unsigned long uninitialized_var(flags);
  2162. struct qla_hw_data *ha = vha->hw;
  2163. if (!locked)
  2164. spin_lock_irqsave(&ha->hardware_lock, flags);
  2165. list_add_tail(&e->list, &vha->work_list);
  2166. qla2xxx_wake_dpc(vha);
  2167. if (!locked)
  2168. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2169. return QLA_SUCCESS;
  2170. }
  2171. int
  2172. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  2173. u32 data)
  2174. {
  2175. struct qla_work_evt *e;
  2176. e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1);
  2177. if (!e)
  2178. return QLA_FUNCTION_FAILED;
  2179. e->u.aen.code = code;
  2180. e->u.aen.data = data;
  2181. return qla2x00_post_work(vha, e, 1);
  2182. }
  2183. static void
  2184. qla2x00_do_work(struct scsi_qla_host *vha)
  2185. {
  2186. struct qla_work_evt *e;
  2187. struct qla_hw_data *ha = vha->hw;
  2188. spin_lock_irq(&ha->hardware_lock);
  2189. while (!list_empty(&vha->work_list)) {
  2190. e = list_entry(vha->work_list.next, struct qla_work_evt, list);
  2191. list_del_init(&e->list);
  2192. spin_unlock_irq(&ha->hardware_lock);
  2193. switch (e->type) {
  2194. case QLA_EVT_AEN:
  2195. fc_host_post_event(vha->host, fc_get_event_number(),
  2196. e->u.aen.code, e->u.aen.data);
  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. uint8_t 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);