bfa_ioc.c 159 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  4. * Copyright (c) 2014- QLogic Corporation.
  5. * All rights reserved
  6. * www.qlogic.com
  7. *
  8. * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
  9. */
  10. #include "bfad_drv.h"
  11. #include "bfad_im.h"
  12. #include "bfa_ioc.h"
  13. #include "bfi_reg.h"
  14. #include "bfa_defs.h"
  15. #include "bfa_defs_svc.h"
  16. #include "bfi.h"
  17. BFA_TRC_FILE(CNA, IOC);
  18. /*
  19. * IOC local definitions
  20. */
  21. #define BFA_IOC_TOV 3000 /* msecs */
  22. #define BFA_IOC_HWSEM_TOV 500 /* msecs */
  23. #define BFA_IOC_HB_TOV 500 /* msecs */
  24. #define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV
  25. #define BFA_IOC_POLL_TOV BFA_TIMER_FREQ
  26. #define bfa_ioc_timer_start(__ioc) \
  27. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
  28. bfa_ioc_timeout, (__ioc), BFA_IOC_TOV)
  29. #define bfa_ioc_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
  30. #define bfa_hb_timer_start(__ioc) \
  31. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->hb_timer, \
  32. bfa_ioc_hb_check, (__ioc), BFA_IOC_HB_TOV)
  33. #define bfa_hb_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->hb_timer)
  34. #define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn))
  35. #define bfa_ioc_state_disabled(__sm) \
  36. (((__sm) == BFI_IOC_UNINIT) || \
  37. ((__sm) == BFI_IOC_INITING) || \
  38. ((__sm) == BFI_IOC_HWINIT) || \
  39. ((__sm) == BFI_IOC_DISABLED) || \
  40. ((__sm) == BFI_IOC_FAIL) || \
  41. ((__sm) == BFI_IOC_CFG_DISABLED))
  42. /*
  43. * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
  44. */
  45. #define bfa_ioc_firmware_lock(__ioc) \
  46. ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
  47. #define bfa_ioc_firmware_unlock(__ioc) \
  48. ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
  49. #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
  50. #define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
  51. #define bfa_ioc_notify_fail(__ioc) \
  52. ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
  53. #define bfa_ioc_sync_start(__ioc) \
  54. ((__ioc)->ioc_hwif->ioc_sync_start(__ioc))
  55. #define bfa_ioc_sync_join(__ioc) \
  56. ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
  57. #define bfa_ioc_sync_leave(__ioc) \
  58. ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
  59. #define bfa_ioc_sync_ack(__ioc) \
  60. ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
  61. #define bfa_ioc_sync_complete(__ioc) \
  62. ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
  63. #define bfa_ioc_set_cur_ioc_fwstate(__ioc, __fwstate) \
  64. ((__ioc)->ioc_hwif->ioc_set_fwstate(__ioc, __fwstate))
  65. #define bfa_ioc_get_cur_ioc_fwstate(__ioc) \
  66. ((__ioc)->ioc_hwif->ioc_get_fwstate(__ioc))
  67. #define bfa_ioc_set_alt_ioc_fwstate(__ioc, __fwstate) \
  68. ((__ioc)->ioc_hwif->ioc_set_alt_fwstate(__ioc, __fwstate))
  69. #define bfa_ioc_get_alt_ioc_fwstate(__ioc) \
  70. ((__ioc)->ioc_hwif->ioc_get_alt_fwstate(__ioc))
  71. #define bfa_ioc_mbox_cmd_pending(__ioc) \
  72. (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
  73. readl((__ioc)->ioc_regs.hfn_mbox_cmd))
  74. bfa_boolean_t bfa_auto_recover = BFA_TRUE;
  75. /*
  76. * forward declarations
  77. */
  78. static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc);
  79. static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force);
  80. static void bfa_ioc_timeout(void *ioc);
  81. static void bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc);
  82. static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
  83. static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
  84. static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
  85. static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
  86. static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
  87. static void bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc);
  88. static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
  89. static void bfa_ioc_event_notify(struct bfa_ioc_s *ioc ,
  90. enum bfa_ioc_event_e event);
  91. static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
  92. static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
  93. static void bfa_ioc_fail_notify(struct bfa_ioc_s *ioc);
  94. static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc);
  95. static enum bfi_ioc_img_ver_cmp_e bfa_ioc_fw_ver_patch_cmp(
  96. struct bfi_ioc_image_hdr_s *base_fwhdr,
  97. struct bfi_ioc_image_hdr_s *fwhdr_to_cmp);
  98. static enum bfi_ioc_img_ver_cmp_e bfa_ioc_flash_fwver_cmp(
  99. struct bfa_ioc_s *ioc,
  100. struct bfi_ioc_image_hdr_s *base_fwhdr);
  101. /*
  102. * IOC state machine definitions/declarations
  103. */
  104. bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc_s, enum ioc_event);
  105. bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
  106. bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
  107. bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
  108. bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
  109. bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc_s, enum ioc_event);
  110. bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event);
  111. bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
  112. bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
  113. bfa_fsm_state_decl(bfa_ioc, hwfail, struct bfa_ioc_s, enum ioc_event);
  114. struct bfa_ioc_sm_table {
  115. bfa_ioc_sm_t sm; /* state machine function */
  116. enum bfa_ioc_state state; /* state machine encoding */
  117. char *name; /* state name for display */
  118. };
  119. static struct bfa_ioc_sm_table ioc_sm_table[] = {
  120. {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
  121. {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
  122. {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
  123. {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
  124. {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
  125. {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL},
  126. {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
  127. {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
  128. {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
  129. {BFA_SM(bfa_ioc_sm_hwfail), BFA_IOC_HWFAIL},
  130. };
  131. static inline enum bfa_ioc_state
  132. bfa_ioc_sm_to_state(struct bfa_ioc_sm_table *smt, bfa_ioc_sm_t sm)
  133. {
  134. int i = 0;
  135. while (smt[i].sm && smt[i].sm != sm)
  136. i++;
  137. return smt[i].state;
  138. }
  139. /*
  140. * IOCPF state machine definitions/declarations
  141. */
  142. #define bfa_iocpf_timer_start(__ioc) \
  143. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
  144. bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV)
  145. #define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
  146. #define bfa_iocpf_poll_timer_start(__ioc) \
  147. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
  148. bfa_iocpf_poll_timeout, (__ioc), BFA_IOC_POLL_TOV)
  149. #define bfa_sem_timer_start(__ioc) \
  150. bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \
  151. bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV)
  152. #define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer)
  153. /*
  154. * Forward declareations for iocpf state machine
  155. */
  156. static void bfa_iocpf_timeout(void *ioc_arg);
  157. static void bfa_iocpf_sem_timeout(void *ioc_arg);
  158. static void bfa_iocpf_poll_timeout(void *ioc_arg);
  159. /*
  160. * IOCPF states
  161. */
  162. enum bfa_iocpf_state {
  163. BFA_IOCPF_RESET = 1, /* IOC is in reset state */
  164. BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */
  165. BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */
  166. BFA_IOCPF_READY = 4, /* IOCPF is initialized */
  167. BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */
  168. BFA_IOCPF_FAIL = 6, /* IOCPF failed */
  169. BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */
  170. BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */
  171. BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */
  172. };
  173. bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event);
  174. bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event);
  175. bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event);
  176. bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event);
  177. bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event);
  178. bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event);
  179. bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event);
  180. bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s,
  181. enum iocpf_event);
  182. bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event);
  183. bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf_s, enum iocpf_event);
  184. bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event);
  185. bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event);
  186. bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s,
  187. enum iocpf_event);
  188. bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event);
  189. struct bfa_iocpf_sm_table {
  190. bfa_iocpf_sm_t sm; /* state machine function */
  191. enum bfa_iocpf_state state; /* state machine encoding */
  192. char *name; /* state name for display */
  193. };
  194. static inline enum bfa_iocpf_state
  195. bfa_iocpf_sm_to_state(struct bfa_iocpf_sm_table *smt, bfa_iocpf_sm_t sm)
  196. {
  197. int i = 0;
  198. while (smt[i].sm && smt[i].sm != sm)
  199. i++;
  200. return smt[i].state;
  201. }
  202. static struct bfa_iocpf_sm_table iocpf_sm_table[] = {
  203. {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
  204. {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
  205. {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
  206. {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
  207. {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
  208. {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
  209. {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
  210. {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
  211. {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
  212. {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
  213. {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
  214. {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
  215. {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
  216. {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
  217. };
  218. /*
  219. * IOC State Machine
  220. */
  221. /*
  222. * Beginning state. IOC uninit state.
  223. */
  224. static void
  225. bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
  226. {
  227. }
  228. /*
  229. * IOC is in uninit state.
  230. */
  231. static void
  232. bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
  233. {
  234. bfa_trc(ioc, event);
  235. switch (event) {
  236. case IOC_E_RESET:
  237. bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
  238. break;
  239. default:
  240. bfa_sm_fault(ioc, event);
  241. }
  242. }
  243. /*
  244. * Reset entry actions -- initialize state machine
  245. */
  246. static void
  247. bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
  248. {
  249. bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
  250. }
  251. /*
  252. * IOC is in reset state.
  253. */
  254. static void
  255. bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
  256. {
  257. bfa_trc(ioc, event);
  258. switch (event) {
  259. case IOC_E_ENABLE:
  260. bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
  261. break;
  262. case IOC_E_DISABLE:
  263. bfa_ioc_disable_comp(ioc);
  264. break;
  265. case IOC_E_DETACH:
  266. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  267. break;
  268. default:
  269. bfa_sm_fault(ioc, event);
  270. }
  271. }
  272. static void
  273. bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
  274. {
  275. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
  276. }
  277. /*
  278. * Host IOC function is being enabled, awaiting response from firmware.
  279. * Semaphore is acquired.
  280. */
  281. static void
  282. bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
  283. {
  284. bfa_trc(ioc, event);
  285. switch (event) {
  286. case IOC_E_ENABLED:
  287. bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
  288. break;
  289. case IOC_E_PFFAILED:
  290. /* !!! fall through !!! */
  291. case IOC_E_HWERROR:
  292. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  293. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  294. if (event != IOC_E_PFFAILED)
  295. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
  296. break;
  297. case IOC_E_HWFAILED:
  298. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  299. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
  300. break;
  301. case IOC_E_DISABLE:
  302. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  303. break;
  304. case IOC_E_DETACH:
  305. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  306. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  307. break;
  308. case IOC_E_ENABLE:
  309. break;
  310. default:
  311. bfa_sm_fault(ioc, event);
  312. }
  313. }
  314. static void
  315. bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
  316. {
  317. bfa_ioc_timer_start(ioc);
  318. bfa_ioc_send_getattr(ioc);
  319. }
  320. /*
  321. * IOC configuration in progress. Timer is active.
  322. */
  323. static void
  324. bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
  325. {
  326. bfa_trc(ioc, event);
  327. switch (event) {
  328. case IOC_E_FWRSP_GETATTR:
  329. bfa_ioc_timer_stop(ioc);
  330. bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
  331. break;
  332. case IOC_E_PFFAILED:
  333. case IOC_E_HWERROR:
  334. bfa_ioc_timer_stop(ioc);
  335. fallthrough;
  336. case IOC_E_TIMEOUT:
  337. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  338. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  339. if (event != IOC_E_PFFAILED)
  340. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
  341. break;
  342. case IOC_E_DISABLE:
  343. bfa_ioc_timer_stop(ioc);
  344. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  345. break;
  346. case IOC_E_ENABLE:
  347. break;
  348. default:
  349. bfa_sm_fault(ioc, event);
  350. }
  351. }
  352. static void
  353. bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
  354. {
  355. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  356. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
  357. bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
  358. bfa_ioc_hb_monitor(ioc);
  359. BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
  360. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_ENABLE);
  361. }
  362. static void
  363. bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
  364. {
  365. bfa_trc(ioc, event);
  366. switch (event) {
  367. case IOC_E_ENABLE:
  368. break;
  369. case IOC_E_DISABLE:
  370. bfa_hb_timer_stop(ioc);
  371. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  372. break;
  373. case IOC_E_PFFAILED:
  374. case IOC_E_HWERROR:
  375. bfa_hb_timer_stop(ioc);
  376. fallthrough;
  377. case IOC_E_HBFAIL:
  378. if (ioc->iocpf.auto_recover)
  379. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
  380. else
  381. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  382. bfa_ioc_fail_notify(ioc);
  383. if (event != IOC_E_PFFAILED)
  384. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
  385. break;
  386. default:
  387. bfa_sm_fault(ioc, event);
  388. }
  389. }
  390. static void
  391. bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
  392. {
  393. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  394. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
  395. BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n");
  396. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_DISABLE);
  397. }
  398. /*
  399. * IOC is being disabled
  400. */
  401. static void
  402. bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
  403. {
  404. bfa_trc(ioc, event);
  405. switch (event) {
  406. case IOC_E_DISABLED:
  407. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
  408. break;
  409. case IOC_E_HWERROR:
  410. /*
  411. * No state change. Will move to disabled state
  412. * after iocpf sm completes failure processing and
  413. * moves to disabled state.
  414. */
  415. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
  416. break;
  417. case IOC_E_HWFAILED:
  418. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
  419. bfa_ioc_disable_comp(ioc);
  420. break;
  421. default:
  422. bfa_sm_fault(ioc, event);
  423. }
  424. }
  425. /*
  426. * IOC disable completion entry.
  427. */
  428. static void
  429. bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
  430. {
  431. bfa_ioc_disable_comp(ioc);
  432. }
  433. static void
  434. bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
  435. {
  436. bfa_trc(ioc, event);
  437. switch (event) {
  438. case IOC_E_ENABLE:
  439. bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
  440. break;
  441. case IOC_E_DISABLE:
  442. ioc->cbfn->disable_cbfn(ioc->bfa);
  443. break;
  444. case IOC_E_DETACH:
  445. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  446. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  447. break;
  448. default:
  449. bfa_sm_fault(ioc, event);
  450. }
  451. }
  452. static void
  453. bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc)
  454. {
  455. bfa_trc(ioc, 0);
  456. }
  457. /*
  458. * Hardware initialization retry.
  459. */
  460. static void
  461. bfa_ioc_sm_fail_retry(struct bfa_ioc_s *ioc, enum ioc_event event)
  462. {
  463. bfa_trc(ioc, event);
  464. switch (event) {
  465. case IOC_E_ENABLED:
  466. bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
  467. break;
  468. case IOC_E_PFFAILED:
  469. case IOC_E_HWERROR:
  470. /*
  471. * Initialization retry failed.
  472. */
  473. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  474. bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
  475. if (event != IOC_E_PFFAILED)
  476. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
  477. break;
  478. case IOC_E_HWFAILED:
  479. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  480. bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
  481. break;
  482. case IOC_E_ENABLE:
  483. break;
  484. case IOC_E_DISABLE:
  485. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  486. break;
  487. case IOC_E_DETACH:
  488. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  489. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  490. break;
  491. default:
  492. bfa_sm_fault(ioc, event);
  493. }
  494. }
  495. static void
  496. bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
  497. {
  498. bfa_trc(ioc, 0);
  499. }
  500. /*
  501. * IOC failure.
  502. */
  503. static void
  504. bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
  505. {
  506. bfa_trc(ioc, event);
  507. switch (event) {
  508. case IOC_E_ENABLE:
  509. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  510. break;
  511. case IOC_E_DISABLE:
  512. bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
  513. break;
  514. case IOC_E_DETACH:
  515. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  516. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
  517. break;
  518. case IOC_E_HWERROR:
  519. case IOC_E_HWFAILED:
  520. /*
  521. * HB failure / HW error notification, ignore.
  522. */
  523. break;
  524. default:
  525. bfa_sm_fault(ioc, event);
  526. }
  527. }
  528. static void
  529. bfa_ioc_sm_hwfail_entry(struct bfa_ioc_s *ioc)
  530. {
  531. bfa_trc(ioc, 0);
  532. }
  533. static void
  534. bfa_ioc_sm_hwfail(struct bfa_ioc_s *ioc, enum ioc_event event)
  535. {
  536. bfa_trc(ioc, event);
  537. switch (event) {
  538. case IOC_E_ENABLE:
  539. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  540. break;
  541. case IOC_E_DISABLE:
  542. ioc->cbfn->disable_cbfn(ioc->bfa);
  543. break;
  544. case IOC_E_DETACH:
  545. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  546. break;
  547. case IOC_E_HWERROR:
  548. /* Ignore - already in hwfail state */
  549. break;
  550. default:
  551. bfa_sm_fault(ioc, event);
  552. }
  553. }
  554. /*
  555. * IOCPF State Machine
  556. */
  557. /*
  558. * Reset entry actions -- initialize state machine
  559. */
  560. static void
  561. bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
  562. {
  563. iocpf->fw_mismatch_notified = BFA_FALSE;
  564. iocpf->auto_recover = bfa_auto_recover;
  565. }
  566. /*
  567. * Beginning state. IOC is in reset state.
  568. */
  569. static void
  570. bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  571. {
  572. struct bfa_ioc_s *ioc = iocpf->ioc;
  573. bfa_trc(ioc, event);
  574. switch (event) {
  575. case IOCPF_E_ENABLE:
  576. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
  577. break;
  578. case IOCPF_E_STOP:
  579. break;
  580. default:
  581. bfa_sm_fault(ioc, event);
  582. }
  583. }
  584. /*
  585. * Semaphore should be acquired for version check.
  586. */
  587. static void
  588. bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
  589. {
  590. struct bfi_ioc_image_hdr_s fwhdr;
  591. u32 r32, fwstate, pgnum, loff = 0;
  592. int i;
  593. /*
  594. * Spin on init semaphore to serialize.
  595. */
  596. r32 = readl(iocpf->ioc->ioc_regs.ioc_init_sem_reg);
  597. while (r32 & 0x1) {
  598. udelay(20);
  599. r32 = readl(iocpf->ioc->ioc_regs.ioc_init_sem_reg);
  600. }
  601. /* h/w sem init */
  602. fwstate = bfa_ioc_get_cur_ioc_fwstate(iocpf->ioc);
  603. if (fwstate == BFI_IOC_UNINIT) {
  604. writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
  605. goto sem_get;
  606. }
  607. bfa_ioc_fwver_get(iocpf->ioc, &fwhdr);
  608. if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL) {
  609. writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
  610. goto sem_get;
  611. }
  612. /*
  613. * Clear fwver hdr
  614. */
  615. pgnum = PSS_SMEM_PGNUM(iocpf->ioc->ioc_regs.smem_pg0, loff);
  616. writel(pgnum, iocpf->ioc->ioc_regs.host_page_num_fn);
  617. for (i = 0; i < sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32); i++) {
  618. bfa_mem_write(iocpf->ioc->ioc_regs.smem_page_start, loff, 0);
  619. loff += sizeof(u32);
  620. }
  621. bfa_trc(iocpf->ioc, fwstate);
  622. bfa_trc(iocpf->ioc, swab32(fwhdr.exec));
  623. bfa_ioc_set_cur_ioc_fwstate(iocpf->ioc, BFI_IOC_UNINIT);
  624. bfa_ioc_set_alt_ioc_fwstate(iocpf->ioc, BFI_IOC_UNINIT);
  625. /*
  626. * Unlock the hw semaphore. Should be here only once per boot.
  627. */
  628. bfa_ioc_ownership_reset(iocpf->ioc);
  629. /*
  630. * unlock init semaphore.
  631. */
  632. writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
  633. sem_get:
  634. bfa_ioc_hw_sem_get(iocpf->ioc);
  635. }
  636. /*
  637. * Awaiting h/w semaphore to continue with version check.
  638. */
  639. static void
  640. bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  641. {
  642. struct bfa_ioc_s *ioc = iocpf->ioc;
  643. bfa_trc(ioc, event);
  644. switch (event) {
  645. case IOCPF_E_SEMLOCKED:
  646. if (bfa_ioc_firmware_lock(ioc)) {
  647. if (bfa_ioc_sync_start(ioc)) {
  648. bfa_ioc_sync_join(ioc);
  649. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  650. } else {
  651. bfa_ioc_firmware_unlock(ioc);
  652. writel(1, ioc->ioc_regs.ioc_sem_reg);
  653. bfa_sem_timer_start(ioc);
  654. }
  655. } else {
  656. writel(1, ioc->ioc_regs.ioc_sem_reg);
  657. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
  658. }
  659. break;
  660. case IOCPF_E_SEM_ERROR:
  661. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  662. bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
  663. break;
  664. case IOCPF_E_DISABLE:
  665. bfa_sem_timer_stop(ioc);
  666. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  667. bfa_fsm_send_event(ioc, IOC_E_DISABLED);
  668. break;
  669. case IOCPF_E_STOP:
  670. bfa_sem_timer_stop(ioc);
  671. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  672. break;
  673. default:
  674. bfa_sm_fault(ioc, event);
  675. }
  676. }
  677. /*
  678. * Notify enable completion callback.
  679. */
  680. static void
  681. bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
  682. {
  683. /*
  684. * Call only the first time sm enters fwmismatch state.
  685. */
  686. if (iocpf->fw_mismatch_notified == BFA_FALSE)
  687. bfa_ioc_pf_fwmismatch(iocpf->ioc);
  688. iocpf->fw_mismatch_notified = BFA_TRUE;
  689. bfa_iocpf_timer_start(iocpf->ioc);
  690. }
  691. /*
  692. * Awaiting firmware version match.
  693. */
  694. static void
  695. bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  696. {
  697. struct bfa_ioc_s *ioc = iocpf->ioc;
  698. bfa_trc(ioc, event);
  699. switch (event) {
  700. case IOCPF_E_TIMEOUT:
  701. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
  702. break;
  703. case IOCPF_E_DISABLE:
  704. bfa_iocpf_timer_stop(ioc);
  705. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  706. bfa_fsm_send_event(ioc, IOC_E_DISABLED);
  707. break;
  708. case IOCPF_E_STOP:
  709. bfa_iocpf_timer_stop(ioc);
  710. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  711. break;
  712. default:
  713. bfa_sm_fault(ioc, event);
  714. }
  715. }
  716. /*
  717. * Request for semaphore.
  718. */
  719. static void
  720. bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
  721. {
  722. bfa_ioc_hw_sem_get(iocpf->ioc);
  723. }
  724. /*
  725. * Awaiting semaphore for h/w initialzation.
  726. */
  727. static void
  728. bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  729. {
  730. struct bfa_ioc_s *ioc = iocpf->ioc;
  731. bfa_trc(ioc, event);
  732. switch (event) {
  733. case IOCPF_E_SEMLOCKED:
  734. if (bfa_ioc_sync_complete(ioc)) {
  735. bfa_ioc_sync_join(ioc);
  736. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  737. } else {
  738. writel(1, ioc->ioc_regs.ioc_sem_reg);
  739. bfa_sem_timer_start(ioc);
  740. }
  741. break;
  742. case IOCPF_E_SEM_ERROR:
  743. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  744. bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
  745. break;
  746. case IOCPF_E_DISABLE:
  747. bfa_sem_timer_stop(ioc);
  748. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  749. break;
  750. default:
  751. bfa_sm_fault(ioc, event);
  752. }
  753. }
  754. static void
  755. bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
  756. {
  757. iocpf->poll_time = 0;
  758. bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE);
  759. }
  760. /*
  761. * Hardware is being initialized. Interrupts are enabled.
  762. * Holding hardware semaphore lock.
  763. */
  764. static void
  765. bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  766. {
  767. struct bfa_ioc_s *ioc = iocpf->ioc;
  768. bfa_trc(ioc, event);
  769. switch (event) {
  770. case IOCPF_E_FWREADY:
  771. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
  772. break;
  773. case IOCPF_E_TIMEOUT:
  774. writel(1, ioc->ioc_regs.ioc_sem_reg);
  775. bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
  776. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  777. break;
  778. case IOCPF_E_DISABLE:
  779. bfa_iocpf_timer_stop(ioc);
  780. bfa_ioc_sync_leave(ioc);
  781. writel(1, ioc->ioc_regs.ioc_sem_reg);
  782. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  783. break;
  784. default:
  785. bfa_sm_fault(ioc, event);
  786. }
  787. }
  788. static void
  789. bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
  790. {
  791. bfa_iocpf_timer_start(iocpf->ioc);
  792. /*
  793. * Enable Interrupts before sending fw IOC ENABLE cmd.
  794. */
  795. iocpf->ioc->cbfn->reset_cbfn(iocpf->ioc->bfa);
  796. bfa_ioc_send_enable(iocpf->ioc);
  797. }
  798. /*
  799. * Host IOC function is being enabled, awaiting response from firmware.
  800. * Semaphore is acquired.
  801. */
  802. static void
  803. bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  804. {
  805. struct bfa_ioc_s *ioc = iocpf->ioc;
  806. bfa_trc(ioc, event);
  807. switch (event) {
  808. case IOCPF_E_FWRSP_ENABLE:
  809. bfa_iocpf_timer_stop(ioc);
  810. writel(1, ioc->ioc_regs.ioc_sem_reg);
  811. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
  812. break;
  813. case IOCPF_E_INITFAIL:
  814. bfa_iocpf_timer_stop(ioc);
  815. fallthrough;
  816. case IOCPF_E_TIMEOUT:
  817. writel(1, ioc->ioc_regs.ioc_sem_reg);
  818. if (event == IOCPF_E_TIMEOUT)
  819. bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
  820. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  821. break;
  822. case IOCPF_E_DISABLE:
  823. bfa_iocpf_timer_stop(ioc);
  824. writel(1, ioc->ioc_regs.ioc_sem_reg);
  825. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
  826. break;
  827. default:
  828. bfa_sm_fault(ioc, event);
  829. }
  830. }
  831. static void
  832. bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf)
  833. {
  834. bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED);
  835. }
  836. static void
  837. bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  838. {
  839. struct bfa_ioc_s *ioc = iocpf->ioc;
  840. bfa_trc(ioc, event);
  841. switch (event) {
  842. case IOCPF_E_DISABLE:
  843. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
  844. break;
  845. case IOCPF_E_GETATTRFAIL:
  846. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
  847. break;
  848. case IOCPF_E_FAIL:
  849. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
  850. break;
  851. default:
  852. bfa_sm_fault(ioc, event);
  853. }
  854. }
  855. static void
  856. bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
  857. {
  858. bfa_iocpf_timer_start(iocpf->ioc);
  859. bfa_ioc_send_disable(iocpf->ioc);
  860. }
  861. /*
  862. * IOC is being disabled
  863. */
  864. static void
  865. bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  866. {
  867. struct bfa_ioc_s *ioc = iocpf->ioc;
  868. bfa_trc(ioc, event);
  869. switch (event) {
  870. case IOCPF_E_FWRSP_DISABLE:
  871. bfa_iocpf_timer_stop(ioc);
  872. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  873. break;
  874. case IOCPF_E_FAIL:
  875. bfa_iocpf_timer_stop(ioc);
  876. fallthrough;
  877. case IOCPF_E_TIMEOUT:
  878. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
  879. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  880. break;
  881. case IOCPF_E_FWRSP_ENABLE:
  882. break;
  883. default:
  884. bfa_sm_fault(ioc, event);
  885. }
  886. }
  887. static void
  888. bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf)
  889. {
  890. bfa_ioc_hw_sem_get(iocpf->ioc);
  891. }
  892. /*
  893. * IOC hb ack request is being removed.
  894. */
  895. static void
  896. bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  897. {
  898. struct bfa_ioc_s *ioc = iocpf->ioc;
  899. bfa_trc(ioc, event);
  900. switch (event) {
  901. case IOCPF_E_SEMLOCKED:
  902. bfa_ioc_sync_leave(ioc);
  903. writel(1, ioc->ioc_regs.ioc_sem_reg);
  904. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  905. break;
  906. case IOCPF_E_SEM_ERROR:
  907. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  908. bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
  909. break;
  910. case IOCPF_E_FAIL:
  911. break;
  912. default:
  913. bfa_sm_fault(ioc, event);
  914. }
  915. }
  916. /*
  917. * IOC disable completion entry.
  918. */
  919. static void
  920. bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf)
  921. {
  922. bfa_ioc_mbox_flush(iocpf->ioc);
  923. bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED);
  924. }
  925. static void
  926. bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  927. {
  928. struct bfa_ioc_s *ioc = iocpf->ioc;
  929. bfa_trc(ioc, event);
  930. switch (event) {
  931. case IOCPF_E_ENABLE:
  932. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  933. break;
  934. case IOCPF_E_STOP:
  935. bfa_ioc_firmware_unlock(ioc);
  936. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  937. break;
  938. default:
  939. bfa_sm_fault(ioc, event);
  940. }
  941. }
  942. static void
  943. bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf)
  944. {
  945. bfa_ioc_debug_save_ftrc(iocpf->ioc);
  946. bfa_ioc_hw_sem_get(iocpf->ioc);
  947. }
  948. /*
  949. * Hardware initialization failed.
  950. */
  951. static void
  952. bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  953. {
  954. struct bfa_ioc_s *ioc = iocpf->ioc;
  955. bfa_trc(ioc, event);
  956. switch (event) {
  957. case IOCPF_E_SEMLOCKED:
  958. bfa_ioc_notify_fail(ioc);
  959. bfa_ioc_sync_leave(ioc);
  960. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
  961. writel(1, ioc->ioc_regs.ioc_sem_reg);
  962. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
  963. break;
  964. case IOCPF_E_SEM_ERROR:
  965. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  966. bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
  967. break;
  968. case IOCPF_E_DISABLE:
  969. bfa_sem_timer_stop(ioc);
  970. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  971. break;
  972. case IOCPF_E_STOP:
  973. bfa_sem_timer_stop(ioc);
  974. bfa_ioc_firmware_unlock(ioc);
  975. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  976. break;
  977. case IOCPF_E_FAIL:
  978. break;
  979. default:
  980. bfa_sm_fault(ioc, event);
  981. }
  982. }
  983. static void
  984. bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
  985. {
  986. bfa_trc(iocpf->ioc, 0);
  987. }
  988. /*
  989. * Hardware initialization failed.
  990. */
  991. static void
  992. bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  993. {
  994. struct bfa_ioc_s *ioc = iocpf->ioc;
  995. bfa_trc(ioc, event);
  996. switch (event) {
  997. case IOCPF_E_DISABLE:
  998. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  999. break;
  1000. case IOCPF_E_STOP:
  1001. bfa_ioc_firmware_unlock(ioc);
  1002. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
  1003. break;
  1004. default:
  1005. bfa_sm_fault(ioc, event);
  1006. }
  1007. }
  1008. static void
  1009. bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf)
  1010. {
  1011. /*
  1012. * Mark IOC as failed in hardware and stop firmware.
  1013. */
  1014. bfa_ioc_lpu_stop(iocpf->ioc);
  1015. /*
  1016. * Flush any queued up mailbox requests.
  1017. */
  1018. bfa_ioc_mbox_flush(iocpf->ioc);
  1019. bfa_ioc_hw_sem_get(iocpf->ioc);
  1020. }
  1021. static void
  1022. bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  1023. {
  1024. struct bfa_ioc_s *ioc = iocpf->ioc;
  1025. bfa_trc(ioc, event);
  1026. switch (event) {
  1027. case IOCPF_E_SEMLOCKED:
  1028. bfa_ioc_sync_ack(ioc);
  1029. bfa_ioc_notify_fail(ioc);
  1030. if (!iocpf->auto_recover) {
  1031. bfa_ioc_sync_leave(ioc);
  1032. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
  1033. writel(1, ioc->ioc_regs.ioc_sem_reg);
  1034. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  1035. } else {
  1036. if (bfa_ioc_sync_complete(ioc))
  1037. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
  1038. else {
  1039. writel(1, ioc->ioc_regs.ioc_sem_reg);
  1040. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
  1041. }
  1042. }
  1043. break;
  1044. case IOCPF_E_SEM_ERROR:
  1045. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
  1046. bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
  1047. break;
  1048. case IOCPF_E_DISABLE:
  1049. bfa_sem_timer_stop(ioc);
  1050. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
  1051. break;
  1052. case IOCPF_E_FAIL:
  1053. break;
  1054. default:
  1055. bfa_sm_fault(ioc, event);
  1056. }
  1057. }
  1058. static void
  1059. bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
  1060. {
  1061. bfa_trc(iocpf->ioc, 0);
  1062. }
  1063. /*
  1064. * IOC is in failed state.
  1065. */
  1066. static void
  1067. bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
  1068. {
  1069. struct bfa_ioc_s *ioc = iocpf->ioc;
  1070. bfa_trc(ioc, event);
  1071. switch (event) {
  1072. case IOCPF_E_DISABLE:
  1073. bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
  1074. break;
  1075. default:
  1076. bfa_sm_fault(ioc, event);
  1077. }
  1078. }
  1079. /*
  1080. * BFA IOC private functions
  1081. */
  1082. /*
  1083. * Notify common modules registered for notification.
  1084. */
  1085. static void
  1086. bfa_ioc_event_notify(struct bfa_ioc_s *ioc, enum bfa_ioc_event_e event)
  1087. {
  1088. struct bfa_ioc_notify_s *notify;
  1089. struct list_head *qe;
  1090. list_for_each(qe, &ioc->notify_q) {
  1091. notify = (struct bfa_ioc_notify_s *)qe;
  1092. notify->cbfn(notify->cbarg, event);
  1093. }
  1094. }
  1095. static void
  1096. bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
  1097. {
  1098. ioc->cbfn->disable_cbfn(ioc->bfa);
  1099. bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
  1100. }
  1101. bfa_boolean_t
  1102. bfa_ioc_sem_get(void __iomem *sem_reg)
  1103. {
  1104. u32 r32;
  1105. int cnt = 0;
  1106. #define BFA_SEM_SPINCNT 3000
  1107. r32 = readl(sem_reg);
  1108. while ((r32 & 1) && (cnt < BFA_SEM_SPINCNT)) {
  1109. cnt++;
  1110. udelay(2);
  1111. r32 = readl(sem_reg);
  1112. }
  1113. if (!(r32 & 1))
  1114. return BFA_TRUE;
  1115. return BFA_FALSE;
  1116. }
  1117. static void
  1118. bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
  1119. {
  1120. u32 r32;
  1121. /*
  1122. * First read to the semaphore register will return 0, subsequent reads
  1123. * will return 1. Semaphore is released by writing 1 to the register
  1124. */
  1125. r32 = readl(ioc->ioc_regs.ioc_sem_reg);
  1126. if (r32 == ~0) {
  1127. WARN_ON(r32 == ~0);
  1128. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEM_ERROR);
  1129. return;
  1130. }
  1131. if (!(r32 & 1)) {
  1132. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
  1133. return;
  1134. }
  1135. bfa_sem_timer_start(ioc);
  1136. }
  1137. /*
  1138. * Initialize LPU local memory (aka secondary memory / SRAM)
  1139. */
  1140. static void
  1141. bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
  1142. {
  1143. u32 pss_ctl;
  1144. int i;
  1145. #define PSS_LMEM_INIT_TIME 10000
  1146. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1147. pss_ctl &= ~__PSS_LMEM_RESET;
  1148. pss_ctl |= __PSS_LMEM_INIT_EN;
  1149. /*
  1150. * i2c workaround 12.5khz clock
  1151. */
  1152. pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
  1153. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1154. /*
  1155. * wait for memory initialization to be complete
  1156. */
  1157. i = 0;
  1158. do {
  1159. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1160. i++;
  1161. } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
  1162. /*
  1163. * If memory initialization is not successful, IOC timeout will catch
  1164. * such failures.
  1165. */
  1166. WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
  1167. bfa_trc(ioc, pss_ctl);
  1168. pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
  1169. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1170. }
  1171. static void
  1172. bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
  1173. {
  1174. u32 pss_ctl;
  1175. /*
  1176. * Take processor out of reset.
  1177. */
  1178. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1179. pss_ctl &= ~__PSS_LPU0_RESET;
  1180. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1181. }
  1182. static void
  1183. bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
  1184. {
  1185. u32 pss_ctl;
  1186. /*
  1187. * Put processors in reset.
  1188. */
  1189. pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
  1190. pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
  1191. writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
  1192. }
  1193. /*
  1194. * Get driver and firmware versions.
  1195. */
  1196. void
  1197. bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
  1198. {
  1199. u32 pgnum;
  1200. u32 loff = 0;
  1201. int i;
  1202. u32 *fwsig = (u32 *) fwhdr;
  1203. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  1204. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1205. for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
  1206. i++) {
  1207. fwsig[i] =
  1208. bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  1209. loff += sizeof(u32);
  1210. }
  1211. }
  1212. /*
  1213. * Returns TRUE if driver is willing to work with current smem f/w version.
  1214. */
  1215. bfa_boolean_t
  1216. bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc,
  1217. struct bfi_ioc_image_hdr_s *smem_fwhdr)
  1218. {
  1219. struct bfi_ioc_image_hdr_s *drv_fwhdr;
  1220. enum bfi_ioc_img_ver_cmp_e smem_flash_cmp, drv_smem_cmp;
  1221. drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
  1222. bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
  1223. /*
  1224. * If smem is incompatible or old, driver should not work with it.
  1225. */
  1226. drv_smem_cmp = bfa_ioc_fw_ver_patch_cmp(drv_fwhdr, smem_fwhdr);
  1227. if (drv_smem_cmp == BFI_IOC_IMG_VER_INCOMP ||
  1228. drv_smem_cmp == BFI_IOC_IMG_VER_OLD) {
  1229. return BFA_FALSE;
  1230. }
  1231. /*
  1232. * IF Flash has a better F/W than smem do not work with smem.
  1233. * If smem f/w == flash f/w, as smem f/w not old | incmp, work with it.
  1234. * If Flash is old or incomp work with smem iff smem f/w == drv f/w.
  1235. */
  1236. smem_flash_cmp = bfa_ioc_flash_fwver_cmp(ioc, smem_fwhdr);
  1237. if (smem_flash_cmp == BFI_IOC_IMG_VER_BETTER) {
  1238. return BFA_FALSE;
  1239. } else if (smem_flash_cmp == BFI_IOC_IMG_VER_SAME) {
  1240. return BFA_TRUE;
  1241. } else {
  1242. return (drv_smem_cmp == BFI_IOC_IMG_VER_SAME) ?
  1243. BFA_TRUE : BFA_FALSE;
  1244. }
  1245. }
  1246. /*
  1247. * Return true if current running version is valid. Firmware signature and
  1248. * execution context (driver/bios) must match.
  1249. */
  1250. static bfa_boolean_t
  1251. bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
  1252. {
  1253. struct bfi_ioc_image_hdr_s fwhdr;
  1254. bfa_ioc_fwver_get(ioc, &fwhdr);
  1255. if (swab32(fwhdr.bootenv) != boot_env) {
  1256. bfa_trc(ioc, fwhdr.bootenv);
  1257. bfa_trc(ioc, boot_env);
  1258. return BFA_FALSE;
  1259. }
  1260. return bfa_ioc_fwver_cmp(ioc, &fwhdr);
  1261. }
  1262. static bfa_boolean_t
  1263. bfa_ioc_fwver_md5_check(struct bfi_ioc_image_hdr_s *fwhdr_1,
  1264. struct bfi_ioc_image_hdr_s *fwhdr_2)
  1265. {
  1266. int i;
  1267. for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++)
  1268. if (fwhdr_1->md5sum[i] != fwhdr_2->md5sum[i])
  1269. return BFA_FALSE;
  1270. return BFA_TRUE;
  1271. }
  1272. /*
  1273. * Returns TRUE if major minor and maintainence are same.
  1274. * If patch versions are same, check for MD5 Checksum to be same.
  1275. */
  1276. static bfa_boolean_t
  1277. bfa_ioc_fw_ver_compatible(struct bfi_ioc_image_hdr_s *drv_fwhdr,
  1278. struct bfi_ioc_image_hdr_s *fwhdr_to_cmp)
  1279. {
  1280. if (drv_fwhdr->signature != fwhdr_to_cmp->signature)
  1281. return BFA_FALSE;
  1282. if (drv_fwhdr->fwver.major != fwhdr_to_cmp->fwver.major)
  1283. return BFA_FALSE;
  1284. if (drv_fwhdr->fwver.minor != fwhdr_to_cmp->fwver.minor)
  1285. return BFA_FALSE;
  1286. if (drv_fwhdr->fwver.maint != fwhdr_to_cmp->fwver.maint)
  1287. return BFA_FALSE;
  1288. if (drv_fwhdr->fwver.patch == fwhdr_to_cmp->fwver.patch &&
  1289. drv_fwhdr->fwver.phase == fwhdr_to_cmp->fwver.phase &&
  1290. drv_fwhdr->fwver.build == fwhdr_to_cmp->fwver.build) {
  1291. return bfa_ioc_fwver_md5_check(drv_fwhdr, fwhdr_to_cmp);
  1292. }
  1293. return BFA_TRUE;
  1294. }
  1295. static bfa_boolean_t
  1296. bfa_ioc_flash_fwver_valid(struct bfi_ioc_image_hdr_s *flash_fwhdr)
  1297. {
  1298. if (flash_fwhdr->fwver.major == 0 || flash_fwhdr->fwver.major == 0xFF)
  1299. return BFA_FALSE;
  1300. return BFA_TRUE;
  1301. }
  1302. static bfa_boolean_t fwhdr_is_ga(struct bfi_ioc_image_hdr_s *fwhdr)
  1303. {
  1304. if (fwhdr->fwver.phase == 0 &&
  1305. fwhdr->fwver.build == 0)
  1306. return BFA_TRUE;
  1307. return BFA_FALSE;
  1308. }
  1309. /*
  1310. * Returns TRUE if both are compatible and patch of fwhdr_to_cmp is better.
  1311. */
  1312. static enum bfi_ioc_img_ver_cmp_e
  1313. bfa_ioc_fw_ver_patch_cmp(struct bfi_ioc_image_hdr_s *base_fwhdr,
  1314. struct bfi_ioc_image_hdr_s *fwhdr_to_cmp)
  1315. {
  1316. if (bfa_ioc_fw_ver_compatible(base_fwhdr, fwhdr_to_cmp) == BFA_FALSE)
  1317. return BFI_IOC_IMG_VER_INCOMP;
  1318. if (fwhdr_to_cmp->fwver.patch > base_fwhdr->fwver.patch)
  1319. return BFI_IOC_IMG_VER_BETTER;
  1320. else if (fwhdr_to_cmp->fwver.patch < base_fwhdr->fwver.patch)
  1321. return BFI_IOC_IMG_VER_OLD;
  1322. /*
  1323. * GA takes priority over internal builds of the same patch stream.
  1324. * At this point major minor maint and patch numbers are same.
  1325. */
  1326. if (fwhdr_is_ga(base_fwhdr) == BFA_TRUE) {
  1327. if (fwhdr_is_ga(fwhdr_to_cmp))
  1328. return BFI_IOC_IMG_VER_SAME;
  1329. else
  1330. return BFI_IOC_IMG_VER_OLD;
  1331. } else {
  1332. if (fwhdr_is_ga(fwhdr_to_cmp))
  1333. return BFI_IOC_IMG_VER_BETTER;
  1334. }
  1335. if (fwhdr_to_cmp->fwver.phase > base_fwhdr->fwver.phase)
  1336. return BFI_IOC_IMG_VER_BETTER;
  1337. else if (fwhdr_to_cmp->fwver.phase < base_fwhdr->fwver.phase)
  1338. return BFI_IOC_IMG_VER_OLD;
  1339. if (fwhdr_to_cmp->fwver.build > base_fwhdr->fwver.build)
  1340. return BFI_IOC_IMG_VER_BETTER;
  1341. else if (fwhdr_to_cmp->fwver.build < base_fwhdr->fwver.build)
  1342. return BFI_IOC_IMG_VER_OLD;
  1343. /*
  1344. * All Version Numbers are equal.
  1345. * Md5 check to be done as a part of compatibility check.
  1346. */
  1347. return BFI_IOC_IMG_VER_SAME;
  1348. }
  1349. #define BFA_FLASH_PART_FWIMG_ADDR 0x100000 /* fw image address */
  1350. bfa_status_t
  1351. bfa_ioc_flash_img_get_chnk(struct bfa_ioc_s *ioc, u32 off,
  1352. u32 *fwimg)
  1353. {
  1354. return bfa_flash_raw_read(ioc->pcidev.pci_bar_kva,
  1355. BFA_FLASH_PART_FWIMG_ADDR + (off * sizeof(u32)),
  1356. (char *)fwimg, BFI_FLASH_CHUNK_SZ);
  1357. }
  1358. static enum bfi_ioc_img_ver_cmp_e
  1359. bfa_ioc_flash_fwver_cmp(struct bfa_ioc_s *ioc,
  1360. struct bfi_ioc_image_hdr_s *base_fwhdr)
  1361. {
  1362. struct bfi_ioc_image_hdr_s *flash_fwhdr;
  1363. bfa_status_t status;
  1364. u32 fwimg[BFI_FLASH_CHUNK_SZ_WORDS];
  1365. status = bfa_ioc_flash_img_get_chnk(ioc, 0, fwimg);
  1366. if (status != BFA_STATUS_OK)
  1367. return BFI_IOC_IMG_VER_INCOMP;
  1368. flash_fwhdr = (struct bfi_ioc_image_hdr_s *) fwimg;
  1369. if (bfa_ioc_flash_fwver_valid(flash_fwhdr) == BFA_TRUE)
  1370. return bfa_ioc_fw_ver_patch_cmp(base_fwhdr, flash_fwhdr);
  1371. else
  1372. return BFI_IOC_IMG_VER_INCOMP;
  1373. }
  1374. /*
  1375. * Invalidate fwver signature
  1376. */
  1377. bfa_status_t
  1378. bfa_ioc_fwsig_invalidate(struct bfa_ioc_s *ioc)
  1379. {
  1380. u32 pgnum;
  1381. u32 loff = 0;
  1382. enum bfi_ioc_state ioc_fwstate;
  1383. ioc_fwstate = bfa_ioc_get_cur_ioc_fwstate(ioc);
  1384. if (!bfa_ioc_state_disabled(ioc_fwstate))
  1385. return BFA_STATUS_ADAPTER_ENABLED;
  1386. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  1387. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1388. bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, BFA_IOC_FW_INV_SIGN);
  1389. return BFA_STATUS_OK;
  1390. }
  1391. /*
  1392. * Conditionally flush any pending message from firmware at start.
  1393. */
  1394. static void
  1395. bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
  1396. {
  1397. u32 r32;
  1398. r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
  1399. if (r32)
  1400. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  1401. }
  1402. static void
  1403. bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
  1404. {
  1405. enum bfi_ioc_state ioc_fwstate;
  1406. bfa_boolean_t fwvalid;
  1407. u32 boot_type;
  1408. u32 boot_env;
  1409. ioc_fwstate = bfa_ioc_get_cur_ioc_fwstate(ioc);
  1410. if (force)
  1411. ioc_fwstate = BFI_IOC_UNINIT;
  1412. bfa_trc(ioc, ioc_fwstate);
  1413. boot_type = BFI_FWBOOT_TYPE_NORMAL;
  1414. boot_env = BFI_FWBOOT_ENV_OS;
  1415. /*
  1416. * check if firmware is valid
  1417. */
  1418. fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
  1419. BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
  1420. if (!fwvalid) {
  1421. if (bfa_ioc_boot(ioc, boot_type, boot_env) == BFA_STATUS_OK)
  1422. bfa_ioc_poll_fwinit(ioc);
  1423. return;
  1424. }
  1425. /*
  1426. * If hardware initialization is in progress (initialized by other IOC),
  1427. * just wait for an initialization completion interrupt.
  1428. */
  1429. if (ioc_fwstate == BFI_IOC_INITING) {
  1430. bfa_ioc_poll_fwinit(ioc);
  1431. return;
  1432. }
  1433. /*
  1434. * If IOC function is disabled and firmware version is same,
  1435. * just re-enable IOC.
  1436. *
  1437. * If option rom, IOC must not be in operational state. With
  1438. * convergence, IOC will be in operational state when 2nd driver
  1439. * is loaded.
  1440. */
  1441. if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
  1442. /*
  1443. * When using MSI-X any pending firmware ready event should
  1444. * be flushed. Otherwise MSI-X interrupts are not delivered.
  1445. */
  1446. bfa_ioc_msgflush(ioc);
  1447. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
  1448. return;
  1449. }
  1450. /*
  1451. * Initialize the h/w for any other states.
  1452. */
  1453. if (bfa_ioc_boot(ioc, boot_type, boot_env) == BFA_STATUS_OK)
  1454. bfa_ioc_poll_fwinit(ioc);
  1455. }
  1456. static void
  1457. bfa_ioc_timeout(void *ioc_arg)
  1458. {
  1459. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  1460. bfa_trc(ioc, 0);
  1461. bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
  1462. }
  1463. void
  1464. bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
  1465. {
  1466. u32 *msgp = (u32 *) ioc_msg;
  1467. u32 i;
  1468. bfa_trc(ioc, msgp[0]);
  1469. bfa_trc(ioc, len);
  1470. WARN_ON(len > BFI_IOC_MSGLEN_MAX);
  1471. /*
  1472. * first write msg to mailbox registers
  1473. */
  1474. for (i = 0; i < len / sizeof(u32); i++)
  1475. writel(cpu_to_le32(msgp[i]),
  1476. ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
  1477. for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
  1478. writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
  1479. /*
  1480. * write 1 to mailbox CMD to trigger LPU event
  1481. */
  1482. writel(1, ioc->ioc_regs.hfn_mbox_cmd);
  1483. (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
  1484. }
  1485. static void
  1486. bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
  1487. {
  1488. struct bfi_ioc_ctrl_req_s enable_req;
  1489. bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
  1490. bfa_ioc_portid(ioc));
  1491. enable_req.clscode = cpu_to_be16(ioc->clscode);
  1492. /* unsigned 32-bit time_t overflow in y2106 */
  1493. enable_req.tv_sec = be32_to_cpu(ktime_get_real_seconds());
  1494. bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
  1495. }
  1496. static void
  1497. bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
  1498. {
  1499. struct bfi_ioc_ctrl_req_s disable_req;
  1500. bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
  1501. bfa_ioc_portid(ioc));
  1502. disable_req.clscode = cpu_to_be16(ioc->clscode);
  1503. /* unsigned 32-bit time_t overflow in y2106 */
  1504. disable_req.tv_sec = be32_to_cpu(ktime_get_real_seconds());
  1505. bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
  1506. }
  1507. static void
  1508. bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
  1509. {
  1510. struct bfi_ioc_getattr_req_s attr_req;
  1511. bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
  1512. bfa_ioc_portid(ioc));
  1513. bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
  1514. bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
  1515. }
  1516. static void
  1517. bfa_ioc_hb_check(void *cbarg)
  1518. {
  1519. struct bfa_ioc_s *ioc = cbarg;
  1520. u32 hb_count;
  1521. hb_count = readl(ioc->ioc_regs.heartbeat);
  1522. if (ioc->hb_count == hb_count) {
  1523. bfa_ioc_recover(ioc);
  1524. return;
  1525. } else {
  1526. ioc->hb_count = hb_count;
  1527. }
  1528. bfa_ioc_mbox_poll(ioc);
  1529. bfa_hb_timer_start(ioc);
  1530. }
  1531. static void
  1532. bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
  1533. {
  1534. ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
  1535. bfa_hb_timer_start(ioc);
  1536. }
  1537. /*
  1538. * Initiate a full firmware download.
  1539. */
  1540. static bfa_status_t
  1541. bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
  1542. u32 boot_env)
  1543. {
  1544. u32 *fwimg;
  1545. u32 pgnum;
  1546. u32 loff = 0;
  1547. u32 chunkno = 0;
  1548. u32 i;
  1549. u32 asicmode;
  1550. u32 fwimg_size;
  1551. u32 fwimg_buf[BFI_FLASH_CHUNK_SZ_WORDS];
  1552. bfa_status_t status;
  1553. if (boot_env == BFI_FWBOOT_ENV_OS &&
  1554. boot_type == BFI_FWBOOT_TYPE_FLASH) {
  1555. fwimg_size = BFI_FLASH_IMAGE_SZ/sizeof(u32);
  1556. status = bfa_ioc_flash_img_get_chnk(ioc,
  1557. BFA_IOC_FLASH_CHUNK_ADDR(chunkno), fwimg_buf);
  1558. if (status != BFA_STATUS_OK)
  1559. return status;
  1560. fwimg = fwimg_buf;
  1561. } else {
  1562. fwimg_size = bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc));
  1563. fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc),
  1564. BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
  1565. }
  1566. bfa_trc(ioc, fwimg_size);
  1567. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  1568. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1569. for (i = 0; i < fwimg_size; i++) {
  1570. if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
  1571. chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
  1572. if (boot_env == BFI_FWBOOT_ENV_OS &&
  1573. boot_type == BFI_FWBOOT_TYPE_FLASH) {
  1574. status = bfa_ioc_flash_img_get_chnk(ioc,
  1575. BFA_IOC_FLASH_CHUNK_ADDR(chunkno),
  1576. fwimg_buf);
  1577. if (status != BFA_STATUS_OK)
  1578. return status;
  1579. fwimg = fwimg_buf;
  1580. } else {
  1581. fwimg = bfa_cb_image_get_chunk(
  1582. bfa_ioc_asic_gen(ioc),
  1583. BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
  1584. }
  1585. }
  1586. /*
  1587. * write smem
  1588. */
  1589. bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
  1590. fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
  1591. loff += sizeof(u32);
  1592. /*
  1593. * handle page offset wrap around
  1594. */
  1595. loff = PSS_SMEM_PGOFF(loff);
  1596. if (loff == 0) {
  1597. pgnum++;
  1598. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1599. }
  1600. }
  1601. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1602. ioc->ioc_regs.host_page_num_fn);
  1603. /*
  1604. * Set boot type, env and device mode at the end.
  1605. */
  1606. if (boot_env == BFI_FWBOOT_ENV_OS &&
  1607. boot_type == BFI_FWBOOT_TYPE_FLASH) {
  1608. boot_type = BFI_FWBOOT_TYPE_NORMAL;
  1609. }
  1610. asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode,
  1611. ioc->port0_mode, ioc->port1_mode);
  1612. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_DEVMODE_OFF,
  1613. swab32(asicmode));
  1614. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_TYPE_OFF,
  1615. swab32(boot_type));
  1616. bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_ENV_OFF,
  1617. swab32(boot_env));
  1618. return BFA_STATUS_OK;
  1619. }
  1620. /*
  1621. * Update BFA configuration from firmware configuration.
  1622. */
  1623. static void
  1624. bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
  1625. {
  1626. struct bfi_ioc_attr_s *attr = ioc->attr;
  1627. attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
  1628. attr->card_type = be32_to_cpu(attr->card_type);
  1629. attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
  1630. ioc->fcmode = (attr->port_mode == BFI_PORT_MODE_FC);
  1631. attr->mfg_year = be16_to_cpu(attr->mfg_year);
  1632. bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
  1633. }
  1634. /*
  1635. * Attach time initialization of mbox logic.
  1636. */
  1637. static void
  1638. bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
  1639. {
  1640. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1641. int mc;
  1642. INIT_LIST_HEAD(&mod->cmd_q);
  1643. for (mc = 0; mc < BFI_MC_MAX; mc++) {
  1644. mod->mbhdlr[mc].cbfn = NULL;
  1645. mod->mbhdlr[mc].cbarg = ioc->bfa;
  1646. }
  1647. }
  1648. /*
  1649. * Mbox poll timer -- restarts any pending mailbox requests.
  1650. */
  1651. static void
  1652. bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
  1653. {
  1654. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1655. struct bfa_mbox_cmd_s *cmd;
  1656. u32 stat;
  1657. /*
  1658. * If no command pending, do nothing
  1659. */
  1660. if (list_empty(&mod->cmd_q))
  1661. return;
  1662. /*
  1663. * If previous command is not yet fetched by firmware, do nothing
  1664. */
  1665. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  1666. if (stat)
  1667. return;
  1668. /*
  1669. * Enqueue command to firmware.
  1670. */
  1671. bfa_q_deq(&mod->cmd_q, &cmd);
  1672. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  1673. }
  1674. /*
  1675. * Cleanup any pending requests.
  1676. */
  1677. static void
  1678. bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc)
  1679. {
  1680. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  1681. struct bfa_mbox_cmd_s *cmd;
  1682. while (!list_empty(&mod->cmd_q))
  1683. bfa_q_deq(&mod->cmd_q, &cmd);
  1684. }
  1685. /*
  1686. * Read data from SMEM to host through PCI memmap
  1687. *
  1688. * @param[in] ioc memory for IOC
  1689. * @param[in] tbuf app memory to store data from smem
  1690. * @param[in] soff smem offset
  1691. * @param[in] sz size of smem in bytes
  1692. */
  1693. static bfa_status_t
  1694. bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
  1695. {
  1696. u32 pgnum, loff;
  1697. __be32 r32;
  1698. int i, len;
  1699. u32 *buf = tbuf;
  1700. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
  1701. loff = PSS_SMEM_PGOFF(soff);
  1702. bfa_trc(ioc, pgnum);
  1703. bfa_trc(ioc, loff);
  1704. bfa_trc(ioc, sz);
  1705. /*
  1706. * Hold semaphore to serialize pll init and fwtrc.
  1707. */
  1708. if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
  1709. bfa_trc(ioc, 0);
  1710. return BFA_STATUS_FAILED;
  1711. }
  1712. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1713. len = sz/sizeof(u32);
  1714. bfa_trc(ioc, len);
  1715. for (i = 0; i < len; i++) {
  1716. r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  1717. buf[i] = swab32(r32);
  1718. loff += sizeof(u32);
  1719. /*
  1720. * handle page offset wrap around
  1721. */
  1722. loff = PSS_SMEM_PGOFF(loff);
  1723. if (loff == 0) {
  1724. pgnum++;
  1725. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1726. }
  1727. }
  1728. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1729. ioc->ioc_regs.host_page_num_fn);
  1730. /*
  1731. * release semaphore.
  1732. */
  1733. readl(ioc->ioc_regs.ioc_init_sem_reg);
  1734. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1735. bfa_trc(ioc, pgnum);
  1736. return BFA_STATUS_OK;
  1737. }
  1738. /*
  1739. * Clear SMEM data from host through PCI memmap
  1740. *
  1741. * @param[in] ioc memory for IOC
  1742. * @param[in] soff smem offset
  1743. * @param[in] sz size of smem in bytes
  1744. */
  1745. static bfa_status_t
  1746. bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
  1747. {
  1748. int i, len;
  1749. u32 pgnum, loff;
  1750. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
  1751. loff = PSS_SMEM_PGOFF(soff);
  1752. bfa_trc(ioc, pgnum);
  1753. bfa_trc(ioc, loff);
  1754. bfa_trc(ioc, sz);
  1755. /*
  1756. * Hold semaphore to serialize pll init and fwtrc.
  1757. */
  1758. if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
  1759. bfa_trc(ioc, 0);
  1760. return BFA_STATUS_FAILED;
  1761. }
  1762. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1763. len = sz/sizeof(u32); /* len in words */
  1764. bfa_trc(ioc, len);
  1765. for (i = 0; i < len; i++) {
  1766. bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
  1767. loff += sizeof(u32);
  1768. /*
  1769. * handle page offset wrap around
  1770. */
  1771. loff = PSS_SMEM_PGOFF(loff);
  1772. if (loff == 0) {
  1773. pgnum++;
  1774. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  1775. }
  1776. }
  1777. writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
  1778. ioc->ioc_regs.host_page_num_fn);
  1779. /*
  1780. * release semaphore.
  1781. */
  1782. readl(ioc->ioc_regs.ioc_init_sem_reg);
  1783. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1784. bfa_trc(ioc, pgnum);
  1785. return BFA_STATUS_OK;
  1786. }
  1787. static void
  1788. bfa_ioc_fail_notify(struct bfa_ioc_s *ioc)
  1789. {
  1790. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  1791. /*
  1792. * Notify driver and common modules registered for notification.
  1793. */
  1794. ioc->cbfn->hbfail_cbfn(ioc->bfa);
  1795. bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
  1796. bfa_ioc_debug_save_ftrc(ioc);
  1797. BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
  1798. "Heart Beat of IOC has failed\n");
  1799. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_HBFAIL);
  1800. }
  1801. static void
  1802. bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
  1803. {
  1804. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  1805. /*
  1806. * Provide enable completion callback.
  1807. */
  1808. ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
  1809. BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
  1810. "Running firmware version is incompatible "
  1811. "with the driver version\n");
  1812. bfa_ioc_aen_post(ioc, BFA_IOC_AEN_FWMISMATCH);
  1813. }
  1814. bfa_status_t
  1815. bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
  1816. {
  1817. /*
  1818. * Hold semaphore so that nobody can access the chip during init.
  1819. */
  1820. bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
  1821. bfa_ioc_pll_init_asic(ioc);
  1822. ioc->pllinit = BFA_TRUE;
  1823. /*
  1824. * Initialize LMEM
  1825. */
  1826. bfa_ioc_lmem_init(ioc);
  1827. /*
  1828. * release semaphore.
  1829. */
  1830. readl(ioc->ioc_regs.ioc_init_sem_reg);
  1831. writel(1, ioc->ioc_regs.ioc_init_sem_reg);
  1832. return BFA_STATUS_OK;
  1833. }
  1834. /*
  1835. * Interface used by diag module to do firmware boot with memory test
  1836. * as the entry vector.
  1837. */
  1838. bfa_status_t
  1839. bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
  1840. {
  1841. struct bfi_ioc_image_hdr_s *drv_fwhdr;
  1842. bfa_status_t status;
  1843. bfa_ioc_stats(ioc, ioc_boots);
  1844. if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
  1845. return BFA_STATUS_FAILED;
  1846. if (boot_env == BFI_FWBOOT_ENV_OS &&
  1847. boot_type == BFI_FWBOOT_TYPE_NORMAL) {
  1848. drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
  1849. bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
  1850. /*
  1851. * Work with Flash iff flash f/w is better than driver f/w.
  1852. * Otherwise push drivers firmware.
  1853. */
  1854. if (bfa_ioc_flash_fwver_cmp(ioc, drv_fwhdr) ==
  1855. BFI_IOC_IMG_VER_BETTER)
  1856. boot_type = BFI_FWBOOT_TYPE_FLASH;
  1857. }
  1858. /*
  1859. * Initialize IOC state of all functions on a chip reset.
  1860. */
  1861. if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) {
  1862. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_MEMTEST);
  1863. bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_MEMTEST);
  1864. } else {
  1865. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_INITING);
  1866. bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_INITING);
  1867. }
  1868. bfa_ioc_msgflush(ioc);
  1869. status = bfa_ioc_download_fw(ioc, boot_type, boot_env);
  1870. if (status == BFA_STATUS_OK)
  1871. bfa_ioc_lpu_start(ioc);
  1872. else {
  1873. WARN_ON(boot_type == BFI_FWBOOT_TYPE_MEMTEST);
  1874. bfa_iocpf_timeout(ioc);
  1875. }
  1876. return status;
  1877. }
  1878. /*
  1879. * Enable/disable IOC failure auto recovery.
  1880. */
  1881. void
  1882. bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
  1883. {
  1884. bfa_auto_recover = auto_recover;
  1885. }
  1886. bfa_boolean_t
  1887. bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
  1888. {
  1889. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
  1890. }
  1891. bfa_boolean_t
  1892. bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
  1893. {
  1894. u32 r32 = bfa_ioc_get_cur_ioc_fwstate(ioc);
  1895. return ((r32 != BFI_IOC_UNINIT) &&
  1896. (r32 != BFI_IOC_INITING) &&
  1897. (r32 != BFI_IOC_MEMTEST));
  1898. }
  1899. bfa_boolean_t
  1900. bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
  1901. {
  1902. __be32 *msgp = mbmsg;
  1903. u32 r32;
  1904. int i;
  1905. r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
  1906. if ((r32 & 1) == 0)
  1907. return BFA_FALSE;
  1908. /*
  1909. * read the MBOX msg
  1910. */
  1911. for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
  1912. i++) {
  1913. r32 = readl(ioc->ioc_regs.lpu_mbox +
  1914. i * sizeof(u32));
  1915. msgp[i] = cpu_to_be32(r32);
  1916. }
  1917. /*
  1918. * turn off mailbox interrupt by clearing mailbox status
  1919. */
  1920. writel(1, ioc->ioc_regs.lpu_mbox_cmd);
  1921. readl(ioc->ioc_regs.lpu_mbox_cmd);
  1922. return BFA_TRUE;
  1923. }
  1924. void
  1925. bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
  1926. {
  1927. union bfi_ioc_i2h_msg_u *msg;
  1928. struct bfa_iocpf_s *iocpf = &ioc->iocpf;
  1929. msg = (union bfi_ioc_i2h_msg_u *) m;
  1930. bfa_ioc_stats(ioc, ioc_isrs);
  1931. switch (msg->mh.msg_id) {
  1932. case BFI_IOC_I2H_HBEAT:
  1933. break;
  1934. case BFI_IOC_I2H_ENABLE_REPLY:
  1935. ioc->port_mode = ioc->port_mode_cfg =
  1936. (enum bfa_mode_s)msg->fw_event.port_mode;
  1937. ioc->ad_cap_bm = msg->fw_event.cap_bm;
  1938. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
  1939. break;
  1940. case BFI_IOC_I2H_DISABLE_REPLY:
  1941. bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
  1942. break;
  1943. case BFI_IOC_I2H_GETATTR_REPLY:
  1944. bfa_ioc_getattr_reply(ioc);
  1945. break;
  1946. default:
  1947. bfa_trc(ioc, msg->mh.msg_id);
  1948. WARN_ON(1);
  1949. }
  1950. }
  1951. /*
  1952. * IOC attach time initialization and setup.
  1953. *
  1954. * @param[in] ioc memory for IOC
  1955. * @param[in] bfa driver instance structure
  1956. */
  1957. void
  1958. bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
  1959. struct bfa_timer_mod_s *timer_mod)
  1960. {
  1961. ioc->bfa = bfa;
  1962. ioc->cbfn = cbfn;
  1963. ioc->timer_mod = timer_mod;
  1964. ioc->fcmode = BFA_FALSE;
  1965. ioc->pllinit = BFA_FALSE;
  1966. ioc->dbg_fwsave_once = BFA_TRUE;
  1967. ioc->iocpf.ioc = ioc;
  1968. bfa_ioc_mbox_attach(ioc);
  1969. INIT_LIST_HEAD(&ioc->notify_q);
  1970. bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
  1971. bfa_fsm_send_event(ioc, IOC_E_RESET);
  1972. }
  1973. /*
  1974. * Driver detach time IOC cleanup.
  1975. */
  1976. void
  1977. bfa_ioc_detach(struct bfa_ioc_s *ioc)
  1978. {
  1979. bfa_fsm_send_event(ioc, IOC_E_DETACH);
  1980. INIT_LIST_HEAD(&ioc->notify_q);
  1981. }
  1982. /*
  1983. * Setup IOC PCI properties.
  1984. *
  1985. * @param[in] pcidev PCI device information for this IOC
  1986. */
  1987. void
  1988. bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
  1989. enum bfi_pcifn_class clscode)
  1990. {
  1991. ioc->clscode = clscode;
  1992. ioc->pcidev = *pcidev;
  1993. /*
  1994. * Initialize IOC and device personality
  1995. */
  1996. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC;
  1997. ioc->asic_mode = BFI_ASIC_MODE_FC;
  1998. switch (pcidev->device_id) {
  1999. case BFA_PCI_DEVICE_ID_FC_8G1P:
  2000. case BFA_PCI_DEVICE_ID_FC_8G2P:
  2001. ioc->asic_gen = BFI_ASIC_GEN_CB;
  2002. ioc->fcmode = BFA_TRUE;
  2003. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
  2004. ioc->ad_cap_bm = BFA_CM_HBA;
  2005. break;
  2006. case BFA_PCI_DEVICE_ID_CT:
  2007. ioc->asic_gen = BFI_ASIC_GEN_CT;
  2008. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
  2009. ioc->asic_mode = BFI_ASIC_MODE_ETH;
  2010. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA;
  2011. ioc->ad_cap_bm = BFA_CM_CNA;
  2012. break;
  2013. case BFA_PCI_DEVICE_ID_CT_FC:
  2014. ioc->asic_gen = BFI_ASIC_GEN_CT;
  2015. ioc->fcmode = BFA_TRUE;
  2016. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
  2017. ioc->ad_cap_bm = BFA_CM_HBA;
  2018. break;
  2019. case BFA_PCI_DEVICE_ID_CT2:
  2020. case BFA_PCI_DEVICE_ID_CT2_QUAD:
  2021. ioc->asic_gen = BFI_ASIC_GEN_CT2;
  2022. if (clscode == BFI_PCIFN_CLASS_FC &&
  2023. pcidev->ssid == BFA_PCI_CT2_SSID_FC) {
  2024. ioc->asic_mode = BFI_ASIC_MODE_FC16;
  2025. ioc->fcmode = BFA_TRUE;
  2026. ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
  2027. ioc->ad_cap_bm = BFA_CM_HBA;
  2028. } else {
  2029. ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
  2030. ioc->asic_mode = BFI_ASIC_MODE_ETH;
  2031. if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) {
  2032. ioc->port_mode =
  2033. ioc->port_mode_cfg = BFA_MODE_CNA;
  2034. ioc->ad_cap_bm = BFA_CM_CNA;
  2035. } else {
  2036. ioc->port_mode =
  2037. ioc->port_mode_cfg = BFA_MODE_NIC;
  2038. ioc->ad_cap_bm = BFA_CM_NIC;
  2039. }
  2040. }
  2041. break;
  2042. default:
  2043. WARN_ON(1);
  2044. }
  2045. /*
  2046. * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
  2047. */
  2048. if (ioc->asic_gen == BFI_ASIC_GEN_CB)
  2049. bfa_ioc_set_cb_hwif(ioc);
  2050. else if (ioc->asic_gen == BFI_ASIC_GEN_CT)
  2051. bfa_ioc_set_ct_hwif(ioc);
  2052. else {
  2053. WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2);
  2054. bfa_ioc_set_ct2_hwif(ioc);
  2055. bfa_ioc_ct2_poweron(ioc);
  2056. }
  2057. bfa_ioc_map_port(ioc);
  2058. bfa_ioc_reg_init(ioc);
  2059. }
  2060. /*
  2061. * Initialize IOC dma memory
  2062. *
  2063. * @param[in] dm_kva kernel virtual address of IOC dma memory
  2064. * @param[in] dm_pa physical address of IOC dma memory
  2065. */
  2066. void
  2067. bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
  2068. {
  2069. /*
  2070. * dma memory for firmware attribute
  2071. */
  2072. ioc->attr_dma.kva = dm_kva;
  2073. ioc->attr_dma.pa = dm_pa;
  2074. ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
  2075. }
  2076. void
  2077. bfa_ioc_enable(struct bfa_ioc_s *ioc)
  2078. {
  2079. bfa_ioc_stats(ioc, ioc_enables);
  2080. ioc->dbg_fwsave_once = BFA_TRUE;
  2081. bfa_fsm_send_event(ioc, IOC_E_ENABLE);
  2082. }
  2083. void
  2084. bfa_ioc_disable(struct bfa_ioc_s *ioc)
  2085. {
  2086. bfa_ioc_stats(ioc, ioc_disables);
  2087. bfa_fsm_send_event(ioc, IOC_E_DISABLE);
  2088. }
  2089. void
  2090. bfa_ioc_suspend(struct bfa_ioc_s *ioc)
  2091. {
  2092. ioc->dbg_fwsave_once = BFA_TRUE;
  2093. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  2094. }
  2095. /*
  2096. * Initialize memory for saving firmware trace. Driver must initialize
  2097. * trace memory before call bfa_ioc_enable().
  2098. */
  2099. void
  2100. bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
  2101. {
  2102. ioc->dbg_fwsave = dbg_fwsave;
  2103. ioc->dbg_fwsave_len = BFA_DBG_FWTRC_LEN;
  2104. }
  2105. /*
  2106. * Register mailbox message handler functions
  2107. *
  2108. * @param[in] ioc IOC instance
  2109. * @param[in] mcfuncs message class handler functions
  2110. */
  2111. void
  2112. bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
  2113. {
  2114. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  2115. int mc;
  2116. for (mc = 0; mc < BFI_MC_MAX; mc++)
  2117. mod->mbhdlr[mc].cbfn = mcfuncs[mc];
  2118. }
  2119. /*
  2120. * Register mailbox message handler function, to be called by common modules
  2121. */
  2122. void
  2123. bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
  2124. bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
  2125. {
  2126. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  2127. mod->mbhdlr[mc].cbfn = cbfn;
  2128. mod->mbhdlr[mc].cbarg = cbarg;
  2129. }
  2130. /*
  2131. * Queue a mailbox command request to firmware. Waits if mailbox is busy.
  2132. * Responsibility of caller to serialize
  2133. *
  2134. * @param[in] ioc IOC instance
  2135. * @param[i] cmd Mailbox command
  2136. */
  2137. void
  2138. bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
  2139. {
  2140. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  2141. u32 stat;
  2142. /*
  2143. * If a previous command is pending, queue new command
  2144. */
  2145. if (!list_empty(&mod->cmd_q)) {
  2146. list_add_tail(&cmd->qe, &mod->cmd_q);
  2147. return;
  2148. }
  2149. /*
  2150. * If mailbox is busy, queue command for poll timer
  2151. */
  2152. stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
  2153. if (stat) {
  2154. list_add_tail(&cmd->qe, &mod->cmd_q);
  2155. return;
  2156. }
  2157. /*
  2158. * mailbox is free -- queue command to firmware
  2159. */
  2160. bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
  2161. }
  2162. /*
  2163. * Handle mailbox interrupts
  2164. */
  2165. void
  2166. bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
  2167. {
  2168. struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
  2169. struct bfi_mbmsg_s m;
  2170. int mc;
  2171. if (bfa_ioc_msgget(ioc, &m)) {
  2172. /*
  2173. * Treat IOC message class as special.
  2174. */
  2175. mc = m.mh.msg_class;
  2176. if (mc == BFI_MC_IOC) {
  2177. bfa_ioc_isr(ioc, &m);
  2178. return;
  2179. }
  2180. if ((mc >= BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
  2181. return;
  2182. mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
  2183. }
  2184. bfa_ioc_lpu_read_stat(ioc);
  2185. /*
  2186. * Try to send pending mailbox commands
  2187. */
  2188. bfa_ioc_mbox_poll(ioc);
  2189. }
  2190. void
  2191. bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
  2192. {
  2193. bfa_ioc_stats(ioc, ioc_hbfails);
  2194. ioc->stats.hb_count = ioc->hb_count;
  2195. bfa_fsm_send_event(ioc, IOC_E_HWERROR);
  2196. }
  2197. /*
  2198. * return true if IOC is disabled
  2199. */
  2200. bfa_boolean_t
  2201. bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
  2202. {
  2203. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
  2204. bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
  2205. }
  2206. /*
  2207. * return true if IOC firmware is different.
  2208. */
  2209. bfa_boolean_t
  2210. bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
  2211. {
  2212. return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
  2213. bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
  2214. bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
  2215. }
  2216. /*
  2217. * Check if adapter is disabled -- both IOCs should be in a disabled
  2218. * state.
  2219. */
  2220. bfa_boolean_t
  2221. bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
  2222. {
  2223. u32 ioc_state;
  2224. if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
  2225. return BFA_FALSE;
  2226. ioc_state = bfa_ioc_get_cur_ioc_fwstate(ioc);
  2227. if (!bfa_ioc_state_disabled(ioc_state))
  2228. return BFA_FALSE;
  2229. if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
  2230. ioc_state = bfa_ioc_get_cur_ioc_fwstate(ioc);
  2231. if (!bfa_ioc_state_disabled(ioc_state))
  2232. return BFA_FALSE;
  2233. }
  2234. return BFA_TRUE;
  2235. }
  2236. /*
  2237. * Reset IOC fwstate registers.
  2238. */
  2239. void
  2240. bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
  2241. {
  2242. bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_UNINIT);
  2243. bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_UNINIT);
  2244. }
  2245. #define BFA_MFG_NAME "QLogic"
  2246. void
  2247. bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
  2248. struct bfa_adapter_attr_s *ad_attr)
  2249. {
  2250. struct bfi_ioc_attr_s *ioc_attr;
  2251. ioc_attr = ioc->attr;
  2252. bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
  2253. bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
  2254. bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
  2255. bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
  2256. memcpy(&ad_attr->vpd, &ioc_attr->vpd,
  2257. sizeof(struct bfa_mfg_vpd_s));
  2258. ad_attr->nports = bfa_ioc_get_nports(ioc);
  2259. ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
  2260. bfa_ioc_get_adapter_model(ioc, ad_attr->model);
  2261. /* For now, model descr uses same model string */
  2262. bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
  2263. ad_attr->card_type = ioc_attr->card_type;
  2264. ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
  2265. if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
  2266. ad_attr->prototype = 1;
  2267. else
  2268. ad_attr->prototype = 0;
  2269. ad_attr->pwwn = ioc->attr->pwwn;
  2270. ad_attr->mac = bfa_ioc_get_mac(ioc);
  2271. ad_attr->pcie_gen = ioc_attr->pcie_gen;
  2272. ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
  2273. ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
  2274. ad_attr->asic_rev = ioc_attr->asic_rev;
  2275. bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
  2276. ad_attr->cna_capable = bfa_ioc_is_cna(ioc);
  2277. ad_attr->trunk_capable = (ad_attr->nports > 1) &&
  2278. !bfa_ioc_is_cna(ioc) && !ad_attr->is_mezz;
  2279. ad_attr->mfg_day = ioc_attr->mfg_day;
  2280. ad_attr->mfg_month = ioc_attr->mfg_month;
  2281. ad_attr->mfg_year = ioc_attr->mfg_year;
  2282. memcpy(ad_attr->uuid, ioc_attr->uuid, BFA_ADAPTER_UUID_LEN);
  2283. }
  2284. enum bfa_ioc_type_e
  2285. bfa_ioc_get_type(struct bfa_ioc_s *ioc)
  2286. {
  2287. if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
  2288. return BFA_IOC_TYPE_LL;
  2289. WARN_ON(ioc->clscode != BFI_PCIFN_CLASS_FC);
  2290. return (ioc->attr->port_mode == BFI_PORT_MODE_FC)
  2291. ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
  2292. }
  2293. void
  2294. bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
  2295. {
  2296. memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
  2297. memcpy((void *)serial_num,
  2298. (void *)ioc->attr->brcd_serialnum,
  2299. BFA_ADAPTER_SERIAL_NUM_LEN);
  2300. }
  2301. void
  2302. bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
  2303. {
  2304. memset((void *)fw_ver, 0, BFA_VERSION_LEN);
  2305. memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
  2306. }
  2307. void
  2308. bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
  2309. {
  2310. WARN_ON(!chip_rev);
  2311. memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
  2312. chip_rev[0] = 'R';
  2313. chip_rev[1] = 'e';
  2314. chip_rev[2] = 'v';
  2315. chip_rev[3] = '-';
  2316. chip_rev[4] = ioc->attr->asic_rev;
  2317. chip_rev[5] = '\0';
  2318. }
  2319. void
  2320. bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
  2321. {
  2322. memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
  2323. memcpy(optrom_ver, ioc->attr->optrom_version,
  2324. BFA_VERSION_LEN);
  2325. }
  2326. void
  2327. bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
  2328. {
  2329. memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
  2330. strscpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
  2331. }
  2332. void
  2333. bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
  2334. {
  2335. struct bfi_ioc_attr_s *ioc_attr;
  2336. u8 nports = bfa_ioc_get_nports(ioc);
  2337. WARN_ON(!model);
  2338. memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
  2339. ioc_attr = ioc->attr;
  2340. if (bfa_asic_id_ct2(ioc->pcidev.device_id) &&
  2341. (!bfa_mfg_is_mezz(ioc_attr->card_type)))
  2342. snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u-%u%s",
  2343. BFA_MFG_NAME, ioc_attr->card_type, nports, "p");
  2344. else
  2345. snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
  2346. BFA_MFG_NAME, ioc_attr->card_type);
  2347. }
  2348. enum bfa_ioc_state
  2349. bfa_ioc_get_state(struct bfa_ioc_s *ioc)
  2350. {
  2351. enum bfa_iocpf_state iocpf_st;
  2352. enum bfa_ioc_state ioc_st = bfa_ioc_sm_to_state(ioc_sm_table, ioc->fsm);
  2353. if (ioc_st == BFA_IOC_ENABLING ||
  2354. ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
  2355. iocpf_st = bfa_iocpf_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
  2356. switch (iocpf_st) {
  2357. case BFA_IOCPF_SEMWAIT:
  2358. ioc_st = BFA_IOC_SEMWAIT;
  2359. break;
  2360. case BFA_IOCPF_HWINIT:
  2361. ioc_st = BFA_IOC_HWINIT;
  2362. break;
  2363. case BFA_IOCPF_FWMISMATCH:
  2364. ioc_st = BFA_IOC_FWMISMATCH;
  2365. break;
  2366. case BFA_IOCPF_FAIL:
  2367. ioc_st = BFA_IOC_FAIL;
  2368. break;
  2369. case BFA_IOCPF_INITFAIL:
  2370. ioc_st = BFA_IOC_INITFAIL;
  2371. break;
  2372. default:
  2373. break;
  2374. }
  2375. }
  2376. return ioc_st;
  2377. }
  2378. void
  2379. bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
  2380. {
  2381. memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
  2382. ioc_attr->state = bfa_ioc_get_state(ioc);
  2383. ioc_attr->port_id = bfa_ioc_portid(ioc);
  2384. ioc_attr->port_mode = ioc->port_mode;
  2385. ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
  2386. ioc_attr->cap_bm = ioc->ad_cap_bm;
  2387. ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
  2388. bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
  2389. ioc_attr->pci_attr.device_id = bfa_ioc_devid(ioc);
  2390. ioc_attr->pci_attr.pcifn = bfa_ioc_pcifn(ioc);
  2391. ioc_attr->def_fn = (bfa_ioc_pcifn(ioc) == bfa_ioc_portid(ioc));
  2392. bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
  2393. }
  2394. mac_t
  2395. bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
  2396. {
  2397. /*
  2398. * Check the IOC type and return the appropriate MAC
  2399. */
  2400. if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
  2401. return ioc->attr->fcoe_mac;
  2402. else
  2403. return ioc->attr->mac;
  2404. }
  2405. mac_t
  2406. bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
  2407. {
  2408. mac_t m;
  2409. m = ioc->attr->mfg_mac;
  2410. if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
  2411. m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
  2412. else
  2413. bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
  2414. bfa_ioc_pcifn(ioc));
  2415. return m;
  2416. }
  2417. /*
  2418. * Send AEN notification
  2419. */
  2420. void
  2421. bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event)
  2422. {
  2423. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  2424. struct bfa_aen_entry_s *aen_entry;
  2425. enum bfa_ioc_type_e ioc_type;
  2426. bfad_get_aen_entry(bfad, aen_entry);
  2427. if (!aen_entry)
  2428. return;
  2429. ioc_type = bfa_ioc_get_type(ioc);
  2430. switch (ioc_type) {
  2431. case BFA_IOC_TYPE_FC:
  2432. aen_entry->aen_data.ioc.pwwn = ioc->attr->pwwn;
  2433. break;
  2434. case BFA_IOC_TYPE_FCoE:
  2435. aen_entry->aen_data.ioc.pwwn = ioc->attr->pwwn;
  2436. aen_entry->aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
  2437. break;
  2438. case BFA_IOC_TYPE_LL:
  2439. aen_entry->aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
  2440. break;
  2441. default:
  2442. WARN_ON(ioc_type != BFA_IOC_TYPE_FC);
  2443. break;
  2444. }
  2445. /* Send the AEN notification */
  2446. aen_entry->aen_data.ioc.ioc_type = ioc_type;
  2447. bfad_im_post_vendor_event(aen_entry, bfad, ++ioc->ioc_aen_seq,
  2448. BFA_AEN_CAT_IOC, event);
  2449. }
  2450. /*
  2451. * Retrieve saved firmware trace from a prior IOC failure.
  2452. */
  2453. bfa_status_t
  2454. bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  2455. {
  2456. int tlen;
  2457. if (ioc->dbg_fwsave_len == 0)
  2458. return BFA_STATUS_ENOFSAVE;
  2459. tlen = *trclen;
  2460. if (tlen > ioc->dbg_fwsave_len)
  2461. tlen = ioc->dbg_fwsave_len;
  2462. memcpy(trcdata, ioc->dbg_fwsave, tlen);
  2463. *trclen = tlen;
  2464. return BFA_STATUS_OK;
  2465. }
  2466. /*
  2467. * Retrieve saved firmware trace from a prior IOC failure.
  2468. */
  2469. bfa_status_t
  2470. bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
  2471. {
  2472. u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
  2473. int tlen;
  2474. bfa_status_t status;
  2475. bfa_trc(ioc, *trclen);
  2476. tlen = *trclen;
  2477. if (tlen > BFA_DBG_FWTRC_LEN)
  2478. tlen = BFA_DBG_FWTRC_LEN;
  2479. status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
  2480. *trclen = tlen;
  2481. return status;
  2482. }
  2483. static void
  2484. bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
  2485. {
  2486. struct bfa_mbox_cmd_s cmd;
  2487. struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
  2488. bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
  2489. bfa_ioc_portid(ioc));
  2490. req->clscode = cpu_to_be16(ioc->clscode);
  2491. bfa_ioc_mbox_queue(ioc, &cmd);
  2492. }
  2493. static void
  2494. bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
  2495. {
  2496. u32 fwsync_iter = 1000;
  2497. bfa_ioc_send_fwsync(ioc);
  2498. /*
  2499. * After sending a fw sync mbox command wait for it to
  2500. * take effect. We will not wait for a response because
  2501. * 1. fw_sync mbox cmd doesn't have a response.
  2502. * 2. Even if we implement that, interrupts might not
  2503. * be enabled when we call this function.
  2504. * So, just keep checking if any mbox cmd is pending, and
  2505. * after waiting for a reasonable amount of time, go ahead.
  2506. * It is possible that fw has crashed and the mbox command
  2507. * is never acknowledged.
  2508. */
  2509. while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
  2510. fwsync_iter--;
  2511. }
  2512. /*
  2513. * Dump firmware smem
  2514. */
  2515. bfa_status_t
  2516. bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
  2517. u32 *offset, int *buflen)
  2518. {
  2519. u32 loff;
  2520. int dlen;
  2521. bfa_status_t status;
  2522. u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
  2523. if (*offset >= smem_len) {
  2524. *offset = *buflen = 0;
  2525. return BFA_STATUS_EINVAL;
  2526. }
  2527. loff = *offset;
  2528. dlen = *buflen;
  2529. /*
  2530. * First smem read, sync smem before proceeding
  2531. * No need to sync before reading every chunk.
  2532. */
  2533. if (loff == 0)
  2534. bfa_ioc_fwsync(ioc);
  2535. if ((loff + dlen) >= smem_len)
  2536. dlen = smem_len - loff;
  2537. status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
  2538. if (status != BFA_STATUS_OK) {
  2539. *offset = *buflen = 0;
  2540. return status;
  2541. }
  2542. *offset += dlen;
  2543. if (*offset >= smem_len)
  2544. *offset = 0;
  2545. *buflen = dlen;
  2546. return status;
  2547. }
  2548. /*
  2549. * Firmware statistics
  2550. */
  2551. bfa_status_t
  2552. bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
  2553. {
  2554. u32 loff = BFI_IOC_FWSTATS_OFF + \
  2555. BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
  2556. int tlen;
  2557. bfa_status_t status;
  2558. if (ioc->stats_busy) {
  2559. bfa_trc(ioc, ioc->stats_busy);
  2560. return BFA_STATUS_DEVBUSY;
  2561. }
  2562. ioc->stats_busy = BFA_TRUE;
  2563. tlen = sizeof(struct bfa_fw_stats_s);
  2564. status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
  2565. ioc->stats_busy = BFA_FALSE;
  2566. return status;
  2567. }
  2568. bfa_status_t
  2569. bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
  2570. {
  2571. u32 loff = BFI_IOC_FWSTATS_OFF + \
  2572. BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
  2573. int tlen;
  2574. bfa_status_t status;
  2575. if (ioc->stats_busy) {
  2576. bfa_trc(ioc, ioc->stats_busy);
  2577. return BFA_STATUS_DEVBUSY;
  2578. }
  2579. ioc->stats_busy = BFA_TRUE;
  2580. tlen = sizeof(struct bfa_fw_stats_s);
  2581. status = bfa_ioc_smem_clr(ioc, loff, tlen);
  2582. ioc->stats_busy = BFA_FALSE;
  2583. return status;
  2584. }
  2585. /*
  2586. * Save firmware trace if configured.
  2587. */
  2588. void
  2589. bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
  2590. {
  2591. int tlen;
  2592. if (ioc->dbg_fwsave_once) {
  2593. ioc->dbg_fwsave_once = BFA_FALSE;
  2594. if (ioc->dbg_fwsave_len) {
  2595. tlen = ioc->dbg_fwsave_len;
  2596. bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
  2597. }
  2598. }
  2599. }
  2600. /*
  2601. * Firmware failure detected. Start recovery actions.
  2602. */
  2603. static void
  2604. bfa_ioc_recover(struct bfa_ioc_s *ioc)
  2605. {
  2606. bfa_ioc_stats(ioc, ioc_hbfails);
  2607. ioc->stats.hb_count = ioc->hb_count;
  2608. bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
  2609. }
  2610. /*
  2611. * BFA IOC PF private functions
  2612. */
  2613. static void
  2614. bfa_iocpf_timeout(void *ioc_arg)
  2615. {
  2616. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2617. bfa_trc(ioc, 0);
  2618. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
  2619. }
  2620. static void
  2621. bfa_iocpf_sem_timeout(void *ioc_arg)
  2622. {
  2623. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2624. bfa_ioc_hw_sem_get(ioc);
  2625. }
  2626. static void
  2627. bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc)
  2628. {
  2629. u32 fwstate = bfa_ioc_get_cur_ioc_fwstate(ioc);
  2630. bfa_trc(ioc, fwstate);
  2631. if (fwstate == BFI_IOC_DISABLED) {
  2632. bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
  2633. return;
  2634. }
  2635. if (ioc->iocpf.poll_time >= (3 * BFA_IOC_TOV))
  2636. bfa_iocpf_timeout(ioc);
  2637. else {
  2638. ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
  2639. bfa_iocpf_poll_timer_start(ioc);
  2640. }
  2641. }
  2642. static void
  2643. bfa_iocpf_poll_timeout(void *ioc_arg)
  2644. {
  2645. struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
  2646. bfa_ioc_poll_fwinit(ioc);
  2647. }
  2648. /*
  2649. * bfa timer function
  2650. */
  2651. void
  2652. bfa_timer_beat(struct bfa_timer_mod_s *mod)
  2653. {
  2654. struct list_head *qh = &mod->timer_q;
  2655. struct list_head *qe, *qe_next;
  2656. struct bfa_timer_s *elem;
  2657. struct list_head timedout_q;
  2658. INIT_LIST_HEAD(&timedout_q);
  2659. qe = bfa_q_next(qh);
  2660. while (qe != qh) {
  2661. qe_next = bfa_q_next(qe);
  2662. elem = (struct bfa_timer_s *) qe;
  2663. if (elem->timeout <= BFA_TIMER_FREQ) {
  2664. elem->timeout = 0;
  2665. list_del(&elem->qe);
  2666. list_add_tail(&elem->qe, &timedout_q);
  2667. } else {
  2668. elem->timeout -= BFA_TIMER_FREQ;
  2669. }
  2670. qe = qe_next; /* go to next elem */
  2671. }
  2672. /*
  2673. * Pop all the timeout entries
  2674. */
  2675. while (!list_empty(&timedout_q)) {
  2676. bfa_q_deq(&timedout_q, &elem);
  2677. elem->timercb(elem->arg);
  2678. }
  2679. }
  2680. /*
  2681. * Should be called with lock protection
  2682. */
  2683. void
  2684. bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
  2685. void (*timercb) (void *), void *arg, unsigned int timeout)
  2686. {
  2687. WARN_ON(timercb == NULL);
  2688. WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
  2689. timer->timeout = timeout;
  2690. timer->timercb = timercb;
  2691. timer->arg = arg;
  2692. list_add_tail(&timer->qe, &mod->timer_q);
  2693. }
  2694. /*
  2695. * Should be called with lock protection
  2696. */
  2697. void
  2698. bfa_timer_stop(struct bfa_timer_s *timer)
  2699. {
  2700. WARN_ON(list_empty(&timer->qe));
  2701. list_del(&timer->qe);
  2702. }
  2703. /*
  2704. * ASIC block related
  2705. */
  2706. static void
  2707. bfa_ablk_config_swap(struct bfa_ablk_cfg_s *cfg)
  2708. {
  2709. struct bfa_ablk_cfg_inst_s *cfg_inst;
  2710. int i, j;
  2711. u16 be16;
  2712. for (i = 0; i < BFA_ABLK_MAX; i++) {
  2713. cfg_inst = &cfg->inst[i];
  2714. for (j = 0; j < BFA_ABLK_MAX_PFS; j++) {
  2715. be16 = cfg_inst->pf_cfg[j].pers;
  2716. cfg_inst->pf_cfg[j].pers = be16_to_cpu(be16);
  2717. be16 = cfg_inst->pf_cfg[j].num_qpairs;
  2718. cfg_inst->pf_cfg[j].num_qpairs = be16_to_cpu(be16);
  2719. be16 = cfg_inst->pf_cfg[j].num_vectors;
  2720. cfg_inst->pf_cfg[j].num_vectors = be16_to_cpu(be16);
  2721. be16 = cfg_inst->pf_cfg[j].bw_min;
  2722. cfg_inst->pf_cfg[j].bw_min = be16_to_cpu(be16);
  2723. be16 = cfg_inst->pf_cfg[j].bw_max;
  2724. cfg_inst->pf_cfg[j].bw_max = be16_to_cpu(be16);
  2725. }
  2726. }
  2727. }
  2728. static void
  2729. bfa_ablk_isr(void *cbarg, struct bfi_mbmsg_s *msg)
  2730. {
  2731. struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
  2732. struct bfi_ablk_i2h_rsp_s *rsp = (struct bfi_ablk_i2h_rsp_s *)msg;
  2733. bfa_ablk_cbfn_t cbfn;
  2734. WARN_ON(msg->mh.msg_class != BFI_MC_ABLK);
  2735. bfa_trc(ablk->ioc, msg->mh.msg_id);
  2736. switch (msg->mh.msg_id) {
  2737. case BFI_ABLK_I2H_QUERY:
  2738. if (rsp->status == BFA_STATUS_OK) {
  2739. memcpy(ablk->cfg, ablk->dma_addr.kva,
  2740. sizeof(struct bfa_ablk_cfg_s));
  2741. bfa_ablk_config_swap(ablk->cfg);
  2742. ablk->cfg = NULL;
  2743. }
  2744. break;
  2745. case BFI_ABLK_I2H_ADPT_CONFIG:
  2746. case BFI_ABLK_I2H_PORT_CONFIG:
  2747. /* update config port mode */
  2748. ablk->ioc->port_mode_cfg = rsp->port_mode;
  2749. break;
  2750. case BFI_ABLK_I2H_PF_DELETE:
  2751. case BFI_ABLK_I2H_PF_UPDATE:
  2752. case BFI_ABLK_I2H_OPTROM_ENABLE:
  2753. case BFI_ABLK_I2H_OPTROM_DISABLE:
  2754. /* No-op */
  2755. break;
  2756. case BFI_ABLK_I2H_PF_CREATE:
  2757. *(ablk->pcifn) = rsp->pcifn;
  2758. ablk->pcifn = NULL;
  2759. break;
  2760. default:
  2761. WARN_ON(1);
  2762. }
  2763. ablk->busy = BFA_FALSE;
  2764. if (ablk->cbfn) {
  2765. cbfn = ablk->cbfn;
  2766. ablk->cbfn = NULL;
  2767. cbfn(ablk->cbarg, rsp->status);
  2768. }
  2769. }
  2770. static void
  2771. bfa_ablk_notify(void *cbarg, enum bfa_ioc_event_e event)
  2772. {
  2773. struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
  2774. bfa_trc(ablk->ioc, event);
  2775. switch (event) {
  2776. case BFA_IOC_E_ENABLED:
  2777. WARN_ON(ablk->busy != BFA_FALSE);
  2778. break;
  2779. case BFA_IOC_E_DISABLED:
  2780. case BFA_IOC_E_FAILED:
  2781. /* Fail any pending requests */
  2782. ablk->pcifn = NULL;
  2783. if (ablk->busy) {
  2784. if (ablk->cbfn)
  2785. ablk->cbfn(ablk->cbarg, BFA_STATUS_FAILED);
  2786. ablk->cbfn = NULL;
  2787. ablk->busy = BFA_FALSE;
  2788. }
  2789. break;
  2790. default:
  2791. WARN_ON(1);
  2792. break;
  2793. }
  2794. }
  2795. u32
  2796. bfa_ablk_meminfo(void)
  2797. {
  2798. return BFA_ROUNDUP(sizeof(struct bfa_ablk_cfg_s), BFA_DMA_ALIGN_SZ);
  2799. }
  2800. void
  2801. bfa_ablk_memclaim(struct bfa_ablk_s *ablk, u8 *dma_kva, u64 dma_pa)
  2802. {
  2803. ablk->dma_addr.kva = dma_kva;
  2804. ablk->dma_addr.pa = dma_pa;
  2805. }
  2806. void
  2807. bfa_ablk_attach(struct bfa_ablk_s *ablk, struct bfa_ioc_s *ioc)
  2808. {
  2809. ablk->ioc = ioc;
  2810. bfa_ioc_mbox_regisr(ablk->ioc, BFI_MC_ABLK, bfa_ablk_isr, ablk);
  2811. bfa_q_qe_init(&ablk->ioc_notify);
  2812. bfa_ioc_notify_init(&ablk->ioc_notify, bfa_ablk_notify, ablk);
  2813. list_add_tail(&ablk->ioc_notify.qe, &ablk->ioc->notify_q);
  2814. }
  2815. bfa_status_t
  2816. bfa_ablk_query(struct bfa_ablk_s *ablk, struct bfa_ablk_cfg_s *ablk_cfg,
  2817. bfa_ablk_cbfn_t cbfn, void *cbarg)
  2818. {
  2819. struct bfi_ablk_h2i_query_s *m;
  2820. WARN_ON(!ablk_cfg);
  2821. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2822. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2823. return BFA_STATUS_IOC_FAILURE;
  2824. }
  2825. if (ablk->busy) {
  2826. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2827. return BFA_STATUS_DEVBUSY;
  2828. }
  2829. ablk->cfg = ablk_cfg;
  2830. ablk->cbfn = cbfn;
  2831. ablk->cbarg = cbarg;
  2832. ablk->busy = BFA_TRUE;
  2833. m = (struct bfi_ablk_h2i_query_s *)ablk->mb.msg;
  2834. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_QUERY,
  2835. bfa_ioc_portid(ablk->ioc));
  2836. bfa_dma_be_addr_set(m->addr, ablk->dma_addr.pa);
  2837. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2838. return BFA_STATUS_OK;
  2839. }
  2840. bfa_status_t
  2841. bfa_ablk_pf_create(struct bfa_ablk_s *ablk, u16 *pcifn,
  2842. u8 port, enum bfi_pcifn_class personality,
  2843. u16 bw_min, u16 bw_max,
  2844. bfa_ablk_cbfn_t cbfn, void *cbarg)
  2845. {
  2846. struct bfi_ablk_h2i_pf_req_s *m;
  2847. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2848. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2849. return BFA_STATUS_IOC_FAILURE;
  2850. }
  2851. if (ablk->busy) {
  2852. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2853. return BFA_STATUS_DEVBUSY;
  2854. }
  2855. ablk->pcifn = pcifn;
  2856. ablk->cbfn = cbfn;
  2857. ablk->cbarg = cbarg;
  2858. ablk->busy = BFA_TRUE;
  2859. m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
  2860. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_CREATE,
  2861. bfa_ioc_portid(ablk->ioc));
  2862. m->pers = cpu_to_be16((u16)personality);
  2863. m->bw_min = cpu_to_be16(bw_min);
  2864. m->bw_max = cpu_to_be16(bw_max);
  2865. m->port = port;
  2866. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2867. return BFA_STATUS_OK;
  2868. }
  2869. bfa_status_t
  2870. bfa_ablk_pf_delete(struct bfa_ablk_s *ablk, int pcifn,
  2871. bfa_ablk_cbfn_t cbfn, void *cbarg)
  2872. {
  2873. struct bfi_ablk_h2i_pf_req_s *m;
  2874. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2875. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2876. return BFA_STATUS_IOC_FAILURE;
  2877. }
  2878. if (ablk->busy) {
  2879. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2880. return BFA_STATUS_DEVBUSY;
  2881. }
  2882. ablk->cbfn = cbfn;
  2883. ablk->cbarg = cbarg;
  2884. ablk->busy = BFA_TRUE;
  2885. m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
  2886. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_DELETE,
  2887. bfa_ioc_portid(ablk->ioc));
  2888. m->pcifn = (u8)pcifn;
  2889. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2890. return BFA_STATUS_OK;
  2891. }
  2892. bfa_status_t
  2893. bfa_ablk_adapter_config(struct bfa_ablk_s *ablk, enum bfa_mode_s mode,
  2894. int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2895. {
  2896. struct bfi_ablk_h2i_cfg_req_s *m;
  2897. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2898. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2899. return BFA_STATUS_IOC_FAILURE;
  2900. }
  2901. if (ablk->busy) {
  2902. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2903. return BFA_STATUS_DEVBUSY;
  2904. }
  2905. ablk->cbfn = cbfn;
  2906. ablk->cbarg = cbarg;
  2907. ablk->busy = BFA_TRUE;
  2908. m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
  2909. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_ADPT_CONFIG,
  2910. bfa_ioc_portid(ablk->ioc));
  2911. m->mode = (u8)mode;
  2912. m->max_pf = (u8)max_pf;
  2913. m->max_vf = (u8)max_vf;
  2914. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2915. return BFA_STATUS_OK;
  2916. }
  2917. bfa_status_t
  2918. bfa_ablk_port_config(struct bfa_ablk_s *ablk, int port, enum bfa_mode_s mode,
  2919. int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2920. {
  2921. struct bfi_ablk_h2i_cfg_req_s *m;
  2922. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2923. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2924. return BFA_STATUS_IOC_FAILURE;
  2925. }
  2926. if (ablk->busy) {
  2927. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2928. return BFA_STATUS_DEVBUSY;
  2929. }
  2930. ablk->cbfn = cbfn;
  2931. ablk->cbarg = cbarg;
  2932. ablk->busy = BFA_TRUE;
  2933. m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
  2934. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PORT_CONFIG,
  2935. bfa_ioc_portid(ablk->ioc));
  2936. m->port = (u8)port;
  2937. m->mode = (u8)mode;
  2938. m->max_pf = (u8)max_pf;
  2939. m->max_vf = (u8)max_vf;
  2940. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2941. return BFA_STATUS_OK;
  2942. }
  2943. bfa_status_t
  2944. bfa_ablk_pf_update(struct bfa_ablk_s *ablk, int pcifn, u16 bw_min,
  2945. u16 bw_max, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2946. {
  2947. struct bfi_ablk_h2i_pf_req_s *m;
  2948. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2949. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2950. return BFA_STATUS_IOC_FAILURE;
  2951. }
  2952. if (ablk->busy) {
  2953. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2954. return BFA_STATUS_DEVBUSY;
  2955. }
  2956. ablk->cbfn = cbfn;
  2957. ablk->cbarg = cbarg;
  2958. ablk->busy = BFA_TRUE;
  2959. m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
  2960. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_UPDATE,
  2961. bfa_ioc_portid(ablk->ioc));
  2962. m->pcifn = (u8)pcifn;
  2963. m->bw_min = cpu_to_be16(bw_min);
  2964. m->bw_max = cpu_to_be16(bw_max);
  2965. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2966. return BFA_STATUS_OK;
  2967. }
  2968. bfa_status_t
  2969. bfa_ablk_optrom_en(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2970. {
  2971. struct bfi_ablk_h2i_optrom_s *m;
  2972. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2973. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2974. return BFA_STATUS_IOC_FAILURE;
  2975. }
  2976. if (ablk->busy) {
  2977. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2978. return BFA_STATUS_DEVBUSY;
  2979. }
  2980. ablk->cbfn = cbfn;
  2981. ablk->cbarg = cbarg;
  2982. ablk->busy = BFA_TRUE;
  2983. m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
  2984. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_ENABLE,
  2985. bfa_ioc_portid(ablk->ioc));
  2986. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  2987. return BFA_STATUS_OK;
  2988. }
  2989. bfa_status_t
  2990. bfa_ablk_optrom_dis(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
  2991. {
  2992. struct bfi_ablk_h2i_optrom_s *m;
  2993. if (!bfa_ioc_is_operational(ablk->ioc)) {
  2994. bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
  2995. return BFA_STATUS_IOC_FAILURE;
  2996. }
  2997. if (ablk->busy) {
  2998. bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
  2999. return BFA_STATUS_DEVBUSY;
  3000. }
  3001. ablk->cbfn = cbfn;
  3002. ablk->cbarg = cbarg;
  3003. ablk->busy = BFA_TRUE;
  3004. m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
  3005. bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_DISABLE,
  3006. bfa_ioc_portid(ablk->ioc));
  3007. bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
  3008. return BFA_STATUS_OK;
  3009. }
  3010. /*
  3011. * SFP module specific
  3012. */
  3013. /* forward declarations */
  3014. static void bfa_sfp_getdata_send(struct bfa_sfp_s *sfp);
  3015. static void bfa_sfp_media_get(struct bfa_sfp_s *sfp);
  3016. static bfa_status_t bfa_sfp_speed_valid(struct bfa_sfp_s *sfp,
  3017. enum bfa_port_speed portspeed);
  3018. static void
  3019. bfa_cb_sfp_show(struct bfa_sfp_s *sfp)
  3020. {
  3021. bfa_trc(sfp, sfp->lock);
  3022. if (sfp->cbfn)
  3023. sfp->cbfn(sfp->cbarg, sfp->status);
  3024. sfp->lock = 0;
  3025. sfp->cbfn = NULL;
  3026. }
  3027. static void
  3028. bfa_cb_sfp_state_query(struct bfa_sfp_s *sfp)
  3029. {
  3030. bfa_trc(sfp, sfp->portspeed);
  3031. if (sfp->media) {
  3032. bfa_sfp_media_get(sfp);
  3033. if (sfp->state_query_cbfn)
  3034. sfp->state_query_cbfn(sfp->state_query_cbarg,
  3035. sfp->status);
  3036. sfp->media = NULL;
  3037. }
  3038. if (sfp->portspeed) {
  3039. sfp->status = bfa_sfp_speed_valid(sfp, sfp->portspeed);
  3040. if (sfp->state_query_cbfn)
  3041. sfp->state_query_cbfn(sfp->state_query_cbarg,
  3042. sfp->status);
  3043. sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
  3044. }
  3045. sfp->state_query_lock = 0;
  3046. sfp->state_query_cbfn = NULL;
  3047. }
  3048. /*
  3049. * IOC event handler.
  3050. */
  3051. static void
  3052. bfa_sfp_notify(void *sfp_arg, enum bfa_ioc_event_e event)
  3053. {
  3054. struct bfa_sfp_s *sfp = sfp_arg;
  3055. bfa_trc(sfp, event);
  3056. bfa_trc(sfp, sfp->lock);
  3057. bfa_trc(sfp, sfp->state_query_lock);
  3058. switch (event) {
  3059. case BFA_IOC_E_DISABLED:
  3060. case BFA_IOC_E_FAILED:
  3061. if (sfp->lock) {
  3062. sfp->status = BFA_STATUS_IOC_FAILURE;
  3063. bfa_cb_sfp_show(sfp);
  3064. }
  3065. if (sfp->state_query_lock) {
  3066. sfp->status = BFA_STATUS_IOC_FAILURE;
  3067. bfa_cb_sfp_state_query(sfp);
  3068. }
  3069. break;
  3070. default:
  3071. break;
  3072. }
  3073. }
  3074. /*
  3075. * SFP's State Change Notification post to AEN
  3076. */
  3077. static void
  3078. bfa_sfp_scn_aen_post(struct bfa_sfp_s *sfp, struct bfi_sfp_scn_s *rsp)
  3079. {
  3080. struct bfad_s *bfad = (struct bfad_s *)sfp->ioc->bfa->bfad;
  3081. struct bfa_aen_entry_s *aen_entry;
  3082. enum bfa_port_aen_event aen_evt = 0;
  3083. bfa_trc(sfp, (((u64)rsp->pomlvl) << 16) | (((u64)rsp->sfpid) << 8) |
  3084. ((u64)rsp->event));
  3085. bfad_get_aen_entry(bfad, aen_entry);
  3086. if (!aen_entry)
  3087. return;
  3088. aen_entry->aen_data.port.ioc_type = bfa_ioc_get_type(sfp->ioc);
  3089. aen_entry->aen_data.port.pwwn = sfp->ioc->attr->pwwn;
  3090. aen_entry->aen_data.port.mac = bfa_ioc_get_mac(sfp->ioc);
  3091. switch (rsp->event) {
  3092. case BFA_SFP_SCN_INSERTED:
  3093. aen_evt = BFA_PORT_AEN_SFP_INSERT;
  3094. break;
  3095. case BFA_SFP_SCN_REMOVED:
  3096. aen_evt = BFA_PORT_AEN_SFP_REMOVE;
  3097. break;
  3098. case BFA_SFP_SCN_FAILED:
  3099. aen_evt = BFA_PORT_AEN_SFP_ACCESS_ERROR;
  3100. break;
  3101. case BFA_SFP_SCN_UNSUPPORT:
  3102. aen_evt = BFA_PORT_AEN_SFP_UNSUPPORT;
  3103. break;
  3104. case BFA_SFP_SCN_POM:
  3105. aen_evt = BFA_PORT_AEN_SFP_POM;
  3106. aen_entry->aen_data.port.level = rsp->pomlvl;
  3107. break;
  3108. default:
  3109. bfa_trc(sfp, rsp->event);
  3110. WARN_ON(1);
  3111. }
  3112. /* Send the AEN notification */
  3113. bfad_im_post_vendor_event(aen_entry, bfad, ++sfp->ioc->ioc_aen_seq,
  3114. BFA_AEN_CAT_PORT, aen_evt);
  3115. }
  3116. /*
  3117. * SFP get data send
  3118. */
  3119. static void
  3120. bfa_sfp_getdata_send(struct bfa_sfp_s *sfp)
  3121. {
  3122. struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
  3123. bfa_trc(sfp, req->memtype);
  3124. /* build host command */
  3125. bfi_h2i_set(req->mh, BFI_MC_SFP, BFI_SFP_H2I_SHOW,
  3126. bfa_ioc_portid(sfp->ioc));
  3127. /* send mbox cmd */
  3128. bfa_ioc_mbox_queue(sfp->ioc, &sfp->mbcmd);
  3129. }
  3130. /*
  3131. * SFP is valid, read sfp data
  3132. */
  3133. static void
  3134. bfa_sfp_getdata(struct bfa_sfp_s *sfp, enum bfi_sfp_mem_e memtype)
  3135. {
  3136. struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
  3137. WARN_ON(sfp->lock != 0);
  3138. bfa_trc(sfp, sfp->state);
  3139. sfp->lock = 1;
  3140. sfp->memtype = memtype;
  3141. req->memtype = memtype;
  3142. /* Setup SG list */
  3143. bfa_alen_set(&req->alen, sizeof(struct sfp_mem_s), sfp->dbuf_pa);
  3144. bfa_sfp_getdata_send(sfp);
  3145. }
  3146. /*
  3147. * SFP scn handler
  3148. */
  3149. static void
  3150. bfa_sfp_scn(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg)
  3151. {
  3152. struct bfi_sfp_scn_s *rsp = (struct bfi_sfp_scn_s *) msg;
  3153. switch (rsp->event) {
  3154. case BFA_SFP_SCN_INSERTED:
  3155. sfp->state = BFA_SFP_STATE_INSERTED;
  3156. sfp->data_valid = 0;
  3157. bfa_sfp_scn_aen_post(sfp, rsp);
  3158. break;
  3159. case BFA_SFP_SCN_REMOVED:
  3160. sfp->state = BFA_SFP_STATE_REMOVED;
  3161. sfp->data_valid = 0;
  3162. bfa_sfp_scn_aen_post(sfp, rsp);
  3163. break;
  3164. case BFA_SFP_SCN_FAILED:
  3165. sfp->state = BFA_SFP_STATE_FAILED;
  3166. sfp->data_valid = 0;
  3167. bfa_sfp_scn_aen_post(sfp, rsp);
  3168. break;
  3169. case BFA_SFP_SCN_UNSUPPORT:
  3170. sfp->state = BFA_SFP_STATE_UNSUPPORT;
  3171. bfa_sfp_scn_aen_post(sfp, rsp);
  3172. if (!sfp->lock)
  3173. bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
  3174. break;
  3175. case BFA_SFP_SCN_POM:
  3176. bfa_sfp_scn_aen_post(sfp, rsp);
  3177. break;
  3178. case BFA_SFP_SCN_VALID:
  3179. sfp->state = BFA_SFP_STATE_VALID;
  3180. if (!sfp->lock)
  3181. bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
  3182. break;
  3183. default:
  3184. bfa_trc(sfp, rsp->event);
  3185. WARN_ON(1);
  3186. }
  3187. }
  3188. /*
  3189. * SFP show complete
  3190. */
  3191. static void
  3192. bfa_sfp_show_comp(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg)
  3193. {
  3194. struct bfi_sfp_rsp_s *rsp = (struct bfi_sfp_rsp_s *) msg;
  3195. if (!sfp->lock) {
  3196. /*
  3197. * receiving response after ioc failure
  3198. */
  3199. bfa_trc(sfp, sfp->lock);
  3200. return;
  3201. }
  3202. bfa_trc(sfp, rsp->status);
  3203. if (rsp->status == BFA_STATUS_OK) {
  3204. sfp->data_valid = 1;
  3205. if (sfp->state == BFA_SFP_STATE_VALID)
  3206. sfp->status = BFA_STATUS_OK;
  3207. else if (sfp->state == BFA_SFP_STATE_UNSUPPORT)
  3208. sfp->status = BFA_STATUS_SFP_UNSUPP;
  3209. else
  3210. bfa_trc(sfp, sfp->state);
  3211. } else {
  3212. sfp->data_valid = 0;
  3213. sfp->status = rsp->status;
  3214. /* sfpshow shouldn't change sfp state */
  3215. }
  3216. bfa_trc(sfp, sfp->memtype);
  3217. if (sfp->memtype == BFI_SFP_MEM_DIAGEXT) {
  3218. bfa_trc(sfp, sfp->data_valid);
  3219. if (sfp->data_valid) {
  3220. u32 size = sizeof(struct sfp_mem_s);
  3221. u8 *des = (u8 *)(sfp->sfpmem);
  3222. memcpy(des, sfp->dbuf_kva, size);
  3223. }
  3224. /*
  3225. * Queue completion callback.
  3226. */
  3227. bfa_cb_sfp_show(sfp);
  3228. } else
  3229. sfp->lock = 0;
  3230. bfa_trc(sfp, sfp->state_query_lock);
  3231. if (sfp->state_query_lock) {
  3232. sfp->state = rsp->state;
  3233. /* Complete callback */
  3234. bfa_cb_sfp_state_query(sfp);
  3235. }
  3236. }
  3237. /*
  3238. * SFP query fw sfp state
  3239. */
  3240. static void
  3241. bfa_sfp_state_query(struct bfa_sfp_s *sfp)
  3242. {
  3243. struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
  3244. /* Should not be doing query if not in _INIT state */
  3245. WARN_ON(sfp->state != BFA_SFP_STATE_INIT);
  3246. WARN_ON(sfp->state_query_lock != 0);
  3247. bfa_trc(sfp, sfp->state);
  3248. sfp->state_query_lock = 1;
  3249. req->memtype = 0;
  3250. if (!sfp->lock)
  3251. bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
  3252. }
  3253. static void
  3254. bfa_sfp_media_get(struct bfa_sfp_s *sfp)
  3255. {
  3256. enum bfa_defs_sfp_media_e *media = sfp->media;
  3257. *media = BFA_SFP_MEDIA_UNKNOWN;
  3258. if (sfp->state == BFA_SFP_STATE_UNSUPPORT)
  3259. *media = BFA_SFP_MEDIA_UNSUPPORT;
  3260. else if (sfp->state == BFA_SFP_STATE_VALID) {
  3261. union sfp_xcvr_e10g_code_u e10g;
  3262. struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva;
  3263. u16 xmtr_tech = (sfpmem->srlid_base.xcvr[4] & 0x3) << 7 |
  3264. (sfpmem->srlid_base.xcvr[5] >> 1);
  3265. e10g.b = sfpmem->srlid_base.xcvr[0];
  3266. bfa_trc(sfp, e10g.b);
  3267. bfa_trc(sfp, xmtr_tech);
  3268. /* check fc transmitter tech */
  3269. if ((xmtr_tech & SFP_XMTR_TECH_CU) ||
  3270. (xmtr_tech & SFP_XMTR_TECH_CP) ||
  3271. (xmtr_tech & SFP_XMTR_TECH_CA))
  3272. *media = BFA_SFP_MEDIA_CU;
  3273. else if ((xmtr_tech & SFP_XMTR_TECH_EL_INTRA) ||
  3274. (xmtr_tech & SFP_XMTR_TECH_EL_INTER))
  3275. *media = BFA_SFP_MEDIA_EL;
  3276. else if ((xmtr_tech & SFP_XMTR_TECH_LL) ||
  3277. (xmtr_tech & SFP_XMTR_TECH_LC))
  3278. *media = BFA_SFP_MEDIA_LW;
  3279. else if ((xmtr_tech & SFP_XMTR_TECH_SL) ||
  3280. (xmtr_tech & SFP_XMTR_TECH_SN) ||
  3281. (xmtr_tech & SFP_XMTR_TECH_SA))
  3282. *media = BFA_SFP_MEDIA_SW;
  3283. /* Check 10G Ethernet Compilance code */
  3284. else if (e10g.r.e10g_sr)
  3285. *media = BFA_SFP_MEDIA_SW;
  3286. else if (e10g.r.e10g_lrm && e10g.r.e10g_lr)
  3287. *media = BFA_SFP_MEDIA_LW;
  3288. else if (e10g.r.e10g_unall)
  3289. *media = BFA_SFP_MEDIA_UNKNOWN;
  3290. else
  3291. bfa_trc(sfp, 0);
  3292. } else
  3293. bfa_trc(sfp, sfp->state);
  3294. }
  3295. static bfa_status_t
  3296. bfa_sfp_speed_valid(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed)
  3297. {
  3298. struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva;
  3299. struct sfp_xcvr_s *xcvr = (struct sfp_xcvr_s *) sfpmem->srlid_base.xcvr;
  3300. union sfp_xcvr_fc3_code_u fc3 = xcvr->fc3;
  3301. union sfp_xcvr_e10g_code_u e10g = xcvr->e10g;
  3302. if (portspeed == BFA_PORT_SPEED_10GBPS) {
  3303. if (e10g.r.e10g_sr || e10g.r.e10g_lr)
  3304. return BFA_STATUS_OK;
  3305. else {
  3306. bfa_trc(sfp, e10g.b);
  3307. return BFA_STATUS_UNSUPP_SPEED;
  3308. }
  3309. }
  3310. if (((portspeed & BFA_PORT_SPEED_16GBPS) && fc3.r.mb1600) ||
  3311. ((portspeed & BFA_PORT_SPEED_8GBPS) && fc3.r.mb800) ||
  3312. ((portspeed & BFA_PORT_SPEED_4GBPS) && fc3.r.mb400) ||
  3313. ((portspeed & BFA_PORT_SPEED_2GBPS) && fc3.r.mb200) ||
  3314. ((portspeed & BFA_PORT_SPEED_1GBPS) && fc3.r.mb100))
  3315. return BFA_STATUS_OK;
  3316. else {
  3317. bfa_trc(sfp, portspeed);
  3318. bfa_trc(sfp, fc3.b);
  3319. bfa_trc(sfp, e10g.b);
  3320. return BFA_STATUS_UNSUPP_SPEED;
  3321. }
  3322. }
  3323. /*
  3324. * SFP hmbox handler
  3325. */
  3326. void
  3327. bfa_sfp_intr(void *sfparg, struct bfi_mbmsg_s *msg)
  3328. {
  3329. struct bfa_sfp_s *sfp = sfparg;
  3330. switch (msg->mh.msg_id) {
  3331. case BFI_SFP_I2H_SHOW:
  3332. bfa_sfp_show_comp(sfp, msg);
  3333. break;
  3334. case BFI_SFP_I2H_SCN:
  3335. bfa_sfp_scn(sfp, msg);
  3336. break;
  3337. default:
  3338. bfa_trc(sfp, msg->mh.msg_id);
  3339. WARN_ON(1);
  3340. }
  3341. }
  3342. /*
  3343. * Return DMA memory needed by sfp module.
  3344. */
  3345. u32
  3346. bfa_sfp_meminfo(void)
  3347. {
  3348. return BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
  3349. }
  3350. /*
  3351. * Attach virtual and physical memory for SFP.
  3352. */
  3353. void
  3354. bfa_sfp_attach(struct bfa_sfp_s *sfp, struct bfa_ioc_s *ioc, void *dev,
  3355. struct bfa_trc_mod_s *trcmod)
  3356. {
  3357. sfp->dev = dev;
  3358. sfp->ioc = ioc;
  3359. sfp->trcmod = trcmod;
  3360. sfp->cbfn = NULL;
  3361. sfp->cbarg = NULL;
  3362. sfp->sfpmem = NULL;
  3363. sfp->lock = 0;
  3364. sfp->data_valid = 0;
  3365. sfp->state = BFA_SFP_STATE_INIT;
  3366. sfp->state_query_lock = 0;
  3367. sfp->state_query_cbfn = NULL;
  3368. sfp->state_query_cbarg = NULL;
  3369. sfp->media = NULL;
  3370. sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
  3371. sfp->is_elb = BFA_FALSE;
  3372. bfa_ioc_mbox_regisr(sfp->ioc, BFI_MC_SFP, bfa_sfp_intr, sfp);
  3373. bfa_q_qe_init(&sfp->ioc_notify);
  3374. bfa_ioc_notify_init(&sfp->ioc_notify, bfa_sfp_notify, sfp);
  3375. list_add_tail(&sfp->ioc_notify.qe, &sfp->ioc->notify_q);
  3376. }
  3377. /*
  3378. * Claim Memory for SFP
  3379. */
  3380. void
  3381. bfa_sfp_memclaim(struct bfa_sfp_s *sfp, u8 *dm_kva, u64 dm_pa)
  3382. {
  3383. sfp->dbuf_kva = dm_kva;
  3384. sfp->dbuf_pa = dm_pa;
  3385. memset(sfp->dbuf_kva, 0, sizeof(struct sfp_mem_s));
  3386. dm_kva += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
  3387. dm_pa += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
  3388. }
  3389. /*
  3390. * Show SFP eeprom content
  3391. *
  3392. * @param[in] sfp - bfa sfp module
  3393. *
  3394. * @param[out] sfpmem - sfp eeprom data
  3395. *
  3396. */
  3397. bfa_status_t
  3398. bfa_sfp_show(struct bfa_sfp_s *sfp, struct sfp_mem_s *sfpmem,
  3399. bfa_cb_sfp_t cbfn, void *cbarg)
  3400. {
  3401. if (!bfa_ioc_is_operational(sfp->ioc)) {
  3402. bfa_trc(sfp, 0);
  3403. return BFA_STATUS_IOC_NON_OP;
  3404. }
  3405. if (sfp->lock) {
  3406. bfa_trc(sfp, 0);
  3407. return BFA_STATUS_DEVBUSY;
  3408. }
  3409. sfp->cbfn = cbfn;
  3410. sfp->cbarg = cbarg;
  3411. sfp->sfpmem = sfpmem;
  3412. bfa_sfp_getdata(sfp, BFI_SFP_MEM_DIAGEXT);
  3413. return BFA_STATUS_OK;
  3414. }
  3415. /*
  3416. * Return SFP Media type
  3417. *
  3418. * @param[in] sfp - bfa sfp module
  3419. *
  3420. * @param[out] media - port speed from user
  3421. *
  3422. */
  3423. bfa_status_t
  3424. bfa_sfp_media(struct bfa_sfp_s *sfp, enum bfa_defs_sfp_media_e *media,
  3425. bfa_cb_sfp_t cbfn, void *cbarg)
  3426. {
  3427. if (!bfa_ioc_is_operational(sfp->ioc)) {
  3428. bfa_trc(sfp, 0);
  3429. return BFA_STATUS_IOC_NON_OP;
  3430. }
  3431. sfp->media = media;
  3432. if (sfp->state == BFA_SFP_STATE_INIT) {
  3433. if (sfp->state_query_lock) {
  3434. bfa_trc(sfp, 0);
  3435. return BFA_STATUS_DEVBUSY;
  3436. } else {
  3437. sfp->state_query_cbfn = cbfn;
  3438. sfp->state_query_cbarg = cbarg;
  3439. bfa_sfp_state_query(sfp);
  3440. return BFA_STATUS_SFP_NOT_READY;
  3441. }
  3442. }
  3443. bfa_sfp_media_get(sfp);
  3444. return BFA_STATUS_OK;
  3445. }
  3446. /*
  3447. * Check if user set port speed is allowed by the SFP
  3448. *
  3449. * @param[in] sfp - bfa sfp module
  3450. * @param[in] portspeed - port speed from user
  3451. *
  3452. */
  3453. bfa_status_t
  3454. bfa_sfp_speed(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed,
  3455. bfa_cb_sfp_t cbfn, void *cbarg)
  3456. {
  3457. WARN_ON(portspeed == BFA_PORT_SPEED_UNKNOWN);
  3458. if (!bfa_ioc_is_operational(sfp->ioc))
  3459. return BFA_STATUS_IOC_NON_OP;
  3460. /* For Mezz card, all speed is allowed */
  3461. if (bfa_mfg_is_mezz(sfp->ioc->attr->card_type))
  3462. return BFA_STATUS_OK;
  3463. /* Check SFP state */
  3464. sfp->portspeed = portspeed;
  3465. if (sfp->state == BFA_SFP_STATE_INIT) {
  3466. if (sfp->state_query_lock) {
  3467. bfa_trc(sfp, 0);
  3468. return BFA_STATUS_DEVBUSY;
  3469. } else {
  3470. sfp->state_query_cbfn = cbfn;
  3471. sfp->state_query_cbarg = cbarg;
  3472. bfa_sfp_state_query(sfp);
  3473. return BFA_STATUS_SFP_NOT_READY;
  3474. }
  3475. }
  3476. if (sfp->state == BFA_SFP_STATE_REMOVED ||
  3477. sfp->state == BFA_SFP_STATE_FAILED) {
  3478. bfa_trc(sfp, sfp->state);
  3479. return BFA_STATUS_NO_SFP_DEV;
  3480. }
  3481. if (sfp->state == BFA_SFP_STATE_INSERTED) {
  3482. bfa_trc(sfp, sfp->state);
  3483. return BFA_STATUS_DEVBUSY; /* sfp is reading data */
  3484. }
  3485. /* For eloopback, all speed is allowed */
  3486. if (sfp->is_elb)
  3487. return BFA_STATUS_OK;
  3488. return bfa_sfp_speed_valid(sfp, portspeed);
  3489. }
  3490. /*
  3491. * Flash module specific
  3492. */
  3493. /*
  3494. * FLASH DMA buffer should be big enough to hold both MFG block and
  3495. * asic block(64k) at the same time and also should be 2k aligned to
  3496. * avoid write segement to cross sector boundary.
  3497. */
  3498. #define BFA_FLASH_SEG_SZ 2048
  3499. #define BFA_FLASH_DMA_BUF_SZ \
  3500. BFA_ROUNDUP(0x010000 + sizeof(struct bfa_mfg_block_s), BFA_FLASH_SEG_SZ)
  3501. static void
  3502. bfa_flash_aen_audit_post(struct bfa_ioc_s *ioc, enum bfa_audit_aen_event event,
  3503. int inst, int type)
  3504. {
  3505. struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
  3506. struct bfa_aen_entry_s *aen_entry;
  3507. bfad_get_aen_entry(bfad, aen_entry);
  3508. if (!aen_entry)
  3509. return;
  3510. aen_entry->aen_data.audit.pwwn = ioc->attr->pwwn;
  3511. aen_entry->aen_data.audit.partition_inst = inst;
  3512. aen_entry->aen_data.audit.partition_type = type;
  3513. /* Send the AEN notification */
  3514. bfad_im_post_vendor_event(aen_entry, bfad, ++ioc->ioc_aen_seq,
  3515. BFA_AEN_CAT_AUDIT, event);
  3516. }
  3517. static void
  3518. bfa_flash_cb(struct bfa_flash_s *flash)
  3519. {
  3520. flash->op_busy = 0;
  3521. if (flash->cbfn)
  3522. flash->cbfn(flash->cbarg, flash->status);
  3523. }
  3524. static void
  3525. bfa_flash_notify(void *cbarg, enum bfa_ioc_event_e event)
  3526. {
  3527. struct bfa_flash_s *flash = cbarg;
  3528. bfa_trc(flash, event);
  3529. switch (event) {
  3530. case BFA_IOC_E_DISABLED:
  3531. case BFA_IOC_E_FAILED:
  3532. if (flash->op_busy) {
  3533. flash->status = BFA_STATUS_IOC_FAILURE;
  3534. flash->cbfn(flash->cbarg, flash->status);
  3535. flash->op_busy = 0;
  3536. }
  3537. break;
  3538. default:
  3539. break;
  3540. }
  3541. }
  3542. /*
  3543. * Send flash attribute query request.
  3544. *
  3545. * @param[in] cbarg - callback argument
  3546. */
  3547. static void
  3548. bfa_flash_query_send(void *cbarg)
  3549. {
  3550. struct bfa_flash_s *flash = cbarg;
  3551. struct bfi_flash_query_req_s *msg =
  3552. (struct bfi_flash_query_req_s *) flash->mb.msg;
  3553. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_QUERY_REQ,
  3554. bfa_ioc_portid(flash->ioc));
  3555. bfa_alen_set(&msg->alen, sizeof(struct bfa_flash_attr_s),
  3556. flash->dbuf_pa);
  3557. bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
  3558. }
  3559. /*
  3560. * Send flash write request.
  3561. *
  3562. * @param[in] cbarg - callback argument
  3563. */
  3564. static void
  3565. bfa_flash_write_send(struct bfa_flash_s *flash)
  3566. {
  3567. struct bfi_flash_write_req_s *msg =
  3568. (struct bfi_flash_write_req_s *) flash->mb.msg;
  3569. u32 len;
  3570. msg->type = be32_to_cpu(flash->type);
  3571. msg->instance = flash->instance;
  3572. msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
  3573. len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
  3574. flash->residue : BFA_FLASH_DMA_BUF_SZ;
  3575. msg->length = be32_to_cpu(len);
  3576. /* indicate if it's the last msg of the whole write operation */
  3577. msg->last = (len == flash->residue) ? 1 : 0;
  3578. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_WRITE_REQ,
  3579. bfa_ioc_portid(flash->ioc));
  3580. bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
  3581. memcpy(flash->dbuf_kva, flash->ubuf + flash->offset, len);
  3582. bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
  3583. flash->residue -= len;
  3584. flash->offset += len;
  3585. }
  3586. /*
  3587. * Send flash read request.
  3588. *
  3589. * @param[in] cbarg - callback argument
  3590. */
  3591. static void
  3592. bfa_flash_read_send(void *cbarg)
  3593. {
  3594. struct bfa_flash_s *flash = cbarg;
  3595. struct bfi_flash_read_req_s *msg =
  3596. (struct bfi_flash_read_req_s *) flash->mb.msg;
  3597. u32 len;
  3598. msg->type = be32_to_cpu(flash->type);
  3599. msg->instance = flash->instance;
  3600. msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
  3601. len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
  3602. flash->residue : BFA_FLASH_DMA_BUF_SZ;
  3603. msg->length = be32_to_cpu(len);
  3604. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_READ_REQ,
  3605. bfa_ioc_portid(flash->ioc));
  3606. bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
  3607. bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
  3608. }
  3609. /*
  3610. * Send flash erase request.
  3611. *
  3612. * @param[in] cbarg - callback argument
  3613. */
  3614. static void
  3615. bfa_flash_erase_send(void *cbarg)
  3616. {
  3617. struct bfa_flash_s *flash = cbarg;
  3618. struct bfi_flash_erase_req_s *msg =
  3619. (struct bfi_flash_erase_req_s *) flash->mb.msg;
  3620. msg->type = be32_to_cpu(flash->type);
  3621. msg->instance = flash->instance;
  3622. bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_ERASE_REQ,
  3623. bfa_ioc_portid(flash->ioc));
  3624. bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
  3625. }
  3626. /*
  3627. * Process flash response messages upon receiving interrupts.
  3628. *
  3629. * @param[in] flasharg - flash structure
  3630. * @param[in] msg - message structure
  3631. */
  3632. static void
  3633. bfa_flash_intr(void *flasharg, struct bfi_mbmsg_s *msg)
  3634. {
  3635. struct bfa_flash_s *flash = flasharg;
  3636. u32 status;
  3637. union {
  3638. struct bfi_flash_query_rsp_s *query;
  3639. struct bfi_flash_erase_rsp_s *erase;
  3640. struct bfi_flash_write_rsp_s *write;
  3641. struct bfi_flash_read_rsp_s *read;
  3642. struct bfi_flash_event_s *event;
  3643. struct bfi_mbmsg_s *msg;
  3644. } m;
  3645. m.msg = msg;
  3646. bfa_trc(flash, msg->mh.msg_id);
  3647. if (!flash->op_busy && msg->mh.msg_id != BFI_FLASH_I2H_EVENT) {
  3648. /* receiving response after ioc failure */
  3649. bfa_trc(flash, 0x9999);
  3650. return;
  3651. }
  3652. switch (msg->mh.msg_id) {
  3653. case BFI_FLASH_I2H_QUERY_RSP:
  3654. status = be32_to_cpu(m.query->status);
  3655. bfa_trc(flash, status);
  3656. if (status == BFA_STATUS_OK) {
  3657. u32 i;
  3658. struct bfa_flash_attr_s *attr, *f;
  3659. attr = (struct bfa_flash_attr_s *) flash->ubuf;
  3660. f = (struct bfa_flash_attr_s *) flash->dbuf_kva;
  3661. attr->status = be32_to_cpu(f->status);
  3662. attr->npart = be32_to_cpu(f->npart);
  3663. bfa_trc(flash, attr->status);
  3664. bfa_trc(flash, attr->npart);
  3665. for (i = 0; i < attr->npart; i++) {
  3666. attr->part[i].part_type =
  3667. be32_to_cpu(f->part[i].part_type);
  3668. attr->part[i].part_instance =
  3669. be32_to_cpu(f->part[i].part_instance);
  3670. attr->part[i].part_off =
  3671. be32_to_cpu(f->part[i].part_off);
  3672. attr->part[i].part_size =
  3673. be32_to_cpu(f->part[i].part_size);
  3674. attr->part[i].part_len =
  3675. be32_to_cpu(f->part[i].part_len);
  3676. attr->part[i].part_status =
  3677. be32_to_cpu(f->part[i].part_status);
  3678. }
  3679. }
  3680. flash->status = status;
  3681. bfa_flash_cb(flash);
  3682. break;
  3683. case BFI_FLASH_I2H_ERASE_RSP:
  3684. status = be32_to_cpu(m.erase->status);
  3685. bfa_trc(flash, status);
  3686. flash->status = status;
  3687. bfa_flash_cb(flash);
  3688. break;
  3689. case BFI_FLASH_I2H_WRITE_RSP:
  3690. status = be32_to_cpu(m.write->status);
  3691. bfa_trc(flash, status);
  3692. if (status != BFA_STATUS_OK || flash->residue == 0) {
  3693. flash->status = status;
  3694. bfa_flash_cb(flash);
  3695. } else {
  3696. bfa_trc(flash, flash->offset);
  3697. bfa_flash_write_send(flash);
  3698. }
  3699. break;
  3700. case BFI_FLASH_I2H_READ_RSP:
  3701. status = be32_to_cpu(m.read->status);
  3702. bfa_trc(flash, status);
  3703. if (status != BFA_STATUS_OK) {
  3704. flash->status = status;
  3705. bfa_flash_cb(flash);
  3706. } else {
  3707. u32 len = be32_to_cpu(m.read->length);
  3708. bfa_trc(flash, flash->offset);
  3709. bfa_trc(flash, len);
  3710. memcpy(flash->ubuf + flash->offset,
  3711. flash->dbuf_kva, len);
  3712. flash->residue -= len;
  3713. flash->offset += len;
  3714. if (flash->residue == 0) {
  3715. flash->status = status;
  3716. bfa_flash_cb(flash);
  3717. } else
  3718. bfa_flash_read_send(flash);
  3719. }
  3720. break;
  3721. case BFI_FLASH_I2H_BOOT_VER_RSP:
  3722. break;
  3723. case BFI_FLASH_I2H_EVENT:
  3724. status = be32_to_cpu(m.event->status);
  3725. bfa_trc(flash, status);
  3726. if (status == BFA_STATUS_BAD_FWCFG)
  3727. bfa_ioc_aen_post(flash->ioc, BFA_IOC_AEN_FWCFG_ERROR);
  3728. else if (status == BFA_STATUS_INVALID_VENDOR) {
  3729. u32 param;
  3730. param = be32_to_cpu(m.event->param);
  3731. bfa_trc(flash, param);
  3732. bfa_ioc_aen_post(flash->ioc,
  3733. BFA_IOC_AEN_INVALID_VENDOR);
  3734. }
  3735. break;
  3736. default:
  3737. WARN_ON(1);
  3738. }
  3739. }
  3740. /*
  3741. * Flash memory info API.
  3742. *
  3743. * @param[in] mincfg - minimal cfg variable
  3744. */
  3745. u32
  3746. bfa_flash_meminfo(bfa_boolean_t mincfg)
  3747. {
  3748. /* min driver doesn't need flash */
  3749. if (mincfg)
  3750. return 0;
  3751. return BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  3752. }
  3753. /*
  3754. * Flash attach API.
  3755. *
  3756. * @param[in] flash - flash structure
  3757. * @param[in] ioc - ioc structure
  3758. * @param[in] dev - device structure
  3759. * @param[in] trcmod - trace module
  3760. * @param[in] logmod - log module
  3761. */
  3762. void
  3763. bfa_flash_attach(struct bfa_flash_s *flash, struct bfa_ioc_s *ioc, void *dev,
  3764. struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
  3765. {
  3766. flash->ioc = ioc;
  3767. flash->trcmod = trcmod;
  3768. flash->cbfn = NULL;
  3769. flash->cbarg = NULL;
  3770. flash->op_busy = 0;
  3771. bfa_ioc_mbox_regisr(flash->ioc, BFI_MC_FLASH, bfa_flash_intr, flash);
  3772. bfa_q_qe_init(&flash->ioc_notify);
  3773. bfa_ioc_notify_init(&flash->ioc_notify, bfa_flash_notify, flash);
  3774. list_add_tail(&flash->ioc_notify.qe, &flash->ioc->notify_q);
  3775. /* min driver doesn't need flash */
  3776. if (mincfg) {
  3777. flash->dbuf_kva = NULL;
  3778. flash->dbuf_pa = 0;
  3779. }
  3780. }
  3781. /*
  3782. * Claim memory for flash
  3783. *
  3784. * @param[in] flash - flash structure
  3785. * @param[in] dm_kva - pointer to virtual memory address
  3786. * @param[in] dm_pa - physical memory address
  3787. * @param[in] mincfg - minimal cfg variable
  3788. */
  3789. void
  3790. bfa_flash_memclaim(struct bfa_flash_s *flash, u8 *dm_kva, u64 dm_pa,
  3791. bfa_boolean_t mincfg)
  3792. {
  3793. if (mincfg)
  3794. return;
  3795. flash->dbuf_kva = dm_kva;
  3796. flash->dbuf_pa = dm_pa;
  3797. memset(flash->dbuf_kva, 0, BFA_FLASH_DMA_BUF_SZ);
  3798. dm_kva += BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  3799. dm_pa += BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  3800. }
  3801. /*
  3802. * Get flash attribute.
  3803. *
  3804. * @param[in] flash - flash structure
  3805. * @param[in] attr - flash attribute structure
  3806. * @param[in] cbfn - callback function
  3807. * @param[in] cbarg - callback argument
  3808. *
  3809. * Return status.
  3810. */
  3811. bfa_status_t
  3812. bfa_flash_get_attr(struct bfa_flash_s *flash, struct bfa_flash_attr_s *attr,
  3813. bfa_cb_flash_t cbfn, void *cbarg)
  3814. {
  3815. bfa_trc(flash, BFI_FLASH_H2I_QUERY_REQ);
  3816. if (!bfa_ioc_is_operational(flash->ioc))
  3817. return BFA_STATUS_IOC_NON_OP;
  3818. if (flash->op_busy) {
  3819. bfa_trc(flash, flash->op_busy);
  3820. return BFA_STATUS_DEVBUSY;
  3821. }
  3822. flash->op_busy = 1;
  3823. flash->cbfn = cbfn;
  3824. flash->cbarg = cbarg;
  3825. flash->ubuf = (u8 *) attr;
  3826. bfa_flash_query_send(flash);
  3827. return BFA_STATUS_OK;
  3828. }
  3829. /*
  3830. * Erase flash partition.
  3831. *
  3832. * @param[in] flash - flash structure
  3833. * @param[in] type - flash partition type
  3834. * @param[in] instance - flash partition instance
  3835. * @param[in] cbfn - callback function
  3836. * @param[in] cbarg - callback argument
  3837. *
  3838. * Return status.
  3839. */
  3840. bfa_status_t
  3841. bfa_flash_erase_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
  3842. u8 instance, bfa_cb_flash_t cbfn, void *cbarg)
  3843. {
  3844. bfa_trc(flash, BFI_FLASH_H2I_ERASE_REQ);
  3845. bfa_trc(flash, type);
  3846. bfa_trc(flash, instance);
  3847. if (!bfa_ioc_is_operational(flash->ioc))
  3848. return BFA_STATUS_IOC_NON_OP;
  3849. if (flash->op_busy) {
  3850. bfa_trc(flash, flash->op_busy);
  3851. return BFA_STATUS_DEVBUSY;
  3852. }
  3853. flash->op_busy = 1;
  3854. flash->cbfn = cbfn;
  3855. flash->cbarg = cbarg;
  3856. flash->type = type;
  3857. flash->instance = instance;
  3858. bfa_flash_erase_send(flash);
  3859. bfa_flash_aen_audit_post(flash->ioc, BFA_AUDIT_AEN_FLASH_ERASE,
  3860. instance, type);
  3861. return BFA_STATUS_OK;
  3862. }
  3863. /*
  3864. * Update flash partition.
  3865. *
  3866. * @param[in] flash - flash structure
  3867. * @param[in] type - flash partition type
  3868. * @param[in] instance - flash partition instance
  3869. * @param[in] buf - update data buffer
  3870. * @param[in] len - data buffer length
  3871. * @param[in] offset - offset relative to the partition starting address
  3872. * @param[in] cbfn - callback function
  3873. * @param[in] cbarg - callback argument
  3874. *
  3875. * Return status.
  3876. */
  3877. bfa_status_t
  3878. bfa_flash_update_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
  3879. u8 instance, void *buf, u32 len, u32 offset,
  3880. bfa_cb_flash_t cbfn, void *cbarg)
  3881. {
  3882. bfa_trc(flash, BFI_FLASH_H2I_WRITE_REQ);
  3883. bfa_trc(flash, type);
  3884. bfa_trc(flash, instance);
  3885. bfa_trc(flash, len);
  3886. bfa_trc(flash, offset);
  3887. if (!bfa_ioc_is_operational(flash->ioc))
  3888. return BFA_STATUS_IOC_NON_OP;
  3889. /*
  3890. * 'len' must be in word (4-byte) boundary
  3891. * 'offset' must be in sector (16kb) boundary
  3892. */
  3893. if (!len || (len & 0x03) || (offset & 0x00003FFF))
  3894. return BFA_STATUS_FLASH_BAD_LEN;
  3895. if (type == BFA_FLASH_PART_MFG)
  3896. return BFA_STATUS_EINVAL;
  3897. if (flash->op_busy) {
  3898. bfa_trc(flash, flash->op_busy);
  3899. return BFA_STATUS_DEVBUSY;
  3900. }
  3901. flash->op_busy = 1;
  3902. flash->cbfn = cbfn;
  3903. flash->cbarg = cbarg;
  3904. flash->type = type;
  3905. flash->instance = instance;
  3906. flash->residue = len;
  3907. flash->offset = 0;
  3908. flash->addr_off = offset;
  3909. flash->ubuf = buf;
  3910. bfa_flash_write_send(flash);
  3911. return BFA_STATUS_OK;
  3912. }
  3913. /*
  3914. * Read flash partition.
  3915. *
  3916. * @param[in] flash - flash structure
  3917. * @param[in] type - flash partition type
  3918. * @param[in] instance - flash partition instance
  3919. * @param[in] buf - read data buffer
  3920. * @param[in] len - data buffer length
  3921. * @param[in] offset - offset relative to the partition starting address
  3922. * @param[in] cbfn - callback function
  3923. * @param[in] cbarg - callback argument
  3924. *
  3925. * Return status.
  3926. */
  3927. bfa_status_t
  3928. bfa_flash_read_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
  3929. u8 instance, void *buf, u32 len, u32 offset,
  3930. bfa_cb_flash_t cbfn, void *cbarg)
  3931. {
  3932. bfa_trc(flash, BFI_FLASH_H2I_READ_REQ);
  3933. bfa_trc(flash, type);
  3934. bfa_trc(flash, instance);
  3935. bfa_trc(flash, len);
  3936. bfa_trc(flash, offset);
  3937. if (!bfa_ioc_is_operational(flash->ioc))
  3938. return BFA_STATUS_IOC_NON_OP;
  3939. /*
  3940. * 'len' must be in word (4-byte) boundary
  3941. * 'offset' must be in sector (16kb) boundary
  3942. */
  3943. if (!len || (len & 0x03) || (offset & 0x00003FFF))
  3944. return BFA_STATUS_FLASH_BAD_LEN;
  3945. if (flash->op_busy) {
  3946. bfa_trc(flash, flash->op_busy);
  3947. return BFA_STATUS_DEVBUSY;
  3948. }
  3949. flash->op_busy = 1;
  3950. flash->cbfn = cbfn;
  3951. flash->cbarg = cbarg;
  3952. flash->type = type;
  3953. flash->instance = instance;
  3954. flash->residue = len;
  3955. flash->offset = 0;
  3956. flash->addr_off = offset;
  3957. flash->ubuf = buf;
  3958. bfa_flash_read_send(flash);
  3959. return BFA_STATUS_OK;
  3960. }
  3961. /*
  3962. * DIAG module specific
  3963. */
  3964. #define BFA_DIAG_MEMTEST_TOV 50000 /* memtest timeout in msec */
  3965. #define CT2_BFA_DIAG_MEMTEST_TOV (9*30*1000) /* 4.5 min */
  3966. /* IOC event handler */
  3967. static void
  3968. bfa_diag_notify(void *diag_arg, enum bfa_ioc_event_e event)
  3969. {
  3970. struct bfa_diag_s *diag = diag_arg;
  3971. bfa_trc(diag, event);
  3972. bfa_trc(diag, diag->block);
  3973. bfa_trc(diag, diag->fwping.lock);
  3974. bfa_trc(diag, diag->tsensor.lock);
  3975. switch (event) {
  3976. case BFA_IOC_E_DISABLED:
  3977. case BFA_IOC_E_FAILED:
  3978. if (diag->fwping.lock) {
  3979. diag->fwping.status = BFA_STATUS_IOC_FAILURE;
  3980. diag->fwping.cbfn(diag->fwping.cbarg,
  3981. diag->fwping.status);
  3982. diag->fwping.lock = 0;
  3983. }
  3984. if (diag->tsensor.lock) {
  3985. diag->tsensor.status = BFA_STATUS_IOC_FAILURE;
  3986. diag->tsensor.cbfn(diag->tsensor.cbarg,
  3987. diag->tsensor.status);
  3988. diag->tsensor.lock = 0;
  3989. }
  3990. if (diag->block) {
  3991. if (diag->timer_active) {
  3992. bfa_timer_stop(&diag->timer);
  3993. diag->timer_active = 0;
  3994. }
  3995. diag->status = BFA_STATUS_IOC_FAILURE;
  3996. diag->cbfn(diag->cbarg, diag->status);
  3997. diag->block = 0;
  3998. }
  3999. break;
  4000. default:
  4001. break;
  4002. }
  4003. }
  4004. static void
  4005. bfa_diag_memtest_done(void *cbarg)
  4006. {
  4007. struct bfa_diag_s *diag = cbarg;
  4008. struct bfa_ioc_s *ioc = diag->ioc;
  4009. struct bfa_diag_memtest_result *res = diag->result;
  4010. u32 loff = BFI_BOOT_MEMTEST_RES_ADDR;
  4011. u32 pgnum, i;
  4012. pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
  4013. writel(pgnum, ioc->ioc_regs.host_page_num_fn);
  4014. for (i = 0; i < (sizeof(struct bfa_diag_memtest_result) /
  4015. sizeof(u32)); i++) {
  4016. /* read test result from smem */
  4017. *((u32 *) res + i) =
  4018. bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
  4019. loff += sizeof(u32);
  4020. }
  4021. /* Reset IOC fwstates to BFI_IOC_UNINIT */
  4022. bfa_ioc_reset_fwstate(ioc);
  4023. res->status = swab32(res->status);
  4024. bfa_trc(diag, res->status);
  4025. if (res->status == BFI_BOOT_MEMTEST_RES_SIG)
  4026. diag->status = BFA_STATUS_OK;
  4027. else {
  4028. diag->status = BFA_STATUS_MEMTEST_FAILED;
  4029. res->addr = swab32(res->addr);
  4030. res->exp = swab32(res->exp);
  4031. res->act = swab32(res->act);
  4032. res->err_status = swab32(res->err_status);
  4033. res->err_status1 = swab32(res->err_status1);
  4034. res->err_addr = swab32(res->err_addr);
  4035. bfa_trc(diag, res->addr);
  4036. bfa_trc(diag, res->exp);
  4037. bfa_trc(diag, res->act);
  4038. bfa_trc(diag, res->err_status);
  4039. bfa_trc(diag, res->err_status1);
  4040. bfa_trc(diag, res->err_addr);
  4041. }
  4042. diag->timer_active = 0;
  4043. diag->cbfn(diag->cbarg, diag->status);
  4044. diag->block = 0;
  4045. }
  4046. /*
  4047. * Firmware ping
  4048. */
  4049. /*
  4050. * Perform DMA test directly
  4051. */
  4052. static void
  4053. diag_fwping_send(struct bfa_diag_s *diag)
  4054. {
  4055. struct bfi_diag_fwping_req_s *fwping_req;
  4056. u32 i;
  4057. bfa_trc(diag, diag->fwping.dbuf_pa);
  4058. /* fill DMA area with pattern */
  4059. for (i = 0; i < (BFI_DIAG_DMA_BUF_SZ >> 2); i++)
  4060. *((u32 *)diag->fwping.dbuf_kva + i) = diag->fwping.data;
  4061. /* Fill mbox msg */
  4062. fwping_req = (struct bfi_diag_fwping_req_s *)diag->fwping.mbcmd.msg;
  4063. /* Setup SG list */
  4064. bfa_alen_set(&fwping_req->alen, BFI_DIAG_DMA_BUF_SZ,
  4065. diag->fwping.dbuf_pa);
  4066. /* Set up dma count */
  4067. fwping_req->count = cpu_to_be32(diag->fwping.count);
  4068. /* Set up data pattern */
  4069. fwping_req->data = diag->fwping.data;
  4070. /* build host command */
  4071. bfi_h2i_set(fwping_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_FWPING,
  4072. bfa_ioc_portid(diag->ioc));
  4073. /* send mbox cmd */
  4074. bfa_ioc_mbox_queue(diag->ioc, &diag->fwping.mbcmd);
  4075. }
  4076. static void
  4077. diag_fwping_comp(struct bfa_diag_s *diag,
  4078. struct bfi_diag_fwping_rsp_s *diag_rsp)
  4079. {
  4080. u32 rsp_data = diag_rsp->data;
  4081. u8 rsp_dma_status = diag_rsp->dma_status;
  4082. bfa_trc(diag, rsp_data);
  4083. bfa_trc(diag, rsp_dma_status);
  4084. if (rsp_dma_status == BFA_STATUS_OK) {
  4085. u32 i, pat;
  4086. pat = (diag->fwping.count & 0x1) ? ~(diag->fwping.data) :
  4087. diag->fwping.data;
  4088. /* Check mbox data */
  4089. if (diag->fwping.data != rsp_data) {
  4090. bfa_trc(diag, rsp_data);
  4091. diag->fwping.result->dmastatus =
  4092. BFA_STATUS_DATACORRUPTED;
  4093. diag->fwping.status = BFA_STATUS_DATACORRUPTED;
  4094. diag->fwping.cbfn(diag->fwping.cbarg,
  4095. diag->fwping.status);
  4096. diag->fwping.lock = 0;
  4097. return;
  4098. }
  4099. /* Check dma pattern */
  4100. for (i = 0; i < (BFI_DIAG_DMA_BUF_SZ >> 2); i++) {
  4101. if (*((u32 *)diag->fwping.dbuf_kva + i) != pat) {
  4102. bfa_trc(diag, i);
  4103. bfa_trc(diag, pat);
  4104. bfa_trc(diag,
  4105. *((u32 *)diag->fwping.dbuf_kva + i));
  4106. diag->fwping.result->dmastatus =
  4107. BFA_STATUS_DATACORRUPTED;
  4108. diag->fwping.status = BFA_STATUS_DATACORRUPTED;
  4109. diag->fwping.cbfn(diag->fwping.cbarg,
  4110. diag->fwping.status);
  4111. diag->fwping.lock = 0;
  4112. return;
  4113. }
  4114. }
  4115. diag->fwping.result->dmastatus = BFA_STATUS_OK;
  4116. diag->fwping.status = BFA_STATUS_OK;
  4117. diag->fwping.cbfn(diag->fwping.cbarg, diag->fwping.status);
  4118. diag->fwping.lock = 0;
  4119. } else {
  4120. diag->fwping.status = BFA_STATUS_HDMA_FAILED;
  4121. diag->fwping.cbfn(diag->fwping.cbarg, diag->fwping.status);
  4122. diag->fwping.lock = 0;
  4123. }
  4124. }
  4125. /*
  4126. * Temperature Sensor
  4127. */
  4128. static void
  4129. diag_tempsensor_send(struct bfa_diag_s *diag)
  4130. {
  4131. struct bfi_diag_ts_req_s *msg;
  4132. msg = (struct bfi_diag_ts_req_s *)diag->tsensor.mbcmd.msg;
  4133. bfa_trc(diag, msg->temp);
  4134. /* build host command */
  4135. bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_TEMPSENSOR,
  4136. bfa_ioc_portid(diag->ioc));
  4137. /* send mbox cmd */
  4138. bfa_ioc_mbox_queue(diag->ioc, &diag->tsensor.mbcmd);
  4139. }
  4140. static void
  4141. diag_tempsensor_comp(struct bfa_diag_s *diag, bfi_diag_ts_rsp_t *rsp)
  4142. {
  4143. if (!diag->tsensor.lock) {
  4144. /* receiving response after ioc failure */
  4145. bfa_trc(diag, diag->tsensor.lock);
  4146. return;
  4147. }
  4148. /*
  4149. * ASIC junction tempsensor is a reg read operation
  4150. * it will always return OK
  4151. */
  4152. diag->tsensor.temp->temp = be16_to_cpu(rsp->temp);
  4153. diag->tsensor.temp->ts_junc = rsp->ts_junc;
  4154. diag->tsensor.temp->ts_brd = rsp->ts_brd;
  4155. if (rsp->ts_brd) {
  4156. /* tsensor.temp->status is brd_temp status */
  4157. diag->tsensor.temp->status = rsp->status;
  4158. if (rsp->status == BFA_STATUS_OK) {
  4159. diag->tsensor.temp->brd_temp =
  4160. be16_to_cpu(rsp->brd_temp);
  4161. } else
  4162. diag->tsensor.temp->brd_temp = 0;
  4163. }
  4164. bfa_trc(diag, rsp->status);
  4165. bfa_trc(diag, rsp->ts_junc);
  4166. bfa_trc(diag, rsp->temp);
  4167. bfa_trc(diag, rsp->ts_brd);
  4168. bfa_trc(diag, rsp->brd_temp);
  4169. /* tsensor status is always good bcos we always have junction temp */
  4170. diag->tsensor.status = BFA_STATUS_OK;
  4171. diag->tsensor.cbfn(diag->tsensor.cbarg, diag->tsensor.status);
  4172. diag->tsensor.lock = 0;
  4173. }
  4174. /*
  4175. * LED Test command
  4176. */
  4177. static void
  4178. diag_ledtest_send(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest)
  4179. {
  4180. struct bfi_diag_ledtest_req_s *msg;
  4181. msg = (struct bfi_diag_ledtest_req_s *)diag->ledtest.mbcmd.msg;
  4182. /* build host command */
  4183. bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LEDTEST,
  4184. bfa_ioc_portid(diag->ioc));
  4185. /*
  4186. * convert the freq from N blinks per 10 sec to
  4187. * crossbow ontime value. We do it here because division is need
  4188. */
  4189. if (ledtest->freq)
  4190. ledtest->freq = 500 / ledtest->freq;
  4191. if (ledtest->freq == 0)
  4192. ledtest->freq = 1;
  4193. bfa_trc(diag, ledtest->freq);
  4194. /* mcpy(&ledtest_req->req, ledtest, sizeof(bfa_diag_ledtest_t)); */
  4195. msg->cmd = (u8) ledtest->cmd;
  4196. msg->color = (u8) ledtest->color;
  4197. msg->portid = bfa_ioc_portid(diag->ioc);
  4198. msg->led = ledtest->led;
  4199. msg->freq = cpu_to_be16(ledtest->freq);
  4200. /* send mbox cmd */
  4201. bfa_ioc_mbox_queue(diag->ioc, &diag->ledtest.mbcmd);
  4202. }
  4203. static void
  4204. diag_ledtest_comp(struct bfa_diag_s *diag, struct bfi_diag_ledtest_rsp_s *msg)
  4205. {
  4206. bfa_trc(diag, diag->ledtest.lock);
  4207. diag->ledtest.lock = BFA_FALSE;
  4208. /* no bfa_cb_queue is needed because driver is not waiting */
  4209. }
  4210. /*
  4211. * Port beaconing
  4212. */
  4213. static void
  4214. diag_portbeacon_send(struct bfa_diag_s *diag, bfa_boolean_t beacon, u32 sec)
  4215. {
  4216. struct bfi_diag_portbeacon_req_s *msg;
  4217. msg = (struct bfi_diag_portbeacon_req_s *)diag->beacon.mbcmd.msg;
  4218. /* build host command */
  4219. bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_PORTBEACON,
  4220. bfa_ioc_portid(diag->ioc));
  4221. msg->beacon = beacon;
  4222. msg->period = cpu_to_be32(sec);
  4223. /* send mbox cmd */
  4224. bfa_ioc_mbox_queue(diag->ioc, &diag->beacon.mbcmd);
  4225. }
  4226. static void
  4227. diag_portbeacon_comp(struct bfa_diag_s *diag)
  4228. {
  4229. bfa_trc(diag, diag->beacon.state);
  4230. diag->beacon.state = BFA_FALSE;
  4231. if (diag->cbfn_beacon)
  4232. diag->cbfn_beacon(diag->dev, BFA_FALSE, diag->beacon.link_e2e);
  4233. }
  4234. /*
  4235. * Diag hmbox handler
  4236. */
  4237. static void
  4238. bfa_diag_intr(void *diagarg, struct bfi_mbmsg_s *msg)
  4239. {
  4240. struct bfa_diag_s *diag = diagarg;
  4241. switch (msg->mh.msg_id) {
  4242. case BFI_DIAG_I2H_PORTBEACON:
  4243. diag_portbeacon_comp(diag);
  4244. break;
  4245. case BFI_DIAG_I2H_FWPING:
  4246. diag_fwping_comp(diag, (struct bfi_diag_fwping_rsp_s *) msg);
  4247. break;
  4248. case BFI_DIAG_I2H_TEMPSENSOR:
  4249. diag_tempsensor_comp(diag, (bfi_diag_ts_rsp_t *) msg);
  4250. break;
  4251. case BFI_DIAG_I2H_LEDTEST:
  4252. diag_ledtest_comp(diag, (struct bfi_diag_ledtest_rsp_s *) msg);
  4253. break;
  4254. default:
  4255. bfa_trc(diag, msg->mh.msg_id);
  4256. WARN_ON(1);
  4257. }
  4258. }
  4259. /*
  4260. * Gen RAM Test
  4261. *
  4262. * @param[in] *diag - diag data struct
  4263. * @param[in] *memtest - mem test params input from upper layer,
  4264. * @param[in] pattern - mem test pattern
  4265. * @param[in] *result - mem test result
  4266. * @param[in] cbfn - mem test callback functioin
  4267. * @param[in] cbarg - callback functioin arg
  4268. *
  4269. * @param[out]
  4270. */
  4271. bfa_status_t
  4272. bfa_diag_memtest(struct bfa_diag_s *diag, struct bfa_diag_memtest_s *memtest,
  4273. u32 pattern, struct bfa_diag_memtest_result *result,
  4274. bfa_cb_diag_t cbfn, void *cbarg)
  4275. {
  4276. u32 memtest_tov;
  4277. bfa_trc(diag, pattern);
  4278. if (!bfa_ioc_adapter_is_disabled(diag->ioc))
  4279. return BFA_STATUS_ADAPTER_ENABLED;
  4280. /* check to see if there is another destructive diag cmd running */
  4281. if (diag->block) {
  4282. bfa_trc(diag, diag->block);
  4283. return BFA_STATUS_DEVBUSY;
  4284. } else
  4285. diag->block = 1;
  4286. diag->result = result;
  4287. diag->cbfn = cbfn;
  4288. diag->cbarg = cbarg;
  4289. /* download memtest code and take LPU0 out of reset */
  4290. bfa_ioc_boot(diag->ioc, BFI_FWBOOT_TYPE_MEMTEST, BFI_FWBOOT_ENV_OS);
  4291. memtest_tov = (bfa_ioc_asic_gen(diag->ioc) == BFI_ASIC_GEN_CT2) ?
  4292. CT2_BFA_DIAG_MEMTEST_TOV : BFA_DIAG_MEMTEST_TOV;
  4293. bfa_timer_begin(diag->ioc->timer_mod, &diag->timer,
  4294. bfa_diag_memtest_done, diag, memtest_tov);
  4295. diag->timer_active = 1;
  4296. return BFA_STATUS_OK;
  4297. }
  4298. /*
  4299. * DIAG firmware ping command
  4300. *
  4301. * @param[in] *diag - diag data struct
  4302. * @param[in] cnt - dma loop count for testing PCIE
  4303. * @param[in] data - data pattern to pass in fw
  4304. * @param[in] *result - pt to bfa_diag_fwping_result_t data struct
  4305. * @param[in] cbfn - callback function
  4306. * @param[in] *cbarg - callback functioin arg
  4307. *
  4308. * @param[out]
  4309. */
  4310. bfa_status_t
  4311. bfa_diag_fwping(struct bfa_diag_s *diag, u32 cnt, u32 data,
  4312. struct bfa_diag_results_fwping *result, bfa_cb_diag_t cbfn,
  4313. void *cbarg)
  4314. {
  4315. bfa_trc(diag, cnt);
  4316. bfa_trc(diag, data);
  4317. if (!bfa_ioc_is_operational(diag->ioc))
  4318. return BFA_STATUS_IOC_NON_OP;
  4319. if (bfa_asic_id_ct2(bfa_ioc_devid((diag->ioc))) &&
  4320. ((diag->ioc)->clscode == BFI_PCIFN_CLASS_ETH))
  4321. return BFA_STATUS_CMD_NOTSUPP;
  4322. /* check to see if there is another destructive diag cmd running */
  4323. if (diag->block || diag->fwping.lock) {
  4324. bfa_trc(diag, diag->block);
  4325. bfa_trc(diag, diag->fwping.lock);
  4326. return BFA_STATUS_DEVBUSY;
  4327. }
  4328. /* Initialization */
  4329. diag->fwping.lock = 1;
  4330. diag->fwping.cbfn = cbfn;
  4331. diag->fwping.cbarg = cbarg;
  4332. diag->fwping.result = result;
  4333. diag->fwping.data = data;
  4334. diag->fwping.count = cnt;
  4335. /* Init test results */
  4336. diag->fwping.result->data = 0;
  4337. diag->fwping.result->status = BFA_STATUS_OK;
  4338. /* kick off the first ping */
  4339. diag_fwping_send(diag);
  4340. return BFA_STATUS_OK;
  4341. }
  4342. /*
  4343. * Read Temperature Sensor
  4344. *
  4345. * @param[in] *diag - diag data struct
  4346. * @param[in] *result - pt to bfa_diag_temp_t data struct
  4347. * @param[in] cbfn - callback function
  4348. * @param[in] *cbarg - callback functioin arg
  4349. *
  4350. * @param[out]
  4351. */
  4352. bfa_status_t
  4353. bfa_diag_tsensor_query(struct bfa_diag_s *diag,
  4354. struct bfa_diag_results_tempsensor_s *result,
  4355. bfa_cb_diag_t cbfn, void *cbarg)
  4356. {
  4357. /* check to see if there is a destructive diag cmd running */
  4358. if (diag->block || diag->tsensor.lock) {
  4359. bfa_trc(diag, diag->block);
  4360. bfa_trc(diag, diag->tsensor.lock);
  4361. return BFA_STATUS_DEVBUSY;
  4362. }
  4363. if (!bfa_ioc_is_operational(diag->ioc))
  4364. return BFA_STATUS_IOC_NON_OP;
  4365. /* Init diag mod params */
  4366. diag->tsensor.lock = 1;
  4367. diag->tsensor.temp = result;
  4368. diag->tsensor.cbfn = cbfn;
  4369. diag->tsensor.cbarg = cbarg;
  4370. diag->tsensor.status = BFA_STATUS_OK;
  4371. /* Send msg to fw */
  4372. diag_tempsensor_send(diag);
  4373. return BFA_STATUS_OK;
  4374. }
  4375. /*
  4376. * LED Test command
  4377. *
  4378. * @param[in] *diag - diag data struct
  4379. * @param[in] *ledtest - pt to ledtest data structure
  4380. *
  4381. * @param[out]
  4382. */
  4383. bfa_status_t
  4384. bfa_diag_ledtest(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest)
  4385. {
  4386. bfa_trc(diag, ledtest->cmd);
  4387. if (!bfa_ioc_is_operational(diag->ioc))
  4388. return BFA_STATUS_IOC_NON_OP;
  4389. if (diag->beacon.state)
  4390. return BFA_STATUS_BEACON_ON;
  4391. if (diag->ledtest.lock)
  4392. return BFA_STATUS_LEDTEST_OP;
  4393. /* Send msg to fw */
  4394. diag->ledtest.lock = BFA_TRUE;
  4395. diag_ledtest_send(diag, ledtest);
  4396. return BFA_STATUS_OK;
  4397. }
  4398. /*
  4399. * Port beaconing command
  4400. *
  4401. * @param[in] *diag - diag data struct
  4402. * @param[in] beacon - port beaconing 1:ON 0:OFF
  4403. * @param[in] link_e2e_beacon - link beaconing 1:ON 0:OFF
  4404. * @param[in] sec - beaconing duration in seconds
  4405. *
  4406. * @param[out]
  4407. */
  4408. bfa_status_t
  4409. bfa_diag_beacon_port(struct bfa_diag_s *diag, bfa_boolean_t beacon,
  4410. bfa_boolean_t link_e2e_beacon, uint32_t sec)
  4411. {
  4412. bfa_trc(diag, beacon);
  4413. bfa_trc(diag, link_e2e_beacon);
  4414. bfa_trc(diag, sec);
  4415. if (!bfa_ioc_is_operational(diag->ioc))
  4416. return BFA_STATUS_IOC_NON_OP;
  4417. if (diag->ledtest.lock)
  4418. return BFA_STATUS_LEDTEST_OP;
  4419. if (diag->beacon.state && beacon) /* beacon alread on */
  4420. return BFA_STATUS_BEACON_ON;
  4421. diag->beacon.state = beacon;
  4422. diag->beacon.link_e2e = link_e2e_beacon;
  4423. if (diag->cbfn_beacon)
  4424. diag->cbfn_beacon(diag->dev, beacon, link_e2e_beacon);
  4425. /* Send msg to fw */
  4426. diag_portbeacon_send(diag, beacon, sec);
  4427. return BFA_STATUS_OK;
  4428. }
  4429. /*
  4430. * Return DMA memory needed by diag module.
  4431. */
  4432. u32
  4433. bfa_diag_meminfo(void)
  4434. {
  4435. return BFA_ROUNDUP(BFI_DIAG_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  4436. }
  4437. /*
  4438. * Attach virtual and physical memory for Diag.
  4439. */
  4440. void
  4441. bfa_diag_attach(struct bfa_diag_s *diag, struct bfa_ioc_s *ioc, void *dev,
  4442. bfa_cb_diag_beacon_t cbfn_beacon, struct bfa_trc_mod_s *trcmod)
  4443. {
  4444. diag->dev = dev;
  4445. diag->ioc = ioc;
  4446. diag->trcmod = trcmod;
  4447. diag->block = 0;
  4448. diag->cbfn = NULL;
  4449. diag->cbarg = NULL;
  4450. diag->result = NULL;
  4451. diag->cbfn_beacon = cbfn_beacon;
  4452. bfa_ioc_mbox_regisr(diag->ioc, BFI_MC_DIAG, bfa_diag_intr, diag);
  4453. bfa_q_qe_init(&diag->ioc_notify);
  4454. bfa_ioc_notify_init(&diag->ioc_notify, bfa_diag_notify, diag);
  4455. list_add_tail(&diag->ioc_notify.qe, &diag->ioc->notify_q);
  4456. }
  4457. void
  4458. bfa_diag_memclaim(struct bfa_diag_s *diag, u8 *dm_kva, u64 dm_pa)
  4459. {
  4460. diag->fwping.dbuf_kva = dm_kva;
  4461. diag->fwping.dbuf_pa = dm_pa;
  4462. memset(diag->fwping.dbuf_kva, 0, BFI_DIAG_DMA_BUF_SZ);
  4463. }
  4464. /*
  4465. * PHY module specific
  4466. */
  4467. #define BFA_PHY_DMA_BUF_SZ 0x02000 /* 8k dma buffer */
  4468. #define BFA_PHY_LOCK_STATUS 0x018878 /* phy semaphore status reg */
  4469. static void
  4470. bfa_phy_ntoh32(u32 *obuf, u32 *ibuf, int sz)
  4471. {
  4472. int i, m = sz >> 2;
  4473. for (i = 0; i < m; i++)
  4474. obuf[i] = be32_to_cpu(ibuf[i]);
  4475. }
  4476. static bfa_boolean_t
  4477. bfa_phy_present(struct bfa_phy_s *phy)
  4478. {
  4479. return (phy->ioc->attr->card_type == BFA_MFG_TYPE_LIGHTNING);
  4480. }
  4481. static void
  4482. bfa_phy_notify(void *cbarg, enum bfa_ioc_event_e event)
  4483. {
  4484. struct bfa_phy_s *phy = cbarg;
  4485. bfa_trc(phy, event);
  4486. switch (event) {
  4487. case BFA_IOC_E_DISABLED:
  4488. case BFA_IOC_E_FAILED:
  4489. if (phy->op_busy) {
  4490. phy->status = BFA_STATUS_IOC_FAILURE;
  4491. phy->cbfn(phy->cbarg, phy->status);
  4492. phy->op_busy = 0;
  4493. }
  4494. break;
  4495. default:
  4496. break;
  4497. }
  4498. }
  4499. /*
  4500. * Send phy attribute query request.
  4501. *
  4502. * @param[in] cbarg - callback argument
  4503. */
  4504. static void
  4505. bfa_phy_query_send(void *cbarg)
  4506. {
  4507. struct bfa_phy_s *phy = cbarg;
  4508. struct bfi_phy_query_req_s *msg =
  4509. (struct bfi_phy_query_req_s *) phy->mb.msg;
  4510. msg->instance = phy->instance;
  4511. bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_QUERY_REQ,
  4512. bfa_ioc_portid(phy->ioc));
  4513. bfa_alen_set(&msg->alen, sizeof(struct bfa_phy_attr_s), phy->dbuf_pa);
  4514. bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
  4515. }
  4516. /*
  4517. * Send phy write request.
  4518. *
  4519. * @param[in] cbarg - callback argument
  4520. */
  4521. static void
  4522. bfa_phy_write_send(void *cbarg)
  4523. {
  4524. struct bfa_phy_s *phy = cbarg;
  4525. struct bfi_phy_write_req_s *msg =
  4526. (struct bfi_phy_write_req_s *) phy->mb.msg;
  4527. u32 len;
  4528. u16 *buf, *dbuf;
  4529. int i, sz;
  4530. msg->instance = phy->instance;
  4531. msg->offset = cpu_to_be32(phy->addr_off + phy->offset);
  4532. len = (phy->residue < BFA_PHY_DMA_BUF_SZ) ?
  4533. phy->residue : BFA_PHY_DMA_BUF_SZ;
  4534. msg->length = cpu_to_be32(len);
  4535. /* indicate if it's the last msg of the whole write operation */
  4536. msg->last = (len == phy->residue) ? 1 : 0;
  4537. bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_WRITE_REQ,
  4538. bfa_ioc_portid(phy->ioc));
  4539. bfa_alen_set(&msg->alen, len, phy->dbuf_pa);
  4540. buf = (u16 *) (phy->ubuf + phy->offset);
  4541. dbuf = (u16 *)phy->dbuf_kva;
  4542. sz = len >> 1;
  4543. for (i = 0; i < sz; i++)
  4544. buf[i] = cpu_to_be16(dbuf[i]);
  4545. bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
  4546. phy->residue -= len;
  4547. phy->offset += len;
  4548. }
  4549. /*
  4550. * Send phy read request.
  4551. *
  4552. * @param[in] cbarg - callback argument
  4553. */
  4554. static void
  4555. bfa_phy_read_send(void *cbarg)
  4556. {
  4557. struct bfa_phy_s *phy = cbarg;
  4558. struct bfi_phy_read_req_s *msg =
  4559. (struct bfi_phy_read_req_s *) phy->mb.msg;
  4560. u32 len;
  4561. msg->instance = phy->instance;
  4562. msg->offset = cpu_to_be32(phy->addr_off + phy->offset);
  4563. len = (phy->residue < BFA_PHY_DMA_BUF_SZ) ?
  4564. phy->residue : BFA_PHY_DMA_BUF_SZ;
  4565. msg->length = cpu_to_be32(len);
  4566. bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_READ_REQ,
  4567. bfa_ioc_portid(phy->ioc));
  4568. bfa_alen_set(&msg->alen, len, phy->dbuf_pa);
  4569. bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
  4570. }
  4571. /*
  4572. * Send phy stats request.
  4573. *
  4574. * @param[in] cbarg - callback argument
  4575. */
  4576. static void
  4577. bfa_phy_stats_send(void *cbarg)
  4578. {
  4579. struct bfa_phy_s *phy = cbarg;
  4580. struct bfi_phy_stats_req_s *msg =
  4581. (struct bfi_phy_stats_req_s *) phy->mb.msg;
  4582. msg->instance = phy->instance;
  4583. bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_STATS_REQ,
  4584. bfa_ioc_portid(phy->ioc));
  4585. bfa_alen_set(&msg->alen, sizeof(struct bfa_phy_stats_s), phy->dbuf_pa);
  4586. bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
  4587. }
  4588. /*
  4589. * Flash memory info API.
  4590. *
  4591. * @param[in] mincfg - minimal cfg variable
  4592. */
  4593. u32
  4594. bfa_phy_meminfo(bfa_boolean_t mincfg)
  4595. {
  4596. /* min driver doesn't need phy */
  4597. if (mincfg)
  4598. return 0;
  4599. return BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  4600. }
  4601. /*
  4602. * Flash attach API.
  4603. *
  4604. * @param[in] phy - phy structure
  4605. * @param[in] ioc - ioc structure
  4606. * @param[in] dev - device structure
  4607. * @param[in] trcmod - trace module
  4608. * @param[in] logmod - log module
  4609. */
  4610. void
  4611. bfa_phy_attach(struct bfa_phy_s *phy, struct bfa_ioc_s *ioc, void *dev,
  4612. struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
  4613. {
  4614. phy->ioc = ioc;
  4615. phy->trcmod = trcmod;
  4616. phy->cbfn = NULL;
  4617. phy->cbarg = NULL;
  4618. phy->op_busy = 0;
  4619. bfa_ioc_mbox_regisr(phy->ioc, BFI_MC_PHY, bfa_phy_intr, phy);
  4620. bfa_q_qe_init(&phy->ioc_notify);
  4621. bfa_ioc_notify_init(&phy->ioc_notify, bfa_phy_notify, phy);
  4622. list_add_tail(&phy->ioc_notify.qe, &phy->ioc->notify_q);
  4623. /* min driver doesn't need phy */
  4624. if (mincfg) {
  4625. phy->dbuf_kva = NULL;
  4626. phy->dbuf_pa = 0;
  4627. }
  4628. }
  4629. /*
  4630. * Claim memory for phy
  4631. *
  4632. * @param[in] phy - phy structure
  4633. * @param[in] dm_kva - pointer to virtual memory address
  4634. * @param[in] dm_pa - physical memory address
  4635. * @param[in] mincfg - minimal cfg variable
  4636. */
  4637. void
  4638. bfa_phy_memclaim(struct bfa_phy_s *phy, u8 *dm_kva, u64 dm_pa,
  4639. bfa_boolean_t mincfg)
  4640. {
  4641. if (mincfg)
  4642. return;
  4643. phy->dbuf_kva = dm_kva;
  4644. phy->dbuf_pa = dm_pa;
  4645. memset(phy->dbuf_kva, 0, BFA_PHY_DMA_BUF_SZ);
  4646. dm_kva += BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  4647. dm_pa += BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  4648. }
  4649. bfa_boolean_t
  4650. bfa_phy_busy(struct bfa_ioc_s *ioc)
  4651. {
  4652. void __iomem *rb;
  4653. rb = bfa_ioc_bar0(ioc);
  4654. return readl(rb + BFA_PHY_LOCK_STATUS);
  4655. }
  4656. /*
  4657. * Get phy attribute.
  4658. *
  4659. * @param[in] phy - phy structure
  4660. * @param[in] attr - phy attribute structure
  4661. * @param[in] cbfn - callback function
  4662. * @param[in] cbarg - callback argument
  4663. *
  4664. * Return status.
  4665. */
  4666. bfa_status_t
  4667. bfa_phy_get_attr(struct bfa_phy_s *phy, u8 instance,
  4668. struct bfa_phy_attr_s *attr, bfa_cb_phy_t cbfn, void *cbarg)
  4669. {
  4670. bfa_trc(phy, BFI_PHY_H2I_QUERY_REQ);
  4671. bfa_trc(phy, instance);
  4672. if (!bfa_phy_present(phy))
  4673. return BFA_STATUS_PHY_NOT_PRESENT;
  4674. if (!bfa_ioc_is_operational(phy->ioc))
  4675. return BFA_STATUS_IOC_NON_OP;
  4676. if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
  4677. bfa_trc(phy, phy->op_busy);
  4678. return BFA_STATUS_DEVBUSY;
  4679. }
  4680. phy->op_busy = 1;
  4681. phy->cbfn = cbfn;
  4682. phy->cbarg = cbarg;
  4683. phy->instance = instance;
  4684. phy->ubuf = (uint8_t *) attr;
  4685. bfa_phy_query_send(phy);
  4686. return BFA_STATUS_OK;
  4687. }
  4688. /*
  4689. * Get phy stats.
  4690. *
  4691. * @param[in] phy - phy structure
  4692. * @param[in] instance - phy image instance
  4693. * @param[in] stats - pointer to phy stats
  4694. * @param[in] cbfn - callback function
  4695. * @param[in] cbarg - callback argument
  4696. *
  4697. * Return status.
  4698. */
  4699. bfa_status_t
  4700. bfa_phy_get_stats(struct bfa_phy_s *phy, u8 instance,
  4701. struct bfa_phy_stats_s *stats,
  4702. bfa_cb_phy_t cbfn, void *cbarg)
  4703. {
  4704. bfa_trc(phy, BFI_PHY_H2I_STATS_REQ);
  4705. bfa_trc(phy, instance);
  4706. if (!bfa_phy_present(phy))
  4707. return BFA_STATUS_PHY_NOT_PRESENT;
  4708. if (!bfa_ioc_is_operational(phy->ioc))
  4709. return BFA_STATUS_IOC_NON_OP;
  4710. if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
  4711. bfa_trc(phy, phy->op_busy);
  4712. return BFA_STATUS_DEVBUSY;
  4713. }
  4714. phy->op_busy = 1;
  4715. phy->cbfn = cbfn;
  4716. phy->cbarg = cbarg;
  4717. phy->instance = instance;
  4718. phy->ubuf = (u8 *) stats;
  4719. bfa_phy_stats_send(phy);
  4720. return BFA_STATUS_OK;
  4721. }
  4722. /*
  4723. * Update phy image.
  4724. *
  4725. * @param[in] phy - phy structure
  4726. * @param[in] instance - phy image instance
  4727. * @param[in] buf - update data buffer
  4728. * @param[in] len - data buffer length
  4729. * @param[in] offset - offset relative to starting address
  4730. * @param[in] cbfn - callback function
  4731. * @param[in] cbarg - callback argument
  4732. *
  4733. * Return status.
  4734. */
  4735. bfa_status_t
  4736. bfa_phy_update(struct bfa_phy_s *phy, u8 instance,
  4737. void *buf, u32 len, u32 offset,
  4738. bfa_cb_phy_t cbfn, void *cbarg)
  4739. {
  4740. bfa_trc(phy, BFI_PHY_H2I_WRITE_REQ);
  4741. bfa_trc(phy, instance);
  4742. bfa_trc(phy, len);
  4743. bfa_trc(phy, offset);
  4744. if (!bfa_phy_present(phy))
  4745. return BFA_STATUS_PHY_NOT_PRESENT;
  4746. if (!bfa_ioc_is_operational(phy->ioc))
  4747. return BFA_STATUS_IOC_NON_OP;
  4748. /* 'len' must be in word (4-byte) boundary */
  4749. if (!len || (len & 0x03))
  4750. return BFA_STATUS_FAILED;
  4751. if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
  4752. bfa_trc(phy, phy->op_busy);
  4753. return BFA_STATUS_DEVBUSY;
  4754. }
  4755. phy->op_busy = 1;
  4756. phy->cbfn = cbfn;
  4757. phy->cbarg = cbarg;
  4758. phy->instance = instance;
  4759. phy->residue = len;
  4760. phy->offset = 0;
  4761. phy->addr_off = offset;
  4762. phy->ubuf = buf;
  4763. bfa_phy_write_send(phy);
  4764. return BFA_STATUS_OK;
  4765. }
  4766. /*
  4767. * Read phy image.
  4768. *
  4769. * @param[in] phy - phy structure
  4770. * @param[in] instance - phy image instance
  4771. * @param[in] buf - read data buffer
  4772. * @param[in] len - data buffer length
  4773. * @param[in] offset - offset relative to starting address
  4774. * @param[in] cbfn - callback function
  4775. * @param[in] cbarg - callback argument
  4776. *
  4777. * Return status.
  4778. */
  4779. bfa_status_t
  4780. bfa_phy_read(struct bfa_phy_s *phy, u8 instance,
  4781. void *buf, u32 len, u32 offset,
  4782. bfa_cb_phy_t cbfn, void *cbarg)
  4783. {
  4784. bfa_trc(phy, BFI_PHY_H2I_READ_REQ);
  4785. bfa_trc(phy, instance);
  4786. bfa_trc(phy, len);
  4787. bfa_trc(phy, offset);
  4788. if (!bfa_phy_present(phy))
  4789. return BFA_STATUS_PHY_NOT_PRESENT;
  4790. if (!bfa_ioc_is_operational(phy->ioc))
  4791. return BFA_STATUS_IOC_NON_OP;
  4792. /* 'len' must be in word (4-byte) boundary */
  4793. if (!len || (len & 0x03))
  4794. return BFA_STATUS_FAILED;
  4795. if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
  4796. bfa_trc(phy, phy->op_busy);
  4797. return BFA_STATUS_DEVBUSY;
  4798. }
  4799. phy->op_busy = 1;
  4800. phy->cbfn = cbfn;
  4801. phy->cbarg = cbarg;
  4802. phy->instance = instance;
  4803. phy->residue = len;
  4804. phy->offset = 0;
  4805. phy->addr_off = offset;
  4806. phy->ubuf = buf;
  4807. bfa_phy_read_send(phy);
  4808. return BFA_STATUS_OK;
  4809. }
  4810. /*
  4811. * Process phy response messages upon receiving interrupts.
  4812. *
  4813. * @param[in] phyarg - phy structure
  4814. * @param[in] msg - message structure
  4815. */
  4816. void
  4817. bfa_phy_intr(void *phyarg, struct bfi_mbmsg_s *msg)
  4818. {
  4819. struct bfa_phy_s *phy = phyarg;
  4820. u32 status;
  4821. union {
  4822. struct bfi_phy_query_rsp_s *query;
  4823. struct bfi_phy_stats_rsp_s *stats;
  4824. struct bfi_phy_write_rsp_s *write;
  4825. struct bfi_phy_read_rsp_s *read;
  4826. struct bfi_mbmsg_s *msg;
  4827. } m;
  4828. m.msg = msg;
  4829. bfa_trc(phy, msg->mh.msg_id);
  4830. if (!phy->op_busy) {
  4831. /* receiving response after ioc failure */
  4832. bfa_trc(phy, 0x9999);
  4833. return;
  4834. }
  4835. switch (msg->mh.msg_id) {
  4836. case BFI_PHY_I2H_QUERY_RSP:
  4837. status = be32_to_cpu(m.query->status);
  4838. bfa_trc(phy, status);
  4839. if (status == BFA_STATUS_OK) {
  4840. struct bfa_phy_attr_s *attr =
  4841. (struct bfa_phy_attr_s *) phy->ubuf;
  4842. bfa_phy_ntoh32((u32 *)attr, (u32 *)phy->dbuf_kva,
  4843. sizeof(struct bfa_phy_attr_s));
  4844. bfa_trc(phy, attr->status);
  4845. bfa_trc(phy, attr->length);
  4846. }
  4847. phy->status = status;
  4848. phy->op_busy = 0;
  4849. if (phy->cbfn)
  4850. phy->cbfn(phy->cbarg, phy->status);
  4851. break;
  4852. case BFI_PHY_I2H_STATS_RSP:
  4853. status = be32_to_cpu(m.stats->status);
  4854. bfa_trc(phy, status);
  4855. if (status == BFA_STATUS_OK) {
  4856. struct bfa_phy_stats_s *stats =
  4857. (struct bfa_phy_stats_s *) phy->ubuf;
  4858. bfa_phy_ntoh32((u32 *)stats, (u32 *)phy->dbuf_kva,
  4859. sizeof(struct bfa_phy_stats_s));
  4860. bfa_trc(phy, stats->status);
  4861. }
  4862. phy->status = status;
  4863. phy->op_busy = 0;
  4864. if (phy->cbfn)
  4865. phy->cbfn(phy->cbarg, phy->status);
  4866. break;
  4867. case BFI_PHY_I2H_WRITE_RSP:
  4868. status = be32_to_cpu(m.write->status);
  4869. bfa_trc(phy, status);
  4870. if (status != BFA_STATUS_OK || phy->residue == 0) {
  4871. phy->status = status;
  4872. phy->op_busy = 0;
  4873. if (phy->cbfn)
  4874. phy->cbfn(phy->cbarg, phy->status);
  4875. } else {
  4876. bfa_trc(phy, phy->offset);
  4877. bfa_phy_write_send(phy);
  4878. }
  4879. break;
  4880. case BFI_PHY_I2H_READ_RSP:
  4881. status = be32_to_cpu(m.read->status);
  4882. bfa_trc(phy, status);
  4883. if (status != BFA_STATUS_OK) {
  4884. phy->status = status;
  4885. phy->op_busy = 0;
  4886. if (phy->cbfn)
  4887. phy->cbfn(phy->cbarg, phy->status);
  4888. } else {
  4889. u32 len = be32_to_cpu(m.read->length);
  4890. u16 *buf = (u16 *)(phy->ubuf + phy->offset);
  4891. u16 *dbuf = (u16 *)phy->dbuf_kva;
  4892. int i, sz = len >> 1;
  4893. bfa_trc(phy, phy->offset);
  4894. bfa_trc(phy, len);
  4895. for (i = 0; i < sz; i++)
  4896. buf[i] = be16_to_cpu(dbuf[i]);
  4897. phy->residue -= len;
  4898. phy->offset += len;
  4899. if (phy->residue == 0) {
  4900. phy->status = status;
  4901. phy->op_busy = 0;
  4902. if (phy->cbfn)
  4903. phy->cbfn(phy->cbarg, phy->status);
  4904. } else
  4905. bfa_phy_read_send(phy);
  4906. }
  4907. break;
  4908. default:
  4909. WARN_ON(1);
  4910. }
  4911. }
  4912. /* forward declaration of DCONF state machine */
  4913. static void bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf,
  4914. enum bfa_dconf_event event);
  4915. static void bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf,
  4916. enum bfa_dconf_event event);
  4917. static void bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf,
  4918. enum bfa_dconf_event event);
  4919. static void bfa_dconf_sm_dirty(struct bfa_dconf_mod_s *dconf,
  4920. enum bfa_dconf_event event);
  4921. static void bfa_dconf_sm_sync(struct bfa_dconf_mod_s *dconf,
  4922. enum bfa_dconf_event event);
  4923. static void bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf,
  4924. enum bfa_dconf_event event);
  4925. static void bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf,
  4926. enum bfa_dconf_event event);
  4927. static void bfa_dconf_cbfn(void *dconf, bfa_status_t status);
  4928. static void bfa_dconf_timer(void *cbarg);
  4929. static bfa_status_t bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf);
  4930. static void bfa_dconf_init_cb(void *arg, bfa_status_t status);
  4931. /*
  4932. * Beginning state of dconf module. Waiting for an event to start.
  4933. */
  4934. static void
  4935. bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
  4936. {
  4937. bfa_status_t bfa_status;
  4938. bfa_trc(dconf->bfa, event);
  4939. switch (event) {
  4940. case BFA_DCONF_SM_INIT:
  4941. if (dconf->min_cfg) {
  4942. bfa_trc(dconf->bfa, dconf->min_cfg);
  4943. bfa_fsm_send_event(&dconf->bfa->iocfc,
  4944. IOCFC_E_DCONF_DONE);
  4945. return;
  4946. }
  4947. bfa_sm_set_state(dconf, bfa_dconf_sm_flash_read);
  4948. bfa_timer_start(dconf->bfa, &dconf->timer,
  4949. bfa_dconf_timer, dconf, 2 * BFA_DCONF_UPDATE_TOV);
  4950. bfa_status = bfa_flash_read_part(BFA_FLASH(dconf->bfa),
  4951. BFA_FLASH_PART_DRV, dconf->instance,
  4952. dconf->dconf,
  4953. sizeof(struct bfa_dconf_s), 0,
  4954. bfa_dconf_init_cb, dconf->bfa);
  4955. if (bfa_status != BFA_STATUS_OK) {
  4956. bfa_timer_stop(&dconf->timer);
  4957. bfa_dconf_init_cb(dconf->bfa, BFA_STATUS_FAILED);
  4958. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4959. return;
  4960. }
  4961. break;
  4962. case BFA_DCONF_SM_EXIT:
  4963. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  4964. break;
  4965. case BFA_DCONF_SM_IOCDISABLE:
  4966. case BFA_DCONF_SM_WR:
  4967. case BFA_DCONF_SM_FLASH_COMP:
  4968. break;
  4969. default:
  4970. bfa_sm_fault(dconf->bfa, event);
  4971. }
  4972. }
  4973. /*
  4974. * Read flash for dconf entries and make a call back to the driver once done.
  4975. */
  4976. static void
  4977. bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf,
  4978. enum bfa_dconf_event event)
  4979. {
  4980. bfa_trc(dconf->bfa, event);
  4981. switch (event) {
  4982. case BFA_DCONF_SM_FLASH_COMP:
  4983. bfa_timer_stop(&dconf->timer);
  4984. bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
  4985. break;
  4986. case BFA_DCONF_SM_TIMEOUT:
  4987. bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
  4988. bfa_ioc_suspend(&dconf->bfa->ioc);
  4989. break;
  4990. case BFA_DCONF_SM_EXIT:
  4991. bfa_timer_stop(&dconf->timer);
  4992. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4993. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  4994. break;
  4995. case BFA_DCONF_SM_IOCDISABLE:
  4996. bfa_timer_stop(&dconf->timer);
  4997. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  4998. break;
  4999. default:
  5000. bfa_sm_fault(dconf->bfa, event);
  5001. }
  5002. }
  5003. /*
  5004. * DCONF Module is in ready state. Has completed the initialization.
  5005. */
  5006. static void
  5007. bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
  5008. {
  5009. bfa_trc(dconf->bfa, event);
  5010. switch (event) {
  5011. case BFA_DCONF_SM_WR:
  5012. bfa_timer_start(dconf->bfa, &dconf->timer,
  5013. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  5014. bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
  5015. break;
  5016. case BFA_DCONF_SM_EXIT:
  5017. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  5018. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  5019. break;
  5020. case BFA_DCONF_SM_INIT:
  5021. case BFA_DCONF_SM_IOCDISABLE:
  5022. break;
  5023. default:
  5024. bfa_sm_fault(dconf->bfa, event);
  5025. }
  5026. }
  5027. /*
  5028. * entries are dirty, write back to the flash.
  5029. */
  5030. static void
  5031. bfa_dconf_sm_dirty(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
  5032. {
  5033. bfa_trc(dconf->bfa, event);
  5034. switch (event) {
  5035. case BFA_DCONF_SM_TIMEOUT:
  5036. bfa_sm_set_state(dconf, bfa_dconf_sm_sync);
  5037. bfa_dconf_flash_write(dconf);
  5038. break;
  5039. case BFA_DCONF_SM_WR:
  5040. bfa_timer_stop(&dconf->timer);
  5041. bfa_timer_start(dconf->bfa, &dconf->timer,
  5042. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  5043. break;
  5044. case BFA_DCONF_SM_EXIT:
  5045. bfa_timer_stop(&dconf->timer);
  5046. bfa_timer_start(dconf->bfa, &dconf->timer,
  5047. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  5048. bfa_sm_set_state(dconf, bfa_dconf_sm_final_sync);
  5049. bfa_dconf_flash_write(dconf);
  5050. break;
  5051. case BFA_DCONF_SM_FLASH_COMP:
  5052. break;
  5053. case BFA_DCONF_SM_IOCDISABLE:
  5054. bfa_timer_stop(&dconf->timer);
  5055. bfa_sm_set_state(dconf, bfa_dconf_sm_iocdown_dirty);
  5056. break;
  5057. default:
  5058. bfa_sm_fault(dconf->bfa, event);
  5059. }
  5060. }
  5061. /*
  5062. * Sync the dconf entries to the flash.
  5063. */
  5064. static void
  5065. bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf,
  5066. enum bfa_dconf_event event)
  5067. {
  5068. bfa_trc(dconf->bfa, event);
  5069. switch (event) {
  5070. case BFA_DCONF_SM_IOCDISABLE:
  5071. case BFA_DCONF_SM_FLASH_COMP:
  5072. bfa_timer_stop(&dconf->timer);
  5073. fallthrough;
  5074. case BFA_DCONF_SM_TIMEOUT:
  5075. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  5076. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  5077. break;
  5078. default:
  5079. bfa_sm_fault(dconf->bfa, event);
  5080. }
  5081. }
  5082. static void
  5083. bfa_dconf_sm_sync(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
  5084. {
  5085. bfa_trc(dconf->bfa, event);
  5086. switch (event) {
  5087. case BFA_DCONF_SM_FLASH_COMP:
  5088. bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
  5089. break;
  5090. case BFA_DCONF_SM_WR:
  5091. bfa_timer_start(dconf->bfa, &dconf->timer,
  5092. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  5093. bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
  5094. break;
  5095. case BFA_DCONF_SM_EXIT:
  5096. bfa_timer_start(dconf->bfa, &dconf->timer,
  5097. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  5098. bfa_sm_set_state(dconf, bfa_dconf_sm_final_sync);
  5099. break;
  5100. case BFA_DCONF_SM_IOCDISABLE:
  5101. bfa_sm_set_state(dconf, bfa_dconf_sm_iocdown_dirty);
  5102. break;
  5103. default:
  5104. bfa_sm_fault(dconf->bfa, event);
  5105. }
  5106. }
  5107. static void
  5108. bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf,
  5109. enum bfa_dconf_event event)
  5110. {
  5111. bfa_trc(dconf->bfa, event);
  5112. switch (event) {
  5113. case BFA_DCONF_SM_INIT:
  5114. bfa_timer_start(dconf->bfa, &dconf->timer,
  5115. bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
  5116. bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
  5117. break;
  5118. case BFA_DCONF_SM_EXIT:
  5119. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  5120. bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
  5121. break;
  5122. case BFA_DCONF_SM_IOCDISABLE:
  5123. break;
  5124. default:
  5125. bfa_sm_fault(dconf->bfa, event);
  5126. }
  5127. }
  5128. /*
  5129. * Compute and return memory needed by DRV_CFG module.
  5130. */
  5131. void
  5132. bfa_dconf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
  5133. struct bfa_s *bfa)
  5134. {
  5135. struct bfa_mem_kva_s *dconf_kva = BFA_MEM_DCONF_KVA(bfa);
  5136. if (cfg->drvcfg.min_cfg)
  5137. bfa_mem_kva_setup(meminfo, dconf_kva,
  5138. sizeof(struct bfa_dconf_hdr_s));
  5139. else
  5140. bfa_mem_kva_setup(meminfo, dconf_kva,
  5141. sizeof(struct bfa_dconf_s));
  5142. }
  5143. void
  5144. bfa_dconf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg)
  5145. {
  5146. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5147. dconf->bfad = bfad;
  5148. dconf->bfa = bfa;
  5149. dconf->instance = bfa->ioc.port_id;
  5150. bfa_trc(bfa, dconf->instance);
  5151. dconf->dconf = (struct bfa_dconf_s *) bfa_mem_kva_curp(dconf);
  5152. if (cfg->drvcfg.min_cfg) {
  5153. bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_hdr_s);
  5154. dconf->min_cfg = BFA_TRUE;
  5155. } else {
  5156. dconf->min_cfg = BFA_FALSE;
  5157. bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_s);
  5158. }
  5159. bfa_dconf_read_data_valid(bfa) = BFA_FALSE;
  5160. bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
  5161. }
  5162. static void
  5163. bfa_dconf_init_cb(void *arg, bfa_status_t status)
  5164. {
  5165. struct bfa_s *bfa = arg;
  5166. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5167. if (status == BFA_STATUS_OK) {
  5168. bfa_dconf_read_data_valid(bfa) = BFA_TRUE;
  5169. if (dconf->dconf->hdr.signature != BFI_DCONF_SIGNATURE)
  5170. dconf->dconf->hdr.signature = BFI_DCONF_SIGNATURE;
  5171. if (dconf->dconf->hdr.version != BFI_DCONF_VERSION)
  5172. dconf->dconf->hdr.version = BFI_DCONF_VERSION;
  5173. }
  5174. bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP);
  5175. bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_DCONF_DONE);
  5176. }
  5177. void
  5178. bfa_dconf_modinit(struct bfa_s *bfa)
  5179. {
  5180. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5181. bfa_sm_send_event(dconf, BFA_DCONF_SM_INIT);
  5182. }
  5183. static void bfa_dconf_timer(void *cbarg)
  5184. {
  5185. struct bfa_dconf_mod_s *dconf = cbarg;
  5186. bfa_sm_send_event(dconf, BFA_DCONF_SM_TIMEOUT);
  5187. }
  5188. void
  5189. bfa_dconf_iocdisable(struct bfa_s *bfa)
  5190. {
  5191. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5192. bfa_sm_send_event(dconf, BFA_DCONF_SM_IOCDISABLE);
  5193. }
  5194. static bfa_status_t
  5195. bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf)
  5196. {
  5197. bfa_status_t bfa_status;
  5198. bfa_trc(dconf->bfa, 0);
  5199. bfa_status = bfa_flash_update_part(BFA_FLASH(dconf->bfa),
  5200. BFA_FLASH_PART_DRV, dconf->instance,
  5201. dconf->dconf, sizeof(struct bfa_dconf_s), 0,
  5202. bfa_dconf_cbfn, dconf);
  5203. if (bfa_status != BFA_STATUS_OK)
  5204. WARN_ON(bfa_status);
  5205. bfa_trc(dconf->bfa, bfa_status);
  5206. return bfa_status;
  5207. }
  5208. bfa_status_t
  5209. bfa_dconf_update(struct bfa_s *bfa)
  5210. {
  5211. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5212. bfa_trc(dconf->bfa, 0);
  5213. if (bfa_sm_cmp_state(dconf, bfa_dconf_sm_iocdown_dirty))
  5214. return BFA_STATUS_FAILED;
  5215. if (dconf->min_cfg) {
  5216. bfa_trc(dconf->bfa, dconf->min_cfg);
  5217. return BFA_STATUS_FAILED;
  5218. }
  5219. bfa_sm_send_event(dconf, BFA_DCONF_SM_WR);
  5220. return BFA_STATUS_OK;
  5221. }
  5222. static void
  5223. bfa_dconf_cbfn(void *arg, bfa_status_t status)
  5224. {
  5225. struct bfa_dconf_mod_s *dconf = arg;
  5226. WARN_ON(status);
  5227. bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP);
  5228. }
  5229. void
  5230. bfa_dconf_modexit(struct bfa_s *bfa)
  5231. {
  5232. struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
  5233. bfa_sm_send_event(dconf, BFA_DCONF_SM_EXIT);
  5234. }
  5235. /*
  5236. * FRU specific functions
  5237. */
  5238. #define BFA_FRU_DMA_BUF_SZ 0x02000 /* 8k dma buffer */
  5239. #define BFA_FRU_CHINOOK_MAX_SIZE 0x10000
  5240. #define BFA_FRU_LIGHTNING_MAX_SIZE 0x200
  5241. static void
  5242. bfa_fru_notify(void *cbarg, enum bfa_ioc_event_e event)
  5243. {
  5244. struct bfa_fru_s *fru = cbarg;
  5245. bfa_trc(fru, event);
  5246. switch (event) {
  5247. case BFA_IOC_E_DISABLED:
  5248. case BFA_IOC_E_FAILED:
  5249. if (fru->op_busy) {
  5250. fru->status = BFA_STATUS_IOC_FAILURE;
  5251. fru->cbfn(fru->cbarg, fru->status);
  5252. fru->op_busy = 0;
  5253. }
  5254. break;
  5255. default:
  5256. break;
  5257. }
  5258. }
  5259. /*
  5260. * Send fru write request.
  5261. *
  5262. * @param[in] cbarg - callback argument
  5263. */
  5264. static void
  5265. bfa_fru_write_send(void *cbarg, enum bfi_fru_h2i_msgs msg_type)
  5266. {
  5267. struct bfa_fru_s *fru = cbarg;
  5268. struct bfi_fru_write_req_s *msg =
  5269. (struct bfi_fru_write_req_s *) fru->mb.msg;
  5270. u32 len;
  5271. msg->offset = cpu_to_be32(fru->addr_off + fru->offset);
  5272. len = (fru->residue < BFA_FRU_DMA_BUF_SZ) ?
  5273. fru->residue : BFA_FRU_DMA_BUF_SZ;
  5274. msg->length = cpu_to_be32(len);
  5275. /*
  5276. * indicate if it's the last msg of the whole write operation
  5277. */
  5278. msg->last = (len == fru->residue) ? 1 : 0;
  5279. msg->trfr_cmpl = (len == fru->residue) ? fru->trfr_cmpl : 0;
  5280. bfi_h2i_set(msg->mh, BFI_MC_FRU, msg_type, bfa_ioc_portid(fru->ioc));
  5281. bfa_alen_set(&msg->alen, len, fru->dbuf_pa);
  5282. memcpy(fru->dbuf_kva, fru->ubuf + fru->offset, len);
  5283. bfa_ioc_mbox_queue(fru->ioc, &fru->mb);
  5284. fru->residue -= len;
  5285. fru->offset += len;
  5286. }
  5287. /*
  5288. * Send fru read request.
  5289. *
  5290. * @param[in] cbarg - callback argument
  5291. */
  5292. static void
  5293. bfa_fru_read_send(void *cbarg, enum bfi_fru_h2i_msgs msg_type)
  5294. {
  5295. struct bfa_fru_s *fru = cbarg;
  5296. struct bfi_fru_read_req_s *msg =
  5297. (struct bfi_fru_read_req_s *) fru->mb.msg;
  5298. u32 len;
  5299. msg->offset = cpu_to_be32(fru->addr_off + fru->offset);
  5300. len = (fru->residue < BFA_FRU_DMA_BUF_SZ) ?
  5301. fru->residue : BFA_FRU_DMA_BUF_SZ;
  5302. msg->length = cpu_to_be32(len);
  5303. bfi_h2i_set(msg->mh, BFI_MC_FRU, msg_type, bfa_ioc_portid(fru->ioc));
  5304. bfa_alen_set(&msg->alen, len, fru->dbuf_pa);
  5305. bfa_ioc_mbox_queue(fru->ioc, &fru->mb);
  5306. }
  5307. /*
  5308. * Flash memory info API.
  5309. *
  5310. * @param[in] mincfg - minimal cfg variable
  5311. */
  5312. u32
  5313. bfa_fru_meminfo(bfa_boolean_t mincfg)
  5314. {
  5315. /* min driver doesn't need fru */
  5316. if (mincfg)
  5317. return 0;
  5318. return BFA_ROUNDUP(BFA_FRU_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  5319. }
  5320. /*
  5321. * Flash attach API.
  5322. *
  5323. * @param[in] fru - fru structure
  5324. * @param[in] ioc - ioc structure
  5325. * @param[in] dev - device structure
  5326. * @param[in] trcmod - trace module
  5327. * @param[in] logmod - log module
  5328. */
  5329. void
  5330. bfa_fru_attach(struct bfa_fru_s *fru, struct bfa_ioc_s *ioc, void *dev,
  5331. struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
  5332. {
  5333. fru->ioc = ioc;
  5334. fru->trcmod = trcmod;
  5335. fru->cbfn = NULL;
  5336. fru->cbarg = NULL;
  5337. fru->op_busy = 0;
  5338. bfa_ioc_mbox_regisr(fru->ioc, BFI_MC_FRU, bfa_fru_intr, fru);
  5339. bfa_q_qe_init(&fru->ioc_notify);
  5340. bfa_ioc_notify_init(&fru->ioc_notify, bfa_fru_notify, fru);
  5341. list_add_tail(&fru->ioc_notify.qe, &fru->ioc->notify_q);
  5342. /* min driver doesn't need fru */
  5343. if (mincfg) {
  5344. fru->dbuf_kva = NULL;
  5345. fru->dbuf_pa = 0;
  5346. }
  5347. }
  5348. /*
  5349. * Claim memory for fru
  5350. *
  5351. * @param[in] fru - fru structure
  5352. * @param[in] dm_kva - pointer to virtual memory address
  5353. * @param[in] dm_pa - frusical memory address
  5354. * @param[in] mincfg - minimal cfg variable
  5355. */
  5356. void
  5357. bfa_fru_memclaim(struct bfa_fru_s *fru, u8 *dm_kva, u64 dm_pa,
  5358. bfa_boolean_t mincfg)
  5359. {
  5360. if (mincfg)
  5361. return;
  5362. fru->dbuf_kva = dm_kva;
  5363. fru->dbuf_pa = dm_pa;
  5364. memset(fru->dbuf_kva, 0, BFA_FRU_DMA_BUF_SZ);
  5365. dm_kva += BFA_ROUNDUP(BFA_FRU_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  5366. dm_pa += BFA_ROUNDUP(BFA_FRU_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
  5367. }
  5368. /*
  5369. * Update fru vpd image.
  5370. *
  5371. * @param[in] fru - fru structure
  5372. * @param[in] buf - update data buffer
  5373. * @param[in] len - data buffer length
  5374. * @param[in] offset - offset relative to starting address
  5375. * @param[in] cbfn - callback function
  5376. * @param[in] cbarg - callback argument
  5377. *
  5378. * Return status.
  5379. */
  5380. bfa_status_t
  5381. bfa_fruvpd_update(struct bfa_fru_s *fru, void *buf, u32 len, u32 offset,
  5382. bfa_cb_fru_t cbfn, void *cbarg, u8 trfr_cmpl)
  5383. {
  5384. bfa_trc(fru, BFI_FRUVPD_H2I_WRITE_REQ);
  5385. bfa_trc(fru, len);
  5386. bfa_trc(fru, offset);
  5387. if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2 &&
  5388. fru->ioc->attr->card_type != BFA_MFG_TYPE_CHINOOK2)
  5389. return BFA_STATUS_FRU_NOT_PRESENT;
  5390. if (fru->ioc->attr->card_type != BFA_MFG_TYPE_CHINOOK)
  5391. return BFA_STATUS_CMD_NOTSUPP;
  5392. if (!bfa_ioc_is_operational(fru->ioc))
  5393. return BFA_STATUS_IOC_NON_OP;
  5394. if (fru->op_busy) {
  5395. bfa_trc(fru, fru->op_busy);
  5396. return BFA_STATUS_DEVBUSY;
  5397. }
  5398. fru->op_busy = 1;
  5399. fru->cbfn = cbfn;
  5400. fru->cbarg = cbarg;
  5401. fru->residue = len;
  5402. fru->offset = 0;
  5403. fru->addr_off = offset;
  5404. fru->ubuf = buf;
  5405. fru->trfr_cmpl = trfr_cmpl;
  5406. bfa_fru_write_send(fru, BFI_FRUVPD_H2I_WRITE_REQ);
  5407. return BFA_STATUS_OK;
  5408. }
  5409. /*
  5410. * Read fru vpd image.
  5411. *
  5412. * @param[in] fru - fru structure
  5413. * @param[in] buf - read data buffer
  5414. * @param[in] len - data buffer length
  5415. * @param[in] offset - offset relative to starting address
  5416. * @param[in] cbfn - callback function
  5417. * @param[in] cbarg - callback argument
  5418. *
  5419. * Return status.
  5420. */
  5421. bfa_status_t
  5422. bfa_fruvpd_read(struct bfa_fru_s *fru, void *buf, u32 len, u32 offset,
  5423. bfa_cb_fru_t cbfn, void *cbarg)
  5424. {
  5425. bfa_trc(fru, BFI_FRUVPD_H2I_READ_REQ);
  5426. bfa_trc(fru, len);
  5427. bfa_trc(fru, offset);
  5428. if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
  5429. return BFA_STATUS_FRU_NOT_PRESENT;
  5430. if (fru->ioc->attr->card_type != BFA_MFG_TYPE_CHINOOK &&
  5431. fru->ioc->attr->card_type != BFA_MFG_TYPE_CHINOOK2)
  5432. return BFA_STATUS_CMD_NOTSUPP;
  5433. if (!bfa_ioc_is_operational(fru->ioc))
  5434. return BFA_STATUS_IOC_NON_OP;
  5435. if (fru->op_busy) {
  5436. bfa_trc(fru, fru->op_busy);
  5437. return BFA_STATUS_DEVBUSY;
  5438. }
  5439. fru->op_busy = 1;
  5440. fru->cbfn = cbfn;
  5441. fru->cbarg = cbarg;
  5442. fru->residue = len;
  5443. fru->offset = 0;
  5444. fru->addr_off = offset;
  5445. fru->ubuf = buf;
  5446. bfa_fru_read_send(fru, BFI_FRUVPD_H2I_READ_REQ);
  5447. return BFA_STATUS_OK;
  5448. }
  5449. /*
  5450. * Get maximum size fru vpd image.
  5451. *
  5452. * @param[in] fru - fru structure
  5453. * @param[out] size - maximum size of fru vpd data
  5454. *
  5455. * Return status.
  5456. */
  5457. bfa_status_t
  5458. bfa_fruvpd_get_max_size(struct bfa_fru_s *fru, u32 *max_size)
  5459. {
  5460. if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
  5461. return BFA_STATUS_FRU_NOT_PRESENT;
  5462. if (!bfa_ioc_is_operational(fru->ioc))
  5463. return BFA_STATUS_IOC_NON_OP;
  5464. if (fru->ioc->attr->card_type == BFA_MFG_TYPE_CHINOOK ||
  5465. fru->ioc->attr->card_type == BFA_MFG_TYPE_CHINOOK2)
  5466. *max_size = BFA_FRU_CHINOOK_MAX_SIZE;
  5467. else
  5468. return BFA_STATUS_CMD_NOTSUPP;
  5469. return BFA_STATUS_OK;
  5470. }
  5471. /*
  5472. * tfru write.
  5473. *
  5474. * @param[in] fru - fru structure
  5475. * @param[in] buf - update data buffer
  5476. * @param[in] len - data buffer length
  5477. * @param[in] offset - offset relative to starting address
  5478. * @param[in] cbfn - callback function
  5479. * @param[in] cbarg - callback argument
  5480. *
  5481. * Return status.
  5482. */
  5483. bfa_status_t
  5484. bfa_tfru_write(struct bfa_fru_s *fru, void *buf, u32 len, u32 offset,
  5485. bfa_cb_fru_t cbfn, void *cbarg)
  5486. {
  5487. bfa_trc(fru, BFI_TFRU_H2I_WRITE_REQ);
  5488. bfa_trc(fru, len);
  5489. bfa_trc(fru, offset);
  5490. bfa_trc(fru, *((u8 *) buf));
  5491. if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
  5492. return BFA_STATUS_FRU_NOT_PRESENT;
  5493. if (!bfa_ioc_is_operational(fru->ioc))
  5494. return BFA_STATUS_IOC_NON_OP;
  5495. if (fru->op_busy) {
  5496. bfa_trc(fru, fru->op_busy);
  5497. return BFA_STATUS_DEVBUSY;
  5498. }
  5499. fru->op_busy = 1;
  5500. fru->cbfn = cbfn;
  5501. fru->cbarg = cbarg;
  5502. fru->residue = len;
  5503. fru->offset = 0;
  5504. fru->addr_off = offset;
  5505. fru->ubuf = buf;
  5506. bfa_fru_write_send(fru, BFI_TFRU_H2I_WRITE_REQ);
  5507. return BFA_STATUS_OK;
  5508. }
  5509. /*
  5510. * tfru read.
  5511. *
  5512. * @param[in] fru - fru structure
  5513. * @param[in] buf - read data buffer
  5514. * @param[in] len - data buffer length
  5515. * @param[in] offset - offset relative to starting address
  5516. * @param[in] cbfn - callback function
  5517. * @param[in] cbarg - callback argument
  5518. *
  5519. * Return status.
  5520. */
  5521. bfa_status_t
  5522. bfa_tfru_read(struct bfa_fru_s *fru, void *buf, u32 len, u32 offset,
  5523. bfa_cb_fru_t cbfn, void *cbarg)
  5524. {
  5525. bfa_trc(fru, BFI_TFRU_H2I_READ_REQ);
  5526. bfa_trc(fru, len);
  5527. bfa_trc(fru, offset);
  5528. if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
  5529. return BFA_STATUS_FRU_NOT_PRESENT;
  5530. if (!bfa_ioc_is_operational(fru->ioc))
  5531. return BFA_STATUS_IOC_NON_OP;
  5532. if (fru->op_busy) {
  5533. bfa_trc(fru, fru->op_busy);
  5534. return BFA_STATUS_DEVBUSY;
  5535. }
  5536. fru->op_busy = 1;
  5537. fru->cbfn = cbfn;
  5538. fru->cbarg = cbarg;
  5539. fru->residue = len;
  5540. fru->offset = 0;
  5541. fru->addr_off = offset;
  5542. fru->ubuf = buf;
  5543. bfa_fru_read_send(fru, BFI_TFRU_H2I_READ_REQ);
  5544. return BFA_STATUS_OK;
  5545. }
  5546. /*
  5547. * Process fru response messages upon receiving interrupts.
  5548. *
  5549. * @param[in] fruarg - fru structure
  5550. * @param[in] msg - message structure
  5551. */
  5552. void
  5553. bfa_fru_intr(void *fruarg, struct bfi_mbmsg_s *msg)
  5554. {
  5555. struct bfa_fru_s *fru = fruarg;
  5556. struct bfi_fru_rsp_s *rsp = (struct bfi_fru_rsp_s *)msg;
  5557. u32 status;
  5558. bfa_trc(fru, msg->mh.msg_id);
  5559. if (!fru->op_busy) {
  5560. /*
  5561. * receiving response after ioc failure
  5562. */
  5563. bfa_trc(fru, 0x9999);
  5564. return;
  5565. }
  5566. switch (msg->mh.msg_id) {
  5567. case BFI_FRUVPD_I2H_WRITE_RSP:
  5568. case BFI_TFRU_I2H_WRITE_RSP:
  5569. status = be32_to_cpu(rsp->status);
  5570. bfa_trc(fru, status);
  5571. if (status != BFA_STATUS_OK || fru->residue == 0) {
  5572. fru->status = status;
  5573. fru->op_busy = 0;
  5574. if (fru->cbfn)
  5575. fru->cbfn(fru->cbarg, fru->status);
  5576. } else {
  5577. bfa_trc(fru, fru->offset);
  5578. if (msg->mh.msg_id == BFI_FRUVPD_I2H_WRITE_RSP)
  5579. bfa_fru_write_send(fru,
  5580. BFI_FRUVPD_H2I_WRITE_REQ);
  5581. else
  5582. bfa_fru_write_send(fru,
  5583. BFI_TFRU_H2I_WRITE_REQ);
  5584. }
  5585. break;
  5586. case BFI_FRUVPD_I2H_READ_RSP:
  5587. case BFI_TFRU_I2H_READ_RSP:
  5588. status = be32_to_cpu(rsp->status);
  5589. bfa_trc(fru, status);
  5590. if (status != BFA_STATUS_OK) {
  5591. fru->status = status;
  5592. fru->op_busy = 0;
  5593. if (fru->cbfn)
  5594. fru->cbfn(fru->cbarg, fru->status);
  5595. } else {
  5596. u32 len = be32_to_cpu(rsp->length);
  5597. bfa_trc(fru, fru->offset);
  5598. bfa_trc(fru, len);
  5599. memcpy(fru->ubuf + fru->offset, fru->dbuf_kva, len);
  5600. fru->residue -= len;
  5601. fru->offset += len;
  5602. if (fru->residue == 0) {
  5603. fru->status = status;
  5604. fru->op_busy = 0;
  5605. if (fru->cbfn)
  5606. fru->cbfn(fru->cbarg, fru->status);
  5607. } else {
  5608. if (msg->mh.msg_id == BFI_FRUVPD_I2H_READ_RSP)
  5609. bfa_fru_read_send(fru,
  5610. BFI_FRUVPD_H2I_READ_REQ);
  5611. else
  5612. bfa_fru_read_send(fru,
  5613. BFI_TFRU_H2I_READ_REQ);
  5614. }
  5615. }
  5616. break;
  5617. default:
  5618. WARN_ON(1);
  5619. }
  5620. }
  5621. /*
  5622. * register definitions
  5623. */
  5624. #define FLI_CMD_REG 0x0001d000
  5625. #define FLI_RDDATA_REG 0x0001d010
  5626. #define FLI_ADDR_REG 0x0001d004
  5627. #define FLI_DEV_STATUS_REG 0x0001d014
  5628. #define BFA_FLASH_FIFO_SIZE 128 /* fifo size */
  5629. #define BFA_FLASH_CHECK_MAX 10000 /* max # of status check */
  5630. #define BFA_FLASH_BLOCKING_OP_MAX 1000000 /* max # of blocking op check */
  5631. #define BFA_FLASH_WIP_MASK 0x01 /* write in progress bit mask */
  5632. enum bfa_flash_cmd {
  5633. BFA_FLASH_FAST_READ = 0x0b, /* fast read */
  5634. BFA_FLASH_READ_STATUS = 0x05, /* read status */
  5635. };
  5636. /*
  5637. * Hardware error definition
  5638. */
  5639. enum bfa_flash_err {
  5640. BFA_FLASH_NOT_PRESENT = -1, /*!< flash not present */
  5641. BFA_FLASH_UNINIT = -2, /*!< flash not initialized */
  5642. BFA_FLASH_BAD = -3, /*!< flash bad */
  5643. BFA_FLASH_BUSY = -4, /*!< flash busy */
  5644. BFA_FLASH_ERR_CMD_ACT = -5, /*!< command active never cleared */
  5645. BFA_FLASH_ERR_FIFO_CNT = -6, /*!< fifo count never cleared */
  5646. BFA_FLASH_ERR_WIP = -7, /*!< write-in-progress never cleared */
  5647. BFA_FLASH_ERR_TIMEOUT = -8, /*!< fli timeout */
  5648. BFA_FLASH_ERR_LEN = -9, /*!< invalid length */
  5649. };
  5650. /*
  5651. * Flash command register data structure
  5652. */
  5653. union bfa_flash_cmd_reg_u {
  5654. struct {
  5655. #ifdef __BIG_ENDIAN
  5656. u32 act:1;
  5657. u32 rsv:1;
  5658. u32 write_cnt:9;
  5659. u32 read_cnt:9;
  5660. u32 addr_cnt:4;
  5661. u32 cmd:8;
  5662. #else
  5663. u32 cmd:8;
  5664. u32 addr_cnt:4;
  5665. u32 read_cnt:9;
  5666. u32 write_cnt:9;
  5667. u32 rsv:1;
  5668. u32 act:1;
  5669. #endif
  5670. } r;
  5671. u32 i;
  5672. };
  5673. /*
  5674. * Flash device status register data structure
  5675. */
  5676. union bfa_flash_dev_status_reg_u {
  5677. struct {
  5678. #ifdef __BIG_ENDIAN
  5679. u32 rsv:21;
  5680. u32 fifo_cnt:6;
  5681. u32 busy:1;
  5682. u32 init_status:1;
  5683. u32 present:1;
  5684. u32 bad:1;
  5685. u32 good:1;
  5686. #else
  5687. u32 good:1;
  5688. u32 bad:1;
  5689. u32 present:1;
  5690. u32 init_status:1;
  5691. u32 busy:1;
  5692. u32 fifo_cnt:6;
  5693. u32 rsv:21;
  5694. #endif
  5695. } r;
  5696. u32 i;
  5697. };
  5698. /*
  5699. * Flash address register data structure
  5700. */
  5701. union bfa_flash_addr_reg_u {
  5702. struct {
  5703. #ifdef __BIG_ENDIAN
  5704. u32 addr:24;
  5705. u32 dummy:8;
  5706. #else
  5707. u32 dummy:8;
  5708. u32 addr:24;
  5709. #endif
  5710. } r;
  5711. u32 i;
  5712. };
  5713. /*
  5714. * dg flash_raw_private Flash raw private functions
  5715. */
  5716. static void
  5717. bfa_flash_set_cmd(void __iomem *pci_bar, u8 wr_cnt,
  5718. u8 rd_cnt, u8 ad_cnt, u8 op)
  5719. {
  5720. union bfa_flash_cmd_reg_u cmd;
  5721. cmd.i = 0;
  5722. cmd.r.act = 1;
  5723. cmd.r.write_cnt = wr_cnt;
  5724. cmd.r.read_cnt = rd_cnt;
  5725. cmd.r.addr_cnt = ad_cnt;
  5726. cmd.r.cmd = op;
  5727. writel(cmd.i, (pci_bar + FLI_CMD_REG));
  5728. }
  5729. static void
  5730. bfa_flash_set_addr(void __iomem *pci_bar, u32 address)
  5731. {
  5732. union bfa_flash_addr_reg_u addr;
  5733. addr.r.addr = address & 0x00ffffff;
  5734. addr.r.dummy = 0;
  5735. writel(addr.i, (pci_bar + FLI_ADDR_REG));
  5736. }
  5737. static int
  5738. bfa_flash_cmd_act_check(void __iomem *pci_bar)
  5739. {
  5740. union bfa_flash_cmd_reg_u cmd;
  5741. cmd.i = readl(pci_bar + FLI_CMD_REG);
  5742. if (cmd.r.act)
  5743. return BFA_FLASH_ERR_CMD_ACT;
  5744. return 0;
  5745. }
  5746. /*
  5747. * @brief
  5748. * Flush FLI data fifo.
  5749. *
  5750. * @param[in] pci_bar - pci bar address
  5751. * @param[in] dev_status - device status
  5752. *
  5753. * Return 0 on success, negative error number on error.
  5754. */
  5755. static u32
  5756. bfa_flash_fifo_flush(void __iomem *pci_bar)
  5757. {
  5758. u32 i;
  5759. union bfa_flash_dev_status_reg_u dev_status;
  5760. dev_status.i = readl(pci_bar + FLI_DEV_STATUS_REG);
  5761. if (!dev_status.r.fifo_cnt)
  5762. return 0;
  5763. /* fifo counter in terms of words */
  5764. for (i = 0; i < dev_status.r.fifo_cnt; i++)
  5765. readl(pci_bar + FLI_RDDATA_REG);
  5766. /*
  5767. * Check the device status. It may take some time.
  5768. */
  5769. for (i = 0; i < BFA_FLASH_CHECK_MAX; i++) {
  5770. dev_status.i = readl(pci_bar + FLI_DEV_STATUS_REG);
  5771. if (!dev_status.r.fifo_cnt)
  5772. break;
  5773. }
  5774. if (dev_status.r.fifo_cnt)
  5775. return BFA_FLASH_ERR_FIFO_CNT;
  5776. return 0;
  5777. }
  5778. /*
  5779. * @brief
  5780. * Read flash status.
  5781. *
  5782. * @param[in] pci_bar - pci bar address
  5783. *
  5784. * Return 0 on success, negative error number on error.
  5785. */
  5786. static u32
  5787. bfa_flash_status_read(void __iomem *pci_bar)
  5788. {
  5789. union bfa_flash_dev_status_reg_u dev_status;
  5790. int status;
  5791. u32 ret_status;
  5792. int i;
  5793. status = bfa_flash_fifo_flush(pci_bar);
  5794. if (status < 0)
  5795. return status;
  5796. bfa_flash_set_cmd(pci_bar, 0, 4, 0, BFA_FLASH_READ_STATUS);
  5797. for (i = 0; i < BFA_FLASH_CHECK_MAX; i++) {
  5798. status = bfa_flash_cmd_act_check(pci_bar);
  5799. if (!status)
  5800. break;
  5801. }
  5802. if (status)
  5803. return status;
  5804. dev_status.i = readl(pci_bar + FLI_DEV_STATUS_REG);
  5805. if (!dev_status.r.fifo_cnt)
  5806. return BFA_FLASH_BUSY;
  5807. ret_status = readl(pci_bar + FLI_RDDATA_REG);
  5808. ret_status >>= 24;
  5809. status = bfa_flash_fifo_flush(pci_bar);
  5810. if (status < 0)
  5811. return status;
  5812. return ret_status;
  5813. }
  5814. /*
  5815. * @brief
  5816. * Start flash read operation.
  5817. *
  5818. * @param[in] pci_bar - pci bar address
  5819. * @param[in] offset - flash address offset
  5820. * @param[in] len - read data length
  5821. * @param[in] buf - read data buffer
  5822. *
  5823. * Return 0 on success, negative error number on error.
  5824. */
  5825. static u32
  5826. bfa_flash_read_start(void __iomem *pci_bar, u32 offset, u32 len,
  5827. char *buf)
  5828. {
  5829. int status;
  5830. /*
  5831. * len must be mutiple of 4 and not exceeding fifo size
  5832. */
  5833. if (len == 0 || len > BFA_FLASH_FIFO_SIZE || (len & 0x03) != 0)
  5834. return BFA_FLASH_ERR_LEN;
  5835. /*
  5836. * check status
  5837. */
  5838. status = bfa_flash_status_read(pci_bar);
  5839. if (status == BFA_FLASH_BUSY)
  5840. status = bfa_flash_status_read(pci_bar);
  5841. if (status < 0)
  5842. return status;
  5843. /*
  5844. * check if write-in-progress bit is cleared
  5845. */
  5846. if (status & BFA_FLASH_WIP_MASK)
  5847. return BFA_FLASH_ERR_WIP;
  5848. bfa_flash_set_addr(pci_bar, offset);
  5849. bfa_flash_set_cmd(pci_bar, 0, (u8)len, 4, BFA_FLASH_FAST_READ);
  5850. return 0;
  5851. }
  5852. /*
  5853. * @brief
  5854. * Check flash read operation.
  5855. *
  5856. * @param[in] pci_bar - pci bar address
  5857. *
  5858. * Return flash device status, 1 if busy, 0 if not.
  5859. */
  5860. static u32
  5861. bfa_flash_read_check(void __iomem *pci_bar)
  5862. {
  5863. if (bfa_flash_cmd_act_check(pci_bar))
  5864. return 1;
  5865. return 0;
  5866. }
  5867. /*
  5868. * @brief
  5869. * End flash read operation.
  5870. *
  5871. * @param[in] pci_bar - pci bar address
  5872. * @param[in] len - read data length
  5873. * @param[in] buf - read data buffer
  5874. *
  5875. */
  5876. static void
  5877. bfa_flash_read_end(void __iomem *pci_bar, u32 len, char *buf)
  5878. {
  5879. u32 i;
  5880. /*
  5881. * read data fifo up to 32 words
  5882. */
  5883. for (i = 0; i < len; i += 4) {
  5884. u32 w = readl(pci_bar + FLI_RDDATA_REG);
  5885. *((u32 *) (buf + i)) = swab32(w);
  5886. }
  5887. bfa_flash_fifo_flush(pci_bar);
  5888. }
  5889. /*
  5890. * @brief
  5891. * Perform flash raw read.
  5892. *
  5893. * @param[in] pci_bar - pci bar address
  5894. * @param[in] offset - flash partition address offset
  5895. * @param[in] buf - read data buffer
  5896. * @param[in] len - read data length
  5897. *
  5898. * Return status.
  5899. */
  5900. #define FLASH_BLOCKING_OP_MAX 500
  5901. #define FLASH_SEM_LOCK_REG 0x18820
  5902. static int
  5903. bfa_raw_sem_get(void __iomem *bar)
  5904. {
  5905. int locked;
  5906. locked = readl((bar + FLASH_SEM_LOCK_REG));
  5907. return !locked;
  5908. }
  5909. static bfa_status_t
  5910. bfa_flash_sem_get(void __iomem *bar)
  5911. {
  5912. u32 n = FLASH_BLOCKING_OP_MAX;
  5913. while (!bfa_raw_sem_get(bar)) {
  5914. if (--n <= 0)
  5915. return BFA_STATUS_BADFLASH;
  5916. mdelay(10);
  5917. }
  5918. return BFA_STATUS_OK;
  5919. }
  5920. static void
  5921. bfa_flash_sem_put(void __iomem *bar)
  5922. {
  5923. writel(0, (bar + FLASH_SEM_LOCK_REG));
  5924. }
  5925. bfa_status_t
  5926. bfa_flash_raw_read(void __iomem *pci_bar, u32 offset, char *buf,
  5927. u32 len)
  5928. {
  5929. u32 n;
  5930. int status;
  5931. u32 off, l, s, residue, fifo_sz;
  5932. residue = len;
  5933. off = 0;
  5934. fifo_sz = BFA_FLASH_FIFO_SIZE;
  5935. status = bfa_flash_sem_get(pci_bar);
  5936. if (status != BFA_STATUS_OK)
  5937. return status;
  5938. while (residue) {
  5939. s = offset + off;
  5940. n = s / fifo_sz;
  5941. l = (n + 1) * fifo_sz - s;
  5942. if (l > residue)
  5943. l = residue;
  5944. status = bfa_flash_read_start(pci_bar, offset + off, l,
  5945. &buf[off]);
  5946. if (status < 0) {
  5947. bfa_flash_sem_put(pci_bar);
  5948. return BFA_STATUS_FAILED;
  5949. }
  5950. n = BFA_FLASH_BLOCKING_OP_MAX;
  5951. while (bfa_flash_read_check(pci_bar)) {
  5952. if (--n <= 0) {
  5953. bfa_flash_sem_put(pci_bar);
  5954. return BFA_STATUS_FAILED;
  5955. }
  5956. }
  5957. bfa_flash_read_end(pci_bar, l, &buf[off]);
  5958. residue -= l;
  5959. off += l;
  5960. }
  5961. bfa_flash_sem_put(pci_bar);
  5962. return BFA_STATUS_OK;
  5963. }