ql4_os.c 146 KB

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