qla_os.c 82 KB

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