be_main.c 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829
  1. /**
  2. * Copyright (C) 2005 - 2014 Emulex
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation. The full GNU General
  8. * Public License is included in this distribution in the file called COPYING.
  9. *
  10. * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
  11. *
  12. * Contact Information:
  13. * linux-drivers@emulex.com
  14. *
  15. * Emulex
  16. * 3333 Susan Street
  17. * Costa Mesa, CA 92626
  18. */
  19. #include <linux/reboot.h>
  20. #include <linux/delay.h>
  21. #include <linux/slab.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/blkdev.h>
  24. #include <linux/pci.h>
  25. #include <linux/string.h>
  26. #include <linux/kernel.h>
  27. #include <linux/semaphore.h>
  28. #include <linux/iscsi_boot_sysfs.h>
  29. #include <linux/module.h>
  30. #include <linux/bsg-lib.h>
  31. #include <scsi/libiscsi.h>
  32. #include <scsi/scsi_bsg_iscsi.h>
  33. #include <scsi/scsi_netlink.h>
  34. #include <scsi/scsi_transport_iscsi.h>
  35. #include <scsi/scsi_transport.h>
  36. #include <scsi/scsi_cmnd.h>
  37. #include <scsi/scsi_device.h>
  38. #include <scsi/scsi_host.h>
  39. #include <scsi/scsi.h>
  40. #include "be_main.h"
  41. #include "be_iscsi.h"
  42. #include "be_mgmt.h"
  43. #include "be_cmds.h"
  44. static unsigned int be_iopoll_budget = 10;
  45. static unsigned int be_max_phys_size = 64;
  46. static unsigned int enable_msix = 1;
  47. MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
  48. MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
  49. MODULE_VERSION(BUILD_STR);
  50. MODULE_AUTHOR("Emulex Corporation");
  51. MODULE_LICENSE("GPL");
  52. module_param(be_iopoll_budget, int, 0);
  53. module_param(enable_msix, int, 0);
  54. module_param(be_max_phys_size, uint, S_IRUGO);
  55. MODULE_PARM_DESC(be_max_phys_size,
  56. "Maximum Size (In Kilobytes) of physically contiguous "
  57. "memory that can be allocated. Range is 16 - 128");
  58. #define beiscsi_disp_param(_name)\
  59. ssize_t \
  60. beiscsi_##_name##_disp(struct device *dev,\
  61. struct device_attribute *attrib, char *buf) \
  62. { \
  63. struct Scsi_Host *shost = class_to_shost(dev);\
  64. struct beiscsi_hba *phba = iscsi_host_priv(shost); \
  65. uint32_t param_val = 0; \
  66. param_val = phba->attr_##_name;\
  67. return snprintf(buf, PAGE_SIZE, "%d\n",\
  68. phba->attr_##_name);\
  69. }
  70. #define beiscsi_change_param(_name, _minval, _maxval, _defaval)\
  71. int \
  72. beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\
  73. {\
  74. if (val >= _minval && val <= _maxval) {\
  75. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
  76. "BA_%d : beiscsi_"#_name" updated "\
  77. "from 0x%x ==> 0x%x\n",\
  78. phba->attr_##_name, val); \
  79. phba->attr_##_name = val;\
  80. return 0;\
  81. } \
  82. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \
  83. "BA_%d beiscsi_"#_name" attribute "\
  84. "cannot be updated to 0x%x, "\
  85. "range allowed is ["#_minval" - "#_maxval"]\n", val);\
  86. return -EINVAL;\
  87. }
  88. #define beiscsi_store_param(_name) \
  89. ssize_t \
  90. beiscsi_##_name##_store(struct device *dev,\
  91. struct device_attribute *attr, const char *buf,\
  92. size_t count) \
  93. { \
  94. struct Scsi_Host *shost = class_to_shost(dev);\
  95. struct beiscsi_hba *phba = iscsi_host_priv(shost);\
  96. uint32_t param_val = 0;\
  97. if (!isdigit(buf[0]))\
  98. return -EINVAL;\
  99. if (sscanf(buf, "%i", &param_val) != 1)\
  100. return -EINVAL;\
  101. if (beiscsi_##_name##_change(phba, param_val) == 0) \
  102. return strlen(buf);\
  103. else \
  104. return -EINVAL;\
  105. }
  106. #define beiscsi_init_param(_name, _minval, _maxval, _defval) \
  107. int \
  108. beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \
  109. { \
  110. if (val >= _minval && val <= _maxval) {\
  111. phba->attr_##_name = val;\
  112. return 0;\
  113. } \
  114. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
  115. "BA_%d beiscsi_"#_name" attribute " \
  116. "cannot be updated to 0x%x, "\
  117. "range allowed is ["#_minval" - "#_maxval"]\n", val);\
  118. phba->attr_##_name = _defval;\
  119. return -EINVAL;\
  120. }
  121. #define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \
  122. static uint beiscsi_##_name = _defval;\
  123. module_param(beiscsi_##_name, uint, S_IRUGO);\
  124. MODULE_PARM_DESC(beiscsi_##_name, _descp);\
  125. beiscsi_disp_param(_name)\
  126. beiscsi_change_param(_name, _minval, _maxval, _defval)\
  127. beiscsi_store_param(_name)\
  128. beiscsi_init_param(_name, _minval, _maxval, _defval)\
  129. DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\
  130. beiscsi_##_name##_disp, beiscsi_##_name##_store)
  131. /*
  132. * When new log level added update the
  133. * the MAX allowed value for log_enable
  134. */
  135. BEISCSI_RW_ATTR(log_enable, 0x00,
  136. 0xFF, 0x00, "Enable logging Bit Mask\n"
  137. "\t\t\t\tInitialization Events : 0x01\n"
  138. "\t\t\t\tMailbox Events : 0x02\n"
  139. "\t\t\t\tMiscellaneous Events : 0x04\n"
  140. "\t\t\t\tError Handling : 0x08\n"
  141. "\t\t\t\tIO Path Events : 0x10\n"
  142. "\t\t\t\tConfiguration Path : 0x20\n"
  143. "\t\t\t\tiSCSI Protocol : 0x40\n");
  144. DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL);
  145. DEVICE_ATTR(beiscsi_adapter_family, S_IRUGO, beiscsi_adap_family_disp, NULL);
  146. DEVICE_ATTR(beiscsi_fw_ver, S_IRUGO, beiscsi_fw_ver_disp, NULL);
  147. DEVICE_ATTR(beiscsi_phys_port, S_IRUGO, beiscsi_phys_port_disp, NULL);
  148. DEVICE_ATTR(beiscsi_active_session_count, S_IRUGO,
  149. beiscsi_active_session_disp, NULL);
  150. DEVICE_ATTR(beiscsi_free_session_count, S_IRUGO,
  151. beiscsi_free_session_disp, NULL);
  152. struct device_attribute *beiscsi_attrs[] = {
  153. &dev_attr_beiscsi_log_enable,
  154. &dev_attr_beiscsi_drvr_ver,
  155. &dev_attr_beiscsi_adapter_family,
  156. &dev_attr_beiscsi_fw_ver,
  157. &dev_attr_beiscsi_active_session_count,
  158. &dev_attr_beiscsi_free_session_count,
  159. &dev_attr_beiscsi_phys_port,
  160. NULL,
  161. };
  162. static char const *cqe_desc[] = {
  163. "RESERVED_DESC",
  164. "SOL_CMD_COMPLETE",
  165. "SOL_CMD_KILLED_DATA_DIGEST_ERR",
  166. "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
  167. "CXN_KILLED_BURST_LEN_MISMATCH",
  168. "CXN_KILLED_AHS_RCVD",
  169. "CXN_KILLED_HDR_DIGEST_ERR",
  170. "CXN_KILLED_UNKNOWN_HDR",
  171. "CXN_KILLED_STALE_ITT_TTT_RCVD",
  172. "CXN_KILLED_INVALID_ITT_TTT_RCVD",
  173. "CXN_KILLED_RST_RCVD",
  174. "CXN_KILLED_TIMED_OUT",
  175. "CXN_KILLED_RST_SENT",
  176. "CXN_KILLED_FIN_RCVD",
  177. "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
  178. "CXN_KILLED_BAD_WRB_INDEX_ERROR",
  179. "CXN_KILLED_OVER_RUN_RESIDUAL",
  180. "CXN_KILLED_UNDER_RUN_RESIDUAL",
  181. "CMD_KILLED_INVALID_STATSN_RCVD",
  182. "CMD_KILLED_INVALID_R2T_RCVD",
  183. "CMD_CXN_KILLED_LUN_INVALID",
  184. "CMD_CXN_KILLED_ICD_INVALID",
  185. "CMD_CXN_KILLED_ITT_INVALID",
  186. "CMD_CXN_KILLED_SEQ_OUTOFORDER",
  187. "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
  188. "CXN_INVALIDATE_NOTIFY",
  189. "CXN_INVALIDATE_INDEX_NOTIFY",
  190. "CMD_INVALIDATED_NOTIFY",
  191. "UNSOL_HDR_NOTIFY",
  192. "UNSOL_DATA_NOTIFY",
  193. "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
  194. "DRIVERMSG_NOTIFY",
  195. "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
  196. "SOL_CMD_KILLED_DIF_ERR",
  197. "CXN_KILLED_SYN_RCVD",
  198. "CXN_KILLED_IMM_DATA_RCVD"
  199. };
  200. static int beiscsi_slave_configure(struct scsi_device *sdev)
  201. {
  202. blk_queue_max_segment_size(sdev->request_queue, 65536);
  203. return 0;
  204. }
  205. static int beiscsi_eh_abort(struct scsi_cmnd *sc)
  206. {
  207. struct iscsi_cls_session *cls_session;
  208. struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
  209. struct beiscsi_io_task *aborted_io_task;
  210. struct iscsi_conn *conn;
  211. struct beiscsi_conn *beiscsi_conn;
  212. struct beiscsi_hba *phba;
  213. struct iscsi_session *session;
  214. struct invalidate_command_table *inv_tbl;
  215. struct be_dma_mem nonemb_cmd;
  216. unsigned int cid, tag, num_invalidate;
  217. int rc;
  218. cls_session = starget_to_session(scsi_target(sc->device));
  219. session = cls_session->dd_data;
  220. spin_lock_bh(&session->frwd_lock);
  221. if (!aborted_task || !aborted_task->sc) {
  222. /* we raced */
  223. spin_unlock_bh(&session->frwd_lock);
  224. return SUCCESS;
  225. }
  226. aborted_io_task = aborted_task->dd_data;
  227. if (!aborted_io_task->scsi_cmnd) {
  228. /* raced or invalid command */
  229. spin_unlock_bh(&session->frwd_lock);
  230. return SUCCESS;
  231. }
  232. spin_unlock_bh(&session->frwd_lock);
  233. /* Invalidate WRB Posted for this Task */
  234. AMAP_SET_BITS(struct amap_iscsi_wrb, invld,
  235. aborted_io_task->pwrb_handle->pwrb,
  236. 1);
  237. conn = aborted_task->conn;
  238. beiscsi_conn = conn->dd_data;
  239. phba = beiscsi_conn->phba;
  240. /* invalidate iocb */
  241. cid = beiscsi_conn->beiscsi_conn_cid;
  242. inv_tbl = phba->inv_tbl;
  243. memset(inv_tbl, 0x0, sizeof(*inv_tbl));
  244. inv_tbl->cid = cid;
  245. inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
  246. num_invalidate = 1;
  247. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  248. sizeof(struct invalidate_commands_params_in),
  249. &nonemb_cmd.dma);
  250. if (nonemb_cmd.va == NULL) {
  251. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
  252. "BM_%d : Failed to allocate memory for"
  253. "mgmt_invalidate_icds\n");
  254. return FAILED;
  255. }
  256. nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
  257. tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
  258. cid, &nonemb_cmd);
  259. if (!tag) {
  260. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
  261. "BM_%d : mgmt_invalidate_icds could not be"
  262. "submitted\n");
  263. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  264. nonemb_cmd.va, nonemb_cmd.dma);
  265. return FAILED;
  266. }
  267. rc = beiscsi_mccq_compl(phba, tag, NULL, &nonemb_cmd);
  268. if (rc != -EBUSY)
  269. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  270. nonemb_cmd.va, nonemb_cmd.dma);
  271. return iscsi_eh_abort(sc);
  272. }
  273. static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
  274. {
  275. struct iscsi_task *abrt_task;
  276. struct beiscsi_io_task *abrt_io_task;
  277. struct iscsi_conn *conn;
  278. struct beiscsi_conn *beiscsi_conn;
  279. struct beiscsi_hba *phba;
  280. struct iscsi_session *session;
  281. struct iscsi_cls_session *cls_session;
  282. struct invalidate_command_table *inv_tbl;
  283. struct be_dma_mem nonemb_cmd;
  284. unsigned int cid, tag, i, num_invalidate;
  285. int rc;
  286. /* invalidate iocbs */
  287. cls_session = starget_to_session(scsi_target(sc->device));
  288. session = cls_session->dd_data;
  289. spin_lock_bh(&session->frwd_lock);
  290. if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
  291. spin_unlock_bh(&session->frwd_lock);
  292. return FAILED;
  293. }
  294. conn = session->leadconn;
  295. beiscsi_conn = conn->dd_data;
  296. phba = beiscsi_conn->phba;
  297. cid = beiscsi_conn->beiscsi_conn_cid;
  298. inv_tbl = phba->inv_tbl;
  299. memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
  300. num_invalidate = 0;
  301. for (i = 0; i < conn->session->cmds_max; i++) {
  302. abrt_task = conn->session->cmds[i];
  303. abrt_io_task = abrt_task->dd_data;
  304. if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
  305. continue;
  306. if (sc->device->lun != abrt_task->sc->device->lun)
  307. continue;
  308. /* Invalidate WRB Posted for this Task */
  309. AMAP_SET_BITS(struct amap_iscsi_wrb, invld,
  310. abrt_io_task->pwrb_handle->pwrb,
  311. 1);
  312. inv_tbl->cid = cid;
  313. inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
  314. num_invalidate++;
  315. inv_tbl++;
  316. }
  317. spin_unlock_bh(&session->frwd_lock);
  318. inv_tbl = phba->inv_tbl;
  319. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  320. sizeof(struct invalidate_commands_params_in),
  321. &nonemb_cmd.dma);
  322. if (nonemb_cmd.va == NULL) {
  323. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
  324. "BM_%d : Failed to allocate memory for"
  325. "mgmt_invalidate_icds\n");
  326. return FAILED;
  327. }
  328. nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
  329. memset(nonemb_cmd.va, 0, nonemb_cmd.size);
  330. tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
  331. cid, &nonemb_cmd);
  332. if (!tag) {
  333. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
  334. "BM_%d : mgmt_invalidate_icds could not be"
  335. " submitted\n");
  336. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  337. nonemb_cmd.va, nonemb_cmd.dma);
  338. return FAILED;
  339. }
  340. rc = beiscsi_mccq_compl(phba, tag, NULL, &nonemb_cmd);
  341. if (rc != -EBUSY)
  342. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  343. nonemb_cmd.va, nonemb_cmd.dma);
  344. return iscsi_eh_device_reset(sc);
  345. }
  346. static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
  347. {
  348. struct beiscsi_hba *phba = data;
  349. struct mgmt_session_info *boot_sess = &phba->boot_sess;
  350. struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
  351. char *str = buf;
  352. int rc;
  353. switch (type) {
  354. case ISCSI_BOOT_TGT_NAME:
  355. rc = sprintf(buf, "%.*s\n",
  356. (int)strlen(boot_sess->target_name),
  357. (char *)&boot_sess->target_name);
  358. break;
  359. case ISCSI_BOOT_TGT_IP_ADDR:
  360. if (boot_conn->dest_ipaddr.ip_type == 0x1)
  361. rc = sprintf(buf, "%pI4\n",
  362. (char *)&boot_conn->dest_ipaddr.addr);
  363. else
  364. rc = sprintf(str, "%pI6\n",
  365. (char *)&boot_conn->dest_ipaddr.addr);
  366. break;
  367. case ISCSI_BOOT_TGT_PORT:
  368. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  369. break;
  370. case ISCSI_BOOT_TGT_CHAP_NAME:
  371. rc = sprintf(str, "%.*s\n",
  372. boot_conn->negotiated_login_options.auth_data.chap.
  373. target_chap_name_length,
  374. (char *)&boot_conn->negotiated_login_options.
  375. auth_data.chap.target_chap_name);
  376. break;
  377. case ISCSI_BOOT_TGT_CHAP_SECRET:
  378. rc = sprintf(str, "%.*s\n",
  379. boot_conn->negotiated_login_options.auth_data.chap.
  380. target_secret_length,
  381. (char *)&boot_conn->negotiated_login_options.
  382. auth_data.chap.target_secret);
  383. break;
  384. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  385. rc = sprintf(str, "%.*s\n",
  386. boot_conn->negotiated_login_options.auth_data.chap.
  387. intr_chap_name_length,
  388. (char *)&boot_conn->negotiated_login_options.
  389. auth_data.chap.intr_chap_name);
  390. break;
  391. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  392. rc = sprintf(str, "%.*s\n",
  393. boot_conn->negotiated_login_options.auth_data.chap.
  394. intr_secret_length,
  395. (char *)&boot_conn->negotiated_login_options.
  396. auth_data.chap.intr_secret);
  397. break;
  398. case ISCSI_BOOT_TGT_FLAGS:
  399. rc = sprintf(str, "2\n");
  400. break;
  401. case ISCSI_BOOT_TGT_NIC_ASSOC:
  402. rc = sprintf(str, "0\n");
  403. break;
  404. default:
  405. rc = -ENOSYS;
  406. break;
  407. }
  408. return rc;
  409. }
  410. static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
  411. {
  412. struct beiscsi_hba *phba = data;
  413. char *str = buf;
  414. int rc;
  415. switch (type) {
  416. case ISCSI_BOOT_INI_INITIATOR_NAME:
  417. rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
  418. break;
  419. default:
  420. rc = -ENOSYS;
  421. break;
  422. }
  423. return rc;
  424. }
  425. static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
  426. {
  427. struct beiscsi_hba *phba = data;
  428. char *str = buf;
  429. int rc;
  430. switch (type) {
  431. case ISCSI_BOOT_ETH_FLAGS:
  432. rc = sprintf(str, "2\n");
  433. break;
  434. case ISCSI_BOOT_ETH_INDEX:
  435. rc = sprintf(str, "0\n");
  436. break;
  437. case ISCSI_BOOT_ETH_MAC:
  438. rc = beiscsi_get_macaddr(str, phba);
  439. break;
  440. default:
  441. rc = -ENOSYS;
  442. break;
  443. }
  444. return rc;
  445. }
  446. static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
  447. {
  448. umode_t rc;
  449. switch (type) {
  450. case ISCSI_BOOT_TGT_NAME:
  451. case ISCSI_BOOT_TGT_IP_ADDR:
  452. case ISCSI_BOOT_TGT_PORT:
  453. case ISCSI_BOOT_TGT_CHAP_NAME:
  454. case ISCSI_BOOT_TGT_CHAP_SECRET:
  455. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  456. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  457. case ISCSI_BOOT_TGT_NIC_ASSOC:
  458. case ISCSI_BOOT_TGT_FLAGS:
  459. rc = S_IRUGO;
  460. break;
  461. default:
  462. rc = 0;
  463. break;
  464. }
  465. return rc;
  466. }
  467. static umode_t beiscsi_ini_get_attr_visibility(void *data, int type)
  468. {
  469. umode_t rc;
  470. switch (type) {
  471. case ISCSI_BOOT_INI_INITIATOR_NAME:
  472. rc = S_IRUGO;
  473. break;
  474. default:
  475. rc = 0;
  476. break;
  477. }
  478. return rc;
  479. }
  480. static umode_t beiscsi_eth_get_attr_visibility(void *data, int type)
  481. {
  482. umode_t rc;
  483. switch (type) {
  484. case ISCSI_BOOT_ETH_FLAGS:
  485. case ISCSI_BOOT_ETH_MAC:
  486. case ISCSI_BOOT_ETH_INDEX:
  487. rc = S_IRUGO;
  488. break;
  489. default:
  490. rc = 0;
  491. break;
  492. }
  493. return rc;
  494. }
  495. /*------------------- PCI Driver operations and data ----------------- */
  496. static const struct pci_device_id beiscsi_pci_id_table[] = {
  497. { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
  498. { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
  499. { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
  500. { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
  501. { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
  502. { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) },
  503. { 0 }
  504. };
  505. MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
  506. static struct scsi_host_template beiscsi_sht = {
  507. .module = THIS_MODULE,
  508. .name = "Emulex 10Gbe open-iscsi Initiator Driver",
  509. .proc_name = DRV_NAME,
  510. .queuecommand = iscsi_queuecommand,
  511. .change_queue_depth = iscsi_change_queue_depth,
  512. .slave_configure = beiscsi_slave_configure,
  513. .target_alloc = iscsi_target_alloc,
  514. .eh_abort_handler = beiscsi_eh_abort,
  515. .eh_device_reset_handler = beiscsi_eh_device_reset,
  516. .eh_target_reset_handler = iscsi_eh_session_reset,
  517. .shost_attrs = beiscsi_attrs,
  518. .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
  519. .can_queue = BE2_IO_DEPTH,
  520. .this_id = -1,
  521. .max_sectors = BEISCSI_MAX_SECTORS,
  522. .cmd_per_lun = BEISCSI_CMD_PER_LUN,
  523. .use_clustering = ENABLE_CLUSTERING,
  524. .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
  525. };
  526. static struct scsi_transport_template *beiscsi_scsi_transport;
  527. static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
  528. {
  529. struct beiscsi_hba *phba;
  530. struct Scsi_Host *shost;
  531. shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
  532. if (!shost) {
  533. dev_err(&pcidev->dev,
  534. "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
  535. return NULL;
  536. }
  537. shost->max_id = BE2_MAX_SESSIONS;
  538. shost->max_channel = 0;
  539. shost->max_cmd_len = BEISCSI_MAX_CMD_LEN;
  540. shost->max_lun = BEISCSI_NUM_MAX_LUN;
  541. shost->transportt = beiscsi_scsi_transport;
  542. phba = iscsi_host_priv(shost);
  543. memset(phba, 0, sizeof(*phba));
  544. phba->shost = shost;
  545. phba->pcidev = pci_dev_get(pcidev);
  546. pci_set_drvdata(pcidev, phba);
  547. phba->interface_handle = 0xFFFFFFFF;
  548. return phba;
  549. }
  550. static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
  551. {
  552. if (phba->csr_va) {
  553. iounmap(phba->csr_va);
  554. phba->csr_va = NULL;
  555. }
  556. if (phba->db_va) {
  557. iounmap(phba->db_va);
  558. phba->db_va = NULL;
  559. }
  560. if (phba->pci_va) {
  561. iounmap(phba->pci_va);
  562. phba->pci_va = NULL;
  563. }
  564. }
  565. static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
  566. struct pci_dev *pcidev)
  567. {
  568. u8 __iomem *addr;
  569. int pcicfg_reg;
  570. addr = ioremap_nocache(pci_resource_start(pcidev, 2),
  571. pci_resource_len(pcidev, 2));
  572. if (addr == NULL)
  573. return -ENOMEM;
  574. phba->ctrl.csr = addr;
  575. phba->csr_va = addr;
  576. phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
  577. addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
  578. if (addr == NULL)
  579. goto pci_map_err;
  580. phba->ctrl.db = addr;
  581. phba->db_va = addr;
  582. phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
  583. if (phba->generation == BE_GEN2)
  584. pcicfg_reg = 1;
  585. else
  586. pcicfg_reg = 0;
  587. addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
  588. pci_resource_len(pcidev, pcicfg_reg));
  589. if (addr == NULL)
  590. goto pci_map_err;
  591. phba->ctrl.pcicfg = addr;
  592. phba->pci_va = addr;
  593. phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
  594. return 0;
  595. pci_map_err:
  596. beiscsi_unmap_pci_function(phba);
  597. return -ENOMEM;
  598. }
  599. static int beiscsi_enable_pci(struct pci_dev *pcidev)
  600. {
  601. int ret;
  602. ret = pci_enable_device(pcidev);
  603. if (ret) {
  604. dev_err(&pcidev->dev,
  605. "beiscsi_enable_pci - enable device failed\n");
  606. return ret;
  607. }
  608. pci_set_master(pcidev);
  609. ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64));
  610. if (ret) {
  611. ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
  612. if (ret) {
  613. dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
  614. pci_disable_device(pcidev);
  615. return ret;
  616. } else {
  617. ret = pci_set_consistent_dma_mask(pcidev,
  618. DMA_BIT_MASK(32));
  619. }
  620. } else {
  621. ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
  622. if (ret) {
  623. dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
  624. pci_disable_device(pcidev);
  625. return ret;
  626. }
  627. }
  628. return 0;
  629. }
  630. static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
  631. {
  632. struct be_ctrl_info *ctrl = &phba->ctrl;
  633. struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
  634. struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
  635. int status = 0;
  636. ctrl->pdev = pdev;
  637. status = beiscsi_map_pci_bars(phba, pdev);
  638. if (status)
  639. return status;
  640. mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
  641. mbox_mem_alloc->va = pci_alloc_consistent(pdev,
  642. mbox_mem_alloc->size,
  643. &mbox_mem_alloc->dma);
  644. if (!mbox_mem_alloc->va) {
  645. beiscsi_unmap_pci_function(phba);
  646. return -ENOMEM;
  647. }
  648. mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
  649. mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
  650. mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
  651. memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
  652. spin_lock_init(&ctrl->mbox_lock);
  653. spin_lock_init(&phba->ctrl.mcc_lock);
  654. spin_lock_init(&phba->ctrl.mcc_cq_lock);
  655. return status;
  656. }
  657. /**
  658. * beiscsi_get_params()- Set the config paramters
  659. * @phba: ptr device priv structure
  660. **/
  661. static void beiscsi_get_params(struct beiscsi_hba *phba)
  662. {
  663. uint32_t total_cid_count = 0;
  664. uint32_t total_icd_count = 0;
  665. uint8_t ulp_num = 0;
  666. total_cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) +
  667. BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1);
  668. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  669. uint32_t align_mask = 0;
  670. uint32_t icd_post_per_page = 0;
  671. uint32_t icd_count_unavailable = 0;
  672. uint32_t icd_start = 0, icd_count = 0;
  673. uint32_t icd_start_align = 0, icd_count_align = 0;
  674. if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
  675. icd_start = phba->fw_config.iscsi_icd_start[ulp_num];
  676. icd_count = phba->fw_config.iscsi_icd_count[ulp_num];
  677. /* Get ICD count that can be posted on each page */
  678. icd_post_per_page = (PAGE_SIZE / (BE2_SGE *
  679. sizeof(struct iscsi_sge)));
  680. align_mask = (icd_post_per_page - 1);
  681. /* Check if icd_start is aligned ICD per page posting */
  682. if (icd_start % icd_post_per_page) {
  683. icd_start_align = ((icd_start +
  684. icd_post_per_page) &
  685. ~(align_mask));
  686. phba->fw_config.
  687. iscsi_icd_start[ulp_num] =
  688. icd_start_align;
  689. }
  690. icd_count_align = (icd_count & ~align_mask);
  691. /* ICD discarded in the process of alignment */
  692. if (icd_start_align)
  693. icd_count_unavailable = ((icd_start_align -
  694. icd_start) +
  695. (icd_count -
  696. icd_count_align));
  697. /* Updated ICD count available */
  698. phba->fw_config.iscsi_icd_count[ulp_num] = (icd_count -
  699. icd_count_unavailable);
  700. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  701. "BM_%d : Aligned ICD values\n"
  702. "\t ICD Start : %d\n"
  703. "\t ICD Count : %d\n"
  704. "\t ICD Discarded : %d\n",
  705. phba->fw_config.
  706. iscsi_icd_start[ulp_num],
  707. phba->fw_config.
  708. iscsi_icd_count[ulp_num],
  709. icd_count_unavailable);
  710. break;
  711. }
  712. }
  713. total_icd_count = phba->fw_config.iscsi_icd_count[ulp_num];
  714. phba->params.ios_per_ctrl = (total_icd_count -
  715. (total_cid_count +
  716. BE2_TMFS + BE2_NOPOUT_REQ));
  717. phba->params.cxns_per_ctrl = total_cid_count;
  718. phba->params.asyncpdus_per_ctrl = total_cid_count;
  719. phba->params.icds_per_ctrl = total_icd_count;
  720. phba->params.num_sge_per_io = BE2_SGE;
  721. phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
  722. phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
  723. phba->params.eq_timer = 64;
  724. phba->params.num_eq_entries = 1024;
  725. phba->params.num_cq_entries = 1024;
  726. phba->params.wrbs_per_cxn = 256;
  727. }
  728. static void hwi_ring_eq_db(struct beiscsi_hba *phba,
  729. unsigned int id, unsigned int clr_interrupt,
  730. unsigned int num_processed,
  731. unsigned char rearm, unsigned char event)
  732. {
  733. u32 val = 0;
  734. if (rearm)
  735. val |= 1 << DB_EQ_REARM_SHIFT;
  736. if (clr_interrupt)
  737. val |= 1 << DB_EQ_CLR_SHIFT;
  738. if (event)
  739. val |= 1 << DB_EQ_EVNT_SHIFT;
  740. val |= num_processed << DB_EQ_NUM_POPPED_SHIFT;
  741. /* Setting lower order EQ_ID Bits */
  742. val |= (id & DB_EQ_RING_ID_LOW_MASK);
  743. /* Setting Higher order EQ_ID Bits */
  744. val |= (((id >> DB_EQ_HIGH_FEILD_SHIFT) &
  745. DB_EQ_RING_ID_HIGH_MASK)
  746. << DB_EQ_HIGH_SET_SHIFT);
  747. iowrite32(val, phba->db_va + DB_EQ_OFFSET);
  748. }
  749. /**
  750. * be_isr_mcc - The isr routine of the driver.
  751. * @irq: Not used
  752. * @dev_id: Pointer to host adapter structure
  753. */
  754. static irqreturn_t be_isr_mcc(int irq, void *dev_id)
  755. {
  756. struct beiscsi_hba *phba;
  757. struct be_eq_entry *eqe = NULL;
  758. struct be_queue_info *eq;
  759. struct be_queue_info *mcc;
  760. unsigned int num_eq_processed;
  761. struct be_eq_obj *pbe_eq;
  762. unsigned long flags;
  763. pbe_eq = dev_id;
  764. eq = &pbe_eq->q;
  765. phba = pbe_eq->phba;
  766. mcc = &phba->ctrl.mcc_obj.cq;
  767. eqe = queue_tail_node(eq);
  768. num_eq_processed = 0;
  769. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  770. & EQE_VALID_MASK) {
  771. if (((eqe->dw[offsetof(struct amap_eq_entry,
  772. resource_id) / 32] &
  773. EQE_RESID_MASK) >> 16) == mcc->id) {
  774. spin_lock_irqsave(&phba->isr_lock, flags);
  775. pbe_eq->todo_mcc_cq = true;
  776. spin_unlock_irqrestore(&phba->isr_lock, flags);
  777. }
  778. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  779. queue_tail_inc(eq);
  780. eqe = queue_tail_node(eq);
  781. num_eq_processed++;
  782. }
  783. if (pbe_eq->todo_mcc_cq)
  784. queue_work(phba->wq, &pbe_eq->work_cqs);
  785. if (num_eq_processed)
  786. hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1);
  787. return IRQ_HANDLED;
  788. }
  789. /**
  790. * be_isr_msix - The isr routine of the driver.
  791. * @irq: Not used
  792. * @dev_id: Pointer to host adapter structure
  793. */
  794. static irqreturn_t be_isr_msix(int irq, void *dev_id)
  795. {
  796. struct beiscsi_hba *phba;
  797. struct be_eq_entry *eqe = NULL;
  798. struct be_queue_info *eq;
  799. struct be_queue_info *cq;
  800. unsigned int num_eq_processed;
  801. struct be_eq_obj *pbe_eq;
  802. pbe_eq = dev_id;
  803. eq = &pbe_eq->q;
  804. cq = pbe_eq->cq;
  805. eqe = queue_tail_node(eq);
  806. phba = pbe_eq->phba;
  807. num_eq_processed = 0;
  808. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  809. & EQE_VALID_MASK) {
  810. if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
  811. blk_iopoll_sched(&pbe_eq->iopoll);
  812. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  813. queue_tail_inc(eq);
  814. eqe = queue_tail_node(eq);
  815. num_eq_processed++;
  816. }
  817. if (num_eq_processed)
  818. hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 0, 1);
  819. return IRQ_HANDLED;
  820. }
  821. /**
  822. * be_isr - The isr routine of the driver.
  823. * @irq: Not used
  824. * @dev_id: Pointer to host adapter structure
  825. */
  826. static irqreturn_t be_isr(int irq, void *dev_id)
  827. {
  828. struct beiscsi_hba *phba;
  829. struct hwi_controller *phwi_ctrlr;
  830. struct hwi_context_memory *phwi_context;
  831. struct be_eq_entry *eqe = NULL;
  832. struct be_queue_info *eq;
  833. struct be_queue_info *mcc;
  834. unsigned long flags, index;
  835. unsigned int num_mcceq_processed, num_ioeq_processed;
  836. struct be_ctrl_info *ctrl;
  837. struct be_eq_obj *pbe_eq;
  838. int isr;
  839. phba = dev_id;
  840. ctrl = &phba->ctrl;
  841. isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
  842. (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
  843. if (!isr)
  844. return IRQ_NONE;
  845. phwi_ctrlr = phba->phwi_ctrlr;
  846. phwi_context = phwi_ctrlr->phwi_ctxt;
  847. pbe_eq = &phwi_context->be_eq[0];
  848. eq = &phwi_context->be_eq[0].q;
  849. mcc = &phba->ctrl.mcc_obj.cq;
  850. index = 0;
  851. eqe = queue_tail_node(eq);
  852. num_ioeq_processed = 0;
  853. num_mcceq_processed = 0;
  854. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  855. & EQE_VALID_MASK) {
  856. if (((eqe->dw[offsetof(struct amap_eq_entry,
  857. resource_id) / 32] &
  858. EQE_RESID_MASK) >> 16) == mcc->id) {
  859. spin_lock_irqsave(&phba->isr_lock, flags);
  860. pbe_eq->todo_mcc_cq = true;
  861. spin_unlock_irqrestore(&phba->isr_lock, flags);
  862. num_mcceq_processed++;
  863. } else {
  864. if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
  865. blk_iopoll_sched(&pbe_eq->iopoll);
  866. num_ioeq_processed++;
  867. }
  868. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  869. queue_tail_inc(eq);
  870. eqe = queue_tail_node(eq);
  871. }
  872. if (num_ioeq_processed || num_mcceq_processed) {
  873. if (pbe_eq->todo_mcc_cq)
  874. queue_work(phba->wq, &pbe_eq->work_cqs);
  875. if ((num_mcceq_processed) && (!num_ioeq_processed))
  876. hwi_ring_eq_db(phba, eq->id, 0,
  877. (num_ioeq_processed +
  878. num_mcceq_processed) , 1, 1);
  879. else
  880. hwi_ring_eq_db(phba, eq->id, 0,
  881. (num_ioeq_processed +
  882. num_mcceq_processed), 0, 1);
  883. return IRQ_HANDLED;
  884. } else
  885. return IRQ_NONE;
  886. }
  887. static int beiscsi_init_irqs(struct beiscsi_hba *phba)
  888. {
  889. struct pci_dev *pcidev = phba->pcidev;
  890. struct hwi_controller *phwi_ctrlr;
  891. struct hwi_context_memory *phwi_context;
  892. int ret, msix_vec, i, j;
  893. phwi_ctrlr = phba->phwi_ctrlr;
  894. phwi_context = phwi_ctrlr->phwi_ctxt;
  895. if (phba->msix_enabled) {
  896. for (i = 0; i < phba->num_cpus; i++) {
  897. phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
  898. GFP_KERNEL);
  899. if (!phba->msi_name[i]) {
  900. ret = -ENOMEM;
  901. goto free_msix_irqs;
  902. }
  903. sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
  904. phba->shost->host_no, i);
  905. msix_vec = phba->msix_entries[i].vector;
  906. ret = request_irq(msix_vec, be_isr_msix, 0,
  907. phba->msi_name[i],
  908. &phwi_context->be_eq[i]);
  909. if (ret) {
  910. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  911. "BM_%d : beiscsi_init_irqs-Failed to"
  912. "register msix for i = %d\n",
  913. i);
  914. kfree(phba->msi_name[i]);
  915. goto free_msix_irqs;
  916. }
  917. }
  918. phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
  919. if (!phba->msi_name[i]) {
  920. ret = -ENOMEM;
  921. goto free_msix_irqs;
  922. }
  923. sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
  924. phba->shost->host_no);
  925. msix_vec = phba->msix_entries[i].vector;
  926. ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i],
  927. &phwi_context->be_eq[i]);
  928. if (ret) {
  929. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT ,
  930. "BM_%d : beiscsi_init_irqs-"
  931. "Failed to register beiscsi_msix_mcc\n");
  932. kfree(phba->msi_name[i]);
  933. goto free_msix_irqs;
  934. }
  935. } else {
  936. ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED,
  937. "beiscsi", phba);
  938. if (ret) {
  939. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  940. "BM_%d : beiscsi_init_irqs-"
  941. "Failed to register irq\\n");
  942. return ret;
  943. }
  944. }
  945. return 0;
  946. free_msix_irqs:
  947. for (j = i - 1; j >= 0; j--) {
  948. kfree(phba->msi_name[j]);
  949. msix_vec = phba->msix_entries[j].vector;
  950. free_irq(msix_vec, &phwi_context->be_eq[j]);
  951. }
  952. return ret;
  953. }
  954. void hwi_ring_cq_db(struct beiscsi_hba *phba,
  955. unsigned int id, unsigned int num_processed,
  956. unsigned char rearm, unsigned char event)
  957. {
  958. u32 val = 0;
  959. if (rearm)
  960. val |= 1 << DB_CQ_REARM_SHIFT;
  961. val |= num_processed << DB_CQ_NUM_POPPED_SHIFT;
  962. /* Setting lower order CQ_ID Bits */
  963. val |= (id & DB_CQ_RING_ID_LOW_MASK);
  964. /* Setting Higher order CQ_ID Bits */
  965. val |= (((id >> DB_CQ_HIGH_FEILD_SHIFT) &
  966. DB_CQ_RING_ID_HIGH_MASK)
  967. << DB_CQ_HIGH_SET_SHIFT);
  968. iowrite32(val, phba->db_va + DB_CQ_OFFSET);
  969. }
  970. static unsigned int
  971. beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,
  972. struct beiscsi_hba *phba,
  973. struct pdu_base *ppdu,
  974. unsigned long pdu_len,
  975. void *pbuffer, unsigned long buf_len)
  976. {
  977. struct iscsi_conn *conn = beiscsi_conn->conn;
  978. struct iscsi_session *session = conn->session;
  979. struct iscsi_task *task;
  980. struct beiscsi_io_task *io_task;
  981. struct iscsi_hdr *login_hdr;
  982. switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] &
  983. PDUBASE_OPCODE_MASK) {
  984. case ISCSI_OP_NOOP_IN:
  985. pbuffer = NULL;
  986. buf_len = 0;
  987. break;
  988. case ISCSI_OP_ASYNC_EVENT:
  989. break;
  990. case ISCSI_OP_REJECT:
  991. WARN_ON(!pbuffer);
  992. WARN_ON(!(buf_len == 48));
  993. beiscsi_log(phba, KERN_ERR,
  994. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  995. "BM_%d : In ISCSI_OP_REJECT\n");
  996. break;
  997. case ISCSI_OP_LOGIN_RSP:
  998. case ISCSI_OP_TEXT_RSP:
  999. task = conn->login_task;
  1000. io_task = task->dd_data;
  1001. login_hdr = (struct iscsi_hdr *)ppdu;
  1002. login_hdr->itt = io_task->libiscsi_itt;
  1003. break;
  1004. default:
  1005. beiscsi_log(phba, KERN_WARNING,
  1006. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1007. "BM_%d : Unrecognized opcode 0x%x in async msg\n",
  1008. (ppdu->
  1009. dw[offsetof(struct amap_pdu_base, opcode) / 32]
  1010. & PDUBASE_OPCODE_MASK));
  1011. return 1;
  1012. }
  1013. spin_lock_bh(&session->back_lock);
  1014. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len);
  1015. spin_unlock_bh(&session->back_lock);
  1016. return 0;
  1017. }
  1018. static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
  1019. {
  1020. struct sgl_handle *psgl_handle;
  1021. if (phba->io_sgl_hndl_avbl) {
  1022. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
  1023. "BM_%d : In alloc_io_sgl_handle,"
  1024. " io_sgl_alloc_index=%d\n",
  1025. phba->io_sgl_alloc_index);
  1026. psgl_handle = phba->io_sgl_hndl_base[phba->
  1027. io_sgl_alloc_index];
  1028. phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
  1029. phba->io_sgl_hndl_avbl--;
  1030. if (phba->io_sgl_alloc_index == (phba->params.
  1031. ios_per_ctrl - 1))
  1032. phba->io_sgl_alloc_index = 0;
  1033. else
  1034. phba->io_sgl_alloc_index++;
  1035. } else
  1036. psgl_handle = NULL;
  1037. return psgl_handle;
  1038. }
  1039. static void
  1040. free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
  1041. {
  1042. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
  1043. "BM_%d : In free_,io_sgl_free_index=%d\n",
  1044. phba->io_sgl_free_index);
  1045. if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
  1046. /*
  1047. * this can happen if clean_task is called on a task that
  1048. * failed in xmit_task or alloc_pdu.
  1049. */
  1050. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
  1051. "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
  1052. "value there=%p\n", phba->io_sgl_free_index,
  1053. phba->io_sgl_hndl_base
  1054. [phba->io_sgl_free_index]);
  1055. return;
  1056. }
  1057. phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
  1058. phba->io_sgl_hndl_avbl++;
  1059. if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
  1060. phba->io_sgl_free_index = 0;
  1061. else
  1062. phba->io_sgl_free_index++;
  1063. }
  1064. /**
  1065. * alloc_wrb_handle - To allocate a wrb handle
  1066. * @phba: The hba pointer
  1067. * @cid: The cid to use for allocation
  1068. *
  1069. * This happens under session_lock until submission to chip
  1070. */
  1071. struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid)
  1072. {
  1073. struct hwi_wrb_context *pwrb_context;
  1074. struct hwi_controller *phwi_ctrlr;
  1075. struct wrb_handle *pwrb_handle, *pwrb_handle_tmp;
  1076. uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
  1077. phwi_ctrlr = phba->phwi_ctrlr;
  1078. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  1079. if (pwrb_context->wrb_handles_available >= 2) {
  1080. pwrb_handle = pwrb_context->pwrb_handle_base[
  1081. pwrb_context->alloc_index];
  1082. pwrb_context->wrb_handles_available--;
  1083. if (pwrb_context->alloc_index ==
  1084. (phba->params.wrbs_per_cxn - 1))
  1085. pwrb_context->alloc_index = 0;
  1086. else
  1087. pwrb_context->alloc_index++;
  1088. pwrb_handle_tmp = pwrb_context->pwrb_handle_base[
  1089. pwrb_context->alloc_index];
  1090. pwrb_handle->nxt_wrb_index = pwrb_handle_tmp->wrb_index;
  1091. } else
  1092. pwrb_handle = NULL;
  1093. return pwrb_handle;
  1094. }
  1095. /**
  1096. * free_wrb_handle - To free the wrb handle back to pool
  1097. * @phba: The hba pointer
  1098. * @pwrb_context: The context to free from
  1099. * @pwrb_handle: The wrb_handle to free
  1100. *
  1101. * This happens under session_lock until submission to chip
  1102. */
  1103. static void
  1104. free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
  1105. struct wrb_handle *pwrb_handle)
  1106. {
  1107. pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
  1108. pwrb_context->wrb_handles_available++;
  1109. if (pwrb_context->free_index == (phba->params.wrbs_per_cxn - 1))
  1110. pwrb_context->free_index = 0;
  1111. else
  1112. pwrb_context->free_index++;
  1113. beiscsi_log(phba, KERN_INFO,
  1114. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1115. "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
  1116. "wrb_handles_available=%d\n",
  1117. pwrb_handle, pwrb_context->free_index,
  1118. pwrb_context->wrb_handles_available);
  1119. }
  1120. static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
  1121. {
  1122. struct sgl_handle *psgl_handle;
  1123. if (phba->eh_sgl_hndl_avbl) {
  1124. psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
  1125. phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
  1126. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1127. "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
  1128. phba->eh_sgl_alloc_index,
  1129. phba->eh_sgl_alloc_index);
  1130. phba->eh_sgl_hndl_avbl--;
  1131. if (phba->eh_sgl_alloc_index ==
  1132. (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl -
  1133. 1))
  1134. phba->eh_sgl_alloc_index = 0;
  1135. else
  1136. phba->eh_sgl_alloc_index++;
  1137. } else
  1138. psgl_handle = NULL;
  1139. return psgl_handle;
  1140. }
  1141. void
  1142. free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
  1143. {
  1144. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1145. "BM_%d : In free_mgmt_sgl_handle,"
  1146. "eh_sgl_free_index=%d\n",
  1147. phba->eh_sgl_free_index);
  1148. if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) {
  1149. /*
  1150. * this can happen if clean_task is called on a task that
  1151. * failed in xmit_task or alloc_pdu.
  1152. */
  1153. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  1154. "BM_%d : Double Free in eh SGL ,"
  1155. "eh_sgl_free_index=%d\n",
  1156. phba->eh_sgl_free_index);
  1157. return;
  1158. }
  1159. phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
  1160. phba->eh_sgl_hndl_avbl++;
  1161. if (phba->eh_sgl_free_index ==
  1162. (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1))
  1163. phba->eh_sgl_free_index = 0;
  1164. else
  1165. phba->eh_sgl_free_index++;
  1166. }
  1167. static void
  1168. be_complete_io(struct beiscsi_conn *beiscsi_conn,
  1169. struct iscsi_task *task,
  1170. struct common_sol_cqe *csol_cqe)
  1171. {
  1172. struct beiscsi_io_task *io_task = task->dd_data;
  1173. struct be_status_bhs *sts_bhs =
  1174. (struct be_status_bhs *)io_task->cmd_bhs;
  1175. struct iscsi_conn *conn = beiscsi_conn->conn;
  1176. unsigned char *sense;
  1177. u32 resid = 0, exp_cmdsn, max_cmdsn;
  1178. u8 rsp, status, flags;
  1179. exp_cmdsn = csol_cqe->exp_cmdsn;
  1180. max_cmdsn = (csol_cqe->exp_cmdsn +
  1181. csol_cqe->cmd_wnd - 1);
  1182. rsp = csol_cqe->i_resp;
  1183. status = csol_cqe->i_sts;
  1184. flags = csol_cqe->i_flags;
  1185. resid = csol_cqe->res_cnt;
  1186. if (!task->sc) {
  1187. if (io_task->scsi_cmnd) {
  1188. scsi_dma_unmap(io_task->scsi_cmnd);
  1189. io_task->scsi_cmnd = NULL;
  1190. }
  1191. return;
  1192. }
  1193. task->sc->result = (DID_OK << 16) | status;
  1194. if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
  1195. task->sc->result = DID_ERROR << 16;
  1196. goto unmap;
  1197. }
  1198. /* bidi not initially supported */
  1199. if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
  1200. if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
  1201. task->sc->result = DID_ERROR << 16;
  1202. if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
  1203. scsi_set_resid(task->sc, resid);
  1204. if (!status && (scsi_bufflen(task->sc) - resid <
  1205. task->sc->underflow))
  1206. task->sc->result = DID_ERROR << 16;
  1207. }
  1208. }
  1209. if (status == SAM_STAT_CHECK_CONDITION) {
  1210. u16 sense_len;
  1211. unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
  1212. sense = sts_bhs->sense_info + sizeof(unsigned short);
  1213. sense_len = be16_to_cpu(*slen);
  1214. memcpy(task->sc->sense_buffer, sense,
  1215. min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
  1216. }
  1217. if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ)
  1218. conn->rxdata_octets += resid;
  1219. unmap:
  1220. scsi_dma_unmap(io_task->scsi_cmnd);
  1221. io_task->scsi_cmnd = NULL;
  1222. iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
  1223. }
  1224. static void
  1225. be_complete_logout(struct beiscsi_conn *beiscsi_conn,
  1226. struct iscsi_task *task,
  1227. struct common_sol_cqe *csol_cqe)
  1228. {
  1229. struct iscsi_logout_rsp *hdr;
  1230. struct beiscsi_io_task *io_task = task->dd_data;
  1231. struct iscsi_conn *conn = beiscsi_conn->conn;
  1232. hdr = (struct iscsi_logout_rsp *)task->hdr;
  1233. hdr->opcode = ISCSI_OP_LOGOUT_RSP;
  1234. hdr->t2wait = 5;
  1235. hdr->t2retain = 0;
  1236. hdr->flags = csol_cqe->i_flags;
  1237. hdr->response = csol_cqe->i_resp;
  1238. hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
  1239. hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
  1240. csol_cqe->cmd_wnd - 1);
  1241. hdr->dlength[0] = 0;
  1242. hdr->dlength[1] = 0;
  1243. hdr->dlength[2] = 0;
  1244. hdr->hlength = 0;
  1245. hdr->itt = io_task->libiscsi_itt;
  1246. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1247. }
  1248. static void
  1249. be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
  1250. struct iscsi_task *task,
  1251. struct common_sol_cqe *csol_cqe)
  1252. {
  1253. struct iscsi_tm_rsp *hdr;
  1254. struct iscsi_conn *conn = beiscsi_conn->conn;
  1255. struct beiscsi_io_task *io_task = task->dd_data;
  1256. hdr = (struct iscsi_tm_rsp *)task->hdr;
  1257. hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
  1258. hdr->flags = csol_cqe->i_flags;
  1259. hdr->response = csol_cqe->i_resp;
  1260. hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
  1261. hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
  1262. csol_cqe->cmd_wnd - 1);
  1263. hdr->itt = io_task->libiscsi_itt;
  1264. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1265. }
  1266. static void
  1267. hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
  1268. struct beiscsi_hba *phba, struct sol_cqe *psol)
  1269. {
  1270. struct hwi_wrb_context *pwrb_context;
  1271. struct wrb_handle *pwrb_handle = NULL;
  1272. struct hwi_controller *phwi_ctrlr;
  1273. struct iscsi_task *task;
  1274. struct beiscsi_io_task *io_task;
  1275. uint16_t wrb_index, cid, cri_index;
  1276. phwi_ctrlr = phba->phwi_ctrlr;
  1277. if (is_chip_be2_be3r(phba)) {
  1278. wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
  1279. wrb_idx, psol);
  1280. cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
  1281. cid, psol);
  1282. } else {
  1283. wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
  1284. wrb_idx, psol);
  1285. cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
  1286. cid, psol);
  1287. }
  1288. cri_index = BE_GET_CRI_FROM_CID(cid);
  1289. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  1290. pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index];
  1291. task = pwrb_handle->pio_handle;
  1292. io_task = task->dd_data;
  1293. memset(io_task->pwrb_handle->pwrb, 0, sizeof(struct iscsi_wrb));
  1294. iscsi_put_task(task);
  1295. }
  1296. static void
  1297. be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
  1298. struct iscsi_task *task,
  1299. struct common_sol_cqe *csol_cqe)
  1300. {
  1301. struct iscsi_nopin *hdr;
  1302. struct iscsi_conn *conn = beiscsi_conn->conn;
  1303. struct beiscsi_io_task *io_task = task->dd_data;
  1304. hdr = (struct iscsi_nopin *)task->hdr;
  1305. hdr->flags = csol_cqe->i_flags;
  1306. hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
  1307. hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
  1308. csol_cqe->cmd_wnd - 1);
  1309. hdr->opcode = ISCSI_OP_NOOP_IN;
  1310. hdr->itt = io_task->libiscsi_itt;
  1311. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1312. }
  1313. static void adapter_get_sol_cqe(struct beiscsi_hba *phba,
  1314. struct sol_cqe *psol,
  1315. struct common_sol_cqe *csol_cqe)
  1316. {
  1317. if (is_chip_be2_be3r(phba)) {
  1318. csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe,
  1319. i_exp_cmd_sn, psol);
  1320. csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe,
  1321. i_res_cnt, psol);
  1322. csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe,
  1323. i_cmd_wnd, psol);
  1324. csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe,
  1325. wrb_index, psol);
  1326. csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe,
  1327. cid, psol);
  1328. csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe,
  1329. hw_sts, psol);
  1330. csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe,
  1331. i_resp, psol);
  1332. csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe,
  1333. i_sts, psol);
  1334. csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe,
  1335. i_flags, psol);
  1336. } else {
  1337. csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1338. i_exp_cmd_sn, psol);
  1339. csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1340. i_res_cnt, psol);
  1341. csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1342. wrb_index, psol);
  1343. csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1344. cid, psol);
  1345. csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1346. hw_sts, psol);
  1347. csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1348. i_cmd_wnd, psol);
  1349. if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1350. cmd_cmpl, psol))
  1351. csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1352. i_sts, psol);
  1353. else
  1354. csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1355. i_sts, psol);
  1356. if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1357. u, psol))
  1358. csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW;
  1359. if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1360. o, psol))
  1361. csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW;
  1362. }
  1363. }
  1364. static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
  1365. struct beiscsi_hba *phba, struct sol_cqe *psol)
  1366. {
  1367. struct hwi_wrb_context *pwrb_context;
  1368. struct wrb_handle *pwrb_handle;
  1369. struct iscsi_wrb *pwrb = NULL;
  1370. struct hwi_controller *phwi_ctrlr;
  1371. struct iscsi_task *task;
  1372. unsigned int type;
  1373. struct iscsi_conn *conn = beiscsi_conn->conn;
  1374. struct iscsi_session *session = conn->session;
  1375. struct common_sol_cqe csol_cqe = {0};
  1376. uint16_t cri_index = 0;
  1377. phwi_ctrlr = phba->phwi_ctrlr;
  1378. /* Copy the elements to a common structure */
  1379. adapter_get_sol_cqe(phba, psol, &csol_cqe);
  1380. cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid);
  1381. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  1382. pwrb_handle = pwrb_context->pwrb_handle_basestd[
  1383. csol_cqe.wrb_index];
  1384. task = pwrb_handle->pio_handle;
  1385. pwrb = pwrb_handle->pwrb;
  1386. type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type;
  1387. spin_lock_bh(&session->back_lock);
  1388. switch (type) {
  1389. case HWH_TYPE_IO:
  1390. case HWH_TYPE_IO_RD:
  1391. if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
  1392. ISCSI_OP_NOOP_OUT)
  1393. be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
  1394. else
  1395. be_complete_io(beiscsi_conn, task, &csol_cqe);
  1396. break;
  1397. case HWH_TYPE_LOGOUT:
  1398. if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
  1399. be_complete_logout(beiscsi_conn, task, &csol_cqe);
  1400. else
  1401. be_complete_tmf(beiscsi_conn, task, &csol_cqe);
  1402. break;
  1403. case HWH_TYPE_LOGIN:
  1404. beiscsi_log(phba, KERN_ERR,
  1405. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1406. "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
  1407. " hwi_complete_cmd- Solicited path\n");
  1408. break;
  1409. case HWH_TYPE_NOP:
  1410. be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
  1411. break;
  1412. default:
  1413. beiscsi_log(phba, KERN_WARNING,
  1414. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1415. "BM_%d : In hwi_complete_cmd, unknown type = %d"
  1416. "wrb_index 0x%x CID 0x%x\n", type,
  1417. csol_cqe.wrb_index,
  1418. csol_cqe.cid);
  1419. break;
  1420. }
  1421. spin_unlock_bh(&session->back_lock);
  1422. }
  1423. static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
  1424. *pasync_ctx, unsigned int is_header,
  1425. unsigned int host_write_ptr)
  1426. {
  1427. if (is_header)
  1428. return &pasync_ctx->async_entry[host_write_ptr].
  1429. header_busy_list;
  1430. else
  1431. return &pasync_ctx->async_entry[host_write_ptr].data_busy_list;
  1432. }
  1433. static struct async_pdu_handle *
  1434. hwi_get_async_handle(struct beiscsi_hba *phba,
  1435. struct beiscsi_conn *beiscsi_conn,
  1436. struct hwi_async_pdu_context *pasync_ctx,
  1437. struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index)
  1438. {
  1439. struct be_bus_address phys_addr;
  1440. struct list_head *pbusy_list;
  1441. struct async_pdu_handle *pasync_handle = NULL;
  1442. unsigned char is_header = 0;
  1443. unsigned int index, dpl;
  1444. if (is_chip_be2_be3r(phba)) {
  1445. dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
  1446. dpl, pdpdu_cqe);
  1447. index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
  1448. index, pdpdu_cqe);
  1449. } else {
  1450. dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
  1451. dpl, pdpdu_cqe);
  1452. index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
  1453. index, pdpdu_cqe);
  1454. }
  1455. phys_addr.u.a32.address_lo =
  1456. (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1457. db_addr_lo) / 32] - dpl);
  1458. phys_addr.u.a32.address_hi =
  1459. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1460. db_addr_hi) / 32];
  1461. phys_addr.u.a64.address =
  1462. *((unsigned long long *)(&phys_addr.u.a64.address));
  1463. switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
  1464. & PDUCQE_CODE_MASK) {
  1465. case UNSOL_HDR_NOTIFY:
  1466. is_header = 1;
  1467. pbusy_list = hwi_get_async_busy_list(pasync_ctx,
  1468. is_header, index);
  1469. break;
  1470. case UNSOL_DATA_NOTIFY:
  1471. pbusy_list = hwi_get_async_busy_list(pasync_ctx,
  1472. is_header, index);
  1473. break;
  1474. default:
  1475. pbusy_list = NULL;
  1476. beiscsi_log(phba, KERN_WARNING,
  1477. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1478. "BM_%d : Unexpected code=%d\n",
  1479. pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
  1480. code) / 32] & PDUCQE_CODE_MASK);
  1481. return NULL;
  1482. }
  1483. WARN_ON(list_empty(pbusy_list));
  1484. list_for_each_entry(pasync_handle, pbusy_list, link) {
  1485. if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address)
  1486. break;
  1487. }
  1488. WARN_ON(!pasync_handle);
  1489. pasync_handle->cri = BE_GET_ASYNC_CRI_FROM_CID(
  1490. beiscsi_conn->beiscsi_conn_cid);
  1491. pasync_handle->is_header = is_header;
  1492. pasync_handle->buffer_len = dpl;
  1493. *pcq_index = index;
  1494. return pasync_handle;
  1495. }
  1496. static unsigned int
  1497. hwi_update_async_writables(struct beiscsi_hba *phba,
  1498. struct hwi_async_pdu_context *pasync_ctx,
  1499. unsigned int is_header, unsigned int cq_index)
  1500. {
  1501. struct list_head *pbusy_list;
  1502. struct async_pdu_handle *pasync_handle;
  1503. unsigned int num_entries, writables = 0;
  1504. unsigned int *pep_read_ptr, *pwritables;
  1505. num_entries = pasync_ctx->num_entries;
  1506. if (is_header) {
  1507. pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
  1508. pwritables = &pasync_ctx->async_header.writables;
  1509. } else {
  1510. pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
  1511. pwritables = &pasync_ctx->async_data.writables;
  1512. }
  1513. while ((*pep_read_ptr) != cq_index) {
  1514. (*pep_read_ptr)++;
  1515. *pep_read_ptr = (*pep_read_ptr) % num_entries;
  1516. pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
  1517. *pep_read_ptr);
  1518. if (writables == 0)
  1519. WARN_ON(list_empty(pbusy_list));
  1520. if (!list_empty(pbusy_list)) {
  1521. pasync_handle = list_entry(pbusy_list->next,
  1522. struct async_pdu_handle,
  1523. link);
  1524. WARN_ON(!pasync_handle);
  1525. pasync_handle->consumed = 1;
  1526. }
  1527. writables++;
  1528. }
  1529. if (!writables) {
  1530. beiscsi_log(phba, KERN_ERR,
  1531. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1532. "BM_%d : Duplicate notification received - index 0x%x!!\n",
  1533. cq_index);
  1534. WARN_ON(1);
  1535. }
  1536. *pwritables = *pwritables + writables;
  1537. return 0;
  1538. }
  1539. static void hwi_free_async_msg(struct beiscsi_hba *phba,
  1540. struct hwi_async_pdu_context *pasync_ctx,
  1541. unsigned int cri)
  1542. {
  1543. struct async_pdu_handle *pasync_handle, *tmp_handle;
  1544. struct list_head *plist;
  1545. plist = &pasync_ctx->async_entry[cri].wait_queue.list;
  1546. list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
  1547. list_del(&pasync_handle->link);
  1548. if (pasync_handle->is_header) {
  1549. list_add_tail(&pasync_handle->link,
  1550. &pasync_ctx->async_header.free_list);
  1551. pasync_ctx->async_header.free_entries++;
  1552. } else {
  1553. list_add_tail(&pasync_handle->link,
  1554. &pasync_ctx->async_data.free_list);
  1555. pasync_ctx->async_data.free_entries++;
  1556. }
  1557. }
  1558. INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
  1559. pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
  1560. pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
  1561. }
  1562. static struct phys_addr *
  1563. hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
  1564. unsigned int is_header, unsigned int host_write_ptr)
  1565. {
  1566. struct phys_addr *pasync_sge = NULL;
  1567. if (is_header)
  1568. pasync_sge = pasync_ctx->async_header.ring_base;
  1569. else
  1570. pasync_sge = pasync_ctx->async_data.ring_base;
  1571. return pasync_sge + host_write_ptr;
  1572. }
  1573. static void hwi_post_async_buffers(struct beiscsi_hba *phba,
  1574. unsigned int is_header, uint8_t ulp_num)
  1575. {
  1576. struct hwi_controller *phwi_ctrlr;
  1577. struct hwi_async_pdu_context *pasync_ctx;
  1578. struct async_pdu_handle *pasync_handle;
  1579. struct list_head *pfree_link, *pbusy_list;
  1580. struct phys_addr *pasync_sge;
  1581. unsigned int ring_id, num_entries;
  1582. unsigned int host_write_num, doorbell_offset;
  1583. unsigned int writables;
  1584. unsigned int i = 0;
  1585. u32 doorbell = 0;
  1586. phwi_ctrlr = phba->phwi_ctrlr;
  1587. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num);
  1588. num_entries = pasync_ctx->num_entries;
  1589. if (is_header) {
  1590. writables = min(pasync_ctx->async_header.writables,
  1591. pasync_ctx->async_header.free_entries);
  1592. pfree_link = pasync_ctx->async_header.free_list.next;
  1593. host_write_num = pasync_ctx->async_header.host_write_ptr;
  1594. ring_id = phwi_ctrlr->default_pdu_hdr[ulp_num].id;
  1595. doorbell_offset = phwi_ctrlr->default_pdu_hdr[ulp_num].
  1596. doorbell_offset;
  1597. } else {
  1598. writables = min(pasync_ctx->async_data.writables,
  1599. pasync_ctx->async_data.free_entries);
  1600. pfree_link = pasync_ctx->async_data.free_list.next;
  1601. host_write_num = pasync_ctx->async_data.host_write_ptr;
  1602. ring_id = phwi_ctrlr->default_pdu_data[ulp_num].id;
  1603. doorbell_offset = phwi_ctrlr->default_pdu_data[ulp_num].
  1604. doorbell_offset;
  1605. }
  1606. writables = (writables / 8) * 8;
  1607. if (writables) {
  1608. for (i = 0; i < writables; i++) {
  1609. pbusy_list =
  1610. hwi_get_async_busy_list(pasync_ctx, is_header,
  1611. host_write_num);
  1612. pasync_handle =
  1613. list_entry(pfree_link, struct async_pdu_handle,
  1614. link);
  1615. WARN_ON(!pasync_handle);
  1616. pasync_handle->consumed = 0;
  1617. pfree_link = pfree_link->next;
  1618. pasync_sge = hwi_get_ring_address(pasync_ctx,
  1619. is_header, host_write_num);
  1620. pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
  1621. pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
  1622. list_move(&pasync_handle->link, pbusy_list);
  1623. host_write_num++;
  1624. host_write_num = host_write_num % num_entries;
  1625. }
  1626. if (is_header) {
  1627. pasync_ctx->async_header.host_write_ptr =
  1628. host_write_num;
  1629. pasync_ctx->async_header.free_entries -= writables;
  1630. pasync_ctx->async_header.writables -= writables;
  1631. pasync_ctx->async_header.busy_entries += writables;
  1632. } else {
  1633. pasync_ctx->async_data.host_write_ptr = host_write_num;
  1634. pasync_ctx->async_data.free_entries -= writables;
  1635. pasync_ctx->async_data.writables -= writables;
  1636. pasync_ctx->async_data.busy_entries += writables;
  1637. }
  1638. doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
  1639. doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
  1640. doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
  1641. doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
  1642. << DB_DEF_PDU_CQPROC_SHIFT;
  1643. iowrite32(doorbell, phba->db_va + doorbell_offset);
  1644. }
  1645. }
  1646. static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
  1647. struct beiscsi_conn *beiscsi_conn,
  1648. struct i_t_dpdu_cqe *pdpdu_cqe)
  1649. {
  1650. struct hwi_controller *phwi_ctrlr;
  1651. struct hwi_async_pdu_context *pasync_ctx;
  1652. struct async_pdu_handle *pasync_handle = NULL;
  1653. unsigned int cq_index = -1;
  1654. uint16_t cri_index = BE_GET_CRI_FROM_CID(
  1655. beiscsi_conn->beiscsi_conn_cid);
  1656. phwi_ctrlr = phba->phwi_ctrlr;
  1657. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
  1658. BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
  1659. cri_index));
  1660. pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
  1661. pdpdu_cqe, &cq_index);
  1662. BUG_ON(pasync_handle->is_header != 0);
  1663. if (pasync_handle->consumed == 0)
  1664. hwi_update_async_writables(phba, pasync_ctx,
  1665. pasync_handle->is_header, cq_index);
  1666. hwi_free_async_msg(phba, pasync_ctx, pasync_handle->cri);
  1667. hwi_post_async_buffers(phba, pasync_handle->is_header,
  1668. BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
  1669. cri_index));
  1670. }
  1671. static unsigned int
  1672. hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
  1673. struct beiscsi_hba *phba,
  1674. struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
  1675. {
  1676. struct list_head *plist;
  1677. struct async_pdu_handle *pasync_handle;
  1678. void *phdr = NULL;
  1679. unsigned int hdr_len = 0, buf_len = 0;
  1680. unsigned int status, index = 0, offset = 0;
  1681. void *pfirst_buffer = NULL;
  1682. unsigned int num_buf = 0;
  1683. plist = &pasync_ctx->async_entry[cri].wait_queue.list;
  1684. list_for_each_entry(pasync_handle, plist, link) {
  1685. if (index == 0) {
  1686. phdr = pasync_handle->pbuffer;
  1687. hdr_len = pasync_handle->buffer_len;
  1688. } else {
  1689. buf_len = pasync_handle->buffer_len;
  1690. if (!num_buf) {
  1691. pfirst_buffer = pasync_handle->pbuffer;
  1692. num_buf++;
  1693. }
  1694. memcpy(pfirst_buffer + offset,
  1695. pasync_handle->pbuffer, buf_len);
  1696. offset += buf_len;
  1697. }
  1698. index++;
  1699. }
  1700. status = beiscsi_process_async_pdu(beiscsi_conn, phba,
  1701. phdr, hdr_len, pfirst_buffer,
  1702. offset);
  1703. hwi_free_async_msg(phba, pasync_ctx, cri);
  1704. return 0;
  1705. }
  1706. static unsigned int
  1707. hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
  1708. struct beiscsi_hba *phba,
  1709. struct async_pdu_handle *pasync_handle)
  1710. {
  1711. struct hwi_async_pdu_context *pasync_ctx;
  1712. struct hwi_controller *phwi_ctrlr;
  1713. unsigned int bytes_needed = 0, status = 0;
  1714. unsigned short cri = pasync_handle->cri;
  1715. struct pdu_base *ppdu;
  1716. phwi_ctrlr = phba->phwi_ctrlr;
  1717. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
  1718. BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
  1719. BE_GET_CRI_FROM_CID(beiscsi_conn->
  1720. beiscsi_conn_cid)));
  1721. list_del(&pasync_handle->link);
  1722. if (pasync_handle->is_header) {
  1723. pasync_ctx->async_header.busy_entries--;
  1724. if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
  1725. hwi_free_async_msg(phba, pasync_ctx, cri);
  1726. BUG();
  1727. }
  1728. pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
  1729. pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
  1730. pasync_ctx->async_entry[cri].wait_queue.hdr_len =
  1731. (unsigned short)pasync_handle->buffer_len;
  1732. list_add_tail(&pasync_handle->link,
  1733. &pasync_ctx->async_entry[cri].wait_queue.list);
  1734. ppdu = pasync_handle->pbuffer;
  1735. bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
  1736. data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
  1737. 0xFFFF0000) | ((be16_to_cpu((ppdu->
  1738. dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
  1739. & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
  1740. if (status == 0) {
  1741. pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
  1742. bytes_needed;
  1743. if (bytes_needed == 0)
  1744. status = hwi_fwd_async_msg(beiscsi_conn, phba,
  1745. pasync_ctx, cri);
  1746. }
  1747. } else {
  1748. pasync_ctx->async_data.busy_entries--;
  1749. if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
  1750. list_add_tail(&pasync_handle->link,
  1751. &pasync_ctx->async_entry[cri].wait_queue.
  1752. list);
  1753. pasync_ctx->async_entry[cri].wait_queue.
  1754. bytes_received +=
  1755. (unsigned short)pasync_handle->buffer_len;
  1756. if (pasync_ctx->async_entry[cri].wait_queue.
  1757. bytes_received >=
  1758. pasync_ctx->async_entry[cri].wait_queue.
  1759. bytes_needed)
  1760. status = hwi_fwd_async_msg(beiscsi_conn, phba,
  1761. pasync_ctx, cri);
  1762. }
  1763. }
  1764. return status;
  1765. }
  1766. static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
  1767. struct beiscsi_hba *phba,
  1768. struct i_t_dpdu_cqe *pdpdu_cqe)
  1769. {
  1770. struct hwi_controller *phwi_ctrlr;
  1771. struct hwi_async_pdu_context *pasync_ctx;
  1772. struct async_pdu_handle *pasync_handle = NULL;
  1773. unsigned int cq_index = -1;
  1774. uint16_t cri_index = BE_GET_CRI_FROM_CID(
  1775. beiscsi_conn->beiscsi_conn_cid);
  1776. phwi_ctrlr = phba->phwi_ctrlr;
  1777. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
  1778. BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
  1779. cri_index));
  1780. pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
  1781. pdpdu_cqe, &cq_index);
  1782. if (pasync_handle->consumed == 0)
  1783. hwi_update_async_writables(phba, pasync_ctx,
  1784. pasync_handle->is_header, cq_index);
  1785. hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
  1786. hwi_post_async_buffers(phba, pasync_handle->is_header,
  1787. BEISCSI_GET_ULP_FROM_CRI(
  1788. phwi_ctrlr, cri_index));
  1789. }
  1790. static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
  1791. {
  1792. struct be_queue_info *mcc_cq;
  1793. struct be_mcc_compl *mcc_compl;
  1794. unsigned int num_processed = 0;
  1795. mcc_cq = &phba->ctrl.mcc_obj.cq;
  1796. mcc_compl = queue_tail_node(mcc_cq);
  1797. mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
  1798. while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
  1799. if (num_processed >= 32) {
  1800. hwi_ring_cq_db(phba, mcc_cq->id,
  1801. num_processed, 0, 0);
  1802. num_processed = 0;
  1803. }
  1804. if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
  1805. /* Interpret flags as an async trailer */
  1806. if (is_link_state_evt(mcc_compl->flags))
  1807. /* Interpret compl as a async link evt */
  1808. beiscsi_async_link_state_process(phba,
  1809. (struct be_async_event_link_state *) mcc_compl);
  1810. else
  1811. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX,
  1812. "BM_%d : Unsupported Async Event, flags"
  1813. " = 0x%08x\n",
  1814. mcc_compl->flags);
  1815. } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
  1816. be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
  1817. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  1818. }
  1819. mcc_compl->flags = 0;
  1820. queue_tail_inc(mcc_cq);
  1821. mcc_compl = queue_tail_node(mcc_cq);
  1822. mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
  1823. num_processed++;
  1824. }
  1825. if (num_processed > 0)
  1826. hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1, 0);
  1827. }
  1828. /**
  1829. * beiscsi_process_cq()- Process the Completion Queue
  1830. * @pbe_eq: Event Q on which the Completion has come
  1831. *
  1832. * return
  1833. * Number of Completion Entries processed.
  1834. **/
  1835. unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
  1836. {
  1837. struct be_queue_info *cq;
  1838. struct sol_cqe *sol;
  1839. struct dmsg_cqe *dmsg;
  1840. unsigned int num_processed = 0;
  1841. unsigned int tot_nump = 0;
  1842. unsigned short code = 0, cid = 0;
  1843. uint16_t cri_index = 0;
  1844. struct beiscsi_conn *beiscsi_conn;
  1845. struct beiscsi_endpoint *beiscsi_ep;
  1846. struct iscsi_endpoint *ep;
  1847. struct beiscsi_hba *phba;
  1848. cq = pbe_eq->cq;
  1849. sol = queue_tail_node(cq);
  1850. phba = pbe_eq->phba;
  1851. while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
  1852. CQE_VALID_MASK) {
  1853. be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
  1854. code = (sol->dw[offsetof(struct amap_sol_cqe, code) /
  1855. 32] & CQE_CODE_MASK);
  1856. /* Get the CID */
  1857. if (is_chip_be2_be3r(phba)) {
  1858. cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol);
  1859. } else {
  1860. if ((code == DRIVERMSG_NOTIFY) ||
  1861. (code == UNSOL_HDR_NOTIFY) ||
  1862. (code == UNSOL_DATA_NOTIFY))
  1863. cid = AMAP_GET_BITS(
  1864. struct amap_i_t_dpdu_cqe_v2,
  1865. cid, sol);
  1866. else
  1867. cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
  1868. cid, sol);
  1869. }
  1870. cri_index = BE_GET_CRI_FROM_CID(cid);
  1871. ep = phba->ep_array[cri_index];
  1872. if (ep == NULL) {
  1873. /* connection has already been freed
  1874. * just move on to next one
  1875. */
  1876. beiscsi_log(phba, KERN_WARNING,
  1877. BEISCSI_LOG_INIT,
  1878. "BM_%d : proc cqe of disconn ep: cid %d\n",
  1879. cid);
  1880. goto proc_next_cqe;
  1881. }
  1882. beiscsi_ep = ep->dd_data;
  1883. beiscsi_conn = beiscsi_ep->conn;
  1884. if (num_processed >= 32) {
  1885. hwi_ring_cq_db(phba, cq->id,
  1886. num_processed, 0, 0);
  1887. tot_nump += num_processed;
  1888. num_processed = 0;
  1889. }
  1890. switch (code) {
  1891. case SOL_CMD_COMPLETE:
  1892. hwi_complete_cmd(beiscsi_conn, phba, sol);
  1893. break;
  1894. case DRIVERMSG_NOTIFY:
  1895. beiscsi_log(phba, KERN_INFO,
  1896. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1897. "BM_%d : Received %s[%d] on CID : %d\n",
  1898. cqe_desc[code], code, cid);
  1899. dmsg = (struct dmsg_cqe *)sol;
  1900. hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
  1901. break;
  1902. case UNSOL_HDR_NOTIFY:
  1903. beiscsi_log(phba, KERN_INFO,
  1904. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1905. "BM_%d : Received %s[%d] on CID : %d\n",
  1906. cqe_desc[code], code, cid);
  1907. spin_lock_bh(&phba->async_pdu_lock);
  1908. hwi_process_default_pdu_ring(beiscsi_conn, phba,
  1909. (struct i_t_dpdu_cqe *)sol);
  1910. spin_unlock_bh(&phba->async_pdu_lock);
  1911. break;
  1912. case UNSOL_DATA_NOTIFY:
  1913. beiscsi_log(phba, KERN_INFO,
  1914. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1915. "BM_%d : Received %s[%d] on CID : %d\n",
  1916. cqe_desc[code], code, cid);
  1917. spin_lock_bh(&phba->async_pdu_lock);
  1918. hwi_process_default_pdu_ring(beiscsi_conn, phba,
  1919. (struct i_t_dpdu_cqe *)sol);
  1920. spin_unlock_bh(&phba->async_pdu_lock);
  1921. break;
  1922. case CXN_INVALIDATE_INDEX_NOTIFY:
  1923. case CMD_INVALIDATED_NOTIFY:
  1924. case CXN_INVALIDATE_NOTIFY:
  1925. beiscsi_log(phba, KERN_ERR,
  1926. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1927. "BM_%d : Ignoring %s[%d] on CID : %d\n",
  1928. cqe_desc[code], code, cid);
  1929. break;
  1930. case SOL_CMD_KILLED_DATA_DIGEST_ERR:
  1931. case CMD_KILLED_INVALID_STATSN_RCVD:
  1932. case CMD_KILLED_INVALID_R2T_RCVD:
  1933. case CMD_CXN_KILLED_LUN_INVALID:
  1934. case CMD_CXN_KILLED_ICD_INVALID:
  1935. case CMD_CXN_KILLED_ITT_INVALID:
  1936. case CMD_CXN_KILLED_SEQ_OUTOFORDER:
  1937. case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
  1938. beiscsi_log(phba, KERN_ERR,
  1939. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  1940. "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
  1941. cqe_desc[code], code, cid);
  1942. break;
  1943. case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
  1944. beiscsi_log(phba, KERN_ERR,
  1945. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1946. "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
  1947. cqe_desc[code], code, cid);
  1948. spin_lock_bh(&phba->async_pdu_lock);
  1949. hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
  1950. (struct i_t_dpdu_cqe *) sol);
  1951. spin_unlock_bh(&phba->async_pdu_lock);
  1952. break;
  1953. case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
  1954. case CXN_KILLED_BURST_LEN_MISMATCH:
  1955. case CXN_KILLED_AHS_RCVD:
  1956. case CXN_KILLED_HDR_DIGEST_ERR:
  1957. case CXN_KILLED_UNKNOWN_HDR:
  1958. case CXN_KILLED_STALE_ITT_TTT_RCVD:
  1959. case CXN_KILLED_INVALID_ITT_TTT_RCVD:
  1960. case CXN_KILLED_TIMED_OUT:
  1961. case CXN_KILLED_FIN_RCVD:
  1962. case CXN_KILLED_RST_SENT:
  1963. case CXN_KILLED_RST_RCVD:
  1964. case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
  1965. case CXN_KILLED_BAD_WRB_INDEX_ERROR:
  1966. case CXN_KILLED_OVER_RUN_RESIDUAL:
  1967. case CXN_KILLED_UNDER_RUN_RESIDUAL:
  1968. case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
  1969. beiscsi_log(phba, KERN_ERR,
  1970. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1971. "BM_%d : Event %s[%d] received on CID : %d\n",
  1972. cqe_desc[code], code, cid);
  1973. if (beiscsi_conn)
  1974. iscsi_conn_failure(beiscsi_conn->conn,
  1975. ISCSI_ERR_CONN_FAILED);
  1976. break;
  1977. default:
  1978. beiscsi_log(phba, KERN_ERR,
  1979. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  1980. "BM_%d : Invalid CQE Event Received Code : %d"
  1981. "CID 0x%x...\n",
  1982. code, cid);
  1983. break;
  1984. }
  1985. proc_next_cqe:
  1986. AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
  1987. queue_tail_inc(cq);
  1988. sol = queue_tail_node(cq);
  1989. num_processed++;
  1990. }
  1991. if (num_processed > 0) {
  1992. tot_nump += num_processed;
  1993. hwi_ring_cq_db(phba, cq->id, num_processed, 1, 0);
  1994. }
  1995. return tot_nump;
  1996. }
  1997. void beiscsi_process_all_cqs(struct work_struct *work)
  1998. {
  1999. unsigned long flags;
  2000. struct hwi_controller *phwi_ctrlr;
  2001. struct hwi_context_memory *phwi_context;
  2002. struct beiscsi_hba *phba;
  2003. struct be_eq_obj *pbe_eq =
  2004. container_of(work, struct be_eq_obj, work_cqs);
  2005. phba = pbe_eq->phba;
  2006. phwi_ctrlr = phba->phwi_ctrlr;
  2007. phwi_context = phwi_ctrlr->phwi_ctxt;
  2008. if (pbe_eq->todo_mcc_cq) {
  2009. spin_lock_irqsave(&phba->isr_lock, flags);
  2010. pbe_eq->todo_mcc_cq = false;
  2011. spin_unlock_irqrestore(&phba->isr_lock, flags);
  2012. beiscsi_process_mcc_isr(phba);
  2013. }
  2014. if (pbe_eq->todo_cq) {
  2015. spin_lock_irqsave(&phba->isr_lock, flags);
  2016. pbe_eq->todo_cq = false;
  2017. spin_unlock_irqrestore(&phba->isr_lock, flags);
  2018. beiscsi_process_cq(pbe_eq);
  2019. }
  2020. /* rearm EQ for further interrupts */
  2021. hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
  2022. }
  2023. static int be_iopoll(struct blk_iopoll *iop, int budget)
  2024. {
  2025. unsigned int ret;
  2026. struct beiscsi_hba *phba;
  2027. struct be_eq_obj *pbe_eq;
  2028. pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
  2029. ret = beiscsi_process_cq(pbe_eq);
  2030. pbe_eq->cq_count += ret;
  2031. if (ret < budget) {
  2032. phba = pbe_eq->phba;
  2033. blk_iopoll_complete(iop);
  2034. beiscsi_log(phba, KERN_INFO,
  2035. BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
  2036. "BM_%d : rearm pbe_eq->q.id =%d\n",
  2037. pbe_eq->q.id);
  2038. hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
  2039. }
  2040. return ret;
  2041. }
  2042. static void
  2043. hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg,
  2044. unsigned int num_sg, struct beiscsi_io_task *io_task)
  2045. {
  2046. struct iscsi_sge *psgl;
  2047. unsigned int sg_len, index;
  2048. unsigned int sge_len = 0;
  2049. unsigned long long addr;
  2050. struct scatterlist *l_sg;
  2051. unsigned int offset;
  2052. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb,
  2053. io_task->bhs_pa.u.a32.address_lo);
  2054. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb,
  2055. io_task->bhs_pa.u.a32.address_hi);
  2056. l_sg = sg;
  2057. for (index = 0; (index < num_sg) && (index < 2); index++,
  2058. sg = sg_next(sg)) {
  2059. if (index == 0) {
  2060. sg_len = sg_dma_len(sg);
  2061. addr = (u64) sg_dma_address(sg);
  2062. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  2063. sge0_addr_lo, pwrb,
  2064. lower_32_bits(addr));
  2065. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  2066. sge0_addr_hi, pwrb,
  2067. upper_32_bits(addr));
  2068. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  2069. sge0_len, pwrb,
  2070. sg_len);
  2071. sge_len = sg_len;
  2072. } else {
  2073. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset,
  2074. pwrb, sge_len);
  2075. sg_len = sg_dma_len(sg);
  2076. addr = (u64) sg_dma_address(sg);
  2077. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  2078. sge1_addr_lo, pwrb,
  2079. lower_32_bits(addr));
  2080. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  2081. sge1_addr_hi, pwrb,
  2082. upper_32_bits(addr));
  2083. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  2084. sge1_len, pwrb,
  2085. sg_len);
  2086. }
  2087. }
  2088. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  2089. memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
  2090. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
  2091. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2092. io_task->bhs_pa.u.a32.address_hi);
  2093. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2094. io_task->bhs_pa.u.a32.address_lo);
  2095. if (num_sg == 1) {
  2096. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
  2097. 1);
  2098. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
  2099. 0);
  2100. } else if (num_sg == 2) {
  2101. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
  2102. 0);
  2103. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
  2104. 1);
  2105. } else {
  2106. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
  2107. 0);
  2108. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
  2109. 0);
  2110. }
  2111. sg = l_sg;
  2112. psgl++;
  2113. psgl++;
  2114. offset = 0;
  2115. for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
  2116. sg_len = sg_dma_len(sg);
  2117. addr = (u64) sg_dma_address(sg);
  2118. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2119. lower_32_bits(addr));
  2120. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2121. upper_32_bits(addr));
  2122. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
  2123. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
  2124. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  2125. offset += sg_len;
  2126. }
  2127. psgl--;
  2128. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  2129. }
  2130. static void
  2131. hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
  2132. unsigned int num_sg, struct beiscsi_io_task *io_task)
  2133. {
  2134. struct iscsi_sge *psgl;
  2135. unsigned int sg_len, index;
  2136. unsigned int sge_len = 0;
  2137. unsigned long long addr;
  2138. struct scatterlist *l_sg;
  2139. unsigned int offset;
  2140. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
  2141. io_task->bhs_pa.u.a32.address_lo);
  2142. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
  2143. io_task->bhs_pa.u.a32.address_hi);
  2144. l_sg = sg;
  2145. for (index = 0; (index < num_sg) && (index < 2); index++,
  2146. sg = sg_next(sg)) {
  2147. if (index == 0) {
  2148. sg_len = sg_dma_len(sg);
  2149. addr = (u64) sg_dma_address(sg);
  2150. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
  2151. ((u32)(addr & 0xFFFFFFFF)));
  2152. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
  2153. ((u32)(addr >> 32)));
  2154. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
  2155. sg_len);
  2156. sge_len = sg_len;
  2157. } else {
  2158. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
  2159. pwrb, sge_len);
  2160. sg_len = sg_dma_len(sg);
  2161. addr = (u64) sg_dma_address(sg);
  2162. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
  2163. ((u32)(addr & 0xFFFFFFFF)));
  2164. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
  2165. ((u32)(addr >> 32)));
  2166. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
  2167. sg_len);
  2168. }
  2169. }
  2170. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  2171. memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
  2172. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
  2173. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2174. io_task->bhs_pa.u.a32.address_hi);
  2175. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2176. io_task->bhs_pa.u.a32.address_lo);
  2177. if (num_sg == 1) {
  2178. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  2179. 1);
  2180. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  2181. 0);
  2182. } else if (num_sg == 2) {
  2183. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  2184. 0);
  2185. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  2186. 1);
  2187. } else {
  2188. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
  2189. 0);
  2190. AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
  2191. 0);
  2192. }
  2193. sg = l_sg;
  2194. psgl++;
  2195. psgl++;
  2196. offset = 0;
  2197. for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
  2198. sg_len = sg_dma_len(sg);
  2199. addr = (u64) sg_dma_address(sg);
  2200. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2201. (addr & 0xFFFFFFFF));
  2202. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2203. (addr >> 32));
  2204. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
  2205. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
  2206. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  2207. offset += sg_len;
  2208. }
  2209. psgl--;
  2210. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  2211. }
  2212. /**
  2213. * hwi_write_buffer()- Populate the WRB with task info
  2214. * @pwrb: ptr to the WRB entry
  2215. * @task: iscsi task which is to be executed
  2216. **/
  2217. static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
  2218. {
  2219. struct iscsi_sge *psgl;
  2220. struct beiscsi_io_task *io_task = task->dd_data;
  2221. struct beiscsi_conn *beiscsi_conn = io_task->conn;
  2222. struct beiscsi_hba *phba = beiscsi_conn->phba;
  2223. uint8_t dsp_value = 0;
  2224. io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
  2225. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
  2226. io_task->bhs_pa.u.a32.address_lo);
  2227. AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
  2228. io_task->bhs_pa.u.a32.address_hi);
  2229. if (task->data) {
  2230. /* Check for the data_count */
  2231. dsp_value = (task->data_count) ? 1 : 0;
  2232. if (is_chip_be2_be3r(phba))
  2233. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp,
  2234. pwrb, dsp_value);
  2235. else
  2236. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp,
  2237. pwrb, dsp_value);
  2238. /* Map addr only if there is data_count */
  2239. if (dsp_value) {
  2240. io_task->mtask_addr = pci_map_single(phba->pcidev,
  2241. task->data,
  2242. task->data_count,
  2243. PCI_DMA_TODEVICE);
  2244. io_task->mtask_data_count = task->data_count;
  2245. } else
  2246. io_task->mtask_addr = 0;
  2247. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
  2248. lower_32_bits(io_task->mtask_addr));
  2249. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
  2250. upper_32_bits(io_task->mtask_addr));
  2251. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
  2252. task->data_count);
  2253. AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
  2254. } else {
  2255. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  2256. io_task->mtask_addr = 0;
  2257. }
  2258. psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
  2259. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
  2260. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2261. io_task->bhs_pa.u.a32.address_hi);
  2262. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2263. io_task->bhs_pa.u.a32.address_lo);
  2264. if (task->data) {
  2265. psgl++;
  2266. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
  2267. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
  2268. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
  2269. AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
  2270. AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
  2271. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
  2272. psgl++;
  2273. if (task->data) {
  2274. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
  2275. lower_32_bits(io_task->mtask_addr));
  2276. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
  2277. upper_32_bits(io_task->mtask_addr));
  2278. }
  2279. AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
  2280. }
  2281. AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
  2282. }
  2283. /**
  2284. * beiscsi_find_mem_req()- Find mem needed
  2285. * @phba: ptr to HBA struct
  2286. **/
  2287. static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
  2288. {
  2289. uint8_t mem_descr_index, ulp_num;
  2290. unsigned int num_cq_pages, num_async_pdu_buf_pages;
  2291. unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
  2292. unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
  2293. num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
  2294. sizeof(struct sol_cqe));
  2295. phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
  2296. phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
  2297. BE_ISCSI_PDU_HEADER_SIZE;
  2298. phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
  2299. sizeof(struct hwi_context_memory);
  2300. phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
  2301. * (phba->params.wrbs_per_cxn)
  2302. * phba->params.cxns_per_ctrl;
  2303. wrb_sz_per_cxn = sizeof(struct wrb_handle) *
  2304. (phba->params.wrbs_per_cxn);
  2305. phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
  2306. phba->params.cxns_per_ctrl);
  2307. phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
  2308. phba->params.icds_per_ctrl;
  2309. phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
  2310. phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
  2311. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  2312. if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
  2313. num_async_pdu_buf_sgl_pages =
  2314. PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
  2315. phba, ulp_num) *
  2316. sizeof(struct phys_addr));
  2317. num_async_pdu_buf_pages =
  2318. PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
  2319. phba, ulp_num) *
  2320. phba->params.defpdu_hdr_sz);
  2321. num_async_pdu_data_pages =
  2322. PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
  2323. phba, ulp_num) *
  2324. phba->params.defpdu_data_sz);
  2325. num_async_pdu_data_sgl_pages =
  2326. PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
  2327. phba, ulp_num) *
  2328. sizeof(struct phys_addr));
  2329. mem_descr_index = (HWI_MEM_TEMPLATE_HDR_ULP0 +
  2330. (ulp_num * MEM_DESCR_OFFSET));
  2331. phba->mem_req[mem_descr_index] =
  2332. BEISCSI_GET_CID_COUNT(phba, ulp_num) *
  2333. BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE;
  2334. mem_descr_index = (HWI_MEM_ASYNC_HEADER_BUF_ULP0 +
  2335. (ulp_num * MEM_DESCR_OFFSET));
  2336. phba->mem_req[mem_descr_index] =
  2337. num_async_pdu_buf_pages *
  2338. PAGE_SIZE;
  2339. mem_descr_index = (HWI_MEM_ASYNC_DATA_BUF_ULP0 +
  2340. (ulp_num * MEM_DESCR_OFFSET));
  2341. phba->mem_req[mem_descr_index] =
  2342. num_async_pdu_data_pages *
  2343. PAGE_SIZE;
  2344. mem_descr_index = (HWI_MEM_ASYNC_HEADER_RING_ULP0 +
  2345. (ulp_num * MEM_DESCR_OFFSET));
  2346. phba->mem_req[mem_descr_index] =
  2347. num_async_pdu_buf_sgl_pages *
  2348. PAGE_SIZE;
  2349. mem_descr_index = (HWI_MEM_ASYNC_DATA_RING_ULP0 +
  2350. (ulp_num * MEM_DESCR_OFFSET));
  2351. phba->mem_req[mem_descr_index] =
  2352. num_async_pdu_data_sgl_pages *
  2353. PAGE_SIZE;
  2354. mem_descr_index = (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 +
  2355. (ulp_num * MEM_DESCR_OFFSET));
  2356. phba->mem_req[mem_descr_index] =
  2357. BEISCSI_GET_CID_COUNT(phba, ulp_num) *
  2358. sizeof(struct async_pdu_handle);
  2359. mem_descr_index = (HWI_MEM_ASYNC_DATA_HANDLE_ULP0 +
  2360. (ulp_num * MEM_DESCR_OFFSET));
  2361. phba->mem_req[mem_descr_index] =
  2362. BEISCSI_GET_CID_COUNT(phba, ulp_num) *
  2363. sizeof(struct async_pdu_handle);
  2364. mem_descr_index = (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
  2365. (ulp_num * MEM_DESCR_OFFSET));
  2366. phba->mem_req[mem_descr_index] =
  2367. sizeof(struct hwi_async_pdu_context) +
  2368. (BEISCSI_GET_CID_COUNT(phba, ulp_num) *
  2369. sizeof(struct hwi_async_entry));
  2370. }
  2371. }
  2372. }
  2373. static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
  2374. {
  2375. dma_addr_t bus_add;
  2376. struct hwi_controller *phwi_ctrlr;
  2377. struct be_mem_descriptor *mem_descr;
  2378. struct mem_array *mem_arr, *mem_arr_orig;
  2379. unsigned int i, j, alloc_size, curr_alloc_size;
  2380. phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
  2381. if (!phba->phwi_ctrlr)
  2382. return -ENOMEM;
  2383. /* Allocate memory for wrb_context */
  2384. phwi_ctrlr = phba->phwi_ctrlr;
  2385. phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) *
  2386. phba->params.cxns_per_ctrl,
  2387. GFP_KERNEL);
  2388. if (!phwi_ctrlr->wrb_context)
  2389. return -ENOMEM;
  2390. phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
  2391. GFP_KERNEL);
  2392. if (!phba->init_mem) {
  2393. kfree(phwi_ctrlr->wrb_context);
  2394. kfree(phba->phwi_ctrlr);
  2395. return -ENOMEM;
  2396. }
  2397. mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
  2398. GFP_KERNEL);
  2399. if (!mem_arr_orig) {
  2400. kfree(phba->init_mem);
  2401. kfree(phwi_ctrlr->wrb_context);
  2402. kfree(phba->phwi_ctrlr);
  2403. return -ENOMEM;
  2404. }
  2405. mem_descr = phba->init_mem;
  2406. for (i = 0; i < SE_MEM_MAX; i++) {
  2407. if (!phba->mem_req[i]) {
  2408. mem_descr->mem_array = NULL;
  2409. mem_descr++;
  2410. continue;
  2411. }
  2412. j = 0;
  2413. mem_arr = mem_arr_orig;
  2414. alloc_size = phba->mem_req[i];
  2415. memset(mem_arr, 0, sizeof(struct mem_array) *
  2416. BEISCSI_MAX_FRAGS_INIT);
  2417. curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
  2418. do {
  2419. mem_arr->virtual_address = pci_alloc_consistent(
  2420. phba->pcidev,
  2421. curr_alloc_size,
  2422. &bus_add);
  2423. if (!mem_arr->virtual_address) {
  2424. if (curr_alloc_size <= BE_MIN_MEM_SIZE)
  2425. goto free_mem;
  2426. if (curr_alloc_size -
  2427. rounddown_pow_of_two(curr_alloc_size))
  2428. curr_alloc_size = rounddown_pow_of_two
  2429. (curr_alloc_size);
  2430. else
  2431. curr_alloc_size = curr_alloc_size / 2;
  2432. } else {
  2433. mem_arr->bus_address.u.
  2434. a64.address = (__u64) bus_add;
  2435. mem_arr->size = curr_alloc_size;
  2436. alloc_size -= curr_alloc_size;
  2437. curr_alloc_size = min(be_max_phys_size *
  2438. 1024, alloc_size);
  2439. j++;
  2440. mem_arr++;
  2441. }
  2442. } while (alloc_size);
  2443. mem_descr->num_elements = j;
  2444. mem_descr->size_in_bytes = phba->mem_req[i];
  2445. mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
  2446. GFP_KERNEL);
  2447. if (!mem_descr->mem_array)
  2448. goto free_mem;
  2449. memcpy(mem_descr->mem_array, mem_arr_orig,
  2450. sizeof(struct mem_array) * j);
  2451. mem_descr++;
  2452. }
  2453. kfree(mem_arr_orig);
  2454. return 0;
  2455. free_mem:
  2456. mem_descr->num_elements = j;
  2457. while ((i) || (j)) {
  2458. for (j = mem_descr->num_elements; j > 0; j--) {
  2459. pci_free_consistent(phba->pcidev,
  2460. mem_descr->mem_array[j - 1].size,
  2461. mem_descr->mem_array[j - 1].
  2462. virtual_address,
  2463. (unsigned long)mem_descr->
  2464. mem_array[j - 1].
  2465. bus_address.u.a64.address);
  2466. }
  2467. if (i) {
  2468. i--;
  2469. kfree(mem_descr->mem_array);
  2470. mem_descr--;
  2471. }
  2472. }
  2473. kfree(mem_arr_orig);
  2474. kfree(phba->init_mem);
  2475. kfree(phba->phwi_ctrlr->wrb_context);
  2476. kfree(phba->phwi_ctrlr);
  2477. return -ENOMEM;
  2478. }
  2479. static int beiscsi_get_memory(struct beiscsi_hba *phba)
  2480. {
  2481. beiscsi_find_mem_req(phba);
  2482. return beiscsi_alloc_mem(phba);
  2483. }
  2484. static void iscsi_init_global_templates(struct beiscsi_hba *phba)
  2485. {
  2486. struct pdu_data_out *pdata_out;
  2487. struct pdu_nop_out *pnop_out;
  2488. struct be_mem_descriptor *mem_descr;
  2489. mem_descr = phba->init_mem;
  2490. mem_descr += ISCSI_MEM_GLOBAL_HEADER;
  2491. pdata_out =
  2492. (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
  2493. memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
  2494. AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
  2495. IIOC_SCSI_DATA);
  2496. pnop_out =
  2497. (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
  2498. virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
  2499. memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
  2500. AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
  2501. AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
  2502. AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
  2503. }
  2504. static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
  2505. {
  2506. struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
  2507. struct hwi_context_memory *phwi_ctxt;
  2508. struct wrb_handle *pwrb_handle = NULL;
  2509. struct hwi_controller *phwi_ctrlr;
  2510. struct hwi_wrb_context *pwrb_context;
  2511. struct iscsi_wrb *pwrb = NULL;
  2512. unsigned int num_cxn_wrbh = 0;
  2513. unsigned int num_cxn_wrb = 0, j, idx = 0, index;
  2514. mem_descr_wrbh = phba->init_mem;
  2515. mem_descr_wrbh += HWI_MEM_WRBH;
  2516. mem_descr_wrb = phba->init_mem;
  2517. mem_descr_wrb += HWI_MEM_WRB;
  2518. phwi_ctrlr = phba->phwi_ctrlr;
  2519. /* Allocate memory for WRBQ */
  2520. phwi_ctxt = phwi_ctrlr->phwi_ctxt;
  2521. phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) *
  2522. phba->params.cxns_per_ctrl,
  2523. GFP_KERNEL);
  2524. if (!phwi_ctxt->be_wrbq) {
  2525. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2526. "BM_%d : WRBQ Mem Alloc Failed\n");
  2527. return -ENOMEM;
  2528. }
  2529. for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
  2530. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2531. pwrb_context->pwrb_handle_base =
  2532. kzalloc(sizeof(struct wrb_handle *) *
  2533. phba->params.wrbs_per_cxn, GFP_KERNEL);
  2534. if (!pwrb_context->pwrb_handle_base) {
  2535. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2536. "BM_%d : Mem Alloc Failed. Failing to load\n");
  2537. goto init_wrb_hndl_failed;
  2538. }
  2539. pwrb_context->pwrb_handle_basestd =
  2540. kzalloc(sizeof(struct wrb_handle *) *
  2541. phba->params.wrbs_per_cxn, GFP_KERNEL);
  2542. if (!pwrb_context->pwrb_handle_basestd) {
  2543. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2544. "BM_%d : Mem Alloc Failed. Failing to load\n");
  2545. goto init_wrb_hndl_failed;
  2546. }
  2547. if (!num_cxn_wrbh) {
  2548. pwrb_handle =
  2549. mem_descr_wrbh->mem_array[idx].virtual_address;
  2550. num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
  2551. ((sizeof(struct wrb_handle)) *
  2552. phba->params.wrbs_per_cxn));
  2553. idx++;
  2554. }
  2555. pwrb_context->alloc_index = 0;
  2556. pwrb_context->wrb_handles_available = 0;
  2557. pwrb_context->free_index = 0;
  2558. if (num_cxn_wrbh) {
  2559. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  2560. pwrb_context->pwrb_handle_base[j] = pwrb_handle;
  2561. pwrb_context->pwrb_handle_basestd[j] =
  2562. pwrb_handle;
  2563. pwrb_context->wrb_handles_available++;
  2564. pwrb_handle->wrb_index = j;
  2565. pwrb_handle++;
  2566. }
  2567. num_cxn_wrbh--;
  2568. }
  2569. }
  2570. idx = 0;
  2571. for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
  2572. pwrb_context = &phwi_ctrlr->wrb_context[index];
  2573. if (!num_cxn_wrb) {
  2574. pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
  2575. num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
  2576. ((sizeof(struct iscsi_wrb) *
  2577. phba->params.wrbs_per_cxn));
  2578. idx++;
  2579. }
  2580. if (num_cxn_wrb) {
  2581. for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
  2582. pwrb_handle = pwrb_context->pwrb_handle_base[j];
  2583. pwrb_handle->pwrb = pwrb;
  2584. pwrb++;
  2585. }
  2586. num_cxn_wrb--;
  2587. }
  2588. }
  2589. return 0;
  2590. init_wrb_hndl_failed:
  2591. for (j = index; j > 0; j--) {
  2592. pwrb_context = &phwi_ctrlr->wrb_context[j];
  2593. kfree(pwrb_context->pwrb_handle_base);
  2594. kfree(pwrb_context->pwrb_handle_basestd);
  2595. }
  2596. return -ENOMEM;
  2597. }
  2598. static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
  2599. {
  2600. uint8_t ulp_num;
  2601. struct hwi_controller *phwi_ctrlr;
  2602. struct hba_parameters *p = &phba->params;
  2603. struct hwi_async_pdu_context *pasync_ctx;
  2604. struct async_pdu_handle *pasync_header_h, *pasync_data_h;
  2605. unsigned int index, idx, num_per_mem, num_async_data;
  2606. struct be_mem_descriptor *mem_descr;
  2607. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  2608. if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
  2609. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2610. mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
  2611. (ulp_num * MEM_DESCR_OFFSET));
  2612. phwi_ctrlr = phba->phwi_ctrlr;
  2613. phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num] =
  2614. (struct hwi_async_pdu_context *)
  2615. mem_descr->mem_array[0].virtual_address;
  2616. pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num];
  2617. memset(pasync_ctx, 0, sizeof(*pasync_ctx));
  2618. pasync_ctx->async_entry =
  2619. (struct hwi_async_entry *)
  2620. ((long unsigned int)pasync_ctx +
  2621. sizeof(struct hwi_async_pdu_context));
  2622. pasync_ctx->num_entries = BEISCSI_GET_CID_COUNT(phba,
  2623. ulp_num);
  2624. pasync_ctx->buffer_size = p->defpdu_hdr_sz;
  2625. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2626. mem_descr += HWI_MEM_ASYNC_HEADER_BUF_ULP0 +
  2627. (ulp_num * MEM_DESCR_OFFSET);
  2628. if (mem_descr->mem_array[0].virtual_address) {
  2629. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2630. "BM_%d : hwi_init_async_pdu_ctx"
  2631. " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n",
  2632. ulp_num,
  2633. mem_descr->mem_array[0].
  2634. virtual_address);
  2635. } else
  2636. beiscsi_log(phba, KERN_WARNING,
  2637. BEISCSI_LOG_INIT,
  2638. "BM_%d : No Virtual address for ULP : %d\n",
  2639. ulp_num);
  2640. pasync_ctx->async_header.va_base =
  2641. mem_descr->mem_array[0].virtual_address;
  2642. pasync_ctx->async_header.pa_base.u.a64.address =
  2643. mem_descr->mem_array[0].
  2644. bus_address.u.a64.address;
  2645. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2646. mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 +
  2647. (ulp_num * MEM_DESCR_OFFSET);
  2648. if (mem_descr->mem_array[0].virtual_address) {
  2649. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2650. "BM_%d : hwi_init_async_pdu_ctx"
  2651. " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n",
  2652. ulp_num,
  2653. mem_descr->mem_array[0].
  2654. virtual_address);
  2655. } else
  2656. beiscsi_log(phba, KERN_WARNING,
  2657. BEISCSI_LOG_INIT,
  2658. "BM_%d : No Virtual address for ULP : %d\n",
  2659. ulp_num);
  2660. pasync_ctx->async_header.ring_base =
  2661. mem_descr->mem_array[0].virtual_address;
  2662. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2663. mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 +
  2664. (ulp_num * MEM_DESCR_OFFSET);
  2665. if (mem_descr->mem_array[0].virtual_address) {
  2666. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2667. "BM_%d : hwi_init_async_pdu_ctx"
  2668. " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n",
  2669. ulp_num,
  2670. mem_descr->mem_array[0].
  2671. virtual_address);
  2672. } else
  2673. beiscsi_log(phba, KERN_WARNING,
  2674. BEISCSI_LOG_INIT,
  2675. "BM_%d : No Virtual address for ULP : %d\n",
  2676. ulp_num);
  2677. pasync_ctx->async_header.handle_base =
  2678. mem_descr->mem_array[0].virtual_address;
  2679. pasync_ctx->async_header.writables = 0;
  2680. INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
  2681. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2682. mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 +
  2683. (ulp_num * MEM_DESCR_OFFSET);
  2684. if (mem_descr->mem_array[0].virtual_address) {
  2685. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2686. "BM_%d : hwi_init_async_pdu_ctx"
  2687. " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n",
  2688. ulp_num,
  2689. mem_descr->mem_array[0].
  2690. virtual_address);
  2691. } else
  2692. beiscsi_log(phba, KERN_WARNING,
  2693. BEISCSI_LOG_INIT,
  2694. "BM_%d : No Virtual address for ULP : %d\n",
  2695. ulp_num);
  2696. pasync_ctx->async_data.ring_base =
  2697. mem_descr->mem_array[0].virtual_address;
  2698. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2699. mem_descr += HWI_MEM_ASYNC_DATA_HANDLE_ULP0 +
  2700. (ulp_num * MEM_DESCR_OFFSET);
  2701. if (!mem_descr->mem_array[0].virtual_address)
  2702. beiscsi_log(phba, KERN_WARNING,
  2703. BEISCSI_LOG_INIT,
  2704. "BM_%d : No Virtual address for ULP : %d\n",
  2705. ulp_num);
  2706. pasync_ctx->async_data.handle_base =
  2707. mem_descr->mem_array[0].virtual_address;
  2708. pasync_ctx->async_data.writables = 0;
  2709. INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
  2710. pasync_header_h =
  2711. (struct async_pdu_handle *)
  2712. pasync_ctx->async_header.handle_base;
  2713. pasync_data_h =
  2714. (struct async_pdu_handle *)
  2715. pasync_ctx->async_data.handle_base;
  2716. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  2717. mem_descr += HWI_MEM_ASYNC_DATA_BUF_ULP0 +
  2718. (ulp_num * MEM_DESCR_OFFSET);
  2719. if (mem_descr->mem_array[0].virtual_address) {
  2720. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2721. "BM_%d : hwi_init_async_pdu_ctx"
  2722. " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n",
  2723. ulp_num,
  2724. mem_descr->mem_array[0].
  2725. virtual_address);
  2726. } else
  2727. beiscsi_log(phba, KERN_WARNING,
  2728. BEISCSI_LOG_INIT,
  2729. "BM_%d : No Virtual address for ULP : %d\n",
  2730. ulp_num);
  2731. idx = 0;
  2732. pasync_ctx->async_data.va_base =
  2733. mem_descr->mem_array[idx].virtual_address;
  2734. pasync_ctx->async_data.pa_base.u.a64.address =
  2735. mem_descr->mem_array[idx].
  2736. bus_address.u.a64.address;
  2737. num_async_data = ((mem_descr->mem_array[idx].size) /
  2738. phba->params.defpdu_data_sz);
  2739. num_per_mem = 0;
  2740. for (index = 0; index < BEISCSI_GET_CID_COUNT
  2741. (phba, ulp_num); index++) {
  2742. pasync_header_h->cri = -1;
  2743. pasync_header_h->index = (char)index;
  2744. INIT_LIST_HEAD(&pasync_header_h->link);
  2745. pasync_header_h->pbuffer =
  2746. (void *)((unsigned long)
  2747. (pasync_ctx->
  2748. async_header.va_base) +
  2749. (p->defpdu_hdr_sz * index));
  2750. pasync_header_h->pa.u.a64.address =
  2751. pasync_ctx->async_header.pa_base.u.a64.
  2752. address + (p->defpdu_hdr_sz * index);
  2753. list_add_tail(&pasync_header_h->link,
  2754. &pasync_ctx->async_header.
  2755. free_list);
  2756. pasync_header_h++;
  2757. pasync_ctx->async_header.free_entries++;
  2758. pasync_ctx->async_header.writables++;
  2759. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
  2760. wait_queue.list);
  2761. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
  2762. header_busy_list);
  2763. pasync_data_h->cri = -1;
  2764. pasync_data_h->index = (char)index;
  2765. INIT_LIST_HEAD(&pasync_data_h->link);
  2766. if (!num_async_data) {
  2767. num_per_mem = 0;
  2768. idx++;
  2769. pasync_ctx->async_data.va_base =
  2770. mem_descr->mem_array[idx].
  2771. virtual_address;
  2772. pasync_ctx->async_data.pa_base.u.
  2773. a64.address =
  2774. mem_descr->mem_array[idx].
  2775. bus_address.u.a64.address;
  2776. num_async_data =
  2777. ((mem_descr->mem_array[idx].
  2778. size) /
  2779. phba->params.defpdu_data_sz);
  2780. }
  2781. pasync_data_h->pbuffer =
  2782. (void *)((unsigned long)
  2783. (pasync_ctx->async_data.va_base) +
  2784. (p->defpdu_data_sz * num_per_mem));
  2785. pasync_data_h->pa.u.a64.address =
  2786. pasync_ctx->async_data.pa_base.u.a64.
  2787. address + (p->defpdu_data_sz *
  2788. num_per_mem);
  2789. num_per_mem++;
  2790. num_async_data--;
  2791. list_add_tail(&pasync_data_h->link,
  2792. &pasync_ctx->async_data.
  2793. free_list);
  2794. pasync_data_h++;
  2795. pasync_ctx->async_data.free_entries++;
  2796. pasync_ctx->async_data.writables++;
  2797. INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
  2798. data_busy_list);
  2799. }
  2800. pasync_ctx->async_header.host_write_ptr = 0;
  2801. pasync_ctx->async_header.ep_read_ptr = -1;
  2802. pasync_ctx->async_data.host_write_ptr = 0;
  2803. pasync_ctx->async_data.ep_read_ptr = -1;
  2804. }
  2805. }
  2806. return 0;
  2807. }
  2808. static int
  2809. be_sgl_create_contiguous(void *virtual_address,
  2810. u64 physical_address, u32 length,
  2811. struct be_dma_mem *sgl)
  2812. {
  2813. WARN_ON(!virtual_address);
  2814. WARN_ON(!physical_address);
  2815. WARN_ON(!length > 0);
  2816. WARN_ON(!sgl);
  2817. sgl->va = virtual_address;
  2818. sgl->dma = (unsigned long)physical_address;
  2819. sgl->size = length;
  2820. return 0;
  2821. }
  2822. static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
  2823. {
  2824. memset(sgl, 0, sizeof(*sgl));
  2825. }
  2826. static void
  2827. hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
  2828. struct mem_array *pmem, struct be_dma_mem *sgl)
  2829. {
  2830. if (sgl->va)
  2831. be_sgl_destroy_contiguous(sgl);
  2832. be_sgl_create_contiguous(pmem->virtual_address,
  2833. pmem->bus_address.u.a64.address,
  2834. pmem->size, sgl);
  2835. }
  2836. static void
  2837. hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
  2838. struct mem_array *pmem, struct be_dma_mem *sgl)
  2839. {
  2840. if (sgl->va)
  2841. be_sgl_destroy_contiguous(sgl);
  2842. be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
  2843. pmem->bus_address.u.a64.address,
  2844. pmem->size, sgl);
  2845. }
  2846. static int be_fill_queue(struct be_queue_info *q,
  2847. u16 len, u16 entry_size, void *vaddress)
  2848. {
  2849. struct be_dma_mem *mem = &q->dma_mem;
  2850. memset(q, 0, sizeof(*q));
  2851. q->len = len;
  2852. q->entry_size = entry_size;
  2853. mem->size = len * entry_size;
  2854. mem->va = vaddress;
  2855. if (!mem->va)
  2856. return -ENOMEM;
  2857. memset(mem->va, 0, mem->size);
  2858. return 0;
  2859. }
  2860. static int beiscsi_create_eqs(struct beiscsi_hba *phba,
  2861. struct hwi_context_memory *phwi_context)
  2862. {
  2863. unsigned int i, num_eq_pages;
  2864. int ret = 0, eq_for_mcc;
  2865. struct be_queue_info *eq;
  2866. struct be_dma_mem *mem;
  2867. void *eq_vaddress;
  2868. dma_addr_t paddr;
  2869. num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
  2870. sizeof(struct be_eq_entry));
  2871. if (phba->msix_enabled)
  2872. eq_for_mcc = 1;
  2873. else
  2874. eq_for_mcc = 0;
  2875. for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
  2876. eq = &phwi_context->be_eq[i].q;
  2877. mem = &eq->dma_mem;
  2878. phwi_context->be_eq[i].phba = phba;
  2879. eq_vaddress = pci_alloc_consistent(phba->pcidev,
  2880. num_eq_pages * PAGE_SIZE,
  2881. &paddr);
  2882. if (!eq_vaddress)
  2883. goto create_eq_error;
  2884. mem->va = eq_vaddress;
  2885. ret = be_fill_queue(eq, phba->params.num_eq_entries,
  2886. sizeof(struct be_eq_entry), eq_vaddress);
  2887. if (ret) {
  2888. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2889. "BM_%d : be_fill_queue Failed for EQ\n");
  2890. goto create_eq_error;
  2891. }
  2892. mem->dma = paddr;
  2893. ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
  2894. phwi_context->cur_eqd);
  2895. if (ret) {
  2896. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2897. "BM_%d : beiscsi_cmd_eq_create"
  2898. "Failed for EQ\n");
  2899. goto create_eq_error;
  2900. }
  2901. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2902. "BM_%d : eqid = %d\n",
  2903. phwi_context->be_eq[i].q.id);
  2904. }
  2905. return 0;
  2906. create_eq_error:
  2907. for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
  2908. eq = &phwi_context->be_eq[i].q;
  2909. mem = &eq->dma_mem;
  2910. if (mem->va)
  2911. pci_free_consistent(phba->pcidev, num_eq_pages
  2912. * PAGE_SIZE,
  2913. mem->va, mem->dma);
  2914. }
  2915. return ret;
  2916. }
  2917. static int beiscsi_create_cqs(struct beiscsi_hba *phba,
  2918. struct hwi_context_memory *phwi_context)
  2919. {
  2920. unsigned int i, num_cq_pages;
  2921. int ret = 0;
  2922. struct be_queue_info *cq, *eq;
  2923. struct be_dma_mem *mem;
  2924. struct be_eq_obj *pbe_eq;
  2925. void *cq_vaddress;
  2926. dma_addr_t paddr;
  2927. num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
  2928. sizeof(struct sol_cqe));
  2929. for (i = 0; i < phba->num_cpus; i++) {
  2930. cq = &phwi_context->be_cq[i];
  2931. eq = &phwi_context->be_eq[i].q;
  2932. pbe_eq = &phwi_context->be_eq[i];
  2933. pbe_eq->cq = cq;
  2934. pbe_eq->phba = phba;
  2935. mem = &cq->dma_mem;
  2936. cq_vaddress = pci_alloc_consistent(phba->pcidev,
  2937. num_cq_pages * PAGE_SIZE,
  2938. &paddr);
  2939. if (!cq_vaddress)
  2940. goto create_cq_error;
  2941. ret = be_fill_queue(cq, phba->params.num_cq_entries,
  2942. sizeof(struct sol_cqe), cq_vaddress);
  2943. if (ret) {
  2944. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2945. "BM_%d : be_fill_queue Failed "
  2946. "for ISCSI CQ\n");
  2947. goto create_cq_error;
  2948. }
  2949. mem->dma = paddr;
  2950. ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
  2951. false, 0);
  2952. if (ret) {
  2953. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2954. "BM_%d : beiscsi_cmd_eq_create"
  2955. "Failed for ISCSI CQ\n");
  2956. goto create_cq_error;
  2957. }
  2958. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  2959. "BM_%d : iscsi cq_id is %d for eq_id %d\n"
  2960. "iSCSI CQ CREATED\n", cq->id, eq->id);
  2961. }
  2962. return 0;
  2963. create_cq_error:
  2964. for (i = 0; i < phba->num_cpus; i++) {
  2965. cq = &phwi_context->be_cq[i];
  2966. mem = &cq->dma_mem;
  2967. if (mem->va)
  2968. pci_free_consistent(phba->pcidev, num_cq_pages
  2969. * PAGE_SIZE,
  2970. mem->va, mem->dma);
  2971. }
  2972. return ret;
  2973. }
  2974. static int
  2975. beiscsi_create_def_hdr(struct beiscsi_hba *phba,
  2976. struct hwi_context_memory *phwi_context,
  2977. struct hwi_controller *phwi_ctrlr,
  2978. unsigned int def_pdu_ring_sz, uint8_t ulp_num)
  2979. {
  2980. unsigned int idx;
  2981. int ret;
  2982. struct be_queue_info *dq, *cq;
  2983. struct be_dma_mem *mem;
  2984. struct be_mem_descriptor *mem_descr;
  2985. void *dq_vaddress;
  2986. idx = 0;
  2987. dq = &phwi_context->be_def_hdrq[ulp_num];
  2988. cq = &phwi_context->be_cq[0];
  2989. mem = &dq->dma_mem;
  2990. mem_descr = phba->init_mem;
  2991. mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 +
  2992. (ulp_num * MEM_DESCR_OFFSET);
  2993. dq_vaddress = mem_descr->mem_array[idx].virtual_address;
  2994. ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
  2995. sizeof(struct phys_addr),
  2996. sizeof(struct phys_addr), dq_vaddress);
  2997. if (ret) {
  2998. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  2999. "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n",
  3000. ulp_num);
  3001. return ret;
  3002. }
  3003. mem->dma = (unsigned long)mem_descr->mem_array[idx].
  3004. bus_address.u.a64.address;
  3005. ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
  3006. def_pdu_ring_sz,
  3007. phba->params.defpdu_hdr_sz,
  3008. BEISCSI_DEFQ_HDR, ulp_num);
  3009. if (ret) {
  3010. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3011. "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n",
  3012. ulp_num);
  3013. return ret;
  3014. }
  3015. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3016. "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n",
  3017. ulp_num,
  3018. phwi_context->be_def_hdrq[ulp_num].id);
  3019. hwi_post_async_buffers(phba, BEISCSI_DEFQ_HDR, ulp_num);
  3020. return 0;
  3021. }
  3022. static int
  3023. beiscsi_create_def_data(struct beiscsi_hba *phba,
  3024. struct hwi_context_memory *phwi_context,
  3025. struct hwi_controller *phwi_ctrlr,
  3026. unsigned int def_pdu_ring_sz, uint8_t ulp_num)
  3027. {
  3028. unsigned int idx;
  3029. int ret;
  3030. struct be_queue_info *dataq, *cq;
  3031. struct be_dma_mem *mem;
  3032. struct be_mem_descriptor *mem_descr;
  3033. void *dq_vaddress;
  3034. idx = 0;
  3035. dataq = &phwi_context->be_def_dataq[ulp_num];
  3036. cq = &phwi_context->be_cq[0];
  3037. mem = &dataq->dma_mem;
  3038. mem_descr = phba->init_mem;
  3039. mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 +
  3040. (ulp_num * MEM_DESCR_OFFSET);
  3041. dq_vaddress = mem_descr->mem_array[idx].virtual_address;
  3042. ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
  3043. sizeof(struct phys_addr),
  3044. sizeof(struct phys_addr), dq_vaddress);
  3045. if (ret) {
  3046. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3047. "BM_%d : be_fill_queue Failed for DEF PDU "
  3048. "DATA on ULP : %d\n",
  3049. ulp_num);
  3050. return ret;
  3051. }
  3052. mem->dma = (unsigned long)mem_descr->mem_array[idx].
  3053. bus_address.u.a64.address;
  3054. ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
  3055. def_pdu_ring_sz,
  3056. phba->params.defpdu_data_sz,
  3057. BEISCSI_DEFQ_DATA, ulp_num);
  3058. if (ret) {
  3059. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3060. "BM_%d be_cmd_create_default_pdu_queue"
  3061. " Failed for DEF PDU DATA on ULP : %d\n",
  3062. ulp_num);
  3063. return ret;
  3064. }
  3065. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3066. "BM_%d : iscsi def data id on ULP : %d is %d\n",
  3067. ulp_num,
  3068. phwi_context->be_def_dataq[ulp_num].id);
  3069. hwi_post_async_buffers(phba, BEISCSI_DEFQ_DATA, ulp_num);
  3070. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3071. "BM_%d : DEFAULT PDU DATA RING CREATED"
  3072. "on ULP : %d\n", ulp_num);
  3073. return 0;
  3074. }
  3075. static int
  3076. beiscsi_post_template_hdr(struct beiscsi_hba *phba)
  3077. {
  3078. struct be_mem_descriptor *mem_descr;
  3079. struct mem_array *pm_arr;
  3080. struct be_dma_mem sgl;
  3081. int status, ulp_num;
  3082. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  3083. if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
  3084. mem_descr = (struct be_mem_descriptor *)phba->init_mem;
  3085. mem_descr += HWI_MEM_TEMPLATE_HDR_ULP0 +
  3086. (ulp_num * MEM_DESCR_OFFSET);
  3087. pm_arr = mem_descr->mem_array;
  3088. hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
  3089. status = be_cmd_iscsi_post_template_hdr(
  3090. &phba->ctrl, &sgl);
  3091. if (status != 0) {
  3092. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3093. "BM_%d : Post Template HDR Failed for"
  3094. "ULP_%d\n", ulp_num);
  3095. return status;
  3096. }
  3097. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3098. "BM_%d : Template HDR Pages Posted for"
  3099. "ULP_%d\n", ulp_num);
  3100. }
  3101. }
  3102. return 0;
  3103. }
  3104. static int
  3105. beiscsi_post_pages(struct beiscsi_hba *phba)
  3106. {
  3107. struct be_mem_descriptor *mem_descr;
  3108. struct mem_array *pm_arr;
  3109. unsigned int page_offset, i;
  3110. struct be_dma_mem sgl;
  3111. int status, ulp_num = 0;
  3112. mem_descr = phba->init_mem;
  3113. mem_descr += HWI_MEM_SGE;
  3114. pm_arr = mem_descr->mem_array;
  3115. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
  3116. if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
  3117. break;
  3118. page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
  3119. phba->fw_config.iscsi_icd_start[ulp_num]) / PAGE_SIZE;
  3120. for (i = 0; i < mem_descr->num_elements; i++) {
  3121. hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
  3122. status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
  3123. page_offset,
  3124. (pm_arr->size / PAGE_SIZE));
  3125. page_offset += pm_arr->size / PAGE_SIZE;
  3126. if (status != 0) {
  3127. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3128. "BM_%d : post sgl failed.\n");
  3129. return status;
  3130. }
  3131. pm_arr++;
  3132. }
  3133. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3134. "BM_%d : POSTED PAGES\n");
  3135. return 0;
  3136. }
  3137. static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
  3138. {
  3139. struct be_dma_mem *mem = &q->dma_mem;
  3140. if (mem->va) {
  3141. pci_free_consistent(phba->pcidev, mem->size,
  3142. mem->va, mem->dma);
  3143. mem->va = NULL;
  3144. }
  3145. }
  3146. static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
  3147. u16 len, u16 entry_size)
  3148. {
  3149. struct be_dma_mem *mem = &q->dma_mem;
  3150. memset(q, 0, sizeof(*q));
  3151. q->len = len;
  3152. q->entry_size = entry_size;
  3153. mem->size = len * entry_size;
  3154. mem->va = pci_zalloc_consistent(phba->pcidev, mem->size, &mem->dma);
  3155. if (!mem->va)
  3156. return -ENOMEM;
  3157. return 0;
  3158. }
  3159. static int
  3160. beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
  3161. struct hwi_context_memory *phwi_context,
  3162. struct hwi_controller *phwi_ctrlr)
  3163. {
  3164. unsigned int wrb_mem_index, offset, size, num_wrb_rings;
  3165. u64 pa_addr_lo;
  3166. unsigned int idx, num, i, ulp_num;
  3167. struct mem_array *pwrb_arr;
  3168. void *wrb_vaddr;
  3169. struct be_dma_mem sgl;
  3170. struct be_mem_descriptor *mem_descr;
  3171. struct hwi_wrb_context *pwrb_context;
  3172. int status;
  3173. uint8_t ulp_count = 0, ulp_base_num = 0;
  3174. uint16_t cid_count_ulp[BEISCSI_ULP_COUNT] = { 0 };
  3175. idx = 0;
  3176. mem_descr = phba->init_mem;
  3177. mem_descr += HWI_MEM_WRB;
  3178. pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
  3179. GFP_KERNEL);
  3180. if (!pwrb_arr) {
  3181. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3182. "BM_%d : Memory alloc failed in create wrb ring.\n");
  3183. return -ENOMEM;
  3184. }
  3185. wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
  3186. pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
  3187. num_wrb_rings = mem_descr->mem_array[idx].size /
  3188. (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
  3189. for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
  3190. if (num_wrb_rings) {
  3191. pwrb_arr[num].virtual_address = wrb_vaddr;
  3192. pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
  3193. pwrb_arr[num].size = phba->params.wrbs_per_cxn *
  3194. sizeof(struct iscsi_wrb);
  3195. wrb_vaddr += pwrb_arr[num].size;
  3196. pa_addr_lo += pwrb_arr[num].size;
  3197. num_wrb_rings--;
  3198. } else {
  3199. idx++;
  3200. wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
  3201. pa_addr_lo = mem_descr->mem_array[idx].\
  3202. bus_address.u.a64.address;
  3203. num_wrb_rings = mem_descr->mem_array[idx].size /
  3204. (phba->params.wrbs_per_cxn *
  3205. sizeof(struct iscsi_wrb));
  3206. pwrb_arr[num].virtual_address = wrb_vaddr;
  3207. pwrb_arr[num].bus_address.u.a64.address\
  3208. = pa_addr_lo;
  3209. pwrb_arr[num].size = phba->params.wrbs_per_cxn *
  3210. sizeof(struct iscsi_wrb);
  3211. wrb_vaddr += pwrb_arr[num].size;
  3212. pa_addr_lo += pwrb_arr[num].size;
  3213. num_wrb_rings--;
  3214. }
  3215. }
  3216. /* Get the ULP Count */
  3217. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
  3218. if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
  3219. ulp_count++;
  3220. ulp_base_num = ulp_num;
  3221. cid_count_ulp[ulp_num] =
  3222. BEISCSI_GET_CID_COUNT(phba, ulp_num);
  3223. }
  3224. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  3225. wrb_mem_index = 0;
  3226. offset = 0;
  3227. size = 0;
  3228. if (ulp_count > 1) {
  3229. ulp_base_num = (ulp_base_num + 1) % BEISCSI_ULP_COUNT;
  3230. if (!cid_count_ulp[ulp_base_num])
  3231. ulp_base_num = (ulp_base_num + 1) %
  3232. BEISCSI_ULP_COUNT;
  3233. cid_count_ulp[ulp_base_num]--;
  3234. }
  3235. hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
  3236. status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
  3237. &phwi_context->be_wrbq[i],
  3238. &phwi_ctrlr->wrb_context[i],
  3239. ulp_base_num);
  3240. if (status != 0) {
  3241. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3242. "BM_%d : wrbq create failed.");
  3243. kfree(pwrb_arr);
  3244. return status;
  3245. }
  3246. pwrb_context = &phwi_ctrlr->wrb_context[i];
  3247. BE_SET_CID_TO_CRI(i, pwrb_context->cid);
  3248. }
  3249. kfree(pwrb_arr);
  3250. return 0;
  3251. }
  3252. static void free_wrb_handles(struct beiscsi_hba *phba)
  3253. {
  3254. unsigned int index;
  3255. struct hwi_controller *phwi_ctrlr;
  3256. struct hwi_wrb_context *pwrb_context;
  3257. phwi_ctrlr = phba->phwi_ctrlr;
  3258. for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
  3259. pwrb_context = &phwi_ctrlr->wrb_context[index];
  3260. kfree(pwrb_context->pwrb_handle_base);
  3261. kfree(pwrb_context->pwrb_handle_basestd);
  3262. }
  3263. }
  3264. static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
  3265. {
  3266. struct be_queue_info *q;
  3267. struct be_ctrl_info *ctrl = &phba->ctrl;
  3268. q = &phba->ctrl.mcc_obj.q;
  3269. if (q->created)
  3270. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
  3271. be_queue_free(phba, q);
  3272. q = &phba->ctrl.mcc_obj.cq;
  3273. if (q->created)
  3274. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
  3275. be_queue_free(phba, q);
  3276. }
  3277. static void hwi_cleanup(struct beiscsi_hba *phba)
  3278. {
  3279. struct be_queue_info *q;
  3280. struct be_ctrl_info *ctrl = &phba->ctrl;
  3281. struct hwi_controller *phwi_ctrlr;
  3282. struct hwi_context_memory *phwi_context;
  3283. struct hwi_async_pdu_context *pasync_ctx;
  3284. int i, eq_for_mcc, ulp_num;
  3285. phwi_ctrlr = phba->phwi_ctrlr;
  3286. phwi_context = phwi_ctrlr->phwi_ctxt;
  3287. be_cmd_iscsi_remove_template_hdr(ctrl);
  3288. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  3289. q = &phwi_context->be_wrbq[i];
  3290. if (q->created)
  3291. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
  3292. }
  3293. kfree(phwi_context->be_wrbq);
  3294. free_wrb_handles(phba);
  3295. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  3296. if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
  3297. q = &phwi_context->be_def_hdrq[ulp_num];
  3298. if (q->created)
  3299. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
  3300. q = &phwi_context->be_def_dataq[ulp_num];
  3301. if (q->created)
  3302. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
  3303. pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num];
  3304. }
  3305. }
  3306. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  3307. for (i = 0; i < (phba->num_cpus); i++) {
  3308. q = &phwi_context->be_cq[i];
  3309. if (q->created)
  3310. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
  3311. }
  3312. be_mcc_queues_destroy(phba);
  3313. if (phba->msix_enabled)
  3314. eq_for_mcc = 1;
  3315. else
  3316. eq_for_mcc = 0;
  3317. for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
  3318. q = &phwi_context->be_eq[i].q;
  3319. if (q->created)
  3320. beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
  3321. }
  3322. be_cmd_fw_uninit(ctrl);
  3323. }
  3324. static int be_mcc_queues_create(struct beiscsi_hba *phba,
  3325. struct hwi_context_memory *phwi_context)
  3326. {
  3327. struct be_queue_info *q, *cq;
  3328. struct be_ctrl_info *ctrl = &phba->ctrl;
  3329. /* Alloc MCC compl queue */
  3330. cq = &phba->ctrl.mcc_obj.cq;
  3331. if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
  3332. sizeof(struct be_mcc_compl)))
  3333. goto err;
  3334. /* Ask BE to create MCC compl queue; */
  3335. if (phba->msix_enabled) {
  3336. if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
  3337. [phba->num_cpus].q, false, true, 0))
  3338. goto mcc_cq_free;
  3339. } else {
  3340. if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
  3341. false, true, 0))
  3342. goto mcc_cq_free;
  3343. }
  3344. /* Alloc MCC queue */
  3345. q = &phba->ctrl.mcc_obj.q;
  3346. if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
  3347. goto mcc_cq_destroy;
  3348. /* Ask BE to create MCC queue */
  3349. if (beiscsi_cmd_mccq_create(phba, q, cq))
  3350. goto mcc_q_free;
  3351. return 0;
  3352. mcc_q_free:
  3353. be_queue_free(phba, q);
  3354. mcc_cq_destroy:
  3355. beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
  3356. mcc_cq_free:
  3357. be_queue_free(phba, cq);
  3358. err:
  3359. return -ENOMEM;
  3360. }
  3361. /**
  3362. * find_num_cpus()- Get the CPU online count
  3363. * @phba: ptr to priv structure
  3364. *
  3365. * CPU count is used for creating EQ.
  3366. **/
  3367. static void find_num_cpus(struct beiscsi_hba *phba)
  3368. {
  3369. int num_cpus = 0;
  3370. num_cpus = num_online_cpus();
  3371. switch (phba->generation) {
  3372. case BE_GEN2:
  3373. case BE_GEN3:
  3374. phba->num_cpus = (num_cpus > BEISCSI_MAX_NUM_CPUS) ?
  3375. BEISCSI_MAX_NUM_CPUS : num_cpus;
  3376. break;
  3377. case BE_GEN4:
  3378. /*
  3379. * If eqid_count == 1 fall back to
  3380. * INTX mechanism
  3381. **/
  3382. if (phba->fw_config.eqid_count == 1) {
  3383. enable_msix = 0;
  3384. phba->num_cpus = 1;
  3385. return;
  3386. }
  3387. phba->num_cpus =
  3388. (num_cpus > (phba->fw_config.eqid_count - 1)) ?
  3389. (phba->fw_config.eqid_count - 1) : num_cpus;
  3390. break;
  3391. default:
  3392. phba->num_cpus = 1;
  3393. }
  3394. }
  3395. static int hwi_init_port(struct beiscsi_hba *phba)
  3396. {
  3397. struct hwi_controller *phwi_ctrlr;
  3398. struct hwi_context_memory *phwi_context;
  3399. unsigned int def_pdu_ring_sz;
  3400. struct be_ctrl_info *ctrl = &phba->ctrl;
  3401. int status, ulp_num;
  3402. phwi_ctrlr = phba->phwi_ctrlr;
  3403. phwi_context = phwi_ctrlr->phwi_ctxt;
  3404. phwi_context->max_eqd = 128;
  3405. phwi_context->min_eqd = 0;
  3406. phwi_context->cur_eqd = 0;
  3407. be_cmd_fw_initialize(&phba->ctrl);
  3408. status = beiscsi_create_eqs(phba, phwi_context);
  3409. if (status != 0) {
  3410. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3411. "BM_%d : EQ not created\n");
  3412. goto error;
  3413. }
  3414. status = be_mcc_queues_create(phba, phwi_context);
  3415. if (status != 0)
  3416. goto error;
  3417. status = mgmt_check_supported_fw(ctrl, phba);
  3418. if (status != 0) {
  3419. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3420. "BM_%d : Unsupported fw version\n");
  3421. goto error;
  3422. }
  3423. status = beiscsi_create_cqs(phba, phwi_context);
  3424. if (status != 0) {
  3425. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3426. "BM_%d : CQ not created\n");
  3427. goto error;
  3428. }
  3429. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  3430. if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
  3431. def_pdu_ring_sz =
  3432. BEISCSI_GET_CID_COUNT(phba, ulp_num) *
  3433. sizeof(struct phys_addr);
  3434. status = beiscsi_create_def_hdr(phba, phwi_context,
  3435. phwi_ctrlr,
  3436. def_pdu_ring_sz,
  3437. ulp_num);
  3438. if (status != 0) {
  3439. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3440. "BM_%d : Default Header not created for ULP : %d\n",
  3441. ulp_num);
  3442. goto error;
  3443. }
  3444. status = beiscsi_create_def_data(phba, phwi_context,
  3445. phwi_ctrlr,
  3446. def_pdu_ring_sz,
  3447. ulp_num);
  3448. if (status != 0) {
  3449. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3450. "BM_%d : Default Data not created for ULP : %d\n",
  3451. ulp_num);
  3452. goto error;
  3453. }
  3454. }
  3455. }
  3456. status = beiscsi_post_pages(phba);
  3457. if (status != 0) {
  3458. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3459. "BM_%d : Post SGL Pages Failed\n");
  3460. goto error;
  3461. }
  3462. status = beiscsi_post_template_hdr(phba);
  3463. if (status != 0) {
  3464. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3465. "BM_%d : Template HDR Posting for CXN Failed\n");
  3466. }
  3467. status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
  3468. if (status != 0) {
  3469. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3470. "BM_%d : WRB Rings not created\n");
  3471. goto error;
  3472. }
  3473. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  3474. uint16_t async_arr_idx = 0;
  3475. if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
  3476. uint16_t cri = 0;
  3477. struct hwi_async_pdu_context *pasync_ctx;
  3478. pasync_ctx = HWI_GET_ASYNC_PDU_CTX(
  3479. phwi_ctrlr, ulp_num);
  3480. for (cri = 0; cri <
  3481. phba->params.cxns_per_ctrl; cri++) {
  3482. if (ulp_num == BEISCSI_GET_ULP_FROM_CRI
  3483. (phwi_ctrlr, cri))
  3484. pasync_ctx->cid_to_async_cri_map[
  3485. phwi_ctrlr->wrb_context[cri].cid] =
  3486. async_arr_idx++;
  3487. }
  3488. }
  3489. }
  3490. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3491. "BM_%d : hwi_init_port success\n");
  3492. return 0;
  3493. error:
  3494. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3495. "BM_%d : hwi_init_port failed");
  3496. hwi_cleanup(phba);
  3497. return status;
  3498. }
  3499. static int hwi_init_controller(struct beiscsi_hba *phba)
  3500. {
  3501. struct hwi_controller *phwi_ctrlr;
  3502. phwi_ctrlr = phba->phwi_ctrlr;
  3503. if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
  3504. phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
  3505. init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
  3506. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3507. "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
  3508. phwi_ctrlr->phwi_ctxt);
  3509. } else {
  3510. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3511. "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
  3512. "than one element.Failing to load\n");
  3513. return -ENOMEM;
  3514. }
  3515. iscsi_init_global_templates(phba);
  3516. if (beiscsi_init_wrb_handle(phba))
  3517. return -ENOMEM;
  3518. if (hwi_init_async_pdu_ctx(phba)) {
  3519. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3520. "BM_%d : hwi_init_async_pdu_ctx failed\n");
  3521. return -ENOMEM;
  3522. }
  3523. if (hwi_init_port(phba) != 0) {
  3524. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3525. "BM_%d : hwi_init_controller failed\n");
  3526. return -ENOMEM;
  3527. }
  3528. return 0;
  3529. }
  3530. static void beiscsi_free_mem(struct beiscsi_hba *phba)
  3531. {
  3532. struct be_mem_descriptor *mem_descr;
  3533. int i, j;
  3534. mem_descr = phba->init_mem;
  3535. i = 0;
  3536. j = 0;
  3537. for (i = 0; i < SE_MEM_MAX; i++) {
  3538. for (j = mem_descr->num_elements; j > 0; j--) {
  3539. pci_free_consistent(phba->pcidev,
  3540. mem_descr->mem_array[j - 1].size,
  3541. mem_descr->mem_array[j - 1].virtual_address,
  3542. (unsigned long)mem_descr->mem_array[j - 1].
  3543. bus_address.u.a64.address);
  3544. }
  3545. kfree(mem_descr->mem_array);
  3546. mem_descr++;
  3547. }
  3548. kfree(phba->init_mem);
  3549. kfree(phba->phwi_ctrlr->wrb_context);
  3550. kfree(phba->phwi_ctrlr);
  3551. }
  3552. static int beiscsi_init_controller(struct beiscsi_hba *phba)
  3553. {
  3554. int ret = -ENOMEM;
  3555. ret = beiscsi_get_memory(phba);
  3556. if (ret < 0) {
  3557. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3558. "BM_%d : beiscsi_dev_probe -"
  3559. "Failed in beiscsi_alloc_memory\n");
  3560. return ret;
  3561. }
  3562. ret = hwi_init_controller(phba);
  3563. if (ret)
  3564. goto free_init;
  3565. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3566. "BM_%d : Return success from beiscsi_init_controller");
  3567. return 0;
  3568. free_init:
  3569. beiscsi_free_mem(phba);
  3570. return ret;
  3571. }
  3572. static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
  3573. {
  3574. struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
  3575. struct sgl_handle *psgl_handle;
  3576. struct iscsi_sge *pfrag;
  3577. unsigned int arr_index, i, idx;
  3578. unsigned int ulp_icd_start, ulp_num = 0;
  3579. phba->io_sgl_hndl_avbl = 0;
  3580. phba->eh_sgl_hndl_avbl = 0;
  3581. mem_descr_sglh = phba->init_mem;
  3582. mem_descr_sglh += HWI_MEM_SGLH;
  3583. if (1 == mem_descr_sglh->num_elements) {
  3584. phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
  3585. phba->params.ios_per_ctrl,
  3586. GFP_KERNEL);
  3587. if (!phba->io_sgl_hndl_base) {
  3588. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3589. "BM_%d : Mem Alloc Failed. Failing to load\n");
  3590. return -ENOMEM;
  3591. }
  3592. phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
  3593. (phba->params.icds_per_ctrl -
  3594. phba->params.ios_per_ctrl),
  3595. GFP_KERNEL);
  3596. if (!phba->eh_sgl_hndl_base) {
  3597. kfree(phba->io_sgl_hndl_base);
  3598. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3599. "BM_%d : Mem Alloc Failed. Failing to load\n");
  3600. return -ENOMEM;
  3601. }
  3602. } else {
  3603. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3604. "BM_%d : HWI_MEM_SGLH is more than one element."
  3605. "Failing to load\n");
  3606. return -ENOMEM;
  3607. }
  3608. arr_index = 0;
  3609. idx = 0;
  3610. while (idx < mem_descr_sglh->num_elements) {
  3611. psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
  3612. for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
  3613. sizeof(struct sgl_handle)); i++) {
  3614. if (arr_index < phba->params.ios_per_ctrl) {
  3615. phba->io_sgl_hndl_base[arr_index] = psgl_handle;
  3616. phba->io_sgl_hndl_avbl++;
  3617. arr_index++;
  3618. } else {
  3619. phba->eh_sgl_hndl_base[arr_index -
  3620. phba->params.ios_per_ctrl] =
  3621. psgl_handle;
  3622. arr_index++;
  3623. phba->eh_sgl_hndl_avbl++;
  3624. }
  3625. psgl_handle++;
  3626. }
  3627. idx++;
  3628. }
  3629. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3630. "BM_%d : phba->io_sgl_hndl_avbl=%d"
  3631. "phba->eh_sgl_hndl_avbl=%d\n",
  3632. phba->io_sgl_hndl_avbl,
  3633. phba->eh_sgl_hndl_avbl);
  3634. mem_descr_sg = phba->init_mem;
  3635. mem_descr_sg += HWI_MEM_SGE;
  3636. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3637. "\n BM_%d : mem_descr_sg->num_elements=%d\n",
  3638. mem_descr_sg->num_elements);
  3639. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
  3640. if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
  3641. break;
  3642. ulp_icd_start = phba->fw_config.iscsi_icd_start[ulp_num];
  3643. arr_index = 0;
  3644. idx = 0;
  3645. while (idx < mem_descr_sg->num_elements) {
  3646. pfrag = mem_descr_sg->mem_array[idx].virtual_address;
  3647. for (i = 0;
  3648. i < (mem_descr_sg->mem_array[idx].size) /
  3649. (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
  3650. i++) {
  3651. if (arr_index < phba->params.ios_per_ctrl)
  3652. psgl_handle = phba->io_sgl_hndl_base[arr_index];
  3653. else
  3654. psgl_handle = phba->eh_sgl_hndl_base[arr_index -
  3655. phba->params.ios_per_ctrl];
  3656. psgl_handle->pfrag = pfrag;
  3657. AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
  3658. AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
  3659. pfrag += phba->params.num_sge_per_io;
  3660. psgl_handle->sgl_index = ulp_icd_start + arr_index++;
  3661. }
  3662. idx++;
  3663. }
  3664. phba->io_sgl_free_index = 0;
  3665. phba->io_sgl_alloc_index = 0;
  3666. phba->eh_sgl_free_index = 0;
  3667. phba->eh_sgl_alloc_index = 0;
  3668. return 0;
  3669. }
  3670. static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
  3671. {
  3672. int ret;
  3673. uint16_t i, ulp_num;
  3674. struct ulp_cid_info *ptr_cid_info = NULL;
  3675. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  3676. if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
  3677. ptr_cid_info = kzalloc(sizeof(struct ulp_cid_info),
  3678. GFP_KERNEL);
  3679. if (!ptr_cid_info) {
  3680. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3681. "BM_%d : Failed to allocate memory"
  3682. "for ULP_CID_INFO for ULP : %d\n",
  3683. ulp_num);
  3684. ret = -ENOMEM;
  3685. goto free_memory;
  3686. }
  3687. /* Allocate memory for CID array */
  3688. ptr_cid_info->cid_array = kzalloc(sizeof(void *) *
  3689. BEISCSI_GET_CID_COUNT(phba,
  3690. ulp_num), GFP_KERNEL);
  3691. if (!ptr_cid_info->cid_array) {
  3692. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3693. "BM_%d : Failed to allocate memory"
  3694. "for CID_ARRAY for ULP : %d\n",
  3695. ulp_num);
  3696. kfree(ptr_cid_info);
  3697. ptr_cid_info = NULL;
  3698. ret = -ENOMEM;
  3699. goto free_memory;
  3700. }
  3701. ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT(
  3702. phba, ulp_num);
  3703. /* Save the cid_info_array ptr */
  3704. phba->cid_array_info[ulp_num] = ptr_cid_info;
  3705. }
  3706. }
  3707. phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
  3708. phba->params.cxns_per_ctrl, GFP_KERNEL);
  3709. if (!phba->ep_array) {
  3710. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3711. "BM_%d : Failed to allocate memory in "
  3712. "hba_setup_cid_tbls\n");
  3713. ret = -ENOMEM;
  3714. goto free_memory;
  3715. }
  3716. phba->conn_table = kzalloc(sizeof(struct beiscsi_conn *) *
  3717. phba->params.cxns_per_ctrl, GFP_KERNEL);
  3718. if (!phba->conn_table) {
  3719. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3720. "BM_%d : Failed to allocate memory in"
  3721. "hba_setup_cid_tbls\n");
  3722. kfree(phba->ep_array);
  3723. phba->ep_array = NULL;
  3724. ret = -ENOMEM;
  3725. goto free_memory;
  3726. }
  3727. for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
  3728. ulp_num = phba->phwi_ctrlr->wrb_context[i].ulp_num;
  3729. ptr_cid_info = phba->cid_array_info[ulp_num];
  3730. ptr_cid_info->cid_array[ptr_cid_info->cid_alloc++] =
  3731. phba->phwi_ctrlr->wrb_context[i].cid;
  3732. }
  3733. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  3734. if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
  3735. ptr_cid_info = phba->cid_array_info[ulp_num];
  3736. ptr_cid_info->cid_alloc = 0;
  3737. ptr_cid_info->cid_free = 0;
  3738. }
  3739. }
  3740. return 0;
  3741. free_memory:
  3742. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  3743. if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
  3744. ptr_cid_info = phba->cid_array_info[ulp_num];
  3745. if (ptr_cid_info) {
  3746. kfree(ptr_cid_info->cid_array);
  3747. kfree(ptr_cid_info);
  3748. phba->cid_array_info[ulp_num] = NULL;
  3749. }
  3750. }
  3751. }
  3752. return ret;
  3753. }
  3754. static void hwi_enable_intr(struct beiscsi_hba *phba)
  3755. {
  3756. struct be_ctrl_info *ctrl = &phba->ctrl;
  3757. struct hwi_controller *phwi_ctrlr;
  3758. struct hwi_context_memory *phwi_context;
  3759. struct be_queue_info *eq;
  3760. u8 __iomem *addr;
  3761. u32 reg, i;
  3762. u32 enabled;
  3763. phwi_ctrlr = phba->phwi_ctrlr;
  3764. phwi_context = phwi_ctrlr->phwi_ctxt;
  3765. addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
  3766. PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
  3767. reg = ioread32(addr);
  3768. enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3769. if (!enabled) {
  3770. reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3771. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3772. "BM_%d : reg =x%08x addr=%p\n", reg, addr);
  3773. iowrite32(reg, addr);
  3774. }
  3775. if (!phba->msix_enabled) {
  3776. eq = &phwi_context->be_eq[0].q;
  3777. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3778. "BM_%d : eq->id=%d\n", eq->id);
  3779. hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
  3780. } else {
  3781. for (i = 0; i <= phba->num_cpus; i++) {
  3782. eq = &phwi_context->be_eq[i].q;
  3783. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  3784. "BM_%d : eq->id=%d\n", eq->id);
  3785. hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
  3786. }
  3787. }
  3788. }
  3789. static void hwi_disable_intr(struct beiscsi_hba *phba)
  3790. {
  3791. struct be_ctrl_info *ctrl = &phba->ctrl;
  3792. u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
  3793. u32 reg = ioread32(addr);
  3794. u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3795. if (enabled) {
  3796. reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
  3797. iowrite32(reg, addr);
  3798. } else
  3799. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  3800. "BM_%d : In hwi_disable_intr, Already Disabled\n");
  3801. }
  3802. /**
  3803. * beiscsi_get_boot_info()- Get the boot session info
  3804. * @phba: The device priv structure instance
  3805. *
  3806. * Get the boot target info and store in driver priv structure
  3807. *
  3808. * return values
  3809. * Success: 0
  3810. * Failure: Non-Zero Value
  3811. **/
  3812. static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
  3813. {
  3814. struct be_cmd_get_session_resp *session_resp;
  3815. struct be_dma_mem nonemb_cmd;
  3816. unsigned int tag;
  3817. unsigned int s_handle;
  3818. int ret = -ENOMEM;
  3819. /* Get the session handle of the boot target */
  3820. ret = be_mgmt_get_boot_shandle(phba, &s_handle);
  3821. if (ret) {
  3822. beiscsi_log(phba, KERN_ERR,
  3823. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  3824. "BM_%d : No boot session\n");
  3825. return ret;
  3826. }
  3827. nonemb_cmd.va = pci_zalloc_consistent(phba->ctrl.pdev,
  3828. sizeof(*session_resp),
  3829. &nonemb_cmd.dma);
  3830. if (nonemb_cmd.va == NULL) {
  3831. beiscsi_log(phba, KERN_ERR,
  3832. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  3833. "BM_%d : Failed to allocate memory for"
  3834. "beiscsi_get_session_info\n");
  3835. return -ENOMEM;
  3836. }
  3837. tag = mgmt_get_session_info(phba, s_handle,
  3838. &nonemb_cmd);
  3839. if (!tag) {
  3840. beiscsi_log(phba, KERN_ERR,
  3841. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  3842. "BM_%d : beiscsi_get_session_info"
  3843. " Failed\n");
  3844. goto boot_freemem;
  3845. }
  3846. ret = beiscsi_mccq_compl(phba, tag, NULL, &nonemb_cmd);
  3847. if (ret) {
  3848. beiscsi_log(phba, KERN_ERR,
  3849. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  3850. "BM_%d : beiscsi_get_session_info Failed");
  3851. if (ret != -EBUSY)
  3852. goto boot_freemem;
  3853. else
  3854. return ret;
  3855. }
  3856. session_resp = nonemb_cmd.va ;
  3857. memcpy(&phba->boot_sess, &session_resp->session_info,
  3858. sizeof(struct mgmt_session_info));
  3859. ret = 0;
  3860. boot_freemem:
  3861. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  3862. nonemb_cmd.va, nonemb_cmd.dma);
  3863. return ret;
  3864. }
  3865. static void beiscsi_boot_release(void *data)
  3866. {
  3867. struct beiscsi_hba *phba = data;
  3868. scsi_host_put(phba->shost);
  3869. }
  3870. static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
  3871. {
  3872. struct iscsi_boot_kobj *boot_kobj;
  3873. /* it has been created previously */
  3874. if (phba->boot_kset)
  3875. return 0;
  3876. /* get boot info using mgmt cmd */
  3877. if (beiscsi_get_boot_info(phba))
  3878. /* Try to see if we can carry on without this */
  3879. return 0;
  3880. phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
  3881. if (!phba->boot_kset)
  3882. return -ENOMEM;
  3883. /* get a ref because the show function will ref the phba */
  3884. if (!scsi_host_get(phba->shost))
  3885. goto free_kset;
  3886. boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
  3887. beiscsi_show_boot_tgt_info,
  3888. beiscsi_tgt_get_attr_visibility,
  3889. beiscsi_boot_release);
  3890. if (!boot_kobj)
  3891. goto put_shost;
  3892. if (!scsi_host_get(phba->shost))
  3893. goto free_kset;
  3894. boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
  3895. beiscsi_show_boot_ini_info,
  3896. beiscsi_ini_get_attr_visibility,
  3897. beiscsi_boot_release);
  3898. if (!boot_kobj)
  3899. goto put_shost;
  3900. if (!scsi_host_get(phba->shost))
  3901. goto free_kset;
  3902. boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
  3903. beiscsi_show_boot_eth_info,
  3904. beiscsi_eth_get_attr_visibility,
  3905. beiscsi_boot_release);
  3906. if (!boot_kobj)
  3907. goto put_shost;
  3908. return 0;
  3909. put_shost:
  3910. scsi_host_put(phba->shost);
  3911. free_kset:
  3912. iscsi_boot_destroy_kset(phba->boot_kset);
  3913. return -ENOMEM;
  3914. }
  3915. static int beiscsi_init_port(struct beiscsi_hba *phba)
  3916. {
  3917. int ret;
  3918. ret = beiscsi_init_controller(phba);
  3919. if (ret < 0) {
  3920. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3921. "BM_%d : beiscsi_dev_probe - Failed in"
  3922. "beiscsi_init_controller\n");
  3923. return ret;
  3924. }
  3925. ret = beiscsi_init_sgl_handle(phba);
  3926. if (ret < 0) {
  3927. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3928. "BM_%d : beiscsi_dev_probe - Failed in"
  3929. "beiscsi_init_sgl_handle\n");
  3930. goto do_cleanup_ctrlr;
  3931. }
  3932. if (hba_setup_cid_tbls(phba)) {
  3933. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  3934. "BM_%d : Failed in hba_setup_cid_tbls\n");
  3935. kfree(phba->io_sgl_hndl_base);
  3936. kfree(phba->eh_sgl_hndl_base);
  3937. goto do_cleanup_ctrlr;
  3938. }
  3939. return ret;
  3940. do_cleanup_ctrlr:
  3941. hwi_cleanup(phba);
  3942. return ret;
  3943. }
  3944. static void hwi_purge_eq(struct beiscsi_hba *phba)
  3945. {
  3946. struct hwi_controller *phwi_ctrlr;
  3947. struct hwi_context_memory *phwi_context;
  3948. struct be_queue_info *eq;
  3949. struct be_eq_entry *eqe = NULL;
  3950. int i, eq_msix;
  3951. unsigned int num_processed;
  3952. phwi_ctrlr = phba->phwi_ctrlr;
  3953. phwi_context = phwi_ctrlr->phwi_ctxt;
  3954. if (phba->msix_enabled)
  3955. eq_msix = 1;
  3956. else
  3957. eq_msix = 0;
  3958. for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
  3959. eq = &phwi_context->be_eq[i].q;
  3960. eqe = queue_tail_node(eq);
  3961. num_processed = 0;
  3962. while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
  3963. & EQE_VALID_MASK) {
  3964. AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
  3965. queue_tail_inc(eq);
  3966. eqe = queue_tail_node(eq);
  3967. num_processed++;
  3968. }
  3969. if (num_processed)
  3970. hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
  3971. }
  3972. }
  3973. static void beiscsi_clean_port(struct beiscsi_hba *phba)
  3974. {
  3975. int mgmt_status, ulp_num;
  3976. struct ulp_cid_info *ptr_cid_info = NULL;
  3977. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  3978. if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
  3979. mgmt_status = mgmt_epfw_cleanup(phba, ulp_num);
  3980. if (mgmt_status)
  3981. beiscsi_log(phba, KERN_WARNING,
  3982. BEISCSI_LOG_INIT,
  3983. "BM_%d : mgmt_epfw_cleanup FAILED"
  3984. " for ULP_%d\n", ulp_num);
  3985. }
  3986. }
  3987. hwi_purge_eq(phba);
  3988. hwi_cleanup(phba);
  3989. kfree(phba->io_sgl_hndl_base);
  3990. kfree(phba->eh_sgl_hndl_base);
  3991. kfree(phba->ep_array);
  3992. kfree(phba->conn_table);
  3993. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  3994. if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
  3995. ptr_cid_info = phba->cid_array_info[ulp_num];
  3996. if (ptr_cid_info) {
  3997. kfree(ptr_cid_info->cid_array);
  3998. kfree(ptr_cid_info);
  3999. phba->cid_array_info[ulp_num] = NULL;
  4000. }
  4001. }
  4002. }
  4003. }
  4004. /**
  4005. * beiscsi_free_mgmt_task_handles()- Free driver CXN resources
  4006. * @beiscsi_conn: ptr to the conn to be cleaned up
  4007. * @task: ptr to iscsi_task resource to be freed.
  4008. *
  4009. * Free driver mgmt resources binded to CXN.
  4010. **/
  4011. void
  4012. beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
  4013. struct iscsi_task *task)
  4014. {
  4015. struct beiscsi_io_task *io_task;
  4016. struct beiscsi_hba *phba = beiscsi_conn->phba;
  4017. struct hwi_wrb_context *pwrb_context;
  4018. struct hwi_controller *phwi_ctrlr;
  4019. uint16_t cri_index = BE_GET_CRI_FROM_CID(
  4020. beiscsi_conn->beiscsi_conn_cid);
  4021. phwi_ctrlr = phba->phwi_ctrlr;
  4022. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  4023. io_task = task->dd_data;
  4024. if (io_task->pwrb_handle) {
  4025. memset(io_task->pwrb_handle->pwrb, 0,
  4026. sizeof(struct iscsi_wrb));
  4027. free_wrb_handle(phba, pwrb_context,
  4028. io_task->pwrb_handle);
  4029. io_task->pwrb_handle = NULL;
  4030. }
  4031. if (io_task->psgl_handle) {
  4032. spin_lock_bh(&phba->mgmt_sgl_lock);
  4033. free_mgmt_sgl_handle(phba,
  4034. io_task->psgl_handle);
  4035. io_task->psgl_handle = NULL;
  4036. spin_unlock_bh(&phba->mgmt_sgl_lock);
  4037. }
  4038. if (io_task->mtask_addr)
  4039. pci_unmap_single(phba->pcidev,
  4040. io_task->mtask_addr,
  4041. io_task->mtask_data_count,
  4042. PCI_DMA_TODEVICE);
  4043. }
  4044. /**
  4045. * beiscsi_cleanup_task()- Free driver resources of the task
  4046. * @task: ptr to the iscsi task
  4047. *
  4048. **/
  4049. static void beiscsi_cleanup_task(struct iscsi_task *task)
  4050. {
  4051. struct beiscsi_io_task *io_task = task->dd_data;
  4052. struct iscsi_conn *conn = task->conn;
  4053. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  4054. struct beiscsi_hba *phba = beiscsi_conn->phba;
  4055. struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
  4056. struct hwi_wrb_context *pwrb_context;
  4057. struct hwi_controller *phwi_ctrlr;
  4058. uint16_t cri_index = BE_GET_CRI_FROM_CID(
  4059. beiscsi_conn->beiscsi_conn_cid);
  4060. phwi_ctrlr = phba->phwi_ctrlr;
  4061. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  4062. if (io_task->cmd_bhs) {
  4063. pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
  4064. io_task->bhs_pa.u.a64.address);
  4065. io_task->cmd_bhs = NULL;
  4066. }
  4067. if (task->sc) {
  4068. if (io_task->pwrb_handle) {
  4069. free_wrb_handle(phba, pwrb_context,
  4070. io_task->pwrb_handle);
  4071. io_task->pwrb_handle = NULL;
  4072. }
  4073. if (io_task->psgl_handle) {
  4074. spin_lock(&phba->io_sgl_lock);
  4075. free_io_sgl_handle(phba, io_task->psgl_handle);
  4076. spin_unlock(&phba->io_sgl_lock);
  4077. io_task->psgl_handle = NULL;
  4078. }
  4079. if (io_task->scsi_cmnd) {
  4080. scsi_dma_unmap(io_task->scsi_cmnd);
  4081. io_task->scsi_cmnd = NULL;
  4082. }
  4083. } else {
  4084. if (!beiscsi_conn->login_in_progress)
  4085. beiscsi_free_mgmt_task_handles(beiscsi_conn, task);
  4086. }
  4087. }
  4088. void
  4089. beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
  4090. struct beiscsi_offload_params *params)
  4091. {
  4092. struct wrb_handle *pwrb_handle;
  4093. struct beiscsi_hba *phba = beiscsi_conn->phba;
  4094. struct iscsi_task *task = beiscsi_conn->task;
  4095. struct iscsi_session *session = task->conn->session;
  4096. u32 doorbell = 0;
  4097. /*
  4098. * We can always use 0 here because it is reserved by libiscsi for
  4099. * login/startup related tasks.
  4100. */
  4101. beiscsi_conn->login_in_progress = 0;
  4102. spin_lock_bh(&session->back_lock);
  4103. beiscsi_cleanup_task(task);
  4104. spin_unlock_bh(&session->back_lock);
  4105. pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid);
  4106. /* Check for the adapter family */
  4107. if (is_chip_be2_be3r(phba))
  4108. beiscsi_offload_cxn_v0(params, pwrb_handle,
  4109. phba->init_mem);
  4110. else
  4111. beiscsi_offload_cxn_v2(params, pwrb_handle);
  4112. be_dws_le_to_cpu(pwrb_handle->pwrb,
  4113. sizeof(struct iscsi_target_context_update_wrb));
  4114. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  4115. doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
  4116. << DB_DEF_PDU_WRB_INDEX_SHIFT;
  4117. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  4118. iowrite32(doorbell, phba->db_va +
  4119. beiscsi_conn->doorbell_offset);
  4120. }
  4121. static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
  4122. int *index, int *age)
  4123. {
  4124. *index = (int)itt;
  4125. if (age)
  4126. *age = conn->session->age;
  4127. }
  4128. /**
  4129. * beiscsi_alloc_pdu - allocates pdu and related resources
  4130. * @task: libiscsi task
  4131. * @opcode: opcode of pdu for task
  4132. *
  4133. * This is called with the session lock held. It will allocate
  4134. * the wrb and sgl if needed for the command. And it will prep
  4135. * the pdu's itt. beiscsi_parse_pdu will later translate
  4136. * the pdu itt to the libiscsi task itt.
  4137. */
  4138. static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  4139. {
  4140. struct beiscsi_io_task *io_task = task->dd_data;
  4141. struct iscsi_conn *conn = task->conn;
  4142. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  4143. struct beiscsi_hba *phba = beiscsi_conn->phba;
  4144. struct hwi_wrb_context *pwrb_context;
  4145. struct hwi_controller *phwi_ctrlr;
  4146. itt_t itt;
  4147. uint16_t cri_index = 0;
  4148. struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
  4149. dma_addr_t paddr;
  4150. io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
  4151. GFP_ATOMIC, &paddr);
  4152. if (!io_task->cmd_bhs)
  4153. return -ENOMEM;
  4154. io_task->bhs_pa.u.a64.address = paddr;
  4155. io_task->libiscsi_itt = (itt_t)task->itt;
  4156. io_task->conn = beiscsi_conn;
  4157. task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
  4158. task->hdr_max = sizeof(struct be_cmd_bhs);
  4159. io_task->psgl_handle = NULL;
  4160. io_task->pwrb_handle = NULL;
  4161. if (task->sc) {
  4162. spin_lock(&phba->io_sgl_lock);
  4163. io_task->psgl_handle = alloc_io_sgl_handle(phba);
  4164. spin_unlock(&phba->io_sgl_lock);
  4165. if (!io_task->psgl_handle) {
  4166. beiscsi_log(phba, KERN_ERR,
  4167. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  4168. "BM_%d : Alloc of IO_SGL_ICD Failed"
  4169. "for the CID : %d\n",
  4170. beiscsi_conn->beiscsi_conn_cid);
  4171. goto free_hndls;
  4172. }
  4173. io_task->pwrb_handle = alloc_wrb_handle(phba,
  4174. beiscsi_conn->beiscsi_conn_cid);
  4175. if (!io_task->pwrb_handle) {
  4176. beiscsi_log(phba, KERN_ERR,
  4177. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  4178. "BM_%d : Alloc of WRB_HANDLE Failed"
  4179. "for the CID : %d\n",
  4180. beiscsi_conn->beiscsi_conn_cid);
  4181. goto free_io_hndls;
  4182. }
  4183. } else {
  4184. io_task->scsi_cmnd = NULL;
  4185. if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
  4186. beiscsi_conn->task = task;
  4187. if (!beiscsi_conn->login_in_progress) {
  4188. spin_lock(&phba->mgmt_sgl_lock);
  4189. io_task->psgl_handle = (struct sgl_handle *)
  4190. alloc_mgmt_sgl_handle(phba);
  4191. spin_unlock(&phba->mgmt_sgl_lock);
  4192. if (!io_task->psgl_handle) {
  4193. beiscsi_log(phba, KERN_ERR,
  4194. BEISCSI_LOG_IO |
  4195. BEISCSI_LOG_CONFIG,
  4196. "BM_%d : Alloc of MGMT_SGL_ICD Failed"
  4197. "for the CID : %d\n",
  4198. beiscsi_conn->
  4199. beiscsi_conn_cid);
  4200. goto free_hndls;
  4201. }
  4202. beiscsi_conn->login_in_progress = 1;
  4203. beiscsi_conn->plogin_sgl_handle =
  4204. io_task->psgl_handle;
  4205. io_task->pwrb_handle =
  4206. alloc_wrb_handle(phba,
  4207. beiscsi_conn->beiscsi_conn_cid);
  4208. if (!io_task->pwrb_handle) {
  4209. beiscsi_log(phba, KERN_ERR,
  4210. BEISCSI_LOG_IO |
  4211. BEISCSI_LOG_CONFIG,
  4212. "BM_%d : Alloc of WRB_HANDLE Failed"
  4213. "for the CID : %d\n",
  4214. beiscsi_conn->
  4215. beiscsi_conn_cid);
  4216. goto free_mgmt_hndls;
  4217. }
  4218. beiscsi_conn->plogin_wrb_handle =
  4219. io_task->pwrb_handle;
  4220. } else {
  4221. io_task->psgl_handle =
  4222. beiscsi_conn->plogin_sgl_handle;
  4223. io_task->pwrb_handle =
  4224. beiscsi_conn->plogin_wrb_handle;
  4225. }
  4226. } else {
  4227. spin_lock(&phba->mgmt_sgl_lock);
  4228. io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
  4229. spin_unlock(&phba->mgmt_sgl_lock);
  4230. if (!io_task->psgl_handle) {
  4231. beiscsi_log(phba, KERN_ERR,
  4232. BEISCSI_LOG_IO |
  4233. BEISCSI_LOG_CONFIG,
  4234. "BM_%d : Alloc of MGMT_SGL_ICD Failed"
  4235. "for the CID : %d\n",
  4236. beiscsi_conn->
  4237. beiscsi_conn_cid);
  4238. goto free_hndls;
  4239. }
  4240. io_task->pwrb_handle =
  4241. alloc_wrb_handle(phba,
  4242. beiscsi_conn->beiscsi_conn_cid);
  4243. if (!io_task->pwrb_handle) {
  4244. beiscsi_log(phba, KERN_ERR,
  4245. BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
  4246. "BM_%d : Alloc of WRB_HANDLE Failed"
  4247. "for the CID : %d\n",
  4248. beiscsi_conn->beiscsi_conn_cid);
  4249. goto free_mgmt_hndls;
  4250. }
  4251. }
  4252. }
  4253. itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
  4254. wrb_index << 16) | (unsigned int)
  4255. (io_task->psgl_handle->sgl_index));
  4256. io_task->pwrb_handle->pio_handle = task;
  4257. io_task->cmd_bhs->iscsi_hdr.itt = itt;
  4258. return 0;
  4259. free_io_hndls:
  4260. spin_lock(&phba->io_sgl_lock);
  4261. free_io_sgl_handle(phba, io_task->psgl_handle);
  4262. spin_unlock(&phba->io_sgl_lock);
  4263. goto free_hndls;
  4264. free_mgmt_hndls:
  4265. spin_lock(&phba->mgmt_sgl_lock);
  4266. free_mgmt_sgl_handle(phba, io_task->psgl_handle);
  4267. io_task->psgl_handle = NULL;
  4268. spin_unlock(&phba->mgmt_sgl_lock);
  4269. free_hndls:
  4270. phwi_ctrlr = phba->phwi_ctrlr;
  4271. cri_index = BE_GET_CRI_FROM_CID(
  4272. beiscsi_conn->beiscsi_conn_cid);
  4273. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  4274. if (io_task->pwrb_handle)
  4275. free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
  4276. io_task->pwrb_handle = NULL;
  4277. pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
  4278. io_task->bhs_pa.u.a64.address);
  4279. io_task->cmd_bhs = NULL;
  4280. return -ENOMEM;
  4281. }
  4282. int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg,
  4283. unsigned int num_sg, unsigned int xferlen,
  4284. unsigned int writedir)
  4285. {
  4286. struct beiscsi_io_task *io_task = task->dd_data;
  4287. struct iscsi_conn *conn = task->conn;
  4288. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  4289. struct beiscsi_hba *phba = beiscsi_conn->phba;
  4290. struct iscsi_wrb *pwrb = NULL;
  4291. unsigned int doorbell = 0;
  4292. pwrb = io_task->pwrb_handle->pwrb;
  4293. io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
  4294. io_task->bhs_len = sizeof(struct be_cmd_bhs);
  4295. if (writedir) {
  4296. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
  4297. INI_WR_CMD);
  4298. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1);
  4299. } else {
  4300. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
  4301. INI_RD_CMD);
  4302. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0);
  4303. }
  4304. io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2,
  4305. type, pwrb);
  4306. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb,
  4307. cpu_to_be16(*(unsigned short *)
  4308. &io_task->cmd_bhs->iscsi_hdr.lun));
  4309. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen);
  4310. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
  4311. io_task->pwrb_handle->wrb_index);
  4312. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
  4313. be32_to_cpu(task->cmdsn));
  4314. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
  4315. io_task->psgl_handle->sgl_index);
  4316. hwi_write_sgl_v2(pwrb, sg, num_sg, io_task);
  4317. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
  4318. io_task->pwrb_handle->nxt_wrb_index);
  4319. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
  4320. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  4321. doorbell |= (io_task->pwrb_handle->wrb_index &
  4322. DB_DEF_PDU_WRB_INDEX_MASK) <<
  4323. DB_DEF_PDU_WRB_INDEX_SHIFT;
  4324. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  4325. iowrite32(doorbell, phba->db_va +
  4326. beiscsi_conn->doorbell_offset);
  4327. return 0;
  4328. }
  4329. static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
  4330. unsigned int num_sg, unsigned int xferlen,
  4331. unsigned int writedir)
  4332. {
  4333. struct beiscsi_io_task *io_task = task->dd_data;
  4334. struct iscsi_conn *conn = task->conn;
  4335. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  4336. struct beiscsi_hba *phba = beiscsi_conn->phba;
  4337. struct iscsi_wrb *pwrb = NULL;
  4338. unsigned int doorbell = 0;
  4339. pwrb = io_task->pwrb_handle->pwrb;
  4340. io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
  4341. io_task->bhs_len = sizeof(struct be_cmd_bhs);
  4342. if (writedir) {
  4343. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  4344. INI_WR_CMD);
  4345. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
  4346. } else {
  4347. AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
  4348. INI_RD_CMD);
  4349. AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
  4350. }
  4351. io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb,
  4352. type, pwrb);
  4353. AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
  4354. cpu_to_be16(*(unsigned short *)
  4355. &io_task->cmd_bhs->iscsi_hdr.lun));
  4356. AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
  4357. AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
  4358. io_task->pwrb_handle->wrb_index);
  4359. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
  4360. be32_to_cpu(task->cmdsn));
  4361. AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
  4362. io_task->psgl_handle->sgl_index);
  4363. hwi_write_sgl(pwrb, sg, num_sg, io_task);
  4364. AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
  4365. io_task->pwrb_handle->nxt_wrb_index);
  4366. be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
  4367. doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
  4368. doorbell |= (io_task->pwrb_handle->wrb_index &
  4369. DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
  4370. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  4371. iowrite32(doorbell, phba->db_va +
  4372. beiscsi_conn->doorbell_offset);
  4373. return 0;
  4374. }
  4375. static int beiscsi_mtask(struct iscsi_task *task)
  4376. {
  4377. struct beiscsi_io_task *io_task = task->dd_data;
  4378. struct iscsi_conn *conn = task->conn;
  4379. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  4380. struct beiscsi_hba *phba = beiscsi_conn->phba;
  4381. struct iscsi_wrb *pwrb = NULL;
  4382. unsigned int doorbell = 0;
  4383. unsigned int cid;
  4384. unsigned int pwrb_typeoffset = 0;
  4385. cid = beiscsi_conn->beiscsi_conn_cid;
  4386. pwrb = io_task->pwrb_handle->pwrb;
  4387. memset(pwrb, 0, sizeof(*pwrb));
  4388. if (is_chip_be2_be3r(phba)) {
  4389. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
  4390. be32_to_cpu(task->cmdsn));
  4391. AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
  4392. io_task->pwrb_handle->wrb_index);
  4393. AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
  4394. io_task->psgl_handle->sgl_index);
  4395. AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
  4396. task->data_count);
  4397. AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
  4398. io_task->pwrb_handle->nxt_wrb_index);
  4399. pwrb_typeoffset = BE_WRB_TYPE_OFFSET;
  4400. } else {
  4401. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
  4402. be32_to_cpu(task->cmdsn));
  4403. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
  4404. io_task->pwrb_handle->wrb_index);
  4405. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
  4406. io_task->psgl_handle->sgl_index);
  4407. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb,
  4408. task->data_count);
  4409. AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
  4410. io_task->pwrb_handle->nxt_wrb_index);
  4411. pwrb_typeoffset = SKH_WRB_TYPE_OFFSET;
  4412. }
  4413. switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
  4414. case ISCSI_OP_LOGIN:
  4415. AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
  4416. ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
  4417. hwi_write_buffer(pwrb, task);
  4418. break;
  4419. case ISCSI_OP_NOOP_OUT:
  4420. if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
  4421. ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
  4422. if (is_chip_be2_be3r(phba))
  4423. AMAP_SET_BITS(struct amap_iscsi_wrb,
  4424. dmsg, pwrb, 1);
  4425. else
  4426. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  4427. dmsg, pwrb, 1);
  4428. } else {
  4429. ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset);
  4430. if (is_chip_be2_be3r(phba))
  4431. AMAP_SET_BITS(struct amap_iscsi_wrb,
  4432. dmsg, pwrb, 0);
  4433. else
  4434. AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
  4435. dmsg, pwrb, 0);
  4436. }
  4437. hwi_write_buffer(pwrb, task);
  4438. break;
  4439. case ISCSI_OP_TEXT:
  4440. ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
  4441. hwi_write_buffer(pwrb, task);
  4442. break;
  4443. case ISCSI_OP_SCSI_TMFUNC:
  4444. ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset);
  4445. hwi_write_buffer(pwrb, task);
  4446. break;
  4447. case ISCSI_OP_LOGOUT:
  4448. ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset);
  4449. hwi_write_buffer(pwrb, task);
  4450. break;
  4451. default:
  4452. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4453. "BM_%d : opcode =%d Not supported\n",
  4454. task->hdr->opcode & ISCSI_OPCODE_MASK);
  4455. return -EINVAL;
  4456. }
  4457. /* Set the task type */
  4458. io_task->wrb_type = (is_chip_be2_be3r(phba)) ?
  4459. AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) :
  4460. AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb);
  4461. doorbell |= cid & DB_WRB_POST_CID_MASK;
  4462. doorbell |= (io_task->pwrb_handle->wrb_index &
  4463. DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
  4464. doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
  4465. iowrite32(doorbell, phba->db_va +
  4466. beiscsi_conn->doorbell_offset);
  4467. return 0;
  4468. }
  4469. static int beiscsi_task_xmit(struct iscsi_task *task)
  4470. {
  4471. struct beiscsi_io_task *io_task = task->dd_data;
  4472. struct scsi_cmnd *sc = task->sc;
  4473. struct beiscsi_hba *phba = NULL;
  4474. struct scatterlist *sg;
  4475. int num_sg;
  4476. unsigned int writedir = 0, xferlen = 0;
  4477. phba = ((struct beiscsi_conn *)task->conn->dd_data)->phba;
  4478. if (!sc)
  4479. return beiscsi_mtask(task);
  4480. io_task->scsi_cmnd = sc;
  4481. num_sg = scsi_dma_map(sc);
  4482. if (num_sg < 0) {
  4483. struct iscsi_conn *conn = task->conn;
  4484. struct beiscsi_hba *phba = NULL;
  4485. phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
  4486. beiscsi_log(phba, KERN_ERR,
  4487. BEISCSI_LOG_IO | BEISCSI_LOG_ISCSI,
  4488. "BM_%d : scsi_dma_map Failed "
  4489. "Driver_ITT : 0x%x ITT : 0x%x Xferlen : 0x%x\n",
  4490. be32_to_cpu(io_task->cmd_bhs->iscsi_hdr.itt),
  4491. io_task->libiscsi_itt, scsi_bufflen(sc));
  4492. return num_sg;
  4493. }
  4494. xferlen = scsi_bufflen(sc);
  4495. sg = scsi_sglist(sc);
  4496. if (sc->sc_data_direction == DMA_TO_DEVICE)
  4497. writedir = 1;
  4498. else
  4499. writedir = 0;
  4500. return phba->iotask_fn(task, sg, num_sg, xferlen, writedir);
  4501. }
  4502. /**
  4503. * beiscsi_bsg_request - handle bsg request from ISCSI transport
  4504. * @job: job to handle
  4505. */
  4506. static int beiscsi_bsg_request(struct bsg_job *job)
  4507. {
  4508. struct Scsi_Host *shost;
  4509. struct beiscsi_hba *phba;
  4510. struct iscsi_bsg_request *bsg_req = job->request;
  4511. int rc = -EINVAL;
  4512. unsigned int tag;
  4513. struct be_dma_mem nonemb_cmd;
  4514. struct be_cmd_resp_hdr *resp;
  4515. struct iscsi_bsg_reply *bsg_reply = job->reply;
  4516. unsigned short status, extd_status;
  4517. shost = iscsi_job_to_shost(job);
  4518. phba = iscsi_host_priv(shost);
  4519. switch (bsg_req->msgcode) {
  4520. case ISCSI_BSG_HST_VENDOR:
  4521. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  4522. job->request_payload.payload_len,
  4523. &nonemb_cmd.dma);
  4524. if (nonemb_cmd.va == NULL) {
  4525. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4526. "BM_%d : Failed to allocate memory for "
  4527. "beiscsi_bsg_request\n");
  4528. return -ENOMEM;
  4529. }
  4530. tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
  4531. &nonemb_cmd);
  4532. if (!tag) {
  4533. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4534. "BM_%d : MBX Tag Allocation Failed\n");
  4535. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  4536. nonemb_cmd.va, nonemb_cmd.dma);
  4537. return -EAGAIN;
  4538. }
  4539. rc = wait_event_interruptible_timeout(
  4540. phba->ctrl.mcc_wait[tag],
  4541. phba->ctrl.mcc_numtag[tag],
  4542. msecs_to_jiffies(
  4543. BEISCSI_HOST_MBX_TIMEOUT));
  4544. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  4545. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  4546. free_mcc_tag(&phba->ctrl, tag);
  4547. resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
  4548. sg_copy_from_buffer(job->reply_payload.sg_list,
  4549. job->reply_payload.sg_cnt,
  4550. nonemb_cmd.va, (resp->response_length
  4551. + sizeof(*resp)));
  4552. bsg_reply->reply_payload_rcv_len = resp->response_length;
  4553. bsg_reply->result = status;
  4554. bsg_job_done(job, bsg_reply->result,
  4555. bsg_reply->reply_payload_rcv_len);
  4556. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  4557. nonemb_cmd.va, nonemb_cmd.dma);
  4558. if (status || extd_status) {
  4559. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4560. "BM_%d : MBX Cmd Failed"
  4561. " status = %d extd_status = %d\n",
  4562. status, extd_status);
  4563. return -EIO;
  4564. } else {
  4565. rc = 0;
  4566. }
  4567. break;
  4568. default:
  4569. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  4570. "BM_%d : Unsupported bsg command: 0x%x\n",
  4571. bsg_req->msgcode);
  4572. break;
  4573. }
  4574. return rc;
  4575. }
  4576. void beiscsi_hba_attrs_init(struct beiscsi_hba *phba)
  4577. {
  4578. /* Set the logging parameter */
  4579. beiscsi_log_enable_init(phba, beiscsi_log_enable);
  4580. }
  4581. /*
  4582. * beiscsi_quiesce()- Cleanup Driver resources
  4583. * @phba: Instance Priv structure
  4584. * @unload_state:i Clean or EEH unload state
  4585. *
  4586. * Free the OS and HW resources held by the driver
  4587. **/
  4588. static void beiscsi_quiesce(struct beiscsi_hba *phba,
  4589. uint32_t unload_state)
  4590. {
  4591. struct hwi_controller *phwi_ctrlr;
  4592. struct hwi_context_memory *phwi_context;
  4593. struct be_eq_obj *pbe_eq;
  4594. unsigned int i, msix_vec;
  4595. phwi_ctrlr = phba->phwi_ctrlr;
  4596. phwi_context = phwi_ctrlr->phwi_ctxt;
  4597. hwi_disable_intr(phba);
  4598. if (phba->msix_enabled) {
  4599. for (i = 0; i <= phba->num_cpus; i++) {
  4600. msix_vec = phba->msix_entries[i].vector;
  4601. synchronize_irq(msix_vec);
  4602. free_irq(msix_vec, &phwi_context->be_eq[i]);
  4603. kfree(phba->msi_name[i]);
  4604. }
  4605. } else
  4606. if (phba->pcidev->irq) {
  4607. synchronize_irq(phba->pcidev->irq);
  4608. free_irq(phba->pcidev->irq, phba);
  4609. }
  4610. pci_disable_msix(phba->pcidev);
  4611. cancel_delayed_work_sync(&phba->beiscsi_hw_check_task);
  4612. for (i = 0; i < phba->num_cpus; i++) {
  4613. pbe_eq = &phwi_context->be_eq[i];
  4614. blk_iopoll_disable(&pbe_eq->iopoll);
  4615. }
  4616. if (unload_state == BEISCSI_CLEAN_UNLOAD) {
  4617. destroy_workqueue(phba->wq);
  4618. beiscsi_clean_port(phba);
  4619. beiscsi_free_mem(phba);
  4620. beiscsi_unmap_pci_function(phba);
  4621. pci_free_consistent(phba->pcidev,
  4622. phba->ctrl.mbox_mem_alloced.size,
  4623. phba->ctrl.mbox_mem_alloced.va,
  4624. phba->ctrl.mbox_mem_alloced.dma);
  4625. } else {
  4626. hwi_purge_eq(phba);
  4627. hwi_cleanup(phba);
  4628. }
  4629. }
  4630. static void beiscsi_remove(struct pci_dev *pcidev)
  4631. {
  4632. struct beiscsi_hba *phba = NULL;
  4633. phba = pci_get_drvdata(pcidev);
  4634. if (!phba) {
  4635. dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
  4636. return;
  4637. }
  4638. beiscsi_destroy_def_ifaces(phba);
  4639. beiscsi_quiesce(phba, BEISCSI_CLEAN_UNLOAD);
  4640. iscsi_boot_destroy_kset(phba->boot_kset);
  4641. iscsi_host_remove(phba->shost);
  4642. pci_dev_put(phba->pcidev);
  4643. iscsi_host_free(phba->shost);
  4644. pci_disable_pcie_error_reporting(pcidev);
  4645. pci_set_drvdata(pcidev, NULL);
  4646. pci_disable_device(pcidev);
  4647. }
  4648. static void beiscsi_shutdown(struct pci_dev *pcidev)
  4649. {
  4650. struct beiscsi_hba *phba = NULL;
  4651. phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
  4652. if (!phba) {
  4653. dev_err(&pcidev->dev, "beiscsi_shutdown called with no phba\n");
  4654. return;
  4655. }
  4656. phba->state = BE_ADAPTER_STATE_SHUTDOWN;
  4657. iscsi_host_for_each_session(phba->shost, be2iscsi_fail_session);
  4658. beiscsi_quiesce(phba, BEISCSI_CLEAN_UNLOAD);
  4659. pci_disable_device(pcidev);
  4660. }
  4661. static void beiscsi_msix_enable(struct beiscsi_hba *phba)
  4662. {
  4663. int i, status;
  4664. for (i = 0; i <= phba->num_cpus; i++)
  4665. phba->msix_entries[i].entry = i;
  4666. status = pci_enable_msix_range(phba->pcidev, phba->msix_entries,
  4667. phba->num_cpus + 1, phba->num_cpus + 1);
  4668. if (status > 0)
  4669. phba->msix_enabled = true;
  4670. return;
  4671. }
  4672. static void be_eqd_update(struct beiscsi_hba *phba)
  4673. {
  4674. struct be_set_eqd set_eqd[MAX_CPUS];
  4675. struct be_aic_obj *aic;
  4676. struct be_eq_obj *pbe_eq;
  4677. struct hwi_controller *phwi_ctrlr;
  4678. struct hwi_context_memory *phwi_context;
  4679. int eqd, i, num = 0;
  4680. ulong now;
  4681. u32 pps, delta;
  4682. unsigned int tag;
  4683. phwi_ctrlr = phba->phwi_ctrlr;
  4684. phwi_context = phwi_ctrlr->phwi_ctxt;
  4685. for (i = 0; i <= phba->num_cpus; i++) {
  4686. aic = &phba->aic_obj[i];
  4687. pbe_eq = &phwi_context->be_eq[i];
  4688. now = jiffies;
  4689. if (!aic->jiffs || time_before(now, aic->jiffs) ||
  4690. pbe_eq->cq_count < aic->eq_prev) {
  4691. aic->jiffs = now;
  4692. aic->eq_prev = pbe_eq->cq_count;
  4693. continue;
  4694. }
  4695. delta = jiffies_to_msecs(now - aic->jiffs);
  4696. pps = (((u32)(pbe_eq->cq_count - aic->eq_prev) * 1000) / delta);
  4697. eqd = (pps / 1500) << 2;
  4698. if (eqd < 8)
  4699. eqd = 0;
  4700. eqd = min_t(u32, eqd, phwi_context->max_eqd);
  4701. eqd = max_t(u32, eqd, phwi_context->min_eqd);
  4702. aic->jiffs = now;
  4703. aic->eq_prev = pbe_eq->cq_count;
  4704. if (eqd != aic->prev_eqd) {
  4705. set_eqd[num].delay_multiplier = (eqd * 65)/100;
  4706. set_eqd[num].eq_id = pbe_eq->q.id;
  4707. aic->prev_eqd = eqd;
  4708. num++;
  4709. }
  4710. }
  4711. if (num) {
  4712. tag = be_cmd_modify_eq_delay(phba, set_eqd, num);
  4713. if (tag)
  4714. beiscsi_mccq_compl(phba, tag, NULL, NULL);
  4715. }
  4716. }
  4717. static void be_check_boot_session(struct beiscsi_hba *phba)
  4718. {
  4719. if (beiscsi_setup_boot_info(phba))
  4720. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4721. "BM_%d : Could not set up "
  4722. "iSCSI boot info on async event.\n");
  4723. }
  4724. /*
  4725. * beiscsi_hw_health_check()- Check adapter health
  4726. * @work: work item to check HW health
  4727. *
  4728. * Check if adapter in an unrecoverable state or not.
  4729. **/
  4730. static void
  4731. beiscsi_hw_health_check(struct work_struct *work)
  4732. {
  4733. struct beiscsi_hba *phba =
  4734. container_of(work, struct beiscsi_hba,
  4735. beiscsi_hw_check_task.work);
  4736. be_eqd_update(phba);
  4737. if (phba->state & BE_ADAPTER_CHECK_BOOT) {
  4738. phba->state &= ~BE_ADAPTER_CHECK_BOOT;
  4739. be_check_boot_session(phba);
  4740. }
  4741. beiscsi_ue_detect(phba);
  4742. schedule_delayed_work(&phba->beiscsi_hw_check_task,
  4743. msecs_to_jiffies(1000));
  4744. }
  4745. static pci_ers_result_t beiscsi_eeh_err_detected(struct pci_dev *pdev,
  4746. pci_channel_state_t state)
  4747. {
  4748. struct beiscsi_hba *phba = NULL;
  4749. phba = (struct beiscsi_hba *)pci_get_drvdata(pdev);
  4750. phba->state |= BE_ADAPTER_PCI_ERR;
  4751. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4752. "BM_%d : EEH error detected\n");
  4753. beiscsi_quiesce(phba, BEISCSI_EEH_UNLOAD);
  4754. if (state == pci_channel_io_perm_failure) {
  4755. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4756. "BM_%d : EEH : State PERM Failure");
  4757. return PCI_ERS_RESULT_DISCONNECT;
  4758. }
  4759. pci_disable_device(pdev);
  4760. /* The error could cause the FW to trigger a flash debug dump.
  4761. * Resetting the card while flash dump is in progress
  4762. * can cause it not to recover; wait for it to finish.
  4763. * Wait only for first function as it is needed only once per
  4764. * adapter.
  4765. **/
  4766. if (pdev->devfn == 0)
  4767. ssleep(30);
  4768. return PCI_ERS_RESULT_NEED_RESET;
  4769. }
  4770. static pci_ers_result_t beiscsi_eeh_reset(struct pci_dev *pdev)
  4771. {
  4772. struct beiscsi_hba *phba = NULL;
  4773. int status = 0;
  4774. phba = (struct beiscsi_hba *)pci_get_drvdata(pdev);
  4775. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4776. "BM_%d : EEH Reset\n");
  4777. status = pci_enable_device(pdev);
  4778. if (status)
  4779. return PCI_ERS_RESULT_DISCONNECT;
  4780. pci_set_master(pdev);
  4781. pci_set_power_state(pdev, PCI_D0);
  4782. pci_restore_state(pdev);
  4783. /* Wait for the CHIP Reset to complete */
  4784. status = be_chk_reset_complete(phba);
  4785. if (!status) {
  4786. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  4787. "BM_%d : EEH Reset Completed\n");
  4788. } else {
  4789. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  4790. "BM_%d : EEH Reset Completion Failure\n");
  4791. return PCI_ERS_RESULT_DISCONNECT;
  4792. }
  4793. pci_cleanup_aer_uncorrect_error_status(pdev);
  4794. return PCI_ERS_RESULT_RECOVERED;
  4795. }
  4796. static void beiscsi_eeh_resume(struct pci_dev *pdev)
  4797. {
  4798. int ret = 0, i;
  4799. struct be_eq_obj *pbe_eq;
  4800. struct beiscsi_hba *phba = NULL;
  4801. struct hwi_controller *phwi_ctrlr;
  4802. struct hwi_context_memory *phwi_context;
  4803. phba = (struct beiscsi_hba *)pci_get_drvdata(pdev);
  4804. pci_save_state(pdev);
  4805. if (enable_msix)
  4806. find_num_cpus(phba);
  4807. else
  4808. phba->num_cpus = 1;
  4809. if (enable_msix) {
  4810. beiscsi_msix_enable(phba);
  4811. if (!phba->msix_enabled)
  4812. phba->num_cpus = 1;
  4813. }
  4814. ret = beiscsi_cmd_reset_function(phba);
  4815. if (ret) {
  4816. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4817. "BM_%d : Reset Failed\n");
  4818. goto ret_err;
  4819. }
  4820. ret = be_chk_reset_complete(phba);
  4821. if (ret) {
  4822. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4823. "BM_%d : Failed to get out of reset.\n");
  4824. goto ret_err;
  4825. }
  4826. beiscsi_get_params(phba);
  4827. phba->shost->max_id = phba->params.cxns_per_ctrl;
  4828. phba->shost->can_queue = phba->params.ios_per_ctrl;
  4829. ret = hwi_init_controller(phba);
  4830. for (i = 0; i < MAX_MCC_CMD; i++) {
  4831. init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
  4832. phba->ctrl.mcc_tag[i] = i + 1;
  4833. phba->ctrl.mcc_numtag[i + 1] = 0;
  4834. phba->ctrl.mcc_tag_available++;
  4835. }
  4836. phwi_ctrlr = phba->phwi_ctrlr;
  4837. phwi_context = phwi_ctrlr->phwi_ctxt;
  4838. for (i = 0; i < phba->num_cpus; i++) {
  4839. pbe_eq = &phwi_context->be_eq[i];
  4840. blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
  4841. be_iopoll);
  4842. blk_iopoll_enable(&pbe_eq->iopoll);
  4843. }
  4844. i = (phba->msix_enabled) ? i : 0;
  4845. /* Work item for MCC handling */
  4846. pbe_eq = &phwi_context->be_eq[i];
  4847. INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs);
  4848. ret = beiscsi_init_irqs(phba);
  4849. if (ret < 0) {
  4850. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4851. "BM_%d : beiscsi_eeh_resume - "
  4852. "Failed to beiscsi_init_irqs\n");
  4853. goto ret_err;
  4854. }
  4855. hwi_enable_intr(phba);
  4856. phba->state &= ~BE_ADAPTER_PCI_ERR;
  4857. return;
  4858. ret_err:
  4859. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4860. "BM_%d : AER EEH Resume Failed\n");
  4861. }
  4862. static int beiscsi_dev_probe(struct pci_dev *pcidev,
  4863. const struct pci_device_id *id)
  4864. {
  4865. struct beiscsi_hba *phba = NULL;
  4866. struct hwi_controller *phwi_ctrlr;
  4867. struct hwi_context_memory *phwi_context;
  4868. struct be_eq_obj *pbe_eq;
  4869. int ret = 0, i;
  4870. ret = beiscsi_enable_pci(pcidev);
  4871. if (ret < 0) {
  4872. dev_err(&pcidev->dev,
  4873. "beiscsi_dev_probe - Failed to enable pci device\n");
  4874. return ret;
  4875. }
  4876. phba = beiscsi_hba_alloc(pcidev);
  4877. if (!phba) {
  4878. dev_err(&pcidev->dev,
  4879. "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
  4880. goto disable_pci;
  4881. }
  4882. /* Enable EEH reporting */
  4883. ret = pci_enable_pcie_error_reporting(pcidev);
  4884. if (ret)
  4885. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  4886. "BM_%d : PCIe Error Reporting "
  4887. "Enabling Failed\n");
  4888. pci_save_state(pcidev);
  4889. /* Initialize Driver configuration Paramters */
  4890. beiscsi_hba_attrs_init(phba);
  4891. phba->fw_timeout = false;
  4892. phba->mac_addr_set = false;
  4893. switch (pcidev->device) {
  4894. case BE_DEVICE_ID1:
  4895. case OC_DEVICE_ID1:
  4896. case OC_DEVICE_ID2:
  4897. phba->generation = BE_GEN2;
  4898. phba->iotask_fn = beiscsi_iotask;
  4899. break;
  4900. case BE_DEVICE_ID2:
  4901. case OC_DEVICE_ID3:
  4902. phba->generation = BE_GEN3;
  4903. phba->iotask_fn = beiscsi_iotask;
  4904. break;
  4905. case OC_SKH_ID1:
  4906. phba->generation = BE_GEN4;
  4907. phba->iotask_fn = beiscsi_iotask_v2;
  4908. break;
  4909. default:
  4910. phba->generation = 0;
  4911. }
  4912. ret = be_ctrl_init(phba, pcidev);
  4913. if (ret) {
  4914. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4915. "BM_%d : beiscsi_dev_probe-"
  4916. "Failed in be_ctrl_init\n");
  4917. goto hba_free;
  4918. }
  4919. ret = beiscsi_cmd_reset_function(phba);
  4920. if (ret) {
  4921. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4922. "BM_%d : Reset Failed\n");
  4923. goto hba_free;
  4924. }
  4925. ret = be_chk_reset_complete(phba);
  4926. if (ret) {
  4927. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4928. "BM_%d : Failed to get out of reset.\n");
  4929. goto hba_free;
  4930. }
  4931. spin_lock_init(&phba->io_sgl_lock);
  4932. spin_lock_init(&phba->mgmt_sgl_lock);
  4933. spin_lock_init(&phba->isr_lock);
  4934. spin_lock_init(&phba->async_pdu_lock);
  4935. ret = mgmt_get_fw_config(&phba->ctrl, phba);
  4936. if (ret != 0) {
  4937. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4938. "BM_%d : Error getting fw config\n");
  4939. goto free_port;
  4940. }
  4941. if (enable_msix)
  4942. find_num_cpus(phba);
  4943. else
  4944. phba->num_cpus = 1;
  4945. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  4946. "BM_%d : num_cpus = %d\n",
  4947. phba->num_cpus);
  4948. if (enable_msix) {
  4949. beiscsi_msix_enable(phba);
  4950. if (!phba->msix_enabled)
  4951. phba->num_cpus = 1;
  4952. }
  4953. phba->shost->max_id = phba->params.cxns_per_ctrl;
  4954. beiscsi_get_params(phba);
  4955. phba->shost->can_queue = phba->params.ios_per_ctrl;
  4956. ret = beiscsi_init_port(phba);
  4957. if (ret < 0) {
  4958. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4959. "BM_%d : beiscsi_dev_probe-"
  4960. "Failed in beiscsi_init_port\n");
  4961. goto free_port;
  4962. }
  4963. for (i = 0; i < MAX_MCC_CMD; i++) {
  4964. init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
  4965. phba->ctrl.mcc_tag[i] = i + 1;
  4966. phba->ctrl.mcc_numtag[i + 1] = 0;
  4967. phba->ctrl.mcc_tag_available++;
  4968. memset(&phba->ctrl.ptag_state[i].tag_mem_state, 0,
  4969. sizeof(struct be_dma_mem));
  4970. }
  4971. phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
  4972. snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq",
  4973. phba->shost->host_no);
  4974. phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, phba->wq_name);
  4975. if (!phba->wq) {
  4976. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4977. "BM_%d : beiscsi_dev_probe-"
  4978. "Failed to allocate work queue\n");
  4979. goto free_twq;
  4980. }
  4981. INIT_DELAYED_WORK(&phba->beiscsi_hw_check_task,
  4982. beiscsi_hw_health_check);
  4983. phwi_ctrlr = phba->phwi_ctrlr;
  4984. phwi_context = phwi_ctrlr->phwi_ctxt;
  4985. for (i = 0; i < phba->num_cpus; i++) {
  4986. pbe_eq = &phwi_context->be_eq[i];
  4987. blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
  4988. be_iopoll);
  4989. blk_iopoll_enable(&pbe_eq->iopoll);
  4990. }
  4991. i = (phba->msix_enabled) ? i : 0;
  4992. /* Work item for MCC handling */
  4993. pbe_eq = &phwi_context->be_eq[i];
  4994. INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs);
  4995. ret = beiscsi_init_irqs(phba);
  4996. if (ret < 0) {
  4997. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  4998. "BM_%d : beiscsi_dev_probe-"
  4999. "Failed to beiscsi_init_irqs\n");
  5000. goto free_blkenbld;
  5001. }
  5002. hwi_enable_intr(phba);
  5003. if (iscsi_host_add(phba->shost, &phba->pcidev->dev))
  5004. goto free_blkenbld;
  5005. if (beiscsi_setup_boot_info(phba))
  5006. /*
  5007. * log error but continue, because we may not be using
  5008. * iscsi boot.
  5009. */
  5010. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  5011. "BM_%d : Could not set up "
  5012. "iSCSI boot info.\n");
  5013. beiscsi_create_def_ifaces(phba);
  5014. schedule_delayed_work(&phba->beiscsi_hw_check_task,
  5015. msecs_to_jiffies(1000));
  5016. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  5017. "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
  5018. return 0;
  5019. free_blkenbld:
  5020. destroy_workqueue(phba->wq);
  5021. for (i = 0; i < phba->num_cpus; i++) {
  5022. pbe_eq = &phwi_context->be_eq[i];
  5023. blk_iopoll_disable(&pbe_eq->iopoll);
  5024. }
  5025. free_twq:
  5026. beiscsi_clean_port(phba);
  5027. beiscsi_free_mem(phba);
  5028. free_port:
  5029. pci_free_consistent(phba->pcidev,
  5030. phba->ctrl.mbox_mem_alloced.size,
  5031. phba->ctrl.mbox_mem_alloced.va,
  5032. phba->ctrl.mbox_mem_alloced.dma);
  5033. beiscsi_unmap_pci_function(phba);
  5034. hba_free:
  5035. if (phba->msix_enabled)
  5036. pci_disable_msix(phba->pcidev);
  5037. pci_dev_put(phba->pcidev);
  5038. iscsi_host_free(phba->shost);
  5039. pci_set_drvdata(pcidev, NULL);
  5040. disable_pci:
  5041. pci_disable_device(pcidev);
  5042. return ret;
  5043. }
  5044. static struct pci_error_handlers beiscsi_eeh_handlers = {
  5045. .error_detected = beiscsi_eeh_err_detected,
  5046. .slot_reset = beiscsi_eeh_reset,
  5047. .resume = beiscsi_eeh_resume,
  5048. };
  5049. struct iscsi_transport beiscsi_iscsi_transport = {
  5050. .owner = THIS_MODULE,
  5051. .name = DRV_NAME,
  5052. .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
  5053. CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
  5054. .create_session = beiscsi_session_create,
  5055. .destroy_session = beiscsi_session_destroy,
  5056. .create_conn = beiscsi_conn_create,
  5057. .bind_conn = beiscsi_conn_bind,
  5058. .destroy_conn = iscsi_conn_teardown,
  5059. .attr_is_visible = be2iscsi_attr_is_visible,
  5060. .set_iface_param = be2iscsi_iface_set_param,
  5061. .get_iface_param = be2iscsi_iface_get_param,
  5062. .set_param = beiscsi_set_param,
  5063. .get_conn_param = iscsi_conn_get_param,
  5064. .get_session_param = iscsi_session_get_param,
  5065. .get_host_param = beiscsi_get_host_param,
  5066. .start_conn = beiscsi_conn_start,
  5067. .stop_conn = iscsi_conn_stop,
  5068. .send_pdu = iscsi_conn_send_pdu,
  5069. .xmit_task = beiscsi_task_xmit,
  5070. .cleanup_task = beiscsi_cleanup_task,
  5071. .alloc_pdu = beiscsi_alloc_pdu,
  5072. .parse_pdu_itt = beiscsi_parse_pdu,
  5073. .get_stats = beiscsi_conn_get_stats,
  5074. .get_ep_param = beiscsi_ep_get_param,
  5075. .ep_connect = beiscsi_ep_connect,
  5076. .ep_poll = beiscsi_ep_poll,
  5077. .ep_disconnect = beiscsi_ep_disconnect,
  5078. .session_recovery_timedout = iscsi_session_recovery_timedout,
  5079. .bsg_request = beiscsi_bsg_request,
  5080. };
  5081. static struct pci_driver beiscsi_pci_driver = {
  5082. .name = DRV_NAME,
  5083. .probe = beiscsi_dev_probe,
  5084. .remove = beiscsi_remove,
  5085. .shutdown = beiscsi_shutdown,
  5086. .id_table = beiscsi_pci_id_table,
  5087. .err_handler = &beiscsi_eeh_handlers
  5088. };
  5089. static int __init beiscsi_module_init(void)
  5090. {
  5091. int ret;
  5092. beiscsi_scsi_transport =
  5093. iscsi_register_transport(&beiscsi_iscsi_transport);
  5094. if (!beiscsi_scsi_transport) {
  5095. printk(KERN_ERR
  5096. "beiscsi_module_init - Unable to register beiscsi transport.\n");
  5097. return -ENOMEM;
  5098. }
  5099. printk(KERN_INFO "In beiscsi_module_init, tt=%p\n",
  5100. &beiscsi_iscsi_transport);
  5101. ret = pci_register_driver(&beiscsi_pci_driver);
  5102. if (ret) {
  5103. printk(KERN_ERR
  5104. "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
  5105. goto unregister_iscsi_transport;
  5106. }
  5107. return 0;
  5108. unregister_iscsi_transport:
  5109. iscsi_unregister_transport(&beiscsi_iscsi_transport);
  5110. return ret;
  5111. }
  5112. static void __exit beiscsi_module_exit(void)
  5113. {
  5114. pci_unregister_driver(&beiscsi_pci_driver);
  5115. iscsi_unregister_transport(&beiscsi_iscsi_transport);
  5116. }
  5117. module_init(beiscsi_module_init);
  5118. module_exit(beiscsi_module_exit);