ql4_os.c 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2010 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include <linux/moduleparam.h>
  8. #include <linux/slab.h>
  9. #include <linux/blkdev.h>
  10. #include <linux/iscsi_boot_sysfs.h>
  11. #include <scsi/scsi_tcq.h>
  12. #include <scsi/scsicam.h>
  13. #include "ql4_def.h"
  14. #include "ql4_version.h"
  15. #include "ql4_glbl.h"
  16. #include "ql4_dbg.h"
  17. #include "ql4_inline.h"
  18. /*
  19. * Driver version
  20. */
  21. static char qla4xxx_version_str[40];
  22. /*
  23. * SRB allocation cache
  24. */
  25. static struct kmem_cache *srb_cachep;
  26. /*
  27. * Module parameter information and variables
  28. */
  29. int ql4xdontresethba = 0;
  30. module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
  31. MODULE_PARM_DESC(ql4xdontresethba,
  32. "Don't reset the HBA for driver recovery \n"
  33. " 0 - It will reset HBA (Default)\n"
  34. " 1 - It will NOT reset HBA");
  35. int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
  36. module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
  37. MODULE_PARM_DESC(ql4xextended_error_logging,
  38. "Option to enable extended error logging, "
  39. "Default is 0 - no logging, 1 - debug logging");
  40. int ql4xenablemsix = 1;
  41. module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
  42. MODULE_PARM_DESC(ql4xenablemsix,
  43. "Set to enable MSI or MSI-X interrupt mechanism.\n"
  44. " 0 = enable INTx interrupt mechanism.\n"
  45. " 1 = enable MSI-X interrupt mechanism (Default).\n"
  46. " 2 = enable MSI interrupt mechanism.");
  47. #define QL4_DEF_QDEPTH 32
  48. static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
  49. module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
  50. MODULE_PARM_DESC(ql4xmaxqdepth,
  51. "Maximum queue depth to report for target devices.\n"
  52. " Default: 32.");
  53. static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
  54. module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
  55. MODULE_PARM_DESC(ql4xsess_recovery_tmo,
  56. "Target Session Recovery Timeout.\n"
  57. " Default: 30 sec.");
  58. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
  59. /*
  60. * SCSI host template entry points
  61. */
  62. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
  63. /*
  64. * iSCSI template entry points
  65. */
  66. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  67. enum iscsi_param param, char *buf);
  68. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  69. enum iscsi_host_param param, char *buf);
  70. static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
  71. uint32_t len);
  72. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  73. enum iscsi_param_type param_type,
  74. int param, char *buf);
  75. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
  76. static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
  77. struct sockaddr *dst_addr,
  78. int non_blocking);
  79. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
  80. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
  81. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  82. enum iscsi_param param, char *buf);
  83. static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
  84. static struct iscsi_cls_conn *
  85. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
  86. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  87. struct iscsi_cls_conn *cls_conn,
  88. uint64_t transport_fd, int is_leading);
  89. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
  90. static struct iscsi_cls_session *
  91. qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
  92. uint16_t qdepth, uint32_t initial_cmdsn);
  93. static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
  94. static void qla4xxx_task_work(struct work_struct *wdata);
  95. static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
  96. static int qla4xxx_task_xmit(struct iscsi_task *);
  97. static void qla4xxx_task_cleanup(struct iscsi_task *);
  98. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
  99. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  100. struct iscsi_stats *stats);
  101. /*
  102. * SCSI host template entry points
  103. */
  104. static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  105. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
  106. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
  107. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
  108. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
  109. static int qla4xxx_slave_alloc(struct scsi_device *device);
  110. static int qla4xxx_slave_configure(struct scsi_device *device);
  111. static void qla4xxx_slave_destroy(struct scsi_device *sdev);
  112. static mode_t ql4_attr_is_visible(int param_type, int param);
  113. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
  114. static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
  115. QLA82XX_LEGACY_INTR_CONFIG;
  116. static struct scsi_host_template qla4xxx_driver_template = {
  117. .module = THIS_MODULE,
  118. .name = DRIVER_NAME,
  119. .proc_name = DRIVER_NAME,
  120. .queuecommand = qla4xxx_queuecommand,
  121. .eh_abort_handler = qla4xxx_eh_abort,
  122. .eh_device_reset_handler = qla4xxx_eh_device_reset,
  123. .eh_target_reset_handler = qla4xxx_eh_target_reset,
  124. .eh_host_reset_handler = qla4xxx_eh_host_reset,
  125. .eh_timed_out = qla4xxx_eh_cmd_timed_out,
  126. .slave_configure = qla4xxx_slave_configure,
  127. .slave_alloc = qla4xxx_slave_alloc,
  128. .slave_destroy = qla4xxx_slave_destroy,
  129. .this_id = -1,
  130. .cmd_per_lun = 3,
  131. .use_clustering = ENABLE_CLUSTERING,
  132. .sg_tablesize = SG_ALL,
  133. .max_sectors = 0xFFFF,
  134. .shost_attrs = qla4xxx_host_attrs,
  135. .host_reset = qla4xxx_host_reset,
  136. .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
  137. };
  138. static struct iscsi_transport qla4xxx_iscsi_transport = {
  139. .owner = THIS_MODULE,
  140. .name = DRIVER_NAME,
  141. .caps = CAP_TEXT_NEGO |
  142. CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
  143. CAP_DATADGST | CAP_LOGIN_OFFLOAD |
  144. CAP_MULTI_R2T,
  145. .attr_is_visible = ql4_attr_is_visible,
  146. .create_session = qla4xxx_session_create,
  147. .destroy_session = qla4xxx_session_destroy,
  148. .start_conn = qla4xxx_conn_start,
  149. .create_conn = qla4xxx_conn_create,
  150. .bind_conn = qla4xxx_conn_bind,
  151. .stop_conn = iscsi_conn_stop,
  152. .destroy_conn = qla4xxx_conn_destroy,
  153. .set_param = iscsi_set_param,
  154. .get_conn_param = qla4xxx_conn_get_param,
  155. .get_session_param = iscsi_session_get_param,
  156. .get_ep_param = qla4xxx_get_ep_param,
  157. .ep_connect = qla4xxx_ep_connect,
  158. .ep_poll = qla4xxx_ep_poll,
  159. .ep_disconnect = qla4xxx_ep_disconnect,
  160. .get_stats = qla4xxx_conn_get_stats,
  161. .send_pdu = iscsi_conn_send_pdu,
  162. .xmit_task = qla4xxx_task_xmit,
  163. .cleanup_task = qla4xxx_task_cleanup,
  164. .alloc_pdu = qla4xxx_alloc_pdu,
  165. .get_host_param = qla4xxx_host_get_param,
  166. .set_iface_param = qla4xxx_iface_set_param,
  167. .get_iface_param = qla4xxx_get_iface_param,
  168. .bsg_request = qla4xxx_bsg_request,
  169. };
  170. static struct scsi_transport_template *qla4xxx_scsi_transport;
  171. static mode_t ql4_attr_is_visible(int param_type, int param)
  172. {
  173. switch (param_type) {
  174. case ISCSI_HOST_PARAM:
  175. switch (param) {
  176. case ISCSI_HOST_PARAM_HWADDRESS:
  177. case ISCSI_HOST_PARAM_IPADDRESS:
  178. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  179. return S_IRUGO;
  180. default:
  181. return 0;
  182. }
  183. case ISCSI_PARAM:
  184. switch (param) {
  185. case ISCSI_PARAM_CONN_ADDRESS:
  186. case ISCSI_PARAM_CONN_PORT:
  187. case ISCSI_PARAM_TARGET_NAME:
  188. case ISCSI_PARAM_TPGT:
  189. case ISCSI_PARAM_TARGET_ALIAS:
  190. case ISCSI_PARAM_MAX_BURST:
  191. case ISCSI_PARAM_MAX_R2T:
  192. case ISCSI_PARAM_FIRST_BURST:
  193. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  194. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  195. case ISCSI_PARAM_IFACE_NAME:
  196. return S_IRUGO;
  197. default:
  198. return 0;
  199. }
  200. case ISCSI_NET_PARAM:
  201. switch (param) {
  202. case ISCSI_NET_PARAM_IPV4_ADDR:
  203. case ISCSI_NET_PARAM_IPV4_SUBNET:
  204. case ISCSI_NET_PARAM_IPV4_GW:
  205. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  206. case ISCSI_NET_PARAM_IFACE_ENABLE:
  207. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  208. case ISCSI_NET_PARAM_IPV6_ADDR:
  209. case ISCSI_NET_PARAM_IPV6_ROUTER:
  210. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  211. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  212. case ISCSI_NET_PARAM_VLAN_ID:
  213. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  214. case ISCSI_NET_PARAM_VLAN_ENABLED:
  215. case ISCSI_NET_PARAM_MTU:
  216. case ISCSI_NET_PARAM_PORT:
  217. return S_IRUGO;
  218. default:
  219. return 0;
  220. }
  221. }
  222. return 0;
  223. }
  224. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  225. enum iscsi_param_type param_type,
  226. int param, char *buf)
  227. {
  228. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  229. struct scsi_qla_host *ha = to_qla_host(shost);
  230. int len = -ENOSYS;
  231. if (param_type != ISCSI_NET_PARAM)
  232. return -ENOSYS;
  233. switch (param) {
  234. case ISCSI_NET_PARAM_IPV4_ADDR:
  235. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  236. break;
  237. case ISCSI_NET_PARAM_IPV4_SUBNET:
  238. len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
  239. break;
  240. case ISCSI_NET_PARAM_IPV4_GW:
  241. len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
  242. break;
  243. case ISCSI_NET_PARAM_IFACE_ENABLE:
  244. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  245. len = sprintf(buf, "%s\n",
  246. (ha->ip_config.ipv4_options &
  247. IPOPT_IPV4_PROTOCOL_ENABLE) ?
  248. "enabled" : "disabled");
  249. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  250. len = sprintf(buf, "%s\n",
  251. (ha->ip_config.ipv6_options &
  252. IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
  253. "enabled" : "disabled");
  254. break;
  255. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  256. len = sprintf(buf, "%s\n",
  257. (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
  258. "dhcp" : "static");
  259. break;
  260. case ISCSI_NET_PARAM_IPV6_ADDR:
  261. if (iface->iface_num == 0)
  262. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
  263. if (iface->iface_num == 1)
  264. len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
  265. break;
  266. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  267. len = sprintf(buf, "%pI6\n",
  268. &ha->ip_config.ipv6_link_local_addr);
  269. break;
  270. case ISCSI_NET_PARAM_IPV6_ROUTER:
  271. len = sprintf(buf, "%pI6\n",
  272. &ha->ip_config.ipv6_default_router_addr);
  273. break;
  274. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  275. len = sprintf(buf, "%s\n",
  276. (ha->ip_config.ipv6_addl_options &
  277. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
  278. "nd" : "static");
  279. break;
  280. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  281. len = sprintf(buf, "%s\n",
  282. (ha->ip_config.ipv6_addl_options &
  283. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
  284. "auto" : "static");
  285. break;
  286. case ISCSI_NET_PARAM_VLAN_ID:
  287. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  288. len = sprintf(buf, "%d\n",
  289. (ha->ip_config.ipv4_vlan_tag &
  290. ISCSI_MAX_VLAN_ID));
  291. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  292. len = sprintf(buf, "%d\n",
  293. (ha->ip_config.ipv6_vlan_tag &
  294. ISCSI_MAX_VLAN_ID));
  295. break;
  296. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  297. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  298. len = sprintf(buf, "%d\n",
  299. ((ha->ip_config.ipv4_vlan_tag >> 13) &
  300. ISCSI_MAX_VLAN_PRIORITY));
  301. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  302. len = sprintf(buf, "%d\n",
  303. ((ha->ip_config.ipv6_vlan_tag >> 13) &
  304. ISCSI_MAX_VLAN_PRIORITY));
  305. break;
  306. case ISCSI_NET_PARAM_VLAN_ENABLED:
  307. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  308. len = sprintf(buf, "%s\n",
  309. (ha->ip_config.ipv4_options &
  310. IPOPT_VLAN_TAGGING_ENABLE) ?
  311. "enabled" : "disabled");
  312. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  313. len = sprintf(buf, "%s\n",
  314. (ha->ip_config.ipv6_options &
  315. IPV6_OPT_VLAN_TAGGING_ENABLE) ?
  316. "enabled" : "disabled");
  317. break;
  318. case ISCSI_NET_PARAM_MTU:
  319. len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
  320. break;
  321. case ISCSI_NET_PARAM_PORT:
  322. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  323. len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
  324. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  325. len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
  326. break;
  327. default:
  328. len = -ENOSYS;
  329. }
  330. return len;
  331. }
  332. static struct iscsi_endpoint *
  333. qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  334. int non_blocking)
  335. {
  336. int ret;
  337. struct iscsi_endpoint *ep;
  338. struct qla_endpoint *qla_ep;
  339. struct scsi_qla_host *ha;
  340. struct sockaddr_in *addr;
  341. struct sockaddr_in6 *addr6;
  342. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  343. if (!shost) {
  344. ret = -ENXIO;
  345. printk(KERN_ERR "%s: shost is NULL\n",
  346. __func__);
  347. return ERR_PTR(ret);
  348. }
  349. ha = iscsi_host_priv(shost);
  350. ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
  351. if (!ep) {
  352. ret = -ENOMEM;
  353. return ERR_PTR(ret);
  354. }
  355. qla_ep = ep->dd_data;
  356. memset(qla_ep, 0, sizeof(struct qla_endpoint));
  357. if (dst_addr->sa_family == AF_INET) {
  358. memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
  359. addr = (struct sockaddr_in *)&qla_ep->dst_addr;
  360. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
  361. (char *)&addr->sin_addr));
  362. } else if (dst_addr->sa_family == AF_INET6) {
  363. memcpy(&qla_ep->dst_addr, dst_addr,
  364. sizeof(struct sockaddr_in6));
  365. addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
  366. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
  367. (char *)&addr6->sin6_addr));
  368. }
  369. qla_ep->host = shost;
  370. return ep;
  371. }
  372. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  373. {
  374. struct qla_endpoint *qla_ep;
  375. struct scsi_qla_host *ha;
  376. int ret = 0;
  377. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  378. qla_ep = ep->dd_data;
  379. ha = to_qla_host(qla_ep->host);
  380. if (adapter_up(ha))
  381. ret = 1;
  382. return ret;
  383. }
  384. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
  385. {
  386. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  387. iscsi_destroy_endpoint(ep);
  388. }
  389. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  390. enum iscsi_param param,
  391. char *buf)
  392. {
  393. struct qla_endpoint *qla_ep = ep->dd_data;
  394. struct sockaddr *dst_addr;
  395. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  396. switch (param) {
  397. case ISCSI_PARAM_CONN_PORT:
  398. case ISCSI_PARAM_CONN_ADDRESS:
  399. if (!qla_ep)
  400. return -ENOTCONN;
  401. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  402. if (!dst_addr)
  403. return -ENOTCONN;
  404. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  405. &qla_ep->dst_addr, param, buf);
  406. default:
  407. return -ENOSYS;
  408. }
  409. }
  410. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  411. struct iscsi_stats *stats)
  412. {
  413. struct iscsi_session *sess;
  414. struct iscsi_cls_session *cls_sess;
  415. struct ddb_entry *ddb_entry;
  416. struct scsi_qla_host *ha;
  417. struct ql_iscsi_stats *ql_iscsi_stats;
  418. int stats_size;
  419. int ret;
  420. dma_addr_t iscsi_stats_dma;
  421. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  422. cls_sess = iscsi_conn_to_session(cls_conn);
  423. sess = cls_sess->dd_data;
  424. ddb_entry = sess->dd_data;
  425. ha = ddb_entry->ha;
  426. stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
  427. /* Allocate memory */
  428. ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
  429. &iscsi_stats_dma, GFP_KERNEL);
  430. if (!ql_iscsi_stats) {
  431. ql4_printk(KERN_ERR, ha,
  432. "Unable to allocate memory for iscsi stats\n");
  433. goto exit_get_stats;
  434. }
  435. ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
  436. iscsi_stats_dma);
  437. if (ret != QLA_SUCCESS) {
  438. ql4_printk(KERN_ERR, ha,
  439. "Unable to retreive iscsi stats\n");
  440. goto free_stats;
  441. }
  442. /* octets */
  443. stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
  444. stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
  445. /* xmit pdus */
  446. stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
  447. stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
  448. stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
  449. stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
  450. stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
  451. stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
  452. stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
  453. stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
  454. /* recv pdus */
  455. stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
  456. stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
  457. stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
  458. stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
  459. stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
  460. stats->logoutrsp_pdus =
  461. le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
  462. stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
  463. stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
  464. stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
  465. free_stats:
  466. dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
  467. iscsi_stats_dma);
  468. exit_get_stats:
  469. return;
  470. }
  471. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
  472. {
  473. struct iscsi_cls_session *session;
  474. struct iscsi_session *sess;
  475. unsigned long flags;
  476. enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
  477. session = starget_to_session(scsi_target(sc->device));
  478. sess = session->dd_data;
  479. spin_lock_irqsave(&session->lock, flags);
  480. if (session->state == ISCSI_SESSION_FAILED)
  481. ret = BLK_EH_RESET_TIMER;
  482. spin_unlock_irqrestore(&session->lock, flags);
  483. return ret;
  484. }
  485. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  486. enum iscsi_host_param param, char *buf)
  487. {
  488. struct scsi_qla_host *ha = to_qla_host(shost);
  489. int len;
  490. switch (param) {
  491. case ISCSI_HOST_PARAM_HWADDRESS:
  492. len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
  493. break;
  494. case ISCSI_HOST_PARAM_IPADDRESS:
  495. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  496. break;
  497. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  498. len = sprintf(buf, "%s\n", ha->name_string);
  499. break;
  500. default:
  501. return -ENOSYS;
  502. }
  503. return len;
  504. }
  505. static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
  506. {
  507. if (ha->iface_ipv4)
  508. return;
  509. /* IPv4 */
  510. ha->iface_ipv4 = iscsi_create_iface(ha->host,
  511. &qla4xxx_iscsi_transport,
  512. ISCSI_IFACE_TYPE_IPV4, 0, 0);
  513. if (!ha->iface_ipv4)
  514. ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
  515. "iface0.\n");
  516. }
  517. static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
  518. {
  519. if (!ha->iface_ipv6_0)
  520. /* IPv6 iface-0 */
  521. ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
  522. &qla4xxx_iscsi_transport,
  523. ISCSI_IFACE_TYPE_IPV6, 0,
  524. 0);
  525. if (!ha->iface_ipv6_0)
  526. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  527. "iface0.\n");
  528. if (!ha->iface_ipv6_1)
  529. /* IPv6 iface-1 */
  530. ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
  531. &qla4xxx_iscsi_transport,
  532. ISCSI_IFACE_TYPE_IPV6, 1,
  533. 0);
  534. if (!ha->iface_ipv6_1)
  535. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  536. "iface1.\n");
  537. }
  538. static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
  539. {
  540. if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
  541. qla4xxx_create_ipv4_iface(ha);
  542. if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
  543. qla4xxx_create_ipv6_iface(ha);
  544. }
  545. static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
  546. {
  547. if (ha->iface_ipv4) {
  548. iscsi_destroy_iface(ha->iface_ipv4);
  549. ha->iface_ipv4 = NULL;
  550. }
  551. }
  552. static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
  553. {
  554. if (ha->iface_ipv6_0) {
  555. iscsi_destroy_iface(ha->iface_ipv6_0);
  556. ha->iface_ipv6_0 = NULL;
  557. }
  558. if (ha->iface_ipv6_1) {
  559. iscsi_destroy_iface(ha->iface_ipv6_1);
  560. ha->iface_ipv6_1 = NULL;
  561. }
  562. }
  563. static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
  564. {
  565. qla4xxx_destroy_ipv4_iface(ha);
  566. qla4xxx_destroy_ipv6_iface(ha);
  567. }
  568. static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
  569. struct iscsi_iface_param_info *iface_param,
  570. struct addr_ctrl_blk *init_fw_cb)
  571. {
  572. /*
  573. * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
  574. * iface_num 1 is valid only for IPv6 Addr.
  575. */
  576. switch (iface_param->param) {
  577. case ISCSI_NET_PARAM_IPV6_ADDR:
  578. if (iface_param->iface_num & 0x1)
  579. /* IPv6 Addr 1 */
  580. memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
  581. sizeof(init_fw_cb->ipv6_addr1));
  582. else
  583. /* IPv6 Addr 0 */
  584. memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
  585. sizeof(init_fw_cb->ipv6_addr0));
  586. break;
  587. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  588. if (iface_param->iface_num & 0x1)
  589. break;
  590. memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
  591. sizeof(init_fw_cb->ipv6_if_id));
  592. break;
  593. case ISCSI_NET_PARAM_IPV6_ROUTER:
  594. if (iface_param->iface_num & 0x1)
  595. break;
  596. memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
  597. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  598. break;
  599. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  600. /* Autocfg applies to even interface */
  601. if (iface_param->iface_num & 0x1)
  602. break;
  603. if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
  604. init_fw_cb->ipv6_addtl_opts &=
  605. cpu_to_le16(
  606. ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  607. else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
  608. init_fw_cb->ipv6_addtl_opts |=
  609. cpu_to_le16(
  610. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  611. else
  612. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  613. "IPv6 addr\n");
  614. break;
  615. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  616. /* Autocfg applies to even interface */
  617. if (iface_param->iface_num & 0x1)
  618. break;
  619. if (iface_param->value[0] ==
  620. ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
  621. init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
  622. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  623. else if (iface_param->value[0] ==
  624. ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
  625. init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
  626. ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  627. else
  628. ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
  629. "IPv6 linklocal addr\n");
  630. break;
  631. case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
  632. /* Autocfg applies to even interface */
  633. if (iface_param->iface_num & 0x1)
  634. break;
  635. if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
  636. memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
  637. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  638. break;
  639. case ISCSI_NET_PARAM_IFACE_ENABLE:
  640. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  641. init_fw_cb->ipv6_opts |=
  642. cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
  643. qla4xxx_create_ipv6_iface(ha);
  644. } else {
  645. init_fw_cb->ipv6_opts &=
  646. cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
  647. 0xFFFF);
  648. qla4xxx_destroy_ipv6_iface(ha);
  649. }
  650. break;
  651. case ISCSI_NET_PARAM_VLAN_TAG:
  652. if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
  653. break;
  654. init_fw_cb->ipv6_vlan_tag =
  655. cpu_to_be16(*(uint16_t *)iface_param->value);
  656. break;
  657. case ISCSI_NET_PARAM_VLAN_ENABLED:
  658. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  659. init_fw_cb->ipv6_opts |=
  660. cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
  661. else
  662. init_fw_cb->ipv6_opts &=
  663. cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
  664. break;
  665. case ISCSI_NET_PARAM_MTU:
  666. init_fw_cb->eth_mtu_size =
  667. cpu_to_le16(*(uint16_t *)iface_param->value);
  668. break;
  669. case ISCSI_NET_PARAM_PORT:
  670. /* Autocfg applies to even interface */
  671. if (iface_param->iface_num & 0x1)
  672. break;
  673. init_fw_cb->ipv6_port =
  674. cpu_to_le16(*(uint16_t *)iface_param->value);
  675. break;
  676. default:
  677. ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
  678. iface_param->param);
  679. break;
  680. }
  681. }
  682. static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
  683. struct iscsi_iface_param_info *iface_param,
  684. struct addr_ctrl_blk *init_fw_cb)
  685. {
  686. switch (iface_param->param) {
  687. case ISCSI_NET_PARAM_IPV4_ADDR:
  688. memcpy(init_fw_cb->ipv4_addr, iface_param->value,
  689. sizeof(init_fw_cb->ipv4_addr));
  690. break;
  691. case ISCSI_NET_PARAM_IPV4_SUBNET:
  692. memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
  693. sizeof(init_fw_cb->ipv4_subnet));
  694. break;
  695. case ISCSI_NET_PARAM_IPV4_GW:
  696. memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
  697. sizeof(init_fw_cb->ipv4_gw_addr));
  698. break;
  699. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  700. if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
  701. init_fw_cb->ipv4_tcp_opts |=
  702. cpu_to_le16(TCPOPT_DHCP_ENABLE);
  703. else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
  704. init_fw_cb->ipv4_tcp_opts &=
  705. cpu_to_le16(~TCPOPT_DHCP_ENABLE);
  706. else
  707. ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
  708. break;
  709. case ISCSI_NET_PARAM_IFACE_ENABLE:
  710. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  711. init_fw_cb->ipv4_ip_opts |=
  712. cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
  713. qla4xxx_create_ipv4_iface(ha);
  714. } else {
  715. init_fw_cb->ipv4_ip_opts &=
  716. cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
  717. 0xFFFF);
  718. qla4xxx_destroy_ipv4_iface(ha);
  719. }
  720. break;
  721. case ISCSI_NET_PARAM_VLAN_TAG:
  722. if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
  723. break;
  724. init_fw_cb->ipv4_vlan_tag =
  725. cpu_to_be16(*(uint16_t *)iface_param->value);
  726. break;
  727. case ISCSI_NET_PARAM_VLAN_ENABLED:
  728. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  729. init_fw_cb->ipv4_ip_opts |=
  730. cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
  731. else
  732. init_fw_cb->ipv4_ip_opts &=
  733. cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
  734. break;
  735. case ISCSI_NET_PARAM_MTU:
  736. init_fw_cb->eth_mtu_size =
  737. cpu_to_le16(*(uint16_t *)iface_param->value);
  738. break;
  739. case ISCSI_NET_PARAM_PORT:
  740. init_fw_cb->ipv4_port =
  741. cpu_to_le16(*(uint16_t *)iface_param->value);
  742. break;
  743. default:
  744. ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
  745. iface_param->param);
  746. break;
  747. }
  748. }
  749. static void
  750. qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
  751. {
  752. struct addr_ctrl_blk_def *acb;
  753. acb = (struct addr_ctrl_blk_def *)init_fw_cb;
  754. memset(acb->reserved1, 0, sizeof(acb->reserved1));
  755. memset(acb->reserved2, 0, sizeof(acb->reserved2));
  756. memset(acb->reserved3, 0, sizeof(acb->reserved3));
  757. memset(acb->reserved4, 0, sizeof(acb->reserved4));
  758. memset(acb->reserved5, 0, sizeof(acb->reserved5));
  759. memset(acb->reserved6, 0, sizeof(acb->reserved6));
  760. memset(acb->reserved7, 0, sizeof(acb->reserved7));
  761. memset(acb->reserved8, 0, sizeof(acb->reserved8));
  762. memset(acb->reserved9, 0, sizeof(acb->reserved9));
  763. memset(acb->reserved10, 0, sizeof(acb->reserved10));
  764. memset(acb->reserved11, 0, sizeof(acb->reserved11));
  765. memset(acb->reserved12, 0, sizeof(acb->reserved12));
  766. memset(acb->reserved13, 0, sizeof(acb->reserved13));
  767. memset(acb->reserved14, 0, sizeof(acb->reserved14));
  768. memset(acb->reserved15, 0, sizeof(acb->reserved15));
  769. }
  770. static int
  771. qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
  772. {
  773. struct scsi_qla_host *ha = to_qla_host(shost);
  774. int rval = 0;
  775. struct iscsi_iface_param_info *iface_param = NULL;
  776. struct addr_ctrl_blk *init_fw_cb = NULL;
  777. dma_addr_t init_fw_cb_dma;
  778. uint32_t mbox_cmd[MBOX_REG_COUNT];
  779. uint32_t mbox_sts[MBOX_REG_COUNT];
  780. uint32_t rem = len;
  781. struct nlattr *attr;
  782. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  783. sizeof(struct addr_ctrl_blk),
  784. &init_fw_cb_dma, GFP_KERNEL);
  785. if (!init_fw_cb) {
  786. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
  787. __func__);
  788. return -ENOMEM;
  789. }
  790. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  791. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  792. memset(&mbox_sts, 0, sizeof(mbox_sts));
  793. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
  794. ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
  795. rval = -EIO;
  796. goto exit_init_fw_cb;
  797. }
  798. nla_for_each_attr(attr, data, len, rem) {
  799. iface_param = nla_data(attr);
  800. if (iface_param->param_type != ISCSI_NET_PARAM)
  801. continue;
  802. switch (iface_param->iface_type) {
  803. case ISCSI_IFACE_TYPE_IPV4:
  804. switch (iface_param->iface_num) {
  805. case 0:
  806. qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
  807. break;
  808. default:
  809. /* Cannot have more than one IPv4 interface */
  810. ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
  811. "number = %d\n",
  812. iface_param->iface_num);
  813. break;
  814. }
  815. break;
  816. case ISCSI_IFACE_TYPE_IPV6:
  817. switch (iface_param->iface_num) {
  818. case 0:
  819. case 1:
  820. qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
  821. break;
  822. default:
  823. /* Cannot have more than two IPv6 interface */
  824. ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
  825. "number = %d\n",
  826. iface_param->iface_num);
  827. break;
  828. }
  829. break;
  830. default:
  831. ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
  832. break;
  833. }
  834. }
  835. init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
  836. rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
  837. sizeof(struct addr_ctrl_blk),
  838. FLASH_OPT_RMW_COMMIT);
  839. if (rval != QLA_SUCCESS) {
  840. ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
  841. __func__);
  842. rval = -EIO;
  843. goto exit_init_fw_cb;
  844. }
  845. qla4xxx_disable_acb(ha);
  846. qla4xxx_initcb_to_acb(init_fw_cb);
  847. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
  848. if (rval != QLA_SUCCESS) {
  849. ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
  850. __func__);
  851. rval = -EIO;
  852. goto exit_init_fw_cb;
  853. }
  854. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  855. qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
  856. init_fw_cb_dma);
  857. exit_init_fw_cb:
  858. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  859. init_fw_cb, init_fw_cb_dma);
  860. return rval;
  861. }
  862. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
  863. enum iscsi_param param, char *buf)
  864. {
  865. struct iscsi_conn *conn;
  866. struct qla_conn *qla_conn;
  867. struct sockaddr *dst_addr;
  868. int len = 0;
  869. conn = cls_conn->dd_data;
  870. qla_conn = conn->dd_data;
  871. dst_addr = &qla_conn->qla_ep->dst_addr;
  872. switch (param) {
  873. case ISCSI_PARAM_CONN_PORT:
  874. case ISCSI_PARAM_CONN_ADDRESS:
  875. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  876. dst_addr, param, buf);
  877. default:
  878. return iscsi_conn_get_param(cls_conn, param, buf);
  879. }
  880. return len;
  881. }
  882. static struct iscsi_cls_session *
  883. qla4xxx_session_create(struct iscsi_endpoint *ep,
  884. uint16_t cmds_max, uint16_t qdepth,
  885. uint32_t initial_cmdsn)
  886. {
  887. struct iscsi_cls_session *cls_sess;
  888. struct scsi_qla_host *ha;
  889. struct qla_endpoint *qla_ep;
  890. struct ddb_entry *ddb_entry;
  891. uint32_t ddb_index;
  892. uint32_t mbx_sts = 0;
  893. struct iscsi_session *sess;
  894. struct sockaddr *dst_addr;
  895. int ret;
  896. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  897. if (!ep) {
  898. printk(KERN_ERR "qla4xxx: missing ep.\n");
  899. return NULL;
  900. }
  901. qla_ep = ep->dd_data;
  902. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  903. ha = to_qla_host(qla_ep->host);
  904. get_ddb_index:
  905. ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
  906. if (ddb_index >= MAX_DDB_ENTRIES) {
  907. DEBUG2(ql4_printk(KERN_INFO, ha,
  908. "Free DDB index not available\n"));
  909. return NULL;
  910. }
  911. if (test_and_set_bit(ddb_index, ha->ddb_idx_map))
  912. goto get_ddb_index;
  913. DEBUG2(ql4_printk(KERN_INFO, ha,
  914. "Found a free DDB index at %d\n", ddb_index));
  915. ret = qla4xxx_req_ddb_entry(ha, ddb_index, &mbx_sts);
  916. if (ret == QLA_ERROR) {
  917. if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
  918. ql4_printk(KERN_INFO, ha,
  919. "DDB index = %d not available trying next\n",
  920. ddb_index);
  921. goto get_ddb_index;
  922. }
  923. DEBUG2(ql4_printk(KERN_INFO, ha,
  924. "Free FW DDB not available\n"));
  925. return NULL;
  926. }
  927. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
  928. cmds_max, sizeof(struct ddb_entry),
  929. sizeof(struct ql4_task_data),
  930. initial_cmdsn, ddb_index);
  931. if (!cls_sess)
  932. return NULL;
  933. sess = cls_sess->dd_data;
  934. ddb_entry = sess->dd_data;
  935. ddb_entry->fw_ddb_index = ddb_index;
  936. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  937. ddb_entry->ha = ha;
  938. ddb_entry->sess = cls_sess;
  939. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  940. ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
  941. ha->tot_ddbs++;
  942. return cls_sess;
  943. }
  944. static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
  945. {
  946. struct iscsi_session *sess;
  947. struct ddb_entry *ddb_entry;
  948. struct scsi_qla_host *ha;
  949. unsigned long flags;
  950. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  951. sess = cls_sess->dd_data;
  952. ddb_entry = sess->dd_data;
  953. ha = ddb_entry->ha;
  954. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  955. spin_lock_irqsave(&ha->hardware_lock, flags);
  956. qla4xxx_free_ddb(ha, ddb_entry);
  957. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  958. iscsi_session_teardown(cls_sess);
  959. }
  960. static struct iscsi_cls_conn *
  961. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
  962. {
  963. struct iscsi_cls_conn *cls_conn;
  964. struct iscsi_session *sess;
  965. struct ddb_entry *ddb_entry;
  966. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  967. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
  968. conn_idx);
  969. sess = cls_sess->dd_data;
  970. ddb_entry = sess->dd_data;
  971. ddb_entry->conn = cls_conn;
  972. return cls_conn;
  973. }
  974. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  975. struct iscsi_cls_conn *cls_conn,
  976. uint64_t transport_fd, int is_leading)
  977. {
  978. struct iscsi_conn *conn;
  979. struct qla_conn *qla_conn;
  980. struct iscsi_endpoint *ep;
  981. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  982. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  983. return -EINVAL;
  984. ep = iscsi_lookup_endpoint(transport_fd);
  985. conn = cls_conn->dd_data;
  986. qla_conn = conn->dd_data;
  987. qla_conn->qla_ep = ep->dd_data;
  988. return 0;
  989. }
  990. static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
  991. {
  992. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  993. struct iscsi_session *sess;
  994. struct ddb_entry *ddb_entry;
  995. struct scsi_qla_host *ha;
  996. struct dev_db_entry *fw_ddb_entry;
  997. dma_addr_t fw_ddb_entry_dma;
  998. uint32_t mbx_sts = 0;
  999. int ret = 0;
  1000. int status = QLA_SUCCESS;
  1001. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1002. sess = cls_sess->dd_data;
  1003. ddb_entry = sess->dd_data;
  1004. ha = ddb_entry->ha;
  1005. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1006. &fw_ddb_entry_dma, GFP_KERNEL);
  1007. if (!fw_ddb_entry) {
  1008. ql4_printk(KERN_ERR, ha,
  1009. "%s: Unable to allocate dma buffer\n", __func__);
  1010. return -ENOMEM;
  1011. }
  1012. ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
  1013. if (ret) {
  1014. /* If iscsid is stopped and started then no need to do
  1015. * set param again since ddb state will be already
  1016. * active and FW does not allow set ddb to an
  1017. * active session.
  1018. */
  1019. if (mbx_sts)
  1020. if (ddb_entry->fw_ddb_device_state ==
  1021. DDB_DS_SESSION_ACTIVE) {
  1022. iscsi_conn_start(ddb_entry->conn);
  1023. iscsi_conn_login_event(ddb_entry->conn,
  1024. ISCSI_CONN_STATE_LOGGED_IN);
  1025. goto exit_set_param;
  1026. }
  1027. ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
  1028. __func__, ddb_entry->fw_ddb_index);
  1029. goto exit_conn_start;
  1030. }
  1031. status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
  1032. if (status == QLA_ERROR) {
  1033. ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
  1034. sess->targetname);
  1035. ret = -EINVAL;
  1036. goto exit_conn_start;
  1037. }
  1038. if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
  1039. ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
  1040. DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
  1041. ddb_entry->fw_ddb_device_state));
  1042. exit_set_param:
  1043. ret = 0;
  1044. exit_conn_start:
  1045. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1046. fw_ddb_entry, fw_ddb_entry_dma);
  1047. return ret;
  1048. }
  1049. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
  1050. {
  1051. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  1052. struct iscsi_session *sess;
  1053. struct scsi_qla_host *ha;
  1054. struct ddb_entry *ddb_entry;
  1055. int options;
  1056. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  1057. sess = cls_sess->dd_data;
  1058. ddb_entry = sess->dd_data;
  1059. ha = ddb_entry->ha;
  1060. options = LOGOUT_OPTION_CLOSE_SESSION;
  1061. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
  1062. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
  1063. }
  1064. static void qla4xxx_task_work(struct work_struct *wdata)
  1065. {
  1066. struct ql4_task_data *task_data;
  1067. struct scsi_qla_host *ha;
  1068. struct passthru_status *sts;
  1069. struct iscsi_task *task;
  1070. struct iscsi_hdr *hdr;
  1071. uint8_t *data;
  1072. uint32_t data_len;
  1073. struct iscsi_conn *conn;
  1074. int hdr_len;
  1075. itt_t itt;
  1076. task_data = container_of(wdata, struct ql4_task_data, task_work);
  1077. ha = task_data->ha;
  1078. task = task_data->task;
  1079. sts = &task_data->sts;
  1080. hdr_len = sizeof(struct iscsi_hdr);
  1081. DEBUG3(printk(KERN_INFO "Status returned\n"));
  1082. DEBUG3(qla4xxx_dump_buffer(sts, 64));
  1083. DEBUG3(printk(KERN_INFO "Response buffer"));
  1084. DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
  1085. conn = task->conn;
  1086. switch (sts->completionStatus) {
  1087. case PASSTHRU_STATUS_COMPLETE:
  1088. hdr = (struct iscsi_hdr *)task_data->resp_buffer;
  1089. /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
  1090. itt = sts->handle;
  1091. hdr->itt = itt;
  1092. data = task_data->resp_buffer + hdr_len;
  1093. data_len = task_data->resp_len - hdr_len;
  1094. iscsi_complete_pdu(conn, hdr, data, data_len);
  1095. break;
  1096. default:
  1097. ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
  1098. sts->completionStatus);
  1099. break;
  1100. }
  1101. return;
  1102. }
  1103. static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  1104. {
  1105. struct ql4_task_data *task_data;
  1106. struct iscsi_session *sess;
  1107. struct ddb_entry *ddb_entry;
  1108. struct scsi_qla_host *ha;
  1109. int hdr_len;
  1110. sess = task->conn->session;
  1111. ddb_entry = sess->dd_data;
  1112. ha = ddb_entry->ha;
  1113. task_data = task->dd_data;
  1114. memset(task_data, 0, sizeof(struct ql4_task_data));
  1115. if (task->sc) {
  1116. ql4_printk(KERN_INFO, ha,
  1117. "%s: SCSI Commands not implemented\n", __func__);
  1118. return -EINVAL;
  1119. }
  1120. hdr_len = sizeof(struct iscsi_hdr);
  1121. task_data->ha = ha;
  1122. task_data->task = task;
  1123. if (task->data_count) {
  1124. task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
  1125. task->data_count,
  1126. PCI_DMA_TODEVICE);
  1127. }
  1128. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1129. __func__, task->conn->max_recv_dlength, hdr_len));
  1130. task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
  1131. task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1132. task_data->resp_len,
  1133. &task_data->resp_dma,
  1134. GFP_ATOMIC);
  1135. if (!task_data->resp_buffer)
  1136. goto exit_alloc_pdu;
  1137. task_data->req_len = task->data_count + hdr_len;
  1138. task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
  1139. task_data->req_len,
  1140. &task_data->req_dma,
  1141. GFP_ATOMIC);
  1142. if (!task_data->req_buffer)
  1143. goto exit_alloc_pdu;
  1144. task->hdr = task_data->req_buffer;
  1145. INIT_WORK(&task_data->task_work, qla4xxx_task_work);
  1146. return 0;
  1147. exit_alloc_pdu:
  1148. if (task_data->resp_buffer)
  1149. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1150. task_data->resp_buffer, task_data->resp_dma);
  1151. if (task_data->req_buffer)
  1152. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  1153. task_data->req_buffer, task_data->req_dma);
  1154. return -ENOMEM;
  1155. }
  1156. static void qla4xxx_task_cleanup(struct iscsi_task *task)
  1157. {
  1158. struct ql4_task_data *task_data;
  1159. struct iscsi_session *sess;
  1160. struct ddb_entry *ddb_entry;
  1161. struct scsi_qla_host *ha;
  1162. int hdr_len;
  1163. hdr_len = sizeof(struct iscsi_hdr);
  1164. sess = task->conn->session;
  1165. ddb_entry = sess->dd_data;
  1166. ha = ddb_entry->ha;
  1167. task_data = task->dd_data;
  1168. if (task->data_count) {
  1169. dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
  1170. task->data_count, PCI_DMA_TODEVICE);
  1171. }
  1172. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  1173. __func__, task->conn->max_recv_dlength, hdr_len));
  1174. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  1175. task_data->resp_buffer, task_data->resp_dma);
  1176. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  1177. task_data->req_buffer, task_data->req_dma);
  1178. return;
  1179. }
  1180. static int qla4xxx_task_xmit(struct iscsi_task *task)
  1181. {
  1182. struct scsi_cmnd *sc = task->sc;
  1183. struct iscsi_session *sess = task->conn->session;
  1184. struct ddb_entry *ddb_entry = sess->dd_data;
  1185. struct scsi_qla_host *ha = ddb_entry->ha;
  1186. if (!sc)
  1187. return qla4xxx_send_passthru0(task);
  1188. ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
  1189. __func__);
  1190. return -ENOSYS;
  1191. }
  1192. void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
  1193. struct ddb_entry *ddb_entry)
  1194. {
  1195. struct iscsi_cls_session *cls_sess;
  1196. struct iscsi_cls_conn *cls_conn;
  1197. struct iscsi_session *sess;
  1198. struct iscsi_conn *conn;
  1199. uint32_t ddb_state;
  1200. dma_addr_t fw_ddb_entry_dma;
  1201. struct dev_db_entry *fw_ddb_entry;
  1202. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  1203. &fw_ddb_entry_dma, GFP_KERNEL);
  1204. if (!fw_ddb_entry) {
  1205. ql4_printk(KERN_ERR, ha,
  1206. "%s: Unable to allocate dma buffer\n", __func__);
  1207. return;
  1208. }
  1209. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  1210. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  1211. NULL, NULL, NULL) == QLA_ERROR) {
  1212. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  1213. "get_ddb_entry for fw_ddb_index %d\n",
  1214. ha->host_no, __func__,
  1215. ddb_entry->fw_ddb_index));
  1216. return;
  1217. }
  1218. cls_sess = ddb_entry->sess;
  1219. sess = cls_sess->dd_data;
  1220. cls_conn = ddb_entry->conn;
  1221. conn = cls_conn->dd_data;
  1222. /* Update params */
  1223. conn->max_recv_dlength = BYTE_UNITS *
  1224. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  1225. conn->max_xmit_dlength = BYTE_UNITS *
  1226. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  1227. sess->initial_r2t_en =
  1228. (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1229. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  1230. sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
  1231. sess->first_burst = BYTE_UNITS *
  1232. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  1233. sess->max_burst = BYTE_UNITS *
  1234. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  1235. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  1236. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  1237. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  1238. memcpy(sess->initiatorname, ha->name_string,
  1239. min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
  1240. }
  1241. /*
  1242. * Timer routines
  1243. */
  1244. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  1245. unsigned long interval)
  1246. {
  1247. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  1248. __func__, ha->host->host_no));
  1249. init_timer(&ha->timer);
  1250. ha->timer.expires = jiffies + interval * HZ;
  1251. ha->timer.data = (unsigned long)ha;
  1252. ha->timer.function = (void (*)(unsigned long))func;
  1253. add_timer(&ha->timer);
  1254. ha->timer_active = 1;
  1255. }
  1256. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  1257. {
  1258. del_timer_sync(&ha->timer);
  1259. ha->timer_active = 0;
  1260. }
  1261. /***
  1262. * qla4xxx_mark_device_missing - blocks the session
  1263. * @cls_session: Pointer to the session to be blocked
  1264. * @ddb_entry: Pointer to device database entry
  1265. *
  1266. * This routine marks a device missing and close connection.
  1267. **/
  1268. void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
  1269. {
  1270. iscsi_block_session(cls_session);
  1271. }
  1272. /**
  1273. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  1274. * @ha: Pointer to host adapter structure.
  1275. *
  1276. * This routine marks a device missing and resets the relogin retry count.
  1277. **/
  1278. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  1279. {
  1280. iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
  1281. }
  1282. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  1283. struct ddb_entry *ddb_entry,
  1284. struct scsi_cmnd *cmd)
  1285. {
  1286. struct srb *srb;
  1287. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  1288. if (!srb)
  1289. return srb;
  1290. kref_init(&srb->srb_ref);
  1291. srb->ha = ha;
  1292. srb->ddb = ddb_entry;
  1293. srb->cmd = cmd;
  1294. srb->flags = 0;
  1295. CMD_SP(cmd) = (void *)srb;
  1296. return srb;
  1297. }
  1298. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  1299. {
  1300. struct scsi_cmnd *cmd = srb->cmd;
  1301. if (srb->flags & SRB_DMA_VALID) {
  1302. scsi_dma_unmap(cmd);
  1303. srb->flags &= ~SRB_DMA_VALID;
  1304. }
  1305. CMD_SP(cmd) = NULL;
  1306. }
  1307. void qla4xxx_srb_compl(struct kref *ref)
  1308. {
  1309. struct srb *srb = container_of(ref, struct srb, srb_ref);
  1310. struct scsi_cmnd *cmd = srb->cmd;
  1311. struct scsi_qla_host *ha = srb->ha;
  1312. qla4xxx_srb_free_dma(ha, srb);
  1313. mempool_free(srb, ha->srb_mempool);
  1314. cmd->scsi_done(cmd);
  1315. }
  1316. /**
  1317. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  1318. * @host: scsi host
  1319. * @cmd: Pointer to Linux's SCSI command structure
  1320. *
  1321. * Remarks:
  1322. * This routine is invoked by Linux to send a SCSI command to the driver.
  1323. * The mid-level driver tries to ensure that queuecommand never gets
  1324. * invoked concurrently with itself or the interrupt handler (although
  1325. * the interrupt handler may call this routine as part of request-
  1326. * completion handling). Unfortunely, it sometimes calls the scheduler
  1327. * in interrupt context which is a big NO! NO!.
  1328. **/
  1329. static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  1330. {
  1331. struct scsi_qla_host *ha = to_qla_host(host);
  1332. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  1333. struct iscsi_cls_session *sess = ddb_entry->sess;
  1334. struct srb *srb;
  1335. int rval;
  1336. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  1337. if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  1338. cmd->result = DID_NO_CONNECT << 16;
  1339. else
  1340. cmd->result = DID_REQUEUE << 16;
  1341. goto qc_fail_command;
  1342. }
  1343. if (!sess) {
  1344. cmd->result = DID_IMM_RETRY << 16;
  1345. goto qc_fail_command;
  1346. }
  1347. rval = iscsi_session_chkready(sess);
  1348. if (rval) {
  1349. cmd->result = rval;
  1350. goto qc_fail_command;
  1351. }
  1352. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  1353. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  1354. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1355. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  1356. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  1357. !test_bit(AF_ONLINE, &ha->flags) ||
  1358. !test_bit(AF_LINK_UP, &ha->flags) ||
  1359. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  1360. goto qc_host_busy;
  1361. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
  1362. if (!srb)
  1363. goto qc_host_busy;
  1364. rval = qla4xxx_send_command_to_isp(ha, srb);
  1365. if (rval != QLA_SUCCESS)
  1366. goto qc_host_busy_free_sp;
  1367. return 0;
  1368. qc_host_busy_free_sp:
  1369. qla4xxx_srb_free_dma(ha, srb);
  1370. mempool_free(srb, ha->srb_mempool);
  1371. qc_host_busy:
  1372. return SCSI_MLQUEUE_HOST_BUSY;
  1373. qc_fail_command:
  1374. cmd->scsi_done(cmd);
  1375. return 0;
  1376. }
  1377. /**
  1378. * qla4xxx_mem_free - frees memory allocated to adapter
  1379. * @ha: Pointer to host adapter structure.
  1380. *
  1381. * Frees memory previously allocated by qla4xxx_mem_alloc
  1382. **/
  1383. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  1384. {
  1385. if (ha->queues)
  1386. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  1387. ha->queues_dma);
  1388. ha->queues_len = 0;
  1389. ha->queues = NULL;
  1390. ha->queues_dma = 0;
  1391. ha->request_ring = NULL;
  1392. ha->request_dma = 0;
  1393. ha->response_ring = NULL;
  1394. ha->response_dma = 0;
  1395. ha->shadow_regs = NULL;
  1396. ha->shadow_regs_dma = 0;
  1397. /* Free srb pool. */
  1398. if (ha->srb_mempool)
  1399. mempool_destroy(ha->srb_mempool);
  1400. ha->srb_mempool = NULL;
  1401. if (ha->chap_dma_pool)
  1402. dma_pool_destroy(ha->chap_dma_pool);
  1403. if (ha->chap_list)
  1404. vfree(ha->chap_list);
  1405. ha->chap_list = NULL;
  1406. /* release io space registers */
  1407. if (is_qla8022(ha)) {
  1408. if (ha->nx_pcibase)
  1409. iounmap(
  1410. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  1411. } else if (ha->reg)
  1412. iounmap(ha->reg);
  1413. pci_release_regions(ha->pdev);
  1414. }
  1415. /**
  1416. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  1417. * @ha: Pointer to host adapter structure
  1418. *
  1419. * Allocates DMA memory for request and response queues. Also allocates memory
  1420. * for srbs.
  1421. **/
  1422. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  1423. {
  1424. unsigned long align;
  1425. /* Allocate contiguous block of DMA memory for queues. */
  1426. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  1427. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  1428. sizeof(struct shadow_regs) +
  1429. MEM_ALIGN_VALUE +
  1430. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  1431. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  1432. &ha->queues_dma, GFP_KERNEL);
  1433. if (ha->queues == NULL) {
  1434. ql4_printk(KERN_WARNING, ha,
  1435. "Memory Allocation failed - queues.\n");
  1436. goto mem_alloc_error_exit;
  1437. }
  1438. memset(ha->queues, 0, ha->queues_len);
  1439. /*
  1440. * As per RISC alignment requirements -- the bus-address must be a
  1441. * multiple of the request-ring size (in bytes).
  1442. */
  1443. align = 0;
  1444. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  1445. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  1446. (MEM_ALIGN_VALUE - 1));
  1447. /* Update request and response queue pointers. */
  1448. ha->request_dma = ha->queues_dma + align;
  1449. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  1450. ha->response_dma = ha->queues_dma + align +
  1451. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  1452. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  1453. (REQUEST_QUEUE_DEPTH *
  1454. QUEUE_SIZE));
  1455. ha->shadow_regs_dma = ha->queues_dma + align +
  1456. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  1457. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  1458. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  1459. (REQUEST_QUEUE_DEPTH *
  1460. QUEUE_SIZE) +
  1461. (RESPONSE_QUEUE_DEPTH *
  1462. QUEUE_SIZE));
  1463. /* Allocate memory for srb pool. */
  1464. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  1465. mempool_free_slab, srb_cachep);
  1466. if (ha->srb_mempool == NULL) {
  1467. ql4_printk(KERN_WARNING, ha,
  1468. "Memory Allocation failed - SRB Pool.\n");
  1469. goto mem_alloc_error_exit;
  1470. }
  1471. ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
  1472. CHAP_DMA_BLOCK_SIZE, 8, 0);
  1473. if (ha->chap_dma_pool == NULL) {
  1474. ql4_printk(KERN_WARNING, ha,
  1475. "%s: chap_dma_pool allocation failed..\n", __func__);
  1476. goto mem_alloc_error_exit;
  1477. }
  1478. return QLA_SUCCESS;
  1479. mem_alloc_error_exit:
  1480. qla4xxx_mem_free(ha);
  1481. return QLA_ERROR;
  1482. }
  1483. /**
  1484. * qla4_8xxx_check_fw_alive - Check firmware health
  1485. * @ha: Pointer to host adapter structure.
  1486. *
  1487. * Context: Interrupt
  1488. **/
  1489. static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  1490. {
  1491. uint32_t fw_heartbeat_counter, halt_status;
  1492. fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
  1493. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  1494. if (fw_heartbeat_counter == 0xffffffff) {
  1495. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
  1496. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  1497. ha->host_no, __func__));
  1498. return;
  1499. }
  1500. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  1501. ha->seconds_since_last_heartbeat++;
  1502. /* FW not alive after 2 seconds */
  1503. if (ha->seconds_since_last_heartbeat == 2) {
  1504. ha->seconds_since_last_heartbeat = 0;
  1505. halt_status = qla4_8xxx_rd_32(ha,
  1506. QLA82XX_PEG_HALT_STATUS1);
  1507. ql4_printk(KERN_INFO, ha,
  1508. "scsi(%ld): %s, Dumping hw/fw registers:\n "
  1509. " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
  1510. " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
  1511. " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
  1512. " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
  1513. ha->host_no, __func__, halt_status,
  1514. qla4_8xxx_rd_32(ha,
  1515. QLA82XX_PEG_HALT_STATUS2),
  1516. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
  1517. 0x3c),
  1518. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
  1519. 0x3c),
  1520. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
  1521. 0x3c),
  1522. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
  1523. 0x3c),
  1524. qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
  1525. 0x3c));
  1526. /* Since we cannot change dev_state in interrupt
  1527. * context, set appropriate DPC flag then wakeup
  1528. * DPC */
  1529. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  1530. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  1531. else {
  1532. printk("scsi%ld: %s: detect abort needed!\n",
  1533. ha->host_no, __func__);
  1534. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1535. }
  1536. qla4xxx_wake_dpc(ha);
  1537. qla4xxx_mailbox_premature_completion(ha);
  1538. }
  1539. } else
  1540. ha->seconds_since_last_heartbeat = 0;
  1541. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  1542. }
  1543. /**
  1544. * qla4_8xxx_watchdog - Poll dev state
  1545. * @ha: Pointer to host adapter structure.
  1546. *
  1547. * Context: Interrupt
  1548. **/
  1549. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  1550. {
  1551. uint32_t dev_state;
  1552. dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  1553. /* don't poll if reset is going on */
  1554. if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  1555. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1556. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
  1557. if (dev_state == QLA82XX_DEV_NEED_RESET &&
  1558. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  1559. if (!ql4xdontresethba) {
  1560. ql4_printk(KERN_INFO, ha, "%s: HW State: "
  1561. "NEED RESET!\n", __func__);
  1562. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1563. qla4xxx_wake_dpc(ha);
  1564. qla4xxx_mailbox_premature_completion(ha);
  1565. }
  1566. } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
  1567. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  1568. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
  1569. __func__);
  1570. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  1571. qla4xxx_wake_dpc(ha);
  1572. } else {
  1573. /* Check firmware health */
  1574. qla4_8xxx_check_fw_alive(ha);
  1575. }
  1576. }
  1577. }
  1578. /**
  1579. * qla4xxx_timer - checks every second for work to do.
  1580. * @ha: Pointer to host adapter structure.
  1581. **/
  1582. static void qla4xxx_timer(struct scsi_qla_host *ha)
  1583. {
  1584. int start_dpc = 0;
  1585. uint16_t w;
  1586. /* If we are in the middle of AER/EEH processing
  1587. * skip any processing and reschedule the timer
  1588. */
  1589. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  1590. mod_timer(&ha->timer, jiffies + HZ);
  1591. return;
  1592. }
  1593. /* Hardware read to trigger an EEH error during mailbox waits. */
  1594. if (!pci_channel_offline(ha->pdev))
  1595. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  1596. if (is_qla8022(ha)) {
  1597. qla4_8xxx_watchdog(ha);
  1598. }
  1599. if (!is_qla8022(ha)) {
  1600. /* Check for heartbeat interval. */
  1601. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  1602. ha->heartbeat_interval != 0) {
  1603. ha->seconds_since_last_heartbeat++;
  1604. if (ha->seconds_since_last_heartbeat >
  1605. ha->heartbeat_interval + 2)
  1606. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1607. }
  1608. }
  1609. /* Wakeup the dpc routine for this adapter, if needed. */
  1610. if (start_dpc ||
  1611. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  1612. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  1613. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  1614. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  1615. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  1616. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  1617. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  1618. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  1619. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  1620. test_bit(DPC_AEN, &ha->dpc_flags)) {
  1621. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  1622. " - dpc flags = 0x%lx\n",
  1623. ha->host_no, __func__, ha->dpc_flags));
  1624. qla4xxx_wake_dpc(ha);
  1625. }
  1626. /* Reschedule timer thread to call us back in one second */
  1627. mod_timer(&ha->timer, jiffies + HZ);
  1628. DEBUG2(ha->seconds_since_last_intr++);
  1629. }
  1630. /**
  1631. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  1632. * @ha: Pointer to host adapter structure.
  1633. *
  1634. * This routine stalls the driver until all outstanding commands are returned.
  1635. * Caller must release the Hardware Lock prior to calling this routine.
  1636. **/
  1637. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  1638. {
  1639. uint32_t index = 0;
  1640. unsigned long flags;
  1641. struct scsi_cmnd *cmd;
  1642. unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
  1643. DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
  1644. "complete\n", WAIT_CMD_TOV));
  1645. while (!time_after_eq(jiffies, wtime)) {
  1646. spin_lock_irqsave(&ha->hardware_lock, flags);
  1647. /* Find a command that hasn't completed. */
  1648. for (index = 0; index < ha->host->can_queue; index++) {
  1649. cmd = scsi_host_find_tag(ha->host, index);
  1650. /*
  1651. * We cannot just check if the index is valid,
  1652. * becase if we are run from the scsi eh, then
  1653. * the scsi/block layer is going to prevent
  1654. * the tag from being released.
  1655. */
  1656. if (cmd != NULL && CMD_SP(cmd))
  1657. break;
  1658. }
  1659. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1660. /* If No Commands are pending, wait is complete */
  1661. if (index == ha->host->can_queue)
  1662. return QLA_SUCCESS;
  1663. msleep(1000);
  1664. }
  1665. /* If we timed out on waiting for commands to come back
  1666. * return ERROR. */
  1667. return QLA_ERROR;
  1668. }
  1669. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  1670. {
  1671. uint32_t ctrl_status;
  1672. unsigned long flags = 0;
  1673. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  1674. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  1675. return QLA_ERROR;
  1676. spin_lock_irqsave(&ha->hardware_lock, flags);
  1677. /*
  1678. * If the SCSI Reset Interrupt bit is set, clear it.
  1679. * Otherwise, the Soft Reset won't work.
  1680. */
  1681. ctrl_status = readw(&ha->reg->ctrl_status);
  1682. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  1683. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  1684. /* Issue Soft Reset */
  1685. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  1686. readl(&ha->reg->ctrl_status);
  1687. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1688. return QLA_SUCCESS;
  1689. }
  1690. /**
  1691. * qla4xxx_soft_reset - performs soft reset.
  1692. * @ha: Pointer to host adapter structure.
  1693. **/
  1694. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  1695. {
  1696. uint32_t max_wait_time;
  1697. unsigned long flags = 0;
  1698. int status;
  1699. uint32_t ctrl_status;
  1700. status = qla4xxx_hw_reset(ha);
  1701. if (status != QLA_SUCCESS)
  1702. return status;
  1703. status = QLA_ERROR;
  1704. /* Wait until the Network Reset Intr bit is cleared */
  1705. max_wait_time = RESET_INTR_TOV;
  1706. do {
  1707. spin_lock_irqsave(&ha->hardware_lock, flags);
  1708. ctrl_status = readw(&ha->reg->ctrl_status);
  1709. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1710. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  1711. break;
  1712. msleep(1000);
  1713. } while ((--max_wait_time));
  1714. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  1715. DEBUG2(printk(KERN_WARNING
  1716. "scsi%ld: Network Reset Intr not cleared by "
  1717. "Network function, clearing it now!\n",
  1718. ha->host_no));
  1719. spin_lock_irqsave(&ha->hardware_lock, flags);
  1720. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  1721. readl(&ha->reg->ctrl_status);
  1722. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1723. }
  1724. /* Wait until the firmware tells us the Soft Reset is done */
  1725. max_wait_time = SOFT_RESET_TOV;
  1726. do {
  1727. spin_lock_irqsave(&ha->hardware_lock, flags);
  1728. ctrl_status = readw(&ha->reg->ctrl_status);
  1729. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1730. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  1731. status = QLA_SUCCESS;
  1732. break;
  1733. }
  1734. msleep(1000);
  1735. } while ((--max_wait_time));
  1736. /*
  1737. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  1738. * after the soft reset has taken place.
  1739. */
  1740. spin_lock_irqsave(&ha->hardware_lock, flags);
  1741. ctrl_status = readw(&ha->reg->ctrl_status);
  1742. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  1743. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  1744. readl(&ha->reg->ctrl_status);
  1745. }
  1746. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1747. /* If soft reset fails then most probably the bios on other
  1748. * function is also enabled.
  1749. * Since the initialization is sequential the other fn
  1750. * wont be able to acknowledge the soft reset.
  1751. * Issue a force soft reset to workaround this scenario.
  1752. */
  1753. if (max_wait_time == 0) {
  1754. /* Issue Force Soft Reset */
  1755. spin_lock_irqsave(&ha->hardware_lock, flags);
  1756. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  1757. readl(&ha->reg->ctrl_status);
  1758. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1759. /* Wait until the firmware tells us the Soft Reset is done */
  1760. max_wait_time = SOFT_RESET_TOV;
  1761. do {
  1762. spin_lock_irqsave(&ha->hardware_lock, flags);
  1763. ctrl_status = readw(&ha->reg->ctrl_status);
  1764. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1765. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  1766. status = QLA_SUCCESS;
  1767. break;
  1768. }
  1769. msleep(1000);
  1770. } while ((--max_wait_time));
  1771. }
  1772. return status;
  1773. }
  1774. /**
  1775. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  1776. * @ha: Pointer to host adapter structure.
  1777. * @res: returned scsi status
  1778. *
  1779. * This routine is called just prior to a HARD RESET to return all
  1780. * outstanding commands back to the Operating System.
  1781. * Caller should make sure that the following locks are released
  1782. * before this calling routine: Hardware lock, and io_request_lock.
  1783. **/
  1784. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  1785. {
  1786. struct srb *srb;
  1787. int i;
  1788. unsigned long flags;
  1789. spin_lock_irqsave(&ha->hardware_lock, flags);
  1790. for (i = 0; i < ha->host->can_queue; i++) {
  1791. srb = qla4xxx_del_from_active_array(ha, i);
  1792. if (srb != NULL) {
  1793. srb->cmd->result = res;
  1794. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  1795. }
  1796. }
  1797. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1798. }
  1799. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  1800. {
  1801. clear_bit(AF_ONLINE, &ha->flags);
  1802. /* Disable the board */
  1803. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  1804. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  1805. qla4xxx_mark_all_devices_missing(ha);
  1806. clear_bit(AF_INIT_DONE, &ha->flags);
  1807. }
  1808. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
  1809. {
  1810. struct iscsi_session *sess;
  1811. struct ddb_entry *ddb_entry;
  1812. sess = cls_session->dd_data;
  1813. ddb_entry = sess->dd_data;
  1814. ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
  1815. iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
  1816. }
  1817. /**
  1818. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  1819. * @ha: Pointer to host adapter structure.
  1820. **/
  1821. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  1822. {
  1823. int status = QLA_ERROR;
  1824. uint8_t reset_chip = 0;
  1825. /* Stall incoming I/O until we are done */
  1826. scsi_block_requests(ha->host);
  1827. clear_bit(AF_ONLINE, &ha->flags);
  1828. clear_bit(AF_LINK_UP, &ha->flags);
  1829. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  1830. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  1831. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  1832. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  1833. reset_chip = 1;
  1834. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  1835. * do not reset adapter, jump to initialize_adapter */
  1836. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  1837. status = QLA_SUCCESS;
  1838. goto recover_ha_init_adapter;
  1839. }
  1840. /* For the ISP-82xx adapter, issue a stop_firmware if invoked
  1841. * from eh_host_reset or ioctl module */
  1842. if (is_qla8022(ha) && !reset_chip &&
  1843. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  1844. DEBUG2(ql4_printk(KERN_INFO, ha,
  1845. "scsi%ld: %s - Performing stop_firmware...\n",
  1846. ha->host_no, __func__));
  1847. status = ha->isp_ops->reset_firmware(ha);
  1848. if (status == QLA_SUCCESS) {
  1849. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  1850. qla4xxx_cmd_wait(ha);
  1851. ha->isp_ops->disable_intrs(ha);
  1852. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  1853. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  1854. } else {
  1855. /* If the stop_firmware fails then
  1856. * reset the entire chip */
  1857. reset_chip = 1;
  1858. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  1859. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  1860. }
  1861. }
  1862. /* Issue full chip reset if recovering from a catastrophic error,
  1863. * or if stop_firmware fails for ISP-82xx.
  1864. * This is the default case for ISP-4xxx */
  1865. if (!is_qla8022(ha) || reset_chip) {
  1866. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  1867. qla4xxx_cmd_wait(ha);
  1868. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  1869. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  1870. DEBUG2(ql4_printk(KERN_INFO, ha,
  1871. "scsi%ld: %s - Performing chip reset..\n",
  1872. ha->host_no, __func__));
  1873. status = ha->isp_ops->reset_chip(ha);
  1874. }
  1875. /* Flush any pending ddb changed AENs */
  1876. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  1877. recover_ha_init_adapter:
  1878. /* Upon successful firmware/chip reset, re-initialize the adapter */
  1879. if (status == QLA_SUCCESS) {
  1880. /* For ISP-4xxx, force function 1 to always initialize
  1881. * before function 3 to prevent both funcions from
  1882. * stepping on top of the other */
  1883. if (!is_qla8022(ha) && (ha->mac_index == 3))
  1884. ssleep(6);
  1885. /* NOTE: AF_ONLINE flag set upon successful completion of
  1886. * qla4xxx_initialize_adapter */
  1887. status = qla4xxx_initialize_adapter(ha);
  1888. }
  1889. /* Retry failed adapter initialization, if necessary
  1890. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  1891. * case to prevent ping-pong resets between functions */
  1892. if (!test_bit(AF_ONLINE, &ha->flags) &&
  1893. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  1894. /* Adapter initialization failed, see if we can retry
  1895. * resetting the ha.
  1896. * Since we don't want to block the DPC for too long
  1897. * with multiple resets in the same thread,
  1898. * utilize DPC to retry */
  1899. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  1900. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  1901. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  1902. "(%d) more times\n", ha->host_no,
  1903. ha->retry_reset_ha_cnt));
  1904. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  1905. status = QLA_ERROR;
  1906. } else {
  1907. if (ha->retry_reset_ha_cnt > 0) {
  1908. /* Schedule another Reset HA--DPC will retry */
  1909. ha->retry_reset_ha_cnt--;
  1910. DEBUG2(printk("scsi%ld: recover adapter - "
  1911. "retry remaining %d\n",
  1912. ha->host_no,
  1913. ha->retry_reset_ha_cnt));
  1914. status = QLA_ERROR;
  1915. }
  1916. if (ha->retry_reset_ha_cnt == 0) {
  1917. /* Recover adapter retries have been exhausted.
  1918. * Adapter DEAD */
  1919. DEBUG2(printk("scsi%ld: recover adapter "
  1920. "failed - board disabled\n",
  1921. ha->host_no));
  1922. qla4xxx_dead_adapter_cleanup(ha);
  1923. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  1924. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  1925. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  1926. &ha->dpc_flags);
  1927. status = QLA_ERROR;
  1928. }
  1929. }
  1930. } else {
  1931. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  1932. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  1933. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  1934. }
  1935. ha->adapter_error_count++;
  1936. if (test_bit(AF_ONLINE, &ha->flags))
  1937. ha->isp_ops->enable_intrs(ha);
  1938. scsi_unblock_requests(ha->host);
  1939. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  1940. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  1941. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  1942. return status;
  1943. }
  1944. static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
  1945. {
  1946. struct iscsi_session *sess;
  1947. struct ddb_entry *ddb_entry;
  1948. struct scsi_qla_host *ha;
  1949. sess = cls_session->dd_data;
  1950. ddb_entry = sess->dd_data;
  1951. ha = ddb_entry->ha;
  1952. if (!iscsi_is_session_online(cls_session)) {
  1953. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
  1954. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  1955. " unblock session\n", ha->host_no, __func__,
  1956. ddb_entry->fw_ddb_index);
  1957. iscsi_unblock_session(ddb_entry->sess);
  1958. } else {
  1959. /* Trigger relogin */
  1960. iscsi_session_failure(cls_session->dd_data,
  1961. ISCSI_ERR_CONN_FAILED);
  1962. }
  1963. }
  1964. }
  1965. static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
  1966. {
  1967. iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
  1968. }
  1969. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  1970. {
  1971. if (ha->dpc_thread)
  1972. queue_work(ha->dpc_thread, &ha->dpc_work);
  1973. }
  1974. /**
  1975. * qla4xxx_do_dpc - dpc routine
  1976. * @data: in our case pointer to adapter structure
  1977. *
  1978. * This routine is a task that is schedule by the interrupt handler
  1979. * to perform the background processing for interrupts. We put it
  1980. * on a task queue that is consumed whenever the scheduler runs; that's
  1981. * so you can do anything (i.e. put the process to sleep etc). In fact,
  1982. * the mid-level tries to sleep when it reaches the driver threshold
  1983. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  1984. **/
  1985. static void qla4xxx_do_dpc(struct work_struct *work)
  1986. {
  1987. struct scsi_qla_host *ha =
  1988. container_of(work, struct scsi_qla_host, dpc_work);
  1989. int status = QLA_ERROR;
  1990. DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
  1991. "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  1992. ha->host_no, __func__, ha->flags, ha->dpc_flags))
  1993. /* Initialization not yet finished. Don't do anything yet. */
  1994. if (!test_bit(AF_INIT_DONE, &ha->flags))
  1995. return;
  1996. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  1997. DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
  1998. ha->host_no, __func__, ha->flags));
  1999. return;
  2000. }
  2001. if (is_qla8022(ha)) {
  2002. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  2003. qla4_8xxx_idc_lock(ha);
  2004. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2005. QLA82XX_DEV_FAILED);
  2006. qla4_8xxx_idc_unlock(ha);
  2007. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  2008. qla4_8xxx_device_state_handler(ha);
  2009. }
  2010. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  2011. qla4_8xxx_need_qsnt_handler(ha);
  2012. }
  2013. }
  2014. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  2015. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  2016. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  2017. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  2018. if (ql4xdontresethba) {
  2019. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  2020. ha->host_no, __func__));
  2021. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  2022. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  2023. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  2024. goto dpc_post_reset_ha;
  2025. }
  2026. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  2027. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  2028. qla4xxx_recover_adapter(ha);
  2029. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  2030. uint8_t wait_time = RESET_INTR_TOV;
  2031. while ((readw(&ha->reg->ctrl_status) &
  2032. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  2033. if (--wait_time == 0)
  2034. break;
  2035. msleep(1000);
  2036. }
  2037. if (wait_time == 0)
  2038. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  2039. "bit not cleared-- resetting\n",
  2040. ha->host_no, __func__));
  2041. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  2042. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  2043. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  2044. status = qla4xxx_recover_adapter(ha);
  2045. }
  2046. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  2047. if (status == QLA_SUCCESS)
  2048. ha->isp_ops->enable_intrs(ha);
  2049. }
  2050. }
  2051. dpc_post_reset_ha:
  2052. /* ---- process AEN? --- */
  2053. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  2054. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  2055. /* ---- Get DHCP IP Address? --- */
  2056. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  2057. qla4xxx_get_dhcp_ip_address(ha);
  2058. /* ---- link change? --- */
  2059. if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  2060. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  2061. /* ---- link down? --- */
  2062. qla4xxx_mark_all_devices_missing(ha);
  2063. } else {
  2064. /* ---- link up? --- *
  2065. * F/W will auto login to all devices ONLY ONCE after
  2066. * link up during driver initialization and runtime
  2067. * fatal error recovery. Therefore, the driver must
  2068. * manually relogin to devices when recovering from
  2069. * connection failures, logouts, expired KATO, etc. */
  2070. qla4xxx_relogin_all_devices(ha);
  2071. }
  2072. }
  2073. }
  2074. /**
  2075. * qla4xxx_free_adapter - release the adapter
  2076. * @ha: pointer to adapter structure
  2077. **/
  2078. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  2079. {
  2080. if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
  2081. /* Turn-off interrupts on the card. */
  2082. ha->isp_ops->disable_intrs(ha);
  2083. }
  2084. /* Remove timer thread, if present */
  2085. if (ha->timer_active)
  2086. qla4xxx_stop_timer(ha);
  2087. /* Kill the kernel thread for this host */
  2088. if (ha->dpc_thread)
  2089. destroy_workqueue(ha->dpc_thread);
  2090. /* Kill the kernel thread for this host */
  2091. if (ha->task_wq)
  2092. destroy_workqueue(ha->task_wq);
  2093. /* Put firmware in known state */
  2094. ha->isp_ops->reset_firmware(ha);
  2095. if (is_qla8022(ha)) {
  2096. qla4_8xxx_idc_lock(ha);
  2097. qla4_8xxx_clear_drv_active(ha);
  2098. qla4_8xxx_idc_unlock(ha);
  2099. }
  2100. /* Detach interrupts */
  2101. if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
  2102. qla4xxx_free_irqs(ha);
  2103. /* free extra memory */
  2104. qla4xxx_mem_free(ha);
  2105. }
  2106. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  2107. {
  2108. int status = 0;
  2109. uint8_t revision_id;
  2110. unsigned long mem_base, mem_len, db_base, db_len;
  2111. struct pci_dev *pdev = ha->pdev;
  2112. status = pci_request_regions(pdev, DRIVER_NAME);
  2113. if (status) {
  2114. printk(KERN_WARNING
  2115. "scsi(%ld) Failed to reserve PIO regions (%s) "
  2116. "status=%d\n", ha->host_no, pci_name(pdev), status);
  2117. goto iospace_error_exit;
  2118. }
  2119. pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
  2120. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  2121. __func__, revision_id));
  2122. ha->revision_id = revision_id;
  2123. /* remap phys address */
  2124. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  2125. mem_len = pci_resource_len(pdev, 0);
  2126. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  2127. __func__, mem_base, mem_len));
  2128. /* mapping of pcibase pointer */
  2129. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  2130. if (!ha->nx_pcibase) {
  2131. printk(KERN_ERR
  2132. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  2133. pci_release_regions(ha->pdev);
  2134. goto iospace_error_exit;
  2135. }
  2136. /* Mapping of IO base pointer, door bell read and write pointer */
  2137. /* mapping of IO base pointer */
  2138. ha->qla4_8xxx_reg =
  2139. (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
  2140. 0xbc000 + (ha->pdev->devfn << 11));
  2141. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  2142. db_len = pci_resource_len(pdev, 4);
  2143. ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
  2144. QLA82XX_CAM_RAM_DB2);
  2145. return 0;
  2146. iospace_error_exit:
  2147. return -ENOMEM;
  2148. }
  2149. /***
  2150. * qla4xxx_iospace_config - maps registers
  2151. * @ha: pointer to adapter structure
  2152. *
  2153. * This routines maps HBA's registers from the pci address space
  2154. * into the kernel virtual address space for memory mapped i/o.
  2155. **/
  2156. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  2157. {
  2158. unsigned long pio, pio_len, pio_flags;
  2159. unsigned long mmio, mmio_len, mmio_flags;
  2160. pio = pci_resource_start(ha->pdev, 0);
  2161. pio_len = pci_resource_len(ha->pdev, 0);
  2162. pio_flags = pci_resource_flags(ha->pdev, 0);
  2163. if (pio_flags & IORESOURCE_IO) {
  2164. if (pio_len < MIN_IOBASE_LEN) {
  2165. ql4_printk(KERN_WARNING, ha,
  2166. "Invalid PCI I/O region size\n");
  2167. pio = 0;
  2168. }
  2169. } else {
  2170. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  2171. pio = 0;
  2172. }
  2173. /* Use MMIO operations for all accesses. */
  2174. mmio = pci_resource_start(ha->pdev, 1);
  2175. mmio_len = pci_resource_len(ha->pdev, 1);
  2176. mmio_flags = pci_resource_flags(ha->pdev, 1);
  2177. if (!(mmio_flags & IORESOURCE_MEM)) {
  2178. ql4_printk(KERN_ERR, ha,
  2179. "region #0 not an MMIO resource, aborting\n");
  2180. goto iospace_error_exit;
  2181. }
  2182. if (mmio_len < MIN_IOBASE_LEN) {
  2183. ql4_printk(KERN_ERR, ha,
  2184. "Invalid PCI mem region size, aborting\n");
  2185. goto iospace_error_exit;
  2186. }
  2187. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  2188. ql4_printk(KERN_WARNING, ha,
  2189. "Failed to reserve PIO/MMIO regions\n");
  2190. goto iospace_error_exit;
  2191. }
  2192. ha->pio_address = pio;
  2193. ha->pio_length = pio_len;
  2194. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  2195. if (!ha->reg) {
  2196. ql4_printk(KERN_ERR, ha,
  2197. "cannot remap MMIO, aborting\n");
  2198. goto iospace_error_exit;
  2199. }
  2200. return 0;
  2201. iospace_error_exit:
  2202. return -ENOMEM;
  2203. }
  2204. static struct isp_operations qla4xxx_isp_ops = {
  2205. .iospace_config = qla4xxx_iospace_config,
  2206. .pci_config = qla4xxx_pci_config,
  2207. .disable_intrs = qla4xxx_disable_intrs,
  2208. .enable_intrs = qla4xxx_enable_intrs,
  2209. .start_firmware = qla4xxx_start_firmware,
  2210. .intr_handler = qla4xxx_intr_handler,
  2211. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  2212. .reset_chip = qla4xxx_soft_reset,
  2213. .reset_firmware = qla4xxx_hw_reset,
  2214. .queue_iocb = qla4xxx_queue_iocb,
  2215. .complete_iocb = qla4xxx_complete_iocb,
  2216. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  2217. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  2218. .get_sys_info = qla4xxx_get_sys_info,
  2219. };
  2220. static struct isp_operations qla4_8xxx_isp_ops = {
  2221. .iospace_config = qla4_8xxx_iospace_config,
  2222. .pci_config = qla4_8xxx_pci_config,
  2223. .disable_intrs = qla4_8xxx_disable_intrs,
  2224. .enable_intrs = qla4_8xxx_enable_intrs,
  2225. .start_firmware = qla4_8xxx_load_risc,
  2226. .intr_handler = qla4_8xxx_intr_handler,
  2227. .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
  2228. .reset_chip = qla4_8xxx_isp_reset,
  2229. .reset_firmware = qla4_8xxx_stop_firmware,
  2230. .queue_iocb = qla4_8xxx_queue_iocb,
  2231. .complete_iocb = qla4_8xxx_complete_iocb,
  2232. .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
  2233. .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
  2234. .get_sys_info = qla4_8xxx_get_sys_info,
  2235. };
  2236. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  2237. {
  2238. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  2239. }
  2240. uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  2241. {
  2242. return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
  2243. }
  2244. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  2245. {
  2246. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  2247. }
  2248. uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  2249. {
  2250. return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
  2251. }
  2252. static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
  2253. {
  2254. struct scsi_qla_host *ha = data;
  2255. char *str = buf;
  2256. int rc;
  2257. switch (type) {
  2258. case ISCSI_BOOT_ETH_FLAGS:
  2259. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  2260. break;
  2261. case ISCSI_BOOT_ETH_INDEX:
  2262. rc = sprintf(str, "0\n");
  2263. break;
  2264. case ISCSI_BOOT_ETH_MAC:
  2265. rc = sysfs_format_mac(str, ha->my_mac,
  2266. MAC_ADDR_LEN);
  2267. break;
  2268. default:
  2269. rc = -ENOSYS;
  2270. break;
  2271. }
  2272. return rc;
  2273. }
  2274. static mode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
  2275. {
  2276. int rc;
  2277. switch (type) {
  2278. case ISCSI_BOOT_ETH_FLAGS:
  2279. case ISCSI_BOOT_ETH_MAC:
  2280. case ISCSI_BOOT_ETH_INDEX:
  2281. rc = S_IRUGO;
  2282. break;
  2283. default:
  2284. rc = 0;
  2285. break;
  2286. }
  2287. return rc;
  2288. }
  2289. static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
  2290. {
  2291. struct scsi_qla_host *ha = data;
  2292. char *str = buf;
  2293. int rc;
  2294. switch (type) {
  2295. case ISCSI_BOOT_INI_INITIATOR_NAME:
  2296. rc = sprintf(str, "%s\n", ha->name_string);
  2297. break;
  2298. default:
  2299. rc = -ENOSYS;
  2300. break;
  2301. }
  2302. return rc;
  2303. }
  2304. static mode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
  2305. {
  2306. int rc;
  2307. switch (type) {
  2308. case ISCSI_BOOT_INI_INITIATOR_NAME:
  2309. rc = S_IRUGO;
  2310. break;
  2311. default:
  2312. rc = 0;
  2313. break;
  2314. }
  2315. return rc;
  2316. }
  2317. static ssize_t
  2318. qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
  2319. char *buf)
  2320. {
  2321. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  2322. char *str = buf;
  2323. int rc;
  2324. switch (type) {
  2325. case ISCSI_BOOT_TGT_NAME:
  2326. rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
  2327. break;
  2328. case ISCSI_BOOT_TGT_IP_ADDR:
  2329. if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
  2330. rc = sprintf(buf, "%pI4\n",
  2331. &boot_conn->dest_ipaddr.ip_address);
  2332. else
  2333. rc = sprintf(str, "%pI6\n",
  2334. &boot_conn->dest_ipaddr.ip_address);
  2335. break;
  2336. case ISCSI_BOOT_TGT_PORT:
  2337. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  2338. break;
  2339. case ISCSI_BOOT_TGT_CHAP_NAME:
  2340. rc = sprintf(str, "%.*s\n",
  2341. boot_conn->chap.target_chap_name_length,
  2342. (char *)&boot_conn->chap.target_chap_name);
  2343. break;
  2344. case ISCSI_BOOT_TGT_CHAP_SECRET:
  2345. rc = sprintf(str, "%.*s\n",
  2346. boot_conn->chap.target_secret_length,
  2347. (char *)&boot_conn->chap.target_secret);
  2348. break;
  2349. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  2350. rc = sprintf(str, "%.*s\n",
  2351. boot_conn->chap.intr_chap_name_length,
  2352. (char *)&boot_conn->chap.intr_chap_name);
  2353. break;
  2354. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  2355. rc = sprintf(str, "%.*s\n",
  2356. boot_conn->chap.intr_secret_length,
  2357. (char *)&boot_conn->chap.intr_secret);
  2358. break;
  2359. case ISCSI_BOOT_TGT_FLAGS:
  2360. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  2361. break;
  2362. case ISCSI_BOOT_TGT_NIC_ASSOC:
  2363. rc = sprintf(str, "0\n");
  2364. break;
  2365. default:
  2366. rc = -ENOSYS;
  2367. break;
  2368. }
  2369. return rc;
  2370. }
  2371. static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
  2372. {
  2373. struct scsi_qla_host *ha = data;
  2374. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
  2375. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  2376. }
  2377. static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
  2378. {
  2379. struct scsi_qla_host *ha = data;
  2380. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
  2381. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  2382. }
  2383. static mode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
  2384. {
  2385. int rc;
  2386. switch (type) {
  2387. case ISCSI_BOOT_TGT_NAME:
  2388. case ISCSI_BOOT_TGT_IP_ADDR:
  2389. case ISCSI_BOOT_TGT_PORT:
  2390. case ISCSI_BOOT_TGT_CHAP_NAME:
  2391. case ISCSI_BOOT_TGT_CHAP_SECRET:
  2392. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  2393. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  2394. case ISCSI_BOOT_TGT_NIC_ASSOC:
  2395. case ISCSI_BOOT_TGT_FLAGS:
  2396. rc = S_IRUGO;
  2397. break;
  2398. default:
  2399. rc = 0;
  2400. break;
  2401. }
  2402. return rc;
  2403. }
  2404. static void qla4xxx_boot_release(void *data)
  2405. {
  2406. struct scsi_qla_host *ha = data;
  2407. scsi_host_put(ha->host);
  2408. }
  2409. static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
  2410. {
  2411. dma_addr_t buf_dma;
  2412. uint32_t addr, pri_addr, sec_addr;
  2413. uint32_t offset;
  2414. uint16_t func_num;
  2415. uint8_t val;
  2416. uint8_t *buf = NULL;
  2417. size_t size = 13 * sizeof(uint8_t);
  2418. int ret = QLA_SUCCESS;
  2419. func_num = PCI_FUNC(ha->pdev->devfn);
  2420. ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
  2421. __func__, ha->pdev->device, func_num);
  2422. if (is_qla40XX(ha)) {
  2423. if (func_num == 1) {
  2424. addr = NVRAM_PORT0_BOOT_MODE;
  2425. pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
  2426. sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
  2427. } else if (func_num == 3) {
  2428. addr = NVRAM_PORT1_BOOT_MODE;
  2429. pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
  2430. sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
  2431. } else {
  2432. ret = QLA_ERROR;
  2433. goto exit_boot_info;
  2434. }
  2435. /* Check Boot Mode */
  2436. val = rd_nvram_byte(ha, addr);
  2437. if (!(val & 0x07)) {
  2438. DEBUG2(ql4_printk(KERN_ERR, ha,
  2439. "%s: Failed Boot options : 0x%x\n",
  2440. __func__, val));
  2441. ret = QLA_ERROR;
  2442. goto exit_boot_info;
  2443. }
  2444. /* get primary valid target index */
  2445. val = rd_nvram_byte(ha, pri_addr);
  2446. if (val & BIT_7)
  2447. ddb_index[0] = (val & 0x7f);
  2448. /* get secondary valid target index */
  2449. val = rd_nvram_byte(ha, sec_addr);
  2450. if (val & BIT_7)
  2451. ddb_index[1] = (val & 0x7f);
  2452. } else if (is_qla8022(ha)) {
  2453. buf = dma_alloc_coherent(&ha->pdev->dev, size,
  2454. &buf_dma, GFP_KERNEL);
  2455. if (!buf) {
  2456. DEBUG2(ql4_printk(KERN_ERR, ha,
  2457. "%s: Unable to allocate dma buffer\n",
  2458. __func__));
  2459. ret = QLA_ERROR;
  2460. goto exit_boot_info;
  2461. }
  2462. if (ha->port_num == 0)
  2463. offset = BOOT_PARAM_OFFSET_PORT0;
  2464. else if (ha->port_num == 1)
  2465. offset = BOOT_PARAM_OFFSET_PORT1;
  2466. else {
  2467. ret = QLA_ERROR;
  2468. goto exit_boot_info_free;
  2469. }
  2470. addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
  2471. offset;
  2472. if (qla4xxx_get_flash(ha, buf_dma, addr,
  2473. 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
  2474. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
  2475. "failed\n", ha->host_no, __func__));
  2476. ret = QLA_ERROR;
  2477. goto exit_boot_info_free;
  2478. }
  2479. /* Check Boot Mode */
  2480. if (!(buf[1] & 0x07)) {
  2481. DEBUG2(ql4_printk(KERN_INFO, ha,
  2482. "Failed: Boot options : 0x%x\n",
  2483. buf[1]));
  2484. ret = QLA_ERROR;
  2485. goto exit_boot_info_free;
  2486. }
  2487. /* get primary valid target index */
  2488. if (buf[2] & BIT_7)
  2489. ddb_index[0] = buf[2] & 0x7f;
  2490. /* get secondary valid target index */
  2491. if (buf[11] & BIT_7)
  2492. ddb_index[1] = buf[11] & 0x7f;
  2493. } else {
  2494. ret = QLA_ERROR;
  2495. goto exit_boot_info;
  2496. }
  2497. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
  2498. " target ID %d\n", __func__, ddb_index[0],
  2499. ddb_index[1]));
  2500. exit_boot_info_free:
  2501. dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
  2502. exit_boot_info:
  2503. return ret;
  2504. }
  2505. /**
  2506. * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
  2507. * @ha: pointer to adapter structure
  2508. * @username: CHAP username to be returned
  2509. * @password: CHAP password to be returned
  2510. *
  2511. * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
  2512. * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
  2513. * So from the CHAP cache find the first BIDI CHAP entry and set it
  2514. * to the boot record in sysfs.
  2515. **/
  2516. static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
  2517. char *password)
  2518. {
  2519. int i, ret = -EINVAL;
  2520. int max_chap_entries = 0;
  2521. struct ql4_chap_table *chap_table;
  2522. if (is_qla8022(ha))
  2523. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  2524. sizeof(struct ql4_chap_table);
  2525. else
  2526. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  2527. if (!ha->chap_list) {
  2528. ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
  2529. return ret;
  2530. }
  2531. mutex_lock(&ha->chap_sem);
  2532. for (i = 0; i < max_chap_entries; i++) {
  2533. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  2534. if (chap_table->cookie !=
  2535. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  2536. continue;
  2537. }
  2538. if (chap_table->flags & BIT_7) /* local */
  2539. continue;
  2540. if (!(chap_table->flags & BIT_6)) /* Not BIDI */
  2541. continue;
  2542. strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
  2543. strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
  2544. ret = 0;
  2545. break;
  2546. }
  2547. mutex_unlock(&ha->chap_sem);
  2548. return ret;
  2549. }
  2550. static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
  2551. struct ql4_boot_session_info *boot_sess,
  2552. uint16_t ddb_index)
  2553. {
  2554. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  2555. struct dev_db_entry *fw_ddb_entry;
  2556. dma_addr_t fw_ddb_entry_dma;
  2557. uint16_t idx;
  2558. uint16_t options;
  2559. int ret = QLA_SUCCESS;
  2560. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2561. &fw_ddb_entry_dma, GFP_KERNEL);
  2562. if (!fw_ddb_entry) {
  2563. DEBUG2(ql4_printk(KERN_ERR, ha,
  2564. "%s: Unable to allocate dma buffer.\n",
  2565. __func__));
  2566. ret = QLA_ERROR;
  2567. return ret;
  2568. }
  2569. if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
  2570. fw_ddb_entry_dma, ddb_index)) {
  2571. DEBUG2(ql4_printk(KERN_ERR, ha,
  2572. "%s: Flash DDB read Failed\n", __func__));
  2573. ret = QLA_ERROR;
  2574. goto exit_boot_target;
  2575. }
  2576. /* Update target name and IP from DDB */
  2577. memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
  2578. min(sizeof(boot_sess->target_name),
  2579. sizeof(fw_ddb_entry->iscsi_name)));
  2580. options = le16_to_cpu(fw_ddb_entry->options);
  2581. if (options & DDB_OPT_IPV6_DEVICE) {
  2582. memcpy(&boot_conn->dest_ipaddr.ip_address,
  2583. &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
  2584. } else {
  2585. boot_conn->dest_ipaddr.ip_type = 0x1;
  2586. memcpy(&boot_conn->dest_ipaddr.ip_address,
  2587. &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
  2588. }
  2589. boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
  2590. /* update chap information */
  2591. idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  2592. if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  2593. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
  2594. ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
  2595. target_chap_name,
  2596. (char *)&boot_conn->chap.target_secret,
  2597. idx);
  2598. if (ret) {
  2599. ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
  2600. ret = QLA_ERROR;
  2601. goto exit_boot_target;
  2602. }
  2603. boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  2604. boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  2605. }
  2606. if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  2607. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
  2608. ret = qla4xxx_get_bidi_chap(ha,
  2609. (char *)&boot_conn->chap.intr_chap_name,
  2610. (char *)&boot_conn->chap.intr_secret);
  2611. if (ret) {
  2612. ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
  2613. ret = QLA_ERROR;
  2614. goto exit_boot_target;
  2615. }
  2616. boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  2617. boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  2618. }
  2619. exit_boot_target:
  2620. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2621. fw_ddb_entry, fw_ddb_entry_dma);
  2622. return ret;
  2623. }
  2624. static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
  2625. {
  2626. uint16_t ddb_index[2];
  2627. int ret = QLA_ERROR;
  2628. int rval;
  2629. memset(ddb_index, 0, sizeof(ddb_index));
  2630. ddb_index[0] = 0xffff;
  2631. ddb_index[1] = 0xffff;
  2632. ret = get_fw_boot_info(ha, ddb_index);
  2633. if (ret != QLA_SUCCESS) {
  2634. DEBUG2(ql4_printk(KERN_ERR, ha,
  2635. "%s: Failed to set boot info.\n", __func__));
  2636. return ret;
  2637. }
  2638. if (ddb_index[0] == 0xffff)
  2639. goto sec_target;
  2640. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
  2641. ddb_index[0]);
  2642. if (rval != QLA_SUCCESS) {
  2643. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get "
  2644. "primary target\n", __func__));
  2645. } else
  2646. ret = QLA_SUCCESS;
  2647. sec_target:
  2648. if (ddb_index[1] == 0xffff)
  2649. goto exit_get_boot_info;
  2650. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
  2651. ddb_index[1]);
  2652. if (rval != QLA_SUCCESS) {
  2653. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get "
  2654. "secondary target\n", __func__));
  2655. } else
  2656. ret = QLA_SUCCESS;
  2657. exit_get_boot_info:
  2658. return ret;
  2659. }
  2660. static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
  2661. {
  2662. struct iscsi_boot_kobj *boot_kobj;
  2663. if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
  2664. return 0;
  2665. ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
  2666. if (!ha->boot_kset)
  2667. goto kset_free;
  2668. if (!scsi_host_get(ha->host))
  2669. goto kset_free;
  2670. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
  2671. qla4xxx_show_boot_tgt_pri_info,
  2672. qla4xxx_tgt_get_attr_visibility,
  2673. qla4xxx_boot_release);
  2674. if (!boot_kobj)
  2675. goto put_host;
  2676. if (!scsi_host_get(ha->host))
  2677. goto kset_free;
  2678. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
  2679. qla4xxx_show_boot_tgt_sec_info,
  2680. qla4xxx_tgt_get_attr_visibility,
  2681. qla4xxx_boot_release);
  2682. if (!boot_kobj)
  2683. goto put_host;
  2684. if (!scsi_host_get(ha->host))
  2685. goto kset_free;
  2686. boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
  2687. qla4xxx_show_boot_ini_info,
  2688. qla4xxx_ini_get_attr_visibility,
  2689. qla4xxx_boot_release);
  2690. if (!boot_kobj)
  2691. goto put_host;
  2692. if (!scsi_host_get(ha->host))
  2693. goto kset_free;
  2694. boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
  2695. qla4xxx_show_boot_eth_info,
  2696. qla4xxx_eth_get_attr_visibility,
  2697. qla4xxx_boot_release);
  2698. if (!boot_kobj)
  2699. goto put_host;
  2700. return 0;
  2701. put_host:
  2702. scsi_host_put(ha->host);
  2703. kset_free:
  2704. iscsi_boot_destroy_kset(ha->boot_kset);
  2705. return -ENOMEM;
  2706. }
  2707. /**
  2708. * qla4xxx_create chap_list - Create CHAP list from FLASH
  2709. * @ha: pointer to adapter structure
  2710. *
  2711. * Read flash and make a list of CHAP entries, during login when a CHAP entry
  2712. * is received, it will be checked in this list. If entry exist then the CHAP
  2713. * entry index is set in the DDB. If CHAP entry does not exist in this list
  2714. * then a new entry is added in FLASH in CHAP table and the index obtained is
  2715. * used in the DDB.
  2716. **/
  2717. static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
  2718. {
  2719. int rval = 0;
  2720. uint8_t *chap_flash_data = NULL;
  2721. uint32_t offset;
  2722. dma_addr_t chap_dma;
  2723. uint32_t chap_size = 0;
  2724. if (is_qla40XX(ha))
  2725. chap_size = MAX_CHAP_ENTRIES_40XX *
  2726. sizeof(struct ql4_chap_table);
  2727. else /* Single region contains CHAP info for both
  2728. * ports which is divided into half for each port.
  2729. */
  2730. chap_size = ha->hw.flt_chap_size / 2;
  2731. chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
  2732. &chap_dma, GFP_KERNEL);
  2733. if (!chap_flash_data) {
  2734. ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
  2735. return;
  2736. }
  2737. if (is_qla40XX(ha))
  2738. offset = FLASH_CHAP_OFFSET;
  2739. else {
  2740. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  2741. if (ha->port_num == 1)
  2742. offset += chap_size;
  2743. }
  2744. rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  2745. if (rval != QLA_SUCCESS)
  2746. goto exit_chap_list;
  2747. if (ha->chap_list == NULL)
  2748. ha->chap_list = vmalloc(chap_size);
  2749. if (ha->chap_list == NULL) {
  2750. ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
  2751. goto exit_chap_list;
  2752. }
  2753. memcpy(ha->chap_list, chap_flash_data, chap_size);
  2754. exit_chap_list:
  2755. dma_free_coherent(&ha->pdev->dev, chap_size,
  2756. chap_flash_data, chap_dma);
  2757. return;
  2758. }
  2759. /**
  2760. * qla4xxx_probe_adapter - callback function to probe HBA
  2761. * @pdev: pointer to pci_dev structure
  2762. * @pci_device_id: pointer to pci_device entry
  2763. *
  2764. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  2765. * It returns zero if successful. It also initializes all data necessary for
  2766. * the driver.
  2767. **/
  2768. static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
  2769. const struct pci_device_id *ent)
  2770. {
  2771. int ret = -ENODEV, status;
  2772. struct Scsi_Host *host;
  2773. struct scsi_qla_host *ha;
  2774. uint8_t init_retry_count = 0;
  2775. char buf[34];
  2776. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  2777. uint32_t dev_state;
  2778. if (pci_enable_device(pdev))
  2779. return -1;
  2780. host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
  2781. if (host == NULL) {
  2782. printk(KERN_WARNING
  2783. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  2784. goto probe_disable_device;
  2785. }
  2786. /* Clear our data area */
  2787. ha = to_qla_host(host);
  2788. memset(ha, 0, sizeof(*ha));
  2789. /* Save the information from PCI BIOS. */
  2790. ha->pdev = pdev;
  2791. ha->host = host;
  2792. ha->host_no = host->host_no;
  2793. pci_enable_pcie_error_reporting(pdev);
  2794. /* Setup Runtime configurable options */
  2795. if (is_qla8022(ha)) {
  2796. ha->isp_ops = &qla4_8xxx_isp_ops;
  2797. rwlock_init(&ha->hw_lock);
  2798. ha->qdr_sn_window = -1;
  2799. ha->ddr_mn_window = -1;
  2800. ha->curr_window = 255;
  2801. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  2802. nx_legacy_intr = &legacy_intr[ha->func_num];
  2803. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  2804. ha->nx_legacy_intr.tgt_status_reg =
  2805. nx_legacy_intr->tgt_status_reg;
  2806. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  2807. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  2808. } else {
  2809. ha->isp_ops = &qla4xxx_isp_ops;
  2810. }
  2811. /* Set EEH reset type to fundamental if required by hba */
  2812. if (is_qla8022(ha))
  2813. pdev->needs_freset = 1;
  2814. /* Configure PCI I/O space. */
  2815. ret = ha->isp_ops->iospace_config(ha);
  2816. if (ret)
  2817. goto probe_failed_ioconfig;
  2818. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  2819. pdev->device, pdev->irq, ha->reg);
  2820. qla4xxx_config_dma_addressing(ha);
  2821. /* Initialize lists and spinlocks. */
  2822. INIT_LIST_HEAD(&ha->free_srb_q);
  2823. mutex_init(&ha->mbox_sem);
  2824. mutex_init(&ha->chap_sem);
  2825. init_completion(&ha->mbx_intr_comp);
  2826. init_completion(&ha->disable_acb_comp);
  2827. spin_lock_init(&ha->hardware_lock);
  2828. /* Allocate dma buffers */
  2829. if (qla4xxx_mem_alloc(ha)) {
  2830. ql4_printk(KERN_WARNING, ha,
  2831. "[ERROR] Failed to allocate memory for adapter\n");
  2832. ret = -ENOMEM;
  2833. goto probe_failed;
  2834. }
  2835. host->cmd_per_lun = 3;
  2836. host->max_channel = 0;
  2837. host->max_lun = MAX_LUNS - 1;
  2838. host->max_id = MAX_TARGETS;
  2839. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  2840. host->can_queue = MAX_SRBS ;
  2841. host->transportt = qla4xxx_scsi_transport;
  2842. ret = scsi_init_shared_tag_map(host, MAX_SRBS);
  2843. if (ret) {
  2844. ql4_printk(KERN_WARNING, ha,
  2845. "%s: scsi_init_shared_tag_map failed\n", __func__);
  2846. goto probe_failed;
  2847. }
  2848. pci_set_drvdata(pdev, ha);
  2849. ret = scsi_add_host(host, &pdev->dev);
  2850. if (ret)
  2851. goto probe_failed;
  2852. if (is_qla8022(ha))
  2853. (void) qla4_8xxx_get_flash_info(ha);
  2854. /*
  2855. * Initialize the Host adapter request/response queues and
  2856. * firmware
  2857. * NOTE: interrupts enabled upon successful completion
  2858. */
  2859. status = qla4xxx_initialize_adapter(ha);
  2860. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  2861. init_retry_count++ < MAX_INIT_RETRIES) {
  2862. if (is_qla8022(ha)) {
  2863. qla4_8xxx_idc_lock(ha);
  2864. dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
  2865. qla4_8xxx_idc_unlock(ha);
  2866. if (dev_state == QLA82XX_DEV_FAILED) {
  2867. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  2868. "initialize adapter. H/W is in failed state\n",
  2869. __func__);
  2870. break;
  2871. }
  2872. }
  2873. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  2874. "(%d)\n", __func__, init_retry_count));
  2875. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  2876. continue;
  2877. status = qla4xxx_initialize_adapter(ha);
  2878. }
  2879. if (!test_bit(AF_ONLINE, &ha->flags)) {
  2880. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  2881. if (is_qla8022(ha) && ql4xdontresethba) {
  2882. /* Put the device in failed state. */
  2883. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  2884. qla4_8xxx_idc_lock(ha);
  2885. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2886. QLA82XX_DEV_FAILED);
  2887. qla4_8xxx_idc_unlock(ha);
  2888. }
  2889. ret = -ENODEV;
  2890. goto remove_host;
  2891. }
  2892. /* Startup the kernel thread for this host adapter. */
  2893. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  2894. "qla4xxx_dpc\n", __func__));
  2895. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  2896. ha->dpc_thread = create_singlethread_workqueue(buf);
  2897. if (!ha->dpc_thread) {
  2898. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  2899. ret = -ENODEV;
  2900. goto remove_host;
  2901. }
  2902. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  2903. sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
  2904. ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
  2905. if (!ha->task_wq) {
  2906. ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
  2907. ret = -ENODEV;
  2908. goto remove_host;
  2909. }
  2910. /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
  2911. * (which is called indirectly by qla4xxx_initialize_adapter),
  2912. * so that irqs will be registered after crbinit but before
  2913. * mbx_intr_enable.
  2914. */
  2915. if (!is_qla8022(ha)) {
  2916. ret = qla4xxx_request_irqs(ha);
  2917. if (ret) {
  2918. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  2919. "interrupt %d already in use.\n", pdev->irq);
  2920. goto remove_host;
  2921. }
  2922. }
  2923. pci_save_state(ha->pdev);
  2924. ha->isp_ops->enable_intrs(ha);
  2925. /* Start timer thread. */
  2926. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  2927. set_bit(AF_INIT_DONE, &ha->flags);
  2928. printk(KERN_INFO
  2929. " QLogic iSCSI HBA Driver version: %s\n"
  2930. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  2931. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  2932. ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
  2933. ha->patch_number, ha->build_number);
  2934. qla4xxx_create_chap_list(ha);
  2935. if (qla4xxx_setup_boot_info(ha))
  2936. ql4_printk(KERN_ERR, ha, "%s:ISCSI boot info setup failed\n",
  2937. __func__);
  2938. qla4xxx_create_ifaces(ha);
  2939. return 0;
  2940. remove_host:
  2941. scsi_remove_host(ha->host);
  2942. probe_failed:
  2943. qla4xxx_free_adapter(ha);
  2944. probe_failed_ioconfig:
  2945. pci_disable_pcie_error_reporting(pdev);
  2946. scsi_host_put(ha->host);
  2947. probe_disable_device:
  2948. pci_disable_device(pdev);
  2949. return ret;
  2950. }
  2951. /**
  2952. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  2953. * @ha: pointer to adapter structure
  2954. *
  2955. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  2956. * so that the other port will not re-initialize while in the process of
  2957. * removing the ha due to driver unload or hba hotplug.
  2958. **/
  2959. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  2960. {
  2961. struct scsi_qla_host *other_ha = NULL;
  2962. struct pci_dev *other_pdev = NULL;
  2963. int fn = ISP4XXX_PCI_FN_2;
  2964. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  2965. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  2966. fn = ISP4XXX_PCI_FN_1;
  2967. other_pdev =
  2968. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  2969. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  2970. fn));
  2971. /* Get other_ha if other_pdev is valid and state is enable*/
  2972. if (other_pdev) {
  2973. if (atomic_read(&other_pdev->enable_cnt)) {
  2974. other_ha = pci_get_drvdata(other_pdev);
  2975. if (other_ha) {
  2976. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  2977. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  2978. "Prevent %s reinit\n", __func__,
  2979. dev_name(&other_ha->pdev->dev)));
  2980. }
  2981. }
  2982. pci_dev_put(other_pdev);
  2983. }
  2984. }
  2985. /**
  2986. * qla4xxx_remove_adapter - calback function to remove adapter.
  2987. * @pci_dev: PCI device pointer
  2988. **/
  2989. static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
  2990. {
  2991. struct scsi_qla_host *ha;
  2992. ha = pci_get_drvdata(pdev);
  2993. if (!is_qla8022(ha))
  2994. qla4xxx_prevent_other_port_reinit(ha);
  2995. /* destroy iface from sysfs */
  2996. qla4xxx_destroy_ifaces(ha);
  2997. if (ha->boot_kset)
  2998. iscsi_boot_destroy_kset(ha->boot_kset);
  2999. scsi_remove_host(ha->host);
  3000. qla4xxx_free_adapter(ha);
  3001. scsi_host_put(ha->host);
  3002. pci_disable_pcie_error_reporting(pdev);
  3003. pci_disable_device(pdev);
  3004. pci_set_drvdata(pdev, NULL);
  3005. }
  3006. /**
  3007. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  3008. * @ha: HA context
  3009. *
  3010. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  3011. * supported addressing method.
  3012. */
  3013. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  3014. {
  3015. int retval;
  3016. /* Update our PCI device dma_mask for full 64 bit mask */
  3017. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  3018. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  3019. dev_dbg(&ha->pdev->dev,
  3020. "Failed to set 64 bit PCI consistent mask; "
  3021. "using 32 bit.\n");
  3022. retval = pci_set_consistent_dma_mask(ha->pdev,
  3023. DMA_BIT_MASK(32));
  3024. }
  3025. } else
  3026. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  3027. }
  3028. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  3029. {
  3030. struct iscsi_cls_session *cls_sess;
  3031. struct iscsi_session *sess;
  3032. struct ddb_entry *ddb;
  3033. int queue_depth = QL4_DEF_QDEPTH;
  3034. cls_sess = starget_to_session(sdev->sdev_target);
  3035. sess = cls_sess->dd_data;
  3036. ddb = sess->dd_data;
  3037. sdev->hostdata = ddb;
  3038. sdev->tagged_supported = 1;
  3039. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  3040. queue_depth = ql4xmaxqdepth;
  3041. scsi_activate_tcq(sdev, queue_depth);
  3042. return 0;
  3043. }
  3044. static int qla4xxx_slave_configure(struct scsi_device *sdev)
  3045. {
  3046. sdev->tagged_supported = 1;
  3047. return 0;
  3048. }
  3049. static void qla4xxx_slave_destroy(struct scsi_device *sdev)
  3050. {
  3051. scsi_deactivate_tcq(sdev, 1);
  3052. }
  3053. /**
  3054. * qla4xxx_del_from_active_array - returns an active srb
  3055. * @ha: Pointer to host adapter structure.
  3056. * @index: index into the active_array
  3057. *
  3058. * This routine removes and returns the srb at the specified index
  3059. **/
  3060. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  3061. uint32_t index)
  3062. {
  3063. struct srb *srb = NULL;
  3064. struct scsi_cmnd *cmd = NULL;
  3065. cmd = scsi_host_find_tag(ha->host, index);
  3066. if (!cmd)
  3067. return srb;
  3068. srb = (struct srb *)CMD_SP(cmd);
  3069. if (!srb)
  3070. return srb;
  3071. /* update counters */
  3072. if (srb->flags & SRB_DMA_VALID) {
  3073. ha->req_q_count += srb->iocb_cnt;
  3074. ha->iocb_cnt -= srb->iocb_cnt;
  3075. if (srb->cmd)
  3076. srb->cmd->host_scribble =
  3077. (unsigned char *)(unsigned long) MAX_SRBS;
  3078. }
  3079. return srb;
  3080. }
  3081. /**
  3082. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  3083. * @ha: Pointer to host adapter structure.
  3084. * @cmd: Scsi Command to wait on.
  3085. *
  3086. * This routine waits for the command to be returned by the Firmware
  3087. * for some max time.
  3088. **/
  3089. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  3090. struct scsi_cmnd *cmd)
  3091. {
  3092. int done = 0;
  3093. struct srb *rp;
  3094. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  3095. int ret = SUCCESS;
  3096. /* Dont wait on command if PCI error is being handled
  3097. * by PCI AER driver
  3098. */
  3099. if (unlikely(pci_channel_offline(ha->pdev)) ||
  3100. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  3101. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  3102. ha->host_no, __func__);
  3103. return ret;
  3104. }
  3105. do {
  3106. /* Checking to see if its returned to OS */
  3107. rp = (struct srb *) CMD_SP(cmd);
  3108. if (rp == NULL) {
  3109. done++;
  3110. break;
  3111. }
  3112. msleep(2000);
  3113. } while (max_wait_time--);
  3114. return done;
  3115. }
  3116. /**
  3117. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  3118. * @ha: Pointer to host adapter structure
  3119. **/
  3120. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  3121. {
  3122. unsigned long wait_online;
  3123. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  3124. while (time_before(jiffies, wait_online)) {
  3125. if (adapter_up(ha))
  3126. return QLA_SUCCESS;
  3127. msleep(2000);
  3128. }
  3129. return QLA_ERROR;
  3130. }
  3131. /**
  3132. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  3133. * @ha: pointer to HBA
  3134. * @t: target id
  3135. * @l: lun id
  3136. *
  3137. * This function waits for all outstanding commands to a lun to complete. It
  3138. * returns 0 if all pending commands are returned and 1 otherwise.
  3139. **/
  3140. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  3141. struct scsi_target *stgt,
  3142. struct scsi_device *sdev)
  3143. {
  3144. int cnt;
  3145. int status = 0;
  3146. struct scsi_cmnd *cmd;
  3147. /*
  3148. * Waiting for all commands for the designated target or dev
  3149. * in the active array
  3150. */
  3151. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  3152. cmd = scsi_host_find_tag(ha->host, cnt);
  3153. if (cmd && stgt == scsi_target(cmd->device) &&
  3154. (!sdev || sdev == cmd->device)) {
  3155. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  3156. status++;
  3157. break;
  3158. }
  3159. }
  3160. }
  3161. return status;
  3162. }
  3163. /**
  3164. * qla4xxx_eh_abort - callback for abort task.
  3165. * @cmd: Pointer to Linux's SCSI command structure
  3166. *
  3167. * This routine is called by the Linux OS to abort the specified
  3168. * command.
  3169. **/
  3170. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  3171. {
  3172. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  3173. unsigned int id = cmd->device->id;
  3174. unsigned int lun = cmd->device->lun;
  3175. unsigned long flags;
  3176. struct srb *srb = NULL;
  3177. int ret = SUCCESS;
  3178. int wait = 0;
  3179. ql4_printk(KERN_INFO, ha,
  3180. "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
  3181. ha->host_no, id, lun, cmd);
  3182. spin_lock_irqsave(&ha->hardware_lock, flags);
  3183. srb = (struct srb *) CMD_SP(cmd);
  3184. if (!srb) {
  3185. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3186. return SUCCESS;
  3187. }
  3188. kref_get(&srb->srb_ref);
  3189. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3190. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  3191. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
  3192. ha->host_no, id, lun));
  3193. ret = FAILED;
  3194. } else {
  3195. DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
  3196. ha->host_no, id, lun));
  3197. wait = 1;
  3198. }
  3199. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  3200. /* Wait for command to complete */
  3201. if (wait) {
  3202. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  3203. DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
  3204. ha->host_no, id, lun));
  3205. ret = FAILED;
  3206. }
  3207. }
  3208. ql4_printk(KERN_INFO, ha,
  3209. "scsi%ld:%d:%d: Abort command - %s\n",
  3210. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  3211. return ret;
  3212. }
  3213. /**
  3214. * qla4xxx_eh_device_reset - callback for target reset.
  3215. * @cmd: Pointer to Linux's SCSI command structure
  3216. *
  3217. * This routine is called by the Linux OS to reset all luns on the
  3218. * specified target.
  3219. **/
  3220. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  3221. {
  3222. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  3223. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  3224. int ret = FAILED, stat;
  3225. if (!ddb_entry)
  3226. return ret;
  3227. ret = iscsi_block_scsi_eh(cmd);
  3228. if (ret)
  3229. return ret;
  3230. ret = FAILED;
  3231. ql4_printk(KERN_INFO, ha,
  3232. "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
  3233. cmd->device->channel, cmd->device->id, cmd->device->lun);
  3234. DEBUG2(printk(KERN_INFO
  3235. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  3236. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  3237. cmd, jiffies, cmd->request->timeout / HZ,
  3238. ha->dpc_flags, cmd->result, cmd->allowed));
  3239. /* FIXME: wait for hba to go online */
  3240. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  3241. if (stat != QLA_SUCCESS) {
  3242. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  3243. goto eh_dev_reset_done;
  3244. }
  3245. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  3246. cmd->device)) {
  3247. ql4_printk(KERN_INFO, ha,
  3248. "DEVICE RESET FAILED - waiting for "
  3249. "commands.\n");
  3250. goto eh_dev_reset_done;
  3251. }
  3252. /* Send marker. */
  3253. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  3254. MM_LUN_RESET) != QLA_SUCCESS)
  3255. goto eh_dev_reset_done;
  3256. ql4_printk(KERN_INFO, ha,
  3257. "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
  3258. ha->host_no, cmd->device->channel, cmd->device->id,
  3259. cmd->device->lun);
  3260. ret = SUCCESS;
  3261. eh_dev_reset_done:
  3262. return ret;
  3263. }
  3264. /**
  3265. * qla4xxx_eh_target_reset - callback for target reset.
  3266. * @cmd: Pointer to Linux's SCSI command structure
  3267. *
  3268. * This routine is called by the Linux OS to reset the target.
  3269. **/
  3270. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  3271. {
  3272. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  3273. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  3274. int stat, ret;
  3275. if (!ddb_entry)
  3276. return FAILED;
  3277. ret = iscsi_block_scsi_eh(cmd);
  3278. if (ret)
  3279. return ret;
  3280. starget_printk(KERN_INFO, scsi_target(cmd->device),
  3281. "WARM TARGET RESET ISSUED.\n");
  3282. DEBUG2(printk(KERN_INFO
  3283. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  3284. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  3285. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  3286. ha->dpc_flags, cmd->result, cmd->allowed));
  3287. stat = qla4xxx_reset_target(ha, ddb_entry);
  3288. if (stat != QLA_SUCCESS) {
  3289. starget_printk(KERN_INFO, scsi_target(cmd->device),
  3290. "WARM TARGET RESET FAILED.\n");
  3291. return FAILED;
  3292. }
  3293. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  3294. NULL)) {
  3295. starget_printk(KERN_INFO, scsi_target(cmd->device),
  3296. "WARM TARGET DEVICE RESET FAILED - "
  3297. "waiting for commands.\n");
  3298. return FAILED;
  3299. }
  3300. /* Send marker. */
  3301. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  3302. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  3303. starget_printk(KERN_INFO, scsi_target(cmd->device),
  3304. "WARM TARGET DEVICE RESET FAILED - "
  3305. "marker iocb failed.\n");
  3306. return FAILED;
  3307. }
  3308. starget_printk(KERN_INFO, scsi_target(cmd->device),
  3309. "WARM TARGET RESET SUCCEEDED.\n");
  3310. return SUCCESS;
  3311. }
  3312. /**
  3313. * qla4xxx_eh_host_reset - kernel callback
  3314. * @cmd: Pointer to Linux's SCSI command structure
  3315. *
  3316. * This routine is invoked by the Linux kernel to perform fatal error
  3317. * recovery on the specified adapter.
  3318. **/
  3319. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  3320. {
  3321. int return_status = FAILED;
  3322. struct scsi_qla_host *ha;
  3323. ha = to_qla_host(cmd->device->host);
  3324. if (ql4xdontresethba) {
  3325. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  3326. ha->host_no, __func__));
  3327. return FAILED;
  3328. }
  3329. ql4_printk(KERN_INFO, ha,
  3330. "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
  3331. cmd->device->channel, cmd->device->id, cmd->device->lun);
  3332. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  3333. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  3334. "DEAD.\n", ha->host_no, cmd->device->channel,
  3335. __func__));
  3336. return FAILED;
  3337. }
  3338. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  3339. if (is_qla8022(ha))
  3340. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  3341. else
  3342. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  3343. }
  3344. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  3345. return_status = SUCCESS;
  3346. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  3347. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  3348. return return_status;
  3349. }
  3350. static int qla4xxx_context_reset(struct scsi_qla_host *ha)
  3351. {
  3352. uint32_t mbox_cmd[MBOX_REG_COUNT];
  3353. uint32_t mbox_sts[MBOX_REG_COUNT];
  3354. struct addr_ctrl_blk_def *acb = NULL;
  3355. uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
  3356. int rval = QLA_SUCCESS;
  3357. dma_addr_t acb_dma;
  3358. acb = dma_alloc_coherent(&ha->pdev->dev,
  3359. sizeof(struct addr_ctrl_blk_def),
  3360. &acb_dma, GFP_KERNEL);
  3361. if (!acb) {
  3362. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
  3363. __func__);
  3364. rval = -ENOMEM;
  3365. goto exit_port_reset;
  3366. }
  3367. memset(acb, 0, acb_len);
  3368. rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
  3369. if (rval != QLA_SUCCESS) {
  3370. rval = -EIO;
  3371. goto exit_free_acb;
  3372. }
  3373. rval = qla4xxx_disable_acb(ha);
  3374. if (rval != QLA_SUCCESS) {
  3375. rval = -EIO;
  3376. goto exit_free_acb;
  3377. }
  3378. wait_for_completion_timeout(&ha->disable_acb_comp,
  3379. DISABLE_ACB_TOV * HZ);
  3380. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
  3381. if (rval != QLA_SUCCESS) {
  3382. rval = -EIO;
  3383. goto exit_free_acb;
  3384. }
  3385. exit_free_acb:
  3386. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
  3387. acb, acb_dma);
  3388. exit_port_reset:
  3389. DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
  3390. rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
  3391. return rval;
  3392. }
  3393. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
  3394. {
  3395. struct scsi_qla_host *ha = to_qla_host(shost);
  3396. int rval = QLA_SUCCESS;
  3397. if (ql4xdontresethba) {
  3398. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
  3399. __func__));
  3400. rval = -EPERM;
  3401. goto exit_host_reset;
  3402. }
  3403. rval = qla4xxx_wait_for_hba_online(ha);
  3404. if (rval != QLA_SUCCESS) {
  3405. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unable to reset host "
  3406. "adapter\n", __func__));
  3407. rval = -EIO;
  3408. goto exit_host_reset;
  3409. }
  3410. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  3411. goto recover_adapter;
  3412. switch (reset_type) {
  3413. case SCSI_ADAPTER_RESET:
  3414. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  3415. break;
  3416. case SCSI_FIRMWARE_RESET:
  3417. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  3418. if (is_qla8022(ha))
  3419. /* set firmware context reset */
  3420. set_bit(DPC_RESET_HA_FW_CONTEXT,
  3421. &ha->dpc_flags);
  3422. else {
  3423. rval = qla4xxx_context_reset(ha);
  3424. goto exit_host_reset;
  3425. }
  3426. }
  3427. break;
  3428. }
  3429. recover_adapter:
  3430. rval = qla4xxx_recover_adapter(ha);
  3431. if (rval != QLA_SUCCESS) {
  3432. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
  3433. __func__));
  3434. rval = -EIO;
  3435. }
  3436. exit_host_reset:
  3437. return rval;
  3438. }
  3439. /* PCI AER driver recovers from all correctable errors w/o
  3440. * driver intervention. For uncorrectable errors PCI AER
  3441. * driver calls the following device driver's callbacks
  3442. *
  3443. * - Fatal Errors - link_reset
  3444. * - Non-Fatal Errors - driver's pci_error_detected() which
  3445. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  3446. *
  3447. * PCI AER driver calls
  3448. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  3449. * returns RECOVERED or NEED_RESET if fw_hung
  3450. * NEED_RESET - driver's slot_reset()
  3451. * DISCONNECT - device is dead & cannot recover
  3452. * RECOVERED - driver's pci_resume()
  3453. */
  3454. static pci_ers_result_t
  3455. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  3456. {
  3457. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  3458. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  3459. ha->host_no, __func__, state);
  3460. if (!is_aer_supported(ha))
  3461. return PCI_ERS_RESULT_NONE;
  3462. switch (state) {
  3463. case pci_channel_io_normal:
  3464. clear_bit(AF_EEH_BUSY, &ha->flags);
  3465. return PCI_ERS_RESULT_CAN_RECOVER;
  3466. case pci_channel_io_frozen:
  3467. set_bit(AF_EEH_BUSY, &ha->flags);
  3468. qla4xxx_mailbox_premature_completion(ha);
  3469. qla4xxx_free_irqs(ha);
  3470. pci_disable_device(pdev);
  3471. /* Return back all IOs */
  3472. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  3473. return PCI_ERS_RESULT_NEED_RESET;
  3474. case pci_channel_io_perm_failure:
  3475. set_bit(AF_EEH_BUSY, &ha->flags);
  3476. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  3477. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  3478. return PCI_ERS_RESULT_DISCONNECT;
  3479. }
  3480. return PCI_ERS_RESULT_NEED_RESET;
  3481. }
  3482. /**
  3483. * qla4xxx_pci_mmio_enabled() gets called if
  3484. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  3485. * and read/write to the device still works.
  3486. **/
  3487. static pci_ers_result_t
  3488. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  3489. {
  3490. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  3491. if (!is_aer_supported(ha))
  3492. return PCI_ERS_RESULT_NONE;
  3493. return PCI_ERS_RESULT_RECOVERED;
  3494. }
  3495. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  3496. {
  3497. uint32_t rval = QLA_ERROR;
  3498. uint32_t ret = 0;
  3499. int fn;
  3500. struct pci_dev *other_pdev = NULL;
  3501. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  3502. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  3503. if (test_bit(AF_ONLINE, &ha->flags)) {
  3504. clear_bit(AF_ONLINE, &ha->flags);
  3505. clear_bit(AF_LINK_UP, &ha->flags);
  3506. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  3507. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  3508. }
  3509. fn = PCI_FUNC(ha->pdev->devfn);
  3510. while (fn > 0) {
  3511. fn--;
  3512. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
  3513. "func %x\n", ha->host_no, __func__, fn);
  3514. /* Get the pci device given the domain, bus,
  3515. * slot/function number */
  3516. other_pdev =
  3517. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  3518. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  3519. fn));
  3520. if (!other_pdev)
  3521. continue;
  3522. if (atomic_read(&other_pdev->enable_cnt)) {
  3523. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
  3524. "func in enabled state%x\n", ha->host_no,
  3525. __func__, fn);
  3526. pci_dev_put(other_pdev);
  3527. break;
  3528. }
  3529. pci_dev_put(other_pdev);
  3530. }
  3531. /* The first function on the card, the reset owner will
  3532. * start & initialize the firmware. The other functions
  3533. * on the card will reset the firmware context
  3534. */
  3535. if (!fn) {
  3536. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  3537. "0x%x is the owner\n", ha->host_no, __func__,
  3538. ha->pdev->devfn);
  3539. qla4_8xxx_idc_lock(ha);
  3540. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3541. QLA82XX_DEV_COLD);
  3542. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
  3543. QLA82XX_IDC_VERSION);
  3544. qla4_8xxx_idc_unlock(ha);
  3545. clear_bit(AF_FW_RECOVERY, &ha->flags);
  3546. rval = qla4xxx_initialize_adapter(ha);
  3547. qla4_8xxx_idc_lock(ha);
  3548. if (rval != QLA_SUCCESS) {
  3549. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  3550. "FAILED\n", ha->host_no, __func__);
  3551. qla4_8xxx_clear_drv_active(ha);
  3552. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3553. QLA82XX_DEV_FAILED);
  3554. } else {
  3555. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  3556. "READY\n", ha->host_no, __func__);
  3557. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3558. QLA82XX_DEV_READY);
  3559. /* Clear driver state register */
  3560. qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
  3561. qla4_8xxx_set_drv_active(ha);
  3562. ret = qla4xxx_request_irqs(ha);
  3563. if (ret) {
  3564. ql4_printk(KERN_WARNING, ha, "Failed to "
  3565. "reserve interrupt %d already in use.\n",
  3566. ha->pdev->irq);
  3567. rval = QLA_ERROR;
  3568. } else {
  3569. ha->isp_ops->enable_intrs(ha);
  3570. rval = QLA_SUCCESS;
  3571. }
  3572. }
  3573. qla4_8xxx_idc_unlock(ha);
  3574. } else {
  3575. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  3576. "the reset owner\n", ha->host_no, __func__,
  3577. ha->pdev->devfn);
  3578. if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
  3579. QLA82XX_DEV_READY)) {
  3580. clear_bit(AF_FW_RECOVERY, &ha->flags);
  3581. rval = qla4xxx_initialize_adapter(ha);
  3582. if (rval == QLA_SUCCESS) {
  3583. ret = qla4xxx_request_irqs(ha);
  3584. if (ret) {
  3585. ql4_printk(KERN_WARNING, ha, "Failed to"
  3586. " reserve interrupt %d already in"
  3587. " use.\n", ha->pdev->irq);
  3588. rval = QLA_ERROR;
  3589. } else {
  3590. ha->isp_ops->enable_intrs(ha);
  3591. rval = QLA_SUCCESS;
  3592. }
  3593. }
  3594. qla4_8xxx_idc_lock(ha);
  3595. qla4_8xxx_set_drv_active(ha);
  3596. qla4_8xxx_idc_unlock(ha);
  3597. }
  3598. }
  3599. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  3600. return rval;
  3601. }
  3602. static pci_ers_result_t
  3603. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  3604. {
  3605. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  3606. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  3607. int rc;
  3608. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  3609. ha->host_no, __func__);
  3610. if (!is_aer_supported(ha))
  3611. return PCI_ERS_RESULT_NONE;
  3612. /* Restore the saved state of PCIe device -
  3613. * BAR registers, PCI Config space, PCIX, MSI,
  3614. * IOV states
  3615. */
  3616. pci_restore_state(pdev);
  3617. /* pci_restore_state() clears the saved_state flag of the device
  3618. * save restored state which resets saved_state flag
  3619. */
  3620. pci_save_state(pdev);
  3621. /* Initialize device or resume if in suspended state */
  3622. rc = pci_enable_device(pdev);
  3623. if (rc) {
  3624. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  3625. "device after reset\n", ha->host_no, __func__);
  3626. goto exit_slot_reset;
  3627. }
  3628. ha->isp_ops->disable_intrs(ha);
  3629. if (is_qla8022(ha)) {
  3630. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  3631. ret = PCI_ERS_RESULT_RECOVERED;
  3632. goto exit_slot_reset;
  3633. } else
  3634. goto exit_slot_reset;
  3635. }
  3636. exit_slot_reset:
  3637. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  3638. "device after reset\n", ha->host_no, __func__, ret);
  3639. return ret;
  3640. }
  3641. static void
  3642. qla4xxx_pci_resume(struct pci_dev *pdev)
  3643. {
  3644. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  3645. int ret;
  3646. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  3647. ha->host_no, __func__);
  3648. ret = qla4xxx_wait_for_hba_online(ha);
  3649. if (ret != QLA_SUCCESS) {
  3650. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  3651. "resume I/O from slot/link_reset\n", ha->host_no,
  3652. __func__);
  3653. }
  3654. pci_cleanup_aer_uncorrect_error_status(pdev);
  3655. clear_bit(AF_EEH_BUSY, &ha->flags);
  3656. }
  3657. static struct pci_error_handlers qla4xxx_err_handler = {
  3658. .error_detected = qla4xxx_pci_error_detected,
  3659. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  3660. .slot_reset = qla4xxx_pci_slot_reset,
  3661. .resume = qla4xxx_pci_resume,
  3662. };
  3663. static struct pci_device_id qla4xxx_pci_tbl[] = {
  3664. {
  3665. .vendor = PCI_VENDOR_ID_QLOGIC,
  3666. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  3667. .subvendor = PCI_ANY_ID,
  3668. .subdevice = PCI_ANY_ID,
  3669. },
  3670. {
  3671. .vendor = PCI_VENDOR_ID_QLOGIC,
  3672. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  3673. .subvendor = PCI_ANY_ID,
  3674. .subdevice = PCI_ANY_ID,
  3675. },
  3676. {
  3677. .vendor = PCI_VENDOR_ID_QLOGIC,
  3678. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  3679. .subvendor = PCI_ANY_ID,
  3680. .subdevice = PCI_ANY_ID,
  3681. },
  3682. {
  3683. .vendor = PCI_VENDOR_ID_QLOGIC,
  3684. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  3685. .subvendor = PCI_ANY_ID,
  3686. .subdevice = PCI_ANY_ID,
  3687. },
  3688. {0, 0},
  3689. };
  3690. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  3691. static struct pci_driver qla4xxx_pci_driver = {
  3692. .name = DRIVER_NAME,
  3693. .id_table = qla4xxx_pci_tbl,
  3694. .probe = qla4xxx_probe_adapter,
  3695. .remove = qla4xxx_remove_adapter,
  3696. .err_handler = &qla4xxx_err_handler,
  3697. };
  3698. static int __init qla4xxx_module_init(void)
  3699. {
  3700. int ret;
  3701. /* Allocate cache for SRBs. */
  3702. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  3703. SLAB_HWCACHE_ALIGN, NULL);
  3704. if (srb_cachep == NULL) {
  3705. printk(KERN_ERR
  3706. "%s: Unable to allocate SRB cache..."
  3707. "Failing load!\n", DRIVER_NAME);
  3708. ret = -ENOMEM;
  3709. goto no_srp_cache;
  3710. }
  3711. /* Derive version string. */
  3712. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  3713. if (ql4xextended_error_logging)
  3714. strcat(qla4xxx_version_str, "-debug");
  3715. qla4xxx_scsi_transport =
  3716. iscsi_register_transport(&qla4xxx_iscsi_transport);
  3717. if (!qla4xxx_scsi_transport){
  3718. ret = -ENODEV;
  3719. goto release_srb_cache;
  3720. }
  3721. ret = pci_register_driver(&qla4xxx_pci_driver);
  3722. if (ret)
  3723. goto unregister_transport;
  3724. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  3725. return 0;
  3726. unregister_transport:
  3727. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  3728. release_srb_cache:
  3729. kmem_cache_destroy(srb_cachep);
  3730. no_srp_cache:
  3731. return ret;
  3732. }
  3733. static void __exit qla4xxx_module_exit(void)
  3734. {
  3735. pci_unregister_driver(&qla4xxx_pci_driver);
  3736. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  3737. kmem_cache_destroy(srb_cachep);
  3738. }
  3739. module_init(qla4xxx_module_init);
  3740. module_exit(qla4xxx_module_exit);
  3741. MODULE_AUTHOR("QLogic Corporation");
  3742. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  3743. MODULE_LICENSE("GPL");
  3744. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);